Clean architecture: which layer for a very common module? - clean-architecture

I have a very common module for report events to multi-platform/service that It looks like
class EventReportRepository #Inject constructor(
private val logServiceADataSource,
private val logServiceBDataSource
) {
suspend fun sendEvent(evt: String, args: Map<String,String>)
}
Many layers may call this module, such as DataSource, Repository, Domain, ViewMode, Presenter.
My question is, Where is the best position for this module? How to reference it for other layers?

If a module is called from many layers, it would make sense to put it in a separate "core" folder
|--> lib/
|--> core/
| |--> utility/
| | |--> common_module_a/
| | |--> common_module_b/
| | |...
| |--> ...
|--> features/
| |--> feature_a/
| | |--> data_source/
| | |--> repository/
| | |--> domain/
| | |--> view_mode/
| | |--> presenter/
| |--> feature_b/
| | |...
Note: I've seen people organise the features in the above way, but also with the layer folders being the top-level ones, containing feature sub-folder for each layer:
|...
|--> layers/
|--> data_source/
| |--> feature_a/
| |--> feature_b/
|--> repository/
| |--> feature_a/
| |--> feature_b/
|--> ...
In any case, unlike the features/layers folders, I don't believe there's a hard and fast rule on how to organise the core folder. It will really be case-dependent. It may contain:
modules that are used throughout the layers (like your example)
contracts that enforce clean architecture (abstract repository/datasoruce classes, etc.)
Here's an example of such an organisation.

Related

what does Spring Boot multiple modules project's classpath look like?

I am developing a multi-modules project with Spring Boot, and it always confuse me that what does its class path look like .
My project looks like this:
project
|-- module1
| |-- src
| | `-- main
| | |-- java
| | `-- resources
| | |-- /params/applicationContext.xml
| |
| `-- pom.xml
|-- module2
| |-- src
| | `-- main
| | |-- java
| | | `--GetPropertyUtils.java
| | `-- resources
| | `-- /params/batch-jobs.xml
| `-- pom.xml
If Module1 is my web module and module2 is a CommonUtil module,
When the server is started, are two property files(batch-jobs.xml and applicationContext.xml)' classpath the same(which are /resources/params)?
Ist there any document I can learn from?

How are NuGet repos organized?

I decided to push a .NET Standard class library to an existing local NuGet repo at my workplace.
I did it by having the NuGet package automatically pushed after the build in Visual Studio:
nuget push [PACKAGE_FILENAME] -Source [REPO_ON_THE_NETWORK]
Prior to my push, there were 3 pre-existing packages for other projects in the repo. After my push, the only project visible - via the NuGet Package Manager UI in Visual Studio - was the one I just pushed. I can consume my project from the NuGet repo without issues.
I took a look in the folder itself on the network, and this is what I saw:
[ ] Repo
|
|_ [ ] Proj1
| |
| |_ [ ] v1.0.0
| | |
| | |_ [ ] lib
| | | |
| | | |_ [ ] net20
| | | | |
| | | | |_ .dll
| | | | |_ .pdb
| | | |
| | | |_ [ ] net46
| | | |
| | | |_ .dll
| | | |_ .pdb
| | |
| | |_ .nupkg
| | |_ .nupkg.sha512
| | |_ .nuspec
| |
| |_ [ ] v1.0.1
| |
| |_ .nupkg
| |_ .nupkg.sha512
| |_ .nuspec
|
|_ [ ] MyRecentlyPushedProj
|
|_ .nupkg
I have three questions:
Why are the folder's organized in such different ways? Notice how one folder has a sub-folder with the actual project binaries, while the others don't. Also notice how my recently-pushed project lacks everything except for the NuGet package file.
When we manually delete the recently-pushed project from the repo, then the old projects reappear in the NuGet Package Manager UI. Does having differently-organized folders mess with NuGet's ability to scan the repo? Has the way NuGet organizes the projects changed over time (with newer versions)?
How am I able to consume the recently-pushed project successfully without the folder containing any of the binaries?
From the hierarchy tree you drew, I can see some differences:
Your package doesn't come with a version.
Your package doesn't have a lib folder.
Now, there are two ways of publishing a NuGet package with NuGet CLI: push and add.
The main difference is that add is for non-HTTP package source (as stated on MSDN) and that it publishes the package in a hierarchic manner, while push doesn't always (and it usually depends on how the feed was initialized).
My recommendation is that you check the documentation I added, and based on that decide whether to use one command or the other. From what I can gather, you should use add.
Hope this helps.

child module not found in maven multi project execution

