Search in sources :

Example 6 with UnfiledContainerChild

use of org.alfresco.rest.rm.community.model.unfiledcontainer.UnfiledContainerChild in project records-management by Alfresco.

the class ScheduleUnfiledRecordLoadersUnitTest method testUploadRecordsWithNotExistentPreconfiguredSinglePath.

@Test
public void testUploadRecordsWithNotExistentPreconfiguredSinglePath() throws Exception {
    int maxActiveLoaders = 8;
    int unfiledRecordsNumber = 4;
    String configuredPath1 = "/e1/e2/e3";
    String paths = configuredPath1;
    scheduleUnfiledRecordLoaders.setUploadUnfiledRecords(true);
    scheduleUnfiledRecordLoaders.setMaxActiveLoaders(maxActiveLoaders);
    scheduleUnfiledRecordLoaders.setUnfiledRecordsNumber(unfiledRecordsNumber);
    scheduleUnfiledRecordLoaders.setUnfiledRecordFolderPaths(paths);
    // unfiledRecord should be always there
    FolderData mockedUnfiledRecordContainer = mock(FolderData.class);
    when(mockedUnfiledRecordContainer.getId()).thenReturn("unfiledRecordContainerId");
    when(mockedUnfiledRecordContainer.getContext()).thenReturn(UNFILED_CONTEXT);
    when(mockedUnfiledRecordContainer.getPath()).thenReturn(UNFILED_RECORD_CONTAINER_PATH);
    when(mockedFileFolderService.getFolder(UNFILED_CONTEXT, UNFILED_RECORD_CONTAINER_PATH)).thenReturn(mockedUnfiledRecordContainer);
    when(mockedRestApiFactory.getUnfiledContainersAPI()).thenReturn(mockedUnfiledContainerAPI);
    when(mockedRestApiFactory.getUnfiledRecordFoldersAPI()).thenReturn(mockedUnfiledRecorFolderAPI);
    UnfiledContainer mockedUnfiledContainer = mock(UnfiledContainer.class);
    when(mockedUnfiledContainer.getId()).thenReturn("unfiledRecordContainerId");
    when(mockedUnfiledContainerAPI.getUnfiledContainer("unfiledRecordContainerId")).thenReturn(mockedUnfiledContainer);
    // e1 folder
    UnfiledContainerChild mockedE1RootUnfiledRecordFolder = mock(UnfiledContainerChild.class);
    when(mockedE1RootUnfiledRecordFolder.getId()).thenReturn("e1Id");
    when(mockedUnfiledContainerAPI.createUnfiledContainerChild(any(UnfiledContainerChild.class), eq("unfiledRecordContainerId"))).thenReturn(mockedE1RootUnfiledRecordFolder);
    String e1Path = UNFILED_RECORD_CONTAINER_PATH + "/e1";
    FolderData mockedE1 = mock(FolderData.class);
    when(mockedE1.getId()).thenReturn("e1Id");
    when(mockedE1.getContext()).thenReturn(UNFILED_CONTEXT);
    when(mockedE1.getPath()).thenReturn(e1Path);
    when(mockedFileFolderService.getFolder(UNFILED_CONTEXT, e1Path)).thenReturn(null).thenReturn(mockedE1);
    when(mockedFileFolderService.getFolder("e1Id")).thenReturn(mockedE1);
    // e2 folder
    UnfiledContainerChild mockedE2ChildunfiledRecordFolder = mock(UnfiledContainerChild.class);
    when(mockedE2ChildunfiledRecordFolder.getId()).thenReturn("e2Id");
    when(mockedUnfiledRecorFolderAPI.createUnfiledRecordFolderChild(any(UnfiledContainerChild.class), eq("e1Id"))).thenReturn(mockedE2ChildunfiledRecordFolder);
    String e2Path = UNFILED_RECORD_CONTAINER_PATH + "/e1/e2";
    FolderData mockedE2 = mock(FolderData.class);
    when(mockedE2.getId()).thenReturn("e2Id");
    when(mockedE2.getContext()).thenReturn(UNFILED_CONTEXT);
    when(mockedE2.getPath()).thenReturn(e2Path);
    when(mockedFileFolderService.getFolder(UNFILED_CONTEXT, e2Path)).thenReturn(null).thenReturn(mockedE2);
    when(mockedFileFolderService.getFolder("e2Id")).thenReturn(mockedE2);
    // e3 folder
    UnfiledContainerChild mockedE3FilePlanComponent = mock(UnfiledContainerChild.class);
    when(mockedE3FilePlanComponent.getId()).thenReturn("e3Id");
    String e3Path = UNFILED_RECORD_CONTAINER_PATH + "/e1/e2/e3";
    FolderData mockedE3 = mock(FolderData.class);
    when(mockedE3.getId()).thenReturn("e3Id");
    when(mockedE3.getContext()).thenReturn(UNFILED_CONTEXT);
    when(mockedE3.getPath()).thenReturn(e3Path);
    when(mockedFileFolderService.getFolder(UNFILED_CONTEXT, e3Path)).thenReturn(null).thenReturn(null).thenReturn(mockedE3);
    when(mockedFileFolderService.getFolder("e3Id")).thenReturn(mockedE3);
    when(mockedUnfiledRecorFolderAPI.createUnfiledRecordFolderChild(any(UnfiledContainerChild.class), eq("e2Id"))).thenReturn(mockedE3FilePlanComponent);
    when(mockedApplicationContext.getBean("restAPIFactory", RestAPIFactory.class)).thenReturn(mockedRestApiFactory);
    EventResult result = scheduleUnfiledRecordLoaders.processEvent(null, new StopWatch());
    verify(mockedFileFolderService, never()).getFoldersByCounts(any(String.class), any(Long.class), any(Long.class), any(Long.class), any(Long.class), any(Long.class), any(Long.class), any(Integer.class), any(Integer.class));
    verify(mockedFileFolderService, times(3)).createNewFolder(any(String.class), any(String.class), any(String.class));
    verify(mockedFileFolderService, times(3)).incrementFolderCount(any(String.class), any(String.class), eq(1L));
    verify(mockedFileFolderService, times(3)).getFolder(any(String.class));
    verify(mockedSessionService, times(4)).startSession(any(DBObject.class));
    assertEquals(true, result.isSuccess());
    assertEquals("Raised further 4 events and rescheduled self.", result.getData());
    assertEquals(5, result.getNextEvents().size());
    for (int i = 0; i < unfiledRecordsNumber; i++) {
        Event event = result.getNextEvents().get(0);
        assertEquals(EVENT_LOAD_UNFILED_RECORD, event.getName());
        DBObject dataObj = (DBObject) event.getData();
        assertNotNull(dataObj);
        assertEquals(UNFILED_CONTEXT, (String) dataObj.get(FIELD_CONTEXT));
        assertEquals(e3Path, (String) dataObj.get(FIELD_PATH));
        assertEquals(LOAD_UNFILED_RECORD_OPERATION, dataObj.get(FIELD_LOAD_OPERATION));
    }
    assertEquals(EVENT_SCHEDULE_UNFILED_RECORD_LOADERS, result.getNextEvents().get(4).getName());
}
Also used : UnfiledContainer(org.alfresco.rest.rm.community.model.unfiledcontainer.UnfiledContainer) EventResult(org.alfresco.bm.event.EventResult) UnfiledContainerChild(org.alfresco.rest.rm.community.model.unfiledcontainer.UnfiledContainerChild) FolderData(org.alfresco.bm.cm.FolderData) Event(org.alfresco.bm.event.Event) DBObject(com.mongodb.DBObject) StopWatch(org.apache.commons.lang3.time.StopWatch) Test(org.junit.Test)

