]> git.aero2k.de Git - tmp/jakarta-migration.git/commitdiff
CSPACE-1895 Work towards adding repeating sections. For now, just put in notes in...
authorPatrick Schmitz <pschmitz@berkeley.edu>
Fri, 11 Jun 2010 20:02:41 +0000 (20:02 +0000)
committerPatrick Schmitz <pschmitz@berkeley.edu>
Fri, 11 Jun 2010 20:02:41 +0000 (20:02 +0000)
services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/DocumentModelHandler.java
services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/RemoteDocumentModelHandlerImpl.java
services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/RepositoryJavaClientImpl.java
services/location/client/src/main/java/org/collectionspace/services/client/LocationAuthorityClientUtils.java

index 33d7ef941e5627ce17c7bac422b4a2ccd4e496a1..b88b4d85e9f18a5f80c024545d75cdfa43dce234 100644 (file)
@@ -73,11 +73,20 @@ public abstract class DocumentModelHandler<T, TL>
 
     @Override
     public void handleCreate(DocumentWrapper<DocumentModel> wrapDoc) throws Exception {
+       // TODO for sub-docs - check to see if the current service context is a multipart input, 
+       // OR a docfragment, and call a variant to fill the DocModel.
         fillAllParts(wrapDoc);
     }
+    
+    // TODO for sub-docs - Add completeCreate in which we look for set-aside doc fragments 
+    // and create the subitems. We will create service contexts with the doc fragments
+    // and then call 
+
 
     @Override
     public void handleUpdate(DocumentWrapper<DocumentModel> wrapDoc) throws Exception {
+       // TODO for sub-docs - check to see if the current service context is a multipart input, 
+       // OR a docfragment, and call a variant to fill the DocModel.
         fillAllParts(wrapDoc);
     }
 
