Search in sources :

Example 26 with MdBusinessDAOIF

use of com.runwaysdk.dataaccess.MdBusinessDAOIF in project geoprism-registry by terraframe.

the class MasterListExcelExporter method createMetadataSheet.

private void createMetadataSheet(Workbook workbook) {
    Sheet sheet = workbook.createSheet(this.getSheetName(workbook, "masterlist.metadata"));
    Locale locale = Session.getCurrentLocale();
    MdBusinessDAOIF metadata = MdBusinessDAO.getMdBusinessDAO(MasterList.CLASS);
    int rowNumber = 0;
    this.createRow(sheet, locale, metadata, rowNumber++, MasterList.DISPLAYLABEL, this.list.getDisplayLabel().getValue());
    this.createRow(sheet, locale, metadata, rowNumber++, MasterList.CODE, this.list.getCode());
    this.createRow(sheet, rowNumber++, LocalizationFacade.getFromBundles("masterlist.publishDate"), stripTime(this.version.getPublishDate()));
    this.createRow(sheet, rowNumber++, LocalizationFacade.getFromBundles("masterlist.forDate"), stripTime(this.version.getForDate()));
    this.createRow(sheet, locale, metadata, rowNumber++, MasterList.DESCRIPTIONLOCAL, this.list.getDescriptionLocal().getValue());
    this.createRow(sheet, locale, metadata, rowNumber++, MasterList.PROCESSLOCAL, this.list.getProcessLocal().getValue());
    this.createRow(sheet, locale, metadata, rowNumber++, MasterList.PROGRESSLOCAL, this.list.getProgressLocal().getValue());
    this.createRow(sheet, locale, metadata, rowNumber++, MasterList.ACCESSCONSTRAINTSLOCAL, this.list.getAccessConstraintsLocal().getValue());
    this.createRow(sheet, locale, metadata, rowNumber++, MasterList.USECONSTRAINTSLOCAL, this.list.getUseConstraintsLocal().getValue());
    this.createRow(sheet, locale, metadata, rowNumber++, MasterList.ACKNOWLEDGEMENTSLOCAL, this.list.getAcknowledgementsLocal().getValue());
    this.createRow(sheet, locale, metadata, rowNumber++, MasterList.DISCLAIMERLOCAL, this.list.getDisclaimerLocal().getValue());
    rowNumber++;
    this.createRow(sheet, locale, metadata, rowNumber++, MasterList.CONTACTNAME, this.list.getContactName());
    this.createRow(sheet, locale, metadata, rowNumber++, MasterList.ORGANIZATION, this.list.getOrganization().getDisplayLabel().getValue());
    this.createRow(sheet, locale, metadata, rowNumber++, MasterList.TELEPHONENUMBER, this.list.getTelephoneNumber());
    this.createRow(sheet, locale, metadata, rowNumber++, MasterList.EMAIL, this.list.getEmail());
}
Also used : Locale(java.util.Locale) MdBusinessDAOIF(com.runwaysdk.dataaccess.MdBusinessDAOIF) Sheet(org.apache.poi.ss.usermodel.Sheet) Point(com.vividsolutions.jts.geom.Point)

Example 27 with MdBusinessDAOIF

use of com.runwaysdk.dataaccess.MdBusinessDAOIF in project geoprism-registry by terraframe.

the class ListTypeShapefileExporter method writeDictionaryFile.

/**
 * Writes an additional "data dictionary" / metadata excel spreadsheet to the
 * directory, which is intended to be part of the final Shapfile. This is
 * useful for downstream developers trying to make sense of the GIS data.
 *
 * See also: - https://github.com/terraframe/geoprism-registry/issues/628
 */
