-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
grooming, bugfixing, and some javadoc
- Loading branch information
Showing
31 changed files
with
413 additions
and
49 deletions.
There are no files selected for viewing
6 changes: 6 additions & 0 deletions
6
photoalbum-common/src/main/java/com/mgu/photoalbum/exception/PhotoalbumException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,11 @@ | ||
package com.mgu.photoalbum.exception; | ||
|
||
/** | ||
* This is the base exception type for all exceptions within the photoalbum service. It provides the | ||
* means to retain the cause (if there is any) as well as an error message and an error code. | ||
* | ||
* @author Markus Günther ([email protected]) | ||
*/ | ||
abstract public class PhotoalbumException extends RuntimeException { | ||
|
||
private static final long serialVersionUID = -8563374709814927511L; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,11 @@ | |
import java.io.InputStream; | ||
import java.util.Base64; | ||
|
||
/** | ||
* Provides some convenience methods to handle {@link InputStream}. | ||
* | ||
* @author Markus Günther ([email protected]) | ||
*/ | ||
public class InputStreamAdapter { | ||
|
||
public InputStream getBase64DecodingInputStream(final String base64EncodedData) { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,10 +14,27 @@ | |
import java.nio.file.Path; | ||
import java.nio.file.StandardCopyOption; | ||
|
||
/** | ||
* Provides the means to handle basic I/O using {@link Path}. | ||
* | ||
* @author Markus Günther ([email protected]) | ||
*/ | ||
public class PathAdapter { | ||
|
||
private static final Logger LOGGER = LoggerFactory.getLogger(PathAdapter.class); | ||
|
||
/** | ||
* Reads the contents of the file located at {@code Path} and returns them as | ||
* byte array. | ||
* | ||
* @param path | ||
* refers to a location on the filesystem | ||
* @throws UnableToReadFromFilesystemException | ||
* in case the read operation fails | ||
* @return | ||
* {@code byte[]} array containing all the bytes that were read from | ||
* the file located at the given {@code Path} | ||
*/ | ||
public byte[] readBytes(final Path path) { | ||
try { | ||
return convertToBytes(Files.newInputStream(path)); | ||
|
@@ -26,19 +43,6 @@ public byte[] readBytes(final Path path) { | |
} | ||
} | ||
|
||
/** | ||
* Reads in all bytes from the given {@link InputStream} and returns them as | ||
* byte array. | ||
* | ||
* @param in | ||
* Represents the {@link InputStream} from which to read | ||
* @throws IOException | ||
* In case reading from the given {@link InputStream} raises an | ||
* {@link IOException} | ||
* @return | ||
* <code>byte[]</code> array containing all the bytes that were | ||
* read from the given {@link InputStream} | ||
*/ | ||
private byte[] convertToBytes(final InputStream in) throws IOException { | ||
try { | ||
return IOUtils.toByteArray(in); | ||
|
@@ -50,6 +54,17 @@ private byte[] convertToBytes(final InputStream in) throws IOException { | |
} | ||
} | ||
|
||
/** | ||
* Reads the contents of the file located at {@code Path} as String (binary-safe). | ||
* | ||
* @param path | ||
* refers to a location on the filesystem | ||
* @throws UnableToReadFromFilesystemException | ||
* in case the read operation fails | ||
* @return | ||
* the contents of the file located at the given {@code Path} in form | ||
* of a binary-safe {@link String} | ||
*/ | ||
public String readString(final Path path) { | ||
try { | ||
return convertToString(Files.newInputStream(path)); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,13 @@ | |
|
||
import com.mgu.photoalbum.exception.PhotoalbumException; | ||
|
||
/** | ||
* This exception is raised whenever a copy operation to the filesystem (from any I/O resource) or to a | ||
* different location on the filesystem fails. Causes for this are manifold. Thus, the root cause is retained | ||
* with this exception. | ||
* | ||
* @author Markus Günther ([email protected]) | ||
*/ | ||
public class UnableToCopyFileException extends PhotoalbumException { | ||
|
||
private static final String ERROR_MESSAGE_ONLY_DESTINATION = "Unable to write data to %s."; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,12 @@ | |
|
||
import com.mgu.photoalbum.exception.PhotoalbumException; | ||
|
||
/** | ||
* This exception is raised when a Base64-decoding wrapper on an {@code InputStream} is unable | ||
* to decode the stream data properly. | ||
* | ||
* @author Markus Günther ([email protected]) | ||
*/ | ||
public class UnableToDecodeFromBase64Exception extends PhotoalbumException { | ||
|
||
private static final String ERROR_MESSAGE = "Unable to decode given Base64-encoded data."; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,13 @@ | |
|
||
import com.mgu.photoalbum.exception.PhotoalbumException; | ||
|
||
/** | ||
* This exception is raised if the service was unable to read a requested file from | ||
* the filesystem. The cause for this is is potentially manifold, so the root cause | ||
* is retained within this exception. | ||
* | ||
* @author Markus Günther ([email protected]) | ||
*/ | ||
public class UnableToReadFromFilesystemException extends PhotoalbumException { | ||
|
||
private static final String ERROR_MESSAGE = "Unable to read the contents of %s."; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,13 @@ | |
|
||
import com.mgu.photoalbum.exception.PhotoalbumException; | ||
|
||
/** | ||
* This exception is raised if the service was unable to write a given file | ||
* to the filesystem. The cause for this is potentially manifold, so the root | ||
* cause is retained with this exception. | ||
* | ||
* @author Markus Günther ([email protected]) | ||
*/ | ||
public class UnableToWriteToFilesystemException extends PhotoalbumException { | ||
|
||
private static final String ERROR_MESSAGE = "Unable to write to filesystem (path was %s)."; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,6 +10,15 @@ | |
import org.joda.time.DateTime; | ||
import org.joda.time.DateTimeZone; | ||
|
||
/** | ||
* A {@code Album} is a managed resource that has been created by user (referred to as owner) and | ||
* contains {@link Photo}s. This association is inversely implemented within the system: Photos know | ||
* to which albums they belong to. | ||
* | ||
* Only owners are granted the right to access their albums and perform modifications on it. | ||
* | ||
* @author Markus Günther ([email protected]) | ||
*/ | ||
public class Album extends Document { | ||
|
||
public static final String DOCUMENT_TYPE = "album"; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,6 +15,19 @@ | |
import java.util.List; | ||
import java.util.stream.Collectors; | ||
|
||
/** | ||
* A {@code Photo} is a managed resource that has been created by a user (referred to | ||
* as the owner) and belongs to an existing {@link Album}. Its lifetime is bound to the | ||
* lifetime of the {@link Album} it belongs to. As such, if the corresponding {@link Album} | ||
* is deleted, all its containing photos are as well. | ||
* | ||
* A {@code Photo} can be tagged. | ||
* | ||
* Only owners are granted the right to access their photo and perform modifications | ||
* on it. | ||
* | ||
* @author Markus Günther ([email protected]) | ||
*/ | ||
public class Photo extends Document { | ||
|
||
public static final String DOCUMENT_TYPE = "photo"; | ||
|
28 changes: 27 additions & 1 deletion
28
photoalbum-management/src/main/java/com/mgu/photoalbum/service/AlbumCommandService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,34 @@ | ||
package com.mgu.photoalbum.service; | ||
|
||
/** | ||
* {@code AlbumCommandService} provides the means to create and delete domain objects of type {@code Album}. | ||
* This service does not determine if a command is authorized. Clients of this class must ensure that the | ||
* requested command is admissible. | ||
* | ||
* @author Markus Günther ([email protected]) | ||
*/ | ||
public interface AlbumCommandService { | ||
|
||
/** | ||
* Creates a new album with the provided metadata. | ||
* | ||
* @param ownerId | ||
* represents the ID of the user that requested to create the album | ||
* @param title | ||
* represents the title of the album | ||
* @return | ||
* unique ID that is identifies the newly created album | ||
*/ | ||
String createAlbum(String ownerId, String title); | ||
|
||
void deleteAlbum(String id); | ||
/** | ||
* Deletes the album identified by the given {@code albumId}. Implementing classes must ensure | ||
* that this method also deletes all photos that are associated with the album. Implementing | ||
* classes may handle a non-existing album as good case, since the system already has reached | ||
* a convergent stace with regard to a missing album (this should not raise an error). | ||
* | ||
* @param albumId | ||
* Uniquely identifies an album | ||
*/ | ||
void deleteAlbum(String albumId); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,11 @@ | |
|
||
import com.mgu.photoalbum.exception.PhotoalbumException; | ||
|
||
/** | ||
* The requested album does not exist. | ||
* | ||
* @author Markus Günther ([email protected]) | ||
*/ | ||
public class AlbumDoesNotExistException extends PhotoalbumException { | ||
|
||
private static final String ERROR_MESSAGE = "An album for the given album ID %s does not exist."; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,9 +4,34 @@ | |
|
||
import java.util.List; | ||
|
||
/** | ||
* {@code AlbumQueryService} provides the means to lookup {@link Album}s by their ID or search for them. | ||
* | ||
* @author Markus Günther ([email protected]) | ||
*/ | ||
public interface AlbumQueryService { | ||
|
||
Album albumById(final String id); | ||
/** | ||
* Retrieves the {@link Album} identified by the given ID. | ||
* | ||
* @param albumId | ||
* Uniquely identifies an {@link Album} within the system | ||
* @throws AlbumDoesNotExistException | ||
* in case the ID refers to a non-existing album | ||
* @return | ||
* {@link Album} identified by the given ID | ||
*/ | ||
Album albumById(final String albumId); | ||
|
||
/** | ||
* Performs a search request using the provided search parameters encoded with | ||
* {@link AlbumSearchRequest}. | ||
* | ||
* @param searchRequest | ||
* data holder which is used to parameterize the search for albums | ||
* @return | ||
* Instance of {@link AlbumSearchResult} which holds the search results | ||
* and retains the search parameters that led to those results | ||
*/ | ||
AlbumSearchResult search(final AlbumSearchRequest searchRequest); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,11 @@ | |
|
||
import org.apache.commons.lang3.StringUtils; | ||
|
||
/** | ||
* Container for Album-related search parameters. | ||
* | ||
* @author Markus Günther ([email protected]) | ||
*/ | ||
public class AlbumSearchRequest { | ||
|
||
public static class AlbumSearchRequestBuilder { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,11 @@ | |
|
||
import com.mgu.photoalbum.exception.PhotoalbumException; | ||
|
||
/** | ||
* The requested image within the image archive does not exist. | ||
* | ||
* @author Markus Günther ([email protected]) | ||
*/ | ||
public class ImageDoesNotExistException extends PhotoalbumException { | ||
|
||
private static final String ERROR_MESSAGE = "The image file for photo with ID %s does not exist on the filesystem."; | ||
|
Oops, something went wrong.