Skip to content

Commit

Permalink
Merge pull request #100 from nimble-platform/staging
Browse files Browse the repository at this point in the history
Pull Request for Release 17.0.14
  • Loading branch information
dogukan10 authored Dec 16, 2020
2 parents fb58f6e + e65b0c0 commit c704ced
Show file tree
Hide file tree
Showing 10 changed files with 187 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ public enum NimbleExceptionMessageCode {
INTERNAL_SERVER_ERROR_GET_ORDER_DOCUMENT("INTERNAL_SERVER_ERROR.getOrderDocument"),
INTERNAL_SERVER_ERROR_GET_PROCESS_COUNT("INTERNAL_SERVER_ERROR.getProcessCount"),
INTERNAL_SERVER_ERROR_GET_PROCESS_COUNT_BREAK_DOWN("INTERNAL_SERVER_ERROR.getProcessCountBreakDown"),
INTERNAL_SERVER_ERROR_GET_PROCESS_DOCUMENT_METADATA_SUMMARIES("INTERNAL_SERVER_ERROR.getProcessDocumentMetadataSummaries"),
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"),
Expand Down
36 changes: 32 additions & 4 deletions src/main/java/eu/nimble/service/bp/impl/StatisticsController.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
package eu.nimble.service.bp.impl;

import eu.nimble.service.bp.config.RoleConfig;
import eu.nimble.service.bp.model.statistics.BusinessProcessCount;
import eu.nimble.service.bp.model.statistics.FulfilmentStatistics;
import eu.nimble.service.bp.model.statistics.NonOrderedProducts;
import eu.nimble.service.bp.model.statistics.OverallStatistics;
import eu.nimble.service.bp.model.statistics.*;
import eu.nimble.service.bp.util.bp.BusinessProcessUtility;
import eu.nimble.service.bp.util.controller.InputValidatorUtil;
import eu.nimble.service.bp.util.controller.ValidationResponse;
Expand Down Expand Up @@ -513,6 +510,37 @@ public ResponseEntity getFulfilmentStatistics(@ApiParam(value = "Identifier of t
return ResponseEntity.ok(serializedResponse);
}

@ApiOperation(value = "",notes = "Gets the process document metadata summaries")
@ApiResponses(value = {
@ApiResponse(code = 200, message = "Retrieved the process document metadata summaries successfully",response = ProcessDocumentMetadataSummary.class,responseContainer = "List"),
@ApiResponse(code = 401, message = "Invalid token. No user was found for the provided token"),
@ApiResponse(code = 500, message = "Unexpected error while getting the process document metadata summaries")
})
@RequestMapping(value = "/document-metadata",
produces = {"application/json"},
method = RequestMethod.GET)
public ResponseEntity getProcessDocumentMetadataSummaries(@ApiParam(value = "The Bearer token provided by the identity service" ,required=true ) @RequestHeader(value="Authorization", required=true) String bearerToken) throws NimbleException {

try {
// set request log of ExecutionContext
String requestLog = "Getting process document metadata summaries";
executionContext.setRequestLog(requestLog);

logger.info(requestLog);
// validate role
if(!validationUtil.validateRole(bearerToken,executionContext.getUserRoles(), RoleConfig.REQUIRED_ROLES_PURCHASES_OR_SALES_READ)) {
throw new NimbleException(NimbleExceptionMessageCode.UNAUTHORIZED_INVALID_ROLE.toString());
}

List<ProcessDocumentMetadataSummary> summaries = ProcessDocumentMetadataDAOUtility.getProcessDocumentMetadataSummaries(bearerToken);
logger.info("Retrieved process document metadata summaries");
return ResponseEntity.ok().body(summaries);

} catch (Exception e) {
throw new NimbleException(NimbleExceptionMessageCode.INTERNAL_SERVER_ERROR_GET_PROCESS_DOCUMENT_METADATA_SUMMARIES.toString(),e);
}
}


private String validateFederationIdHeader(String federationIdHeader){
if(federationIdHeader == null){
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
package eu.nimble.service.bp.model.statistics;

public class ProcessDocumentMetadataSummary {

private String submissionDate;
private String initiatorPartyID;
private String initiatorPartyName;
private String responderPartyID;
private String responderPartyName;
private String type;
private String status;

public ProcessDocumentMetadataSummary() {
}

public String getSubmissionDate() {
return submissionDate;
}

public void setSubmissionDate(String submissionDate) {
this.submissionDate = submissionDate;
}

public String getInitiatorPartyID() {
return initiatorPartyID;
}

public void setInitiatorPartyID(String initiatorPartyID) {
this.initiatorPartyID = initiatorPartyID;
}

public String getInitiatorPartyName() {
return initiatorPartyName;
}

public void setInitiatorPartyName(String initiatorPartyName) {
this.initiatorPartyName = initiatorPartyName;
}

public String getResponderPartyID() {
return responderPartyID;
}

public void setResponderPartyID(String responderPartyID) {
this.responderPartyID = responderPartyID;
}

public String getResponderPartyName() {
return responderPartyName;
}

public void setResponderPartyName(String responderPartyName) {
this.responderPartyName = responderPartyName;
}

public String getType() {
return type;
}

public void setType(String type) {
this.type = type;
}

public String getStatus() {
return status;
}

public void setStatus(String status) {
this.status = status;
}
}
24 changes: 7 additions & 17 deletions src/main/java/eu/nimble/service/bp/util/email/EmailSenderUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import eu.nimble.service.bp.exception.NimbleExceptionMessageCode;
import eu.nimble.service.bp.model.hyperjaxb.*;
import eu.nimble.service.bp.util.persistence.bp.ProcessDocumentMetadataDAOUtility;
import eu.nimble.service.bp.util.persistence.catalogue.PartyPersistenceUtility;
import eu.nimble.service.bp.util.spring.SpringBridge;
import eu.nimble.service.model.ubl.commonaggregatecomponents.PartyType;
import eu.nimble.service.model.ubl.commonaggregatecomponents.PersonType;
Expand Down Expand Up @@ -163,7 +164,7 @@ public void sendNewDeliveryDateEmail(String bearerToken, Date newDeliveryDate, S
// trading partner of the party in this collaboration
PartyType tradingPartner = null;
try {
tradingPartner = getParty(buyerPartyId,buyerPartyFederationId,bearerToken);
tradingPartner = PartyPersistenceUtility.getParty(buyerPartyId,buyerPartyFederationId,bearerToken);
} catch (IOException e) {
logger.error("Failed to send the new delivery date information to buyer party: {}", buyerPartyId);
logger.error("Failed to get party with id: {} from identity service", buyerPartyId, e);
Expand Down Expand Up @@ -229,11 +230,11 @@ public void sendBusinessProcessStatusEmail(String bearerToken, String originalBe

try {
if (processDocumentStatus.equals(ProcessDocumentStatus.WAITINGRESPONSE)) {
respondingParty = getParty(processDocumentMetadataDAO.getResponderID(),processDocumentMetadataDAO.getResponderFederationID(),bearerToken);
initiatingParty = getParty(processDocumentMetadataDAO.getInitiatorID(),processDocumentMetadataDAO.getInitiatorFederationID(),bearerToken);
respondingParty = PartyPersistenceUtility.getParty(processDocumentMetadataDAO.getResponderID(),processDocumentMetadataDAO.getResponderFederationID(),bearerToken);
initiatingParty = PartyPersistenceUtility.getParty(processDocumentMetadataDAO.getInitiatorID(),processDocumentMetadataDAO.getInitiatorFederationID(),bearerToken);
}else {
respondingParty = getParty(processDocumentMetadataDAO.getInitiatorID(),processDocumentMetadataDAO.getInitiatorFederationID(),bearerToken);
initiatingParty = getParty(processDocumentMetadataDAO.getResponderID(),processDocumentMetadataDAO.getResponderFederationID(),bearerToken);
respondingParty = PartyPersistenceUtility.getParty(processDocumentMetadataDAO.getInitiatorID(),processDocumentMetadataDAO.getInitiatorFederationID(),bearerToken);
initiatingParty = PartyPersistenceUtility.getParty(processDocumentMetadataDAO.getResponderID(),processDocumentMetadataDAO.getResponderFederationID(),bearerToken);
}

} catch (IOException e) {
Expand Down Expand Up @@ -332,7 +333,7 @@ public void sendTrustScoreUpdateEmail(String partyID, String federationID, Strin
new Thread(() -> {
PartyType partyType = null;
try {
partyType = getParty(partyID,federationID,bearerToken);
partyType = PartyPersistenceUtility.getParty(partyID,federationID,bearerToken);
} catch (IOException e) {
logger.error("Failed to get party with id: {} from identity service", partyID, e);
return;
Expand Down Expand Up @@ -440,17 +441,6 @@ public void notifyPartyOnNewDeliveryDate(String toEmail,String productName, Stri
}

/* Helper Methods */
private PartyType getParty(String partyId,String federationId,String bearerToken) throws IOException {
PartyType party = null;
if(federationId.contentEquals(SpringBridge.getInstance().getFederationId())){
party = iIdentityClientTyped.getParty(bearerToken, partyId,true);
}
else {
Response response = SpringBridge.getInstance().getDelegateClient().getParty(bearerToken, Long.valueOf(partyId),true,federationId);
party = JsonSerializationUtility.getObjectMapper().readValue(HttpResponseUtil.extractBodyFromFeignClientResponse(response),PartyType.class);
}
return party;
}

private PersonType getPerson(String personId,String federationId,String bearerToken) throws IOException {
PersonType person = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@
import eu.nimble.service.bp.model.hyperjaxb.RoleType;
import eu.nimble.service.bp.model.export.TransactionSummary;
import eu.nimble.service.bp.model.statistics.BusinessProcessCount;
import eu.nimble.service.bp.model.statistics.ProcessDocumentMetadataSummary;
import eu.nimble.service.bp.util.bp.BusinessProcessUtility;
import eu.nimble.service.bp.util.bp.DocumentEnumClassMapper;
import eu.nimble.service.bp.util.persistence.catalogue.DocumentPersistenceUtility;
import eu.nimble.service.bp.util.persistence.catalogue.PartyPersistenceUtility;
import eu.nimble.service.bp.util.spring.SpringBridge;
import eu.nimble.service.bp.processor.BusinessProcessContext;
import eu.nimble.service.bp.processor.BusinessProcessContextHandler;
Expand All @@ -29,10 +31,7 @@
import org.slf4j.LoggerFactory;

import java.io.IOException;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.*;
import java.util.concurrent.*;

/**
Expand Down Expand Up @@ -716,6 +715,50 @@ public static ProcessDocumentMetadata getResponseMetadata(String processInstance
return HibernateSwaggerObjectMapper.createProcessDocumentMetadata(processDocumentDAO);
}

public static List<ProcessDocumentMetadataSummary> getProcessDocumentMetadataSummaries(String bearerToken) throws IOException {
List<ProcessDocumentMetadataSummary> summaries = new ArrayList<>();
// get all process document metadata dao
List<ProcessDocumentMetadataDAO> processDocumentMetadataDAOS = new JPARepositoryFactory().forBpRepository().getEntities(ProcessDocumentMetadataDAO.class);
// party name map
// the key is the concatenation of party id and federation id in the following format: <PARTY_ID>-<FEDERATION_ID>
Map<String,String> partyNameMap = new HashMap<>();
// create summaries
for (ProcessDocumentMetadataDAO processDocumentMetadataDAO : processDocumentMetadataDAOS) {
ProcessDocumentMetadataSummary summary = new ProcessDocumentMetadataSummary();
summary.setInitiatorPartyID(processDocumentMetadataDAO.getInitiatorID());
summary.setResponderPartyID(processDocumentMetadataDAO.getResponderID());
summary.setType(processDocumentMetadataDAO.getType().value());
summary.setStatus(processDocumentMetadataDAO.getStatus().value());
summary.setSubmissionDate(processDocumentMetadataDAO.getSubmissionDate());
// retrieve party names
String initiatorPartyNameKey = String.format("%s-%s",processDocumentMetadataDAO.getInitiatorID(),processDocumentMetadataDAO.getInitiatorFederationID());
String responderPartyNameKey = String.format("%s-%s",processDocumentMetadataDAO.getResponderID(),processDocumentMetadataDAO.getResponderFederationID());
String initiatorPartyName;
String responderPartyName;
if (partyNameMap.containsKey(initiatorPartyNameKey)) {
initiatorPartyName = partyNameMap.get(initiatorPartyNameKey);
} else{
PartyType initiatorParty = PartyPersistenceUtility.getParty(processDocumentMetadataDAO.getInitiatorID(),processDocumentMetadataDAO.getInitiatorFederationID(),bearerToken);
initiatorPartyName = initiatorParty.getPartyName().get(0).getName().getValue();
partyNameMap.put(initiatorPartyNameKey,initiatorPartyName);
}

if (partyNameMap.containsKey(responderPartyNameKey)) {
responderPartyName = partyNameMap.get(responderPartyNameKey);
} else{
PartyType responderParty = PartyPersistenceUtility.getParty(processDocumentMetadataDAO.getResponderID(),processDocumentMetadataDAO.getResponderFederationID(),bearerToken);
responderPartyName = responderParty.getPartyName().get(0).getName().getValue();
partyNameMap.put(responderPartyNameKey,initiatorPartyName);
}

summary.setInitiatorPartyName(initiatorPartyName);
summary.setResponderPartyName(responderPartyName);

summaries.add(summary);
}
return summaries;
}

public static List<String> getUnshippedOrderIds() {
return getUnshippedOrderIds(null,null);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@
import eu.nimble.service.model.ubl.commonaggregatecomponents.PartyType;
import eu.nimble.service.model.ubl.commonaggregatecomponents.PersonType;
import eu.nimble.service.model.ubl.commonaggregatecomponents.QualifyingPartyType;
import eu.nimble.utility.HttpResponseUtil;
import eu.nimble.utility.JsonSerializationUtility;
import eu.nimble.utility.persistence.GenericJPARepository;
import eu.nimble.utility.persistence.JPARepositoryFactory;
import feign.Response;
import org.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -197,4 +199,20 @@ public static PartyType getParty(String bearerToken, PartyType partyType) throws
PartyType party = SpringBridge.getInstance().getiIdentityClientTyped().getParty(bearerToken,partyType.getPartyIdentification().get(0).getID());
return party == null ? partyType : party;
}

/**
* Retrieve the party info for the given party and federation id. Based on the given federation id, the party info is taken from the identity-service
* or it is taken from the delegate client
* */
public static PartyType getParty(String partyId,String federationId,String bearerToken) throws IOException {
PartyType party = null;
if(federationId.contentEquals(SpringBridge.getInstance().getFederationId())){
party = SpringBridge.getInstance().getiIdentityClientTyped().getParty(bearerToken, partyId,true);
}
else {
Response response = SpringBridge.getInstance().getDelegateClient().getParty(bearerToken, Long.valueOf(partyId),true,federationId);
party = JsonSerializationUtility.getObjectMapper().readValue(HttpResponseUtil.extractBodyFromFeignClientResponse(response),PartyType.class);
}
return party;
}
}
1 change: 1 addition & 0 deletions src/main/resources/messages.properties
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ INTERNAL_SERVER_ERROR.sendPaymentLog=Failed to send payment log for order {0}
INTERNAL_SERVER_ERROR.getCatalogueLineForEPCCode=Unexpected error while getting CatalogueLine for the epc: {0}
INTERNAL_SERVER_ERROR.getProcessCount=Unexpected error while getting the total number for business process type: {0}, start date: {1}, end date: {2}, partyId id: {3}, role: {4}, state: {5}
INTERNAL_SERVER_ERROR.getProcessCountBreakDown=Unexpected error while getting the total number for start date: {0}, end date: {1}, party id: {2}, role: {3}
INTERNAL_SERVER_ERROR.getProcessDocumentMetadataSummaries=Unexpected error while getting the process document metadata summaries
INTERNAL_SERVER_ERROR.getNonOrderedProducts=Unexpected error while getting the non-ordered products for party id: {0}
INTERNAL_SERVER_ERROR.getTradingVolume=Unexpected error while getting the trading volume for start date: {0}, end date: {1}, party id: {2}, role: {3}, state: {4}
INTERNAL_SERVER_ERROR.getInactiveCompanies=Unexpected error while getting the inactive companies
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 @@ -61,6 +61,7 @@ INTERNAL_SERVER_ERROR.sendPaymentLog=Failed to send payment log for order {0}
INTERNAL_SERVER_ERROR.getCatalogueLineForEPCCode=Unexpected error while getting CatalogueLine for the epc: {0}
INTERNAL_SERVER_ERROR.getProcessCount=Unexpected error while getting the total number for business process type: {0}, start date: {1}, end date: {2}, partyId id: {3}, role: {4}, state: {5}
INTERNAL_SERVER_ERROR.getProcessCountBreakDown=Unexpected error while getting the total number for start date: {0}, end date: {1}, party id: {2}, role: {3}
INTERNAL_SERVER_ERROR.getProcessDocumentMetadataSummaries=Unexpected error while getting the process document metadata summaries
INTERNAL_SERVER_ERROR.getNonOrderedProducts=Unexpected error while getting the non-ordered products for party id: {0}
INTERNAL_SERVER_ERROR.getTradingVolume=Unexpected error while getting the trading volume for start date: {0}, end date: {1}, party id: {2}, role: {3}, state: {4}
INTERNAL_SERVER_ERROR.getInactiveCompanies=Unexpected error while getting the inactive companies
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
import eu.nimble.service.bp.contract.ContractGenerator;
import eu.nimble.service.bp.model.dashboard.CollaborationGroupResponse;
import eu.nimble.service.bp.swagger.model.*;
import eu.nimble.service.bp.util.persistence.bp.CollaborationGroupDAOUtility;
import eu.nimble.service.bp.util.persistence.bp.ProcessInstanceGroupDAOUtility;
import eu.nimble.service.bp.util.persistence.catalogue.DocumentPersistenceUtility;
import eu.nimble.service.model.ubl.commonaggregatecomponents.ClauseType;
import eu.nimble.service.model.ubl.order.OrderType;
import eu.nimble.utility.JsonSerializationUtility;
Expand Down Expand Up @@ -66,6 +66,10 @@ public class BusinessProcessExecutionTest {
private final String partyID = "706";
private final String productName = "QDeneme";
private final String serviceName = "QService";
// fields for the dispatch request
private final String orderReferenceId = "146b213d-24a8-4645-a03f-193bc1a5d403";
private final String orderLineHjidPlaceholder = "ORDER_LINE_HJID";
// end of fields for the dispatch request

public static String buyerProcessInstanceGroupID;
public static String transportProviderProcessInstanceGroupID;
Expand Down Expand Up @@ -326,6 +330,9 @@ public void test14_TEPResponse() throws Exception {

public void test15_DispatchRequest() throws Exception {
String inputMessageAsString = IOUtils.toString(ProcessInstanceInputMessage.class.getResourceAsStream(dispatchRequestJSON));
// replace the placeholder with the order line hjid
OrderType order = (OrderType) DocumentPersistenceUtility.getUBLDocument(orderReferenceId, DocumentType.ORDER);
inputMessageAsString = inputMessageAsString.replace(orderLineHjidPlaceholder,order.getOrderLine().get(0).getHjid().toString());

// start business process
MockHttpServletRequestBuilder request = post("/process-document")
Expand Down
2 changes: 1 addition & 1 deletion src/test/resources/controller/dispatchRequestJSON.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3730,7 +3730,7 @@
}
},
"orderLineReference": {
"lineID":3432
"lineID": ORDER_LINE_HJID
},
"shipment": [
{
Expand Down

0 comments on commit c704ced

Please sign in to comment.