]> git.aero2k.de Git - tmp/jakarta-migration.git/commitdiff
DRYD-177: Supports definition of authorities/vocabularies and terms in the service...
authorremillet <remillet@yahoo.com>
Thu, 2 Nov 2017 22:15:40 +0000 (15:15 -0700)
committerremillet <remillet@yahoo.com>
Thu, 2 Nov 2017 22:15:40 +0000 (15:15 -0700)
22 files changed:
services/JaxRsServiceProvider/src/main/java/org/collectionspace/services/jaxrs/CSpaceResteasyBootstrap.java
services/authority/service/src/main/java/org/collectionspace/services/common/vocabulary/AuthorityResource.java
services/citation/client/src/main/java/org/collectionspace/services/client/CitationAuthorityClient.java
services/client/src/main/java/org/collectionspace/services/client/AuthorityClient.java
services/client/src/main/java/org/collectionspace/services/client/GenericAuthorityClientImpl.java
services/client/src/main/java/org/collectionspace/services/client/test/BaseServiceTest.java
services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/RemoteDocumentModelHandlerImpl.java
services/concept/client/src/main/java/org/collectionspace/services/client/ConceptAuthorityClient.java
services/concept/client/src/main/java/org/collectionspace/services/client/ConceptAuthorityClientUtils.java
services/config/src/main/resources/service.xsd
services/location/client/src/main/java/org/collectionspace/services/client/LocationAuthorityClient.java
services/material/client/src/main/java/org/collectionspace/services/client/MaterialAuthorityClient.java
services/material/client/src/main/java/org/collectionspace/services/client/MaterialAuthorityClientUtils.java
services/organization/client/src/main/java/org/collectionspace/services/client/OrgAuthorityClient.java
services/person/client/src/main/java/org/collectionspace/services/client/PersonAuthorityClient.java
services/person/client/src/main/java/org/collectionspace/services/client/PersonAuthorityClientUtils.java
services/place/client/src/main/java/org/collectionspace/services/client/PlaceAuthorityClient.java
services/taxonomy/client/src/main/java/org/collectionspace/services/client/TaxonomyAuthorityClient.java
services/vocabulary/client/src/main/java/org/collectionspace/services/client/VocabularyClient.java
services/vocabulary/client/src/main/java/org/collectionspace/services/client/VocabularyClientUtils.java
services/vocabulary/client/src/test/java/org/collectionspace/services/client/test/VocabularyServiceTest.java
services/work/client/src/main/java/org/collectionspace/services/client/WorkAuthorityClient.java

index 495c2b0fa34b3a494392087b5e8e015be850bf5d..29936c9c50c360a7ea35d6ea0c9c8cb700184d7d 100644 (file)
@@ -5,26 +5,33 @@ import javax.ws.rs.core.Response;
 
 import org.jboss.resteasy.core.Dispatcher;
 import org.jboss.resteasy.plugins.server.servlet.ResteasyBootstrap;
+
 import org.collectionspace.authentication.CSpaceTenant;
 import org.collectionspace.services.authorization.AuthZ;
-import org.collectionspace.services.client.PersonAuthorityClient;
-import org.collectionspace.services.client.PersonAuthorityClientUtils;
-import org.collectionspace.services.client.PoxPayloadOut;
-import org.collectionspace.services.person.PersonAuthorityResource;
+import org.collectionspace.services.client.AuthorityClient;
+import org.collectionspace.services.common.CSWebApplicationException;
 import org.collectionspace.services.common.ResourceMap;
 import org.collectionspace.services.common.ServiceMain;
+import org.collectionspace.services.common.api.RefName;
 import org.collectionspace.services.common.config.TenantBindingConfigReaderImpl;
+import org.collectionspace.services.common.vocabulary.AuthorityResource;
 import org.collectionspace.services.config.service.AuthorityInstanceType;
 import org.collectionspace.services.config.service.ServiceBindingType;
 import org.collectionspace.services.config.service.ServiceBindingType.AuthorityInstanceList;
+import org.collectionspace.services.config.service.Term;
+import org.collectionspace.services.config.service.TermList;
 import org.collectionspace.services.config.tenant.TenantBindingType;
 
+import java.lang.reflect.Constructor;
 import java.util.Date;
 import java.util.Hashtable;
 import java.util.List;
