Search in sources :

Example 86 with WebScriptException

use of org.springframework.extensions.webscripts.WebScriptException in project records-management by Alfresco.

the class CustomPropertyDefinitionDelete method getPropertyFromReq.

private QName getPropertyFromReq(WebScriptRequest req) {
    Map<String, String> templateVars = req.getServiceMatch().getTemplateVars();
    String propIdString = templateVars.get(PROP_ID);
    QName propQName = this.rmAdminService.getQNameForClientId(propIdString);
    Map<QName, PropertyDefinition> existingPropDefs = rmAdminService.getCustomPropertyDefinitions();
    if (!existingPropDefs.containsKey(propQName)) {
        throw new WebScriptException(HttpServletResponse.SC_NOT_FOUND, "Requested property definition (id:" + propIdString + ") does not exist");
    }
    return propQName;
}
Also used : WebScriptException(org.springframework.extensions.webscripts.WebScriptException) QName(org.alfresco.service.namespace.QName) PropertyDefinition(org.alfresco.service.cmr.dictionary.PropertyDefinition)

Example 87 with WebScriptException

use of org.springframework.extensions.webscripts.WebScriptException in project records-management by Alfresco.

the class CustomPropertyDefinitionPut method updatePropertyDefinition.

/**
 * If label has a non-null value, it is set on the property def.
 * If constraintRef has a non-null value, it is set on this propDef.
 * If constraintRef has a null value, all constraints for that propDef are removed.
 *
 * @param params
 * @return
 * @throws CustomMetadataException
 */
protected QName updatePropertyDefinition(Map<String, Serializable> params) throws CustomMetadataException {
    QName result = null;
    boolean updated = false;
    String propId = (String) params.get(PROP_ID);
    ParameterCheck.mandatoryString("propId", propId);
    QName propQName = rmAdminService.getQNameForClientId(propId);
    if (propQName == null) {
        propQName = rmAdminService.getQNameForClientId(URLEncoder.encode(propId));
    }
    if (propQName == null) {
        throw new WebScriptException(Status.STATUS_NOT_FOUND, "Could not find property definition for: " + propId);
    }
    if (params.containsKey(PARAM_CONSTRAINT_REF)) {
        String constraintRef = (String) params.get(PARAM_CONSTRAINT_REF);
        List<ConstraintDefinition> constraints = rmAdminService.getCustomPropertyDefinitions().get(propQName).getConstraints();
        if (constraintRef == null) {
            result = rmAdminService.removeCustomPropertyDefinitionConstraints(propQName);
            updated = constraints.isEmpty() ? false : true;
        } else {
            boolean exists = false;
            for (ConstraintDefinition constraintDefinition : constraints) {
                if (constraintDefinition.getConstraint().getShortName().equalsIgnoreCase(constraintRef)) {
                    exists = true;
                    break;
                }
            }
            if (!exists) {
                QName constraintRefQName = QName.createQName(constraintRef, getNamespaceService());
                result = rmAdminService.setCustomPropertyDefinitionConstraint(propQName, constraintRefQName);
                updated = true;
            }
        }
    }
    if (params.containsKey(PARAM_LABEL)) {
        String label = (String) params.get(PARAM_LABEL);
        try {
            result = rmAdminService.updateCustomPropertyDefinitionName(propQName, label);
        } catch (PropertyAlreadyExistsMetadataException ex) {
            if (!updated) {
                String propIdAsString = rmAdminService.getQNameForClientId(label).toPrefixString(getNamespaceService());
                throw new PropertyAlreadyExistsMetadataException(propIdAsString);
            }
        }
    }
    return result;
}
Also used : PropertyAlreadyExistsMetadataException(org.alfresco.module.org_alfresco_module_rm.admin.PropertyAlreadyExistsMetadataException) WebScriptException(org.springframework.extensions.webscripts.WebScriptException) QName(org.alfresco.service.namespace.QName) ConstraintDefinition(org.alfresco.service.cmr.dictionary.ConstraintDefinition)

Example 88 with WebScriptException

use of org.springframework.extensions.webscripts.WebScriptException in project records-management by Alfresco.

the class CustomRefDelete method getTargetNode.

/**
 * Gets the target node
 *
 * @param req The webscript request
 * @return The target node
 */
private NodeRef getTargetNode(WebScriptRequest req) {
    String storeType = req.getParameter(ST);
    String storeId = req.getParameter(SI);
    String nodeId = req.getParameter(ID);
    NodeRef targetNode = new NodeRef(storeType, storeId, nodeId);
    if (!getNodeService().exists(targetNode)) {
        throw new WebScriptException(Status.STATUS_NOT_FOUND, "Unable to find the target node: '" + targetNode.toString() + "'.");
    }
    return targetNode;
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) WebScriptException(org.springframework.extensions.webscripts.WebScriptException)

Example 89 with WebScriptException

use of org.springframework.extensions.webscripts.WebScriptException in project records-management by Alfresco.

the class RmRoleGet method executeImpl.

@Override
public Map<String, Object> executeImpl(WebScriptRequest req, Status status, Cache cache) {
    Map<String, Object> model = new HashMap<String, Object>();
    // 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.");
    }
    // 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);
    }
    RoleItem item = new RoleItem(filePlanRoleService.getRole(filePlan, roleParam));
    model.put("role", item);
    return model;
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) WebScriptException(org.springframework.extensions.webscripts.WebScriptException) HashMap(java.util.HashMap)

Example 90 with WebScriptException

use of org.springframework.extensions.webscripts.WebScriptException in project records-management by Alfresco.

the class RmRolesGet method executeImpl.

/**
 * @see org.springframework.extensions.webscripts.DeclarativeWebScript#executeImpl(org.springframework.extensions.webscripts.WebScriptRequest, org.springframework.extensions.webscripts.Status, org.springframework.extensions.webscripts.Cache)
 */
@Override
public Map<String, Object> executeImpl(WebScriptRequest req, Status status, Cache cache) {
    Map<String, Object> model = new HashMap<String, Object>();
    Set<Role> roles = null;
    // get the file plan
    NodeRef filePlan = getFilePlan(req);
    if (filePlan == null) {
        throw new WebScriptException(Status.STATUS_FOUND, "File plan does not exist.");
    }
    // get the includesystem parameter
    boolean includeSystem = false;
    String includeSystemValue = req.getParameter("is");
    if (includeSystemValue != null && includeSystemValue.length() != 0) {
        includeSystem = Boolean.parseBoolean(includeSystemValue);
    }
    // get the user filter
    String user = req.getParameter("user");
    if (user != null && user.length() != 0) {
        roles = filePlanRoleService.getRolesByUser(filePlan, user, includeSystem);
    } else {
        roles = filePlanRoleService.getRoles(filePlan, includeSystem);
    }
    // get the auths parameter
    boolean showAuths = false;
    String auths = req.getParameter("auths");
    if (auths != null && auths.length() != 0) {
        showAuths = Boolean.parseBoolean(auths);
    }
    Set<RoleItem> items = createRoleItems(filePlan, roles, showAuths);
    model.put("roles", items);
    return model;
}
Also used : Role(org.alfresco.module.org_alfresco_module_rm.role.Role) NodeRef(org.alfresco.service.cmr.repository.NodeRef) WebScriptException(org.springframework.extensions.webscripts.WebScriptException) HashMap(java.util.HashMap)

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