Skip to content

Commit

Permalink
Adding sustainalytics company url
Browse files Browse the repository at this point in the history
  • Loading branch information
goulven authored and goulven committed Dec 9, 2024
1 parent 9249f00 commit 62aa991
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ public class SustainalyticsAggregationService extends AbstractScoreAggregationSe

public static final String RISK_LEVEL = "risk-level";

public static final String COMPANY_URL = "url";

private BrandService brandService;

private BrandScoreService brandScoreService;
Expand Down Expand Up @@ -74,7 +76,9 @@ public void onProduct(Product data, VerticalConfig vConf) {
Map<String, String> metadatas = new HashMap<>();
metadatas.put(RATING, brandResult.getScoreValue());
metadatas.put(RISK_LEVEL, getRiskLevel(brandResult));
metadatas.put(COMPANY_URL, brandResult.getUrl());

s.setMetadatas(metadatas);
// Saving in product
data.getScores().put(s.getName(),s);
} catch (Exception e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,18 @@ public class BrandScore {

@Field(index = true, store = false, type = FieldType.Keyword)
private Set<String> tags = new HashSet<>();

@Field(index = true, store = false, type = FieldType.Keyword)
private String url;

public BrandScore(DataSourceProperties datasourceProperties, String brandName, String scoreValue) {
public BrandScore(DataSourceProperties datasourceProperties, String brandName, String scoreValue, String url) {
super();
this.datasourceName = datasourceProperties.getName();
this.brandName = brandName.toLowerCase().trim();
this.id=id(datasourceProperties.getName(), brandName);
this.lastUpdate = System.currentTimeMillis();
this.scoreValue = scoreValue;
this.url = url;

try {
Double norm;
Expand Down Expand Up @@ -146,6 +150,16 @@ public Double getNormalized() {
public void setNormalized(Double normalized) {
this.normalized = normalized;
}


public String getUrl() {
return url;
}


public void setUrl(String url) {
this.url = url;
}



Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,9 @@ public BrandScoreService( BrandScoresRepository brandRepository, String logsFol
* @param brand
* @param datasourceProperties
* @param scoreValue
* @param url
*/
public void addBrandScore(String brand, DataSourceProperties datasourceProperties, String scoreValue) {
public void addBrandScore(String brand, DataSourceProperties datasourceProperties, String scoreValue, String url) {

if (StringUtils.isEmpty(brand) || StringUtils.isEmpty(scoreValue)) {
logger.info("Cannot proceed empty brand or score, skipping");
Expand All @@ -58,7 +59,7 @@ public void addBrandScore(String brand, DataSourceProperties datasourcePropertie

logger.info("Adding brand score {}:{} for brand {}", datasourceProperties.getName(), scoreValue, brand);

BrandScore brandScore = new BrandScore(datasourceProperties, brand, scoreValue);
BrandScore brandScore = new BrandScore(datasourceProperties, brand, scoreValue, url);



Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ public void complete(final DataFragment o, final String datasourceConfigName, fi
Attribute score = o.getAttributes().stream().filter(e-> e.getName().equals("SCORE")).findFirst().orElse(null);
if (null != score) {
LOGGER.info("Found a brand score for brand {} : {}",o.brand(),score.getRawValue());
brandService.addBrandScore(o.brand(), datasourceProperties, score.getRawValue());
brandService.addBrandScore(o.brand(), datasourceProperties, score.getRawValue(), o.affiliatedUrlIfPossible());
} else {
LOGGER.warn("Empty brand score found for brand {} ",o.brand());
}
Expand Down

0 comments on commit 62aa991

Please sign in to comment.