RM-560 (Email mapping UI refactor)

RM-561 (Email mapping service API refactor)

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/modules/recordsmanagement/HEAD@44133 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Tuna Aksoy
2012-11-28 22:42:58 +00:00
parent 83cd918890
commit 2e873199e3
11 changed files with 568 additions and 641 deletions

View File

@@ -364,9 +364,9 @@
<property name="customEmailMappingService" ref="CustomEmailMappingService" />
</bean>
<!-- REST impl for PUT Email Map -->
<bean id="webscript.org.alfresco.rma.admin.emailmap.put"
class="org.alfresco.module.org_alfresco_module_rm.script.EmailMapPut"
<!-- REST impl for DELETE Email Map -->
<bean id="webscript.org.alfresco.rma.admin.emailmap.delete"
class="org.alfresco.module.org_alfresco_module_rm.script.EmailMapDelete"
parent="webscript">
<property name="customEmailMappingService" ref="CustomEmailMappingService" />
</bean>
@@ -482,15 +482,18 @@
</bean>
<!-- REST impl for GET Data Sets -->
<bean id="webscript.org.alfresco.rma.datasets.get" class="org.alfresco.module.org_alfresco_module_rm.script.DataSetsGet" parent="webscript">
<bean id="webscript.org.alfresco.rma.datasets.get"
class="org.alfresco.module.org_alfresco_module_rm.script.DataSetsGet"
parent="webscript">
<property name="dataSetService" ref="DataSetService" />
<property name="siteService" ref="SiteService" />
</bean>
<!-- REST impl for POST Load Data Set -->
<bean id="webscript.org.alfresco.rma.dataset.post" class="org.alfresco.module.org_alfresco_module_rm.script.DataSetPost" parent="webscript">
<bean id="webscript.org.alfresco.rma.dataset.post"
class="org.alfresco.module.org_alfresco_module_rm.script.DataSetPost"
parent="webscript">
<property name="dataSetService" ref="DataSetService" />
<property name="siteService" ref="SiteService" />
</bean>
</beans>

View File

@@ -0,0 +1,15 @@
<webscript>
<shortname>Delete email property map</shortname>
<description><![CDATA[
Delete the custom email property map
<br />
DELETE /api/rma/admin/emailmap/{from}/{to} deletes the specified mapping
Returns data in the same format as the get method
]]>
</description>
<url>/api/rma/admin/emailmap/{from}/{to}</url>
<format default="json">argument</format>
<authentication>user</authentication>
<transaction>required</transaction>
<lifecycle>internal</lifecycle>
</webscript>

View File

@@ -2,7 +2,6 @@
<#escape x as jsonUtils.encodeJSONString(x)>
{
"data":
<@emailmapLib.emailmapJSON emailmap=emailmap />
"data": <@emailmapLib.emailmapJSON emailmap=emailmap />
}
</#escape>

View File

@@ -2,7 +2,6 @@
<#escape x as jsonUtils.encodeJSONString(x)>
{
"data":
<@emailmapLib.emailmapJSON emailmap=emailmap />
"data": <@emailmapLib.emailmapJSON emailmap=emailmap />
}
</#escape>

View File

@@ -2,6 +2,11 @@
<#escape x as jsonUtils.encodeJSONString(x)>
{
"success": ${success?string},
<#if success>
"data": <@emailmapLib.emailmapJSON emailmap=emailmap />
<#else>
"message": "${message}"
</#if>
}
</#escape>

View File

