Java Code Examples for org.alfresco.service.cmr.repository.StoreRef#PROTOCOL_WORKSPACE

The following examples show how to use org.alfresco.service.cmr.repository.StoreRef#PROTOCOL_WORKSPACE . 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 check out the related API usage on the sidebar.
Example 1
Source File: HasTagEvaluatorTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Before
public void before() throws Exception
{
    this.nodeService = (NodeService)applicationContext.getBean("nodeService");
    this.taggingService = (TaggingService)applicationContext.getBean("taggingService");
    
    // Create the store and get the root node
    this.testStoreRef = new StoreRef(StoreRef.PROTOCOL_WORKSPACE, "SpacesStore");
    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();
    
    this.evaluator = (HasTagEvaluator)applicationContext.getBean(HasTagEvaluator.NAME);        
    AuthenticationUtil.setFullyAuthenticatedUser("admin");
}
 
Example 2
Source File: RuleServiceTest.java    From alfresco-remote-api with GNU Lesser General Public License v3.0 6 votes vote down vote up
private void createTestFolders()
{
    StoreRef testStore = new StoreRef(StoreRef.PROTOCOL_WORKSPACE, TEST_STORE_IDENTIFIER);

    if (!nodeService.exists(testStore))
    {
        testStore = nodeService.createStore(StoreRef.PROTOCOL_WORKSPACE, TEST_STORE_IDENTIFIER);
    }

    NodeRef rootNodeRef = nodeService.getRootNode(testStore);

    testWorkNodeRef = nodeService.createNode(rootNodeRef, ContentModel.ASSOC_CHILDREN, QName.createQName("{test}testnode"), ContentModel.TYPE_FOLDER).getChildRef();

    testNodeRef = fileFolderService.create(testWorkNodeRef, TEST_FOLDER, ContentModel.TYPE_FOLDER).getNodeRef();
    testNodeRef2 = fileFolderService.create(testWorkNodeRef, TEST_FOLDER_2, ContentModel.TYPE_FOLDER).getNodeRef();
}
 
Example 3
Source File: ContentStoreCleanerScalabilityRunner.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Creates a node with two properties
 */
public void makeNode(ContentData contentData)
{
    StoreRef storeRef = new StoreRef(StoreRef.PROTOCOL_WORKSPACE, "SpacesStore");
    Long rootNodeId = nodeDAO.newStore(storeRef).getFirst();
    ChildAssocEntity assoc = nodeDAO.newNode(
            rootNodeId,
            ContentModel.ASSOC_CHILDREN,
            ContentModel.ASSOC_CHILDREN,
            storeRef,
            null,
            ContentModel.TYPE_CONTENT,
            I18NUtil.getLocale(),
            null,
            null);
    Long nodeId = assoc.getChildNode().getId();
    nodeDAO.addNodeProperty(nodeId, contentQName, contentData);
}
 
Example 4
Source File: NodeRefRadixHasherTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Test
public void testSupportedStores() throws Exception
{
    NodeRefRadixHasher h = NodeRefRadixHasher.RADIX_36_HASHER;
    
    String[] storeProtocols = new String[] { StoreRef.PROTOCOL_WORKSPACE, StoreRef.PROTOCOL_ARCHIVE,
                StoreRef.PROTOCOL_AVM, StoreRef.PROTOCOL_DELETED, VersionService.VERSION_STORE_PROTOCOL };
    String[] storeIds = new String[] { "SpacesStore", VersionModel.STORE_ID, Version2Model.STORE_ID };

    for (int i = 0; i < storeProtocols.length; i++)
    {
        for (int j = 0; j < storeIds.length; j++)
        {
            NodeRef nr = new NodeRef(storeProtocols[i],
                                     storeIds[j],
                                     "0d3b26ff-c4c1-4680-8622-8608ea7ab4b2");
            Pair<String, String> nh = h.hash(nr);
            NodeRef nr2 = h.lookup(nh);
            assertEquals("Could match hash-lookup " + nr,
                         nr,
                         nr2);
        }
    }
}
 
