org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback Java Examples

The following examples show how to use org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback. 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: SolrFacetServiceImplTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Test public void getFacetsAndReorderThem() throws Exception
{
    TRANSACTION_HELPER.doInTransaction(new RetryingTransactionCallback<Void>()
    {
        @Override public Void execute() throws Throwable
        {
            final List<String> facetIds = getExistingFacetIds();
            final List<String> reorderedFacetIds = new ArrayList<>(facetIds);
            Collections.reverse(reorderedFacetIds);
            
            SOLR_FACET_SERVICE.reorderFacets(reorderedFacetIds);
            
            final List<String> newfacetIds = getExistingFacetIds();
            
            assertEquals(reorderedFacetIds, newfacetIds);
            
            return null;
        }
    });
}
 
Example #2
Source File: RepoStore.java    From alfresco-remote-api with GNU Lesser General Public License v3.0 6 votes vote down vote up
public long lastModified(final String documentPath) throws IOException
{
    return AuthenticationUtil.runAs(new AuthenticationUtil.RunAsWork<Long>()
    {
        public Long doWork() throws Exception
        {
            return retryingTransactionHelper.doInTransaction(new RetryingTransactionCallback<Long>()
            {
                public Long execute() throws Exception
                {
                    ContentReader reader = contentService.getReader(
                            findNodeRef(documentPath), ContentModel.PROP_CONTENT);
                    return reader.getLastModified();
                }
            }, true, false);
        }
    }, AuthenticationUtil.getSystemUserName());            
}
 
Example #3
Source File: ContentDataDAOTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Retrieves and checks the ContentData for equality
 */
private Pair<Long, ContentData> getAndCheck(final Long contentDataId, ContentData checkContentData)
{
    RetryingTransactionCallback<Pair<Long, ContentData>> callback = new RetryingTransactionCallback<Pair<Long, ContentData>>()
    {
        public Pair<Long, ContentData> execute() throws Throwable
        {
            Pair<Long, ContentData> contentDataPair = contentDataDAO.getContentData(contentDataId);
            return contentDataPair;
        }
    };
    Pair<Long, ContentData> resultPair = txnHelper.doInTransaction(callback, true, false);
    assertNotNull("Failed to find result for ID " + contentDataId, resultPair);
    assertEquals("ContentData retrieved not the same as persisted: ", checkContentData, resultPair.getSecond());
    return resultPair;
}
 
Example #4
Source File: ScriptNodeTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * MNT-9369
 * <p>
 * Initially the ContentModel.PROP_AUTO_VERSION and ContentModel.PROP_AUTO_VERSION_PROPS are true by defaults.
 */
@Test
public void testVersioningPropsDefault()
{
    createTestContent(false);
    Map<QName, PropertyDefinition> versionableProps = DICTIONARY_SERVICE.getAspect(ContentModel.ASPECT_VERSIONABLE).getProperties();
    autoVersion = Boolean.parseBoolean(versionableProps.get(ContentModel.PROP_AUTO_VERSION).getDefaultValue());
    autoVersionProps = Boolean.parseBoolean(versionableProps.get(ContentModel.PROP_AUTO_VERSION_PROPS).getDefaultValue());

    TRANSACTION_HELPER.doInTransaction(new RetryingTransactionCallback<Void>()
    {
        public Void execute() throws Throwable
        {
            log.debug("Adding versionable aspect.");

            ScriptNode sn = new ScriptNode(testNode, SERVICE_REGISTRY);
            sn.addAspect("cm:versionable");
            return null;
        }
    });

    assertEquals("Incorrect Auto Version property.", autoVersion, NODE_SERVICE.getProperty(testNode, ContentModel.PROP_AUTO_VERSION));
    assertEquals("Incorrect Auto Version Props property.", autoVersionProps, NODE_SERVICE.getProperty(testNode, ContentModel.PROP_AUTO_VERSION_PROPS));
}
 