private void writeDictionaryFile(File directory) {
    MdBusinessDAOIF mdBusiness = MdBusinessDAO.get(this.version.getMdBusinessOid());
    List<? extends MdAttributeConcreteDAOIF> mdAttributes = mdBusiness.definesAttributesOrdered().stream().filter(mdAttribute -> this.version.isValid(mdAttribute)).collect(Collectors.toList());
    mdAttributes = mdAttributes.stream().filter(mdAttribute -> !mdAttribute.definesAttribute().equals("invalid")).collect(Collectors.toList());
    try {
        File file = new File(directory, "metadata.xlsx");
        FileOutputStream fos = new FileOutputStream(file);
        ListTypeExcelExporter exporter = new ListTypeExcelExporter(this.version, mdBusiness, mdAttributes, new ListTypeExcelExporterSheet[] { ListTypeExcelExporterSheet.DICTIONARY, ListTypeExcelExporterSheet.METADATA }, criteria);
        Workbook wb = exporter.createWorkbook();
        wb.write(fos);
    } catch (IOException e) {
        throw new ProgrammingErrorException(e);
    }
}
Also used : MdAttributeMultiPointDAOIF(com.runwaysdk.gis.dataaccess.MdAttributeMultiPointDAOIF) SimpleFeatureBuilder(org.geotools.feature.simple.SimpleFeatureBuilder) JsonObject(com.google.gson.JsonObject) Transaction(org.geotools.data.Transaction) Date(java.util.Date) MdAttributeBooleanDAOIF(com.runwaysdk.dataaccess.MdAttributeBooleanDAOIF) LoggerFactory(org.slf4j.LoggerFactory) GeoObject(org.commongeoregistry.adapter.dataaccess.GeoObject) SimpleFeatureStore(org.geotools.data.simple.SimpleFeatureStore) MdAttributeFloatDAOIF(com.runwaysdk.dataaccess.MdAttributeFloatDAOIF) SimpleFeatureTypeBuilder(org.geotools.feature.simple.SimpleFeatureTypeBuilder) PipedInputStream(java.io.PipedInputStream) SimpleFeature(org.opengis.feature.simple.SimpleFeature) Map(java.util.Map) MdAttributeCharacterDAOIF(com.runwaysdk.dataaccess.MdAttributeCharacterDAOIF) ShapefileDataStore(org.geotools.data.shapefile.ShapefileDataStore) ZipEntry(java.util.zip.ZipEntry) MdAttributeGeometryDAOIF(com.runwaysdk.gis.dataaccess.MdAttributeGeometryDAOIF) MdAttributeTextDAOIF(com.runwaysdk.dataaccess.MdAttributeTextDAOIF) BusinessQuery(com.runwaysdk.business.BusinessQuery) UnsupportedOperationException(com.amazonaws.services.kms.model.UnsupportedOperationException) ListTypeExcelExporter(net.geoprism.registry.excel.ListTypeExcelExporter) DefaultGeographicCRS(org.geotools.referencing.crs.DefaultGeographicCRS) MdAttributeLongDAOIF(com.runwaysdk.dataaccess.MdAttributeLongDAOIF) Collectors(java.util.stream.Collectors) Serializable(java.io.Serializable) IOUtils(org.apache.commons.io.IOUtils) List(java.util.List) MdAttributeLineStringDAOIF(com.runwaysdk.gis.dataaccess.MdAttributeLineStringDAOIF) MdAttributeDateDAOIF(com.runwaysdk.dataaccess.MdAttributeDateDAOIF) ZipOutputStream(java.util.zip.ZipOutputStream) ListFeatureCollection(org.geotools.data.collection.ListFeatureCollection) ProgrammingErrorException(com.runwaysdk.dataaccess.ProgrammingErrorException) MdAttributeMultiPolygonDAOIF(com.runwaysdk.gis.dataaccess.MdAttributeMultiPolygonDAOIF) ListTypeExcelExporterSheet(net.geoprism.registry.excel.ListTypeExcelExporter.ListTypeExcelExporterSheet) HashMap(java.util.HashMap) ShapefileDataStoreFactory(org.geotools.data.shapefile.ShapefileDataStoreFactory) FeatureCollection(org.geotools.feature.FeatureCollection) MdAttributeDoubleDAOIF(com.runwaysdk.dataaccess.MdAttributeDoubleDAOIF) SimpleFeatureType(org.opengis.feature.simple.SimpleFeatureType) LineString(com.vividsolutions.jts.geom.LineString) Point(com.vividsolutions.jts.geom.Point) ArrayList(java.util.ArrayList) SimpleFeatureSource(org.geotools.data.simple.SimpleFeatureSource) MdAttributeMultiLineStringDAOIF(com.runwaysdk.gis.dataaccess.MdAttributeMultiLineStringDAOIF) MdAttributeConcreteDAOIF(com.runwaysdk.dataaccess.MdAttributeConcreteDAOIF) DefaultAttribute(org.commongeoregistry.adapter.constants.DefaultAttribute) Charset(java.nio.charset.Charset) SessionPredicate(net.geoprism.gis.geoserver.SessionPredicate) MultiPolygon(com.vividsolutions.jts.geom.MultiPolygon) VaultProperties(com.runwaysdk.constants.VaultProperties) Logger(org.slf4j.Logger) MdBusinessDAOIF(com.runwaysdk.dataaccess.MdBusinessDAOIF) FileOutputStream(java.io.FileOutputStream) IOException(java.io.IOException) FileUtils(org.apache.commons.io.FileUtils) MdAttributeDateTimeDAOIF(com.runwaysdk.dataaccess.MdAttributeDateTimeDAOIF) FileInputStream(java.io.FileInputStream) PipedOutputStream(java.io.PipedOutputStream) RegistryConstants(net.geoprism.registry.RegistryConstants) File(java.io.File) ListType(net.geoprism.registry.ListType) ListTypeVersion(net.geoprism.registry.ListTypeVersion) OIterator(com.runwaysdk.query.OIterator) MdAttributeIntegerDAOIF(com.runwaysdk.dataaccess.MdAttributeIntegerDAOIF) Workbook(org.apache.poi.ss.usermodel.Workbook) MdAttributePolygonDAOIF(com.runwaysdk.gis.dataaccess.MdAttributePolygonDAOIF) MultiPoint(com.vividsolutions.jts.geom.MultiPoint) Business(com.runwaysdk.business.Business) MdBusinessDAO(com.runwaysdk.dataaccess.metadata.MdBusinessDAO) MultiLineString(com.vividsolutions.jts.geom.MultiLineString) DefaultTransaction(org.geotools.data.DefaultTransaction) MdAttributePointDAOIF(com.runwaysdk.gis.dataaccess.MdAttributePointDAOIF) InputStream(java.io.InputStream) Polygon(com.vividsolutions.jts.geom.Polygon) MdBusinessDAOIF(com.runwaysdk.dataaccess.MdBusinessDAOIF) FileOutputStream(java.io.FileOutputStream) ListTypeExcelExporter(net.geoprism.registry.excel.ListTypeExcelExporter) IOException(java.io.IOException) File(java.io.File) Workbook(org.apache.poi.ss.usermodel.Workbook) ProgrammingErrorException(com.runwaysdk.dataaccess.ProgrammingErrorException)

