Search in sources :

Example 31 with Attribute

use of org.hisp.dhis.attribute.Attribute in project dhis2-core by dhis2.

the class GeoJsonAttributesCheckTest method setUpTest.

@BeforeEach
public void setUpTest() {
    organisationUnit = new OrganisationUnit();
    organisationUnit.setName("A");
    attribute = new Attribute();
    attribute.setUid("geoJson");
    attribute.setName("geoJson");
    validationContext = Mockito.mock(ValidationContext.class);
    Schema schema = new Schema(OrganisationUnit.class, "organisationUnit", "organisationUnits");
    Property property = new Property();
    property.setPersisted(true);
    schema.getPropertyMap().put("attributeValues", property);
    SchemaService schemaService = Mockito.mock(SchemaService.class);
    when(schemaService.getDynamicSchema(OrganisationUnit.class)).thenReturn(schema);
    when(validationContext.getSchemaService()).thenReturn(schemaService);
    Preheat preheat = Mockito.mock(Preheat.class);
    when(preheat.getAttributeIdsByValueType(OrganisationUnit.class, ValueType.GEOJSON)).thenReturn(Sets.newSet("geoJson"));
    objectBundle = Mockito.mock(ObjectBundle.class);
    when(objectBundle.getPreheat()).thenReturn(preheat);
}
Also used : OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) ObjectBundle(org.hisp.dhis.dxf2.metadata.objectbundle.ObjectBundle) Attribute(org.hisp.dhis.attribute.Attribute) SchemaService(org.hisp.dhis.schema.SchemaService) Schema(org.hisp.dhis.schema.Schema) Preheat(org.hisp.dhis.preheat.Preheat) Property(org.hisp.dhis.schema.Property) ValidationContext(org.hisp.dhis.dxf2.metadata.objectbundle.validation.ValidationContext) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 32 with Attribute

use of org.hisp.dhis.attribute.Attribute in project dhis2-core by dhis2.

the class MetadataExportControllerUtilsTest method getWithDependenciesAsDownload.

@Test
void getWithDependenciesAsDownload() {
    final Map<String, List<String>> parameterValuesMap = new HashMap<>();
    final MetadataExportParams exportParams = new MetadataExportParams();
    final Attribute attribute = new Attribute();
    final ObjectNode rootNode = JacksonObjectMapperConfig.jsonMapper.createObjectNode();
    Mockito.when(contextService.getParameterValuesMap()).thenReturn(parameterValuesMap);
    Mockito.when(exportService.getParamsFromMap(Mockito.same(parameterValuesMap))).thenReturn(exportParams);
    Mockito.when(exportService.getMetadataWithDependenciesAsNode(Mockito.same(attribute), Mockito.same(exportParams))).thenReturn(rootNode);
    final ResponseEntity<JsonNode> responseEntity = MetadataExportControllerUtils.getWithDependencies(contextService, exportService, attribute, true);
    Assertions.assertEquals(HttpStatus.OK, responseEntity.getStatusCode());
    Assertions.assertSame(rootNode, responseEntity.getBody());
    Assertions.assertEquals("attachment; filename=metadata", responseEntity.getHeaders().getFirst(HttpHeaders.CONTENT_DISPOSITION));
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) HashMap(java.util.HashMap) MetadataExportParams(org.hisp.dhis.dxf2.metadata.MetadataExportParams) Attribute(org.hisp.dhis.attribute.Attribute) List(java.util.List) JsonNode(com.fasterxml.jackson.databind.JsonNode) Test(org.junit.jupiter.api.Test)

Example 33 with Attribute

use of org.hisp.dhis.attribute.Attribute in project dhis2-core by dhis2.

the class MetadataExportControllerUtilsTest method getWithDependencies.

@Test
void getWithDependencies() {
    final Map<String, List<String>> parameterValuesMap = new HashMap<>();
    final MetadataExportParams exportParams = new MetadataExportParams();
    final Attribute attribute = new Attribute();
    final ObjectNode rootNode = JacksonObjectMapperConfig.jsonMapper.createObjectNode();
    Mockito.when(contextService.getParameterValuesMap()).thenReturn(parameterValuesMap);
    Mockito.when(exportService.getParamsFromMap(Mockito.same(parameterValuesMap))).thenReturn(exportParams);
    Mockito.when(exportService.getMetadataWithDependenciesAsNode(Mockito.same(attribute), Mockito.same(exportParams))).thenReturn(rootNode);
    final ResponseEntity<JsonNode> responseEntity = MetadataExportControllerUtils.getWithDependencies(contextService, exportService, attribute, false);
    Assertions.assertEquals(HttpStatus.OK, responseEntity.getStatusCode());
    Assertions.assertSame(rootNode, responseEntity.getBody());
    Assertions.assertFalse(responseEntity.getHeaders().containsKey(HttpHeaders.CONTENT_DISPOSITION));
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) HashMap(java.util.HashMap) MetadataExportParams(org.hisp.dhis.dxf2.metadata.MetadataExportParams) Attribute(org.hisp.dhis.attribute.Attribute) List(java.util.List) JsonNode(com.fasterxml.jackson.databind.JsonNode) Test(org.junit.jupiter.api.Test)