Example 5
Source File: ComponentsTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
private NodeRef getLoadedCategoryRoot()
{
    StoreRef storeRef = new StoreRef(StoreRef.PROTOCOL_WORKSPACE, "SpacesStore");
    
    CategoryService categoryService = serviceRegistry.getCategoryService();
    // Check if the categories exist
    Collection<ChildAssociationRef> assocRefs = categoryService.getRootCategories(
            storeRef,
            ContentModel.ASPECT_GEN_CLASSIFIABLE);
    // Find it
    for (ChildAssociationRef assocRef : assocRefs)
    {
        NodeRef nodeRef = assocRef.getChildRef();
        if (nodeRef.getId().equals("test:xyz-root"))
        {
            // Found it
            return nodeRef;
        }
    }
    return null;
}
 
Example 6
Source File: FileFolderPerformanceTester.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
protected NodeRef getOrCreateRootFolder()
{
    // find the company home folder
    StoreRef storeRef = new StoreRef(StoreRef.PROTOCOL_WORKSPACE, "SpacesStore");
    NodeRef storeRootNodeRef = nodeService.getRootNode(storeRef);
    List<NodeRef> results = searchService.selectNodes(
            storeRootNodeRef,
            "/app:company_home",
            null,
            namespaceService,
            false,
            SearchService.LANGUAGE_XPATH);
    if (results.size() == 0)
    {
        throw new AlfrescoRuntimeException("Didn't find Company Home");
    }
    NodeRef companyHomeNodeRef = results.get(0);
    return fileFolderService.create(
            companyHomeNodeRef,
            getName() + "_" + System.currentTimeMillis(),
            ContentModel.TYPE_FOLDER).getNodeRef();
}
 
Example 7
Source File: VersionHistoryImplTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Set up
 */
protected void setUp() throws Exception
{
    super.setUp();
    
    // Create dummy node ref
    nodeRef = new NodeRef(new StoreRef(StoreRef.PROTOCOL_WORKSPACE, "test"), "test");
    
    this.rootVersion = newVersion(nodeRef, "1");
    this.childVersion1 = newVersion(nodeRef, "2");
    this.childVersion2 = newVersion(nodeRef, "3");
}
 
Example 8
Source File: ImporterComponentTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Test
public void testBootstrap()
{
    StoreRef bootstrapStoreRef = new StoreRef(StoreRef.PROTOCOL_WORKSPACE, "Test_" + System.currentTimeMillis());
    importerBootstrap.setStoreUrl(bootstrapStoreRef.toString());
    importerBootstrap.bootstrap();
    authenticationComponent.setSystemUserAsCurrentUser();
    System.out.println(NodeStoreInspector.dumpNodeStore(nodeService, bootstrapStoreRef));
}
 
