RM-3964: Refactoring further to API implementation discussion.

This commit is contained in:
Kristijan Conkas
2016-10-25 16:45:47 +01:00
parent a892c63d77
commit fefee35dac
4 changed files with 192 additions and 8 deletions

View File

@@ -16,21 +16,16 @@ import static org.alfresco.com.FilePlanComponentFields.PROPERTIES;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
/**
* POJO for file plan component
*
* @author Tuna Aksoy
* @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 FilePlanComponent
{
{
private String id;
private String parentId;

View File

@@ -0,0 +1,24 @@
/*
* #%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.model;
import org.alfresco.rest.core.RestModels;
/**
* Handle collection of FilePlanComponents
* @author Kristijan Conkas
* @since 1.0
*/
public class FilePlanComponentsCollection extends RestModels<FilePlanComponent, FilePlanComponentsCollection>
{
}

View File

@@ -24,6 +24,7 @@ import com.google.gson.JsonObject;
import org.alfresco.rest.core.RestAPI;
import org.alfresco.rest.model.FilePlanComponent;
import org.alfresco.rest.model.FilePlanComponentsCollection;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
@@ -61,6 +62,29 @@ public class FilePlanComponentApi extends RestAPI
));
}
/**
* List child components of a file plan component
*
* @param filePlanComponentId The id of the file plan component of which to get child components
* @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 FilePlanComponentsCollection listChildComponents(String filePlanComponentId) throws Exception
{
mandatoryString("filePlanComponentId", filePlanComponentId);
return usingRestWrapper().processModels(FilePlanComponentsCollection.class, simpleRequest(
GET,
"fileplan-components/{fileplanComponentId}/children",
filePlanComponentId
));
}
/**
* Creates a file plan component with the given properties under the parent node with the given id
*

View File

@@ -19,21 +19,29 @@ 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.alfresco.com.FilePlanComponentType.RECORD_FOLDER_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.assertNotNull;
import static org.testng.Assert.assertTrue;
import java.util.ArrayList;
import java.util.List;
import com.google.gson.JsonObject;
import org.alfresco.com.FilePlanComponentType;
import org.alfresco.rest.BaseRestTest;
import org.alfresco.rest.core.RestWrapper;
import org.alfresco.rest.model.FilePlanComponent;
import org.alfresco.rest.model.FilePlanComponentProperties;
import org.alfresco.rest.model.FilePlanComponentsCollection;
import org.alfresco.rest.requests.FilePlanComponentApi;
import org.alfresco.utility.data.DataUser;
import org.alfresco.utility.data.RandomData;
import org.springframework.beans.factory.annotation.Autowired;
import org.testng.annotations.Test;
@@ -51,7 +59,16 @@ public class RecordCategoryTest extends BaseRestTest
@Autowired
private DataUser dataUser;
// for children creation test
private static final int NUMBER_OF_CHILDREN = 10;
/**
* <pre>
* Given that a file plan exists
* When I ask the API to create a root record category
* Then it is created as a root record category
*/
@Test
(
description = "Create category as authorised user"
@@ -88,6 +105,12 @@ public class RecordCategoryTest extends BaseRestTest
assertEquals(filePlanComponentProperties.getTitle(), categoryTitle);
}
/**
* <pre>
* Given that a record category exists
* When I ask the API to update the details of the record category
* Then the details of the record category are updated
*/
@Test
(
description = "Rename category as authorised user"
@@ -113,7 +136,6 @@ public class RecordCategoryTest extends BaseRestTest
// Create the record category
FilePlanComponent filePlanComponent = filePlanComponentApi.createFilePlanComponent(recordCategoryProperties, FILE_PLAN_ALIAS.toString());
String newCategoryName = "Rename " + categoryName;
// Build the properties which will be updated
@@ -131,9 +153,15 @@ public class RecordCategoryTest extends BaseRestTest
assertEquals(renamedFilePlanComponent.getName(), newCategoryName);
}
/**
* <pre>
* Given that a record category exists
* When I ask the API to delete the record category
* Then the record category and all its contents is deleted
*/
@Test
(
description = "Rename category as authorised user"
description = "Delete category as authorised user"
)
public void deleteCategoryAsAuthorisedUser() throws Exception
{
@@ -162,4 +190,117 @@ public class RecordCategoryTest extends BaseRestTest
// Verify the status code
restWrapper.assertStatusCodeIs(NO_CONTENT);
}
/**
* <pre>
* Given that a record category exists
* When I ask the API to create a record category
* Then it is created within the record category
*/
@Test
(
description = "Create child category"
)
public void createSubcategory() throws Exception
{
// create root level category
FilePlanComponent rootCategory = createCategory(FILE_PLAN_ALIAS.toString(), RandomData.getRandomAlphanumeric());
assertNotNull(rootCategory.getId());
// create subcategory as a child of rootCategory
FilePlanComponent childCategory = createCategory(rootCategory.getId(), RandomData.getRandomAlphanumeric());
// child category created?
assertNotNull(childCategory.getId());
}
/**
* <pre>
* Given that a record category exists
* And contains a number of record categories and record folders
* When I ask the APi to get me the children of the record category
* Then I am returned the contained record categories and record folders
* And their details
*/
@Test
(
description = "List children of a category"
)
public void listChildren() throws Exception
{
// create root level category
FilePlanComponent rootCategory = createCategory(FILE_PLAN_ALIAS.toString(), RandomData.getRandomAlphanumeric());
assertNotNull(rootCategory.getId());
// add child categories/folders
ArrayList<FilePlanComponent> children = new ArrayList<FilePlanComponent>();
for(int i=0; i < NUMBER_OF_CHILDREN; i++)
{
// create a child
FilePlanComponent child = createComponent(rootCategory.getId(),
RandomData.getRandomAlphanumeric(),
// half of the children should be subcategories, the other subfolders
(i <= NUMBER_OF_CHILDREN / 2) ? RECORD_CATEGORY_TYPE : RECORD_FOLDER_TYPE);
assertNotNull(child.getId());
children.add(child);
}
// list children from API
RestWrapper restWrapper = filePlanComponentApi.usingRestWrapper().authenticateUser(dataUser.getAdminUser());
FilePlanComponentsCollection apiChildren = filePlanComponentApi.listChildComponents(rootCategory.getId());
restWrapper.assertStatusCodeIs(OK);
List<FilePlanComponent> childrenApi = apiChildren.getEntries();
childrenApi.forEach(c -> {
//assertNotNull(c.getId());
logger.info(c + " id=" + c.getId() + " name=" + c.getName() + " properties=" + c.getProperties());
});
}
/**
* Helper method to create child category
* @param parentCategoryId
* @param categoryName
* @throws Exception on unsuccessful component creation
*/
private FilePlanComponent createCategory(String parentCategoryId, String categoryName) throws Exception
{
return createComponent(parentCategoryId, categoryName, RECORD_CATEGORY_TYPE);
}
/**
* Helper method to create child folder
* @param parentComponentId parent category or folder id
* @param folderName new folder name
* @throws Exception on unsuccessful folder creation
*/
private FilePlanComponent createFolder(String parentComponentId, String folderName) throws Exception
{
return createComponent(parentComponentId, folderName, RECORD_FOLDER_TYPE);
}
/**
* Helper method to create generic child component
* @param parentComponentId
* @param componentName
* @param componentType
* @return
* @throws Exception
*/
private FilePlanComponent createComponent(String parentComponentId, String componentName, FilePlanComponentType componentType) throws Exception
{
RestWrapper restWrapper = filePlanComponentApi.usingRestWrapper().authenticateUser(dataUser.getAdminUser());
JsonObject componentProperties = buildObject().
add(NAME, componentName).
add(NODE_TYPE, componentType.toString()).
addObject(PROPERTIES).
add(PROPERTIES_TITLE, "Title for " + componentName).
end().
getJson();
FilePlanComponent fpc = filePlanComponentApi.createFilePlanComponent(componentProperties, parentComponentId);
restWrapper.assertStatusCodeIs(CREATED);
return fpc;
}
}