Merge branch 'feature/RM-3964_Record_Category_CRUD_2' into 'master'

Feature/rm 3964 record category crud 2

MR to complete RM-3964.

See merge request !6
This commit is contained in:
Kristijan Conkas
2016-10-28 11:56:03 +01:00
4 changed files with 158 additions and 34 deletions

View File

@@ -12,7 +12,7 @@
package org.alfresco.com.fileplancomponents; package org.alfresco.com.fileplancomponents;
/** /**
* FIXME: Document me :) * File plan component field names constants
* *
* @author Tuna Aksoy * @author Tuna Aksoy
* @since 1.0 * @since 1.0
@@ -21,6 +21,7 @@ public class FilePlanComponentFields
{ {
public static final String NAME = "name"; public static final String NAME = "name";
public static final String NODE_TYPE = "nodeType"; public static final String NODE_TYPE = "nodeType";
public static final String NODE_PARENT_ID = "parentId";
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_VITAL_RECORD_INDICATOR = "rma:vitalRecordIndicator"; public static final String PROPERTIES_VITAL_RECORD_INDICATOR = "rma:vitalRecordIndicator";

View File

@@ -13,6 +13,8 @@ package org.alfresco.rest.model.fileplancomponents;
import static org.alfresco.com.fileplancomponents.FilePlanComponentFields.PROPERTIES; import static org.alfresco.com.fileplancomponents.FilePlanComponentFields.PROPERTIES;
import java.util.List;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.annotation.JsonProperty;
@@ -42,8 +44,12 @@ public class FilePlanComponent
private boolean hasRetentionSchedule; private boolean hasRetentionSchedule;
private List<String> aspectNames;
@JsonProperty(PROPERTIES) @JsonProperty(PROPERTIES)
private FilePlanComponentProperties properties; private FilePlanComponentProperties properties;
private FilePlanComponentCreatedByUser createdByUser;
/** /**
* @return the id * @return the id
@@ -188,4 +194,36 @@ public class FilePlanComponent
{ {
this.properties = properties; this.properties = properties;
} }
/**
* @return the aspectNames
*/
public List<String> getAspectNames()
{
return this.aspectNames;
}
/**
* @param aspectNames the aspectNames to set
*/
public void setAspectNames(List<String> aspectNames)
{
this.aspectNames = aspectNames;
}
/**
* @return the createdByUser
*/
public FilePlanComponentCreatedByUser getCreatedByUser()
{
return this.createdByUser;
}
/**
* @param createdByUser the createdByUser to set
*/
public void setCreatedByUser(FilePlanComponentCreatedByUser createdByUser)
{
this.createdByUser = createdByUser;
}
} }

View File

@@ -0,0 +1,51 @@
/*
* #%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.fileplancomponents;
/**
* POJO for file plan component created by object
* @author Kristijan Conkas
* @since 1.0
*/
public class FilePlanComponentCreatedByUser
{
private String id;
private String displayName;
/**
* @return the id
*/
public String getId()
{
return this.id;
}
/**
* @param id the id to set
*/
public void setId(String id)
{
this.id = id;
}
/**
* @return the displayName
*/
public String getDisplayName()
{
return this.displayName;
}
/**
* @param displayName the displayName to set
*/
public void setDisplayName(String displayName)
{
this.displayName = displayName;
}
}

View File

