Search in sources :

Example 66 with WebScriptException

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;
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) WebScriptException(org.springframework.extensions.webscripts.WebScriptException)

Example 67 with WebScriptException

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;
}
Also used : RelationshipDisplayName(org.alfresco.module.org_alfresco_module_rm.relationship.RelationshipDisplayName) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) RelationshipType(org.alfresco.module.org_alfresco_module_rm.relationship.RelationshipType) NodeRef(org.alfresco.service.cmr.repository.NodeRef) WebScriptException(org.springframework.extensions.webscripts.WebScriptException) Relationship(org.alfresco.module.org_alfresco_module_rm.relationship.Relationship) RelationshipDefinition(org.alfresco.module.org_alfresco_module_rm.relationship.RelationshipDefinition) HashMap(java.util.HashMap) Map(java.util.Map)

Example 68 with WebScriptException

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;
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) WebScriptException(org.springframework.extensions.webscripts.WebScriptException) HashMap(java.util.HashMap) WebScriptException(org.springframework.extensions.webscripts.WebScriptException)

Example 69 with WebScriptException

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;
}
Also used : WebScriptException(org.springframework.extensions.webscripts.WebScriptException) DispositionActionDefinition(org.alfresco.module.org_alfresco_module_rm.disposition.DispositionActionDefinition)

Example 70 with WebScriptException

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;
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) WebScriptException(org.springframework.extensions.webscripts.WebScriptException) DispositionSchedule(org.alfresco.module.org_alfresco_module_rm.disposition.DispositionSchedule)

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