Search in sources :

Example 1 with UnfiledContainerChild

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

the class LoadUnfiledRecordUnitTest method testLoadUnfiledRecordOperationInUnfiledRecordContainer.

@Test
public void testLoadUnfiledRecordOperationInUnfiledRecordContainer() throws Exception {
    loadSingleComponent.setEventNameComplete(EVENT_UNFILED_RECORD_LOADED);
    loadSingleComponent.setDelay(1L);
    Event mockedEvent = mock(Event.class);
    DBObject mockedData = mock(DBObject.class);
    when(mockedData.get(FIELD_CONTEXT)).thenReturn("someContext");
    when(mockedData.get(FIELD_PATH)).thenReturn("/aPath");
    when(mockedData.get(FIELD_LOAD_OPERATION)).thenReturn(LOAD_UNFILED_RECORD_OPERATION);
    when(mockedEvent.getData()).thenReturn(mockedData);
    FolderData mockedFolder = mock(FolderData.class);
    when(mockedFolder.getId()).thenReturn("folderId");
    when(mockedFolder.getPath()).thenReturn("/aPath");
    when(mockedFolder.getContext()).thenReturn("someContext");
    when(mockedFileFolderService.getFolder("someContext", "/aPath")).thenReturn(mockedFolder);
    when(mockedEvent.getSessionId()).thenReturn("someId");
    when(mockedRestApiFactory.getUnfiledContainersAPI(any(UserModel.class))).thenReturn(mockedUnfiledContainerAPI);
    when(mockedRestApiFactory.getUnfiledRecordFoldersAPI(any(UserModel.class))).thenReturn(mockedUnfiledRecordFolderAPI);
    when(mockedFileFolderService.getFolder(UNFILED_CONTEXT, UNFILED_RECORD_CONTAINER_PATH)).thenReturn(mockedFolder);
    UnfiledContainer mockedFilePlanComponent = mock(UnfiledContainer.class);
    when(mockedFilePlanComponent.getId()).thenReturn("folderId");
    when(mockedUnfiledContainerAPI.getUnfiledContainer("folderId")).thenReturn(mockedFilePlanComponent);
    UnfiledContainerChild mockRecord1 = mock(UnfiledContainerChild.class);
    String recordId1 = "recordId1";
    String recordName1 = "recordName1";
    when(mockRecord1.getId()).thenReturn(recordId1);
    when(mockRecord1.getName()).thenReturn(recordName1);
    when(mockedUnfiledContainerAPI.uploadRecord(any(UnfiledContainerChild.class), eq("folderId"), any(File.class))).thenReturn(mockRecord1).thenReturn(null);
    File mockedFile = mock(File.class);
    when(mockedTestFileService.getFile()).thenReturn(mockedFile);
    mockSiteAndUserData();
    EventResult result = loadSingleComponent.processEvent(mockedEvent, new StopWatch());
    verify(mockedTestFileService, times(1)).getFile();
    verify(mockedUnfiledContainerAPI, times(1)).uploadRecord(any(UnfiledContainerChild.class), eq("folderId"), any(File.class));
    verify(mockedFileFolderService, times(1)).incrementFileCount(any(String.class), any(String.class), any(Long.class));
    assertEquals(true, result.isSuccess());
    DBObject data = (DBObject) result.getData();
    assertEquals("Created 1 record.", data.get("msg"));
    assertEquals("/aPath", data.get(FIELD_PATH));
    assertEquals("aUser", data.get("username"));
    assertEquals(1, result.getNextEvents().size());
    Event event = result.getNextEvents().get(0);
    assertEquals(EVENT_UNFILED_RECORD_LOADED, event.getName());
    DBObject eventData = (DBObject) event.getData();
    assertEquals("someContext", eventData.get(FIELD_CONTEXT));
    assertEquals("/aPath", eventData.get(FIELD_PATH));
}
Also used : UserModel(org.alfresco.utility.model.UserModel) 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) File(java.io.File) StopWatch(org.apache.commons.lang3.time.StopWatch) LoadSingleComponentUnitTest(org.alfresco.bm.dataload.LoadSingleComponentUnitTest) Test(org.junit.Test)

Example 2 with UnfiledContainerChild

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

