Search in sources :

Example 21 with RestBodyResponse

use of com.runwaysdk.mvc.RestBodyResponse 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 22 with RestBodyResponse

use of com.runwaysdk.mvc.RestBodyResponse 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 23 with RestBodyResponse

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

the class ShapefileController method getShapefileConfiguration.

@Endpoint(url = "get-shapefile-configuration", method = ServletMethod.POST, error = ErrorSerialization.JSON)
public ResponseIF getShapefileConfiguration(ClientRequestIF request, @RequestParamter(name = "type", required = true) String type, @RequestParamter(name = "startDate") String startDate, @RequestParamter(name = "endDate") String endDate, @RequestParamter(name = "file", required = true) MultipartFileParameter file, @RequestParamter(name = "strategy", required = true) String sStrategy, @RequestParamter(name = "copyBlank", required = true) Boolean copyBlank) throws IOException, JSONException, ParseException {
    try (InputStream stream = file.getInputStream()) {
        String fileName = file.getFilename();
        SimpleDateFormat format = new SimpleDateFormat(GeoObjectImportConfiguration.DATE_FORMAT);
        format.setTimeZone(GeoRegistryUtil.SYSTEM_TIMEZONE);
        Date sDate = startDate != null ? format.parse(startDate) : null;
        Date eDate = endDate != null ? format.parse(endDate) : null;
        ImportStrategy strategy = ImportStrategy.valueOf(sStrategy);
        JSONObject configuration = service.getShapefileConfiguration(request.getSessionId(), type, sDate, eDate, fileName, stream, strategy, copyBlank);
        return new RestBodyResponse(configuration);
    }
}
Also used : ImportStrategy(net.geoprism.registry.etl.upload.ImportConfiguration.ImportStrategy) JSONObject(org.json.JSONObject) InputStream(java.io.InputStream) SimpleDateFormat(java.text.SimpleDateFormat) RestBodyResponse(com.runwaysdk.mvc.RestBodyResponse) Date(java.util.Date) Endpoint(com.runwaysdk.mvc.Endpoint)

Example 24 with RestBodyResponse

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

the class TermController method createClassifierSynonym.

@Endpoint(method = ServletMethod.POST, error = ErrorSerialization.JSON)
public ResponseIF createClassifierSynonym(ClientRequestIF request, @RequestParamter(name = "classifierId", required = true) String classifierId, @RequestParamter(name = "label", required = true) String label) throws JSONException {
    String response = DataUploaderDTO.createClassifierSynonym(request, classifierId, label);
    JSONObject object = new JSONObject(response);
    return new RestBodyResponse(object);
}
Also used : JSONObject(org.json.JSONObject) RestBodyResponse(com.runwaysdk.mvc.RestBodyResponse) Endpoint(com.runwaysdk.mvc.Endpoint)

Example 25 with RestBodyResponse

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

the class UndirectedGraphController method addChild.

@Endpoint(url = "add-target", method = ServletMethod.POST, error = ErrorSerialization.JSON)
public ResponseIF addChild(ClientRequestIF request, @RequestParamter(name = "sourceCode", required = true) String sourceCode, @RequestParamter(name = "sourceTypeCode", required = true) String sourceTypeCode, @RequestParamter(name = "targetCode", required = true) String targetCode, @RequestParamter(name = "targetTypeCode", required = true) String targetTypeCode, @RequestParamter(name = "undirectedRelationshipCode", required = true) String undirectedRelationshipCode, @RequestParamter(name = "startDate", required = true) String startDateStr, @RequestParamter(name = "endDate", required = true) String endDateStr) {
    Date startDate = GeoRegistryUtil.parseDate(startDateStr, true);
    Date endDate = GeoRegistryUtil.parseDate(endDateStr, true);
    JsonObject response = this.service.addChild(request.getSessionId(), sourceCode, sourceTypeCode, targetCode, targetTypeCode, undirectedRelationshipCode, startDate, endDate);
    return new RestBodyResponse(response);
}
Also used : JsonObject(com.google.gson.JsonObject) RestBodyResponse(com.runwaysdk.mvc.RestBodyResponse) Date(java.util.Date) Endpoint(com.runwaysdk.mvc.Endpoint)

Aggregations

RestBodyResponse (com.runwaysdk.mvc.RestBodyResponse)53 Endpoint (com.runwaysdk.mvc.Endpoint)52 CustomSerializer (org.commongeoregistry.adapter.metadata.CustomSerializer)25 Date (java.util.Date)16 JsonObject (com.google.gson.JsonObject)14 HierarchyType (org.commongeoregistry.adapter.metadata.HierarchyType)11 JsonArray (com.google.gson.JsonArray)10 GeoObject (org.commongeoregistry.adapter.dataaccess.GeoObject)8 JSONArray (org.json.JSONArray)7 JSONObject (org.json.JSONObject)7 SimpleDateFormat (java.text.SimpleDateFormat)5 InputStream (java.io.InputStream)4 GeoObjectOverTime (org.commongeoregistry.adapter.dataaccess.GeoObjectOverTime)4 OrganizationDTO (org.commongeoregistry.adapter.metadata.OrganizationDTO)4 ImportStrategy (net.geoprism.registry.etl.upload.ImportConfiguration.ImportStrategy)3 ParentTreeNode (org.commongeoregistry.adapter.dataaccess.ParentTreeNode)3 GeoObjectType (org.commongeoregistry.adapter.metadata.GeoObjectType)3 PermissionContext (net.geoprism.registry.permission.PermissionContext)2 TreeNode (org.commongeoregistry.adapter.dataaccess.TreeNode)2 ValueObjectDTO (com.runwaysdk.business.ValueObjectDTO)1