Java Code Examples for org.alfresco.service.cmr.repository.ContentService

The following examples show how to use org.alfresco.service.cmr.repository.ContentService. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may want to check out the right sidebar which shows the related API usage.
Example 1
@Before
public void setUp(){
    commentsImpl = new CommentsImpl();
    nodes = mock(Nodes.class);
    typeConstraint = mock(TypeConstraint.class);
    commentService = mock(CommentService.class);
    nodeService = mock(NodeService.class);
    contentService = mock(ContentService.class);
    people = mock(People.class);

    commentsImpl.setNodes(nodes);
    commentsImpl.setTypeConstraint(typeConstraint);
    commentsImpl.setCommentService(commentService);
    commentsImpl.setNodeService(nodeService);
    commentsImpl.setContentService(contentService);
    commentsImpl.setPeople(people);
}
 
Example 2
@SuppressWarnings("deprecation")
@Before
public void before() throws Exception
{
    // Get a reference to the node service
    this.nodeService = (NodeService) this.applicationContext.getBean("nodeService");
    this.contentService = (ContentService) this.applicationContext.getBean("contentService");
    this.authenticationService = (MutableAuthenticationService) this.applicationContext.getBean("authenticationService");
    this.actionService = (ActionService)this.applicationContext.getBean("actionService");
    this.transactionService = (TransactionService)this.applicationContext.getBean("transactionComponent");

    // Authenticate as the system user
    authenticationComponent = (AuthenticationComponent) this.applicationContext
            .getBean("authenticationComponent");
    authenticationComponent.setSystemUserAsCurrentUser();
    
    // Create the store and get the root node
    this.storeRef = this.nodeService.createStore(StoreRef.PROTOCOL_WORKSPACE, "Test_" + System.currentTimeMillis());
    this.rootNodeRef = this.nodeService.getRootNode(this.storeRef);
}
 
Example 3
@Override
protected void setUp() throws Exception
{
    super.setUp();
    
    repoAdminService = (RepoAdminService) ctx.getBean("RepoAdminService");
    dictionaryService = (DictionaryService) ctx.getBean("DictionaryService");
    transactionService = (TransactionService) ctx.getBean("TransactionService");
    nodeService = (NodeService) ctx.getBean("NodeService");
    contentService = (ContentService) ctx.getBean("ContentService");
    searchService = (SearchService) ctx.getBean("SearchService");
    namespaceService = (NamespaceService) ctx.getBean("NamespaceService");
    behaviourFilter = (BehaviourFilter)ctx.getBean("policyBehaviourFilter");
    dictionaryDAO = (DictionaryDAO) ctx.getBean("dictionaryDAO");
    
    DbNodeServiceImpl dbNodeService = (DbNodeServiceImpl)ctx.getBean("dbNodeService");
    dbNodeService.setEnableTimestampPropagation(false);
    
    AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getAdminUserName());
}
 
Example 4
@Override
public void setUp() throws Exception
{
    this.nodeService = (NodeService) ctx.getBean("nodeService");
    this.contentService = (ContentService) ctx.getBean("ContentService");

    this.retryingTransactionHelper = (RetryingTransactionHelper) ctx.getBean("retryingTransactionHelper");

    retryingTransactionHelper.doInTransaction(new RetryingTransactionCallback<Object>()
    {
        @Override
        public Object execute() throws Throwable
        {
            // As system user
            AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getSystemUserName());

            storeRef = StoreRef.STORE_REF_WORKSPACE_SPACESSTORE;

            rootNodeRef = nodeService.getRootNode(storeRef);

            return null;
        }
    });
}
 
Example 5
@Override
protected void setUp() throws Exception
{
    applicationContext = ApplicationContextHelper.getApplicationContext();
    if (AlfrescoTransactionSupport.getTransactionReadState() != TxnReadState.TXN_NONE)
    {
        fail("Detected a leaked transaction from a previous test.");
    }
    
    // Get the services by name from the application context
    messageService = (MessageService)applicationContext.getBean("messageService");
    nodeService = (NodeService)applicationContext.getBean("NodeService");
    authenticationService = (MutableAuthenticationService)applicationContext.getBean("AuthenticationService");
    contentService = (ContentService) applicationContext.getBean("ContentService");
    transactionService = (TransactionService) applicationContext.getBean("transactionComponent");
    authenticationComponent = (AuthenticationComponent) applicationContext.getBean("authenticationComponent");
    dictionaryDAO = (DictionaryDAO) applicationContext.getBean("dictionaryDAO");
    
    // Re-set the current locale to be the default
    Locale.setDefault(Locale.ENGLISH);
    messageService.setLocale(Locale.getDefault());
    
    testTX = transactionService.getUserTransaction();
    testTX.begin();
    authenticationComponent.setSystemUserAsCurrentUser();
}
 
