use of org.alfresco.service.cmr.repository.ContentWriter in project records-management by Alfresco.
the class CommonRMTestUtils method createRecord.
/**
* Helper method to create a record in a record folder.
*
* @param recordFolder record folder
* @param name name of record
* @param properties properties of the record
* @param content content of the record
* @return {@link NodeRef} record node reference
*/
public NodeRef createRecord(NodeRef recordFolder, String name, Map<QName, Serializable> properties, String content) {
// Create the record
NodeRef record = createRecordImpl(recordFolder, name, properties);
// Set the content
ContentWriter writer = contentService.getWriter(record, ContentModel.PROP_CONTENT, true);
writer.setMimetype(MimetypeMap.MIMETYPE_TEXT_PLAIN);
writer.setEncoding("UTF-8");
writer.putContent(content);
return record;
}
use of org.alfresco.service.cmr.repository.ContentWriter in project records-management by Alfresco.
the class RMCaveatConfigComponentImpl method updateOrCreateCaveatConfig.
public NodeRef updateOrCreateCaveatConfig(File jsonFile) {
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(jsonFile);
return caveatConfig;
}
use of org.alfresco.service.cmr.repository.ContentWriter in project records-management by Alfresco.
the class RMCaveatConfigComponentImpl method updateOrCreateCaveatConfig.
public NodeRef updateOrCreateCaveatConfig(String jsonString) {
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(jsonString);
return caveatConfig;
}
use of org.alfresco.service.cmr.repository.ContentWriter in project records-management by Alfresco.
the class DeclarativeReportGenerator method generateReportContent.
/**
* @see org.alfresco.module.org_alfresco_module_rm.report.generator.BaseReportGenerator#generateReportContent(NodeRef, String, Map)
*/
@Override
protected ContentReader generateReportContent(NodeRef reportedUponNodeRef, String mimetype, Map<String, Serializable> properties) {
// get the template
NodeRef reportTemplateNodeRef = getReportTemplate(mimetype);
// get the model
Map<String, Serializable> model = createTemplateModel(reportTemplateNodeRef, reportedUponNodeRef, properties);
// run the template
String result = templateService.processTemplate("freemarker", reportTemplateNodeRef.toString(), model);
// create the temp content
ContentWriter contentWriter = contentService.getTempWriter();
contentWriter.setEncoding("UTF-8");
contentWriter.setMimetype(mimetype);
contentWriter.putContent(result);
// return the reader to the temp content
return contentWriter.getReader();
}
use of org.alfresco.service.cmr.repository.ContentWriter in project records-management by Alfresco.
the class RecordServiceImpl method createRecordFromContent.
/**
* @see org.alfresco.module.org_alfresco_module_rm.record.RecordService#createNewRecord(org.alfresco.service.cmr.repository.NodeRef, java.lang.String, org.alfresco.service.namespace.QName, java.util.Map, org.alfresco.service.cmr.repository.ContentReader)
*/
@Override
public NodeRef createRecordFromContent(NodeRef parent, String name, QName type, Map<QName, Serializable> properties, ContentReader reader) {
ParameterCheck.mandatory("nodeRef", parent);
ParameterCheck.mandatory("name", name);
NodeRef result = null;
NodeRef destination = parent;
if (isFilePlan(parent)) {
// get the unfiled record container for the file plan
destination = filePlanService.getUnfiledContainer(parent);
if (destination == null) {
throw new AlfrescoRuntimeException("Unable to create record, because unfiled container could not be found.");
}
}
// if none set the default record type is cm:content
if (type == null) {
type = ContentModel.TYPE_CONTENT;
} else if (!dictionaryService.isSubClass(type, ContentModel.TYPE_CONTENT)) {
throw new AlfrescoRuntimeException("Record can only be created from a sub-type of cm:content.");
}
disablePropertyEditableCheck();
try {
// create the new record
final NodeRef record = fileFolderService.create(destination, name, type).getNodeRef();
// set the properties
if (properties != null) {
nodeService.addProperties(record, properties);
}
// set the content
if (reader != null) {
ContentWriter writer = fileFolderService.getWriter(record);
writer.setEncoding(reader.getEncoding());
writer.setMimetype(reader.getMimetype());
writer.putContent(reader);
}
result = authenticationUtil.runAsSystem(new RunAsWork<NodeRef>() {
public NodeRef doWork() throws Exception {
// a destination for the report has been selected.
if (!nodeService.hasAspect(record, ASPECT_RECORD)) {
// make record
makeRecord(record);
generateRecordIdentifier(nodeService, identifierService, record);
}
return record;
}
});
} finally {
enablePropertyEditableCheck();
}
return result;
}
Aggregations