From 42dac04cd211f278fdbc73375c9612ea4bca5c2d Mon Sep 17 00:00:00 2001 From: Rodica Sutu Date: Mon, 28 Nov 2016 14:34:58 +0200 Subject: [PATCH] tidy up code, add java docs --- .../fileplancomponents/FilePlanComponent.java | 27 ++++++++++++++++--- .../fileplancomponents/ReviewPeriod.java | 9 +++++++ .../rest/rm/community/model/site/RMSite.java | 16 ++++++++++- .../rest/rm/community/util/PojoUtility.java | 16 +++++++---- .../util/ReviewPeriodSerializer.java | 10 ++++++- .../fileplancomponents/FilePlanTests.java | 5 ++-- .../RecordCategoryTest.java | 7 +++-- .../fileplancomponents/RecordFolderTests.java | 11 ++++++-- .../UnfiledRecordsFolderTests.java | 3 ++- 9 files changed, 87 insertions(+), 17 deletions(-) diff --git a/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/rm/community/model/fileplancomponents/FilePlanComponent.java b/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/rm/community/model/fileplancomponents/FilePlanComponent.java index 3807987900..c0fbe62a63 100644 --- a/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/rm/community/model/fileplancomponents/FilePlanComponent.java +++ b/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/rm/community/model/fileplancomponents/FilePlanComponent.java @@ -38,6 +38,7 @@ import com.fasterxml.jackson.annotation.JsonProperty; * POJO for file plan component * * @author Tuna Aksoy + * @author Rodica Sutu * @since 2.6 */ public class FilePlanComponent @@ -94,6 +95,13 @@ public class FilePlanComponent @JsonProperty (required = true) private FilePlanComponentUserInfo modifiedByUser; + + /**Helper constructor for creating the file plan component using + * + * @param name File Plan Component name + * @param nodeType File Plan Component node type + * @param properties File Plan Component properties + */ public FilePlanComponent(String name, String nodeType, FilePlanComponentProperties properties) { this.name = name; @@ -101,14 +109,27 @@ public class FilePlanComponent this.properties = properties; } - public FilePlanComponent() - { - } + /** + * Helper constructor to create empty file plan component + */ + public FilePlanComponent() { } + /** + * Helper constructor for creating the file plan component using + * + * @param name File Plan Component name + */ public FilePlanComponent(String name) { this.name = name; } + + /** + * Helper constructor for creating the file plan component using + * + * @param name File Plan Component name + * @param properties File Plan Component properties + */ public FilePlanComponent(String name, FilePlanComponentProperties properties) { this.name = name; diff --git a/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/rm/community/model/fileplancomponents/ReviewPeriod.java b/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/rm/community/model/fileplancomponents/ReviewPeriod.java index c338f4d784..30c2c63938 100644 --- a/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/rm/community/model/fileplancomponents/ReviewPeriod.java +++ b/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/rm/community/model/fileplancomponents/ReviewPeriod.java @@ -38,12 +38,21 @@ public class ReviewPeriod private String periodType; private String expression; + /** + * Helper constructor with + * + * @param periodType + * @param expression + */ public ReviewPeriod(String periodType, String expression) { this.periodType = periodType; this.expression = expression; } + /** + * Helper constructor + */ public ReviewPeriod() { } diff --git a/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/rm/community/model/site/RMSite.java b/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/rm/community/model/site/RMSite.java index 1bea0145dc..e9f80ede48 100644 --- a/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/rm/community/model/site/RMSite.java +++ b/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/rm/community/model/site/RMSite.java @@ -29,7 +29,6 @@ package org.alfresco.rest.rm.community.model.site; import static org.alfresco.rest.rm.community.model.site.RMSiteFields.COMPLIANCE; import com.fasterxml.jackson.annotation.JsonProperty; -import com.google.gson.Gson; import org.alfresco.rest.model.RestSiteModel; @@ -44,6 +43,13 @@ public class RMSite extends RestSiteModel @JsonProperty (value = COMPLIANCE,required = true) private RMSiteCompliance compliance; + /** + * Helper constructor to create RM Site object using + * + * @param title + * @param description + * @param compliance + */ public RMSite(String title, String description, RMSiteCompliance compliance) { this.title=title; @@ -51,8 +57,16 @@ public class RMSite extends RestSiteModel this.compliance=compliance; } + /** + * Helper constructor for creating the RM Site + */ public RMSite() { } + /** + * Helper constructor to create RM Site object using + * + * @param compliance RM Site Compliance + */ public RMSite(RMSiteCompliance compliance) { super(); diff --git a/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/rm/community/util/PojoUtility.java b/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/rm/community/util/PojoUtility.java index 724d267c4c..ede5960c17 100644 --- a/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/rm/community/util/PojoUtility.java +++ b/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/rm/community/util/PojoUtility.java @@ -42,16 +42,22 @@ import com.fasterxml.jackson.databind.ObjectMapper; */ public class PojoUtility { - - public static String toJson(Object rmModel) throws JsonProcessingException + /** + * Converting object to JSON string + * + * @param model The java object model to convert + * @throws JsonProcessingException Throws exceptions if the given object doesn't match to the POJO class model + */ + public static String toJson(Object model) throws JsonProcessingException { ObjectMapper mapper = new ObjectMapper(); + //include only values that differ from default settings to be included mapper.setSerializationInclusion(Include.NON_DEFAULT); try { - String json = mapper.writerWithDefaultPrettyPrinter().writeValueAsString(rmModel); - System.out.println("Json object generated is :" + json); - return json; + //return the json object + return mapper.writerWithDefaultPrettyPrinter().writeValueAsString(model); + } catch (JsonGenerationException e) { return e.toString(); diff --git a/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/rm/community/util/ReviewPeriodSerializer.java b/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/rm/community/util/ReviewPeriodSerializer.java index 09f00828b4..97c8847dcf 100644 --- a/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/rm/community/util/ReviewPeriodSerializer.java +++ b/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/rm/community/util/ReviewPeriodSerializer.java @@ -45,10 +45,18 @@ import org.alfresco.rest.rm.community.model.fileplancomponents.ReviewPeriod; public class ReviewPeriodSerializer extends JsonSerializer { + /** + * @param value The Review Period value that is being serialized. + * @param gen Jackson utility is responsible for writing JSON + * @param serializers Provider for getting access to other serializers and configurations registered with the ObjectMapper. + * @throws IOException + * @throws JsonProcessingException + */ @Override public void serialize(ReviewPeriod value, JsonGenerator gen, SerializerProvider serializers) throws IOException, JsonProcessingException { - gen.writeString(String.valueOf(new StringBuilder().append(value.getPeriodType()).append("|").append(value.getExpression()))); + //create the custom string value for the Review Period type + gen.writeString(new StringBuilder().append(value.getPeriodType()).append("|").append(value.getExpression()).toString()); } } diff --git a/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/fileplancomponents/FilePlanTests.java b/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/fileplancomponents/FilePlanTests.java index 0e5c7e62a3..bd95856a50 100644 --- a/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/fileplancomponents/FilePlanTests.java +++ b/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/fileplancomponents/FilePlanTests.java @@ -198,7 +198,7 @@ public class FilePlanTests extends BaseRestTest // Authenticate with admin user filePlanComponentAPI.usingRestWrapper().authenticateUser(dataUser.getAdminUser()); - // Build the file plan root properties + // Build object for updating the filePlan FilePlanComponent filePlanComponent= new FilePlanComponent(); FilePlanComponentProperties filePlanComponentProperties=new FilePlanComponentProperties(FILE_PLAN_TITLE, FILE_PLAN_DESCRIPTION); filePlanComponent.setProperties(filePlanComponentProperties); @@ -295,9 +295,9 @@ public class FilePlanTests extends BaseRestTest // Authenticate with admin user rmSiteAPI.usingRestWrapper().authenticateUser(dataUser.getAdminUser()); + // Get the RM site ID String rmSiteId = rmSiteAPI.getSite().getGuid(); - String name = filePlanAlias + getRandomAlphanumeric(); // Build the file plan root properties @@ -305,6 +305,7 @@ public class FilePlanTests extends BaseRestTest // Authenticate with admin user filePlanComponentAPI.usingRestWrapper().authenticateUser(dataUser.getAdminUser()); + // Create the special containers into RM site - parent folder filePlanComponentAPI.createFilePlanComponent(filePlanComponent, rmSiteId); filePlanComponentAPI.usingRestWrapper().assertStatusCodeIs(UNPROCESSABLE_ENTITY); diff --git a/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/fileplancomponents/RecordCategoryTest.java b/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/fileplancomponents/RecordCategoryTest.java index 376cc3b22a..6a5364e3ec 100644 --- a/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/fileplancomponents/RecordCategoryTest.java +++ b/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/fileplancomponents/RecordCategoryTest.java @@ -340,14 +340,17 @@ public class RecordCategoryTest extends BaseRestTest public void createTypesNotAllowedInCategory(String nodeType) throws Exception { String COMPONENT_NAME="Component"+getRandomAlphanumeric(); - // Authenticate with admin user + // Authenticate with admin user filePlanComponentAPI.usingRestWrapper().authenticateUser(dataUser.getAdminUser()); + + //Create the category FilePlanComponent category = createCategory(FILE_PLAN_ALIAS.toString(), COMPONENT_NAME); //Build node properties FilePlanComponent recordCategory = new FilePlanComponent(COMPONENT_NAME,nodeType, - new FilePlanComponentProperties("Title for " + COMPONENT_NAME)); + new FilePlanComponentProperties("Title for " + COMPONENT_NAME)); + //create the invalid node type filePlanComponentAPI.createFilePlanComponent(recordCategory, category.getId()); filePlanComponentAPI.usingRestWrapper().assertStatusCodeIs(UNPROCESSABLE_ENTITY); diff --git a/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/fileplancomponents/RecordFolderTests.java b/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/fileplancomponents/RecordFolderTests.java index 5892ea0b41..bf38a0283a 100644 --- a/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/fileplancomponents/RecordFolderTests.java +++ b/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/fileplancomponents/RecordFolderTests.java @@ -197,7 +197,10 @@ public class RecordFolderTests extends BaseRestTest String CATEGORY = CATEGORY_NAME + getRandomAlphanumeric(); // Authenticate with admin user filePlanComponentAPI.usingRestWrapper().authenticateUser(dataUser.getAdminUser()); + //Create a record category FilePlanComponent category = createCategory(FILE_PLAN_ALIAS.toString(), CATEGORY); + + //Create a record folder FilePlanComponent folder = createFolder(category.getId(), FOLDER_NAME); // Create record category first @@ -206,13 +209,13 @@ public class RecordFolderTests extends BaseRestTest String folderTitle = "Update title " + getRandomAlphanumeric(); String location="Location"+getRandomAlphanumeric(); - String review_period="month|1"; - + //Create the file plan component properties to update FilePlanComponentProperties filePlanComponentProperties= new FilePlanComponentProperties(folderTitle, folderDescription); filePlanComponentProperties.setVitalRecord(true); filePlanComponentProperties.setReviewPeriod( new ReviewPeriod("month","1")); filePlanComponentProperties.setLocation(location); FilePlanComponent recordFolder = new FilePlanComponent(folderName,filePlanComponentProperties); + // Update the record category FilePlanComponent folderUpdated = filePlanComponentAPI.updateFilePlanComponent(recordFolder, folder.getId()); @@ -246,8 +249,12 @@ public class RecordFolderTests extends BaseRestTest // Authenticate with admin user filePlanComponentAPI.usingRestWrapper().authenticateUser(dataUser.getAdminUser()); + // Create the record category FilePlanComponent category = createCategory(FILE_PLAN_ALIAS.toString(), CATEGORY); + + // Create the record folder FilePlanComponent folder = createFolder(category.getId(), FOLDER_NAME); + // Delete the Record folder filePlanComponentAPI.deleteFilePlanComponent(folder.getId()); // Check the Response Status Code diff --git a/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/fileplancomponents/UnfiledRecordsFolderTests.java b/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/fileplancomponents/UnfiledRecordsFolderTests.java index 8c58b8ed03..f6e1481140 100644 --- a/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/fileplancomponents/UnfiledRecordsFolderTests.java +++ b/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/fileplancomponents/UnfiledRecordsFolderTests.java @@ -206,7 +206,8 @@ public class UnfiledRecordsFolderTests extends BaseRestTest assertEquals(childFolder.getName(), childFolderName); assertEquals(childFolder.getNodeType(), UNFILED_RECORD_FOLDER_TYPE.toString()); -// assertFalse(childFolder.isHasRetentionSchedule()); + // FIXME: TO DO investigate. Has Retention schedule is not returned!! + //assertFalse(childFolder.isHasRetentionSchedule()); assertEquals(childFolder.getCreatedByUser().getId(), dataUser.getAdminUser().getUsername());