use of net.geoprism.registry.model.LocationInfo 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 net.geoprism.registry.model.LocationInfo 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 net.geoprism.registry.model.LocationInfo in project geoprism-registry by terraframe.
the class GeoObjectUtilTest method testGetAncestorMapForTreeType.
@Test
@Request
public void testGetAncestorMapForTreeType() {
ServerGeoObjectType type = USATestData.AREA.getServerObject();
ServerHierarchyType hierarchyType = ServerHierarchyType.get(USATestData.HIER_ADMIN.getCode());
ServerGeoObjectIF object = new ServerGeoObjectService().getGeoObjectByCode(USATestData.CO_A_ONE.getCode(), type);
List<GeoObjectType> dtoAncestors = type.getTypeAncestors(hierarchyType, true);
List<ServerGeoObjectType> ancestors = new LinkedList<ServerGeoObjectType>();
for (GeoObjectType ancestor : dtoAncestors) {
ancestors.add(ServerGeoObjectType.get(ancestor));
}
Map<String, LocationInfo> map = object.getAncestorMap(hierarchyType, ancestors);
Assert.assertEquals(3, map.size());
// Validate the county values
Assert.assertTrue(map.containsKey(USATestData.COUNTY.getCode()));
LocationInfo vObject = map.get(USATestData.COUNTY.getCode());
Assert.assertEquals(USATestData.CO_C_ONE.getCode(), vObject.getCode());
Assert.assertEquals(USATestData.CO_C_ONE.getDisplayLabel(), vObject.getLabel());
// Validate the state values
Assert.assertTrue(map.containsKey(USATestData.STATE.getCode()));
vObject = map.get(USATestData.STATE.getCode());
Assert.assertEquals(USATestData.COLORADO.getCode(), vObject.getCode());
Assert.assertEquals(USATestData.COLORADO.getDisplayLabel(), vObject.getLabel());
// Validate the country values
Assert.assertTrue(map.containsKey(USATestData.COUNTRY.getCode()));
vObject = map.get(USATestData.COUNTRY.getCode());
Assert.assertEquals(USATestData.USA.getCode(), vObject.getCode());
Assert.assertEquals(USATestData.USA.getDisplayLabel(), vObject.getLabel());
}
use of net.geoprism.registry.model.LocationInfo in project geoprism-registry by terraframe.
the class GeoObjectExcelExporter method writeRow.
public void writeRow(Row row, ServerGeoObjectIF object, Collection<AttributeType> attributes, List<ServerGeoObjectType> ancestors, CellStyle dateStyle) {
int col = 0;
// Write the row
for (AttributeType attribute : attributes) {
String name = attribute.getName();
Cell cell = row.createCell(col++);
if (name.equals(GeoObjectImportConfiguration.LATITUDE)) {
Point point = (Point) object.getGeometry();
if (point != null) {
cell.setCellValue(point.getY());
}
} else if (name.equals(GeoObjectImportConfiguration.LONGITUDE)) {
Point point = (Point) object.getGeometry();
if (point != null) {
cell.setCellValue(point.getX());
}
} else {
Object value = object.getValue(name);
if (value != null) {
if (attribute instanceof AttributeTermType) {
cell.setCellValue(GeoObjectUtil.convertToTermString((AttributeTermType) attribute, value));
} else if (attribute instanceof AttributeClassificationType) {
cell.setCellValue(GeoObjectUtil.convertToTermString((AttributeClassificationType) attribute, value));
} else if (attribute instanceof AttributeLocalType) {
cell.setCellValue(((LocalizedValue) value).getValue());
} else {
if (value instanceof String) {
cell.setCellValue((String) value);
} else if (value instanceof Date) {
cell.setCellValue((Date) value);
cell.setCellStyle(dateStyle);
} else if (value instanceof Number) {
cell.setCellValue(((Number) value).doubleValue());
} else if (value instanceof Boolean) {
cell.setCellValue((Boolean) value);
}
}
}
}
}
{
LocalizedValue value = (LocalizedValue) object.getValue(DefaultAttribute.DISPLAY_LABEL.getName());
Cell cell = row.createCell(col++);
cell.setCellValue(value.getValue(LocalizedValue.DEFAULT_LOCALE));
for (Locale locale : locales) {
cell = row.createCell(col++);
cell.setCellValue(value.getValue(locale));
}
}
// Write the parent values
Map<String, LocationInfo> map = object.getAncestorMap(this.hierarchy, ancestors);
for (ServerGeoObjectType ancestor : ancestors) {
LocationInfo vObject = map.get(ancestor.getCode());
Cell codeCell = row.createCell(col++);
Cell labelCell = row.createCell(col++);
for (int i = 0; i < locales.size(); i++) {
row.createCell(col++);
}
if (vObject != null) {
codeCell.setCellValue(vObject.getCode());
labelCell.setCellValue(vObject.getLabel());
for (int i = 0; i < locales.size(); ++i) {
Cell cell = row.getCell(labelCell.getColumnIndex() + i + 1);
cell.setCellValue(vObject.getLabel(locales.get(i)));
}
}
}
}
use of net.geoprism.registry.model.LocationInfo in project geoprism-registry by terraframe.
the class VertexServerGeoObject method getAncestorMap.
@SuppressWarnings("unchecked")
public Map<String, LocationInfo> getAncestorMap(ServerHierarchyType hierarchy, List<ServerGeoObjectType> parents) {
TreeMap<String, LocationInfo> map = new TreeMap<String, LocationInfo>();
GraphQuery<Map<String, Object>> query = buildAncestorQueryFast(hierarchy, parents);
List<Map<String, Object>> results = query.getResults();
if (results.size() <= 1) {
return map;
}
// First result is the child object
results.remove(0);
results.forEach(result -> {
String clazz = (String) result.get("cl");
String code = (String) result.get("code");
List<Map<String, Object>> displayLabelRaw = (List<Map<String, Object>>) result.get("label");
LocalizedValue localized = LocalizedValueConverter.convert(displayLabelRaw, this.date);
ServerGeoObjectType type = null;
for (ServerGeoObjectType parent : parents) {
if (parent.getMdVertex().getDBClassName().equals(clazz)) {
type = parent;
}
}
if (type != null && localized != null) {
LocationInfoHolder holder = new LocationInfoHolder(code, localized, type);
map.put(type.getUniversal().getKey(), holder);
} else {
logger.error("Could not find [" + clazz + "] or the localized value was null.");
}
});
return map;
}
Aggregations