Search in sources :

Example 46 with MetadataImportParams

use of org.hisp.dhis.dxf2.metadata.MetadataImportParams in project dhis2-core by dhis2.

the class MetadataSyncJob method handleMetadataSync.

// ----------------------------------------------------------------------------------------
// Private Methods
// ----------------------------------------------------------------------------------------
private MetadataSyncSummary handleMetadataSync(MetadataRetryContext context, MetadataVersion dataVersion) throws DhisVersionMismatchException {
    MetadataSyncParams syncParams = new MetadataSyncParams(new MetadataImportParams(), dataVersion);
    MetadataSyncSummary metadataSyncSummary = null;
    try {
        metadataSyncSummary = metadataSyncService.doMetadataSync(syncParams);
    } catch (MetadataSyncServiceException e) {
        log.error("Exception happened  while trying to do metadata sync  " + e.getMessage(), e);
        context.updateRetryContext(METADATA_SYNC, e.getMessage(), dataVersion);
        throw e;
    } catch (DhisVersionMismatchException e) {
        context.updateRetryContext(METADATA_SYNC, e.getMessage(), dataVersion);
        throw e;
    }
    return metadataSyncSummary;
}
Also used : MetadataSyncServiceException(org.hisp.dhis.dxf2.metadata.sync.exception.MetadataSyncServiceException) MetadataSyncParams(org.hisp.dhis.dxf2.metadata.sync.MetadataSyncParams) MetadataImportParams(org.hisp.dhis.dxf2.metadata.MetadataImportParams) DhisVersionMismatchException(org.hisp.dhis.dxf2.metadata.sync.exception.DhisVersionMismatchException) MetadataSyncSummary(org.hisp.dhis.dxf2.metadata.sync.MetadataSyncSummary)

Example 47 with MetadataImportParams

use of org.hisp.dhis.dxf2.metadata.MetadataImportParams in project dhis2-core by dhis2.

the class MetadataSyncJob method runSyncTask.

synchronized void runSyncTask(MetadataRetryContext context, MetadataSyncJobParameters jobParameters) throws MetadataSyncServiceException, DhisVersionMismatchException {
    metadataSyncPreProcessor.setUp(context);
    metadataSyncPreProcessor.handleDataValuePush(context, jobParameters);
    metadataSyncPreProcessor.handleEventProgramsDataPush(context, jobParameters);
    metadataSyncPreProcessor.handleCompleteDataSetRegistrationDataPush(context);
    metadataSyncPreProcessor.handleTrackerProgramsDataPush(context, jobParameters);
    MetadataVersion metadataVersion = metadataSyncPreProcessor.handleCurrentMetadataVersion(context);
    List<MetadataVersion> metadataVersionList = metadataSyncPreProcessor.handleMetadataVersionsList(context, metadataVersion);
    if (metadataVersionList != null) {
        for (MetadataVersion dataVersion : metadataVersionList) {
            MetadataSyncParams syncParams = new MetadataSyncParams(new MetadataImportParams(), dataVersion);
            boolean isSyncRequired = metadataSyncService.isSyncRequired(syncParams);
            MetadataSyncSummary metadataSyncSummary = null;
            if (isSyncRequired) {
                metadataSyncSummary = handleMetadataSync(context, dataVersion);
            } else {
                metadataSyncPostProcessor.handleVersionAlreadyExists(context, dataVersion);
                break;
            }
            boolean abortStatus = metadataSyncPostProcessor.handleSyncNotificationsAndAbortStatus(metadataSyncSummary, context, dataVersion);
            if (abortStatus) {
                break;
            }
            clearFailedVersionSettings();
        }
    }
    log.info("Metadata sync cron job ended ");
}
Also used : MetadataVersion(org.hisp.dhis.metadata.version.MetadataVersion) MetadataSyncParams(org.hisp.dhis.dxf2.metadata.sync.MetadataSyncParams) MetadataImportParams(org.hisp.dhis.dxf2.metadata.MetadataImportParams) MetadataSyncSummary(org.hisp.dhis.dxf2.metadata.sync.MetadataSyncSummary)

Example 48 with MetadataImportParams

use of org.hisp.dhis.dxf2.metadata.MetadataImportParams in project dhis2-core by dhis2.

the class MetadataSyncImportHandler method importMetadata.

