Search in sources :

Example 71 with WebScriptException

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);
}
Also used : Serializable(java.io.Serializable) WebScriptException(org.springframework.extensions.webscripts.WebScriptException) HashMap(java.util.HashMap) QName(org.alfresco.service.namespace.QName) JSONArray(org.json.JSONArray) ArrayList(java.util.ArrayList)

Example 72 with WebScriptException

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;
}
Also used : JSONTokener(org.json.JSONTokener) JSONObject(org.json.JSONObject) WebScriptException(org.springframework.extensions.webscripts.WebScriptException) HashMap(java.util.HashMap) DispositionSchedule(org.alfresco.module.org_alfresco_module_rm.disposition.DispositionSchedule) JSONException(org.json.JSONException) DispositionActionDefinition(org.alfresco.module.org_alfresco_module_rm.disposition.DispositionActionDefinition) JSONObject(org.json.JSONObject) IOException(java.io.IOException)

Example 73 with WebScriptException

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);
    }
}
Also used : JSONObject(org.json.JSONObject) WebScriptException(org.springframework.extensions.webscripts.WebScriptException) HashMap(java.util.HashMap) JSONException(org.json.JSONException) JSONObject(org.json.JSONObject)

Example 74 with WebScriptException

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;
}
Also used : Capability(org.alfresco.module.org_alfresco_module_rm.capability.Capability) HashMap(java.util.HashMap) JSONArray(org.json.JSONArray) JSONException(org.json.JSONException) IOException(java.io.IOException) JSONTokener(org.json.JSONTokener) Role(org.alfresco.module.org_alfresco_module_rm.role.Role) NodeRef(org.alfresco.service.cmr.repository.NodeRef) JSONObject(org.json.JSONObject) WebScriptException(org.springframework.extensions.webscripts.WebScriptException) JSONObject(org.json.JSONObject) HashSet(java.util.HashSet)

Example 75 with WebScriptException

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;
}
Also used : Capability(org.alfresco.module.org_alfresco_module_rm.capability.Capability) HashMap(java.util.HashMap) JSONArray(org.json.JSONArray) JSONException(org.json.JSONException) IOException(java.io.IOException) JSONTokener(org.json.JSONTokener) Role(org.alfresco.module.org_alfresco_module_rm.role.Role) NodeRef(org.alfresco.service.cmr.repository.NodeRef) JSONObject(org.json.JSONObject) WebScriptException(org.springframework.extensions.webscripts.WebScriptException) JSONObject(org.json.JSONObject) HashSet(java.util.HashSet)

Aggregations

WebScriptException (org.springframework.extensions.webscripts.WebScriptException)204 HashMap (java.util.HashMap)94 NodeRef (org.alfresco.service.cmr.repository.NodeRef)67 IOException (java.io.IOException)60 JSONException (org.json.JSONException)48 JSONObject (org.json.JSONObject)44 ArrayList (java.util.ArrayList)32 QName (org.alfresco.service.namespace.QName)31 JSONTokener (org.json.JSONTokener)29 JSONObject (org.json.simple.JSONObject)25 JSONArray (org.json.JSONArray)18 Map (java.util.Map)12 AlfrescoRuntimeException (org.alfresco.error.AlfrescoRuntimeException)11 SiteInfo (org.alfresco.service.cmr.site.SiteInfo)11 StoreRef (org.alfresco.service.cmr.repository.StoreRef)10 File (java.io.File)9 Date (java.util.Date)8 JSONParser (org.json.simple.parser.JSONParser)8 Serializable (java.io.Serializable)7 InvalidNodeRefException (org.alfresco.service.cmr.repository.InvalidNodeRefException)7