-
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.
added bootstrapping module, removed obsolete path entries in Photo do…
…main class
- Loading branch information
Showing
10 changed files
with
264 additions
and
33 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -0,0 +1,39 @@ | ||
<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-bootstrap</artifactId> | ||
<packaging>jar</packaging> | ||
|
||
<name>[photoalbum] Bootstrapping</name> | ||
|
||
<properties> | ||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
</properties> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>com.mgu.photoalbum</groupId> | ||
<artifactId>photoalbum-user-management</artifactId> | ||
<version>${photoalbum.version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.mgu.photoalbum</groupId> | ||
<artifactId>photoalbum-management</artifactId> | ||
<version>${photoalbum.version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.mgu.photoalbum</groupId> | ||
<artifactId>photoalbum-couchdb-adapter</artifactId> | ||
<version>${photoalbum.version}</version> | ||
</dependency> | ||
</dependencies> | ||
</project> |
44 changes: 44 additions & 0 deletions
44
photoalbum-bootstrap/src/main/java/com/mgu/photoalbum/bootstrap/AlbumGenerator.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 |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package com.mgu.photoalbum.bootstrap; | ||
|
||
import com.mgu.photoalbum.domain.Album; | ||
import com.mgu.photoalbum.storage.AlbumRepository; | ||
import org.ektorp.CouchDbConnector; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
public class AlbumGenerator implements Generator { | ||
|
||
private final AlbumRepository repository; | ||
|
||
public AlbumGenerator(final CouchDbConnector connector) { | ||
this.repository = new AlbumRepository(connector); | ||
} | ||
|
||
@Override | ||
public void generate() { | ||
|
||
List<Album> albumsToCreate = new ArrayList<Album>() {{ | ||
|
||
final Album hamburg = Album.create().createdBy("CU-zkVDzWSctsEqqk").id("AL-zk3Dz0Sct9XccF").title("Hamburg 2014").build(); | ||
hamburg.associatePhoto("PH-aB34z0013t9XccF"); | ||
|
||
final Album jersey = Album.create().createdBy("CU-zkVDzWSctsEqqk").id("AL-vcdjke39svm292").title("Jersey 2014").build(); | ||
jersey.associatePhoto("PH-aBffzee1ddddccF"); | ||
|
||
add(hamburg); | ||
add(jersey); | ||
add(Album.create().createdBy("CU-pzgBftxNCMLXql").id("AL-392952409vadsj").title("Tara").build()); | ||
}}; | ||
|
||
for (Album album : albumsToCreate) { | ||
repository.add(album); | ||
System.out.println("Added album '" + album.getTitle() + "' with ID " + album.getId() + " to database."); | ||
} | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "Album Document Generator"; | ||
} | ||
} |
62 changes: 62 additions & 0 deletions
62
photoalbum-bootstrap/src/main/java/com/mgu/photoalbum/bootstrap/Bootstrap.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 |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package com.mgu.photoalbum.bootstrap; | ||
|
||
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 java.util.ArrayList; | ||
import java.util.List; | ||
|
||
public class Bootstrap implements Generator { | ||
|
||
private final List<Generator> generators = new ArrayList<>(); | ||
|
||
private final CouchDbConnector connector; | ||
|
||
public Bootstrap(final String databaseName) { | ||
connector = establishConnection(databaseName); | ||
generators.add(new UserGenerator(connector)); | ||
generators.add(new AlbumGenerator(connector)); | ||
generators.add(new PhotoGenerator(connector)); | ||
} | ||
|
||
private CouchDbConnector establishConnection(final String databaseName) { | ||
try { | ||
final HttpClient httpClient = new StdHttpClient.Builder() | ||
.url("https://localhost:5984") | ||
.connectionTimeout(1000) | ||
.socketTimeout(1000) | ||
.build(); | ||
final CouchDbInstance dbInstance = new StdCouchDbInstance(httpClient); | ||
return new StdCouchDbConnector(databaseName, dbInstance); | ||
} catch (Exception e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
|
||
@Override | ||
public void generate() { | ||
this.connector.createDatabaseIfNotExists(); | ||
for (Generator generator : this.generators) { | ||
System.out.println(); | ||
System.out.println("***************************************************************************"); | ||
System.out.println("** Running " + generator.toString()); | ||
System.out.println("***************************************************************************"); | ||
System.out.println(); | ||
generator.generate(); | ||
} | ||
} | ||
|
||
public static void main(String[] args) { | ||
try { | ||
final Bootstrap bootstrap = new Bootstrap("test-photoalbum"); | ||
bootstrap.generate(); | ||
} catch (Throwable t) { | ||
System.err.println("Caught exception: " + t.getMessage()); | ||
t.printStackTrace(System.err); | ||
} | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
photoalbum-bootstrap/src/main/java/com/mgu/photoalbum/bootstrap/Generator.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 |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package com.mgu.photoalbum.bootstrap; | ||
|
||
public interface Generator { | ||
|
||
void generate(); | ||
} |
55 changes: 55 additions & 0 deletions
55
photoalbum-bootstrap/src/main/java/com/mgu/photoalbum/bootstrap/PhotoGenerator.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 |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package com.mgu.photoalbum.bootstrap; | ||
|
||
import com.mgu.photoalbum.domain.Photo; | ||
import com.mgu.photoalbum.storage.PhotoRepository; | ||
import org.ektorp.CouchDbConnector; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Arrays; | ||
import java.util.List; | ||
|
||
public class PhotoGenerator implements Generator { | ||
|
||
private final PhotoRepository repository; | ||
|
||
public PhotoGenerator(final CouchDbConnector connector) { | ||
this.repository = new PhotoRepository(connector); | ||
} | ||
|
||
@Override | ||
public void generate() { | ||
|
||
List<Photo> photosToCreate = new ArrayList<Photo>() {{ | ||
|
||
add(Photo | ||
.create() | ||
.id("PH-aB34z0013t9XccF") | ||
.belongsTo("AL-zk3Dz0Sct9XccF") | ||
.createdBy("CU-zkVDzWSctsEqqk") | ||
.description("Blick auf den Hamburger Hafen") | ||
.originalFilename("DCIM02023424.jpg") | ||
.tag(Arrays.asList("hafen")) | ||
.build()); | ||
|
||
add(Photo | ||
.create() | ||
.id("PH-aBffzee1ddddccF") | ||
.belongsTo("AL-vcdjke39svm292") | ||
.createdBy("CU-zkVDzWSctsEqqk") | ||
.description("Vorbei am Greve de Lecq") | ||
.originalFilename("DCIM02023412.jpg") | ||
.tag(Arrays.asList("footpath")) | ||
.build()); | ||
}}; | ||
|
||
for (Photo photo : photosToCreate) { | ||
repository.add(photo); | ||
System.out.println("Added photo '" + photo.getDescription() + "' with ID " + photo.getId() + " to database."); | ||
} | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "Photo Document Generator"; | ||
} | ||
} |
55 changes: 55 additions & 0 deletions
55
photoalbum-bootstrap/src/main/java/com/mgu/photoalbum/bootstrap/UserGenerator.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 |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package com.mgu.photoalbum.bootstrap; | ||
|
||
import com.mgu.photoalbum.user.Status; | ||
import com.mgu.photoalbum.user.User; | ||
import com.mgu.photoalbum.user.UserRepository; | ||
import org.apache.commons.codec.digest.DigestUtils; | ||
import org.ektorp.CouchDbConnector; | ||
|
||
public class UserGenerator implements Generator { | ||
|
||
private final UserRepository userRepository; | ||
|
||
public UserGenerator(final CouchDbConnector connector) { | ||
this.userRepository = new UserRepository(connector); | ||
} | ||
|
||
@Override | ||
public void generate() { | ||
final User activeUser = new User(); | ||
activeUser.setId("CU-zkVDzWSctsEqqk"); | ||
activeUser.setFirstName("Max"); | ||
activeUser.setLastName("Mustermann"); | ||
activeUser.setHashedPassword(DigestUtils.sha1Hex("secret")); | ||
activeUser.setEmail("[email protected]"); | ||
activeUser.setStatus(Status.ACTIVE); | ||
|
||
final User pendingUser = new User(); | ||
pendingUser.setId("CU-pzgBftxNCMLXql"); | ||
pendingUser.setFirstName("Karla"); | ||
pendingUser.setLastName("Klempner"); | ||
pendingUser.setHashedPassword(DigestUtils.sha1Hex("secret")); | ||
pendingUser.setEmail("[email protected]"); | ||
pendingUser.setStatus(Status.PENDING); | ||
|
||
final User suspendedUser = new User(); | ||
suspendedUser.setId("CU-tSSQRBvYmbWGag"); | ||
suspendedUser.setFirstName("Dancing"); | ||
suspendedUser.setLastName("Denzell"); | ||
suspendedUser.setHashedPassword(DigestUtils.sha1Hex("secret")); | ||
suspendedUser.setEmail("[email protected]"); | ||
suspendedUser.setStatus(Status.SUSPENDED); | ||
|
||
userRepository.add(activeUser); | ||
System.out.println("Adding user document with ID " + activeUser.getId() + " to database."); | ||
userRepository.add(pendingUser); | ||
System.out.println("Adding user document with ID " + pendingUser.getId() + " to database."); | ||
userRepository.add(suspendedUser); | ||
System.out.println("Adding user document with ID " + suspendedUser.getId() + " to database."); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "User Document Generator"; | ||
} | ||
} |
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