Package org.fluxtream.core.mvc.models

Examples of org.fluxtream.core.mvc.models.StatusModel


    public String deleteGuest(@PathParam("username") String username)
            throws InstantiationException, IllegalAccessException,
                   ClassNotFoundException {
        try {
            guestService.eraseGuestInfo(username);
            StatusModel result = new StatusModel(true, "User " + username
                                                       + " was successfully deleted");
            return gson.toJson(result);
        } catch (Exception e) {
            StatusModel result = new StatusModel(false,
                                                 "Could not delete guest: " + e.getMessage());
            return gson.toJson(result);
        }

    }
View Full Code Here


                array.add(guestJson);
            }
            return array.toString();
        }
        catch (Exception e){
            return gson.toJson(new StatusModel(false,"Failed to list guests: " + e.getMessage()));
        }
    }
View Full Code Here

        try {
            Guest guest = guestService.getGuest(username);
            JSONArray array = getGuestRolesJsonArray(guest);
            return array.toString();
        } catch (Exception e) {
            StatusModel result = new StatusModel(false,
                                                 "Could not get roles: " + e.getMessage());
            return gson.toJson(result);
        }

    }
View Full Code Here

                            "successfully added role "
                            + StringUtils.join(addedRoles, ", "))
                    .accumulate("user_roles:", array);
            return result.toString();
        } catch (Exception e) {
            StatusModel result = new StatusModel(false,
                                                 "Could not grant role: " + e.getMessage());
            return gson.toJson(result);
        }

    }
View Full Code Here

            result.accumulate("result", "OK")
                    .accumulate("message", "successfully removed role " + role)
                    .accumulate("user_roles:", array);
            return result.toString();
        } catch (Exception e) {
            StatusModel result = new StatusModel(false,
                                                 "Could not revoke role: " + e.getMessage());
            return gson.toJson(result);
        }

    }
View Full Code Here

  @Produces({ MediaType.APPLICATION_JSON })
    @Deprecated
  public String loadHistory(@QueryParam("username") String username,
      @QueryParam("connectorName") String connectorName) throws InstantiationException,
      IllegalAccessException, ClassNotFoundException {
        StatusModel status;
        try{
            Guest guest = guestService.getGuest(username);

            if (!checkForPermissionAccess(guest.getId())){
                status = new StatusModel(false, "Failure!");
            }
            else {
                final ApiKey apiKey = guestService.getApiKey(guest.getId(), Connector.getConnector(connectorName));
                bodytrackStorageService.storeInitialHistory(apiKey);
                status = new StatusModel(true, "Success!");
            }
        }
        catch (Exception e){
            status = new StatusModel(false,"Failure!");
        }
        return gson.toJson(status);
    }
View Full Code Here

    @ApiOperation(value = "Delete a view", response = String.class)
    @Produces({ MediaType.APPLICATION_JSON })
    @Deprecated
    public String deleteBodytrackView(@ApiParam(value="User ID (must be ID of loggedIn user)", required=true) @PathParam("UID") Long uid,
                                      @ApiParam(value="View ID", required=true) @PathParam("id") long viewId){
        StatusModel status;
        try{
            if (!checkForPermissionAccess(uid)){
                uid = null;
            }
            bodyTrackHelper.deleteView(uid, viewId);
            status = new StatusModel(true,"successfully deleted view " + viewId);
        }
        catch (Exception e){
            status = new StatusModel(false,"failed to delete view " + viewId);
        }
        return gson.toJson(status);
    }
View Full Code Here

    @ApiOperation(value = "Upload binary data via multipart encoding for the current logged in user", response = String.class)
    @Deprecated
    public String uploadToBodytrack(@ApiParam(value="The device to upload the data for", required=true) @FormParam("dev_nickname") String deviceNickname,
                                    @ApiParam(value="JSON encoded array of channels being uploaded for", required=true) @FormParam("channel_names") String channels,
                                    @ApiParam(value="Multipart form data to be uploaded", required=true@FormParam("data") String data){
        StatusModel status;
        try{
            long guestId = AuthHelper.getGuestId();
            Type channelsType =  new TypeToken<Collection<String>>(){}.getType();

            List<List<Object>> parsedData = new ArrayList<List<Object>>();

            //Gson doesn't seem to be able to handle arrays with mixed types nicely
            //This will parse through the array, we don't need much error checking because we want this to fail if the data is malformed
            JsonElement element = new JsonParser().parse(data);

            for (JsonElement e : element.getAsJsonArray()){
                List<Object> currentList = new ArrayList<Object>();
                parsedData.add(currentList);
                for (JsonElement dataPoint : e.getAsJsonArray()){
                    if (dataPoint instanceof JsonNull){
                        currentList.add(null);
                    }
                    else{
                        JsonPrimitive primitive = dataPoint.getAsJsonPrimitive();
                        if (primitive.isBoolean()){
                            currentList.add(primitive.getAsBoolean());
                        }
                        else if (primitive.isString()){
                            currentList.add(primitive.getAsString());
                        }
                        else{
                            currentList.add(primitive.getAsDouble());
                        }
                    }
                }
            }

            final BodyTrackHelper.BodyTrackUploadResult uploadResult = bodyTrackHelper.uploadToBodyTrack(guestId, deviceNickname, (Collection<String>)gson.fromJson(channels, channelsType), parsedData);
            if (uploadResult instanceof BodyTrackHelper.ParsedBodyTrackUploadResult){
                BodyTrackHelper.ParsedBodyTrackUploadResult parsedResult = (BodyTrackHelper.ParsedBodyTrackUploadResult) uploadResult;
                List<ApiKey> keys = guestService.getApiKeys(guestId,Connector.getConnector("fluxtream_capture"));
                long apiKeyId = -1;
                if (keys.size() > 0){
                    apiKeyId = keys.get(0).getId();
                }
                dataUpdateService.logBodyTrackDataUpdate(guestId,apiKeyId,null,parsedResult);
            }
            status = createStatusModelFromBodyTrackUploadResult(uploadResult);
        }
        catch (Exception e){
            status = new StatusModel(false,"Upload failed!");
        }
        return gson.toJson(status);
    }
View Full Code Here

    @Produces({MediaType.APPLICATION_JSON})
    @ApiOperation(value = "Upload JSON data for current logged in user", response = String.class)
    @Deprecated
    public String uploadJsonToBodytrack(@ApiParam(value="The device to upload the data for", required=true) @QueryParam("dev_nickname"String deviceNickname,
                                        @ApiParam(value="The data to upload", required=true) String body){
        StatusModel status;
        try{
            long uid = AuthHelper.getGuestId();
            status = createStatusModelFromBodyTrackUploadResult(bodyTrackHelper.uploadJsonToBodyTrack(uid, deviceNickname, body));
        }
        catch (Exception e){
            status = new StatusModel(false,"Upload failed!");
        }
        return gson.toJson(status);
    }
View Full Code Here

    }

    private StatusModel createStatusModelFromBodyTrackUploadResult(final BodyTrackHelper.BodyTrackUploadResult uploadResult) {

        // check the uploadResult for success, and create a new StatusModel accordingly
        final StatusModel status;
        if (uploadResult.isSuccess()) {
            status = new StatusModel(true, "Upload successful!");
        }
        else {
            status = new StatusModel(false, "Upload failed!");
        }

        // Now try to parse the response in the uploadResult as JSON, inflating it into a BodyTrackUploadResponse
        BodyTrackUploadResponse bodyTrackUploadResponse = null;
        try {
View Full Code Here

TOP

Related Classes of org.fluxtream.core.mvc.models.StatusModel

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.