use of org.hisp.dhis.node.types.RootNode in project dhis2-core by dhis2.
the class AbstractFullReadOnlyController method getObjectInternal.
@SuppressWarnings("unchecked")
private RootNode getObjectInternal(String uid, Map<String, String> parameters, List<String> filters, List<String> fields, User currentUser) throws Exception {
WebOptions options = new WebOptions(parameters);
List<T> entities = getEntity(uid, options);
if (entities.isEmpty()) {
throw new WebMessageException(notFound(getEntityClass(), uid));
}
Query query = queryService.getQueryFromUrl(getEntityClass(), filters, new ArrayList<>(), getPaginationData(options), options.getRootJunction());
query.setUser(currentUser);
query.setObjects(entities);
query.setDefaults(Defaults.valueOf(options.get("defaults", DEFAULTS)));
entities = (List<T>) queryService.query(query);
handleLinksAndAccess(entities, fields, true);
handleAttributeValues(entities, fields);
for (T entity : entities) {
postProcessResponseEntity(entity, options, parameters);
}
CollectionNode collectionNode = fieldFilterService.toCollectionNode(getEntityClass(), new FieldFilterParams(entities, fields, Defaults.valueOf(options.get("defaults", DEFAULTS))).setUser(currentUser));
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 ResponseHandlerTest method testAddPaginationToNodeWhenPagingIsFalse.
@Test
void testAddPaginationToNodeWhenPagingIsFalse() {
// Given
final RootNode anyRootNode = new RootNode("any");
final Set<Class<? extends BaseIdentifiableObject>> anyTargetEntities = asSet(Indicator.class, DataSet.class);
final Set<String> anyFilters = newHashSet("any");
final User anyUser = new User();
final WebOptions webOptionsNoPaging = mockWebOptionsNoPaging();
// When
responseHandler.addPaginationToNode(anyRootNode, anyTargetEntities, anyUser, webOptionsNoPaging, anyFilters);
// Then
assertThat(anyRootNode, is(notNullValue()));
assertThat(anyRootNode.getName(), is(equalTo("any")));
assertThat(anyRootNode.getChildren(), is(empty()));
verify(linkService, never()).generatePagerLinks(any(Pager.class), anyString());
}
use of org.hisp.dhis.node.types.RootNode in project dhis2-core by dhis2.
the class ResponseHandlerTest method testAddPaginationToNodeWithSuccess.
@Test
void testAddPaginationToNodeWithSuccess() {
// Given
final RootNode anyRootNode = new RootNode("any");
final Set<Class<? extends BaseIdentifiableObject>> anyTargetEntities = asSet(Indicator.class, DataSet.class);
final Set<String> anyFilters = newHashSet("any");
final User anyUser = new User();
final WebOptions anyWebOptions = mockWebOptions(10, 1);
// When
responseHandler.addPaginationToNode(anyRootNode, anyTargetEntities, anyUser, anyWebOptions, anyFilters);
// Then
assertThat(anyRootNode, is(notNullValue()));
assertThat(anyRootNode.getName(), is(equalTo("any")));
assertThat(anyRootNode.getChildren(), hasSize(1));
assertThat(anyRootNode.getChildren().get(0).isMetadata(), is(true));
assertThat(anyRootNode.getChildren().get(0).isComplex(), is(true));
verify(linkService, times(1)).generatePagerLinks(any(Pager.class), anyString());
}
use of org.hisp.dhis.node.types.RootNode in project dhis2-core by dhis2.
the class DimensionItemPageHandlerTest method testAddPaginationToNodeWhenPagingIsFalse.
@Test
void testAddPaginationToNodeWhenPagingIsFalse() {
// Given
final RootNode anyRootNode = new RootNode("any");
final WebOptions webOptionsNoPaging = mockWebOptionsWithPagingFlagFalse();
final String anyUid = "LFsZ8v5v7rq";
final int anyTotals = 12;
// When
dimensionItemPageHandler.addPaginationToNodeIfEnabled(anyRootNode, webOptionsNoPaging, anyUid, anyTotals);
// Then
assertThat(anyRootNode, is(notNullValue()));
assertThat(anyRootNode.getName(), is(equalTo("any")));
assertThat(anyRootNode.getChildren(), is(empty()));
verify(linkService, never()).generatePagerLinks(any(Pager.class), anyString());
}
use of org.hisp.dhis.node.types.RootNode in project dhis2-core by dhis2.
the class DataItemQueryControllerTest method testGetWithSuccess.
@Test
void testGetWithSuccess() {
// Given
final Map<String, String> anyUrlParameters = new HashMap<>();
final OrderParams anyOrderParams = new OrderParams();
final User anyUser = new User();
final Set<Class<? extends BaseIdentifiableObject>> targetEntities = new HashSet<>(singletonList(Indicator.class));
final List<DataItem> itemsFound = singletonList(new DataItem());
// When
when(dataItemServiceFacade.extractTargetEntities(anySet())).thenReturn(targetEntities);
when(aclService.canRead(anyUser, Indicator.class)).thenReturn(true);
when(dataItemServiceFacade.retrieveDataItemEntities(anySet(), anySet(), any(WebOptions.class), any(OrderParams.class))).thenReturn(itemsFound);
final ResponseEntity<RootNode> actualResponse = dataItemQueryController.getJson(anyUrlParameters, anyOrderParams, anyUser);
// Then
assertThat(actualResponse, is(not(nullValue())));
assertThat(actualResponse.getStatusCode(), is(OK));
verify(responseHandler, times(1)).addResultsToNode(any(RootNode.class), anyList(), anySet());
verify(responseHandler, times(1)).addPaginationToNode(any(RootNode.class), anySet(), any(), any(), anySet());
}
Aggregations