Search in sources :

Example 21 with MdAttributeDAOIF

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

the class TransitionEvent method page.

public static Page<TransitionEvent> page(Integer pageSize, Integer pageNumber, String attrConditions) {
    Long count = getCount();
    MdVertexDAOIF mdVertex = MdVertexDAO.getMdVertexDAO(TransitionEvent.CLASS);
    MdAttributeDAOIF eventDate = mdVertex.definesAttribute(TransitionEvent.EVENTDATE);
    Map<String, Object> parameters = new HashMap<String, Object>();
    StringBuilder statement = new StringBuilder();
    statement.append("SELECT FROM " + mdVertex.getDBClassName());
    addPageWhereCriteria(statement, parameters, attrConditions);
    statement.append(" ORDER BY " + eventDate.getColumnName() + " DESC");
    statement.append(" SKIP " + ((pageNumber - 1) * pageSize) + " LIMIT " + pageSize);
    GraphQuery<TransitionEvent> query = new GraphQuery<TransitionEvent>(statement.toString(), parameters);
    return new Page<TransitionEvent>(count, pageNumber, pageSize, query.getResults());
}
Also used : MdVertexDAOIF(com.runwaysdk.dataaccess.MdVertexDAOIF) MdAttributeDAOIF(com.runwaysdk.dataaccess.MdAttributeDAOIF) HashMap(java.util.HashMap) JsonObject(com.google.gson.JsonObject) VertexServerGeoObject(net.geoprism.registry.model.graph.VertexServerGeoObject) Page(net.geoprism.registry.view.Page) GraphQuery(com.runwaysdk.business.graph.GraphQuery)

Example 22 with MdAttributeDAOIF

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

the class TransitionEvent method getTransitions.

public List<Transition> getTransitions() {
    MdVertexDAOIF mdVertex = MdVertexDAO.getMdVertexDAO(Transition.CLASS);
    MdAttributeDAOIF mdAttribute = mdVertex.definesAttribute(Transition.EVENT);
    // MdAttributeDAOIF sourceAttribute = mdVertex.definesAttribute(Transition.SOURCE);
    MdAttributeDAOIF targetAttribute = mdVertex.definesAttribute(Transition.TARGET);
    MdAttributeDAOIF orderAttribute = mdVertex.definesAttribute(Transition.ORDER);
    StringBuilder statement = new StringBuilder();
    statement.append("SELECT FROM " + mdVertex.getDBClassName());
    statement.append(" WHERE " + mdAttribute.getColumnName() + " = :event");
    statement.append(" ORDER BY " + orderAttribute.getColumnName() + " ASC");
    statement.append(", " + targetAttribute.getColumnName() + ".code");
    GraphQuery<Transition> query = new GraphQuery<Transition>(statement.toString());
    query.setParameter("event", this.getRID());
    List<Transition> results = query.getResults();
    return results;
}
Also used : MdVertexDAOIF(com.runwaysdk.dataaccess.MdVertexDAOIF) MdAttributeDAOIF(com.runwaysdk.dataaccess.MdAttributeDAOIF) GraphQuery(com.runwaysdk.business.graph.GraphQuery)

Example 23 with MdAttributeDAOIF

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

the class TransitionEvent method addPageWhereCriteria.