Example 9
Source File: MultiTServiceImplTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Before
public void setUp() throws Exception
{
    multiTServiceImpl = applicationContext.getBean("tenantService", MultiTServiceImpl.class);
    tenantAdminService = applicationContext.getBean("tenantAdminService", TenantAdminService.class);
    personService = applicationContext.getBean("PersonService", PersonService.class);
    tenantService = applicationContext.getBean("tenantService", TenantService.class);
    authenticationService = applicationContext.getBean("AuthenticationService", MutableAuthenticationService.class);
    transactionService = applicationContext.getBean("TransactionService", TransactionService.class);
    nodeService = applicationContext.getBean("NodeService", NodeService.class);
    searchService = applicationContext.getBean("SearchService", SearchService.class);
    namespaceService = applicationContext.getBean("NamespaceService", NamespaceService.class);

    DOMAIN = GUID.generate();
    USER1 = GUID.generate();
    USER2 = GUID.generate();
    USER3 = GUID.generate();
    USER2_WITH_DOMAIN = USER2 + TenantService.SEPARATOR + DOMAIN;
    STRING = GUID.generate();
    TENANT_STRING = addDomainToId(STRING, DOMAIN);
    STRING_WITH_EXISTENT_DOMAIN = TenantService.SEPARATOR + DOMAIN + TenantService.SEPARATOR;
    STRING_WITH_NONEXITENT_DOMAIN = TenantService.SEPARATOR + STRING + TenantService.SEPARATOR;
    TENANT_STORE = new StoreRef(StoreRef.PROTOCOL_WORKSPACE, addDomainToId("SpacesStore", DOMAIN));
    TENANT_NODE_REF = new NodeRef(PROTOCOL, addDomainToId(IDENTIFIER, DOMAIN), ID);
    TENANT_STORE_REF = new StoreRef(PROTOCOL, addDomainToId(IDENTIFIER, DOMAIN));
    TENANT_QNAME = QName.createQName(addDomainToId(NAMESPACE_URI, DOMAIN), LOCAL_NAME);
    tenantAssocRef = new AssociationRef(TENANT_NODE_REF, QNAME, TENANT_NODE_REF);
    childAssocRef = new ChildAssociationRef(QNAME, NODE_REF, QNAME, NODE_REF);
    tenantChildAssocRef = new ChildAssociationRef(QNAME, TENANT_NODE_REF, QNAME, TENANT_NODE_REF);

    AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getAdminUserName());

    mtEnabled = AuthenticationUtil.isMtEnabled();
    AuthenticationUtil.setMtEnabled(false);
}
 
Example 10
Source File: RoutingContentServiceTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 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());
    copyService = (CopyService) ctx.getBean("CopyService");
    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);

    ChildAssociationRef assocRef = nodeService.createNode(
            rootNodeRef,
            ContentModel.ASSOC_CHILDREN,
            QName.createQName(TEST_NAMESPACE, GUID.generate()),
            ContentModel.TYPE_CONTENT);
    contentNodeRef = assocRef.getChildRef();

    ContentWriter writer = contentService.getWriter(contentNodeRef, ContentModel.PROP_CONTENT, true);
    writer.setEncoding("UTF-16");
    writer.setLocale(Locale.CHINESE);
    writer.setMimetype("text/plain");
    writer.putContent("sample content");
}
 
Example 11
Source File: AbstractMultilingualTestCases.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
protected void setUp() throws Exception
{
    nodeArchiveService = (NodeArchiveService) ctx.getBean("nodeArchiveService");
    serviceRegistry = (ServiceRegistry) ctx.getBean(ServiceRegistry.SERVICE_REGISTRY);
    authenticationComponent = (AuthenticationComponent) ctx.getBean("AuthenticationComponent");
    transactionService = serviceRegistry.getTransactionService();
    nodeService = serviceRegistry.getNodeService();
    fileFolderService = serviceRegistry.getFileFolderService();
    versionService = serviceRegistry.getVersionService();
    multilingualContentService = (MultilingualContentService) ctx.getBean("MultilingualContentService");
    contentFilterLanguagesService = (ContentFilterLanguagesService) ctx.getBean("ContentFilterLanguagesService");
    editionService = (EditionService) ctx.getBean("EditionService");

    // Run as admin
    authenticationComponent.setCurrentUser(AuthenticationUtil.getAdminUserName());

    // Create a folder to work in
    RetryingTransactionCallback<NodeRef> createFolderCallback = new RetryingTransactionCallback<NodeRef>()
    {
        public NodeRef execute() throws Exception
        {
            StoreRef storeRef = new StoreRef(StoreRef.PROTOCOL_WORKSPACE, "SpacesStore");
            NodeRef rootNodeRef = nodeService.getRootNode(storeRef);
            // Create the folder
            NodeRef folderNodeRef = nodeService.createNode(
                    rootNodeRef,
                    ContentModel.ASSOC_CHILDREN,
                    QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, "testFolder"),
                    ContentModel.TYPE_FOLDER).getChildRef();
            // done
            return folderNodeRef;
        }
    };
    folderNodeRef = transactionService.getRetryingTransactionHelper().doInTransaction(createFolderCallback);
}
 
