Search in sources :

Example 66 with AlfrescoRuntimeException

use of org.alfresco.error.AlfrescoRuntimeException in project records-management by Alfresco.

the class DispositionServiceImpl method getAssociatedDispositionScheduleImpl.

/**
 * Gets the node reference of the disposition schedule associated with the container.
 *
 * @param nodeRef   node reference of the container
 * @return {@link NodeRef}  node reference of the disposition schedule, null if none
 */
private NodeRef getAssociatedDispositionScheduleImpl(NodeRef nodeRef) {
    NodeRef result = null;
    ParameterCheck.mandatory("nodeRef", nodeRef);
    // Make sure we are dealing with an RM node
    if (!filePlanService.isFilePlanComponent(nodeRef)) {
        throw new AlfrescoRuntimeException("Can not find the associated retention schedule for a non records management component. (nodeRef=" + nodeRef.toString() + ")");
    }
    if (this.nodeService.hasAspect(nodeRef, ASPECT_SCHEDULED)) {
        List<ChildAssociationRef> childAssocs = this.nodeService.getChildAssocs(nodeRef, ASSOC_DISPOSITION_SCHEDULE, RegexQNamePattern.MATCH_ALL);
        if (!childAssocs.isEmpty()) {
            ChildAssociationRef firstChildAssocRef = childAssocs.get(0);
            result = firstChildAssocRef.getChildRef();
        }
    }
    return result;
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) AlfrescoRuntimeException(org.alfresco.error.AlfrescoRuntimeException) ChildAssociationRef(org.alfresco.service.cmr.repository.ChildAssociationRef)

Example 67 with AlfrescoRuntimeException

use of org.alfresco.error.AlfrescoRuntimeException in project records-management by Alfresco.

the class RecordsManagementEventServiceImpl method canEditEvent.

/**
 * @see org.alfresco.module.org_alfresco_module_rm.event.RecordsManagementEventService#canEditEvent(java.lang.String, java.lang.String, java.lang.String)
 */
@SuppressWarnings("rawtypes")
public boolean canEditEvent(String eventDisplayLabel, String eventName, String eventType) {
    ParameterCheck.mandatoryString("eventDisplayLabel", eventDisplayLabel);
    ParameterCheck.mandatoryString("eventName", eventName);
    ParameterCheck.mandatoryString("eventType", eventType);
    boolean canEditEvent = true;
    if (!existsEvent(eventName)) {
        throw new AlfrescoRuntimeException("The event '" + eventName + "' does not exist.");
    }
    for (Iterator iterator = getEventMap().values().iterator(); iterator.hasNext(); ) {
        RecordsManagementEvent recordsManagementEvent = (RecordsManagementEvent) iterator.next();
        if (recordsManagementEvent.getDisplayLabel().equalsIgnoreCase(eventDisplayLabel)) {
            if (recordsManagementEvent.getName().equalsIgnoreCase(eventName)) {
                if (!recordsManagementEvent.getType().equalsIgnoreCase(eventType)) {
                    canEditEvent = true;
                } else {
                    canEditEvent = false;
                }
            } else {
                throw new AlfrescoRuntimeException("Cannot edit event. An event with the display label '" + eventDisplayLabel + "' already exist.");
            }
            break;
        }
    }
    return canEditEvent;
}
Also used : Iterator(java.util.Iterator) AlfrescoRuntimeException(org.alfresco.error.AlfrescoRuntimeException)

Example 68 with AlfrescoRuntimeException

use of org.alfresco.error.AlfrescoRuntimeException in project records-management by Alfresco.

the class FilePlanServiceImpl method getContained.

/**
 * Get contained nodes of a particular type.  If null return all.
 *
 * @param container container node reference
 * @param typeFilter type filter, null if none
 * @return {@link List}<{@link NodeRef> list of contained node references
 */
private List<NodeRef> getContained(NodeRef container, QName typeFilter, boolean deep) {
    // Parameter check
    ParameterCheck.mandatory("container", container);
    // Check we have a container in our hands
    if (!isRecordCategory(container)) {
        throw new AlfrescoRuntimeException(I18NUtil.getMessage(MSG_CONTAINER_EXPECTED));
    }
    List<NodeRef> result = new ArrayList<NodeRef>(1);
    List<ChildAssociationRef> assocs = this.nodeService.getChildAssocs(container, ContentModel.ASSOC_CONTAINS, RegexQNamePattern.MATCH_ALL);
    for (ChildAssociationRef assoc : assocs) {
        NodeRef child = assoc.getChildRef();
        QName childType = nodeService.getType(child);
        if (typeFilter == null || typeFilter.equals(childType) || dictionaryService.isSubClass(childType, typeFilter)) {
            result.add(child);
        }
        // Inspect the containers and add children if deep
        if (deep && (TYPE_RECORD_CATEGORY.equals(childType) || dictionaryService.isSubClass(childType, TYPE_RECORD_CATEGORY))) {
            result.addAll(getContained(child, typeFilter, deep));
        }
    }
    return result;
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) QName(org.alfresco.service.namespace.QName) ArrayList(java.util.ArrayList) AlfrescoRuntimeException(org.alfresco.error.AlfrescoRuntimeException) ChildAssociationRef(org.alfresco.service.cmr.repository.ChildAssociationRef)