Example 7 with UnfiledContainerChild

use of org.alfresco.rest.rm.community.model.unfiledcontainer.UnfiledContainerChild in project records-management by Alfresco.

the class RMBaseEventProcessor method createRootUnfiledRecordFolderWithFixedName.

/**
 * Helper method for creating a root unfiled record folder with a specified name.
 *
 * @param folder - container that will contain created root unfiled record folder
 * @param name - the name that created root unfiled record folder will have
 * @return created root unfiled record folder with a specified name
 * @throws Exception
 */
public FolderData createRootUnfiledRecordFolderWithFixedName(FolderData folder, String name) throws Exception {
    FolderData createdFolder = null;
    String folderPath = folder.getPath();
    String newfilePlanComponentTitle = "title: " + name;
    // Build root unfiled record folder properties
    UnfiledContainerChild unfiledContainerChildModel = UnfiledContainerChild.builder().name(name).nodeType(UNFILED_RECORD_FOLDER_TYPE).properties(UnfiledContainerChildProperties.builder().title(newfilePlanComponentTitle).description(EMPTY).build()).build();
    UnfiledContainerAPI unfiledContainersAPI = getRestAPIFactory().getUnfiledContainersAPI();
    UnfiledContainerChild rootUnfiledRecordFolder = unfiledContainersAPI.createUnfiledContainerChild(unfiledContainerChildModel, folder.getId());
    String newRootUnfiledRecordFolderId = rootUnfiledRecordFolder.getId();
    fileFolderService.createNewFolder(newRootUnfiledRecordFolderId, UNFILED_CONTEXT, folderPath + "/" + name);
    // Increment counts
    fileFolderService.incrementFolderCount(folder.getContext(), folderPath, 1);
    createdFolder = fileFolderService.getFolder(newRootUnfiledRecordFolderId);
    return createdFolder;
}
Also used : UnfiledContainerChild(org.alfresco.rest.rm.community.model.unfiledcontainer.UnfiledContainerChild) FolderData(org.alfresco.bm.cm.FolderData) UnfiledContainerAPI(org.alfresco.rest.rm.community.requests.gscore.api.UnfiledContainerAPI)