Example #5
Source File: AbstractMimeMessage.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
protected void buildMessage(FileInfo fileInfo, ServiceRegistry serviceRegistry) throws MessagingException
{
    checkParameter(serviceRegistry, "ServiceRegistry");
    this.content = null;
    this.serviceRegistry = serviceRegistry;
    this.imapService = serviceRegistry.getImapService();
    this.messageFileInfo = fileInfo;
    this.isMessageInSitesLibrary = imapService.getNodeSiteContainer(messageFileInfo.getNodeRef()) != null ? true : false;
    RetryingTransactionHelper txHelper = serviceRegistry.getTransactionService().getRetryingTransactionHelper();
    txHelper.setMaxRetries(MAX_RETRIES);
    txHelper.setReadOnly(false);
    txHelper.doInTransaction(new RetryingTransactionCallback<Object>() {
        public Object execute() throws Throwable
        {
            buildMessageInternal();
            return null;
        }
    }, false);
    
}
 
Example #6
Source File: ContentDataDAOTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Category(PerformanceTests.class)
public void testCreateSpeedSingleTxn()
{
    RetryingTransactionCallback<List<Pair<Long, ContentData>>> writeCallback = new RetryingTransactionCallback<List<Pair<Long, ContentData>>>()
    {
        public List<Pair<Long, ContentData>> execute() throws Throwable
        {
            return speedTestWrite(getName(), 10000);
        }
    };
    final List<Pair<Long, ContentData>> pairs = txnHelper.doInTransaction(writeCallback, false, false);
    RetryingTransactionCallback<Void> readCallback = new RetryingTransactionCallback<Void>()
    {
        public Void execute() throws Throwable
        {
            speedTestRead(getName(), pairs);
            return null;
        }
    };
    txnHelper.doInTransaction(readCallback, false, false);
}
 
Example #7
Source File: SolrFacetServiceImplTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
@AfterClass
public static void cleanup()
{
    TRANSACTION_HELPER.doInTransaction(new RetryingTransactionCallback<Void>()
    {
        @Override
        public Void execute() throws Throwable
        {
            for (String filter : FILTERS)
            {
                try
                {
                    SOLR_FACET_SERVICE.deleteFacet(filter);
                }
                catch (SolrFacetConfigException sfe)
                {
                    logger.info("Cannot delete filter [" + filter + "]. " + sfe);
                }
            }
            return null;
        }
    });

}
 
Example #8
Source File: ActionServiceImpl2Test.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Before
public void initTestSiteAndUsersAndSomeContent()
{
    final String siteShortName = ActionServiceImpl2Test.class.getSimpleName() + "TestSite"
            + System.currentTimeMillis();

    // This will create a public Share site whose creator is the admin user.
    // It will create 4 users (one for each of the Share roles, and add them
    // to the site.
    testSiteAndMemberInfo = temporarySites.createTestSiteWithUserPerRole(siteShortName, "sitePreset",
            SiteVisibility.PUBLIC, AuthenticationUtil.getAdminUserName());

    AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getAdminUserName());
    testNode = transactionHelper.doInTransaction(new RetryingTransactionCallback<NodeRef>()
    {
        public NodeRef execute() throws Throwable
        {
            // get the Document Library NodeRef
            final NodeRef docLibNodeRef = testSiteAndMemberInfo.doclib;

            // Create a test node. It doesn't need content.
            return nodeService.createNode(docLibNodeRef, ContentModel.ASSOC_CONTAINS, ContentModel.ASSOC_CONTAINS,
                    ContentModel.TYPE_CONTENT).getChildRef();
        }
    });
}
 
Example #9
Source File: RepoStore.java    From alfresco-remote-api with GNU Lesser General Public License v3.0 6 votes vote down vote up
public ScriptContent getScript(final String path)
{
    return AuthenticationUtil.runAs(new AuthenticationUtil.RunAsWork<ScriptContent>()
    {
        public ScriptContent doWork() throws Exception
        {
            return retryingTransactionHelper.doInTransaction(new RetryingTransactionCallback<ScriptContent>()
            {
                public ScriptContent execute() throws Exception
                {
                    ScriptContent location = null;
                    NodeRef nodeRef = findNodeRef(path);
                    if (nodeRef != null)
                    {
                        location = new RepoScriptContent(path, nodeRef);
                    }
                    return location;
                }
            }, true, false);
        }
    }, AuthenticationUtil.getSystemUserName());
}
 
