use of org.hisp.dhis.node.types.SimpleNode in project dhis2-core by dhis2.
the class MetadataVersionController method getMetadataVersionsAsNode.
private RootNode getMetadataVersionsAsNode(List<MetadataVersion> versions) {
RootNode rootNode = NodeUtils.createRootNode("metadataversions");
CollectionNode collectionNode = new CollectionNode("metadataversions", true);
rootNode.addChild(collectionNode);
for (MetadataVersion version : versions) {
ComplexNode complexNode = new ComplexNode("");
complexNode.addChild(new SimpleNode("name", version.getName()));
complexNode.addChild(new SimpleNode("type", version.getType()));
complexNode.addChild(new SimpleNode("created", version.getCreated()));
complexNode.addChild(new SimpleNode("id", version.getUid()));
complexNode.addChild(new SimpleNode("importdate", version.getImportDate()));
complexNode.addChild(new SimpleNode("hashCode", version.getHashCode()));
collectionNode.addChild(complexNode);
}
return rootNode;
}
use of org.hisp.dhis.node.types.SimpleNode in project dhis2-core by dhis2.
the class UserControllerUtils method getWorkflowLevelNodes.
// -------------------------------------------------------------------------
// Supportive methods
// -------------------------------------------------------------------------
/**
* For a user and workflow, returns a list of levels accessible to the user
* user and the actions (if any) they can take at those levels to approve
* (and accept if configured) data.
*
* @param user the user
* @param workflow the approval workflow for which to fetch the levels
* @return a node with the ordered list of data approval levels
*/
private CollectionNode getWorkflowLevelNodes(User user, DataApprovalWorkflow workflow) {
Set<String> authorities = user.getAllAuthorities();
boolean canApprove = authorities.contains(AUTHORITY_ALL) || authorities.contains(AUTH_APPROVE);
boolean canApproveLowerLevels = authorities.contains(AUTHORITY_ALL) || authorities.contains(AUTH_APPROVE_LOWER_LEVELS);
boolean canAccept = authorities.contains(AUTHORITY_ALL) || authorities.contains(AUTH_ACCEPT_LOWER_LEVELS);
boolean acceptConfigured = systemSettingManager.getBoolSetting(SettingKey.ACCEPTANCE_REQUIRED_FOR_APPROVAL);
int lowestUserOrgUnitLevel = getLowsetUserOrgUnitLevel(user);
CollectionNode levelNodes = new CollectionNode("dataApprovalLevels", true);
boolean highestLevelInWorkflow = true;
for (DataApprovalLevel level : dataApprovalLevelService.getUserDataApprovalLevels(user, workflow)) {
if (level.getOrgUnitLevel() < lowestUserOrgUnitLevel) {
continue;
}
ComplexNode levelNode = new ComplexNode("dataApprovalLevel");
levelNode.addChild(new SimpleNode("name", level.getName()));
levelNode.addChild(new SimpleNode("id", level.getUid()));
levelNode.addChild(new SimpleNode("level", level.getLevel()));
levelNode.addChild(new SimpleNode("approve", (canApprove && highestLevelInWorkflow) || canApproveLowerLevels));
if (acceptConfigured) {
levelNode.addChild(new SimpleNode("accept", canAccept && !highestLevelInWorkflow));
}
levelNodes.addChild(levelNode);
highestLevelInWorkflow = false;
}
return levelNodes;
}
use of org.hisp.dhis.node.types.SimpleNode in project dhis2-core by dhis2.
the class MeController method validatePasswordInternal.
private RootNode validatePasswordInternal(String password, User currentUser) throws WebMessageException {
if (password == null) {
throw new WebMessageException(conflict("Required attribute 'password' missing or null."));
}
CredentialsInfo credentialsInfo = new CredentialsInfo(currentUser.getUsername(), password, currentUser.getEmail(), false);
PasswordValidationResult result = passwordValidationService.validate(credentialsInfo);
RootNode rootNode = NodeUtils.createRootNode("response");
rootNode.addChild(new SimpleNode("isValidPassword", result.isValid()));
if (!result.isValid()) {
rootNode.addChild(new SimpleNode("errorMessage", result.getErrorMessage()));
}
return rootNode;
}
use of org.hisp.dhis.node.types.SimpleNode in project dhis2-core by dhis2.
the class MessageConversationController method removeUserFromMessageConversation.
// --------------------------------------------------------------------------
// Remove a user from a MessageConversation
// In practice a DELETE on MessageConversation <-> User relationship
// --------------------------------------------------------------------------
@DeleteMapping(value = "/{mc-uid}/{user-uid}", produces = { MediaType.APPLICATION_JSON_VALUE, MediaType.APPLICATION_XML_VALUE })
@ResponseBody
public RootNode removeUserFromMessageConversation(@PathVariable(value = "mc-uid") String mcUid, @PathVariable(value = "user-uid") String userUid, @CurrentUser User currentUser, HttpServletResponse response) throws DeleteAccessDeniedException {
RootNode responseNode = new RootNode("reply");
User user = userService.getUser(userUid);
if (user == null) {
responseNode.addChild(new SimpleNode("message", "No user with uid: " + userUid));
response.setStatus(HttpServletResponse.SC_NOT_FOUND);
return responseNode;
}
if (!canModifyUserConversation(currentUser, user)) {
throw new DeleteAccessDeniedException("Not authorized to modify user: " + user.getUid());
}
org.hisp.dhis.message.MessageConversation messageConversation = messageService.getMessageConversation(mcUid);
if (messageConversation == null) {
responseNode.addChild(new SimpleNode("message", "No messageConversation with uid: " + mcUid));
response.setStatus(HttpServletResponse.SC_NOT_FOUND);
return responseNode;
}
CollectionNode removed = responseNode.addChild(new CollectionNode("removed"));
if (messageConversation.remove(user)) {
messageService.updateMessageConversation(messageConversation);
removed.addChild(new SimpleNode("uid", messageConversation.getUid()));
}
response.setStatus(HttpServletResponse.SC_OK);
return responseNode;
}
use of org.hisp.dhis.node.types.SimpleNode in project dhis2-core by dhis2.
the class MessageConversationController method unmarkMessageConversationFollowup.
// --------------------------------------------------------------------------
// Clear follow up
// --------------------------------------------------------------------------
@PostMapping(value = "unfollowup", produces = { MediaType.APPLICATION_JSON_VALUE, MediaType.APPLICATION_XML_VALUE })
@ResponseBody
public RootNode unmarkMessageConversationFollowup(@RequestParam(value = "user", required = false) String userUid, @RequestBody List<String> uids, HttpServletResponse response, @CurrentUser User currentUser) {
RootNode responseNode = new RootNode("response");
User user = userUid != null ? userService.getUser(userUid) : currentUser;
if (user == null) {
response.setStatus(HttpServletResponse.SC_NOT_FOUND);
responseNode.addChild(new SimpleNode("message", "No user with uid: " + userUid));
return responseNode;
}
if (!canModifyUserConversation(currentUser, user)) {
throw new UpdateAccessDeniedException("Not authorized to modify this object.");
}
Collection<org.hisp.dhis.message.MessageConversation> messageConversations = messageService.getMessageConversations(user, uids);
if (messageConversations.isEmpty()) {
response.setStatus(HttpServletResponse.SC_NOT_FOUND);
responseNode.addChild(new SimpleNode("message", "No MessageConversations found for the given UIDs"));
return responseNode;
}
CollectionNode marked = responseNode.addChild(new CollectionNode("unmarkedFollowup"));
marked.setWrapping(false);
for (org.hisp.dhis.message.MessageConversation conversation : messageConversations) {
if (conversation.isFollowUp()) {
conversation.toggleFollowUp(user);
messageService.updateMessageConversation(conversation);
}
marked.addChild(new SimpleNode("uid", conversation.getUid()));
}
response.setStatus(HttpServletResponse.SC_OK);
return responseNode;
}
Aggregations