Search in sources :

Example 1 with ListTypeShapefileExporter

use of net.geoprism.registry.shapefile.ListTypeShapefileExporter in project geoprism-registry by terraframe.

the class ListTypeGeoObjectShapefileExporterTest method testCreateFeatures.

@Test
@Request
public void testCreateFeatures() {
    ServerGeoObjectIF object = FastTestDataset.PROV_CENTRAL.getServerObject();
    ServerGeoObjectType type = object.getType();
    ListTypeShapefileExporter exporter = new ListTypeShapefileExporter(version, mdBusiness, mdAttributes, new JsonObject());
    SimpleFeatureType featureType = exporter.createFeatureType();
    FeatureCollection<SimpleFeatureType, SimpleFeature> features = exporter.features(featureType);
    Assert.assertEquals(2, features.size());
    FeatureIterator<SimpleFeature> it = features.features();
    SimpleFeature feature = null;
    while (it.hasNext()) {
        SimpleFeature f = it.next();
        if (object.getCode().equals(f.getAttribute(GeoObject.CODE))) {
            feature = f;
        }
    }
    Assert.assertNotNull(feature);
    Assert.assertEquals("Attributes not equal [code]", object.getCode(), feature.getAttribute(GeoObject.CODE));
    Object geometry = feature.getDefaultGeometry();
    Assert.assertNotNull(geometry);
    ImportAttributeSerializer serializer = new ImportAttributeSerializer(Session.getCurrentLocale(), false, false, LocalizationFacade.getInstalledLocales());
    Collection<AttributeType> attributes = serializer.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.assertEquals(FastTestDataset.CAMBODIA.getCode(), feature.getAttribute(exporter.getColumnName("fastadmincodefastcountry")));
    Assert.assertEquals(FastTestDataset.CAMBODIA.getDisplayLabel(), feature.getAttribute(exporter.getColumnName("fastadmincodefastcountryDefaultLocale")));
}
Also used : ServerGeoObjectIF(net.geoprism.registry.model.ServerGeoObjectIF) ServerGeoObjectType(net.geoprism.registry.model.ServerGeoObjectType) JsonObject(com.google.gson.JsonObject) SimpleFeature(org.opengis.feature.simple.SimpleFeature) AttributeLocalType(org.commongeoregistry.adapter.metadata.AttributeLocalType) SimpleFeatureType(org.opengis.feature.simple.SimpleFeatureType) LocalizedValue(org.commongeoregistry.adapter.dataaccess.LocalizedValue) ListTypeShapefileExporter(net.geoprism.registry.shapefile.ListTypeShapefileExporter) AttributeType(org.commongeoregistry.adapter.metadata.AttributeType) JsonObject(com.google.gson.JsonObject) GeoObject(org.commongeoregistry.adapter.dataaccess.GeoObject) AttributeTermType(org.commongeoregistry.adapter.metadata.AttributeTermType) ListTypeTest(net.geoprism.registry.service.ListTypeTest) Test(org.junit.Test) Request(com.runwaysdk.session.Request)

Example 2 with ListTypeShapefileExporter

use of net.geoprism.registry.shapefile.ListTypeShapefileExporter in project geoprism-registry by terraframe.

the class GeoRegistryUtil method exportListTypeShapefile.

