Search in sources :

Example 36 with FolderData

use of org.alfresco.bm.cm.FolderData in project records-management by Alfresco.

the class LoadRecordUnitTest method testLoadRecordOperationWithRestAPiException.

@Test
public void testLoadRecordOperationWithRestAPiException() throws Exception {
    loadSingleComponent.setEventNameComplete("recordLoaded");
    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_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.getRecordFolderAPI(any(UserModel.class))).thenReturn(mockedRecordFolderAPI);
    RecordFolder mockedFilePlanComponent = mock(RecordFolder.class);
    when(mockedRecordFolderAPI.getRecordFolder("folderId")).thenReturn(mockedFilePlanComponent);
    File mockedFile = mock(File.class);
    when(mockedTestFileService.getFile()).thenReturn(mockedFile);
    Mockito.doThrow(new Exception("someError")).when(mockedRecordFolderAPI).createRecord(any(Record.class), any(String.class), any(File.class));
    mockSiteAndUserData();
    EventResult result = loadSingleComponent.processEvent(mockedEvent, new StopWatch());
    verify(mockedTestFileService, times(1)).getFile();
    verify(mockedRecordFolderAPI, times(1)).createRecord(any(Record.class), eq("folderId"), any(File.class));
    verify(mockedFileFolderService, never()).incrementFileCount(any(String.class), any(String.class), any(Long.class));
    assertEquals(false, result.isSuccess());
    DBObject data = (DBObject) result.getData();
    assertNotNull(data.get("error"));
    assertEquals("someError", data.get("error"));
    assertEquals("aUser", data.get("username"));
    assertEquals(mockedFolder.getPath(), data.get("path"));
    assertNotNull(data.get("stack"));
    assertEquals(0, result.getNextEvents().size());
}
Also used : UserModel(org.alfresco.utility.model.UserModel) EventResult(org.alfresco.bm.event.EventResult) RecordFolder(org.alfresco.rest.rm.community.model.recordfolder.RecordFolder) FolderData(org.alfresco.bm.cm.FolderData) Event(org.alfresco.bm.event.Event) Record(org.alfresco.rest.rm.community.model.record.Record) 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 37 with FolderData

use of org.alfresco.bm.cm.FolderData 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 38 with FolderData

use of org.alfresco.bm.cm.FolderData in project records-management by Alfresco.

the class RMBaseEventProcessorUnitTest method testDistributeNumberOfRecords.

@Test
public void testDistributeNumberOfRecords() throws Exception {
    Random random = new Random();
    int k = random.nextInt(10) + 1;
    List<FolderData> listOfFolders = new ArrayList<FolderData>();
    int sum = 0;
    for (int i = 0; i < k; i++) {
        int filesCount = random.nextInt(5) + 1;
        FolderData mockedFolder = mock(FolderData.class);
        when(mockedFolder.getFileCount()).thenReturn(Long.valueOf(filesCount));
        listOfFolders.add(mockedFolder);
        sum += filesCount;
    }
    int numberOfRecords = random.nextInt(100) + 1;
    HashMap<FolderData, Integer> distributeNumberOfRecords = testRMBaseEventProcessor.distributeNumberOfRecords(listOfFolders, numberOfRecords);
    int expectedSum = sum + numberOfRecords;
    int actualSum = 0;
    Collection<Integer> values = distributeNumberOfRecords.values();
    for (Integer value : values) {
        actualSum += value;
    }
    assertEquals(expectedSum, actualSum);
}
Also used : Random(java.util.Random) FolderData(org.alfresco.bm.cm.FolderData) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 39 with FolderData

use of org.alfresco.bm.cm.FolderData in project records-management by Alfresco.

the class RMAbstractLoadComponent method processEvent.

