use of org.commongeoregistry.adapter.metadata.AttributeTermType in project geoprism-registry by terraframe.
the class ListTypeVersion method createMdAttributeFromAttributeType.
protected static void createMdAttributeFromAttributeType(TableMetadata metadata, AttributeType attributeType, ServerGeoObjectType type, Collection<Locale> locales) {
MdBusiness mdBusiness = metadata.getMdBusiness();
if (!(attributeType instanceof AttributeTermType || attributeType instanceof AttributeClassificationType || attributeType instanceof AttributeLocalType)) {
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(AttributeBooleanType.TYPE)) {
mdAttribute = new MdAttributeBoolean();
} else {
throw new UnsupportedOperationException("Unsupported type [" + attributeType.getType() + "]");
}
mdAttribute.setAttributeName(attributeType.getName());
LocalizedValueConverter.populate(mdAttribute.getDisplayLabel(), attributeType.getLabel());
LocalizedValueConverter.populate(mdAttribute.getDescription(), attributeType.getDescription());
mdAttribute.setDefiningMdClass(mdBusiness);
mdAttribute.apply();
} else if (attributeType instanceof AttributeTermType || attributeType instanceof AttributeClassificationType) {
MdAttributeCharacter cloneAttribute = new MdAttributeCharacter();
cloneAttribute.setValue(MdAttributeConcreteInfo.NAME, attributeType.getName());
cloneAttribute.setValue(MdAttributeCharacterInfo.SIZE, "255");
cloneAttribute.addIndexType(MdAttributeIndices.NON_UNIQUE_INDEX);
LocalizedValueConverter.populate(cloneAttribute.getDisplayLabel(), attributeType.getLabel());
LocalizedValueConverter.populate(cloneAttribute.getDescription(), attributeType.getDescription());
cloneAttribute.setDefiningMdClass(mdBusiness);
cloneAttribute.apply();
metadata.addPair(cloneAttribute, cloneAttribute);
MdAttributeCharacter mdAttributeDefaultLocale = new MdAttributeCharacter();
mdAttributeDefaultLocale.setValue(MdAttributeCharacterInfo.NAME, attributeType.getName() + DEFAULT_LOCALE);
mdAttributeDefaultLocale.setValue(MdAttributeCharacterInfo.SIZE, "255");
mdAttributeDefaultLocale.setDefiningMdClass(mdBusiness);
LocalizedValueConverter.populate(mdAttributeDefaultLocale.getDisplayLabel(), attributeType.getLabel(), " (defaultLocale)");
LocalizedValueConverter.populate(mdAttributeDefaultLocale.getDescription(), attributeType.getDescription(), " (defaultLocale)");
mdAttributeDefaultLocale.apply();
metadata.addPair(mdAttributeDefaultLocale, cloneAttribute);
for (Locale locale : locales) {
MdAttributeCharacter mdAttributeLocale = new MdAttributeCharacter();
mdAttributeLocale.setValue(MdAttributeCharacterInfo.NAME, attributeType.getName() + locale.toString());
mdAttributeLocale.setValue(MdAttributeCharacterInfo.SIZE, "255");
mdAttributeLocale.setDefiningMdClass(mdBusiness);
LocalizedValueConverter.populate(mdAttributeLocale.getDisplayLabel(), attributeType.getLabel(), " (" + locale.toString() + ")");
LocalizedValueConverter.populate(mdAttributeLocale.getDescription(), attributeType.getDescription());
mdAttributeLocale.apply();
metadata.addPair(mdAttributeLocale, cloneAttribute);
}
// MdAttributeUUID mdAttributeOid = new MdAttributeUUID();
// mdAttributeOid.setValue(MdAttributeConcreteInfo.NAME,
// attributeType.getName() + "Oid");
// AbstractBuilder.populate(mdAttributeOid.getDisplayLabel(),
// attributeType.getLabel());
// AbstractBuilder.populate(mdAttributeOid.getDescription(),
// attributeType.getDescription());
// mdAttributeOid.setDefiningMdClass(mdBusiness);
// mdAttributeOid.apply();
} else if (attributeType instanceof AttributeLocalType) {
boolean isDisplayLabel = attributeType.getName().equals(DefaultAttribute.DISPLAY_LABEL.getName());
MdAttributeCharacter mdAttributeDefaultLocale = new MdAttributeCharacter();
mdAttributeDefaultLocale.setValue(MdAttributeCharacterInfo.NAME, attributeType.getName() + DEFAULT_LOCALE);
mdAttributeDefaultLocale.setValue(MdAttributeCharacterInfo.SIZE, "255");
mdAttributeDefaultLocale.setDefiningMdClass(mdBusiness);
LocalizedValueConverter.populate(mdAttributeDefaultLocale.getDisplayLabel(), isDisplayLabel ? type.getLabel() : attributeType.getLabel(), " (defaultLocale)");
LocalizedValueConverter.populate(mdAttributeDefaultLocale.getDescription(), attributeType.getDescription(), " (defaultLocale)");
mdAttributeDefaultLocale.apply();
for (Locale locale : locales) {
MdAttributeCharacter mdAttributeLocale = new MdAttributeCharacter();
mdAttributeLocale.setValue(MdAttributeCharacterInfo.NAME, attributeType.getName() + locale.toString());
mdAttributeLocale.setValue(MdAttributeCharacterInfo.SIZE, "255");
mdAttributeLocale.setDefiningMdClass(mdBusiness);
LocalizedValueConverter.populate(mdAttributeLocale.getDisplayLabel(), isDisplayLabel ? type.getLabel() : attributeType.getLabel(), " (" + locale.toString() + ")");
LocalizedValueConverter.populate(mdAttributeLocale.getDescription(), attributeType.getDescription());
mdAttributeLocale.apply();
}
}
}
use of org.commongeoregistry.adapter.metadata.AttributeTermType in project geoprism-registry by terraframe.
the class ListTypeVersion method publish.
private void publish(ListType listType, ServerGeoObjectType type, ServerGeoObjectIF go, Business business, Collection<AttributeType> attributes, Map<ServerHierarchyType, List<ServerGeoObjectType>> ancestorMap, Set<ServerHierarchyType> hierarchiesOfSubTypes, Collection<Locale> locales) {
VertexServerGeoObject vertexGo = (VertexServerGeoObject) go;
business.setValue(RegistryConstants.GEOMETRY_ATTRIBUTE_NAME, go.getGeometry());
for (AttributeType attribute : attributes) {
String name = attribute.getName();
business.setValue(ORIGINAL_OID, go.getRunwayId());
if (this.isValid(attribute)) {
Object value = go.getValue(name, this.getForDate());
if (value != null) {
if (value instanceof LocalizedValue && ((LocalizedValue) value).isNull()) {
continue;
}
if (attribute instanceof AttributeTermType) {
Classifier classifier = (Classifier) value;
Term term = ((AttributeTermType) attribute).getTermByCode(classifier.getClassifierId()).get();
LocalizedValue label = term.getLabel();
this.setValue(business, name, term.getCode());
this.setValue(business, name + DEFAULT_LOCALE, label.getValue(LocalizedValue.DEFAULT_LOCALE));
for (Locale locale : locales) {
this.setValue(business, name + locale.toString(), label.getValue(locale));
}
} else if (attribute instanceof AttributeClassificationType) {
String classificationTypeCode = ((AttributeClassificationType) attribute).getClassificationType();
ClassificationType classificationType = ClassificationType.getByCode(classificationTypeCode);
Classification classification = Classification.getByOid(classificationType, (String) value);
LocalizedValue label = classification.getDisplayLabel();
this.setValue(business, name, classification.getCode());
this.setValue(business, name + DEFAULT_LOCALE, label.getValue(LocalizedValue.DEFAULT_LOCALE));
for (Locale locale : locales) {
this.setValue(business, name + locale.toString(), label.getValue(locale));
}
} else if (attribute instanceof AttributeLocalType) {
LocalizedValue label = (LocalizedValue) value;
String defaultLocale = label.getValue(LocalizedValue.DEFAULT_LOCALE);
if (defaultLocale == null) {
defaultLocale = "";
}
this.setValue(business, name + DEFAULT_LOCALE, defaultLocale);
for (Locale locale : locales) {
String localeValue = label.getValue(locale);
if (localeValue == null) {
localeValue = "";
}
this.setValue(business, name + locale.toString(), localeValue);
}
} else {
this.setValue(business, name, value);
}
}
}
}
Set<Entry<ServerHierarchyType, List<ServerGeoObjectType>>> entries = ancestorMap.entrySet();
for (Entry<ServerHierarchyType, List<ServerGeoObjectType>> entry : entries) {
ServerHierarchyType hierarchy = entry.getKey();
Map<String, LocationInfo> map = vertexGo.getAncestorMap(hierarchy, entry.getValue());
Set<Entry<String, LocationInfo>> locations = map.entrySet();
for (Entry<String, LocationInfo> location : locations) {
String pCode = location.getKey();
LocationInfo vObject = location.getValue();
if (vObject != null) {
String attributeName = hierarchy.getCode().toLowerCase() + pCode.toLowerCase();
this.setValue(business, attributeName, vObject.getCode());
this.setValue(business, attributeName + DEFAULT_LOCALE, vObject.getLabel());
for (Locale locale : locales) {
this.setValue(business, attributeName + locale.toString(), vObject.getLabel(locale));
}
}
}
}
for (ServerHierarchyType hierarchy : hierarchiesOfSubTypes) {
ServerParentTreeNode node = go.getParentsForHierarchy(hierarchy, false, this.getForDate());
List<ServerParentTreeNode> parents = node.getParents();
if (parents.size() > 0) {
ServerParentTreeNode parent = parents.get(0);
String attributeName = hierarchy.getCode().toLowerCase();
ServerGeoObjectIF geoObject = parent.getGeoObject();
LocalizedValue label = geoObject.getDisplayLabel();
this.setValue(business, attributeName, geoObject.getCode());
this.setValue(business, attributeName + DEFAULT_LOCALE, label.getValue(DEFAULT_LOCALE));
for (Locale locale : locales) {
this.setValue(business, attributeName + locale.toString(), label.getValue(locale));
}
}
}
if (type.getGeometryType().equals(GeometryType.MULTIPOINT) || type.getGeometryType().equals(GeometryType.POINT) && listType.getIncludeLatLong()) {
Geometry geom = vertexGo.getGeometry();
if (geom instanceof MultiPoint) {
MultiPoint mp = (MultiPoint) geom;
Coordinate[] coords = mp.getCoordinates();
Coordinate firstCoord = coords[0];
this.setValue(business, "latitude", String.valueOf(firstCoord.y));
this.setValue(business, "longitude", String.valueOf(firstCoord.x));
} else if (geom instanceof Point) {
Point point = (Point) geom;
Coordinate firstCoord = point.getCoordinate();
this.setValue(business, "latitude", String.valueOf(firstCoord.y));
this.setValue(business, "longitude", String.valueOf(firstCoord.x));
}
}
business.apply();
}
use of org.commongeoregistry.adapter.metadata.AttributeTermType in project geoprism-registry by terraframe.
the class MasterListVersion method publish.
private void publish(ServerGeoObjectIF go, Business business, Collection<AttributeType> attributes, Map<ServerHierarchyType, List<ServerGeoObjectType>> ancestorMap, Set<ServerHierarchyType> hierarchiesOfSubTypes, Collection<Locale> locales) {
VertexServerGeoObject vertexGo = (VertexServerGeoObject) go;
boolean hasData = false;
business.setValue(RegistryConstants.GEOMETRY_ATTRIBUTE_NAME, go.getGeometry());
for (AttributeType attribute : attributes) {
String name = attribute.getName();
business.setValue(ORIGINAL_OID, go.getRunwayId());
if (this.isValid(attribute)) {
Object value = go.getValue(name, this.getForDate());
if (value != null) {
if (value instanceof LocalizedValue && ((LocalizedValue) value).isNull()) {
continue;
}
if (!name.equals(DefaultAttribute.CODE.getName()) && !name.equals(DefaultAttribute.INVALID.getName()) && attribute.isChangeOverTime() && (!name.equals(DefaultAttribute.EXISTS.getName()) || (value instanceof Boolean && ((Boolean) value)))) {
hasData = true;
}
if (attribute instanceof AttributeTermType) {
Classifier classifier = (Classifier) value;
Term term = ((AttributeTermType) attribute).getTermByCode(classifier.getClassifierId()).get();
LocalizedValue label = term.getLabel();
this.setValue(business, name, term.getCode());
this.setValue(business, name + DEFAULT_LOCALE, label.getValue(LocalizedValue.DEFAULT_LOCALE));
for (Locale locale : locales) {
this.setValue(business, name + locale.toString(), label.getValue(locale));
}
} else if (attribute instanceof AttributeClassificationType) {
String classificationType = ((AttributeClassificationType) attribute).getClassificationType();
MdClassificationDAOIF mdClassificationDAO = MdClassificationDAO.getMdClassificationDAO(classificationType);
MdVertexDAOIF mdVertexDAO = mdClassificationDAO.getReferenceMdVertexDAO();
VertexObject classification = VertexObject.get(mdVertexDAO, (String) value);
LocalizedValue label = LocalizedValueConverter.convert(classification.getEmbeddedComponent(AbstractClassification.DISPLAYLABEL));
this.setValue(business, name, classification.getObjectValue(AbstractClassification.CODE));
this.setValue(business, name + DEFAULT_LOCALE, label.getValue(LocalizedValue.DEFAULT_LOCALE));
for (Locale locale : locales) {
this.setValue(business, name + locale.toString(), label.getValue(locale));
}
} else if (attribute instanceof AttributeLocalType) {
LocalizedValue label = (LocalizedValue) value;
String defaultLocale = label.getValue(LocalizedValue.DEFAULT_LOCALE);
if (defaultLocale == null) {
defaultLocale = "";
}
this.setValue(business, name + DEFAULT_LOCALE, defaultLocale);
for (Locale locale : locales) {
String localeValue = label.getValue(locale);
if (localeValue == null) {
localeValue = "";
}
this.setValue(business, name + locale.toString(), localeValue);
}
} else {
this.setValue(business, name, value);
}
}
}
}
if (hasData) {
Set<Entry<ServerHierarchyType, List<ServerGeoObjectType>>> entries = ancestorMap.entrySet();
for (Entry<ServerHierarchyType, List<ServerGeoObjectType>> entry : entries) {
ServerHierarchyType hierarchy = entry.getKey();
Map<String, LocationInfo> map = vertexGo.getAncestorMap(hierarchy, entry.getValue());
Set<Entry<String, LocationInfo>> locations = map.entrySet();
for (Entry<String, LocationInfo> location : locations) {
String pCode = location.getKey();
LocationInfo vObject = location.getValue();
if (vObject != null) {
String attributeName = hierarchy.getCode().toLowerCase() + pCode.toLowerCase();
this.setValue(business, attributeName, vObject.getCode());
this.setValue(business, attributeName + DEFAULT_LOCALE, vObject.getLabel());
for (Locale locale : locales) {
this.setValue(business, attributeName + locale.toString(), vObject.getLabel(locale));
}
}
}
}
for (ServerHierarchyType hierarchy : hierarchiesOfSubTypes) {
ServerParentTreeNode node = go.getParentsForHierarchy(hierarchy, false, this.getForDate());
List<ServerParentTreeNode> parents = node.getParents();
if (parents.size() > 0) {
ServerParentTreeNode parent = parents.get(0);
String attributeName = hierarchy.getCode().toLowerCase();
ServerGeoObjectIF geoObject = parent.getGeoObject();
LocalizedValue label = geoObject.getDisplayLabel();
this.setValue(business, attributeName, geoObject.getCode());
this.setValue(business, attributeName + DEFAULT_LOCALE, label.getValue(DEFAULT_LOCALE));
for (Locale locale : locales) {
this.setValue(business, attributeName + locale.toString(), label.getValue(locale));
}
}
}
business.apply();
}
}
use of org.commongeoregistry.adapter.metadata.AttributeTermType in project geoprism-registry by terraframe.
the class DHIS2TermAttributeMapping method writeAttributeValue.
@Override
protected void writeAttributeValue(AttributeType attr, String propertyName, Object value, JsonObject av) {
if (attr instanceof AttributeTermType) {
String termId = this.getTermId(value);
String termMapping = this.getTermMapping(termId);
if (termMapping == null) {
MissingDHIS2TermMapping ex = new MissingDHIS2TermMapping();
ex.setTermCode(termId);
throw ex;
}
av.addProperty("value", termMapping);
} else {
logger.error("Unsupported attribute type [" + attr.getClass().getName() + "] with name [" + attr.getName() + "] for mapping type [" + DHIS2TermAttributeMapping.class.getName() + "].");
return;
}
}
use of org.commongeoregistry.adapter.metadata.AttributeTermType in project geoprism-registry by terraframe.
the class BusinessObjectImporter method setTermValue.
protected void setTermValue(BusinessObject entity, AttributeType attributeType, String attributeName, Object value) {
if (!this.configuration.isExclusion(attributeName, value.toString())) {
try {
BusinessType type = this.configuration.getType();
MdVertexDAOIF mdBusiness = type.getMdVertexDAO();
MdAttributeTermDAOIF mdAttribute = (MdAttributeTermDAOIF) mdBusiness.definesAttribute(attributeName);
Classifier classifier = Classifier.findMatchingTerm(value.toString().trim(), mdAttribute);
if (classifier == null) {
Term rootTerm = ((AttributeTermType) attributeType).getRootTerm();
TermReferenceProblem trp = new TermReferenceProblem(value.toString(), rootTerm.getCode(), mdAttribute.getOid(), attributeName, attributeType.getLabel().getValue());
trp.addAffectedRowNumber(this.progressListener.getWorkProgress() + 1);
trp.setHistoryId(this.configuration.getHistoryId());
this.progressListener.addReferenceProblem(trp);
} else {
entity.setValue(attributeName, classifier.getOid());
}
} catch (UnknownTermException e) {
TermValueException ex = new TermValueException();
ex.setAttributeLabel(e.getAttribute().getLabel().getValue());
ex.setCode(e.getCode());
throw e;
}
}
}
Aggregations