private CandidateDimension parse(DimensionContext context, JSONArray jsonConfig) { List<CandidateDimensionParserStrategy.StrategyConfig> configList = jsonConfig.stream() .filter(json -> json instanceof JSONObject) .map(JSONObject.class::cast) .filter(json -> json.get("dimension") != null && CollectionUtils.isNotEmpty(json.getJSONArray("idList"))) .map(json -> { CandidateDimensionParserStrategy.StrategyConfig config = json.toJavaObject(CandidateDimensionParserStrategy.StrategyConfig.class); if (config.getConfig() == null) { config.setConfig(json); } return config; }).collect(Collectors.toList()); if (configList.isEmpty()) { return CandidateDimension.empty; } return Lazy.val(() -> { List<String> list = configList.stream() .flatMap(config -> strategies .stream() .filter(strategy -> strategy.support(config.getDimension())) .map(strategy -> strategy.parse(context, config)) .filter(CollectionUtils::isNotEmpty) .flatMap(Collection::stream) .filter(StringUtils::hasText) ).collect(Collectors.toList()); return (CandidateDimension) () -> list; }, CandidateDimension.class); }
@Override public AuthenticationBuilder permission(String permissionJson) { JSONArray jsonArray = JSON.parseArray(permissionJson); List<Permission> permissions = new ArrayList<>(); for (int i = 0; i < jsonArray.size(); i++) { JSONObject jsonObject = jsonArray.getJSONObject(i); SimplePermission permission = new SimplePermission(); permission.setId(jsonObject.getString("id")); permission.setName(jsonObject.getString("name")); JSONArray actions = jsonObject.getJSONArray("actions"); if (actions != null) { permission.setActions(new HashSet<>(actions.toJavaList(String.class))); } JSONArray dataAccess = jsonObject.getJSONArray("dataAccesses"); if (null != dataAccess) { permission.setDataAccesses(dataAccess.stream().map(JSONObject.class::cast) .map(dataJson -> dataBuilderFactory.create().fromJson(dataJson.toJSONString()).build()) .filter(Objects::nonNull) .collect(Collectors.toSet())); } permissions.add(permission); } authentication.setPermissions(permissions); return this; }
@Override public Stream<Object> stream() { return jsonArray.stream(); }
private void parseMetadata(JSONArray metadataArray) { Map<String,List<Metadata>> metaMap = metadataArray.stream().map(obj -> { JSONObject metadataJson = (JSONObject)obj; return MetadataParser.parse(metadataJson); }).collect(groupingBy(Metadata::getType, toList())); GenerateContext.put("metadataMapList", metaMap); } }
@RequestMapping(value = "/view/{uploadType}") public Object view(@PathVariable UploadType uploadType, UploadResult uploadResultView) { List<JSONObject> list = new ArrayList<>(); uploadResultView.setUploadType(uploadType); List<UploadResult> uploadResults = uploadResultService.getByType(uploadResultView); if (uploadResults.size() > 0) { for (UploadResult uploadResult : uploadResults) { Date date = uploadResult.getCreateDate(); JSON.parseArray(uploadResult.getDetail()).stream().forEach(o -> { JSONObject per = (JSONObject) o; per.put("createDate", date); list.add(per); }); } } return list.stream().filter(o -> !o.getString("status").equals(STATUS_SUCCESS)).collect(Collectors.toList()); }
@Override public List<Pager> build(String config) { config = config.trim(); List<Object> list = config.startsWith("[") ? JSON.parseArray(config) : Collections.singletonList(JSON.parseObject(config)); return list.stream() .map(JSONObject.class::cast) .map(jsonObject -> { Pager pager = new Pager(); Integer orientation = jsonObject.getInteger("orientation"); pager.setOrientation(orientation == null ? 0 : orientation); List<Layer> layers = jsonObject.getJSONArray("layers") .stream() .map(JSONObject.class::cast) .map(this::buildLayer) .filter(Objects::nonNull) .collect(Collectors.toList()); pager.setLayers(layers); return pager; }).collect(Collectors.toList()); } }
/** * Build a suggest part from the given {@link JSONObject}. * * @param part the JSON object * @return the newly created suggest part */ public static SuggestPart makeSuggestPart(JSONObject part) { SuggestPart suggestPart = new SuggestPart(part.getString(PARAM_TEXT), part.getIntValue(PARAM_OFFSET), part.getIntValue(PARAM_LENGTH)); suggestPart.withOptions(part.getJSONArray(PARAM_OPTIONS) .stream() .map(option -> (JSONObject) option) .map(SuggestOption::makeSuggestOption) .collect(Collectors.toList())); return suggestPart; } }
sb.append(fields.stream().map(obj -> { JSONObject field = (JSONObject)obj; StringBuilder ss = new StringBuilder(); sb.append(",\nUNIQUE KEY `").append(entityName).append("UniqueKey`").append(" ("); sb.append( uniques.stream().map(obj ->{ String fieldName = String.valueOf(obj); return DDLUtils.getColumnName(fieldName);
private CandidateDimension parse(DimensionContext context, JSONArray jsonConfig) { List<CandidateDimensionParserStrategy.StrategyConfig> configList = jsonConfig.stream() .filter(json -> json instanceof JSONObject) .map(JSONObject.class::cast) .filter(json -> json.get("dimension") != null && CollectionUtils.isNotEmpty(json.getJSONArray("idList"))) .map(json -> { CandidateDimensionParserStrategy.StrategyConfig config = json.toJavaObject(CandidateDimensionParserStrategy.StrategyConfig.class); if (config.getConfig() == null) { config.setConfig(json); } return config; }).collect(Collectors.toList()); if (configList.isEmpty()) { return CandidateDimension.empty; } return Lazy.val(() -> { List<String> list = configList.stream() .flatMap(config -> strategies .stream() .filter(strategy -> strategy.support(config.getDimension())) .map(strategy -> strategy.parse(context, config)) .filter(CollectionUtils::isNotEmpty) .flatMap(Collection::stream) .filter(StringUtils::hasText) ).collect(Collectors.toList()); return (CandidateDimension) () -> list; }, CandidateDimension.class); }
/** * Returns the hits as a map of {@link JSONObject}s. * <p> * Note that the query has to be executed before calling this method. * * @return a map of the hits as JSON with the document ID as the key */ public Map<String, JSONObject> getRawHits() { if (useScrolling()) { throw Exceptions.handle() .to(Mixing.LOG) .withSystemErrorMessage("'getRawHits' not possible when scrolling") .handle(); } return response.getJSONObject(KEY_HITS) .getJSONArray(KEY_HITS) .stream() .filter(hit -> hit instanceof JSONObject) .map(hit -> (JSONObject) hit) .collect(Collectors.toMap(hit -> hit.getString(Elastic.ID_FIELD), Function.identity())); }
/** * Returns all suggest parts for the suggester with the given name. * <p> * This is mainly used for term suggesters where every term receives their own suggestions. * * @param name the name of the suggester * @return a list of suggest parts */ public List<SuggestPart> getSuggestParts(String name) { if (response == null) { checkRouting(); List<String> indices = determineIndices(); if (indices.isEmpty()) { Collections.emptyList(); } this.response = client.search(indices, elastic.determineTypeName(descriptor), routing, skip, limit, buildPayload()); } JSONObject responseSuggestions = response.getJSONObject(KEY_SUGGEST); if (responseSuggestions == null) { return Collections.emptyList(); } return responseSuggestions.getJSONArray(name) .stream() .map(part -> (JSONObject) part) .map(SuggestPart::makeSuggestPart) .collect(Collectors.toList()); }
@Override public boolean modelFieldGenerated(Field field, TopLevelClass topLevelClass, IntrospectedColumn introspectedColumn, IntrospectedTable introspectedTable, ModelClassType modelClassType) { introspectedColumn.getLength(); introspectedColumn.isNullable(); Properties colProps = introspectedColumn.getProperties(); String fieldName = field.getName(); LOG.debug("fieldName = {},{}" , fieldName,colProps); String validates = colProps.getProperty("validates","[]"); JSONArray array = JSONArray.parseArray(validates); array.stream().forEach(o -> { String v = String.valueOf(o); LOG.debug("validate=>{}", v); field.addAnnotation(v); FullyQualifiedJavaType imptStr = new FullyQualifiedJavaType(getImport(v)); topLevelClass.addImportedType(imptStr); }); return super.modelFieldGenerated(field, topLevelClass, introspectedColumn, introspectedTable, modelClassType); }
fields.stream().forEach(obj ->{ JSONObject field = (JSONObject)obj; ColumnOverride col = new ColumnOverride(field.getString("fieldName"));