Example #10
Source File: FixedAclUpdaterTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public void tearDown() throws Exception
{
    // delete created folder hierarchy
    try
    {
        txnHelper.doInTransaction((RetryingTransactionCallback<Void>) () -> {
            Set<QName> aspect = new HashSet<>();
            aspect.add(ContentModel.ASPECT_TEMPORARY);
            nodeDAO.addNodeAspects(nodeDAO.getNodePair(folderAsyncCallNodeRef).getFirst(), aspect);
            nodeDAO.addNodeAspects(nodeDAO.getNodePair(folderSyncCallNodeRef).getFirst(), aspect);
            fileFolderService.delete(folderAsyncCallNodeRef);
            fileFolderService.delete(folderSyncCallNodeRef);
            return null;
        }, false, true);
    }
    catch (Exception e)
    {
    }
    AuthenticationUtil.clearCurrentSecurityContext();
}
 
Example #11
Source File: RepoStore.java    From alfresco-remote-api with GNU Lesser General Public License v3.0 6 votes vote down vote up
public boolean hasDocument(final String documentPath)
{
    return AuthenticationUtil.runAs(new AuthenticationUtil.RunAsWork<Boolean>()
    {
        public Boolean doWork() throws Exception
        {
            return retryingTransactionHelper.doInTransaction(new RetryingTransactionCallback<Boolean>()
            {
                public Boolean execute() throws Exception
                {
                    NodeRef nodeRef = findNodeRef(documentPath);
                    return (nodeRef != null);
                }
            }, true, false);
        }
    }, AuthenticationUtil.getSystemUserName());
}
 
Example #12
Source File: RatingServiceIntegrationTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
private void applyIllegalRating(final NodeRef nodeRef, final float illegalRating, final String schemeName)
{
    try
    {
        TRANSACTION_HELPER.doInTransaction(new RetryingTransactionCallback<Void>()
        {
            @Override
            public Void execute() throws Throwable
            {
                RATING_SERVICE.applyRating(nodeRef, illegalRating, schemeName);
                return null;
            }
        });
    } 
    catch (RatingServiceException expectedException)
    {
        return;
    }
    fail("Illegal rating " + illegalRating + " should have caused exception.");
}
 
Example #13
Source File: AppliedPatchDAOTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
public void testCreateWithRollback() throws Exception
{
    final String id = getName() + "-" + System.currentTimeMillis();
    // Create an encoding
    RetryingTransactionCallback<Void> callback = new RetryingTransactionCallback<Void>()
    {
        public Void execute() throws Throwable
        {
            create(id, false);
            // Now force a rollback
            throw new RuntimeException("Forced");
        }
    };
    try
    {
        txnHelper.doInTransaction(callback);
        fail("Transaction didn't roll back");
    }
    catch (RuntimeException e)
    {
        // Expected
    }
    // Check that it doesn't exist
    get(id);
}
 
Example #14
Source File: CannedQueryDAOTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
@BeforeClass public static void setup() throws Exception
{

    ServiceRegistry serviceRegistry = (ServiceRegistry) APP_CONTEXT_INIT.getApplicationContext().getBean(ServiceRegistry.SERVICE_REGISTRY);
    transactionService = serviceRegistry.getTransactionService();
    txnHelper = transactionService.getRetryingTransactionHelper();
    
    cannedQueryDAO = (CannedQueryDAO) APP_CONTEXT_INIT.getApplicationContext().getBean("cannedQueryDAO");
    cannedQueryDAOForTesting = (CannedQueryDAO) APP_CONTEXT_INIT.getApplicationContext().getBean("cannedQueryDAOForTesting");
    mimetypeDAO = (MimetypeDAO) APP_CONTEXT_INIT.getApplicationContext().getBean("mimetypeDAO");

    RetryingTransactionCallback<String> createMimetypeCallback = new RetryingTransactionCallback<String>()
    {
        @Override
        public String execute() throws Throwable
        {
            String mimetypePrefix = GUID.generate();
            mimetypeDAO.getOrCreateMimetype(mimetypePrefix + "-aaa");
            mimetypeDAO.getOrCreateMimetype(mimetypePrefix + "-bbb");
            return mimetypePrefix;
        }
    };
    mimetypePrefix = txnHelper.doInTransaction(createMimetypeCallback);
}
 
