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;
}
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() + ")");
}
}
}
}
}
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() + ")");
}
}
}
}
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);
}
}
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);
}
}
Aggregations