mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-07 17:49:17 +00:00
Refactored test code
This commit is contained in:
2
README
2
README
@@ -1 +1,3 @@
|
||||
FIXME: DOCUMENT ME BETTER :)
|
||||
|
||||
In order to change the value of a property in "config.properties" create a file called "local.properties" under src/test/resources and redefine the property with the new value.
|
5
pom.xml
5
pom.xml
@@ -25,5 +25,10 @@
|
||||
<type>test-jar</type>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.jglue.fluent-json</groupId>
|
||||
<artifactId>fluent-json</artifactId>
|
||||
<version>2.0.0</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
|
59
src/main/java/org/alfresco/com/FilePlanComponentAlias.java
Normal file
59
src/main/java/org/alfresco/com/FilePlanComponentAlias.java
Normal file
@@ -0,0 +1,59 @@
|
||||
/*
|
||||
* #%L
|
||||
* Alfresco Records Management Module
|
||||
* %%
|
||||
* Copyright (C) 2005 - 2016 Alfresco Software Limited
|
||||
* %%
|
||||
* License rights for this program may be obtained from Alfresco Software, Ltd.
|
||||
* pursuant to a written agreement and any use of this program without such an
|
||||
* agreement is prohibited.
|
||||
* #L%
|
||||
*/
|
||||
package org.alfresco.com;
|
||||
|
||||
/**
|
||||
* File plan component alias enumeration
|
||||
*
|
||||
* @author Tuna Aksoy
|
||||
* @since 1.0
|
||||
*/
|
||||
public enum FilePlanComponentAlias
|
||||
{
|
||||
FILE_PLAN_ALIAS("-filePlan-"),
|
||||
TRANSFERS_ALIAS("-transfers-"),
|
||||
UNFILED_RECORDS_CONTAINER_ALIAS("-unfiled-"),
|
||||
HOLDS_ALIAS("-holds-");
|
||||
|
||||
private String alias;
|
||||
|
||||
private FilePlanComponentAlias(String alias)
|
||||
{
|
||||
this.alias = alias;
|
||||
}
|
||||
|
||||
public static final FilePlanComponentAlias getFilePlanComponentAlias(String alias)
|
||||
{
|
||||
switch (alias)
|
||||
{
|
||||
case "-filePlan-":
|
||||
return FILE_PLAN_ALIAS;
|
||||
case "-transfers-":
|
||||
return TRANSFERS_ALIAS;
|
||||
case "-unfiled-":
|
||||
return UNFILED_RECORDS_CONTAINER_ALIAS;
|
||||
case "-holds-":
|
||||
return HOLDS_ALIAS;
|
||||
}
|
||||
|
||||
throw new IllegalArgumentException("Invalid file plan component alias enum value: '" + alias + "'.");
|
||||
}
|
||||
|
||||
/**
|
||||
* @see java.lang.Enum#toString()
|
||||
*/
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return this.alias;
|
||||
}
|
||||
}
|
28
src/main/java/org/alfresco/com/FilePlanComponentFields.java
Normal file
28
src/main/java/org/alfresco/com/FilePlanComponentFields.java
Normal file
@@ -0,0 +1,28 @@
|
||||
/*
|
||||
* #%L
|
||||
* Alfresco Records Management Module
|
||||
* %%
|
||||
* Copyright (C) 2005 - 2016 Alfresco Software Limited
|
||||
* %%
|
||||
* License rights for this program may be obtained from Alfresco Software, Ltd.
|
||||
* pursuant to a written agreement and any use of this program without such an
|
||||
* agreement is prohibited.
|
||||
* #L%
|
||||
*/
|
||||
package org.alfresco.com;
|
||||
|
||||
/**
|
||||
* FIXME: Document me :)
|
||||
*
|
||||
* @author Tuna Aksoy
|
||||
* @since 1.0
|
||||
*/
|
||||
public class FilePlanComponentFields
|
||||
{
|
||||
public static final String NAME = "name";
|
||||
public static final String NODE_TYPE = "nodeType";
|
||||
public static final String PROPERTIES = "properties";
|
||||
public static final String PROPERTIES_TITLE = "cm:title";
|
||||
public static final String PROPERTIES_VITAL_RECORD_INDICATOR = "rma:vitalRecordIndicator";
|
||||
public static final String PROPERTIES_HOLD_REASON = "rma:holdReason";
|
||||
}
|
62
src/main/java/org/alfresco/com/FilePlanComponentType.java
Normal file
62
src/main/java/org/alfresco/com/FilePlanComponentType.java
Normal file
@@ -0,0 +1,62 @@
|
||||
/*
|
||||
* #%L
|
||||
* Alfresco Records Management Module
|
||||
* %%
|
||||
* Copyright (C) 2005 - 2016 Alfresco Software Limited
|
||||
* %%
|
||||
* License rights for this program may be obtained from Alfresco Software, Ltd.
|
||||
* pursuant to a written agreement and any use of this program without such an
|
||||
* agreement is prohibited.
|
||||
* #L%
|
||||
*/
|
||||
package org.alfresco.com;
|
||||
|
||||
/**
|
||||
* File plan component type enumeration
|
||||
*
|
||||
* @author Tuna Aksoy
|
||||
* @since 1.0
|
||||
*/
|
||||
public enum FilePlanComponentType
|
||||
{
|
||||
FILE_PLAN_TYPE("rma:filePlan"),
|
||||
RECORD_CATEGORY_TYPE("rma:recordCategory"),
|
||||
RECORD_FOLDER_TYPE("rma:recordFolder"),
|
||||
HOLD_TYPE("rma:hold"),
|
||||
UNFILED_RECORD_FOLDER_TYPE("rma:unfiledRecordFolder");
|
||||
|
||||
private String type;
|
||||
|
||||
private FilePlanComponentType(String type)
|
||||
{
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public static final FilePlanComponentType getFilePlanComponentType(String type)
|
||||
{
|
||||
switch (type)
|
||||
{
|
||||
case "rma:filePlan":
|
||||
return FILE_PLAN_TYPE;
|
||||
case "rma:recordCategory":
|
||||
return RECORD_CATEGORY_TYPE;
|
||||
case "rma:recordFolder":
|
||||
return RECORD_FOLDER_TYPE;
|
||||
case "rma:hold":
|
||||
return HOLD_TYPE;
|
||||
case "rma:unfiledRecordFolder":
|
||||
return UNFILED_RECORD_FOLDER_TYPE;
|
||||
}
|
||||
|
||||
throw new IllegalArgumentException("Invalid file plan component type enum value: '" + type + "'.");
|
||||
}
|
||||
|
||||
/**
|
||||
* @see java.lang.Enum#toString()
|
||||
*/
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return this.type;
|
||||
}
|
||||
}
|
57
src/main/java/org/alfresco/com/util/ParameterCheck.java
Normal file
57
src/main/java/org/alfresco/com/util/ParameterCheck.java
Normal file
@@ -0,0 +1,57 @@
|
||||
/*
|
||||
* #%L
|
||||
* Alfresco Records Management Module
|
||||
* %%
|
||||
* Copyright (C) 2005 - 2016 Alfresco Software Limited
|
||||
* %%
|
||||
* License rights for this program may be obtained from Alfresco Software, Ltd.
|
||||
* pursuant to a written agreement and any use of this program without such an
|
||||
* agreement is prohibited.
|
||||
* #L%
|
||||
*/
|
||||
package org.alfresco.com.util;
|
||||
|
||||
import static org.apache.commons.lang3.StringUtils.isBlank;
|
||||
|
||||
/**
|
||||
* Utility class for checking parameters
|
||||
*
|
||||
* @author Tuna Aksoy
|
||||
* @since 1.0
|
||||
*/
|
||||
public class ParameterCheck
|
||||
{
|
||||
private ParameterCheck()
|
||||
{
|
||||
// Intentionally blank
|
||||
}
|
||||
|
||||
/**
|
||||
* FIXME: Document me :)
|
||||
*
|
||||
* @param paramName FIXME: Document me :)
|
||||
* @param paramValue FIXME: Document me :)
|
||||
* @throws IllegalArgumentException FIXME: Document me :)
|
||||
*/
|
||||
public static void mandatoryString(final String paramName, final String paramValue) throws IllegalArgumentException
|
||||
{
|
||||
if (isBlank(paramValue))
|
||||
{
|
||||
throw new IllegalArgumentException("'" + paramName + "' is a mandatory parameter.");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* FIXME: Document me :)
|
||||
*
|
||||
* @param paramName FIXME: Document me :)
|
||||
* @param object FIXME: Document me :)
|
||||
*/
|
||||
public static void mandatoryObject(final String paramName, final Object object)
|
||||
{
|
||||
if (object == null)
|
||||
{
|
||||
throw new IllegalArgumentException("'" + paramName + "' is a mandatory parameter.");
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,93 +0,0 @@
|
||||
/*
|
||||
* #%L
|
||||
* Alfresco Records Management Module
|
||||
* %%
|
||||
* Copyright (C) 2005 - 2016 Alfresco Software Limited
|
||||
* %%
|
||||
* License rights for this program may be obtained from Alfresco Software, Ltd.
|
||||
* pursuant to a written agreement and any use of this program without such an
|
||||
* agreement is prohibited.
|
||||
* #L%
|
||||
*/
|
||||
package org.alfresco.rest.body;
|
||||
|
||||
import javax.json.Json;
|
||||
import javax.json.JsonBuilderFactory;
|
||||
import javax.json.JsonObjectBuilder;
|
||||
|
||||
import org.alfresco.rest.model.PropertiesModel;
|
||||
import org.alfresco.rest.model.RestFilePlanComponentModel;
|
||||
|
||||
/**
|
||||
* Helper for building JSON objects
|
||||
* @author Kristijan Conkas
|
||||
* @since 2.6
|
||||
*/
|
||||
public class IgJsonBodyGenerator
|
||||
{
|
||||
private static JsonBuilderFactory jsonBuilderFactory;
|
||||
|
||||
/**
|
||||
* @return the initialized JSON builder factory
|
||||
*/
|
||||
private static JsonBuilderFactory getJsonBuilder()
|
||||
{
|
||||
if (jsonBuilderFactory == null)
|
||||
{
|
||||
return Json.createBuilderFactory(null);
|
||||
}
|
||||
else
|
||||
{
|
||||
return jsonBuilderFactory;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate request body for create API calls
|
||||
* @param model
|
||||
* @return request body JSON string
|
||||
*/
|
||||
public static String filePlanComponentCreate(RestFilePlanComponentModel model)
|
||||
{
|
||||
PropertiesModel properties = model.getProperties();
|
||||
JsonObjectBuilder valueBuilder = getJsonBuilder()
|
||||
.createObjectBuilder()
|
||||
.add("name", model.getName())
|
||||
.add("nodeType", model.getNodeType());
|
||||
if (properties != null)
|
||||
{
|
||||
// handle properties
|
||||
JsonObjectBuilder propertiesBuilder = getJsonBuilder().createObjectBuilder();
|
||||
if (properties.getTitle() != null)
|
||||
{
|
||||
propertiesBuilder.add("cm:title", properties.getTitle());
|
||||
}
|
||||
valueBuilder.add("properties", propertiesBuilder.build());
|
||||
}
|
||||
return valueBuilder.build().toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate request body for update API calls
|
||||
* @param model
|
||||
* @return request body JSON string
|
||||
*/
|
||||
public static String filePlanComponentUpdate(RestFilePlanComponentModel model)
|
||||
{
|
||||
PropertiesModel properties = model.getProperties();
|
||||
JsonObjectBuilder valueBuilder = getJsonBuilder()
|
||||
.createObjectBuilder()
|
||||
.add("name", model.getName());
|
||||
if (properties != null)
|
||||
{
|
||||
// handle properties
|
||||
JsonObjectBuilder propertiesBuilder = getJsonBuilder().createObjectBuilder();
|
||||
if (properties.getTitle() != null)
|
||||
{
|
||||
propertiesBuilder.add("cm:title", properties.getTitle());
|
||||
}
|
||||
valueBuilder.add("properties", propertiesBuilder.build());
|
||||
}
|
||||
return valueBuilder.build().toString();
|
||||
}
|
||||
}
|
@@ -11,6 +11,8 @@
|
||||
*/
|
||||
package org.alfresco.rest.model;
|
||||
|
||||
import static org.alfresco.com.FilePlanComponentFields.PROPERTIES;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
|
||||
@@ -18,28 +20,35 @@ import org.springframework.context.annotation.Scope;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* FIXME: Document me :)
|
||||
* POJO for file plan component
|
||||
*
|
||||
* @author Tuna Aksoy
|
||||
* @since 1.0
|
||||
*/
|
||||
@Component
|
||||
@Scope(value = "prototype")
|
||||
//FIXME: Once the fields have been added this annotation should be removed
|
||||
//FIXME: Once the fields have been added the JsonIgnoreProperties annotation should be removed
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public class RestFilePlanComponentModel
|
||||
public class FilePlanComponent
|
||||
{
|
||||
private String id;
|
||||
|
||||
private String parentId;
|
||||
|
||||
private String name;
|
||||
|
||||
private String nodeType;
|
||||
|
||||
private boolean isCategory;
|
||||
|
||||
private boolean isRecordFolder;
|
||||
|
||||
private boolean isFile;
|
||||
|
||||
private boolean hasRetentionSchedule;
|
||||
|
||||
@JsonProperty(value = "properties")
|
||||
private PropertiesModel properties;
|
||||
@JsonProperty(PROPERTIES)
|
||||
private FilePlanComponentProperties properties;
|
||||
|
||||
/**
|
||||
* @return the id
|
||||
@@ -172,7 +181,7 @@ public class RestFilePlanComponentModel
|
||||
/**
|
||||
* @return the properties
|
||||
*/
|
||||
public PropertiesModel getProperties()
|
||||
public FilePlanComponentProperties getProperties()
|
||||
{
|
||||
return properties;
|
||||
}
|
||||
@@ -180,7 +189,7 @@ public class RestFilePlanComponentModel
|
||||
/**
|
||||
* @param properties the properties to set
|
||||
*/
|
||||
public void setProperties(PropertiesModel properties)
|
||||
public void setProperties(FilePlanComponentProperties properties)
|
||||
{
|
||||
this.properties = properties;
|
||||
}
|
@@ -11,6 +11,10 @@
|
||||
*/
|
||||
package org.alfresco.rest.model;
|
||||
|
||||
import static org.alfresco.com.FilePlanComponentFields.PROPERTIES_HOLD_REASON;
|
||||
import static org.alfresco.com.FilePlanComponentFields.PROPERTIES_TITLE;
|
||||
import static org.alfresco.com.FilePlanComponentFields.PROPERTIES_VITAL_RECORD_INDICATOR;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
|
||||
@@ -18,24 +22,26 @@ import org.springframework.context.annotation.Scope;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* Fileplan component properties
|
||||
* POJO for file plan component properties
|
||||
*
|
||||
* @author Kristijan Conkas
|
||||
* @since 2.6
|
||||
* @since 1.0
|
||||
*/
|
||||
@Component
|
||||
@Scope(value = "prototype")
|
||||
//FIXME: Once the fields have been added the JsonIgnoreProperties annotation should be removed
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public class PropertiesModel
|
||||
public class FilePlanComponentProperties
|
||||
{
|
||||
// TODO: handling individual properties is tedious and error prone, how about @JsonGetter + @JsonSetter?
|
||||
|
||||
@JsonProperty("rma:vitalRecordIndicator")
|
||||
@JsonProperty(PROPERTIES_VITAL_RECORD_INDICATOR)
|
||||
private boolean vitalRecord;
|
||||
|
||||
@JsonProperty("cm:title")
|
||||
@JsonProperty(PROPERTIES_TITLE)
|
||||
private String title;
|
||||
|
||||
@JsonProperty("rma:holdReason")
|
||||
@JsonProperty(PROPERTIES_HOLD_REASON)
|
||||
private String holdReason;
|
||||
|
||||
/**
|
@@ -0,0 +1,145 @@
|
||||
/*
|
||||
* #%L
|
||||
* Alfresco Records Management Module
|
||||
* %%
|
||||
* Copyright (C) 2005 - 2016 Alfresco Software Limited
|
||||
* %%
|
||||
* License rights for this program may be obtained from Alfresco Software, Ltd.
|
||||
* pursuant to a written agreement and any use of this program without such an
|
||||
* agreement is prohibited.
|
||||
* #L%
|
||||
*/
|
||||
package org.alfresco.rest.requests;
|
||||
|
||||
import static org.alfresco.com.util.ParameterCheck.mandatoryObject;
|
||||
import static org.alfresco.com.util.ParameterCheck.mandatoryString;
|
||||
import static org.alfresco.rest.core.RestRequest.requestWithBody;
|
||||
import static org.alfresco.rest.core.RestRequest.simpleRequest;
|
||||
import static org.springframework.http.HttpMethod.DELETE;
|
||||
import static org.springframework.http.HttpMethod.GET;
|
||||
import static org.springframework.http.HttpMethod.POST;
|
||||
import static org.springframework.http.HttpMethod.PUT;
|
||||
|
||||
import com.google.gson.JsonObject;
|
||||
|
||||
import org.alfresco.rest.core.RestAPI;
|
||||
import org.alfresco.rest.model.FilePlanComponent;
|
||||
import org.springframework.context.annotation.Scope;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* File plan component REST API Wrapper
|
||||
*
|
||||
* @author Tuna Aksoy
|
||||
* @author Kristijan Conkas
|
||||
* @since 1.0
|
||||
*/
|
||||
@Component
|
||||
@Scope(value = "prototype")
|
||||
public class FilePlanComponentApi extends RestAPI
|
||||
{
|
||||
/**
|
||||
* Get a file plan component
|
||||
*
|
||||
* @param filePlanComponentId The id of the file plan component to get
|
||||
* @return The {@link FilePlanComponent} for the given file plan component id
|
||||
* @throws Exception for the following cases:
|
||||
* <ul>
|
||||
* <li>{@code fileplanComponentId} is not a valid format</li>
|
||||
* <li>authentication fails</li>
|
||||
* <li>{@code fileplanComponentId} does not exist</li>
|
||||
* </ul>
|
||||
*/
|
||||
public FilePlanComponent getFilePlanComponent(String filePlanComponentId) throws Exception
|
||||
{
|
||||
mandatoryString("filePlanComponentId", filePlanComponentId);
|
||||
|
||||
return usingRestWrapper().processModel(FilePlanComponent.class, simpleRequest(
|
||||
GET,
|
||||
"fileplan-components/{fileplanComponentId}",
|
||||
filePlanComponentId
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a file plan component with the given properties under the parent node with the given id
|
||||
*
|
||||
* @param filePlanComponentProperties The properties of the file plan component to be created
|
||||
* @param parentId The id of the parent where the new file plan component should be created
|
||||
* @return The {@link FilePlanComponent} with the given properties
|
||||
* @throws Exception for the following cases:
|
||||
* <ul>
|
||||
* <li>{@code fileplanComponentId} is not a valid format</li>
|
||||
* <li>authentication fails</li>
|
||||
* <li>current user does not have permission to add children to {@code fileplanComponentId}</li>
|
||||
* <li>{@code fileplanComponentId} does not exist</li>
|
||||
* <li>new name clashes with an existing node in the current parent container</li>
|
||||
* <li>model integrity exception, including node name with invalid characters</li>
|
||||
* </ul>
|
||||
*/
|
||||
public FilePlanComponent createFilePlanComponent(JsonObject filePlanComponentProperties, String parentId) throws Exception
|
||||
{
|
||||
mandatoryObject("filePlanComponentProperties", filePlanComponentProperties);
|
||||
mandatoryString("parentId", parentId);
|
||||
|
||||
return usingRestWrapper().processModel(FilePlanComponent.class, requestWithBody(
|
||||
POST,
|
||||
filePlanComponentProperties.toString(),
|
||||
"fileplan-components/{fileplanComponentId}/children",
|
||||
parentId
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates a file plan component
|
||||
*
|
||||
* @param filePlanComponentProperties The properties to be updated
|
||||
* @param filePlanComponentId The id of the file plan component which will be updated
|
||||
* @param returns The updated {@link FilePlanComponent}
|
||||
* @throws Exception for the following cases:
|
||||
* <ul>
|
||||
* <li>the update request is invalid or {@code fileplanComponentId} is not a valid format or {@code filePlanComponentProperties} is invalid</li>
|
||||
* <li>authentication fails</li>
|
||||
* <li>current user does not have permission to update {@code fileplanComponentId}</li>
|
||||
* <li>{@code fileplanComponentId} does not exist</li>
|
||||
* <li>the updated name clashes with an existing node in the current parent folder</li>
|
||||
* <li>model integrity exception, including node name with invalid characters</li>
|
||||
* </ul>
|
||||
*/
|
||||
public FilePlanComponent updateFilePlanComponent(JsonObject filePlanComponentProperties, String filePlanComponentId) throws Exception
|
||||
{
|
||||
mandatoryObject("filePlanComponentProperties", filePlanComponentProperties);
|
||||
mandatoryString("filePlanComponentId", filePlanComponentId);
|
||||
|
||||
return usingRestWrapper().processModel(FilePlanComponent.class, requestWithBody(
|
||||
PUT,
|
||||
filePlanComponentProperties.toString(),
|
||||
"fileplan-components/{fileplanComponentId}",
|
||||
filePlanComponentId
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete file plan component
|
||||
*
|
||||
* @param filePlanComponentId The id of the file plan component to be deleted
|
||||
* @throws Exception for the following cases:
|
||||
* <ul>
|
||||
* <li>{@code fileplanComponentId} is not a valid format</li>
|
||||
* <li>authentication fails</li>
|
||||
* <li>current user does not have permission to delete {@code fileplanComponentId}</li>
|
||||
* <li>{@code fileplanComponentId} does not exist</li>
|
||||
* <li>{@code fileplanComponentId} is locked and cannot be deleted</li>
|
||||
* </ul>
|
||||
*/
|
||||
public void deleteFilePlanComponent(String filePlanComponentId) throws Exception
|
||||
{
|
||||
mandatoryString("filePlanComponentId", filePlanComponentId);
|
||||
|
||||
usingRestWrapper().processEmptyModel(simpleRequest(
|
||||
DELETE,
|
||||
"fileplan-components/{fileplanComponentId}",
|
||||
filePlanComponentId
|
||||
));
|
||||
}
|
||||
}
|
@@ -1,99 +0,0 @@
|
||||
/*
|
||||
* #%L
|
||||
* Alfresco Records Management Module
|
||||
* %%
|
||||
* Copyright (C) 2005 - 2016 Alfresco Software Limited
|
||||
* %%
|
||||
* License rights for this program may be obtained from Alfresco Software, Ltd.
|
||||
* pursuant to a written agreement and any use of this program without such an
|
||||
* agreement is prohibited.
|
||||
* #L%
|
||||
*/
|
||||
package org.alfresco.rest.requests;
|
||||
|
||||
import static org.alfresco.rest.body.IgJsonBodyGenerator.filePlanComponentCreate;
|
||||
import static org.alfresco.rest.body.IgJsonBodyGenerator.filePlanComponentUpdate;
|
||||
import static org.alfresco.rest.core.RestRequest.requestWithBody;
|
||||
import static org.alfresco.rest.core.RestRequest.simpleRequest;
|
||||
|
||||
import static org.springframework.http.HttpMethod.DELETE;
|
||||
import static org.springframework.http.HttpMethod.GET;
|
||||
import static org.springframework.http.HttpMethod.POST;
|
||||
import static org.springframework.http.HttpMethod.PUT;
|
||||
|
||||
import org.alfresco.rest.core.RestAPI;
|
||||
import org.alfresco.rest.core.RestRequest;
|
||||
import org.alfresco.rest.model.RestFilePlanComponentModel;
|
||||
import org.json.JSONObject;
|
||||
import org.springframework.context.annotation.Scope;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* REST wrapper for IG APIs
|
||||
*
|
||||
* @author Tuna Aksoy
|
||||
* @author kconkas
|
||||
* @since 1.0
|
||||
*/
|
||||
@Component
|
||||
@Scope(value = "prototype")
|
||||
public class RestFilePlanComponentApi extends RestAPI
|
||||
{
|
||||
/**
|
||||
* Get file plan component
|
||||
* @param filePlanComponentId
|
||||
* @return {@link RestFilePlanComponentModel} for filePlanComponentId
|
||||
* @throws Exception for non-existent components
|
||||
*/
|
||||
public RestFilePlanComponentModel getFilePlanComponent(String filePlanComponentId) throws Exception
|
||||
{
|
||||
RestRequest request = simpleRequest(GET, "fileplan-components/{fileplanComponentId}", filePlanComponentId);
|
||||
return usingRestWrapper().processModel(RestFilePlanComponentModel.class, request);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create file plan component
|
||||
* @param model
|
||||
* @return
|
||||
* @throws Exception
|
||||
*/
|
||||
public RestFilePlanComponentModel createFilePlanComponent(RestFilePlanComponentModel model) throws Exception
|
||||
{
|
||||
RestRequest request = requestWithBody(POST,
|
||||
filePlanComponentCreate(model).toString(),
|
||||
"fileplan-components/{fileplanComponentId}/children",
|
||||
model.getId());
|
||||
return usingRestWrapper().processModel(RestFilePlanComponentModel.class, request);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update file plan component
|
||||
* @param update {@link RestFilePlanComponentModel} to update
|
||||
* @param returns updated {@link RestFilePlanComponentModel}
|
||||
* @throws Exception
|
||||
*/
|
||||
public RestFilePlanComponentModel updateFilePlanComponent(RestFilePlanComponentModel update) throws Exception
|
||||
{
|
||||
RestRequest request = requestWithBody(PUT,
|
||||
filePlanComponentUpdate(update).toString(),
|
||||
"fileplan-components/{fileplanComponentId}",
|
||||
update.getId());
|
||||
return usingRestWrapper().processModel(RestFilePlanComponentModel.class, request);
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete file plan component
|
||||
* @param delete {@link RestFilePlanComponentModel} to delete
|
||||
* @param deletePermanently if set to <code>true</code> delete without moving to the trashcan
|
||||
* @throws Exception
|
||||
*/
|
||||
public RestRequest deleteFilePlanComponent(RestFilePlanComponentModel delete, boolean deletePermanently) throws Exception
|
||||
{
|
||||
JSONObject body = new JSONObject();
|
||||
if (deletePermanently) body.put("permanent", deletePermanently);
|
||||
|
||||
RestRequest request = requestWithBody(DELETE, body.toString(), "fileplan-components/{fileplanComponentId}", delete.getId());
|
||||
usingRestWrapper().processEmptyModel(request);
|
||||
return request;
|
||||
}
|
||||
}
|
@@ -25,26 +25,13 @@ import org.testng.annotations.BeforeClass;
|
||||
*
|
||||
* @author Kristijan Conkas
|
||||
* @author Tuna Aksoy
|
||||
* @since 2.6
|
||||
* @since 1.0
|
||||
*/
|
||||
@Configuration
|
||||
@PropertySource("classpath:config.properties")
|
||||
@PropertySource(value = "classpath:local.properties", ignoreResourceNotFound = true)
|
||||
public class BaseIgRestTest extends RestTest
|
||||
public class BaseRestTest extends RestTest
|
||||
{
|
||||
/** Alias which can be used instead of the identifier of a node. */
|
||||
public static final String ALIAS_FILE_PLAN = "-filePlan-";
|
||||
public static final String ALIAS_TRANSFERS = "-transfers-";
|
||||
public static final String ALIAS_UNFILED_RECORDS_CONTAINER = "-unfiled-";
|
||||
public static final String ALIAS_HOLDS = "-holds-";
|
||||
|
||||
/** Component types. */
|
||||
public static final String COMPONENT_FILE_PLAN = "rma:filePlan";
|
||||
public static final String COMPONENT_RECORD_CATEGORY = "rma:recordCategory";
|
||||
public static final String COMPONENT_RECORD_FOLDER = "rma:recordFolder";
|
||||
public static final String COMPONENT_HOLD = "rma:hold";
|
||||
public static final String COMPONENT_UNFILED_RECORD_FOLDER = "rma:unfiledRecordFolder";
|
||||
|
||||
@Value("${alfresco.rm.scheme}")
|
||||
private String scheme;
|
||||
|
@@ -1,48 +0,0 @@
|
||||
/*
|
||||
* #%L
|
||||
* Alfresco Records Management Module
|
||||
* %%
|
||||
* Copyright (C) 2005 - 2016 Alfresco Software Limited
|
||||
* %%
|
||||
* License rights for this program may be obtained from Alfresco Software, Ltd.
|
||||
* pursuant to a written agreement and any use of this program without such an
|
||||
* agreement is prohibited.
|
||||
* #L%
|
||||
*/
|
||||
package org.alfresco.rest.fileplancomponents;
|
||||
|
||||
import static org.springframework.http.HttpStatus.OK;
|
||||
import static org.testng.Assert.assertEquals;
|
||||
|
||||
import org.alfresco.rest.BaseIgRestTest;
|
||||
import org.alfresco.rest.core.RestWrapper;
|
||||
import org.alfresco.rest.model.RestFilePlanComponentModel;
|
||||
import org.alfresco.rest.requests.RestFilePlanComponentApi;
|
||||
import org.alfresco.utility.data.DataUser;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
/**
|
||||
* FIXME: Document me :)
|
||||
*
|
||||
* @author Tuna Aksoy
|
||||
* @since 1.0
|
||||
*/
|
||||
public class FilePlanTest extends BaseIgRestTest
|
||||
{
|
||||
@Autowired
|
||||
private RestFilePlanComponentApi filePlanComponentApi;
|
||||
|
||||
@Autowired
|
||||
private DataUser dataUser;
|
||||
|
||||
@Test
|
||||
public void testfilePlanComponentsGet() throws Exception
|
||||
{
|
||||
RestWrapper restWrapper = filePlanComponentApi.usingRestWrapper();
|
||||
restWrapper.authenticateUser(dataUser.getAdminUser());
|
||||
RestFilePlanComponentModel filePlanComponent = filePlanComponentApi.getFilePlanComponent(ALIAS_FILE_PLAN);
|
||||
restWrapper.assertStatusCodeIs(OK);
|
||||
assertEquals(filePlanComponent.getNodeType(), COMPONENT_FILE_PLAN);
|
||||
}
|
||||
}
|
@@ -11,114 +11,155 @@
|
||||
*/
|
||||
package org.alfresco.rest.fileplancomponents;
|
||||
|
||||
import java.util.UUID;
|
||||
import static java.util.UUID.randomUUID;
|
||||
|
||||
import org.alfresco.rest.BaseIgRestTest;
|
||||
import static org.alfresco.com.FilePlanComponentAlias.FILE_PLAN_ALIAS;
|
||||
import static org.alfresco.com.FilePlanComponentFields.NAME;
|
||||
import static org.alfresco.com.FilePlanComponentFields.NODE_TYPE;
|
||||
import static org.alfresco.com.FilePlanComponentFields.PROPERTIES;
|
||||
import static org.alfresco.com.FilePlanComponentFields.PROPERTIES_TITLE;
|
||||
import static org.alfresco.com.FilePlanComponentType.RECORD_CATEGORY_TYPE;
|
||||
import static org.jglue.fluentjson.JsonBuilderFactory.buildObject;
|
||||
import static org.springframework.http.HttpStatus.CREATED;
|
||||
import static org.springframework.http.HttpStatus.NO_CONTENT;
|
||||
import static org.springframework.http.HttpStatus.OK;
|
||||
import static org.testng.Assert.assertEquals;
|
||||
import static org.testng.Assert.assertTrue;
|
||||
|
||||
import com.google.gson.JsonObject;
|
||||
|
||||
import org.alfresco.rest.BaseRestTest;
|
||||
import org.alfresco.rest.core.RestWrapper;
|
||||
import org.alfresco.rest.model.PropertiesModel;
|
||||
import org.alfresco.rest.model.RestFilePlanComponentModel;
|
||||
import org.alfresco.rest.requests.RestFilePlanComponentApi;
|
||||
import org.alfresco.rest.model.FilePlanComponent;
|
||||
import org.alfresco.rest.model.FilePlanComponentProperties;
|
||||
import org.alfresco.rest.requests.FilePlanComponentApi;
|
||||
import org.alfresco.utility.data.DataUser;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import static org.testng.Assert.assertEquals;
|
||||
import static org.testng.Assert.assertFalse;
|
||||
import static org.testng.Assert.assertTrue;
|
||||
import static org.testng.Assert.assertNotNull;
|
||||
import static org.springframework.http.HttpStatus.CREATED;
|
||||
import static org.springframework.http.HttpStatus.OK;
|
||||
import static org.springframework.http.HttpStatus.NO_CONTENT;
|
||||
|
||||
|
||||
/**
|
||||
* FIXME: Document me :)
|
||||
*
|
||||
* @author Kristijan Conkas
|
||||
* @since
|
||||
* @author Tuna Aksoy
|
||||
* @since 1.0
|
||||
*/
|
||||
public class RecordCategoryTest extends BaseIgRestTest
|
||||
public class RecordCategoryTest extends BaseRestTest
|
||||
{
|
||||
@Autowired
|
||||
private RestFilePlanComponentApi filePlanComponentApi;
|
||||
private FilePlanComponentApi filePlanComponentApi;
|
||||
|
||||
@Autowired
|
||||
private DataUser dataUser;
|
||||
|
||||
@Autowired
|
||||
private RestFilePlanComponentModel componentModel;
|
||||
|
||||
@Autowired
|
||||
private PropertiesModel propertiesModel;
|
||||
|
||||
/** new category name */
|
||||
private String categoryName = "cat " + UUID.randomUUID().toString().substring(0, 8);
|
||||
|
||||
private String newCategoryId = null;
|
||||
|
||||
@Test
|
||||
(
|
||||
description = "Create category as authorised user"
|
||||
)
|
||||
public void createCategoryAsAuthorisedUser() throws Exception
|
||||
{
|
||||
// create category
|
||||
propertiesModel.setTitle("New Test File Plan");
|
||||
componentModel.setId(ALIAS_FILE_PLAN );
|
||||
componentModel.setName(categoryName);
|
||||
componentModel.setNodeType(COMPONENT_RECORD_CATEGORY);
|
||||
componentModel.setProperties(propertiesModel);
|
||||
|
||||
RestWrapper restWrapper = filePlanComponentApi.usingRestWrapper().authenticateUser(dataUser.getAdminUser());
|
||||
RestFilePlanComponentModel filePlanComponent = filePlanComponentApi.createFilePlanComponent(componentModel);
|
||||
|
||||
// verify returned object
|
||||
String categoryName = "Category name " + randomUUID().toString().substring(0, 8);
|
||||
String categoryTitle = "Category title " + randomUUID().toString().substring(0, 8);
|
||||
|
||||
// Build the record category properties
|
||||
JsonObject recordCategoryProperties = buildObject().
|
||||
add(NAME, categoryName).
|
||||
add(NODE_TYPE, RECORD_CATEGORY_TYPE.toString()).
|
||||
addObject(PROPERTIES).
|
||||
add(PROPERTIES_TITLE, categoryTitle).
|
||||
end().
|
||||
getJson();
|
||||
|
||||
// Create the record category
|
||||
FilePlanComponent filePlanComponent = filePlanComponentApi.createFilePlanComponent(recordCategoryProperties, FILE_PLAN_ALIAS.toString());
|
||||
|
||||
// Verify the status code
|
||||
restWrapper.assertStatusCodeIs(CREATED);
|
||||
|
||||
// Verify the returned file plan component
|
||||
assertTrue(filePlanComponent.isIsCategory());
|
||||
assertEquals(filePlanComponent.getName(), categoryName);
|
||||
assertEquals(filePlanComponent.getNodeType(), COMPONENT_RECORD_CATEGORY.toString());
|
||||
assertFalse(filePlanComponent.getProperties().isVitalRecord());
|
||||
assertEquals(filePlanComponent.getNodeType(), RECORD_CATEGORY_TYPE.toString());
|
||||
|
||||
newCategoryId = filePlanComponent.getId();
|
||||
// Verify the returned file plan component properties
|
||||
FilePlanComponentProperties filePlanComponentProperties = filePlanComponent.getProperties();
|
||||
assertEquals(filePlanComponentProperties.getTitle(), categoryTitle);
|
||||
}
|
||||
|
||||
@Test
|
||||
(
|
||||
description = "Rename category as authorised user",
|
||||
dependsOnMethods= { "createCategoryAsAuthorisedUser" }
|
||||
)
|
||||
description = "Rename category as authorised user"
|
||||
)
|
||||
public void renameCategoryAsAuthorisedUser() throws Exception
|
||||
{
|
||||
assertNotNull(newCategoryId);
|
||||
String newName = "renamed " + categoryName;
|
||||
RestWrapper restWrapper = filePlanComponentApi.usingRestWrapper().authenticateUser(dataUser.getAdminUser());
|
||||
|
||||
RestWrapper restWrapper = filePlanComponentApi.usingRestWrapper();
|
||||
restWrapper.authenticateUser(dataUser.getAdminUser());
|
||||
// Create record category first
|
||||
|
||||
RestFilePlanComponentModel filePlanComponent = filePlanComponentApi.getFilePlanComponent(newCategoryId);
|
||||
filePlanComponent.setName(newName);
|
||||
String categoryName = "Category name " + randomUUID().toString().substring(0, 8);
|
||||
String categoryTitle = "Category title " + randomUUID().toString().substring(0, 8);
|
||||
|
||||
RestFilePlanComponentModel renamedFilePlanComponent = filePlanComponentApi.updateFilePlanComponent(filePlanComponent);
|
||||
// Build the record category properties
|
||||
JsonObject recordCategoryProperties = buildObject().
|
||||
add(NAME, categoryName).
|
||||
add(NODE_TYPE, RECORD_CATEGORY_TYPE.toString()).
|
||||
addObject(PROPERTIES).
|
||||
add(PROPERTIES_TITLE, categoryTitle).
|
||||
end().
|
||||
getJson();
|
||||
|
||||
// verify returned object
|
||||
// Create the record category
|
||||
FilePlanComponent filePlanComponent = filePlanComponentApi.createFilePlanComponent(recordCategoryProperties, FILE_PLAN_ALIAS.toString());
|
||||
|
||||
|
||||
String newCategoryName = "Rename " + categoryName;
|
||||
|
||||
// Build the properties which will be updated
|
||||
JsonObject updateRecordCategoryProperties = buildObject().
|
||||
add(NAME, newCategoryName).
|
||||
getJson();
|
||||
|
||||
// Update the record category
|
||||
FilePlanComponent renamedFilePlanComponent = filePlanComponentApi.updateFilePlanComponent(updateRecordCategoryProperties, filePlanComponent.getId());
|
||||
|
||||
// Verify the status code
|
||||
restWrapper.assertStatusCodeIs(OK);
|
||||
assertEquals(renamedFilePlanComponent.getName(), newName);
|
||||
|
||||
// Verify the returned file plan component
|
||||
assertEquals(renamedFilePlanComponent.getName(), newCategoryName);
|
||||
}
|
||||
|
||||
@Test
|
||||
(
|
||||
description = "Rename category as authorised user",
|
||||
dependsOnMethods= { "renameCategoryAsAuthorisedUser" }
|
||||
description = "Rename category as authorised user"
|
||||
)
|
||||
public void deleteCategoryAsAuthorisedUser() throws Exception
|
||||
{
|
||||
// delete
|
||||
RestWrapper restWrapper = filePlanComponentApi.usingRestWrapper();
|
||||
restWrapper.authenticateUser(dataUser.getAdminUser());
|
||||
filePlanComponentApi.deleteFilePlanComponent(filePlanComponentApi.getFilePlanComponent(newCategoryId), true);
|
||||
RestWrapper restWrapper = filePlanComponentApi.usingRestWrapper().authenticateUser(dataUser.getAdminUser());
|
||||
|
||||
// verify deletion
|
||||
// Create record category first
|
||||
|
||||
String categoryName = "Category name " + randomUUID().toString().substring(0, 8);
|
||||
String categoryTitle = "Category title " + randomUUID().toString().substring(0, 8);
|
||||
|
||||
// Build the record category properties
|
||||
JsonObject recordCategoryProperties = buildObject().
|
||||
add(NAME, categoryName).
|
||||
add(NODE_TYPE, RECORD_CATEGORY_TYPE.toString()).
|
||||
addObject(PROPERTIES).
|
||||
add(PROPERTIES_TITLE, categoryTitle).
|
||||
end().
|
||||
getJson();
|
||||
|
||||
// Create the record category
|
||||
FilePlanComponent filePlanComponent = filePlanComponentApi.createFilePlanComponent(recordCategoryProperties, FILE_PLAN_ALIAS.toString());
|
||||
|
||||
// Delete the record category
|
||||
filePlanComponentApi.deleteFilePlanComponent(filePlanComponent.getId());
|
||||
|
||||
// Verify the status code
|
||||
restWrapper.assertStatusCodeIs(NO_CONTENT);
|
||||
// TODO: verify we can't get an object with this ID again
|
||||
// TODO: can we verify that deletion with deletePermanently=false indeed ended up in trashcan?
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user