From 710c7375aaae96138ca7723384b9d3b9e8157b63 Mon Sep 17 00:00:00 2001 From: dogukan10 Date: Fri, 4 Dec 2020 15:32:01 +0300 Subject: [PATCH 1/3] modified dispatch request test so that the order line hjid is not hardcoded --- .../bp/impl/controller/BusinessProcessExecutionTest.java | 9 ++++++++- src/test/resources/controller/dispatchRequestJSON.txt | 2 +- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/test/java/eu/nimble/service/bp/impl/controller/BusinessProcessExecutionTest.java b/src/test/java/eu/nimble/service/bp/impl/controller/BusinessProcessExecutionTest.java index 9a1f474e..d98c4e44 100644 --- a/src/test/java/eu/nimble/service/bp/impl/controller/BusinessProcessExecutionTest.java +++ b/src/test/java/eu/nimble/service/bp/impl/controller/BusinessProcessExecutionTest.java @@ -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; @@ -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; @@ -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") diff --git a/src/test/resources/controller/dispatchRequestJSON.txt b/src/test/resources/controller/dispatchRequestJSON.txt index 118cf7d5..55e165f3 100644 --- a/src/test/resources/controller/dispatchRequestJSON.txt +++ b/src/test/resources/controller/dispatchRequestJSON.txt @@ -3730,7 +3730,7 @@ } }, "orderLineReference": { - "lineID":3432 + "lineID": ORDER_LINE_HJID }, "shipment": [ { From 1c8e9b7828a19affb6bdace92769c70f51ea5d21 Mon Sep 17 00:00:00 2001 From: dogukan10 Date: Tue, 15 Dec 2020 16:38:03 +0300 Subject: [PATCH 2/3] move getParty method to PartyPersistenceUtility --- .../bp/util/email/EmailSenderUtil.java | 24 ++++++------------- .../catalogue/PartyPersistenceUtility.java | 18 ++++++++++++++ 2 files changed, 25 insertions(+), 17 deletions(-) diff --git a/src/main/java/eu/nimble/service/bp/util/email/EmailSenderUtil.java b/src/main/java/eu/nimble/service/bp/util/email/EmailSenderUtil.java index 198348a3..c9a5685c 100644 --- a/src/main/java/eu/nimble/service/bp/util/email/EmailSenderUtil.java +++ b/src/main/java/eu/nimble/service/bp/util/email/EmailSenderUtil.java @@ -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; @@ -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); @@ -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) { @@ -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; @@ -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; diff --git a/src/main/java/eu/nimble/service/bp/util/persistence/catalogue/PartyPersistenceUtility.java b/src/main/java/eu/nimble/service/bp/util/persistence/catalogue/PartyPersistenceUtility.java index 928fdcb9..7b7d6682 100644 --- a/src/main/java/eu/nimble/service/bp/util/persistence/catalogue/PartyPersistenceUtility.java +++ b/src/main/java/eu/nimble/service/bp/util/persistence/catalogue/PartyPersistenceUtility.java @@ -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; @@ -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; + } } From e65b0c01b377fdb45da3817a5a9137b24ab80444 Mon Sep 17 00:00:00 2001 From: dogukan10 Date: Wed, 16 Dec 2020 09:30:37 +0300 Subject: [PATCH 3/3] add service to retrieve process document metadata summaries --- .../exception/NimbleExceptionMessageCode.java | 1 + .../service/bp/impl/StatisticsController.java | 36 ++++++++-- .../ProcessDocumentMetadataSummary.java | 71 +++++++++++++++++++ .../bp/ProcessDocumentMetadataDAOUtility.java | 51 +++++++++++-- src/main/resources/messages.properties | 1 + src/main/resources/messages_es.properties | 1 + 6 files changed, 153 insertions(+), 8 deletions(-) create mode 100644 src/main/java/eu/nimble/service/bp/model/statistics/ProcessDocumentMetadataSummary.java diff --git a/src/main/java/eu/nimble/service/bp/exception/NimbleExceptionMessageCode.java b/src/main/java/eu/nimble/service/bp/exception/NimbleExceptionMessageCode.java index 57ca5e5b..cf966ccd 100644 --- a/src/main/java/eu/nimble/service/bp/exception/NimbleExceptionMessageCode.java +++ b/src/main/java/eu/nimble/service/bp/exception/NimbleExceptionMessageCode.java @@ -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"), diff --git a/src/main/java/eu/nimble/service/bp/impl/StatisticsController.java b/src/main/java/eu/nimble/service/bp/impl/StatisticsController.java index bf1938ff..616e8147 100644 --- a/src/main/java/eu/nimble/service/bp/impl/StatisticsController.java +++ b/src/main/java/eu/nimble/service/bp/impl/StatisticsController.java @@ -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; @@ -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 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){ diff --git a/src/main/java/eu/nimble/service/bp/model/statistics/ProcessDocumentMetadataSummary.java b/src/main/java/eu/nimble/service/bp/model/statistics/ProcessDocumentMetadataSummary.java new file mode 100644 index 00000000..2d3df9b0 --- /dev/null +++ b/src/main/java/eu/nimble/service/bp/model/statistics/ProcessDocumentMetadataSummary.java @@ -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; + } +} diff --git a/src/main/java/eu/nimble/service/bp/util/persistence/bp/ProcessDocumentMetadataDAOUtility.java b/src/main/java/eu/nimble/service/bp/util/persistence/bp/ProcessDocumentMetadataDAOUtility.java index ae1251ff..3ea86775 100644 --- a/src/main/java/eu/nimble/service/bp/util/persistence/bp/ProcessDocumentMetadataDAOUtility.java +++ b/src/main/java/eu/nimble/service/bp/util/persistence/bp/ProcessDocumentMetadataDAOUtility.java @@ -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; @@ -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.*; /** @@ -716,6 +715,50 @@ public static ProcessDocumentMetadata getResponseMetadata(String processInstance return HibernateSwaggerObjectMapper.createProcessDocumentMetadata(processDocumentDAO); } + public static List getProcessDocumentMetadataSummaries(String bearerToken) throws IOException { + List summaries = new ArrayList<>(); + // get all process document metadata dao + List 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: - + Map 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 getUnshippedOrderIds() { return getUnshippedOrderIds(null,null); } diff --git a/src/main/resources/messages.properties b/src/main/resources/messages.properties index f9a4171d..0a9b7ed8 100644 --- a/src/main/resources/messages.properties +++ b/src/main/resources/messages.properties @@ -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 diff --git a/src/main/resources/messages_es.properties b/src/main/resources/messages_es.properties index e69d7689..9cd929aa 100644 --- a/src/main/resources/messages_es.properties +++ b/src/main/resources/messages_es.properties @@ -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