+import java.util.logging.Level;
 
 public class CSpaceResteasyBootstrap extends ResteasyBootstrap {
        
+       java.util.logging.Logger logger = java.util.logging.Logger.getAnonymousLogger();
+       
        @Override
        public void  contextInitialized(ServletContextEvent event) {
                try {
@@ -32,7 +39,7 @@ public class CSpaceResteasyBootstrap extends ResteasyBootstrap {
                // This call to super instantiates and initializes our JAX-RS application class.
                // The application class is org.collectionspace.services.jaxrs.CollectionSpaceJaxRsApplication.
                //
-               System.out.println(String.format("%tc [INFO] Starting up the CollectionSpace Services' JAX-RS application.", new Date()));
+                       logger.log(Level.INFO, String.format("%tc [INFO] Starting up the CollectionSpace Services' JAX-RS application.", new Date()));
                        super.contextInitialized(event);
                        CollectionSpaceJaxRsApplication app = (CollectionSpaceJaxRsApplication)deployment.getApplication();
                        Dispatcher disp = deployment.getDispatcher();
@@ -40,58 +47,153 @@ public class CSpaceResteasyBootstrap extends ResteasyBootstrap {
                        
                        initializeAuthorities(app.getResourceMap());
                        
-               System.out.println(String.format("%tc [INFO] CollectionSpace Services' JAX-RS application started.", new Date()));
-               } catch (Throwable e) {
+                       logger.log(Level.INFO, String.format("%tc [INFO] CollectionSpace Services' JAX-RS application started.", new Date()));
+               } catch (Exception e) {
                        e.printStackTrace();
-                       throw e;
+                       throw new RuntimeException(e);
                }
        }
        
     @Override
     public void contextDestroyed(ServletContextEvent event) {
-       System.out.println("[INFO] Shutting down the CollectionSpace Services' JAX-RS application.");
+       logger.log(Level.INFO, "[INFO] Shutting down the CollectionSpace Services' JAX-RS application.");
        //Do something if needed.
-       System.out.println("[INFO] CollectionSpace Services' JAX-RS application stopped.");
+       logger.log(Level.INFO, "[INFO] CollectionSpace Services' JAX-RS application stopped.");
     }  
 
-    public void initializeAuthorities(ResourceMap resourceMap) {
+    /**
+     * Initialize all authorities and vocabularies defined in the service bindings.
+     * @param resourceMap
+     * @throws Exception
+     */
+    public void initializeAuthorities(ResourceMap resourceMap) throws Exception {
        TenantBindingConfigReaderImpl tenantBindingConfigReader = ServiceMain.getInstance().getTenantBindingConfigReader();     
        Hashtable<String, TenantBindingType> tenantBindingsTable = tenantBindingConfigReader.getTenantBindings(false);
        for (TenantBindingType tenantBindings : tenantBindingsTable.values()) {
+                       CSpaceTenant tenant = new CSpaceTenant(tenantBindings.getId(), tenantBindings.getName());
                for (ServiceBindingType serviceBinding : tenantBindings.getServiceBindings()) {
                        AuthorityInstanceList element = serviceBinding.getAuthorityInstanceList();
                        if (element != null && element.getAuthorityInstance() != null) {
                                List<AuthorityInstanceType> authorityInstanceList = element.getAuthorityInstance();
                                for (AuthorityInstanceType authorityInstance : authorityInstanceList) {
-                                       CSpaceTenant tenant = new CSpaceTenant(tenantBindings.getId(), tenantBindings.getName());
-                                       initializeAuthorityInstance(resourceMap, authorityInstance, serviceBinding.getName(), tenant);
+                                       try {
+                                               initializeAuthorityInstance(resourceMap, authorityInstance, serviceBinding, tenant);
+                                       } catch (Exception e) {
+                                               logger.log(Level.SEVERE, "Could not initialize authorities and authority terms: " + e.getMessage());
+                                               throw e;
+                                       }
                                }
                        }
                }
        }
        }
+    
+    @SuppressWarnings("rawtypes")
+       private AuthorityClient getAuthorityClient(String classname) throws Exception {
+        Class clazz = Class.forName(classname.trim());
+        Constructor co = clazz.getConstructor(null);
+        Object classInstance = co.newInstance(null);
+        return (AuthorityClient) classInstance;
+    }
+
+    /*
+     * Check to see if an an authority instance and its corresponding terms exist.  If not, try to create them.
+     */
+    private void initializeAuthorityInstance(ResourceMap resourceMap, AuthorityInstanceType authorityInstance, ServiceBindingType serviceBinding, CSpaceTenant tenant) throws Exception {
+       int status = -1;
+       Response response = null;
+               String serviceName = serviceBinding.getName();
+       
+               AuthZ.get().login(tenant);
+               String clientClassName = serviceBinding.getClientHandler();
+               AuthorityClient client = getAuthorityClient(clientClassName);
+               String authoritySpecifier = RefName.shortIdToPath(authorityInstance.getTitleRef());  // e.g., urn:cspace:name(ulan)
 
-    private void initializeAuthorityInstance(ResourceMap resourceMap, AuthorityInstanceType authorityInstance, String serviceName, CSpaceTenant tenant) {
-               // TODO Auto-generated method stub
+               //
+               // Test to see if the authority instance exists already.
+               //
+               AuthorityResource authorityResource = (AuthorityResource) resourceMap.get(serviceName.toLowerCase());
                try {
-                       AuthZ.get().login(tenant);
-                       PersonAuthorityClient client = new PersonAuthorityClient();                     
-                       PoxPayloadOut xmlPayloadOut = PersonAuthorityClientUtils.createPersonAuthorityInstance(
-                                       authorityInstance.getTitle(), authorityInstance.getTitleRef(), client.getCommonPartName());
-                       String xmlPayload = xmlPayloadOut.asXML();
-                       PersonAuthorityResource personAuthorityResource = (PersonAuthorityResource) resourceMap.get(serviceName.toLowerCase());
-                       Response response = personAuthorityResource.createAuthority(xmlPayload);
-                       int status = response.getStatus();
-                                               
-               } catch (Exception e) {
-                       // TODO Auto-generated catch block
-                       e.printStackTrace();
+                       response = authorityResource.get(null, null, authoritySpecifier);
+               } catch (CSWebApplicationException e) {
+                       response = e.getResponse();  // If the authority doesn't exist, we expect a 404 error
                }
-       }
-
-       private void initializeVocabularies() {
-               // TODO Auto-generated method stub
                
+               //
+               // If it doesn't exist (status is not 200), then try to create the authority instance
+               //
+               status = response.getStatus();
+               if (status != Response.Status.OK.getStatusCode()) {
+                       String xmlPayload = client.createAuthorityInstance(authorityInstance.getTitleRef(), authorityInstance.getTitle());
+                       response = authorityResource.createAuthority(xmlPayload);
+                       status = response.getStatus();
+                       if (status != Response.Status.CREATED.getStatusCode()) {
+                               throw new CSWebApplicationException(response); 
+                       }
+               }
+               
+               if (status == Response.Status.OK.getStatusCode()) {
+                       logger.log(Level.FINE, String.format("Authority of type '%s' with the short ID of '%s' existed already.",
+                                       serviceName, authorityInstance.getTitleRef()));
+               } else if (status == Response.Status.CREATED.getStatusCode()) {
+                       logger.log(Level.INFO, String.format("Created a new authority of type '%s' with the short ID of '%s'.",
+                                       serviceName, authorityInstance.getTitleRef()));
+               } else {
+                       logger.log(Level.WARNING, String.format("Unknown status '%d' encountered when creating or fetching authority of type '%s' with the short ID of '%s'.",
+                                       serviceName, authorityInstance.getTitleRef()));
+               }               
+               
+               //
+               // Finally, try to create or verify the authority terms.
+               //
+               initializeAuthorityInstanceTerms(authorityResource, client, authoritySpecifier, resourceMap, authorityInstance, serviceName, tenant);
        }
+    
+    private void initializeAuthorityInstanceTerms(
+               AuthorityResource authorityResource,
+               AuthorityClient client, 
+               String authoritySpecifier, 
+               ResourceMap resourceMap, 
+               AuthorityInstanceType authorityInstance, 
+               String serviceName,
+               CSpaceTenant tenant) throws Exception {
+       
+       int status = -1;
+       Response response = null;
 
+       TermList termListElement = authorityInstance.getTermList();
+       for (Term term : termListElement.getTerm()) {
+               //
+               // Check to see if the term already exists
+               //
+               try {
+                       String termSpecifier = RefName.shortIdToPath(term.getId());                     
+                       authorityResource.getAuthorityItem(null, null, resourceMap, authoritySpecifier, termSpecifier);
+                       status = Response.Status.OK.getStatusCode();
+               } catch (CSWebApplicationException e) {
+                       response = e.getResponse();  // If the authority doesn't exist, we expect a 404 error
+                       status = response.getStatus();
+               }
+               
+               //
+               // If the term doesn't exist, create it.
+               //
+               if (status != Response.Status.OK.getStatusCode()) {
+                       String termShortId = term.getId();
+                       String termDisplayName = term.getContent().trim();
+                       String xmlPayload = client.createAuthorityItemInstance(termShortId, termDisplayName);
+                       try {
+                               authorityResource.createAuthorityItem(resourceMap, null, authoritySpecifier, xmlPayload);
+                               logger.log(Level.INFO, String.format("Created a new term '%s:%s' in the authority of type '%s' with the short ID of '%s'.",
+                                               termDisplayName, termShortId, serviceName, authorityInstance.getTitleRef()));
+                       } catch (CSWebApplicationException e) {
+                               response = e.getResponse();
+                               status = response.getStatus();
+                               if (status != Response.Status.CREATED.getStatusCode()) {
+                                       throw new CSWebApplicationException(response); 
+                               }
+                       }
+               }
+       }
+    }
 }
index cbfe4f4adb430accc91e8668dba09ac5123b33a5..f1d81fab4385c14cc884e776b35f8c045e25ca00 100644 (file)
@@ -664,7 +664,7 @@ public abstract class AuthorityResource<AuthCommon, AuthItemHandler>
     @Path("{csid}/items")
     public Response createAuthorityItem(
                @Context ResourceMap resourceMap,
-               @Context UriInfo uriInfo, 
+               @Context UriInfo uriInfo,
                @PathParam("csid") String parentIdentifier, // Either a CSID or a URN form -e.g., a8ad38ec-1d7d-4bf2-bd31 or urn:cspace:name(bugsbunny)
                String xmlPayload) {
        uriInfo = new UriInfoWrapper(uriInfo);
@@ -678,7 +678,7 @@ public abstract class AuthorityResource<AuthCommon, AuthItemHandler>
         } catch (Exception e) {
             throw bigReThrow(e, ServiceMessages.CREATE_FAILED);
         }
-        
+
         return result;
     }
 
index 6bf858faada3bc57cf58f637985e93c5a79e118e..4eb49e814672b8d23c2c4279327dcc88c1d250c6 100644 (file)
@@ -88,4 +88,16 @@ public class CitationAuthorityClient extends AuthorityClientImpl<Citationauthori
     public void setInAuthority(CitationsCommon item, String inAuthorityCsid) {
         item.setInAuthority(inAuthorityCsid);
     }
+
+       @Override
+       public String createAuthorityInstance(String shortIdentifier, String displayName) {
+               PoxPayloadOut poxPayloadOut = CitationAuthorityClientUtils.createCitationAuthorityInstance(displayName, shortIdentifier, SERVICE_COMMON_PART_NAME);
+               return poxPayloadOut.asXML();
+       }
+
+       @Override
+       public String createAuthorityItemInstance(String shortIdentifier, String displayName) {
+               // TODO Auto-generated method stub
+               return null;
+       }
 }
index e4a5f7a0e9cc166cc116f7a261e2db65ac18723e..321df718fb2a621ed5ad415bf17056a718a528d8 100644 (file)
@@ -188,4 +188,16 @@ public interface AuthorityClient<AUTHORITY_COMMON_TYPE, AUTHORITY_ITEM_TYPE, P e
     public Response readItemWorkflow(String vcsid, String csid);
     
     public Response updateItemWorkflowWithTransition(String vcsid, String csid, String workflowTransition);
+    
+    //
+    // General utils
+    //
+    
+    /*
+     * Should return a valid XML payload for creating an authority instance 
+     */
+    public String createAuthorityInstance(String shortIdentifier, String displayName);
+    
+    public String createAuthorityItemInstance(String shortIdentifier, String displayName);
+    
 }
index bc039573d6f82beecf23d421c609a69a2ff8a287..fc5ec355782b17d721e3192d6585473afb680ea1 100644 (file)
@@ -43,4 +43,16 @@ public class GenericAuthorityClientImpl extends
                return null;
        }
 
