Skip to content

Commit

Permalink
Merge pull request #183 from nicolasb29/main
Browse files Browse the repository at this point in the history
Review code, set java target to 21, enabled virtual thread
  • Loading branch information
GoulvenF authored Dec 3, 2023
2 parents ac80366 + e68fdb5 commit 04bf762
Show file tree
Hide file tree
Showing 100 changed files with 371 additions and 473 deletions.
2 changes: 1 addition & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,9 @@

import java.io.Closeable;
import java.io.IOException;
import java.util.Collection;
import java.util.Set;

import org.open4goods.exceptions.AggregationSkipException;
import org.open4goods.helper.GenericFileLogger;
import org.open4goods.model.data.DataFragment;
import org.open4goods.model.product.Product;
import org.slf4j.Logger;

import ch.qos.logback.classic.Level;


/**
* Defines the contract for an AggregationService, that participates in building AggregatedDatas from DataFragments
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
package org.open4goods.aggregation;

import java.io.Closeable;
import java.io.IOException;
import java.util.Collection;
import java.util.Set;

import org.open4goods.exceptions.AggregationSkipException;
import org.open4goods.helper.GenericFileLogger;
import org.open4goods.model.data.DataFragment;
import org.open4goods.model.product.Product;
import org.slf4j.Logger;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
package org.open4goods.aggregation;

import java.io.Closeable;
import java.io.IOException;
import java.util.Collection;
import java.util.Set;

import org.open4goods.exceptions.AggregationSkipException;
import org.open4goods.helper.GenericFileLogger;
import org.open4goods.model.data.DataFragment;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import java.util.List;

import org.open4goods.aggregation.AbstractAggregationService;
import org.open4goods.aggregation.AbstractBatchAggregationService;
import org.open4goods.aggregation.AbstractRealTimeAggregationService;
import org.open4goods.exceptions.AggregationSkipException;
import org.open4goods.model.data.DataFragment;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,5 @@
package org.open4goods.aggregation.services.aggregation;

import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import java.util.stream.Collectors;

import org.apache.commons.lang3.StringUtils;
import org.open4goods.aggregation.AbstractRealTimeAggregationService;
import org.open4goods.config.yml.attributes.AttributeConfig;
Expand All @@ -28,6 +18,10 @@
import org.open4goods.services.BrandService;
import org.open4goods.services.VerticalsConfigService;

import java.util.*;
import java.util.Map.Entry;
import java.util.stream.Collectors;

public class AttributeRealtimeAggregationService extends AbstractRealTimeAggregationService {


Expand Down Expand Up @@ -55,9 +49,8 @@ public void onDataFragment(final DataFragment dataFragment, final Product produc

AttributesConfig attributesConfig = verticalConfigService.getConfigById(product.getVertical() == null ? "all" : product.getVertical() ).get().getAttributesConfig() ;

Set<String> toRemoveFromUnmatched = new HashSet<>();
// Adding the list of "to be removed" attributes
toRemoveFromUnmatched.addAll(attributesConfig.getExclusions());
// Adding the list of "to be removed" attributes
Set<String> toRemoveFromUnmatched = new HashSet<>(attributesConfig.getExclusions());

/////////////////////////////////////////
// Converting to AggregatedAttributes for matches from config
Expand Down Expand Up @@ -100,7 +93,7 @@ public void onDataFragment(final DataFragment dataFragment, final Product produc


toRemoveFromUnmatched.add(translated.getName());
agg.addAttribute(translated,attrConfig, new UnindexedKeyValTimestamp(dataFragment.getDatasourceName(), translated.getValue().toString()));
agg.addAttribute(translated,attrConfig, new UnindexedKeyValTimestamp(dataFragment.getDatasourceName(), translated.getValue()));

// Replacing new AggAttribute in product
product.getAttributes().getAggregatedAttributes().put(agg.getName(), agg);
Expand All @@ -126,7 +119,7 @@ public void onDataFragment(final DataFragment dataFragment, final Product produc
.filter(e -> isFeatureAttribute(e, attributesConfig))
.collect(Collectors.toList());

toRemoveFromUnmatched.addAll(matchedFeatures.stream().map(e->e.getName()).collect(Collectors.toSet()));
toRemoveFromUnmatched.addAll(matchedFeatures.stream().map(Attribute::getName).collect(Collectors.toSet()));


Collection<AggregatedFeature> af = aggregateFeatures(matchedFeatures);
Expand All @@ -153,7 +146,7 @@ public void onDataFragment(final DataFragment dataFragment, final Product produc
agg = new AggregatedAttribute();
agg.setName(attr.getName());
}
agg.addAttribute(attr, new UnindexedKeyValTimestamp(dataFragment.getDatasourceName(), attr.getValue().toString()));
agg.addAttribute(attr, new UnindexedKeyValTimestamp(dataFragment.getDatasourceName(), attr.getValue()));

product.getAttributes().getUnmapedAttributes().add(agg);
}
Expand Down Expand Up @@ -357,7 +350,7 @@ private Collection<AggregatedFeature> aggregateFeatures(List<Attribute> matchedF
* @return
*/
private boolean isFeatureAttribute(Attribute e, AttributesConfig attributesConfig) {
return attributesConfig.getFeaturedValues().contains(e.getRawValue().toString().trim().toUpperCase());
return attributesConfig.getFeaturedValues().contains(e.getRawValue().trim().toUpperCase());
}