Example #15
Source File: RepoStore.java    From alfresco-remote-api with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Gets the content reader
 * 
 * @return  content reader
 * @throws IOException
 */
public Reader getReader() throws IOException
{
    return AuthenticationUtil.runAs(new AuthenticationUtil.RunAsWork<Reader>()
    {
        public Reader doWork() throws Exception
        {
            return retryingTransactionHelper.doInTransaction(new RetryingTransactionCallback<Reader>()
            {
                public Reader execute() throws Exception
                {
                    ContentReader reader = contentService.getReader(nodeRef, ContentModel.PROP_CONTENT);
                    return new InputStreamReader(reader.getContentInputStream(), reader.getEncoding());
                }
            });
        }
    }, AuthenticationUtil.getSystemUserName());            
}
 
Example #16
Source File: CalendarServiceImplTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
private static void deleteUser(final String userName)
{
    TRANSACTION_HELPER.doInTransaction(new RetryingTransactionHelper.RetryingTransactionCallback<Void>()
    {
       @Override
       public Void execute() throws Throwable
       {
          if (PERSON_SERVICE.personExists(userName))
          {
             PERSON_SERVICE.deletePerson(userName);
          }

          return null;
       }
    });
}
 
Example #17
Source File: FileFolderServicePropagationTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
@After
public void tearDown() throws Exception
{
    // Resetting to default value...
    fileFolderService.setPreserveAuditableData(defaultPreservationValue);

    transactionService.getRetryingTransactionHelper().doInTransaction(new RetryingTransactionCallback<Void>()
    {
        @Override
        public Void execute() throws Throwable
        {
            return AuthenticationUtil.runAsSystem(new RunAsWork<Void>()
            {
                @Override
                public Void doWork() throws Exception
                {
                    authenticationService.deleteAuthentication(TEST_USER_NAME);
                    fileFolderService.delete(testRootFolder.getNodeRef());
                    return null;
                }
            });
        }
    });
}
 
Example #18
Source File: ConfigurationChecker.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
protected void onBootstrap(ApplicationEvent event)
{
    RetryingTransactionCallback<Object> checkWork = new RetryingTransactionCallback<Object>()
    {
        public Object execute() throws Throwable {
            // run as System on bootstrap
            return AuthenticationUtil.runAs(new RunAsWork<Object>()
            {
                public Object doWork()
                {
                    check();
                    return null;
                }
            }, AuthenticationUtil.getSystemUserName());
        }
    };
    transactionService.getRetryingTransactionHelper().doInTransaction(checkWork, true);
}
 
Example #19
Source File: ModuleStarter.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
protected void onBootstrap(ApplicationEvent event)
{
    PropertyCheck.mandatory(this, "moduleService", moduleService);
    final RetryingTransactionCallback<Object> startModulesCallback = new RetryingTransactionCallback<Object>()
    {
        public Object execute() throws Throwable
        {
            moduleService.startModules();
            return null;
        }
    };
    
    AuthenticationUtil.runAs(new RunAsWork<Object>()
    {
        @Override
        public Object doWork() throws Exception 
        {
            transactionService.getRetryingTransactionHelper().doInTransaction(startModulesCallback, transactionService.isReadOnly());
            return null;
        }
    	
    }, AuthenticationUtil.getSystemUserName());       
}
 
Example #20
Source File: TemporarySitesTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Test public void ensureUsersWithShareRolesArePresentAndCorrect() throws Exception
{
    TRANSACTION_HELPER.doInTransaction(new RetryingTransactionCallback<Void>()
    {
        public Void execute() throws Throwable
        {
            final String shortName = testSiteWithMembers.siteInfo.getShortName();
            final SiteInfo recoveredSite = SITE_SERVICE.getSite(shortName);
            
            assertNotNull("Test site does not exist", recoveredSite);
            
            assertEquals(SiteModel.SITE_MANAGER,      SITE_SERVICE.getMembersRole(shortName, testSiteWithMembers.siteManager));
            assertEquals(SiteModel.SITE_COLLABORATOR, SITE_SERVICE.getMembersRole(shortName, testSiteWithMembers.siteCollaborator));
            assertEquals(SiteModel.SITE_CONTRIBUTOR,  SITE_SERVICE.getMembersRole(shortName, testSiteWithMembers.siteContributor));
            assertEquals(SiteModel.SITE_CONSUMER,     SITE_SERVICE.getMembersRole(shortName, testSiteWithMembers.siteConsumer));
            
            assertNotNull(testSiteWithMembers.doclib);
            assertTrue("Site doclib was not pre-created.", NODE_SERVICE.exists(testSiteWithMembers.doclib));
            assertEquals("Site doclib was in wrong place.", testSiteWithMembers.siteInfo.getNodeRef(),
                                                            NODE_SERVICE.getPrimaryParent(testSiteWithMembers.doclib).getParentRef());
            
            return null;
        }
    });
}
 
