Search in sources :

Example 76 with RetryingTransactionCallback

use of org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback in project records-management by Alfresco.

the class BaseUnitTest method before.

/**
 * Test method setup
 */
@SuppressWarnings("unchecked")
@Before
public void before() throws Exception {
    MockitoAnnotations.initMocks(this);
    // setup application context
    doReturn(mockedNodeService).when(mockedApplicationContext).getBean("dbNodeService");
    // setup retrying transaction helper
    Answer<Object> doInTransactionAnswer = new Answer<Object>() {

        @SuppressWarnings("rawtypes")
        @Override
        public Object answer(InvocationOnMock invocation) throws Throwable {
            RetryingTransactionCallback callback = (RetryingTransactionCallback) invocation.getArguments()[0];
            return callback.execute();
        }
    };
    doAnswer(doInTransactionAnswer).when(mockedRetryingTransactionHelper).<Object>doInTransaction(any(RetryingTransactionCallback.class));
    // setup mocked authentication util
    MockAuthenticationUtilHelper.setup(mockedAuthenticationUtil);
    // setup file plan
    filePlan = generateNodeRef(TYPE_FILE_PLAN);
    setupAsFilePlanComponent(filePlan);
    doReturn(true).when(mockedFilePlanService).isFilePlan(filePlan);
    // setup basic file plan component
    filePlanComponent = generateNodeRef();
    setupAsFilePlanComponent(filePlanComponent);
    // setup namespace service
    doReturn(RM_URI).when(mockedNamespaceService).getNamespaceURI(RM_PREFIX);
    doReturn(CollectionUtils.unmodifiableSet(RM_PREFIX)).when(mockedNamespaceService).getPrefixes(RM_URI);
    // setup record folder and record
    recordFolder = generateRecordFolder();
    record = generateRecord();
    // set record as child of record folder
    List<ChildAssociationRef> result = new ArrayList<ChildAssociationRef>(1);
    result.add(new ChildAssociationRef(ContentModel.ASSOC_CONTAINS, recordFolder, generateQName(RM_URI), record, true, 1));
    doReturn(result).when(mockedNodeService).getChildAssocs(eq(recordFolder), eq(ContentModel.ASSOC_CONTAINS), any(QNamePattern.class));
    doReturn(result).when(mockedNodeService).getParentAssocs(record);
    doReturn(Collections.singletonList(recordFolder)).when(mockedRecordFolderService).getRecordFolders(record);
    doReturn(Collections.singletonList(record)).when(mockedRecordService).getRecords(recordFolder);
}
Also used : Mockito.doAnswer(org.mockito.Mockito.doAnswer) Answer(org.mockito.stubbing.Answer) RetryingTransactionCallback(org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback) InvocationOnMock(org.mockito.invocation.InvocationOnMock) QNamePattern(org.alfresco.service.namespace.QNamePattern) RegexQNamePattern(org.alfresco.service.namespace.RegexQNamePattern) ArrayList(java.util.ArrayList) ChildAssociationRef(org.alfresco.service.cmr.repository.ChildAssociationRef) Before(org.junit.Before)

Example 77 with RetryingTransactionCallback

use of org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback in project records-management by Alfresco.

the class FilePlanEntityResource method update.

@Override
@WebApiDescription(title = "Update file plan", description = "Updates a filePlan with id 'filePlanId'")
public FilePlan update(String filePlanId, FilePlan filePlanInfo, Parameters parameters) {
    checkNotBlank("filePlanId", filePlanId);
    mandatory("filePlanInfo", filePlanInfo);
    mandatory("parameters", parameters);
    QName filePlanType = apiUtils.getFilePlanType();
    if (// rm site not created
    filePlanType == null) {
        throw new EntityNotFoundException(filePlanId);
    }
    NodeRef nodeRef = apiUtils.lookupAndValidateNodeType(filePlanId, filePlanType);
    RetryingTransactionCallback<Void> updateCallback = new RetryingTransactionCallback<Void>() {

        public Void execute() {
            apiUtils.updateNode(nodeRef, filePlanInfo, parameters);
            return null;
        }
    };
    transactionService.getRetryingTransactionHelper().doInTransaction(updateCallback, false, true);
    RetryingTransactionCallback<FileInfo> readCallback = new RetryingTransactionCallback<FileInfo>() {

        public FileInfo execute() {
            return fileFolderService.getFileInfo(nodeRef);
        }
    };
    FileInfo info = transactionService.getRetryingTransactionHelper().doInTransaction(readCallback, false, true);
    return nodesModelFactory.createFilePlan(info, parameters, null, false);
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) FileInfo(org.alfresco.service.cmr.model.FileInfo) RetryingTransactionCallback(org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback) QName(org.alfresco.service.namespace.QName) EntityNotFoundException(org.alfresco.rest.framework.core.exceptions.EntityNotFoundException) WebApiDescription(org.alfresco.rest.framework.WebApiDescription)

Example 78 with RetryingTransactionCallback

use of org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback in project records-management by Alfresco.

the class RecordsManagementActionServiceImplTest method setUp.

@Override
protected void setUp() throws Exception {
    super.setUp();
    this.txnHelper = transactionService.getRetryingTransactionHelper();
    // Set the current security context as system
    AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getSystemUserName());
    RetryingTransactionCallback<Void> setUpCallback = new RetryingTransactionCallback<Void>() {

        public Void execute() throws Throwable {
            // Create a node we can use for the tests
            NodeRef rootNodeRef = nodeService.getRootNode(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE);
            nodeRef = nodeService.createNode(rootNodeRef, ContentModel.ASSOC_CHILDREN, QName.createQName(NamespaceService.CONTENT_MODEL_PREFIX, "temp.txt"), ContentModel.TYPE_CONTENT).getChildRef();
            // Create nodeRef list
            nodeRefs = new ArrayList<NodeRef>(5);
            for (int i = 0; i < 5; i++) {
                nodeRefs.add(nodeService.createNode(rootNodeRef, ContentModel.ASSOC_CHILDREN, QName.createQName(NamespaceService.CONTENT_MODEL_PREFIX, "temp.txt"), ContentModel.TYPE_CONTENT).getChildRef());
            }
            return null;
        }
    };
    txnHelper.doInTransaction(setUpCallback);
    beforeMarker = false;
    onMarker = false;
    inTest = false;
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) RetryingTransactionCallback(org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback)

Aggregations

RetryingTransactionCallback (org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback)78 NodeRef (org.alfresco.service.cmr.repository.NodeRef)44 RetryingTransactionHelper (org.alfresco.repo.transaction.RetryingTransactionHelper)20 FileInfo (org.alfresco.service.cmr.model.FileInfo)20 WebApiDescription (org.alfresco.rest.framework.WebApiDescription)16 HashMap (java.util.HashMap)15 AlfrescoRuntimeException (org.alfresco.error.AlfrescoRuntimeException)15 FacesContext (javax.faces.context.FacesContext)12 QName (org.alfresco.service.namespace.QName)11 Serializable (java.io.Serializable)10 List (java.util.List)9 ArrayList (java.util.ArrayList)8 ContentWriter (org.alfresco.service.cmr.repository.ContentWriter)8 IOException (java.io.IOException)7 FileNotFoundException (org.alfresco.service.cmr.model.FileNotFoundException)7 Test (org.junit.Test)7 WebScriptException (org.springframework.extensions.webscripts.WebScriptException)7 AuthenticationUtil (org.alfresco.repo.security.authentication.AuthenticationUtil)6 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)6 AbstractList (java.util.AbstractList)5