Java Code Examples for org.alfresco.service.ServiceRegistry#getCheckOutCheckInService()

The following examples show how to use org.alfresco.service.ServiceRegistry#getCheckOutCheckInService() . 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: CheckOutCheckInServiceImplTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * <br>
 * Creating node - CheckOut - Add write lock to working copy - Unlock working copy - CancelCheckOut
 */
@Test
public void testCancelCheckoutUnlockedWCopy()
{
    ServiceRegistry serviceRegistry = (ServiceRegistry)this.applicationContext.getBean(ServiceRegistry.SERVICE_REGISTRY);
    CheckOutCheckInService securityCOCIService = serviceRegistry.getCheckOutCheckInService();
    NodeRef folderA = createFolder(rootNodeRef, "testMnt9502_" + System.currentTimeMillis());
    assertNotNull(folderA);
    NodeRef clucc = createContent("checkout_lock_unlock_cancelCO", folderA);
    assertNotNull(clucc);
    
    NodeRef wc = securityCOCIService.checkout(clucc);
    lockService.lock(wc, LockType.WRITE_LOCK, 60*60);
    lockService.unlock(wc);
    securityCOCIService.cancelCheckout(wc);
}
 
Example 2
Source File: FileFolderServiceImplTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
public void setUp() throws Exception
{
    ServiceRegistry serviceRegistry = (ServiceRegistry) ctx.getBean("ServiceRegistry");
    transactionService = serviceRegistry.getTransactionService();
    nodeService = serviceRegistry.getNodeService();
    fileFolderService = serviceRegistry.getFileFolderService();
    permissionService = serviceRegistry.getPermissionService();
    authenticationService = (MutableAuthenticationService) ctx.getBean("AuthenticationService");
    dictionaryDAO = (DictionaryDAO) ctx.getBean("dictionaryDAO");
    tenantService = (TenantService) ctx.getBean("tenantService");
    cociService = serviceRegistry.getCheckOutCheckInService();
    
    // start the transaction
    txn = transactionService.getUserTransaction();
    txn.begin();

    // downgrade integrity
    IntegrityChecker.setWarnInTransaction();

    // authenticate
    AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getAdminUserName());

    // create a test store
    StoreRef storeRef = nodeService
            .createStore(StoreRef.PROTOCOL_WORKSPACE, getName() + System.currentTimeMillis());
    rootNodeRef = nodeService.getRootNode(storeRef);

    // create a folder to import into
    workingRootNodeRef = nodeService.createNode(
            rootNodeRef,
            ContentModel.ASSOC_CHILDREN,
            QName.createQName(NamespaceService.ALFRESCO_URI, "working root"),
            ContentModel.TYPE_FOLDER).getChildRef();

    // import the test data
    ImporterService importerService = serviceRegistry.getImporterService();
    Location importLocation = new Location(workingRootNodeRef);
    InputStream is = getClass().getClassLoader().getResourceAsStream(IMPORT_VIEW);
    if (is == null)
    {
        throw new NullPointerException("Test resource not found: " + IMPORT_VIEW);
    }
    Reader reader = new InputStreamReader(is);
    importerService.importView(reader, importLocation, null, null);

    // Load test model
    DictionaryBootstrap bootstrap = new DictionaryBootstrap();
    List<String> bootstrapModels = new ArrayList<String>();
    bootstrapModels.add("org/alfresco/repo/model/filefolder/testModel.xml");
    List<String> labels = new ArrayList<String>();
    bootstrap.setModels(bootstrapModels);
    bootstrap.setLabels(labels);
    bootstrap.setDictionaryDAO(dictionaryDAO);
    bootstrap.setTenantService(tenantService);
    bootstrap.bootstrap();
    
    workingRootNodeRef1 = nodeService.createNode(
            rootNodeRef,
            ContentModel.ASSOC_CHILDREN,
            QName.createQName(NamespaceService.ALFRESCO_URI, "working root1"),
            QName.createQName("http://www.alfresco.org/test/filefoldertest/1.0", "folder")).getChildRef();
    nodeService.createNode(
            workingRootNodeRef1,
            ContentModel.ASSOC_CONTAINS,
            QName.createQName(NamespaceService.ALFRESCO_URI, "node1"),
            ContentModel.TYPE_CONTENT).getChildRef();
    nodeService.createNode(
            workingRootNodeRef1,
            QName.createQName("http://www.alfresco.org/test/filefoldertest/1.0", "contains1"),
            QName.createQName(NamespaceService.ALFRESCO_URI, "node2"),
            ContentModel.TYPE_CONTENT).getChildRef();
    
    // Make sure we hit the MLTranslationInterceptor, which is part of the Foundation API
    // See MNT-9114: FileFolderService method not registered in MLTranslationInterceptor
    I18NUtil.setContentLocale(Locale.ENGLISH);
}
 
