Search in sources :

Example 31 with MdAttributeDAOIF

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);
}
Also used : MdVertexDAOIF(com.runwaysdk.dataaccess.MdVertexDAOIF) Transition(net.geoprism.registry.graph.transition.Transition) JsonObject(com.google.gson.JsonObject) TransitionEvent(net.geoprism.registry.graph.transition.TransitionEvent) Date(java.util.Date) GraphQuery(com.runwaysdk.business.graph.GraphQuery) LocalizationFacade(net.geoprism.localization.LocalizationFacade) IOException(java.io.IOException) LocalizedValue(org.commongeoregistry.adapter.dataaccess.LocalizedValue) ServerGeoObjectType(net.geoprism.registry.model.ServerGeoObjectType) Collectors(java.util.stream.Collectors) GsonBuilder(com.google.gson.GsonBuilder) MdVertexDAO(com.runwaysdk.dataaccess.metadata.graph.MdVertexDAO) JsonElement(com.google.gson.JsonElement) MdVertexDAOIF(com.runwaysdk.dataaccess.MdVertexDAOIF) List(java.util.List) HistoricalReportExcelExporter(net.geoprism.registry.excel.HistoricalReportExcelExporter) LocalizedValueConverter(net.geoprism.registry.conversion.LocalizedValueConverter) Map(java.util.Map) MdAttributeDAOIF(com.runwaysdk.dataaccess.MdAttributeDAOIF) SeverGeoObjectJsonAdapters(net.geoprism.registry.etl.export.SeverGeoObjectJsonAdapters) LinkedList(java.util.LinkedList) InputStream(java.io.InputStream) ServerGeoObjectType(net.geoprism.registry.model.ServerGeoObjectType) LinkedList(java.util.LinkedList) MdAttributeDAOIF(com.runwaysdk.dataaccess.MdAttributeDAOIF) JsonObject(com.google.gson.JsonObject) Map(java.util.Map) GraphQuery(com.runwaysdk.business.graph.GraphQuery)

Example 32 with MdAttributeDAOIF

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);
}
Also used : LocalizedValue(org.commongeoregistry.adapter.dataaccess.LocalizedValue) ServerGeoObjectType(net.geoprism.registry.model.ServerGeoObjectType) GeoObjectType(org.commongeoregistry.adapter.metadata.GeoObjectType) MdAttributeDAOIF(com.runwaysdk.dataaccess.MdAttributeDAOIF) AttributeType(org.commongeoregistry.adapter.metadata.AttributeType) MdAttributeMomentDAOIF(com.runwaysdk.dataaccess.MdAttributeMomentDAOIF) Test(org.junit.Test) ClassificationTypeTest(net.geoprism.registry.classification.ClassificationTypeTest)

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