Search in sources :

Example 11 with TransitionEvent

use of net.geoprism.registry.graph.transition.TransitionEvent in project geoprism-registry by terraframe.

the class TransitionEventTest method testExportHistoricalReportToExcel.

@Test
@Request
public void testExportHistoricalReportToExcel() throws IOException {
    TransitionEvent event = new TransitionEvent();
    try {
        LocalizedValueConverter.populate(event, TransitionEvent.DESCRIPTION, new LocalizedValue("Test"));
        event.setEventDate(FastTestDataset.DEFAULT_OVER_TIME_DATE);
        event.setBeforeTypeCode(FastTestDataset.COUNTRY.getCode());
        event.setBeforeTypeOrgCode(FastTestDataset.COUNTRY.getOrganization().getCode());
        event.setAfterTypeCode(FastTestDataset.PROVINCE.getCode());
        event.setAfterTypeOrgCode(FastTestDataset.PROVINCE.getOrganization().getCode());
        event.apply();
        event.addTransition(FastTestDataset.CAMBODIA.getServerObject(), FastTestDataset.PROV_CENTRAL.getServerObject(), TransitionType.REASSIGN, TransitionImpact.FULL);
        InputStream istream = HistoricalRow.exportToExcel(FastTestDataset.PROVINCE.getServerObject(), FastTestDataset.DEFAULT_OVER_TIME_DATE, FastTestDataset.DEFAULT_OVER_TIME_DATE);
        Workbook workbook = WorkbookFactory.create(istream);
        Assert.assertEquals(1, workbook.getNumberOfSheets());
        Sheet sheet = workbook.getSheetAt(0);
        Assert.assertEquals(1, sheet.getLastRowNum());
        Row header = sheet.getRow(0);
        Assert.assertEquals("Event Id", header.getCell(0).getStringCellValue());
        Assert.assertEquals("Event Date", header.getCell(1).getStringCellValue());
        Assert.assertEquals("Event Type", header.getCell(2).getStringCellValue());
        Assert.assertEquals("Description", header.getCell(3).getStringCellValue());
        Assert.assertEquals("Before Type Code", header.getCell(4).getStringCellValue());
        Assert.assertEquals("Before Code", header.getCell(5).getStringCellValue());
        Assert.assertEquals("Before Label", header.getCell(6).getStringCellValue());
        Assert.assertEquals("After Type Code", header.getCell(7).getStringCellValue());
        Assert.assertEquals("After Code", header.getCell(8).getStringCellValue());
        Assert.assertEquals("After Label", header.getCell(9).getStringCellValue());
        Row row = sheet.getRow(1);
        Assert.assertEquals(event.getEventId(), new Long((long) row.getCell(0).getNumericCellValue()));
        Assert.assertEquals("2020-04-04", row.getCell(1).getStringCellValue());
        Assert.assertEquals("Reassign", row.getCell(2).getStringCellValue());
        Assert.assertEquals("Test", row.getCell(3).getStringCellValue());
        Assert.assertEquals(FastTestDataset.COUNTRY.getCode(), row.getCell(4).getStringCellValue());
        Assert.assertEquals(FastTestDataset.CAMBODIA.getCode(), row.getCell(5).getStringCellValue());
        Assert.assertEquals(FastTestDataset.CAMBODIA.getDisplayLabel(), row.getCell(6).getStringCellValue());
        Assert.assertEquals(FastTestDataset.PROVINCE.getCode(), row.getCell(7).getStringCellValue());
        Assert.assertEquals(FastTestDataset.PROV_CENTRAL.getCode(), row.getCell(8).getStringCellValue());
        Assert.assertEquals(FastTestDataset.PROV_CENTRAL.getDisplayLabel(), row.getCell(9).getStringCellValue());
    } finally {
        event.delete();
    }
}
Also used : LocalizedValue(org.commongeoregistry.adapter.dataaccess.LocalizedValue) InputStream(java.io.InputStream) TransitionEvent(net.geoprism.registry.graph.transition.TransitionEvent) HistoricalRow(net.geoprism.registry.view.HistoricalRow) Row(org.apache.poi.ss.usermodel.Row) Sheet(org.apache.poi.ss.usermodel.Sheet) Workbook(org.apache.poi.ss.usermodel.Workbook) Test(org.junit.Test) Request(com.runwaysdk.session.Request)

Example 12 with TransitionEvent

use of net.geoprism.registry.graph.transition.TransitionEvent in project geoprism-registry by terraframe.

the class TransitionEventTest method testAddTransition.