Example 3
Source File: DocumentLinkServiceImplTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
public void setUp() throws Exception
{
    ctx = ApplicationContextHelper.getApplicationContext();
    // Set up the services
    ServiceRegistry serviceRegistry = (ServiceRegistry) ctx.getBean("ServiceRegistry");
    transactionService = serviceRegistry.getTransactionService();
    documentLinkService = serviceRegistry.getDocumentLinkService();
    permissionService = serviceRegistry.getPermissionService();
    personService = serviceRegistry.getPersonService();
    siteService = serviceRegistry.getSiteService();
    fileFolderService = serviceRegistry.getFileFolderService();
    nodeService = serviceRegistry.getNodeService();
    cociService = serviceRegistry.getCheckOutCheckInService();

    // Start the transaction
    txn = transactionService.getUserTransaction();
    txn.begin();

    // Authenticate
    AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getAdminUserName());

    /* Create the test user */
    Map<QName, Serializable> props = new HashMap<QName, Serializable>();
    props.put(ContentModel.PROP_USERNAME, TEST_USER);
    personService.createPerson(props);

    /*
     * Create the working test root 1 to which the user has read/write
     * permission
     */
    site1 = siteService.createSite("site1", GUID.generate(), "myTitle", "myDescription", SiteVisibility.PUBLIC).getNodeRef();
    permissionService.setPermission(site1, TEST_USER, PermissionService.ALL_PERMISSIONS, true);
    site1Folder1 = fileFolderService.create(site1, site1Folder1Name, ContentModel.TYPE_FOLDER).getNodeRef();
    site1File1 = fileFolderService.create(site1Folder1, site1File1Name, ContentModel.TYPE_CONTENT).getNodeRef();
    site1File2 = fileFolderService.create(site1Folder1, GUID.generate(), ContentModel.TYPE_CONTENT).getNodeRef();
    site1Folder2 = fileFolderService.create(site1, GUID.generate(), ContentModel.TYPE_FOLDER).getNodeRef();
    site1Folder3 = fileFolderService.create(site1, GUID.generate(), ContentModel.TYPE_FOLDER).getNodeRef();
    // create a link of site1File1 in site1Folder3 to test regular deletion
     documentLinkService.createDocumentLink(site1File2, site1Folder3);

    /* Create the working test root 2 to which the user has no permission */
    NodeRef site2 = siteService.createSite("site2", GUID.generate(), "myTitle", "myDescription", SiteVisibility.PRIVATE).getNodeRef();
    permissionService.setPermission(site2, TEST_USER, PermissionService.ALL_PERMISSIONS, false);
    site2File = fileFolderService.create(site2, GUID.generate(), ContentModel.TYPE_CONTENT).getNodeRef();
    site2Folder1 = fileFolderService.create(site2, GUID.generate(), ContentModel.TYPE_FOLDER).getNodeRef();
    site2Folder2 = fileFolderService.create(site2, GUID.generate(), ContentModel.TYPE_FOLDER).getNodeRef();
    // Create a link of site1File1 in site2Folder2 to test the deletion
    // without permission
    linkOfFile1Site2 = documentLinkService.createDocumentLink(site1File2, site2Folder2);
}
 
Example 4
Source File: OpenCmisLocalTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * MNT-14687 - Creating a document as checkedout and then cancelling the
 * checkout should delete the document.
 * 
 * This test would have fit better within CheckOutCheckInServiceImplTest but
 * was added here to make use of existing methods
 */
public void testCancelCheckoutWhileInCheckedOutState()
{
    ServiceRegistry serviceRegistry = (ServiceRegistry) ctx.getBean(ServiceRegistry.SERVICE_REGISTRY);
    CheckOutCheckInService cociService = serviceRegistry.getCheckOutCheckInService();

    // Authenticate as system
    AuthenticationComponent authenticationComponent = (AuthenticationComponent) ctx.getBean(BEAN_NAME_AUTHENTICATION_COMPONENT);
    authenticationComponent.setSystemUserAsCurrentUser();

    /* Create the document using openCmis services */
    Repository repository = getRepository("admin", "admin");
    Session session = repository.createSession();
    Folder rootFolder = session.getRootFolder();

    // Set file properties
    String docname = "myDoc-" + GUID.generate() + ".txt";
    Map<String, String> props = new HashMap<String, String>();
    {
        props.put(PropertyIds.OBJECT_TYPE_ID, BaseTypeId.CMIS_DOCUMENT.value());
        props.put(PropertyIds.NAME, docname);
    }

    // Create some content
    byte[] byteContent = "Some content".getBytes();
    InputStream stream = new ByteArrayInputStream(byteContent);
    ContentStream contentStream = new ContentStreamImpl(docname, BigInteger.valueOf(byteContent.length), MIME_PLAIN_TEXT, stream);

    // Create the document
    Document doc1 = rootFolder.createDocument(props, contentStream, VersioningState.CHECKEDOUT);
    NodeRef doc1NodeRef = cmisIdToNodeRef(doc1.getId());
    NodeRef doc1WorkingCopy = cociService.getWorkingCopy(doc1NodeRef);

    /* Cancel Checkout */
    cociService.cancelCheckout(doc1WorkingCopy);

    /* Check if both the working copy and the document were deleted */
    NodeService nodeService = serviceRegistry.getNodeService();
    assertFalse(nodeService.exists(doc1NodeRef));
    assertFalse(nodeService.exists(doc1WorkingCopy));
}