From 5c83a754879bb8be7d0433c582e6eb4029793687 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Markus=20G=C3=BCnther?= Date: Sat, 10 Oct 2015 03:05:34 +0200 Subject: [PATCH] renaming of stuff, fixed dependency conflicts between ektorp and dropwizard, wired everything --- photoalbum-common/pom.xml | 4 +- photoalbum-management/pom.xml | 3 +- photoalbum-security/pom.xml | 3 +- photoalbum-webapp/pom.xml | 5 -- .../src/main/config/development.properties | 21 ++++++ .../src/main/config/integration.properties | 21 ++++++ .../src/main/config/production.properties | 21 ++++++ .../mgu/photoalbum/PhotoalbumApplication.java | 2 - .../mgu/photoalbum/config/DatabaseModule.java | 36 --------- .../photoalbum/config/PhotoalbumConfig.java | 12 --- .../mgu/photoalbum/config/ServiceModule.java | 75 ++++++++++++++++++- ...nverter.java => GalleryReprConverter.java} | 4 +- .../photoalbum/resource/AlbumsResource.java | 6 +- .../mgu/photoalbum/resource/LinkScheme.java | 3 + .../src/main/resources/banner.txt | 12 +++ .../src/main/resources/config.yml | 50 +++++++++++++ 16 files changed, 208 insertions(+), 70 deletions(-) create mode 100644 photoalbum-webapp/src/main/config/development.properties create mode 100644 photoalbum-webapp/src/main/config/integration.properties create mode 100644 photoalbum-webapp/src/main/config/production.properties delete mode 100644 photoalbum-webapp/src/main/java/com/mgu/photoalbum/config/DatabaseModule.java rename photoalbum-webapp/src/main/java/com/mgu/photoalbum/converter/{GalleryConverter.java => GalleryReprConverter.java} (91%) create mode 100644 photoalbum-webapp/src/main/resources/banner.txt create mode 100644 photoalbum-webapp/src/main/resources/config.yml diff --git a/photoalbum-common/pom.xml b/photoalbum-common/pom.xml index d3f84c7..1b85d9d 100644 --- a/photoalbum-common/pom.xml +++ b/photoalbum-common/pom.xml @@ -10,8 +10,7 @@ photoalbum-common jar - photoalbum-common - http://maven.apache.org + [photoalbum] Common UTF-8 @@ -21,7 +20,6 @@ junit junit - 3.8.1 test diff --git a/photoalbum-management/pom.xml b/photoalbum-management/pom.xml index 4988e19..2a7b669 100644 --- a/photoalbum-management/pom.xml +++ b/photoalbum-management/pom.xml @@ -10,8 +10,7 @@ photoalbum-management jar - photoalbum-management - http://maven.apache.org + [photoalbum] Asset Management UTF-8 diff --git a/photoalbum-security/pom.xml b/photoalbum-security/pom.xml index e9d0ce0..41595c6 100644 --- a/photoalbum-security/pom.xml +++ b/photoalbum-security/pom.xml @@ -10,8 +10,7 @@ photoalbum-security jar - photoalbum-security - http://maven.apache.org + [photoalbum] Security Component UTF-8 diff --git a/photoalbum-webapp/pom.xml b/photoalbum-webapp/pom.xml index dc1c472..caf5911 100644 --- a/photoalbum-webapp/pom.xml +++ b/photoalbum-webapp/pom.xml @@ -188,11 +188,6 @@ com.hubspot.dropwizard dropwizard-guice - - - org.ektorp - org.ektorp - junit diff --git a/photoalbum-webapp/src/main/config/development.properties b/photoalbum-webapp/src/main/config/development.properties new file mode 100644 index 0000000..caafdef --- /dev/null +++ b/photoalbum-webapp/src/main/config/development.properties @@ -0,0 +1,21 @@ +connector.type=http +connector.port=8080 + +database.url=http://localhost:5984 +database.name=test-photoalbum +database.user= +database.password= + +photoalbum.archive.path=archive +photoalbum.caching.max_age=864000 + +log.file=logs/photoalbum-service.log +log.archive_logs=false +log.archived_file=logs/photoalbum-service-%d{yyyy-MM-dd}-%i.log.gz +log.max_archived_logs=7 +log.level=DEBUG + +log.request.file=logs/photoalbum-access.log +log.request.archive_logs=false +log.request.archived_file=logs/photoalbum-access-%d{yyyy-MM-dd}-%i.log.gz +log.request.max_archived_logs=7 \ No newline at end of file diff --git a/photoalbum-webapp/src/main/config/integration.properties b/photoalbum-webapp/src/main/config/integration.properties new file mode 100644 index 0000000..caafdef --- /dev/null +++ b/photoalbum-webapp/src/main/config/integration.properties @@ -0,0 +1,21 @@ +connector.type=http +connector.port=8080 + +database.url=http://localhost:5984 +database.name=test-photoalbum +database.user= +database.password= + +photoalbum.archive.path=archive +photoalbum.caching.max_age=864000 + +log.file=logs/photoalbum-service.log +log.archive_logs=false +log.archived_file=logs/photoalbum-service-%d{yyyy-MM-dd}-%i.log.gz +log.max_archived_logs=7 +log.level=DEBUG + +log.request.file=logs/photoalbum-access.log +log.request.archive_logs=false +log.request.archived_file=logs/photoalbum-access-%d{yyyy-MM-dd}-%i.log.gz +log.request.max_archived_logs=7 \ No newline at end of file diff --git a/photoalbum-webapp/src/main/config/production.properties b/photoalbum-webapp/src/main/config/production.properties new file mode 100644 index 0000000..17b5a49 --- /dev/null +++ b/photoalbum-webapp/src/main/config/production.properties @@ -0,0 +1,21 @@ +connector.type=http +connector.port=8080 + +database.url=http://localhost:5984 +database.name=photoalbum +database.user= +database.password= + +receipt.archive.path=/opt/app/photoalbum/archive +receipt.caching.max_age=864000 + +log.file=/var/log/photoalbum/photoalbum-service.log +log.archive_logs=true +log.archived_file=/var/log/photoalbum/archive/photoalbum-service-%d{yyyy-MM-dd}-%i.log.gz +log.max_archived_logs=7 +log.level=INFO + +log.request.file=/var/log/photoalbum/photoalbum-access.log +log.request.archive_logs=true +log.request.archived_file=/var/log/photoalbum/archive/photoalbum-access-%d{yyyy-MM-dd}-%i.log.gz +log.request.max_archived_logs=7 \ No newline at end of file diff --git a/photoalbum-webapp/src/main/java/com/mgu/photoalbum/PhotoalbumApplication.java b/photoalbum-webapp/src/main/java/com/mgu/photoalbum/PhotoalbumApplication.java index ff6a62d..6aa6ad3 100644 --- a/photoalbum-webapp/src/main/java/com/mgu/photoalbum/PhotoalbumApplication.java +++ b/photoalbum-webapp/src/main/java/com/mgu/photoalbum/PhotoalbumApplication.java @@ -1,7 +1,6 @@ package com.mgu.photoalbum; import com.hubspot.dropwizard.guice.GuiceBundle; -import com.mgu.photoalbum.config.DatabaseModule; import com.mgu.photoalbum.config.ServiceConfig; import com.mgu.photoalbum.config.ServiceModule; import com.mgu.photoalbum.security.Principal; @@ -21,7 +20,6 @@ public class PhotoalbumApplication extends Application { public void initialize(final Bootstrap bootstrap) { this.guiceBundle = GuiceBundle.newBuilder() - .addModule(new DatabaseModule()) .addModule(new ServiceModule()) .setConfigClass(ServiceConfig.class) .enableAutoConfig(getClass().getPackage().getName()) diff --git a/photoalbum-webapp/src/main/java/com/mgu/photoalbum/config/DatabaseModule.java b/photoalbum-webapp/src/main/java/com/mgu/photoalbum/config/DatabaseModule.java deleted file mode 100644 index 9e50b27..0000000 --- a/photoalbum-webapp/src/main/java/com/mgu/photoalbum/config/DatabaseModule.java +++ /dev/null @@ -1,36 +0,0 @@ -package com.mgu.photoalbum.config; - -import com.google.inject.AbstractModule; -import com.google.inject.Provides; -import com.mgu.photoalbum.config.DatabaseConfig; -import com.mgu.photoalbum.config.ServiceConfig; -import org.ektorp.CouchDbConnector; -import org.ektorp.CouchDbInstance; -import org.ektorp.http.HttpClient; -import org.ektorp.http.StdHttpClient; -import org.ektorp.impl.StdCouchDbConnector; -import org.ektorp.impl.StdCouchDbInstance; - -public class DatabaseModule extends AbstractModule { - - @Provides - public CouchDbConnector provideConnection(final ServiceConfig config) { - final DatabaseConfig database = config.getDatabaseConfig(); - try { - final HttpClient httpClient = new StdHttpClient.Builder() - .url(database.getUrl()) - .connectionTimeout(1000) - .socketTimeout(1000) - .build(); - final CouchDbInstance dbInstance = new StdCouchDbInstance(httpClient); - return new StdCouchDbConnector(database.getName(), dbInstance); - } catch (Exception e) { - throw new RuntimeException(e); - } - } - - @Override - protected void configure() { - // TODO: Wire repositories! - } -} \ No newline at end of file diff --git a/photoalbum-webapp/src/main/java/com/mgu/photoalbum/config/PhotoalbumConfig.java b/photoalbum-webapp/src/main/java/com/mgu/photoalbum/config/PhotoalbumConfig.java index 2c98a4a..17de5b0 100644 --- a/photoalbum-webapp/src/main/java/com/mgu/photoalbum/config/PhotoalbumConfig.java +++ b/photoalbum-webapp/src/main/java/com/mgu/photoalbum/config/PhotoalbumConfig.java @@ -14,18 +14,6 @@ public class PhotoalbumConfig { @Range(min = 0) private int maxCacheAge; - @JsonProperty("hostname") - @NotEmpty - private String hostname; - - public String getHostname() { - return hostname; - } - - public void setHostname(final String hostname) { - this.hostname = hostname; - } - public String getImageArchivePath() { return imageArchivePath; } diff --git a/photoalbum-webapp/src/main/java/com/mgu/photoalbum/config/ServiceModule.java b/photoalbum-webapp/src/main/java/com/mgu/photoalbum/config/ServiceModule.java index 3e640fd..6154c5b 100644 --- a/photoalbum-webapp/src/main/java/com/mgu/photoalbum/config/ServiceModule.java +++ b/photoalbum-webapp/src/main/java/com/mgu/photoalbum/config/ServiceModule.java @@ -1,8 +1,15 @@ package com.mgu.photoalbum.config; import com.google.inject.AbstractModule; +import com.google.inject.Provides; import com.mgu.photoalbum.adapter.fileio.PathAdapter; +import com.mgu.photoalbum.converter.AlbumReprConverter; +import com.mgu.photoalbum.converter.AlbumShortReprConverter; +import com.mgu.photoalbum.converter.GalleryReprConverter; +import com.mgu.photoalbum.converter.PhotoMetadataReprConverter; +import com.mgu.photoalbum.converter.PhotoShortReprConverter; import com.mgu.photoalbum.identity.IdGenerator; +import com.mgu.photoalbum.resource.LinkScheme; import com.mgu.photoalbum.security.Authentication; import com.mgu.photoalbum.security.Authorization; import com.mgu.photoalbum.security.IdentityBasedAuth; @@ -15,9 +22,44 @@ import com.mgu.photoalbum.service.PhotoService; import com.mgu.photoalbum.service.scaler.ImageScaler; import com.mgu.photoalbum.service.scaler.ScalrImageScaler; +import com.mgu.photoalbum.storage.AlbumRepository; +import com.mgu.photoalbum.storage.PhotoRepository; +import com.mgu.photoalbum.user.UserQueryService; +import com.mgu.photoalbum.user.UserRepository; +import com.mgu.photoalbum.user.UserService; +import org.ektorp.CouchDbConnector; +import org.ektorp.CouchDbInstance; +import org.ektorp.http.HttpClient; +import org.ektorp.http.StdHttpClient; +import org.ektorp.impl.StdCouchDbConnector; +import org.ektorp.impl.StdCouchDbInstance; + +import javax.inject.Named; public class ServiceModule extends AbstractModule { + @Provides + @Named("pathToArchive") + public String provideImageArchive(final ServiceConfig configuration) { + return configuration.getPhotoalbumConfig().getImageArchivePath(); + } + + @Provides + public CouchDbConnector provideConnection(final ServiceConfig config) { + final DatabaseConfig database = config.getDatabaseConfig(); + try { + final HttpClient httpClient = new StdHttpClient.Builder() + .url(database.getUrl()) + .connectionTimeout(10000) + .socketTimeout(10000) + .build(); + final CouchDbInstance dbInstance = new StdCouchDbInstance(httpClient); + return new StdCouchDbConnector(database.getName(), dbInstance); + } catch (Exception e) { + throw new RuntimeException(e); + } + } + @Override protected void configure() { @@ -31,19 +73,46 @@ protected void configure() { bind(PathAdapter.class).toInstance(new PathAdapter()); + configureAssetManagement(); + configureUserManagement(); + configureSecurity(); + configureFacade(); + } + + private void configureAssetManagement() { bind(ImageScaler.class).to(ScalrImageScaler.class); bind(PhotoCommandService.class).to(PhotoService.class); bind(PhotoQueryService.class).to(PhotoService.class); bind(AlbumCommandService.class).to(AlbumService.class); bind(AlbumQueryService.class).to(AlbumService.class); + try { + bind(AlbumRepository.class).toConstructor(AlbumRepository.class.getConstructor(CouchDbConnector.class)); + bind(PhotoRepository.class).toConstructor(PhotoRepository.class.getConstructor(CouchDbConnector.class)); + } catch (NoSuchMethodException e) { + addError(e); + } + } - configureSecurity(); - - + private void configureUserManagement() { + bind(UserQueryService.class).to(UserService.class); + try { + bind(UserRepository.class).toConstructor(UserRepository.class.getConstructor(CouchDbConnector.class)); + } catch (NoSuchMethodException e) { + addError(e); + } } private void configureSecurity() { bind(Authentication.class).to(IdentityBasedAuth.class); bind(Authorization.class).to(IdentityBasedAuth.class); } + + private void configureFacade() { + bind(LinkScheme.class); + bind(AlbumReprConverter.class); + bind(AlbumShortReprConverter.class); + bind(GalleryReprConverter.class); + bind(PhotoMetadataReprConverter.class); + bind(PhotoShortReprConverter.class); + } } \ No newline at end of file diff --git a/photoalbum-webapp/src/main/java/com/mgu/photoalbum/converter/GalleryConverter.java b/photoalbum-webapp/src/main/java/com/mgu/photoalbum/converter/GalleryReprConverter.java similarity index 91% rename from photoalbum-webapp/src/main/java/com/mgu/photoalbum/converter/GalleryConverter.java rename to photoalbum-webapp/src/main/java/com/mgu/photoalbum/converter/GalleryReprConverter.java index ebd5e05..416c4e0 100644 --- a/photoalbum-webapp/src/main/java/com/mgu/photoalbum/converter/GalleryConverter.java +++ b/photoalbum-webapp/src/main/java/com/mgu/photoalbum/converter/GalleryReprConverter.java @@ -12,14 +12,14 @@ import java.util.List; import java.util.stream.Collectors; -public class GalleryConverter implements Converter, GalleryRepr> { +public class GalleryReprConverter implements Converter, GalleryRepr> { private final LinkScheme linkScheme; private final AlbumShortReprConverter albumConverter; @Inject - public GalleryConverter(final LinkScheme linkScheme, final AlbumShortReprConverter albumConverter) { + public GalleryReprConverter(final LinkScheme linkScheme, final AlbumShortReprConverter albumConverter) { this.linkScheme = linkScheme; this.albumConverter = albumConverter; } diff --git a/photoalbum-webapp/src/main/java/com/mgu/photoalbum/resource/AlbumsResource.java b/photoalbum-webapp/src/main/java/com/mgu/photoalbum/resource/AlbumsResource.java index 64c7876..6e1aaa3 100644 --- a/photoalbum-webapp/src/main/java/com/mgu/photoalbum/resource/AlbumsResource.java +++ b/photoalbum-webapp/src/main/java/com/mgu/photoalbum/resource/AlbumsResource.java @@ -3,7 +3,7 @@ import com.codahale.metrics.annotation.Timed; import com.google.inject.Inject; import com.mgu.photoalbum.converter.AlbumShortReprConverter; -import com.mgu.photoalbum.converter.GalleryConverter; +import com.mgu.photoalbum.converter.GalleryReprConverter; import com.mgu.photoalbum.representation.CreateAlbumRepr; import com.mgu.photoalbum.representation.GalleryRepr; import com.mgu.photoalbum.security.Authorization; @@ -28,7 +28,7 @@ public class AlbumsResource { private final LinkScheme linkScheme; - private final GalleryConverter galleryConverter; + private final GalleryReprConverter galleryConverter; @Inject public AlbumsResource( @@ -39,7 +39,7 @@ public AlbumsResource( this.commandService = commandService; this.authorization = authorization; this.linkScheme = new LinkScheme(); - this.galleryConverter = new GalleryConverter(linkScheme, new AlbumShortReprConverter(linkScheme)); + this.galleryConverter = new GalleryReprConverter(linkScheme, new AlbumShortReprConverter(linkScheme)); } @POST diff --git a/photoalbum-webapp/src/main/java/com/mgu/photoalbum/resource/LinkScheme.java b/photoalbum-webapp/src/main/java/com/mgu/photoalbum/resource/LinkScheme.java index 5d1a6be..4858efa 100644 --- a/photoalbum-webapp/src/main/java/com/mgu/photoalbum/resource/LinkScheme.java +++ b/photoalbum-webapp/src/main/java/com/mgu/photoalbum/resource/LinkScheme.java @@ -1,8 +1,11 @@ package com.mgu.photoalbum.resource; +import com.google.inject.Singleton; + import javax.ws.rs.core.UriBuilder; import java.net.URI; +@Singleton public class LinkScheme { private static final String GALLERY_URI_TEMPLATE = "/albums"; diff --git a/photoalbum-webapp/src/main/resources/banner.txt b/photoalbum-webapp/src/main/resources/banner.txt new file mode 100644 index 0000000..50447cf --- /dev/null +++ b/photoalbum-webapp/src/main/resources/banner.txt @@ -0,0 +1,12 @@ + + +██████╗ ██╗ ██╗ ██████╗ ████████╗ ██████╗ █████╗ ██╗ ██████╗ ██╗ ██╗███╗ ███╗ +██╔══██╗██║ ██║██╔═══██╗╚══██╔══╝██╔═══██╗██╔══██╗██║ ██╔══██╗██║ ██║████╗ ████║ +██████╔╝███████║██║ ██║ ██║ ██║ ██║███████║██║ ██████╔╝██║ ██║██╔████╔██║ +██╔═══╝ ██╔══██║██║ ██║ ██║ ██║ ██║██╔══██║██║ ██╔══██╗██║ ██║██║╚██╔╝██║ +██║ ██║ ██║╚██████╔╝ ██║ ╚██████╔╝██║ ██║███████╗██████╔╝╚██████╔╝██║ ╚═╝ ██║ +╚═╝ ╚═╝ ╚═╝ ╚═════╝ ╚═╝ ╚═════╝ ╚═╝ ╚═╝╚══════╝╚═════╝ ╚═════╝ ╚═╝ ╚═╝ + +_______________________________________________________________________________________ + (c) 2015, mgu + diff --git a/photoalbum-webapp/src/main/resources/config.yml b/photoalbum-webapp/src/main/resources/config.yml new file mode 100644 index 0000000..e351f19 --- /dev/null +++ b/photoalbum-webapp/src/main/resources/config.yml @@ -0,0 +1,50 @@ +photoalbum: + imageArchivePath: ${photoalbum.archive.path} + maxCacheAge: ${photoalbum.caching.max_age} + +database: + url: ${database.url} + name: ${database.name} + user: ${database.user} + password: ${database.password} + +server: + registerDefaultExceptionMappers: true + requestLog: + timeZone: UTC + appenders: + - type: console + - type: file + currentLogFilename: ${log.request.file} + threshold: ALL + archive: ${log.request.archive_logs} + archivedLogFilenamePattern: ${log.request.archived_file} + archivedFileCount: ${log.request.max_archived_logs} + applicationConnectors: + - type: ${connector.type} + port: ${connector.port} + +logging: + # This is the default level of all loggers. Admissible log levels are + # [OFF, ERROR, WARN, INFO, DEBUG, TRACE, ALL]. This log level should be + # higher than the log level for everything that resides under + # com.cream.webapp (to shut up overly gossipy frameworks / libraries) + level: INFO + # sets the log level for our webapp + loggers: + com.cream: ${log.level} + # define log appenders for various log channels (console, file) + appenders: + # log to console + - type: console + threshold: ALL + logFormat: "%-6level [%d{HH:mm:ss.SSS}] [%t] %logger{5} - %X{code} %msg %n" + # log to file + - type: file + threshold: ALL + logFormat: "%-6level [%d{HH:mm:ss.SSS}] [%t] %logger{5} - %X{code} %msg %n" + currentLogFilename: ${log.file} + archive: ${log.archive_logs} + archivedLogFilenamePattern: ${log.archived_file} + archivedFileCount: ${log.max_archived_logs} + timeZone: UTC \ No newline at end of file