use of org.hisp.dhis.dxf2.metadata.feedback.ImportReport in project dhis2-core by dhis2.
the class WebMessageUtils method importReport.
public static WebMessage importReport(ImportReport importReport) {
WebMessage webMessage = new WebMessage();
webMessage.setResponse(new ImportReportWebMessageResponse(importReport));
webMessage.setStatus(importReport.getStatus());
if (webMessage.getStatus() != Status.OK) {
webMessage.setMessage("One more more errors occurred, please see full details in import report.");
webMessage.setStatus(Status.WARNING);
webMessage.setHttpStatus(HttpStatus.CONFLICT);
}
return webMessage;
}
use of org.hisp.dhis.dxf2.metadata.feedback.ImportReport in project dhis2-core by dhis2.
the class MetadataImportController method postJsonMetadata.
@RequestMapping(value = "", method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE)
public void postJsonMetadata(HttpServletRequest request, HttpServletResponse response) throws IOException {
MetadataImportParams params = metadataImportService.getParamsFromMap(contextService.getParameterValuesMap());
params.setObjects(renderService.fromMetadata(StreamUtils.wrapAndCheckCompressionFormat(request.getInputStream()), RenderFormat.JSON));
if (params.hasTaskId()) {
startAsync(params);
response.setStatus(HttpServletResponse.SC_NO_CONTENT);
} else {
ImportReport importReport = metadataImportService.importMetadata(params);
renderService.toJson(response.getOutputStream(), importReport);
}
}
use of org.hisp.dhis.dxf2.metadata.feedback.ImportReport 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.feedback.ImportReport in project dhis2-core by dhis2.
the class MetadataSyncPostProcessor method handleSyncNotificationsAndAbortStatus.
public boolean handleSyncNotificationsAndAbortStatus(MetadataSyncSummary metadataSyncSummary, MetadataRetryContext retryContext, MetadataVersion dataVersion) {
ImportReport importReport = metadataSyncSummary.getImportReport();
if (importReport == null) {
handleImportFailedContext(null, retryContext, dataVersion);
return true;
}
Status syncStatus = importReport.getStatus();
log.info("Import completed. Import Status: " + syncStatus);
if (Status.OK.equals(syncStatus) || (Status.WARNING.equals(syncStatus) && VersionType.BEST_EFFORT.equals(dataVersion.getType()))) {
sendSuccessMailToAdmin(metadataSyncSummary);
return false;
}
if (Status.ERROR.equals(syncStatus)) {
handleImportFailedContext(metadataSyncSummary, retryContext, dataVersion);
return true;
}
return false;
}
use of org.hisp.dhis.dxf2.metadata.feedback.ImportReport 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);
}
Aggregations