public static void addPageWhereCriteria(StringBuilder statement, Map<String, Object> parameters, String attrConditions) {
    List<String> whereConditions = new ArrayList<String>();
    // Add permissions criteria
    if (Session.getCurrentSession() != null) {
        String beforeCondition = GeoObjectTypeRestrictionUtil.buildTypeWritePermissionsFilter(TransitionEvent.BEFORETYPEORGCODE, TransitionEvent.BEFORETYPECODE);
        if (beforeCondition.length() > 0) {
            whereConditions.add(beforeCondition);
        }
        String afterCondition = GeoObjectTypeRestrictionUtil.buildTypeReadPermissionsFilter(TransitionEvent.AFTERTYPEORGCODE, TransitionEvent.AFTERTYPECODE);
        if (afterCondition.length() > 0) {
            whereConditions.add(afterCondition);
        }
    }
    // Filter based on attributes
    if (attrConditions != null && attrConditions.length() > 0) {
        List<String> lAttrConditions = new ArrayList<String>();
        JsonArray jaAttrConditions = JsonParser.parseString(attrConditions).getAsJsonArray();
        for (int i = 0; i < jaAttrConditions.size(); ++i) {
            JsonObject attrCondition = jaAttrConditions.get(i).getAsJsonObject();
            String attr = attrCondition.get("attribute").getAsString();
            MdVertexDAO eventMd = (MdVertexDAO) MdVertexDAO.getMdVertexDAO(TransitionEvent.CLASS);
            MdAttributeDAOIF mdAttr = eventMd.definesAttribute(attr);
            if (attr.equals(TransitionEvent.EVENTDATE)) {
                DateFormat format = new SimpleDateFormat("yyyy-MM-dd");
                format.setTimeZone(GeoRegistryUtil.SYSTEM_TIMEZONE);
                List<String> dateConditions = new ArrayList<String>();
                try {
                    if (attrCondition.has("startDate") && !attrCondition.get("startDate").isJsonNull() && attrCondition.get("startDate").getAsString().length() > 0) {
                        Date startDate = format.parse(attrCondition.get("startDate").getAsString());
                        dateConditions.add(mdAttr.getColumnName() + ">=:startDate" + i);
                        parameters.put("startDate" + i, startDate);
                    }
                    if (attrCondition.has("endDate") && !attrCondition.get("endDate").isJsonNull() && attrCondition.get("endDate").getAsString().length() > 0) {
                        Date endDate = format.parse(attrCondition.get("endDate").getAsString());
                        dateConditions.add(mdAttr.getColumnName() + "<=:endDate" + i);
                        parameters.put("endDate" + i, endDate);
                    }
                } catch (ParseException e) {
                    throw new ProgrammingErrorException(e);
                }
                if (dateConditions.size() > 0) {
                    lAttrConditions.add("(" + StringUtils.join(dateConditions, " AND ") + ")");
                }
            } else if (attrCondition.has("value") && !attrCondition.get("value").isJsonNull() && attrCondition.get("value").getAsString().length() > 0) {
                String value = attrCondition.get("value").getAsString();
                lAttrConditions.add(mdAttr.getColumnName() + "=:val" + i);
                parameters.put("val" + i, value);
            }
        }
        if (lAttrConditions.size() > 0) {
            whereConditions.add(StringUtils.join(lAttrConditions, " AND "));
        }
    }
    if (whereConditions.size() > 0) {
        statement.append(" WHERE " + StringUtils.join(whereConditions, " AND "));
    }
}
Also used : ArrayList(java.util.ArrayList) JsonObject(com.google.gson.JsonObject) Date(java.util.Date) ProgrammingErrorException(com.runwaysdk.dataaccess.ProgrammingErrorException) JsonArray(com.google.gson.JsonArray) MdAttributeDAOIF(com.runwaysdk.dataaccess.MdAttributeDAOIF) SimpleDateFormat(java.text.SimpleDateFormat) DateFormat(java.text.DateFormat) MdVertexDAO(com.runwaysdk.dataaccess.metadata.graph.MdVertexDAO) ParseException(java.text.ParseException) SimpleDateFormat(java.text.SimpleDateFormat)

Example 24 with MdAttributeDAOIF

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

the class TransitionEvent method getAll.

