proposed solution for creating electronic records with setting properties inside the FilePlanComponentProperties object using multipart upload

This commit is contained in:
Rodica Sutu
2017-01-30 09:34:34 +02:00
parent 9455eb3aee
commit 596eb3a937
4 changed files with 96 additions and 3 deletions

View File

@@ -32,6 +32,7 @@ import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanCo
import static org.alfresco.rest.rm.community.util.ParameterCheck.mandatoryObject; import static org.alfresco.rest.rm.community.util.ParameterCheck.mandatoryObject;
import static org.alfresco.rest.rm.community.util.ParameterCheck.mandatoryString; import static org.alfresco.rest.rm.community.util.ParameterCheck.mandatoryString;
import static org.alfresco.rest.rm.community.util.PojoUtility.toJson; import static org.alfresco.rest.rm.community.util.PojoUtility.toJson;
import static org.alfresco.rest.rm.community.util.PojoUtility.toJsonElectronicRecord;
import static org.apache.commons.lang3.StringUtils.EMPTY; import static org.apache.commons.lang3.StringUtils.EMPTY;
import static org.springframework.http.HttpMethod.DELETE; import static org.springframework.http.HttpMethod.DELETE;
import static org.springframework.http.HttpMethod.GET; import static org.springframework.http.HttpMethod.GET;
@@ -253,8 +254,7 @@ public class FilePlanComponentAPI extends RMModelRequest
* to the request. * to the request.
*/ */
RequestSpecBuilder builder = getRMRestWrapper().configureRequestSpec(); RequestSpecBuilder builder = getRMRestWrapper().configureRequestSpec();
JsonNode root = new ObjectMapper().readTree(toJson(electronicRecordModel)); JsonNode root = new ObjectMapper().readTree(toJsonElectronicRecord(electronicRecordModel));
// add request fields // add request fields
Iterator<String> fieldNames = root.fieldNames(); Iterator<String> fieldNames = root.fieldNames();
while (fieldNames.hasNext()) while (fieldNames.hasNext())

View File

@@ -0,0 +1,50 @@
/*
* #%L
* Alfresco Records Management Module
* %%
* Copyright (C) 2005 - 2017 Alfresco Software Limited
* %%
* This file is part of the Alfresco software.
* -
* If the software was purchased under a paid Alfresco license, the terms of
* the paid license agreement will prevail. Otherwise, the software is
* provided under the following open source license terms:
* -
* Alfresco is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
* -
* Alfresco is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
* -
* You should have received a copy of the GNU Lesser General Public License
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
* #L%
*/
package org.alfresco.rest.rm.community.util;
import com.fasterxml.jackson.annotation.JsonUnwrapped;
import org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentProperties;
/**
* Mix class for FilePlanComponent POJO class
* Mix-in annotations are: a way to associate annotations with classes
* without modifying (target) classes themselves.
*
* @author Rodica Sutu
* @since 2.6
*/
public abstract class FilePlanComponentMix
{
/**
* Annotation used to indicate that a property should be serialized "unwrapped"
* Its properties are instead included as properties of its containing Object
*/
@JsonUnwrapped
abstract FilePlanComponentProperties getProperties();
}

View File

@@ -34,6 +34,8 @@ import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.JsonMappingException;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
import org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponent;
/** /**
* Utility class for creating the json object * Utility class for creating the json object
* *
@@ -71,4 +73,37 @@ public class PojoUtility
return e.toString(); return e.toString();
} }
} }
/**
* Converting object to JSON string for electronic records
*
* @param model The java object model to convert
* @throws JsonProcessingException Throws exceptions if the given object doesn't match to the POJO class model
*/
public static String toJsonElectronicRecord(Object model) throws JsonProcessingException
{
ObjectMapper mapper = new ObjectMapper();
//inject the "mix-in" annotations from FilePlanComponentMix to
// FilePlanComponent POJO class when converting to json
mapper.addMixIn(FilePlanComponent.class, FilePlanComponentMix.class);
//include only values that differ from default settings to be included
mapper.setSerializationInclusion(Include.NON_DEFAULT);
try
{
//return the json object
return mapper.writerWithDefaultPrettyPrinter().writeValueAsString(model);
} catch (JsonGenerationException e)
{
return e.toString();
} catch (JsonMappingException e)
{
return e.toString();
} catch (IOException e)
{
return e.toString();
}
}
} }

View File

@@ -49,6 +49,7 @@ import org.alfresco.rest.rm.community.base.BaseRMRestTest;
import org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponent; import org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponent;
import org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentContent; import org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentContent;
import org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentFields; import org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentFields;
import org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentProperties;
import org.alfresco.rest.rm.community.requests.igCoreAPI.FilePlanComponentAPI; import org.alfresco.rest.rm.community.requests.igCoreAPI.FilePlanComponentAPI;
import org.alfresco.utility.report.Bug; import org.alfresco.utility.report.Bug;
import org.testng.annotations.DataProvider; import org.testng.annotations.DataProvider;
@@ -272,6 +273,11 @@ public class ElectronicRecordTests extends BaseRMRestTest
.mimeType("text/plain") .mimeType("text/plain")
.build() .build()
) )
.properties(FilePlanComponentProperties
.builder()
.description(ELECTRONIC_RECORD_NAME)
.build()
)
.relativePath(RELATIVE_PATH) .relativePath(RELATIVE_PATH)
.build(); .build();
@@ -283,6 +289,8 @@ public class ElectronicRecordTests extends BaseRMRestTest
// get newly created electronic record and verify its properties // get newly created electronic record and verify its properties
assertTrue(filePlanComponentsAPI.getFilePlanComponent(recordCreated.getId()) assertTrue(filePlanComponentsAPI.getFilePlanComponent(recordCreated.getId())
.getName().startsWith(ELECTRONIC_RECORD_NAME)); .getName().startsWith(ELECTRONIC_RECORD_NAME));
assertTrue(filePlanComponentsAPI.getFilePlanComponent(recordCreated.getId())
.getProperties().getDescription().equals(ELECTRONIC_RECORD_NAME));
assertTrue(filePlanComponentsAPI.getFilePlanComponent(recordCreated.getParentId()) assertTrue(filePlanComponentsAPI.getFilePlanComponent(recordCreated.getParentId())
.getName().equals(FOLDER_NAME)); .getName().equals(FOLDER_NAME));
//get newly created electronic record using the relativePath //get newly created electronic record using the relativePath