Example usage for com.google.gson JsonObject getAsJsonArray

List of usage examples for com.google.gson JsonObject getAsJsonArray

Introduction

In this page you can find the example usage for com.google.gson JsonObject getAsJsonArray.

Prototype

public JsonArray getAsJsonArray(String memberName) 

Source Link

Document

Convenience method to get the specified member as a JsonArray.

Usage

From source file:com.inkubator.hrm.web.recruitment.RecruitMppApplyFormController.java

private RecruitMppApplyModel convertJsonToModel(String jsonData) throws Exception {
    RecruitMppApplyModel model = null;/*from  w w w  .  j  a  v  a2 s .c  o m*/
    Gson gson = JsonUtil.getHibernateEntityGsonBuilder().create();

    JsonParser parser = new JsonParser();
    JsonObject jsonObject = (JsonObject) parser.parse(jsonData);
    RecruitMppApply recruitMppApply = gson.fromJson(jsonObject, RecruitMppApply.class);
    model = convertEntityToModel(recruitMppApply);
    JsonArray arrayDetailMpp = jsonObject.getAsJsonArray("listMppDetail");

    if (StringUtils.isNotEmpty(recruitMppApply.getAttachmentDocPath())) {
        mppApplyFile = recruitMppApplyService.convertFileToUploadedFile(recruitMppApply.getAttachmentDocPath());
        model.setRecruitMppApplyFileName(mppApplyFile.getFileName());
    }

    for (int i = 0; i < arrayDetailMpp.size(); i++) {
        RecruitMppApplyDetail detail = gson.fromJson(arrayDetailMpp.get(i), RecruitMppApplyDetail.class);

        Integer actual = empDataService
                .getTotalKaryawanByJabatanId(HrmUserInfoUtil.getCompanyId(), detail.getJabatan().getId())
                .intValue();
        Integer difference = detail.getRecruitPlan() == actual ? 0
                : detail.getRecruitPlan() > actual ? (detail.getRecruitPlan() - actual)
                        : (actual - detail.getRecruitPlan());
        detail.setActualNumber(actual);
        detail.setDifference(difference);
        listMppDetail.add(detail);
    }
    return model;
}

From source file:com.inmind.restful.testcases.Org.java

@Test
public void GetOrgsDeptsList() {
    try {/*  w  w w .  j a v  a  2s .c o  m*/
        LOGGER.info("*****************Test case: Get Orgs Depts List Started*****************");
        String uri = APITest.getValue("baseuri");
        String cookievalue = cookies.get(0);
        APIResponse response = APIRequest.GET(uri).path("/orgs/depts/list")
                .type(MediaType.APPLICATION_JSON_TYPE).header("cookie", cookievalue)
                .param("orgId", String.valueOf(orgid)).param("text", "Test for automation").invoke();
        response.assertBodyContains("200");
        String responsbody = response.getBody();
        JsonObject jsonObject = new JsonParser().parse(responsbody).getAsJsonObject();
        JsonArray body = jsonObject.getAsJsonArray("_body");
        ResultSet resultSet = dbCtrl.query(conn,
                "SELECT * FROM org_dept WHERE org_id=" + orgid + " AND name = \"Test for Automation\";");
        for (int i = 0; i < body.size(); i++) {
            resultSet.next();
            JsonObject object = body.get(i).getAsJsonObject();
            commonutil.AssertEqualsCustomize(object.get("createdBy").getAsLong(),
                    resultSet.getLong("created_by"));
            commonutil.AssertEqualsCustomize(object.get("updatedBy").getAsLong(),
                    resultSet.getLong("updated_by"));
            commonutil.AssertEqualsCustomize(object.get("id").getAsLong(), resultSet.getLong("id"));
            commonutil.AssertEqualsCustomize(object.get("orgId").getAsLong(), resultSet.getLong("org_id"));
            commonutil.AssertEqualsCustomize(object.get("telNo").getAsString(), resultSet.getString("tel_no"));
            commonutil.AssertEqualsCustomize(object.get("name").getAsString(), resultSet.getString("name"));
            //commonutil.AssertEqualsCustomize(object.get("createdAt").getAsString(), resultSet.getString("created_at"));
            //commonutil.AssertEqualsCustomize(object.get("updatedAt").getAsString(), resultSet.getString("updated_at"));
        }
    } catch (SQLException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } finally {
        LOGGER.info("*****************Test case: Get Orgs Depts List Ended*****************");
    }
}

From source file:com.inmind.restful.testcases.Org.java

