Search in sources :

Example 1 with DispositionActionDefinition

use of org.alfresco.module.org_alfresco_module_rm.disposition.DispositionActionDefinition in project records-management by Alfresco.

the class DispositionAbstractBase method getDispositionScheduleModel.

/**
 * Helper method to parse the request and retrieve the disposition schedule model.
 *
 * @param req The webscript request
 * @return Map representing the model
 */
protected Map<String, Object> getDispositionScheduleModel(WebScriptRequest req) {
    // parse the request to retrieve the schedule object
    DispositionSchedule schedule = parseRequestForSchedule(req);
    // add all the schedule data to Map
    Map<String, Object> scheduleModel = new HashMap<String, Object>(8);
    // build url
    String serviceUrl = req.getServiceContextPath() + req.getPathInfo();
    scheduleModel.put("url", serviceUrl);
    String actionsUrl = serviceUrl + "/dispositionactiondefinitions";
    scheduleModel.put("actionsUrl", actionsUrl);
    scheduleModel.put("nodeRef", schedule.getNodeRef().toString());
    scheduleModel.put("recordLevelDisposition", schedule.isRecordLevelDisposition());
    scheduleModel.put("canStepsBeRemoved", !getDispositionService().hasDisposableItems(schedule));
    if (schedule.getDispositionAuthority() != null) {
        scheduleModel.put("authority", schedule.getDispositionAuthority());
    }
    if (schedule.getDispositionInstructions() != null) {
        scheduleModel.put("instructions", schedule.getDispositionInstructions());
    }
    boolean unpublishedUpdates = false;
    boolean publishInProgress = false;
    List<Map<String, Object>> actions = new ArrayList<Map<String, Object>>();
    for (DispositionActionDefinition actionDef : schedule.getDispositionActionDefinitions()) {
        NodeRef actionDefNodeRef = actionDef.getNodeRef();
        if (getNodeService().hasAspect(actionDefNodeRef, RecordsManagementModel.ASPECT_UNPUBLISHED_UPDATE)) {
            unpublishedUpdates = true;
            publishInProgress = ((Boolean) getNodeService().getProperty(actionDefNodeRef, RecordsManagementModel.PROP_PUBLISH_IN_PROGRESS)).booleanValue();
        }
        actions.add(createActionDefModel(actionDef, actionsUrl + "/" + actionDef.getId()));
    }
    scheduleModel.put("actions", actions);
    scheduleModel.put("unpublishedUpdates", unpublishedUpdates);
    scheduleModel.put("publishInProgress", publishInProgress);
    // create model object with just the schedule data
    Map<String, Object> model = new HashMap<String, Object>(1);
    model.put("schedule", scheduleModel);
    return model;
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) HashMap(java.util.HashMap) DispositionSchedule(org.alfresco.module.org_alfresco_module_rm.disposition.DispositionSchedule) ArrayList(java.util.ArrayList) DispositionActionDefinition(org.alfresco.module.org_alfresco_module_rm.disposition.DispositionActionDefinition) Map(java.util.Map) HashMap(java.util.HashMap)

Example 2 with DispositionActionDefinition

use of org.alfresco.module.org_alfresco_module_rm.disposition.DispositionActionDefinition 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 3 with DispositionActionDefinition

use of org.alfresco.module.org_alfresco_module_rm.disposition.DispositionActionDefinition 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 4 with DispositionActionDefinition

use of org.alfresco.module.org_alfresco_module_rm.disposition.DispositionActionDefinition in project records-management by Alfresco.

the class TransferServiceImpl method transfer.

/**
 * @see org.alfresco.module.org_alfresco_module_rm.transfer.TransferService#transfer(NodeRef, boolean)
 */