I created two projects(PROJECT-1,PROJECT-2) in the directory and i would like to execute both the projects in one click for that i create another project(PROJECT-3) in the directory and present these two projects((PROJECT-1,PROJECT-2) as modules and define packaging as pom Here i am using modules concept.
<modules>
<module>D:/20-6-2014/PROJECT-1</module>
<module>D:/20-6-2014/PROJECT-2</module>
</module>
I define the PROJECT-3 as parent for both the projects,while i run the PROJECT-3 it gives an error.
Error is: Child module D:\20-6-2014\PROJECT-3\PROJECT-1 of
D:\20-6-2014\PROJECT-3\POM.XML does not exist.
your directory structure should be like as follows PROJECT-3 is your parent project for PROJECT-1 and PROJECT-2
|
|
----PROJECT-3
|
|
----pom.xml
|
|
----PROJECT-1
| |
| |
| ------pom.xml
----PROJECT-2
|
|
-------pom.xml
and PROJECT-3's pom.xml should have
<modules>
<module>PROJECT-1</module>
<module>PROJECT-2</module>
</module>

Step definition from multiple files for same scenario

I have a scenario where its step definitions resides in multiple files. For instance the login step resides in login_steps.rb and a search related step resides in search_steps.rb
Cucumber outputs undefined steps for any step that is not in login_steps.rb. The step definitions are run only when its present in login_steps.rb. Is it required to place all the step definitions of a scenario in the same file?
My folder structure
Project folder
└─ features
├─ pages
├─ scenarios
├─ step_definitions
└─ support
Command I used:
cucumber -r features features\scenarios\Test.feature
The whole point to Cucumber and the POM is that you have flexibility and do not need to re-write your steps per feature file. This is what my directory structure looks like:
Root
- features
- step_definitions
- step_definition.rb
- support
- env.rb
- lib
- BasePage.rb
- feature.feature
Basically, with this directory structure, it doesn't matter where your step definitions are AS LONG AS YOU REQUIRE THE SPECIFIC PAGE YOU'RE REFERENCING (your BasePage.rb file, for example)
require File.join(File.dirname(__FILE__), '..', '..', 'lib', 'pages', 'BasePage')
And /^I do something$/ do
#page = BasePage.new(#test_env)
#page.verify_el(css)
end
I'm not familiar with the specifics of RoR and cucumber, but I do use cucumber-jvm. Using steps from different files is supported. Note the documentation https://github.com/cucumber/cucumber/wiki/Cucumber-Backgrounder#where-do-i-put-tests specifically mentions it.
Sorry I can't be more help with the specific issue, but what you are trying to do (use step from different files) is workable.
This might be a "violation" but I would combine the answers from Whitney Imura and Dave W just to make the answer more clear...
You ask:
"Is it required to place all the step
definitions of a scenario in the same file?"
No. You can place your step definitions in logically distinct files within various folders, as you see fit (example below). After all, it is just ruby code.
Essentially Your command is correct for running an individual feature that has step definitions in various other folders...
cucumber -r features features\entities\entity.feature
If you do not run it as above, you will get missing stepdefs... Here I execute tests on a current project as a means to demonstrate:
cucumber
60 scenarios (14 undefined, 46 passed)
409 steps (32 skipped, 26 undefined, 351 passed)
cucumber -r features
60 scenarios (60 passed)
409 steps (409 passed)
As described in the Cucumber documentation, you can arrange your tests to suite your logical breakdown of your features:
|__ features
| |__ entities
| | |__ entity.feature
| | |__ step_definitions
| | |__ anything.rb
| | |__ entity_steps.rb
| |__ locations
| | |__ location.feature
| | |__ step_definitions
| | |__location_steps.rb
| |__ sites
| | |__ step_definitions
| |__ step_definitions
| | |__ local_assert_steps.rb
| | |__ local_crud_response_steps.rb
| | |__ local_email_steps.rb
| | |__ local_file_steps.rb
| | |__ local_script_steps.rb
| | |__ local_steps.rb
| | |__ local_web_steps.rb
` | |__ local_xml_file_steps.rb
|__ support
|__ env.rb
|__ local_env.rb
|__ local_transforms.rb

Create a war containing only image

I'm trying to create a war that is to be deployed in an EAR and that should contain only images.
My war source organization is as follows :
+---src
| +---main
| | +---java
| | +---resources
| | | \---META-INF
| | | \---resources
| | | \---images
| | | placeholder_image.jpg
| | | placeholder_template.png
| | |
| | \---webapp
| | \---WEB-INF
| \---test
| +---java
| \---resources
and my war effective organization is
+---META-INF
\---WEB-INF
\---classes
\---META-INF
\---resources
\---images
placeholder_image.jpg
placeholder_template.png
The images I want to serve are in the src/main/resources/META-INF/resources/images folder.
I package this war using maven-war-plugin.
Under which url will those images be available on my local machine, provided my war is indicated as available under the http://localhost:8080/myapp/ path ?
None. Content from WEB-INF is not statically served, resources is for classpath resources. You need to put the images (folder) directly under webapp or add an servlet that serves the content.
This depends on whether you deploy the war in a Servlet-3-compatible container like Tomcat 7 or Jetty 8.
If so, your resources should be visible under http://localhost:8080/myapp/images/....
See also this post, where the only difference is that the resources are packaged in a jar. For jars, this feature makes more sense than for WEB-INF/classes, as, like the first answer points out, you should simply put your resources directly into src/main/webapp if they are located in the same Maven module.

Resources