Search in sources :

Example 6 with RestNodeModelsCollection

use of org.alfresco.rest.model.RestNodeModelsCollection in project records-management by Alfresco.

the class ScheduleInPlaceRecordLoadersUnitTest method testDeclareRecordsFromTwiDiferentPaths.

@Test
public void testDeclareRecordsFromTwiDiferentPaths() throws Exception {
    String numberOfRecordsToDeclare = "2";
    int maxActiveLoaders = 8;
    String siteId = "testSiteId";
    String documentLibraryId = UUID.randomUUID().toString();
    scheduleInPlaceRecordLoaders.setEnabled(true);
    scheduleInPlaceRecordLoaders.setRecordDeclarationLimit(numberOfRecordsToDeclare);
    scheduleInPlaceRecordLoaders.setMaxActiveLoaders(maxActiveLoaders);
    scheduleInPlaceRecordLoaders.setCollabSiteId(siteId);
    scheduleInPlaceRecordLoaders.setCollabSitePaths("path1,path2");
    RestSiteModel mockedRestSiteModel = mock(RestSiteModel.class);
    RestSiteContainerModel mockedRestSiteContainerModel = mock(RestSiteContainerModel.class);
    when(mockedRestSiteContainerModel.getId()).thenReturn(documentLibraryId);
    Site mockedSite = mock(Site.class);
    when(mockedSite.getSite()).thenReturn(mockedRestSiteModel);
    when(mockedSite.getSiteContainer("documentLibrary")).thenReturn(mockedRestSiteContainerModel);
    RestCoreAPI mockedRestCoreAPI = mock(RestCoreAPI.class);
    when(mockedRestCoreAPI.usingSite(siteId.toLowerCase())).thenReturn(mockedSite);
    when(mockedRestWrapper.withCoreAPI()).thenReturn(mockedRestCoreAPI);
    when(mockedRestWrapper.getStatusCode()).thenReturn(Integer.toString(HttpStatus.SC_OK));
    SiteData mockedSiteData = mock(SiteData.class);
    when(mockedSiteDataService.getSite(siteId.toLowerCase())).thenReturn(mockedSiteData);
    RestPaginationModel mockedPagination = mock(RestPaginationModel.class);
    when(mockedPagination.isHasMoreItems()).thenReturn(false);
    RestNodeModelsCollection mockedCollection = mock(RestNodeModelsCollection.class);
    when(mockedCollection.getPagination()).thenReturn(mockedPagination);
    String childFileId1 = "childFileId1";
    RestNodeModel mockedOnModel1 = mock(RestNodeModel.class);
    when(mockedOnModel1.getIsFile()).thenReturn(true);
    when(mockedOnModel1.getId()).thenReturn(childFileId1);
    when(mockedOnModel1.getName()).thenReturn("fileName1");
    RestNodeModel mockedFile1 = mock(RestNodeModel.class);
    when(mockedFile1.onModel()).thenReturn(mockedOnModel1);
    String childFileId2 = "childFileId2";
    RestNodeModel mockedOnModel2 = mock(RestNodeModel.class);
    when(mockedOnModel2.getIsFile()).thenReturn(true);
    when(mockedOnModel2.getId()).thenReturn(childFileId2);
    when(mockedOnModel2.getName()).thenReturn("fileName2");
    RestNodeModel mockedFile2 = mock(RestNodeModel.class);
    when(mockedFile2.onModel()).thenReturn(mockedOnModel2);
    when(mockedCollection.getEntries()).thenReturn(Arrays.asList(mockedFile1)).thenReturn(Arrays.asList(mockedFile2));
    Node mockedNode = mock(Node.class);
    when(mockedNode.listChildren()).thenReturn(mockedCollection);
    RestCoreAPI mockedRestCoreAPIWithParams = mock(RestCoreAPI.class);
    when(mockedRestCoreAPIWithParams.usingNode(any(RepoTestModel.class))).thenReturn(mockedNode);
    RestWrapper mockedRestWrapperWithParams = mock(RestWrapper.class);
    when(mockedRestWrapperWithParams.withCoreAPI()).thenReturn(mockedRestCoreAPIWithParams);
    when(mockedRestWrapper.withParams(any(String.class), any(String.class), any(String.class))).thenReturn(mockedRestWrapperWithParams);
    EventResult result = scheduleInPlaceRecordLoaders.processEvent(null, new StopWatch());
    verify(mockedSite, never()).createSite();
    verify(mockedSiteDataService, never()).addSite(any(SiteData.class));
    assertEquals(true, result.isSuccess());
    String template = "Preparing files to declare: \nSheduled file to be declared as record: {0}. Sheduled file to be declared as record: {1}. Raised further {2} events and rescheduled self.";
    assertEquals(MessageFormat.format(template, childFileId1, childFileId2, 2), result.getData());
    assertEquals(3, result.getNextEvents().size());
    assertEquals(scheduleInPlaceRecordLoaders.getEventNameDeclareInPlaceRecord(), result.getNextEvents().get(0).getName());
    assertEquals(scheduleInPlaceRecordLoaders.getEventNameDeclareInPlaceRecord(), result.getNextEvents().get(1).getName());
    assertEquals(scheduleInPlaceRecordLoaders.getEventNameRescheduleSelf(), result.getNextEvents().get(2).getName());
}
Also used : Site(org.alfresco.rest.requests.Site) SiteData(org.alfresco.bm.site.SiteData) RestCoreAPI(org.alfresco.rest.requests.coreAPI.RestCoreAPI) Node(org.alfresco.rest.requests.Node) RepoTestModel(org.alfresco.utility.model.RepoTestModel) RestWrapper(org.alfresco.rest.core.RestWrapper) RestNodeModelsCollection(org.alfresco.rest.model.RestNodeModelsCollection) StopWatch(org.apache.commons.lang3.time.StopWatch) RestPaginationModel(org.alfresco.rest.model.RestPaginationModel) EventResult(org.alfresco.bm.event.EventResult) RestSiteModel(org.alfresco.rest.model.RestSiteModel) RestNodeModel(org.alfresco.rest.model.RestNodeModel) RestSiteContainerModel(org.alfresco.rest.model.RestSiteContainerModel) Test(org.junit.Test)

