Search in sources :

Example 46 with ContentWriter

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

the class SaveSearchDialog method saveNewSearchOK.

public String saveNewSearchOK(FacesContext newContext, String newOutcome) {
    String outcome = newOutcome;
    NodeRef searchesRef;
    if (properties.isSearchSaveGlobal()) {
        searchesRef = getGlobalSearchesRef();
    } else {
        searchesRef = getUserSearchesRef();
    }
    final SearchContext search = this.navigator.getSearchContext();
    if (searchesRef != null && search != null) {
        try {
            // FacesContext.getCurrentInstance();
            final FacesContext context = newContext;
            final NodeRef searchesRefFinal = searchesRef;
            RetryingTransactionCallback<Object> callback = new RetryingTransactionCallback<Object>() {

                public Object execute() throws Throwable {
                    // create new content node as the saved search object
                    Map<QName, Serializable> props = new HashMap<QName, Serializable>(2, 1.0f);
                    props.put(ContentModel.PROP_NAME, properties.getSearchName());
                    props.put(ContentModel.PROP_DESCRIPTION, properties.getSearchDescription());
                    ChildAssociationRef childRef = getNodeService().createNode(searchesRefFinal, ContentModel.ASSOC_CONTAINS, QName.createQName(NamespaceService.ALFRESCO_URI, QName.createValidLocalName(properties.getSearchName())), ContentModel.TYPE_CONTENT, props);
                    ContentService contentService = Repository.getServiceRegistry(context).getContentService();
                    ContentWriter writer = contentService.getWriter(childRef.getChildRef(), ContentModel.PROP_CONTENT, true);
                    // get a writer to our new node ready for XML content
                    writer.setMimetype(MimetypeMap.MIMETYPE_XML);
                    writer.setEncoding("UTF-8");
                    // output an XML serialized version of the SearchContext
                    // object
                    writer.putContent(search.toXML());
                    return null;
                }
            };
            callback.execute();
            properties.getCachedSavedSearches().clear();
            properties.setSavedSearch(null);
        } catch (Throwable e) {
            Utils.addErrorMessage(MessageFormat.format(Application.getMessage(newContext, MSG_ERROR_SAVE_SEARCH), e.getMessage()), e);
            outcome = null;
            this.isFinished = false;
            ReportedException.throwIfNecessary(e);
        }
    }
    return outcome;
}
Also used : FacesContext(javax.faces.context.FacesContext) Serializable(java.io.Serializable) HashMap(java.util.HashMap) QName(org.alfresco.service.namespace.QName) ContentService(org.alfresco.service.cmr.repository.ContentService) ChildAssociationRef(org.alfresco.service.cmr.repository.ChildAssociationRef) NodeRef(org.alfresco.service.cmr.repository.NodeRef) ContentWriter(org.alfresco.service.cmr.repository.ContentWriter) RetryingTransactionCallback(org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback)

Example 47 with ContentWriter

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

the class EditContentWizard method saveContent.

@Override
protected void saveContent(File fileContent, String strContent) throws Exception {
    ContentWriter writer = getContentService().getWriter(nodeRef, ContentModel.PROP_CONTENT, true);
    writer.putContent(strContent);
}
Also used : ContentWriter(org.alfresco.service.cmr.repository.ContentWriter)

Example 48 with ContentWriter

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

the class CreateTopicDialog method finishImpl.

@Override
protected String finishImpl(FacesContext context, String outcome) throws Exception {
    super.finishImpl(context, outcome);
    // do topic specific processing
    // get the node ref of the node that will contain the content
    NodeRef containerNodeRef = this.createdNode;
    // create a unique file name for the message content
    String fileName = ForumsBean.createPostFileName();
    FileInfo fileInfo = this.getFileFolderService().create(containerNodeRef, fileName, ForumModel.TYPE_POST);
    NodeRef postNodeRef = fileInfo.getNodeRef();
    if (logger.isDebugEnabled())
        logger.debug("Created post node with filename: " + fileName);
    // apply the titled aspect - title and description
    Map<QName, Serializable> titledProps = new HashMap<QName, Serializable>(3, 1.0f);
    titledProps.put(ContentModel.PROP_TITLE, fileName);
    this.getNodeService().addAspect(postNodeRef, ContentModel.ASPECT_TITLED, titledProps);
    if (logger.isDebugEnabled())
        logger.debug("Added titled aspect with properties: " + titledProps);
    Map<QName, Serializable> editProps = new HashMap<QName, Serializable>(1, 1.0f);
    editProps.put(ApplicationModel.PROP_EDITINLINE, true);
    this.getNodeService().addAspect(postNodeRef, ApplicationModel.ASPECT_INLINEEDITABLE, editProps);
    if (logger.isDebugEnabled())
        logger.debug("Added inlineeditable aspect with properties: " + editProps);
    // get a writer for the content and put the file
    ContentWriter writer = getContentService().getWriter(postNodeRef, ContentModel.PROP_CONTENT, true);
    // set the mimetype and encoding
    writer.setMimetype(Repository.getMimeTypeForFileName(context, fileName));
    writer.setEncoding("UTF-8");
    writer.putContent(Utils.replaceLineBreaks(this.message, false));
    return outcome;
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) Serializable(java.io.Serializable) ContentWriter(org.alfresco.service.cmr.repository.ContentWriter) FileInfo(org.alfresco.service.cmr.model.FileInfo) HashMap(java.util.HashMap) QName(org.alfresco.service.namespace.QName)

Example 49 with ContentWriter

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

the class SolrContentStoreTest method delete.

@Test
public void delete() throws Exception {
    SolrContentStore store = new SolrContentStore(solrHome);
    ContentContext ctx = createContentContext("abc");
    String url = ctx.getContentUrl();
    ContentWriter writer = store.getWriter(ctx);
    writer.putContent("Content goes here.");
    // Check the reader
    ContentReader reader = store.getReader(url);
    Assert.assertNotNull(reader);
    Assert.assertTrue(reader.exists());
    // Delete
    store.delete(url);
    reader = store.getReader(url);
    Assert.assertNotNull(reader);
    Assert.assertFalse(reader.exists());
    // Delete when already gone; should just not fail
    store.delete(url);
}
Also used : ContentWriter(org.alfresco.service.cmr.repository.ContentWriter) ContentReader(org.alfresco.service.cmr.repository.ContentReader) ContentContext(org.alfresco.repo.content.ContentContext) Test(org.junit.Test)

Example 50 with ContentWriter

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

the class SolrContentStoreTest method contentByStream.

@Test
public void contentByStream() throws Exception {
    SolrContentStore store = new SolrContentStore(solrHome);
    ContentContext ctx = createContentContext("abc");
    ContentWriter writer = store.getWriter(ctx);
    byte[] bytes = new byte[] { 1, 7, 13 };
    ByteArrayInputStream bis = new ByteArrayInputStream(bytes);
    writer.putContent(bis);
    // Now get the reader
    ContentReader reader = store.getReader(ctx.getContentUrl());
    ByteArrayOutputStream bos = new ByteArrayOutputStream(3);
    reader.getContent(bos);
    Assert.assertEquals(bytes[0], bos.toByteArray()[0]);
    Assert.assertEquals(bytes[1], bos.toByteArray()[1]);
    Assert.assertEquals(bytes[2], bos.toByteArray()[2]);
}
Also used : ContentWriter(org.alfresco.service.cmr.repository.ContentWriter) ByteArrayInputStream(java.io.ByteArrayInputStream) ContentReader(org.alfresco.service.cmr.repository.ContentReader) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ContentContext(org.alfresco.repo.content.ContentContext) Test(org.junit.Test)

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