@Test
public void PostOrgsExternaljobs() {
    try {//from  www  .  jav a2 s. c o  m
        LOGGER.info("*****************Test case: Post Orgs External Jobs Started*****************");
        String uri = APITest.getValue("baseuri");
        String cookievalue = cookies.get(0);
        //String payload= String.format(APITest.loadFile("Post_Orgs_External_Jobs.json"));
        String payload = "{\n" + "  \"orgId\": " + orgid + ",\n" + "  \"salaryLower\": 15000,\n"
                + "  \"salaryUpper\": 25000,\n"
                + "  \"sourceUrl\": \"http://www.lagou.com/jobs/2611255.html?utm_source=m_cf_seo_ald_zhw\",\n"
                + "  \"source\": \"Test for Automation\",\n" + "  \"title\": [\"Test Automation\"]\n" + "}";
        APIResponse response = APIRequest.POST(uri).path("/orgs/external_jobs/")
                .type(MediaType.APPLICATION_JSON_TYPE).header("cookie", cookievalue).body(payload).invoke();
        response.assertBodyContains("200");
        ResultSet resultSet = dbCtrl.query(conn,
                "SELECT * From external_job WHERE org_id=" + orgid + " AND title=\"Test for Automation\"");
        String responsbody = response.getBody();
        JsonObject jsonObject = new JsonParser().parse(responsbody).getAsJsonObject();
        JsonArray body = jsonObject.getAsJsonArray("_body");
        for (int i = 0; i < body.size(); i++) {
            resultSet.next();
            JsonObject subObject = body.get(i).getAsJsonObject();
            commonutil.AssertEqualsCustomize(subObject.get("source").getAsString(),
                    resultSet.getString("source"));
            commonutil.AssertEqualsCustomize(subObject.get("title").getAsString(),
                    resultSet.getString("title"));
            commonutil.AssertEqualsCustomize(subObject.get("id").getAsLong(), resultSet.getLong("id"));
            commonutil.AssertEqualsCustomize(subObject.get("sourceUrl").getAsString(),
                    resultSet.getString("source_url"));
            commonutil.AssertEqualsCustomize(subObject.get("salaryLower").getAsBigDecimal(),
                    resultSet.getBigDecimal("salary_lower"));
            commonutil.AssertEqualsCustomize(subObject.get("salaryUpper").getAsBigDecimal(),
                    resultSet.getBigDecimal("salary_Upper"));
        }
    } catch (SQLException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    finally {
        LOGGER.info("*****************Test case: Post Orgs External Jobs Ended*****************");
    }
}

From source file:com.intuit.wasabi.tests.service.statistic.StatisticsUtils.java

License:Apache License

static void COMPUTE_EVENT_COUNT_PER_LABEL(String bucketLabel, JsonObject events,
        Map<String, Map<String, Integer>> bucketLabelToEventCount) {
    Map<String, Integer> event = bucketLabelToEventCount.getOrDefault(bucketLabel, new HashMap<>());
    bucketLabelToEventCount.put(bucketLabel, event);
    for (JsonElement element : events.getAsJsonArray("events")) {
        String name = element.getAsJsonObject().get("name").getAsString().toLowerCase();
        Integer value = event.getOrDefault(name, 0);
        event.put(name, value + 1);//from   w w w  .  jav  a  2 s  .c o m
    }
}

From source file:com.intuit.wasabi.tests.service.statistic.StatisticsUtils.java

License:Apache License

/**
 * @param jsonObject/*from www . java2  s  .c  o m*/
 */
static void COMPUTE_DAILY_COUNT(JsonObject jsonObject) {
    for (JsonElement element : jsonObject.getAsJsonArray("days")) {
        element.getAsJsonObject().remove("cumulative");
        element.getAsJsonObject().remove("jointProgress");
        element.getAsJsonObject().remove("actionProgress");
        element.getAsJsonObject().remove("experimentProgress");
        element.getAsJsonObject().remove("jointActionRate");
        element.getAsJsonObject().remove("actionRates");
        JsonObject experimentStatistics = element.getAsJsonObject().getAsJsonObject("perDay");
        experimentStatistics.remove("jointActionRate");
        experimentStatistics.remove("actionRates");
        JsonObject buckets = experimentStatistics.getAsJsonObject("buckets");
        for (String label : new String[] { "red", "blue" }) {
            JsonObject bucket = buckets.getAsJsonObject(label);
            bucket.remove("actionRates");
            bucket.remove("jointActionRate");
        }
    }
}

From source file:com.intuit.wasabi.tests.service.statistic.StatisticsUtils.java

License:Apache License

static Map<String, List<EventDateTime>> EVENT_DATETIME() {
    Map<String, List<EventDateTime>> result = new HashMap<>();

    for (Object[] values : SharedExperimentDataProvider.validEvents()) {
        String bucket = (String) values[0];
        List<EventDateTime> eventAndDatetimes = result.getOrDefault(bucket, new ArrayList<>());
        result.put(bucket, eventAndDatetimes);
        JsonObject eventJsonObject = new JsonParser().parse((String) values[1]).getAsJsonObject();
        for (JsonElement element : eventJsonObject.getAsJsonArray("events")) {
            String name = element.getAsJsonObject().get("name").getAsString().toLowerCase();
            LocalDateTime value = LocalDateTime.parse(element.getAsJsonObject().get("timestamp").getAsString(),
                    SharedExperimentDataProvider.formatter);
            eventAndDatetimes.add(new EventDateTime(name, value));
        }/* w w w  .  ja v  a2  s  . com*/
    }
    return result;
}

From source file:com.ixvil.android.BoxBonus.Fragments.ShopsListFragment.java

License:Apache License

public void getAllShops(final LayoutInflater inflater, final ViewGroup container, Bundle savedInstanceState) {

    final RecyclerView recyclerView = (RecyclerView) inflater.inflate(R.layout.recycler_view, container, false);

    try {/*  ww  w .j  a  v  a2 s .  c  o m*/
        Ion.with(recyclerView.getContext())
                .load(inflater.getContext().getResources().getString(R.string.hostname) + "/json/getpartners")
                .asJsonObject().setCallback(new FutureCallback<JsonObject>() {
                    @Override
                    public void onCompleted(Exception e, JsonObject result) {
                        if (e == null) {
                            JsonArray partnersJson = result.getAsJsonArray("data");
                            if (partnersJson != null) {
                                try {
                                    onFetchSuccess(partnersJson);
                                } catch (IOException e1) {
                                    e1.printStackTrace();
                                }
                            } else {
                                onFetchFailed(result.get("message").getAsString(), recyclerView.getContext());
                            }
                        } else {
                            onFetchFailed(e.getMessage().toString(), recyclerView.getContext());
                        }
                    }
                });
    } catch (Exception e) {
        onFetchFailed(e.getMessage().toString(), recyclerView.getContext());
    }

}

From source file:com.jaspervanriet.huntingthatproduct.Activities.CollectionActivity.java

License:Open Source License

private void getProducts() {
    Ion.with(this).load(Constants.API_URL + "collections/" + mCollection.id)
            .setHeader("Authorization", "Bearer " + Constants.CLIENT_TOKEN).asJsonObject()
            .setCallback(new FutureCallback<JsonObject>() {
                @Override/*  w  ww.  j  ava  2  s.  c  o  m*/
                public void onCompleted(Exception e, JsonObject result) {
                    if (e != null && e instanceof TimeoutException) {
                        Toast.makeText(CollectionActivity.this,
                                getResources().getString(R.string.error_connection), Toast.LENGTH_SHORT).show();
                        return;
                    }
                    if (result != null && result.has("collection")) {
                        int i;
                        result = result.getAsJsonObject("collection");
                        JsonArray products = result.getAsJsonArray("posts");
                        for (i = 0; i < products.size(); i++) {
                            JsonObject obj = products.get(i).getAsJsonObject();
                            Product product = new Product(obj);
                            mProducts.add(product);
                        }
                        mListAdapter.notifyDataSetChanged();
                        mProgressWheel.stopSpinning();
                        mProgressWheel.setVisibility(View.INVISIBLE);
                        checkEmpty();
                    }
                }
            });
}

From source file:com.jaspervanriet.huntingthatproduct.Activities.CommentsActivity.java

License:Open Source License

private void getComments() {
    Ion.with(this).load(Constants.API_URL + "posts/" + mProductId)
            .setHeader("Authorization", "Bearer " + Constants.CLIENT_TOKEN).asJsonObject()
            .setCallback(new FutureCallback<JsonObject>() {
                @Override/*  w  ww . j  a va2 s  . c o  m*/
                public void onCompleted(Exception e, JsonObject result) {
                    if (result == null || !result.has("post") || e != null) {
                        return;
                    }
                    result = result.get("post").getAsJsonObject();
                    if (result.has("comments")) {
                        int i;
                        JsonArray comments = result.getAsJsonArray("comments");
                        for (i = 0; i < comments.size(); i++) {
                            JsonObject object = comments.get(i).getAsJsonObject();
                            processComment(object, 0);
                        }
                        mCommentListAdapter.notifyDataSetChanged();
                        mListProgressWheel.setVisibility(View.GONE);
                        mListProgressWheel.stopSpinning();
                        checkEmpty();
                    }
                }
            });
}

From source file:com.jaspervanriet.huntingthatproduct.Activities.CommentsActivity.java

License:Open Source License

private void processComment(JsonObject object, int level) {
    Comment comment = new Comment(object);
    comment.level = level;//from www .  j  a va 2s  .  c  o  m
    mComments.add(comment);
    if (!object.get("child_comments").isJsonNull()) {
        int i;
        level++;
        for (i = 0; i < comment.childCommentCount; i++) {
            processComment(object.getAsJsonArray("child_comments").get(i).getAsJsonObject(), level);
        }
    }
}