use of org.springframework.extensions.webscripts.WebScriptException in project records-management by Alfresco.
the class DispositionActionDefinitionPost method createActionDefinition.
/**
* Creates a dispositionActionDefinition node in the repo.
*
* @param json The JSON to use to create the action definition
* @param schedule The DispositionSchedule the action is for
* @return The DispositionActionDefinition representing the new action definition
*/
protected DispositionActionDefinition createActionDefinition(JSONObject json, DispositionSchedule schedule) throws JSONException {
// extract the data from the JSON request
if (!json.has("name")) {
throw new WebScriptException(Status.STATUS_BAD_REQUEST, "Mandatory 'name' parameter was not provided in request body");
}
// create the properties for the action definition
Map<QName, Serializable> props = new HashMap<QName, Serializable>(8);
String name = json.getString("name");
props.put(RecordsManagementModel.PROP_DISPOSITION_ACTION_NAME, name);
if (json.has("description")) {
props.put(RecordsManagementModel.PROP_DISPOSITION_DESCRIPTION, json.getString("description"));
}
if (json.has("period")) {
props.put(RecordsManagementModel.PROP_DISPOSITION_PERIOD, json.getString("period"));
}
if (json.has("periodProperty")) {
QName periodProperty = QName.createQName(json.getString("periodProperty"), getNamespaceService());
props.put(RecordsManagementModel.PROP_DISPOSITION_PERIOD_PROPERTY, periodProperty);
}
if (json.has("eligibleOnFirstCompleteEvent")) {
props.put(RecordsManagementModel.PROP_DISPOSITION_EVENT_COMBINATION, json.getBoolean("eligibleOnFirstCompleteEvent") ? "or" : "and");
}
if (json.has("location")) {
props.put(RecordsManagementModel.PROP_DISPOSITION_LOCATION, json.getString("location"));
}
if (json.has("events")) {
JSONArray events = json.getJSONArray("events");
List<String> eventsList = new ArrayList<String>(events.length());
for (int x = 0; x < events.length(); x++) {
eventsList.add(events.getString(x));
}
props.put(RecordsManagementModel.PROP_DISPOSITION_EVENT, (Serializable) eventsList);
}
if (json.has("name") && "destroy".equals(json.getString("name"))) {
if (json.has("ghostOnDestroy")) {
props.put(RecordsManagementModel.PROP_DISPOSITION_ACTION_GHOST_ON_DESTROY, "ghost");
} else {
props.put(RecordsManagementModel.PROP_DISPOSITION_ACTION_GHOST_ON_DESTROY, "delete");
}
}
// add the action definition to the schedule
return getDispositionService().addDispositionActionDefinition(schedule, props);
}
use of org.springframework.extensions.webscripts.WebScriptException in project records-management by Alfresco.
the class DispositionActionDefinitionPost method executeImpl.
/*
* @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) {
// parse the request to retrieve the schedule object
DispositionSchedule schedule = parseRequestForSchedule(req);
// retrieve the rest of the post body and create the action
// definition
JSONObject json = null;
DispositionActionDefinition actionDef = null;
try {
json = new JSONObject(new JSONTokener(req.getContent().getContent()));
actionDef = createActionDefinition(json, schedule);
} 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);
}
// create model object with just the action data
Map<String, Object> model = new HashMap<String, Object>(1);
model.put("action", createActionDefModel(actionDef, req.getURL() + "/" + actionDef.getId()));
return model;
}
use of org.springframework.extensions.webscripts.WebScriptException in project records-management by Alfresco.
the class EmailMapDelete method executeImpl.
/**
* @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 {
// 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);
}
}
use of org.springframework.extensions.webscripts.WebScriptException in project records-management by Alfresco.
the class RmRolePut method executeImpl.
@Override
public Map<String, Object> executeImpl(WebScriptRequest req, Status status, Cache cache) {
Map<String, Object> model = new HashMap<String, Object>();
JSONObject json = null;
try {
// Role name
Map<String, String> templateVars = req.getServiceMatch().getTemplateVars();
String roleParam = templateVars.get("rolename");
if (roleParam == null) {
throw new WebScriptException(Status.STATUS_NOT_FOUND, "No role name was provided on the URL.");
}
json = new JSONObject(new JSONTokener(req.getContent().getContent()));
String name = json.getString("name");
// TODO check
String displayLabel = json.getString("displayLabel");
// TODO check
JSONArray capabilitiesArray = json.getJSONArray("capabilities");
Set<Capability> capabilites = new HashSet<Capability>(capabilitiesArray.length());
for (int i = 0; i < capabilitiesArray.length(); i++) {
Capability capability = capabilityService.getCapability(capabilitiesArray.getString(i));
capabilites.add(capability);
}
// get the file plan
NodeRef filePlan = getFilePlan(req);
if (filePlan == null) {
throw new WebScriptException(Status.STATUS_NOT_FOUND, "File plan does not exist.");
}
// Check that the role exists
if (!filePlanRoleService.existsRole(filePlan, roleParam)) {
throw new WebScriptException(Status.STATUS_NOT_FOUND, "The role " + roleParam + " does not exist on the records managment root " + filePlan);
}
Role role = filePlanRoleService.updateRole(filePlan, name, displayLabel, capabilites);
model.put("role", new RoleItem(role));
} 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);
}
return model;
}
use of org.springframework.extensions.webscripts.WebScriptException in project records-management by Alfresco.
the class RmRolesPost method executeImpl.
@Override
public Map<String, Object> executeImpl(WebScriptRequest req, Status status, Cache cache) {
Map<String, Object> model = new HashMap<String, Object>();
JSONObject json = null;
try {
json = new JSONObject(new JSONTokener(req.getContent().getContent()));
String name = json.getString("name");
// TODO check
String displayString = json.getString("displayLabel");
// TODO check
JSONArray capabilitiesArray = json.getJSONArray("capabilities");
Set<Capability> capabilites = new HashSet<Capability>(capabilitiesArray.length());
for (int i = 0; i < capabilitiesArray.length(); i++) {
Capability capability = capabilityService.getCapability(capabilitiesArray.getString(i));
capabilites.add(capability);
}
// get the file plan
NodeRef filePlan = getFilePlan(req);
if (filePlan == null) {
throw new WebScriptException(Status.STATUS_NOT_FOUND, "File plan does not exist.");
}
Role role = filePlanRoleService.createRole(filePlan, name, displayString, capabilites);
model.put("role", new RoleItem(role));
} 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);
}
return model;
}
Aggregations