Search in sources :

Example 71 with RetryingTransactionCallback

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

the class FilePlanChildrenRelation method create.

@Override
@WebApiDescription(title = "Create one (or more) record categories as children of container identified by 'filePlanId'")
public List<RecordCategory> create(String filePlanId, List<RecordCategory> nodeInfos, Parameters parameters) {
    checkNotBlank("filePlanId", filePlanId);
    mandatory("nodeInfos", nodeInfos);
    mandatory("parameters", parameters);
    QName filePlanType = apiUtils.getFilePlanType();
    if (// rm site not created
    filePlanType == null) {
        throw new EntityNotFoundException(filePlanId);
    }
    NodeRef parentNodeRef = apiUtils.lookupAndValidateNodeType(filePlanId, filePlanType);
    RetryingTransactionCallback<List<NodeRef>> callback = new RetryingTransactionCallback<List<NodeRef>>() {

        public List<NodeRef> execute() {
            List<NodeRef> createdNodes = new LinkedList<>();
            for (RecordCategory nodeInfo : nodeInfos) {
                // Create the node
                nodeInfo.setNodeType(RECORD_CATEGORY_TYPE);
                NodeRef newNodeRef = apiUtils.createRMNode(parentNodeRef, nodeInfo, parameters);
                createdNodes.add(newNodeRef);
            }
            return createdNodes;
        }
    };
    List<NodeRef> createdNodes = transactionService.getRetryingTransactionHelper().doInTransaction(callback, false, true);
    // Get the nodes info
    List<RecordCategory> result = new ArrayList<>(nodeInfos.size());
    Map<String, UserInfo> mapUserInfo = new HashMap<>();
    for (NodeRef newNodeRef : createdNodes) {
        FileInfo info = fileFolderService.getFileInfo(newNodeRef);
        result.add(nodesModelFactory.createRecordCategory(info, parameters, mapUserInfo, false));
    }
    return result;
}
Also used : HashMap(java.util.HashMap) QName(org.alfresco.service.namespace.QName) ArrayList(java.util.ArrayList) RecordCategory(org.alfresco.rm.rest.api.model.RecordCategory) UserInfo(org.alfresco.rest.api.model.UserInfo) EntityNotFoundException(org.alfresco.rest.framework.core.exceptions.EntityNotFoundException) LinkedList(java.util.LinkedList) NodeRef(org.alfresco.service.cmr.repository.NodeRef) FileInfo(org.alfresco.service.cmr.model.FileInfo) RetryingTransactionCallback(org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback) AbstractList(java.util.AbstractList) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) List(java.util.List) WebApiDescription(org.alfresco.rest.framework.WebApiDescription)

Example 72 with RetryingTransactionCallback

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

the class UnfiledContainerChildrenRelation method create.

@Override
@WebApiDescription(title = "Create one (or more) nodes as children of a unfiled container identified by 'unfiledContainerId'")
public List<UnfiledContainerChild> create(String unfiledContainerId, final List<UnfiledContainerChild> nodeInfos, Parameters parameters) {
    checkNotBlank("unfiledContainerId", unfiledContainerId);
    mandatory("nodeInfos", nodeInfos);
    mandatory("parameters", parameters);
    final NodeRef parentNodeRef = apiUtils.lookupAndValidateNodeType(unfiledContainerId, RecordsManagementModel.TYPE_UNFILED_RECORD_CONTAINER);
    // Create the nodes
    RetryingTransactionCallback<List<NodeRef>> callback = new RetryingTransactionCallback<List<NodeRef>>() {

        public List<NodeRef> execute() {
            List<NodeRef> createdNodes = new LinkedList<>();
            for (UnfiledContainerChild nodeInfo : nodeInfos) {
                NodeRef newNodeRef = apiUtils.createRMNode(parentNodeRef, nodeInfo, parameters);
                createdNodes.add(newNodeRef);
            }
            return createdNodes;
        }
    };
    List<NodeRef> createdNodes = transactionService.getRetryingTransactionHelper().doInTransaction(callback, false, true);
    // Get the nodes info
    List<UnfiledContainerChild> result = new LinkedList<>();
    Map<String, UserInfo> mapUserInfo = new HashMap<>();
    for (NodeRef newNodeRef : createdNodes) {
        FileInfo info = fileFolderService.getFileInfo(newNodeRef);
        apiUtils.postActivity(info, parentNodeRef, ActivityType.FILE_ADDED);
        result.add(nodesModelFactory.createUnfiledContainerChild(info, parameters, mapUserInfo, false));
    }
    return result;
}
Also used : UnfiledContainerChild(org.alfresco.rm.rest.api.model.UnfiledContainerChild) HashMap(java.util.HashMap) UserInfo(org.alfresco.rest.api.model.UserInfo) LinkedList(java.util.LinkedList) NodeRef(org.alfresco.service.cmr.repository.NodeRef) FileInfo(org.alfresco.service.cmr.model.FileInfo) RetryingTransactionCallback(org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback) AbstractList(java.util.AbstractList) LinkedList(java.util.LinkedList) List(java.util.List) WebApiDescription(org.alfresco.rest.framework.WebApiDescription)

