Search in sources :

Example 26 with ContentWriter

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

the class RMCaveatConfigComponentImpl method updateOrCreateCaveatConfig.

public NodeRef updateOrCreateCaveatConfig(InputStream is) {
    NodeRef caveatConfig = getOrCreateCaveatConfig();
    // Update the content
    ContentWriter writer = this.contentService.getWriter(caveatConfig, ContentModel.PROP_CONTENT, true);
    writer.setMimetype(MimetypeMap.MIMETYPE_TEXT_PLAIN);
    writer.setEncoding("UTF-8");
    writer.putContent(is);
    return caveatConfig;
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) ContentWriter(org.alfresco.service.cmr.repository.ContentWriter)

Example 27 with ContentWriter

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

the class RMv2SavedSearchPatch method executePatch.

/**
 * @see org.alfresco.repo.module.AbstractModuleComponent#executeInternal()
 */
@Override
protected void executePatch() {
    if (siteService.getSite(DEFAULT_SITE_NAME) != null) {
        // get the saved searches
        List<SavedSearchDetails> savedSearches = recordsManagementSearchService.getSavedSearches(DEFAULT_SITE_NAME);
        if (LOGGER.isDebugEnabled()) {
            LOGGER.debug("  ... updating " + savedSearches.size() + " saved searches");
        }
        for (SavedSearchDetails savedSearchDetails : savedSearches) {
            // refresh the query
            String refreshedJSON = savedSearchDetails.toJSONString();
            NodeRef nodeRef = savedSearchDetails.getNodeRef();
            if (nodeRef != null) {
                ContentWriter writer = contentService.getWriter(nodeRef, ContentModel.PROP_CONTENT, true);
                writer.putContent(refreshedJSON);
                if (LOGGER.isDebugEnabled()) {
                    LOGGER.debug("    ... updated saved search " + savedSearchDetails.getName() + " (nodeRef=" + nodeRef.toString() + ")");
                }
            }
        }
    }
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) ContentWriter(org.alfresco.service.cmr.repository.ContentWriter) SavedSearchDetails(org.alfresco.module.org_alfresco_module_rm.search.SavedSearchDetails)

Example 28 with ContentWriter

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

the class NotificationTemplatePatch method updateTemplate.

/**
 * Attempt to update the template with the updated version
 *
 * @param template
 * @param updatedTemplate
 */
private void updateTemplate(NodeRef template, String templateUpdate) {
    if (template == null || !nodeService.exists(template)) {
        if (LOGGER.isDebugEnabled()) {
            LOGGER.debug("Skipping template update, because template has not been bootstraped.");
        }
    } else {
        // Check to see if this template has already been updated
        String lastPatchUpdate = (String) nodeService.getProperty(template, PROP_LAST_PATCH_UPDATE);
        if (lastPatchUpdate == null || !name.equals(lastPatchUpdate)) {
            if (LOGGER.isDebugEnabled()) {
                LOGGER.debug("Applying update to template. (template=" + template.toString() + ", templateUpdate=" + templateUpdate + ")");
            }
            // Make sure the template is versionable
            if (!nodeService.hasAspect(template, ContentModel.ASPECT_VERSIONABLE)) {
                nodeService.addAspect(template, ContentModel.ASPECT_VERSIONABLE, null);
                // Create version (before template is updated)
                Map<String, Serializable> versionProperties = new HashMap<String, Serializable>(2);
                versionProperties.put(Version.PROP_DESCRIPTION, "Initial version");
                versionProperties.put(VersionModel.PROP_VERSION_TYPE, VersionType.MINOR);
                versionService.createVersion(template, versionProperties);
            }
            // Update the content of the template
            InputStream is = getClass().getClassLoader().getResourceAsStream(templateUpdate);
            ContentWriter writer = contentService.getWriter(template, ContentModel.PROP_CONTENT, true);
            writer.putContent(is);
            boolean enabled = auditService.isAuditEnabled();
            auditService.setAuditEnabled(false);
            try {
                // Set the last patch update property
                nodeService.setProperty(template, PROP_LAST_PATCH_UPDATE, name);
            } finally {
                auditService.setAuditEnabled(enabled);
            }
        } else {
            if (LOGGER.isDebugEnabled()) {
                LOGGER.debug("Skipping template update, because template has already been patched. (template=" + template.toString() + ")");
            }
        }
    }
}
Also used : Serializable(java.io.Serializable) ContentWriter(org.alfresco.service.cmr.repository.ContentWriter) HashMap(java.util.HashMap) InputStream(java.io.InputStream)

