RM-4615: now using RM FilePlanComponentAPI calls to create electronic records.

This commit is contained in:
Kristijan Conkas
2017-01-27 11:52:21 +00:00
parent 8a875a0ef7
commit 678e3e6cf5
2 changed files with 10 additions and 28 deletions

View File

@@ -52,8 +52,6 @@ import org.alfresco.rest.core.RMRestWrapper;
import org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponent;
import org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentsCollection;
import org.alfresco.rest.rm.community.requests.RMModelRequest;
import org.alfresco.utility.model.ContentModel;
import org.alfresco.utility.model.RepoTestModel;
/**
* File plan component REST API Wrapper
@@ -233,13 +231,15 @@ public class FilePlanComponentAPI extends RMModelRequest
/**
* Create electronic record from file resource
*
* @param electronicRecordModel {@link FilePlanComponent} for electronic record to be created
* @param recordContent {@link File} pointing to the content of the electronic record to be created
* @param parentId parent container id
* @return newly created {@link FilePlanComponent}
* @throws Exception if electronic record couldn't be created
* @throws Exception for invalid electronicRecordModel JSON strings
*/
public FilePlanComponent createElectronicRecord(FilePlanComponent electronicRecordModel, File recordContent, String parentId) throws Exception
public FilePlanComponent createElectronicRecord(FilePlanComponent electronicRecordModel, File recordContent,
String parentId) throws Exception
{
mandatoryObject("electronicRecordModel", electronicRecordModel);
mandatoryString("parentId", parentId);
@@ -248,10 +248,6 @@ public class FilePlanComponentAPI extends RMModelRequest
fail("Only electronic records are supported");
}
RepoTestModel parentNode = new ContentModel();
// using getFilePlanComponent to work around RM special containers, unsupported in Core API usingNode()
parentNode.setNodeRef(getFilePlanComponent(parentId).getId());
/*
* For file uploads nodeBodyCreate is ignored hence can't be used. Append all FilePlanComponent fields
* to the request.
@@ -268,20 +264,8 @@ public class FilePlanComponentAPI extends RMModelRequest
}
builder.addMultiPart("filedata", recordContent, ContentType.BINARY.name());
// create node with given content using core Node API
String nodeId = getRMRestWrapper().withCoreAPI().usingNode(parentNode).createNode().getId();
String createStatusCode = getRMRestWrapper().getStatusCode();
// return FilePlanComponent for created node
FilePlanComponent createdComponent = getRMRestWrapper()
.withIGCoreAPI()
.usingFilePlanComponents()
.getFilePlanComponent(nodeId);
// avoid getFilePlanComponent() overriding the createNode status code
getRMRestWrapper().setStatusCode(createStatusCode);
return createdComponent;
// create node with given content
return createFilePlanComponent(electronicRecordModel, parentId);
}
/**

View File

@@ -95,8 +95,7 @@ public class ElectronicRecordTests extends BaseRMRestTest
@Test
(
dataProvider = "invalidParentContainers",
description = "Electronic records can't be created in invalid parent containers",
expectedExceptions = IllegalArgumentException.class
description = "Electronic records can't be created in invalid parent containers"
)
public void cantCreateElectronicRecordsInInvalidContainers(FilePlanComponent container) throws Exception
{
@@ -119,8 +118,7 @@ public class ElectronicRecordTests extends BaseRMRestTest
*/
@Test
(
description = "Electronic record can't be created in closed record folder",
expectedExceptions = IllegalArgumentException.class
description = "Electronic record can't be created in closed record folder"
)
public void cantCreateElectronicRecordInClosedFolder() throws Exception
{