Search in sources :

Example 21 with MdBusinessDAOIF

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

the class MasterListVersion method data.

public JsonObject data(Integer pageNumber, Integer pageSize, String filterJson, String sort, Boolean includeGeometries) {
    if (includeGeometries == null) {
        includeGeometries = Boolean.FALSE;
    }
    SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
    format.setTimeZone(GeoRegistryUtil.SYSTEM_TIMEZONE);
    NumberFormat numberFormat = NumberFormat.getInstance(Session.getCurrentLocale());
    JsonArray results = new JsonArray();
    MdBusinessDAOIF mdBusiness = MdBusinessDAO.get(this.getMdBusinessOid());
    List<? extends MdAttributeConcreteDAOIF> mdAttributes = mdBusiness.definesAttributes();
    BusinessQuery query = this.buildQuery(filterJson);
    if (sort != null && sort.length() > 0) {
        JsonObject jObject = JsonParser.parseString(sort).getAsJsonObject();
        String attribute = jObject.get("attribute").getAsString();
        String order = jObject.get("order").getAsString();
        if (order.equalsIgnoreCase("DESC")) {
            query.ORDER_BY_DESC(query.getS(attribute));
        } else {
            query.ORDER_BY_ASC(query.getS(attribute));
        }
        if (!attribute.equals(DefaultAttribute.CODE.getName())) {
            query.ORDER_BY_ASC(query.aCharacter(DefaultAttribute.CODE.getName()));
        }
    }
    try (OIterator<Business> iterator = query.getIterator(pageSize, pageNumber)) {
        while (iterator.hasNext()) {
            Business row = iterator.next();
            JsonObject object = new JsonObject();
            MdAttributeConcreteDAOIF mdGeometry = mdBusiness.definesAttribute(RegistryConstants.GEOMETRY_ATTRIBUTE_NAME);
            if (includeGeometries) {
                Geometry geom = (Geometry) row.getObjectValue(mdGeometry.definesAttribute());
                if (geom != null) {
                    GeoJSONWriter gw = new GeoJSONWriter();
                    org.wololo.geojson.Geometry gJSON = gw.write(geom);
                    JsonObject geojson = JsonParser.parseString(gJSON.toString()).getAsJsonObject();
                    object.add("geometry", geojson);
                }
            }
            object.addProperty(ORIGINAL_OID, row.getValue(ORIGINAL_OID));
            for (MdAttributeConcreteDAOIF mdAttribute : mdAttributes) {
                if (this.isValid(mdAttribute)) {
                    String attributeName = mdAttribute.definesAttribute();
                    Object value = row.getObjectValue(attributeName);
                    if (value != null) {
                        if (value instanceof Double) {
                            object.addProperty(mdAttribute.definesAttribute(), numberFormat.format((Double) value));
                        } else if (value instanceof Number) {
                            object.addProperty(mdAttribute.definesAttribute(), (Number) value);
                        } else if (value instanceof Boolean) {
                            object.addProperty(mdAttribute.definesAttribute(), (Boolean) value);
                        } else if (value instanceof String) {
                            object.addProperty(mdAttribute.definesAttribute(), (String) value);
                        } else if (value instanceof Character) {
                            object.addProperty(mdAttribute.definesAttribute(), (Character) value);
                        } else if (value instanceof Date) {
                            object.addProperty(mdAttribute.definesAttribute(), format.format((Date) value));
                        }
                    }
                }
            }
            results.add(object);
        }
    }
    JsonObject page = new JsonObject();
    page.addProperty("pageNumber", pageNumber);
    page.addProperty("pageSize", pageSize);
    page.addProperty("filter", filterJson);
    page.addProperty("count", query.getCount());
    page.add("results", results);
    return page;
}
Also used : BusinessQuery(com.runwaysdk.business.BusinessQuery) MdBusinessDAOIF(com.runwaysdk.dataaccess.MdBusinessDAOIF) MdAttributeCharacter(com.runwaysdk.system.metadata.MdAttributeCharacter) JsonObject(com.google.gson.JsonObject) MdAttributeMultiLineString(com.runwaysdk.system.gis.metadata.MdAttributeMultiLineString) MdAttributeLineString(com.runwaysdk.system.gis.metadata.MdAttributeLineString) MdAttributeDouble(com.runwaysdk.system.metadata.MdAttributeDouble) Date(java.util.Date) JsonArray(com.google.gson.JsonArray) Geometry(com.vividsolutions.jts.geom.Geometry) MdAttributeGeometry(com.runwaysdk.system.gis.metadata.MdAttributeGeometry) VertexObject(com.runwaysdk.business.graph.VertexObject) JsonObject(com.google.gson.JsonObject) ValueObject(com.runwaysdk.dataaccess.ValueObject) VertexServerGeoObject(net.geoprism.registry.model.graph.VertexServerGeoObject) MdAttributeBoolean(com.runwaysdk.system.metadata.MdAttributeBoolean) AttributeBoolean(com.runwaysdk.query.AttributeBoolean) SimpleDateFormat(java.text.SimpleDateFormat) GeoJSONWriter(org.wololo.jts2geojson.GeoJSONWriter) NumberFormat(java.text.NumberFormat) MdBusiness(com.runwaysdk.system.metadata.MdBusiness) Business(com.runwaysdk.business.Business) MdAttributeConcreteDAOIF(com.runwaysdk.dataaccess.MdAttributeConcreteDAOIF)

