Search in sources :

Example 16 with Term

use of org.commongeoregistry.adapter.Term in project geoprism-registry by terraframe.

the class AttributeTypeConverter method build.

public AttributeType build(MdAttributeConcreteDAOIF mdAttribute) {
    Locale locale = Session.getCurrentLocale();
    String attributeName = mdAttribute.definesAttribute();
    LocalizedValue displayLabel = AttributeTypeConverter.convert(mdAttribute.getDisplayLabel(locale), mdAttribute.getDisplayLabels());
    LocalizedValue description = AttributeTypeConverter.convert(mdAttribute.getDescription(locale), mdAttribute.getDescriptions());
    boolean required = mdAttribute.isRequired();
    boolean unique = mdAttribute.isUnique();
    boolean isChangeOverTime = true;
    DefaultAttribute defaultAttr = DefaultAttribute.getByAttributeName(attributeName);
    if (defaultAttr != null) {
        isChangeOverTime = defaultAttr.isChangeOverTime();
    }
    if (mdAttribute instanceof MdAttributeBooleanDAOIF) {
        return AttributeType.factory(attributeName, displayLabel, description, AttributeBooleanType.TYPE, required, unique, isChangeOverTime);
    } else if (mdAttribute instanceof MdAttributeLocalDAOIF) {
        return AttributeType.factory(attributeName, displayLabel, description, AttributeLocalType.TYPE, required, unique, isChangeOverTime);
    } else if (mdAttribute instanceof MdAttributeCharacterDAOIF) {
        return AttributeType.factory(attributeName, displayLabel, description, AttributeCharacterType.TYPE, required, unique, isChangeOverTime);
    } else if (mdAttribute instanceof MdAttributeDateDAOIF || mdAttribute instanceof MdAttributeDateTimeDAOIF) {
        return AttributeType.factory(attributeName, displayLabel, description, AttributeDateType.TYPE, required, unique, isChangeOverTime);
    } else if (mdAttribute instanceof MdAttributeDecDAOIF) {
        MdAttributeDecDAOIF mdAttributeDec = (MdAttributeDecDAOIF) mdAttribute;
        AttributeFloatType attributeType = (AttributeFloatType) AttributeType.factory(attributeName, displayLabel, description, AttributeFloatType.TYPE, required, unique, isChangeOverTime);
        attributeType.setPrecision(Integer.parseInt(mdAttributeDec.getLength()));
        attributeType.setScale(Integer.parseInt(mdAttributeDec.getDecimal()));
        return attributeType;
    } else if (mdAttribute instanceof MdAttributeIntegerDAOIF || mdAttribute instanceof MdAttributeLongDAOIF) {
        return AttributeType.factory(attributeName, displayLabel, description, AttributeIntegerType.TYPE, required, unique, isChangeOverTime);
    } else if (mdAttribute instanceof MdAttributeClassificationDAOIF) {
        MdClassificationDAOIF mdClassification = ((MdAttributeClassificationDAOIF) mdAttribute).getMdClassificationDAOIF();
        AttributeClassificationType attributeType = (AttributeClassificationType) AttributeType.factory(attributeName, displayLabel, description, AttributeClassificationType.TYPE, required, unique, isChangeOverTime);
        attributeType.setClassificationType(mdClassification.getValue(MdClassificationInfo.TYPE_NAME));
        String rootOid = ((MdAttributeClassificationDAOIF) mdAttribute).getValue(MdAttributeClassificationInfo.ROOT);
        if (rootOid != null && rootOid.length() > 0) {
            ClassificationType type = new ClassificationType(mdClassification);
            Classification classification = Classification.getByOid(type, rootOid);
            attributeType.setRootTerm(classification.toTerm());
        }
        return attributeType;
    } else if (mdAttribute instanceof MdAttributeEnumerationDAOIF || mdAttribute instanceof MdAttributeTermDAOIF) {
        AttributeTermType attributeType = (AttributeTermType) AttributeType.factory(attributeName, displayLabel, description, AttributeTermType.TYPE, required, unique, isChangeOverTime);
        if (mdAttribute instanceof MdAttributeTermDAOIF) {
            List<RelationshipDAOIF> rels = ((MdAttributeTermDAOIF) mdAttribute).getAllAttributeRoots();
            if (rels.size() > 0) {
                RelationshipDAOIF rel = rels.get(0);
                BusinessDAO classy = (BusinessDAO) rel.getChild();
                TermConverter termBuilder = new TermConverter(classy.getKey());
                Term adapterTerm = termBuilder.build();
                attributeType.setRootTerm(adapterTerm);
            } else {
                throw new ProgrammingErrorException("Expected an attribute root on MdAttribute [" + mdAttribute.getKey() + "].");
            }
        } else {
            throw new ProgrammingErrorException("Enum attributes are not supported at this time.");
        }
        return attributeType;
    }
    throw new UnsupportedOperationException("Unsupported attribute type [" + mdAttribute.getClass().getSimpleName() + "]");
}
Also used : Locale(java.util.Locale) AttributeFloatType(org.commongeoregistry.adapter.metadata.AttributeFloatType) MdClassificationDAOIF(com.runwaysdk.dataaccess.MdClassificationDAOIF) RelationshipDAOIF(com.runwaysdk.dataaccess.RelationshipDAOIF) LocalizedValue(org.commongeoregistry.adapter.dataaccess.LocalizedValue) MdAttributeEnumerationDAOIF(com.runwaysdk.dataaccess.MdAttributeEnumerationDAOIF) MdAttributeLongDAOIF(com.runwaysdk.dataaccess.MdAttributeLongDAOIF) MdAttributeIntegerDAOIF(com.runwaysdk.dataaccess.MdAttributeIntegerDAOIF) Classification(net.geoprism.registry.model.Classification) MdAttributeTermDAOIF(com.runwaysdk.dataaccess.MdAttributeTermDAOIF) List(java.util.List) MdAttributeBooleanDAOIF(com.runwaysdk.dataaccess.MdAttributeBooleanDAOIF) BusinessDAO(com.runwaysdk.dataaccess.BusinessDAO) MdAttributeDateTimeDAOIF(com.runwaysdk.dataaccess.MdAttributeDateTimeDAOIF) Term(org.commongeoregistry.adapter.Term) AttributeClassificationType(org.commongeoregistry.adapter.metadata.AttributeClassificationType) AttributeClassificationType(org.commongeoregistry.adapter.metadata.AttributeClassificationType) ClassificationType(net.geoprism.registry.model.ClassificationType) ProgrammingErrorException(com.runwaysdk.dataaccess.ProgrammingErrorException) MdAttributeLocalDAOIF(com.runwaysdk.dataaccess.MdAttributeLocalDAOIF) MdAttributeDecDAOIF(com.runwaysdk.dataaccess.MdAttributeDecDAOIF) DefaultAttribute(org.commongeoregistry.adapter.constants.DefaultAttribute) MdAttributeClassificationDAOIF(com.runwaysdk.dataaccess.MdAttributeClassificationDAOIF) MdAttributeDateDAOIF(com.runwaysdk.dataaccess.MdAttributeDateDAOIF) AttributeTermType(org.commongeoregistry.adapter.metadata.AttributeTermType) MdAttributeCharacterDAOIF(com.runwaysdk.dataaccess.MdAttributeCharacterDAOIF)

