Search in sources :

Example 21 with ContentReader

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

the class CustomEmailMappingServiceImpl method loadConfig.

/**
 * Loads the custom mappings from the configuration file.
 *
 * @return
 */
private Set<CustomMapping> loadConfig() {
    Set<CustomMapping> result = new HashSet<CustomMapping>();
    ContentReader cr = contentService.getReader(CONFIG_NODE_REF, ContentModel.PROP_CONTENT);
    if (cr != null) {
        String text = cr.getContentString();
        try {
            JSONArray jsonArray = new JSONArray(new JSONTokener(text));
            for (int i = 0; i < jsonArray.length(); i++) {
                JSONObject obj = jsonArray.getJSONObject(i);
                CustomMapping mapping = new CustomMapping();
                mapping.setFrom(obj.getString("from"));
                mapping.setTo(obj.getString("to"));
                result.add(mapping);
            }
        } catch (JSONException je) {
            throw new AlfrescoRuntimeException("Unable to read custom email configuration", je);
        }
    }
    return result;
}
Also used : JSONTokener(org.json.JSONTokener) JSONObject(org.json.JSONObject) ContentReader(org.alfresco.service.cmr.repository.ContentReader) JSONArray(org.json.JSONArray) JSONException(org.json.JSONException) AlfrescoRuntimeException(org.alfresco.error.AlfrescoRuntimeException) HashSet(java.util.HashSet)

Example 22 with ContentReader

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

the class EagerContentStoreCleaner method cleanseContent.

/**
 * Cleanse content
 *
 * @param contentUrl    content url
 * @param store         content store
 */
private void cleanseContent(String contentUrl, ContentStore store) {
    if (contentCleanser == null) {
        logger.error("No content cleanser specified.  Unable to cleanse: \n" + "   URL:    " + contentUrl + "\n" + "   Source: " + store);
    } else {
        // First check if the content is present at all
        ContentReader reader = store.getReader(contentUrl);
        if (reader != null && reader.exists()) {
            // Call to implementation's shred
            if (logger.isDebugEnabled()) {
                logger.debug("About to cleanse: \n" + "   URL:    " + contentUrl + "\n" + "   Source: " + store);
            }
            try {
                if (reader instanceof FileContentReader) {
                    // get file content
                    FileContentReader fileReader = (FileContentReader) reader;
                    File file = fileReader.getFile();
                    // cleanse content
                    contentCleanser.cleanse(file);
                }
            } catch (Exception e) {
                logger.error("Content cleansing failed: \n" + "   URL:    " + contentUrl + "\n" + "   Source: " + store + "\n" + "   Reader: " + reader, e);
            }
        } else {
            logger.error("Content no longer exists.  Unable to cleanse: \n" + "   URL:    " + contentUrl + "\n" + "   Source: " + store);
        }
    }
}
Also used : FileContentReader(org.alfresco.repo.content.filestore.FileContentReader) FileContentReader(org.alfresco.repo.content.filestore.FileContentReader) ContentReader(org.alfresco.service.cmr.repository.ContentReader) File(java.io.File)

Example 23 with ContentReader

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

the class ApplyDodCertModelFixesGet method readCustomContentModel.

private M2Model readCustomContentModel() {
    ContentReader reader = this.contentService.getReader(RM_CUSTOM_MODEL_NODE_REF, ContentModel.TYPE_CONTENT);
    if (!reader.exists()) {
        throw new AlfrescoRuntimeException("RM CustomModel has no content.");
    }
    InputStream contentIn = null;
    M2Model deserializedModel = null;
    try {
        contentIn = reader.getContentInputStream();
        deserializedModel = M2Model.createModel(contentIn);
    } finally {
        try {
            if (contentIn != null) {
                contentIn.close();
            }
        } catch (IOException ignored) {
        // Intentionally empty.`
        }
    }
    return deserializedModel;
}
Also used : InputStream(java.io.InputStream) ContentReader(org.alfresco.service.cmr.repository.ContentReader) M2Model(org.alfresco.repo.dictionary.M2Model) AlfrescoRuntimeException(org.alfresco.error.AlfrescoRuntimeException) IOException(java.io.IOException)

Example 24 with ContentReader

