Search in sources :

Example 6 with MdAttributeConcreteDAOIF

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

the class MasterListVersion method getAttributesAsJson.

private JsonArray getAttributesAsJson() {
    Collection<Locale> locales = LocalizationFacade.getInstalledLocales();
    MasterList list = this.getMasterlist();
    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 {
                    MasterListAttributeGroup group = MasterListAttributeGroup.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());
                }
                attributes.add(attribute);
            }
        }
    }
    return attributes;
}
Also used : Locale(java.util.Locale) 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) MdAttributePoint(com.runwaysdk.system.gis.metadata.MdAttributePoint) MdAttributeMultiPoint(com.runwaysdk.system.gis.metadata.MdAttributeMultiPoint) JsonArray(com.google.gson.JsonArray) MdAttributePointDAOIF(com.runwaysdk.gis.dataaccess.MdAttributePointDAOIF) ListTypeAttributeComparator(net.geoprism.registry.masterlist.ListTypeAttributeComparator) MdAttributeConcreteDAOIF(com.runwaysdk.dataaccess.MdAttributeConcreteDAOIF)

Example 7 with MdAttributeConcreteDAOIF

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

the class MasterListVersion method values.

public JsonArray values(String value, String attributeName, String valueAttribute, String filterJson) {
    DateFormat filterFormat = new SimpleDateFormat(GeoObjectImportConfiguration.DATE_FORMAT);
    filterFormat.setTimeZone(GeoRegistryUtil.SYSTEM_TIMEZONE);
    JsonArray results = new JsonArray();
    MdBusinessDAOIF mdBusiness = MdBusinessDAO.get(this.getMdBusinessOid());
    ValueQuery vQuery = new ValueQuery(new QueryFactory());
    BusinessQuery query = new BusinessQuery(vQuery, mdBusiness.definesType());
    vQuery.SELECT_DISTINCT(query.get(attributeName, "label"), query.get(valueAttribute, "value"));
    vQuery.FROM(query);
    Map<MdAttributeConcreteDAOIF, Condition> conditionMap = this.buildQueryConditionsFromFilter(filterJson, attributeName, query, mdBusiness);
    for (Condition condition : conditionMap.values()) {
        vQuery.WHERE(condition);
    }
    if (value != null && value.length() > 0) {
        vQuery.WHERE(query.aCharacter(attributeName).LIKEi("%" + value + "%"));
    }
    vQuery.ORDER_BY_ASC(query.get(attributeName));
    OIterator<ValueObject> it = vQuery.getIterator(100, 1);
    try {
        while (it.hasNext()) {
            ValueObject vObject = it.next();
            JsonObject result = new JsonObject();
            result.addProperty("label", vObject.getValue("label"));
            result.addProperty("value", vObject.getValue("value"));
            results.add(result);
        }
    } finally {
        it.close();
    }
    return results;
}
Also used : ValueQuery(com.runwaysdk.query.ValueQuery) 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) JsonObject(com.google.gson.JsonObject) JsonArray(com.google.gson.JsonArray) SimpleDateFormat(java.text.SimpleDateFormat) DateFormat(java.text.DateFormat) ValueObject(com.runwaysdk.dataaccess.ValueObject) SimpleDateFormat(java.text.SimpleDateFormat) MdAttributeConcreteDAOIF(com.runwaysdk.dataaccess.MdAttributeConcreteDAOIF)

Example 8 with MdAttributeConcreteDAOIF

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

the class MasterListVersion method removeAttribute.

private void removeAttribute(MdBusinessDAOIF mdBusiness, String name) {
    MdAttributeConcreteDAOIF mdAttribute = mdBusiness.definesAttribute(name);
    if (mdAttribute != null) {
        MasterListAttributeGroup.remove(mdAttribute);
        mdAttribute.getBusinessDAO().delete();
    }
}
Also used : MdAttributeConcreteDAOIF(com.runwaysdk.dataaccess.MdAttributeConcreteDAOIF)

Example 9 with MdAttributeConcreteDAOIF

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

the class ListTypeExcelExporter method writeRow.

public void writeRow(Row row, Business object, CellStyle dateStyle) {
    int col = 0;
    // Write the row
    MdAttributeConcreteDAOIF mdGeometry = mdBusiness.definesAttribute(RegistryConstants.GEOMETRY_ATTRIBUTE_NAME);
    if (mdGeometry instanceof MdAttributePointDAOIF) {
        Point point = (Point) object.getObjectValue(mdGeometry.definesAttribute());
        if (point != null) {
            row.createCell(col++).setCellValue(point.getX());
            row.createCell(col++).setCellValue(point.getY());
        }
    }
    for (MdAttributeConcreteDAOIF mdAttribute : mdAttributes) {
        String attributeName = mdAttribute.definesAttribute();
        Object value = object.getObjectValue(attributeName);
        Cell cell = row.createCell(col++);
        if (value != null) {
            if (value instanceof String) {
                cell.setCellValue((String) value);
            } else if (value instanceof Date) {
                cell.setCellValue((Date) value);
                cell.setCellStyle(dateStyle);
            } else if (value instanceof Number) {
                cell.setCellValue(((Number) value).doubleValue());
            } else if (value instanceof Boolean) {
                cell.setCellValue((Boolean) value);
            }
        }
    }
}
Also used : MdAttributePointDAOIF(com.runwaysdk.gis.dataaccess.MdAttributePointDAOIF) JsonObject(com.google.gson.JsonObject) Point(com.vividsolutions.jts.geom.Point) Cell(org.apache.poi.ss.usermodel.Cell) Point(com.vividsolutions.jts.geom.Point) Date(java.util.Date) MdAttributeConcreteDAOIF(com.runwaysdk.dataaccess.MdAttributeConcreteDAOIF)

Example 10 with MdAttributeConcreteDAOIF

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

the class ListTypeExcelExporter method writeHeader.

public void writeHeader(CellStyle boldStyle, Row header) {
    int col = 0;
    Locale locale = Session.getCurrentLocale();
    MdAttributeConcreteDAOIF mdGeometry = mdBusiness.definesAttribute(RegistryConstants.GEOMETRY_ATTRIBUTE_NAME);
    if (mdGeometry instanceof MdAttributePointDAOIF) {
        Cell longitude = header.createCell(col++);
        longitude.setCellStyle(boldStyle);
        longitude.setCellValue(LocalizationFacade.getFromBundles(GeoObjectImportConfiguration.LONGITUDE_KEY));
        Cell latitude = header.createCell(col++);
        latitude.setCellStyle(boldStyle);
        latitude.setCellValue(LocalizationFacade.getFromBundles(GeoObjectImportConfiguration.LATITUDE_KEY));
    }
    for (MdAttributeConcreteDAOIF mdAttribute : this.mdAttributes) {
        Cell cell = header.createCell(col++);
        cell.setCellStyle(boldStyle);
        cell.setCellValue(mdAttribute.getDisplayLabel(locale));
    }
}
Also used : Locale(java.util.Locale) MdAttributePointDAOIF(com.runwaysdk.gis.dataaccess.MdAttributePointDAOIF) Cell(org.apache.poi.ss.usermodel.Cell) Point(com.vividsolutions.jts.geom.Point) MdAttributeConcreteDAOIF(com.runwaysdk.dataaccess.MdAttributeConcreteDAOIF)

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