Example 22 with MdBusinessDAOIF

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

the class MasterListVersion method removeAttributeType.

public void removeAttributeType(TableMetadata metadata, AttributeType attributeType) {
    Collection<Locale> locales = LocalizationFacade.getInstalledLocales();
    MdBusinessDAOIF mdBusiness = MdBusinessDAO.get(metadata.getMdBusiness().getOid());
    if (!(attributeType instanceof AttributeTermType || attributeType instanceof AttributeClassificationType || attributeType instanceof AttributeLocalType)) {
        removeAttribute(mdBusiness, attributeType.getName());
    } else if (attributeType instanceof AttributeTermType || attributeType instanceof AttributeClassificationType) {
        removeAttribute(mdBusiness, attributeType.getName());
        removeAttribute(mdBusiness, attributeType.getName() + DEFAULT_LOCALE);
        for (Locale locale : locales) {
            removeAttribute(mdBusiness, attributeType.getName() + locale.toString());
        }
    } else if (attributeType instanceof AttributeLocalType) {
        removeAttribute(mdBusiness, attributeType.getName() + DEFAULT_LOCALE);
        for (Locale locale : locales) {
            removeAttribute(mdBusiness, attributeType.getName() + locale.toString());
        }
    }
}
Also used : Locale(java.util.Locale) AttributeLocalType(org.commongeoregistry.adapter.metadata.AttributeLocalType) MdBusinessDAOIF(com.runwaysdk.dataaccess.MdBusinessDAOIF) AttributeTermType(org.commongeoregistry.adapter.metadata.AttributeTermType) AttributeClassificationType(org.commongeoregistry.adapter.metadata.AttributeClassificationType)

Example 23 with MdBusinessDAOIF

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

the class MasterListVersion method generateShapefile.