+       @Override
+       public String createAuthorityInstance(String shortIdentifier, String displayName) {
+               // TODO Auto-generated method stub
+               return null;
+       }
+
+       @Override
+       public String createAuthorityItemInstance(String shortIdentifier, String displayName) {
+               // TODO Auto-generated method stub
+               return null;
+       }
+
 }
index ac6d33aaa9f66737f9433b8131f7851e701cf080..e4b41f4bb71be1feeb0b215029ec7f3c0f4ba441 100644 (file)
@@ -62,6 +62,7 @@ import org.testng.annotations.DataProvider;
 import org.w3c.dom.Document;
 import org.collectionspace.services.client.AuthorityClient;
 import org.collectionspace.services.client.CollectionSpaceClient;
+import org.collectionspace.services.client.CollectionSpaceClientUtils;
 import org.collectionspace.services.client.PayloadInputPart;
 import org.collectionspace.services.client.PayloadOutputPart;
 import org.collectionspace.services.client.PoxPayloadIn;
@@ -451,17 +452,7 @@ public abstract class BaseServiceTest<CLT> {
      * @return the string
      */
     static protected String extractId(Response res) {
-        MultivaluedMap<String, Object> mvm = res.getMetadata();
-        String uri = (String) ((List<Object>) mvm.get("Location")).get(0);
-        if (logger.isDebugEnabled()) {
-            logger.debug("extractId:uri=" + uri);
-        }
-        String[] segments = uri.split("/");
-        String id = segments[segments.length - 1];
-        if (logger.isDebugEnabled()) {
-            logger.debug("id=" + id);
-        }
-        return id;
+        return CollectionSpaceClientUtils.extractId(res);
     }
     
  
index d6b11a094cb0cce3817ec0e2dc14cd7558296d72..d3348b029dfa7476dd2db1a4c6aecc893ccaedc3 100644 (file)
@@ -365,7 +365,8 @@ public abstract class   RemoteDocumentModelHandlerImpl<T, TL>
         }
         
         String currentUser = ctx.getUserId();