Example 8 with UnfiledContainerChild

use of org.alfresco.rest.rm.community.model.unfiledcontainer.UnfiledContainerChild in project records-management by Alfresco.

the class RMBaseEventProcessor method createUnfiledRecordFolder.

/**
 * Helper method for creating one unfiled record folder that have the name starting with provided nameIdentifier and a random generated string.
 *
 * @param folder - container that will contain created unfiled record folder
 * @param userModel - UserModel instance with wich rest api will be called
 * @param nameIdentifier - a string identifier that the created unfiled record folder will start with
 * @param context - the context for created unfiled record folder
 * @param loadFilePlanComponentDelay - delay between creation of unfiled record folders
 * @throws Exception
 */
public void createUnfiledRecordFolder(FolderData folder, UserModel userModel, String nameIdentifier, String context, long loadFilePlanComponentDelay) throws Exception {
    String unique;
    String folderPath = folder.getPath();
    unique = UUID.randomUUID().toString();
    String newfilePlanComponentName = nameIdentifier + unique;
    String newfilePlanComponentTitle = "title: " + newfilePlanComponentName;
    // Build unfiled record folder properties
    UnfiledContainerChild unfiledRecordFolderChildModel = UnfiledContainerChild.builder().name(newfilePlanComponentName).nodeType(UNFILED_RECORD_FOLDER_TYPE).properties(UnfiledContainerChildProperties.builder().title(newfilePlanComponentTitle).description(EMPTY).build()).build();
    UnfiledRecordFolderAPI unfiledRecordFoldersAPI = getRestAPIFactory().getUnfiledRecordFoldersAPI(userModel);
    UnfiledContainerChild unfiledRecordFolderChild = unfiledRecordFoldersAPI.createUnfiledRecordFolderChild(unfiledRecordFolderChildModel, folder.getId());
    String newUnfiledRecordFolderChildId = unfiledRecordFolderChild.getId();
    fileFolderService.createNewFolder(newUnfiledRecordFolderChildId, context, folderPath + "/" + newfilePlanComponentName);
    TimeUnit.MILLISECONDS.sleep(loadFilePlanComponentDelay);
    // Increment counts
    fileFolderService.incrementFolderCount(folder.getContext(), folderPath, 1);
}
Also used : UnfiledRecordFolderAPI(org.alfresco.rest.rm.community.requests.gscore.api.UnfiledRecordFolderAPI) UnfiledContainerChild(org.alfresco.rest.rm.community.model.unfiledcontainer.UnfiledContainerChild)

