use of org.commongeoregistry.adapter.metadata.CustomSerializer in project geoprism-registry by terraframe.
the class LocationService method getLocationInformationJson.
@Request(RequestType.SESSION)
public JsonElement getLocationInformationJson(String sessionId, Date date, String typeCode, String hierarchyCode) {
LocationInformation information = this.getLocationInformation(sessionId, date, typeCode, hierarchyCode);
CustomSerializer serializer = ServiceFactory.getRegistryService().serializer(sessionId);
return information.toJson(serializer);
}
use of org.commongeoregistry.adapter.metadata.CustomSerializer in project geoprism-registry by terraframe.
the class RegistryService method initHierarchyManager.
@Request(RequestType.SESSION)
public JsonObject initHierarchyManager(String sessionId) {
GeoObjectType[] gots = this.getGeoObjectTypes(sessionId, null, null, PermissionContext.READ);
HierarchyType[] hts = ServiceFactory.getHierarchyService().getHierarchyTypes(sessionId, null, PermissionContext.READ);
OrganizationDTO[] orgDtos = RegistryService.getInstance().getOrganizations(sessionId, null);
CustomSerializer serializer = this.serializer(sessionId);
JsonArray types = new JsonArray();
for (GeoObjectType got : gots) {
JsonObject joGot = got.toJSON(serializer);
JsonArray relatedHiers = new JsonArray();
for (HierarchyType ht : hts) {
List<HierarchyNode> hns = ht.getRootGeoObjectTypes();
for (HierarchyNode hn : hns) {
if (hn.hierarchyHasGeoObjectType(got.getCode(), true)) {
relatedHiers.add(ht.getCode());
}
}
}
joGot.add("relatedHierarchies", relatedHiers);
types.add(joGot);
}
JsonArray hierarchies = new JsonArray();
for (HierarchyType ht : hts) {
hierarchies.add(ht.toJSON(serializer));
}
JsonArray organizations = new JsonArray();
for (OrganizationDTO dto : orgDtos) {
organizations.add(dto.toJSON(serializer));
}
JsonObject response = new JsonObject();
response.add("types", types);
response.add("hierarchies", hierarchies);
response.add("organizations", organizations);
response.add("locales", this.getLocales(sessionId));
return response;
}
use of org.commongeoregistry.adapter.metadata.CustomSerializer in project geoprism-registry by terraframe.
the class RegistryService method newGeoObjectInstance2.
@Request(RequestType.SESSION)
public String newGeoObjectInstance2(String sessionId, String geoObjectTypeCode) {
CustomSerializer serializer = ServiceFactory.getRegistryService().serializer(sessionId);
JSONObject joResp = new JSONObject();
/**
* Create a new GeoObject
*/
GeoObject go = this.adapter.newGeoObjectInstance(geoObjectTypeCode);
/**
* Add all locales so the front-end knows what are available.
*/
LocalizedValue label = new LocalizedValue("");
label.setValue(MdAttributeLocalInfo.DEFAULT_LOCALE, "");
Set<Locale> locales = LocalizationFacade.getInstalledLocales();
for (Locale locale : locales) {
label.setValue(locale, "");
}
go.setValue(DefaultAttribute.DISPLAY_LABEL.getName(), label);
/**
* Serialize the GeoObject and add it to the response
*/
JsonObject jsonObject = go.toJSON(serializer);
joResp.put("geoObject", new JSONObject(jsonObject.toString()));
JsonArray hierarchies = ServiceFactory.getHierarchyService().getHierarchiesForType(sessionId, go.getType().getCode(), true);
joResp.put("hierarchies", new JSONArray(hierarchies.toString()));
return joResp.toString();
}
use of org.commongeoregistry.adapter.metadata.CustomSerializer in project geoprism-registry by terraframe.
the class SynchronizationConfigService method getConfigForExternalSystem.
@Request(RequestType.SESSION)
public JsonObject getConfigForExternalSystem(String sessionId, String externalSystemId, String hierarchyTypeCode) {
JsonObject ret = new JsonObject();
// Add GeoObjectTypes
GeoObjectType[] gots = ServiceFactory.getRegistryService().getGeoObjectTypes(sessionId, null, new String[] { hierarchyTypeCode }, PermissionContext.WRITE);
CustomSerializer serializer = ServiceFactory.getRegistryService().serializer(sessionId);
JsonArray jarray = new JsonArray();
for (int i = 0; i < gots.length; ++i) {
jarray.add(gots[i].toJSON(serializer));
}
ret.add("types", jarray);
// Add DHIS2 OrgUnitGroups
DHIS2ExternalSystem system = DHIS2ExternalSystem.get(externalSystemId);
try {
DHIS2TransportServiceIF dhis2 = DHIS2ServiceFactory.buildDhis2TransportService(system);
JsonArray jaGroups = new JsonArray();
MetadataGetResponse<OrganisationUnitGroup> resp = dhis2.<OrganisationUnitGroup>metadataGet(OrganisationUnitGroup.class);
List<OrganisationUnitGroup> groups = resp.getObjects();
for (OrganisationUnitGroup group : groups) {
JsonObject joGroup = new JsonObject();
joGroup.addProperty("id", group.getId());
joGroup.addProperty("name", group.getName());
jaGroups.add(joGroup);
}
ret.add("orgUnitGroups", jaGroups);
} catch (InvalidLoginException e) {
LoginException cgrlogin = new LoginException(e);
throw cgrlogin;
} catch (HTTPException | UnexpectedResponseException | IllegalArgumentException | BadServerUriException e) {
HttpError cgrhttp = new HttpError(e);
throw cgrhttp;
}
return ret;
}
Aggregations