Search in sources :

Example 96 with FileInfo

use of org.alfresco.service.cmr.model.FileInfo in project records-management by Alfresco.

the class DynamicAuthoritiesGetUnitTest method processedWithParentNodeRef.

@SuppressWarnings("unchecked")
@Test
public void processedWithParentNodeRef() throws Exception {
    List<Long> ids = Stream.of(1l, 2l, 3l).collect(Collectors.toList());
    NodeRef parentNodeRef = AlfMock.generateNodeRef(mockedNodeService);
    List<FileInfo> children = new ArrayList<FileInfo>();
    ids.stream().forEach((i) -> {
        NodeRef nodeRef = AlfMock.generateNodeRef(mockedNodeService);
        when(mockedNodeService.hasAspect(nodeRef, ASPECT_RECORD)).thenReturn(true);
        when(mockedNodeService.hasAspect(nodeRef, ASPECT)).thenReturn(true);
        when(mockedNodeService.getProperty(nodeRef, PROP_READERS)).thenReturn((Serializable) Collections.emptyMap());
        when(mockedNodeService.getProperty(nodeRef, PROP_WRITERS)).thenReturn((Serializable) Collections.emptyMap());
        String name = "name" + i;
        when(mockedNodeService.getProperty(nodeRef, ContentModel.PROP_NAME)).thenReturn((Serializable) name);
        FileInfo mockedFileInfo = mock(FileInfo.class);
        when(mockedFileInfo.getNodeRef()).thenReturn(nodeRef);
        children.add(mockedFileInfo);
    });
    when(mockedFileFolderService.search(eq(parentNodeRef), eq("*"), eq(true), eq(true), eq(true))).thenReturn(children);
    Map<String, String> parameters = ImmutableMap.of("batchsize", "3", "maxProcessedRecords", "4", "export", "false", "parentNodeRef", parentNodeRef.toString());
    JSONObject json = executeJSONWebScript(parameters);
    assertNotNull(json);
    String actualJSONString = json.toString();
    ObjectMapper mapper = new ObjectMapper();
    String expectedJSONString = "{\"responsestatus\":\"success\",\"message\":\"Processed 3 records.\"}";
    assertEquals(mapper.readTree(expectedJSONString), mapper.readTree(actualJSONString));
    verify(contentStreamer, never()).streamContent(any(WebScriptRequest.class), any(WebScriptResponse.class), any(File.class), any(Long.class), any(Boolean.class), any(String.class), any(Map.class));
}
Also used : WebScriptRequest(org.springframework.extensions.webscripts.WebScriptRequest) ArrayList(java.util.ArrayList) NodeRef(org.alfresco.service.cmr.repository.NodeRef) FileInfo(org.alfresco.service.cmr.model.FileInfo) JSONObject(org.json.JSONObject) WebScriptResponse(org.springframework.extensions.webscripts.WebScriptResponse) Matchers.anyLong(org.mockito.Matchers.anyLong) Matchers.anyBoolean(org.mockito.Matchers.anyBoolean) File(java.io.File) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) Collections.emptyMap(java.util.Collections.emptyMap) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test) BaseWebScriptUnitTest(org.alfresco.module.org_alfresco_module_rm.test.util.BaseWebScriptUnitTest)

Example 97 with FileInfo

use of org.alfresco.service.cmr.model.FileInfo 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 98 with FileInfo

use of org.alfresco.service.cmr.model.FileInfo in project records-management by Alfresco.

the class FilePlanEntityResource method readById.

@WebApiDescription(title = "Get file plan information", description = "Get information for a file plan with id 'filePlanId'")
@WebApiParam(name = "filePlanId", title = "The file plan id")
public FilePlan readById(String filePlanId, Parameters parameters) {
    checkNotBlank("filePlanId", filePlanId);
    mandatory("parameters", parameters);
    QName filePlanType = apiUtils.getFilePlanType();
    if (// rm site not created
    filePlanType == null) {
        throw new EntityNotFoundException(filePlanId);
    }
    NodeRef nodeRef = apiUtils.lookupAndValidateNodeType(filePlanId, filePlanType);
    FileInfo info = fileFolderService.getFileInfo(nodeRef);
    return nodesModelFactory.createFilePlan(info, parameters, null, false);
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) FileInfo(org.alfresco.service.cmr.model.FileInfo) QName(org.alfresco.service.namespace.QName) EntityNotFoundException(org.alfresco.rest.framework.core.exceptions.EntityNotFoundException) WebApiDescription(org.alfresco.rest.framework.WebApiDescription) WebApiParam(org.alfresco.rest.framework.WebApiParam)

