]> git.aero2k.de Git - tmp/jakarta-migration.git/commitdiff
NOJIRA: Added support for concept and org term initialization at startup.
authorRichard Millet <remillet@yahoo.com>
Wed, 27 Jun 2018 19:48:10 +0000 (12:48 -0700)
committerRichard Millet <remillet@yahoo.com>
Wed, 27 Jun 2018 19:48:10 +0000 (12:48 -0700)
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/concept/service/src/main/java/org/collectionspace/services/concept/nuxeo/ConceptValidatorHandler.java
services/organization/client/src/main/java/org/collectionspace/services/client/OrgAuthorityClient.java
services/organization/client/src/main/java/org/collectionspace/services/client/OrgAuthorityClientUtils.java
services/organization/service/src/main/java/org/collectionspace/services/organization/nuxeo/OrganizationValidatorHandler.java
services/person/client/src/main/java/org/collectionspace/services/client/PersonAuthorityClient.java
services/person/service/src/main/java/org/collectionspace/services/person/nuxeo/PersonValidatorHandler.java

index 651a26ab2a0dcdf37ccedeb1d4e5741401232133..1c7fece550ca429751cd294e8e69c44c65f9c571 100644 (file)
@@ -98,7 +98,7 @@ public class ConceptAuthorityClient extends AuthorityClientImpl<Conceptauthoriti
 
        @Override
        public String createAuthorityItemInstance(String shortIdentifier, String displayName) {
-               // TODO Auto-generated method stub
-               return null;
+           PoxPayloadOut conceptItemInstance = ConceptAuthorityClientUtils.createConceptInstance(shortIdentifier, displayName, SERVICE_ITEM_COMMON_PART_NAME);
+        return conceptItemInstance.asXML();
        }
 }
index 1f122616a8374d7d1330f3b2047d67884b17da09..0fd9a7d95c205dbdfb1c41198fe748832b11428f 100644 (file)
@@ -3,19 +3,24 @@ package org.collectionspace.services.client;
 import java.io.File;
 import java.util.ArrayList;
 import java.util.Date;
+import java.util.HashMap;
 import java.util.List;
+import java.util.Map;
 
 import javax.ws.rs.core.MediaType;
 import javax.ws.rs.core.MultivaluedMap;
 import javax.ws.rs.core.Response;
 
-import org.apache.commons.io.FileUtils;
-
+import org.collectionspace.services.ConceptJAXBSchema;
 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.ConceptTermGroupList;
 import org.collectionspace.services.concept.ConceptauthoritiesCommon;
+import org.collectionspace.services.concept.ConceptsCommon;
 
+import org.apache.commons.io.FileUtils;
 import org.dom4j.DocumentException;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -48,6 +53,41 @@ public class ConceptAuthorityClientUtils {
 
         return multipart;
     }
