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.imaginea.betterdocs.BetterDocsAction.java

License:Apache License

private static Map<String, String> getFileTokens(String esResultJson) {
    Map<String, String> fileTokenMap = new HashMap<String, String>();
    JsonReader reader = new JsonReader(new StringReader(esResultJson));
    reader.setLenient(true);//from w ww .j a  va2  s . c o m
    JsonElement jsonElement = new JsonParser().parse(reader);
    JsonObject jsonObject = jsonElement.getAsJsonObject();
    JsonObject hitsObject = jsonObject.getAsJsonObject(HITS);
    JsonArray hitsArray = hitsObject.getAsJsonArray(HITS);

    for (JsonElement hits : hitsArray) {
        JsonObject hitObject = hits.getAsJsonObject();
        JsonObject sourceObject = hitObject.getAsJsonObject(SOURCE);
        String fileName = sourceObject.getAsJsonPrimitive(FILE).getAsString();
        String tokens = sourceObject.get(TOKENS).toString();
        fileTokenMap.put(fileName, tokens);
    }
    return fileTokenMap;
}

From source file:com.imaginea.kodebeagle.base.util.ESUtils.java

License:Apache License

private JsonArray getJsonHitsArray(final JsonObject hitsObject) {
    return hitsObject.getAsJsonArray(HITS);
}

From source file:com.imaginea.kodebeagle.base.util.JSONUtils.java

License:Apache License

public final List<Integer> getLineNumbers(final Collection<String> imports, final String tokens) {
    List<Integer> lineNumbers = new ArrayList<Integer>();
    JsonReader reader = new JsonReader(new StringReader(tokens));
    reader.setLenient(true);//from  w ww  .ja v a2s .co m
    JsonArray tokensArray = new JsonParser().parse(reader).getAsJsonArray();
    for (JsonElement token : tokensArray) {
        JsonObject jObject = token.getAsJsonObject();
        String importName = jObject.getAsJsonPrimitive(IMPORT_EXACT_NAME).getAsString();
        if (imports.contains(importName)) {
            JsonArray lineNumbersArray = jObject.getAsJsonArray(LINE_NUMBERS);
            for (JsonElement lineNumberInfo : lineNumbersArray) {
                lineNumbers.add(lineNumberInfo.getAsJsonObject().getAsJsonPrimitive(LINE_NUMBER).getAsInt());
            }
        }
    }
    return lineNumbers;
}

From source file:com.imaginea.kodebeagle.base.util.SearchUtils.java

License:Apache License

public final Map<String, String> getFileTokens(final String kbResultJson) {
    Map<String, String> fileTokenMap = new HashMap<String, String>();
    final JsonObject hitsObject = getJsonElements(kbResultJson);
    if (hitsObject != null) {
        JsonArray hitsArray = getJsonHitsArray(hitsObject);
        resultCount = hitsArray.size();//from  w  w  w  .  j a v  a2 s. c  o  m
        totalHitsCount = getTotalHits(hitsObject);
        for (JsonElement hits : hitsArray) {
            JsonObject hitObject = hits.getAsJsonObject();
            String fileName = hitObject.getAsJsonPrimitive(FILE_NAME).getAsString();
            String types = hitObject.getAsJsonArray(TYPES).toString();
            fileTokenMap.put(fileName, types);
        }
    }
    return fileTokenMap;
}

From source file:com.imaginea.kodebeagle.base.util.SearchUtils.java

License:Apache License

public final List<Integer> getLineNumbers(final Collection<String> imports, final String tokens) {

    List<Integer> lineNumbers = new ArrayList<Integer>();
    JsonReader reader = new JsonReader(new StringReader(tokens));
    reader.setLenient(true);/*from www  .  java2 s. c  o m*/
    JsonArray tokensArray = new JsonParser().parse(reader).getAsJsonArray();
    for (JsonElement token : tokensArray) {
        JsonObject jObject = token.getAsJsonObject();
        String typeName = jObject.getAsJsonPrimitive(TYPE_EXACT_NAME).getAsString();
        if (imports.contains(typeName)) {

            JsonArray propsArray = jObject.getAsJsonArray(PROPS);
            for (JsonElement propsInfo : propsArray) {

                JsonArray lineNumbersArray = propsInfo.getAsJsonObject().getAsJsonArray(LINES);
                for (JsonElement lineNumber : lineNumbersArray) {

                    lineNumbers.add(lineNumber.getAsJsonArray().get(0).getAsInt());

                }

            }
        }
    }
    return lineNumbers;
}

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

