Search in sources :

Example 26 with CustomSerializer

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);
}
Also used : LocationInformation(net.geoprism.registry.view.LocationInformation) CustomSerializer(org.commongeoregistry.adapter.metadata.CustomSerializer) Request(com.runwaysdk.session.Request)

Example 27 with CustomSerializer

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;
}
Also used : JsonArray(com.google.gson.JsonArray) ServerHierarchyType(net.geoprism.registry.model.ServerHierarchyType) HierarchyType(org.commongeoregistry.adapter.metadata.HierarchyType) ServerGeoObjectType(net.geoprism.registry.model.ServerGeoObjectType) GeoObjectType(org.commongeoregistry.adapter.metadata.GeoObjectType) JsonObject(com.google.gson.JsonObject) CustomSerializer(org.commongeoregistry.adapter.metadata.CustomSerializer) OrganizationDTO(org.commongeoregistry.adapter.metadata.OrganizationDTO) HierarchyNode(org.commongeoregistry.adapter.metadata.HierarchyNode) Request(com.runwaysdk.session.Request) OAuthClientRequest(org.apache.oltu.oauth2.client.request.OAuthClientRequest)

Example 28 with CustomSerializer

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();
}
Also used : Locale(java.util.Locale) JsonArray(com.google.gson.JsonArray) JSONObject(org.json.JSONObject) LocalizedValue(org.commongeoregistry.adapter.dataaccess.LocalizedValue) JSONArray(org.json.JSONArray) JsonObject(com.google.gson.JsonObject) CustomSerializer(org.commongeoregistry.adapter.metadata.CustomSerializer) GeoObject(org.commongeoregistry.adapter.dataaccess.GeoObject) Request(com.runwaysdk.session.Request) OAuthClientRequest(org.apache.oltu.oauth2.client.request.OAuthClientRequest)

Example 29 with CustomSerializer

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;
}
Also used : DHIS2TransportServiceIF(net.geoprism.registry.etl.export.dhis2.DHIS2TransportServiceIF) HTTPException(net.geoprism.dhis2.dhis2adapter.exception.HTTPException) DHIS2ExternalSystem(net.geoprism.registry.graph.DHIS2ExternalSystem) JsonObject(com.google.gson.JsonObject) CustomSerializer(org.commongeoregistry.adapter.metadata.CustomSerializer) BadServerUriException(net.geoprism.dhis2.dhis2adapter.exception.BadServerUriException) JsonArray(com.google.gson.JsonArray) OrganisationUnitGroup(net.geoprism.dhis2.dhis2adapter.response.model.OrganisationUnitGroup) GeoObjectType(org.commongeoregistry.adapter.metadata.GeoObjectType) InvalidLoginException(net.geoprism.dhis2.dhis2adapter.exception.InvalidLoginException) LoginException(net.geoprism.registry.etl.export.LoginException) InvalidLoginException(net.geoprism.dhis2.dhis2adapter.exception.InvalidLoginException) UnexpectedResponseException(net.geoprism.dhis2.dhis2adapter.exception.UnexpectedResponseException) HttpError(net.geoprism.registry.etl.export.HttpError) Request(com.runwaysdk.session.Request)

Aggregations

CustomSerializer (org.commongeoregistry.adapter.metadata.CustomSerializer)29 Endpoint (com.runwaysdk.mvc.Endpoint)25 RestBodyResponse (com.runwaysdk.mvc.RestBodyResponse)25 HierarchyType (org.commongeoregistry.adapter.metadata.HierarchyType)12 JsonArray (com.google.gson.JsonArray)8 GeoObject (org.commongeoregistry.adapter.dataaccess.GeoObject)7 JsonObject (com.google.gson.JsonObject)5 OrganizationDTO (org.commongeoregistry.adapter.metadata.OrganizationDTO)5 Request (com.runwaysdk.session.Request)4 GeoObjectOverTime (org.commongeoregistry.adapter.dataaccess.GeoObjectOverTime)4 Date (java.util.Date)2 OAuthClientRequest (org.apache.oltu.oauth2.client.request.OAuthClientRequest)2 GeoObjectType (org.commongeoregistry.adapter.metadata.GeoObjectType)2 JSONArray (org.json.JSONArray)2 Locale (java.util.Locale)1 BadServerUriException (net.geoprism.dhis2.dhis2adapter.exception.BadServerUriException)1 HTTPException (net.geoprism.dhis2.dhis2adapter.exception.HTTPException)1 InvalidLoginException (net.geoprism.dhis2.dhis2adapter.exception.InvalidLoginException)1 UnexpectedResponseException (net.geoprism.dhis2.dhis2adapter.exception.UnexpectedResponseException)1 OrganisationUnitGroup (net.geoprism.dhis2.dhis2adapter.response.model.OrganisationUnitGroup)1