Skip to content

Commit

Permalink
some modules, some domain logic, much adapters
Browse files Browse the repository at this point in the history
  • Loading branch information
mguenther committed Oct 8, 2015
1 parent 2b39d82 commit 4667257
Show file tree
Hide file tree
Showing 52 changed files with 3,273 additions and 3 deletions.
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Created by .ignore support plugin (hsz.mobi)
.idea
photoalbum-webapp/photoalbum-webapp.iml
photoalbum.iml
photoalbum-couchdb-adapter/photoalbum-couchdb-adapter.iml
photoalbum-management/photoalbum-management.iml
photoalbum-common/photoalbum-common.iml
photoalbum-fileio-adapter/photoalbum-fileio-adapter.iml
28 changes: 28 additions & 0 deletions photoalbum-common/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<project xmlns="https://maven.apache.org/POM/4.0.0" xmlns:xsi="https://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="https://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>photoalbum</artifactId>
<groupId>com.mgu.photoalbum</groupId>
<version>0.1.0</version>
</parent>
<modelVersion>4.0.0</modelVersion>

<artifactId>photoalbum-common</artifactId>
<packaging>jar</packaging>

<name>photoalbum-common</name>
<url>https://maven.apache.org</url>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.mgu.photoalbum.exception;

abstract public class PhotoalbumException extends RuntimeException {

private static final long serialVersionUID = -8563374709814927511L;

public PhotoalbumException(final String message) {
super(message);
}

public PhotoalbumException(final Throwable cause) {
super(cause);
}

public PhotoalbumException(final String message, final Throwable cause) {
super(message, cause);
}

abstract public String getErrorCode();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
package com.mgu.photoalbum.identity;

/**
* IDs are generally generated at the server-side upon client request over the alphabet [A-Za-z0-9]. This
* generator can be parameterized with an optional prefix and a length that the generated ID must adhere
* to.
*
* Most of the properties of strong passwords should be applied to IDs as well. Some IDs - for instance user IDs -
* should have a high level of entropy. With regard to strong passwords, NIST recommends an entropy of at least
* 78 bits. If we apply this recommendation to an ID within the context of the given the alphabet [A-Za-z0-9], a minimum
* length of 14 characters is advised. Thus, if the caller does not supply the length parameter, the default
* length is exactly 14 characters.
*
* @author Markus Günther ([email protected])
*/
public class IdGenerator {

private static final String ALPHABET = "ABCDEFGHIJKLMNOPQRSTUVW" + "ABCDEFGHIJKLMNOPQRSTUVW".toLowerCase() + "0123456789";

private static final String WITHOUT_PREFIX = "";

private static final int DEFAULT_LENGTH = 14;

public String generateId() {
return generateId(WITHOUT_PREFIX, DEFAULT_LENGTH);
}

public String generateId(final int length) {
return generateId(WITHOUT_PREFIX, length);
}

public String generateId(final String prefix) {
return generateId(prefix, DEFAULT_LENGTH);
}

/**
* Generates an ID that adheres to the given parameters {@code prefix} and {@code length}. The prefix
* segment is separated using a '-' from the randomized segment.
*
* Example: Given the prefix 'CU' and a target length of 5, the ID 'CU-AbjEk' would be in the language
* that both parameters span in conjunction with the alphabet.
*
* @param prefix
* Optional prefix for the ID
* @param length
* Length of the randomized segment
* @return
* Generated ID with an optional prefix segment followed by a randomized segment, where both segments
* are delimited by a dash ('-')
*/
public String generateId(final String prefix, final int length) {

final StringBuilder sb = new StringBuilder();

if (!prefix.equals(WITHOUT_PREFIX)) {
sb.append(prefix).append("-");
}

for (int i = 0; i < length; i++) {
final int randomIndex = (int) (Math.random() * ALPHABET.length());
sb.append(ALPHABET.charAt(randomIndex));
}

return sb.toString();
}
}
52 changes: 52 additions & 0 deletions photoalbum-couchdb-adapter/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<project xmlns="https://maven.apache.org/POM/4.0.0" xmlns:xsi="https://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="https://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">

<modelVersion>4.0.0</modelVersion>

<parent>
<artifactId>photoalbum</artifactId>
<groupId>com.mgu.photoalbum</groupId>
<version>0.1.0</version>
</parent>

<artifactId>photoalbum-couchdb-adapter</artifactId>
<packaging>jar</packaging>

<name>[photoalbum] CouchDB Adapter</name>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<dependencies>
<dependency>
<groupId>org.ektorp</groupId>
<artifactId>org.ektorp</artifactId>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
</dependency>
<dependency>
<groupId>joda-time</groupId>
<artifactId>joda-time</artifactId>
</dependency>
<!-- Test -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-core</artifactId>
<version>${hamcrest.version}</version>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-all</artifactId>
<version>${mockito.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
Loading

0 comments on commit 4667257

Please sign in to comment.