Search in sources :

Example 31 with MdAttributeConcreteDAOIF

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

the class ServerGeoObjectTypeConverter method convertAttributeTypes.

public GeoObjectType convertAttributeTypes(Universal uni, GeoObjectType gt, MdBusiness mdBusiness) {
    if (mdBusiness != null) {
        MdBusinessDAOIF mdBusinessDAOIF = (MdBusinessDAOIF) BusinessFacade.getEntityDAO(mdBusiness);
        // Standard attributes are defined by default on the GeoObjectType
        AttributeTypeConverter builder = new AttributeTypeConverter();
        List<? extends MdAttributeConcreteDAOIF> definedMdAttributeList = mdBusinessDAOIF.getAllDefinedMdAttributes();
        for (MdAttributeConcreteDAOIF mdAttribute : definedMdAttributeList) {
            if (this.convertMdAttributeToAttributeType(mdAttribute)) {
                AttributeType attributeType = builder.build(mdAttribute);
                if (attributeType != null) {
                    gt.addAttribute(attributeType);
                }
            }
        }
    }
    return gt;
}
Also used : MdBusinessDAOIF(com.runwaysdk.dataaccess.MdBusinessDAOIF) AttributeType(org.commongeoregistry.adapter.metadata.AttributeType) MdAttributeConcreteDAOIF(com.runwaysdk.dataaccess.MdAttributeConcreteDAOIF)

Example 32 with MdAttributeConcreteDAOIF

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

the class ListTypeExcelExporter method createDataDictionarySheet.

private void createDataDictionarySheet(Workbook workbook) {
    Sheet sheet = workbook.createSheet(getSheetName(workbook, "masterlist.data.dictionary"));
    Locale locale = Session.getCurrentLocale();
    int rowNumber = 0;
    for (MdAttributeConcreteDAOIF mdAttribute : mdAttributes) {
        this.createRow(sheet, locale, rowNumber++, mdAttribute, mdAttribute.getDescription(locale));
    }
}
Also used : Locale(java.util.Locale) Sheet(org.apache.poi.ss.usermodel.Sheet) Point(com.vividsolutions.jts.geom.Point) MdAttributeConcreteDAOIF(com.runwaysdk.dataaccess.MdAttributeConcreteDAOIF)

Example 33 with MdAttributeConcreteDAOIF

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

the class ServerGeoObjectType method updateMdAttributeFromAttributeType.

/**
 * Creates an {@link MdAttributeConcrete} for the given {@link MdBusiness}
 * from the given {@link AttributeType}
 *
 * @pre assumes no attribute has been defined on the type with the given name.
 *
 * @param mdBusiness
 *          Type to receive attribute definition
 * @param attributeType
 *          newly defined attribute
 *
 * @return {@link AttributeType}
 */
@Transaction
public static MdAttributeConcrete updateMdAttributeFromAttributeType(MdClass mdClass, AttributeType attributeType) {
    MdAttributeConcreteDAOIF mdAttributeConcreteDAOIF = getMdAttribute(mdClass, attributeType.getName());
    if (mdAttributeConcreteDAOIF != null) {
        // Get the type safe version
        MdAttributeConcrete mdAttribute = (MdAttributeConcrete) BusinessFacade.get(mdAttributeConcreteDAOIF);
        mdAttribute.lock();
        try {
            // The name cannot be updated
            // mdAttribute.setAttributeName(attributeType.getName());
            LocalizedValueConverter.populate(mdAttribute.getDisplayLabel(), attributeType.getLabel());
            LocalizedValueConverter.populate(mdAttribute.getDescription(), attributeType.getDescription());
            if (attributeType instanceof AttributeFloatType) {
                // Refresh the terms
                AttributeFloatType attributeFloatType = (AttributeFloatType) attributeType;
                mdAttribute.setValue(MdAttributeDoubleInfo.LENGTH, Integer.toString(attributeFloatType.getPrecision()));
                mdAttribute.setValue(MdAttributeDoubleInfo.DECIMAL, Integer.toString(attributeFloatType.getScale()));
            } else if (attributeType instanceof AttributeClassificationType) {
                MdAttributeClassification mdAttributeTerm = (MdAttributeClassification) mdAttribute;
                AttributeClassificationType attributeClassificationType = (AttributeClassificationType) attributeType;
                String classificationTypeCode = attributeClassificationType.getClassificationType();
                ClassificationType classificationType = ClassificationType.getByCode(classificationTypeCode);
                Term root = attributeClassificationType.getRootTerm();
                if (root != null) {
                    Classification classification = Classification.get(classificationType, root.getCode());
                    mdAttributeTerm.setValue(MdAttributeClassification.ROOT, classification.getOid());
                }
            }
            mdAttribute.apply();
        } finally {
            mdAttribute.unlock();
        }
        if (attributeType instanceof AttributeTermType) {
            // Refresh the terms
            AttributeTermType attributeTermType = (AttributeTermType) attributeType;
            org.commongeoregistry.adapter.Term getRootTerm = attributeTermType.getRootTerm();
            String classifierKey = TermConverter.buildClassifierKeyFromTermCode(getRootTerm.getCode());
            TermConverter termBuilder = new TermConverter(classifierKey);
            attributeTermType.setRootTerm(termBuilder.build());
        }
        return mdAttribute;
    }
    return null;
}
Also used : MdAttributeClassification(com.runwaysdk.system.metadata.MdAttributeClassification) Term(org.commongeoregistry.adapter.Term) MdAttributeTerm(com.runwaysdk.system.metadata.MdAttributeTerm) Term(org.commongeoregistry.adapter.Term) AttributeClassificationType(org.commongeoregistry.adapter.metadata.AttributeClassificationType) AttributeClassificationType(org.commongeoregistry.adapter.metadata.AttributeClassificationType) AttributeFloatType(org.commongeoregistry.adapter.metadata.AttributeFloatType) MdAttributeClassification(com.runwaysdk.system.metadata.MdAttributeClassification) MdAttributeConcrete(com.runwaysdk.system.metadata.MdAttributeConcrete) AttributeTermType(org.commongeoregistry.adapter.metadata.AttributeTermType) TermConverter(net.geoprism.registry.conversion.TermConverter) MdAttributeConcreteDAOIF(com.runwaysdk.dataaccess.MdAttributeConcreteDAOIF) Transaction(com.runwaysdk.dataaccess.transaction.Transaction)