-        if (currentUser.equalsIgnoreCase(AuthN.ANONYMOUS_USER) == false) {
+        if (currentUser.equalsIgnoreCase(AuthN.ANONYMOUS_USER) == false &&
+                       currentUser.equalsIgnoreCase(AuthN.SPRING_ADMIN_USER) == false) {
                addAccountPermissionsPart();
         }
     }
index 7e0643c5af0b763373c89fa60dc6ba68f4ff1dc8..651a26ab2a0dcdf37ccedeb1d4e5741401232133 100644 (file)
@@ -89,4 +89,16 @@ public class ConceptAuthorityClient extends AuthorityClientImpl<Conceptauthoriti
     public void setInAuthority(ConceptsCommon item, String inAuthorityCsid) {
         item.setInAuthority(inAuthorityCsid);
     }
+
+       @Override
+       public String createAuthorityInstance(String shortIdentifier, String displayName) {
+               PoxPayloadOut poxPayloadout = ConceptAuthorityClientUtils.createConceptAuthorityInstance(displayName, shortIdentifier, SERVICE_COMMON_PART_NAME);
+               return poxPayloadout.asXML();
+       }
+
+       @Override
+       public String createAuthorityItemInstance(String shortIdentifier, String displayName) {
+               // TODO Auto-generated method stub
+               return null;
+       }
 }
index 5b3f20fd0ad8a8b5b469f833b1a6065cbb3de458..1f122616a8374d7d1330f3b2047d67884b17da09 100644 (file)
@@ -10,12 +10,13 @@ import javax.ws.rs.core.MultivaluedMap;
 import javax.ws.rs.core.Response;
 
 import org.apache.commons.io.FileUtils;
+
 import org.collectionspace.services.client.test.ServiceRequestType;
 import org.collectionspace.services.common.api.Tools;
 import org.collectionspace.services.concept.ConceptTermGroup;
 import org.collectionspace.services.concept.ConceptauthoritiesCommon;
+
 import org.dom4j.DocumentException;
-import org.jboss.resteasy.client.ClientResponse;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
index 8b63a326f430925896746d188333d8640a8234e2..9c18f810d77e55f0f18b3e791d14100f0421f8e1 100644 (file)
             <xs:element name="web-url" type="xs:string" minOccurs="1" maxOccurs="1"></xs:element>
             <xs:element name="title-ref" type="xs:string" minOccurs="1" maxOccurs="1"></xs:element>
             <xs:element name="title" type="xs:string" minOccurs="1" maxOccurs="1"></xs:element>
-<!--            <xs:element ref="termList"/> -->
+            <xs:element ref="termList"/>
         </xs:sequence>
     </xs:complexType>
         
-<!--
     <xs:element name="termList">
         <xs:complexType>
             <xs:sequence>
             <xs:attribute name="id" use="required" type="xs:NCName"/>
         </xs:complexType>
     </xs:element>
--->
     
     <!--
         ServiceObjectType defines the manifest for a collectionspace
index 2b2f35c86f2a5948d90ce97c39e453a501e155cb..efe97c7d6105cb3f95792ad7a70a603c4f301943 100644 (file)
@@ -83,4 +83,16 @@ public class LocationAuthorityClient extends AuthorityClientImpl<Locationauthori
     public void setInAuthority(LocationsCommon item, String inAuthorityCsid) {
         item.setInAuthority(inAuthorityCsid);
     }
+
+       @Override
+       public String createAuthorityInstance(String shortIdentifier, String displayName) {
+               PoxPayloadOut poxPayloadout = LocationAuthorityClientUtils.createLocationAuthorityInstance(displayName, shortIdentifier, SERVICE_COMMON_PART_NAME);
+               return poxPayloadout.asXML();
+       }
+
+       @Override
+       public String createAuthorityItemInstance(String shortIdentifier, String displayName) {
+               // TODO Auto-generated method stub
+               return null;
+       }
 }