public static List<TransitionEvent> getAll(ServerGeoObjectType type) {
    MdVertexDAOIF mdVertex = MdVertexDAO.getMdVertexDAO(TransitionEvent.CLASS);
    MdAttributeDAOIF beforeTypeCode = mdVertex.definesAttribute(TransitionEvent.BEFORETYPECODE);
    MdAttributeDAOIF afterTypeCode = mdVertex.definesAttribute(TransitionEvent.AFTERTYPECODE);
    List<ServerGeoObjectType> types = new LinkedList<ServerGeoObjectType>();
    types.add(type);
    types.addAll(type.getSubtypes());
    List<String> codes = types.stream().map(t -> type.getCode()).collect(Collectors.toList());
    StringBuilder statement = new StringBuilder();
    statement.append("SELECT FROM " + mdVertex.getDBClassName());
    statement.append(" WHERE (" + beforeTypeCode.getColumnName() + " IN :typeCode");
    statement.append(" OR " + afterTypeCode.getColumnName() + " IN :typeCode )");
    GraphQuery<TransitionEvent> query = new GraphQuery<TransitionEvent>(statement.toString());
    query.setParameter("typeCode", codes);
    return query.getResults();
}
Also used : MdVertexDAOIF(com.runwaysdk.dataaccess.MdVertexDAOIF) RegistryRole(org.commongeoregistry.adapter.metadata.RegistryRole) JsonObject(com.google.gson.JsonObject) StringUtils(org.apache.commons.lang.StringUtils) TransitionImpact(net.geoprism.registry.graph.transition.Transition.TransitionImpact) ProgrammingErrorException(com.runwaysdk.dataaccess.ProgrammingErrorException) Date(java.util.Date) Transaction(com.runwaysdk.dataaccess.transaction.Transaction) SimpleDateFormat(java.text.SimpleDateFormat) HashMap(java.util.HashMap) LocalizedValue(org.commongeoregistry.adapter.dataaccess.LocalizedValue) ServerGeoObjectType(net.geoprism.registry.model.ServerGeoObjectType) JsonParser(com.google.gson.JsonParser) GeoObjectPermissionService(net.geoprism.registry.permission.GeoObjectPermissionService) GsonBuilder(com.google.gson.GsonBuilder) ServiceFactory(net.geoprism.registry.service.ServiceFactory) ArrayList(java.util.ArrayList) LocalizedValueConverter(net.geoprism.registry.conversion.LocalizedValueConverter) GeoObjectTypeRestrictionUtil(net.geoprism.registry.query.graph.GeoObjectTypeRestrictionUtil) Map(java.util.Map) ParseException(java.text.ParseException) LinkedList(java.util.LinkedList) TransitionPermissionService(net.geoprism.registry.transition.TransitionPermissionService) JsonSerializable(net.geoprism.registry.view.JsonSerializable) DateFormat(java.text.DateFormat) ServerGeoObjectIF(net.geoprism.registry.model.ServerGeoObjectIF) Optional(org.commongeoregistry.adapter.Optional) GraphQuery(com.runwaysdk.business.graph.GraphQuery) VertexServerGeoObject(net.geoprism.registry.model.graph.VertexServerGeoObject) RoleDAOIF(com.runwaysdk.business.rbac.RoleDAOIF) GeoRegistryUtil(net.geoprism.registry.GeoRegistryUtil) TransitionType(net.geoprism.registry.graph.transition.Transition.TransitionType) Collectors(java.util.stream.Collectors) MdVertexDAO(com.runwaysdk.dataaccess.metadata.graph.MdVertexDAO) Page(net.geoprism.registry.view.Page) MdVertexDAOIF(com.runwaysdk.dataaccess.MdVertexDAOIF) List(java.util.List) JsonArray(com.google.gson.JsonArray) SingleActorDAOIF(com.runwaysdk.business.rbac.SingleActorDAOIF) MdAttributeDAOIF(com.runwaysdk.dataaccess.MdAttributeDAOIF) GeoObjectImportConfiguration(net.geoprism.registry.io.GeoObjectImportConfiguration) Session(com.runwaysdk.session.Session) RolePermissionService(net.geoprism.registry.permission.RolePermissionService) MdAttributeDAOIF(com.runwaysdk.dataaccess.MdAttributeDAOIF) ServerGeoObjectType(net.geoprism.registry.model.ServerGeoObjectType) GraphQuery(com.runwaysdk.business.graph.GraphQuery) LinkedList(java.util.LinkedList)

