Search in sources :

Example 1 with EventCompletionDetails

use of org.alfresco.module.org_alfresco_module_rm.event.EventCompletionDetails in project records-management by Alfresco.

the class DispositionLifecycleGet 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 next action
    NodeRef nodeRef = parseRequestForNodeRef(req);
    // make sure the node passed in has a next action attached
    DispositionAction nextAction = getDispositionService().getNextDispositionAction(nodeRef);
    if (nextAction == null) {
        Map<String, Object> nextActionModel = new HashMap<String, Object>(2);
        nextActionModel.put("notFound", true);
        nextActionModel.put("message", "Node " + nodeRef.toString() + " does not have a disposition lifecycle");
        Map<String, Object> model = new HashMap<String, Object>(1);
        model.put("nextaction", nextActionModel);
        return model;
    } else {
        // add all the next action data to Map
        Map<String, Object> nextActionModel = new HashMap<String, Object>(8);
        String serviceUrl = req.getServiceContextPath() + req.getPathInfo();
        nextActionModel.put("url", serviceUrl);
        nextActionModel.put("name", nextAction.getName());
        nextActionModel.put("label", nextAction.getLabel());
        nextActionModel.put("eventsEligible", getDispositionService().isNextDispositionActionEligible(nodeRef));
        if (nextAction.getAsOfDate() != null) {
            nextActionModel.put("asOf", ISO8601DateFormat.format(nextAction.getAsOfDate()));
        }
        if (nextAction.getStartedAt() != null) {
            nextActionModel.put("startedAt", ISO8601DateFormat.format(nextAction.getStartedAt()));
        }
        String startedBy = nextAction.getStartedBy();
        if (startedBy != null) {
            nextActionModel.put("startedBy", startedBy);
            addUsersRealName(nextActionModel, startedBy, "startedBy");
        }
        if (nextAction.getCompletedAt() != null) {
            nextActionModel.put("completedAt", ISO8601DateFormat.format(nextAction.getCompletedAt()));
        }
        String completedBy = nextAction.getCompletedBy();
        if (completedBy != null) {
            nextActionModel.put("completedBy", completedBy);
            addUsersRealName(nextActionModel, completedBy, "completedBy");
        }
        List<Map<String, Object>> events = new ArrayList<Map<String, Object>>();
        for (EventCompletionDetails event : nextAction.getEventCompletionDetails()) {
            events.add(createEventModel(event));
        }
        nextActionModel.put("events", events);
        // create model object with just the schedule data
        Map<String, Object> model = new HashMap<String, Object>(1);
        model.put("nextaction", nextActionModel);
        return model;
    }
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) HashMap(java.util.HashMap) EventCompletionDetails(org.alfresco.module.org_alfresco_module_rm.event.EventCompletionDetails) ArrayList(java.util.ArrayList) HashMap(java.util.HashMap) Map(java.util.Map) DispositionAction(org.alfresco.module.org_alfresco_module_rm.disposition.DispositionAction)

Example 2 with EventCompletionDetails

use of org.alfresco.module.org_alfresco_module_rm.event.EventCompletionDetails in project records-management by Alfresco.

the class BroadcastDispositionActionDefinitionUpdateAction method rollupSearchProperties.

/**
 * Manually update the rolled up search properties
 *
 * @param disposableItem    disposable item
 */
private void rollupSearchProperties(NodeRef disposableItem) {
    DispositionAction da = getDispositionService().getNextDispositionAction(disposableItem);
    if (da != null) {
        Map<QName, Serializable> props = getNodeService().getProperties(disposableItem);
        props.put(PROP_RS_DISPOSITION_ACTION_NAME, da.getName());
        props.put(PROP_RS_DISPOSITION_ACTION_AS_OF, da.getAsOfDate());
        props.put(PROP_RS_DISPOSITION_EVENTS_ELIGIBLE, getNodeService().getProperty(da.getNodeRef(), PROP_DISPOSITION_EVENTS_ELIGIBLE));
        DispositionActionDefinition daDefinition = da.getDispositionActionDefinition();
        Period period = daDefinition.getPeriod();
        if (period != null) {
            props.put(PROP_RS_DISPOSITION_PERIOD, period.getPeriodType());
            props.put(PROP_RS_DISPOSITION_PERIOD_EXPRESSION, period.getExpression());
        } else {
            props.put(PROP_RS_DISPOSITION_PERIOD, null);
            props.put(PROP_RS_DISPOSITION_PERIOD_EXPRESSION, null);
        }
        List<EventCompletionDetails> events = da.getEventCompletionDetails();
        List<String> list = new ArrayList<String>(events.size());
        for (EventCompletionDetails event : events) {
            list.add(event.getEventName());
        }
        props.put(PROP_RS_DISPOSITION_EVENTS, (Serializable) list);
        getNodeService().setProperties(disposableItem, props);
    }
}
Also used : Serializable(java.io.Serializable) QName(org.alfresco.service.namespace.QName) EventCompletionDetails(org.alfresco.module.org_alfresco_module_rm.event.EventCompletionDetails) ArrayList(java.util.ArrayList) Period(org.alfresco.service.cmr.repository.Period) DispositionActionDefinition(org.alfresco.module.org_alfresco_module_rm.disposition.DispositionActionDefinition) DispositionAction(org.alfresco.module.org_alfresco_module_rm.disposition.DispositionAction)

Example 3 with EventCompletionDetails

use of org.alfresco.module.org_alfresco_module_rm.event.EventCompletionDetails in project records-management by Alfresco.

the class DispositionServiceImplTest method checkDispositionAction.

/**
 * @param da
 * @param name
 * @param arrEventNames
 * @param strPeriod
 */