Example 9 with UnfiledContainerChild

use of org.alfresco.rest.rm.community.model.unfiledcontainer.UnfiledContainerChild in project records-management by Alfresco.

the class RMBaseEventProcessor method createRootUnfiledRecordFolder.

/**
 * Helper method for creating one root unfiled record folder with the name starting with provided nameIdentifier and a random generated string.
 *
 * @param folder - container that will contain created root unfiled record folder
 * @param userModel - UserModel instance with wich rest api will be called
 * @param nameIdentifier - a string identifier that the created root unfiled record folder will start with
 * @param context - the context for created root unfiled record folder
 * @param loadFilePlanComponentDelay - delay between creation of root unfiled record folders
 * @throws Exception
 */
public void createRootUnfiledRecordFolder(FolderData folder, UserModel userModel, String nameIdentifier, String context, long loadFilePlanComponentDelay) throws Exception {
    String unique;
    String folderPath = folder.getPath();
    unique = UUID.randomUUID().toString();
    String newfilePlanComponentName = nameIdentifier + unique;
    String newfilePlanComponentTitle = "title: " + newfilePlanComponentName;
    // Build root unfiled records folder properties
    UnfiledContainerChild unfiledContainerChildModel = UnfiledContainerChild.builder().name(newfilePlanComponentName).nodeType(UNFILED_RECORD_FOLDER_TYPE).properties(UnfiledContainerChildProperties.builder().title(newfilePlanComponentTitle).description(EMPTY).build()).build();
    UnfiledContainerAPI unfiledContainersAPI = getRestAPIFactory().getUnfiledContainersAPI(userModel);
    UnfiledContainerChild unfiledContainerChild = unfiledContainersAPI.createUnfiledContainerChild(unfiledContainerChildModel, folder.getId());
    String newUnfiledContainerChildId = unfiledContainerChild.getId();
    fileFolderService.createNewFolder(newUnfiledContainerChildId, context, folderPath + "/" + newfilePlanComponentName);
    TimeUnit.MILLISECONDS.sleep(loadFilePlanComponentDelay);
    // Increment counts
    fileFolderService.incrementFolderCount(folder.getContext(), folderPath, 1);
}
Also used : UnfiledContainerChild(org.alfresco.rest.rm.community.model.unfiledcontainer.UnfiledContainerChild) UnfiledContainerAPI(org.alfresco.rest.rm.community.requests.gscore.api.UnfiledContainerAPI)

Example 10 with UnfiledContainerChild

use of org.alfresco.rest.rm.community.model.unfiledcontainer.UnfiledContainerChild in project records-management by Alfresco.

the class RMBaseEventProcessor method createNonElectonicRecordInUnfiledContext.

/**
 * Helper method for creating specified number of non-electronic documents in specified unfiled container or unfiled record folder.
 *
 * @param folder - unfiled container or unfiled record folder that will contain created non-electronic document
 * @param userModel - UserModel instance with wich rest api will be called
 * @param nameIdentifier - a string identifier that the created non-electronic documents will start with
 * @param loadFilePlanComponentDelay - delay between creation of non-electronic documents
 * @throws Exception
 */