Example 99 with FileInfo

use of org.alfresco.service.cmr.model.FileInfo in project records-management by Alfresco.

the class RM4619Test method testConvertFolderToRecordFolder.

/**
 * Given an existing category
 * When we create a regular folder in the category
 * Then the folder is immediately converted to a record folder
 */
public void testConvertFolderToRecordFolder() throws Exception {
    /*
         * Create a folder in a record category and check it is converted
         */
    final NodeRef recordFolder = doTestInTransaction(new Test<NodeRef>() {

        @Override
        public NodeRef run() throws Exception {
            FileInfo info = fileFolderService.create(rmContainer, GUID.generate(), TYPE_FOLDER);
            return info.getNodeRef();
        }
    }, ADMIN_USER);
    doTestInTransaction(new Test<Void>() {

        @Override
        public Void run() throws Exception {
            assertEquals(TYPE_RECORD_FOLDER, nodeService.getType(recordFolder));
            assertNotNull(nodeService.getProperty(recordFolder, PROP_IDENTIFIER));
            return null;
        }
    }, ADMIN_USER);
    /*
         * Check that when the transaction ends the identifier is no longer editable
         * And the record folder has the ASPECT_RM_SEARCH aspect
         */
    doTestInTransaction(new Test<Void>() {

        @Override
        public Void run() throws Exception {
            assertTrue(nodeService.hasAspect(recordFolder, ASPECT_RM_SEARCH));
            return null;
        }
    }, ADMIN_USER);
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) FileInfo(org.alfresco.service.cmr.model.FileInfo)

Example 100 with FileInfo

use of org.alfresco.service.cmr.model.FileInfo in project records-management by Alfresco.

the class RM4619Test method testConvertFolderToCategory.

/**
 * Given the RM site is created
 * When we create a regular folder in the fileplan
 * Then the folder is immediately converted to a record category
 */
public void testConvertFolderToCategory() throws Exception {
    /*
         * Create a folder in the unfiled record container and check it is immediately converted
         */
    final NodeRef recordCategory = doTestInTransaction(new Test<NodeRef>() {

        @Override
        public NodeRef run() throws Exception {
            FileInfo info = fileFolderService.create(filePlan, GUID.generate(), TYPE_FOLDER);
            return info.getNodeRef();
        }
    }, ADMIN_USER);
    doTestInTransaction(new Test<Void>() {

        @Override
        public Void run() throws Exception {
            assertEquals(TYPE_RECORD_CATEGORY, nodeService.getType(recordCategory));
            assertNotNull(nodeService.getProperty(recordCategory, PROP_IDENTIFIER));
            return null;
        }
    }, ADMIN_USER);
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) FileInfo(org.alfresco.service.cmr.model.FileInfo)

Aggregations

FileInfo (org.alfresco.service.cmr.model.FileInfo)101 NodeRef (org.alfresco.service.cmr.repository.NodeRef)82 WebApiDescription (org.alfresco.rest.framework.WebApiDescription)34 FileNotFoundException (org.alfresco.service.cmr.model.FileNotFoundException)26 HashMap (java.util.HashMap)20 RetryingTransactionCallback (org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback)20 QName (org.alfresco.service.namespace.QName)20 AbstractList (java.util.AbstractList)13 UserInfo (org.alfresco.rest.api.model.UserInfo)13 WebApiParam (org.alfresco.rest.framework.WebApiParam)11 Test (org.junit.Test)11 ArrayList (java.util.ArrayList)10 AccessDeniedException (org.alfresco.repo.security.permissions.AccessDeniedException)10 FileFolderService (org.alfresco.service.cmr.model.FileFolderService)9 IOException (java.io.IOException)8 EntityNotFoundException (org.alfresco.rest.framework.core.exceptions.EntityNotFoundException)8 Serializable (java.io.Serializable)7 List (java.util.List)7 ContentWriter (org.alfresco.service.cmr.repository.ContentWriter)7 FacesContext (javax.faces.context.FacesContext)6