Skip to content

Commit

Permalink
Merge pull request #98 from nimble-platform/staging
Browse files Browse the repository at this point in the history
Pull Request for Release 17.0.12
  • Loading branch information
dogukan10 authored Nov 11, 2020
2 parents 81c3b2d + 35e093b commit ff2a3ac
Show file tree
Hide file tree
Showing 5 changed files with 133 additions and 53 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ public enum NimbleExceptionMessageCode {
INTERNAL_SERVER_ERROR_GET_PROCESS_INSTANCE_GROUP_FILTERS("INTERNAL_SERVER_ERROR.getProcessInstanceGroupFilters"),
INTERNAL_SERVER_ERROR_GET_PROCESS_INSTANCE_GROUPS("INTERNAL_SERVER_ERROR.getProcessInstanceGroups"),
INTERNAL_SERVER_ERROR_GET_PROCESS_INSTANCE_ID_FOR_DOCUMENT("INTERNAL_SERVER_ERROR.getProcessInstanceIdForDocument"),
INTERNAL_SERVER_ERROR_GET_RATINGS_SUMMARY("INTERNAL_SERVER_ERROR.getRatingsSummary"),
INTERNAL_SERVER_ERROR_GET_STATISTICS("INTERNAL_SERVER_ERROR.getStatistics"),
INTERNAL_SERVER_ERROR_GET_TRADING_VOLUME("INTERNAL_SERVER_ERROR.getTradingVolume"),
INTERNAL_SERVER_ERROR_IS_RATED("INTERNAL_SERVER_ERROR.isRated"),
Expand Down
64 changes: 11 additions & 53 deletions src/main/java/eu/nimble/service/bp/impl/TrustServiceController.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import eu.nimble.service.bp.util.persistence.catalogue.PartyPersistenceUtility;
import eu.nimble.service.bp.util.persistence.catalogue.TrustPersistenceUtility;
import eu.nimble.service.bp.util.spring.SpringBridge;
import eu.nimble.service.bp.util.trust.TrustUtility;
import eu.nimble.service.model.ubl.commonaggregatecomponents.*;
import eu.nimble.utility.ExecutionContext;
import eu.nimble.utility.JsonSerializationUtility;
Expand All @@ -33,7 +34,7 @@
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

import java.math.BigDecimal;
import java.io.IOException;
import java.util.Arrays;
import java.util.List;

Expand Down Expand Up @@ -169,12 +170,19 @@ public ResponseEntity getRatingsSummary(@ApiParam(value = "Identifier of the par
throw new NimbleException(NimbleExceptionMessageCode.UNAUTHORIZED_INVALID_ROLE.toString());
}

// check party
// check qualifying party
QualifyingPartyType qualifyingParty = PartyPersistenceUtility.getQualifyingParty(partyId,federationId);
if (qualifyingParty == null) {
throw new NimbleException(NimbleExceptionMessageCode.BAD_REQUEST_NO_QUALIFYING_PARTY.toString(), Arrays.asList(partyId));
}
JSONObject jsonResponse = createJSONResponse(qualifyingParty.getCompletedTask());
// retrieve the party
PartyType party = null;
try {
party = SpringBridge.getInstance().getiIdentityClientTyped().getParty(bearerToken,partyId);
} catch (IOException e) {
throw new NimbleException(NimbleExceptionMessageCode.INTERNAL_SERVER_ERROR_GET_RATINGS_SUMMARY.toString(), Arrays.asList(partyId));
}
JSONObject jsonResponse = TrustUtility.createRatingSummaryJson(qualifyingParty.getCompletedTask(),party.getProcessID());
logger.info("Retrieved ratings summary for the party with id: {}",partyId);
return ResponseEntity.ok(jsonResponse.toString());
}
Expand Down Expand Up @@ -220,56 +228,6 @@ public ResponseEntity listAllIndividualRatingsAndReviews(@ApiParam(value = "Iden
}
}

private JSONObject createJSONResponse(List<CompletedTaskType> completedTasks){
// rating summary for the company
BigDecimal totalNumberOfRatings = BigDecimal.ZERO;
BigDecimal qualityOfNegotiationProcess = BigDecimal.ZERO;
BigDecimal qualityOfOrderingProcess = BigDecimal.ZERO;
BigDecimal responseTimeRating = BigDecimal.ZERO;
BigDecimal listingAccuracy = BigDecimal.ZERO;
BigDecimal conformanceToContractualTerms = BigDecimal.ZERO;
BigDecimal deliveryAndPackaging = BigDecimal.ZERO;
for(CompletedTaskType completedTask:completedTasks){
if(completedTask.getEvidenceSupplied().size() == 0){
continue;
}
else{
totalNumberOfRatings = totalNumberOfRatings.add(BigDecimal.ONE);
}
for(EvidenceSuppliedType evidenceSupplied:completedTask.getEvidenceSupplied()){
if(evidenceSupplied.getID().equals("QualityOfTheNegotiationProcess")){
qualityOfNegotiationProcess = qualityOfNegotiationProcess.add(evidenceSupplied.getValueDecimal());
}
else if(evidenceSupplied.getID().equals("QualityOfTheOrderingProcess")){
qualityOfOrderingProcess = qualityOfOrderingProcess.add(evidenceSupplied.getValueDecimal());
}
else if(evidenceSupplied.getID().equals("ResponseTime")){
responseTimeRating = responseTimeRating.add(evidenceSupplied.getValueDecimal());
}
else if(evidenceSupplied.getID().equals("ProductListingAccuracy")){
listingAccuracy = listingAccuracy.add(evidenceSupplied.getValueDecimal());
}
else if(evidenceSupplied.getID().equals("ConformanceToOtherAgreedTerms")){
conformanceToContractualTerms = conformanceToContractualTerms.add(evidenceSupplied.getValueDecimal());
}
else if(evidenceSupplied.getID().equals("DeliveryAndPackaging")){
deliveryAndPackaging = deliveryAndPackaging.add(evidenceSupplied.getValueDecimal());
}
}
}
// create JSON response
JSONObject jsonResponse = new JSONObject();
jsonResponse.put("totalNumberOfRatings",totalNumberOfRatings);
jsonResponse.put("qualityOfNegotiationProcess",qualityOfNegotiationProcess);
jsonResponse.put("qualityOfOrderingProcess",qualityOfOrderingProcess);
jsonResponse.put("responseTimeRating",responseTimeRating);
jsonResponse.put("listingAccuracy",listingAccuracy);
jsonResponse.put("conformanceToContractualTerms",conformanceToContractualTerms);
jsonResponse.put("deliveryAndPackaging",deliveryAndPackaging);

return jsonResponse;
}

private String validateFederationIdHeader(String federationIdHeader){
if(federationIdHeader == null){
federationIdHeader = SpringBridge.getInstance().getFederationId();
Expand Down
119 changes: 119 additions & 0 deletions src/main/java/eu/nimble/service/bp/util/trust/TrustUtility.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
package eu.nimble.service.bp.util.trust;

import eu.nimble.service.bp.util.bp.ClassProcessTypeMap;
import eu.nimble.service.model.ubl.commonaggregatecomponents.CompletedTaskType;
import eu.nimble.service.model.ubl.commonaggregatecomponents.EvidenceSuppliedType;
import org.json.JSONObject;

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

public class TrustUtility {

/**
* Returns the rating summary as json
*
* @param completedTasks the completed tasks of company
* @param processIds the identifiers of business processes applicable for the company
* @return JSON consisting of the total number of ratings and average values for sub-ratings
*/
public static JSONObject createRatingSummaryJson(List<CompletedTaskType> completedTasks, List<String> processIds) {
// rating summary for the company
BigDecimal totalNumberOfRatings = BigDecimal.ZERO;
List<BigDecimal> qualityOfNegotiationProcess = new ArrayList<>();
List<BigDecimal> qualityOfOrderingProcess = new ArrayList<>();
List<BigDecimal> responseTimeRating = new ArrayList<>();
List<BigDecimal> listingAccuracy = new ArrayList<>();
List<BigDecimal> conformanceToContractualTerms = new ArrayList<>();
List<BigDecimal> deliveryAndPackaging = new ArrayList<>();

// get applicable sub-ratings for the process ids
List<String> applicableRatings = getSubRatingsForBusinessProcesses(processIds);

for (CompletedTaskType completedTask : completedTasks) {
if (completedTask.getEvidenceSupplied().size() == 0) {
continue;
}
boolean incrementTotalNumberOfRatings = false;
for (EvidenceSuppliedType evidenceSupplied : completedTask.getEvidenceSupplied()) {
if (applicableRatings.contains(evidenceSupplied.getID())) {
incrementTotalNumberOfRatings = true;
switch (evidenceSupplied.getID()) {
case "QualityOfTheNegotiationProcess":
qualityOfNegotiationProcess.add(evidenceSupplied.getValueDecimal());
break;
case "QualityOfTheOrderingProcess":
qualityOfOrderingProcess.add(evidenceSupplied.getValueDecimal());
break;
case "ResponseTime":
responseTimeRating.add(evidenceSupplied.getValueDecimal());
break;
case "ProductListingAccuracy":
listingAccuracy.add(evidenceSupplied.getValueDecimal());
break;
case "ConformanceToOtherAgreedTerms":
conformanceToContractualTerms.add(evidenceSupplied.getValueDecimal());
break;
case "DeliveryAndPackaging":
deliveryAndPackaging.add(evidenceSupplied.getValueDecimal());
break;
}
}
}
if (incrementTotalNumberOfRatings) {
totalNumberOfRatings = totalNumberOfRatings.add(BigDecimal.ONE);
}
}
// create JSON response
JSONObject jsonResponse = new JSONObject();
jsonResponse.put("totalNumberOfRatings", totalNumberOfRatings);
jsonResponse.put("qualityOfNegotiationProcess", qualityOfNegotiationProcess.stream().filter(TrustUtility::isNotNullOrZero).mapToLong(BigDecimal::longValue).average().orElse(0));
jsonResponse.put("qualityOfOrderingProcess", qualityOfOrderingProcess.stream().filter(TrustUtility::isNotNullOrZero).mapToLong(BigDecimal::longValue).average().orElse(0));
jsonResponse.put("responseTimeRating", responseTimeRating.stream().filter(TrustUtility::isNotNullOrZero).mapToLong(BigDecimal::longValue).average().orElse(0));
jsonResponse.put("listingAccuracy", listingAccuracy.stream().filter(TrustUtility::isNotNullOrZero).mapToLong(BigDecimal::longValue).average().orElse(0));
jsonResponse.put("conformanceToContractualTerms", conformanceToContractualTerms.stream().filter(TrustUtility::isNotNullOrZero).mapToLong(BigDecimal::longValue).average().orElse(0));
jsonResponse.put("deliveryAndPackaging", deliveryAndPackaging.stream().filter(TrustUtility::isNotNullOrZero).mapToLong(BigDecimal::longValue).average().orElse(0));

return jsonResponse;
}

/**
* Returns the applicable sub-ratings for the given business processes
*
* @param processIds the business process ids
* @return the list of applicable sub-ratings for the given business processes
*/
private static List<String> getSubRatingsForBusinessProcesses(List<String> processIds) {
List<String> ratings = new ArrayList<>();
// if no process is specified, assume that all ratings are available
if (processIds == null || processIds.size() == 0) {
ratings.add("QualityOfTheNegotiationProcess");
ratings.add("QualityOfTheOrderingProcess");
ratings.add("ResponseTime");
ratings.add("ProductListingAccuracy");
ratings.add("ConformanceToOtherAgreedTerms");
ratings.add("DeliveryAndPackaging");
} else {
if (processIds.contains(ClassProcessTypeMap.CAMUNDA_PROCESS_ID_PPAP) || processIds.contains(ClassProcessTypeMap.CAMUNDA_PROCESS_ID_ITEM_INFORMATION_REQUEST)) {
ratings.add("ProductListingAccuracy");
ratings.add("ConformanceToOtherAgreedTerms");
}
if (processIds.contains(ClassProcessTypeMap.CAMUNDA_PROCESS_ID_NEGOTIATION)) {
ratings.add("QualityOfTheNegotiationProcess");
ratings.add("ResponseTime");
}
if (processIds.contains(ClassProcessTypeMap.CAMUNDA_PROCESS_ID_ORDER) || processIds.contains(ClassProcessTypeMap.CAMUNDA_PROCESS_ID_TRANSPORT_EXECUTION_PLAN)) {
ratings.add("QualityOfTheOrderingProcess");
}
if (processIds.contains(ClassProcessTypeMap.CAMUNDA_PROCESS_ID_FULFILMENT)) {
ratings.add("DeliveryAndPackaging");
}
}
return ratings;
}

private static boolean isNotNullOrZero(BigDecimal d) {
return d != null && d.compareTo(BigDecimal.ZERO) != 0;
}
}
1 change: 1 addition & 0 deletions src/main/resources/messages.properties
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ INTERNAL_SERVER_ERROR.getFederatedMetadata=Failed to read Federated Collaboratio
INTERNAL_SERVER_ERROR.unmergeGroups=Failed to unmerge group
INTERNAL_SERVER_ERROR.failedToDeserializeFederatedMetadata=Failed to deserialize federatedCollaborationGroupMetadata
INTERNAL_SERVER_ERROR.completeProcess=Failed to complete process for the given document
INTERNAL_SERVER_ERROR.getRatingsSummary=Unexpected error while retrieving the ratings summary for the party: {0}
INTERNAL_SERVER_ERROR.failedToSendDocumentToInitiatorParty=Failed to send the document to the initiator party {0}, endpoint: {1} : {2}
INTERNAL_SERVER_ERROR.failedToSerializeRFQSummary=Unexpected error while serializing the RFQSummary
INTERNAL_SERVER_ERROR.getNegotiationSettings=Unexpected error while getting negotiation settings for the party: {0}
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/messages_es.properties
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ INTERNAL_SERVER_ERROR.getFederatedMetadata=Failed to read Federated Collaboratio
INTERNAL_SERVER_ERROR.unmergeGroups=Failed to unmerge group
INTERNAL_SERVER_ERROR.failedToDeserializeFederatedMetadata=Failed to deserialize federatedCollaborationGroupMetadata
INTERNAL_SERVER_ERROR.completeProcess=Failed to complete process for the given document
INTERNAL_SERVER_ERROR.getRatingsSummary=Unexpected error while retrieving the ratings summary for the party: {0}
INTERNAL_SERVER_ERROR.failedToSendDocumentToInitiatorParty=Failed to send the document to the initiator party {0}, endpoint: {1} : {2}
INTERNAL_SERVER_ERROR.failedToSerializeRFQSummary=Unexpected error while serializing the RFQSummary
INTERNAL_SERVER_ERROR.getNegotiationSettings=Unexpected error while getting negotiation settings for the party: {0}
Expand Down

0 comments on commit ff2a3ac

Please sign in to comment.