use of org.alfresco.service.cmr.repository.ContentWriter in project records-management by Alfresco.
the class RMv21ReportServicePatch method executePatch.
@Override
protected void executePatch() {
// check whether report dir exists or not
if (nodeService.exists(RM_CONFIG_FOLDER) && !nodeService.exists(TEMPLATE_ROOT)) {
if (LOGGER.isDebugEnabled()) {
LOGGER.debug(" ... adding template root folder");
}
NodeRef reportTemplates = createNode(RM_CONFIG_FOLDER, ContentModel.TYPE_FOLDER, "rm_report_templates", "Records Management Report Templates", "rm_report_templates", "Records Management Report Templates", "Records Management Report Templates");
nodeService.addAspect(reportTemplates, ContentModel.ASPECT_TITLED, null);
nodeService.addAspect(reportTemplates, ContentModel.ASPECT_AUTHOR, null);
if (LOGGER.isDebugEnabled()) {
LOGGER.debug(" ... adding destruction report template");
}
// create report templates
NodeRef destructionTemplate = createNode(TEMPLATE_ROOT, ContentModel.TYPE_CONTENT, "rmr_destructionReport", "report_rmr_destructionReport.html.ftl", "report_rmr_destructionReport.html.ftl", "Destruction Report Template", "Desruction report template.");
nodeService.addAspect(destructionTemplate, ContentModel.ASPECT_TITLED, null);
nodeService.addAspect(destructionTemplate, ContentModel.ASPECT_AUTHOR, null);
// put the content
ContentWriter writer = contentService.getWriter(destructionTemplate, ContentModel.PROP_CONTENT, true);
InputStream is = getClass().getClassLoader().getResourceAsStream(PATH_DESTRUCTION_TEMPLATE);
writer.setEncoding("UTF-8");
writer.setMimetype(MimetypeMap.MIMETYPE_TEXT_PLAIN);
writer.putContent(is);
}
}
use of org.alfresco.service.cmr.repository.ContentWriter in project records-management by Alfresco.
the class RMv22ReportTemplatePatch method applyInternal.
/**
* @see org.alfresco.module.org_alfresco_module_rm.patch.AbstractModulePatch#applyInternal()
*/
@Override
public void applyInternal() {
NodeRef transferReport = new NodeRef(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE, TRANSFER_REPORT);
NodeRef destructionReport = new NodeRef(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE, DESTRUCTION_REPORT);
if (!nodeService.exists(transferReport) && nodeService.exists(destructionReport)) {
NodeRef parent = nodeService.getPrimaryParent(destructionReport).getParentRef();
// get the assoc qname
QName assocQName = QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, QName.createValidLocalName("report_rmr_transferReport.html.ftl"));
// build the node properties
Map<QName, Serializable> props = new HashMap<QName, Serializable>(4);
props.put(ContentModel.PROP_DESCRIPTION, "Transfer report template.");
props.put(ContentModel.PROP_TITLE, "Transfer Report Template");
props.put(ContentModel.PROP_NAME, "report_rmr_transferReport.html.ftl");
props.put(ContentModel.PROP_NODE_UUID, "rmr_transferReport");
// 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(REPORT_TEMPLATE_PATH);
writer.setEncoding("UTF-8");
writer.setMimetype(MimetypeMap.MIMETYPE_TEXT_PLAIN);
writer.putContent(is);
}
}
use of org.alfresco.service.cmr.repository.ContentWriter in project records-management by Alfresco.
the class RecordableVersionsBaseTest method prepareContent.
protected void prepareContent(NodeRef content) {
// add titled aspect
PropertyMap titledProperties = new PropertyMap(2);
titledProperties.put(ContentModel.PROP_TITLE, "document title");
titledProperties.put(ContentModel.PROP_DESCRIPTION, "document description");
nodeService.addAspect(content, ContentModel.ASPECT_TITLED, titledProperties);
// add ownable aspect
PropertyMap ownableProperties = new PropertyMap(1);
ownableProperties.put(ContentModel.PROP_OWNER, OWNER);
nodeService.addAspect(content, ContentModel.ASPECT_OWNABLE, ownableProperties);
// add Dublin core aspect
PropertyMap dublinCoreProperties = new PropertyMap(2);
dublinCoreProperties.put(QNAME_PUBLISHER, PUBLISHER);
dublinCoreProperties.put(QNAME_SUBJECT, SUBJECT);
nodeService.addAspect(content, ContentModel.ASPECT_DUBLINCORE, dublinCoreProperties);
// add content
ContentWriter writer = contentService.getWriter(content, ContentModel.PROP_CONTENT, true);
writer.setEncoding("UTF-8");
writer.setMimetype(MimetypeMap.MIMETYPE_TEXT_PLAIN);
writer.putContent(CONTENT);
}
use of org.alfresco.service.cmr.repository.ContentWriter in project records-management by Alfresco.
the class CreateRecordTest method testCreateRecordCapabilityOnlyFromFileFolderService.
/**
*/
public void testCreateRecordCapabilityOnlyFromFileFolderService() throws Exception {
doBehaviourDrivenTest(new BehaviourDrivenTest() {
/**
* test data
*/
String roleName = GUID.generate();
String user = GUID.generate();
NodeRef recordFolder;
NodeRef record;
public void given() {
// create role
Set<Capability> capabilities = new HashSet<Capability>(2);
capabilities.add(capabilityService.getCapability("ViewRecords"));
capabilities.add(capabilityService.getCapability("CreateRecords"));
filePlanRoleService.createRole(filePlan, roleName, roleName, capabilities);
// create user and assign to role
createPerson(user, true);
filePlanRoleService.assignRoleToAuthority(filePlan, roleName, user);
// create file plan structure
NodeRef rc = filePlanService.createRecordCategory(filePlan, GUID.generate());
recordFolder = recordFolderService.createRecordFolder(rc, GUID.generate());
}
public void when() {
// give read and file permissions to user
filePlanPermissionService.setPermission(recordFolder, user, RMPermissionModel.FILING);
AuthenticationUtil.runAs(new RunAsWork<Void>() {
public Void doWork() throws Exception {
record = fileFolderService.create(recordFolder, GUID.generate(), ContentModel.TYPE_CONTENT).getNodeRef();
ContentWriter writer = contentService.getWriter(record, ContentModel.TYPE_CONTENT, true);
writer.setMimetype(MimetypeMap.MIMETYPE_TEXT_PLAIN);
writer.setEncoding("UTF-8");
writer.putContent("Lucy Wetherall");
return null;
}
}, user);
}
public void then() {
// check the details of the record
assertTrue(recordService.isRecord(record));
}
});
}
use of org.alfresco.service.cmr.repository.ContentWriter in project records-management by Alfresco.
the class RejectRecordTest method testRevertAfterReject.
/**
*/
public void testRevertAfterReject() throws Exception {
doBehaviourDrivenTest(new BehaviourDrivenTest() {
private NodeRef document;
public void given() {
NodeRef folder = fileFolderService.create(documentLibrary, GUID.generate(), TYPE_FOLDER).getNodeRef();
document = fileFolderService.create(folder, GUID.generate(), TYPE_CONTENT).getNodeRef();
assertFalse(recordService.isRecord(document));
ownableService.setOwner(document, userName);
versionService.ensureVersioningEnabled(document, null);
// document is declared as a record by user
AuthenticationUtil.runAs(new RunAsWork<Void>() {
public Void doWork() throws Exception {
// declare record
recordService.createRecord(filePlan, document);
return null;
}
}, userName);
assertTrue(nodeService.hasAspect(document, ASPECT_FILE_PLAN_COMPONENT));
}
public void when() {
// reject the record
recordService.rejectRecord(document, REASON);
assertFalse(nodeService.hasAspect(document, ASPECT_FILE_PLAN_COMPONENT));
// upload a new version of the document
AuthenticationUtil.runAs(new RunAsWork<Void>() {
public Void doWork() throws Exception {
ContentWriter writer = contentService.getWriter(document, ContentModel.PROP_CONTENT, true);
writer.putContent("This is a change to the content and should force a new version");
versionService.createVersion(document, null);
return null;
}
}, userName);
assertFalse(nodeService.hasAspect(document, ASPECT_FILE_PLAN_COMPONENT));
VersionHistory history = versionService.getVersionHistory(document);
assertEquals(2, history.getAllVersions().size());
final Version initial = history.getRootVersion();
assertFalse(nodeService.hasAspect(initial.getFrozenStateNodeRef(), ASPECT_FILE_PLAN_COMPONENT));
AuthenticationUtil.runAs(new RunAsWork<Void>() {
public Void doWork() throws Exception {
// revert the document to a previous version
versionService.revert(document, initial);
return null;
}
}, userName);
}
public void then() {
// document is no longer a record
assertFalse(recordService.isRecord(document));
// expected owner has be re-set
assertEquals(userName, ownableService.getOwner(document));
}
});
}
Aggregations