From d8bbd140dc7bf252da63597f52679f193dc979d3 Mon Sep 17 00:00:00 2001 From: Raj Shah Date: Wed, 23 Aug 2023 11:15:52 +0530 Subject: [PATCH 01/36] Added create event controller, services and lib changes --- pom.xml | 6 + .../api/controllers/EventController.java | 42 +++ .../formatter/CreateEventFormatterDto.java | 15 ++ .../api/dto/requestMapper/CreateEventDto.java | 31 +++ .../createEvent/CreateEventFactory.java | 42 +++ .../createEvent/CreateEventInterface.java | 15 ++ .../createEvent/CreateSalesforceEvent.java | 129 +++++++++ .../globalConstants/SalesforceConstants.java | 4 + .../dto/SalesforceCreateEventDto.java | 15 ++ .../services/events/CreateEventService.java | 37 +++ .../createEvent.scenarios.json | 244 ++++++++++++++++++ 11 files changed, 580 insertions(+) create mode 100644 src/main/java/com/salessparrow/api/controllers/EventController.java create mode 100644 src/main/java/com/salessparrow/api/dto/formatter/CreateEventFormatterDto.java create mode 100644 src/main/java/com/salessparrow/api/dto/requestMapper/CreateEventDto.java create mode 100644 src/main/java/com/salessparrow/api/lib/crmActions/createEvent/CreateEventFactory.java create mode 100644 src/main/java/com/salessparrow/api/lib/crmActions/createEvent/CreateEventInterface.java create mode 100644 src/main/java/com/salessparrow/api/lib/crmActions/createEvent/CreateSalesforceEvent.java create mode 100644 src/main/java/com/salessparrow/api/lib/salesforce/dto/SalesforceCreateEventDto.java create mode 100644 src/main/java/com/salessparrow/api/services/events/CreateEventService.java create mode 100644 src/test/resources/data/controllers/eventController/createEvent.scenarios.json diff --git a/pom.xml b/pom.xml index 17f637e0..3a09e0fb 100644 --- a/pom.xml +++ b/pom.xml @@ -48,6 +48,12 @@ 2.15.2 + + com.fasterxml.jackson.datatype + jackson-datatype-joda + 2.15.2 + + org.springframework.boot spring-boot-starter-test diff --git a/src/main/java/com/salessparrow/api/controllers/EventController.java b/src/main/java/com/salessparrow/api/controllers/EventController.java new file mode 100644 index 00000000..f1e40931 --- /dev/null +++ b/src/main/java/com/salessparrow/api/controllers/EventController.java @@ -0,0 +1,42 @@ +package com.salessparrow.api.controllers; + +import org.slf4j.Logger; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.ResponseEntity; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import com.salessparrow.api.dto.formatter.CreateEventFormatterDto; +import com.salessparrow.api.dto.requestMapper.CreateEventDto; +import com.salessparrow.api.services.events.CreateEventService; + +import jakarta.servlet.http.HttpServletRequest; +import jakarta.validation.Valid; + +@RestController +@RequestMapping("/api/v1/accounts/{account_id}/events") +@Validated +public class EventController { + private Logger logger = org.slf4j.LoggerFactory.getLogger(AccountController.class); + + @Autowired + private CreateEventService createEventService; + + @PostMapping("") + public ResponseEntity createEvent( + HttpServletRequest request, + @PathVariable("account_id") String accountId, + @Valid @RequestBody CreateEventDto createEventDto + ) { + logger.info("Create Event Request received"); + + CreateEventFormatterDto createEventFormatterDto = createEventService.createEvent(request, accountId, createEventDto); + + return ResponseEntity.ok().body(createEventFormatterDto); + } + +} diff --git a/src/main/java/com/salessparrow/api/dto/formatter/CreateEventFormatterDto.java b/src/main/java/com/salessparrow/api/dto/formatter/CreateEventFormatterDto.java new file mode 100644 index 00000000..b827a115 --- /dev/null +++ b/src/main/java/com/salessparrow/api/dto/formatter/CreateEventFormatterDto.java @@ -0,0 +1,15 @@ +package com.salessparrow.api.dto.formatter; + +import com.fasterxml.jackson.databind.PropertyNamingStrategies; +import com.fasterxml.jackson.databind.annotation.JsonNaming; + +import lombok.Data; + +/** + * CreateEventFormatterDto is a DTO class for the Create Event response. + */ +@Data +@JsonNaming(PropertyNamingStrategies.SnakeCaseStrategy.class) +public class CreateEventFormatterDto { + private String eventId; +} \ No newline at end of file diff --git a/src/main/java/com/salessparrow/api/dto/requestMapper/CreateEventDto.java b/src/main/java/com/salessparrow/api/dto/requestMapper/CreateEventDto.java new file mode 100644 index 00000000..791669d4 --- /dev/null +++ b/src/main/java/com/salessparrow/api/dto/requestMapper/CreateEventDto.java @@ -0,0 +1,31 @@ +package com.salessparrow.api.dto.requestMapper; + +import com.fasterxml.jackson.databind.PropertyNamingStrategies; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonNaming; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import org.joda.time.DateTime; + +import com.fasterxml.jackson.datatype.joda.deser.DateTimeDeserializer; +import com.fasterxml.jackson.datatype.joda.ser.DateTimeSerializer; + +import jakarta.validation.constraints.NotBlank; +import jakarta.validation.constraints.NotNull; +import lombok.Data; + +@JsonNaming(PropertyNamingStrategies.SnakeCaseStrategy.class) +@Data +public class CreateEventDto { + @NotBlank(message = "missing_description") + private String description; + + @JsonSerialize(using = DateTimeSerializer.class) + @JsonDeserialize(using = DateTimeDeserializer.class) + @NotNull(message = "missing_start_datetime") + private DateTime startDatetime; + + @JsonSerialize(using = DateTimeSerializer.class) + @JsonDeserialize(using = DateTimeDeserializer.class) + @NotNull(message = "missing_end_datetime") + private DateTime endDatetime; +} diff --git a/src/main/java/com/salessparrow/api/lib/crmActions/createEvent/CreateEventFactory.java b/src/main/java/com/salessparrow/api/lib/crmActions/createEvent/CreateEventFactory.java new file mode 100644 index 00000000..7ffab174 --- /dev/null +++ b/src/main/java/com/salessparrow/api/lib/crmActions/createEvent/CreateEventFactory.java @@ -0,0 +1,42 @@ +package com.salessparrow.api.lib.crmActions.createEvent; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +import com.salessparrow.api.domain.SalesforceUser; +import com.salessparrow.api.dto.formatter.CreateEventFormatterDto; +import com.salessparrow.api.dto.requestMapper.CreateEventDto; +import com.salessparrow.api.exception.CustomException; +import com.salessparrow.api.lib.errorLib.ErrorObject; +import com.salessparrow.api.lib.globalConstants.UserConstants; + +/** + * CreateEventFactory is a factory class for the create event action for the CRM. + */ +@Component +public class CreateEventFactory { + + @Autowired + private CreateSalesforceEvent createSalesforceEvent; + + /** + * Create an event for a given account + * @param user + * @param accountId + * + * @return CreateEventFormatterDto + **/ + public CreateEventFormatterDto createEvent(SalesforceUser user, String accountId, CreateEventDto createEventDto) { + + switch(user.getUserKind()) { + case UserConstants.SALESFORCE_USER_KIND: + return createSalesforceEvent.createEvent(user, accountId, createEventDto); + default: + throw new CustomException( + new ErrorObject( + "l_ca_ce_cef_ce_1", + "something_went_wrong", + "Invalid user kind.")); + } + } +} diff --git a/src/main/java/com/salessparrow/api/lib/crmActions/createEvent/CreateEventInterface.java b/src/main/java/com/salessparrow/api/lib/crmActions/createEvent/CreateEventInterface.java new file mode 100644 index 00000000..0cd6389a --- /dev/null +++ b/src/main/java/com/salessparrow/api/lib/crmActions/createEvent/CreateEventInterface.java @@ -0,0 +1,15 @@ +package com.salessparrow.api.lib.crmActions.createEvent; + +import org.springframework.stereotype.Component; + +import com.salessparrow.api.domain.SalesforceUser; +import com.salessparrow.api.dto.formatter.CreateEventFormatterDto; +import com.salessparrow.api.dto.requestMapper.CreateEventDto; + +/** + * CreateEventInterface is an interface for the create event action for the CRM. + */ +@Component +public interface CreateEventInterface { + public CreateEventFormatterDto createEvent(SalesforceUser user, String accountId, CreateEventDto createEventDto); +} diff --git a/src/main/java/com/salessparrow/api/lib/crmActions/createEvent/CreateSalesforceEvent.java b/src/main/java/com/salessparrow/api/lib/crmActions/createEvent/CreateSalesforceEvent.java new file mode 100644 index 00000000..b6e757ad --- /dev/null +++ b/src/main/java/com/salessparrow/api/lib/crmActions/createEvent/CreateSalesforceEvent.java @@ -0,0 +1,129 @@ +package com.salessparrow.api.lib.crmActions.createEvent; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +import com.fasterxml.jackson.databind.DeserializationFeature; +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.salessparrow.api.domain.SalesforceUser; +import com.salessparrow.api.dto.formatter.CreateEventFormatterDto; +import com.salessparrow.api.dto.requestMapper.CreateEventDto; +import com.salessparrow.api.exception.CustomException; +import com.salessparrow.api.lib.Base64Helper; +import com.salessparrow.api.lib.Util; +import com.salessparrow.api.lib.errorLib.ErrorObject; +import com.salessparrow.api.lib.globalConstants.SalesforceConstants; +import com.salessparrow.api.lib.httpLib.HttpClient; +import com.salessparrow.api.lib.salesforce.dto.CompositeRequestDto; +import com.salessparrow.api.lib.salesforce.dto.SalesforceCreateEventDto; +import com.salessparrow.api.lib.salesforce.helper.MakeCompositeRequest; + +/** + * CreateSalesforceEvent is a class that creates an event for an account in Salesforce. + */ +@Component +public class CreateSalesforceEvent implements CreateEventInterface { + + @Autowired + private SalesforceConstants salesforceConstants; + + @Autowired + private MakeCompositeRequest makeCompositeRequest; + + @Autowired + private Base64Helper base64Helper; + + /** + * Create an event for a given account. + * + * @param user + * @param accountId + * @param createEventDto + * + * @return CreateEventFormatterDto + */ + public CreateEventFormatterDto createEvent(SalesforceUser user, String accountId, CreateEventDto createEventDto) { + String salesforceUserId = user.getExternalUserId(); + + String eventSubject = getEventSubjectFromDescription(createEventDto); + // String eventDescription = base64Helper.base64Encode(createEventDto.getDescription()); + + Map createEventBody = new HashMap(); + createEventBody.put("Subject", eventSubject); + createEventBody.put("Description", createEventDto.getDescription()); + createEventBody.put("WhatId", accountId); + createEventBody.put("StartDateTime", createEventDto.getStartDatetime().toString()); + createEventBody.put("EndDateTime", createEventDto.getEndDatetime().toString()); + + CompositeRequestDto createEventCompositeRequestDto = new CompositeRequestDto( + "POST", + salesforceConstants.salesforceCreateEventUrl(), + "CreateEvent", + createEventBody + ); + + List compositeRequests = new ArrayList(); + compositeRequests.add(createEventCompositeRequestDto); + + HttpClient.HttpResponse response = makeCompositeRequest.makePostRequest(compositeRequests, salesforceUserId); + + return parseResponse(response.getResponseBody()); + } + + /** + * Parse the response from Salesforce. + * + * @param createEventResponse + * + * @return CreateEventFormatterDto - formatted response + */ + private CreateEventFormatterDto parseResponse(String createEventResponse) { + Util util = new Util(); + JsonNode rootNode = util.getJsonNode(createEventResponse); + + JsonNode createEventCompositeResponse = rootNode.get("compositeResponse").get(0); + Integer createEventStatusCode = createEventCompositeResponse.get("httpStatusCode").asInt(); + + if (createEventStatusCode != 200 && createEventStatusCode != 201) { + String errorBody = createEventCompositeResponse.get("body").asText(); + + throw new CustomException( + new ErrorObject( + "l_ca_ce_cse_pr_1", + "internal_server_error", + errorBody)); + } + + JsonNode createEventNodeResponseBody = rootNode.get("compositeResponse").get(0).get("body"); + + ObjectMapper mapper = new ObjectMapper(); + mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES); + SalesforceCreateEventDto salesforceCreateEventDto = mapper.convertValue(createEventNodeResponseBody, SalesforceCreateEventDto.class); + + CreateEventFormatterDto createEventFormatterDto = new CreateEventFormatterDto(); + createEventFormatterDto.setEventId(salesforceCreateEventDto.getId()); + + return createEventFormatterDto; + } + + /** + * Get the first 60 characters of the event description. + * + * @param createEventDto + * + * @return String + */ + private String getEventSubjectFromDescription(CreateEventDto createEventDto) { + if (createEventDto.getDescription().length() < 60) { + return createEventDto.getDescription(); + } + + return createEventDto.getDescription().substring(0, 60); + } +} diff --git a/src/main/java/com/salessparrow/api/lib/globalConstants/SalesforceConstants.java b/src/main/java/com/salessparrow/api/lib/globalConstants/SalesforceConstants.java index d379d8d0..20e8af45 100644 --- a/src/main/java/com/salessparrow/api/lib/globalConstants/SalesforceConstants.java +++ b/src/main/java/com/salessparrow/api/lib/globalConstants/SalesforceConstants.java @@ -38,6 +38,10 @@ public String salesforceAttachNoteUrl() { return sObjectsPath() + "/ContentDocumentLink"; } + public String salesforceCreateEventUrl() { + return sObjectsPath() + "/Event"; + } + public String identityUrl() { return "/services/oauth2/userinfo"; } diff --git a/src/main/java/com/salessparrow/api/lib/salesforce/dto/SalesforceCreateEventDto.java b/src/main/java/com/salessparrow/api/lib/salesforce/dto/SalesforceCreateEventDto.java new file mode 100644 index 00000000..187d7555 --- /dev/null +++ b/src/main/java/com/salessparrow/api/lib/salesforce/dto/SalesforceCreateEventDto.java @@ -0,0 +1,15 @@ +package com.salessparrow.api.lib.salesforce.dto; + +import lombok.Data; + +/** + * DTO for the response of the Salesforce API when creating an event. + */ +@Data +public class SalesforceCreateEventDto { + String id; + + String success; + + String[] errors; +} diff --git a/src/main/java/com/salessparrow/api/services/events/CreateEventService.java b/src/main/java/com/salessparrow/api/services/events/CreateEventService.java new file mode 100644 index 00000000..86508318 --- /dev/null +++ b/src/main/java/com/salessparrow/api/services/events/CreateEventService.java @@ -0,0 +1,37 @@ +package com.salessparrow.api.services.events; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import com.salessparrow.api.domain.SalesforceUser; +import com.salessparrow.api.dto.formatter.CreateEventFormatterDto; +import com.salessparrow.api.dto.requestMapper.CreateEventDto; +import com.salessparrow.api.lib.crmActions.createEvent.CreateEventFactory; + +import jakarta.servlet.http.HttpServletRequest; + +/** + * CreateEventService is a service class for the create event action for the CRM. + */ +@Service +public class CreateEventService { + + @Autowired + private CreateEventFactory createEventFactory; + + /** + * Create an event for a specific account. + * + * @param request + * @param accountId + * @param createEventDto + * + * @return CreateEventFormatterDto + */ + public CreateEventFormatterDto createEvent(HttpServletRequest request, String accountId, CreateEventDto createEventDto) { + + SalesforceUser currentUser = (SalesforceUser) request.getAttribute("current_user"); + + return createEventFactory.createEvent(currentUser, accountId, createEventDto); + } +} diff --git a/src/test/resources/data/controllers/eventController/createEvent.scenarios.json b/src/test/resources/data/controllers/eventController/createEvent.scenarios.json new file mode 100644 index 00000000..0463c4b7 --- /dev/null +++ b/src/test/resources/data/controllers/eventController/createEvent.scenarios.json @@ -0,0 +1,244 @@ +[ + { + "description": "Should successfully create the event", + "input": { + "body": { + "description": "Here the event description will go and it is a long description with length of more than 100 characters", + "start_datetime": "2023-07-21T13:12:17.000+0000", + "end_datetime": "2023-07-21T14:12:17.000+0000" + }, + "accountId": "0011e00000bWSxdAAG" + }, + "mocks": { + "makeCompositeRequest": { + "compositeResponse": [ + { + "body": { + "id": "00U1e000003ToABEA0", + "success": true, + "errors": [] + }, + "httpHeaders": { + "Location": "/services/data/v58.0/sobjects/Event/00U1e000003ToABEA0" + }, + "httpStatusCode": 201, + "referenceId": "createEvent" + } + ] + } + }, + "output": { + "event_id": "00U1e000003ToABEA0" + } + }, + { + "description": "Should fail when the event description is empty", + "input": { + "body": { + "description": "", + "start_datetime": "2023-07-21T13:12:17.000+0000", + "end_datetime": "2023-07-21T14:12:17.000+0000" + }, + "accountId": "0011e00000bWSxdAAG" + }, + "mocks": {}, + "output": { + "http_code": 400, + "message": "At least one parameter is invalid or missing.", + "code": "INVALID_PARAMS", + "internal_error_identifier": "b_2", + "param_errors": [ + { + "parameter": "description", + "param_error_identifier": "missing_description", + "message": "description is required parameter. Please provide description." + } + ] + } + }, + { + "description": "Should fail when the event description is not provided", + "input": { + "body": { + "start_datetime": "2023-07-21T13:12:17.000+0000", + "end_datetime": "2023-07-21T14:12:17.000+0000" + }, + "accountId": "0011e00000bWSxdAAG" + }, + "mocks": {}, + "output": { + "http_code": 400, + "message": "At least one parameter is invalid or missing.", + "code": "INVALID_PARAMS", + "internal_error_identifier": "b_2", + "param_errors": [ + { + "parameter": "description", + "param_error_identifier": "missing_description", + "message": "description is required parameter. Please provide description." + } + ] + } + }, + { + "description": "Should fail when the event start_datetime is not provided", + "input": { + "body": { + "description":"Test Description", + "end_datetime": "2023-07-21T14:12:17.000+0000" + }, + "accountId": "0011e00000bWSxdAAG" + }, + "mocks": {}, + "output": { + "http_code": 400, + "message": "At least one parameter is invalid or missing.", + "code": "INVALID_PARAMS", + "internal_error_identifier": "b_2", + "param_errors": [ + { + "parameter": "description", + "param_error_identifier": "missing_description", + "message": "description is required parameter. Please provide description." + } + ] + } + }, + { + "description": "Should fail when the event end_datetime is not provided", + "input": { + "body": { + "description":"Test Description", + "start_datetime": "2023-07-21T13:12:17.000+0000" + }, + "accountId": "0011e00000bWSxdAAG" + }, + "mocks": {}, + "output": { + "http_code": 400, + "message": "At least one parameter is invalid or missing.", + "code": "INVALID_PARAMS", + "internal_error_identifier": "b_2", + "param_errors": [ + { + "parameter": "description", + "param_error_identifier": "missing_description", + "message": "description is required parameter. Please provide description." + } + ] + } + }, + { + "description": "Should fail when incorrect start_datetime format is provided", + "input": { + "body": { + "description":"Test Description", + "start_datetime": "07-2023-21T13:12:17.000+0000", + "end_datetime": "2023-07-21T14:12:17.000+0000" + }, + "accountId": "0011e00000bWSxdAAG" + }, + "mocks": {}, + "output": { + "http_code": 400, + "message": "Invalid datetime format.", + "code": "INVALID_PARAMS", + "internal_error_identifier": "b_2", + "param_errors": [ + { + "parameter": "start_datetime", + "param_error_identifier": "invalid_datetime_format", + "message": "start_datetime is invalid. Please provide valid datetime format." + } + ] + } + }, + { + "description": "Should fail when incorrect end_datetime format is provided", + "input": { + "body": { + "description":"Test Description", + "start_datetime": "2023-07-21T14:12:17.000+0000", + "end_datetime": "07-2023-21T13:12:17.000+0000" + }, + "accountId": "0011e00000bWSxdAAG" + }, + "mocks": {}, + "output": { + "http_code": 400, + "message": "Invalid datetime format.", + "code": "INVALID_PARAMS", + "internal_error_identifier": "b_2", + "param_errors": [ + { + "parameter": "end_datetime", + "param_error_identifier": "invalid_datetime_format", + "message": "Please provide valid datetime format." + } + ] + } + }, + { + "description": "Should fail when the account id invalid", + "input": { + "body": { + "description": "Here the event description will go and it is a long description with length of more than 100 characters", + "start_datetime": "2023-07-21T13:12:17.000+0000", + "end_datetime": "2023-07-21T14:12:17.000+0000" + }, + "accountId": "invalid" + }, + "mocks": { + "makeCompositeRequest": { + "compositeResponse": [ + { + "body": [ + { + "message": "Related To ID: id value of incorrect type: invalid", + "errorCode": "MALFORMED_ID", + "fields": [ + "WhatId" + ] + } + ], + "httpHeaders": {}, + "httpStatusCode": 400, + "referenceId": "createEvent" + } + ] + } + }, + "output": { + "http_code": 500, + "message": "Something went wrong.", + "code": "INTERNAL_SERVER_ERROR", + "internal_error_identifier": "l_ca_ce_cse_pr_1", + "param_errors": [] + } + }, + { + "description": "Should fail when description length is greater than 32000 characters", + "input": { + "body": { + "description":"Test Description to be extended in code upto more than 32000 characters", + "start_datetime": "2023-07-21T14:12:17.000+0000", + "end_datetime": "2023-07-21T14:12:17.000+0000" + }, + "accountId": "0011e00000bWSxdAAG" + }, + "mocks": {}, + "output": { + "http_code": 400, + "message": "Invalid datetime format.", + "code": "INVALID_PARAMS", + "internal_error_identifier": "b_2", + "param_errors": [ + { + "parameter": "end_datetime", + "param_error_identifier": "invalid_datetime_format", + "message": "Please provide valid datetime format." + } + ] + } + } +] \ No newline at end of file From e611e5adb235ffc14aaec4626f0473e1af9bfe75 Mon Sep 17 00:00:00 2001 From: Raj Shah Date: Wed, 23 Aug 2023 11:23:53 +0530 Subject: [PATCH 02/36] Added logs and renamed Event Controller file --- .../{EventController.java => AccountEventController.java} | 4 ++-- .../api/lib/crmActions/createEvent/CreateEventFactory.java | 3 +++ .../lib/crmActions/createEvent/CreateSalesforceEvent.java | 7 +++++++ .../api/services/events/CreateEventService.java | 3 +++ 4 files changed, 15 insertions(+), 2 deletions(-) rename src/main/java/com/salessparrow/api/controllers/{EventController.java => AccountEventController.java} (95%) diff --git a/src/main/java/com/salessparrow/api/controllers/EventController.java b/src/main/java/com/salessparrow/api/controllers/AccountEventController.java similarity index 95% rename from src/main/java/com/salessparrow/api/controllers/EventController.java rename to src/main/java/com/salessparrow/api/controllers/AccountEventController.java index f1e40931..8ed0d4a1 100644 --- a/src/main/java/com/salessparrow/api/controllers/EventController.java +++ b/src/main/java/com/salessparrow/api/controllers/AccountEventController.java @@ -20,8 +20,8 @@ @RestController @RequestMapping("/api/v1/accounts/{account_id}/events") @Validated -public class EventController { - private Logger logger = org.slf4j.LoggerFactory.getLogger(AccountController.class); +public class AccountEventController { + private Logger logger = org.slf4j.LoggerFactory.getLogger(AccountEventController.class); @Autowired private CreateEventService createEventService; diff --git a/src/main/java/com/salessparrow/api/lib/crmActions/createEvent/CreateEventFactory.java b/src/main/java/com/salessparrow/api/lib/crmActions/createEvent/CreateEventFactory.java index 7ffab174..c1c77a32 100644 --- a/src/main/java/com/salessparrow/api/lib/crmActions/createEvent/CreateEventFactory.java +++ b/src/main/java/com/salessparrow/api/lib/crmActions/createEvent/CreateEventFactory.java @@ -1,5 +1,6 @@ package com.salessparrow.api.lib.crmActions.createEvent; +import org.slf4j.Logger; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; @@ -15,6 +16,7 @@ */ @Component public class CreateEventFactory { + private Logger logger = org.slf4j.LoggerFactory.getLogger(CreateEventFactory.class); @Autowired private CreateSalesforceEvent createSalesforceEvent; @@ -27,6 +29,7 @@ public class CreateEventFactory { * @return CreateEventFormatterDto **/ public CreateEventFormatterDto createEvent(SalesforceUser user, String accountId, CreateEventDto createEventDto) { + logger.info("Create Event Factory started"); switch(user.getUserKind()) { case UserConstants.SALESFORCE_USER_KIND: diff --git a/src/main/java/com/salessparrow/api/lib/crmActions/createEvent/CreateSalesforceEvent.java b/src/main/java/com/salessparrow/api/lib/crmActions/createEvent/CreateSalesforceEvent.java index b6e757ad..563aa6c4 100644 --- a/src/main/java/com/salessparrow/api/lib/crmActions/createEvent/CreateSalesforceEvent.java +++ b/src/main/java/com/salessparrow/api/lib/crmActions/createEvent/CreateSalesforceEvent.java @@ -5,6 +5,7 @@ import java.util.List; import java.util.Map; +import org.slf4j.Logger; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; @@ -30,6 +31,8 @@ @Component public class CreateSalesforceEvent implements CreateEventInterface { + private Logger logger = org.slf4j.LoggerFactory.getLogger(CreateSalesforceEvent.class); + @Autowired private SalesforceConstants salesforceConstants; @@ -49,6 +52,8 @@ public class CreateSalesforceEvent implements CreateEventInterface { * @return CreateEventFormatterDto */ public CreateEventFormatterDto createEvent(SalesforceUser user, String accountId, CreateEventDto createEventDto) { + logger.info("Create Salesforce Event started"); + String salesforceUserId = user.getExternalUserId(); String eventSubject = getEventSubjectFromDescription(createEventDto); @@ -84,6 +89,8 @@ public CreateEventFormatterDto createEvent(SalesforceUser user, String accountId * @return CreateEventFormatterDto - formatted response */ private CreateEventFormatterDto parseResponse(String createEventResponse) { + logger.info("Parsing the response from Salesforce"); + Util util = new Util(); JsonNode rootNode = util.getJsonNode(createEventResponse); diff --git a/src/main/java/com/salessparrow/api/services/events/CreateEventService.java b/src/main/java/com/salessparrow/api/services/events/CreateEventService.java index 86508318..1d5a9d20 100644 --- a/src/main/java/com/salessparrow/api/services/events/CreateEventService.java +++ b/src/main/java/com/salessparrow/api/services/events/CreateEventService.java @@ -1,5 +1,6 @@ package com.salessparrow.api.services.events; +import org.slf4j.Logger; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -15,6 +16,7 @@ */ @Service public class CreateEventService { + private Logger logger = org.slf4j.LoggerFactory.getLogger(CreateEventService.class); @Autowired private CreateEventFactory createEventFactory; @@ -29,6 +31,7 @@ public class CreateEventService { * @return CreateEventFormatterDto */ public CreateEventFormatterDto createEvent(HttpServletRequest request, String accountId, CreateEventDto createEventDto) { + logger.info("Create Event Service started"); SalesforceUser currentUser = (SalesforceUser) request.getAttribute("current_user"); From 0b554d713903e7dabe769c443427b6f42849986a Mon Sep 17 00:00:00 2001 From: Raj Shah Date: Thu, 14 Sep 2023 14:14:52 +0530 Subject: [PATCH 03/36] Added create account event api changes --- .../controllers/AccountEventController.java | 29 ++-- .../formatter/CreateEventFormatterDto.java | 4 +- .../requestMapper/CreateAccountEventDto.java | 28 ++++ .../api/dto/requestMapper/CreateEventDto.java | 31 ---- .../CreateAccountEventFactory.java} | 31 ++-- .../CreateAccountEventInterface.java | 18 +++ .../CreateSalesforceAccountEvent.java | 123 ++++++++++++++++ .../createEvent/CreateEventInterface.java | 15 -- .../createEvent/CreateSalesforceEvent.java | 136 ------------------ .../ValidDatetimeFormat.java | 20 +++ .../globalConstants/SalesforceConstants.java | 6 +- .../dto/SalesforceCreateEventDto.java | 10 +- .../validators/DatetimeFormatValidator.java | 43 ++++++ .../CreateAccountEventService.java | 42 ++++++ .../services/events/CreateEventService.java | 40 ------ .../resources/config/ParamErrorConfig.json | 10 ++ 16 files changed, 325 insertions(+), 261 deletions(-) create mode 100644 src/main/java/com/salessparrow/api/dto/requestMapper/CreateAccountEventDto.java delete mode 100644 src/main/java/com/salessparrow/api/dto/requestMapper/CreateEventDto.java rename src/main/java/com/salessparrow/api/lib/crmActions/{createEvent/CreateEventFactory.java => createAccountEvent/CreateAccountEventFactory.java} (54%) create mode 100644 src/main/java/com/salessparrow/api/lib/crmActions/createAccountEvent/CreateAccountEventInterface.java create mode 100644 src/main/java/com/salessparrow/api/lib/crmActions/createAccountEvent/CreateSalesforceAccountEvent.java delete mode 100644 src/main/java/com/salessparrow/api/lib/crmActions/createEvent/CreateEventInterface.java delete mode 100644 src/main/java/com/salessparrow/api/lib/crmActions/createEvent/CreateSalesforceEvent.java create mode 100644 src/main/java/com/salessparrow/api/lib/customAnnotations/ValidDatetimeFormat.java create mode 100644 src/main/java/com/salessparrow/api/lib/validators/DatetimeFormatValidator.java create mode 100644 src/main/java/com/salessparrow/api/services/accountEvents/CreateAccountEventService.java delete mode 100644 src/main/java/com/salessparrow/api/services/events/CreateEventService.java diff --git a/src/main/java/com/salessparrow/api/controllers/AccountEventController.java b/src/main/java/com/salessparrow/api/controllers/AccountEventController.java index 8ed0d4a1..8bedef05 100644 --- a/src/main/java/com/salessparrow/api/controllers/AccountEventController.java +++ b/src/main/java/com/salessparrow/api/controllers/AccountEventController.java @@ -11,8 +11,8 @@ import org.springframework.web.bind.annotation.RestController; import com.salessparrow.api.dto.formatter.CreateEventFormatterDto; -import com.salessparrow.api.dto.requestMapper.CreateEventDto; -import com.salessparrow.api.services.events.CreateEventService; +import com.salessparrow.api.dto.requestMapper.CreateAccountEventDto; +import com.salessparrow.api.services.accountEvents.CreateAccountEventService; import jakarta.servlet.http.HttpServletRequest; import jakarta.validation.Valid; @@ -21,22 +21,21 @@ @RequestMapping("/api/v1/accounts/{account_id}/events") @Validated public class AccountEventController { - private Logger logger = org.slf4j.LoggerFactory.getLogger(AccountEventController.class); - @Autowired - private CreateEventService createEventService; + private Logger logger = org.slf4j.LoggerFactory.getLogger(AccountEventController.class); - @PostMapping("") - public ResponseEntity createEvent( - HttpServletRequest request, - @PathVariable("account_id") String accountId, - @Valid @RequestBody CreateEventDto createEventDto - ) { - logger.info("Create Event Request received"); + @Autowired + private CreateAccountEventService createEventService; - CreateEventFormatterDto createEventFormatterDto = createEventService.createEvent(request, accountId, createEventDto); + @PostMapping("") + public ResponseEntity createEvent(HttpServletRequest request, + @PathVariable("account_id") String accountId, @Valid @RequestBody CreateAccountEventDto createEventDto) { + logger.info("Create Event Request received"); - return ResponseEntity.ok().body(createEventFormatterDto); - } + CreateEventFormatterDto createEventFormatterDto = createEventService.createEvent(request, accountId, + createEventDto); + + return ResponseEntity.ok().body(createEventFormatterDto); + } } diff --git a/src/main/java/com/salessparrow/api/dto/formatter/CreateEventFormatterDto.java b/src/main/java/com/salessparrow/api/dto/formatter/CreateEventFormatterDto.java index b827a115..06d7f156 100644 --- a/src/main/java/com/salessparrow/api/dto/formatter/CreateEventFormatterDto.java +++ b/src/main/java/com/salessparrow/api/dto/formatter/CreateEventFormatterDto.java @@ -11,5 +11,7 @@ @Data @JsonNaming(PropertyNamingStrategies.SnakeCaseStrategy.class) public class CreateEventFormatterDto { - private String eventId; + + private String eventId; + } \ No newline at end of file diff --git a/src/main/java/com/salessparrow/api/dto/requestMapper/CreateAccountEventDto.java b/src/main/java/com/salessparrow/api/dto/requestMapper/CreateAccountEventDto.java new file mode 100644 index 00000000..7231c427 --- /dev/null +++ b/src/main/java/com/salessparrow/api/dto/requestMapper/CreateAccountEventDto.java @@ -0,0 +1,28 @@ +package com.salessparrow.api.dto.requestMapper; + +import com.fasterxml.jackson.databind.PropertyNamingStrategies; +import com.fasterxml.jackson.databind.annotation.JsonNaming; +import com.salessparrow.api.lib.customAnnotations.ValidDatetimeFormat; + +import jakarta.validation.constraints.NotBlank; +import jakarta.validation.constraints.NotNull; +import jakarta.validation.constraints.Size; +import lombok.Data; + +@Data +@JsonNaming(PropertyNamingStrategies.SnakeCaseStrategy.class) +public class CreateAccountEventDto { + + @NotBlank(message = "missing_description") + @Size(max = 32000, message = "description_too_long") + private String description; + + @NotNull(message = "missing_start_datetime") + @ValidDatetimeFormat(message = "invalid_start_datetime") + private String startDatetime; + + @NotNull(message = "missing_end_datetime") + @ValidDatetimeFormat(message = "invalid_end_datetime") + private String endDatetime; + +} diff --git a/src/main/java/com/salessparrow/api/dto/requestMapper/CreateEventDto.java b/src/main/java/com/salessparrow/api/dto/requestMapper/CreateEventDto.java deleted file mode 100644 index 791669d4..00000000 --- a/src/main/java/com/salessparrow/api/dto/requestMapper/CreateEventDto.java +++ /dev/null @@ -1,31 +0,0 @@ -package com.salessparrow.api.dto.requestMapper; - -import com.fasterxml.jackson.databind.PropertyNamingStrategies; -import com.fasterxml.jackson.databind.annotation.JsonDeserialize; -import com.fasterxml.jackson.databind.annotation.JsonNaming; -import com.fasterxml.jackson.databind.annotation.JsonSerialize; -import org.joda.time.DateTime; - -import com.fasterxml.jackson.datatype.joda.deser.DateTimeDeserializer; -import com.fasterxml.jackson.datatype.joda.ser.DateTimeSerializer; - -import jakarta.validation.constraints.NotBlank; -import jakarta.validation.constraints.NotNull; -import lombok.Data; - -@JsonNaming(PropertyNamingStrategies.SnakeCaseStrategy.class) -@Data -public class CreateEventDto { - @NotBlank(message = "missing_description") - private String description; - - @JsonSerialize(using = DateTimeSerializer.class) - @JsonDeserialize(using = DateTimeDeserializer.class) - @NotNull(message = "missing_start_datetime") - private DateTime startDatetime; - - @JsonSerialize(using = DateTimeSerializer.class) - @JsonDeserialize(using = DateTimeDeserializer.class) - @NotNull(message = "missing_end_datetime") - private DateTime endDatetime; -} diff --git a/src/main/java/com/salessparrow/api/lib/crmActions/createEvent/CreateEventFactory.java b/src/main/java/com/salessparrow/api/lib/crmActions/createAccountEvent/CreateAccountEventFactory.java similarity index 54% rename from src/main/java/com/salessparrow/api/lib/crmActions/createEvent/CreateEventFactory.java rename to src/main/java/com/salessparrow/api/lib/crmActions/createAccountEvent/CreateAccountEventFactory.java index c1c77a32..a578e100 100644 --- a/src/main/java/com/salessparrow/api/lib/crmActions/createEvent/CreateEventFactory.java +++ b/src/main/java/com/salessparrow/api/lib/crmActions/createAccountEvent/CreateAccountEventFactory.java @@ -1,4 +1,4 @@ -package com.salessparrow.api.lib.crmActions.createEvent; +package com.salessparrow.api.lib.crmActions.createAccountEvent; import org.slf4j.Logger; import org.springframework.beans.factory.annotation.Autowired; @@ -6,40 +6,39 @@ import com.salessparrow.api.domain.SalesforceUser; import com.salessparrow.api.dto.formatter.CreateEventFormatterDto; -import com.salessparrow.api.dto.requestMapper.CreateEventDto; +import com.salessparrow.api.dto.requestMapper.CreateAccountEventDto; import com.salessparrow.api.exception.CustomException; import com.salessparrow.api.lib.errorLib.ErrorObject; import com.salessparrow.api.lib.globalConstants.UserConstants; /** - * CreateEventFactory is a factory class for the create event action for the CRM. + * CreateAccountEventFactory is a factory class for the create event action for the CRM. */ @Component -public class CreateEventFactory { - private Logger logger = org.slf4j.LoggerFactory.getLogger(CreateEventFactory.class); +public class CreateAccountEventFactory { - @Autowired - private CreateSalesforceEvent createSalesforceEvent; + private Logger logger = org.slf4j.LoggerFactory.getLogger(CreateAccountEventFactory.class); - /** + @Autowired + private CreateSalesforceAccountEvent createSalesforceEvent; + + /** * Create an event for a given account * @param user * @param accountId - * * @return CreateEventFormatterDto **/ - public CreateEventFormatterDto createEvent(SalesforceUser user, String accountId, CreateEventDto createEventDto) { - logger.info("Create Event Factory started"); + public CreateEventFormatterDto createEvent(SalesforceUser user, String accountId, + CreateAccountEventDto createEventDto) { + logger.info("Create Event Factory started"); - switch(user.getUserKind()) { + switch (user.getUserKind()) { case UserConstants.SALESFORCE_USER_KIND: return createSalesforceEvent.createEvent(user, accountId, createEventDto); default: throw new CustomException( - new ErrorObject( - "l_ca_ce_cef_ce_1", - "something_went_wrong", - "Invalid user kind.")); + new ErrorObject("l_ca_cae_caef_cae_1", "something_went_wrong", "Invalid user kind.")); } } + } diff --git a/src/main/java/com/salessparrow/api/lib/crmActions/createAccountEvent/CreateAccountEventInterface.java b/src/main/java/com/salessparrow/api/lib/crmActions/createAccountEvent/CreateAccountEventInterface.java new file mode 100644 index 00000000..3d67ea1e --- /dev/null +++ b/src/main/java/com/salessparrow/api/lib/crmActions/createAccountEvent/CreateAccountEventInterface.java @@ -0,0 +1,18 @@ +package com.salessparrow.api.lib.crmActions.createAccountEvent; + +import org.springframework.stereotype.Component; + +import com.salessparrow.api.domain.SalesforceUser; +import com.salessparrow.api.dto.formatter.CreateEventFormatterDto; +import com.salessparrow.api.dto.requestMapper.CreateAccountEventDto; + +/** + * CreateAccountEventInterface is an interface for the create event action for the CRM. + */ +@Component +public interface CreateAccountEventInterface { + + public CreateEventFormatterDto createEvent(SalesforceUser user, String accountId, + CreateAccountEventDto createEventDto); + +} diff --git a/src/main/java/com/salessparrow/api/lib/crmActions/createAccountEvent/CreateSalesforceAccountEvent.java b/src/main/java/com/salessparrow/api/lib/crmActions/createAccountEvent/CreateSalesforceAccountEvent.java new file mode 100644 index 00000000..55b8230e --- /dev/null +++ b/src/main/java/com/salessparrow/api/lib/crmActions/createAccountEvent/CreateSalesforceAccountEvent.java @@ -0,0 +1,123 @@ +package com.salessparrow.api.lib.crmActions.createAccountEvent; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.slf4j.Logger; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +import com.fasterxml.jackson.databind.DeserializationFeature; +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.salessparrow.api.domain.SalesforceUser; +import com.salessparrow.api.dto.formatter.CreateEventFormatterDto; +import com.salessparrow.api.dto.requestMapper.CreateAccountEventDto; +import com.salessparrow.api.exception.CustomException; +import com.salessparrow.api.lib.Util; +import com.salessparrow.api.lib.errorLib.ErrorObject; +import com.salessparrow.api.lib.globalConstants.SalesforceConstants; +import com.salessparrow.api.lib.httpLib.HttpClient; +import com.salessparrow.api.lib.salesforce.dto.CompositeRequestDto; +import com.salessparrow.api.lib.salesforce.dto.SalesforceCreateEventDto; +import com.salessparrow.api.lib.salesforce.helper.MakeCompositeRequest; + +/** + * CreateSalesforceAccountEvent is a class that creates an event for an account in + * Salesforce. + */ +@Component +public class CreateSalesforceAccountEvent implements CreateAccountEventInterface { + + private Logger logger = org.slf4j.LoggerFactory.getLogger(CreateSalesforceAccountEvent.class); + + @Autowired + private SalesforceConstants salesforceConstants; + + @Autowired + private MakeCompositeRequest makeCompositeRequest; + + /** + * Create an event for a given account. + * @param user + * @param accountId + * @param createEventDto + * @return CreateEventFormatterDto + */ + public CreateEventFormatterDto createEvent(SalesforceUser user, String accountId, + CreateAccountEventDto createEventDto) { + logger.info("Create Salesforce Event started"); + + String salesforceUserId = user.getExternalUserId(); + + Util util = new Util(); + String eventDescription = util.unEscapeSpecialCharactersForPlainText(createEventDto.getDescription()); + String eventSubject = getEventSubjectFromDescription(eventDescription); + + Map createEventBody = new HashMap(); + createEventBody.put("Subject", eventSubject); + createEventBody.put("Description", eventDescription); + createEventBody.put("WhatId", accountId); + createEventBody.put("StartDateTime", createEventDto.getStartDatetime().toString()); + createEventBody.put("EndDateTime", createEventDto.getEndDatetime().toString()); + + CompositeRequestDto createEventCompositeRequestDto = new CompositeRequestDto("POST", + salesforceConstants.salesforceCreateEventUrl(), "CreateEvent", createEventBody); + + List compositeRequests = new ArrayList(); + compositeRequests.add(createEventCompositeRequestDto); + + HttpClient.HttpResponse response = makeCompositeRequest.makePostRequest(compositeRequests, salesforceUserId); + + return parseResponse(response.getResponseBody()); + } + + /** + * Parse the response from Salesforce. + * @param createEventResponse + * @return CreateEventFormatterDto - formatted response + */ + private CreateEventFormatterDto parseResponse(String createEventResponse) { + logger.info("Parsing the response from Salesforce"); + + Util util = new Util(); + JsonNode rootNode = util.getJsonNode(createEventResponse); + + JsonNode createEventCompositeResponse = rootNode.get("compositeResponse").get(0); + Integer createEventStatusCode = createEventCompositeResponse.get("httpStatusCode").asInt(); + + if (createEventStatusCode != 200 && createEventStatusCode != 201) { + String errorBody = createEventCompositeResponse.get("body").asText(); + + throw new CustomException(new ErrorObject("l_ca_ce_cse_pr_1", "internal_server_error", errorBody)); + } + + JsonNode createEventNodeResponseBody = rootNode.get("compositeResponse").get(0).get("body"); + + ObjectMapper mapper = new ObjectMapper(); + mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES); + SalesforceCreateEventDto salesforceCreateEventDto = mapper.convertValue(createEventNodeResponseBody, + SalesforceCreateEventDto.class); + + CreateEventFormatterDto createEventFormatterDto = new CreateEventFormatterDto(); + createEventFormatterDto.setEventId(salesforceCreateEventDto.getId()); + + return createEventFormatterDto; + } + + /** + * Get the first 60 characters of the event description. + * @param createEventDto + * @return String + */ + private String getEventSubjectFromDescription(String eventDescription) { + if (eventDescription.length() < 60) { + return eventDescription; + } + + return eventDescription.substring(0, 60); + } + +} diff --git a/src/main/java/com/salessparrow/api/lib/crmActions/createEvent/CreateEventInterface.java b/src/main/java/com/salessparrow/api/lib/crmActions/createEvent/CreateEventInterface.java deleted file mode 100644 index 0cd6389a..00000000 --- a/src/main/java/com/salessparrow/api/lib/crmActions/createEvent/CreateEventInterface.java +++ /dev/null @@ -1,15 +0,0 @@ -package com.salessparrow.api.lib.crmActions.createEvent; - -import org.springframework.stereotype.Component; - -import com.salessparrow.api.domain.SalesforceUser; -import com.salessparrow.api.dto.formatter.CreateEventFormatterDto; -import com.salessparrow.api.dto.requestMapper.CreateEventDto; - -/** - * CreateEventInterface is an interface for the create event action for the CRM. - */ -@Component -public interface CreateEventInterface { - public CreateEventFormatterDto createEvent(SalesforceUser user, String accountId, CreateEventDto createEventDto); -} diff --git a/src/main/java/com/salessparrow/api/lib/crmActions/createEvent/CreateSalesforceEvent.java b/src/main/java/com/salessparrow/api/lib/crmActions/createEvent/CreateSalesforceEvent.java deleted file mode 100644 index 563aa6c4..00000000 --- a/src/main/java/com/salessparrow/api/lib/crmActions/createEvent/CreateSalesforceEvent.java +++ /dev/null @@ -1,136 +0,0 @@ -package com.salessparrow.api.lib.crmActions.createEvent; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import org.slf4j.Logger; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Component; - -import com.fasterxml.jackson.databind.DeserializationFeature; -import com.fasterxml.jackson.databind.JsonNode; -import com.fasterxml.jackson.databind.ObjectMapper; -import com.salessparrow.api.domain.SalesforceUser; -import com.salessparrow.api.dto.formatter.CreateEventFormatterDto; -import com.salessparrow.api.dto.requestMapper.CreateEventDto; -import com.salessparrow.api.exception.CustomException; -import com.salessparrow.api.lib.Base64Helper; -import com.salessparrow.api.lib.Util; -import com.salessparrow.api.lib.errorLib.ErrorObject; -import com.salessparrow.api.lib.globalConstants.SalesforceConstants; -import com.salessparrow.api.lib.httpLib.HttpClient; -import com.salessparrow.api.lib.salesforce.dto.CompositeRequestDto; -import com.salessparrow.api.lib.salesforce.dto.SalesforceCreateEventDto; -import com.salessparrow.api.lib.salesforce.helper.MakeCompositeRequest; - -/** - * CreateSalesforceEvent is a class that creates an event for an account in Salesforce. - */ -@Component -public class CreateSalesforceEvent implements CreateEventInterface { - - private Logger logger = org.slf4j.LoggerFactory.getLogger(CreateSalesforceEvent.class); - - @Autowired - private SalesforceConstants salesforceConstants; - - @Autowired - private MakeCompositeRequest makeCompositeRequest; - - @Autowired - private Base64Helper base64Helper; - - /** - * Create an event for a given account. - * - * @param user - * @param accountId - * @param createEventDto - * - * @return CreateEventFormatterDto - */ - public CreateEventFormatterDto createEvent(SalesforceUser user, String accountId, CreateEventDto createEventDto) { - logger.info("Create Salesforce Event started"); - - String salesforceUserId = user.getExternalUserId(); - - String eventSubject = getEventSubjectFromDescription(createEventDto); - // String eventDescription = base64Helper.base64Encode(createEventDto.getDescription()); - - Map createEventBody = new HashMap(); - createEventBody.put("Subject", eventSubject); - createEventBody.put("Description", createEventDto.getDescription()); - createEventBody.put("WhatId", accountId); - createEventBody.put("StartDateTime", createEventDto.getStartDatetime().toString()); - createEventBody.put("EndDateTime", createEventDto.getEndDatetime().toString()); - - CompositeRequestDto createEventCompositeRequestDto = new CompositeRequestDto( - "POST", - salesforceConstants.salesforceCreateEventUrl(), - "CreateEvent", - createEventBody - ); - - List compositeRequests = new ArrayList(); - compositeRequests.add(createEventCompositeRequestDto); - - HttpClient.HttpResponse response = makeCompositeRequest.makePostRequest(compositeRequests, salesforceUserId); - - return parseResponse(response.getResponseBody()); - } - - /** - * Parse the response from Salesforce. - * - * @param createEventResponse - * - * @return CreateEventFormatterDto - formatted response - */ - private CreateEventFormatterDto parseResponse(String createEventResponse) { - logger.info("Parsing the response from Salesforce"); - - Util util = new Util(); - JsonNode rootNode = util.getJsonNode(createEventResponse); - - JsonNode createEventCompositeResponse = rootNode.get("compositeResponse").get(0); - Integer createEventStatusCode = createEventCompositeResponse.get("httpStatusCode").asInt(); - - if (createEventStatusCode != 200 && createEventStatusCode != 201) { - String errorBody = createEventCompositeResponse.get("body").asText(); - - throw new CustomException( - new ErrorObject( - "l_ca_ce_cse_pr_1", - "internal_server_error", - errorBody)); - } - - JsonNode createEventNodeResponseBody = rootNode.get("compositeResponse").get(0).get("body"); - - ObjectMapper mapper = new ObjectMapper(); - mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES); - SalesforceCreateEventDto salesforceCreateEventDto = mapper.convertValue(createEventNodeResponseBody, SalesforceCreateEventDto.class); - - CreateEventFormatterDto createEventFormatterDto = new CreateEventFormatterDto(); - createEventFormatterDto.setEventId(salesforceCreateEventDto.getId()); - - return createEventFormatterDto; - } - - /** - * Get the first 60 characters of the event description. - * - * @param createEventDto - * - * @return String - */ - private String getEventSubjectFromDescription(CreateEventDto createEventDto) { - if (createEventDto.getDescription().length() < 60) { - return createEventDto.getDescription(); - } - - return createEventDto.getDescription().substring(0, 60); - } -} diff --git a/src/main/java/com/salessparrow/api/lib/customAnnotations/ValidDatetimeFormat.java b/src/main/java/com/salessparrow/api/lib/customAnnotations/ValidDatetimeFormat.java new file mode 100644 index 00000000..788832e5 --- /dev/null +++ b/src/main/java/com/salessparrow/api/lib/customAnnotations/ValidDatetimeFormat.java @@ -0,0 +1,20 @@ +package com.salessparrow.api.lib.customAnnotations; + +import jakarta.validation.Constraint; +import jakarta.validation.Payload; +import java.lang.annotation.*; + +import com.salessparrow.api.lib.validators.DatetimeFormatValidator; + +@Target({ ElementType.FIELD }) +@Retention(RetentionPolicy.RUNTIME) +@Constraint(validatedBy = DatetimeFormatValidator.class) +public @interface ValidDatetimeFormat { + + String message() default "Invalid Datetime Format"; + + Class[] groups() default {}; + + Class[] payload() default {}; + +} \ No newline at end of file diff --git a/src/main/java/com/salessparrow/api/lib/globalConstants/SalesforceConstants.java b/src/main/java/com/salessparrow/api/lib/globalConstants/SalesforceConstants.java index 161dc6c9..f0a8086b 100644 --- a/src/main/java/com/salessparrow/api/lib/globalConstants/SalesforceConstants.java +++ b/src/main/java/com/salessparrow/api/lib/globalConstants/SalesforceConstants.java @@ -38,9 +38,9 @@ public String salesforceCreateNoteUrl() { return sObjectsPath() + "/ContentNote"; } - public String salesforceCreateEventUrl() { - return sObjectsPath() + "/Event"; - } + public String salesforceCreateEventUrl() { + return sObjectsPath() + "/Event"; + } public String salesforceDeleteNoteUrl(String noteId) { return sObjectsPath() + "/ContentNote/" + noteId; diff --git a/src/main/java/com/salessparrow/api/lib/salesforce/dto/SalesforceCreateEventDto.java b/src/main/java/com/salessparrow/api/lib/salesforce/dto/SalesforceCreateEventDto.java index 187d7555..e521ba1a 100644 --- a/src/main/java/com/salessparrow/api/lib/salesforce/dto/SalesforceCreateEventDto.java +++ b/src/main/java/com/salessparrow/api/lib/salesforce/dto/SalesforceCreateEventDto.java @@ -7,9 +7,11 @@ */ @Data public class SalesforceCreateEventDto { - String id; - String success; - - String[] errors; + String id; + + String success; + + String[] errors; + } diff --git a/src/main/java/com/salessparrow/api/lib/validators/DatetimeFormatValidator.java b/src/main/java/com/salessparrow/api/lib/validators/DatetimeFormatValidator.java new file mode 100644 index 00000000..ab51b193 --- /dev/null +++ b/src/main/java/com/salessparrow/api/lib/validators/DatetimeFormatValidator.java @@ -0,0 +1,43 @@ +package com.salessparrow.api.lib.validators; + +import java.text.SimpleDateFormat; +import java.util.Date; + +import com.salessparrow.api.lib.customAnnotations.ValidDatetimeFormat; + +import jakarta.validation.ConstraintValidator; +import jakarta.validation.ConstraintValidatorContext; + +/** + * Validate datetime format with regular expression + * + */ +public class DatetimeFormatValidator implements ConstraintValidator { + + private static final String DATETIME_FORMAT = "yyyy-MM-dd'T'HH:mm:ss.SSSZ"; + + /** + * Validate datetime format with regular expression + * @param value datetime address for validation + * @return true valid date format, false invalid date format + */ + @Override + public boolean isValid(String value, ConstraintValidatorContext context) { + if (value == null) { + return false; + } + + SimpleDateFormat sdf = new SimpleDateFormat(DATETIME_FORMAT); + sdf.setLenient(false); + + try { + Date parsedDate = sdf.parse(value); + String dateString = sdf.format(parsedDate); + return dateString.equals(value.toString()); + } + catch (Exception ex) { + return false; + } + } + +} \ No newline at end of file diff --git a/src/main/java/com/salessparrow/api/services/accountEvents/CreateAccountEventService.java b/src/main/java/com/salessparrow/api/services/accountEvents/CreateAccountEventService.java new file mode 100644 index 00000000..09f6d23c --- /dev/null +++ b/src/main/java/com/salessparrow/api/services/accountEvents/CreateAccountEventService.java @@ -0,0 +1,42 @@ +package com.salessparrow.api.services.accountEvents; + +import org.slf4j.Logger; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import com.salessparrow.api.domain.SalesforceUser; +import com.salessparrow.api.dto.formatter.CreateEventFormatterDto; +import com.salessparrow.api.dto.requestMapper.CreateAccountEventDto; +import com.salessparrow.api.lib.crmActions.createAccountEvent.CreateAccountEventFactory; + +import jakarta.servlet.http.HttpServletRequest; + +/** + * CreateAccountEventService is a service class for the create account event action for + * the CRM. + */ +@Service +public class CreateAccountEventService { + + private Logger logger = org.slf4j.LoggerFactory.getLogger(CreateAccountEventService.class); + + @Autowired + private CreateAccountEventFactory createAccountEventFactory; + + /** + * Create an event for a specific account. + * @param request + * @param accountId + * @param createEventDto + * @return CreateEventFormatterDto + */ + public CreateEventFormatterDto createEvent(HttpServletRequest request, String accountId, + CreateAccountEventDto createEventDto) { + logger.info("Create Account Event Service started"); + + SalesforceUser currentUser = (SalesforceUser) request.getAttribute("current_user"); + + return createAccountEventFactory.createEvent(currentUser, accountId, createEventDto); + } + +} \ No newline at end of file diff --git a/src/main/java/com/salessparrow/api/services/events/CreateEventService.java b/src/main/java/com/salessparrow/api/services/events/CreateEventService.java deleted file mode 100644 index 1d5a9d20..00000000 --- a/src/main/java/com/salessparrow/api/services/events/CreateEventService.java +++ /dev/null @@ -1,40 +0,0 @@ -package com.salessparrow.api.services.events; - -import org.slf4j.Logger; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Service; - -import com.salessparrow.api.domain.SalesforceUser; -import com.salessparrow.api.dto.formatter.CreateEventFormatterDto; -import com.salessparrow.api.dto.requestMapper.CreateEventDto; -import com.salessparrow.api.lib.crmActions.createEvent.CreateEventFactory; - -import jakarta.servlet.http.HttpServletRequest; - -/** - * CreateEventService is a service class for the create event action for the CRM. - */ -@Service -public class CreateEventService { - private Logger logger = org.slf4j.LoggerFactory.getLogger(CreateEventService.class); - - @Autowired - private CreateEventFactory createEventFactory; - - /** - * Create an event for a specific account. - * - * @param request - * @param accountId - * @param createEventDto - * - * @return CreateEventFormatterDto - */ - public CreateEventFormatterDto createEvent(HttpServletRequest request, String accountId, CreateEventDto createEventDto) { - logger.info("Create Event Service started"); - - SalesforceUser currentUser = (SalesforceUser) request.getAttribute("current_user"); - - return createEventFactory.createEvent(currentUser, accountId, createEventDto); - } -} diff --git a/src/main/resources/config/ParamErrorConfig.json b/src/main/resources/config/ParamErrorConfig.json index eb3fb4a1..69e181db 100644 --- a/src/main/resources/config/ParamErrorConfig.json +++ b/src/main/resources/config/ParamErrorConfig.json @@ -58,5 +58,15 @@ "parameter": "account_id", "param_error_identifier": "invalid_account_id", "message": "The account id you sent is incorrect. Please double check and try again." + }, + "invalid_start_datetime": { + "parameter": "start_datetime", + "param_error_identifier": "invalid_start_datetime", + "message": "Invalid start datetime. Please double check and try again." + }, + "invalid_end_datetime": { + "parameter": "end_datetime", + "param_error_identifier": "invalid_end_datetime", + "message": "Invalid end datetime. Please double check and try again." } } \ No newline at end of file From 247fc4e9cf6f1758a9ed3e309261578ae266e8b1 Mon Sep 17 00:00:00 2001 From: Raj Shah Date: Thu, 14 Sep 2023 15:31:58 +0530 Subject: [PATCH 04/36] Added create account event test case --- .../controllers/AccountEventController.java | 3 +- .../requestMapper/CreateAccountEventDto.java | 2 +- .../CreateSalesforceAccountEvent.java | 2 +- .../CreateAccountEventTest.java | 137 ++++++++++++++ .../createAccountEvent.scenarios.json | 176 ++++++++++++++++++ .../createAccountEvent.fixtures.json | 14 ++ 6 files changed, 331 insertions(+), 3 deletions(-) create mode 100644 src/test/java/com/salessparrow/api/functional/controllers/accountEventController/CreateAccountEventTest.java create mode 100644 src/test/resources/data/functional/controllers/accountEventController/createAccountEvent.scenarios.json create mode 100644 src/test/resources/fixtures/functional/controllers/accountEventController/createAccountEvent.fixtures.json diff --git a/src/main/java/com/salessparrow/api/controllers/AccountEventController.java b/src/main/java/com/salessparrow/api/controllers/AccountEventController.java index 8bedef05..b312c96b 100644 --- a/src/main/java/com/salessparrow/api/controllers/AccountEventController.java +++ b/src/main/java/com/salessparrow/api/controllers/AccountEventController.java @@ -2,6 +2,7 @@ import org.slf4j.Logger; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.PathVariable; @@ -35,7 +36,7 @@ public ResponseEntity createEvent(HttpServletRequest re CreateEventFormatterDto createEventFormatterDto = createEventService.createEvent(request, accountId, createEventDto); - return ResponseEntity.ok().body(createEventFormatterDto); + return ResponseEntity.status(HttpStatus.CREATED).body(createEventFormatterDto); } } diff --git a/src/main/java/com/salessparrow/api/dto/requestMapper/CreateAccountEventDto.java b/src/main/java/com/salessparrow/api/dto/requestMapper/CreateAccountEventDto.java index 7231c427..e2315545 100644 --- a/src/main/java/com/salessparrow/api/dto/requestMapper/CreateAccountEventDto.java +++ b/src/main/java/com/salessparrow/api/dto/requestMapper/CreateAccountEventDto.java @@ -14,7 +14,7 @@ public class CreateAccountEventDto { @NotBlank(message = "missing_description") - @Size(max = 32000, message = "description_too_long") + @Size(max = 32000, message = "description_too_long") private String description; @NotNull(message = "missing_start_datetime") diff --git a/src/main/java/com/salessparrow/api/lib/crmActions/createAccountEvent/CreateSalesforceAccountEvent.java b/src/main/java/com/salessparrow/api/lib/crmActions/createAccountEvent/CreateSalesforceAccountEvent.java index 55b8230e..4c2af835 100644 --- a/src/main/java/com/salessparrow/api/lib/crmActions/createAccountEvent/CreateSalesforceAccountEvent.java +++ b/src/main/java/com/salessparrow/api/lib/crmActions/createAccountEvent/CreateSalesforceAccountEvent.java @@ -91,7 +91,7 @@ private CreateEventFormatterDto parseResponse(String createEventResponse) { if (createEventStatusCode != 200 && createEventStatusCode != 201) { String errorBody = createEventCompositeResponse.get("body").asText(); - throw new CustomException(new ErrorObject("l_ca_ce_cse_pr_1", "internal_server_error", errorBody)); + throw new CustomException(new ErrorObject("l_ca_cae_csae_pr_1", "internal_server_error", errorBody)); } JsonNode createEventNodeResponseBody = rootNode.get("compositeResponse").get(0).get("body"); diff --git a/src/test/java/com/salessparrow/api/functional/controllers/accountEventController/CreateAccountEventTest.java b/src/test/java/com/salessparrow/api/functional/controllers/accountEventController/CreateAccountEventTest.java new file mode 100644 index 00000000..2dce8e1e --- /dev/null +++ b/src/test/java/com/salessparrow/api/functional/controllers/accountEventController/CreateAccountEventTest.java @@ -0,0 +1,137 @@ +package com.salessparrow.api.functional.controllers.accountEventController; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.when; + +import java.io.IOException; +import java.util.List; +import java.util.stream.Stream; + +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.mock.mockito.MockBean; +import org.springframework.context.annotation.Import; +import org.springframework.core.io.DefaultResourceLoader; +import org.springframework.core.io.Resource; +import org.springframework.http.MediaType; +import org.springframework.test.context.web.WebAppConfiguration; +import org.springframework.test.web.servlet.MockMvc; +import org.springframework.test.web.servlet.ResultActions; +import org.springframework.test.web.servlet.request.MockMvcRequestBuilders; + +import com.fasterxml.jackson.core.type.TypeReference; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.github.dynamobee.exception.DynamobeeException; +import com.salessparrow.api.helper.Cleanup; +import com.salessparrow.api.helper.Common; +import com.salessparrow.api.helper.Constants; +import com.salessparrow.api.helper.FixtureData; +import com.salessparrow.api.helper.LoadFixture; +import com.salessparrow.api.helper.Scenario; +import com.salessparrow.api.helper.Setup; +import com.salessparrow.api.lib.globalConstants.CookieConstants; +import com.salessparrow.api.lib.httpLib.HttpClient.HttpResponse; +import com.salessparrow.api.lib.salesforce.helper.MakeCompositeRequest; + +import jakarta.servlet.http.Cookie; + +@SpringBootTest +@AutoConfigureMockMvc +@WebAppConfiguration +@Import({ Setup.class, Cleanup.class, Common.class, LoadFixture.class }) +public class CreateAccountEventTest { + + @Autowired + private MockMvc mockMvc; + + @Autowired + private Common common; + + @Autowired + private LoadFixture loadFixture; + + @Autowired + private Setup setup; + + @Autowired + private Cleanup cleanup; + + @MockBean + private MakeCompositeRequest makeCompositeRequestMock; + + @BeforeEach + public void setUp() throws DynamobeeException { + setup.perform(); + } + + @AfterEach + public void tearDown() { + cleanup.perform(); + } + + @ParameterizedTest + @MethodSource("testScenariosProvider") + public void createAccountEvent(Scenario testScenario) throws Exception { + + // Load fixture data + String currentFunctionName = new Object() { + }.getClass().getEnclosingMethod().getName(); + FixtureData fixtureData = common.loadFixture( + "classpath:fixtures/functional/controllers/accountEventController/createAccountEvent.fixtures.json", + currentFunctionName); + loadFixture.perform(fixtureData); + + // Read data from the scenario + ObjectMapper objectMapper = new ObjectMapper(); + String cookieValue = Constants.SALESFORCE_ACTIVE_USER_COOKIE_VALUE; + String accountId = (String) testScenario.getInput().get("accountId"); + + // Prepare mock responses + HttpResponse createNoteMockResponse = new HttpResponse(); + createNoteMockResponse + .setResponseBody(objectMapper.writeValueAsString(testScenario.getMocks().get("makeCompositeRequest"))); + when(makeCompositeRequestMock.makePostRequest(any(), any())).thenReturn(createNoteMockResponse); + + // Perform the request + String requestBody = objectMapper.writeValueAsString(testScenario.getInput().get("body")); + String url = "/api/v1/accounts/" + accountId + "/events"; + + ResultActions resultActions = mockMvc.perform(MockMvcRequestBuilders.post(url) + .cookie(new Cookie(CookieConstants.USER_LOGIN_COOKIE_NAME, cookieValue)) + .content(requestBody) + .contentType(MediaType.APPLICATION_JSON)); + + // Check the response + String expectedOutput = objectMapper.writeValueAsString(testScenario.getOutput()); + String actualOutput = resultActions.andReturn().getResponse().getContentAsString(); + System.out.println("actualOutput ++++++++++ " + actualOutput); + System.out.println("expectedOutput ++++++++++ " + expectedOutput); + + if (resultActions.andReturn().getResponse().getStatus() == 201) { + assertEquals(expectedOutput, actualOutput); + } + else { + common.compareErrors(testScenario, actualOutput); + } + } + + static Stream testScenariosProvider() throws IOException { + List testScenarios = loadScenarios(); + return testScenarios.stream(); + } + + private static List loadScenarios() throws IOException { + String scenariosPath = "classpath:data/functional/controllers/accountEventController/createAccountEvent.scenarios.json"; + Resource resource = new DefaultResourceLoader().getResource(scenariosPath); + ObjectMapper objectMapper = new ObjectMapper(); + return objectMapper.readValue(resource.getInputStream(), new TypeReference>() { + }); + } + +} diff --git a/src/test/resources/data/functional/controllers/accountEventController/createAccountEvent.scenarios.json b/src/test/resources/data/functional/controllers/accountEventController/createAccountEvent.scenarios.json new file mode 100644 index 00000000..b78e6953 --- /dev/null +++ b/src/test/resources/data/functional/controllers/accountEventController/createAccountEvent.scenarios.json @@ -0,0 +1,176 @@ +[ + { + "description": "Should successfully create the event", + "input": { + "body": { + "description":"Create Event", + "start_datetime": "2023-07-21T13:12:17.000+0000", + "end_datetime": "2023-07-22T13:12:17.000+0000" + }, + "accountId": "0011e00000bWSxdAAG" + }, + "mocks": { + "makeCompositeRequest": { + "compositeResponse": [ + { + "body": { + "id": "00T1e000007mDA7EAM", + "success": true, + "errors": [] + }, + "httpHeaders": { + "Location": "/services/data/v58.0/sobjects/Event/00T1e000007mDA7EAM" + }, + "httpStatusCode": 201, + "referenceId": "CreateEvent" + } + ] + } + }, + "output": { + "event_id": "00T1e000007mDA7EAM" + } + }, + { + "description": "Should fail when the event description is empty", + "input": { + "body": { + "description":"", + "start_datetime": "2023-07-21T13:12:17.000+0000", + "end_datetime": "2023-07-22T13:12:17.000+0000" + }, + "accountId": "0011e00000bWSxdAAG" + }, + "mocks": {}, + "output": { + "http_code": 400, + "message": "At least one parameter is invalid or missing.", + "code": "INVALID_PARAMS", + "internal_error_identifier": "b_2", + "param_errors": [ + "missing_description" + ] + } + }, + { + "description": "Should fail when event task description is not provided", + "input": { + "body": { + "start_datetime": "2023-07-21T13:12:17.000+0000", + "end_datetime": "2023-07-22T13:12:17.000+0000" + }, + "accountId": "0011e00000bWSxdAAG" + }, + "mocks": {}, + "output": { + "http_code": 400, + "message": "At least one parameter is invalid or missing.", + "code": "INVALID_PARAMS", + "internal_error_identifier": "b_2", + "param_errors": [ + "missing_description" + ] + } + }, + { + "description": "Should fail when the event start_datetime is invalid", + "input": { + "body": { + "description":"Create Event", + "start_datetime": "2023-07-21", + "end_datetime": "2023-07-22T13:12:17.000+0000" + }, + "accountId": "0011e00000bWSxdAAG" + }, + "mocks": {}, + "output": { + "http_code": 400, + "message": "At least one parameter is invalid or missing.", + "code": "INVALID_PARAMS", + "internal_error_identifier": "b_2", + "param_errors": [ + "invalid_start_datetime" + ] + } + }, + { + "description": "Should fail when the event end_datetime is invalid", + "input": { + "body": { + "description":"Create Event", + "start_datetime": "2023-07-22T13:12:17.000+0000", + "end_datetime": "2023-07-22T13:12.000+0000" + }, + "accountId": "0011e00000bWSxdAAG" + }, + "mocks": {}, + "output": { + "http_code": 400, + "message": "At least one parameter is invalid or missing.", + "code": "INVALID_PARAMS", + "internal_error_identifier": "b_2", + "param_errors": [ + "invalid_end_datetime" + ] + } + }, + { + "description": "Should fail when the event description is too long", + "input": { + "body": { + "description":"Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Donec quam felis, ultricies nec, pellentesque eu, pretium quis, sem. Nulla consequat massa quis enim. Donec pede justo, fringilla vel, aliquet nec, vulputate eget, arcu. In enim justo, rhoncus ut, imperdiet a, venenatis vitae, justo. Nullam dictum felis eu pede mollis pretium. Integer tincidunt. Cras dapibus. Vivamus elementum semper nisi. Aenean vulputate eleifend tellus. Aenean leo ligula, porttitor eu, consequat vitae, eleifend ac, enim. Aliquam lorem ante, dapibus in, viverra quis, feugiat a, tellus. Phasellus viverra nulla ut metus varius laoreet. Quisque rutrum. Aenean imperdiet. Etiam ultricies nisi vel augue. Curabitur ullamcorper ultricies nisi. Nam eget dui. Etiam rhoncus. Maecenas tempus, tellus eget condimentum rhoncus, sem quam semper libero, sit amet adipiscing sem neque sed ipsum. Nam quam nunc, blandit vel, luctus pulvinar, hendrerit id, lorem. Maecenas nec odio et ante tincidunt tempus. Donec vitae sapien ut libero venenatis faucibus. Nullam quis ante. Etiam sit amet orci eget eros faucibus tincidunt. Duis leo. Sed fringilla mauris sit amet nibh. Donec sodales sagittis magna. Sed consequat, leo eget bibendum sodales, augue velit cursus nunc, quis gravida magna mi a libero. Fusce vulputate eleifend sapien. Vestibulum purus quam, scelerisque ut, mollis sed, nonummy id, metus. Nullam accumsan lorem in dui. Cras ultricies mi eu turpis hendrerit fringilla. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; In ac dui quis mi consectetuer lacinia. Nam pretium turpis et arcu. Duis arcu tortor, suscipit eget, imperdiet nec, imperdiet iaculis, ipsum. Sed aliquam ultrices mauris. Integer ante arcu, accumsan a, consectetuer eget, posuere ut, mauris. Praesent adipiscing. Phasellus ullamcorper ipsum rutrum nunc. Nunc nonummy metus. Vestibulum volutpat pretium libero. Cras id dui. Aenean ut eros et nisl sagittis vestibulum. Nullam nulla eros, ultricies sit amet, nonummy id, imperdiet feugiat, pede. Sed lectus. Donec mollis hendrerit risus. Phasellus nec sem in justo pellentesque facilisis. Etiam imperdiet imperdiet orci. Nunc nec neque. Phasellus leo dolor, tempus non, auctor et, hendrerit quis, nisi. Curabitur ligula sapien, tincidunt non, euismod vitae, posuere imperdiet, leo. Maecenas malesuada. Praesent congue erat at massa. Sed cursus turpis vitae tortor. Donec posuere vulputate arcu. Phasellus accumsan cursus velit. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Sed aliquam, nisi quis porttitor congue, elit erat euismod orci, ac placerat dolor lectus quis orci. Phasellus consectetuer vestibulum elit. Aenean tellus metus, bibendum sed, posuere ac, mattis non, nunc. Vestibulum fringilla pede sit amet augue. In turpis. Pellentesque posuere. Praesent turpis. Aenean posuere, tortor sed cursus feugiat, nunc augue blandit nunc, eu sollicitudin urna dolor sagittis lacus. Donec elit libero, sodales nec, volutpat a, suscipit non, turpis. Nullam sagittis. Suspendisse pulvinar, augue ac venenatis condimentum, sem libero volutpat nibh, nec pellentesque velit pede quis nunc. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Fusce id purus. Ut varius tincidunt libero. Phasellus dolor. Maecenas vestibulum mollis diam. Pellentesque ut neque. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. In dui magna, posuere eget, vestibulum et, tempor auctor, justo. In ac felis quis tortor malesuada pretium. Pellentesque auctor neque nec urna. Proin sapien ipsum, porta a, auctor quis, euismod ut, mi. Aenean viverra rhoncus pede. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Ut non enim eleifend felis pretium feugiat. Vivamus quis mi. Phasellus a est. Phasellus magna. In hac habitasse platea dictumst. Curabitur at lacus ac velit ornare lobortis. Curabitur a felis in nunc fringilla tristique. Morbi mattis ullamcorper velit. Phasellus gravida semper nisi. Nullam vel sem. Pellentesque libero tortor, tincidunt et, tincidunt eget, semper nec, quam. Sed hendrerit. Morbi ac felis. Nunc egestas, augue at pellentesque laoreet, felis eros vehicula leo, at malesuada velit leo quis pede. Donec interdum, metus et hendrerit aliquet, dolor diam sagittis ligula, eget egestas libero turpis vel mi. Nunc nulla. Fusce risus nisl, viverra et, tempor et, pretium in, sapien. Donec venenatis vulputate lorem. Morbi nec metus. Phasellus blandit leo ut odio. Maecenas ullamcorper, dui et placerat feugiat, eros pede varius nisi, condimentum viverra felis nunc et lorem. Sed magna purus, fermentum eu, tincidunt eu, varius ut, felis. In auctor lobortis lacus. Quisque libero metus, condimentum nec, tempor a, commodo mollis, magna. Vestibulum ullamcorper mauris at ligula. Fusce fermentum. Nullam cursus lacinia erat. Praesent blandit laoreet nibh. Fusce convallis metus id felis luctus adipiscing. Pellentesque egestas, neque sit amet convallis pulvinar, justo nulla eleifend augue, ac auctor orci leo non est. Quisque id mi. Ut tincidunt tincidunt erat. Etiam feugiat lorem non metus. Vestibulum dapibus nunc ac augue. Curabitur vestibulum aliquam leo. Praesent egestas neque eu enim. In hac habitasse platea dictumst. Fusce a quam. Etiam ut purus mattis mauris sodales aliquam. Curabitur nisi. Quisque malesuada placerat nisl. Nam ipsum risus, rutrum vitae, vestibulum eu, molestie vel, lacus. Sed augue ipsum, egestas nec, vestibulum et, malesuada adipiscing, dui. Vestibulum facilisis, purus nec pulvinar iaculis, ligula mi congue nunc, vitae euismod ligula urna in dolor. Mauris sollicitudin fermentum libero. Praesent nonummy mi in odio. Nunc interdum lacus sit amet orci. Vestibulum rutrum, mi nec elementum vehicula, eros quam gravida nisl, id fringilla neque ante vel mi. Morbi mollis tellus ac sapien. Phasellus volutpat, metus eget egestas mollis, lacus lacus blandit dui, id egestas quam mauris ut lacus. Fusce vel dui. Sed in libero ut nibh placerat accumsan. Proin faucibus arcu quis ante. In consectetuer turpis ut velit. Nulla sit amet est. Praesent metus tellus, elementum eu, semper a, adipiscing nec, purus. Cras risus ipsum, faucibus ut, ullamcorper id, varius ac, leo. Suspendisse feugiat. Suspendisse enim turpis, dictum sed, iaculis a, condimentum nec, nisi. Praesent nec nisl a purus blandit viverra. Praesent ac massa at ligula laoreet iaculis. Nulla neque dolor, sagittis eget, iaculis quis, molestie non, velit. Mauris turpis nunc, blandit et, volutpat molestie, porta ut, ligula. Fusce pharetra convallis urna. Quisque ut nisi. Donec mi odio, faucibus at, scelerisque quis, convallis in, nisi. Suspendisse non nisl sit amet velit hendrerit rutrum. Ut leo. Ut a nisl id ante tempus hendrerit. Proin pretium, leo ac pellentesque mollis, felis nunc ultrices eros, sed gravida augue augue mollis justo. Suspendisse eu ligula. Nulla facilisi. Donec id justo. Praesent porttitor, nulla vitae posuere iaculis, arcu nisl dignissim dolor, a pretium mi sem ut ipsum. Curabitur suscipit suscipit tellus. Praesent vestibulum dapibus nibh. Etiam iaculis nunc ac metus. Ut id nisl quis enim dignissim sagittis. Etiam sollicitudin, ipsum eu pulvinar rutrum, tellus ipsum laoreet sapien, quis venenatis ante odio sit amet eros. Proin magna. Duis vel nibh at velit scelerisque suscipit. Curabitur turpis. Vestibulum suscipit nulla quis orci. Fusce ac felis sit amet ligula pharetra condimentum. Maecenas egestas arcu quis ligula mattis placerat. Duis lobortis massa imperdiet quam. Suspendisse potenti. Pellentesque commodo eros a enim. Vestibulum turpis sem, aliquet eget, lobortis pellentesque, rutrum eu, nisl. Sed libero. Aliquam erat volutpat. Etiam vitae tortor. Morbi vestibulum volutpat enim. Aliquam eu nunc. Nunc sed turpis. Sed mollis, eros et ultrices tempus, mauris ipsum aliquam libero, non adipiscing dolor urna a orci. Nulla porta dolor. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos hymenaeos. Pellentesque dapibus hendrerit tortor. Praesent egestas tristique nibh. Sed a libero. Cras varius. Donec vitae orci sed dolor rutrum auctor. Fusce egestas elit eget lorem. Suspendisse nisl elit, rhoncus eget, elementum ac, condimentum eget, diam. Nam at tortor in tellus interdum sagittis. Aliquam lobortis. Donec orci lectus, aliquam ut, faucibus non, euismod id, nulla. Curabitur blandit mollis lacus. Nam adipiscing. Vestibulum eu odio. Vivamus laoreet. Nullam tincidunt adipiscing enim. Phasellus tempus. Proin viverra, ligula sit amet ultrices semper, ligula arcu tristique sapien, a accumsan nisi mauris ac eros. Fusce neque. Suspendisse faucibus, nunc et pellentesque egestas, lacus ante convallis tellus, vitae iaculis lacus elit id tortor. Vivamus aliquet elit ac nisl. Fusce fermentum odio nec arcu. Vivamus euismod mauris. In ut quam vitae odio lacinia tincidunt. Praesent ut ligula non mi varius sagittis. Cras sagittis. Praesent ac sem eget est egestas volutpat. Vivamus consectetuer hendrerit lacus. Cras non dolor. Vivamus in erat ut urna cursus vestibulum. Fusce commodo aliquam arcu. Nam commodo suscipit quam. Quisque id odio. Praesent venenatis metus at tortor pulvinar varius. Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Donec quam felis, ultricies nec, pellentesque eu, pretium quis, sem. Nulla consequat massa quis enim. Donec pede justo, fringilla vel, aliquet nec, vulputate eget, arcu. In enim justo, rhoncus ut, imperdiet a, venenatis vitae, justo. Nullam dictum felis eu pede mollis pretium. Integer tincidunt. Cras dapibus. Vivamus elementum semper nisi. Aenean vulputate eleifend tellus. Aenean leo ligula, porttitor eu, consequat vitae, eleifend ac, enim. Aliquam lorem ante, dapibus in, viverra quis, feugiat a, tellus. Phasellus viverra nulla ut metus varius laoreet. Quisque rutrum. Aenean imperdiet. Etiam ultricies nisi vel augue. Curabitur ullamcorper ultricies nisi. Nam eget dui. Etiam rhoncus. Maecenas tempus, tellus eget condimentum rhoncus, sem quam semper libero, sit amet adipiscing sem neque sed ipsum. Nam quam nunc, blandit vel, luctus pulvinar, hendrerit id, lorem. Maecenas nec odio et ante tincidunt tempus. Donec vitae sapien ut libero venenatis faucibus. Nullam quis ante. Etiam sit amet orci eget eros faucibus tincidunt. Duis leo. Sed fringilla mauris sit amet nibh. Donec sodales sagittis magna. Sed consequat, leo eget bibendum sodales, augue velit cursus nunc, quis gravida magna mi a libero. Fusce vulputate eleifend sapien. Vestibulum purus quam, scelerisque ut, mollis sed, nonummy id, metus. Nullam accumsan lorem in dui. Cras ultricies mi eu turpis hendrerit fringilla. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; In ac dui quis mi consectetuer lacinia. Nam pretium turpis et arcu. Duis arcu tortor, suscipit eget, imperdiet nec, imperdiet iaculis, ipsum. Sed aliquam ultrices mauris. Integer ante arcu, accumsan a, consectetuer eget, posuere ut, mauris. Praesent adipiscing. Phasellus ullamcorper ipsum rutrum nunc. Nunc nonummy metus. Vestibulum volutpat pretium libero. Cras id dui. Aenean ut eros et nisl sagittis vestibulum. Nullam nulla eros, ultricies sit amet, nonummy id, imperdiet feugiat, pede. Sed lectus. Donec mollis hendrerit risus. Phasellus nec sem in justo pellentesque facilisis. Etiam imperdiet imperdiet orci. Nunc nec neque. Phasellus leo dolor, tempus non, auctor et, hendrerit quis, nisi. Curabitur ligula sapien, tincidunt non, euismod vitae, posuere imperdiet, leo. Maecenas malesuada. Praesent congue erat at massa. Sed cursus turpis vitae tortor. Donec posuere vulputate arcu. Phasellus accumsan cursus velit. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Sed aliquam, nisi quis porttitor congue, elit erat euismod orci, ac placerat dolor lectus quis orci. Phasellus consectetuer vestibulum elit. Aenean tellus metus, bibendum sed, posuere ac, mattis non, nunc. Vestibulum fringilla pede sit amet augue. In turpis. Pellentesque posuere. Praesent turpis. Aenean posuere, tortor sed cursus feugiat, nunc augue blandit nunc, eu sollicitudin urna dolor sagittis lacus. Donec elit libero, sodales nec, volutpat a, suscipit non, turpis. Nullam sagittis. Suspendisse pulvinar, augue ac venenatis condimentum, sem libero volutpat nibh, nec pellentesque velit pede quis nunc. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Fusce id purus. Ut varius tincidunt libero. Phasellus dolor. Maecenas vestibulum mollis diam. Pellentesque ut neque. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. In dui magna, posuere eget, vestibulum et, tempor auctor, justo. In ac felis quis tortor malesuada pretium. Pellentesque auctor neque nec urna. Proin sapien ipsum, porta a, auctor quis, euismod ut, mi. Aenean viverra rhoncus pede. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Ut non enim eleifend felis pretium feugiat. Vivamus quis mi. Phasellus a est. Phasellus magna. In hac habitasse platea dictumst. Curabitur at lacus ac velit ornare lobortis. Curabitur a felis in nunc fringilla tristique. Morbi mattis ullamcorper velit. Phasellus gravida semper nisi. Nullam vel sem. Pellentesque libero tortor, tincidunt et, tincidunt eget, semper nec, quam. Sed hendrerit. Morbi ac felis. Nunc egestas, augue at pellentesque laoreet, felis eros vehicula leo, at malesuada velit leo quis pede. Donec interdum, metus et hendrerit aliquet, dolor diam sagittis ligula, eget egestas libero turpis vel mi. Nunc nulla. Fusce risus nisl, viverra et, tempor et, pretium in, sapien. Donec venenatis vulputate lorem. Morbi nec metus. Phasellus blandit leo ut odio. Maecenas ullamcorper, dui et placerat feugiat, eros pede varius nisi, condimentum viverra felis nunc et lorem. Sed magna purus, fermentum eu, tincidunt eu, varius ut, felis. In auctor lobortis lacus. Quisque libero metus, condimentum nec, tempor a, commodo mollis, magna. Vestibulum ullamcorper mauris at ligula. Fusce fermentum. Nullam cursus lacinia erat. Praesent blandit laoreet nibh. Fusce convallis metus id felis luctus adipiscing. Pellentesque egestas, neque sit amet convallis pulvinar, justo nulla eleifend augue, ac auctor orci leo non est. Quisque id mi. Ut tincidunt tincidunt erat. Etiam feugiat lorem non metus. Vestibulum dapibus nunc ac augue. Curabitur vestibulum aliquam leo. Praesent egestas neque eu enim. In hac habitasse platea dictumst. Fusce a quam. Etiam ut purus mattis mauris sodales aliquam. Curabitur nisi. Quisque malesuada placerat nisl. Nam ipsum risus, rutrum vitae, vestibulum eu, molestie vel, lacus. Sed augue ipsum, egestas nec, vestibulum et, malesuada adipiscing, dui. Vestibulum facilisis, purus nec pulvinar iaculis, ligula mi congue nunc, vitae euismod ligula urna in dolor. Mauris sollicitudin fermentum libero. Praesent nonummy mi in odio. Nunc interdum lacus sit amet orci. Vestibulum rutrum, mi nec elementum vehicula, eros quam gravida nisl, id fringilla neque ante vel mi. Morbi mollis tellus ac sapien. Phasellus volutpat, metus eget egestas mollis, lacus lacus blandit dui, id egestas quam mauris ut lacus. Fusce vel dui. Sed in libero ut nibh placerat accumsan. Proin faucibus arcu quis ante. In consectetuer turpis ut velit. Nulla sit amet est. Praesent metus tellus, elementum eu, semper a, adipiscing nec, purus. Cras risus ipsum, faucibus ut, ullamcorper id, varius ac, leo. Suspendisse feugiat. Suspendisse enim turpis, dictum sed, iaculis a, condimentum nec, nisi. Praesent nec nisl a purus blandit viverra. Praesent ac massa at ligula laoreet iaculis. Nulla neque dolor, sagittis eget, iaculis quis, molestie non, velit. Mauris turpis nunc, blandit et, volutpat molestie, porta ut, ligula. Fusce pharetra convallis urna. Quisque ut nisi. Donec mi odio, faucibus at, scelerisque quis, convallis in, nisi. Suspendisse non nisl sit amet velit hendrerit rutrum. Ut leo. Ut a nisl id ante tempus hendrerit. Proin pretium, leo ac pellentesque mollis, felis nunc ultrices eros, sed gravida augue augue mollis justo. Suspendisse eu ligula. Nulla facilisi. Donec id justo. Praesent porttitor, nulla vitae posuere iaculis, arcu nisl dignissim dolor, a pretium mi sem ut ipsum. Curabitur suscipit suscipit tellus. Praesent vestibulum dapibus nibh. Etiam iaculis nunc ac metus. Ut id nisl quis enim dignissim sagittis. Etiam sollicitudin, ipsum eu pulvinar rutrum, tellus ipsum laoreet sapien, quis venenatis ante odio sit amet eros. Proin magna. Duis vel nibh at velit scelerisque suscipit. Curabitur turpis. Vestibulum suscipit nulla quis orci. Fusce ac felis sit amet ligula pharetra condimentum. Maecenas egestas arcu quis ligula mattis placerat. Duis lobortis massa imperdiet quam. Suspendisse potenti. Pellentesque commodo eros a enim. Vestibulum turpis sem, aliquet eget, lobortis pellentesque, rutrum eu, nisl. Sed libero. Aliquam erat volutpat. Etiam vitae tortor. Morbi vestibulum volutpat enim. Aliquam eu nunc. Nunc sed turpis. Sed mollis, eros et ultrices tempus, mauris ipsum aliquam libero, non adipiscing dolor urna a orci. Nulla porta dolor. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos hymenaeos. Pellentesque dapibus hendrerit tortor. Praesent egestas tristique nibh. Sed a libero. Cras varius. Donec vitae orci sed dolor rutrum auctor. Fusce egestas elit eget lorem. Suspendisse nisl elit, rhoncus eget, elementum ac, condimentum eget, diam. Nam at tortor in tellus interdum sagittis. Aliquam lobortis. Donec orci lectus, aliquam ut, faucibus non, euismod id, nulla. Curabitur blandit mollis lacus. Nam adipiscing. Vestibulum eu odio. Vivamus laoreet. Nullam tincidunt adipiscing enim. Phasellus tempus. Proin viverra, ligula sit amet ultrices semper, ligula arcu tristique sapien, a accumsan nisi mauris ac eros. Fusce neque. Suspendisse faucibus, nunc et pellentesque egestas, lacus ante convallis tellus, vitae iaculis lacus elit id tortor. Vivamus aliquet elit ac nisl. Fusce fermentum odio nec arcu. Vivamus euismod mauris. In ut quam vitae odio lacinia tincidunt. Praesent ut ligula non mi varius sagittis. Cras sagittis. Praesent ac sem eget est egestas volutpat. Vivamus consectetuer hendrerit lacus. Cras non dolor. Vivamus in erat ut urna cursus vestibulum. Fusce commodo aliquam arcu. Nam commodo suscipit quam. Quisque id odio. Praesent venenatis metus at tortor pulvinar varius. Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Donec quam felis, ultricies nec, pellentesque eu, pretium quis, sem. Nulla consequat massa quis enim. Donec pede justo, fringilla vel, aliquet nec, vulputate eget, arcu. In enim justo, rhoncus ut, imperdiet a, venenatis vitae, justo. Nullam dictum felis eu pede mollis pretium. Integer tincidunt. Cras dapibus. Vivamus elementum semper nisi. Aenean vulputate eleifend tellus. Aenean leo ligula, porttitor eu, consequat vitae, eleifend ac, enim. Aliquam lorem ante, dapibus in, viverra quis, feugiat a, tellus. Phasellus viverra nulla ut metus varius laoreet. Quisque rutrum. Aenean imperdiet. Etiam ultricies nisi vel augue. Curabitur ullamcorper ultricies nisi. Nam eget dui. Etiam rhoncus. Maecenas tempus, tellus eget condimentum rhoncus, sem quam semper libero, sit amet adipiscing sem neque sed ipsum. Nam quam nunc, blandit vel, luctus pulvinar, hendrerit id, lorem. Maecenas nec odio et ante tincidunt tempus. Donec vitae sapien ut libero venenatis faucibus. Nullam quis ante. Etiam sit amet orci eget eros faucibus tincidunt. Duis leo. Sed fringilla mauris sit amet nibh. Donec sodales sagittis magna. Sed consequat, leo eget bibendum sodales, augue velit cursus nunc, quis gravida magna mi a libero. Fusce vulputate eleifend sapien. Vestibulum purus quam, scelerisque ut, mollis sed, nonummy id, metus. Nullam accumsan lorem in dui. Cras ultricies mi eu turpis hendrerit fringilla. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; In ac dui quis mi consectetuer lacinia. Nam pretium turpis et arcu. Duis arcu tortor, suscipit eget, imperdiet nec, imperdiet iaculis, ipsum. Sed aliquam ultrices mauris. Integer ante arcu, accumsan a, consectetuer eget, posuere ut, mauris. Praesent adipiscing. Phasellus ullamcorper ipsum rutrum nunc. Nunc nonummy metus. Vestibulum volutpat pretium libero. Cras id dui. Aenean ut eros et nisl sagittis vestibulum. Nullam nulla eros, ultricies sit amet, nonummy id, imperdiet feugiat, pede. Sed lectus. Donec mollis hendrerit risus. Phasellus nec sem in justo pellentesque facilisis. Etiam imperdiet imperdiet orci. Nunc nec neque. Phasellus leo dolor, tempus non, auctor et, hendrerit quis, nisi. Curabitur ligula sapien, tincidunt non, euismod vitae, posuere imperdiet, leo. Maecenas malesuada. Praesent congue erat at massa. Sed cursus turpis vitae tortor. Donec posuere vulputate arcu. Phasellus accumsan cursus velit. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Sed aliquam, nisi quis porttitor congue, elit erat euismod orci, ac placerat dolor lectus quis orci. Phasellus consectetuer vestibulum elit. Aenean tellus metus, bibendum sed, posuere ac, mattis non, nunc. Vestibulum fringilla pede sit amet augue. In turpis. Pellentesque posuere. Praesent turpis. Aenean posuere, tortor sed cursus feugiat, nunc augue blandit nunc, eu sollicitudin urna dolor sagittis lacus. Donec elit libero, sodales nec, volutpat a, suscipit non, turpis. Nullam sagittis. Suspendisse pulvinar, augue ac venenatis condimentum, sem libero volutpat nibh, nec pellentesque velit pede quis nunc. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Fusce id purus. Ut varius tincidunt libero. Phasellus dolor. Maecenas vestibulum mollis diam. Pellentesque ut neque. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. In dui magna, posuere eget, vestibulum et, tempor auctor, justo. In ac felis quis tortor malesuada pretium. Pellentesque auctor neque nec urna. Proin sapien ipsum, porta a, auctor quis, euismod ut, mi. Aenean viverra rhoncus pede. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Ut non enim eleifend felis pretium feugiat. Vivamus quis mi. Phasellus a est. Phasellus magna. In hac habitasse platea dictumst. Curabitur at lacus ac velit ornare lobortis. Curabitur a felis in nunc fringilla tristique. Morbi mattis ullamcorper velit. Phasellus gravida semper nisi. Nullam vel sem. Pellentesque libero tortor, tincidunt et, tincidunt eget, semper nec, quam. Sed hendrerit. Morbi ac felis. Nunc egestas, augue at pellentesque laoreet, felis eros vehicula leo, at malesuada velit leo quis pede. Donec interdum, metus et hendrerit aliquet, dolor diam sagittis ligula, eget egestas libero turpis vel mi. Nunc nulla. Fusce risus nisl, viverra et, tempor et, pretium in, sapien. Donec venenatis vulputate lorem. Morbi nec metus. Phasellus blandit leo ut odio. Maecenas ullamcorper, dui et placerat feugiat, eros pede varius nisi, condimentum viverra felis nunc et lorem. Sed magna purus, fermentum eu, tincidunt eu, varius ut, felis. In auctor lobortis lacus. Quisque libero metus, condimentum nec, tempor a, commodo mollis, magna. Vestibulum ullamcorper mauris at ligula. Fusce fermentum. Nullam cursus lacinia erat. Praesent blandit laoreet nibh. Fusce convallis metus id felis luctus adipiscing. Pellentesque egestas, neque sit amet convallis pulvinar, justo nulla eleifend augue, ac auctor orci leo non est. Quisque id mi. Ut tincidunt tincidunt erat. Etiam feugiat lorem non metus. Vestibulum dapibus nunc ac augue. Curabitur vestibulum aliquam leo. Praesent egestas neque eu enim. In hac habitasse platea dictumst. Fusce a quam. Etiam ut purus mattis mauris sodales aliquam. Curabitur nisi. Quisque malesuada placerat nisl. Nam ipsum risus, rutrum vitae, vestibulum eu, molestie vel, lacus. Sed augue ipsum, egestas nec, vestibulum et, malesuada adipiscing, dui. Vestibulum facilisis, purus nec pulvinar iaculis, ligula mi congue nunc, vitae euismod ligula urna in dolor. Mauris sollicitudin fermentum libero. Praesent nonummy mi in odio. Nunc interdum lacus sit amet orci. Vestibulum rutrum, mi nec elementum vehicula, eros quam gravida nisl, id fringilla neque ante vel mi. Morbi mollis tellus ac sapien. Phasellus volutpat, metus eget egestas mollis, lacus lacus blandit dui, id egestas quam mauris ut lacus. Fusce vel dui. Sed in libero ut nibh placerat accumsan. Proin faucibus arcu quis ante. In consectetuer turpis ut velit. Nulla sit amet est. Praesent metus tellus, elementum eu, semper a, adipiscing nec, purus. Cras risus ipsum, faucibus ut, ullamcorper id, varius ac, leo. Suspendisse feugiat. Suspendisse enim turpis, dictum sed, iaculis a, condimentum nec, nisi. Praesent nec nisl a purus blandit viverra. Praesent ac massa at ligula laoreet iaculis. Nulla neque dolor, sagittis eget, iaculis quis, molestie non, velit. Mauris turpis nunc, blandit et, volutpat molestie, porta ut, ligula. Fusce pharetra convallis urna. Quisque ut nisi. Donec mi odio, faucibus at, scelerisque quis, convallis in, nisi. Suspendisse non nisl sit amet velit hendrerit rutrum. Ut leo. Ut a nisl id ante tempus hendrerit. Proin pretium, leo ac pellentesque mollis, felis nunc ultrices eros, sed gravida augue augue mollis justo. Suspendisse eu ligula. Nulla facilisi. Donec id justo. Praesent porttitor, nulla vitae posuere iaculis, arcu nisl dignissim dolor, a pretium mi sem ut ipsum. Curabitur suscipit suscipit tellus. Praesent vestibulum dapibus nibh. Etiam iaculis nunc ac metus. Ut id nisl quis enim dignissim sagittis. Etiam sollicitudin, ipsum eu pulvinar rutrum, tellus ipsum laoreet sapien, quis venenatis ante odio sit amet eros. Proin magna. Duis vel nibh at velit scelerisque suscipit. Curabitur turpis. Vestibulum suscipit nulla quis orci. Fusce ac felis sit amet ligula pharetra condimentum. Maecenas egestas arcu quis ligula mattis placerat. Duis lobortis massa imperdiet quam. Suspendisse potenti. Pellentesque commodo eros a enim. Vestibulum turpis sem, aliquet eget, lobortis pellentesque, rutrum eu, nisl. Sed libero. Aliquam erat volutpat. Etiam vitae tortor. Morbi vestibulum volutpat enim. Aliquam eu nunc. Nunc sed turpis. Sed mollis, eros et ultrices tempus, mauris ipsum aliquam libero, non adipiscing dolor urna a orci. Nulla porta dolor. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos hymenaeos. Pellentesque dapibus hendrerit tortor. Praesent egestas tristique nibh. Sed a libero. Cras varius. Donec vitae orci sed dolor rutrum auctor. Fusce egestas elit eget lorem. Suspendisse nisl elit, rhoncus eget, elementum ac, condimentum eget, diam. Nam at tortor in tellus interdum sagittis. Aliquam lobortis. Donec orci lectus, aliquam ut, faucibus non, euismod id, nulla. Curabitur blandit mollis lacus. Nam adipiscing. Vestibulum eu odio. Vivamus laoreet. Nullam tincidunt adipiscing enim. Phasellus tempus. Proin viverra, ligula sit amet ultrices semper, ligula arcu tristique sapien, a accumsan nisi mauris ac eros. Fusce neque. Suspendisse faucibus, nunc et pellentesque egestas, lacus ante convallis tellus, vitae iaculis lacus elit id tortor. Vivamus aliquet elit ac nisl. Fusce fermentum odio nec arcu. Vivamus euismod mauris. In ut quam vitae odio lacinia tincidunt. Praesent ut ligula non mi varius sagittis. Cras sagittis. Praesent ac sem eget est egestas volutpat. Vivamus consectetuer hendrerit lacus. Cras non dolor. Vivamus in erat ut urna cursus vestibulum. Fusce commodo aliquam arcu. Nam commodo suscipit quam. Quisque id odio. Praesent venenatis metus at tortor pulvinar varius. Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Donec quam felis, ultricies nec, pellentesque eu, pretium quis, sem. Nulla consequat massa quis enim. Donec pede justo, fringilla vel, aliquet nec, vulputate eget, arcu. In enim justo, rhoncus ut, imperdiet a, venenatis vitae, justo. Nullam dictum felis eu pede mollis pretium. Integer tincidunt. Cras dapibus. Vivamus elementum semper nisi. Aenean vulputate eleifend tellus. Aenean leo ligula, porttitor eu, consequat vitae, eleifend ac, enim. Aliquam lorem ante, dapibus in, viverra quis, feugiat a, tellus. Phasellus viverra nulla ut metus varius laoreet. Quisque rutrum. Aenean imperdiet. Etiam ultricies nisi vel augue. Curabitur ullamcorper ultricies nisi. Nam eget dui. Etiam rhoncus. Maecenas tempus, tellus eget condimentum rhoncus, sem quam semper libero, sit amet adipiscing sem neque sed ipsum. Nam quam nunc, blandit vel, luctus pulvinar, hendrerit id, lorem. Maecenas nec odio et ante tincidunt tempus. Donec vitae sapien ut libero venenatis faucibus. Nullam quis ante. Etiam sit amet orci eget eros faucibus tincidunt. Duis leo. Sed fringilla mauris sit amet nibh. Donec sodales sagittis magna. Sed consequat, leo eget bibendum sodales, augue velit cursus nunc, quis gravida magna mi a libero. Fusce vulputate eleifend sapien. Vestibulum purus quam, scelerisque ut, mollis sed, nonummy id, metus. Nullam accumsan lorem in dui. Cras ultricies mi eu turpis hendrerit fringilla. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; In ac dui quis mi consectetuer lacinia. Nam pretium turpis et arcu. Duis arcu tortor, suscipit eget, imperdiet nec, imperdiet iaculis, ipsum. Sed aliquam ultrices mauris. Integer ante arcu, accumsan a, consectetuer eget, posuere ut, mauris. Praesent adipiscing. Phasellus ullamcorper ipsum rutrum nunc. Nunc nonummy metus. Vestibulum volutpat pretium libero. Cras id dui. Aenean ut eros et nisl sagittis vestibulum. Nullam nulla eros, ultricies sit amet, nonummy id, imperdiet feugiat, pede. Sed lectus. Donec mollis hendrerit risus. Phasellus nec sem in justo pellentesque facilisis. Etiam imperdiet imperdiet orci. Nunc nec neque. Phasellus leo dolor, tempus non, auctor et, hendrerit quis, nisi. Curabitur ligula sapien, tincidunt non, euismod vitae, posuere imperdiet, leo. Maecenas malesuada. Praesent congue erat at massa. Sed cursus turpis vitae tortor. Donec posuere vulputate arcu. Phasellus accumsan cursus velit. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Sed aliquam, nisi quis porttitor congue, elit erat euismod orci, ac placerat dolor lectus quis orci. Phasellus consectetuer vestibulum elit. Aenean tellus metus, bibendum sed, posuere ac, mattis non, nunc. Vestibulum fringilla pede sit amet augue. In turpis. Pellentesque posuere. Praesent turpis. Aenean posuere, tortor sed cursus feugiat, nunc augue blandit nunc, eu sollicitudin urna dolor sagittis lacus. Donec elit libero, sodales nec, volutpat a, suscipit non, turpis. Nullam sagittis. Suspendisse pulvinar, augue ac venenatis condimentum, sem libero volutpat nibh, nec pellentesque velit pede quis nunc. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Fusce id purus. Ut varius tincidunt libero. Phasellus dolor. Maecenas vestibulum mollis diam. Pellentesque ut neque. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. In dui magna, posuere eget, vestibulum et, tempor auctor, justo. In ac felis quis tortor malesuada pretium. Pellentesque auctor neque nec urna. Proin sapien ipsum, porta a, auctor quis, euismod ut, mi. Aenean viverra rhoncus pede. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Ut non enim eleifend felis pretium feugiat. Vivamus quis mi. Phasellus a est. Phasellus magna. In hac habitasse platea dictumst. Curabitur at lacus ac velit ornare lobortis. Curabitur a felis in nunc fringilla tristique. Morbi mattis ullamcorper velit. Phasellus gravida semper nisi. Nullam vel sem. Pellentesque libero tortor, tincidunt et, tincidunt eget, semper nec, quam. Sed hendrerit. Morbi ac felis. Nunc egestas, augue at pellentesque laoreet, felis eros vehicula leo, at malesuada velit leo quis pede. Donec interdum, metus et hendrerit aliquet, dolor diam sagittis ligula, eget egestas libero turpis vel mi. Nunc nulla. Fusce risus nisl, viverra et, tempor et, pretium in, sapien. Donec venenatis vulputate lorem. Morbi nec metus. Phasellus blandit leo ut odio. Maecenas ullamcorper, dui et placerat feugiat, eros pede varius nisi, condimentum viverra felis nunc et lorem. Sed magna purus, fermentum eu, tincidunt eu,", + "start_datetime": "2023-07-21T13:12:17.000+0000", + "end_datetime": "2023-07-22T13:12:17.000+0000" + }, + "accountId": "0011e00000bWSxdAAG" + }, + "mocks": {}, + "output": { + "http_code": 400, + "message": "At least one parameter is invalid or missing.", + "code": "INVALID_PARAMS", + "internal_error_identifier": "b_2", + "param_errors": [ + "description_too_long" + ] + } + }, + { + "description": "Should fail when the account id invalid", + "input": { + "body": { + "description":"Create Event", + "start_datetime": "2023-07-21T13:12:17.000+0000", + "end_datetime": "2023-07-22T13:12:17.000+0000" + }, + "accountId": "invalid" + }, + "mocks": { + "makeCompositeRequest": { + "compositeResponse": [ + { + "body": [ + { + "message": "Related To ID: id value of incorrect type: 0011e00000bWSxdAA1", + "errorCode": "MALFORMED_ID", + "fields": [ + "WhatId" + ] + } + ], + "httpHeaders": {}, + "httpStatusCode": 400, + "referenceId": "CreateEvent" + } + ] + } + }, + "output": { + "http_code": 500, + "message": "Something went wrong.", + "code": "INTERNAL_SERVER_ERROR", + "internal_error_identifier": "l_ca_cae_csae_pr_1", + "param_errors": [] + } + } +] \ No newline at end of file diff --git a/src/test/resources/fixtures/functional/controllers/accountEventController/createAccountEvent.fixtures.json b/src/test/resources/fixtures/functional/controllers/accountEventController/createAccountEvent.fixtures.json new file mode 100644 index 00000000..a6dd0b3f --- /dev/null +++ b/src/test/resources/fixtures/functional/controllers/accountEventController/createAccountEvent.fixtures.json @@ -0,0 +1,14 @@ +{ + "createAccountEvent": { + "salesforce_users": [ + { + "filepath": "classpath:fixtures/common/repositories/salesforceUser/ActiveSalesforceUser.json" + } + ], + "salesforce_oauth_tokens": [ + { + "filepath": "classpath:fixtures/common/repositories/salesforceOauthToken/ActiveSalesforceOauthToken.json" + } + ] + } +} \ No newline at end of file From cfb274e0cef6f3ec145623be6f1585b2144a635f Mon Sep 17 00:00:00 2001 From: Raj Shah Date: Fri, 15 Sep 2023 10:21:52 +0530 Subject: [PATCH 05/36] Removed unnecessary dependency --- pom.xml | 6 ------ 1 file changed, 6 deletions(-) diff --git a/pom.xml b/pom.xml index 196b1158..c9e70ecb 100644 --- a/pom.xml +++ b/pom.xml @@ -59,12 +59,6 @@ 2.15.2 - - com.fasterxml.jackson.datatype - jackson-datatype-joda - 2.15.2 - - org.springframework.boot spring-boot-starter-test From 22069f4d0ee81b4cec3441b10e6da1b01ec1caf0 Mon Sep 17 00:00:00 2001 From: Raj Shah Date: Fri, 15 Sep 2023 17:15:08 +0530 Subject: [PATCH 06/36] Added get events list api changes --- .../controllers/AccountEventController.java | 16 ++ .../api/dto/entities/EventEntity.java | 29 +++ .../formatter/GetEventsListFormatterDto.java | 23 ++ .../GetAccountEventsListFactory.java | 44 ++++ .../GetAccountEventsListInterface.java | 17 ++ .../GetSalesforceAccountEventsList.java | 121 ++++++++++ .../dto/SalesforceGetEventsListDto.java | 56 +++++ .../helper/SalesforceQueryBuilder.java | 13 + .../GetAccountEventsListService.java | 39 +++ .../CreateAccountEventTest.java | 2 - .../GetAccountEventsListTest.java | 128 ++++++++++ .../getAccountEventsList.scenarios.json | 228 ++++++++++++++++++ .../getAccountEventsList.fixtures.json | 14 ++ 13 files changed, 728 insertions(+), 2 deletions(-) create mode 100644 src/main/java/com/salessparrow/api/dto/entities/EventEntity.java create mode 100644 src/main/java/com/salessparrow/api/dto/formatter/GetEventsListFormatterDto.java create mode 100644 src/main/java/com/salessparrow/api/lib/crmActions/getAccountEventsList/GetAccountEventsListFactory.java create mode 100644 src/main/java/com/salessparrow/api/lib/crmActions/getAccountEventsList/GetAccountEventsListInterface.java create mode 100644 src/main/java/com/salessparrow/api/lib/crmActions/getAccountEventsList/GetSalesforceAccountEventsList.java create mode 100644 src/main/java/com/salessparrow/api/lib/salesforce/dto/SalesforceGetEventsListDto.java create mode 100644 src/main/java/com/salessparrow/api/services/accountEvents/GetAccountEventsListService.java create mode 100644 src/test/java/com/salessparrow/api/functional/controllers/accountEventController/GetAccountEventsListTest.java create mode 100644 src/test/resources/data/functional/controllers/accountEventController/getAccountEventsList.scenarios.json create mode 100644 src/test/resources/fixtures/functional/controllers/accountEventController/getAccountEventsList.fixtures.json diff --git a/src/main/java/com/salessparrow/api/controllers/AccountEventController.java b/src/main/java/com/salessparrow/api/controllers/AccountEventController.java index b312c96b..f8d816a1 100644 --- a/src/main/java/com/salessparrow/api/controllers/AccountEventController.java +++ b/src/main/java/com/salessparrow/api/controllers/AccountEventController.java @@ -5,6 +5,7 @@ import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; @@ -12,8 +13,10 @@ import org.springframework.web.bind.annotation.RestController; import com.salessparrow.api.dto.formatter.CreateEventFormatterDto; +import com.salessparrow.api.dto.formatter.GetEventsListFormatterDto; import com.salessparrow.api.dto.requestMapper.CreateAccountEventDto; import com.salessparrow.api.services.accountEvents.CreateAccountEventService; +import com.salessparrow.api.services.accountEvents.GetAccountEventsListService; import jakarta.servlet.http.HttpServletRequest; import jakarta.validation.Valid; @@ -28,6 +31,9 @@ public class AccountEventController { @Autowired private CreateAccountEventService createEventService; + @Autowired + private GetAccountEventsListService getAccountEventsListService; + @PostMapping("") public ResponseEntity createEvent(HttpServletRequest request, @PathVariable("account_id") String accountId, @Valid @RequestBody CreateAccountEventDto createEventDto) { @@ -39,4 +45,14 @@ public ResponseEntity createEvent(HttpServletRequest re return ResponseEntity.status(HttpStatus.CREATED).body(createEventFormatterDto); } + @GetMapping("") + public ResponseEntity getEventsList(HttpServletRequest request, + @PathVariable("account_id") String accountId) { + logger.info("Get events list request received"); + + GetEventsListFormatterDto getEventsListFormatterDto = getAccountEventsListService.getAccountEventsList(request, + accountId); + return ResponseEntity.status(HttpStatus.OK).body(getEventsListFormatterDto); + } + } diff --git a/src/main/java/com/salessparrow/api/dto/entities/EventEntity.java b/src/main/java/com/salessparrow/api/dto/entities/EventEntity.java new file mode 100644 index 00000000..3c21fed6 --- /dev/null +++ b/src/main/java/com/salessparrow/api/dto/entities/EventEntity.java @@ -0,0 +1,29 @@ +package com.salessparrow.api.dto.entities; + +import java.util.Date; + +import com.fasterxml.jackson.databind.PropertyNamingStrategies; +import com.fasterxml.jackson.databind.annotation.JsonNaming; + +import lombok.Data; + +/** + * EventEntity is a DTO class for the Event List. + */ +@Data +@JsonNaming(PropertyNamingStrategies.SnakeCaseStrategy.class) +public class EventEntity { + + private String id; + + private String creatorName; + + private String description; + + private String startDatetime; + + private String endDatetime; + + private Date lastModifiedTime; + +} diff --git a/src/main/java/com/salessparrow/api/dto/formatter/GetEventsListFormatterDto.java b/src/main/java/com/salessparrow/api/dto/formatter/GetEventsListFormatterDto.java new file mode 100644 index 00000000..bbd573c2 --- /dev/null +++ b/src/main/java/com/salessparrow/api/dto/formatter/GetEventsListFormatterDto.java @@ -0,0 +1,23 @@ +package com.salessparrow.api.dto.formatter; + +import java.util.List; +import java.util.Map; + +import com.fasterxml.jackson.databind.PropertyNamingStrategies; +import com.fasterxml.jackson.databind.annotation.JsonNaming; +import com.salessparrow.api.dto.entities.EventEntity; + +import lombok.Data; + +/** + * GetEventsListFormatterDto is a DTO class for the GetEventsListFormatterDto response. + */ +@Data +@JsonNaming(PropertyNamingStrategies.SnakeCaseStrategy.class) +public class GetEventsListFormatterDto { + + private List eventIds; + + private Map eventMapById; + +} diff --git a/src/main/java/com/salessparrow/api/lib/crmActions/getAccountEventsList/GetAccountEventsListFactory.java b/src/main/java/com/salessparrow/api/lib/crmActions/getAccountEventsList/GetAccountEventsListFactory.java new file mode 100644 index 00000000..ff701c05 --- /dev/null +++ b/src/main/java/com/salessparrow/api/lib/crmActions/getAccountEventsList/GetAccountEventsListFactory.java @@ -0,0 +1,44 @@ +package com.salessparrow.api.lib.crmActions.getAccountEventsList; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +import com.salessparrow.api.domain.User; +import com.salessparrow.api.dto.formatter.GetEventsListFormatterDto; +import com.salessparrow.api.exception.CustomException; +import com.salessparrow.api.lib.errorLib.ErrorObject; +import com.salessparrow.api.lib.globalConstants.UserConstants; + +/** + * GetAccountEventsListFactory is a factory class for the GetAccountEventsList action for + * the CRM. + */ +@Component +public class GetAccountEventsListFactory { + + Logger logger = LoggerFactory.getLogger(GetAccountEventsListFactory.class); + + @Autowired + private GetSalesforceAccountEventsList getSalesforceAccountEventsList; + + /** + * Get the list of events for a given account. + * @param user + * @param accountId + * @return GetEventsListFormatterDto + **/ + public GetEventsListFormatterDto getAccountEventsList(User user, String accountId) { + logger.info("factory for getAccountEventsList action"); + + switch (user.getUserKind()) { + case UserConstants.SALESFORCE_USER_KIND: + return getSalesforceAccountEventsList.getAccountEventsList(user, accountId); + default: + throw new CustomException( + new ErrorObject("l_ca_gatl_gatlf_gtl_1", "something_went_wrong", "Invalid user kind.")); + } + } + +} diff --git a/src/main/java/com/salessparrow/api/lib/crmActions/getAccountEventsList/GetAccountEventsListInterface.java b/src/main/java/com/salessparrow/api/lib/crmActions/getAccountEventsList/GetAccountEventsListInterface.java new file mode 100644 index 00000000..e86a0a26 --- /dev/null +++ b/src/main/java/com/salessparrow/api/lib/crmActions/getAccountEventsList/GetAccountEventsListInterface.java @@ -0,0 +1,17 @@ +package com.salessparrow.api.lib.crmActions.getAccountEventsList; + +import org.springframework.stereotype.Component; + +import com.salessparrow.api.domain.User; +import com.salessparrow.api.dto.formatter.GetEventsListFormatterDto; + +/** + * GetAccountEventsListInterface is an interface for the GetAccountEventsList action for + * the CRM. + */ +@Component +public interface GetAccountEventsListInterface { + + public GetEventsListFormatterDto getAccountEventsList(User user, String accountId); + +} diff --git a/src/main/java/com/salessparrow/api/lib/crmActions/getAccountEventsList/GetSalesforceAccountEventsList.java b/src/main/java/com/salessparrow/api/lib/crmActions/getAccountEventsList/GetSalesforceAccountEventsList.java new file mode 100644 index 00000000..4e1ae8ab --- /dev/null +++ b/src/main/java/com/salessparrow/api/lib/crmActions/getAccountEventsList/GetSalesforceAccountEventsList.java @@ -0,0 +1,121 @@ +package com.salessparrow.api.lib.crmActions.getAccountEventsList; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +import com.fasterxml.jackson.databind.DeserializationFeature; +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.salessparrow.api.domain.User; +import com.salessparrow.api.dto.entities.EventEntity; +import com.salessparrow.api.dto.formatter.GetEventsListFormatterDto; +import com.salessparrow.api.exception.CustomException; +import com.salessparrow.api.lib.Util; +import com.salessparrow.api.lib.errorLib.ErrorObject; +import com.salessparrow.api.lib.errorLib.ParamErrorObject; +import com.salessparrow.api.lib.globalConstants.SalesforceConstants; +import com.salessparrow.api.lib.httpLib.HttpClient; +import com.salessparrow.api.lib.salesforce.dto.CompositeRequestDto; +import com.salessparrow.api.lib.salesforce.dto.SalesforceGetEventsListDto; +import com.salessparrow.api.lib.salesforce.helper.MakeCompositeRequest; +import com.salessparrow.api.lib.salesforce.helper.SalesforceQueryBuilder; + +/** + * GetSalesforceAccountEventsList is a class for the GetAccountEventsList service for the + * Salesforce CRM. + */ +@Component +public class GetSalesforceAccountEventsList { + + Logger logger = LoggerFactory.getLogger(GetSalesforceAccountEventsList.class); + + @Autowired + private SalesforceConstants salesforceConstants; + + @Autowired + private MakeCompositeRequest makeCompositeRequest; + + /** + * Get the list of events for a given account in salesforce + * @param user + * @param accountId + * @return GetEventsListFormatterDto + **/ + public GetEventsListFormatterDto getAccountEventsList(User user, String accountId) { + logger.info("Salesforce getAccountEventsList action called"); + + String salesforceUserId = user.getExternalUserId(); + + SalesforceQueryBuilder salesforceQuery = new SalesforceQueryBuilder(); + String query = salesforceQuery.getAccountEventsQuery(accountId); + + String url = salesforceConstants.queryUrlPath() + query; + + CompositeRequestDto compositeReq = new CompositeRequestDto("GET", url, "GetEventsList"); + + List compositeRequests = new ArrayList(); + compositeRequests.add(compositeReq); + + HttpClient.HttpResponse response = makeCompositeRequest.makePostRequest(compositeRequests, salesforceUserId); + + return parseResponse(response.getResponseBody()); + } + + /** + * Parse Response + * @param responseBody + * @return GetEventsListFormatterDto + **/ + public GetEventsListFormatterDto parseResponse(String responseBody) { + + List eventIds = new ArrayList(); + Map eventIdToEntityMap = new HashMap<>(); + + Util util = new Util(); + JsonNode rootNode = util.getJsonNode(responseBody); + + JsonNode getEventsCompositeResponse = rootNode.get("compositeResponse").get(0); + Integer getEventsStatusCode = getEventsCompositeResponse.get("httpStatusCode").asInt(); + + if (getEventsStatusCode != 200 && getEventsStatusCode != 201) { + String errorBody = getEventsCompositeResponse.get("body").asText(); + + if (getEventsStatusCode == 400) { + throw new CustomException( + new ParamErrorObject("l_ca_gael_gsael_pr_1", errorBody, Arrays.asList("invalid_account_id"))); + } + else { + throw new CustomException(new ErrorObject("l_ca_gael_gsael_pr_2", "something_went_wrong", errorBody)); + } + } + + JsonNode recordsNode = rootNode.get("compositeResponse").get(0).get("body").get("records"); + ; + + for (JsonNode recordNode : recordsNode) { + ObjectMapper mapper = new ObjectMapper(); + mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES); + SalesforceGetEventsListDto salesforceGetEventsListDto = mapper.convertValue(recordNode, + SalesforceGetEventsListDto.class); + EventEntity eventEntity = salesforceGetEventsListDto.eventEntity(); + + eventIds.add(eventEntity.getId()); + eventIdToEntityMap.put(eventEntity.getId(), eventEntity); + } + + GetEventsListFormatterDto getEventsListFormatterDto = new GetEventsListFormatterDto(); + getEventsListFormatterDto.setEventMapById(eventIdToEntityMap); + getEventsListFormatterDto.setEventIds(eventIds); + + return getEventsListFormatterDto; + } + +} diff --git a/src/main/java/com/salessparrow/api/lib/salesforce/dto/SalesforceGetEventsListDto.java b/src/main/java/com/salessparrow/api/lib/salesforce/dto/SalesforceGetEventsListDto.java new file mode 100644 index 00000000..496a49cb --- /dev/null +++ b/src/main/java/com/salessparrow/api/lib/salesforce/dto/SalesforceGetEventsListDto.java @@ -0,0 +1,56 @@ +package com.salessparrow.api.lib.salesforce.dto; + +import java.util.Date; + +import com.fasterxml.jackson.databind.PropertyNamingStrategies; +import com.fasterxml.jackson.databind.annotation.JsonNaming; +import com.salessparrow.api.dto.entities.EventEntity; + +import lombok.Data; + +@Data +@JsonNaming(PropertyNamingStrategies.UpperCamelCaseStrategy.class) +public class SalesforceGetEventsListDto { + + private String id; + + private String description; + + private CreatedBy createdBy; + + private String startDateTime; + + private String endDateTime; + + private Date lastModifiedDate; + + @Data + @JsonNaming(PropertyNamingStrategies.UpperCamelCaseStrategy.class) + private class CreatedBy { + + private String name; + + } + + @Data + @JsonNaming(PropertyNamingStrategies.UpperCamelCaseStrategy.class) + private class Owner { + + private String name; + + } + + public EventEntity eventEntity() { + + EventEntity eventEntity = new EventEntity(); + eventEntity.setId(this.id); + eventEntity.setCreatorName(this.createdBy.name); + eventEntity.setDescription(this.description); + eventEntity.setStartDatetime(this.startDateTime); + eventEntity.setEndDatetime(this.endDateTime); + eventEntity.setLastModifiedTime(this.lastModifiedDate); + + return eventEntity; + } + +} diff --git a/src/main/java/com/salessparrow/api/lib/salesforce/helper/SalesforceQueryBuilder.java b/src/main/java/com/salessparrow/api/lib/salesforce/helper/SalesforceQueryBuilder.java index eeacbeda..cf1bcaf4 100644 --- a/src/main/java/com/salessparrow/api/lib/salesforce/helper/SalesforceQueryBuilder.java +++ b/src/main/java/com/salessparrow/api/lib/salesforce/helper/SalesforceQueryBuilder.java @@ -115,4 +115,17 @@ public String getCrmOrganizationUsersQuery(String searchTerm) { return Util.urlEncoder(query); } + /** + * Get the list of events for a given account + * @param accountId + * @return String + */ + public String getAccountEventsQuery(String accountId) { + accountId = Util.escapeSpecialChars(accountId); + + return Util.urlEncoder( + "SELECT Id, Description, CreatedBy.Name, StartDateTime, EndDateTime, LastModifiedDate FROM Event WHERE WhatId='" + + accountId + "' ORDER BY LastModifiedDate DESC LIMIT 5"); + } + } diff --git a/src/main/java/com/salessparrow/api/services/accountEvents/GetAccountEventsListService.java b/src/main/java/com/salessparrow/api/services/accountEvents/GetAccountEventsListService.java new file mode 100644 index 00000000..8566c3ee --- /dev/null +++ b/src/main/java/com/salessparrow/api/services/accountEvents/GetAccountEventsListService.java @@ -0,0 +1,39 @@ +package com.salessparrow.api.services.accountEvents; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import com.salessparrow.api.domain.User; +import com.salessparrow.api.dto.formatter.GetEventsListFormatterDto; +import com.salessparrow.api.lib.crmActions.getAccountEventsList.GetAccountEventsListFactory; + +import jakarta.servlet.http.HttpServletRequest; + +/** + * GetAccountEventsListService class is responsible for getting list of account events in + * CRM + */ +@Service +public class GetAccountEventsListService { + + Logger logger = LoggerFactory.getLogger(GetAccountEventsListService.class); + + @Autowired + private GetAccountEventsListFactory getAccountEventsListFactory; + + /** + * Get list of account events from CRM + * @param request HttpServletRequest object + * @param accountId CRM account id + * @return GetEventsListFormatterDto object + */ + public GetEventsListFormatterDto getAccountEventsList(HttpServletRequest request, String accountId) { + logger.info("getAccountEventsList Service called"); + + User currentUser = (User) request.getAttribute("current_user"); + return getAccountEventsListFactory.getAccountEventsList(currentUser, accountId); + } + +} diff --git a/src/test/java/com/salessparrow/api/functional/controllers/accountEventController/CreateAccountEventTest.java b/src/test/java/com/salessparrow/api/functional/controllers/accountEventController/CreateAccountEventTest.java index 2dce8e1e..957a1756 100644 --- a/src/test/java/com/salessparrow/api/functional/controllers/accountEventController/CreateAccountEventTest.java +++ b/src/test/java/com/salessparrow/api/functional/controllers/accountEventController/CreateAccountEventTest.java @@ -110,8 +110,6 @@ public void createAccountEvent(Scenario testScenario) throws Exception { // Check the response String expectedOutput = objectMapper.writeValueAsString(testScenario.getOutput()); String actualOutput = resultActions.andReturn().getResponse().getContentAsString(); - System.out.println("actualOutput ++++++++++ " + actualOutput); - System.out.println("expectedOutput ++++++++++ " + expectedOutput); if (resultActions.andReturn().getResponse().getStatus() == 201) { assertEquals(expectedOutput, actualOutput); diff --git a/src/test/java/com/salessparrow/api/functional/controllers/accountEventController/GetAccountEventsListTest.java b/src/test/java/com/salessparrow/api/functional/controllers/accountEventController/GetAccountEventsListTest.java new file mode 100644 index 00000000..4b0179d4 --- /dev/null +++ b/src/test/java/com/salessparrow/api/functional/controllers/accountEventController/GetAccountEventsListTest.java @@ -0,0 +1,128 @@ +package com.salessparrow.api.functional.controllers.accountEventController; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.when; + +import java.io.IOException; +import java.util.List; +import java.util.stream.Stream; + +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.mock.mockito.MockBean; +import org.springframework.context.annotation.Import; +import org.springframework.core.io.DefaultResourceLoader; +import org.springframework.core.io.Resource; +import org.springframework.http.MediaType; +import org.springframework.test.context.web.WebAppConfiguration; +import org.springframework.test.web.servlet.MockMvc; +import org.springframework.test.web.servlet.ResultActions; +import org.springframework.test.web.servlet.request.MockMvcRequestBuilders; + +import com.fasterxml.jackson.core.type.TypeReference; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.github.dynamobee.exception.DynamobeeException; +import com.salessparrow.api.helper.Cleanup; +import com.salessparrow.api.helper.Common; +import com.salessparrow.api.helper.Constants; +import com.salessparrow.api.helper.FixtureData; +import com.salessparrow.api.helper.LoadFixture; +import com.salessparrow.api.helper.Scenario; +import com.salessparrow.api.helper.Setup; +import com.salessparrow.api.lib.globalConstants.CookieConstants; +import com.salessparrow.api.lib.httpLib.HttpClient.HttpResponse; +import com.salessparrow.api.lib.salesforce.helper.MakeCompositeRequest; + +import jakarta.servlet.http.Cookie; + +@SpringBootTest +@AutoConfigureMockMvc +@WebAppConfiguration +@Import({ Setup.class, Cleanup.class, Common.class, LoadFixture.class }) +public class GetAccountEventsListTest { + + @Autowired + private MockMvc mockMvc; + + @Autowired + private Common common; + + @Autowired + private LoadFixture loadFixture; + + @Autowired + private Setup setup; + + @Autowired + private Cleanup cleanup; + + @MockBean + private MakeCompositeRequest makeCompositeRequestMock; + + @BeforeEach + public void setUp() throws DynamobeeException { + setup.perform(); + } + + @AfterEach + public void tearDown() { + cleanup.perform(); + } + + @ParameterizedTest + @MethodSource("testScenariosProvider") + public void getAccountEventsList(Scenario testScenario) throws Exception { + + // Load fixture data + String currentFunctionName = new Object() { + }.getClass().getEnclosingMethod().getName(); + FixtureData fixtureData = common.loadFixture( + "classpath:fixtures/functional/controllers/accountEventController/getAccountEventsList.fixtures.json", + currentFunctionName); + loadFixture.perform(fixtureData); + + // Read data from the scenario + ObjectMapper objectMapper = new ObjectMapper(); + String cookieValue = Constants.SALESFORCE_ACTIVE_USER_COOKIE_VALUE; + String accountId = (String) testScenario.getInput().get("accountId"); + + // Prepare mock responses + HttpResponse getEventsListMockResponse = new HttpResponse(); + getEventsListMockResponse + .setResponseBody(objectMapper.writeValueAsString(testScenario.getMocks().get("makeCompositeRequest"))); + when(makeCompositeRequestMock.makePostRequest(any(), any())).thenReturn(getEventsListMockResponse); + + // Perform the request + String url = "/api/v1/accounts/" + accountId + "/events"; + + ResultActions resultActions = mockMvc.perform(MockMvcRequestBuilders.get(url) + .cookie(new Cookie(CookieConstants.USER_LOGIN_COOKIE_NAME, cookieValue)) + .contentType(MediaType.APPLICATION_JSON)); + + // Check the response + String expectedOutput = objectMapper.writeValueAsString(testScenario.getOutput()); + String actualOutput = resultActions.andReturn().getResponse().getContentAsString(); + + assertEquals(expectedOutput, actualOutput); + } + + static Stream testScenariosProvider() throws IOException { + List testScenarios = loadScenarios(); + return testScenarios.stream(); + } + + private static List loadScenarios() throws IOException { + String scenariosPath = "classpath:data/functional/controllers/accountEventController/getAccountEventsList.scenarios.json"; + Resource resource = new DefaultResourceLoader().getResource(scenariosPath); + ObjectMapper objectMapper = new ObjectMapper(); + return objectMapper.readValue(resource.getInputStream(), new TypeReference>() { + }); + } + +} diff --git a/src/test/resources/data/functional/controllers/accountEventController/getAccountEventsList.scenarios.json b/src/test/resources/data/functional/controllers/accountEventController/getAccountEventsList.scenarios.json new file mode 100644 index 00000000..f0f59495 --- /dev/null +++ b/src/test/resources/data/functional/controllers/accountEventController/getAccountEventsList.scenarios.json @@ -0,0 +1,228 @@ +[ + { + "description": "Should return the 5 latest Notes", + "input": { + "accountId": "0011e00000bWSxdAAG" + }, + "mocks": { + "makeCompositeRequest": { + "compositeResponse": [ + { + "body": { + "totalSize": 5, + "done": true, + "records": [ + { + "attributes": { + "type": "Event", + "url": "/services/data/v58.0/sobjects/Event/00T1e000007mGYaEAA" + }, + "Id": "00T1e000007mGYaEAA", + "Description": "Description 1", + "CreatedBy": { + "attributes": { + "type": "User", + "url": "/services/data/v58.0/sobjects/User/0055i00000AUxQHAA1" + }, + "Name": "Name1" + }, + "LastModifiedDate": "2023-08-24T12:09:51.000+00:00", + "StartDateTime": "2023-08-24T12:16:05.000+0000", + "EndDateTime": "2023-08-24T13:16:05.000+0000" + }, + { + "attributes": { + "type": "Event", + "url": "/services/data/v58.0/sobjects/Event/00T1e000007mGYaEAB" + }, + "Id": "00T1e000007mGYaEAB", + "Description": "Description 2", + "CreatedBy": { + "attributes": { + "type": "User", + "url": "/services/data/v58.0/sobjects/User/0055i00000AUxQHAA1" + }, + "Name": "Name2" + }, + "LastModifiedDate": "2023-08-24T12:09:51.000+00:00", + "StartDateTime": "2023-08-24T12:16:05.000+0000", + "EndDateTime": "2023-08-24T13:16:05.000+0000" + }, + { + "attributes": { + "type": "Event", + "url": "/services/data/v58.0/sobjects/Event/00T1e000007mGYaEAC" + }, + "Id": "00T1e000007mGYaEAC", + "Description": "Description 3", + "CreatedBy": { + "attributes": { + "type": "User", + "url": "/services/data/v58.0/sobjects/User/0055i00000AUxQHAA1" + }, + "Name": "Name3" + }, + "LastModifiedDate": "2023-08-24T12:09:51.000+00:00", + "StartDateTime": "2023-08-24T12:16:05.000+0000", + "EndDateTime": "2023-08-24T13:16:05.000+0000" + }, + { + "attributes": { + "type": "Event", + "url": "/services/data/v58.0/sobjects/Event/00T1e000007mGYaEAD" + }, + "Id": "00T1e000007mGYaEAD", + "Description": "Description 4", + "CreatedBy": { + "attributes": { + "type": "User", + "url": "/services/data/v58.0/sobjects/User/0055i00000AUxQHAA1" + }, + "Name": "Name4" + }, + "LastModifiedDate": "2023-08-24T12:09:51.000+00:00", + "StartDateTime": "2023-08-24T12:16:05.000+0000", + "EndDateTime": "2023-08-24T13:16:05.000+0000" + }, + { + "attributes": { + "type": "Event", + "url": "/services/data/v58.0/sobjects/Event/00T1e000007mGYaEAE" + }, + "Id": "00T1e000007mGYaEAE", + "Description": "Description 5", + "CreatedBy": { + "attributes": { + "type": "User", + "url": "/services/data/v58.0/sobjects/User/0055i00000AUxQHAA1" + }, + "Name": "Name5" + }, + "LastModifiedDate": "2023-08-24T12:09:51.000+00:00", + "StartDateTime": "2023-08-24T12:16:05.000+0000", + "EndDateTime": "2023-08-24T13:16:05.000+0000" + } + ] + }, + "httpHeaders": {}, + "httpStatusCode": 200, + "referenceId": "GetEventsList" + } + ] + } + }, + "output": { + "event_ids": [ + "00T1e000007mGYaEAA", + "00T1e000007mGYaEAB", + "00T1e000007mGYaEAC", + "00T1e000007mGYaEAD", + "00T1e000007mGYaEAE" + ], + "event_map_by_id": { + "00T1e000007mGYaEAE": { + "id": "00T1e000007mGYaEAE", + "creator_name": "Name5", + "description": "Description 5", + "start_datetime": "2023-08-24T12:16:05.000+0000", + "end_datetime": "2023-08-24T13:16:05.000+0000", + "last_modified_time": "2023-08-24T12:09:51.000+00:00" + }, + "00T1e000007mGYaEAD": { + "id": "00T1e000007mGYaEAD", + "creator_name": "Name4", + "description": "Description 4", + "start_datetime": "2023-08-24T12:16:05.000+0000", + "end_datetime": "2023-08-24T13:16:05.000+0000", + "last_modified_time": "2023-08-24T12:09:51.000+00:00" + }, + "00T1e000007mGYaEAC": { + "id": "00T1e000007mGYaEAC", + "creator_name": "Name3", + "description": "Description 3", + "start_datetime": "2023-08-24T12:16:05.000+0000", + "end_datetime": "2023-08-24T13:16:05.000+0000", + "last_modified_time": "2023-08-24T12:09:51.000+00:00" + }, + "00T1e000007mGYaEAB": { + "id": "00T1e000007mGYaEAB", + "creator_name": "Name2", + "description": "Description 2", + "start_datetime": "2023-08-24T12:16:05.000+0000", + "end_datetime": "2023-08-24T13:16:05.000+0000", + "last_modified_time": "2023-08-24T12:09:51.000+00:00" + }, + "00T1e000007mGYaEAA": { + "id": "00T1e000007mGYaEAA", + "creator_name": "Name1", + "description": "Description 1", + "start_datetime": "2023-08-24T12:16:05.000+0000", + "end_datetime": "2023-08-24T13:16:05.000+0000", + "last_modified_time": "2023-08-24T12:09:51.000+00:00" + } + } + } + }, + { + "description": "should return empty response when no events are present", + "input": { + "accountId": "0011e00000bWSxdAAG" + }, + "mocks": { + "makeCompositeRequest": { + "compositeResponse": [ + { + "body": { + "totalSize": 0, + "done": true, + "records": [] + }, + "httpHeaders": {}, + "httpStatusCode": 200, + "referenceId": "GetEventsList" + } + ] + } + }, + "output": { + "event_ids": [], + "event_map_by_id": {} + } + }, + { + "description": "should return error response when account id is invalid", + "input": { + "accountId": "invalid" + }, + "mocks": { + "makeCompositeRequest": { + "compositeResponse": [ + { + "body": [ + { + "message": "\nLastModifiedDate FROM Event WHERE WhatId='invalid' ORDER BY LastModifiedDate\n ^\nERROR at Row:1:Column:109\ninvalid ID field: abcd", + "errorCode": "INVALID_QUERY_FILTER_OPERATOR" + } + ], + "httpHeaders": {}, + "httpStatusCode": 400, + "referenceId": "GetEventsList" + } + ] + } + }, + "output": { + "http_code": 400, + "message": "At least one parameter is invalid or missing.", + "code": "INVALID_PARAMS", + "internal_error_identifier": "l_ca_gael_gsael_pr_1", + "param_errors": [ + { + "parameter": "account_id", + "param_error_identifier": "invalid_account_id", + "message": "The account id you sent is incorrect. Please double check and try again." + } + ] + } + } +] \ No newline at end of file diff --git a/src/test/resources/fixtures/functional/controllers/accountEventController/getAccountEventsList.fixtures.json b/src/test/resources/fixtures/functional/controllers/accountEventController/getAccountEventsList.fixtures.json new file mode 100644 index 00000000..692a6447 --- /dev/null +++ b/src/test/resources/fixtures/functional/controllers/accountEventController/getAccountEventsList.fixtures.json @@ -0,0 +1,14 @@ +{ + "getAccountEventsList": { + "salesforce_users": [ + { + "filepath": "classpath:fixtures/common/repositories/salesforceUser/ActiveSalesforceUser.json" + } + ], + "salesforce_oauth_tokens": [ + { + "filepath": "classpath:fixtures/common/repositories/salesforceOauthToken/ActiveSalesforceOauthToken.json" + } + ] + } + } \ No newline at end of file From 7c8a60a03212c155777bdef1ceceb810e239c54d Mon Sep 17 00:00:00 2001 From: Raj Shah Date: Fri, 15 Sep 2023 17:32:22 +0530 Subject: [PATCH 07/36] Renamed variables --- .../DeleteSalesforceAccountTask.java | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/salessparrow/api/lib/crmActions/deleteAccountTask/DeleteSalesforceAccountTask.java b/src/main/java/com/salessparrow/api/lib/crmActions/deleteAccountTask/DeleteSalesforceAccountTask.java index ea237034..e5144cfc 100644 --- a/src/main/java/com/salessparrow/api/lib/crmActions/deleteAccountTask/DeleteSalesforceAccountTask.java +++ b/src/main/java/com/salessparrow/api/lib/crmActions/deleteAccountTask/DeleteSalesforceAccountTask.java @@ -70,15 +70,15 @@ private void parseResponse(String responseBody) { Util util = new Util(); JsonNode rootNode = util.getJsonNode(responseBody); - JsonNode deleteNoteCompositeResponse = rootNode.get("compositeResponse").get(0); - Integer deleteNoteStatusCode = deleteNoteCompositeResponse.get("httpStatusCode").asInt(); + JsonNode deleteTaskCompositeResponse = rootNode.get("compositeResponse").get(0); + Integer deleteTaskStatusCode = deleteTaskCompositeResponse.get("httpStatusCode").asInt(); - if (deleteNoteStatusCode != 200 && deleteNoteStatusCode != 201 && deleteNoteStatusCode != 204) { - logger.error("Error in deleting task in salesforce:{}", deleteNoteCompositeResponse); - String errorBody = deleteNoteCompositeResponse.get("body").asText(); + if (deleteTaskStatusCode != 200 && deleteTaskStatusCode != 201 && deleteTaskStatusCode != 204) { + logger.error("Error in deleting task in salesforce:{}", deleteTaskCompositeResponse); + String errorBody = deleteTaskCompositeResponse.get("body").asText(); // MALFORMED_ID or NOT_FOUND - if (deleteNoteStatusCode == 400 || deleteNoteStatusCode == 404) { + if (deleteTaskStatusCode == 400 || deleteTaskStatusCode == 404) { throw new CustomException( new ParamErrorObject("l_ca_dan_dasn_pr_1", errorBody, Arrays.asList("invalid_task_id"))); From 7431e479b00f5afb012cfc5ed57ed28dc4363278 Mon Sep 17 00:00:00 2001 From: Raj Shah Date: Fri, 15 Sep 2023 18:47:27 +0530 Subject: [PATCH 08/36] Added delete note api --- .../controllers/AccountEventController.java | 15 +++ .../DeleteAccountEvent.java | 15 +++ .../DeleteAccountEventFactory.java | 44 +++++++++ .../DeleteSalesforceAccountEvent.java | 92 +++++++++++++++++++ .../globalConstants/SalesforceConstants.java | 4 + .../accountEvents/DeleteEventService.java | 40 ++++++++ .../resources/config/ParamErrorConfig.json | 5 + 7 files changed, 215 insertions(+) create mode 100644 src/main/java/com/salessparrow/api/lib/crmActions/deleteAccountEvent/DeleteAccountEvent.java create mode 100644 src/main/java/com/salessparrow/api/lib/crmActions/deleteAccountEvent/DeleteAccountEventFactory.java create mode 100644 src/main/java/com/salessparrow/api/lib/crmActions/deleteAccountEvent/DeleteSalesforceAccountEvent.java create mode 100644 src/main/java/com/salessparrow/api/services/accountEvents/DeleteEventService.java diff --git a/src/main/java/com/salessparrow/api/controllers/AccountEventController.java b/src/main/java/com/salessparrow/api/controllers/AccountEventController.java index f8d816a1..1ff0e591 100644 --- a/src/main/java/com/salessparrow/api/controllers/AccountEventController.java +++ b/src/main/java/com/salessparrow/api/controllers/AccountEventController.java @@ -5,6 +5,7 @@ import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.DeleteMapping; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PostMapping; @@ -16,6 +17,7 @@ import com.salessparrow.api.dto.formatter.GetEventsListFormatterDto; import com.salessparrow.api.dto.requestMapper.CreateAccountEventDto; import com.salessparrow.api.services.accountEvents.CreateAccountEventService; +import com.salessparrow.api.services.accountEvents.DeleteEventService; import com.salessparrow.api.services.accountEvents.GetAccountEventsListService; import jakarta.servlet.http.HttpServletRequest; @@ -34,6 +36,9 @@ public class AccountEventController { @Autowired private GetAccountEventsListService getAccountEventsListService; + @Autowired + private DeleteEventService deleteEventService; + @PostMapping("") public ResponseEntity createEvent(HttpServletRequest request, @PathVariable("account_id") String accountId, @Valid @RequestBody CreateAccountEventDto createEventDto) { @@ -55,4 +60,14 @@ public ResponseEntity getEventsList(HttpServletReques return ResponseEntity.status(HttpStatus.OK).body(getEventsListFormatterDto); } + @DeleteMapping("/{event_id}") + public ResponseEntity deleteEvent(HttpServletRequest request, @PathVariable("account_id") String accountId, + @PathVariable("event_id") String eventId) { + logger.info("Delete event request received"); + + deleteEventService.deleteAccountEvent(request, accountId, eventId); + + return ResponseEntity.status(HttpStatus.NO_CONTENT).build(); + } + } diff --git a/src/main/java/com/salessparrow/api/lib/crmActions/deleteAccountEvent/DeleteAccountEvent.java b/src/main/java/com/salessparrow/api/lib/crmActions/deleteAccountEvent/DeleteAccountEvent.java new file mode 100644 index 00000000..c93c59aa --- /dev/null +++ b/src/main/java/com/salessparrow/api/lib/crmActions/deleteAccountEvent/DeleteAccountEvent.java @@ -0,0 +1,15 @@ +package com.salessparrow.api.lib.crmActions.deleteAccountEvent; + +import org.springframework.stereotype.Component; + +import com.salessparrow.api.domain.User; + +/** + * DeleteAccountEvent is an interface for deleting an event in an account. + */ +@Component +public interface DeleteAccountEvent { + + public void deleteAccountEvent(User user, String accountId, String eventId); + +} diff --git a/src/main/java/com/salessparrow/api/lib/crmActions/deleteAccountEvent/DeleteAccountEventFactory.java b/src/main/java/com/salessparrow/api/lib/crmActions/deleteAccountEvent/DeleteAccountEventFactory.java new file mode 100644 index 00000000..388fd3be --- /dev/null +++ b/src/main/java/com/salessparrow/api/lib/crmActions/deleteAccountEvent/DeleteAccountEventFactory.java @@ -0,0 +1,44 @@ +package com.salessparrow.api.lib.crmActions.deleteAccountEvent; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +import com.salessparrow.api.domain.User; +import com.salessparrow.api.exception.CustomException; +import com.salessparrow.api.lib.errorLib.ErrorObject; +import com.salessparrow.api.lib.globalConstants.UserConstants; + +/** + * DeleteAccountEventFactory is a factory class that handles the deleting of an event in + * an account. + */ +@Component +public class DeleteAccountEventFactory { + + Logger logger = LoggerFactory.getLogger(DeleteAccountEventFactory.class); + + @Autowired + DeleteSalesforceAccountEvent deleteSalesforceAccountEvent; + + /** + * Deletes a event in an account. + * @param user + * @param accountId + * @param eventId + * @return void + */ + public void deleteAccountEvent(User user, String accountId, String eventId) { + logger.info("Delete Account Event Factory called"); + switch (user.getUserKind()) { + case UserConstants.SALESFORCE_USER_KIND: + deleteSalesforceAccountEvent.deleteAccountEvent(user, accountId, eventId); + break; + default: + throw new CustomException( + new ErrorObject("l_ca_dae_daef_1", "something_went_wrong", "Invalid user kind.")); + } + } + +} diff --git a/src/main/java/com/salessparrow/api/lib/crmActions/deleteAccountEvent/DeleteSalesforceAccountEvent.java b/src/main/java/com/salessparrow/api/lib/crmActions/deleteAccountEvent/DeleteSalesforceAccountEvent.java new file mode 100644 index 00000000..4805cb8c --- /dev/null +++ b/src/main/java/com/salessparrow/api/lib/crmActions/deleteAccountEvent/DeleteSalesforceAccountEvent.java @@ -0,0 +1,92 @@ +package com.salessparrow.api.lib.crmActions.deleteAccountEvent; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +import com.fasterxml.jackson.databind.JsonNode; +import com.salessparrow.api.domain.User; +import com.salessparrow.api.exception.CustomException; +import com.salessparrow.api.lib.Util; +import com.salessparrow.api.lib.errorLib.ErrorObject; +import com.salessparrow.api.lib.errorLib.ParamErrorObject; +import com.salessparrow.api.lib.globalConstants.SalesforceConstants; +import com.salessparrow.api.lib.httpLib.HttpClient; +import com.salessparrow.api.lib.salesforce.dto.CompositeRequestDto; +import com.salessparrow.api.lib.salesforce.helper.MakeCompositeRequest; + +/** + * DeleteSalesforceAccountEvent is a class that handles the deleting of an event in an + * account for salesforce. + */ +@Component +public class DeleteSalesforceAccountEvent implements DeleteAccountEvent { + + Logger logger = LoggerFactory.getLogger(DeleteSalesforceAccountEvent.class); + + @Autowired + private SalesforceConstants salesforceConstants; + + @Autowired + private MakeCompositeRequest makeCompositeRequest; + + /** + * Deletes an event in an account for salesforce. + * @param user + * @param accountId + * @param eventId + * @return void + */ + public void deleteAccountEvent(User user, String accountId, String eventId) { + logger.info("Delete Salesforce Account Event called"); + + String salesforceUserId = user.getExternalUserId(); + + String url = salesforceConstants.salesforceDeleteAccountEventUrl(eventId); + + CompositeRequestDto compositeReq = new CompositeRequestDto("DELETE", url, "DeleteEvent"); + + List compositeRequests = new ArrayList(); + compositeRequests.add(compositeReq); + + HttpClient.HttpResponse response = makeCompositeRequest.makePostRequest(compositeRequests, salesforceUserId); + + parseResponse(response.getResponseBody()); + + } + + /** + * Parses the response from salesforce. + * @param responseBody + * @return void + */ + private void parseResponse(String responseBody) { + logger.info("Parsing response body"); + Util util = new Util(); + JsonNode rootNode = util.getJsonNode(responseBody); + + JsonNode deleteEventCompositeResponse = rootNode.get("compositeResponse").get(0); + Integer deleteEventStatusCode = deleteEventCompositeResponse.get("httpStatusCode").asInt(); + + if (deleteEventStatusCode != 200 && deleteEventStatusCode != 201 && deleteEventStatusCode != 204) { + logger.error("Error in deleting event in salesforce:{}", deleteEventCompositeResponse); + String errorBody = deleteEventCompositeResponse.get("body").asText(); + + // MALFORMED_ID or NOT_FOUND + if (deleteEventStatusCode == 400 || deleteEventStatusCode == 404) { + + throw new CustomException( + new ParamErrorObject("l_ca_dat_dsat_pr_1", errorBody, Arrays.asList("invalid_event_id"))); + } + else { + throw new CustomException(new ErrorObject("l_ca_dat_dsat_pr_2", "something_went_wrong", errorBody)); + } + } + } + +} diff --git a/src/main/java/com/salessparrow/api/lib/globalConstants/SalesforceConstants.java b/src/main/java/com/salessparrow/api/lib/globalConstants/SalesforceConstants.java index f0a8086b..ac31a0da 100644 --- a/src/main/java/com/salessparrow/api/lib/globalConstants/SalesforceConstants.java +++ b/src/main/java/com/salessparrow/api/lib/globalConstants/SalesforceConstants.java @@ -82,4 +82,8 @@ public String salesforceDeleteAccountTaskUrl(String taskId) { return sObjectsPath() + "/Task/" + taskId; } + public String salesforceDeleteAccountEventUrl(String eventId) { + return sObjectsPath() + "/Event/" + eventId; + } + } diff --git a/src/main/java/com/salessparrow/api/services/accountEvents/DeleteEventService.java b/src/main/java/com/salessparrow/api/services/accountEvents/DeleteEventService.java new file mode 100644 index 00000000..b4252ef4 --- /dev/null +++ b/src/main/java/com/salessparrow/api/services/accountEvents/DeleteEventService.java @@ -0,0 +1,40 @@ +package com.salessparrow.api.services.accountEvents; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import com.salessparrow.api.domain.User; +import com.salessparrow.api.lib.crmActions.deleteAccountEvent.DeleteAccountEventFactory; + +import jakarta.servlet.http.HttpServletRequest; + +/** + * DeleteEventService is a service class that handles the deleting of an event in an + * account. + */ +@Service +public class DeleteEventService { + + Logger logger = LoggerFactory.getLogger(DeleteEventService.class); + + @Autowired + private DeleteAccountEventFactory deleteAccountEventFactory; + + /** + * Deletes an event in an account. + * @param request + * @param accountId + * @param eventId + * @return void + */ + public void deleteAccountEvent(HttpServletRequest request, String accountId, String eventId) { + logger.info("Delete event in account service called"); + + User currentUser = (User) request.getAttribute("current_user"); + + deleteAccountEventFactory.deleteAccountEvent(currentUser, accountId, eventId); + } + +} diff --git a/src/main/resources/config/ParamErrorConfig.json b/src/main/resources/config/ParamErrorConfig.json index 69e181db..72d0ff7b 100644 --- a/src/main/resources/config/ParamErrorConfig.json +++ b/src/main/resources/config/ParamErrorConfig.json @@ -49,6 +49,11 @@ "param_error_identifier": "invalid_note_id", "message": "The note id you sent is incorrect. Please double check and try again." }, + "invalid_event_id":{ + "parameter": "event_id", + "param_error_identifier": "invalid_event_id", + "message": "Invalid event ID. Please double check and try again." + }, "text_too_long": { "parameter": "text", "param_error_identifier": "text_too_long", From 4ae9de9471a9d913240014abdbc1268777bd105e Mon Sep 17 00:00:00 2001 From: Raj Shah Date: Mon, 18 Sep 2023 10:42:16 +0530 Subject: [PATCH 09/36] Added delete account event test --- .../DeleteSalesforceAccountEvent.java | 4 +- .../DeleteSalesforceAccountTask.java | 4 +- .../DeleteAccountEventTest.java | 139 ++++++++++++++++++ .../deleteAccountEvent.scenarios.json | 55 +++++++ .../deleteAccountTask.scenarios.json | 2 +- .../deleteAccountEvent.fixtures.json | 14 ++ 6 files changed, 213 insertions(+), 5 deletions(-) create mode 100644 src/test/java/com/salessparrow/api/functional/controllers/accountEventController/DeleteAccountEventTest.java create mode 100644 src/test/resources/data/functional/controllers/accountEventController/deleteAccountEvent.scenarios.json create mode 100644 src/test/resources/fixtures/functional/controllers/accountEventController/deleteAccountEvent.fixtures.json diff --git a/src/main/java/com/salessparrow/api/lib/crmActions/deleteAccountEvent/DeleteSalesforceAccountEvent.java b/src/main/java/com/salessparrow/api/lib/crmActions/deleteAccountEvent/DeleteSalesforceAccountEvent.java index 4805cb8c..3d4e7aa0 100644 --- a/src/main/java/com/salessparrow/api/lib/crmActions/deleteAccountEvent/DeleteSalesforceAccountEvent.java +++ b/src/main/java/com/salessparrow/api/lib/crmActions/deleteAccountEvent/DeleteSalesforceAccountEvent.java @@ -81,10 +81,10 @@ private void parseResponse(String responseBody) { if (deleteEventStatusCode == 400 || deleteEventStatusCode == 404) { throw new CustomException( - new ParamErrorObject("l_ca_dat_dsat_pr_1", errorBody, Arrays.asList("invalid_event_id"))); + new ParamErrorObject("l_ca_dae_dsae_pr_1", errorBody, Arrays.asList("invalid_event_id"))); } else { - throw new CustomException(new ErrorObject("l_ca_dat_dsat_pr_2", "something_went_wrong", errorBody)); + throw new CustomException(new ErrorObject("l_ca_dae_dsae_pr_2", "something_went_wrong", errorBody)); } } } diff --git a/src/main/java/com/salessparrow/api/lib/crmActions/deleteAccountTask/DeleteSalesforceAccountTask.java b/src/main/java/com/salessparrow/api/lib/crmActions/deleteAccountTask/DeleteSalesforceAccountTask.java index e5144cfc..d1305f19 100644 --- a/src/main/java/com/salessparrow/api/lib/crmActions/deleteAccountTask/DeleteSalesforceAccountTask.java +++ b/src/main/java/com/salessparrow/api/lib/crmActions/deleteAccountTask/DeleteSalesforceAccountTask.java @@ -81,10 +81,10 @@ private void parseResponse(String responseBody) { if (deleteTaskStatusCode == 400 || deleteTaskStatusCode == 404) { throw new CustomException( - new ParamErrorObject("l_ca_dan_dasn_pr_1", errorBody, Arrays.asList("invalid_task_id"))); + new ParamErrorObject("l_ca_dat_dsat_pr_1", errorBody, Arrays.asList("invalid_task_id"))); } else { - throw new CustomException(new ErrorObject("l_ca_dan_dasn_pr_2", "something_went_wrong", errorBody)); + throw new CustomException(new ErrorObject("l_ca_dat_dsat_pr_2", "something_went_wrong", errorBody)); } } } diff --git a/src/test/java/com/salessparrow/api/functional/controllers/accountEventController/DeleteAccountEventTest.java b/src/test/java/com/salessparrow/api/functional/controllers/accountEventController/DeleteAccountEventTest.java new file mode 100644 index 00000000..e82783d4 --- /dev/null +++ b/src/test/java/com/salessparrow/api/functional/controllers/accountEventController/DeleteAccountEventTest.java @@ -0,0 +1,139 @@ +package com.salessparrow.api.functional.controllers.accountEventController; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.when; + +import java.io.IOException; +import java.util.List; +import java.util.stream.Stream; + +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.mock.mockito.MockBean; +import org.springframework.context.annotation.Import; +import org.springframework.core.io.DefaultResourceLoader; +import org.springframework.core.io.Resource; +import org.springframework.http.MediaType; +import org.springframework.test.context.web.WebAppConfiguration; +import org.springframework.test.web.servlet.MockMvc; +import org.springframework.test.web.servlet.ResultActions; +import org.springframework.test.web.servlet.request.MockMvcRequestBuilders; + +import com.fasterxml.jackson.core.type.TypeReference; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.github.dynamobee.exception.DynamobeeException; +import com.salessparrow.api.helper.Cleanup; +import com.salessparrow.api.helper.Common; +import com.salessparrow.api.helper.Constants; +import com.salessparrow.api.helper.FixtureData; +import com.salessparrow.api.helper.LoadFixture; +import com.salessparrow.api.helper.Scenario; +import com.salessparrow.api.helper.Setup; +import com.salessparrow.api.lib.globalConstants.CookieConstants; +import com.salessparrow.api.lib.httpLib.HttpClient.HttpResponse; +import com.salessparrow.api.lib.salesforce.helper.MakeCompositeRequest; + +import jakarta.servlet.http.Cookie; + +@SpringBootTest +@AutoConfigureMockMvc +@WebAppConfiguration +@Import({ Setup.class, Cleanup.class, Common.class, LoadFixture.class }) +public class DeleteAccountEventTest { + + @Autowired + private MockMvc mockMvc; + + @Autowired + private Common common; + + @Autowired + private LoadFixture loadFixture; + + @Autowired + private Setup setup; + + @Autowired + private Cleanup cleanup; + + @MockBean + private MakeCompositeRequest makeCompositeRequestMock; + + @BeforeEach + public void setUp() throws DynamobeeException { + setup.perform(); + } + + @AfterEach + public void tearDown() { + cleanup.perform(); + } + + @ParameterizedTest + @MethodSource("testScenariosProvider") + public void deleteAccountEvent(Scenario testScenario) throws Exception { + + // Load fixture data + String currentFunctionName = new Object() { + }.getClass().getEnclosingMethod().getName(); + FixtureData fixtureData = common.loadFixture( + "classpath:fixtures/functional/controllers/accountEventController/deleteAccountEvent.fixtures.json", + currentFunctionName); + loadFixture.perform(fixtureData); + + // Read data from the scenario + ObjectMapper objectMapper = new ObjectMapper(); + String cookieValue = Constants.SALESFORCE_ACTIVE_USER_COOKIE_VALUE; + String accountId = (String) testScenario.getInput().get("accountId"); + String eventId = (String) testScenario.getInput().get("eventId"); + + // Prepare mock responses + HttpResponse createNoteMockResponse = new HttpResponse(); + createNoteMockResponse + .setResponseBody(objectMapper.writeValueAsString(testScenario.getMocks().get("makeCompositeRequest"))); + when(makeCompositeRequestMock.makePostRequest(any(), any())).thenReturn(createNoteMockResponse); + + // Perform the request + String requestBody = objectMapper.writeValueAsString(testScenario.getInput().get("body")); + String url = "/api/v1/accounts/" + accountId + "/events/" + eventId; + + ResultActions resultActions = mockMvc.perform(MockMvcRequestBuilders.delete(url) + .cookie(new Cookie(CookieConstants.USER_LOGIN_COOKIE_NAME, cookieValue)) + .content(requestBody) + .contentType(MediaType.APPLICATION_JSON)); + + // Check the response + String expectedOutput = objectMapper.writeValueAsString(testScenario.getOutput()); + String actualOutput = resultActions.andReturn().getResponse().getContentAsString(); + + if (resultActions.andReturn().getResponse().getStatus() == 204) { + if (expectedOutput.equals("{}")) { + expectedOutput = ""; + } + assertEquals(expectedOutput, actualOutput); + } + else { + common.compareErrors(testScenario, actualOutput); + } + } + + static Stream testScenariosProvider() throws IOException { + List testScenarios = loadScenarios(); + return testScenarios.stream(); + } + + private static List loadScenarios() throws IOException { + String scenariosPath = "classpath:data/functional/controllers/accountEventController/deleteAccountEvent.scenarios.json"; + Resource resource = new DefaultResourceLoader().getResource(scenariosPath); + ObjectMapper objectMapper = new ObjectMapper(); + return objectMapper.readValue(resource.getInputStream(), new TypeReference>() { + }); + } + +} diff --git a/src/test/resources/data/functional/controllers/accountEventController/deleteAccountEvent.scenarios.json b/src/test/resources/data/functional/controllers/accountEventController/deleteAccountEvent.scenarios.json new file mode 100644 index 00000000..6dc71950 --- /dev/null +++ b/src/test/resources/data/functional/controllers/accountEventController/deleteAccountEvent.scenarios.json @@ -0,0 +1,55 @@ +[ + { + "description": "Should successfully delete the event for given event id", + "input": { + "accountId": "0011e00000bWSxdAAG", + "eventId":"0691e000001X1yTAAS" + }, + "mocks": { + "makeCompositeRequest": { + "compositeResponse": [ + { + "body": null, + "httpHeaders": {}, + "httpStatusCode": 204, + "referenceId": "DeleteEvent" + } + ] + } + }, + "output": {} + }, + { + "description": "should return error response when event id is invalid", + "input": { + "accountId": "0011e00000bWSxdAAG", + "eventId":"invalidEventId" + }, + "mocks": { + "makeCompositeRequest": { + "compositeResponse": [ + { + "body": [ + { + "errorCode": "NOT_FOUND", + "message": "Provided external ID field does not exist or is not accessible: INVALID_EVENT_ID" + } + ], + "httpHeaders": {}, + "httpStatusCode": 404, + "referenceId": "DeleteEvent" + } + ] + } + }, + "output": { + "http_code": 400, + "message": "At least one parameter is invalid or missing.", + "code": "INVALID_PARAMS", + "internal_error_identifier": "l_ca_dae_dsae_pr_1", + "param_errors": [ + "invalid_event_id" + ] + } + } + ] \ No newline at end of file diff --git a/src/test/resources/data/functional/controllers/accountTaskController/deleteAccountTask.scenarios.json b/src/test/resources/data/functional/controllers/accountTaskController/deleteAccountTask.scenarios.json index 33f9fbac..b03d0d0c 100644 --- a/src/test/resources/data/functional/controllers/accountTaskController/deleteAccountTask.scenarios.json +++ b/src/test/resources/data/functional/controllers/accountTaskController/deleteAccountTask.scenarios.json @@ -46,7 +46,7 @@ "http_code": 400, "message": "At least one parameter is invalid or missing.", "code": "INVALID_PARAMS", - "internal_error_identifier": "l_ca_dan_dasn_pr_1", + "internal_error_identifier": "l_ca_dat_dsat_pr_1", "param_errors": [ "invalid_task_id" ] diff --git a/src/test/resources/fixtures/functional/controllers/accountEventController/deleteAccountEvent.fixtures.json b/src/test/resources/fixtures/functional/controllers/accountEventController/deleteAccountEvent.fixtures.json new file mode 100644 index 00000000..51619d2e --- /dev/null +++ b/src/test/resources/fixtures/functional/controllers/accountEventController/deleteAccountEvent.fixtures.json @@ -0,0 +1,14 @@ +{ + "deleteAccountEvent": { + "salesforce_users": [ + { + "filepath": "classpath:fixtures/common/repositories/salesforceUser/ActiveSalesforceUser.json" + } + ], + "salesforce_oauth_tokens": [ + { + "filepath": "classpath:fixtures/common/repositories/salesforceOauthToken/ActiveSalesforceOauthToken.json" + } + ] + } + } \ No newline at end of file From e0b2112c9168865b0fed45100278e22c350305cb Mon Sep 17 00:00:00 2001 From: Raj Shah Date: Mon, 25 Sep 2023 14:03:49 +0530 Subject: [PATCH 10/36] Added changes for event suggestion --- .../entities/AddEventSuggestionEntityDto.java | 21 +++++++++ .../CrmActionSuggestionsFormatterDto.java | 3 ++ .../api/lib/GetCrmActionSuggestions.java | 46 +++++++++++++++++-- .../api/lib/openAi/OpenAiPayloadBuilder.java | 33 +++++++++---- .../validators/DatetimeFormatValidator.java | 15 +++++- .../salessparrow/api/helper/Constants.java | 2 +- .../authController/Logout.scenarios.json | 2 +- .../crmActionsSuggestions.scenarios.json | 33 ++++++++----- .../getCurrentUser.scenarios.json | 2 +- 9 files changed, 125 insertions(+), 32 deletions(-) create mode 100644 src/main/java/com/salessparrow/api/dto/entities/AddEventSuggestionEntityDto.java diff --git a/src/main/java/com/salessparrow/api/dto/entities/AddEventSuggestionEntityDto.java b/src/main/java/com/salessparrow/api/dto/entities/AddEventSuggestionEntityDto.java new file mode 100644 index 00000000..3886fa16 --- /dev/null +++ b/src/main/java/com/salessparrow/api/dto/entities/AddEventSuggestionEntityDto.java @@ -0,0 +1,21 @@ +package com.salessparrow.api.dto.entities; + +import com.fasterxml.jackson.databind.PropertyNamingStrategies; +import com.fasterxml.jackson.databind.annotation.JsonNaming; + +import lombok.Data; + +/** + * Add Event Suggestion Entity is a DTO class for the Add Event Suggestion Entity. + */ +@Data +@JsonNaming(PropertyNamingStrategies.SnakeCaseStrategy.class) +public class AddEventSuggestionEntityDto { + + private String description; + + private String startDatetime; + + private String endDatetime; + +} diff --git a/src/main/java/com/salessparrow/api/dto/formatter/CrmActionSuggestionsFormatterDto.java b/src/main/java/com/salessparrow/api/dto/formatter/CrmActionSuggestionsFormatterDto.java index 36d39ad7..0057ac18 100644 --- a/src/main/java/com/salessparrow/api/dto/formatter/CrmActionSuggestionsFormatterDto.java +++ b/src/main/java/com/salessparrow/api/dto/formatter/CrmActionSuggestionsFormatterDto.java @@ -4,6 +4,7 @@ import com.fasterxml.jackson.databind.PropertyNamingStrategies; import com.fasterxml.jackson.databind.annotation.JsonNaming; +import com.salessparrow.api.dto.entities.AddEventSuggestionEntityDto; import com.salessparrow.api.dto.entities.AddTaskSuggestionEntityDto; import lombok.Data; @@ -18,4 +19,6 @@ public class CrmActionSuggestionsFormatterDto { private List addTaskSuggestions; + private List addEventSuggestions; + } diff --git a/src/main/java/com/salessparrow/api/lib/GetCrmActionSuggestions.java b/src/main/java/com/salessparrow/api/lib/GetCrmActionSuggestions.java index b39ad738..7d87c30f 100644 --- a/src/main/java/com/salessparrow/api/lib/GetCrmActionSuggestions.java +++ b/src/main/java/com/salessparrow/api/lib/GetCrmActionSuggestions.java @@ -13,6 +13,7 @@ import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; import com.salessparrow.api.controllers.SuggestionsController; +import com.salessparrow.api.dto.entities.AddEventSuggestionEntityDto; import com.salessparrow.api.dto.entities.AddTaskSuggestionEntityDto; import com.salessparrow.api.dto.formatter.CrmActionSuggestionsFormatterDto; import com.salessparrow.api.exception.CustomException; @@ -20,6 +21,7 @@ import com.salessparrow.api.lib.openAi.OpenAiPayloadBuilder; import com.salessparrow.api.lib.openAi.OpenAiRequest; import com.salessparrow.api.lib.validators.DateFormatValidator; +import com.salessparrow.api.lib.validators.DatetimeFormatValidator; /** * GetCrmActionSuggestions is a class for getting the crm action suggestions. @@ -35,6 +37,8 @@ public class GetCrmActionSuggestions { private DateFormatValidator dateFormatValidator = new DateFormatValidator(); + private DatetimeFormatValidator datetimeFormatValidator = new DatetimeFormatValidator(); + private Logger logger = org.slf4j.LoggerFactory.getLogger(SuggestionsController.class); /** @@ -69,6 +73,7 @@ private CrmActionSuggestionsFormatterDto parseResponse(String responseBody) { JsonNode functionNode = rootNode.get("choices").get(0).get("message").get("function_call"); List formattedTaskSuggestionEntityDtos = new ArrayList<>(); + List formattedEventSuggestionEntityDtos = new ArrayList<>(); if (functionNode != null) { @@ -78,13 +83,23 @@ private CrmActionSuggestionsFormatterDto parseResponse(String responseBody) { objectMapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES); String argumentsJson = objectMapper.convertValue(argumentsNode, String.class); - Map> arguments = objectMapper.readValue(argumentsJson, - new TypeReference>>() { + Map> arguments = objectMapper.readValue(argumentsJson, + new TypeReference>>() { + }); + + List addTaskList = arguments.get("add_task"); + List addEventList = arguments.get("add_event"); + + List typedAddTaskList = objectMapper.convertValue(addTaskList, + new TypeReference>() { }); - List addTaskList = arguments.get("add_task"); - if (addTaskList != null) { - for (AddTaskSuggestionEntityDto addTask : addTaskList) { + List typedAddEventList = objectMapper.convertValue(addEventList, + new TypeReference>() { + }); + + if (typedAddTaskList != null) { + for (AddTaskSuggestionEntityDto addTask : typedAddTaskList) { AddTaskSuggestionEntityDto addTaskSuggestionEntityDto = new AddTaskSuggestionEntityDto(); addTaskSuggestionEntityDto.setDescription(addTask.getDescription()); @@ -98,9 +113,30 @@ private CrmActionSuggestionsFormatterDto parseResponse(String responseBody) { formattedTaskSuggestionEntityDtos.add(addTaskSuggestionEntityDto); } } + + if (typedAddEventList != null) { + for (AddEventSuggestionEntityDto addEvent : typedAddEventList) { + AddEventSuggestionEntityDto addEventSuggestionEntityDto = new AddEventSuggestionEntityDto(); + addEventSuggestionEntityDto.setDescription(addEvent.getDescription()); + + // Format the response check if datetime format is + // yyyy-MM-dd'T'HH:mm:ss.SSSZ else + // remove datetime + if (datetimeFormatValidator.isValid(addEvent.getStartDatetime(), null)) { + addEventSuggestionEntityDto.setStartDatetime(addEvent.getStartDatetime()); + } + + if (datetimeFormatValidator.isValid(addEvent.getEndDatetime(), null)) { + addEventSuggestionEntityDto.setEndDatetime(addEvent.getEndDatetime()); + } + + formattedEventSuggestionEntityDtos.add(addEventSuggestionEntityDto); + } + } } crmActionSuggestionsFormatterDto.setAddTaskSuggestions(formattedTaskSuggestionEntityDtos); + crmActionSuggestionsFormatterDto.setAddEventSuggestions(formattedEventSuggestionEntityDtos); return crmActionSuggestionsFormatterDto; } catch (Exception e) { diff --git a/src/main/java/com/salessparrow/api/lib/openAi/OpenAiPayloadBuilder.java b/src/main/java/com/salessparrow/api/lib/openAi/OpenAiPayloadBuilder.java index 4603d099..c2ffdd1a 100644 --- a/src/main/java/com/salessparrow/api/lib/openAi/OpenAiPayloadBuilder.java +++ b/src/main/java/com/salessparrow/api/lib/openAi/OpenAiPayloadBuilder.java @@ -17,29 +17,42 @@ public class OpenAiPayloadBuilder { * @return */ public String payloadForCrmActionsSuggestions(String text) { - String todayDate = getTodaysDate(); - return "{\n" + " \"model\": \"gpt-3.5-turbo-0613\",\n" + " \"messages\": [\n" + " {\n" + String payload = "{\n" + " \"model\": \"gpt-3.5-turbo-0613\",\n" + " \"messages\": [\n" + " {\n" + " \"role\": \"system\",\n" - + " \"content\": \"You are an AI assistant that provides suggestions for creating tasks in CRM based solely on the content of the input message. The content of task if any found should only be from input message. If no task suggestions are found in the input message, return empty data. If task suggestions are found, they should include description and due date. Due Date format should be YYYY-MM-DD. Today's date is " + + " \"content\": \"You are an AI assistant that provides suggestions for creating tasks and events in CRM based solely on the content of the input message. The content of the task or event, if any found, should only be from the input message. If no task or event suggestions are found in the input message, return empty data. Suggestions can either be both task and event list or only tasks or only events or empty. If task suggestions are found, they should include description and due date. Due Date format should be YYYY-MM-DD. If event suggestions are found, they should include description and start datetime and end datetime. If end datetime not provided it should be start datetime + 1 hour. Start datetime and end datetime format is yyyy-MM-dd'T'HH:mm:ss.SSS+0000. Today's date is " + todayDate - + ". Use the functions provided to determine task suggestions. If no tasks are possible for the given input message, return an empty response. For example, If Input Message: Had a call with product team. They need a pitch desk by tomorrow. Then it should return description: Create pitch deck. For 2nd Example, If Input Message: 3 tasks. Then it should return empty response as no tasks can be suggested from input message\"\n" + + ". Use the functions provided to determine events and tasks suggestions. If no tasks or events are possible for the given input message, return an empty response. Example 1: Input Message: Had a call with the product team. They need a pitch deck by tomorrow. A meeting is gonna be held in 5 days to discuss the product. Output for Task: Description: Create pitch deck. Output for Event: Description: Meeting with product team to discuss the product. Example 2: Input Message: 3 tasks. Then it should return an empty response as no tasks and no events can be suggested from the input message.\"\n" + " },\n" + " {\n" + " \"role\": \"user\",\n" + " \"content\": \" Input message: \\n" + text + "\\n\"\n" + " }\n" + " ],\n" + " \"functions\": [\n" + " {\n" + " \"name\": \"suggest_actions\",\n" - + " \"description\": \"This is function for suggesting actions in crm(example salesforce, freshsales) based on input message.\",\n" + + " \"description\": \"This is a function for suggesting actions in CRM (example Salesforce, Freshsales) based on the input message.\",\n" + " \"parameters\": {\n" + " \"type\": \"object\",\n" + " \"properties\": {\n" + " \"add_task\": {\n" + " \"name\": \"add_task\",\n" - + " \"description\": \"Tasks using input message. The task should be created only from the input message and if no task can be generated from input message then empty data should be returned.\",\n" + + " \"description\": \"Tasks using the input message. The task should be created only from the input message, and if no task can be generated from the input message, then empty data should be returned.\",\n" + " \"type\": \"array\",\n" + " \"items\": {\n" - + " \"type\": \"object\",\n" + " \"properties\": {\n" + + " \"type\": \"object\",\n" + " \"properties\": {\n" + " \"description\": {\n" + " \"type\": \"string\",\n" - + " \"description\": \"Description for task to add.\"\n" + " },\n" + + " \"description\": \"Description for the task to add.\"\n" + " },\n" + " \"due_date\": {\n" + " \"type\": \"string\",\n" - + " \"description\": \"Due date for task in YYYY-MM-DD format. Today's date is " + + " \"description\": \"Due date for the task in YYYY-MM-DD format. Today's date is " + todayDate + ".\"\n" + " }\n" + " }\n" + " }\n" - + " }\n" + " }\n" + " }\n" + " }\n" + " ]\n" + "}"; + + " },\n" + " \"add_event\": {\n" + " \"name\": \"add_event\",\n" + + " \"description\": \"Events using the input message. The event should be created only from the input message, and if no event can be generated from the input message, then empty data should be returned.\",\n" + + " \"type\": \"array\",\n" + " \"items\": {\n" + + " \"type\": \"object\",\n" + " \"properties\": {\n" + + " \"description\": {\n" + " \"type\": \"string\",\n" + + " \"description\": \"Description for the event to add.\"\n" + " },\n" + + " \"start_datetime\": {\n" + " \"type\": \"string\",\n" + + " \"description\": \"Start Datetime for the event in yyyy-MM-dd'T'HH:mm:ss.SSS+0000 format.\"\n" + + " },\n" + " \"start_datetime\": {\n" + + " \"type\": \"string\",\n" + + " \"description\": \"End Datetime for the event in yyyy-MM-dd'T'HH:mm:ss.SSS+0000 format.\"\n" + + " }\n" + " }\n" + " }\n" + " }\n" + " }\n" + + " }\n" + " }\n" + " ]\n" + "}"; + + return payload; } /** diff --git a/src/main/java/com/salessparrow/api/lib/validators/DatetimeFormatValidator.java b/src/main/java/com/salessparrow/api/lib/validators/DatetimeFormatValidator.java index ab51b193..d843e3c3 100644 --- a/src/main/java/com/salessparrow/api/lib/validators/DatetimeFormatValidator.java +++ b/src/main/java/com/salessparrow/api/lib/validators/DatetimeFormatValidator.java @@ -31,9 +31,20 @@ public boolean isValid(String value, ConstraintValidatorContext context) { sdf.setLenient(false); try { + // Attempt to parse the input date string Date parsedDate = sdf.parse(value); - String dateString = sdf.format(parsedDate); - return dateString.equals(value.toString()); + + // Check if the parsed date is not null + if (parsedDate != null) { + // Format the parsed date back into a string + String formattedDate = sdf.format(parsedDate); + + // Compare the formatted date with the input value + return formattedDate.equals(value); + } + else { + return false; + } } catch (Exception ex) { return false; diff --git a/src/test/java/com/salessparrow/api/helper/Constants.java b/src/test/java/com/salessparrow/api/helper/Constants.java index 0ad4b468..5e0cc281 100644 --- a/src/test/java/com/salessparrow/api/helper/Constants.java +++ b/src/test/java/com/salessparrow/api/helper/Constants.java @@ -5,6 +5,6 @@ */ public class Constants { - public static final String SALESFORCE_ACTIVE_USER_COOKIE_VALUE = "1:0055i00000AUxQHAA1:SALESFORCE:app:1692878227:a2xOxjcPChK/YsKCWRuY50J3gH21/tqcGlv7sWU/aPw3/UFVFPbvWn2LLzY5B5kVPXjj1gELRqa4B4ds6uuqIw=="; + public static final String SALESFORCE_ACTIVE_USER_COOKIE_VALUE = "1:0055i00000AUxQHAA1:SALESFORCE:app:1702978227:3sYUB9JUTxtN1ETSlAMgTio66GodR6cGTb/gEcXWGzBcQ4D3YlaiFxq1xFv3Hnd8McSILBnVIcjI88HW+yL3Hw=="; } diff --git a/src/test/resources/data/functional/controllers/authController/Logout.scenarios.json b/src/test/resources/data/functional/controllers/authController/Logout.scenarios.json index 6b46c398..fda8d52b 100644 --- a/src/test/resources/data/functional/controllers/authController/Logout.scenarios.json +++ b/src/test/resources/data/functional/controllers/authController/Logout.scenarios.json @@ -3,7 +3,7 @@ { "description": "Should logout user if valid cookie", "input": { - "cookie": "1:0055i00000AUxQHAA1:SALESFORCE:app:1692878227:a2xOxjcPChK/YsKCWRuY50J3gH21/tqcGlv7sWU/aPw3/UFVFPbvWn2LLzY5B5kVPXjj1gELRqa4B4ds6uuqIw==" + "cookie": "1:0055i00000AUxQHAA1:SALESFORCE:app:1702978227:3sYUB9JUTxtN1ETSlAMgTio66GodR6cGTb/gEcXWGzBcQ4D3YlaiFxq1xFv3Hnd8McSILBnVIcjI88HW+yL3Hw==" } }, { diff --git a/src/test/resources/data/functional/controllers/suggestionsController/crmActionsSuggestions.scenarios.json b/src/test/resources/data/functional/controllers/suggestionsController/crmActionsSuggestions.scenarios.json index 740e1765..33056e3d 100644 --- a/src/test/resources/data/functional/controllers/suggestionsController/crmActionsSuggestions.scenarios.json +++ b/src/test/resources/data/functional/controllers/suggestionsController/crmActionsSuggestions.scenarios.json @@ -2,13 +2,13 @@ { "description": "Should return correct suggestions for a given text", "input": { - "text": "We reviewed the tasks that the team has completed since the last meeting and discussed additional projects.\n\nHere are the main topics we discussed:\n\nJoe updated us on the calendar for editorial, advertorial and social media content.\n" + "text": "Had a call with product team. They need a pitch desk by tomorrow and need to setup another call for next week." }, "mocks":{ "makeRequest":{ - "id": "chatcmpl-0000", + "id": "chatcmpl-82Yb6OZk8wrZ1W91BDwmSi1O2spzr", "object": "chat.completion", - "created": 1692945329, + "created": 1695620340, "model": "gpt-3.5-turbo-0613", "choices": [ { @@ -18,24 +18,31 @@ "content": null, "function_call": { "name": "suggest_actions", - "arguments": "{\n \"add_task\": [\n {\n \"description\": \"Review calendar for editorial, advertorial, and social media content\",\n \"due_date\": \"2023-08-30\"\n }\n ]\n}" + "arguments": "{\n \"add_task\": [\n {\n \"description\": \"Create pitch deck\",\n \"due_date\": \"2023-09-26\"\n }\n ],\n \"add_event\": [\n {\n \"description\": \"Call with product team\",\n \"start_datetime\": \"2023-10-02T00:00:00.000+0000\"\n,\n \"end_datetime\": \"2023-10-02T01:00:00.000+0000\"\n }\n ]\n}" } }, "finish_reason": "function_call" } ], "usage": { - "prompt_tokens": 168, - "completion_tokens": 52, - "total_tokens": 220 + "prompt_tokens": 485, + "completion_tokens": 89, + "total_tokens": 574 } } }, "output": { "add_task_suggestions": [ { - "description": "Review calendar for editorial, advertorial, and social media content", - "due_date": "2023-08-30" + "description": "Create pitch deck", + "due_date": "2023-09-26" + } + ], + "add_event_suggestions": [ + { + "description": "Call with product team", + "start_datetime": "2023-10-02T00:00:00.000+0000", + "end_datetime": "2023-10-02T01:00:00.000+0000" } ] } @@ -59,7 +66,7 @@ "content": null, "function_call": { "name": "suggest_actions", - "arguments": "{\n \"add_task\": []\n}" + "arguments": "{\n \"add_task\": []\n,\"add_event\": []\n}" } }, "finish_reason": "function_call" @@ -73,7 +80,8 @@ } }, "output": { - "add_task_suggestions": [] + "add_task_suggestions": [], + "add_event_suggestions": [] } }, { @@ -114,7 +122,8 @@ "description": "Review calendar for editorial, advertorial, and social media content", "due_date": null } - ] + ], + "add_event_suggestions": [] } }, { diff --git a/src/test/resources/data/functional/controllers/userController/getCurrentUser.scenarios.json b/src/test/resources/data/functional/controllers/userController/getCurrentUser.scenarios.json index 16920d99..0d94ae76 100644 --- a/src/test/resources/data/functional/controllers/userController/getCurrentUser.scenarios.json +++ b/src/test/resources/data/functional/controllers/userController/getCurrentUser.scenarios.json @@ -2,7 +2,7 @@ { "description": "Should return current user", "input": { - "cookie": "1:0055i00000AUxQHAA1:SALESFORCE:app:1692878227:a2xOxjcPChK/YsKCWRuY50J3gH21/tqcGlv7sWU/aPw3/UFVFPbvWn2LLzY5B5kVPXjj1gELRqa4B4ds6uuqIw==" + "cookie": "1:0055i00000AUxQHAA1:SALESFORCE:app:1702978227:3sYUB9JUTxtN1ETSlAMgTio66GodR6cGTb/gEcXWGzBcQ4D3YlaiFxq1xFv3Hnd8McSILBnVIcjI88HW+yL3Hw==" }, "output": { "current_user": { From 6c402e6adfcc76533df5bcd9f347053e4b4bf485 Mon Sep 17 00:00:00 2001 From: Raj Shah Date: Tue, 26 Sep 2023 16:28:46 +0530 Subject: [PATCH 11/36] Added update account event api --- .../controllers/AccountEventController.java | 20 +++- .../requestMapper/UpdateAccountEventDto.java | 28 ++++++ .../java/com/salessparrow/api/lib/Util.java | 14 +++ .../CreateAccountEventFactory.java | 5 +- .../CreateAccountEventInterface.java | 5 +- .../CreateSalesforceAccountEvent.java | 20 +--- .../UpdateAccountEventFactory.java | 43 +++++++++ .../UpdateAccountEventInterface.java | 16 ++++ .../UpdateSalesforceAccountEvent.java | 92 +++++++++++++++++++ .../globalConstants/SalesforceConstants.java | 8 ++ .../CreateAccountEventService.java | 4 +- ...ce.java => DeleteAccountEventService.java} | 8 +- .../UpdateAccountEventService.java | 42 +++++++++ 13 files changed, 274 insertions(+), 31 deletions(-) create mode 100644 src/main/java/com/salessparrow/api/dto/requestMapper/UpdateAccountEventDto.java create mode 100644 src/main/java/com/salessparrow/api/lib/crmActions/updateAccountEvent/UpdateAccountEventFactory.java create mode 100644 src/main/java/com/salessparrow/api/lib/crmActions/updateAccountEvent/UpdateAccountEventInterface.java create mode 100644 src/main/java/com/salessparrow/api/lib/crmActions/updateAccountEvent/UpdateSalesforceAccountEvent.java rename src/main/java/com/salessparrow/api/services/accountEvents/{DeleteEventService.java => DeleteAccountEventService.java} (80%) create mode 100644 src/main/java/com/salessparrow/api/services/accountEvents/UpdateAccountEventService.java diff --git a/src/main/java/com/salessparrow/api/controllers/AccountEventController.java b/src/main/java/com/salessparrow/api/controllers/AccountEventController.java index 1ff0e591..7a28d113 100644 --- a/src/main/java/com/salessparrow/api/controllers/AccountEventController.java +++ b/src/main/java/com/salessparrow/api/controllers/AccountEventController.java @@ -9,6 +9,7 @@ import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.PutMapping; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; @@ -16,9 +17,11 @@ import com.salessparrow.api.dto.formatter.CreateEventFormatterDto; import com.salessparrow.api.dto.formatter.GetEventsListFormatterDto; import com.salessparrow.api.dto.requestMapper.CreateAccountEventDto; +import com.salessparrow.api.dto.requestMapper.UpdateAccountEventDto; import com.salessparrow.api.services.accountEvents.CreateAccountEventService; -import com.salessparrow.api.services.accountEvents.DeleteEventService; +import com.salessparrow.api.services.accountEvents.DeleteAccountEventService; import com.salessparrow.api.services.accountEvents.GetAccountEventsListService; +import com.salessparrow.api.services.accountEvents.UpdateAccountEventService; import jakarta.servlet.http.HttpServletRequest; import jakarta.validation.Valid; @@ -37,7 +40,10 @@ public class AccountEventController { private GetAccountEventsListService getAccountEventsListService; @Autowired - private DeleteEventService deleteEventService; + private DeleteAccountEventService deleteEventService; + + @Autowired + private UpdateAccountEventService updateEventService; @PostMapping("") public ResponseEntity createEvent(HttpServletRequest request, @@ -70,4 +76,14 @@ public ResponseEntity deleteEvent(HttpServletRequest request, @PathVariabl return ResponseEntity.status(HttpStatus.NO_CONTENT).build(); } + @PutMapping("/{event_id}") + public ResponseEntity updateEvent(HttpServletRequest request, @PathVariable("account_id") String accountId, + @PathVariable("event_id") String eventId, @Valid @RequestBody UpdateAccountEventDto updateEventDto) { + logger.info("Update event request received"); + + updateEventService.updateAccountEvent(request, accountId, eventId, updateEventDto); + + return ResponseEntity.status(HttpStatus.OK).build(); + } + } diff --git a/src/main/java/com/salessparrow/api/dto/requestMapper/UpdateAccountEventDto.java b/src/main/java/com/salessparrow/api/dto/requestMapper/UpdateAccountEventDto.java new file mode 100644 index 00000000..80b3327b --- /dev/null +++ b/src/main/java/com/salessparrow/api/dto/requestMapper/UpdateAccountEventDto.java @@ -0,0 +1,28 @@ +package com.salessparrow.api.dto.requestMapper; + +import com.fasterxml.jackson.databind.PropertyNamingStrategies; +import com.fasterxml.jackson.databind.annotation.JsonNaming; +import com.salessparrow.api.lib.customAnnotations.ValidDatetimeFormat; + +import jakarta.validation.constraints.NotBlank; +import jakarta.validation.constraints.NotNull; +import jakarta.validation.constraints.Size; +import lombok.Data; + +@Data +@JsonNaming(PropertyNamingStrategies.SnakeCaseStrategy.class) +public class UpdateAccountEventDto { + + @NotBlank(message = "missing_description") + @Size(max = 32000, message = "description_too_long") + private String description; + + @NotNull(message = "missing_start_datetime") + @ValidDatetimeFormat(message = "invalid_start_datetime") + private String startDatetime; + + @NotNull(message = "missing_end_datetime") + @ValidDatetimeFormat(message = "invalid_end_datetime") + private String endDatetime; + +} diff --git a/src/main/java/com/salessparrow/api/lib/Util.java b/src/main/java/com/salessparrow/api/lib/Util.java index 2ca7e414..0b6f5ac4 100644 --- a/src/main/java/com/salessparrow/api/lib/Util.java +++ b/src/main/java/com/salessparrow/api/lib/Util.java @@ -181,4 +181,18 @@ public String replaceNewLineWithBreak(String input) { return input.replace("\n", "
"); } + /** + * Get a trimmed string of a given length. + * @param input + * @param length + * @return String + */ + public String getTrimmedString(String input, Integer length) { + if (input.length() < length) { + return input; + } + + return input.substring(0, length); + } + } diff --git a/src/main/java/com/salessparrow/api/lib/crmActions/createAccountEvent/CreateAccountEventFactory.java b/src/main/java/com/salessparrow/api/lib/crmActions/createAccountEvent/CreateAccountEventFactory.java index a578e100..434f8e29 100644 --- a/src/main/java/com/salessparrow/api/lib/crmActions/createAccountEvent/CreateAccountEventFactory.java +++ b/src/main/java/com/salessparrow/api/lib/crmActions/createAccountEvent/CreateAccountEventFactory.java @@ -4,7 +4,7 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; -import com.salessparrow.api.domain.SalesforceUser; +import com.salessparrow.api.domain.User; import com.salessparrow.api.dto.formatter.CreateEventFormatterDto; import com.salessparrow.api.dto.requestMapper.CreateAccountEventDto; import com.salessparrow.api.exception.CustomException; @@ -28,8 +28,7 @@ public class CreateAccountEventFactory { * @param accountId * @return CreateEventFormatterDto **/ - public CreateEventFormatterDto createEvent(SalesforceUser user, String accountId, - CreateAccountEventDto createEventDto) { + public CreateEventFormatterDto createEvent(User user, String accountId, CreateAccountEventDto createEventDto) { logger.info("Create Event Factory started"); switch (user.getUserKind()) { diff --git a/src/main/java/com/salessparrow/api/lib/crmActions/createAccountEvent/CreateAccountEventInterface.java b/src/main/java/com/salessparrow/api/lib/crmActions/createAccountEvent/CreateAccountEventInterface.java index 3d67ea1e..2acead11 100644 --- a/src/main/java/com/salessparrow/api/lib/crmActions/createAccountEvent/CreateAccountEventInterface.java +++ b/src/main/java/com/salessparrow/api/lib/crmActions/createAccountEvent/CreateAccountEventInterface.java @@ -2,7 +2,7 @@ import org.springframework.stereotype.Component; -import com.salessparrow.api.domain.SalesforceUser; +import com.salessparrow.api.domain.User; import com.salessparrow.api.dto.formatter.CreateEventFormatterDto; import com.salessparrow.api.dto.requestMapper.CreateAccountEventDto; @@ -12,7 +12,6 @@ @Component public interface CreateAccountEventInterface { - public CreateEventFormatterDto createEvent(SalesforceUser user, String accountId, - CreateAccountEventDto createEventDto); + public CreateEventFormatterDto createEvent(User user, String accountId, CreateAccountEventDto createEventDto); } diff --git a/src/main/java/com/salessparrow/api/lib/crmActions/createAccountEvent/CreateSalesforceAccountEvent.java b/src/main/java/com/salessparrow/api/lib/crmActions/createAccountEvent/CreateSalesforceAccountEvent.java index 4c2af835..8d2f00c3 100644 --- a/src/main/java/com/salessparrow/api/lib/crmActions/createAccountEvent/CreateSalesforceAccountEvent.java +++ b/src/main/java/com/salessparrow/api/lib/crmActions/createAccountEvent/CreateSalesforceAccountEvent.java @@ -12,7 +12,7 @@ import com.fasterxml.jackson.databind.DeserializationFeature; import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; -import com.salessparrow.api.domain.SalesforceUser; +import com.salessparrow.api.domain.User; import com.salessparrow.api.dto.formatter.CreateEventFormatterDto; import com.salessparrow.api.dto.requestMapper.CreateAccountEventDto; import com.salessparrow.api.exception.CustomException; @@ -46,15 +46,14 @@ public class CreateSalesforceAccountEvent implements CreateAccountEventInterface * @param createEventDto * @return CreateEventFormatterDto */ - public CreateEventFormatterDto createEvent(SalesforceUser user, String accountId, - CreateAccountEventDto createEventDto) { + public CreateEventFormatterDto createEvent(User user, String accountId, CreateAccountEventDto createEventDto) { logger.info("Create Salesforce Event started"); String salesforceUserId = user.getExternalUserId(); Util util = new Util(); String eventDescription = util.unEscapeSpecialCharactersForPlainText(createEventDto.getDescription()); - String eventSubject = getEventSubjectFromDescription(eventDescription); + String eventSubject = util.getTrimmedString(eventDescription, salesforceConstants.salesforceSubjectLength()); Map createEventBody = new HashMap(); createEventBody.put("Subject", eventSubject); @@ -107,17 +106,4 @@ private CreateEventFormatterDto parseResponse(String createEventResponse) { return createEventFormatterDto; } - /** - * Get the first 60 characters of the event description. - * @param createEventDto - * @return String - */ - private String getEventSubjectFromDescription(String eventDescription) { - if (eventDescription.length() < 60) { - return eventDescription; - } - - return eventDescription.substring(0, 60); - } - } diff --git a/src/main/java/com/salessparrow/api/lib/crmActions/updateAccountEvent/UpdateAccountEventFactory.java b/src/main/java/com/salessparrow/api/lib/crmActions/updateAccountEvent/UpdateAccountEventFactory.java new file mode 100644 index 00000000..ad9cb5ae --- /dev/null +++ b/src/main/java/com/salessparrow/api/lib/crmActions/updateAccountEvent/UpdateAccountEventFactory.java @@ -0,0 +1,43 @@ +package com.salessparrow.api.lib.crmActions.updateAccountEvent; + +import org.slf4j.Logger; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +import com.salessparrow.api.domain.User; +import com.salessparrow.api.dto.requestMapper.UpdateAccountEventDto; +import com.salessparrow.api.exception.CustomException; +import com.salessparrow.api.lib.errorLib.ErrorObject; +import com.salessparrow.api.lib.globalConstants.UserConstants; + +/** + * UpdateAccountEventFactory is a factory class for the update event action for the CRM. + */ +@Component +public class UpdateAccountEventFactory { + + private Logger logger = org.slf4j.LoggerFactory.getLogger(UpdateAccountEventFactory.class); + + @Autowired + private UpdateSalesforceAccountEvent updateSalesforceEvent; + + /** + * Update an event for a given account + * @param user + * @param accountId + * @return void + **/ + public void updateEvent(User user, String accountId, String eventId, UpdateAccountEventDto updateEventDto) { + logger.info("Update Event Factory started"); + + switch (user.getUserKind()) { + case UserConstants.SALESFORCE_USER_KIND: + updateSalesforceEvent.updateEvent(user, accountId, eventId, updateEventDto); + return; + default: + throw new CustomException( + new ErrorObject("l_ua_uae_uaef_uae_1", "something_went_wrong", "Invalid user kind.")); + } + } + +} diff --git a/src/main/java/com/salessparrow/api/lib/crmActions/updateAccountEvent/UpdateAccountEventInterface.java b/src/main/java/com/salessparrow/api/lib/crmActions/updateAccountEvent/UpdateAccountEventInterface.java new file mode 100644 index 00000000..1427bb66 --- /dev/null +++ b/src/main/java/com/salessparrow/api/lib/crmActions/updateAccountEvent/UpdateAccountEventInterface.java @@ -0,0 +1,16 @@ +package com.salessparrow.api.lib.crmActions.updateAccountEvent; + +import org.springframework.stereotype.Component; + +import com.salessparrow.api.domain.User; +import com.salessparrow.api.dto.requestMapper.UpdateAccountEventDto; + +/** + * UpdateAccountEventInterface is an interface for the update event action for the CRM. + */ +@Component +public interface UpdateAccountEventInterface { + + public void updateEvent(User user, String accountId, String eventId, UpdateAccountEventDto updateEventDto); + +} diff --git a/src/main/java/com/salessparrow/api/lib/crmActions/updateAccountEvent/UpdateSalesforceAccountEvent.java b/src/main/java/com/salessparrow/api/lib/crmActions/updateAccountEvent/UpdateSalesforceAccountEvent.java new file mode 100644 index 00000000..da260c96 --- /dev/null +++ b/src/main/java/com/salessparrow/api/lib/crmActions/updateAccountEvent/UpdateSalesforceAccountEvent.java @@ -0,0 +1,92 @@ +package com.salessparrow.api.lib.crmActions.updateAccountEvent; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.slf4j.Logger; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +import com.fasterxml.jackson.databind.JsonNode; +import com.salessparrow.api.domain.User; +import com.salessparrow.api.dto.requestMapper.UpdateAccountEventDto; +import com.salessparrow.api.exception.CustomException; +import com.salessparrow.api.lib.Util; +import com.salessparrow.api.lib.errorLib.ErrorObject; +import com.salessparrow.api.lib.globalConstants.SalesforceConstants; +import com.salessparrow.api.lib.httpLib.HttpClient; +import com.salessparrow.api.lib.salesforce.dto.CompositeRequestDto; +import com.salessparrow.api.lib.salesforce.helper.MakeCompositeRequest; + +/** + * UpdateSalesforceAccountEvent is a class that updates an event for an account in + * Salesforce. + */ +@Component +public class UpdateSalesforceAccountEvent implements UpdateAccountEventInterface { + + private Logger logger = org.slf4j.LoggerFactory.getLogger(UpdateSalesforceAccountEvent.class); + + @Autowired + private SalesforceConstants salesforceConstants; + + @Autowired + private MakeCompositeRequest makeCompositeRequest; + + /** + * Update an event for a given account. + * @param user + * @param accountId + * @param updateEventDto + * @return void + */ + public void updateEvent(User user, String accountId, String eventId, UpdateAccountEventDto updateEventDto) { + logger.info("Update Salesforce Event started"); + + String salesforceUserId = user.getExternalUserId(); + + Util util = new Util(); + String eventDescription = util.unEscapeSpecialCharactersForPlainText(updateEventDto.getDescription()); + String eventSubject = util.getTrimmedString(eventDescription, salesforceConstants.salesforceSubjectLength()); + + Map updateEventBody = new HashMap(); + updateEventBody.put("Subject", eventSubject); + updateEventBody.put("Description", eventDescription); + updateEventBody.put("StartDateTime", updateEventDto.getStartDatetime().toString()); + updateEventBody.put("EndDateTime", updateEventDto.getEndDatetime().toString()); + + CompositeRequestDto updateEventCompositeRequestDto = new CompositeRequestDto("PATCH", + salesforceConstants.salesforceUpdateEventUrl(eventId), "UpdateEvent", updateEventBody); + + List compositeRequests = new ArrayList(); + compositeRequests.add(updateEventCompositeRequestDto); + + HttpClient.HttpResponse response = makeCompositeRequest.makePostRequest(compositeRequests, salesforceUserId); + + parseResponse(response.getResponseBody()); + } + + /** + * Parse the response from Salesforce. + * @param updateEventResponse + * @return void + */ + private void parseResponse(String updateEventResponse) { + logger.info("Parsing the response from Salesforce"); + + Util util = new Util(); + JsonNode rootNode = util.getJsonNode(updateEventResponse); + + JsonNode updateEventCompositeResponse = rootNode.get("compositeResponse").get(0); + Integer updateEventStatusCode = updateEventCompositeResponse.get("httpStatusCode").asInt(); + + if (updateEventStatusCode != 200 && updateEventStatusCode != 201 && updateEventStatusCode != 204) { + String errorBody = updateEventCompositeResponse.get("body").asText(); + + throw new CustomException(new ErrorObject("l_ua_uae_usae_pr_1", "internal_server_error", errorBody)); + } + } + +} diff --git a/src/main/java/com/salessparrow/api/lib/globalConstants/SalesforceConstants.java b/src/main/java/com/salessparrow/api/lib/globalConstants/SalesforceConstants.java index ac31a0da..6c23ffb7 100644 --- a/src/main/java/com/salessparrow/api/lib/globalConstants/SalesforceConstants.java +++ b/src/main/java/com/salessparrow/api/lib/globalConstants/SalesforceConstants.java @@ -42,6 +42,10 @@ public String salesforceCreateEventUrl() { return sObjectsPath() + "/Event"; } + public String salesforceUpdateEventUrl(String eventId) { + return sObjectsPath() + "/Event/" + eventId; + } + public String salesforceDeleteNoteUrl(String noteId) { return sObjectsPath() + "/ContentNote/" + noteId; } @@ -70,6 +74,10 @@ public Integer timeoutMillis() { return 10000; } + public Integer salesforceSubjectLength() { + return 60; + } + public String salesforceNotesContentUrl(String urlPrefix, String noteId) { return urlPrefix + "/services/data/v58.0/sobjects/ContentNote/" + noteId + "/Content"; } diff --git a/src/main/java/com/salessparrow/api/services/accountEvents/CreateAccountEventService.java b/src/main/java/com/salessparrow/api/services/accountEvents/CreateAccountEventService.java index 09f6d23c..6ce0a0dd 100644 --- a/src/main/java/com/salessparrow/api/services/accountEvents/CreateAccountEventService.java +++ b/src/main/java/com/salessparrow/api/services/accountEvents/CreateAccountEventService.java @@ -4,7 +4,7 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; -import com.salessparrow.api.domain.SalesforceUser; +import com.salessparrow.api.domain.User; import com.salessparrow.api.dto.formatter.CreateEventFormatterDto; import com.salessparrow.api.dto.requestMapper.CreateAccountEventDto; import com.salessparrow.api.lib.crmActions.createAccountEvent.CreateAccountEventFactory; @@ -34,7 +34,7 @@ public CreateEventFormatterDto createEvent(HttpServletRequest request, String ac CreateAccountEventDto createEventDto) { logger.info("Create Account Event Service started"); - SalesforceUser currentUser = (SalesforceUser) request.getAttribute("current_user"); + User currentUser = (User) request.getAttribute("current_user"); return createAccountEventFactory.createEvent(currentUser, accountId, createEventDto); } diff --git a/src/main/java/com/salessparrow/api/services/accountEvents/DeleteEventService.java b/src/main/java/com/salessparrow/api/services/accountEvents/DeleteAccountEventService.java similarity index 80% rename from src/main/java/com/salessparrow/api/services/accountEvents/DeleteEventService.java rename to src/main/java/com/salessparrow/api/services/accountEvents/DeleteAccountEventService.java index b4252ef4..20ee67a6 100644 --- a/src/main/java/com/salessparrow/api/services/accountEvents/DeleteEventService.java +++ b/src/main/java/com/salessparrow/api/services/accountEvents/DeleteAccountEventService.java @@ -11,13 +11,13 @@ import jakarta.servlet.http.HttpServletRequest; /** - * DeleteEventService is a service class that handles the deleting of an event in an - * account. + * DeleteAccountEventService is a service class that handles the deleting of an event in + * an account. */ @Service -public class DeleteEventService { +public class DeleteAccountEventService { - Logger logger = LoggerFactory.getLogger(DeleteEventService.class); + Logger logger = LoggerFactory.getLogger(DeleteAccountEventService.class); @Autowired private DeleteAccountEventFactory deleteAccountEventFactory; diff --git a/src/main/java/com/salessparrow/api/services/accountEvents/UpdateAccountEventService.java b/src/main/java/com/salessparrow/api/services/accountEvents/UpdateAccountEventService.java new file mode 100644 index 00000000..85721a26 --- /dev/null +++ b/src/main/java/com/salessparrow/api/services/accountEvents/UpdateAccountEventService.java @@ -0,0 +1,42 @@ +package com.salessparrow.api.services.accountEvents; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import com.salessparrow.api.domain.User; +import com.salessparrow.api.dto.requestMapper.UpdateAccountEventDto; +import com.salessparrow.api.lib.crmActions.updateAccountEvent.UpdateAccountEventFactory; + +import jakarta.servlet.http.HttpServletRequest; + +/** + * UpdateAccountEventService is a service class that handles the update of an event in an + * account. + */ +@Service +public class UpdateAccountEventService { + + Logger logger = LoggerFactory.getLogger(UpdateAccountEventService.class); + + @Autowired + private UpdateAccountEventFactory updateAccountEventFactory; + + /** + * Updates an event in an account. + * @param request + * @param accountId + * @param eventId + * @return void + */ + public void updateAccountEvent(HttpServletRequest request, String accountId, String eventId, + UpdateAccountEventDto updateEventDto) { + logger.info("Update event in account service called"); + + User currentUser = (User) request.getAttribute("current_user"); + + updateAccountEventFactory.updateEvent(currentUser, accountId, eventId, updateEventDto); + } + +} From 107102ff1317a58f59eee6928b4728e944bc5883 Mon Sep 17 00:00:00 2001 From: Raj Shah Date: Tue, 26 Sep 2023 16:48:31 +0530 Subject: [PATCH 12/36] Added event id invalid check for update event --- .../UpdateSalesforceAccountEvent.java | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/salessparrow/api/lib/crmActions/updateAccountEvent/UpdateSalesforceAccountEvent.java b/src/main/java/com/salessparrow/api/lib/crmActions/updateAccountEvent/UpdateSalesforceAccountEvent.java index da260c96..82f68769 100644 --- a/src/main/java/com/salessparrow/api/lib/crmActions/updateAccountEvent/UpdateSalesforceAccountEvent.java +++ b/src/main/java/com/salessparrow/api/lib/crmActions/updateAccountEvent/UpdateSalesforceAccountEvent.java @@ -1,6 +1,7 @@ package com.salessparrow.api.lib.crmActions.updateAccountEvent; import java.util.ArrayList; +import java.util.Arrays; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -15,6 +16,7 @@ import com.salessparrow.api.exception.CustomException; import com.salessparrow.api.lib.Util; import com.salessparrow.api.lib.errorLib.ErrorObject; +import com.salessparrow.api.lib.errorLib.ParamErrorObject; import com.salessparrow.api.lib.globalConstants.SalesforceConstants; import com.salessparrow.api.lib.httpLib.HttpClient; import com.salessparrow.api.lib.salesforce.dto.CompositeRequestDto; @@ -85,7 +87,15 @@ private void parseResponse(String updateEventResponse) { if (updateEventStatusCode != 200 && updateEventStatusCode != 201 && updateEventStatusCode != 204) { String errorBody = updateEventCompositeResponse.get("body").asText(); - throw new CustomException(new ErrorObject("l_ua_uae_usae_pr_1", "internal_server_error", errorBody)); + // MALFORMED_ID or NOT_FOUND + if (updateEventStatusCode == 400 || updateEventStatusCode == 404) { + + throw new CustomException( + new ParamErrorObject("l_ua_uae_usae_pr_1", errorBody, Arrays.asList("invalid_event_id"))); + } + else { + throw new CustomException(new ErrorObject("l_ua_uae_usae_pr_2", "something_went_wrong", errorBody)); + } } } From 30fdd4e9b5f7afe815886038e237dcc33c986404 Mon Sep 17 00:00:00 2001 From: Raj Shah Date: Tue, 26 Sep 2023 18:08:59 +0530 Subject: [PATCH 13/36] Added update event test case --- .../DeleteAccountEventTest.java | 6 +- .../UpdateAccountEventTest.java | 139 ++++++++++++++++++ .../DeleteAccountNoteTest.java | 1 - .../updateAccountEvent.scenarios.json | 65 ++++++++ .../updateAccountEvent.fixtures.json | 14 ++ 5 files changed, 221 insertions(+), 4 deletions(-) create mode 100644 src/test/java/com/salessparrow/api/functional/controllers/accountEventController/UpdateAccountEventTest.java create mode 100644 src/test/resources/data/functional/controllers/accountEventController/updateAccountEvent.scenarios.json create mode 100644 src/test/resources/fixtures/functional/controllers/accountEventController/updateAccountEvent.fixtures.json diff --git a/src/test/java/com/salessparrow/api/functional/controllers/accountEventController/DeleteAccountEventTest.java b/src/test/java/com/salessparrow/api/functional/controllers/accountEventController/DeleteAccountEventTest.java index e82783d4..3bc8804e 100644 --- a/src/test/java/com/salessparrow/api/functional/controllers/accountEventController/DeleteAccountEventTest.java +++ b/src/test/java/com/salessparrow/api/functional/controllers/accountEventController/DeleteAccountEventTest.java @@ -94,10 +94,10 @@ public void deleteAccountEvent(Scenario testScenario) throws Exception { String eventId = (String) testScenario.getInput().get("eventId"); // Prepare mock responses - HttpResponse createNoteMockResponse = new HttpResponse(); - createNoteMockResponse + HttpResponse mockResponse = new HttpResponse(); + mockResponse .setResponseBody(objectMapper.writeValueAsString(testScenario.getMocks().get("makeCompositeRequest"))); - when(makeCompositeRequestMock.makePostRequest(any(), any())).thenReturn(createNoteMockResponse); + when(makeCompositeRequestMock.makePostRequest(any(), any())).thenReturn(mockResponse); // Perform the request String requestBody = objectMapper.writeValueAsString(testScenario.getInput().get("body")); diff --git a/src/test/java/com/salessparrow/api/functional/controllers/accountEventController/UpdateAccountEventTest.java b/src/test/java/com/salessparrow/api/functional/controllers/accountEventController/UpdateAccountEventTest.java new file mode 100644 index 00000000..1a1f035e --- /dev/null +++ b/src/test/java/com/salessparrow/api/functional/controllers/accountEventController/UpdateAccountEventTest.java @@ -0,0 +1,139 @@ +package com.salessparrow.api.functional.controllers.accountEventController; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.when; + +import java.io.IOException; +import java.util.List; +import java.util.stream.Stream; + +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.mock.mockito.MockBean; +import org.springframework.context.annotation.Import; +import org.springframework.core.io.DefaultResourceLoader; +import org.springframework.core.io.Resource; +import org.springframework.http.MediaType; +import org.springframework.test.context.web.WebAppConfiguration; +import org.springframework.test.web.servlet.MockMvc; +import org.springframework.test.web.servlet.ResultActions; +import org.springframework.test.web.servlet.request.MockMvcRequestBuilders; + +import com.fasterxml.jackson.core.type.TypeReference; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.github.dynamobee.exception.DynamobeeException; +import com.salessparrow.api.helper.Cleanup; +import com.salessparrow.api.helper.Common; +import com.salessparrow.api.helper.Constants; +import com.salessparrow.api.helper.FixtureData; +import com.salessparrow.api.helper.LoadFixture; +import com.salessparrow.api.helper.Scenario; +import com.salessparrow.api.helper.Setup; +import com.salessparrow.api.lib.globalConstants.CookieConstants; +import com.salessparrow.api.lib.httpLib.HttpClient.HttpResponse; +import com.salessparrow.api.lib.salesforce.helper.MakeCompositeRequest; + +import jakarta.servlet.http.Cookie; + +@SpringBootTest +@AutoConfigureMockMvc +@WebAppConfiguration +@Import({ Setup.class, Cleanup.class, Common.class, LoadFixture.class }) +public class UpdateAccountEventTest { + + @Autowired + private MockMvc mockMvc; + + @Autowired + private Common common; + + @Autowired + private LoadFixture loadFixture; + + @Autowired + private Setup setup; + + @Autowired + private Cleanup cleanup; + + @MockBean + private MakeCompositeRequest makeCompositeRequestMock; + + @BeforeEach + public void setUp() throws DynamobeeException { + setup.perform(); + } + + @AfterEach + public void tearDown() { + cleanup.perform(); + } + + @ParameterizedTest + @MethodSource("testScenariosProvider") + public void updateAccountEvent(Scenario testScenario) throws Exception { + + // Load fixture data + String currentFunctionName = new Object() { + }.getClass().getEnclosingMethod().getName(); + FixtureData fixtureData = common.loadFixture( + "classpath:fixtures/functional/controllers/accountEventController/updateAccountEvent.fixtures.json", + currentFunctionName); + loadFixture.perform(fixtureData); + + // Read data from the scenario + ObjectMapper objectMapper = new ObjectMapper(); + String cookieValue = Constants.SALESFORCE_ACTIVE_USER_COOKIE_VALUE; + String accountId = (String) testScenario.getInput().get("accountId"); + String eventId = (String) testScenario.getInput().get("eventId"); + + // Prepare mock responses + HttpResponse mockResponse = new HttpResponse(); + mockResponse + .setResponseBody(objectMapper.writeValueAsString(testScenario.getMocks().get("makeCompositeRequest"))); + when(makeCompositeRequestMock.makePostRequest(any(), any())).thenReturn(mockResponse); + + // Perform the request + String requestBody = objectMapper.writeValueAsString(testScenario.getInput().get("body")); + String url = "/api/v1/accounts/" + accountId + "/events/" + eventId; + + ResultActions resultActions = mockMvc.perform(MockMvcRequestBuilders.put(url) + .cookie(new Cookie(CookieConstants.USER_LOGIN_COOKIE_NAME, cookieValue)) + .content(requestBody) + .contentType(MediaType.APPLICATION_JSON)); + + // Check the response + String expectedOutput = objectMapper.writeValueAsString(testScenario.getOutput()); + String actualOutput = resultActions.andReturn().getResponse().getContentAsString(); + + if (resultActions.andReturn().getResponse().getStatus() == 200) { + if (expectedOutput.equals("{}")) { + expectedOutput = ""; + } + assertEquals(expectedOutput, actualOutput); + } + else { + common.compareErrors(testScenario, actualOutput); + } + } + + static Stream testScenariosProvider() throws IOException { + List testScenarios = loadScenarios(); + return testScenarios.stream(); + } + + private static List loadScenarios() throws IOException { + String scenariosPath = "classpath:data/functional/controllers/accountEventController/updateAccountEvent.scenarios.json"; + Resource resource = new DefaultResourceLoader().getResource(scenariosPath); + ObjectMapper objectMapper = new ObjectMapper(); + return objectMapper.readValue(resource.getInputStream(), new TypeReference>() { + }); + } + +} diff --git a/src/test/java/com/salessparrow/api/functional/controllers/accountNoteController/DeleteAccountNoteTest.java b/src/test/java/com/salessparrow/api/functional/controllers/accountNoteController/DeleteAccountNoteTest.java index 2c5d5cee..574fa4c7 100644 --- a/src/test/java/com/salessparrow/api/functional/controllers/accountNoteController/DeleteAccountNoteTest.java +++ b/src/test/java/com/salessparrow/api/functional/controllers/accountNoteController/DeleteAccountNoteTest.java @@ -1,6 +1,5 @@ package com.salessparrow.api.functional.controllers.accountNoteController; -import static org.junit.jupiter.api.Assertions.assertEquals; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.when; diff --git a/src/test/resources/data/functional/controllers/accountEventController/updateAccountEvent.scenarios.json b/src/test/resources/data/functional/controllers/accountEventController/updateAccountEvent.scenarios.json new file mode 100644 index 00000000..5e1d460e --- /dev/null +++ b/src/test/resources/data/functional/controllers/accountEventController/updateAccountEvent.scenarios.json @@ -0,0 +1,65 @@ +[ + { + "description": "Should successfully update the event for given event id", + "input": { + "body": { + "description":"Create Event", + "start_datetime": "2023-07-21T13:12:17.000+0000", + "end_datetime": "2023-07-22T13:12:17.000+0000" + }, + "accountId": "0011e00000bWSxdAAG", + "eventId":"0691e000001X1yTAAS" + }, + "mocks": { + "makeCompositeRequest": { + "compositeResponse": [ + { + "body": null, + "httpHeaders": {}, + "httpStatusCode": 200, + "referenceId": "UpdateEvent" + } + ] + } + }, + "output": {} + }, + { + "description": "should return error response when event id is invalid", + "input": { + "body": { + "description":"Create Event", + "start_datetime": "2023-07-21T13:12:17.000+0000", + "end_datetime": "2023-07-22T13:12:17.000+0000" + }, + "accountId": "0011e00000bWSxdAAG", + "eventId":"invalidEventId" + }, + "mocks": { + "makeCompositeRequest": { + "compositeResponse": [ + { + "body": [ + { + "errorCode": "NOT_FOUND", + "message": "Provided external ID field does not exist or is not accessible: INVALID_EVENT_ID" + } + ], + "httpHeaders": {}, + "httpStatusCode": 404, + "referenceId": "UpdateEvent" + } + ] + } + }, + "output": { + "http_code": 400, + "message": "At least one parameter is invalid or missing.", + "code": "INVALID_PARAMS", + "internal_error_identifier": "l_ua_uae_usae_pr_1", + "param_errors": [ + "invalid_event_id" + ] + } + } + ] \ No newline at end of file diff --git a/src/test/resources/fixtures/functional/controllers/accountEventController/updateAccountEvent.fixtures.json b/src/test/resources/fixtures/functional/controllers/accountEventController/updateAccountEvent.fixtures.json new file mode 100644 index 00000000..11986457 --- /dev/null +++ b/src/test/resources/fixtures/functional/controllers/accountEventController/updateAccountEvent.fixtures.json @@ -0,0 +1,14 @@ +{ + "updateAccountEvent": { + "salesforce_users": [ + { + "filepath": "classpath:fixtures/common/repositories/salesforceUser/ActiveSalesforceUser.json" + } + ], + "salesforce_oauth_tokens": [ + { + "filepath": "classpath:fixtures/common/repositories/salesforceOauthToken/ActiveSalesforceOauthToken.json" + } + ] + } +} \ No newline at end of file From 434b0459f8c82f1f5dbbf20fbdbd6dfb5dd2fece Mon Sep 17 00:00:00 2001 From: Raj Shah Date: Thu, 28 Sep 2023 12:31:07 +0530 Subject: [PATCH 14/36] Added get event details api and update task api --- .../controllers/AccountEventController.java | 16 ++ .../controllers/AccountTaskController.java | 16 ++ .../GetEventDetailsFormatterDto.java | 15 ++ .../requestMapper/UpdateAccountTaskDto.java | 25 ++++ .../GetAccountEventDetails.java | 16 ++ .../GetAccountEventDetailsFactory.java | 39 +++++ .../GetSalesforceAccountEventDetails.java | 111 ++++++++++++++ .../UpdateAccountTaskFactory.java | 43 ++++++ .../UpdateAccountTaskInterface.java | 16 ++ .../UpdateSalesforceAccountTask.java | 102 +++++++++++++ .../globalConstants/SalesforceConstants.java | 4 + .../helper/SalesforceQueryBuilder.java | 8 + .../GetAccountEventDetailsService.java | 34 +++++ .../accountTask/UpdateAccountTaskService.java | 42 ++++++ .../CreateAccountEventTest.java | 6 +- .../GetAccountEventDetailsTest.java | 137 ++++++++++++++++++ .../getAccountEventDetails.scenarios.json | 88 +++++++++++ .../getAccountEventDetails.fixtures.json | 14 ++ 18 files changed, 729 insertions(+), 3 deletions(-) create mode 100644 src/main/java/com/salessparrow/api/dto/formatter/GetEventDetailsFormatterDto.java create mode 100644 src/main/java/com/salessparrow/api/dto/requestMapper/UpdateAccountTaskDto.java create mode 100644 src/main/java/com/salessparrow/api/lib/crmActions/getAccountEventDetails/GetAccountEventDetails.java create mode 100644 src/main/java/com/salessparrow/api/lib/crmActions/getAccountEventDetails/GetAccountEventDetailsFactory.java create mode 100644 src/main/java/com/salessparrow/api/lib/crmActions/getAccountEventDetails/GetSalesforceAccountEventDetails.java create mode 100644 src/main/java/com/salessparrow/api/lib/crmActions/updateAccountTask/UpdateAccountTaskFactory.java create mode 100644 src/main/java/com/salessparrow/api/lib/crmActions/updateAccountTask/UpdateAccountTaskInterface.java create mode 100644 src/main/java/com/salessparrow/api/lib/crmActions/updateAccountTask/UpdateSalesforceAccountTask.java create mode 100644 src/main/java/com/salessparrow/api/services/accountEvents/GetAccountEventDetailsService.java create mode 100644 src/main/java/com/salessparrow/api/services/accountTask/UpdateAccountTaskService.java create mode 100644 src/test/java/com/salessparrow/api/functional/controllers/accountEventController/GetAccountEventDetailsTest.java create mode 100644 src/test/resources/data/functional/controllers/accountEventController/getAccountEventDetails.scenarios.json create mode 100644 src/test/resources/fixtures/functional/controllers/accountEventController/getAccountEventDetails.fixtures.json diff --git a/src/main/java/com/salessparrow/api/controllers/AccountEventController.java b/src/main/java/com/salessparrow/api/controllers/AccountEventController.java index 7a28d113..c7bd71f6 100644 --- a/src/main/java/com/salessparrow/api/controllers/AccountEventController.java +++ b/src/main/java/com/salessparrow/api/controllers/AccountEventController.java @@ -15,11 +15,13 @@ import org.springframework.web.bind.annotation.RestController; import com.salessparrow.api.dto.formatter.CreateEventFormatterDto; +import com.salessparrow.api.dto.formatter.GetEventDetailsFormatterDto; import com.salessparrow.api.dto.formatter.GetEventsListFormatterDto; import com.salessparrow.api.dto.requestMapper.CreateAccountEventDto; import com.salessparrow.api.dto.requestMapper.UpdateAccountEventDto; import com.salessparrow.api.services.accountEvents.CreateAccountEventService; import com.salessparrow.api.services.accountEvents.DeleteAccountEventService; +import com.salessparrow.api.services.accountEvents.GetAccountEventDetailsService; import com.salessparrow.api.services.accountEvents.GetAccountEventsListService; import com.salessparrow.api.services.accountEvents.UpdateAccountEventService; @@ -45,6 +47,9 @@ public class AccountEventController { @Autowired private UpdateAccountEventService updateEventService; + @Autowired + private GetAccountEventDetailsService getAccountEventDetailsService; + @PostMapping("") public ResponseEntity createEvent(HttpServletRequest request, @PathVariable("account_id") String accountId, @Valid @RequestBody CreateAccountEventDto createEventDto) { @@ -86,4 +91,15 @@ public ResponseEntity updateEvent(HttpServletRequest request, @PathVariabl return ResponseEntity.status(HttpStatus.OK).build(); } + @GetMapping("/{event_id}") + public ResponseEntity getEventFromAccount(HttpServletRequest request, + @PathVariable("account_id") String accountId, @PathVariable("event_id") String eventId) { + logger.info("Get Event request received"); + + GetEventDetailsFormatterDto getEventDetailsResponse = getAccountEventDetailsService.getEventDetails(request, + eventId); + + return ResponseEntity.ok().body(getEventDetailsResponse); + } + } diff --git a/src/main/java/com/salessparrow/api/controllers/AccountTaskController.java b/src/main/java/com/salessparrow/api/controllers/AccountTaskController.java index 7cab58dc..4ab0996d 100644 --- a/src/main/java/com/salessparrow/api/controllers/AccountTaskController.java +++ b/src/main/java/com/salessparrow/api/controllers/AccountTaskController.java @@ -10,16 +10,19 @@ import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.PutMapping; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; import com.salessparrow.api.dto.formatter.CreateTaskFormatterDto; import com.salessparrow.api.dto.requestMapper.CreateAccountTaskDto; +import com.salessparrow.api.dto.requestMapper.UpdateAccountTaskDto; import com.salessparrow.api.services.accountTask.CreateTaskService; import com.salessparrow.api.services.accountTask.DeleteTaskService; import com.salessparrow.api.dto.formatter.GetTasksListFormatterDto; import com.salessparrow.api.services.accountTask.GetAccountTasksListService; +import com.salessparrow.api.services.accountTask.UpdateAccountTaskService; import jakarta.servlet.http.HttpServletRequest; import jakarta.validation.Valid; @@ -40,6 +43,9 @@ public class AccountTaskController { @Autowired private GetAccountTasksListService getAccountTasksListService; + @Autowired + private UpdateAccountTaskService updateTaskService; + @PostMapping("/{account_id}/tasks") public ResponseEntity createTask(HttpServletRequest request, @PathVariable("account_id") String accountId, @Valid @RequestBody CreateAccountTaskDto task) { @@ -70,4 +76,14 @@ public ResponseEntity deleteTask(HttpServletRequest request, @PathVariable return ResponseEntity.status(HttpStatus.NO_CONTENT).build(); } + @PutMapping("/{task_id}") + public ResponseEntity updateTask(HttpServletRequest request, @PathVariable("account_id") String accountId, + @PathVariable("task_id") String taskId, @Valid @RequestBody UpdateAccountTaskDto updateTaskDto) { + logger.info("Update task request received"); + + updateTaskService.updateAccountTask(request, accountId, taskId, updateTaskDto); + + return ResponseEntity.status(HttpStatus.OK).build(); + } + } diff --git a/src/main/java/com/salessparrow/api/dto/formatter/GetEventDetailsFormatterDto.java b/src/main/java/com/salessparrow/api/dto/formatter/GetEventDetailsFormatterDto.java new file mode 100644 index 00000000..40872016 --- /dev/null +++ b/src/main/java/com/salessparrow/api/dto/formatter/GetEventDetailsFormatterDto.java @@ -0,0 +1,15 @@ +package com.salessparrow.api.dto.formatter; + +import com.fasterxml.jackson.databind.PropertyNamingStrategies; +import com.fasterxml.jackson.databind.annotation.JsonNaming; +import com.salessparrow.api.dto.entities.EventEntity; + +import lombok.Data; + +@Data +@JsonNaming(PropertyNamingStrategies.SnakeCaseStrategy.class) +public class GetEventDetailsFormatterDto { + + private EventEntity eventDetail; + +} diff --git a/src/main/java/com/salessparrow/api/dto/requestMapper/UpdateAccountTaskDto.java b/src/main/java/com/salessparrow/api/dto/requestMapper/UpdateAccountTaskDto.java new file mode 100644 index 00000000..3a9efc05 --- /dev/null +++ b/src/main/java/com/salessparrow/api/dto/requestMapper/UpdateAccountTaskDto.java @@ -0,0 +1,25 @@ +package com.salessparrow.api.dto.requestMapper; + +import com.fasterxml.jackson.databind.PropertyNamingStrategies; +import com.fasterxml.jackson.databind.annotation.JsonNaming; +import com.salessparrow.api.lib.customAnnotations.ValidDateFormat; + +import jakarta.validation.constraints.NotBlank; +import jakarta.validation.constraints.Size; +import lombok.Data; + +@Data +@JsonNaming(PropertyNamingStrategies.SnakeCaseStrategy.class) +public class UpdateAccountTaskDto { + + @NotBlank(message = "missing_crm_organization_user_id") + private String crmOrganizationUserId; + + @NotBlank(message = "missing_description") + @Size(max = 32000, message = "description_too_long") + private String description; + + @ValidDateFormat(message = "invalid_due_date") + private String dueDate; + +} diff --git a/src/main/java/com/salessparrow/api/lib/crmActions/getAccountEventDetails/GetAccountEventDetails.java b/src/main/java/com/salessparrow/api/lib/crmActions/getAccountEventDetails/GetAccountEventDetails.java new file mode 100644 index 00000000..303855e0 --- /dev/null +++ b/src/main/java/com/salessparrow/api/lib/crmActions/getAccountEventDetails/GetAccountEventDetails.java @@ -0,0 +1,16 @@ +package com.salessparrow.api.lib.crmActions.getAccountEventDetails; + +import org.springframework.stereotype.Component; + +import com.salessparrow.api.domain.User; +import com.salessparrow.api.dto.formatter.GetEventDetailsFormatterDto; + +/** + * GetAccountEventDetails is an interface for the getEventDetails action for the CRM. + */ +@Component +public interface GetAccountEventDetails { + + public GetEventDetailsFormatterDto getEventDetails(User user, String eventId); + +} diff --git a/src/main/java/com/salessparrow/api/lib/crmActions/getAccountEventDetails/GetAccountEventDetailsFactory.java b/src/main/java/com/salessparrow/api/lib/crmActions/getAccountEventDetails/GetAccountEventDetailsFactory.java new file mode 100644 index 00000000..b7393264 --- /dev/null +++ b/src/main/java/com/salessparrow/api/lib/crmActions/getAccountEventDetails/GetAccountEventDetailsFactory.java @@ -0,0 +1,39 @@ +package com.salessparrow.api.lib.crmActions.getAccountEventDetails; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +import com.salessparrow.api.domain.User; +import com.salessparrow.api.dto.formatter.GetEventDetailsFormatterDto; +import com.salessparrow.api.exception.CustomException; +import com.salessparrow.api.lib.errorLib.ErrorObject; +import com.salessparrow.api.lib.globalConstants.UserConstants; + +/** + * GetAccountEventDetailsFactory is a factory class for the getEventDetails action for the + * CRM. + */ +@Component +public class GetAccountEventDetailsFactory { + + @Autowired + GetSalesforceAccountEventDetails getSalesforceEventDetails; + + /** + * getEventDetails is a method that returns the details of an event. + * @param user + * @param eventId + * @return GetEventDetailsFormatterDto + */ + public GetEventDetailsFormatterDto getEventDetails(User user, String eventId) { + + switch (user.getUserKind()) { + case UserConstants.SALESFORCE_USER_KIND: + return getSalesforceEventDetails.getEventDetails(user, eventId); + default: + throw new CustomException( + new ErrorObject("l_ca_gaed_gaedf_gaed_1", "something_went_wrong", "Invalid user kind.")); + } + } + +} diff --git a/src/main/java/com/salessparrow/api/lib/crmActions/getAccountEventDetails/GetSalesforceAccountEventDetails.java b/src/main/java/com/salessparrow/api/lib/crmActions/getAccountEventDetails/GetSalesforceAccountEventDetails.java new file mode 100644 index 00000000..a32eae5b --- /dev/null +++ b/src/main/java/com/salessparrow/api/lib/crmActions/getAccountEventDetails/GetSalesforceAccountEventDetails.java @@ -0,0 +1,111 @@ +package com.salessparrow.api.lib.crmActions.getAccountEventDetails; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +import com.fasterxml.jackson.databind.DeserializationFeature; +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.salessparrow.api.domain.User; +import com.salessparrow.api.dto.entities.EventEntity; +import com.salessparrow.api.dto.formatter.GetEventDetailsFormatterDto; +import com.salessparrow.api.exception.CustomException; +import com.salessparrow.api.lib.Util; +import com.salessparrow.api.lib.errorLib.ErrorObject; +import com.salessparrow.api.lib.errorLib.ParamErrorObject; +import com.salessparrow.api.lib.globalConstants.SalesforceConstants; +import com.salessparrow.api.lib.httpLib.HttpClient; +import com.salessparrow.api.lib.salesforce.dto.CompositeRequestDto; +import com.salessparrow.api.lib.salesforce.dto.SalesforceGetEventsListDto; +import com.salessparrow.api.lib.salesforce.helper.MakeCompositeRequest; +import com.salessparrow.api.lib.salesforce.helper.SalesforceQueryBuilder; + +@Component +public class GetSalesforceAccountEventDetails implements GetAccountEventDetails { + + Logger logger = LoggerFactory.getLogger(GetSalesforceAccountEventDetails.class); + + @Autowired + private SalesforceConstants salesforceConstants; + + @Autowired + private MakeCompositeRequest makeCompositeRequest; + + /** + * Get the details of an event. + * @param user + * @param eventId + * @return GetEventDetailsFormatterDto + **/ + public GetEventDetailsFormatterDto getEventDetails(User user, String eventId) { + + logger.info("Salesforce getEventDetails action called"); + + String salesforceUserId = user.getExternalUserId(); + + SalesforceQueryBuilder salesforceQuery = new SalesforceQueryBuilder(); + String query = salesforceQuery.getAccountEventDetailsUrl(eventId); + + String url = salesforceConstants.queryUrlPath() + query; + + CompositeRequestDto compositeReq = new CompositeRequestDto("GET", url, "GetEventsList"); + + List compositeRequests = new ArrayList(); + compositeRequests.add(compositeReq); + + HttpClient.HttpResponse response = makeCompositeRequest.makePostRequest(compositeRequests, salesforceUserId); + + return parseResponse(response.getResponseBody()); + + } + + /** + * Parse Response + * @param responseBody + * @return GetEventsListFormatterDto + **/ + public GetEventDetailsFormatterDto parseResponse(String responseBody) { + + Util util = new Util(); + JsonNode rootNode = util.getJsonNode(responseBody); + + JsonNode compositeResponse = rootNode.get("compositeResponse").get(0); + Integer statusCode = compositeResponse.get("httpStatusCode").asInt(); + + if (statusCode != 200 && statusCode != 201) { + String errorBody = compositeResponse.get("body").asText(); + + if (statusCode == 400) { + throw new CustomException( + new ParamErrorObject("l_ca_gaed_gsaed_pr_1", errorBody, Arrays.asList("invalid_account_id"))); + } + else { + throw new CustomException(new ErrorObject("l_ca_gaed_gsaed_pr_2", "something_went_wrong", errorBody)); + } + } + + JsonNode recordsNode = rootNode.get("compositeResponse").get(0).get("body").get("records"); + ; + + EventEntity eventEntity = new EventEntity(); + for (JsonNode recordNode : recordsNode) { + ObjectMapper mapper = new ObjectMapper(); + mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES); + SalesforceGetEventsListDto salesforceGetEventsListDto = mapper.convertValue(recordNode, + SalesforceGetEventsListDto.class); + eventEntity = salesforceGetEventsListDto.eventEntity(); + } + + GetEventDetailsFormatterDto getEventDetailsFormatterDto = new GetEventDetailsFormatterDto(); + getEventDetailsFormatterDto.setEventDetail(eventEntity); + + return getEventDetailsFormatterDto; + } + +} diff --git a/src/main/java/com/salessparrow/api/lib/crmActions/updateAccountTask/UpdateAccountTaskFactory.java b/src/main/java/com/salessparrow/api/lib/crmActions/updateAccountTask/UpdateAccountTaskFactory.java new file mode 100644 index 00000000..2d2e335b --- /dev/null +++ b/src/main/java/com/salessparrow/api/lib/crmActions/updateAccountTask/UpdateAccountTaskFactory.java @@ -0,0 +1,43 @@ +package com.salessparrow.api.lib.crmActions.updateAccountTask; + +import org.slf4j.Logger; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +import com.salessparrow.api.domain.User; +import com.salessparrow.api.dto.requestMapper.UpdateAccountTaskDto; +import com.salessparrow.api.exception.CustomException; +import com.salessparrow.api.lib.errorLib.ErrorObject; +import com.salessparrow.api.lib.globalConstants.UserConstants; + +/** + * UpdateAccountTaskFactory is a factory class for the update task action for the CRM. + */ +@Component +public class UpdateAccountTaskFactory { + + private Logger logger = org.slf4j.LoggerFactory.getLogger(UpdateAccountTaskFactory.class); + + @Autowired + private UpdateSalesforceAccountTask updateSalesforceTask; + + /** + * Update a task for a given account + * @param user + * @param accountId + * @return void + **/ + public void updateTask(User user, String accountId, String taskId, UpdateAccountTaskDto updateTaskDto) { + logger.info("Update Task Factory started"); + + switch (user.getUserKind()) { + case UserConstants.SALESFORCE_USER_KIND: + updateSalesforceTask.updateTask(user, accountId, taskId, updateTaskDto); + return; + default: + throw new CustomException( + new ErrorObject("l_ua_uae_uaef_uae_1", "something_went_wrong", "Invalid user kind.")); + } + } + +} diff --git a/src/main/java/com/salessparrow/api/lib/crmActions/updateAccountTask/UpdateAccountTaskInterface.java b/src/main/java/com/salessparrow/api/lib/crmActions/updateAccountTask/UpdateAccountTaskInterface.java new file mode 100644 index 00000000..581b820f --- /dev/null +++ b/src/main/java/com/salessparrow/api/lib/crmActions/updateAccountTask/UpdateAccountTaskInterface.java @@ -0,0 +1,16 @@ +package com.salessparrow.api.lib.crmActions.updateAccountTask; + +import org.springframework.stereotype.Component; + +import com.salessparrow.api.domain.User; +import com.salessparrow.api.dto.requestMapper.UpdateAccountTaskDto; + +/** + * UpdateAccountTaskInterface is an interface for the update task action for the CRM. + */ +@Component +public interface UpdateAccountTaskInterface { + + public void updateTask(User user, String accountId, String taskId, UpdateAccountTaskDto updateTaskDto); + +} diff --git a/src/main/java/com/salessparrow/api/lib/crmActions/updateAccountTask/UpdateSalesforceAccountTask.java b/src/main/java/com/salessparrow/api/lib/crmActions/updateAccountTask/UpdateSalesforceAccountTask.java new file mode 100644 index 00000000..2834c1fc --- /dev/null +++ b/src/main/java/com/salessparrow/api/lib/crmActions/updateAccountTask/UpdateSalesforceAccountTask.java @@ -0,0 +1,102 @@ +package com.salessparrow.api.lib.crmActions.updateAccountTask; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.slf4j.Logger; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +import com.fasterxml.jackson.databind.JsonNode; +import com.salessparrow.api.domain.User; +import com.salessparrow.api.dto.requestMapper.UpdateAccountTaskDto; +import com.salessparrow.api.exception.CustomException; +import com.salessparrow.api.lib.Util; +import com.salessparrow.api.lib.errorLib.ErrorObject; +import com.salessparrow.api.lib.errorLib.ParamErrorObject; +import com.salessparrow.api.lib.globalConstants.SalesforceConstants; +import com.salessparrow.api.lib.httpLib.HttpClient; +import com.salessparrow.api.lib.salesforce.dto.CompositeRequestDto; +import com.salessparrow.api.lib.salesforce.helper.MakeCompositeRequest; + +/** + * UpdateSalesforceAccountTask is a class that updates a task for an account in + * Salesforce. + */ +@Component +public class UpdateSalesforceAccountTask implements UpdateAccountTaskInterface { + + private Logger logger = org.slf4j.LoggerFactory.getLogger(UpdateSalesforceAccountTask.class); + + @Autowired + private SalesforceConstants salesforceConstants; + + @Autowired + private MakeCompositeRequest makeCompositeRequest; + + /** + * Update a task for a given account. + * @param user + * @param accountId + * @param updateTaskDto + * @return void + */ + public void updateTask(User user, String accountId, String taskId, UpdateAccountTaskDto updateTaskDto) { + logger.info("Update Salesforce Task started"); + + String salesforceUserId = user.getExternalUserId(); + + Util util = new Util(); + String taskDescription = util.unEscapeSpecialCharactersForPlainText(updateTaskDto.getDescription()); + String taskSubject = util.getTrimmedString(taskDescription, salesforceConstants.salesforceSubjectLength()); + + Map updateTaskBody = new HashMap(); + updateTaskBody.put("Subject", taskSubject); + updateTaskBody.put("Description", taskDescription); + updateTaskBody.put("OwnerId", updateTaskDto.getCrmOrganizationUserId()); + updateTaskBody.put("ActivityDate", updateTaskDto.getDueDate()); + + CompositeRequestDto updateTaskCompositeRequestDto = new CompositeRequestDto("PATCH", + salesforceConstants.salesforceUpdateTaskUrl(taskId), "UpdateTask", updateTaskBody); + + List compositeRequests = new ArrayList(); + compositeRequests.add(updateTaskCompositeRequestDto); + + HttpClient.HttpResponse response = makeCompositeRequest.makePostRequest(compositeRequests, salesforceUserId); + + parseResponse(response.getResponseBody()); + } + + /** + * Parse the response from Salesforce. + * @param updateTaskResponse + * @return void + */ + private void parseResponse(String updateTaskResponse) { + logger.info("Parsing the response from Salesforce"); + + Util util = new Util(); + JsonNode rootNode = util.getJsonNode(updateTaskResponse); + + JsonNode compositeResponse = rootNode.get("compositeResponse").get(0); + Integer statusCode = compositeResponse.get("httpStatusCode").asInt(); + + if (statusCode != 200 && statusCode != 201 && statusCode != 204) { + String errorBody = compositeResponse.get("body").asText(); + + // MALFORMED_ID or NOT_FOUND + if (statusCode == 400 || statusCode == 404) { + + throw new CustomException( + new ParamErrorObject("l_ua_uae_usae_pr_1", errorBody, Arrays.asList("invalid_task_id"))); + } + else { + throw new CustomException(new ErrorObject("l_ua_uae_usae_pr_2", "something_went_wrong", errorBody)); + } + } + } + +} diff --git a/src/main/java/com/salessparrow/api/lib/globalConstants/SalesforceConstants.java b/src/main/java/com/salessparrow/api/lib/globalConstants/SalesforceConstants.java index 6c23ffb7..f3dfab94 100644 --- a/src/main/java/com/salessparrow/api/lib/globalConstants/SalesforceConstants.java +++ b/src/main/java/com/salessparrow/api/lib/globalConstants/SalesforceConstants.java @@ -46,6 +46,10 @@ public String salesforceUpdateEventUrl(String eventId) { return sObjectsPath() + "/Event/" + eventId; } + public String salesforceUpdateTaskUrl(String taskId) { + return sObjectsPath() + "/Task/" + taskId; + } + public String salesforceDeleteNoteUrl(String noteId) { return sObjectsPath() + "/ContentNote/" + noteId; } diff --git a/src/main/java/com/salessparrow/api/lib/salesforce/helper/SalesforceQueryBuilder.java b/src/main/java/com/salessparrow/api/lib/salesforce/helper/SalesforceQueryBuilder.java index cf1bcaf4..21dfbbb6 100644 --- a/src/main/java/com/salessparrow/api/lib/salesforce/helper/SalesforceQueryBuilder.java +++ b/src/main/java/com/salessparrow/api/lib/salesforce/helper/SalesforceQueryBuilder.java @@ -128,4 +128,12 @@ public String getAccountEventsQuery(String accountId) { + accountId + "' ORDER BY LastModifiedDate DESC LIMIT 5"); } + public String getAccountEventDetailsUrl(String eventId) { + eventId = Util.escapeSpecialChars(eventId); + + return Util.urlEncoder( + "SELECT Id, Description, CreatedBy.Name, StartDateTime, EndDateTime, LastModifiedDate FROM Event WHERE Id = '" + + eventId + "'"); + } + } diff --git a/src/main/java/com/salessparrow/api/services/accountEvents/GetAccountEventDetailsService.java b/src/main/java/com/salessparrow/api/services/accountEvents/GetAccountEventDetailsService.java new file mode 100644 index 00000000..a9e47013 --- /dev/null +++ b/src/main/java/com/salessparrow/api/services/accountEvents/GetAccountEventDetailsService.java @@ -0,0 +1,34 @@ +package com.salessparrow.api.services.accountEvents; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import com.salessparrow.api.domain.User; +import com.salessparrow.api.dto.formatter.GetEventDetailsFormatterDto; +import com.salessparrow.api.lib.crmActions.getAccountEventDetails.GetAccountEventDetailsFactory; + +import jakarta.servlet.http.HttpServletRequest; + +/** + * GetAccountEventDetailsService is a service class for the getEventDetails action for the + * CRM. + */ +@Service +public class GetAccountEventDetailsService { + + @Autowired + private GetAccountEventDetailsFactory getEventDetailsFactory; + + /** + * Get the details of an event + * @param accountId + * @param eventId + * @return GetEventDetailsFormatterDto + */ + public GetEventDetailsFormatterDto getEventDetails(HttpServletRequest request, String eventId) { + User currentUser = (User) request.getAttribute("current_user"); + + return getEventDetailsFactory.getEventDetails(currentUser, eventId); + } + +} diff --git a/src/main/java/com/salessparrow/api/services/accountTask/UpdateAccountTaskService.java b/src/main/java/com/salessparrow/api/services/accountTask/UpdateAccountTaskService.java new file mode 100644 index 00000000..3bfc5c95 --- /dev/null +++ b/src/main/java/com/salessparrow/api/services/accountTask/UpdateAccountTaskService.java @@ -0,0 +1,42 @@ +package com.salessparrow.api.services.accountTask; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import com.salessparrow.api.domain.User; +import com.salessparrow.api.dto.requestMapper.UpdateAccountTaskDto; +import com.salessparrow.api.lib.crmActions.updateAccountTask.UpdateAccountTaskFactory; + +import jakarta.servlet.http.HttpServletRequest; + +/** + * UpdateAccountTaskService is a service class that handles the update of a task in an + * account. + */ +@Service +public class UpdateAccountTaskService { + + Logger logger = LoggerFactory.getLogger(UpdateAccountTaskService.class); + + @Autowired + private UpdateAccountTaskFactory updateAccountTaskFactory; + + /** + * Updates a task in an account. + * @param request + * @param accountId + * @param taskId + * @return void + */ + public void updateAccountTask(HttpServletRequest request, String accountId, String taskId, + UpdateAccountTaskDto updateTaskDto) { + logger.info("Update task in account service called"); + + User currentUser = (User) request.getAttribute("current_user"); + + updateAccountTaskFactory.updateTask(currentUser, accountId, taskId, updateTaskDto); + } + +} diff --git a/src/test/java/com/salessparrow/api/functional/controllers/accountEventController/CreateAccountEventTest.java b/src/test/java/com/salessparrow/api/functional/controllers/accountEventController/CreateAccountEventTest.java index 957a1756..5a2ed9cc 100644 --- a/src/test/java/com/salessparrow/api/functional/controllers/accountEventController/CreateAccountEventTest.java +++ b/src/test/java/com/salessparrow/api/functional/controllers/accountEventController/CreateAccountEventTest.java @@ -93,10 +93,10 @@ public void createAccountEvent(Scenario testScenario) throws Exception { String accountId = (String) testScenario.getInput().get("accountId"); // Prepare mock responses - HttpResponse createNoteMockResponse = new HttpResponse(); - createNoteMockResponse + HttpResponse createEventMockResponse = new HttpResponse(); + createEventMockResponse .setResponseBody(objectMapper.writeValueAsString(testScenario.getMocks().get("makeCompositeRequest"))); - when(makeCompositeRequestMock.makePostRequest(any(), any())).thenReturn(createNoteMockResponse); + when(makeCompositeRequestMock.makePostRequest(any(), any())).thenReturn(createEventMockResponse); // Perform the request String requestBody = objectMapper.writeValueAsString(testScenario.getInput().get("body")); diff --git a/src/test/java/com/salessparrow/api/functional/controllers/accountEventController/GetAccountEventDetailsTest.java b/src/test/java/com/salessparrow/api/functional/controllers/accountEventController/GetAccountEventDetailsTest.java new file mode 100644 index 00000000..cfa57c8d --- /dev/null +++ b/src/test/java/com/salessparrow/api/functional/controllers/accountEventController/GetAccountEventDetailsTest.java @@ -0,0 +1,137 @@ +package com.salessparrow.api.functional.controllers.accountEventController; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.when; + +import java.io.IOException; +import java.util.List; +import java.util.stream.Stream; + +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.mock.mockito.MockBean; +import org.springframework.context.annotation.Import; +import org.springframework.core.io.DefaultResourceLoader; +import org.springframework.core.io.Resource; +import org.springframework.http.MediaType; +import org.springframework.test.context.web.WebAppConfiguration; +import org.springframework.test.web.servlet.MockMvc; +import org.springframework.test.web.servlet.ResultActions; +import org.springframework.test.web.servlet.request.MockMvcRequestBuilders; + +import com.fasterxml.jackson.core.type.TypeReference; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.github.dynamobee.exception.DynamobeeException; +import com.salessparrow.api.helper.Cleanup; +import com.salessparrow.api.helper.Common; +import com.salessparrow.api.helper.FixtureData; +import com.salessparrow.api.helper.LoadFixture; +import com.salessparrow.api.helper.Scenario; +import com.salessparrow.api.helper.Setup; +import com.salessparrow.api.lib.globalConstants.CookieConstants; +import com.salessparrow.api.helper.Constants; + +import com.salessparrow.api.lib.httpLib.HttpClient.HttpResponse; +import com.salessparrow.api.lib.salesforce.helper.MakeCompositeRequest; + +import jakarta.servlet.http.Cookie; + +@SpringBootTest +@AutoConfigureMockMvc +@WebAppConfiguration +@Import({ Setup.class, Cleanup.class, Common.class, LoadFixture.class }) +public class GetAccountEventDetailsTest { + + @Autowired + private MockMvc mockMvc; + + @Autowired + private Common common; + + @Autowired + private LoadFixture loadFixture; + + @Autowired + private Setup setup; + + @Autowired + private Cleanup cleanup; + + @MockBean + private MakeCompositeRequest makeCompositeRequestMock; + + @BeforeEach + public void setUp() throws DynamobeeException, IOException { + setup.perform(); + } + + @AfterEach + public void tearDown() { + cleanup.perform(); + } + + @ParameterizedTest + @MethodSource("testScenariosProvider") + public void getAccountEventDetails(Scenario testScenario) throws Exception { + // Load fixture data + String currentFunctionName = new Object() { + }.getClass().getEnclosingMethod().getName(); + FixtureData fixtureData = common.loadFixture( + "classpath:fixtures/functional/controllers/accountEventController/getAccountEventDetails.fixtures.json", + currentFunctionName); + loadFixture.perform(fixtureData); + + // Read data from the scenario + ObjectMapper objectMapper = new ObjectMapper(); + String cookieValue = Constants.SALESFORCE_ACTIVE_USER_COOKIE_VALUE; + String accountId = (String) testScenario.getInput().get("accountId"); + String eventId = (String) testScenario.getInput().get("eventId"); + + // Prepare mock responses + HttpResponse getEventsListMockResponse = new HttpResponse(); + getEventsListMockResponse + .setResponseBody(objectMapper.writeValueAsString(testScenario.getMocks().get("makeCompositeRequest"))); + when(makeCompositeRequestMock.makePostRequest(any(), any())).thenReturn(getEventsListMockResponse); + + // Perform the request + String url = "/api/v1/accounts/" + accountId + "/events/" + eventId; + + ResultActions resultActions = mockMvc.perform(MockMvcRequestBuilders.get(url) + .cookie(new Cookie(CookieConstants.USER_LOGIN_COOKIE_NAME, cookieValue)) + .contentType(MediaType.APPLICATION_JSON)); + + // Check the response + String expectedOutput = objectMapper.writeValueAsString(testScenario.getOutput()); + String actualOutput = resultActions.andReturn().getResponse().getContentAsString(); + + if (resultActions.andReturn().getResponse().getStatus() == 200) { + if (expectedOutput.equals("{}")) { + expectedOutput = ""; + } + assertEquals(expectedOutput, actualOutput); + } + else { + common.compareErrors(testScenario, actualOutput); + } + } + + static Stream testScenariosProvider() throws IOException { + List testScenarios = loadScenarios(); + return testScenarios.stream(); + } + + private static List loadScenarios() throws IOException { + String scenariosPath = "classpath:data/functional/controllers/accountEventController/getAccountEventDetails.scenarios.json"; + Resource resource = new DefaultResourceLoader().getResource(scenariosPath); + ObjectMapper objectMapper = new ObjectMapper(); + return objectMapper.readValue(resource.getInputStream(), new TypeReference>() { + }); + } + +} diff --git a/src/test/resources/data/functional/controllers/accountEventController/getAccountEventDetails.scenarios.json b/src/test/resources/data/functional/controllers/accountEventController/getAccountEventDetails.scenarios.json new file mode 100644 index 00000000..5a1969bc --- /dev/null +++ b/src/test/resources/data/functional/controllers/accountEventController/getAccountEventDetails.scenarios.json @@ -0,0 +1,88 @@ +[ + { + "description": "Should return the event details for a given event id", + "input": { + "accountId": "0011e00000bWSxdAAG", + "eventId": "00T1e000007mGYaEAA" + }, + "mocks": { + "makeCompositeRequest": { + "compositeResponse": [ + { + "body": { + "totalSize": 1, + "done": true, + "records": [ + { + "attributes": { + "type": "Event", + "url": "/services/data/v58.0/sobjects/Event/00U1e000003UPzbEAG" + }, + "Id": "00U1e000003UPzbEAG", + "WhatId": "0011e00000bWSxdAAG", + "StartDateTime": "2023-09-16T06:49:00.000+0000", + "EndDateTime": "2023-09-16T07:49:00.000+0000", + "Description": "Event Description", + "CreatedBy": { + "attributes": { + "type": "User", + "url": "/services/data/v58.0/sobjects/User/0055i00000AUxQHAA1" + }, + "Name": "Ashfaq Bhojani" + }, + "LastModifiedDate": "2023-09-28T04:55:12.000+0000" + } + ] + }, + "httpHeaders": {}, + "httpStatusCode": 200, + "referenceId": "getEvent" + } + ] + } + }, + "output": { + "event_detail": { + "id": "00U1e000003UPzbEAG", + "creator_name": "Ashfaq Bhojani", + "description": "Event Description", + "start_datetime": "2023-09-16T06:49:00.000+0000", + "end_datetime": "2023-09-16T07:49:00.000+0000", + "last_modified_time": "2023-09-28T04:55:12.000+00:00" + } + } + }, + { + "description": "should return error response when event id is invalid", + "input": { + "account_id": "0011e00000bWSxdAAG", + "event_id": "invalid_event_id" + }, + "mocks":{ + "makeCompositeRequest":{ + "compositeResponse": [ + { + "body": [ + { + "message": "\nLastModifiedDate FROM Event WHERE Id='invalid_event_id'\n ^\nERROR at Row:1:Column:105\ninvalid ID field: invalid_event_id", + "errorCode": "INVALID_QUERY_FILTER_OPERATOR" + } + ], + "httpHeaders": {}, + "httpStatusCode": 400, + "referenceId": "getEvent" + } + ] + } + }, + "output": { + "http_code": 400, + "message": "At least one parameter is invalid or missing.", + "code": "INVALID_PARAMS", + "internal_error_identifier": "l_ca_gaed_gsaed_pr_1", + "param_errors": [ + "invalid_account_id" + ] + } + } +] \ No newline at end of file diff --git a/src/test/resources/fixtures/functional/controllers/accountEventController/getAccountEventDetails.fixtures.json b/src/test/resources/fixtures/functional/controllers/accountEventController/getAccountEventDetails.fixtures.json new file mode 100644 index 00000000..b08a0cd6 --- /dev/null +++ b/src/test/resources/fixtures/functional/controllers/accountEventController/getAccountEventDetails.fixtures.json @@ -0,0 +1,14 @@ +{ + "getAccountEventDetails": { + "salesforce_users": [ + { + "filepath": "classpath:fixtures/common/repositories/salesforceUser/ActiveSalesforceUser.json" + } + ], + "salesforce_oauth_tokens": [ + { + "filepath": "classpath:fixtures/common/repositories/salesforceOauthToken/ActiveSalesforceOauthToken.json" + } + ] + } +} \ No newline at end of file From dd09f360f94bd456fdb648691a3290ba64a6835a Mon Sep 17 00:00:00 2001 From: Raj Shah Date: Thu, 28 Sep 2023 17:57:39 +0530 Subject: [PATCH 15/36] Updated success status for updateEvent to 204 --- .../salessparrow/api/controllers/AccountEventController.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/salessparrow/api/controllers/AccountEventController.java b/src/main/java/com/salessparrow/api/controllers/AccountEventController.java index c7bd71f6..1c313ae3 100644 --- a/src/main/java/com/salessparrow/api/controllers/AccountEventController.java +++ b/src/main/java/com/salessparrow/api/controllers/AccountEventController.java @@ -88,7 +88,7 @@ public ResponseEntity updateEvent(HttpServletRequest request, @PathVariabl updateEventService.updateAccountEvent(request, accountId, eventId, updateEventDto); - return ResponseEntity.status(HttpStatus.OK).build(); + return ResponseEntity.status(HttpStatus.NO_CONTENT).build(); } @GetMapping("/{event_id}") From 68c043b9ca7b5316e2afa46f36b1909d90437aa0 Mon Sep 17 00:00:00 2001 From: Raj Shah Date: Thu, 28 Sep 2023 17:58:09 +0530 Subject: [PATCH 16/36] Updated success status for updateTask to 204 --- .../com/salessparrow/api/controllers/AccountTaskController.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/salessparrow/api/controllers/AccountTaskController.java b/src/main/java/com/salessparrow/api/controllers/AccountTaskController.java index 4ab0996d..46878dac 100644 --- a/src/main/java/com/salessparrow/api/controllers/AccountTaskController.java +++ b/src/main/java/com/salessparrow/api/controllers/AccountTaskController.java @@ -83,7 +83,7 @@ public ResponseEntity updateTask(HttpServletRequest request, @PathVariable updateTaskService.updateAccountTask(request, accountId, taskId, updateTaskDto); - return ResponseEntity.status(HttpStatus.OK).build(); + return ResponseEntity.status(HttpStatus.NO_CONTENT).build(); } } From 1f462bf75c3d7143237114d1aa9878ba3a6b60ca Mon Sep 17 00:00:00 2001 From: Raj Shah Date: Wed, 4 Oct 2023 19:58:06 +0530 Subject: [PATCH 17/36] Added update task and get task details api --- .../controllers/AccountTaskController.java | 24 ++- .../api/dto/entities/TaskEntity.java | 2 + .../formatter/GetTaskDetailsFormatterDto.java | 15 ++ .../GetAccountTaskDetails.java | 16 ++ .../GetAccountTaskDetailsFactory.java | 39 +++++ .../GetSalesforceAccountTaskDetails.java | 111 ++++++++++++++ .../UpdateSalesforceAccountTask.java | 4 +- .../dto/SalesforceGetTasksListDto.java | 3 + .../helper/SalesforceQueryBuilder.java | 10 +- .../GetAccountTaskDetailsService.java | 34 +++++ .../UpdateAccountEventTest.java | 4 +- .../GetAccountTaskDetailsTest.java | 137 +++++++++++++++++ .../UpdateAccountTaskTest.java | 141 ++++++++++++++++++ .../getAccountEventDetails.scenarios.json | 4 +- .../getAccountTaskDetails.scenarios.json | 95 ++++++++++++ .../getAccountTasksList.scenarios.json | 20 ++- .../updateAccountTask.scenarios.json | 65 ++++++++ .../getAccountTaskDetails.fixtures.json | 14 ++ .../updateAccountTask.fixtures.json | 14 ++ 19 files changed, 737 insertions(+), 15 deletions(-) create mode 100644 src/main/java/com/salessparrow/api/dto/formatter/GetTaskDetailsFormatterDto.java create mode 100644 src/main/java/com/salessparrow/api/lib/crmActions/getAccountTaskDetails/GetAccountTaskDetails.java create mode 100644 src/main/java/com/salessparrow/api/lib/crmActions/getAccountTaskDetails/GetAccountTaskDetailsFactory.java create mode 100644 src/main/java/com/salessparrow/api/lib/crmActions/getAccountTaskDetails/GetSalesforceAccountTaskDetails.java create mode 100644 src/main/java/com/salessparrow/api/services/accountTask/GetAccountTaskDetailsService.java create mode 100644 src/test/java/com/salessparrow/api/functional/controllers/accountTaskController/GetAccountTaskDetailsTest.java create mode 100644 src/test/java/com/salessparrow/api/functional/controllers/accountTaskController/UpdateAccountTaskTest.java create mode 100644 src/test/resources/data/functional/controllers/accountTaskController/getAccountTaskDetails.scenarios.json create mode 100644 src/test/resources/data/functional/controllers/accountTaskController/updateAccountTask.scenarios.json create mode 100644 src/test/resources/fixtures/functional/controllers/accountTaskController/getAccountTaskDetails.fixtures.json create mode 100644 src/test/resources/fixtures/functional/controllers/accountTaskController/updateAccountTask.fixtures.json diff --git a/src/main/java/com/salessparrow/api/controllers/AccountTaskController.java b/src/main/java/com/salessparrow/api/controllers/AccountTaskController.java index 46878dac..54a34218 100644 --- a/src/main/java/com/salessparrow/api/controllers/AccountTaskController.java +++ b/src/main/java/com/salessparrow/api/controllers/AccountTaskController.java @@ -16,10 +16,12 @@ import org.springframework.web.bind.annotation.RestController; import com.salessparrow.api.dto.formatter.CreateTaskFormatterDto; +import com.salessparrow.api.dto.formatter.GetTaskDetailsFormatterDto; import com.salessparrow.api.dto.requestMapper.CreateAccountTaskDto; import com.salessparrow.api.dto.requestMapper.UpdateAccountTaskDto; import com.salessparrow.api.services.accountTask.CreateTaskService; import com.salessparrow.api.services.accountTask.DeleteTaskService; +import com.salessparrow.api.services.accountTask.GetAccountTaskDetailsService; import com.salessparrow.api.dto.formatter.GetTasksListFormatterDto; import com.salessparrow.api.services.accountTask.GetAccountTasksListService; import com.salessparrow.api.services.accountTask.UpdateAccountTaskService; @@ -28,7 +30,7 @@ import jakarta.validation.Valid; @RestController -@RequestMapping("/api/v1/accounts") +@RequestMapping("/api/v1/accounts/{account_id}/tasks") @Validated public class AccountTaskController { @@ -46,7 +48,10 @@ public class AccountTaskController { @Autowired private UpdateAccountTaskService updateTaskService; - @PostMapping("/{account_id}/tasks") + @Autowired + private GetAccountTaskDetailsService getAccountTaskDetailsService; + + @PostMapping("") public ResponseEntity createTask(HttpServletRequest request, @PathVariable("account_id") String accountId, @Valid @RequestBody CreateAccountTaskDto task) { logger.info("Create task request received"); @@ -56,7 +61,7 @@ public ResponseEntity createTask(HttpServletRequest requ return ResponseEntity.status(HttpStatus.CREATED).body(createTaskFormatterDto); } - @GetMapping("/{account_id}/tasks") + @GetMapping("") public ResponseEntity getTasksList(HttpServletRequest request, @PathVariable("account_id") String accountId) { logger.info("Get tasks list request received"); @@ -66,7 +71,7 @@ public ResponseEntity getTasksList(HttpServletRequest return ResponseEntity.status(HttpStatus.OK).body(getTasksListFormatterDto); } - @DeleteMapping("/{account_id}/tasks/{task_id}") + @DeleteMapping("/{task_id}") public ResponseEntity deleteTask(HttpServletRequest request, @PathVariable("account_id") String accountId, @PathVariable("task_id") String taskId) { logger.info("Delete task request received"); @@ -86,4 +91,15 @@ public ResponseEntity updateTask(HttpServletRequest request, @PathVariable return ResponseEntity.status(HttpStatus.NO_CONTENT).build(); } + @GetMapping("/{task_id}") + public ResponseEntity getTaskFromAccount(HttpServletRequest request, + @PathVariable("account_id") String accountId, @PathVariable("task_id") String taskId) { + logger.info("Get Task request received"); + + GetTaskDetailsFormatterDto getTaskDetailsResponse = getAccountTaskDetailsService.getTaskDetails(request, + taskId); + + return ResponseEntity.ok().body(getTaskDetailsResponse); + } + } diff --git a/src/main/java/com/salessparrow/api/dto/entities/TaskEntity.java b/src/main/java/com/salessparrow/api/dto/entities/TaskEntity.java index ba1a199e..6897a273 100644 --- a/src/main/java/com/salessparrow/api/dto/entities/TaskEntity.java +++ b/src/main/java/com/salessparrow/api/dto/entities/TaskEntity.java @@ -24,6 +24,8 @@ public class TaskEntity { private String crmOrganizationUserName; + private String crmOrganizationUserId; + private Date lastModifiedTime; } diff --git a/src/main/java/com/salessparrow/api/dto/formatter/GetTaskDetailsFormatterDto.java b/src/main/java/com/salessparrow/api/dto/formatter/GetTaskDetailsFormatterDto.java new file mode 100644 index 00000000..16981303 --- /dev/null +++ b/src/main/java/com/salessparrow/api/dto/formatter/GetTaskDetailsFormatterDto.java @@ -0,0 +1,15 @@ +package com.salessparrow.api.dto.formatter; + +import com.fasterxml.jackson.databind.PropertyNamingStrategies; +import com.fasterxml.jackson.databind.annotation.JsonNaming; +import com.salessparrow.api.dto.entities.TaskEntity; + +import lombok.Data; + +@Data +@JsonNaming(PropertyNamingStrategies.SnakeCaseStrategy.class) +public class GetTaskDetailsFormatterDto { + + private TaskEntity taskDetail; + +} diff --git a/src/main/java/com/salessparrow/api/lib/crmActions/getAccountTaskDetails/GetAccountTaskDetails.java b/src/main/java/com/salessparrow/api/lib/crmActions/getAccountTaskDetails/GetAccountTaskDetails.java new file mode 100644 index 00000000..a06b190e --- /dev/null +++ b/src/main/java/com/salessparrow/api/lib/crmActions/getAccountTaskDetails/GetAccountTaskDetails.java @@ -0,0 +1,16 @@ +package com.salessparrow.api.lib.crmActions.getAccountTaskDetails; + +import org.springframework.stereotype.Component; + +import com.salessparrow.api.domain.User; +import com.salessparrow.api.dto.formatter.GetTaskDetailsFormatterDto; + +/** + * GetAccountTaskDetails is an interface for the getTaskDetails action for the CRM. + */ +@Component +public interface GetAccountTaskDetails { + + public GetTaskDetailsFormatterDto getTaskDetails(User user, String taskId); + +} diff --git a/src/main/java/com/salessparrow/api/lib/crmActions/getAccountTaskDetails/GetAccountTaskDetailsFactory.java b/src/main/java/com/salessparrow/api/lib/crmActions/getAccountTaskDetails/GetAccountTaskDetailsFactory.java new file mode 100644 index 00000000..6f1d49c0 --- /dev/null +++ b/src/main/java/com/salessparrow/api/lib/crmActions/getAccountTaskDetails/GetAccountTaskDetailsFactory.java @@ -0,0 +1,39 @@ +package com.salessparrow.api.lib.crmActions.getAccountTaskDetails; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +import com.salessparrow.api.domain.User; +import com.salessparrow.api.dto.formatter.GetTaskDetailsFormatterDto; +import com.salessparrow.api.exception.CustomException; +import com.salessparrow.api.lib.errorLib.ErrorObject; +import com.salessparrow.api.lib.globalConstants.UserConstants; + +/** + * GetAccountTaskDetailsFactory is a factory class for the getTaskDetails action for the + * CRM. + */ +@Component +public class GetAccountTaskDetailsFactory { + + @Autowired + GetSalesforceAccountTaskDetails getSalesforceTaskDetails; + + /** + * getTaskDetails is a method that returns the details of a task. + * @param user + * @param taskId + * @return GetTaskDetailsFormatterDto + */ + public GetTaskDetailsFormatterDto getTaskDetails(User user, String taskId) { + + switch (user.getUserKind()) { + case UserConstants.SALESFORCE_USER_KIND: + return getSalesforceTaskDetails.getTaskDetails(user, taskId); + default: + throw new CustomException( + new ErrorObject("l_ca_gatd_gatdf_gatd_1", "something_went_wrong", "Invalid user kind.")); + } + } + +} diff --git a/src/main/java/com/salessparrow/api/lib/crmActions/getAccountTaskDetails/GetSalesforceAccountTaskDetails.java b/src/main/java/com/salessparrow/api/lib/crmActions/getAccountTaskDetails/GetSalesforceAccountTaskDetails.java new file mode 100644 index 00000000..0af54c29 --- /dev/null +++ b/src/main/java/com/salessparrow/api/lib/crmActions/getAccountTaskDetails/GetSalesforceAccountTaskDetails.java @@ -0,0 +1,111 @@ +package com.salessparrow.api.lib.crmActions.getAccountTaskDetails; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +import com.fasterxml.jackson.databind.DeserializationFeature; +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.salessparrow.api.domain.User; +import com.salessparrow.api.dto.entities.TaskEntity; +import com.salessparrow.api.dto.formatter.GetTaskDetailsFormatterDto; +import com.salessparrow.api.exception.CustomException; +import com.salessparrow.api.lib.Util; +import com.salessparrow.api.lib.errorLib.ErrorObject; +import com.salessparrow.api.lib.errorLib.ParamErrorObject; +import com.salessparrow.api.lib.globalConstants.SalesforceConstants; +import com.salessparrow.api.lib.httpLib.HttpClient; +import com.salessparrow.api.lib.salesforce.dto.CompositeRequestDto; +import com.salessparrow.api.lib.salesforce.dto.SalesforceGetTasksListDto; +import com.salessparrow.api.lib.salesforce.helper.MakeCompositeRequest; +import com.salessparrow.api.lib.salesforce.helper.SalesforceQueryBuilder; + +@Component +public class GetSalesforceAccountTaskDetails implements GetAccountTaskDetails { + + Logger logger = LoggerFactory.getLogger(GetSalesforceAccountTaskDetails.class); + + @Autowired + private SalesforceConstants salesforceConstants; + + @Autowired + private MakeCompositeRequest makeCompositeRequest; + + /** + * Get the details of an task. + * @param user + * @param taskId + * @return GetTaskDetailsFormatterDto + **/ + public GetTaskDetailsFormatterDto getTaskDetails(User user, String taskId) { + + logger.info("Salesforce getTaskDetails action called"); + + String salesforceUserId = user.getExternalUserId(); + + SalesforceQueryBuilder salesforceQuery = new SalesforceQueryBuilder(); + String query = salesforceQuery.getAccountTaskDetailsUrl(taskId); + + String url = salesforceConstants.queryUrlPath() + query; + + CompositeRequestDto compositeReq = new CompositeRequestDto("GET", url, "GetTaskDetails"); + + List compositeRequests = new ArrayList(); + compositeRequests.add(compositeReq); + + HttpClient.HttpResponse response = makeCompositeRequest.makePostRequest(compositeRequests, salesforceUserId); + + return parseResponse(response.getResponseBody()); + + } + + /** + * Parse Response + * @param responseBody + * @return GetTaskDetailsFormatterDto + **/ + public GetTaskDetailsFormatterDto parseResponse(String responseBody) { + + Util util = new Util(); + JsonNode rootNode = util.getJsonNode(responseBody); + + JsonNode compositeResponse = rootNode.get("compositeResponse").get(0); + Integer statusCode = compositeResponse.get("httpStatusCode").asInt(); + + if (statusCode != 200 && statusCode != 201) { + String errorBody = compositeResponse.get("body").asText(); + + if (statusCode == 400) { + throw new CustomException( + new ParamErrorObject("l_ca_gatd_gsatd_pr_1", errorBody, Arrays.asList("invalid_account_id"))); + } + else { + throw new CustomException(new ErrorObject("l_ca_gatd_gsatd_pr_2", "something_went_wrong", errorBody)); + } + } + + JsonNode recordsNode = rootNode.get("compositeResponse").get(0).get("body").get("records"); + ; + + TaskEntity taskEntity = new TaskEntity(); + for (JsonNode recordNode : recordsNode) { + ObjectMapper mapper = new ObjectMapper(); + mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES); + SalesforceGetTasksListDto salesforceGetTasksListDto = mapper.convertValue(recordNode, + SalesforceGetTasksListDto.class); + taskEntity = salesforceGetTasksListDto.taskEntity(); + } + + GetTaskDetailsFormatterDto getTaskDetailsFormatterDto = new GetTaskDetailsFormatterDto(); + getTaskDetailsFormatterDto.setTaskDetail(taskEntity); + + return getTaskDetailsFormatterDto; + } + +} diff --git a/src/main/java/com/salessparrow/api/lib/crmActions/updateAccountTask/UpdateSalesforceAccountTask.java b/src/main/java/com/salessparrow/api/lib/crmActions/updateAccountTask/UpdateSalesforceAccountTask.java index 2834c1fc..141b358d 100644 --- a/src/main/java/com/salessparrow/api/lib/crmActions/updateAccountTask/UpdateSalesforceAccountTask.java +++ b/src/main/java/com/salessparrow/api/lib/crmActions/updateAccountTask/UpdateSalesforceAccountTask.java @@ -91,10 +91,10 @@ private void parseResponse(String updateTaskResponse) { if (statusCode == 400 || statusCode == 404) { throw new CustomException( - new ParamErrorObject("l_ua_uae_usae_pr_1", errorBody, Arrays.asList("invalid_task_id"))); + new ParamErrorObject("l_ua_uat_usat_pr_1", errorBody, Arrays.asList("invalid_task_id"))); } else { - throw new CustomException(new ErrorObject("l_ua_uae_usae_pr_2", "something_went_wrong", errorBody)); + throw new CustomException(new ErrorObject("l_ua_uat_usat_pr_2", "something_went_wrong", errorBody)); } } } diff --git a/src/main/java/com/salessparrow/api/lib/salesforce/dto/SalesforceGetTasksListDto.java b/src/main/java/com/salessparrow/api/lib/salesforce/dto/SalesforceGetTasksListDto.java index f8bfe670..10fc80ca 100644 --- a/src/main/java/com/salessparrow/api/lib/salesforce/dto/SalesforceGetTasksListDto.java +++ b/src/main/java/com/salessparrow/api/lib/salesforce/dto/SalesforceGetTasksListDto.java @@ -39,6 +39,8 @@ private class Owner { private String name; + private String id; + } public TaskEntity taskEntity() { @@ -49,6 +51,7 @@ public TaskEntity taskEntity() { taskEntity.setCreatorName(this.createdBy.name); taskEntity.setDescription(this.description); taskEntity.setCrmOrganizationUserName(this.owner.name); + taskEntity.setCrmOrganizationUserId(this.owner.id); taskEntity.setLastModifiedTime(this.lastModifiedDate); String dueDate = util.getDateFormatFromDatetime(this.activityDate); diff --git a/src/main/java/com/salessparrow/api/lib/salesforce/helper/SalesforceQueryBuilder.java b/src/main/java/com/salessparrow/api/lib/salesforce/helper/SalesforceQueryBuilder.java index 21dfbbb6..4b496cb2 100644 --- a/src/main/java/com/salessparrow/api/lib/salesforce/helper/SalesforceQueryBuilder.java +++ b/src/main/java/com/salessparrow/api/lib/salesforce/helper/SalesforceQueryBuilder.java @@ -54,7 +54,7 @@ public String getAccountTasksQuery(String accountId) { accountId = Util.escapeSpecialChars(accountId); return Util.urlEncoder( - "SELECT Id, Description, ActivityDate, CreatedBy.Name, Owner.Name, LastModifiedDate FROM Task WHERE WhatId='" + "SELECT Id, Description, ActivityDate, CreatedBy.Name, Owner.Name, Owner.Id, LastModifiedDate FROM Task WHERE WhatId='" + accountId + "' ORDER BY LastModifiedDate DESC LIMIT 5"); } @@ -136,4 +136,12 @@ public String getAccountEventDetailsUrl(String eventId) { + eventId + "'"); } + public String getAccountTaskDetailsUrl(String taskId) { + taskId = Util.escapeSpecialChars(taskId); + + return Util.urlEncoder( + "SELECT Id, Description, ActivityDate, CreatedBy.Name, Owner.Name, Owner.Id, LastModifiedDate FROM Task WHERE Id = '" + + taskId + "'"); + } + } diff --git a/src/main/java/com/salessparrow/api/services/accountTask/GetAccountTaskDetailsService.java b/src/main/java/com/salessparrow/api/services/accountTask/GetAccountTaskDetailsService.java new file mode 100644 index 00000000..888efd91 --- /dev/null +++ b/src/main/java/com/salessparrow/api/services/accountTask/GetAccountTaskDetailsService.java @@ -0,0 +1,34 @@ +package com.salessparrow.api.services.accountTask; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import com.salessparrow.api.domain.User; +import com.salessparrow.api.dto.formatter.GetTaskDetailsFormatterDto; +import com.salessparrow.api.lib.crmActions.getAccountTaskDetails.GetAccountTaskDetailsFactory; + +import jakarta.servlet.http.HttpServletRequest; + +/** + * GetAccountTaskDetailsService is a service class for the getTaskDetails action for the + * CRM. + */ +@Service +public class GetAccountTaskDetailsService { + + @Autowired + private GetAccountTaskDetailsFactory getTaskDetailsFactory; + + /** + * Get the details of a task + * @param accountId + * @param taskId + * @return GetTaskDetailsFormatterDto + */ + public GetTaskDetailsFormatterDto getTaskDetails(HttpServletRequest request, String taskId) { + User currentUser = (User) request.getAttribute("current_user"); + + return getTaskDetailsFactory.getTaskDetails(currentUser, taskId); + } + +} diff --git a/src/test/java/com/salessparrow/api/functional/controllers/accountEventController/UpdateAccountEventTest.java b/src/test/java/com/salessparrow/api/functional/controllers/accountEventController/UpdateAccountEventTest.java index 1a1f035e..9b86179c 100644 --- a/src/test/java/com/salessparrow/api/functional/controllers/accountEventController/UpdateAccountEventTest.java +++ b/src/test/java/com/salessparrow/api/functional/controllers/accountEventController/UpdateAccountEventTest.java @@ -112,7 +112,9 @@ public void updateAccountEvent(Scenario testScenario) throws Exception { String expectedOutput = objectMapper.writeValueAsString(testScenario.getOutput()); String actualOutput = resultActions.andReturn().getResponse().getContentAsString(); - if (resultActions.andReturn().getResponse().getStatus() == 200) { + Integer responseStatus = resultActions.andReturn().getResponse().getStatus(); + + if (responseStatus == 200 || responseStatus == 201 || responseStatus == 204) { if (expectedOutput.equals("{}")) { expectedOutput = ""; } diff --git a/src/test/java/com/salessparrow/api/functional/controllers/accountTaskController/GetAccountTaskDetailsTest.java b/src/test/java/com/salessparrow/api/functional/controllers/accountTaskController/GetAccountTaskDetailsTest.java new file mode 100644 index 00000000..bd814c91 --- /dev/null +++ b/src/test/java/com/salessparrow/api/functional/controllers/accountTaskController/GetAccountTaskDetailsTest.java @@ -0,0 +1,137 @@ +package com.salessparrow.api.functional.controllers.accountTaskController; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.when; + +import java.io.IOException; +import java.util.List; +import java.util.stream.Stream; + +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.mock.mockito.MockBean; +import org.springframework.context.annotation.Import; +import org.springframework.core.io.DefaultResourceLoader; +import org.springframework.core.io.Resource; +import org.springframework.http.MediaType; +import org.springframework.test.context.web.WebAppConfiguration; +import org.springframework.test.web.servlet.MockMvc; +import org.springframework.test.web.servlet.ResultActions; +import org.springframework.test.web.servlet.request.MockMvcRequestBuilders; + +import com.fasterxml.jackson.core.type.TypeReference; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.github.dynamobee.exception.DynamobeeException; +import com.salessparrow.api.helper.Cleanup; +import com.salessparrow.api.helper.Common; +import com.salessparrow.api.helper.FixtureData; +import com.salessparrow.api.helper.LoadFixture; +import com.salessparrow.api.helper.Scenario; +import com.salessparrow.api.helper.Setup; +import com.salessparrow.api.lib.globalConstants.CookieConstants; +import com.salessparrow.api.helper.Constants; + +import com.salessparrow.api.lib.httpLib.HttpClient.HttpResponse; +import com.salessparrow.api.lib.salesforce.helper.MakeCompositeRequest; + +import jakarta.servlet.http.Cookie; + +@SpringBootTest +@AutoConfigureMockMvc +@WebAppConfiguration +@Import({ Setup.class, Cleanup.class, Common.class, LoadFixture.class }) +public class GetAccountTaskDetailsTest { + + @Autowired + private MockMvc mockMvc; + + @Autowired + private Common common; + + @Autowired + private LoadFixture loadFixture; + + @Autowired + private Setup setup; + + @Autowired + private Cleanup cleanup; + + @MockBean + private MakeCompositeRequest makeCompositeRequestMock; + + @BeforeEach + public void setUp() throws DynamobeeException, IOException { + setup.perform(); + } + + @AfterEach + public void tearDown() { + cleanup.perform(); + } + + @ParameterizedTest + @MethodSource("testScenariosProvider") + public void getAccountTaskDetails(Scenario testScenario) throws Exception { + // Load fixture data + String currentFunctionName = new Object() { + }.getClass().getEnclosingMethod().getName(); + FixtureData fixtureData = common.loadFixture( + "classpath:fixtures/functional/controllers/accountTaskController/getAccountTaskDetails.fixtures.json", + currentFunctionName); + loadFixture.perform(fixtureData); + + // Read data from the scenario + ObjectMapper objectMapper = new ObjectMapper(); + String cookieValue = Constants.SALESFORCE_ACTIVE_USER_COOKIE_VALUE; + String accountId = (String) testScenario.getInput().get("accountId"); + String taskId = (String) testScenario.getInput().get("taskId"); + + // Prepare mock responses + HttpResponse getTasksListMockResponse = new HttpResponse(); + getTasksListMockResponse + .setResponseBody(objectMapper.writeValueAsString(testScenario.getMocks().get("makeCompositeRequest"))); + when(makeCompositeRequestMock.makePostRequest(any(), any())).thenReturn(getTasksListMockResponse); + + // Perform the request + String url = "/api/v1/accounts/" + accountId + "/tasks/" + taskId; + + ResultActions resultActions = mockMvc.perform(MockMvcRequestBuilders.get(url) + .cookie(new Cookie(CookieConstants.USER_LOGIN_COOKIE_NAME, cookieValue)) + .contentType(MediaType.APPLICATION_JSON)); + + // Check the response + String expectedOutput = objectMapper.writeValueAsString(testScenario.getOutput()); + String actualOutput = resultActions.andReturn().getResponse().getContentAsString(); + + if (resultActions.andReturn().getResponse().getStatus() == 200) { + if (expectedOutput.equals("{}")) { + expectedOutput = ""; + } + assertEquals(expectedOutput, actualOutput); + } + else { + common.compareErrors(testScenario, actualOutput); + } + } + + static Stream testScenariosProvider() throws IOException { + List testScenarios = loadScenarios(); + return testScenarios.stream(); + } + + private static List loadScenarios() throws IOException { + String scenariosPath = "classpath:data/functional/controllers/accountTaskController/getAccountTaskDetails.scenarios.json"; + Resource resource = new DefaultResourceLoader().getResource(scenariosPath); + ObjectMapper objectMapper = new ObjectMapper(); + return objectMapper.readValue(resource.getInputStream(), new TypeReference>() { + }); + } + +} diff --git a/src/test/java/com/salessparrow/api/functional/controllers/accountTaskController/UpdateAccountTaskTest.java b/src/test/java/com/salessparrow/api/functional/controllers/accountTaskController/UpdateAccountTaskTest.java new file mode 100644 index 00000000..b7f6a1c2 --- /dev/null +++ b/src/test/java/com/salessparrow/api/functional/controllers/accountTaskController/UpdateAccountTaskTest.java @@ -0,0 +1,141 @@ +package com.salessparrow.api.functional.controllers.accountTaskController; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.when; + +import java.io.IOException; +import java.util.List; +import java.util.stream.Stream; + +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.mock.mockito.MockBean; +import org.springframework.context.annotation.Import; +import org.springframework.core.io.DefaultResourceLoader; +import org.springframework.core.io.Resource; +import org.springframework.http.MediaType; +import org.springframework.test.context.web.WebAppConfiguration; +import org.springframework.test.web.servlet.MockMvc; +import org.springframework.test.web.servlet.ResultActions; +import org.springframework.test.web.servlet.request.MockMvcRequestBuilders; + +import com.fasterxml.jackson.core.type.TypeReference; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.github.dynamobee.exception.DynamobeeException; +import com.salessparrow.api.helper.Cleanup; +import com.salessparrow.api.helper.Common; +import com.salessparrow.api.helper.Constants; +import com.salessparrow.api.helper.FixtureData; +import com.salessparrow.api.helper.LoadFixture; +import com.salessparrow.api.helper.Scenario; +import com.salessparrow.api.helper.Setup; +import com.salessparrow.api.lib.globalConstants.CookieConstants; +import com.salessparrow.api.lib.httpLib.HttpClient.HttpResponse; +import com.salessparrow.api.lib.salesforce.helper.MakeCompositeRequest; + +import jakarta.servlet.http.Cookie; + +@SpringBootTest +@AutoConfigureMockMvc +@WebAppConfiguration +@Import({ Setup.class, Cleanup.class, Common.class, LoadFixture.class }) +public class UpdateAccountTaskTest { + + @Autowired + private MockMvc mockMvc; + + @Autowired + private Common common; + + @Autowired + private LoadFixture loadFixture; + + @Autowired + private Setup setup; + + @Autowired + private Cleanup cleanup; + + @MockBean + private MakeCompositeRequest makeCompositeRequestMock; + + @BeforeEach + public void setUp() throws DynamobeeException { + setup.perform(); + } + + @AfterEach + public void tearDown() { + cleanup.perform(); + } + + @ParameterizedTest + @MethodSource("testScenariosProvider") + public void updateAccountTask(Scenario testScenario) throws Exception { + + // Load fixture data + String currentFunctionName = new Object() { + }.getClass().getEnclosingMethod().getName(); + FixtureData fixtureData = common.loadFixture( + "classpath:fixtures/functional/controllers/accountTaskController/updateAccountTask.fixtures.json", + currentFunctionName); + loadFixture.perform(fixtureData); + + // Read data from the scenario + ObjectMapper objectMapper = new ObjectMapper(); + String cookieValue = Constants.SALESFORCE_ACTIVE_USER_COOKIE_VALUE; + String accountId = (String) testScenario.getInput().get("accountId"); + String taskId = (String) testScenario.getInput().get("taskId"); + + // Prepare mock responses + HttpResponse mockResponse = new HttpResponse(); + mockResponse + .setResponseBody(objectMapper.writeValueAsString(testScenario.getMocks().get("makeCompositeRequest"))); + when(makeCompositeRequestMock.makePostRequest(any(), any())).thenReturn(mockResponse); + + // Perform the request + String requestBody = objectMapper.writeValueAsString(testScenario.getInput().get("body")); + String url = "/api/v1/accounts/" + accountId + "/tasks/" + taskId; + + ResultActions resultActions = mockMvc.perform(MockMvcRequestBuilders.put(url) + .cookie(new Cookie(CookieConstants.USER_LOGIN_COOKIE_NAME, cookieValue)) + .content(requestBody) + .contentType(MediaType.APPLICATION_JSON)); + + // Check the response + String expectedOutput = objectMapper.writeValueAsString(testScenario.getOutput()); + String actualOutput = resultActions.andReturn().getResponse().getContentAsString(); + + Integer responseStatus = resultActions.andReturn().getResponse().getStatus(); + + if (responseStatus == 200 || responseStatus == 201 || responseStatus == 204) { + if (expectedOutput.equals("{}")) { + expectedOutput = ""; + } + assertEquals(expectedOutput, actualOutput); + } + else { + common.compareErrors(testScenario, actualOutput); + } + } + + static Stream testScenariosProvider() throws IOException { + List testScenarios = loadScenarios(); + return testScenarios.stream(); + } + + private static List loadScenarios() throws IOException { + String scenariosPath = "classpath:data/functional/controllers/accountTaskController/updateAccountTask.scenarios.json"; + Resource resource = new DefaultResourceLoader().getResource(scenariosPath); + ObjectMapper objectMapper = new ObjectMapper(); + return objectMapper.readValue(resource.getInputStream(), new TypeReference>() { + }); + } + +} diff --git a/src/test/resources/data/functional/controllers/accountEventController/getAccountEventDetails.scenarios.json b/src/test/resources/data/functional/controllers/accountEventController/getAccountEventDetails.scenarios.json index 5a1969bc..1d536fd0 100644 --- a/src/test/resources/data/functional/controllers/accountEventController/getAccountEventDetails.scenarios.json +++ b/src/test/resources/data/functional/controllers/accountEventController/getAccountEventDetails.scenarios.json @@ -55,8 +55,8 @@ { "description": "should return error response when event id is invalid", "input": { - "account_id": "0011e00000bWSxdAAG", - "event_id": "invalid_event_id" + "accountId": "0011e00000bWSxdAAG", + "eventId": "invalid_event_id" }, "mocks":{ "makeCompositeRequest":{ diff --git a/src/test/resources/data/functional/controllers/accountTaskController/getAccountTaskDetails.scenarios.json b/src/test/resources/data/functional/controllers/accountTaskController/getAccountTaskDetails.scenarios.json new file mode 100644 index 00000000..3853a927 --- /dev/null +++ b/src/test/resources/data/functional/controllers/accountTaskController/getAccountTaskDetails.scenarios.json @@ -0,0 +1,95 @@ +[ + { + "description": "Should return the task details for a given task id", + "input": { + "accountId": "0011e00000bWSxdAAG", + "taskId": "00T1e000007mGYaEAM" + }, + "mocks": { + "makeCompositeRequest": { + "compositeResponse": [ + { + "body": { + "totalSize": 1, + "done": true, + "records": [ + { + "attributes": { + "type": "Task", + "url": "/services/data/v58.0/sobjects/Task/00T1e000007mGYaEAM" + }, + "Id": "00T1e000007mGYaEAM", + "Description": "Task documentation", + "ActivityDate": "2023-12-01", + "CreatedBy": { + "attributes": { + "type": "User", + "url": "/services/data/v58.0/sobjects/User/0055i00000AUxQHAA1" + }, + "Name": "Name2" + }, + "Owner": { + "attributes": { + "type": "Name", + "url": "/services/data/v58.0/sobjects/User/0051e0000047G03AAE" + }, + "Name": "Name1", + "Id":"0055i00000AUxQHAA1" + }, + "LastModifiedDate": "2023-08-24T12:16:05.000+0000" + } + ] + }, + "httpHeaders": {}, + "httpStatusCode": 200, + "referenceId": "getTaskDetails" + } + ] + } + }, + "output": { + "task_detail": { + "id": "00T1e000007mGYaEAM", + "creator_name": "Name2", + "description": "Task documentation", + "due_date": "2023-12-01", + "crm_organization_user_name": "Name1", + "crm_organization_user_id": "0055i00000AUxQHAA1", + "last_modified_time": "2023-08-24T12:16:05.000+00:00" + } + } + }, + { + "description": "should return error response when task id is invalid", + "input": { + "account_id": "0011e00000bWSxdAAG", + "task_id": "invalid_task_id" + }, + "mocks":{ + "makeCompositeRequest":{ + "compositeResponse": [ + { + "body": [ + { + "message": "\nLastModifiedDate FROM Task WHERE Id='invalid_task_id'\n ^\nERROR at Row:1:Column:105\ninvalid ID field: invalid_task_id", + "errorCode": "INVALID_QUERY_FILTER_OPERATOR" + } + ], + "httpHeaders": {}, + "httpStatusCode": 400, + "referenceId": "GetTaskDetails" + } + ] + } + }, + "output": { + "http_code": 400, + "message": "At least one parameter is invalid or missing.", + "code": "INVALID_PARAMS", + "internal_error_identifier": "l_ca_gatd_gsatd_pr_1", + "param_errors": [ + "invalid_account_id" + ] + } + } +] \ No newline at end of file diff --git a/src/test/resources/data/functional/controllers/accountTaskController/getAccountTasksList.scenarios.json b/src/test/resources/data/functional/controllers/accountTaskController/getAccountTasksList.scenarios.json index 0d1e6afc..07f557a9 100644 --- a/src/test/resources/data/functional/controllers/accountTaskController/getAccountTasksList.scenarios.json +++ b/src/test/resources/data/functional/controllers/accountTaskController/getAccountTasksList.scenarios.json @@ -32,7 +32,8 @@ "type": "Name", "url": "/services/data/v58.0/sobjects/User/0051e0000047G03AAE" }, - "Name": "Name1" + "Name": "Name1", + "Id":"0051e0000047G03AAE" }, "LastModifiedDate": "2023-08-24T12:16:05.000+0000" }, @@ -56,7 +57,8 @@ "type": "Name", "url": "/services/data/v58.0/sobjects/User/0051e0000047G03AAE" }, - "Name": "Name1" + "Name": "Name1", + "Id":"0051e0000047G03AAE" }, "LastModifiedDate": "2023-08-24T12:09:51.000+0000" }, @@ -80,7 +82,8 @@ "type": "Name", "url": "/services/data/v58.0/sobjects/User/0051e0000047G03AAE" }, - "Name": "Name1" + "Name": "Name1", + "Id":"0051e0000047G03AAE" }, "LastModifiedDate": "2023-08-23T13:11:03.000+0000" }, @@ -104,7 +107,8 @@ "type": "Name", "url": "/services/data/v58.0/sobjects/User/0051e0000047G03AAE" }, - "Name": "Name1" + "Name": "Name1", + "Id":"0051e0000047G03AAE" }, "LastModifiedDate": "2023-08-23T07:49:23.000+0000" }, @@ -128,7 +132,8 @@ "type": "Name", "url": "/services/data/v58.0/sobjects/User/0051e0000047G03AAE" }, - "Name": "Name1" + "Name": "Name1", + "Id":"0051e0000047G03AAE" }, "LastModifiedDate": "2023-08-23T07:10:53.000+0000" } @@ -156,6 +161,7 @@ "description": "Update remaining documentations", "due_date": "2023-12-01", "crm_organization_user_name": "Name1", + "crm_organization_user_id": "0051e0000047G03AAE", "last_modified_time": "2023-08-24T12:09:51.000+00:00" }, "00T1e000007mEk9EAE": { @@ -164,6 +170,7 @@ "description": "Update remaining documentations", "due_date": "2023-12-01", "crm_organization_user_name": "Name1", + "crm_organization_user_id": "0051e0000047G03AAE", "last_modified_time": "2023-08-23T07:49:23.000+00:00" }, "00T1e000007mEfuEAE": { @@ -172,6 +179,7 @@ "description": "Update remaining documentations", "due_date": "2023-12-01", "crm_organization_user_name": "Name1", + "crm_organization_user_id": "0051e0000047G03AAE", "last_modified_time": "2023-08-23T07:10:53.000+00:00" }, "00T1e000007mF0oEAE": { @@ -180,6 +188,7 @@ "description": "Update remaining documentations", "due_date": "2023-12-01", "crm_organization_user_name": "Name1", + "crm_organization_user_id": "0051e0000047G03AAE", "last_modified_time": "2023-08-23T13:11:03.000+00:00" }, "00T1e000007mGYaEAM": { @@ -188,6 +197,7 @@ "description": "Update remaining documentations", "due_date": "2023-12-01", "crm_organization_user_name": "Name1", + "crm_organization_user_id": "0051e0000047G03AAE", "last_modified_time": "2023-08-24T12:16:05.000+00:00" } } diff --git a/src/test/resources/data/functional/controllers/accountTaskController/updateAccountTask.scenarios.json b/src/test/resources/data/functional/controllers/accountTaskController/updateAccountTask.scenarios.json new file mode 100644 index 00000000..fa0533bb --- /dev/null +++ b/src/test/resources/data/functional/controllers/accountTaskController/updateAccountTask.scenarios.json @@ -0,0 +1,65 @@ +[ + { + "description": "Should successfully update the task for given task id", + "input": { + "body": { + "crm_organization_user_id":"0011e00000bWSxdAA1", + "description":"Update remaining documentations", + "due_date":"2023-12-01" + }, + "accountId": "0011e00000bWSxdAAG", + "taskId":"0691e000001X1yTAAS" + }, + "mocks": { + "makeCompositeRequest": { + "compositeResponse": [ + { + "body": null, + "httpHeaders": {}, + "httpStatusCode": 200, + "referenceId": "UpdateTask" + } + ] + } + }, + "output": {} + }, + { + "description": "should return error response when task id is invalid", + "input": { + "body": { + "crm_organization_user_id":"0011e00000bWSxdAA1", + "description":"Update remaining documentations", + "due_date":"2023-12-01" + }, + "accountId": "0011e00000bWSxdAAG", + "taskId":"invalidTaskId" + }, + "mocks": { + "makeCompositeRequest": { + "compositeResponse": [ + { + "body": [ + { + "errorCode": "NOT_FOUND", + "message": "Provided external ID field does not exist or is not accessible: INVALID_TASK_ID" + } + ], + "httpHeaders": {}, + "httpStatusCode": 404, + "referenceId": "UpdateTask" + } + ] + } + }, + "output": { + "http_code": 400, + "message": "At least one parameter is invalid or missing.", + "code": "INVALID_PARAMS", + "internal_error_identifier": "l_ua_uat_usat_pr_1", + "param_errors": [ + "invalid_task_id" + ] + } + } + ] \ No newline at end of file diff --git a/src/test/resources/fixtures/functional/controllers/accountTaskController/getAccountTaskDetails.fixtures.json b/src/test/resources/fixtures/functional/controllers/accountTaskController/getAccountTaskDetails.fixtures.json new file mode 100644 index 00000000..ec2bddc0 --- /dev/null +++ b/src/test/resources/fixtures/functional/controllers/accountTaskController/getAccountTaskDetails.fixtures.json @@ -0,0 +1,14 @@ +{ + "getAccountTaskDetails": { + "salesforce_users": [ + { + "filepath": "classpath:fixtures/common/repositories/salesforceUser/ActiveSalesforceUser.json" + } + ], + "salesforce_oauth_tokens": [ + { + "filepath": "classpath:fixtures/common/repositories/salesforceOauthToken/ActiveSalesforceOauthToken.json" + } + ] + } +} \ No newline at end of file diff --git a/src/test/resources/fixtures/functional/controllers/accountTaskController/updateAccountTask.fixtures.json b/src/test/resources/fixtures/functional/controllers/accountTaskController/updateAccountTask.fixtures.json new file mode 100644 index 00000000..f95030fd --- /dev/null +++ b/src/test/resources/fixtures/functional/controllers/accountTaskController/updateAccountTask.fixtures.json @@ -0,0 +1,14 @@ +{ + "updateAccountTask": { + "salesforce_users": [ + { + "filepath": "classpath:fixtures/common/repositories/salesforceUser/ActiveSalesforceUser.json" + } + ], + "salesforce_oauth_tokens": [ + { + "filepath": "classpath:fixtures/common/repositories/salesforceOauthToken/ActiveSalesforceOauthToken.json" + } + ] + } +} \ No newline at end of file From 3a8c91baa0d29e50bfeb5d5430beda5d35ce8626 Mon Sep 17 00:00:00 2001 From: Raj Shah Date: Thu, 5 Oct 2023 15:57:51 +0530 Subject: [PATCH 18/36] Added update note api --- .../api/config/SecurityConfig.java | 17 ++- .../controllers/AccountNoteController.java | 20 +++- .../{NoteDto.java => AccountNoteDto.java} | 2 +- .../CreateSalesforceAccountEvent.java | 3 +- .../createAccountNote/CreateNoteFactory.java | 4 +- .../CreateNoteInterface.java | 4 +- .../CreateSalesforceNote.java | 25 +--- .../UpdateSalesforceAccountEvent.java | 3 +- .../UpdateAccountNoteFactory.java | 43 +++++++ .../UpdateAccountNoteInterface.java | 16 +++ .../UpdateSalesforceAccountNote.java | 110 ++++++++++++++++++ .../UpdateAccountTaskFactory.java | 2 +- .../UpdateSalesforceAccountTask.java | 2 +- .../globalConstants/SalesforceConstants.java | 14 ++- .../CreateAccountNoteService.java | 4 +- .../UpdateAccountNoteService.java | 42 +++++++ 16 files changed, 277 insertions(+), 34 deletions(-) rename src/main/java/com/salessparrow/api/dto/requestMapper/{NoteDto.java => AccountNoteDto.java} (90%) create mode 100644 src/main/java/com/salessparrow/api/lib/crmActions/updateAccountNote/UpdateAccountNoteFactory.java create mode 100644 src/main/java/com/salessparrow/api/lib/crmActions/updateAccountNote/UpdateAccountNoteInterface.java create mode 100644 src/main/java/com/salessparrow/api/lib/crmActions/updateAccountNote/UpdateSalesforceAccountNote.java create mode 100644 src/main/java/com/salessparrow/api/services/accountNotes/UpdateAccountNoteService.java diff --git a/src/main/java/com/salessparrow/api/config/SecurityConfig.java b/src/main/java/com/salessparrow/api/config/SecurityConfig.java index d8d55c72..8f98d886 100644 --- a/src/main/java/com/salessparrow/api/config/SecurityConfig.java +++ b/src/main/java/com/salessparrow/api/config/SecurityConfig.java @@ -2,9 +2,12 @@ import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; +import org.springframework.http.HttpStatus; import org.springframework.security.config.annotation.web.builders.HttpSecurity; import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; +import org.springframework.security.web.AuthenticationEntryPoint; import org.springframework.security.web.SecurityFilterChain; +import org.springframework.security.web.authentication.HttpStatusEntryPoint; import org.springframework.security.web.header.writers.XXssProtectionHeaderWriter; import org.springframework.security.web.header.writers.ReferrerPolicyHeaderWriter.ReferrerPolicy; @@ -17,7 +20,10 @@ public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Excepti http // disable authorization for all routes - .authorizeHttpRequests(authorizeRequests -> authorizeRequests.anyRequest().permitAll()) + .authorizeHttpRequests(authorizeRequests -> authorizeRequests.requestMatchers("/api/v1/**") + .permitAll() + .anyRequest() + .authenticated()) // Disable authentication for all routes .httpBasic(httpBasic -> httpBasic.disable()) // Disable form login @@ -70,6 +76,9 @@ public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Excepti hsts -> hsts.includeSubDomains(true).preload(true).maxAgeInSeconds(31536000)) .xssProtection(xss -> xss.headerValue(XXssProtectionHeaderWriter.HeaderValue.ENABLED_MODE_BLOCK)) .referrerPolicy(referrer -> referrer.policy(ReferrerPolicy.SAME_ORIGIN))); + // .exceptionHandling( + // exceptionHandling -> + // exceptionHandling.authenticationEntryPoint(authenticationEntryPoint())); // http redirect to https is handled by the reverse proxy server (nginx). So no // need to handle it here. @@ -77,4 +86,10 @@ public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Excepti return http.build(); } + @Bean + public AuthenticationEntryPoint authenticationEntryPoint() { + // Use HttpStatusEntryPoint to return a 404 response for invalid routes + return new HttpStatusEntryPoint(HttpStatus.NOT_FOUND); + } + } diff --git a/src/main/java/com/salessparrow/api/controllers/AccountNoteController.java b/src/main/java/com/salessparrow/api/controllers/AccountNoteController.java index ff6d4d6c..c2ef4167 100644 --- a/src/main/java/com/salessparrow/api/controllers/AccountNoteController.java +++ b/src/main/java/com/salessparrow/api/controllers/AccountNoteController.java @@ -2,12 +2,14 @@ import org.slf4j.Logger; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.DeleteMapping; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.PutMapping; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; @@ -15,11 +17,12 @@ import com.salessparrow.api.dto.formatter.CreateNoteFormatterDto; import com.salessparrow.api.dto.formatter.GetNoteDetailsFormatterDto; import com.salessparrow.api.dto.formatter.GetNotesListFormatterDto; -import com.salessparrow.api.dto.requestMapper.NoteDto; +import com.salessparrow.api.dto.requestMapper.AccountNoteDto; import com.salessparrow.api.services.accountNotes.CreateAccountNoteService; import com.salessparrow.api.services.accountNotes.DeleteAccountNoteService; import com.salessparrow.api.services.accountNotes.GetAccountNoteDetailsService; import com.salessparrow.api.services.accountNotes.GetAccountNotesListService; +import com.salessparrow.api.services.accountNotes.UpdateAccountNoteService; import jakarta.servlet.http.HttpServletRequest; import jakarta.validation.Valid; @@ -43,9 +46,12 @@ public class AccountNoteController { @Autowired private DeleteAccountNoteService deleteAccountNoteService; + @Autowired + private UpdateAccountNoteService updateNoteService; + @PostMapping("") public ResponseEntity addNoteToAccount(HttpServletRequest request, - @PathVariable("account_id") String accountId, @Valid @RequestBody NoteDto note) { + @PathVariable("account_id") String accountId, @Valid @RequestBody AccountNoteDto note) { logger.info("Create Note request received"); CreateNoteFormatterDto createNoteFormatterDto = createNoteService.createNote(request, accountId, note); @@ -83,4 +89,14 @@ public ResponseEntity deleteNote(HttpServletRequest return ResponseEntity.noContent().build(); } + @PutMapping("/{note_id}") + public ResponseEntity updateNote(HttpServletRequest request, @PathVariable("account_id") String accountId, + @PathVariable("note_id") String noteId, @Valid @RequestBody AccountNoteDto accountNoteDto) { + logger.info("Update note request received"); + + updateNoteService.updateAccountNote(request, accountId, noteId, accountNoteDto); + + return ResponseEntity.status(HttpStatus.NO_CONTENT).build(); + } + } diff --git a/src/main/java/com/salessparrow/api/dto/requestMapper/NoteDto.java b/src/main/java/com/salessparrow/api/dto/requestMapper/AccountNoteDto.java similarity index 90% rename from src/main/java/com/salessparrow/api/dto/requestMapper/NoteDto.java rename to src/main/java/com/salessparrow/api/dto/requestMapper/AccountNoteDto.java index 44ca28f6..cfc24e53 100644 --- a/src/main/java/com/salessparrow/api/dto/requestMapper/NoteDto.java +++ b/src/main/java/com/salessparrow/api/dto/requestMapper/AccountNoteDto.java @@ -6,7 +6,7 @@ import lombok.Data; @Data -public class NoteDto { +public class AccountNoteDto { @NotBlank(message = "missing_text") @Length(max = 12000, message = "text_too_long") diff --git a/src/main/java/com/salessparrow/api/lib/crmActions/createAccountEvent/CreateSalesforceAccountEvent.java b/src/main/java/com/salessparrow/api/lib/crmActions/createAccountEvent/CreateSalesforceAccountEvent.java index 8d2f00c3..38c853ea 100644 --- a/src/main/java/com/salessparrow/api/lib/crmActions/createAccountEvent/CreateSalesforceAccountEvent.java +++ b/src/main/java/com/salessparrow/api/lib/crmActions/createAccountEvent/CreateSalesforceAccountEvent.java @@ -53,7 +53,8 @@ public CreateEventFormatterDto createEvent(User user, String accountId, CreateAc Util util = new Util(); String eventDescription = util.unEscapeSpecialCharactersForPlainText(createEventDto.getDescription()); - String eventSubject = util.getTrimmedString(eventDescription, salesforceConstants.salesforceSubjectLength()); + String eventSubject = util.getTrimmedString(eventDescription, + salesforceConstants.salesforceEventSubjectLength()); Map createEventBody = new HashMap(); createEventBody.put("Subject", eventSubject); diff --git a/src/main/java/com/salessparrow/api/lib/crmActions/createAccountNote/CreateNoteFactory.java b/src/main/java/com/salessparrow/api/lib/crmActions/createAccountNote/CreateNoteFactory.java index 64eff701..40eaff4d 100644 --- a/src/main/java/com/salessparrow/api/lib/crmActions/createAccountNote/CreateNoteFactory.java +++ b/src/main/java/com/salessparrow/api/lib/crmActions/createAccountNote/CreateNoteFactory.java @@ -8,7 +8,7 @@ import com.salessparrow.api.exception.CustomException; import com.salessparrow.api.lib.errorLib.ErrorObject; import com.salessparrow.api.lib.globalConstants.UserConstants; -import com.salessparrow.api.dto.requestMapper.NoteDto; +import com.salessparrow.api.dto.requestMapper.AccountNoteDto; /** * CreateNoteFactory is a factory class for the create note action for the CRM. @@ -25,7 +25,7 @@ public class CreateNoteFactory { * @param accountId * @return CreateNoteFormatterDto **/ - public CreateNoteFormatterDto createNote(SalesforceUser user, String accountId, NoteDto note) { + public CreateNoteFormatterDto createNote(SalesforceUser user, String accountId, AccountNoteDto note) { switch (user.getUserKind()) { case UserConstants.SALESFORCE_USER_KIND: diff --git a/src/main/java/com/salessparrow/api/lib/crmActions/createAccountNote/CreateNoteInterface.java b/src/main/java/com/salessparrow/api/lib/crmActions/createAccountNote/CreateNoteInterface.java index 614274ae..f5526072 100644 --- a/src/main/java/com/salessparrow/api/lib/crmActions/createAccountNote/CreateNoteInterface.java +++ b/src/main/java/com/salessparrow/api/lib/crmActions/createAccountNote/CreateNoteInterface.java @@ -4,7 +4,7 @@ import com.salessparrow.api.domain.SalesforceUser; import com.salessparrow.api.dto.formatter.CreateNoteFormatterDto; -import com.salessparrow.api.dto.requestMapper.NoteDto; +import com.salessparrow.api.dto.requestMapper.AccountNoteDto; /** * CreateNoteInterface is an interface for the create note action for the CRM. @@ -12,6 +12,6 @@ @Component public interface CreateNoteInterface { - public CreateNoteFormatterDto createNote(SalesforceUser user, String accountId, NoteDto note); + public CreateNoteFormatterDto createNote(SalesforceUser user, String accountId, AccountNoteDto note); } diff --git a/src/main/java/com/salessparrow/api/lib/crmActions/createAccountNote/CreateSalesforceNote.java b/src/main/java/com/salessparrow/api/lib/crmActions/createAccountNote/CreateSalesforceNote.java index 5e06f69e..3bc22745 100644 --- a/src/main/java/com/salessparrow/api/lib/crmActions/createAccountNote/CreateSalesforceNote.java +++ b/src/main/java/com/salessparrow/api/lib/crmActions/createAccountNote/CreateSalesforceNote.java @@ -16,7 +16,7 @@ import com.salessparrow.api.domain.SalesforceUser; import com.salessparrow.api.dto.formatter.CreateNoteFormatterDto; import com.salessparrow.api.exception.CustomException; -import com.salessparrow.api.dto.requestMapper.NoteDto; +import com.salessparrow.api.dto.requestMapper.AccountNoteDto; import com.salessparrow.api.lib.Base64Helper; import com.salessparrow.api.lib.Util; import com.salessparrow.api.lib.errorLib.ErrorObject; @@ -51,12 +51,15 @@ public class CreateSalesforceNote implements CreateNoteInterface { * @param note * @return CreateNoteFormatterDto */ - public CreateNoteFormatterDto createNote(SalesforceUser user, String accountId, NoteDto note) { + public CreateNoteFormatterDto createNote(SalesforceUser user, String accountId, AccountNoteDto note) { String salesforceUserId = user.getExternalUserId(); Util util = new Util(); String noteContent = note.getText(); - String noteTitle = getNoteTitleFromContent(noteContent); + String unEscapeNoteContent = util.unEscapeSpecialCharactersForPlainText(noteContent); + String noteTitle = util.getTrimmedString(unEscapeNoteContent, + salesforceConstants.salesforceContentNoteTitleLength()); + noteContent = util.replaceNewLineWithBreak(noteContent); String encodedNoteContent = base64Helper.base64Encode(noteContent); @@ -124,20 +127,4 @@ private CreateNoteFormatterDto parseResponse(String createNoteResponse) { return createNoteFormatterDto; } - /** - * Get the first 50 characters of the note content. - * @param note - note dto - * @return String - */ - private String getNoteTitleFromContent(String noteContent) { - Util util = new Util(); - noteContent = util.unEscapeSpecialCharactersForPlainText(noteContent); - - if (noteContent.length() < 50) { - return noteContent; - } - - return noteContent.substring(0, 50); - } - } diff --git a/src/main/java/com/salessparrow/api/lib/crmActions/updateAccountEvent/UpdateSalesforceAccountEvent.java b/src/main/java/com/salessparrow/api/lib/crmActions/updateAccountEvent/UpdateSalesforceAccountEvent.java index 82f68769..947d9a34 100644 --- a/src/main/java/com/salessparrow/api/lib/crmActions/updateAccountEvent/UpdateSalesforceAccountEvent.java +++ b/src/main/java/com/salessparrow/api/lib/crmActions/updateAccountEvent/UpdateSalesforceAccountEvent.java @@ -51,7 +51,8 @@ public void updateEvent(User user, String accountId, String eventId, UpdateAccou Util util = new Util(); String eventDescription = util.unEscapeSpecialCharactersForPlainText(updateEventDto.getDescription()); - String eventSubject = util.getTrimmedString(eventDescription, salesforceConstants.salesforceSubjectLength()); + String eventSubject = util.getTrimmedString(eventDescription, + salesforceConstants.salesforceEventSubjectLength()); Map updateEventBody = new HashMap(); updateEventBody.put("Subject", eventSubject); diff --git a/src/main/java/com/salessparrow/api/lib/crmActions/updateAccountNote/UpdateAccountNoteFactory.java b/src/main/java/com/salessparrow/api/lib/crmActions/updateAccountNote/UpdateAccountNoteFactory.java new file mode 100644 index 00000000..3f08cd00 --- /dev/null +++ b/src/main/java/com/salessparrow/api/lib/crmActions/updateAccountNote/UpdateAccountNoteFactory.java @@ -0,0 +1,43 @@ +package com.salessparrow.api.lib.crmActions.updateAccountNote; + +import org.slf4j.Logger; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +import com.salessparrow.api.domain.User; +import com.salessparrow.api.dto.requestMapper.AccountNoteDto; +import com.salessparrow.api.exception.CustomException; +import com.salessparrow.api.lib.errorLib.ErrorObject; +import com.salessparrow.api.lib.globalConstants.UserConstants; + +/** + * UpdateAccountNoteFactory is a factory class for the update note action for the CRM. + */ +@Component +public class UpdateAccountNoteFactory { + + private Logger logger = org.slf4j.LoggerFactory.getLogger(UpdateAccountNoteFactory.class); + + @Autowired + private UpdateSalesforceAccountNote updateSalesforceNote; + + /** + * Update a note for a given account + * @param user + * @param accountId + * @return void + **/ + public void updateNote(User user, String accountId, String noteId, AccountNoteDto accountNoteDto) { + logger.info("Update Note Factory started"); + + switch (user.getUserKind()) { + case UserConstants.SALESFORCE_USER_KIND: + updateSalesforceNote.updateNote(user, accountId, noteId, accountNoteDto); + return; + default: + throw new CustomException( + new ErrorObject("l_ua_uan_uanf_uan_1", "something_went_wrong", "Invalid user kind.")); + } + } + +} diff --git a/src/main/java/com/salessparrow/api/lib/crmActions/updateAccountNote/UpdateAccountNoteInterface.java b/src/main/java/com/salessparrow/api/lib/crmActions/updateAccountNote/UpdateAccountNoteInterface.java new file mode 100644 index 00000000..cd872529 --- /dev/null +++ b/src/main/java/com/salessparrow/api/lib/crmActions/updateAccountNote/UpdateAccountNoteInterface.java @@ -0,0 +1,16 @@ +package com.salessparrow.api.lib.crmActions.updateAccountNote; + +import org.springframework.stereotype.Component; + +import com.salessparrow.api.domain.User; +import com.salessparrow.api.dto.requestMapper.AccountNoteDto; + +/** + * UpdateAccountNoteInterface is an interface for the update note action for the CRM. + */ +@Component +public interface UpdateAccountNoteInterface { + + public void updateNote(User user, String accountId, String noteId, AccountNoteDto noteDto); + +} diff --git a/src/main/java/com/salessparrow/api/lib/crmActions/updateAccountNote/UpdateSalesforceAccountNote.java b/src/main/java/com/salessparrow/api/lib/crmActions/updateAccountNote/UpdateSalesforceAccountNote.java new file mode 100644 index 00000000..b5d7a89e --- /dev/null +++ b/src/main/java/com/salessparrow/api/lib/crmActions/updateAccountNote/UpdateSalesforceAccountNote.java @@ -0,0 +1,110 @@ +package com.salessparrow.api.lib.crmActions.updateAccountNote; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.slf4j.Logger; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +import com.fasterxml.jackson.databind.JsonNode; +import com.salessparrow.api.domain.User; +import com.salessparrow.api.dto.requestMapper.AccountNoteDto; +import com.salessparrow.api.exception.CustomException; +import com.salessparrow.api.lib.Base64Helper; +import com.salessparrow.api.lib.Util; +import com.salessparrow.api.lib.errorLib.ErrorObject; +import com.salessparrow.api.lib.errorLib.ParamErrorObject; +import com.salessparrow.api.lib.globalConstants.SalesforceConstants; +import com.salessparrow.api.lib.httpLib.HttpClient; +import com.salessparrow.api.lib.salesforce.dto.CompositeRequestDto; +import com.salessparrow.api.lib.salesforce.helper.MakeCompositeRequest; + +/** + * UpdateSalesforceAccountNote is a class that updates a note for an account in + * Salesforce. + */ +@Component +public class UpdateSalesforceAccountNote implements UpdateAccountNoteInterface { + + private Logger logger = org.slf4j.LoggerFactory.getLogger(UpdateSalesforceAccountNote.class); + + @Autowired + private SalesforceConstants salesforceConstants; + + @Autowired + private MakeCompositeRequest makeCompositeRequest; + + @Autowired + private Base64Helper base64Helper; + + /** + * Update a note for a given account. + * @param user + * @param accountId + * @param accountNoteDto + * @param noteId + * @return void + */ + public void updateNote(User user, String accountId, String noteId, AccountNoteDto accountNoteDto) { + logger.info("Update Salesforce Note started"); + String salesforceUserId = user.getExternalUserId(); + + Util util = new Util(); + + String noteContent = accountNoteDto.getText(); + String unEscapeNoteContent = util.unEscapeSpecialCharactersForPlainText(noteContent); + String noteTitle = util.getTrimmedString(unEscapeNoteContent, + salesforceConstants.salesforceContentNoteTitleLength()); + + noteContent = util.replaceNewLineWithBreak(noteContent); + String encodedNoteContent = base64Helper.base64Encode(noteContent); + + Map updateNoteBody = new HashMap(); + updateNoteBody.put("Title", noteTitle); + updateNoteBody.put("Content", encodedNoteContent); + + CompositeRequestDto updateNoteCompositeRequestDto = new CompositeRequestDto("PATCH", + salesforceConstants.salesforceUpdateNoteUrl(noteId), "UpdateNote", updateNoteBody); + + List compositeRequests = new ArrayList(); + compositeRequests.add(updateNoteCompositeRequestDto); + + HttpClient.HttpResponse response = makeCompositeRequest.makePostRequest(compositeRequests, salesforceUserId); + + parseResponse(response.getResponseBody()); + } + + /** + * Parse the response from Salesforce. + * @param updateNoteResponse + * @return void + */ + private void parseResponse(String updateNoteResponse) { + logger.info("Parsing the response from Salesforce"); + + Util util = new Util(); + JsonNode rootNode = util.getJsonNode(updateNoteResponse); + + JsonNode compositeResponse = rootNode.get("compositeResponse").get(0); + Integer statusCode = compositeResponse.get("httpStatusCode").asInt(); + + if (statusCode != 200 && statusCode != 201 && statusCode != 204) { + String errorBody = compositeResponse.get("body").asText(); + + // MALFORMED_ID or NOT_FOUND + if (statusCode == 400 || statusCode == 404) { + + throw new CustomException( + new ParamErrorObject("l_ua_uan_usan_pr_1", errorBody, Arrays.asList("invalid_note_id"))); + } + else { + throw new CustomException(new ErrorObject("l_ua_uan_usan_pr_2", "something_went_wrong", errorBody)); + } + } + } + +} diff --git a/src/main/java/com/salessparrow/api/lib/crmActions/updateAccountTask/UpdateAccountTaskFactory.java b/src/main/java/com/salessparrow/api/lib/crmActions/updateAccountTask/UpdateAccountTaskFactory.java index 2d2e335b..fefefb57 100644 --- a/src/main/java/com/salessparrow/api/lib/crmActions/updateAccountTask/UpdateAccountTaskFactory.java +++ b/src/main/java/com/salessparrow/api/lib/crmActions/updateAccountTask/UpdateAccountTaskFactory.java @@ -36,7 +36,7 @@ public void updateTask(User user, String accountId, String taskId, UpdateAccount return; default: throw new CustomException( - new ErrorObject("l_ua_uae_uaef_uae_1", "something_went_wrong", "Invalid user kind.")); + new ErrorObject("l_ua_uat_uatf_uat_1", "something_went_wrong", "Invalid user kind.")); } } diff --git a/src/main/java/com/salessparrow/api/lib/crmActions/updateAccountTask/UpdateSalesforceAccountTask.java b/src/main/java/com/salessparrow/api/lib/crmActions/updateAccountTask/UpdateSalesforceAccountTask.java index 141b358d..f67a4d0b 100644 --- a/src/main/java/com/salessparrow/api/lib/crmActions/updateAccountTask/UpdateSalesforceAccountTask.java +++ b/src/main/java/com/salessparrow/api/lib/crmActions/updateAccountTask/UpdateSalesforceAccountTask.java @@ -51,7 +51,7 @@ public void updateTask(User user, String accountId, String taskId, UpdateAccount Util util = new Util(); String taskDescription = util.unEscapeSpecialCharactersForPlainText(updateTaskDto.getDescription()); - String taskSubject = util.getTrimmedString(taskDescription, salesforceConstants.salesforceSubjectLength()); + String taskSubject = util.getTrimmedString(taskDescription, salesforceConstants.salesforceTaskSubjectLength()); Map updateTaskBody = new HashMap(); updateTaskBody.put("Subject", taskSubject); diff --git a/src/main/java/com/salessparrow/api/lib/globalConstants/SalesforceConstants.java b/src/main/java/com/salessparrow/api/lib/globalConstants/SalesforceConstants.java index f3dfab94..cb5372ab 100644 --- a/src/main/java/com/salessparrow/api/lib/globalConstants/SalesforceConstants.java +++ b/src/main/java/com/salessparrow/api/lib/globalConstants/SalesforceConstants.java @@ -50,6 +50,10 @@ public String salesforceUpdateTaskUrl(String taskId) { return sObjectsPath() + "/Task/" + taskId; } + public String salesforceUpdateNoteUrl(String noteId) { + return sObjectsPath() + "/ContentNote/" + noteId; + } + public String salesforceDeleteNoteUrl(String noteId) { return sObjectsPath() + "/ContentNote/" + noteId; } @@ -78,10 +82,18 @@ public Integer timeoutMillis() { return 10000; } - public Integer salesforceSubjectLength() { + public Integer salesforceEventSubjectLength() { + return 60; + } + + public Integer salesforceTaskSubjectLength() { return 60; } + public Integer salesforceContentNoteTitleLength() { + return 50; + } + public String salesforceNotesContentUrl(String urlPrefix, String noteId) { return urlPrefix + "/services/data/v58.0/sobjects/ContentNote/" + noteId + "/Content"; } diff --git a/src/main/java/com/salessparrow/api/services/accountNotes/CreateAccountNoteService.java b/src/main/java/com/salessparrow/api/services/accountNotes/CreateAccountNoteService.java index c7ab77aa..17b9bf85 100644 --- a/src/main/java/com/salessparrow/api/services/accountNotes/CreateAccountNoteService.java +++ b/src/main/java/com/salessparrow/api/services/accountNotes/CreateAccountNoteService.java @@ -5,7 +5,7 @@ import com.salessparrow.api.domain.SalesforceUser; import com.salessparrow.api.dto.formatter.CreateNoteFormatterDto; -import com.salessparrow.api.dto.requestMapper.NoteDto; +import com.salessparrow.api.dto.requestMapper.AccountNoteDto; import com.salessparrow.api.lib.crmActions.createAccountNote.CreateNoteFactory; import jakarta.servlet.http.HttpServletRequest; @@ -25,7 +25,7 @@ public class CreateAccountNoteService { * @param accountId * @return CreateNoteFormatterDto */ - public CreateNoteFormatterDto createNote(HttpServletRequest request, String accountId, NoteDto note) { + public CreateNoteFormatterDto createNote(HttpServletRequest request, String accountId, AccountNoteDto note) { SalesforceUser currentUser = (SalesforceUser) request.getAttribute("current_user"); diff --git a/src/main/java/com/salessparrow/api/services/accountNotes/UpdateAccountNoteService.java b/src/main/java/com/salessparrow/api/services/accountNotes/UpdateAccountNoteService.java new file mode 100644 index 00000000..3dcb0715 --- /dev/null +++ b/src/main/java/com/salessparrow/api/services/accountNotes/UpdateAccountNoteService.java @@ -0,0 +1,42 @@ +package com.salessparrow.api.services.accountNotes; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import com.salessparrow.api.domain.User; +import com.salessparrow.api.dto.requestMapper.AccountNoteDto; +import com.salessparrow.api.lib.crmActions.updateAccountNote.UpdateAccountNoteFactory; + +import jakarta.servlet.http.HttpServletRequest; + +/** + * UpdateAccountNoteService is a service class that handles the update of a note in an + * account. + */ +@Service +public class UpdateAccountNoteService { + + Logger logger = LoggerFactory.getLogger(UpdateAccountNoteService.class); + + @Autowired + private UpdateAccountNoteFactory updateAccountNoteFactory; + + /** + * Updates a note in an account. + * @param request + * @param accountId + * @param noteId + * @return void + */ + public void updateAccountNote(HttpServletRequest request, String accountId, String noteId, + AccountNoteDto accountNoteDto) { + logger.info("Update note in account service called"); + + User currentUser = (User) request.getAttribute("current_user"); + + updateAccountNoteFactory.updateNote(currentUser, accountId, noteId, accountNoteDto); + } + +} From 01c317a25089e09b4e9fc9c04beeb0b5cc55b48c Mon Sep 17 00:00:00 2001 From: Raj Shah Date: Fri, 6 Oct 2023 11:24:04 +0530 Subject: [PATCH 19/36] Added update note test cases --- .../UpdateAccountNoteTest.java | 141 ++++++++++++++++++ .../updateAccountNote.scenarios.json | 61 ++++++++ .../updateAccountNote.fixtures.json | 14 ++ 3 files changed, 216 insertions(+) create mode 100644 src/test/java/com/salessparrow/api/functional/controllers/accountNoteController/UpdateAccountNoteTest.java create mode 100644 src/test/resources/data/functional/controllers/accountNoteController/updateAccountNote.scenarios.json create mode 100644 src/test/resources/fixtures/functional/controllers/accountNoteController/updateAccountNote.fixtures.json diff --git a/src/test/java/com/salessparrow/api/functional/controllers/accountNoteController/UpdateAccountNoteTest.java b/src/test/java/com/salessparrow/api/functional/controllers/accountNoteController/UpdateAccountNoteTest.java new file mode 100644 index 00000000..02dfd91f --- /dev/null +++ b/src/test/java/com/salessparrow/api/functional/controllers/accountNoteController/UpdateAccountNoteTest.java @@ -0,0 +1,141 @@ +package com.salessparrow.api.functional.controllers.accountNoteController; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.when; + +import java.io.IOException; +import java.util.List; +import java.util.stream.Stream; + +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.mock.mockito.MockBean; +import org.springframework.context.annotation.Import; +import org.springframework.core.io.DefaultResourceLoader; +import org.springframework.core.io.Resource; +import org.springframework.http.MediaType; +import org.springframework.test.context.web.WebAppConfiguration; +import org.springframework.test.web.servlet.MockMvc; +import org.springframework.test.web.servlet.ResultActions; +import org.springframework.test.web.servlet.request.MockMvcRequestBuilders; + +import com.fasterxml.jackson.core.type.TypeReference; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.github.dynamobee.exception.DynamobeeException; +import com.salessparrow.api.helper.Cleanup; +import com.salessparrow.api.helper.Common; +import com.salessparrow.api.helper.Constants; +import com.salessparrow.api.helper.FixtureData; +import com.salessparrow.api.helper.LoadFixture; +import com.salessparrow.api.helper.Scenario; +import com.salessparrow.api.helper.Setup; +import com.salessparrow.api.lib.globalConstants.CookieConstants; +import com.salessparrow.api.lib.httpLib.HttpClient.HttpResponse; +import com.salessparrow.api.lib.salesforce.helper.MakeCompositeRequest; + +import jakarta.servlet.http.Cookie; + +@SpringBootTest +@AutoConfigureMockMvc +@WebAppConfiguration +@Import({ Setup.class, Cleanup.class, Common.class, LoadFixture.class }) +public class UpdateAccountNoteTest { + + @Autowired + private MockMvc mockMvc; + + @Autowired + private Common common; + + @Autowired + private LoadFixture loadFixture; + + @Autowired + private Setup setup; + + @Autowired + private Cleanup cleanup; + + @MockBean + private MakeCompositeRequest makeCompositeRequestMock; + + @BeforeEach + public void setUp() throws DynamobeeException { + setup.perform(); + } + + @AfterEach + public void tearDown() { + cleanup.perform(); + } + + @ParameterizedTest + @MethodSource("testScenariosProvider") + public void updateAccountNote(Scenario testScenario) throws Exception { + + // Load fixture data + String currentFunctionName = new Object() { + }.getClass().getEnclosingMethod().getName(); + FixtureData fixtureData = common.loadFixture( + "classpath:fixtures/functional/controllers/accountNoteController/updateAccountNote.fixtures.json", + currentFunctionName); + loadFixture.perform(fixtureData); + + // Read data from the scenario + ObjectMapper objectMapper = new ObjectMapper(); + String cookieValue = Constants.SALESFORCE_ACTIVE_USER_COOKIE_VALUE; + String accountId = (String) testScenario.getInput().get("accountId"); + String noteId = (String) testScenario.getInput().get("noteId"); + + // Prepare mock responses + HttpResponse mockResponse = new HttpResponse(); + mockResponse + .setResponseBody(objectMapper.writeValueAsString(testScenario.getMocks().get("makeCompositeRequest"))); + when(makeCompositeRequestMock.makePostRequest(any(), any())).thenReturn(mockResponse); + + // Perform the request + String requestBody = objectMapper.writeValueAsString(testScenario.getInput().get("body")); + String url = "/api/v1/accounts/" + accountId + "/notes/" + noteId; + + ResultActions resultActions = mockMvc.perform(MockMvcRequestBuilders.put(url) + .cookie(new Cookie(CookieConstants.USER_LOGIN_COOKIE_NAME, cookieValue)) + .content(requestBody) + .contentType(MediaType.APPLICATION_JSON)); + + // Check the response + String expectedOutput = objectMapper.writeValueAsString(testScenario.getOutput()); + String actualOutput = resultActions.andReturn().getResponse().getContentAsString(); + + Integer responseStatus = resultActions.andReturn().getResponse().getStatus(); + + if (responseStatus == 200 || responseStatus == 201 || responseStatus == 204) { + if (expectedOutput.equals("{}")) { + expectedOutput = ""; + } + assertEquals(expectedOutput, actualOutput); + } + else { + common.compareErrors(testScenario, actualOutput); + } + } + + static Stream testScenariosProvider() throws IOException { + List testScenarios = loadScenarios(); + return testScenarios.stream(); + } + + private static List loadScenarios() throws IOException { + String scenariosPath = "classpath:data/functional/controllers/accountNoteController/updateAccountNote.scenarios.json"; + Resource resource = new DefaultResourceLoader().getResource(scenariosPath); + ObjectMapper objectMapper = new ObjectMapper(); + return objectMapper.readValue(resource.getInputStream(), new TypeReference>() { + }); + } + +} diff --git a/src/test/resources/data/functional/controllers/accountNoteController/updateAccountNote.scenarios.json b/src/test/resources/data/functional/controllers/accountNoteController/updateAccountNote.scenarios.json new file mode 100644 index 00000000..b253fad6 --- /dev/null +++ b/src/test/resources/data/functional/controllers/accountNoteController/updateAccountNote.scenarios.json @@ -0,0 +1,61 @@ +[ + { + "description": "Should successfully update the note for given note id", + "input": { + "body": { + "text": "Updated Test note" + }, + "accountId": "0011e00000bWSxdAAG", + "noteId":"0691e000001X1yTAAS" + }, + "mocks": { + "makeCompositeRequest": { + "compositeResponse": [ + { + "body": null, + "httpHeaders": {}, + "httpStatusCode": 200, + "referenceId": "UpdateNote" + } + ] + } + }, + "output": {} + }, + { + "description": "should return error response when note id is invalid", + "input": { + "body": { + "text": "Updated Test note" + }, + "accountId": "0011e00000bWSxdAAG", + "noteId":"invalidNoteId" + }, + "mocks": { + "makeCompositeRequest": { + "compositeResponse": [ + { + "body": [ + { + "errorCode": "NOT_FOUND", + "message": "Provided external ID field does not exist or is not accessible: INVALID_NOTE_ID" + } + ], + "httpHeaders": {}, + "httpStatusCode": 404, + "referenceId": "UpdateNote" + } + ] + } + }, + "output": { + "http_code": 400, + "message": "At least one parameter is invalid or missing.", + "code": "INVALID_PARAMS", + "internal_error_identifier": "l_ua_uan_usan_pr_1", + "param_errors": [ + "invalid_note_id" + ] + } + } + ] \ No newline at end of file diff --git a/src/test/resources/fixtures/functional/controllers/accountNoteController/updateAccountNote.fixtures.json b/src/test/resources/fixtures/functional/controllers/accountNoteController/updateAccountNote.fixtures.json new file mode 100644 index 00000000..37e0bf0f --- /dev/null +++ b/src/test/resources/fixtures/functional/controllers/accountNoteController/updateAccountNote.fixtures.json @@ -0,0 +1,14 @@ +{ + "updateAccountNote": { + "salesforce_users": [ + { + "filepath": "classpath:fixtures/common/repositories/salesforceUser/ActiveSalesforceUser.json" + } + ], + "salesforce_oauth_tokens": [ + { + "filepath": "classpath:fixtures/common/repositories/salesforceOauthToken/ActiveSalesforceOauthToken.json" + } + ] + } +} \ No newline at end of file From b7b693cdfd5cfa786f940f057b4abe796a400b16 Mon Sep 17 00:00:00 2001 From: Raj Shah Date: Mon, 9 Oct 2023 10:17:17 +0530 Subject: [PATCH 20/36] Updated security config --- .../com/salessparrow/api/config/SecurityConfig.java | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/src/main/java/com/salessparrow/api/config/SecurityConfig.java b/src/main/java/com/salessparrow/api/config/SecurityConfig.java index 8f98d886..fa165774 100644 --- a/src/main/java/com/salessparrow/api/config/SecurityConfig.java +++ b/src/main/java/com/salessparrow/api/config/SecurityConfig.java @@ -2,12 +2,9 @@ import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; -import org.springframework.http.HttpStatus; import org.springframework.security.config.annotation.web.builders.HttpSecurity; import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; -import org.springframework.security.web.AuthenticationEntryPoint; import org.springframework.security.web.SecurityFilterChain; -import org.springframework.security.web.authentication.HttpStatusEntryPoint; import org.springframework.security.web.header.writers.XXssProtectionHeaderWriter; import org.springframework.security.web.header.writers.ReferrerPolicyHeaderWriter.ReferrerPolicy; @@ -76,9 +73,6 @@ public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Excepti hsts -> hsts.includeSubDomains(true).preload(true).maxAgeInSeconds(31536000)) .xssProtection(xss -> xss.headerValue(XXssProtectionHeaderWriter.HeaderValue.ENABLED_MODE_BLOCK)) .referrerPolicy(referrer -> referrer.policy(ReferrerPolicy.SAME_ORIGIN))); - // .exceptionHandling( - // exceptionHandling -> - // exceptionHandling.authenticationEntryPoint(authenticationEntryPoint())); // http redirect to https is handled by the reverse proxy server (nginx). So no // need to handle it here. @@ -86,10 +80,4 @@ public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Excepti return http.build(); } - @Bean - public AuthenticationEntryPoint authenticationEntryPoint() { - // Use HttpStatusEntryPoint to return a 404 response for invalid routes - return new HttpStatusEntryPoint(HttpStatus.NOT_FOUND); - } - } From 621ff2b1586bc1bee46152b84cbf0b942652d912 Mon Sep 17 00:00:00 2001 From: Raj Shah Date: Mon, 9 Oct 2023 10:26:34 +0530 Subject: [PATCH 21/36] Reverted back security change --- .../java/com/salessparrow/api/config/SecurityConfig.java | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/main/java/com/salessparrow/api/config/SecurityConfig.java b/src/main/java/com/salessparrow/api/config/SecurityConfig.java index fa165774..d8d55c72 100644 --- a/src/main/java/com/salessparrow/api/config/SecurityConfig.java +++ b/src/main/java/com/salessparrow/api/config/SecurityConfig.java @@ -17,10 +17,7 @@ public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Excepti http // disable authorization for all routes - .authorizeHttpRequests(authorizeRequests -> authorizeRequests.requestMatchers("/api/v1/**") - .permitAll() - .anyRequest() - .authenticated()) + .authorizeHttpRequests(authorizeRequests -> authorizeRequests.anyRequest().permitAll()) // Disable authentication for all routes .httpBasic(httpBasic -> httpBasic.disable()) // Disable form login From 25dde2f0ddea9c1763e2f9fef2d62bb5fa4ed386 Mon Sep 17 00:00:00 2001 From: Raj Shah Date: Mon, 9 Oct 2023 15:28:27 +0530 Subject: [PATCH 22/36] Added changelog file for 0.3.0 --- repo-docs/CHANGELOG.md | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/repo-docs/CHANGELOG.md b/repo-docs/CHANGELOG.md index 755b3952..0a9e4dab 100644 --- a/repo-docs/CHANGELOG.md +++ b/repo-docs/CHANGELOG.md @@ -1,5 +1,19 @@ # SalesSparrow APIs +## 0.3.0 + +### New Features and Enhancements: + +- API - Edit Note Endpoint [#18](https://github.com/TrueSparrowSystems/AI-SalesSparrow-API/issues/18) +- API - Get a list of Events in an account [#29](https://github.com/TrueSparrowSystems/AI-SalesSparrow-API/issues/29) +- API - Create Event for an Account [#30](https://github.com/TrueSparrowSystems/AI-SalesSparrow-API/issues/30) +- API - Edit Event in an Account Endpoint [#31](https://github.com/TrueSparrowSystems/AI-SalesSparrow-API/issues/31) +- API - Delete Event in an Account Endpoint [#32](https://github.com/TrueSparrowSystems/AI-SalesSparrow-API/issues/32) +- API - Edit Task in an Account Endpoint [#36](https://github.com/TrueSparrowSystems/AI-SalesSparrow-API/issues/36) +- API - Get Event By Id Endpoint [#101](https://github.com/TrueSparrowSystems/AI-SalesSparrow-API/issues/101) +- API - Get Task By Id Endpoint [#102](https://github.com/TrueSparrowSystems/AI-SalesSparrow-API/issues/102) +- Add Event Suggestion Prompt [#103](https://github.com/TrueSparrowSystems/AI-SalesSparrow-API/issues/103) + ## 0.2.3 ### Enhancements: From 1794d18f89ae72a6d7f7c2c35bc32ffe6c7b84d9 Mon Sep 17 00:00:00 2001 From: Raj Shah Date: Mon, 9 Oct 2023 16:01:54 +0530 Subject: [PATCH 23/36] Updated version in pom.xml --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index ffb28e87..7b1344f8 100644 --- a/pom.xml +++ b/pom.xml @@ -13,7 +13,7 @@ com.salessparrow salessparrow-api - 0.2.3 + 0.3.0 api Salessparrow apis From 999b80b17276f895b187a6991ce6b1c0e210c649 Mon Sep 17 00:00:00 2001 From: Raj Shah Date: Tue, 10 Oct 2023 14:17:23 +0530 Subject: [PATCH 24/36] Added html decode for note content response --- .../lib/salesforce/dto/SalesforceGetNoteDetailsDto.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/salessparrow/api/lib/salesforce/dto/SalesforceGetNoteDetailsDto.java b/src/main/java/com/salessparrow/api/lib/salesforce/dto/SalesforceGetNoteDetailsDto.java index bb8422d2..9151bda6 100644 --- a/src/main/java/com/salessparrow/api/lib/salesforce/dto/SalesforceGetNoteDetailsDto.java +++ b/src/main/java/com/salessparrow/api/lib/salesforce/dto/SalesforceGetNoteDetailsDto.java @@ -2,6 +2,8 @@ import java.util.Date; +import org.springframework.web.util.HtmlUtils; + import com.fasterxml.jackson.databind.PropertyNamingStrategies; import com.fasterxml.jackson.databind.annotation.JsonNaming; import com.salessparrow.api.dto.entities.NoteDetailEntity; @@ -27,8 +29,9 @@ private class CreatedBy { } public NoteDetailEntity noteDetailEntity(String noteContentResponse) { - NoteDetailEntity noteDetailEntity = new NoteDetailEntity(this.id, this.createdBy.name, noteContentResponse, - this.lastModifiedDate); + String decodedNoteContentResponse = HtmlUtils.htmlUnescape(noteContentResponse); + NoteDetailEntity noteDetailEntity = new NoteDetailEntity(this.id, this.createdBy.name, + decodedNoteContentResponse, this.lastModifiedDate); return noteDetailEntity; } From fd579bdd8c10cf16a4e3c8bde362a47184851232 Mon Sep 17 00:00:00 2001 From: Raj Shah Date: Wed, 11 Oct 2023 14:31:11 +0530 Subject: [PATCH 25/36] Added code test changes --- .../controllers/accountController/getNoteDetails.scenarios.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/resources/data/functional/controllers/accountController/getNoteDetails.scenarios.json b/src/test/resources/data/functional/controllers/accountController/getNoteDetails.scenarios.json index b2359c95..57766053 100644 --- a/src/test/resources/data/functional/controllers/accountController/getNoteDetails.scenarios.json +++ b/src/test/resources/data/functional/controllers/accountController/getNoteDetails.scenarios.json @@ -44,7 +44,7 @@ "note_detail": { "id": "0691e000001WY58AAG", "creator": "Ashfaq Bhojani", - "text": "\"

Let's use plural routes and have accountId in URL as per the API Convention.\\n/v1/account/content-notes => /v1/salesforce/accounts/{accountId}/content-notes\\n/v1/composite is generic. It can be under a salesforce route.\\n/v1/composite => /v1/salesforce/composite\\nQuestion:TextPreview in content notes response is a truncated version of the full text in notes?She suspicion dejection saw instantly. Well deny may real one told yet saw hard dear. Bed chief house rapid right the. Set noisy one state tears which. No girl oh part must fact high my he. Simplicity in excellence melancholy as remarkably discovered. Own partiality motionless was old excellence she inquietude contrasted. Sister giving so wicket cousin of an he rather marked. Of on game part body rich. Adapted mr savings venture it or comfort affixed friends.Prepared is me marianne pleasure likewise debating. Wonder an unable except better stairs do ye admire. His and eat secure sex called esteem praise. So moreover as speedily differed branched ignorant. Tall are her knew poor now does then. Procured to contempt oh he raptures amounted occasion. One boy assure income spirit lovers set.Passage its ten led hearted removal cordial. Preference any astonished unreserved mrs. Prosperous understood middletons in conviction an uncommonly do. Supposing so be resolving breakfast am or perfectly. Is drew am hill from mr. Valley by oh twenty direct me so. Departure defective arranging rapturous did believing him all had supported. Family months lasted simple set nature vulgar him. Picture for attempt joy excited ten carried manners talking how. Suspicion neglected he resolving agreement perceived at an.Dashwood contempt on mr unlocked resolved provided of of. Stanhill wondered it it welcomed oh. Hundred no prudent he however smiling at an offence. If earnestly extremity he he propriety something admitting convinced ye. Pleasant in to although as if differed horrible. Mirth his quick its set front enjoy hoped had there. Who connection imprudence middletons too but increasing celebrated principles joy. Herself too improve gay winding ask expense are compact. New all paid few hard pure she.That know ask case sex ham dear her spot. Weddings followed the all marianne nor whatever settling. Perhaps six prudent several her had offence. Did had way law dinner square tastes. Recommend concealed yet her procuring see consulted depending. Adieu

\"", + "text": "\"

Let's use plural routes and have accountId in URL as per the API Convention.\\n/v1/account/content-notes => /v1/salesforce/accounts/{accountId}/content-notes\\n/v1/composite is generic. It can be under a salesforce route.\\n/v1/composite => /v1/salesforce/composite\\nQuestion:TextPreview in content notes response is a truncated version of the full text in notes?She suspicion dejection saw instantly. Well deny may real one told yet saw hard dear. Bed chief house rapid right the. Set noisy one state tears which. No girl oh part must fact high my he. Simplicity in excellence melancholy as remarkably discovered. Own partiality motionless was old excellence she inquietude contrasted. Sister giving so wicket cousin of an he rather marked. Of on game part body rich. Adapted mr savings venture it or comfort affixed friends.Prepared is me marianne pleasure likewise debating. Wonder an unable except better stairs do ye admire. His and eat secure sex called esteem praise. So moreover as speedily differed branched ignorant. Tall are her knew poor now does then. Procured to contempt oh he raptures amounted occasion. One boy assure income spirit lovers set.Passage its ten led hearted removal cordial. Preference any astonished unreserved mrs. Prosperous understood middletons in conviction an uncommonly do. Supposing so be resolving breakfast am or perfectly. Is drew am hill from mr. Valley by oh twenty direct me so. Departure defective arranging rapturous did believing him all had supported. Family months lasted simple set nature vulgar him. Picture for attempt joy excited ten carried manners talking how. Suspicion neglected he resolving agreement perceived at an.Dashwood contempt on mr unlocked resolved provided of of. Stanhill wondered it it welcomed oh. Hundred no prudent he however smiling at an offence. If earnestly extremity he he propriety something admitting convinced ye. Pleasant in to although as if differed horrible. Mirth his quick its set front enjoy hoped had there. Who connection imprudence middletons too but increasing celebrated principles joy. Herself too improve gay winding ask expense are compact. New all paid few hard pure she.That know ask case sex ham dear her spot. Weddings followed the all marianne nor whatever settling. Perhaps six prudent several her had offence. Did had way law dinner square tastes. Recommend concealed yet her procuring see consulted depending. Adieu

\"", "last_modified_time": "2023-08-01T10:38:23.000+00:00" } } From 1504725da0a733a1efd2a592e784f7602396d36e Mon Sep 17 00:00:00 2001 From: Raj Shah Date: Wed, 11 Oct 2023 14:54:13 +0530 Subject: [PATCH 26/36] Updated open ai prompt --- .../com/salessparrow/api/lib/openAi/OpenAiPayloadBuilder.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/salessparrow/api/lib/openAi/OpenAiPayloadBuilder.java b/src/main/java/com/salessparrow/api/lib/openAi/OpenAiPayloadBuilder.java index c2ffdd1a..4bf306c2 100644 --- a/src/main/java/com/salessparrow/api/lib/openAi/OpenAiPayloadBuilder.java +++ b/src/main/java/com/salessparrow/api/lib/openAi/OpenAiPayloadBuilder.java @@ -46,7 +46,7 @@ public String payloadForCrmActionsSuggestions(String text) { + " \"description\": \"Description for the event to add.\"\n" + " },\n" + " \"start_datetime\": {\n" + " \"type\": \"string\",\n" + " \"description\": \"Start Datetime for the event in yyyy-MM-dd'T'HH:mm:ss.SSS+0000 format.\"\n" - + " },\n" + " \"start_datetime\": {\n" + + " },\n" + " \"end_datetime\": {\n" + " \"type\": \"string\",\n" + " \"description\": \"End Datetime for the event in yyyy-MM-dd'T'HH:mm:ss.SSS+0000 format.\"\n" + " }\n" + " }\n" + " }\n" + " }\n" + " }\n" From b3a76a991e9a451879ca9931fcf3692b9b1ebe4e Mon Sep 17 00:00:00 2001 From: Raj Shah Date: Mon, 16 Oct 2023 10:28:46 +0530 Subject: [PATCH 27/36] Added TODO for payload of opan ai --- .../com/salessparrow/api/lib/openAi/OpenAiPayloadBuilder.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/com/salessparrow/api/lib/openAi/OpenAiPayloadBuilder.java b/src/main/java/com/salessparrow/api/lib/openAi/OpenAiPayloadBuilder.java index 4bf306c2..27913c85 100644 --- a/src/main/java/com/salessparrow/api/lib/openAi/OpenAiPayloadBuilder.java +++ b/src/main/java/com/salessparrow/api/lib/openAi/OpenAiPayloadBuilder.java @@ -19,6 +19,7 @@ public class OpenAiPayloadBuilder { public String payloadForCrmActionsSuggestions(String text) { String todayDate = getTodaysDate(); + // TODO - Use Jackson Library to build this JSON String payload = "{\n" + " \"model\": \"gpt-3.5-turbo-0613\",\n" + " \"messages\": [\n" + " {\n" + " \"role\": \"system\",\n" + " \"content\": \"You are an AI assistant that provides suggestions for creating tasks and events in CRM based solely on the content of the input message. The content of the task or event, if any found, should only be from the input message. If no task or event suggestions are found in the input message, return empty data. Suggestions can either be both task and event list or only tasks or only events or empty. If task suggestions are found, they should include description and due date. Due Date format should be YYYY-MM-DD. If event suggestions are found, they should include description and start datetime and end datetime. If end datetime not provided it should be start datetime + 1 hour. Start datetime and end datetime format is yyyy-MM-dd'T'HH:mm:ss.SSS+0000. Today's date is " From 53801c27ae245a0ef11f140c5d229414edeed65d Mon Sep 17 00:00:00 2001 From: Raj Shah Date: Mon, 16 Oct 2023 10:31:12 +0530 Subject: [PATCH 28/36] Added null check for getTrimmedString --- src/main/java/com/salessparrow/api/lib/Util.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/main/java/com/salessparrow/api/lib/Util.java b/src/main/java/com/salessparrow/api/lib/Util.java index 0b6f5ac4..b14bbc85 100644 --- a/src/main/java/com/salessparrow/api/lib/Util.java +++ b/src/main/java/com/salessparrow/api/lib/Util.java @@ -188,6 +188,10 @@ public String replaceNewLineWithBreak(String input) { * @return String */ public String getTrimmedString(String input, Integer length) { + if (input == null) { + return null; + } + if (input.length() < length) { return input; } From 1bcc0722489038c166ad6f71f9b7e8480b285f2e Mon Sep 17 00:00:00 2001 From: Raj Shah Date: Mon, 16 Oct 2023 10:51:54 +0530 Subject: [PATCH 29/36] Changed getTrimmedString to static method --- src/main/java/com/salessparrow/api/lib/Util.java | 8 ++++---- .../createAccountEvent/CreateSalesforceAccountEvent.java | 2 +- .../createAccountNote/CreateSalesforceNote.java | 2 +- .../updateAccountEvent/UpdateSalesforceAccountEvent.java | 2 +- .../updateAccountNote/UpdateSalesforceAccountNote.java | 2 +- .../updateAccountTask/UpdateSalesforceAccountTask.java | 2 +- .../salessparrow/api/lib/openAi/OpenAiPayloadBuilder.java | 2 +- 7 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/main/java/com/salessparrow/api/lib/Util.java b/src/main/java/com/salessparrow/api/lib/Util.java index b14bbc85..94470ccf 100644 --- a/src/main/java/com/salessparrow/api/lib/Util.java +++ b/src/main/java/com/salessparrow/api/lib/Util.java @@ -187,10 +187,10 @@ public String replaceNewLineWithBreak(String input) { * @param length * @return String */ - public String getTrimmedString(String input, Integer length) { - if (input == null) { - return null; - } + public static String getTrimmedString(String input, Integer length) { + if (input == null) { + return null; + } if (input.length() < length) { return input; diff --git a/src/main/java/com/salessparrow/api/lib/crmActions/createAccountEvent/CreateSalesforceAccountEvent.java b/src/main/java/com/salessparrow/api/lib/crmActions/createAccountEvent/CreateSalesforceAccountEvent.java index 38c853ea..615a1238 100644 --- a/src/main/java/com/salessparrow/api/lib/crmActions/createAccountEvent/CreateSalesforceAccountEvent.java +++ b/src/main/java/com/salessparrow/api/lib/crmActions/createAccountEvent/CreateSalesforceAccountEvent.java @@ -53,7 +53,7 @@ public CreateEventFormatterDto createEvent(User user, String accountId, CreateAc Util util = new Util(); String eventDescription = util.unEscapeSpecialCharactersForPlainText(createEventDto.getDescription()); - String eventSubject = util.getTrimmedString(eventDescription, + String eventSubject = Util.getTrimmedString(eventDescription, salesforceConstants.salesforceEventSubjectLength()); Map createEventBody = new HashMap(); diff --git a/src/main/java/com/salessparrow/api/lib/crmActions/createAccountNote/CreateSalesforceNote.java b/src/main/java/com/salessparrow/api/lib/crmActions/createAccountNote/CreateSalesforceNote.java index 3bc22745..bc5b751a 100644 --- a/src/main/java/com/salessparrow/api/lib/crmActions/createAccountNote/CreateSalesforceNote.java +++ b/src/main/java/com/salessparrow/api/lib/crmActions/createAccountNote/CreateSalesforceNote.java @@ -57,7 +57,7 @@ public CreateNoteFormatterDto createNote(SalesforceUser user, String accountId, Util util = new Util(); String noteContent = note.getText(); String unEscapeNoteContent = util.unEscapeSpecialCharactersForPlainText(noteContent); - String noteTitle = util.getTrimmedString(unEscapeNoteContent, + String noteTitle = Util.getTrimmedString(unEscapeNoteContent, salesforceConstants.salesforceContentNoteTitleLength()); noteContent = util.replaceNewLineWithBreak(noteContent); diff --git a/src/main/java/com/salessparrow/api/lib/crmActions/updateAccountEvent/UpdateSalesforceAccountEvent.java b/src/main/java/com/salessparrow/api/lib/crmActions/updateAccountEvent/UpdateSalesforceAccountEvent.java index 947d9a34..3b26d569 100644 --- a/src/main/java/com/salessparrow/api/lib/crmActions/updateAccountEvent/UpdateSalesforceAccountEvent.java +++ b/src/main/java/com/salessparrow/api/lib/crmActions/updateAccountEvent/UpdateSalesforceAccountEvent.java @@ -51,7 +51,7 @@ public void updateEvent(User user, String accountId, String eventId, UpdateAccou Util util = new Util(); String eventDescription = util.unEscapeSpecialCharactersForPlainText(updateEventDto.getDescription()); - String eventSubject = util.getTrimmedString(eventDescription, + String eventSubject = Util.getTrimmedString(eventDescription, salesforceConstants.salesforceEventSubjectLength()); Map updateEventBody = new HashMap(); diff --git a/src/main/java/com/salessparrow/api/lib/crmActions/updateAccountNote/UpdateSalesforceAccountNote.java b/src/main/java/com/salessparrow/api/lib/crmActions/updateAccountNote/UpdateSalesforceAccountNote.java index b5d7a89e..ae74146c 100644 --- a/src/main/java/com/salessparrow/api/lib/crmActions/updateAccountNote/UpdateSalesforceAccountNote.java +++ b/src/main/java/com/salessparrow/api/lib/crmActions/updateAccountNote/UpdateSalesforceAccountNote.java @@ -57,7 +57,7 @@ public void updateNote(User user, String accountId, String noteId, AccountNoteDt String noteContent = accountNoteDto.getText(); String unEscapeNoteContent = util.unEscapeSpecialCharactersForPlainText(noteContent); - String noteTitle = util.getTrimmedString(unEscapeNoteContent, + String noteTitle = Util.getTrimmedString(unEscapeNoteContent, salesforceConstants.salesforceContentNoteTitleLength()); noteContent = util.replaceNewLineWithBreak(noteContent); diff --git a/src/main/java/com/salessparrow/api/lib/crmActions/updateAccountTask/UpdateSalesforceAccountTask.java b/src/main/java/com/salessparrow/api/lib/crmActions/updateAccountTask/UpdateSalesforceAccountTask.java index f67a4d0b..5f1804d0 100644 --- a/src/main/java/com/salessparrow/api/lib/crmActions/updateAccountTask/UpdateSalesforceAccountTask.java +++ b/src/main/java/com/salessparrow/api/lib/crmActions/updateAccountTask/UpdateSalesforceAccountTask.java @@ -51,7 +51,7 @@ public void updateTask(User user, String accountId, String taskId, UpdateAccount Util util = new Util(); String taskDescription = util.unEscapeSpecialCharactersForPlainText(updateTaskDto.getDescription()); - String taskSubject = util.getTrimmedString(taskDescription, salesforceConstants.salesforceTaskSubjectLength()); + String taskSubject = Util.getTrimmedString(taskDescription, salesforceConstants.salesforceTaskSubjectLength()); Map updateTaskBody = new HashMap(); updateTaskBody.put("Subject", taskSubject); diff --git a/src/main/java/com/salessparrow/api/lib/openAi/OpenAiPayloadBuilder.java b/src/main/java/com/salessparrow/api/lib/openAi/OpenAiPayloadBuilder.java index 27913c85..35ce37e0 100644 --- a/src/main/java/com/salessparrow/api/lib/openAi/OpenAiPayloadBuilder.java +++ b/src/main/java/com/salessparrow/api/lib/openAi/OpenAiPayloadBuilder.java @@ -19,7 +19,7 @@ public class OpenAiPayloadBuilder { public String payloadForCrmActionsSuggestions(String text) { String todayDate = getTodaysDate(); - // TODO - Use Jackson Library to build this JSON + // TODO - Use Jackson Library to build this JSON String payload = "{\n" + " \"model\": \"gpt-3.5-turbo-0613\",\n" + " \"messages\": [\n" + " {\n" + " \"role\": \"system\",\n" + " \"content\": \"You are an AI assistant that provides suggestions for creating tasks and events in CRM based solely on the content of the input message. The content of the task or event, if any found, should only be from the input message. If no task or event suggestions are found in the input message, return empty data. Suggestions can either be both task and event list or only tasks or only events or empty. If task suggestions are found, they should include description and due date. Due Date format should be YYYY-MM-DD. If event suggestions are found, they should include description and start datetime and end datetime. If end datetime not provided it should be start datetime + 1 hour. Start datetime and end datetime format is yyyy-MM-dd'T'HH:mm:ss.SSS+0000. Today's date is " From a93296bbdd7283b7298c244dbcc18108d4915a9b Mon Sep 17 00:00:00 2001 From: Raj Shah Date: Mon, 16 Oct 2023 10:57:45 +0530 Subject: [PATCH 30/36] Added TODO to use Slf4j instead of logger --- .../com/salessparrow/api/controllers/AccountTaskController.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/com/salessparrow/api/controllers/AccountTaskController.java b/src/main/java/com/salessparrow/api/controllers/AccountTaskController.java index 54a34218..0efc4823 100644 --- a/src/main/java/com/salessparrow/api/controllers/AccountTaskController.java +++ b/src/main/java/com/salessparrow/api/controllers/AccountTaskController.java @@ -34,6 +34,7 @@ @Validated public class AccountTaskController { + // TODO: Use Lombok's @Slf4j annotation instead of the following: Logger logger = LoggerFactory.getLogger(AccountTaskController.class); @Autowired From 39922f56fa983be953bd6f5a957762944073e15a Mon Sep 17 00:00:00 2001 From: Raj Shah Date: Mon, 16 Oct 2023 11:11:12 +0530 Subject: [PATCH 31/36] Renamed Files --- ...CreateAccountTask.java => CreateAccountTaskInterface.java} | 4 ++-- .../createAccountTask/CreateSalesforceAccountTask.java | 2 +- ...leteAccountEvent.java => DeleteAccountEventInterface.java} | 4 ++-- .../deleteAccountEvent/DeleteSalesforceAccountEvent.java | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) rename src/main/java/com/salessparrow/api/lib/crmActions/createAccountTask/{CreateAccountTask.java => CreateAccountTaskInterface.java} (75%) rename src/main/java/com/salessparrow/api/lib/crmActions/deleteAccountEvent/{DeleteAccountEvent.java => DeleteAccountEventInterface.java} (66%) diff --git a/src/main/java/com/salessparrow/api/lib/crmActions/createAccountTask/CreateAccountTask.java b/src/main/java/com/salessparrow/api/lib/crmActions/createAccountTask/CreateAccountTaskInterface.java similarity index 75% rename from src/main/java/com/salessparrow/api/lib/crmActions/createAccountTask/CreateAccountTask.java rename to src/main/java/com/salessparrow/api/lib/crmActions/createAccountTask/CreateAccountTaskInterface.java index eb57e094..3ec40ba3 100644 --- a/src/main/java/com/salessparrow/api/lib/crmActions/createAccountTask/CreateAccountTask.java +++ b/src/main/java/com/salessparrow/api/lib/crmActions/createAccountTask/CreateAccountTaskInterface.java @@ -7,10 +7,10 @@ import com.salessparrow.api.dto.requestMapper.CreateAccountTaskDto; /** - * CreateTask interface is interface for createTask for various CRM services + * CreateAccountTaskInterface interface is interface for createTask for various CRM services */ @Component -public interface CreateAccountTask { +public interface CreateAccountTaskInterface { public CreateTaskFormatterDto createAccountTask(User User, String accountId, CreateAccountTaskDto task); diff --git a/src/main/java/com/salessparrow/api/lib/crmActions/createAccountTask/CreateSalesforceAccountTask.java b/src/main/java/com/salessparrow/api/lib/crmActions/createAccountTask/CreateSalesforceAccountTask.java index be02ebb9..9561abbd 100644 --- a/src/main/java/com/salessparrow/api/lib/crmActions/createAccountTask/CreateSalesforceAccountTask.java +++ b/src/main/java/com/salessparrow/api/lib/crmActions/createAccountTask/CreateSalesforceAccountTask.java @@ -29,7 +29,7 @@ * CreateSalesforceTask class is responsible for creating a task in Salesforce */ @Component -public class CreateSalesforceAccountTask implements CreateAccountTask { +public class CreateSalesforceAccountTask implements CreateAccountTaskInterface { Logger logger = LoggerFactory.getLogger(CreateSalesforceAccountTask.class); diff --git a/src/main/java/com/salessparrow/api/lib/crmActions/deleteAccountEvent/DeleteAccountEvent.java b/src/main/java/com/salessparrow/api/lib/crmActions/deleteAccountEvent/DeleteAccountEventInterface.java similarity index 66% rename from src/main/java/com/salessparrow/api/lib/crmActions/deleteAccountEvent/DeleteAccountEvent.java rename to src/main/java/com/salessparrow/api/lib/crmActions/deleteAccountEvent/DeleteAccountEventInterface.java index c93c59aa..d3572468 100644 --- a/src/main/java/com/salessparrow/api/lib/crmActions/deleteAccountEvent/DeleteAccountEvent.java +++ b/src/main/java/com/salessparrow/api/lib/crmActions/deleteAccountEvent/DeleteAccountEventInterface.java @@ -5,10 +5,10 @@ import com.salessparrow.api.domain.User; /** - * DeleteAccountEvent is an interface for deleting an event in an account. + * DeleteAccountEventInterface is an interface for deleting an event in an account. */ @Component -public interface DeleteAccountEvent { +public interface DeleteAccountEventInterface { public void deleteAccountEvent(User user, String accountId, String eventId); diff --git a/src/main/java/com/salessparrow/api/lib/crmActions/deleteAccountEvent/DeleteSalesforceAccountEvent.java b/src/main/java/com/salessparrow/api/lib/crmActions/deleteAccountEvent/DeleteSalesforceAccountEvent.java index 3d4e7aa0..e8129f75 100644 --- a/src/main/java/com/salessparrow/api/lib/crmActions/deleteAccountEvent/DeleteSalesforceAccountEvent.java +++ b/src/main/java/com/salessparrow/api/lib/crmActions/deleteAccountEvent/DeleteSalesforceAccountEvent.java @@ -25,7 +25,7 @@ * account for salesforce. */ @Component -public class DeleteSalesforceAccountEvent implements DeleteAccountEvent { +public class DeleteSalesforceAccountEvent implements DeleteAccountEventInterface { Logger logger = LoggerFactory.getLogger(DeleteSalesforceAccountEvent.class); From b2ccfcbe9213fd0d9655026975dfbe7819e592f0 Mon Sep 17 00:00:00 2001 From: Raj Shah Date: Mon, 16 Oct 2023 11:46:39 +0530 Subject: [PATCH 32/36] Changed util methods to static --- .../api/controllers/AccountTaskController.java | 2 +- src/main/java/com/salessparrow/api/lib/Util.java | 4 ++-- .../CreateSalesforceAccountEvent.java | 3 +-- .../createAccountNote/CreateSalesforceNote.java | 5 ++--- .../CreateAccountTaskInterface.java | 3 ++- .../CreateSalesforceAccountTask.java | 4 ++-- .../GetSalesforceAccountTaskDetails.java | 14 ++++++++------ .../UpdateSalesforceAccountEvent.java | 3 +-- .../UpdateSalesforceAccountNote.java | 6 ++---- .../UpdateSalesforceAccountTask.java | 3 +-- 10 files changed, 22 insertions(+), 25 deletions(-) diff --git a/src/main/java/com/salessparrow/api/controllers/AccountTaskController.java b/src/main/java/com/salessparrow/api/controllers/AccountTaskController.java index 0efc4823..0e9f38c9 100644 --- a/src/main/java/com/salessparrow/api/controllers/AccountTaskController.java +++ b/src/main/java/com/salessparrow/api/controllers/AccountTaskController.java @@ -34,7 +34,7 @@ @Validated public class AccountTaskController { - // TODO: Use Lombok's @Slf4j annotation instead of the following: + // TODO: Use Lombok's @Slf4j annotation instead of the following: Logger logger = LoggerFactory.getLogger(AccountTaskController.class); @Autowired diff --git a/src/main/java/com/salessparrow/api/lib/Util.java b/src/main/java/com/salessparrow/api/lib/Util.java index 94470ccf..afce9580 100644 --- a/src/main/java/com/salessparrow/api/lib/Util.java +++ b/src/main/java/com/salessparrow/api/lib/Util.java @@ -173,11 +173,11 @@ public String getDateFormatFromDatetime(Date date) { * @param input The original string containing escaped special characters. * @return A new string where certain special characters have been unescaped. */ - public String unEscapeSpecialCharactersForPlainText(String input) { + public static String unEscapeSpecialCharactersForPlainText(String input) { return input.replace("&", "&"); } - public String replaceNewLineWithBreak(String input) { + public static String replaceNewLineWithBreak(String input) { return input.replace("\n", "
"); } diff --git a/src/main/java/com/salessparrow/api/lib/crmActions/createAccountEvent/CreateSalesforceAccountEvent.java b/src/main/java/com/salessparrow/api/lib/crmActions/createAccountEvent/CreateSalesforceAccountEvent.java index 615a1238..e93fc804 100644 --- a/src/main/java/com/salessparrow/api/lib/crmActions/createAccountEvent/CreateSalesforceAccountEvent.java +++ b/src/main/java/com/salessparrow/api/lib/crmActions/createAccountEvent/CreateSalesforceAccountEvent.java @@ -51,8 +51,7 @@ public CreateEventFormatterDto createEvent(User user, String accountId, CreateAc String salesforceUserId = user.getExternalUserId(); - Util util = new Util(); - String eventDescription = util.unEscapeSpecialCharactersForPlainText(createEventDto.getDescription()); + String eventDescription = Util.unEscapeSpecialCharactersForPlainText(createEventDto.getDescription()); String eventSubject = Util.getTrimmedString(eventDescription, salesforceConstants.salesforceEventSubjectLength()); diff --git a/src/main/java/com/salessparrow/api/lib/crmActions/createAccountNote/CreateSalesforceNote.java b/src/main/java/com/salessparrow/api/lib/crmActions/createAccountNote/CreateSalesforceNote.java index bc5b751a..030a8635 100644 --- a/src/main/java/com/salessparrow/api/lib/crmActions/createAccountNote/CreateSalesforceNote.java +++ b/src/main/java/com/salessparrow/api/lib/crmActions/createAccountNote/CreateSalesforceNote.java @@ -54,13 +54,12 @@ public class CreateSalesforceNote implements CreateNoteInterface { public CreateNoteFormatterDto createNote(SalesforceUser user, String accountId, AccountNoteDto note) { String salesforceUserId = user.getExternalUserId(); - Util util = new Util(); String noteContent = note.getText(); - String unEscapeNoteContent = util.unEscapeSpecialCharactersForPlainText(noteContent); + String unEscapeNoteContent = Util.unEscapeSpecialCharactersForPlainText(noteContent); String noteTitle = Util.getTrimmedString(unEscapeNoteContent, salesforceConstants.salesforceContentNoteTitleLength()); - noteContent = util.replaceNewLineWithBreak(noteContent); + noteContent = Util.replaceNewLineWithBreak(noteContent); String encodedNoteContent = base64Helper.base64Encode(noteContent); Map createNoteBody = new HashMap(); diff --git a/src/main/java/com/salessparrow/api/lib/crmActions/createAccountTask/CreateAccountTaskInterface.java b/src/main/java/com/salessparrow/api/lib/crmActions/createAccountTask/CreateAccountTaskInterface.java index 3ec40ba3..8e044ea7 100644 --- a/src/main/java/com/salessparrow/api/lib/crmActions/createAccountTask/CreateAccountTaskInterface.java +++ b/src/main/java/com/salessparrow/api/lib/crmActions/createAccountTask/CreateAccountTaskInterface.java @@ -7,7 +7,8 @@ import com.salessparrow.api.dto.requestMapper.CreateAccountTaskDto; /** - * CreateAccountTaskInterface interface is interface for createTask for various CRM services + * CreateAccountTaskInterface interface is interface for createTask for various CRM + * services */ @Component public interface CreateAccountTaskInterface { diff --git a/src/main/java/com/salessparrow/api/lib/crmActions/createAccountTask/CreateSalesforceAccountTask.java b/src/main/java/com/salessparrow/api/lib/crmActions/createAccountTask/CreateSalesforceAccountTask.java index 9561abbd..3a8e19de 100644 --- a/src/main/java/com/salessparrow/api/lib/crmActions/createAccountTask/CreateSalesforceAccountTask.java +++ b/src/main/java/com/salessparrow/api/lib/crmActions/createAccountTask/CreateSalesforceAccountTask.java @@ -50,8 +50,8 @@ public CreateTaskFormatterDto createAccountTask(User User, String accountId, Cre String salesforceUserId = User.getExternalUserId(); logger.info("createAccountTask task description: {}", task.getDescription()); - Util util = new Util(); - String unEscapedTaskDescription = util.unEscapeSpecialCharactersForPlainText(task.getDescription()); + + String unEscapedTaskDescription = Util.unEscapeSpecialCharactersForPlainText(task.getDescription()); String taskSubject = getTaskSubjectFromDescription(unEscapedTaskDescription); logger.info("performing create task in salesforce"); diff --git a/src/main/java/com/salessparrow/api/lib/crmActions/getAccountTaskDetails/GetSalesforceAccountTaskDetails.java b/src/main/java/com/salessparrow/api/lib/crmActions/getAccountTaskDetails/GetSalesforceAccountTaskDetails.java index 0af54c29..8fff05b5 100644 --- a/src/main/java/com/salessparrow/api/lib/crmActions/getAccountTaskDetails/GetSalesforceAccountTaskDetails.java +++ b/src/main/java/com/salessparrow/api/lib/crmActions/getAccountTaskDetails/GetSalesforceAccountTaskDetails.java @@ -94,12 +94,14 @@ public GetTaskDetailsFormatterDto parseResponse(String responseBody) { ; TaskEntity taskEntity = new TaskEntity(); - for (JsonNode recordNode : recordsNode) { - ObjectMapper mapper = new ObjectMapper(); - mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES); - SalesforceGetTasksListDto salesforceGetTasksListDto = mapper.convertValue(recordNode, - SalesforceGetTasksListDto.class); - taskEntity = salesforceGetTasksListDto.taskEntity(); + if (recordsNode.size() > 0) { + for (JsonNode recordNode : recordsNode) { + ObjectMapper mapper = new ObjectMapper(); + mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES); + SalesforceGetTasksListDto salesforceGetTasksListDto = mapper.convertValue(recordNode, + SalesforceGetTasksListDto.class); + taskEntity = salesforceGetTasksListDto.taskEntity(); + } } GetTaskDetailsFormatterDto getTaskDetailsFormatterDto = new GetTaskDetailsFormatterDto(); diff --git a/src/main/java/com/salessparrow/api/lib/crmActions/updateAccountEvent/UpdateSalesforceAccountEvent.java b/src/main/java/com/salessparrow/api/lib/crmActions/updateAccountEvent/UpdateSalesforceAccountEvent.java index 3b26d569..ca1c10db 100644 --- a/src/main/java/com/salessparrow/api/lib/crmActions/updateAccountEvent/UpdateSalesforceAccountEvent.java +++ b/src/main/java/com/salessparrow/api/lib/crmActions/updateAccountEvent/UpdateSalesforceAccountEvent.java @@ -49,8 +49,7 @@ public void updateEvent(User user, String accountId, String eventId, UpdateAccou String salesforceUserId = user.getExternalUserId(); - Util util = new Util(); - String eventDescription = util.unEscapeSpecialCharactersForPlainText(updateEventDto.getDescription()); + String eventDescription = Util.unEscapeSpecialCharactersForPlainText(updateEventDto.getDescription()); String eventSubject = Util.getTrimmedString(eventDescription, salesforceConstants.salesforceEventSubjectLength()); diff --git a/src/main/java/com/salessparrow/api/lib/crmActions/updateAccountNote/UpdateSalesforceAccountNote.java b/src/main/java/com/salessparrow/api/lib/crmActions/updateAccountNote/UpdateSalesforceAccountNote.java index ae74146c..a16d58e6 100644 --- a/src/main/java/com/salessparrow/api/lib/crmActions/updateAccountNote/UpdateSalesforceAccountNote.java +++ b/src/main/java/com/salessparrow/api/lib/crmActions/updateAccountNote/UpdateSalesforceAccountNote.java @@ -53,14 +53,12 @@ public void updateNote(User user, String accountId, String noteId, AccountNoteDt logger.info("Update Salesforce Note started"); String salesforceUserId = user.getExternalUserId(); - Util util = new Util(); - String noteContent = accountNoteDto.getText(); - String unEscapeNoteContent = util.unEscapeSpecialCharactersForPlainText(noteContent); + String unEscapeNoteContent = Util.unEscapeSpecialCharactersForPlainText(noteContent); String noteTitle = Util.getTrimmedString(unEscapeNoteContent, salesforceConstants.salesforceContentNoteTitleLength()); - noteContent = util.replaceNewLineWithBreak(noteContent); + noteContent = Util.replaceNewLineWithBreak(noteContent); String encodedNoteContent = base64Helper.base64Encode(noteContent); Map updateNoteBody = new HashMap(); diff --git a/src/main/java/com/salessparrow/api/lib/crmActions/updateAccountTask/UpdateSalesforceAccountTask.java b/src/main/java/com/salessparrow/api/lib/crmActions/updateAccountTask/UpdateSalesforceAccountTask.java index 5f1804d0..7942b9f5 100644 --- a/src/main/java/com/salessparrow/api/lib/crmActions/updateAccountTask/UpdateSalesforceAccountTask.java +++ b/src/main/java/com/salessparrow/api/lib/crmActions/updateAccountTask/UpdateSalesforceAccountTask.java @@ -49,8 +49,7 @@ public void updateTask(User user, String accountId, String taskId, UpdateAccount String salesforceUserId = user.getExternalUserId(); - Util util = new Util(); - String taskDescription = util.unEscapeSpecialCharactersForPlainText(updateTaskDto.getDescription()); + String taskDescription = Util.unEscapeSpecialCharactersForPlainText(updateTaskDto.getDescription()); String taskSubject = Util.getTrimmedString(taskDescription, salesforceConstants.salesforceTaskSubjectLength()); Map updateTaskBody = new HashMap(); From be534d099e176dff250316decb637edd34e040dc Mon Sep 17 00:00:00 2001 From: Raj Shah Date: Mon, 16 Oct 2023 12:06:12 +0530 Subject: [PATCH 33/36] Changed all logger to static final --- .../com/salessparrow/api/controllers/AccountController.java | 2 +- .../salessparrow/api/controllers/AccountEventController.java | 2 +- .../com/salessparrow/api/controllers/AccountNoteController.java | 2 +- .../com/salessparrow/api/controllers/SuggestionsController.java | 2 +- .../com/salessparrow/api/exception/GlobalExceptionHandler.java | 2 +- .../java/com/salessparrow/api/lib/GetCrmActionSuggestions.java | 2 +- .../createAccountEvent/CreateAccountEventFactory.java | 2 +- .../createAccountEvent/CreateSalesforceAccountEvent.java | 2 +- .../crmActions/deleteAccountNote/DeleteAccountNoteFactory.java | 2 +- .../deleteAccountNote/DeleteSalesforceAccountNote.java | 2 +- .../updateAccountEvent/UpdateAccountEventFactory.java | 2 +- .../updateAccountEvent/UpdateSalesforceAccountEvent.java | 2 +- .../crmActions/updateAccountNote/UpdateAccountNoteFactory.java | 2 +- .../updateAccountNote/UpdateSalesforceAccountNote.java | 2 +- .../crmActions/updateAccountTask/UpdateAccountTaskFactory.java | 2 +- .../updateAccountTask/UpdateSalesforceAccountTask.java | 2 +- .../java/com/salessparrow/api/lib/openAi/OpenAiRequest.java | 2 +- .../api/services/accountEvents/CreateAccountEventService.java | 2 +- .../api/services/accountNotes/DeleteAccountNoteService.java | 2 +- .../api/services/suggestions/CrmActionsSuggestionsService.java | 2 +- 20 files changed, 20 insertions(+), 20 deletions(-) diff --git a/src/main/java/com/salessparrow/api/controllers/AccountController.java b/src/main/java/com/salessparrow/api/controllers/AccountController.java index adaa9ab5..4050afa7 100644 --- a/src/main/java/com/salessparrow/api/controllers/AccountController.java +++ b/src/main/java/com/salessparrow/api/controllers/AccountController.java @@ -24,7 +24,7 @@ @Validated public class AccountController { - private Logger logger = org.slf4j.LoggerFactory.getLogger(AccountController.class); + private static final Logger logger = org.slf4j.LoggerFactory.getLogger(AccountController.class); @Autowired private GetAccountListService getAccountListService; diff --git a/src/main/java/com/salessparrow/api/controllers/AccountEventController.java b/src/main/java/com/salessparrow/api/controllers/AccountEventController.java index 1c313ae3..ac28d711 100644 --- a/src/main/java/com/salessparrow/api/controllers/AccountEventController.java +++ b/src/main/java/com/salessparrow/api/controllers/AccountEventController.java @@ -33,7 +33,7 @@ @Validated public class AccountEventController { - private Logger logger = org.slf4j.LoggerFactory.getLogger(AccountEventController.class); + private static final Logger logger = org.slf4j.LoggerFactory.getLogger(AccountEventController.class); @Autowired private CreateAccountEventService createEventService; diff --git a/src/main/java/com/salessparrow/api/controllers/AccountNoteController.java b/src/main/java/com/salessparrow/api/controllers/AccountNoteController.java index c2ef4167..c4bfd8d1 100644 --- a/src/main/java/com/salessparrow/api/controllers/AccountNoteController.java +++ b/src/main/java/com/salessparrow/api/controllers/AccountNoteController.java @@ -32,7 +32,7 @@ @Validated public class AccountNoteController { - private Logger logger = org.slf4j.LoggerFactory.getLogger(AccountNoteController.class); + private static final Logger logger = org.slf4j.LoggerFactory.getLogger(AccountNoteController.class); @Autowired private GetAccountNotesListService getNotesListService; diff --git a/src/main/java/com/salessparrow/api/controllers/SuggestionsController.java b/src/main/java/com/salessparrow/api/controllers/SuggestionsController.java index 0bef0c1e..f07c7df9 100644 --- a/src/main/java/com/salessparrow/api/controllers/SuggestionsController.java +++ b/src/main/java/com/salessparrow/api/controllers/SuggestionsController.java @@ -19,7 +19,7 @@ @Validated public class SuggestionsController { - private Logger logger = org.slf4j.LoggerFactory.getLogger(SuggestionsController.class); + private static final Logger logger = org.slf4j.LoggerFactory.getLogger(SuggestionsController.class); @Autowired private CrmActionsSuggestionsService crmActionsSuggestionsService; diff --git a/src/main/java/com/salessparrow/api/exception/GlobalExceptionHandler.java b/src/main/java/com/salessparrow/api/exception/GlobalExceptionHandler.java index fe628eee..7ed1a7c0 100644 --- a/src/main/java/com/salessparrow/api/exception/GlobalExceptionHandler.java +++ b/src/main/java/com/salessparrow/api/exception/GlobalExceptionHandler.java @@ -26,7 +26,7 @@ @ControllerAdvice public class GlobalExceptionHandler { - private Logger logger = org.slf4j.LoggerFactory.getLogger(GlobalExceptionHandler.class); + private static final Logger logger = org.slf4j.LoggerFactory.getLogger(GlobalExceptionHandler.class); @Autowired private ErrorResponse er; diff --git a/src/main/java/com/salessparrow/api/lib/GetCrmActionSuggestions.java b/src/main/java/com/salessparrow/api/lib/GetCrmActionSuggestions.java index 7d87c30f..fc14fb8c 100644 --- a/src/main/java/com/salessparrow/api/lib/GetCrmActionSuggestions.java +++ b/src/main/java/com/salessparrow/api/lib/GetCrmActionSuggestions.java @@ -39,7 +39,7 @@ public class GetCrmActionSuggestions { private DatetimeFormatValidator datetimeFormatValidator = new DatetimeFormatValidator(); - private Logger logger = org.slf4j.LoggerFactory.getLogger(SuggestionsController.class); + private static final Logger logger = org.slf4j.LoggerFactory.getLogger(SuggestionsController.class); /** * Get the crm action suggestions. diff --git a/src/main/java/com/salessparrow/api/lib/crmActions/createAccountEvent/CreateAccountEventFactory.java b/src/main/java/com/salessparrow/api/lib/crmActions/createAccountEvent/CreateAccountEventFactory.java index 434f8e29..54341752 100644 --- a/src/main/java/com/salessparrow/api/lib/crmActions/createAccountEvent/CreateAccountEventFactory.java +++ b/src/main/java/com/salessparrow/api/lib/crmActions/createAccountEvent/CreateAccountEventFactory.java @@ -17,7 +17,7 @@ @Component public class CreateAccountEventFactory { - private Logger logger = org.slf4j.LoggerFactory.getLogger(CreateAccountEventFactory.class); + private static final Logger logger = org.slf4j.LoggerFactory.getLogger(CreateAccountEventFactory.class); @Autowired private CreateSalesforceAccountEvent createSalesforceEvent; diff --git a/src/main/java/com/salessparrow/api/lib/crmActions/createAccountEvent/CreateSalesforceAccountEvent.java b/src/main/java/com/salessparrow/api/lib/crmActions/createAccountEvent/CreateSalesforceAccountEvent.java index e93fc804..0f689cbd 100644 --- a/src/main/java/com/salessparrow/api/lib/crmActions/createAccountEvent/CreateSalesforceAccountEvent.java +++ b/src/main/java/com/salessparrow/api/lib/crmActions/createAccountEvent/CreateSalesforceAccountEvent.java @@ -31,7 +31,7 @@ @Component public class CreateSalesforceAccountEvent implements CreateAccountEventInterface { - private Logger logger = org.slf4j.LoggerFactory.getLogger(CreateSalesforceAccountEvent.class); + private static final Logger logger = org.slf4j.LoggerFactory.getLogger(CreateSalesforceAccountEvent.class); @Autowired private SalesforceConstants salesforceConstants; diff --git a/src/main/java/com/salessparrow/api/lib/crmActions/deleteAccountNote/DeleteAccountNoteFactory.java b/src/main/java/com/salessparrow/api/lib/crmActions/deleteAccountNote/DeleteAccountNoteFactory.java index c3cfce49..8f32eb8a 100644 --- a/src/main/java/com/salessparrow/api/lib/crmActions/deleteAccountNote/DeleteAccountNoteFactory.java +++ b/src/main/java/com/salessparrow/api/lib/crmActions/deleteAccountNote/DeleteAccountNoteFactory.java @@ -16,7 +16,7 @@ @Component public class DeleteAccountNoteFactory { - private Logger logger = org.slf4j.LoggerFactory.getLogger(DeleteAccountNoteFactory.class); + private static final Logger logger = org.slf4j.LoggerFactory.getLogger(DeleteAccountNoteFactory.class); @Autowired DeleteSalesforceAccountNote getSalesforceNoteDetails; diff --git a/src/main/java/com/salessparrow/api/lib/crmActions/deleteAccountNote/DeleteSalesforceAccountNote.java b/src/main/java/com/salessparrow/api/lib/crmActions/deleteAccountNote/DeleteSalesforceAccountNote.java index 07bd0299..434f08bb 100644 --- a/src/main/java/com/salessparrow/api/lib/crmActions/deleteAccountNote/DeleteSalesforceAccountNote.java +++ b/src/main/java/com/salessparrow/api/lib/crmActions/deleteAccountNote/DeleteSalesforceAccountNote.java @@ -26,7 +26,7 @@ @Component public class DeleteSalesforceAccountNote implements DeleteAccountNoteInterface { - private Logger logger = org.slf4j.LoggerFactory.getLogger(DeleteSalesforceAccountNote.class); + private static final Logger logger = org.slf4j.LoggerFactory.getLogger(DeleteSalesforceAccountNote.class); @Autowired private SalesforceConstants salesforceConstants; diff --git a/src/main/java/com/salessparrow/api/lib/crmActions/updateAccountEvent/UpdateAccountEventFactory.java b/src/main/java/com/salessparrow/api/lib/crmActions/updateAccountEvent/UpdateAccountEventFactory.java index ad9cb5ae..44fe8d5d 100644 --- a/src/main/java/com/salessparrow/api/lib/crmActions/updateAccountEvent/UpdateAccountEventFactory.java +++ b/src/main/java/com/salessparrow/api/lib/crmActions/updateAccountEvent/UpdateAccountEventFactory.java @@ -16,7 +16,7 @@ @Component public class UpdateAccountEventFactory { - private Logger logger = org.slf4j.LoggerFactory.getLogger(UpdateAccountEventFactory.class); + private static final Logger logger = org.slf4j.LoggerFactory.getLogger(UpdateAccountEventFactory.class); @Autowired private UpdateSalesforceAccountEvent updateSalesforceEvent; diff --git a/src/main/java/com/salessparrow/api/lib/crmActions/updateAccountEvent/UpdateSalesforceAccountEvent.java b/src/main/java/com/salessparrow/api/lib/crmActions/updateAccountEvent/UpdateSalesforceAccountEvent.java index ca1c10db..2c1299ed 100644 --- a/src/main/java/com/salessparrow/api/lib/crmActions/updateAccountEvent/UpdateSalesforceAccountEvent.java +++ b/src/main/java/com/salessparrow/api/lib/crmActions/updateAccountEvent/UpdateSalesforceAccountEvent.java @@ -29,7 +29,7 @@ @Component public class UpdateSalesforceAccountEvent implements UpdateAccountEventInterface { - private Logger logger = org.slf4j.LoggerFactory.getLogger(UpdateSalesforceAccountEvent.class); + private static final Logger logger = org.slf4j.LoggerFactory.getLogger(UpdateSalesforceAccountEvent.class); @Autowired private SalesforceConstants salesforceConstants; diff --git a/src/main/java/com/salessparrow/api/lib/crmActions/updateAccountNote/UpdateAccountNoteFactory.java b/src/main/java/com/salessparrow/api/lib/crmActions/updateAccountNote/UpdateAccountNoteFactory.java index 3f08cd00..1b304287 100644 --- a/src/main/java/com/salessparrow/api/lib/crmActions/updateAccountNote/UpdateAccountNoteFactory.java +++ b/src/main/java/com/salessparrow/api/lib/crmActions/updateAccountNote/UpdateAccountNoteFactory.java @@ -16,7 +16,7 @@ @Component public class UpdateAccountNoteFactory { - private Logger logger = org.slf4j.LoggerFactory.getLogger(UpdateAccountNoteFactory.class); + private static final Logger logger = org.slf4j.LoggerFactory.getLogger(UpdateAccountNoteFactory.class); @Autowired private UpdateSalesforceAccountNote updateSalesforceNote; diff --git a/src/main/java/com/salessparrow/api/lib/crmActions/updateAccountNote/UpdateSalesforceAccountNote.java b/src/main/java/com/salessparrow/api/lib/crmActions/updateAccountNote/UpdateSalesforceAccountNote.java index a16d58e6..63ec6929 100644 --- a/src/main/java/com/salessparrow/api/lib/crmActions/updateAccountNote/UpdateSalesforceAccountNote.java +++ b/src/main/java/com/salessparrow/api/lib/crmActions/updateAccountNote/UpdateSalesforceAccountNote.java @@ -30,7 +30,7 @@ @Component public class UpdateSalesforceAccountNote implements UpdateAccountNoteInterface { - private Logger logger = org.slf4j.LoggerFactory.getLogger(UpdateSalesforceAccountNote.class); + private static final Logger logger = org.slf4j.LoggerFactory.getLogger(UpdateSalesforceAccountNote.class); @Autowired private SalesforceConstants salesforceConstants; diff --git a/src/main/java/com/salessparrow/api/lib/crmActions/updateAccountTask/UpdateAccountTaskFactory.java b/src/main/java/com/salessparrow/api/lib/crmActions/updateAccountTask/UpdateAccountTaskFactory.java index fefefb57..85b14968 100644 --- a/src/main/java/com/salessparrow/api/lib/crmActions/updateAccountTask/UpdateAccountTaskFactory.java +++ b/src/main/java/com/salessparrow/api/lib/crmActions/updateAccountTask/UpdateAccountTaskFactory.java @@ -16,7 +16,7 @@ @Component public class UpdateAccountTaskFactory { - private Logger logger = org.slf4j.LoggerFactory.getLogger(UpdateAccountTaskFactory.class); + private static final Logger logger = org.slf4j.LoggerFactory.getLogger(UpdateAccountTaskFactory.class); @Autowired private UpdateSalesforceAccountTask updateSalesforceTask; diff --git a/src/main/java/com/salessparrow/api/lib/crmActions/updateAccountTask/UpdateSalesforceAccountTask.java b/src/main/java/com/salessparrow/api/lib/crmActions/updateAccountTask/UpdateSalesforceAccountTask.java index 7942b9f5..6bf18ae4 100644 --- a/src/main/java/com/salessparrow/api/lib/crmActions/updateAccountTask/UpdateSalesforceAccountTask.java +++ b/src/main/java/com/salessparrow/api/lib/crmActions/updateAccountTask/UpdateSalesforceAccountTask.java @@ -29,7 +29,7 @@ @Component public class UpdateSalesforceAccountTask implements UpdateAccountTaskInterface { - private Logger logger = org.slf4j.LoggerFactory.getLogger(UpdateSalesforceAccountTask.class); + private static final Logger logger = org.slf4j.LoggerFactory.getLogger(UpdateSalesforceAccountTask.class); @Autowired private SalesforceConstants salesforceConstants; diff --git a/src/main/java/com/salessparrow/api/lib/openAi/OpenAiRequest.java b/src/main/java/com/salessparrow/api/lib/openAi/OpenAiRequest.java index c9389108..e29c828d 100644 --- a/src/main/java/com/salessparrow/api/lib/openAi/OpenAiRequest.java +++ b/src/main/java/com/salessparrow/api/lib/openAi/OpenAiRequest.java @@ -24,7 +24,7 @@ public class OpenAiRequest { @Autowired private OpenAiConstants openAiConstants; - private Logger logger = org.slf4j.LoggerFactory.getLogger(SuggestionsController.class); + private static final Logger logger = org.slf4j.LoggerFactory.getLogger(SuggestionsController.class); /** * Make a request to the OpenAI API. diff --git a/src/main/java/com/salessparrow/api/services/accountEvents/CreateAccountEventService.java b/src/main/java/com/salessparrow/api/services/accountEvents/CreateAccountEventService.java index 6ce0a0dd..ae21eb43 100644 --- a/src/main/java/com/salessparrow/api/services/accountEvents/CreateAccountEventService.java +++ b/src/main/java/com/salessparrow/api/services/accountEvents/CreateAccountEventService.java @@ -18,7 +18,7 @@ @Service public class CreateAccountEventService { - private Logger logger = org.slf4j.LoggerFactory.getLogger(CreateAccountEventService.class); + private static final Logger logger = org.slf4j.LoggerFactory.getLogger(CreateAccountEventService.class); @Autowired private CreateAccountEventFactory createAccountEventFactory; diff --git a/src/main/java/com/salessparrow/api/services/accountNotes/DeleteAccountNoteService.java b/src/main/java/com/salessparrow/api/services/accountNotes/DeleteAccountNoteService.java index 2c5843b9..2aaf22bf 100644 --- a/src/main/java/com/salessparrow/api/services/accountNotes/DeleteAccountNoteService.java +++ b/src/main/java/com/salessparrow/api/services/accountNotes/DeleteAccountNoteService.java @@ -16,7 +16,7 @@ @Service public class DeleteAccountNoteService { - private Logger logger = org.slf4j.LoggerFactory.getLogger(DeleteAccountNoteService.class); + private static final Logger logger = org.slf4j.LoggerFactory.getLogger(DeleteAccountNoteService.class); @Autowired private DeleteAccountNoteFactory deleteAccountNoteFactory; diff --git a/src/main/java/com/salessparrow/api/services/suggestions/CrmActionsSuggestionsService.java b/src/main/java/com/salessparrow/api/services/suggestions/CrmActionsSuggestionsService.java index 2923e2e2..f2ad3ecd 100644 --- a/src/main/java/com/salessparrow/api/services/suggestions/CrmActionsSuggestionsService.java +++ b/src/main/java/com/salessparrow/api/services/suggestions/CrmActionsSuggestionsService.java @@ -18,7 +18,7 @@ public class CrmActionsSuggestionsService { @Autowired private GetCrmActionSuggestions getCrmActionSuggestions; - private Logger logger = org.slf4j.LoggerFactory.getLogger(SuggestionsController.class); + private static final Logger logger = org.slf4j.LoggerFactory.getLogger(SuggestionsController.class); public CrmActionSuggestionsFormatterDto getSuggestions(CrmActionsSuggestionsDto crmActionsSuggestionsDto) { logger.info("Crm actions service called"); From 491cff015d4a366ba30266d4b51da04bb6043b9f Mon Sep 17 00:00:00 2001 From: Raj Shah Date: Mon, 16 Oct 2023 14:08:23 +0530 Subject: [PATCH 34/36] Removed Owner class from SalesforceGetEventsListDto --- .../deleteAccountEvent/DeleteSalesforceAccountEvent.java | 3 ++- .../lib/salesforce/dto/SalesforceGetEventsListDto.java | 8 -------- 2 files changed, 2 insertions(+), 9 deletions(-) diff --git a/src/main/java/com/salessparrow/api/lib/crmActions/deleteAccountEvent/DeleteSalesforceAccountEvent.java b/src/main/java/com/salessparrow/api/lib/crmActions/deleteAccountEvent/DeleteSalesforceAccountEvent.java index e8129f75..9bb2200a 100644 --- a/src/main/java/com/salessparrow/api/lib/crmActions/deleteAccountEvent/DeleteSalesforceAccountEvent.java +++ b/src/main/java/com/salessparrow/api/lib/crmActions/deleteAccountEvent/DeleteSalesforceAccountEvent.java @@ -27,6 +27,8 @@ @Component public class DeleteSalesforceAccountEvent implements DeleteAccountEventInterface { + private final Util util = new Util(); + Logger logger = LoggerFactory.getLogger(DeleteSalesforceAccountEvent.class); @Autowired @@ -67,7 +69,6 @@ public void deleteAccountEvent(User user, String accountId, String eventId) { */ private void parseResponse(String responseBody) { logger.info("Parsing response body"); - Util util = new Util(); JsonNode rootNode = util.getJsonNode(responseBody); JsonNode deleteEventCompositeResponse = rootNode.get("compositeResponse").get(0); diff --git a/src/main/java/com/salessparrow/api/lib/salesforce/dto/SalesforceGetEventsListDto.java b/src/main/java/com/salessparrow/api/lib/salesforce/dto/SalesforceGetEventsListDto.java index 496a49cb..26bf7e84 100644 --- a/src/main/java/com/salessparrow/api/lib/salesforce/dto/SalesforceGetEventsListDto.java +++ b/src/main/java/com/salessparrow/api/lib/salesforce/dto/SalesforceGetEventsListDto.java @@ -32,14 +32,6 @@ private class CreatedBy { } - @Data - @JsonNaming(PropertyNamingStrategies.UpperCamelCaseStrategy.class) - private class Owner { - - private String name; - - } - public EventEntity eventEntity() { EventEntity eventEntity = new EventEntity(); From 32264e69dc47ce5b6a5a25554dd207ebc5ecbed3 Mon Sep 17 00:00:00 2001 From: Raj Shah Date: Mon, 16 Oct 2023 16:39:03 +0530 Subject: [PATCH 35/36] Removed extra semicolons --- .../GetSalesforceAccountEventDetails.java | 15 ++++++++------- .../GetSalesforceAccountEventsList.java | 1 - .../GetSalesforceAccountTaskDetails.java | 5 ++--- .../GetSalesforceAccountTasksList.java | 1 - 4 files changed, 10 insertions(+), 12 deletions(-) diff --git a/src/main/java/com/salessparrow/api/lib/crmActions/getAccountEventDetails/GetSalesforceAccountEventDetails.java b/src/main/java/com/salessparrow/api/lib/crmActions/getAccountEventDetails/GetSalesforceAccountEventDetails.java index a32eae5b..7a29d623 100644 --- a/src/main/java/com/salessparrow/api/lib/crmActions/getAccountEventDetails/GetSalesforceAccountEventDetails.java +++ b/src/main/java/com/salessparrow/api/lib/crmActions/getAccountEventDetails/GetSalesforceAccountEventDetails.java @@ -91,15 +91,16 @@ public GetEventDetailsFormatterDto parseResponse(String responseBody) { } JsonNode recordsNode = rootNode.get("compositeResponse").get(0).get("body").get("records"); - ; EventEntity eventEntity = new EventEntity(); - for (JsonNode recordNode : recordsNode) { - ObjectMapper mapper = new ObjectMapper(); - mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES); - SalesforceGetEventsListDto salesforceGetEventsListDto = mapper.convertValue(recordNode, - SalesforceGetEventsListDto.class); - eventEntity = salesforceGetEventsListDto.eventEntity(); + if (recordsNode.size() > 0) { + for (JsonNode recordNode : recordsNode) { + ObjectMapper mapper = new ObjectMapper(); + mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES); + SalesforceGetEventsListDto salesforceGetEventsListDto = mapper.convertValue(recordNode, + SalesforceGetEventsListDto.class); + eventEntity = salesforceGetEventsListDto.eventEntity(); + } } GetEventDetailsFormatterDto getEventDetailsFormatterDto = new GetEventDetailsFormatterDto(); diff --git a/src/main/java/com/salessparrow/api/lib/crmActions/getAccountEventsList/GetSalesforceAccountEventsList.java b/src/main/java/com/salessparrow/api/lib/crmActions/getAccountEventsList/GetSalesforceAccountEventsList.java index 4e1ae8ab..6802ffcf 100644 --- a/src/main/java/com/salessparrow/api/lib/crmActions/getAccountEventsList/GetSalesforceAccountEventsList.java +++ b/src/main/java/com/salessparrow/api/lib/crmActions/getAccountEventsList/GetSalesforceAccountEventsList.java @@ -98,7 +98,6 @@ public GetEventsListFormatterDto parseResponse(String responseBody) { } JsonNode recordsNode = rootNode.get("compositeResponse").get(0).get("body").get("records"); - ; for (JsonNode recordNode : recordsNode) { ObjectMapper mapper = new ObjectMapper(); diff --git a/src/main/java/com/salessparrow/api/lib/crmActions/getAccountTaskDetails/GetSalesforceAccountTaskDetails.java b/src/main/java/com/salessparrow/api/lib/crmActions/getAccountTaskDetails/GetSalesforceAccountTaskDetails.java index 8fff05b5..f269ec86 100644 --- a/src/main/java/com/salessparrow/api/lib/crmActions/getAccountTaskDetails/GetSalesforceAccountTaskDetails.java +++ b/src/main/java/com/salessparrow/api/lib/crmActions/getAccountTaskDetails/GetSalesforceAccountTaskDetails.java @@ -91,13 +91,12 @@ public GetTaskDetailsFormatterDto parseResponse(String responseBody) { } JsonNode recordsNode = rootNode.get("compositeResponse").get(0).get("body").get("records"); - ; TaskEntity taskEntity = new TaskEntity(); if (recordsNode.size() > 0) { + ObjectMapper mapper = new ObjectMapper(); + mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES); for (JsonNode recordNode : recordsNode) { - ObjectMapper mapper = new ObjectMapper(); - mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES); SalesforceGetTasksListDto salesforceGetTasksListDto = mapper.convertValue(recordNode, SalesforceGetTasksListDto.class); taskEntity = salesforceGetTasksListDto.taskEntity(); diff --git a/src/main/java/com/salessparrow/api/lib/crmActions/getAccountTasksList/GetSalesforceAccountTasksList.java b/src/main/java/com/salessparrow/api/lib/crmActions/getAccountTasksList/GetSalesforceAccountTasksList.java index 5d29e90d..24bc2a27 100644 --- a/src/main/java/com/salessparrow/api/lib/crmActions/getAccountTasksList/GetSalesforceAccountTasksList.java +++ b/src/main/java/com/salessparrow/api/lib/crmActions/getAccountTasksList/GetSalesforceAccountTasksList.java @@ -98,7 +98,6 @@ public GetTasksListFormatterDto parseResponse(String responseBody) { } JsonNode recordsNode = rootNode.get("compositeResponse").get(0).get("body").get("records"); - ; for (JsonNode recordNode : recordsNode) { ObjectMapper mapper = new ObjectMapper(); From 2dd7180a8bd8aadd7200272276f1bad452009b67 Mon Sep 17 00:00:00 2001 From: Raj Shah Date: Fri, 27 Oct 2023 13:33:18 +0530 Subject: [PATCH 36/36] Added test cases in update event and task --- .../updateAccountEvent.scenarios.json | 154 ++++++++++++------ .../updateAccountTask.scenarios.json | 102 ++++++++++++ 2 files changed, 210 insertions(+), 46 deletions(-) diff --git a/src/test/resources/data/functional/controllers/accountEventController/updateAccountEvent.scenarios.json b/src/test/resources/data/functional/controllers/accountEventController/updateAccountEvent.scenarios.json index 5e1d460e..14ca4652 100644 --- a/src/test/resources/data/functional/controllers/accountEventController/updateAccountEvent.scenarios.json +++ b/src/test/resources/data/functional/controllers/accountEventController/updateAccountEvent.scenarios.json @@ -1,43 +1,105 @@ [ - { - "description": "Should successfully update the event for given event id", - "input": { - "body": { - "description":"Create Event", - "start_datetime": "2023-07-21T13:12:17.000+0000", - "end_datetime": "2023-07-22T13:12:17.000+0000" - }, - "accountId": "0011e00000bWSxdAAG", - "eventId":"0691e000001X1yTAAS" + { + "description": "Should successfully update the event for given event id", + "input": { + "body": { + "description":"Create Event", + "start_datetime": "2023-07-21T13:12:17.000+0000", + "end_datetime": "2023-07-22T13:12:17.000+0000" }, - "mocks": { - "makeCompositeRequest": { - "compositeResponse": [ - { - "body": null, - "httpHeaders": {}, - "httpStatusCode": 200, - "referenceId": "UpdateEvent" - } - ] - } + "accountId": "0011e00000bWSxdAAG", + "eventId":"0691e000001X1yTAAS" + }, + "mocks": { + "makeCompositeRequest": { + "compositeResponse": [ + { + "body": null, + "httpHeaders": {}, + "httpStatusCode": 200, + "referenceId": "UpdateEvent" + } + ] + } + }, + "output": {} + }, + { + "description": "Should fail when event task description is not provided", + "input": { + "body": { + "start_datetime": "2023-07-21T13:12:17.000+0000", + "end_datetime": "2023-07-22T13:12:17.000+0000" + }, + "accountId": "0011e00000bWSxdAAG" + }, + "mocks": {}, + "output": { + "http_code": 400, + "message": "At least one parameter is invalid or missing.", + "code": "INVALID_PARAMS", + "internal_error_identifier": "b_2", + "param_errors": [ + "missing_description" + ] + } + }, + { + "description": "Should fail when the event start_datetime is invalid", + "input": { + "body": { + "description":"Create Event", + "start_datetime": "2023-07-21", + "end_datetime": "2023-07-22T13:12:17.000+0000" }, - "output": {} + "accountId": "0011e00000bWSxdAAG" }, - { - "description": "should return error response when event id is invalid", - "input": { - "body": { - "description":"Create Event", - "start_datetime": "2023-07-21T13:12:17.000+0000", - "end_datetime": "2023-07-22T13:12:17.000+0000" - }, - "accountId": "0011e00000bWSxdAAG", - "eventId":"invalidEventId" + "mocks": {}, + "output": { + "http_code": 400, + "message": "At least one parameter is invalid or missing.", + "code": "INVALID_PARAMS", + "internal_error_identifier": "b_2", + "param_errors": [ + "invalid_start_datetime" + ] + } + }, + { + "description": "Should fail when the event end_datetime is invalid", + "input": { + "body": { + "description":"Create Event", + "start_datetime": "2023-07-22T13:12:17.000+0000", + "end_datetime": "2023-07-22T13:12.000+0000" + }, + "accountId": "0011e00000bWSxdAAG" + }, + "mocks": {}, + "output": { + "http_code": 400, + "message": "At least one parameter is invalid or missing.", + "code": "INVALID_PARAMS", + "internal_error_identifier": "b_2", + "param_errors": [ + "invalid_end_datetime" + ] + } + }, + { + "description": "should return error response when event id is invalid", + "input": { + "body": { + "description":"Create Event", + "start_datetime": "2023-07-21T13:12:17.000+0000", + "end_datetime": "2023-07-22T13:12:17.000+0000" }, - "mocks": { - "makeCompositeRequest": { - "compositeResponse": [ + "accountId": "0011e00000bWSxdAAG", + "eventId":"invalidEventId" + }, + "mocks": { + "makeCompositeRequest": { + "compositeResponse": [ { "body": [ { @@ -51,15 +113,15 @@ } ] } - }, - "output": { - "http_code": 400, - "message": "At least one parameter is invalid or missing.", - "code": "INVALID_PARAMS", - "internal_error_identifier": "l_ua_uae_usae_pr_1", - "param_errors": [ - "invalid_event_id" - ] - } + }, + "output": { + "http_code": 400, + "message": "At least one parameter is invalid or missing.", + "code": "INVALID_PARAMS", + "internal_error_identifier": "l_ua_uae_usae_pr_1", + "param_errors": [ + "invalid_event_id" + ] } - ] \ No newline at end of file + } +] \ No newline at end of file diff --git a/src/test/resources/data/functional/controllers/accountTaskController/updateAccountTask.scenarios.json b/src/test/resources/data/functional/controllers/accountTaskController/updateAccountTask.scenarios.json index fa0533bb..35226689 100644 --- a/src/test/resources/data/functional/controllers/accountTaskController/updateAccountTask.scenarios.json +++ b/src/test/resources/data/functional/controllers/accountTaskController/updateAccountTask.scenarios.json @@ -24,6 +24,108 @@ }, "output": {} }, + { + "description": "Should fail when the task description is empty", + "input": { + "body": { + "crm_organization_user_id":"0011e00000bWSxdAA1", + "description":"", + "due_date":"2023-12-01" + }, + "accountId": "0011e00000bWSxdAAG" + }, + "mocks": {}, + "output": { + "http_code": 400, + "message": "At least one parameter is invalid or missing.", + "code": "INVALID_PARAMS", + "internal_error_identifier": "b_2", + "param_errors": [ + "missing_description" + ] + } + }, + { + "description": "Should fail when the task description is not provided", + "input": { + "body": { + "crm_organization_user_id":"0011e00000bWSxdAA1", + "due_date":"2023-12-01" + }, + "accountId": "0011e00000bWSxdAAG" + }, + "mocks": {}, + "output": { + "http_code": 400, + "message": "At least one parameter is invalid or missing.", + "code": "INVALID_PARAMS", + "internal_error_identifier": "b_2", + "param_errors": [ + "missing_description" + ] + } + }, + { + "description": "Should fail when the task due_date is not provided", + "input": { + "body": { + "crm_organization_user_id":"0011e00000bWSxdAA1", + "description":"Update remaining documentations" + }, + "accountId": "0011e00000bWSxdAAG" + }, + "mocks": {}, + "output": { + "http_code": 400, + "message": "At least one parameter is invalid or missing.", + "code": "INVALID_PARAMS", + "internal_error_identifier": "b_2", + "param_errors": [ + "invalid_due_date" + ] + } + }, + { + "description": "Should fail when the task crm_organization_user_id is not provided", + "input": { + "body": { + "description":"Update remaining documentations", + "due_date":"2023-12-01" + }, + "accountId": "0011e00000bWSxdAAG" + }, + "mocks": {}, + "output": { + "http_code": 400, + "message": "At least one parameter is invalid or missing.", + "code": "INVALID_PARAMS", + "internal_error_identifier": "b_2", + "param_errors": [ + "missing_crm_organization_user_id" + ] + } + }, + { + "description": "Should fail when the task Due is not valid", + "input": { + "body": { + "crm_organization_user_id":"0011e00000bWSxdAA1", + "description":"Update remaining documentations", + "due_date":"2023-120-01" + }, + "accountId": "0011e00000bWSxdAAG" + }, + "mocks": {}, + "output": { + "http_code": 400, + "message": "At least one parameter is invalid or missing.", + "code": "INVALID_PARAMS", + "internal_error_identifier": "b_2", + "param_errors": [ + "invalid_due_date" + ] + } + }, { "description": "should return error response when task id is invalid", "input": {