use of org.hisp.dhis.node.types.RootNode in project dhis2-core by dhis2.
the class AbstractCrudController method getObjectInternal.
@SuppressWarnings("unchecked")
private RootNode getObjectInternal(String uid, Map<String, String> parameters, List<String> filters, List<String> fields, User user) throws Exception {
WebOptions options = new WebOptions(parameters);
List<T> entities = getEntity(uid, options);
if (entities.isEmpty()) {
throw new WebMessageException(WebMessageUtils.notFound(getEntityClass(), uid));
}
Query query = queryService.getQueryFromUrl(getEntityClass(), filters, new ArrayList<>(), options.getRootJunction());
query.setUser(user);
query.setObjects(entities);
entities = (List<T>) queryService.query(query);
handleLinksAndAccess(entities, fields, true, user);
for (T entity : entities) {
postProcessEntity(entity);
postProcessEntity(entity, options, parameters);
}
CollectionNode collectionNode = fieldFilterService.filter(getEntityClass(), entities, fields);
if (options.isTrue("useWrapper") || entities.size() > 1) {
RootNode rootNode = NodeUtils.createMetadata(collectionNode);
rootNode.getConfig().setInclusionStrategy(getInclusionStrategy(parameters.get("inclusionStrategy")));
return rootNode;
} else {
List<Node> children = collectionNode.getChildren();
RootNode rootNode;
if (!children.isEmpty()) {
rootNode = NodeUtils.createRootNode(children.get(0));
} else {
rootNode = NodeUtils.createRootNode(new ComplexNode(getSchema().getSingular()));
}
rootNode.getConfig().setInclusionStrategy(getInclusionStrategy(parameters.get("inclusionStrategy")));
return rootNode;
}
}
use of org.hisp.dhis.node.types.RootNode in project dhis2-core by dhis2.
the class AbstractCrudController method getCollectionItem.
//--------------------------------------------------------------------------
// Identifiable object collections add, delete
//--------------------------------------------------------------------------
@RequestMapping(value = "/{uid}/{property}/{itemId}", method = RequestMethod.GET)
@ResponseBody
public RootNode getCollectionItem(@PathVariable("uid") String pvUid, @PathVariable("property") String pvProperty, @PathVariable("itemId") String pvItemId, @RequestParam Map<String, String> parameters, TranslateParams translateParams, HttpServletRequest request, HttpServletResponse response) throws Exception {
User user = currentUserService.getCurrentUser();
setUserContext(user, translateParams);
if (!aclService.canRead(user, getEntityClass())) {
throw new ReadAccessDeniedException("You don't have the proper permissions to read objects of this type.");
}
RootNode rootNode = getObjectInternal(pvUid, parameters, Lists.newArrayList(), Lists.newArrayList(pvProperty + "[:all]"), user);
// TODO optimize this using field filter (collection filtering)
if (!rootNode.getChildren().isEmpty() && rootNode.getChildren().get(0).isCollection()) {
rootNode.getChildren().get(0).getChildren().stream().filter(Node::isComplex).forEach(node -> {
node.getChildren().stream().filter(child -> child.isSimple() && child.getName().equals("id") && !((SimpleNode) child).getValue().equals(pvItemId)).forEach(child -> rootNode.getChildren().get(0).removeChild(node));
});
}
if (rootNode.getChildren().isEmpty() || rootNode.getChildren().get(0).getChildren().isEmpty()) {
throw new WebMessageException(WebMessageUtils.notFound(pvProperty + " with ID " + pvItemId + " could not be found."));
}
return rootNode;
}
use of org.hisp.dhis.node.types.RootNode in project dhis2-core by dhis2.
the class ValidationResultController method getObjectList.
@GetMapping
@ResponseBody
public RootNode getObjectList(ValidationResultQuery query) {
List<String> fields = Lists.newArrayList(contextService.getParameterValues("fields"));
if (fields.isEmpty()) {
fields.addAll(Preset.ALL.getFields());
}
List<ValidationResult> validationResults = validationResultService.getValidationResults(query);
RootNode rootNode = NodeUtils.createMetadata();
if (!query.isSkipPaging()) {
query.setTotal(validationResultService.countValidationResults(query));
rootNode.addChild(NodeUtils.createPager(query.getPager()));
}
rootNode.addChild(fieldFilterService.filter(ValidationResult.class, validationResults, fields));
return rootNode;
}
use of org.hisp.dhis.node.types.RootNode in project dhis2-core by dhis2.
the class CurrentUserController method getCurrentUser.
@RequestMapping
@ResponseBody
public RootNode getCurrentUser(HttpServletResponse response) throws Exception {
List<String> fields = Lists.newArrayList(contextService.getParameterValues("fields"));
User currentUser = currentUserService.getCurrentUser();
if (currentUser == null) {
throw new NotAuthenticatedException();
}
if (fields.isEmpty()) {
fields.add(":all");
}
CollectionNode collectionNode = fieldFilterService.filter(User.class, Collections.singletonList(currentUser), fields);
RootNode rootNode = new RootNode(collectionNode.getChildren().get(0));
rootNode.setDefaultNamespace(DxfNamespaces.DXF_2_0);
rootNode.setNamespace(DxfNamespaces.DXF_2_0);
return rootNode;
}
use of org.hisp.dhis.node.types.RootNode in project dhis2-core by dhis2.
the class MessageConversationController method setUserAssigned.
//--------------------------------------------------------------------------
// Assign user
//--------------------------------------------------------------------------
@RequestMapping(value = "/{uid}/assign", method = RequestMethod.POST, produces = { MediaType.APPLICATION_JSON_VALUE, MediaType.APPLICATION_XML_VALUE })
@ResponseBody
public RootNode setUserAssigned(@PathVariable String uid, @RequestParam(required = false) String userId, HttpServletResponse response) {
RootNode responseNode = new RootNode("response");
User user = currentUserService.getCurrentUser();
if (!canModifyUserConversation(user, user) && (messageService.hasAccessToManageFeedbackMessages(user))) {
throw new UpdateAccessDeniedException("Not authorized to modify this object.");
}
org.hisp.dhis.message.MessageConversation messageConversation = messageService.getMessageConversation(uid);
if (messageConversation == null) {
response.setStatus(HttpServletResponse.SC_NOT_FOUND);
responseNode.addChild(new SimpleNode("message", "No MessageConversation found for the given ID."));
return responseNode;
}
User userToAssign;
if ((userToAssign = userService.getUser(userId)) == null) {
response.setStatus(HttpServletResponse.SC_NOT_FOUND);
responseNode.addChild(new SimpleNode("message", "Could not find user to assign"));
return responseNode;
}
if (!configurationService.isUserInFeedbackRecipientUserGroup(userToAssign)) {
response.setStatus(HttpServletResponse.SC_CONFLICT);
responseNode.addChild(new SimpleNode("message", "User provided is not a member of the system's feedback recipient group"));
return responseNode;
}
messageConversation.setAssignee(userToAssign);
messageService.updateMessageConversation(messageConversation);
responseNode.addChild(new SimpleNode("message", "User " + userToAssign.getName() + " was assigned to ticket"));
response.setStatus(HttpServletResponse.SC_OK);
return responseNode;
}
Aggregations