Example usage for com.liferay.portal.kernel.json JSONFactoryUtil getJSONFactory

List of usage examples for com.liferay.portal.kernel.json JSONFactoryUtil getJSONFactory

Introduction

In this page you can find the example usage for com.liferay.portal.kernel.json JSONFactoryUtil getJSONFactory.

Prototype

public static JSONFactory getJSONFactory() 

Source Link

Usage

From source file:com.liferay.dynamic.data.mapping.storage.GeolocationFieldRendererTest.java

License:Open Source License

protected void setUpJSONFactoryUtil() {
    spy(JSONFactoryUtil.class);

    when(JSONFactoryUtil.getJSONFactory()).thenReturn(new JSONFactoryImpl());
}

From source file:com.liferay.jira.metrics.portlet.JiraMetricsPortlet.java

License:Open Source License

@Override
public void serveResource(ResourceRequest resourceRequest, ResourceResponse resourceResponse)
        throws IOException, PortletException {

    String jiraProjectKey = ParamUtil.getString(resourceRequest, "jiraProjectKey");

    JiraProject jiraProject = null;//from  w w  w  . ja  v  a  2  s . c om

    try {
        jiraProject = JiraProjectLocalServiceUtil.getJiraProjectByProjectLabel(jiraProjectKey);
    } catch (Exception e) {
        throw new PortletException(e);
    }

    JSONObject jsonFeed = JSONFactoryUtil.createJSONObject();

    JSONArray componentsNameCode = JSONFactoryUtil.getJSONFactory().createJSONArray();

    List<JiraComponent> componentList = null;

    try {
        componentList = JiraComponentLocalServiceUtil
                .getJiraComponentsByJiraProjectId(jiraProject.getJiraProjectId());
    } catch (SystemException e) {
        throw new PortletException(e);
    }

    for (JiraComponent component : componentList) {
        componentsNameCode.put(component.getName() + ":" + component.getName());
    }

    jsonFeed.put("componentsNameCode", componentsNameCode);

    resourceResponse.setContentType("application/json");
    resourceResponse.setCharacterEncoding("UTF-8");

    PrintWriter writer = resourceResponse.getWriter();

    writer.write(jsonFeed.toString());
}

From source file:org.oep.cmon.admin.portlet.action.AdminActionPortlet.java

License:Apache License

/**
 * This is function serveResource/*from  www .j a v  a2  s  .  co m*/
 * Version: 1.0
 *  
 * History: 
 *   DATE        AUTHOR      DESCRIPTION 
 *  ------------------------------------------------- 
 *  3-March-2013  Nam Dinh    Create new
 * @param resourceRequest
 * @param resourceResponse
 * @throws Exception
 * @throws PortletException
 */
