Search in sources :

Example 51 with Attribute

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

the class TrackerPreheatServiceIntegration method setUpTest.

@Override
public void setUpTest() throws Exception {
    userService = _userService;
    // Set up placeholder OU; We add Code for testing idScheme.
    OrganisationUnit ouA = createOrganisationUnit('A');
    ouA.setCode("OUA");
    organisationUnitService.addOrganisationUnit(ouA);
    // Set up placeholder TET
    TrackedEntityType tetA = createTrackedEntityType('A');
    tetA.setUid(TET_UID);
    trackedEntityTypeService.addTrackedEntityType(tetA);
    // Set up attribute for program, to be used for testing idScheme.
    Attribute attributeA = createAttribute('A');
    attributeA.setUid(ATTRIBUTE_UID);
    attributeA.setUnique(true);
    attributeA.setProgramAttribute(true);
    attributeService.addAttribute(attributeA);
    // Set up placeholder Program, with attributeValue
    Program programA = createProgram('A');
    programA.addOrganisationUnit(ouA);
    programA.setTrackedEntityType(tetA);
    programA.setProgramType(ProgramType.WITH_REGISTRATION);
    programA.setAttributeValues(Sets.newHashSet(new AttributeValue("PROGRAM1", attributeA)));
    programService.addProgram(programA);
}
Also used : OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) TrackedEntityType(org.hisp.dhis.trackedentity.TrackedEntityType) AttributeValue(org.hisp.dhis.attribute.AttributeValue) Program(org.hisp.dhis.program.Program) Attribute(org.hisp.dhis.attribute.Attribute)

Example 52 with Attribute

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

the class HibernateGenericStore method getAllValuesByAttributes.

@Override
public List<AttributeValue> getAllValuesByAttributes(List<Attribute> attributes) {
    CriteriaBuilder builder = getCriteriaBuilder();
    CriteriaQuery<String> query = builder.createQuery(String.class);
    Root<T> root = query.from(getClazz());
    CriteriaBuilder.Coalesce<String> coalesce = builder.coalesce();
    attributes.stream().forEach(attribute -> coalesce.value(builder.function(FUNCTION_JSONB_EXTRACT_PATH, String.class, root.get("attributeValues"), builder.literal(attribute.getUid()))));
    query.select(coalesce);
    List<Predicate> predicates = attributes.stream().map(attribute -> builder.isNotNull(builder.function(FUNCTION_JSONB_EXTRACT_PATH, String.class, root.get("attributeValues"), builder.literal(attribute.getUid())))).collect(Collectors.toList());
    query.where(builder.or(predicates.toArray(new Predicate[predicates.size()])));
    List<String> result = getSession().createQuery(query).list();
    return convertListJsonToListObject(JsonAttributeValueBinaryType.MAPPER, result, AttributeValue.class);
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) AttributeValue(org.hisp.dhis.attribute.AttributeValue) Criteria(org.hibernate.Criteria) JsonAttributeValueBinaryType(org.hisp.dhis.hibernate.jsonb.type.JsonAttributeValueBinaryType) Session(org.hibernate.Session) Function(java.util.function.Function) TypedQuery(javax.persistence.TypedQuery) ObjectDeletionRequestedEvent(org.hisp.dhis.common.ObjectDeletionRequestedEvent) Attribute(org.hisp.dhis.attribute.Attribute) JdbcTemplate(org.springframework.jdbc.core.JdbcTemplate) GenericStore(org.hisp.dhis.common.GenericStore) NonUniqueResultException(javax.persistence.NonUniqueResultException) Lists(com.google.common.collect.Lists) Predicate(javax.persistence.criteria.Predicate) NativeQuery(org.hibernate.query.NativeQuery) CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) Query(org.hibernate.query.Query) ApplicationEventPublisher(org.springframework.context.ApplicationEventPublisher) Expression(javax.persistence.criteria.Expression) Root(javax.persistence.criteria.Root) AuditLogUtil(org.hisp.dhis.common.AuditLogUtil) IdentifiableObject(org.hisp.dhis.common.IdentifiableObject) CriteriaQuery(javax.persistence.criteria.CriteriaQuery) Preconditions.checkNotNull(com.google.common.base.Preconditions.checkNotNull) SessionFactory(org.hibernate.SessionFactory) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) IOException(java.io.IOException) QueryHints(org.hibernate.annotations.QueryHints) Collectors(java.util.stream.Collectors) List(java.util.List) Slf4j(lombok.extern.slf4j.Slf4j) DetachedCriteria(org.hibernate.criterion.DetachedCriteria) Order(javax.persistence.criteria.Order) Predicate(javax.persistence.criteria.Predicate)

Example 53 with Attribute

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

the class DhisConvenienceTest method createAttribute.

public static Attribute createAttribute(String name, ValueType valueType) {
    Attribute attribute = new Attribute(name, valueType);
    attribute.setAutoFields();
    return attribute;
}
Also used : Attribute(org.hisp.dhis.attribute.Attribute) ProgramTrackedEntityAttribute(org.hisp.dhis.program.ProgramTrackedEntityAttribute) TrackedEntityAttribute(org.hisp.dhis.trackedentity.TrackedEntityAttribute)

