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