Example #21
Source File: ChainingUserRegistrySynchronizer.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Persists the most recent update time for a label and zone.
 * 
 * @param label
 *            the label
 * @param zoneId
 *            the zone id
 * @param lastModifiedMillis
 *            the update time in milliseconds
 * @param splitTxns
 *            Can the modifications to Alfresco be split across multiple transactions for maximum performance? If
 *            <code>true</code>, the attribute is persisted in a new transaction for increased performance and
 *            reliability.
 */
private void setMostRecentUpdateTime(final String label, final String zoneId, final long lastModifiedMillis,
        boolean splitTxns)
{
    this.transactionService.getRetryingTransactionHelper().doInTransaction(
            new RetryingTransactionHelper.RetryingTransactionCallback<Object>()
            {
                public Object execute() throws Throwable
                {
                    ChainingUserRegistrySynchronizer.this.attributeService.setAttribute(Long
                            .valueOf(lastModifiedMillis), ChainingUserRegistrySynchronizer.ROOT_ATTRIBUTE_PATH,
                            label, zoneId);
                    return null;
                }
            }, false, splitTxns);
}
 
Example #22
Source File: RepoTransferReceiverImpl.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
public void run()
{
    RunAsWork<Object> actionRunAs = new RunAsWork<Object>()
    {
        public Object doWork() throws Exception
        {
            return transactionService.getRetryingTransactionHelper().doInTransaction(
                    new RetryingTransactionCallback<Object>()
                    {
                        public Object execute()
                        {
                            commit(transferId);
                            return null;
                        }
                    }, false, true);
        }
    };
    AuthenticationUtil.runAs(actionRunAs, runAsUser);
}
 
Example #23
Source File: CustomModelServiceImplTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
private CustomModelDefinition createModel(final M2Model m2Model, final boolean activate)
{
    return transactionHelper.doInTransaction(new RetryingTransactionCallback<CustomModelDefinition>()
    {
        public CustomModelDefinition execute() throws Exception
        {
            return customModelService.createCustomModel(m2Model, activate);
        }
    });
}
 
Example #24
Source File: QuickShareRestApiTest.java    From alfresco-remote-api with GNU Lesser General Public License v3.0 5 votes vote down vote up
private void deleteSite(final String shortName)
{
    transactionHelper.doInTransaction(new RetryingTransactionCallback<Void>()
    {
          @Override
          public Void execute() throws Throwable
          {
              siteService.deleteSite(shortName);
              return null;
          }
    }, false, true); 
}
 
Example #25
Source File: CacheTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * <ul>
 *   <li>Add to the transaction cache</li>
 *   <li>Add to the backing cache</li>
 *   <li>Commit</li>
 * </ul>
 */
public void testConcurrentAddAgainstAdd()throws Throwable
{
    RetryingTransactionCallback<Object> callback = new RetryingTransactionCallback<Object>()
    {
        public Object execute() throws Throwable
        {
            transactionalCache.put(COMMON_KEY, VALUE_ONE_A);
            TransactionalCache.putSharedCacheValue(backingCache, COMMON_KEY, VALUE_ONE_B, null);
            return null;
        }
    };
    transactionalCache.setAllowEqualsChecks(false);
    transactionalCache.setMutable(true);
    executeAndCheck(callback, false, COMMON_KEY, null, false);  // Mutable: Pessimistic removal
    executeAndCheck(callback, true, COMMON_KEY, null, false);   // Mutable: Pessimistic removal
    transactionalCache.setMutable(false);
    executeAndCheck(callback, false, COMMON_KEY, VALUE_ONE_B, true);  // Immutable: Assume backing cache is correct
    executeAndCheck(callback, true, COMMON_KEY, VALUE_ONE_B, true);   // Immutable: Assume backing cache is correct

    transactionalCache.setAllowEqualsChecks(true);
    transactionalCache.setMutable(true);
    executeAndCheck(callback, false, COMMON_KEY, VALUE_ONE_B, true);  // Mutable: Shared cache value checked
    executeAndCheck(callback, true, COMMON_KEY, VALUE_ONE_B, true);   // Mutable: Shared cache value checked
    transactionalCache.setMutable(false);
    executeAndCheck(callback, false, COMMON_KEY, VALUE_ONE_B, true);  // Immutable: Assume backing cache is correct
    executeAndCheck(callback, true, COMMON_KEY, VALUE_ONE_B, true);   // Immutable: Assume backing cache is correct
}
 
