Search in sources :

Example 6 with RestNodeModel

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;
}
Also used : RestNodeModel(org.alfresco.rest.model.RestNodeModel)

Example 7 with RestNodeModel

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());
}
Also used : Site(org.alfresco.rest.requests.Site) SiteData(org.alfresco.bm.site.SiteData) EventResult(org.alfresco.bm.event.EventResult) RestNodeModel(org.alfresco.rest.model.RestNodeModel) NodeDetail(org.alfresco.rest.model.builder.NodesBuilder.NodeDetail) RestCoreAPI(org.alfresco.rest.requests.coreAPI.RestCoreAPI) Node(org.alfresco.rest.requests.Node) NodesBuilder(org.alfresco.rest.model.builder.NodesBuilder) StopWatch(org.apache.commons.lang3.time.StopWatch) Test(org.junit.Test)

Example 8 with RestNodeModel

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);
}
Also used : ContentModel(org.alfresco.utility.model.ContentModel) RecordData(org.alfresco.bm.dataload.rm.services.RecordData) RestNodeModel(org.alfresco.rest.model.RestNodeModel) RestNodeModelsCollection(org.alfresco.rest.model.RestNodeModelsCollection)

Aggregations

RestNodeModel (org.alfresco.rest.model.RestNodeModel)8 EventResult (org.alfresco.bm.event.EventResult)6 Node (org.alfresco.rest.requests.Node)6 Site (org.alfresco.rest.requests.Site)6 RestCoreAPI (org.alfresco.rest.requests.coreAPI.RestCoreAPI)6 StopWatch (org.apache.commons.lang3.time.StopWatch)6 Test (org.junit.Test)6 SiteData (org.alfresco.bm.site.SiteData)5 RestNodeModelsCollection (org.alfresco.rest.model.RestNodeModelsCollection)5 RestWrapper (org.alfresco.rest.core.RestWrapper)4 RestPaginationModel (org.alfresco.rest.model.RestPaginationModel)4 RestSiteContainerModel (org.alfresco.rest.model.RestSiteContainerModel)4 RestSiteModel (org.alfresco.rest.model.RestSiteModel)4 RepoTestModel (org.alfresco.utility.model.RepoTestModel)4 NodesBuilder (org.alfresco.rest.model.builder.NodesBuilder)3 NodeDetail (org.alfresco.rest.model.builder.NodesBuilder.NodeDetail)3 RecordData (org.alfresco.bm.dataload.rm.services.RecordData)1 ContentModel (org.alfresco.utility.model.ContentModel)1