Example 12
Source File: OutputSpacesStoreSystemTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Dump the contents of the spaces store to standard out
 */
public void testDumpSpacesStore()
{
    NodeService nodeService = (NodeService)this.applicationContext.getBean("nodeService");
    StoreRef spacesStore = new StoreRef(StoreRef.PROTOCOL_WORKSPACE, "SpacesStore");
    System.out.println(NodeStoreInspector.dumpNodeStore(nodeService, spacesStore));
}
 
Example 13
Source File: VersionServiceImpl.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Gets the reference to the version store
 *
 * @return  reference to the version store
 */
@Override
public StoreRef getVersionStoreReference()
{
    if (logger.isDebugEnabled())
    {
        logger.debug("Run as user " + AuthenticationUtil.getRunAsUser());
        logger.debug("Fully authenticated " + AuthenticationUtil.getFullyAuthenticatedUser());
    }
    
    return new StoreRef(
            StoreRef.PROTOCOL_WORKSPACE,
            VersionModel.STORE_ID);
}
 
Example 14
Source File: Version2ServiceImpl.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
@Extend(extensionAPI=VersionServiceExtension.class,traitAPI=VersionServiceTrait.class)
public StoreRef getVersionStoreReference()
{
    if (logger.isDebugEnabled())
    {
        logger.debug("Run as user " + AuthenticationUtil.getRunAsUser());
        logger.debug("Fully authenticated " + AuthenticationUtil.getFullyAuthenticatedUser());
    }
    
    return new StoreRef(StoreRef.PROTOCOL_WORKSPACE, Version2Model.STORE_ID);
}
 
Example 15
Source File: IncompleteNodeTaggerTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 4 votes vote down vote up
public void setUp() throws Exception
{
    ApplicationContext ctx = ApplicationContextHelper.getApplicationContext();
    DictionaryDAO dictionaryDao = (DictionaryDAO) ctx.getBean("dictionaryDAO");
    ClassLoader cl = BaseNodeServiceTest.class.getClassLoader();
    // load the test model
    InputStream modelStream = cl.getResourceAsStream("org/alfresco/repo/node/integrity/IntegrityTest_model.xml");
    assertNotNull(modelStream);
    M2Model model = M2Model.createModel(modelStream);
    dictionaryDao.putModel(model);

    tagger = (IncompleteNodeTagger) ctx.getBean("incompleteNodeTagger");

    serviceRegistry = (ServiceRegistry) ctx.getBean(ServiceRegistry.SERVICE_REGISTRY);
    nodeService = serviceRegistry.getNodeService();
    authenticationService = serviceRegistry.getAuthenticationService();
    permissionService = serviceRegistry.getPermissionService();
    this.authenticationComponent = (AuthenticationComponent) ctx.getBean("authenticationComponent");
    
    this.authenticationComponent.setSystemUserAsCurrentUser();
    
    String user = getName();
    if (!authenticationService.authenticationExists(user))
    {
        authenticationService.createAuthentication(user, user.toCharArray());
    }
    
    // begin a transaction
    TransactionService transactionService = serviceRegistry.getTransactionService();
    txn = transactionService.getUserTransaction();
    txn.begin();
    StoreRef storeRef = new StoreRef(StoreRef.PROTOCOL_WORKSPACE, getName());
    if (!nodeService.exists(storeRef))
    {
        nodeService.createStore(storeRef.getProtocol(), storeRef.getIdentifier());
        rootNodeRef = nodeService.getRootNode(storeRef);
        // Make sure our user can do everything
        permissionService.setPermission(rootNodeRef, user, PermissionService.ALL_PERMISSIONS, true);
    }
    else
    {
        rootNodeRef = nodeService.getRootNode(storeRef);
    }
    
    properties = new PropertyMap();
    properties.put(IntegrityTest.TEST_PROP_TEXT_C, "abc");
    
    // Authenticate as a test-specific user
    authenticationComponent.setCurrentUser(user);
}
 
