Search in sources :

Example 81 with FolderData

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

the class RMBaseEventProcessor method createRootRecordCategoryWithFixedName.

/**
 * Helper method for creating a root record category with a specified name.
 *
 * @param folder - container that will contain created root record category
 * @param name - the name that created root record category will have
 * @return created root record category with a specified name
 * @throws Exception
 */
public FolderData createRootRecordCategoryWithFixedName(FolderData folder, String name) throws Exception {
    FolderData createdFolder = null;
    String folderPath = folder.getPath();
    String newfilePlanComponentTitle = "title: " + name;
    // Build root category properties
    RecordCategory recordCategoryModel = RecordCategory.builder().name(name).nodeType(RECORD_CATEGORY_TYPE).properties(RecordCategoryProperties.builder().title(newfilePlanComponentTitle).description(EMPTY).build()).build();
    FilePlanAPI filePlansAPI = getRestAPIFactory().getFilePlansAPI();
    RecordCategory rootCategory = filePlansAPI.createRootRecordCategory(recordCategoryModel, folder.getId());
    String newRootCategoryId = rootCategory.getId();
    fileFolderService.createNewFolder(newRootCategoryId, RECORD_CATEGORY_CONTEXT, folderPath + "/" + name);
    // Increment counts
    fileFolderService.incrementFolderCount(folder.getContext(), folderPath, 1);
    createdFolder = fileFolderService.getFolder(newRootCategoryId);
    return createdFolder;
}
Also used : FilePlanAPI(org.alfresco.rest.rm.community.requests.gscore.api.FilePlanAPI) FolderData(org.alfresco.bm.cm.FolderData) RecordCategory(org.alfresco.rest.rm.community.model.recordcategory.RecordCategory)

Example 82 with FolderData

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

the class RMBaseEventProcessor method distributeNumberOfRecords.

/**
 * Helper method to distribute the number of records to create on the given list of folders.
 *
 * @param listOfFolders - list of available folders to distribute records into
 * @param numberOfRecords - number of records to be distributed
 * @return a map with folders as keys and the number of records to create on that folder as values.
 */
public LinkedHashMap<FolderData, Integer> distributeNumberOfRecords(List<FolderData> listOfFolders, int numberOfRecords) {
    LinkedHashMap<FolderData, Integer> mapOfRecordsPerFolder = new LinkedHashMap<FolderData, Integer>();
    int[] generateRandomValues = generateRandomValues(listOfFolders.size(), numberOfRecords);
    int counter = 0;
    for (FolderData folder : listOfFolders) {
        int records = (int) (folder.getFileCount() + generateRandomValues[counter]);
        mapOfRecordsPerFolder.put(folder, records);
        counter++;
    }
    return mapOfRecordsPerFolder;
}
Also used : FolderData(org.alfresco.bm.cm.FolderData) LinkedHashMap(java.util.LinkedHashMap)

Example 83 with FolderData

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

the class RMBaseEventProcessor method calculateListOfEmptyFolders.

/**
 * Helper method that initialize the record folders that can receive records.
 * This method, also calculates the number of records to  add to the initialized record folders.
 *
 * @param mapOfRecordsPerRecordFolder - linked hash map with available record folders as keys and calculated number of records to load/file in each record folder
 * @param paths - record category or record folder paths to load/file records in
 * @param numberOrRecords - number of records to load/file
 */
public LinkedHashMap<FolderData, Integer> calculateListOfEmptyFolders(LinkedHashMap<FolderData, Integer> mapOfRecordsPerRecordFolder, List<String> paths, int numberOrRecords) {
    if (mapOfRecordsPerRecordFolder == null) {
        mapOfRecordsPerRecordFolder = new LinkedHashMap<FolderData, Integer>();
        List<FolderData> recordFoldersThatNeedRecords = new ArrayList<FolderData>();
        if (paths == null || paths.isEmpty()) {
            // get the existing file plan folder structure
            recordFoldersThatNeedRecords.addAll(initialiseFoldersToExistingStructure(RECORD_FOLDER_CONTEXT));
        } else {
            LinkedHashSet<FolderData> structureFromExistentProvidedPaths = new LinkedHashSet<FolderData>();
            for (String path : paths) {
                if (!path.startsWith("/")) {
                    path = "/" + path;
                }
                // if the path is category and exists
                FolderData folder = fileFolderService.getFolder(RECORD_CATEGORY_CONTEXT, RECORD_CONTAINER_PATH + path);
                if (// if folder is not a category verify if it is a record folder and exists
                folder == null) {
                    folder = fileFolderService.getFolder(RECORD_FOLDER_CONTEXT, RECORD_CONTAINER_PATH + path);
                }
                if (// if folder exists
                folder != null) {
                    structureFromExistentProvidedPaths.addAll(getRecordFolders(folder));
                } else {
                    try {
                        folder = createRecordCategoryOrRecordFolder(path);
                        recordFoldersThatNeedRecords.add(folder);
                    } catch (Exception e) {
                        // something went wrong on creating current path structure, not all required paths will be created
                        logger.debug("Path elements of " + path + "could not be created.", e);
                    }
                }
            }
            // add record folders from existent paths
            if (!structureFromExistentProvidedPaths.isEmpty()) {
                recordFoldersThatNeedRecords.addAll(structureFromExistentProvidedPaths);
            }
            // initialize to existing structure in this case
            if (recordFoldersThatNeedRecords.isEmpty()) {
                recordFoldersThatNeedRecords.addAll(initialiseFoldersToExistingStructure(RECORD_FOLDER_CONTEXT));
            }
        }
        if (!recordFoldersThatNeedRecords.isEmpty()) {
            mapOfRecordsPerRecordFolder = distributeNumberOfRecords(recordFoldersThatNeedRecords, numberOrRecords);
        }
    }
    return mapOfRecordsPerRecordFolder;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) FolderData(org.alfresco.bm.cm.FolderData) ArrayList(java.util.ArrayList) BeansException(org.springframework.beans.BeansException)

Example 84 with FolderData

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

Example 85 with FolderData

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

the class LoadUnfiledRecordUnitTest method testLoadUnfiledRecordOperationInUnfiledRecordFolder.

@Test
public void testLoadUnfiledRecordOperationInUnfiledRecordFolder() 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);
    FolderData mockedFolder1 = mock(FolderData.class);
    when(mockedFileFolderService.getFolder(UNFILED_CONTEXT, UNFILED_RECORD_CONTAINER_PATH)).thenReturn(mockedFolder1);
    UnfiledContainerChild mockRecord1 = mock(UnfiledContainerChild.class);
    String recordId1 = "recordId1";
    String recordName1 = "recordName1";
    when(mockRecord1.getId()).thenReturn(recordId1);
    when(mockRecord1.getName()).thenReturn(recordName1);
    when(mockedUnfiledRecordFolderAPI.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(mockedUnfiledRecordFolderAPI, 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) 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)

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