use of org.commongeoregistry.adapter.metadata.AttributeLocalType 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 org.commongeoregistry.adapter.metadata.AttributeLocalType in project geoprism-registry by terraframe.
the class GeoObjectAtTimeShapefileExporterTest method testCreateFeatures.
@Test
@Request
public void testCreateFeatures() {
ServerGeoObjectType type = FastTestDataset.PROVINCE.getServerObject();
GeoObjectAtTimeShapefileExporter exporter = new GeoObjectAtTimeShapefileExporter(type, FastTestDataset.DEFAULT_OVER_TIME_DATE);
SimpleFeatureType featureType = exporter.createFeatureType();
FeatureCollection<SimpleFeatureType, SimpleFeature> features = exporter.features(featureType);
Assert.assertTrue(features.size() > 0);
final FeatureIterator<SimpleFeature> it = features.features();
boolean hasCentralProvince = false;
while (it.hasNext()) {
SimpleFeature feature = it.next();
if (feature.getID().equals(FastTestDataset.PROV_CENTRAL.getCode())) {
hasCentralProvince = true;
final ServerGeoObjectIF object = FastTestDataset.PROV_CENTRAL.getServerObject();
Object geometry = feature.getDefaultGeometry();
Assert.assertNotNull(geometry);
Collection<AttributeType> attributes = new ImportAttributeSerializer(Session.getCurrentLocale(), false, false, LocalizationFacade.getInstalledLocales()).attributes(type.getType());
for (AttributeType attribute : attributes) {
String attributeName = attribute.getName();
Object oValue = object.getValue(attributeName);
Object fValue = feature.getAttribute(exporter.getColumnName(attributeName));
if (attribute instanceof AttributeTermType) {
Assert.assertEquals("Attributes not equal [" + attributeName + "]", GeoObjectUtil.convertToTermString((AttributeTermType) attribute, oValue), fValue);
} else if (attribute instanceof AttributeLocalType) {
Assert.assertEquals("Attributes not equal [" + attributeName + "]", ((LocalizedValue) oValue).getValue(), fValue);
} else {
Assert.assertEquals("Attributes not equal [" + attributeName + "]", oValue, fValue);
}
}
}
}
Assert.assertTrue("Unable to find the central province feature", hasCentralProvince);
}
Aggregations