@@ -22,15 +22,16 @@ import static org.alfresco.com.fileplancomponents.FilePlanComponentType.RECORD_C
import static org.alfresco.com.fileplancomponents.FilePlanComponentType.RECORD_FOLDER_TYPE; import static org.alfresco.com.fileplancomponents.FilePlanComponentType.RECORD_FOLDER_TYPE;
import static org.jglue.fluentjson.JsonBuilderFactory.buildObject; import static org.jglue.fluentjson.JsonBuilderFactory.buildObject;
import static org.springframework.http.HttpStatus.CREATED; import static org.springframework.http.HttpStatus.CREATED;
import static org.springframework.http.HttpStatus.NOT_FOUND;
import static org.springframework.http.HttpStatus.NO_CONTENT; import static org.springframework.http.HttpStatus.NO_CONTENT;
import static org.springframework.http.HttpStatus.OK; import static org.springframework.http.HttpStatus.OK;
import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertFalse;
import static org.testng.Assert.assertNotNull; import static org.testng.Assert.assertNotNull;
import static org.testng.Assert.assertTrue; import static org.testng.Assert.assertTrue;
import static org.testng.Assert.fail; import static org.testng.Assert.fail;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List;
import java.util.NoSuchElementException; import java.util.NoSuchElementException;
import com.google.gson.JsonObject; import com.google.gson.JsonObject;
@@ -39,7 +40,6 @@ import org.alfresco.com.fileplancomponents.FilePlanComponentType;
import org.alfresco.rest.BaseRestTest; import org.alfresco.rest.BaseRestTest;
import org.alfresco.rest.core.RestWrapper; import org.alfresco.rest.core.RestWrapper;
import org.alfresco.rest.model.fileplancomponents.FilePlanComponent; import org.alfresco.rest.model.fileplancomponents.FilePlanComponent;
import org.alfresco.rest.model.fileplancomponents.FilePlanComponentEntry;
import org.alfresco.rest.model.fileplancomponents.FilePlanComponentProperties; import org.alfresco.rest.model.fileplancomponents.FilePlanComponentProperties;
import org.alfresco.rest.model.fileplancomponents.FilePlanComponentsCollection; import org.alfresco.rest.model.fileplancomponents.FilePlanComponentsCollection;
import org.alfresco.rest.requests.FilePlanComponentApi; import org.alfresco.rest.requests.FilePlanComponentApi;
@@ -74,9 +74,9 @@ public class RecordCategoryTest extends BaseRestTest
*/ */
@Test @Test
( (
description = "Create category as authorised user" description = "Create root category"
) )
public void createCategoryAsAuthorisedUser() throws Exception public void createCategoryTest() throws Exception
{ {
RestWrapper restWrapper = filePlanComponentApi.usingRestWrapper().authenticateUser(dataUser.getAdminUser()); RestWrapper restWrapper = filePlanComponentApi.usingRestWrapper().authenticateUser(dataUser.getAdminUser());
@@ -100,12 +100,20 @@ public class RecordCategoryTest extends BaseRestTest
// Verify the returned file plan component // Verify the returned file plan component
assertTrue(filePlanComponent.isIsCategory()); assertTrue(filePlanComponent.isIsCategory());
assertFalse(filePlanComponent.isIsFile());
assertFalse(filePlanComponent.isIsRecordFolder());
assertEquals(filePlanComponent.getName(), categoryName); assertEquals(filePlanComponent.getName(), categoryName);
assertEquals(filePlanComponent.getNodeType(), RECORD_CATEGORY_TYPE.toString()); assertEquals(filePlanComponent.getNodeType(), RECORD_CATEGORY_TYPE.toString());
assertFalse(filePlanComponent.isHasRetentionSchedule());
assertEquals(filePlanComponent.getCreatedByUser().getId(), dataUser.getAdminUser().getUsername());
// Verify the returned file plan component properties // Verify the returned file plan component properties
FilePlanComponentProperties filePlanComponentProperties = filePlanComponent.getProperties(); FilePlanComponentProperties filePlanComponentProperties = filePlanComponent.getProperties();
assertEquals(filePlanComponentProperties.getTitle(), categoryTitle); assertEquals(filePlanComponentProperties.getTitle(), categoryTitle);
logger.info("aspects: " + filePlanComponent.getAspectNames());
} }
/** /**
@@ -116,14 +124,13 @@ public class RecordCategoryTest extends BaseRestTest
*/ */
@Test @Test
( (
description = "Rename category as authorised user" description = "Rename root category"
) )
public void renameCategoryAsAuthorisedUser() throws Exception public void renameCategory() throws Exception
{ {
RestWrapper restWrapper = filePlanComponentApi.usingRestWrapper().authenticateUser(dataUser.getAdminUser()); RestWrapper restWrapper = filePlanComponentApi.usingRestWrapper().authenticateUser(dataUser.getAdminUser());
// Create record category first // Create record category first
String categoryName = "Category name " + randomUUID().toString().substring(0, 8); String categoryName = "Category name " + randomUUID().toString().substring(0, 8);
String categoryTitle = "Category title " + randomUUID().toString().substring(0, 8); String categoryTitle = "Category title " + randomUUID().toString().substring(0, 8);
@@ -154,6 +161,11 @@ public class RecordCategoryTest extends BaseRestTest
// Verify the returned file plan component // Verify the returned file plan component
assertEquals(renamedFilePlanComponent.getName(), newCategoryName); assertEquals(renamedFilePlanComponent.getName(), newCategoryName);
// get actual FILE_PLAN_ALIAS id
FilePlanComponent parentComponent = filePlanComponentApi.getFilePlanComponent(FILE_PLAN_ALIAS.toString());
// verify renamed component still has this parent
assertEquals(renamedFilePlanComponent.getParentId(), parentComponent.getId());
} }
/** /**
@@ -164,14 +176,13 @@ public class RecordCategoryTest extends BaseRestTest
*/ */
@Test @Test
( (
description = "Delete category as authorised user" description = "Delete category"
) )
public void deleteCategoryAsAuthorisedUser() throws Exception public void deleteCategory() throws Exception
{ {
RestWrapper restWrapper = filePlanComponentApi.usingRestWrapper().authenticateUser(dataUser.getAdminUser()); RestWrapper restWrapper = filePlanComponentApi.usingRestWrapper().authenticateUser(dataUser.getAdminUser());
// Create record category first // Create record category first
String categoryName = "Category name " + randomUUID().toString().substring(0, 8); String categoryName = "Category name " + randomUUID().toString().substring(0, 8);
String categoryTitle = "Category title " + randomUUID().toString().substring(0, 8); String categoryTitle = "Category title " + randomUUID().toString().substring(0, 8);
@@ -192,6 +203,10 @@ public class RecordCategoryTest extends BaseRestTest
// Verify the status code // Verify the status code
restWrapper.assertStatusCodeIs(NO_CONTENT); restWrapper.assertStatusCodeIs(NO_CONTENT);
// deleted component should no longer be retrievable
filePlanComponentApi.getFilePlanComponent(filePlanComponent.getId());
restWrapper.assertStatusCodeIs(NOT_FOUND);
} }
/** /**
@@ -215,6 +230,13 @@ public class RecordCategoryTest extends BaseRestTest
// child category created? // child category created?
assertNotNull(childCategory.getId()); assertNotNull(childCategory.getId());
// verify child category
assertEquals(childCategory.getParentId(), rootCategory.getId());
assertTrue(childCategory.isIsCategory());
assertFalse(childCategory.isIsFile());
assertFalse(childCategory.isIsRecordFolder());
assertEquals(childCategory.getNodeType(), RECORD_CATEGORY_TYPE.toString());
} }
/** /**
@@ -233,7 +255,7 @@ public class RecordCategoryTest extends BaseRestTest
{ {
// create root level category // create root level category
FilePlanComponent rootCategory = createCategory(FILE_PLAN_ALIAS.toString(), RandomData.getRandomAlphanumeric()); FilePlanComponent rootCategory = createCategory(FILE_PLAN_ALIAS.toString(), RandomData.getRandomAlphanumeric());
assertNotNull(rootCategory.getId()); assertNotNull(rootCategory.getId());
// add child categories/folders // add child categories/folders
ArrayList<FilePlanComponent> children = new ArrayList<FilePlanComponent>(); ArrayList<FilePlanComponent> children = new ArrayList<FilePlanComponent>();
@@ -252,28 +274,51 @@ public class RecordCategoryTest extends BaseRestTest
RestWrapper restWrapper = filePlanComponentApi.usingRestWrapper().authenticateUser(dataUser.getAdminUser()); RestWrapper restWrapper = filePlanComponentApi.usingRestWrapper().authenticateUser(dataUser.getAdminUser());
FilePlanComponentsCollection apiChildren = filePlanComponentApi.listChildComponents(rootCategory.getId()); FilePlanComponentsCollection apiChildren = filePlanComponentApi.listChildComponents(rootCategory.getId());
restWrapper.assertStatusCodeIs(OK); restWrapper.assertStatusCodeIs(OK);
logger.info("parent: " + rootCategory.getId());
// check listed children against created list // check listed children against created list
List<FilePlanComponentEntry> childrenApi = apiChildren.getEntries(); apiChildren.getEntries().forEach(c ->
childrenApi.forEach(c ->
{ {
FilePlanComponent filePlanComponent = c.getFilePlanComponent(); FilePlanComponent filePlanComponent = c.getFilePlanComponent();
assertNotNull(filePlanComponent.getId()); assertNotNull(filePlanComponent.getId());
logger.info("checking child " + filePlanComponent.getId());
logger.info(c + " id=" + filePlanComponent.getId() + " name=" + filePlanComponent.getName() + " properties=" + filePlanComponent.getProperties());
try
try
{ {
// find this child in created children list
FilePlanComponent createdComponent = children.stream() FilePlanComponent createdComponent = children.stream()
.filter(child -> child.getId().compareTo(filePlanComponent.getId()) == 0) .filter(child -> child.getId().equals(filePlanComponent.getId()))
.findFirst() .findFirst()
.get(); .get();
// created by
assertEquals(filePlanComponent.getCreatedByUser().getId(), dataUser.getAdminUser().getUsername());
// is parent Id set correctly?
assertEquals(filePlanComponent.getParentId(), rootCategory.getId());
// only categories or folders have been created
assertFalse(filePlanComponent.isIsFile());
// boolean properties related to node type
// only RECORD_CATEGORY_TYPE and RECORD_FOLDER_TYPE have been created
if (filePlanComponent.getNodeType().equals(RECORD_CATEGORY_TYPE.toString()))
{
assertTrue(filePlanComponent.isIsCategory());
assertFalse(filePlanComponent.isIsRecordFolder());
}
else
{
assertTrue(filePlanComponent.isIsRecordFolder());
assertFalse(filePlanComponent.isIsCategory());
}
// does returned object have the same contents as the created one? // does returned object have the same contents as the created one?
assertEquals(createdComponent.getName(), filePlanComponent.getName()); assertEquals(createdComponent.getName(), filePlanComponent.getName());
assertEquals(createdComponent.getNodeType(), filePlanComponent.getNodeType()); assertEquals(createdComponent.getNodeType(), filePlanComponent.getNodeType());
//assertEquals(createdComponent.getProperties().getTitle(), filePlanComponent.getProperties().getTitle());
} // verify properties
}
catch (NoSuchElementException e) catch (NoSuchElementException e)
{ {
fail("No child element for " + filePlanComponent.getId()); fail("No child element for " + filePlanComponent.getId());
@@ -292,17 +337,6 @@ public class RecordCategoryTest extends BaseRestTest
return createComponent(parentCategoryId, categoryName, RECORD_CATEGORY_TYPE); 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 * Helper method to create generic child component
* @param parentComponentId * @param parentComponentId