@@ -1,40 +0,0 @@
<webscript>
<shortname>Update email property map</shortname>
<description><![CDATA[
Update the custom email property map
<br />
Data is specified in JSON format as a JSONObject with two optional fields, "add" and "delete".
<br />
The contents of the add array are added.
<br />
The contents of the delete array are deleted.
<br />
Add mapping:
<pre>
{
"add":
[
{"to":"rmc:Wibble", "from":"whatever"},
{"to":"rmc:wobble", "from":"whatever"}
]
}
</pre>
Delete mapping:
<pre>
{
"delete":
[
{"to":"rmc:Wibble", "from":"whatever"},
{"to":"rmc:wobble", "from":"whatever"}
]
}
</pre>
Returns data in the same format as the get method
]]>
</description>
<url>/api/rma/admin/emailmap</url>
<format default="json">argument</format>
<authentication>user</authentication>
<transaction>required</transaction>
<lifecycle>internal</lifecycle>
</webscript>

View File

@@ -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
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;
}
/**
* @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<String, Object> executeImpl(WebScriptRequest req, Status status, Cache cache)
{
try
{
JSONObject json = null;
json = new JSONObject(new JSONTokener(req.getContent().getContent()));
// Get the data from the request
JSONObject json = new JSONObject(req.getServiceMatch().getTemplateVars());
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"));
// Delete custom mapping
customEmailMappingService.deleteCustomMapping(json.getString("from"), json.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<CustomMapping> emailMap = customEmailMappingService.getCustomMappings();
// create model object with the lists model
// Create model object with the lists of custom mappings
Map<String, Object> model = new HashMap<String, Object>(1);
model.put("emailmap", emailMap);
model.put("emailmap", customEmailMappingService.getCustomMappings());
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);
}
}
private CustomEmailMappingService customEmailMappingService;
public void setCustomEmailMappingService(CustomEmailMappingService customEmailMappingService)
{
this.customEmailMappingService = customEmailMappingService;
}
public CustomEmailMappingService getCustomEmailMappingService()
{
return customEmailMappingService;
}
}

View File

@@ -20,10 +20,8 @@ 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;
@@ -35,33 +33,28 @@ import org.springframework.extensions.webscripts.WebScriptRequest;
*/
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<String, Object> executeImpl(WebScriptRequest req, Status status, Cache cache)
{
// String requestUrl = req.getURL();
Set<CustomMapping> emailMap = customEmailMappingService.getCustomMappings();
// create model object with the lists model
Map<String, Object> model = new HashMap<String, Object>(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<String, Object> executeImpl(WebScriptRequest req, Status status, Cache cache)
{
return customEmailMappingService;
// Create model object with the lists of custom mappings
Map<String, Object> model = new HashMap<String, Object>(1);
model.put("emailmap", customEmailMappingService.getCustomMappings());
return model;
}
}

View File

@@ -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;
@@ -41,45 +39,37 @@ import org.springframework.extensions.webscripts.WebScriptRequest;
*/
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<String, Object> executeImpl(WebScriptRequest req, Status status, Cache cache)
{
Map<String, Object> model = new HashMap<String, Object>(1);
try
{
JSONObject json = null;
json = new JSONObject(new JSONTokener(req.getContent().getContent()));
// Get the data from the content
JSONObject 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"));
}
}
// Add custom mapping
customEmailMappingService.addCustomMapping(json.getString("from"), json.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<CustomMapping> emailMap = customEmailMappingService.getCustomMappings();
// create model object with the lists model
Map<String, Object> model = new HashMap<String, Object>(1);
model.put("emailmap", emailMap);
return model;
// Add the lists of custom mappings to the model
model.put("emailmap", customEmailMappingService.getCustomMappings());
model.put("success", true);
}
catch (IOException iox)
{
@@ -91,19 +81,12 @@ public class EmailMapPost extends DeclarativeWebScript
throw new WebScriptException(Status.STATUS_BAD_REQUEST,
"Could not parse JSON from req.", je);
}
}
private CustomEmailMappingService customEmailMappingService;
public void setCustomEmailMappingService(CustomEmailMappingService customEmailMappingService)
catch (AlfrescoRuntimeException are)
{
this.customEmailMappingService = customEmailMappingService;
model.put("message", are.getMessage());
model.put("success", false);
}
public CustomEmailMappingService getCustomEmailMappingService()
{
return customEmailMappingService;
return model;
}
}