Search in sources :

Example 66 with ContentWriter

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;
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) ContentWriter(org.alfresco.service.cmr.repository.ContentWriter)

Example 67 with ContentWriter

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;
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) ContentWriter(org.alfresco.service.cmr.repository.ContentWriter)

Example 68 with ContentWriter

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;
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) ContentWriter(org.alfresco.service.cmr.repository.ContentWriter)

Example 69 with ContentWriter

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();
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) Serializable(java.io.Serializable) ContentWriter(org.alfresco.service.cmr.repository.ContentWriter)

Example 70 with ContentWriter

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;
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) ContentWriter(org.alfresco.service.cmr.repository.ContentWriter) RunAsWork(org.alfresco.repo.security.authentication.AuthenticationUtil.RunAsWork) AlfrescoRuntimeException(org.alfresco.error.AlfrescoRuntimeException)

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