Search in sources :

Example 1 with BehaviourFilter

use of org.alfresco.repo.policy.BehaviourFilter in project alfresco-repository by Alfresco.

the class CronScheduledQueryBasedTemplateActionDefinitionTest method createTestContent.

/**
 * Creates <code>rootTestFolder</code> test folder as start of test content hierarchy. Then it creates
 * {@link CronScheduledQueryBasedTemplateActionDefinitionTest#TEST_DOCUMENTS_AMOUNT} documents in the root folder with "today" creation date and the same amount of documents
 * with "yesterday" creation date
 */
private void createTestContent() throws Exception {
    FileFolderService fileFolderService = registry.getFileFolderService();
    NodeRef companyHomeNodeRef = registry.getNodeLocatorService().getNode(CompanyHomeNodeLocator.NAME, null, null);
    rootTestFolder = fileFolderService.create(companyHomeNodeRef, TEST_FOLDER_NAME, ContentModel.TYPE_FOLDER).getNodeRef();
    for (int i = 0; i < TEST_DOCUMENTS_AMOUNT; i++) {
        String freshDocName = String.format(FRESH_TEST_DOCUMENT_NAME_TEMPLATE, i, System.currentTimeMillis());
        FileInfo fileInfo = fileFolderService.create(rootTestFolder, freshDocName, ContentModel.TYPE_CONTENT);
        freshNodes.add(fileInfo);
    }
    Calendar calendar = GregorianCalendar.getInstance();
    calendar.setTimeInMillis(System.currentTimeMillis());
    calendar.add(Calendar.DAY_OF_YEAR, AMOUNT_OF_DAYS_BEFORE);
    Date yesterdayTime = calendar.getTime();
    NodeService nodeService = registry.getNodeService();
    BehaviourFilter policyBehaviourFilter = (BehaviourFilter) applicationContext.getBean(POLICY_BEHAVIOUR_FILTER_BEAN_NAME);
    policyBehaviourFilter.disableBehaviour(ContentModel.ASPECT_AUDITABLE);
    try {
        for (int i = 0; i < TEST_DOCUMENTS_AMOUNT; i++) {
            String yesterdayDocName = String.format(YESTERDAY_TEST_DOCUMENT_NAME_TEMPLATE, i, System.currentTimeMillis());
            FileInfo fileInfo = fileFolderService.create(rootTestFolder, yesterdayDocName, ContentModel.TYPE_CONTENT);
            nodeService.setProperty(fileInfo.getNodeRef(), ContentModel.PROP_CREATED, yesterdayTime);
            yesterdayNodes.add(fileInfo);
        }
    } finally {
        policyBehaviourFilter.enableBehaviour(ContentModel.ASPECT_AUDITABLE);
    }
    checkNodes(freshNodes);
    checkNodes(yesterdayNodes);
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) FileInfo(org.alfresco.service.cmr.model.FileInfo) Calendar(java.util.Calendar) GregorianCalendar(java.util.GregorianCalendar) NodeService(org.alfresco.service.cmr.repository.NodeService) BehaviourFilter(org.alfresco.repo.policy.BehaviourFilter) FileFolderService(org.alfresco.service.cmr.model.FileFolderService) Date(java.util.Date)

Example 2 with BehaviourFilter

use of org.alfresco.repo.policy.BehaviourFilter in project alfresco-repository by Alfresco.

the class MultiTServiceImplTest method deleteTenant.

private void deleteTenant(final String tenantDomain) {
    AuthenticationUtil.runAs(new RunAsWork<Object>() {

        public Object doWork() throws Exception {
            RetryingTransactionHelper.RetryingTransactionCallback<Void> work = new RetryingTransactionHelper.RetryingTransactionCallback<Void>() {

                public Void execute() throws Throwable {
                    // delete tenant (if it exists)
                    if (tenantAdminService.existsTenant(tenantDomain)) {
                        // TODO: WARNING: HACK for ALF-19155: MT deleteTenant does not work
                        // PersonService prevents 'guest' authorities from being deleted
                        {
                            BehaviourFilter behaviourFilter = (BehaviourFilter) applicationContext.getBean("policyBehaviourFilter");
                            behaviourFilter.disableBehaviour(ContentModel.TYPE_PERSON);
                            behaviourFilter.disableBehaviour(ContentModel.ASPECT_UNDELETABLE);
                        }
                        tenantAdminService.deleteTenant(tenantDomain);
                    }
                    return null;
                }
            };
            transactionService.getRetryingTransactionHelper().doInTransaction(work);
            return null;
        }
    }, AuthenticationUtil.getSystemUserName());
}
Also used : RetryingTransactionHelper(org.alfresco.repo.transaction.RetryingTransactionHelper) BehaviourFilter(org.alfresco.repo.policy.BehaviourFilter) AlfrescoRuntimeException(org.alfresco.error.AlfrescoRuntimeException)

