From 21defb43310e145d0243aed53b3c817cb6d69a27 Mon Sep 17 00:00:00 2001 From: alex Date: Sun, 16 Aug 2020 16:23:26 -0700 Subject: [PATCH 01/22] Adding bceid starter --- src/pom.xml | 22 + src/spring-bceid-starter/pom.xml | 128 ++ .../open/bceid/starter/AutoConfiguration.java | 40 + .../open/bceid/starter/BCeIdProperties.java | 35 + .../bceid/starter/user/BCeIDUserService.java | 7 + .../starter/user/BCeIDUserServiceImpl.java | 21 + .../src/main/resources/wsdl/BCeIDService.wsdl | 1086 +++++++++++++++++ src/spring-sftp-starter/pom.xml | 8 +- src/spring-starters-bom/pom.xml | 63 + 9 files changed, 1409 insertions(+), 1 deletion(-) create mode 100644 src/spring-bceid-starter/pom.xml create mode 100644 src/spring-bceid-starter/src/main/java/ca/bc/gov/open/bceid/starter/AutoConfiguration.java create mode 100644 src/spring-bceid-starter/src/main/java/ca/bc/gov/open/bceid/starter/BCeIdProperties.java create mode 100644 src/spring-bceid-starter/src/main/java/ca/bc/gov/open/bceid/starter/user/BCeIDUserService.java create mode 100644 src/spring-bceid-starter/src/main/java/ca/bc/gov/open/bceid/starter/user/BCeIDUserServiceImpl.java create mode 100644 src/spring-bceid-starter/src/main/resources/wsdl/BCeIDService.wsdl create mode 100644 src/spring-starters-bom/pom.xml diff --git a/src/pom.xml b/src/pom.xml index 7755868..19743c4 100644 --- a/src/pom.xml +++ b/src/pom.xml @@ -6,6 +6,9 @@ ca.bc.gov.open spring-starters 0.1.1 + + + spring-starters pom @@ -20,8 +23,27 @@ all spring-sftp-starter + spring-bceid-starter + spring-starters-bom + + + + + spring-sftp-starter + + spring-starters-bom + spring-sftp-starter + + + spring-bceid-starter + + spring-starters-bom + spring-bceid-starter + + + diff --git a/src/spring-bceid-starter/pom.xml b/src/spring-bceid-starter/pom.xml new file mode 100644 index 0000000..b97f4f2 --- /dev/null +++ b/src/spring-bceid-starter/pom.xml @@ -0,0 +1,128 @@ + + + 4.0.0 + + ca.bc.gov.open + spring-bceid-starter + 0.1.1 + + + 1.8 + UTF-8 + 1.8 + 1.8 + 2.2.4.RELEASE + + + + + + org.springframework.boot + spring-boot-starter-web-services + + + org.springframework.boot + spring-boot-starter-tomcat + + + + + + org.springframework.boot + spring-boot-starter-test + test + + + org.junit.vintage + junit-vintage-engine + + + + + + org.apache.cxf + cxf-rt-frontend-jaxws + + + + org.apache.cxf + cxf-rt-transports-http + + + + org.apache.cxf + cxf-rt-transports-http-jetty + + + + org.apache.commons + commons-lang3 + + + + + + + org.springframework.boot + spring-boot-dependencies + ${spring-boot.version} + pom + import + + + ca.bc.gov.open + spring-starters-bom + 0.1.1 + pom + import + + + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + + ${java.version} + ${java.version} + + + + + + org.apache.cxf + cxf-codegen-plugin + 3.3.7 + + + generate-sources + generate-sources + + ${project.build.directory}/generated-sources/cxf + + + ${project.basedir}/src/main/resources/wsdl/BCeIDService.wsdl + + -client + -autoNameResolution + + + + + + wsdl2java + + + + + + + + + + \ No newline at end of file diff --git a/src/spring-bceid-starter/src/main/java/ca/bc/gov/open/bceid/starter/AutoConfiguration.java b/src/spring-bceid-starter/src/main/java/ca/bc/gov/open/bceid/starter/AutoConfiguration.java new file mode 100644 index 0000000..e60b028 --- /dev/null +++ b/src/spring-bceid-starter/src/main/java/ca/bc/gov/open/bceid/starter/AutoConfiguration.java @@ -0,0 +1,40 @@ +package ca.bc.gov.open.bceid.starter; + +import ca.bc.gov.open.bceid.starter.user.BCeIDUserService; +import ca.bc.gov.open.bceid.starter.user.BCeIDUserServiceImpl; +import ca.bceid.webservices.client.v9.BCeIDServiceSoap; +import org.apache.commons.lang3.StringUtils; +import org.apache.cxf.jaxws.JaxWsProxyFactoryBean; +import org.springframework.boot.context.properties.EnableConfigurationProperties; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +@Configuration +@EnableConfigurationProperties(BCeIdProperties.class) +public class AutoConfiguration { + + private final BCeIdProperties bCeIdProperties; + + public AutoConfiguration(BCeIdProperties bCeIdProperties) { + this.bCeIdProperties = bCeIdProperties; + } + + @Bean + public BCeIDServiceSoap bCeIDServiceSoap() { + + JaxWsProxyFactoryBean jaxWsProxyFactoryBean = new JaxWsProxyFactoryBean(); + jaxWsProxyFactoryBean.setServiceClass(BCeIDServiceSoap.class); + jaxWsProxyFactoryBean.setAddress(bCeIdProperties.getUri()); + if(StringUtils.isNotBlank(bCeIdProperties.getUsername())) + jaxWsProxyFactoryBean.setUsername(bCeIdProperties.getUsername()); + if(StringUtils.isNotBlank(bCeIdProperties.getPassword())) + jaxWsProxyFactoryBean.setPassword(bCeIdProperties.getPassword()); + return (BCeIDServiceSoap) jaxWsProxyFactoryBean.create(); + + } + + @Bean + public BCeIDUserService bCeIDUserService(BCeIDServiceSoap bCeIDServiceSoap) { + return new BCeIDUserServiceImpl(bCeIDServiceSoap); + } +} diff --git a/src/spring-bceid-starter/src/main/java/ca/bc/gov/open/bceid/starter/BCeIdProperties.java b/src/spring-bceid-starter/src/main/java/ca/bc/gov/open/bceid/starter/BCeIdProperties.java new file mode 100644 index 0000000..0a6433d --- /dev/null +++ b/src/spring-bceid-starter/src/main/java/ca/bc/gov/open/bceid/starter/BCeIdProperties.java @@ -0,0 +1,35 @@ +package ca.bc.gov.open.bceid.starter; + +import org.springframework.boot.context.properties.ConfigurationProperties; + +@ConfigurationProperties(prefix = "bcgov.bceid.service") +public class BCeIdProperties { + + private String uri; + private String username; + private String password; + + public String getUri() { + return uri; + } + + public void setUri(String uri) { + this.uri = uri; + } + + public String getUsername() { + return username; + } + + public void setUsername(String username) { + this.username = username; + } + + public String getPassword() { + return password; + } + + public void setPassword(String password) { + this.password = password; + } +} diff --git a/src/spring-bceid-starter/src/main/java/ca/bc/gov/open/bceid/starter/user/BCeIDUserService.java b/src/spring-bceid-starter/src/main/java/ca/bc/gov/open/bceid/starter/user/BCeIDUserService.java new file mode 100644 index 0000000..02de2b5 --- /dev/null +++ b/src/spring-bceid-starter/src/main/java/ca/bc/gov/open/bceid/starter/user/BCeIDUserService.java @@ -0,0 +1,7 @@ +package ca.bc.gov.open.bceid.starter.user; + +public interface BCeIDUserService { + + public String getById(String userId); + +} diff --git a/src/spring-bceid-starter/src/main/java/ca/bc/gov/open/bceid/starter/user/BCeIDUserServiceImpl.java b/src/spring-bceid-starter/src/main/java/ca/bc/gov/open/bceid/starter/user/BCeIDUserServiceImpl.java new file mode 100644 index 0000000..6332d4e --- /dev/null +++ b/src/spring-bceid-starter/src/main/java/ca/bc/gov/open/bceid/starter/user/BCeIDUserServiceImpl.java @@ -0,0 +1,21 @@ +package ca.bc.gov.open.bceid.starter.user; + +import ca.bceid.webservices.client.v9.AccountDetailRequest; +import ca.bceid.webservices.client.v9.BCeIDServiceSoap; + +public class BCeIDUserServiceImpl implements BCeIDUserService { + + private final BCeIDServiceSoap bCeIDServiceSoap; + + public BCeIDUserServiceImpl(BCeIDServiceSoap bCeIDServiceSoap) { + this.bCeIDServiceSoap = bCeIDServiceSoap; + } + + @Override + public String getById(String userId) { + + AccountDetailRequest accountDetailRequest = new AccountDetailRequest(); + return bCeIDServiceSoap.getAccountDetail(accountDetailRequest).getMessage(); + } + +} diff --git a/src/spring-bceid-starter/src/main/resources/wsdl/BCeIDService.wsdl b/src/spring-bceid-starter/src/main/resources/wsdl/BCeIDService.wsdl new file mode 100644 index 0000000..480b3fc --- /dev/null +++ b/src/spring-bceid-starter/src/main/resources/wsdl/BCeIDService.wsdl @@ -0,0 +1,1086 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Get Internal User Group Membership Information + + + + + Search for all BCeID accounts. + + + + + Search for all internal accounts. + + + + + Get details for a given list of accounts. + + + + + Get details for a given account. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/spring-sftp-starter/pom.xml b/src/spring-sftp-starter/pom.xml index c662ddb..cde3cf4 100644 --- a/src/spring-sftp-starter/pom.xml +++ b/src/spring-sftp-starter/pom.xml @@ -32,7 +32,6 @@ commons-io commons-io - 1.4 @@ -68,6 +67,13 @@ pom import + + ca.bc.gov.open + spring-starters-bom + 0.1.1 + pom + import + diff --git a/src/spring-starters-bom/pom.xml b/src/spring-starters-bom/pom.xml new file mode 100644 index 0000000..41cf413 --- /dev/null +++ b/src/spring-starters-bom/pom.xml @@ -0,0 +1,63 @@ + + + + 4.0.0 + + ca.bc.gov.open + spring-starters-bom + 0.1.1 + + + 3.3.7 + 2.11.2 + 2.3.1 + 1.4 + + + + + + + + org.mapstruct + mapstruct + ${org.mapstruct.version} + + + + + org.apache.cxf + cxf-rt-frontend-jaxws + ${org.apache.cxf.version} + + + org.apache.cxf + cxf-rt-transports-http + ${org.apache.cxf.version} + + + org.apache.cxf + cxf-rt-transports-http-jetty + ${org.apache.cxf.version} + + + javax.xml.bind + jaxb-api + ${javax.xml.bind.version} + + + + commons-io + commons-io + ${commons.io.version} + + + + + + + + + \ No newline at end of file From ce03378c6c04d9136a0f1051bcb627115c1ce2f4 Mon Sep 17 00:00:00 2001 From: alex Date: Sun, 16 Aug 2020 20:57:19 -0700 Subject: [PATCH 02/22] Adding individual identity --- src/spring-bceid-starter/pom.xml | 6 ++ .../open/bceid/starter/AutoConfiguration.java | 8 +- .../open/bceid/starter/BCeIdProperties.java | 9 +++ .../starter/account/BCeIDAccountService.java | 11 +++ .../account/BCeIDAccountServiceImpl.java | 76 +++++++++++++++++++ .../starter/account/GetAccountRequest.java | 66 ++++++++++++++++ .../bceid/starter/account/models/Address.java | 50 ++++++++++++ .../account/models/IndividualIdentity.java | 34 +++++++++ .../bceid/starter/account/models/Name.java | 38 ++++++++++ .../bceid/starter/user/BCeIDUserService.java | 7 -- .../starter/user/BCeIDUserServiceImpl.java | 21 ----- .../main/resources/META-INF/spring.factories | 3 + src/spring-starters-bom/pom.xml | 7 ++ 13 files changed, 304 insertions(+), 32 deletions(-) create mode 100644 src/spring-bceid-starter/src/main/java/ca/bc/gov/open/bceid/starter/account/BCeIDAccountService.java create mode 100644 src/spring-bceid-starter/src/main/java/ca/bc/gov/open/bceid/starter/account/BCeIDAccountServiceImpl.java create mode 100644 src/spring-bceid-starter/src/main/java/ca/bc/gov/open/bceid/starter/account/GetAccountRequest.java create mode 100644 src/spring-bceid-starter/src/main/java/ca/bc/gov/open/bceid/starter/account/models/Address.java create mode 100644 src/spring-bceid-starter/src/main/java/ca/bc/gov/open/bceid/starter/account/models/IndividualIdentity.java create mode 100644 src/spring-bceid-starter/src/main/java/ca/bc/gov/open/bceid/starter/account/models/Name.java delete mode 100644 src/spring-bceid-starter/src/main/java/ca/bc/gov/open/bceid/starter/user/BCeIDUserService.java delete mode 100644 src/spring-bceid-starter/src/main/java/ca/bc/gov/open/bceid/starter/user/BCeIDUserServiceImpl.java create mode 100644 src/spring-bceid-starter/src/main/resources/META-INF/spring.factories diff --git a/src/spring-bceid-starter/pom.xml b/src/spring-bceid-starter/pom.xml index b97f4f2..f1631c4 100644 --- a/src/spring-bceid-starter/pom.xml +++ b/src/spring-bceid-starter/pom.xml @@ -60,6 +60,12 @@ org.apache.commons commons-lang3 + + + joda-time + joda-time + + diff --git a/src/spring-bceid-starter/src/main/java/ca/bc/gov/open/bceid/starter/AutoConfiguration.java b/src/spring-bceid-starter/src/main/java/ca/bc/gov/open/bceid/starter/AutoConfiguration.java index e60b028..b36a4d6 100644 --- a/src/spring-bceid-starter/src/main/java/ca/bc/gov/open/bceid/starter/AutoConfiguration.java +++ b/src/spring-bceid-starter/src/main/java/ca/bc/gov/open/bceid/starter/AutoConfiguration.java @@ -1,7 +1,7 @@ package ca.bc.gov.open.bceid.starter; -import ca.bc.gov.open.bceid.starter.user.BCeIDUserService; -import ca.bc.gov.open.bceid.starter.user.BCeIDUserServiceImpl; +import ca.bc.gov.open.bceid.starter.account.BCeIDAccountService; +import ca.bc.gov.open.bceid.starter.account.BCeIDAccountServiceImpl; import ca.bceid.webservices.client.v9.BCeIDServiceSoap; import org.apache.commons.lang3.StringUtils; import org.apache.cxf.jaxws.JaxWsProxyFactoryBean; @@ -34,7 +34,7 @@ public BCeIDServiceSoap bCeIDServiceSoap() { } @Bean - public BCeIDUserService bCeIDUserService(BCeIDServiceSoap bCeIDServiceSoap) { - return new BCeIDUserServiceImpl(bCeIDServiceSoap); + public BCeIDAccountService bCeIDUserService(BCeIDServiceSoap bCeIDServiceSoap) { + return new BCeIDAccountServiceImpl(bCeIDServiceSoap, bCeIdProperties); } } diff --git a/src/spring-bceid-starter/src/main/java/ca/bc/gov/open/bceid/starter/BCeIdProperties.java b/src/spring-bceid-starter/src/main/java/ca/bc/gov/open/bceid/starter/BCeIdProperties.java index 0a6433d..e4de6ae 100644 --- a/src/spring-bceid-starter/src/main/java/ca/bc/gov/open/bceid/starter/BCeIdProperties.java +++ b/src/spring-bceid-starter/src/main/java/ca/bc/gov/open/bceid/starter/BCeIdProperties.java @@ -8,6 +8,7 @@ public class BCeIdProperties { private String uri; private String username; private String password; + private String onlineServiceId; public String getUri() { return uri; @@ -32,4 +33,12 @@ public String getPassword() { public void setPassword(String password) { this.password = password; } + + public String getOnlineServiceId() { + return onlineServiceId; + } + + public void setOnlineServiceId(String onlineServiceId) { + this.onlineServiceId = onlineServiceId; + } } diff --git a/src/spring-bceid-starter/src/main/java/ca/bc/gov/open/bceid/starter/account/BCeIDAccountService.java b/src/spring-bceid-starter/src/main/java/ca/bc/gov/open/bceid/starter/account/BCeIDAccountService.java new file mode 100644 index 0000000..33f17ba --- /dev/null +++ b/src/spring-bceid-starter/src/main/java/ca/bc/gov/open/bceid/starter/account/BCeIDAccountService.java @@ -0,0 +1,11 @@ +package ca.bc.gov.open.bceid.starter.account; + +import ca.bc.gov.open.bceid.starter.account.models.IndividualIdentity; + +import java.util.Optional; + +public interface BCeIDAccountService { + + Optional getIndividualIdentity(GetAccountRequest request); + +} diff --git a/src/spring-bceid-starter/src/main/java/ca/bc/gov/open/bceid/starter/account/BCeIDAccountServiceImpl.java b/src/spring-bceid-starter/src/main/java/ca/bc/gov/open/bceid/starter/account/BCeIDAccountServiceImpl.java new file mode 100644 index 0000000..330bfbd --- /dev/null +++ b/src/spring-bceid-starter/src/main/java/ca/bc/gov/open/bceid/starter/account/BCeIDAccountServiceImpl.java @@ -0,0 +1,76 @@ +package ca.bc.gov.open.bceid.starter.account; + +import ca.bc.gov.open.bceid.starter.BCeIdProperties; +import ca.bc.gov.open.bceid.starter.account.models.Address; +import ca.bc.gov.open.bceid.starter.account.models.IndividualIdentity; +import ca.bc.gov.open.bceid.starter.account.models.Name; +import ca.bceid.webservices.client.v9.*; +import org.joda.time.DateTime; + +import java.util.Optional; + +public class BCeIDAccountServiceImpl implements BCeIDAccountService { + + private final BCeIDServiceSoap bCeIDServiceSoap; + + private final BCeIdProperties bCeIdProperties; + + public BCeIDAccountServiceImpl(BCeIDServiceSoap bCeIDServiceSoap, BCeIdProperties bCeIdProperties) { + this.bCeIDServiceSoap = bCeIDServiceSoap; + this.bCeIdProperties = bCeIdProperties; + } + + @Override + public Optional getIndividualIdentity(GetAccountRequest request) { + + AccountDetailRequest accountDetailRequest = new AccountDetailRequest(); + accountDetailRequest.setOnlineServiceId(bCeIdProperties.getOnlineServiceId()); + accountDetailRequest.setRequesterUserGuid(request.getId()); + accountDetailRequest.setRequesterAccountTypeCode(request.getbCeIDAccountTypeCode()); + accountDetailRequest.setUserGuid(request.getRequesterId()); + accountDetailRequest.setAccountTypeCode(request.getRequesterBCeIDAccountTypeCode()); + AccountDetailResponse response = bCeIDServiceSoap.getAccountDetail(accountDetailRequest); + + if (response.getCode() == ResponseCode.SUCCESS) { + + Name name = new Name( + response.getAccount().getIndividualIdentity().getName().getFirstname().getValue(), + response.getAccount().getIndividualIdentity().getName().getMiddleName().getValue(), + response.getAccount().getIndividualIdentity().getName().getOtherMiddleName().getValue(), + response.getAccount().getIndividualIdentity().getName().getSurname().getValue(), + response.getAccount().getIndividualIdentity().getName().getInitials().getValue()); + + + BCeIDAddress bresidentialAddress = response.getAccount().getIndividualIdentity().getResidentialAddress(); + + Address residentialAddress = new Address(bresidentialAddress.getAddressLine1().getValue(), + bresidentialAddress.getAddressLine2().getValue(), + bresidentialAddress.getCountry().getValue(), + bresidentialAddress.getPostal().getValue(), + bresidentialAddress.getProvince().getValue(), + bresidentialAddress.getCountry().getValue(), + bresidentialAddress.getUnstructuredAddress().getValue()); + + BCeIDAddress bmailingAddress = response.getAccount().getIndividualIdentity().getMailingAddress(); + + Address mailingAddress = new Address(bmailingAddress.getAddressLine1().getValue(), + bmailingAddress.getAddressLine2().getValue(), + bmailingAddress.getCountry().getValue(), + bmailingAddress.getPostal().getValue(), + bmailingAddress.getProvince().getValue(), + bmailingAddress.getCountry().getValue(), + bmailingAddress.getUnstructuredAddress().getValue()); + + return Optional.of(new IndividualIdentity( + name, + new DateTime(response.getAccount().getIndividualIdentity().getDateOfBirth().getValue().toGregorianCalendar().getTime()), + residentialAddress, + mailingAddress)); + + } + + return Optional.empty(); + + } + +} diff --git a/src/spring-bceid-starter/src/main/java/ca/bc/gov/open/bceid/starter/account/GetAccountRequest.java b/src/spring-bceid-starter/src/main/java/ca/bc/gov/open/bceid/starter/account/GetAccountRequest.java new file mode 100644 index 0000000..f8642b4 --- /dev/null +++ b/src/spring-bceid-starter/src/main/java/ca/bc/gov/open/bceid/starter/account/GetAccountRequest.java @@ -0,0 +1,66 @@ +package ca.bc.gov.open.bceid.starter.account; + +import ca.bceid.webservices.client.v9.BCeIDAccountTypeCode; +import org.apache.commons.lang3.StringUtils; + +public class GetAccountRequest { + + private String id; + private BCeIDAccountTypeCode bCeIDAccountTypeCode; + private String requesterId; + private BCeIDAccountTypeCode requesterBCeIDAccountTypeCode; + + private GetAccountRequest(String id, BCeIDAccountTypeCode bCeIDAccountTypeCode) { + this.id = id; + this.bCeIDAccountTypeCode = bCeIDAccountTypeCode; + this.requesterId = id; + this.requesterBCeIDAccountTypeCode = bCeIDAccountTypeCode; + } + + public String getId() { + return id; + } + + public BCeIDAccountTypeCode getbCeIDAccountTypeCode() { + return bCeIDAccountTypeCode; + } + + public String getRequesterId() { + return requesterId; + } + + public BCeIDAccountTypeCode getRequesterBCeIDAccountTypeCode() { + return requesterBCeIDAccountTypeCode; + } + + public static GetAccountRequest BusinessSelfRequest(String id) { + if(StringUtils.isBlank(id)) throw new IllegalArgumentException("Id value is required"); + return new GetAccountRequest(id, BCeIDAccountTypeCode.BUSINESS); + } + + public static GetAccountRequest EdsSelfRequest(String id) { + if(StringUtils.isBlank(id)) throw new IllegalArgumentException("Id value is required"); + return new GetAccountRequest(id, BCeIDAccountTypeCode.EDS); + } + + public static GetAccountRequest IndividualSelfRequest(String id) { + if(StringUtils.isBlank(id)) throw new IllegalArgumentException("Id value is required"); + return new GetAccountRequest(id, BCeIDAccountTypeCode.INDIVIDUAL); + } + + public static GetAccountRequest InternalSelfRequest(String id) { + if(StringUtils.isBlank(id)) throw new IllegalArgumentException("Id value is required"); + return new GetAccountRequest(id, BCeIDAccountTypeCode.INTERNAL); + } + + public static GetAccountRequest LdbSelfRequest(String id) { + if(StringUtils.isBlank(id)) throw new IllegalArgumentException("Id value is required"); + return new GetAccountRequest(id, BCeIDAccountTypeCode.LDB); + } + + public static GetAccountRequest VerifiedIndividualSelfRequest(String id) { + if(StringUtils.isBlank(id)) throw new IllegalArgumentException("Id value is required"); + return new GetAccountRequest(id, BCeIDAccountTypeCode.VERIFIED_INDIVIDUAL); + } + +} diff --git a/src/spring-bceid-starter/src/main/java/ca/bc/gov/open/bceid/starter/account/models/Address.java b/src/spring-bceid-starter/src/main/java/ca/bc/gov/open/bceid/starter/account/models/Address.java new file mode 100644 index 0000000..55ee3ae --- /dev/null +++ b/src/spring-bceid-starter/src/main/java/ca/bc/gov/open/bceid/starter/account/models/Address.java @@ -0,0 +1,50 @@ +package ca.bc.gov.open.bceid.starter.account.models; + +public class Address { + + private String addressLine1; + private String addressLine2; + private String city; + private String postal; + private String province; + private String country; + private String unstructuredAddress; + + public Address(String addressLine1, String addressLine2, String city, String postal, String province, String country, String unstructuredAddress) { + this.addressLine1 = addressLine1; + this.addressLine2 = addressLine2; + this.city = city; + this.postal = postal; + this.province = province; + this.country = country; + this.unstructuredAddress = unstructuredAddress; + } + + public String getAddressLine1() { + return addressLine1; + } + + public String getAddressLine2() { + return addressLine2; + } + + public String getCity() { + return city; + } + + public String getPostal() { + return postal; + } + + public String getProvince() { + return province; + } + + public String getCountry() { + return country; + } + + public String getUnstructuredAddress() { + return unstructuredAddress; + } +} diff --git a/src/spring-bceid-starter/src/main/java/ca/bc/gov/open/bceid/starter/account/models/IndividualIdentity.java b/src/spring-bceid-starter/src/main/java/ca/bc/gov/open/bceid/starter/account/models/IndividualIdentity.java new file mode 100644 index 0000000..4a4b7e3 --- /dev/null +++ b/src/spring-bceid-starter/src/main/java/ca/bc/gov/open/bceid/starter/account/models/IndividualIdentity.java @@ -0,0 +1,34 @@ +package ca.bc.gov.open.bceid.starter.account.models; + +import org.joda.time.DateTime; + +public class IndividualIdentity { + + private Name name; + private DateTime dateOfBirth; + private Address residentialAddress; + private Address mailingAddress; + + public IndividualIdentity(Name name, DateTime dateOfBirth, Address residentialAddress, Address mailingAddress) { + this.name = name; + this.dateOfBirth = dateOfBirth; + this.residentialAddress = residentialAddress; + this.mailingAddress = mailingAddress; + } + + public Name getName() { + return name; + } + + public DateTime getDateOfBirth() { + return dateOfBirth; + } + + public Address getResidentialAddress() { + return residentialAddress; + } + + public Address getMailingAddress() { + return mailingAddress; + } +} diff --git a/src/spring-bceid-starter/src/main/java/ca/bc/gov/open/bceid/starter/account/models/Name.java b/src/spring-bceid-starter/src/main/java/ca/bc/gov/open/bceid/starter/account/models/Name.java new file mode 100644 index 0000000..289629c --- /dev/null +++ b/src/spring-bceid-starter/src/main/java/ca/bc/gov/open/bceid/starter/account/models/Name.java @@ -0,0 +1,38 @@ +package ca.bc.gov.open.bceid.starter.account.models; + +public class Name { + + private String firstname; + private String middleName; + private String otherMiddleName; + private String surname; + private String initials; + + public Name(String firstname, String middleName, String otherMiddleName, String surname, String initials) { + this.firstname = firstname; + this.middleName = middleName; + this.otherMiddleName = otherMiddleName; + this.surname = surname; + this.initials = initials; + } + + public String getFirstname() { + return firstname; + } + + public String getMiddleName() { + return middleName; + } + + public String getOtherMiddleName() { + return otherMiddleName; + } + + public String getSurname() { + return surname; + } + + public String getInitials() { + return initials; + } +} diff --git a/src/spring-bceid-starter/src/main/java/ca/bc/gov/open/bceid/starter/user/BCeIDUserService.java b/src/spring-bceid-starter/src/main/java/ca/bc/gov/open/bceid/starter/user/BCeIDUserService.java deleted file mode 100644 index 02de2b5..0000000 --- a/src/spring-bceid-starter/src/main/java/ca/bc/gov/open/bceid/starter/user/BCeIDUserService.java +++ /dev/null @@ -1,7 +0,0 @@ -package ca.bc.gov.open.bceid.starter.user; - -public interface BCeIDUserService { - - public String getById(String userId); - -} diff --git a/src/spring-bceid-starter/src/main/java/ca/bc/gov/open/bceid/starter/user/BCeIDUserServiceImpl.java b/src/spring-bceid-starter/src/main/java/ca/bc/gov/open/bceid/starter/user/BCeIDUserServiceImpl.java deleted file mode 100644 index 6332d4e..0000000 --- a/src/spring-bceid-starter/src/main/java/ca/bc/gov/open/bceid/starter/user/BCeIDUserServiceImpl.java +++ /dev/null @@ -1,21 +0,0 @@ -package ca.bc.gov.open.bceid.starter.user; - -import ca.bceid.webservices.client.v9.AccountDetailRequest; -import ca.bceid.webservices.client.v9.BCeIDServiceSoap; - -public class BCeIDUserServiceImpl implements BCeIDUserService { - - private final BCeIDServiceSoap bCeIDServiceSoap; - - public BCeIDUserServiceImpl(BCeIDServiceSoap bCeIDServiceSoap) { - this.bCeIDServiceSoap = bCeIDServiceSoap; - } - - @Override - public String getById(String userId) { - - AccountDetailRequest accountDetailRequest = new AccountDetailRequest(); - return bCeIDServiceSoap.getAccountDetail(accountDetailRequest).getMessage(); - } - -} diff --git a/src/spring-bceid-starter/src/main/resources/META-INF/spring.factories b/src/spring-bceid-starter/src/main/resources/META-INF/spring.factories new file mode 100644 index 0000000..3b83c3a --- /dev/null +++ b/src/spring-bceid-starter/src/main/resources/META-INF/spring.factories @@ -0,0 +1,3 @@ +org.springframework.boot.autoconfigure.EnableAutoConfiguration=\ + ca.bc.gov.open.bceid.starter.AutoConfiguration + \ No newline at end of file diff --git a/src/spring-starters-bom/pom.xml b/src/spring-starters-bom/pom.xml index 41cf413..c885617 100644 --- a/src/spring-starters-bom/pom.xml +++ b/src/spring-starters-bom/pom.xml @@ -14,6 +14,7 @@ 2.11.2 2.3.1 1.4 + 2.10.6 @@ -54,6 +55,12 @@ ${commons.io.version} + + joda-time + joda-time + ${joda-time.version} + + From 32e5dba159c4185275334b91a14c9647fbca5963 Mon Sep 17 00:00:00 2001 From: TayGov Date: Mon, 17 Aug 2020 08:05:07 -0700 Subject: [PATCH 03/22] Adding tests --- .../bceid/starter/AutoConfigurationTest.java | 23 +++++++++++++++++++ .../account/BCeIDAccountServiceImplTest.java | 4 ++++ 2 files changed, 27 insertions(+) create mode 100644 src/spring-bceid-starter/src/test/java/ca/bc/gov/open/bceid/starter/AutoConfigurationTest.java create mode 100644 src/spring-bceid-starter/src/test/java/ca/bc/gov/open/bceid/starter/account/BCeIDAccountServiceImplTest.java diff --git a/src/spring-bceid-starter/src/test/java/ca/bc/gov/open/bceid/starter/AutoConfigurationTest.java b/src/spring-bceid-starter/src/test/java/ca/bc/gov/open/bceid/starter/AutoConfigurationTest.java new file mode 100644 index 0000000..ec01652 --- /dev/null +++ b/src/spring-bceid-starter/src/test/java/ca/bc/gov/open/bceid/starter/AutoConfigurationTest.java @@ -0,0 +1,23 @@ +package ca.bc.gov.open.bceid.starter; + +import ca.bc.gov.open.bceid.starter.account.BCeIDAccountService; +import ca.bceid.webservices.client.v9.BCeIDServiceSoap; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; +import org.springframework.boot.test.context.runner.ApplicationContextRunner; + +import static org.assertj.core.api.Assertions.assertThat; + +public class AutoConfigurationTest { + ApplicationContextRunner context = new ApplicationContextRunner(); + + @Test + public void testConfigure() { + + context.run(it -> { + Assertions.assertNotNull(assertThat(it).getBean(BCeIDServiceSoap.class)); + Assertions.assertNotNull(assertThat(it).getBean(BCeIDAccountService.class)); + }); + + } +} diff --git a/src/spring-bceid-starter/src/test/java/ca/bc/gov/open/bceid/starter/account/BCeIDAccountServiceImplTest.java b/src/spring-bceid-starter/src/test/java/ca/bc/gov/open/bceid/starter/account/BCeIDAccountServiceImplTest.java new file mode 100644 index 0000000..82e444c --- /dev/null +++ b/src/spring-bceid-starter/src/test/java/ca/bc/gov/open/bceid/starter/account/BCeIDAccountServiceImplTest.java @@ -0,0 +1,4 @@ +package ca.bc.gov.open.bceid.starter.account; + +public class BCeIDAccountServiceImplTest { +} From 0997140d2e87c6d3ee72d5aeae9123ac190aa3e6 Mon Sep 17 00:00:00 2001 From: TayGov Date: Mon, 17 Aug 2020 09:34:28 -0700 Subject: [PATCH 04/22] UPdate tests Fix city mapping --- .../account/BCeIDAccountServiceImpl.java | 4 +- .../starter/account/GetAccountRequest.java | 7 +- .../bceid/starter/AutoConfigurationTest.java | 6 +- .../account/BCeIDAccountServiceImplTest.java | 127 ++++++++++++++++++ 4 files changed, 135 insertions(+), 9 deletions(-) diff --git a/src/spring-bceid-starter/src/main/java/ca/bc/gov/open/bceid/starter/account/BCeIDAccountServiceImpl.java b/src/spring-bceid-starter/src/main/java/ca/bc/gov/open/bceid/starter/account/BCeIDAccountServiceImpl.java index 330bfbd..445fc7d 100644 --- a/src/spring-bceid-starter/src/main/java/ca/bc/gov/open/bceid/starter/account/BCeIDAccountServiceImpl.java +++ b/src/spring-bceid-starter/src/main/java/ca/bc/gov/open/bceid/starter/account/BCeIDAccountServiceImpl.java @@ -45,7 +45,7 @@ public Optional getIndividualIdentity(GetAccountRequest requ Address residentialAddress = new Address(bresidentialAddress.getAddressLine1().getValue(), bresidentialAddress.getAddressLine2().getValue(), - bresidentialAddress.getCountry().getValue(), + bresidentialAddress.getCity().getValue(), bresidentialAddress.getPostal().getValue(), bresidentialAddress.getProvince().getValue(), bresidentialAddress.getCountry().getValue(), @@ -55,7 +55,7 @@ public Optional getIndividualIdentity(GetAccountRequest requ Address mailingAddress = new Address(bmailingAddress.getAddressLine1().getValue(), bmailingAddress.getAddressLine2().getValue(), - bmailingAddress.getCountry().getValue(), + bmailingAddress.getCity().getValue(), bmailingAddress.getPostal().getValue(), bmailingAddress.getProvince().getValue(), bmailingAddress.getCountry().getValue(), diff --git a/src/spring-bceid-starter/src/main/java/ca/bc/gov/open/bceid/starter/account/GetAccountRequest.java b/src/spring-bceid-starter/src/main/java/ca/bc/gov/open/bceid/starter/account/GetAccountRequest.java index f8642b4..477658a 100644 --- a/src/spring-bceid-starter/src/main/java/ca/bc/gov/open/bceid/starter/account/GetAccountRequest.java +++ b/src/spring-bceid-starter/src/main/java/ca/bc/gov/open/bceid/starter/account/GetAccountRequest.java @@ -11,6 +11,7 @@ public class GetAccountRequest { private BCeIDAccountTypeCode requesterBCeIDAccountTypeCode; private GetAccountRequest(String id, BCeIDAccountTypeCode bCeIDAccountTypeCode) { + if(StringUtils.isBlank(id)) throw new IllegalArgumentException("Id value is required"); this.id = id; this.bCeIDAccountTypeCode = bCeIDAccountTypeCode; this.requesterId = id; @@ -34,32 +35,26 @@ public BCeIDAccountTypeCode getRequesterBCeIDAccountTypeCode() { } public static GetAccountRequest BusinessSelfRequest(String id) { - if(StringUtils.isBlank(id)) throw new IllegalArgumentException("Id value is required"); return new GetAccountRequest(id, BCeIDAccountTypeCode.BUSINESS); } public static GetAccountRequest EdsSelfRequest(String id) { - if(StringUtils.isBlank(id)) throw new IllegalArgumentException("Id value is required"); return new GetAccountRequest(id, BCeIDAccountTypeCode.EDS); } public static GetAccountRequest IndividualSelfRequest(String id) { - if(StringUtils.isBlank(id)) throw new IllegalArgumentException("Id value is required"); return new GetAccountRequest(id, BCeIDAccountTypeCode.INDIVIDUAL); } public static GetAccountRequest InternalSelfRequest(String id) { - if(StringUtils.isBlank(id)) throw new IllegalArgumentException("Id value is required"); return new GetAccountRequest(id, BCeIDAccountTypeCode.INTERNAL); } public static GetAccountRequest LdbSelfRequest(String id) { - if(StringUtils.isBlank(id)) throw new IllegalArgumentException("Id value is required"); return new GetAccountRequest(id, BCeIDAccountTypeCode.LDB); } public static GetAccountRequest VerifiedIndividualSelfRequest(String id) { - if(StringUtils.isBlank(id)) throw new IllegalArgumentException("Id value is required"); return new GetAccountRequest(id, BCeIDAccountTypeCode.VERIFIED_INDIVIDUAL); } diff --git a/src/spring-bceid-starter/src/test/java/ca/bc/gov/open/bceid/starter/AutoConfigurationTest.java b/src/spring-bceid-starter/src/test/java/ca/bc/gov/open/bceid/starter/AutoConfigurationTest.java index ec01652..d831ad6 100644 --- a/src/spring-bceid-starter/src/test/java/ca/bc/gov/open/bceid/starter/AutoConfigurationTest.java +++ b/src/spring-bceid-starter/src/test/java/ca/bc/gov/open/bceid/starter/AutoConfigurationTest.java @@ -3,15 +3,19 @@ import ca.bc.gov.open.bceid.starter.account.BCeIDAccountService; import ca.bceid.webservices.client.v9.BCeIDServiceSoap; import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestInstance; import org.springframework.boot.test.context.runner.ApplicationContextRunner; import static org.assertj.core.api.Assertions.assertThat; - +@TestInstance(TestInstance.Lifecycle.PER_CLASS) +@DisplayName("Test AutoConfiguration") public class AutoConfigurationTest { ApplicationContextRunner context = new ApplicationContextRunner(); @Test + @DisplayName("Test Beans Exist") public void testConfigure() { context.run(it -> { diff --git a/src/spring-bceid-starter/src/test/java/ca/bc/gov/open/bceid/starter/account/BCeIDAccountServiceImplTest.java b/src/spring-bceid-starter/src/test/java/ca/bc/gov/open/bceid/starter/account/BCeIDAccountServiceImplTest.java index 82e444c..2d80913 100644 --- a/src/spring-bceid-starter/src/test/java/ca/bc/gov/open/bceid/starter/account/BCeIDAccountServiceImplTest.java +++ b/src/spring-bceid-starter/src/test/java/ca/bc/gov/open/bceid/starter/account/BCeIDAccountServiceImplTest.java @@ -1,4 +1,131 @@ package ca.bc.gov.open.bceid.starter.account; +import ca.bc.gov.open.bceid.starter.BCeIdProperties; +import ca.bc.gov.open.bceid.starter.account.models.Address; +import ca.bc.gov.open.bceid.starter.account.models.IndividualIdentity; +import ca.bc.gov.open.bceid.starter.account.models.Name; +import ca.bceid.webservices.client.v9.*; +import org.junit.jupiter.api.*; +import org.mockito.Mock; +import org.mockito.Mockito; + +import java.util.Optional; + +import static org.mockito.ArgumentMatchers.any; + +@TestInstance(TestInstance.Lifecycle.PER_CLASS) +@DisplayName("Test BCeIDAccountServiceImpl") public class BCeIDAccountServiceImplTest { + private static final String SUCCESS = "SUCCESS"; + private static final String FIRSTNAME = "FIRSTNAME"; + private static final String MIDDLENAME = "MIDDLENAME"; + private static final String OTHERMIDDLE = "OTHERMIDDLE"; + private static final String SURNAME = "SURNAME"; + private static final String INITIAL = "INITIAL"; + private static final String ADDRESS_1 = "ADDRESS1"; + private static final String ADDRESS_2 = "ADDRESS2"; + private static final String COUNTRY = "COUNTRY"; + private static final String POSTAL = "POSTAL"; + private static final String PROVINCE = "PROVINCE"; + private static final String UNSTRUCTUREDADDRESS = "UNSTRUCTUREDADDRESS"; + private static final String CITY = "CITY"; + private static final String FAILED = "FAILED"; + BCeIDAccountServiceImpl sut; + + @Mock + BCeIDServiceSoap bCeIDServiceSoapMock; + + @Mock + BCeIdProperties bCeIdPropertiesMock; + + + @BeforeEach + public void init() { + + sut = new BCeIDAccountServiceImpl(bCeIDServiceSoapMock, bCeIdPropertiesMock); + + } + + @Test + @DisplayName("Test Return Individual Identity") + public void withValidRequestReturnAccount() { + Mockito.when(bCeIDServiceSoapMock.getAccountDetail(any())).thenReturn(createAccountDetailsResponse(ResponseCode.SUCCESS)); + + Optional result = sut.getIndividualIdentity(GetAccountRequest.IndividualSelfRequest(SUCCESS)); + + Assertions.assertTrue(result.isPresent()); + Assertions.assertEquals(FIRSTNAME, result.get().getName().getFirstname()); + Assertions.assertEquals(INITIAL, result.get().getName().getInitials()); + Assertions.assertEquals(MIDDLENAME, result.get().getName().getMiddleName()); + Assertions.assertEquals(OTHERMIDDLE, result.get().getName().getOtherMiddleName()); + Assertions.assertEquals(SURNAME, result.get().getName().getSurname()); + + Assertions.assertEquals(ADDRESS_1, result.get().getResidentialAddress().getAddressLine1()); + Assertions.assertEquals(ADDRESS_2, result.get().getResidentialAddress().getAddressLine2()); + Assertions.assertEquals(CITY, result.get().getResidentialAddress().getCity()); + Assertions.assertEquals(COUNTRY, result.get().getResidentialAddress().getCountry()); + Assertions.assertEquals(POSTAL, result.get().getResidentialAddress().getPostal()); + Assertions.assertEquals(PROVINCE, result.get().getResidentialAddress().getProvince()); + Assertions.assertEquals(UNSTRUCTUREDADDRESS, result.get().getResidentialAddress().getUnstructuredAddress()); + + Assertions.assertEquals(ADDRESS_1, result.get().getMailingAddress().getAddressLine1()); + Assertions.assertEquals(ADDRESS_2, result.get().getMailingAddress().getAddressLine2()); + Assertions.assertEquals(CITY, result.get().getMailingAddress().getCity()); + Assertions.assertEquals(COUNTRY, result.get().getMailingAddress().getCountry()); + Assertions.assertEquals(POSTAL, result.get().getMailingAddress().getPostal()); + Assertions.assertEquals(PROVINCE, result.get().getMailingAddress().getProvince()); + Assertions.assertEquals(UNSTRUCTUREDADDRESS, result.get().getMailingAddress().getUnstructuredAddress()); + + } + + @Test + @DisplayName("Test Return Failure") + public void withValidRequestReturnFailure() { + Mockito.when(bCeIDServiceSoapMock.getAccountDetail(any())).thenReturn(createAccountDetailsResponse(ResponseCode.FAILED)); + + Optional result = sut.getIndividualIdentity(GetAccountRequest.IndividualSelfRequest(FAILED)); + + Assertions.assertFalse(result.isPresent()); + } + + private BCeIDString getString(String value) { + BCeIDString stringVal = new BCeIDString(); + stringVal.setValue(value); + return stringVal; + } + + private AccountDetailResponse createAccountDetailsResponse(ResponseCode responseCode) { + AccountDetailResponse accountDetailResponse = new AccountDetailResponse(); + + BCeIDAccount account = new BCeIDAccount(); + + BCeIDIndividualIdentity identity = new BCeIDIndividualIdentity(); + + BCeIDName name = new BCeIDName(); + + name.setFirstname(getString(FIRSTNAME)); + name.setMiddleName(getString(MIDDLENAME)); + name.setOtherMiddleName(getString(OTHERMIDDLE)); + name.setSurname(getString(SURNAME)); + name.setInitials(getString(INITIAL)); + identity.setName(name); + + BCeIDAddress address = new BCeIDAddress(); + address.setAddressLine1(getString(ADDRESS_1)); + address.setAddressLine2(getString(ADDRESS_2)); + address.setCity(getString(CITY)); + address.setCountry(getString(COUNTRY)); + address.setPostal(getString(POSTAL)); + address.setProvince(getString(PROVINCE)); + address.setUnstructuredAddress(getString(UNSTRUCTUREDADDRESS)); + identity.setResidentialAddress(address); + identity.setMailingAddress(address); + + account.setIndividualIdentity(identity); + + accountDetailResponse.setAccount(account); + + accountDetailResponse.setCode(responseCode); + return accountDetailResponse; + } } From 444f4250677c92272b67729cae5ef3e2cf15242e Mon Sep 17 00:00:00 2001 From: TayGov Date: Mon, 17 Aug 2020 09:36:52 -0700 Subject: [PATCH 05/22] Doh --- .../open/bceid/starter/account/BCeIDAccountServiceImplTest.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/spring-bceid-starter/src/test/java/ca/bc/gov/open/bceid/starter/account/BCeIDAccountServiceImplTest.java b/src/spring-bceid-starter/src/test/java/ca/bc/gov/open/bceid/starter/account/BCeIDAccountServiceImplTest.java index 2d80913..d721766 100644 --- a/src/spring-bceid-starter/src/test/java/ca/bc/gov/open/bceid/starter/account/BCeIDAccountServiceImplTest.java +++ b/src/spring-bceid-starter/src/test/java/ca/bc/gov/open/bceid/starter/account/BCeIDAccountServiceImplTest.java @@ -8,6 +8,7 @@ import org.junit.jupiter.api.*; import org.mockito.Mock; import org.mockito.Mockito; +import org.mockito.MockitoAnnotations; import java.util.Optional; @@ -41,6 +42,7 @@ public class BCeIDAccountServiceImplTest { @BeforeEach public void init() { + MockitoAnnotations.initMocks(this); sut = new BCeIDAccountServiceImpl(bCeIDServiceSoapMock, bCeIdPropertiesMock); From 2acc6b434e38bc4d3a85fe7e637b1e49dfbba293 Mon Sep 17 00:00:00 2001 From: TayGov Date: Mon, 17 Aug 2020 09:51:01 -0700 Subject: [PATCH 06/22] UPdate test --- .../account/BCeIDAccountServiceImplTest.java | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/spring-bceid-starter/src/test/java/ca/bc/gov/open/bceid/starter/account/BCeIDAccountServiceImplTest.java b/src/spring-bceid-starter/src/test/java/ca/bc/gov/open/bceid/starter/account/BCeIDAccountServiceImplTest.java index d721766..fb57168 100644 --- a/src/spring-bceid-starter/src/test/java/ca/bc/gov/open/bceid/starter/account/BCeIDAccountServiceImplTest.java +++ b/src/spring-bceid-starter/src/test/java/ca/bc/gov/open/bceid/starter/account/BCeIDAccountServiceImplTest.java @@ -10,6 +10,12 @@ import org.mockito.Mockito; import org.mockito.MockitoAnnotations; +import javax.xml.datatype.DatatypeConfigurationException; +import javax.xml.datatype.DatatypeFactory; +import javax.xml.datatype.XMLGregorianCalendar; +import java.util.Calendar; +import java.util.Date; +import java.util.GregorianCalendar; import java.util.Optional; import static org.mockito.ArgumentMatchers.any; @@ -102,6 +108,9 @@ private AccountDetailResponse createAccountDetailsResponse(ResponseCode response BCeIDAccount account = new BCeIDAccount(); BCeIDIndividualIdentity identity = new BCeIDIndividualIdentity(); + BCeIDDateTime birthDate = new BCeIDDateTime(); + birthDate.setValue(getDate()); + identity.setDateOfBirth(birthDate); BCeIDName name = new BCeIDName(); @@ -130,4 +139,15 @@ private AccountDetailResponse createAccountDetailsResponse(ResponseCode response accountDetailResponse.setCode(responseCode); return accountDetailResponse; } + private XMLGregorianCalendar getDate() { + Calendar createDate = Calendar.getInstance(); + Date cDate = createDate.getTime(); + GregorianCalendar c = new GregorianCalendar(); + c.setTime(cDate); + try { + return DatatypeFactory.newInstance().newXMLGregorianCalendar(c); + } catch (DatatypeConfigurationException e) { + return null; + } + } } From 822523c92a1d513f6e1d35a766800baa91a40c58 Mon Sep 17 00:00:00 2001 From: alex Date: Mon, 17 Aug 2020 09:52:48 -0700 Subject: [PATCH 07/22] Adding automapper --- src/spring-bceid-starter/pom.xml | 14 ++++++++++++++ .../open/bceid/starter/AutoConfiguration.java | 7 +++++++ .../mappers/AccountDetailRequestMapper.java | 18 ++++++++++++++++++ src/spring-starters-bom/pom.xml | 1 + 4 files changed, 40 insertions(+) create mode 100644 src/spring-bceid-starter/src/main/java/ca/bc/gov/open/bceid/starter/account/mappers/AccountDetailRequestMapper.java diff --git a/src/spring-bceid-starter/pom.xml b/src/spring-bceid-starter/pom.xml index f1631c4..75a6817 100644 --- a/src/spring-bceid-starter/pom.xml +++ b/src/spring-bceid-starter/pom.xml @@ -14,6 +14,7 @@ 1.8 1.8 2.2.4.RELEASE + 1.3.1.Final @@ -66,6 +67,11 @@ joda-time + + org.mapstruct + mapstruct + + @@ -93,9 +99,17 @@ org.apache.maven.plugins maven-compiler-plugin + 3.5.1 ${java.version} ${java.version} + + + org.mapstruct + mapstruct-processor + ${org.mapstruct.version} + + diff --git a/src/spring-bceid-starter/src/main/java/ca/bc/gov/open/bceid/starter/AutoConfiguration.java b/src/spring-bceid-starter/src/main/java/ca/bc/gov/open/bceid/starter/AutoConfiguration.java index b36a4d6..88ded73 100644 --- a/src/spring-bceid-starter/src/main/java/ca/bc/gov/open/bceid/starter/AutoConfiguration.java +++ b/src/spring-bceid-starter/src/main/java/ca/bc/gov/open/bceid/starter/AutoConfiguration.java @@ -2,6 +2,8 @@ import ca.bc.gov.open.bceid.starter.account.BCeIDAccountService; import ca.bc.gov.open.bceid.starter.account.BCeIDAccountServiceImpl; +import ca.bc.gov.open.bceid.starter.account.mappers.AccountDetailRequestMapper; +import ca.bc.gov.open.bceid.starter.account.mappers.AccountDetailRequestMapperImpl; import ca.bceid.webservices.client.v9.BCeIDServiceSoap; import org.apache.commons.lang3.StringUtils; import org.apache.cxf.jaxws.JaxWsProxyFactoryBean; @@ -19,6 +21,11 @@ public AutoConfiguration(BCeIdProperties bCeIdProperties) { this.bCeIdProperties = bCeIdProperties; } + @Bean + public AccountDetailRequestMapper accountDetailRequestMapper() { + return new AccountDetailRequestMapperImpl(); + } + @Bean public BCeIDServiceSoap bCeIDServiceSoap() { diff --git a/src/spring-bceid-starter/src/main/java/ca/bc/gov/open/bceid/starter/account/mappers/AccountDetailRequestMapper.java b/src/spring-bceid-starter/src/main/java/ca/bc/gov/open/bceid/starter/account/mappers/AccountDetailRequestMapper.java new file mode 100644 index 0000000..9ca16a9 --- /dev/null +++ b/src/spring-bceid-starter/src/main/java/ca/bc/gov/open/bceid/starter/account/mappers/AccountDetailRequestMapper.java @@ -0,0 +1,18 @@ +package ca.bc.gov.open.bceid.starter.account.mappers; + +import ca.bc.gov.open.bceid.starter.account.GetAccountRequest; +import ca.bceid.webservices.client.v9.AccountDetailRequest; +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; + +@Mapper +public interface AccountDetailRequestMapper { + + @Mapping(target = "userGuid", source = "getAccountRequest.id") + @Mapping(target = "accountTypeCode", source="getAccountRequest.bCeIDAccountTypeCode") + @Mapping(target = "requesterUserGuid", source="getAccountRequest.requesterId") + @Mapping(target = "requesterAccountTypeCode", source="getAccountRequest.requesterBCeIDAccountTypeCode") + @Mapping(target = "onlineServiceId", source = "onlineServiceId") + AccountDetailRequest toAccountDetailRequest(GetAccountRequest getAccountRequest, String onlineServiceId); + +} diff --git a/src/spring-starters-bom/pom.xml b/src/spring-starters-bom/pom.xml index c885617..183758d 100644 --- a/src/spring-starters-bom/pom.xml +++ b/src/spring-starters-bom/pom.xml @@ -15,6 +15,7 @@ 2.3.1 1.4 2.10.6 + 1.3.1.Final From 764d43d9d5601e1e6b6deea580b5a1a44e4a0fa7 Mon Sep 17 00:00:00 2001 From: alex Date: Mon, 17 Aug 2020 10:14:40 -0700 Subject: [PATCH 08/22] Adding request mapper --- .../open/bceid/starter/AutoConfiguration.java | 4 +-- .../account/BCeIDAccountServiceImpl.java | 14 ++++----- .../account/BCeIDAccountServiceImplTest.java | 30 +++++++++++++------ 3 files changed, 30 insertions(+), 18 deletions(-) diff --git a/src/spring-bceid-starter/src/main/java/ca/bc/gov/open/bceid/starter/AutoConfiguration.java b/src/spring-bceid-starter/src/main/java/ca/bc/gov/open/bceid/starter/AutoConfiguration.java index 88ded73..c175458 100644 --- a/src/spring-bceid-starter/src/main/java/ca/bc/gov/open/bceid/starter/AutoConfiguration.java +++ b/src/spring-bceid-starter/src/main/java/ca/bc/gov/open/bceid/starter/AutoConfiguration.java @@ -41,7 +41,7 @@ public BCeIDServiceSoap bCeIDServiceSoap() { } @Bean - public BCeIDAccountService bCeIDUserService(BCeIDServiceSoap bCeIDServiceSoap) { - return new BCeIDAccountServiceImpl(bCeIDServiceSoap, bCeIdProperties); + public BCeIDAccountService bCeIDUserService(BCeIDServiceSoap bCeIDServiceSoap, AccountDetailRequestMapper accountDetailRequestMapper) { + return new BCeIDAccountServiceImpl(bCeIDServiceSoap, bCeIdProperties, accountDetailRequestMapper); } } diff --git a/src/spring-bceid-starter/src/main/java/ca/bc/gov/open/bceid/starter/account/BCeIDAccountServiceImpl.java b/src/spring-bceid-starter/src/main/java/ca/bc/gov/open/bceid/starter/account/BCeIDAccountServiceImpl.java index 445fc7d..bddfa0a 100644 --- a/src/spring-bceid-starter/src/main/java/ca/bc/gov/open/bceid/starter/account/BCeIDAccountServiceImpl.java +++ b/src/spring-bceid-starter/src/main/java/ca/bc/gov/open/bceid/starter/account/BCeIDAccountServiceImpl.java @@ -1,6 +1,7 @@ package ca.bc.gov.open.bceid.starter.account; import ca.bc.gov.open.bceid.starter.BCeIdProperties; +import ca.bc.gov.open.bceid.starter.account.mappers.AccountDetailRequestMapper; import ca.bc.gov.open.bceid.starter.account.models.Address; import ca.bc.gov.open.bceid.starter.account.models.IndividualIdentity; import ca.bc.gov.open.bceid.starter.account.models.Name; @@ -15,20 +16,19 @@ public class BCeIDAccountServiceImpl implements BCeIDAccountService { private final BCeIdProperties bCeIdProperties; - public BCeIDAccountServiceImpl(BCeIDServiceSoap bCeIDServiceSoap, BCeIdProperties bCeIdProperties) { + private final AccountDetailRequestMapper accountDetailRequestMapper; + + public BCeIDAccountServiceImpl(BCeIDServiceSoap bCeIDServiceSoap, BCeIdProperties bCeIdProperties, AccountDetailRequestMapper accountDetailRequestMapper) { this.bCeIDServiceSoap = bCeIDServiceSoap; this.bCeIdProperties = bCeIdProperties; + this.accountDetailRequestMapper = accountDetailRequestMapper; } @Override public Optional getIndividualIdentity(GetAccountRequest request) { - AccountDetailRequest accountDetailRequest = new AccountDetailRequest(); - accountDetailRequest.setOnlineServiceId(bCeIdProperties.getOnlineServiceId()); - accountDetailRequest.setRequesterUserGuid(request.getId()); - accountDetailRequest.setRequesterAccountTypeCode(request.getbCeIDAccountTypeCode()); - accountDetailRequest.setUserGuid(request.getRequesterId()); - accountDetailRequest.setAccountTypeCode(request.getRequesterBCeIDAccountTypeCode()); + AccountDetailRequest accountDetailRequest = accountDetailRequestMapper.toAccountDetailRequest(request, bCeIdProperties.getOnlineServiceId()); + AccountDetailResponse response = bCeIDServiceSoap.getAccountDetail(accountDetailRequest); if (response.getCode() == ResponseCode.SUCCESS) { diff --git a/src/spring-bceid-starter/src/test/java/ca/bc/gov/open/bceid/starter/account/BCeIDAccountServiceImplTest.java b/src/spring-bceid-starter/src/test/java/ca/bc/gov/open/bceid/starter/account/BCeIDAccountServiceImplTest.java index fb57168..fc4a1ab 100644 --- a/src/spring-bceid-starter/src/test/java/ca/bc/gov/open/bceid/starter/account/BCeIDAccountServiceImplTest.java +++ b/src/spring-bceid-starter/src/test/java/ca/bc/gov/open/bceid/starter/account/BCeIDAccountServiceImplTest.java @@ -1,11 +1,12 @@ package ca.bc.gov.open.bceid.starter.account; import ca.bc.gov.open.bceid.starter.BCeIdProperties; -import ca.bc.gov.open.bceid.starter.account.models.Address; +import ca.bc.gov.open.bceid.starter.account.mappers.AccountDetailRequestMapper; +import ca.bc.gov.open.bceid.starter.account.mappers.AccountDetailRequestMapperImpl; import ca.bc.gov.open.bceid.starter.account.models.IndividualIdentity; -import ca.bc.gov.open.bceid.starter.account.models.Name; import ca.bceid.webservices.client.v9.*; import org.junit.jupiter.api.*; +import org.mockito.ArgumentMatchers; import org.mockito.Mock; import org.mockito.Mockito; import org.mockito.MockitoAnnotations; @@ -18,8 +19,6 @@ import java.util.GregorianCalendar; import java.util.Optional; -import static org.mockito.ArgumentMatchers.any; - @TestInstance(TestInstance.Lifecycle.PER_CLASS) @DisplayName("Test BCeIDAccountServiceImpl") public class BCeIDAccountServiceImplTest { @@ -40,24 +39,37 @@ public class BCeIDAccountServiceImplTest { BCeIDAccountServiceImpl sut; @Mock - BCeIDServiceSoap bCeIDServiceSoapMock; + private BCeIDServiceSoap bCeIDServiceSoapMock; @Mock - BCeIdProperties bCeIdPropertiesMock; + private BCeIdProperties bCeIdPropertiesMock; + private AccountDetailRequestMapper accountDetailRequestMapper; @BeforeEach public void init() { + MockitoAnnotations.initMocks(this); - sut = new BCeIDAccountServiceImpl(bCeIDServiceSoapMock, bCeIdPropertiesMock); + Mockito.doReturn(createAccountDetailsResponse(ResponseCode.SUCCESS)) + .when(bCeIDServiceSoapMock) + .getAccountDetail(ArgumentMatchers.argThat(x -> x.getUserGuid().equals(SUCCESS) && x.getAccountTypeCode() == BCeIDAccountTypeCode.INDIVIDUAL)); + + Mockito + .doReturn(createAccountDetailsResponse(ResponseCode.FAILED)) + .when(bCeIDServiceSoapMock) + .getAccountDetail(ArgumentMatchers.argThat(x -> x.getUserGuid().equals(FAILED))); + + // Testing mapper as part of the test + accountDetailRequestMapper = new AccountDetailRequestMapperImpl(); + + sut = new BCeIDAccountServiceImpl(bCeIDServiceSoapMock, bCeIdPropertiesMock, accountDetailRequestMapper); } @Test @DisplayName("Test Return Individual Identity") public void withValidRequestReturnAccount() { - Mockito.when(bCeIDServiceSoapMock.getAccountDetail(any())).thenReturn(createAccountDetailsResponse(ResponseCode.SUCCESS)); Optional result = sut.getIndividualIdentity(GetAccountRequest.IndividualSelfRequest(SUCCESS)); @@ -89,7 +101,7 @@ public void withValidRequestReturnAccount() { @Test @DisplayName("Test Return Failure") public void withValidRequestReturnFailure() { - Mockito.when(bCeIDServiceSoapMock.getAccountDetail(any())).thenReturn(createAccountDetailsResponse(ResponseCode.FAILED)); + Optional result = sut.getIndividualIdentity(GetAccountRequest.IndividualSelfRequest(FAILED)); From df28f07e6c1e287e1afacffd71b1384f2eed19f7 Mon Sep 17 00:00:00 2001 From: TayGov Date: Mon, 17 Aug 2020 10:08:05 -0700 Subject: [PATCH 09/22] Add test and update another --- .../account/BCeIDAccountServiceImplTest.java | 2 + .../account/GetAccountRequestTest.java | 88 +++++++++++++++++++ 2 files changed, 90 insertions(+) create mode 100644 src/spring-bceid-starter/src/test/java/ca/bc/gov/open/bceid/starter/account/GetAccountRequestTest.java diff --git a/src/spring-bceid-starter/src/test/java/ca/bc/gov/open/bceid/starter/account/BCeIDAccountServiceImplTest.java b/src/spring-bceid-starter/src/test/java/ca/bc/gov/open/bceid/starter/account/BCeIDAccountServiceImplTest.java index fc4a1ab..a1013d5 100644 --- a/src/spring-bceid-starter/src/test/java/ca/bc/gov/open/bceid/starter/account/BCeIDAccountServiceImplTest.java +++ b/src/spring-bceid-starter/src/test/java/ca/bc/gov/open/bceid/starter/account/BCeIDAccountServiceImplTest.java @@ -96,6 +96,8 @@ public void withValidRequestReturnAccount() { Assertions.assertEquals(PROVINCE, result.get().getMailingAddress().getProvince()); Assertions.assertEquals(UNSTRUCTUREDADDRESS, result.get().getMailingAddress().getUnstructuredAddress()); + Assertions.assertNotNull(result.get().getDateOfBirth()); + } @Test diff --git a/src/spring-bceid-starter/src/test/java/ca/bc/gov/open/bceid/starter/account/GetAccountRequestTest.java b/src/spring-bceid-starter/src/test/java/ca/bc/gov/open/bceid/starter/account/GetAccountRequestTest.java new file mode 100644 index 0000000..36ea308 --- /dev/null +++ b/src/spring-bceid-starter/src/test/java/ca/bc/gov/open/bceid/starter/account/GetAccountRequestTest.java @@ -0,0 +1,88 @@ +package ca.bc.gov.open.bceid.starter.account; + +import ca.bceid.webservices.client.v9.BCeIDAccountTypeCode; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestInstance; + +@TestInstance(TestInstance.Lifecycle.PER_CLASS) +@DisplayName("Test BCeIDAccountServiceImpl") +public class GetAccountRequestTest { + + private static final String ID = "ID"; + + @Test + @DisplayName("Test Static BusinessSelfRequest") + public void testStaticMethodBusinessSelfRequest() { + GetAccountRequest result = GetAccountRequest.BusinessSelfRequest(ID); + + Assertions.assertEquals(ID, result.getId()); + Assertions.assertEquals(ID, result.getRequesterId()); + Assertions.assertEquals(BCeIDAccountTypeCode.BUSINESS, result.getbCeIDAccountTypeCode()); + Assertions.assertEquals(BCeIDAccountTypeCode.BUSINESS, result.getRequesterBCeIDAccountTypeCode()); + } + + @Test + @DisplayName("Test Static EdsSelfRequest") + public void testStaticMethodEdsSelfRequest() { + GetAccountRequest result = GetAccountRequest.EdsSelfRequest(ID); + + Assertions.assertEquals(ID, result.getId()); + Assertions.assertEquals(ID, result.getRequesterId()); + Assertions.assertEquals(BCeIDAccountTypeCode.EDS, result.getbCeIDAccountTypeCode()); + Assertions.assertEquals(BCeIDAccountTypeCode.EDS, result.getRequesterBCeIDAccountTypeCode()); + } + + + @Test + @DisplayName("Test Static IndividualSelfRequest") + public void testStaticMethodIndividualSelfRequest() { + GetAccountRequest result = GetAccountRequest.IndividualSelfRequest(ID); + + Assertions.assertEquals(ID, result.getId()); + Assertions.assertEquals(ID, result.getRequesterId()); + Assertions.assertEquals(BCeIDAccountTypeCode.INDIVIDUAL, result.getbCeIDAccountTypeCode()); + Assertions.assertEquals(BCeIDAccountTypeCode.INDIVIDUAL, result.getRequesterBCeIDAccountTypeCode()); + } + + + @Test + @DisplayName("Test Static InternalSelfRequest") + public void testStaticMethodInternalSelfRequest() { + GetAccountRequest result = GetAccountRequest.InternalSelfRequest(ID); + + Assertions.assertEquals(ID, result.getId()); + Assertions.assertEquals(ID, result.getRequesterId()); + Assertions.assertEquals(BCeIDAccountTypeCode.INTERNAL, result.getbCeIDAccountTypeCode()); + Assertions.assertEquals(BCeIDAccountTypeCode.INTERNAL, result.getRequesterBCeIDAccountTypeCode()); + } + + @Test + @DisplayName("Test Static LdbSelfRequest") + public void testStaticMethodLdbSelfRequest() { + GetAccountRequest result = GetAccountRequest.LdbSelfRequest(ID); + + Assertions.assertEquals(ID, result.getId()); + Assertions.assertEquals(ID, result.getRequesterId()); + Assertions.assertEquals(BCeIDAccountTypeCode.LDB, result.getbCeIDAccountTypeCode()); + Assertions.assertEquals(BCeIDAccountTypeCode.LDB, result.getRequesterBCeIDAccountTypeCode()); + } + + @Test + @DisplayName("Test Static VerifiedIndividualSelfRequest") + public void testStaticMethodVerifiedIndividualSelfRequest() { + GetAccountRequest result = GetAccountRequest.VerifiedIndividualSelfRequest(ID); + + Assertions.assertEquals(ID, result.getId()); + Assertions.assertEquals(ID, result.getRequesterId()); + Assertions.assertEquals(BCeIDAccountTypeCode.VERIFIED_INDIVIDUAL, result.getbCeIDAccountTypeCode()); + Assertions.assertEquals(BCeIDAccountTypeCode.VERIFIED_INDIVIDUAL, result.getRequesterBCeIDAccountTypeCode()); + } + + @Test + @DisplayName("Test No Id Exception") + public void testException() { + Assertions.assertThrows(IllegalArgumentException.class,() -> GetAccountRequest.IndividualSelfRequest(null)); + } +} From 80e6179453d723864b72bf3fe96cd9aeb78fc8e4 Mon Sep 17 00:00:00 2001 From: TayGov Date: Mon, 17 Aug 2020 10:25:33 -0700 Subject: [PATCH 10/22] Add test for mapper bean --- .../ca/bc/gov/open/bceid/starter/AutoConfigurationTest.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/spring-bceid-starter/src/test/java/ca/bc/gov/open/bceid/starter/AutoConfigurationTest.java b/src/spring-bceid-starter/src/test/java/ca/bc/gov/open/bceid/starter/AutoConfigurationTest.java index d831ad6..f3a005e 100644 --- a/src/spring-bceid-starter/src/test/java/ca/bc/gov/open/bceid/starter/AutoConfigurationTest.java +++ b/src/spring-bceid-starter/src/test/java/ca/bc/gov/open/bceid/starter/AutoConfigurationTest.java @@ -1,6 +1,7 @@ package ca.bc.gov.open.bceid.starter; import ca.bc.gov.open.bceid.starter.account.BCeIDAccountService; +import ca.bc.gov.open.bceid.starter.account.mappers.AccountDetailRequestMapper; import ca.bceid.webservices.client.v9.BCeIDServiceSoap; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.DisplayName; @@ -19,6 +20,7 @@ public class AutoConfigurationTest { public void testConfigure() { context.run(it -> { + Assertions.assertNotNull(assertThat(it).getBean(AccountDetailRequestMapper.class)); Assertions.assertNotNull(assertThat(it).getBean(BCeIDServiceSoap.class)); Assertions.assertNotNull(assertThat(it).getBean(BCeIDAccountService.class)); }); From f0152bf209ce382ba5cce2aca111afeddda8970d Mon Sep 17 00:00:00 2001 From: alex Date: Mon, 17 Aug 2020 11:41:31 -0700 Subject: [PATCH 11/22] Adding mapper --- .../open/bceid/starter/AutoConfiguration.java | 11 +++- .../account/BCeIDAccountServiceImpl.java | 48 +++----------- .../account/mappers/AddressMapper.java | 20 ++++++ .../starter/account/mappers/BCeIdMapper.java | 24 +++++++ .../mappers/IndividualIdentityMapper.java | 18 +++++ .../starter/account/mappers/NameMapper.java | 18 +++++ .../bceid/starter/account/models/Address.java | 66 +++++++++++++++++++ .../account/models/IndividualIdentity.java | 45 +++++++++++++ .../bceid/starter/account/models/Name.java | 64 ++++++++++++++++-- .../account/BCeIDAccountServiceImplTest.java | 9 ++- 10 files changed, 276 insertions(+), 47 deletions(-) create mode 100644 src/spring-bceid-starter/src/main/java/ca/bc/gov/open/bceid/starter/account/mappers/AddressMapper.java create mode 100644 src/spring-bceid-starter/src/main/java/ca/bc/gov/open/bceid/starter/account/mappers/BCeIdMapper.java create mode 100644 src/spring-bceid-starter/src/main/java/ca/bc/gov/open/bceid/starter/account/mappers/IndividualIdentityMapper.java create mode 100644 src/spring-bceid-starter/src/main/java/ca/bc/gov/open/bceid/starter/account/mappers/NameMapper.java diff --git a/src/spring-bceid-starter/src/main/java/ca/bc/gov/open/bceid/starter/AutoConfiguration.java b/src/spring-bceid-starter/src/main/java/ca/bc/gov/open/bceid/starter/AutoConfiguration.java index c175458..bf47365 100644 --- a/src/spring-bceid-starter/src/main/java/ca/bc/gov/open/bceid/starter/AutoConfiguration.java +++ b/src/spring-bceid-starter/src/main/java/ca/bc/gov/open/bceid/starter/AutoConfiguration.java @@ -4,6 +4,8 @@ import ca.bc.gov.open.bceid.starter.account.BCeIDAccountServiceImpl; import ca.bc.gov.open.bceid.starter.account.mappers.AccountDetailRequestMapper; import ca.bc.gov.open.bceid.starter.account.mappers.AccountDetailRequestMapperImpl; +import ca.bc.gov.open.bceid.starter.account.mappers.IndividualIdentityMapper; +import ca.bc.gov.open.bceid.starter.account.mappers.IndividualIdentityMapperImpl; import ca.bceid.webservices.client.v9.BCeIDServiceSoap; import org.apache.commons.lang3.StringUtils; import org.apache.cxf.jaxws.JaxWsProxyFactoryBean; @@ -26,6 +28,11 @@ public AccountDetailRequestMapper accountDetailRequestMapper() { return new AccountDetailRequestMapperImpl(); } + @Bean + public IndividualIdentityMapper individualIdentityMapper() { + return new IndividualIdentityMapperImpl(); + } + @Bean public BCeIDServiceSoap bCeIDServiceSoap() { @@ -41,7 +48,7 @@ public BCeIDServiceSoap bCeIDServiceSoap() { } @Bean - public BCeIDAccountService bCeIDUserService(BCeIDServiceSoap bCeIDServiceSoap, AccountDetailRequestMapper accountDetailRequestMapper) { - return new BCeIDAccountServiceImpl(bCeIDServiceSoap, bCeIdProperties, accountDetailRequestMapper); + public BCeIDAccountService bCeIDUserService(BCeIDServiceSoap bCeIDServiceSoap, AccountDetailRequestMapper accountDetailRequestMapper, IndividualIdentityMapper individualIdentityMapper) { + return new BCeIDAccountServiceImpl(bCeIDServiceSoap, bCeIdProperties, accountDetailRequestMapper, individualIdentityMapper); } } diff --git a/src/spring-bceid-starter/src/main/java/ca/bc/gov/open/bceid/starter/account/BCeIDAccountServiceImpl.java b/src/spring-bceid-starter/src/main/java/ca/bc/gov/open/bceid/starter/account/BCeIDAccountServiceImpl.java index bddfa0a..09f2201 100644 --- a/src/spring-bceid-starter/src/main/java/ca/bc/gov/open/bceid/starter/account/BCeIDAccountServiceImpl.java +++ b/src/spring-bceid-starter/src/main/java/ca/bc/gov/open/bceid/starter/account/BCeIDAccountServiceImpl.java @@ -2,11 +2,12 @@ import ca.bc.gov.open.bceid.starter.BCeIdProperties; import ca.bc.gov.open.bceid.starter.account.mappers.AccountDetailRequestMapper; -import ca.bc.gov.open.bceid.starter.account.models.Address; +import ca.bc.gov.open.bceid.starter.account.mappers.IndividualIdentityMapper; import ca.bc.gov.open.bceid.starter.account.models.IndividualIdentity; -import ca.bc.gov.open.bceid.starter.account.models.Name; -import ca.bceid.webservices.client.v9.*; -import org.joda.time.DateTime; +import ca.bceid.webservices.client.v9.AccountDetailRequest; +import ca.bceid.webservices.client.v9.AccountDetailResponse; +import ca.bceid.webservices.client.v9.BCeIDServiceSoap; +import ca.bceid.webservices.client.v9.ResponseCode; import java.util.Optional; @@ -18,10 +19,13 @@ public class BCeIDAccountServiceImpl implements BCeIDAccountService { private final AccountDetailRequestMapper accountDetailRequestMapper; - public BCeIDAccountServiceImpl(BCeIDServiceSoap bCeIDServiceSoap, BCeIdProperties bCeIdProperties, AccountDetailRequestMapper accountDetailRequestMapper) { + private final IndividualIdentityMapper individualIdentityMapper; + + public BCeIDAccountServiceImpl(BCeIDServiceSoap bCeIDServiceSoap, BCeIdProperties bCeIdProperties, AccountDetailRequestMapper accountDetailRequestMapper, IndividualIdentityMapper individualIdentityMapper) { this.bCeIDServiceSoap = bCeIDServiceSoap; this.bCeIdProperties = bCeIdProperties; this.accountDetailRequestMapper = accountDetailRequestMapper; + this.individualIdentityMapper = individualIdentityMapper; } @Override @@ -33,39 +37,7 @@ public Optional getIndividualIdentity(GetAccountRequest requ if (response.getCode() == ResponseCode.SUCCESS) { - Name name = new Name( - response.getAccount().getIndividualIdentity().getName().getFirstname().getValue(), - response.getAccount().getIndividualIdentity().getName().getMiddleName().getValue(), - response.getAccount().getIndividualIdentity().getName().getOtherMiddleName().getValue(), - response.getAccount().getIndividualIdentity().getName().getSurname().getValue(), - response.getAccount().getIndividualIdentity().getName().getInitials().getValue()); - - - BCeIDAddress bresidentialAddress = response.getAccount().getIndividualIdentity().getResidentialAddress(); - - Address residentialAddress = new Address(bresidentialAddress.getAddressLine1().getValue(), - bresidentialAddress.getAddressLine2().getValue(), - bresidentialAddress.getCity().getValue(), - bresidentialAddress.getPostal().getValue(), - bresidentialAddress.getProvince().getValue(), - bresidentialAddress.getCountry().getValue(), - bresidentialAddress.getUnstructuredAddress().getValue()); - - BCeIDAddress bmailingAddress = response.getAccount().getIndividualIdentity().getMailingAddress(); - - Address mailingAddress = new Address(bmailingAddress.getAddressLine1().getValue(), - bmailingAddress.getAddressLine2().getValue(), - bmailingAddress.getCity().getValue(), - bmailingAddress.getPostal().getValue(), - bmailingAddress.getProvince().getValue(), - bmailingAddress.getCountry().getValue(), - bmailingAddress.getUnstructuredAddress().getValue()); - - return Optional.of(new IndividualIdentity( - name, - new DateTime(response.getAccount().getIndividualIdentity().getDateOfBirth().getValue().toGregorianCalendar().getTime()), - residentialAddress, - mailingAddress)); + return Optional.of(individualIdentityMapper.toIndividualIdentity(response)); } diff --git a/src/spring-bceid-starter/src/main/java/ca/bc/gov/open/bceid/starter/account/mappers/AddressMapper.java b/src/spring-bceid-starter/src/main/java/ca/bc/gov/open/bceid/starter/account/mappers/AddressMapper.java new file mode 100644 index 0000000..205dad0 --- /dev/null +++ b/src/spring-bceid-starter/src/main/java/ca/bc/gov/open/bceid/starter/account/mappers/AddressMapper.java @@ -0,0 +1,20 @@ +package ca.bc.gov.open.bceid.starter.account.mappers; + +import ca.bc.gov.open.bceid.starter.account.models.Address; +import ca.bceid.webservices.client.v9.BCeIDAddress; +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; + +@Mapper(uses = { BCeIdMapper.class }) +public interface AddressMapper { + + @Mapping(source="addressLine1", target = "addressLine1", qualifiedByName= {"BCeIdMapper", "toString"}) + @Mapping(source="addressLine2", target = "addressLine2", qualifiedByName= {"BCeIdMapper", "toString"}) + @Mapping(source="city", target = "city", qualifiedByName= {"BCeIdMapper", "toString"}) + @Mapping(source="postal", target = "postal", qualifiedByName= {"BCeIdMapper", "toString"}) + @Mapping(source="province", target = "province", qualifiedByName= {"BCeIdMapper", "toString"}) + @Mapping(source="country", target = "country", qualifiedByName= {"BCeIdMapper", "toString"}) + @Mapping(source="unstructuredAddress", target = "unstructuredAddress", qualifiedByName= {"BCeIdMapper", "toString"}) + Address toAddress(BCeIDAddress bCeIDAddress); + +} diff --git a/src/spring-bceid-starter/src/main/java/ca/bc/gov/open/bceid/starter/account/mappers/BCeIdMapper.java b/src/spring-bceid-starter/src/main/java/ca/bc/gov/open/bceid/starter/account/mappers/BCeIdMapper.java new file mode 100644 index 0000000..d2424cc --- /dev/null +++ b/src/spring-bceid-starter/src/main/java/ca/bc/gov/open/bceid/starter/account/mappers/BCeIdMapper.java @@ -0,0 +1,24 @@ +package ca.bc.gov.open.bceid.starter.account.mappers; + +import ca.bceid.webservices.client.v9.BCeIDDateTime; +import ca.bceid.webservices.client.v9.BCeIDString; +import org.joda.time.DateTime; +import org.mapstruct.Named; + +import javax.xml.datatype.DatatypeConfigurationException; + +@Named("BCeIdMapper") +public interface BCeIdMapper { + + @Named("toString") + static String toString(BCeIDString bCeIDString) throws DatatypeConfigurationException { + return bCeIDString.getValue(); + } + + @Named("toDateTime") + static DateTime toDateTime(BCeIDDateTime bCeIDDateTime) throws DatatypeConfigurationException { + return new DateTime(bCeIDDateTime.getValue().toGregorianCalendar().getTime()); + } + + +} diff --git a/src/spring-bceid-starter/src/main/java/ca/bc/gov/open/bceid/starter/account/mappers/IndividualIdentityMapper.java b/src/spring-bceid-starter/src/main/java/ca/bc/gov/open/bceid/starter/account/mappers/IndividualIdentityMapper.java new file mode 100644 index 0000000..e0f1a4e --- /dev/null +++ b/src/spring-bceid-starter/src/main/java/ca/bc/gov/open/bceid/starter/account/mappers/IndividualIdentityMapper.java @@ -0,0 +1,18 @@ +package ca.bc.gov.open.bceid.starter.account.mappers; + +import ca.bc.gov.open.bceid.starter.account.models.IndividualIdentity; +import ca.bceid.webservices.client.v9.AccountDetailResponse; +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; + +@Mapper(uses = {NameMapper.class, BCeIdMapper.class, AddressMapper.class}) +public interface IndividualIdentityMapper { + + @Mapping(target = "dateOfBirth", source="account.individualIdentity.dateOfBirth", qualifiedByName= {"BCeIdMapper", "toDateTime"}) + @Mapping(target = "name", source="account.individualIdentity.name") + @Mapping(target = "residentialAddress", source="account.individualIdentity.residentialAddress") + @Mapping(target = "mailingAddress", source="account.individualIdentity.mailingAddress") + IndividualIdentity toIndividualIdentity(AccountDetailResponse accountDetailResponse); + + +} diff --git a/src/spring-bceid-starter/src/main/java/ca/bc/gov/open/bceid/starter/account/mappers/NameMapper.java b/src/spring-bceid-starter/src/main/java/ca/bc/gov/open/bceid/starter/account/mappers/NameMapper.java new file mode 100644 index 0000000..f021d08 --- /dev/null +++ b/src/spring-bceid-starter/src/main/java/ca/bc/gov/open/bceid/starter/account/mappers/NameMapper.java @@ -0,0 +1,18 @@ +package ca.bc.gov.open.bceid.starter.account.mappers; + +import ca.bc.gov.open.bceid.starter.account.models.Name; +import ca.bceid.webservices.client.v9.BCeIDName; +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; + +@Mapper(uses = BCeIdMapper.class) +public interface NameMapper { + + @Mapping(target = "firstName", source = "firstname", qualifiedByName= { "BCeIdMapper", "toString"} ) + @Mapping(target = "middleName", source = "middleName", qualifiedByName= { "BCeIdMapper", "toString"} ) + @Mapping(target = "otherMiddleName", source = "otherMiddleName", qualifiedByName= { "BCeIdMapper", "toString"} ) + @Mapping(target = "surname", source = "surname", qualifiedByName= { "BCeIdMapper", "toString"} ) + @Mapping(target = "initials", source = "initials", qualifiedByName= { "BCeIdMapper", "toString"} ) + Name toName(BCeIDName bCeIDName); + +} diff --git a/src/spring-bceid-starter/src/main/java/ca/bc/gov/open/bceid/starter/account/models/Address.java b/src/spring-bceid-starter/src/main/java/ca/bc/gov/open/bceid/starter/account/models/Address.java index 55ee3ae..bdfa4e1 100644 --- a/src/spring-bceid-starter/src/main/java/ca/bc/gov/open/bceid/starter/account/models/Address.java +++ b/src/spring-bceid-starter/src/main/java/ca/bc/gov/open/bceid/starter/account/models/Address.java @@ -10,6 +10,16 @@ public class Address { private String country; private String unstructuredAddress; + protected Address(Builder builder) { + this.addressLine1 = builder.addressLine1; + this.addressLine2 = builder.addressLine2; + this.city = builder.city; + this.postal = builder.postal; + this.province = builder.province; + this.country = builder.country; + this.unstructuredAddress = builder.unstructuredAddress; + } + public Address(String addressLine1, String addressLine2, String city, String postal, String province, String country, String unstructuredAddress) { this.addressLine1 = addressLine1; this.addressLine2 = addressLine2; @@ -47,4 +57,60 @@ public String getCountry() { public String getUnstructuredAddress() { return unstructuredAddress; } + + public static Address.Builder builder() { + return new Address.Builder(); + } + + public static class Builder { + + private String addressLine1; + private String addressLine2; + private String city; + private String postal; + private String province; + private String country; + private String unstructuredAddress; + + public Builder addressLine1(String addressLine1) { + this.addressLine1 = addressLine1; + return this; + } + + public Builder addressLine2(String addressLine2) { + this.addressLine2 = addressLine2; + return this; + } + + public Builder city(String city) { + this.city = city; + return this; + } + + public Builder postal(String postal) { + this.postal = postal; + return this; + } + + public Builder province(String province) { + this.province = province; + return this; + } + + public Builder country(String country) { + this.country = country; + return this; + } + + public Builder unstructuredAddress(String unstructuredAddress) { + this.unstructuredAddress = unstructuredAddress; + return this; + } + + public Address create() { + return new Address(this); + } + + } + } diff --git a/src/spring-bceid-starter/src/main/java/ca/bc/gov/open/bceid/starter/account/models/IndividualIdentity.java b/src/spring-bceid-starter/src/main/java/ca/bc/gov/open/bceid/starter/account/models/IndividualIdentity.java index 4a4b7e3..0489be6 100644 --- a/src/spring-bceid-starter/src/main/java/ca/bc/gov/open/bceid/starter/account/models/IndividualIdentity.java +++ b/src/spring-bceid-starter/src/main/java/ca/bc/gov/open/bceid/starter/account/models/IndividualIdentity.java @@ -9,6 +9,13 @@ public class IndividualIdentity { private Address residentialAddress; private Address mailingAddress; + protected IndividualIdentity(Builder builder) { + this.name = builder.name; + this.dateOfBirth = builder.dateOfBirth; + this.residentialAddress = builder.residentialAddress; + this.mailingAddress = builder.mailingAddress; + } + public IndividualIdentity(Name name, DateTime dateOfBirth, Address residentialAddress, Address mailingAddress) { this.name = name; this.dateOfBirth = dateOfBirth; @@ -31,4 +38,42 @@ public Address getResidentialAddress() { public Address getMailingAddress() { return mailingAddress; } + + public static IndividualIdentity.Builder builder() { + return new IndividualIdentity.Builder(); + } + + public static class Builder { + + private Name name; + private DateTime dateOfBirth; + private Address residentialAddress; + private Address mailingAddress; + + public Builder name(Name name) { + this.name = name; + return this; + } + + public Builder dateOfBirth(DateTime dateOfBirth) { + this.dateOfBirth = dateOfBirth; + return this; + } + + public Builder residentialAddress(Address residentialAddress) { + this.residentialAddress = residentialAddress; + return this; + } + + public Builder mailingAddress(Address mailingAddress) { + this.mailingAddress = mailingAddress; + return this; + } + + public IndividualIdentity create() { + return new IndividualIdentity(this); + } + + } + } diff --git a/src/spring-bceid-starter/src/main/java/ca/bc/gov/open/bceid/starter/account/models/Name.java b/src/spring-bceid-starter/src/main/java/ca/bc/gov/open/bceid/starter/account/models/Name.java index 289629c..8c981fd 100644 --- a/src/spring-bceid-starter/src/main/java/ca/bc/gov/open/bceid/starter/account/models/Name.java +++ b/src/spring-bceid-starter/src/main/java/ca/bc/gov/open/bceid/starter/account/models/Name.java @@ -2,22 +2,30 @@ public class Name { - private String firstname; + private String firstName; private String middleName; private String otherMiddleName; private String surname; private String initials; - public Name(String firstname, String middleName, String otherMiddleName, String surname, String initials) { - this.firstname = firstname; + protected Name(Builder builder) { + this.firstName = builder.firstName; + this.middleName = builder.middleName; + this.otherMiddleName = builder.otherMiddleName; + this.surname = builder.surname; + this.initials = builder.initials; + } + + public Name(String firstName, String middleName, String otherMiddleName, String surname, String initials) { + this.firstName = firstName; this.middleName = middleName; this.otherMiddleName = otherMiddleName; this.surname = surname; this.initials = initials; } - public String getFirstname() { - return firstname; + public String getFirstName() { + return firstName; } public String getMiddleName() { @@ -35,4 +43,50 @@ public String getSurname() { public String getInitials() { return initials; } + + public static Name.Builder builder() { + return new Name.Builder(); + } + + public static class Builder { + + private String firstName; + private String middleName; + private String otherMiddleName; + private String surname; + private String initials; + + + public Builder firstName(String firstName) { + this.firstName = firstName; + return this; + } + + public Builder middleName(String middleName) { + this.middleName = middleName; + return this; + } + + public Builder otherMiddleName(String otherMiddleName) { + this.otherMiddleName = otherMiddleName; + return this; + } + + public Builder surname(String surname) { + this.surname = surname; + return this; + } + + public Builder initials(String initials) { + this.initials = initials; + return this; + } + + + public Name create() { + return new Name(this); + } + + } + } diff --git a/src/spring-bceid-starter/src/test/java/ca/bc/gov/open/bceid/starter/account/BCeIDAccountServiceImplTest.java b/src/spring-bceid-starter/src/test/java/ca/bc/gov/open/bceid/starter/account/BCeIDAccountServiceImplTest.java index fc4a1ab..226545a 100644 --- a/src/spring-bceid-starter/src/test/java/ca/bc/gov/open/bceid/starter/account/BCeIDAccountServiceImplTest.java +++ b/src/spring-bceid-starter/src/test/java/ca/bc/gov/open/bceid/starter/account/BCeIDAccountServiceImplTest.java @@ -3,6 +3,8 @@ import ca.bc.gov.open.bceid.starter.BCeIdProperties; import ca.bc.gov.open.bceid.starter.account.mappers.AccountDetailRequestMapper; import ca.bc.gov.open.bceid.starter.account.mappers.AccountDetailRequestMapperImpl; +import ca.bc.gov.open.bceid.starter.account.mappers.IndividualIdentityMapper; +import ca.bc.gov.open.bceid.starter.account.mappers.IndividualIdentityMapperImpl; import ca.bc.gov.open.bceid.starter.account.models.IndividualIdentity; import ca.bceid.webservices.client.v9.*; import org.junit.jupiter.api.*; @@ -46,6 +48,8 @@ public class BCeIDAccountServiceImplTest { private AccountDetailRequestMapper accountDetailRequestMapper; + private IndividualIdentityMapper individualIdentityMapper; + @BeforeEach public void init() { @@ -62,8 +66,9 @@ public void init() { // Testing mapper as part of the test accountDetailRequestMapper = new AccountDetailRequestMapperImpl(); + individualIdentityMapper = new IndividualIdentityMapperImpl(); - sut = new BCeIDAccountServiceImpl(bCeIDServiceSoapMock, bCeIdPropertiesMock, accountDetailRequestMapper); + sut = new BCeIDAccountServiceImpl(bCeIDServiceSoapMock, bCeIdPropertiesMock, accountDetailRequestMapper, individualIdentityMapper); } @@ -74,7 +79,7 @@ public void withValidRequestReturnAccount() { Optional result = sut.getIndividualIdentity(GetAccountRequest.IndividualSelfRequest(SUCCESS)); Assertions.assertTrue(result.isPresent()); - Assertions.assertEquals(FIRSTNAME, result.get().getName().getFirstname()); + Assertions.assertEquals(FIRSTNAME, result.get().getName().getFirstName()); Assertions.assertEquals(INITIAL, result.get().getName().getInitials()); Assertions.assertEquals(MIDDLENAME, result.get().getName().getMiddleName()); Assertions.assertEquals(OTHERMIDDLE, result.get().getName().getOtherMiddleName()); From 1613218f8b7d36a2c42c043f062702770ceaa40d Mon Sep 17 00:00:00 2001 From: TayGov Date: Mon, 17 Aug 2020 11:47:28 -0700 Subject: [PATCH 12/22] Add formatting --- .../starter/account/BCeIDAccountServiceImplTest.java | 8 +++++++- .../bceid/starter/account/GetAccountRequestTest.java | 12 ++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/src/spring-bceid-starter/src/test/java/ca/bc/gov/open/bceid/starter/account/BCeIDAccountServiceImplTest.java b/src/spring-bceid-starter/src/test/java/ca/bc/gov/open/bceid/starter/account/BCeIDAccountServiceImplTest.java index a1013d5..5290908 100644 --- a/src/spring-bceid-starter/src/test/java/ca/bc/gov/open/bceid/starter/account/BCeIDAccountServiceImplTest.java +++ b/src/spring-bceid-starter/src/test/java/ca/bc/gov/open/bceid/starter/account/BCeIDAccountServiceImplTest.java @@ -104,19 +104,21 @@ public void withValidRequestReturnAccount() { @DisplayName("Test Return Failure") public void withValidRequestReturnFailure() { - Optional result = sut.getIndividualIdentity(GetAccountRequest.IndividualSelfRequest(FAILED)); Assertions.assertFalse(result.isPresent()); } private BCeIDString getString(String value) { + BCeIDString stringVal = new BCeIDString(); stringVal.setValue(value); return stringVal; + } private AccountDetailResponse createAccountDetailsResponse(ResponseCode responseCode) { + AccountDetailResponse accountDetailResponse = new AccountDetailResponse(); BCeIDAccount account = new BCeIDAccount(); @@ -152,8 +154,10 @@ private AccountDetailResponse createAccountDetailsResponse(ResponseCode response accountDetailResponse.setCode(responseCode); return accountDetailResponse; + } private XMLGregorianCalendar getDate() { + Calendar createDate = Calendar.getInstance(); Date cDate = createDate.getTime(); GregorianCalendar c = new GregorianCalendar(); @@ -163,5 +167,7 @@ private XMLGregorianCalendar getDate() { } catch (DatatypeConfigurationException e) { return null; } + } + } diff --git a/src/spring-bceid-starter/src/test/java/ca/bc/gov/open/bceid/starter/account/GetAccountRequestTest.java b/src/spring-bceid-starter/src/test/java/ca/bc/gov/open/bceid/starter/account/GetAccountRequestTest.java index 36ea308..bc176f1 100644 --- a/src/spring-bceid-starter/src/test/java/ca/bc/gov/open/bceid/starter/account/GetAccountRequestTest.java +++ b/src/spring-bceid-starter/src/test/java/ca/bc/gov/open/bceid/starter/account/GetAccountRequestTest.java @@ -15,58 +15,68 @@ public class GetAccountRequestTest { @Test @DisplayName("Test Static BusinessSelfRequest") public void testStaticMethodBusinessSelfRequest() { + GetAccountRequest result = GetAccountRequest.BusinessSelfRequest(ID); Assertions.assertEquals(ID, result.getId()); Assertions.assertEquals(ID, result.getRequesterId()); Assertions.assertEquals(BCeIDAccountTypeCode.BUSINESS, result.getbCeIDAccountTypeCode()); Assertions.assertEquals(BCeIDAccountTypeCode.BUSINESS, result.getRequesterBCeIDAccountTypeCode()); + } @Test @DisplayName("Test Static EdsSelfRequest") public void testStaticMethodEdsSelfRequest() { + GetAccountRequest result = GetAccountRequest.EdsSelfRequest(ID); Assertions.assertEquals(ID, result.getId()); Assertions.assertEquals(ID, result.getRequesterId()); Assertions.assertEquals(BCeIDAccountTypeCode.EDS, result.getbCeIDAccountTypeCode()); Assertions.assertEquals(BCeIDAccountTypeCode.EDS, result.getRequesterBCeIDAccountTypeCode()); + } @Test @DisplayName("Test Static IndividualSelfRequest") public void testStaticMethodIndividualSelfRequest() { + GetAccountRequest result = GetAccountRequest.IndividualSelfRequest(ID); Assertions.assertEquals(ID, result.getId()); Assertions.assertEquals(ID, result.getRequesterId()); Assertions.assertEquals(BCeIDAccountTypeCode.INDIVIDUAL, result.getbCeIDAccountTypeCode()); Assertions.assertEquals(BCeIDAccountTypeCode.INDIVIDUAL, result.getRequesterBCeIDAccountTypeCode()); + } @Test @DisplayName("Test Static InternalSelfRequest") public void testStaticMethodInternalSelfRequest() { + GetAccountRequest result = GetAccountRequest.InternalSelfRequest(ID); Assertions.assertEquals(ID, result.getId()); Assertions.assertEquals(ID, result.getRequesterId()); Assertions.assertEquals(BCeIDAccountTypeCode.INTERNAL, result.getbCeIDAccountTypeCode()); Assertions.assertEquals(BCeIDAccountTypeCode.INTERNAL, result.getRequesterBCeIDAccountTypeCode()); + } @Test @DisplayName("Test Static LdbSelfRequest") public void testStaticMethodLdbSelfRequest() { + GetAccountRequest result = GetAccountRequest.LdbSelfRequest(ID); Assertions.assertEquals(ID, result.getId()); Assertions.assertEquals(ID, result.getRequesterId()); Assertions.assertEquals(BCeIDAccountTypeCode.LDB, result.getbCeIDAccountTypeCode()); Assertions.assertEquals(BCeIDAccountTypeCode.LDB, result.getRequesterBCeIDAccountTypeCode()); + } @Test @@ -83,6 +93,8 @@ public void testStaticMethodVerifiedIndividualSelfRequest() { @Test @DisplayName("Test No Id Exception") public void testException() { + Assertions.assertThrows(IllegalArgumentException.class,() -> GetAccountRequest.IndividualSelfRequest(null)); + } } From 6c85512a40a62a874a265aa29e4bcdee84b200db Mon Sep 17 00:00:00 2001 From: alex Date: Mon, 17 Aug 2020 11:59:37 -0700 Subject: [PATCH 13/22] Add documentation --- src/spring-bceid-starter/README.md | 36 ++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 src/spring-bceid-starter/README.md diff --git a/src/spring-bceid-starter/README.md b/src/spring-bceid-starter/README.md new file mode 100644 index 0000000..58d30ef --- /dev/null +++ b/src/spring-bceid-starter/README.md @@ -0,0 +1,36 @@ +# spring-bceid-starter + +A stater to facilitate usage of bceid service. + +## Configuration + +| name | definition | required | +| --- | --- | --- | +| [bcgov.bceid.service.uri](#cgovbceidserviceuri) | String | Yes | +| [bcgov.bceid.service.username](#bcgovbceidserviceusername) | String | Yes | +| [bcgov.bceid.service.password](#bcgovbceidservicepassword) | String | Yes | +| [bcgov.bceid.service.onlineServiceId](#bcgovbceidserviceonlineServiceId) | String | Yes | + +#### bcgov.bceid.service.uri + +* Value type is String + +Sets the bceid service URI + +#### bcgov.bceid.service.username + +* Value type is String + +Sets the username used to set basic authentication on bceid service + +#### bcgov.bceid.service.password + +* Value type is String + +Sets the password used to set basic authentication on bceid service + +#### bcgov.bceid.service.onlineServiceId + +* Value type is String + +Sets the onlineServiceId From 0d7d055b8ff13f5523bebcbcc5be644dfbea972c Mon Sep 17 00:00:00 2001 From: alex Date: Mon, 17 Aug 2020 12:00:38 -0700 Subject: [PATCH 14/22] version 0.1.2 --- src/pom.xml | 2 +- src/spring-bceid-starter/pom.xml | 4 ++-- src/spring-sftp-starter/pom.xml | 4 ++-- src/spring-starters-bom/pom.xml | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/pom.xml b/src/pom.xml index 19743c4..c492a4b 100644 --- a/src/pom.xml +++ b/src/pom.xml @@ -5,7 +5,7 @@ ca.bc.gov.open spring-starters - 0.1.1 + 0.1.2 diff --git a/src/spring-bceid-starter/pom.xml b/src/spring-bceid-starter/pom.xml index 75a6817..a0f3286 100644 --- a/src/spring-bceid-starter/pom.xml +++ b/src/spring-bceid-starter/pom.xml @@ -6,7 +6,7 @@ ca.bc.gov.open spring-bceid-starter - 0.1.1 + 0.1.2 1.8 @@ -86,7 +86,7 @@ ca.bc.gov.open spring-starters-bom - 0.1.1 + 0.1.2 pom import diff --git a/src/spring-sftp-starter/pom.xml b/src/spring-sftp-starter/pom.xml index cde3cf4..4a2561b 100644 --- a/src/spring-sftp-starter/pom.xml +++ b/src/spring-sftp-starter/pom.xml @@ -7,7 +7,7 @@ ca.bc.gov.open spring-sftp-starter - 0.1.1 + 0.1.2 UTF-8 @@ -70,7 +70,7 @@ ca.bc.gov.open spring-starters-bom - 0.1.1 + 0.1.2 pom import diff --git a/src/spring-starters-bom/pom.xml b/src/spring-starters-bom/pom.xml index 183758d..feada05 100644 --- a/src/spring-starters-bom/pom.xml +++ b/src/spring-starters-bom/pom.xml @@ -7,7 +7,7 @@ ca.bc.gov.open spring-starters-bom - 0.1.1 + 0.1.2 3.3.7 From 97c2a1fa0912209177f870d411fb7d872d5380fb Mon Sep 17 00:00:00 2001 From: alex Date: Mon, 17 Aug 2020 12:01:56 -0700 Subject: [PATCH 15/22] more doc --- src/spring-bceid-starter/README.md | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/spring-bceid-starter/README.md b/src/spring-bceid-starter/README.md index 58d30ef..3614179 100644 --- a/src/spring-bceid-starter/README.md +++ b/src/spring-bceid-starter/README.md @@ -2,6 +2,20 @@ A stater to facilitate usage of bceid service. +## Usage + +Add spring-bceid-starter as a maven dependency + +```xml + + + ca.bc.gov.open + spring-bceid-starter + 0.1.2 + + +``` + ## Configuration | name | definition | required | From d792eb9910e94936fa25cfa43fa7d3e3742b69ed Mon Sep 17 00:00:00 2001 From: alex Date: Mon, 17 Aug 2020 12:04:26 -0700 Subject: [PATCH 16/22] remove unused exception --- .../gov/open/bceid/starter/account/mappers/BCeIdMapper.java | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/spring-bceid-starter/src/main/java/ca/bc/gov/open/bceid/starter/account/mappers/BCeIdMapper.java b/src/spring-bceid-starter/src/main/java/ca/bc/gov/open/bceid/starter/account/mappers/BCeIdMapper.java index d2424cc..7b80af3 100644 --- a/src/spring-bceid-starter/src/main/java/ca/bc/gov/open/bceid/starter/account/mappers/BCeIdMapper.java +++ b/src/spring-bceid-starter/src/main/java/ca/bc/gov/open/bceid/starter/account/mappers/BCeIdMapper.java @@ -5,18 +5,16 @@ import org.joda.time.DateTime; import org.mapstruct.Named; -import javax.xml.datatype.DatatypeConfigurationException; - @Named("BCeIdMapper") public interface BCeIdMapper { @Named("toString") - static String toString(BCeIDString bCeIDString) throws DatatypeConfigurationException { + static String toString(BCeIDString bCeIDString) { return bCeIDString.getValue(); } @Named("toDateTime") - static DateTime toDateTime(BCeIDDateTime bCeIDDateTime) throws DatatypeConfigurationException { + static DateTime toDateTime(BCeIDDateTime bCeIDDateTime) { return new DateTime(bCeIDDateTime.getValue().toGregorianCalendar().getTime()); } From 9b34af3e4f3769b35007ed168ee83cdf1b4f7326 Mon Sep 17 00:00:00 2001 From: alex Date: Mon, 17 Aug 2020 12:07:07 -0700 Subject: [PATCH 17/22] adding new line --- src/spring-bceid-starter/pom.xml | 2 +- src/spring-starters-bom/pom.xml | 6 ++---- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/src/spring-bceid-starter/pom.xml b/src/spring-bceid-starter/pom.xml index a0f3286..bf8f86e 100644 --- a/src/spring-bceid-starter/pom.xml +++ b/src/spring-bceid-starter/pom.xml @@ -145,4 +145,4 @@ - \ No newline at end of file + diff --git a/src/spring-starters-bom/pom.xml b/src/spring-starters-bom/pom.xml index feada05..8e2489e 100644 --- a/src/spring-starters-bom/pom.xml +++ b/src/spring-starters-bom/pom.xml @@ -65,7 +65,5 @@ - - - - \ No newline at end of file + + From 32e54059ba4d7366af7d08300ceaf136f5f455be Mon Sep 17 00:00:00 2001 From: alex Date: Mon, 17 Aug 2020 12:07:33 -0700 Subject: [PATCH 18/22] adding nl --- .../src/main/resources/META-INF/spring.factories | 1 - 1 file changed, 1 deletion(-) diff --git a/src/spring-bceid-starter/src/main/resources/META-INF/spring.factories b/src/spring-bceid-starter/src/main/resources/META-INF/spring.factories index 3b83c3a..17e8183 100644 --- a/src/spring-bceid-starter/src/main/resources/META-INF/spring.factories +++ b/src/spring-bceid-starter/src/main/resources/META-INF/spring.factories @@ -1,3 +1,2 @@ org.springframework.boot.autoconfigure.EnableAutoConfiguration=\ ca.bc.gov.open.bceid.starter.AutoConfiguration - \ No newline at end of file From d6817ac5ebba4f42826d85dcf920a8bdc620a1e9 Mon Sep 17 00:00:00 2001 From: alex Date: Mon, 17 Aug 2020 12:20:54 -0700 Subject: [PATCH 19/22] Adding javadoc --- .../starter/account/GetAccountRequest.java | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/src/spring-bceid-starter/src/main/java/ca/bc/gov/open/bceid/starter/account/GetAccountRequest.java b/src/spring-bceid-starter/src/main/java/ca/bc/gov/open/bceid/starter/account/GetAccountRequest.java index 477658a..ce61a5c 100644 --- a/src/spring-bceid-starter/src/main/java/ca/bc/gov/open/bceid/starter/account/GetAccountRequest.java +++ b/src/spring-bceid-starter/src/main/java/ca/bc/gov/open/bceid/starter/account/GetAccountRequest.java @@ -38,22 +38,47 @@ public static GetAccountRequest BusinessSelfRequest(String id) { return new GetAccountRequest(id, BCeIDAccountTypeCode.BUSINESS); } + /** + * Build a request EDS Federated Accounts + * @param id + * @return + */ public static GetAccountRequest EdsSelfRequest(String id) { return new GetAccountRequest(id, BCeIDAccountTypeCode.EDS); } + /** + * Build a request for individual + * @param id + * @return + */ public static GetAccountRequest IndividualSelfRequest(String id) { return new GetAccountRequest(id, BCeIDAccountTypeCode.INDIVIDUAL); } + /** + * Build a request for internal + * @param id + * @return + */ public static GetAccountRequest InternalSelfRequest(String id) { return new GetAccountRequest(id, BCeIDAccountTypeCode.INTERNAL); } + /** + * Build a request for Liquor Distribution Branch Federated Accounts + * @param id + * @return + */ public static GetAccountRequest LdbSelfRequest(String id) { return new GetAccountRequest(id, BCeIDAccountTypeCode.LDB); } + /** + * Build a request for Verified Individual. + * @param id + * @return + */ public static GetAccountRequest VerifiedIndividualSelfRequest(String id) { return new GetAccountRequest(id, BCeIDAccountTypeCode.VERIFIED_INDIVIDUAL); } From 5729f24a3b4999447ea510b7f3b4d1c20804f0a6 Mon Sep 17 00:00:00 2001 From: alexjoybc <51387119+alexjoybc@users.noreply.github.com> Date: Mon, 17 Aug 2020 12:22:32 -0700 Subject: [PATCH 20/22] Update src/spring-bceid-starter/README.md --- src/spring-bceid-starter/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/spring-bceid-starter/README.md b/src/spring-bceid-starter/README.md index 3614179..9c37cdc 100644 --- a/src/spring-bceid-starter/README.md +++ b/src/spring-bceid-starter/README.md @@ -29,7 +29,7 @@ Add spring-bceid-starter as a maven dependency * Value type is String -Sets the bceid service URI +Sets the BCeID service URI #### bcgov.bceid.service.username From c66f550cf4d5b8ff857a8a8fb9aecddfbf7d8b91 Mon Sep 17 00:00:00 2001 From: alexjoybc <51387119+alexjoybc@users.noreply.github.com> Date: Mon, 17 Aug 2020 12:22:39 -0700 Subject: [PATCH 21/22] Update src/spring-bceid-starter/README.md --- src/spring-bceid-starter/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/spring-bceid-starter/README.md b/src/spring-bceid-starter/README.md index 9c37cdc..578fc37 100644 --- a/src/spring-bceid-starter/README.md +++ b/src/spring-bceid-starter/README.md @@ -41,7 +41,7 @@ Sets the username used to set basic authentication on bceid service * Value type is String -Sets the password used to set basic authentication on bceid service +Sets the password used to set basic authentication on the BCeID service #### bcgov.bceid.service.onlineServiceId From 4b82ebc323813a8c0b80ae2d92d5e8cb778ed5fa Mon Sep 17 00:00:00 2001 From: alexjoybc <51387119+alexjoybc@users.noreply.github.com> Date: Mon, 17 Aug 2020 12:22:48 -0700 Subject: [PATCH 22/22] Update src/spring-bceid-starter/README.md --- src/spring-bceid-starter/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/spring-bceid-starter/README.md b/src/spring-bceid-starter/README.md index 578fc37..10344c6 100644 --- a/src/spring-bceid-starter/README.md +++ b/src/spring-bceid-starter/README.md @@ -35,7 +35,7 @@ Sets the BCeID service URI * Value type is String -Sets the username used to set basic authentication on bceid service +Sets the username used to set basic authentication on the BCeID service #### bcgov.bceid.service.password