RM-4550: Files API wrapper + declare document as record test.

This commit is contained in:
Kristijan Conkas
2017-01-06 15:20:24 +00:00
parent c8ec44ca0c
commit e31524ffb7
5 changed files with 124 additions and 1 deletions

View File

@@ -27,6 +27,7 @@
package org.alfresco.rest.core; package org.alfresco.rest.core;
import org.alfresco.rest.rm.community.requests.igCoreAPI.FilePlanComponentAPI; import org.alfresco.rest.rm.community.requests.igCoreAPI.FilePlanComponentAPI;
import org.alfresco.rest.rm.community.requests.igCoreAPI.FilesAPI;
import org.alfresco.rest.rm.community.requests.igCoreAPI.RMSiteAPI; import org.alfresco.rest.rm.community.requests.igCoreAPI.RMSiteAPI;
import org.alfresco.rest.rm.community.requests.igCoreAPI.RecordsAPI; import org.alfresco.rest.rm.community.requests.igCoreAPI.RecordsAPI;
import org.alfresco.rest.rm.community.requests.igCoreAPI.RestIGCoreAPI; import org.alfresco.rest.rm.community.requests.igCoreAPI.RestIGCoreAPI;
@@ -95,4 +96,14 @@ public class RestAPIFactory
{ {
return getRestIGCoreAPI(userModel).usingRecords(); return getRestIGCoreAPI(userModel).usingRecords();
} }
public FilesAPI getFilesAPI()
{
return getRestIGCoreAPI(null).usingFiles();
}
public FilesAPI getFilesAPI(UserModel userModel)
{
return getRestIGCoreAPI(userModel).usingFiles();
}
} }

View File

@@ -40,6 +40,7 @@ public class FilePlanComponentFields
public static final String ENTRY = "entry"; public static final String ENTRY = "entry";
public static final String PROPERTIES = "properties"; public static final String PROPERTIES = "properties";
public static final String PROPERTIES_TITLE = "cm:title"; public static final String PROPERTIES_TITLE = "cm:title";
public static final String PROPERTIES_RECORD_ID = "rma:identifier";
public static final String PROPERTIES_VITAL_RECORD_INDICATOR = "rma:vitalRecordIndicator"; public static final String PROPERTIES_VITAL_RECORD_INDICATOR = "rma:vitalRecordIndicator";
public static final String PROPERTIES_HOLD_REASON = "rma:holdReason"; public static final String PROPERTIES_HOLD_REASON = "rma:holdReason";
public static final String PROPERTIES_DESCRIPTION = "cm:description"; public static final String PROPERTIES_DESCRIPTION = "cm:description";
@@ -50,7 +51,7 @@ public class FilePlanComponentFields
public static final String PROPERTIES_LOCATION = "rma:location"; public static final String PROPERTIES_LOCATION = "rma:location";
public static final String PROPERTIES_IS_CLOSED = "rma:isClosed"; // not to be confused with IS_CLOSED! public static final String PROPERTIES_IS_CLOSED = "rma:isClosed"; // not to be confused with IS_CLOSED!
public static final String IS_COMPLETED = "isCompleted"; public static final String IS_COMPLETED = "isCompleted";
// for non-electronic records // for non-electronic records
public static final String PROPERTIES_BOX = "rma:box"; public static final String PROPERTIES_BOX = "rma:box";
public static final String PROPERTIES_FILE = "rma:file"; public static final String PROPERTIES_FILE = "rma:file";

View File

@@ -39,6 +39,7 @@ import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanCo
import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentFields.PROPERTIES_SUPPLEMENTAL_MARKING_LIST; import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentFields.PROPERTIES_SUPPLEMENTAL_MARKING_LIST;
import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentFields.PROPERTIES_TITLE; import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentFields.PROPERTIES_TITLE;
import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentFields.PROPERTIES_VITAL_RECORD_INDICATOR; import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentFields.PROPERTIES_VITAL_RECORD_INDICATOR;
import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentFields.PROPERTIES_RECORD_ID;
import java.util.List; import java.util.List;
@@ -106,4 +107,7 @@ public class FilePlanComponentProperties
@JsonProperty(value = PROPERTIES_PHYSICAL_SIZE, required = false) @JsonProperty(value = PROPERTIES_PHYSICAL_SIZE, required = false)
private Integer physicalSize; private Integer physicalSize;
@JsonProperty(value = PROPERTIES_RECORD_ID, required = false)
private String recordId;
} }

View File

@@ -0,0 +1,97 @@
/*
* #%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.requests.igCoreAPI;
import static com.jayway.restassured.RestAssured.given;
import static org.alfresco.rest.core.RestRequest.requestWithBody;
import static org.alfresco.rest.core.RestRequest.simpleRequest;
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.PojoUtility.toJson;
import static org.apache.commons.lang3.StringUtils.EMPTY;
import static org.springframework.http.HttpMethod.POST;
import com.jayway.restassured.response.Response;
import com.jayway.restassured.response.ResponseBody;
import org.alfresco.rest.core.RMRestWrapper;
import org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponent;
import org.alfresco.rest.rm.community.model.fileplancomponents.RecordBodyFile;
import org.alfresco.rest.rm.community.requests.RMModelRequest;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
/**
* Files REST API Wrapper
*
* @author Kristijan Conkas
* @since 2.6
*/
@Component
@Scope (value = "prototype")
public class FilesAPI extends RMModelRequest
{
/**
* @param rmRestWrapper
*/
public FilesAPI(RMRestWrapper rmRestWrapper)
{
super(rmRestWrapper);
}
/**
* Declare file as record
* @param fileId The Id of a file to declare as record
* @param parameters Request parameters, refer to API documentation for more details
* @return The {@link FilePlanComponent} for created record
* @throws Exception
*/
public FilePlanComponent declareAsRecord(String fileId, String parameters) throws Exception
{
mandatoryString("fileId", fileId);
return getRMRestWrapper().processModel(FilePlanComponent.class, simpleRequest(
POST,
"/files/{fileId}/declare?{parameters}",
fileId,
parameters
));
}
/**
* A no-parameter version of {@link FilesAPI#declareAsRecord}
* @param fileId The Id of a file to declare as record
* @return The {@link FilePlanComponent} for created record
* @throws Exception
*/
public FilePlanComponent declareAsRecord(String fileId) throws Exception
{
return declareAsRecord(fileId, EMPTY);
}
}

View File

@@ -87,4 +87,14 @@ public class RestIGCoreAPI extends RMModelRequest
{ {
return new RecordsAPI(getRMRestWrapper()); return new RecordsAPI(getRMRestWrapper());
} }
/**
* Provides DSL on all REST calls under <code>files/...</code> API path
*
* @return {@link FilesAPI}
*/
public FilesAPI usingFiles()
{
return new FilesAPI(getRMRestWrapper());
}
} }