From 992a3be30ec719237568e90b4b2c9c54950221f1 Mon Sep 17 00:00:00 2001 From: Tuna Aksoy Date: Thu, 23 Jul 2015 21:15:31 +0000 Subject: [PATCH] RM-2421 (Add PUT method to classify content REST API) +review RM git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/modules/recordsmanagement/HEAD@108911 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261 --- .../rm-webscript-context.xml | 14 +- .../classifycontent.put.desc.xml | 27 ++++ .../classifycontent.put.json.ftl | 5 + .../classification/ClassifyContentBase.java | 131 ++++++++++++++++++ .../classification/ClassifyContentPost.java | 77 +--------- .../classification/ClassifyContentPut.java | 41 ++++++ 6 files changed, 219 insertions(+), 76 deletions(-) create mode 100644 rm-server/config/alfresco/templates/webscripts/org/alfresco/rma/classification/classifycontent.put.desc.xml create mode 100644 rm-server/config/alfresco/templates/webscripts/org/alfresco/rma/classification/classifycontent.put.json.ftl create mode 100644 rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/script/classification/ClassifyContentBase.java create mode 100644 rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/script/classification/ClassifyContentPut.java diff --git a/rm-server/config/alfresco/module/org_alfresco_module_rm/rm-webscript-context.xml b/rm-server/config/alfresco/module/org_alfresco_module_rm/rm-webscript-context.xml index e23278fd75..002c78487e 100644 --- a/rm-server/config/alfresco/module/org_alfresco_module_rm/rm-webscript-context.xml +++ b/rm-server/config/alfresco/module/org_alfresco_module_rm/rm-webscript-context.xml @@ -670,12 +670,20 @@ + + + + + - - + parent="rmClassifyContentBase"/> + + + + Edits a classified content + +
+ The body of the pust should be in the form, e.g.
+ {
+ "classificationLevelId": "aLevelId",
+ "classifiedBy": "some person or entity",
+ "classificationAgency": "anAgency",
+ "classificationReasons": [
+ {
+ "id": "reason1Id"
+ },
+ {
+ "id": "reason2Id"
+ }
+ ]
+ }
+ ]]> +
+ /api/node/{store_type}/{store_id}/{id}/classify + argument + user + required + internal + \ No newline at end of file diff --git a/rm-server/config/alfresco/templates/webscripts/org/alfresco/rma/classification/classifycontent.put.json.ftl b/rm-server/config/alfresco/templates/webscripts/org/alfresco/rma/classification/classifycontent.put.json.ftl new file mode 100644 index 0000000000..beda2de343 --- /dev/null +++ b/rm-server/config/alfresco/templates/webscripts/org/alfresco/rma/classification/classifycontent.put.json.ftl @@ -0,0 +1,5 @@ +<#escape x as jsonUtils.encodeJSONString(x)> +{ + "success": ${success?string} +} + \ No newline at end of file diff --git a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/script/classification/ClassifyContentBase.java b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/script/classification/ClassifyContentBase.java new file mode 100644 index 0000000000..45a40a3953 --- /dev/null +++ b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/script/classification/ClassifyContentBase.java @@ -0,0 +1,131 @@ +/* + * Copyright (C) 2005-2015 Alfresco Software Limited. + * + * This file is part of Alfresco + * + * 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 . + */ +package org.alfresco.module.org_alfresco_module_rm.script.classification; + +import static org.alfresco.util.WebScriptUtils.getJSONArrayFromJSONObject; +import static org.alfresco.util.WebScriptUtils.getJSONArrayValue; +import static org.alfresco.util.WebScriptUtils.getRequestContentAsJsonObject; +import static org.alfresco.util.WebScriptUtils.getStringValueFromJSONObject; + +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; + +import org.alfresco.module.org_alfresco_module_rm.classification.ContentClassificationService; +import org.alfresco.module.org_alfresco_module_rm.script.AbstractRmWebScript; +import org.alfresco.service.cmr.repository.NodeRef; +import org.json.JSONArray; +import org.json.JSONObject; +import org.springframework.extensions.webscripts.Cache; +import org.springframework.extensions.webscripts.Status; +import org.springframework.extensions.webscripts.WebScriptRequest; + +/** + * Base class for classify content actions + * + * @author Tuna Aksoy + * @since 3.0 + */ +public abstract class ClassifyContentBase extends AbstractRmWebScript +{ + /** Constants */ + public static final String CLASSIFICATION_LEVEL_ID = "classificationLevelId"; + public static final String CLASSIFIED_BY = "classifiedBy"; + public static final String CLASSIFICATION_AGENCY = "classificationAgency"; + public static final String CLASSIFICATION_REASONS = "classificationReasons"; + + /** The service responsible for classifying content. */ + private ContentClassificationService contentClassificationService; + + /** + * Get the service responsible for classifying content. + * + * @return the contentClassificationService + */ + protected ContentClassificationService getContentClassificationService() + { + return this.contentClassificationService; + } + + /** + * Set the service responsible for classifying content. + * + * @param contentClassificationService The service responsible for classifying content. + */ + public void setContentClassificationService(ContentClassificationService contentClassificationService) + { + this.contentClassificationService = contentClassificationService; + } + + /** + * Abstract method which does the action of either + * classifying a content or editing a classified content + * + * @param classificationLevelId The security clearance needed to access the content. + * @param classifiedBy Free-form text identifying who edited the classified content. + * @param classificationAgency The name of the agency responsible for editing the classified content. + * @param classificationReasonIds A non-empty set of ids of reasons for editing the classified content in this way. + * @param document The classified content which will be edited. + */ + protected abstract void doClassifyAction(String classificationLevelId, String classifiedBy, String classificationAgency, Set classificationReasonIds, NodeRef document); + + /** + * @see org.springframework.extensions.webscripts.DeclarativeWebScript#executeImpl(org.springframework.extensions.webscripts.WebScriptRequest, + * org.springframework.extensions.webscripts.Status, + * org.springframework.extensions.webscripts.Cache) + */ + @Override + protected Map executeImpl(WebScriptRequest req, Status status, Cache cache) + { + JSONObject jsonObject = getRequestContentAsJsonObject(req); + String classificationLevelId = getStringValueFromJSONObject(jsonObject, CLASSIFICATION_LEVEL_ID); + String classifiedBy = getStringValueFromJSONObject(jsonObject, CLASSIFIED_BY); + String classificationAgency = getStringValueFromJSONObject(jsonObject, CLASSIFICATION_AGENCY, false, false); + Set classificationReasonIds = getClassificationReasonIds(jsonObject); + NodeRef document = parseRequestForNodeRef(req); + + doClassifyAction(classificationLevelId, classifiedBy, classificationAgency, classificationReasonIds, document); + + Map model = new HashMap<>(1); + model.put(SUCCESS, true); + + return model; + } + + /** + * Helper method to get the classification reason ids + * + * @param jsonObject The json object representing the request body + * @return {@link Set}<{@link String}> classification ids + */ + private Set getClassificationReasonIds(JSONObject jsonObject) + { + Set classificationReasonIds = new HashSet<>(); + + JSONArray classificationReasons = getJSONArrayFromJSONObject(jsonObject, CLASSIFICATION_REASONS); + for (int i = 0; i < classificationReasons.length(); i++) + { + JSONObject classificationReason = (JSONObject) getJSONArrayValue(classificationReasons, i); + classificationReasonIds.add(getStringValueFromJSONObject(classificationReason, ID)); + } + + return classificationReasonIds; + } +} diff --git a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/script/classification/ClassifyContentPost.java b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/script/classification/ClassifyContentPost.java index 284be8e853..fc2de3ee19 100644 --- a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/script/classification/ClassifyContentPost.java +++ b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/script/classification/ClassifyContentPost.java @@ -18,24 +18,9 @@ */ package org.alfresco.module.org_alfresco_module_rm.script.classification; -import static org.alfresco.util.WebScriptUtils.getJSONArrayFromJSONObject; -import static org.alfresco.util.WebScriptUtils.getJSONArrayValue; -import static org.alfresco.util.WebScriptUtils.getRequestContentAsJsonObject; -import static org.alfresco.util.WebScriptUtils.getStringValueFromJSONObject; - -import java.util.HashMap; -import java.util.HashSet; -import java.util.Map; import java.util.Set; -import org.alfresco.module.org_alfresco_module_rm.classification.ContentClassificationService; -import org.alfresco.module.org_alfresco_module_rm.script.AbstractRmWebScript; import org.alfresco.service.cmr.repository.NodeRef; -import org.json.JSONArray; -import org.json.JSONObject; -import org.springframework.extensions.webscripts.Cache; -import org.springframework.extensions.webscripts.Status; -import org.springframework.extensions.webscripts.WebScriptRequest; /** * Implementation for Java backed webscript to classify a content. @@ -43,68 +28,14 @@ import org.springframework.extensions.webscripts.WebScriptRequest; * @author Tuna Aksoy * @since 3.0 */ -public class ClassifyContentPost extends AbstractRmWebScript +public class ClassifyContentPost extends ClassifyContentBase { - /** Constants */ - public static final String CLASSIFICATION_LEVEL_ID = "classificationLevelId"; - public static final String CLASSIFIED_BY = "classifiedBy"; - public static final String CLASSIFICATION_AGENCY = "classificationAgency"; - public static final String CLASSIFICATION_REASONS = "classificationReasons"; - - /** The service responsible for classifying content. */ - private ContentClassificationService contentClassificationService; - /** - * Set the service responsible for classifying content. - * - * @param contentClassificationService The service responsible for classifying content. - */ - public void setContentClassificationService(ContentClassificationService contentClassificationService) - { - this.contentClassificationService = contentClassificationService; - } - - /** - * @see org.springframework.extensions.webscripts.DeclarativeWebScript#executeImpl(org.springframework.extensions.webscripts.WebScriptRequest, - * org.springframework.extensions.webscripts.Status, - * org.springframework.extensions.webscripts.Cache) + * @see org.alfresco.module.org_alfresco_module_rm.script.classification.ClassifyContentBase#doClassifyAction(java.lang.String, java.lang.String, java.lang.String, java.util.Set, org.alfresco.service.cmr.repository.NodeRef) */ @Override - protected Map executeImpl(WebScriptRequest req, Status status, Cache cache) + protected void doClassifyAction(String classificationLevelId, String classifiedBy, String classificationAgency, Set classificationReasonIds, NodeRef document) { - JSONObject jsonObject = getRequestContentAsJsonObject(req); - String classificationLevelId = getStringValueFromJSONObject(jsonObject, CLASSIFICATION_LEVEL_ID); - String classifiedBy = getStringValueFromJSONObject(jsonObject, CLASSIFIED_BY); - String classificationAgency = getStringValueFromJSONObject(jsonObject, CLASSIFICATION_AGENCY, false, false); - Set classificationReasonIds = getClassificationReasonIds(jsonObject); - NodeRef document = parseRequestForNodeRef(req); - - contentClassificationService.classifyContent(classificationLevelId, classifiedBy, classificationAgency, - classificationReasonIds, document); - - Map model = new HashMap<>(1); - model.put(SUCCESS, true); - - return model; - } - - /** - * Helper method to get the classification reason ids - * - * @param jsonObject The json object representing the request body - * @return {@link Set}<{@link String}> classification ids - */ - private Set getClassificationReasonIds(JSONObject jsonObject) - { - Set classificationReasonIds = new HashSet<>(); - - JSONArray classificationReasons = getJSONArrayFromJSONObject(jsonObject, CLASSIFICATION_REASONS); - for (int i = 0; i < classificationReasons.length(); i++) - { - JSONObject classificationReason = (JSONObject) getJSONArrayValue(classificationReasons, i); - classificationReasonIds.add(getStringValueFromJSONObject(classificationReason, ID)); - } - - return classificationReasonIds; + getContentClassificationService().classifyContent(classificationLevelId, classifiedBy, classificationAgency, classificationReasonIds, document); } } \ No newline at end of file diff --git a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/script/classification/ClassifyContentPut.java b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/script/classification/ClassifyContentPut.java new file mode 100644 index 0000000000..66939cd23e --- /dev/null +++ b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/script/classification/ClassifyContentPut.java @@ -0,0 +1,41 @@ +/* + * Copyright (C) 2005-2014 Alfresco Software Limited. + * + * This file is part of Alfresco + * + * 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 . + */ +package org.alfresco.module.org_alfresco_module_rm.script.classification; + +import java.util.Set; + +import org.alfresco.service.cmr.repository.NodeRef; + +/** + * Implementation for Java backed webscript to edit a classified content. + * + * @author Tuna Aksoy + * @since 3.0 + */ +public class ClassifyContentPut extends ClassifyContentBase +{ + /** + * @see org.alfresco.module.org_alfresco_module_rm.script.classification.ClassifyContentBase#doClassifyAction(java.lang.String, java.lang.String, java.lang.String, java.util.Set, org.alfresco.service.cmr.repository.NodeRef) + */ + @Override + protected void doClassifyAction(String classificationLevelId, String classifiedBy, String classificationAgency, Set classificationReasonIds, NodeRef document) + { + getContentClassificationService().editClassifiedContent(classificationLevelId, classifiedBy, classificationAgency, classificationReasonIds, document); + } +} \ No newline at end of file