private Set<Object> singletons = new HashSet<Object>();
private Set<Class<?>> empty = new HashSet<Class<?>>();
private ResourceMap resourceMap = new ResourceMapImpl();
- private static UriTemplateRegistry uriTemplateRegistry = new UriTemplateRegistry();
+ private UriTemplateRegistry uriTemplateRegistry = new UriTemplateRegistry();
private ServletContext servletContext = null;
public CollectionSpaceJaxRsApplication() {
ResourceMap resources = getResourceMap();
for (Map.Entry<String, ResourceBase> entry : resources.entrySet()) {
resource = entry.getValue();
- System.out.println(resource.getServiceName()); // for debugging
- getUriTemplateRegistry().putAll(resource.getUriRegistryEntries());
- getUriTemplateRegistry().dump(); // for debugging
+ Map<UriTemplateRegistryKey, Map<UriTemplateFactory.UriTemplateType, StoredValuesUriTemplate>> entries =
+ resource.getUriRegistryEntries();
+ getUriTemplateRegistry().putAll(entries);
}
// Contacts itself should not have an entry in the URI template registry;
// there should be a Contacts entry in that registry only for use in
return resourceMap;
}
+ private void setUriTemplateRegistry(UriTemplateRegistry registry) {
+ this.uriTemplateRegistry = registry;
+ }
+
public UriTemplateRegistry getUriTemplateRegistry() {
return uriTemplateRegistry;
}
public ServletContext getServletContext() {
return this.servletContext;
}
+
}
protected String getItemDocType(String tenantId) {
return super.getDocType(tenantId, getItemServiceName());
}
-
+
/**
- * Constructs and returns a map of URI templates for the current resource,
- * for the specified tenant
+ * Constructs and returns a map of URI templates for the current resource.
+ * This map assumes that there will be only one URI template of a given type
+ * ("resource", "item", etc.) for each resource.
*
- * @param tenantId a tenant ID
- * @return a map of URI templates for the current resource, for the specified tenant
+ * @return a map of URI templates for the current resource
*/
@Override
- protected Map<String,StoredValuesUriTemplate> getUriTemplateMap(String tenantId) {
+ protected Map<UriTemplateFactory.UriTemplateType,StoredValuesUriTemplate> getUriTemplateMap() {
// Get the resource URI template from the superclass
- Map<String,StoredValuesUriTemplate> uriTemplateMap = super.getUriTemplateMap(tenantId);
+ Map<UriTemplateFactory.UriTemplateType,StoredValuesUriTemplate> uriTemplateMap = super.getUriTemplateMap();
// Add the item URI template here, and return both templates in the map
- String itemDocType = getItemDocType(tenantId);
- if (itemDocType == null) {
- return uriTemplateMap; // return map as obtained from superclass
- }
StoredValuesUriTemplate itemUriTemplate = getUriTemplate(UriTemplateFactory.ITEM);
if (itemUriTemplate == null) {
return uriTemplateMap; // return map as obtained from superclass
}
- uriTemplateMap.put(itemDocType, itemUriTemplate);
+ uriTemplateMap.put(itemUriTemplate.getUriTemplateType(), itemUriTemplate);
return uriTemplateMap;
}
import org.collectionspace.services.client.IQueryManager;\r
import org.collectionspace.services.client.PoxPayloadIn;\r
import org.collectionspace.services.client.PoxPayloadOut;\r
+import org.collectionspace.services.common.UriTemplateFactory.UriTemplateType;\r
+import org.collectionspace.services.common.UriTemplateRegistryKey;\r
import org.collectionspace.services.common.api.RefName;\r
import org.collectionspace.services.common.api.Tools;\r
import org.collectionspace.services.common.authorityref.AuthorityRefList;\r
return getDocType(tenantId, getServiceName());\r
}\r
\r
+ /**\r
+ * Returns the Nuxeo document type associated with a specified service, within a specified tenant.\r
+ * \r
+ * @param tenantId a tenant ID\r
+ * @param serviceName a service name\r
+ * @return the Nuxeo document type associated with that service and tenant.\r
+ */\r
// FIXME: This method may properly belong in a different services package or class.\r
+ // Also, we need to check for any existing methods that may duplicate this one.\r
protected String getDocType(String tenantId, String serviceName) {\r
String docType = "";\r
- if (Tools.notBlank(tenantId)) {\r
- ServiceBindingType sb = getTenantBindingsReader().getServiceBinding(tenantId, serviceName);\r
- docType = sb.getObject().getName(); // Reads the Nuxeo Document Type from tenant bindings configuration\r
+ if (Tools.isBlank(tenantId)) {\r
+ return docType;\r
}\r
+ ServiceBindingType sb = getTenantBindingsReader().getServiceBinding(tenantId, serviceName);\r
+ if (sb == null) {\r
+ return docType;\r
+ }\r
+ docType = sb.getObject().getName(); // Reads the Nuxeo Document Type from tenant bindings configuration\r
return docType;\r
}\r
\r
* \r
* @return a map of URI templates for the current resource, for all tenants\r
*/\r
- public HashMap<String,Map<String,StoredValuesUriTemplate>> getUriRegistryEntries() {\r
- HashMap<String,Map<String,StoredValuesUriTemplate>> uriRegistryEntriesMap =\r
- new HashMap<String, Map<String,StoredValuesUriTemplate>>();\r
+ public Map<UriTemplateRegistryKey,Map<UriTemplateType,StoredValuesUriTemplate>> getUriRegistryEntries() {\r
+ Map<UriTemplateRegistryKey,Map<UriTemplateType,StoredValuesUriTemplate>> uriRegistryEntriesMap =\r
+ new HashMap<UriTemplateRegistryKey,Map<UriTemplateType,StoredValuesUriTemplate>>();\r
List<String> tenantIds = getTenantIds();\r
+ UriTemplateRegistryKey key;\r
+ String docType = "";\r
for (String tenantId : tenantIds) {\r
- uriRegistryEntriesMap.put(tenantId, getUriTemplateMap(tenantId));\r
+ docType = getDocType(tenantId);\r
+ if (Tools.notBlank(docType)) {\r
+ key = new UriTemplateRegistryKey();\r
+ key.setTenantId(tenantId);\r
+ key.setDocType(docType); \r
+ uriRegistryEntriesMap.put(key, getUriTemplateMap());\r
+ }\r
}\r
return uriRegistryEntriesMap;\r
}\r
\r
\r
/**\r
- * Constructs and returns a map of URI templates for the current resource,\r
- * for the specified tenant\r
+ * Constructs and returns a map of URI templates for the current resource.\r
+ * This map assumes that there will be only one URI template of a given type\r
+ * ("reesource", "item", etc.) for each resource.\r
* \r
- * @param tenantId a tenant ID\r
- * @return a map of URI templates for the current resource, for the specified tenant\r
+ * @return a map of URI templates for the current resource\r
*/\r
- protected Map<String,StoredValuesUriTemplate> getUriTemplateMap(String tenantId) {\r
- Map<String,StoredValuesUriTemplate> uriTemplateMap = new HashMap<String, StoredValuesUriTemplate>();\r
- if (tenantId == null) {\r
- return uriTemplateMap; // return an empty map\r
- }\r
- String docType = getDocType(tenantId);\r
- if (docType == null) {\r
- return uriTemplateMap; // return an empty map\r
- }\r
+ protected Map<UriTemplateType,StoredValuesUriTemplate> getUriTemplateMap() {\r
+ Map<UriTemplateType,StoredValuesUriTemplate> uriTemplateMap = new HashMap<UriTemplateType, StoredValuesUriTemplate>();\r
StoredValuesUriTemplate resourceUriTemplate = getUriTemplate(UriTemplateFactory.RESOURCE);\r
if (resourceUriTemplate == null) {\r
return uriTemplateMap; // return an empty map\r
}\r
- uriTemplateMap.put(docType, resourceUriTemplate);\r
+ uriTemplateMap.put(resourceUriTemplate.getUriTemplateType(), resourceUriTemplate);\r
return uriTemplateMap;\r
}\r
\r
/**\r
- * Returns a UriTemplate of the appropriate type, populated with the\r
+ * Returns a URI template of the appropriate type, populated with the\r
* current service name as one of its stored values.\r
- * \r
- * @param type a UriTemplate type\r
- * @return a UriTemplate of the appropriate type\r
+ * * \r
+ * @param type a URI template type\r
+ * @return a URI template of the appropriate type.\r
*/\r
protected StoredValuesUriTemplate getUriTemplate(UriTemplateFactory.UriTemplateType type) {\r
Map<String,String> storedValuesMap = new HashMap<String,String>();\r
* @return a list of tenant IDs\r
*/\r
// FIXME: This method may properly belong in a different services package or class.\r
+ // Also, we need to check for any existing methods that may duplicate this one.\r
protected List<String> getTenantIds() {\r
List<String> tenantIds = new ArrayList<String>();\r
String tenantId;\r
\r
import java.util.HashMap;\r
import java.util.Map;\r
+import java.util.Set;\r
+import org.collectionspace.services.common.UriTemplateRegistryKey;\r
+import org.collectionspace.services.common.UriTemplateFactory.UriTemplateType;\r
\r
/**\r
* UriTemplateRegistry.java\r
*\r
* Maps document types to templates for building URIs, per tenant.\r
*/\r
-public class UriTemplateRegistry extends HashMap<String, Map<String, StoredValuesUriTemplate>> {\r
+public class UriTemplateRegistry extends HashMap<UriTemplateRegistryKey, Map<UriTemplateType, StoredValuesUriTemplate>> {\r
\r
- // For debugging\r
+ /**\r
+ * Dump all registry settings, For debugging purposes.\r
+ */\r
public void dump() {\r
- for (String tenantId : this.keySet()) {\r
- System.out.println("###############################");\r
- System.out.println("Tenant ID = " + tenantId);\r
- System.out.println("###############################");\r
- for (Map.Entry<String, StoredValuesUriTemplate> uriTemplateEntry : this.get(tenantId).entrySet()) {\r
- System.out.println("Key = " + uriTemplateEntry.getKey()\r
- + ", Value = " + uriTemplateEntry.getValue().getUriTemplateType()\r
- + " : " + uriTemplateEntry.getValue().toString());\r
+ for (Map.Entry<UriTemplateRegistryKey, Map<UriTemplateType, StoredValuesUriTemplate>> uriTemplateEntry : this.entrySet()) {\r
+\r
+ System.out.println(\r
+ "Tenant : DocType = "\r
+ + uriTemplateEntry.getKey().getTenantId()\r
+ + " : "\r
+ + uriTemplateEntry.getKey().getDocType());\r
+\r
+ System.out.println(" Value(s) of TemplateType : Template = ");\r
+ for (Map.Entry<UriTemplateType, StoredValuesUriTemplate> template : uriTemplateEntry.getValue().entrySet()) {\r
+ System.out.println(\r
+ " "\r
+ + template.getKey()\r
+ + " : "\r
+ + template.getValue().toString());\r
}\r
}\r
}\r
protected String getContactDocType() {
return ContactConstants.NUXEO_DOCTYPE;
}
-
+
/**
- * Constructs and returns a map of URI templates for the current resource,
- * for the specified tenant
+ * Constructs and returns a map of URI templates for the current resource.
+ * This map assumes that there will be only one URI template of a given type
+ * ("resource", "item", "contacts" etc.) for each resource.
*
- * @param tenantId a tenant ID
- * @return a map of URI templates for the current resource, for the specified tenant
+ * @return a map of URI templates for the current resource
*/
- // FIXME: This method currently populates only one entry in the UriTemplateRegistry
- // for the Contacts docType, even though contacts can be a sub-resource of
- // multiple authority item resources. (This method may be called more than once,
- // but each time the existing item with the same key in the map is overwritten.)
@Override
- protected Map<String,StoredValuesUriTemplate> getUriTemplateMap(String tenantId) {
+ protected Map<UriTemplateFactory.UriTemplateType,StoredValuesUriTemplate> getUriTemplateMap() {
// Get the resource and item URI templates from the superclass
- Map<String,StoredValuesUriTemplate> uriTemplateMap = super.getUriTemplateMap(tenantId);
+ Map<UriTemplateFactory.UriTemplateType,StoredValuesUriTemplate> uriTemplateMap = super.getUriTemplateMap();
// Add the contact URI template here, and return all three templates in the map
- String contactDocType = getContactDocType();
- if (contactDocType == null) {
- return uriTemplateMap; // return map as obtained from superclass
- }
StoredValuesUriTemplate contactUriTemplate = getUriTemplate(UriTemplateFactory.CONTACT);
if (contactUriTemplate == null) {
return uriTemplateMap; // return map as obtained from superclass
}
- // Remove any service name value stored in the template, as the service name
- // for contact resources will vary, and must be provided at URI build time
- contactUriTemplate.getStoredValuesMap().put(UriTemplateFactory.SERVICENAME_VAR, "");
- uriTemplateMap.put(contactDocType, contactUriTemplate);
+ uriTemplateMap.put(contactUriTemplate.getUriTemplateType(), contactUriTemplate);
return uriTemplateMap;
}