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

@@ -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<String, Object> 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<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;
}
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<String, Object> 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<String, Object> model = new HashMap<String, Object>(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);
}
}
}

View File

@@ -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<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;
@@ -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<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()));
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<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;
// 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;
}
}