Search in sources :

Example 6 with RecordCategoryChild

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

the class RMBaseEventProcessor method createSubCategory.

/**
 * Helper method for creating one sub-category with the name starting with provided nameIdentifier and a random generated string.
 *
 * @param folder - container that will contain created sub-category
 * @param userModel - UserModel instance with wich rest api will be called
 * @param nameIdentifier - a string identifier that the created sub-category will start with
 * @param context - the context for created sub-category
 * @param loadFilePlanComponentDelay - delay between creation of sub-categories
 * @throws Exception
 */
public void createSubCategory(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 child record category properties
    RecordCategoryChild recordCategoryChildModel = RecordCategoryChild.builder().name(newfilePlanComponentName).nodeType(RECORD_CATEGORY_TYPE).properties(RecordCategoryChildProperties.builder().title(newfilePlanComponentTitle).description(EMPTY).build()).build();
    RecordCategoryAPI recordCategoryAPI = getRestAPIFactory().getRecordCategoryAPI(userModel);
    RecordCategoryChild childRecordCategory = recordCategoryAPI.createRecordCategoryChild(recordCategoryChildModel, folder.getId());
    String newChildRecordCategoryId = childRecordCategory.getId();
    fileFolderService.createNewFolder(newChildRecordCategoryId, context, folderPath + "/" + newfilePlanComponentName);
    TimeUnit.MILLISECONDS.sleep(loadFilePlanComponentDelay);
    // Increment counts
    fileFolderService.incrementFolderCount(folder.getContext(), folderPath, 1);
}
Also used : RecordCategoryAPI(org.alfresco.rest.rm.community.requests.gscore.api.RecordCategoryAPI) RecordCategoryChild(org.alfresco.rest.rm.community.model.recordcategory.RecordCategoryChild)

Example 7 with RecordCategoryChild

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

the class ScheduleRecordLoadersUnitTest method testUploadRecordsWithNotExistentPreconfiguredSinglePath.

@Test
public void testUploadRecordsWithNotExistentPreconfiguredSinglePath() throws Exception {
    int maxActiveLoaders = 8;
    int recordsNumber = 4;
    String configuredPath1 = "/e1/e2/e3";
    String paths = configuredPath1;
    scheduleRecordLoaders.setUploadRecords(true);
    scheduleRecordLoaders.setMaxActiveLoaders(maxActiveLoaders);
    scheduleRecordLoaders.setRecordsNumber(recordsNumber);
    scheduleRecordLoaders.setRecordFolderPaths(paths);
    // file plan should be always there
    FolderData mockedFilePlanContainer = mock(FolderData.class);
    when(mockedFilePlanContainer.getId()).thenReturn("filePlanId");
    when(mockedFilePlanContainer.getContext()).thenReturn(FILEPLAN_CONTEXT);
    when(mockedFilePlanContainer.getPath()).thenReturn(RECORD_CONTAINER_PATH);
    when(mockedFileFolderService.getFolder(FILEPLAN_CONTEXT, RECORD_CONTAINER_PATH)).thenReturn(mockedFilePlanContainer);
    when(mockedRestApiFactory.getFilePlansAPI()).thenReturn(mockedFilePlanAPI);
    when(mockedRestApiFactory.getRecordCategoryAPI()).thenReturn(mockedRecordCategoryAPI);
    FilePlan mockedFilePlan = mock(FilePlan.class);
    when(mockedFilePlan.getId()).thenReturn("filePlanId");
    when(mockedFilePlanAPI.getFilePlan("filePlanId")).thenReturn(mockedFilePlan);
    // e1 root category
    RecordCategory mockedE1FilePlanComponent = mock(RecordCategory.class);
    when(mockedE1FilePlanComponent.getId()).thenReturn("e1Id");
    when(mockedRecordCategoryAPI.getRecordCategory("e1Id")).thenReturn(mockedE1FilePlanComponent);
    when(mockedFilePlanAPI.createRootRecordCategory(any(RecordCategory.class), eq("filePlanId"))).thenReturn(mockedE1FilePlanComponent);
    String e1Path = RECORD_CONTAINER_PATH + "/e1";
    FolderData mockedE1 = mock(FolderData.class);
    when(mockedE1.getId()).thenReturn("e1Id");
    when(mockedE1.getContext()).thenReturn(RECORD_CATEGORY_CONTEXT);
    when(mockedE1.getPath()).thenReturn(e1Path);
    when(mockedFileFolderService.getFolder(RECORD_CATEGORY_CONTEXT, e1Path)).thenReturn(null).thenReturn(mockedE1);
    when(mockedFileFolderService.getFolder("e1Id")).thenReturn(mockedE1);
    // e2 child category
    RecordCategory mockedE2childRecordCategory = mock(RecordCategory.class);
    when(mockedE2childRecordCategory.getId()).thenReturn("e2Id");
    RecordCategoryChild mockedE2RecordCategoryChild = mock(RecordCategoryChild.class);
    when(mockedE2RecordCategoryChild.getId()).thenReturn("e2Id");
    when(mockedRecordCategoryAPI.getRecordCategory("e2Id")).thenReturn(mockedE2childRecordCategory);
    when(mockedRecordCategoryAPI.createRecordCategoryChild(any(RecordCategoryChild.class), eq("e1Id"))).thenReturn(mockedE2RecordCategoryChild);
    String e2Path = RECORD_CONTAINER_PATH + "/e1/e2";
    FolderData mockedE2 = mock(FolderData.class);
    when(mockedE2.getId()).thenReturn("e2Id");
    when(mockedE2.getContext()).thenReturn(RECORD_CATEGORY_CONTEXT);
    when(mockedE2.getPath()).thenReturn(e2Path);
    when(mockedFileFolderService.getFolder(RECORD_CATEGORY_CONTEXT, e2Path)).thenReturn(null).thenReturn(mockedE2);
    when(mockedFileFolderService.getFolder("e2Id")).thenReturn(mockedE2);
    // e3 record folder
    RecordCategoryChild mockedE3RecordFolder = mock(RecordCategoryChild.class);
    when(mockedE3RecordFolder.getId()).thenReturn("e3Id");
    String e3Path = RECORD_CONTAINER_PATH + "/e1/e2/e3";
    FolderData mockedE3 = mock(FolderData.class);
    when(mockedE3.getId()).thenReturn("e3Id");
    when(mockedE3.getContext()).thenReturn(RECORD_FOLDER_CONTEXT);
    when(mockedE3.getPath()).thenReturn(e3Path);
    when(mockedFileFolderService.getFolder(RECORD_FOLDER_CONTEXT, e3Path)).thenReturn(null).thenReturn(null).thenReturn(mockedE3);
    when(mockedFileFolderService.getFolder("e3Id")).thenReturn(mockedE3);
    when(mockedRecordCategoryAPI.createRecordCategoryChild(any(RecordCategoryChild.class), eq("e2Id"))).thenReturn(mockedE3RecordFolder);
    when(mockedApplicationContext.getBean("restAPIFactory", RestAPIFactory.class)).thenReturn(mockedRestApiFactory);
    EventResult result = scheduleRecordLoaders.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(recordsNumber)).startSession(any(DBObject.class));
    assertEquals(true, result.isSuccess());
    assertEquals("Raised further " + (recordsNumber) + " events and rescheduled self.", result.getData());
    assertEquals(recordsNumber + 1, result.getNextEvents().size());
    for (int i = 0; i < recordsNumber; i++) {
        Event event = result.getNextEvents().get(i);
        assertEquals(EVENT_LOAD_RECORD, event.getName());
        DBObject dataObj = (DBObject) event.getData();
        assertNotNull(dataObj);
        assertEquals(RECORD_FOLDER_CONTEXT, (String) dataObj.get(FIELD_CONTEXT));
        assertEquals(LOAD_RECORD_OPERATION, dataObj.get(FIELD_LOAD_OPERATION));
    }
    assertEquals(EVENT_SCHEDULE_RECORD_LOADERS, result.getNextEvents().get(recordsNumber).getName());
}
Also used : EventResult(org.alfresco.bm.event.EventResult) FilePlan(org.alfresco.rest.rm.community.model.fileplan.FilePlan) RecordCategoryChild(org.alfresco.rest.rm.community.model.recordcategory.RecordCategoryChild) FolderData(org.alfresco.bm.cm.FolderData) Event(org.alfresco.bm.event.Event) RecordCategory(org.alfresco.rest.rm.community.model.recordcategory.RecordCategory) DBObject(com.mongodb.DBObject) StopWatch(org.apache.commons.lang3.time.StopWatch) Test(org.junit.Test)

