List of usage examples for java.util HashMap forEach
@Override public void forEach(BiConsumer<? super K, ? super V> action)
From source file:com.falcon.orca.domain.DynDataStore.java
public DynDataStore(final HashMap<String, List<Object>> bodyParamsData, final HashMap<String, List<Object>> urlParamsData, final HashMap<String, DynVarUseType> bodyVariableType, final HashMap<String, DynVarUseType> urlVariableType, final HashMap<String, DynGenerator> dataGenerators, final String dataTemplate, final String urlTemplate) { this.bodyParamsData = bodyParamsData; this.urlParamsData = urlParamsData; this.bodyVariableType = bodyVariableType; this.urlVariableType = urlVariableType; this.bodyDataCounters = new HashMap<>(); this.urlDataCounters = new HashMap<>(); this.dataGenerators = new HashMap<>(); if (dataGenerators != null) { dataGenerators.forEach((k, v) -> { switch (v.getType()) { case NUMERIC: { DataGenerator<Long> generator = new NumberGenerator( Long.parseLong(v.getProperties().get("limit")), Long.parseLong(v.getProperties().get("offset"))); this.dataGenerators.put(k, generator); break; }/*from ww w.j av a2 s . c o m*/ case ALPHA_NUMERIC: { DataGenerator<String> generator = new StringGenerator(v.getProperties().get("characters"), Integer.parseInt(StringUtils.isBlank(v.getProperties().get("length")) ? "10" : v.getProperties().get("length")), true, true); this.dataGenerators.put(k, generator); break; } case STRING: { DataGenerator<String> generator = new StringGenerator(v.getProperties().get("characters"), Integer.parseInt(StringUtils.isBlank(v.getProperties().get("length")) ? "10" : v.getProperties().get("length")), true, false); this.dataGenerators.put(k, generator); break; } } }); } if (bodyVariableType != null) { bodyVariableType.forEach((k, v) -> { if (v.equals(DynVarUseType.USE_MULTIPLE)) { this.bodyDataCounters.put(k, 0); } }); } if (urlVariableType != null) { urlVariableType.forEach((k, v) -> { if (v.equals(DynVarUseType.USE_MULTIPLE)) { this.urlDataCounters.put(k, 0); } }); } MustacheFactory mf = new DefaultMustacheFactory(); if (!StringUtils.isBlank(dataTemplate)) { bodyMustache = mf.compile(new StringReader(dataTemplate), "orca-body"); } else { bodyMustache = null; } if (!StringUtils.isBlank(urlTemplate)) { urlMustache = mf.compile(new StringReader(urlTemplate), "orca-url"); } else { urlMustache = null; } }
From source file:com.geometrycloud.happydonut.ui.ChartFilterPanel.java
/** * Carga la informacion para generar la grafica con el top de ventas. * * @param from desde donde buscar./*w w w. ja v a2s . c om*/ * @param to hasta donde buscar. * @return informacion de la grafica. */ private PieDataset chartDataset(LocalDate from, LocalDate to) { DefaultPieDataset dataset = new DefaultPieDataset(); RowList sales = DATABASE.table(SALES_TABLE_NAME).where(SALES_SALE_DATE, ">=", from.toString()) .where(SALES_SALE_DATE, "<=", to.toString()).get(SALES_PRIMARY_KEY, SALES_SALE_DATE); HashMap<String, Long> top = new HashMap<>(); for (Row sale : sales) { RowList details = DATABASE.table(SALE_DETAILS_TABLE_NAME) .where(SALE_DETAILS_SALE, "=", sale.value(SALES_PRIMARY_KEY)) .get(SALE_DETAILS_NAME, SALE_DETAILS_QUANTITY); String name; Long quantity; for (Row detail : details) { name = detail.string(SALE_DETAILS_NAME); quantity = detail.number(SALE_DETAILS_QUANTITY); if (top.containsKey(name)) { quantity += top.get(name); } top.put(name, quantity); } } top.forEach((k, v) -> dataset.setValue(k, v)); return dataset; }
From source file:com.simiacryptus.mindseye.lang.Layer.java
/** * Write zip.// w w w . ja v a 2s.co m * * @param out the out * @param precision the precision */ default void writeZip(@Nonnull ZipOutputStream out, SerialPrecision precision) { try { @Nonnull HashMap<CharSequence, byte[]> resources = new HashMap<>(); JsonObject json = getJson(resources, precision); out.putNextEntry(new ZipEntry("model.json")); @Nonnull JsonWriter writer = new JsonWriter(new OutputStreamWriter(out)); writer.setIndent(" "); writer.setHtmlSafe(true); writer.setSerializeNulls(false); new GsonBuilder().setPrettyPrinting().create().toJson(json, writer); writer.flush(); out.closeEntry(); resources.forEach((name, data) -> { try { out.putNextEntry(new ZipEntry(String.valueOf(name))); IOUtils.write(data, out); out.flush(); out.closeEntry(); } catch (IOException e) { throw new RuntimeException(e); } }); } catch (IOException e) { throw new RuntimeException(e); } }
From source file:com.wormsim.data.SimulationConditions.java
public static SimulationConditions read(String str) throws IOException { RealDistribution food = null;//from w w w .j a v a 2s . co m HashMap<Integer, RealDistribution> pheromones = new HashMap<>(); HashMap<String, IntegerDistribution> groups = new HashMap<>(); if (Utils.MULTIBRACKET_VALIDITY_PATTERN.matcher(str).matches()) { Matcher m = Utils.SAMPLER_PATTERN.matcher(str); while (m.find()) { String match = m.group(); String[] keyvalue = match.split("~"); if (keyvalue[0].matches("\\s*food\\s*")) { food = Utils.readRealDistribution(keyvalue[1].trim()); } else if (keyvalue[0].matches("\\s*pheromone\\[\\d+\\]\\s*")) { int leftbracket = keyvalue[0].indexOf('[') + 1; int rightbracket = keyvalue[0].indexOf(']'); int id = 0; try { id = Integer.valueOf(keyvalue[0].substring(leftbracket, rightbracket)); if (id < 0) { throw new IOException("Invalid pheromone reference " + id + ", must be positive!"); } } catch (NumberFormatException ex) { throw new IOException(ex); } if (pheromones.putIfAbsent(id, Utils.readRealDistribution(keyvalue[1].trim())) != null) { throw new IOException("Duplicate pheromone id " + id); } } else { // Group Distribution groups.put(keyvalue[0].trim(), Utils.readIntegerDistribution(keyvalue[1].trim())); } } } else { throw new IOException("Brackets are missing on simulation conditions definition."); } if (food == null || groups.isEmpty()) { throw new IOException("Incomplete Data! Missing food or groups."); } // Convert pheromones into array Optional<Integer> max = pheromones.keySet().stream().max(Integer::max); RealDistribution[] pheromone_arr = new RealDistribution[max.orElse(0)]; pheromones.forEach((k, v) -> pheromone_arr[k - 1] = v); for (int i = 0; i < pheromone_arr.length; i++) { if (pheromone_arr[i] == null) { pheromone_arr[i] = Utils.ZERO_REAL_DISTRIBUTION; } } return new SimulationConditions(food, pheromone_arr, groups); }
From source file:de.hbz.lobid.helper.CompareJsonMaps.java
public boolean writeFileAndTestJson(final JsonNode actual, final JsonNode expected) { // generated data to map final HashMap<String, String> actualMap = new HashMap<>(); extractFlatMapFromJsonNode(actual, actualMap); // expected data to map final HashMap<String, String> expectedMap = new HashMap<>(); extractFlatMapFromJsonNode(expected, expectedMap); CompareJsonMaps.logger.debug("\n##### remove good entries ###"); Iterator<String> it = actualMap.keySet().iterator(); removeContext(it);/*from w w w . j av a 2s . c om*/ it = expectedMap.keySet().iterator(); removeContext(it); for (final Entry<String, String> e : expectedMap.entrySet()) { CompareJsonMaps.logger.debug("Trying to remove " + e.getKey() + "..."); if (!actualMap.containsKey(e.getKey())) { CompareJsonMaps.logger.warn("At least this element is missing in actual: " + e.getKey()); return false; } if (e.getKey().endsWith("Order]")) { handleOrderedValues(actualMap, e); } else { handleUnorderedValues(actualMap, e); } } if (!actualMap.isEmpty()) { CompareJsonMaps.logger.warn("Fail - no Equality! These keys/values were NOT expected:"); actualMap.forEach((key, val) -> CompareJsonMaps.logger.warn("KEY=" + key + " VALUE=" + val)); } else CompareJsonMaps.logger.info("Succeeded - resources are equal"); return actualMap.size() == 0; }
From source file:org.egov.adtax.service.AdvertisementPermitDetailService.java
public List<HoardingAgencyWiseSearch> getAgencyWiseAdvertisementSearchResult( final AdvertisementPermitDetail advPermitDetail) { final List<AdvertisementPermitDetail> advPermitDtl = advertisementPermitDetailRepository .searchAdvertisementPermitDetailBySearchParams(advPermitDetail); final HashMap<String, HoardingAgencyWiseSearch> agencyWiseHoardingMap = new HashMap<String, HoardingAgencyWiseSearch>(); final List<HoardingAgencyWiseSearch> agencyWiseFinalHoardingList = new ArrayList<HoardingAgencyWiseSearch>(); advPermitDtl.forEach(result -> {/*from w ww . j av a2s . c o m*/ if (result.getAgency() != null) { final HoardingAgencyWiseSearch hoardingSearchResult = new HoardingAgencyWiseSearch(); hoardingSearchResult.setAdvertisementNumber(result.getAdvertisement().getAdvertisementNumber()); hoardingSearchResult.setAgencyName(result.getAgency() != null ? result.getAgency().getName() : ""); hoardingSearchResult.setCategoryName(result.getAdvertisement().getCategory().getName()); hoardingSearchResult .setSubCategoryName(result.getAdvertisement().getSubCategory().getDescription()); BigDecimal totalDemandAmount = BigDecimal.ZERO; BigDecimal totalCollectedAmount = BigDecimal.ZERO; BigDecimal totalPending = BigDecimal.ZERO; BigDecimal totalPenalty = BigDecimal.ZERO; BigDecimal totalAdditionalTax = BigDecimal.ZERO; final Map<String, BigDecimal> demandWiseFeeDetail = advertisementDemandService .checkPendingAmountByDemand(result); totalDemandAmount = totalDemandAmount .add(demandWiseFeeDetail.get(AdvertisementTaxConstants.TOTAL_DEMAND)); totalCollectedAmount = totalCollectedAmount .add(demandWiseFeeDetail.get(AdvertisementTaxConstants.TOTALCOLLECTION)); totalPending = totalPending .add(demandWiseFeeDetail.get(AdvertisementTaxConstants.PENDINGDEMANDAMOUNT)); totalPenalty = totalPenalty.add(demandWiseFeeDetail.get(AdvertisementTaxConstants.PENALTYAMOUNT)); totalAdditionalTax = totalAdditionalTax .add(demandWiseFeeDetail.get(AdvertisementTaxConstants.ADDITIONALTAXAMOUNT)); final HoardingAgencyWiseSearch hoardingSearchObj = agencyWiseHoardingMap .get(result.getAgency().getName()); if (hoardingSearchObj == null) { hoardingSearchResult.setAgency(result.getAgency().getId()); hoardingSearchResult.setTotalDemand(totalDemandAmount); hoardingSearchResult.setCollectedAmount(totalCollectedAmount); hoardingSearchResult.setPendingAmount(totalDemandAmount.subtract(totalCollectedAmount)); hoardingSearchResult.setPenaltyAmount(totalPenalty); hoardingSearchResult.setAdditionalTaxAmount(totalAdditionalTax); hoardingSearchResult.setTotalHoardingInAgency(1); hoardingSearchResult.setHordingIdsSearchedByAgency(result.getId().toString()); hoardingSearchResult .setOwnerDetail(result.getOwnerDetail() != null ? result.getOwnerDetail() : ""); agencyWiseHoardingMap.put(result.getAgency().getName(), hoardingSearchResult); } else { hoardingSearchResult.setAgency(result.getAgency().getId()); hoardingSearchResult.setTotalDemand(agencyWiseHoardingMap.get(result.getAgency().getName()) .getTotalDemand().add(totalDemandAmount)); hoardingSearchResult.setCollectedAmount(agencyWiseHoardingMap.get(result.getAgency().getName()) .getCollectedAmount().add(totalCollectedAmount)); hoardingSearchResult.setPendingAmount(agencyWiseHoardingMap.get(result.getAgency().getName()) .getPendingAmount().add(totalPending)); hoardingSearchResult.setPenaltyAmount(agencyWiseHoardingMap.get(result.getAgency().getName()) .getPenaltyAmount().add(totalPenalty)); hoardingSearchResult.setAdditionalTaxAmount(agencyWiseHoardingMap .get(result.getAgency().getName()).getAdditionalTaxAmount().add(totalAdditionalTax)); hoardingSearchResult.setTotalHoardingInAgency(hoardingSearchObj.getTotalHoardingInAgency() + 1); agencyWiseHoardingMap.put(result.getAgency().getName(), hoardingSearchResult); } } }); if (agencyWiseHoardingMap.size() > 0) agencyWiseHoardingMap.forEach((key, value) -> { agencyWiseFinalHoardingList.add(value); }); return agencyWiseFinalHoardingList; }
From source file:org.egov.adtax.service.AdvertisementPermitDetailService.java
public List<HoardingSearch> getActiveAdvertisementSearchResult(final AdvertisementPermitDetail advPermitDetail, final String searchType) { final List<AdvertisementPermitDetail> advPermitDtl = advertisementPermitDetailRepository .searchActiveAdvertisementPermitDetailBySearchParams(advPermitDetail); final HashMap<String, HoardingSearch> agencyWiseHoardingList = new HashMap<String, HoardingSearch>(); final List<HoardingSearch> hoardingSearchResults = new ArrayList<>(); advPermitDtl.forEach(result -> {// w w w .j ava2 s.co m final HoardingSearch hoardingSearchResult = new HoardingSearch(); hoardingSearchResult.setAdvertisementNumber(result.getAdvertisement().getAdvertisementNumber()); hoardingSearchResult.setApplicationNumber(result.getApplicationNumber()); hoardingSearchResult.setApplicationFromDate(result.getApplicationDate()); hoardingSearchResult.setAgencyName(result.getAgency() != null ? result.getAgency().getName() : ""); hoardingSearchResult.setStatus(result.getAdvertisement().getStatus()); hoardingSearchResult.setPermitStatus(result.getStatus().getCode()); hoardingSearchResult.setPermissionNumber(result.getPermissionNumber()); hoardingSearchResult.setId(result.getId()); hoardingSearchResult.setCategoryName(result.getAdvertisement().getCategory().getName()); hoardingSearchResult.setSubCategoryName(result.getAdvertisement().getSubCategory().getDescription()); hoardingSearchResult.setOwnerDetail(result.getOwnerDetail() != null ? result.getOwnerDetail() : ""); if (result.getAdvertisement().getDemandId() != null) { hoardingSearchResult.setFinancialYear( result.getAdvertisement().getDemandId().getEgInstallmentMaster().getDescription()); if (searchType != null && "agency".equalsIgnoreCase(searchType) && result.getAgency() != null) { // PASS DEMAND OF EACH HOARDING AND GROUP BY AGENCY WISE. final Map<String, BigDecimal> demandWiseFeeDetail = advertisementDemandService .checkPedingAmountByDemand(result); // TODO: DO CODE CHANGE final HoardingSearch hoardingSearchObj = agencyWiseHoardingList .get(result.getAgency().getName()); if (hoardingSearchObj == null) { hoardingSearchResult .setPenaltyAmount(demandWiseFeeDetail.get(AdvertisementTaxConstants.PENALTYAMOUNT)); hoardingSearchResult.setPendingDemandAmount( demandWiseFeeDetail.get(AdvertisementTaxConstants.PENDINGDEMANDAMOUNT)); hoardingSearchResult.setAdditionalTaxAmount( demandWiseFeeDetail.get(AdvertisementTaxConstants.ADDITIONALTAXAMOUNT)); hoardingSearchResult.setTotalHoardingInAgency(1); hoardingSearchResult.setHordingIdsSearchedByAgency(result.getId().toString()); agencyWiseHoardingList.put(result.getAgency().getName(), hoardingSearchResult); } else { final StringBuffer hoardingIds = new StringBuffer(); hoardingSearchObj.setPenaltyAmount(hoardingSearchObj.getPenaltyAmount() .add(demandWiseFeeDetail.get(AdvertisementTaxConstants.PENALTYAMOUNT))); hoardingSearchObj.setAdditionalTaxAmount(hoardingSearchObj.getAdditionalTaxAmount() .add(demandWiseFeeDetail.get(AdvertisementTaxConstants.ADDITIONALTAXAMOUNT))); hoardingSearchObj.setPendingDemandAmount(hoardingSearchObj.getPendingDemandAmount() .add(demandWiseFeeDetail.get(AdvertisementTaxConstants.PENDINGDEMANDAMOUNT))); hoardingSearchObj .setTotalHoardingInAgency(hoardingSearchObj.getTotalHoardingInAgency() + 1); hoardingIds.append(hoardingSearchObj.getHordingIdsSearchedByAgency()).append("~") .append(result.getId()); hoardingSearchObj.setHordingIdsSearchedByAgency(hoardingIds.toString()); agencyWiseHoardingList.put(result.getAgency().getName(), hoardingSearchObj); } } else { final Map<String, BigDecimal> demandWiseFeeDetail = advertisementDemandService .checkPedingAmountByDemand(result); hoardingSearchResult .setPenaltyAmount(demandWiseFeeDetail.get(AdvertisementTaxConstants.PENALTYAMOUNT)); hoardingSearchResult.setAdditionalTaxAmount( demandWiseFeeDetail.get(AdvertisementTaxConstants.ADDITIONALTAXAMOUNT)); hoardingSearchResult.setPendingDemandAmount( demandWiseFeeDetail.get(AdvertisementTaxConstants.PENDINGDEMANDAMOUNT)); hoardingSearchResults.add(hoardingSearchResult); } } }); if (agencyWiseHoardingList.size() > 0) { final List<HoardingSearch> agencyWiseFinalHoardingList = new ArrayList<HoardingSearch>(); agencyWiseHoardingList.forEach((key, value) -> { agencyWiseFinalHoardingList.add(value); }); return agencyWiseFinalHoardingList; } return hoardingSearchResults; }
From source file:org.egov.adtax.service.AdvertisementPermitDetailService.java
public List<HoardingSearch> getAdvertisementSearchResult(final AdvertisementPermitDetail advPermitDetail, final String searchType) { final List<AdvertisementPermitDetail> advPermitDtl = advertisementPermitDetailRepository .searchAdvertisementPermitDetailBySearchParams(advPermitDetail); final HashMap<String, HoardingSearch> agencyWiseHoardingList = new HashMap<String, HoardingSearch>(); final List<HoardingSearch> hoardingSearchResults = new ArrayList<>(); advPermitDtl.forEach(result -> {// w w w . ja v a 2 s. c o m final HoardingSearch hoardingSearchResult = new HoardingSearch(); hoardingSearchResult.setAdvertisementNumber(result.getAdvertisement().getAdvertisementNumber()); hoardingSearchResult.setApplicationNumber(result.getApplicationNumber()); hoardingSearchResult.setApplicationFromDate(result.getApplicationDate()); hoardingSearchResult.setAgencyName(result.getAgency() != null ? result.getAgency().getName() : ""); hoardingSearchResult.setStatus(result.getAdvertisement().getStatus()); hoardingSearchResult.setPermitStatus(result.getStatus().getCode()); hoardingSearchResult.setPermissionNumber(result.getPermissionNumber()); hoardingSearchResult.setId(result.getId()); hoardingSearchResult.setLegacy(result.getAdvertisement().getLegacy()); hoardingSearchResult.setCategoryName(result.getAdvertisement().getCategory().getName()); hoardingSearchResult.setSubCategoryName(result.getAdvertisement().getSubCategory().getDescription()); hoardingSearchResult.setOwnerDetail(result.getOwnerDetail() != null ? result.getOwnerDetail() : ""); setWorkFlowDetails(result, hoardingSearchResult); if (result.getAdvertisement().getDemandId() != null) { hoardingSearchResult.setFinancialYear( result.getAdvertisement().getDemandId().getEgInstallmentMaster().getDescription()); if (searchType != null && "agency".equalsIgnoreCase(searchType)) { if (result.getAgency() != null) { // PASS DEMAND OF EACH HOARDING AND GROUP BY AGENCY WISE. final Map<String, BigDecimal> demandWiseFeeDetail = advertisementDemandService .checkPedingAmountByDemand(result); // TODO: DO CODE CHANGE final HoardingSearch hoardingSearchObj = agencyWiseHoardingList .get(result.getAgency().getName()); if (hoardingSearchObj == null) { hoardingSearchResult.setPenaltyAmount( demandWiseFeeDetail.get(AdvertisementTaxConstants.PENALTYAMOUNT)); hoardingSearchResult.setPendingDemandAmount( demandWiseFeeDetail.get(AdvertisementTaxConstants.PENDINGDEMANDAMOUNT)); hoardingSearchResult.setAdditionalTaxAmount( demandWiseFeeDetail.get(AdvertisementTaxConstants.ADDITIONALTAXAMOUNT)); hoardingSearchResult.setTotalAmount(hoardingSearchResult.getPendingDemandAmount() .add(hoardingSearchResult.getPenaltyAmount()) .add(hoardingSearchResult.getAdditionalTaxAmount() != null ? hoardingSearchResult.getAdditionalTaxAmount() : BigDecimal.ZERO)); hoardingSearchResult.setTotalHoardingInAgency(1); hoardingSearchResult.setHordingIdsSearchedByAgency(result.getId().toString()); agencyWiseHoardingList.put(result.getAgency().getName(), hoardingSearchResult); } else { final StringBuffer hoardingIds = new StringBuffer(); hoardingSearchObj.setPenaltyAmount(hoardingSearchObj.getPenaltyAmount() .add(demandWiseFeeDetail.get(AdvertisementTaxConstants.PENALTYAMOUNT))); hoardingSearchObj.setAdditionalTaxAmount(hoardingSearchObj.getAdditionalTaxAmount() .add(demandWiseFeeDetail.get(AdvertisementTaxConstants.ADDITIONALTAXAMOUNT))); hoardingSearchObj.setPendingDemandAmount(hoardingSearchObj.getPendingDemandAmount() .add(demandWiseFeeDetail.get(AdvertisementTaxConstants.PENDINGDEMANDAMOUNT))); hoardingSearchObj.setTotalAmount(hoardingSearchObj.getPendingDemandAmount() .add(hoardingSearchObj.getPenaltyAmount()) .add(hoardingSearchResult.getAdditionalTaxAmount() != null ? hoardingSearchResult.getAdditionalTaxAmount() : BigDecimal.ZERO)); hoardingSearchObj .setTotalHoardingInAgency(hoardingSearchObj.getTotalHoardingInAgency() + 1); hoardingIds.append(hoardingSearchObj.getHordingIdsSearchedByAgency()).append("~") .append(result.getId()); hoardingSearchObj.setHordingIdsSearchedByAgency(hoardingIds.toString()); agencyWiseHoardingList.put(result.getAgency().getName(), hoardingSearchObj); } } } else { final Map<String, BigDecimal> demandWiseFeeDetail = advertisementDemandService .checkPedingAmountByDemand(result); hoardingSearchResult .setPenaltyAmount(demandWiseFeeDetail.get(AdvertisementTaxConstants.PENALTYAMOUNT)); hoardingSearchResult.setPendingDemandAmount( demandWiseFeeDetail.get(AdvertisementTaxConstants.PENDINGDEMANDAMOUNT)); hoardingSearchResult.setAdditionalTaxAmount( demandWiseFeeDetail.get(AdvertisementTaxConstants.ADDITIONALTAXAMOUNT)); hoardingSearchResult.setTotalAmount(hoardingSearchResult.getPendingDemandAmount() .add(hoardingSearchResult.getPenaltyAmount()) .add(hoardingSearchResult.getAdditionalTaxAmount() != null ? hoardingSearchResult.getAdditionalTaxAmount() : BigDecimal.ZERO)); hoardingSearchResults.add(hoardingSearchResult); } } }); if (agencyWiseHoardingList.size() > 0) { final List<HoardingSearch> agencyWiseFinalHoardingList = new ArrayList<HoardingSearch>(); agencyWiseHoardingList.forEach((key, value) -> { agencyWiseFinalHoardingList.add(value); }); return agencyWiseFinalHoardingList; } return hoardingSearchResults; }
From source file:com.javafxpert.wikibrowser.WikiVisGraphController.java
/** * Calls the Neo4j Transactional Cypher service and returns an object that holds results * @param neoCypherUrl// w ww .j a va 2 s. c om * @param postString * @return */ private VisGraphResponseNear queryProcessSearchResponse(String neoCypherUrl, String postString) { log.info("neoCypherUrl: " + neoCypherUrl); log.info("postString: " + postString); RestTemplate restTemplate = new RestTemplate(); HttpHeaders httpHeaders = WikiBrowserUtils.createHeaders(wikiBrowserProperties.getCypherUsername(), wikiBrowserProperties.getCypherPassword()); httpHeaders.setContentType(MediaType.APPLICATION_JSON); httpHeaders.setAccept(Arrays.asList(MediaType.APPLICATION_JSON)); HttpEntity request = new HttpEntity(postString, httpHeaders); GraphResponseFar graphResponseFar = null; VisGraphResponseNear visGraphResponseNear = new VisGraphResponseNear(); try { ResponseEntity<GraphResponseFar> result = restTemplate.exchange(neoCypherUrl, HttpMethod.POST, request, GraphResponseFar.class); graphResponseFar = result.getBody(); log.info("graphResponseFar: " + graphResponseFar); // Populate VisGraphResponseNear instance from GraphResponseFar instance HashMap<String, VisGraphNodeNear> visGraphNodeNearMap = new HashMap<>(); HashMap<String, VisGraphEdgeNear> visGraphEdgeNearMap = new HashMap<>(); List<ResultFar> resultFarList = graphResponseFar.getResultFarList(); if (resultFarList.size() > 0) { List<DataFar> dataFarList = resultFarList.get(0).getDataFarList(); Iterator<DataFar> dataFarIterator = dataFarList.iterator(); while (dataFarIterator.hasNext()) { GraphFar graphFar = dataFarIterator.next().getGraphFar(); List<GraphNodeFar> graphNodeFarList = graphFar.getGraphNodeFarList(); Iterator<GraphNodeFar> graphNodeFarIterator = graphNodeFarList.iterator(); while (graphNodeFarIterator.hasNext()) { GraphNodeFar graphNodeFar = graphNodeFarIterator.next(); VisGraphNodeNear visGraphNodeNear = new VisGraphNodeNear(); //visGraphNodeNear.setDbId(graphNodeFar.getId()); // Database ID for this node visGraphNodeNear.setDbId(graphNodeFar.getGraphNodePropsFar().getItemId().substring(1)); visGraphNodeNear.setTitle(graphNodeFar.getGraphNodePropsFar().getTitle()); visGraphNodeNear.setLabelsList(graphNodeFar.getLabelsList()); visGraphNodeNear.setItemId(graphNodeFar.getGraphNodePropsFar().getItemId()); String itemId = visGraphNodeNear.getItemId(); String articleTitle = visGraphNodeNear.getTitle(); // Retrieve the article's image String thumbnailUrl = null; String articleLang = "en"; // TODO: Add a language property to Item nodes stored in Neo4j that aren't currently in English, // and use that property to mutate articleTitleLang // First, try to get the thumbnail by ID from cache thumbnailUrl = ThumbnailCache.getThumbnailUrlById(itemId, articleLang); if (thumbnailUrl == null) { // If not available, try to get thumbnail by ID from ThumbnailService try { String thumbnailByIdUrl = this.wikiBrowserProperties .getThumbnailByIdServiceUrl(itemId, articleLang); thumbnailUrl = new RestTemplate().getForObject(thumbnailByIdUrl, String.class); if (thumbnailUrl != null) { visGraphNodeNear.setImageUrl(thumbnailUrl); } else { // If thumbnail isn't available by ID, try to get thumbnail by article title try { String thumbnailByTitleUrl = this.wikiBrowserProperties .getThumbnailByTitleServiceUrl(articleTitle, articleLang); thumbnailUrl = new RestTemplate().getForObject(thumbnailByTitleUrl, String.class); if (thumbnailUrl != null) { visGraphNodeNear.setImageUrl(thumbnailUrl); } else { visGraphNodeNear.setImageUrl(""); } //log.info("thumbnailUrl:" + thumbnailUrl); } catch (Exception e) { e.printStackTrace(); log.info("Caught exception when calling /thumbnail?title=" + articleTitle + " : " + e); } } //log.info("thumbnailUrl:" + thumbnailUrl); } catch (Exception e) { e.printStackTrace(); log.info("Caught exception when calling /thumbnail?id=" + itemId + " : " + e); } } else { visGraphNodeNear.setImageUrl(thumbnailUrl); } /* // Check cache for thumbnail thumbnailUrl = ThumbnailCache.getThumbnailUrlById(itemId, articleLang); if (thumbnailUrl != null && thumbnailUrl.length() > 0) { // Thumbnail image found in cache by ID, which is the preferred location visGraphNodeNear.setImageUrl(thumbnailUrl); } else { // Thumbnail image not found in cache by ID, so look with Wikimedia API by article title log.info("Thumbnail not found in cache for itemId: " + itemId + ", lang: " + articleLang + " so looking with Wikimedia API by article title"); try { String url = this.wikiBrowserProperties.getThumbnailByTitleServiceUrl(articleTitle, articleLang); thumbnailUrl = new RestTemplate().getForObject(url, String.class); if (thumbnailUrl != null && thumbnailUrl.length() > 0) { visGraphNodeNear.setImageUrl(thumbnailUrl); } else { log.info("Thumbnail not found for articleTitle: " + articleTitle + ", trying by itemId: " + itemId); try { String url = this.wikiBrowserProperties.getThumbnailByIdServiceUrl(itemId, articleLang); thumbnailUrl = new RestTemplate().getForObject(url, String.class); if (thumbnailUrl != null) { visGraphNodeNear.setImageUrl(thumbnailUrl); // Because successful, cache by article title ThumbnailCache.setThumbnailUrlByTitle(articleTitle, articleLang, thumbnailUrl); } else { visGraphNodeNear.setImageUrl(""); } //log.info("thumbnailUrl:" + thumbnailUrl); } catch (Exception e) { e.printStackTrace(); log.info("Caught exception when calling /thumbnail?id=" + itemId + " : " + e); } } //log.info("thumbnailUrl:" + thumbnailUrl); } catch (Exception e) { e.printStackTrace(); log.info("Caught exception when calling /thumbnail?title=" + articleTitle + " : " + e); } } */ // Note: The key in the graphNodeNearMap is the Neo4j node id, not the Wikidata item ID visGraphNodeNearMap.put(graphNodeFar.getId(), visGraphNodeNear); } List<GraphRelationFar> graphRelationFarList = graphFar.getGraphRelationFarList(); Iterator<GraphRelationFar> graphRelationFarIterator = graphRelationFarList.iterator(); while (graphRelationFarIterator.hasNext()) { GraphRelationFar graphRelationFar = graphRelationFarIterator.next(); VisGraphEdgeNear visGraphEdgeNear = new VisGraphEdgeNear(); // Use the Neo4j node ids from the relationship to retrieve the Wikidata Item IDs from the graphNodeNearMap String neo4jStartNodeId = graphRelationFar.getStartNode(); String wikidataStartNodeItemId = visGraphNodeNearMap.get(neo4jStartNodeId).getItemId(); String neo4jEndNodeId = graphRelationFar.getEndNode(); String wikidataEndNodeItemId = visGraphNodeNearMap.get(neo4jEndNodeId).getItemId(); //visGraphEdgeNear.setFromDbId(neo4jStartNodeId); visGraphEdgeNear.setFromDbId(wikidataStartNodeItemId.substring(1)); //visGraphEdgeNear.setToDbId(neo4jEndNodeId); visGraphEdgeNear.setToDbId(wikidataEndNodeItemId.substring(1)); visGraphEdgeNear.setLabel(graphRelationFar.getType()); visGraphEdgeNear.setArrowDirection("to"); visGraphEdgeNear.setPropId(graphRelationFar.getGraphRelationPropsFar().getPropId()); visGraphEdgeNear.setFromItemId(wikidataStartNodeItemId); visGraphEdgeNear.setToItemId(wikidataEndNodeItemId); // Note: The key in the graphLinkNearMap is the Neo4j node id, not the Wikidata item ID visGraphEdgeNearMap.put(graphRelationFar.getId(), visGraphEdgeNear); } } // Create and populate a List of nodes to set into the graphResponseNear instance List<VisGraphNodeNear> visGraphNodeNearList = new ArrayList<>(); visGraphNodeNearMap.forEach((k, v) -> { visGraphNodeNearList.add(v); }); visGraphResponseNear.setVisGraphNodeNearList(visGraphNodeNearList); // Create and populate a List of links to set into the graphResponseNear instance List<VisGraphEdgeNear> visGraphEdgeNearList = new ArrayList<>(); visGraphEdgeNearMap.forEach((k, v) -> { visGraphEdgeNearList.add(v); }); visGraphResponseNear.setVisGraphEdgeNearList(visGraphEdgeNearList); } } catch (Exception e) { e.printStackTrace(); log.info("Caught exception when calling Neo Cypher service " + e); } return visGraphResponseNear; }