Example 28 with MdBusinessDAOIF

use of com.runwaysdk.dataaccess.MdBusinessDAOIF in project geoprism-registry by terraframe.

the class VectorTileBuilder method getResultSet.

private ResultSet getResultSet() {
    MdBusinessDAOIF mdBusiness = MdBusinessDAO.get(this.version.getMdBusinessOid());
    MdAttributeConcreteDAOIF geomAttribute = mdBusiness.definesAttribute(RegistryConstants.GEOMETRY_ATTRIBUTE_NAME);
    MdAttributeConcreteDAOIF labelAttribute = mdBusiness.definesAttribute(DefaultAttribute.DISPLAY_LABEL.getName() + MasterListVersion.DEFAULT_LOCALE);
    String column = geomAttribute.getColumnName();
    String labelColumn = labelAttribute.getColumnName();
    StringBuilder sql = new StringBuilder();
    sql.append("SELECT ge.oid");
    sql.append(", ge.uid");
    sql.append(", ge.code");
    sql.append(", ge." + labelColumn + " AS default_locale");
    for (Locale locale : locales) {
        MdAttributeConcreteDAOIF localeAttribute = mdBusiness.definesAttribute(DefaultAttribute.DISPLAY_LABEL.getName() + locale.toString());
        if (localeAttribute != null) {
            sql.append(", ge." + localeAttribute.getColumnName() + " AS " + locale.toString());
        }
    }
    sql.append(", ST_Transform(ge." + column + ", 3857) AS " + GeoserverFacade.GEOM_COLUMN + "\n ");
    sql.append("FROM " + mdBusiness.getTableName() + " AS ge\n ");
    sql.append("WHERE ge." + column + " IS NOT NULL\n ");
    sql.append("AND ge.invalid=0");
    return Database.query(sql.toString());
}
Also used : Locale(java.util.Locale) MdBusinessDAOIF(com.runwaysdk.dataaccess.MdBusinessDAOIF) MdAttributeConcreteDAOIF(com.runwaysdk.dataaccess.MdAttributeConcreteDAOIF)

