1 package org.kuali.ole;
2
3 import org.kuali.ole.docstore.model.enums.DocCategory;
4 import org.kuali.ole.docstore.model.enums.DocFormat;
5 import org.kuali.ole.docstore.model.enums.DocType;
6
7 import java.util.HashMap;
8 import java.util.Map;
9
10
11
12
13
14
15
16
17 public class DocumentUniqueIDPrefix {
18
19 public static String PREFIX_WORK_BIB_MARC = "wbm";
20 public static String PREFIX_WORK_BIB_DUBLIN = "wbd";
21 public static String PREFIX_WORK_BIB_DUBLIN_UNQUALIFIED = "wbu";
22 public static String PREFIX_WORK_INSTANCE_OLEML = "wno";
23 public static String PREFIX_WORK_HOLDINGS_OLEML = "who";
24 public static String PREFIX_WORK_ITEM_OLEML = "wio";
25 public static String PREFIX_WORK_EINSTANCE_OLEML = "wen";
26 public static String PREFIX_WORK_EHOLDINGS_OLEML = "weh";
27 public static String PREFIX_WORK_LICENSE_ONIXPL = "wlo";
28 public static String PREFIX_WORK_LICENSE_ATTACHMENT = "wla";
29
30 public static Map<String, Map<String, String>> categoryTypeFormatMap = new HashMap<>();
31 public static Map<String, String> prefixMap = new HashMap<>();
32
33 static {
34 String key = DocCategory.WORK.getCode() + DocType.BIB.getDescription() + DocFormat.MARC.getCode();
35 prefixMap.put(key, PREFIX_WORK_BIB_MARC);
36
37 Map<String, String> map = new HashMap<String, String>();
38 map.put("category", DocCategory.WORK.getCode());
39 map.put("type", DocType.BIB.getDescription());
40 map.put("format", DocFormat.MARC.getCode());
41 categoryTypeFormatMap.put(PREFIX_WORK_BIB_MARC, map);
42
43 key = DocCategory.WORK.getCode() + DocType.BIB.getDescription() + DocFormat.DUBLIN_CORE.getCode();
44 prefixMap.put(key, PREFIX_WORK_BIB_DUBLIN);
45
46 map = new HashMap<String, String>();
47 map.put("category", DocCategory.WORK.getCode());
48 map.put("type", DocType.BIB.getDescription());
49 map.put("format", DocFormat.DUBLIN_CORE.getCode());
50 categoryTypeFormatMap.put(PREFIX_WORK_BIB_DUBLIN, map);
51
52
53 key = DocCategory.WORK.getCode() + DocType.BIB.getDescription() + DocFormat.DUBLIN_UNQUALIFIED.getCode();
54 prefixMap.put(key, PREFIX_WORK_BIB_DUBLIN_UNQUALIFIED);
55
56 map = new HashMap<String, String>();
57 map.put("category", DocCategory.WORK.getCode());
58 map.put("type", DocType.BIB.getDescription());
59 map.put("format", DocFormat.DUBLIN_UNQUALIFIED.getCode());
60 categoryTypeFormatMap.put(PREFIX_WORK_BIB_DUBLIN_UNQUALIFIED, map);
61
62 key = DocCategory.WORK.getCode() + DocType.INSTANCE.getCode() + DocFormat.OLEML.getCode();
63 prefixMap.put(key, PREFIX_WORK_INSTANCE_OLEML);
64
65 map = new HashMap<String, String>();
66 map.put("category", DocCategory.WORK.getCode());
67 map.put("type", DocType.INSTANCE.getDescription());
68 map.put("format", DocFormat.OLEML.getCode());
69 categoryTypeFormatMap.put(PREFIX_WORK_INSTANCE_OLEML, map);
70
71 key = DocCategory.WORK.getCode() + DocType.HOLDINGS.getCode() + DocFormat.OLEML.getCode();
72 prefixMap.put(key, PREFIX_WORK_HOLDINGS_OLEML);
73
74 map = new HashMap<String, String>();
75 map.put("category", DocCategory.WORK.getCode());
76 map.put("type", DocType.HOLDINGS.getDescription());
77 map.put("format", DocFormat.OLEML.getCode());
78 categoryTypeFormatMap.put(PREFIX_WORK_HOLDINGS_OLEML, map);
79
80 map = new HashMap<String, String>();
81
82 key = DocCategory.WORK.getCode() + DocType.ITEM.getCode() + DocFormat.OLEML.getCode();
83 prefixMap.put(key, PREFIX_WORK_ITEM_OLEML);
84
85 map = new HashMap<String, String>();
86 map.put("category", DocCategory.WORK.getCode());
87 map.put("type", DocType.ITEM.getDescription());
88 map.put("format", DocFormat.OLEML.getCode());
89 categoryTypeFormatMap.put(PREFIX_WORK_ITEM_OLEML, map);
90
91
92 key = DocCategory.WORK.getCode() + DocType.EINSTANCE.getCode() + DocFormat.OLEML.getCode();
93 prefixMap.put(key, PREFIX_WORK_EINSTANCE_OLEML);
94
95 map = new HashMap<String, String>();
96 map.put("category", DocCategory.WORK.getCode());
97 map.put("type", DocType.EINSTANCE.getDescription());
98 map.put("format", DocFormat.OLEML.getCode());
99 categoryTypeFormatMap.put(PREFIX_WORK_EINSTANCE_OLEML, map);
100
101 key = DocCategory.WORK.getCode() + DocType.EHOLDINGS.getCode() + DocFormat.OLEML.getCode();
102 prefixMap.put(key, PREFIX_WORK_EHOLDINGS_OLEML);
103
104 map = new HashMap<String, String>();
105 map.put("category", DocCategory.WORK.getCode());
106 map.put("type", DocType.EHOLDINGS.getDescription());
107 map.put("format", DocFormat.OLEML.getCode());
108 categoryTypeFormatMap.put(PREFIX_WORK_EHOLDINGS_OLEML, map);
109
110 key = DocCategory.WORK.getCode() + DocType.LICENSE.getCode() + DocFormat.ONIXPL;
111 prefixMap.put(key, PREFIX_WORK_LICENSE_ONIXPL);
112
113 map = new HashMap<String, String>();
114 map.put("category", DocCategory.WORK.getCode());
115 map.put("type", DocType.LICENSE.getDescription());
116 map.put("format", DocFormat.ONIXPL.getCode());
117 categoryTypeFormatMap.put(PREFIX_WORK_LICENSE_ONIXPL, map);
118
119 }
120
121
122 public static String getPrefix(String category, String type, String format) {
123 return prefixMap.get(category + type + format);
124 }
125
126 public static boolean hasPrefix(String uuid) {
127 if (uuid != null) {
128 String[] prefixes = uuid.split("-");
129 if (prefixes.length == 2) {
130 return true;
131 }
132 }
133 return false;
134 }
135
136 public static Map<String, String> getCategoryTypeFormat(String uuid) {
137 String[] prefixes = uuid.split("-");
138 return categoryTypeFormatMap.get(prefixes[0]);
139 }
140
141 public static String getBibFormatType(String uuid) {
142 Map<String, String> map = getCategoryTypeFormat(uuid);
143 return map.get("format");
144 }
145
146 public static String getPrefixedId(String prefix, String id) {
147 if (hasPrefix(id)) {
148 return id;
149 }
150 return prefix + "-" + id;
151 }
152
153 public static String getDocumentId(String uuid) {
154 if (hasPrefix(uuid)) {
155 String[] prefixes = uuid.split("-");
156 return prefixes[1];
157 }
158 return uuid;
159 }
160 }