Skip to content

Commit

Permalink
Merge pull request #108 from TrueSparrowSystems/create-accounts-event
Browse files Browse the repository at this point in the history
Code Review Changes
  • Loading branch information
Raj-Shah1 authored Oct 16, 2023
2 parents 6c420bf + 32264e6 commit eaaf3f7
Show file tree
Hide file tree
Showing 34 changed files with 68 additions and 74 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
10 changes: 7 additions & 3 deletions src/main/java/com/salessparrow/api/lib/Util.java
Original file line number Diff line number Diff line change
Expand Up @@ -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", "<br>");
}

Expand All @@ -187,7 +187,11 @@ public String replaceNewLineWithBreak(String input) {
* @param length
* @return String
*/
public String getTrimmedString(String input, Integer length) {
public static String getTrimmedString(String input, Integer length) {
if (input == null) {
return null;
}

if (input.length() < length) {
return input;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -51,9 +51,8 @@ public CreateEventFormatterDto createEvent(User user, String accountId, CreateAc

String salesforceUserId = user.getExternalUserId();

Util util = new Util();
String eventDescription = util.unEscapeSpecialCharactersForPlainText(createEventDto.getDescription());
String eventSubject = util.getTrimmedString(eventDescription,
String eventDescription = Util.unEscapeSpecialCharactersForPlainText(createEventDto.getDescription());
String eventSubject = Util.getTrimmedString(eventDescription,
salesforceConstants.salesforceEventSubjectLength());

Map<String, String> createEventBody = new HashMap<String, String>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 noteTitle = util.getTrimmedString(unEscapeNoteContent,
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<String, String> createNoteBody = new HashMap<String, String>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@
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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@
* account for salesforce.
*/
@Component
public class DeleteSalesforceAccountEvent implements DeleteAccountEvent {
public class DeleteSalesforceAccountEvent implements DeleteAccountEventInterface {

private final Util util = new Util();

Logger logger = LoggerFactory.getLogger(DeleteSalesforceAccountEvent.class);

Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,15 +91,16 @@ public GetTaskDetailsFormatterDto parseResponse(String responseBody) {
}

JsonNode recordsNode = rootNode.get("compositeResponse").get(0).get("body").get("records");
;

TaskEntity taskEntity = new TaskEntity();
for (JsonNode recordNode : recordsNode) {
if (recordsNode.size() > 0) {
ObjectMapper mapper = new ObjectMapper();
mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
SalesforceGetTasksListDto salesforceGetTasksListDto = mapper.convertValue(recordNode,
SalesforceGetTasksListDto.class);
taskEntity = salesforceGetTasksListDto.taskEntity();
for (JsonNode recordNode : recordsNode) {
SalesforceGetTasksListDto salesforceGetTasksListDto = mapper.convertValue(recordNode,
SalesforceGetTasksListDto.class);
taskEntity = salesforceGetTasksListDto.taskEntity();
}
}

GetTaskDetailsFormatterDto getTaskDetailsFormatterDto = new GetTaskDetailsFormatterDto();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -49,9 +49,8 @@ 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 eventSubject = util.getTrimmedString(eventDescription,
String eventDescription = Util.unEscapeSpecialCharactersForPlainText(updateEventDto.getDescription());
String eventSubject = Util.getTrimmedString(eventDescription,
salesforceConstants.salesforceEventSubjectLength());

Map<String, String> updateEventBody = new HashMap<String, String>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 noteTitle = util.getTrimmedString(unEscapeNoteContent,
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<String, String> updateNoteBody = new HashMap<String, String>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -49,9 +49,8 @@ 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 taskSubject = util.getTrimmedString(taskDescription, salesforceConstants.salesforceTaskSubjectLength());
String taskDescription = Util.unEscapeSpecialCharactersForPlainText(updateTaskDto.getDescription());
String taskSubject = Util.getTrimmedString(taskDescription, salesforceConstants.salesforceTaskSubjectLength());

Map<String, String> updateTaskBody = new HashMap<String, String>();
updateTaskBody.put("Subject", taskSubject);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 "
Expand Down Expand Up @@ -46,7 +47,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"
Expand Down
Loading

0 comments on commit eaaf3f7

Please sign in to comment.