Example 17 with Term

use of org.commongeoregistry.adapter.Term in project geoprism-registry by terraframe.

the class TermConverter method buildTermFromClassifier.

private Term buildTermFromClassifier(Classifier classifier) {
    LocalizedValue label = AttributeTypeConverter.convert(classifier.getDisplayLabel());
    Term term = new Term(classifier.getClassifierId(), label, new LocalizedValue(""));
    OIterator<? extends net.geoprism.ontology.Classifier> childClassifiers = classifier.getAllIsAChild();
    childClassifiers.forEach(c -> term.addChild(this.buildTermFromClassifier(c)));
    return term;
}
Also used : LocalizedValue(org.commongeoregistry.adapter.dataaccess.LocalizedValue) Term(org.commongeoregistry.adapter.Term) MdAttributeTerm(com.runwaysdk.system.metadata.MdAttributeTerm) MdAttributeMultiTerm(com.runwaysdk.system.metadata.MdAttributeMultiTerm)

Example 18 with Term

use of org.commongeoregistry.adapter.Term in project geoprism-registry by terraframe.

the class VertexTermConverter method buildTermFromClassifier.

private Term buildTermFromClassifier(VertexObject classification) {
    LocalizedValue label = AttributeTypeConverter.convert(classification.getEmbeddedComponent(AbstractClassification.DISPLAYLABEL));
    Term term = new Term(classification.getObjectValue(AbstractClassification.CODE), label, new LocalizedValue(""));
    return term;
}
Also used : LocalizedValue(org.commongeoregistry.adapter.dataaccess.LocalizedValue) Term(org.commongeoregistry.adapter.Term)

