List of usage examples for javax.json JsonReader readArray
JsonArray readArray();
From source file:org.grogshop.services.endpoints.impl.ShopItemsServiceImpl.java
@Override public Response newItem(@NotNull @FormParam("user_id") Long userId, @NotNull @FormParam("club_id") Long clubId, @NotNull @FormParam("type") String type, @NotNull @NotEmpty @FormParam("name") String name, @NotNull @NotEmpty @FormParam("description") String description, @NotNull @NotEmpty @FormParam("tags") String tags, @FormParam("minPrice") String minPrice, @FormParam("maxPrice") String maxPrice) throws ServiceException { JsonReader reader = Json.createReader(new ByteArrayInputStream(tags.getBytes())); JsonArray array = reader.readArray(); reader.close();// w w w . java2s . co m List<String> interestsList = new ArrayList<String>(); if (array != null) { for (int i = 0; i < array.size(); i++) { log.info("Tag[" + i + "]: " + array.getJsonObject(i).getString("text")); interestsList.add(array.getJsonObject(i).getString("text")); } } Long newItem = itemsService.newItem(userId, clubId, type, name, description, interestsList, (minPrice == null) ? new BigDecimal(0) : new BigDecimal(minPrice), (maxPrice == null) ? new BigDecimal(0) : new BigDecimal(maxPrice)); return Response.ok(newItem).build(); }
From source file:org.grogshop.services.endpoints.impl.ShopUserProfileServiceImpl.java
public Response setInterests(@NotNull @PathParam("user_id") Long user_id, @FormParam("interests") String interests) throws ServiceException { log.info("Storing from the database: (" + user_id + ") " + interests); if (interests != null) { JsonReader reader = Json.createReader(new ByteArrayInputStream(interests.getBytes())); JsonArray array = reader.readArray(); reader.close();//ww w .jav a 2s . c om List<Interest> interestsList = new ArrayList<Interest>(array.size()); if (array != null) { for (int i = 0; i < array.size(); i++) { log.info("Interest[" + i + "]: " + array.getJsonObject(i).getString("name")); interestsList.add(interestService.get(array.getJsonObject(i).getString("name"))); } } profileService.setInterests(user_id, interestsList); } return Response.ok().build(); }
From source file:org.kuali.rice.krad.uif.layout.collections.DataTablesPagingHelper.java
/** * Extract the sorting information from the DataTablesInputs into a more generic form. * * @param form object containing the view's data * @param view posted view containing the collection * @param dataTablesInputs the parsed request data from dataTables * @return the List of ColumnSort elements representing the requested sort columns, types, and directions *//* w w w .j a v a 2 s. c om*/ private static List<ColumnSort> buildColumnSorts(View view, ViewModel form, DataTablesInputs dataTablesInputs, CollectionGroup collectionGroup) { int[] sortCols = dataTablesInputs.iSortCol_; // cols being sorted on (for multi-col sort) boolean[] sortable = dataTablesInputs.bSortable_; // which columns are sortable String[] sortDir = dataTablesInputs.sSortDir_; // direction to sort // parse table options to gather the sort types String aoColumnDefsValue = (String) form.getViewPostMetadata().getComponentPostData(collectionGroup.getId(), UifConstants.TableToolsKeys.AO_COLUMN_DEFS); JsonArray jsonColumnDefs = null; if (!StringUtils.isEmpty(aoColumnDefsValue)) { // we'll parse this using a JSON library to make things simpler // function definitions are not allowed in JSON aoColumnDefsValue = aoColumnDefsValue.replaceAll("function\\([^)]*\\)\\s*\\{[^}]*\\}", "\"REDACTED\""); JsonReader jsonReader = Json.createReader(new StringReader(aoColumnDefsValue)); jsonColumnDefs = jsonReader.readArray(); } List<ColumnSort> columnSorts = new ArrayList<ColumnSort>(sortCols.length); for (int sortColsIndex = 0; sortColsIndex < sortCols.length; sortColsIndex++) { int sortCol = sortCols[sortColsIndex]; // get the index of the column being sorted on if (sortable[sortCol]) { String sortType = getSortType(jsonColumnDefs, sortCol); ColumnSort.Direction sortDirection = ColumnSort.Direction .valueOf(sortDir[sortColsIndex].toUpperCase()); columnSorts.add(new ColumnSort(sortCol, sortDirection, sortType)); } } return columnSorts; }
From source file:org.kuali.rice.krad.web.controller.helper.DataTablesPagingHelper.java
/** * Extract the sorting information from the DataTablesInputs into a more generic form. * * @param dataTablesInputs the parsed request data from dataTables * @return the List of ColumnSort elements representing the requested sort columns, types, and directions *///www .j av a2 s. c o m private List<ColumnSort> buildColumnSorts(DataTablesInputs dataTablesInputs, CollectionGroup collectionGroup) { int[] sortCols = dataTablesInputs.iSortCol_; // cols being sorted on (for multi-col sort) boolean[] sortable = dataTablesInputs.bSortable_; // which columns are sortable String[] sortDir = dataTablesInputs.sSortDir_; // direction to sort // parse table options to gather the sort types String aoColumnDefsValue = ((TableLayoutManager) collectionGroup.getLayoutManager()).getRichTable() .getTemplateOptions().get(UifConstants.TableToolsKeys.AO_COLUMN_DEFS); JsonArray jsonColumnDefs = null; if (!StringUtils.isEmpty(aoColumnDefsValue)) { // we'll parse this using a JSON library to make things simpler // function definitions are not allowed in JSON aoColumnDefsValue = aoColumnDefsValue.replaceAll("function\\([^)]*\\)\\s*\\{[^}]*\\}", "\"REDACTED\""); JsonReader jsonReader = Json.createReader(new StringReader(aoColumnDefsValue)); jsonColumnDefs = jsonReader.readArray(); } List<ColumnSort> columnSorts = new ArrayList<ColumnSort>(sortCols.length); for (int sortColsIndex = 0; sortColsIndex < sortCols.length; sortColsIndex++) { int sortCol = sortCols[sortColsIndex]; // get the index of the column being sorted on if (sortable[sortCol]) { String sortType = getSortType(jsonColumnDefs, sortCol); ColumnSort.Direction sortDirection = ColumnSort.Direction .valueOf(sortDir[sortColsIndex].toUpperCase()); columnSorts.add(new ColumnSort(sortCol, sortDirection, sortType)); } } return columnSorts; }