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