Search in sources :

Example 26 with Endpoint

use of com.runwaysdk.mvc.Endpoint in project geoprism-registry by terraframe.

the class RegistryController method updateGeoObjectOverTime.

@Endpoint(method = ServletMethod.POST, error = ErrorSerialization.JSON, url = RegistryUrls.GEO_OBJECT_TIME_UPDATE)
public ResponseIF updateGeoObjectOverTime(ClientRequestIF request, @RequestParamter(name = RegistryUrls.GEO_OBJECT_TIME_UPDATE_PARAM_GEOOBJECT) String jGeoObj) {
    GeoObjectOverTime goTime = this.registryService.updateGeoObjectOverTime(request.getSessionId(), jGeoObj);
    CustomSerializer serializer = this.registryService.serializer(request.getSessionId());
    return new RestBodyResponse(goTime.toJSON(serializer));
}
Also used : GeoObjectOverTime(org.commongeoregistry.adapter.dataaccess.GeoObjectOverTime) CustomSerializer(org.commongeoregistry.adapter.metadata.CustomSerializer) RestBodyResponse(com.runwaysdk.mvc.RestBodyResponse) Endpoint(com.runwaysdk.mvc.Endpoint)

Example 27 with Endpoint

use of com.runwaysdk.mvc.Endpoint in project geoprism-registry by terraframe.

the class RegistryController method getGeoObjectByCode.

/**
 * Returns a GeoObject with the given code.
 *
 * @pre @post
 *
 * @param uid
 *          The UID of the GeoObject.
 *
 * @returns a GeoObject in GeoJSON format with the given uid. @throws
 */
@Endpoint(method = ServletMethod.GET, error = ErrorSerialization.JSON, url = RegistryUrls.GEO_OBJECT_GET_CODE)
public ResponseIF getGeoObjectByCode(ClientRequestIF request, @RequestParamter(name = RegistryUrls.GEO_OBJECT_GET_CODE_PARAM_CODE) String code, @RequestParamter(name = RegistryUrls.GEO_OBJECT_GET_CODE_PARAM_TYPE_CODE) String typeCode, @RequestParamter(name = "date") String date) throws JSONException {
    GeoObject geoObject = this.registryService.getGeoObjectByCode(request.getSessionId(), code, typeCode, GeoRegistryUtil.parseDate(date, true));
    CustomSerializer serializer = this.registryService.serializer(request.getSessionId());
    return new RestBodyResponse(geoObject.toJSON(serializer));
}
Also used : GeoObject(org.commongeoregistry.adapter.dataaccess.GeoObject) CustomSerializer(org.commongeoregistry.adapter.metadata.CustomSerializer) RestBodyResponse(com.runwaysdk.mvc.RestBodyResponse) Endpoint(com.runwaysdk.mvc.Endpoint)

Example 28 with Endpoint

use of com.runwaysdk.mvc.Endpoint in project geoprism-registry by terraframe.

the class RegistryController method getGeoObjectTypes.

/**
 * Returns an array of {@link GeoOjectType} objects that define the given list
 * of types.
 *
 * @pre @post
 *
 * @param types
 *          A serialized json array of GeoObjectType codes. If blank then all
 *          GeoObjectType objects are returned.
 * @param hierarchies
 *          A serialized json array of HierarchyType codes. If blank then
 *          GeoObjectTypes belonging to all hierarchies are returned.
 *
 * @returns @throws
 */