Example 6
/**
 * Called at the beginning of all tests
 */
@Before
protected void before() throws Exception
{
    this.checkOutCheckInService = (CheckOutCheckInService) this.applicationContext.getBean("checkOutCheckInService");
    this.nodeService = (NodeService)this.applicationContext.getBean("nodeService");
    this.ruleService = (RuleService)this.applicationContext.getBean("ruleService");
    this.actionService = (ActionService)this.applicationContext.getBean("actionService");
    transactionHelper = (RetryingTransactionHelper)applicationContext.getBean("retryingTransactionHelper");
    fileFolderService = applicationContext.getBean("fileFolderService", FileFolderService.class);
    contentService = applicationContext.getBean("contentService", ContentService.class);
    
    AuthenticationComponent authenticationComponent = (AuthenticationComponent)applicationContext.getBean("authenticationComponent");
    authenticationComponent.setCurrentUser(authenticationComponent.getSystemUserName());
    
    // Create the store and get the root node
    this.testStoreRef = this.nodeService.createStore(
            StoreRef.PROTOCOL_WORKSPACE, "Test_"
                    + System.currentTimeMillis());
    this.rootNodeRef = this.nodeService.getRootNode(this.testStoreRef);

    // Get the executer instance 
    this.executer = (ExecuteAllRulesActionExecuter)this.applicationContext.getBean(ExecuteAllRulesActionExecuter.NAME);
}
 
Example 7
/**
 * Delete the content stream
 */
public void delete()
{
    ContentService contentService = services.getContentService();
    ContentWriter writer = contentService.getWriter(nodeRef, this.property, true);
    OutputStream output = writer.getContentOutputStream();
    try
    {
        output.close();
    }
    catch (IOException e)
    {
        // NOTE: fall-through
    }
    writer.setMimetype(null);
    writer.setEncoding(null);
    
    // update cached variables after putContent()
    updateContentData(true);
}
 
Example 8
@Before
public void before() throws Exception
{
    super.before();
    this.nodeService = (NodeService) this.applicationContext.getBean("NodeService");
    this.contentService = (ContentService) this.applicationContext.getBean("ContentService");
    this.renditionService = (RenditionService) this.applicationContext.getBean("RenditionService");
    this.repositoryHelper = (Repository) this.applicationContext.getBean("repositoryHelper");
    this.dictionaryService = (DictionaryService) this.applicationContext.getBean("dictionaryService");
    this.companyHome = repositoryHelper.getCompanyHome();
    
    createTargetFolder();
    
    // Setup the basic rendition definition
    QName renditionName = QName.createQName("Test");
    RenditionDefinition rd = renditionService.loadRenditionDefinition(renditionName); 
    if(rd != null)
    {
       RenditionDefinitionPersisterImpl rdp = new RenditionDefinitionPersisterImpl();
       rdp.setNodeService(nodeService);
       rdp.deleteRenditionDefinition(rd);
    }
    def = renditionService.createRenditionDefinition(renditionName, HTMLRenderingEngine.NAME);
}
 
Example 9
/**
 * This method creates a cm:content NodeRef whose content is taken from the named Alfresco 'quick' file and adds it to the internal
 * list of NodeRefs to be tidied up by the rule.
 * This method will be run in its own transaction and will be run with the specified user as the fully authenticated user,
 * thus ensuring the named user is the cm:creator of the new node.
 *
 * @param quickFileName the file name of the quick file - will also be the cm:name of the new node.
 * @param parentNode the parent node
 * @param nodeCreator the username of the person who will create the node
 * @return the newly created NodeRef.
 * @since 4.1.4
 */