Example #26
Source File: NodeServiceTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
private NodeRef setupTestGetChildren(final NodeRef workspaceRootNodeRef, final int numberOfReferences)
{
    RetryingTransactionCallback<NodeRef> setupCallback = new RetryingTransactionCallback<NodeRef>()
    {
        @Override
        public NodeRef execute() throws Throwable
        {
            NodeRef[] referenceNodeRefs = new NodeRef[numberOfReferences];
            // Create one folder
            Map<QName, Serializable> folderProps = new HashMap<QName, Serializable>(3);
            folderProps.put(ContentModel.PROP_NAME, "folder-" + GUID.generate());
            NodeRef folderNodeRef = nodeService.createNode(
                    workspaceRootNodeRef,
                    ContentModel.ASSOC_CHILDREN,
                    QName.createQName(NAMESPACE, "folder"),
                    ContentModel.TYPE_FOLDER,
                    folderProps).getChildRef();

            // Create some content
            for (int i = 0; i < numberOfReferences; i++)
            {
                Map<QName, Serializable> props = new HashMap<QName, Serializable>(3);
                props.put(ContentModel.PROP_NAME, "reference-" + GUID.generate());
                referenceNodeRefs[i] = nodeService.createNode(
                        folderNodeRef,
                        ContentModel.ASSOC_CONTAINS,
                        QName.createQName(NAMESPACE, "reference"),
                        ContentModel.TYPE_RATING,
                        props).getChildRef();
            }
            return folderNodeRef;
        }
    };
    return txnService.getRetryingTransactionHelper().doInTransaction(setupCallback);
}
 
Example #27
Source File: CMMDownloadTestUtil.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
public synchronized void cleanup()
{
    if (isExtFolderCreated)
    {
        transactionHelper.doInTransaction(new RetryingTransactionCallback<Void>()
        {
            @Override
            public Void execute() throws Throwable
            {
                nodeService.deleteNode(extensionsNodeRef);
                return null;
            }
        });

        logger.info("Deleted 'cm:extensions' folder within the 'app:company_home/st:sites/cm:surf-config");
    }
    else if (originalShareExtFile != null)
    {
        transactionHelper.doInTransaction(new RetryingTransactionCallback<Void>()
        {
            @Override
            public Void execute() throws Throwable
            {
                ContentWriter writer = contentService.getWriter(sharePersistedExtNodeRef, ContentModel.PROP_CONTENT, true);
                writer.setMimetype(MimetypeMap.MIMETYPE_XML);
                writer.setEncoding("UTF-8");
                writer.putContent(originalShareExtFile); // put back the original extension file
                return null;
            }
        });

        logger.info("Reverted default-persisted-extension.xml content.");
    }

    if (originalShareExtFile != null)
    {
        originalShareExtFile.delete();
    }
}
 