Example 73 with RetryingTransactionCallback

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

the class RecordCategoriesEntityResource method update.

@Override
@WebApiDescription(title = "Update record category", description = "Updates a record category with id 'recordCategoryId'")
public RecordCategory update(String recordCategoryId, RecordCategory recordCategoryInfo, Parameters parameters) {
    checkNotBlank("recordCategoryId", recordCategoryId);
    mandatory("recordCategoryInfo", recordCategoryInfo);
    mandatory("parameters", parameters);
    NodeRef nodeRef = apiUtils.lookupAndValidateNodeType(recordCategoryId, RecordsManagementModel.TYPE_RECORD_CATEGORY);
    RetryingTransactionCallback<Void> callback = new RetryingTransactionCallback<Void>() {

        public Void execute() {
            apiUtils.updateNode(nodeRef, recordCategoryInfo, parameters);
            return null;
        }
    };
    transactionService.getRetryingTransactionHelper().doInTransaction(callback, 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.createRecordCategory(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) WebApiDescription(org.alfresco.rest.framework.WebApiDescription)

Example 74 with RetryingTransactionCallback

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

the class RecordsEntityResource method update.

@Override
@WebApiDescription(title = "Update record", description = "Updates a record with id 'recordId'")
public Record update(String recordId, Record recordInfo, Parameters parameters) {
    checkNotBlank("recordId", recordId);
    mandatory("recordInfo", recordInfo);
    mandatory("parameters", parameters);
    // Get record
    NodeRef record = apiUtils.validateRecord(recordId);
    // update info
    RetryingTransactionCallback<Void> callback = new RetryingTransactionCallback<Void>() {

        public Void execute() {
            apiUtils.updateNode(record, recordInfo, parameters);
            return null;
        }
    };
    transactionService.getRetryingTransactionHelper().doInTransaction(callback, false, true);
    // return record state
    RetryingTransactionCallback<FileInfo> readCallback = new RetryingTransactionCallback<FileInfo>() {

        public FileInfo execute() {
            return fileFolderService.getFileInfo(record);
        }
    };
    FileInfo info = transactionService.getRetryingTransactionHelper().doInTransaction(readCallback, false, true);
    apiUtils.postActivity(info, recordInfo.getParentId(), ActivityType.FILE_UPDATED);
    return nodesModelFactory.createRecord(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) WebApiDescription(org.alfresco.rest.framework.WebApiDescription)

Example 75 with RetryingTransactionCallback

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

the class ExtendedSecurityServiceImplUnitTest method before.

/**
 * Before tests
 */
@SuppressWarnings("unchecked")
@Before
public void before() {
    // initialise mocks
    MockitoAnnotations.initMocks(this);
    // setup node
    nodeRef = AlfMock.generateNodeRef(mockedNodeService);
    // setup file plan
    filePlan = AlfMock.generateNodeRef(mockedNodeService);
    when(mockedFilePlanService.getFilePlan(any(NodeRef.class))).thenReturn(filePlan);
    // set-up application context
    when(mockedApplicationContext.getBean("dbNodeService")).thenReturn(mockedNodeService);
    // 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));
    when(mockedTransactionService.getRetryingTransactionHelper()).thenReturn(mockedRetryingTransactionHelper);
    // setup create authority
    Answer<String> createAuthorityAnswer = new Answer<String>() {

        public String answer(InvocationOnMock invocation) throws Throwable {
            return PermissionService.GROUP_PREFIX + (String) invocation.getArguments()[1];
        }
    };
    when(mockedAuthorityService.createAuthority(any(AuthorityType.class), anyString(), anyString(), anySet())).thenAnswer(createAuthorityAnswer);
    // setup group prefixes
    readGroupPrefix = extendedSecurityService.getIPRGroupPrefixShortName(READER_GROUP_PREFIX, READERS);
    writeGroupPrefix = extendedSecurityService.getIPRGroupPrefixShortName(WRITER_GROUP_PREFIX, WRITERS);
    // make sure the users and groups exist
    Stream.of(USER, USER_W, GROUP, GROUP_W).forEach((a) -> when(mockedAuthorityService.authorityExists(a)).thenReturn(true));
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) Mockito.doAnswer(org.mockito.Mockito.doAnswer) Answer(org.mockito.stubbing.Answer) AuthorityType(org.alfresco.service.cmr.security.AuthorityType) RetryingTransactionCallback(org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback) InvocationOnMock(org.mockito.invocation.InvocationOnMock) Matchers.anyString(org.mockito.Matchers.anyString) Before(org.junit.Before)

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