From 88309365de2388ae039e8b4f8e69dcf043ec9f9e Mon Sep 17 00:00:00 2001 From: Akayeshmantha Date: Thu, 11 Jul 2019 16:19:16 +0200 Subject: [PATCH 01/30] Add index identification url to trust. --- src/main/resources/bootstrap.yml | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/main/resources/bootstrap.yml b/src/main/resources/bootstrap.yml index 5bf5339..8995449 100644 --- a/src/main/resources/bootstrap.yml +++ b/src/main/resources/bootstrap.yml @@ -43,23 +43,25 @@ logstash: nimble: identity: - url: ${IDENTITY_SERVICE_URL:http://nimble-staging.salzburgresearch.at/identity-v2} + url: ${IDENTITY_SERVICE_URL:http://nimble-staging.salzburgresearch.at/identity} trust: url: ${TRUST_SERVICE_URL:http://nimble-staging.salzburgresearch.at/trust} catalog: url: ${CATALOG_SERVICE_URL:http://nimble-staging.salzburgresearch.at/catalog} business-process: url: ${BUSINESS_PROCESS_SERVICE_URL:http://nimble-staging.salzburgresearch.at/business-process} + indexing: + url: ${INDEXING_SERVICE_URL:http://nimble-staging.salzburgresearch.at/index} kafka: topics: - companyUpdates: ${KAFKA_TOPIC_COMPANY_UPDATES:company-updates} - trustScoreUpdates: ${KAFKA_TOPIC_TRUST_SCORE_UPDATES:trust-score-updates} - ratingsUpdates: ${KAFKA_TOPIC_BUSINESS_PROCESS_UPDATES:business-process-updates} + companyUpdates: ${KAFKA_TOPIC_COMPANY_UPDATES:company-updates-staging} + trustScoreUpdates: ${KAFKA_TOPIC_TRUST_SCORE_UPDATES:trust-score-updates-staging} + ratingsUpdates: ${KAFKA_TOPIC_BUSINESS_PROCESS_UPDATES:business-process-updates-staging} -# + #feign: # client: # config: # default: # connectTimeout: 10000 -# readTimeout: 10000 \ No newline at end of file +# readTimeout: 10000 From bdc6146562afd2ece74703c755c1cf99b68be8bd Mon Sep 17 00:00:00 2001 From: Akayeshmantha Date: Thu, 11 Jul 2019 16:19:39 +0200 Subject: [PATCH 02/30] Adding feign fallback client. --- .../restclient/IndexingClientFallback.java | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 src/main/java/nimble/trust/engine/restclient/IndexingClientFallback.java diff --git a/src/main/java/nimble/trust/engine/restclient/IndexingClientFallback.java b/src/main/java/nimble/trust/engine/restclient/IndexingClientFallback.java new file mode 100644 index 0000000..6e19424 --- /dev/null +++ b/src/main/java/nimble/trust/engine/restclient/IndexingClientFallback.java @@ -0,0 +1,28 @@ +package nimble.trust.engine.restclient; + +import eu.nimble.service.model.solr.party.PartyType; + +import org.springframework.stereotype.Component; + +/** + * + * @author Ayeshmantha Perera + */ +@Component +public class IndexingClientFallback implements IndexingClient { + + @Override + public Boolean setParty(PartyType party) { + return false; + } + + @Override + public PartyType getParty(String uri) { + return null; + } + + @Override + public Boolean deleteParty(PartyType party) { + return false; + } +} From be47c620dee3296934351a0fcb1074e29cfab7b3 Mon Sep 17 00:00:00 2001 From: Akayeshmantha Date: Thu, 11 Jul 2019 16:19:57 +0200 Subject: [PATCH 03/30] Adding indexing client. --- .../engine/restclient/IndexingClient.java | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 src/main/java/nimble/trust/engine/restclient/IndexingClient.java diff --git a/src/main/java/nimble/trust/engine/restclient/IndexingClient.java b/src/main/java/nimble/trust/engine/restclient/IndexingClient.java new file mode 100644 index 0000000..89484d1 --- /dev/null +++ b/src/main/java/nimble/trust/engine/restclient/IndexingClient.java @@ -0,0 +1,29 @@ +package nimble.trust.engine.restclient; + +import eu.nimble.service.model.solr.party.PartyType; +import feign.Headers; +import org.springframework.cloud.netflix.feign.FeignClient; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestParam; + +/** + * REST Client to index entities via the Indexing Service. + * + * @author Ayeshmantha Perera + */ +@FeignClient(name = "indexing-service", url = "${nimble.indexing.url}", fallback = IndexingClientFallback.class) +public interface IndexingClient { + @RequestMapping(method = RequestMethod.PUT, value = "/party", consumes = "application/json") + @Headers("Content-Type: application/json") + Boolean setParty(@RequestBody PartyType party); + + @RequestMapping(method = RequestMethod.GET, value = "/party") + PartyType getParty(@RequestParam(value = "uri") String uri); + + @RequestMapping(method = RequestMethod.DELETE, value = "/party") + Boolean deleteParty(@RequestBody PartyType party); + + +} From 0507877752dcd66b1f73efac68f8c84ab481a039 Mon Sep 17 00:00:00 2001 From: Akayeshmantha Date: Thu, 11 Jul 2019 16:20:37 +0200 Subject: [PATCH 04/30] Trust score update to solr. --- .../service/TrustCalculationService.java | 275 ++++++++++-------- 1 file changed, 153 insertions(+), 122 deletions(-) diff --git a/src/main/java/nimble/trust/engine/service/TrustCalculationService.java b/src/main/java/nimble/trust/engine/service/TrustCalculationService.java index e3d9fcf..4990f22 100644 --- a/src/main/java/nimble/trust/engine/service/TrustCalculationService.java +++ b/src/main/java/nimble/trust/engine/service/TrustCalculationService.java @@ -1,122 +1,153 @@ -package nimble.trust.engine.service; - -import java.net.URI; -import java.util.List; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Value; -import org.springframework.data.domain.Page; -import org.springframework.data.domain.PageRequest; -import org.springframework.http.HttpStatus; -import org.springframework.scheduling.annotation.Async; -import org.springframework.security.core.context.SecurityContextHolder; -import org.springframework.stereotype.Service; - -import com.fasterxml.jackson.core.type.TypeReference; -import com.google.common.collect.Lists; - -import eu.nimble.utility.JsonSerializationUtility; -import nimble.trust.engine.collector.ProfileCompletnessCollector; -import nimble.trust.engine.domain.Agent; -import nimble.trust.engine.domain.TrustPolicy; -import nimble.trust.engine.model.pojo.TrustCriteria; -import nimble.trust.engine.model.vocabulary.Trust; -import nimble.trust.engine.module.Factory; -import nimble.trust.engine.restclient.IdentityServiceClient; -import nimble.trust.engine.service.interfaces.TrustSimpleManager; -import nimble.trust.engine.util.PolicyConverter; -import nimble.trust.web.dto.IdentifierNameTuple; - -@Service -public class TrustCalculationService { - - private static Logger log = LoggerFactory.getLogger(TrustCalculationService.class); - - @Autowired - private TrustScoreSync trustScoreSync; - - @Autowired - private TrustPolicyService trustPolicyService; - - @Autowired - private AgentService agentService; - - @Autowired - private IdentityServiceClient identityServiceClient; - -// @Autowired -// private ProfileCompletnessCollector completnessCollector; - - - @Value("${app.trust.trustScore.syncWithCatalogService}") - private Boolean syncWithCatalogService; - - public void score(String partyId) { - // get profile and policy and calculate; - final TrustSimpleManager trustManager = Factory.createInstance(TrustSimpleManager.class); - TrustPolicy trustPolicy = trustPolicyService.findGlobalTRustPolicy(); - TrustCriteria criteria = PolicyConverter.fromPolicyToCriteria(trustPolicy); - Double trustScore = null; - try { - trustScore = trustManager.obtainTrustIndex(URI.create(Trust.getURI() + partyId), criteria); - - agentService.updateTrustScore(partyId, trustScore); - - if (syncWithCatalogService) { - trustScoreSync.syncWithCatalogService(partyId); - } - log.info("trust score of party with ID " + partyId + " is updated to " + trustScore); - } catch (Exception e) { - log.error("Exception", e); - } - } - - /** - * - */ - @Async - public void scoreBatch() { - int pageNumber = 0; - int pageLimit = 100; - Page page; - do { - page = agentService.findAll(new PageRequest(pageNumber, pageLimit)); - pageNumber++; - List list = page.getContent(); - for (Agent agent : list) { - score(agent.getAltId()); - } - } while (!page.isLast()); - } - - /** - * - */ - @Async - public void createAllAndScoreBatch() { - - final String bearerToken = SecurityContextHolder.getContext().getAuthentication().getPrincipal().toString(); - - try { - feign.Response response = identityServiceClient.getAllPartyIds(bearerToken, Lists.newArrayList()); - if (response.status() == HttpStatus.OK.value()) { - List tuples = JsonSerializationUtility.deserializeContent( - response.body().asInputStream(), new TypeReference>() { - }); - for (IdentifierNameTuple t : tuples) { -// completnessCollector.fetchProfileCompletnessValues(t.getIdentifier(), true); -// trustScoreSync.syncWithCatalogService(t.getIdentifier()); - - } - } else { - log.info("GetAllPartyIds request to identity service failed due: " - + new feign.codec.StringDecoder().decode(response, String.class)); - } - } catch (Exception e) { - log.error("CreateAllAndScoreBatch failed or internal error happened", e); - } - } - -} +package nimble.trust.engine.service; + +import java.net.URI; +import java.util.List; + +import eu.nimble.service.model.ubl.commonaggregatecomponents.PartyType; +import eu.nimble.service.model.ubl.extension.QualityIndicatorParameter; +import nimble.trust.engine.restclient.IndexingClient; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.PageRequest; +import org.springframework.http.HttpStatus; +import org.springframework.scheduling.annotation.Async; +import org.springframework.security.core.context.SecurityContextHolder; +import org.springframework.stereotype.Service; + +import com.fasterxml.jackson.core.type.TypeReference; +import com.google.common.collect.Lists; + +import eu.nimble.utility.JsonSerializationUtility; +import nimble.trust.engine.collector.ProfileCompletnessCollector; +import nimble.trust.engine.domain.Agent; +import nimble.trust.engine.domain.TrustPolicy; +import nimble.trust.engine.model.pojo.TrustCriteria; +import nimble.trust.engine.model.vocabulary.Trust; +import nimble.trust.engine.module.Factory; +import nimble.trust.engine.restclient.IdentityServiceClient; +import nimble.trust.engine.service.interfaces.TrustSimpleManager; +import nimble.trust.engine.util.PolicyConverter; +import nimble.trust.web.dto.IdentifierNameTuple; + +@Service +public class TrustCalculationService { + + private static Logger log = LoggerFactory.getLogger(TrustCalculationService.class); + + @Autowired + private TrustScoreSync trustScoreSync; + + @Autowired + private TrustPolicyService trustPolicyService; + + @Autowired + private AgentService agentService; + + @Autowired + private IdentityServiceClient identityServiceClient; + + @Autowired + private IndexingClient indexingClient; + + @Autowired + private TrustProfileService trustProfileService; +// @Autowired +// private ProfileCompletnessCollector completnessCollector; + + + @Value("${app.trust.trustScore.syncWithCatalogService}") + private Boolean syncWithCatalogService; + + public void score(String partyId) { + // get profile and policy and calculate; + final TrustSimpleManager trustManager = Factory.createInstance(TrustSimpleManager.class); + TrustPolicy trustPolicy = trustPolicyService.findGlobalTRustPolicy(); + TrustCriteria criteria = PolicyConverter.fromPolicyToCriteria(trustPolicy); + Double trustScore = null; + try { + trustScore = trustManager.obtainTrustIndex(URI.create(Trust.getURI() + partyId), criteria); + + agentService.updateTrustScore(partyId, trustScore); + + if (syncWithCatalogService) { + PartyType partyType = trustProfileService.createPartyType(partyId); + eu.nimble.service.model.solr.party.PartyType indexParty = indexingClient.getParty(partyId); + + // get trust scores + partyType.getQualityIndicator().forEach(qualityIndicator -> { + if(qualityIndicator.getQualityParameter() != null && qualityIndicator.getQuantity() != null) { + if(qualityIndicator.getQualityParameter().contentEquals(QualityIndicatorParameter.COMPANY_RATING.toString())) { + indexParty.setTrustRating(qualityIndicator.getQuantity().getValue().doubleValue()); + } else if(qualityIndicator.getQualityParameter().contentEquals(QualityIndicatorParameter.TRUST_SCORE.toString())) { + indexParty.setTrustScore(qualityIndicator.getQuantity().getValue().doubleValue()); + } else if(qualityIndicator.getQualityParameter().contentEquals(QualityIndicatorParameter.DELIVERY_PACKAGING.toString())) { + indexParty.setTrustDeliveryPackaging(qualityIndicator.getQuantity().getValue().doubleValue()); + } else if(qualityIndicator.getQualityParameter().contentEquals(QualityIndicatorParameter.FULFILLMENT_OF_TERMS.toString())) { + indexParty.setTrustFullfillmentOfTerms(qualityIndicator.getQuantity().getValue().doubleValue()); + } else if(qualityIndicator.getQualityParameter().contentEquals(QualityIndicatorParameter.SELLER_COMMUNICATION.toString())) { + indexParty.setTrustSellerCommunication(qualityIndicator.getQuantity().getValue().doubleValue()); + } else if(qualityIndicator.getQualityParameter().contentEquals(QualityIndicatorParameter.NUMBER_OF_TRANSACTIONS.toString())) { + indexParty.setTrustNumberOfTransactions(qualityIndicator.getQuantity().getValue().doubleValue()); + } else if(qualityIndicator.getQualityParameter().contentEquals(QualityIndicatorParameter.TRADING_VOLUME.toString())) { + indexParty.setTrustTradingVolume(qualityIndicator.getQuantity().getValue().doubleValue()); + } + } + }); + indexingClient.setParty(indexParty); + } + log.info("trust score of party with ID " + partyId + " is updated to " + trustScore); + } catch (Exception e) { + log.error("Exception", e); + } + } + + /** + * + */ + @Async + public void scoreBatch() { + int pageNumber = 0; + int pageLimit = 100; + Page page; + do { + page = agentService.findAll(new PageRequest(pageNumber, pageLimit)); + pageNumber++; + List list = page.getContent(); + for (Agent agent : list) { + score(agent.getAltId()); + } + } while (!page.isLast()); + } + + /** + * + */ + @Async + public void createAllAndScoreBatch() { + + final String bearerToken = SecurityContextHolder.getContext().getAuthentication().getPrincipal().toString(); + + try { + feign.Response response = identityServiceClient.getAllPartyIds(bearerToken, Lists.newArrayList()); + if (response.status() == HttpStatus.OK.value()) { + List tuples = JsonSerializationUtility.deserializeContent( + response.body().asInputStream(), new TypeReference>() { + }); + for (IdentifierNameTuple t : tuples) { +// completnessCollector.fetchProfileCompletnessValues(t.getIdentifier(), true); +// trustScoreSync.syncWithCatalogService(t.getIdentifier()); + + } + } else { + log.info("GetAllPartyIds request to identity service failed due: " + + new feign.codec.StringDecoder().decode(response, String.class)); + } + } catch (Exception e) { + log.error("CreateAllAndScoreBatch failed or internal error happened", e); + } + } + +} From 454f6cde9543098b717a27eb0a19a287ce508164 Mon Sep 17 00:00:00 2001 From: Akayeshmantha Date: Thu, 11 Jul 2019 16:25:25 +0200 Subject: [PATCH 05/30] Adding commons solr model as a maven dependency. --- pom.xml | 946 ++++++++++++++++++++++++++++---------------------------- 1 file changed, 479 insertions(+), 467 deletions(-) diff --git a/pom.xml b/pom.xml index aa3fdb0..91ff1cb 100644 --- a/pom.xml +++ b/pom.xml @@ -1,467 +1,479 @@ - - - - 4.0.0 - - eu.nimble.services - trust-service - 5.0.1 - Nimble Trust Scoring and Ranking Microservice - jar - - - UTF-8 - UTF-8 - 1.8 - ${java.version} - ${java.version} - 1.1.6 - - ${maven.build.timestamp} - yyyy-MM-dd HH:mm - 2.5.0 - nimble.trust - src/main/resources/api.yml - ${project.version} - 1.3.7.RELEASE - - - - org.springframework.boot - spring-boot-starter-parent - 1.4.1.RELEASE - - - - - vujasm - Marko at Innova - - - - - - - org.springframework.cloud - spring-cloud-dependencies - Camden.RELEASE - pom - import - - - - - - - org.springframework.cloud - spring-cloud-starter-eureka - - - javax.ws.rs - jsr311-api - - - - - org.springframework.cloud - spring-cloud-starter-hystrix - - - org.springframework.boot - spring-boot-starter-actuator - - - org.springframework.cloud - spring-cloud-starter-config - - - org.springframework.cloud - spring-cloud-starter-feign - - - org.springframework.cloud - spring-cloud-starter-sleuth - - - net.logstash.logback - logstash-logback-encoder - 4.7 - - - org.springframework.boot - spring-boot-starter-test - test - - - org.springframework.security - spring-security-test - test - - - org.springframework.boot - spring-boot-starter-security - compile - - - org.springframework.boot - spring-boot-starter-data-jpa - - - org.springframework.boot - spring-boot-starter-web - - - org.springframework.boot - spring-boot-starter-tomcat - - - - - - - io.springfox - springfox-swagger2 - ${springfox.version} - - - io.springfox - springfox-swagger-ui - ${springfox.version} - - - - com.fasterxml.jackson.datatype - jackson-datatype-joda - - - joda-time - joda-time - - - - org.postgresql - postgresql - - - - io.github.openfeign - feign-gson - 9.3.1 - - - - eu.nimble.core.common - utility - 0.0.1-SNAPSHOT - - - eu.nimble.core.common - rest-client - 0.0.1-SNAPSHOT - - - org.slf4j - slf4j-log4j12 - - - - - - eu.nimble.core.common - ubl-data-model - 0.0.1-SNAPSHOT - - - org.slf4j - slf4j-log4j12 - - - - - - org.projectlombok - lombok - compile - - - - - - - - org.apache.maven - maven-plugin-api - 2.0 - - - junit - junit - - test - - - com.fasterxml.jackson.core - jackson-databind - - - - xml-apis - xml-apis - - provided - - - xerces - xercesImpl - 2.9.1 - - - - - org.apache.httpcomponents - httpclient - - - - - org.glassfish.jersey.core - jersey-client - 2.15 - - - - org.glassfish.jersey.core - jersey-common - 2.15 - - - - - - org.apache.jena - apache-jena-libs - 2.11.0 - pom - - - xerces - xercesImpl - - - log4j - log4j - - - org.slf4j - slf4j-log4j12 - - - - - org.jgrapht - jgrapht-core - 0.9.1 - - - org.jgrapht - jgrapht-ext - 0.9.1 - - - - - - com.google.inject - guice - 3.0 - - - - com.google.inject.extensions - guice-assistedinject - 3.0 - - - - com.google.inject.extensions - guice-multibindings - 3.0 - - - - mysql - mysql-connector-java - - - - - - - - javax.ws.rs - javax.ws.rs-api - 2.0.1 - - - com.google.guava - guava - - - - - - com.github.sharispe - slib-sml - 0.9.1 - - - org.slf4j - slf4j-log4j12 - - - - - - - - - - org.springframework.kafka - spring-kafka - ${spring.kafka.version} - - - - - - - app - - - org.springframework.boot - spring-boot-maven-plugin - - nimble.trust.application.TrustApplication - - - - - repackage - - - - - - - io.swagger - swagger-codegen-maven-plugin - 2.2.1 - - - code - - generate - - - ${swagger.api.src} - spring - ${project.build.directory}/generated-sources/java - ${default.package}.swagger.model - ${default.package}.swagger.api - ${default.package}.swagger.invoker - - true - - - - - - doc - - generate - - - ${swagger.api.src} - html - - - - - - - - src/main/resources - - **/*.java - - - - ${project.build.directory}/generated-sources/java/src/main/java - - **/*.java - - - - - - - - docker - - 1.2.0 - nimbleplatform - ${project.version} - - - - - com.spotify - docker-maven-plugin - ${docker.plugin.version} - - - - build - - - - - ${docker.image.prefix}/${project.artifactId} - ${project.basedir}/src/main/docker - - ${project.build.finalName}.jar - - - - / - ${project.build.directory} - ${project.build.finalName}.jar - - - / - ${project.basedir}/src/main/docker - entrypoint.sh - - - - ${dockerImageTag} - - docker-hub - https://index.docker.io/v1/ - - - - - - - com.spotify - docker-maven-plugin - ${docker.plugin.version} - - - - - - \ No newline at end of file + + + + 4.0.0 + + eu.nimble.services + trust-service + 5.0.1 + Nimble Trust Scoring and Ranking Microservice + jar + + + UTF-8 + UTF-8 + 1.8 + ${java.version} + ${java.version} + 1.1.6 + + ${maven.build.timestamp} + yyyy-MM-dd HH:mm + 2.5.0 + nimble.trust + src/main/resources/api.yml + ${project.version} + 1.3.7.RELEASE + + + + org.springframework.boot + spring-boot-starter-parent + 1.4.1.RELEASE + + + + + vujasm + Marko at Innova + + + + + + + org.springframework.cloud + spring-cloud-dependencies + Camden.RELEASE + pom + import + + + + + + + org.springframework.cloud + spring-cloud-starter-eureka + + + javax.ws.rs + jsr311-api + + + + + org.springframework.cloud + spring-cloud-starter-hystrix + + + org.springframework.boot + spring-boot-starter-actuator + + + org.springframework.cloud + spring-cloud-starter-config + + + org.springframework.cloud + spring-cloud-starter-feign + + + org.springframework.cloud + spring-cloud-starter-sleuth + + + net.logstash.logback + logstash-logback-encoder + 4.7 + + + org.springframework.boot + spring-boot-starter-test + test + + + org.springframework.security + spring-security-test + test + + + org.springframework.boot + spring-boot-starter-security + compile + + + org.springframework.boot + spring-boot-starter-data-jpa + + + org.springframework.boot + spring-boot-starter-web + + + org.springframework.boot + spring-boot-starter-tomcat + + + + + + + io.springfox + springfox-swagger2 + ${springfox.version} + + + io.springfox + springfox-swagger-ui + ${springfox.version} + + + + com.fasterxml.jackson.datatype + jackson-datatype-joda + + + joda-time + joda-time + + + + org.postgresql + postgresql + + + + io.github.openfeign + feign-gson + 9.3.1 + + + + eu.nimble.core.common + utility + 0.0.1-SNAPSHOT + + + eu.nimble.core.common + rest-client + 0.0.1-SNAPSHOT + + + org.slf4j + slf4j-log4j12 + + + + + + eu.nimble.core.common + ubl-data-model + 0.0.1-SNAPSHOT + + + org.slf4j + slf4j-log4j12 + + + + + + eu.nimble.core.common + solr-data-model + 0.0.1-SNAPSHOT + + + org.slf4j + slf4j-log4j12 + + + + + + org.projectlombok + lombok + compile + + + + + + + + org.apache.maven + maven-plugin-api + 2.0 + + + junit + junit + + test + + + com.fasterxml.jackson.core + jackson-databind + + + + xml-apis + xml-apis + + provided + + + xerces + xercesImpl + 2.9.1 + + + + + org.apache.httpcomponents + httpclient + + + + + org.glassfish.jersey.core + jersey-client + 2.15 + + + + org.glassfish.jersey.core + jersey-common + 2.15 + + + + + + org.apache.jena + apache-jena-libs + 2.11.0 + pom + + + xerces + xercesImpl + + + log4j + log4j + + + org.slf4j + slf4j-log4j12 + + + + + org.jgrapht + jgrapht-core + 0.9.1 + + + org.jgrapht + jgrapht-ext + 0.9.1 + + + + + + com.google.inject + guice + 3.0 + + + + com.google.inject.extensions + guice-assistedinject + 3.0 + + + + com.google.inject.extensions + guice-multibindings + 3.0 + + + + mysql + mysql-connector-java + + + + + + + + javax.ws.rs + javax.ws.rs-api + 2.0.1 + + + com.google.guava + guava + + + + + + com.github.sharispe + slib-sml + 0.9.1 + + + org.slf4j + slf4j-log4j12 + + + + + + + + + + org.springframework.kafka + spring-kafka + ${spring.kafka.version} + + + + + + + app + + + org.springframework.boot + spring-boot-maven-plugin + + nimble.trust.application.TrustApplication + + + + + repackage + + + + + + + io.swagger + swagger-codegen-maven-plugin + 2.2.1 + + + code + + generate + + + ${swagger.api.src} + spring + ${project.build.directory}/generated-sources/java + ${default.package}.swagger.model + ${default.package}.swagger.api + ${default.package}.swagger.invoker + + true + + + + + + doc + + generate + + + ${swagger.api.src} + html + + + + + + + + src/main/resources + + **/*.java + + + + ${project.build.directory}/generated-sources/java/src/main/java + + **/*.java + + + + + + + + docker + + 1.2.0 + nimbleplatform + ${project.version} + + + + + com.spotify + docker-maven-plugin + ${docker.plugin.version} + + + + build + + + + + ${docker.image.prefix}/${project.artifactId} + ${project.basedir}/src/main/docker + + ${project.build.finalName}.jar + + + + / + ${project.build.directory} + ${project.build.finalName}.jar + + + / + ${project.basedir}/src/main/docker + entrypoint.sh + + + + ${dockerImageTag} + + docker-hub + https://index.docker.io/v1/ + + + + + + + com.spotify + docker-maven-plugin + ${docker.plugin.version} + + + + + + From 55852b23d086c96f8e3ba24ed49fe7fb75ddab3a Mon Sep 17 00:00:00 2001 From: Akayeshmantha Date: Thu, 11 Jul 2019 16:59:32 +0200 Subject: [PATCH 06/30] Extend hystrix timeout. --- src/main/resources/application.properties | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index 934c4bb..8c4cfc5 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -22,6 +22,6 @@ spring.jpa.generate-ddl=true spring.jpa.hibernate.ddl-auto=update ##hystrix timeout default is one second and that caused some issues when calling business-service -hystrix.command.default.execution.isolation.thread.timeoutInMilliseconds=5000 +hystrix.command.default.execution.isolation.thread.timeoutInMilliseconds=12000 -app.trust.trustScore.syncWithCatalogService=true \ No newline at end of file +app.trust.trustScore.syncWithCatalogService=true From 1c25163426ed1f60db3747fd97e06ab147595a86 Mon Sep 17 00:00:00 2001 From: Akayeshmantha Date: Wed, 31 Jul 2019 16:54:12 +0200 Subject: [PATCH 07/30] modify feign and fallback. --- .../nimble/trust/engine/restclient/IndexingClient.java | 10 +++++++--- .../engine/restclient/IndexingClientFallback.java | 6 +++--- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/src/main/java/nimble/trust/engine/restclient/IndexingClient.java b/src/main/java/nimble/trust/engine/restclient/IndexingClient.java index 89484d1..68a2f10 100644 --- a/src/main/java/nimble/trust/engine/restclient/IndexingClient.java +++ b/src/main/java/nimble/trust/engine/restclient/IndexingClient.java @@ -3,6 +3,7 @@ import eu.nimble.service.model.solr.party.PartyType; import feign.Headers; import org.springframework.cloud.netflix.feign.FeignClient; +import org.springframework.web.bind.annotation.RequestHeader; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RequestBody; @@ -17,13 +18,16 @@ public interface IndexingClient { @RequestMapping(method = RequestMethod.PUT, value = "/party", consumes = "application/json") @Headers("Content-Type: application/json") - Boolean setParty(@RequestBody PartyType party); + Boolean setParty(@RequestBody PartyType party, + @RequestHeader(value = "Authorization", required = true) String bearerToken); @RequestMapping(method = RequestMethod.GET, value = "/party") - PartyType getParty(@RequestParam(value = "uri") String uri); + PartyType getParty(@RequestParam(value = "uri") String uri, + @RequestHeader(value = "Authorization", required = true) String bearerToken); @RequestMapping(method = RequestMethod.DELETE, value = "/party") - Boolean deleteParty(@RequestBody PartyType party); + Boolean deleteParty(@RequestBody PartyType party, + @RequestHeader(value = "Authorization", required = true) String bearerToken); } diff --git a/src/main/java/nimble/trust/engine/restclient/IndexingClientFallback.java b/src/main/java/nimble/trust/engine/restclient/IndexingClientFallback.java index 6e19424..76a8cb9 100644 --- a/src/main/java/nimble/trust/engine/restclient/IndexingClientFallback.java +++ b/src/main/java/nimble/trust/engine/restclient/IndexingClientFallback.java @@ -12,17 +12,17 @@ public class IndexingClientFallback implements IndexingClient { @Override - public Boolean setParty(PartyType party) { + public Boolean setParty(PartyType party,String bearerToken) { return false; } @Override - public PartyType getParty(String uri) { + public PartyType getParty(String uri,String bearerToken) { return null; } @Override - public Boolean deleteParty(PartyType party) { + public Boolean deleteParty(PartyType party,String bearerToken) { return false; } } From cecca2d551c31a29799e7c1204ce8c950f1b94c1 Mon Sep 17 00:00:00 2001 From: Akayeshmantha Date: Wed, 31 Jul 2019 16:54:26 +0200 Subject: [PATCH 08/30] fix end points. --- .../trust/engine/service/TrustCalculationService.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/main/java/nimble/trust/engine/service/TrustCalculationService.java b/src/main/java/nimble/trust/engine/service/TrustCalculationService.java index 4990f22..2c726b6 100644 --- a/src/main/java/nimble/trust/engine/service/TrustCalculationService.java +++ b/src/main/java/nimble/trust/engine/service/TrustCalculationService.java @@ -62,6 +62,8 @@ public class TrustCalculationService { private Boolean syncWithCatalogService; public void score(String partyId) { + + final String bearerToken = SecurityContextHolder.getContext().getAuthentication().getPrincipal().toString(); // get profile and policy and calculate; final TrustSimpleManager trustManager = Factory.createInstance(TrustSimpleManager.class); TrustPolicy trustPolicy = trustPolicyService.findGlobalTRustPolicy(); @@ -74,7 +76,7 @@ public void score(String partyId) { if (syncWithCatalogService) { PartyType partyType = trustProfileService.createPartyType(partyId); - eu.nimble.service.model.solr.party.PartyType indexParty = indexingClient.getParty(partyId); + eu.nimble.service.model.solr.party.PartyType indexParty = indexingClient.getParty(partyId,bearerToken); // get trust scores partyType.getQualityIndicator().forEach(qualityIndicator -> { @@ -96,7 +98,7 @@ public void score(String partyId) { } } }); - indexingClient.setParty(indexParty); + indexingClient.setParty(indexParty,bearerToken); } log.info("trust score of party with ID " + partyId + " is updated to " + trustScore); } catch (Exception e) { From 9d4c409756d252997771fa3580a586d880584aae Mon Sep 17 00:00:00 2001 From: Akayeshmantha Date: Thu, 8 Aug 2019 15:04:40 +0200 Subject: [PATCH 09/30] fix hystrix timeout. --- src/main/resources/application.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index 8c4cfc5..772402b 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -22,6 +22,6 @@ spring.jpa.generate-ddl=true spring.jpa.hibernate.ddl-auto=update ##hystrix timeout default is one second and that caused some issues when calling business-service -hystrix.command.default.execution.isolation.thread.timeoutInMilliseconds=12000 +hystrix.command.default.execution.isolation.thread.timeoutInMilliseconds=5000 app.trust.trustScore.syncWithCatalogService=true From 91c94f496809e76d963b40b9d96acfdec8e3b7ce Mon Sep 17 00:00:00 2001 From: Akayeshmantha Date: Thu, 8 Aug 2019 15:20:53 +0200 Subject: [PATCH 10/30] trust quick fix. --- src/main/java/nimble/trust/application/TrustApplication.java | 2 ++ src/main/resources/bootstrap.yml | 4 ++++ 2 files changed, 6 insertions(+) diff --git a/src/main/java/nimble/trust/application/TrustApplication.java b/src/main/java/nimble/trust/application/TrustApplication.java index ef126a7..7bd3d61 100644 --- a/src/main/java/nimble/trust/application/TrustApplication.java +++ b/src/main/java/nimble/trust/application/TrustApplication.java @@ -8,6 +8,7 @@ import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.autoconfigure.domain.EntityScan; import org.springframework.cloud.client.circuitbreaker.EnableCircuitBreaker; +import org.springframework.cloud.client.discovery.EnableDiscoveryClient; import org.springframework.cloud.netflix.eureka.EnableEurekaClient; import org.springframework.cloud.netflix.feign.EnableFeignClients; import org.springframework.context.annotation.Bean; @@ -27,6 +28,7 @@ @EnableCircuitBreaker @EnableAutoConfiguration @EnableEurekaClient +@EnableDiscoveryClient @EnableFeignClients(basePackages="nimble.trust.engine.restclient") @RestController @EnableJpaAuditing(auditorAwareRef="auditorProvider") diff --git a/src/main/resources/bootstrap.yml b/src/main/resources/bootstrap.yml index 8995449..4149e84 100644 --- a/src/main/resources/bootstrap.yml +++ b/src/main/resources/bootstrap.yml @@ -8,6 +8,10 @@ spring: enabled: ${CONFIG_SERVER_ENABLED:true} uri: ${CONFIG_SERVER_URI:http://localhost:8888} failFast: ${CONFIG_SERVER_FAILFAST:false} + service-registry: + auto-registration: + enabled: ${DISCOVERY_ENABLED:false} + fail-fast: ${DISCOVERY_FAILFAST:true} discovery: enabled: ${DISCOVERY_ENABLED:false} jpa: From 172b39d3aba404d42b82c8ef3d503e3b4647baa2 Mon Sep 17 00:00:00 2001 From: Akayeshmantha Date: Thu, 8 Aug 2019 16:03:45 +0200 Subject: [PATCH 11/30] maven changes. --- pom.xml | 72 ++++++++++++++++++++++++++++----------------------------- 1 file changed, 36 insertions(+), 36 deletions(-) diff --git a/pom.xml b/pom.xml index 91ff1cb..998ad5d 100644 --- a/pom.xml +++ b/pom.xml @@ -95,19 +95,19 @@ test - org.springframework.security - spring-security-test - test - - - org.springframework.boot - spring-boot-starter-security - compile - + org.springframework.security + spring-security-test + test + + + org.springframework.boot + spring-boot-starter-security + compile + org.springframework.boot - spring-boot-starter-data-jpa - + spring-boot-starter-data-jpa + org.springframework.boot spring-boot-starter-web @@ -145,11 +145,11 @@ postgresql - - io.github.openfeign - feign-gson - 9.3.1 - + + io.github.openfeign + feign-gson + 9.3.1 + eu.nimble.core.common @@ -161,24 +161,24 @@ rest-client 0.0.1-SNAPSHOT - - org.slf4j - slf4j-log4j12 - + + org.slf4j + slf4j-log4j12 + - + - - eu.nimble.core.common - ubl-data-model - 0.0.1-SNAPSHOT - - - org.slf4j - slf4j-log4j12 - - - + + eu.nimble.core.common + ubl-data-model + 0.0.1-SNAPSHOT + + + org.slf4j + slf4j-log4j12 + + + eu.nimble.core.common @@ -193,10 +193,10 @@ - org.projectlombok - lombok - compile - + org.projectlombok + lombok + compile + From 7cff528001ee7e39ef6b47b26e5757ac600f4512 Mon Sep 17 00:00:00 2001 From: Akayeshmantha Date: Thu, 8 Aug 2019 16:36:49 +0200 Subject: [PATCH 12/30] add netflix client. --- pom.xml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/pom.xml b/pom.xml index 998ad5d..eb24c43 100644 --- a/pom.xml +++ b/pom.xml @@ -84,6 +84,10 @@ org.springframework.cloud spring-cloud-starter-sleuth + + org.springframework.cloud + spring-cloud-starter-netflix-eureka-client + net.logstash.logback logstash-logback-encoder From b828682dbceadeb668ac5dd8d91a8aeffda83110 Mon Sep 17 00:00:00 2001 From: Akayeshmantha Date: Thu, 8 Aug 2019 16:41:25 +0200 Subject: [PATCH 13/30] quick fix. --- pom.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/pom.xml b/pom.xml index eb24c43..044b33a 100644 --- a/pom.xml +++ b/pom.xml @@ -87,6 +87,7 @@ org.springframework.cloud spring-cloud-starter-netflix-eureka-client + 2.0.0.RELEASE net.logstash.logback From a155a16d1c6832081eebd96fc549f5c95a025470 Mon Sep 17 00:00:00 2001 From: Akayeshmantha Date: Thu, 8 Aug 2019 16:46:10 +0200 Subject: [PATCH 14/30] fetch registry added to trust. --- src/main/resources/application.properties | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index 772402b..8cf05a0 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -23,5 +23,6 @@ spring.jpa.hibernate.ddl-auto=update ##hystrix timeout default is one second and that caused some issues when calling business-service hystrix.command.default.execution.isolation.thread.timeoutInMilliseconds=5000 +eureka.client.fetchRegistry=true app.trust.trustScore.syncWithCatalogService=true From 719d1143138a61a597dce92287677f3f818d26cd Mon Sep 17 00:00:00 2001 From: Akayeshmantha Date: Thu, 8 Aug 2019 17:03:55 +0200 Subject: [PATCH 15/30] Hystrix added. --- src/main/java/nimble/trust/application/TrustApplication.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/nimble/trust/application/TrustApplication.java b/src/main/java/nimble/trust/application/TrustApplication.java index 7bd3d61..2cde136 100644 --- a/src/main/java/nimble/trust/application/TrustApplication.java +++ b/src/main/java/nimble/trust/application/TrustApplication.java @@ -11,6 +11,7 @@ import org.springframework.cloud.client.discovery.EnableDiscoveryClient; import org.springframework.cloud.netflix.eureka.EnableEurekaClient; import org.springframework.cloud.netflix.feign.EnableFeignClients; +import org.springframework.cloud.netflix.hystrix.EnableHystrix; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.ComponentScan; import org.springframework.context.annotation.Configuration; @@ -27,8 +28,8 @@ @Configuration @EnableCircuitBreaker @EnableAutoConfiguration +@EnableHystrix @EnableEurekaClient -@EnableDiscoveryClient @EnableFeignClients(basePackages="nimble.trust.engine.restclient") @RestController @EnableJpaAuditing(auditorAwareRef="auditorProvider") From 2cf4724906e30c6e49be0224bdb6ecd956aab739 Mon Sep 17 00:00:00 2001 From: Akayeshmantha Date: Thu, 8 Aug 2019 17:13:58 +0200 Subject: [PATCH 16/30] register with eureka. --- src/main/resources/application.properties | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index 8cf05a0..ec2dfa7 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -23,6 +23,7 @@ spring.jpa.hibernate.ddl-auto=update ##hystrix timeout default is one second and that caused some issues when calling business-service hystrix.command.default.execution.isolation.thread.timeoutInMilliseconds=5000 -eureka.client.fetchRegistry=true +eureka.client.fetchRegistry=true +eureka.client.registerWithEureka=true app.trust.trustScore.syncWithCatalogService=true From 38467a553bfdc8d9abe26fe5a08b0d43a2baf0de Mon Sep 17 00:00:00 2001 From: Akayeshmantha Date: Fri, 6 Sep 2019 11:58:56 +0200 Subject: [PATCH 17/30] remove registry. --- src/main/resources/bootstrap.yml | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/main/resources/bootstrap.yml b/src/main/resources/bootstrap.yml index 4149e84..8995449 100644 --- a/src/main/resources/bootstrap.yml +++ b/src/main/resources/bootstrap.yml @@ -8,10 +8,6 @@ spring: enabled: ${CONFIG_SERVER_ENABLED:true} uri: ${CONFIG_SERVER_URI:http://localhost:8888} failFast: ${CONFIG_SERVER_FAILFAST:false} - service-registry: - auto-registration: - enabled: ${DISCOVERY_ENABLED:false} - fail-fast: ${DISCOVERY_FAILFAST:true} discovery: enabled: ${DISCOVERY_ENABLED:false} jpa: From a90b84f55d7d7fb32b260d5c5d7744cea9339e64 Mon Sep 17 00:00:00 2001 From: Akayeshmantha Date: Fri, 6 Sep 2019 12:17:03 +0200 Subject: [PATCH 18/30] fix discovery. --- pom.xml | 5 ----- src/main/java/nimble/trust/application/TrustApplication.java | 2 -- src/main/resources/application.properties | 2 -- 3 files changed, 9 deletions(-) diff --git a/pom.xml b/pom.xml index 044b33a..998ad5d 100644 --- a/pom.xml +++ b/pom.xml @@ -84,11 +84,6 @@ org.springframework.cloud spring-cloud-starter-sleuth - - org.springframework.cloud - spring-cloud-starter-netflix-eureka-client - 2.0.0.RELEASE - net.logstash.logback logstash-logback-encoder diff --git a/src/main/java/nimble/trust/application/TrustApplication.java b/src/main/java/nimble/trust/application/TrustApplication.java index 2cde136..d1b503b 100644 --- a/src/main/java/nimble/trust/application/TrustApplication.java +++ b/src/main/java/nimble/trust/application/TrustApplication.java @@ -11,7 +11,6 @@ import org.springframework.cloud.client.discovery.EnableDiscoveryClient; import org.springframework.cloud.netflix.eureka.EnableEurekaClient; import org.springframework.cloud.netflix.feign.EnableFeignClients; -import org.springframework.cloud.netflix.hystrix.EnableHystrix; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.ComponentScan; import org.springframework.context.annotation.Configuration; @@ -28,7 +27,6 @@ @Configuration @EnableCircuitBreaker @EnableAutoConfiguration -@EnableHystrix @EnableEurekaClient @EnableFeignClients(basePackages="nimble.trust.engine.restclient") @RestController diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index ec2dfa7..772402b 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -23,7 +23,5 @@ spring.jpa.hibernate.ddl-auto=update ##hystrix timeout default is one second and that caused some issues when calling business-service hystrix.command.default.execution.isolation.thread.timeoutInMilliseconds=5000 -eureka.client.fetchRegistry=true -eureka.client.registerWithEureka=true app.trust.trustScore.syncWithCatalogService=true From 0335c6e632f1cc6b7434f388258c988dc0b8f4e8 Mon Sep 17 00:00:00 2001 From: Akayeshmantha Date: Fri, 6 Sep 2019 12:40:45 +0200 Subject: [PATCH 19/30] quick fix. --- src/main/java/nimble/trust/application/TrustApplication.java | 1 - src/main/resources/application.properties | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/src/main/java/nimble/trust/application/TrustApplication.java b/src/main/java/nimble/trust/application/TrustApplication.java index d1b503b..ef126a7 100644 --- a/src/main/java/nimble/trust/application/TrustApplication.java +++ b/src/main/java/nimble/trust/application/TrustApplication.java @@ -8,7 +8,6 @@ import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.autoconfigure.domain.EntityScan; import org.springframework.cloud.client.circuitbreaker.EnableCircuitBreaker; -import org.springframework.cloud.client.discovery.EnableDiscoveryClient; import org.springframework.cloud.netflix.eureka.EnableEurekaClient; import org.springframework.cloud.netflix.feign.EnableFeignClients; import org.springframework.context.annotation.Bean; diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index 772402b..8c4cfc5 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -22,6 +22,6 @@ spring.jpa.generate-ddl=true spring.jpa.hibernate.ddl-auto=update ##hystrix timeout default is one second and that caused some issues when calling business-service -hystrix.command.default.execution.isolation.thread.timeoutInMilliseconds=5000 +hystrix.command.default.execution.isolation.thread.timeoutInMilliseconds=12000 app.trust.trustScore.syncWithCatalogService=true From 152897fa91ce312d22d8c86b9f4bd7ed984ae4e6 Mon Sep 17 00:00:00 2001 From: Akayeshmantha Date: Fri, 6 Sep 2019 14:53:58 +0200 Subject: [PATCH 20/30] swagger fix. --- .../nimble/trust/config/SwaggerConfig.java | 75 +++++++++++-------- 1 file changed, 44 insertions(+), 31 deletions(-) diff --git a/src/main/java/nimble/trust/config/SwaggerConfig.java b/src/main/java/nimble/trust/config/SwaggerConfig.java index ccc410d..b56e705 100644 --- a/src/main/java/nimble/trust/config/SwaggerConfig.java +++ b/src/main/java/nimble/trust/config/SwaggerConfig.java @@ -1,31 +1,44 @@ -package nimble.trust.config; - -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; - -import springfox.documentation.builders.RequestHandlerSelectors; -import springfox.documentation.service.ApiInfo; -import springfox.documentation.spi.DocumentationType; -import springfox.documentation.spring.web.plugins.Docket; -import springfox.documentation.swagger2.annotations.EnableSwagger2; - -@Configuration -@EnableSwagger2 -public class SwaggerConfig { - - @Bean - public Docket api() { - return new Docket(DocumentationType.SWAGGER_2) - .select().apis(RequestHandlerSelectors.basePackage("nimble.trust")) - .build().apiInfo(apiInfo()); - } - - private ApiInfo apiInfo() { - return new ApiInfo( - "Nimble Trust Scoring and Ranking REST API", - "REST API NIMBLE TRM", - "1.0", "Terms of service", - new springfox.documentation.service.Contact("", "https://www.nimble-project.org/", "m.vujasinovic@innova-eu.net"), - "Apache 2.0", "http://www.apache.org/licenses/LICENSE-2.0"); - } -} +package nimble.trust.config; + +import org.springframework.beans.factory.annotation.Value; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +import springfox.documentation.builders.PathSelectors; +import springfox.documentation.builders.RequestHandlerSelectors; +import springfox.documentation.service.ApiInfo; +import springfox.documentation.spi.DocumentationType; +import springfox.documentation.spring.web.plugins.Docket; +import springfox.documentation.swagger2.annotations.EnableSwagger2; + +@Configuration +@EnableSwagger2 +public class SwaggerConfig { + + + @Value("${${nimble.trust.url:}}") + private String platformHost; + + @Bean + public Docket api() { + + platformHost = platformHost.replace("https://", ""); + platformHost = platformHost.replace("http://",""); + + return new Docket(DocumentationType.SWAGGER_2) + .host(platformHost) + .select().apis(RequestHandlerSelectors.basePackage("nimble.trust")) + .paths(PathSelectors.any()) + .build() + .apiInfo(apiInfo()) ; + } + + private ApiInfo apiInfo() { + return new ApiInfo( + "Nimble Trust Scoring and Ranking REST API", + "REST API NIMBLE TRM", + "1.0", "Terms of service", + new springfox.documentation.service.Contact("", "https://www.nimble-project.org/", "m.vujasinovic@innova-eu.net"), + "Apache 2.0", "http://www.apache.org/licenses/LICENSE-2.0"); + } +} From f954b5b62b1815cbfa33e66c1d2194dd228dbb43 Mon Sep 17 00:00:00 2001 From: Akayeshmantha Date: Fri, 6 Sep 2019 15:31:49 +0200 Subject: [PATCH 21/30] remove hystrix. --- pom.xml | 4 ---- 1 file changed, 4 deletions(-) diff --git a/pom.xml b/pom.xml index 998ad5d..954ee12 100644 --- a/pom.xml +++ b/pom.xml @@ -64,10 +64,6 @@ - - org.springframework.cloud - spring-cloud-starter-hystrix - org.springframework.boot spring-boot-starter-actuator From e46679d89ac04bf15df04d5851328f427f6a40c2 Mon Sep 17 00:00:00 2001 From: Akayeshmantha Date: Fri, 6 Sep 2019 15:52:24 +0200 Subject: [PATCH 22/30] revert all changes to test service discovery. --- pom.xml | 26 ++++---- .../engine/restclient/IndexingClient.java | 66 +++++++++---------- .../restclient/IndexingClientFallback.java | 56 ++++++++-------- .../service/TrustCalculationService.java | 58 ++++++++-------- 4 files changed, 105 insertions(+), 101 deletions(-) diff --git a/pom.xml b/pom.xml index 954ee12..6f3fa18 100644 --- a/pom.xml +++ b/pom.xml @@ -76,6 +76,10 @@ org.springframework.cloud spring-cloud-starter-feign + + org.springframework.cloud + spring-cloud-starter-hystrix + org.springframework.cloud spring-cloud-starter-sleuth @@ -176,17 +180,17 @@ - - eu.nimble.core.common - solr-data-model - 0.0.1-SNAPSHOT - - - org.slf4j - slf4j-log4j12 - - - + + + + + + + + + + + org.projectlombok diff --git a/src/main/java/nimble/trust/engine/restclient/IndexingClient.java b/src/main/java/nimble/trust/engine/restclient/IndexingClient.java index 68a2f10..5fdacd0 100644 --- a/src/main/java/nimble/trust/engine/restclient/IndexingClient.java +++ b/src/main/java/nimble/trust/engine/restclient/IndexingClient.java @@ -1,33 +1,33 @@ -package nimble.trust.engine.restclient; - -import eu.nimble.service.model.solr.party.PartyType; -import feign.Headers; -import org.springframework.cloud.netflix.feign.FeignClient; -import org.springframework.web.bind.annotation.RequestHeader; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestMethod; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RequestParam; - -/** - * REST Client to index entities via the Indexing Service. - * - * @author Ayeshmantha Perera - */ -@FeignClient(name = "indexing-service", url = "${nimble.indexing.url}", fallback = IndexingClientFallback.class) -public interface IndexingClient { - @RequestMapping(method = RequestMethod.PUT, value = "/party", consumes = "application/json") - @Headers("Content-Type: application/json") - Boolean setParty(@RequestBody PartyType party, - @RequestHeader(value = "Authorization", required = true) String bearerToken); - - @RequestMapping(method = RequestMethod.GET, value = "/party") - PartyType getParty(@RequestParam(value = "uri") String uri, - @RequestHeader(value = "Authorization", required = true) String bearerToken); - - @RequestMapping(method = RequestMethod.DELETE, value = "/party") - Boolean deleteParty(@RequestBody PartyType party, - @RequestHeader(value = "Authorization", required = true) String bearerToken); - - -} +//package nimble.trust.engine.restclient; +// +//import eu.nimble.service.model.solr.party.PartyType; +//import feign.Headers; +//import org.springframework.cloud.netflix.feign.FeignClient; +//import org.springframework.web.bind.annotation.RequestHeader; +//import org.springframework.web.bind.annotation.RequestMapping; +//import org.springframework.web.bind.annotation.RequestMethod; +//import org.springframework.web.bind.annotation.RequestBody; +//import org.springframework.web.bind.annotation.RequestParam; +// +///** +// * REST Client to index entities via the Indexing Service. +// * +// * @author Ayeshmantha Perera +// */ +//@FeignClient(name = "indexing-service", url = "${nimble.indexing.url}", fallback = IndexingClientFallback.class) +//public interface IndexingClient { +// @RequestMapping(method = RequestMethod.PUT, value = "/party", consumes = "application/json") +// @Headers("Content-Type: application/json") +// Boolean setParty(@RequestBody PartyType party, +// @RequestHeader(value = "Authorization", required = true) String bearerToken); +// +// @RequestMapping(method = RequestMethod.GET, value = "/party") +// PartyType getParty(@RequestParam(value = "uri") String uri, +// @RequestHeader(value = "Authorization", required = true) String bearerToken); +// +// @RequestMapping(method = RequestMethod.DELETE, value = "/party") +// Boolean deleteParty(@RequestBody PartyType party, +// @RequestHeader(value = "Authorization", required = true) String bearerToken); +// +// +//} diff --git a/src/main/java/nimble/trust/engine/restclient/IndexingClientFallback.java b/src/main/java/nimble/trust/engine/restclient/IndexingClientFallback.java index 76a8cb9..cbb1e42 100644 --- a/src/main/java/nimble/trust/engine/restclient/IndexingClientFallback.java +++ b/src/main/java/nimble/trust/engine/restclient/IndexingClientFallback.java @@ -1,28 +1,28 @@ -package nimble.trust.engine.restclient; - -import eu.nimble.service.model.solr.party.PartyType; - -import org.springframework.stereotype.Component; - -/** - * - * @author Ayeshmantha Perera - */ -@Component -public class IndexingClientFallback implements IndexingClient { - - @Override - public Boolean setParty(PartyType party,String bearerToken) { - return false; - } - - @Override - public PartyType getParty(String uri,String bearerToken) { - return null; - } - - @Override - public Boolean deleteParty(PartyType party,String bearerToken) { - return false; - } -} +//package nimble.trust.engine.restclient; +// +//import eu.nimble.service.model.solr.party.PartyType; +// +//import org.springframework.stereotype.Component; +// +///** +// * +// * @author Ayeshmantha Perera +// */ +//@Component +//public class IndexingClientFallback implements IndexingClient { +// +// @Override +// public Boolean setParty(PartyType party,String bearerToken) { +// return false; +// } +// +// @Override +// public PartyType getParty(String uri,String bearerToken) { +// return null; +// } +// +// @Override +// public Boolean deleteParty(PartyType party,String bearerToken) { +// return false; +// } +//} diff --git a/src/main/java/nimble/trust/engine/service/TrustCalculationService.java b/src/main/java/nimble/trust/engine/service/TrustCalculationService.java index 2c726b6..544b3ae 100644 --- a/src/main/java/nimble/trust/engine/service/TrustCalculationService.java +++ b/src/main/java/nimble/trust/engine/service/TrustCalculationService.java @@ -5,7 +5,7 @@ import eu.nimble.service.model.ubl.commonaggregatecomponents.PartyType; import eu.nimble.service.model.ubl.extension.QualityIndicatorParameter; -import nimble.trust.engine.restclient.IndexingClient; +//import nimble.trust.engine.restclient.IndexingClient; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; @@ -49,8 +49,8 @@ public class TrustCalculationService { @Autowired private IdentityServiceClient identityServiceClient; - @Autowired - private IndexingClient indexingClient; +// @Autowired +// private IndexingClient indexingClient; @Autowired private TrustProfileService trustProfileService; @@ -74,32 +74,32 @@ public void score(String partyId) { agentService.updateTrustScore(partyId, trustScore); - if (syncWithCatalogService) { - PartyType partyType = trustProfileService.createPartyType(partyId); - eu.nimble.service.model.solr.party.PartyType indexParty = indexingClient.getParty(partyId,bearerToken); - - // get trust scores - partyType.getQualityIndicator().forEach(qualityIndicator -> { - if(qualityIndicator.getQualityParameter() != null && qualityIndicator.getQuantity() != null) { - if(qualityIndicator.getQualityParameter().contentEquals(QualityIndicatorParameter.COMPANY_RATING.toString())) { - indexParty.setTrustRating(qualityIndicator.getQuantity().getValue().doubleValue()); - } else if(qualityIndicator.getQualityParameter().contentEquals(QualityIndicatorParameter.TRUST_SCORE.toString())) { - indexParty.setTrustScore(qualityIndicator.getQuantity().getValue().doubleValue()); - } else if(qualityIndicator.getQualityParameter().contentEquals(QualityIndicatorParameter.DELIVERY_PACKAGING.toString())) { - indexParty.setTrustDeliveryPackaging(qualityIndicator.getQuantity().getValue().doubleValue()); - } else if(qualityIndicator.getQualityParameter().contentEquals(QualityIndicatorParameter.FULFILLMENT_OF_TERMS.toString())) { - indexParty.setTrustFullfillmentOfTerms(qualityIndicator.getQuantity().getValue().doubleValue()); - } else if(qualityIndicator.getQualityParameter().contentEquals(QualityIndicatorParameter.SELLER_COMMUNICATION.toString())) { - indexParty.setTrustSellerCommunication(qualityIndicator.getQuantity().getValue().doubleValue()); - } else if(qualityIndicator.getQualityParameter().contentEquals(QualityIndicatorParameter.NUMBER_OF_TRANSACTIONS.toString())) { - indexParty.setTrustNumberOfTransactions(qualityIndicator.getQuantity().getValue().doubleValue()); - } else if(qualityIndicator.getQualityParameter().contentEquals(QualityIndicatorParameter.TRADING_VOLUME.toString())) { - indexParty.setTrustTradingVolume(qualityIndicator.getQuantity().getValue().doubleValue()); - } - } - }); - indexingClient.setParty(indexParty,bearerToken); - } +// if (syncWithCatalogService) { +// PartyType partyType = trustProfileService.createPartyType(partyId); +// eu.nimble.service.model.solr.party.PartyType indexParty = indexingClient.getParty(partyId,bearerToken); +// +// // get trust scores +// partyType.getQualityIndicator().forEach(qualityIndicator -> { +// if(qualityIndicator.getQualityParameter() != null && qualityIndicator.getQuantity() != null) { +// if(qualityIndicator.getQualityParameter().contentEquals(QualityIndicatorParameter.COMPANY_RATING.toString())) { +// indexParty.setTrustRating(qualityIndicator.getQuantity().getValue().doubleValue()); +// } else if(qualityIndicator.getQualityParameter().contentEquals(QualityIndicatorParameter.TRUST_SCORE.toString())) { +// indexParty.setTrustScore(qualityIndicator.getQuantity().getValue().doubleValue()); +// } else if(qualityIndicator.getQualityParameter().contentEquals(QualityIndicatorParameter.DELIVERY_PACKAGING.toString())) { +// indexParty.setTrustDeliveryPackaging(qualityIndicator.getQuantity().getValue().doubleValue()); +// } else if(qualityIndicator.getQualityParameter().contentEquals(QualityIndicatorParameter.FULFILLMENT_OF_TERMS.toString())) { +// indexParty.setTrustFullfillmentOfTerms(qualityIndicator.getQuantity().getValue().doubleValue()); +// } else if(qualityIndicator.getQualityParameter().contentEquals(QualityIndicatorParameter.SELLER_COMMUNICATION.toString())) { +// indexParty.setTrustSellerCommunication(qualityIndicator.getQuantity().getValue().doubleValue()); +// } else if(qualityIndicator.getQualityParameter().contentEquals(QualityIndicatorParameter.NUMBER_OF_TRANSACTIONS.toString())) { +// indexParty.setTrustNumberOfTransactions(qualityIndicator.getQuantity().getValue().doubleValue()); +// } else if(qualityIndicator.getQualityParameter().contentEquals(QualityIndicatorParameter.TRADING_VOLUME.toString())) { +// indexParty.setTrustTradingVolume(qualityIndicator.getQuantity().getValue().doubleValue()); +// } +// } +// }); +// indexingClient.setParty(indexParty,bearerToken); +// } log.info("trust score of party with ID " + partyId + " is updated to " + trustScore); } catch (Exception e) { log.error("Exception", e); From 460ea4fde0e838c95a722c995b5d37acb1dbf758 Mon Sep 17 00:00:00 2001 From: Akayeshmantha Date: Fri, 6 Sep 2019 15:57:10 +0200 Subject: [PATCH 23/30] add solr data model. --- pom.xml | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/pom.xml b/pom.xml index 6f3fa18..18fd3e5 100644 --- a/pom.xml +++ b/pom.xml @@ -180,17 +180,17 @@ - - - - - - - - - - - + + eu.nimble.core.common + solr-data-model + 0.0.1-SNAPSHOT + + + org.slf4j + slf4j-log4j12 + + + org.projectlombok From 335fc2c63dd23248b62aa5da759fde1751dec591 Mon Sep 17 00:00:00 2001 From: Akayeshmantha Date: Fri, 6 Sep 2019 15:59:49 +0200 Subject: [PATCH 24/30] remove to test solr model. --- pom.xml | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/pom.xml b/pom.xml index 18fd3e5..6f3fa18 100644 --- a/pom.xml +++ b/pom.xml @@ -180,17 +180,17 @@ - - eu.nimble.core.common - solr-data-model - 0.0.1-SNAPSHOT - - - org.slf4j - slf4j-log4j12 - - - + + + + + + + + + + + org.projectlombok From d638e033f291798f9d2953e025b611604c7b6f13 Mon Sep 17 00:00:00 2001 From: Akayeshmantha Date: Mon, 9 Sep 2019 16:13:36 +0200 Subject: [PATCH 25/30] fix trust --- pom.xml | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/pom.xml b/pom.xml index 6f3fa18..a91fa61 100644 --- a/pom.xml +++ b/pom.xml @@ -180,17 +180,11 @@ - - - - - - - - - - - + + eu.nimble.core.common + solr-data-model + 0.0.1-SNAPSHOT + org.projectlombok From 4ea5fecfe9d99cf9ddf6387d87ad62ba7c6e4387 Mon Sep 17 00:00:00 2001 From: Akayeshmantha Date: Mon, 9 Sep 2019 16:27:02 +0200 Subject: [PATCH 26/30] fix trust service. --- pom.xml | 10 ++++++---- .../nimble/trust/application/TrustApplication.java | 4 ++-- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/pom.xml b/pom.xml index a91fa61..5d51210 100644 --- a/pom.xml +++ b/pom.xml @@ -76,10 +76,6 @@ org.springframework.cloud spring-cloud-starter-feign - - org.springframework.cloud - spring-cloud-starter-hystrix - org.springframework.cloud spring-cloud-starter-sleuth @@ -180,6 +176,12 @@ + + org.apache.commons + commons-lang3 + 3.7 + + eu.nimble.core.common solr-data-model diff --git a/src/main/java/nimble/trust/application/TrustApplication.java b/src/main/java/nimble/trust/application/TrustApplication.java index ef126a7..2a9c341 100644 --- a/src/main/java/nimble/trust/application/TrustApplication.java +++ b/src/main/java/nimble/trust/application/TrustApplication.java @@ -8,6 +8,7 @@ import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.autoconfigure.domain.EntityScan; import org.springframework.cloud.client.circuitbreaker.EnableCircuitBreaker; +import org.springframework.cloud.client.discovery.EnableDiscoveryClient; import org.springframework.cloud.netflix.eureka.EnableEurekaClient; import org.springframework.cloud.netflix.feign.EnableFeignClients; import org.springframework.context.annotation.Bean; @@ -25,8 +26,7 @@ @Configuration @EnableCircuitBreaker -@EnableAutoConfiguration -@EnableEurekaClient +@EnableDiscoveryClient @EnableFeignClients(basePackages="nimble.trust.engine.restclient") @RestController @EnableJpaAuditing(auditorAwareRef="auditorProvider") From a8e421f000121b7a4f9bc237227c66a1101e5084 Mon Sep 17 00:00:00 2001 From: Akayeshmantha Date: Mon, 9 Sep 2019 17:07:49 +0200 Subject: [PATCH 27/30] add hystrix --- pom.xml | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 5d51210..a1e780b 100644 --- a/pom.xml +++ b/pom.xml @@ -76,6 +76,10 @@ org.springframework.cloud spring-cloud-starter-feign + + org.springframework.cloud + spring-cloud-starter-hystrix + org.springframework.cloud spring-cloud-starter-sleuth @@ -181,7 +185,7 @@ commons-lang3 3.7 - + eu.nimble.core.common solr-data-model From b45a5f3efb7a483c548434d9cfe2e568ba4dc1eb Mon Sep 17 00:00:00 2001 From: Akayeshmantha Date: Mon, 9 Sep 2019 17:21:06 +0200 Subject: [PATCH 28/30] revert back trust changes. --- pom.xml | 13 ------------- .../nimble/trust/application/TrustApplication.java | 4 ++-- 2 files changed, 2 insertions(+), 15 deletions(-) diff --git a/pom.xml b/pom.xml index a1e780b..77c5c57 100644 --- a/pom.xml +++ b/pom.xml @@ -179,19 +179,6 @@ - - - org.apache.commons - commons-lang3 - 3.7 - - - - eu.nimble.core.common - solr-data-model - 0.0.1-SNAPSHOT - - org.projectlombok lombok diff --git a/src/main/java/nimble/trust/application/TrustApplication.java b/src/main/java/nimble/trust/application/TrustApplication.java index 2a9c341..ef126a7 100644 --- a/src/main/java/nimble/trust/application/TrustApplication.java +++ b/src/main/java/nimble/trust/application/TrustApplication.java @@ -8,7 +8,6 @@ import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.autoconfigure.domain.EntityScan; import org.springframework.cloud.client.circuitbreaker.EnableCircuitBreaker; -import org.springframework.cloud.client.discovery.EnableDiscoveryClient; import org.springframework.cloud.netflix.eureka.EnableEurekaClient; import org.springframework.cloud.netflix.feign.EnableFeignClients; import org.springframework.context.annotation.Bean; @@ -26,7 +25,8 @@ @Configuration @EnableCircuitBreaker -@EnableDiscoveryClient +@EnableAutoConfiguration +@EnableEurekaClient @EnableFeignClients(basePackages="nimble.trust.engine.restclient") @RestController @EnableJpaAuditing(auditorAwareRef="auditorProvider") From c8affb1c8d06c107d9ff440e09a1eff48d17dc6c Mon Sep 17 00:00:00 2001 From: Akayeshmantha Date: Tue, 10 Sep 2019 11:15:29 +0200 Subject: [PATCH 29/30] updated indexing client. --- .../engine/restclient/IndexingClient.java | 59 ++++++++----------- .../restclient/IndexingClientFallback.java | 48 +++++++-------- 2 files changed, 46 insertions(+), 61 deletions(-) diff --git a/src/main/java/nimble/trust/engine/restclient/IndexingClient.java b/src/main/java/nimble/trust/engine/restclient/IndexingClient.java index 5fdacd0..c694236 100644 --- a/src/main/java/nimble/trust/engine/restclient/IndexingClient.java +++ b/src/main/java/nimble/trust/engine/restclient/IndexingClient.java @@ -1,33 +1,26 @@ -//package nimble.trust.engine.restclient; -// -//import eu.nimble.service.model.solr.party.PartyType; -//import feign.Headers; -//import org.springframework.cloud.netflix.feign.FeignClient; -//import org.springframework.web.bind.annotation.RequestHeader; -//import org.springframework.web.bind.annotation.RequestMapping; -//import org.springframework.web.bind.annotation.RequestMethod; -//import org.springframework.web.bind.annotation.RequestBody; -//import org.springframework.web.bind.annotation.RequestParam; -// -///** -// * REST Client to index entities via the Indexing Service. -// * -// * @author Ayeshmantha Perera -// */ -//@FeignClient(name = "indexing-service", url = "${nimble.indexing.url}", fallback = IndexingClientFallback.class) -//public interface IndexingClient { -// @RequestMapping(method = RequestMethod.PUT, value = "/party", consumes = "application/json") -// @Headers("Content-Type: application/json") -// Boolean setParty(@RequestBody PartyType party, -// @RequestHeader(value = "Authorization", required = true) String bearerToken); -// -// @RequestMapping(method = RequestMethod.GET, value = "/party") -// PartyType getParty(@RequestParam(value = "uri") String uri, -// @RequestHeader(value = "Authorization", required = true) String bearerToken); -// -// @RequestMapping(method = RequestMethod.DELETE, value = "/party") -// Boolean deleteParty(@RequestBody PartyType party, -// @RequestHeader(value = "Authorization", required = true) String bearerToken); -// -// -//} +package nimble.trust.engine.restclient; + +import eu.nimble.service.model.ubl.commonaggregatecomponents.PartyType; +import feign.Headers; +import org.springframework.cloud.netflix.feign.FeignClient; +import org.springframework.web.bind.annotation.RequestHeader; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestParam; + +/** + * REST Client to index entities via the Indexing Service. + * + * @author Ayeshmantha Perera + */ +@FeignClient(name = "indexing-service", url = "${nimble.indexing.url}", fallback = IndexingClientFallback.class) +public interface IndexingClient { + + @RequestMapping(method = RequestMethod.POST, value = "/party/trust") + Boolean partyTrustUpdate( + @RequestParam(value = "partyId") String partyId, + @RequestBody PartyType partyType, + @RequestHeader(value = "Authorization", required = true) String bearerToken); + +} diff --git a/src/main/java/nimble/trust/engine/restclient/IndexingClientFallback.java b/src/main/java/nimble/trust/engine/restclient/IndexingClientFallback.java index cbb1e42..cc2c2ae 100644 --- a/src/main/java/nimble/trust/engine/restclient/IndexingClientFallback.java +++ b/src/main/java/nimble/trust/engine/restclient/IndexingClientFallback.java @@ -1,28 +1,20 @@ -//package nimble.trust.engine.restclient; -// -//import eu.nimble.service.model.solr.party.PartyType; -// -//import org.springframework.stereotype.Component; -// -///** -// * -// * @author Ayeshmantha Perera -// */ -//@Component -//public class IndexingClientFallback implements IndexingClient { -// -// @Override -// public Boolean setParty(PartyType party,String bearerToken) { -// return false; -// } -// -// @Override -// public PartyType getParty(String uri,String bearerToken) { -// return null; -// } -// -// @Override -// public Boolean deleteParty(PartyType party,String bearerToken) { -// return false; -// } -//} +package nimble.trust.engine.restclient; + +import eu.nimble.service.model.ubl.commonaggregatecomponents.PartyType; +import org.springframework.stereotype.Component; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestHeader; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; + +/** + * + * @author Ayeshmantha Perera + */ +@Component +public class IndexingClientFallback implements IndexingClient { + @Override + public Boolean partyTrustUpdate(String partyId,PartyType partyType,String bearerToken) { + return false; + } +} From 684f1856153d4a79aed158bfed020392e4d5973d Mon Sep 17 00:00:00 2001 From: Akayeshmantha Date: Tue, 10 Sep 2019 11:15:56 +0200 Subject: [PATCH 30/30] final change for indexing trust score. --- .../service/TrustCalculationService.java | 35 ++++--------------- 1 file changed, 7 insertions(+), 28 deletions(-) diff --git a/src/main/java/nimble/trust/engine/service/TrustCalculationService.java b/src/main/java/nimble/trust/engine/service/TrustCalculationService.java index 544b3ae..f805dee 100644 --- a/src/main/java/nimble/trust/engine/service/TrustCalculationService.java +++ b/src/main/java/nimble/trust/engine/service/TrustCalculationService.java @@ -6,6 +6,7 @@ import eu.nimble.service.model.ubl.commonaggregatecomponents.PartyType; import eu.nimble.service.model.ubl.extension.QualityIndicatorParameter; //import nimble.trust.engine.restclient.IndexingClient; +import nimble.trust.engine.restclient.IndexingClient; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; @@ -49,8 +50,8 @@ public class TrustCalculationService { @Autowired private IdentityServiceClient identityServiceClient; -// @Autowired -// private IndexingClient indexingClient; + @Autowired + private IndexingClient indexingClient; @Autowired private TrustProfileService trustProfileService; @@ -74,32 +75,10 @@ public void score(String partyId) { agentService.updateTrustScore(partyId, trustScore); -// if (syncWithCatalogService) { -// PartyType partyType = trustProfileService.createPartyType(partyId); -// eu.nimble.service.model.solr.party.PartyType indexParty = indexingClient.getParty(partyId,bearerToken); -// -// // get trust scores -// partyType.getQualityIndicator().forEach(qualityIndicator -> { -// if(qualityIndicator.getQualityParameter() != null && qualityIndicator.getQuantity() != null) { -// if(qualityIndicator.getQualityParameter().contentEquals(QualityIndicatorParameter.COMPANY_RATING.toString())) { -// indexParty.setTrustRating(qualityIndicator.getQuantity().getValue().doubleValue()); -// } else if(qualityIndicator.getQualityParameter().contentEquals(QualityIndicatorParameter.TRUST_SCORE.toString())) { -// indexParty.setTrustScore(qualityIndicator.getQuantity().getValue().doubleValue()); -// } else if(qualityIndicator.getQualityParameter().contentEquals(QualityIndicatorParameter.DELIVERY_PACKAGING.toString())) { -// indexParty.setTrustDeliveryPackaging(qualityIndicator.getQuantity().getValue().doubleValue()); -// } else if(qualityIndicator.getQualityParameter().contentEquals(QualityIndicatorParameter.FULFILLMENT_OF_TERMS.toString())) { -// indexParty.setTrustFullfillmentOfTerms(qualityIndicator.getQuantity().getValue().doubleValue()); -// } else if(qualityIndicator.getQualityParameter().contentEquals(QualityIndicatorParameter.SELLER_COMMUNICATION.toString())) { -// indexParty.setTrustSellerCommunication(qualityIndicator.getQuantity().getValue().doubleValue()); -// } else if(qualityIndicator.getQualityParameter().contentEquals(QualityIndicatorParameter.NUMBER_OF_TRANSACTIONS.toString())) { -// indexParty.setTrustNumberOfTransactions(qualityIndicator.getQuantity().getValue().doubleValue()); -// } else if(qualityIndicator.getQualityParameter().contentEquals(QualityIndicatorParameter.TRADING_VOLUME.toString())) { -// indexParty.setTrustTradingVolume(qualityIndicator.getQuantity().getValue().doubleValue()); -// } -// } -// }); -// indexingClient.setParty(indexParty,bearerToken); -// } + if (syncWithCatalogService) { + PartyType partyType = trustProfileService.createPartyType(partyId); + indexingClient.partyTrustUpdate(partyId,partyType,bearerToken); + } log.info("trust score of party with ID " + partyId + " is updated to " + trustScore); } catch (Exception e) { log.error("Exception", e);