Example 29 with MdBusinessDAOIF

use of com.runwaysdk.dataaccess.MdBusinessDAOIF in project geoprism-registry by terraframe.

the class ListTypeInheritedHierarchyTest method testPublishVersion.

@Test
@Request
public void testPublishVersion() {
    TestDataSet.runAsUser(USATestData.USER_ADMIN, (request, adapter) -> {
        JsonObject json = ListTypeTest.getJson(USATestData.ORG_NPS.getServerObject(), USATestData.HIER_SCHOOL, USATestData.SCHOOL_ZONE, USATestData.COUNTRY, USATestData.STATE, USATestData.DISTRICT);
        ListType test = ListType.apply(json);
        try {
            ListTypeEntry entry = test.getOrCreateEntry(new Date(), null);
            ListTypeVersion version = entry.getWorking();
            try {
                MdBusinessDAOIF mdTable = MdBusinessDAO.get(version.getMdBusinessOid());
                Assert.assertNotNull(mdTable);
                version.publish();
            } finally {
                entry.delete();
            }
        } finally {
            test.delete();
        }
    });
}
Also used : MdBusinessDAOIF(com.runwaysdk.dataaccess.MdBusinessDAOIF) ListTypeEntry(net.geoprism.registry.ListTypeEntry) ListType(net.geoprism.registry.ListType) JsonObject(com.google.gson.JsonObject) ListTypeVersion(net.geoprism.registry.ListTypeVersion) Date(java.util.Date) Test(org.junit.Test) Request(com.runwaysdk.session.Request)

Example 30 with MdBusinessDAOIF

use of com.runwaysdk.dataaccess.MdBusinessDAOIF in project geoprism-registry by terraframe.

the class ListTypeTest method dataTest.

