* $LastChangedDate$
*/
public class CollectionSpaceJaxRsApplication extends Application
- implements ResourceMapHolder, UriTemplateRegistryHolder {
+ implements ResourceMapHolder {
private Set<Object> singletons = new HashSet<Object>();
private Set<Class<?>> empty = new HashSet<Class<?>>();
private ResourceMap resourceMap = new ResourceMapImpl();
- private UriTemplateRegistry uriTemplateRegistry = new UriTemplateRegistry();
private ServletContext servletContext = null;
public CollectionSpaceJaxRsApplication() {
singletons.add(new IDResource());
- buildUriTemplateRegistry();
- // FIXME: Temporary for CSPACE-5271 - please remove once
- // that issue is resolved
- uriTemplateRegistry.dump();
-
/*
singletons.add(new WorkflowResource());
*/
resourceMap.put(resource.getServiceName(), resource);
}
- /**
- * Build a registry of URI templates by querying each resource
- * for its own entries in the registry.
- *
- * These entries consist of one or more URI templates for
- * building URIs for accessing that resource.
- */
- private void buildUriTemplateRegistry() {
- ResourceBase resource = null;
- ResourceMap resources = getResourceMap();
- for (Map.Entry<String, ResourceBase> entry : resources.entrySet()) {
- resource = entry.getValue();
- 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
- // building URIs for resources that have contacts as a sub-resource
- //
- // FIXME: There may be a more elegant way to filter this out; or it may
- // fall out during implementation of CSPACE-2698
- //
- // final String CONTACT_DOCTYPE = "Contact";
- // uriTemplateRegistry.remove(CONTACT_DOCTYPE);
- }
-
@Override
public Set<Class<?>> getClasses() {
return singletons;
}
+ @Override
public ResourceMap getResourceMap() {
return resourceMap;
}
- private void setUriTemplateRegistry(UriTemplateRegistry registry) {
- this.uriTemplateRegistry = registry;
- }
-
- public UriTemplateRegistry getUriTemplateRegistry() {
- return uriTemplateRegistry;
- }
-
public void setServletContext(ServletContext servletContext) {
this.servletContext = servletContext;
}
import org.collectionspace.services.config.types.PropertyType;\r
import org.collectionspace.services.nuxeo.client.java.NuxeoConnectorEmbedded;\r
import org.collectionspace.services.nuxeo.client.java.TenantRepository;\r
+import org.jboss.resteasy.spi.ResteasyProviderFactory;\r
\r
import org.slf4j.Logger;\r
import org.slf4j.LoggerFactory;\r
private String serverRootDir = null;\r
private ServicesConfigReaderImpl servicesConfigReader;\r
private TenantBindingConfigReaderImpl tenantBindingConfigReader;\r
+ private UriTemplateRegistry uriTemplateRegistry = new UriTemplateRegistry();\r
\r
private static final String SERVER_HOME_PROPERTY = "catalina.home";\r
\r
public TenantBindingConfigReaderImpl getTenantBindingConfigReader() {\r
return tenantBindingConfigReader;\r
}\r
+ \r
+ /**\r
+ * Populate a registry of URI templates by querying each resource\r
+ * for its own entries in the registry.\r
+ * \r
+ * These entries consist of one or more URI templates for\r
+ * building URIs for accessing that resource.\r
+ */\r
+ private synchronized void populateUriTemplateRegistry() {\r
+ if (uriTemplateRegistry.isEmpty()) {\r
+ ResourceBase resource = null;\r
+ ResourceMap resourceMap = ResteasyProviderFactory.getContextData(ResourceMap.class);\r
+ for (Map.Entry<String, ResourceBase> entry : resourceMap.entrySet()) {\r
+ resource = entry.getValue();\r
+ Map<UriTemplateRegistryKey, StoredValuesUriTemplate> entries =\r
+ resource.getUriRegistryEntries();\r
+ uriTemplateRegistry.putAll(entries);\r
+ }\r
+\r
+ // FIXME: Contacts itself should not have an entry in the URI template registry;\r
+ // there should be a Contacts entry in that registry only for use in\r
+ // building URIs for resources that have contacts as a sub-resource\r
+ // (This may also fall out during implementation of CSPACE-2698.)\r
+\r
+ // FIXME: Temporary for debugging in-process work on CSPACE-5271.\r
+ // Please remove the following statement once that issue is resolved.\r
+ uriTemplateRegistry.dump();\r
+ }\r
+ }\r
+\r
+ public UriTemplateRegistry getUriTemplateRegistry() {\r
+ if (uriTemplateRegistry.isEmpty()) {\r
+ populateUriTemplateRegistry();\r
+ }\r
+ return uriTemplateRegistry;\r
+ }\r
\r
\r
}\r
package org.collectionspace.services.common.vocabulary;\r
\r
import java.util.ArrayList;\r
-import java.util.Collection;\r
import java.util.HashMap;\r
import java.util.Iterator;\r
import java.util.List;\r
import org.collectionspace.services.client.PoxPayloadIn;\r
import org.collectionspace.services.client.PoxPayloadOut;\r
import org.collectionspace.services.common.ServiceMain;\r
+import org.collectionspace.services.common.StoredValuesUriTemplate;\r
+import org.collectionspace.services.common.UriTemplateFactory;\r
+import org.collectionspace.services.common.UriTemplateRegistry;\r
+import org.collectionspace.services.common.UriTemplateRegistryKey;\r
import org.collectionspace.services.common.context.ServiceContext;\r
import org.collectionspace.services.common.context.AbstractServiceContextImpl;\r
import org.collectionspace.services.common.api.RefNameUtils;\r
import org.collectionspace.services.common.api.Tools;\r
import org.collectionspace.services.common.api.RefNameUtils.AuthorityTermInfo;\r
import org.collectionspace.services.common.authorityref.AuthorityRefDocList;\r
-import org.collectionspace.services.common.authorityref.AuthorityRefList;\r
import org.collectionspace.services.common.config.TenantBindingConfigReaderImpl;\r
-import org.collectionspace.services.common.config.URIUtils;\r
import org.collectionspace.services.common.context.ServiceBindingUtils;\r
import org.collectionspace.services.common.document.DocumentException;\r
import org.collectionspace.services.common.document.DocumentFilter;\r
import org.collectionspace.services.common.document.DocumentWrapper;\r
import org.collectionspace.services.common.query.QueryManager;\r
import org.collectionspace.services.common.repository.RepositoryClient;\r
-// import org.collectionspace.services.common.vocabulary.AuthorityItemJAXBSchema;\r
import org.collectionspace.services.nuxeo.client.java.DocHandlerBase;\r
import org.collectionspace.services.nuxeo.client.java.RepositoryJavaClientImpl;\r
import org.collectionspace.services.common.security.SecurityUtils;\r
import org.collectionspace.services.config.service.ServiceBindingType;\r
import org.collectionspace.services.jaxb.AbstractCommonList;\r
import org.collectionspace.services.nuxeo.util.NuxeoUtils;\r
+import org.jboss.resteasy.spi.ResteasyProviderFactory;\r
\r
-import com.sun.xml.bind.v2.runtime.unmarshaller.XsiNilLoader.Array;\r
\r
/**\r
* RefNameServiceUtils is a collection of services utilities related to refName\r
public static AuthorityRefDocList getAuthorityRefDocs(\r
RepositoryInstance repoSession,\r
ServiceContext<PoxPayloadIn, PoxPayloadOut> ctx,\r
+ UriTemplateRegistry uriTemplateRegistry,\r
RepositoryClient<PoxPayloadIn, PoxPayloadOut> repoClient,\r
List<String> serviceTypes,\r
String refName,\r
// item within any individual document scanned, so the number of\r
// authority references may potentially exceed the total number\r
// of documents scanned.\r
- int nRefsFound = processRefObjsDocList(docList, refName, queriedServiceBindings, authRefFieldsByService, // the actual list size needs to be updated to the size of "list"\r
+ int nRefsFound = processRefObjsDocList(docList, ctx.getTenantId(), refName, queriedServiceBindings, authRefFieldsByService, // the actual list size needs to be updated to the size of "list"\r
list, null);\r
\r
commonList.setPageSize(pageSize);\r
return refNameServiceTypes;\r
}\r
// Seems like a good value - no real data to set this well.\r
- // Note: can set this value lower; e.g. to 3 during debugging; - ADR 2012-07-10\r
+ // Note: can set this value lower during debugging; e.g. to 3 - ADR 2012-07-10\r
private static final int N_OBJS_TO_UPDATE_PER_LOOP = 100;\r
\r
public static int updateAuthorityRefDocs(\r
morePages = false;\r
}\r
\r
- int nRefsFoundThisPage = processRefObjsDocList(docList, oldRefName, queriedServiceBindings, authRefFieldsByService,\r
+ int nRefsFoundThisPage = processRefObjsDocList(docList, ctx.getTenantId(), oldRefName, queriedServiceBindings, authRefFieldsByService,\r
null, newRefName);\r
if (nRefsFoundThisPage > 0) {\r
((RepositoryJavaClientImpl) repoClient).saveDocListWithoutHandlerProcessing(ctx, repoSession, docList, true);\r
*/\r
private static int processRefObjsDocList(\r
DocumentModelList docList,\r
+ String tenantId,\r
String refName,\r
Map<String, ServiceBindingType> queriedServiceBindings,\r
Map<String, List<AuthRefConfigInfo>> authRefFieldsByService,\r
ilistItem = new AuthorityRefDocList.AuthorityRefDocItem();\r
String csid = NuxeoUtils.getCsid(docModel);//NuxeoUtils.extractId(docModel.getPathAsString());\r
ilistItem.setDocId(csid);\r
- String uri = "";\r
- // FIXME: Hack for CSPACE-5406; this instead should use the (forthcoming)\r
- // URL pattern-to-Doctype registry described in CSPACE-5471 - ADR 2012-07-18\r
- if (sb.getType().equalsIgnoreCase(URIUtils.AUTHORITY_SERVICE_CATEGORY)) {\r
- String authoritySvcName = URIUtils.getAuthoritySvcName(docType);\r
- String inAuthorityCsid;\r
+ UriTemplateRegistry uriTemplateRegistry = ServiceMain.getInstance().getUriTemplateRegistry();\r
+ StoredValuesUriTemplate storedValuesResourceTemplate = uriTemplateRegistry.get(new UriTemplateRegistryKey(docType, tenantId));\r
+ Map<String, String> additionalValues = new HashMap<String, String>();\r
+ if (storedValuesResourceTemplate.getUriTemplateType() == UriTemplateFactory.ITEM) {\r
try {\r
- inAuthorityCsid = (String) docModel.getPropertyValue("inAuthority"); // AuthorityItemJAXBSchema.IN_AUTHORITY\r
- uri = URIUtils.getAuthorityItemUri(authoritySvcName, inAuthorityCsid, csid);\r
+ String inAuthorityCsid = (String) docModel.getPropertyValue("inAuthority"); // AuthorityItemJAXBSchema.IN_AUTHORITY\r
+ additionalValues.put(UriTemplateFactory.IDENTIFIER_VAR, inAuthorityCsid);\r
+ additionalValues.put(UriTemplateFactory.ITEM_IDENTIFIER_VAR, csid);\r
} catch (Exception e) {\r
logger.warn("Could not extract inAuthority property from authority item record: " + e.getMessage());\r
}\r
} else {\r
- uri = URIUtils.getUri(sb.getName(), csid);;\r
+ additionalValues.put(UriTemplateFactory.IDENTIFIER_VAR, csid);\r
}\r
- ilistItem.setUri(uri);\r
+ String uriStr = storedValuesResourceTemplate.buildUri(additionalValues);\r
+ ilistItem.setUri(uriStr);\r
try {\r
ilistItem.setWorkflowState(docModel.getCurrentLifeCycleState());\r
ilistItem.setUpdatedAt(DocHandlerBase.getUpdatedAtAsString(docModel));\r