Search in sources :

Example 46 with FileInfo

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

the class FilesEntityResource method declareAsRecord.

@Operation("declare")
@WebApiDescription(title = "Declare as record", description = "Declare a file as record.")
public Record declareAsRecord(String fileId, Void body, Parameters parameters, WithResponse withResponse) {
    // Get fileplan
    NodeRef filePlan = authenticationUtil.runAsSystem(new RunAsWork<NodeRef>() {

        @Override
        public NodeRef doWork() {
            return filePlanService.getFilePlanBySiteId(FilePlanService.DEFAULT_RM_SITE_ID);
        }
    });
    // default false (if not provided)
    boolean hideRecord = Boolean.valueOf(parameters.getParameter(Record.PARAM_HIDE_RECORD));
    // Create the record
    NodeRef file = new NodeRef(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE, fileId);
    RetryingTransactionCallback<Void> callback = new RetryingTransactionCallback<Void>() {

        public Void execute() {
            recordService.createRecord(filePlan, file, !hideRecord);
            return null;
        }
    };
    transactionService.getRetryingTransactionHelper().doInTransaction(callback, false, true);
    // Return record state
    FileInfo info = fileFolderService.getFileInfo(file);
    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) Operation(org.alfresco.rest.framework.Operation)

Example 47 with FileInfo

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

the class RecordableVersionServiceImplUnitTest method before.

/**
 * @see org.alfresco.module.org_alfresco_module_rm.test.util.BaseUnitTest#before()
 */
@SuppressWarnings("unchecked")
@Override
public void before() throws Exception {
    super.before();
    nodeRef = generateCmContent(CONTENT_NAME);
    doReturn(123l).when(mockedNodeService).getProperty(nodeRef, ContentModel.PROP_NODE_DBID);
    versionProperties = new HashMap<String, Serializable>(5);
    recordableVersionService.initialise();
    doReturn(generateChildAssociationRef(null, generateNodeRef(Version2Model.TYPE_QNAME_VERSION_HISTORY))).when(mockedDbNodeService).createNode(any(NodeRef.class), any(QName.class), any(QName.class), eq(Version2Model.TYPE_QNAME_VERSION_HISTORY), anyMap());
    doReturn(generateChildAssociationRef(null, generateNodeRef(TYPE_CONTENT))).when(mockedDbNodeService).createNode(any(NodeRef.class), any(QName.class), any(QName.class), eq(TYPE_CONTENT), anyMap());
    doReturn(filePlan).when(mockedFilePlanService).getFilePlanBySiteId(FilePlanService.DEFAULT_RM_SITE_ID);
    doReturn(unfiledRecordContainer).when(mockedFilePlanService).getUnfiledContainer(any(NodeRef.class));
    record = generateCmContent(CONTENT_NAME);
    FileInfo mockedFileInfo = mock(FileInfo.class);
    doReturn(record).when(mockedFileInfo).getNodeRef();
    doReturn(mockedFileInfo).when(mockedFileFolderService).copy(any(NodeRef.class), any(NodeRef.class), any(String.class));
    version = generateNodeRef(TYPE_CONTENT);
    doReturn(generateChildAssociationRef(null, version)).when(mockedDbNodeService).createNode(any(NodeRef.class), eq(Version2Model.CHILD_QNAME_VERSIONS), any(QName.class), eq(TYPE_CONTENT), anyMap());
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) Serializable(java.io.Serializable) FileInfo(org.alfresco.service.cmr.model.FileInfo) QName(org.alfresco.service.namespace.QName) Matchers.anyString(org.mockito.Matchers.anyString)

Example 48 with FileInfo

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

the class DynamicAuthoritiesGetUnitTest method processedWithParentNodeRefWithFirstTwoBatchesAlreadyProcessed.

@SuppressWarnings("unchecked")
@Test
public void processedWithParentNodeRefWithFirstTwoBatchesAlreadyProcessed() throws Exception {
    List<Long> ids = Stream.of(1l, 2l, 3l, 4l, 5l, 6l, 7l, 8l).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);
        if (i <= 6l) {
            when(mockedNodeService.hasAspect(nodeRef, ASPECT)).thenReturn(false);
        } else {
            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", "parentNodeRef", parentNodeRef.toString());
    JSONObject json = executeJSONWebScript(parameters);
    assertNotNull(json);
    String actualJSONString = json.toString();
    ObjectMapper mapper = new ObjectMapper();
    String expectedJSONString = "{\"responsestatus\":\"success\",\"message\":\"Processed 2 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 49 with FileInfo

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

the class RecordFolderEntityResource method update.

@Override
@WebApiDescription(title = "Update record folder", description = "Updates a record folder with id 'recordFolderId'")
public RecordFolder update(String recordFolderId, RecordFolder recordFolderInfo, Parameters parameters) {
    checkNotBlank("recordFolderId", recordFolderId);
    mandatory("recordFolderInfo", recordFolderInfo);
    mandatory("parameters", parameters);
    NodeRef nodeRef = apiUtils.lookupAndValidateNodeType(recordFolderId, RecordsManagementModel.TYPE_RECORD_FOLDER);
    RetryingTransactionCallback<Void> callback = new RetryingTransactionCallback<Void>() {

        public Void execute() {
            apiUtils.updateNode(nodeRef, recordFolderInfo, 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.createRecordFolder(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 50 with FileInfo

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

the class RecordsEntityResource method fileRecord.

@Operation("file")
@WebApiDescription(title = "File record", description = "File a record into fileplan.")
public Record fileRecord(String recordId, TargetContainer target, Parameters parameters, WithResponse withResponse) {
    checkNotBlank("recordId", recordId);
    mandatory("target", target);
    mandatory("targetParentId", target.getTargetParentId());
    mandatory("parameters", parameters);
    // Get record and target folder
    NodeRef record = apiUtils.validateRecord(recordId);
    NodeRef targetRecordFolder = apiUtils.lookupAndValidateNodeType(target.getTargetParentId(), RecordsManagementModel.TYPE_RECORD_FOLDER);
    // Get the current parent type to decide if we link or move the record
    NodeRef primaryParent = nodeService.getPrimaryParent(record).getParentRef();
    if (RecordsManagementModel.TYPE_RECORD_FOLDER.equals(nodeService.getType(primaryParent))) {
        recordService.link(record, targetRecordFolder);
    } else {
        try {
            fileFolderService.moveFrom(record, primaryParent, targetRecordFolder, null);
        } catch (FileExistsException e) {
            throw new IntegrityException(e.getMessage(), null);
        } catch (FileNotFoundException e) {
            throw new ConcurrencyFailureException("The record was deleted while filing it", e);
        }
    }
    // return record state
    FileInfo info = fileFolderService.getFileInfo(record);
    return nodesModelFactory.createRecord(info, parameters, null, false);
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) FileInfo(org.alfresco.service.cmr.model.FileInfo) ConcurrencyFailureException(org.springframework.dao.ConcurrencyFailureException) FileNotFoundException(org.alfresco.service.cmr.model.FileNotFoundException) IntegrityException(org.alfresco.repo.node.integrity.IntegrityException) FileExistsException(org.alfresco.service.cmr.model.FileExistsException) WebApiDescription(org.alfresco.rest.framework.WebApiDescription) Operation(org.alfresco.rest.framework.Operation)

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