Example 16
Source File: UnlockMethodTest.java    From alfresco-remote-api with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * Set up preconditions for unlock a checked out node
 */
protected void setUpPreconditionForCheckedOutTest() throws Exception
{
    appContext = ApplicationContextHelper.getApplicationContext(new String[]
    {
        "classpath:alfresco/application-context.xml", "classpath:alfresco/web-scripts-application-context.xml",
        "classpath:alfresco/remote-api-context.xml"
    });

    // Set the services
    this.cociService = (CheckOutCheckInService) appContext.getBean("checkOutCheckInService");
    this.contentService = (ContentService) appContext.getBean("contentService");
    this.authenticationService = (MutableAuthenticationService) appContext.getBean("authenticationService");
    this.permissionService = (PermissionService) appContext.getBean("permissionService");
    this.transactionService = (TransactionService) appContext.getBean("TransactionService");
    this.nodeService = (NodeService) appContext.getBean("NodeService");
    // Authenticate as system to create initial test data set
    this.authenticationComponent = (AuthenticationComponent) appContext.getBean("authenticationComponent");
    this.authenticationComponent.setSystemUserAsCurrentUser();

    RetryingTransactionCallback<Void> createTestFileCallback = new RetryingTransactionCallback<Void>()
    {
        @Override
        public Void execute() throws Throwable
        {
            // Create the store and get the root node reference
            storeRef = new StoreRef(StoreRef.PROTOCOL_WORKSPACE, TEST_STORE_IDENTIFIER);
            if (!nodeService.exists(storeRef))
            {
                storeRef = nodeService.createStore(StoreRef.PROTOCOL_WORKSPACE, TEST_STORE_IDENTIFIER);
            }
            rootNodeRef = nodeService.getRootNode(storeRef);

            // Create and authenticate the user
            userName = "webdavUnlockTest" + GUID.generate();
            TestWithUserUtils.createUser(userName, PWD, rootNodeRef, nodeService, authenticationService);
            permissionService.setPermission(rootNodeRef, userName, PermissionService.ALL_PERMISSIONS, true);
            TestWithUserUtils.authenticateUser(userName, PWD, rootNodeRef, authenticationService);
            userNodeRef = TestWithUserUtils.getCurrentUser(authenticationService);

            // create test file in test folder
            folderNodeRef = nodeService.createNode(rootNodeRef, ContentModel.ASSOC_CHILDREN, QName.createQName("test"), ContentModel.TYPE_FOLDER,
                    Collections.<QName, Serializable> singletonMap(ContentModel.PROP_NAME, "folder")).getChildRef();
            fileNodeRef = nodeService.createNode(folderNodeRef, ContentModel.ASSOC_CONTAINS, QName.createQName("test"), ContentModel.TYPE_CONTENT,
                    Collections.<QName, Serializable> singletonMap(ContentModel.PROP_NAME, TEST_FILE_NAME)).getChildRef();
            ContentWriter contentWriter = contentService.getWriter(fileNodeRef, ContentModel.PROP_CONTENT, true);
            contentWriter.setMimetype("text/plain");
            contentWriter.setEncoding("UTF-8");
            contentWriter.putContent(CONTENT_1);

            // Check out test file
            fileWorkingCopyNodeRef = cociService.checkout(fileNodeRef);
            assertNotNull(fileWorkingCopyNodeRef);
            assertEquals(userNodeRef, nodeService.getProperty(fileNodeRef, ContentModel.PROP_LOCK_OWNER));

            return null;
        }

    };
    this.transactionService.getRetryingTransactionHelper().doInTransaction(createTestFileCallback);
}
 
