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);
}
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());
}
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));
}
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);
}
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);
}
Aggregations