private RecruitHireApplyModel convertJsonToModel(String jsonData) throws Exception {

    RecruitHireApplyModel model = null;/*from  ww  w. j  a v  a2  s .c o m*/
    Gson gson = JsonUtil.getHibernateEntityGsonBuilder().create();

    JsonParser parser = new JsonParser();
    JsonObject jsonObject = (JsonObject) parser.parse(jsonData);
    RecruitHireApply recruitHireApply = gson.fromJson(jsonObject, RecruitHireApply.class);
    model = convertModelFromEntity(recruitHireApply);

    JsonArray arrayDetailRecruitmentRequest = jsonObject.getAsJsonArray("listDetailRecruitHireApply");
    List<OrgTypeOfSpecList> listTypeOfSpec = new ArrayList<>();

    if (null != arrayDetailRecruitmentRequest) {
        for (int i = 0; i < arrayDetailRecruitmentRequest.size(); i++) {
            RecruitHireApplyDetail detail = gson.fromJson(arrayDetailRecruitmentRequest.get(i),
                    RecruitHireApplyDetail.class);
            listTypeOfSpec.add(detail.getOrgTypeOfSpecList());
        }
    }

    //Group list by OrgTypeOfSpec.name
    Group<OrgTypeOfSpecList> groupOrgTypeOfSpecList = Lambda.group(listTypeOfSpec,
            Lambda.by(Lambda.on(OrgTypeOfSpecList.class).getOrgTypeOfSpec().getId()));

    //iterate each group list element
    for (String key : groupOrgTypeOfSpecList.keySet()) {

        List<OrgTypeOfSpecList> listGroupedOrgTypeOfSpecList = groupOrgTypeOfSpecList.find(key);
        OrgTypeOfSpec orgTypeOfSpec = orgTypeOfSpecService.getEntiyByPK(Long.parseLong(key));
        int index = name.indexOf(orgTypeOfSpec.getName());

        if (index != -1) {
            mapTypeList.put(orgTypeOfSpec.getName(), listGroupedOrgTypeOfSpecList);
        }
    }

    return model;
}

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

private RecruitHireApplyModel convertJsonToModel(String jsonData) throws Exception {

    RecruitHireApplyModel model = null;//from   w ww. j  a  va2  s .  co  m
    Gson gson = JsonUtil.getHibernateEntityGsonBuilder().create();

    JsonParser parser = new JsonParser();
    JsonObject jsonObject = (JsonObject) parser.parse(jsonData);
    RecruitHireApply recruitHireApply = gson.fromJson(jsonObject, RecruitHireApply.class);
    model = getModelFromEntity(recruitHireApply);

    JsonArray arrayDetailRecruitmentRequest = jsonObject.getAsJsonArray("listDetailRecruitHireApply");
    List<OrgTypeOfSpecList> listTypeOfSpec = new ArrayList<>();

    if (null != arrayDetailRecruitmentRequest) {
        for (int i = 0; i < arrayDetailRecruitmentRequest.size(); i++) {
            RecruitHireApplyDetail detail = gson.fromJson(arrayDetailRecruitmentRequest.get(i),
                    RecruitHireApplyDetail.class);
            listTypeOfSpec.add(detail.getOrgTypeOfSpecList());
        }
    }

    //Group list by OrgTypeOfSpec.name
    Group<OrgTypeOfSpecList> groupOrgTypeOfSpecList = Lambda.group(listTypeOfSpec,
            Lambda.by(Lambda.on(OrgTypeOfSpecList.class).getOrgTypeOfSpec().getId()));

    //iterate each group list element
    for (String key : groupOrgTypeOfSpecList.keySet()) {

        List<OrgTypeOfSpecList> listGroupedOrgTypeOfSpecList = groupOrgTypeOfSpecList.find(key);
        OrgTypeOfSpec orgTypeOfSpec = orgTypeOfSpecService.getEntiyByPK(Long.parseLong(key));
        int index = name.indexOf(orgTypeOfSpec.getName());

        if (index != -1) {

            List<OrgTypeOfSpecList> listSource = dataForRenders.get(index).getSource();
            List<OrgTypeOfSpecList> listSourceToRemove = Lambda.select(listSource,
                    Lambda.having(Lambda.on(OrgTypeOfSpecList.class).getCode(),
                            Matchers.isIn(Lambda.extract(listGroupedOrgTypeOfSpecList,
                                    Lambda.on(OrgTypeOfSpecList.class).getCode()))));
            listSource.removeAll(listSourceToRemove);

            dataForRenders.get(index).setTarget(listGroupedOrgTypeOfSpecList);
            dataForRenders.get(index).setSource(listSource);
        }
    }

    List<RecruitMppApplyDetail> listMppDetail = recruitMppApplyDetailService
            .getListInSelectedMppPeriodIdWithApprovalStatus(model.getRecruitMppPeriodId(),
                    HRMConstant.APPROVAL_STATUS_APPROVED);
    for (RecruitMppApplyDetail detail : listMppDetail) {
        mapJabatan.put(detail.getJabatan().getName(), detail.getJabatan().getId());
    }

    return model;
}

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