index aa48b0423b2ab881b5822017dbf9d8af2fb160fa..4385643a1fdaaa3841ffd4c49b37436e9fad3521 100644 (file)
@@ -23,6 +23,7 @@ import org.collectionspace.services.material.MaterialsCommon;
  */
 public class MaterialAuthorityClient extends AuthorityClientImpl<MaterialauthoritiesCommon, MaterialsCommon, MaterialAuthorityProxy> {
 
+       public static final String SERVICE_BINDING_NAME = "MaterialAuthority";
     public static final String SERVICE_NAME = "materialauthorities";
     public static final String SERVICE_PATH_COMPONENT = SERVICE_NAME;
     public static final String SERVICE_PATH = "/" + SERVICE_PATH_COMPONENT;
@@ -81,4 +82,16 @@ public class MaterialAuthorityClient extends AuthorityClientImpl<Materialauthori
     public void setInAuthority(MaterialsCommon item, String inAuthorityCsid) {
         item.setInAuthority(inAuthorityCsid);
     }
+
+       @Override
+       public String createAuthorityInstance(String shortIdentifier, String displayName) {
+               PoxPayloadOut poxPayloadOut = MaterialAuthorityClientUtils.createMaterialAuthorityInstance(displayName, shortIdentifier, SERVICE_COMMON_PART_NAME);
+               return poxPayloadOut.asXML();
+       }
+
+       @Override
+       public String createAuthorityItemInstance(String shortIdentifier, String displayName) {
+               // TODO Auto-generated method stub
+               return null;
+       }
 }
index 789929283720edb51628f36bc6ed1f203a157261..16f33c3fcde4cae4f83cd8f8d9a5c6ffd2757d77 100644 (file)
@@ -40,7 +40,7 @@ public class MaterialAuthorityClientUtils {
         materialAuthority.setShortIdentifier(shortIdentifier);
         String refName = createMaterialAuthRefName(shortIdentifier, displayName);
         materialAuthority.setRefName(refName);
-        materialAuthority.setVocabType("MaterialAuthority"); //FIXME: REM - Should this really be hard-coded?
+        materialAuthority.setVocabType(MaterialAuthorityClient.SERVICE_BINDING_NAME);
         PoxPayloadOut multipart = new PoxPayloadOut(MaterialAuthorityClient.SERVICE_PAYLOAD_NAME);
         PayloadOutputPart commonPart = multipart.addPart(materialAuthority, MediaType.APPLICATION_XML_TYPE);
         commonPart.setLabel(headerLabel);
index ddc46ba4b9ccbf2468b2d3dbf7c4aa0c24e52386..5b807403b8d5e34b6df5ad74fa4aec730497690d 100644 (file)
@@ -94,4 +94,16 @@ public class OrgAuthorityClient extends AuthorityWithContactsClientImpl<Orgautho
     public void setInAuthority(OrganizationsCommon item, String inAuthorityCsid) {
         item.setInAuthority(inAuthorityCsid);
     }
+
+       @Override
+       public String createAuthorityInstance(String shortIdentifier, String displayName) {
+               PoxPayloadOut poxPayloadout = OrgAuthorityClientUtils.createOrgAuthorityInstance(displayName, shortIdentifier, SERVICE_COMMON_PART_NAME);
+               return poxPayloadout.asXML();
+       }
+
+       @Override
+       public String createAuthorityItemInstance(String shortIdentifier, String displayName) {
+               // TODO Auto-generated method stub
+               return null;
+       }
 }
index 482690fc6cd52bd70f79918b75616c503766944b..c59f88a986c15c56bb8a47bb10336016601e2e5f 100644 (file)
@@ -92,4 +92,19 @@ public class PersonAuthorityClient extends AuthorityWithContactsClientImpl<Perso
     public void setInAuthority(PersonsCommon item, String inAuthorityCsid) {
         item.setInAuthority(inAuthorityCsid);
     }
+
+    //
+    // Should return a valid XML payload for creating an authority instance
+    //
+       @Override
+       public String createAuthorityInstance(String shortIdentifier, String displayName) {
+               PoxPayloadOut personAuthorityInstance = PersonAuthorityClientUtils.createPersonAuthorityInstance(displayName, shortIdentifier, SERVICE_COMMON_PART_NAME);
+               return personAuthorityInstance.asXML();
+       }
+
+       @Override
+       public String createAuthorityItemInstance(String shortIdentifier, String displayName) {
+               PoxPayloadOut personAuthorityInstance = PersonAuthorityClientUtils.createPersonInstance(shortIdentifier, displayName, SERVICE_COMMON_PART_NAME);
+               return personAuthorityInstance.asXML();
+       }
 }
index f9b25752f7b127376c07256afe5e63b28acc3448..029da410e7bd1db1e382db86668a86b3b0dd37e0 100644 (file)
@@ -127,7 +127,7 @@ public class PersonAuthorityClientUtils {
                res.close();
         }
     }
-
+    
     /**
      * Creates the person authority instance.
      *
@@ -155,6 +155,19 @@ public class PersonAuthorityClientUtils {
         return multipart;
     }
 
+    /*
+     * Create a very simple Person term -just a short ID and display name.
+     */
+       public static PoxPayloadOut createPersonInstance(String shortIdentifier, String displayName,
+                       String headerLabel) {
+               List<PersonTermGroup> terms = getTermGroupInstance(shortIdentifier, displayName);
+               
+               Map<String, String> personInfo = new HashMap<String, String>();
+       personInfo.put(PersonJAXBSchema.SHORT_IDENTIFIER, shortIdentifier);
+
+               return createPersonInstance(null, null, personInfo, terms, null, headerLabel);
+       }    
+    
     /**
      * Creates a person instance.
      *
@@ -164,16 +177,16 @@ public class PersonAuthorityClientUtils {
      * @param headerLabel the header label
      * @return the multipart output
      */
