Search in sources :

Example 11 with AttributeLocalType

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)));
            }
        }
    }
}
Also used : Locale(java.util.Locale) ServerGeoObjectType(net.geoprism.registry.model.ServerGeoObjectType) Point(com.vividsolutions.jts.geom.Point) AttributeClassificationType(org.commongeoregistry.adapter.metadata.AttributeClassificationType) Point(com.vividsolutions.jts.geom.Point) Date(java.util.Date) LocationInfo(net.geoprism.registry.model.LocationInfo) AttributeLocalType(org.commongeoregistry.adapter.metadata.AttributeLocalType) LocalizedValue(org.commongeoregistry.adapter.dataaccess.LocalizedValue) AttributeType(org.commongeoregistry.adapter.metadata.AttributeType) GeoObject(org.commongeoregistry.adapter.dataaccess.GeoObject) AttributeTermType(org.commongeoregistry.adapter.metadata.AttributeTermType) Cell(org.apache.poi.ss.usermodel.Cell)

Example 12 with AttributeLocalType

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);
}
Also used : ServerGeoObjectIF(net.geoprism.registry.model.ServerGeoObjectIF) ServerGeoObjectType(net.geoprism.registry.model.ServerGeoObjectType) GeoObjectAtTimeShapefileExporter(net.geoprism.registry.shapefile.GeoObjectAtTimeShapefileExporter) SimpleFeature(org.opengis.feature.simple.SimpleFeature) AttributeLocalType(org.commongeoregistry.adapter.metadata.AttributeLocalType) SimpleFeatureType(org.opengis.feature.simple.SimpleFeatureType) LocalizedValue(org.commongeoregistry.adapter.dataaccess.LocalizedValue) AttributeType(org.commongeoregistry.adapter.metadata.AttributeType) AttributeTermType(org.commongeoregistry.adapter.metadata.AttributeTermType) Test(org.junit.Test) Request(com.runwaysdk.session.Request)

Aggregations

AttributeLocalType (org.commongeoregistry.adapter.metadata.AttributeLocalType)12 AttributeTermType (org.commongeoregistry.adapter.metadata.AttributeTermType)12 Locale (java.util.Locale)9 AttributeClassificationType (org.commongeoregistry.adapter.metadata.AttributeClassificationType)9 AttributeType (org.commongeoregistry.adapter.metadata.AttributeType)8 ServerGeoObjectType (net.geoprism.registry.model.ServerGeoObjectType)7 LocalizedValue (org.commongeoregistry.adapter.dataaccess.LocalizedValue)7 JsonObject (com.google.gson.JsonObject)5 ServerGeoObjectIF (net.geoprism.registry.model.ServerGeoObjectIF)4 VertexServerGeoObject (net.geoprism.registry.model.graph.VertexServerGeoObject)4 Term (org.commongeoregistry.adapter.Term)4 AttributeFloatType (org.commongeoregistry.adapter.metadata.AttributeFloatType)4 MdAttributeBoolean (com.runwaysdk.system.metadata.MdAttributeBoolean)3 Point (com.vividsolutions.jts.geom.Point)3 Classifier (net.geoprism.ontology.Classifier)3 LocationInfo (net.geoprism.registry.model.LocationInfo)3 JsonArray (com.google.gson.JsonArray)2 MdBusinessDAOIF (com.runwaysdk.dataaccess.MdBusinessDAOIF)2 ValueObject (com.runwaysdk.dataaccess.ValueObject)2 Request (com.runwaysdk.session.Request)2