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 ");
}
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;
}
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;
}
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);
}
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();
}
Aggregations