public NodeRef createQuickFileByName(final String quickFileName, final NodeRef parentNode, final String nodeCreator)
{
    final MimetypeMap mimetypeService = (MimetypeMap) appContextRule.getApplicationContext().getBean("mimetypeService");
    final RetryingTransactionHelper transactionHelper = (RetryingTransactionHelper) appContextRule.getApplicationContext().getBean("retryingTransactionHelper");
    
    AuthenticationUtil.pushAuthentication();
    AuthenticationUtil.setFullyAuthenticatedUser(nodeCreator);
    
    NodeRef newNodeRef = transactionHelper.doInTransaction(new RetryingTransactionCallback<NodeRef>()
    {
        public NodeRef execute() throws Throwable
        {
            final NodeRef result = createNode(quickFileName, parentNode, ContentModel.TYPE_CONTENT);
            
            File quickFile = AbstractContentTransformerTest.loadNamedQuickTestFile(quickFileName);
            
            ContentService contentService = appContextRule.getApplicationContext().getBean("contentService", ContentService.class);
            ContentWriter writer = contentService.getWriter(result, ContentModel.PROP_CONTENT, true);
            writer.setMimetype(mimetypeService.guessMimetype(quickFileName));
            writer.setEncoding("UTF-8");
            writer.putContent(quickFile);
            
            return result;
        }
    });
    
    AuthenticationUtil.popAuthentication();
    
    this.temporaryNodeRefs.add(newNodeRef);
    return newNodeRef;
}
 
Example 10
@Before
public void setup() throws Exception
{
    contentService = applicationContext.getBean("contentService", ContentService.class);
    synchronousTransformClient = applicationContext.getBean("synchronousTransformClient", SynchronousTransformClient.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);
}
 
Example 11
@Before
public void before()
{
    this.actionService = (ActionService)ctx.getBean("actionService");
    this.ruleService = (RuleService)ctx.getBean("ruleService");
	this.fileFolderService = (FileFolderService)ctx.getBean("FileFolderService");
	this.transactionService = (TransactionService)ctx.getBean("transactionService");
	this.nodeService = (NodeService)ctx.getBean("NodeService");
	this.contentService = (ContentService)ctx.getBean("ContentService");
    this.versionService = (VersionService) ctx.getBean("versionService");
    this.lockService = (LockService) ctx.getBean("lockService");
    this.taggingService = (TaggingService) ctx.getBean("TaggingService");
    this.namespaceService = (NamespaceService) ctx.getBean("namespaceService");
    this.repositoryHelper = (Repository)ctx.getBean("repositoryHelper");
	this.factory = (AlfrescoCmisServiceFactory)ctx.getBean("CMISServiceFactory");
    this.versionService = (VersionService) ctx.getBean("versionService");
	this.cmisConnector = (CMISConnector) ctx.getBean("CMISConnector");
    this.nodeDAO = (NodeDAO) ctx.getBean("nodeDAO");
    this.authorityService = (AuthorityService)ctx.getBean("AuthorityService");
    this.auditSubsystem = (AuditModelRegistryImpl) ctx.getBean("Audit");
    this.permissionService = (PermissionService) ctx.getBean("permissionService");
	this.dictionaryDAO = (DictionaryDAO)ctx.getBean("dictionaryDAO");
	this.cmisDictionaryService = (CMISDictionaryService)ctx.getBean("OpenCMISDictionaryService1.1");
    this.auditDAO = (AuditDAO) ctx.getBean("auditDAO");
    this.nodeArchiveService = (NodeArchiveService) ctx.getBean("nodeArchiveService");
    this.dictionaryService = (DictionaryService) ctx.getBean("dictionaryService");
    this.workflowService = (WorkflowService) ctx.getBean("WorkflowService");
    this.workflowAdminService = (WorkflowAdminService) ctx.getBean("workflowAdminService");
    this.authenticationContext = (AuthenticationContext) ctx.getBean("authenticationContext");
    this.tenantAdminService = (TenantAdminService) ctx.getBean("tenantAdminService");
    this.tenantService = (TenantService) ctx.getBean("tenantService");
    this.searchService = (SearchService) ctx.getBean("SearchService");
    this.auditComponent = (AuditComponentImpl) ctx.getBean("auditComponent");

    this.globalProperties = (java.util.Properties) ctx.getBean("global-properties");
    this.globalProperties.setProperty(VersionableAspectTest.AUTO_VERSION_PROPS_KEY, "true");
}
 