public void createNonElectonicRecordInUnfiledContext(FolderData folder, UserModel userModel, String nameIdentifier, long loadFilePlanComponentDelay) throws Exception {
    String unique;
    boolean isUnfiledContainer = fileFolderService.getFolder(UNFILED_CONTEXT, UNFILED_RECORD_CONTAINER_PATH).equals(folder);
    String folderPath = folder.getPath();
    unique = UUID.randomUUID().toString();
    String newfilePlanComponentName = nameIdentifier + unique;
    String newfilePlanComponentTitle = "title: " + newfilePlanComponentName;
    // Build non electronic record properties
    UnfiledContainerChild unfiledContainerChildModel = UnfiledContainerChild.builder().name(newfilePlanComponentName).nodeType(NON_ELECTRONIC_RECORD_TYPE).properties(UnfiledContainerChildProperties.builder().title(newfilePlanComponentTitle).description(EMPTY).build()).build();
    String newRecordId;
    String newRecordName;
    if (isUnfiledContainer) {
        UnfiledContainerAPI unfiledContainersAPI = getRestAPIFactory().getUnfiledContainersAPI(userModel);
        UnfiledContainerChild createdRecord = unfiledContainersAPI.createUnfiledContainerChild(unfiledContainerChildModel, folder.getId());
        newRecordId = createdRecord.getId();
        newRecordName = createdRecord.getName();
    } else {
        UnfiledRecordFolderAPI unfiledRecordFoldersAPI = getRestAPIFactory().getUnfiledRecordFoldersAPI(userModel);
        UnfiledContainerChild createdRecord = unfiledRecordFoldersAPI.createUnfiledRecordFolderChild(unfiledContainerChildModel, folder.getId());
        newRecordId = createdRecord.getId();
        newRecordName = createdRecord.getName();
    }
    RecordData record = new RecordData(newRecordId, RecordContext.RECORD, newRecordName, folderPath, null, ExecutionState.UNFILED_RECORD_DECLARED);
    recordService.createRecord(record);
    TimeUnit.MILLISECONDS.sleep(loadFilePlanComponentDelay);
    // Increment counts
    fileFolderService.incrementFileCount(folder.getContext(), folderPath, 1);
}
Also used : UnfiledRecordFolderAPI(org.alfresco.rest.rm.community.requests.gscore.api.UnfiledRecordFolderAPI) RecordData(org.alfresco.bm.dataload.rm.services.RecordData) UnfiledContainerChild(org.alfresco.rest.rm.community.model.unfiledcontainer.UnfiledContainerChild) UnfiledContainerAPI(org.alfresco.rest.rm.community.requests.gscore.api.UnfiledContainerAPI)

Aggregations

UnfiledContainerChild (org.alfresco.rest.rm.community.model.unfiledcontainer.UnfiledContainerChild)12 FolderData (org.alfresco.bm.cm.FolderData)8 DBObject (com.mongodb.DBObject)6 Event (org.alfresco.bm.event.Event)6 EventResult (org.alfresco.bm.event.EventResult)6 StopWatch (org.apache.commons.lang3.time.StopWatch)6 Test (org.junit.Test)6 LoadSingleComponentUnitTest (org.alfresco.bm.dataload.LoadSingleComponentUnitTest)4 UnfiledContainerAPI (org.alfresco.rest.rm.community.requests.gscore.api.UnfiledContainerAPI)4 UnfiledRecordFolderAPI (org.alfresco.rest.rm.community.requests.gscore.api.UnfiledRecordFolderAPI)4 UserModel (org.alfresco.utility.model.UserModel)4 File (java.io.File)3 UnfiledContainer (org.alfresco.rest.rm.community.model.unfiledcontainer.UnfiledContainer)3 RecordData (org.alfresco.bm.dataload.rm.services.RecordData)2