Search in sources :

Example 26 with RecordData

use of org.alfresco.bm.dataload.rm.services.RecordData in project records-management by Alfresco.

the class RecordServiceTest method testAllowDuplicateState.

@Test
public void testAllowDuplicateState() {
    RecordData record1 = new RecordData("test_id_1", RecordContext.IN_PLACE_RECORD, "test_name_1", "test_parentPath_1", "test_inPlacePath_1", ExecutionState.SCHEDULED);
    recordService.createRecord(record1);
    RecordData record2 = new RecordData("test_id_2", RecordContext.RECORD, "test_name_2", "test_parentPath_2", "test_inPlacePath_2", ExecutionState.SCHEDULED);
    recordService.createRecord(record2);
    doubleCheckOverwrittenMethods_notEqual(record1, record2);
}
Also used : RecordData(org.alfresco.bm.dataload.rm.services.RecordData) Test(org.junit.Test)

Example 27 with RecordData

use of org.alfresco.bm.dataload.rm.services.RecordData in project records-management by Alfresco.

the class RecordServiceTest method testRejectDuplicateRecordId.

@Test(expected = DuplicateRecordException.class)
public void testRejectDuplicateRecordId() {
    String duplicateId = "test_id";
    RecordData record1 = new RecordData(duplicateId, RecordContext.IN_PLACE_RECORD, "test_name_1", "test_parentPath_1", "test_inPlacePath_1", ExecutionState.SCHEDULED);
    recordService.createRecord(record1);
    RecordData record2 = new RecordData(duplicateId, RecordContext.RECORD, "test_name_2", "test_parentPath_2", "test_inPlacePath_2", ExecutionState.UNFILED_RECORD_DECLARED);
    recordService.createRecord(record2);
    doubleCheckOverwrittenMethods_notEqual(record1, record2);
}
Also used : RecordData(org.alfresco.bm.dataload.rm.services.RecordData) Test(org.junit.Test)

Example 28 with RecordData

use of org.alfresco.bm.dataload.rm.services.RecordData in project records-management by Alfresco.

the class ScheduleInPlaceRecordLoaders method preloadExistingFiles.

/**
 * Helper method that iterates the hierarchy tree starting from a folder and caches the file ids
 * If the path doesn't exist nothing happens
 *
 * @param currentNodeId
 * @param relativePath
 * @param eventOutputMsg
 * @throws Exception
 */
private void preloadExistingFiles(String currentNodeId, String relativePath, StringBuilder eventOutputMsg) throws Exception {
    boolean moreChildren;
    int skipCount = 0;
    do {
        ContentModel currentNodeModel = new ContentModel();
        currentNodeModel.setNodeRef(currentNodeId);
        RestNodeModelsCollection children = restCoreAPI.withParams("where=(isPrimary=true)", "relativePath=" + relativePath, "skipCount=" + skipCount).withCoreAPI().usingNode(currentNodeModel).listChildren();
        if (Integer.parseInt(restCoreAPI.getStatusCode()) == HttpStatus.SC_NOT_FOUND) {
            return;
        }
        for (RestNodeModel child : children.getEntries()) {
            if (numberOfFilesLeftToPreload() <= 0) {
                // we have enough files
                return;
            }
            if (child.onModel().getIsFile()) {
                RecordData record = new RecordData(child.onModel().getId(), RecordContext.IN_PLACE_RECORD, child.onModel().getName(), null, null, ExecutionState.SCHEDULED);
                unscheduledFilesCache.add(record);
            } else if (!fullLoadedFolders.contains(child.onModel().getId())) {
                preloadExistingFiles(child.onModel().getId(), "", eventOutputMsg);
            }
        }
        moreChildren = children.getPagination().isHasMoreItems();
        skipCount += children.getPagination().getCount();
    } while (moreChildren);
    // mark the folder as complete to avoid listing its children in a following iteration
    fullLoadedFolders.add(currentNodeId);
}
Also used : ContentModel(org.alfresco.utility.model.ContentModel) RecordData(org.alfresco.bm.dataload.rm.services.RecordData) RestNodeModel(org.alfresco.rest.model.RestNodeModel) RestNodeModelsCollection(org.alfresco.rest.model.RestNodeModelsCollection)