private void dataTest(Boolean includeGeometries) {
    GeoJSONReader reader = new GeoJSONReader();
    TestDataSet.runAsUser(USATestData.USER_ADMIN, (request, adapter) -> {
        ListTypeBuilder.Hierarchy hierarchy = new ListTypeBuilder.Hierarchy();
        hierarchy.setType(USATestData.HIER_ADMIN);
        hierarchy.setParents(USATestData.COUNTRY, USATestData.STATE, USATestData.DISTRICT);
        hierarchy.setSubtypeHierarchies(USATestData.HIER_REPORTS_TO);
        ListTypeBuilder builder = new ListTypeBuilder();
        builder.setOrg(USATestData.ORG_NPS.getServerObject());
        builder.setInfo(USATestData.HEALTH_FACILITY);
        builder.setHts(hierarchy);
        ListType test = builder.build();
        try {
            ListTypeEntry entry = test.createEntry(TestDataSet.DEFAULT_OVER_TIME_DATE);
            try {
                entry.publish(createVersionMetadata().toString());
                List<ListTypeVersion> versions = entry.getVersions();
                Assert.assertEquals(2, versions.size());
                ListTypeVersion version = versions.get(0);
                MdBusinessDAOIF mdTable = MdBusinessDAO.get(version.getMdBusinessOid());
                Assert.assertNotNull(mdTable);
                Page<JsonSerializable> data = version.data(new JsonObject(), true, includeGeometries);
                // Entries should be HP_1, HP_2, HS_1, HS_2
                Assert.assertEquals(new Long(4), data.getCount());
                List<JsonSerializable> results = data.getResults();
                for (int i = 0; i < results.size(); i++) {
                    JsonObject result = results.get(i).toJSON().getAsJsonObject();
                    String code = result.get("code").getAsString();
                    if (code.equals(USATestData.HS_ONE.getCode())) {
                        String reportsTo = result.get("usatestdatareportstocode").getAsString();
                        Assert.assertEquals(USATestData.HP_ONE.getCode(), reportsTo);
                    } else if (code.equals(USATestData.HS_TWO.getCode())) {
                        String reportsTo = result.get("usatestdatareportstocode").getAsString();
                        Assert.assertEquals(USATestData.HP_TWO.getCode(), reportsTo);
                    }
                    if (includeGeometries != null && includeGeometries.equals(Boolean.TRUE)) {
                        Assert.assertEquals(true, result.has("geometry"));
                        JsonObject geometries = result.get("geometry").getAsJsonObject();
                        Geometry jtsGeom = reader.read(geometries.toString());
                        Assert.assertTrue(jtsGeom.isValid());
                    } else {
                        Assert.assertEquals(false, result.has("geometry"));
                    }
                }
            } finally {
                entry.delete();
            }
        } catch (Throwable t) {
            t.printStackTrace();
            throw new RuntimeException(t);
        } finally {
            test.delete();
        }
    });
}
Also used : MdBusinessDAOIF(com.runwaysdk.dataaccess.MdBusinessDAOIF) ListTypeEntry(net.geoprism.registry.ListTypeEntry) JsonSerializable(net.geoprism.registry.view.JsonSerializable) JsonObject(com.google.gson.JsonObject) ListTypeVersion(net.geoprism.registry.ListTypeVersion) Geometry(com.vividsolutions.jts.geom.Geometry) GeoJSONReader(org.wololo.jts2geojson.GeoJSONReader) SingleListType(net.geoprism.registry.SingleListType) IntervalListType(net.geoprism.registry.IntervalListType) ListType(net.geoprism.registry.ListType) IncrementalListType(net.geoprism.registry.IncrementalListType) ListTypeBuilder(net.geoprism.registry.ListTypeBuilder)

Aggregations

MdBusinessDAOIF (com.runwaysdk.dataaccess.MdBusinessDAOIF)30 MdAttributeConcreteDAOIF (com.runwaysdk.dataaccess.MdAttributeConcreteDAOIF)18 JsonObject (com.google.gson.JsonObject)15 Date (java.util.Date)11 ProgrammingErrorException (com.runwaysdk.dataaccess.ProgrammingErrorException)10 BusinessQuery (com.runwaysdk.business.BusinessQuery)9 IOException (java.io.IOException)9 SimpleDateFormat (java.text.SimpleDateFormat)9 Locale (java.util.Locale)9 JsonArray (com.google.gson.JsonArray)8 MdBusinessDAO (com.runwaysdk.dataaccess.metadata.MdBusinessDAO)8 QueryFactory (com.runwaysdk.query.QueryFactory)8 InputStream (java.io.InputStream)8 List (java.util.List)8 Collectors (java.util.stream.Collectors)8 Transaction (com.runwaysdk.dataaccess.transaction.Transaction)7 MdAttributeLineString (com.runwaysdk.system.gis.metadata.MdAttributeLineString)7 MdAttributeMultiLineString (com.runwaysdk.system.gis.metadata.MdAttributeMultiLineString)7 ParseException (java.text.ParseException)7 JsonParser (com.google.gson.JsonParser)6