Search in sources :

Example 51 with ContentReader

use of org.alfresco.service.cmr.repository.ContentReader in project records-management by Alfresco.

the class RecordsManagementSearchServiceImpl method getSavedSearch.

/**
 * @see org.alfresco.module.org_alfresco_module_rm.search.RecordsManagementSearchService#getSavedSearch(java.lang.String, java.lang.String)
 */
@Override
public SavedSearchDetails getSavedSearch(String siteId, String name) {
    // check for mandatory parameters
    ParameterCheck.mandatory("siteId", siteId);
    ParameterCheck.mandatory("name", name);
    SavedSearchDetails result = null;
    // get the saved search node
    NodeRef searchNode = getSearchNodeRef(siteId, name);
    if (searchNode != null) {
        // get the json content
        ContentReader reader = fileFolderService.getReader(searchNode);
        String jsonString = reader.getContentString();
        // create the saved search details
        result = SavedSearchDetails.createFromJSON(jsonString, namespaceService, this, searchNode);
    }
    return result;
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) ContentReader(org.alfresco.service.cmr.repository.ContentReader)

Example 52 with ContentReader

use of org.alfresco.service.cmr.repository.ContentReader in project records-management by Alfresco.

the class ApplyFixMob1573Get method readCustomContentModel.

private M2Model readCustomContentModel() {
    ContentReader reader = contentService.getReader(RM_CUSTOM_MODEL_NODE_REF, ContentModel.TYPE_CONTENT);
    if (!reader.exists()) {
        throw new AlfrescoRuntimeException("RM CustomModel has no content.");
    }
    InputStream contentIn = null;
    M2Model deserializedModel = null;
    try {
        contentIn = reader.getContentInputStream();
        deserializedModel = M2Model.createModel(contentIn);
    } finally {
        try {
            if (contentIn != null) {
                contentIn.close();
            }
        } catch (IOException ignored) {
        // Intentionally empty.
        }
    }
    return deserializedModel;
}
Also used : InputStream(java.io.InputStream) ContentReader(org.alfresco.service.cmr.repository.ContentReader) M2Model(org.alfresco.repo.dictionary.M2Model) AlfrescoRuntimeException(org.alfresco.error.AlfrescoRuntimeException) IOException(java.io.IOException)

Example 53 with ContentReader

use of org.alfresco.service.cmr.repository.ContentReader in project records-management by Alfresco.

the class SplitEmailAction method executeImpl.

/**
 * @see org.alfresco.repo.action.executer.ActionExecuterAbstractBase#executeImpl(org.alfresco.service.cmr.action.Action,
 *      org.alfresco.service.cmr.repository.NodeRef)
 */
@Override
protected void executeImpl(Action action, NodeRef actionedUponNodeRef) {
    // get node type
    getNodeService().getType(actionedUponNodeRef);
    if (logger.isDebugEnabled()) {
        logger.debug("split email:" + actionedUponNodeRef);
    }
    if (getRecordService().isRecord(actionedUponNodeRef)) {
        if (!getRecordService().isDeclared(actionedUponNodeRef)) {
            ChildAssociationRef parent = getNodeService().getPrimaryParent(actionedUponNodeRef);
            /**
             * Check whether the email message has already been split - do nothing if it has already been split
             */
            List<AssociationRef> refs = getNodeService().getTargetAssocs(actionedUponNodeRef, ImapModel.ASSOC_IMAP_ATTACHMENT);
            if (refs.size() > 0) {
                if (logger.isDebugEnabled()) {
                    logger.debug("mail message has already been split - do nothing");
                }
                return;
            }
            /**
             * Get the content and if its a mime message then create atachments for each part
             */
            try {
                ContentReader reader = getContentService().getReader(actionedUponNodeRef, ContentModel.PROP_CONTENT);
                InputStream is = reader.getContentInputStream();
                MimeMessage mimeMessage = new MimeMessage(null, is);
                Object content = mimeMessage.getContent();
                if (content instanceof Multipart) {
                    Multipart multipart = (Multipart) content;
                    for (int i = 0, n = multipart.getCount(); i < n; i++) {
                        Part part = multipart.getBodyPart(i);
                        if ("attachment".equalsIgnoreCase(part.getDisposition())) {
                            createAttachment(actionedUponNodeRef, parent.getParentRef(), part);
                        }
                    }
                }
            } catch (Exception e) {
                throw new AlfrescoRuntimeException(I18NUtil.getMessage(MSG_NO_READ_MIME_MESSAGE, e.toString()), e);
            }
        } else {
            throw new AlfrescoRuntimeException(I18NUtil.getMessage(MSG_EMAIL_DECLARED, actionedUponNodeRef.toString()));
        }
    } else {
        throw new AlfrescoRuntimeException(I18NUtil.getMessage(MSG_EMAIL_NOT_RECORD, actionedUponNodeRef.toString()));
    }
}
Also used : Multipart(javax.mail.Multipart) MimeMessage(javax.mail.internet.MimeMessage) InputStream(java.io.InputStream) Part(javax.mail.Part) ContentReader(org.alfresco.service.cmr.repository.ContentReader) AlfrescoRuntimeException(org.alfresco.error.AlfrescoRuntimeException) ChildAssociationRef(org.alfresco.service.cmr.repository.ChildAssociationRef) AssociationRef(org.alfresco.service.cmr.repository.AssociationRef) ChildAssociationRef(org.alfresco.service.cmr.repository.ChildAssociationRef) MessagingException(javax.mail.MessagingException) IOException(java.io.IOException) AlfrescoRuntimeException(org.alfresco.error.AlfrescoRuntimeException) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Aggregations

ContentReader (org.alfresco.service.cmr.repository.ContentReader)53 NodeRef (org.alfresco.service.cmr.repository.NodeRef)25 ContentWriter (org.alfresco.service.cmr.repository.ContentWriter)20 Test (org.junit.Test)17 HashMap (java.util.HashMap)16 AlfrescoDocument (org.alfresco.cmis.client.AlfrescoDocument)13 AlfrescoFolder (org.alfresco.cmis.client.AlfrescoFolder)13 FileContentWriter (org.alfresco.repo.content.filestore.FileContentWriter)13 VersionableAspectTest (org.alfresco.repo.version.VersionableAspectTest)13 TestNetwork (org.alfresco.rest.api.tests.RepoService.TestNetwork)13 CmisSession (org.alfresco.rest.api.tests.client.PublicApiClient.CmisSession)13 RequestContext (org.alfresco.rest.api.tests.client.RequestContext)13 ContentStreamImpl (org.apache.chemistry.opencmis.commons.impl.dataobjects.ContentStreamImpl)13 TestPerson (org.alfresco.rest.api.tests.RepoService.TestPerson)12 CmisUpdateConflictException (org.apache.chemistry.opencmis.commons.exceptions.CmisUpdateConflictException)12 PublicApiException (org.alfresco.rest.api.tests.client.PublicApiException)11 CmisConstraintException (org.apache.chemistry.opencmis.commons.exceptions.CmisConstraintException)11 CmisInvalidArgumentException (org.apache.chemistry.opencmis.commons.exceptions.CmisInvalidArgumentException)11 CmisObjectNotFoundException (org.apache.chemistry.opencmis.commons.exceptions.CmisObjectNotFoundException)11 CmisPermissionDeniedException (org.apache.chemistry.opencmis.commons.exceptions.CmisPermissionDeniedException)11