use of com.runwaysdk.dataaccess.MdAttributeDAOIF in project geoprism-registry by terraframe.
the class HistoricalRow method getHistoricalReport.
public static Page<HistoricalRow> getHistoricalReport(ServerGeoObjectType type, Date startDate, Date endDate, Integer pageSize, Integer pageNumber) {
MdVertexDAOIF transitionVertex = MdVertexDAO.getMdVertexDAO(Transition.CLASS);
MdAttributeDAOIF eventAttribute = transitionVertex.definesAttribute(Transition.EVENT);
MdAttributeDAOIF sourceAttribute = transitionVertex.definesAttribute(Transition.SOURCE);
MdAttributeDAOIF targetAttribute = transitionVertex.definesAttribute(Transition.TARGET);
MdAttributeDAOIF transitionAttribute = transitionVertex.definesAttribute(Transition.TRANSITIONTYPE);
MdVertexDAOIF eventVertex = MdVertexDAO.getMdVertexDAO(TransitionEvent.CLASS);
MdAttributeDAOIF eventId = eventVertex.definesAttribute(TransitionEvent.EVENTID);
MdAttributeDAOIF beforeTypeCode = eventVertex.definesAttribute(TransitionEvent.BEFORETYPECODE);
MdAttributeDAOIF afterTypeCode = eventVertex.definesAttribute(TransitionEvent.AFTERTYPECODE);
MdAttributeDAOIF eventDate = eventVertex.definesAttribute(TransitionEvent.EVENTDATE);
MdAttributeDAOIF description = eventVertex.definesAttribute(TransitionEvent.DESCRIPTION);
List<ServerGeoObjectType> types = new LinkedList<ServerGeoObjectType>();
types.add(type);
types.addAll(type.getSubtypes());
List<String> codes = types.stream().map(t -> t.getCode()).distinct().collect(Collectors.toList());
StringBuilder statement = new StringBuilder();
statement.append("SELECT " + eventAttribute.getColumnName() + "." + eventId.getColumnName() + " AS " + HistoricalRow.EVENT_ID);
statement.append(", " + eventAttribute.getColumnName() + "." + eventDate.getColumnName() + " AS " + HistoricalRow.EVENT_DATE);
statement.append(", " + transitionAttribute.getColumnName() + " AS " + HistoricalRow.EVENT_TYPE);
statement.append(", " + eventAttribute.getColumnName() + "." + description.getColumnName() + " AS " + HistoricalRow.DESCRIPTION);
statement.append(", " + eventAttribute.getColumnName() + "." + beforeTypeCode.getColumnName() + " AS " + HistoricalRow.BEFORE_TYPE);
statement.append(", " + sourceAttribute.getColumnName() + ".code AS " + HistoricalRow.BEFORE_CODE);
statement.append(", " + sourceAttribute.getColumnName() + ".displayLabel_cot AS " + HistoricalRow.BEFORE_LABEL);
statement.append(", " + eventAttribute.getColumnName() + "." + afterTypeCode.getColumnName() + " AS " + HistoricalRow.AFTER_TYPE);
statement.append(", " + targetAttribute.getColumnName() + ".code AS " + HistoricalRow.AFTER_CODE);
statement.append(", " + targetAttribute.getColumnName() + ".displayLabel_cot AS " + HistoricalRow.AFTER_LABEL);
statement.append(" FROM " + transitionVertex.getDBClassName());
statement.append(" WHERE ( " + eventAttribute.getColumnName() + "." + beforeTypeCode.getColumnName() + " IN :typeCode");
statement.append(" OR " + eventAttribute.getColumnName() + "." + afterTypeCode.getColumnName() + " IN :typeCode )");
statement.append(" AND " + eventAttribute.getColumnName() + "." + eventDate.getColumnName() + " BETWEEN :startDate AND :endDate");
statement.append(" ORDER BY " + eventAttribute.getColumnName() + "." + eventDate.getColumnName() + " DESC");
statement.append(", " + eventAttribute.getColumnName() + "." + eventId.getColumnName());
statement.append(", " + sourceAttribute.getColumnName() + ".code");
statement.append(", " + targetAttribute.getColumnName() + ".code");
if (pageNumber != null && pageSize != null) {
statement.append(" SKIP " + ((pageNumber - 1) * pageSize) + " LIMIT " + pageSize);
}
GraphQuery<Map<String, Object>> query = new GraphQuery<Map<String, Object>>(statement.toString());
query.setParameter("typeCode", codes);
query.setParameter("startDate", startDate);
query.setParameter("endDate", endDate);
Long count = getCount(type, startDate, endDate);
List<HistoricalRow> results = query.getRawResults().stream().map(list -> HistoricalRow.parse(list)).collect(Collectors.toList());
return new Page<HistoricalRow>(count, pageNumber, pageSize, results);
}
use of com.runwaysdk.dataaccess.MdAttributeDAOIF in project geoprism-registry by terraframe.
the class AttributeTypeServiceTest method testCreateGeoObjectTypeDate.
@Test
public void testCreateGeoObjectTypeDate() {
String organizationCode = FastTestDataset.ORG_CGOV.getCode();
GeoObjectType province = MetadataFactory.newGeoObjectType(TEST_GOT.getCode(), GeometryType.POLYGON, new LocalizedValue("Province"), new LocalizedValue(""), true, organizationCode, testData.adapter);
String gtJSON = province.toJSON().toString();
AttributeType testDate = AttributeType.factory("testDate", new LocalizedValue("testDateLocalName"), new LocalizedValue("testDateLocalDescrip"), AttributeDateType.TYPE, false, false, false);
testData.adapter.createGeoObjectType(gtJSON);
String geoObjectTypeCode = province.getCode();
String attributeTypeJSON = testDate.toJSON().toString();
testDate = testData.adapter.createAttributeType(geoObjectTypeCode, attributeTypeJSON);
MdAttributeDAOIF mdAttributeConcreteDAOIF = checkAttribute(TEST_GOT.getCode(), testDate.getName());
Assert.assertNotNull("A GeoObjectType did not define the attribute: " + testDate.getName(), mdAttributeConcreteDAOIF);
Assert.assertTrue("A GeoObjectType did not define the attribute of the correct type: " + mdAttributeConcreteDAOIF.getType(), mdAttributeConcreteDAOIF instanceof MdAttributeMomentDAOIF);
}
Aggregations