Example 29 with RecordData

use of org.alfresco.bm.dataload.rm.services.RecordData in project records-management by Alfresco.

the class LoadSingleComponent method fileRecordOperation.

/**
 * Helper method to file the unfiled record with specified id in specified record folder.
 *
 * @param folder - the record folded to file unfiled record in
 * @param recordId - the id of the unfiled record to be filed
 * @param userModel - the user model with which the unfiled record will be filed
 * @return String - the filing message
 * @throws Exception
 */
private String fileRecordOperation(FolderData folder, String recordId, UserModel userModel) throws Exception {
    // FileRecords records
    String folderPath = folder.getPath();
    String parentId = folder.getId();
    RecordBodyFile recordBodyFileModel = RecordBodyFile.builder().targetParentId(parentId).build();
    RecordData randomRecord = recordService.getRecord(recordId);
    super.resumeTimer();
    RecordsAPI recordsAPI = getRestAPIFactory().getRecordsAPI(userModel);
    recordsAPI.fileRecord(recordBodyFileModel, randomRecord.getId());
    super.suspendTimer();
    // Increment counts
    fileFolderService.incrementFileCount(folder.getContext(), folderPath, 1);
    // Decrement counts for unfiled record folder or unfiled container
    String unfiledParentPath = randomRecord.getParentPath();
    fileFolderService.incrementFileCount(UNFILED_CONTEXT, unfiledParentPath, -1);
    // change parent path to the new parent
    randomRecord.setParentPath(folderPath);
    randomRecord.setExecutionState(ExecutionState.RECORD_FILED);
    recordService.updateRecord(randomRecord);
    TimeUnit.MILLISECONDS.sleep(getDelay());
    return "Filed record with id " + recordId + ".";
}
Also used : RecordData(org.alfresco.bm.dataload.rm.services.RecordData) RecordsAPI(org.alfresco.rest.rm.community.requests.gscore.api.RecordsAPI) RecordBodyFile(org.alfresco.rest.rm.community.model.record.RecordBodyFile)

Example 30 with RecordData

use of org.alfresco.bm.dataload.rm.services.RecordData 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

RecordData (org.alfresco.bm.dataload.rm.services.RecordData)31 Test (org.junit.Test)22 Event (org.alfresco.bm.event.Event)15 DBObject (com.mongodb.DBObject)14 EventResult (org.alfresco.bm.event.EventResult)14 StopWatch (org.apache.commons.lang3.time.StopWatch)12 FolderData (org.alfresco.bm.cm.FolderData)10 UserModel (org.alfresco.utility.model.UserModel)6 FilesAPI (org.alfresco.rest.rm.community.requests.gscore.api.FilesAPI)4 UnfiledContainerAPI (org.alfresco.rest.rm.community.requests.gscore.api.UnfiledContainerAPI)4 RMRestWrapper (org.alfresco.rest.core.RMRestWrapper)3 Record (org.alfresco.rest.rm.community.model.record.Record)3 ArrayList (java.util.ArrayList)2 Random (java.util.Random)2 LoadSingleComponentUnitTest (org.alfresco.bm.dataload.LoadSingleComponentUnitTest)2 RecordBodyFile (org.alfresco.rest.rm.community.model.record.RecordBodyFile)2 UnfiledContainer (org.alfresco.rest.rm.community.model.unfiledcontainer.UnfiledContainer)2 UnfiledContainerChild (org.alfresco.rest.rm.community.model.unfiledcontainer.UnfiledContainerChild)2 UnfiledRecordFolderAPI (org.alfresco.rest.rm.community.requests.gscore.api.UnfiledRecordFolderAPI)2 ContentModel (org.alfresco.utility.model.ContentModel)2