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;
}
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;
}
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;
}
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;
}
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;
}
Aggregations