Example 34 with Attribute

use of org.hisp.dhis.attribute.Attribute in project dhis2-core by dhis2.

the class DataElementStoreTest method testDataElementByUniqueAttributeValue.

@Test
public void testDataElementByUniqueAttributeValue() throws NonUniqueAttributeValueException {
    Attribute attribute = new Attribute("cid", ValueType.TEXT);
    attribute.setDataElementAttribute(true);
    attribute.setUnique(true);
    attributeService.addAttribute(attribute);
    DataElement dataElementA = createDataElement('A');
    DataElement dataElementB = createDataElement('B');
    DataElement dataElementC = createDataElement('C');
    dataElementStore.save(dataElementA);
    dataElementStore.save(dataElementB);
    dataElementStore.save(dataElementC);
    AttributeValue attributeValueA = new AttributeValue("CID1", attribute);
    AttributeValue attributeValueB = new AttributeValue("CID2", attribute);
    AttributeValue attributeValueC = new AttributeValue("CID3", attribute);
    attributeService.addAttributeValue(dataElementA, attributeValueA);
    attributeService.addAttributeValue(dataElementB, attributeValueB);
    attributeService.addAttributeValue(dataElementC, attributeValueC);
    dataElementStore.update(dataElementA);
    dataElementStore.update(dataElementB);
    dataElementStore.update(dataElementC);
    assertNotNull(dataElementStore.getByUniqueAttributeValue(attribute, "CID1"));
    assertNotNull(dataElementStore.getByUniqueAttributeValue(attribute, "CID2"));
    assertNotNull(dataElementStore.getByUniqueAttributeValue(attribute, "CID3"));
    assertNull(dataElementStore.getByUniqueAttributeValue(attribute, "CID4"));
    assertNull(dataElementStore.getByUniqueAttributeValue(attribute, "CID5"));
    assertEquals("DataElementA", dataElementStore.getByUniqueAttributeValue(attribute, "CID1").getName());
    assertEquals("DataElementB", dataElementStore.getByUniqueAttributeValue(attribute, "CID2").getName());
    assertEquals("DataElementC", dataElementStore.getByUniqueAttributeValue(attribute, "CID3").getName());
}
Also used : AttributeValue(org.hisp.dhis.attribute.AttributeValue) Attribute(org.hisp.dhis.attribute.Attribute) Test(org.junit.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Example 35 with Attribute

use of org.hisp.dhis.attribute.Attribute in project dhis2-core by dhis2.

the class DataElementStoreTest method testAttributeValueFromAttribute.

@Test
public void testAttributeValueFromAttribute() throws NonUniqueAttributeValueException {
    Attribute attribute = new Attribute("test", ValueType.TEXT);
    attribute.setDataElementAttribute(true);
    attributeService.addAttribute(attribute);
    DataElement dataElementA = createDataElement('A');
    DataElement dataElementB = createDataElement('B');
    DataElement dataElementC = createDataElement('C');
    dataElementStore.save(dataElementA);
    dataElementStore.save(dataElementB);
    dataElementStore.save(dataElementC);
    AttributeValue attributeValueA = new AttributeValue("SOME VALUE", attribute);
    AttributeValue attributeValueB = new AttributeValue("SOME VALUE", attribute);
    AttributeValue attributeValueC = new AttributeValue("ANOTHER VALUE", attribute);
    attributeService.addAttributeValue(dataElementA, attributeValueA);
    attributeService.addAttributeValue(dataElementB, attributeValueB);
    attributeService.addAttributeValue(dataElementC, attributeValueC);
    dataElementStore.update(dataElementA);
    dataElementStore.update(dataElementB);
    dataElementStore.update(dataElementC);
    List<AttributeValue> values = dataElementStore.getAttributeValueByAttribute(attribute);
    assertEquals(3, values.size());
}
Also used : AttributeValue(org.hisp.dhis.attribute.AttributeValue) Attribute(org.hisp.dhis.attribute.Attribute) Test(org.junit.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Aggregations

Attribute (org.hisp.dhis.attribute.Attribute)56 Test (org.junit.jupiter.api.Test)28 AttributeValue (org.hisp.dhis.attribute.AttributeValue)27 HashMap (java.util.HashMap)13 DhisSpringTest (org.hisp.dhis.DhisSpringTest)10 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)10 List (java.util.List)8 DataElement (org.hisp.dhis.dataelement.DataElement)8 ArrayList (java.util.ArrayList)7 IdentifiableObject (org.hisp.dhis.common.IdentifiableObject)7 Property (org.hisp.dhis.schema.Property)7 Schema (org.hisp.dhis.schema.Schema)7 OrganisationUnitGroup (org.hisp.dhis.organisationunit.OrganisationUnitGroup)6 OrganisationUnitGroupSet (org.hisp.dhis.organisationunit.OrganisationUnitGroupSet)6 Test (org.junit.Test)5 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)4 Lists (com.google.common.collect.Lists)4 HashSet (java.util.HashSet)4 Map (java.util.Map)4 Collectors (java.util.stream.Collectors)4