Java Code Examples for org.alfresco.service.cmr.repository.NodeService#deleteNode()

The following examples show how to use org.alfresco.service.cmr.repository.NodeService#deleteNode() . 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: ReplicationServiceIntegrationTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
protected void setUp() throws Exception
{
    if (AlfrescoTransactionSupport.getTransactionReadState() != TxnReadState.TXN_NONE)
    {
        fail("Dangling transaction detected, left by a previous test.");
    }
    ctx = (ConfigurableApplicationContext) ApplicationContextHelper.getApplicationContext();
    replicationActionExecutor = (ReplicationActionExecutor) ctx.getBean("replicationActionExecutor");
    replicationService = (ReplicationService) ctx.getBean("replicationService");
    replicationParams = (ReplicationParams) ctx.getBean("replicationParams");
    transactionService = (TransactionService) ctx.getBean("transactionService");
    transferService = (TransferService2) ctx.getBean("transferService2");
    contentService = (ContentService) ctx.getBean("contentService");
    jobLockService = (JobLockService) ctx.getBean("jobLockService");
    actionService = (ActionService) ctx.getBean("actionService");
    scriptService = (ScriptService)ctx.getBean("scriptService");
    nodeService = (NodeService) ctx.getBean("NodeService");
    lockService = (LockService) ctx.getBean("lockService");
    repositoryHelper = (Repository) ctx.getBean("repositoryHelper");
    actionTrackingService = (ActionTrackingService) ctx.getBean("actionTrackingService");
    scheduledPersistedActionService = (ScheduledPersistedActionService) ctx.getBean("scheduledPersistedActionService");
    
    // Set the current security context as admin
    AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getAdminUserName());
    
    replicationParams.setEnabled(true);
    
    UserTransaction txn = transactionService.getUserTransaction();
    txn.begin();
    
    // Zap any existing replication entries
    replicationRoot = ReplicationDefinitionPersisterImpl.REPLICATION_ACTION_ROOT_NODE_REF;
    for(ChildAssociationRef child : nodeService.getChildAssocs(replicationRoot)) {
       QName type = nodeService.getType( child.getChildRef() );
       if(ReplicationDefinitionPersisterImpl.ACTION_TYPES.contains(type)) {
          nodeService.deleteNode(child.getChildRef());
       }
    }
    
    // Create the test folder structure
    destinationFolder = makeNode(repositoryHelper.getCompanyHome(), ContentModel.TYPE_FOLDER, "ReplicationTransferDestination");
    folder1 = makeNode(repositoryHelper.getCompanyHome(), ContentModel.TYPE_FOLDER);
    folder2 = makeNode(repositoryHelper.getCompanyHome(), ContentModel.TYPE_FOLDER);
    folder2a = makeNode(folder2, ContentModel.TYPE_FOLDER);
    folder2b = makeNode(folder2, ContentModel.TYPE_FOLDER);
    
    content1_1 = makeNode(folder1, ContentModel.TYPE_CONTENT);
    content1_2 = makeNode(folder1, ContentModel.TYPE_CONTENT);
    thumbnail1_3 = makeNode(folder1, ContentModel.TYPE_THUMBNAIL);
    authority1_4 = makeNode(folder1, ContentModel.TYPE_AUTHORITY);
    content2a_1 = makeNode(folder2a, ContentModel.TYPE_CONTENT);
    thumbnail2a_2 = makeNode(folder2a, ContentModel.TYPE_THUMBNAIL);
    zone2a_3 = makeNode(folder2a, ContentModel.TYPE_ZONE);
    
    deletedFolder = makeNode(repositoryHelper.getCompanyHome(), ContentModel.TYPE_FOLDER);
    nodeService.deleteNode(deletedFolder);
    
    // Tell the transfer service not to use HTTP
    makeTransferServiceLocal();
    
    // Finish setup
    txn.commit();
}
 
