Search in sources :

Example 6 with Term

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

the class ServerGeoObjectType method createMdAttributeFromAttributeType.

public static MdAttributeConcrete createMdAttributeFromAttributeType(MdClass mdClass, AttributeType attributeType) {
    MdAttributeConcrete mdAttribute = null;
    if (attributeType.getType().equals(AttributeCharacterType.TYPE)) {
        mdAttribute = new MdAttributeCharacter();
        MdAttributeCharacter mdAttributeCharacter = (MdAttributeCharacter) mdAttribute;
        mdAttributeCharacter.setDatabaseSize(MdAttributeCharacterInfo.MAX_CHARACTER_SIZE);
    } else if (attributeType.getType().equals(AttributeDateType.TYPE)) {
        mdAttribute = new MdAttributeDateTime();
    } else if (attributeType.getType().equals(AttributeIntegerType.TYPE)) {
        mdAttribute = new MdAttributeLong();
    } else if (attributeType.getType().equals(AttributeFloatType.TYPE)) {
        AttributeFloatType attributeFloatType = (AttributeFloatType) attributeType;
        mdAttribute = new MdAttributeDouble();
        mdAttribute.setValue(MdAttributeDoubleInfo.LENGTH, Integer.toString(attributeFloatType.getPrecision()));
        mdAttribute.setValue(MdAttributeDoubleInfo.DECIMAL, Integer.toString(attributeFloatType.getScale()));
    } else if (attributeType.getType().equals(AttributeTermType.TYPE)) {
        mdAttribute = new MdAttributeTerm();
        MdAttributeTerm mdAttributeTerm = (MdAttributeTerm) mdAttribute;
        MdBusiness classifierMdBusiness = MdBusiness.getMdBusiness(Classifier.CLASS);
        mdAttributeTerm.setMdBusiness(classifierMdBusiness);
    // TODO implement support for multi-term
    // mdAttribute = new MdAttributeMultiTerm();
    // MdAttributeMultiTerm mdAttributeMultiTerm =
    // (MdAttributeMultiTerm)mdAttribute;
    // 
    // MdBusiness classifierMdBusiness =
    // MdBusiness.getMdBusiness(Classifier.CLASS);
    // mdAttributeMultiTerm.setMdBusiness(classifierMdBusiness);
    } else if (attributeType.getType().equals(AttributeClassificationType.TYPE)) {
        AttributeClassificationType attributeClassificationType = (AttributeClassificationType) attributeType;
        String classificationTypeCode = attributeClassificationType.getClassificationType();
        ClassificationType classificationType = ClassificationType.getByCode(classificationTypeCode);
        mdAttribute = new MdAttributeClassification();
        MdAttributeClassification mdAttributeTerm = (MdAttributeClassification) mdAttribute;
        mdAttributeTerm.setReferenceMdClassification(classificationType.getMdClassificationObject());
        Term root = attributeClassificationType.getRootTerm();
        if (root != null) {
            Classification classification = Classification.get(classificationType, root.getCode());
            if (classification == null) {
                net.geoprism.registry.DataNotFoundException ex = new net.geoprism.registry.DataNotFoundException();
                ex.setTypeLabel(classificationType.getDisplayLabel().getValue());
                ex.setDataIdentifier(root.getCode());
                ex.setAttributeLabel(GeoObjectMetadata.get().getAttributeDisplayLabel(DefaultAttribute.CODE.getName()));
                throw ex;
            }
            mdAttributeTerm.setValue(MdAttributeClassification.ROOT, classification.getOid());
        }
    } else if (attributeType.getType().equals(AttributeBooleanType.TYPE)) {
        mdAttribute = new MdAttributeBoolean();
    }
    mdAttribute.setAttributeName(attributeType.getName());
    mdAttribute.setValue(MdAttributeConcreteInfo.REQUIRED, Boolean.toString(attributeType.isRequired()));
    if (attributeType.isUnique()) {
        mdAttribute.addIndexType(MdAttributeIndices.UNIQUE_INDEX);
    }
    LocalizedValueConverter.populate(mdAttribute.getDisplayLabel(), attributeType.getLabel());
    LocalizedValueConverter.populate(mdAttribute.getDescription(), attributeType.getDescription());
    mdAttribute.setDefiningMdClass(mdClass);
    mdAttribute.apply();
    if (attributeType.getType().equals(AttributeTermType.TYPE)) {
        MdAttributeTerm mdAttributeTerm = (MdAttributeTerm) mdAttribute;
        // Build the parent class term root if it does not exist.
        Classifier classTerm = TermConverter.buildIfNotExistdMdBusinessClassifier(mdClass);
        // Create the root term node for this attribute
        Classifier attributeTermRoot = TermConverter.buildIfNotExistAttribute(mdClass, mdAttributeTerm.getAttributeName(), classTerm);
        // Make this the root term of the multi-attribute
        attributeTermRoot.addClassifierTermAttributeRoots(mdAttributeTerm).apply();
        AttributeTermType attributeTermType = (AttributeTermType) attributeType;
        LocalizedValue label = LocalizedValueConverter.convert(attributeTermRoot.getDisplayLabel());
        org.commongeoregistry.adapter.Term term = new org.commongeoregistry.adapter.Term(attributeTermRoot.getClassifierId(), label, new LocalizedValue(""));
        attributeTermType.setRootTerm(term);
    }
    return mdAttribute;
}
Also used : DataNotFoundException(com.runwaysdk.dataaccess.cache.DataNotFoundException) MdAttributeDateTime(com.runwaysdk.system.metadata.MdAttributeDateTime) MdBusiness(com.runwaysdk.system.metadata.MdBusiness) Classifier(net.geoprism.ontology.Classifier) AttributeFloatType(org.commongeoregistry.adapter.metadata.AttributeFloatType) MdAttributeTerm(com.runwaysdk.system.metadata.MdAttributeTerm) LocalizedValue(org.commongeoregistry.adapter.dataaccess.LocalizedValue) MdAttributeClassification(com.runwaysdk.system.metadata.MdAttributeClassification) MdAttributeConcrete(com.runwaysdk.system.metadata.MdAttributeConcrete) MdAttributeLong(com.runwaysdk.system.metadata.MdAttributeLong) MdAttributeClassification(com.runwaysdk.system.metadata.MdAttributeClassification) MdAttributeCharacter(com.runwaysdk.system.metadata.MdAttributeCharacter) Term(org.commongeoregistry.adapter.Term) MdAttributeTerm(com.runwaysdk.system.metadata.MdAttributeTerm) Term(org.commongeoregistry.adapter.Term) AttributeClassificationType(org.commongeoregistry.adapter.metadata.AttributeClassificationType) AttributeClassificationType(org.commongeoregistry.adapter.metadata.AttributeClassificationType) MdAttributeBoolean(com.runwaysdk.system.metadata.MdAttributeBoolean) MdAttributeDouble(com.runwaysdk.system.metadata.MdAttributeDouble) AttributeTermType(org.commongeoregistry.adapter.metadata.AttributeTermType)

