Search in sources :

Example 1 with BusinessQuery

use of com.runwaysdk.business.BusinessQuery in project geoprism-registry by terraframe.

the class ListTypeVersion method updateRecord.

@Transaction
public void updateRecord(ServerGeoObjectIF object) {
    // Only working lists can be updated from changes to the graph objects
    if (this.getWorking()) {
        object.setDate(this.getForDate());
        // Delete tile cache
        ListTileCache.deleteTiles(this);
        ListType masterlist = this.getListType();
        MdBusinessDAO mdBusiness = MdBusinessDAO.get(this.getMdBusinessOid()).getBusinessDAO();
        Collection<Locale> locales = LocalizationFacade.getInstalledLocales();
        // Add the type ancestor fields
        ServerGeoObjectType type = ServerGeoObjectType.get(masterlist.getUniversal());
        Set<ServerHierarchyType> hierarchiesOfSubTypes = type.getHierarchiesOfSubTypes();
        Map<ServerHierarchyType, List<ServerGeoObjectType>> ancestorMap = masterlist.getAncestorMap(type);
        Collection<AttributeType> attributes = type.getAttributeMap().values();
        BusinessQuery query = new QueryFactory().businessQuery(mdBusiness.definesType());
        query.WHERE(query.aCharacter(DefaultAttribute.CODE.getName()).EQ(object.getCode()));
        List<Business> records = query.getIterator().getAll();
        for (Business record : records) {
            try {
                record.appLock();
                this.publish(masterlist, type, object, record, attributes, ancestorMap, hierarchiesOfSubTypes, locales);
            } finally {
                record.unlock();
            }
        }
    }
}
Also used : Locale(java.util.Locale) BusinessQuery(com.runwaysdk.business.BusinessQuery) ServerHierarchyType(net.geoprism.registry.model.ServerHierarchyType) QueryFactory(com.runwaysdk.query.QueryFactory) MdBusinessDAO(com.runwaysdk.dataaccess.metadata.MdBusinessDAO) ServerGeoObjectType(net.geoprism.registry.model.ServerGeoObjectType) AttributeType(org.commongeoregistry.adapter.metadata.AttributeType) List(java.util.List) LinkedList(java.util.LinkedList) MdBusiness(com.runwaysdk.system.metadata.MdBusiness) Business(com.runwaysdk.business.Business) Transaction(com.runwaysdk.dataaccess.transaction.Transaction)

Example 2 with BusinessQuery

use of com.runwaysdk.business.BusinessQuery in project geoprism-registry by terraframe.

the class ListTypeVersion method record.

public JsonObject record(String uid) {
    SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
    format.setTimeZone(GeoRegistryUtil.SYSTEM_TIMEZONE);
    NumberFormat numberFormat = NumberFormat.getInstance(Session.getCurrentLocale());
    MdBusinessDAOIF mdBusiness = MdBusinessDAO.get(this.getMdBusinessOid());
    List<? extends MdAttributeConcreteDAOIF> mdAttributes = mdBusiness.definesAttributes();
    BusinessQuery query = new QueryFactory().businessQuery(mdBusiness.definesType());
    query.WHERE(query.get(DefaultAttribute.UID.getName()).EQ(uid));
    JsonObject record = new JsonObject();
    record.addProperty("recordType", "LIST");
    record.addProperty("version", this.getOid());
    record.add("typeLabel", LocalizedValueConverter.convert(this.getListType().getDisplayLabel()).toJSON());
    record.add("attributes", this.getAttributesAsJson());
    try (OIterator<Business> iterator = query.getIterator()) {
        if (iterator.hasNext()) {
            Business row = iterator.next();
            JsonObject object = new JsonObject();
            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));
                        }
                    }
                }
            }
            record.add("data", object);
        }
    }
    JsonArray bbox = this.bbox(uid);
    if (bbox == null || bbox.size() == 0) {
        bbox = this.bbox(null);
    }
    record.add("bbox", bbox);
    return record;
}
Also used : BusinessQuery(com.runwaysdk.business.BusinessQuery) MdBusinessDAOIF(com.runwaysdk.dataaccess.MdBusinessDAOIF) QueryFactory(com.runwaysdk.query.QueryFactory) 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) 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) NumberFormat(java.text.NumberFormat) MdBusiness(com.runwaysdk.system.metadata.MdBusiness) Business(com.runwaysdk.business.Business) MdAttributeConcreteDAOIF(com.runwaysdk.dataaccess.MdAttributeConcreteDAOIF)

Example 3 with BusinessQuery

use of com.runwaysdk.business.BusinessQuery 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 4 with BusinessQuery

use of com.runwaysdk.business.BusinessQuery in project geoprism-registry by terraframe.

the class ChangeRequest method getOrderedActions.

