Search in sources :

Example 1 with RecordsManagementEvent

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

the class ListOfValuesGet method createEventsModel.

/**
 * Creates the model for the list of events.
 *
 * @param baseUrl The base URL of the service
 * @return model of events list
 */
protected Map<String, Object> createEventsModel(String baseUrl) {
    // get all the events including their display labels from the event service
    List<RecordsManagementEvent> events = this.rmEventService.getEvents();
    List<Map<String, Object>> items = new ArrayList<Map<String, Object>>(events.size());
    for (RecordsManagementEvent event : events) {
        Map<String, Object> item = new HashMap<String, Object>(3);
        item.put("label", event.getDisplayLabel());
        item.put("value", event.getName());
        item.put("automatic", this.rmEventService.getEventType(event.getType()).isAutomaticEvent());
        items.add(item);
    }
    // create the model
    Map<String, Object> model = new HashMap<String, Object>(2);
    model.put("url", baseUrl + "/events");
    model.put("items", items);
    return model;
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) RecordsManagementEvent(org.alfresco.module.org_alfresco_module_rm.event.RecordsManagementEvent) HashMap(java.util.HashMap) Map(java.util.Map)

Example 2 with RecordsManagementEvent

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

the class RmEventPut 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) {
    ParameterCheck.mandatory("req", req);
    Map<String, Object> model = new HashMap<String, Object>();
    JSONObject json = null;
    try {
        // Convert the request content to JSON
        json = new JSONObject(new JSONTokener(req.getContent().getContent()));
        // Check the event name
        Map<String, String> templateVars = req.getServiceMatch().getTemplateVars();
        String eventName = templateVars.get(PARAM_EVENTNAME);
        if (eventName == null || eventName.isEmpty() || !rmEventService.existsEvent(eventName)) {
            throw new WebScriptException(Status.STATUS_NOT_FOUND, "No event name was provided.");
        }
        // Check the event display label
        String eventDisplayLabel = getValue(json, "eventDisplayLabel");
        doCheck(eventDisplayLabel, "No event display label was provided.");
        // Check the event type
        String eventType = getValue(json, "eventType");
        doCheck(eventType, "No event type was provided.");
        // Check if the event can be edited or not
        RecordsManagementEvent event = null;
        if (canEditEvent(eventDisplayLabel, eventName, eventType)) {
            // Create event
            event = rmEventService.addEvent(eventType, eventName, eventDisplayLabel);
        } else {
            // Get event
            event = rmEventService.getEvent(eventName);
        }
        model.put("event", event);
    } 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);
    }
    return model;
}
Also used : JSONTokener(org.json.JSONTokener) JSONObject(org.json.JSONObject) WebScriptException(org.springframework.extensions.webscripts.WebScriptException) HashMap(java.util.HashMap) RecordsManagementEvent(org.alfresco.module.org_alfresco_module_rm.event.RecordsManagementEvent) JSONException(org.json.JSONException) JSONObject(org.json.JSONObject) IOException(java.io.IOException)

Example 3 with RecordsManagementEvent

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

the class DispositionActionDefinitionImpl method getEvents.

/**
 * @see org.alfresco.module.org_alfresco_module_rm.disposition.DispositionActionDefinition#getEvents()
 */
@Override
@SuppressWarnings("unchecked")
public List<RecordsManagementEvent> getEvents() {
    List<RecordsManagementEvent> events = null;
    Collection<String> eventNames = (Collection<String>) nodeService.getProperty(this.dispositionActionNodeRef, PROP_DISPOSITION_EVENT);
    if (eventNames != null) {
        events = new ArrayList<RecordsManagementEvent>(eventNames.size());
        for (String eventName : eventNames) {
            RecordsManagementEvent event = recordsManagementEventService.getEvent(eventName);
            events.add(event);
        }
    } else {
        events = java.util.Collections.EMPTY_LIST;
    }
    return events;
}
Also used : RecordsManagementEvent(org.alfresco.module.org_alfresco_module_rm.event.RecordsManagementEvent) Collection(java.util.Collection)

Example 4 with RecordsManagementEvent

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

the class DispositionServiceImpl method initialiseDispositionAction.

/**
 * ========= Disposition Action Methods =========
 */
