use of org.hisp.dhis.node.types.RootNode in project dhis2-core by dhis2.
the class SchemaController method getSchemas.
@RequestMapping
@ResponseBody
public RootNode getSchemas() {
List<String> fields = Lists.newArrayList(contextService.getParameterValues("fields"));
if (fields.isEmpty()) {
fields.add("*");
}
Schemas schemas = new Schemas(schemaService.getSortedSchemas());
linkService.generateSchemaLinks(schemas.getSchemas());
RootNode rootNode = NodeUtils.createRootNode("schemas");
CollectionNode collectionNode = fieldFilterService.filter(Schema.class, schemas.getSchemas(), fields);
collectionNode.setWrapping(false);
rootNode.addChild(collectionNode);
return rootNode;
}
use of org.hisp.dhis.node.types.RootNode 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
//--------------------------------------------------------------------------
@RequestMapping(value = "/{mc-uid}/{user-uid}", method = RequestMethod.DELETE, 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, 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(currentUserService.getCurrentUser(), 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.RootNode in project dhis2-core by dhis2.
the class DataElementOperandController method getObjectList.
@GetMapping
@SuppressWarnings("unchecked")
@ResponseBody
public RootNode getObjectList(@RequestParam Map<String, String> rpParameters, OrderParams orderParams) throws QueryParserException {
Schema schema = schemaService.getDynamicSchema(DataElementOperand.class);
List<String> fields = Lists.newArrayList(contextService.getParameterValues("fields"));
List<String> filters = Lists.newArrayList(contextService.getParameterValues("filter"));
List<Order> orders = orderParams.getOrders(schema);
if (fields.isEmpty()) {
fields.addAll(Preset.ALL.getFields());
}
WebOptions options = new WebOptions(rpParameters);
WebMetadata metadata = new WebMetadata();
List<DataElementOperand> dataElementOperands;
if (options.isTrue("persisted")) {
dataElementOperands = Lists.newArrayList(manager.getAll(DataElementOperand.class));
} else {
boolean totals = options.isTrue("totals");
String deg = CollectionUtils.popStartsWith(filters, "dataElement.dataElementGroups.id:eq:");
deg = deg != null ? deg.substring("dataElement.dataElementGroups.id:eq:".length()) : null;
String ds = options.get("dataSet");
if (deg != null) {
DataElementGroup dataElementGroup = manager.get(DataElementGroup.class, deg);
dataElementOperands = dataElementCategoryService.getOperands(dataElementGroup.getMembers(), totals);
} else if (ds != null) {
DataSet dataSet = manager.get(DataSet.class, ds);
dataElementOperands = dataElementCategoryService.getOperands(dataSet, totals);
} else {
List<DataElement> dataElements = new ArrayList<>(manager.getAllSorted(DataElement.class));
dataElementOperands = dataElementCategoryService.getOperands(dataElements, totals);
}
}
Query query = queryService.getQueryFromUrl(DataElementOperand.class, filters, orders, options.getRootJunction());
query.setDefaultOrder();
query.setObjects(dataElementOperands);
dataElementOperands = (List<DataElementOperand>) queryService.query(query);
Pager pager = metadata.getPager();
if (options.hasPaging() && pager == null) {
pager = new Pager(options.getPage(), dataElementOperands.size(), options.getPageSize());
linkService.generatePagerLinks(pager, DataElementOperand.class);
dataElementOperands = PagerUtils.pageCollection(dataElementOperands, pager);
}
RootNode rootNode = NodeUtils.createMetadata();
if (pager != null) {
rootNode.addChild(NodeUtils.createPager(pager));
}
rootNode.addChild(fieldFilterService.filter(DataElementOperand.class, dataElementOperands, fields));
return rootNode;
}
use of org.hisp.dhis.node.types.RootNode in project dhis2-core by dhis2.
the class AbstractNodeTest method createRootNode.
private RootNode createRootNode(String nodeName, String propertyName, String propertyValue) {
RootNode rootNode = new RootNode(createComplexNode(nodeName));
rootNode.setDefaultNamespace("testNamespace");
rootNode.getConfig().getProperties().put(propertyName, propertyValue);
return rootNode;
}
use of org.hisp.dhis.node.types.RootNode in project dhis2-core by dhis2.
the class AbstractNodeTest method testRootNodeNotEquals.
@Test
void testRootNodeNotEquals() {
final RootNode rootNode1 = createRootNode(NODE_1, "propName1", "propValue1");
final RootNode rootNode2 = createRootNode(NODE_1, "propName2", "propValue2");
assertNotEquals(rootNode1, rootNode2);
}
Aggregations