Example 7 with RestNodeModelsCollection

use of org.alfresco.rest.model.RestNodeModelsCollection in project records-management by Alfresco.

the class ScheduleInPlaceRecordLoadersUnitTest method testDeclareRecordsColabSiteExistsNotLoadedInDb.

@Test
public void testDeclareRecordsColabSiteExistsNotLoadedInDb() throws Exception {
    String numberOfRecordsToDeclare = "1";
    int maxActiveLoaders = 8;
    String siteId = "testSiteId";
    String documentLibraryId = UUID.randomUUID().toString();
    String siteTitle = "someTitle";
    String guid = UUID.randomUUID().toString();
    String description = "someDescription";
    String preset = "somePreset";
    Visibility visibility = Visibility.PUBLIC;
    scheduleInPlaceRecordLoaders.setEnabled(true);
    scheduleInPlaceRecordLoaders.setRecordDeclarationLimit(numberOfRecordsToDeclare);
    scheduleInPlaceRecordLoaders.setMaxActiveLoaders(maxActiveLoaders);
    scheduleInPlaceRecordLoaders.setCollabSiteId(siteId);
    scheduleInPlaceRecordLoaders.setCollabSitePaths(null);
    RestSiteModel mockedRestSiteModel = mock(RestSiteModel.class);
    when(mockedRestSiteModel.getTitle()).thenReturn(siteTitle);
    when(mockedRestSiteModel.getGuid()).thenReturn(guid);
    when(mockedRestSiteModel.getDescription()).thenReturn(description);
    when(mockedRestSiteModel.getPreset()).thenReturn(preset);
    when(mockedRestSiteModel.getVisibility()).thenReturn(visibility);
    RestSiteContainerModel mockedRestSiteContainerModel = mock(RestSiteContainerModel.class);
    when(mockedRestSiteContainerModel.getId()).thenReturn(documentLibraryId);
    Site mockedSite = mock(Site.class);
    when(mockedSite.getSite()).thenReturn(mockedRestSiteModel);
    when(mockedSite.getSiteContainer("documentLibrary")).thenReturn(mockedRestSiteContainerModel);
    RestCoreAPI mockedRestCoreAPI = mock(RestCoreAPI.class);
    when(mockedRestCoreAPI.usingSite(siteId.toLowerCase())).thenReturn(mockedSite);
    when(mockedRestWrapper.withCoreAPI()).thenReturn(mockedRestCoreAPI);
    when(mockedRestWrapper.getStatusCode()).thenReturn(Integer.toString(HttpStatus.SC_OK));
    when(mockedSiteDataService.getSite(siteId.toLowerCase())).thenReturn(null);
    RestPaginationModel mockedPagination = mock(RestPaginationModel.class);
    when(mockedPagination.isHasMoreItems()).thenReturn(false);
    RestNodeModelsCollection mockedCollection = mock(RestNodeModelsCollection.class);
    when(mockedCollection.getPagination()).thenReturn(mockedPagination);
    Node mockedNode = mock(Node.class);
    when(mockedNode.listChildren()).thenReturn(mockedCollection);
    when(mockedRestCoreAPI.usingNode(any(RepoTestModel.class))).thenReturn(mockedNode);
    RestWrapper mockedRestWrapperWithParams = mock(RestWrapper.class);
    when(mockedRestWrapperWithParams.withCoreAPI()).thenReturn(mockedRestCoreAPI);
    when(mockedRestWrapper.withParams(any(String.class), any(String.class), any(String.class))).thenReturn(mockedRestWrapperWithParams);
    // for creating files
    NodeDetail mockedTargetNodeDetail = mock(NodeDetail.class);
    NodesBuilder mockedNodeBuilder = mock(NodesBuilder.class);
    when(mockedNodeBuilder.folder("AutoGeneratedFiles")).thenReturn(mockedTargetNodeDetail);
    when(mockedNode.defineNodes()).thenReturn(mockedNodeBuilder);
    when(mockedRestWrapper.withCoreAPI()).thenReturn(mockedRestCoreAPI);
    NodeDetail mockedFile = mock(NodeDetail.class);
    String fileID = UUID.randomUUID().toString();
    when(mockedFile.getId()).thenReturn(fileID);
    when(mockedFile.getName()).thenReturn("recordName");
    when(mockedTargetNodeDetail.file("recordToBe")).thenReturn(mockedFile);
    EventResult result = scheduleInPlaceRecordLoaders.processEvent(null, new StopWatch());
    verify(mockedSite, never()).createSite();
    verify(mockedSiteDataService, times(1)).addSite(any(SiteData.class));
    assertEquals(true, result.isSuccess());
    String template = "Preparing files to declare: \n Added site \"{0}\" as created.\nCreated file {1}.Sheduled file to be declared as record: {2}. Raised further {3} events and rescheduled self.";
    assertEquals(MessageFormat.format(template, siteId.toLowerCase(), fileID, fileID, 1), result.getData());
    assertEquals(2, result.getNextEvents().size());
    assertEquals(scheduleInPlaceRecordLoaders.getEventNameDeclareInPlaceRecord(), result.getNextEvents().get(0).getName());
    assertEquals(scheduleInPlaceRecordLoaders.getEventNameRescheduleSelf(), result.getNextEvents().get(1).getName());
}
Also used : Site(org.alfresco.rest.requests.Site) SiteData(org.alfresco.bm.site.SiteData) RestCoreAPI(org.alfresco.rest.requests.coreAPI.RestCoreAPI) Node(org.alfresco.rest.requests.Node) RepoTestModel(org.alfresco.utility.model.RepoTestModel) RestWrapper(org.alfresco.rest.core.RestWrapper) RestNodeModelsCollection(org.alfresco.rest.model.RestNodeModelsCollection) StopWatch(org.apache.commons.lang3.time.StopWatch) RestPaginationModel(org.alfresco.rest.model.RestPaginationModel) EventResult(org.alfresco.bm.event.EventResult) RestSiteModel(org.alfresco.rest.model.RestSiteModel) NodeDetail(org.alfresco.rest.model.builder.NodesBuilder.NodeDetail) NodesBuilder(org.alfresco.rest.model.builder.NodesBuilder) Visibility(org.alfresco.dataprep.SiteService.Visibility) RestSiteContainerModel(org.alfresco.rest.model.RestSiteContainerModel) Test(org.junit.Test)

