Search in sources :

Example 16 with QueryFactory

use of com.runwaysdk.query.QueryFactory 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 17 with QueryFactory

use of com.runwaysdk.query.QueryFactory 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 18 with QueryFactory

use of com.runwaysdk.query.QueryFactory in project geoprism-registry by terraframe.

the class MasterList method getOrCreateVersion.

@Transaction
public MasterListVersion getOrCreateVersion(Date forDate, String versionType) {
    if (!this.isValid()) {
        throw new InvalidMasterListException();
    }
    MasterListVersionQuery query = new MasterListVersionQuery(new QueryFactory());
    query.WHERE(query.getMasterlist().EQ(this));
    query.AND(query.getForDate().EQ(forDate));
    query.AND(query.getVersionType().EQ(versionType));
    try (OIterator<? extends MasterListVersion> it = query.getIterator()) {
        if (it.hasNext()) {
            return it.next();
        }
    }
    return MasterListVersion.create(this, forDate, versionType);
}
Also used : QueryFactory(com.runwaysdk.query.QueryFactory) Transaction(com.runwaysdk.dataaccess.transaction.Transaction)

Example 19 with QueryFactory

use of com.runwaysdk.query.QueryFactory in project geoprism-registry by terraframe.

the class MasterList method listByOrg.

public static JsonArray listByOrg() {
    JsonArray response = new JsonArray();
    final List<? extends Organization> orgs = Organization.getOrganizations();
    for (Organization org : orgs) {
        final boolean isMember = Organization.isMember(org);
        MasterListQuery query = new MasterListQuery(new QueryFactory());
        query.WHERE(query.getOrganization().EQ(org));
        query.ORDER_BY_DESC(query.getDisplayLabel().localize());
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
        JsonArray lists = new JsonArray();
        try (OIterator<? extends MasterList> it = query.getIterator()) {
            while (it.hasNext()) {
                MasterList list = it.next();
                if (isMember || list.getVisibility().equals(MasterList.PUBLIC)) {
                    JsonObject object = new JsonObject();
                    object.addProperty("label", list.getDisplayLabel().getValue());
                    object.addProperty("oid", list.getOid());
                    object.addProperty("createDate", format.format(list.getCreateDate()));
                    object.addProperty("lasteUpdateDate", format.format(list.getLastUpdateDate()));
                    object.addProperty("isMaster", list.getIsMaster());
                    object.addProperty("visibility", list.getVisibility());
                    object.addProperty("write", list.doesActorHaveWritePermission());
                    object.addProperty("read", list.doesActorHaveReadPermission());
                    lists.add(object);
                }
            }
        }
        JsonObject object = new JsonObject();
        object.addProperty("oid", org.getOid());
        object.addProperty("code", org.getCode());
        object.addProperty("label", org.getDisplayLabel().getValue());
        object.addProperty("write", Organization.isRegistryAdmin(org) || Organization.isRegistryMaintainer(org));
        object.add("lists", lists);
        response.add(object);
    }
    return response;
}
Also used : JsonArray(com.google.gson.JsonArray) QueryFactory(com.runwaysdk.query.QueryFactory) JsonObject(com.google.gson.JsonObject) SimpleDateFormat(java.text.SimpleDateFormat)

Example 20 with QueryFactory

use of com.runwaysdk.query.QueryFactory in project geoprism-registry by terraframe.

the class MasterList method deleteAll.

@Transaction
public static void deleteAll(Universal universal) {
    MasterListQuery query = new MasterListQuery(new QueryFactory());
    query.WHERE(query.getUniversal().EQ(universal));
    List<? extends MasterList> lists = query.getIterator().getAll();
    for (MasterList list : lists) {
        list.delete();
    }
}
Also used : QueryFactory(com.runwaysdk.query.QueryFactory) Transaction(com.runwaysdk.dataaccess.transaction.Transaction)

Aggregations

QueryFactory (com.runwaysdk.query.QueryFactory)158 Transaction (com.runwaysdk.dataaccess.transaction.Transaction)37 LinkedList (java.util.LinkedList)35 Request (com.runwaysdk.session.Request)31 JsonArray (com.google.gson.JsonArray)19 JsonObject (com.google.gson.JsonObject)19 ServerGeoObjectType (net.geoprism.registry.model.ServerGeoObjectType)19 SimpleDateFormat (java.text.SimpleDateFormat)15 List (java.util.List)14 Date (java.util.Date)13 ChangeRequest (net.geoprism.registry.action.ChangeRequest)13 OIterator (com.runwaysdk.query.OIterator)12 Universal (com.runwaysdk.system.gis.geo.Universal)12 ChangeRequestQuery (net.geoprism.registry.action.ChangeRequestQuery)12 ServerHierarchyType (net.geoprism.registry.model.ServerHierarchyType)11 BusinessQuery (com.runwaysdk.business.BusinessQuery)10 Session (com.runwaysdk.session.Session)10 GeoprismUser (net.geoprism.GeoprismUser)10 ProgrammingErrorException (com.runwaysdk.dataaccess.ProgrammingErrorException)9 MdBusinessDAOIF (com.runwaysdk.dataaccess.MdBusinessDAOIF)8