Example 7 with Term

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

the class ServerGeoObjectType method findHierarchy.

/**
 * Finds the actual hierarchy used for the parent type if the parent type is
 * inherited from a different hierarchy
 *
 * @param hierarchyType
 * @param parent
 * @return
 */
public ServerHierarchyType findHierarchy(ServerHierarchyType hierarchyType, ServerGeoObjectType parent) {
    Collection<com.runwaysdk.business.ontology.Term> list = GeoEntityUtil.getOrderedAncestors(Universal.getRoot(), this.getUniversal(), hierarchyType.getUniversalType());
    for (Object term : list) {
        Universal universal = (Universal) term;
        if (parent.getUniversal().getOid().equals(universal.getOid())) {
            return hierarchyType;
        }
        ServerGeoObjectType sParent = ServerGeoObjectType.get(universal);
        if (sParent.isRoot(hierarchyType)) {
            ServerHierarchyType inheritedHierarchy = sParent.getInheritedHierarchy(hierarchyType);
            if (inheritedHierarchy != null) {
                return sParent.findHierarchy(inheritedHierarchy, parent);
            }
        }
    }
    return hierarchyType;
}
Also used : Universal(com.runwaysdk.system.gis.geo.Universal) JsonObject(com.google.gson.JsonObject) MdAttributeTerm(com.runwaysdk.system.metadata.MdAttributeTerm) Term(org.commongeoregistry.adapter.Term)