use of org.alfresco.service.cmr.repository.ContentReader in project SearchServices by Alfresco.

the class SolrContentStoreTest method contentByString.

@Test
public void contentByString() {
    SolrContentStore store = new SolrContentStore(solrHome);
    ContentContext ctx = createContentContext("abc");
    ContentWriter writer = store.getWriter(ctx);
    File file = new File(store.getRootLocation() + "/" + writer.getContentUrl().replace("solr://", ""));
    Assert.assertFalse("File was created before anything was written", file.exists());
    String content = "Quick brown fox jumps over the lazy dog.";
    writer.putContent(content);
    Assert.assertTrue("File was not created.", file.exists());
    try {
        writer.putContent("Should not work");
    } catch (IllegalStateException e) {
    // Expected
    }
    // Now get the reader
    ContentReader reader = store.getReader(ctx.getContentUrl());
    Assert.assertNotNull(reader);
    Assert.assertTrue(reader.exists());
    Assert.assertEquals(content, reader.getContentString());
}
Also used : ContentWriter(org.alfresco.service.cmr.repository.ContentWriter) ContentReader(org.alfresco.service.cmr.repository.ContentReader) ContentContext(org.alfresco.repo.content.ContentContext) File(java.io.File) Test(org.junit.Test)

Example 25 with ContentReader

use of org.alfresco.service.cmr.repository.ContentReader in project acs-community-packaging by Alfresco.

the class AddContentDialog method finishImpl.

// ------------------------------------------------------------------------------
// Dialog implementation
@Override
protected String finishImpl(FacesContext context, String outcome) throws Exception {
    // Try and extract metadata from the file
    ContentReader cr = new FileContentReader(this.file);
    cr.setMimetype(this.mimeType);
    cr.setEncoding(this.encoding);
    // create properties for content type
    Map<QName, Serializable> contentProps = new HashMap<QName, Serializable>(5, 1.0f);
    if (Repository.extractMetadata(FacesContext.getCurrentInstance(), cr, contentProps)) {
        this.author = (String) (contentProps.get(ContentModel.PROP_AUTHOR));
        this.title = DefaultTypeConverter.INSTANCE.convert(String.class, contentProps.get(ContentModel.PROP_TITLE));
        this.description = DefaultTypeConverter.INSTANCE.convert(String.class, contentProps.get(ContentModel.PROP_DESCRIPTION));
    }
    // default the title to the file name if not set
    if (this.title == null) {
        this.title = this.fileName;
    }
    // determine whether inline editing should be enabled by default.
    // if the mime type of the added file is in the list of mime types
    // configured in "Content Wizards" then enable inline editing
    List<String> mimeTypes = getInlineEditableMimeTypes();
    if (mimeTypes.contains(this.mimeType)) {
        this.inlineEdit = true;
    }
    saveContent(this.file, null);
    // return default outcome
    return outcome;
}
Also used : Serializable(java.io.Serializable) FileContentReader(org.alfresco.repo.content.filestore.FileContentReader) HashMap(java.util.HashMap) QName(org.alfresco.service.namespace.QName) FileContentReader(org.alfresco.repo.content.filestore.FileContentReader) ContentReader(org.alfresco.service.cmr.repository.ContentReader)

Aggregations

ContentReader (org.alfresco.service.cmr.repository.ContentReader)53 NodeRef (org.alfresco.service.cmr.repository.NodeRef)25 ContentWriter (org.alfresco.service.cmr.repository.ContentWriter)20 Test (org.junit.Test)17 HashMap (java.util.HashMap)16 AlfrescoDocument (org.alfresco.cmis.client.AlfrescoDocument)13 AlfrescoFolder (org.alfresco.cmis.client.AlfrescoFolder)13 FileContentWriter (org.alfresco.repo.content.filestore.FileContentWriter)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 CmisInvalidArgumentException (org.apache.chemistry.opencmis.commons.exceptions.CmisInvalidArgumentException)11 CmisObjectNotFoundException (org.apache.chemistry.opencmis.commons.exceptions.CmisObjectNotFoundException)11 CmisPermissionDeniedException (org.apache.chemistry.opencmis.commons.exceptions.CmisPermissionDeniedException)11