Example 3 with BehaviourFilter

use of org.alfresco.repo.policy.BehaviourFilter in project records-management by Alfresco.

the class BaseRMTestCase method tearDownImpl.

/**
 * Tear down implementation
 */
protected void tearDownImpl() {
    BehaviourFilter filter = (BehaviourFilter) applicationContext.getBean("policyBehaviourFilter");
    filter.disableBehaviour();
    try {
        if (filePlan != null && nodeService.exists(filePlan)) {
            List<NodeRef> holds = holdService.getHolds(filePlan);
            for (NodeRef hold : holds) {
                holdService.deleteHold(hold);
            }
        }
        if (folder != null && nodeService.exists(folder)) {
            // Delete the folder
            nodeService.deleteNode(folder);
        }
        if (siteId != null && siteService.getSite(siteId) != null) {
            // Delete the site
            siteService.deleteSite(siteId);
        }
        // delete the collaboration site (if required)
        if (isCollaborationSiteTest() && siteService.getSite(collabSiteId) != null) {
            siteService.deleteSite(collabSiteId);
        }
    } finally {
        filter.enableBehaviour();
    }
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) BehaviourFilter(org.alfresco.repo.policy.BehaviourFilter)

Example 4 with BehaviourFilter

use of org.alfresco.repo.policy.BehaviourFilter in project alfresco-repository by Alfresco.

the class DiscussionServiceImplTest method deleteTenant.

private static void deleteTenant() {
    TRANSACTION_HELPER.doInTransaction(new RetryingTransactionHelper.RetryingTransactionCallback<Void>() {

        @Override
        public Void execute() throws Throwable {
            // TODO: WARNING: HACK for ALF-19155: MT deleteTenant does not work
            // PersonService prevents 'guest' authorities from being deleted
            {
                BehaviourFilter behaviourFilter = (BehaviourFilter) testContext.getBean("policyBehaviourFilter");
                behaviourFilter.disableBehaviour(ContentModel.TYPE_PERSON);
                behaviourFilter.disableBehaviour(ContentModel.ASPECT_UNDELETABLE);
            }
            TENANT_ADMIN_SERVICE.deleteTenant(TENANT_DOMAIN);
            return null;
        }
    });
}
Also used : RetryingTransactionHelper(org.alfresco.repo.transaction.RetryingTransactionHelper) BehaviourFilter(org.alfresco.repo.policy.BehaviourFilter)

Example 5 with BehaviourFilter

use of org.alfresco.repo.policy.BehaviourFilter in project alfresco-repository by Alfresco.

the class VirtualBehaviourFilterExtensionTest method setUp.

@Before
public void setUp() throws Exception {
    super.setUp();
    behaviourFilter = ctx.getBean("policyBehaviourFilter", BehaviourFilter.class);
    smartStore = ctx.getBean("smartStore", VirtualStoreImpl.class);
    NodeRef nodeRef = nodeService.getChildByName(virtualFolder1NodeRef, ContentModel.ASSOC_CONTAINS, "Node1");
    virtualNodeRef = createContent(nodeRef, "actualContentName", "0", MimetypeMap.MIMETYPE_TEXT_PLAIN, "UTF-8").getChildRef();
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) BehaviourFilter(org.alfresco.repo.policy.BehaviourFilter) VirtualStoreImpl(org.alfresco.repo.virtual.store.VirtualStoreImpl) Before(org.junit.Before)

Aggregations

BehaviourFilter (org.alfresco.repo.policy.BehaviourFilter)6 NodeRef (org.alfresco.service.cmr.repository.NodeRef)4 RetryingTransactionHelper (org.alfresco.repo.transaction.RetryingTransactionHelper)2 Serializable (java.io.Serializable)1 Calendar (java.util.Calendar)1 Date (java.util.Date)1 GregorianCalendar (java.util.GregorianCalendar)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Map (java.util.Map)1 Set (java.util.Set)1 AlfrescoRuntimeException (org.alfresco.error.AlfrescoRuntimeException)1 MimetypeMap (org.alfresco.repo.content.MimetypeMap)1 Node (org.alfresco.repo.domain.node.Node)1 NodeVersionKey (org.alfresco.repo.domain.node.NodeVersionKey)1 CannedQueryDAOTest (org.alfresco.repo.domain.query.CannedQueryDAOTest)1 VisitedNode (org.alfresco.repo.node.db.NodeHierarchyWalker.VisitedNode)1 RetryingTransactionCallback (org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback)1 VirtualStoreImpl (org.alfresco.repo.virtual.store.VirtualStoreImpl)1 FileFolderService (org.alfresco.service.cmr.model.FileFolderService)1