@Override
public NodeRef transfer(NodeRef nodeRef, boolean isAccession) {
    ParameterCheck.mandatory("nodeRef", nodeRef);
    // Get the root rm node
    NodeRef root = filePlanService.getFilePlan(nodeRef);
    // Get the transfer object
    NodeRef transferNodeRef = (NodeRef) AlfrescoTransactionSupport.getResource(KEY_TRANSFER_NODEREF);
    if (transferNodeRef == null) {
        // Calculate a transfer name
        QName nodeDbid = QName.createQName(NamespaceService.SYSTEM_MODEL_1_0_URI, "node-dbid");
        Long dbId = (Long) nodeService.getProperty(nodeRef, nodeDbid);
        String transferName = StringUtils.leftPad(dbId.toString(), 10, "0");
        // Create the transfer object
        Map<QName, Serializable> transferProps = new HashMap<QName, Serializable>(2);
        transferProps.put(ContentModel.PROP_NAME, transferName);
        transferProps.put(PROP_TRANSFER_ACCESSION_INDICATOR, isAccession);
        // setup location property from disposition schedule
        DispositionAction da = dispositionService.getNextDispositionAction(nodeRef);
        if (da != null) {
            DispositionActionDefinition actionDef = da.getDispositionActionDefinition();
            if (actionDef != null) {
                transferProps.put(PROP_TRANSFER_LOCATION, actionDef.getLocation());
            }
        }
        NodeRef transferContainer = filePlanService.getTransferContainer(root);
        transferContainerType.disable();
        transferType.disable();
        try {
            transferNodeRef = nodeService.createNode(transferContainer, ContentModel.ASSOC_CONTAINS, QName.createQName(RM_URI, transferName), TYPE_TRANSFER, transferProps).getChildRef();
        } finally {
            transferContainerType.enable();
            transferType.enable();
        }
        // Bind the hold node reference to the transaction
        AlfrescoTransactionSupport.bindResource(KEY_TRANSFER_NODEREF, transferNodeRef);
    } else {
        // ensure this node has not already in the process of being transferred
        List<ChildAssociationRef> transferredAlready = nodeService.getChildAssocs(transferNodeRef, ASSOC_TRANSFERRED, ASSOC_TRANSFERRED);
        for (ChildAssociationRef car : transferredAlready) {
            if (car.getChildRef().equals(nodeRef)) {
                throw new AlfrescoRuntimeException(I18NUtil.getMessage(MSG_NODE_ALREADY_TRANSFER, nodeRef.toString()));
            }
        }
    }
    // Link the record to the trasnfer object
    transferType.disable();
    try {
        nodeService.addChild(transferNodeRef, nodeRef, ASSOC_TRANSFERRED, ASSOC_TRANSFERRED);
        // Set PDF indicator flag
        setPDFIndicationFlag(transferNodeRef, nodeRef);
    } finally {
        transferType.enable();
    }
    // Set the transferring indicator aspect
    nodeService.addAspect(nodeRef, ASPECT_TRANSFERRING, null);
    if (isRecordFolder(nodeRef)) {
        // add the transferring indicator aspect to all the child records
        for (NodeRef record : recordService.getRecords(nodeRef)) {
            nodeService.addAspect(record, ASPECT_TRANSFERRING, null);
        }
    }
    return transferNodeRef;
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) Serializable(java.io.Serializable) HashMap(java.util.HashMap) QName(org.alfresco.service.namespace.QName) AlfrescoRuntimeException(org.alfresco.error.AlfrescoRuntimeException) DispositionActionDefinition(org.alfresco.module.org_alfresco_module_rm.disposition.DispositionActionDefinition) ChildAssociationRef(org.alfresco.service.cmr.repository.ChildAssociationRef) DispositionAction(org.alfresco.module.org_alfresco_module_rm.disposition.DispositionAction)

Example 5 with DispositionActionDefinition

use of org.alfresco.module.org_alfresco_module_rm.disposition.DispositionActionDefinition in project records-management by Alfresco.

the class UpdateDispositionScheduleTest method testUpdatePeriod.

/**
 * <a href="https://issues.alfresco.com/jira/browse/RM-3386">RM-3386</a>
 * <p><pre>
 * Given a record subject to a disposition schedule
 * And the next step is due to run at some period after the date the content was created
 * When I update the period of the next step (and wait for this to be processed)
 * Then the "as of" date is updated to be at the new period after the creation date.
 * </pre>
 */