private RecruitHireApplyModel convertJsonToModel(String jsonData) throws Exception {

    RecruitHireApplyModel model = null;//w  w w. ja va2 s.  c  o  m
    Gson gson = JsonUtil.getHibernateEntityGsonBuilder().create();

    JsonParser parser = new JsonParser();
    JsonObject jsonObject = (JsonObject) parser.parse(jsonData);
    RecruitHireApply recruitHireApply = gson.fromJson(jsonObject, RecruitHireApply.class);
    model = getModelFromEntity(recruitHireApply);

    JsonArray arrayDetailRecruitmentRequest = jsonObject.getAsJsonArray("listDetailRecruitHireApply");
    List<OrgTypeOfSpecList> listTypeOfSpec = new ArrayList<>();

    if (null != arrayDetailRecruitmentRequest) {
        for (int i = 0; i < arrayDetailRecruitmentRequest.size(); i++) {
            RecruitHireApplyDetail detail = gson.fromJson(arrayDetailRecruitmentRequest.get(i),
                    RecruitHireApplyDetail.class);
            listTypeOfSpec.add(detail.getOrgTypeOfSpecList());
        }
    }

    //Group list by OrgTypeOfSpec.name
    Group<OrgTypeOfSpecList> groupOrgTypeOfSpecList = Lambda.group(listTypeOfSpec,
            Lambda.by(Lambda.on(OrgTypeOfSpecList.class).getOrgTypeOfSpec().getId()));

    //iterate each group list element
    for (String key : groupOrgTypeOfSpecList.keySet()) {

        List<OrgTypeOfSpecList> listGroupedOrgTypeOfSpecList = groupOrgTypeOfSpecList.find(key);
        OrgTypeOfSpec orgTypeOfSpec = orgTypeOfSpecService.getEntiyByPK(Long.parseLong(key));
        int index = name.indexOf(orgTypeOfSpec.getName());

        if (index != -1) {

            mapTypeList.put(orgTypeOfSpec.getName(), listGroupedOrgTypeOfSpecList);
            List<OrgTypeOfSpecList> listSource = dataForRenders.get(index).getSource();
            List<OrgTypeOfSpecList> listSourceToRemove = Lambda.select(listSource,
                    Lambda.having(Lambda.on(OrgTypeOfSpecList.class).getCode(),
                            Matchers.isIn(Lambda.extract(listGroupedOrgTypeOfSpecList,
                                    Lambda.on(OrgTypeOfSpecList.class).getCode()))));
            listSource.removeAll(listSourceToRemove);

            dataForRenders.get(index).setTarget(listGroupedOrgTypeOfSpecList);
            dataForRenders.get(index).setSource(listSource);
        }
    }

    return model;
}

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

private RecruitMppApplyModel convertJsonToModel(String jsonData) throws Exception {

    RecruitMppApplyModel model = null;//from   w w  w  . j  a va  2  s .c  om
    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 arrayDetailRecruitMppApplyRequest = jsonObject.getAsJsonArray("listMppDetail");
    List<RecruitMppApplyDetail> listMppApplyDetail = new ArrayList<>();

    if (null != arrayDetailRecruitMppApplyRequest) {
        for (int i = 0; i < arrayDetailRecruitMppApplyRequest.size(); i++) {
            RecruitMppApplyDetail detail = gson.fromJson(arrayDetailRecruitMppApplyRequest.get(i),
                    RecruitMppApplyDetail.class);
            listMppApplyDetail.add(detail);
        }
    }

    model.setListMppDetail(listMppApplyDetail);
    return model;
}

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

private RecruitMppApplyModel convertJsonToModel(String jsonData) throws Exception {

    Gson gson = JsonUtil.getHibernateEntityGsonBuilder().create();

    JsonParser parser = new JsonParser();
    JsonObject jsonObject = (JsonObject) parser.parse(jsonData);
    RecruitMppApply recruitMppApply = gson.fromJson(jsonObject, RecruitMppApply.class);
    RecruitMppApplyModel model = convertEntityToModel(recruitMppApply);
    model.setApprovalStatus(selectedApprovalActivity.getApprovalStatus());

    if (StringUtils.isNotEmpty(recruitMppApply.getAttachmentDocPath())) {
        mppApplyFile = recruitMppApplyService.convertFileToUploadedFile(recruitMppApply.getAttachmentDocPath());
        model.setRecruitMppApplyFileName(mppApplyFile.getFileName());
    }//  w  ww.j a  v a2s.c  o  m

    JsonArray arrayDetailMpp = jsonObject.getAsJsonArray("listMppDetail");
    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;
}