+    
+    /**
+     * Creates a concept instance.
+     *
+     */
+    public static PoxPayloadOut createConceptInstance(
+            Map<String, String> conceptInfo,
+            List<ConceptTermGroup> terms,
+            String headerLabel) {
+        
+        ConceptsCommon concept = new ConceptsCommon();
+        String shortId = conceptInfo.get(ConceptJAXBSchema.SHORT_IDENTIFIER);
+        if (shortId == null || shortId.isEmpty()) {
+            throw new IllegalArgumentException("shortIdentifier cannot be null or empty");
+        }       
+        concept.setShortIdentifier(shortId);
+                
+        // Set values in the Term Information Group
+        ConceptTermGroupList termList = new ConceptTermGroupList();
+        if (terms == null || terms.isEmpty()) {
+            terms = getTermGroupInstance(getGeneratedIdentifier());
+        }
+        termList.getConceptTermGroup().addAll(terms); 
+        concept.setConceptTermGroupList(termList);
+        
+        PoxPayloadOut multipart = new PoxPayloadOut(ConceptAuthorityClient.SERVICE_ITEM_PAYLOAD_NAME);
+        PayloadOutputPart commonPart = multipart.addPart(concept, MediaType.APPLICATION_XML_TYPE);
+        commonPart.setLabel(headerLabel);
+
+        if (logger.isDebugEnabled()) {
+            logger.debug("to be created, concept common ", concept, ConceptsCommon.class);
+        }
+
+        return multipart;
+    }    
 
     /**
      * @param commonPartXML the XML payload for the common part.
@@ -73,6 +113,35 @@ public class ConceptAuthorityClientUtils {
 
         return multipart;
     }
+
+    public static List<ConceptTermGroup> getTermGroupInstance(String shortIdentifier, String displayName) {
+        if (Tools.isBlank(shortIdentifier)) {
+            shortIdentifier = getGeneratedIdentifier();
+        }
+        if (Tools.isBlank(shortIdentifier)) {
+            displayName = shortIdentifier;
+        }
+        
+        List<ConceptTermGroup> terms = new ArrayList<ConceptTermGroup>();
+        ConceptTermGroup term = new ConceptTermGroup();
+        term.setTermDisplayName(displayName);
+        term.setTermName(shortIdentifier);
+        terms.add(term);
+        return terms;
+    }
+    
+    /*
+     * Create a very simple Concept term -just a short ID and display name.
+     */
+    public static PoxPayloadOut createConceptInstance(String shortIdentifier, String displayName,
+            String headerLabel) {
+        List<ConceptTermGroup> terms = getTermGroupInstance(shortIdentifier, displayName);
+        
+        Map<String, String> conceptInfo = new HashMap<String, String>();
+        conceptInfo.put(ConceptJAXBSchema.SHORT_IDENTIFIER, shortIdentifier);
+
+        return createConceptInstance(conceptInfo, terms, headerLabel);
+    }       
     
     public static String createItemInAuthority(String vcsid,
                String commonPartXML,
index 8f5d342f03a3ac59f952051c5e6e6d4cd422400d..17a77961ef7349a95f841b6ffbd388dd8fdedf20 100644 (file)
@@ -67,7 +67,8 @@ public class ConceptValidatorHandler extends ValidatorHandlerImpl {
             try {
                 String shortId = concept.getShortIdentifier();
                 if (shortId != null) {
-                    CS_ASSERT(shortIdentifierContainsOnlyValidChars(shortId), SHORT_ID_BAD_CHARS_ERROR);
+                    String msg = String.format("%s: %s", SHORT_ID_BAD_CHARS_ERROR, shortId);
+                    CS_ASSERT(shortIdentifierContainsOnlyValidChars(shortId), msg);
                 }
                 CS_ASSERT(containsAtLeastOneTerm(concept), HAS_NO_TERMS_ERROR);
                 CS_ASSERT(allTermsContainDisplayName(concept), TERM_HAS_EMPTY_DISPLAYNAME_ERROR);
index 5b807403b8d5e34b6df5ad74fa4aec730497690d..bb2146d49a4266327a3c9fb7c22c429ddb7736dd 100644 (file)
@@ -103,7 +103,7 @@ public class OrgAuthorityClient extends AuthorityWithContactsClientImpl<Orgautho
 
        @Override
        public String createAuthorityItemInstance(String shortIdentifier, String displayName) {
-               // TODO Auto-generated method stub
-               return null;
+           PoxPayloadOut orgAuthorityInstance = OrgAuthorityClientUtils.createOrganizationInstance(shortIdentifier, displayName, SERVICE_ITEM_COMMON_PART_NAME);
+        return orgAuthorityInstance.asXML();
        }
 }
index 09f6f56d7ad50fa7bd234131dbb9a98c325d17d2..3d3618979afc06850104f017529bfd95ba5f8284 100644 (file)
@@ -29,6 +29,8 @@ import javax.ws.rs.core.Response;
 import org.collectionspace.services.OrganizationJAXBSchema;
 import org.collectionspace.services.client.test.ServiceRequestType;
 import org.collectionspace.services.common.api.Tools;
+
+import org.collectionspace.services.organization.StructuredDateGroup;
 import org.collectionspace.services.organization.ContactNameList;
 import org.collectionspace.services.organization.FunctionList;
 import org.collectionspace.services.organization.GroupList;
@@ -37,10 +39,10 @@ import org.collectionspace.services.organization.OrganizationsCommon;
 import org.collectionspace.services.organization.OrgauthoritiesCommon;
 import org.collectionspace.services.organization.OrgTermGroup;
 import org.collectionspace.services.organization.OrgTermGroupList;
+
 import org.jboss.resteasy.client.ClientResponse;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
-import org.collectionspace.services.organization.StructuredDateGroup;
 
 /**
  * OrgAuthorityClientUtils.
@@ -204,6 +206,37 @@ public class OrgAuthorityClientUtils {
        
        return result;
     }
+    
+    public static List<OrgTermGroup> getTermGroupInstance(String shortIdentifier, String displayName) {
+        if (Tools.isBlank(shortIdentifier)) {
+            shortIdentifier = getGeneratedIdentifier();
+        }
+        if (Tools.isBlank(shortIdentifier)) {
+            displayName = shortIdentifier;
+        }
+        
+        List<OrgTermGroup> terms = new ArrayList<OrgTermGroup>();
+        OrgTermGroup term = new OrgTermGroup();
+        term.setTermDisplayName(displayName);
+        term.setTermName(shortIdentifier);
+        terms.add(term);
+        return terms;
+    }
+    
+    /*
+     * Create a very simple Organization term -just a short ID and display name.
+     */
+    public static PoxPayloadOut createOrganizationInstance(String shortIdentifier, String displayName,
+            String headerLabel) {
+        List<OrgTermGroup> terms = getTermGroupInstance(shortIdentifier, displayName);
+        
+        Map<String, String> orgInfo = new HashMap<String, String>();
+        orgInfo.put(OrganizationJAXBSchema.SHORT_IDENTIFIER, shortIdentifier);
+        
+        final Map<String, List<String>> EMPTY_ORG_REPEATABLES_INFO = new HashMap<String, List<String>>();
+
+        return createOrganizationInstance(null, orgInfo, terms, EMPTY_ORG_REPEATABLES_INFO, headerLabel);
+    }      
 
     /**
      * Creates the organization instance.
@@ -234,14 +267,18 @@ public class OrgAuthorityClientUtils {
      * @return the multipart output
      */
     public static PoxPayloadOut createOrganizationInstance( 
-               String orgAuthRefName, Map<String, String> orgInfo, List<OrgTermGroup> terms,
-                Map<String, List<String>> orgRepeatablesInfo, String headerLabel){
+                       String orgAuthRefName, 
+                       Map<String, String> orgInfo, 
+                       List<OrgTermGroup> terms,
+                       Map<String, List<String>> orgRepeatablesInfo,
+                       String headerLabel) {
+        
         OrganizationsCommon organization = new OrganizationsCommon();
-       String shortId = orgInfo.get(OrganizationJAXBSchema.SHORT_IDENTIFIER);
-       if (shortId == null || shortId.isEmpty()) {
-               throw new IllegalArgumentException("shortIdentifier cannot be null or empty");
-       }       
-       organization.setShortIdentifier(shortId);
+               String shortId = orgInfo.get(OrganizationJAXBSchema.SHORT_IDENTIFIER);
+               if (shortId == null || shortId.isEmpty()) {
+                       throw new IllegalArgumentException("shortIdentifier cannot be null or empty");
+               }       
+               organization.setShortIdentifier(shortId);
                String value = null;
         List<String> values = null;
         
@@ -253,23 +290,23 @@ public class OrgAuthorityClientUtils {
         termList.getOrgTermGroup().addAll(terms); 
         organization.setOrgTermGroupList(termList);
         
-        if((values = (List<String>)orgRepeatablesInfo.get(OrganizationJAXBSchema.CONTACT_NAMES))!=null) {
+        if ((values = (List<String>)orgRepeatablesInfo.get(OrganizationJAXBSchema.CONTACT_NAMES))!=null) {
                 ContactNameList contactsList = new ContactNameList();
                 List<String> contactNames = contactsList.getContactName();
                contactNames.addAll(values);
                 organization.setContactNames(contactsList);
         }
-        if((value = (String)orgInfo.get(OrganizationJAXBSchema.FOUNDING_DATE))!=null) {
+        if ((value = (String)orgInfo.get(OrganizationJAXBSchema.FOUNDING_DATE))!=null) {
             StructuredDateGroup foundingDate = new StructuredDateGroup();
             foundingDate.setDateDisplayDate(value);
             organization.setFoundingDateGroup(foundingDate);
         }
-        if((value = (String)orgInfo.get(OrganizationJAXBSchema.DISSOLUTION_DATE))!=null) {
+        if ((value = (String)orgInfo.get(OrganizationJAXBSchema.DISSOLUTION_DATE))!=null) {
             StructuredDateGroup dissolutionDate = new StructuredDateGroup();
             dissolutionDate.setDateDisplayDate(value);
             organization.setDissolutionDateGroup(dissolutionDate);
         }
-        if((value = (String)orgInfo.get(OrganizationJAXBSchema.FOUNDING_PLACE))!=null)
+        if ((value = (String)orgInfo.get(OrganizationJAXBSchema.FOUNDING_PLACE))!=null)
                organization.setFoundingPlace(value);
         if((values = (List<String>)orgRepeatablesInfo.get(OrganizationJAXBSchema.GROUPS))!=null) {
                 GroupList groupsList = new GroupList();
@@ -277,13 +314,13 @@ public class OrgAuthorityClientUtils {
                groups.addAll(values);
                 organization.setGroups(groupsList);
         }
-        if((values = (List<String>)orgRepeatablesInfo.get(OrganizationJAXBSchema.FUNCTIONS))!=null) {
+        if ((values = (List<String>)orgRepeatablesInfo.get(OrganizationJAXBSchema.FUNCTIONS))!=null) {
                 FunctionList functionsList = new FunctionList();
                 List<String> functions = functionsList.getFunction();
                functions.addAll(values);
                 organization.setFunctions(functionsList);
         }
-        if((values = (List<String>)orgRepeatablesInfo.get(OrganizationJAXBSchema.HISTORY_NOTES))!=null) {
+        if ((values = (List<String>)orgRepeatablesInfo.get(OrganizationJAXBSchema.HISTORY_NOTES))!=null) {
                 HistoryNoteList historyNotesList = new HistoryNoteList();
                 List<String> historyNotes = historyNotesList.getHistoryNote();
                historyNotes.addAll(values);
@@ -296,7 +333,7 @@ public class OrgAuthorityClientUtils {
         commonPart.setLabel(headerLabel);
 
         if(logger.isDebugEnabled()){
-               logger.debug("to be created, organization common ", organization, OrganizationsCommon.class);
+                   logger.debug("to be created, organization common ", organization, OrganizationsCommon.class);
         }
 
         return multipart;
index c28a4c8f0e3a05b4400baa15a3bfb5d8939b5445..85c5b621c1cd28379d97d87f6a119dc92d5b6db9 100644 (file)
@@ -67,7 +67,8 @@ public class OrganizationValidatorHandler extends ValidatorHandlerImpl {
             try {
                 String shortId = organization.getShortIdentifier();
                 if (shortId != null) {
-                    CS_ASSERT(shortIdentifierContainsOnlyValidChars(shortId), SHORT_ID_BAD_CHARS_ERROR);
+                    String msg = String.format("%s: %s", SHORT_ID_BAD_CHARS_ERROR, shortId);
+                    CS_ASSERT(shortIdentifierContainsOnlyValidChars(shortId), msg);
                 }
                 CS_ASSERT(containsAtLeastOneTerm(organization), HAS_NO_TERMS_ERROR);
                 CS_ASSERT(allTermsContainDisplayName(organization), TERM_HAS_EMPTY_DISPLAYNAME_ERROR);
index c59f88a986c15c56bb8a47bb10336016601e2e5f..44e1a85c672397e68fb7cafe95ff49e9597fec47 100644 (file)
@@ -104,7 +104,7 @@ public class PersonAuthorityClient extends AuthorityWithContactsClientImpl<Perso
 
        @Override
        public String createAuthorityItemInstance(String shortIdentifier, String displayName) {
-               PoxPayloadOut personAuthorityInstance = PersonAuthorityClientUtils.createPersonInstance(shortIdentifier, displayName, SERVICE_COMMON_PART_NAME);
+               PoxPayloadOut personAuthorityInstance = PersonAuthorityClientUtils.createPersonInstance(shortIdentifier, displayName, SERVICE_ITEM_COMMON_PART_NAME);
                return personAuthorityInstance.asXML();
        }
 }
index 65e245ce30b7c74868145725a23959898cfbda1a..7fd666ffee126f61a6a73319fca21ddc41e6b9c5 100644 (file)
@@ -66,7 +66,8 @@ public class PersonValidatorHandler extends ValidatorHandlerImpl {
             try {
                 String shortId = person.getShortIdentifier();
                 if (shortId != null) {
-                    CS_ASSERT(shortIdentifierContainsOnlyValidChars(shortId), SHORT_ID_BAD_CHARS_ERROR);
+                    String msg = String.format("%s: %s", SHORT_ID_BAD_CHARS_ERROR, shortId);
+                    CS_ASSERT(shortIdentifierContainsOnlyValidChars(shortId), msg);
                 }
                 CS_ASSERT(containsAtLeastOneTerm(person), HAS_NO_TERMS_ERROR);
                 CS_ASSERT(allTermsContainDisplayName(person), TERM_HAS_EMPTY_DISPLAYNAME_ERROR);