Example 8 with RecordCategoryChild

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

the class RMBaseEventProcessor method createRecordFolderWithFixedName.

/**
 * Helper method for creating a child record folder with a specified name.
 *
 * @param folder - container that will contain created child record folder
 * @param name - the name that created child record folder will have
 * @return created child record folder with a specified name
 * @throws Exception
 */
public FolderData createRecordFolderWithFixedName(FolderData folder, String name) throws Exception {
    FolderData createdFolder = null;
    String folderPath = folder.getPath();
    String newfilePlanComponentTitle = "title: " + name;
    // Build filePlan component records folder properties
    RecordCategoryChild recordCategoryChildModel = RecordCategoryChild.builder().name(name).nodeType(RECORD_FOLDER_TYPE).properties(RecordCategoryChildProperties.builder().title(newfilePlanComponentTitle).description(EMPTY).build()).build();
    RecordCategoryAPI recordCategoryAPI = getRestAPIFactory().getRecordCategoryAPI();
    RecordCategoryChild recordFolderChild = recordCategoryAPI.createRecordCategoryChild(recordCategoryChildModel, folder.getId());
    String newRecordFolderChildId = recordFolderChild.getId();
    fileFolderService.createNewFolder(newRecordFolderChildId, RECORD_FOLDER_CONTEXT, folderPath + "/" + name);
    // Increment counts
    fileFolderService.incrementFolderCount(folder.getContext(), folderPath, 1);
    createdFolder = fileFolderService.getFolder(newRecordFolderChildId);
    return createdFolder;
}
Also used : RecordCategoryAPI(org.alfresco.rest.rm.community.requests.gscore.api.RecordCategoryAPI) RecordCategoryChild(org.alfresco.rest.rm.community.model.recordcategory.RecordCategoryChild) FolderData(org.alfresco.bm.cm.FolderData)

Aggregations

RecordCategoryChild (org.alfresco.rest.rm.community.model.recordcategory.RecordCategoryChild)8 FolderData (org.alfresco.bm.cm.FolderData)6 DBObject (com.mongodb.DBObject)4 Event (org.alfresco.bm.event.Event)4 EventResult (org.alfresco.bm.event.EventResult)4 RecordCategory (org.alfresco.rest.rm.community.model.recordcategory.RecordCategory)4 RecordCategoryAPI (org.alfresco.rest.rm.community.requests.gscore.api.RecordCategoryAPI)4 StopWatch (org.apache.commons.lang3.time.StopWatch)4 Test (org.junit.Test)4 LoadSingleComponentUnitTest (org.alfresco.bm.dataload.LoadSingleComponentUnitTest)2 FilePlan (org.alfresco.rest.rm.community.model.fileplan.FilePlan)2 UserModel (org.alfresco.utility.model.UserModel)2