private void checkDispositionAction(DispositionAction da, String name, String[] arrEventNames, String strPeriod) {
    assertNotNull(da);
    assertEquals(name, da.getName());
    List<EventCompletionDetails> events = da.getEventCompletionDetails();
    assertNotNull(events);
    assertEquals(arrEventNames.length, events.size());
    List<String> origEvents = new ArrayList<String>(events.size());
    for (EventCompletionDetails event : events) {
        origEvents.add(event.getEventName());
    }
    List<String> expectedEvents = Arrays.asList(arrEventNames);
    Collection<String> copy = new ArrayList<String>(origEvents);
    for (Iterator<String> i = origEvents.iterator(); i.hasNext(); ) {
        String origEvent = i.next();
        if (expectedEvents.contains(origEvent)) {
            i.remove();
            copy.remove(origEvent);
        }
    }
    if (copy.size() != 0 && expectedEvents.size() != 0) {
        StringBuffer buff = new StringBuffer(255);
        if (copy.size() != 0) {
            buff.append("The following events where found, but not expected: (");
            for (String eventName : copy) {
                buff.append(eventName).append(", ");
            }
            buff.append(").  ");
        }
        if (expectedEvents.size() != 0) {
            buff.append("The following events where not found, but expected: (");
            for (String eventName : expectedEvents) {
                buff.append(eventName).append(", ");
            }
            buff.append(").");
        }
        fail(buff.toString());
    }
    if (CommonRMTestUtils.PERIOD_NONE.equals(strPeriod)) {
        assertNull(da.getAsOfDate());
    } else {
        assertNotNull(da.getAsOfDate());
    }
}
Also used : EventCompletionDetails(org.alfresco.module.org_alfresco_module_rm.event.EventCompletionDetails) ArrayList(java.util.ArrayList)

Example 4 with EventCompletionDetails

use of org.alfresco.module.org_alfresco_module_rm.event.EventCompletionDetails in project records-management by Alfresco.

the class DispositionActionImpl method updateEventEligible.

/**
 * Calculates and updates the <code>rma:dispositionEventsEligible</code>
 * property for the given next disposition action.
 *
 * @param nextAction The next disposition action
 * @return The result of calculation
 *
 * @since 2.2
 */
private boolean updateEventEligible() {
    boolean eligible = false;
    // get the events for the next disposition action
    List<EventCompletionDetails> events = getEventCompletionDetails();
    if (!events.isEmpty()) {
        // get the disposition action definition
        DispositionActionDefinition dispositionActionDefinition = getDispositionActionDefinition();
        if (dispositionActionDefinition != null) {
            if (!dispositionActionDefinition.eligibleOnFirstCompleteEvent()) {
                // if one event is complete then the disposition action is eligible
                eligible = true;
                for (EventCompletionDetails event : events) {
                    if (!event.isEventComplete()) {
                        eligible = false;
                        break;
                    }
                }
            } else {
                // all events must be complete for the disposition action to be eligible
                for (EventCompletionDetails event : events) {
                    if (event.isEventComplete()) {
                        eligible = true;
                        break;
                    }
                }
            }
        }
    }
    // Update the property with the eligible value
    services.getNodeService().setProperty(getNodeRef(), PROP_DISPOSITION_EVENTS_ELIGIBLE, eligible);
    return eligible;
}
Also used : EventCompletionDetails(org.alfresco.module.org_alfresco_module_rm.event.EventCompletionDetails)

Example 5 with EventCompletionDetails

use of org.alfresco.module.org_alfresco_module_rm.event.EventCompletionDetails in project records-management by Alfresco.

the class DispositionActionImpl method getEventCompletionDetailsFromNodeRef.

/**
 * Helper method to create object representation of event completed details from
 * node reference.
 *
 * @param nodeRef                           node reference
 * @return {@link EventCompletionDetails}   event completion details
 */
private EventCompletionDetails getEventCompletionDetailsFromNodeRef(NodeRef nodeRef) {
    // get the properties
    Map<QName, Serializable> props = this.services.getNodeService().getProperties(nodeRef);
    // get the event name
    String eventName = (String) props.get(PROP_EVENT_EXECUTION_NAME);
    // create event completion details
    EventCompletionDetails ecd = new EventCompletionDetails(nodeRef, eventName, services.getRecordsManagementEventService().getEvent(eventName).getDisplayLabel(), getBooleanValue(props.get(PROP_EVENT_EXECUTION_AUTOMATIC), false), getBooleanValue(props.get(PROP_EVENT_EXECUTION_COMPLETE), false), (Date) props.get(PROP_EVENT_EXECUTION_COMPLETED_AT), (String) props.get(PROP_EVENT_EXECUTION_COMPLETED_BY));
    return ecd;
}
Also used : Serializable(java.io.Serializable) QName(org.alfresco.service.namespace.QName) EventCompletionDetails(org.alfresco.module.org_alfresco_module_rm.event.EventCompletionDetails)

Aggregations

EventCompletionDetails (org.alfresco.module.org_alfresco_module_rm.event.EventCompletionDetails)8 ArrayList (java.util.ArrayList)4 Serializable (java.io.Serializable)2 DispositionAction (org.alfresco.module.org_alfresco_module_rm.disposition.DispositionAction)2 ChildAssociationRef (org.alfresco.service.cmr.repository.ChildAssociationRef)2 QName (org.alfresco.service.namespace.QName)2 HashMap (java.util.HashMap)1 Map (java.util.Map)1 AlfrescoRuntimeException (org.alfresco.error.AlfrescoRuntimeException)1 DispositionActionDefinition (org.alfresco.module.org_alfresco_module_rm.disposition.DispositionActionDefinition)1 NodeRef (org.alfresco.service.cmr.repository.NodeRef)1 Period (org.alfresco.service.cmr.repository.Period)1