Search in sources :

Example 1 with ContentService

use of org.alfresco.service.cmr.repository.ContentService in project alfresco-remote-api by Alfresco.

the class RenditionsTest method setup.

@Before
public void setup() throws Exception {
    contentService = applicationContext.getBean("contentService", ContentService.class);
    networkN1 = repoService.createNetworkWithAlias("ping", true);
    networkN1.create();
    userOneN1 = networkN1.createUser();
    setRequestContext(networkN1.getId(), userOneN1.getId(), null);
    String siteTitle = "RandomSite" + System.currentTimeMillis();
    userOneN1Site = createSite(siteTitle, SiteVisibility.PRIVATE);
}
Also used : ContentService(org.alfresco.service.cmr.repository.ContentService) RestApiUtil.toJsonAsString(org.alfresco.rest.api.tests.util.RestApiUtil.toJsonAsString) Before(org.junit.Before)

Example 2 with ContentService

use of org.alfresco.service.cmr.repository.ContentService in project alfresco-remote-api by Alfresco.

the class TestPeople method createAvatarDirect.

private NodeRef createAvatarDirect(NodeRef personRef, File avatarFile) {
    // create new avatar node
    nodeService.addAspect(personRef, ContentModel.ASPECT_PREFERENCES, null);
    ChildAssociationRef assoc = nodeService.createNode(personRef, ContentModel.ASSOC_PREFERENCE_IMAGE, QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, "origAvatar"), ContentModel.TYPE_CONTENT);
    final NodeRef avatarRef = assoc.getChildRef();
    // JSF client compatibility?
    nodeService.createAssociation(personRef, avatarRef, ContentModel.ASSOC_AVATAR);
    // upload the avatar content
    ContentService contentService = applicationContext.getBean("ContentService", ContentService.class);
    ContentWriter writer = contentService.getWriter(avatarRef, ContentModel.PROP_CONTENT, true);
    writer.guessMimetype(avatarFile.getName());
    writer.putContent(avatarFile);
    Rendition avatarR = new Rendition();
    avatarR.setId("avatar");
    Renditions renditions = applicationContext.getBean("Renditions", Renditions.class);
    renditions.createRendition(avatarRef, avatarR, false, null);
    return avatarRef;
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) ContentWriter(org.alfresco.service.cmr.repository.ContentWriter) Rendition(org.alfresco.rest.api.model.Rendition) Renditions(org.alfresco.rest.api.Renditions) ContentService(org.alfresco.service.cmr.repository.ContentService) ChildAssociationRef(org.alfresco.service.cmr.repository.ChildAssociationRef)

Example 3 with ContentService

use of org.alfresco.service.cmr.repository.ContentService in project alfresco-remote-api by Alfresco.

the class PutMethodTest method setUp.

@Before
public void setUp() throws Exception {
    searchService = ctx.getBean("SearchService", SearchService.class);
    fileFolderService = ctx.getBean("FileFolderService", FileFolderService.class);
    nodeService = ctx.getBean("NodeService", NodeService.class);
    transactionService = ctx.getBean("transactionService", TransactionService.class);
    webDAVHelper = ctx.getBean("webDAVHelper", WebDAVHelper.class);
    authenticationService = ctx.getBean("authenticationService", MutableAuthenticationService.class);
    personService = ctx.getBean("PersonService", PersonService.class);
    lockService = ctx.getBean("LockService", LockService.class);
    contentService = ctx.getBean("contentService", ContentService.class);
    checkOutCheckInService = ctx.getBean("CheckOutCheckInService", CheckOutCheckInService.class);
    permissionService = ctx.getBean("PermissionService", PermissionService.class);
    namespaceService = ctx.getBean("namespaceService", NamespaceService.class);
    actionService = ctx.getBean("ActionService", ActionService.class);
    AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getAdminUserName());
    repositoryHelper = (Repository) ctx.getBean("repositoryHelper");
    companyHomeNodeRef = repositoryHelper.getCompanyHome();
    txn = transactionService.getUserTransaction();
    txn.begin();
    createUser(USER1_NAME);
    createUser(USER2_NAME);
    InputStream testDataIS = getClass().getClassLoader().getResourceAsStream(TEST_DATA_FILE_NAME);
    InputStream davLockInfoAdminIS = getClass().getClassLoader().getResourceAsStream(DAV_LOCK_INFO_ADMIN);
    InputStream davLockInfoUser2IS = getClass().getClassLoader().getResourceAsStream(DAV_LOCK_INFO_USER2);
    testDataFile = IOUtils.toByteArray(testDataIS);
    davLockInfoAdminFile = IOUtils.toByteArray(davLockInfoAdminIS);
    davLockInfoUser2File = IOUtils.toByteArray(davLockInfoUser2IS);
    testDataIS.close();
    davLockInfoAdminIS.close();
    davLockInfoUser2IS.close();
    // Create a test file with versionable aspect and content
    Map<QName, Serializable> properties = new HashMap<QName, Serializable>();
    versionableDocName = "doc-" + GUID.generate();
    properties.put(ContentModel.PROP_NAME, versionableDocName);
    versionableDoc = nodeService.createNode(companyHomeNodeRef, ContentModel.ASSOC_CONTAINS, QName.createQName(ContentModel.USER_MODEL_URI, versionableDocName), ContentModel.TYPE_CONTENT, properties).getChildRef();
    contentService.getWriter(versionableDoc, ContentModel.PROP_CONTENT, true).putContent("WebDAVTestContent");
    nodeService.addAspect(versionableDoc, ContentModel.ASPECT_VERSIONABLE, null);
    txn.commit();
    txn = transactionService.getUserTransaction();
    txn.begin();
}
Also used : Serializable(java.io.Serializable) TransactionService(org.alfresco.service.transaction.TransactionService) LockService(org.alfresco.service.cmr.lock.LockService) HashMap(java.util.HashMap) InputStream(java.io.InputStream) QName(org.alfresco.service.namespace.QName) NodeService(org.alfresco.service.cmr.repository.NodeService) PersonService(org.alfresco.service.cmr.security.PersonService) FileFolderService(org.alfresco.service.cmr.model.FileFolderService) ContentService(org.alfresco.service.cmr.repository.ContentService) MutableAuthenticationService(org.alfresco.service.cmr.security.MutableAuthenticationService) PermissionService(org.alfresco.service.cmr.security.PermissionService) CheckOutCheckInService(org.alfresco.service.cmr.coci.CheckOutCheckInService) NamespaceService(org.alfresco.service.namespace.NamespaceService) SearchService(org.alfresco.service.cmr.search.SearchService) ActionService(org.alfresco.service.cmr.action.ActionService) Before(org.junit.Before)