Example 69 with AlfrescoRuntimeException

use of org.alfresco.error.AlfrescoRuntimeException in project records-management by Alfresco.

the class FilePlanServiceImpl method createRecordCategory.

/**
 * @see org.alfresco.module.org_alfresco_module_rm.fileplan.FilePlanService#createRecordCategory(org.alfresco.service.cmr.repository.NodeRef, java.lang.String, org.alfresco.service.namespace.QName, java.util.Map)
 */
public NodeRef createRecordCategory(NodeRef parent, String name, QName type, Map<QName, Serializable> properties) {
    ParameterCheck.mandatory("parent", parent);
    ParameterCheck.mandatory("name", name);
    ParameterCheck.mandatory("type", type);
    // Check that the parent is a container
    QName parentType = nodeService.getType(parent);
    if (!TYPE_RECORDS_MANAGEMENT_CONTAINER.equals(parentType) && !dictionaryService.isSubClass(parentType, TYPE_RECORDS_MANAGEMENT_CONTAINER)) {
        throw new AlfrescoRuntimeException(I18NUtil.getMessage(MSG_CONTAINER_PARENT_TYPE, parentType.toString()));
    }
    // Check that the the provided type is a sub-type of rm:recordCategory
    if (!TYPE_RECORD_CATEGORY.equals(type) && !dictionaryService.isSubClass(type, TYPE_RECORD_CATEGORY)) {
        throw new AlfrescoRuntimeException(I18NUtil.getMessage(MSG_CONTAINER_TYPE, type.toString()));
    }
    // Set the properties for the record category
    Map<QName, Serializable> props = new HashMap<QName, Serializable>(1);
    if (properties != null && properties.size() != 0) {
        props.putAll(properties);
    }
    props.put(ContentModel.PROP_NAME, name);
    return nodeService.createNode(parent, ContentModel.ASSOC_CONTAINS, QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, (name.length() > QName.MAX_LENGTH ? name.substring(0, QName.MAX_LENGTH) : name)), type, props).getChildRef();
}
Also used : Serializable(java.io.Serializable) HashMap(java.util.HashMap) QName(org.alfresco.service.namespace.QName) AlfrescoRuntimeException(org.alfresco.error.AlfrescoRuntimeException)

Example 70 with AlfrescoRuntimeException

use of org.alfresco.error.AlfrescoRuntimeException in project records-management by Alfresco.

the class CustomEmailMappingServiceImpl method loadConfig.

/**
 * Loads the custom mappings from the configuration file.
 *
 * @return
 */
private Set<CustomMapping> loadConfig() {
    Set<CustomMapping> result = new HashSet<CustomMapping>();
    ContentReader cr = contentService.getReader(CONFIG_NODE_REF, ContentModel.PROP_CONTENT);
    if (cr != null) {
        String text = cr.getContentString();
        try {
            JSONArray jsonArray = new JSONArray(new JSONTokener(text));
            for (int i = 0; i < jsonArray.length(); i++) {
                JSONObject obj = jsonArray.getJSONObject(i);
                CustomMapping mapping = new CustomMapping();
                mapping.setFrom(obj.getString("from"));
                mapping.setTo(obj.getString("to"));
                result.add(mapping);
            }
        } catch (JSONException je) {
            throw new AlfrescoRuntimeException("Unable to read custom email configuration", je);
        }
    }
    return result;
}
Also used : JSONTokener(org.json.JSONTokener) JSONObject(org.json.JSONObject) ContentReader(org.alfresco.service.cmr.repository.ContentReader) JSONArray(org.json.JSONArray) JSONException(org.json.JSONException) AlfrescoRuntimeException(org.alfresco.error.AlfrescoRuntimeException) HashSet(java.util.HashSet)

Aggregations

AlfrescoRuntimeException (org.alfresco.error.AlfrescoRuntimeException)197 NodeRef (org.alfresco.service.cmr.repository.NodeRef)79 QName (org.alfresco.service.namespace.QName)39 HashMap (java.util.HashMap)38 IOException (java.io.IOException)32 ArrayList (java.util.ArrayList)31 JSONException (org.json.JSONException)23 ChildAssociationRef (org.alfresco.service.cmr.repository.ChildAssociationRef)22 Serializable (java.io.Serializable)20 M2Model (org.alfresco.repo.dictionary.M2Model)18 JSONObject (org.json.JSONObject)15 Date (java.util.Date)14 Map (java.util.Map)12 FacesContext (javax.faces.context.FacesContext)12 InputStream (java.io.InputStream)10 RetryingTransactionCallback (org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback)10 SiteInfo (org.alfresco.service.cmr.site.SiteInfo)10 JSONArray (org.json.JSONArray)10 List (java.util.List)8 FileNotFoundException (org.alfresco.service.cmr.model.FileNotFoundException)8