Search in sources :

Example 71 with AlfrescoRuntimeException

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

the class CustomEmailMappingServiceImpl method saveConfig.

/**
 * @param customMappingsToSave
 */
private void saveConfig(Set<CustomMapping> customMappingsToSave) {
    if (!nodeService.exists(CONFIG_NODE_REF)) {
        // create the config node
        Map<QName, Serializable> properties = new HashMap<QName, Serializable>(2);
        properties.put(ContentModel.PROP_NAME, CONFIG_NAME);
        properties.put(ContentModel.PROP_NODE_UUID, CONFIG_NODE_REF.getId());
        nodeService.createNode(CONFIG_FOLDER_NODE_REF, ContentModel.ASSOC_CONTAINS, QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, CONFIG_NAME), ContentModel.TYPE_CONTENT, properties);
    }
    // build JSON array of mappings
    JSONArray jsonMappings = new JSONArray();
    try {
        for (CustomMapping mapping : customMappingsToSave) {
            JSONObject obj = new JSONObject();
            obj.put("from", mapping.getFrom());
            obj.put("to", mapping.getTo());
            jsonMappings.put(obj);
        }
    } catch (JSONException je) {
        throw new AlfrescoRuntimeException("Unable to create JSON email mapping configuration during save.", je);
    }
    // update the content
    ContentWriter writer = this.contentService.getWriter(CONFIG_NODE_REF, ContentModel.PROP_CONTENT, true);
    writer.setMimetype(MimetypeMap.MIMETYPE_TEXT_PLAIN);
    writer.setEncoding("UTF-8");
    writer.putContent(jsonMappings.toString());
}
Also used : Serializable(java.io.Serializable) ContentWriter(org.alfresco.service.cmr.repository.ContentWriter) JSONObject(org.json.JSONObject) HashMap(java.util.HashMap) QName(org.alfresco.service.namespace.QName) JSONArray(org.json.JSONArray) JSONException(org.json.JSONException) AlfrescoRuntimeException(org.alfresco.error.AlfrescoRuntimeException)

Example 72 with AlfrescoRuntimeException

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

the class HoldServiceImpl method removeFromHolds.

/**
 * @see org.alfresco.module.org_alfresco_module_rm.hold.HoldService#removeFromHolds(java.util.List, org.alfresco.service.cmr.repository.NodeRef)
 */
@Override
public void removeFromHolds(List<NodeRef> holds, final NodeRef nodeRef) {
    ParameterCheck.mandatory("holds", holds);
    ParameterCheck.mandatory("nodeRef", nodeRef);
    if (holds != null && !holds.isEmpty()) {
        for (final NodeRef hold : holds) {
            if (!instanceOf(hold, TYPE_HOLD)) {
                throw new AlfrescoRuntimeException("Can't remove from hold, because it isn't a hold. (hold=" + hold + ")");
            }
            if (getHeld(hold).contains(nodeRef)) {
                // run as system so we don't run into further permission issues
                // we already know we have to have the correct capability to get here
                authenticationUtil.runAsSystem(new RunAsWork<Void>() {

                    @Override
                    public Void doWork() {
                        // remove from hold
                        nodeService.removeChild(hold, nodeRef);
                        // audit that the node has been remove from the hold
                        // TODO add details of the hold that the node was removed from
                        recordsManagementAuditService.auditEvent(nodeRef, AUDIT_REMOVE_FROM_HOLD);
                        return null;
                    }
                });
            }
        }
        // run as system as we can't be sure if have remove aspect rights on node
        authenticationUtil.runAsSystem(new RunAsWork<Void>() {

            @Override
            public Void doWork() {
                removeFreezeAspect(nodeRef, 0);
                return null;
            }
        });
    }
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) AlfrescoRuntimeException(org.alfresco.error.AlfrescoRuntimeException)

Example 73 with AlfrescoRuntimeException

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

the class HoldServiceImpl method getHold.

/**
 * @see org.alfresco.module.org_alfresco_module_rm.hold.HoldService#getHold(org.alfresco.service.cmr.repository.NodeRef, java.lang.String)
 */
