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 d82e9ef861..0453a26594 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 @@ -2,495 +2,498 @@ - - - - - + + + + + - - - - - - - + + + + + + + - - - - + + + + - - - - - + + + + + - - - - + + + + - - - - + + + + - - - - + + + + - - - - - + + + + + - - - - - + + + + + - - - - + + + + - - - - + + + + - - - - + + + + - - - - + + + + - - - - + + + + - - - + + + - - - + + + - - - + + + - - - + + + - - - - + + + + - - - - - - - - - - + + + + + + + + + + - - - - - + + + + + - - - - - - + + + + + + - - - - - - - - + + + + + + + + - - - + + + - - - - - - - - + + + + + + + + - - - - + + + + - - - - + + + + - - - - - - - - + + + + + + + + - - - - - - - - + + + + + + + + - - - - - - - - + + + + + + + + - - - + + + - - - - - - + + + + + + - - - - - - - + + + + + + + - + - - - - + + + + - - - - - + + + + + - - - - + + + + - - - - - + + + + + - - - - + + + + - + - - - - + + + + - + - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + - - - - + + + + - - - - + + + + - - - - + + + + - - - - + + + + - - - - - - - - + + + + + + + + - - - - - - - - - - - - - - + + + + + + + + + + + + + + - - - - - - + + + + + + - - - - - + + + + + - - - - - + + + + + - - - - - + + + + + - - - - + + + + - - - - - - - - - - + + + + + + + + + + - - - - - - + + + + + + - - - - - + + + + + - - - - - - - - - - - - + + + + + + + + + + + \ No newline at end of file diff --git a/rm-server/config/alfresco/templates/webscripts/org/alfresco/rma/admin/emailmap.delete.desc.xml b/rm-server/config/alfresco/templates/webscripts/org/alfresco/rma/admin/emailmap.delete.desc.xml new file mode 100644 index 0000000000..40af72f2cb --- /dev/null +++ b/rm-server/config/alfresco/templates/webscripts/org/alfresco/rma/admin/emailmap.delete.desc.xml @@ -0,0 +1,15 @@ + + Delete email property map + + DELETE /api/rma/admin/emailmap/{from}/{to} deletes the specified mapping + Returns data in the same format as the get method + ]]> + + /api/rma/admin/emailmap/{from}/{to} + argument + user + required + internal + \ No newline at end of file diff --git a/rm-server/config/alfresco/templates/webscripts/org/alfresco/rma/admin/emailmap.put.json.ftl b/rm-server/config/alfresco/templates/webscripts/org/alfresco/rma/admin/emailmap.delete.json.ftl similarity index 59% rename from rm-server/config/alfresco/templates/webscripts/org/alfresco/rma/admin/emailmap.put.json.ftl rename to rm-server/config/alfresco/templates/webscripts/org/alfresco/rma/admin/emailmap.delete.json.ftl index 99d37fbb76..d798509bc0 100644 --- a/rm-server/config/alfresco/templates/webscripts/org/alfresco/rma/admin/emailmap.put.json.ftl +++ b/rm-server/config/alfresco/templates/webscripts/org/alfresco/rma/admin/emailmap.delete.json.ftl @@ -2,7 +2,6 @@ <#escape x as jsonUtils.encodeJSONString(x)> { - "data": - <@emailmapLib.emailmapJSON emailmap=emailmap /> + "data": <@emailmapLib.emailmapJSON emailmap=emailmap /> } \ No newline at end of file diff --git a/rm-server/config/alfresco/templates/webscripts/org/alfresco/rma/admin/emailmap.get.json.ftl b/rm-server/config/alfresco/templates/webscripts/org/alfresco/rma/admin/emailmap.get.json.ftl index f38906ee62..d798509bc0 100644 --- a/rm-server/config/alfresco/templates/webscripts/org/alfresco/rma/admin/emailmap.get.json.ftl +++ b/rm-server/config/alfresco/templates/webscripts/org/alfresco/rma/admin/emailmap.get.json.ftl @@ -2,7 +2,6 @@ <#escape x as jsonUtils.encodeJSONString(x)> { - "data": - <@emailmapLib.emailmapJSON emailmap=emailmap /> + "data": <@emailmapLib.emailmapJSON emailmap=emailmap /> } \ No newline at end of file diff --git a/rm-server/config/alfresco/templates/webscripts/org/alfresco/rma/admin/emailmap.lib.ftl b/rm-server/config/alfresco/templates/webscripts/org/alfresco/rma/admin/emailmap.lib.ftl index d4a297276e..e857188b9c 100644 --- a/rm-server/config/alfresco/templates/webscripts/org/alfresco/rma/admin/emailmap.lib.ftl +++ b/rm-server/config/alfresco/templates/webscripts/org/alfresco/rma/admin/emailmap.lib.ftl @@ -2,13 +2,13 @@ <#macro emailmapJSON emailmap> <#escape x as jsonUtils.encodeJSONString(x)> - { - "mappings": - [ - <#list emailmap as mapping> - {"from": "${mapping.from}", "to": "${mapping.to}" }<#if mapping_has_next>, - - ] - } + { + "mappings": + [ + <#list emailmap as mapping> + {"from": "${mapping.from}", "to": "${mapping.to}" }<#if mapping_has_next>, + + ] + } \ No newline at end of file diff --git a/rm-server/config/alfresco/templates/webscripts/org/alfresco/rma/admin/emailmap.post.json.ftl b/rm-server/config/alfresco/templates/webscripts/org/alfresco/rma/admin/emailmap.post.json.ftl index 68bf020fe0..559ac91406 100644 --- a/rm-server/config/alfresco/templates/webscripts/org/alfresco/rma/admin/emailmap.post.json.ftl +++ b/rm-server/config/alfresco/templates/webscripts/org/alfresco/rma/admin/emailmap.post.json.ftl @@ -2,6 +2,11 @@ <#escape x as jsonUtils.encodeJSONString(x)> { - "data": <@emailmapLib.emailmapJSON emailmap=emailmap /> + "success": ${success?string}, + <#if success> + "data": <@emailmapLib.emailmapJSON emailmap=emailmap /> + <#else> + "message": "${message}" + } \ No newline at end of file diff --git a/rm-server/config/alfresco/templates/webscripts/org/alfresco/rma/admin/emailmap.put.desc.xml b/rm-server/config/alfresco/templates/webscripts/org/alfresco/rma/admin/emailmap.put.desc.xml deleted file mode 100644 index eec6580c60..0000000000 --- a/rm-server/config/alfresco/templates/webscripts/org/alfresco/rma/admin/emailmap.put.desc.xml +++ /dev/null @@ -1,40 +0,0 @@ - - Update email property map - - Data is specified in JSON format as a JSONObject with two optional fields, "add" and "delete". -
- The contents of the add array are added. -
- The contents of the delete array are deleted. -
- Add mapping: -
-   {
-      "add":
-      [
-         {"to":"rmc:Wibble", "from":"whatever"},
-         {"to":"rmc:wobble", "from":"whatever"}
-      ]
-   }
-  
- Delete mapping: -
-   {
-      "delete":
-      [
-         {"to":"rmc:Wibble", "from":"whatever"},
-         {"to":"rmc:wobble", "from":"whatever"}
-      ]
-   }
-  
- Returns data in the same format as the get method - ]]> -
- /api/rma/admin/emailmap - argument - user - required - internal -
\ No newline at end of file diff --git a/rm-server/config/alfresco/templates/webscripts/org/alfresco/slingshot/rmsearch/rmsearchproperties.get.json.ftl b/rm-server/config/alfresco/templates/webscripts/org/alfresco/slingshot/rmsearch/rmsearchproperties.get.json.ftl index e5fe1b268d..0341c3843b 100644 --- a/rm-server/config/alfresco/templates/webscripts/org/alfresco/slingshot/rmsearch/rmsearchproperties.get.json.ftl +++ b/rm-server/config/alfresco/templates/webscripts/org/alfresco/slingshot/rmsearch/rmsearchproperties.get.json.ftl @@ -1,27 +1,27 @@ <#escape x as jsonUtils.encodeJSONString(x)> { - "data" : - { - "groups" : - [ - <#list groups as group> - { - "id" : "${group.id}", - "label" : "${group.label}", - "properties" : - [ - <#list group.properties as property> - { - "prefix" : "${property.prefix}", - "name" : "${property.shortName}", - "label" : "${property.label}", - "type" : "${property.type}" - }<#if property_has_next>, - - ] - }<#if group_has_next>, - - ] - } + "data" : + { + "groups" : + [ + <#list groups as group> + { + "id" : "${group.id}", + "label" : "${group.label}", + "properties" : + [ + <#list group.properties as property> + { + "prefix" : "${property.prefix}", + "name" : "${property.shortName}", + "label" : "${property.label}", + "type" : "${property.type}" + }<#if property_has_next>, + + ] + }<#if group_has_next>, + + ] + } } \ No newline at end of file diff --git a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/script/EmailMapPut.java b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/script/EmailMapDelete.java similarity index 53% rename from rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/script/EmailMapPut.java rename to rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/script/EmailMapDelete.java index f49a8bfa9b..c51778d372 100644 --- a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/script/EmailMapPut.java +++ b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/script/EmailMapDelete.java @@ -18,17 +18,12 @@ */ package org.alfresco.module.org_alfresco_module_rm.script; -import java.io.IOException; import java.util.HashMap; import java.util.Map; -import java.util.Set; import org.alfresco.module.org_alfresco_module_rm.email.CustomEmailMappingService; -import org.alfresco.module.org_alfresco_module_rm.email.CustomMapping; -import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; -import org.json.JSONTokener; import org.springframework.extensions.webscripts.Cache; import org.springframework.extensions.webscripts.DeclarativeWebScript; import org.springframework.extensions.webscripts.Status; @@ -39,70 +34,45 @@ import org.springframework.extensions.webscripts.WebScriptRequest; * Implementation for Java backed webscript to return * custom email field mappings */ -public class EmailMapPut extends DeclarativeWebScript -{ - /* - * @see org.alfresco.web.scripts.DeclarativeWebScript#executeImpl(org.alfresco.web.scripts.WebScriptRequest, org.alfresco.web.scripts.Status, org.alfresco.web.scripts.Cache) - */ - @Override - protected Map executeImpl(WebScriptRequest req, Status status, Cache cache) - { - - try - { - JSONObject json = null; - json = new JSONObject(new JSONTokener(req.getContent().getContent())); - - if(json.has("add")) - { - JSONArray toAdd = json.getJSONArray("add"); - for(int i = 0 ; i < toAdd.length(); i++) - { - JSONObject val = toAdd.getJSONObject(i); - customEmailMappingService.addCustomMapping(val.getString("from"), val.getString("to")); - - } - } - - if(json.has("delete")) - { - JSONArray toDelete = json.getJSONArray("delete"); - for(int i = 0 ; i < toDelete.length(); i++) - { - JSONObject val = toDelete.getJSONObject(i); - customEmailMappingService.deleteCustomMapping(val.getString("from"), val.getString("to")); - } - } - - - // Set the return value. - Set emailMap = customEmailMappingService.getCustomMappings(); - // create model object with the lists model - Map model = new HashMap(1); - model.put("emailmap", emailMap); - return model; - } - catch (IOException iox) - { - throw new WebScriptException(Status.STATUS_BAD_REQUEST, - "Could not read content from req.", iox); - } - catch (JSONException je) - { - throw new WebScriptException(Status.STATUS_BAD_REQUEST, - "Could not parse JSON from req.", je); - } - } - +public class EmailMapDelete extends DeclarativeWebScript +{ + /** Custom email mapping service */ private CustomEmailMappingService customEmailMappingService; + /** + * Custom email mapping service + * + * @param customEmailMappingService the custom email mapping service + */ public void setCustomEmailMappingService(CustomEmailMappingService customEmailMappingService) { this.customEmailMappingService = customEmailMappingService; } - public CustomEmailMappingService getCustomEmailMappingService() + /** + * @see org.alfresco.web.scripts.DeclarativeWebScript#executeImpl(org.alfresco.web.scripts.WebScriptRequest, org.alfresco.web.scripts.Status, org.alfresco.web.scripts.Cache) + */ + @Override + protected Map executeImpl(WebScriptRequest req, Status status, Cache cache) { - return customEmailMappingService; + try + { + // Get the data from the request + JSONObject json = new JSONObject(req.getServiceMatch().getTemplateVars()); + + // Delete custom mapping + customEmailMappingService.deleteCustomMapping(json.getString("from"), json.getString("to")); + + // Create model object with the lists of custom mappings + Map model = new HashMap(1); + model.put("emailmap", customEmailMappingService.getCustomMappings()); + + return model; + } + catch (JSONException je) + { + throw new WebScriptException(Status.STATUS_BAD_REQUEST, + "Could not parse JSON from req.", je); + } } } \ No newline at end of file diff --git a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/script/EmailMapGet.java b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/script/EmailMapGet.java index 7f225e5cac..257dc4e4dc 100644 --- a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/script/EmailMapGet.java +++ b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/script/EmailMapGet.java @@ -20,48 +20,41 @@ package org.alfresco.module.org_alfresco_module_rm.script; import java.util.HashMap; import java.util.Map; -import java.util.Set; import org.alfresco.module.org_alfresco_module_rm.email.CustomEmailMappingService; -import org.alfresco.module.org_alfresco_module_rm.email.CustomMapping; import org.springframework.extensions.webscripts.Cache; import org.springframework.extensions.webscripts.DeclarativeWebScript; import org.springframework.extensions.webscripts.Status; import org.springframework.extensions.webscripts.WebScriptRequest; /** - * Implementation for Java backed webscript to return + * Implementation for Java backed webscript to return * custom email field mappings */ public class EmailMapGet extends DeclarativeWebScript -{ - - /* - * @see org.alfresco.web.scripts.DeclarativeWebScript#executeImpl(org.alfresco.web.scripts.WebScriptRequest, org.alfresco.web.scripts.Status, org.alfresco.web.scripts.Cache) - */ - @Override - protected Map executeImpl(WebScriptRequest req, Status status, Cache cache) - { - // String requestUrl = req.getURL(); - - Set emailMap = customEmailMappingService.getCustomMappings(); - - // create model object with the lists model - Map model = new HashMap(1); - model.put("emailmap", emailMap); - return model; - } - +{ + /** Custom email mapping service */ private CustomEmailMappingService customEmailMappingService; + /** + * Custom email mapping service + * + * @param customEmailMappingService the custom email mapping service + */ public void setCustomEmailMappingService(CustomEmailMappingService customEmailMappingService) { this.customEmailMappingService = customEmailMappingService; } - public CustomEmailMappingService getCustomEmailMappingService() + /** + * @see org.alfresco.web.scripts.DeclarativeWebScript#executeImpl(org.alfresco.web.scripts.WebScriptRequest, org.alfresco.web.scripts.Status, org.alfresco.web.scripts.Cache) + */ + @Override + protected Map executeImpl(WebScriptRequest req, Status status, Cache cache) { - return customEmailMappingService; + // Create model object with the lists of custom mappings + Map model = new HashMap(1); + model.put("emailmap", customEmailMappingService.getCustomMappings()); + return model; } - } \ No newline at end of file diff --git a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/script/EmailMapPost.java b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/script/EmailMapPost.java index 369f069218..4461c0b57c 100644 --- a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/script/EmailMapPost.java +++ b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/script/EmailMapPost.java @@ -21,11 +21,9 @@ package org.alfresco.module.org_alfresco_module_rm.script; import java.io.IOException; import java.util.HashMap; import java.util.Map; -import java.util.Set; +import org.alfresco.error.AlfrescoRuntimeException; import org.alfresco.module.org_alfresco_module_rm.email.CustomEmailMappingService; -import org.alfresco.module.org_alfresco_module_rm.email.CustomMapping; -import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; import org.json.JSONTokener; @@ -40,46 +38,38 @@ import org.springframework.extensions.webscripts.WebScriptRequest; * custom email field mappings */ public class EmailMapPost extends DeclarativeWebScript -{ - /* +{ + /** Custom email mapping service */ + private CustomEmailMappingService customEmailMappingService; + + /** + * Custom email mapping service + * + * @param customEmailMappingService the custom email mapping service + */ + public void setCustomEmailMappingService(CustomEmailMappingService customEmailMappingService) + { + this.customEmailMappingService = customEmailMappingService; + } + + /** * @see org.alfresco.web.scripts.DeclarativeWebScript#executeImpl(org.alfresco.web.scripts.WebScriptRequest, org.alfresco.web.scripts.Status, org.alfresco.web.scripts.Cache) */ @Override protected Map executeImpl(WebScriptRequest req, Status status, Cache cache) { - + Map model = new HashMap(1); try { - JSONObject json = null; - json = new JSONObject(new JSONTokener(req.getContent().getContent())); - - if(json.has("delete")) - { - JSONArray toDelete = json.getJSONArray("delete"); - for(int i = 0 ; i < toDelete.length(); i++) - { - JSONObject val = toDelete.getJSONObject(i); - customEmailMappingService.deleteCustomMapping(val.getString("from"), val.getString("to")); - } - } - - if(json.has("add")) - { - JSONArray toAdd = json.getJSONArray("add"); - for(int i = 0 ; i < toAdd.length(); i++) - { - JSONObject val = toAdd.getJSONObject(i); - customEmailMappingService.addCustomMapping(val.getString("from"), val.getString("to")); - - } - } - - // Set the return value. - Set emailMap = customEmailMappingService.getCustomMappings(); - // create model object with the lists model - Map model = new HashMap(1); - model.put("emailmap", emailMap); - return model; + // Get the data from the content + JSONObject json = new JSONObject(new JSONTokener(req.getContent().getContent())); + + // Add custom mapping + customEmailMappingService.addCustomMapping(json.getString("from"), json.getString("to")); + + // Add the lists of custom mappings to the model + model.put("emailmap", customEmailMappingService.getCustomMappings()); + model.put("success", true); } catch (IOException iox) { @@ -89,21 +79,14 @@ public class EmailMapPost extends DeclarativeWebScript catch (JSONException je) { throw new WebScriptException(Status.STATUS_BAD_REQUEST, - "Could not parse JSON from req.", je); + "Could not parse JSON from req.", je); + } + catch (AlfrescoRuntimeException are) + { + model.put("message", are.getMessage()); + model.put("success", false); } - } - - private CustomEmailMappingService customEmailMappingService; - public void setCustomEmailMappingService(CustomEmailMappingService customEmailMappingService) - { - this.customEmailMappingService = customEmailMappingService; + return model; } - - public CustomEmailMappingService getCustomEmailMappingService() - { - return customEmailMappingService; - } - - } \ No newline at end of file