index 8d2aafc50239fec677a116b509f38ed53f556502..14bfe0cce5b1178ea4118969b40113ba632fff75 100644 (file)
@@ -218,6 +218,9 @@ public abstract class RemoteDocumentModelHandlerImpl<T, TL>
     protected void fillPart(InputPart part, DocumentModel docModel, ObjectPartType partMeta)
             throws Exception {
         InputStream payload = part.getBody(InputStream.class, null);
+        
+// TODO for sub-docs - after we parse the doc, we need to look for elements that are configured as 
+// subitem lists, for this part (schema), pull them out, and set them aside for later processing.
 
         //check if this is an xml part
         if(part.getMediaType().equals(MediaType.APPLICATION_XML_TYPE)){
index 737dec28b535263372c72331757e97c85d5c9a1b..e51105cdf5ec884c271652d76d89dba7533ec945 100644 (file)
@@ -226,6 +226,8 @@ public class RepositoryJavaClientImpl implements RepositoryClient {
             setCollectionSpaceCoreValues(ctx, doc, Action.CREATE);
             doc = repoSession.createDocument(doc);
             repoSession.save();
+// TODO for sub-docs need to call into the handler to let it deal with subitems. Pass in the id,
+// and assume the handler has the state it needs (doc fragments). 
             handler.complete(Action.CREATE, wrapDoc);
             return id;
         } catch (BadRequestException bre) {
index 4919c3795d50e41c012fe138c3f8db053409482b..063f1ac17ee818b2b9daf7ca315d6785e513af96 100644 (file)
@@ -1,5 +1,6 @@
 package org.collectionspace.services.client;\r
 \r
+import java.io.File;\r
 import java.util.ArrayList;\r
 import java.util.Arrays;\r
 import java.util.List;\r
@@ -9,6 +10,7 @@ import javax.ws.rs.core.MediaType;
 import javax.ws.rs.core.MultivaluedMap;\r
 import javax.ws.rs.core.Response;\r
 \r
+import org.apache.commons.io.FileUtils;\r
 import org.collectionspace.services.LocationJAXBSchema;\r
 import org.collectionspace.services.client.test.ServiceRequestType;\r
 import org.collectionspace.services.location.LocationsCommon;\r
@@ -18,11 +20,19 @@ import org.jboss.resteasy.plugins.providers.multipart.MultipartOutput;
 import org.jboss.resteasy.plugins.providers.multipart.OutputPart;\r
 import org.slf4j.Logger;\r
 import org.slf4j.LoggerFactory;\r
+import org.testng.Assert;\r
 \r
 public class LocationAuthorityClientUtils {\r
     private static final Logger logger =\r
         LoggerFactory.getLogger(LocationAuthorityClientUtils.class);\r
 \r
+    /**\r
+     * Creates a new Location Authority\r
+     * @param displayName      The displayName used in UI, etc.\r
+     * @param refName          The proper refName for this authority\r
+     * @param headerLabel      The common part label\r
+     * @return The MultipartOutput payload for the create call\r
+     */\r
     public static MultipartOutput createLocationAuthorityInstance(\r
                String displayName, String refName, String headerLabel ) {\r
         LocationauthoritiesCommon locationAuthority = new LocationauthoritiesCommon();\r
@@ -41,6 +51,13 @@ public class LocationAuthorityClientUtils {
         return multipart;\r
     }\r
 \r
+    /**\r
+     * @param inAuthority CSID of the authority to create a new location in\r
+     * @param locationRefName  The proper refName for this authority\r
+     * @param locationInfo the properties for the new Location\r
+     * @param headerLabel      The common part label\r
+     * @return The MultipartOutput payload for the create call\r
+     */\r
     public static MultipartOutput createLocationInstance(String inAuthority, \r
                String locationRefName, Map<String, String> locationInfo, String headerLabel){\r
         LocationsCommon location = new LocationsCommon();\r
@@ -74,6 +91,13 @@ public class LocationAuthorityClientUtils {
         return multipart;\r
     }\r
     \r
+    /**\r
+     * @param vcsid CSID of the authority to create a new location in\r
+     * @param locationAuthorityRefName The refName for the authority\r
+     * @param locationMap the properties for the new Location\r
+     * @param client the service client\r
+     * @return the CSID of the new item\r
+     */\r
     public static String createItemInAuthority(String vcsid, \r
                String locationAuthorityRefName, Map<String,String> locationMap,\r
                LocationAuthorityClient client ) {\r
@@ -121,6 +145,61 @@ public class LocationAuthorityClientUtils {
        return extractId(res);\r
     }\r
 \r
+    public static MultipartOutput createLocationInstance(\r
+               String commonPartXML, String headerLabel){\r
+        MultipartOutput multipart = new MultipartOutput();\r
+        OutputPart commonPart = multipart.addPart(commonPartXML,\r
+            MediaType.APPLICATION_XML_TYPE);\r
+        commonPart.getHeaders().add("label", headerLabel);\r
+\r
+        if(logger.isDebugEnabled()){\r
+               logger.debug("to be created, location common ", commonPartXML);\r
+        }\r
+\r
+        return multipart;\r
+    }\r
+    \r
+    public static String createItemInAuthority(String vcsid,\r
+               String commonPartXML,\r
+               LocationAuthorityClient client ) {\r
+       // Expected status code: 201 Created\r
+       int EXPECTED_STATUS_CODE = Response.Status.CREATED.getStatusCode();\r
+       // Type of service request being tested\r
+       ServiceRequestType REQUEST_TYPE = ServiceRequestType.CREATE;\r
+       \r
+       MultipartOutput multipart = \r
+               createLocationInstance( commonPartXML, client.getItemCommonPartName() );\r
+       ClientResponse<Response> res = client.createItem(vcsid, multipart);\r
+\r
+       int statusCode = res.getStatus();\r
+\r
+       if(!REQUEST_TYPE.isValidStatusCode(statusCode)) {\r
+               throw new RuntimeException("Could not create Item: \""+commonPartXML\r
+                               +"\" in locationAuthority: \"" + vcsid\r
+                               +"\" "+ invalidStatusCodeMessage(REQUEST_TYPE, statusCode));\r
+       }\r
+       if(statusCode != EXPECTED_STATUS_CODE) {\r
+               throw new RuntimeException("Unexpected Status when creating Item: \""+commonPartXML\r
+                               +"\" in locationAuthority: \"" + vcsid +"\", Status:"+ statusCode);\r
+       }\r
+\r
+       return extractId(res);\r
+    }\r
+    \r
+    /**\r
+     * Creates the from xml file.\r
+     *\r
+     * @param fileName the file name\r
+     * @return new CSID as string\r
+     * @throws Exception the exception\r
+     */\r
+    private String createItemInAuthorityFromXmlFile(String vcsid, String commonPartFileName, \r
+               LocationAuthorityClient client) throws Exception {\r
+        byte[] b = FileUtils.readFileToByteArray(new File(commonPartFileName));\r
+        String commonPartXML = new String(b);\r
+       return createItemInAuthority(vcsid, commonPartXML, client );\r
+    }    \r
+\r
     public static String createLocationAuthRefName(String locationAuthorityName, boolean withDisplaySuffix) {\r
        String refName = "urn:cspace:org.collectionspace.demo:locationauthority:name("\r
                        +locationAuthorityName+")";\r