use of org.hisp.dhis.legend.LegendSet in project dhis2-core by dhis2.
the class LegendSetController method deleteObject.
@Override
@RequestMapping(value = "/{uid}", method = RequestMethod.DELETE)
@PreAuthorize("hasRole('F_GIS_ADMIN') or hasRole('F_LEGEND_SET_DELETE') or hasRole('ALL')")
@ResponseStatus(HttpStatus.NO_CONTENT)
public void deleteObject(@PathVariable String uid, HttpServletRequest request, HttpServletResponse response) throws Exception {
LegendSet legendSet = legendSetService.getLegendSet(uid);
if (legendSet == null) {
throw new WebMessageException(WebMessageUtils.notFound("Legend set does not exist: " + uid));
}
legendSet.getLegends().clear();
legendSetService.deleteLegendSet(legendSet);
}
use of org.hisp.dhis.legend.LegendSet in project dhis2-core by dhis2.
the class QueryItemHelperTest method setUp.
@BeforeEach
void setUp() {
DataElement deA = createDataElement('A');
Option opA = createOption('A');
Option opB = createOption('B');
opA.setUid(UID_A);
opB.setUid(UID_B);
OptionSet os = createOptionSet('A', opA, opB);
Legend lpA = createLegend('A', 0.0, 1.0);
lpA.setCode(LEGEND_CODE_A);
Legend lpB = createLegend('B', 0.0, 1.0);
lpB.setCode(LEGEND_CODE_B);
lpA.setUid(UID_A);
lpB.setUid(UID_B);
LegendSet ls = createLegendSet('A', lpA, lpB);
queryItem = new QueryItem(deA, ls, deA.getValueType(), deA.getAggregationType(), os);
}
use of org.hisp.dhis.legend.LegendSet in project dhis2-core by dhis2.
the class EventQueryParamsTest method testGetItemLegends.
@Test
void testGetItemLegends() {
Legend leA = createLegend('A', 0d, 1d);
Legend leB = createLegend('B', 1d, 2d);
LegendSet lsA = createLegendSet('A', leA, leB);
QueryItem qiA = new QueryItem(deA, lsA, deA.getValueType(), deA.getAggregationType(), null);
EventQueryParams params = new EventQueryParams.Builder().addItem(qiA).build();
Set<Legend> expected = Sets.newHashSet(leA, leB);
assertEquals(expected, params.getItemLegends());
}
use of org.hisp.dhis.legend.LegendSet in project dhis2-core by dhis2.
the class DefaultQueryItemLocator method getQueryItemFromDimension.
@Override
public QueryItem getQueryItemFromDimension(String dimension, Program program, EventOutputType type) {
checkNotNull(program, "Program can not be null");
LegendSet legendSet = getLegendSet(dimension);
return getDataElement(dimension, program, legendSet, type).orElseGet(() -> getTrackedEntityAttribute(dimension, program, legendSet).orElseGet(() -> getProgramIndicator(dimension, program, legendSet).orElseThrow(() -> new IllegalQueryException(new ErrorMessage(ErrorCode.E7224, dimension)))));
}
use of org.hisp.dhis.legend.LegendSet in project dhis2-core by dhis2.
the class QueryItemLocatorTest method verifyDimensionWithLegendSetAndProgramStageReturnsDataElement.
@Test
void verifyDimensionWithLegendSetAndProgramStageReturnsDataElement() {
String legendSetUid = CodeGenerator.generateUid();
DataElement dataElementA = createDataElement('A');
ProgramStage programStageA = createProgramStage('A', programA);
programStageA.setProgramStageDataElements(Sets.newHashSet(createProgramStageDataElement(programStageA, dataElementA, 1)));
programA.setProgramStages(Sets.newHashSet(programStageA));
LegendSet legendSetA = createLegendSet('A');
when(dataElementService.getDataElement(dimension)).thenReturn(dataElementA);
when(legendSetService.getLegendSet(legendSetUid)).thenReturn(legendSetA);
when(programStageService.getProgramStage(programStageUid)).thenReturn(programStageA);
// programStageUid.dimensionUid-legendSetUid
int stageOffset = -1256;
String withStageOffset = "[" + stageOffset + "]";
QueryItem queryItem = subject.getQueryItemFromDimension(programStageUid + withStageOffset + PROGRAMSTAGE_SEP + dimension + ITEM_SEP + legendSetUid, programA, EventOutputType.ENROLLMENT);
assertThat(queryItem, is(notNullValue()));
assertThat(queryItem.getItem(), is(dataElementA));
assertThat(queryItem.getProgram(), is(programA));
assertThat(queryItem.getProgramStage(), is(programStageA));
assertThat(queryItem.getLegendSet(), is(legendSetA));
assertThat(queryItem.getProgramStageOffset(), is(stageOffset));
verifyNoMoreInteractions(attributeService);
verifyNoMoreInteractions(programIndicatorService);
}
Aggregations