@Test
@Request
public void testAddTransition() {
    long beforeCount = new TaskQuery(new QueryFactory()).getCount();
    TransitionEvent event = new TransitionEvent();
    try {
        LocalizedValueConverter.populate(event, TransitionEvent.DESCRIPTION, new LocalizedValue("Test"));
        event.setEventDate(FastTestDataset.DEFAULT_OVER_TIME_DATE);
        event.setBeforeTypeCode(FastTestDataset.COUNTRY.getCode());
        event.setBeforeTypeOrgCode(FastTestDataset.COUNTRY.getOrganization().getCode());
        event.setAfterTypeCode(FastTestDataset.PROVINCE.getCode());
        event.setAfterTypeOrgCode(FastTestDataset.PROVINCE.getOrganization().getCode());
        event.apply();
        Transition transition = event.addTransition(FastTestDataset.CAMBODIA.getServerObject(), FastTestDataset.PROV_CENTRAL.getServerObject(), TransitionType.DOWNGRADE, TransitionImpact.FULL);
        Assert.assertEquals(6, Task.getTasks(transition.getOid()).size());
        List<Transition> transitions = event.getTransitions();
        Assert.assertEquals(1, transitions.size());
        transition = transitions.get(0);
        VertexServerGeoObject source = transition.getSourceVertex();
        VertexServerGeoObject target = transition.getTargetVertex();
        Assert.assertEquals(FastTestDataset.CAMBODIA.getCode(), source.getCode());
        Assert.assertEquals(FastTestDataset.PROV_CENTRAL.getCode(), target.getCode());
    } finally {
        event.delete();
    }
    // Ensure that the unresolved tasks are deleted on event delete
    Assert.assertEquals(beforeCount, new TaskQuery(new QueryFactory()).getCount());
}
Also used : QueryFactory(com.runwaysdk.query.QueryFactory) LocalizedValue(org.commongeoregistry.adapter.dataaccess.LocalizedValue) TaskQuery(net.geoprism.registry.task.TaskQuery) TransitionEvent(net.geoprism.registry.graph.transition.TransitionEvent) Transition(net.geoprism.registry.graph.transition.Transition) VertexServerGeoObject(net.geoprism.registry.model.graph.VertexServerGeoObject) Test(org.junit.Test) Request(com.runwaysdk.session.Request)

Example 13 with TransitionEvent

use of net.geoprism.registry.graph.transition.TransitionEvent in project geoprism-registry by terraframe.

the class TransitionEventTest method testRemoveTransitionsByTarget.

@Test
@Request
public void testRemoveTransitionsByTarget() {
    TransitionEvent event = new TransitionEvent();
    try {
        LocalizedValueConverter.populate(event, TransitionEvent.DESCRIPTION, new LocalizedValue("Test"));
        event.setEventDate(FastTestDataset.DEFAULT_OVER_TIME_DATE);
        event.setBeforeTypeCode(FastTestDataset.COUNTRY.getCode());
        event.setBeforeTypeOrgCode(FastTestDataset.COUNTRY.getOrganization().getCode());
        event.setAfterTypeCode(FastTestDataset.PROVINCE.getCode());
        event.setAfterTypeOrgCode(FastTestDataset.PROVINCE.getOrganization().getCode());
        event.apply();
        event.addTransition(FastTestDataset.CAMBODIA.getServerObject(), FastTestDataset.PROV_CENTRAL.getServerObject(), TransitionType.REASSIGN, TransitionImpact.FULL);
        Assert.assertEquals(1, event.getTransitions().size());
        Transition.removeAll(FastTestDataset.PROVINCE.getServerObject());
        Assert.assertEquals(0, event.getTransitions().size());
    } finally {
        event.delete();
    }
}
Also used : LocalizedValue(org.commongeoregistry.adapter.dataaccess.LocalizedValue) TransitionEvent(net.geoprism.registry.graph.transition.TransitionEvent) Test(org.junit.Test) Request(com.runwaysdk.session.Request)

Example 14 with TransitionEvent

use of net.geoprism.registry.graph.transition.TransitionEvent in project geoprism-registry by terraframe.

the class TransitionEventTest method testGetAll.

@Test
@Request
public void testGetAll() {
    TransitionEvent event = new TransitionEvent();
    try {
        LocalizedValueConverter.populate(event, TransitionEvent.DESCRIPTION, new LocalizedValue("Test"));
        event.setEventDate(FastTestDataset.DEFAULT_OVER_TIME_DATE);
        event.setBeforeTypeCode(FastTestDataset.COUNTRY.getCode());
        event.setBeforeTypeOrgCode(FastTestDataset.COUNTRY.getOrganization().getCode());
        event.setAfterTypeCode(FastTestDataset.PROVINCE.getCode());
        event.setAfterTypeOrgCode(FastTestDataset.PROVINCE.getOrganization().getCode());
        event.apply();
        event.addTransition(FastTestDataset.CAMBODIA.getServerObject(), FastTestDataset.PROV_CENTRAL.getServerObject(), TransitionType.REASSIGN, TransitionImpact.FULL);
        List<TransitionEvent> results = TransitionEvent.getAll(FastTestDataset.PROVINCE.getServerObject());
        Assert.assertEquals(1, results.size());
        TransitionEvent result = results.get(0);
        Assert.assertEquals(event.getOid(), result.getOid());
    } finally {
        event.delete();
    }
}
Also used : LocalizedValue(org.commongeoregistry.adapter.dataaccess.LocalizedValue) TransitionEvent(net.geoprism.registry.graph.transition.TransitionEvent) Test(org.junit.Test) Request(com.runwaysdk.session.Request)

