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());
}
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;
}
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 "));
}
}
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();
}
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();
}
}
}
Aggregations