public MetadataSyncSummary importMetadata(MetadataSyncParams syncParams, String versionSnapShot) {
    MetadataVersion version = getMetadataVersion(syncParams);
    MetadataImportParams importParams = syncParams.getImportParams();
    MetadataSyncSummary metadataSyncSummary = new MetadataSyncSummary();
    if (importParams == null) {
        throw new MetadataSyncServiceException("MetadataImportParams for the Sync cant be null.");
    }
    Map<Class<? extends IdentifiableObject>, List<IdentifiableObject>> classListMap = parseClassListMap(versionSnapShot);
    if (classListMap == null) {
        throw new MetadataSyncServiceException("ClassListMap can't be null");
    }
    // Job configurations should not be imported from any source
    // (neither by normal metadata import nor by sync).
    classListMap.remove(JobConfiguration.class);
    importParams.setObjects(classListMap);
    ImportReport importReport = null;
    try {
        importReport = metadataImportService.importMetadata(importParams);
    } catch (Exception e) {
        String message = "Exception occurred while trying to import the metadata. " + e.getMessage();
        log.error(message, e);
        throw new MetadataSyncImportException(message, e);
    }
    boolean addNewVersion = handleImportReport(importReport, version);
    if (addNewVersion) {
        try {
            metadataVersionDelegate.addNewMetadataVersion(version);
        } catch (MetadataVersionServiceException e) {
            throw new MetadataSyncServiceException(e.getMessage(), e);
        }
    }
    metadataSyncSummary.setImportReport(importReport);
    metadataSyncSummary.setMetadataVersion(version);
    return metadataSyncSummary;
}
Also used : MetadataSyncServiceException(org.hisp.dhis.dxf2.metadata.sync.exception.MetadataSyncServiceException) MetadataImportParams(org.hisp.dhis.dxf2.metadata.MetadataImportParams) ImportReport(org.hisp.dhis.dxf2.metadata.feedback.ImportReport) IOException(java.io.IOException) MetadataSyncImportException(org.hisp.dhis.dxf2.metadata.sync.exception.MetadataSyncImportException) MetadataSyncServiceException(org.hisp.dhis.dxf2.metadata.sync.exception.MetadataSyncServiceException) MetadataVersionServiceException(org.hisp.dhis.dxf2.metadata.version.exception.MetadataVersionServiceException) IdentifiableObject(org.hisp.dhis.common.IdentifiableObject) MetadataVersion(org.hisp.dhis.metadata.version.MetadataVersion) MetadataVersionServiceException(org.hisp.dhis.dxf2.metadata.version.exception.MetadataVersionServiceException) MetadataSyncImportException(org.hisp.dhis.dxf2.metadata.sync.exception.MetadataSyncImportException) List(java.util.List)

Example 49 with MetadataImportParams

use of org.hisp.dhis.dxf2.metadata.MetadataImportParams in project dhis2-core by dhis2.

the class EventImportWithMetadataTest method setUpTest.

@Override
protected void setUpTest() throws Exception {
    renderService = _renderService;
    userService = _userService;
    Map<Class<? extends IdentifiableObject>, List<IdentifiableObject>> metadata = renderService.fromMetadata(new ClassPathResource("dxf2/import/create_program_stages.json").getInputStream(), RenderFormat.JSON);
    MetadataImportParams params = new MetadataImportParams();
    params.setImportMode(ObjectBundleMode.COMMIT);
    params.setImportStrategy(ImportStrategy.CREATE);
    params.setObjects(metadata);
    params.setSkipSharing(true);
    ImportReport report = importService.importMetadata(params);
    assertEquals(Status.OK, report.getStatus());
    idSchemes.setDataElementIdScheme("UID");
    idSchemes.setOrgUnitIdScheme("CODE");
    idSchemes.setProgramStageInstanceIdScheme("UID");
    events = csvEventService.readEvents(new ClassPathResource("dxf2/import/csv/events_import_code.csv").getInputStream(), true);
}
Also used : MetadataImportParams(org.hisp.dhis.dxf2.metadata.MetadataImportParams) ImportReport(org.hisp.dhis.dxf2.metadata.feedback.ImportReport) List(java.util.List) ClassPathResource(org.springframework.core.io.ClassPathResource) IdentifiableObject(org.hisp.dhis.common.IdentifiableObject)

Example 50 with MetadataImportParams

use of org.hisp.dhis.dxf2.metadata.MetadataImportParams in project dhis2-core by dhis2.

the class MetadataImportServiceTest method testImportUser.

@Test
void testImportUser() throws IOException {
    User userF = createUser('F', Lists.newArrayList("ALL"));
    userService.addUser(userF);
    injectSecurityContext(userF);
    Map<Class<? extends IdentifiableObject>, List<IdentifiableObject>> metadata = renderService.fromMetadata(new ClassPathResource("dxf2/create_user_without_createdBy.json").getInputStream(), RenderFormat.JSON);
    MetadataImportParams params = createParams(ImportStrategy.CREATE_AND_UPDATE, metadata);
    params.setUser(userF);
    ImportReport report = importService.importMetadata(params);
    assertEquals(Status.OK, report.getStatus());
    User user = manager.get(User.class, "MwhEJUnTHkn");
    assertNotNull(user.getCreatedBy());
}
Also used : User(org.hisp.dhis.user.User) ImportReport(org.hisp.dhis.dxf2.metadata.feedback.ImportReport) List(java.util.List) ClassPathResource(org.springframework.core.io.ClassPathResource) IdentifiableObject(org.hisp.dhis.common.IdentifiableObject) TransactionalIntegrationTest(org.hisp.dhis.TransactionalIntegrationTest) Test(org.junit.jupiter.api.Test)

Aggregations

ImportReport (org.hisp.dhis.dxf2.metadata.feedback.ImportReport)58 MetadataImportParams (org.hisp.dhis.dxf2.metadata.MetadataImportParams)49 List (java.util.List)38 IdentifiableObject (org.hisp.dhis.common.IdentifiableObject)38 Test (org.junit.jupiter.api.Test)38 ClassPathResource (org.springframework.core.io.ClassPathResource)31 User (org.hisp.dhis.user.User)30 TransactionalIntegrationTest (org.hisp.dhis.TransactionalIntegrationTest)29 DataSet (org.hisp.dhis.dataset.DataSet)12 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)12 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)11 UpdateAccessDeniedException (org.hisp.dhis.hibernate.exception.UpdateAccessDeniedException)10 WebMessageException (org.hisp.dhis.dxf2.webmessage.WebMessageException)9 BaseIdentifiableObject (org.hisp.dhis.common.BaseIdentifiableObject)8 WebMessage (org.hisp.dhis.dxf2.webmessage.WebMessage)8 HashMap (java.util.HashMap)6 UserGroup (org.hisp.dhis.user.UserGroup)6 ResponseStatus (org.springframework.web.bind.annotation.ResponseStatus)6 IOException (java.io.IOException)5 InputStream (java.io.InputStream)5