Search in sources :

Example 6 with MetadataSyncParams

use of org.hisp.dhis.dxf2.metadata.sync.MetadataSyncParams 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 7 with MetadataSyncParams

use of org.hisp.dhis.dxf2.metadata.sync.MetadataSyncParams 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 8 with MetadataSyncParams

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

the class DefaultMetadataSyncService method doMetadataSync.

@Override
public synchronized MetadataSyncSummary doMetadataSync(MetadataSyncParams syncParams) throws MetadataSyncServiceException, DhisVersionMismatchException {
    MetadataVersion version = getMetadataVersion(syncParams);
    setMetadataImportMode(syncParams, version);
    String metadataVersionSnapshot = getMetadataVersionSnapshot(version);
    if (metadataSyncDelegate.shouldStopSync(metadataVersionSnapshot)) {
        throw new DhisVersionMismatchException("Metadata sync failed because your version of DHIS does not match the master version");
    }
    saveMetadataVersionSnapshotLocally(version, metadataVersionSnapshot);
    MetadataSyncSummary metadataSyncSummary = metadataSyncImportHandler.importMetadata(syncParams, metadataVersionSnapshot);
    log.info("Metadata Sync Summary: " + metadataSyncSummary);
    return metadataSyncSummary;
}
Also used : MetadataVersion(org.hisp.dhis.metadata.version.MetadataVersion) DhisVersionMismatchException(org.hisp.dhis.dxf2.metadata.sync.exception.DhisVersionMismatchException)

Example 9 with MetadataSyncParams

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

the class DefaultMetadataSyncServiceTest method testShouldVerifyImportParamsAtomicTypeForTheGivenBestEffortVersion.

@Test
void testShouldVerifyImportParamsAtomicTypeForTheGivenBestEffortVersion() throws DhisVersionMismatchException {
    MetadataSyncParams syncParams = new MetadataSyncParams();
    MetadataVersion metadataVersion = new MetadataVersion("testVersion", VersionType.BEST_EFFORT);
    MetadataImportParams metadataImportParams = new MetadataImportParams();
    syncParams.setVersion(metadataVersion);
    syncParams.setImportParams(metadataImportParams);
    MetadataSyncSummary metadataSyncSummary = new MetadataSyncSummary();
    metadataSyncSummary.setMetadataVersion(metadataVersion);
    String expectedMetadataSnapshot = "{\"date\":\"2016-05-24T05:27:25.128+0000\"}";
    when(metadataVersionService.getVersionData("testVersion")).thenReturn(expectedMetadataSnapshot);
    metadataSyncService.doMetadataSync(syncParams);
    verify(metadataSyncImportHandler, times(1)).importMetadata((argThat(metadataSyncParams -> syncParams.getImportParams().getAtomicMode().equals(AtomicMode.NONE))), eq(expectedMetadataSnapshot));
    verify(metadataVersionService, never()).createMetadataVersionInDataStore(metadataVersion.getName(), expectedMetadataSnapshot);
    verify(metadataVersionDelegate, never()).downloadMetadataVersionSnapshot(metadataVersion);
}
Also used : MetadataVersion(org.hisp.dhis.metadata.version.MetadataVersion) MetadataImportParams(org.hisp.dhis.dxf2.metadata.MetadataImportParams) Test(org.junit.jupiter.api.Test)

Example 10 with MetadataSyncParams

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

the class MetadataSyncImportHandlerTest method setup.

@BeforeEach
public void setup() {
    metadataVersion = new MetadataVersion("testVersion", VersionType.ATOMIC);
    expectedMetadataSnapshot = "{\"date\":\"2016-05-24T05:27:25.128+0000\"}";
    syncParams = new MetadataSyncParams();
    importReport = new ImportReport();
}
Also used : MetadataVersion(org.hisp.dhis.metadata.version.MetadataVersion) ImportReport(org.hisp.dhis.dxf2.metadata.feedback.ImportReport) BeforeEach(org.junit.jupiter.api.BeforeEach)

Aggregations

MetadataImportParams (org.hisp.dhis.dxf2.metadata.MetadataImportParams)7 MetadataVersion (org.hisp.dhis.metadata.version.MetadataVersion)7 MetadataSyncParams (org.hisp.dhis.dxf2.metadata.sync.MetadataSyncParams)5 MetadataSyncSummary (org.hisp.dhis.dxf2.metadata.sync.MetadataSyncSummary)5 MetadataSyncServiceException (org.hisp.dhis.dxf2.metadata.sync.exception.MetadataSyncServiceException)5 DhisVersionMismatchException (org.hisp.dhis.dxf2.metadata.sync.exception.DhisVersionMismatchException)4 ImportReport (org.hisp.dhis.dxf2.metadata.feedback.ImportReport)2 MetadataSyncImportException (org.hisp.dhis.dxf2.metadata.sync.exception.MetadataSyncImportException)2 MetadataVersionServiceException (org.hisp.dhis.dxf2.metadata.version.exception.MetadataVersionServiceException)2 IOException (java.io.IOException)1 List (java.util.List)1 IdentifiableObject (org.hisp.dhis.common.IdentifiableObject)1 RemoteServerUnavailableException (org.hisp.dhis.dxf2.metadata.sync.exception.RemoteServerUnavailableException)1 BadRequestException (org.hisp.dhis.webapi.controller.exception.BadRequestException)1 MetadataImportConflictException (org.hisp.dhis.webapi.controller.exception.MetadataImportConflictException)1 MetadataSyncException (org.hisp.dhis.webapi.controller.exception.MetadataSyncException)1 OperationNotAllowedException (org.hisp.dhis.webapi.controller.exception.OperationNotAllowedException)1 BeforeEach (org.junit.jupiter.api.BeforeEach)1 Test (org.junit.jupiter.api.Test)1 ResponseEntity (org.springframework.http.ResponseEntity)1