Search in sources :

Example 16 with MdBusinessDAOIF

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

the class ListTypeVersion method bbox.

public JsonArray bbox(String uid) {
    MdBusinessDAOIF mdBusiness = MdBusinessDAO.get(this.getMdBusinessOid());
    String tableName = mdBusiness.getTableName();
    // collect all the views and extend the bounding box
    ValueQuery union = new ValueQuery(new QueryFactory());
    union.SELECT(union.aSQLClob(GeoserverFacade.GEOM_COLUMN, GeoserverFacade.GEOM_COLUMN, GeoserverFacade.GEOM_COLUMN));
    union.FROM(tableName, tableName);
    if (uid != null && uid.length() > 0) {
        MdAttributeConcreteDAOIF attribute = mdBusiness.definesAttribute(DefaultAttribute.UID.getName());
        String columName = attribute.getColumnName();
        union.WHERE(union.aSQLCharacter(columName, columName).EQ(uid));
    }
    ValueQuery collected = new ValueQuery(union.getQueryFactory());
    collected.SELECT(collected.aSQLAggregateClob("collected", "st_collect(" + GeoserverFacade.GEOM_COLUMN + ")", "collected"));
    collected.FROM("(" + union.getSQL() + ")", "unioned");
    ValueQuery outer = new ValueQuery(union.getQueryFactory());
    outer.SELECT(union.aSQLAggregateDouble("minx", "st_xmin(collected)"), union.aSQLAggregateDouble("miny", "st_ymin(collected)"), union.aSQLAggregateDouble("maxx", "st_xmax(collected)"), union.aSQLAggregateDouble("maxy", "st_ymax(collected)"));
    outer.FROM("(" + collected.getSQL() + ")", "collected");
    try (OIterator<? extends ValueObject> iter = outer.getIterator()) {
        ValueObject o = iter.next();
        try {
            JsonArray bboxArr = new JsonArray();
            bboxArr.add(Double.parseDouble(o.getValue("minx")));
            bboxArr.add(Double.parseDouble(o.getValue("miny")));
            bboxArr.add(Double.parseDouble(o.getValue("maxx")));
            bboxArr.add(Double.parseDouble(o.getValue("maxy")));
            return bboxArr;
        } catch (JSONException ex) {
            throw new ProgrammingErrorException(ex);
        }
    } catch (Exception e) {
        return null;
    // throw new NoLayerDataException();
    }
}
Also used : ValueQuery(com.runwaysdk.query.ValueQuery) JsonArray(com.google.gson.JsonArray) MdBusinessDAOIF(com.runwaysdk.dataaccess.MdBusinessDAOIF) QueryFactory(com.runwaysdk.query.QueryFactory) JSONException(org.json.JSONException) MdAttributeMultiLineString(com.runwaysdk.system.gis.metadata.MdAttributeMultiLineString) MdAttributeLineString(com.runwaysdk.system.gis.metadata.MdAttributeLineString) ValueObject(com.runwaysdk.dataaccess.ValueObject) ProgrammingErrorException(com.runwaysdk.dataaccess.ProgrammingErrorException) JSONException(org.json.JSONException) IOException(java.io.IOException) DataNotFoundException(com.runwaysdk.dataaccess.cache.DataNotFoundException) ParseException(java.text.ParseException) UnsupportedOperationException(com.amazonaws.services.kms.model.UnsupportedOperationException) FileNotFoundException(java.io.FileNotFoundException) ProgrammingErrorException(com.runwaysdk.dataaccess.ProgrammingErrorException) MdAttributeConcreteDAOIF(com.runwaysdk.dataaccess.MdAttributeConcreteDAOIF)

Example 17 with MdBusinessDAOIF

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

the class ListTypeVersion method getAttributesAsJson.