@Transaction
public static InputStream exportListTypeShapefile(String oid, String json) {
    ListTypeVersion version = ListTypeVersion.get(oid);
    MdBusinessDAOIF mdBusiness = MdBusinessDAO.get(version.getMdBusinessOid());
    JsonObject criteria = (json != null) ? JsonParser.parseString(json).getAsJsonObject() : new JsonObject();
    List<? extends MdAttributeConcreteDAOIF> mdAttributes = mdBusiness.definesAttributesOrdered().stream().filter(mdAttribute -> version.isValid(mdAttribute)).collect(Collectors.toList());
    if (json.contains("invalid")) {
        mdAttributes = mdAttributes.stream().filter(mdAttribute -> !mdAttribute.definesAttribute().equals("invalid")).collect(Collectors.toList());
    }
    try {
        ListTypeShapefileExporter exporter = new ListTypeShapefileExporter(version, mdBusiness, mdAttributes, criteria);
        return exporter.export();
    } catch (IOException e) {
        throw new ProgrammingErrorException(e);
    }
}
Also used : JsonObject(com.google.gson.JsonObject) ProgrammingErrorException(com.runwaysdk.dataaccess.ProgrammingErrorException) Date(java.util.Date) Transaction(com.runwaysdk.dataaccess.transaction.Transaction) SimpleDateFormat(java.text.SimpleDateFormat) Authenticate(com.runwaysdk.business.rbac.Authenticate) JsonParser(com.google.gson.JsonParser) ClassificationType(net.geoprism.registry.model.ClassificationType) ServiceFactory(net.geoprism.registry.service.ServiceFactory) TemporalAccessor(java.time.temporal.TemporalAccessor) MdAttributeConcreteDAOIF(com.runwaysdk.dataaccess.MdAttributeConcreteDAOIF) MasterListExcelExporter(net.geoprism.registry.excel.MasterListExcelExporter) ListTypeShapefileExporter(net.geoprism.registry.shapefile.ListTypeShapefileExporter) ParseException(java.text.ParseException) ServerHierarchyType(net.geoprism.registry.model.ServerHierarchyType) MdBusinessDAOIF(com.runwaysdk.dataaccess.MdBusinessDAOIF) TimeZone(java.util.TimeZone) IOException(java.io.IOException) ListTypeExcelExporter(net.geoprism.registry.excel.ListTypeExcelExporter) Instant(java.time.Instant) Collectors(java.util.stream.Collectors) HierarchyType(org.commongeoregistry.adapter.metadata.HierarchyType) List(java.util.List) ServerHierarchyTypeBuilder(net.geoprism.registry.conversion.ServerHierarchyTypeBuilder) MdBusinessDAO(com.runwaysdk.dataaccess.metadata.MdBusinessDAO) DateTimeFormatter(java.time.format.DateTimeFormatter) GeoObjectImportConfiguration(net.geoprism.registry.io.GeoObjectImportConfiguration) MasterListShapefileExporter(net.geoprism.registry.shapefile.MasterListShapefileExporter) XMLImporter(net.geoprism.registry.xml.XMLImporter) RegistryAdapter(org.commongeoregistry.adapter.RegistryAdapter) InputStream(java.io.InputStream) MdBusinessDAOIF(com.runwaysdk.dataaccess.MdBusinessDAOIF) ListTypeShapefileExporter(net.geoprism.registry.shapefile.ListTypeShapefileExporter) JsonObject(com.google.gson.JsonObject) IOException(java.io.IOException) ProgrammingErrorException(com.runwaysdk.dataaccess.ProgrammingErrorException) Transaction(com.runwaysdk.dataaccess.transaction.Transaction)

Example 3 with ListTypeShapefileExporter

use of net.geoprism.registry.shapefile.ListTypeShapefileExporter in project geoprism-registry by terraframe.

the class ListTypeVersion method generateShapefile.