Example 34 with MdAttributeConcreteDAOIF

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

the class ListTypeShapefileExporter method features.

public FeatureCollection<SimpleFeatureType, SimpleFeature> features(SimpleFeatureType featureType) {
    List<SimpleFeature> features = new ArrayList<SimpleFeature>();
    SimpleFeatureBuilder builder = new SimpleFeatureBuilder(featureType);
    BusinessQuery query = this.version.buildQuery(this.criteria);
    query.ORDER_BY_DESC(query.aCharacter(DefaultAttribute.CODE.getName()));
    OIterator<Business> objects = query.getIterator();
    try {
        while (objects.hasNext()) {
            Business row = objects.next();
            builder.set(GEOM, row.getObjectValue(RegistryConstants.GEOMETRY_ATTRIBUTE_NAME));
            for (MdAttributeConcreteDAOIF mdAttribute : mdAttributes) {
                String attributeName = mdAttribute.definesAttribute();
                Object value = row.getObjectValue(attributeName);
                if (value != null) {
                    builder.set(this.getColumnName(attributeName), value);
                }
            }
            SimpleFeature feature = builder.buildFeature(row.getValue(DefaultAttribute.CODE.getName()));
            features.add(feature);
        }
    } finally {
        objects.close();
    }
    return new ListFeatureCollection(featureType, features);
}
Also used : BusinessQuery(com.runwaysdk.business.BusinessQuery) ArrayList(java.util.ArrayList) ListFeatureCollection(org.geotools.data.collection.ListFeatureCollection) JsonObject(com.google.gson.JsonObject) GeoObject(org.commongeoregistry.adapter.dataaccess.GeoObject) LineString(com.vividsolutions.jts.geom.LineString) MultiLineString(com.vividsolutions.jts.geom.MultiLineString) SimpleFeature(org.opengis.feature.simple.SimpleFeature) SimpleFeatureBuilder(org.geotools.feature.simple.SimpleFeatureBuilder) Business(com.runwaysdk.business.Business) MdAttributeConcreteDAOIF(com.runwaysdk.dataaccess.MdAttributeConcreteDAOIF)

Example 35 with MdAttributeConcreteDAOIF

use of com.runwaysdk.dataaccess.MdAttributeConcreteDAOIF 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)

Aggregations

MdAttributeConcreteDAOIF (com.runwaysdk.dataaccess.MdAttributeConcreteDAOIF)36 MdBusinessDAOIF (com.runwaysdk.dataaccess.MdBusinessDAOIF)18 JsonObject (com.google.gson.JsonObject)16 Date (java.util.Date)12 BusinessQuery (com.runwaysdk.business.BusinessQuery)11 ProgrammingErrorException (com.runwaysdk.dataaccess.ProgrammingErrorException)11 Point (com.vividsolutions.jts.geom.Point)11 SimpleDateFormat (java.text.SimpleDateFormat)11 JsonArray (com.google.gson.JsonArray)10 MdAttributePointDAOIF (com.runwaysdk.gis.dataaccess.MdAttributePointDAOIF)10 Transaction (com.runwaysdk.dataaccess.transaction.Transaction)9 MdAttributeLineString (com.runwaysdk.system.gis.metadata.MdAttributeLineString)9 MdAttributeMultiLineString (com.runwaysdk.system.gis.metadata.MdAttributeMultiLineString)9 IOException (java.io.IOException)9 ParseException (java.text.ParseException)9 Locale (java.util.Locale)9 Business (com.runwaysdk.business.Business)8 MdBusinessDAO (com.runwaysdk.dataaccess.metadata.MdBusinessDAO)8 InputStream (java.io.InputStream)8 List (java.util.List)8