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

The following are top voted examples for showing how to use org.alfresco.service.cmr.repository.ContentService. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: alfresco-repository   File: FileFolderLoader.java   View source code 7 votes vote down vote up
/**
 * @param repoState             keep track of repository readiness
 * @param transactionService    ensure proper rollback, where required
 * @param repositoryHelper      access standard repository paths
 * @param fileFolderService     perform actual file-folder manipulation
 */
public FileFolderLoader(
        RepositoryState repoState,
        TransactionService transactionService,
        Repository repositoryHelper,
        FileFolderService fileFolderService,
        NodeService nodeService,
        ContentService contentService,
        BehaviourFilter policyBehaviourFilter)
{
    this.repoState = repoState;
    this.transactionService = transactionService;
    this.repositoryHelper = repositoryHelper;
    this.fileFolderService = fileFolderService;
    this.nodeService = nodeService;
    this.contentService = contentService;
    this.policyBehaviourFilter = policyBehaviourFilter;
    
    this.normalDistribution = new NormalDistributionHelper();
}
 
Example 2
Project: alfresco-remote-api   File: MoveMethod.java   View source code 7 votes vote down vote up
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);
    }
}
 
Example 3
Project: alfresco-repository   File: ModelValidatorTest.java   View source code 7 votes vote down vote up
@Before
public void setUp() throws Exception
{
    ctx = ApplicationContextHelper.getApplicationContext();
    this.modelValidator = (ModelValidator)ctx.getBean("modelValidator");
    this.dictionaryDAO = (DictionaryDAO)ctx.getBean("dictionaryDAO");
    this.qnameDAO = (QNameDAO)ctx.getBean("qnameDAO");
    this.namespaceDAO = (NamespaceDAO)ctx.getBean("namespaceDAO");
    this.nodeService = (NodeService)ctx.getBean("NodeService");
    this.fileFolderService = (FileFolderService)ctx.getBean("FileFolderService");
    this.contentService = (ContentService)ctx.getBean("contentService");
    this.versionService = (VersionService)ctx.getBean("VersionService");
    this.transactionService = (TransactionService)ctx.getBean("TransactionService");
    this.nodeArchiveService = (NodeArchiveService)ctx.getBean("nodeArchiveService");

    this.modelName = "modelvalidatortest" + System.currentTimeMillis();
    addModel();
}
 