// public List<ExecutableJob> getJobs()
// {
// LinkedList<ExecutableJob> jobs = new LinkedList<ExecutableJob>();
// 
// PublishShapefileJobQuery psjq = new PublishShapefileJobQuery(new
// QueryFactory());
// psjq.WHERE(psjq.getVersion().EQ(this));
// 
// try (OIterator<? extends PublishShapefileJob> it = psjq.getIterator())
// {
// jobs.addAll(it.getAll());
// }
// 
// PublishListTypeVersionJobQuery pmlvj = new
// PublishListTypeVersionJobQuery(new QueryFactory());
// pmlvj.WHERE(pmlvj.getListTypeVersion().EQ(this));
// 
// try (OIterator<? extends PublishListTypeVersionJob> it =
// pmlvj.getIterator())
// {
// jobs.addAll(it.getAll());
// }
// 
// return jobs;
// }
public File generateShapefile() {
    String filename = this.getOid() + ".zip";
    final ListType list = this.getListType();
    final File directory = list.getShapefileDirectory();
    directory.mkdirs();
    final File file = new File(directory, filename);
    MdBusinessDAOIF mdBusiness = MdBusinessDAO.get(this.getMdBusinessOid());
    List<? extends MdAttributeConcreteDAOIF> mdAttributes = mdBusiness.definesAttributesOrdered().stream().filter(mdAttribute -> this.isValid(mdAttribute)).collect(Collectors.toList());
    try {
        ListTypeShapefileExporter exporter = new ListTypeShapefileExporter(this, mdBusiness, mdAttributes, null);
        try (final InputStream istream = exporter.export()) {
            try (final FileOutputStream fos = new FileOutputStream(file)) {
                IOUtils.copy(istream, fos);
            }
        }
    } catch (IOException e) {
        throw new ProgrammingErrorException(e);
    }
    return file;
}
Also used : MdAttributeBooleanDAOIF(com.runwaysdk.dataaccess.MdAttributeBooleanDAOIF) Authenticate(com.runwaysdk.business.rbac.Authenticate) AttributeFloatType(org.commongeoregistry.adapter.metadata.AttributeFloatType) MdAttributeBoolean(com.runwaysdk.system.metadata.MdAttributeBoolean) MdAttributeDateTimeUtil(com.runwaysdk.constants.MdAttributeDateTimeUtil) MdAttributeMomentDAOIF(com.runwaysdk.dataaccess.MdAttributeMomentDAOIF) JSONException(org.json.JSONException) Condition(com.runwaysdk.query.Condition) IndexTypes(com.runwaysdk.constants.IndexTypes) TableMetadata(net.geoprism.registry.masterlist.TableMetadata) Map(java.util.Map) ServerGeoObjectRestriction(net.geoprism.registry.query.ServerGeoObjectRestriction) AttributeBooleanType(org.commongeoregistry.adapter.metadata.AttributeBooleanType) AttributeBoolean(com.runwaysdk.query.AttributeBoolean) ComponentIF(com.runwaysdk.ComponentIF) ListTypeAttributeComparator(net.geoprism.registry.masterlist.ListTypeAttributeComparator) Set(java.util.Set) BusinessFacade(com.runwaysdk.business.BusinessFacade) IOUtils(org.apache.commons.io.IOUtils) JsonArray(com.google.gson.JsonArray) GeoObjectImportConfiguration(net.geoprism.registry.io.GeoObjectImportConfiguration) MdBusiness(com.runwaysdk.system.metadata.MdBusiness) GeoserverRemoveWMSCommand(net.geoprism.registry.command.GeoserverRemoveWMSCommand) MdAttributeLong(com.runwaysdk.system.metadata.MdAttributeLong) SimpleDateFormat(java.text.SimpleDateFormat) JsonParser(com.google.gson.JsonParser) DefaultConfiguration(net.geoprism.DefaultConfiguration) NumberFormat(java.text.NumberFormat) MdAttributeDouble(com.runwaysdk.system.metadata.MdAttributeDouble) ServerParentTreeNode(net.geoprism.registry.model.ServerParentTreeNode) F(com.runwaysdk.query.F) Classification(net.geoprism.registry.model.Classification) BasicVertexQuery(net.geoprism.registry.query.graph.BasicVertexQuery) MdAttributeFloatInfo(com.runwaysdk.constants.MdAttributeFloatInfo) QueryFactory(com.runwaysdk.query.QueryFactory) RoleDAO(com.runwaysdk.business.rbac.RoleDAO) ListTypeShapefileExporter(net.geoprism.registry.shapefile.ListTypeShapefileExporter) VertexGeoObjectQuery(net.geoprism.registry.query.graph.VertexGeoObjectQuery) JsonSerializable(net.geoprism.registry.view.JsonSerializable) MdAttributeNumberDAOIF(com.runwaysdk.dataaccess.MdAttributeNumberDAOIF) ComponentQuery(com.runwaysdk.query.ComponentQuery) MdAttribute(com.runwaysdk.system.metadata.MdAttribute) MdAttributeConcrete(com.runwaysdk.system.metadata.MdAttributeConcrete) Coordinate(com.vividsolutions.jts.geom.Coordinate) AttributeType(org.commongeoregistry.adapter.metadata.AttributeType) MdBusinessDAOIF(com.runwaysdk.dataaccess.MdBusinessDAOIF) AttributeDateType(org.commongeoregistry.adapter.metadata.AttributeDateType) FileOutputStream(java.io.FileOutputStream) IOException(java.io.IOException) File(java.io.File) HierarchyType(org.commongeoregistry.adapter.metadata.HierarchyType) ListCurationHistory(net.geoprism.registry.curation.ListCurationHistory) DataNotFoundException(com.runwaysdk.dataaccess.cache.DataNotFoundException) MultiPoint(com.vividsolutions.jts.geom.MultiPoint) Business(com.runwaysdk.business.Business) MdAttributeFloatDAO(com.runwaysdk.dataaccess.metadata.MdAttributeFloatDAO) MdBusinessDAO(com.runwaysdk.dataaccess.metadata.MdBusinessDAO) BasicVertexRestriction(net.geoprism.registry.query.graph.BasicVertexRestriction) BusinessInfo(com.runwaysdk.constants.BusinessInfo) MdAttributePolygon(com.runwaysdk.system.gis.metadata.MdAttributePolygon) JsonObject(com.google.gson.JsonObject) Operation(com.runwaysdk.business.rbac.Operation) Date(java.util.Date) AttributeLocalType(org.commongeoregistry.adapter.metadata.AttributeLocalType) ValueObject(com.runwaysdk.dataaccess.ValueObject) ServerGeoObjectType(net.geoprism.registry.model.ServerGeoObjectType) ClassificationType(net.geoprism.registry.model.ClassificationType) MdAttributeBooleanInfo(com.runwaysdk.constants.MdAttributeBooleanInfo) MdTableInfo(com.runwaysdk.constants.MdTableInfo) ValueQuery(com.runwaysdk.query.ValueQuery) MdAttributeShape(com.runwaysdk.system.gis.metadata.MdAttributeShape) Locale(java.util.Locale) Geometry(com.vividsolutions.jts.geom.Geometry) ParseException(java.text.ParseException) AttributeCharacterType(org.commongeoregistry.adapter.metadata.AttributeCharacterType) Database(com.runwaysdk.dataaccess.database.Database) MdAttributePoint(com.runwaysdk.system.gis.metadata.MdAttributePoint) DateFormat(java.text.DateFormat) GeoserverFacade(net.geoprism.gis.geoserver.GeoserverFacade) BusinessQuery(com.runwaysdk.business.BusinessQuery) MdAttributeCharacterDAO(com.runwaysdk.dataaccess.metadata.MdAttributeCharacterDAO) UnsupportedOperationException(com.amazonaws.services.kms.model.UnsupportedOperationException) LocationInfo(net.geoprism.registry.model.LocationInfo) Collection(java.util.Collection) VertexServerGeoObject(net.geoprism.registry.model.graph.VertexServerGeoObject) MdAttributeConcreteInfo(com.runwaysdk.constants.MdAttributeConcreteInfo) Collectors(java.util.stream.Collectors) ProgressService(net.geoprism.registry.progress.ProgressService) FileNotFoundException(java.io.FileNotFoundException) Page(net.geoprism.registry.view.Page) List(java.util.List) MdAttributeDoubleInfo(com.runwaysdk.constants.MdAttributeDoubleInfo) MdAttributeMultiLineString(com.runwaysdk.system.gis.metadata.MdAttributeMultiLineString) MdAttributeMultiPoint(com.runwaysdk.system.gis.metadata.MdAttributeMultiPoint) MdAttributeMultiPolygon(com.runwaysdk.system.gis.metadata.MdAttributeMultiPolygon) MdAttributeCharacter(com.runwaysdk.system.metadata.MdAttributeCharacter) Entry(java.util.Map.Entry) MdAttributeLineString(com.runwaysdk.system.gis.metadata.MdAttributeLineString) GeometryType(org.commongeoregistry.adapter.constants.GeometryType) MdAttributeIndices(com.runwaysdk.system.metadata.MdAttributeIndices) ProgrammingErrorException(com.runwaysdk.dataaccess.ProgrammingErrorException) Transaction(com.runwaysdk.dataaccess.transaction.Transaction) AttributeClassificationType(org.commongeoregistry.adapter.metadata.AttributeClassificationType) CurationService(net.geoprism.registry.curation.CurationService) HashMap(java.util.HashMap) ListTypeVersionPageQuery(net.geoprism.registry.query.ListTypeVersionPageQuery) LocalizedValue(org.commongeoregistry.adapter.dataaccess.LocalizedValue) MdAttributeLocalInfo(com.runwaysdk.constants.MdAttributeLocalInfo) Progress(net.geoprism.registry.progress.Progress) Constants(com.runwaysdk.constants.Constants) Point(com.vividsolutions.jts.geom.Point) ServiceFactory(net.geoprism.registry.service.ServiceFactory) Classifier(net.geoprism.ontology.Classifier) MdAttributeConcreteDAOIF(com.runwaysdk.dataaccess.MdAttributeConcreteDAOIF) DefaultAttribute(org.commongeoregistry.adapter.constants.DefaultAttribute) LocalizationFacade(com.runwaysdk.localization.LocalizationFacade) BasicCondition(com.runwaysdk.query.BasicCondition) MdAttributeCharacterInfo(com.runwaysdk.constants.MdAttributeCharacterInfo) GeoserverCreateWMSCommand(net.geoprism.registry.command.GeoserverCreateWMSCommand) LocalizedValueConverter(net.geoprism.registry.conversion.LocalizedValueConverter) MdAttributeUUIDDAO(com.runwaysdk.dataaccess.metadata.MdAttributeUUIDDAO) LinkedList(java.util.LinkedList) LocalStruct(com.runwaysdk.business.LocalStruct) MdAttributeGeometry(com.runwaysdk.system.gis.metadata.MdAttributeGeometry) MdAttributeDateTime(com.runwaysdk.system.metadata.MdAttributeDateTime) ServerGeoObjectIF(net.geoprism.registry.model.ServerGeoObjectIF) ServerHierarchyType(net.geoprism.registry.model.ServerHierarchyType) MdAttributeConcreteDAO(com.runwaysdk.dataaccess.metadata.MdAttributeConcreteDAO) Term(org.commongeoregistry.adapter.Term) AttributeTermType(org.commongeoregistry.adapter.metadata.AttributeTermType) FileInputStream(java.io.FileInputStream) AttributeIntegerType(org.commongeoregistry.adapter.metadata.AttributeIntegerType) OIterator(com.runwaysdk.query.OIterator) Session(com.runwaysdk.session.Session) MdAttributePointDAOIF(com.runwaysdk.gis.dataaccess.MdAttributePointDAOIF) Collections(java.util.Collections) InputStream(java.io.InputStream) MdBusinessDAOIF(com.runwaysdk.dataaccess.MdBusinessDAOIF) ListTypeShapefileExporter(net.geoprism.registry.shapefile.ListTypeShapefileExporter) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) FileOutputStream(java.io.FileOutputStream) MdAttributeMultiLineString(com.runwaysdk.system.gis.metadata.MdAttributeMultiLineString) MdAttributeLineString(com.runwaysdk.system.gis.metadata.MdAttributeLineString) IOException(java.io.IOException) File(java.io.File) ProgrammingErrorException(com.runwaysdk.dataaccess.ProgrammingErrorException)

