1 /*
2 * Copyright (c) 2022 Kaiserpfalz EDV-Service, Roland T. Lichti
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18 package de.kaiserpfalzedv.rpg.torg.data;
19
20 import de.kaiserpfalzedv.commons.core.resources.MetadataImpl;
21 import de.kaiserpfalzedv.commons.core.resources.PointerImpl;
22 import de.kaiserpfalzedv.rpg.core.Books.Publication;
23 import de.kaiserpfalzedv.rpg.core.Books.PublicationData;
24 import de.kaiserpfalzedv.rpg.torg.About;
25
26 import java.util.HashMap;
27 import java.util.Optional;
28 import java.util.UUID;
29
30 /**
31 * Publications -- The known publications
32 *
33 * @author klenkes74 {@literal <rlichti@kaiserpfalz-edv.de>}
34 * @since 1.2.0 2021-05-23
35 */
36 public interface Publications {
37 Publication CORE_RULES = Publication.builder()
38 .metadata(
39 MetadataImpl.builder()
40 .identity(
41 PointerImpl.builder()
42 .kind(Publication.KIND)
43 .apiVersion(Publication.VERSION)
44 .nameSpace(About.TORG_NAMESPACE)
45 .name("Torg Core Rules")
46 .build()
47 )
48 .uid(UUID.fromString("dc1de20e-c19b-49a7-873e-45fd0ce91e73"))
49 .generation(1)
50 .created(About.DEFAULT_CREATION)
51 .owner(Publishers.ULISSES_SPIELE.toPointer())
52
53 .build()
54 )
55 .spec(
56 PublicationData.builder()
57 .displayTitle("Torg Core Rules")
58 .title("Torg Eternity - Core Rules")
59 .orderId("UNA10000")
60 .driveThroughId(216248)
61 .build()
62 )
63 .build();
64
65
66 HashMap<UUID, Publication> PUBLICATIONS = new HashMap<>();
67
68 /**
69 * @param id The UUID of the publication.
70 * @return The publication with the given ID (if present).
71 */
72 default Optional<Publication> findPublicationByUuid(final UUID id) {
73 if (PUBLICATIONS.isEmpty()) {
74 PUBLICATIONS.put(CORE_RULES.getUid(), CORE_RULES);
75 }
76 return Optional.ofNullable(PUBLICATIONS.get(id));
77 }
78 }