Example 15 with TransitionEvent

use of net.geoprism.registry.graph.transition.TransitionEvent in project geoprism-registry by terraframe.

the class TransitionEventTest method testEventToJson.

@Test
@Request
public void testEventToJson() {
    DateFormat format = new SimpleDateFormat(GeoObjectImportConfiguration.DATE_FORMAT);
    format.setTimeZone(GeoRegistryUtil.SYSTEM_TIMEZONE);
    TransitionEvent event = new TransitionEvent();
    try {
        Date date = FastTestDataset.DEFAULT_OVER_TIME_DATE;
        LocalizedValue expectedDescription = new LocalizedValue("Test");
        LocalizedValueConverter.populate(event, TransitionEvent.DESCRIPTION, expectedDescription);
        event.setEventDate(date);
        event.setBeforeTypeCode(FastTestDataset.COUNTRY.getCode());
        event.setBeforeTypeOrgCode(FastTestDataset.COUNTRY.getOrganization().getCode());
        event.setAfterTypeCode(FastTestDataset.PROVINCE.getCode());
        event.setAfterTypeOrgCode(FastTestDataset.PROVINCE.getOrganization().getCode());
        event.apply();
        Assert.assertTrue(event.isAppliedToDb());
        event.addTransition(FastTestDataset.CAMBODIA.getServerObject(), FastTestDataset.PROV_CENTRAL.getServerObject(), TransitionType.REASSIGN, TransitionImpact.FULL);
        JsonObject json = event.toJSON(true);
        Assert.assertEquals(FastTestDataset.COUNTRY.getCode(), json.get(TransitionEvent.BEFORETYPECODE).getAsString());
        Assert.assertEquals(FastTestDataset.PROVINCE.getCode(), json.get(TransitionEvent.AFTERTYPECODE).getAsString());
        Assert.assertEquals(format.format(date), json.get(TransitionEvent.EVENTDATE).getAsString());
        LocalizedValue actualDescription = LocalizedValue.fromJSON(json.get(TransitionEvent.DESCRIPTION).getAsJsonObject());
        Assert.assertEquals(expectedDescription.getValue(), actualDescription.getValue());
        JsonArray transitions = json.get("transitions").getAsJsonArray();
        Assert.assertEquals(1, transitions.size());
        JsonObject object = transitions.get(0).getAsJsonObject();
        Assert.assertEquals(FastTestDataset.COUNTRY.getCode(), object.get("sourceType").getAsString());
        Assert.assertEquals(FastTestDataset.CAMBODIA.getCode(), object.get("sourceCode").getAsString());
        Assert.assertEquals(FastTestDataset.PROVINCE.getCode(), object.get("targetType").getAsString());
        Assert.assertEquals(FastTestDataset.PROV_CENTRAL.getCode(), object.get("targetCode").getAsString());
        Assert.assertEquals(TransitionType.REASSIGN.name(), object.get(Transition.TRANSITIONTYPE).getAsString());
        Assert.assertEquals(TransitionImpact.FULL.name(), object.get(Transition.IMPACT).getAsString());
    } finally {
        event.delete();
    }
}
Also used : JsonArray(com.google.gson.JsonArray) LocalizedValue(org.commongeoregistry.adapter.dataaccess.LocalizedValue) SimpleDateFormat(java.text.SimpleDateFormat) DateFormat(java.text.DateFormat) TransitionEvent(net.geoprism.registry.graph.transition.TransitionEvent) JsonObject(com.google.gson.JsonObject) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date) Test(org.junit.Test) Request(com.runwaysdk.session.Request)

Aggregations

Request (com.runwaysdk.session.Request)17 TransitionEvent (net.geoprism.registry.graph.transition.TransitionEvent)17 LocalizedValue (org.commongeoregistry.adapter.dataaccess.LocalizedValue)17 Test (org.junit.Test)16 HistoricalRow (net.geoprism.registry.view.HistoricalRow)4 Date (java.util.Date)3 Transition (net.geoprism.registry.graph.transition.Transition)3 JsonArray (com.google.gson.JsonArray)2 JsonObject (com.google.gson.JsonObject)2 QueryFactory (com.runwaysdk.query.QueryFactory)2 VertexServerGeoObject (net.geoprism.registry.model.graph.VertexServerGeoObject)2 TaskQuery (net.geoprism.registry.task.TaskQuery)2 ProgrammingErrorException (com.runwaysdk.dataaccess.ProgrammingErrorException)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 DateFormat (java.text.DateFormat)1 SimpleDateFormat (java.text.SimpleDateFormat)1 Task (net.geoprism.registry.task.Task)1 Row (org.apache.poi.ss.usermodel.Row)1 Sheet (org.apache.poi.ss.usermodel.Sheet)1