Skip to content

Commit

Permalink
Tidy up and refactor customer mgmt related classes (#49)
Browse files Browse the repository at this point in the history
  • Loading branch information
acltabontabon authored Dec 26, 2024
1 parent fca655b commit 7e86f8d
Show file tree
Hide file tree
Showing 25 changed files with 129 additions and 119 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ public class OpenWealthApiProperties {

private String baseUrl;
private String accessToken;
private CustomerManagement customerManagement;
private CustomerManagementResourcePaths customerManagementResourcePaths;

@Data
public static class CustomerManagement {
public static class CustomerManagementResourcePaths {
private String newCustomerDetails;
private String customers;
private String customer;
Expand All @@ -36,5 +36,4 @@ public static class CustomerManagement {
private String prospectPreCheck;
private String prospectPreCheckStatus;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
@AutoConfiguration
@PropertySource("classpath:openwealth.properties")
@EnableConfigurationProperties(OpenWealthApiProperties.class)
public class CustomerManagementConfig {
public class OpenWealthAutoConfiguration {

@Bean
@ConditionalOnMissingBean
Expand All @@ -38,7 +38,7 @@ public RestClient openWealthRestClient(RestClient.Builder builder, OpenWealthApi
@Bean
@ConditionalOnMissingBean
public CustomerService customerService(RestClient openWealthRestClient, OpenWealthApiProperties openWealthApiProperties) {
return new CustomerService(openWealthRestClient, openWealthApiProperties.getCustomerManagement());
return new CustomerService(openWealthRestClient, openWealthApiProperties.getCustomerManagementResourcePaths());
}

@Bean
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import java.util.function.Consumer;

public abstract class CreateAsyncCommand<T> extends AsyncCommand<T> {
public abstract class CreateCommand<T> extends AsyncCommand<T> {

public T submit() {
return execute();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.acltabontabon.openwealth.services;

import java.util.function.Consumer;
import lombok.Getter;

public abstract class DeleteCommand extends AsyncCommand<Void> {

public void submit() {
execute();
}

public void submitAsync(Consumer<Void> success, Consumer<Throwable> error) {
executeAsync(success, error);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import java.util.function.Consumer;

public abstract class QueryAsyncCommand<T> extends AsyncCommand<T> {
public abstract class QueryCommand<T> extends AsyncCommand<T> {

public T fetch() {
return execute();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,23 @@

import static com.acltabontabon.openwealth.configs.Constants.HEADER_CORRELATION_ID;

import com.acltabontabon.openwealth.configs.OpenWealthApiProperties;
import com.acltabontabon.openwealth.configs.OpenWealthApiProperties.CustomerManagementResourcePaths;
import com.acltabontabon.openwealth.dtos.ApiResponse;
import com.acltabontabon.openwealth.dtos.ContactResponse;
import com.acltabontabon.openwealth.models.Contact;
import com.acltabontabon.openwealth.services.CreateAsyncCommand;
import com.acltabontabon.openwealth.services.CreateCommand;
import lombok.RequiredArgsConstructor;
import org.springframework.web.client.RestClient;

@RequiredArgsConstructor
public class ContactCreator extends CreateAsyncCommand<ApiResponse> {
public class ContactCreator extends CreateCommand<ApiResponse> {

private final RestClient restClient;
private final OpenWealthApiProperties.CustomerManagement apiProperties;
private final CustomerManagementResourcePaths apiProperties;

private final String correlationId;
private final String customerId;
private final String personId;
private final String correlationId;

private final Contact newContact;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,36 +2,35 @@

import static com.acltabontabon.openwealth.configs.Constants.HEADER_CORRELATION_ID;

import com.acltabontabon.openwealth.configs.OpenWealthApiProperties;
import com.acltabontabon.openwealth.dtos.ApiResponse;
import com.acltabontabon.openwealth.dtos.GenericResponse;
import com.acltabontabon.openwealth.services.CreateAsyncCommand;
import com.acltabontabon.openwealth.configs.OpenWealthApiProperties.CustomerManagementResourcePaths;
import com.acltabontabon.openwealth.services.DeleteCommand;
import lombok.RequiredArgsConstructor;
import org.springframework.web.client.RestClient;

@SuppressWarnings("rawtypes")
@RequiredArgsConstructor
public class ContactDeleter extends CreateAsyncCommand<ApiResponse> {
public class ContactDeleter extends DeleteCommand {

private final RestClient restClient;
private final OpenWealthApiProperties.CustomerManagement apiProperties;
private final CustomerManagementResourcePaths apiProperties;

private final String correlationId;
private final String customerId;
private final String personId;
private final String contactId;
private final String correlationId;

@Override
protected ApiResponse execute() {
protected Void execute() {
try {
restClient.delete()
.uri(builder -> builder.path(apiProperties.getPersonContact()).build(this.customerId, this.personId, this.contactId))
.header(HEADER_CORRELATION_ID, this.correlationId)
.retrieve()
.toBodilessEntity();

return new GenericResponse<>();
} catch (Exception e) {
throw new RuntimeException("Failed to delete contact details", e);
}

return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,27 @@

import static com.acltabontabon.openwealth.configs.Constants.HEADER_CORRELATION_ID;

import com.acltabontabon.openwealth.configs.OpenWealthApiProperties;
import com.acltabontabon.openwealth.configs.OpenWealthApiProperties.CustomerManagementResourcePaths;
import com.acltabontabon.openwealth.dtos.GenericResponse;
import com.acltabontabon.openwealth.models.Contact;
import com.acltabontabon.openwealth.services.QueryAsyncCommand;
import com.acltabontabon.openwealth.services.QueryCommand;
import java.util.List;
import lombok.RequiredArgsConstructor;
import org.springframework.core.ParameterizedTypeReference;
import org.springframework.web.client.RestClient;

@RequiredArgsConstructor
public class ContactQuery extends QueryAsyncCommand<GenericResponse<List<Contact>>> {
public class ContactQuery extends QueryCommand<GenericResponse<List<Contact>>> {

private final RestClient restClient;
private final OpenWealthApiProperties.CustomerManagement apiProperties;
private final CustomerManagementResourcePaths apiProperties;

private final String correlationId;
private final String customerId;
private final String personId;
private final String correlationId;

public SingleContactQuery withContactId(String contactId) {
return new SingleContactQuery(restClient, apiProperties, customerId, personId, contactId, this.correlationId);
return new SingleContactQuery(restClient, apiProperties, this.correlationId, customerId, personId, contactId);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,19 @@

import static com.acltabontabon.openwealth.configs.Constants.HEADER_CORRELATION_ID;

import com.acltabontabon.openwealth.configs.OpenWealthApiProperties;
import com.acltabontabon.openwealth.configs.OpenWealthApiProperties.CustomerManagementResourcePaths;
import com.acltabontabon.openwealth.dtos.ApiResponse;
import com.acltabontabon.openwealth.dtos.GenericResponse;
import com.acltabontabon.openwealth.models.Contact;
import com.acltabontabon.openwealth.services.CreateAsyncCommand;
import com.acltabontabon.openwealth.services.CreateCommand;
import lombok.RequiredArgsConstructor;
import org.springframework.web.client.RestClient;

@RequiredArgsConstructor
public class ContactUpdater extends CreateAsyncCommand<ApiResponse> {
public class ContactUpdater extends CreateCommand<ApiResponse> {

private final RestClient restClient;
private final OpenWealthApiProperties.CustomerManagement apiProperties;
private final CustomerManagementResourcePaths apiProperties;

private final String customerId;
private final String personId;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,23 @@

import static com.acltabontabon.openwealth.configs.Constants.HEADER_CORRELATION_ID;

import com.acltabontabon.openwealth.configs.OpenWealthApiProperties;
import com.acltabontabon.openwealth.configs.OpenWealthApiProperties.CustomerManagementResourcePaths;
import com.acltabontabon.openwealth.dtos.GenericResponse;
import com.acltabontabon.openwealth.models.Contact;
import com.acltabontabon.openwealth.services.QueryAsyncCommand;
import com.acltabontabon.openwealth.services.QueryCommand;
import lombok.RequiredArgsConstructor;
import org.springframework.web.client.RestClient;

@RequiredArgsConstructor
public class SingleContactQuery extends QueryAsyncCommand<GenericResponse<Contact>> {
public class SingleContactQuery extends QueryCommand<GenericResponse<Contact>> {

private final RestClient restClient;
private final OpenWealthApiProperties.CustomerManagement apiProperties;
private final CustomerManagementResourcePaths apiProperties;

private final String correlationId;
private final String customerId;
private final String personId;
private final String contactId;
private final String correlationId;

@Override
protected GenericResponse<Contact> execute() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,24 @@

import static com.acltabontabon.openwealth.configs.Constants.HEADER_CORRELATION_ID;

import com.acltabontabon.openwealth.configs.OpenWealthApiProperties;
import com.acltabontabon.openwealth.configs.OpenWealthApiProperties.CustomerManagementResourcePaths;
import com.acltabontabon.openwealth.dtos.CustomerResponse;
import com.acltabontabon.openwealth.models.Customer;
import com.acltabontabon.openwealth.services.CreateAsyncCommand;
import com.acltabontabon.openwealth.services.CreateCommand;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.MediaType;
import org.springframework.web.client.RestClient;

@Slf4j
@RequiredArgsConstructor
public class CustomerCreator extends CreateAsyncCommand<CustomerResponse> {
public class CustomerCreator extends CreateCommand<CustomerResponse> {

private final RestClient restClient;
private final OpenWealthApiProperties.CustomerManagement apiProperties;
private final CustomerManagementResourcePaths apiProperties;

private final Customer customer;
private final String correlationId;
private final Customer customer;

@Override
protected CustomerResponse execute() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

import static com.acltabontabon.openwealth.configs.Constants.HEADER_CORRELATION_ID;

import com.acltabontabon.openwealth.configs.OpenWealthApiProperties.CustomerManagementResourcePaths;
import com.acltabontabon.openwealth.dtos.GenericResponse;
import com.acltabontabon.openwealth.models.Customer;
import com.acltabontabon.openwealth.configs.OpenWealthApiProperties;
import com.acltabontabon.openwealth.services.QueryAsyncCommand;
import com.acltabontabon.openwealth.services.QueryCommand;
import java.util.List;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
Expand All @@ -14,10 +14,10 @@

@Slf4j
@RequiredArgsConstructor
public class CustomerQuery extends QueryAsyncCommand<GenericResponse<List<Customer>>> {
public class CustomerQuery extends QueryCommand<GenericResponse<List<Customer>>> {

private final RestClient restClient;
private final OpenWealthApiProperties.CustomerManagement apiProperties;
private final CustomerManagementResourcePaths apiProperties;

private String correlationId;

Expand All @@ -31,7 +31,7 @@ public SingleCustomerQuery withCustomerId(String customerId) {
}

public CustomerCreator createNew(Customer customer) {
return new CustomerCreator(restClient, apiProperties, customer, this.correlationId);
return new CustomerCreator(restClient, apiProperties, this.correlationId, customer);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.acltabontabon.openwealth.services.customermgmt.customer;

import com.acltabontabon.openwealth.configs.OpenWealthApiProperties;
import com.acltabontabon.openwealth.configs.OpenWealthApiProperties.CustomerManagementResourcePaths;
import com.acltabontabon.openwealth.services.customermgmt.prospect.PreCheckCreator;
import com.acltabontabon.openwealth.services.customermgmt.prospect.PreCheckStatusQuery;
import lombok.RequiredArgsConstructor;
Expand All @@ -20,7 +20,7 @@
public class CustomerService {

private final RestClient openWealthRestClient;
private final OpenWealthApiProperties.CustomerManagement apiProperties;
private final CustomerManagementResourcePaths apiProperties;


/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

import static com.acltabontabon.openwealth.configs.Constants.HEADER_CORRELATION_ID;

import com.acltabontabon.openwealth.configs.OpenWealthApiProperties;
import com.acltabontabon.openwealth.configs.OpenWealthApiProperties.CustomerManagementResourcePaths;
import com.acltabontabon.openwealth.dtos.GenericResponse;
import com.acltabontabon.openwealth.models.Customer;
import com.acltabontabon.openwealth.models.Document;
import com.acltabontabon.openwealth.models.Person;
import com.acltabontabon.openwealth.services.QueryAsyncCommand;
import com.acltabontabon.openwealth.services.QueryCommand;
import com.acltabontabon.openwealth.services.customermgmt.document.DocumentCreator;
import com.acltabontabon.openwealth.services.customermgmt.document.DocumentQuery;
import com.acltabontabon.openwealth.services.customermgmt.person.PersonCreator;
Expand All @@ -16,13 +16,13 @@
import org.springframework.web.client.RestClient;

@RequiredArgsConstructor
public class SingleCustomerQuery extends QueryAsyncCommand<GenericResponse<Customer>> {
public class SingleCustomerQuery extends QueryCommand<GenericResponse<Customer>> {

private final RestClient restClient;
private final OpenWealthApiProperties.CustomerManagement apiProperties;
private final CustomerManagementResourcePaths apiProperties;

private final String customerId;
private final String correlationId;
private final String customerId;

private boolean completeDetails;

Expand All @@ -36,15 +36,15 @@ public PersonQuery associatedPersons() {
}

public PersonCreator addPerson(Person personToAssociate) {
return new PersonCreator(restClient, apiProperties, personToAssociate, customerId, correlationId);
return new PersonCreator(restClient, apiProperties, correlationId, customerId, personToAssociate);
}

public DocumentQuery documents() {
return new DocumentQuery(restClient, apiProperties, customerId, correlationId);
return new DocumentQuery(restClient, apiProperties, correlationId, customerId);
}

public DocumentCreator addDocument(Document document) {
return new DocumentCreator(restClient, apiProperties, customerId, correlationId, document);
return new DocumentCreator(restClient, apiProperties, correlationId, customerId, document);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,22 @@

import static com.acltabontabon.openwealth.configs.Constants.HEADER_CORRELATION_ID;

import com.acltabontabon.openwealth.configs.OpenWealthApiProperties;
import com.acltabontabon.openwealth.configs.OpenWealthApiProperties.CustomerManagementResourcePaths;
import com.acltabontabon.openwealth.dtos.ApiResponse;
import com.acltabontabon.openwealth.dtos.ContactResponse;
import com.acltabontabon.openwealth.models.Document;
import com.acltabontabon.openwealth.services.CreateAsyncCommand;
import com.acltabontabon.openwealth.services.CreateCommand;
import lombok.RequiredArgsConstructor;
import org.springframework.web.client.RestClient;

@RequiredArgsConstructor
public class DocumentCreator extends CreateAsyncCommand<ApiResponse> {
public class DocumentCreator extends CreateCommand<ApiResponse> {

private final RestClient restClient;
private final OpenWealthApiProperties.CustomerManagement apiProperties;
private final CustomerManagementResourcePaths apiProperties;

private final String customerId;
private final String correlationId;
private final String customerId;

private final Document newDocument;

Expand Down
Loading

0 comments on commit 7e86f8d

Please sign in to comment.