Example 25 with MdAttributeDAOIF

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

the class CRAttributePatch method patchAllGos.

private void patchAllGos() {
    for (Universal uni : getUniversals()) {
        MdGeoVertexDAO mdVertex = GeoVertexType.getMdGeoVertex(uni.getUniversalId());
        List<? extends MdAttributeDAOIF> attributes = mdVertex.getAllDefinedMdAttributes();
        String[] skipAttrs = new String[] { DefaultAttribute.UID.getName(), "uuid", DefaultAttribute.CODE.getName(), DefaultAttribute.CREATE_DATE.getName(), DefaultAttribute.LAST_UPDATE_DATE.getName(), DefaultAttribute.SEQUENCE.getName(), DefaultAttribute.TYPE.getName(), MdAttributeConcreteInfo.OID, MdAttributeConcreteInfo.SEQUENCE };
        StringBuilder statement = new StringBuilder();
        statement.append("SELECT FROM " + mdVertex.getDBClassName());
        GraphQuery<VertexObject> query = new GraphQuery<VertexObject>(statement.toString());
        List<VertexObject> results = query.getResults();
        logger.info("Updating [" + results.size() + "] objects on table [" + mdVertex.getDBClassName() + "].");
        for (VertexObject vo : query.getResults()) {
            for (MdAttributeDAOIF attr : attributes) {
                if (!ArrayUtils.contains(skipAttrs, attr.definesAttribute())) {
                    ValueOverTimeCollection col = vo.getValuesOverTime(attr.definesAttribute());
                    for (ValueOverTime vot : col) {
                        vot.setOid(UUID.randomUUID().toString());
                    }
                }
            }
            vo.apply();
        }
    }
}
Also used : Universal(com.runwaysdk.system.gis.geo.Universal) VertexObject(com.runwaysdk.business.graph.VertexObject) ValueOverTime(com.runwaysdk.dataaccess.graph.attributes.ValueOverTime) MdAttributeDAOIF(com.runwaysdk.dataaccess.MdAttributeDAOIF) ValueOverTimeCollection(com.runwaysdk.dataaccess.graph.attributes.ValueOverTimeCollection) MdGeoVertexDAO(com.runwaysdk.gis.dataaccess.metadata.graph.MdGeoVertexDAO) GraphQuery(com.runwaysdk.business.graph.GraphQuery)

Aggregations

MdAttributeDAOIF (com.runwaysdk.dataaccess.MdAttributeDAOIF)32 MdVertexDAOIF (com.runwaysdk.dataaccess.MdVertexDAOIF)24 GraphQuery (com.runwaysdk.business.graph.GraphQuery)23 VertexObject (com.runwaysdk.business.graph.VertexObject)9 ServerGeoObjectType (net.geoprism.registry.model.ServerGeoObjectType)9 JsonObject (com.google.gson.JsonObject)7 Transaction (com.runwaysdk.dataaccess.transaction.Transaction)7 LinkedList (java.util.LinkedList)7 VertexServerGeoObject (net.geoprism.registry.model.graph.VertexServerGeoObject)7 Date (java.util.Date)5 JsonArray (com.google.gson.JsonArray)4 HashMap (java.util.HashMap)4 LocalizedValue (org.commongeoregistry.adapter.dataaccess.LocalizedValue)4 MdVertexDAO (com.runwaysdk.dataaccess.metadata.graph.MdVertexDAO)3 Page (net.geoprism.registry.view.Page)3 AttributeType (org.commongeoregistry.adapter.metadata.AttributeType)3 GsonBuilder (com.google.gson.GsonBuilder)2 MdAttributeTermDAOIF (com.runwaysdk.dataaccess.MdAttributeTermDAOIF)2 MdEdgeDAOIF (com.runwaysdk.dataaccess.MdEdgeDAOIF)2 ProgrammingErrorException (com.runwaysdk.dataaccess.ProgrammingErrorException)2