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