Example #28
Source File: MultiTDemoTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
private void createTestAuthoritiesForTenant(final String[] uniqueGroupNames, final String userName)
{
    String tenantDomain = tenantService.getUserDomain(userName);

    // Create groups for tenant
    TenantUtil.runAsUserTenant(new TenantRunAsWork<Void>()
    {
        public Void doWork() throws Exception
        {
            transactionService.getRetryingTransactionHelper().doInTransaction(new RetryingTransactionCallback<Void>()
            {
                @Override
                public Void execute() throws Throwable
                {
                    // find person
                    NodeRef personNodeRef = personService.getPerson(userName);
                    NodeRef homeSpaceRef = (NodeRef) nodeService.getProperty(personNodeRef, ContentModel.PROP_HOMEFOLDER);
                    assertNotNull(homeSpaceRef);

                    for (int i = 0; i < uniqueGroupNames.length; i++)
                    {
                        authorityService.createAuthority(AuthorityType.GROUP, uniqueGroupNames[i]);
                        permissionService.setPermission(homeSpaceRef, "GROUP_" + uniqueGroupNames[i], "Consumer", true);
                    }

                    return null;
                }
            }, false);
            return null;
        }
    }, userName, tenantDomain);
}
 
Example #29
Source File: CacheTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * <ul>
 *   <li>Add to the backing cache</li>
 *   <li>Update the transactional cache with a <tt>null</tt> value</li>
 *   <li>Update the backing cache with a <tt>null</tt> value</li>
 *   <li>Commit</li>
 * </ul>
 */
public void testConcurrentUpdateNullAgainstUpdateNull()throws Throwable
{
    RetryingTransactionCallback<Object> callback = new RetryingTransactionCallback<Object>()
    {
        public Object execute() throws Throwable
        {
            TransactionalCache.putSharedCacheValue(backingCache, COMMON_KEY, VALUE_ONE_A, null);
            transactionalCache.put(COMMON_KEY, null);
            TransactionalCache.putSharedCacheValue(backingCache, COMMON_KEY, null, null);
            return null;
        }
    };
    transactionalCache.setAllowEqualsChecks(false);
    transactionalCache.setMutable(true);
    executeAndCheck(callback, false, COMMON_KEY, null, false);          // Mutable: Pessimistic removal
    executeAndCheck(callback, true, COMMON_KEY, null, false);           // Mutable: Pessimistic removal
    transactionalCache.setMutable(false);
    executeAndCheck(callback, false, COMMON_KEY, null, true);           // Immutable: Assume backing cache is correct
    executeAndCheck(callback, true, COMMON_KEY, null, true);            // Immutable: Assume backing cache is correct

    transactionalCache.setAllowEqualsChecks(true);
    transactionalCache.setMutable(true);
    executeAndCheck(callback, false, COMMON_KEY, null, true);           // Mutable: Equality check
    executeAndCheck(callback, true, COMMON_KEY, null, true);            // Mutable: Equality check
    transactionalCache.setMutable(false);
    executeAndCheck(callback, false, COMMON_KEY, null, true);           // Immutable: Equality check
    executeAndCheck(callback, true, COMMON_KEY, null, true);            // Immutable: Equality check
}
 
Example #30
Source File: ActionServiceImpl2Test.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Test
public void testIncrementCounter() throws Exception
{
    // Set authentication to SiteManager.
    AuthenticationUtil.setFullyAuthenticatedUser(testSiteAndMemberInfo.siteManager);
    transactionHelper.doInTransaction(new RetryingTransactionCallback<Void>()
    {
        public Void execute() throws Throwable
        {
            // add the cm:countable aspect and set the value to 1
            Map<QName, Serializable> props = new HashMap<QName, Serializable>(1);
            props.put(ContentModel.PROP_COUNTER, 1);
            nodeService.addAspect(testNode, ContentModel.ASPECT_COUNTABLE, props);

            return null;
        }
    });
    // check that the default counter value is set to 1
    int beforeIncrement = (Integer) nodeService.getProperty(testNode, ContentModel.PROP_COUNTER);
    assertEquals("Counter value incorrect", 1, beforeIncrement);

    // Set authentication to SiteConsumer.
    AuthenticationUtil.setFullyAuthenticatedUser(testSiteAndMemberInfo.siteConsumer);
    transactionHelper.doInTransaction(new RetryingTransactionCallback<Void>()
    {
        public Void execute() throws Throwable
        {
            Action incrementAction = actionService.createAction(CounterIncrementActionExecuter.NAME);

            actionService.executeAction(incrementAction, testNode);
            return null;
        }
    });

    int afterIncrement = (Integer) nodeService.getProperty(testNode, ContentModel.PROP_COUNTER);
    // CounterIncrementActionExecuter is a sample action, therefore, the
    // permission is no checked.
    assertEquals(2, afterIncrement);
}