diff --git a/api/src/main/java/org/open4goods/api/controller/api/VerticalsGenerationController.java b/api/src/main/java/org/open4goods/api/controller/api/VerticalsGenerationController.java index 6ed0eacfb..dc293ca32 100644 --- a/api/src/main/java/org/open4goods/api/controller/api/VerticalsGenerationController.java +++ b/api/src/main/java/org/open4goods/api/controller/api/VerticalsGenerationController.java @@ -175,6 +175,15 @@ public void updateVerticalWithMappings( } - + @GetMapping(path="/update/verticals/attributes/{vertical}") + @Operation(summary="Update the suggested attributes for a given vertical directly in the file !") + @PreAuthorize("hasAuthority('"+RolesConstants.ROLE_ADMIN+"')") + public void updateVerticalWithAttributes( + @RequestParam (defaultValue = "tv") String vertical) throws ResourceNotFoundException, IOException { + + //TODO(p2,conf) : from conf + verticalsGenService.generateAttributesMapping(verticalsConfigService.getConfigById(vertical)); + + } } diff --git a/api/src/main/java/org/open4goods/api/services/VerticalsGenerationService.java b/api/src/main/java/org/open4goods/api/services/VerticalsGenerationService.java index e4ef170bf..3951c7990 100644 --- a/api/src/main/java/org/open4goods/api/services/VerticalsGenerationService.java +++ b/api/src/main/java/org/open4goods/api/services/VerticalsGenerationService.java @@ -418,7 +418,7 @@ public String generateMapping(VerticalConfig vc, Integer minOfferscount) { .map(e->e.gtin()) .toList(); - return generateCategoryMappingFragmentForGtin(items,vc.getExcludedFromCategoriesMatching()); + return generateCategoryMappingFragmentForGtin(items,vc.getGenerationExcludedFromCategoriesMatching()); @@ -533,9 +533,23 @@ public void updateVerticalFile(Integer minOffers, String fileName) { * @param vertical * @return */ - public String generateAttributesMapping(String vertical, Set excludeAttributes) { - VerticalAttributesStats stats = attributesStats(vertical); + public String generateAttributesMapping(VerticalConfig verticalConfig) { + LOGGER.info("Generating attributes mapping for {}", verticalConfig); + VerticalAttributesStats stats = attributesStats(verticalConfig.getId()); + Set exclusions = new HashSet(); + if (null != verticalConfig.getGenerationExcludedFromAttributesMatching()) { + exclusions.addAll(verticalConfig.getGenerationExcludedFromAttributesMatching()); + } + + // Adding existing defined attributes matching + verticalConfig.getAttributesConfig().getConfigs().stream().map(e->e.getSynonyms().values()).forEach(e -> { + e.forEach(elem -> { + elem.forEach(e1 -> { + exclusions.add(e1); + }); + }); + }); @@ -543,9 +557,9 @@ public String generateAttributesMapping(String vertical, Set excludeAttr for (Entry cat : stats.getStats().entrySet()) { - if (null != excludeAttributes && !excludeAttributes.contains(cat.getKey())) { - + if (!exclusions.contains(cat.getKey())) { + LOGGER.info("An unknown attribute !"); // AttributesConfig } @@ -555,8 +569,35 @@ public String generateAttributesMapping(String vertical, Set excludeAttr } - - - + /** + * + * @return an attribute definition, from template + */ +// public String attributeConfigTemplate() { +// String ret = ""; +// try { +// Resource r = resourceResolver.getResource("classpath:/templates/attribute.yml"); +// String content = r.getContentAsString(Charset.defaultCharset()); +// +// Map context = new HashMap(); +// +// context.put("id",id ); +// context.put("googleTaxonomyId", googleTaxonomyId); +// // Here is a tweak, we provide some sample products coma separated +// context.put("matchingCategories", generateCategoryMappingFragmentForGtin(Arrays.asList(matchingCategories.split(",")), null)); +// context.put("urlPrefix", urlPrefix); +// context.put("h1Prefix", h1Prefix); +// context.put("verticalHomeUrl", verticalHomeUrl); +// context.put("verticalHomeTitle", verticalHomeTitle); +// +// ret = evalService.thymeleafEval(context, content); +// } catch (IOException e) { +// LOGGER.error("Error while generating vertical file",e); +// } +// +// return ret; +// +// } +// } diff --git a/commons/src/main/java/org/open4goods/commons/config/yml/ui/VerticalConfig.java b/commons/src/main/java/org/open4goods/commons/config/yml/ui/VerticalConfig.java index e091887cc..683c88eb5 100644 --- a/commons/src/main/java/org/open4goods/commons/config/yml/ui/VerticalConfig.java +++ b/commons/src/main/java/org/open4goods/commons/config/yml/ui/VerticalConfig.java @@ -103,11 +103,18 @@ public class VerticalConfig{ private Set excludingTokensFromCategoriesMatching = new HashSet(); /** - * The set of datasourcenames that will be excluded to generate categories matching + * The set of datasourcenames that will be excluded in generation of categories matching */ @JsonMerge - private Set excludedFromCategoriesMatching = new HashSet(); + private Set generationExcludedFromCategoriesMatching = new HashSet(); + /** + * The set of attributes names that will be excluded in generation of attributes suggestion + */ + + @JsonMerge + private Set generationExcludedFromAttributesMatching = new HashSet(); + /** @@ -793,12 +800,12 @@ public void setForceNameGeneration(boolean forceUrlNameGeneration) { this.forceNameGeneration = forceUrlNameGeneration; } - public Set getExcludedFromCategoriesMatching() { - return excludedFromCategoriesMatching; + public Set getGenerationExcludedFromCategoriesMatching() { + return generationExcludedFromCategoriesMatching; } - public void setExcludedFromCategoriesMatching(Set excludedFromCategoriesMatching) { - this.excludedFromCategoriesMatching = excludedFromCategoriesMatching; + public void setGenerationExcludedFromCategoriesMatching(Set excludedFromCategoriesMatching) { + this.generationExcludedFromCategoriesMatching = excludedFromCategoriesMatching; } public Set getExcludingTokensFromCategoriesMatching() { @@ -809,6 +816,14 @@ public void setExcludingTokensFromCategoriesMatching(Set excludingTokens this.excludingTokensFromCategoriesMatching = excludingTokens; } + public Set getGenerationExcludedFromAttributesMatching() { + return generationExcludedFromAttributesMatching; + } + + public void setGenerationExcludedFromAttributesMatching(Set generationExcludedFromAttributesMatching) { + this.generationExcludedFromAttributesMatching = generationExcludedFromAttributesMatching; + } + diff --git a/verticals/src/main/resources/verticals/_default.yml b/verticals/src/main/resources/verticals/_default.yml index 9ed1daf12..2c6928439 100644 --- a/verticals/src/main/resources/verticals/_default.yml +++ b/verticals/src/main/resources/verticals/_default.yml @@ -10,13 +10,24 @@ forceNameGeneration: true # These datasources will be excluded from categories matching -excludedFromCategoriesMatching: +generationExcludedFromCategoriesMatching: - "fnac.com" # - "rakuten.com-csv.yml" +generationExcludedFromAttributesMatching: + - FEED_URL + - FABRICANT + - REFURBISHED + - DISPONIBILITE + - ETAT_PRODUIT + + +# If product categories contains one of this token, this will be unmatched excludingTokensFromCategoriesMatching: - ACCESSOIRE + + ##################################################################################################################################### # I18N CONFIGURATION # Configure in a i18n way all the texts of a product, including the Url, the title, the description, the open graph metas, .... @@ -256,6 +267,7 @@ attributesConfig: - "CODEBARRE" - "ETAT" - "REFURBISHED" + - "ETAT_PRODUIT" - "DISPONIBILITE" # Noisy items @@ -286,6 +298,7 @@ attributesConfig: - "PRE_ORDER" - "RATING" - "SEARCH_PRICE" + - "PRICE_NEW" - "STOCK_QUANTITY" - "STOCK_STATUS" - "WEB_OFFER"