Example 29 with ContentWriter

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

the class NotificationTemplatePatch_v21 method executePatch.

@Override
protected void executePatch() {
    NodeRef nodeRef = new NodeRef(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE, CONFIG_NODEID);
    // get the parent node
    NodeRef supersededTemplate = notificationHelper.getSupersededTemplate();
    if (!nodeService.exists(nodeRef) && nodeService.exists(supersededTemplate)) {
        NodeRef parent = nodeService.getPrimaryParent(supersededTemplate).getParentRef();
        // build the node properties
        Map<QName, Serializable> props = new HashMap<QName, Serializable>(4);
        props.put(ContentModel.PROP_DESCRIPTION, "Record superseded email template.");
        props.put(ContentModel.PROP_TITLE, "record-rejected-email.ftl");
        props.put(ContentModel.PROP_NAME, "record-rejected-email.ftl");
        props.put(ContentModel.PROP_NODE_UUID, "record_rejected_template");
        // get the assoc qname
        QName assocQName = QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, QName.createValidLocalName("record-rejected-email.ftl"));
        // create the node
        ChildAssociationRef node = nodeService.createNode(parent, ContentModel.ASSOC_CONTAINS, assocQName, ContentModel.TYPE_CONTENT, props);
        // put the content
        ContentWriter writer = contentService.getWriter(node.getChildRef(), ContentModel.PROP_CONTENT, true);
        InputStream is = getClass().getClassLoader().getResourceAsStream(PATH_REJECTED);
        writer.putContent(is);
    }
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) Serializable(java.io.Serializable) ContentWriter(org.alfresco.service.cmr.repository.ContentWriter) HashMap(java.util.HashMap) QName(org.alfresco.service.namespace.QName) InputStream(java.io.InputStream) ChildAssociationRef(org.alfresco.service.cmr.repository.ChildAssociationRef)

Example 30 with ContentWriter

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

the class RMv22HoldReportPatch method applyInternal.

/**
 * @see org.alfresco.module.org_alfresco_module_rm.patch.AbstractModulePatch#applyInternal()
 */
@Override
public void applyInternal() {
    if (!nodeService.exists(REPORT)) {
        // get the assoc qname
        QName assocQName = QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, QName.createValidLocalName("report_rmr_holdReport.html.ftl"));
        // build the node properties
        Map<QName, Serializable> props = new HashMap<QName, Serializable>(4);
        props.put(ContentModel.PROP_DESCRIPTION, "Hold report template.");
        props.put(ContentModel.PROP_TITLE, "Hold Report Template");
        props.put(ContentModel.PROP_NAME, "report_rmr_holdReport.html.ftl");
        props.put(ContentModel.PROP_NODE_UUID, "rmr_holdReport");
        // create the node
        ChildAssociationRef node = nodeService.createNode(REPORT_FOLDER, ContentModel.ASSOC_CONTAINS, assocQName, ContentModel.TYPE_CONTENT, props);
        // put the content
        ContentWriter writer = contentService.getWriter(node.getChildRef(), ContentModel.PROP_CONTENT, true);
        writer.setEncoding("UTF-8");
        writer.setMimetype(MimetypeMap.MIMETYPE_TEXT_PLAIN);
        InputStream is = getClass().getClassLoader().getResourceAsStream(REPORT_TEMPLATE_PATH);
        writer.putContent(is);
    }
}
Also used : Serializable(java.io.Serializable) ContentWriter(org.alfresco.service.cmr.repository.ContentWriter) HashMap(java.util.HashMap) QName(org.alfresco.service.namespace.QName) InputStream(java.io.InputStream) ChildAssociationRef(org.alfresco.service.cmr.repository.ChildAssociationRef)

Aggregations

ContentWriter (org.alfresco.service.cmr.repository.ContentWriter)76 NodeRef (org.alfresco.service.cmr.repository.NodeRef)50 HashMap (java.util.HashMap)31 Serializable (java.io.Serializable)22 QName (org.alfresco.service.namespace.QName)21 ContentReader (org.alfresco.service.cmr.repository.ContentReader)20 Test (org.junit.Test)18 FileContentWriter (org.alfresco.repo.content.filestore.FileContentWriter)14 InputStream (java.io.InputStream)13 AlfrescoDocument (org.alfresco.cmis.client.AlfrescoDocument)13 AlfrescoFolder (org.alfresco.cmis.client.AlfrescoFolder)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