diff --git a/.github/workflows/maven-pr-builder.yml b/.github/workflows/maven-pr-builder.yml index 8bdd067da..0edf916ae 100644 --- a/.github/workflows/maven-pr-builder.yml +++ b/.github/workflows/maven-pr-builder.yml @@ -61,7 +61,7 @@ jobs: run: sudo apt-get install -y xvfb - name: Build with Maven and run SonarQube analysis - run: xvfb-run ./mvnw clean -Dsonar.host.url=https://sonarcloud.io -Dsonar.organization=iluwatar -Dsonar.projectKey=iluwatar_java-design-patterns -Dsonar.pullrequest.branch=${{ github.head_ref }} -Dsonar.pullrequest.base=${{ github.base_ref }} -Dsonar.pullrequest.key=${{ github.event.pull_request.number }} + run: xvfb-run ./mvnw clean verify -Dsonar.host.url=https://sonarcloud.io -Dsonar.organization=iluwatar -Dsonar.projectKey=iluwatar_java-design-patterns -Dsonar.pullrequest.branch=${{ github.head_ref }} -Dsonar.pullrequest.base=${{ github.base_ref }} -Dsonar.pullrequest.key=${{ github.event.pull_request.number }} env: # These two env variables are needed for sonar analysis GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/client-session/etc/client-session.urm.puml b/client-session/etc/client-session.urm.puml new file mode 100644 index 000000000..eea5ce8a9 --- /dev/null +++ b/client-session/etc/client-session.urm.puml @@ -0,0 +1,51 @@ +@startuml +package com.iluwatar.client.session { + class App { + + App() + + main(args : String[]) {static} + } + class Request { + - data : String + - session : Session + + Request(data : String, session : Session) + # canEqual(other : Object) : boolean + + equals(o : Object) : boolean + + getData() : String + + getSession() : Session + + hashCode() : int + + setData(data : String) + + setSession(session : Session) + + toString() : String + } + class Server { + - LOGGER : Logger {static} + - host : String + - port : int + + Server(host : String, port : int) + # canEqual(other : Object) : boolean + + equals(o : Object) : boolean + + getHost() : String + + getPort() : int + + getSession(name : String) : Session + + hashCode() : int + + process(request : Request) + + setHost(host : String) + + setPort(port : int) + + toString() : String + } + class Session { + - clientName : String + - id : String + + Session(id : String, clientName : String) + # canEqual(other : Object) : boolean + + equals(o : Object) : boolean + + getClientName() : String + + getId() : String + + hashCode() : int + + setClientName(clientName : String) + + setId(id : String) + + toString() : String + } +} +Request --> "-session" Session +@enduml \ No newline at end of file diff --git a/context-object/README.md b/context-object/README.md index 0c4462aa6..15848371b 100644 --- a/context-object/README.md +++ b/context-object/README.md @@ -179,6 +179,7 @@ Use the Context Object pattern for: ## Credits -* [J2EE Design Patterns](http://corej2eepatterns.com/ContextObject.htm) +* [Core J2EE Design Patterns](https://amzn.to/3IhcY9w) +* [Core J2EE Design Patterns website - Context Object](http://corej2eepatterns.com/ContextObject.htm) * [Allan Kelly - The Encapsulate Context Pattern](https://accu.org/journals/overload/12/63/kelly_246/) -* [Arvid S. Krishna et al. - Context Object](https://www.dre.vanderbilt.edu/~schmidt/PDF/Context-Object-Pattern.pdf) \ No newline at end of file +* [Arvid S. Krishna et al. - Context Object](https://www.dre.vanderbilt.edu/~schmidt/PDF/Context-Object-Pattern.pdf) diff --git a/context-object/src/main/java/com/iluwatar/context/object/App.java b/context-object/src/main/java/com/iluwatar/context/object/App.java index c76ddd93b..4041a5273 100644 --- a/context-object/src/main/java/com/iluwatar/context/object/App.java +++ b/context-object/src/main/java/com/iluwatar/context/object/App.java @@ -13,29 +13,30 @@ import lombok.extern.slf4j.Slf4j; @Slf4j public class App { - private static final String SERVICE = "SERVICE"; + private static final String SERVICE = "SERVICE"; - /** - * Program entry point. - * @param args command line args - */ - public static void main(String[] args) { - //Initiate first layer and add service information into context - var layerA = new LayerA(); - layerA.addAccountInfo(SERVICE); + /** + * Program entry point. + * + * @param args command line args + */ + public static void main(String[] args) { + //Initiate first layer and add service information into context + var layerA = new LayerA(); + layerA.addAccountInfo(SERVICE); - LOGGER.info("Context = {}",layerA.getContext()); + LOGGER.info("Context = {}", layerA.getContext()); - //Initiate second layer and preserving information retrieved in first layer through passing context object - var layerB = new LayerB(layerA); - layerB.addSessionInfo(SERVICE); + //Initiate second layer and preserving information retrieved in first layer through passing context object + var layerB = new LayerB(layerA); + layerB.addSessionInfo(SERVICE); - LOGGER.info("Context = {}",layerB.getContext()); + LOGGER.info("Context = {}", layerB.getContext()); - //Initiate third layer and preserving information retrieved in first and second layer through passing context object - var layerC = new LayerC(layerB); - layerC.addSearchInfo(SERVICE); + //Initiate third layer and preserving information retrieved in first and second layer through passing context object + var layerC = new LayerC(layerB); + layerC.addSearchInfo(SERVICE); - LOGGER.info("Context = {}",layerC.getContext()); - } + LOGGER.info("Context = {}", layerC.getContext()); + } } diff --git a/context-object/src/main/java/com/iluwatar/context/object/LayerA.java b/context-object/src/main/java/com/iluwatar/context/object/LayerA.java index f7a634448..3b471e8a6 100644 --- a/context-object/src/main/java/com/iluwatar/context/object/LayerA.java +++ b/context-object/src/main/java/com/iluwatar/context/object/LayerA.java @@ -5,13 +5,13 @@ import lombok.Getter; @Getter public class LayerA { - private ServiceContext context; + private ServiceContext context; - public LayerA() { - context = ServiceContextFactory.createContext(); - } + public LayerA() { + context = ServiceContextFactory.createContext(); + } - public void addAccountInfo(String accountService) { - context.setAccountService(accountService); - } + public void addAccountInfo(String accountService) { + context.setAccountService(accountService); + } } diff --git a/context-object/src/main/java/com/iluwatar/context/object/LayerB.java b/context-object/src/main/java/com/iluwatar/context/object/LayerB.java index 8e4bd9c0f..4c7daab1c 100644 --- a/context-object/src/main/java/com/iluwatar/context/object/LayerB.java +++ b/context-object/src/main/java/com/iluwatar/context/object/LayerB.java @@ -5,13 +5,13 @@ import lombok.Getter; @Getter public class LayerB { - private ServiceContext context; + private ServiceContext context; - public LayerB(LayerA layerA) { - this.context = layerA.getContext(); - } + public LayerB(LayerA layerA) { + this.context = layerA.getContext(); + } - public void addSessionInfo(String sessionService) { - context.setSessionService(sessionService); - } + public void addSessionInfo(String sessionService) { + context.setSessionService(sessionService); + } } diff --git a/context-object/src/main/java/com/iluwatar/context/object/LayerC.java b/context-object/src/main/java/com/iluwatar/context/object/LayerC.java index b6a23b539..f1a2ba035 100644 --- a/context-object/src/main/java/com/iluwatar/context/object/LayerC.java +++ b/context-object/src/main/java/com/iluwatar/context/object/LayerC.java @@ -5,13 +5,13 @@ import lombok.Getter; @Getter public class LayerC { - public ServiceContext context; + public ServiceContext context; - public LayerC(LayerB layerB) { - this.context = layerB.getContext(); - } + public LayerC(LayerB layerB) { + this.context = layerB.getContext(); + } - public void addSearchInfo(String searchService) { - context.setSearchService(searchService); - } + public void addSearchInfo(String searchService) { + context.setSearchService(searchService); + } } diff --git a/context-object/src/main/java/com/iluwatar/context/object/ServiceContext.java b/context-object/src/main/java/com/iluwatar/context/object/ServiceContext.java index 9f334d374..d8e78dd25 100644 --- a/context-object/src/main/java/com/iluwatar/context/object/ServiceContext.java +++ b/context-object/src/main/java/com/iluwatar/context/object/ServiceContext.java @@ -12,5 +12,7 @@ import lombok.ToString; @Setter public class ServiceContext { - String AccountService, SessionService, SearchService; + String accountService; + String sessionService; + String searchService; } diff --git a/context-object/src/main/java/com/iluwatar/context/object/ServiceContextFactory.java b/context-object/src/main/java/com/iluwatar/context/object/ServiceContextFactory.java index d3fe442df..f315ea247 100644 --- a/context-object/src/main/java/com/iluwatar/context/object/ServiceContextFactory.java +++ b/context-object/src/main/java/com/iluwatar/context/object/ServiceContextFactory.java @@ -5,7 +5,7 @@ package com.iluwatar.context.object; */ public class ServiceContextFactory { - public static ServiceContext createContext() { - return new ServiceContext(); - } + public static ServiceContext createContext() { + return new ServiceContext(); + } } diff --git a/context-object/src/test/java/com/iluwatar/contect/object/AppTest.java b/context-object/src/test/java/com/iluwatar/contect/object/AppTest.java index d65cb440d..44adacaff 100644 --- a/context-object/src/test/java/com/iluwatar/contect/object/AppTest.java +++ b/context-object/src/test/java/com/iluwatar/contect/object/AppTest.java @@ -7,11 +7,11 @@ import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; public class AppTest { - /** - * Test example app runs without error. - */ - @Test - void shouldExecuteWithoutException() { - assertDoesNotThrow(() -> App.main(new String[]{})); - } + /** + * Test example app runs without error. + */ + @Test + void shouldExecuteWithoutException() { + assertDoesNotThrow(() -> App.main(new String[] {})); + } } diff --git a/context-object/src/test/java/com/iluwatar/contect/object/ServiceContextTest.java b/context-object/src/test/java/com/iluwatar/contect/object/ServiceContextTest.java index 48d9ce76b..3086c45b9 100644 --- a/context-object/src/test/java/com/iluwatar/contect/object/ServiceContextTest.java +++ b/context-object/src/test/java/com/iluwatar/contect/object/ServiceContextTest.java @@ -18,49 +18,52 @@ import static org.junit.jupiter.api.Assertions.assertNull; */ public class ServiceContextTest { - private static final String SERVICE = "SERVICE"; + private static final String SERVICE = "SERVICE"; - private LayerA layerA; + private LayerA layerA; - @BeforeEach - void initiateLayerA() { - this.layerA = new LayerA(); - } + @BeforeEach + void initiateLayerA() { + this.layerA = new LayerA(); + } - @Test - void testSameContextPassedBetweenLayers() { - ServiceContext context1 = layerA.getContext(); - var layerB = new LayerB(layerA); - ServiceContext context2 = layerB.getContext(); - var layerC = new LayerC(layerB); - ServiceContext context3 = layerC.getContext(); + @Test + void testSameContextPassedBetweenLayers() { + ServiceContext context1 = layerA.getContext(); + var layerB = new LayerB(layerA); + ServiceContext context2 = layerB.getContext(); + var layerC = new LayerC(layerB); + ServiceContext context3 = layerC.getContext(); - assertSame(context1, context2); - assertSame(context2, context3); - assertSame(context3, context1); - } + assertSame(context1, context2); + assertSame(context2, context3); + assertSame(context3, context1); + } - @Test - void testScopedDataPassedBetweenLayers() { - layerA.addAccountInfo(SERVICE); - var layerB = new LayerB(layerA); - var layerC = new LayerC(layerB); - layerC.addSearchInfo(SERVICE); - ServiceContext context = layerC.getContext(); + @Test + void testScopedDataPassedBetweenLayers() { + layerA.addAccountInfo(SERVICE); + var layerB = new LayerB(layerA); + var layerC = new LayerC(layerB); + layerC.addSearchInfo(SERVICE); + ServiceContext context = layerC.getContext(); - assertEquals(SERVICE,context.getAccountService()); - assertNull(context.getSessionService()); - assertEquals(SERVICE,context.getSearchService()); - } + assertEquals(SERVICE, context.getAccountService()); + assertNull(context.getSessionService()); + assertEquals(SERVICE, context.getSearchService()); + } - @Test - void testToString() { - assertEquals(layerA.getContext().toString(),"ServiceContext(AccountService=null, SessionService=null, SearchService=null)"); - layerA.addAccountInfo(SERVICE); - assertEquals(layerA.getContext().toString(), "ServiceContext(AccountService=SERVICE, SessionService=null, SearchService=null)"); - var layerB = new LayerB(layerA); - layerB.addSessionInfo(SERVICE); - var layerC = new LayerC(layerB); - assertEquals(layerC.getContext().toString(), "ServiceContext(AccountService=SERVICE, SessionService=SERVICE, SearchService=null)"); - } + @Test + void testToString() { + assertEquals(layerA.getContext().toString(), + "ServiceContext(AccountService=null, SessionService=null, SearchService=null)"); + layerA.addAccountInfo(SERVICE); + assertEquals(layerA.getContext().toString(), + "ServiceContext(AccountService=SERVICE, SessionService=null, SearchService=null)"); + var layerB = new LayerB(layerA); + layerB.addSessionInfo(SERVICE); + var layerC = new LayerC(layerB); + assertEquals(layerC.getContext().toString(), + "ServiceContext(AccountService=SERVICE, SessionService=SERVICE, SearchService=null)"); + } } diff --git a/page-controller/src/main/resources/application.properties b/page-controller/src/main/resources/application.properties index 59cc8812c..013167d1f 100644 --- a/page-controller/src/main/resources/application.properties +++ b/page-controller/src/main/resources/application.properties @@ -1,6 +1,8 @@ # +# This project is licensed under the MIT license. Module model-view-viewmodel is using ZK framework licensed under LGPL (see lgpl-3.0.txt). +# # The MIT License -# Copyright © 2014-2021 Ilkka Seppälä +# Copyright © 2014-2022 Ilkka Seppälä # # Permission is hereby granted, free of charge, to any person obtaining a copy # of this software and associated documentation files (the "Software"), to deal @@ -20,6 +22,5 @@ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN # THE SOFTWARE. # -#spring.thymeleaf.mode=HTML server.port=51515 diff --git a/page-controller/src/main/resources/templates/signup.html b/page-controller/src/main/resources/templates/signup.html index 56c5487fe..3aa6209c4 100644 --- a/page-controller/src/main/resources/templates/signup.html +++ b/page-controller/src/main/resources/templates/signup.html @@ -1,3 +1,29 @@ +
diff --git a/page-controller/src/main/resources/templates/user.html b/page-controller/src/main/resources/templates/user.html index 70130cef6..493912fe7 100644 --- a/page-controller/src/main/resources/templates/user.html +++ b/page-controller/src/main/resources/templates/user.html @@ -1,3 +1,29 @@ + diff --git a/page-controller/src/test/java/com/iluwatar/page/controller/UserControllerTest.java b/page-controller/src/test/java/com/iluwatar/page/controller/UserControllerTest.java index d20d5e036..7fd1c0cd1 100644 --- a/page-controller/src/test/java/com/iluwatar/page/controller/UserControllerTest.java +++ b/page-controller/src/test/java/com/iluwatar/page/controller/UserControllerTest.java @@ -1,3 +1,27 @@ +/* + * This project is licensed under the MIT license. Module model-view-viewmodel is using ZK framework licensed under LGPL (see lgpl-3.0.txt). + * + * The MIT License + * Copyright © 2014-2022 Ilkka Seppälä + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ package com.iluwatar.page.controller; import org.junit.jupiter.api.Test; diff --git a/page-controller/src/test/java/com/iluwatar/page/controller/UserModelTest.java b/page-controller/src/test/java/com/iluwatar/page/controller/UserModelTest.java index 42e8e0c30..49e1102c8 100644 --- a/page-controller/src/test/java/com/iluwatar/page/controller/UserModelTest.java +++ b/page-controller/src/test/java/com/iluwatar/page/controller/UserModelTest.java @@ -1,3 +1,27 @@ +/* + * This project is licensed under the MIT license. Module model-view-viewmodel is using ZK framework licensed under LGPL (see lgpl-3.0.txt). + * + * The MIT License + * Copyright © 2014-2022 Ilkka Seppälä + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ package com.iluwatar.page.controller; import static org.junit.jupiter.api.Assertions.assertEquals; diff --git a/pom.xml b/pom.xml index 90c4b2941..25a212327 100644 --- a/pom.xml +++ b/pom.xml @@ -204,6 +204,7 @@