public void serveResource(ResourceRequest resourceRequest, ResourceResponse resourceResponse)
        throws IOException, PortletException {
    // Get resource id
    String resourceId = resourceRequest.getResourceID();

    // Process Jason feed
    JSONObject jsonFeed = JSONFactoryUtil.createJSONObject();
    if ("fetchDonViHanhChinh".equals(resourceId)) {
        // Get country code from URL
        long parentId = ParamUtil.getInteger(resourceRequest, "parentId");

        // Create Jason array o bject
        JSONArray donViHanhChinhArray = JSONFactoryUtil.getJSONFactory().createJSONArray();

        // Query all sub don vi hanh chinh using parent id
        List<DonViHanhChinh> donviHanhChinhList = null;

        try {
            donviHanhChinhList = DonViHanhChinhLocalServiceUtil.findByChaId(parentId, Constants.ACTIVATED);
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

        // Store all data to jSon object
        for (DonViHanhChinh donViHanhChinh : donviHanhChinhList) {
            donViHanhChinhArray.put(donViHanhChinh.getId() + ":" + donViHanhChinh.getTen());
        }

        jsonFeed.put("donViHanhChinhArray", donViHanhChinhArray);
    }

    resourceResponse.setContentType("application/json");
    resourceResponse.setCharacterEncoding("UTF-8");
    resourceResponse.getWriter().write(jsonFeed.toString());
}

From source file:org.oep.cmon.admin.portlet.action.AdminActionPortlet.java

License:Apache License

/**
 * This is  function get DonViHanhChinh by Id
 * Version: 1.0//w  ww  .j a  va 2  s  . c  om
 *  
 * History: 
 *   DATE        AUTHOR      DESCRIPTION 
 *  ------------------------------------------------- 
 *  3-March-2013  Nam Dinh    Create new
 * @param resourceRequest
 * @param httpReq
 * @throws Exception
 */
public void getDonViHanhChinhById(ActionRequest resourceRequest, ActionResponse httpReq)
        throws NumberFormatException, Exception {

    String id = ParamUtil.getString(resourceRequest, "id");

    // Process Jason feed
    JSONObject jsonFeed = JSONFactoryUtil.createJSONObject();
    JSONArray _name = JSONFactoryUtil.getJSONFactory().createJSONArray();
    JSONArray _id = JSONFactoryUtil.getJSONFactory().createJSONArray();

    // Danh sach don vi hanh chinh
    List<DonViHanhChinh> dsDVHC = findDonViHanhChinhByChaId(Long.parseLong(id));

    for (DonViHanhChinh item : dsDVHC) {
        _id.put(item.getId());
        _name.put(item.getTen());
    }
    jsonFeed.put("id", _id);
    jsonFeed.put("name", _name);

    HttpServletResponse resourceResponse = PortalUtil.getHttpServletResponse(httpReq);

    resourceResponse.setContentType("application/json");
    resourceResponse.setCharacterEncoding("UTF-8");
    resourceResponse.getWriter().write(jsonFeed.toString());
    resourceResponse.getWriter().close();
}

From source file:org.oep.cmon.admin.portlet.action.CongChucAction.java

License:Apache License

/**
 * This is function search popup VaiTroCanBo remove Ajax
 * Version: 1.0/*from  w w w. j  av  a2  s.  c  o  m*/
 *  
 * History: 
 *   DATE        AUTHOR      DESCRIPTION 
 *  ------------------------------------------------- 
 *  3-March-2013  Nam Dinh    Create new
 * @param actionRequest
 * @param actionResponse
 * @throws Exception
 */
public void searchPopUpVaiTroChoCanBoAjax(ActionRequest actionRequest, ActionResponse actionResponse)
        throws Exception {
    // Get the search option
    List<VaiTro> results = null;
    String chucVuID = ParamUtil.getString(actionRequest, "chucVuID").trim();
    String coQuanQuanLy = ParamUtil.getString(actionRequest, "coQuanQuanLy").trim();
    String vaiTroThem = ParamUtil.getString(actionRequest, "vaiTroThem").trim();
    String keyWord = ParamUtil.getString(actionRequest, "keyWord");

    if (chucVuID.length() > 0) {
        String[] _chucVuID = chucVuID.split("-");
        String[] _vaiTroThem = vaiTroThem.split("-");
        String[] _coQuanQuanLyID = coQuanQuanLy.split("-");
        List<ChucVu2VaiTro> lisChucVu2VaiTros = ChucVu2VaiTroLocalServiceUtil.findByIdChucVuAndIdCoQuanQuanLy(
                ConvertUtil.convertToLong(_chucVuID[0]), ConvertUtil.convertToLong(_coQuanQuanLyID[0]), 0);
        List<Long> listIDs = new ArrayList<Long>();
        String dataPrint = "";
        for (int i = 0; i < lisChucVu2VaiTros.size(); i++) {
            listIDs.add(lisChucVu2VaiTros.get(i).getVaiTroId());
            dataPrint += lisChucVu2VaiTros.get(i).getVaiTroId() + ";";
        }
        for (int i = 0; i < _vaiTroThem.length; i++) {
            if (ConvertUtil.convertToLong(_vaiTroThem[i]) > 0) {
                listIDs.add(ConvertUtil.convertToLong(_vaiTroThem[i]));
                dataPrint += ConvertUtil.convertToLong(_vaiTroThem[i]) + ";";
            }
        }

        // Build the query      
        DynamicQuery query = DynamicQueryFactoryUtil.forClass(VaiTro.class);

        // Always search un-deleted record
        query = query.add(PropertyFactoryUtil.forName("daXoa").eq(0));
        query = query.add(RestrictionsFactoryUtil.not(RestrictionsFactoryUtil.in("id", listIDs.toArray())));

        // Add the criteria incase keyword search is not null
        if (Validator.isNotNull(keyWord)) {
            Criterion criteria = RestrictionsFactoryUtil.ilike("ten", "%" + keyWord + "%");
            // Define search criteria
            query = query.add(criteria);
        }

        try {
            results = VaiTroLocalServiceUtil.dynamicQuery(query);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    if (results == null) {
        results = new ArrayList<VaiTro>();
    }

    JSONObject jsonFeed = JSONFactoryUtil.createJSONObject();
    JSONArray _name = JSONFactoryUtil.getJSONFactory().createJSONArray();
    JSONArray _id = JSONFactoryUtil.getJSONFactory().createJSONArray();

    for (VaiTro item : results) {
        _id.put(item.getId());
        _name.put(item.getTen());
    }
    jsonFeed.put("id", _id);
    jsonFeed.put("name", _name);

    HttpServletResponse resourceResponse = PortalUtil.getHttpServletResponse(actionResponse);

    resourceResponse.setContentType("application/json");
    resourceResponse.setCharacterEncoding("UTF-8");
    resourceResponse.getWriter().write(jsonFeed.toString());
    resourceResponse.getWriter().close();

}

From source file:org.oep.cmon.portlet.admin.congchuc.action.CongChucPortlet.java

License:Apache License

/**
 * This is  function get data ChucVu//from  w ww. j a  v  a 2  s. co  m
 * Version: 1.0
 *  
 * History: 
 *   DATE        AUTHOR      DESCRIPTION 
 *  ------------------------------------------------- 
 *  3-March-2013  Nam Dinh    Create new
 * @param actionRequest
 * @param actionResponse
 * @throws IOException
 * @throws PortletException
 * @throws NumberFormatException
 * @throws SystemException
 */
public void getDataChucVu(ActionRequest actionRequest, ActionResponse actionResponse)
        throws IOException, PortletException, NumberFormatException, SystemException {
    String coQuanQuanLyId = ParamUtil.getString(actionRequest, "coQuanQuanLyId");
    JSONArray rows = JSONFactoryUtil.getJSONFactory().createJSONArray();
    List<ChucVu> listChucVu = new ArrayList<ChucVu>();
    if (!Helpers.isEmpty(coQuanQuanLyId)) {
        listChucVu = ChucVuLocalServiceUtil.findByCoQuanQuanLy(Long.valueOf(coQuanQuanLyId), 0);
    }

    for (ChucVu item : listChucVu) {
        JSONObject obj = JSONFactoryUtil.getJSONFactory().createJSONObject();
        obj.put("id", item.getId());
        obj.put("name", item.getTen());
        rows.put(obj);
    }

    HttpServletResponse resourceResponse = PortalUtil.getHttpServletResponse(actionResponse);
    resourceResponse.setContentType(ContentTypes.APPLICATION_JSON);
    resourceResponse.setCharacterEncoding(StringPool.UTF8);
    resourceResponse.getWriter().write(rows.toString());
    resourceResponse.getWriter().close();
}

From source file:org.oep.cmon.portlet.doanhnghiep.quanlytaikhoan.action.QuanLyTaiKhoanPortlet.java

License:Apache License

/**
 * This is  function get data HoCaThe/* ww w . java2s .  com*/
 * Version: 1.0
 *  
 * History: 
 *   DATE        AUTHOR      DESCRIPTION 
 *  ------------------------------------------------- 
 *  3-March-2013  Nam Dinh    Create new
 * @param actionRequest
 * @param actionResponse
 * @throws Exception
 */
public void getDataHoCaThe(ActionRequest actionRequest, ActionResponse actionResponse) throws Exception {
    long hoCaTheId = ParamUtil.getLong(actionRequest, "hoCaTheId", 0l);
    DateFormat df = new SimpleDateFormat("dd/MM/yyyy");
    DoanhNghiep hoCaThe = DoanhNghiepLocalServiceUtil.fetchDoanhNghiep(hoCaTheId);

    JSONObject obj = JSONFactoryUtil.getJSONFactory().createJSONObject();
    obj.put("id", hoCaThe.getId());
    obj.put("ten", hoCaThe.getTen());
    obj.put("maGiayPhep", hoCaThe.getSoGCNDKKD());

    obj.put("tinhId", hoCaThe.getDiaChiDoanhNghiepTinhId());
    obj.put("huyenId", hoCaThe.getDiaChiDoanhNghiepHuyenId());
    obj.put("xaId", hoCaThe.getDiaChiDoanhNghiepXaId());

    obj.put("chiTietDiaDiem", hoCaThe.getDiaChiDoanhNghiep());
    obj.put("maSoThue", hoCaThe.getMaSoThue());
    obj.put("ngayDangKy", df.format(hoCaThe.getNgayCapGCNDKKD()));
    obj.put("vonKinhDoanh", hoCaThe.getVonDieuLe());
    obj.put("dienThoai", hoCaThe.getDienThoaiDoanhNghiep());
    obj.put("fax", hoCaThe.getFax());
    obj.put("email", hoCaThe.getEmailDoanhNghiep());
    obj.put("website", hoCaThe.getWebsite());
    obj.put("moTaNgheNghiep", hoCaThe.getMoTaNganhNgheKinhDoanh());

    obj.put("nddId", hoCaThe.getNguoiDaiDienId());
    List<NganhNgheKinhDoanh> listNganhNghe = XacThucDoanhNghiepUtils.getNganhNgheByIdDoanhNghiep(hoCaTheId);
    JSONArray lnn = JSONFactoryUtil.getJSONFactory().createJSONArray();
    for (int i = 0; i < listNganhNghe.size(); i++) {
        JSONObject row = JSONFactoryUtil.getJSONFactory().createJSONObject();
        row.put("id", listNganhNghe.get(i).getId());
        row.put("name", listNganhNghe.get(i).getTen());
        lnn.put(row);
    }
    obj.put("listNganhNghe", lnn);
    HttpServletResponse resourceResponse = PortalUtil.getHttpServletResponse(actionResponse);
    resourceResponse.setContentType(ContentTypes.APPLICATION_JSON);
    resourceResponse.setCharacterEncoding(StringPool.UTF8);
    resourceResponse.getWriter().write(obj.toString());
    resourceResponse.getWriter().close();
}

From source file:org.oep.cmon.portlet.doanhnghiep.quanlytaikhoan.action.QuanLyTaiKhoanPortlet.java

License:Apache License

/**
 * This is  function get data CongDan/*from w  w  w  .  j a v a 2 s  .  c om*/
 * Version: 1.0
 *  
 * History: 
 *   DATE        AUTHOR      DESCRIPTION 
 *  ------------------------------------------------- 
 *  3-March-2013  Nam Dinh    Create new
 * @param actionRequest
 * @param actionResponse
 * @throws Exception
 */
public void getDataCongDan(ActionRequest actionRequest, ActionResponse actionResponse) throws Exception {
    long congDanId = ParamUtil.getLong(actionRequest, "congDanId", 0l);
    DateFormat df = new SimpleDateFormat("dd/MM/yyyy");
    CongDan congDan = CongDanLocalServiceUtil.fetchCongDan(congDanId);

    JSONObject obj = JSONFactoryUtil.getJSONFactory().createJSONObject();

    obj.put("nddId", congDan.getId());
    obj.put("nddTen", congDan.getTenDayDu());
    obj.put("nddNgaySinh", df.format(congDan.getNgaySinh()));
    obj.put("nddGioiTinh", congDan.getGioiTinh());
    obj.put("nddQuocTich", congDan.getQuocTichId());
    obj.put("nddDanToc", congDan.getDanTocId());
    obj.put("nddSoCMND", congDan.getSoCmnd());
    obj.put("nddNgayCapCMND", congDan.getNgayCapCmnd() != null ? df.format(congDan.getNgayCapCmnd()) : "");
    obj.put("nddNoiCapCMND",
            congDan.getNoiCapCmndId() != null ? String.valueOf(congDan.getNoiCapCmndId()) : "");
    obj.put("nddTtTinhId", congDan.getDiaChiThuongTruTinhId());
    obj.put("nddTtHuyenId", congDan.getDiaChiThuongTruHuyenId());
    obj.put("nddTtXaId", congDan.getDiaChiThuongTruXaId());
    obj.put("nddTtMoTaDiaChi", congDan.getDiaChiThuongTru());
    obj.put("nddCohtTinhId", congDan.getDiaChiHienNayTinhId());
    obj.put("nddCohtHuyenId", congDan.getDiaChiHienNayHuyenId());
    obj.put("nddCohtXaId", congDan.getDiaChiHienNayXaId());
    obj.put("nddCohtMoTaChoO", congDan.getDiaChiHienNay());
    obj.put("nddDienThoai", congDan.getDienThoaiCoDinh());
    obj.put("nddFax", congDan.getFax());
    obj.put("nddEmail", congDan.getEmail());
    obj.put("nddWebsite", congDan.getWebsite());

    HttpServletResponse resourceResponse = PortalUtil.getHttpServletResponse(actionResponse);
    resourceResponse.setContentType(ContentTypes.APPLICATION_JSON);
    resourceResponse.setCharacterEncoding(StringPool.UTF8);
    resourceResponse.getWriter().write(obj.toString());
    resourceResponse.getWriter().close();
}

From source file:org.oep.cmon.portlet.doanhnghiep.quanlytaikhoan.action.QuanLyTaiKhoanPortlet.java

License:Apache License

/**
 * This is  function get DonViHanhChinh by Id
 * Version: 1.0/*from w ww. jav  a 2  s.  co m*/
 *  
 * History: 
 *   DATE        AUTHOR      DESCRIPTION 
 *  ------------------------------------------------- 
 *  3-March-2013  Nam Dinh    Create new
 * @param resourceRequest
 * @param httlReq
 * @throws NumberFormatException
 * @throws Exception
 */
public void getDonViHanhChinhById(ActionRequest resourceRequest, ActionResponse httpReq)
        throws NumberFormatException, Exception {

    //String id = ParamUtil.getString(resourceRequest, "id");
    long id = ParamUtil.getInteger(resourceRequest, "id");
    // Process Jason feed
    JSONObject jsonFeed = JSONFactoryUtil.createJSONObject();
    JSONArray _name = JSONFactoryUtil.getJSONFactory().createJSONArray();
    JSONArray _id = JSONFactoryUtil.getJSONFactory().createJSONArray();

    // Danh sach don vi hanh chinh
    List<DonViHanhChinh> dsDVHC = DonViHanhChinhLocalServiceUtil.findByChaId(id, 0);

    for (DonViHanhChinh item : dsDVHC) {
        _id.put(item.getId());
        _name.put(item.getTen());
    }
    jsonFeed.put("id", _id);
    jsonFeed.put("name", _name);

    HttpServletResponse resourceResponse = PortalUtil.getHttpServletResponse(httpReq);
    resourceResponse.setContentType("application/json");
    resourceResponse.setCharacterEncoding("UTF-8");
    resourceResponse.getWriter().write(jsonFeed.toString());
    resourceResponse.getWriter().close();
}

From source file:org.oep.cmon.portlet.doanhnghiep.quanlytaikhoan.action.QuanLyTaiKhoanPortlet.java

License:Apache License

/**
 * This is  function get CongDan by Id /* w  w  w.j  av  a2  s. co  m*/
 * Version: 1.0
 *  
 * History: 
 *   DATE        AUTHOR      DESCRIPTION 
 *  ------------------------------------------------- 
 *  3-March-2013  Nam Dinh    Create new
 * @param resourceRequest
 * @param httlReq
 * @throws NumberFormatException
 * @throws Exception
 */
public void getCongDanByID(ActionRequest resourceRequest, ActionResponse httpReq)
        throws NumberFormatException, Exception {

    //String id = ParamUtil.getString(resourceRequest, "id");
    long idCD = ParamUtil.getLong(resourceRequest, "idCD");
    // Process Jason feed
    JSONObject jsonFeed = JSONFactoryUtil.createJSONObject();
    JSONArray _name = JSONFactoryUtil.getJSONFactory().createJSONArray();
    JSONArray _id = JSONFactoryUtil.getJSONFactory().createJSONArray();

    // Danh sach don vi hanh chinh
    CongDan congDan = CongDanLocalServiceUtil.fetchCongDan(idCD);

    String fullName = congDan.getHo() + " " + congDan.getDem() + " " + congDan.getTen();
    /*_id.put(congDan.getId());
    _name.put(congDan.getTen());*/
    //jsonFeed.put("id", congDan.getId());
    jsonFeed.put("name", fullName);
    jsonFeed.put("ngaysinh", FormatUtils.getFormatDate(congDan.getNgaySinh()));
    jsonFeed.put("gioitinh", congDan.getGioiTinh());
    jsonFeed.put("quocgiaid", congDan.getQuocTichId());
    jsonFeed.put("dantocid", congDan.getDanTocId());

    jsonFeed.put("diachihiennay", congDan.getDiaChiHienNay());
    jsonFeed.put("hiennaytinhid", congDan.getDiaChiHienNayTinhId());
    jsonFeed.put("hiennayhuyenid", congDan.getDiaChiHienNayHuyenId());
    jsonFeed.put("hiennayxaid", congDan.getDiaChiHienNayXaId());

    jsonFeed.put("diachithuongtru", congDan.getDiaChiThuongTru());
    jsonFeed.put("thuongtrutinhid", congDan.getDiaChiThuongTruTinhId());
    jsonFeed.put("thuongtruhuyenid", congDan.getDiaChiThuongTruHuyenId());
    jsonFeed.put("thuongtruxaid", congDan.getDiaChiThuongTruXaId());

    jsonFeed.put("socmnd", congDan.getSoCmnd());
    jsonFeed.put("ngaycapcmnd", congDan.getNgayCapCmnd());

    String temp = "";
    if (congDan.getNoiCapCmndId() != null)
        temp = String.valueOf(congDan.getNoiCapCmndId());
    jsonFeed.put("noicapcmndid", temp);

    jsonFeed.put("fax", congDan.getFax());
    jsonFeed.put("website", congDan.getWebsite());
    jsonFeed.put("email", congDan.getEmail());
    jsonFeed.put("dtdd", congDan.getDienThoaiDiDong());

    HttpServletResponse resourceResponse = PortalUtil.getHttpServletResponse(httpReq);
    resourceResponse.setContentType("application/json");
    resourceResponse.setCharacterEncoding("UTF-8");
    resourceResponse.getWriter().write(jsonFeed.toString());
    resourceResponse.getWriter().close();
}