Skip to content

Commit

Permalink
Merge pull request #6 from nimble-platform/staging
Browse files Browse the repository at this point in the history
PR for release MVP 8.0.0 / FMP 2.0.0
  • Loading branch information
jinnerbichler authored Feb 28, 2019
2 parents 8da1e22 + b4fb91f commit ae7644a
Show file tree
Hide file tree
Showing 5 changed files with 93 additions and 6 deletions.
5 changes: 5 additions & 0 deletions src/main/java/nimble/trust/engine/service/AgentService.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package nimble.trust.engine.service;

import java.math.BigDecimal;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
Expand Down Expand Up @@ -49,4 +50,8 @@ public Page<Agent> findAll(Pageable pageable){
return agentRepository.findAll(pageable);
}

public List<Agent> findAll(){
return agentRepository.findAll();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -111,14 +111,45 @@ public TrustPolicy createTrustPolicy() {
for (TrustAttributeType trustAttributeType : list) {
TrustAttribute attr = new TrustAttribute();
attr.setTrustAttributeType(trustAttributeType);
attr.setImportance(0);
attr = setAttributeDefaultConfig(attr);
attr.setTrustPolicy(policy);
policy.getTrustAttributes().add(attr);
}
policy = save(policy);
return policy;
}

private TrustAttribute setAttributeDefaultConfig(TrustAttribute attr) {
String type = attr.getTrustAttributeType().getName();

if (type.equalsIgnoreCase("OverallCompanyRating")){
attr.setImportance(1);
}
if (type.equalsIgnoreCase("TradingVolume")){
attr.setImportance(1);
}
if (type.equalsIgnoreCase("OverallProfileCompletness")){
attr.setImportance(1);
}
if (type.equalsIgnoreCase("NumberOfUncompletedTransactions")){
attr.setImportance(0);
}
if (type.equalsIgnoreCase("NumberOfCompletedTransactions")){
attr.setImportance(1);
}
if (type.equalsIgnoreCase("AverageTimeToRespond")){
attr.setImportance(1);
attr.setMaxValue("43200");
attr.setMinValue("0");
}
if (type.equalsIgnoreCase("AverageNegotiationTime")){
attr.setImportance(1D);
attr.setMaxValue("43200");
attr.setMinValue("0");
}
return attr;
}

public TrustPolicy findById(Long id) {
return trustPolicyRepository.findById(id);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

import com.google.common.collect.Lists;

import eu.nimble.service.model.ubl.commonaggregatecomponents.PartyIdentificationType;
import eu.nimble.service.model.ubl.commonaggregatecomponents.PartyType;
import eu.nimble.service.model.ubl.commonaggregatecomponents.QualityIndicatorType;
import eu.nimble.service.model.ubl.commonbasiccomponents.QuantityType;
Expand Down Expand Up @@ -88,6 +89,18 @@ private TrustAttribute findInProfileOrCreate(TrustProfile profile, String trustA
profile.getTrustAttributes().add(result);
return result;
}


public List<PartyType> listPartiesWithTrustData(){

List<PartyType> partyTypes = Lists.newArrayList();
List<Agent> list = agentService.findAll();
if (CollectionUtils.isEmpty(list)) return partyTypes;
for (Agent agent : list) {
partyTypes.add(createPartyType(agent.getAltId()));
}
return partyTypes;
}

public PartyType createPartyType(String partyId) {
TrustProfile profile = findByAgentAltId(partyId);
Expand All @@ -97,7 +110,11 @@ public PartyType createPartyType(String partyId) {

// create UBL Party populated with a trust-related data
PartyType party = new PartyType();
party.setID(partyId);
PartyIdentificationType partyIdentification = new PartyIdentificationType();
partyIdentification.setID(partyId);
List<PartyIdentificationType> identificationTypes = Lists.newArrayList();
identificationTypes.add(partyIdentification);
party.setPartyIdentification(identificationTypes);
List<TrustAttribute> trustAttributes = profile.getTrustAttributes();
List<QualityIndicatorType> qualityIndicatorTypes = Lists.newArrayList();
for (TrustAttribute trustAttribute : trustAttributes) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public ResponseEntity<TrustPolicyDto> getTrustPolicy( @RequestHeader(value = "Au
if (policy == null){
String msg = "Failed to find trust policy";
log.warn(msg);
return new ResponseEntity<>(HttpStatus.NOT_FOUND);
return new ResponseEntity<>(HttpStatus.OK); //return OK and empty response
}
TrustPolicyDto dto = DtoUtil.toDto(policy);
return new ResponseEntity<>(dto, HttpStatus.OK);
Expand Down Expand Up @@ -137,14 +137,25 @@ public ResponseEntity<Object> updateTrustPolicy(@RequestHeader(value = "Authoriz
response = TrustPolicy.class, responseContainer = "")
@ApiResponses(value = {
@ApiResponse(code = 200, message = "Policy sucessfully initialized",response=TrustPolicyDto.class),
@ApiResponse(code = 500, message = "Internal error",response=String.class)
@ApiResponse(code = 500, message = "Internal error",response=String.class),
@ApiResponse(code = 409, message = "Conflict - policy already exists",response=String.class)
})
@RequestMapping(value = "/policy/global/initialize", produces = { "application/json" }, method = RequestMethod.POST)
public ResponseEntity<TrustPolicyDto> createNewTrustPolicy(@RequestHeader(value = "Authorization") String bearerToken) {

try {
TrustPolicy policy = trustPolicyService.createTrustPolicy();
return new ResponseEntity<TrustPolicyDto>(DtoUtil.toDto(policy), HttpStatus.OK);

TrustPolicy policy = trustPolicyService.findGlobalTRustPolicy();

if (policy != null){
String msg = "Global policy already existis ";
log.warn(msg);
return new ResponseEntity<>(HttpStatus.CONFLICT);
}
else{
policy = trustPolicyService.createTrustPolicy();
return new ResponseEntity<TrustPolicyDto>(DtoUtil.toDto(policy), HttpStatus.OK);
}
} catch (Exception e) {
log.error("Internal error", e);
return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.google.common.collect.Lists;

import eu.nimble.service.model.ubl.commonaggregatecomponents.PartyType;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
Expand Down Expand Up @@ -113,6 +115,27 @@ public ResponseEntity<?> getPartyTrustData(@ApiParam(value = "Identifier of the
}


@ApiOperation(value = "Obtain list of parties with their trust score", notes = "Obtain list of parties with their trust score",
response = PartyType.class, tags={ }, responseContainer = "List")
@ApiResponses(value = {
@ApiResponse(code = 200, message = "Request succesfull processed", response = String.class),
@ApiResponse(code = 404, message = "No data found", response = String.class),
@ApiResponse(code = 500, message = "Internal Server Error", response = String.class)})
@RequestMapping(value = "/party/list/trust",produces = MediaType.APPLICATION_JSON_VALUE,method = RequestMethod.GET)
public ResponseEntity<?> getListPartyTrustData(@ApiParam(value = "Authorization header to be obtained via login to the NIMBLE platform") @RequestHeader(value = "Authorization") String bearerToken) {

List<PartyType> partyTypes = Lists.newArrayList();
try {
partyTypes = trustProfileService.listPartiesWithTrustData();
log.info("getListPartyTrustData successfully executed. List size+"+partyTypes.size());
return new ResponseEntity<>(partyTypes, HttpStatus.OK);
} catch (Exception e) {
log.error("getListPartyTrustData failed", e);
return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR);
}
}



@ApiOperation(value = "Calculate trust score using global policy", notes = "Calculate trust score using global policy",
response = PartyType.class, tags={ })
Expand Down

0 comments on commit ae7644a

Please sign in to comment.