use of org.alfresco.utility.model.ContentModel in project records-management by Alfresco.
the class ScheduleInPlaceRecordLoadersUnitTest method mockNodesEndpoint.
/**
* Utility method that mocks the nodes endpoint
*
* @param mockedCoreApi the mocked core api
* @param nodeId the id of the node to mock the endpoint for
* @return the mocked endpoint
* @throws Exception
*/
private Node mockNodesEndpoint(RestCoreAPI mockedCoreApi, String nodeId) throws Exception {
ArgumentMatcher<ContentModel> modelForCurrentNode = new ArgumentMatcher<ContentModel>() {
@Override
public boolean matches(Object argument) {
return ((ContentModel) argument).getNodeRef().equals(nodeId);
}
};
Node nodesEndpoint = mock(Node.class);
doReturn(nodesEndpoint).when(mockedCoreApi).usingNode(argThat(modelForCurrentNode));
return nodesEndpoint;
}
use of org.alfresco.utility.model.ContentModel in project records-management by Alfresco.
the class ScheduleInPlaceRecordLoaders method prepareFilesToBeDeclared.
/**
* Helper method that makes sure the collaboration site contains enough files to declare.
* If the collaboration site doesn't have enough files it creates new empty files.
* The method caches the ids of the files ready to be declared in unscheduledFileBuffer queue.
*
* @param eventOutputMsg
* @throws Exception
*/
public void prepareFilesToBeDeclared(StringBuilder eventOutputMsg) throws Exception {
if (!unscheduledFilesCache.isEmpty()) {
return;
}
eventOutputMsg.append("Preparing files to declare: \n");
// Get the collaboration site document library
String documentLibraryNodeId = getCollaborationSiteDoclib(eventOutputMsg);
// Get the existing files in the provided paths
for (String relativePath : collabSitePaths) {
if (numberOfFilesLeftToPreload() <= 0) {
// we have enough files cached
return;
}
preloadExistingFiles(documentLibraryNodeId, relativePath, eventOutputMsg);
}
/*
* Not enough files to load, create new files
*/
if (recordDeclarationLimit == 0) {
// If number of records to declare is 0 declare all files we can find but don't create new files
return;
}
int filesToCreate = numberOfFilesLeftToPreload();
if (filesToCreate > 0) {
// Create a folder in document library
ContentModel currentNodeModel = new ContentModel();
currentNodeModel.setNodeRef(documentLibraryNodeId);
NodeDetail targetFolder = restCoreAPI.withCoreAPI().usingNode(currentNodeModel).defineNodes().folder("AutoGeneratedFiles");
for (int i = 0; i < filesToCreate; i++) {
// Create a new file
NodeDetail file = targetFolder.file("recordToBe");
eventOutputMsg.append("Created file " + file.getId() + ".");
RecordData record = new RecordData(file.getId(), RecordContext.IN_PLACE_RECORD, file.getName(), null, null, ExecutionState.SCHEDULED);
unscheduledFilesCache.add(record);
if (numberOfFilesLeftToPreload() <= 0) {
return;
}
}
}
}
use of org.alfresco.utility.model.ContentModel 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