Example 4 with ContentService

use of org.alfresco.service.cmr.repository.ContentService in project alfresco-remote-api by Alfresco.

the class MoveMethod method copyContentOnly.

private void copyContentOnly(FileInfo sourceFileInfo, FileInfo destFileInfo, FileFolderService fileFolderService) throws WebDAVServerException {
    ContentService contentService = getContentService();
    ContentReader reader = contentService.getReader(sourceFileInfo.getNodeRef(), ContentModel.PROP_CONTENT);
    if (reader == null) {
        // There is no content for the node if it is a folder
        if (!sourceFileInfo.isFolder()) {
            // Non-folders should have content available.
            logger.error("Unable to get ContentReader for source node " + sourceFileInfo.getNodeRef());
            throw new WebDAVServerException(HttpServletResponse.SC_NOT_FOUND);
        }
    } else {
        ContentWriter contentWriter = contentService.getWriter(destFileInfo.getNodeRef(), ContentModel.PROP_CONTENT, true);
        contentWriter.putContent(reader);
    }
}
Also used : ContentWriter(org.alfresco.service.cmr.repository.ContentWriter) ContentReader(org.alfresco.service.cmr.repository.ContentReader) ContentService(org.alfresco.service.cmr.repository.ContentService)

Example 5 with ContentService

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

the class EditSearchDialog method saveEditSearchOK.

public String saveEditSearchOK(FacesContext newContext, String newOutcome) {
    String outcome = newOutcome;
    final SearchContext search = this.navigator.getSearchContext();
    if (search != null) {
        try {
            final FacesContext context = newContext;
            RetryingTransactionCallback<Object> callback = new RetryingTransactionCallback<Object>() {

                public Object execute() throws Throwable {
                    // handle Edit e.g. Overwrite of existing search
                    // detect if was previously selected saved search (e.g.
                    // NodeRef not null)
                    NodeRef searchRef = new NodeRef(Repository.getStoreRef(), properties.getSavedSearch());
                    if (getNodeService().exists(searchRef)) {
                        Map<QName, Serializable> props = getNodeService().getProperties(searchRef);
                        props.put(ContentModel.PROP_NAME, properties.getSearchName());
                        props.put(ContentModel.PROP_DESCRIPTION, properties.getSearchDescription());
                        getNodeService().setProperties(searchRef, props);
                        ContentService contentService = Repository.getServiceRegistry(context).getContentService();
                        ContentWriter writer = contentService.getWriter(searchRef, 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) QName(org.alfresco.service.namespace.QName) ContentService(org.alfresco.service.cmr.repository.ContentService) NodeRef(org.alfresco.service.cmr.repository.NodeRef) ContentWriter(org.alfresco.service.cmr.repository.ContentWriter) RetryingTransactionCallback(org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback)

Aggregations

ContentService (org.alfresco.service.cmr.repository.ContentService)18 NodeRef (org.alfresco.service.cmr.repository.NodeRef)12 ContentReader (org.alfresco.service.cmr.repository.ContentReader)9 ContentWriter (org.alfresco.service.cmr.repository.ContentWriter)6 QName (org.alfresco.service.namespace.QName)6 ServiceRegistry (org.alfresco.service.ServiceRegistry)5 NodeService (org.alfresco.service.cmr.repository.NodeService)5 Serializable (java.io.Serializable)4 StringTokenizer (java.util.StringTokenizer)3 FacesContext (javax.faces.context.FacesContext)3 FileInfo (org.alfresco.service.cmr.model.FileInfo)3 ChildAssociationRef (org.alfresco.service.cmr.repository.ChildAssociationRef)3 InputStream (java.io.InputStream)2 SocketException (java.net.SocketException)2 Date (java.util.Date)2 HashMap (java.util.HashMap)2 Locale (java.util.Locale)2 RetryingTransactionCallback (org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback)2 DictionaryService (org.alfresco.service.cmr.dictionary.DictionaryService)2 FileFolderService (org.alfresco.service.cmr.model.FileFolderService)2