Example 12
/**
 * This method writes space as a content. We need this space because rules doesn't proceed documents with empty content. We need rule processing for command email messages with
 * empty body.
 * 
 * @param nodeRef Reference to the parent node
 */
private void writeSpace(NodeRef nodeRef)
{
    if (log.isDebugEnabled())
    {
        log.debug("Write space string");
    }

    ContentService contentService = getContentService();
    ContentWriter writer = contentService.getWriter(nodeRef, ContentModel.PROP_CONTENT, true);
    writer.setMimetype(MimetypeMap.MIMETYPE_TEXT_PLAIN);
    writer.setEncoding("UTF-8");
    writer.putContent(" ");
}
 
Example 13
/**
 * Called during the transaction setup
 */
@Before
public void before() throws Exception
{
    super.before();
    
    // Get the required services
    this.transferService = (TransferService)this.applicationContext.getBean("TransferService");
    this.contentService = (ContentService)this.applicationContext.getBean("ContentService");
    this.transferServiceImpl = (TransferServiceImpl2)this.applicationContext.getBean("transferService2");
    this.searchService = (SearchService)this.applicationContext.getBean("SearchService");
    this.transactionService = (TransactionService)this.applicationContext.getBean("TransactionService");
    this.nodeService = (NodeService) this.applicationContext.getBean("nodeService");
    this.contentService = (ContentService) this.applicationContext.getBean("contentService");
    this.authenticationService = (MutableAuthenticationService) this.applicationContext.getBean("authenticationService");
    this.actionService = (ActionService)this.applicationContext.getBean("actionService");
    this.permissionService = (PermissionService)this.applicationContext.getBean("permissionService");
    this.receiver = (TransferReceiver)this.applicationContext.getBean("transferReceiver");
    this.transferManifestNodeFactory = (TransferManifestNodeFactory)this.applicationContext.getBean("transferManifestNodeFactory");
    this.authenticationComponent = (AuthenticationComponent) this.applicationContext.getBean("authenticationComponent");
    this.lockService = (LockService) this.applicationContext.getBean("lockService");
    this.personService = (PersonService)this.applicationContext.getBean("PersonService");
    this.descriptorService = (DescriptorService)this.applicationContext.getBean("DescriptorService");
    this.copyService = (CopyService)this.applicationContext.getBean("CopyService");
    this.taggingService = ((TaggingService)this.applicationContext.getBean("TaggingService"));
    this.categoryService = (CategoryService)this.applicationContext.getBean("CategoryService");
    this.repositoryHelper = (Repository) this.applicationContext.getBean("repositoryHelper");
    
    this.serverDescriptor = descriptorService.getServerDescriptor();
    
    REPO_ID_B = descriptorService.getCurrentRepositoryDescriptor().getId();
    
    authenticationComponent.setSystemUserAsCurrentUser();
    assertNotNull("receiver is null", this.receiver);

    TestTransaction.flagForCommit();
    TestTransaction.end();
}
 
Example 14
/**
 * This method creates a NodeRef with some text/plain, UTF-8 content and adds it to the internal list of NodeRefs to be tidied up by the rule.
 * This method will be run in its own transaction and will be run with the specified user as the fully authenticated user,
 * thus ensuring the named user is the cm:creator of the new node.
 * 
 * @param parentNode the parent node
 * @param nodeCmName the cm:name of the new node
 * @param nodeType   the type of the new node
 * @param nodeCreator the username of the person who will create the node
 * @param textContent the text/plain, UTF-8 content that will be stored in the node's content. <code>null</code> content will not be written.
 * @return the newly created NodeRef.
 */
