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;
}
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;
}
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());
}
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;
}
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;
}
Aggregations