@Override
protected EventResult processEvent(Event event) throws Exception {
    super.suspendTimer();
    if (event == null) {
        throw new IllegalStateException("This processor requires an event.");
    }
    DBObject dataObj = (DBObject) event.getData();
    if (dataObj == null) {
        throw new IllegalStateException("This processor requires data with field " + FIELD_PATH);
    }
    String context = (String) dataObj.get(FIELD_CONTEXT);
    String path = (String) dataObj.get(FIELD_PATH);
    String operation = (String) dataObj.get(FIELD_LOAD_OPERATION);
    if (context == null || path == null || isBlank(operation)) {
        return new EventResult("Request data not complete for filing unfiled record: " + dataObj, false);
    }
    // Get the folder
    FolderData folder = fileFolderService.getFolder(context, path);
    if (folder == null) {
        throw new IllegalStateException("No such folder recorded: " + dataObj);
    }
    // Get the session
    String sessionId = event.getSessionId();
    if (sessionId == null) {
        return new EventResult("Load scheduling should create a session for each loader.", false);
    }
    switch(operation) {
        case FILE_RECORD_OPERATION:
        case LOAD_UNFILED_RECORD_OPERATION:
        case LOAD_RECORD_OPERATION:
        case LOAD_ROOT_CATEGORY_OPERATION:
        case LOAD_SUB_CATEGORY_OPERATION:
        case LOAD_RECORD_FOLDER_OPERATION:
        case LOAD_ROOT_UNFILED_RECORD_FOLDER_OPERATION:
        case LOAD_UNFILED_RECORD_FOLDER_OPERATION:
            return loadOperation(folder, dataObj, operation);
        default:
            throw new IllegalStateException("Unsuported operation: " + operation);
    }
}
Also used : EventResult(org.alfresco.bm.event.EventResult) FolderData(org.alfresco.bm.cm.FolderData) DBObject(com.mongodb.DBObject)

Example 40 with FolderData

use of org.alfresco.bm.cm.FolderData in project records-management by Alfresco.

the class RMBaseEventProcessor method createRecordCategoryWithFixedName.

/**
 * Helper method for creating a child record category with a specified name.
 *
 * @param folder - container that will contain created child record category
 * @param name - the name that created child record category will have
 * @return created child record category with a specified name
 * @throws Exception
 */
public FolderData createRecordCategoryWithFixedName(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_CATEGORY_TYPE).properties(RecordCategoryChildProperties.builder().title(newfilePlanComponentTitle).description(EMPTY).build()).build();
    RecordCategoryAPI recordCategoryAPI = getRestAPIFactory().getRecordCategoryAPI();
    RecordCategoryChild recordCategoryChild = recordCategoryAPI.createRecordCategoryChild(recordCategoryChildModel, folder.getId());
    String newRecordCategoryChildId = recordCategoryChild.getId();
    fileFolderService.createNewFolder(newRecordCategoryChildId, RECORD_CATEGORY_CONTEXT, folderPath + "/" + name);
    // Increment counts
    fileFolderService.incrementFolderCount(folder.getContext(), folderPath, 1);
    createdFolder = fileFolderService.getFolder(newRecordCategoryChildId);
    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

FolderData (org.alfresco.bm.cm.FolderData)94 DBObject (com.mongodb.DBObject)76 Event (org.alfresco.bm.event.Event)70 Test (org.junit.Test)69 EventResult (org.alfresco.bm.event.EventResult)68 StopWatch (org.apache.commons.lang3.time.StopWatch)68 LoadSingleComponentUnitTest (org.alfresco.bm.dataload.LoadSingleComponentUnitTest)23 UserModel (org.alfresco.utility.model.UserModel)21 UnfiledContainerChild (org.alfresco.rest.rm.community.model.unfiledcontainer.UnfiledContainerChild)14 RecordData (org.alfresco.bm.dataload.rm.services.RecordData)10 File (java.io.File)9 RecordCategoryChild (org.alfresco.rest.rm.community.model.recordcategory.RecordCategoryChild)8 ArrayList (java.util.ArrayList)7 RecordCategory (org.alfresco.rest.rm.community.model.recordcategory.RecordCategory)7 UnfiledContainer (org.alfresco.rest.rm.community.model.unfiledcontainer.UnfiledContainer)7 LinkedHashSet (java.util.LinkedHashSet)5 FilePlan (org.alfresco.rest.rm.community.model.fileplan.FilePlan)5 Record (org.alfresco.rest.rm.community.model.record.Record)4 RecordFolder (org.alfresco.rest.rm.community.model.recordfolder.RecordFolder)3 RecordCategoryAPI (org.alfresco.rest.rm.community.requests.gscore.api.RecordCategoryAPI)2