public File generateShapefile() {
    String filename = this.getOid() + ".zip";
    final MasterList list = this.getMasterlist();
    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 {
        MasterListShapefileExporter exporter = new MasterListShapefileExporter(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) MdAttributeMomentDAOIF(com.runwaysdk.dataaccess.MdAttributeMomentDAOIF) JSONException(org.json.JSONException) Condition(com.runwaysdk.query.Condition) IndexTypes(com.runwaysdk.constants.IndexTypes) GeoJSONWriter(org.wololo.jts2geojson.GeoJSONWriter) TableMetadata(net.geoprism.registry.masterlist.TableMetadata) Map(java.util.Map) 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) MdVertexDAOIF(com.runwaysdk.dataaccess.MdVertexDAOIF) 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) VertexObject(com.runwaysdk.business.graph.VertexObject) SimpleDateFormat(java.text.SimpleDateFormat) ExecutableJob(com.runwaysdk.system.scheduler.ExecutableJob) 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) Calendar(java.util.Calendar) QueryFactory(com.runwaysdk.query.QueryFactory) RoleDAO(com.runwaysdk.business.rbac.RoleDAO) VertexGeoObjectQuery(net.geoprism.registry.query.graph.VertexGeoObjectQuery) ComponentQuery(com.runwaysdk.query.ComponentQuery) MdAttribute(com.runwaysdk.system.metadata.MdAttribute) MdClassificationDAOIF(com.runwaysdk.dataaccess.MdClassificationDAOIF) MdAttributeConcrete(com.runwaysdk.system.metadata.MdAttributeConcrete) 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) DataNotFoundException(com.runwaysdk.dataaccess.cache.DataNotFoundException) Business(com.runwaysdk.business.Business) MdBusinessDAO(com.runwaysdk.dataaccess.metadata.MdBusinessDAO) MasterListShapefileExporter(net.geoprism.registry.shapefile.MasterListShapefileExporter) 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) MdAttributeBooleanInfo(com.runwaysdk.constants.MdAttributeBooleanInfo) PublishMasterListVersionJobQuery(net.geoprism.registry.etl.PublishMasterListVersionJobQuery) 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) 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) 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) MdClassificationDAO(com.runwaysdk.dataaccess.metadata.graph.MdClassificationDAO) MdAttributeLineString(com.runwaysdk.system.gis.metadata.MdAttributeLineString) GeometryType(org.commongeoregistry.adapter.constants.GeometryType) MdAttributeIndices(com.runwaysdk.system.metadata.MdAttributeIndices) AbstractClassification(com.runwaysdk.system.AbstractClassification) ProgrammingErrorException(com.runwaysdk.dataaccess.ProgrammingErrorException) PublishMasterListVersionJob(net.geoprism.registry.etl.PublishMasterListVersionJob) Transaction(com.runwaysdk.dataaccess.transaction.Transaction) AttributeClassificationType(org.commongeoregistry.adapter.metadata.AttributeClassificationType) HashMap(java.util.HashMap) LocalizedValue(org.commongeoregistry.adapter.dataaccess.LocalizedValue) MdAttributeLocalInfo(com.runwaysdk.constants.MdAttributeLocalInfo) Progress(net.geoprism.registry.progress.Progress) ServiceFactory(net.geoprism.registry.service.ServiceFactory) Classifier(net.geoprism.ontology.Classifier) MdAttributeConcreteDAOIF(com.runwaysdk.dataaccess.MdAttributeConcreteDAOIF) PublishShapefileJob(net.geoprism.registry.etl.PublishShapefileJob) 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) 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) PublishShapefileJobQuery(net.geoprism.registry.etl.PublishShapefileJobQuery) Session(com.runwaysdk.session.Session) MdAttributePointDAOIF(com.runwaysdk.gis.dataaccess.MdAttributePointDAOIF) Collections(java.util.Collections) JSONArray(org.json.JSONArray) InputStream(java.io.InputStream) MasterListShapefileExporter(net.geoprism.registry.shapefile.MasterListShapefileExporter) MdBusinessDAOIF(com.runwaysdk.dataaccess.MdBusinessDAOIF) 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 24 with MdBusinessDAOIF

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

the class MasterListVersion method bbox.

public String bbox() {
    MdBusinessDAOIF mdBusiness = MdBusinessDAO.get(this.getMdBusinessOid());
    double[] geometry = GeoserverFacade.getBBOX(mdBusiness.getTableName());
    if (geometry != null) {
        try {
            JSONArray bboxArr = new JSONArray();
            bboxArr.put(geometry[0]);
            bboxArr.put(geometry[1]);
            bboxArr.put(geometry[2]);
            bboxArr.put(geometry[3]);
            return bboxArr.toString();
        } catch (JSONException ex) {
            throw new ProgrammingErrorException(ex);
        }
    }
    return null;
}
Also used : MdBusinessDAOIF(com.runwaysdk.dataaccess.MdBusinessDAOIF) JSONArray(org.json.JSONArray) JSONException(org.json.JSONException) ProgrammingErrorException(com.runwaysdk.dataaccess.ProgrammingErrorException)

Example 25 with MdBusinessDAOIF

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

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