Example 19 with Term

use of org.commongeoregistry.adapter.Term in project geoprism-registry by terraframe.

the class DHIS2FeatureService method getDHIS2AttributeConfiguration.

@Request(RequestType.SESSION)
public JsonArray getDHIS2AttributeConfiguration(String sessionId, String dhis2SystemOid, String geoObjectTypeCode) {
    DHIS2ExternalSystem system = DHIS2ExternalSystem.get(dhis2SystemOid);
    JsonArray response = new JsonArray();
    ServerGeoObjectType got = ServerGeoObjectType.get(geoObjectTypeCode);
    Map<String, AttributeType> cgrAttrs = got.getAttributeMap();
    DHIS2TransportServiceIF dhis2;
    try {
        dhis2 = DHIS2ServiceFactory.buildDhis2TransportService(system);
    } catch (InvalidLoginException e) {
        LoginException cgrlogin = new LoginException(e);
        throw cgrlogin;
    } catch (HTTPException | UnexpectedResponseException | BadServerUriException | IllegalArgumentException e) {
        HttpError cgrhttp = new HttpError(e);
        throw cgrhttp;
    }
    final DHIS2OptionCache optionCache = new DHIS2OptionCache(dhis2);
    List<Attribute> dhis2Attrs = getDHIS2Attributes(dhis2);
    final String[] skipAttrs = new String[] { DefaultAttribute.GEOMETRY.getName(), DefaultAttribute.SEQUENCE.getName(), DefaultAttribute.TYPE.getName() };
    for (AttributeType cgrAttr : cgrAttrs.values()) {
        if (!ArrayUtils.contains(skipAttrs, cgrAttr.getName())) {
            JsonObject joAttr = new JsonObject();
            JsonObject joCgrAttr = new JsonObject();
            joCgrAttr.addProperty("name", cgrAttr.getName());
            joCgrAttr.addProperty("label", cgrAttr.getLabel().getValue());
            joCgrAttr.addProperty("type", cgrAttr.getType());
            joCgrAttr.addProperty("typeLabel", AttributeTypeMetadata.get().getTypeEnumDisplayLabel(cgrAttr.getType()));
            joAttr.add("cgrAttr", joCgrAttr);
            JsonArray jaStrategies = new JsonArray();
            List<DHIS2AttributeMapping> strategies = this.getMappingStrategies(cgrAttr);
            for (DHIS2AttributeMapping strategy : strategies) {
                jaStrategies.add(strategy.getClass().getName());
            }
            joAttr.add("attributeMappingStrategies", jaStrategies);
            JsonArray jaDhis2Attrs = new JsonArray();
            for (Attribute dhis2Attr : dhis2Attrs) {
                if (!dhis2Attr.getOrganisationUnitAttribute()) {
                    continue;
                }
                boolean valid = false;
                JsonObject jo = new JsonObject();
                if (cgrAttr instanceof AttributeBooleanType && dhis2Attr.getOptionSetId() == null && (dhis2Attr.getValueType().equals(ValueType.BOOLEAN) || dhis2Attr.getValueType().equals(ValueType.TRUE_ONLY))) {
                    valid = true;
                } else if (cgrAttr instanceof AttributeIntegerType && dhis2Attr.getOptionSetId() == null && (dhis2Attr.getValueType().equals(ValueType.INTEGER) || dhis2Attr.getValueType().equals(ValueType.INTEGER_POSITIVE) || dhis2Attr.getValueType().equals(ValueType.INTEGER_NEGATIVE) || dhis2Attr.getValueType().equals(ValueType.INTEGER_ZERO_OR_POSITIVE))) {
                    valid = true;
                } else if (cgrAttr instanceof AttributeFloatType && dhis2Attr.getOptionSetId() == null && (dhis2Attr.getValueType().equals(ValueType.NUMBER) || dhis2Attr.getValueType().equals(ValueType.UNIT_INTERVAL) || dhis2Attr.getValueType().equals(ValueType.PERCENTAGE))) {
                    valid = true;
                } else if (cgrAttr instanceof AttributeDateType && dhis2Attr.getOptionSetId() == null && (dhis2Attr.getValueType().equals(ValueType.DATE) || dhis2Attr.getValueType().equals(ValueType.DATETIME) || dhis2Attr.getValueType().equals(ValueType.TIME) || dhis2Attr.getValueType().equals(ValueType.AGE))) {
                    valid = true;
                } else if (cgrAttr instanceof AttributeTermType && dhis2Attr.getOptionSetId() != null) {
                    valid = true;
                    JsonArray jaDhis2Options = new JsonArray();
                    IntegratedOptionSet set = optionCache.getOptionSet(dhis2Attr.getOptionSetId());
                    SortedSet<Option> options = set.getOptions();
                    for (Option option : options) {
                        JsonObject joDhis2Option = new JsonObject();
                        joDhis2Option.addProperty("code", option.getCode());
                        joDhis2Option.addProperty("name", option.getName());
                        joDhis2Option.addProperty("id", option.getName());
                        jaDhis2Options.add(joDhis2Option);
                    }
                    jo.add("options", jaDhis2Options);
                } else if ((cgrAttr instanceof AttributeCharacterType || cgrAttr instanceof AttributeLocalType) && dhis2Attr.getOptionSetId() == null && (dhis2Attr.getValueType().equals(ValueType.TEXT) || dhis2Attr.getValueType().equals(ValueType.LONG_TEXT) || dhis2Attr.getValueType().equals(ValueType.LETTER) || dhis2Attr.getValueType().equals(ValueType.PHONE_NUMBER) || dhis2Attr.getValueType().equals(ValueType.EMAIL) || dhis2Attr.getValueType().equals(ValueType.USERNAME) || dhis2Attr.getValueType().equals(ValueType.URL))) {
                    valid = true;
                }
                if (valid) {
                    jo.addProperty("dhis2Id", dhis2Attr.getId());
                    jo.addProperty("code", dhis2Attr.getCode());
                    jo.addProperty("name", dhis2Attr.getName());
                    jaDhis2Attrs.add(jo);
                }
            }
            joAttr.add("dhis2Attrs", jaDhis2Attrs);
            if (cgrAttr instanceof AttributeTermType) {
                JsonArray terms = new JsonArray();
                List<Term> children = ((AttributeTermType) cgrAttr).getTerms();
                for (Term child : children) {
                    JsonObject joTerm = new JsonObject();
                    joTerm.addProperty("label", child.getLabel().getValue());
                    joTerm.addProperty("code", child.getCode());
                    terms.add(joTerm);
                }
                joAttr.add("terms", terms);
            }
            response.add(joAttr);
        }
    }
    return response;
}
Also used : HTTPException(net.geoprism.dhis2.dhis2adapter.exception.HTTPException) AttributeIntegerType(org.commongeoregistry.adapter.metadata.AttributeIntegerType) Attribute(net.geoprism.dhis2.dhis2adapter.response.model.Attribute) DefaultAttribute(org.commongeoregistry.adapter.constants.DefaultAttribute) JsonObject(com.google.gson.JsonObject) DHIS2AttributeMapping(net.geoprism.registry.etl.DHIS2AttributeMapping) AttributeFloatType(org.commongeoregistry.adapter.metadata.AttributeFloatType) AttributeDateType(org.commongeoregistry.adapter.metadata.AttributeDateType) AttributeType(org.commongeoregistry.adapter.metadata.AttributeType) AttributeBooleanType(org.commongeoregistry.adapter.metadata.AttributeBooleanType) DHIS2TransportServiceIF(net.geoprism.registry.etl.export.dhis2.DHIS2TransportServiceIF) DHIS2ExternalSystem(net.geoprism.registry.graph.DHIS2ExternalSystem) ServerGeoObjectType(net.geoprism.registry.model.ServerGeoObjectType) Term(org.commongeoregistry.adapter.Term) BadServerUriException(net.geoprism.dhis2.dhis2adapter.exception.BadServerUriException) IntegratedOptionSet(net.geoprism.registry.etl.export.dhis2.DHIS2OptionCache.IntegratedOptionSet) JsonArray(com.google.gson.JsonArray) DHIS2OptionCache(net.geoprism.registry.etl.export.dhis2.DHIS2OptionCache) AttributeLocalType(org.commongeoregistry.adapter.metadata.AttributeLocalType) InvalidLoginException(net.geoprism.dhis2.dhis2adapter.exception.InvalidLoginException) LoginException(net.geoprism.registry.etl.export.LoginException) InvalidLoginException(net.geoprism.dhis2.dhis2adapter.exception.InvalidLoginException) UnexpectedResponseException(net.geoprism.dhis2.dhis2adapter.exception.UnexpectedResponseException) Option(net.geoprism.dhis2.dhis2adapter.response.model.Option) HttpError(net.geoprism.registry.etl.export.HttpError) AttributeTermType(org.commongeoregistry.adapter.metadata.AttributeTermType) AttributeCharacterType(org.commongeoregistry.adapter.metadata.AttributeCharacterType) Request(com.runwaysdk.session.Request)

