Merge pull request 'feature/rename-to-maze' (#8) from feature/rename-to-maze into master
	
		
			
	
		
	
	
		
	
		
			All checks were successful
		
		
	
	
		
			
				
	
				continuous-integration/drone/push Build is passing
				
			
		
		
	
	
				
					
				
			
		
			All checks were successful
		
		
	
	continuous-integration/drone/push Build is passing
				
			Reviewed-on: #8
This commit is contained in:
		
						commit
						90088536ed
					
				
					 18 changed files with 206 additions and 175 deletions
				
			
		|  | @ -26,6 +26,8 @@ steps: | ||||||
|     environment: |     environment: | ||||||
|       REPO_TOKEN: |       REPO_TOKEN: | ||||||
|         from_secret: repo-token |         from_secret: repo-token | ||||||
|  |       REPO_TOKEN_OSSRH: | ||||||
|  |         from_secret: repo-token-ossrh | ||||||
|     commands: |     commands: | ||||||
|       - mvn -s maven-settings.xml deploy -DskipTests=true |       - mvn -s maven-settings.xml deploy -DskipTests=true | ||||||
|     when: |     when: | ||||||
|  | @ -41,7 +43,7 @@ steps: | ||||||
|       username: manuel |       username: manuel | ||||||
|       password: |       password: | ||||||
|         from_secret: docker-token |         from_secret: docker-token | ||||||
|       repo: gittr.ch/java/labyrinth |       repo: gittr.ch/java/a-maze-r | ||||||
|       tags: |       tags: | ||||||
|         - latest |         - latest | ||||||
|       dockerfile: docker/Dockerfile |       dockerfile: docker/Dockerfile | ||||||
|  | @ -59,7 +61,7 @@ steps: | ||||||
|       username: manuel |       username: manuel | ||||||
|       password: |       password: | ||||||
|         from_secret: docker-token |         from_secret: docker-token | ||||||
|       repo: gittr.ch/java/labyrinth |       repo: gittr.ch/java/a-maze-r | ||||||
|       tags: |       tags: | ||||||
|         - latest |         - latest | ||||||
|         - ${DRONE_TAG} |         - ${DRONE_TAG} | ||||||
|  |  | ||||||
|  | @ -1,2 +1 @@ | ||||||
| # labyrinth-server | # maze-server | ||||||
| 
 |  | ||||||
|  |  | ||||||
|  | @ -1,7 +1,7 @@ | ||||||
| FROM openjdk:17-slim | FROM openjdk:17-slim | ||||||
| 
 | 
 | ||||||
| COPY target/labyrinth-server-*.jar /app/ | COPY target/maze-server-*.jar /app/ | ||||||
| RUN rm /app/*-sources.jar | RUN rm /app/*-sources.jar | ||||||
| RUN mv /app/*.jar /app/app.jar | RUN mv /app/*.jar /app/app.jar | ||||||
| 
 | 
 | ||||||
| CMD java -Dfritteli.labyrinth.server.host=0.0.0.0 -Dfritteli.labyrinth.server.port=80 -jar /app/app.jar | CMD java -Dfritteli.maze.server.host=0.0.0.0 -Dfritteli.maze.server.port=80 -jar /app/app.jar | ||||||
|  |  | ||||||
|  | @ -8,5 +8,10 @@ | ||||||
|             <username>ci</username> |             <username>ci</username> | ||||||
|             <password>${env.REPO_TOKEN}</password> |             <password>${env.REPO_TOKEN}</password> | ||||||
|         </server> |         </server> | ||||||
|  |         <server> | ||||||
|  |             <id>ossrh</id> | ||||||
|  |             <username>fritteli</username> | ||||||
|  |             <password>${env.REPO_TOKEN_OSSRH}</password> | ||||||
|  |         </server> | ||||||
|     </servers> |     </servers> | ||||||
| </settings> | </settings> | ||||||
|  |  | ||||||
							
								
								
									
										163
									
								
								pom.xml
									
										
									
									
									
								
							
							
						
						
									
										163
									
								
								pom.xml
									
										
									
									
									
								
							|  | @ -1,31 +1,28 @@ | ||||||
| <?xml version="1.0" encoding="UTF-8"?> | <?xml version="1.0" encoding="UTF-8"?> | ||||||
| <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||||||
|  |          xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||||||
|     <modelVersion>4.0.0</modelVersion> |     <modelVersion>4.0.0</modelVersion> | ||||||
| 
 | 
 | ||||||
|     <parent> |     <parent> | ||||||
|         <groupId>ch.fritteli</groupId> |         <groupId>ch.fritteli</groupId> | ||||||
|         <artifactId>fritteli-build-parent</artifactId> |         <artifactId>fritteli-build-parent</artifactId> | ||||||
|         <version>2.0.4</version> |         <version>5.0.0</version> | ||||||
|     </parent> |     </parent> | ||||||
| 
 | 
 | ||||||
|     <groupId>ch.fritteli.labyrinth</groupId> |     <groupId>ch.fritteli.a-maze-r</groupId> | ||||||
|     <artifactId>labyrinth-server</artifactId> |     <artifactId>maze-server</artifactId> | ||||||
|     <version>0.0.7-SNAPSHOT</version> |     <version>0.0.7-SNAPSHOT</version> | ||||||
|     <description>The Labyrinth server, offering a REST endpoint to access the Labyrinth Generator.</description> |  | ||||||
|     <url>https://manuel.friedli.info/labyrinth.html</url> |  | ||||||
| 
 | 
 | ||||||
|     <properties> |     <description>The A-Maze-R server, offering a REST endpoint to access the Maze Generator.</description> | ||||||
|         <java.source.version>17</java.source.version> |     <url>https://manuel.friedli.info/maze.html</url> | ||||||
|         <java.target.version>17</java.target.version> |     <inceptionYear>2022</inceptionYear> | ||||||
|         <jetbrains-annotations.version>24.0.1</jetbrains-annotations.version> | 
 | ||||||
|         <junit-jupiter.version>5.9.2</junit-jupiter.version> |     <licenses> | ||||||
|         <labyrinth-generator.version>0.0.8</labyrinth-generator.version> |         <license> | ||||||
|         <logback.version>1.4.6</logback.version> |             <name>GNU Affero General Public License</name> | ||||||
|         <lombok.version>1.18.26</lombok.version> |             <url>https://www.gnu.org/licenses/agpl-3.0.html</url> | ||||||
|         <slf4j.version>2.0.7</slf4j.version> |         </license> | ||||||
|         <undertow.version>2.3.5.Final</undertow.version> |     </licenses> | ||||||
|         <vavr.version>0.10.4</vavr.version> |  | ||||||
|     </properties> |  | ||||||
| 
 | 
 | ||||||
|     <developers> |     <developers> | ||||||
|         <developer> |         <developer> | ||||||
|  | @ -43,11 +40,32 @@ | ||||||
|         </developer> |         </developer> | ||||||
|     </developers> |     </developers> | ||||||
| 
 | 
 | ||||||
|  |     <scm> | ||||||
|  |         <connection>scm:git:https://gittr.ch/java/maze-server.git</connection> | ||||||
|  |         <developerConnection>scm:git:ssh://git@gittr.ch/java/maze-server.git</developerConnection> | ||||||
|  |         <url>https://gittr.ch/java/maze-server</url> | ||||||
|  |         <tag>HEAD</tag> | ||||||
|  |     </scm> | ||||||
|  | 
 | ||||||
|  |     <distributionManagement> | ||||||
|  |         <snapshotRepository> | ||||||
|  |             <id>ossrh</id> | ||||||
|  |             <name>Sonatype Maven Repository - Snapshots</name> | ||||||
|  |             <url>https://s01.oss.sonatype.org/content/repositories/snapshots</url> | ||||||
|  |         </snapshotRepository> | ||||||
|  |     </distributionManagement> | ||||||
|  | 
 | ||||||
|  |     <properties> | ||||||
|  |         <maze-generator.version>0.1.0</maze-generator.version> | ||||||
|  |         <maven-site-plugin.version>4.0.0-M8</maven-site-plugin.version> | ||||||
|  |         <undertow.version>2.3.5.Final</undertow.version> | ||||||
|  |     </properties> | ||||||
|  | 
 | ||||||
|     <dependencies> |     <dependencies> | ||||||
|         <dependency> |         <dependency> | ||||||
|             <groupId>ch.fritteli.labyrinth</groupId> |             <groupId>ch.fritteli.a-maze-r</groupId> | ||||||
|             <artifactId>labyrinth-generator</artifactId> |             <artifactId>maze-generator</artifactId> | ||||||
|             <version>${labyrinth-generator.version}</version> |             <version>${maze-generator.version}</version> | ||||||
|         </dependency> |         </dependency> | ||||||
|         <dependency> |         <dependency> | ||||||
|             <groupId>io.vavr</groupId> |             <groupId>io.vavr</groupId> | ||||||
|  | @ -64,12 +82,10 @@ | ||||||
|         <dependency> |         <dependency> | ||||||
|             <groupId>org.slf4j</groupId> |             <groupId>org.slf4j</groupId> | ||||||
|             <artifactId>slf4j-api</artifactId> |             <artifactId>slf4j-api</artifactId> | ||||||
|             <version>${slf4j.version}</version> |  | ||||||
|         </dependency> |         </dependency> | ||||||
|         <dependency> |         <dependency> | ||||||
|             <groupId>ch.qos.logback</groupId> |             <groupId>ch.qos.logback</groupId> | ||||||
|             <artifactId>logback-classic</artifactId> |             <artifactId>logback-classic</artifactId> | ||||||
|             <version>${logback.version}</version> |  | ||||||
|         </dependency> |         </dependency> | ||||||
|         <dependency> |         <dependency> | ||||||
|             <groupId>io.undertow</groupId> |             <groupId>io.undertow</groupId> | ||||||
|  | @ -87,16 +103,16 @@ | ||||||
|             <plugin> |             <plugin> | ||||||
|                 <groupId>org.apache.maven.plugins</groupId> |                 <groupId>org.apache.maven.plugins</groupId> | ||||||
|                 <artifactId>maven-shade-plugin</artifactId> |                 <artifactId>maven-shade-plugin</artifactId> | ||||||
|                 <version>3.4.1</version> |  | ||||||
|                 <configuration> |                 <configuration> | ||||||
|                     <transformers> |                     <transformers> | ||||||
|                         <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer"> |                         <transformer | ||||||
|                             <mainClass>ch.fritteli.labyrinth.server.Main</mainClass> |                                 implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer"> | ||||||
|  |                             <mainClass>ch.fritteli.maze.server.Main</mainClass> | ||||||
|                         </transformer> |                         </transformer> | ||||||
|                     </transformers> |                     </transformers> | ||||||
|                     <filters> |                     <filters> | ||||||
|                         <filter> |                         <filter> | ||||||
|                             <artifact>ch.fritteli.labyrinth:labyrinth-generator</artifact> |                             <artifact>ch.fritteli.a-maze-r:maze-generator</artifact> | ||||||
|                             <excludes> |                             <excludes> | ||||||
|                                 <exclude>logback.xml</exclude> |                                 <exclude>logback.xml</exclude> | ||||||
|                             </excludes> |                             </excludes> | ||||||
|  | @ -128,52 +144,55 @@ | ||||||
|             <plugin> |             <plugin> | ||||||
|                 <groupId>org.apache.maven.plugins</groupId> |                 <groupId>org.apache.maven.plugins</groupId> | ||||||
|                 <artifactId>maven-site-plugin</artifactId> |                 <artifactId>maven-site-plugin</artifactId> | ||||||
|                 <version>4.0.0-M6</version> |                 <version>${maven-site-plugin.version}</version> | ||||||
|             </plugin> |             </plugin> | ||||||
|         </plugins> |         </plugins> | ||||||
|     </build> |     </build> | ||||||
|     <scm> | 
 | ||||||
|         <connection>scm:git:https://gittr.ch/java/labyrinth-server.git</connection> |     <profiles> | ||||||
|         <developerConnection>scm:git:ssh://git@gittr.ch/java/labyrinth-server.git</developerConnection> |         <profile> | ||||||
|         <url>https://gittr.ch/java/labyrinth-server</url> |             <id>release</id> | ||||||
|         <tag>HEAD</tag> |             <build> | ||||||
|     </scm> |                 <plugins> | ||||||
|     <distributionManagement> |                     <plugin> | ||||||
|         <repository> |                         <groupId>org.apache.maven.plugins</groupId> | ||||||
|             <id>repo.gittr.ch</id> |                         <artifactId>maven-source-plugin</artifactId> | ||||||
|             <name>gittr.ch</name> |                         <executions> | ||||||
|             <url>https://repo.gittr.ch/releases/</url> |                             <execution> | ||||||
|         </repository> |                                 <id>attach-sources</id> | ||||||
|         <snapshotRepository> |                                 <goals> | ||||||
|             <id>repo.gittr.ch</id> |                                     <goal>jar-no-fork</goal> | ||||||
|             <name>gittr.ch</name> |                                 </goals> | ||||||
|             <url>https://repo.gittr.ch/snapshots/</url> |                             </execution> | ||||||
|         </snapshotRepository> |                         </executions> | ||||||
|     </distributionManagement> |                     </plugin> | ||||||
|     <repositories> |                     <plugin> | ||||||
|         <repository> |                         <groupId>org.apache.maven.plugins</groupId> | ||||||
|             <id>repo.gittr.ch.releases</id> |                         <artifactId>maven-javadoc-plugin</artifactId> | ||||||
|             <url>https://repo.gittr.ch/releases/</url> |                         <executions> | ||||||
|             <releases> |                             <execution> | ||||||
|                 <enabled>true</enabled> |                                 <id>attach-javadocs</id> | ||||||
|                 <updatePolicy>never</updatePolicy> |                                 <goals> | ||||||
|             </releases> |                                     <goal>jar</goal> | ||||||
|             <snapshots> |                                 </goals> | ||||||
|                 <enabled>false</enabled> |                             </execution> | ||||||
|                 <updatePolicy>never</updatePolicy> |                         </executions> | ||||||
|             </snapshots> |                     </plugin> | ||||||
|         </repository> |                     <plugin> | ||||||
|         <repository> |                         <groupId>org.apache.maven.plugins</groupId> | ||||||
|             <id>repo.gittr.ch.snapshots</id> |                         <artifactId>maven-gpg-plugin</artifactId> | ||||||
|             <url>https://repo.gittr.ch/snapshots/</url> |                         <executions> | ||||||
|             <releases> |                             <execution> | ||||||
|                 <enabled>false</enabled> |                                 <id>sign-artifacts</id> | ||||||
|                 <updatePolicy>never</updatePolicy> |                                 <phase>verify</phase> | ||||||
|             </releases> |                                 <goals> | ||||||
|             <snapshots> |                                     <goal>sign</goal> | ||||||
|                 <enabled>true</enabled> |                                 </goals> | ||||||
|                 <updatePolicy>always</updatePolicy> |                             </execution> | ||||||
|             </snapshots> |                         </executions> | ||||||
|         </repository> |                     </plugin> | ||||||
|     </repositories> |                 </plugins> | ||||||
|  |             </build> | ||||||
|  |         </profile> | ||||||
|  |     </profiles> | ||||||
| </project> | </project> | ||||||
|  |  | ||||||
|  | @ -1,4 +1,4 @@ | ||||||
| package ch.fritteli.labyrinth.server; | package ch.fritteli.maze.server; | ||||||
| 
 | 
 | ||||||
| import org.jetbrains.annotations.Nullable; | import org.jetbrains.annotations.Nullable; | ||||||
| 
 | 
 | ||||||
|  | @ -1,4 +1,4 @@ | ||||||
| package ch.fritteli.labyrinth.server; | package ch.fritteli.maze.server; | ||||||
| 
 | 
 | ||||||
| import lombok.experimental.UtilityClass; | import lombok.experimental.UtilityClass; | ||||||
| import lombok.extern.slf4j.Slf4j; | import lombok.extern.slf4j.Slf4j; | ||||||
|  | @ -8,7 +8,7 @@ import lombok.extern.slf4j.Slf4j; | ||||||
| public class Main { | public class Main { | ||||||
| 
 | 
 | ||||||
|     public static void main(String[] args) { |     public static void main(String[] args) { | ||||||
|         LabyrinthServer.createAndStartServer() |         MazeServer.createAndStartServer() | ||||||
|                 .onFailure(e -> log.error("Failed to create server. Stopping.", e)); |                 .onFailure(e -> log.error("Failed to create server. Stopping.", e)); | ||||||
|     } |     } | ||||||
| } | } | ||||||
|  | @ -1,8 +1,8 @@ | ||||||
| package ch.fritteli.labyrinth.server; | package ch.fritteli.maze.server; | ||||||
| 
 | 
 | ||||||
| import ch.fritteli.labyrinth.server.handler.CreateHandler; | import ch.fritteli.maze.server.handler.CreateHandler; | ||||||
| import ch.fritteli.labyrinth.server.handler.RenderV1Handler; | import ch.fritteli.maze.server.handler.RenderV1Handler; | ||||||
| import ch.fritteli.labyrinth.server.handler.RenderV2Handler; | import ch.fritteli.maze.server.handler.RenderV2Handler; | ||||||
| import io.undertow.Undertow; | import io.undertow.Undertow; | ||||||
| import io.undertow.server.RoutingHandler; | import io.undertow.server.RoutingHandler; | ||||||
| import io.vavr.control.Try; | import io.vavr.control.Try; | ||||||
|  | @ -11,12 +11,12 @@ import lombok.NonNull; | ||||||
| import lombok.extern.slf4j.Slf4j; | import lombok.extern.slf4j.Slf4j; | ||||||
| 
 | 
 | ||||||
| @Slf4j | @Slf4j | ||||||
| public class LabyrinthServer { | public class MazeServer { | ||||||
| 
 | 
 | ||||||
|     @NonNull |     @NonNull | ||||||
|     private final Undertow undertow; |     private final Undertow undertow; | ||||||
| 
 | 
 | ||||||
|     private LabyrinthServer(@NonNull final ServerConfig config) { |     private MazeServer(@NonNull final ServerConfig config) { | ||||||
|         final String hostAddress = config.getAddress().getHostAddress(); |         final String hostAddress = config.getAddress().getHostAddress(); | ||||||
|         final int port = config.getPort(); |         final int port = config.getPort(); | ||||||
|         log.info("Starting Server at http://{}:{}/", hostAddress, port); |         log.info("Starting Server at http://{}:{}/", hostAddress, port); | ||||||
|  | @ -32,15 +32,15 @@ public class LabyrinthServer { | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     @NonNull |     @NonNull | ||||||
|     public static Try<LabyrinthServer> createAndStartServer() { |     public static Try<MazeServer> createAndStartServer() { | ||||||
|         return Try.of(ServerConfig::init) |         return Try.of(ServerConfig::init) | ||||||
|                 .flatMapTry(LabyrinthServer::createAndStartServer); |                 .flatMapTry(MazeServer::createAndStartServer); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     @NonNull |     @NonNull | ||||||
|     public static Try<LabyrinthServer> createAndStartServer(@NonNull final ServerConfig config) { |     public static Try<MazeServer> createAndStartServer(@NonNull final ServerConfig config) { | ||||||
|         return Try.of(() -> new LabyrinthServer(config)) |         return Try.of(() -> new MazeServer(config)) | ||||||
|                 .peek(LabyrinthServer::start); |                 .peek(MazeServer::start); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     private void start() { |     private void start() { | ||||||
|  | @ -1,12 +1,12 @@ | ||||||
| package ch.fritteli.labyrinth.server; | package ch.fritteli.maze.server; | ||||||
| 
 | 
 | ||||||
| import ch.fritteli.labyrinth.generator.model.Labyrinth; | import ch.fritteli.maze.generator.renderer.html.HTMLRenderer; | ||||||
| import ch.fritteli.labyrinth.generator.renderer.html.HTMLRenderer; | import ch.fritteli.maze.generator.renderer.json.JsonRenderer; | ||||||
| import ch.fritteli.labyrinth.generator.renderer.json.JsonRenderer; | import ch.fritteli.maze.generator.renderer.pdf.PDFRenderer; | ||||||
| import ch.fritteli.labyrinth.generator.renderer.pdf.PDFRenderer; | import ch.fritteli.maze.generator.renderer.text.TextRenderer; | ||||||
| import ch.fritteli.labyrinth.generator.renderer.text.TextRenderer; | import ch.fritteli.maze.generator.serialization.v1.SerializerDeserializerV1; | ||||||
| import ch.fritteli.labyrinth.generator.serialization.v1.SerializerDeserializerV1; | import ch.fritteli.maze.generator.serialization.v2.SerializerDeserializerV2; | ||||||
| import ch.fritteli.labyrinth.generator.serialization.v2.SerializerDeserializerV2; | import ch.fritteli.maze.generator.model.Maze; | ||||||
| import io.vavr.collection.List; | import io.vavr.collection.List; | ||||||
| import io.vavr.collection.Stream; | import io.vavr.collection.Stream; | ||||||
| import io.vavr.control.Option; | import io.vavr.control.Option; | ||||||
|  | @ -20,37 +20,37 @@ import java.util.function.Function; | ||||||
| public enum OutputType { | public enum OutputType { | ||||||
|     TEXT_PLAIN("text/plain; charset=UTF-8", |     TEXT_PLAIN("text/plain; charset=UTF-8", | ||||||
|             "txt", |             "txt", | ||||||
|             labyrinth -> TextRenderer.newInstance().render(labyrinth).getBytes(StandardCharsets.UTF_8), |             maze -> TextRenderer.newInstance().render(maze).getBytes(StandardCharsets.UTF_8), | ||||||
|             false, |             false, | ||||||
|             "t", |             "t", | ||||||
|             "text"), |             "text"), | ||||||
|     HTML("text/html", |     HTML("text/html", | ||||||
|             "html", |             "html", | ||||||
|             labyrinth -> HTMLRenderer.newInstance().render(labyrinth).getBytes(StandardCharsets.UTF_8), |             maze -> HTMLRenderer.newInstance().render(maze).getBytes(StandardCharsets.UTF_8), | ||||||
|             false, |             false, | ||||||
|             "h", |             "h", | ||||||
|             "html"), |             "html"), | ||||||
|     JSON("application/json", |     JSON("application/json", | ||||||
|             "json", |             "json", | ||||||
|             labyrinth -> JsonRenderer.newInstance().render(labyrinth).getBytes(StandardCharsets.UTF_8), |             maze -> JsonRenderer.newInstance().render(maze).getBytes(StandardCharsets.UTF_8), | ||||||
|             false, |             false, | ||||||
|             "j", |             "j", | ||||||
|             "json"), |             "json"), | ||||||
|     JSONFILE("application/json", |     JSONFILE("application/json", | ||||||
|             "json", |             "json", | ||||||
|             labyrinth -> JsonRenderer.newInstance().render(labyrinth).getBytes(StandardCharsets.UTF_8), |             maze -> JsonRenderer.newInstance().render(maze).getBytes(StandardCharsets.UTF_8), | ||||||
|             true, |             true, | ||||||
|             "s", |             "s", | ||||||
|             "jsonfile"), |             "jsonfile"), | ||||||
|     PDF("application/pdf", |     PDF("application/pdf", | ||||||
|             "pdf", |             "pdf", | ||||||
|             labyrinth -> PDFRenderer.newInstance().render(labyrinth).toByteArray(), |             maze -> PDFRenderer.newInstance().render(maze).toByteArray(), | ||||||
|             false, |             false, | ||||||
|             "p", |             "p", | ||||||
|             "pdf"), |             "pdf"), | ||||||
|     PDFFILE("application/pdf", |     PDFFILE("application/pdf", | ||||||
|             "pdf", |             "pdf", | ||||||
|             labyrinth -> PDFRenderer.newInstance().render(labyrinth).toByteArray(), |             maze -> PDFRenderer.newInstance().render(maze).toByteArray(), | ||||||
|             true, |             true, | ||||||
|             "f", |             "f", | ||||||
|             "pdffile"), |             "pdffile"), | ||||||
|  | @ -61,7 +61,7 @@ public enum OutputType { | ||||||
|             "b", |             "b", | ||||||
|             "binary"), |             "binary"), | ||||||
|     BINARY_V2("application/octet-stream", |     BINARY_V2("application/octet-stream", | ||||||
|             "lab2", |             "maze", | ||||||
|             SerializerDeserializerV2::serialize, |             SerializerDeserializerV2::serialize, | ||||||
|             true, |             true, | ||||||
|             "v", |             "v", | ||||||
|  | @ -73,7 +73,7 @@ public enum OutputType { | ||||||
|     @NonNull |     @NonNull | ||||||
|     private final String fileExtension; |     private final String fileExtension; | ||||||
|     @NonNull |     @NonNull | ||||||
|     private final Function<Labyrinth, byte[]> render; |     private final Function<Maze, byte[]> render; | ||||||
|     @Getter |     @Getter | ||||||
|     private final boolean attachment; |     private final boolean attachment; | ||||||
|     @Getter |     @Getter | ||||||
|  | @ -82,7 +82,7 @@ public enum OutputType { | ||||||
| 
 | 
 | ||||||
|     OutputType(@NonNull final String contentType, |     OutputType(@NonNull final String contentType, | ||||||
|                @NonNull final String fileExtension, |                @NonNull final String fileExtension, | ||||||
|                @NonNull final Function<Labyrinth, byte[]> render, |                @NonNull final Function<Maze, byte[]> render, | ||||||
|                final boolean attachment, |                final boolean attachment, | ||||||
|                @NonNull final String... names) { |                @NonNull final String... names) { | ||||||
|         this.contentType = contentType; |         this.contentType = contentType; | ||||||
|  | @ -108,7 +108,7 @@ public enum OutputType { | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     @NonNull |     @NonNull | ||||||
|     public byte[] render(@NonNull final Labyrinth labyrinth) { |     public byte[] render(@NonNull final Maze maze) { | ||||||
|         return this.render.apply(labyrinth); |         return this.render.apply(maze); | ||||||
|     } |     } | ||||||
| } | } | ||||||
|  | @ -1,4 +1,4 @@ | ||||||
| package ch.fritteli.labyrinth.server; | package ch.fritteli.maze.server; | ||||||
| 
 | 
 | ||||||
| import io.vavr.control.Try; | import io.vavr.control.Try; | ||||||
| import lombok.AccessLevel; | import lombok.AccessLevel; | ||||||
|  | @ -14,8 +14,8 @@ import java.net.InetAddress; | ||||||
| @Slf4j | @Slf4j | ||||||
| @Value | @Value | ||||||
| public class ServerConfig { | public class ServerConfig { | ||||||
|     public static final String SYSPROP_HOST = "fritteli.labyrinth.server.host"; |     public static final String SYSPROP_HOST = "fritteli.maze.server.host"; | ||||||
|     public static final String SYSPROP_PORT = "fritteli.labyrinth.server.port"; |     public static final String SYSPROP_PORT = "fritteli.maze.server.port"; | ||||||
| 
 | 
 | ||||||
|     @NonNull |     @NonNull | ||||||
|     InetAddress address; |     InetAddress address; | ||||||
|  | @ -1,4 +1,4 @@ | ||||||
| package ch.fritteli.labyrinth.server.handler; | package ch.fritteli.maze.server.handler; | ||||||
| 
 | 
 | ||||||
| import io.undertow.server.HttpHandler; | import io.undertow.server.HttpHandler; | ||||||
| import io.undertow.server.HttpServerExchange; | import io.undertow.server.HttpServerExchange; | ||||||
|  | @ -1,7 +1,7 @@ | ||||||
| package ch.fritteli.labyrinth.server.handler; | package ch.fritteli.maze.server.handler; | ||||||
| 
 | 
 | ||||||
| import ch.fritteli.labyrinth.generator.model.Labyrinth; | import ch.fritteli.maze.server.OutputType; | ||||||
| import ch.fritteli.labyrinth.server.OutputType; | import ch.fritteli.maze.generator.model.Maze; | ||||||
| import io.undertow.server.HttpServerExchange; | import io.undertow.server.HttpServerExchange; | ||||||
| import io.undertow.util.Headers; | import io.undertow.util.Headers; | ||||||
| import io.undertow.util.HttpString; | import io.undertow.util.HttpString; | ||||||
|  | @ -26,9 +26,9 @@ public class CreateHandler extends AbstractHttpHandler { | ||||||
|     protected void handle(@NonNull final HttpServerExchange exchange) { |     protected void handle(@NonNull final HttpServerExchange exchange) { | ||||||
|         final Instant start = Instant.now(); |         final Instant start = Instant.now(); | ||||||
|         log.debug("Handling create request"); |         log.debug("Handling create request"); | ||||||
|         this.createLabyrinthFromRequestParameters(exchange.getQueryParameters()) |         this.createMazeFromRequestParameters(exchange.getQueryParameters()) | ||||||
|                 .onFailure(e -> { |                 .onFailure(e -> { | ||||||
|                     log.error("Error creating Labyrinth from request", e); |                     log.error("Error creating maze from request", e); | ||||||
|                     exchange.setStatusCode(StatusCodes.INTERNAL_SERVER_ERROR) |                     exchange.setStatusCode(StatusCodes.INTERNAL_SERVER_ERROR) | ||||||
|                             .setReasonPhrase(StatusCodes.INTERNAL_SERVER_ERROR_STRING) |                             .setReasonPhrase(StatusCodes.INTERNAL_SERVER_ERROR_STRING) | ||||||
|                             .getResponseSender() |                             .getResponseSender() | ||||||
|  | @ -36,31 +36,33 @@ public class CreateHandler extends AbstractHttpHandler { | ||||||
|                 }) |                 }) | ||||||
|                 .forEach(tuple -> { |                 .forEach(tuple -> { | ||||||
|                     final OutputType outputType = tuple._1(); |                     final OutputType outputType = tuple._1(); | ||||||
|                     final Labyrinth labyrinth = tuple._2(); |                     final Maze maze = tuple._2(); | ||||||
|                     final byte[] bytes; |                     final byte[] bytes; | ||||||
|                     try { |                     try { | ||||||
|                         bytes = outputType.render(labyrinth); |                         bytes = outputType.render(maze); | ||||||
|                     } catch (@NonNull final Exception e) { |                     } catch (@NonNull final Exception e) { | ||||||
|                         log.error("Error rendering Labyrinth", e); |                         log.error("Error rendering Maze", e); | ||||||
|                         exchange.setStatusCode(StatusCodes.INTERNAL_SERVER_ERROR) |                         exchange.setStatusCode(StatusCodes.INTERNAL_SERVER_ERROR) | ||||||
|                                 .setReasonPhrase(StatusCodes.INTERNAL_SERVER_ERROR_STRING) |                                 .setReasonPhrase(StatusCodes.INTERNAL_SERVER_ERROR_STRING) | ||||||
|                                 .getResponseSender() |                                 .getResponseSender() | ||||||
|                                 .send("Error creating the Labyrinth. Please contact the administrator. Request id=%s".formatted(MDC.get("correlationId"))); |                                 .send("Error creating the maze. Please contact the administrator. Request id=%s".formatted(MDC.get("correlationId"))); | ||||||
|                         return; |                         return; | ||||||
|                     } |                     } | ||||||
|                     final long durationMillis = start.until(Instant.now(), ChronoUnit.MILLIS); |                     final long durationMillis = start.until(Instant.now(), ChronoUnit.MILLIS); | ||||||
|                     exchange.getResponseHeaders() |                     exchange.getResponseHeaders() | ||||||
|                             .put(Headers.CONTENT_TYPE, outputType.getContentType()) |                             .put(Headers.CONTENT_TYPE, outputType.getContentType()) | ||||||
|                             .put(HttpString.tryFromString("X-Labyrinth-ID"), String.valueOf(labyrinth.getRandomSeed())) |                             .put(HttpString.tryFromString("X-Maze-ID"), String.valueOf(maze.getRandomSeed())) | ||||||
|                             .put(HttpString.tryFromString("X-Labyrinth-Width"), String.valueOf(labyrinth.getWidth())) |                             .put(HttpString.tryFromString("X-Maze-Width"), String.valueOf(maze.getWidth())) | ||||||
|                             .put(HttpString.tryFromString("X-Labyrinth-Height"), String.valueOf(labyrinth.getHeight())) |                             .put(HttpString.tryFromString("X-Maze-Height"), String.valueOf(maze.getHeight())) | ||||||
|                             .put(HttpString.tryFromString("X-Labyrinth-Generation-Duration-millis"), String.valueOf(durationMillis)); |                             // TODO read the algorithm from the maze once this is supported. | ||||||
|  |                             .put(HttpString.tryFromString("X-Maze-Algorithm"), "RandomDepthFirst") | ||||||
|  |                             .put(HttpString.tryFromString("X-Maze-Generation-Duration-millis"), String.valueOf(durationMillis)); | ||||||
|                     if (outputType.isAttachment()) { |                     if (outputType.isAttachment()) { | ||||||
|                         exchange.getResponseHeaders() |                         exchange.getResponseHeaders() | ||||||
|                                 .put(Headers.CONTENT_DISPOSITION, "attachment; filename=\"labyrinth-%dx%d-%d.%s\"".formatted( |                                 .put(Headers.CONTENT_DISPOSITION, "attachment; filename=\"maze-%dx%d-%d.%s\"".formatted( | ||||||
|                                         labyrinth.getWidth(), |                                         maze.getWidth(), | ||||||
|                                         labyrinth.getHeight(), |                                         maze.getHeight(), | ||||||
|                                         labyrinth.getRandomSeed(), |                                         maze.getRandomSeed(), | ||||||
|                                         outputType.getFileExtension() |                                         outputType.getFileExtension() | ||||||
|                                 )); |                                 )); | ||||||
|                     } |                     } | ||||||
|  | @ -70,7 +72,7 @@ public class CreateHandler extends AbstractHttpHandler { | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     @NonNull |     @NonNull | ||||||
|     private Try<Tuple2<OutputType, Labyrinth>> createLabyrinthFromRequestParameters(final Map<String, Deque<String>> queryParameters) { |     private Try<Tuple2<OutputType, Maze>> createMazeFromRequestParameters(final Map<String, Deque<String>> queryParameters) { | ||||||
|         return new ParametersToLabyrinthExtractor(queryParameters).createLabyrinth(); |         return new ParametersToMazeExtractor(queryParameters).createMaze(); | ||||||
|     } |     } | ||||||
| } | } | ||||||
|  | @ -1,28 +1,29 @@ | ||||||
| package ch.fritteli.labyrinth.server.handler; | package ch.fritteli.maze.server.handler; | ||||||
| 
 | 
 | ||||||
| import ch.fritteli.labyrinth.generator.Generator; | import ch.fritteli.maze.server.OutputType; | ||||||
| import ch.fritteli.labyrinth.generator.model.Labyrinth; | import ch.fritteli.maze.generator.algorithm.RandomDepthFirst; | ||||||
| import ch.fritteli.labyrinth.generator.model.Position; | import ch.fritteli.maze.generator.model.Maze; | ||||||
| import ch.fritteli.labyrinth.server.OutputType; | import ch.fritteli.maze.generator.model.Position; | ||||||
| import io.vavr.Tuple; | import io.vavr.Tuple; | ||||||
| import io.vavr.Tuple2; | import io.vavr.Tuple2; | ||||||
| import io.vavr.collection.Stream; | import io.vavr.collection.Stream; | ||||||
| import io.vavr.control.Option; | import io.vavr.control.Option; | ||||||
| import io.vavr.control.Try; | import io.vavr.control.Try; | ||||||
| import java.util.Deque; |  | ||||||
| import java.util.Map; |  | ||||||
| import java.util.Random; |  | ||||||
| import lombok.NonNull; | import lombok.NonNull; | ||||||
| import lombok.RequiredArgsConstructor; | import lombok.RequiredArgsConstructor; | ||||||
| 
 | 
 | ||||||
|  | import java.util.Deque; | ||||||
|  | import java.util.Map; | ||||||
|  | import java.util.Random; | ||||||
|  | 
 | ||||||
| @RequiredArgsConstructor | @RequiredArgsConstructor | ||||||
| class ParametersToLabyrinthExtractor { | class ParametersToMazeExtractor { | ||||||
| 
 | 
 | ||||||
|     @NonNull |     @NonNull | ||||||
|     private final Map<String, Deque<String>> queryParameters; |     private final Map<String, Deque<String>> queryParameters; | ||||||
| 
 | 
 | ||||||
|     @NonNull |     @NonNull | ||||||
|     Try<Tuple2<OutputType, Labyrinth>> createLabyrinth() { |     Try<Tuple2<OutputType, Maze>> createMaze() { | ||||||
|         final Option<OutputType> output = getParameterValue(RequestParameter.OUTPUT); |         final Option<OutputType> output = getParameterValue(RequestParameter.OUTPUT); | ||||||
|         final Option<Integer> width = getParameterValue(RequestParameter.WIDTH); |         final Option<Integer> width = getParameterValue(RequestParameter.WIDTH); | ||||||
|         final Option<Integer> height = getParameterValue(RequestParameter.HEIGHT); |         final Option<Integer> height = getParameterValue(RequestParameter.HEIGHT); | ||||||
|  | @ -50,14 +51,14 @@ class ParametersToLabyrinthExtractor { | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         return Try.of(() -> { |         return Try.of(() -> { | ||||||
|             final Labyrinth labyrinth; |             final Maze maze; | ||||||
|             if (start.isDefined() && end.isDefined()) { |             if (start.isDefined() && end.isDefined()) { | ||||||
|                 labyrinth = new Labyrinth(width.get(), height.get(), id.getOrElse(() -> new Random().nextLong()), start.get(), end.get()); |                 maze = new Maze(width.get(), height.get(), id.getOrElse(() -> new Random().nextLong()), start.get(), end.get()); | ||||||
|             } else { |             } else { | ||||||
|                 labyrinth = new Labyrinth(width.get(), height.get(), id.getOrElse(() -> new Random().nextLong())); |                 maze = new Maze(width.get(), height.get(), id.getOrElse(() -> new Random().nextLong())); | ||||||
|             } |             } | ||||||
|             new Generator(labyrinth).run(); |             new RandomDepthFirst(maze).run(); | ||||||
|             return Tuple.of(output.get(), labyrinth); |             return Tuple.of(output.get(), maze); | ||||||
|         }); |         }); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  | @ -1,16 +1,17 @@ | ||||||
| package ch.fritteli.labyrinth.server.handler; | package ch.fritteli.maze.server.handler; | ||||||
| 
 | 
 | ||||||
| import ch.fritteli.labyrinth.generator.model.Labyrinth; | import ch.fritteli.maze.server.OutputType; | ||||||
| import ch.fritteli.labyrinth.generator.serialization.v1.SerializerDeserializerV1; | import ch.fritteli.maze.generator.model.Maze; | ||||||
| import ch.fritteli.labyrinth.server.OutputType; | import ch.fritteli.maze.generator.serialization.v1.SerializerDeserializerV1; | ||||||
| import io.undertow.server.HttpServerExchange; | import io.undertow.server.HttpServerExchange; | ||||||
| import io.undertow.util.HeaderValues; | import io.undertow.util.HeaderValues; | ||||||
| import io.undertow.util.Headers; | import io.undertow.util.Headers; | ||||||
| import io.undertow.util.StatusCodes; | import io.undertow.util.StatusCodes; | ||||||
| import java.nio.ByteBuffer; |  | ||||||
| import lombok.NonNull; | import lombok.NonNull; | ||||||
| import lombok.extern.slf4j.Slf4j; | import lombok.extern.slf4j.Slf4j; | ||||||
| 
 | 
 | ||||||
|  | import java.nio.ByteBuffer; | ||||||
|  | 
 | ||||||
| @Slf4j | @Slf4j | ||||||
| public class RenderV1Handler extends AbstractHttpHandler { | public class RenderV1Handler extends AbstractHttpHandler { | ||||||
| 
 | 
 | ||||||
|  | @ -28,13 +29,13 @@ public class RenderV1Handler extends AbstractHttpHandler { | ||||||
|             final OutputType output = this.getOutputType(httpServerExchange); |             final OutputType output = this.getOutputType(httpServerExchange); | ||||||
|             final byte[] render; |             final byte[] render; | ||||||
|             try { |             try { | ||||||
|                 final Labyrinth labyrinth = SerializerDeserializerV1.deserialize(bytes); |                 final Maze maze = SerializerDeserializerV1.deserialize(bytes); | ||||||
|                 render = output.render(labyrinth); |                 render = output.render(maze); | ||||||
|             } catch (final Exception e) { |             } catch (final Exception e) { | ||||||
|                 log.error("Error rendering binary labyrinth data", e); |                 log.error("Error rendering binary maze data", e); | ||||||
|                 httpServerExchange.setStatusCode(StatusCodes.INTERNAL_SERVER_ERROR) |                 httpServerExchange.setStatusCode(StatusCodes.INTERNAL_SERVER_ERROR) | ||||||
|                         .getResponseSender() |                         .getResponseSender() | ||||||
|                         .send("Error rendering labyrinth: %s".formatted(e.getMessage())); |                         .send("Error rendering maze: %s".formatted(e.getMessage())); | ||||||
|                 return; |                 return; | ||||||
|             } |             } | ||||||
|             httpServerExchange |             httpServerExchange | ||||||
|  | @ -1,16 +1,17 @@ | ||||||
| package ch.fritteli.labyrinth.server.handler; | package ch.fritteli.maze.server.handler; | ||||||
| 
 | 
 | ||||||
| import ch.fritteli.labyrinth.generator.model.Labyrinth; | import ch.fritteli.maze.server.OutputType; | ||||||
| import ch.fritteli.labyrinth.generator.serialization.v2.SerializerDeserializerV2; | import ch.fritteli.maze.generator.model.Maze; | ||||||
| import ch.fritteli.labyrinth.server.OutputType; | import ch.fritteli.maze.generator.serialization.v2.SerializerDeserializerV2; | ||||||
| import io.undertow.server.HttpServerExchange; | import io.undertow.server.HttpServerExchange; | ||||||
| import io.undertow.util.HeaderValues; | import io.undertow.util.HeaderValues; | ||||||
| import io.undertow.util.Headers; | import io.undertow.util.Headers; | ||||||
| import io.undertow.util.StatusCodes; | import io.undertow.util.StatusCodes; | ||||||
| import java.nio.ByteBuffer; |  | ||||||
| import lombok.NonNull; | import lombok.NonNull; | ||||||
| import lombok.extern.slf4j.Slf4j; | import lombok.extern.slf4j.Slf4j; | ||||||
| 
 | 
 | ||||||
|  | import java.nio.ByteBuffer; | ||||||
|  | 
 | ||||||
| @Slf4j | @Slf4j | ||||||
| public class RenderV2Handler extends AbstractHttpHandler { | public class RenderV2Handler extends AbstractHttpHandler { | ||||||
| 
 | 
 | ||||||
|  | @ -28,13 +29,13 @@ public class RenderV2Handler extends AbstractHttpHandler { | ||||||
|             final OutputType output = this.getOutputType(httpServerExchange); |             final OutputType output = this.getOutputType(httpServerExchange); | ||||||
|             final byte[] render; |             final byte[] render; | ||||||
|             try { |             try { | ||||||
|                 final Labyrinth labyrinth = SerializerDeserializerV2.deserialize(bytes); |                 final Maze maze = SerializerDeserializerV2.deserialize(bytes); | ||||||
|                 render = output.render(labyrinth); |                 render = output.render(maze); | ||||||
|             } catch (final Exception e) { |             } catch (final Exception e) { | ||||||
|                 log.error("Error rendering binary labyrinth data", e); |                 log.error("Error rendering binary maze data", e); | ||||||
|                 httpServerExchange.setStatusCode(StatusCodes.INTERNAL_SERVER_ERROR) |                 httpServerExchange.setStatusCode(StatusCodes.INTERNAL_SERVER_ERROR) | ||||||
|                         .getResponseSender() |                         .getResponseSender() | ||||||
|                         .send("Error rendering labyrinth: %s".formatted(e.getMessage())); |                         .send("Error rendering maze: %s".formatted(e.getMessage())); | ||||||
|                 return; |                 return; | ||||||
|             } |             } | ||||||
|             httpServerExchange |             httpServerExchange | ||||||
|  | @ -1,20 +1,21 @@ | ||||||
| package ch.fritteli.labyrinth.server.handler; | package ch.fritteli.maze.server.handler; | ||||||
| 
 | 
 | ||||||
| import ch.fritteli.labyrinth.generator.model.Position; | import ch.fritteli.maze.server.OutputType; | ||||||
| import ch.fritteli.labyrinth.server.OutputType; | import ch.fritteli.maze.generator.model.Position; | ||||||
| import io.vavr.Tuple2; | import io.vavr.Tuple2; | ||||||
| import io.vavr.collection.HashMap; | import io.vavr.collection.HashMap; | ||||||
| import io.vavr.collection.HashSet; | import io.vavr.collection.HashSet; | ||||||
| import io.vavr.collection.Set; | import io.vavr.collection.Set; | ||||||
| import io.vavr.control.Option; | import io.vavr.control.Option; | ||||||
| import io.vavr.control.Try; | import io.vavr.control.Try; | ||||||
| import java.util.Deque; |  | ||||||
| import java.util.Map; |  | ||||||
| import java.util.function.Function; |  | ||||||
| import lombok.Getter; | import lombok.Getter; | ||||||
| import lombok.NonNull; | import lombok.NonNull; | ||||||
| import lombok.extern.slf4j.Slf4j; | import lombok.extern.slf4j.Slf4j; | ||||||
| 
 | 
 | ||||||
|  | import java.util.Deque; | ||||||
|  | import java.util.Map; | ||||||
|  | import java.util.function.Function; | ||||||
|  | 
 | ||||||
| @Slf4j | @Slf4j | ||||||
| enum RequestParameter { | enum RequestParameter { | ||||||
|     WIDTH(p -> Try.of(() -> Integer.parseInt(p)) |     WIDTH(p -> Try.of(() -> Integer.parseInt(p)) | ||||||
|  | @ -13,5 +13,5 @@ | ||||||
|     <root level="info"> |     <root level="info"> | ||||||
|         <appender-ref ref="STDOUT"/> |         <appender-ref ref="STDOUT"/> | ||||||
|     </root> |     </root> | ||||||
|     <logger name="ch.fritteli.labyrinth.*" level="debug"/> |     <logger name="ch.fritteli.maze.*" level="debug"/> | ||||||
| </configuration> | </configuration> | ||||||
|  |  | ||||||
|  | @ -1,4 +1,4 @@ | ||||||
| package ch.fritteli.labyrinth.server; | package ch.fritteli.maze.server; | ||||||
| 
 | 
 | ||||||
| import org.junit.jupiter.api.BeforeEach; | import org.junit.jupiter.api.BeforeEach; | ||||||
| import org.junit.jupiter.api.Test; | import org.junit.jupiter.api.Test; | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue