Skip to content

Commit

Permalink
BrandScore layout
Browse files Browse the repository at this point in the history
  • Loading branch information
Goulven.Furet authored and Goulven.Furet committed Jun 1, 2024
1 parent c10d8f4 commit 4fbcfa5
Show file tree
Hide file tree
Showing 7 changed files with 65 additions and 12 deletions.
4 changes: 2 additions & 2 deletions api/src/main/java/org/open4goods/api/config/ApiConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -491,8 +491,8 @@ FetcherOrchestrationService fetcherOrchestrationService(TaskScheduler taskSchedu
}

@Bean
DataFragmentCompletionService offerCompletionService() {
return new DataFragmentCompletionService();
DataFragmentCompletionService offerCompletionService(@Autowired BrandService brandService) {
return new DataFragmentCompletionService(brandService);
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import org.open4goods.model.constants.Currency;
import org.open4goods.model.data.DataFragment;
import org.open4goods.model.data.Price;
import org.open4goods.services.BrandService;
import org.open4goods.services.DataSourceConfigService;
import org.open4goods.services.EvaluationService;
import org.open4goods.services.ImageMagickService;
Expand Down Expand Up @@ -150,8 +151,13 @@ DataSourceConfigService datasourceConfigService(@Autowired final ApiProperties c
}

@Bean
DataFragmentCompletionService offerCompletionService() {
return new DataFragmentCompletionService();
BrandService brandService() {
return new BrandService(null, null);
}

@Bean
DataFragmentCompletionService offerCompletionService(@Autowired BrandService brandService) {
return new DataFragmentCompletionService(brandService);
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,15 @@ public class DataSourceProperties {
private String portalUrl;


/**
* If true, will be computed as a brand score
*/
private boolean brandScore = false;





/**
* The percent of reversement for the provider
*/
Expand Down Expand Up @@ -555,6 +563,14 @@ public void setDatasourceConfigName(String datasourceConfigName) {
this.datasourceConfigName = datasourceConfigName;
}

public boolean isBrandScore() {
return brandScore;
}

public void setBrandScore(boolean brandScore) {
this.brandScore = brandScore;
}




Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.StringUtils;
import org.open4goods.config.BrandConfiguration;
import org.open4goods.config.yml.datasource.DataSourceProperties;
import org.open4goods.exceptions.InvalidParameterException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -107,6 +108,12 @@ public InputStream getLogo(String brand) throws InvalidParameterException, File
// remoteFileCachingService.
return IOUtils.toBufferedInputStream(new FileInputStream(f));
}

public void addBrandScore(String brand, DataSourceProperties datasourceProperties, String rawValue) {
// TODO Auto-generated method stub
System.out.println("TODO");
}



}
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,7 @@ public CrawlerConfig(Environment env) {
}


@Bean
DataFragmentCompletionService offerCompletionService(@Autowired final FetcherProperties fetcherProperties) {
return new DataFragmentCompletionService();
}



// @Bean
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import org.open4goods.model.constants.ReferentielKey;
import org.open4goods.model.data.DataFragment;
import org.open4goods.model.data.ProviderSupportType;
import org.open4goods.services.BrandService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand All @@ -29,6 +30,14 @@ public class DataFragmentCompletionService {


private static final Logger LOGGER = LoggerFactory.getLogger(DataFragmentCompletionService.class);
private BrandService brandService;


public DataFragmentCompletionService(BrandService brandService) {
this.brandService = brandService;
}




/**
Expand Down Expand Up @@ -108,7 +117,27 @@ public void complete(final DataFragment o, final String datasourceConfigName, fi
o.setProductState(datasourceProperties.getDefaultItemCondition());
}
}


////////////////////////////////
// Special hook for brand score handlings.
// Not the better way, but this is the central point.
// specific service are triggered here, the datafragment will after classicaly fail because of no gtin, and will be discarded of products
// *pipeline*
///////////////////////////////

if (datasourceProperties.isBrandScore()) {
Attribute score = o.getAttributes().stream().filter(e-> e.getName().equals("SCORE")).findFirst().get();
if (null != score) {
LOGGER.info("Found a brand score for brand {} : {}",o.brand(),score.getRawValue());
brandService.addBrandScore(o.brand(), datasourceProperties, score.getRawValue());
} else {
LOGGER.warn("Empty brand score found for brand {} ",o.brand());
}




}
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,12 +83,10 @@ public class CsvIndexationWorker implements Runnable {

private final CsvIndexationRepository csvIndexationRepository;




/** The duration of the worker thread pause when nothing to get from the queue **/
private final int pauseDuration;


private String logsFolder;


Expand Down

0 comments on commit 4fbcfa5

Please sign in to comment.