public NodeRef createNodeWithTextContent(final NodeRef parentNode, final QName childName, final String nodeCmName, final QName nodeType, final String nodeCreator, final String textContent)
{
    final RetryingTransactionHelper transactionHelper = (RetryingTransactionHelper) appContextRule.getApplicationContext().getBean("retryingTransactionHelper");
    
    AuthenticationUtil.pushAuthentication();
    AuthenticationUtil.setFullyAuthenticatedUser(nodeCreator);
    
    NodeRef newNodeRef = transactionHelper.doInTransaction(new RetryingTransactionCallback<NodeRef>()
    {
        public NodeRef execute() throws Throwable
        {
            final NodeService nodeService = (NodeService) appContextRule.getApplicationContext().getBean("nodeService");
            
            Map<QName, Serializable> props = new HashMap<QName, Serializable>();
            props.put(ContentModel.PROP_NAME, nodeCmName);
            ChildAssociationRef childAssoc = nodeService.createNode(parentNode,
                        ContentModel.ASSOC_CONTAINS,
                        childName,
                        nodeType,
                        props);
            
            // If there is any content, add it.
            if (textContent != null)
            {
                ContentService contentService = appContextRule.getApplicationContext().getBean("contentService", ContentService.class);
                ContentWriter writer = contentService.getWriter(childAssoc.getChildRef(), ContentModel.PROP_CONTENT, true);
                writer.setMimetype(MimetypeMap.MIMETYPE_TEXT_PLAIN);
                writer.setEncoding("UTF-8");
                writer.putContent(textContent);
            }
            return childAssoc.getChildRef();
        }
    });
    
    AuthenticationUtil.popAuthentication();
    
    this.temporaryNodeRefs.add(newNodeRef);
    return newNodeRef;
}
 
Example 15
@Override
protected void setUp() throws Exception
{
    super.setUp();
    MockitoAnnotations.initMocks(this);

    ApplicationContext ctx = getServer().getApplicationContext();
    this.authenticationService = (MutableAuthenticationService)ctx.getBean("AuthenticationService");
    this.authenticationComponent = (AuthenticationComponent)ctx.getBean("authenticationComponent");
    this.personService = (PersonService)ctx.getBean("PersonService");
    this.userNameMatcherImpl = (UserNameMatcherImpl)ctx.getBean("userNameMatcher");
    this.nodeService = (NodeService)ctx.getBean("NodeService");
    this.contentService = (ContentService)ctx.getBean("contentService");
    this.userUsageTrackingComponent = (UserUsageTrackingComponent)ctx.getBean("userUsageTrackingComponent");
    this.contentUsage = (ContentUsageImpl)ctx.getBean("contentUsageImpl");
    this.transactionService = (TransactionService) ctx.getBean("TransactionService");

	serviceRegistry = (ServiceDescriptorRegistry) ctx.getBean("ServiceRegistry");
	serviceRegistry.setMockSearchService(mockSearchService);
    when(mockSearchService.query(any())).thenReturn(mockSearchServiceQueryResultSet);
    when(mockSearchServiceQueryResultSet.getNodeRefs()).thenReturn(dummySearchServiceQueryNodeRefs);

    // enable usages
    contentUsage.setEnabled(true);
    contentUsage.init();
    userUsageTrackingComponent.setEnabled(true);
    userUsageTrackingComponent.init();
    userUsageTrackingComponent.bootstrapInternal();

    this.authenticationComponent.setSystemUserAsCurrentUser();

    // Create users
    createUser(USER_ONE);
    createUser(USER_TWO);
    createUser(USER_THREE);
    
    // Do tests as user one
    this.authenticationComponent.setCurrentUser(USER_ONE);
}
 
Example 16
@Override
protected void setUp() throws Exception
{
    super.setUp();
    ctx = ApplicationContextHelper.getApplicationContext(new String[] { ApplicationContextHelper.CONFIG_LOCATIONS[0], "classpath:tenant/mt-*context.xml" });

    nodeService = (NodeService) ctx.getBean("NodeService");
    nodeArchiveService = (NodeArchiveService) ctx.getBean("nodeArchiveService");
    namespaceService = (NamespaceService) ctx.getBean("NamespaceService");
    authenticationService = (MutableAuthenticationService) ctx.getBean("AuthenticationService");
    tenantAdminService = (TenantAdminService) ctx.getBean("tenantAdminService");
    tenantService = (TenantService) ctx.getBean("tenantService");
    personService = (PersonService) ctx.getBean("PersonService");
    searchService = (SearchService) ctx.getBean("SearchService");
    contentService = (ContentService) ctx.getBean("ContentService");
    permissionService = (PermissionService) ctx.getBean("PermissionService");
    ownableService = (OwnableService) ctx.getBean("OwnableService");
    authorityService = (AuthorityService) ctx.getBean("AuthorityService");
    categoryService = (CategoryService) ctx.getBean("CategoryService");
    cociService = (CheckOutCheckInService) ctx.getBean("CheckoutCheckinService");
    repoAdminService = (RepoAdminService) ctx.getBean("RepoAdminService");
    dictionaryService = (DictionaryService) ctx.getBean("DictionaryService");
    usageService = (UsageService) ctx.getBean("usageService");
    transactionService = (TransactionService) ctx.getBean("TransactionService");
    fileFolderService = (FileFolderService) ctx.getBean("FileFolderService");
    ownableService = (OwnableService) ctx.getBean("OwnableService");
    repositoryHelper = (Repository) ctx.getBean("repositoryHelper");
    siteService = (SiteService) ctx.getBean("SiteService");
    
    AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getAdminUserName()); // authenticate as super-admin
    
    createTenants();
    createUsers();
}
 