Example 8 with RestNodeModelsCollection

use of org.alfresco.rest.model.RestNodeModelsCollection in project records-management by Alfresco.

the class ScheduleInPlaceRecordLoadersUnitTest method testDeclareRecordsColabSiteDoesNotExistsNotLoadedInDb.

@Test
public void testDeclareRecordsColabSiteDoesNotExistsNotLoadedInDb() throws Exception {
    String numberOfRecordsToDeclare = "1";
    int maxActiveLoaders = 8;
    String siteId = "testSiteId";
    String documentLibraryId = UUID.randomUUID().toString();
    String siteTitle = "someTitle";
    String guid = UUID.randomUUID().toString();
    String description = "someDescription";
    String preset = "somePreset";
    Visibility visibility = Visibility.PUBLIC;
    scheduleInPlaceRecordLoaders.setEnabled(true);
    scheduleInPlaceRecordLoaders.setRecordDeclarationLimit(numberOfRecordsToDeclare);
    scheduleInPlaceRecordLoaders.setMaxActiveLoaders(maxActiveLoaders);
    scheduleInPlaceRecordLoaders.setCollabSiteId(siteId);
    scheduleInPlaceRecordLoaders.setCollabSitePaths(null);
    RestSiteModel mockedRestSiteModel = mock(RestSiteModel.class);
    when(mockedRestSiteModel.getTitle()).thenReturn(siteTitle);
    when(mockedRestSiteModel.getGuid()).thenReturn(guid);
    when(mockedRestSiteModel.getDescription()).thenReturn(description);
    when(mockedRestSiteModel.getPreset()).thenReturn(preset);
    when(mockedRestSiteModel.getVisibility()).thenReturn(visibility);
    RestSiteContainerModel mockedRestSiteContainerModel = mock(RestSiteContainerModel.class);
    when(mockedRestSiteContainerModel.getId()).thenReturn(documentLibraryId);
    Site mockedSite = mock(Site.class);
    when(mockedSite.getSite()).thenReturn(null);
    when(mockedSite.createSite()).thenReturn(mockedRestSiteModel);
    when(mockedSite.getSiteContainer("documentLibrary")).thenReturn(mockedRestSiteContainerModel);
    RestCoreAPI mockedRestCoreAPI = mock(RestCoreAPI.class);
    when(mockedRestCoreAPI.usingSite(siteId.toLowerCase())).thenReturn(mockedSite);
    when(mockedRestWrapper.withCoreAPI()).thenReturn(mockedRestCoreAPI);
    when(mockedRestWrapper.getStatusCode()).thenReturn(Integer.toString(HttpStatus.SC_NOT_FOUND));
    when(mockedSiteDataService.getSite(siteId.toLowerCase())).thenReturn(null);
    RestPaginationModel mockedPagination = mock(RestPaginationModel.class);
    when(mockedPagination.isHasMoreItems()).thenReturn(false);
    RestNodeModelsCollection mockedCollection = mock(RestNodeModelsCollection.class);
    when(mockedCollection.getPagination()).thenReturn(mockedPagination);
    Node mockedNode = mock(Node.class);
    when(mockedNode.listChildren()).thenReturn(mockedCollection);
    RestCoreAPI mockedRestCoreAPIWithParams = mock(RestCoreAPI.class);
    when(mockedRestCoreAPIWithParams.usingNode(any(RepoTestModel.class))).thenReturn(mockedNode);
    RestWrapper mockedRestWrapperWithParams = mock(RestWrapper.class);
    when(mockedRestWrapperWithParams.withCoreAPI()).thenReturn(mockedRestCoreAPIWithParams);
    when(mockedRestWrapper.withParams(any(String.class), any(String.class), any(String.class))).thenReturn(mockedRestWrapperWithParams);
    // for creating files
    NodeDetail mockedTargetNodeDetail = mock(NodeDetail.class);
    NodesBuilder mockedNodeBuilder = mock(NodesBuilder.class);
    when(mockedNodeBuilder.folder("AutoGeneratedFiles")).thenReturn(mockedTargetNodeDetail);
    when(mockedNode.defineNodes()).thenReturn(mockedNodeBuilder);
    when(mockedRestCoreAPI.usingNode(any(RepoTestModel.class))).thenReturn(mockedNode);
    NodeDetail mockedFile = mock(NodeDetail.class);
    String fileID = UUID.randomUUID().toString();
    when(mockedFile.getId()).thenReturn(fileID);
    when(mockedFile.getName()).thenReturn("fileName");
    when(mockedTargetNodeDetail.file("recordToBe")).thenReturn(mockedFile);
    EventResult result = scheduleInPlaceRecordLoaders.processEvent(null, new StopWatch());
    verify(mockedSite, times(1)).createSite();
    verify(mockedSiteDataService, times(1)).addSite(any(SiteData.class));
    assertEquals(true, result.isSuccess());
    String template = "Preparing files to declare: \n Added site \"{0}\" as created.\nCreated file {1}.Sheduled file to be declared as record: {2}. Raised further {3} events and rescheduled self.";
    assertEquals(MessageFormat.format(template, siteId.toLowerCase(), fileID, fileID, 1), result.getData());
    assertEquals(2, result.getNextEvents().size());
    assertEquals(scheduleInPlaceRecordLoaders.getEventNameDeclareInPlaceRecord(), result.getNextEvents().get(0).getName());
    assertEquals(scheduleInPlaceRecordLoaders.getEventNameRescheduleSelf(), result.getNextEvents().get(1).getName());
}
Also used : Site(org.alfresco.rest.requests.Site) SiteData(org.alfresco.bm.site.SiteData) RestCoreAPI(org.alfresco.rest.requests.coreAPI.RestCoreAPI) Node(org.alfresco.rest.requests.Node) RepoTestModel(org.alfresco.utility.model.RepoTestModel) RestWrapper(org.alfresco.rest.core.RestWrapper) RestNodeModelsCollection(org.alfresco.rest.model.RestNodeModelsCollection) StopWatch(org.apache.commons.lang3.time.StopWatch) RestPaginationModel(org.alfresco.rest.model.RestPaginationModel) EventResult(org.alfresco.bm.event.EventResult) RestSiteModel(org.alfresco.rest.model.RestSiteModel) NodeDetail(org.alfresco.rest.model.builder.NodesBuilder.NodeDetail) NodesBuilder(org.alfresco.rest.model.builder.NodesBuilder) Visibility(org.alfresco.dataprep.SiteService.Visibility) RestSiteContainerModel(org.alfresco.rest.model.RestSiteContainerModel) Test(org.junit.Test)