Example 4 with ListTypeShapefileExporter

use of net.geoprism.registry.shapefile.ListTypeShapefileExporter in project geoprism-registry by terraframe.

the class ListTypeGeoObjectShapefileExporterTest method testGenerateName.

@Test
@Request
public void testGenerateName() {
    ListTypeShapefileExporter exporter = new ListTypeShapefileExporter(version, mdBusiness, mdAttributes, null);
    Assert.assertEquals("testestest", exporter.generateColumnName("testestestest1"));
    Assert.assertEquals("testestes1", exporter.generateColumnName("testestestest2"));
    Assert.assertEquals("testestes2", exporter.generateColumnName("testestestest3"));
    Assert.assertEquals("testestes3", exporter.generateColumnName("testestestest4"));
    Assert.assertEquals("testestes4", exporter.generateColumnName("testestestest5"));
    Assert.assertEquals("testestes5", exporter.generateColumnName("testestestest6"));
    Assert.assertEquals("testestes6", exporter.generateColumnName("testestestest7"));
    Assert.assertEquals("testestes7", exporter.generateColumnName("testestestest8"));
    Assert.assertEquals("testestes8", exporter.generateColumnName("testestestest9"));
    Assert.assertEquals("testestes9", exporter.generateColumnName("testestestest10"));
    Assert.assertEquals("testeste10", exporter.generateColumnName("testestestest11"));
}
Also used : ListTypeShapefileExporter(net.geoprism.registry.shapefile.ListTypeShapefileExporter) ListTypeTest(net.geoprism.registry.service.ListTypeTest) Test(org.junit.Test) Request(com.runwaysdk.session.Request)