Example 8 with Term

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

the class VertexServerGeoObject method populate.

@SuppressWarnings("unchecked")
@Override
public void populate(GeoObjectOverTime goTime) {
    Map<String, AttributeType> attributes = goTime.getType().getAttributeMap();
    attributes.forEach((attributeName, attribute) -> {
        if (attributeName.equals(DefaultAttribute.INVALID.getName()) || attributeName.equals(DefaultAttribute.CODE.getName()) || attributeName.equals(DefaultAttribute.UID.getName()) || attributeName.equals(GeoVertex.LASTUPDATEDATE) || attributeName.equals(GeoVertex.CREATEDATE)) {
        // Ignore the attributes
        } else // }
        if (attributeName.equals(DefaultAttribute.DISPLAY_LABEL.getName())) {
            this.getValuesOverTime(attributeName).clear();
            for (ValueOverTimeDTO votDTO : goTime.getAllValues(attributeName)) {
                LocalizedValue label = (LocalizedValue) votDTO.getValue();
                this.setDisplayLabel(label, votDTO.getStartDate(), votDTO.getEndDate());
            }
        } else if (this.vertex.hasAttribute(attributeName) && !this.vertex.getMdAttributeDAO(attributeName).isSystem()) {
            this.getValuesOverTime(attributeName).clear();
            ValueOverTimeCollectionDTO collection = goTime.getAllValues(attributeName);
            for (ValueOverTimeDTO votDTO : collection) {
                if (attribute instanceof AttributeTermType) {
                    Iterator<String> it = (Iterator<String>) votDTO.getValue();
                    if (it.hasNext()) {
                        String code = it.next();
                        Term root = ((AttributeTermType) attribute).getRootTerm();
                        String parent = TermConverter.buildClassifierKeyFromTermCode(root.getCode());
                        String classifierKey = Classifier.buildKey(parent, code);
                        Classifier classifier = Classifier.getByKey(classifierKey);
                        this.vertex.setValue(attributeName, classifier.getOid(), votDTO.getStartDate(), votDTO.getEndDate());
                    } else {
                        this.vertex.setValue(attributeName, (String) null, votDTO.getStartDate(), votDTO.getEndDate());
                    }
                } else if (attribute instanceof AttributeClassificationType) {
                    String value = (String) votDTO.getValue();
                    if (value != null) {
                        Classification classification = Classification.get((AttributeClassificationType) attribute, value);
                        this.vertex.setValue(attributeName, classification.getVertex(), votDTO.getStartDate(), votDTO.getEndDate());
                    } else {
                        this.vertex.setValue(attributeName, (String) null, this.date, this.date);
                    }
                } else {
                    Object value = votDTO.getValue();
                    if (value != null) {
                        this.vertex.setValue(attributeName, value, votDTO.getStartDate(), votDTO.getEndDate());
                    } else {
                        this.vertex.setValue(attributeName, (String) null, votDTO.getStartDate(), votDTO.getEndDate());
                    }
                }
            }
        }
    });
    this.getValuesOverTime(this.getGeometryAttributeName()).clear();
    for (ValueOverTimeDTO votDTO : goTime.getAllValues(DefaultAttribute.GEOMETRY.getName())) {
        Geometry geom = goTime.getGeometry(votDTO.getStartDate());
        this.setGeometry(geom, votDTO.getStartDate(), votDTO.getEndDate());
    }
    this.setUid(goTime.getUid());
    this.setCode(goTime.getCode());
    this.setInvalid(goTime.getInvalid());
}
Also used : ValueOverTimeCollectionDTO(org.commongeoregistry.adapter.dataaccess.ValueOverTimeCollectionDTO) ValueOverTimeDTO(org.commongeoregistry.adapter.dataaccess.ValueOverTimeDTO) MultiLineString(com.vividsolutions.jts.geom.MultiLineString) LineString(com.vividsolutions.jts.geom.LineString) Term(org.commongeoregistry.adapter.Term) Classifier(net.geoprism.ontology.Classifier) AttributeClassificationType(org.commongeoregistry.adapter.metadata.AttributeClassificationType) Geometry(com.vividsolutions.jts.geom.Geometry) LocalizedValue(org.commongeoregistry.adapter.dataaccess.LocalizedValue) AttributeType(org.commongeoregistry.adapter.metadata.AttributeType) Classification(net.geoprism.registry.model.Classification) AbstractClassification(com.runwaysdk.system.AbstractClassification) Iterator(java.util.Iterator) GeoObject(org.commongeoregistry.adapter.dataaccess.GeoObject) VertexObject(com.runwaysdk.business.graph.VertexObject) EdgeObject(com.runwaysdk.business.graph.EdgeObject) AbstractServerGeoObject(net.geoprism.registry.model.AbstractServerGeoObject) GraphObject(com.runwaysdk.business.graph.GraphObject) AttributeTermType(org.commongeoregistry.adapter.metadata.AttributeTermType)

