use of org.hisp.dhis.dxf2.metadata.feedback.ImportReport in project dhis2-core by dhis2.
the class AbstractCrudController method putJsonObject.
//--------------------------------------------------------------------------
// PUT
//--------------------------------------------------------------------------
@RequestMapping(value = "/{uid}", method = RequestMethod.PUT, consumes = MediaType.APPLICATION_JSON_VALUE)
public void putJsonObject(@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 = deserializeJsonEntity(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 DefaultMetadataImportService method importMetadata.
@Override
public ImportReport importMetadata(MetadataImportParams params) {
Timer timer = new SystemTimer().start();
ImportReport importReport = new ImportReport();
importReport.setImportParams(params);
importReport.setStatus(Status.OK);
if (params.getUser() == null) {
params.setUser(currentUserService.getCurrentUser());
}
String message = "(" + params.getUsername() + ") Import:Start";
log.info(message);
if (params.hasTaskId()) {
notifier.notify(params.getTaskId(), message);
}
ObjectBundleParams bundleParams = params.toObjectBundleParams();
ObjectBundle bundle = objectBundleService.create(bundleParams);
prepareBundle(bundle);
ObjectBundleValidationReport validationReport = objectBundleValidationService.validate(bundle);
importReport.addTypeReports(validationReport.getTypeReportMap());
if (!(!validationReport.getErrorReports().isEmpty() && AtomicMode.ALL == bundle.getAtomicMode())) {
Timer commitTimer = new SystemTimer().start();
ObjectBundleCommitReport commitReport = objectBundleService.commit(bundle);
importReport.addTypeReports(commitReport.getTypeReportMap());
if (!importReport.getErrorReports().isEmpty()) {
importReport.setStatus(Status.WARNING);
}
log.info("(" + bundle.getUsername() + ") Import:Commit took " + commitTimer.toString());
} else {
importReport.getStats().ignored();
importReport.getTypeReports().forEach(tr -> tr.getStats().ignored());
importReport.setStatus(Status.ERROR);
}
message = "(" + bundle.getUsername() + ") Import:Done took " + timer.toString();
log.info(message);
if (bundle.hasTaskId()) {
notifier.notify(bundle.getTaskId(), NotificationLevel.INFO, message, true).addTaskSummary(bundle.getTaskId(), importReport);
}
if (ObjectBundleMode.VALIDATE == params.getImportMode()) {
return importReport;
}
Lists.newArrayList(importReport.getTypeReportMap().keySet()).forEach(typeReportKey -> {
if (importReport.getTypeReportMap().get(typeReportKey).getStats().getTotal() == 0) {
importReport.getTypeReportMap().remove(typeReportKey);
return;
}
TypeReport typeReport = importReport.getTypeReportMap().get(typeReportKey);
if (ImportReportMode.ERRORS == params.getImportReportMode()) {
Lists.newArrayList(typeReport.getObjectReportMap().keySet()).forEach(objectReportKey -> {
if (typeReport.getObjectReportMap().get(objectReportKey).getErrorReportsByCode().isEmpty()) {
typeReport.getObjectReportMap().remove(objectReportKey);
}
});
}
if (ImportReportMode.DEBUG != params.getImportReportMode()) {
typeReport.getObjectReports().forEach(objectReport -> objectReport.setDisplayName(null));
}
});
return importReport;
}
use of org.hisp.dhis.dxf2.metadata.feedback.ImportReport in project dhis2-core by dhis2.
the class MetadataImportController method postXmlMetadata.
@RequestMapping(value = "", method = RequestMethod.POST, consumes = MediaType.APPLICATION_XML_VALUE)
public void postXmlMetadata(HttpServletRequest request, HttpServletResponse response) throws IOException {
MetadataImportParams params = metadataImportService.getParamsFromMap(contextService.getParameterValuesMap());
Metadata metadata = renderService.fromXml(StreamUtils.wrapAndCheckCompressionFormat(request.getInputStream()), Metadata.class);
params.addMetadata(schemaService.getMetadataSchemas(), metadata);
if (params.hasTaskId()) {
startAsync(params);
response.setStatus(HttpServletResponse.SC_NO_CONTENT);
} else {
ImportReport importReport = metadataImportService.importMetadata(params);
renderService.toXml(response.getOutputStream(), importReport);
}
}
use of org.hisp.dhis.dxf2.metadata.feedback.ImportReport in project dhis2-core by dhis2.
the class UserController method createUser.
/**
* Creates a user.
*
* @param user user object parsed from the POST request.
*/
private ImportReport createUser(User user, User currentUser) throws Exception {
user.getUserCredentials().getCogsDimensionConstraints().addAll(currentUser.getUserCredentials().getCogsDimensionConstraints());
user.getUserCredentials().getCatDimensionConstraints().addAll(currentUser.getUserCredentials().getCatDimensionConstraints());
MetadataImportParams importParams = new MetadataImportParams().setImportReportMode(ImportReportMode.FULL).setImportStrategy(ImportStrategy.CREATE).addObject(user);
ImportReport importReport = importService.importMetadata(importParams);
if (importReport.getStatus() == Status.OK && importReport.getStats().getCreated() == 1) {
userGroupService.addUserToGroups(user, IdentifiableObjectUtils.getUids(user.getGroups()), currentUser);
}
return importReport;
}
use of org.hisp.dhis.dxf2.metadata.feedback.ImportReport in project dhis2-core by dhis2.
the class SynchronizationController method importMetaData.
@PreAuthorize("hasRole('ALL')")
@RequestMapping(value = "/metadataPull", method = RequestMethod.POST)
public void importMetaData(@RequestBody String url, HttpServletResponse response) throws IOException {
ImportReport importReport = synchronizationManager.executeMetadataPull(url);
response.setContentType(CONTENT_TYPE_JSON);
renderService.toJson(response.getOutputStream(), importReport);
}
Aggregations