*\r
* User: laramie\r
*/\r
- \r
public class RefName {\r
+\r
public static final String HACK_VOCABULARIES = "Vocabularies"; //TODO: get rid of these.\r
public static final String HACK_ORGANIZATIONS = "Organizations"; //TODO: get rid of these.\r
public static final String HACK_ORGAUTHORITIES = "Orgauthorities"; //TODO: get rid of these.\r
public static final String HACK_PERSONAUTHORITIES = "Personauthorities"; //TODO: get rid of these.\r
public static final String HACK_LOCATIONAUTHORITIES = "Locationauthorities"; //TODO: get rid of these.\r
-\r
- public static final String URN_PREFIX = "urn:cspace:";\r
+ public static final String URN_PREFIX = "urn:cspace:";\r
public static final String URN_NAME_PREFIX = "urn:cspace:name";\r
-\r
public static final String REFNAME = "refName";\r
-\r
- public static final String AUTHORITY_REGEX = "urn:cspace:(.*):(.*):name\\((.*)\\)\\'?([^\\']*)\\'?";\r
+ public static final String AUTHORITY_REGEX = "urn:cspace:(.*):(.*):name\\((.*)\\)\\'?([^\\']*)\\'?";\r
public static final String AUTHORITY_ITEM_REGEX = "urn:cspace:(.*):(.*):name\\((.*)\\):item:name\\((.*)\\)\\'?([^\\']*)\\'?";\r
-\r
- public static final String AUTHORITY_EXAMPLE = "urn:cspace:collectionspace.org:Loansin:name(shortID)'displayName'";\r
+ public static final String AUTHORITY_EXAMPLE = "urn:cspace:collectionspace.org:Loansin:name(shortID)'displayName'";\r
public static final String AUTHORITY_EXAMPLE2 = "urn:cspace:collectionspace.org:Loansin:name(shortID)";\r
-\r
- public static final String AUTHORITY_ITEM_EXAMPLE ="urn:cspace:collectionspace.org:Loansin:name(shortID):item:name(itemShortID)'itemDisplayName'";\r
-\r
+ public static final String AUTHORITY_ITEM_EXAMPLE = "urn:cspace:collectionspace.org:Loansin:name(shortID):item:name(itemShortID)'itemDisplayName'";\r
public static final String EX_tenantName = "collectionspace.org";\r
public static final String EX_resource = "Loansin";\r
public static final String EX_shortIdentifier = "shortID";\r
public static final String EX_itemShortIdentifier = "itemShortID";\r
public static final String EX_itemDisplayName = "itemDisplayName";\r
\r
-\r
public static class Authority {\r
+\r
public String tenantName = "";\r
public String resource = "";\r
public String shortIdentifier = "";\r
public String displayName = "";\r
+\r
public static Authority parse(String urn) {\r
Authority info = new Authority();\r
Pattern p = Pattern.compile(AUTHORITY_REGEX);\r
Matcher m = p.matcher(urn);\r
- if (m.find()){\r
- if (m.groupCount()<4){\r
+ if (m.find()) {\r
+ if (m.groupCount() < 4) {\r
return null;\r
}\r
info.tenantName = m.group(1);\r
}\r
return null;\r
}\r
- public boolean equals(Object other){\r
- if (other == null){\r
+ \r
+ public String getShortIdentifier() {\r
+ return this.shortIdentifier;\r
+ }\r
+\r
+ public boolean equals(Object other) {\r
+ if (other == null) {\r
return false;\r
}\r
- if (other instanceof Authority){\r
- Authority ao = (Authority)other;\r
- return ( this.tenantName.equals(ao.tenantName)\r
+ if (other instanceof Authority) {\r
+ Authority ao = (Authority) other;\r
+ return (this.tenantName.equals(ao.tenantName)\r
&& this.resource.equals(ao.resource)\r
- && this.shortIdentifier.equals(ao.shortIdentifier)\r
- );\r
+ && this.shortIdentifier.equals(ao.shortIdentifier));\r
} else {\r
return false;\r
}\r
}\r
+\r
public String getRelativeUri() {\r
- return "/"+resource+"/"+URN_NAME_PREFIX+"("+shortIdentifier+")";\r
+ return "/" + resource + "/" + URN_NAME_PREFIX + "(" + shortIdentifier + ")";\r
}\r
+\r
public String toString() {\r
String displaySuffix = (displayName != null && (!displayName.isEmpty())) ? '\'' + displayName + '\'' : "";\r
return URN_PREFIX + tenantName + ':' + resource + ":" + "name" + "(" + shortIdentifier + ")" + displaySuffix;\r
}\r
-\r
}\r
\r
public static class AuthorityItem {\r
+\r
public Authority inAuthority;\r
public String shortIdentifier = "";\r
public String displayName = "";\r
+\r
public static AuthorityItem parse(String urn) {\r
Authority info = new Authority();\r
AuthorityItem termInfo = new AuthorityItem();\r
termInfo.inAuthority = info;\r
Pattern p = Pattern.compile(AUTHORITY_ITEM_REGEX);\r
Matcher m = p.matcher(urn);\r
- if (m.find()){\r
- if (m.groupCount()<5){\r
- return null;\r
+ if (m.find()) {\r
+ if (m.groupCount() < 5) {\r
+ return null;\r
}\r
termInfo.inAuthority.tenantName = m.group(1);\r
termInfo.inAuthority.resource = m.group(2);\r
}\r
return null;\r
}\r
- public boolean equals(Object other){\r
- if (other == null){\r
+ \r
+ public String getParentShortIdentifier() {\r
+ return this.inAuthority.shortIdentifier;\r
+ }\r
+ \r
+ public String getShortIdentifier() {\r
+ return this.shortIdentifier;\r
+ }\r
+ \r
+ public boolean equals(Object other) {\r
+ if (other == null) {\r
return false;\r
}\r
- if (other instanceof AuthorityItem){\r
- AuthorityItem aio = (AuthorityItem)other;\r
+ if (other instanceof AuthorityItem) {\r
+ AuthorityItem aio = (AuthorityItem) other;\r
boolean ok = true;\r
ok = ok && aio.inAuthority != null;\r
ok = ok && aio.inAuthority.equals(this.inAuthority);\r
return false;\r
}\r
}\r
+\r
public String getRelativeUri() {\r
- return inAuthority.getRelativeUri()+"/items/"+URN_NAME_PREFIX+"("+shortIdentifier+")";\r
+ return inAuthority.getRelativeUri() + "/items/" + URN_NAME_PREFIX + "(" + shortIdentifier + ")";\r
}\r
+\r
public String toString() {\r
String displaySuffix = (displayName != null && (!displayName.isEmpty())) ? '\'' + displayName + '\'' : "";\r
Authority ai = inAuthority;\r
- if (ai==null){\r
- return URN_PREFIX+"ERROR:inAuthorityNotSet: (" + shortIdentifier + ")" + displaySuffix;\r
+ if (ai == null) {\r
+ return URN_PREFIX + "ERROR:inAuthorityNotSet: (" + shortIdentifier + ")" + displaySuffix;\r
} else {\r
- String base = URN_PREFIX + ai.tenantName + ':' + ai.resource + ":" + "name" + "(" + ai.shortIdentifier + ")" ;\r
- String refname = base+":item:name("+shortIdentifier+")"+displaySuffix;\r
- return refname;\r
+ String base = URN_PREFIX + ai.tenantName + ':' + ai.resource + ":" + "name" + "(" + ai.shortIdentifier + ")";\r
+ String refname = base + ":item:name(" + shortIdentifier + ")" + displaySuffix;\r
+ return refname;\r
}\r
}\r
-\r
}\r
\r
public static Authority buildAuthority(String tenantName, String serviceName, String authorityShortIdentifier, String authorityDisplayName) {\r
}\r
\r
public static AuthorityItem buildAuthorityItem(String tenantName, String serviceName, String authorityShortIdentifier,\r
- String itemShortIdentifier, String itemDisplayName) {\r
+ String itemShortIdentifier, String itemDisplayName) {\r
Authority authority = buildAuthority(tenantName, serviceName, authorityShortIdentifier, "");\r
return buildAuthorityItem(authority, itemShortIdentifier, itemDisplayName);\r
}\r
* so that calling shortIdToPath("TestAuthority") returns "urn:cspace:name(TestAuthority)", and\r
* then this value may be put into a path, such as "/personauthorities/urn:cspace:name(TestAuthority)/items".\r
*/\r
- public static String shortIdToPath(String shortId){\r
- return URN_NAME_PREFIX+'('+shortId+')';\r
+ public static String shortIdToPath(String shortId) {\r
+ return URN_NAME_PREFIX + '(' + shortId + ')';\r
}\r
}\r
check(item.toString(), item3.toString(), "buildAuthorityItem(Authority,str,str) from AUTHORITY_EXAMPLE2 vs. AUTHORITY_ITEM_EXAMPLE");\r
Assert.assertEquals(item, item3);\r
}\r
+ \r
+ /**\r
+ * Test convenience getters that return short identifiers for authorities and authority items.\r
+ */\r
+ @Test\r
+ public void testShortIDGetters(){\r
+ testBanner("testShortIDGetters");\r
+ RefName.Authority authority = RefName.Authority.parse(RefName.AUTHORITY_EXAMPLE);\r
+ Assert.assertEquals(authority.getShortIdentifier(), RefName.EX_shortIdentifier,\r
+ "Short identifier from parsing parent authority refName does not match value of Authority.getShortIdentifier().");\r
+ \r
+ RefName.AuthorityItem item = RefName.buildAuthorityItem(RefName.AUTHORITY_EXAMPLE,\r
+ RefName.EX_itemShortIdentifier,\r
+ RefName.EX_itemDisplayName);\r
+ Assert.assertEquals(item.getParentShortIdentifier(), RefName.EX_shortIdentifier,\r
+ "Parent short identifier from parsing authority refName does not match value of AuthorityItem.getParentShortIdentifier().");\r
+ Assert.assertEquals(item.getShortIdentifier(), RefName.EX_itemShortIdentifier,\r
+ "Short identifier from item does not match value of AuthorityItem.getShortIdentifier().");\r
+ \r
+ RefName.AuthorityItem parsedItem = RefName.AuthorityItem.parse(RefName.AUTHORITY_ITEM_EXAMPLE);\r
+ Assert.assertEquals(parsedItem.getParentShortIdentifier(), RefName.EX_shortIdentifier,\r
+ "Parent short identifier from parsing item refName does not match value of AuthorityItem.getParentShortIdentifier().");\r
+ Assert.assertEquals(parsedItem.getShortIdentifier(), RefName.EX_itemShortIdentifier,\r
+ "Short identifier from parsing item refName does not match value of AuthorityItem.getShortIdentifier().");\r
+\r
+ }\r
\r
}\r