use of org.hisp.dhis.webapi.controller.exception.NotAuthenticatedException in project dhis2-core by dhis2.
the class CurrentUserController method getInboxInterpretations.
@RequestMapping(value = "/inbox/interpretations", produces = { "application/json", "text/*" })
public void getInboxInterpretations(HttpServletResponse response) throws Exception {
User user = currentUserService.getCurrentUser();
if (user == null) {
throw new NotAuthenticatedException();
}
response.setContentType(MediaType.APPLICATION_JSON_VALUE);
List<Interpretation> interpretations = new ArrayList<>(interpretationService.getInterpretations(0, MAX_OBJECTS));
for (Interpretation interpretation : interpretations) {
interpretation.setAccess(aclService.getAccess(interpretation, user));
}
renderService.toJson(response.getOutputStream(), interpretations);
}
use of org.hisp.dhis.webapi.controller.exception.NotAuthenticatedException in project dhis2-core by dhis2.
the class CurrentUserController method getAssignedOrganisationUnits.
@RequestMapping(value = { "/assignedOrganisationUnits", "/organisationUnits" }, produces = { "application/json", "text/*" })
public void getAssignedOrganisationUnits(HttpServletResponse response, @RequestParam Map<String, String> parameters) throws IOException, NotAuthenticatedException {
User currentUser = currentUserService.getCurrentUser();
if (currentUser == null) {
throw new NotAuthenticatedException();
}
Set<OrganisationUnit> userOrganisationUnits = new HashSet<>();
userOrganisationUnits.add(currentUser.getOrganisationUnit());
if (parameters.containsKey("includeChildren") && Boolean.parseBoolean(parameters.get("includeChildren"))) {
List<OrganisationUnit> children = new ArrayList<>();
for (OrganisationUnit organisationUnit : userOrganisationUnits) {
children.addAll(organisationUnit.getChildren());
}
userOrganisationUnits.addAll(children);
} else if (parameters.containsKey("includeDescendants") && Boolean.parseBoolean(parameters.get("includeDescendants"))) {
List<OrganisationUnit> children = new ArrayList<>();
for (OrganisationUnit organisationUnit : userOrganisationUnits) {
children.addAll(organisationUnitService.getOrganisationUnitWithChildren(organisationUnit.getUid()));
}
userOrganisationUnits.addAll(children);
}
response.setContentType(MediaType.APPLICATION_JSON_VALUE);
renderService.toJson(response.getOutputStream(), userOrganisationUnits);
}
use of org.hisp.dhis.webapi.controller.exception.NotAuthenticatedException in project dhis2-core by dhis2.
the class CurrentUserController method postUserAccountJson.
@RequestMapping(value = { "/profile", "/user-account" }, method = RequestMethod.POST, consumes = "application/json")
public void postUserAccountJson(HttpServletResponse response, HttpServletRequest request) throws Exception {
UserAccount userAccount = renderService.fromJson(request.getInputStream(), UserAccount.class);
User currentUser = currentUserService.getCurrentUser();
if (currentUser == null) {
throw new NotAuthenticatedException();
}
// basic user account
currentUser.setFirstName(userAccount.getFirstName());
currentUser.setSurname(userAccount.getSurname());
currentUser.setEmail(userAccount.getEmail());
currentUser.setPhoneNumber(userAccount.getPhoneNumber());
// profile
currentUser.setIntroduction(userAccount.getIntroduction());
currentUser.setJobTitle(userAccount.getJobTitle());
currentUser.setGender(userAccount.getGender());
if (userAccount.getBirthday() != null && !userAccount.getBirthday().isEmpty()) {
currentUser.setBirthday(DateUtils.getMediumDate(userAccount.getBirthday()));
}
currentUser.setNationality(userAccount.getNationality());
currentUser.setEmployer(userAccount.getEmployer());
currentUser.setEducation(userAccount.getEducation());
currentUser.setInterests(userAccount.getInterests());
currentUser.setLanguages(userAccount.getLanguages());
userService.updateUser(currentUser);
}
use of org.hisp.dhis.webapi.controller.exception.NotAuthenticatedException in project dhis2-core by dhis2.
the class CurrentUserController method getDataSets.
@RequestMapping(value = { "/assignedDataSets", "/dataSets" }, produces = { "application/json", "text/*" })
public void getDataSets(@RequestParam(defaultValue = "false") boolean optionSets, @RequestParam(defaultValue = "50") int maxOptions, HttpServletResponse response, @RequestParam Map<String, String> parameters) throws IOException, NotAuthenticatedException {
User currentUser = currentUserService.getCurrentUser();
if (currentUser == null) {
throw new NotAuthenticatedException();
}
Forms forms = new Forms();
Set<OrganisationUnit> organisationUnits = new HashSet<>();
Set<DataSet> userDataSets;
Set<OrganisationUnit> userOrganisationUnits = new HashSet<>(currentUser.getOrganisationUnits());
if (currentUser.getUserCredentials().getAllAuthorities().contains("ALL")) {
userDataSets = new HashSet<>(dataSetService.getAllDataSets());
if (userOrganisationUnits.isEmpty()) {
userOrganisationUnits = new HashSet<>(organisationUnitService.getRootOrganisationUnits());
}
} else {
userDataSets = currentUser.getUserCredentials().getAllDataSets();
}
if (parameters.containsKey("includeDescendants") && Boolean.parseBoolean(parameters.get("includeDescendants"))) {
List<OrganisationUnit> children = new ArrayList<>();
for (OrganisationUnit organisationUnit : userOrganisationUnits) {
children.addAll(organisationUnitService.getOrganisationUnitWithChildren(organisationUnit.getUid()));
}
userOrganisationUnits.addAll(children);
} else {
List<OrganisationUnit> children = new ArrayList<>();
for (OrganisationUnit organisationUnit : userOrganisationUnits) {
children.addAll(organisationUnit.getChildren());
}
userOrganisationUnits.addAll(children);
}
for (OrganisationUnit ou : userOrganisationUnits) {
Set<DataSet> dataSets = new HashSet<>(Sets.intersection(ou.getDataSets(), userDataSets));
if (dataSets.size() > 0) {
organisationUnits.add(ou);
}
}
for (OrganisationUnit organisationUnit : organisationUnits) {
FormOrganisationUnit formOrganisationUnit = new FormOrganisationUnit();
formOrganisationUnit.setId(organisationUnit.getUid());
formOrganisationUnit.setLabel(organisationUnit.getDisplayName());
formOrganisationUnit.setLevel(organisationUnit.getLevel());
if (organisationUnit.getParent() != null) {
formOrganisationUnit.setParent(organisationUnit.getParent().getUid());
}
Set<DataSet> dataSets = new HashSet<>(Sets.intersection(organisationUnit.getDataSets(), userDataSets));
for (DataSet dataSet : dataSets) {
String uid = dataSet.getUid();
FormDataSet formDataSet = new FormDataSet();
formDataSet.setId(uid);
formDataSet.setLabel(dataSet.getDisplayName());
dataSet.getCategoryCombo().getCategories().forEach(cat -> {
cat.setAccess(aclService.getAccess(cat, currentUser));
cat.getCategoryOptions().forEach(catOpts -> catOpts.setAccess(aclService.getAccess(catOpts, currentUser)));
});
forms.getForms().put(uid, FormUtils.fromDataSet(dataSet, false, userOrganisationUnits));
formOrganisationUnit.getDataSets().add(formDataSet);
if (optionSets) {
for (DataElement dataElement : dataSet.getDataElements()) {
if (dataElement.hasOptionSet()) {
int size = maxOptions;
if (size >= dataElement.getOptionSet().getOptions().size()) {
size = dataElement.getOptionSet().getOptions().size();
}
forms.getOptionSets().put(dataElement.getOptionSet().getUid(), dataElement.getOptionSet().getOptionValues().subList(0, size - 1));
}
}
}
}
forms.getOrganisationUnits().put(formOrganisationUnit.getId(), formOrganisationUnit);
}
response.setContentType(MediaType.APPLICATION_JSON_VALUE);
renderService.toJson(response.getOutputStream(), forms);
}
use of org.hisp.dhis.webapi.controller.exception.NotAuthenticatedException in project dhis2-core by dhis2.
the class CurrentUserController method getUserAccount.
private UserAccount getUserAccount() throws NotAuthenticatedException {
User currentUser = currentUserService.getCurrentUser();
if (currentUser == null) {
throw new NotAuthenticatedException();
}
UserAccount userAccount = new UserAccount();
// user account
userAccount.setId(currentUser.getUid());
userAccount.setUsername(currentUser.getUsername());
userAccount.setFirstName(currentUser.getFirstName());
userAccount.setSurname(currentUser.getSurname());
userAccount.setEmail(currentUser.getEmail());
userAccount.setPhoneNumber(currentUser.getPhoneNumber());
// profile
userAccount.setIntroduction(currentUser.getIntroduction());
userAccount.setJobTitle(currentUser.getJobTitle());
userAccount.setGender(currentUser.getGender());
if (currentUser.getBirthday() != null) {
userAccount.setBirthday(DateUtils.getMediumDateString(currentUser.getBirthday()));
}
userAccount.setNationality(currentUser.getNationality());
userAccount.setEmployer(currentUser.getEmployer());
userAccount.setEducation(currentUser.getEducation());
userAccount.setInterests(currentUser.getInterests());
userAccount.setLanguages(currentUser.getLanguages());
userAccount.getSettings().put(UserSettingKey.UI_LOCALE.getName(), TextUtils.toString(userSettingService.getUserSetting(UserSettingKey.UI_LOCALE)));
userAccount.getSettings().put(UserSettingKey.DB_LOCALE.getName(), TextUtils.toString(userSettingService.getUserSetting(UserSettingKey.DB_LOCALE)));
userAccount.getSettings().put(UserSettingKey.MESSAGE_EMAIL_NOTIFICATION.getName(), TextUtils.toString(userSettingService.getUserSetting(UserSettingKey.MESSAGE_EMAIL_NOTIFICATION)));
userAccount.getSettings().put(UserSettingKey.MESSAGE_SMS_NOTIFICATION.getName(), TextUtils.toString(userSettingService.getUserSetting(UserSettingKey.MESSAGE_SMS_NOTIFICATION)));
userAccount.getSettings().put(UserSettingKey.ANALYSIS_DISPLAY_PROPERTY.getName(), TextUtils.toString(userSettingService.getUserSetting(UserSettingKey.ANALYSIS_DISPLAY_PROPERTY)));
return userAccount;
}
Aggregations