Example 17
protected void setUp() throws Exception
{
    super.setUp();
    ctx = ApplicationContextHelper.getApplicationContext();
    transactionService = (TransactionService)ctx.getBean("transactionComponent");
    contentService = (ContentService)ctx.getBean("contentService");
    nodeService = (NodeService)ctx.getBean("nodeService");
    scriptService = (ScriptService)ctx.getBean("scriptService");
    serviceRegistry = (ServiceRegistry)ctx.getBean("ServiceRegistry");
    
    this.authenticationComponent = (AuthenticationComponent)ctx.getBean("authenticationComponent");
    this.authenticationComponent.setSystemUserAsCurrentUser();
    
    DictionaryDAO dictionaryDao = (DictionaryDAO)ctx.getBean("dictionaryDAO");
    
    // load the system model
    ClassLoader cl = BaseNodeServiceTest.class.getClassLoader();
    InputStream modelStream = cl.getResourceAsStream("alfresco/model/contentModel.xml");
    assertNotNull(modelStream);
    M2Model model = M2Model.createModel(modelStream);
    dictionaryDao.putModel(model);
    
    // load the test model
    modelStream = cl.getResourceAsStream("org/alfresco/repo/node/BaseNodeServiceTest_model.xml");
    assertNotNull(modelStream);
    model = M2Model.createModel(modelStream);
    dictionaryDao.putModel(model);
    
    DictionaryComponent dictionary = new DictionaryComponent();
    dictionary.setDictionaryDAO(dictionaryDao);
    BaseNodeServiceTest.loadModel(ctx);
}
 
Example 18
@Before
public void before() throws Exception
{
    this.nodeService = (NodeService) this.applicationContext.getBean("nodeService");
    this.contentService = (ContentService) this.applicationContext.getBean("contentService");
    this.dictionaryService = (DictionaryService) this.applicationContext.getBean("dictionaryService");
    this.mimetypeService = (MimetypeService) this.applicationContext.getBean("mimetypeService");
    this.metadataExtracterRegistry  = (MetadataExtracterRegistry) this.applicationContext.getBean("metadataExtracterRegistry");
    
    AuthenticationComponent authenticationComponent = (AuthenticationComponent)applicationContext.getBean("authenticationComponent");
    authenticationComponent.setSystemUserAsCurrentUser();

    // Create the store and get the root node
    this.testStoreRef = this.nodeService.createStore(
            StoreRef.PROTOCOL_WORKSPACE,
            "Test_" + System.currentTimeMillis());
    this.rootNodeRef = this.nodeService.getRootNode(this.testStoreRef);

    // Create the node used for tests
    this.nodeRef = this.nodeService.createNode(
            this.rootNodeRef, ContentModel.ASSOC_CHILDREN,
            QName.createQName("{test}testnode"),
            ContentModel.TYPE_CONTENT).getChildRef();

    // Setup the content from the PDF test data
    ContentWriter cw = this.contentService.getWriter(nodeRef, ContentModel.PROP_CONTENT, true);
    cw.setMimetype(MimetypeMap.MIMETYPE_PDF);
    cw.putContent(AbstractContentTransformerTest.loadQuickTestFile("pdf"));

    // Get the executer instance
    this.executer = new ContentMetadataEmbedder();
    this.executer.setNodeService(nodeService);
    this.executer.setContentService(contentService);
    this.executer.setMetadataExtracterRegistry(metadataExtracterRegistry);
    this.executer.setApplicableTypes(new String[] { ContentModel.TYPE_CONTENT.toString() });
}
 