@Endpoint(method = ServletMethod.GET, error = ErrorSerialization.JSON, url = RegistryUrls.GEO_OBJECT_TYPE_GET_ALL)
public ResponseIF getGeoObjectTypes(ClientRequestIF request, @RequestParamter(name = RegistryUrls.GEO_OBJECT_TYPE_GET_ALL_PARAM_TYPES) String types, @RequestParamter(name = RegistryUrls.GEO_OBJECT_TYPE_GET_ALL_PARAM_HIERARCHIES) String hierarchies, @RequestParamter(name = "context") String context) {
    String[] aTypes = null;
    if (types != null) {
        JSONArray jaTypes = new JSONArray(types);
        aTypes = new String[jaTypes.length()];
        for (int i = 0; i < jaTypes.length(); i++) {
            aTypes[i] = jaTypes.getString(i);
        }
    }
    String[] aHierarchies = null;
    if (hierarchies != null) {
        JSONArray jaHierarchies = new JSONArray(hierarchies);
        aHierarchies = new String[jaHierarchies.length()];
        for (int i = 0; i < jaHierarchies.length(); i++) {
            aHierarchies[i] = jaHierarchies.getString(i);
        }
    }
    PermissionContext pContext = PermissionContext.get(context);
    GeoObjectType[] gots = this.registryService.getGeoObjectTypes(request.getSessionId(), aTypes, aHierarchies, pContext);
    JsonArray jarray = new JsonArray();
    for (int i = 0; i < gots.length; ++i) {
        JsonObject jo = this.registryService.serialize(request.getSessionId(), gots[i]);
        jarray.add(jo);
    }
    return new RestBodyResponse(jarray);
}
Also used : JsonArray(com.google.gson.JsonArray) GeoObjectType(org.commongeoregistry.adapter.metadata.GeoObjectType) JSONArray(org.json.JSONArray) PermissionContext(net.geoprism.registry.permission.PermissionContext) JsonObject(com.google.gson.JsonObject) RestBodyResponse(com.runwaysdk.mvc.RestBodyResponse) Endpoint(com.runwaysdk.mvc.Endpoint) Endpoint(com.runwaysdk.mvc.Endpoint)

Example 29 with Endpoint

use of com.runwaysdk.mvc.Endpoint in project geoprism-registry by terraframe.

the class RegistryLocationController method search.

@Endpoint(error = ErrorSerialization.JSON)
public ResponseIF search(ClientRequestIF request, @RequestParamter(name = "text") String text, @RequestParamter(name = "date") String date) throws JSONException, ParseException {
    List<GeoObject> results = service.search(request.getSessionId(), text, parseDate(date));
    CustomSerializer serializer = ServiceFactory.getRegistryService().serializer(request.getSessionId());
    JsonArray features = results.stream().collect(() -> new JsonArray(), (array, element) -> array.add(element.toJSON(serializer)), (listA, listB) -> {
    });
    JsonObject featureCollection = new JsonObject();
    featureCollection.addProperty("type", "FeatureCollection");
    featureCollection.add("features", features);
    return new RestBodyResponse(featureCollection);
}
Also used : JsonArray(com.google.gson.JsonArray) JsonObject(com.google.gson.JsonObject) GeoObject(org.commongeoregistry.adapter.dataaccess.GeoObject) CustomSerializer(org.commongeoregistry.adapter.metadata.CustomSerializer) RestBodyResponse(com.runwaysdk.mvc.RestBodyResponse) Endpoint(com.runwaysdk.mvc.Endpoint)

Example 30 with Endpoint

use of com.runwaysdk.mvc.Endpoint in project geoprism-registry by terraframe.

the class RegistrySessionController method ologin.

