use of net.geoprism.registry.transition.TransitionPermissionService in project geoprism-registry by terraframe.
the class TransitionEvent method toJSON.
public JsonObject toJSON(boolean includeTransitions) {
DateFormat format = new SimpleDateFormat(GeoObjectImportConfiguration.DATE_FORMAT);
format.setTimeZone(GeoRegistryUtil.SYSTEM_TIMEZONE);
LocalizedValue localizedValue = LocalizedValueConverter.convert(this.getEmbeddedComponent(TransitionEvent.DESCRIPTION));
ServerGeoObjectType beforeType = ServerGeoObjectType.get(this.getBeforeTypeCode());
ServerGeoObjectType afterType = ServerGeoObjectType.get(this.getAfterTypeCode());
JsonObject object = new JsonObject();
object.addProperty(TransitionEvent.OID, this.getOid());
object.addProperty(TransitionEvent.EVENTID, this.getEventId());
object.addProperty(TransitionEvent.BEFORETYPECODE, beforeType.getCode());
object.addProperty(TransitionEvent.AFTERTYPECODE, afterType.getCode());
object.addProperty(TransitionEvent.EVENTDATE, format.format(this.getEventDate()));
object.addProperty("beforeTypeLabel", beforeType.getLabel().getValue());
object.addProperty("afterTypeLabel", afterType.getLabel().getValue());
object.add(TransitionEvent.DESCRIPTION, localizedValue.toJSON());
GsonBuilder builder = new GsonBuilder();
JsonArray ja = builder.create().toJsonTree(new TransitionPermissionService().getPermissions(this)).getAsJsonArray();
object.add("permissions", ja);
if (includeTransitions) {
JsonArray transitions = this.getTransitions().stream().map(e -> e.toJSON()).collect(() -> new JsonArray(), (array, element) -> array.add(element), (listA, listB) -> listA.addAll(listB));
object.add("transitions", transitions);
}
return object;
}
Aggregations