Example 19
@Before
public void setUp() throws Exception
{
    transactionService = ctx.getBean("transactionService", TransactionService.class);
    searchService = ctx.getBean("SearchService", SearchService.class);
    nodeService = ctx.getBean("NodeService", NodeService.class);
    contentService = ctx.getBean("contentService", ContentService.class);
    webDAVHelper = ctx.getBean("webDAVHelper", WebDAVHelper.class);         
    repositoryHelper = (Repository)ctx.getBean("repositoryHelper");
    companyHomeNodeRef = repositoryHelper.getCompanyHome();
}
 
Example 20
@Before
public void before() throws Exception
{
    super.before();
    
    // Get the instance of the required content service
    this.contentService = (ContentService)this.applicationContext.getBean("contentService");
    this.contentStore = (ContentStore) ReflectionTestUtils.getField(contentService, "store");
}
 
Example 21
/** utility function for parsing xml */
public static Document parse(final NodeRef nodeRef,
                             final ContentService contentService)
   throws SAXException,
   IOException
{
   final ContentReader contentReader = 
      contentService.getReader(nodeRef, ContentModel.TYPE_CONTENT);
   final InputStream in = contentReader.getContentInputStream();
   return XMLUtil.parse(in);
}
 
Example 22
@Override
protected void setUp() throws Exception
{
    super.setUp();

    this.contentService = mock(ContentService.class);
    this.nodeService = mock(NodeService.class);
    engine = new TestRenderingEngine();
    engine.setContentService(contentService);
    engine.setNodeService(nodeService);
    engine.setBehaviourFilter(mock(BehaviourFilter.class));
}
 
Example 23
/**
 * Generic method to transform Node content from one mimetype to another.
 * 
 * @param transformer   The Transformer delegate supplying the transformation logic
 * @param mimetype      Mimetype of the destination content
 * @param destination   Destination folder location for the resulting document
 * 
 * @return Node representing the transformed content - or null if the transform failed
 */
private ScriptNode transformNode(Transformer transformer, String mimetype, NodeRef destination)
{
    ScriptNode transformedNode = null;
    
    // get the content reader
    ContentService contentService = this.services.getContentService();
    ContentReader reader = contentService.getReader(this.nodeRef, ContentModel.PROP_CONTENT);
    
    // only perform the transformation if some content is available
    if (reader != null)
    {
        // Copy the content node to a new node
        String copyName = TransformActionExecuter.transformName(this.services.getMimetypeService(), getName(),
                mimetype, true);
        NodeRef copyNodeRef = this.services.getCopyService().copy(this.nodeRef, destination,
                ContentModel.ASSOC_CONTAINS,
                QName.createQName(ContentModel.PROP_CONTENT.getNamespaceURI(), QName.createValidLocalName(copyName)),
                false);
        
        // modify the name of the copy to reflect the new mimetype
        this.nodeService.setProperty(copyNodeRef, ContentModel.PROP_NAME, copyName);
        
        // get the writer and set it up
        ContentWriter writer = contentService.getWriter(copyNodeRef, ContentModel.PROP_CONTENT, true);
        writer.setMimetype(mimetype); // new mimetype
        writer.setEncoding(reader.getEncoding()); // original encoding
        
        // Try and transform the content using the supplied delegate
        transformedNode = transformer.transform(synchronousTransformClient, copyNodeRef, reader, writer);
    }
    
    return transformedNode;
}
 
Example 24
protected void setUp() throws Exception
{
    applicationContext = ApplicationContextHelper.getApplicationContext();
    if (AlfrescoTransactionSupport.isActualTransactionActive())
    {
        fail("Test started with transaction in progress");
    }
    
    nodeService = (NodeService)applicationContext.getBean("NodeService");
    authenticationService = (MutableAuthenticationService)applicationContext.getBean("authenticationService");   
    transactionService = (TransactionService)applicationContext.getBean("transactionComponent");
    personService = (PersonService)applicationContext.getBean("PersonService");
    contentService = (ContentService)applicationContext.getBean("ContentService");
    contentUsageService = (ContentUsageService)applicationContext.getBean("ContentUsageService");
    
    userUsageTrackingComponent = (UserUsageTrackingComponent)applicationContext.getBean("userUsageTrackingComponent");
    
    // Enable
    ContentUsageImpl contentUsage = (ContentUsageImpl)applicationContext.getBean("contentUsageImpl");
    contentUsage.setEnabled(true);
    contentUsage.init();
    userUsageTrackingComponent.setEnabled(true);
    userUsageTrackingComponent.init();
    userUsageTrackingComponent.bootstrapInternal();
    
    AuthenticationUtil.setRunAsUserSystem();
}
 