@Endpoint(method = ServletMethod.GET, error = ErrorSerialization.JSON)
public ResponseIF ologin(ServletRequestIF req, @RequestParamter(name = "code", required = true) String code, @RequestParamter(name = "state", required = true) String state) throws MalformedURLException, JSONException {
    final SessionController geoprism = new SessionController();
    // URL url = new URL(req.getScheme(), req.getServerName(), req.getServerPort(), req.getContextPath());
    // 
    // String redirect = url.toString();
    JSONObject stateObject = new JSONObject(state);
    String serverId = stateObject.getString(OauthServerIF.SERVER_ID);
    Locale[] locales = geoprism.getLocales(req);
    WebClientSession clientSession = WebClientSession.createAnonymousSession(locales);
    try {
        ClientRequestIF clientRequest = clientSession.getRequest();
        String cgrSessionJsonString = RegistrySessionServiceDTO.ologin(clientRequest, serverId, code, LocaleSerializer.serialize(locales), null);
        JsonObject cgrSessionJson = (JsonObject) JsonParser.parseString(cgrSessionJsonString);
        final String sessionId = cgrSessionJson.get("sessionId").getAsString();
        final String username = cgrSessionJson.get("username").getAsString();
        geoprism.createSession(req, sessionId, locales);
        clientRequest = (ClientRequestIF) req.getAttribute(ClientConstants.CLIENTREQUEST);
        JsonArray roles = (JsonArray) JsonParser.parseString(RoleViewDTO.getCurrentRoles(clientRequest));
        JsonArray roleDisplayLabels = (JsonArray) JsonParser.parseString(RoleViewDTO.getCurrentRoleDisplayLabels(clientRequest));
        JsonObject cookieJson = new JsonObject();
        cookieJson.addProperty("loggedIn", clientRequest.isLoggedIn());
        cookieJson.add("roles", roles);
        cookieJson.add("roleDisplayLabels", roleDisplayLabels);
        cookieJson.addProperty("userName", username);
        cookieJson.addProperty("version", ClientConfigurationService.getServerVersion());
        // final Locale sessionLocale = Session.getCurrentLocale();
        // 
        // JsonArray installedLocalesArr = new JsonArray();
        // Set<SupportedLocaleIF> installedLocales = LocalizationFacade.getSupportedLocales();
        // for (SupportedLocaleIF supportedLocale : installedLocales)
        // {
        // Locale locale = supportedLocale.getLocale();
        // 
        // JsonObject locObj = new JsonObject();
        // locObj.addProperty("language", locale.getDisplayLanguage(sessionLocale));
        // locObj.addProperty("country", locale.getDisplayCountry(sessionLocale));
        // locObj.addProperty("name", locale.getDisplayName(sessionLocale));
        // locObj.addProperty("variant", locale.getDisplayVariant(sessionLocale));
        // 
        // installedLocalesArr.add(locObj);
        // }
        JsonArray jaLocales = ServiceFactory.getRegistryService().getLocales(clientRequest.getSessionId());
        cookieJson.add("installedLocales", jaLocales);
        final String cookieValue = URLEncoder.encode(cookieJson.toString(), "UTF-8");
        Cookie cookie = new Cookie("user", cookieValue);
        cookie.setMaxAge(-1);
        RedirectResponse response = new RedirectResponse("/");
        response.addCookie(cookie);
        return response;
    } catch (Throwable t) {
        Locale locale = CommonProperties.getDefaultLocale();
        if (locales.length > 0) {
            locale = locales[0];
        }
        String errorMessage = RunwayException.localizeThrowable(t, locale);
        try {
            errorMessage = URLEncoder.encode(errorMessage, StandardCharsets.UTF_8.name());
        } catch (Throwable t2) {
            throw new ProgrammingErrorException(t2);
        }
        RedirectResponse response = new RedirectResponse("/cgr/manage#/login/" + errorMessage);
        return response;
    } finally {
        clientSession.logout();
    }
}
Also used : Locale(java.util.Locale) Cookie(javax.servlet.http.Cookie) RedirectResponse(com.runwaysdk.mvc.RedirectResponse) JsonObject(com.google.gson.JsonObject) ClientRequestIF(com.runwaysdk.constants.ClientRequestIF) ProgrammingErrorException(com.runwaysdk.dataaccess.ProgrammingErrorException) WebClientSession(com.runwaysdk.web.WebClientSession) JsonArray(com.google.gson.JsonArray) JSONObject(org.json.JSONObject) SessionController(net.geoprism.SessionController) Endpoint(com.runwaysdk.mvc.Endpoint)

Aggregations

Endpoint (com.runwaysdk.mvc.Endpoint)68 RestBodyResponse (com.runwaysdk.mvc.RestBodyResponse)52 CustomSerializer (org.commongeoregistry.adapter.metadata.CustomSerializer)25 Date (java.util.Date)21 JsonObject (com.google.gson.JsonObject)19 JsonArray (com.google.gson.JsonArray)16 HierarchyType (org.commongeoregistry.adapter.metadata.HierarchyType)11 JSONArray (org.json.JSONArray)11 JSONObject (org.json.JSONObject)11 RestResponse (com.runwaysdk.mvc.RestResponse)8 GeoObject (org.commongeoregistry.adapter.dataaccess.GeoObject)8 SimpleDateFormat (java.text.SimpleDateFormat)6 InputStreamResponse (com.runwaysdk.mvc.InputStreamResponse)5 InputStream (java.io.InputStream)5 RegistryRole (org.commongeoregistry.adapter.metadata.RegistryRole)5 GeoObjectOverTime (org.commongeoregistry.adapter.dataaccess.GeoObjectOverTime)4 OrganizationDTO (org.commongeoregistry.adapter.metadata.OrganizationDTO)4 Locale (java.util.Locale)3 ImportStrategy (net.geoprism.registry.etl.upload.ImportConfiguration.ImportStrategy)3 ParentTreeNode (org.commongeoregistry.adapter.dataaccess.ParentTreeNode)3