private JsonArray getAttributesAsJson() {
    Collection<Locale> locales = LocalizationFacade.getInstalledLocales();
    ListType list = this.getListType();
    Map<String, JsonArray> dependencies = new HashMap<String, JsonArray>();
    Map<String, String> baseAttributes = new HashMap<String, String>();
    List<String> attributesOrder = new LinkedList<String>();
    JsonArray hierarchies = list.getHierarchiesAsJson();
    for (int i = 0; i < hierarchies.size(); i++) {
        JsonObject hierarchy = hierarchies.get(i).getAsJsonObject();
        List<String> pCodes = list.getParentCodes(hierarchy);
        if (pCodes.size() > 0) {
            String hCode = hierarchy.get(DefaultAttribute.CODE.getName()).getAsString();
            String previous = null;
            for (String pCode : pCodes) {
                String attributeName = hCode.toLowerCase() + pCode.toLowerCase();
                baseAttributes.put(attributeName, attributeName);
                baseAttributes.put(attributeName + DEFAULT_LOCALE, attributeName);
                for (Locale locale : locales) {
                    baseAttributes.put(attributeName + locale.toString(), attributeName);
                }
                attributesOrder.add(attributeName);
                attributesOrder.add(attributeName + DEFAULT_LOCALE);
                for (Locale locale : locales) {
                    attributesOrder.add(attributeName + locale.toString());
                }
                if (previous != null) {
                    addDependency(dependencies, attributeName, previous);
                    addDependency(dependencies, attributeName + DEFAULT_LOCALE, previous);
                    for (Locale locale : locales) {
                        addDependency(dependencies, attributeName + locale.toString(), previous);
                    }
                }
                previous = attributeName;
            }
            if (previous != null) {
                addDependency(dependencies, DefaultAttribute.CODE.getName(), previous);
                addDependency(dependencies, DefaultAttribute.DISPLAY_LABEL.getName() + DEFAULT_LOCALE, previous);
                for (Locale locale : locales) {
                    addDependency(dependencies, DefaultAttribute.DISPLAY_LABEL.getName() + locale.toString(), previous);
                }
            }
        }
    }
    baseAttributes.put(DefaultAttribute.CODE.getName(), DefaultAttribute.CODE.getName());
    baseAttributes.put(DefaultAttribute.DISPLAY_LABEL.getName() + DEFAULT_LOCALE, DefaultAttribute.CODE.getName());
    for (Locale locale : locales) {
        baseAttributes.put(DefaultAttribute.DISPLAY_LABEL.getName() + locale.toString(), DefaultAttribute.CODE.getName());
    }
    attributesOrder.add(DefaultAttribute.CODE.getName());
    attributesOrder.add(DefaultAttribute.DISPLAY_LABEL.getName() + DEFAULT_LOCALE);
    for (Locale locale : locales) {
        attributesOrder.add(DefaultAttribute.DISPLAY_LABEL.getName() + locale.toString());
    }
    JsonArray attributes = new JsonArray();
    String mdBusinessId = this.getMdBusinessOid();
    if (mdBusinessId != null && mdBusinessId.length() > 0) {
        MdBusinessDAOIF mdBusiness = MdBusinessDAO.get(mdBusinessId);
        List<? extends MdAttributeConcreteDAOIF> mdAttributes = mdBusiness.definesAttributesOrdered();
        Collections.sort(mdAttributes, new ListTypeAttributeComparator(attributesOrder, mdAttributes));
        MdAttributeConcreteDAOIF mdGeometry = mdBusiness.definesAttribute(RegistryConstants.GEOMETRY_ATTRIBUTE_NAME);
        if (mdGeometry instanceof MdAttributePointDAOIF) {
            JsonObject longitude = new JsonObject();
            longitude.addProperty(NAME, "longitude");
            longitude.addProperty(LABEL, LocalizationFacade.localize(GeoObjectImportConfiguration.LONGITUDE_KEY));
            longitude.addProperty(TYPE, "none");
            attributes.add(longitude);
            JsonObject latitude = new JsonObject();
            latitude.addProperty(NAME, "latitude");
            latitude.addProperty(LABEL, LocalizationFacade.localize(GeoObjectImportConfiguration.LATITUDE_KEY));
            latitude.addProperty(TYPE, "none");
            attributes.add(latitude);
        }
        for (MdAttributeConcreteDAOIF mdAttribute : mdAttributes) {
            if (this.isValid(mdAttribute)) {
                String attributeName = mdAttribute.definesAttribute();
                try {
                    ListTypeAttributeGroup group = ListTypeAttributeGroup.getByKey(mdAttribute.getOid());
                    if (group != null) {
                        baseAttributes.put(mdAttribute.definesAttribute(), group.getSourceAttribute().getAttributeName());
                    }
                } catch (DataNotFoundException e) {
                // Ignore
                }
                JsonObject attribute = new JsonObject();
                attribute.addProperty(NAME, attributeName);
                attribute.addProperty(LABEL, mdAttribute.getDisplayLabel(Session.getCurrentLocale()));
                attribute.addProperty(TYPE, baseAttributes.containsKey(attributeName) ? "list" : "input");
                attribute.addProperty(BASE, baseAttributes.containsKey(attributeName) ? baseAttributes.get(attributeName) : attributeName);
                attribute.add(DEPENDENCY, dependencies.containsKey(attributeName) ? dependencies.get(attributeName) : new JsonArray());
                if (mdAttribute instanceof MdAttributeMomentDAOIF) {
                    attribute.addProperty(TYPE, "date");
                    attribute.add(VALUE, new JsonObject());
                } else if (mdAttribute instanceof MdAttributeBooleanDAOIF) {
                    attribute.addProperty(TYPE, "boolean");
                } else if (mdAttribute instanceof MdAttributeNumberDAOIF) {
                    attribute.addProperty(TYPE, "number");
                }
                attributes.add(attribute);
            }
        }
    }
    return attributes;
}
Also used : Locale(java.util.Locale) MdAttributeBooleanDAOIF(com.runwaysdk.dataaccess.MdAttributeBooleanDAOIF) DataNotFoundException(com.runwaysdk.dataaccess.cache.DataNotFoundException) MdBusinessDAOIF(com.runwaysdk.dataaccess.MdBusinessDAOIF) HashMap(java.util.HashMap) JsonObject(com.google.gson.JsonObject) MdAttributeMultiLineString(com.runwaysdk.system.gis.metadata.MdAttributeMultiLineString) MdAttributeLineString(com.runwaysdk.system.gis.metadata.MdAttributeLineString) MdAttributeMomentDAOIF(com.runwaysdk.dataaccess.MdAttributeMomentDAOIF) LinkedList(java.util.LinkedList) MultiPoint(com.vividsolutions.jts.geom.MultiPoint) MdAttributePoint(com.runwaysdk.system.gis.metadata.MdAttributePoint) MdAttributeMultiPoint(com.runwaysdk.system.gis.metadata.MdAttributeMultiPoint) Point(com.vividsolutions.jts.geom.Point) JsonArray(com.google.gson.JsonArray) MdAttributePointDAOIF(com.runwaysdk.gis.dataaccess.MdAttributePointDAOIF) MdAttributeNumberDAOIF(com.runwaysdk.dataaccess.MdAttributeNumberDAOIF) ListTypeAttributeComparator(net.geoprism.registry.masterlist.ListTypeAttributeComparator) MdAttributeConcreteDAOIF(com.runwaysdk.dataaccess.MdAttributeConcreteDAOIF)

