use of org.alfresco.rest.model.RestNodeModel in project records-management by Alfresco.
the class ScheduleInPlaceRecordLoadersUnitTest method mockNodeModel.
/**
* Utility method that mock a node model
* @param id the id of the node to mock
* @param isFile isFile value of the node to mock
* @return the mocked model for the file
* @throws Exception
*/
private RestNodeModel mockNodeModel(String id, boolean isFile) throws Exception {
RestNodeModel node = mock(RestNodeModel.class);
RestNodeModel onModelNode = mock(RestNodeModel.class);
when(node.onModel()).thenReturn(onModelNode);
when(onModelNode.getId()).thenReturn(id);
when(onModelNode.getIsFile()).thenReturn(isFile);
when(onModelNode.getName()).thenReturn("fileName");
return node;
}
use of org.alfresco.rest.model.RestNodeModel in project records-management by Alfresco.
the class ScheduleInPlaceRecordLoadersUnitTest method testDeclareRecordsColabSiteExistsAndLoadedInDb.
/**
* Given the collaboration site already exists and is loaded in the database
* When running the scheduler with numberOfRecordsToDeclare=1
* Then we don't attempt to load or create the site and 1 file is created and scheduled to be declared
*
* @throws Exception
*/
@Test
public void testDeclareRecordsColabSiteExistsAndLoadedInDb() throws Exception {
String fileID = UUID.randomUUID().toString();
/*
* Given
*/
String numberOfRecordsToDeclare = "1";
scheduleInPlaceRecordLoaders.setEnabled(true);
scheduleInPlaceRecordLoaders.setRecordDeclarationLimit(numberOfRecordsToDeclare);
scheduleInPlaceRecordLoaders.setMaxActiveLoaders(DEFAULT_MAX_ACTIVE_LOADERS);
scheduleInPlaceRecordLoaders.setCollabSiteId(DEFAULT_COLLABORATION_SITE_ID);
scheduleInPlaceRecordLoaders.setCollabSitePaths(null);
RestCoreAPI mockedRestCoreAPI = mockCoreApi();
Site mockedSitesEndpoint = mockSitesEndpoint(mockedRestCoreAPI, DEFAULT_COLLABORATION_SITE_ID);
String documentLibraryId = mockExistingCollaborationSite(mockedSitesEndpoint, DEFAULT_COLLABORATION_SITE_ID, true);
Node doclibNodesEndpoint = mockNodesEndpoint(mockedRestCoreAPI, documentLibraryId);
mockListChildren(doclibNodesEndpoint, false, new ArrayList<RestNodeModel>());
// mock node builder
NodesBuilder mockedNodeBuilder = mock(NodesBuilder.class);
when(doclibNodesEndpoint.defineNodes()).thenReturn(mockedNodeBuilder);
// mock create folder helper method
NodeDetail mockedAutoGeneratedFolder = mock(NodeDetail.class);
when(mockedNodeBuilder.folder("AutoGeneratedFiles")).thenReturn(mockedAutoGeneratedFolder);
// mock create file
NodeDetail mockedFile = mock(NodeDetail.class);
when(mockedFile.getId()).thenReturn(fileID);
when(mockedFile.getName()).thenReturn("fileName");
when(mockedAutoGeneratedFolder.file("recordToBe")).thenReturn(mockedFile);
/*
* When
*/
EventResult result = scheduleInPlaceRecordLoaders.processEvent(null, new StopWatch());
/*
* Then
*/
verify(mockedSitesEndpoint, never()).createSite();
verify(mockedSiteDataService, never()).addSite(any(SiteData.class));
assertEquals(true, result.isSuccess());
List<String> createdAndScheduledFiles = Arrays.asList(fileID);
validateScheduleFilesOutputMessage(createdAndScheduledFiles, createdAndScheduledFiles, (String) result.getData());
validateFiredEvents(true, Arrays.asList(fileID), result.getNextEvents());
}
use of org.alfresco.rest.model.RestNodeModel in project records-management by Alfresco.
the class ScheduleInPlaceRecordLoaders method preloadExistingFiles.
/**
* Helper method that iterates the hierarchy tree starting from a folder and caches the file ids
* If the path doesn't exist nothing happens
*
* @param currentNodeId
* @param relativePath
* @param eventOutputMsg
* @throws Exception
*/
private void preloadExistingFiles(String currentNodeId, String relativePath, StringBuilder eventOutputMsg) throws Exception {
boolean moreChildren;
int skipCount = 0;
do {
ContentModel currentNodeModel = new ContentModel();
currentNodeModel.setNodeRef(currentNodeId);
RestNodeModelsCollection children = restCoreAPI.withParams("where=(isPrimary=true)", "relativePath=" + relativePath, "skipCount=" + skipCount).withCoreAPI().usingNode(currentNodeModel).listChildren();
if (Integer.parseInt(restCoreAPI.getStatusCode()) == HttpStatus.SC_NOT_FOUND) {
return;
}
for (RestNodeModel child : children.getEntries()) {
if (numberOfFilesLeftToPreload() <= 0) {
// we have enough files
return;
}
if (child.onModel().getIsFile()) {
RecordData record = new RecordData(child.onModel().getId(), RecordContext.IN_PLACE_RECORD, child.onModel().getName(), null, null, ExecutionState.SCHEDULED);
unscheduledFilesCache.add(record);
} else if (!fullLoadedFolders.contains(child.onModel().getId())) {
preloadExistingFiles(child.onModel().getId(), "", eventOutputMsg);
}
}
moreChildren = children.getPagination().isHasMoreItems();
skipCount += children.getPagination().getCount();
} while (moreChildren);
// mark the folder as complete to avoid listing its children in a following iteration
fullLoadedFolders.add(currentNodeId);
}
Aggregations