Search in sources :

Example 16 with LegendSet

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);
}
Also used : WebMessageException(org.hisp.dhis.dxf2.webmessage.WebMessageException) LegendSet(org.hisp.dhis.legend.LegendSet) ResponseStatus(org.springframework.web.bind.annotation.ResponseStatus) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 17 with 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);
}
Also used : DataElement(org.hisp.dhis.dataelement.DataElement) QueryItem(org.hisp.dhis.common.QueryItem) Legend(org.hisp.dhis.legend.Legend) Option(org.hisp.dhis.option.Option) LegendSet(org.hisp.dhis.legend.LegendSet) OptionSet(org.hisp.dhis.option.OptionSet) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 18 with LegendSet

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());
}
Also used : QueryItem(org.hisp.dhis.common.QueryItem) Legend(org.hisp.dhis.legend.Legend) LegendSet(org.hisp.dhis.legend.LegendSet) Test(org.junit.jupiter.api.Test) DhisConvenienceTest(org.hisp.dhis.DhisConvenienceTest)

Example 19 with LegendSet

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)))));
}
Also used : LegendSet(org.hisp.dhis.legend.LegendSet) IllegalQueryException(org.hisp.dhis.common.IllegalQueryException) ErrorMessage(org.hisp.dhis.feedback.ErrorMessage)

Example 20 with LegendSet

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);
}
Also used : DhisConvenienceTest.createProgramStageDataElement(org.hisp.dhis.DhisConvenienceTest.createProgramStageDataElement) DataElement(org.hisp.dhis.dataelement.DataElement) DhisConvenienceTest.createDataElement(org.hisp.dhis.DhisConvenienceTest.createDataElement) QueryItem(org.hisp.dhis.common.QueryItem) LegendSet(org.hisp.dhis.legend.LegendSet) DhisConvenienceTest.createLegendSet(org.hisp.dhis.DhisConvenienceTest.createLegendSet) DhisConvenienceTest.createProgramStage(org.hisp.dhis.DhisConvenienceTest.createProgramStage) ProgramStage(org.hisp.dhis.program.ProgramStage) Test(org.junit.jupiter.api.Test)

Aggregations

LegendSet (org.hisp.dhis.legend.LegendSet)24 Test (org.junit.jupiter.api.Test)10 DataElement (org.hisp.dhis.dataelement.DataElement)8 QueryItem (org.hisp.dhis.common.QueryItem)4 Legend (org.hisp.dhis.legend.Legend)4 ProgramStage (org.hisp.dhis.program.ProgramStage)4 DhisSpringTest (org.hisp.dhis.DhisSpringTest)3 TrackedEntityAttribute (org.hisp.dhis.trackedentity.TrackedEntityAttribute)3 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)3 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)3 ResponseStatus (org.springframework.web.bind.annotation.ResponseStatus)3 List (java.util.List)2 DhisConvenienceTest.createDataElement (org.hisp.dhis.DhisConvenienceTest.createDataElement)2 DhisConvenienceTest.createLegendSet (org.hisp.dhis.DhisConvenienceTest.createLegendSet)2 DhisConvenienceTest.createProgramStage (org.hisp.dhis.DhisConvenienceTest.createProgramStage)2 DhisConvenienceTest.createProgramStageDataElement (org.hisp.dhis.DhisConvenienceTest.createProgramStageDataElement)2 IdentifiableObject (org.hisp.dhis.common.IdentifiableObject)2 Dashboard (org.hisp.dhis.dashboard.Dashboard)2 ObjectBundleValidationReport (org.hisp.dhis.dxf2.metadata.objectbundle.feedback.ObjectBundleValidationReport)2 WebMessageException (org.hisp.dhis.dxf2.webmessage.WebMessageException)2