Example 9 with Term

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

the class ConversionService method termToClassifier.

// public GeoObject getGeoObjectById(String uuid, String geoObjectTypeCode)
// {
// Universal universal = Universal.getByKey(geoObjectTypeCode);
// 
// MdBusiness mdBusiness = universal.getMdBusiness();
// 
// 
// 
// }
public Classifier termToClassifier(AttributeTermType attr, Term term) {
    Term root = attr.getRootTerm();
    String parent = TermConverter.buildClassifierKeyFromTermCode(root.getCode());
    String classifierKey = Classifier.buildKey(parent, term.getCode());
    Classifier classifier = Classifier.getByKey(classifierKey);
    return classifier;
}
Also used : Term(org.commongeoregistry.adapter.Term) Classifier(net.geoprism.ontology.Classifier)

Example 10 with Term

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

the class RegistryService method updateTerm.

/**
 * Creates a new {@link Term} object and makes it a child of the term with the
 * given code.
 *
 * @param sessionId
 * @param parentTermCode
 *          TODO
 * @param termJSON
 *          JSON of the term object.
 * @return Updated {@link Term} object.
 */
@Request(RequestType.SESSION)
public Term updateTerm(String sessionId, String parentTermCode, String termJSON) {
    JsonObject termJSONobj = JsonParser.parseString(termJSON).getAsJsonObject();
    String termCode = termJSONobj.get(Term.JSON_CODE).getAsString();
    LocalizedValue value = LocalizedValue.fromJSON(termJSONobj.get(Term.JSON_LOCALIZED_LABEL).getAsJsonObject());
    Classifier classifier = TermConverter.updateClassifier(parentTermCode, termCode, value);
    TermConverter termBuilder = new TermConverter(classifier.getKeyName());
    Term returnTerm = termBuilder.build();
    List<MdAttributeConcrete> mdAttrList = this.findRootClassifier(classifier);
    this.refreshAttributeTermTypeInCache(mdAttrList);
    return returnTerm;
}
Also used : LocalizedValue(org.commongeoregistry.adapter.dataaccess.LocalizedValue) JsonObject(com.google.gson.JsonObject) Classifier(net.geoprism.ontology.Classifier) MdAttributeMultiTerm(com.runwaysdk.system.metadata.MdAttributeMultiTerm) MdAttributeTerm(com.runwaysdk.system.metadata.MdAttributeTerm) Term(org.commongeoregistry.adapter.Term) MdAttributeConcrete(com.runwaysdk.system.metadata.MdAttributeConcrete) TermConverter(net.geoprism.registry.conversion.TermConverter) Request(com.runwaysdk.session.Request) OAuthClientRequest(org.apache.oltu.oauth2.client.request.OAuthClientRequest)

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