Example 9 with RestNodeModelsCollection

use of org.alfresco.rest.model.RestNodeModelsCollection in project records-management by Alfresco.

the class ScheduleInPlaceRecordLoadersUnitTest method testDeclareRecordsNonExistentNodeId.

@Test
public void testDeclareRecordsNonExistentNodeId() throws Exception {
    String numberOfRecordsToDeclare = "1";
    int maxActiveLoaders = 8;
    String siteId = "testSiteId";
    String documentLibraryId = UUID.randomUUID().toString();
    scheduleInPlaceRecordLoaders.setEnabled(true);
    scheduleInPlaceRecordLoaders.setRecordDeclarationLimit(numberOfRecordsToDeclare);
    scheduleInPlaceRecordLoaders.setMaxActiveLoaders(maxActiveLoaders);
    scheduleInPlaceRecordLoaders.setCollabSiteId(siteId);
    scheduleInPlaceRecordLoaders.setCollabSitePaths(null);
    RestSiteModel mockedRestSiteModel = mock(RestSiteModel.class);
    RestSiteContainerModel mockedRestSiteContainerModel = mock(RestSiteContainerModel.class);
    when(mockedRestSiteContainerModel.getId()).thenReturn(documentLibraryId);
    Site mockedSite = mock(Site.class);
    when(mockedSite.getSite()).thenReturn(mockedRestSiteModel);
    when(mockedSite.getSiteContainer("documentLibrary")).thenReturn(mockedRestSiteContainerModel);
    RestCoreAPI mockedRestCoreAPI = mock(RestCoreAPI.class);
    when(mockedRestCoreAPI.usingSite(siteId.toLowerCase())).thenReturn(mockedSite);
    when(mockedRestWrapper.withCoreAPI()).thenReturn(mockedRestCoreAPI);
    when(mockedRestWrapper.getStatusCode()).thenReturn(Integer.toString(HttpStatus.SC_OK)).thenReturn(Integer.toString(HttpStatus.SC_NOT_FOUND));
    SiteData mockedSiteData = mock(SiteData.class);
    when(mockedSiteDataService.getSite(siteId.toLowerCase())).thenReturn(mockedSiteData);
    RestPaginationModel mockedPagination = mock(RestPaginationModel.class);
    when(mockedPagination.isHasMoreItems()).thenReturn(false);
    RestNodeModelsCollection mockedCollection = mock(RestNodeModelsCollection.class);
    when(mockedCollection.getPagination()).thenReturn(mockedPagination);
    Node mockedNode = mock(Node.class);
    when(mockedNode.listChildren()).thenReturn(mockedCollection);
    RestCoreAPI mockedRestCoreAPIWithParams = mock(RestCoreAPI.class);
    when(mockedRestCoreAPIWithParams.usingNode(any(RepoTestModel.class))).thenReturn(mockedNode);
    RestWrapper mockedRestWrapperWithParams = mock(RestWrapper.class);
    when(mockedRestWrapperWithParams.withCoreAPI()).thenReturn(mockedRestCoreAPIWithParams);
    when(mockedRestWrapper.withParams(any(String.class), any(String.class), any(String.class))).thenReturn(mockedRestWrapperWithParams);
    // for creating files
    NodeDetail mockedTargetNodeDetail = mock(NodeDetail.class);
    NodesBuilder mockedNodeBuilder = mock(NodesBuilder.class);
    when(mockedNodeBuilder.folder("AutoGeneratedFiles")).thenReturn(mockedTargetNodeDetail);
    when(mockedNode.defineNodes()).thenReturn(mockedNodeBuilder);
    when(mockedRestCoreAPI.usingNode(any(RepoTestModel.class))).thenReturn(mockedNode);
    NodeDetail mockedFile = mock(NodeDetail.class);
    String fileID = UUID.randomUUID().toString();
    when(mockedFile.getId()).thenReturn(fileID);
    when(mockedFile.getName()).thenReturn("fileName");
    when(mockedTargetNodeDetail.file("recordToBe")).thenReturn(mockedFile);
    EventResult result = scheduleInPlaceRecordLoaders.processEvent(null, new StopWatch());
    verify(mockedSite, never()).createSite();
    verify(mockedSiteDataService, never()).addSite(any(SiteData.class));
    assertEquals(true, result.isSuccess());
    String template = "Preparing files to declare: \nCreated file {0}.Sheduled file to be declared as record: {1}. Raised further {2} events and rescheduled self.";
    assertEquals(MessageFormat.format(template, fileID, fileID, 1), result.getData());
    assertEquals(2, result.getNextEvents().size());
    assertEquals(scheduleInPlaceRecordLoaders.getEventNameDeclareInPlaceRecord(), result.getNextEvents().get(0).getName());
    assertEquals(scheduleInPlaceRecordLoaders.getEventNameRescheduleSelf(), result.getNextEvents().get(1).getName());
}
Also used : Site(org.alfresco.rest.requests.Site) SiteData(org.alfresco.bm.site.SiteData) RestCoreAPI(org.alfresco.rest.requests.coreAPI.RestCoreAPI) Node(org.alfresco.rest.requests.Node) RepoTestModel(org.alfresco.utility.model.RepoTestModel) RestWrapper(org.alfresco.rest.core.RestWrapper) RestNodeModelsCollection(org.alfresco.rest.model.RestNodeModelsCollection) StopWatch(org.apache.commons.lang3.time.StopWatch) RestPaginationModel(org.alfresco.rest.model.RestPaginationModel) EventResult(org.alfresco.bm.event.EventResult) RestSiteModel(org.alfresco.rest.model.RestSiteModel) NodeDetail(org.alfresco.rest.model.builder.NodesBuilder.NodeDetail) NodesBuilder(org.alfresco.rest.model.builder.NodesBuilder) RestSiteContainerModel(org.alfresco.rest.model.RestSiteContainerModel) Test(org.junit.Test)

Example 10 with RestNodeModelsCollection

use of org.alfresco.rest.model.RestNodeModelsCollection 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

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