Example 20 with Term

use of org.commongeoregistry.adapter.Term in project geoprism-registry by terraframe.

the class GeoObjectUtil method convertToTermString.

@SuppressWarnings("unchecked")
public static String convertToTermString(AttributeTermType attributeType, Object value) {
    StringBuilder builder = new StringBuilder();
    boolean first = true;
    if (value instanceof Classifier) {
        if (!first) {
            builder.append(",");
        }
        builder.append(((Classifier) value).getDisplayLabel().getValue());
        first = false;
    } else {
        Iterator<String> codes = (Iterator<String>) value;
        if (codes != null) {
            while (codes.hasNext()) {
                String code = codes.next();
                Term term = attributeType.getTermByCode(code).get();
                if (!first) {
                    builder.append(",");
                }
                builder.append(term.getLabel());
                first = false;
            }
            return builder.toString();
        }
    }
    return null;
}
Also used : Iterator(java.util.Iterator) Classifier(net.geoprism.ontology.Classifier) Term(org.commongeoregistry.adapter.Term)

Aggregations

Term (org.commongeoregistry.adapter.Term)25 AttributeTermType (org.commongeoregistry.adapter.metadata.AttributeTermType)16 Classifier (net.geoprism.ontology.Classifier)14 LocalizedValue (org.commongeoregistry.adapter.dataaccess.LocalizedValue)14 AttributeClassificationType (org.commongeoregistry.adapter.metadata.AttributeClassificationType)11 JsonObject (com.google.gson.JsonObject)8 AttributeType (org.commongeoregistry.adapter.metadata.AttributeType)8 MdAttributeTerm (com.runwaysdk.system.metadata.MdAttributeTerm)7 ServerGeoObjectType (net.geoprism.registry.model.ServerGeoObjectType)7 Classification (net.geoprism.registry.model.Classification)6 AttributeFloatType (org.commongeoregistry.adapter.metadata.AttributeFloatType)6 MdAttributeTermDAOIF (com.runwaysdk.dataaccess.MdAttributeTermDAOIF)4 MdAttributeConcrete (com.runwaysdk.system.metadata.MdAttributeConcrete)4 Iterator (java.util.Iterator)4 AttributeBooleanType (org.commongeoregistry.adapter.metadata.AttributeBooleanType)4 AttributeDateType (org.commongeoregistry.adapter.metadata.AttributeDateType)4 VertexObject (com.runwaysdk.business.graph.VertexObject)3 Request (com.runwaysdk.session.Request)3 Geometry (com.vividsolutions.jts.geom.Geometry)3 LinkedList (java.util.LinkedList)3