Search in sources :

Example 46 with AlfrescoRuntimeException

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

the class RelationshipServiceImpl method getAssociationDefinitionName.

/**
 * Gets the qualified name of the association definition for the given unique name
 *
 * @param uniqueName The unique name
 * @return The qualified name of the association definition for the given unique name
 */
private QName getAssociationDefinitionName(String uniqueName) {
    AssociationDefinition associationDefinition = getAssociationDefinition(uniqueName);
    if (associationDefinition == null) {
        StringBuilder sb = new StringBuilder();
        sb.append("The qualified name for '").append(uniqueName).append("' was not found.");
        throw new AlfrescoRuntimeException(sb.toString());
    }
    return associationDefinition.getName();
}
Also used : AssociationDefinition(org.alfresco.service.cmr.dictionary.AssociationDefinition) ChildAssociationDefinition(org.alfresco.service.cmr.dictionary.ChildAssociationDefinition) AlfrescoRuntimeException(org.alfresco.error.AlfrescoRuntimeException)

Example 47 with AlfrescoRuntimeException

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

the class RelationshipServiceImpl method getRelationshipDisplayName.

/**
 * Gets the relationship display name of the relationship definition
 *
 * @param type The type of the relationship definition
 * @param title The title of the association definition
 * @return The relationship display name of the relationship definition
 */
private RelationshipDisplayName getRelationshipDisplayName(RelationshipType type, String title) {
    String sourceText = null;
    String targetText = null;
    switch(type) {
        case BIDIRECTIONAL:
            sourceText = title;
            targetText = title;
            break;
        case PARENTCHILD:
            String[] sourceAndTarget = splitAssociationDefinitionTitle(title);
            sourceText = sourceAndTarget[0];
            targetText = sourceAndTarget[1];
            break;
        default:
            StringBuilder sb = new StringBuilder();
            sb.append("Unsupported relationship type: '").append(type.toString()).append("'.");
            throw new AlfrescoRuntimeException(sb.toString());
    }
    return new RelationshipDisplayName(sourceText, targetText);
}
Also used : AlfrescoRuntimeException(org.alfresco.error.AlfrescoRuntimeException) ParameterCheck.mandatoryString(org.alfresco.util.ParameterCheck.mandatoryString)

Example 48 with AlfrescoRuntimeException

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

the class ApplyFixMob1573Get method writeCustomContentModel.

private void writeCustomContentModel(M2Model deserializedModel) {
    ContentWriter writer = contentService.getWriter(RM_CUSTOM_MODEL_NODE_REF, 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("Exception when writing custom model xml.", uex);
    }
}
Also used : ContentWriter(org.alfresco.service.cmr.repository.ContentWriter) UnsupportedEncodingException(java.io.UnsupportedEncodingException) AlfrescoRuntimeException(org.alfresco.error.AlfrescoRuntimeException) ByteArrayOutputStream(java.io.ByteArrayOutputStream)

Example 49 with AlfrescoRuntimeException

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

the class BootstrapTestDataGet method executeImpl.

@Override
public Map<String, Object> executeImpl(WebScriptRequest req, Status status, Cache cache) {
    // resolve import argument
    boolean importData = false;
    if (req.getParameter(ARG_IMPORT) != null) {
        importData = Boolean.parseBoolean(req.getParameter(ARG_IMPORT));
    }
    // resolve rm site
    String siteName = RmSiteType.DEFAULT_SITE_NAME;
    if (req.getParameter(ARG_SITE_NAME) != null) {
        siteName = req.getParameter(ARG_SITE_NAME);
    }
    if (importData) {
        SiteInfo site = siteService.getSite(siteName);
        if (site == null) {
            throw new AlfrescoRuntimeException("Records Management site does not exist: " + siteName);
        }
        // resolve documentLibrary (filePlan) container
        NodeRef filePlan = siteService.getContainer(siteName, RmSiteType.COMPONENT_DOCUMENT_LIBRARY);
        if (filePlan == null) {
            filePlan = siteService.createContainer(siteName, RmSiteType.COMPONENT_DOCUMENT_LIBRARY, TYPE_FILE_PLAN, null);
        }
        // import the RM test data ACP into the the provided filePlan node reference
        InputStream is = BootstrapTestDataGet.class.getClassLoader().getResourceAsStream(XML_IMPORT);
        if (is == null) {
            throw new AlfrescoRuntimeException("The DODExampleFilePlan.xml import file could not be found");
        }
        Reader viewReader = null;
        try {
            viewReader = new InputStreamReader(is, CHARSET_NAME);
        } catch (UnsupportedEncodingException error) {
            throw new AlfrescoRuntimeException("The Character Encoding '" + CHARSET_NAME + "' is not supported.", error);
        }
        Location location = new Location(filePlan);
        importerService.importView(viewReader, location, null, null);
    }
    // Patch data
    BootstrapTestDataGet.patchLoadedData(searchService, nodeService, recordsManagementService, recordsManagementActionService, permissionService, authorityService, recordsManagementSecurityService, recordsManagementSearchBehaviour, dispositionService, recordFolderService);
    Map<String, Object> model = new HashMap<String, Object>(1, 1.0f);
    model.put("success", true);
    return model;
}
Also used : SiteInfo(org.alfresco.service.cmr.site.SiteInfo) InputStreamReader(java.io.InputStreamReader) HashMap(java.util.HashMap) InputStream(java.io.InputStream) Reader(java.io.Reader) InputStreamReader(java.io.InputStreamReader) UnsupportedEncodingException(java.io.UnsupportedEncodingException) NodeRef(org.alfresco.service.cmr.repository.NodeRef) AlfrescoRuntimeException(org.alfresco.error.AlfrescoRuntimeException) Location(org.alfresco.service.cmr.view.Location)

Example 50 with AlfrescoRuntimeException

use of org.alfresco.error.AlfrescoRuntimeException 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)

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