/**
Expand Down Expand Up @@ -501,7 +494,7 @@ public Attribute parseAttributeValue(final Attribute attr, final AttributeConfig
boolean found = false;


final String val = attr.getRawValue().toString();
final String val = attr.getRawValue();
for (final String match : conf.getParser().getTokenMatch()) {
if (val.contains(match)) {
attr.setRawValue(match);
Expand Down Expand Up @@ -544,7 +537,7 @@ public Attribute parseAttributeValue(final Attribute attr, final AttributeConfig
if (!StringUtils.isEmpty(conf.getParser().getClazz())) {
try {
final AttributeParser parser = conf.getParserInstance();
final String parserRes = parser.parse(attr.getRawValue().toString(), attr, conf);
final String parserRes = parser.parse(attr.getRawValue(), attr, conf);
attr.setRawValue(parserRes);
} catch (final ResourceNotFoundException e) {
dedicatedLogger.warn("Error while applying specific parser for {}", conf.getParser().getClazz(), e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import java.util.HashMap;
import java.util.Map;

import org.open4goods.aggregation.AbstractAggregationService;
import org.open4goods.aggregation.AbstractBatchAggregationService;
import org.open4goods.exceptions.ValidationException;
import org.open4goods.model.attribute.Cardinality;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public Double generateScoresFromAttribute(String attributeKey , AggregatedAttrib

if (ac.getType().equals(AttributeType.NUMERIC)) {
try {
return Double.valueOf(a.getValue().toString());
return Double.valueOf(a.getValue());
} catch (Exception e) {
throw new ValidationException("Cannot convert to numeric" +a);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public void onProduct(Product data) {
// TODO : complete with real datas
private Double generateScoreFromBrand(String brand) {

Double s;
double s;

switch (brand) {
case "SAMSUNG" -> s = 5.0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public void onProduct(Product data) {
private Double generateEcoScore(Map<String, Score> scores) throws ValidationException {


Double va = 0.0;
double va = 0.0;
for (String config : ecoScoreconfig.keySet()) {
Score score = scores.get(config);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

import java.util.AbstractMap.SimpleEntry;

import org.open4goods.aggregation.AbstractAggregationService;
import org.open4goods.aggregation.AbstractRealTimeAggregationService;
import org.open4goods.exceptions.AggregationSkipException;
import org.open4goods.model.BarcodeType;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import org.apache.commons.lang3.StringUtils;
import org.jsoup.Jsoup;
import org.open4goods.aggregation.AbstractAggregationService;
import org.open4goods.aggregation.AbstractRealTimeAggregationService;
import org.open4goods.config.yml.ui.DescriptionsAggregationConfig;
import org.open4goods.model.data.DataFragment;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import java.io.IOException;

import org.open4goods.aggregation.AbstractAggregationService;
import org.open4goods.aggregation.AbstractRealTimeAggregationService;
import org.open4goods.config.yml.ui.VerticalConfig;
import org.open4goods.helper.IdHelper;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,11 @@
import java.util.stream.Collectors;

import org.apache.commons.lang3.StringUtils;
import org.open4goods.aggregation.AbstractAggregationService;
import org.open4goods.aggregation.AbstractRealTimeAggregationService;
import org.open4goods.config.yml.ui.SiteNaming;
import org.open4goods.helper.IdHelper;
import org.open4goods.model.data.DataFragment;
import org.open4goods.model.product.Names;
import org.open4goods.model.product.Product;
import org.open4goods.services.EvaluationService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -74,7 +71,7 @@ private String computeProductName(Names names, String gtin) {
return gtin;
}
else {
String frags[] = names.shortestOfferName().split(" ");
String[] frags = names.shortestOfferName().split(" ");

int maxchars = 70;
int curChars = 0;
Expand Down Expand Up @@ -117,7 +114,7 @@ private String normalizeName(String name) {

String normalized = StringUtils.normalizeSpace(name.toLowerCase());

String frags[] = normalized.split(" ");
String[] frags = normalized.split(" ");

LinkedHashSet<String> linkedHashSet = new LinkedHashSet<>();
StringBuilder ret = new StringBuilder();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,7 @@
package org.open4goods.aggregation.services.aggregation.realtime;

import java.io.IOException;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import java.util.stream.Collectors;
import java.util.*;

import org.open4goods.aggregation.AbstractRealTimeAggregationService;
import org.open4goods.config.yml.ui.VerticalProperties;
Expand Down Expand Up @@ -82,7 +76,7 @@ public void onDataFragment(final DataFragment e, final Product aggregatedData) {
}
}

final Set<AggregatedPrice> filtered = reducedPrices.values().stream().collect(Collectors.toSet());
final Set<AggregatedPrice> filtered = new HashSet<>(reducedPrices.values());

////////////////////////////
// Computing the compensation
Expand Down Expand Up @@ -123,9 +117,7 @@ public void onDataFragment(final DataFragment e, final Product aggregatedData) {


// Setting the product state summary
aggPrices.getOffers().stream().forEach(i -> {
aggPrices.getConditions().add(i.getProductState());
});
aggPrices.getOffers().forEach(i -> aggPrices.getConditions().add(i.getProductState()));

// Setting the result
aggregatedData.setPrice(aggPrices);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
package org.open4goods.aggregation.services.aggregation.realtime;

import java.util.Set;

import org.apache.commons.lang3.StringUtils;
import org.open4goods.aggregation.AbstractAggregationService;
import org.open4goods.aggregation.AbstractRealTimeAggregationService;
import org.open4goods.config.yml.ui.VerticalConfig;
import org.open4goods.model.data.DataFragment;
Expand Down
3 changes: 0 additions & 3 deletions api/src/main/java/org/open4goods/api/Api.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,8 @@

import java.io.IOException;

import org.apache.commons.math3.stat.descriptive.summary.Product;
import org.open4goods.crawler.controller.CrawlController;
import org.open4goods.crawler.repository.IndexationRepository;
import org.open4goods.dao.ProductRepository;
import org.open4goods.services.SerialisationService;
import org.open4goods.store.repository.ProductSpringRepository;
import org.slf4j.Logger;
Expand All @@ -15,7 +13,6 @@
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.context.annotation.EnableAspectJAutoProxy;
import org.springframework.data.elasticsearch.repository.config.EnableElasticsearchRepositories;
import org.springframework.scheduling.annotation.EnableScheduling;

Expand Down
29 changes: 10 additions & 19 deletions api/src/main/java/org/open4goods/api/config/ApiConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -112,12 +112,9 @@ BrandService brandService(@Autowired RemoteFileCachingService rfc, @Autowired A
@Autowired
BatchService batchService(SearchService searchService, ProductRepository dataRepository, VerticalsConfigService verticalsConfigService, BatchAggregationService batchAggregationService) throws IOException {
// Logging to console according to dev profile and conf
boolean toConsole = false;
boolean toConsole = ArrayUtils.contains(env.getActiveProfiles(), "dev") || ArrayUtils.contains(env.getActiveProfiles(), "devsec");
// TODO : Not nice, mutualize
if (ArrayUtils.contains(env.getActiveProfiles(), "dev") || ArrayUtils.contains(env.getActiveProfiles(), "devsec")) {
toConsole = true;
}
return new BatchService(dataRepository, apiProperties, verticalsConfigService,batchAggregationService, searchService, toConsole);
return new BatchService(dataRepository, apiProperties, verticalsConfigService,batchAggregationService, searchService, toConsole);
}


Expand Down Expand Up @@ -340,14 +337,11 @@ CsvDatasourceFetchingService csvDatasourceFetchingService(

) {

boolean toConsole = false;
boolean toConsole = ArrayUtils.contains(env.getActiveProfiles(), "dev") || ArrayUtils.contains(env.getActiveProfiles(), "devsec");
// TODO : Not nice, mutualize
if (ArrayUtils.contains(env.getActiveProfiles(), "dev") || ArrayUtils.contains(env.getActiveProfiles(), "devsec")) {
toConsole = true;
}


return new CsvDatasourceFetchingService(completionService, indexationService,


return new CsvDatasourceFetchingService(completionService, indexationService,
apiProperties.getFetcherProperties(), webDatasourceFetchingService,indexationRepository, apiProperties.logsFolder(), toConsole);
}

Expand All @@ -356,14 +350,11 @@ WebDatasourceFetchingService webDatasourceFetchingService(@Autowired final Index
@Autowired final IndexationService indexationService, @Autowired final ApiProperties apiProperties) {

// Logging to console according to dev profile and conf
boolean toConsole = false;
boolean toConsole = ArrayUtils.contains(env.getActiveProfiles(), "dev") || ArrayUtils.contains(env.getActiveProfiles(), "devsec");
// TODO : Not nice, mutualize
if (ArrayUtils.contains(env.getActiveProfiles(), "dev") || ArrayUtils.contains(env.getActiveProfiles(), "devsec")) {
toConsole = true;
}


return new WebDatasourceFetchingService(indexationService, apiProperties.getFetcherProperties(),indexationRepository,


return new WebDatasourceFetchingService(indexationService, apiProperties.getFetcherProperties(),indexationRepository,
apiProperties.logsFolder(), toConsole);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity;
import org.springframework.security.config.annotation.method.configuration.EnableMethodSecurity;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
Expand All @@ -34,7 +33,11 @@
@EnableMethodSecurity(prePostEnabled = true)
public class WebSecurityConfig {

private @Autowired ApiProperties apiProperties;
private final ApiProperties apiProperties;

public WebSecurityConfig(ApiProperties apiProperties) {
this.apiProperties = apiProperties;
}

@Bean
public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
import org.open4goods.model.constants.RolesConstants;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import org.open4goods.model.dto.FetchRequestResponse;
import org.open4goods.services.DataSourceConfigService;
import org.open4goods.services.SerialisationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
Expand Down
Loading

0 comments on commit 04bf762

Please sign in to comment.