Example 17
Source File: UserUsageTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 4 votes vote down vote up
protected void setUp() throws Exception
{
    applicationContext = ApplicationContextHelper.getApplicationContext();
    if (AlfrescoTransactionSupport.isActualTransactionActive())
    {
        fail("Test started with transaction in progress");
    }
    
    nodeService = (NodeService) applicationContext.getBean("nodeService");
    fileFolderService = (FileFolderService) applicationContext.getBean("fileFolderService");
    
    authenticationService = (MutableAuthenticationService) applicationContext.getBean("authenticationService");
    authenticationComponent = (AuthenticationComponent) applicationContext.getBean("authenticationComponent");
    
    authenticationComponent.setCurrentUser(authenticationComponent.getSystemUserName());
    authenticationDAO = (MutableAuthenticationDao) applicationContext.getBean("authenticationDao");
    transactionService = (TransactionService) applicationContext.getBean("transactionComponent");
    
    contentService = (ContentService) applicationContext.getBean("contentService");
    personService = (PersonService) applicationContext.getBean("personService");
    
    contentUsageImpl = (ContentUsageImpl) applicationContext.getBean("contentUsageImpl");
    usageService = (UsageService) applicationContext.getBean("usageService");
    
    ownableService = (OwnableService) applicationContext.getBean("ownableService");
    
    repoAdminService = (RepoAdminService) applicationContext.getBean("repoAdminService");
    
    testTX = transactionService.getUserTransaction();
    testTX.begin();
    //Authenticate as the admin user
    AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getAdminUserName());
    
    // get default store (as configured for content usage service)
    StoreRef storeRef = new StoreRef(StoreRef.PROTOCOL_WORKSPACE, "SpacesStore");
    rootNodeRef = nodeService.getRootNode(storeRef);
    
    // create test users
    createTestUsers();
    
    // deploy custom model
    InputStream modelStream = getClass().getClassLoader().getResourceAsStream("tenant/exampleModel.xml");
    repoAdminService.deployModel(modelStream, "exampleModel.xml");
    
    testTX.commit();
    
    authenticationComponent.clearCurrentSecurityContext();
    
    testTX = transactionService.getUserTransaction();
    testTX.begin();
}
 
Example 18
Source File: IntegrityTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 4 votes vote down vote up
public void setUp() throws Exception
{
    ApplicationContext ctx = ApplicationContextHelper.getApplicationContext();
    DictionaryDAO dictionaryDao = (DictionaryDAO) ctx.getBean("dictionaryDAO");
    ClassLoader cl = BaseNodeServiceTest.class.getClassLoader();
    // load the test model
    InputStream modelStream = cl.getResourceAsStream("org/alfresco/repo/node/integrity/IntegrityTest_model.xml");
    assertNotNull(modelStream);
    M2Model model = M2Model.createModel(modelStream);
    dictionaryDao.putModel(model);

    integrityChecker = (IntegrityChecker) ctx.getBean("integrityChecker");
    integrityChecker.setEnabled(true);
    integrityChecker.setFailOnViolation(true);
    integrityChecker.setTraceOn(true);
    integrityChecker.setMaxErrorsPerTransaction(100);   // we want to count the correct number of errors
    
    MetadataEncryptor encryptor = (MetadataEncryptor) ctx.getBean("metadataEncryptor");

    serviceRegistry = (ServiceRegistry) ctx.getBean(ServiceRegistry.SERVICE_REGISTRY);
    nodeService = serviceRegistry.getNodeService();
    this.authenticationComponent = (AuthenticationComponent)ctx.getBean("authenticationComponent");
    
    this.authenticationComponent.setSystemUserAsCurrentUser();
    
    // begin a transaction
    TransactionService transactionService = serviceRegistry.getTransactionService();
    txn = transactionService.getUserTransaction();
    txn.begin();
    StoreRef storeRef = new StoreRef(StoreRef.PROTOCOL_WORKSPACE, getName());
    if (!nodeService.exists(storeRef))
    {
        nodeService.createStore(storeRef.getProtocol(), storeRef.getIdentifier());
    }
    rootNodeRef = nodeService.getRootNode(storeRef);
    
    allProperties = new PropertyMap();
    allProperties.put(TEST_PROP_TEXT_A, "ABC");
    allProperties.put(TEST_PROP_TEXT_B, "DEF");
    allProperties.put(TEST_PROP_INT_A, "123");
    allProperties.put(TEST_PROP_INT_B, "456");
    allProperties.put(TEST_PROP_ENCRYPTED_A, "ABC");
    allProperties.put(TEST_PROP_ENCRYPTED_B, "DEF");
    allProperties = encryptor.encrypt(allProperties);
}
 