Example 54 with Attribute

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

the class OrganisationUnitLocationController method getEntitiesWithinRange.

/**
 * Get Organisation Units within a distance from a location
 */
@GetMapping(value = "/withinRange", produces = { "*/*", APPLICATION_JSON_VALUE })
@ResponseBody
public List<OrganisationUnit> getEntitiesWithinRange(@RequestParam Double longitude, @RequestParam Double latitude, @RequestParam Double distance, @RequestParam(required = false) String orgUnitGroupSetId) {
    List<OrganisationUnit> entityList = new ArrayList<>(organisationUnitService.getOrganisationUnitWithinDistance(longitude, latitude, distance));
    for (OrganisationUnit organisationUnit : entityList) {
        Set<AttributeValue> attributeValues = organisationUnit.getAttributeValues();
        attributeValues.clear();
        if (orgUnitGroupSetId != null) {
            for (OrganisationUnitGroup organisationUnitGroup : organisationUnit.getGroups()) {
                for (OrganisationUnitGroupSet orgunitGroupSet : organisationUnitGroup.getGroupSets()) {
                    if (orgunitGroupSet.getUid().compareTo(orgUnitGroupSetId) == 0) {
                        AttributeValue attributeValue = new AttributeValue();
                        // attributeValue.setAttribute( new Attribute(
                        // ORGUNIGROUP_SYMBOL, ORGUNIGROUP_SYMBOL ) );
                        attributeValue.setAttribute(new Attribute(ORGUNIGROUP_SYMBOL, ValueType.TEXT));
                        attributeValue.setValue(organisationUnitGroup.getSymbol());
                        attributeValues.add(attributeValue);
                    }
                }
            }
        }
        organisationUnit.setAttributeValues(attributeValues);
        // Clear out all data not needed for this task
        organisationUnit.removeAllDataSets();
        organisationUnit.removeAllUsers();
        organisationUnit.removeAllOrganisationUnitGroups();
    }
    return entityList;
}
Also used : OrganisationUnitGroup(org.hisp.dhis.organisationunit.OrganisationUnitGroup) OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) AttributeValue(org.hisp.dhis.attribute.AttributeValue) Attribute(org.hisp.dhis.attribute.Attribute) ArrayList(java.util.ArrayList) OrganisationUnitGroupSet(org.hisp.dhis.organisationunit.OrganisationUnitGroupSet) GetMapping(org.springframework.web.bind.annotation.GetMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 55 with Attribute

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

the class GeoFeatureService method getGeoFeatures.

/**
 * Returns a list of {@link GeoFeature}. Returns null if not modified based
 * on the request.
 *
 * @param parameters the {@link Parameters} passing from controller.
 * @return a list of geo features or null.
 */
public List<GeoFeature> getGeoFeatures(Parameters parameters) {
    Attribute geoJsonAttribute = validateCoordinateField(parameters.getCoordinateField());
    Set<String> dimensionParams = new HashSet<>();
    dimensionParams.add(parameters.getOrganisationUnit());
    dimensionParams.add(parameters.getOrganisationUnitGroupId());
    DataQueryRequest dataQueryRequest = DataQueryRequest.newBuilder().dimension(dimensionParams).aggregationType(AggregationType.SUM).displayProperty(parameters.getDisplayProperty()).relativePeriodDate(parameters.getRelativePeriodDate()).userOrgUnit(parameters.getUserOrgUnit()).apiVersion(parameters.getApiVersion()).build();
    DataQueryParams params = dataQueryService.getFromRequest(dataQueryRequest);
    boolean useOrgUnitGroup = parameters.getOrganisationUnit() == null;
    DimensionalObject dimensionalObject = params.getDimension(useOrgUnitGroup ? ORGUNIT_GROUP_DIM_ID : ORGUNIT_DIM_ID);
    if (dimensionalObject == null) {
        throw new IllegalArgumentException("Dimension is present in query without any valid dimension options");
    }
    List<DimensionalItemObject> dimensionalItemObjects = DimensionalObjectUtils.asTypedList(dimensionalObject.getItems());
    dimensionalItemObjects = dimensionalItemObjects.stream().filter(object -> validateDimensionalItemObject(object, geoJsonAttribute)).collect(Collectors.toList());
    boolean modified = !ContextUtils.clearIfNotModified(parameters.getRequest(), parameters.getResponse(), dimensionalItemObjects);
    if (!modified) {
        return null;
    }
    return getGeoFeatures(params, dimensionalItemObjects, parameters.isIncludeGroupSets(), useOrgUnitGroup, geoJsonAttribute);
}
Also used : DataQueryParams(org.hisp.dhis.analytics.DataQueryParams) DimensionalItemObject(org.hisp.dhis.common.DimensionalItemObject) Attribute(org.hisp.dhis.attribute.Attribute) MultiLineString(org.geojson.MultiLineString) LineString(org.geojson.LineString) DataQueryRequest(org.hisp.dhis.common.DataQueryRequest) HashSet(java.util.HashSet) DimensionalObject(org.hisp.dhis.common.DimensionalObject)

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