Example 4
Project: alfresco-repository   File: HTMLRenderingEngineTest.java   View source code 7 votes vote down vote up
@SuppressWarnings("deprecation")
@Override
protected void onSetUpInTransaction() throws Exception
{
    super.onSetUpInTransaction();
    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 5
Project: alfresco-repository   File: MultiUserRenditionTest.java   View source code 6 votes vote down vote up
public  void initContextAndCreateUser()
{
    appContext = ApplicationContextHelper.getApplicationContext();

    authenticationService = (MutableAuthenticationService) appContext.getBean("AuthenticationService");
    contentService = (ContentService) appContext.getBean("ContentService");
    nodeService = (NodeService) appContext.getBean("NodeService");
    permissionService = (PermissionService) appContext.getBean("PermissionService");
    personService = (PersonService) appContext.getBean("PersonService");
    renditionService = (RenditionService) appContext.getBean("RenditionService");
    repositoryHelper = (Repository) appContext.getBean("repositoryHelper");
    transactionService = (TransactionService) appContext.getBean("TransactionService");
    txnHelper = transactionService.getRetryingTransactionHelper();
    ownableService = (OwnableService) appContext.getBean("ownableService");

    ADMIN_USER = AuthenticationUtil.getAdminUserName();
    
    // Create a nonAdminUser
    createUser(NON_ADMIN_USER);

}
 
Example 6
Project: alfresco-remote-api   File: TestCMIS.java   View source code 6 votes vote down vote up
@Before
  public void before() throws Exception
  {
      ctx = getTestFixture().getApplicationContext();
      this.dictionaryDAO = (DictionaryDAO)ctx.getBean("dictionaryDAO");
      this.lockService = (LockService) ctx.getBean("lockService");
      this.tenantService = (TenantService)ctx.getBean("tenantService");
      this.cmisDictionary = (CMISStrictDictionaryService)ctx.getBean("OpenCMISDictionaryService");
      this.cmisTypeExclusions = (QNameFilter)ctx.getBean("cmisTypeExclusions");
this.nodeService = (NodeService) ctx.getBean("NodeService");
      this.fileFolderService = (FileFolderService) ctx.getBean("FileFolderService");
  	this.contentService = (ContentService)applicationContext.getBean("ContentService");
this.permissionService = (PermissionService) ctx.getBean("permissionService");
      
this.globalProperties = (Properties) ctx.getBean("global-properties");
this.globalProperties.setProperty(VersionableAspectTest.AUTO_VERSION_PROPS_KEY, "true");
  }
 
Example 7
Project: alfresco-repository   File: BaseAlfrescoSpringTest.java   View source code 6 votes vote down vote up
/**
 * On setup in transaction override
 */
@SuppressWarnings("deprecation")
@Override
protected void onSetUpInTransaction() throws Exception
{
    super.onSetUpInTransaction();

    // 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 8
Project: alfresco-repository   File: RhinoScriptTest.java   View source code 6 votes vote down vote up
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 9
Project: alfresco-repository   File: ScriptNodeTest.java   View source code 6 votes vote down vote up
@BeforeClass public static void initStaticData() throws Exception
{
    CONTENT_SERVICE       = APP_CONTEXT_INIT.getApplicationContext().getBean("ContentService", ContentService.class);
    NODE_SERVICE          = APP_CONTEXT_INIT.getApplicationContext().getBean("NodeService", NodeService.class);
    SERVICE_REGISTRY      = APP_CONTEXT_INIT.getApplicationContext().getBean("ServiceRegistry", ServiceRegistry.class);
    TRANSACTION_HELPER    = APP_CONTEXT_INIT.getApplicationContext().getBean("retryingTransactionHelper", RetryingTransactionHelper.class);
    PERMISSION_SERVICE    = APP_CONTEXT_INIT.getApplicationContext().getBean("permissionService", PermissionServiceSPI.class);
    SEARCH_SCRIPT         = APP_CONTEXT_INIT.getApplicationContext().getBean("searchScript", Search.class);
    VERSIONABLE_ASPECT    = APP_CONTEXT_INIT.getApplicationContext().getBean("versionableAspect", VersionableAspect.class);
    VERSION_SERVICE       = APP_CONTEXT_INIT.getApplicationContext().getBean("VersionService", VersionService.class);
    DICTIONARY_SERVICE    = APP_CONTEXT_INIT.getApplicationContext().getBean("DictionaryService", DictionaryService.class);       
    NAMESPACE_SERVICE     = APP_CONTEXT_INIT.getApplicationContext().getBean("namespaceService", NamespaceService.class);
    DICTIONARY_DAO        = APP_CONTEXT_INIT.getApplicationContext().getBean("dictionaryDAO", DictionaryDAO.class);
    TENANT_ADMIN_SERVICE  = APP_CONTEXT_INIT.getApplicationContext().getBean("tenantAdminService", TenantAdminService.class);
    MESSAGE_SERVICE       = APP_CONTEXT_INIT.getApplicationContext().getBean("messageService", MessageService.class);
    TRANSACTION_SERVICE   = APP_CONTEXT_INIT.getApplicationContext().getBean("transactionComponent", TransactionService.class);
    POLICY_COMPONENT      = APP_CONTEXT_INIT.getApplicationContext().getBean("policyComponent", PolicyComponent.class);

    USER_ONES_TEST_SITE = STATIC_TEST_SITES.createTestSiteWithUserPerRole(GUID.generate(), "sitePreset", SiteVisibility.PRIVATE, USER_ONE_NAME);
    USER_ONES_TEST_FILE = STATIC_TEST_NODES.createQuickFile(MimetypeMap.MIMETYPE_TEXT_PLAIN, USER_ONES_TEST_SITE.doclib, "test.txt", USER_ONE_NAME);		
}
 
Example 10
Project: alfresco-repository   File: LinksServiceImplTest.java   View source code 6 votes vote down vote up
@BeforeClass public static void initTestsContext() throws Exception
{
    AUTHENTICATION_SERVICE = (MutableAuthenticationService)testContext.getBean("authenticationService");
    BEHAVIOUR_FILTER       = (BehaviourFilter)testContext.getBean("policyBehaviourFilter");
    LINKS_SERVICE          = (LinksService)testContext.getBean("LinksService");
    NODE_SERVICE           = (NodeService)testContext.getBean("nodeService");
    PUBLIC_NODE_SERVICE    = (NodeService)testContext.getBean("NodeService");
    PERSON_SERVICE         = (PersonService)testContext.getBean("personService");
    TRANSACTION_HELPER     = (RetryingTransactionHelper)testContext.getBean("retryingTransactionHelper");
    PERMISSION_SERVICE     = (PermissionService)testContext.getBean("permissionService");
    SITE_SERVICE           = (SiteService)testContext.getBean("siteService");
    CONTENT_SERVICE        = (ContentService)testContext.getBean("ContentService");

    // Do the setup as admin
    AuthenticationUtil.setFullyAuthenticatedUser(ADMIN_USER);
    createUser(TEST_USER);
    
    // We need to create the test site as the test user so that they can contribute content to it in tests below.
    AuthenticationUtil.setFullyAuthenticatedUser(TEST_USER);
    createTestSites();
}
 
Example 11
Project: alfresco-repository   File: ScriptNode.java   View source code 6 votes vote down vote up
private ScriptNode transformDocument(String mimetype, NodeRef destination)
{
    ParameterCheck.mandatoryString("Mimetype", mimetype);
    ParameterCheck.mandatory("Destination Node", destination);
    final NodeRef sourceNodeRef = nodeRef;
    
    // the delegate definition for transforming a document
    Transformer transformer = new AbstractTransformer()
    {
        protected void doTransform(ContentService contentService,
            ContentReader reader, ContentWriter writer)
        {
            TransformationOptions options = new TransformationOptions();
            options.setSourceNodeRef(sourceNodeRef);
            contentService.transform(reader, writer, options);
        }
    };
    
    return transformNode(transformer, mimetype, destination);
}
 
Example 12
Project: alfresco-repository   File: MessageServiceImplTest.java   View source code 6 votes vote down vote up
@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 13
Project: alfresco-repository   File: ScriptNode.java   View source code 6 votes vote down vote up
/**
 * 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 14
Project: alfresco-repository   File: ApplicationContextInitTest.java   View source code 6 votes vote down vote up
@Test public void ensureSpringContextWasInitedWithOverrides() throws Exception
{
    // Bean from the standard Alfresco context
    assertNotNull("Spring context did not contain expected bean.",
                  APP_CONTEXT_INIT.getApplicationContext().getBean("contentService", ContentService.class));
    
    // Bean from the first override context
    assertEquals("Value from dummy1-context.xml",
                  APP_CONTEXT_INIT.getApplicationContext().getBean("testBean1", String.class));
    
    // Bean from the second override context
    assertEquals("Value from dummy2-context.xml",
            APP_CONTEXT_INIT.getApplicationContext().getBean("testBean2", String.class));
    
    // Bean overridden in second context
    assertEquals("Value from dummy2-context.xml",
            APP_CONTEXT_INIT.getApplicationContext().getBean("testBean1and2", String.class));
}
 
Example 15
Project: alfresco-repository   File: ManifestIntegrationTest.java   View source code 5 votes vote down vote up
/**
 * Called during the transaction setup
 */
protected void onSetUpInTransaction() throws Exception
{
    super.onSetUpInTransaction();

    // Get the required services
    this.transferService = (TransferService)this.applicationContext.getBean("TransferService");
    this.contentService = (ContentService)this.applicationContext.getBean("ContentService");
    this.permissionService = (PermissionService)this.applicationContext.getBean("PermissionService");
    this.dictionaryService = (DictionaryService)this.applicationContext.getBean("DictionaryService");
    this.mlAwareNodeService = (NodeService) this.applicationContext.getBean("mlAwareNodeService");
}
 
Example 16
Project: alfresco-repository   File: MSOfficeContentNetworkFile.java   View source code 5 votes vote down vote up
/**
 * Class constructor
 * 
 * @param nodeService NodeService
 * @param contentService ContentService
 * @param mimetypeService MimetypeService
 * @param nodeRef NodeRef
 * @param name String
 */
protected MSOfficeContentNetworkFile(
        NodeService nodeService,
        ContentService contentService,
        MimetypeService mimetypeService,
        NodeRef nodeRef,
        String name)
{
    super(nodeService, contentService, mimetypeService, nodeRef, name);

    // Create the buffered write list
    
    m_writeList = new ArrayList<BufferedWrite>(); 
}
 
Example 17
Project: alfresco-repository   File: OpenOfficeContentNetworkFile.java   View source code 5 votes vote down vote up
/**
 * Class constructor
 * 
 * @param nodeService NodeService
 * @param contentService ContentService
 * @param mimetypeService MimetypeService
 * @param nodeRef NodeRef
 * @param name String
 */
protected OpenOfficeContentNetworkFile(
        NodeService nodeService,
        ContentService contentService,
        MimetypeService mimetypeService,
        NodeRef nodeRef,
        String name)
{
    super(nodeService, contentService, mimetypeService, nodeRef, name);
    
    // DEBUG
    
    if (logger.isDebugEnabled())
        logger.debug("Using OpenOffice network file for " + name + ", versionLabel=" + nodeService.getProperty( nodeRef, ContentModel.PROP_VERSION_LABEL));
}
 
Example 18
Project: alfresco-repository   File: XSLTRenderingEngineTest.java   View source code 5 votes vote down vote up
@SuppressWarnings("deprecation")
@Override
protected void onSetUpInTransaction() throws Exception
{
    super.onSetUpInTransaction();
    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.renditionService = (RenditionService) this.applicationContext.getBean("RenditionService");
    
    this.companyHome = this.applicationContext.getBean("repositoryHelper", Repository.class).getCompanyHome();
}
 
Example 19
Project: alfresco-remote-api   File: PersonServiceTest.java   View source code 5 votes vote down vote up
@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 20
Project: alfresco-repository   File: XSLTProcessorTest.java   View source code 5 votes vote down vote up
@SuppressWarnings("deprecation")
@Override
protected void onSetUpInTransaction() throws Exception
{
    super.onSetUpInTransaction();
    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 21
Project: alfresco-repository   File: ContentDataPart.java   View source code 5 votes vote down vote up
/**
 * ContentDataPart 
 * @param contentService content service
 * @param partName String
 * @param data data
 */
public ContentDataPart(ContentService contentService, String partName, ContentData data) {
    super(partName, data.getMimetype(), data.getEncoding(), null);
    this.contentService = contentService;
    this.data = data;
    this.filename = partName;
}
 
Example 22
Project: alfresco-repository   File: RuleTypeImplTest.java   View source code 5 votes vote down vote up
@Override
protected void onSetUpInTransaction() 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 23
Project: alfresco-remote-api   File: UploadWebScriptTest.java   View source code 5 votes vote down vote up
@Override
protected void setUp() throws Exception
{
    super.setUp();

    this.authenticationService = (MutableAuthenticationService) getServer().getApplicationContext().getBean("AuthenticationService");
    this.globalProperties = (Properties) getServer().getApplicationContext().getBean("global-properties");
    this.transactionService = (TransactionService) getServer().getApplicationContext().getBean("transactionService");
    this.siteService = (SiteService) getServer().getApplicationContext().getBean("SiteService");
    this.nodeService = (NodeService) getServer().getApplicationContext().getBean("nodeService");
    this.contentService = (ContentService) getServer().getApplicationContext().getBean("contentService");
    this.checkOutCheckInService = (CheckOutCheckInService) getServer().getApplicationContext().getBean("checkOutCheckInService");

    globalProperties.setProperty(AUTO_VERSION_PROPS_KEY, "true");

    transactionService.getRetryingTransactionHelper().doInTransaction(new RetryingTransactionCallback<Void>()
    {
        @Override
        public Void execute() throws Throwable
        {
            authenticationService.authenticate(ADMIN_CREDENTIAL, ADMIN_CREDENTIAL.toCharArray());
            fileName = "quick-2.pdf";
            file = getResourceFile(fileName);

            // Create a Public site
            SiteInfo siteInfo = createSite("site" + GUID.generate(), "doclib", SiteVisibility.PUBLIC);
            
            //Upload file in a site using webScript
            Response response = uploadFileWs(file, fileName, siteInfo.getShortName(), "doclib");
            assertNotNull("content of file", response.getContentAsString());
            JSONObject jsonRsp = (JSONObject) JSONValue.parse(response.getContentAsString());
            final String ssdNodeRefString = (String) jsonRsp.get("nodeRef");
            assertNotNull("nodeRef", ssdNodeRefString);
            documentSite = new NodeRef(ssdNodeRefString);

            return null;
        }
    });
}
 
Example 24
Project: alfresco-repository   File: CMISTest.java   View source code 5 votes vote down vote up
@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 25
Project: alfresco-repository   File: BaseRuleTest.java   View source code 5 votes vote down vote up
/**
 * onSetUpInTransaction implementation
 */
@Override
protected void onSetUpInTransaction() 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
Project: alfresco-repository   File: AbstractRenderingEngineTest.java   View source code 5 votes vote down vote up
@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 27
Project: alfresco-repository   File: RepoTransferReceiverImplTest.java   View source code 5 votes vote down vote up
/**
 * Called during the transaction setup
 */
protected void onSetUp() throws Exception
{
    super.onSetUp();
    System.out.println("java.io.tmpdir == " + System.getProperty("java.io.tmpdir"));

    // Get the required services
    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");
    this.authenticationComponent = (AuthenticationComponent) this.applicationContext
            .getBean("authenticationComponent");
    this.receiver = (RepoTransferReceiverImpl) this.getApplicationContext().getBean("transferReceiver");
    this.policyComponent = (PolicyComponent) this.getApplicationContext().getBean("policyComponent");
    this.searchService = (SearchService) this.getApplicationContext().getBean("searchService");
    this.repositoryHelper = (Repository) this.getApplicationContext().getBean("repositoryHelper");
    this.namespaceService = (NamespaceService) this.getApplicationContext().getBean("namespaceService");
    this.dummyContent = "This is some dummy content.";        
    this.dummyContentBytes = dummyContent.getBytes("UTF-8");
    setTransactionDefinition(new DefaultTransactionDefinition(TransactionDefinition.PROPAGATION_REQUIRES_NEW));
    authenticationComponent.setSystemUserAsCurrentUser();

    startNewTransaction();
    guestHome = repositoryHelper.getGuestHome();
    endTransaction();
}
 
Example 28
Project: alfresco-repository   File: TemporaryNodesTest.java   View source code 5 votes vote down vote up
@BeforeClass public static void initStaticData() throws Exception
{
    COCI_SERVICE       = APP_CONTEXT_INIT.getApplicationContext().getBean("checkOutCheckInService", CheckOutCheckInService.class);
    CONTENT_SERVICE    = APP_CONTEXT_INIT.getApplicationContext().getBean("ContentService", ContentService.class);
    NODE_SERVICE       = APP_CONTEXT_INIT.getApplicationContext().getBean("NodeService", NodeService.class);
    SITE_SERVICE       = APP_CONTEXT_INIT.getApplicationContext().getBean("SiteService", SiteService.class);
    TRANSACTION_HELPER = APP_CONTEXT_INIT.getApplicationContext().getBean("retryingTransactionHelper", RetryingTransactionHelper.class);
    VERSION_SERVICE    = APP_CONTEXT_INIT.getApplicationContext().getBean("VersionService", VersionService.class);
    
    Repository repositoryHelper = APP_CONTEXT_INIT.getApplicationContext().getBean("repositoryHelper", Repository.class);
    COMPANY_HOME = repositoryHelper.getCompanyHome();
}
 
Example 29
Project: alfresco-repository   File: TransformerConfigDynamicTransformers.java   View source code 5 votes vote down vote up
public TransformerConfigDynamicTransformers(TransformerConfig transformerConfig, TransformerProperties transformerProperties,
        MimetypeService mimetypeService, ContentService contentService, ContentTransformerRegistry transformerRegistry,
        TransformerDebug transformerDebug, ModuleService moduleService, DescriptorService descriptorService,
        Properties globalProperties)
{
    createDynamicTransformers(transformerConfig, transformerProperties, mimetypeService, contentService,
            transformerRegistry, transformerDebug, moduleService, descriptorService, globalProperties);
}
 
Example 30
Project: alfresco-repository   File: TransformerConfigDynamicTransformers.java   View source code 5 votes vote down vote up
private void setupContentTransformer2(TransformerSourceTargetSuffixValue property,
        TransformerConfig transformerConfig, MimetypeService mimetypeService,
        ContentService contentService, ContentTransformerRegistry transformerRegistry,
        TransformerDebug transformerDebug, boolean available,
        AbstractContentTransformer2 transformer, List<ContentTransformer> transformers,
        Properties globalProperties)
{
    try
    {
        // Throws an exception if it does not exist
        transformerRegistry.getTransformer(property.transformerName);
        throw new AlfrescoRuntimeException("Cannot create dynamic transformer "+
                property.transformerName+" as a transformer with that name already exists.");
    }
    catch (IllegalArgumentException e)
    {
        // good news it does not exist
    }
    
    // unregisteredBaseContentTransformer
    transformer.setMimetypeService(mimetypeService);
    transformer.setTransformerDebug(transformerDebug);
    transformer.setTransformerConfig(transformerConfig);
    transformer.setRegistry(transformerRegistry);

    // baseContentTransformer
    transformer.setRegisterTransformer(true);
    
    // AbstractContentTransformer2
    transformer.setBeanName(property.transformerName);
    transformer.setRegisterTransformer(available);
    transformer.setStrictMimeTypeCheck(getBoolean(globalProperties, "transformer.strict.mimetype.check"));
    transformer.setRetryTransformOnDifferentMimeType(getBoolean(globalProperties, "content.transformer.retryOn.different.mimetype"));
}
 
Example 31
Project: alfresco-repository   File: ContentServiceImplTest.java   View source code 5 votes vote down vote up
/**
 * Called during the transaction setup
 */
protected void onSetUpInTransaction() throws Exception
{
    super.onSetUpInTransaction();
    
    // Get the instance of the required content service
    this.contentService = (ContentService)this.applicationContext.getBean("contentService");
}
 
Example 32
Project: alfresco-repository   File: ScriptNode.java   View source code 5 votes vote down vote up
/**
 * Set the content stream from another content object.
 *  
 * @param content  ScriptContent to set
 */
public void write(Content content)
{
    ContentService contentService = services.getContentService();
    ContentWriter writer = contentService.getWriter(nodeRef, this.property, true);
    writer.setMimetype(content.getMimetype());
    writer.setEncoding(content.getEncoding());
    writer.putContent(content.getInputStream());

    // update cached variables after putContent()
    updateContentData(true);
}
 
Example 33
Project: alfresco-repository   File: RoutingContentServiceTest.java   View source code 5 votes vote down vote up
@Override
public void setUp() throws Exception
{
    ctx = ApplicationContextHelper.getApplicationContext();
    transactionService = (TransactionService) ctx.getBean("TransactionService");
    nodeService = (NodeService) ctx.getBean("NodeService");
    contentService = (ContentService) ctx.getBean(ServiceRegistry.CONTENT_SERVICE.getLocalName());
    this.policyComponent = (PolicyComponent) ctx.getBean("policyComponent");
    this.authenticationComponent = (AuthenticationComponent) ctx.getBean("authenticationComponent");
    
    // authenticate
    this.authenticationComponent.setSystemUserAsCurrentUser();
    
    // start the transaction
    txn = getUserTransaction();
    txn.begin();
    
    // create a store and get the root node
    StoreRef storeRef = new StoreRef(StoreRef.PROTOCOL_WORKSPACE, getName());
    if (!nodeService.exists(storeRef))
    {
        storeRef = nodeService.createStore(storeRef.getProtocol(), storeRef.getIdentifier());
    }
    rootNodeRef = nodeService.getRootNode(storeRef);
    // create a content node
    ContentData contentData = new ContentData(null, "text/plain", 0L, "UTF-16", Locale.CHINESE);
    
    PropertyMap properties = new PropertyMap();
    properties.put(ContentModel.PROP_CONTENT, contentData);
    
    ChildAssociationRef assocRef = nodeService.createNode(
            rootNodeRef,
            ContentModel.ASSOC_CHILDREN,
            QName.createQName(TEST_NAMESPACE, GUID.generate()),
            ContentModel.TYPE_CONTENT,
            properties);
    contentNodeRef = assocRef.getChildRef();
}
 
Example 34
Project: alfresco-repository   File: BaseContentNode.java   View source code 5 votes vote down vote up
/**
 * @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 35
Project: alfresco-repository   File: DownloadServiceIntegrationTest.java   View source code 5 votes vote down vote up
@BeforeClass public static void init()
{
    // Resolve required services
    CHECK_OUT_CHECK_IN_SERVICE = APP_CONTEXT_INIT.getApplicationContext().getBean("CheckOutCheckInService", CheckOutCheckInService.class);
    CONTENT_SERVICE = APP_CONTEXT_INIT.getApplicationContext().getBean("contentService", ContentService.class);
    DOWNLOAD_SERVICE = APP_CONTEXT_INIT.getApplicationContext().getBean("DownloadService", DownloadService.class);
    NODE_SERVICE = APP_CONTEXT_INIT.getApplicationContext().getBean("NodeService", NodeService.class);
    PERMISSION_SERVICE = APP_CONTEXT_INIT.getApplicationContext().getBean("PermissionService", PermissionService.class);
    TRANSACTION_HELPER = APP_CONTEXT_INIT.getApplicationContext().getBean("retryingTransactionHelper", RetryingTransactionHelper.class);
    INTEGRITY_CHECKER = APP_CONTEXT_INIT.getApplicationContext().getBean("integrityChecker", IntegrityChecker.class);
    INTEGRITY_CHECKER.setEnabled(true);
    INTEGRITY_CHECKER.setFailOnViolation(true);
    INTEGRITY_CHECKER.setTraceOn(true);
}
 
Example 36
Project: alfresco-repository   File: TemporaryNodes.java   View source code 5 votes vote down vote up
/**
 * 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 37
Project: alfresco-repository   File: ContentMetadataExtracterTest.java   View source code 5 votes vote down vote up
@Override
protected void onSetUpInTransaction() throws Exception
{
    this.nodeService = (NodeService) this.applicationContext.getBean("nodeService");
    this.contentService = (ContentService) this.applicationContext.getBean("contentService");
    
    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 = (ContentMetadataExtracter) this.applicationContext.getBean("extract-metadata");
}
 
Example 38
Project: alfresco-repository   File: ContentDiskDriver.java   View source code 4 votes vote down vote up
/**
 * @param contentService the content service
 */
public void setContentService(ContentService contentService)
{
    this.contentService = contentService;
}
 
Example 39
Project: alfresco-repository   File: ContentQuotaManager.java   View source code 4 votes vote down vote up
public void setContentService(ContentService contentService)
{
    this.contentService = contentService;
}
 
Example 40
Project: alfresco-repository   File: ContentDiskDriver2.java   View source code 4 votes vote down vote up
/**
 * @param contentService the content service
 */
public void setContentService(ContentService contentService)
{
    this.contentService = contentService;
}