Example 19
Source File: Version2ServiceImpl.java    From alfresco-repository with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * Check if versions are marked with invalid version label, if true > apply default serial version label (e.g. "1.0", "1.1") 
 * 
 * @param versionHistory a version history node reference
 * @param nodeRef a node reference
 */
private void checkForCorruptedVersions(NodeRef versionHistory, NodeRef nodeRef)
{
    // get the current version label in live store
    String versionLabel = (String) this.nodeService.getProperty(nodeRef, ContentModel.PROP_VERSION_LABEL);

    if (versionLabel != null && versionLabel.equals("0"))
    {
        // need to correct version labels
        List<Version> versions = getAllVersions(versionHistory);

        // sort versions by node id
        Collections.sort(versions, new Comparator<Version>()
        {

            public int compare(Version v1, Version v2)
            {
                int result = v1.getFrozenModifiedDate().compareTo(v2.getFrozenModifiedDate());
                if (result == 0)
                {
                    Long dbid1 = (Long)nodeService.getProperty(v1.getFrozenStateNodeRef(), ContentModel.PROP_NODE_DBID);
                    Long dbid2 = (Long)nodeService.getProperty(v2.getFrozenStateNodeRef(), ContentModel.PROP_NODE_DBID);
                    
                    if (dbid1 != null && dbid2 != null)
                    {
                        result = dbid1.compareTo(dbid2);
                    }
                    else
                    {
                        result = 0;
                        
                        if (logger.isWarnEnabled())
                        {
                            logger.warn("node-dbid property is missing for versions: " + v1.toString() + " or " + v2.toString());
                        }
                    }
                }
                return result;
            }

        });

        SerialVersionLabelPolicy serialVersionLabelPolicy = new SerialVersionLabelPolicy();
        QName classRef = this.nodeService.getType(nodeRef);
        Version preceedingVersion = null;

        for (Version version : versions)
        {
            // re-calculate version label
            versionLabel = serialVersionLabelPolicy.calculateVersionLabel(classRef, preceedingVersion, 0, version.getVersionProperties());

            // update version with new version label
            NodeRef versionNodeRef = new NodeRef(StoreRef.PROTOCOL_WORKSPACE, version.getFrozenStateNodeRef().getStoreRef().getIdentifier(), version.getFrozenStateNodeRef()
                    .getId());
            this.dbNodeService.setProperty(versionNodeRef, Version2Model.PROP_QNAME_VERSION_LABEL, versionLabel);
            
            version.getVersionProperties().put(VersionBaseModel.PROP_VERSION_LABEL, versionLabel);

            // remember preceding version
            preceedingVersion = version;
        }

        // update current version label in live store
        this.nodeService.setProperty(nodeRef, ContentModel.PROP_VERSION_LABEL, versionLabel);
    }
}
 
Example 20
Source File: VersionUtil.java    From alfresco-repository with GNU Lesser General Public License v3.0 2 votes vote down vote up
/**
 * Create Version Store Ref
 * 
 * @param  storeRef ref
 * @return  store ref for version store
 */
public static StoreRef convertStoreRef(StoreRef storeRef)
{
    return new StoreRef(StoreRef.PROTOCOL_WORKSPACE, storeRef.getIdentifier());
}