the class LoadRootUnfiledRecordFolderUnitTest method testLoadRootUnfiledRecordFolderOperation.

@Test
public void testLoadRootUnfiledRecordFolderOperation() throws Exception {
    loadSingleComponent.setEventNameComplete(EVENT_ROOT_UNFILED_RECORD_FOLDER_LOADED);
    Event mockedEvent = mock(Event.class);
    DBObject mockedData = mock(DBObject.class);
    when(mockedData.get(FIELD_CONTEXT)).thenReturn("someContext");
    when(mockedData.get(FIELD_PATH)).thenReturn("/aPath");
    when(mockedData.get(FIELD_LOAD_OPERATION)).thenReturn(LOAD_ROOT_UNFILED_RECORD_FOLDER_OPERATION);
    when(mockedEvent.getData()).thenReturn(mockedData);
    FolderData mockedFolder = mock(FolderData.class);
    when(mockedFolder.getId()).thenReturn("folderId");
    when(mockedFolder.getPath()).thenReturn("/aPath");
    when(mockedFileFolderService.getFolder("someContext", "/aPath")).thenReturn(mockedFolder);
    when(mockedEvent.getSessionId()).thenReturn("someId");
    when(mockedRestApiFactory.getUnfiledContainersAPI(any(UserModel.class))).thenReturn(mockedUnfiledContainerAPI);
    UnfiledContainerChild mockedChildFilePlanComponent = mock(UnfiledContainerChild.class);
    when(mockedChildFilePlanComponent.getId()).thenReturn(UUID.randomUUID().toString());
    when(mockedUnfiledContainerAPI.createUnfiledContainerChild(any(UnfiledContainerChild.class), eq("folderId"))).thenReturn(mockedChildFilePlanComponent);
    mockSiteAndUserData();
    EventResult result = loadSingleComponent.processEvent(mockedEvent, new StopWatch());
    verify(mockedFileFolderService, times(1)).createNewFolder(any(String.class), any(String.class), any(String.class));
    verify(mockedFileFolderService, times(1)).incrementFolderCount(any(String.class), any(String.class), any(Long.class));
    assertEquals(true, result.isSuccess());
    DBObject data = (DBObject) result.getData();
    assertEquals("Created 1 root unfiled record folder.", data.get("msg"));
    assertEquals("/aPath", data.get(FIELD_PATH));
    assertEquals("aUser", data.get("username"));
    assertEquals(1, result.getNextEvents().size());
    Event event = result.getNextEvents().get(0);
    assertEquals(EVENT_ROOT_UNFILED_RECORD_FOLDER_LOADED, event.getName());
}
Also used : UserModel(org.alfresco.utility.model.UserModel) 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) LoadSingleComponentUnitTest(org.alfresco.bm.dataload.LoadSingleComponentUnitTest) Test(org.junit.Test)

Example 3 with UnfiledContainerChild

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

the class RMBaseEventProcessor method uploadElectronicRecordInUnfiledContext.

/**
 * Helper method for uploading one record on specified unfiled container or unfiled record folder.
 *
 * @param folder - unfiled container or unfiled record folder that will contain uploaded records
 * @param userModel - UserModel instance with wich rest api will be called
 * @param nameIdentifier - a string identifier that the uploaded records will start with
 * @param loadFilePlanComponentDelay - delay between upload record operations
 * @throws Exception
 */
