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")));
}
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);
}
}
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;
}
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"));
}
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);
}
Aggregations