Example 5 with ListTypeShapefileExporter

use of net.geoprism.registry.shapefile.ListTypeShapefileExporter in project geoprism-registry by terraframe.

the class ListTypeGeoObjectShapefileExporterTest method testWriteToFile.

@Test
@Request
public void testWriteToFile() throws IOException {
    ListTypeShapefileExporter exporter = new ListTypeShapefileExporter(version, mdBusiness, mdAttributes, new JsonObject());
    File directory = exporter.writeToFile();
    Assert.assertTrue(directory.exists());
    File[] files = directory.listFiles();
    Assert.assertEquals(7, files.length);
}
Also used : ListTypeShapefileExporter(net.geoprism.registry.shapefile.ListTypeShapefileExporter) JsonObject(com.google.gson.JsonObject) File(java.io.File) ListTypeTest(net.geoprism.registry.service.ListTypeTest) Test(org.junit.Test) Request(com.runwaysdk.session.Request)

Aggregations

ListTypeShapefileExporter (net.geoprism.registry.shapefile.ListTypeShapefileExporter)7 JsonObject (com.google.gson.JsonObject)5 Request (com.runwaysdk.session.Request)5 ListTypeTest (net.geoprism.registry.service.ListTypeTest)5 Test (org.junit.Test)5 InputStream (java.io.InputStream)3 JsonParser (com.google.gson.JsonParser)2 Authenticate (com.runwaysdk.business.rbac.Authenticate)2 MdAttributeConcreteDAOIF (com.runwaysdk.dataaccess.MdAttributeConcreteDAOIF)2 MdBusinessDAOIF (com.runwaysdk.dataaccess.MdBusinessDAOIF)2 ProgrammingErrorException (com.runwaysdk.dataaccess.ProgrammingErrorException)2 MdBusinessDAO (com.runwaysdk.dataaccess.metadata.MdBusinessDAO)2 Transaction (com.runwaysdk.dataaccess.transaction.Transaction)2 File (java.io.File)2 IOException (java.io.IOException)2 ParseException (java.text.ParseException)2 SimpleDateFormat (java.text.SimpleDateFormat)2 Date (java.util.Date)2 List (java.util.List)2 Collectors (java.util.stream.Collectors)2