/**
 * Initialises the details of the next disposition action based on the details of a disposition
 * action definition.
 *
 *  @param nodeRef node reference
 *  @param dispositionActionDefinition disposition action definition
 */
private DispositionAction initialiseDispositionAction(NodeRef nodeRef, DispositionActionDefinition dispositionActionDefinition) {
    List<ChildAssociationRef> childAssocs = nodeService.getChildAssocs(nodeRef, ASSOC_NEXT_DISPOSITION_ACTION, ASSOC_NEXT_DISPOSITION_ACTION, 1, true);
    if (childAssocs != null && !childAssocs.isEmpty()) {
        return new DispositionActionImpl(serviceRegistry, childAssocs.get(0).getChildRef());
    }
    // Create the properties
    Map<QName, Serializable> props = new HashMap<QName, Serializable>(10);
    Date asOfDate = calculateAsOfDate(nodeRef, dispositionActionDefinition);
    // Set the property values
    props.put(PROP_DISPOSITION_ACTION_ID, dispositionActionDefinition.getId());
    props.put(PROP_DISPOSITION_ACTION, dispositionActionDefinition.getName());
    if (asOfDate != null) {
        props.put(PROP_DISPOSITION_AS_OF, asOfDate);
    }
    // Create a new disposition action object
    NodeRef dispositionActionNodeRef = this.nodeService.createNode(nodeRef, ASSOC_NEXT_DISPOSITION_ACTION, ASSOC_NEXT_DISPOSITION_ACTION, TYPE_DISPOSITION_ACTION, props).getChildRef();
    DispositionAction da = new DispositionActionImpl(serviceRegistry, dispositionActionNodeRef);
    // Create the events
    List<RecordsManagementEvent> events = dispositionActionDefinition.getEvents();
    for (RecordsManagementEvent event : events) {
        // For every event create an entry on the action
        da.addEventCompletionDetails(event);
    }
    return da;
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) Serializable(java.io.Serializable) HashMap(java.util.HashMap) QName(org.alfresco.service.namespace.QName) RecordsManagementEvent(org.alfresco.module.org_alfresco_module_rm.event.RecordsManagementEvent) ChildAssociationRef(org.alfresco.service.cmr.repository.ChildAssociationRef) Date(java.util.Date)

Example 5 with RecordsManagementEvent

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

the class RmEventGet method executeImpl.

@Override
public Map<String, Object> executeImpl(WebScriptRequest req, Status status, Cache cache) {
    Map<String, Object> model = new HashMap<String, Object>();
    // Event name
    Map<String, String> templateVars = req.getServiceMatch().getTemplateVars();
    String eventName = templateVars.get("eventname");
    if (eventName == null) {
        throw new WebScriptException(Status.STATUS_NOT_FOUND, "No event name was provided on the URL.");
    }
    // Check the event exists
    if (!rmEventService.existsEvent(eventName)) {
        throw new WebScriptException(Status.STATUS_NOT_FOUND, "The event " + eventName + " does not exist.");
    }
    // Get the event
    RecordsManagementEvent event = rmEventService.getEvent(eventName);
    model.put("event", event);
    return model;
}
Also used : WebScriptException(org.springframework.extensions.webscripts.WebScriptException) HashMap(java.util.HashMap) RecordsManagementEvent(org.alfresco.module.org_alfresco_module_rm.event.RecordsManagementEvent)

Aggregations

RecordsManagementEvent (org.alfresco.module.org_alfresco_module_rm.event.RecordsManagementEvent)8 HashMap (java.util.HashMap)7 WebScriptException (org.springframework.extensions.webscripts.WebScriptException)3 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 JSONException (org.json.JSONException)2 JSONObject (org.json.JSONObject)2 JSONTokener (org.json.JSONTokener)2 Serializable (java.io.Serializable)1 Collection (java.util.Collection)1 Date (java.util.Date)1 Map (java.util.Map)1 RecordsManagementEventType (org.alfresco.module.org_alfresco_module_rm.event.RecordsManagementEventType)1 ChildAssociationRef (org.alfresco.service.cmr.repository.ChildAssociationRef)1 NodeRef (org.alfresco.service.cmr.repository.NodeRef)1 QName (org.alfresco.service.namespace.QName)1