use of org.springframework.extensions.webscripts.WebScriptException in project records-management by Alfresco.
the class CustomRefPost method getTargetNode.
/**
* Gets the target node
*
* @param json Request content as json object
* @return The target node
*/
private NodeRef getTargetNode(JSONObject json) {
String targetNodeString = getStringValueFromJSONObject(json, TO_NODE);
NodeRef targetNode = new NodeRef(targetNodeString);
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 CustomRefsGet method getRelationshipData.
/**
* Creates relationship data for the ftl template
*
* @param relationships The relationships
* @return The relationship data
*/
private List<Map<String, String>> getRelationshipData(Set<Relationship> relationships) {
List<Map<String, String>> relationshipData = new ArrayList<Map<String, String>>();
for (Relationship relationship : relationships) {
String uniqueName = relationship.getUniqueName();
RelationshipDefinition relationshipDefinition = getRelationshipService().getRelationshipDefinition(uniqueName);
NodeRef source = relationship.getSource();
NodeRef target = relationship.getTarget();
if (relationshipDefinition != null && hasView(source) && hasView(target)) {
Map<String, String> data = new HashMap<String, String>();
RelationshipType type = relationshipDefinition.getType();
RelationshipDisplayName displayName = relationshipDefinition.getDisplayName();
if (RelationshipType.BIDIRECTIONAL.equals(type)) {
data.put(LABEL, displayName.getSourceText());
data.put(SOURCE_REF, source.toString());
data.put(TARGET_REF, target.toString());
} else if (RelationshipType.PARENTCHILD.equals(type)) {
data.put(SOURCE, displayName.getSourceText());
data.put(TARGET, displayName.getTargetText());
data.put(PARENT_REF, source.toString());
data.put(CHILD_REF, target.toString());
} else {
StringBuilder sb = new StringBuilder();
sb.append("Unsupported relationship type '").append(type).append("'.");
throw new WebScriptException(Status.STATUS_BAD_REQUEST, sb.toString());
}
data.put(REFERENCE_TYPE, type.toString().toLowerCase());
data.put(REF_ID, uniqueName);
relationshipData.add(data);
}
}
return relationshipData;
}
use of org.springframework.extensions.webscripts.WebScriptException in project records-management by Alfresco.
the class DataSetPost 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
protected Map<String, Object> executeImpl(WebScriptRequest req, Status status, Cache cache) {
Map<String, Object> model = new HashMap<String, Object>(1, 1.0f);
try {
// Resolve data set id
String dataSetId = req.getServiceMatch().getTemplateVars().get(ARG_DATA_SET_ID);
if (StringUtils.isBlank(dataSetId)) {
throw new WebScriptException(Status.STATUS_BAD_REQUEST, "A data set id was not provided.");
}
if (!dataSetService.existsDataSet(dataSetId)) {
throw new WebScriptException(Status.STATUS_NOT_FOUND, "A data set with the id '" + dataSetId + "'" + " does not exist.");
}
// Resolve RM site
String siteName = req.getParameter(ARG_SITE_NAME);
if (StringUtils.isBlank(siteName)) {
siteName = RmSiteType.DEFAULT_SITE_NAME;
}
// Check the site if it exists
if (siteService.getSite(siteName) == null) {
throw new WebScriptException(Status.STATUS_BAD_REQUEST, "A Records Management site with the name '" + siteName + "' does not exist.");
}
// Resolve documentLibrary (filePlan) container
NodeRef filePlan = siteService.getContainer(siteName, RmSiteType.COMPONENT_DOCUMENT_LIBRARY);
if (filePlan == null) {
filePlan = siteService.createContainer(siteName, RmSiteType.COMPONENT_DOCUMENT_LIBRARY, TYPE_FILE_PLAN, null);
}
// Load data set in to the file plan
dataSetService.loadDataSet(filePlan, dataSetId);
model.put("success", true);
model.put("message", "Successfully imported data set.");
} catch (Exception ex) {
model.put("success", false);
model.put("message", ex.getMessage());
logger.error("Error while importing data set: " + ex);
}
return model;
}
use of org.springframework.extensions.webscripts.WebScriptException in project records-management by Alfresco.
the class DispositionAbstractBase method parseRequestForActionDefinition.
/**
* Parses the request and providing it's valid returns the DispositionActionDefinition object.
*
* @param req The webscript request
* @param schedule The disposition schedule
* @return The DispositionActionDefinition object the request is aimed at
*/
protected DispositionActionDefinition parseRequestForActionDefinition(WebScriptRequest req, DispositionSchedule schedule) {
// make sure the requested action definition exists
Map<String, String> templateVars = req.getServiceMatch().getTemplateVars();
String actionDefId = templateVars.get("action_def_id");
DispositionActionDefinition actionDef = schedule.getDispositionActionDefinition(actionDefId);
if (actionDef == null) {
throw new WebScriptException(HttpServletResponse.SC_NOT_FOUND, "Requested disposition action definition (id:" + actionDefId + ") does not exist");
}
return actionDef;
}
use of org.springframework.extensions.webscripts.WebScriptException in project records-management by Alfresco.
the class DispositionAbstractBase method parseRequestForSchedule.
/**
* Parses the request and providing it's valid returns the DispositionSchedule object.
*
* @param req The webscript request
* @return The DispositionSchedule object the request is aimed at
*/
protected DispositionSchedule parseRequestForSchedule(WebScriptRequest req) {
// get the NodeRef from the request
NodeRef nodeRef = parseRequestForNodeRef(req);
// Determine whether we are getting the inherited disposition schedule or not
boolean inherited = true;
String inheritedString = req.getParameter("inherited");
if (inheritedString != null) {
inherited = Boolean.parseBoolean(inheritedString);
}
// make sure the node passed in has a disposition schedule attached
DispositionSchedule schedule = null;
if (inherited) {
schedule = getDispositionService().getDispositionSchedule(nodeRef);
} else {
schedule = getDispositionService().getAssociatedDispositionSchedule(nodeRef);
}
if (schedule == null) {
throw new WebScriptException(HttpServletResponse.SC_NOT_FOUND, "Node " + nodeRef.toString() + " does not have a disposition schedule");
}
return schedule;
}
Aggregations