public void uploadElectronicRecordInUnfiledContext(FolderData folder, UserModel userModel, String nameIdentifier, // to-check: type of exception
long loadFilePlanComponentDelay) throws // to-check: type of exception
Exception {
    String unique;
    boolean isUnfiledContainer = fileFolderService.getFolder(UNFILED_CONTEXT, UNFILED_RECORD_CONTAINER_PATH).equals(folder);
    String folderPath = folder.getPath();
    File file = testFileService.getFile();
    if (file == null) {
        throw new RuntimeException("No test files exist for upload: " + testFileService);
    }
    unique = UUID.randomUUID().toString();
    String newfilePlanComponentName = nameIdentifier + unique + "-" + file.getName();
    String newfilePlanComponentTitle = "title: " + newfilePlanComponentName;
    // Build record properties
    UnfiledContainerChild unfiledContainerChildModel = UnfiledContainerChild.builder().name(newfilePlanComponentName).nodeType(CONTENT_TYPE).properties(UnfiledContainerChildProperties.builder().title(newfilePlanComponentTitle).description(EMPTY).build()).build();
    String newRecordId;
    String newRecordName;
    if (isUnfiledContainer) {
        UnfiledContainerAPI unfiledContainersAPI = getRestAPIFactory().getUnfiledContainersAPI(userModel);
        UnfiledContainerChild uploadedRecord = unfiledContainersAPI.uploadRecord(unfiledContainerChildModel, folder.getId(), file);
        newRecordId = uploadedRecord.getId();
        newRecordName = uploadedRecord.getName();
    } else {
        UnfiledRecordFolderAPI unfiledRecordFoldersAPI = getRestAPIFactory().getUnfiledRecordFoldersAPI(userModel);
        UnfiledContainerChild uploadedRecord = unfiledRecordFoldersAPI.uploadRecord(unfiledContainerChildModel, folder.getId(), file);
        newRecordId = uploadedRecord.getId();
        newRecordName = uploadedRecord.getName();
    }
    RecordData record = new RecordData(newRecordId, RecordContext.RECORD, newRecordName, folderPath, null, ExecutionState.UNFILED_RECORD_DECLARED);
    recordService.createRecord(record);
    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) File(java.io.File) UnfiledContainerAPI(org.alfresco.rest.rm.community.requests.gscore.api.UnfiledContainerAPI)

Example 4 with UnfiledContainerChild

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

the class RMBaseEventProcessor method createUnfiledRecordFolderWithFixedName.

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

Example 5 with UnfiledContainerChild

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

the class ScheduleUnfiledRecordLoadersUnitTest method testUploadRecordsWithNotExistentPreconfiguredPaths.

@Test
public void testUploadRecordsWithNotExistentPreconfiguredPaths() throws Exception {
    int maxActiveLoaders = 3;
    int unfiledRecordsNumber = 4;
    String configuredPath1 = "/e1/e2/e3";
    String configuredPath2 = "/e1/e2/e4";
    String paths = configuredPath1 + "," + configuredPath2;
    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);
    // e4 folder
    UnfiledContainerChild mockedE4FilePlanComponent = mock(UnfiledContainerChild.class);
    when(mockedE4FilePlanComponent.getId()).thenReturn("e4Id");
    String e4Path = UNFILED_RECORD_CONTAINER_PATH + "/e1/e2/e4";
    FolderData mockedE4 = mock(FolderData.class);
    when(mockedE4.getId()).thenReturn("e4Id");
    when(mockedE4.getContext()).thenReturn(UNFILED_CONTEXT);
    when(mockedE4.getPath()).thenReturn(e4Path);
    when(mockedFileFolderService.getFolder(UNFILED_CONTEXT, e4Path)).thenReturn(null).thenReturn(null).thenReturn(mockedE4);
    when(mockedFileFolderService.getFolder("e4Id")).thenReturn(mockedE4);
    when(mockedUnfiledRecorFolderAPI.createUnfiledRecordFolderChild(any(UnfiledContainerChild.class), eq("e2Id"))).thenReturn(mockedE3FilePlanComponent).thenReturn(mockedE4FilePlanComponent);
    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(4)).createNewFolder(any(String.class), any(String.class), any(String.class));
    verify(mockedFileFolderService, times(4)).incrementFolderCount(any(String.class), any(String.class), eq(1L));
    verify(mockedFileFolderService, times(4)).getFolder(any(String.class));
    verify(mockedSessionService, times(3)).startSession(any(DBObject.class));
    assertEquals(true, result.isSuccess());
    assertEquals("Raised further " + (maxActiveLoaders) + " events and rescheduled self.", result.getData());
    assertEquals(maxActiveLoaders + 1, result.getNextEvents().size());
    for (int i = 0; i < maxActiveLoaders; 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(LOAD_UNFILED_RECORD_OPERATION, dataObj.get(FIELD_LOAD_OPERATION));
    }
    assertEquals(EVENT_SCHEDULE_UNFILED_RECORD_LOADERS, result.getNextEvents().get(maxActiveLoaders).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)

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