Example 25
@Before
public void before() throws Exception
{
    // Get the services
    this.nodeService = (NodeService) this.applicationContext
            .getBean("nodeService");
    this.contentService = (ContentService) this.applicationContext
            .getBean("contentService");
    this.ruleService = (RuleService) this.applicationContext
            .getBean("ruleService");
    this.configService = (ConfigurableService)this.applicationContext
    		.getBean("ConfigurableService");
    this.actionService = (ActionService)this.applicationContext.getBean("actionService");
    this.transactionService = (TransactionService)this.applicationContext.getBean("transactionComponent");
    this.authenticationComponent = (AuthenticationComponent)this.applicationContext.getBean("authenticationComponent");

    //authenticationComponent.setSystemUserAsCurrentUser();
    authenticationComponent.setCurrentUser(AuthenticationUtil.getAdminUserName());
    
    // Get the rule type
    this.ruleType = this.ruleService.getRuleType(RULE_TYPE_NAME);

    // Create the store and get the root node
    this.testStoreRef = this.nodeService.createStore(
            StoreRef.PROTOCOL_WORKSPACE, "Test_"
                    + System.currentTimeMillis());
    this.rootNodeRef = this.nodeService.getRootNode(this.testStoreRef);

    // Create the node used for tests
    this.nodeRef = this.nodeService.createNode(rootNodeRef,
            ContentModel.ASSOC_CHILDREN,
            QName.createQName("{test}testnode"),
            ContentModel.TYPE_CONTAINER).getChildRef();
}
 
Example 26
@Before
   public void before() throws Exception
   {
       this.nodeService = (NodeService)this.applicationContext.getBean("nodeService");
	this.contentService = (ContentService)this.applicationContext.getBean("contentService");
	
	this.testStoreRef = this.nodeService.createStore(StoreRef.PROTOCOL_WORKSPACE, "Test_" + System.currentTimeMillis());
       this.rootNodeRef = this.nodeService.getRootNode(this.testStoreRef);
}
 
Example 27
@Before
public void before() throws Exception
{
    super.before();
    this.nodeService = (NodeService) this.applicationContext.getBean("NodeService");
    this.contentService = (ContentService) this.applicationContext.getBean("ContentService");
    this.fileFolderService = (FileFolderService) this.applicationContext.getBean("FileFolderService");
    this.xsltProcessor = (TemplateProcessor) this.applicationContext.getBean("xsltProcessor");
    this.templateService = (TemplateService) this.applicationContext.getBean("TemplateService");
    this.repositoryHelper = (Repository) this.applicationContext.getBean("repositoryHelper");
    this.companyHome = repositoryHelper.getCompanyHome();
}
 
Example 28
/**
 * @return the content stream
 */
public String getContent()
{
    ContentService contentService = services.getContentService();
    ContentReader reader = contentService.getReader(getNodeRef(), property);
    
    return (reader != null && reader.exists()) ? reader.getContentString() : "";
}
 
Example 29
/**
 * @return the content stream to the specified maximum length in characters
 */
public String getContentMaxLength(int length)
{
    ContentService contentService = services.getContentService();
    ContentReader reader = contentService.getReader(getNodeRef(), property);
    
    return (reader != null && reader.exists()) ? reader.getContentString(length) : "";
}
 
Example 30
@BeforeClass
public static void initStaticData() throws Exception
{
    nodeService = (NodeService) APP_CONTEXT_INIT.getApplicationContext().getBean("nodeService");
    actionService = (ActionService) APP_CONTEXT_INIT.getApplicationContext().getBean("actionService");
    contentService = (ContentService) APP_CONTEXT_INIT.getApplicationContext().getBean("contentService");
    transactionHelper = (RetryingTransactionHelper) APP_CONTEXT_INIT.getApplicationContext().getBean(
            "retryingTransactionHelper");
}