public List<AbstractAction> getOrderedActions() {
    // TODO : Runway querybuilder is dumb
    // QueryFactory qf = new QueryFactory();
    // 
    // ChangeRequestQuery crq = new ChangeRequestQuery(qf);
    // AbstractActionQuery aaq = new AbstractActionQuery(qf);
    // 
    // aaq.ORDER_BY(aaq.getCreateActionDate(), SortOrder.DESC);
    // aaq.WHERE(aaq.request(crq));
    // aaq.WHERE(crq.getOid().EQ(this.getOid()));
    // 
    // return aaq.getIterator().getAll();
    MdRelationshipDAOIF mdRelationshipIF = MdRelationshipDAO.getMdRelationshipDAO(HasActionRelationship.CLASS);
    QueryFactory queryFactory = new QueryFactory();
    // Get the relationships where this object is the parent
    RelationshipQuery rq = queryFactory.relationshipQuery(HasActionRelationship.CLASS);
    rq.WHERE(rq.parentOid().EQ(this.getOid()));
    // Now fetch the child objects
    BusinessQuery bq = queryFactory.businessQuery(mdRelationshipIF.getChildMdBusiness().definesType());
    bq.WHERE(bq.isChildIn(rq));
    bq.ORDER_BY(bq.get(AbstractAction.CREATEACTIONDATE), SortOrder.ASC);
    List<Business> bizes = bq.getIterator().getAll();
    List<AbstractAction> actions = new ArrayList<AbstractAction>();
    for (Business biz : bizes) {
        actions.add((AbstractAction) biz);
    }
    return actions;
}
Also used : BusinessQuery(com.runwaysdk.business.BusinessQuery) MdRelationshipDAOIF(com.runwaysdk.dataaccess.MdRelationshipDAOIF) QueryFactory(com.runwaysdk.query.QueryFactory) RelationshipQuery(com.runwaysdk.business.RelationshipQuery) ArrayList(java.util.ArrayList) Business(com.runwaysdk.business.Business)

Example 5 with BusinessQuery

use of com.runwaysdk.business.BusinessQuery in project geoprism-registry by terraframe.

the class MasterListExcelExporter method createDataSheet.

private void createDataSheet(Workbook workbook) {
    Sheet sheet = workbook.createSheet(WorkbookUtil.createSafeSheetName(this.getList().getDisplayLabel().getValue()));
    Row header = sheet.createRow(0);
    // MdAttributeGeometryDAOIF geometryAttribute = (MdAttributeGeometryDAOIF)
    // this.mdBusiness.definesAttribute(RegistryConstants.GEOMETRY_ATTRIBUTE_NAME);
    // 
    // boolean includeCoordinates = ( geometryAttribute instanceof
    // MdAttributePointDAOIF );
    this.writeHeader(this.boldStyle, header);
    int rownum = 1;
    BusinessQuery query = this.version.buildQuery(this.filterJson);
    query.ORDER_BY_DESC(query.aCharacter(DefaultAttribute.CODE.getName()));
    OIterator<Business> objects = query.getIterator();
    try {
        while (objects.hasNext()) {
            Business object = objects.next();
            Row row = sheet.createRow(rownum++);
            this.writeRow(row, object, this.dateStyle);
        }
    } finally {
        objects.close();
    }
}
Also used : BusinessQuery(com.runwaysdk.business.BusinessQuery) Row(org.apache.poi.ss.usermodel.Row) Sheet(org.apache.poi.ss.usermodel.Sheet) Point(com.vividsolutions.jts.geom.Point) Business(com.runwaysdk.business.Business)

Aggregations

BusinessQuery (com.runwaysdk.business.BusinessQuery)17 Business (com.runwaysdk.business.Business)12 QueryFactory (com.runwaysdk.query.QueryFactory)9 MdAttributeConcreteDAOIF (com.runwaysdk.dataaccess.MdAttributeConcreteDAOIF)7 JsonObject (com.google.gson.JsonObject)6 MdBusinessDAOIF (com.runwaysdk.dataaccess.MdBusinessDAOIF)5 JsonArray (com.google.gson.JsonArray)4 ValueObject (com.runwaysdk.dataaccess.ValueObject)4 MdBusiness (com.runwaysdk.system.metadata.MdBusiness)4 SimpleDateFormat (java.text.SimpleDateFormat)4 ServerGeoObjectType (net.geoprism.registry.model.ServerGeoObjectType)4 Transaction (com.runwaysdk.dataaccess.transaction.Transaction)3 BasicCondition (com.runwaysdk.query.BasicCondition)3 Condition (com.runwaysdk.query.Condition)3 ArrayList (java.util.ArrayList)3 VertexObject (com.runwaysdk.business.graph.VertexObject)2 MdBusinessDAO (com.runwaysdk.dataaccess.metadata.MdBusinessDAO)2 AttributeBoolean (com.runwaysdk.query.AttributeBoolean)2 ValueQuery (com.runwaysdk.query.ValueQuery)2 MdAttributeLineString (com.runwaysdk.system.gis.metadata.MdAttributeLineString)2