Search in sources :

Example 1 with ValueList

use of org.boon.core.value.ValueList in project ddf by codice.

the class FeedbackApplication method parseFeedbackRequest.

private static FeedbackRequest parseFeedbackRequest(String json) {
    FeedbackRequest feedbackRequest = new FeedbackRequest();
    String name = UNKNOWN;
    String email = UNKNOWN;
    String searchStr = UNKNOWN;
    String workspaceId = UNKNOWN;
    String workspaceName = UNKNOWN;
    Date searchInitiated = null;
    ValueList searchStatus = null;
    ValueList searchResults = null;
    Map<String, Object> rootObject = MAPPER.parser().parseMap(json);
    Object userObj = rootObject.get("user");
    if (userObj instanceof Map) {
        Map<String, Object> userObject = (Map<String, Object>) userObj;
        name = (String) userObject.get("name");
        email = (String) userObject.get("email");
    }
    Object searchObj = rootObject.get("search");
    if (searchObj instanceof Map) {
        Map<String, Object> searchObject = (Map<String, Object>) searchObj;
        searchStr = (String) searchObject.get("cql");
        searchInitiated = (Date) searchObject.get("initiated");
        searchStatus = (ValueList) searchObject.get("status");
        Object resultsObj = searchObject.get("results");
        if (resultsObj instanceof ValueList) {
            searchResults = (ValueList) resultsObj;
        }
    }
    Object workspaceObj = rootObject.get("workspace");
    if (workspaceObj instanceof Map) {
        Map<String, Object> workspaceObject = (Map<String, Object>) workspaceObj;
        workspaceId = (String) workspaceObject.get("id");
        workspaceName = (String) workspaceObject.get("name");
    }
    String comments = (String) rootObject.get("comments");
    feedbackRequest.setUsername(name);
    feedbackRequest.setEmail(email);
    feedbackRequest.setQuery(searchStr);
    if (searchInitiated != null) {
        feedbackRequest.setQueryInitiated(searchInitiated.toString());
    }
    if (searchResults != null) {
        String prettyPrintedJson = Boon.toPrettyJson(searchResults);
        feedbackRequest.setQueryResults(prettyPrintedJson);
    }
    if (searchStatus != null) {
        feedbackRequest.setQueryStatus(searchStatus.stream().map(Object::toString).collect(Collectors.joining(", ")));
    }
    feedbackRequest.setWorkspaceId(workspaceId);
    feedbackRequest.setWorkspaceName(workspaceName);
    feedbackRequest.setComments(comments);
    return feedbackRequest;
}
Also used : ValueList(org.boon.core.value.ValueList) FeedbackRequest(org.codice.ddf.catalog.ui.query.feedback.FeedbackRequest) HashMap(java.util.HashMap) Map(java.util.Map) Date(java.util.Date)

Aggregations

Date (java.util.Date)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 ValueList (org.boon.core.value.ValueList)1 FeedbackRequest (org.codice.ddf.catalog.ui.query.feedback.FeedbackRequest)1