Example 2
Source File: AuthorityServiceTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 4 votes vote down vote up
public void setUp() throws Exception
{
    if (AlfrescoTransactionSupport.getTransactionReadState() != TxnReadState.TXN_NONE)
    {
        throw new AlfrescoRuntimeException(
                "A previous tests did not clean up transaction: " +
                AlfrescoTransactionSupport.getTransactionId());
    }
    
    authenticationComponent = (AuthenticationComponent) ctx.getBean("authenticationComponent");
    authenticationService = (MutableAuthenticationService) ctx.getBean("authenticationService");
    authorityService = (AuthorityService) ctx.getBean("authorityService");
    pubAuthorityService = (AuthorityService) ctx.getBean("AuthorityService");
    personService = (PersonService) ctx.getBean("personService");
    authenticationDAO = (MutableAuthenticationDao) ctx.getBean("authenticationDao");
    aclDaoComponent = (AclDAO) ctx.getBean("aclDAO");
    nodeService = (NodeService) ctx.getBean("nodeService");
    authorityBridgeTableCache = (AuthorityBridgeTableAsynchronouslyRefreshedCache) ctx.getBean("authorityBridgeTableCache");
    nodeArchiveService = (NodeArchiveService) ctx.getBean("nodeArchiveService");
    policyComponent = (PolicyComponent) ctx.getBean("policyComponent");
    transactionService = (TransactionService) ctx.getBean(ServiceRegistry.TRANSACTION_SERVICE.getLocalName());
    authorityDAO = ctx.getBean("authorityDAO", AuthorityDAO.class);
    
    String defaultAdminUser = AuthenticationUtil.getAdminUserName();
    AuthenticationUtil.setFullyAuthenticatedUser(defaultAdminUser);
    
    // cleanup trashcan
    nodeArchiveService.purgeAllArchivedNodes(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE);
    
    // note: currently depends on any existing (and/or bootstrap) group data - eg. default site "swsdp" (Sample Web Site Design Project)
    SiteService siteService = (SiteService) ctx.getBean("SiteService");
    SITE_CNT = siteService.listSites(defaultAdminUser).size();
    GRP_CNT = DEFAULT_GRP_CNT + (DEFAULT_SITE_GRP_CNT * SITE_CNT);
    ROOT_GRP_CNT = DEFAULT_GRP_CNT + (DEFAULT_SITE_ROOT_GRP_CNT * SITE_CNT);
    
    tx = transactionService.getUserTransaction();
    tx.begin();
    for (String user : getAllAuthorities(AuthorityType.USER))
    {
        if (user.equals(AuthenticationUtil.getGuestUserName()))
        {
            continue;
        }
        else if (user.equals(AuthenticationUtil.getAdminUserName()))
        {
            continue;
        }
        else
        {
            if (personService.personExists(user))
            {
                NodeRef person = personService.getPerson(user);
                NodeRef hf = DefaultTypeConverter.INSTANCE.convert(NodeRef.class, nodeService.getProperty(person, ContentModel.PROP_HOMEFOLDER));
                if (hf != null)
                {
                    nodeService.deleteNode(hf);
                }
                aclDaoComponent.deleteAccessControlEntries(user);
                personService.deletePerson(user);
            }
            if (authenticationDAO.userExists(user))
            {
                authenticationDAO.deleteUser(user);
            }
        }

    }
    tx.commit();

    tx = transactionService.getUserTransaction();
    tx.begin();

    if (!authenticationDAO.userExists("andy"))
    {
        authenticationService.createAuthentication("andy", "andy".toCharArray());
    }

    if (!authenticationDAO.userExists(AuthenticationUtil.getAdminUserName()))
    {
        authenticationService.createAuthentication(AuthenticationUtil.getAdminUserName(), "admin".toCharArray());
    }

    if (!authenticationDAO.userExists("administrator"))
    {
        authenticationService.createAuthentication("administrator", "administrator".toCharArray());
    }

}