@Override
public NodeRef getHold(NodeRef filePlan, String name) {
    ParameterCheck.mandatory("filePlan", filePlan);
    ParameterCheck.mandatory("name", name);
    // get the root hold container
    NodeRef holdContainer = filePlanService.getHoldContainer(filePlan);
    // get the hold by name
    NodeRef hold = nodeService.getChildByName(holdContainer, ContentModel.ASSOC_CONTAINS, name);
    if (hold != null && !isHold(hold)) {
        throw new AlfrescoRuntimeException("Can not get hold, because the named node reference isn't a hold.");
    }
    return hold;
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) AlfrescoRuntimeException(org.alfresco.error.AlfrescoRuntimeException)

Example 74 with AlfrescoRuntimeException

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

the class RecordsManagementAdminBase method writeCustomContentModel.

/**
 * Updates the content of the custom model
 *
 * @param modelRef The node reference of the model
 * @param deserializedModel The deserialized model
 */
protected void writeCustomContentModel(NodeRef modelRef, M2Model deserializedModel) {
    ContentWriter writer = getContentService().getWriter(modelRef, ContentModel.TYPE_CONTENT, true);
    writer.setMimetype(MimetypeMap.MIMETYPE_XML);
    writer.setEncoding("UTF-8");
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    deserializedModel.toXML(baos);
    String updatedModelXml;
    try {
        updatedModelXml = baos.toString("UTF-8");
        writer.putContent(updatedModelXml);
    // putContent closes all resources.
    // so we don't have to.
    } catch (UnsupportedEncodingException uex) {
        throw new AlfrescoRuntimeException(I18NUtil.getMessage(MSG_ERROR_WRITE_CUSTOM_MODEL, modelRef.toString()), uex);
    }
}
Also used : ContentWriter(org.alfresco.service.cmr.repository.ContentWriter) UnsupportedEncodingException(java.io.UnsupportedEncodingException) AlfrescoRuntimeException(org.alfresco.error.AlfrescoRuntimeException) ByteArrayOutputStream(java.io.ByteArrayOutputStream)

Example 75 with AlfrescoRuntimeException

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

the class RecordsManagementAdminServiceImpl method removeCustomPropertyDefinition.

/**
 * @see org.alfresco.module.org_alfresco_module_rm.RecordsManagementAdminService#removeCustomPropertyDefinition(org.alfresco.service.namespace.QName)
 */
public void removeCustomPropertyDefinition(QName propQName) {
    mandatory("propQName", propQName);
    NodeRef modelRef = getCustomModelRef(propQName.getNamespaceURI());
    M2Model deserializedModel = readCustomContentModel(modelRef);
    String propQNameAsString = propQName.toPrefixString(getNamespaceService());
    String aspectName = null;
    boolean found = false;
    // attempt to delete the property definition.
    for (QName customisableType : getCustomisable()) {
        aspectName = getCustomAspect(customisableType).toPrefixString(getNamespaceService());
        M2Aspect customPropsAspect = deserializedModel.getAspect(aspectName);
        if (customPropsAspect == null) {
            throw new AlfrescoRuntimeException(I18NUtil.getMessage(MSG_UNKNOWN_ASPECT, aspectName));
        }
        M2Property prop = customPropsAspect.getProperty(propQNameAsString);
        if (prop != null) {
            if (logger.isDebugEnabled()) {
                StringBuilder msg = new StringBuilder();
                msg.append("Attempting to delete custom property: ");
                msg.append(propQNameAsString);
                logger.debug(msg.toString());
            }
            found = true;
            customPropsAspect.removeProperty(propQNameAsString);
            break;
        }
    }
    if (!found) {
        throw new AlfrescoRuntimeException(I18NUtil.getMessage(MSG_PROP_EXIST, propQNameAsString));
    }
    writeCustomContentModel(modelRef, deserializedModel);
    if (logger.isInfoEnabled()) {
        logger.info("deleteCustomPropertyDefinition: " + propQNameAsString + " from aspect: " + aspectName);
    }
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) QName(org.alfresco.service.namespace.QName) M2Property(org.alfresco.repo.dictionary.M2Property) M2Model(org.alfresco.repo.dictionary.M2Model) AlfrescoRuntimeException(org.alfresco.error.AlfrescoRuntimeException) ParameterCheck.mandatoryString(org.springframework.extensions.surf.util.ParameterCheck.mandatoryString) M2Aspect(org.alfresco.repo.dictionary.M2Aspect)

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