-    public static PoxPayloadOut createPersonInstance(String inAuthority,
+    public static PoxPayloadOut createPersonInstance(
+               String inAuthority,
                String personAuthRefName,
                Map<String, String> personInfo,
             List<PersonTermGroup> terms,
-               String headerLabel){
+               String headerLabel) {
         if (terms == null || terms.isEmpty()) {
             terms = getTermGroupInstance(getGeneratedIdentifier());
         }
-        final Map<String, List<String>> EMPTY_PERSON_REPEATABLES_INFO =
-                new HashMap<String, List<String>>();
+        final Map<String, List<String>> EMPTY_PERSON_REPEATABLES_INFO = new HashMap<String, List<String>>();
         return createPersonInstance(inAuthority, null /*personAuthRefName*/,
                 personInfo, terms, EMPTY_PERSON_REPEATABLES_INFO, headerLabel);
     }
@@ -189,12 +202,14 @@ public class PersonAuthorityClientUtils {
      * @param headerLabel the header label
      * @return the multipart output
      */
-    public static PoxPayloadOut createPersonInstance(String inAuthority, 
+    public static PoxPayloadOut createPersonInstance(
+               String inAuthority,
                String personAuthRefName,
                Map<String, String> personInfo,
             List<PersonTermGroup> terms,
             Map<String, List<String>> personRepeatablesInfo,
-            String headerLabel){
+            String headerLabel) {
+       
         PersonsCommon person = new PersonsCommon();
         person.setInAuthority(inAuthority);
        String shortId = personInfo.get(PersonJAXBSchema.SHORT_IDENTIFIER);
@@ -203,29 +218,30 @@ public class PersonAuthorityClientUtils {
        }       
        person.setShortIdentifier(shortId);
        
-       String value;
-        List<String> values = null;
+        if (personInfo != null) {
+               String value;
 
-        if((value = (String)personInfo.get(PersonJAXBSchema.BIRTH_DATE))!=null) {
-            StructuredDateGroup birthDate = new StructuredDateGroup();
-            birthDate.setDateDisplayDate(value);
-            person.setBirthDateGroup(birthDate);
-        }
-        if((value = (String)personInfo.get(PersonJAXBSchema.DEATH_DATE))!=null) {
-            StructuredDateGroup deathDate = new StructuredDateGroup();
-            deathDate.setDateDisplayDate(value);
-            person.setDeathDateGroup(deathDate);
+                       if ((value = personInfo.get(PersonJAXBSchema.BIRTH_DATE)) != null) {
+                               StructuredDateGroup birthDate = new StructuredDateGroup();
+                               birthDate.setDateDisplayDate(value);
+                               person.setBirthDateGroup(birthDate);
+                       }
+                       if ((value = personInfo.get(PersonJAXBSchema.DEATH_DATE)) != null) {
+                               StructuredDateGroup deathDate = new StructuredDateGroup();
+                               deathDate.setDateDisplayDate(value);
+                               person.setDeathDateGroup(deathDate);
+                       }
+                       if ((value = personInfo.get(PersonJAXBSchema.BIRTH_PLACE)) != null)
+                               person.setBirthPlace(value);
+                       if ((value = personInfo.get(PersonJAXBSchema.DEATH_PLACE)) != null)
+                               person.setDeathPlace(value);
+                       if ((value = personInfo.get(PersonJAXBSchema.GENDER)) != null)
+                               person.setGender(value);
+                       if ((value = personInfo.get(PersonJAXBSchema.BIO_NOTE)) != null)
+                               person.setBioNote(value);
+                       if ((value = personInfo.get(PersonJAXBSchema.NAME_NOTE)) != null)
+                               person.setNameNote(value);
         }
-        if((value = (String)personInfo.get(PersonJAXBSchema.BIRTH_PLACE))!=null)
-               person.setBirthPlace(value);
-        if((value = (String)personInfo.get(PersonJAXBSchema.DEATH_PLACE))!=null)
-               person.setDeathPlace(value);
-        if((value = (String)personInfo.get(PersonJAXBSchema.GENDER))!=null)
-               person.setGender(value);
-         if((value = (String)personInfo.get(PersonJAXBSchema.BIO_NOTE))!=null)
-               person.setBioNote(value);
-        if((value = (String)personInfo.get(PersonJAXBSchema.NAME_NOTE))!=null)
-               person.setNameNote(value);
         
         // Set values in the Term Information Group
         PersonTermGroupList termList = new PersonTermGroupList();
@@ -235,41 +251,41 @@ public class PersonAuthorityClientUtils {
         termList.getPersonTermGroup().addAll(terms); 
         person.setPersonTermGroupList(termList);
         
-        if (personRepeatablesInfo != null) {
-            if((values = (List<String>)personRepeatablesInfo.get(PersonJAXBSchema.GROUPS))!=null) {
-                    GroupList groupsList = new GroupList();
-                    List<String> groups = groupsList.getGroup();
-                    groups.addAll(values);
-                    person.setGroups(groupsList);
-            }
-            if((values = (List<String>)personRepeatablesInfo.get(PersonJAXBSchema.NATIONALITIES))!=null) {
-                    NationalityList nationalitiesList = new NationalityList();
-                    List<String> nationalities = nationalitiesList.getNationality();
-                    nationalities.addAll(values);
-                    person.setNationalities(nationalitiesList);
-            }
+               if (personRepeatablesInfo != null) {
+                       List<String> values = null;
 
-            if((values = (List<String>)personRepeatablesInfo.get(PersonJAXBSchema.OCCUPATIONS))!=null) {
-                    OccupationList occupationsList = new OccupationList();
-                    List<String> occupations = occupationsList.getOccupation();
-                    occupations.addAll(values);
-                    person.setOccupations(occupationsList);
-            }
-            if((values = (List<String>)personRepeatablesInfo.get(PersonJAXBSchema.SCHOOLS_OR_STYLES))!=null) {
-                    SchoolOrStyleList schoolOrStyleList = new SchoolOrStyleList();
-                    List<String> schoolsOrStyles = schoolOrStyleList.getSchoolOrStyle();
-                    schoolsOrStyles.addAll(values);
-                    person.setSchoolsOrStyles(schoolOrStyleList);
-            }        
-        }
+                       if ((values = (List<String>) personRepeatablesInfo.get(PersonJAXBSchema.GROUPS)) != null) {
+                               GroupList groupsList = new GroupList();
+                               List<String> groups = groupsList.getGroup();
+                               groups.addAll(values);
+                               person.setGroups(groupsList);
+                       }
+                       if ((values = (List<String>) personRepeatablesInfo.get(PersonJAXBSchema.NATIONALITIES)) != null) {
+                               NationalityList nationalitiesList = new NationalityList();
+                               List<String> nationalities = nationalitiesList.getNationality();
+                               nationalities.addAll(values);
+                               person.setNationalities(nationalitiesList);
+                       }
+
+                       if ((values = (List<String>) personRepeatablesInfo.get(PersonJAXBSchema.OCCUPATIONS)) != null) {
+                               OccupationList occupationsList = new OccupationList();
+                               List<String> occupations = occupationsList.getOccupation();
+                               occupations.addAll(values);
+                               person.setOccupations(occupationsList);
+                       }
+                       if ((values = (List<String>) personRepeatablesInfo.get(PersonJAXBSchema.SCHOOLS_OR_STYLES)) != null) {
+                               SchoolOrStyleList schoolOrStyleList = new SchoolOrStyleList();
+                               List<String> schoolsOrStyles = schoolOrStyleList.getSchoolOrStyle();
+                               schoolsOrStyles.addAll(values);
+                               person.setSchoolsOrStyles(schoolOrStyleList);
+                       }
+               }
 
-        
         PoxPayloadOut multipart = new PoxPayloadOut(PersonAuthorityClient.SERVICE_ITEM_PAYLOAD_NAME);
-        PayloadOutputPart commonPart = multipart.addPart(person,
-            MediaType.APPLICATION_XML_TYPE);
+        PayloadOutputPart commonPart = multipart.addPart(person, MediaType.APPLICATION_XML_TYPE);
         commonPart.setLabel(headerLabel);
 
-        if(logger.isDebugEnabled()){
+        if (logger.isDebugEnabled()) {
                logger.debug("to be created, person common ", person, PersonsCommon.class);
         }
 
@@ -457,14 +473,22 @@ public class PersonAuthorityClientUtils {
                return newStr.toString();
     }
     
-    public static List<PersonTermGroup> getTermGroupInstance(String identifier) {
-        if (Tools.isBlank(identifier)) {
-            identifier = getGeneratedIdentifier();
+    private static List<PersonTermGroup> getTermGroupInstance(String shortIdentifier) {
+       return getTermGroupInstance(shortIdentifier, shortIdentifier);
+    }
+    
+    public static List<PersonTermGroup> getTermGroupInstance(String shortIdentifier, String displayName) {
+        if (Tools.isBlank(shortIdentifier)) {
+               shortIdentifier = getGeneratedIdentifier();
+        }
+        if (Tools.isBlank(shortIdentifier)) {
+            displayName = shortIdentifier;
         }
+        
         List<PersonTermGroup> terms = new ArrayList<PersonTermGroup>();
         PersonTermGroup term = new PersonTermGroup();
-        term.setTermDisplayName(identifier);
-        term.setTermName(identifier);
+        term.setTermDisplayName(displayName);
+        term.setTermName(shortIdentifier);
         terms.add(term);
         return terms;
     }
@@ -476,6 +500,5 @@ public class PersonAuthorityClientUtils {
     private static String createIdentifier() {
         long identifier = System.currentTimeMillis() + random.nextInt();
         return Long.toString(identifier);
-    }    
-
+    }
 }
index d1eaaefaa9b63888ed11c37c95dfe4af22964885..5723fbd719d286715b21bc02487addde29963751 100644 (file)
@@ -81,4 +81,16 @@ public class PlaceAuthorityClient extends AuthorityClientImpl<PlaceauthoritiesCo
     public void setInAuthority(PlacesCommon item, String inAuthorityCsid) {
         item.setInAuthority(inAuthorityCsid);
     }
+
+       @Override
+       public String createAuthorityInstance(String shortIdentifier, String displayName) {
+               PoxPayloadOut poxPayloadout = PlaceAuthorityClientUtils.createPlaceAuthorityInstance(displayName, shortIdentifier, SERVICE_COMMON_PART_NAME);
+               return poxPayloadout.asXML();
+       }
+
+       @Override
+       public String createAuthorityItemInstance(String shortIdentifier, String displayName) {
+               // TODO Auto-generated method stub
+               return null;
+       }
 }
index 76e9a9b875800c62b4b8a3778df7f8a04bd4f615..f05614a33f9b3d3ec7716677a67ec27ef2cb8024 100644 (file)
@@ -92,4 +92,16 @@ public class TaxonomyAuthorityClient extends AuthorityClientImpl<Taxonomyauthori
        public void setInAuthority(TaxonCommon item, String inAuthorityCsid) {
                item.setInAuthority(inAuthorityCsid);
        }
+
+       @Override
+       public String createAuthorityInstance(String shortIdentifier, String displayName) {
+               PoxPayloadOut poxPayloadout = TaxonomyAuthorityClientUtils.createTaxonomyAuthorityInstance(displayName, shortIdentifier, SERVICE_COMMON_PART_NAME);
+               return poxPayloadout.asXML();
+       }
+
+       @Override
+       public String createAuthorityItemInstance(String shortIdentifier, String displayName) {
+               // TODO Auto-generated method stub
+               return null;
+       }
 }
index 43b562ab257d91556aab7a534a3ddee5d0aea374..91a1888feb3e0613e6549416144fdce0be421de2 100644 (file)
@@ -104,4 +104,16 @@ public class VocabularyClient extends AuthorityClientImpl<VocabulariesCommon, Vo
        public String getInAuthority(VocabularyitemsCommon item) {
                return item.getInAuthority();
        }
+
+       @Override
+       public String createAuthorityInstance(String shortIdentifier, String displayName) {
+               PoxPayloadOut poxPayloadout = VocabularyClientUtils.createVocabularyInstance(displayName, shortIdentifier, SERVICE_COMMON_PART_NAME);
+               return poxPayloadout.asXML();
+       }
+
+       @Override
+       public String createAuthorityItemInstance(String shortIdentifier, String displayName) {
+               PoxPayloadOut poxPayloadout = VocabularyClientUtils.createVocabularyItemInstance(displayName, shortIdentifier, SERVICE_COMMON_PART_NAME);
+               return poxPayloadout.asXML();
+       }
 }
index 56709df5fc531e5adc17858f0a9ceb605ec4437c..f5b8d748b726780bcd23800ea06f61f26b549dc9 100644 (file)
@@ -11,9 +11,7 @@ import org.collectionspace.services.common.vocabulary.AuthorityItemJAXBSchema;
 import org.collectionspace.services.client.test.ServiceRequestType;
 import org.collectionspace.services.vocabulary.VocabularyitemsCommon;
 import org.collectionspace.services.vocabulary.VocabulariesCommon;
-import org.jboss.resteasy.client.ClientResponse;
-//import org.jboss.resteasy.plugins.providers.multipart.PoxPayloadOut;
-//import org.jboss.resteasy.plugins.providers.multipart.OutputPart;
+
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -21,7 +19,7 @@ public class VocabularyClientUtils {
     private static final Logger logger =
         LoggerFactory.getLogger(VocabularyClientUtils.class);
     
-    public static PoxPayloadOut createEnumerationInstance(
+    public static PoxPayloadOut createVocabularyInstance(
                String displayName, String shortIdentifier, String headerLabel ) {
         VocabulariesCommon vocabulary = new VocabulariesCommon();
         vocabulary.setDisplayName(displayName);
@@ -41,14 +39,17 @@ public class VocabularyClientUtils {
         return multipart;
     }
 
-               // Note that we do not use the map, but we will once we add more info to the 
-               // items
     public static PoxPayloadOut createVocabularyItemInstance( 
                String vocabularyRefName, Map<String, String> vocabItemInfo, String headerLabel){
-        VocabularyitemsCommon vocabularyItem = new VocabularyitemsCommon();
        String shortId = vocabItemInfo.get(AuthorityItemJAXBSchema.SHORT_IDENTIFIER);
        String displayName = vocabItemInfo.get(AuthorityItemJAXBSchema.DISPLAY_NAME);
-               vocabularyItem.setShortIdentifier(shortId);
+       return createVocabularyItemInstance(displayName, shortId, headerLabel);
+    }
+    
+    public static PoxPayloadOut createVocabularyItemInstance(
+               String displayName, String shortIdentifier, String headerLabel ){
+        VocabularyitemsCommon vocabularyItem = new VocabularyitemsCommon();
+               vocabularyItem.setShortIdentifier(shortIdentifier);
                vocabularyItem.setDisplayName(displayName);
        //String refName = createVocabularyItemRefName(vocabularyRefName, shortId, displayName);
                //vocabularyItem.setRefName(refName);
@@ -62,7 +63,7 @@ public class VocabularyClientUtils {
         }
 
         return multipart;
-    }
+    }    
 
     public static String createItemInVocabulary(String vcsid, 
                String vocabularyRefName, Map<String,String> itemMap,
index 2d7883a16f7a2b249de13dcd04e79d4dfe2ccc77..2d546a1009cecebd128b6cc44adab13de73f866b 100644 (file)
@@ -106,7 +106,7 @@ public class VocabularyServiceTest extends AbstractAuthorityServiceTest<Vocabula
 
         // Submit the request to the service and store the response.
         VocabularyClient client = new VocabularyClient();
-        PoxPayloadOut multipart = VocabularyClientUtils.createEnumerationInstance(
+        PoxPayloadOut multipart = VocabularyClientUtils.createVocabularyInstance(
                 "Vocab with Bad Short Id", "Bad Short Id!", client.getCommonPartName());
         Response res = client.create(multipart);
         try {
@@ -126,7 +126,7 @@ public class VocabularyServiceTest extends AbstractAuthorityServiceTest<Vocabula
         // Create a new vocabulary
         String shortId = "nonunique" + random.nextInt(1000); // Prevent collisions with past test sessions that never cleaned up properly
         VocabularyClient client = new VocabularyClient();
-        PoxPayloadOut multipart = VocabularyClientUtils.createEnumerationInstance(
+        PoxPayloadOut multipart = VocabularyClientUtils.createVocabularyInstance(
                 "Vocab with non-unique Short Id", shortId, client.getCommonPartName());
         Response res = client.create(multipart);
         try {
@@ -313,7 +313,7 @@ public class VocabularyServiceTest extends AbstractAuthorityServiceTest<Vocabula
        protected PoxPayloadOut createInstance(String commonPartName,
                        String identifier) {
         String displayName = "displayName-" + identifier;
-        PoxPayloadOut result = VocabularyClientUtils.createEnumerationInstance(
+        PoxPayloadOut result = VocabularyClientUtils.createVocabularyInstance(
                 displayName, identifier, commonPartName);
                return result;
        }
index 0209e4c2743669eb7a0b551146a63b8d9a5f1992..8057795eb5436a143fae51d62bc1af16c8d3adf1 100644 (file)
@@ -81,4 +81,16 @@ public class WorkAuthorityClient extends AuthorityClientImpl<WorkauthoritiesComm
     public void setInAuthority(WorksCommon item, String inAuthorityCsid) {
         item.setInAuthority(inAuthorityCsid);
     }
+
+       @Override
+       public String createAuthorityInstance(String shortIdentifier, String displayName) {
+               PoxPayloadOut poxPayloadout = WorkAuthorityClientUtils.createWorkAuthorityInstance(displayName, shortIdentifier, SERVICE_COMMON_PART_NAME);
+               return poxPayloadout.asXML();
+       }
+
+       @Override
+       public String createAuthorityItemInstance(String shortIdentifier, String displayName) {
+               // TODO Auto-generated method stub
+               return null;
+       }
 }