]> git.aero2k.de Git - tmp/jakarta-migration.git/commitdiff
DRYD-202: PUT requests to /vocabularies/${csid} that include an items-list part now...
authorremillet <remillet@yahoo.com>
Fri, 26 Jan 2018 19:05:42 +0000 (11:05 -0800)
committerremillet <remillet@yahoo.com>
Fri, 26 Jan 2018 19:05:42 +0000 (11:05 -0800)
services/authority/service/src/main/java/org/collectionspace/services/common/vocabulary/AuthorityResource.java
services/authority/service/src/main/java/org/collectionspace/services/common/vocabulary/nuxeo/AuthorityIdentifierUtils.java
services/vocabulary/service/src/main/java/org/collectionspace/services/vocabulary/VocabularyResource.java

index 4bd7077265fb9ae29c4b478b75bb50db676f2566..c73266f2dd07e30d728f24b386c063d6a8b57400 100644 (file)
@@ -569,6 +569,7 @@ public abstract class AuthorityResource<AuthCommon, AuthItemHandler>
     @PUT
     @Path("{csid}")
     public byte[] updateAuthority(
+               @Context Request request,
                @Context ResourceMap resourceMap,
                @Context UriInfo uriInfo,               
             @PathParam("csid") String specifier,
index 6389a516425b441ffa8da5a3b207608c8ea17392..0272c9216360d2c71030566dfac4a3e4a920105e 100644 (file)
@@ -23,7 +23,6 @@
  */
 package org.collectionspace.services.common.vocabulary.nuxeo;
 
-import org.collectionspace.services.common.api.Tools;
 import org.collectionspace.services.common.api.Tools;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -45,7 +44,7 @@ public class AuthorityIdentifierUtils {
     // FIXME: Verify uniqueness before returning the generated short identifier.
     // FIXME: Consider using a hash of the display name, rather than a timestamp,
     // when it is necessary to add a suffix for uniqueness.
-    protected static String generateShortIdentifierFromDisplayName(String displayName, String shortDisplayName) {
+    public static String generateShortIdentifierFromDisplayName(String displayName, String shortDisplayName) {
         String generatedShortIdentifier = "";
         if (Tools.notEmpty(displayName)) {
             generatedShortIdentifier = displayName + '-' + Tools.now().toString();
@@ -62,6 +61,4 @@ public class AuthorityIdentifierUtils {
         }
         return generatedShortIdentifier;
     }
-
-
 }
index 1ae94b8c151ff22a384eb70fb4acb4d162515ce1..7a924496b7a9759188cfe5ff0656875fdf5a528d 100644 (file)
@@ -46,6 +46,7 @@ import org.collectionspace.services.common.vocabulary.AuthorityServiceUtils;
 import org.collectionspace.services.common.vocabulary.RefNameServiceUtils;
 import org.collectionspace.services.common.vocabulary.RefNameServiceUtils.Specifier;
 import org.collectionspace.services.common.vocabulary.RefNameServiceUtils.SpecifierForm;
+import org.collectionspace.services.common.vocabulary.nuxeo.AuthorityIdentifierUtils;
 import org.collectionspace.services.jaxb.AbstractCommonList;
 import org.collectionspace.services.jaxb.AbstractCommonList.ListItem;
 import org.collectionspace.services.nuxeo.client.java.CoreSessionInterface;
@@ -142,6 +143,7 @@ public class VocabularyResource extends
     @Path("{csid}")
     @Override
     public byte[] updateAuthority(
+               @Context Request request,
                @Context ResourceMap resourceMap,
                @Context UriInfo ui,
             @PathParam("csid") String specifier,
@@ -165,8 +167,11 @@ public class VocabularyResource extends
                        csid = getRepositoryClient(ctx).findDocCSID(null, ctx, whereClause);
                    }
                    getRepositoryClient(ctx).update(ctx, csid, handler);
-                   handleItemsPayload(Method.PUT, ctx, csid, resourceMap, uriInfo, theUpdate);
-                   result = ctx.getOutput();
+                   if (handleItemsPayload(Method.PUT, ctx, csid, resourceMap, uriInfo, theUpdate) == true) {
+                       result = this.getAuthority(ctx, request, uriInfo, specifier, true);
+                   } else {
+                       result = ctx.getOutput();
+                   }
             } catch (Throwable t) {
                repoSession.setTransactionRollbackOnly();
                throw t;
@@ -375,7 +380,7 @@ public class VocabularyResource extends
                ResourceMap resourceMap,
                UriInfo uriInfo,
                PoxPayloadIn input) throws Exception {
-       boolean result = true;
+       boolean result = false;
        
        PayloadInputPart abstractCommonListPart  = input.getPart(PoxPayload.ABSTRACT_COMMON_LIST_ROOT_ELEMENT_LABEL);
        if (abstractCommonListPart != null) {
@@ -388,6 +393,7 @@ public class VocabularyResource extends
                            updateWithItemsPayload(itemsList, existingCtx, parentIdentifier, resourceMap, uriInfo, input);
                                break;                                  
                        }
+                       result = true; // mark that we've handled an items-list payload
        }
        
        return result;
@@ -493,14 +499,12 @@ public class VocabularyResource extends
                                        break;
                        }
                }
-               
+               //
+               // We need to create a short ID if one wasn't supplied
+               //
                if (Tools.isEmpty(vocabularyItem.getShortIdentifier())) {
-                       //
-                       // We need to create a short ID since one wasn't supplied
-                       //
-                       String value = String.format("%s%d", getDisplayName(item), System.currentTimeMillis());
-                       value = DatatypeConverter.printHexBinary(value.getBytes()).toUpperCase();
-                       vocabularyItem.setShortIdentifier(value);
+                       vocabularyItem.setShortIdentifier(AuthorityIdentifierUtils.generateShortIdentifierFromDisplayName(
+                                       vocabularyItem.getDisplayName() , null)); ;
                }
                
                result = new PoxPayloadIn(VocabularyClient.SERVICE_ITEM_PAYLOAD_NAME, vocabularyItem,