use of org.hisp.dhis.dxf2.metadata.feedback.ImportReport in project dhis2-core by dhis2.
the class MetadataImportExportController method postCsvMetadata.
@PostMapping(value = "", consumes = "application/csv")
@ResponseBody
public WebMessage postCsvMetadata(HttpServletRequest request) throws IOException {
MetadataImportParams params = metadataImportService.getParamsFromMap(contextService.getParameterValuesMap());
String classKey = request.getParameter("classKey");
if (StringUtils.isEmpty(classKey) || !CsvImportClass.classExists(classKey)) {
return conflict("Cannot find Csv import class: " + classKey);
}
params.setCsvImportClass(CsvImportClass.valueOf(classKey));
Metadata metadata = csvImportService.fromCsv(request.getInputStream(), new CsvImportOptions().setImportClass(params.getCsvImportClass()).setFirstRowIsHeader(params.isFirstRowIsHeader()));
params.addMetadata(schemaService.getMetadataSchemas(), metadata);
if (params.hasJobId()) {
return startAsyncMetadata(params);
}
ImportReport importReport = metadataImportService.importMetadata(params);
return importReport(importReport).withPlainResponseBefore(DhisApiVersion.V38);
}
use of org.hisp.dhis.dxf2.metadata.feedback.ImportReport in project dhis2-core by dhis2.
the class MetadataImportExportController method postGmlMetadata.
@PostMapping(value = "/gml", consumes = APPLICATION_XML_VALUE)
@ResponseBody
public WebMessage postGmlMetadata(HttpServletRequest request) throws IOException {
MetadataImportParams params = metadataImportService.getParamsFromMap(contextService.getParameterValuesMap());
if (params.hasJobId()) {
return startAsyncGml(params, request);
}
ImportReport importReport = gmlImportService.importGml(request.getInputStream(), params);
return importReport(importReport).withPlainResponseBefore(DhisApiVersion.V38);
}
use of org.hisp.dhis.dxf2.metadata.feedback.ImportReport in project dhis2-core by dhis2.
the class DefaultSynchronizationManager method executeMetadataPull.
@Override
public ImportReport executeMetadataPull(String url) {
User user = currentUserService.getCurrentUser();
String userUid = user != null ? user.getUid() : null;
log.info(String.format("Metadata pull, url: %s, user: %s", url, userUid));
String json = restTemplate.getForObject(url, String.class);
Metadata metadata = null;
try {
metadata = jsonMapper.readValue(json, Metadata.class);
} catch (IOException ex) {
throw new RuntimeException("Failed to parse remote JSON document", ex);
}
MetadataImportParams importParams = new MetadataImportParams();
importParams.setSkipSharing(true);
importParams.setAtomicMode(AtomicMode.NONE);
importParams.addMetadata(schemaService.getMetadataSchemas(), metadata);
return importService.importMetadata(importParams);
}
use of org.hisp.dhis.dxf2.metadata.feedback.ImportReport in project dhis2-core by dhis2.
the class UserController method updateUser.
protected ImportReport updateUser(String userUid, User parsedUserObject) throws WebMessageException {
List<User> users = getEntity(userUid, NO_WEB_OPTIONS);
if (users.isEmpty()) {
throw new WebMessageException(conflict(getEntityName() + " does not exist: " + userUid));
}
User currentUser = currentUserService.getCurrentUser();
if (!aclService.canUpdate(currentUser, users.get(0))) {
throw new UpdateAccessDeniedException("You don't have the proper permissions to update this user.");
}
// force initialization of all authorities of current user in order to
// prevent cases where user must be reloaded later
// (in case it gets detached)
currentUser.getAllAuthorities();
parsedUserObject.setId(users.get(0).getId());
parsedUserObject.setUid(userUid);
mergeLastLoginAttribute(users.get(0), parsedUserObject);
boolean isPasswordChangeAttempt = parsedUserObject.getPassword() != null;
List<String> groupsUids = getUids(parsedUserObject.getGroups());
if (!userService.canAddOrUpdateUser(groupsUids, currentUser) || !currentUser.canModifyUser(users.get(0))) {
throw new WebMessageException(conflict("You must have permissions to create user, " + "or ability to manage at least one user group for the user."));
}
MetadataImportParams params = importService.getParamsFromMap(contextService.getParameterValuesMap());
params.setImportReportMode(ImportReportMode.FULL);
params.setImportStrategy(ImportStrategy.UPDATE);
params.addObject(parsedUserObject);
ImportReport importReport = importService.importMetadata(params);
if (importReport.getStatus() == Status.OK && importReport.getStats().getUpdated() == 1) {
updateUserGroups(userUid, parsedUserObject, currentUser);
// same. i.e. no before & after equals pw check
if (isPasswordChangeAttempt) {
userService.expireActiveSessions(parsedUserObject);
}
}
return 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) {
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, getUids(user.getGroups()), currentUser);
}
return importReport;
}
Aggregations