public void testUpdatePeriod() {
    test().given(() -> {
        // Create a category.
        category = filePlanService.createRecordCategory(filePlan, CATEGORY_NAME);
        // Create a disposition schedule for the category (Cut off immediately, then Destroy 1 year after the creation date).
        DispositionSchedule dispSched = utils.createBasicDispositionSchedule(category, "instructions", "authority", true, false);
        Map<QName, Serializable> cutOffParams = ImmutableMap.of(PROP_DISPOSITION_ACTION_NAME, CutOffAction.NAME, PROP_DISPOSITION_DESCRIPTION, "description", PROP_DISPOSITION_PERIOD, CommonRMTestUtils.PERIOD_IMMEDIATELY);
        dispositionService.addDispositionActionDefinition(dispSched, cutOffParams);
        Map<QName, Serializable> destroyParams = ImmutableMap.of(PROP_DISPOSITION_ACTION_NAME, DestroyAction.NAME, PROP_DISPOSITION_DESCRIPTION, "description", PROP_DISPOSITION_PERIOD, CommonRMTestUtils.PERIOD_ONE_YEAR, PROP_DISPOSITION_PERIOD_PROPERTY, ContentModel.PROP_CREATED);
        dispositionService.addDispositionActionDefinition(dispSched, destroyParams);
        // Create a folder containing a record within the category.
        folder = recordFolderService.createRecordFolder(category, FOLDER_NAME);
        record = fileFolderService.create(folder, RECORD_NAME, ContentModel.TYPE_CONTENT).getNodeRef();
        dispositionService.cutoffDisposableItem(record);
        // Ensure the update has been applied to the record.
        internalDispositionService.updateNextDispositionAction(record);
        originalAsOfDate = dispositionService.getNextDispositionAction(record).getAsOfDate();
    }).when(() -> {
        // Update the Destroy step to be 3 years after the creation date.
        DispositionSchedule dispSched = dispositionService.getDispositionSchedule(category);
        DispositionActionDefinition destroy = dispSched.getDispositionActionDefinitionByName(DestroyAction.NAME);
        Map<QName, Serializable> destroyParams = ImmutableMap.of(PROP_DISPOSITION_ACTION_NAME, DestroyAction.NAME, PROP_DISPOSITION_DESCRIPTION, "description", PROP_DISPOSITION_PERIOD, CommonRMTestUtils.PERIOD_THREE_YEARS, PROP_DISPOSITION_PERIOD_PROPERTY, ContentModel.PROP_CREATED);
        dispositionService.updateDispositionActionDefinition(destroy, destroyParams);
        // Make the disposition action definition update job run.
        dispositionActionDefinitionPublishExecutor.publish(destroy.getNodeRef());
    }).then().expect(true).from(() -> aboutTwoYearsApart(originalAsOfDate, dispositionService.getNextDispositionAction(record).getAsOfDate())).because("Increasing the destroy period by two years should increase the 'as of' date by two years.");
}
Also used : Serializable(java.io.Serializable) QName(org.alfresco.service.namespace.QName) DispositionSchedule(org.alfresco.module.org_alfresco_module_rm.disposition.DispositionSchedule) DispositionActionDefinition(org.alfresco.module.org_alfresco_module_rm.disposition.DispositionActionDefinition) ImmutableMap(com.google.common.collect.ImmutableMap) Map(java.util.Map)

Aggregations

DispositionActionDefinition (org.alfresco.module.org_alfresco_module_rm.disposition.DispositionActionDefinition)19 DispositionSchedule (org.alfresco.module.org_alfresco_module_rm.disposition.DispositionSchedule)10 QName (org.alfresco.service.namespace.QName)7 Serializable (java.io.Serializable)6 HashMap (java.util.HashMap)6 DispositionAction (org.alfresco.module.org_alfresco_module_rm.disposition.DispositionAction)6 NodeRef (org.alfresco.service.cmr.repository.NodeRef)4 Date (java.util.Date)3 WebScriptException (org.springframework.extensions.webscripts.WebScriptException)3 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 Map (java.util.Map)2 ChildAssociationRef (org.alfresco.service.cmr.repository.ChildAssociationRef)2 Period (org.alfresco.service.cmr.repository.Period)2 JSONException (org.json.JSONException)2 JSONObject (org.json.JSONObject)2 JSONTokener (org.json.JSONTokener)2 Test (org.junit.Test)2 ImmutableMap (com.google.common.collect.ImmutableMap)1 AlfrescoRuntimeException (org.alfresco.error.AlfrescoRuntimeException)1