├── .gitignore
├── LICENSE
├── README.md
├── pom.xml
└── src
├── main
├── java
│ └── com
│ │ └── github
│ │ └── andbed
│ │ └── cleanarch
│ │ ├── chargingproduct
│ │ ├── core
│ │ │ └── GetChargingProducts.java
│ │ └── delivery
│ │ │ └── rest
│ │ │ └── ChargingProductController.java
│ │ ├── eventtype
│ │ ├── core
│ │ │ ├── GetAllEventTypes.java
│ │ │ ├── ImportEventTypes.java
│ │ │ ├── boundary
│ │ │ │ ├── MessageCode.java
│ │ │ │ ├── provide
│ │ │ │ │ ├── Command.java
│ │ │ │ │ ├── DataStoreException.java
│ │ │ │ │ ├── EventTypeFactory.java
│ │ │ │ │ ├── EventTypeFullResponseModel.java
│ │ │ │ │ ├── EventTypeRequestModel.java
│ │ │ │ │ ├── EventTypeShortResponseModel.java
│ │ │ │ │ ├── EventTypesListPresenter.java
│ │ │ │ │ ├── ImportPresenter.java
│ │ │ │ │ └── PageRequest.java
│ │ │ │ └── require
│ │ │ │ │ ├── EventTypesFileProvider.java
│ │ │ │ │ ├── EventTypesFinder.java
│ │ │ │ │ ├── EventTypesPersister.java
│ │ │ │ │ ├── Notifier.java
│ │ │ │ │ └── XMLParser.java
│ │ │ └── entity
│ │ │ │ ├── EventAttribute.java
│ │ │ │ └── EventType.java
│ │ ├── delivery
│ │ │ ├── rest
│ │ │ │ ├── EventTypesController.java
│ │ │ │ └── ImportEventTypesController.java
│ │ │ └── ws
│ │ │ │ └── EventTypesWSController.java
│ │ └── infrastructure
│ │ │ ├── di
│ │ │ └── SpringDIFactory.java
│ │ │ ├── io
│ │ │ ├── EventTypeFileManager.java
│ │ │ └── XMLParserSAX.java
│ │ │ ├── notification
│ │ │ └── email
│ │ │ │ └── EmailSender.java
│ │ │ └── repository
│ │ │ ├── db
│ │ │ └── jpa
│ │ │ │ ├── EventTypeJPA.java
│ │ │ │ └── EventTypeRepository.java
│ │ │ └── rest
│ │ │ ├── EventTypeFromRest.java
│ │ │ └── EventTypeRestRepo.java
│ │ ├── rate
│ │ ├── core
│ │ │ ├── DisableRateFromCurrentOffer.java
│ │ │ └── GetRates.java
│ │ └── delivery
│ │ │ └── rest
│ │ │ └── RateController.java
│ │ └── tariffplan
│ │ ├── core
│ │ └── ActivateTariffPlan.java
│ │ └── delivery
│ │ └── rest
│ │ └── TariffPlanRESTAPI.java
└── resources
│ └── application.properties
└── test
├── java
└── com
│ └── github
│ └── andbed
│ └── cleanarch
│ ├── eventtype
│ ├── core
│ │ └── GetAllEventTypesTest.java
│ └── delivery
│ │ └── rest
│ │ └── EventTypesControllerIntegrationTest.java
│ └── learningtest
│ ├── java8
│ ├── Example.java
│ ├── Example1.java
│ └── ExamplesForPresentation.java
│ └── tdd
│ └── FilteredSortedListTest.java
└── resources
└── test.properties
/.gitignore:
--------------------------------------------------------------------------------
1 | *.class
2 |
3 | # Mobile Tools for Java (J2ME)
4 | .mtj.tmp/
5 |
6 | # Package Files #
7 | *.jar
8 | *.war
9 | *.ear
10 |
11 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
12 | hs_err_pid*
13 | /target
14 | /.classpath
15 | /.project
16 | /.settings
17 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Apache License
2 | Version 2.0, January 2004
3 | http://www.apache.org/licenses/
4 |
5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6 |
7 | 1. Definitions.
8 |
9 | "License" shall mean the terms and conditions for use, reproduction,
10 | and distribution as defined by Sections 1 through 9 of this document.
11 |
12 | "Licensor" shall mean the copyright owner or entity authorized by
13 | the copyright owner that is granting the License.
14 |
15 | "Legal Entity" shall mean the union of the acting entity and all
16 | other entities that control, are controlled by, or are under common
17 | control with that entity. For the purposes of this definition,
18 | "control" means (i) the power, direct or indirect, to cause the
19 | direction or management of such entity, whether by contract or
20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the
21 | outstanding shares, or (iii) beneficial ownership of such entity.
22 |
23 | "You" (or "Your") shall mean an individual or Legal Entity
24 | exercising permissions granted by this License.
25 |
26 | "Source" form shall mean the preferred form for making modifications,
27 | including but not limited to software source code, documentation
28 | source, and configuration files.
29 |
30 | "Object" form shall mean any form resulting from mechanical
31 | transformation or translation of a Source form, including but
32 | not limited to compiled object code, generated documentation,
33 | and conversions to other media types.
34 |
35 | "Work" shall mean the work of authorship, whether in Source or
36 | Object form, made available under the License, as indicated by a
37 | copyright notice that is included in or attached to the work
38 | (an example is provided in the Appendix below).
39 |
40 | "Derivative Works" shall mean any work, whether in Source or Object
41 | form, that is based on (or derived from) the Work and for which the
42 | editorial revisions, annotations, elaborations, or other modifications
43 | represent, as a whole, an original work of authorship. For the purposes
44 | of this License, Derivative Works shall not include works that remain
45 | separable from, or merely link (or bind by name) to the interfaces of,
46 | the Work and Derivative Works thereof.
47 |
48 | "Contribution" shall mean any work of authorship, including
49 | the original version of the Work and any modifications or additions
50 | to that Work or Derivative Works thereof, that is intentionally
51 | submitted to Licensor for inclusion in the Work by the copyright owner
52 | or by an individual or Legal Entity authorized to submit on behalf of
53 | the copyright owner. For the purposes of this definition, "submitted"
54 | means any form of electronic, verbal, or written communication sent
55 | to the Licensor or its representatives, including but not limited to
56 | communication on electronic mailing lists, source code control systems,
57 | and issue tracking systems that are managed by, or on behalf of, the
58 | Licensor for the purpose of discussing and improving the Work, but
59 | excluding communication that is conspicuously marked or otherwise
60 | designated in writing by the copyright owner as "Not a Contribution."
61 |
62 | "Contributor" shall mean Licensor and any individual or Legal Entity
63 | on behalf of whom a Contribution has been received by Licensor and
64 | subsequently incorporated within the Work.
65 |
66 | 2. Grant of Copyright License. Subject to the terms and conditions of
67 | this License, each Contributor hereby grants to You a perpetual,
68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69 | copyright license to reproduce, prepare Derivative Works of,
70 | publicly display, publicly perform, sublicense, and distribute the
71 | Work and such Derivative Works in Source or Object form.
72 |
73 | 3. Grant of Patent License. Subject to the terms and conditions of
74 | this License, each Contributor hereby grants to You a perpetual,
75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76 | (except as stated in this section) patent license to make, have made,
77 | use, offer to sell, sell, import, and otherwise transfer the Work,
78 | where such license applies only to those patent claims licensable
79 | by such Contributor that are necessarily infringed by their
80 | Contribution(s) alone or by combination of their Contribution(s)
81 | with the Work to which such Contribution(s) was submitted. If You
82 | institute patent litigation against any entity (including a
83 | cross-claim or counterclaim in a lawsuit) alleging that the Work
84 | or a Contribution incorporated within the Work constitutes direct
85 | or contributory patent infringement, then any patent licenses
86 | granted to You under this License for that Work shall terminate
87 | as of the date such litigation is filed.
88 |
89 | 4. Redistribution. You may reproduce and distribute copies of the
90 | Work or Derivative Works thereof in any medium, with or without
91 | modifications, and in Source or Object form, provided that You
92 | meet the following conditions:
93 |
94 | (a) You must give any other recipients of the Work or
95 | Derivative Works a copy of this License; and
96 |
97 | (b) You must cause any modified files to carry prominent notices
98 | stating that You changed the files; and
99 |
100 | (c) You must retain, in the Source form of any Derivative Works
101 | that You distribute, all copyright, patent, trademark, and
102 | attribution notices from the Source form of the Work,
103 | excluding those notices that do not pertain to any part of
104 | the Derivative Works; and
105 |
106 | (d) If the Work includes a "NOTICE" text file as part of its
107 | distribution, then any Derivative Works that You distribute must
108 | include a readable copy of the attribution notices contained
109 | within such NOTICE file, excluding those notices that do not
110 | pertain to any part of the Derivative Works, in at least one
111 | of the following places: within a NOTICE text file distributed
112 | as part of the Derivative Works; within the Source form or
113 | documentation, if provided along with the Derivative Works; or,
114 | within a display generated by the Derivative Works, if and
115 | wherever such third-party notices normally appear. The contents
116 | of the NOTICE file are for informational purposes only and
117 | do not modify the License. You may add Your own attribution
118 | notices within Derivative Works that You distribute, alongside
119 | or as an addendum to the NOTICE text from the Work, provided
120 | that such additional attribution notices cannot be construed
121 | as modifying the License.
122 |
123 | You may add Your own copyright statement to Your modifications and
124 | may provide additional or different license terms and conditions
125 | for use, reproduction, or distribution of Your modifications, or
126 | for any such Derivative Works as a whole, provided Your use,
127 | reproduction, and distribution of the Work otherwise complies with
128 | the conditions stated in this License.
129 |
130 | 5. Submission of Contributions. Unless You explicitly state otherwise,
131 | any Contribution intentionally submitted for inclusion in the Work
132 | by You to the Licensor shall be under the terms and conditions of
133 | this License, without any additional terms or conditions.
134 | Notwithstanding the above, nothing herein shall supersede or modify
135 | the terms of any separate license agreement you may have executed
136 | with Licensor regarding such Contributions.
137 |
138 | 6. Trademarks. This License does not grant permission to use the trade
139 | names, trademarks, service marks, or product names of the Licensor,
140 | except as required for reasonable and customary use in describing the
141 | origin of the Work and reproducing the content of the NOTICE file.
142 |
143 | 7. Disclaimer of Warranty. Unless required by applicable law or
144 | agreed to in writing, Licensor provides the Work (and each
145 | Contributor provides its Contributions) on an "AS IS" BASIS,
146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147 | implied, including, without limitation, any warranties or conditions
148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149 | PARTICULAR PURPOSE. You are solely responsible for determining the
150 | appropriateness of using or redistributing the Work and assume any
151 | risks associated with Your exercise of permissions under this License.
152 |
153 | 8. Limitation of Liability. In no event and under no legal theory,
154 | whether in tort (including negligence), contract, or otherwise,
155 | unless required by applicable law (such as deliberate and grossly
156 | negligent acts) or agreed to in writing, shall any Contributor be
157 | liable to You for damages, including any direct, indirect, special,
158 | incidental, or consequential damages of any character arising as a
159 | result of this License or out of the use or inability to use the
160 | Work (including but not limited to damages for loss of goodwill,
161 | work stoppage, computer failure or malfunction, or any and all
162 | other commercial damages or losses), even if such Contributor
163 | has been advised of the possibility of such damages.
164 |
165 | 9. Accepting Warranty or Additional Liability. While redistributing
166 | the Work or Derivative Works thereof, You may choose to offer,
167 | and charge a fee for, acceptance of support, warranty, indemnity,
168 | or other liability obligations and/or rights consistent with this
169 | License. However, in accepting such obligations, You may act only
170 | on Your own behalf and on Your sole responsibility, not on behalf
171 | of any other Contributor, and only if You agree to indemnify,
172 | defend, and hold each Contributor harmless for any liability
173 | incurred by, or claims asserted against, such Contributor by reason
174 | of your accepting any such warranty or additional liability.
175 |
176 | END OF TERMS AND CONDITIONS
177 |
178 | APPENDIX: How to apply the Apache License to your work.
179 |
180 | To apply the Apache License to your work, attach the following
181 | boilerplate notice, with the fields enclosed by brackets "{}"
182 | replaced with your own identifying information. (Don't include
183 | the brackets!) The text should be enclosed in the appropriate
184 | comment syntax for the file format. We also recommend that a
185 | file or class name and description of purpose be included on the
186 | same "printed page" as the copyright notice for easier
187 | identification within third-party archives.
188 |
189 | Copyright {yyyy} {name of copyright owner}
190 |
191 | Licensed under the Apache License, Version 2.0 (the "License");
192 | you may not use this file except in compliance with the License.
193 | You may obtain a copy of the License at
194 |
195 | http://www.apache.org/licenses/LICENSE-2.0
196 |
197 | Unless required by applicable law or agreed to in writing, software
198 | distributed under the License is distributed on an "AS IS" BASIS,
199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200 | See the License for the specific language governing permissions and
201 | limitations under the License.
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | Clean-architecture
2 | ==================
3 |
4 | An example of applying "The Clean Architecture" principles as defined by Uncle Bob:
5 | http://blog.8thlight.com/uncle-bob/2012/08/13/the-clean-architecture.html
6 |
7 | This is only to illustrate key concepts.
8 |
9 | Version 1.1
10 |
11 | Next TODOs:
12 | * Add HSQLDB
13 | * Finish configuring app as a working REST service (Spring based)
14 | * Add security
15 | * Add validation
16 | * Add another delivery mechanism
17 | * Implement some real functionality for a couple of use cases
18 |
19 | Changelog:
20 | * version 1.0 - prepared for Confitura 2014, contained only basic project structure
21 | * version 1.1 - added stand-alone controller tests and Spring DI support
22 |
23 |
--------------------------------------------------------------------------------
/pom.xml:
--------------------------------------------------------------------------------
1 |
3 | 4.0.0
4 | com.github.andbed.cleanarch
5 | cleanarch
6 | 2.0.1-SNAPSHOT
7 | war
8 |
9 |
10 | 1.8
11 | 4.1.4.RELEASE
12 | 3.2.2.RELEASE
13 | 2.1.4
14 | 1.12.6
15 | 1.7.7
16 | 1.1.2
17 |
18 | UTF-8
19 |
20 | 4.12
21 |
22 |
23 |
24 |
25 | org.springframework
26 | spring-context
27 | ${spring.version}
28 |
29 |
30 |
31 | org.springframework.hateoas
32 | spring-hateoas
33 | 0.9.0.RELEASE
34 |
35 |
36 |
37 | org.springframework
38 | spring-webmvc
39 | ${spring.version}
40 |
41 |
42 | commons-logging
43 | commons-logging
44 |
45 |
46 |
47 |
48 |
49 | org.springframework
50 | spring-web
51 | ${spring.version}
52 |
53 |
54 | commons-logging
55 | commons-logging
56 |
57 |
58 |
59 |
60 |
61 | org.springframework
62 | spring-core
63 | ${spring.version}
64 |
65 |
66 | commons-logging
67 | commons-logging
68 |
69 |
70 |
71 |
72 |
73 | org.springframework.plugin
74 | spring-plugin-core
75 | 1.0.0.RELEASE
76 |
77 |
78 |
79 | org.springframework
80 | spring-oxm
81 | ${spring.version}
82 |
83 |
84 |
85 | org.springframework
86 | spring-aop
87 | ${spring.version}
88 |
89 |
90 |
91 | org.aspectj
92 | aspectjweaver
93 | 1.7.2
94 | runtime
95 |
96 |
97 |
98 | org.springframework
99 | spring-orm
100 | ${spring.version}
101 |
102 |
103 |
104 | org.springframework
105 | spring-jdbc
106 | ${spring.version}
107 |
108 |
109 |
110 | org.springframework.data
111 | spring-data-jpa
112 | 1.7.1.RELEASE
113 |
114 |
115 |
116 |
117 | org.hibernate
118 | hibernate-core
119 | 4.3.7.Final
120 |
121 |
122 | org.hibernate
123 | hibernate-entitymanager
124 | 4.3.7.Final
125 |
126 |
127 | javax.validation
128 | validation-api
129 | 1.1.0.Final
130 |
131 |
132 | org.hibernate
133 | hibernate-validator
134 | 5.1.0.Final
135 |
136 |
137 | javax.el
138 | javax.el-api
139 | 2.2.4
140 |
141 |
142 |
143 |
144 | org.hsqldb
145 | hsqldb
146 | 2.3.2
147 | runtime
148 |
149 |
150 |
151 | com.fasterxml.jackson.core
152 | jackson-databind
153 | ${jackson.version}
154 |
155 |
156 |
157 | javax.servlet
158 | javax.servlet-api
159 | 3.0.1
160 | provided
161 |
162 |
163 |
164 | org.projectlombok
165 | lombok
166 | ${lombok.version}
167 | provided
168 |
169 |
170 |
171 |
172 | com.google.guava
173 | guava
174 | 18.0
175 |
176 |
177 | joda-time
178 | joda-time
179 | 2.2
180 |
181 |
182 |
183 |
184 |
185 | org.slf4j
186 | jcl-over-slf4j
187 | ${slf4j.version}
188 | runtime
189 |
190 |
191 |
192 | ch.qos.logback
193 | logback-classic
194 | ${logback.version}
195 | runtime
196 |
197 |
198 |
199 | org.springframework
200 | spring-test
201 | ${spring.version}
202 | test
203 |
204 |
205 |
206 | junit
207 | junit
208 | ${junit.version}
209 | test
210 |
211 |
212 |
213 |
214 | org.mockito
215 | mockito-all
216 | 1.9.5
217 | test
218 |
219 |
220 |
221 | org.assertj
222 | assertj-core
223 | 1.3.0
224 | test
225 |
226 |
227 |
228 | javax.inject
229 | javax.inject
230 | 1
231 |
232 |
233 |
234 | com.jayway.jsonpath
235 | json-path
236 | 0.8.1
237 |
238 |
239 |
240 |
241 |
242 |
243 |
244 |
245 | org.apache.maven.plugins
246 | maven-compiler-plugin
247 | 2.5.1
248 |
249 |
250 | compile
251 | compile
252 |
253 | compile
254 |
255 |
256 |
257 | unit-test-compile
258 |
259 | testCompile
260 |
261 |
262 |
263 |
264 | ${jdkLevel}
265 | ${jdkLevel}
266 |
267 |
268 |
269 | org.apache.maven.plugins
270 | maven-war-plugin
271 |
272 | ${project.artifactId}
273 | false
274 |
275 |
276 |
277 |
278 |
279 |
280 |
281 |
--------------------------------------------------------------------------------
/src/main/java/com/github/andbed/cleanarch/chargingproduct/core/GetChargingProducts.java:
--------------------------------------------------------------------------------
1 | package com.github.andbed.cleanarch.chargingproduct.core;
2 |
3 | public class GetChargingProducts {
4 |
5 | }
6 |
--------------------------------------------------------------------------------
/src/main/java/com/github/andbed/cleanarch/chargingproduct/delivery/rest/ChargingProductController.java:
--------------------------------------------------------------------------------
1 | package com.github.andbed.cleanarch.chargingproduct.delivery.rest;
2 |
3 | public class ChargingProductController {
4 |
5 | }
6 |
--------------------------------------------------------------------------------
/src/main/java/com/github/andbed/cleanarch/eventtype/core/GetAllEventTypes.java:
--------------------------------------------------------------------------------
1 | package com.github.andbed.cleanarch.eventtype.core;
2 |
3 | import java.util.List;
4 | import java.util.Optional;
5 | import java.util.stream.Collectors;
6 |
7 | import lombok.extern.slf4j.Slf4j;
8 |
9 | import com.github.andbed.cleanarch.eventtype.core.boundary.MessageCode;
10 | import com.github.andbed.cleanarch.eventtype.core.boundary.provide.Command;
11 | import com.github.andbed.cleanarch.eventtype.core.boundary.provide.EventTypeRequestModel;
12 | import com.github.andbed.cleanarch.eventtype.core.boundary.provide.EventTypeShortResponseModel;
13 | import com.github.andbed.cleanarch.eventtype.core.boundary.provide.EventTypesListPresenter;
14 | import com.github.andbed.cleanarch.eventtype.core.boundary.require.EventTypesFinder;
15 | import com.github.andbed.cleanarch.eventtype.core.entity.EventType;
16 |
17 | @Slf4j
18 | public class GetAllEventTypes implements Command {
19 |
20 | protected final EventTypesFinder provider;
21 | protected final EventTypesListPresenter presenter;
22 | protected final Optional requestModel;
23 |
24 | public GetAllEventTypes(EventTypesFinder provider, EventTypesListPresenter presenter,
25 | Optional requestModel) {
26 | this.provider = provider;
27 | this.presenter = presenter;
28 | this.requestModel = requestModel;
29 | }
30 |
31 | @Override
32 | public void execute() {
33 | try {
34 | List allEventTypes = provider.findAll(requestModel);
35 |
36 | if (!allEventTypes.isEmpty()) {
37 | List eventTypes = allEventTypes.stream()
38 | .filter(EventType::isVisible)
39 | .map(e -> e.toShortEventType())
40 | .collect(Collectors.toList());
41 |
42 | presenter.sendResult(eventTypes);
43 |
44 | } else {
45 | presenter.sendClientErrorMessage(MessageCode.NOT_FOUND);
46 | }
47 |
48 | } catch (Exception e) {
49 | log.debug(e.getMessage(), e);
50 | presenter.sendServerErrorMessage(MessageCode.INTERNAL_SERVER_ERROR);
51 | }
52 | }
53 |
54 | }
55 |
--------------------------------------------------------------------------------
/src/main/java/com/github/andbed/cleanarch/eventtype/core/ImportEventTypes.java:
--------------------------------------------------------------------------------
1 | package com.github.andbed.cleanarch.eventtype.core;
2 |
3 | import java.io.IOException;
4 | import java.util.List;
5 |
6 | import com.github.andbed.cleanarch.eventtype.core.boundary.MessageCode;
7 | import com.github.andbed.cleanarch.eventtype.core.boundary.provide.Command;
8 | import com.github.andbed.cleanarch.eventtype.core.boundary.provide.ImportPresenter;
9 | import com.github.andbed.cleanarch.eventtype.core.boundary.require.EventTypesFileProvider;
10 | import com.github.andbed.cleanarch.eventtype.core.boundary.require.EventTypesPersister;
11 | import com.github.andbed.cleanarch.eventtype.core.boundary.require.Notifier;
12 | import com.github.andbed.cleanarch.eventtype.core.boundary.require.XMLParser;
13 | import com.github.andbed.cleanarch.eventtype.core.entity.EventType;
14 |
15 | public class ImportEventTypes implements Command {
16 |
17 | private static final String MESSAGE = "EventTypes were successfuly parsed and persisted";
18 | private static final boolean SUCCESS = true;
19 | private final EventTypesFileProvider fileProvider;
20 | private final EventTypesPersister eventTypesPersister;
21 | private final Notifier notificator;
22 | private final XMLParser xmlParser;
23 | private final ImportPresenter presenter;
24 |
25 | public ImportEventTypes(EventTypesFileProvider fileProvider, EventTypesPersister eventTypesPersister,
26 | Notifier notificator, XMLParser xmlParser, ImportPresenter receiver) {
27 | this.fileProvider = fileProvider;
28 | this.eventTypesPersister = eventTypesPersister;
29 | this.notificator = notificator;
30 | this.xmlParser = xmlParser;
31 | this.presenter = receiver;
32 | }
33 |
34 | @Override
35 | public void execute() {
36 |
37 | String xmlPath, xsdPath;
38 |
39 | try {
40 | xmlPath = fileProvider.findEventTypesFile();
41 | xsdPath = fileProvider.findEventTypesXSD();
42 | } catch (IOException ex) {
43 | presenter.sendMessage(MessageCode.FILE_NOT_FOUND);
44 | return;
45 | }
46 |
47 | boolean isValidFile = xmlParser.isValid(xmlPath, xsdPath);
48 | if (!isValidFile) {
49 | presenter.sendMessage(MessageCode.XML_NOT_VALID);
50 | return;
51 | }
52 |
53 | List eventTypes = xmlParser.bind(EventType.class);
54 |
55 | if (!eventTypes.isEmpty()) {
56 |
57 | eventTypes.forEach(
58 | e -> e.calculateInheritedAttributes());
59 |
60 | eventTypesPersister.persist(eventTypes);
61 |
62 | notificator.notifyAdministrator(MESSAGE);
63 |
64 | presenter.sendResult(SUCCESS);
65 |
66 | } else {
67 | presenter.sendMessage(MessageCode.NOT_FOUND);
68 | }
69 | }
70 |
71 | }
72 |
--------------------------------------------------------------------------------
/src/main/java/com/github/andbed/cleanarch/eventtype/core/boundary/MessageCode.java:
--------------------------------------------------------------------------------
1 | package com.github.andbed.cleanarch.eventtype.core.boundary;
2 |
3 | public enum MessageCode {
4 | NOT_FOUND,
5 | INTERNAL_SERVER_ERROR,
6 | XML_NOT_VALID,
7 | FILE_NOT_FOUND;
8 | }
9 |
--------------------------------------------------------------------------------
/src/main/java/com/github/andbed/cleanarch/eventtype/core/boundary/provide/Command.java:
--------------------------------------------------------------------------------
1 | package com.github.andbed.cleanarch.eventtype.core.boundary.provide;
2 |
3 | public interface Command {
4 | void execute();
5 | }
6 |
--------------------------------------------------------------------------------
/src/main/java/com/github/andbed/cleanarch/eventtype/core/boundary/provide/DataStoreException.java:
--------------------------------------------------------------------------------
1 | package com.github.andbed.cleanarch.eventtype.core.boundary.provide;
2 |
3 | @SuppressWarnings("serial")
4 | public class DataStoreException extends RuntimeException {
5 |
6 | }
7 |
--------------------------------------------------------------------------------
/src/main/java/com/github/andbed/cleanarch/eventtype/core/boundary/provide/EventTypeFactory.java:
--------------------------------------------------------------------------------
1 | package com.github.andbed.cleanarch.eventtype.core.boundary.provide;
2 |
3 | import java.util.Optional;
4 |
5 | public interface EventTypeFactory {
6 |
7 | Command createGetAllEventTypesCommand(EventTypesListPresenter presenter,
8 | Optional requestModel);
9 |
10 | }
11 |
--------------------------------------------------------------------------------
/src/main/java/com/github/andbed/cleanarch/eventtype/core/boundary/provide/EventTypeFullResponseModel.java:
--------------------------------------------------------------------------------
1 | package com.github.andbed.cleanarch.eventtype.core.boundary.provide;
2 |
3 | import java.util.List;
4 |
5 | import lombok.Data;
6 | import lombok.experimental.Accessors;
7 |
8 | @Data
9 | @Accessors(chain = true)
10 | public class EventTypeFullResponseModel {
11 | Long id;
12 | String name;
13 | List attributeNames;
14 | }
15 |
--------------------------------------------------------------------------------
/src/main/java/com/github/andbed/cleanarch/eventtype/core/boundary/provide/EventTypeRequestModel.java:
--------------------------------------------------------------------------------
1 | package com.github.andbed.cleanarch.eventtype.core.boundary.provide;
2 |
3 | import lombok.Data;
4 | import lombok.experimental.Accessors;
5 |
6 | @Data
7 | @Accessors(chain = true)
8 | public class EventTypeRequestModel {
9 | String searchTerm;
10 | PageRequest page;
11 | }
12 |
--------------------------------------------------------------------------------
/src/main/java/com/github/andbed/cleanarch/eventtype/core/boundary/provide/EventTypeShortResponseModel.java:
--------------------------------------------------------------------------------
1 | package com.github.andbed.cleanarch.eventtype.core.boundary.provide;
2 |
3 | import lombok.Data;
4 | import lombok.experimental.Accessors;
5 |
6 | @Data
7 | @Accessors(chain = true)
8 | public class EventTypeShortResponseModel {
9 | Long id;
10 | String name;
11 | Long number;
12 | }
13 |
--------------------------------------------------------------------------------
/src/main/java/com/github/andbed/cleanarch/eventtype/core/boundary/provide/EventTypesListPresenter.java:
--------------------------------------------------------------------------------
1 | package com.github.andbed.cleanarch.eventtype.core.boundary.provide;
2 |
3 | import java.util.List;
4 |
5 | import com.github.andbed.cleanarch.eventtype.core.boundary.MessageCode;
6 |
7 | public interface EventTypesListPresenter {
8 |
9 | void sendServerErrorMessage(MessageCode code);
10 |
11 | void sendClientErrorMessage(MessageCode code);
12 |
13 | void sendResult(List events);
14 | }
15 |
--------------------------------------------------------------------------------
/src/main/java/com/github/andbed/cleanarch/eventtype/core/boundary/provide/ImportPresenter.java:
--------------------------------------------------------------------------------
1 | package com.github.andbed.cleanarch.eventtype.core.boundary.provide;
2 |
3 | import com.github.andbed.cleanarch.eventtype.core.boundary.MessageCode;
4 |
5 | public interface ImportPresenter {
6 |
7 | void sendMessage(MessageCode xmlNotValid);
8 |
9 | void sendResult(boolean result);
10 |
11 | }
12 |
--------------------------------------------------------------------------------
/src/main/java/com/github/andbed/cleanarch/eventtype/core/boundary/provide/PageRequest.java:
--------------------------------------------------------------------------------
1 | package com.github.andbed.cleanarch.eventtype.core.boundary.provide;
2 |
3 | public class PageRequest {
4 | int pageNumber;
5 | int pageSize;
6 | }
7 |
--------------------------------------------------------------------------------
/src/main/java/com/github/andbed/cleanarch/eventtype/core/boundary/require/EventTypesFileProvider.java:
--------------------------------------------------------------------------------
1 | package com.github.andbed.cleanarch.eventtype.core.boundary.require;
2 |
3 | import java.io.IOException;
4 |
5 | public interface EventTypesFileProvider {
6 |
7 | String findEventTypesFile() throws IOException;
8 |
9 | String findEventTypesXSD() throws IOException;
10 |
11 | }
12 |
--------------------------------------------------------------------------------
/src/main/java/com/github/andbed/cleanarch/eventtype/core/boundary/require/EventTypesFinder.java:
--------------------------------------------------------------------------------
1 | package com.github.andbed.cleanarch.eventtype.core.boundary.require;
2 |
3 | import java.util.List;
4 | import java.util.Optional;
5 |
6 | import com.github.andbed.cleanarch.eventtype.core.boundary.provide.EventTypeRequestModel;
7 | import com.github.andbed.cleanarch.eventtype.core.entity.EventType;
8 |
9 | public interface EventTypesFinder {
10 |
11 | List findAll(Optional requestModel);
12 |
13 | }
14 |
--------------------------------------------------------------------------------
/src/main/java/com/github/andbed/cleanarch/eventtype/core/boundary/require/EventTypesPersister.java:
--------------------------------------------------------------------------------
1 | package com.github.andbed.cleanarch.eventtype.core.boundary.require;
2 |
3 | import java.util.List;
4 |
5 | import com.github.andbed.cleanarch.eventtype.core.entity.EventType;
6 |
7 | public interface EventTypesPersister {
8 |
9 | void persist(List eventTypes);
10 |
11 | }
12 |
--------------------------------------------------------------------------------
/src/main/java/com/github/andbed/cleanarch/eventtype/core/boundary/require/Notifier.java:
--------------------------------------------------------------------------------
1 | package com.github.andbed.cleanarch.eventtype.core.boundary.require;
2 |
3 | public interface Notifier {
4 |
5 | void notifyAdministrator(String message);
6 |
7 | }
8 |
--------------------------------------------------------------------------------
/src/main/java/com/github/andbed/cleanarch/eventtype/core/boundary/require/XMLParser.java:
--------------------------------------------------------------------------------
1 | package com.github.andbed.cleanarch.eventtype.core.boundary.require;
2 |
3 | import java.util.List;
4 |
5 | public interface XMLParser {
6 |
7 | boolean isValid(String xmlPath, String xsdPath);
8 |
9 | List bind(Class className);
10 |
11 | }
12 |
--------------------------------------------------------------------------------
/src/main/java/com/github/andbed/cleanarch/eventtype/core/entity/EventAttribute.java:
--------------------------------------------------------------------------------
1 | package com.github.andbed.cleanarch.eventtype.core.entity;
2 |
3 | import lombok.Data;
4 |
5 | @Data
6 | public class EventAttribute {
7 | String name;
8 | }
9 |
--------------------------------------------------------------------------------
/src/main/java/com/github/andbed/cleanarch/eventtype/core/entity/EventType.java:
--------------------------------------------------------------------------------
1 | package com.github.andbed.cleanarch.eventtype.core.entity;
2 |
3 | import java.util.List;
4 | import java.util.stream.Collectors;
5 |
6 | import com.github.andbed.cleanarch.eventtype.core.boundary.provide.EventTypeFullResponseModel;
7 | import com.github.andbed.cleanarch.eventtype.core.boundary.provide.EventTypeShortResponseModel;
8 |
9 | public abstract class EventType {
10 |
11 | public abstract Long getId();
12 |
13 | public abstract String getName();
14 |
15 | public abstract List getAttributes();
16 |
17 | public abstract boolean isVisible();
18 |
19 | public void calculateInheritedAttributes() {
20 | }
21 |
22 | public EventTypeShortResponseModel toShortEventType() {
23 | return new EventTypeShortResponseModel()
24 | .setName(getName())
25 | .setId(getId());
26 | }
27 |
28 | public EventTypeFullResponseModel toFullEventType() {
29 | return new EventTypeFullResponseModel()
30 | .setName(getName())
31 | .setId(getId())
32 | .setAttributeNames(getAttributes().stream()
33 | .map(a -> a.getName())
34 | .collect(Collectors.toList()));
35 | }
36 |
37 | }
--------------------------------------------------------------------------------
/src/main/java/com/github/andbed/cleanarch/eventtype/delivery/rest/EventTypesController.java:
--------------------------------------------------------------------------------
1 | package com.github.andbed.cleanarch.eventtype.delivery.rest;
2 |
3 | import java.util.ArrayList;
4 | import java.util.List;
5 | import java.util.Optional;
6 |
7 | import javax.inject.Inject;
8 |
9 | import lombok.extern.slf4j.Slf4j;
10 |
11 | import org.springframework.hateoas.Resources;
12 | import org.springframework.http.HttpStatus;
13 | import org.springframework.http.ResponseEntity;
14 | import org.springframework.stereotype.Controller;
15 | import org.springframework.web.bind.annotation.RequestMapping;
16 | import org.springframework.web.bind.annotation.RequestMethod;
17 |
18 | import com.github.andbed.cleanarch.eventtype.core.boundary.MessageCode;
19 | import com.github.andbed.cleanarch.eventtype.core.boundary.provide.Command;
20 | import com.github.andbed.cleanarch.eventtype.core.boundary.provide.EventTypeFactory;
21 | import com.github.andbed.cleanarch.eventtype.core.boundary.provide.EventTypeRequestModel;
22 | import com.github.andbed.cleanarch.eventtype.core.boundary.provide.EventTypeShortResponseModel;
23 | import com.github.andbed.cleanarch.eventtype.core.boundary.provide.EventTypesListPresenter;
24 |
25 | @Controller
26 | @RequestMapping(EventTypesController.URL)
27 | public class EventTypesController {
28 |
29 | public static final String URL = "/event";
30 | private final EventTypeFactory factory;
31 |
32 | @Inject
33 | public EventTypesController(EventTypeFactory factory) {
34 | this.factory = factory;
35 | }
36 |
37 | @RequestMapping(method = RequestMethod.GET)
38 | public ResponseEntity> getAllEventTypes(
39 | Optional requestModel) {
40 |
41 | EventTypesPresenter presenter = new EventTypesPresenter();
42 | Command getAllEventTypesCommand =
43 | factory.createGetAllEventTypesCommand(presenter, requestModel);
44 |
45 | getAllEventTypesCommand.execute();
46 |
47 | return presenter.generateResponse();
48 |
49 | }
50 |
51 | @Slf4j
52 | public static class EventTypesPresenter implements EventTypesListPresenter {
53 |
54 | private Optional> eventTypes;
55 | private Optional serverErrorCode;
56 | private Optional clientErrorCode;
57 |
58 | public EventTypesPresenter() {
59 | this.eventTypes = Optional.empty();
60 | this.serverErrorCode = Optional.empty();
61 | this.clientErrorCode = Optional.empty();
62 | }
63 |
64 | public ResponseEntity> generateResponse() {
65 | return eventTypes.isPresent() ?
66 | new ResponseEntity<>(new Resources(
67 | eventTypes.orElse(new ArrayList<>())),
68 | HttpStatus.OK) :
69 | createErrorResponse();
70 | }
71 |
72 | private ResponseEntity createErrorResponse() {
73 |
74 | return new ResponseEntity(HttpStatus.INTERNAL_SERVER_ERROR);
75 | }
76 |
77 | @Override
78 | public void sendServerErrorMessage(MessageCode code) {
79 | this.serverErrorCode = Optional.ofNullable(code);
80 | log.debug(code.toString());
81 | }
82 |
83 | @Override
84 | public void sendClientErrorMessage(MessageCode code) {
85 | this.clientErrorCode = Optional.ofNullable(code);
86 | log.debug(code.toString());
87 | }
88 |
89 | @Override
90 | public void sendResult(List eventTypes) {
91 | this.eventTypes = Optional.ofNullable(eventTypes);
92 | }
93 | };
94 | }
95 |
--------------------------------------------------------------------------------
/src/main/java/com/github/andbed/cleanarch/eventtype/delivery/rest/ImportEventTypesController.java:
--------------------------------------------------------------------------------
1 | package com.github.andbed.cleanarch.eventtype.delivery.rest;
2 |
3 | import org.springframework.http.HttpStatus;
4 | import org.springframework.http.ResponseEntity;
5 | import org.springframework.stereotype.Controller;
6 | import org.springframework.web.bind.annotation.RequestMapping;
7 | import org.springframework.web.bind.annotation.RequestMethod;
8 |
9 | import com.github.andbed.cleanarch.eventtype.core.boundary.MessageCode;
10 | import com.github.andbed.cleanarch.eventtype.core.boundary.provide.Command;
11 | import com.github.andbed.cleanarch.eventtype.core.boundary.provide.EventTypeRequestModel;
12 | import com.github.andbed.cleanarch.eventtype.core.boundary.provide.ImportPresenter;
13 | import com.github.andbed.cleanarch.eventtype.infrastructure.di.SpringDIFactory;
14 |
15 | @Controller
16 | @RequestMapping(ImportEventTypesController.URL)
17 | public class ImportEventTypesController {
18 |
19 | public static final String URL = "/eventimport";
20 | private final SpringDIFactory factory;
21 |
22 | public ImportEventTypesController(SpringDIFactory factory) {
23 | this.factory = factory;
24 | }
25 |
26 | @RequestMapping(method = RequestMethod.GET)
27 | public void importEventTypes(EventTypeRequestModel params) {
28 | Presenter presenter = new Presenter();
29 |
30 | Command importEventTypes = factory.
31 | createImportEventTypesCommand(presenter, params);
32 |
33 | importEventTypes.execute();
34 | }
35 |
36 | class Presenter implements ImportPresenter {
37 |
38 | private Boolean result;
39 | private MessageCode code;
40 |
41 | @Override
42 | public void sendMessage(MessageCode messageCode) {
43 | this.code = messageCode;
44 | }
45 |
46 | public ResponseEntity generateResponse() {
47 | return code == null ?
48 | new ResponseEntity<>(result, HttpStatus.OK) :
49 | new ResponseEntity(HttpStatus.INTERNAL_SERVER_ERROR);
50 | }
51 |
52 | @Override
53 | public void sendResult(boolean result) {
54 | this.result = result;
55 | }
56 |
57 | };
58 | }
59 |
--------------------------------------------------------------------------------
/src/main/java/com/github/andbed/cleanarch/eventtype/delivery/ws/EventTypesWSController.java:
--------------------------------------------------------------------------------
1 | package com.github.andbed.cleanarch.eventtype.delivery.ws;
2 |
3 | public class EventTypesWSController {
4 |
5 | }
6 |
--------------------------------------------------------------------------------
/src/main/java/com/github/andbed/cleanarch/eventtype/infrastructure/di/SpringDIFactory.java:
--------------------------------------------------------------------------------
1 | package com.github.andbed.cleanarch.eventtype.infrastructure.di;
2 |
3 | import java.util.Optional;
4 |
5 | import javax.inject.Inject;
6 | import javax.inject.Named;
7 |
8 | import com.github.andbed.cleanarch.eventtype.core.GetAllEventTypes;
9 | import com.github.andbed.cleanarch.eventtype.core.ImportEventTypes;
10 | import com.github.andbed.cleanarch.eventtype.core.boundary.provide.Command;
11 | import com.github.andbed.cleanarch.eventtype.core.boundary.provide.EventTypeFactory;
12 | import com.github.andbed.cleanarch.eventtype.core.boundary.provide.EventTypeRequestModel;
13 | import com.github.andbed.cleanarch.eventtype.core.boundary.provide.EventTypesListPresenter;
14 | import com.github.andbed.cleanarch.eventtype.core.boundary.provide.ImportPresenter;
15 | import com.github.andbed.cleanarch.eventtype.core.boundary.require.EventTypesFileProvider;
16 | import com.github.andbed.cleanarch.eventtype.core.boundary.require.Notifier;
17 | import com.github.andbed.cleanarch.eventtype.core.boundary.require.XMLParser;
18 | import com.github.andbed.cleanarch.eventtype.infrastructure.repository.db.jpa.EventTypeRepository;
19 |
20 | @Named
21 | public class SpringDIFactory implements EventTypeFactory {
22 |
23 | private final EventTypeRepository repository;
24 | private final XMLParser xmlParser;
25 | private final Notifier notifier;
26 | private final EventTypesFileProvider fileProvider;
27 |
28 | @Inject
29 | public SpringDIFactory(EventTypeRepository repository, XMLParser xmlParser, Notifier notifier, EventTypesFileProvider fileProvider) {
30 | this.repository = repository;
31 | this.xmlParser = xmlParser;
32 | this.notifier = notifier;
33 | this.fileProvider = fileProvider;
34 | }
35 |
36 | @Override
37 | public Command createGetAllEventTypesCommand(EventTypesListPresenter presenter, Optional requestModel) {
38 | return new GetAllEventTypes(repository, presenter, requestModel);
39 | }
40 |
41 | public Command createImportEventTypesCommand(ImportPresenter presenter, EventTypeRequestModel params) {
42 | return new ImportEventTypes(fileProvider, repository, notifier, xmlParser, presenter);
43 | }
44 |
45 | }
46 |
--------------------------------------------------------------------------------
/src/main/java/com/github/andbed/cleanarch/eventtype/infrastructure/io/EventTypeFileManager.java:
--------------------------------------------------------------------------------
1 | package com.github.andbed.cleanarch.eventtype.infrastructure.io;
2 |
3 | import com.github.andbed.cleanarch.eventtype.core.boundary.require.EventTypesFileProvider;
4 |
5 | public class EventTypeFileManager implements EventTypesFileProvider {
6 |
7 | @Override
8 | public String findEventTypesFile() {
9 | // TODO Auto-generated method stub
10 | return null;
11 | }
12 |
13 | @Override
14 | public String findEventTypesXSD() {
15 | // TODO Auto-generated method stub
16 | return null;
17 | }
18 |
19 | }
20 |
--------------------------------------------------------------------------------
/src/main/java/com/github/andbed/cleanarch/eventtype/infrastructure/io/XMLParserSAX.java:
--------------------------------------------------------------------------------
1 | package com.github.andbed.cleanarch.eventtype.infrastructure.io;
2 |
3 | import java.util.ArrayList;
4 | import java.util.List;
5 |
6 | import com.github.andbed.cleanarch.eventtype.core.boundary.require.XMLParser;
7 |
8 | public class XMLParserSAX implements XMLParser {
9 |
10 | @Override
11 | public boolean isValid(String xmlPath, String xsdPath) {
12 | return true;
13 | }
14 |
15 | @Override
16 | public List bind(Class className) {
17 | return new ArrayList();
18 | }
19 |
20 | }
21 |
--------------------------------------------------------------------------------
/src/main/java/com/github/andbed/cleanarch/eventtype/infrastructure/notification/email/EmailSender.java:
--------------------------------------------------------------------------------
1 | package com.github.andbed.cleanarch.eventtype.infrastructure.notification.email;
2 |
3 | import lombok.extern.slf4j.Slf4j;
4 |
5 | import com.github.andbed.cleanarch.eventtype.core.boundary.require.Notifier;
6 |
7 | @Slf4j
8 | public class EmailSender implements Notifier {
9 |
10 | @Override
11 | public void notifyAdministrator(String message) {
12 | log.debug("Email sent to admin");
13 | }
14 |
15 | }
16 |
--------------------------------------------------------------------------------
/src/main/java/com/github/andbed/cleanarch/eventtype/infrastructure/repository/db/jpa/EventTypeJPA.java:
--------------------------------------------------------------------------------
1 | package com.github.andbed.cleanarch.eventtype.infrastructure.repository.db.jpa;
2 |
3 | import static com.google.common.collect.Lists.newArrayList;
4 |
5 | import java.util.List;
6 |
7 | import javax.persistence.Column;
8 | import javax.persistence.Entity;
9 | import javax.persistence.Id;
10 | import javax.persistence.Table;
11 |
12 | import lombok.Data;
13 | import lombok.EqualsAndHashCode;
14 |
15 | import com.github.andbed.cleanarch.eventtype.core.entity.EventAttribute;
16 | import com.github.andbed.cleanarch.eventtype.core.entity.EventType;
17 |
18 | @Data
19 | @EqualsAndHashCode(callSuper = false)
20 | @Entity
21 | @Table(name = "eventtypes")
22 | public class EventTypeJPA extends EventType {
23 |
24 | @Id
25 | Long id;
26 |
27 | String name;
28 |
29 | @Column(name = "attributes")
30 | String commaSeparatedAttributes;
31 |
32 | boolean visible;
33 |
34 | @Override
35 | public List getAttributes() {
36 | return createAttributesFromString(commaSeparatedAttributes);
37 | }
38 |
39 | private List createAttributesFromString(String atts) {
40 | return newArrayList();
41 | }
42 |
43 | }
44 |
--------------------------------------------------------------------------------
/src/main/java/com/github/andbed/cleanarch/eventtype/infrastructure/repository/db/jpa/EventTypeRepository.java:
--------------------------------------------------------------------------------
1 | package com.github.andbed.cleanarch.eventtype.infrastructure.repository.db.jpa;
2 |
3 | import java.util.ArrayList;
4 | import java.util.List;
5 | import java.util.Optional;
6 |
7 | import com.github.andbed.cleanarch.eventtype.core.boundary.provide.EventTypeRequestModel;
8 | import com.github.andbed.cleanarch.eventtype.core.boundary.require.EventTypesFinder;
9 | import com.github.andbed.cleanarch.eventtype.core.boundary.require.EventTypesPersister;
10 | import com.github.andbed.cleanarch.eventtype.core.entity.EventType;
11 |
12 | public class EventTypeRepository implements EventTypesFinder, EventTypesPersister {
13 |
14 | public EventTypeRepository() {
15 | }
16 |
17 | @Override
18 | public List findAll(Optional requestModel) {
19 | String query = createQueryBasedOnParams(requestModel);
20 | return runQueryOnDB(query);
21 | }
22 |
23 | private List runQueryOnDB(String query) {
24 | return new ArrayList();
25 | }
26 |
27 | private String createQueryBasedOnParams(Optional params) {
28 | return "";
29 | }
30 |
31 | @Override
32 | public void persist(List eventTypes) {
33 | }
34 |
35 | }
36 |
--------------------------------------------------------------------------------
/src/main/java/com/github/andbed/cleanarch/eventtype/infrastructure/repository/rest/EventTypeFromRest.java:
--------------------------------------------------------------------------------
1 | package com.github.andbed.cleanarch.eventtype.infrastructure.repository.rest;
2 |
3 | import com.github.andbed.cleanarch.eventtype.core.entity.EventAttribute;
4 | import com.github.andbed.cleanarch.eventtype.core.entity.EventType;
5 | import lombok.Data;
6 | import lombok.EqualsAndHashCode;
7 |
8 | import javax.persistence.Column;
9 | import javax.persistence.Id;
10 | import java.util.List;
11 |
12 | import static com.google.common.collect.Lists.newArrayList;
13 |
14 | @Data
15 | @EqualsAndHashCode(callSuper = false)
16 | public class EventTypeFromRest extends EventType {
17 |
18 | Long id;
19 |
20 | String name;
21 |
22 | String commaSeparatedAttributes;
23 |
24 | boolean visible;
25 |
26 | @Override
27 | public List getAttributes() {
28 | return createAttributesFromString(commaSeparatedAttributes);
29 | }
30 |
31 | private List createAttributesFromString(String atts) {
32 | return newArrayList();
33 | }
34 |
35 | }
36 |
--------------------------------------------------------------------------------
/src/main/java/com/github/andbed/cleanarch/eventtype/infrastructure/repository/rest/EventTypeRestRepo.java:
--------------------------------------------------------------------------------
1 | package com.github.andbed.cleanarch.eventtype.infrastructure.repository.rest;
2 |
3 | import com.github.andbed.cleanarch.eventtype.core.boundary.provide.EventTypeRequestModel;
4 | import com.github.andbed.cleanarch.eventtype.core.boundary.require.EventTypesFinder;
5 | import com.github.andbed.cleanarch.eventtype.core.boundary.require.EventTypesPersister;
6 | import com.github.andbed.cleanarch.eventtype.core.entity.EventType;
7 |
8 | import java.util.ArrayList;
9 | import java.util.Comparator;
10 | import java.util.List;
11 | import java.util.Optional;
12 | import java.util.stream.Collectors;
13 |
14 | public class EventTypeRestRepo implements EventTypesFinder, EventTypesPersister {
15 |
16 | List events = new ArrayList<>();
17 |
18 |
19 | @Override
20 | public List findAll(Optional request) {
21 |
22 | return events.stream()
23 | .filter(e -> nameIsEqualToOrAll(e, request.map(EventTypeRequestModel::getSearchTerm)))
24 | .sorted(Comparator.comparing(EventTypeFromRest::getName))
25 | .limit(100)
26 | .collect(Collectors.toList());
27 | }
28 |
29 |
30 | private boolean nameIsEqualToOrAll(EventTypeFromRest e, Optional search) {
31 | return search.isPresent() ? e.getName().equals(search.get()) : true;
32 |
33 | }
34 |
35 |
36 | @Override
37 | public void persist(List eventTypes) {
38 |
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/src/main/java/com/github/andbed/cleanarch/rate/core/DisableRateFromCurrentOffer.java:
--------------------------------------------------------------------------------
1 | package com.github.andbed.cleanarch.rate.core;
2 |
3 | public class DisableRateFromCurrentOffer {
4 |
5 | }
6 |
--------------------------------------------------------------------------------
/src/main/java/com/github/andbed/cleanarch/rate/core/GetRates.java:
--------------------------------------------------------------------------------
1 | package com.github.andbed.cleanarch.rate.core;
2 |
3 | public class GetRates {
4 |
5 | }
6 |
--------------------------------------------------------------------------------
/src/main/java/com/github/andbed/cleanarch/rate/delivery/rest/RateController.java:
--------------------------------------------------------------------------------
1 | package com.github.andbed.cleanarch.rate.delivery.rest;
2 |
3 | public class RateController {
4 |
5 | }
6 |
--------------------------------------------------------------------------------
/src/main/java/com/github/andbed/cleanarch/tariffplan/core/ActivateTariffPlan.java:
--------------------------------------------------------------------------------
1 | package com.github.andbed.cleanarch.tariffplan.core;
2 |
3 | public class ActivateTariffPlan {
4 |
5 | }
6 |
--------------------------------------------------------------------------------
/src/main/java/com/github/andbed/cleanarch/tariffplan/delivery/rest/TariffPlanRESTAPI.java:
--------------------------------------------------------------------------------
1 | package com.github.andbed.cleanarch.tariffplan.delivery.rest;
2 |
3 | public class TariffPlanRESTAPI {
4 |
5 | }
6 |
--------------------------------------------------------------------------------
/src/main/resources/application.properties:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/andbed/clean-architecture/d0b09ab9d8678aa1033e8dfe847c97899ce9f120/src/main/resources/application.properties
--------------------------------------------------------------------------------
/src/test/java/com/github/andbed/cleanarch/eventtype/core/GetAllEventTypesTest.java:
--------------------------------------------------------------------------------
1 | package com.github.andbed.cleanarch.eventtype.core;
2 |
3 | import static com.google.common.collect.Lists.newArrayList;
4 | import static org.assertj.core.api.Assertions.assertThat;
5 | import static org.springframework.util.CollectionUtils.isEmpty;
6 |
7 | import java.util.List;
8 | import java.util.Optional;
9 |
10 | import org.junit.Test;
11 |
12 | import com.github.andbed.cleanarch.eventtype.core.boundary.MessageCode;
13 | import com.github.andbed.cleanarch.eventtype.core.boundary.provide.EventTypeRequestModel;
14 | import com.github.andbed.cleanarch.eventtype.core.boundary.provide.EventTypeShortResponseModel;
15 | import com.github.andbed.cleanarch.eventtype.core.boundary.provide.EventTypesListPresenter;
16 | import com.github.andbed.cleanarch.eventtype.core.boundary.require.EventTypesFinder;
17 | import com.github.andbed.cleanarch.eventtype.core.entity.EventAttribute;
18 | import com.github.andbed.cleanarch.eventtype.core.entity.EventType;
19 |
20 | public class GetAllEventTypesTest {
21 |
22 | @Test
23 | public void shouldGetCorrectItemsToDisplay() {
24 | // given
25 | EventTypesFinder finderStub = twoItemsOneVisible();
26 | TestPresenter presenterSpy = new TestPresenter();
27 | GetAllEventTypes command = new GetAllEventTypes(finderStub, presenterSpy, Optional.empty());
28 |
29 | // when
30 | command.execute();
31 |
32 | // then
33 | assertThat(presenterSpy.numberOfDisplayedItems()).isEqualTo(1);
34 | }
35 |
36 | @Test
37 | public void shouldHandleDBDown() {
38 | // given
39 | EventTypesFinder providerStub = throwingDBException();
40 | TestPresenter presenterSpy = new TestPresenter();
41 | GetAllEventTypes command = new GetAllEventTypes(providerStub, presenterSpy, Optional.empty());
42 |
43 | // when
44 | command.execute();
45 |
46 | // then
47 | assertThat(presenterSpy.numberOfDisplayedItems()).isEqualTo(0);
48 | assertThat(presenterSpy.code).isEqualTo(MessageCode.INTERNAL_SERVER_ERROR);
49 | }
50 |
51 | @Test
52 | public void shouldBehaveCorrectlyWhenEmptyListReturnedFromProvider() {
53 | // given
54 | EventTypesFinder providerStub = emptyRepository();
55 | TestPresenter presenterSpy = new TestPresenter();
56 | GetAllEventTypes command = new GetAllEventTypes(providerStub, presenterSpy, Optional.empty());
57 |
58 | // when
59 | command.execute();
60 |
61 | // then
62 | assertThat(presenterSpy.numberOfDisplayedItems()).isEqualTo(0);
63 | assertThat(presenterSpy.code).isEqualTo(MessageCode.NOT_FOUND);
64 | }
65 |
66 | public static class TestPresenter implements EventTypesListPresenter {
67 |
68 | List events;
69 | MessageCode code;
70 |
71 | @Override
72 | public void sendServerErrorMessage(MessageCode code) {
73 | this.code = code;
74 | }
75 |
76 | @Override
77 | public void sendClientErrorMessage(MessageCode code) {
78 | this.code = code;
79 | }
80 |
81 | @Override
82 | public void sendResult(List events) {
83 | this.events = events;
84 | }
85 |
86 | public int numberOfDisplayedItems() {
87 | return isEmpty(events) ? 0 : events.size();
88 | }
89 |
90 | };
91 |
92 | private EventType createEventType(Long id, String name, boolean isDisplayed) {
93 | return new EventType() {
94 |
95 | @Override
96 | public String getName() {
97 | return name;
98 | }
99 |
100 | @Override
101 | public Long getId() {
102 | return id;
103 | }
104 |
105 | @Override
106 | public List getAttributes() {
107 | return null;
108 | }
109 |
110 | @Override
111 | public boolean isVisible() {
112 | return isDisplayed;
113 | }
114 | };
115 | }
116 |
117 | private EventTypesFinder twoItemsOneVisible() {
118 | return new EventTypesFinder() {
119 | @Override
120 | public List findAll(Optional requestModel) {
121 | return newArrayList(createDisplayableEventType(), createNonDisplayableEventType());
122 | }
123 |
124 | };
125 | }
126 |
127 | private EventTypesFinder throwingDBException() {
128 | return new EventTypesFinder() {
129 | @Override
130 | public List findAll(Optional requestModel) {
131 | throw new RuntimeException("DB down");
132 | }
133 | };
134 | }
135 |
136 | private EventTypesFinder emptyRepository() {
137 | return new EventTypesFinder() {
138 | @Override
139 | public List findAll(Optional requestModel) {
140 | return newArrayList();
141 | }
142 | };
143 | }
144 |
145 | boolean nonDisplayable = false;
146 | boolean displayable = true;
147 | long anyId1 = 1L;
148 | long anyId2 = 2L;
149 | String anyDesc = "lorem ipsum";
150 |
151 | private EventType createDisplayableEventType() {
152 | return createEventType(anyId1, anyDesc, displayable);
153 | }
154 |
155 | private EventType createNonDisplayableEventType() {
156 | return createEventType(anyId2, anyDesc, nonDisplayable);
157 | }
158 |
159 | }
160 |
--------------------------------------------------------------------------------
/src/test/java/com/github/andbed/cleanarch/eventtype/delivery/rest/EventTypesControllerIntegrationTest.java:
--------------------------------------------------------------------------------
1 | package com.github.andbed.cleanarch.eventtype.delivery.rest;
2 |
3 | import static com.google.common.collect.Lists.newArrayList;
4 | import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
5 | import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print;
6 | import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
7 | import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
8 |
9 | import java.util.Optional;
10 |
11 | import org.junit.Test;
12 | import org.springframework.http.MediaType;
13 | import org.springframework.test.web.servlet.MockMvc;
14 | import org.springframework.test.web.servlet.setup.MockMvcBuilders;
15 |
16 | import com.github.andbed.cleanarch.eventtype.core.GetAllEventTypes;
17 | import com.github.andbed.cleanarch.eventtype.core.boundary.MessageCode;
18 | import com.github.andbed.cleanarch.eventtype.core.boundary.provide.Command;
19 | import com.github.andbed.cleanarch.eventtype.core.boundary.provide.EventTypeFactory;
20 | import com.github.andbed.cleanarch.eventtype.core.boundary.provide.EventTypeRequestModel;
21 | import com.github.andbed.cleanarch.eventtype.core.boundary.provide.EventTypesListPresenter;
22 |
23 | public class EventTypesControllerIntegrationTest {
24 |
25 | String URL = "http://localhost" + EventTypesController.URL;
26 |
27 | @Test
28 | public void shouldReturnJSONList() throws Exception {
29 | // given
30 | EventTypesController controller =
31 | new EventTypesController(
32 | withCommandStubReturningCorrectResult());
33 | MockMvc mvc = MockMvcBuilders.standaloneSetup(controller).build();
34 |
35 | // when
36 | mvc.perform(get(URL).accept(MediaType.APPLICATION_JSON))
37 | .andDo(print())
38 | // then
39 | .andExpect(status().isOk())
40 | .andExpect(jsonPath("$.content").isArray())
41 | .andExpect(jsonPath("$.links").isArray());
42 | }
43 |
44 | @Test
45 | public void shouldReturnProperErrorCode() throws Exception {
46 | // given
47 | EventTypesController controller =
48 | new EventTypesController(withCommandStubThrowingError());
49 | MockMvc mvc = MockMvcBuilders.standaloneSetup(controller).build();
50 |
51 | // when
52 | mvc.perform(get(URL).accept(MediaType.APPLICATION_JSON))
53 | .andDo(print())
54 | // then
55 | .andExpect(status().is5xxServerError());
56 | }
57 |
58 |
59 |
60 | private EventTypeFactory withCommandStubReturningCorrectResult() {
61 | return new EventTypeFactory() {
62 | @Override
63 | public Command createGetAllEventTypesCommand(EventTypesListPresenter presenter, Optional requestModel) {
64 | return new GetAllEventTypes(null, presenter, requestModel) {
65 | @Override
66 | public void execute() {
67 | presenter.sendResult(newArrayList());
68 | }
69 |
70 | };
71 | }
72 | };
73 | }
74 |
75 | private EventTypeFactory withCommandStubThrowingError() {
76 | return new EventTypeFactory() {
77 | @Override
78 | public Command createGetAllEventTypesCommand(EventTypesListPresenter presenter, Optional requestModel) {
79 | return new GetAllEventTypes(null, presenter, requestModel) {
80 | @Override
81 | public void execute() {
82 |
83 | presenter.sendServerErrorMessage(
84 | MessageCode.INTERNAL_SERVER_ERROR);
85 | }
86 |
87 | };
88 | }
89 | };
90 | }
91 |
92 | }
93 |
--------------------------------------------------------------------------------
/src/test/java/com/github/andbed/cleanarch/learningtest/java8/Example.java:
--------------------------------------------------------------------------------
1 | package com.github.andbed.cleanarch.learningtest.java8;
2 |
3 | import java.util.Arrays;
4 | import java.util.List;
5 | import java.util.function.Consumer;
6 | import java.util.function.ToIntFunction;
7 | import java.util.stream.Collectors;
8 | import java.util.stream.Stream;
9 |
10 | public class Example {
11 |
12 | public static void main (String[] args) {
13 |
14 | List list = Arrays.asList(1, 2, 3, 4, 5, 6);
15 |
16 | int total = 0;
17 | for (int i=0; i< list.size(); i++) {
18 | if ((list.get(i) % 2 == 0) && (list.get(i) > 3)) {
19 | int temp = list.get(i) * list.get(i);
20 | total += temp;
21 | }
22 | }
23 |
24 | System.out.println(total);
25 |
26 | System.out.println(
27 |
28 | list.stream()
29 | .filter(e -> e % 2 == 0)
30 | .filter(e -> e>3)
31 | .mapToInt(e -> e * e)
32 | .sum());
33 |
34 | Stream.iterate(1, e -> e +1)
35 | .filter(e -> e > 3)
36 | .filter(e -> Math.sqrt(e) > 10)
37 | .limit(100)
38 | .collect(Collectors.toList());
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 | }
48 |
49 |
50 | }
51 |
--------------------------------------------------------------------------------
/src/test/java/com/github/andbed/cleanarch/learningtest/java8/Example1.java:
--------------------------------------------------------------------------------
1 | package com.github.andbed.cleanarch.learningtest.java8;
2 |
3 | import java.util.ArrayList;
4 | import java.util.Arrays;
5 | import java.util.List;
6 | import java.util.function.Consumer;
7 | import java.util.function.Function;
8 | import java.util.function.Predicate;
9 | import java.util.stream.Collectors;
10 |
11 | public class Example1 {
12 |
13 | public static void main(String[] args) {
14 |
15 |
16 | }
17 |
18 |
19 | public static void oldFashionedSimpleFor() {
20 |
21 | List ints = Arrays.asList(1, 2, 3, 4, 5, 6);
22 |
23 | int total = 0;
24 |
25 | for (int i=0; i ints = Arrays.asList(1, 2, 3, 4, 5, 6);
35 |
36 | List evenDoubles = new ArrayList<>();
37 |
38 | for (int i=0; i ints = Arrays.asList(1, 2, 3, 4, 5, 6);
50 |
51 | Integer total = ints.stream()
52 | .mapToInt(e -> e * 2)
53 | .sum();
54 |
55 | System.out.println(total);
56 |
57 | }
58 |
59 | public static void functionalComplexFor() {
60 |
61 | List ints = Arrays.asList(1, 2, 3, 4, 5, 6);
62 |
63 | List evenDoubles = ints.stream()
64 | .filter(e -> e % 2 == 0)
65 | .map(e -> e * 2)
66 | .collect(Collectors.toList());
67 |
68 | System.out.println(evenDoubles);
69 | universalListProcessor(e -> e * 2, e -> e % 2 == 0);
70 | }
71 |
72 | public static void universalListProcessor(Function func, Predicate pred) {
73 | List collection = Arrays.asList(1, 2, 3, 4, 5, 6);
74 | List col = collection.stream()
75 | .filter(pred)
76 | .map(func)
77 | .collect(Collectors.toList());
78 | System.out.println(col);
79 |
80 | }
81 |
82 | }
83 |
--------------------------------------------------------------------------------
/src/test/java/com/github/andbed/cleanarch/learningtest/java8/ExamplesForPresentation.java:
--------------------------------------------------------------------------------
1 | package com.github.andbed.cleanarch.learningtest.java8;
2 |
3 | import java.time.LocalDate;
4 | import java.time.LocalDateTime;
5 | import java.time.LocalTime;
6 | import java.time.Month;
7 | import java.util.Optional;
8 |
9 | public class ExamplesForPresentation {
10 |
11 | public static void main(String [] args) {
12 |
13 | Optional computer = Optional.of(new Computer());
14 | computer.get().soundCard = Optional.of(new SoundCard());
15 | computer.get().soundCard.get().driver = Optional.of(new Usb());
16 |
17 | String name = computer.flatMap(c -> c.soundCard)
18 | .flatMap(s -> s.driver)
19 | .map(u -> u.name)
20 | .orElse("UNKNOWN");
21 |
22 |
23 | Optional elem = find(123);
24 |
25 | elem.ifPresent(System.out::println);
26 |
27 | LocalDateTime timePoint = LocalDateTime.now(); // The current date and time
28 | LocalDate.of(2012, Month.DECEMBER, 12); // from values
29 | LocalTime.of(17, 18); // the train I took home today
30 | LocalTime.parse("10:15:30"); // From a String
31 |
32 | int day = timePoint.getDayOfMonth();
33 | timePoint.plusDays(10);
34 |
35 | }
36 |
37 | public static Optional find(int id) {
38 | return null;
39 | }
40 |
41 | static class Computer {
42 | Optional soundCard;
43 | }
44 |
45 | static class SoundCard {
46 | Optional driver;
47 | }
48 |
49 | static class Usb {
50 | public String name="aaa";
51 | }
52 | }
53 |
--------------------------------------------------------------------------------
/src/test/java/com/github/andbed/cleanarch/learningtest/tdd/FilteredSortedListTest.java:
--------------------------------------------------------------------------------
1 | package com.github.andbed.cleanarch.learningtest.tdd;
2 |
3 | import static com.google.common.collect.Lists.newArrayList;
4 | import static org.assertj.core.api.Assertions.assertThat;
5 |
6 | import java.util.ArrayList;
7 | import java.util.List;
8 | import java.util.stream.Collectors;
9 |
10 | import org.assertj.core.api.Condition;
11 | import org.junit.Ignore;
12 | import org.junit.Test;
13 |
14 | public class FilteredSortedListTest {
15 |
16 | @Test
17 | @Ignore
18 | public void shouldFilterActiveOnly() {
19 | MyRepo repo = new MyRepo();
20 |
21 | List- items = repo.findItems();
22 |
23 | assertThat(items).are(activeOnly());
24 | }
25 |
26 | @Test
27 | @Ignore
28 | public void shouldSortList() {
29 | MyRepo repo = new MyRepo();
30 |
31 | List
- items = repo.findItems();
32 |
33 | assertThat(items).isSorted();
34 | }
35 |
36 | private Condition
- activeOnly() {
37 | return new Condition() {
38 | @Override
39 | public boolean matches(Item item) {
40 | return item.isActive();
41 | }
42 | };
43 | }
44 |
45 | public class MyRepo {
46 |
47 | public List
- findItems() {
48 | List
- items = newArrayList(new Item(), new Item());
49 | List
- filteredItems = filter(items);
50 | return sort(filteredItems);
51 | }
52 |
53 | public List
- findItemsNew() {
54 | List
- items = newArrayList(new Item(), new Item());
55 | return items.stream()
56 | .filter(Item::isActive)
57 | .sorted()
58 | .collect(Collectors.toList());
59 | }
60 |
61 | private List
- sort(List
- items) {
62 | List
- itemsSorted = newArrayList(items);
63 | itemsSorted.sort(null);
64 | return itemsSorted;
65 | }
66 |
67 | private List
- filter(List
- items) {
68 |
69 | List
- filtered = new ArrayList<>();
70 |
71 | for (Item item : items) {
72 | if (item.isActive()) {
73 | filtered.add(item);
74 | }
75 | }
76 | return filtered;
77 | }
78 | }
79 |
80 | public class Item {
81 |
82 | public boolean isActive() {
83 | return true;
84 | }
85 |
86 | }
87 |
88 | }
89 |
--------------------------------------------------------------------------------
/src/test/resources/test.properties:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/andbed/clean-architecture/d0b09ab9d8678aa1033e8dfe847c97899ce9f120/src/test/resources/test.properties
--------------------------------------------------------------------------------