Example 18 with MdBusinessDAOIF

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

the class ListTypeVersion 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 19 with MdBusinessDAOIF

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

the class ListTypeVersion method buildQuery.

public BusinessQuery buildQuery(String filterJson) {
    MdBusinessDAOIF mdBusiness = MdBusinessDAO.get(this.getMdBusinessOid());
    BusinessQuery query = new QueryFactory().businessQuery(mdBusiness.definesType());
    Map<MdAttributeConcreteDAOIF, Condition> conditionMap = this.buildQueryConditionsFromFilter(filterJson, null, query, mdBusiness);
    for (Condition condition : conditionMap.values()) {
        query.WHERE(condition);
    }
    return query;
}
Also used : BusinessQuery(com.runwaysdk.business.BusinessQuery) Condition(com.runwaysdk.query.Condition) BasicCondition(com.runwaysdk.query.BasicCondition) MdBusinessDAOIF(com.runwaysdk.dataaccess.MdBusinessDAOIF) QueryFactory(com.runwaysdk.query.QueryFactory) MdAttributeConcreteDAOIF(com.runwaysdk.dataaccess.MdAttributeConcreteDAOIF)

Example 20 with MdBusinessDAOIF

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

the class MasterListVersion method buildQuery.

public BusinessQuery buildQuery(String filterJson) {
    MdBusinessDAOIF mdBusiness = MdBusinessDAO.get(this.getMdBusinessOid());
    BusinessQuery query = new QueryFactory().businessQuery(mdBusiness.definesType());
    Map<MdAttributeConcreteDAOIF, Condition> conditionMap = this.buildQueryConditionsFromFilter(filterJson, null, query, mdBusiness);
    for (Condition condition : conditionMap.values()) {
        query.WHERE(condition);
    }
    return query;
}
Also used : BusinessQuery(com.runwaysdk.business.BusinessQuery) Condition(com.runwaysdk.query.Condition) BasicCondition(com.runwaysdk.query.BasicCondition) MdBusinessDAOIF(com.runwaysdk.dataaccess.MdBusinessDAOIF) QueryFactory(com.runwaysdk.query.QueryFactory) 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