use of org.hisp.dhis.dxf2.metadata.feedback.ImportReport in project dhis2-core by dhis2.
the class AbstractCrudController method postXmlObject.
@RequestMapping(method = RequestMethod.POST, consumes = { "application/xml", "text/xml" })
public void postXmlObject(HttpServletRequest request, HttpServletResponse response) throws Exception {
User user = currentUserService.getCurrentUser();
if (!aclService.canCreate(user, getEntityClass())) {
throw new CreateAccessDeniedException("You don't have the proper permissions to create this object.");
}
T parsed = deserializeXmlEntity(request, response);
parsed.getTranslations().clear();
preCreateEntity(parsed);
MetadataImportParams params = importService.getParamsFromMap(contextService.getParameterValuesMap()).setImportReportMode(ImportReportMode.FULL).setUser(user).setImportStrategy(ImportStrategy.CREATE).addObject(parsed);
ImportReport importReport = importService.importMetadata(params);
ObjectReport objectReport = getObjectReport(importReport);
WebMessage webMessage = WebMessageUtils.objectReport(objectReport);
if (objectReport != null && webMessage.getStatus() == Status.OK) {
String location = contextService.getApiPath() + getSchema().getRelativeApiEndpoint() + "/" + objectReport.getUid();
webMessage.setHttpStatus(HttpStatus.CREATED);
response.setHeader(ContextUtils.HEADER_LOCATION, location);
T entity = manager.get(getEntityClass(), objectReport.getUid());
postCreateEntity(entity);
} else {
webMessage.setStatus(Status.ERROR);
}
webMessageService.send(webMessage, response, request);
}
use of org.hisp.dhis.dxf2.metadata.feedback.ImportReport in project dhis2-core by dhis2.
the class AbstractCrudController method postJsonObject.
//--------------------------------------------------------------------------
// POST
//--------------------------------------------------------------------------
@RequestMapping(method = RequestMethod.POST, consumes = "application/json")
public void postJsonObject(HttpServletRequest request, HttpServletResponse response) throws Exception {
User user = currentUserService.getCurrentUser();
if (!aclService.canCreate(user, getEntityClass())) {
throw new CreateAccessDeniedException("You don't have the proper permissions to create this object.");
}
T parsed = deserializeJsonEntity(request, response);
parsed.getTranslations().clear();
preCreateEntity(parsed);
MetadataImportParams params = importService.getParamsFromMap(contextService.getParameterValuesMap()).setImportReportMode(ImportReportMode.FULL).setUser(user).setImportStrategy(ImportStrategy.CREATE).addObject(parsed);
ImportReport importReport = importService.importMetadata(params);
ObjectReport objectReport = getObjectReport(importReport);
WebMessage webMessage = WebMessageUtils.objectReport(objectReport);
if (objectReport != null && webMessage.getStatus() == Status.OK) {
String location = contextService.getApiPath() + getSchema().getRelativeApiEndpoint() + "/" + objectReport.getUid();
webMessage.setHttpStatus(HttpStatus.CREATED);
response.setHeader(ContextUtils.HEADER_LOCATION, location);
T entity = manager.get(getEntityClass(), objectReport.getUid());
postCreateEntity(entity);
} else {
webMessage.setStatus(Status.ERROR);
}
webMessageService.send(webMessage, response, request);
}
use of org.hisp.dhis.dxf2.metadata.feedback.ImportReport in project dhis2-core by dhis2.
the class AbstractCrudController method putXmlObject.
@RequestMapping(value = "/{uid}", method = RequestMethod.PUT, consumes = { MediaType.APPLICATION_XML_VALUE, MediaType.TEXT_XML_VALUE })
public void putXmlObject(@PathVariable("uid") String pvUid, HttpServletRequest request, HttpServletResponse response) throws Exception {
List<T> objects = getEntity(pvUid);
if (objects.isEmpty()) {
throw new WebMessageException(WebMessageUtils.notFound(getEntityClass(), pvUid));
}
User user = currentUserService.getCurrentUser();
if (!aclService.canUpdate(user, objects.get(0))) {
throw new UpdateAccessDeniedException("You don't have the proper permissions to update this object.");
}
T parsed = deserializeXmlEntity(request, response);
((BaseIdentifiableObject) parsed).setUid(pvUid);
preUpdateEntity(objects.get(0), parsed);
MetadataImportParams params = importService.getParamsFromMap(contextService.getParameterValuesMap()).setImportReportMode(ImportReportMode.FULL).setUser(user).setImportStrategy(ImportStrategy.UPDATE).addObject(parsed);
ImportReport importReport = importService.importMetadata(params);
WebMessage webMessage = WebMessageUtils.objectReport(importReport);
if (importReport.getStatus() == Status.OK) {
T entity = manager.get(getEntityClass(), pvUid);
postUpdateEntity(entity);
} else {
webMessage.setStatus(Status.ERROR);
}
webMessageService.send(webMessage, response, request);
}
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");
}
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;
}
Aggregations