From 21fd63e5fe812114fcef36ecf49fca339bad782a Mon Sep 17 00:00:00 2001 From: Benjamin Komen Date: Sat, 10 Nov 2018 20:59:28 +0100 Subject: [PATCH 01/19] starting new development iteration --- pom.xml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index aaf8ce3..f4b6aa7 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ com.tibiawiki TibiaWikiApi - 1.3.1 + 1.4.0 jar TibiaWikiApi https://github.com/benjaminkomen/TibiaWikiApi @@ -217,6 +217,7 @@ 11 11 + 11 From fbddfb701740a5790498e51fd4463da0baab4de6 Mon Sep 17 00:00:00 2001 From: Benjamin Komen Date: Mon, 12 Nov 2018 20:32:55 +0100 Subject: [PATCH 02/19] working on upload functionality --- pom.xml | 10 ++++- .../domain/interfaces/Validatable.java | 10 +++++ .../tibiawiki/domain/objects/Achievement.java | 10 ++++- .../validation/ValidationException.java | 29 +++++++++++++ .../objects/validation/ValidationResult.java | 17 ++++++++ .../validation/ValidationSeverity.java | 8 ++++ .../tibiawiki/process/ModifyAchievement.java | 41 +++++++++++++++++++ .../AchievementsResource.java | 28 +++++++++++-- 8 files changed, 148 insertions(+), 5 deletions(-) create mode 100644 src/main/java/com/tibiawiki/domain/interfaces/Validatable.java create mode 100644 src/main/java/com/tibiawiki/domain/objects/validation/ValidationException.java create mode 100644 src/main/java/com/tibiawiki/domain/objects/validation/ValidationResult.java create mode 100644 src/main/java/com/tibiawiki/domain/objects/validation/ValidationSeverity.java create mode 100644 src/main/java/com/tibiawiki/process/ModifyAchievement.java diff --git a/pom.xml b/pom.xml index f4b6aa7..3725875 100644 --- a/pom.xml +++ b/pom.xml @@ -35,6 +35,7 @@ 6.2.1 1.5.21 1.1.1 + 0.9.2 @@ -147,6 +148,14 @@ ${swagger.jersey2.jaxrs.version} + + + io.vavr + vavr + ${vavr.version} + + + @@ -217,7 +226,6 @@ 11 11 - 11 diff --git a/src/main/java/com/tibiawiki/domain/interfaces/Validatable.java b/src/main/java/com/tibiawiki/domain/interfaces/Validatable.java new file mode 100644 index 0000000..0cdb059 --- /dev/null +++ b/src/main/java/com/tibiawiki/domain/interfaces/Validatable.java @@ -0,0 +1,10 @@ +package com.tibiawiki.domain.interfaces; + +import com.tibiawiki.domain.objects.validation.ValidationResult; + +import java.util.List; + +public interface Validatable { + + List validate(); +} diff --git a/src/main/java/com/tibiawiki/domain/objects/Achievement.java b/src/main/java/com/tibiawiki/domain/objects/Achievement.java index 03ee183..0df2cd4 100644 --- a/src/main/java/com/tibiawiki/domain/objects/Achievement.java +++ b/src/main/java/com/tibiawiki/domain/objects/Achievement.java @@ -3,19 +3,22 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.tibiawiki.domain.enums.Grade; import com.tibiawiki.domain.enums.YesNo; +import com.tibiawiki.domain.interfaces.Validatable; +import com.tibiawiki.domain.objects.validation.ValidationResult; import lombok.AccessLevel; import lombok.Getter; import lombok.NoArgsConstructor; import org.springframework.stereotype.Component; import java.util.Arrays; +import java.util.Collections; import java.util.List; @JsonIgnoreProperties({"templateType"}) @Getter @NoArgsConstructor(access = AccessLevel.PRIVATE) @Component -public class Achievement extends WikiObject { +public class Achievement extends WikiObject implements Validatable { private Grade grade; private String description; @@ -32,4 +35,9 @@ public List fieldOrder() { return Arrays.asList("grade", "name", "description", "spoiler", "premium", "points", "secret", "coincideswith", "implemented", "achievementid", "relatedpages", "history", "status"); } + + @Override + public List validate() { + return Collections.emptyList(); + } } \ No newline at end of file diff --git a/src/main/java/com/tibiawiki/domain/objects/validation/ValidationException.java b/src/main/java/com/tibiawiki/domain/objects/validation/ValidationException.java new file mode 100644 index 0000000..8532228 --- /dev/null +++ b/src/main/java/com/tibiawiki/domain/objects/validation/ValidationException.java @@ -0,0 +1,29 @@ +package com.tibiawiki.domain.objects.validation; + +import java.util.List; + +public class ValidationException extends RuntimeException { + + private List validationResults; + + public ValidationException() { + super(); + } + + public ValidationException(String messsage) { + super(messsage); + } + + public ValidationException(Throwable throwable) { + super(throwable); + } + + public ValidationException(List validationResults) { + this(); + this.validationResults = validationResults; + } + + public static ValidationException fromResults(List validationResults) { + return new ValidationException(validationResults); + } +} diff --git a/src/main/java/com/tibiawiki/domain/objects/validation/ValidationResult.java b/src/main/java/com/tibiawiki/domain/objects/validation/ValidationResult.java new file mode 100644 index 0000000..6d2b77e --- /dev/null +++ b/src/main/java/com/tibiawiki/domain/objects/validation/ValidationResult.java @@ -0,0 +1,17 @@ +package com.tibiawiki.domain.objects.validation; + +import lombok.AccessLevel; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; + +@Getter +@NoArgsConstructor(access = AccessLevel.PRIVATE) +@AllArgsConstructor(access = AccessLevel.PRIVATE) +@Builder +public class ValidationResult { + + private ValidationSeverity severity; + private String description; +} diff --git a/src/main/java/com/tibiawiki/domain/objects/validation/ValidationSeverity.java b/src/main/java/com/tibiawiki/domain/objects/validation/ValidationSeverity.java new file mode 100644 index 0000000..406704c --- /dev/null +++ b/src/main/java/com/tibiawiki/domain/objects/validation/ValidationSeverity.java @@ -0,0 +1,8 @@ +package com.tibiawiki.domain.objects.validation; + +public enum ValidationSeverity { + + INFO, + WARNING, + ERROR; +} diff --git a/src/main/java/com/tibiawiki/process/ModifyAchievement.java b/src/main/java/com/tibiawiki/process/ModifyAchievement.java new file mode 100644 index 0000000..def46c9 --- /dev/null +++ b/src/main/java/com/tibiawiki/process/ModifyAchievement.java @@ -0,0 +1,41 @@ +package com.tibiawiki.process; + +import com.tibiawiki.domain.objects.Achievement; +import com.tibiawiki.domain.objects.validation.ValidationException; +import com.tibiawiki.domain.objects.validation.ValidationResult; +import io.vavr.control.Try; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +import java.util.List; + +/** + * 1. Validate modified Achievement + * 2. Get current wikipage + * 3. Replace infobox part of template with newly made infobox part of template + * 4. Edit the wiki (via a repository) + */ +@Component +public class ModifyAchievement { + + @Autowired + private RetrieveAchievements retrieveAchievements; + + private ModifyAchievement() { + // nothing to do, all dependencies are injected + } + + public Try modify(Achievement achievement) { + return validate(achievement) +// .map(a -> retrieveAchievements.getAchievementJSON(a.getName())) + ; + } + + private Try validate(Achievement achievement) { + final List validationResults = achievement.validate(); + + return validationResults.isEmpty() + ? Try.success(achievement) + : Try.failure(ValidationException.fromResults(validationResults)); + } +} diff --git a/src/main/java/com/tibiawiki/serviceinterface/AchievementsResource.java b/src/main/java/com/tibiawiki/serviceinterface/AchievementsResource.java index d369fe5..47e96b3 100644 --- a/src/main/java/com/tibiawiki/serviceinterface/AchievementsResource.java +++ b/src/main/java/com/tibiawiki/serviceinterface/AchievementsResource.java @@ -1,5 +1,7 @@ package com.tibiawiki.serviceinterface; +import com.tibiawiki.domain.objects.Achievement; +import com.tibiawiki.process.ModifyAchievement; import com.tibiawiki.process.RetrieveAchievements; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; @@ -10,7 +12,9 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; +import javax.ws.rs.Consumes; import javax.ws.rs.GET; +import javax.ws.rs.PUT; import javax.ws.rs.Path; import javax.ws.rs.PathParam; import javax.ws.rs.Produces; @@ -20,18 +24,19 @@ @Component @Api(value = "Achievements") -@Path("/") +@Path("/achievements") public class AchievementsResource { @Autowired private RetrieveAchievements retrieveAchievements; + @Autowired + private ModifyAchievement modifyAchievement; private AchievementsResource() { // nothing to do, all dependencies are injected } @GET - @Path("/achievements") @ApiResponses(value = { @ApiResponse(code = 200, message = "list of achievements retrieved") }) @@ -49,7 +54,7 @@ public Response getAchievements(@ApiParam(value = "optionally expands the result } @GET - @Path("/achievements/{name}") + @Path("/{name}") @ApiOperation(value = "achievements") @ApiResponses(value = { @ApiResponse(code = 200, message = "achievement with specified name found"), @@ -65,4 +70,21 @@ public Response getAchievementsByName(@PathParam("name") String name) { .orElseGet(() -> Response.status(Response.Status.NOT_FOUND) .build()); } + + @PUT + @ApiResponses(value = { + @ApiResponse(code = 200, message = "the changed achievement"), + @ApiResponse(code = 400, message = "the provided changed achievement is not valid") + }) + @Produces(MediaType.APPLICATION_JSON) + @Consumes(MediaType.APPLICATION_JSON) + public Response putAchievement(Achievement achievement) { + return modifyAchievement.modify(achievement) + .map(a -> Response.ok() + .entity(a) + .header("Access-Control-Allow-Origin", "*") + .build()) + .recover(e -> Response.serverError().build()) + .get(); + } } From cc1e62c69939501c8bdc9b969a6a4d46880cee9e Mon Sep 17 00:00:00 2001 From: Benjamin Komen Date: Mon, 12 Nov 2018 20:38:03 +0100 Subject: [PATCH 03/19] Jdk8 build not necessary --- .travis.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 3d03df8..f19b35a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,7 +1,6 @@ language: java jdk: - - openjdk8 - openjdk11 From 5e1589368ff8448cce8b89bb84237bc2852262bd Mon Sep 17 00:00:00 2001 From: Benjamin Komen Date: Sat, 17 Nov 2018 13:51:57 +0100 Subject: [PATCH 04/19] Working on the edit article feature (work in progress). --- .../domain/factories/ArticleFactory.java | 13 +++ .../domain/factories/JsonFactory.java | 58 ++++++++++++- .../repositories/ArticleRepository.java | 12 +++ .../tibiawiki/domain/utils/TemplateUtils.java | 83 +++++++++++++------ .../tibiawiki/process/ModifyAchievement.java | 2 +- .../AchievementsResource.java | 8 +- .../domain/factories/ArticleFactoryTest.java | 41 +++++++++ 7 files changed, 186 insertions(+), 31 deletions(-) diff --git a/src/main/java/com/tibiawiki/domain/factories/ArticleFactory.java b/src/main/java/com/tibiawiki/domain/factories/ArticleFactory.java index a93c4eb..d25072c 100644 --- a/src/main/java/com/tibiawiki/domain/factories/ArticleFactory.java +++ b/src/main/java/com/tibiawiki/domain/factories/ArticleFactory.java @@ -1,6 +1,7 @@ package com.tibiawiki.domain.factories; import com.tibiawiki.domain.utils.TemplateUtils; +import io.vavr.Tuple2; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.stereotype.Component; @@ -38,4 +39,16 @@ public String extractInfoboxPartOfArticle(Map.Entry pageNameAndA return TemplateUtils.getBetweenOuterBalancedBrackets(articleContent, INFOBOX_HEADER); } + + /** + * @param originalArticleContent the original article content with the old infobox content + * @param newContent the new infobox content + * @return the full article content with the old infobox content replaced by the new infobox content + */ + public String insertInfoboxPartOfArticle(String originalArticleContent, String newContent) { + final Tuple2 beforeAndAfterOuterBalancedBrackets = + TemplateUtils.getBeforeAndAfterOuterBalancedBrackets(originalArticleContent, INFOBOX_HEADER); + + return beforeAndAfterOuterBalancedBrackets._1() + newContent + beforeAndAfterOuterBalancedBrackets._2(); + } } \ No newline at end of file diff --git a/src/main/java/com/tibiawiki/domain/factories/JsonFactory.java b/src/main/java/com/tibiawiki/domain/factories/JsonFactory.java index 1831589..97de686 100644 --- a/src/main/java/com/tibiawiki/domain/factories/JsonFactory.java +++ b/src/main/java/com/tibiawiki/domain/factories/JsonFactory.java @@ -1,5 +1,6 @@ package com.tibiawiki.domain.factories; +import com.google.common.base.Strings; import com.tibiawiki.domain.utils.TemplateUtils; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -20,7 +21,7 @@ import java.util.stream.Collectors; /** - * Conversion from infoboxPartOfArticle to JSON. + * Conversion from infoboxPartOfArticle to JSON and back. */ @Component public class JsonFactory { @@ -73,6 +74,61 @@ public JSONObject convertInfoboxPartOfArticleToJson(@Nullable final String infob return enhanceJsonObject(new JSONObject(parametersAndValues)); } + @NotNull + public String convertJsonToInfoboxPartOfArticle(@Nullable JSONObject jsonObject) { + if (jsonObject == null || jsonObject.isEmpty()) { + return ""; + } + + StringBuilder sb = new StringBuilder(); + sb.append("{{Infobox "); + sb.append(jsonObject.get(TEMPLATE_TYPE)); + sb.append("|List={{{1|}}}|GetValue={{{GetValue|}}}").append("\n"); + + int maxFieldLength = jsonObject.keySet().stream() + .mapToInt(String::length) + .max() + .orElse(0); + + int maxKeyLength = maxFieldLength + 2; + + for (String key : jsonObject.keySet()) { + Object value = jsonObject.get(key); + + if (value instanceof JSONArray) { + + if (SOUNDS.equals(key)) { + // do the opposite of makeSoundsArray() + } else if (SPAWN_TYPE.equals(key)) { + + } else if (LOOT.equals(key)) { + + } else if (DROPPED_BY.equals(key)) { + + } else if (ITEM_ID.equals(key)) { + + } else if (LOWER_LEVELS.equals(key)) { + + } else { + // just convert to a comma-separated list of array values + } + + } else if (value instanceof JSONObject) { + + } else { + String paddedKey = Strings.padEnd(key, maxKeyLength, ' '); + sb.append("| ") + .append(paddedKey) + .append(" = ") + .append(value) + .append("\n"); + } + } + + sb.append("}}").append("\n"); + return sb.toString(); + } + /** * Extracts template type from input. Allows cases of e.g. {{Infobox_Hunt|}} (with an underscore) or without an underscore. */ diff --git a/src/main/java/com/tibiawiki/domain/repositories/ArticleRepository.java b/src/main/java/com/tibiawiki/domain/repositories/ArticleRepository.java index f89a7ad..4be22f7 100644 --- a/src/main/java/com/tibiawiki/domain/repositories/ArticleRepository.java +++ b/src/main/java/com/tibiawiki/domain/repositories/ArticleRepository.java @@ -34,6 +34,9 @@ public List getPageNamesFromCategory(String categoryName) { return wiki.getCategoryMembers(categoryName, NS.MAIN); } + /** + * @return a map of key-value pairs of: title - pagecontent + */ public Map getArticlesFromCategory(List pageNames) { return MQuery.getPageText(wiki, pageNames); } @@ -51,6 +54,10 @@ public String getArticle(String pageName) { return wiki.getPageText(pageName); } + public boolean modifyArticle(String pageName, String pageContent, String editSummary) { + return wiki.edit(pageName, pageContent, editSummary); + } + private boolean login(Wiki wiki) { String username = PropertiesUtil.getUsername(); String password = PropertiesUtil.getPassword(); @@ -61,4 +68,9 @@ private boolean login(Wiki wiki) { return false; } } + + // TODO implement this method + private boolean isLoggedIn() { + return false; + } } \ No newline at end of file diff --git a/src/main/java/com/tibiawiki/domain/utils/TemplateUtils.java b/src/main/java/com/tibiawiki/domain/utils/TemplateUtils.java index 285134c..77be585 100644 --- a/src/main/java/com/tibiawiki/domain/utils/TemplateUtils.java +++ b/src/main/java/com/tibiawiki/domain/utils/TemplateUtils.java @@ -1,11 +1,19 @@ package com.tibiawiki.domain.utils; +import io.vavr.Tuple; +import io.vavr.Tuple2; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.util.*; +import java.util.Arrays; +import java.util.HashMap; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; +import java.util.Objects; +import java.util.Optional; import java.util.regex.Matcher; import java.util.regex.Pattern; import java.util.stream.Collectors; @@ -20,35 +28,23 @@ public class TemplateUtils { private static final String LOWER_LEVELS = "lowerlevels"; private TemplateUtils() { + // no-args constructor, only static methods } public static String getBetweenOuterBalancedBrackets(String text, String start) { - int startingCurlyBrackets = text.indexOf(start); - - if (startingCurlyBrackets < 0) { - throw new IllegalArgumentException("Provided arguments text and start are not valid."); - } - - int endingCurlyBrackets = 0; - int openBracketsCounter = 0; - char currentChar; - - for (int i = startingCurlyBrackets; i < text.length(); i++) { - currentChar = text.charAt(i); - if ('{' == currentChar) { - openBracketsCounter++; - } - - if ('}' == currentChar) { - openBracketsCounter--; - } + final Tuple2 startingAndEndingCurlyBrackets = getStartingAndEndingCurlyBrackets(text, start); + return text.substring(startingAndEndingCurlyBrackets._1(), startingAndEndingCurlyBrackets._2()); + } - if (openBracketsCounter == 0) { - endingCurlyBrackets = i + 1; - break; - } - } - return text.substring(startingCurlyBrackets, endingCurlyBrackets); + /** + * @param text to search in + * @param start string which denoted the start of the balanced brackets + * @return two strings, the first is the substring of the provided text before the start of the balanced brackets, + * the second is the substring after the start of the balanced brackets. + */ + public static Tuple2 getBeforeAndAfterOuterBalancedBrackets(String text, String start) { + final Tuple2 startingAndEndingCurlyBrackets = getStartingAndEndingCurlyBrackets(text, start); + return Tuple.of(text.substring(0, startingAndEndingCurlyBrackets._1()), text.substring(startingAndEndingCurlyBrackets._2())); } /** @@ -166,4 +162,39 @@ public static String removeLowerLevels(@Nullable String infoboxTemplatePartOfArt .map(m -> m.replaceAll("")) .orElse(""); } + + /** + * @param text the text to search in + * @param start the start String which denotes the start of the curly brackets + * @return a tuple of two integers: the index of the start of the curly brackets and an index of the end of + * the curly brackets + */ + private static Tuple2 getStartingAndEndingCurlyBrackets(String text, String start) { + final int startingCurlyBrackets = text.indexOf(start); + + if (startingCurlyBrackets < 0) { + throw new IllegalArgumentException("Provided arguments text and start are not valid."); + } + + int endingCurlyBrackets = 0; + int openBracketsCounter = 0; + char currentChar; + + for (int i = startingCurlyBrackets; i < text.length(); i++) { + currentChar = text.charAt(i); + if ('{' == currentChar) { + openBracketsCounter++; + } + + if ('}' == currentChar) { + openBracketsCounter--; + } + + if (openBracketsCounter == 0) { + endingCurlyBrackets = i + 1; + break; + } + } + return Tuple.of(startingCurlyBrackets, endingCurlyBrackets); + } } \ No newline at end of file diff --git a/src/main/java/com/tibiawiki/process/ModifyAchievement.java b/src/main/java/com/tibiawiki/process/ModifyAchievement.java index def46c9..6105f53 100644 --- a/src/main/java/com/tibiawiki/process/ModifyAchievement.java +++ b/src/main/java/com/tibiawiki/process/ModifyAchievement.java @@ -25,7 +25,7 @@ private ModifyAchievement() { // nothing to do, all dependencies are injected } - public Try modify(Achievement achievement) { + public Try modify(Achievement achievement, String editSummary) { return validate(achievement) // .map(a -> retrieveAchievements.getAchievementJSON(a.getName())) ; diff --git a/src/main/java/com/tibiawiki/serviceinterface/AchievementsResource.java b/src/main/java/com/tibiawiki/serviceinterface/AchievementsResource.java index 47e96b3..c77dd17 100644 --- a/src/main/java/com/tibiawiki/serviceinterface/AchievementsResource.java +++ b/src/main/java/com/tibiawiki/serviceinterface/AchievementsResource.java @@ -14,6 +14,7 @@ import javax.ws.rs.Consumes; import javax.ws.rs.GET; +import javax.ws.rs.HeaderParam; import javax.ws.rs.PUT; import javax.ws.rs.Path; import javax.ws.rs.PathParam; @@ -74,12 +75,13 @@ public Response getAchievementsByName(@PathParam("name") String name) { @PUT @ApiResponses(value = { @ApiResponse(code = 200, message = "the changed achievement"), - @ApiResponse(code = 400, message = "the provided changed achievement is not valid") + @ApiResponse(code = 400, message = "the provided changed achievement is not valid"), + @ApiResponse(code = 401, message = "not authorized to edit without providing credentials") }) @Produces(MediaType.APPLICATION_JSON) @Consumes(MediaType.APPLICATION_JSON) - public Response putAchievement(Achievement achievement) { - return modifyAchievement.modify(achievement) + public Response putAchievement(Achievement achievement, @HeaderParam("X-WIKI-Edit-Summary") String editSummary) { + return modifyAchievement.modify(achievement, editSummary) .map(a -> Response.ok() .entity(a) .header("Access-Control-Allow-Origin", "*") diff --git a/src/test/java/com/tibiawiki/domain/factories/ArticleFactoryTest.java b/src/test/java/com/tibiawiki/domain/factories/ArticleFactoryTest.java index b1b3e2e..aa72890 100644 --- a/src/test/java/com/tibiawiki/domain/factories/ArticleFactoryTest.java +++ b/src/test/java/com/tibiawiki/domain/factories/ArticleFactoryTest.java @@ -2,15 +2,32 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.function.Executable; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.is; +import static org.junit.jupiter.api.Assertions.assertThrows; public class ArticleFactoryTest { private static final String SOME_TEXT_ONLY_INFOBOX = "{{Infobox Achievement|List={{{1|}}}|GetValue={{{GetValue|}}}\n" + "| name = Goo Goo Dancer\n" + "}}"; + private static final String SOME_TEXT_INFOBOX_WITH_BEFORE_AND_AFTER = "{{merge|blabla}}{{Infobox Achievement|List={{{1|}}}|GetValue={{{GetValue|}}}\n" + + "| name = Goo Goo Dancer\n" + + "}}\n" + + "[[Category:Achievements Made By Aliens]]"; + private static final String SOME_TEXT_ONLY_INFOBOX2 = "{{Infobox Achievement|List={{{1|}}}|GetValue={{{GetValue|}}}\n" + + "| name = Goo Goo Dancer\n" + + "| points = 5\n" + + "}}"; + private static final String SOME_TEXT_INFOBOX_WITH_BEFORE_AND_AFTER2 = "{{merge|blabla}}{{Infobox Achievement|List={{{1|}}}|GetValue={{{GetValue|}}}\n" + + "| name = Goo Goo Dancer\n" + + "| points = 5\n" + + "}}\n" + + "[[Category:Achievements Made By Aliens]]"; private static final String SOME_TEXT_NO_INFOBOX = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. {{}}}}}{"; private static final String SOME_TEXT_EMPTY = ""; @@ -42,4 +59,28 @@ public void testExtractInfoboxPartOfArticle_OnlyInfoboxInArticleText() { assertThat(result, is(SOME_TEXT_ONLY_INFOBOX)); } + + @Test + void testInsertInfoboxPartOfArticle_Empty() { + Executable closure = () -> target.insertInfoboxPartOfArticle(SOME_TEXT_EMPTY, "foobar"); + assertThrows(IllegalArgumentException.class, closure); + } + + @Test + void testInsertInfoboxPartOfArticle_NoInfobox() { + Executable closure = () -> target.insertInfoboxPartOfArticle(SOME_TEXT_NO_INFOBOX, "foobar"); + assertThrows(IllegalArgumentException.class, closure); + } + + @Test + void testInsertInfoboxPartOfArticle_OnlyInfoboxInArticleText() { + String result = target.insertInfoboxPartOfArticle(SOME_TEXT_ONLY_INFOBOX, SOME_TEXT_ONLY_INFOBOX2); + assertThat(result, is(SOME_TEXT_ONLY_INFOBOX2)); + } + + @Test + void testInsertInfoboxPartOfArticle_WithTextBeforeAndAfter() { + String result = target.insertInfoboxPartOfArticle(SOME_TEXT_INFOBOX_WITH_BEFORE_AND_AFTER, SOME_TEXT_ONLY_INFOBOX2); + assertThat(result, is(SOME_TEXT_INFOBOX_WITH_BEFORE_AND_AFTER2)); + } } \ No newline at end of file From d5b679a55aa35d6a90b6e72b88ac4c9ab9888e8b Mon Sep 17 00:00:00 2001 From: Benjamin Komen Date: Sat, 17 Nov 2018 18:07:26 +0100 Subject: [PATCH 05/19] Being able to modify achievements. Reuse one main objectmapper. Removed some unnecessary code. --- .../tibiawiki/TibiaWikiApiApplication.java | 20 ++++ .../domain/factories/JsonFactory.java | 37 ++++-- .../domain/factories/WikiObjectFactory.java | 55 +++------ .../domain/jackson/WikiObjectMixin.java | 47 ++++++++ .../tibiawiki/domain/objects/Achievement.java | 53 ++++++--- .../tibiawiki/domain/objects/WikiObject.java | 109 +++++------------- .../validation/ValidationException.java | 14 +++ .../repositories/ArticleRepository.java | 5 +- .../tibiawiki/process/ModifyAchievement.java | 24 +++- .../AchievementsResource.java | 2 + .../domain/factories/JsonFactoryTest.java | 60 ++++++++-- .../domain/objects/WikiObjectTest.java | 39 ------- 12 files changed, 261 insertions(+), 204 deletions(-) create mode 100644 src/main/java/com/tibiawiki/domain/jackson/WikiObjectMixin.java delete mode 100644 src/test/java/com/tibiawiki/domain/objects/WikiObjectTest.java diff --git a/src/main/java/com/tibiawiki/TibiaWikiApiApplication.java b/src/main/java/com/tibiawiki/TibiaWikiApiApplication.java index 6612523..6c3ab35 100644 --- a/src/main/java/com/tibiawiki/TibiaWikiApiApplication.java +++ b/src/main/java/com/tibiawiki/TibiaWikiApiApplication.java @@ -1,7 +1,15 @@ package com.tibiawiki; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.SerializationFeature; +import com.tibiawiki.domain.jackson.WikiObjectMixin; +import com.tibiawiki.domain.objects.WikiObject; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Primary; +import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder; @SpringBootApplication public class TibiaWikiApiApplication { @@ -9,4 +17,16 @@ public class TibiaWikiApiApplication { public static void main(String[] args) { SpringApplication.run(TibiaWikiApiApplication.class, args); } + + @Bean + @Primary + public ObjectMapper objectMapper(Jackson2ObjectMapperBuilder builder) { + ObjectMapper objectMapper = builder.createXmlMapper(false).build(); + objectMapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false); + objectMapper.configure(SerializationFeature.WRITE_DATE_TIMESTAMPS_AS_NANOSECONDS, false); + objectMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL); + + objectMapper.addMixIn(WikiObjectMixin.class, WikiObject.class); + return objectMapper; + } } \ No newline at end of file diff --git a/src/main/java/com/tibiawiki/domain/factories/JsonFactory.java b/src/main/java/com/tibiawiki/domain/factories/JsonFactory.java index 97de686..1b92528 100644 --- a/src/main/java/com/tibiawiki/domain/factories/JsonFactory.java +++ b/src/main/java/com/tibiawiki/domain/factories/JsonFactory.java @@ -26,7 +26,7 @@ @Component public class JsonFactory { - private static final Logger log = LoggerFactory.getLogger(JsonFactory.class); + private static final Logger LOG = LoggerFactory.getLogger(JsonFactory.class); private static final String TEMPLATE_TYPE = "templateType"; protected static final String TEMPLATE_TYPE_ACHIEVEMENT = "Achievement"; protected static final String TEMPLATE_TYPE_BOOK = "Book"; @@ -75,24 +75,39 @@ public JSONObject convertInfoboxPartOfArticleToJson(@Nullable final String infob } @NotNull - public String convertJsonToInfoboxPartOfArticle(@Nullable JSONObject jsonObject) { + public String convertJsonToInfoboxPartOfArticle(@Nullable JSONObject jsonObject, List fieldOrder) { if (jsonObject == null || jsonObject.isEmpty()) { return ""; } + if (!jsonObject.has(TEMPLATE_TYPE)) { + LOG.error("Template type unknown for given json object: {}", jsonObject); + return ""; + } + StringBuilder sb = new StringBuilder(); sb.append("{{Infobox "); sb.append(jsonObject.get(TEMPLATE_TYPE)); sb.append("|List={{{1|}}}|GetValue={{{GetValue|}}}").append("\n"); int maxFieldLength = jsonObject.keySet().stream() - .mapToInt(String::length) - .max() - .orElse(0); + .mapToInt(String::length) + .max() + .orElse(0); - int maxKeyLength = maxFieldLength + 2; + for (String key : fieldOrder) { + + // don't add the metadata parameter templateType to the output + if (TEMPLATE_TYPE.equals(key)) { + continue; + } + + // simply skip fields we don't have, in most cases this is legit, an object doesn't need to have all fields + // of its class + if (!jsonObject.has(key)) { + continue; + } - for (String key : jsonObject.keySet()) { Object value = jsonObject.get(key); if (value instanceof JSONArray) { @@ -116,7 +131,7 @@ public String convertJsonToInfoboxPartOfArticle(@Nullable JSONObject jsonObject) } else if (value instanceof JSONObject) { } else { - String paddedKey = Strings.padEnd(key, maxKeyLength, ' '); + String paddedKey = Strings.padEnd(key, maxFieldLength, ' '); sb.append("| ") .append(paddedKey) .append(" = ") @@ -141,7 +156,7 @@ protected String getTemplateType(@Nullable final String infoboxTemplatePartOfArt .map(m -> m.group(1)) .filter(s -> !"".equals(s)) .orElseGet(() -> { - log.warn("Template type could not be determined from string {}", infoboxTemplatePartOfArticle); + LOG.warn("Template type could not be determined from string {}", infoboxTemplatePartOfArticle); return UNKNOWN; }); } @@ -224,7 +239,7 @@ protected String determineArticleName(@Nullable JSONObject jsonObject, @Nullable @NotNull private JSONArray makeSoundsArray(@Nullable String soundsValue, @NotNull String articleName) { if (soundsValue != null && soundsValue.length() > 2 && !soundsValue.contains("{{Sound List")) { - log.error("soundsValue '{}' from article '{}' does not contain Template:Sound List", soundsValue, articleName); + LOG.error("soundsValue '{}' from article '{}' does not contain Template:Sound List", soundsValue, articleName); return new JSONArray(); } @@ -257,7 +272,7 @@ private JSONArray makeLootTableArray(String lootValue) { } String lootItem = TemplateUtils.removeStartAndEndOfTemplate(lootItemTemplate); if (lootItem == null) { - log.error("Unable to create lootTableArray from lootValue: {}", lootValue); + LOG.error("Unable to create lootTableArray from lootValue: {}", lootValue); return new JSONArray(); } List splitLootItem = Arrays.asList(Pattern.compile("\\|").split(lootItem)); diff --git a/src/main/java/com/tibiawiki/domain/factories/WikiObjectFactory.java b/src/main/java/com/tibiawiki/domain/factories/WikiObjectFactory.java index f7a4041..c6b566d 100644 --- a/src/main/java/com/tibiawiki/domain/factories/WikiObjectFactory.java +++ b/src/main/java/com/tibiawiki/domain/factories/WikiObjectFactory.java @@ -1,8 +1,6 @@ package com.tibiawiki.domain.factories; -import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.databind.ObjectMapper; -import com.google.common.base.Strings; import com.tibiawiki.domain.objects.Achievement; import com.tibiawiki.domain.objects.Book; import com.tibiawiki.domain.objects.Building; @@ -24,11 +22,13 @@ import org.json.JSONObject; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import java.io.IOException; import java.util.Arrays; import java.util.List; +import java.util.Map; import java.util.stream.Stream; /** @@ -59,9 +59,9 @@ public class WikiObjectFactory { private ObjectMapper objectMapper; - public WikiObjectFactory() { - objectMapper = new ObjectMapper(); - objectMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL); + @Autowired + public WikiObjectFactory(ObjectMapper objectMapper) { + this.objectMapper = objectMapper; } public Stream createWikiObjects(List jsonObjects) { @@ -141,43 +141,14 @@ public WikiObject createWikiObject(JSONObject wikiObjectJson) { return wikiObject; } -// /** -// * Creates an Article from a WikiObject, for saving to the wiki. -// * The reverse is achieved by {@link #createWikiObject(JSONObject)} when reading from the wiki. -// */ -// public static Article createJSONObject(WikiBot wikiBot, WikiObject wikiObject) { -// return new Article(wikiBot, createSimpleArticle(wikiBot, wikiObject)); -// } -// -// private static SimpleArticle createSimpleArticle(WikiBot wikiBot, WikiObject wikiObject) { -// SimpleArticle simpleArticle = new SimpleArticle(); -// simpleArticle.setEditor(wikiBot.getUserinfo().getUsername()); -// simpleArticle.setEditTimestamp(new Date(ZonedDateTime.now().toEpochSecond())); -// simpleArticle.setTitle(wikiObject.getName()); -// simpleArticle.setText(createArticleText(wikiObject)); -// return simpleArticle; -// } - - protected static String createArticleText(WikiObject wikiObject) { - StringBuilder sb = new StringBuilder(); - sb.append("{{Infobox "); - sb.append(wikiObject.getClassName()); - sb.append("|List={{{1|}}}|GetValue={{{GetValue|}}}").append("\n"); - - int maxKeyLength = wikiObject.maxFieldSize() + 2; - - for (String key : wikiObject.getFieldNames()) { - Object value = wikiObject.getValue(key); - String paddedKey = Strings.padEnd(key, maxKeyLength, ' '); - sb.append("| ") - .append(paddedKey) - .append(" = ") - .append(value) - .append("\n"); - } - - sb.append("}}").append("\n"); - return sb.toString(); + /** + * Creates an Article from a WikiObject, for saving to the wiki. + * The reverse is achieved by {@link #createWikiObject(JSONObject)} when reading from the wiki. + */ + public JSONObject createJSONObject(WikiObject wikiObject, String templateType) { + final Map wikiObjectAsMap = objectMapper.convertValue(wikiObject, Map.class); + wikiObjectAsMap.put(TEMPLATE_TYPE, templateType); + return new JSONObject(wikiObjectAsMap); } private T mapJsonToObject(JSONObject wikiObjectJson, Class clazz) { diff --git a/src/main/java/com/tibiawiki/domain/jackson/WikiObjectMixin.java b/src/main/java/com/tibiawiki/domain/jackson/WikiObjectMixin.java new file mode 100644 index 0000000..365af9d --- /dev/null +++ b/src/main/java/com/tibiawiki/domain/jackson/WikiObjectMixin.java @@ -0,0 +1,47 @@ +package com.tibiawiki.domain.jackson; + +import com.fasterxml.jackson.annotation.JsonSubTypes; +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import com.tibiawiki.domain.objects.Achievement; +import com.tibiawiki.domain.objects.Book; +import com.tibiawiki.domain.objects.Building; +import com.tibiawiki.domain.objects.Corpse; +import com.tibiawiki.domain.objects.Creature; +import com.tibiawiki.domain.objects.Effect; +import com.tibiawiki.domain.objects.HuntingPlace; +import com.tibiawiki.domain.objects.Item; +import com.tibiawiki.domain.objects.Key; +import com.tibiawiki.domain.objects.Location; +import com.tibiawiki.domain.objects.Mount; +import com.tibiawiki.domain.objects.NPC; +import com.tibiawiki.domain.objects.Outfit; +import com.tibiawiki.domain.objects.Quest; +import com.tibiawiki.domain.objects.Spell; +import com.tibiawiki.domain.objects.Street; +import com.tibiawiki.domain.objects.TibiaObject; +import com.tibiawiki.domain.objects.WikiObject; + +@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "templateType") +@JsonSubTypes({ + @JsonSubTypes.Type(value = Achievement.class, name = "Achievement"), + @JsonSubTypes.Type(value = Book.class, name = "Book"), + @JsonSubTypes.Type(value = Building.class, name = "Building"), + @JsonSubTypes.Type(value = Corpse.class, name = "Corpse"), + @JsonSubTypes.Type(value = Creature.class, name = "Creature"), + @JsonSubTypes.Type(value = Effect.class, name = "Effect"), + @JsonSubTypes.Type(value = HuntingPlace.class, name = "Hunt"), + @JsonSubTypes.Type(value = Item.class, name = "Item"), + @JsonSubTypes.Type(value = Key.class, name = "Key"), + @JsonSubTypes.Type(value = Location.class, name = "Geography"), + @JsonSubTypes.Type(value = Mount.class, name = "Mount"), + @JsonSubTypes.Type(value = NPC.class, name = "NPC"), + @JsonSubTypes.Type(value = Outfit.class, name = "Outfit"), + @JsonSubTypes.Type(value = Quest.class, name = "Quest"), + @JsonSubTypes.Type(value = Spell.class, name = "Spell"), + @JsonSubTypes.Type(value = Street.class, name = "Street"), + @JsonSubTypes.Type(value = TibiaObject.class, name = "Object") +}) +public abstract class WikiObjectMixin extends WikiObject { + + +} diff --git a/src/main/java/com/tibiawiki/domain/objects/Achievement.java b/src/main/java/com/tibiawiki/domain/objects/Achievement.java index 0df2cd4..4954d25 100644 --- a/src/main/java/com/tibiawiki/domain/objects/Achievement.java +++ b/src/main/java/com/tibiawiki/domain/objects/Achievement.java @@ -1,34 +1,59 @@ package com.tibiawiki.domain.objects; -import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.tibiawiki.domain.enums.Grade; +import com.tibiawiki.domain.enums.Status; import com.tibiawiki.domain.enums.YesNo; import com.tibiawiki.domain.interfaces.Validatable; import com.tibiawiki.domain.objects.validation.ValidationResult; -import lombok.AccessLevel; +import lombok.Builder; import lombok.Getter; -import lombok.NoArgsConstructor; import org.springframework.stereotype.Component; import java.util.Arrays; import java.util.Collections; import java.util.List; -@JsonIgnoreProperties({"templateType"}) @Getter -@NoArgsConstructor(access = AccessLevel.PRIVATE) @Component public class Achievement extends WikiObject implements Validatable { - private Grade grade; - private String description; - private String spoiler; - private YesNo premium; - private Integer points; - private YesNo secret; - private Integer coincideswith; - private Integer achievementid; - private String relatedpages; + private final Grade grade; + private final String description; + private final String spoiler; + private final YesNo premium; + private final Integer points; + private final YesNo secret; + private final Integer coincideswith; + private final Integer achievementid; + private final String relatedpages; + + private Achievement() { + this.grade = null; + this.description = null; + this.spoiler = null; + this.premium = null; + this.points = null; + this.secret = null; + this.coincideswith = null; + this.achievementid = null; + this.relatedpages = null; + } + + @Builder + public Achievement(String name, String implemented, String history, Status status, Grade grade, String description, + String spoiler, YesNo premium, Integer points, YesNo secret, Integer coincideswith, + Integer achievementid, String relatedpages) { + super(name, null, null, null, implemented, null, history, status); + this.grade = grade; + this.description = description; + this.spoiler = spoiler; + this.premium = premium; + this.points = points; + this.secret = secret; + this.coincideswith = coincideswith; + this.achievementid = achievementid; + this.relatedpages = relatedpages; + } @Override public List fieldOrder() { diff --git a/src/main/java/com/tibiawiki/domain/objects/WikiObject.java b/src/main/java/com/tibiawiki/domain/objects/WikiObject.java index 9076470..a8aa5c5 100644 --- a/src/main/java/com/tibiawiki/domain/objects/WikiObject.java +++ b/src/main/java/com/tibiawiki/domain/objects/WikiObject.java @@ -3,95 +3,47 @@ import com.fasterxml.jackson.annotation.JsonIgnore; import com.tibiawiki.domain.enums.Article; import com.tibiawiki.domain.enums.Status; -import com.tibiawiki.domain.interfaces.Description; import lombok.Getter; -import java.lang.reflect.Field; -import java.util.ArrayList; import java.util.Arrays; import java.util.List; -import java.util.stream.Collectors; @Getter public abstract class WikiObject { - private String name; - private Article article; - private String actualname; - private String plural; - private String implemented; - private String notes; - private String history; - private Status status; + private final String name; + private final Article article; + private final String actualname; + private final String plural; + private final String implemented; + private final String notes; + private final String history; + private final Status status; protected WikiObject() { - // no-args constructor + name = null; + article = null; + actualname = null; + plural = null; + implemented = null; + notes = null; + history = null; + status = null; } - public abstract List fieldOrder(); - - @JsonIgnore - public List getFieldNames() { - List existingFieldNames = getFields().stream() - .map(Field::getName) - .collect(Collectors.toList()); - - return fieldOrder().stream() - .filter(existingFieldNames::contains) - .collect(Collectors.toList()); - } - - @JsonIgnore - public List getFields() { - List allFields = new ArrayList<>(); - - for (Class c = this.getClass(); c != null; c = c.getSuperclass()) { - Field[] fields = c.getDeclaredFields(); - allFields.addAll(Arrays.asList(fields)); - } - - return allFields.stream() - .filter(this::fieldHasValue) - .collect(Collectors.toList()); - } - - public int maxFieldSize() { - return getFieldNames().stream() - .mapToInt(String::length) - .max() - .orElse(0); + public WikiObject(String name, Article article, String actualname, String plural, String implemented, String notes, + String history, Status status) { + this.name = name; + this.article = article; + this.actualname = actualname; + this.plural = plural; + this.implemented = implemented; + this.notes = notes; + this.history = history; + this.status = status; } - @JsonIgnore - public Object getValue(String fieldName) { - return getFields().stream() - .filter(this::fieldHasValue) - .filter(f -> f.getName().equals(fieldName)) - .map(f -> { - try { - Object fieldValue = f.get(this); - - if (fieldValue instanceof Description) { - return ((Description) fieldValue).getDescription(); - } else { - return fieldValue; - } - } catch (IllegalAccessException e) { - throw new FieldAccessDeniedException(e); - } - }) - .findAny() - .orElse(null); - } - - private boolean fieldHasValue(Field f) { - try { - f.setAccessible(true); - return f.get(this) != null; - } catch (IllegalAccessException e) { - throw new FieldAccessDeniedException(e); - } - } + public abstract List fieldOrder(); @JsonIgnore public String getClassName() { @@ -114,11 +66,4 @@ public List fieldOrder() { return Arrays.asList("name", "article", "actualname", "plural", "implemented", "notes", "history", "status"); } } - - public static class FieldAccessDeniedException extends RuntimeException { - - public FieldAccessDeniedException(Exception e) { - super(e); - } - } } diff --git a/src/main/java/com/tibiawiki/domain/objects/validation/ValidationException.java b/src/main/java/com/tibiawiki/domain/objects/validation/ValidationException.java index 8532228..96ecc42 100644 --- a/src/main/java/com/tibiawiki/domain/objects/validation/ValidationException.java +++ b/src/main/java/com/tibiawiki/domain/objects/validation/ValidationException.java @@ -1,6 +1,7 @@ package com.tibiawiki.domain.objects.validation; import java.util.List; +import java.util.stream.Collectors; public class ValidationException extends RuntimeException { @@ -26,4 +27,17 @@ public ValidationException(List validationResults) { public static ValidationException fromResults(List validationResults) { return new ValidationException(validationResults); } + + public List getValidationResults() { + return validationResults; + } + + @Override + public String getMessage() { + return super.getMessage() != null + ? super.getMessage() + : validationResults != null && !validationResults.isEmpty() + ? validationResults.stream().map(ValidationResult::getDescription).collect(Collectors.joining(", ")) + : ""; + } } diff --git a/src/main/java/com/tibiawiki/domain/repositories/ArticleRepository.java b/src/main/java/com/tibiawiki/domain/repositories/ArticleRepository.java index 4be22f7..5f0cfac 100644 --- a/src/main/java/com/tibiawiki/domain/repositories/ArticleRepository.java +++ b/src/main/java/com/tibiawiki/domain/repositories/ArticleRepository.java @@ -17,6 +17,7 @@ @Repository public class ArticleRepository { + private static final boolean IS_DEBUG_ENABLED = true; private static final String DEFAULT_WIKI_URI = "https://tibia.fandom.com/api.php"; private Wiki wiki; @@ -55,7 +56,9 @@ public String getArticle(String pageName) { } public boolean modifyArticle(String pageName, String pageContent, String editSummary) { - return wiki.edit(pageName, pageContent, editSummary); + return IS_DEBUG_ENABLED + ? true + : wiki.edit(pageName, pageContent, editSummary); } private boolean login(Wiki wiki) { diff --git a/src/main/java/com/tibiawiki/process/ModifyAchievement.java b/src/main/java/com/tibiawiki/process/ModifyAchievement.java index 6105f53..fe9457c 100644 --- a/src/main/java/com/tibiawiki/process/ModifyAchievement.java +++ b/src/main/java/com/tibiawiki/process/ModifyAchievement.java @@ -1,8 +1,12 @@ package com.tibiawiki.process; +import com.tibiawiki.domain.factories.ArticleFactory; +import com.tibiawiki.domain.factories.JsonFactory; +import com.tibiawiki.domain.factories.WikiObjectFactory; import com.tibiawiki.domain.objects.Achievement; import com.tibiawiki.domain.objects.validation.ValidationException; import com.tibiawiki.domain.objects.validation.ValidationResult; +import com.tibiawiki.domain.repositories.ArticleRepository; import io.vavr.control.Try; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; @@ -19,16 +23,30 @@ public class ModifyAchievement { @Autowired - private RetrieveAchievements retrieveAchievements; + private WikiObjectFactory wikiObjectFactory; + @Autowired + private JsonFactory jsonFactory; + @Autowired + private ArticleFactory articleFactory; + @Autowired + private ArticleRepository articleRepository; private ModifyAchievement() { // nothing to do, all dependencies are injected } public Try modify(Achievement achievement, String editSummary) { + final String originalAchievement = articleRepository.getArticle(achievement.getName()); + return validate(achievement) -// .map(a -> retrieveAchievements.getAchievementJSON(a.getName())) - ; + .map(a -> wikiObjectFactory.createJSONObject(a, "Achievement")) + .map(json -> jsonFactory.convertJsonToInfoboxPartOfArticle(json, achievement.fieldOrder())) + .map(s -> articleFactory.insertInfoboxPartOfArticle(originalAchievement, s)) + .map(s -> articleRepository.modifyArticle(achievement.getName(), s, editSummary)) + .flatMap(b -> b + ? Try.success(achievement) + : Try.failure(new ValidationException("Unable to edit achievement.")) + ); } private Try validate(Achievement achievement) { diff --git a/src/main/java/com/tibiawiki/serviceinterface/AchievementsResource.java b/src/main/java/com/tibiawiki/serviceinterface/AchievementsResource.java index c77dd17..84c66e1 100644 --- a/src/main/java/com/tibiawiki/serviceinterface/AchievementsResource.java +++ b/src/main/java/com/tibiawiki/serviceinterface/AchievementsResource.java @@ -1,6 +1,7 @@ package com.tibiawiki.serviceinterface; import com.tibiawiki.domain.objects.Achievement; +import com.tibiawiki.domain.objects.validation.ValidationException; import com.tibiawiki.process.ModifyAchievement; import com.tibiawiki.process.RetrieveAchievements; import io.swagger.annotations.Api; @@ -86,6 +87,7 @@ public Response putAchievement(Achievement achievement, @HeaderParam("X-WIKI-Edi .entity(a) .header("Access-Control-Allow-Origin", "*") .build()) + .recover(ValidationException.class, e -> Response.status(Response.Status.BAD_REQUEST).entity(e.getMessage()).build()) .recover(e -> Response.serverError().build()) .get(); } diff --git a/src/test/java/com/tibiawiki/domain/factories/JsonFactoryTest.java b/src/test/java/com/tibiawiki/domain/factories/JsonFactoryTest.java index 447427f..c3043dc 100644 --- a/src/test/java/com/tibiawiki/domain/factories/JsonFactoryTest.java +++ b/src/test/java/com/tibiawiki/domain/factories/JsonFactoryTest.java @@ -1,5 +1,9 @@ package com.tibiawiki.domain.factories; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.tibiawiki.domain.enums.Grade; +import com.tibiawiki.domain.enums.YesNo; +import com.tibiawiki.domain.objects.Achievement; import org.json.JSONArray; import org.json.JSONObject; import org.junit.jupiter.api.BeforeEach; @@ -15,11 +19,13 @@ public class JsonFactoryTest { private JsonFactory target; + private ObjectMapper objectMapper; @BeforeEach public void setup() { target = new JsonFactory(); + objectMapper = new ObjectMapper(); } @Test @@ -177,8 +183,20 @@ public void testDetermineArticleName_Achievement() { assertThat(target.determineArticleName(input, JsonFactory.TEMPLATE_TYPE_ACHIEVEMENT), is("Foobar")); } - private String makeInfoboxPartOfArticle() { - return null; + @Test + void testConvertJsonToInfoboxPartOfArticle_Empty() { + assertThat(target.convertJsonToInfoboxPartOfArticle(null, Collections.emptyList()), is("")); + assertThat(target.convertJsonToInfoboxPartOfArticle(new JSONObject(), Collections.emptyList()), is("")); + + final JSONObject jsonWithNoTemplateType = makeAchievementJson(makeAchievement()); + jsonWithNoTemplateType.remove("templateType"); + assertThat(target.convertJsonToInfoboxPartOfArticle(jsonWithNoTemplateType, Collections.emptyList()), is("")); + } + + @Test + void testConvertJsonToInfoboxPartOfArticle_Simple() { + String result = target.convertJsonToInfoboxPartOfArticle(makeAchievementJson(makeAchievement()), makeAchievement().fieldOrder()); + assertThat(result, is(INFOBOX__ACHIEVEMENT_TEXT)); } private static final String INFOBOX_TEXT_SPACE = "{{Infobox Achievement|List={{{1|}}}|GetValue={{{GetValue|}}}\n" + @@ -192,17 +210,17 @@ private String makeInfoboxPartOfArticle() { private static final String INFOBOX_TEXT_WRONG = "{{Infobax_Hunt \n|List={{{1|}}}|GetValue={{{GetValue|}}}"; private static final String INFOBOX__ACHIEVEMENT_TEXT = "{{Infobox Achievement|List={{{1|}}}|GetValue={{{GetValue|}}}\n" + - "| grade = 1\n" + - "| name = Goo Goo Dancer\n" + - "| description = Seeing a mucus plug makes your heart dance and you can't resist to see what it hides. Goo goo away!\n" + - "| spoiler = Obtainable by using 100 [[Muck Remover]]s on [[Mucus Plug]]s.\n" + - "| premium = yes\n" + - "| points = 1\n" + - "| secret = yes\n" + - "| implemented = 9.6\n" + + "| grade = 1\n" + + "| name = Goo Goo Dancer\n" + + "| description = Seeing a mucus plug makes your heart dance and you can't resist to see what it hides. Goo goo away!\n" + + "| spoiler = Obtainable by using 100 [[Muck Remover]]s on [[Mucus Plug]]s.\n" + + "| premium = yes\n" + + "| points = 1\n" + + "| secret = yes\n" + + "| implemented = 9.6\n" + "| achievementid = 319\n" + - "| relatedpages = [[Muck Remover]], [[Mucus Plug]]\n" + - "}}"; + "| relatedpages = [[Muck Remover]], [[Mucus Plug]]\n" + + "}}\n"; private static final String INFOBOX_HUNT_TEXT = "{{Infobox Hunt|List={{{1|}}}|GetValue={{{GetValue|}}}\n" + "| name = Hero Cave\n" + @@ -244,4 +262,22 @@ private String makeInfoboxPartOfArticle() { "| map2 = Hero Cave 6.png\n" + "}}"; + private Achievement makeAchievement() { + return Achievement.builder() + .grade(Grade.ONE) + .name("Goo Goo Dancer") + .description("Seeing a mucus plug makes your heart dance and you can't resist to see what it hides. Goo goo away!") + .spoiler("Obtainable by using 100 [[Muck Remover]]s on [[Mucus Plug]]s.") + .premium(YesNo.YES_LOWERCASE) + .points(1) + .secret(YesNo.YES_LOWERCASE) + .implemented("9.6") + .achievementid(319) + .relatedpages("[[Muck Remover]], [[Mucus Plug]]") + .build(); + } + + private JSONObject makeAchievementJson(Achievement achievement) { + return new JSONObject(objectMapper.convertValue(achievement, Map.class)).put("templateType", "Achievement"); + } } \ No newline at end of file diff --git a/src/test/java/com/tibiawiki/domain/objects/WikiObjectTest.java b/src/test/java/com/tibiawiki/domain/objects/WikiObjectTest.java deleted file mode 100644 index 3dbd6bb..0000000 --- a/src/test/java/com/tibiawiki/domain/objects/WikiObjectTest.java +++ /dev/null @@ -1,39 +0,0 @@ -package com.tibiawiki.domain.objects; - -import org.junit.Before; -import org.junit.Ignore; -import org.junit.Test; - -import java.util.List; - -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.hasSize; - -public class WikiObjectTest { - - private WikiObject target; - - @Before - public void setup() { - - } - - @Ignore - @Test - public void testGetFields_WikiObject() { - target = makeWikiObject(); - - List result = target.getFieldNames(); - - assertThat(result, hasSize(3)); - } - - - private WikiObject makeWikiObject() { - WikiObject wikiObject = new WikiObject.WikiObjectImpl(); -// wikiObject.setActualname("bear"); -// wikiObject.setArticle(Article.A); -// wikiObject.setStatus(Status.ACTIVE); - return wikiObject; - } -} From 6f58bdd9234dee0c0e4137b881917ad78899dae2 Mon Sep 17 00:00:00 2001 From: Benjamin Komen Date: Sat, 17 Nov 2018 20:10:30 +0100 Subject: [PATCH 06/19] Expanding JsonFactory to support serialisation of books as well. Other types are work in progress. --- .../domain/factories/JsonFactory.java | 20 +- .../domain/jackson/WikiObjectMixin.java | 2 +- .../tibiawiki/domain/objects/Achievement.java | 6 +- .../com/tibiawiki/domain/objects/Book.java | 244 ++++++--- .../tibiawiki/domain/objects/WikiObject.java | 15 +- .../com/tibiawiki/domain/utils/ListUtil.java | 20 + .../domain/factories/JsonFactoryTest.java | 500 +++++++++++++++++- 7 files changed, 708 insertions(+), 99 deletions(-) create mode 100644 src/main/java/com/tibiawiki/domain/utils/ListUtil.java diff --git a/src/main/java/com/tibiawiki/domain/factories/JsonFactory.java b/src/main/java/com/tibiawiki/domain/factories/JsonFactory.java index 1b92528..1a9421f 100644 --- a/src/main/java/com/tibiawiki/domain/factories/JsonFactory.java +++ b/src/main/java/com/tibiawiki/domain/factories/JsonFactory.java @@ -90,21 +90,12 @@ public String convertJsonToInfoboxPartOfArticle(@Nullable JSONObject jsonObject, sb.append(jsonObject.get(TEMPLATE_TYPE)); sb.append("|List={{{1|}}}|GetValue={{{GetValue|}}}").append("\n"); - int maxFieldLength = jsonObject.keySet().stream() - .mapToInt(String::length) - .max() - .orElse(0); - for (String key : fieldOrder) { // don't add the metadata parameter templateType to the output - if (TEMPLATE_TYPE.equals(key)) { - continue; - } - // simply skip fields we don't have, in most cases this is legit, an object doesn't need to have all fields // of its class - if (!jsonObject.has(key)) { + if (TEMPLATE_TYPE.equals(key) || !jsonObject.has(key)) { continue; } @@ -131,7 +122,7 @@ public String convertJsonToInfoboxPartOfArticle(@Nullable JSONObject jsonObject, } else if (value instanceof JSONObject) { } else { - String paddedKey = Strings.padEnd(key, maxFieldLength, ' '); + String paddedKey = Strings.padEnd(key, getMaxFieldLength(jsonObject), ' '); sb.append("| ") .append(paddedKey) .append(" = ") @@ -333,4 +324,11 @@ private JSONArray makeLowerLevelsArray(String lowerLevelsValue) { private boolean legallyHasNoDroppedByTemplate(String name) { return ITEMS_WITH_NO_DROPPEDBY_LIST.contains(name); } + + private int getMaxFieldLength(@NotNull JSONObject jsonObject) { + return jsonObject.keySet().stream() + .mapToInt(String::length) + .max() + .orElse(0); + } } diff --git a/src/main/java/com/tibiawiki/domain/jackson/WikiObjectMixin.java b/src/main/java/com/tibiawiki/domain/jackson/WikiObjectMixin.java index 365af9d..dd6ab98 100644 --- a/src/main/java/com/tibiawiki/domain/jackson/WikiObjectMixin.java +++ b/src/main/java/com/tibiawiki/domain/jackson/WikiObjectMixin.java @@ -21,7 +21,7 @@ import com.tibiawiki.domain.objects.TibiaObject; import com.tibiawiki.domain.objects.WikiObject; -@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "templateType") +@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "templateType", visible = true) @JsonSubTypes({ @JsonSubTypes.Type(value = Achievement.class, name = "Achievement"), @JsonSubTypes.Type(value = Book.class, name = "Book"), diff --git a/src/main/java/com/tibiawiki/domain/objects/Achievement.java b/src/main/java/com/tibiawiki/domain/objects/Achievement.java index 4954d25..04b89e8 100644 --- a/src/main/java/com/tibiawiki/domain/objects/Achievement.java +++ b/src/main/java/com/tibiawiki/domain/objects/Achievement.java @@ -3,8 +3,8 @@ import com.tibiawiki.domain.enums.Grade; import com.tibiawiki.domain.enums.Status; import com.tibiawiki.domain.enums.YesNo; -import com.tibiawiki.domain.interfaces.Validatable; import com.tibiawiki.domain.objects.validation.ValidationResult; +import com.tibiawiki.domain.utils.ListUtil; import lombok.Builder; import lombok.Getter; import org.springframework.stereotype.Component; @@ -15,7 +15,7 @@ @Getter @Component -public class Achievement extends WikiObject implements Validatable { +public class Achievement extends WikiObject { private final Grade grade; private final String description; @@ -63,6 +63,6 @@ public List fieldOrder() { @Override public List validate() { - return Collections.emptyList(); + return ListUtil.concatenate(super.validate(), Collections.emptyList()); } } \ No newline at end of file diff --git a/src/main/java/com/tibiawiki/domain/objects/Book.java b/src/main/java/com/tibiawiki/domain/objects/Book.java index 4ad0e3c..34dcbf7 100644 --- a/src/main/java/com/tibiawiki/domain/objects/Book.java +++ b/src/main/java/com/tibiawiki/domain/objects/Book.java @@ -1,78 +1,200 @@ package com.tibiawiki.domain.objects; -import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.tibiawiki.domain.enums.BookType; -import lombok.AccessLevel; +import com.tibiawiki.domain.enums.Status; +import lombok.Builder; import lombok.Getter; -import lombok.NoArgsConstructor; import org.springframework.stereotype.Component; -import java.util.Collections; +import java.util.Arrays; import java.util.List; -@JsonIgnoreProperties({"templateType"}) @Getter -@NoArgsConstructor(access = AccessLevel.PRIVATE) @Component public class Book extends WikiObject { - private BookType booktype; - private BookType booktype2; - private BookType booktype3; - private BookType booktype4; - private BookType booktype5; - private BookType booktype6; - private BookType booktype7; - private BookType booktype8; - private String title; - private String pagename; - private String location; - private String location2; - private String location3; - private String location4; - private String location5; - private String location6; - private String location7; - private String location8; - private String blurb; - private String author; - private String returnpage; - private String returnpage2; - private String returnpage3; - private String returnpage4; - private String returnpage5; - private String returnpage6; - private String returnpage7; - private String returnpage8; - private String returnpage9; - private String returnpage10; - private String returnpage11; - private String returnpage12; - private String returnpage13; - private String returnpage14; - private String returnpage15; - private String returnpage16; - private String prevbook; - private String nextbook; - private String relatedpages; - private String text; - private String text2; - private String text3; - private String text4; - private String text5; - private String text6; - private String text7; - private String text8; - private String implemented2; - private String implemented3; - private String implemented4; - private String implemented5; - private String implemented6; - private String implemented7; - private String implemented8; + private final BookType booktype; + private final BookType booktype2; + private final BookType booktype3; + private final BookType booktype4; + private final BookType booktype5; + private final BookType booktype6; + private final BookType booktype7; + private final BookType booktype8; + private final String title; + private final String pagename; + private final String location; + private final String location2; + private final String location3; + private final String location4; + private final String location5; + private final String location6; + private final String location7; + private final String location8; + private final String blurb; + private final String author; + private final String returnpage; + private final String returnpage2; + private final String returnpage3; + private final String returnpage4; + private final String returnpage5; + private final String returnpage6; + private final String returnpage7; + private final String returnpage8; + private final String returnpage9; + private final String returnpage10; + private final String returnpage11; + private final String returnpage12; + private final String returnpage13; + private final String returnpage14; + private final String returnpage15; + private final String returnpage16; + private final String prevbook; + private final String nextbook; + private final String relatedpages; + private final String text; + private final String text2; + private final String text3; + private final String text4; + private final String text5; + private final String text6; + private final String text7; + private final String text8; + private final String implemented2; + private final String implemented3; + private final String implemented4; + private final String implemented5; + private final String implemented6; + private final String implemented7; + private final String implemented8; + + private Book() { + this.booktype = null; + this.booktype2 = null; + this.booktype3 = null; + this.booktype4 = null; + this.booktype5 = null; + this.booktype6 = null; + this.booktype7 = null; + this.booktype8 = null; + this.title = null; + this.pagename = null; + this.location = null; + this.location2 = null; + this.location3 = null; + this.location4 = null; + this.location5 = null; + this.location6 = null; + this.location7 = null; + this.location8 = null; + this.blurb = null; + this.author = null; + this.returnpage = null; + this.returnpage2 = null; + this.returnpage3 = null; + this.returnpage4 = null; + this.returnpage5 = null; + this.returnpage6 = null; + this.returnpage7 = null; + this.returnpage8 = null; + this.returnpage9 = null; + this.returnpage10 = null; + this.returnpage11 = null; + this.returnpage12 = null; + this.returnpage13 = null; + this.returnpage14 = null; + this.returnpage15 = null; + this.returnpage16 = null; + this.prevbook = null; + this.nextbook = null; + this.relatedpages = null; + this.text = null; + this.text2 = null; + this.text3 = null; + this.text4 = null; + this.text5 = null; + this.text6 = null; + this.text7 = null; + this.text8 = null; + this.implemented2 = null; + this.implemented3 = null; + this.implemented4 = null; + this.implemented5 = null; + this.implemented6 = null; + this.implemented7 = null; + this.implemented8 = null; + } + + @Builder + public Book(String name, String implemented, String notes, String history, Status status, BookType booktype, String title, + String pagename, String location, String blurb, String author, String returnpage, String prevbook, + String nextbook, String relatedpages, String text) { + super(name, null, null, null, implemented, notes, history, status); + this.booktype = booktype; + this.booktype2 = null; + this.booktype3 = null; + this.booktype4 = null; + this.booktype5 = null; + this.booktype6 = null; + this.booktype7 = null; + this.booktype8 = null; + this.title = title; + this.pagename = pagename; + this.location = location; + this.location2 = null; + this.location3 = null; + this.location4 = null; + this.location5 = null; + this.location6 = null; + this.location7 = null; + this.location8 = null; + this.blurb = blurb; + this.author = author; + this.returnpage = returnpage; + this.returnpage2 = null; + this.returnpage3 = null; + this.returnpage4 = null; + this.returnpage5 = null; + this.returnpage6 = null; + this.returnpage7 = null; + this.returnpage8 = null; + this.returnpage9 = null; + this.returnpage10 = null; + this.returnpage11 = null; + this.returnpage12 = null; + this.returnpage13 = null; + this.returnpage14 = null; + this.returnpage15 = null; + this.returnpage16 = null; + this.prevbook = prevbook; + this.nextbook = nextbook; + this.relatedpages = relatedpages; + this.text = text; + this.text2 = null; + this.text3 = null; + this.text4 = null; + this.text5 = null; + this.text6 = null; + this.text7 = null; + this.text8 = null; + this.implemented2 = null; + this.implemented3 = null; + this.implemented4 = null; + this.implemented5 = null; + this.implemented6 = null; + this.implemented7 = null; + this.implemented8 = null; + } @Override public List fieldOrder() { - return Collections.emptyList(); + return Arrays.asList("booktype", "booktype2", "booktype3", "booktype4", "booktype5", "booktype6", "booktype7", + "booktype8", "title", "pagename", "location", "location2", "location3", "location4", "location5", + "location6", "location7", "location8", "blurb", "author", "returnpage", "returnpage2", "returnpage3", + "returnpage4", "returnpage5", "returnpage6", "returnpage7", "returnpage8", "returnpage9", + "returnpage10", "returnpage11", "returnpage12", "returnpage13", "returnpage14", "returnpage15", + "returnpage16", "prevbook", "nextbook", "relatedpages", "notes", "text", "text2", "text3", "text4", + "text5", "text6", "text7", "text8", "implemented", "implemented2", "implemented3", "implemented4", + "implemented5", "implemented6", "implemented7", "implemented8", "history", "status"); } } \ No newline at end of file diff --git a/src/main/java/com/tibiawiki/domain/objects/WikiObject.java b/src/main/java/com/tibiawiki/domain/objects/WikiObject.java index a8aa5c5..5daac60 100644 --- a/src/main/java/com/tibiawiki/domain/objects/WikiObject.java +++ b/src/main/java/com/tibiawiki/domain/objects/WikiObject.java @@ -3,13 +3,16 @@ import com.fasterxml.jackson.annotation.JsonIgnore; import com.tibiawiki.domain.enums.Article; import com.tibiawiki.domain.enums.Status; +import com.tibiawiki.domain.interfaces.Validatable; +import com.tibiawiki.domain.objects.validation.ValidationResult; import lombok.Getter; import java.util.Arrays; +import java.util.Collections; import java.util.List; @Getter -public abstract class WikiObject { +public abstract class WikiObject implements Validatable { private final String name; private final Article article; @@ -55,6 +58,11 @@ public String toString() { return "Class: " + getClassName() + ", name: " + getName(); } + @Override + public List validate() { + return Collections.emptyList(); + } + public static class WikiObjectImpl extends WikiObject { public WikiObjectImpl() { @@ -65,5 +73,10 @@ public WikiObjectImpl() { public List fieldOrder() { return Arrays.asList("name", "article", "actualname", "plural", "implemented", "notes", "history", "status"); } + + @Override + public List validate() { + return Collections.emptyList(); + } } } diff --git a/src/main/java/com/tibiawiki/domain/utils/ListUtil.java b/src/main/java/com/tibiawiki/domain/utils/ListUtil.java new file mode 100644 index 0000000..6601a27 --- /dev/null +++ b/src/main/java/com/tibiawiki/domain/utils/ListUtil.java @@ -0,0 +1,20 @@ +package com.tibiawiki.domain.utils; + +import java.util.Arrays; +import java.util.Collection; +import java.util.List; +import java.util.stream.Collectors; + +public class ListUtil { + + private ListUtil() { + // don't instantiate this class, it has only static members + } + + @SafeVarargs + public static List concatenate(List... collections) { + return Arrays.stream(collections) + .flatMap(Collection::stream) + .collect(Collectors.toList()); + } +} diff --git a/src/test/java/com/tibiawiki/domain/factories/JsonFactoryTest.java b/src/test/java/com/tibiawiki/domain/factories/JsonFactoryTest.java index c3043dc..d1859c3 100644 --- a/src/test/java/com/tibiawiki/domain/factories/JsonFactoryTest.java +++ b/src/test/java/com/tibiawiki/domain/factories/JsonFactoryTest.java @@ -1,9 +1,11 @@ package com.tibiawiki.domain.factories; import com.fasterxml.jackson.databind.ObjectMapper; +import com.tibiawiki.domain.enums.BookType; import com.tibiawiki.domain.enums.Grade; import com.tibiawiki.domain.enums.YesNo; import com.tibiawiki.domain.objects.Achievement; +import com.tibiawiki.domain.objects.Book; import org.json.JSONArray; import org.json.JSONObject; import org.junit.jupiter.api.BeforeEach; @@ -36,7 +38,7 @@ public void testConvertInfoboxPartOfArticleToJson_NullOrEmpty() { @Test public void testConvertInfoboxPartOfArticleToJson_InfoboxAchievement() { - JSONObject result = target.convertInfoboxPartOfArticleToJson(INFOBOX__ACHIEVEMENT_TEXT); + JSONObject result = target.convertInfoboxPartOfArticleToJson(INFOBOX_ACHIEVEMENT_TEXT); assertThat(result.get("templateType"), is("Achievement")); assertThat(result.get("grade"), is("1")); @@ -194,9 +196,17 @@ void testConvertJsonToInfoboxPartOfArticle_Empty() { } @Test - void testConvertJsonToInfoboxPartOfArticle_Simple() { - String result = target.convertJsonToInfoboxPartOfArticle(makeAchievementJson(makeAchievement()), makeAchievement().fieldOrder()); - assertThat(result, is(INFOBOX__ACHIEVEMENT_TEXT)); + void testConvertJsonToInfoboxPartOfArticle_Achievement() { + final Achievement achievement = makeAchievement(); + String result = target.convertJsonToInfoboxPartOfArticle(makeAchievementJson(achievement), achievement.fieldOrder()); + assertThat(result, is(INFOBOX_ACHIEVEMENT_TEXT)); + } + + @Test + void testConvertJsonToInfoboxPartOfArticle_Book() { + final Book book = makeBook(); + String result = target.convertJsonToInfoboxPartOfArticle(makeBookJson(book), book.fieldOrder()); + assertThat(result, is(INFOBOX_BOOK_TEXT)); } private static final String INFOBOX_TEXT_SPACE = "{{Infobox Achievement|List={{{1|}}}|GetValue={{{GetValue|}}}\n" + @@ -209,7 +219,7 @@ void testConvertJsonToInfoboxPartOfArticle_Simple() { private static final String INFOBOX_TEXT_WRONG = "{{Infobax_Hunt \n|List={{{1|}}}|GetValue={{{GetValue|}}}"; - private static final String INFOBOX__ACHIEVEMENT_TEXT = "{{Infobox Achievement|List={{{1|}}}|GetValue={{{GetValue|}}}\n" + + private static final String INFOBOX_ACHIEVEMENT_TEXT = "{{Infobox Achievement|List={{{1|}}}|GetValue={{{GetValue|}}}\n" + "| grade = 1\n" + "| name = Goo Goo Dancer\n" + "| description = Seeing a mucus plug makes your heart dance and you can't resist to see what it hides. Goo goo away!\n" + @@ -222,6 +232,240 @@ void testConvertJsonToInfoboxPartOfArticle_Simple() { "| relatedpages = [[Muck Remover]], [[Mucus Plug]]\n" + "}}\n"; + private Achievement makeAchievement() { + return Achievement.builder() + .grade(Grade.ONE) + .name("Goo Goo Dancer") + .description("Seeing a mucus plug makes your heart dance and you can't resist to see what it hides. Goo goo away!") + .spoiler("Obtainable by using 100 [[Muck Remover]]s on [[Mucus Plug]]s.") + .premium(YesNo.YES_LOWERCASE) + .points(1) + .secret(YesNo.YES_LOWERCASE) + .implemented("9.6") + .achievementid(319) + .relatedpages("[[Muck Remover]], [[Mucus Plug]]") + .build(); + } + + private JSONObject makeAchievementJson(Achievement achievement) { + return new JSONObject(objectMapper.convertValue(achievement, Map.class)).put("templateType", "Achievement"); + } + + private static final String INFOBOX_BOOK_TEXT = "{{Infobox Book|List={{{1|}}}|GetValue={{{GetValue|}}}\n" + + "| booktype = Book (Brown)\n" + + "| title = Dungeon Survival Guide\n" + + "| pagename = Dungeon Survival Guide (Book)\n" + + "| location = [[Rookgaard Academy]]\n" + + "| blurb = Tips for exploring dungeons, and warning against being reckless.\n" + + "| returnpage = Rookgaard Libraries\n" + + "| relatedpages = [[Rope]], [[Shovel]]\n" + + "| text = Dungeon Survival Guide

Don't explore the dungeons before you tested your skills" + + " in the training cellars of our academy. You will find dungeons somewhere in the wilderness. Don't enter" + + " dungeons without equipment. Especially a rope and a shovel will prove valuable. Make sure you have a" + + " supply of torches with you, while wandering into the unknown. It's wise to travel the dungeons in groups" + + " and not alone. For more help read all the books of the academy before you begin exploring. Traveling in" + + " the dungeons will reward the cautious and brave, but punish the reckless.\n" + + "}}\n"; + + private Book makeBook() { + return Book.builder() + .booktype(BookType.BOOK_BROWN) + .title("Dungeon Survival Guide") + .pagename("Dungeon Survival Guide (Book)") + .location("[[Rookgaard Academy]]") + .blurb("Tips for exploring dungeons, and warning against being reckless.") + .returnpage("Rookgaard Libraries") + .relatedpages("[[Rope]], [[Shovel]]") + .text("Dungeon Survival Guide

Don't explore the dungeons before you tested your skills" + + " in the training cellars of our academy. You will find dungeons somewhere in the wilderness. Don't enter" + + " dungeons without equipment. Especially a rope and a shovel will prove valuable. Make sure you have a" + + " supply of torches with you, while wandering into the unknown. It's wise to travel the dungeons in groups" + + " and not alone. For more help read all the books of the academy before you begin exploring. Traveling in" + + " the dungeons will reward the cautious and brave, but punish the reckless.") + .build(); + } + + private JSONObject makeBookJson(Book book) { + return new JSONObject(objectMapper.convertValue(book, Map.class)).put("templateType", "Book"); + } + + private static final String INFOBOX_BUILDING_TEXT = "{{Infobox Building|List={{{1|}}}|GetValue={{{GetValue|}}}\n" + + "| name = Theater Avenue 8b\n" + + "| implemented = Pre-6.0\n" + + "| type = House\n" + + "| location = South-east of depot, two floors up.\n" + + "| posx = 126.101\n" + + "| posy = 124.48\n" + + "| posz = 5\n" + + "| street = Theater Avenue\n" + + "| houseid = 20315\n" + + "| size = 26\n" + + "| beds = 3\n" + + "| rent = 1370\n" + + "| city = Carlin\n" + + "| openwindows = 3\n" + + "| floors = 1\n" + + "| rooms = 1\n" + + "| furnishings = 1 [[Wall Lamp]].\n" + + "| notes = \n" + + "| image = [[File:Theater Avenue 8b.png]]\n" + + "}}\n"; + + private static final String INFOBOX_CORPSE_TEXT = "{{Infobox Corpse|List={{{1|}}}|GetValue={{{GetValue|}}}\n" + + "| name = Dead Rat\n" + + "| article = a\n" + + "| liquid = [[Blood]]\n" + + "| 1volume = 5\n" + + "| 1weight = 63.00\n" + + "| 2weight = 44.00\n" + + "| 3weight = 30.00\n" + + "| 1decaytime = 5 minutes.\n" + + "| 2decaytime = 5 minutes.\n" + + "| 3decaytime = 60 seconds.\n" + + "| 1npcvalue = 2\n" + + "| corpseof = [[Rat]], [[Cave Rat]], [[Munster]]\n" + + "| sellto = [[Tom]] ([[Rookgaard]]) '''2''' [[gp]]
[[Seymour]] ([[Rookgaard]]) '''2''' [[gp]]" + + "
[[Billy]] ([[Rookgaard]]) '''2''' [[gp]]
[[Humgolf]] ([[Kazordoon]]) '''2''' [[gp]]
\n" + + "[[Baxter]] ([[Thais]]) '''1''' [[gp]]
\n" + + "| implemented = Pre-6.0\n" + + "| notes = These corpses are commonly used by low level players on [[Rookgaard]] to earn some gold" + + " for better [[equipment]]. Only fresh corpses are accepted, rotted corpses are ignored.\n" + + "}}\n"; + + private static final String INFOBOX_CREATURE_TEXT = "{{Infobox Creature|List={{{1|}}}|GetValue={{{GetValue|}}}\n" + + "| name = Dragon\n" + + "| article = a\n" + + "| actualname = dragon\n" + + "| plural = dragons\n" + + "| implemented = Pre-6.0\n" + + "| hp = 1000\n" + + "| exp = 700\n" + + "| summon = --\n" + + "| convince = --\n" + + "| illusionable = yes\n" + + "| creatureclass = Reptiles\n" + + "| primarytype = Dragons\n" + + "| bestiaryclass = Dragon\n" + + "| bestiarylevel = Medium\n" + + "| occurrence = Common\n" + + "| isboss = no\n" + + "| isarenaboss = no\n" + + "| abilities = [[Melee]] (0-120), [[Fire Wave]] (100-170), [[Great Fireball]] (60-140), [[Self-Healing]] (40-70)\n" + + "| maxdmg = 430\n" + + "| armor = 25\n" + + "| pushable = No\n" + + "| pushobjects = Yes\n" + + "| walksthrough = Fire, Energy, Poison\n" + + "| walksaround = None\n" + + "| paraimmune = yes\n" + + "| senseinvis = yes\n" + + "| physicalDmgMod = 100%\n" + + "| holyDmgMod = 100%\n" + + "| deathDmgMod = 100%\n" + + "| fireDmgMod = 0%\n" + + "| energyDmgMod = 80%\n" + + "| iceDmgMod = 110%\n" + + "| earthDmgMod = 20%\n" + + "| drownDmgMod = 100%?\n" + + "| hpDrainDmgMod = 100%?\n" + + "| bestiaryname = dragon\n" + + "| bestiarytext = Dragons were among the first creatures of Tibia and once ruled the whole continent." + + " Nowadays, there are only a few of them left which live deep in the dungeons. Nevertheless, they are very" + + " powerful monsters and will strive for killing every intruder. Besides their immense strength, they shoot" + + " fireballs at their victims and spit fire. Moreover, they can heal themselves.\n" + + "| sounds = {{Sound List|FCHHHHH|GROOAAARRR}}\n" + + "| notes = Dragons are very slow-moving, but have a potent set of attacks. A [[mage]] or" + + " [[paladin]] can kill one without taking any damage once they master the art. These creatures can be" + + " skinned with an [[Obsidian Knife]]. See also: [[Green Dragon Leather/Skinning]].\n" + + "| behaviour = Dragons are known to [[Retargeting|retarget]]. This often causes shooters in a team" + + " hunt to be burned or killed.\n" + + "| runsat = 300\n" + + "| speed = 86\n" + + "| location = [[Thais]] [[Ancient Temple]], [[Darashia Dragon Lair]], [[Mount Sternum Dragon Cave]]," + + " [[Mintwallin]], deep in [[Fibula Dungeon]], [[Kazordoon Dragon Lair]] (near [[Dwarf Bridge]]), [[Plains" + + " of Havoc]], [[Elven Bane]] castle, [[Maze of Lost Souls]], southern cave and dragon tower in" + + " [[Shadowthorn]], [[Orc Fortress]], [[Venore]] [[Dragon Lair]], [[Pits of Inferno]], [[Behemoth Quest]]" + + " room in [[Edron]], [[Hero Cave]], deep [[Cyclopolis]], [[Edron Dragon Lair]], [[Goroma]], [[Ankrahmun" + + " Dragon Lair]]s, [[Draconia]], [[Dragonblaze Peaks]], some [[Ankrahmun Tombs]], underground of [[Fenrock]]" + + " (on the way to [[Beregar]]), [[Krailos Steppe]] and [[Crystal Lakes]].\n" + + "| strategy = '''All''' [[player]]s should stand diagonal from the dragon, whenever possible, to" + + " avoid the [[Fire Wave]].\n" + + " \n" + + "'''[[Knight]]s''': Only one knight should be present in a team hunt, as they, the [[Blocking|blocker]]," + + " must be able to move freely around the dragon and to maintain their diagonal position as the dragon" + + " takes a step. It is quite easy for a knight of [[level]] 40 or higher to block a dragon without using" + + " any Health Potions at all. Around level 60 a knight with good skills (70/70) can hunt dragons with little" + + " waste and possibly profit. Remember to stand diagonal to it and always be prepared to use" + + " [[Health Potion|potions]]. A level 80+ knight can hunt dragons using only food and" + + " [[Pair of Soft Boots|Soft Boots]].
\n" + + "'''[[Mage]]s''' of level 28 or higher can kill dragons without help from other players, but you need to be" + + " very careful. They can [[Summon]] two [[Demon Skeleton]]s and drink a few extra [[Mana Potion]]s" + + " afterwards. They should try to keep enough [[mana]] to heal, if needed. They should enter, lure the" + + " dragon out, attack it with the demon skeletons, then move to a different floor so the dragon will target" + + " the demon skeletons. It is advisable to move to a space about 3 squares diagonal and use a strike spell" + + " ([[Ice Strike]] if possible) or [[Icicle Rune]]s to kill faster. Heal when your hit points drop below" + + " 250-280. Druids level 35 or higher, can use [[Mass Healing]] to prevent their summons from dying," + + " otherwise use [[Healing Runes]]. This is a reasonably cheap way to hunt dragons although the demon" + + " skeletons also gain a share of the experience.
\n" + + "'''[[Paladin]]s''' with a distance skill of 60+ and enough hit points to survive a fire attack are welcome" + + " additions to a team dragon hunt. Just be sure to have the [[Divine Healing]] spell ready to use, and " + + "stand where you can also escape if the dragon retargets. A paladin's ability to solo a dragon depends" + + " greatly on the terrain. A dragon's melee is weaker than their area attacks, so it would be advisable to" + + " stand diagonal the Dragon but only 1 sqm away, while shooting [[Royal Spear]]s or [[Enchanted Spear]]s." + + " A level 20 paladin with skills 65+ may attempt to solo a single dragon spawn but will have to bring some" + + " potions. Killing a dragon at this level will only prove your strength as a paladin will spend" + + " approximately 500 [[gp]]s per dragon and the chance of dying is very high if not careful. It is advisable" + + " to bring some [[Icicle Rune|Icicles]] or [[Avalanche Rune]]s if facing two or more of them.\n" + + "| loot = {{Loot Table\n" + + " |{{Loot Item|0-105|Gold Coin}}\n" + + " |{{Loot Item|0-3|Dragon Ham}}\n" + + " |{{Loot Item|Steel Shield}}\n" + + " |{{Loot Item|Crossbow}}\n" + + " |{{Loot Item|Dragon's Tail}}\n" + + " |{{Loot Item|0-10|Burst Arrow}}\n" + + " |{{Loot Item|Longsword|semi-rare}}\n" + + " |{{Loot Item|Steel Helmet|semi-rare}}\n" + + " |{{Loot Item|Broadsword|semi-rare}}\n" + + " |{{Loot Item|Plate Legs|semi-rare}}\n" + + " |{{Loot Item|Green Dragon Leather|rare}}\n" + + " |{{Loot Item|Wand of Inferno|rare}}\n" + + " |{{Loot Item|Strong Health Potion|rare}}\n" + + " |{{Loot Item|Green Dragon Scale|rare}}\n" + + " |{{Loot Item|Double Axe|rare}}\n" + + " |{{Loot Item|Dragon Hammer|rare}}\n" + + " |{{Loot Item|Serpent Sword|rare}}\n" + + " |{{Loot Item|Small Diamond|very rare}}\n" + + " |{{Loot Item|Dragon Shield|very rare}}\n" + + " |{{Loot Item|Life Crystal|very rare}}\n" + + " |{{Loot Item|Dragonbone Staff|very rare}}\n" + + "}}\n" + + "| history = Dragons are one of the oldest creatures in the game. In older times (prior to 2001" + + " at least) dragons were [[Summon Creature|summonable]], and during these times it was possible to summon" + + " up to 8 creatures at once (even through requiring very high [[mana]]) and only the highest leveled" + + " [[mage]]s could summon them (back then the highest [[level]]s were only around level 60 or 70). It was a" + + " somewhat common occurrence to see mages walking the streets of [[Thais]] with several dragons summoned" + + " at one time. It was also possible to set summons free by logging out of the game, turning the summons" + + " into wild creatures. Often mages would leave the game after summoning as many as 8 dragons in the middle" + + " of major [[Hometowns|cities]], causing chaos.\n" + + "}}\n"; + + private static final String INFOBOX_EFFECT_TEXT = "{{Infobox Effect|List={{{1|}}}|GetValue={{{GetValue|}}}\n" + + "| name = Fireball Effect\n" + + "| implemented =\n" + + "| effectid = 7\n" + + "| primarytype = Attack\n" + + "| secondarytype = \n" + + "| lightcolor = 208\n" + + "| lightradius = 6\n" + + "| causes = \n" + + "*[[Fireball]] and [[Great Fireball]];\n" + + "*Certain [[Creature Spells]];\n" + + "*Making a [[Stuffed Dragon]] sneeze;\n" + + "*Using a [[Demon Infant]] on [[Lava]] if tasked to.\n" + + "| effect = [[Fire Damage]] on target or nothing.\n" + + "| notes =\n" + + "}}\n"; + private static final String INFOBOX_HUNT_TEXT = "{{Infobox Hunt|List={{{1|}}}|GetValue={{{GetValue|}}}\n" + "| name = Hero Cave\n" + "| image = Hero\n" + @@ -262,22 +506,234 @@ void testConvertJsonToInfoboxPartOfArticle_Simple() { "| map2 = Hero Cave 6.png\n" + "}}"; - private Achievement makeAchievement() { - return Achievement.builder() - .grade(Grade.ONE) - .name("Goo Goo Dancer") - .description("Seeing a mucus plug makes your heart dance and you can't resist to see what it hides. Goo goo away!") - .spoiler("Obtainable by using 100 [[Muck Remover]]s on [[Mucus Plug]]s.") - .premium(YesNo.YES_LOWERCASE) - .points(1) - .secret(YesNo.YES_LOWERCASE) - .implemented("9.6") - .achievementid(319) - .relatedpages("[[Muck Remover]], [[Mucus Plug]]") - .build(); - } + private static final String INFOBOX_ITEM_TEXT = "{{Infobox Item|List={{{1|}}}|GetValue={{{GetValue|}}}\n" + + "| name = Carlin Sword\n" + + "| marketable = yes\n" + + "| usable = yes\n" + + "| sprites = {{Frames|{{Frame Sprite|55266}}}}\n" + + "| article = a\n" + + "| actualname = carlin sword\n" + + "| plural = ?\n" + + "| itemid = 3283\n" + + "| flavortext =\n" + + "| itemclass = Weapons\n" + + "| primarytype = Sword Weapons\n" + + "| levelrequired = 0\n" + + "| hands = One\n" + + "| type = Sword\n" + + "| attack = 15\n" + + "| defense = 13\n" + + "| defensemod = +1\n" + + "| enchantable = no\n" + + "| weight = 40.00\n" + + "| droppedby = {{Dropped By|Grorlam|Stone Golem}}\n" + + "| value = 118 \n" + + "| npcvalue = 118 \n" + + "| npcprice = 473 \n" + + "| npcvaluerook = 0\n" + + "| npcpricerook = 0\n" + + "| buyfrom = Baltim, Brengus, Cedrik, Esrik, Flint, Gamel, Habdel, Hardek, Memech, Morpel, Robert," + + " Rock In A Hard Place, Romella, Rowenna, Sam, Shanar, Turvy, Ulrik, Uzgod, Willard\n" + + "| sellto = Baltim, Brengus, Cedrik, Esrik, Flint, Gamel, H.L.: 5, Habdel, Hardek, Memech, Morpel," + + " Robert, Rock In A Hard Place, Romella, Rowenna, Sam, Shanar, Turvy, Ulrik, Uzgod, Willard\n" + + "| notes = If you have one of these in [[Rookgaard]] and already reached level 8 you may want to" + + " keep it, if you are going to [[Carlin]]. A common strategy in [[Rookgaard]] was to buy as many carlin" + + " swords as the Rookgaardian can carry and sell all their [[equipment]] to other Rookgaardians and make a" + + " hefty profit on the carlin swords in [[Mainland]], although this may not be recommendable now that one" + + " goes to the [[Island of Destiny]] at [[level]] 8 ([[Raffael]] doesn't buy Carlin Swords).\n" + + "{{JSpoiler|Obtainable in [[Rookgaard]] through the [[Minotaur Hell Quest]].}}\n" + + "}}\n"; - private JSONObject makeAchievementJson(Achievement achievement) { - return new JSONObject(objectMapper.convertValue(achievement, Map.class)).put("templateType", "Achievement"); - } + private static final String INFOBOX_KEY_TEXT = "{{Infobox Key|List={{{1|}}}|GetValue={{{GetValue|}}}\n" + + "| number = 4055\n" + + "| aka = Panpipe Quest Key\n" + + "| primarytype = Silver\n" + + "| location = [[Jakundaf Desert]]\n" + + "| value = Negotiable\n" + + "| npcvalue = 0\n" + + "| npcprice = 0\n" + + "| buyfrom = --\n" + + "| sellto = --\n" + + "| origin = Hidden in a rock south of the Desert Dungeon entrance.\n" + + "| shortnotes = Access to the [[Panpipe Quest]].\n" + + "| longnotes = Allows you to open the door ([http://tibia.wikia.com/wiki/Mapper?coords=127.131,125.129,8,3,1,1 here]) to the [[Panpipe Quest]].\n" + + "}}\n"; + + private static final String INFOBOX_MISSILE_TEXT = "{{Infobox Missile|List={{{1|}}}|GetValue={{{GetValue|}}}\n" + + "| name = Throwing Cake Missile\n" + + "| implemented = 7.9\n" + + "| missileid = 42\n" + + "| primarytype = Throwing Weapon\n" + + "| secondarytype = \n" + + "| lightcolor = \n" + + "| lightradius = \n" + + "| shotby = [[Undead Jester]]'s attack and probably by throwing a [[Throwing Cake]].\n" + + "| notes = This missile is followed by the [[Cream Cake Effect]]: [[File:Cream Cake Effect.gif]]\n" + + "}}\n"; + + private static final String INFOBOX_MOUNT_TEXT = "{{Infobox_Mount|List={{{1|}}}|GetValue={{{GetValue|}}}\n" + + "| name = Donkey\n" + + "| speed = 10\n" + + "| taming_method = Use a [[Bag of Apple Slices]] on a creature transformed into Donkey.\n" + + "| implemented = 9.1\n" + + "| achievement = Loyal Lad\n" + + "| notes = Go to [[Incredibly Old Witch]]'s house, [http://tibia.wikia.com/wiki/Mapper?coords=" + + "125.250,126.95,7,2,1,1 here], then lure any wild creature and wait until the witch turns it into a Donkey." + + " Use a [[Bag of Apple Slices]] on the changed creature before it's changed again. You can also trap the" + + " Incredibly Old Witch and use the Bag when she transforms herself. It's recommended to put the Bag of" + + " Apple Slices on a hotkey so when a creature is changed to Donkey you just need to press it instead of" + + " clicking the item and then the Donkey.
\n" + + "If you tame the donkey by using the item on the witch herself (while she is transformed into Donkey), she" + + " will temporarily vanish, and respawns about 10 minutes later.
\n" + + "On most game worlds it's the cheapest mount to obtain, what makes it popular among low or mid levels who" + + " want to gain additional 10 points of speed.\n" + + "\n" + + "Donkey (Transformation).gif|Donkey (transformed creature)\n" + + "}}\n"; + + private static final String INFOBOX_NPC_TEXT = "{{Infobox NPC|List={{{1|}}}|GetValue={{{GetValue|}}}\n" + + "| name = Sam\n" + + "| implemented = Pre-6.0\n" + + "| job = Artisan\n" + + "| job2 = Weapon Shopkeeper\n" + + "| job3 = Armor Shopkeeper\n" + + "| location = [[Temple Street]] in [[Thais]].\n" + + "| posx = 126.104\n" + + "| posy = 125.200\n" + + "| posz = 7\n" + + "| gender = Male\n" + + "| race = Human\n" + + "| city = Thais\n" + + "| buysell = yes\n" + + "| sells = {{Price to Buy |Axe |Battle Axe |Battle Hammer |Bone Sword |Brass Armor |Brass Helmet" + + " |Brass Legs |Brass Shield |Carlin Sword |Chain Armor |Chain Helmet |Chain Legs |Club |Coat |Crowbar " + + "|Dagger |Doublet |Dwarven Shield |Hand Axe |Iron Helmet |Jacket |Leather Armor |Leather Boots: 10 |Leather" + + " Helmet |Leather Legs |Longsword |Mace |Morning Star |Plate Armor |Plate Shield |Rapier |Sabre |Scale Armor" + + " |Short Sword |Sickle |Soldier Helmet |Spike Sword |Steel Helmet |Steel Shield |Studded Armor |Studded" + + " Helmet |Studded Legs |Studded Shield |Sword |Throwing Knife |Two Handed Sword |Viking Helmet |Viking " + + "Shield |War Hammer |Wooden Shield}}\n" + + "| buys = {{Price to Sell |Axe |Battle Axe |Battle Hammer |Battle Shield |Bone Club |Bone Sword" + + " |Brass Armor |Brass Helmet |Brass Legs |Brass Shield |Carlin Sword |Chain Armor |Chain Helmet |Chain Legs" + + " |Club |Coat |Copper Shield |Crowbar |Dagger |Double Axe |Doublet |Dwarven Shield |Fire Sword: 1000" + + " |Halberd |Hand Axe: 4 |Hatchet |Iron Helmet |Jacket |Katana |Leather Armor |Leather Boots |Leather Helmet" + + " |Leather Legs |Legion Helmet |Longsword |Mace |Magic Plate Armor: 6400;sayname |Morning Star |Orcish Axe" + + " |Plate Armor |Plate Legs |Plate Shield |Rapier |Sabre |Scale Armor |Short Sword |Sickle |Small Axe " + + "|Soldier Helmet |Spike Sword: 240 |Steel Helmet |Steel Shield |Studded Armor |Studded Club |Studded Helmet" + + " |Studded Legs |Studded Shield |Swampling Club |Sword |Throwing Knife |Two Handed Sword |Viking Helmet " + + "|Viking Shield |War Hammer: 470 |Wooden Shield}}\n" + + "| sounds = {{Sound List|Hello there, adventurer! Need a deal in weapons or armor? I'm your man!}}\n" + + "| notes = Sam is the Blacksmith of [[Thais]]. His real name is Samuel, but he prefers to be called " + + "Sam. He was named after his grandfather.\n" + + "He sells and buys many weapons and armors. Sam is one of the few [[NPC]]s that buys magic plate armors. " + + "The only way to sell it to him is by typing \"Sell magic plate armor\".\n" + + "His neighbor in Thais is [[Frodo]], innkeeper of the Frodo's Hut, which is clearly an [[Allusions#Samwise" + + " Gamgee|allusion]] to the J.R.R. Tolkien's novel [[wikipedia:The Lord of the Rings|The Lord of The Rings]]" + + " where [[Frodo]] and Sam are the main plot characters. He was the first NPC to see the Tibian light of day.\n" + + "{{JSpoiler|Part of the [[Sam's Old Backpack Quest]], the [[Knight Outfits Quest]], and mission 9 of" + + " [[What a Foolish Quest]].}}\n" + + "}}\n"; + + private static final String INFOBOX_OBJECT_TEXT = "{{Infobox Object|List={{{1|}}}|GetValue={{{GetValue|}}}\n" + + "| name = Blueberry Bush\n" + + "| article = a\n" + + "| objectclass = Bushes\n" + + "| walkable = no\n" + + "| location = Can be found all around [[Tibia]]. There are many Blueberry bushes in [[Greenshore]]," + + " east from the wheat field. The [[Dryad Gardens]] also contain a lot of bushes.\n" + + "| notes = They are the source of the [[blueberry|blueberries]]. 'Use' the [[bush]] first, then " + + "take the three remaining blueberries, however sometimes other players \"use\" the Blueberry Bush and don't" + + " take them with themselves. Thus, there can be up to six blueberries in a bush. It takes one hour for the" + + " blueberry bush to regenerate.\n" + + "| notes2 =
{{JSpoiler|After using [[Blueberry]] Bushes 500 times, you will earn the" + + " achievement [[Bluebarian]].}}\n" + + "| implemented = 7.1\n" + + "}}\n"; + + private static final String INFOBOX_OUTFIT_TEXT = "{{Infobox_Outfit|List={{{1|}}}|GetValue={{{GetValue|}}}\n" + + "| name = Pirate\n" + + "| primarytype = Quest\n" + + "| premium = yes\n" + + "| outfit = premium, see [[Pirate Outfits Quest]].\n" + + "| addons = premium, see [[Pirate Outfits Quest]].\n" + + "| achievement = Swashbuckler\n" + + "| implemented = 7.8\n" + + "| artwork = Pirate Outfits Artwork.jpg\n" + + "| notes = Pirate outfits are perfect for swabbing the deck or walking the plank. Quite dashing and great for sailing.\n" + + "}}\n"; + + private static final String INFOBOX_QUEST_TEXT = "{{Infobox Quest|List={{{1|}}}|GetValue={{{GetValue|}}}\n" + + "| implemented = 6.61-6.97\n" + + "| premium = yes\n" + + "| name = The Paradox Tower Quest\n" + + "| aka = Riddler Quest, Mathemagics Quest\n" + + "| reward = Up to two of the following: 10k [[gp]], [[Wand of Cosmic Energy]], 32 [[Talon]]s," + + " [[Phoenix Egg]] and the [[achievement]] [[Mathemagician]]\n" + + "| location = [[Paradox Tower]] near [[Kazordoon]]\n" + + "| lvl = 30\n" + + "| lvlrec = 50+\n" + + "| log = yes\n" + + "| transcripts = yes\n" + + "| dangers = [[Wyvern]]s
([[Mintwallin]]): [[Minotaur]]s, [[Minotaur Archer]]s, [[Minotaur" + + " Guard]]s, [[Minotaur Mage]]s
([[Hellgate]]): [[Skeleton]]s, [[Ghoul]]s, [[Bonelord]]s, maybe [[Elder" + + " Bonelord]]
\n" + + "([[Plains of Havoc]]): [[Skeleton]]s, [[Ghoul]]s, [[Demon Skeleton]]s, [[Orc Berserker]], [[Orc" + + " Spearman]], maybe [[Cyclops]] and [[Giant Spider]]\n" + + "| legend = Surpass the wrath of a madman and subject yourself to his twisted taunting.\n" + + "}}\n"; + + private static final String INFOBOX_SPELL_TEXT = "{{Infobox Spell|List={{{1|}}}|GetValue={{{GetValue|}}}\n" + + "| name = Light Healing\n" + + "| type = Instant\n" + + "| subclass = Healing\n" + + "| words = exura\n" + + "| premium = no\n" + + "| mana = 20\n" + + "| levelrequired = 8\n" + + "| cooldown = 1\n" + + "| cooldowngroup = 1\n" + + "| voc = [[Paladin]]s, [[Druid]]s and [[Sorcerer]]s\n" + + "| d-abd = [[Maealil]]\n" + + "| p-abd = [[Maealil]]\n" + + "| spellcost = 0\n" + + "| effect = Restores a small amount of [[HP|health]]. (Cures [[paralysis]].)\n" + + "| notes = A weak, but popular healing spell. It was the only healing spell for knights for many" + + " years until [[Wound Cleansing]] was introduced in late 2007. The number of [[hp]] it can heal depends " + + "upon your level and magic level (and is around 1/10th of your UH power). It is useful if you are trying" + + " to raise your [[Magic level]] or to get rid of [[Paralysis]]. [[Knight]]s can't use it since " + + "[[Updates/8.7|Winter Update 2010]]. Since [[Updates/9.8|Winter Update 2012]] this spell is free. It used " + + "to cost 170 [[gp]].\n" + + "[[File:Exura in low hp.png|thumb|left|168px|A player performing the Light Healing spell]]\n" + + "}}\n"; + + private static final String INFOBOX_STREET_TEXT = "{{Infobox Street\n" + + "| name = Sugar Street\n" + + "| implemented = 7.8\n" + + "| city = Liberty Bay\n" + + "| floor = \n" + + "| notes = {{StreetStyles|Sugar Street}} is in west and central [[Liberty Bay]]. It touches " + + "{{StreetStyles|Harvester's Haven}} to the north, '''Smuggler Backyard''' and {{StreetStyles|Shady Trail}}" + + " to the south, and {{StreetStyles|Marble Lane}} and {{StreetStyles|Admiral's Avenue}} to the east.\n" + + "\n" + + "Buildings and NPCs from south to north and west to east:
\n" + + "'''South-West:'''\n" + + "* [[Sugar Street 1]]\n" + + "* [[Sugar Street 2]]\n" + + "* [[Sugar Street 3a]]\n" + + "* [[Sugar Street 4a]]\n" + + "\n" + + "'''North-West:'''\n" + + "* [[Sugar Street 3b]]\n" + + "\n" + + "'''North:'''\n" + + "* [[Ivy Cottage]]\n" + + "\n" + + "'''Central:'''\n" + + "* [[Sugar Street 4b]]\n" + + "* [[Sugar Street 4c]]\n" + + "* [[Sugar Street 4d]]\n" + + "\n" + + "'''East:'''\n" + + "* [[Peggy]], [[Furniture|Furniture Store]]\n" + + "* [[Sugar Street 5]]\n" + + "}}\n"; } \ No newline at end of file From 9b3705583e31ca41ab0e6c521f6058115eb45f84 Mon Sep 17 00:00:00 2001 From: Benjamin Komen Date: Sat, 17 Nov 2018 20:23:44 +0100 Subject: [PATCH 07/19] Support serialisation of buildings. --- .../tibiawiki/domain/objects/Building.java | 100 +++++++++++++----- .../domain/factories/JsonFactoryTest.java | 76 +++++++++---- 2 files changed, 133 insertions(+), 43 deletions(-) diff --git a/src/main/java/com/tibiawiki/domain/objects/Building.java b/src/main/java/com/tibiawiki/domain/objects/Building.java index 0b9fee8..0888c56 100644 --- a/src/main/java/com/tibiawiki/domain/objects/Building.java +++ b/src/main/java/com/tibiawiki/domain/objects/Building.java @@ -3,10 +3,10 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.tibiawiki.domain.enums.BuildingType; import com.tibiawiki.domain.enums.City; +import com.tibiawiki.domain.enums.Status; import com.tibiawiki.domain.enums.YesNo; -import lombok.AccessLevel; +import lombok.Builder; import lombok.Getter; -import lombok.NoArgsConstructor; import org.springframework.stereotype.Component; import java.util.Arrays; @@ -14,31 +14,83 @@ @JsonIgnoreProperties({"templateType"}) @Getter -@NoArgsConstructor(access = AccessLevel.PRIVATE) @Component public class Building extends WikiObject { - private BuildingType type; - private String location; - private String posx; - private String posy; - private String posz; - private String street; - private String street2; - private String street3; - private String street4; - private String street5; - private Integer houseid; - private Integer size; - private Integer beds; - private Integer rent; - private YesNo ownable; - private City city; - private Integer openwindows; - private Integer floors; - private Integer rooms; - private String furnishings; - private String image; + private final BuildingType type; + private final String location; + private final String posx; + private final String posy; + private final String posz; + private final String street; + private final String street2; + private final String street3; + private final String street4; + private final String street5; + private final Integer houseid; + private final Integer size; + private final Integer beds; + private final Integer rent; + private final YesNo ownable; + private final City city; + private final Integer openwindows; + private final Integer floors; + private final Integer rooms; + private final String furnishings; + private final String image; + + private Building() { + this.type = null; + this.location = null; + this.posx = null; + this.posy = null; + this.posz = null; + this.street = null; + this.street2 = null; + this.street3 = null; + this.street4 = null; + this.street5 = null; + this.houseid = null; + this.size = null; + this.beds = null; + this.rent = null; + this.ownable = null; + this.city = null; + this.openwindows = null; + this.floors = null; + this.rooms = null; + this.furnishings = null; + this.image = null; + } + + @Builder + private Building(String name, String implemented, String notes, String history, Status status, BuildingType type, String location, + String posx, String posy, String posz, String street, String street2, String street3, String street4, + String street5, Integer houseid, Integer size, Integer beds, Integer rent, YesNo ownable, City city, + Integer openwindows, Integer floors, Integer rooms, String furnishings, String image) { + super(name, null, null, null, implemented, notes, history, status); + this.type = type; + this.location = location; + this.posx = posx; + this.posy = posy; + this.posz = posz; + this.street = street; + this.street2 = street2; + this.street3 = street3; + this.street4 = street4; + this.street5 = street5; + this.houseid = houseid; + this.size = size; + this.beds = beds; + this.rent = rent; + this.ownable = ownable; + this.city = city; + this.openwindows = openwindows; + this.floors = floors; + this.rooms = rooms; + this.furnishings = furnishings; + this.image = image; + } @Override public List fieldOrder() { diff --git a/src/test/java/com/tibiawiki/domain/factories/JsonFactoryTest.java b/src/test/java/com/tibiawiki/domain/factories/JsonFactoryTest.java index d1859c3..7995e48 100644 --- a/src/test/java/com/tibiawiki/domain/factories/JsonFactoryTest.java +++ b/src/test/java/com/tibiawiki/domain/factories/JsonFactoryTest.java @@ -2,10 +2,13 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.tibiawiki.domain.enums.BookType; +import com.tibiawiki.domain.enums.BuildingType; +import com.tibiawiki.domain.enums.City; import com.tibiawiki.domain.enums.Grade; import com.tibiawiki.domain.enums.YesNo; import com.tibiawiki.domain.objects.Achievement; import com.tibiawiki.domain.objects.Book; +import com.tibiawiki.domain.objects.Building; import org.json.JSONArray; import org.json.JSONObject; import org.junit.jupiter.api.BeforeEach; @@ -209,6 +212,13 @@ void testConvertJsonToInfoboxPartOfArticle_Book() { assertThat(result, is(INFOBOX_BOOK_TEXT)); } + @Test + void testConvertJsonToInfoboxPartOfArticle_Building() { + final Building building = makeBuilding(); + String result = target.convertJsonToInfoboxPartOfArticle(makeBuildingJson(building), building.fieldOrder()); + assertThat(result, is(INFOBOX_BUILDING_TEXT)); + } + private static final String INFOBOX_TEXT_SPACE = "{{Infobox Achievement|List={{{1|}}}|GetValue={{{GetValue|}}}\n" + "| name = Goo Goo Dancer\n" + "}}"; @@ -290,27 +300,55 @@ private JSONObject makeBookJson(Book book) { } private static final String INFOBOX_BUILDING_TEXT = "{{Infobox Building|List={{{1|}}}|GetValue={{{GetValue|}}}\n" + - "| name = Theater Avenue 8b\n" + - "| implemented = Pre-6.0\n" + - "| type = House\n" + - "| location = South-east of depot, two floors up.\n" + - "| posx = 126.101\n" + - "| posy = 124.48\n" + - "| posz = 5\n" + - "| street = Theater Avenue\n" + - "| houseid = 20315\n" + - "| size = 26\n" + - "| beds = 3\n" + - "| rent = 1370\n" + - "| city = Carlin\n" + - "| openwindows = 3\n" + - "| floors = 1\n" + - "| rooms = 1\n" + - "| furnishings = 1 [[Wall Lamp]].\n" + - "| notes = \n" + - "| image = [[File:Theater Avenue 8b.png]]\n" + + "| name = Theater Avenue 8b\n" + + "| implemented = Pre-6.0\n" + + "| type = House\n" + + "| location = South-east of depot, two floors up.\n" + + "| posx = 126.101\n" + + "| posy = 124.48\n" + + "| posz = 5\n" + + "| street = Theater Avenue\n" + + "| houseid = 20315\n" + + "| size = 26\n" + + "| beds = 3\n" + + "| rent = 1370\n" + + "| city = Carlin\n" + + "| openwindows = 3\n" + + "| floors = 1\n" + + "| rooms = 1\n" + + "| furnishings = 1 [[Wall Lamp]].\n" + + "| notes = \n" + + "| image = [[File:Theater Avenue 8b.png]]\n" + "}}\n"; + private Building makeBuilding() { + return Building.builder() + .name("Theater Avenue 8b") + .implemented("Pre-6.0") + .type(BuildingType.House) + .location("South-east of depot, two floors up.") + .posx("126.101") + .posy("124.48") + .posz("5") + .street("Theater Avenue") + .houseid(20315) + .size(26) + .beds(3) + .rent(1370) + .city(City.CARLIN) + .openwindows(3) + .floors(1) + .rooms(1) + .furnishings("1 [[Wall Lamp]].") + .notes("") + .image("[[File:Theater Avenue 8b.png]]") + .build(); + } + + private JSONObject makeBuildingJson(Building building) { + return new JSONObject(objectMapper.convertValue(building, Map.class)).put("templateType", "Building"); + } + private static final String INFOBOX_CORPSE_TEXT = "{{Infobox Corpse|List={{{1|}}}|GetValue={{{GetValue|}}}\n" + "| name = Dead Rat\n" + "| article = a\n" + From 4a169dad04a7bfa824f200a19169af029a4d4128 Mon Sep 17 00:00:00 2001 From: Benjamin Komen Date: Sat, 17 Nov 2018 20:56:56 +0100 Subject: [PATCH 08/19] Support serialisation of corpses. --- .../com/tibiawiki/domain/objects/Corpse.java | 97 ++++++++++++++----- .../domain/factories/JsonFactoryTest.java | 66 ++++++++++--- 2 files changed, 122 insertions(+), 41 deletions(-) diff --git a/src/main/java/com/tibiawiki/domain/objects/Corpse.java b/src/main/java/com/tibiawiki/domain/objects/Corpse.java index 9d56587..3a2e3ec 100644 --- a/src/main/java/com/tibiawiki/domain/objects/Corpse.java +++ b/src/main/java/com/tibiawiki/domain/objects/Corpse.java @@ -1,38 +1,81 @@ package com.tibiawiki.domain.objects; import com.fasterxml.jackson.annotation.JsonGetter; -import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.tibiawiki.domain.enums.Article; +import com.tibiawiki.domain.enums.Status; import com.tibiawiki.domain.enums.YesNo; -import lombok.AccessLevel; +import lombok.Builder; import lombok.Getter; -import lombok.NoArgsConstructor; import org.springframework.stereotype.Component; -import java.util.Collections; +import java.math.BigDecimal; +import java.util.Arrays; import java.util.List; -@JsonIgnoreProperties({"templateType"}) @Getter -@NoArgsConstructor(access = AccessLevel.PRIVATE) @Component public class Corpse extends WikiObject { - private String flavortext; - private YesNo skinable; - private String product; - private String liquid; - private Integer stages; - private String firstDecaytime; // FIXME should be Seconds - private String secondDecaytime; // FIXME should be Seconds - private String thirdDecaytime; // FIXME should be Seconds - private Integer firstVolume; - private Integer secondVolume; - private Integer thirdVolume; - private Double firstWeight; - private Double secondWeight; - private Double thirdWeight; - private String corpseof; - private String sellto; + private final String flavortext; + private final YesNo skinable; + private final String product; + private final String liquid; + private final Integer stages; + private final String firstDecaytime; // FIXME should be Seconds + private final String secondDecaytime; // FIXME should be Seconds + private final String thirdDecaytime; // FIXME should be Seconds + private final Integer firstVolume; + private final Integer secondVolume; + private final Integer thirdVolume; + private final BigDecimal firstWeight; + private final BigDecimal secondWeight; + private final BigDecimal thirdWeight; + private final String corpseof; + private final String sellto; + + private Corpse() { + this.flavortext = null; + this.skinable = null; + this.product = null; + this.liquid = null; + this.stages = null; + this.firstDecaytime = null; + this.secondDecaytime = null; + this.thirdDecaytime = null; + this.firstVolume = null; + this.secondVolume = null; + this.thirdVolume = null; + this.firstWeight = null; + this.secondWeight = null; + this.thirdWeight = null; + this.corpseof = null; + this.sellto = null; + } + + @Builder + private Corpse(String name, Article article, String actualname, String implemented, String notes, String history, + Status status, String flavortext, YesNo skinable, String product, String liquid, Integer stages, + String firstDecaytime, String secondDecaytime, String thirdDecaytime, Integer firstVolume, + Integer secondVolume, Integer thirdVolume, BigDecimal firstWeight, BigDecimal secondWeight, BigDecimal thirdWeight, + String corpseof, String sellto) { + super(name, article, actualname, null, implemented, notes, history, status); + this.flavortext = flavortext; + this.skinable = skinable; + this.product = product; + this.liquid = liquid; + this.stages = stages; + this.firstDecaytime = firstDecaytime; + this.secondDecaytime = secondDecaytime; + this.thirdDecaytime = thirdDecaytime; + this.firstVolume = firstVolume; + this.secondVolume = secondVolume; + this.thirdVolume = thirdVolume; + this.firstWeight = firstWeight; + this.secondWeight = secondWeight; + this.thirdWeight = thirdWeight; + this.corpseof = corpseof; + this.sellto = sellto; + } @JsonGetter("1decaytime") public String getFirstDecaytime() { @@ -65,22 +108,24 @@ public Integer getThirdVolume() { } @JsonGetter("1weight") - public Double getFirstWeight() { + public BigDecimal getFirstWeight() { return firstWeight; } @JsonGetter("2weight") - public Double getSecondWeight() { + public BigDecimal getSecondWeight() { return secondWeight; } @JsonGetter("3weight") - public Double getThirdWeight() { + public BigDecimal getThirdWeight() { return thirdWeight; } @Override public List fieldOrder() { - return Collections.emptyList(); + return Arrays.asList("name", "article", "actualname", "flavortext", "skinable", "product", "liquid", "stages", + "1decaytime", "2decaytime", "3decaytime", "1volume", "2volume", "3volume", "1weight", "2weight", + "3weight", "corpseof", "sellto", "notes", "implemented", "history", "status"); } } \ No newline at end of file diff --git a/src/test/java/com/tibiawiki/domain/factories/JsonFactoryTest.java b/src/test/java/com/tibiawiki/domain/factories/JsonFactoryTest.java index 7995e48..ad10984 100644 --- a/src/test/java/com/tibiawiki/domain/factories/JsonFactoryTest.java +++ b/src/test/java/com/tibiawiki/domain/factories/JsonFactoryTest.java @@ -1,6 +1,7 @@ package com.tibiawiki.domain.factories; import com.fasterxml.jackson.databind.ObjectMapper; +import com.tibiawiki.domain.enums.Article; import com.tibiawiki.domain.enums.BookType; import com.tibiawiki.domain.enums.BuildingType; import com.tibiawiki.domain.enums.City; @@ -9,11 +10,14 @@ import com.tibiawiki.domain.objects.Achievement; import com.tibiawiki.domain.objects.Book; import com.tibiawiki.domain.objects.Building; +import com.tibiawiki.domain.objects.Corpse; import org.json.JSONArray; import org.json.JSONObject; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import java.math.BigDecimal; +import java.math.RoundingMode; import java.util.Collections; import java.util.Map; @@ -219,6 +223,13 @@ void testConvertJsonToInfoboxPartOfArticle_Building() { assertThat(result, is(INFOBOX_BUILDING_TEXT)); } + @Test + void testConvertJsonToInfoboxPartOfArticle_Corpse() { + final Corpse corpse = makeCorpse(); + String result = target.convertJsonToInfoboxPartOfArticle(makeCorpseJson(corpse), corpse.fieldOrder()); + assertThat(result, is(INFOBOX_CORPSE_TEXT)); + } + private static final String INFOBOX_TEXT_SPACE = "{{Infobox Achievement|List={{{1|}}}|GetValue={{{GetValue|}}}\n" + "| name = Goo Goo Dancer\n" + "}}"; @@ -350,26 +361,51 @@ private JSONObject makeBuildingJson(Building building) { } private static final String INFOBOX_CORPSE_TEXT = "{{Infobox Corpse|List={{{1|}}}|GetValue={{{GetValue|}}}\n" + - "| name = Dead Rat\n" + - "| article = a\n" + - "| liquid = [[Blood]]\n" + - "| 1volume = 5\n" + - "| 1weight = 63.00\n" + - "| 2weight = 44.00\n" + - "| 3weight = 30.00\n" + - "| 1decaytime = 5 minutes.\n" + - "| 2decaytime = 5 minutes.\n" + - "| 3decaytime = 60 seconds.\n" + - "| 1npcvalue = 2\n" + - "| corpseof = [[Rat]], [[Cave Rat]], [[Munster]]\n" + - "| sellto = [[Tom]] ([[Rookgaard]]) '''2''' [[gp]]
[[Seymour]] ([[Rookgaard]]) '''2''' [[gp]]" + + "| name = Dead Rat\n" + + "| article = a\n" + + "| liquid = [[Blood]]\n" + + "| 1decaytime = 5 minutes.\n" + + "| 2decaytime = 5 minutes.\n" + + "| 3decaytime = 60 seconds.\n" + + "| 1volume = 5\n" + + "| 1weight = 63.00\n" + + "| 2weight = 44.00\n" + + "| 3weight = 30.00\n" + + "| corpseof = [[Rat]], [[Cave Rat]], [[Munster]]\n" + + "| sellto = [[Tom]] ([[Rookgaard]]) '''2''' [[gp]]
[[Seymour]] ([[Rookgaard]]) '''2''' [[gp]]" + "
[[Billy]] ([[Rookgaard]]) '''2''' [[gp]]
[[Humgolf]] ([[Kazordoon]]) '''2''' [[gp]]
\n" + "[[Baxter]] ([[Thais]]) '''1''' [[gp]]
\n" + - "| implemented = Pre-6.0\n" + - "| notes = These corpses are commonly used by low level players on [[Rookgaard]] to earn some gold" + + "| notes = These corpses are commonly used by low level players on [[Rookgaard]] to earn some gold" + " for better [[equipment]]. Only fresh corpses are accepted, rotted corpses are ignored.\n" + + "| implemented = Pre-6.0\n" + "}}\n"; + private Corpse makeCorpse() { + return Corpse.builder() + .name("Dead Rat") + .article(Article.A) + .liquid("[[Blood]]") + .firstVolume(5) + .firstWeight(BigDecimal.valueOf(63.00).setScale(2, RoundingMode.HALF_UP)) + .secondWeight(BigDecimal.valueOf(44.00).setScale(2, RoundingMode.HALF_UP)) + .thirdWeight(BigDecimal.valueOf(30.00).setScale(2, RoundingMode.HALF_UP)) + .firstDecaytime("5 minutes.") + .secondDecaytime("5 minutes.") + .thirdDecaytime("60 seconds.") + .corpseof("[[Rat]], [[Cave Rat]], [[Munster]]") + .sellto("[[Tom]] ([[Rookgaard]]) '''2''' [[gp]]
[[Seymour]] ([[Rookgaard]]) '''2''' [[gp]]" + + "
[[Billy]] ([[Rookgaard]]) '''2''' [[gp]]
[[Humgolf]] ([[Kazordoon]]) '''2''' [[gp]]
" + + "\n[[Baxter]] ([[Thais]]) '''1''' [[gp]]
") + .implemented("Pre-6.0") + .notes("These corpses are commonly used by low level players on [[Rookgaard]] to earn some gold" + + " for better [[equipment]]. Only fresh corpses are accepted, rotted corpses are ignored.") + .build(); + } + + private JSONObject makeCorpseJson(Corpse corpse) { + return new JSONObject(objectMapper.convertValue(corpse, Map.class)).put("templateType", "Corpse"); + } + private static final String INFOBOX_CREATURE_TEXT = "{{Infobox Creature|List={{{1|}}}|GetValue={{{GetValue|}}}\n" + "| name = Dragon\n" + "| article = a\n" + From fd723fea4cd78296020e8bc9d87563ec93deecb8 Mon Sep 17 00:00:00 2001 From: Benjamin Komen Date: Sun, 18 Nov 2018 13:00:55 +0100 Subject: [PATCH 09/19] Attempt to add integration tests.. --- pom.xml | 45 ++++++++++++- .../domain/factories/JsonFactoryIT.java | 66 +++++++++++++++++++ 2 files changed, 110 insertions(+), 1 deletion(-) create mode 100644 src/it/java/com/tibiawiki/domain/factories/JsonFactoryIT.java diff --git a/pom.xml b/pom.xml index 3725875..0b6dddb 100644 --- a/pom.xml +++ b/pom.xml @@ -27,8 +27,10 @@ 5.3.1 2.0.2-beta 1.3 - 2.22.0 + 2.22.1 + 2.22.1 3.8.0 + 3.0.0 1.2.0 2.0.1 26.0-jre @@ -252,6 +254,47 @@
+ + + org.codehaus.mojo + build-helper-maven-plugin + ${build.helper.maven.plugin.version} + + + add-test-source + process-resources + + add-test-source + + + + src/it/java + + + + + + + + org.apache.maven.plugins + maven-failsafe-plugin + ${maven.failsafe.plugin.version} + + + integration-test + + integration-test + + + + verify + + verify + + + + + diff --git a/src/it/java/com/tibiawiki/domain/factories/JsonFactoryIT.java b/src/it/java/com/tibiawiki/domain/factories/JsonFactoryIT.java new file mode 100644 index 0000000..19303f4 --- /dev/null +++ b/src/it/java/com/tibiawiki/domain/factories/JsonFactoryIT.java @@ -0,0 +1,66 @@ +package com.tibiawiki.domain.factories; + +import com.tibiawiki.domain.enums.Grade; +import com.tibiawiki.domain.enums.YesNo; +import com.tibiawiki.domain.objects.Achievement; +import org.json.JSONObject; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.is; + +/** + * We want to be sure that the deserialization of a wiki article to a java object, + * and serialisation back to the wiki article, do not cause unwanted side-effects in the article's content. Some effects + * are however not side-effects, but completely legit: + * - removal of undocumentend parameters; + * - removal of empty parameters; + * - ... + */ +public class JsonFactoryIT { + + private JsonFactory target; + + @BeforeEach + void setup() { + target = new JsonFactory(); + } + + @Test + void testDeserializeAndSerialiseSomeAchievement() { + JSONObject achievementAsJson = target.convertInfoboxPartOfArticleToJson(INFOBOX_ACHIEVEMENT_TEXT); + + String result = target.convertJsonToInfoboxPartOfArticle(achievementAsJson, makeAchievement().fieldOrder()); + + assertThat(result, is(INFOBOX_ACHIEVEMENT_TEXT)); + } + + private static final String INFOBOX_ACHIEVEMENT_TEXT = "{{Infobox Achievement|List={{{1|}}}|GetValue={{{GetValue|}}}\n" + + "| grade = 1\n" + + "| name = Goo Goo Dancer\n" + + "| description = Seeing a mucus plug makes your heart dance and you can't resist to see what it hides. Goo goo away!\n" + + "| spoiler = Obtainable by using 100 [[Muck Remover]]s on [[Mucus Plug]]s.\n" + + "| premium = yes\n" + + "| points = 1\n" + + "| secret = yes\n" + + "| implemented = 9.6\n" + + "| achievementid = 319\n" + + "| relatedpages = [[Muck Remover]], [[Mucus Plug]]\n" + + "}}\n"; + + private Achievement makeAchievement() { + return Achievement.builder() + .grade(Grade.ONE) + .name("Goo Goo Dancer") + .description("Seeing a mucus plug makes your heart dance and you can't resist to see what it hides. Goo goo away!") + .spoiler("Obtainable by using 100 [[Muck Remover]]s on [[Mucus Plug]]s.") + .premium(YesNo.YES_LOWERCASE) + .points(1) + .secret(YesNo.YES_LOWERCASE) + .implemented("9.6") + .achievementid(319) + .relatedpages("[[Muck Remover]], [[Mucus Plug]]") + .build(); + } +} From 0155af47c53c4fcb58f722564bfc6b5463c7babb Mon Sep 17 00:00:00 2001 From: Benjamin Komen Date: Sun, 18 Nov 2018 17:02:32 +0100 Subject: [PATCH 10/19] Working on creatures. --- .../com/tibiawiki/domain/enums/Rarity.java | 29 +++ .../domain/factories/JsonFactory.java | 67 ++++- .../tibiawiki/domain/objects/Creature.java | 233 ++++++++++++------ .../tibiawiki/domain/objects/LootItem.java | 13 +- .../tibiawiki/domain/objects/Percentage.java | 28 ++- .../domain/factories/JsonFactoryTest.java | 167 ++++++++++++- 6 files changed, 422 insertions(+), 115 deletions(-) create mode 100644 src/main/java/com/tibiawiki/domain/enums/Rarity.java diff --git a/src/main/java/com/tibiawiki/domain/enums/Rarity.java b/src/main/java/com/tibiawiki/domain/enums/Rarity.java new file mode 100644 index 0000000..607ea53 --- /dev/null +++ b/src/main/java/com/tibiawiki/domain/enums/Rarity.java @@ -0,0 +1,29 @@ +package com.tibiawiki.domain.enums; + +import com.fasterxml.jackson.annotation.JsonValue; +import com.tibiawiki.domain.interfaces.Description; + +/** + * See also: https://tibia.fandom.com/wiki/Rareness + */ +public enum Rarity implements Description { + + ALWAYS("always"), + COMMON("common"), + UNCOMMON("uncommon"), + SEMI_RARE("semi-rare"), + RARE("rare"), + VERY_RARE("very rare"), + EXTREMELY_RARE("extremely rare"); + + private String description; + + Rarity(String description) { + this.description = description; + } + + @JsonValue + public String getDescription() { + return description; + } +} diff --git a/src/main/java/com/tibiawiki/domain/factories/JsonFactory.java b/src/main/java/com/tibiawiki/domain/factories/JsonFactory.java index 1a9421f..ca049a7 100644 --- a/src/main/java/com/tibiawiki/domain/factories/JsonFactory.java +++ b/src/main/java/com/tibiawiki/domain/factories/JsonFactory.java @@ -43,6 +43,9 @@ public class JsonFactory { private static final String INFOBOX_HEADER_PATTERN = "\\{\\{Infobox[\\s|_](.*?)[\\||\\n]"; private static final String RARITY_PATTERN = "(always|common|uncommon|semi-rare|rare|very rare|extremely rare)(|\\?)"; private static final String UNKNOWN = "Unknown"; + private static final String RARITY = "rarity"; + private static final String AMOUNT = "amount"; + private static final String ITEM_NAME = "itemName"; /** * Convert a String which consists of key-value pairs of infobox template parameters to a JSON object, or an empty @@ -85,11 +88,18 @@ public String convertJsonToInfoboxPartOfArticle(@Nullable JSONObject jsonObject, return ""; } - StringBuilder sb = new StringBuilder(); - sb.append("{{Infobox "); - sb.append(jsonObject.get(TEMPLATE_TYPE)); - sb.append("|List={{{1|}}}|GetValue={{{GetValue|}}}").append("\n"); + StringBuilder stringBuilder = new StringBuilder(); + stringBuilder.append("{{Infobox "); + stringBuilder.append(jsonObject.get(TEMPLATE_TYPE)); + stringBuilder.append("|List={{{1|}}}|GetValue={{{GetValue|}}}").append("\n"); + constructKeyValuePairs(jsonObject, fieldOrder, stringBuilder); + + stringBuilder.append("}}").append("\n"); + return stringBuilder.toString(); + } + + private void constructKeyValuePairs(@NotNull JSONObject jsonObject, List fieldOrder, StringBuilder sb) { for (String key : fieldOrder) { // don't add the metadata parameter templateType to the output @@ -104,11 +114,11 @@ public String convertJsonToInfoboxPartOfArticle(@Nullable JSONObject jsonObject, if (value instanceof JSONArray) { if (SOUNDS.equals(key)) { - // do the opposite of makeSoundsArray() + sb.append(makeSoundList(jsonObject, key, (JSONArray) value)); } else if (SPAWN_TYPE.equals(key)) { } else if (LOOT.equals(key)) { - + sb.append(makeLootTable(jsonObject, key, (JSONArray) value)); } else if (DROPPED_BY.equals(key)) { } else if (ITEM_ID.equals(key)) { @@ -120,7 +130,8 @@ public String convertJsonToInfoboxPartOfArticle(@Nullable JSONObject jsonObject, } } else if (value instanceof JSONObject) { - + // TODO check if this works + constructKeyValuePairs(((JSONObject) value), fieldOrder, sb); } else { String paddedKey = Strings.padEnd(key, getMaxFieldLength(jsonObject), ' '); sb.append("| ") @@ -130,9 +141,6 @@ public String convertJsonToInfoboxPartOfArticle(@Nullable JSONObject jsonObject, .append("\n"); } } - - sb.append("}}").append("\n"); - return sb.toString(); } /** @@ -279,11 +287,11 @@ private JSONObject makeLootItemJsonObject(List splitLootItem) { for (String lootItemPart : splitLootItem) { if (lootItemPart.toLowerCase().matches(RARITY_PATTERN)) { - lootItemMap.put("rarity", lootItemPart); + lootItemMap.put(RARITY, lootItemPart); } else if (Character.isDigit(lootItemPart.charAt(0))) { - lootItemMap.put("amount", lootItemPart); + lootItemMap.put(AMOUNT, lootItemPart); } else { - lootItemMap.put("itemName", lootItemPart); + lootItemMap.put(ITEM_NAME, lootItemPart); } } return new JSONObject(lootItemMap); @@ -331,4 +339,37 @@ private int getMaxFieldLength(@NotNull JSONObject jsonObject) { .max() .orElse(0); } + + private String makeSoundList(@NotNull JSONObject jsonObject, String key, JSONArray jsonArray) { + final String paddedKey = Strings.padEnd(key, getMaxFieldLength(jsonObject), ' '); + final String value = jsonArray.toList().stream() + .map(String::valueOf) + .collect(Collectors.joining("|")); + + return "| " + paddedKey + " = {{Sound List|" + value + "}}\n"; + } + + private String makeLootTable(JSONObject jsonObject, String key, JSONArray jsonArray) { + final String paddedKey = Strings.padEnd(key, getMaxFieldLength(jsonObject), ' '); + final String value = jsonArray.toList().stream() + .map(this::makeLootItem) + .collect(Collectors.joining("\n |")); + + return "| " + paddedKey + " = {{Loot Table\n |" + value + "\n}}\n"; + } + + private String makeLootItem(Object obj) { + Map map = (Map) obj; + StringBuilder result = new StringBuilder("{{Loot Item"); + if (map.containsKey(AMOUNT)) { + result.append("|").append(map.get(AMOUNT)); + } + if (map.containsKey(ITEM_NAME)) { + result.append("|").append(map.get(ITEM_NAME)); + } + if (map.containsKey(RARITY)) { + result.append("|").append(map.get(RARITY)); + } + return result.append("}}").toString(); + } } diff --git a/src/main/java/com/tibiawiki/domain/objects/Creature.java b/src/main/java/com/tibiawiki/domain/objects/Creature.java index eb11ccf..4dc58f7 100644 --- a/src/main/java/com/tibiawiki/domain/objects/Creature.java +++ b/src/main/java/com/tibiawiki/domain/objects/Creature.java @@ -1,102 +1,184 @@ package com.tibiawiki.domain.objects; import com.fasterxml.jackson.annotation.JsonGetter; -import com.fasterxml.jackson.annotation.JsonIgnoreProperties; -import com.fasterxml.jackson.annotation.JsonSetter; +import com.tibiawiki.domain.enums.Article; import com.tibiawiki.domain.enums.BestiaryClass; import com.tibiawiki.domain.enums.BestiaryLevel; import com.tibiawiki.domain.enums.BestiaryOccurrence; import com.tibiawiki.domain.enums.Spawntype; +import com.tibiawiki.domain.enums.Status; import com.tibiawiki.domain.enums.YesNo; -import lombok.AccessLevel; +import lombok.Builder; import lombok.Getter; -import lombok.NoArgsConstructor; import org.springframework.stereotype.Component; import java.util.Arrays; import java.util.List; -@JsonIgnoreProperties({"templateType"}) @Getter -@NoArgsConstructor(access = AccessLevel.PUBLIC) // TODO make this private and add builder @Component public class Creature extends WikiObject { - private String hitPoints; // FIXME should be Integer - private String experiencePoints; // FIXME should be Integer - private String armor; // FIXME should be Integer - private String summon; // FIXME should be Integer - private String convince; // FIXME should be Integer - private YesNo illusionable; - private String creatureclass; - private String primarytype; - private String secondarytype; - private BestiaryClass bestiaryclass; - private BestiaryLevel bestiarylevel; - private BestiaryOccurrence occurrence; - private List spawntype; - private YesNo isboss; - private YesNo isarenaboss; - private YesNo isevent; - private String abilities; - private String usedelements; // FIXME should be List - private String maxdmg; // FIXME should be Integer - private YesNo pushable; - private YesNo pushobjects; - private String walksaround; // FIXME should be List - private String walksthrough; // FIXME should be List - private YesNo paraimmune; - private YesNo senseinvis; - private Percentage physicalDmgMod; - private Percentage holyDmgMod; - private Percentage deathDmgMod; - private Percentage fireDmgMod; - private Percentage energyDmgMod; - private Percentage iceDmgMod; - private Percentage earthDmgMod; - private Percentage drownDmgMod; - private Percentage hpDrainDmgMod; - private Percentage healMod; - private String bestiaryname; - private String bestiarytext; - private List sounds; - private String behaviour; - private String runsat; // FIXME should be Integer - private String speed; // FIXME should be Integer - private String strategy; - private String location; - private List loot; + private final String hitPoints; // FIXME should be Integer + private final String experiencePoints; // FIXME should be Integer + private final String armor; // FIXME should be Integer + private final String summon; // FIXME should be Integer + private final String convince; // FIXME should be Integer + private final YesNo illusionable; + private final String creatureclass; + private final String primarytype; + private final String secondarytype; + private final BestiaryClass bestiaryclass; + private final BestiaryLevel bestiarylevel; + private final BestiaryOccurrence occurrence; + private final List spawntype; + private final YesNo isboss; + private final YesNo isarenaboss; + private final YesNo isevent; + private final String abilities; + private final String usedelements; // FIXME should be List + private final String maxdmg; // FIXME should be Integer + private final YesNo pushable; + private final YesNo pushobjects; + private final String walksaround; // FIXME should be List + private final String walksthrough; // FIXME should be List + private final YesNo paraimmune; + private final YesNo senseinvis; + private final Percentage physicalDmgMod; + private final Percentage holyDmgMod; + private final Percentage deathDmgMod; + private final Percentage fireDmgMod; + private final Percentage energyDmgMod; + private final Percentage iceDmgMod; + private final Percentage earthDmgMod; + private final Percentage drownDmgMod; + private final Percentage hpDrainDmgMod; + private final Percentage healMod; + private final String bestiaryname; + private final String bestiarytext; + private final List sounds; + private final String behaviour; + private final String runsat; // FIXME should be Integer + private final String speed; // FIXME should be Integer + private final String strategy; + private final String location; + private final List loot; - @JsonGetter("hp") - public String getHitPoints() { - return hitPoints; + private Creature() { + this.hitPoints = null; + this.experiencePoints = null; + this.armor = null; + this.summon = null; + this.convince = null; + this.illusionable = null; + this.creatureclass = null; + this.primarytype = null; + this.secondarytype = null; + this.bestiaryclass = null; + this.bestiarylevel = null; + this.occurrence = null; + this.spawntype = null; + this.isboss = null; + this.isarenaboss = null; + this.isevent = null; + this.abilities = null; + this.usedelements = null; + this.maxdmg = null; + this.pushable = null; + this.pushobjects = null; + this.walksaround = null; + this.walksthrough = null; + this.paraimmune = null; + this.senseinvis = null; + this.physicalDmgMod = null; + this.holyDmgMod = null; + this.deathDmgMod = null; + this.fireDmgMod = null; + this.energyDmgMod = null; + this.iceDmgMod = null; + this.earthDmgMod = null; + this.drownDmgMod = null; + this.hpDrainDmgMod = null; + this.healMod = null; + this.bestiaryname = null; + this.bestiarytext = null; + this.sounds = null; + this.behaviour = null; + this.runsat = null; + this.speed = null; + this.strategy = null; + this.location = null; + this.loot = null; } - @JsonSetter("hp") - public void setHitPoints(String hitPoints) { + @Builder + public Creature(String name, Article article, String actualname, String plural, String implemented, String notes, + String history, Status status, String hitPoints, String experiencePoints, String armor, + String summon, String convince, YesNo illusionable, String creatureclass, String primarytype, + String secondarytype, BestiaryClass bestiaryclass, BestiaryLevel bestiarylevel, + BestiaryOccurrence occurrence, List spawntype, YesNo isboss, YesNo isarenaboss, + YesNo isevent, String abilities, String usedelements, String maxdmg, YesNo pushable, + YesNo pushobjects, String walksaround, String walksthrough, YesNo paraimmune, YesNo senseinvis, + Percentage physicalDmgMod, Percentage holyDmgMod, Percentage deathDmgMod, Percentage fireDmgMod, + Percentage energyDmgMod, Percentage iceDmgMod, Percentage earthDmgMod, Percentage drownDmgMod, + Percentage hpDrainDmgMod, Percentage healMod, String bestiaryname, String bestiarytext, + List sounds, String behaviour, String runsat, String speed, String strategy, String location, + List loot) { + super(name, article, actualname, plural, implemented, notes, history, status); this.hitPoints = hitPoints; - } - - @JsonGetter("exp") - public String getExperiencePoints() { - return experiencePoints; - } - - @JsonSetter("exp") - public void setExperiencePoints(String experiencePoints) { this.experiencePoints = experiencePoints; + this.armor = armor; + this.summon = summon; + this.convince = convince; + this.illusionable = illusionable; + this.creatureclass = creatureclass; + this.primarytype = primarytype; + this.secondarytype = secondarytype; + this.bestiaryclass = bestiaryclass; + this.bestiarylevel = bestiarylevel; + this.occurrence = occurrence; + this.spawntype = spawntype; + this.isboss = isboss; + this.isarenaboss = isarenaboss; + this.isevent = isevent; + this.abilities = abilities; + this.usedelements = usedelements; + this.maxdmg = maxdmg; + this.pushable = pushable; + this.pushobjects = pushobjects; + this.walksaround = walksaround; + this.walksthrough = walksthrough; + this.paraimmune = paraimmune; + this.senseinvis = senseinvis; + this.physicalDmgMod = physicalDmgMod; + this.holyDmgMod = holyDmgMod; + this.deathDmgMod = deathDmgMod; + this.fireDmgMod = fireDmgMod; + this.energyDmgMod = energyDmgMod; + this.iceDmgMod = iceDmgMod; + this.earthDmgMod = earthDmgMod; + this.drownDmgMod = drownDmgMod; + this.hpDrainDmgMod = hpDrainDmgMod; + this.healMod = healMod; + this.bestiaryname = bestiaryname; + this.bestiarytext = bestiarytext; + this.sounds = sounds; + this.behaviour = behaviour; + this.runsat = runsat; + this.speed = speed; + this.strategy = strategy; + this.location = location; + this.loot = loot; } - // TODO remove this when all creatures who use this start using healMOD - @JsonGetter("healmod") - public Percentage gethealmod() { - return healMod; + @JsonGetter("hp") + public String getHitPoints() { + return hitPoints; } - // TODO remove this when all creatures who use this start using healMOD - @JsonSetter("healmod") - public void sethealmod(Percentage healmod) { - this.healMod = healmod; + @JsonGetter("exp") + public String getExperiencePoints() { + return experiencePoints; } @JsonGetter("healMod") @@ -104,16 +186,11 @@ public Percentage gethealMod() { return healMod; } - @JsonSetter("healMod") - public void sethealMod(Percentage healMod) { - this.healMod = healMod; - } - @Override public List fieldOrder() { return Arrays.asList("name", "article", "actualname", "plural", "hp", "exp", "armor", "summon", "convince", "illusionable", "creatureclass", "primarytype", "secondarytype", "bestiaryclass", "bestiarylevel", - "spawntype", "isboss", "isarenaboss", "isevent", "abilities", "usedelements", "maxdmg", "pushable", + "occurrence", "spawntype", "isboss", "isarenaboss", "isevent", "abilities", "usedelements", "maxdmg", "pushable", "pushobjects", "walksaround", "walksthrough", "paraimmune", "senseinvis", "physicalDmgMod", "holyDmgMod", "deathDmgMod", "fireDmgMod", "energyDmgMod", "iceDmgMod", "earthDmgMod", "drownDmgMod", "hpDrainDmgMod", "healMod", "bestiaryname", "bestiarytext", "sounds", "implemented", "notes", "behaviour", "runsat", diff --git a/src/main/java/com/tibiawiki/domain/objects/LootItem.java b/src/main/java/com/tibiawiki/domain/objects/LootItem.java index 9451349..4c2a130 100644 --- a/src/main/java/com/tibiawiki/domain/objects/LootItem.java +++ b/src/main/java/com/tibiawiki/domain/objects/LootItem.java @@ -1,16 +1,19 @@ package com.tibiawiki.domain.objects; +import com.tibiawiki.domain.enums.Rarity; +import lombok.AccessLevel; +import lombok.AllArgsConstructor; +import lombok.Builder; import lombok.Getter; import lombok.NoArgsConstructor; -import lombok.Setter; @Getter -@Setter -@NoArgsConstructor +@NoArgsConstructor(access = AccessLevel.PRIVATE) +@AllArgsConstructor(access = AccessLevel.PRIVATE) +@Builder public class LootItem { private String itemName; private String amount; - private String rarity; - + private Rarity rarity; } diff --git a/src/main/java/com/tibiawiki/domain/objects/Percentage.java b/src/main/java/com/tibiawiki/domain/objects/Percentage.java index bc50226..8686d6a 100644 --- a/src/main/java/com/tibiawiki/domain/objects/Percentage.java +++ b/src/main/java/com/tibiawiki/domain/objects/Percentage.java @@ -1,31 +1,47 @@ package com.tibiawiki.domain.objects; +import com.fasterxml.jackson.annotation.JsonValue; import lombok.Getter; import lombok.NoArgsConstructor; -import lombok.Setter; @Getter -@Setter @NoArgsConstructor public class Percentage { private String originalValue; private Integer value; - public Percentage(String value) { + private Percentage(String value) { this.originalValue = value; this.value = sanitize(value); } + private Percentage(Integer value) { + this.originalValue = value + "%"; + this.value = value; + } + + public static Percentage of(String value) { + return new Percentage(value); + } + + public static Percentage of(Integer value) { + return new Percentage(value); + } + + @JsonValue + public String getOriginalValue() { + return originalValue; + } + private Integer sanitize(String value) { - String sanitizedValue = value.replaceAll("\\D+",""); + String sanitizedValue = value.replaceAll("\\D+", ""); if (sanitizedValue.length() < 1) { return null; } - return Integer.valueOf(sanitizedValue); + return Integer.valueOf(sanitizedValue); } - } diff --git a/src/test/java/com/tibiawiki/domain/factories/JsonFactoryTest.java b/src/test/java/com/tibiawiki/domain/factories/JsonFactoryTest.java index ad10984..18eab31 100644 --- a/src/test/java/com/tibiawiki/domain/factories/JsonFactoryTest.java +++ b/src/test/java/com/tibiawiki/domain/factories/JsonFactoryTest.java @@ -2,22 +2,31 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.tibiawiki.domain.enums.Article; +import com.tibiawiki.domain.enums.BestiaryClass; +import com.tibiawiki.domain.enums.BestiaryLevel; +import com.tibiawiki.domain.enums.BestiaryOccurrence; import com.tibiawiki.domain.enums.BookType; import com.tibiawiki.domain.enums.BuildingType; import com.tibiawiki.domain.enums.City; import com.tibiawiki.domain.enums.Grade; +import com.tibiawiki.domain.enums.Rarity; import com.tibiawiki.domain.enums.YesNo; import com.tibiawiki.domain.objects.Achievement; import com.tibiawiki.domain.objects.Book; import com.tibiawiki.domain.objects.Building; import com.tibiawiki.domain.objects.Corpse; +import com.tibiawiki.domain.objects.Creature; +import com.tibiawiki.domain.objects.LootItem; +import com.tibiawiki.domain.objects.Percentage; import org.json.JSONArray; import org.json.JSONObject; import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; import java.math.BigDecimal; import java.math.RoundingMode; +import java.util.Arrays; import java.util.Collections; import java.util.Map; @@ -230,6 +239,15 @@ void testConvertJsonToInfoboxPartOfArticle_Corpse() { assertThat(result, is(INFOBOX_CORPSE_TEXT)); } + // It almost works, not sure why not + @Disabled + @Test + void testConvertJsonToInfoboxPartOfArticle_Creature() { + final Creature creature = makeCreature(); + String result = target.convertJsonToInfoboxPartOfArticle(makeCreatureJson(creature), creature.fieldOrder()); + assertThat(result, is(INFOBOX_CREATURE_TEXT)); + } + private static final String INFOBOX_TEXT_SPACE = "{{Infobox Achievement|List={{{1|}}}|GetValue={{{GetValue|}}}\n" + "| name = Goo Goo Dancer\n" + "}}"; @@ -411,9 +429,9 @@ private JSONObject makeCorpseJson(Corpse corpse) { "| article = a\n" + "| actualname = dragon\n" + "| plural = dragons\n" + - "| implemented = Pre-6.0\n" + "| hp = 1000\n" + "| exp = 700\n" + + "| armor = 25\n" + "| summon = --\n" + "| convince = --\n" + "| illusionable = yes\n" + @@ -426,11 +444,10 @@ private JSONObject makeCorpseJson(Corpse corpse) { "| isarenaboss = no\n" + "| abilities = [[Melee]] (0-120), [[Fire Wave]] (100-170), [[Great Fireball]] (60-140), [[Self-Healing]] (40-70)\n" + "| maxdmg = 430\n" + - "| armor = 25\n" + - "| pushable = No\n" + - "| pushobjects = Yes\n" + - "| walksthrough = Fire, Energy, Poison\n" + + "| pushable = no\n" + + "| pushobjects = yes\n" + "| walksaround = None\n" + + "| walksthrough = Fire, Energy, Poison\n" + "| paraimmune = yes\n" + "| senseinvis = yes\n" + "| physicalDmgMod = 100%\n" + @@ -448,6 +465,7 @@ private JSONObject makeCorpseJson(Corpse corpse) { " powerful monsters and will strive for killing every intruder. Besides their immense strength, they shoot" + " fireballs at their victims and spit fire. Moreover, they can heal themselves.\n" + "| sounds = {{Sound List|FCHHHHH|GROOAAARRR}}\n" + + "| implemented = Pre-6.0\n" + "| notes = Dragons are very slow-moving, but have a potent set of attacks. A [[mage]] or" + " [[paladin]] can kill one without taking any damage once they master the art. These creatures can be" + " skinned with an [[Obsidian Knife]]. See also: [[Green Dragon Leather/Skinning]].\n" + @@ -455,13 +473,6 @@ private JSONObject makeCorpseJson(Corpse corpse) { " hunt to be burned or killed.\n" + "| runsat = 300\n" + "| speed = 86\n" + - "| location = [[Thais]] [[Ancient Temple]], [[Darashia Dragon Lair]], [[Mount Sternum Dragon Cave]]," + - " [[Mintwallin]], deep in [[Fibula Dungeon]], [[Kazordoon Dragon Lair]] (near [[Dwarf Bridge]]), [[Plains" + - " of Havoc]], [[Elven Bane]] castle, [[Maze of Lost Souls]], southern cave and dragon tower in" + - " [[Shadowthorn]], [[Orc Fortress]], [[Venore]] [[Dragon Lair]], [[Pits of Inferno]], [[Behemoth Quest]]" + - " room in [[Edron]], [[Hero Cave]], deep [[Cyclopolis]], [[Edron Dragon Lair]], [[Goroma]], [[Ankrahmun" + - " Dragon Lair]]s, [[Draconia]], [[Dragonblaze Peaks]], some [[Ankrahmun Tombs]], underground of [[Fenrock]]" + - " (on the way to [[Beregar]]), [[Krailos Steppe]] and [[Crystal Lakes]].\n" + "| strategy = '''All''' [[player]]s should stand diagonal from the dragon, whenever possible, to" + " avoid the [[Fire Wave]].\n" + " \n" + @@ -490,6 +501,13 @@ private JSONObject makeCorpseJson(Corpse corpse) { " potions. Killing a dragon at this level will only prove your strength as a paladin will spend" + " approximately 500 [[gp]]s per dragon and the chance of dying is very high if not careful. It is advisable" + " to bring some [[Icicle Rune|Icicles]] or [[Avalanche Rune]]s if facing two or more of them.\n" + + "| location = [[Thais]] [[Ancient Temple]], [[Darashia Dragon Lair]], [[Mount Sternum Dragon Cave]]," + + " [[Mintwallin]], deep in [[Fibula Dungeon]], [[Kazordoon Dragon Lair]] (near [[Dwarf Bridge]]), [[Plains" + + " of Havoc]], [[Elven Bane]] castle, [[Maze of Lost Souls]], southern cave and dragon tower in" + + " [[Shadowthorn]], [[Orc Fortress]], [[Venore]] [[Dragon Lair]], [[Pits of Inferno]], [[Behemoth Quest]]" + + " room in [[Edron]], [[Hero Cave]], deep [[Cyclopolis]], [[Edron Dragon Lair]], [[Goroma]], [[Ankrahmun" + + " Dragon Lair]]s, [[Draconia]], [[Dragonblaze Peaks]], some [[Ankrahmun Tombs]], underground of [[Fenrock]]" + + " (on the way to [[Beregar]]), [[Krailos Steppe]] and [[Crystal Lakes]].\n" + "| loot = {{Loot Table\n" + " |{{Loot Item|0-105|Gold Coin}}\n" + " |{{Loot Item|0-3|Dragon Ham}}\n" + @@ -513,7 +531,7 @@ private JSONObject makeCorpseJson(Corpse corpse) { " |{{Loot Item|Life Crystal|very rare}}\n" + " |{{Loot Item|Dragonbone Staff|very rare}}\n" + "}}\n" + - "| history = Dragons are one of the oldest creatures in the game. In older times (prior to 2001" + + "| history = Dragons are one of the oldest creatures in the game. In older times (prior to 2001" + " at least) dragons were [[Summon Creature|summonable]], and during these times it was possible to summon" + " up to 8 creatures at once (even through requiring very high [[mana]]) and only the highest leveled" + " [[mage]]s could summon them (back then the highest [[level]]s were only around level 60 or 70). It was a" + @@ -523,6 +541,129 @@ private JSONObject makeCorpseJson(Corpse corpse) { " of major [[Hometowns|cities]], causing chaos.\n" + "}}\n"; + private Creature makeCreature() { + return Creature.builder() + .name("Dragon") + .article(Article.A) + .actualname("dragon") + .plural("dragons") + .implemented("Pre-6.0") + .hitPoints("1000") + .experiencePoints("700") + .summon("--") + .convince("--") + .illusionable(YesNo.YES_LOWERCASE) + .creatureclass("Reptiles") + .primarytype("Dragons") + .bestiaryclass(BestiaryClass.DRAGON) + .bestiarylevel(BestiaryLevel.Medium) + .occurrence(BestiaryOccurrence.COMMON) + .isboss(YesNo.NO_LOWERCASE) + .isarenaboss(YesNo.NO_LOWERCASE) + .abilities("[[Melee]] (0-120), [[Fire Wave]] (100-170), [[Great Fireball]] (60-140), [[Self-Healing]] (40-70)") + .maxdmg("430") + .armor("25") + .pushable(YesNo.NO_LOWERCASE) + .pushobjects(YesNo.YES_LOWERCASE) + .walksthrough("Fire, Energy, Poison") + .walksaround("None") + .paraimmune(YesNo.YES_LOWERCASE) + .senseinvis(YesNo.YES_LOWERCASE) + .physicalDmgMod(Percentage.of(100)) + .holyDmgMod(Percentage.of(100)) + .deathDmgMod(Percentage.of(100)) + .fireDmgMod(Percentage.of(0)) + .energyDmgMod(Percentage.of(80)) + .iceDmgMod(Percentage.of(110)) + .earthDmgMod(Percentage.of(20)) + .drownDmgMod(Percentage.of("100%?")) + .hpDrainDmgMod(Percentage.of("100%?")) + .bestiaryname("dragon") + .bestiarytext("Dragons were among the first creatures of Tibia and once ruled the whole continent." + + " Nowadays, there are only a few of them left which live deep in the dungeons. Nevertheless, they are very" + + " powerful monsters and will strive for killing every intruder. Besides their immense strength, they shoot" + + " fireballs at their victims and spit fire. Moreover, they can heal themselves.") + .sounds(Arrays.asList("FCHHHHH", "GROOAAARRR")) + .notes("Dragons are very slow-moving, but have a potent set of attacks. A [[mage]] or" + + " [[paladin]] can kill one without taking any damage once they master the art. These creatures can be" + + " skinned with an [[Obsidian Knife]]. See also: [[Green Dragon Leather/Skinning]].") + .behaviour("Dragons are known to [[Retargeting|retarget]]. This often causes shooters in a team" + + " hunt to be burned or killed.") + .runsat("300") + .speed("86") + .location("[[Thais]] [[Ancient Temple]], [[Darashia Dragon Lair]], [[Mount Sternum Dragon Cave]]," + + " [[Mintwallin]], deep in [[Fibula Dungeon]], [[Kazordoon Dragon Lair]] (near [[Dwarf Bridge]]), [[Plains" + + " of Havoc]], [[Elven Bane]] castle, [[Maze of Lost Souls]], southern cave and dragon tower in" + + " [[Shadowthorn]], [[Orc Fortress]], [[Venore]] [[Dragon Lair]], [[Pits of Inferno]], [[Behemoth Quest]]" + + " room in [[Edron]], [[Hero Cave]], deep [[Cyclopolis]], [[Edron Dragon Lair]], [[Goroma]], [[Ankrahmun" + + " Dragon Lair]]s, [[Draconia]], [[Dragonblaze Peaks]], some [[Ankrahmun Tombs]], underground of [[Fenrock]]" + + " (on the way to [[Beregar]]), [[Krailos Steppe]] and [[Crystal Lakes]].") + .strategy("'''All''' [[player]]s should stand diagonal from the dragon, whenever possible, to" + + " avoid the [[Fire Wave]].\\n" + + " \\n" + + "'''[[Knight]]s''': Only one knight should be present in a team hunt, as they, the [[Blocking|blocker]]," + + " must be able to move freely around the dragon and to maintain their diagonal position as the dragon" + + " takes a step. It is quite easy for a knight of [[level]] 40 or higher to block a dragon without using" + + " any Health Potions at all. Around level 60 a knight with good skills (70/70) can hunt dragons with little" + + " waste and possibly profit. Remember to stand diagonal to it and always be prepared to use" + + " [[Health Potion|potions]]. A level 80+ knight can hunt dragons using only food and" + + " [[Pair of Soft Boots|Soft Boots]].
\\n" + + "'''[[Mage]]s''' of level 28 or higher can kill dragons without help from other players, but you need to be" + + " very careful. They can [[Summon]] two [[Demon Skeleton]]s and drink a few extra [[Mana Potion]]s" + + " afterwards. They should try to keep enough [[mana]] to heal, if needed. They should enter, lure the" + + " dragon out, attack it with the demon skeletons, then move to a different floor so the dragon will target" + + " the demon skeletons. It is advisable to move to a space about 3 squares diagonal and use a strike spell" + + " ([[Ice Strike]] if possible) or [[Icicle Rune]]s to kill faster. Heal when your hit points drop below" + + " 250-280. Druids level 35 or higher, can use [[Mass Healing]] to prevent their summons from dying," + + " otherwise use [[Healing Runes]]. This is a reasonably cheap way to hunt dragons although the demon" + + " skeletons also gain a share of the experience.
\\n" + + "'''[[Paladin]]s''' with a distance skill of 60+ and enough hit points to survive a fire attack are welcome" + + " additions to a team dragon hunt. Just be sure to have the [[Divine Healing]] spell ready to use, and" + + " stand where you can also escape if the dragon retargets. A paladin's ability to solo a dragon depends" + + " greatly on the terrain. A dragon's melee is weaker than their area attacks, so it would be advisable to" + + " stand diagonal the Dragon but only 1 sqm away, while shooting [[Royal Spear]]s or [[Enchanted Spear]]s." + + " A level 20 paladin with skills 65+ may attempt to solo a single dragon spawn but will have to bring some" + + " potions. Killing a dragon at this level will only prove your strength as a paladin will spend" + + " approximately 500 [[gp]]s per dragon and the chance of dying is very high if not careful. It is advisable" + + " to bring some [[Icicle Rune|Icicles]] or [[Avalanche Rune]]s if facing two or more of them.") + .loot(Arrays.asList( + LootItem.builder().amount("0-105").itemName("Gold Coin").build(), + LootItem.builder().amount("0-3").itemName("Dragon Ham").build(), + LootItem.builder().itemName("Steel Shield").build(), + LootItem.builder().itemName("Crossbow").build(), + LootItem.builder().itemName("Dragon's Tail").build(), + LootItem.builder().amount("0-10").itemName("Burst Arrow").build(), + LootItem.builder().itemName("Longsword").rarity(Rarity.SEMI_RARE).build(), + LootItem.builder().itemName("Steel Helmet").rarity(Rarity.SEMI_RARE).build(), + LootItem.builder().itemName("Broadsword").rarity(Rarity.SEMI_RARE).build(), + LootItem.builder().itemName("Plate Legs").rarity(Rarity.SEMI_RARE).build(), + LootItem.builder().itemName("Green Dragon Leather").rarity(Rarity.RARE).build(), + LootItem.builder().itemName("Wand of Inferno").rarity(Rarity.RARE).build(), + LootItem.builder().itemName("Strong Health Potion").rarity(Rarity.RARE).build(), + LootItem.builder().itemName("Green Dragon Scale").rarity(Rarity.RARE).build(), + LootItem.builder().itemName("Double Axe").rarity(Rarity.RARE).build(), + LootItem.builder().itemName("Dragon Hammer").rarity(Rarity.RARE).build(), + LootItem.builder().itemName("Serpent Sword").rarity(Rarity.RARE).build(), + LootItem.builder().itemName("Small Diamond").rarity(Rarity.VERY_RARE).build(), + LootItem.builder().itemName("Dragon Shield").rarity(Rarity.VERY_RARE).build(), + LootItem.builder().itemName("Life Crystal").rarity(Rarity.VERY_RARE).build(), + LootItem.builder().itemName("Dragonbone Staff").rarity(Rarity.VERY_RARE).build() + )) + .history("Dragons are one of the oldest creatures in the game. In older times (prior to 2001" + + " at least) dragons were [[Summon Creature|summonable]], and during these times it was possible to summon" + + " up to 8 creatures at once (even through requiring very high [[mana]]) and only the highest leveled" + + " [[mage]]s could summon them (back then the highest [[level]]s were only around level 60 or 70). It was a" + + " somewhat common occurrence to see mages walking the streets of [[Thais]] with several dragons summoned" + + " at one time. It was also possible to set summons free by logging out of the game, turning the summons" + + " into wild creatures. Often mages would leave the game after summoning as many as 8 dragons in the middle" + + " of major [[Hometowns|cities]], causing chaos.") + .build(); + } + + private JSONObject makeCreatureJson(Creature creature) { + return new JSONObject(objectMapper.convertValue(creature, Map.class)).put("templateType", "Creature"); + } + private static final String INFOBOX_EFFECT_TEXT = "{{Infobox Effect|List={{{1|}}}|GetValue={{{GetValue|}}}\n" + "| name = Fireball Effect\n" + "| implemented =\n" + From cc9ab5a9d3f82211b145f31fbdac9378e803d5b3 Mon Sep 17 00:00:00 2001 From: Benjamin Komen Date: Sat, 24 Nov 2018 17:40:57 +0100 Subject: [PATCH 11/19] Fixing remaining objects with constructors and builders. Adding Missile. --- .../tibiawiki/domain/objects/Building.java | 2 - .../com/tibiawiki/domain/objects/Effect.java | 46 +- .../domain/objects/HuntingPlace.java | 134 ++-- .../domain/objects/HuntingPlaceSkills.java | 48 +- .../com/tibiawiki/domain/objects/Item.java | 357 ++++++++--- .../com/tibiawiki/domain/objects/Key.java | 68 ++- .../tibiawiki/domain/objects/Location.java | 61 +- .../com/tibiawiki/domain/objects/Missile.java | 48 ++ .../com/tibiawiki/domain/objects/Mount.java | 50 +- .../com/tibiawiki/domain/objects/NPC.java | 148 +++-- .../com/tibiawiki/domain/objects/Outfit.java | 52 +- .../com/tibiawiki/domain/objects/Quest.java | 76 ++- .../com/tibiawiki/domain/objects/Spell.java | 578 +++++++++++++++--- .../com/tibiawiki/domain/objects/Street.java | 29 +- .../tibiawiki/domain/objects/TibiaObject.java | 129 +++- 15 files changed, 1457 insertions(+), 369 deletions(-) create mode 100644 src/main/java/com/tibiawiki/domain/objects/Missile.java diff --git a/src/main/java/com/tibiawiki/domain/objects/Building.java b/src/main/java/com/tibiawiki/domain/objects/Building.java index 0888c56..50e5c90 100644 --- a/src/main/java/com/tibiawiki/domain/objects/Building.java +++ b/src/main/java/com/tibiawiki/domain/objects/Building.java @@ -1,6 +1,5 @@ package com.tibiawiki.domain.objects; -import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.tibiawiki.domain.enums.BuildingType; import com.tibiawiki.domain.enums.City; import com.tibiawiki.domain.enums.Status; @@ -12,7 +11,6 @@ import java.util.Arrays; import java.util.List; -@JsonIgnoreProperties({"templateType"}) @Getter @Component public class Building extends WikiObject { diff --git a/src/main/java/com/tibiawiki/domain/objects/Effect.java b/src/main/java/com/tibiawiki/domain/objects/Effect.java index 0a8d2f9..5ac255c 100644 --- a/src/main/java/com/tibiawiki/domain/objects/Effect.java +++ b/src/main/java/com/tibiawiki/domain/objects/Effect.java @@ -1,31 +1,53 @@ package com.tibiawiki.domain.objects; -import com.fasterxml.jackson.annotation.JsonIgnoreProperties; -import lombok.AccessLevel; +import com.tibiawiki.domain.enums.Status; +import lombok.Builder; import lombok.Getter; -import lombok.NoArgsConstructor; import org.springframework.stereotype.Component; import java.util.Arrays; import java.util.List; -@JsonIgnoreProperties({"templateType"}) @Getter -@NoArgsConstructor(access = AccessLevel.PRIVATE) @Component public class Effect extends WikiObject { - private String primarytype; - private String secondarytype; - private Integer lightradius; - private Integer lightcolor; - private String causes; + private final Integer effectid; + private final String primarytype; + private final String secondarytype; + private final Integer lightradius; + private final Integer lightcolor; + private final String causes; @SuppressWarnings("squid:S1700") // class and field name are the same, but that's understandable - private String effect; + private final String effect; + + private Effect() { + this.effectid = null; + this.primarytype = null; + this.secondarytype = null; + this.lightradius = null; + this.lightcolor = null; + this.causes = null; + this.effect = null; + } + + @Builder + private Effect(String name, String implemented, String notes, String history, Status status, Integer effectid, + String primarytype, String secondarytype, Integer lightradius, Integer lightcolor, String causes, + String effect) { + super(name, null, null, null, implemented, notes, history, status); + this.effectid = effectid; + this.primarytype = primarytype; + this.secondarytype = secondarytype; + this.lightradius = lightradius; + this.lightcolor = lightcolor; + this.causes = causes; + this.effect = effect; + } @Override public List fieldOrder() { - return Arrays.asList("name", "implemented", "primarytype", "secondarytype", "lightradius", "lightcolor", + return Arrays.asList("name", "implemented", "effectid", "primarytype", "secondarytype", "lightradius", "lightcolor", "causes", "effect", "notes", "history", "status"); } } \ No newline at end of file diff --git a/src/main/java/com/tibiawiki/domain/objects/HuntingPlace.java b/src/main/java/com/tibiawiki/domain/objects/HuntingPlace.java index 992284d..8780bf2 100644 --- a/src/main/java/com/tibiawiki/domain/objects/HuntingPlace.java +++ b/src/main/java/com/tibiawiki/domain/objects/HuntingPlace.java @@ -1,54 +1,120 @@ package com.tibiawiki.domain.objects; -import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonManagedReference; import com.tibiawiki.domain.enums.City; import com.tibiawiki.domain.enums.Star; -import lombok.AccessLevel; +import lombok.Builder; import lombok.Getter; -import lombok.NoArgsConstructor; import org.springframework.stereotype.Component; -import java.util.Collections; +import java.util.Arrays; import java.util.List; -@JsonIgnoreProperties({"templateType"}) @Getter -@NoArgsConstructor(access = AccessLevel.PRIVATE) @Component public class HuntingPlace extends WikiObject { - private String image; - private City city; - private String location; - private String vocation; - private String lvlknights; // Integer? - private String lvlpaladins; // Integer? - private String lvlmages; // Integer? - private String skknights; // Integer? - private String skpaladins; // Integer? - private String skmages; // Integer? - private String defknights; // Integer? - private String defpaladins; // Integer? - private String defmages; // Integer? + private final String image; + private final City city; + private final String location; + private final String vocation; + private final String lvlknights; // Integer? + private final String lvlpaladins; // Integer? + private final String lvlmages; // Integer? + private final String skknights; // Integer? + private final String skpaladins; // Integer? + private final String skmages; // Integer? + private final String defknights; // Integer? + private final String defpaladins; // Integer? + private final String defmages; // Integer? @JsonManagedReference - private List lowerlevels; - private String loot; - private Star lootstar; - private String exp; - private Star expstar; - private String bestloot; - private String bestloot2; - private String bestloot3; - private String bestloot4; - private String bestloot5; - private String map; - private String map2; - private String map3; - private String map4; + private final List lowerlevels; + private final String loot; + private final Star lootstar; + private final String exp; + private final Star expstar; + private final String bestloot; + private final String bestloot2; + private final String bestloot3; + private final String bestloot4; + private final String bestloot5; + private final String map; + private final String map2; + private final String map3; + private final String map4; + + private HuntingPlace() { + this.image = null; + this.city = null; + this.location = null; + this.vocation = null; + this.lvlknights = null; + this.lvlpaladins = null; + this.lvlmages = null; + this.skknights = null; + this.skpaladins = null; + this.skmages = null; + this.defknights = null; + this.defpaladins = null; + this.defmages = null; + this.lowerlevels = null; + this.loot = null; + this.lootstar = null; + this.exp = null; + this.expstar = null; + this.bestloot = null; + this.bestloot2 = null; + this.bestloot3 = null; + this.bestloot4 = null; + this.bestloot5 = null; + this.map = null; + this.map2 = null; + this.map3 = null; + this.map4 = null; + } + + @Builder + private HuntingPlace(String name, String implemented, String image, City city, String location, String vocation, + String lvlknights, String lvlpaladins, String lvlmages, String skknights, String skpaladins, + String skmages, String defknights, String defpaladins, String defmages, + List lowerlevels, String loot, Star lootstar, String exp, Star expstar, + String bestloot, String bestloot2, String bestloot3, String bestloot4, String bestloot5, + String map, String map2, String map3, String map4) { + super(name, null, null, null, implemented, null, null, null); + this.image = image; + this.city = city; + this.location = location; + this.vocation = vocation; + this.lvlknights = lvlknights; + this.lvlpaladins = lvlpaladins; + this.lvlmages = lvlmages; + this.skknights = skknights; + this.skpaladins = skpaladins; + this.skmages = skmages; + this.defknights = defknights; + this.defpaladins = defpaladins; + this.defmages = defmages; + this.lowerlevels = lowerlevels; + this.loot = loot; + this.lootstar = lootstar; + this.exp = exp; + this.expstar = expstar; + this.bestloot = bestloot; + this.bestloot2 = bestloot2; + this.bestloot3 = bestloot3; + this.bestloot4 = bestloot4; + this.bestloot5 = bestloot5; + this.map = map; + this.map2 = map2; + this.map3 = map3; + this.map4 = map4; + } @Override public List fieldOrder() { - return Collections.emptyList(); + return Arrays.asList("name", "image", "implemented", "city", "location", "vocation", "lvlknights", "lvlpaladins", + "lvlmages", "skknights", "skpaladins", "skmages", "defknights", "defpaladins", "defmages", "lowerlevels", + "loot", "lootstar", "exp", "expstar", "bestloot", "bestloot2", "bestloot3", "bestloot4", "bestloot5", + "map", "map2", "map3", "map4"); } } diff --git a/src/main/java/com/tibiawiki/domain/objects/HuntingPlaceSkills.java b/src/main/java/com/tibiawiki/domain/objects/HuntingPlaceSkills.java index b7430ad..c4d1acf 100644 --- a/src/main/java/com/tibiawiki/domain/objects/HuntingPlaceSkills.java +++ b/src/main/java/com/tibiawiki/domain/objects/HuntingPlaceSkills.java @@ -2,26 +2,50 @@ import com.fasterxml.jackson.annotation.JsonBackReference; import lombok.AccessLevel; +import lombok.AllArgsConstructor; +import lombok.Builder; import lombok.Getter; -import lombok.NoArgsConstructor; import org.springframework.stereotype.Component; +import java.util.Arrays; +import java.util.List; + @Getter -@NoArgsConstructor(access = AccessLevel.PRIVATE) +@Builder +@AllArgsConstructor(access = AccessLevel.PRIVATE) @Component public class HuntingPlaceSkills { - private String areaname; - private String lvlknights; - private String lvlpaladins; - private String lvlmages; - private String skknights; - private String skpaladins; - private String skmages; - private String defknights; - private String defpaladins; - private String defmages; + private final String areaname; + private final String lvlknights; + private final String lvlpaladins; + private final String lvlmages; + private final String skknights; + private final String skpaladins; + private final String skmages; + private final String defknights; + private final String defpaladins; + private final String defmages; + + private HuntingPlaceSkills() { + this.areaname = null; + this.lvlknights = null; + this.lvlpaladins = null; + this.lvlmages = null; + this.skknights = null; + this.skpaladins = null; + this.skmages = null; + this.defknights = null; + this.defpaladins = null; + this.defmages = null; + this.huntingPlace = null; + } @JsonBackReference private HuntingPlace huntingPlace; + + public List fieldOrder() { + return Arrays.asList("areaname", "lvlknights", "lvlpaladins", "lvlmages", "skknights", "skpaladins", "skmages", + "defknights", "defpaladins", "defmages"); + } } diff --git a/src/main/java/com/tibiawiki/domain/objects/Item.java b/src/main/java/com/tibiawiki/domain/objects/Item.java index 3fe16ee..f74b365 100644 --- a/src/main/java/com/tibiawiki/domain/objects/Item.java +++ b/src/main/java/com/tibiawiki/domain/objects/Item.java @@ -1,95 +1,306 @@ package com.tibiawiki.domain.objects; +import com.fasterxml.jackson.annotation.JsonGetter; +import com.tibiawiki.domain.enums.Article; import com.tibiawiki.domain.enums.DamageElement; import com.tibiawiki.domain.enums.Hands; import com.tibiawiki.domain.enums.ItemClass; import com.tibiawiki.domain.enums.Status; import com.tibiawiki.domain.enums.WeaponType; import com.tibiawiki.domain.enums.YesNo; +import lombok.Builder; import lombok.Getter; -import lombok.NoArgsConstructor; import org.springframework.stereotype.Component; -import java.util.Collections; +import java.util.Arrays; import java.util.List; @Getter -@NoArgsConstructor @Component public class Item extends WikiObject { - private List itemid; - private YesNo marketable; - private YesNo usable; - private String sprites; - private String flavortext; - private Status ingamestatus; - private String words; - private ItemClass itemclass; - private String primarytype; - private String secondarytype; - private Integer lightcolor; - private Integer lightradius; - private Integer levelrequired; - private String vocrequired; - private Integer mlrequired; - private Hands hands; - private WeaponType type; - private String attack; // FIXME should be Integer - private String elementattack; - private Integer defense; - private String defensemod; - private Integer imbueslots; - private String imbuements; - private YesNo enchantable; - private YesNo enchanted; - private String range; // FIXME should be Integer - private String atk_mod; // FIXME should be Integer - private String hit_mod; // FIXME should be Integer - private Integer armor; - private String resist; - private Integer charges; - private Percentage crithit_ch; - private Percentage critextra_dmg; - private Percentage manaleech_ch; - private Percentage manaleech_am; - private Percentage hpleech_ch; - private Percentage hpleech_am; - private String attrib; - private Double weight; - private YesNo stackable; - private YesNo pickupable; - private YesNo immobile; - private YesNo walkable; - private YesNo unshootable; - private YesNo blockspath; - private YesNo rotatable; - private Integer mapcolor; - private YesNo consumable; - private Integer regenseconds; - private List sounds; - private YesNo writable; - private YesNo rewritable; - private Integer writechars; - private YesNo hangable; - private YesNo holdsliquid; - private Integer mana; - private DamageElement damagetype; - private String damage; // FIXME should be Integer - private Integer volume; - private String duration; // FIXME should be Integer - private YesNo destructible; - private List droppedby; - private String value; - private String npcvalue; - private String npcprice; - private Double npcvaluerook; - private Double npcpricerook; - private String buyfrom; - private String sellto; + private final List itemid; + private final YesNo marketable; + private final YesNo usable; + private final String sprites; + private final String flavortext; + private final Status ingamestatus; + private final String words; + private final ItemClass itemclass; + private final String primarytype; + private final String secondarytype; + private final Integer lightcolor; + private final Integer lightradius; + private final Integer levelrequired; + private final String vocrequired; + private final Integer mlrequired; + private final Hands hands; + private final WeaponType type; + private final String attack; // FIXME should be Integer + private final String elementattack; + private final Integer defense; + private final String defensemod; + private final Integer imbueslots; + private final String imbuements; + private final YesNo enchantable; + private final YesNo enchanted; + private final String range; // FIXME should be Integer + private final String attackModification; // FIXME should be Integer + private final String hitpointModification; // FIXME should be Integer + private final Integer armor; + private final String resist; + private final Integer charges; + private final Percentage criticalHitChance; + private final Percentage criticalHitExtraDamage; + private final Percentage manaleechChance; + private final Percentage manaleechAmount; + private final Percentage hitpointLeechChance; + private final Percentage hitpointLeechAmount; + private final String attrib; + private final Double weight; + private final YesNo stackable; + private final YesNo pickupable; + private final YesNo immobile; + private final YesNo walkable; + private final YesNo unshootable; + private final YesNo blockspath; + private final YesNo rotatable; + private final Integer mapcolor; + private final YesNo consumable; + private final Integer regenseconds; + private final List sounds; + private final YesNo writable; + private final YesNo rewritable; + private final Integer writechars; + private final YesNo hangable; + private final YesNo holdsliquid; + private final Integer mana; + private final DamageElement damagetype; + private final String damage; // FIXME should be Integer + private final Integer volume; + private final String duration; // FIXME should be Integer + private final YesNo destructible; + private final List droppedby; + private final String value; + private final String npcvalue; + private final String npcprice; + private final Double npcvaluerook; + private final Double npcpricerook; + private final String buyfrom; + private final String sellto; + + private Item() { + this.itemid = null; + this.marketable = null; + this.usable = null; + this.sprites = null; + this.flavortext = null; + this.ingamestatus = null; + this.words = null; + this.itemclass = null; + this.primarytype = null; + this.secondarytype = null; + this.lightcolor = null; + this.lightradius = null; + this.levelrequired = null; + this.vocrequired = null; + this.mlrequired = null; + this.hands = null; + this.type = null; + this.attack = null; + this.elementattack = null; + this.defense = null; + this.defensemod = null; + this.imbueslots = null; + this.imbuements = null; + this.enchantable = null; + this.enchanted = null; + this.range = null; + this.attackModification = null; + this.hitpointModification = null; + this.armor = null; + this.resist = null; + this.charges = null; + this.criticalHitChance = null; + this.criticalHitExtraDamage = null; + this.manaleechChance = null; + this.manaleechAmount = null; + this.hitpointLeechChance = null; + this.hitpointLeechAmount = null; + this.attrib = null; + this.weight = null; + this.stackable = null; + this.pickupable = null; + this.immobile = null; + this.walkable = null; + this.unshootable = null; + this.blockspath = null; + this.rotatable = null; + this.mapcolor = null; + this.consumable = null; + this.regenseconds = null; + this.sounds = null; + this.writable = null; + this.rewritable = null; + this.writechars = null; + this.hangable = null; + this.holdsliquid = null; + this.mana = null; + this.damagetype = null; + this.damage = null; + this.volume = null; + this.duration = null; + this.destructible = null; + this.droppedby = null; + this.value = null; + this.npcvalue = null; + this.npcprice = null; + this.npcvaluerook = null; + this.npcpricerook = null; + this.buyfrom = null; + this.sellto = null; + } + + @Builder + private Item(String name, Article article, String actualname, String plural, String implemented, String notes, + String history, Status status, List itemid, YesNo marketable, YesNo usable, String sprites, + String flavortext, Status ingamestatus, String words, ItemClass itemclass, String primarytype, + String secondarytype, Integer lightcolor, Integer lightradius, Integer levelrequired, + String vocrequired, Integer mlrequired, Hands hands, WeaponType type, String attack, + String elementattack, Integer defense, String defensemod, Integer imbueslots, String imbuements, + YesNo enchantable, YesNo enchanted, String range, String attackModification, String hitpointModification, + Integer armor, String resist, Integer charges, Percentage criticalHitChance, + Percentage criticalHitExtraDamage, Percentage manaleechChance, Percentage manaleechAmount, + Percentage hitpointLeechChance, Percentage hitpointLeechAmount, String attrib, Double weight, + YesNo stackable, YesNo pickupable, YesNo immobile, YesNo walkable, YesNo unshootable, YesNo blockspath, + YesNo rotatable, Integer mapcolor, YesNo consumable, Integer regenseconds, List sounds, + YesNo writable, YesNo rewritable, Integer writechars, YesNo hangable, YesNo holdsliquid, Integer mana, + DamageElement damagetype, String damage, Integer volume, String duration, YesNo destructible, + List droppedby, String value, String npcvalue, String npcprice, Double npcvaluerook, + Double npcpricerook, String buyfrom, String sellto) { + super(name, article, actualname, plural, implemented, notes, history, status); + this.itemid = itemid; + this.marketable = marketable; + this.usable = usable; + this.sprites = sprites; + this.flavortext = flavortext; + this.ingamestatus = ingamestatus; + this.words = words; + this.itemclass = itemclass; + this.primarytype = primarytype; + this.secondarytype = secondarytype; + this.lightcolor = lightcolor; + this.lightradius = lightradius; + this.levelrequired = levelrequired; + this.vocrequired = vocrequired; + this.mlrequired = mlrequired; + this.hands = hands; + this.type = type; + this.attack = attack; + this.elementattack = elementattack; + this.defense = defense; + this.defensemod = defensemod; + this.imbueslots = imbueslots; + this.imbuements = imbuements; + this.enchantable = enchantable; + this.enchanted = enchanted; + this.range = range; + this.attackModification = attackModification; + this.hitpointModification = hitpointModification; + this.armor = armor; + this.resist = resist; + this.charges = charges; + this.criticalHitChance = criticalHitChance; + this.criticalHitExtraDamage = criticalHitExtraDamage; + this.manaleechChance = manaleechChance; + this.manaleechAmount = manaleechAmount; + this.hitpointLeechChance = hitpointLeechChance; + this.hitpointLeechAmount = hitpointLeechAmount; + this.attrib = attrib; + this.weight = weight; + this.stackable = stackable; + this.pickupable = pickupable; + this.immobile = immobile; + this.walkable = walkable; + this.unshootable = unshootable; + this.blockspath = blockspath; + this.rotatable = rotatable; + this.mapcolor = mapcolor; + this.consumable = consumable; + this.regenseconds = regenseconds; + this.sounds = sounds; + this.writable = writable; + this.rewritable = rewritable; + this.writechars = writechars; + this.hangable = hangable; + this.holdsliquid = holdsliquid; + this.mana = mana; + this.damagetype = damagetype; + this.damage = damage; + this.volume = volume; + this.duration = duration; + this.destructible = destructible; + this.droppedby = droppedby; + this.value = value; + this.npcvalue = npcvalue; + this.npcprice = npcprice; + this.npcvaluerook = npcvaluerook; + this.npcpricerook = npcpricerook; + this.buyfrom = buyfrom; + this.sellto = sellto; + } + + @JsonGetter("atk_mod") + public String getAttackModification() { + return attackModification; + } + + @JsonGetter("hit_mod") + public String getHitpointModification() { + return hitpointModification; + } + + @JsonGetter("crithit_ch") + public Percentage getCriticalHitChance() { + return criticalHitChance; + } + + @JsonGetter("critextra_dmg") + public Percentage getCriticalHitExtraDamage() { + return criticalHitExtraDamage; + } + + @JsonGetter("manaleech_ch") + public Percentage getManaleechChance() { + return manaleechChance; + } + + @JsonGetter("manaleech_am") + public Percentage getManaleechAmount() { + return manaleechAmount; + } + + @JsonGetter("hpleech_ch") + public Percentage getHitpointLeechChance() { + return hitpointLeechChance; + } + + @JsonGetter("hpleech_am") + public Percentage getHitpointLeechAmount() { + return hitpointLeechAmount; + } @Override public List fieldOrder() { - return Collections.emptyList(); + return Arrays.asList("name", "article", "actualname", "plural", "itemid", "marketable", "usable", "sprites", + "flavortext", "implemented", "words", "itemclass", "primarytype", "secondarytype", "lightcolor", + "lightradius", "levelrequired", "vocrequired", "mlrequired", "hands", "type", "attack", "elementattack", + "defense", "defensemod", "imbueslots", "imbuements", "range", "atk_mod", "hit_mod", "armor", "resist", + "charges", "crithit_ch", "critextra_dmg", "manaleech_ch", "manaleech_am", "hpleech_ch", "hpleech_am", + "attrib", "weight", "stackable", "pickupable", "immobile", "walkable", "unshootable", "blockspath", + "rotatable", "mapcolor", "consumable", "regenseconds", "sounds", "writable", "rewritable", "writechars", + "hangable", "holdsliquid", "mana", "damagetype", "damage", "volume", "duration", "destructible", + "droppedby", "value", "npcvalue", "npcprice", "npcvaluerook", "npcpricerook", "buyfrom", "sellto", + "notes", "history", "status"); } } \ No newline at end of file diff --git a/src/main/java/com/tibiawiki/domain/objects/Key.java b/src/main/java/com/tibiawiki/domain/objects/Key.java index 33b53de..c2fadc2 100644 --- a/src/main/java/com/tibiawiki/domain/objects/Key.java +++ b/src/main/java/com/tibiawiki/domain/objects/Key.java @@ -1,33 +1,67 @@ package com.tibiawiki.domain.objects; -import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.tibiawiki.domain.enums.KeyType; +import com.tibiawiki.domain.enums.Status; +import lombok.Builder; import lombok.Getter; -import lombok.NoArgsConstructor; import org.springframework.stereotype.Component; import java.util.Arrays; import java.util.List; -@JsonIgnoreProperties({"templateType"}) @Getter -@NoArgsConstructor @Component public class Key extends WikiObject { - private String number; - private String aka; - private KeyType primarytype; - private KeyType secondarytype; - private String location; - private String value; - private Integer npcvalue; - private Integer npcprice; - private String buyfrom; - private String sellto; - private String origin; - private String shortnotes; - private String longnotes; + private final String number; + private final String aka; + private final KeyType primarytype; + private final KeyType secondarytype; + private final String location; + private final String value; + private final Integer npcvalue; + private final Integer npcprice; + private final String buyfrom; + private final String sellto; + private final String origin; + private final String shortnotes; + private final String longnotes; + + private Key() { + this.number = null; + this.aka = null; + this.primarytype = null; + this.secondarytype = null; + this.location = null; + this.value = null; + this.npcvalue = null; + this.npcprice = null; + this.buyfrom = null; + this.sellto = null; + this.origin = null; + this.shortnotes = null; + this.longnotes = null; + } + + @Builder + private Key(String implemented, String history, Status status, String number, String aka, KeyType primarytype, + KeyType secondarytype, String location, String value, Integer npcvalue, Integer npcprice, String buyfrom, + String sellto, String origin, String shortnotes, String longnotes) { + super(null, null, null, null, implemented, null, history, status); + this.number = number; + this.aka = aka; + this.primarytype = primarytype; + this.secondarytype = secondarytype; + this.location = location; + this.value = value; + this.npcvalue = npcvalue; + this.npcprice = npcprice; + this.buyfrom = buyfrom; + this.sellto = sellto; + this.origin = origin; + this.shortnotes = shortnotes; + this.longnotes = longnotes; + } @Override public List fieldOrder() { diff --git a/src/main/java/com/tibiawiki/domain/objects/Location.java b/src/main/java/com/tibiawiki/domain/objects/Location.java index b0d4299..cb0babc 100644 --- a/src/main/java/com/tibiawiki/domain/objects/Location.java +++ b/src/main/java/com/tibiawiki/domain/objects/Location.java @@ -1,32 +1,61 @@ package com.tibiawiki.domain.objects; -import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.tibiawiki.domain.enums.Status; import com.tibiawiki.domain.enums.YesNo; -import lombok.AccessLevel; +import lombok.Builder; import lombok.Getter; -import lombok.NoArgsConstructor; import org.springframework.stereotype.Component; import java.util.Arrays; import java.util.List; -@JsonIgnoreProperties({"templateType"}) @Getter -@NoArgsConstructor(access = AccessLevel.PRIVATE) @Component public class Location extends WikiObject { - private String ruler; - private Integer population; - private String near; - private String organization; - private String map; - private String map2; - private String map3; - private String map4; - private String map5; - private String map6; - private YesNo links; + private final String ruler; + private final Integer population; + private final String near; + private final String organization; + private final String map; + private final String map2; + private final String map3; + private final String map4; + private final String map5; + private final String map6; + private final YesNo links; + + private Location() { + this.ruler = null; + this.population = null; + this.near = null; + this.organization = null; + this.map = null; + this.map2 = null; + this.map3 = null; + this.map4 = null; + this.map5 = null; + this.map6 = null; + this.links = null; + } + + @Builder + private Location(String name, String implemented, Status status, String ruler, Integer population, String near, + String organization, String map, String map2, String map3, String map4, String map5, String map6, + YesNo links) { + super(name, null, null, null, implemented, null, null, status); + this.ruler = ruler; + this.population = population; + this.near = near; + this.organization = organization; + this.map = map; + this.map2 = map2; + this.map3 = map3; + this.map4 = map4; + this.map5 = map5; + this.map6 = map6; + this.links = links; + } @Override public List fieldOrder() { diff --git a/src/main/java/com/tibiawiki/domain/objects/Missile.java b/src/main/java/com/tibiawiki/domain/objects/Missile.java new file mode 100644 index 0000000..f8df524 --- /dev/null +++ b/src/main/java/com/tibiawiki/domain/objects/Missile.java @@ -0,0 +1,48 @@ +package com.tibiawiki.domain.objects; + +import com.tibiawiki.domain.enums.Status; +import lombok.Builder; +import lombok.Getter; +import org.springframework.stereotype.Component; + +import java.util.Arrays; +import java.util.List; + +@Getter +@Component +public class Missile extends WikiObject { + + private final Integer missileid; + private final String primarytype; + private final String secondarytype; + private final Integer lightradius; + private final Integer lightcolor; + private final String shotby; + + private Missile() { + this.missileid = null; + this.primarytype = null; + this.secondarytype = null; + this.lightradius = null; + this.lightcolor = null; + this.shotby = null; + } + + @Builder + private Missile(String name, String implemented, String notes, String history, Status status, Integer missileid, + String primarytype, String secondarytype, Integer lightradius, Integer lightcolor, String shotby) { + super(name, null, null, null, implemented, notes, history, status); + this.missileid = missileid; + this.primarytype = primarytype; + this.secondarytype = secondarytype; + this.lightradius = lightradius; + this.lightcolor = lightcolor; + this.shotby = shotby; + } + + @Override + public List fieldOrder() { + return Arrays.asList("name", "implemented", "missileid", "primarytype", "secondarytype", "lightradius", "lightcolor", + "shotby", "notes", "history", "status"); + } +} \ No newline at end of file diff --git a/src/main/java/com/tibiawiki/domain/objects/Mount.java b/src/main/java/com/tibiawiki/domain/objects/Mount.java index 3b9e313..b878f5f 100644 --- a/src/main/java/com/tibiawiki/domain/objects/Mount.java +++ b/src/main/java/com/tibiawiki/domain/objects/Mount.java @@ -1,29 +1,53 @@ package com.tibiawiki.domain.objects; import com.fasterxml.jackson.annotation.JsonGetter; -import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.tibiawiki.domain.enums.Status; import com.tibiawiki.domain.enums.YesNo; +import lombok.Builder; import lombok.Getter; -import lombok.NoArgsConstructor; import org.springframework.stereotype.Component; import java.util.Arrays; import java.util.List; -@JsonIgnoreProperties({"templateType"}) @Getter -@NoArgsConstructor @Component public class Mount extends WikiObject { - private Integer speed; - private String tamingMethod; - private YesNo bought; - private Integer price; // unit is Tibia Coins - private String achievement; // this could link to Achievement - private Integer lightradius; - private Integer lightcolor; - private String artwork; + private final Integer speed; + private final String tamingMethod; + private final YesNo bought; + private final Integer price; // unit is Tibia Coins + private final String achievement; // this could link to Achievement + private final Integer lightradius; + private final Integer lightcolor; + private final String artwork; + + private Mount() { + this.speed = null; + this.tamingMethod = null; + this.bought = null; + this.price = null; + this.achievement = null; + this.lightradius = null; + this.lightcolor = null; + this.artwork = null; + } + + @Builder + private Mount(String name, String implemented, String notes, String history, Status status, Integer speed, + String tamingMethod, YesNo bought, Integer price, String achievement, Integer lightradius, + Integer lightcolor, String artwork) { + super(name, null, null, null, implemented, notes, history, status); + this.speed = speed; + this.tamingMethod = tamingMethod; + this.bought = bought; + this.price = price; + this.achievement = achievement; + this.lightradius = lightradius; + this.lightcolor = lightcolor; + this.artwork = artwork; + } @JsonGetter("taming_method") private String getTamingMethod() { @@ -32,7 +56,7 @@ private String getTamingMethod() { @Override public List fieldOrder() { - return Arrays.asList("name", "speed", "tamingMethod", "bought", "price", "achievement", "lightcolor", + return Arrays.asList("name", "speed", "taming_method", "bought", "price", "achievement", "lightcolor", "lightradius", "implemented", "artwork", "notes", "history", "status"); } } \ No newline at end of file diff --git a/src/main/java/com/tibiawiki/domain/objects/NPC.java b/src/main/java/com/tibiawiki/domain/objects/NPC.java index 6ce2a75..44fb36a 100644 --- a/src/main/java/com/tibiawiki/domain/objects/NPC.java +++ b/src/main/java/com/tibiawiki/domain/objects/NPC.java @@ -1,56 +1,130 @@ package com.tibiawiki.domain.objects; -import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.tibiawiki.domain.enums.City; import com.tibiawiki.domain.enums.Gender; +import com.tibiawiki.domain.enums.Status; import com.tibiawiki.domain.enums.YesNo; +import lombok.Builder; import lombok.Getter; -import lombok.NoArgsConstructor; import org.springframework.stereotype.Component; -import java.util.Collections; +import java.util.Arrays; import java.util.List; -@JsonIgnoreProperties({"templateType"}) @Getter -@NoArgsConstructor @Component public class NPC extends WikiObject { - private String job; - private String job2; - private String job3; - private String job4; - private String job5; - private String job6; - private String location; - private City city; - private City city2; - private String street; - private Double posx; - private Double posy; - private Integer posz; - private Double posx2; - private Double posy2; - private Integer posz2; - private Double posx3; - private Double posy3; - private Integer posz3; - private Double posx4; - private Double posy4; - private Integer posz4; - private Double posx5; - private Double posy5; - private Integer posz5; - private Gender gender; - private String race; - private YesNo buysell; - private String buys; - private String sells; - private List sounds; + private final String job; + private final String job2; + private final String job3; + private final String job4; + private final String job5; + private final String job6; + private final String location; + private final City city; + private final City city2; + private final String street; + private final Double posx; + private final Double posy; + private final Integer posz; + private final Double posx2; + private final Double posy2; + private final Integer posz2; + private final Double posx3; + private final Double posy3; + private final Integer posz3; + private final Double posx4; + private final Double posy4; + private final Integer posz4; + private final Double posx5; + private final Double posy5; + private final Integer posz5; + private final Gender gender; + private final String race; + private final YesNo buysell; + private final String buys; + private final String sells; + private final List sounds; + + private NPC() { + this.job = null; + this.job2 = null; + this.job3 = null; + this.job4 = null; + this.job5 = null; + this.job6 = null; + this.location = null; + this.city = null; + this.city2 = null; + this.street = null; + this.posx = null; + this.posy = null; + this.posz = null; + this.posx2 = null; + this.posy2 = null; + this.posz2 = null; + this.posx3 = null; + this.posy3 = null; + this.posz3 = null; + this.posx4 = null; + this.posy4 = null; + this.posz4 = null; + this.posx5 = null; + this.posy5 = null; + this.posz5 = null; + this.gender = null; + this.race = null; + this.buysell = null; + this.buys = null; + this.sells = null; + this.sounds = null; + } + + @Builder + private NPC(String name, String actualname, String implemented, String notes, String history, Status status, + String job, String job2, String job3, String job4, String job5, String job6, String location, City city, + City city2, String street, Double posx, Double posy, Integer posz, Double posx2, Double posy2, + Integer posz2, Double posx3, Double posy3, Integer posz3, Double posx4, Double posy4, Integer posz4, + Double posx5, Double posy5, Integer posz5, Gender gender, String race, YesNo buysell, String buys, + String sells, List sounds) { + super(name, null, actualname, null, implemented, notes, history, status); + this.job = job; + this.job2 = job2; + this.job3 = job3; + this.job4 = job4; + this.job5 = job5; + this.job6 = job6; + this.location = location; + this.city = city; + this.city2 = city2; + this.street = street; + this.posx = posx; + this.posy = posy; + this.posz = posz; + this.posx2 = posx2; + this.posy2 = posy2; + this.posz2 = posz2; + this.posx3 = posx3; + this.posy3 = posy3; + this.posz3 = posz3; + this.posx4 = posx4; + this.posy4 = posy4; + this.posz4 = posz4; + this.posx5 = posx5; + this.posy5 = posy5; + this.posz5 = posz5; + this.gender = gender; + this.race = race; + this.buysell = buysell; + this.buys = buys; + this.sells = sells; + this.sounds = sounds; + } @Override public List fieldOrder() { - return Collections.emptyList(); + return Arrays.asList("name", "actualname", "job", "location", "city", "street", "posx", "posy", "posz", "gender", + "race", "buysell", "buys", "sells", "sounds", "implemented", "notes", "history", "status"); } } \ No newline at end of file diff --git a/src/main/java/com/tibiawiki/domain/objects/Outfit.java b/src/main/java/com/tibiawiki/domain/objects/Outfit.java index 3261cfd..9ee0a7a 100644 --- a/src/main/java/com/tibiawiki/domain/objects/Outfit.java +++ b/src/main/java/com/tibiawiki/domain/objects/Outfit.java @@ -1,30 +1,56 @@ package com.tibiawiki.domain.objects; -import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.tibiawiki.domain.enums.Status; import com.tibiawiki.domain.enums.YesNo; +import lombok.Builder; import lombok.Getter; -import lombok.NoArgsConstructor; import org.springframework.stereotype.Component; import java.util.Arrays; import java.util.List; -@JsonIgnoreProperties({"templateType"}) @Getter -@NoArgsConstructor @Component public class Outfit extends WikiObject { - private String primarytype; - private String secondarytype; - private YesNo premium; + private final String primarytype; + private final String secondarytype; + private final YesNo premium; @SuppressWarnings("squid:S1700") // class and field name are the same, but that's understandable - private String outfit; - private String addons; - private YesNo bought; - private Integer fulloutfitprice; - private String achievement; - private String artwork; + private final String outfit; + private final String addons; + private final YesNo bought; + private final Integer fulloutfitprice; + private final String achievement; + private final String artwork; + + private Outfit() { + this.primarytype = null; + this.secondarytype = null; + this.premium = null; + this.outfit = null; + this.addons = null; + this.bought = null; + this.fulloutfitprice = null; + this.achievement = null; + this.artwork = null; + } + + @Builder + private Outfit(String name, String implemented, String notes, String history, Status status, String primarytype, + String secondarytype, YesNo premium, String outfit, String addons, YesNo bought, + Integer fulloutfitprice, String achievement, String artwork) { + super(name, null, null, null, implemented, notes, history, status); + this.primarytype = primarytype; + this.secondarytype = secondarytype; + this.premium = premium; + this.outfit = outfit; + this.addons = addons; + this.bought = bought; + this.fulloutfitprice = fulloutfitprice; + this.achievement = achievement; + this.artwork = artwork; + } @Override public List fieldOrder() { diff --git a/src/main/java/com/tibiawiki/domain/objects/Quest.java b/src/main/java/com/tibiawiki/domain/objects/Quest.java index f365547..ad85646 100644 --- a/src/main/java/com/tibiawiki/domain/objects/Quest.java +++ b/src/main/java/com/tibiawiki/domain/objects/Quest.java @@ -1,36 +1,74 @@ package com.tibiawiki.domain.objects; -import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.tibiawiki.domain.enums.QuestType; +import com.tibiawiki.domain.enums.Status; import com.tibiawiki.domain.enums.YesNo; +import lombok.Builder; import lombok.Getter; -import lombok.NoArgsConstructor; import org.springframework.stereotype.Component; import java.util.Arrays; import java.util.List; -@JsonIgnoreProperties({"templateType"}) @Getter -@NoArgsConstructor @Component public class Quest extends WikiObject { - private String aka; - private String reward; - private String location; - private YesNo rookgaardquest; - private QuestType type; - private Integer lvl; - private Integer lvlrec; - private String lvlnote; - private YesNo log; - private String time; - private String timealloc; - private YesNo premium; - private YesNo transcripts; - private String dangers; - private String legend; + private final String aka; + private final String reward; + private final String location; + private final YesNo rookgaardquest; + private final QuestType type; + private final Integer lvl; + private final Integer lvlrec; + private final String lvlnote; + private final YesNo log; + private final String time; + private final String timealloc; + private final YesNo premium; + private final YesNo transcripts; + private final String dangers; + private final String legend; + + private Quest() { + this.aka = null; + this.reward = null; + this.location = null; + this.rookgaardquest = null; + this.type = null; + this.lvl = null; + this.lvlrec = null; + this.lvlnote = null; + this.log = null; + this.time = null; + this.timealloc = null; + this.premium = null; + this.transcripts = null; + this.dangers = null; + this.legend = null; + } + + @Builder + private Quest(String name, String implemented, String history, Status status, String aka, String reward, + String location, YesNo rookgaardquest, QuestType type, Integer lvl, Integer lvlrec, String lvlnote, + YesNo log, String time, String timealloc, YesNo premium, YesNo transcripts, String dangers, String legend) { + super(name, null, null, null, implemented, null, history, status); + this.aka = aka; + this.reward = reward; + this.location = location; + this.rookgaardquest = rookgaardquest; + this.type = type; + this.lvl = lvl; + this.lvlrec = lvlrec; + this.lvlnote = lvlnote; + this.log = log; + this.time = time; + this.timealloc = timealloc; + this.premium = premium; + this.transcripts = transcripts; + this.dangers = dangers; + this.legend = legend; + } @Override public List fieldOrder() { diff --git a/src/main/java/com/tibiawiki/domain/objects/Spell.java b/src/main/java/com/tibiawiki/domain/objects/Spell.java index 21ed11d..3e8955e 100644 --- a/src/main/java/com/tibiawiki/domain/objects/Spell.java +++ b/src/main/java/com/tibiawiki/domain/objects/Spell.java @@ -1,109 +1,523 @@ package com.tibiawiki.domain.objects; import com.fasterxml.jackson.annotation.JsonGetter; -import com.fasterxml.jackson.annotation.JsonIgnoreProperties; -import com.fasterxml.jackson.annotation.JsonSetter; import com.tibiawiki.domain.enums.SpellSubclass; import com.tibiawiki.domain.enums.SpellType; +import com.tibiawiki.domain.enums.Status; import com.tibiawiki.domain.enums.YesNo; import lombok.Getter; -import lombok.NoArgsConstructor; import org.springframework.stereotype.Component; import java.util.Arrays; import java.util.List; -@JsonIgnoreProperties({"templateType"}) @Getter -@NoArgsConstructor @Component public class Spell extends WikiObject { - private SpellType type; - private SpellSubclass subclass; - private SpellSubclass runegroup; - private String damagetype; - private String words; - private Integer mana; - private Integer cooldown; - private Integer cooldowngroup; - private Integer cooldowngroup2; - private Integer levelrequired; - private YesNo premium; - private YesNo promotion; - private Integer soul; - private YesNo zoltanonly; - private YesNo partyspell; - private YesNo specialspell; - private YesNo conjurespell; - private String voc; - private String druidAbDendriel; - private String druidAnkrahmun; - private String druidCarlin; - private String druidDarashia; - private String druidEdron; - private String druidKazordoon; - private String druidLibertyBay; - private String druidPortHope; - private String druidRathleton; - private String druidSvargrond; - private String druidThais; - private String druidVenore; - private String druidYalahar; - private String knightAbDendriel; - private String knightAnkrahmun; - private String knightCarlin; - private String knightDarashia; - private String knightEdron; - private String knightKazordoon; - private String knightLibertyBay; - private String knightPortHope; - private String knightRathleton; - private String knightSvargrond; - private String knightThais; - private String knightVenore; - private String knightYalahar; - private String paladinAbDendriel; - private String paladinAnkrahmun; - private String paladinCarlin; - private String paladinDarashia; - private String paladinEdron; - private String paladinKazordoon; - private String paladinLibertyBay; - private String paladinPortHope; - private String paladinRathleton; - private String paladinSvargrond; - private String paladinThais; - private String paladinVenore; - private String paladinYalahar; - private String sorcererAbDendriel; - private String sorcererAnkrahmun; - private String sorcererCarlin; - private String sorcererDarashia; - private String sorcererEdron; - private String sorcererKazordoon; - private String sorcererLibertyBay; - private String sorcererPortHope; - private String sorcererRathleton; - private String sorcererSvargrond; - private String sorcererThais; - private String sorcererVenore; - private String sorcererYalahar; - private Integer spellcost; - private String effect; - private String animation; + private final SpellType type; + private final SpellSubclass subclass; + private final SpellSubclass runegroup; + private final String damagetype; + private final String words; + private final Integer mana; + private final Integer cooldown; + private final Integer cooldowngroup; + private final Integer cooldowngroup2; + private final Integer levelrequired; + private final YesNo premium; + private final YesNo promotion; + private final Integer soul; + private final YesNo zoltanonly; + private final YesNo partyspell; + private final YesNo specialspell; + private final YesNo conjurespell; + private final String voc; + private final String druidAbDendriel; + private final String druidAnkrahmun; + private final String druidCarlin; + private final String druidDarashia; + private final String druidEdron; + private final String druidKazordoon; + private final String druidLibertyBay; + private final String druidPortHope; + private final String druidRathleton; + private final String druidSvargrond; + private final String druidThais; + private final String druidVenore; + private final String druidYalahar; + private final String knightAbDendriel; + private final String knightAnkrahmun; + private final String knightCarlin; + private final String knightDarashia; + private final String knightEdron; + private final String knightKazordoon; + private final String knightLibertyBay; + private final String knightPortHope; + private final String knightRathleton; + private final String knightSvargrond; + private final String knightThais; + private final String knightVenore; + private final String knightYalahar; + private final String paladinAbDendriel; + private final String paladinAnkrahmun; + private final String paladinCarlin; + private final String paladinDarashia; + private final String paladinEdron; + private final String paladinKazordoon; + private final String paladinLibertyBay; + private final String paladinPortHope; + private final String paladinRathleton; + private final String paladinSvargrond; + private final String paladinThais; + private final String paladinVenore; + private final String paladinYalahar; + private final String sorcererAbDendriel; + private final String sorcererAnkrahmun; + private final String sorcererCarlin; + private final String sorcererDarashia; + private final String sorcererEdron; + private final String sorcererKazordoon; + private final String sorcererLibertyBay; + private final String sorcererPortHope; + private final String sorcererRathleton; + private final String sorcererSvargrond; + private final String sorcererThais; + private final String sorcererVenore; + private final String sorcererYalahar; + private final Integer spellcost; + private final String effect; + private final String animation; + + private Spell() { + this.type = null; + this.subclass = null; + this.runegroup = null; + this.damagetype = null; + this.words = null; + this.mana = null; + this.cooldown = null; + this.cooldowngroup = null; + this.cooldowngroup2 = null; + this.levelrequired = null; + this.premium = null; + this.promotion = null; + this.soul = null; + this.zoltanonly = null; + this.partyspell = null; + this.specialspell = null; + this.conjurespell = null; + this.voc = null; + this.druidAbDendriel = null; + this.druidAnkrahmun = null; + this.druidCarlin = null; + this.druidDarashia = null; + this.druidEdron = null; + this.druidKazordoon = null; + this.druidLibertyBay = null; + this.druidPortHope = null; + this.druidRathleton = null; + this.druidSvargrond = null; + this.druidThais = null; + this.druidVenore = null; + this.druidYalahar = null; + this.knightAbDendriel = null; + this.knightAnkrahmun = null; + this.knightCarlin = null; + this.knightDarashia = null; + this.knightEdron = null; + this.knightKazordoon = null; + this.knightLibertyBay = null; + this.knightPortHope = null; + this.knightRathleton = null; + this.knightSvargrond = null; + this.knightThais = null; + this.knightVenore = null; + this.knightYalahar = null; + this.paladinAbDendriel = null; + this.paladinAnkrahmun = null; + this.paladinCarlin = null; + this.paladinDarashia = null; + this.paladinEdron = null; + this.paladinKazordoon = null; + this.paladinLibertyBay = null; + this.paladinPortHope = null; + this.paladinRathleton = null; + this.paladinSvargrond = null; + this.paladinThais = null; + this.paladinVenore = null; + this.paladinYalahar = null; + this.sorcererAbDendriel = null; + this.sorcererAnkrahmun = null; + this.sorcererCarlin = null; + this.sorcererDarashia = null; + this.sorcererEdron = null; + this.sorcererKazordoon = null; + this.sorcererLibertyBay = null; + this.sorcererPortHope = null; + this.sorcererRathleton = null; + this.sorcererSvargrond = null; + this.sorcererThais = null; + this.sorcererVenore = null; + this.sorcererYalahar = null; + this.spellcost = null; + this.effect = null; + this.animation = null; + } + + private Spell(String name, String implemented, String notes, String history, Status status, SpellType type, + SpellSubclass subclass, SpellSubclass runegroup, String damagetype, String words, Integer mana, + Integer cooldown, Integer cooldowngroup, Integer cooldowngroup2, Integer levelrequired, YesNo premium, + YesNo promotion, Integer soul, YesNo zoltanonly, YesNo partyspell, YesNo specialspell, + YesNo conjurespell, String voc, String druidAbDendriel, String druidAnkrahmun, String druidCarlin, + String druidDarashia, String druidEdron, String druidKazordoon, String druidLibertyBay, + String druidPortHope, String druidRathleton, String druidSvargrond, String druidThais, + String druidVenore, String druidYalahar, String knightAbDendriel, String knightAnkrahmun, + String knightCarlin, String knightDarashia, String knightEdron, String knightKazordoon, + String knightLibertyBay, String knightPortHope, String knightRathleton, String knightSvargrond, + String knightThais, String knightVenore, String knightYalahar, String paladinAbDendriel, + String paladinAnkrahmun, String paladinCarlin, String paladinDarashia, String paladinEdron, + String paladinKazordoon, String paladinLibertyBay, String paladinPortHope, String paladinRathleton, + String paladinSvargrond, String paladinThais, String paladinVenore, String paladinYalahar, + String sorcererAbDendriel, String sorcererAnkrahmun, String sorcererCarlin, String sorcererDarashia, + String sorcererEdron, String sorcererKazordoon, String sorcererLibertyBay, String sorcererPortHope, + String sorcererRathleton, String sorcererSvargrond, String sorcererThais, String sorcererVenore, + String sorcererYalahar, Integer spellcost, String effect, String animation) { + super(name, null, null, null, implemented, notes, history, status); + this.type = type; + this.subclass = subclass; + this.runegroup = runegroup; + this.damagetype = damagetype; + this.words = words; + this.mana = mana; + this.cooldown = cooldown; + this.cooldowngroup = cooldowngroup; + this.cooldowngroup2 = cooldowngroup2; + this.levelrequired = levelrequired; + this.premium = premium; + this.promotion = promotion; + this.soul = soul; + this.zoltanonly = zoltanonly; + this.partyspell = partyspell; + this.specialspell = specialspell; + this.conjurespell = conjurespell; + this.voc = voc; + this.druidAbDendriel = druidAbDendriel; + this.druidAnkrahmun = druidAnkrahmun; + this.druidCarlin = druidCarlin; + this.druidDarashia = druidDarashia; + this.druidEdron = druidEdron; + this.druidKazordoon = druidKazordoon; + this.druidLibertyBay = druidLibertyBay; + this.druidPortHope = druidPortHope; + this.druidRathleton = druidRathleton; + this.druidSvargrond = druidSvargrond; + this.druidThais = druidThais; + this.druidVenore = druidVenore; + this.druidYalahar = druidYalahar; + this.knightAbDendriel = knightAbDendriel; + this.knightAnkrahmun = knightAnkrahmun; + this.knightCarlin = knightCarlin; + this.knightDarashia = knightDarashia; + this.knightEdron = knightEdron; + this.knightKazordoon = knightKazordoon; + this.knightLibertyBay = knightLibertyBay; + this.knightPortHope = knightPortHope; + this.knightRathleton = knightRathleton; + this.knightSvargrond = knightSvargrond; + this.knightThais = knightThais; + this.knightVenore = knightVenore; + this.knightYalahar = knightYalahar; + this.paladinAbDendriel = paladinAbDendriel; + this.paladinAnkrahmun = paladinAnkrahmun; + this.paladinCarlin = paladinCarlin; + this.paladinDarashia = paladinDarashia; + this.paladinEdron = paladinEdron; + this.paladinKazordoon = paladinKazordoon; + this.paladinLibertyBay = paladinLibertyBay; + this.paladinPortHope = paladinPortHope; + this.paladinRathleton = paladinRathleton; + this.paladinSvargrond = paladinSvargrond; + this.paladinThais = paladinThais; + this.paladinVenore = paladinVenore; + this.paladinYalahar = paladinYalahar; + this.sorcererAbDendriel = sorcererAbDendriel; + this.sorcererAnkrahmun = sorcererAnkrahmun; + this.sorcererCarlin = sorcererCarlin; + this.sorcererDarashia = sorcererDarashia; + this.sorcererEdron = sorcererEdron; + this.sorcererKazordoon = sorcererKazordoon; + this.sorcererLibertyBay = sorcererLibertyBay; + this.sorcererPortHope = sorcererPortHope; + this.sorcererRathleton = sorcererRathleton; + this.sorcererSvargrond = sorcererSvargrond; + this.sorcererThais = sorcererThais; + this.sorcererVenore = sorcererVenore; + this.sorcererYalahar = sorcererYalahar; + this.spellcost = spellcost; + this.effect = effect; + this.animation = animation; + } @JsonGetter("d-abd") private String getDruidAbDendriel() { return druidAbDendriel; } - @JsonSetter("d-abd") - private void setDruidAbDendriel(String druidAbDendriel) { - this.druidAbDendriel = druidAbDendriel; + @JsonGetter("d-ank") + public String getDruidAnkrahmun() { + return druidAnkrahmun; + } + + @JsonGetter("d-car") + public String getDruidCarlin() { + return druidCarlin; + } + + @JsonGetter("d-dar") + public String getDruidDarashia() { + return druidDarashia; + } + + @JsonGetter("d-edr") + public String getDruidEdron() { + return druidEdron; + } + + @JsonGetter("d-kaz") + public String getDruidKazordoon() { + return druidKazordoon; } - //@todo add jsongetters and setters for the other 51 parameters + @JsonGetter("d-lib") + public String getDruidLibertyBay() { + return druidLibertyBay; + } + + @JsonGetter("d-por") + public String getDruidPortHope() { + return druidPortHope; + } + + @JsonGetter("d-rat") + public String getDruidRathleton() { + return druidRathleton; + } + + @JsonGetter("d-sva") + public String getDruidSvargrond() { + return druidSvargrond; + } + + @JsonGetter("d-tha") + public String getDruidThais() { + return druidThais; + } + + @JsonGetter("d-ven") + public String getDruidVenore() { + return druidVenore; + } + + @JsonGetter("d-yal") + public String getDruidYalahar() { + return druidYalahar; + } + + @JsonGetter("k-abd") + public String getKnightAbDendriel() { + return knightAbDendriel; + } + + @JsonGetter("k-ank") + public String getKnightAnkrahmun() { + return knightAnkrahmun; + } + + @JsonGetter("k-car") + public String getKnightCarlin() { + return knightCarlin; + } + + @JsonGetter("k-dar") + public String getKnightDarashia() { + return knightDarashia; + } + + @JsonGetter("k-edr") + public String getKnightEdron() { + return knightEdron; + } + + @JsonGetter("k-kaz") + public String getKnightKazordoon() { + return knightKazordoon; + } + + @JsonGetter("k-lib") + public String getKnightLibertyBay() { + return knightLibertyBay; + } + + @JsonGetter("k-por") + public String getKnightPortHope() { + return knightPortHope; + } + + @JsonGetter("k-rat") + public String getKnightRathleton() { + return knightRathleton; + } + + @JsonGetter("k-sva") + public String getKnightSvargrond() { + return knightSvargrond; + } + + @JsonGetter("k-tha") + public String getKnightThais() { + return knightThais; + } + + @JsonGetter("k-ven") + public String getKnightVenore() { + return knightVenore; + } + + @JsonGetter("k-yal") + public String getKnightYalahar() { + return knightYalahar; + } + + @JsonGetter("p-abd") + public String getPaladinAbDendriel() { + return paladinAbDendriel; + } + + @JsonGetter("p-ank") + public String getPaladinAnkrahmun() { + return paladinAnkrahmun; + } + + @JsonGetter("p-car") + public String getPaladinCarlin() { + return paladinCarlin; + } + + @JsonGetter("p-dar") + public String getPaladinDarashia() { + return paladinDarashia; + } + + @JsonGetter("p-edr") + public String getPaladinEdron() { + return paladinEdron; + } + + @JsonGetter("p-kaz") + public String getPaladinKazordoon() { + return paladinKazordoon; + } + + @JsonGetter("p-lib") + public String getPaladinLibertyBay() { + return paladinLibertyBay; + } + + @JsonGetter("p-por") + public String getPaladinPortHope() { + return paladinPortHope; + } + + @JsonGetter("p-rat") + public String getPaladinRathleton() { + return paladinRathleton; + } + + @JsonGetter("p-sva") + public String getPaladinSvargrond() { + return paladinSvargrond; + } + + @JsonGetter("p-tha") + public String getPaladinThais() { + return paladinThais; + } + + @JsonGetter("p-ven") + public String getPaladinVenore() { + return paladinVenore; + } + + @JsonGetter("p-yal") + public String getPaladinYalahar() { + return paladinYalahar; + } + + @JsonGetter("s-abd") + public String getSorcererAbDendriel() { + return sorcererAbDendriel; + } + + @JsonGetter("s-ank") + public String getSorcererAnkrahmun() { + return sorcererAnkrahmun; + } + + @JsonGetter("s-car") + public String getSorcererCarlin() { + return sorcererCarlin; + } + + @JsonGetter("s-dar") + public String getSorcererDarashia() { + return sorcererDarashia; + } + + @JsonGetter("s-edr") + public String getSorcererEdron() { + return sorcererEdron; + } + + @JsonGetter("s-kaz") + public String getSorcererKazordoon() { + return sorcererKazordoon; + } + + @JsonGetter("s-lib") + public String getSorcererLibertyBay() { + return sorcererLibertyBay; + } + + @JsonGetter("s-por") + public String getSorcererPortHope() { + return sorcererPortHope; + } + + @JsonGetter("s-rat") + public String getSorcererRathleton() { + return sorcererRathleton; + } + + @JsonGetter("s-sva") + public String getSorcererSvargrond() { + return sorcererSvargrond; + } + + @JsonGetter("s-tha") + public String getSorcererThais() { + return sorcererThais; + } + + @JsonGetter("s-ven") + public String getSorcererVenore() { + return sorcererVenore; + } + + @JsonGetter("s-yal") + public String getSorcererYalahar() { + return sorcererYalahar; + } @Override public List fieldOrder() { diff --git a/src/main/java/com/tibiawiki/domain/objects/Street.java b/src/main/java/com/tibiawiki/domain/objects/Street.java index 9703ea6..c2a3f8d 100644 --- a/src/main/java/com/tibiawiki/domain/objects/Street.java +++ b/src/main/java/com/tibiawiki/domain/objects/Street.java @@ -1,24 +1,37 @@ package com.tibiawiki.domain.objects; -import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.tibiawiki.domain.enums.City; +import lombok.Builder; import lombok.Getter; -import lombok.NoArgsConstructor; import org.springframework.stereotype.Component; import java.util.Arrays; import java.util.List; -@JsonIgnoreProperties({"templateType"}) @Getter -@NoArgsConstructor @Component public class Street extends WikiObject { - private City city; - private City city2; - private String map; - private String floor; + private final City city; + private final City city2; + private final String map; + private final String floor; + + private Street() { + this.city = null; + this.city2 = null; + this.map = null; + this.floor = null; + } + + @Builder + private Street(String name, String implemented, String notes, City city, City city2, String map, String floor) { + super(name, null, null, null, implemented, notes, null, null); + this.city = city; + this.city2 = city2; + this.map = map; + this.floor = floor; + } @Override public List fieldOrder() { diff --git a/src/main/java/com/tibiawiki/domain/objects/TibiaObject.java b/src/main/java/com/tibiawiki/domain/objects/TibiaObject.java index 56a2c72..2da9dc7 100644 --- a/src/main/java/com/tibiawiki/domain/objects/TibiaObject.java +++ b/src/main/java/com/tibiawiki/domain/objects/TibiaObject.java @@ -1,48 +1,115 @@ package com.tibiawiki.domain.objects; -import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.tibiawiki.domain.enums.Article; +import com.tibiawiki.domain.enums.Status; import com.tibiawiki.domain.enums.YesNo; +import lombok.Builder; import lombok.Getter; -import lombok.NoArgsConstructor; import org.springframework.stereotype.Component; -import java.util.Collections; +import java.util.Arrays; import java.util.List; -@JsonIgnoreProperties({"templateType"}) @Getter -@NoArgsConstructor @Component public class TibiaObject extends WikiObject { - private List itemid; - private String objectclass; - private String secondarytype; - private String tertiarytype; - private String flavortext; - private Integer lightradius; - private Integer lightcolor; - private Integer volume; - private YesNo destructable; - private YesNo immobile; - private String attrib; - private YesNo walkable; - private Integer walkingspeed; - private YesNo unshootable; - private YesNo blockspath; - private YesNo pickupable; - private YesNo holdsliquid; - private YesNo usable; - private YesNo writable; - private YesNo rewritable; - private Integer writechars; - private YesNo rotatable; - private Integer mapcolor; - private String location; - private String notes2; + private final List itemid; + private final String objectclass; + private final String secondarytype; + private final String tertiarytype; + private final String flavortext; + private final Integer lightradius; + private final Integer lightcolor; + private final Integer volume; + private final YesNo destructable; + private final YesNo immobile; + private final String attrib; + private final YesNo walkable; + private final Integer walkingspeed; + private final YesNo unshootable; + private final YesNo blockspath; + private final YesNo pickupable; + private final YesNo holdsliquid; + private final YesNo usable; + private final YesNo writable; + private final YesNo rewritable; + private final Integer writechars; + private final YesNo rotatable; + private final Integer mapcolor; + private final String location; + private final String notes2; + + private TibiaObject() { + this.itemid = null; + this.objectclass = null; + this.secondarytype = null; + this.tertiarytype = null; + this.flavortext = null; + this.lightradius = null; + this.lightcolor = null; + this.volume = null; + this.destructable = null; + this.immobile = null; + this.attrib = null; + this.walkable = null; + this.walkingspeed = null; + this.unshootable = null; + this.blockspath = null; + this.pickupable = null; + this.holdsliquid = null; + this.usable = null; + this.writable = null; + this.rewritable = null; + this.writechars = null; + this.rotatable = null; + this.mapcolor = null; + this.location = null; + this.notes2 = null; + } + + @Builder + private TibiaObject(String name, Article article, String actualname, String implemented, String notes, String history, + Status status, List itemid, String objectclass, String secondarytype, String tertiarytype, + String flavortext, Integer lightradius, Integer lightcolor, Integer volume, YesNo destructable, + YesNo immobile, String attrib, YesNo walkable, Integer walkingspeed, YesNo unshootable, + YesNo blockspath, YesNo pickupable, YesNo holdsliquid, YesNo usable, YesNo writable, + YesNo rewritable, Integer writechars, YesNo rotatable, Integer mapcolor, String location, + String notes2) { + super(name, article, actualname, null, implemented, notes, history, status); + this.itemid = itemid; + this.objectclass = objectclass; + this.secondarytype = secondarytype; + this.tertiarytype = tertiarytype; + this.flavortext = flavortext; + this.lightradius = lightradius; + this.lightcolor = lightcolor; + this.volume = volume; + this.destructable = destructable; + this.immobile = immobile; + this.attrib = attrib; + this.walkable = walkable; + this.walkingspeed = walkingspeed; + this.unshootable = unshootable; + this.blockspath = blockspath; + this.pickupable = pickupable; + this.holdsliquid = holdsliquid; + this.usable = usable; + this.writable = writable; + this.rewritable = rewritable; + this.writechars = writechars; + this.rotatable = rotatable; + this.mapcolor = mapcolor; + this.location = location; + this.notes2 = notes2; + } @Override public List fieldOrder() { - return Collections.emptyList(); + return Arrays.asList("name", "article", "actualname", "itemid", "objectclass", "secondarytype", "tertiarytype", + "flavortext", "implemented", "lightradius", "lightcolor", "volume", "destructable", "immobile", "attrib", + "walkable", "walkingspeed", "unshootable", "blockspath", "pickupable", "holdsliquid", "usable", + "writable", "rewritable", "writechars", "rotatable", "mapcolor", "location", "notes", "notes2", + "history", "status"); } } \ No newline at end of file From 93e2dce837a47983ccbabae3d22fa875f42fb051 Mon Sep 17 00:00:00 2001 From: Benjamin Komen Date: Sat, 24 Nov 2018 20:12:09 +0100 Subject: [PATCH 12/19] Working on unit tests for jsonfactory, small fixes in wikiobject classes. --- .../tibiawiki/domain/objects/Location.java | 4 +- .../com/tibiawiki/domain/objects/Spell.java | 2 + .../domain/factories/JsonFactoryTest.java | 579 ++++++++++++------ 3 files changed, 385 insertions(+), 200 deletions(-) diff --git a/src/main/java/com/tibiawiki/domain/objects/Location.java b/src/main/java/com/tibiawiki/domain/objects/Location.java index cb0babc..bd5a8b8 100644 --- a/src/main/java/com/tibiawiki/domain/objects/Location.java +++ b/src/main/java/com/tibiawiki/domain/objects/Location.java @@ -14,7 +14,7 @@ public class Location extends WikiObject { private final String ruler; - private final Integer population; + private final String population; private final String near; private final String organization; private final String map; @@ -40,7 +40,7 @@ private Location() { } @Builder - private Location(String name, String implemented, Status status, String ruler, Integer population, String near, + private Location(String name, String implemented, Status status, String ruler, String population, String near, String organization, String map, String map2, String map3, String map4, String map5, String map6, YesNo links) { super(name, null, null, null, implemented, null, null, status); diff --git a/src/main/java/com/tibiawiki/domain/objects/Spell.java b/src/main/java/com/tibiawiki/domain/objects/Spell.java index 3e8955e..3f616ed 100644 --- a/src/main/java/com/tibiawiki/domain/objects/Spell.java +++ b/src/main/java/com/tibiawiki/domain/objects/Spell.java @@ -5,6 +5,7 @@ import com.tibiawiki.domain.enums.SpellType; import com.tibiawiki.domain.enums.Status; import com.tibiawiki.domain.enums.YesNo; +import lombok.Builder; import lombok.Getter; import org.springframework.stereotype.Component; @@ -165,6 +166,7 @@ private Spell() { this.animation = null; } + @Builder private Spell(String name, String implemented, String notes, String history, Status status, SpellType type, SpellSubclass subclass, SpellSubclass runegroup, String damagetype, String words, Integer mana, Integer cooldown, Integer cooldowngroup, Integer cooldowngroup2, Integer levelrequired, YesNo premium, diff --git a/src/test/java/com/tibiawiki/domain/factories/JsonFactoryTest.java b/src/test/java/com/tibiawiki/domain/factories/JsonFactoryTest.java index 18eab31..c0671db 100644 --- a/src/test/java/com/tibiawiki/domain/factories/JsonFactoryTest.java +++ b/src/test/java/com/tibiawiki/domain/factories/JsonFactoryTest.java @@ -8,16 +8,33 @@ import com.tibiawiki.domain.enums.BookType; import com.tibiawiki.domain.enums.BuildingType; import com.tibiawiki.domain.enums.City; +import com.tibiawiki.domain.enums.Gender; import com.tibiawiki.domain.enums.Grade; +import com.tibiawiki.domain.enums.KeyType; import com.tibiawiki.domain.enums.Rarity; +import com.tibiawiki.domain.enums.SpellSubclass; +import com.tibiawiki.domain.enums.SpellType; import com.tibiawiki.domain.enums.YesNo; import com.tibiawiki.domain.objects.Achievement; import com.tibiawiki.domain.objects.Book; import com.tibiawiki.domain.objects.Building; import com.tibiawiki.domain.objects.Corpse; import com.tibiawiki.domain.objects.Creature; +import com.tibiawiki.domain.objects.Effect; +import com.tibiawiki.domain.objects.HuntingPlace; +import com.tibiawiki.domain.objects.Item; +import com.tibiawiki.domain.objects.Key; +import com.tibiawiki.domain.objects.Location; import com.tibiawiki.domain.objects.LootItem; +import com.tibiawiki.domain.objects.Missile; +import com.tibiawiki.domain.objects.Mount; +import com.tibiawiki.domain.objects.NPC; +import com.tibiawiki.domain.objects.Outfit; import com.tibiawiki.domain.objects.Percentage; +import com.tibiawiki.domain.objects.Quest; +import com.tibiawiki.domain.objects.Spell; +import com.tibiawiki.domain.objects.Street; +import com.tibiawiki.domain.objects.TibiaObject; import org.json.JSONArray; import org.json.JSONObject; import org.junit.jupiter.api.BeforeEach; @@ -239,8 +256,6 @@ void testConvertJsonToInfoboxPartOfArticle_Corpse() { assertThat(result, is(INFOBOX_CORPSE_TEXT)); } - // It almost works, not sure why not - @Disabled @Test void testConvertJsonToInfoboxPartOfArticle_Creature() { final Creature creature = makeCreature(); @@ -248,6 +263,108 @@ void testConvertJsonToInfoboxPartOfArticle_Creature() { assertThat(result, is(INFOBOX_CREATURE_TEXT)); } + @Test + void testConvertJsonToInfoboxPartOfArticle_Effect() { + final Effect effect = makeEffect(); + String result = target.convertJsonToInfoboxPartOfArticle(makeEffectJson(effect), effect.fieldOrder()); + assertThat(result, is(INFOBOX_EFFECT_TEXT)); + } + + @Disabled + @Test + void testConvertJsonToInfoboxPartOfArticle_HuntingPlace() { + final HuntingPlace huntingPlace = makeHuntingPlace(); + String result = target.convertJsonToInfoboxPartOfArticle(makeHuntingPlaceJson(huntingPlace), huntingPlace.fieldOrder()); + assertThat(result, is(INFOBOX_HUNT_TEXT)); + } + + @Disabled + @Test + void testConvertJsonToInfoboxPartOfArticle_Item() { + final Item item = makeItem(); + String result = target.convertJsonToInfoboxPartOfArticle(makeItemJson(item), item.fieldOrder()); + assertThat(result, is(INFOBOX_ITEM_TEXT)); + } + + @Disabled + @Test + void testConvertJsonToInfoboxPartOfArticle_Key() { + final Key key = makeKey(); + String result = target.convertJsonToInfoboxPartOfArticle(makeKeyJson(key), key.fieldOrder()); + assertThat(result, is(INFOBOX_KEY_TEXT)); + } + + @Disabled + @Test + void testConvertJsonToInfoboxPartOfArticle_Location() { + final Location location = makeLocation(); + String result = target.convertJsonToInfoboxPartOfArticle(makeLocationJson(location), location.fieldOrder()); + assertThat(result, is(INFOBOX_LOCATION_TEXT)); + } + + @Disabled + @Test + void testConvertJsonToInfoboxPartOfArticle_Missile() { + final Missile missile = makeMissile(); + String result = target.convertJsonToInfoboxPartOfArticle(makeMissileJson(missile), missile.fieldOrder()); + assertThat(result, is(INFOBOX_MISSILE_TEXT)); + } + + @Disabled + @Test + void testConvertJsonToInfoboxPartOfArticle_Mount() { + final Mount mount = makeMount(); + String result = target.convertJsonToInfoboxPartOfArticle(makeMountJson(mount), mount.fieldOrder()); + assertThat(result, is(INFOBOX_MOUNT_TEXT)); + } + + @Disabled + @Test + void testConvertJsonToInfoboxPartOfArticle_NPC() { + final NPC npc = makeNPC(); + String result = target.convertJsonToInfoboxPartOfArticle(makeNPCJson(npc), npc.fieldOrder()); + assertThat(result, is(INFOBOX_NPC_TEXT)); + } + + @Disabled + @Test + void testConvertJsonToInfoboxPartOfArticle_Object() { + final TibiaObject tibiaObject = makeTibiaObject(); + String result = target.convertJsonToInfoboxPartOfArticle(makeTibiaObjectJson(tibiaObject), tibiaObject.fieldOrder()); + assertThat(result, is(INFOBOX_OBJECT_TEXT)); + } + + @Disabled + @Test + void testConvertJsonToInfoboxPartOfArticle_Outfit() { + final Outfit outfit = makeOutfit(); + String result = target.convertJsonToInfoboxPartOfArticle(makeOutfitJson(outfit), outfit.fieldOrder()); + assertThat(result, is(INFOBOX_OUTFIT_TEXT)); + } + + @Disabled + @Test + void testConvertJsonToInfoboxPartOfArticle_Quest() { + final Quest quest = makeQuest(); + String result = target.convertJsonToInfoboxPartOfArticle(makeQuestJson(quest), quest.fieldOrder()); + assertThat(result, is(INFOBOX_QUEST_TEXT)); + } + + @Test + void testConvertJsonToInfoboxPartOfArticle_Spell() { + final Spell spell = makeSpell(); + String result = target.convertJsonToInfoboxPartOfArticle(makeSpellJson(spell), spell.fieldOrder()); + assertThat(result, is(INFOBOX_SPELL_TEXT)); + } + + @Disabled + @Test + void testConvertJsonToInfoboxPartOfArticle_Street() { + final Street street = makeStreet(); + String result = target.convertJsonToInfoboxPartOfArticle(makeStreetJson(street), street.fieldOrder()); + assertThat(result, is(INFOBOX_STREET_TEXT)); + } + private static final String INFOBOX_TEXT_SPACE = "{{Infobox Achievement|List={{{1|}}}|GetValue={{{GetValue|}}}\n" + "| name = Goo Goo Dancer\n" + "}}"; @@ -460,47 +577,14 @@ private JSONObject makeCorpseJson(Corpse corpse) { "| drownDmgMod = 100%?\n" + "| hpDrainDmgMod = 100%?\n" + "| bestiaryname = dragon\n" + - "| bestiarytext = Dragons were among the first creatures of Tibia and once ruled the whole continent." + - " Nowadays, there are only a few of them left which live deep in the dungeons. Nevertheless, they are very" + - " powerful monsters and will strive for killing every intruder. Besides their immense strength, they shoot" + - " fireballs at their victims and spit fire. Moreover, they can heal themselves.\n" + + "| bestiarytext = Dragons were\n" + "| sounds = {{Sound List|FCHHHHH|GROOAAARRR}}\n" + "| implemented = Pre-6.0\n" + - "| notes = Dragons are very slow-moving, but have a potent set of attacks. A [[mage]] or" + - " [[paladin]] can kill one without taking any damage once they master the art. These creatures can be" + - " skinned with an [[Obsidian Knife]]. See also: [[Green Dragon Leather/Skinning]].\n" + - "| behaviour = Dragons are known to [[Retargeting|retarget]]. This often causes shooters in a team" + - " hunt to be burned or killed.\n" + + "| notes = Dragons are\n" + + "| behaviour = Dragons are\n" + "| runsat = 300\n" + "| speed = 86\n" + - "| strategy = '''All''' [[player]]s should stand diagonal from the dragon, whenever possible, to" + - " avoid the [[Fire Wave]].\n" + - " \n" + - "'''[[Knight]]s''': Only one knight should be present in a team hunt, as they, the [[Blocking|blocker]]," + - " must be able to move freely around the dragon and to maintain their diagonal position as the dragon" + - " takes a step. It is quite easy for a knight of [[level]] 40 or higher to block a dragon without using" + - " any Health Potions at all. Around level 60 a knight with good skills (70/70) can hunt dragons with little" + - " waste and possibly profit. Remember to stand diagonal to it and always be prepared to use" + - " [[Health Potion|potions]]. A level 80+ knight can hunt dragons using only food and" + - " [[Pair of Soft Boots|Soft Boots]].
\n" + - "'''[[Mage]]s''' of level 28 or higher can kill dragons without help from other players, but you need to be" + - " very careful. They can [[Summon]] two [[Demon Skeleton]]s and drink a few extra [[Mana Potion]]s" + - " afterwards. They should try to keep enough [[mana]] to heal, if needed. They should enter, lure the" + - " dragon out, attack it with the demon skeletons, then move to a different floor so the dragon will target" + - " the demon skeletons. It is advisable to move to a space about 3 squares diagonal and use a strike spell" + - " ([[Ice Strike]] if possible) or [[Icicle Rune]]s to kill faster. Heal when your hit points drop below" + - " 250-280. Druids level 35 or higher, can use [[Mass Healing]] to prevent their summons from dying," + - " otherwise use [[Healing Runes]]. This is a reasonably cheap way to hunt dragons although the demon" + - " skeletons also gain a share of the experience.
\n" + - "'''[[Paladin]]s''' with a distance skill of 60+ and enough hit points to survive a fire attack are welcome" + - " additions to a team dragon hunt. Just be sure to have the [[Divine Healing]] spell ready to use, and " + - "stand where you can also escape if the dragon retargets. A paladin's ability to solo a dragon depends" + - " greatly on the terrain. A dragon's melee is weaker than their area attacks, so it would be advisable to" + - " stand diagonal the Dragon but only 1 sqm away, while shooting [[Royal Spear]]s or [[Enchanted Spear]]s." + - " A level 20 paladin with skills 65+ may attempt to solo a single dragon spawn but will have to bring some" + - " potions. Killing a dragon at this level will only prove your strength as a paladin will spend" + - " approximately 500 [[gp]]s per dragon and the chance of dying is very high if not careful. It is advisable" + - " to bring some [[Icicle Rune|Icicles]] or [[Avalanche Rune]]s if facing two or more of them.\n" + + "| strategy = '''All''' [[player]]s\n" + "| location = [[Thais]] [[Ancient Temple]], [[Darashia Dragon Lair]], [[Mount Sternum Dragon Cave]]," + " [[Mintwallin]], deep in [[Fibula Dungeon]], [[Kazordoon Dragon Lair]] (near [[Dwarf Bridge]]), [[Plains" + " of Havoc]], [[Elven Bane]] castle, [[Maze of Lost Souls]], southern cave and dragon tower in" + @@ -531,14 +615,7 @@ private JSONObject makeCorpseJson(Corpse corpse) { " |{{Loot Item|Life Crystal|very rare}}\n" + " |{{Loot Item|Dragonbone Staff|very rare}}\n" + "}}\n" + - "| history = Dragons are one of the oldest creatures in the game. In older times (prior to 2001" + - " at least) dragons were [[Summon Creature|summonable]], and during these times it was possible to summon" + - " up to 8 creatures at once (even through requiring very high [[mana]]) and only the highest leveled" + - " [[mage]]s could summon them (back then the highest [[level]]s were only around level 60 or 70). It was a" + - " somewhat common occurrence to see mages walking the streets of [[Thais]] with several dragons summoned" + - " at one time. It was also possible to set summons free by logging out of the game, turning the summons" + - " into wild creatures. Often mages would leave the game after summoning as many as 8 dragons in the middle" + - " of major [[Hometowns|cities]], causing chaos.\n" + + "| history = Dragons are\n" + "}}\n"; private Creature makeCreature() { @@ -579,16 +656,10 @@ private Creature makeCreature() { .drownDmgMod(Percentage.of("100%?")) .hpDrainDmgMod(Percentage.of("100%?")) .bestiaryname("dragon") - .bestiarytext("Dragons were among the first creatures of Tibia and once ruled the whole continent." + - " Nowadays, there are only a few of them left which live deep in the dungeons. Nevertheless, they are very" + - " powerful monsters and will strive for killing every intruder. Besides their immense strength, they shoot" + - " fireballs at their victims and spit fire. Moreover, they can heal themselves.") + .bestiarytext("Dragons were") .sounds(Arrays.asList("FCHHHHH", "GROOAAARRR")) - .notes("Dragons are very slow-moving, but have a potent set of attacks. A [[mage]] or" + - " [[paladin]] can kill one without taking any damage once they master the art. These creatures can be" + - " skinned with an [[Obsidian Knife]]. See also: [[Green Dragon Leather/Skinning]].") - .behaviour("Dragons are known to [[Retargeting|retarget]]. This often causes shooters in a team" + - " hunt to be burned or killed.") + .notes("Dragons are") + .behaviour("Dragons are") .runsat("300") .speed("86") .location("[[Thais]] [[Ancient Temple]], [[Darashia Dragon Lair]], [[Mount Sternum Dragon Cave]]," + @@ -598,34 +669,7 @@ private Creature makeCreature() { " room in [[Edron]], [[Hero Cave]], deep [[Cyclopolis]], [[Edron Dragon Lair]], [[Goroma]], [[Ankrahmun" + " Dragon Lair]]s, [[Draconia]], [[Dragonblaze Peaks]], some [[Ankrahmun Tombs]], underground of [[Fenrock]]" + " (on the way to [[Beregar]]), [[Krailos Steppe]] and [[Crystal Lakes]].") - .strategy("'''All''' [[player]]s should stand diagonal from the dragon, whenever possible, to" + - " avoid the [[Fire Wave]].\\n" + - " \\n" + - "'''[[Knight]]s''': Only one knight should be present in a team hunt, as they, the [[Blocking|blocker]]," + - " must be able to move freely around the dragon and to maintain their diagonal position as the dragon" + - " takes a step. It is quite easy for a knight of [[level]] 40 or higher to block a dragon without using" + - " any Health Potions at all. Around level 60 a knight with good skills (70/70) can hunt dragons with little" + - " waste and possibly profit. Remember to stand diagonal to it and always be prepared to use" + - " [[Health Potion|potions]]. A level 80+ knight can hunt dragons using only food and" + - " [[Pair of Soft Boots|Soft Boots]].
\\n" + - "'''[[Mage]]s''' of level 28 or higher can kill dragons without help from other players, but you need to be" + - " very careful. They can [[Summon]] two [[Demon Skeleton]]s and drink a few extra [[Mana Potion]]s" + - " afterwards. They should try to keep enough [[mana]] to heal, if needed. They should enter, lure the" + - " dragon out, attack it with the demon skeletons, then move to a different floor so the dragon will target" + - " the demon skeletons. It is advisable to move to a space about 3 squares diagonal and use a strike spell" + - " ([[Ice Strike]] if possible) or [[Icicle Rune]]s to kill faster. Heal when your hit points drop below" + - " 250-280. Druids level 35 or higher, can use [[Mass Healing]] to prevent their summons from dying," + - " otherwise use [[Healing Runes]]. This is a reasonably cheap way to hunt dragons although the demon" + - " skeletons also gain a share of the experience.
\\n" + - "'''[[Paladin]]s''' with a distance skill of 60+ and enough hit points to survive a fire attack are welcome" + - " additions to a team dragon hunt. Just be sure to have the [[Divine Healing]] spell ready to use, and" + - " stand where you can also escape if the dragon retargets. A paladin's ability to solo a dragon depends" + - " greatly on the terrain. A dragon's melee is weaker than their area attacks, so it would be advisable to" + - " stand diagonal the Dragon but only 1 sqm away, while shooting [[Royal Spear]]s or [[Enchanted Spear]]s." + - " A level 20 paladin with skills 65+ may attempt to solo a single dragon spawn but will have to bring some" + - " potions. Killing a dragon at this level will only prove your strength as a paladin will spend" + - " approximately 500 [[gp]]s per dragon and the chance of dying is very high if not careful. It is advisable" + - " to bring some [[Icicle Rune|Icicles]] or [[Avalanche Rune]]s if facing two or more of them.") + .strategy("'''All''' [[player]]s") .loot(Arrays.asList( LootItem.builder().amount("0-105").itemName("Gold Coin").build(), LootItem.builder().amount("0-3").itemName("Dragon Ham").build(), @@ -649,14 +693,7 @@ private Creature makeCreature() { LootItem.builder().itemName("Life Crystal").rarity(Rarity.VERY_RARE).build(), LootItem.builder().itemName("Dragonbone Staff").rarity(Rarity.VERY_RARE).build() )) - .history("Dragons are one of the oldest creatures in the game. In older times (prior to 2001" + - " at least) dragons were [[Summon Creature|summonable]], and during these times it was possible to summon" + - " up to 8 creatures at once (even through requiring very high [[mana]]) and only the highest leveled" + - " [[mage]]s could summon them (back then the highest [[level]]s were only around level 60 or 70). It was a" + - " somewhat common occurrence to see mages walking the streets of [[Thais]] with several dragons summoned" + - " at one time. It was also possible to set summons free by logging out of the game, turning the summons" + - " into wild creatures. Often mages would leave the game after summoning as many as 8 dragons in the middle" + - " of major [[Hometowns|cities]], causing chaos.") + .history("Dragons are") .build(); } @@ -665,22 +702,32 @@ private JSONObject makeCreatureJson(Creature creature) { } private static final String INFOBOX_EFFECT_TEXT = "{{Infobox Effect|List={{{1|}}}|GetValue={{{GetValue|}}}\n" + - "| name = Fireball Effect\n" + - "| implemented =\n" + - "| effectid = 7\n" + - "| primarytype = Attack\n" + - "| secondarytype = \n" + - "| lightcolor = 208\n" + - "| lightradius = 6\n" + - "| causes = \n" + - "*[[Fireball]] and [[Great Fireball]];\n" + - "*Certain [[Creature Spells]];\n" + - "*Making a [[Stuffed Dragon]] sneeze;\n" + - "*Using a [[Demon Infant]] on [[Lava]] if tasked to.\n" + - "| effect = [[Fire Damage]] on target or nothing.\n" + - "| notes =\n" + + "| name = Fireball Effect\n" + + "| effectid = 7\n" + + "| primarytype = Attack\n" + + "| lightradius = 6\n" + + "| lightcolor = 208\n" + + "| causes = *[[Fireball]] and [[Great Fireball]];\n" + + "| effect = [[Fire Damage]] on target or nothing.\n" + "}}\n"; + + private Effect makeEffect() { + return Effect.builder() + .name("Fireball Effect") + .effectid(7) + .primarytype("Attack") + .lightcolor(208) + .lightradius(6) + .causes("*[[Fireball]] and [[Great Fireball]];") + .effect("[[Fire Damage]] on target or nothing.") + .build(); + } + + private JSONObject makeEffectJson(Effect effect) { + return new JSONObject(objectMapper.convertValue(effect, Map.class)).put("templateType", "Effect"); + } + private static final String INFOBOX_HUNT_TEXT = "{{Infobox Hunt|List={{{1|}}}|GetValue={{{GetValue|}}}\n" + "| name = Hero Cave\n" + "| image = Hero\n" + @@ -721,6 +768,15 @@ private JSONObject makeCreatureJson(Creature creature) { "| map2 = Hero Cave 6.png\n" + "}}"; + private HuntingPlace makeHuntingPlace() { + return HuntingPlace.builder() + .build(); + } + + private JSONObject makeHuntingPlaceJson(HuntingPlace huntingPlace) { + return new JSONObject(objectMapper.convertValue(huntingPlace, Map.class)).put("templateType", "Hunt"); + } + private static final String INFOBOX_ITEM_TEXT = "{{Infobox Item|List={{{1|}}}|GetValue={{{GetValue|}}}\n" + "| name = Carlin Sword\n" + "| marketable = yes\n" + @@ -759,6 +815,15 @@ private JSONObject makeCreatureJson(Creature creature) { "{{JSpoiler|Obtainable in [[Rookgaard]] through the [[Minotaur Hell Quest]].}}\n" + "}}\n"; + private Item makeItem() { + return Item.builder() + .build(); + } + + private JSONObject makeItemJson(Item item) { + return new JSONObject(objectMapper.convertValue(item, Map.class)).put("templateType", "Item"); + } + private static final String INFOBOX_KEY_TEXT = "{{Infobox Key|List={{{1|}}}|GetValue={{{GetValue|}}}\n" + "| number = 4055\n" + "| aka = Panpipe Quest Key\n" + @@ -774,37 +839,99 @@ private JSONObject makeCreatureJson(Creature creature) { "| longnotes = Allows you to open the door ([http://tibia.wikia.com/wiki/Mapper?coords=127.131,125.129,8,3,1,1 here]) to the [[Panpipe Quest]].\n" + "}}\n"; + private Key makeKey() { + return Key.builder() + .number("4055") + .aka("Panpipe Quest Key") + .primarytype(KeyType.SILVER) + .location("[[Jakundaf Desert]]") + .value("Negotiable") + .npcvalue(0) + .npcprice(0) + .buyfrom("--") + .sellto("--") + .origin("Hidden in a rock south of the Desert Dungeon entrance.") + .shortnotes("Access to the [[Panpipe Quest]].") + .longnotes("Allows you to open the door ([http://tibia.wikia.com/wiki/Mapper?coords=127.131,125.129,8,3,1,1 here]) to the [[Panpipe Quest]].") + .build(); + } + + private JSONObject makeKeyJson(Key key) { + return new JSONObject(objectMapper.convertValue(key, Map.class)).put("templateType", "Key"); + } + + private static final String INFOBOX_LOCATION_TEXT = "{{Infobox Geography\n" + + "| ruler = [[King Tibianus]]\n" + + "| implemented = Pre-6.0\n" + + "| population = {{PAGESINCATEGORY:Thais NPCs|pages}}\n" + + "| organization = [[Thieves Guild]], [[Tibian Bureau of Investigation]], [[Inquisition]]\n" + + "| near = [[Fibula]], [[Mintwallin]], [[Greenshore]], [[Mount Sternum]]\n" + + "| map = [[File:Map_thais.jpg]]\n" + + "| map2 = [[File:Thais.PNG]]\n" + + "}}"; + + private Location makeLocation() { + return Location.builder() + .ruler("[[King Tibianus]]") + .implemented("Pre-6.0") + .population("{{PAGESINCATEGORY:Thais NPCs|pages}}") + .organization("[[Thieves Guild]], [[Tibian Bureau of Investigation]], [[Inquisition]]") + .near("[[Fibula]], [[Mintwallin]], [[Greenshore]], [[Mount Sternum]]") + .map("[[File:Map_thais.jpg]]") + .map2("[[File:Thais.PNG]]") + .build(); + } + + private JSONObject makeLocationJson(Location location) { + return new JSONObject(objectMapper.convertValue(location, Map.class)).put("templateType", "Geography"); + } + private static final String INFOBOX_MISSILE_TEXT = "{{Infobox Missile|List={{{1|}}}|GetValue={{{GetValue|}}}\n" + "| name = Throwing Cake Missile\n" + "| implemented = 7.9\n" + "| missileid = 42\n" + "| primarytype = Throwing Weapon\n" + - "| secondarytype = \n" + - "| lightcolor = \n" + - "| lightradius = \n" + "| shotby = [[Undead Jester]]'s attack and probably by throwing a [[Throwing Cake]].\n" + "| notes = This missile is followed by the [[Cream Cake Effect]]: [[File:Cream Cake Effect.gif]]\n" + "}}\n"; + private Missile makeMissile() { + return Missile.builder() + .name("Throwing Cake Missile") + .implemented("7.9") + .missileid(42) + .primarytype("Throwing Weapon") + .shotby("[[Undead Jester]]'s attack and probably by throwing a [[Throwing Cake]].") + .notes("This missile is followed by the [[Cream Cake Effect]]: [[File:Cream Cake Effect.gif]]") + .build(); + } + + private JSONObject makeMissileJson(Missile missile) { + return new JSONObject(objectMapper.convertValue(missile, Map.class)).put("templateType", "Missile"); + } + private static final String INFOBOX_MOUNT_TEXT = "{{Infobox_Mount|List={{{1|}}}|GetValue={{{GetValue|}}}\n" + "| name = Donkey\n" + "| speed = 10\n" + "| taming_method = Use a [[Bag of Apple Slices]] on a creature transformed into Donkey.\n" + "| implemented = 9.1\n" + "| achievement = Loyal Lad\n" + - "| notes = Go to [[Incredibly Old Witch]]'s house, [http://tibia.wikia.com/wiki/Mapper?coords=" + - "125.250,126.95,7,2,1,1 here], then lure any wild creature and wait until the witch turns it into a Donkey." + - " Use a [[Bag of Apple Slices]] on the changed creature before it's changed again. You can also trap the" + - " Incredibly Old Witch and use the Bag when she transforms herself. It's recommended to put the Bag of" + - " Apple Slices on a hotkey so when a creature is changed to Donkey you just need to press it instead of" + - " clicking the item and then the Donkey.
\n" + - "If you tame the donkey by using the item on the witch herself (while she is transformed into Donkey), she" + - " will temporarily vanish, and respawns about 10 minutes later.
\n" + - "On most game worlds it's the cheapest mount to obtain, what makes it popular among low or mid levels who" + - " want to gain additional 10 points of speed.\n" + - "\n" + - "Donkey (Transformation).gif|Donkey (transformed creature)\n" + - "}}\n"; + "| notes = Go to [[Incredibly Old Witch]]'s house,\n"; + + private Mount makeMount() { + return Mount.builder() + .name("Donkey") + .speed(10) + .tamingMethod("Use a [[Bag of Apple Slices]] on a creature transformed into Donkey.") + .implemented("9.1") + .achievement("Loyal Lad") + .notes("Go to [[Incredibly Old Witch]]'s house,") + .build(); + } + + private JSONObject makeMountJson(Mount mount) { + return new JSONObject(objectMapper.convertValue(mount, Map.class)).put("templateType", "Mount"); + } private static final String INFOBOX_NPC_TEXT = "{{Infobox NPC|List={{{1|}}}|GetValue={{{GetValue|}}}\n" + "| name = Sam\n" + @@ -820,50 +947,66 @@ private JSONObject makeCreatureJson(Creature creature) { "| race = Human\n" + "| city = Thais\n" + "| buysell = yes\n" + - "| sells = {{Price to Buy |Axe |Battle Axe |Battle Hammer |Bone Sword |Brass Armor |Brass Helmet" + - " |Brass Legs |Brass Shield |Carlin Sword |Chain Armor |Chain Helmet |Chain Legs |Club |Coat |Crowbar " + - "|Dagger |Doublet |Dwarven Shield |Hand Axe |Iron Helmet |Jacket |Leather Armor |Leather Boots: 10 |Leather" + - " Helmet |Leather Legs |Longsword |Mace |Morning Star |Plate Armor |Plate Shield |Rapier |Sabre |Scale Armor" + - " |Short Sword |Sickle |Soldier Helmet |Spike Sword |Steel Helmet |Steel Shield |Studded Armor |Studded" + - " Helmet |Studded Legs |Studded Shield |Sword |Throwing Knife |Two Handed Sword |Viking Helmet |Viking " + - "Shield |War Hammer |Wooden Shield}}\n" + - "| buys = {{Price to Sell |Axe |Battle Axe |Battle Hammer |Battle Shield |Bone Club |Bone Sword" + - " |Brass Armor |Brass Helmet |Brass Legs |Brass Shield |Carlin Sword |Chain Armor |Chain Helmet |Chain Legs" + - " |Club |Coat |Copper Shield |Crowbar |Dagger |Double Axe |Doublet |Dwarven Shield |Fire Sword: 1000" + - " |Halberd |Hand Axe: 4 |Hatchet |Iron Helmet |Jacket |Katana |Leather Armor |Leather Boots |Leather Helmet" + - " |Leather Legs |Legion Helmet |Longsword |Mace |Magic Plate Armor: 6400;sayname |Morning Star |Orcish Axe" + - " |Plate Armor |Plate Legs |Plate Shield |Rapier |Sabre |Scale Armor |Short Sword |Sickle |Small Axe " + - "|Soldier Helmet |Spike Sword: 240 |Steel Helmet |Steel Shield |Studded Armor |Studded Club |Studded Helmet" + - " |Studded Legs |Studded Shield |Swampling Club |Sword |Throwing Knife |Two Handed Sword |Viking Helmet " + - "|Viking Shield |War Hammer: 470 |Wooden Shield}}\n" + + "| sells = {{Price to Buy |Axe\n" + + "| buys = {{Price to Sell |Axe\n" + "| sounds = {{Sound List|Hello there, adventurer! Need a deal in weapons or armor? I'm your man!}}\n" + - "| notes = Sam is the Blacksmith of [[Thais]]. His real name is Samuel, but he prefers to be called " + - "Sam. He was named after his grandfather.\n" + - "He sells and buys many weapons and armors. Sam is one of the few [[NPC]]s that buys magic plate armors. " + - "The only way to sell it to him is by typing \"Sell magic plate armor\".\n" + - "His neighbor in Thais is [[Frodo]], innkeeper of the Frodo's Hut, which is clearly an [[Allusions#Samwise" + - " Gamgee|allusion]] to the J.R.R. Tolkien's novel [[wikipedia:The Lord of the Rings|The Lord of The Rings]]" + - " where [[Frodo]] and Sam are the main plot characters. He was the first NPC to see the Tibian light of day.\n" + - "{{JSpoiler|Part of the [[Sam's Old Backpack Quest]], the [[Knight Outfits Quest]], and mission 9 of" + - " [[What a Foolish Quest]].}}\n" + + "| notes = Sam is the Blacksmith of [[Thais]].\n" + "}}\n"; + private NPC makeNPC() { + return NPC.builder() + .name("Sam") + .implemented("Pre-6.0") + .job("Artisan") + .job2("Weapon Shopkeeper") + .job3("Armor Shopkeeper") + .location("[[Temple Street]] in [[Thais]].") + .posx(126.104) + .posy(125.200) + .posz(7) + .gender(Gender.MALE) + .race("Human") + .city(City.THAIS) + .buysell(YesNo.YES_LOWERCASE) + .sells("{{Price to Buy |Axe") + .buys("{{Price to Sell |Axe") + .sounds(Collections.singletonList("Hello there, adventurer! Need a deal in weapons or armor? I'm your man!")) + .notes("Sam is the Blacksmith of [[Thais]].") + .build(); + } + + private JSONObject makeNPCJson(NPC npc) { + return new JSONObject(objectMapper.convertValue(npc, Map.class)).put("templateType", "NPC"); + } + private static final String INFOBOX_OBJECT_TEXT = "{{Infobox Object|List={{{1|}}}|GetValue={{{GetValue|}}}\n" + "| name = Blueberry Bush\n" + "| article = a\n" + "| objectclass = Bushes\n" + "| walkable = no\n" + - "| location = Can be found all around [[Tibia]]. There are many Blueberry bushes in [[Greenshore]]," + - " east from the wheat field. The [[Dryad Gardens]] also contain a lot of bushes.\n" + - "| notes = They are the source of the [[blueberry|blueberries]]. 'Use' the [[bush]] first, then " + - "take the three remaining blueberries, however sometimes other players \"use\" the Blueberry Bush and don't" + - " take them with themselves. Thus, there can be up to six blueberries in a bush. It takes one hour for the" + - " blueberry bush to regenerate.\n" + - "| notes2 =
{{JSpoiler|After using [[Blueberry]] Bushes 500 times, you will earn the" + - " achievement [[Bluebarian]].}}\n" + + "| location = Can be found all around [[Tibia]].\n" + + "| notes = They are the source of the [[blueberry|blueberries]].\n" + + "| notes2 =
{{JSpoiler|After using [[Blueberry]] Bushes 500 times,\n" + "| implemented = 7.1\n" + "}}\n"; + private TibiaObject makeTibiaObject() { + return TibiaObject.builder() + .name("Blueberry Bush") + .article(Article.A) + .objectclass("Bushes") + .walkable(YesNo.NO_LOWERCASE) + .location("Can be found all around [[Tibia]].") + .notes("They are the source of the [[blueberry|blueberries]].") + .notes2("
{{JSpoiler|After using [[Blueberry]] Bushes 500 times,") + .implemented("7.1") + .build(); + } + + private JSONObject makeTibiaObjectJson(TibiaObject tibiaObject) { + return new JSONObject(objectMapper.convertValue(tibiaObject, Map.class)).put("templateType", "Object"); + } + private static final String INFOBOX_OUTFIT_TEXT = "{{Infobox_Outfit|List={{{1|}}}|GetValue={{{GetValue|}}}\n" + "| name = Pirate\n" + "| primarytype = Quest\n" + @@ -876,79 +1019,119 @@ private JSONObject makeCreatureJson(Creature creature) { "| notes = Pirate outfits are perfect for swabbing the deck or walking the plank. Quite dashing and great for sailing.\n" + "}}\n"; + private Outfit makeOutfit() { + return Outfit.builder() + .name("Pirate") + .primarytype("Quest") + .premium(YesNo.YES_LOWERCASE) + .outfit("premium, see [[Pirate Outfits Quest]].") + .addons("premium, see [[Pirate Outfits Quest]].") + .achievement("Swashbuckler") + .implemented("7.8") + .artwork("Pirate Outfits Artwork.jpg") + .notes("Pirate outfits are perfect for swabbing the deck or walking the plank. Quite dashing and great for sailing.") + .build(); + } + + private JSONObject makeOutfitJson(Outfit outfit) { + return new JSONObject(objectMapper.convertValue(outfit, Map.class)).put("templateType", "Outfit"); + } + private static final String INFOBOX_QUEST_TEXT = "{{Infobox Quest|List={{{1|}}}|GetValue={{{GetValue|}}}\n" + "| implemented = 6.61-6.97\n" + "| premium = yes\n" + "| name = The Paradox Tower Quest\n" + "| aka = Riddler Quest, Mathemagics Quest\n" + - "| reward = Up to two of the following: 10k [[gp]], [[Wand of Cosmic Energy]], 32 [[Talon]]s," + - " [[Phoenix Egg]] and the [[achievement]] [[Mathemagician]]\n" + + "| reward = Up to two of the following:\n" + "| location = [[Paradox Tower]] near [[Kazordoon]]\n" + "| lvl = 30\n" + "| lvlrec = 50+\n" + "| log = yes\n" + "| transcripts = yes\n" + - "| dangers = [[Wyvern]]s
([[Mintwallin]]): [[Minotaur]]s, [[Minotaur Archer]]s, [[Minotaur" + - " Guard]]s, [[Minotaur Mage]]s
([[Hellgate]]): [[Skeleton]]s, [[Ghoul]]s, [[Bonelord]]s, maybe [[Elder" + - " Bonelord]]
\n" + - "([[Plains of Havoc]]): [[Skeleton]]s, [[Ghoul]]s, [[Demon Skeleton]]s, [[Orc Berserker]], [[Orc" + - " Spearman]], maybe [[Cyclops]] and [[Giant Spider]]\n" + + "| dangers = [[Wyvern]]s
([[Mintwallin]]): [[Minotaur]]s,\n" + "| legend = Surpass the wrath of a madman and subject yourself to his twisted taunting.\n" + "}}\n"; + private Quest makeQuest() { + return Quest.builder() + .implemented("6.61-6.97") + .premium(YesNo.YES_LOWERCASE) + .name("The Paradox Tower Quest") + .aka("Riddler Quest, Mathemagics Quest") + .reward("Up to two of the following:") + .location("[[Paradox Tower]] near [[Kazordoon]]") + .lvl(30) + .lvlrec(50) + .log(YesNo.YES_LOWERCASE) + .transcripts(YesNo.YES_LOWERCASE) + .dangers("[[Wyvern]]s
([[Mintwallin]]): [[Minotaur]]s,") + .legend("Surpass the wrath of a madman and subject yourself to his twisted taunting.") + .build(); + } + + private JSONObject makeQuestJson(Quest quest) { + return new JSONObject(objectMapper.convertValue(quest, Map.class)).put("templateType", "Quest"); + } + private static final String INFOBOX_SPELL_TEXT = "{{Infobox Spell|List={{{1|}}}|GetValue={{{GetValue|}}}\n" + "| name = Light Healing\n" + "| type = Instant\n" + "| subclass = Healing\n" + "| words = exura\n" + - "| premium = no\n" + "| mana = 20\n" + - "| levelrequired = 8\n" + "| cooldown = 1\n" + "| cooldowngroup = 1\n" + + "| levelrequired = 8\n" + + "| premium = no\n" + "| voc = [[Paladin]]s, [[Druid]]s and [[Sorcerer]]s\n" + "| d-abd = [[Maealil]]\n" + "| p-abd = [[Maealil]]\n" + "| spellcost = 0\n" + "| effect = Restores a small amount of [[HP|health]]. (Cures [[paralysis]].)\n" + - "| notes = A weak, but popular healing spell. It was the only healing spell for knights for many" + - " years until [[Wound Cleansing]] was introduced in late 2007. The number of [[hp]] it can heal depends " + - "upon your level and magic level (and is around 1/10th of your UH power). It is useful if you are trying" + - " to raise your [[Magic level]] or to get rid of [[Paralysis]]. [[Knight]]s can't use it since " + - "[[Updates/8.7|Winter Update 2010]]. Since [[Updates/9.8|Winter Update 2012]] this spell is free. It used " + - "to cost 170 [[gp]].\n" + - "[[File:Exura in low hp.png|thumb|left|168px|A player performing the Light Healing spell]]\n" + + "| notes = A weak, but popular healing spell.\n" + "}}\n"; + private Spell makeSpell() { + return Spell.builder() + .name("Light Healing") + .type(SpellType.Instant) + .subclass(SpellSubclass.Healing) + .words("exura") + .premium(YesNo.NO_LOWERCASE) + .mana(20) + .levelrequired(8) + .cooldown(1) + .cooldowngroup(1) + .voc("[[Paladin]]s, [[Druid]]s and [[Sorcerer]]s") + .druidAbDendriel("[[Maealil]]") + .paladinAbDendriel("[[Maealil]]") + .spellcost(0) + .effect("Restores a small amount of [[HP|health]]. (Cures [[paralysis]].)") + .notes("A weak, but popular healing spell.") + .build(); + } + + private JSONObject makeSpellJson(Spell spell) { + return new JSONObject(objectMapper.convertValue(spell, Map.class)).put("templateType", "Spell"); + } + private static final String INFOBOX_STREET_TEXT = "{{Infobox Street\n" + "| name = Sugar Street\n" + "| implemented = 7.8\n" + "| city = Liberty Bay\n" + - "| floor = \n" + - "| notes = {{StreetStyles|Sugar Street}} is in west and central [[Liberty Bay]]. It touches " + - "{{StreetStyles|Harvester's Haven}} to the north, '''Smuggler Backyard''' and {{StreetStyles|Shady Trail}}" + - " to the south, and {{StreetStyles|Marble Lane}} and {{StreetStyles|Admiral's Avenue}} to the east.\n" + - "\n" + - "Buildings and NPCs from south to north and west to east:
\n" + - "'''South-West:'''\n" + - "* [[Sugar Street 1]]\n" + - "* [[Sugar Street 2]]\n" + - "* [[Sugar Street 3a]]\n" + - "* [[Sugar Street 4a]]\n" + - "\n" + - "'''North-West:'''\n" + - "* [[Sugar Street 3b]]\n" + - "\n" + - "'''North:'''\n" + - "* [[Ivy Cottage]]\n" + - "\n" + - "'''Central:'''\n" + - "* [[Sugar Street 4b]]\n" + - "* [[Sugar Street 4c]]\n" + - "* [[Sugar Street 4d]]\n" + - "\n" + - "'''East:'''\n" + - "* [[Peggy]], [[Furniture|Furniture Store]]\n" + - "* [[Sugar Street 5]]\n" + + "| notes = {{StreetStyles|Sugar Street}} is in west\n" + "}}\n"; -} \ No newline at end of file + + private Street makeStreet() { + return Street.builder() + .name("Sugar Street") + .implemented("7.8") + .city(City.LIBERTY_BAY) + .notes("{{StreetStyles|Sugar Street}} is in west") + .build(); + } + + private JSONObject makeStreetJson(Street street) { + return new JSONObject(objectMapper.convertValue(street, Map.class)).put("templateType", "Street"); + } +} From 670612c6dad94ec938d7f1a1d597b3e91f8c8bbd Mon Sep 17 00:00:00 2001 From: Benjamin Komen Date: Sun, 25 Nov 2018 15:18:52 +0100 Subject: [PATCH 13/19] Working further on unit tests for jsonfactory, with small fixes in other classes. --- .../domain/factories/JsonFactory.java | 39 +- .../com/tibiawiki/domain/objects/Item.java | 27 +- .../com/tibiawiki/domain/objects/NPC.java | 6 +- .../com/tibiawiki/domain/objects/Quest.java | 3 +- .../domain/factories/JsonFactoryTest.java | 837 ++++++++++-------- 5 files changed, 503 insertions(+), 409 deletions(-) diff --git a/src/main/java/com/tibiawiki/domain/factories/JsonFactory.java b/src/main/java/com/tibiawiki/domain/factories/JsonFactory.java index ca049a7..c1901b2 100644 --- a/src/main/java/com/tibiawiki/domain/factories/JsonFactory.java +++ b/src/main/java/com/tibiawiki/domain/factories/JsonFactory.java @@ -114,19 +114,19 @@ private void constructKeyValuePairs(@NotNull JSONObject jsonObject, List if (value instanceof JSONArray) { if (SOUNDS.equals(key)) { - sb.append(makeSoundList(jsonObject, key, (JSONArray) value)); + sb.append(makeTemplateList(jsonObject, key, (JSONArray) value, "Sound List")); } else if (SPAWN_TYPE.equals(key)) { - + sb.append(makeCommaSeparatedStringList(jsonObject, key, (JSONArray) value)); } else if (LOOT.equals(key)) { sb.append(makeLootTable(jsonObject, key, (JSONArray) value)); } else if (DROPPED_BY.equals(key)) { - + sb.append(makeTemplateList(jsonObject, key, (JSONArray) value, "Dropped By")); } else if (ITEM_ID.equals(key)) { - + sb.append(makeCommaSeparatedStringList(jsonObject, key, (JSONArray) value)); } else if (LOWER_LEVELS.equals(key)) { - + sb.append(makeSkillsTable(jsonObject, key, (JSONArray) value)); } else { - // just convert to a comma-separated list of array values + sb.append(makeCommaSeparatedStringList(jsonObject, key, (JSONArray) value)); } } else if (value instanceof JSONObject) { @@ -340,13 +340,24 @@ private int getMaxFieldLength(@NotNull JSONObject jsonObject) { .orElse(0); } - private String makeSoundList(@NotNull JSONObject jsonObject, String key, JSONArray jsonArray) { + + @NotNull + private String makeTemplateList(JSONObject jsonObject, String key, JSONArray jsonArray, String templateName) { final String paddedKey = Strings.padEnd(key, getMaxFieldLength(jsonObject), ' '); final String value = jsonArray.toList().stream() .map(String::valueOf) .collect(Collectors.joining("|")); - return "| " + paddedKey + " = {{Sound List|" + value + "}}\n"; + return "| " + paddedKey + " = {{" + templateName + "|" + value + "}}\n"; + } + + private String makeCommaSeparatedStringList(JSONObject jsonObject, String key, JSONArray jsonArray) { + final String paddedKey = Strings.padEnd(key, getMaxFieldLength(jsonObject), ' '); + final String value = jsonArray.toList().stream() + .map(String::valueOf) + .collect(Collectors.joining(", ")); + + return "| " + paddedKey + " = " + value + "\n"; } private String makeLootTable(JSONObject jsonObject, String key, JSONArray jsonArray) { @@ -358,6 +369,18 @@ private String makeLootTable(JSONObject jsonObject, String key, JSONArray jsonAr return "| " + paddedKey + " = {{Loot Table\n |" + value + "\n}}\n"; } + /** + * TODO implement this method correctly + */ + private String makeSkillsTable(JSONObject jsonObject, String key, JSONArray jsonArray) { + final String paddedKey = Strings.padEnd(key, getMaxFieldLength(jsonObject), ' '); + final String value = jsonArray.toList().stream() + .map(o -> ((Map) o).get("").toString()) + .collect(Collectors.joining("\n |")); + + return "| " + paddedKey + " = \n {{Infobox Hunt Skills\n |" + value + "\n}}\n"; + } + private String makeLootItem(Object obj) { Map map = (Map) obj; StringBuilder result = new StringBuilder("{{Loot Item"); diff --git a/src/main/java/com/tibiawiki/domain/objects/Item.java b/src/main/java/com/tibiawiki/domain/objects/Item.java index f74b365..20fd993 100644 --- a/src/main/java/com/tibiawiki/domain/objects/Item.java +++ b/src/main/java/com/tibiawiki/domain/objects/Item.java @@ -12,6 +12,7 @@ import lombok.Getter; import org.springframework.stereotype.Component; +import java.math.BigDecimal; import java.util.Arrays; import java.util.List; @@ -57,7 +58,7 @@ public class Item extends WikiObject { private final Percentage hitpointLeechChance; private final Percentage hitpointLeechAmount; private final String attrib; - private final Double weight; + private final BigDecimal weight; private final YesNo stackable; private final YesNo pickupable; private final YesNo immobile; @@ -84,8 +85,8 @@ public class Item extends WikiObject { private final String value; private final String npcvalue; private final String npcprice; - private final Double npcvaluerook; - private final Double npcpricerook; + private final String npcvaluerook; + private final String npcpricerook; private final String buyfrom; private final String sellto; @@ -171,13 +172,13 @@ private Item(String name, Article article, String actualname, String plural, Str YesNo enchantable, YesNo enchanted, String range, String attackModification, String hitpointModification, Integer armor, String resist, Integer charges, Percentage criticalHitChance, Percentage criticalHitExtraDamage, Percentage manaleechChance, Percentage manaleechAmount, - Percentage hitpointLeechChance, Percentage hitpointLeechAmount, String attrib, Double weight, + Percentage hitpointLeechChance, Percentage hitpointLeechAmount, String attrib, BigDecimal weight, YesNo stackable, YesNo pickupable, YesNo immobile, YesNo walkable, YesNo unshootable, YesNo blockspath, YesNo rotatable, Integer mapcolor, YesNo consumable, Integer regenseconds, List sounds, YesNo writable, YesNo rewritable, Integer writechars, YesNo hangable, YesNo holdsliquid, Integer mana, DamageElement damagetype, String damage, Integer volume, String duration, YesNo destructible, - List droppedby, String value, String npcvalue, String npcprice, Double npcvaluerook, - Double npcpricerook, String buyfrom, String sellto) { + List droppedby, String value, String npcvalue, String npcprice, String npcvaluerook, + String npcpricerook, String buyfrom, String sellto) { super(name, article, actualname, plural, implemented, notes, history, status); this.itemid = itemid; this.marketable = marketable; @@ -295,12 +296,12 @@ public List fieldOrder() { return Arrays.asList("name", "article", "actualname", "plural", "itemid", "marketable", "usable", "sprites", "flavortext", "implemented", "words", "itemclass", "primarytype", "secondarytype", "lightcolor", "lightradius", "levelrequired", "vocrequired", "mlrequired", "hands", "type", "attack", "elementattack", - "defense", "defensemod", "imbueslots", "imbuements", "range", "atk_mod", "hit_mod", "armor", "resist", - "charges", "crithit_ch", "critextra_dmg", "manaleech_ch", "manaleech_am", "hpleech_ch", "hpleech_am", - "attrib", "weight", "stackable", "pickupable", "immobile", "walkable", "unshootable", "blockspath", - "rotatable", "mapcolor", "consumable", "regenseconds", "sounds", "writable", "rewritable", "writechars", - "hangable", "holdsliquid", "mana", "damagetype", "damage", "volume", "duration", "destructible", - "droppedby", "value", "npcvalue", "npcprice", "npcvaluerook", "npcpricerook", "buyfrom", "sellto", - "notes", "history", "status"); + "defense", "defensemod", "imbueslots", "imbuements", "enchantable", "enchanted", "range", "atk_mod", + "hit_mod", "armor", "resist", "charges", "crithit_ch", "critextra_dmg", "manaleech_ch", "manaleech_am", + "hpleech_ch", "hpleech_am", "attrib", "weight", "stackable", "pickupable", "immobile", "walkable", + "unshootable", "blockspath", "rotatable", "mapcolor", "consumable", "regenseconds", "sounds", "writable", + "rewritable", "writechars", "hangable", "holdsliquid", "mana", "damagetype", "damage", "volume", + "duration", "destructible", "droppedby", "value", "npcvalue", "npcprice", "npcvaluerook", "npcpricerook", + "buyfrom", "sellto", "notes", "history", "status"); } } \ No newline at end of file diff --git a/src/main/java/com/tibiawiki/domain/objects/NPC.java b/src/main/java/com/tibiawiki/domain/objects/NPC.java index 44fb36a..ebde6ee 100644 --- a/src/main/java/com/tibiawiki/domain/objects/NPC.java +++ b/src/main/java/com/tibiawiki/domain/objects/NPC.java @@ -124,7 +124,9 @@ private NPC(String name, String actualname, String implemented, String notes, St @Override public List fieldOrder() { - return Arrays.asList("name", "actualname", "job", "location", "city", "street", "posx", "posy", "posz", "gender", - "race", "buysell", "buys", "sells", "sounds", "implemented", "notes", "history", "status"); + return Arrays.asList("name", "actualname", "job", "job2", "job3", "job4", "job5", "job6", "location", "city", + "city2", "street", "posx", "posy", "posz", "posx2", "posy2", "posz2", "posx3", "posy3", "posz3", "posx4", + "posy4", "posz4", "posx5", "posy5", "posz5", "gender", "race", "buysell", "buys", "sells", "sounds", + "implemented", "notes", "history", "status"); } } \ No newline at end of file diff --git a/src/main/java/com/tibiawiki/domain/objects/Quest.java b/src/main/java/com/tibiawiki/domain/objects/Quest.java index ad85646..bf665b8 100644 --- a/src/main/java/com/tibiawiki/domain/objects/Quest.java +++ b/src/main/java/com/tibiawiki/domain/objects/Quest.java @@ -73,6 +73,7 @@ private Quest(String name, String implemented, String history, Status status, St @Override public List fieldOrder() { return Arrays.asList("name", "aka", "reward", "location", "rookgaardquest", "type", "lvl", "lvlrec", "lvlnote", - "log", "time", "timealloc", "premium", "transcripts", "dangers", "legend", "history", "status"); + "log", "time", "timealloc", "premium", "transcripts", "dangers", "legend", "implemented", "history", + "status"); } } \ No newline at end of file diff --git a/src/test/java/com/tibiawiki/domain/factories/JsonFactoryTest.java b/src/test/java/com/tibiawiki/domain/factories/JsonFactoryTest.java index c0671db..7c62d61 100644 --- a/src/test/java/com/tibiawiki/domain/factories/JsonFactoryTest.java +++ b/src/test/java/com/tibiawiki/domain/factories/JsonFactoryTest.java @@ -10,10 +10,14 @@ import com.tibiawiki.domain.enums.City; import com.tibiawiki.domain.enums.Gender; import com.tibiawiki.domain.enums.Grade; +import com.tibiawiki.domain.enums.Hands; +import com.tibiawiki.domain.enums.ItemClass; import com.tibiawiki.domain.enums.KeyType; import com.tibiawiki.domain.enums.Rarity; +import com.tibiawiki.domain.enums.Spawntype; import com.tibiawiki.domain.enums.SpellSubclass; import com.tibiawiki.domain.enums.SpellType; +import com.tibiawiki.domain.enums.WeaponType; import com.tibiawiki.domain.enums.YesNo; import com.tibiawiki.domain.objects.Achievement; import com.tibiawiki.domain.objects.Book; @@ -22,6 +26,7 @@ import com.tibiawiki.domain.objects.Creature; import com.tibiawiki.domain.objects.Effect; import com.tibiawiki.domain.objects.HuntingPlace; +import com.tibiawiki.domain.objects.HuntingPlaceSkills; import com.tibiawiki.domain.objects.Item; import com.tibiawiki.domain.objects.Key; import com.tibiawiki.domain.objects.Location; @@ -270,15 +275,84 @@ void testConvertJsonToInfoboxPartOfArticle_Effect() { assertThat(result, is(INFOBOX_EFFECT_TEXT)); } - @Disabled - @Test - void testConvertJsonToInfoboxPartOfArticle_HuntingPlace() { - final HuntingPlace huntingPlace = makeHuntingPlace(); - String result = target.convertJsonToInfoboxPartOfArticle(makeHuntingPlaceJson(huntingPlace), huntingPlace.fieldOrder()); - assertThat(result, is(INFOBOX_HUNT_TEXT)); - } + private static final String INFOBOX_CREATURE_TEXT = "{{Infobox Creature|List={{{1|}}}|GetValue={{{GetValue|}}}\n" + + "| name = Dragon\n" + + "| article = a\n" + + "| actualname = dragon\n" + + "| plural = dragons\n" + + "| hp = 1000\n" + + "| exp = 700\n" + + "| armor = 25\n" + + "| summon = --\n" + + "| convince = --\n" + + "| illusionable = yes\n" + + "| creatureclass = Reptiles\n" + + "| primarytype = Dragons\n" + + "| bestiaryclass = Dragon\n" + + "| bestiarylevel = Medium\n" + + "| occurrence = Common\n" + + "| spawntype = Regular, Raid\n" + + "| isboss = no\n" + + "| isarenaboss = no\n" + + "| abilities = [[Melee]] (0-120), [[Fire Wave]] (100-170), [[Great Fireball]] (60-140), [[Self-Healing]] (40-70)\n" + + "| maxdmg = 430\n" + + "| pushable = no\n" + + "| pushobjects = yes\n" + + "| walksaround = None\n" + + "| walksthrough = Fire, Energy, Poison\n" + + "| paraimmune = yes\n" + + "| senseinvis = yes\n" + + "| physicalDmgMod = 100%\n" + + "| holyDmgMod = 100%\n" + + "| deathDmgMod = 100%\n" + + "| fireDmgMod = 0%\n" + + "| energyDmgMod = 80%\n" + + "| iceDmgMod = 110%\n" + + "| earthDmgMod = 20%\n" + + "| drownDmgMod = 100%?\n" + + "| hpDrainDmgMod = 100%?\n" + + "| bestiaryname = dragon\n" + + "| bestiarytext = Dragons were\n" + + "| sounds = {{Sound List|FCHHHHH|GROOAAARRR}}\n" + + "| implemented = Pre-6.0\n" + + "| notes = Dragons are\n" + + "| behaviour = Dragons are\n" + + "| runsat = 300\n" + + "| speed = 86\n" + + "| strategy = '''All''' [[player]]s\n" + + "| location = [[Thais]] [[Ancient Temple]], [[Darashia Dragon Lair]], [[Mount Sternum Dragon Cave]]," + + " [[Mintwallin]], deep in [[Fibula Dungeon]], [[Kazordoon Dragon Lair]] (near [[Dwarf Bridge]]), [[Plains" + + " of Havoc]], [[Elven Bane]] castle, [[Maze of Lost Souls]], southern cave and dragon tower in" + + " [[Shadowthorn]], [[Orc Fortress]], [[Venore]] [[Dragon Lair]], [[Pits of Inferno]], [[Behemoth Quest]]" + + " room in [[Edron]], [[Hero Cave]], deep [[Cyclopolis]], [[Edron Dragon Lair]], [[Goroma]], [[Ankrahmun" + + " Dragon Lair]]s, [[Draconia]], [[Dragonblaze Peaks]], some [[Ankrahmun Tombs]], underground of [[Fenrock]]" + + " (on the way to [[Beregar]]), [[Krailos Steppe]] and [[Crystal Lakes]].\n" + + "| loot = {{Loot Table\n" + + " |{{Loot Item|0-105|Gold Coin}}\n" + + " |{{Loot Item|0-3|Dragon Ham}}\n" + + " |{{Loot Item|Steel Shield}}\n" + + " |{{Loot Item|Crossbow}}\n" + + " |{{Loot Item|Dragon's Tail}}\n" + + " |{{Loot Item|0-10|Burst Arrow}}\n" + + " |{{Loot Item|Longsword|semi-rare}}\n" + + " |{{Loot Item|Steel Helmet|semi-rare}}\n" + + " |{{Loot Item|Broadsword|semi-rare}}\n" + + " |{{Loot Item|Plate Legs|semi-rare}}\n" + + " |{{Loot Item|Green Dragon Leather|rare}}\n" + + " |{{Loot Item|Wand of Inferno|rare}}\n" + + " |{{Loot Item|Strong Health Potion|rare}}\n" + + " |{{Loot Item|Green Dragon Scale|rare}}\n" + + " |{{Loot Item|Double Axe|rare}}\n" + + " |{{Loot Item|Dragon Hammer|rare}}\n" + + " |{{Loot Item|Serpent Sword|rare}}\n" + + " |{{Loot Item|Small Diamond|very rare}}\n" + + " |{{Loot Item|Dragon Shield|very rare}}\n" + + " |{{Loot Item|Life Crystal|very rare}}\n" + + " |{{Loot Item|Dragonbone Staff|very rare}}\n" + + "}}\n" + + "| history = Dragons are\n" + + "}}\n"; - @Disabled @Test void testConvertJsonToInfoboxPartOfArticle_Item() { final Item item = makeItem(); @@ -286,7 +360,6 @@ void testConvertJsonToInfoboxPartOfArticle_Item() { assertThat(result, is(INFOBOX_ITEM_TEXT)); } - @Disabled @Test void testConvertJsonToInfoboxPartOfArticle_Key() { final Key key = makeKey(); @@ -294,15 +367,46 @@ void testConvertJsonToInfoboxPartOfArticle_Key() { assertThat(result, is(INFOBOX_KEY_TEXT)); } - @Disabled - @Test - void testConvertJsonToInfoboxPartOfArticle_Location() { - final Location location = makeLocation(); - String result = target.convertJsonToInfoboxPartOfArticle(makeLocationJson(location), location.fieldOrder()); - assertThat(result, is(INFOBOX_LOCATION_TEXT)); - } + private static final String INFOBOX_HUNT_TEXT = "{{Infobox Hunt|List={{{1|}}}|GetValue={{{GetValue|}}}\n" + + "| name = Hero Cave\n" + + "| image = Hero\n" + + "| implemented = 6.4\n" + + "| city = Edron\n" + + "| location = North of [[Edron]], [http://tibia.wikia.com/wiki/Mapper?coords=129.140,123.150,7,3,1,1 here].\n" + + "| vocation = All vocations.\n" + + "| lvlknights = 70\n" + + "| lvlpaladins = 60\n" + + "| lvlmages = 50\n" + + "| skknights = 75\n" + + "| skpaladins = 80\n" + + "| skmages = 1\n" + + "| defknights = 75\n" + + "| defpaladins = 1\n" + + "| defmages = 1\n" + + "| lowerlevels = \n" + + " {{Infobox Hunt Skills\n" + + " | areaname = Demons\n" + + " | lvlknights = 130\n" + + " | lvlpaladins = 130\n" + + " | lvlmages = 130\n" + + " | skknights = 1\n" + + " | skpaladins = 1\n" + + " | skmages = 1\n" + + " | defknights = 1\n" + + " | defpaladins = 1\n" + + " | defmages = 1\n" + + " }}\n" + + "| loot = Good\n" + + "| exp = Good\n" + + "| bestloot = Reins\n" + + "| bestloot2 = Foobar\n" + + "| bestloot3 = Foobar\n" + + "| bestloot4 = Foobar\n" + + "| bestloot5 = Foobar\n" + + "| map = Hero Cave 3.png\n" + + "| map2 = Hero Cave 6.png\n" + + "}}\n"; - @Disabled @Test void testConvertJsonToInfoboxPartOfArticle_Missile() { final Missile missile = makeMissile(); @@ -310,7 +414,6 @@ void testConvertJsonToInfoboxPartOfArticle_Missile() { assertThat(result, is(INFOBOX_MISSILE_TEXT)); } - @Disabled @Test void testConvertJsonToInfoboxPartOfArticle_Mount() { final Mount mount = makeMount(); @@ -318,15 +421,37 @@ void testConvertJsonToInfoboxPartOfArticle_Mount() { assertThat(result, is(INFOBOX_MOUNT_TEXT)); } - @Disabled - @Test - void testConvertJsonToInfoboxPartOfArticle_NPC() { - final NPC npc = makeNPC(); - String result = target.convertJsonToInfoboxPartOfArticle(makeNPCJson(npc), npc.fieldOrder()); - assertThat(result, is(INFOBOX_NPC_TEXT)); - } + private static final String INFOBOX_ITEM_TEXT = "{{Infobox Item|List={{{1|}}}|GetValue={{{GetValue|}}}\n" + + "| name = Carlin Sword\n" + + "| article = a\n" + + "| actualname = carlin sword\n" + + "| plural = ?\n" + + "| itemid = 3283\n" + + "| marketable = yes\n" + + "| usable = yes\n" + + "| sprites = {{Frames|{{Frame Sprite|55266}}}}\n" + + "| flavortext = Foobar\n" + + "| itemclass = Weapons\n" + + "| primarytype = Sword Weapons\n" + + "| levelrequired = 0\n" + + "| hands = One\n" + + "| type = Sword\n" + + "| attack = 15\n" + + "| defense = 13\n" + + "| defensemod = +1\n" + + "| enchantable = no\n" + + "| weight = 40.00\n" + + "| droppedby = {{Dropped By|Grorlam|Stone Golem}}\n" + + "| value = 118\n" + + "| npcvalue = 118\n" + + "| npcprice = 473\n" + + "| npcvaluerook = 0\n" + + "| npcpricerook = 0\n" + + "| buyfrom = Baltim, Brengus, Cedrik,\n" + + "| sellto = Baltim, Brengus, Cedrik, Esrik,\n" + + "| notes = If you have one of these \n" + + "}}\n"; - @Disabled @Test void testConvertJsonToInfoboxPartOfArticle_Object() { final TibiaObject tibiaObject = makeTibiaObject(); @@ -334,7 +459,6 @@ void testConvertJsonToInfoboxPartOfArticle_Object() { assertThat(result, is(INFOBOX_OBJECT_TEXT)); } - @Disabled @Test void testConvertJsonToInfoboxPartOfArticle_Outfit() { final Outfit outfit = makeOutfit(); @@ -342,7 +466,6 @@ void testConvertJsonToInfoboxPartOfArticle_Outfit() { assertThat(result, is(INFOBOX_OUTFIT_TEXT)); } - @Disabled @Test void testConvertJsonToInfoboxPartOfArticle_Quest() { final Quest quest = makeQuest(); @@ -357,13 +480,20 @@ void testConvertJsonToInfoboxPartOfArticle_Spell() { assertThat(result, is(INFOBOX_SPELL_TEXT)); } - @Disabled - @Test - void testConvertJsonToInfoboxPartOfArticle_Street() { - final Street street = makeStreet(); - String result = target.convertJsonToInfoboxPartOfArticle(makeStreetJson(street), street.fieldOrder()); - assertThat(result, is(INFOBOX_STREET_TEXT)); - } + private static final String INFOBOX_KEY_TEXT = "{{Infobox Key|List={{{1|}}}|GetValue={{{GetValue|}}}\n" + + "| number = 4055\n" + + "| aka = Panpipe Quest Key\n" + + "| primarytype = Silver\n" + + "| location = [[Jakundaf Desert]]\n" + + "| value = Negotiable\n" + + "| npcvalue = 0\n" + + "| npcprice = 0\n" + + "| buyfrom = --\n" + + "| sellto = --\n" + + "| origin = Hidden in a rock south of the Desert Dungeon entrance.\n" + + "| shortnotes = Access to the [[Panpipe Quest]].\n" + + "| longnotes = Allows you to open the door ([http://tibia.wikia.com/wiki/Mapper?coords=127.131,125.129,8,3,1,1 here]) to the [[Panpipe Quest]].\n" + + "}}\n"; private static final String INFOBOX_TEXT_SPACE = "{{Infobox Achievement|List={{{1|}}}|GetValue={{{GetValue|}}}\n" + "| name = Goo Goo Dancer\n" + @@ -541,162 +671,24 @@ private JSONObject makeCorpseJson(Corpse corpse) { return new JSONObject(objectMapper.convertValue(corpse, Map.class)).put("templateType", "Corpse"); } - private static final String INFOBOX_CREATURE_TEXT = "{{Infobox Creature|List={{{1|}}}|GetValue={{{GetValue|}}}\n" + - "| name = Dragon\n" + - "| article = a\n" + - "| actualname = dragon\n" + - "| plural = dragons\n" + - "| hp = 1000\n" + - "| exp = 700\n" + - "| armor = 25\n" + - "| summon = --\n" + - "| convince = --\n" + - "| illusionable = yes\n" + - "| creatureclass = Reptiles\n" + - "| primarytype = Dragons\n" + - "| bestiaryclass = Dragon\n" + - "| bestiarylevel = Medium\n" + - "| occurrence = Common\n" + - "| isboss = no\n" + - "| isarenaboss = no\n" + - "| abilities = [[Melee]] (0-120), [[Fire Wave]] (100-170), [[Great Fireball]] (60-140), [[Self-Healing]] (40-70)\n" + - "| maxdmg = 430\n" + - "| pushable = no\n" + - "| pushobjects = yes\n" + - "| walksaround = None\n" + - "| walksthrough = Fire, Energy, Poison\n" + - "| paraimmune = yes\n" + - "| senseinvis = yes\n" + - "| physicalDmgMod = 100%\n" + - "| holyDmgMod = 100%\n" + - "| deathDmgMod = 100%\n" + - "| fireDmgMod = 0%\n" + - "| energyDmgMod = 80%\n" + - "| iceDmgMod = 110%\n" + - "| earthDmgMod = 20%\n" + - "| drownDmgMod = 100%?\n" + - "| hpDrainDmgMod = 100%?\n" + - "| bestiaryname = dragon\n" + - "| bestiarytext = Dragons were\n" + - "| sounds = {{Sound List|FCHHHHH|GROOAAARRR}}\n" + - "| implemented = Pre-6.0\n" + - "| notes = Dragons are\n" + - "| behaviour = Dragons are\n" + - "| runsat = 300\n" + - "| speed = 86\n" + - "| strategy = '''All''' [[player]]s\n" + - "| location = [[Thais]] [[Ancient Temple]], [[Darashia Dragon Lair]], [[Mount Sternum Dragon Cave]]," + - " [[Mintwallin]], deep in [[Fibula Dungeon]], [[Kazordoon Dragon Lair]] (near [[Dwarf Bridge]]), [[Plains" + - " of Havoc]], [[Elven Bane]] castle, [[Maze of Lost Souls]], southern cave and dragon tower in" + - " [[Shadowthorn]], [[Orc Fortress]], [[Venore]] [[Dragon Lair]], [[Pits of Inferno]], [[Behemoth Quest]]" + - " room in [[Edron]], [[Hero Cave]], deep [[Cyclopolis]], [[Edron Dragon Lair]], [[Goroma]], [[Ankrahmun" + - " Dragon Lair]]s, [[Draconia]], [[Dragonblaze Peaks]], some [[Ankrahmun Tombs]], underground of [[Fenrock]]" + - " (on the way to [[Beregar]]), [[Krailos Steppe]] and [[Crystal Lakes]].\n" + - "| loot = {{Loot Table\n" + - " |{{Loot Item|0-105|Gold Coin}}\n" + - " |{{Loot Item|0-3|Dragon Ham}}\n" + - " |{{Loot Item|Steel Shield}}\n" + - " |{{Loot Item|Crossbow}}\n" + - " |{{Loot Item|Dragon's Tail}}\n" + - " |{{Loot Item|0-10|Burst Arrow}}\n" + - " |{{Loot Item|Longsword|semi-rare}}\n" + - " |{{Loot Item|Steel Helmet|semi-rare}}\n" + - " |{{Loot Item|Broadsword|semi-rare}}\n" + - " |{{Loot Item|Plate Legs|semi-rare}}\n" + - " |{{Loot Item|Green Dragon Leather|rare}}\n" + - " |{{Loot Item|Wand of Inferno|rare}}\n" + - " |{{Loot Item|Strong Health Potion|rare}}\n" + - " |{{Loot Item|Green Dragon Scale|rare}}\n" + - " |{{Loot Item|Double Axe|rare}}\n" + - " |{{Loot Item|Dragon Hammer|rare}}\n" + - " |{{Loot Item|Serpent Sword|rare}}\n" + - " |{{Loot Item|Small Diamond|very rare}}\n" + - " |{{Loot Item|Dragon Shield|very rare}}\n" + - " |{{Loot Item|Life Crystal|very rare}}\n" + - " |{{Loot Item|Dragonbone Staff|very rare}}\n" + - "}}\n" + - "| history = Dragons are\n" + + private static final String INFOBOX_LOCATION_TEXT = "{{Infobox Geography\n" + + "| implemented = Pre-6.0\n" + + "| ruler = [[King Tibianus]]\n" + + "| population = {{PAGESINCATEGORY:Thais NPCs|pages}}\n" + + "| near = [[Fibula]], [[Mintwallin]], [[Greenshore]], [[Mount Sternum]]\n" + + "| organization = [[Thieves Guild]], [[Tibian Bureau of Investigation]], [[Inquisition]]\n" + + "| map = [[File:Map_thais.jpg]]\n" + + "| map2 = [[File:Thais.PNG]]\n" + + "}}\n"; + private static final String INFOBOX_MISSILE_TEXT = "{{Infobox Missile|List={{{1|}}}|GetValue={{{GetValue|}}}\n" + + "| name = Throwing Cake Missile\n" + + "| implemented = 7.9\n" + + "| missileid = 42\n" + + "| primarytype = Throwing Weapon\n" + + "| shotby = [[Undead Jester]]'s attack and probably by throwing a [[Throwing Cake]].\n" + + "| notes = This missile is followed by the [[Cream Cake Effect]]: [[File:Cream Cake Effect.gif]]\n" + "}}\n"; - private Creature makeCreature() { - return Creature.builder() - .name("Dragon") - .article(Article.A) - .actualname("dragon") - .plural("dragons") - .implemented("Pre-6.0") - .hitPoints("1000") - .experiencePoints("700") - .summon("--") - .convince("--") - .illusionable(YesNo.YES_LOWERCASE) - .creatureclass("Reptiles") - .primarytype("Dragons") - .bestiaryclass(BestiaryClass.DRAGON) - .bestiarylevel(BestiaryLevel.Medium) - .occurrence(BestiaryOccurrence.COMMON) - .isboss(YesNo.NO_LOWERCASE) - .isarenaboss(YesNo.NO_LOWERCASE) - .abilities("[[Melee]] (0-120), [[Fire Wave]] (100-170), [[Great Fireball]] (60-140), [[Self-Healing]] (40-70)") - .maxdmg("430") - .armor("25") - .pushable(YesNo.NO_LOWERCASE) - .pushobjects(YesNo.YES_LOWERCASE) - .walksthrough("Fire, Energy, Poison") - .walksaround("None") - .paraimmune(YesNo.YES_LOWERCASE) - .senseinvis(YesNo.YES_LOWERCASE) - .physicalDmgMod(Percentage.of(100)) - .holyDmgMod(Percentage.of(100)) - .deathDmgMod(Percentage.of(100)) - .fireDmgMod(Percentage.of(0)) - .energyDmgMod(Percentage.of(80)) - .iceDmgMod(Percentage.of(110)) - .earthDmgMod(Percentage.of(20)) - .drownDmgMod(Percentage.of("100%?")) - .hpDrainDmgMod(Percentage.of("100%?")) - .bestiaryname("dragon") - .bestiarytext("Dragons were") - .sounds(Arrays.asList("FCHHHHH", "GROOAAARRR")) - .notes("Dragons are") - .behaviour("Dragons are") - .runsat("300") - .speed("86") - .location("[[Thais]] [[Ancient Temple]], [[Darashia Dragon Lair]], [[Mount Sternum Dragon Cave]]," + - " [[Mintwallin]], deep in [[Fibula Dungeon]], [[Kazordoon Dragon Lair]] (near [[Dwarf Bridge]]), [[Plains" + - " of Havoc]], [[Elven Bane]] castle, [[Maze of Lost Souls]], southern cave and dragon tower in" + - " [[Shadowthorn]], [[Orc Fortress]], [[Venore]] [[Dragon Lair]], [[Pits of Inferno]], [[Behemoth Quest]]" + - " room in [[Edron]], [[Hero Cave]], deep [[Cyclopolis]], [[Edron Dragon Lair]], [[Goroma]], [[Ankrahmun" + - " Dragon Lair]]s, [[Draconia]], [[Dragonblaze Peaks]], some [[Ankrahmun Tombs]], underground of [[Fenrock]]" + - " (on the way to [[Beregar]]), [[Krailos Steppe]] and [[Crystal Lakes]].") - .strategy("'''All''' [[player]]s") - .loot(Arrays.asList( - LootItem.builder().amount("0-105").itemName("Gold Coin").build(), - LootItem.builder().amount("0-3").itemName("Dragon Ham").build(), - LootItem.builder().itemName("Steel Shield").build(), - LootItem.builder().itemName("Crossbow").build(), - LootItem.builder().itemName("Dragon's Tail").build(), - LootItem.builder().amount("0-10").itemName("Burst Arrow").build(), - LootItem.builder().itemName("Longsword").rarity(Rarity.SEMI_RARE).build(), - LootItem.builder().itemName("Steel Helmet").rarity(Rarity.SEMI_RARE).build(), - LootItem.builder().itemName("Broadsword").rarity(Rarity.SEMI_RARE).build(), - LootItem.builder().itemName("Plate Legs").rarity(Rarity.SEMI_RARE).build(), - LootItem.builder().itemName("Green Dragon Leather").rarity(Rarity.RARE).build(), - LootItem.builder().itemName("Wand of Inferno").rarity(Rarity.RARE).build(), - LootItem.builder().itemName("Strong Health Potion").rarity(Rarity.RARE).build(), - LootItem.builder().itemName("Green Dragon Scale").rarity(Rarity.RARE).build(), - LootItem.builder().itemName("Double Axe").rarity(Rarity.RARE).build(), - LootItem.builder().itemName("Dragon Hammer").rarity(Rarity.RARE).build(), - LootItem.builder().itemName("Serpent Sword").rarity(Rarity.RARE).build(), - LootItem.builder().itemName("Small Diamond").rarity(Rarity.VERY_RARE).build(), - LootItem.builder().itemName("Dragon Shield").rarity(Rarity.VERY_RARE).build(), - LootItem.builder().itemName("Life Crystal").rarity(Rarity.VERY_RARE).build(), - LootItem.builder().itemName("Dragonbone Staff").rarity(Rarity.VERY_RARE).build() - )) - .history("Dragons are") - .build(); - } - private JSONObject makeCreatureJson(Creature creature) { return new JSONObject(objectMapper.convertValue(creature, Map.class)).put("templateType", "Creature"); } @@ -728,115 +720,77 @@ private JSONObject makeEffectJson(Effect effect) { return new JSONObject(objectMapper.convertValue(effect, Map.class)).put("templateType", "Effect"); } - private static final String INFOBOX_HUNT_TEXT = "{{Infobox Hunt|List={{{1|}}}|GetValue={{{GetValue|}}}\n" + - "| name = Hero Cave\n" + - "| image = Hero\n" + - "| implemented = 6.4\n" + - "| city = Edron\n" + - "| location = North of [[Edron]], [http://tibia.wikia.com/wiki/Mapper?coords=129.140,123.150,7,3,1,1 here].\n" + - "| vocation = All vocations.\n" + - "| lvlknights = 70\n" + - "| lvlpaladins = 60\n" + - "| lvlmages = 50\n" + - "| skknights = 75\n" + - "| skpaladins = 80\n" + - "| skmages = \n" + - "| defknights = 75\n" + - "| defpaladins = \n" + - "| defmages =\n" + - "| lowerlevels = \n" + - " {{Infobox Hunt Skills\n" + - " | areaname = Demons\n" + - " | lvlknights = 130\n" + - " | lvlpaladins = 130\n" + - " | lvlmages = 130\n" + - " | skknights = \n" + - " | skpaladins = \n" + - " | skmages = \n" + - " | defknights = \n" + - " | defpaladins =\n" + - " | defmages =\n" + - " }}\n" + - "| exp = Good\n" + - "| loot = Good\n" + - "| bestloot = Reins\n" + - "| bestloot2 = \n" + - "| bestloot3 = \n" + - "| bestloot4 = \n" + - "| bestloot5 = \n" + - "| map = Hero Cave 3.png\n" + - "| map2 = Hero Cave 6.png\n" + - "}}"; - - private HuntingPlace makeHuntingPlace() { - return HuntingPlace.builder() - .build(); - } + private static final String INFOBOX_MOUNT_TEXT = "{{Infobox Mount|List={{{1|}}}|GetValue={{{GetValue|}}}\n" + + "| name = Donkey\n" + + "| speed = 10\n" + + "| taming_method = Use a [[Bag of Apple Slices]] on a creature transformed into Donkey.\n" + + "| achievement = Loyal Lad\n" + + "| implemented = 9.1\n" + + "| notes = Go to [[Incredibly Old Witch]]'s house,\n" + + "}}\n"; + private static final String INFOBOX_NPC_TEXT = "{{Infobox NPC|List={{{1|}}}|GetValue={{{GetValue|}}}\n" + + "| name = Sam\n" + + "| job = Artisan\n" + + "| job2 = Weapon Shopkeeper\n" + + "| job3 = Armor Shopkeeper\n" + + "| location = [[Temple Street]] in [[Thais]].\n" + + "| city = Thais\n" + + "| posx = 126.104\n" + + "| posy = 125.200\n" + + "| posz = 7\n" + + "| gender = Male\n" + + "| race = Human\n" + + "| buysell = yes\n" + + "| buys = {{Price to Sell |Axe\n" + + "| sells = {{Price to Buy |Axe\n" + + "| sounds = {{Sound List|Hello there, adventurer! Need a deal in weapons or armor? I'm your man!}}\n" + + "| implemented = Pre-6.0\n" + + "| notes = Sam is the Blacksmith of [[Thais]].\n" + + "}}\n"; private JSONObject makeHuntingPlaceJson(HuntingPlace huntingPlace) { return new JSONObject(objectMapper.convertValue(huntingPlace, Map.class)).put("templateType", "Hunt"); } - private static final String INFOBOX_ITEM_TEXT = "{{Infobox Item|List={{{1|}}}|GetValue={{{GetValue|}}}\n" + - "| name = Carlin Sword\n" + - "| marketable = yes\n" + - "| usable = yes\n" + - "| sprites = {{Frames|{{Frame Sprite|55266}}}}\n" + - "| article = a\n" + - "| actualname = carlin sword\n" + - "| plural = ?\n" + - "| itemid = 3283\n" + - "| flavortext =\n" + - "| itemclass = Weapons\n" + - "| primarytype = Sword Weapons\n" + - "| levelrequired = 0\n" + - "| hands = One\n" + - "| type = Sword\n" + - "| attack = 15\n" + - "| defense = 13\n" + - "| defensemod = +1\n" + - "| enchantable = no\n" + - "| weight = 40.00\n" + - "| droppedby = {{Dropped By|Grorlam|Stone Golem}}\n" + - "| value = 118 \n" + - "| npcvalue = 118 \n" + - "| npcprice = 473 \n" + - "| npcvaluerook = 0\n" + - "| npcpricerook = 0\n" + - "| buyfrom = Baltim, Brengus, Cedrik, Esrik, Flint, Gamel, Habdel, Hardek, Memech, Morpel, Robert," + - " Rock In A Hard Place, Romella, Rowenna, Sam, Shanar, Turvy, Ulrik, Uzgod, Willard\n" + - "| sellto = Baltim, Brengus, Cedrik, Esrik, Flint, Gamel, H.L.: 5, Habdel, Hardek, Memech, Morpel," + - " Robert, Rock In A Hard Place, Romella, Rowenna, Sam, Shanar, Turvy, Ulrik, Uzgod, Willard\n" + - "| notes = If you have one of these in [[Rookgaard]] and already reached level 8 you may want to" + - " keep it, if you are going to [[Carlin]]. A common strategy in [[Rookgaard]] was to buy as many carlin" + - " swords as the Rookgaardian can carry and sell all their [[equipment]] to other Rookgaardians and make a" + - " hefty profit on the carlin swords in [[Mainland]], although this may not be recommendable now that one" + - " goes to the [[Island of Destiny]] at [[level]] 8 ([[Raffael]] doesn't buy Carlin Swords).\n" + - "{{JSpoiler|Obtainable in [[Rookgaard]] through the [[Minotaur Hell Quest]].}}\n" + + private static final String INFOBOX_OBJECT_TEXT = "{{Infobox Object|List={{{1|}}}|GetValue={{{GetValue|}}}\n" + + "| name = Blueberry Bush\n" + + "| article = a\n" + + "| objectclass = Bushes\n" + + "| implemented = 7.1\n" + + "| walkable = no\n" + + "| location = Can be found all around [[Tibia]].\n" + + "| notes = They are the source of the [[blueberry|blueberries]].\n" + + "| notes2 =
{{JSpoiler|After using [[Blueberry]] Bushes 500 times,\n" + + "}}\n"; + private static final String INFOBOX_OUTFIT_TEXT = "{{Infobox Outfit|List={{{1|}}}|GetValue={{{GetValue|}}}\n" + + "| name = Pirate\n" + + "| primarytype = Quest\n" + + "| premium = yes\n" + + "| outfit = premium, see [[Pirate Outfits Quest]].\n" + + "| addons = premium, see [[Pirate Outfits Quest]].\n" + + "| achievement = Swashbuckler\n" + + "| implemented = 7.8\n" + + "| artwork = Pirate Outfits Artwork.jpg\n" + + "| notes = Pirate outfits are perfect for swabbing the deck or walking the plank. Quite dashing and great for sailing.\n" + "}}\n"; - - private Item makeItem() { - return Item.builder() - .build(); - } private JSONObject makeItemJson(Item item) { return new JSONObject(objectMapper.convertValue(item, Map.class)).put("templateType", "Item"); } - private static final String INFOBOX_KEY_TEXT = "{{Infobox Key|List={{{1|}}}|GetValue={{{GetValue|}}}\n" + - "| number = 4055\n" + - "| aka = Panpipe Quest Key\n" + - "| primarytype = Silver\n" + - "| location = [[Jakundaf Desert]]\n" + - "| value = Negotiable\n" + - "| npcvalue = 0\n" + - "| npcprice = 0\n" + - "| buyfrom = --\n" + - "| sellto = --\n" + - "| origin = Hidden in a rock south of the Desert Dungeon entrance.\n" + - "| shortnotes = Access to the [[Panpipe Quest]].\n" + - "| longnotes = Allows you to open the door ([http://tibia.wikia.com/wiki/Mapper?coords=127.131,125.129,8,3,1,1 here]) to the [[Panpipe Quest]].\n" + + private static final String INFOBOX_QUEST_TEXT = "{{Infobox Quest|List={{{1|}}}|GetValue={{{GetValue|}}}\n" + + "| name = The Paradox Tower Quest\n" + + "| aka = Riddler Quest, Mathemagics Quest\n" + + "| reward = Up to two of the following:\n" + + "| location = [[Paradox Tower]] near [[Kazordoon]]\n" + + "| lvl = 30\n" + + "| lvlrec = 50\n" + + "| log = yes\n" + + "| premium = yes\n" + + "| transcripts = yes\n" + + "| dangers = [[Wyvern]]s
([[Mintwallin]]): [[Minotaur]]s,\n" + + "| legend = Surpass the wrath of a madman and subject yourself to his twisted taunting.\n" + + "| implemented = 6.61-6.97\n" + "}}\n"; private Key makeKey() { @@ -860,15 +814,12 @@ private JSONObject makeKeyJson(Key key) { return new JSONObject(objectMapper.convertValue(key, Map.class)).put("templateType", "Key"); } - private static final String INFOBOX_LOCATION_TEXT = "{{Infobox Geography\n" + - "| ruler = [[King Tibianus]]\n" + - "| implemented = Pre-6.0\n" + - "| population = {{PAGESINCATEGORY:Thais NPCs|pages}}\n" + - "| organization = [[Thieves Guild]], [[Tibian Bureau of Investigation]], [[Inquisition]]\n" + - "| near = [[Fibula]], [[Mintwallin]], [[Greenshore]], [[Mount Sternum]]\n" + - "| map = [[File:Map_thais.jpg]]\n" + - "| map2 = [[File:Thais.PNG]]\n" + - "}}"; + private static final String INFOBOX_STREET_TEXT = "{{Infobox Street\n" + + "| name = Sugar Street\n" + + "| implemented = 7.8\n" + + "| city = Liberty Bay\n" + + "| notes = {{StreetStyles|Sugar Street}} is in west\n" + + "}}\n"; private Location makeLocation() { return Location.builder() @@ -886,14 +837,16 @@ private JSONObject makeLocationJson(Location location) { return new JSONObject(objectMapper.convertValue(location, Map.class)).put("templateType", "Geography"); } - private static final String INFOBOX_MISSILE_TEXT = "{{Infobox Missile|List={{{1|}}}|GetValue={{{GetValue|}}}\n" + - "| name = Throwing Cake Missile\n" + - "| implemented = 7.9\n" + - "| missileid = 42\n" + - "| primarytype = Throwing Weapon\n" + - "| shotby = [[Undead Jester]]'s attack and probably by throwing a [[Throwing Cake]].\n" + - "| notes = This missile is followed by the [[Cream Cake Effect]]: [[File:Cream Cake Effect.gif]]\n" + - "}}\n"; + /** + * FIXME enable this test when the factory is make to work + */ + @Disabled + @Test + void testConvertJsonToInfoboxPartOfArticle_HuntingPlace() { + final HuntingPlace huntingPlace = makeHuntingPlace(); + String result = target.convertJsonToInfoboxPartOfArticle(makeHuntingPlaceJson(huntingPlace), huntingPlace.fieldOrder()); + assertThat(result, is(INFOBOX_HUNT_TEXT)); + } private Missile makeMissile() { return Missile.builder() @@ -910,13 +863,16 @@ private JSONObject makeMissileJson(Missile missile) { return new JSONObject(objectMapper.convertValue(missile, Map.class)).put("templateType", "Missile"); } - private static final String INFOBOX_MOUNT_TEXT = "{{Infobox_Mount|List={{{1|}}}|GetValue={{{GetValue|}}}\n" + - "| name = Donkey\n" + - "| speed = 10\n" + - "| taming_method = Use a [[Bag of Apple Slices]] on a creature transformed into Donkey.\n" + - "| implemented = 9.1\n" + - "| achievement = Loyal Lad\n" + - "| notes = Go to [[Incredibly Old Witch]]'s house,\n"; + /** + * FIXME enable this test when the factory is make to work (not always List and GetValue parameters) + */ + @Disabled + @Test + void testConvertJsonToInfoboxPartOfArticle_Location() { + final Location location = makeLocation(); + String result = target.convertJsonToInfoboxPartOfArticle(makeLocationJson(location), location.fieldOrder()); + assertThat(result, is(INFOBOX_LOCATION_TEXT)); + } private Mount makeMount() { return Mount.builder() @@ -933,25 +889,16 @@ private JSONObject makeMountJson(Mount mount) { return new JSONObject(objectMapper.convertValue(mount, Map.class)).put("templateType", "Mount"); } - private static final String INFOBOX_NPC_TEXT = "{{Infobox NPC|List={{{1|}}}|GetValue={{{GetValue|}}}\n" + - "| name = Sam\n" + - "| implemented = Pre-6.0\n" + - "| job = Artisan\n" + - "| job2 = Weapon Shopkeeper\n" + - "| job3 = Armor Shopkeeper\n" + - "| location = [[Temple Street]] in [[Thais]].\n" + - "| posx = 126.104\n" + - "| posy = 125.200\n" + - "| posz = 7\n" + - "| gender = Male\n" + - "| race = Human\n" + - "| city = Thais\n" + - "| buysell = yes\n" + - "| sells = {{Price to Buy |Axe\n" + - "| buys = {{Price to Sell |Axe\n" + - "| sounds = {{Sound List|Hello there, adventurer! Need a deal in weapons or armor? I'm your man!}}\n" + - "| notes = Sam is the Blacksmith of [[Thais]].\n" + - "}}\n"; + /** + * FIXME enable this test when the factory is make to work (posx, posy etc. as doubles was a bad idea, can't set scale) + */ + @Disabled + @Test + void testConvertJsonToInfoboxPartOfArticle_NPC() { + final NPC npc = makeNPC(); + String result = target.convertJsonToInfoboxPartOfArticle(makeNPCJson(npc), npc.fieldOrder()); + assertThat(result, is(INFOBOX_NPC_TEXT)); + } private NPC makeNPC() { return NPC.builder() @@ -979,16 +926,16 @@ private JSONObject makeNPCJson(NPC npc) { return new JSONObject(objectMapper.convertValue(npc, Map.class)).put("templateType", "NPC"); } - private static final String INFOBOX_OBJECT_TEXT = "{{Infobox Object|List={{{1|}}}|GetValue={{{GetValue|}}}\n" + - "| name = Blueberry Bush\n" + - "| article = a\n" + - "| objectclass = Bushes\n" + - "| walkable = no\n" + - "| location = Can be found all around [[Tibia]].\n" + - "| notes = They are the source of the [[blueberry|blueberries]].\n" + - "| notes2 =
{{JSpoiler|After using [[Blueberry]] Bushes 500 times,\n" + - "| implemented = 7.1\n" + - "}}\n"; + /** + * FIXME enable this test when the factory is make to work (not always List and GetValue parameters) + */ + @Disabled + @Test + void testConvertJsonToInfoboxPartOfArticle_Street() { + final Street street = makeStreet(); + String result = target.convertJsonToInfoboxPartOfArticle(makeStreetJson(street), street.fieldOrder()); + assertThat(result, is(INFOBOX_STREET_TEXT)); + } private TibiaObject makeTibiaObject() { return TibiaObject.builder() @@ -1007,17 +954,85 @@ private JSONObject makeTibiaObjectJson(TibiaObject tibiaObject) { return new JSONObject(objectMapper.convertValue(tibiaObject, Map.class)).put("templateType", "Object"); } - private static final String INFOBOX_OUTFIT_TEXT = "{{Infobox_Outfit|List={{{1|}}}|GetValue={{{GetValue|}}}\n" + - "| name = Pirate\n" + - "| primarytype = Quest\n" + - "| premium = yes\n" + - "| outfit = premium, see [[Pirate Outfits Quest]].\n" + - "| addons = premium, see [[Pirate Outfits Quest]].\n" + - "| achievement = Swashbuckler\n" + - "| implemented = 7.8\n" + - "| artwork = Pirate Outfits Artwork.jpg\n" + - "| notes = Pirate outfits are perfect for swabbing the deck or walking the plank. Quite dashing and great for sailing.\n" + - "}}\n"; + private Creature makeCreature() { + return Creature.builder() + .name("Dragon") + .article(Article.A) + .actualname("dragon") + .plural("dragons") + .implemented("Pre-6.0") + .hitPoints("1000") + .experiencePoints("700") + .summon("--") + .convince("--") + .illusionable(YesNo.YES_LOWERCASE) + .creatureclass("Reptiles") + .primarytype("Dragons") + .bestiaryclass(BestiaryClass.DRAGON) + .bestiarylevel(BestiaryLevel.Medium) + .occurrence(BestiaryOccurrence.COMMON) + .spawntype(Arrays.asList(Spawntype.REGULAR, Spawntype.RAID)) + .isboss(YesNo.NO_LOWERCASE) + .isarenaboss(YesNo.NO_LOWERCASE) + .abilities("[[Melee]] (0-120), [[Fire Wave]] (100-170), [[Great Fireball]] (60-140), [[Self-Healing]] (40-70)") + .maxdmg("430") + .armor("25") + .pushable(YesNo.NO_LOWERCASE) + .pushobjects(YesNo.YES_LOWERCASE) + .walksthrough("Fire, Energy, Poison") + .walksaround("None") + .paraimmune(YesNo.YES_LOWERCASE) + .senseinvis(YesNo.YES_LOWERCASE) + .physicalDmgMod(Percentage.of(100)) + .holyDmgMod(Percentage.of(100)) + .deathDmgMod(Percentage.of(100)) + .fireDmgMod(Percentage.of(0)) + .energyDmgMod(Percentage.of(80)) + .iceDmgMod(Percentage.of(110)) + .earthDmgMod(Percentage.of(20)) + .drownDmgMod(Percentage.of("100%?")) + .hpDrainDmgMod(Percentage.of("100%?")) + .bestiaryname("dragon") + .bestiarytext("Dragons were") + .sounds(Arrays.asList("FCHHHHH", "GROOAAARRR")) + .notes("Dragons are") + .behaviour("Dragons are") + .runsat("300") + .speed("86") + .location("[[Thais]] [[Ancient Temple]], [[Darashia Dragon Lair]], [[Mount Sternum Dragon Cave]]," + + " [[Mintwallin]], deep in [[Fibula Dungeon]], [[Kazordoon Dragon Lair]] (near [[Dwarf Bridge]]), [[Plains" + + " of Havoc]], [[Elven Bane]] castle, [[Maze of Lost Souls]], southern cave and dragon tower in" + + " [[Shadowthorn]], [[Orc Fortress]], [[Venore]] [[Dragon Lair]], [[Pits of Inferno]], [[Behemoth Quest]]" + + " room in [[Edron]], [[Hero Cave]], deep [[Cyclopolis]], [[Edron Dragon Lair]], [[Goroma]], [[Ankrahmun" + + " Dragon Lair]]s, [[Draconia]], [[Dragonblaze Peaks]], some [[Ankrahmun Tombs]], underground of [[Fenrock]]" + + " (on the way to [[Beregar]]), [[Krailos Steppe]] and [[Crystal Lakes]].") + .strategy("'''All''' [[player]]s") + .loot(Arrays.asList( + LootItem.builder().amount("0-105").itemName("Gold Coin").build(), + LootItem.builder().amount("0-3").itemName("Dragon Ham").build(), + LootItem.builder().itemName("Steel Shield").build(), + LootItem.builder().itemName("Crossbow").build(), + LootItem.builder().itemName("Dragon's Tail").build(), + LootItem.builder().amount("0-10").itemName("Burst Arrow").build(), + LootItem.builder().itemName("Longsword").rarity(Rarity.SEMI_RARE).build(), + LootItem.builder().itemName("Steel Helmet").rarity(Rarity.SEMI_RARE).build(), + LootItem.builder().itemName("Broadsword").rarity(Rarity.SEMI_RARE).build(), + LootItem.builder().itemName("Plate Legs").rarity(Rarity.SEMI_RARE).build(), + LootItem.builder().itemName("Green Dragon Leather").rarity(Rarity.RARE).build(), + LootItem.builder().itemName("Wand of Inferno").rarity(Rarity.RARE).build(), + LootItem.builder().itemName("Strong Health Potion").rarity(Rarity.RARE).build(), + LootItem.builder().itemName("Green Dragon Scale").rarity(Rarity.RARE).build(), + LootItem.builder().itemName("Double Axe").rarity(Rarity.RARE).build(), + LootItem.builder().itemName("Dragon Hammer").rarity(Rarity.RARE).build(), + LootItem.builder().itemName("Serpent Sword").rarity(Rarity.RARE).build(), + LootItem.builder().itemName("Small Diamond").rarity(Rarity.VERY_RARE).build(), + LootItem.builder().itemName("Dragon Shield").rarity(Rarity.VERY_RARE).build(), + LootItem.builder().itemName("Life Crystal").rarity(Rarity.VERY_RARE).build(), + LootItem.builder().itemName("Dragonbone Staff").rarity(Rarity.VERY_RARE).build() + )) + .history("Dragons are") + .build(); + } private Outfit makeOutfit() { return Outfit.builder() @@ -1037,35 +1052,77 @@ private JSONObject makeOutfitJson(Outfit outfit) { return new JSONObject(objectMapper.convertValue(outfit, Map.class)).put("templateType", "Outfit"); } - private static final String INFOBOX_QUEST_TEXT = "{{Infobox Quest|List={{{1|}}}|GetValue={{{GetValue|}}}\n" + - "| implemented = 6.61-6.97\n" + - "| premium = yes\n" + - "| name = The Paradox Tower Quest\n" + - "| aka = Riddler Quest, Mathemagics Quest\n" + - "| reward = Up to two of the following:\n" + - "| location = [[Paradox Tower]] near [[Kazordoon]]\n" + - "| lvl = 30\n" + - "| lvlrec = 50+\n" + - "| log = yes\n" + - "| transcripts = yes\n" + - "| dangers = [[Wyvern]]s
([[Mintwallin]]): [[Minotaur]]s,\n" + - "| legend = Surpass the wrath of a madman and subject yourself to his twisted taunting.\n" + - "}}\n"; + private HuntingPlace makeHuntingPlace() { + return HuntingPlace.builder() + .name("Hero Cave") + .image("Hero") + .implemented("6.4") + .city(City.EDRON) + .location("North of [[Edron]], [http://tibia.wikia.com/wiki/Mapper?coords=129.140,123.150,7,3,1,1 here].") + .vocation("All vocations.") + .lvlknights("70") + .lvlpaladins("60") + .lvlmages("50") + .skknights("75") + .skpaladins("80") + .skmages("1") + .defknights("75") + .defpaladins("1") + .defmages("1") + .lowerlevels(Collections.singletonList(HuntingPlaceSkills.builder() + .areaname("Demons") + .lvlknights("130") + .lvlpaladins("130") + .lvlmages("130") + .skknights("1") + .skpaladins("1") + .skmages("1") + .defknights("1") + .defpaladins("1") + .defmages("1") + .build())) + .exp("Good") + .loot("Good") + .bestloot("Reins") + .bestloot2("Foobar") + .bestloot3("Foobar") + .bestloot4("Foobar") + .bestloot5("Foobar") + .map("Hero Cave 3.png") + .map2("Hero Cave 6.png") + .build(); + } - private Quest makeQuest() { - return Quest.builder() - .implemented("6.61-6.97") - .premium(YesNo.YES_LOWERCASE) - .name("The Paradox Tower Quest") - .aka("Riddler Quest, Mathemagics Quest") - .reward("Up to two of the following:") - .location("[[Paradox Tower]] near [[Kazordoon]]") - .lvl(30) - .lvlrec(50) - .log(YesNo.YES_LOWERCASE) - .transcripts(YesNo.YES_LOWERCASE) - .dangers("[[Wyvern]]s
([[Mintwallin]]): [[Minotaur]]s,") - .legend("Surpass the wrath of a madman and subject yourself to his twisted taunting.") + private Item makeItem() { + return Item.builder() + .name("Carlin Sword") + .marketable(YesNo.YES_LOWERCASE) + .usable(YesNo.YES_LOWERCASE) + .sprites("{{Frames|{{Frame Sprite|55266}}}}") + .article(Article.A) + .actualname("carlin sword") + .plural("?") + .itemid(Collections.singletonList(3283)) + .flavortext("Foobar") + .itemclass(ItemClass.WEAPONS) + .primarytype("Sword Weapons") + .levelrequired(0) + .hands(Hands.One) + .type(WeaponType.Sword) + .attack("15") + .defense(13) + .defensemod("+1") + .enchantable(YesNo.NO_LOWERCASE) + .weight(BigDecimal.valueOf(40.00).setScale(2, RoundingMode.HALF_UP)) + .droppedby(Arrays.asList("Grorlam", "Stone Golem")) + .value("118") + .npcvalue("118") + .npcprice("473") + .npcvaluerook("0") + .npcpricerook("0") + .buyfrom("Baltim, Brengus, Cedrik,") + .sellto("Baltim, Brengus, Cedrik, Esrik,") + .notes("If you have one of these ") .build(); } @@ -1115,12 +1172,22 @@ private JSONObject makeSpellJson(Spell spell) { return new JSONObject(objectMapper.convertValue(spell, Map.class)).put("templateType", "Spell"); } - private static final String INFOBOX_STREET_TEXT = "{{Infobox Street\n" + - "| name = Sugar Street\n" + - "| implemented = 7.8\n" + - "| city = Liberty Bay\n" + - "| notes = {{StreetStyles|Sugar Street}} is in west\n" + - "}}\n"; + private Quest makeQuest() { + return Quest.builder() + .name("The Paradox Tower Quest") + .aka("Riddler Quest, Mathemagics Quest") + .reward("Up to two of the following:") + .location("[[Paradox Tower]] near [[Kazordoon]]") + .lvl(30) + .lvlrec(50) + .log(YesNo.YES_LOWERCASE) + .premium(YesNo.YES_LOWERCASE) + .transcripts(YesNo.YES_LOWERCASE) + .dangers("[[Wyvern]]s
([[Mintwallin]]): [[Minotaur]]s,") + .legend("Surpass the wrath of a madman and subject yourself to his twisted taunting.") + .implemented("6.61-6.97") + .build(); + } private Street makeStreet() { return Street.builder() From 140e9bcb81a8ca1ad25484da4bf8a751fbb4ade4 Mon Sep 17 00:00:00 2001 From: Benjamin Komen Date: Sat, 8 Dec 2018 12:07:45 +0100 Subject: [PATCH 14/19] Reworking dependency injection in constructors instead of fields. Adding Missiles resource. --- README.md | 94 ++++++++++--------- .../domain/enums/InfoboxTemplate.java | 1 + .../tibiawiki/process/ModifyAchievement.java | 13 +-- .../process/RetrieveAchievements.java | 6 +- .../com/tibiawiki/process/RetrieveAny.java | 10 +- .../com/tibiawiki/process/RetrieveBooks.java | 6 +- .../tibiawiki/process/RetrieveBuildings.java | 6 +- .../tibiawiki/process/RetrieveCorpses.java | 6 +- .../tibiawiki/process/RetrieveCreatures.java | 6 +- .../tibiawiki/process/RetrieveEffects.java | 6 +- .../process/RetrieveHuntingPlaces.java | 6 +- .../com/tibiawiki/process/RetrieveItems.java | 6 +- .../com/tibiawiki/process/RetrieveKeys.java | 6 +- .../tibiawiki/process/RetrieveLocations.java | 6 +- .../tibiawiki/process/RetrieveMissiles.java | 40 ++++++++ .../com/tibiawiki/process/RetrieveMounts.java | 6 +- .../com/tibiawiki/process/RetrieveNPCs.java | 6 +- .../tibiawiki/process/RetrieveObjects.java | 6 +- .../tibiawiki/process/RetrieveOutfits.java | 6 +- .../com/tibiawiki/process/RetrieveQuests.java | 6 +- .../com/tibiawiki/process/RetrieveSpells.java | 6 +- .../tibiawiki/process/RetrieveStreets.java | 6 +- .../AchievementsResource.java | 8 +- .../serviceinterface/BooksResource.java | 6 +- .../serviceinterface/BuildingsResource.java | 6 +- .../serviceinterface/CorpsesResource.java | 12 ++- .../serviceinterface/CreaturesResource.java | 12 ++- .../serviceinterface/EffectsResource.java | 6 +- .../HuntingPlacesResource.java | 6 +- .../serviceinterface/ItemsResource.java | 6 +- .../serviceinterface/KeysResource.java | 6 +- .../serviceinterface/LocationsResource.java | 12 ++- .../serviceinterface/MissilesResource.java | 54 +++++++++++ .../serviceinterface/MountsResource.java | 12 ++- .../serviceinterface/NPCsResource.java | 12 ++- .../serviceinterface/ObjectsResource.java | 12 ++- .../serviceinterface/OutfitsResource.java | 12 ++- .../serviceinterface/QuestsResource.java | 12 ++- .../serviceinterface/SpellsResource.java | 12 ++- .../serviceinterface/StreetsResource.java | 6 +- .../serviceinterface/config/JerseyConfig.java | 20 +++- 41 files changed, 305 insertions(+), 187 deletions(-) create mode 100644 src/main/java/com/tibiawiki/process/RetrieveMissiles.java create mode 100644 src/main/java/com/tibiawiki/serviceinterface/MissilesResource.java diff --git a/README.md b/README.md index 28df628..a21fc4f 100644 --- a/README.md +++ b/README.md @@ -15,7 +15,7 @@ environment such as Git Bash. Now you can start the application by typing the fo Alternatively and maybe easier, you can also execute: `mvn spring-boot:run` in your command line. You can now access the REST resources using your browser or any REST client such as Postman or curl from your command line. - E.g. navigating to http://localhost:8080/corpses should give you a list of corpses. + E.g. navigating to http://localhost:8080/api/corpses should give you a list of corpses. ## API documentation Navigate to http://localhost:8080/ for automatically generated api documentation provided by Swagger. @@ -26,135 +26,143 @@ For all resources the query parameter ?expand=true can be appended to get a full ## Achievements A list of all achievements: -http://localhost:8080/achievements +http://localhost:8080/api/achievements An achievement by achievement name, e.g. "Goo Goo Dancer": -http://localhost:8080/achievements/Goo_Goo_Dancer +http://localhost:8080/api/achievements/Goo_Goo_Dancer ## Books A list of all books: -http://localhost:8080/books +http://localhost:8080/api/books A book by book name, e.g. "Dungeon Survival Guide (Book)": -http://localhost:8080/books/Dungeon_Survival_Guide_%28Book%29 +http://localhost:8080/api/books/Dungeon_Survival_Guide_%28Book%29 ## Buildings A list of all buildings: -http://localhost:8080/buildings +http://localhost:8080/api/buildings A building by building name, e.g. "Theater Avenue 8b": -http://localhost:8080/buildings/Theater_Avenue_8b +http://localhost:8080/api/buildings/Theater_Avenue_8b ## Corpses A list of all corpses: -http://localhost:8080/corpses +http://localhost:8080/api/corpses A corpse by corpse name, e.g. "Dead Rat": -http://localhost:8080/corpses/Dead_Rat +http://localhost:8080/api/corpses/Dead_Rat ## Creatures A list of all creatures: -http://localhost:8080/creatures +http://localhost:8080/api/creatures A creature by creature name, e.g. "Dragon": -http://localhost:8080/creatures/Dragon +http://localhost:8080/api/creatures/Dragon ## Effects A list of all effects: -http://localhost:8080/effects +http://localhost:8080/api/effects -An effect by effect name, e.g. "Throwing Cake Effect": -http://localhost:8080/effects/Throwing_Cake_Effect +An effect by effect name, e.g. "Blue Electricity Effect": +http://localhost:8080/api/effects/Blue_Electricity_Effect -## Locations (Geography) - -A list of all locations: -http://localhost:8080/locations - -A location by location name, e.g. "Thais": -http://localhost:8080/locations/Thais - -## Hunting Places (in progress) +## Hunting Places A list of all hunting places: -http://localhost:8080/huntingplaces +http://localhost:8080/api/huntingplaces A location by location name, e.g. "Hero Cave": -http://localhost:8080/huntingplaces/Hero_Cave +http://localhost:8080/api/huntingplaces/Hero_Cave ## Items A list of all items: -http://localhost:8080/items +http://localhost:8080/api/items An item by item name, e.g. "Carlin Sword": -http://localhost:8080/items/Carlin_Sword +http://localhost:8080/api/items/Carlin_Sword ## Keys A list of all keys: -http://localhost:8080/keys +http://localhost:8080/api/keys A key by key name (not only the number but the full wiki pagename), e.g. "Key 4055": -http://localhost:8080/keys/Key_4055 +http://localhost:8080/api/keys/Key_4055 + +## Locations (Geography) + +A list of all locations: +http://localhost:8080/api/locations + +A location by location name, e.g. "Thais": +http://localhost:8080/api/locations/Thais + +## Missiles + +A list of all missiles: +http://localhost:8080/api/missiles + +A missile by name, e.g. "Throwing Cake Missile": +http://localhost:8080/api/missiles/Throwing_Cake_Missile ## Mounts A list of all mounts: -http://localhost:8080/mounts +http://localhost:8080/api/mounts A mount by mount name, e.g. "Donkey": -http://localhost:8080/mounts/Donkey +http://localhost:8080/api/mounts/Donkey ## NPCs A list of all NPCs: -http://localhost:8080/npcs +http://localhost:8080/api/npcs An NPC by NPC name, e.g. "Sam": -http://localhost:8080/npcs/Sam +http://localhost:8080/api/npcs/Sam ## Objects A list of all objects: -http://localhost:8080/objects +http://localhost:8080/api/objects An object by object name, e.g. "Blueberry Bush": -http://localhost:8080/objects/Blueberry_Bush +http://localhost:8080/api/objects/Blueberry_Bush ## Outfits A list of all outfits: -http://localhost:8080/outfits +http://localhost:8080/api/outfits An outfit by outfit name, e.g. "Pirate Outfits": -http://localhost:8080/outfits/Pirate_Outfits +http://localhost:8080/api/outfits/Pirate_Outfits ## Quests A list of all quests: -http://localhost:8080/quests +http://localhost:8080/api/quests A quest by quest name, e.g. "The Paradox Tower Quest": -http://localhost:8080/quests/The_Paradox_Tower_Quest +http://localhost:8080/api/quests/The_Paradox_Tower_Quest ## Spells A list of all spells: -http://localhost:8080/spells +http://localhost:8080/api/spells A spell by spell name, e.g. "Light Healing": -http://localhost:8080/spells/Light_Healing +http://localhost:8080/api/spells/Light_Healing ## Streets A list of all streets: -http://localhost:8080/streets +http://localhost:8080/api/streets A street by street name, e.g. "Sugar Street": -http://localhost:8080/streets/Sugar_Street \ No newline at end of file +http://localhost:8080/api/streets/Sugar_Street \ No newline at end of file diff --git a/src/main/java/com/tibiawiki/domain/enums/InfoboxTemplate.java b/src/main/java/com/tibiawiki/domain/enums/InfoboxTemplate.java index 012f6da..bd1c6da 100644 --- a/src/main/java/com/tibiawiki/domain/enums/InfoboxTemplate.java +++ b/src/main/java/com/tibiawiki/domain/enums/InfoboxTemplate.java @@ -17,6 +17,7 @@ public enum InfoboxTemplate implements WikiTemplate { HUNT("Hunt", "Hunting Places"), ITEM("Item", "Items"), KEY("Key", "Keys"), + MISSILE("Missile", "Missiles"), MOUNT("Mount", "Mounts"), NPC("NPC", "NPCs"), OBJECT("Object", "Objects"), diff --git a/src/main/java/com/tibiawiki/process/ModifyAchievement.java b/src/main/java/com/tibiawiki/process/ModifyAchievement.java index fe9457c..6597f4c 100644 --- a/src/main/java/com/tibiawiki/process/ModifyAchievement.java +++ b/src/main/java/com/tibiawiki/process/ModifyAchievement.java @@ -22,17 +22,18 @@ @Component public class ModifyAchievement { - @Autowired private WikiObjectFactory wikiObjectFactory; - @Autowired private JsonFactory jsonFactory; - @Autowired private ArticleFactory articleFactory; - @Autowired private ArticleRepository articleRepository; - private ModifyAchievement() { - // nothing to do, all dependencies are injected + @Autowired + private ModifyAchievement(WikiObjectFactory wikiObjectFactory, JsonFactory jsonFactory, ArticleFactory articleFactory, + ArticleRepository articleRepository) { + this.wikiObjectFactory = wikiObjectFactory; + this.jsonFactory = jsonFactory; + this.articleFactory = articleFactory; + this.articleRepository = articleRepository; } public Try modify(Achievement achievement, String editSummary) { diff --git a/src/main/java/com/tibiawiki/process/RetrieveAchievements.java b/src/main/java/com/tibiawiki/process/RetrieveAchievements.java index d51926c..21274ab 100644 --- a/src/main/java/com/tibiawiki/process/RetrieveAchievements.java +++ b/src/main/java/com/tibiawiki/process/RetrieveAchievements.java @@ -5,6 +5,7 @@ import com.tibiawiki.domain.factories.JsonFactory; import com.tibiawiki.domain.repositories.ArticleRepository; import org.json.JSONObject; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import java.util.List; @@ -15,10 +16,7 @@ @Component public class RetrieveAchievements extends RetrieveAny { - private RetrieveAchievements() { - // nothing to do, all dependencies are injected - } - + @Autowired public RetrieveAchievements(ArticleRepository articleRepository, ArticleFactory articleFactory, JsonFactory jsonFactory) { super(articleRepository, articleFactory, jsonFactory); } diff --git a/src/main/java/com/tibiawiki/process/RetrieveAny.java b/src/main/java/com/tibiawiki/process/RetrieveAny.java index 1232af7..83c900c 100644 --- a/src/main/java/com/tibiawiki/process/RetrieveAny.java +++ b/src/main/java/com/tibiawiki/process/RetrieveAny.java @@ -16,18 +16,12 @@ public abstract class RetrieveAny { protected static final String CATEGORY_LISTS = "Lists"; - @Autowired protected ArticleRepository articleRepository; - @Autowired protected ArticleFactory articleFactory; - @Autowired protected JsonFactory jsonFactory; - protected RetrieveAny() { - // nothing to do, all dependencies are injected - } - - public RetrieveAny(ArticleRepository articleRepository, ArticleFactory articleFactory, JsonFactory jsonFactory) { + @Autowired + protected RetrieveAny(ArticleRepository articleRepository, ArticleFactory articleFactory, JsonFactory jsonFactory) { this.articleRepository = articleRepository; this.articleFactory = articleFactory; this.jsonFactory = jsonFactory; diff --git a/src/main/java/com/tibiawiki/process/RetrieveBooks.java b/src/main/java/com/tibiawiki/process/RetrieveBooks.java index 4a36386..20b50b3 100644 --- a/src/main/java/com/tibiawiki/process/RetrieveBooks.java +++ b/src/main/java/com/tibiawiki/process/RetrieveBooks.java @@ -5,6 +5,7 @@ import com.tibiawiki.domain.factories.JsonFactory; import com.tibiawiki.domain.repositories.ArticleRepository; import org.json.JSONObject; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import java.util.List; @@ -15,10 +16,7 @@ @Component public class RetrieveBooks extends RetrieveAny { - private RetrieveBooks() { - // nothing to do, all dependencies are injected - } - + @Autowired public RetrieveBooks(ArticleRepository articleRepository, ArticleFactory articleFactory, JsonFactory jsonFactory) { super(articleRepository, articleFactory, jsonFactory); } diff --git a/src/main/java/com/tibiawiki/process/RetrieveBuildings.java b/src/main/java/com/tibiawiki/process/RetrieveBuildings.java index cd4098d..c0a00e7 100644 --- a/src/main/java/com/tibiawiki/process/RetrieveBuildings.java +++ b/src/main/java/com/tibiawiki/process/RetrieveBuildings.java @@ -5,6 +5,7 @@ import com.tibiawiki.domain.factories.JsonFactory; import com.tibiawiki.domain.repositories.ArticleRepository; import org.json.JSONObject; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import java.util.List; @@ -15,10 +16,7 @@ @Component public class RetrieveBuildings extends RetrieveAny { - private RetrieveBuildings() { - // nothing to do, all dependencies are injected - } - + @Autowired public RetrieveBuildings(ArticleRepository articleRepository, ArticleFactory articleFactory, JsonFactory jsonFactory) { super(articleRepository, articleFactory, jsonFactory); } diff --git a/src/main/java/com/tibiawiki/process/RetrieveCorpses.java b/src/main/java/com/tibiawiki/process/RetrieveCorpses.java index f07e06f..a75af64 100644 --- a/src/main/java/com/tibiawiki/process/RetrieveCorpses.java +++ b/src/main/java/com/tibiawiki/process/RetrieveCorpses.java @@ -5,6 +5,7 @@ import com.tibiawiki.domain.factories.JsonFactory; import com.tibiawiki.domain.repositories.ArticleRepository; import org.json.JSONObject; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import java.util.List; @@ -15,10 +16,7 @@ @Component public class RetrieveCorpses extends RetrieveAny { - private RetrieveCorpses() { - // nothing to do, all dependencies are injected - } - + @Autowired public RetrieveCorpses(ArticleRepository articleRepository, ArticleFactory articleFactory, JsonFactory jsonFactory) { super(articleRepository, articleFactory, jsonFactory); } diff --git a/src/main/java/com/tibiawiki/process/RetrieveCreatures.java b/src/main/java/com/tibiawiki/process/RetrieveCreatures.java index 0858bb5..a6a6d54 100644 --- a/src/main/java/com/tibiawiki/process/RetrieveCreatures.java +++ b/src/main/java/com/tibiawiki/process/RetrieveCreatures.java @@ -5,6 +5,7 @@ import com.tibiawiki.domain.factories.JsonFactory; import com.tibiawiki.domain.repositories.ArticleRepository; import org.json.JSONObject; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import java.util.List; @@ -15,10 +16,7 @@ @Component public class RetrieveCreatures extends RetrieveAny { - private RetrieveCreatures() { - // nothing to do, all dependencies are injected - } - + @Autowired public RetrieveCreatures(ArticleRepository articleRepository, ArticleFactory articleFactory, JsonFactory jsonFactory) { super(articleRepository, articleFactory, jsonFactory); } diff --git a/src/main/java/com/tibiawiki/process/RetrieveEffects.java b/src/main/java/com/tibiawiki/process/RetrieveEffects.java index 712362f..baf3ff0 100644 --- a/src/main/java/com/tibiawiki/process/RetrieveEffects.java +++ b/src/main/java/com/tibiawiki/process/RetrieveEffects.java @@ -5,6 +5,7 @@ import com.tibiawiki.domain.factories.JsonFactory; import com.tibiawiki.domain.repositories.ArticleRepository; import org.json.JSONObject; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import java.util.List; @@ -15,10 +16,7 @@ @Component public class RetrieveEffects extends RetrieveAny { - private RetrieveEffects() { - // nothing to do, all dependencies are injected - } - + @Autowired public RetrieveEffects(ArticleRepository articleRepository, ArticleFactory articleFactory, JsonFactory jsonFactory) { super(articleRepository, articleFactory, jsonFactory); } diff --git a/src/main/java/com/tibiawiki/process/RetrieveHuntingPlaces.java b/src/main/java/com/tibiawiki/process/RetrieveHuntingPlaces.java index a3dc68f..6507f27 100644 --- a/src/main/java/com/tibiawiki/process/RetrieveHuntingPlaces.java +++ b/src/main/java/com/tibiawiki/process/RetrieveHuntingPlaces.java @@ -5,6 +5,7 @@ import com.tibiawiki.domain.factories.JsonFactory; import com.tibiawiki.domain.repositories.ArticleRepository; import org.json.JSONObject; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import java.util.List; @@ -15,10 +16,7 @@ @Component public class RetrieveHuntingPlaces extends RetrieveAny { - private RetrieveHuntingPlaces() { - // nothing to do, all dependencies are injected - } - + @Autowired public RetrieveHuntingPlaces(ArticleRepository articleRepository, ArticleFactory articleFactory, JsonFactory jsonFactory) { super(articleRepository, articleFactory, jsonFactory); } diff --git a/src/main/java/com/tibiawiki/process/RetrieveItems.java b/src/main/java/com/tibiawiki/process/RetrieveItems.java index e614801..d379430 100644 --- a/src/main/java/com/tibiawiki/process/RetrieveItems.java +++ b/src/main/java/com/tibiawiki/process/RetrieveItems.java @@ -5,6 +5,7 @@ import com.tibiawiki.domain.factories.JsonFactory; import com.tibiawiki.domain.repositories.ArticleRepository; import org.json.JSONObject; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import java.util.List; @@ -15,10 +16,7 @@ @Component public class RetrieveItems extends RetrieveAny { - private RetrieveItems() { - // nothing to do, all dependencies are injected - } - + @Autowired public RetrieveItems(ArticleRepository articleRepository, ArticleFactory articleFactory, JsonFactory jsonFactory) { super(articleRepository, articleFactory, jsonFactory); } diff --git a/src/main/java/com/tibiawiki/process/RetrieveKeys.java b/src/main/java/com/tibiawiki/process/RetrieveKeys.java index cc98a07..314d1ef 100644 --- a/src/main/java/com/tibiawiki/process/RetrieveKeys.java +++ b/src/main/java/com/tibiawiki/process/RetrieveKeys.java @@ -5,6 +5,7 @@ import com.tibiawiki.domain.factories.JsonFactory; import com.tibiawiki.domain.repositories.ArticleRepository; import org.json.JSONObject; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import java.util.List; @@ -15,10 +16,7 @@ @Component public class RetrieveKeys extends RetrieveAny { - private RetrieveKeys() { - // nothing to do, all dependencies are injected - } - + @Autowired public RetrieveKeys(ArticleRepository articleRepository, ArticleFactory articleFactory, JsonFactory jsonFactory) { super(articleRepository, articleFactory, jsonFactory); } diff --git a/src/main/java/com/tibiawiki/process/RetrieveLocations.java b/src/main/java/com/tibiawiki/process/RetrieveLocations.java index 65f3f1b..fe186af 100644 --- a/src/main/java/com/tibiawiki/process/RetrieveLocations.java +++ b/src/main/java/com/tibiawiki/process/RetrieveLocations.java @@ -5,6 +5,7 @@ import com.tibiawiki.domain.factories.JsonFactory; import com.tibiawiki.domain.repositories.ArticleRepository; import org.json.JSONObject; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import java.util.List; @@ -15,10 +16,7 @@ @Component public class RetrieveLocations extends RetrieveAny { - private RetrieveLocations() { - // nothing to do, all dependencies are injected - } - + @Autowired public RetrieveLocations(ArticleRepository articleRepository, ArticleFactory articleFactory, JsonFactory jsonFactory) { super(articleRepository, articleFactory, jsonFactory); } diff --git a/src/main/java/com/tibiawiki/process/RetrieveMissiles.java b/src/main/java/com/tibiawiki/process/RetrieveMissiles.java new file mode 100644 index 0000000..3c4a218 --- /dev/null +++ b/src/main/java/com/tibiawiki/process/RetrieveMissiles.java @@ -0,0 +1,40 @@ +package com.tibiawiki.process; + +import com.tibiawiki.domain.enums.InfoboxTemplate; +import com.tibiawiki.domain.factories.ArticleFactory; +import com.tibiawiki.domain.factories.JsonFactory; +import com.tibiawiki.domain.repositories.ArticleRepository; +import org.json.JSONObject; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +import java.util.List; +import java.util.Optional; +import java.util.stream.Collectors; +import java.util.stream.Stream; + +@Component +public class RetrieveMissiles extends RetrieveAny { + + @Autowired + public RetrieveMissiles(ArticleRepository articleRepository, ArticleFactory articleFactory, JsonFactory jsonFactory) { + super(articleRepository, articleFactory, jsonFactory); + } + + public List getMissilesList() { + final List effectsCategory = articleRepository.getPageNamesFromCategory(InfoboxTemplate.MISSILE.getCategoryName()); + final List listsCategory = articleRepository.getPageNamesFromCategory(CATEGORY_LISTS); + + return effectsCategory.stream() + .filter(page -> !listsCategory.contains(page)) + .collect(Collectors.toList()); + } + + public Stream getMissilesJSON() { + return getArticlesFromInfoboxTemplateAsJSON(getMissilesList()); + } + + public Optional getMissileJSON(String pageName) { + return super.getArticleAsJSON(pageName); + } +} diff --git a/src/main/java/com/tibiawiki/process/RetrieveMounts.java b/src/main/java/com/tibiawiki/process/RetrieveMounts.java index 4d2fc76..83da9aa 100644 --- a/src/main/java/com/tibiawiki/process/RetrieveMounts.java +++ b/src/main/java/com/tibiawiki/process/RetrieveMounts.java @@ -5,6 +5,7 @@ import com.tibiawiki.domain.factories.JsonFactory; import com.tibiawiki.domain.repositories.ArticleRepository; import org.json.JSONObject; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import java.util.List; @@ -15,10 +16,7 @@ @Component public class RetrieveMounts extends RetrieveAny { - private RetrieveMounts() { - // nothing to do, all dependencies are injected - } - + @Autowired public RetrieveMounts(ArticleRepository articleRepository, ArticleFactory articleFactory, JsonFactory jsonFactory) { super(articleRepository, articleFactory, jsonFactory); } diff --git a/src/main/java/com/tibiawiki/process/RetrieveNPCs.java b/src/main/java/com/tibiawiki/process/RetrieveNPCs.java index 3933f82..848ae3a 100644 --- a/src/main/java/com/tibiawiki/process/RetrieveNPCs.java +++ b/src/main/java/com/tibiawiki/process/RetrieveNPCs.java @@ -5,6 +5,7 @@ import com.tibiawiki.domain.factories.JsonFactory; import com.tibiawiki.domain.repositories.ArticleRepository; import org.json.JSONObject; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import java.util.List; @@ -15,10 +16,7 @@ @Component public class RetrieveNPCs extends RetrieveAny { - private RetrieveNPCs() { - // nothing to do, all dependencies are injected - } - + @Autowired public RetrieveNPCs(ArticleRepository articleRepository, ArticleFactory articleFactory, JsonFactory jsonFactory) { super(articleRepository, articleFactory, jsonFactory); } diff --git a/src/main/java/com/tibiawiki/process/RetrieveObjects.java b/src/main/java/com/tibiawiki/process/RetrieveObjects.java index be5e4cb..1adb5e0 100644 --- a/src/main/java/com/tibiawiki/process/RetrieveObjects.java +++ b/src/main/java/com/tibiawiki/process/RetrieveObjects.java @@ -5,6 +5,7 @@ import com.tibiawiki.domain.factories.JsonFactory; import com.tibiawiki.domain.repositories.ArticleRepository; import org.json.JSONObject; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import java.util.List; @@ -15,10 +16,7 @@ @Component public class RetrieveObjects extends RetrieveAny { - private RetrieveObjects() { - // nothing to do, all dependencies are injected - } - + @Autowired public RetrieveObjects(ArticleRepository articleRepository, ArticleFactory articleFactory, JsonFactory jsonFactory) { super(articleRepository, articleFactory, jsonFactory); } diff --git a/src/main/java/com/tibiawiki/process/RetrieveOutfits.java b/src/main/java/com/tibiawiki/process/RetrieveOutfits.java index cebd9e9..080565b 100644 --- a/src/main/java/com/tibiawiki/process/RetrieveOutfits.java +++ b/src/main/java/com/tibiawiki/process/RetrieveOutfits.java @@ -5,6 +5,7 @@ import com.tibiawiki.domain.factories.JsonFactory; import com.tibiawiki.domain.repositories.ArticleRepository; import org.json.JSONObject; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import java.util.List; @@ -15,10 +16,7 @@ @Component public class RetrieveOutfits extends RetrieveAny { - private RetrieveOutfits() { - // nothing to do, all dependencies are injected - } - + @Autowired public RetrieveOutfits(ArticleRepository articleRepository, ArticleFactory articleFactory, JsonFactory jsonFactory) { super(articleRepository, articleFactory, jsonFactory); } diff --git a/src/main/java/com/tibiawiki/process/RetrieveQuests.java b/src/main/java/com/tibiawiki/process/RetrieveQuests.java index 2bfc238..191881d 100644 --- a/src/main/java/com/tibiawiki/process/RetrieveQuests.java +++ b/src/main/java/com/tibiawiki/process/RetrieveQuests.java @@ -5,6 +5,7 @@ import com.tibiawiki.domain.factories.JsonFactory; import com.tibiawiki.domain.repositories.ArticleRepository; import org.json.JSONObject; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import java.util.List; @@ -15,10 +16,7 @@ @Component public class RetrieveQuests extends RetrieveAny { - private RetrieveQuests() { - // nothing to do, all dependencies are injected - } - + @Autowired public RetrieveQuests(ArticleRepository articleRepository, ArticleFactory articleFactory, JsonFactory jsonFactory) { super(articleRepository, articleFactory, jsonFactory); } diff --git a/src/main/java/com/tibiawiki/process/RetrieveSpells.java b/src/main/java/com/tibiawiki/process/RetrieveSpells.java index 4a5919e..7a7d1b7 100644 --- a/src/main/java/com/tibiawiki/process/RetrieveSpells.java +++ b/src/main/java/com/tibiawiki/process/RetrieveSpells.java @@ -5,6 +5,7 @@ import com.tibiawiki.domain.factories.JsonFactory; import com.tibiawiki.domain.repositories.ArticleRepository; import org.json.JSONObject; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import java.util.List; @@ -15,10 +16,7 @@ @Component public class RetrieveSpells extends RetrieveAny { - private RetrieveSpells() { - // nothing to do, all dependencies are injected - } - + @Autowired public RetrieveSpells(ArticleRepository articleRepository, ArticleFactory articleFactory, JsonFactory jsonFactory) { super(articleRepository, articleFactory, jsonFactory); } diff --git a/src/main/java/com/tibiawiki/process/RetrieveStreets.java b/src/main/java/com/tibiawiki/process/RetrieveStreets.java index b4b9c52..f96e1cc 100644 --- a/src/main/java/com/tibiawiki/process/RetrieveStreets.java +++ b/src/main/java/com/tibiawiki/process/RetrieveStreets.java @@ -5,6 +5,7 @@ import com.tibiawiki.domain.factories.JsonFactory; import com.tibiawiki.domain.repositories.ArticleRepository; import org.json.JSONObject; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import java.util.List; @@ -15,10 +16,7 @@ @Component public class RetrieveStreets extends RetrieveAny { - private RetrieveStreets() { - // nothing to do, all dependencies are injected - } - + @Autowired public RetrieveStreets(ArticleRepository articleRepository, ArticleFactory articleFactory, JsonFactory jsonFactory) { super(articleRepository, articleFactory, jsonFactory); } diff --git a/src/main/java/com/tibiawiki/serviceinterface/AchievementsResource.java b/src/main/java/com/tibiawiki/serviceinterface/AchievementsResource.java index 84c66e1..bc1a915 100644 --- a/src/main/java/com/tibiawiki/serviceinterface/AchievementsResource.java +++ b/src/main/java/com/tibiawiki/serviceinterface/AchievementsResource.java @@ -29,13 +29,13 @@ @Path("/achievements") public class AchievementsResource { - @Autowired private RetrieveAchievements retrieveAchievements; - @Autowired private ModifyAchievement modifyAchievement; - private AchievementsResource() { - // nothing to do, all dependencies are injected + @Autowired + private AchievementsResource(RetrieveAchievements retrieveAchievements, ModifyAchievement modifyAchievement) { + this.retrieveAchievements = retrieveAchievements; + this.modifyAchievement = modifyAchievement; } @GET diff --git a/src/main/java/com/tibiawiki/serviceinterface/BooksResource.java b/src/main/java/com/tibiawiki/serviceinterface/BooksResource.java index 61caac7..4480328 100644 --- a/src/main/java/com/tibiawiki/serviceinterface/BooksResource.java +++ b/src/main/java/com/tibiawiki/serviceinterface/BooksResource.java @@ -19,11 +19,11 @@ @Path("/") public class BooksResource { - @Autowired private RetrieveBooks retrieveBooks; - private BooksResource() { - // nothing to do, all dependencies are injected + @Autowired + private BooksResource(RetrieveBooks retrieveBooks) { + this.retrieveBooks = retrieveBooks; } @GET diff --git a/src/main/java/com/tibiawiki/serviceinterface/BuildingsResource.java b/src/main/java/com/tibiawiki/serviceinterface/BuildingsResource.java index d793482..a4cb39b 100644 --- a/src/main/java/com/tibiawiki/serviceinterface/BuildingsResource.java +++ b/src/main/java/com/tibiawiki/serviceinterface/BuildingsResource.java @@ -19,11 +19,11 @@ @Path("/") public class BuildingsResource { - @Autowired private RetrieveBuildings retrieveBuildings; - private BuildingsResource() { - // nothing to do, all dependencies are injected + @Autowired + private BuildingsResource(RetrieveBuildings retrieveBuildings) { + this.retrieveBuildings = retrieveBuildings; } @GET diff --git a/src/main/java/com/tibiawiki/serviceinterface/CorpsesResource.java b/src/main/java/com/tibiawiki/serviceinterface/CorpsesResource.java index a8195be..3d78548 100644 --- a/src/main/java/com/tibiawiki/serviceinterface/CorpsesResource.java +++ b/src/main/java/com/tibiawiki/serviceinterface/CorpsesResource.java @@ -6,7 +6,11 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; -import javax.ws.rs.*; +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; +import javax.ws.rs.Produces; +import javax.ws.rs.QueryParam; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; @@ -15,11 +19,11 @@ @Path("/") public class CorpsesResource { - @Autowired private RetrieveCorpses retrieveCorpses; - private CorpsesResource() { - // nothing to do, all dependencies are injected + @Autowired + private CorpsesResource(RetrieveCorpses retrieveCorpses) { + this.retrieveCorpses = retrieveCorpses; } @GET diff --git a/src/main/java/com/tibiawiki/serviceinterface/CreaturesResource.java b/src/main/java/com/tibiawiki/serviceinterface/CreaturesResource.java index 735f4d9..ebf8774 100644 --- a/src/main/java/com/tibiawiki/serviceinterface/CreaturesResource.java +++ b/src/main/java/com/tibiawiki/serviceinterface/CreaturesResource.java @@ -6,7 +6,11 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; -import javax.ws.rs.*; +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; +import javax.ws.rs.Produces; +import javax.ws.rs.QueryParam; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; @@ -15,11 +19,11 @@ @Path("/") public class CreaturesResource { - @Autowired private RetrieveCreatures retrieveCreatures; - private CreaturesResource() { - // nothing to do, all dependencies are injected + @Autowired + private CreaturesResource(RetrieveCreatures retrieveCreatures) { + this.retrieveCreatures = retrieveCreatures; } @GET diff --git a/src/main/java/com/tibiawiki/serviceinterface/EffectsResource.java b/src/main/java/com/tibiawiki/serviceinterface/EffectsResource.java index 9d822d7..9d24076 100644 --- a/src/main/java/com/tibiawiki/serviceinterface/EffectsResource.java +++ b/src/main/java/com/tibiawiki/serviceinterface/EffectsResource.java @@ -19,11 +19,11 @@ @Path("/") public class EffectsResource { - @Autowired private RetrieveEffects retrieveEffects; - private EffectsResource() { - // nothing to do, all dependencies are injected + @Autowired + private EffectsResource(RetrieveEffects retrieveEffects) { + this.retrieveEffects = retrieveEffects; } @GET diff --git a/src/main/java/com/tibiawiki/serviceinterface/HuntingPlacesResource.java b/src/main/java/com/tibiawiki/serviceinterface/HuntingPlacesResource.java index 93b47c3..05c2da8 100644 --- a/src/main/java/com/tibiawiki/serviceinterface/HuntingPlacesResource.java +++ b/src/main/java/com/tibiawiki/serviceinterface/HuntingPlacesResource.java @@ -19,11 +19,11 @@ @Path("/") public class HuntingPlacesResource { - @Autowired private RetrieveHuntingPlaces retrieveHuntingPlaces; - private HuntingPlacesResource() { - // nothing to do, all dependencies are injected + @Autowired + private HuntingPlacesResource(RetrieveHuntingPlaces retrieveHuntingPlaces) { + this.retrieveHuntingPlaces = retrieveHuntingPlaces; } @GET diff --git a/src/main/java/com/tibiawiki/serviceinterface/ItemsResource.java b/src/main/java/com/tibiawiki/serviceinterface/ItemsResource.java index a41de76..bcb78c1 100644 --- a/src/main/java/com/tibiawiki/serviceinterface/ItemsResource.java +++ b/src/main/java/com/tibiawiki/serviceinterface/ItemsResource.java @@ -19,11 +19,11 @@ @Path("/") public class ItemsResource { - @Autowired private RetrieveItems retrieveItems; - private ItemsResource() { - // nothing to do, all dependencies are injected + @Autowired + private ItemsResource(RetrieveItems retrieveItems) { + this.retrieveItems = retrieveItems; } @GET diff --git a/src/main/java/com/tibiawiki/serviceinterface/KeysResource.java b/src/main/java/com/tibiawiki/serviceinterface/KeysResource.java index 6a94f7d..2d0146c 100644 --- a/src/main/java/com/tibiawiki/serviceinterface/KeysResource.java +++ b/src/main/java/com/tibiawiki/serviceinterface/KeysResource.java @@ -19,11 +19,11 @@ @Path("/") public class KeysResource { - @Autowired private RetrieveKeys retrieveKeys; - private KeysResource() { - // nothing to do, all dependencies are injected + @Autowired + private KeysResource(RetrieveKeys retrieveKeys) { + this.retrieveKeys = retrieveKeys; } @GET diff --git a/src/main/java/com/tibiawiki/serviceinterface/LocationsResource.java b/src/main/java/com/tibiawiki/serviceinterface/LocationsResource.java index 151d063..a0eae57 100644 --- a/src/main/java/com/tibiawiki/serviceinterface/LocationsResource.java +++ b/src/main/java/com/tibiawiki/serviceinterface/LocationsResource.java @@ -6,7 +6,11 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; -import javax.ws.rs.*; +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; +import javax.ws.rs.Produces; +import javax.ws.rs.QueryParam; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; @@ -15,11 +19,11 @@ @Path("/") public class LocationsResource { - @Autowired private RetrieveLocations retrieveLocations; - private LocationsResource() { - // nothing to do, all dependencies are injected + @Autowired + private LocationsResource(RetrieveLocations retrieveLocations) { + this.retrieveLocations = retrieveLocations; } @GET diff --git a/src/main/java/com/tibiawiki/serviceinterface/MissilesResource.java b/src/main/java/com/tibiawiki/serviceinterface/MissilesResource.java new file mode 100644 index 0000000..1559010 --- /dev/null +++ b/src/main/java/com/tibiawiki/serviceinterface/MissilesResource.java @@ -0,0 +1,54 @@ +package com.tibiawiki.serviceinterface; + +import com.tibiawiki.process.RetrieveMissiles; +import io.swagger.annotations.Api; +import org.json.JSONObject; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; +import javax.ws.rs.Produces; +import javax.ws.rs.QueryParam; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; + +@Component +@Api(value = "Missiles") +@Path("/") +public class MissilesResource { + + private RetrieveMissiles retrieveMissiles; + + @Autowired + private MissilesResource(RetrieveMissiles retrieveMissiles) { + this.retrieveMissiles = retrieveMissiles; + } + + @GET + @Path("/missiles") + @Produces(MediaType.APPLICATION_JSON) + public Response getMissiles(@QueryParam("expand") Boolean expand) { + return Response.ok() + .entity(expand != null && expand + ? retrieveMissiles.getMissilesJSON().map(JSONObject::toMap) + : retrieveMissiles.getMissilesList() + ) + .header("Access-Control-Allow-Origin", "*") + .build(); + } + + @GET + @Path("/missiles/{name}") + @Produces(MediaType.APPLICATION_JSON) + public Response getMissilesByName(@PathParam("name") String name) { + return retrieveMissiles.getMissileJSON(name) + .map(a -> Response.ok() + .entity(a.toString(2)) + .header("Access-Control-Allow-Origin", "*") + .build()) + .orElseGet(() -> Response.status(Response.Status.NOT_FOUND) + .build()); + } +} diff --git a/src/main/java/com/tibiawiki/serviceinterface/MountsResource.java b/src/main/java/com/tibiawiki/serviceinterface/MountsResource.java index 4555e07..25908f7 100644 --- a/src/main/java/com/tibiawiki/serviceinterface/MountsResource.java +++ b/src/main/java/com/tibiawiki/serviceinterface/MountsResource.java @@ -6,7 +6,11 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; -import javax.ws.rs.*; +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; +import javax.ws.rs.Produces; +import javax.ws.rs.QueryParam; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; @@ -15,11 +19,11 @@ @Path("/") public class MountsResource { - @Autowired private RetrieveMounts retrieveMounts; - private MountsResource() { - // nothing to do, all dependencies are injected + @Autowired + private MountsResource(RetrieveMounts retrieveMounts) { + this.retrieveMounts = retrieveMounts; } @GET diff --git a/src/main/java/com/tibiawiki/serviceinterface/NPCsResource.java b/src/main/java/com/tibiawiki/serviceinterface/NPCsResource.java index 4fc7434..f342210 100644 --- a/src/main/java/com/tibiawiki/serviceinterface/NPCsResource.java +++ b/src/main/java/com/tibiawiki/serviceinterface/NPCsResource.java @@ -6,7 +6,11 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; -import javax.ws.rs.*; +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; +import javax.ws.rs.Produces; +import javax.ws.rs.QueryParam; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; @@ -15,11 +19,11 @@ @Path("/") public class NPCsResource { - @Autowired private RetrieveNPCs retrieveNPCs; - private NPCsResource() { - // nothing to do, all dependencies are injected + @Autowired + private NPCsResource(RetrieveNPCs retrieveNPCs) { + this.retrieveNPCs = retrieveNPCs; } @GET diff --git a/src/main/java/com/tibiawiki/serviceinterface/ObjectsResource.java b/src/main/java/com/tibiawiki/serviceinterface/ObjectsResource.java index 23aaafb..f17cea2 100644 --- a/src/main/java/com/tibiawiki/serviceinterface/ObjectsResource.java +++ b/src/main/java/com/tibiawiki/serviceinterface/ObjectsResource.java @@ -6,7 +6,11 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; -import javax.ws.rs.*; +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; +import javax.ws.rs.Produces; +import javax.ws.rs.QueryParam; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; @@ -15,11 +19,11 @@ @Path("/") public class ObjectsResource { - @Autowired private RetrieveObjects retrieveObjects; - private ObjectsResource() { - // nothing to do, all dependencies are injected + @Autowired + private ObjectsResource(RetrieveObjects retrieveObjects) { + this.retrieveObjects = retrieveObjects; } @GET diff --git a/src/main/java/com/tibiawiki/serviceinterface/OutfitsResource.java b/src/main/java/com/tibiawiki/serviceinterface/OutfitsResource.java index f08a072..a531d3a 100644 --- a/src/main/java/com/tibiawiki/serviceinterface/OutfitsResource.java +++ b/src/main/java/com/tibiawiki/serviceinterface/OutfitsResource.java @@ -6,7 +6,11 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; -import javax.ws.rs.*; +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; +import javax.ws.rs.Produces; +import javax.ws.rs.QueryParam; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; @@ -15,11 +19,11 @@ @Path("/") public class OutfitsResource { - @Autowired private RetrieveOutfits retrieveOutfits; - private OutfitsResource() { - // nothing to do, all dependencies are injected + @Autowired + private OutfitsResource(RetrieveOutfits retrieveOutfits) { + this.retrieveOutfits = retrieveOutfits; } @GET diff --git a/src/main/java/com/tibiawiki/serviceinterface/QuestsResource.java b/src/main/java/com/tibiawiki/serviceinterface/QuestsResource.java index 1393202..c43780f 100644 --- a/src/main/java/com/tibiawiki/serviceinterface/QuestsResource.java +++ b/src/main/java/com/tibiawiki/serviceinterface/QuestsResource.java @@ -6,7 +6,11 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; -import javax.ws.rs.*; +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; +import javax.ws.rs.Produces; +import javax.ws.rs.QueryParam; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; @@ -15,11 +19,11 @@ @Path("/") public class QuestsResource { - @Autowired private RetrieveQuests retrieveQuests; - private QuestsResource() { - // nothing to do, all dependencies are injected + @Autowired + private QuestsResource(RetrieveQuests retrieveQuests) { + this.retrieveQuests = retrieveQuests; } @GET diff --git a/src/main/java/com/tibiawiki/serviceinterface/SpellsResource.java b/src/main/java/com/tibiawiki/serviceinterface/SpellsResource.java index 964b9d9..7d1116b 100644 --- a/src/main/java/com/tibiawiki/serviceinterface/SpellsResource.java +++ b/src/main/java/com/tibiawiki/serviceinterface/SpellsResource.java @@ -6,7 +6,11 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; -import javax.ws.rs.*; +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; +import javax.ws.rs.Produces; +import javax.ws.rs.QueryParam; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; @@ -15,11 +19,11 @@ @Path("/") public class SpellsResource { - @Autowired private RetrieveSpells retrieveSpells; - private SpellsResource() { - // nothing to do, all dependencies are injected + @Autowired + private SpellsResource(RetrieveSpells retrieveSpells) { + this.retrieveSpells = retrieveSpells; } @GET diff --git a/src/main/java/com/tibiawiki/serviceinterface/StreetsResource.java b/src/main/java/com/tibiawiki/serviceinterface/StreetsResource.java index da75fec..9423865 100644 --- a/src/main/java/com/tibiawiki/serviceinterface/StreetsResource.java +++ b/src/main/java/com/tibiawiki/serviceinterface/StreetsResource.java @@ -19,11 +19,11 @@ @Path("/") public class StreetsResource { - @Autowired private RetrieveStreets retrieveStreets; - private StreetsResource() { - // nothing to do, all dependencies are injected + @Autowired + private StreetsResource(RetrieveStreets retrieveStreets) { + this.retrieveStreets = retrieveStreets; } @GET diff --git a/src/main/java/com/tibiawiki/serviceinterface/config/JerseyConfig.java b/src/main/java/com/tibiawiki/serviceinterface/config/JerseyConfig.java index 76fd60a..654f855 100644 --- a/src/main/java/com/tibiawiki/serviceinterface/config/JerseyConfig.java +++ b/src/main/java/com/tibiawiki/serviceinterface/config/JerseyConfig.java @@ -1,6 +1,23 @@ package com.tibiawiki.serviceinterface.config; -import com.tibiawiki.serviceinterface.*; +import com.tibiawiki.serviceinterface.AchievementsResource; +import com.tibiawiki.serviceinterface.BooksResource; +import com.tibiawiki.serviceinterface.BuildingsResource; +import com.tibiawiki.serviceinterface.CorpsesResource; +import com.tibiawiki.serviceinterface.CreaturesResource; +import com.tibiawiki.serviceinterface.EffectsResource; +import com.tibiawiki.serviceinterface.HuntingPlacesResource; +import com.tibiawiki.serviceinterface.ItemsResource; +import com.tibiawiki.serviceinterface.KeysResource; +import com.tibiawiki.serviceinterface.LocationsResource; +import com.tibiawiki.serviceinterface.MissilesResource; +import com.tibiawiki.serviceinterface.MountsResource; +import com.tibiawiki.serviceinterface.NPCsResource; +import com.tibiawiki.serviceinterface.ObjectsResource; +import com.tibiawiki.serviceinterface.OutfitsResource; +import com.tibiawiki.serviceinterface.QuestsResource; +import com.tibiawiki.serviceinterface.SpellsResource; +import com.tibiawiki.serviceinterface.StreetsResource; import io.swagger.jaxrs.config.BeanConfig; import io.swagger.jaxrs.listing.ApiListingResource; import io.swagger.jaxrs.listing.SwaggerSerializers; @@ -37,6 +54,7 @@ private void registerEndpoints() { register(HuntingPlacesResource.class); register(ItemsResource.class); register(KeysResource.class); + register(MissilesResource.class); register(MountsResource.class); register(NPCsResource.class); register(ObjectsResource.class); From 311ea8a1a2a5918e7a46e97ee3b3a2c926db0d24 Mon Sep 17 00:00:00 2001 From: Benjamin Komen Date: Sat, 8 Dec 2018 12:54:56 +0100 Subject: [PATCH 15/19] Adding PUT methods to all resources. --- .../tibiawiki/domain/objects/WikiObject.java | 3 ++ ...{ModifyAchievement.java => ModifyAny.java} | 34 +++++++++---------- .../AchievementsResource.java | 10 +++--- .../serviceinterface/BooksResource.java | 31 ++++++++++++++++- .../serviceinterface/BuildingsResource.java | 31 ++++++++++++++++- .../serviceinterface/CorpsesResource.java | 31 ++++++++++++++++- .../serviceinterface/CreaturesResource.java | 31 ++++++++++++++++- .../serviceinterface/EffectsResource.java | 31 ++++++++++++++++- .../HuntingPlacesResource.java | 31 ++++++++++++++++- .../serviceinterface/ItemsResource.java | 31 ++++++++++++++++- .../serviceinterface/KeysResource.java | 31 ++++++++++++++++- .../serviceinterface/LocationsResource.java | 31 ++++++++++++++++- .../serviceinterface/MissilesResource.java | 31 ++++++++++++++++- .../serviceinterface/MountsResource.java | 31 ++++++++++++++++- .../serviceinterface/NPCsResource.java | 31 ++++++++++++++++- .../serviceinterface/ObjectsResource.java | 31 ++++++++++++++++- .../serviceinterface/OutfitsResource.java | 31 ++++++++++++++++- .../serviceinterface/QuestsResource.java | 31 ++++++++++++++++- .../serviceinterface/SpellsResource.java | 31 ++++++++++++++++- .../serviceinterface/StreetsResource.java | 31 ++++++++++++++++- 20 files changed, 535 insertions(+), 39 deletions(-) rename src/main/java/com/tibiawiki/process/{ModifyAchievement.java => ModifyAny.java} (58%) diff --git a/src/main/java/com/tibiawiki/domain/objects/WikiObject.java b/src/main/java/com/tibiawiki/domain/objects/WikiObject.java index 5daac60..7df0c49 100644 --- a/src/main/java/com/tibiawiki/domain/objects/WikiObject.java +++ b/src/main/java/com/tibiawiki/domain/objects/WikiObject.java @@ -14,6 +14,7 @@ @Getter public abstract class WikiObject implements Validatable { + private final String templateType; private final String name; private final Article article; private final String actualname; @@ -24,6 +25,7 @@ public abstract class WikiObject implements Validatable { private final Status status; protected WikiObject() { + templateType = null; name = null; article = null; actualname = null; @@ -36,6 +38,7 @@ protected WikiObject() { public WikiObject(String name, Article article, String actualname, String plural, String implemented, String notes, String history, Status status) { + this.templateType = null; this.name = name; this.article = article; this.actualname = actualname; diff --git a/src/main/java/com/tibiawiki/process/ModifyAchievement.java b/src/main/java/com/tibiawiki/process/ModifyAny.java similarity index 58% rename from src/main/java/com/tibiawiki/process/ModifyAchievement.java rename to src/main/java/com/tibiawiki/process/ModifyAny.java index 6597f4c..5dac376 100644 --- a/src/main/java/com/tibiawiki/process/ModifyAchievement.java +++ b/src/main/java/com/tibiawiki/process/ModifyAny.java @@ -3,7 +3,7 @@ import com.tibiawiki.domain.factories.ArticleFactory; import com.tibiawiki.domain.factories.JsonFactory; import com.tibiawiki.domain.factories.WikiObjectFactory; -import com.tibiawiki.domain.objects.Achievement; +import com.tibiawiki.domain.objects.WikiObject; import com.tibiawiki.domain.objects.validation.ValidationException; import com.tibiawiki.domain.objects.validation.ValidationResult; import com.tibiawiki.domain.repositories.ArticleRepository; @@ -14,13 +14,13 @@ import java.util.List; /** - * 1. Validate modified Achievement + * 1. Validate modified WikiObject * 2. Get current wikipage * 3. Replace infobox part of template with newly made infobox part of template * 4. Edit the wiki (via a repository) */ @Component -public class ModifyAchievement { +public class ModifyAny { private WikiObjectFactory wikiObjectFactory; private JsonFactory jsonFactory; @@ -28,33 +28,33 @@ public class ModifyAchievement { private ArticleRepository articleRepository; @Autowired - private ModifyAchievement(WikiObjectFactory wikiObjectFactory, JsonFactory jsonFactory, ArticleFactory articleFactory, - ArticleRepository articleRepository) { + private ModifyAny(WikiObjectFactory wikiObjectFactory, JsonFactory jsonFactory, ArticleFactory articleFactory, + ArticleRepository articleRepository) { this.wikiObjectFactory = wikiObjectFactory; this.jsonFactory = jsonFactory; this.articleFactory = articleFactory; this.articleRepository = articleRepository; } - public Try modify(Achievement achievement, String editSummary) { - final String originalAchievement = articleRepository.getArticle(achievement.getName()); + public Try modify(WikiObject wikiObject, String editSummary) { + final String originalWikiObject = articleRepository.getArticle(wikiObject.getName()); - return validate(achievement) - .map(a -> wikiObjectFactory.createJSONObject(a, "Achievement")) - .map(json -> jsonFactory.convertJsonToInfoboxPartOfArticle(json, achievement.fieldOrder())) - .map(s -> articleFactory.insertInfoboxPartOfArticle(originalAchievement, s)) - .map(s -> articleRepository.modifyArticle(achievement.getName(), s, editSummary)) + return validate(wikiObject) + .map(wikiObj -> wikiObjectFactory.createJSONObject(wikiObj, wikiObj.getTemplateType())) + .map(json -> jsonFactory.convertJsonToInfoboxPartOfArticle(json, wikiObject.fieldOrder())) + .map(s -> articleFactory.insertInfoboxPartOfArticle(originalWikiObject, s)) + .map(s -> articleRepository.modifyArticle(wikiObject.getName(), s, editSummary)) .flatMap(b -> b - ? Try.success(achievement) - : Try.failure(new ValidationException("Unable to edit achievement.")) + ? Try.success(wikiObject) + : Try.failure(new ValidationException("Unable to edit wikiObject.")) ); } - private Try validate(Achievement achievement) { - final List validationResults = achievement.validate(); + private Try validate(WikiObject wikiObject) { + final List validationResults = wikiObject.validate(); return validationResults.isEmpty() - ? Try.success(achievement) + ? Try.success(wikiObject) : Try.failure(ValidationException.fromResults(validationResults)); } } diff --git a/src/main/java/com/tibiawiki/serviceinterface/AchievementsResource.java b/src/main/java/com/tibiawiki/serviceinterface/AchievementsResource.java index bc1a915..2a26650 100644 --- a/src/main/java/com/tibiawiki/serviceinterface/AchievementsResource.java +++ b/src/main/java/com/tibiawiki/serviceinterface/AchievementsResource.java @@ -2,7 +2,7 @@ import com.tibiawiki.domain.objects.Achievement; import com.tibiawiki.domain.objects.validation.ValidationException; -import com.tibiawiki.process.ModifyAchievement; +import com.tibiawiki.process.ModifyAny; import com.tibiawiki.process.RetrieveAchievements; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; @@ -30,12 +30,12 @@ public class AchievementsResource { private RetrieveAchievements retrieveAchievements; - private ModifyAchievement modifyAchievement; + private ModifyAny modifyAny; @Autowired - private AchievementsResource(RetrieveAchievements retrieveAchievements, ModifyAchievement modifyAchievement) { + private AchievementsResource(RetrieveAchievements retrieveAchievements, ModifyAny modifyAny) { this.retrieveAchievements = retrieveAchievements; - this.modifyAchievement = modifyAchievement; + this.modifyAny = modifyAny; } @GET @@ -82,7 +82,7 @@ public Response getAchievementsByName(@PathParam("name") String name) { @Produces(MediaType.APPLICATION_JSON) @Consumes(MediaType.APPLICATION_JSON) public Response putAchievement(Achievement achievement, @HeaderParam("X-WIKI-Edit-Summary") String editSummary) { - return modifyAchievement.modify(achievement, editSummary) + return modifyAny.modify(achievement, editSummary) .map(a -> Response.ok() .entity(a) .header("Access-Control-Allow-Origin", "*") diff --git a/src/main/java/com/tibiawiki/serviceinterface/BooksResource.java b/src/main/java/com/tibiawiki/serviceinterface/BooksResource.java index 4480328..ea06d47 100644 --- a/src/main/java/com/tibiawiki/serviceinterface/BooksResource.java +++ b/src/main/java/com/tibiawiki/serviceinterface/BooksResource.java @@ -1,12 +1,20 @@ package com.tibiawiki.serviceinterface; +import com.tibiawiki.domain.objects.Book; +import com.tibiawiki.domain.objects.validation.ValidationException; +import com.tibiawiki.process.ModifyAny; import com.tibiawiki.process.RetrieveBooks; import io.swagger.annotations.Api; +import io.swagger.annotations.ApiResponse; +import io.swagger.annotations.ApiResponses; import org.json.JSONObject; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; +import javax.ws.rs.Consumes; import javax.ws.rs.GET; +import javax.ws.rs.HeaderParam; +import javax.ws.rs.PUT; import javax.ws.rs.Path; import javax.ws.rs.PathParam; import javax.ws.rs.Produces; @@ -20,10 +28,12 @@ public class BooksResource { private RetrieveBooks retrieveBooks; + private ModifyAny modifyAny; @Autowired - private BooksResource(RetrieveBooks retrieveBooks) { + private BooksResource(RetrieveBooks retrieveBooks, ModifyAny modifyAny) { this.retrieveBooks = retrieveBooks; + this.modifyAny = modifyAny; } @GET @@ -51,4 +61,23 @@ public Response getBooksByName(@PathParam("name") String name) { .orElseGet(() -> Response.status(Response.Status.NOT_FOUND) .build()); } + + @PUT + @ApiResponses(value = { + @ApiResponse(code = 200, message = "the changed book"), + @ApiResponse(code = 400, message = "the provided changed book is not valid"), + @ApiResponse(code = 401, message = "not authorized to edit without providing credentials") + }) + @Produces(MediaType.APPLICATION_JSON) + @Consumes(MediaType.APPLICATION_JSON) + public Response putBook(Book book, @HeaderParam("X-WIKI-Edit-Summary") String editSummary) { + return modifyAny.modify(book, editSummary) + .map(a -> Response.ok() + .entity(a) + .header("Access-Control-Allow-Origin", "*") + .build()) + .recover(ValidationException.class, e -> Response.status(Response.Status.BAD_REQUEST).entity(e.getMessage()).build()) + .recover(e -> Response.serverError().build()) + .get(); + } } diff --git a/src/main/java/com/tibiawiki/serviceinterface/BuildingsResource.java b/src/main/java/com/tibiawiki/serviceinterface/BuildingsResource.java index a4cb39b..3bb4804 100644 --- a/src/main/java/com/tibiawiki/serviceinterface/BuildingsResource.java +++ b/src/main/java/com/tibiawiki/serviceinterface/BuildingsResource.java @@ -1,12 +1,20 @@ package com.tibiawiki.serviceinterface; +import com.tibiawiki.domain.objects.Building; +import com.tibiawiki.domain.objects.validation.ValidationException; +import com.tibiawiki.process.ModifyAny; import com.tibiawiki.process.RetrieveBuildings; import io.swagger.annotations.Api; +import io.swagger.annotations.ApiResponse; +import io.swagger.annotations.ApiResponses; import org.json.JSONObject; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; +import javax.ws.rs.Consumes; import javax.ws.rs.GET; +import javax.ws.rs.HeaderParam; +import javax.ws.rs.PUT; import javax.ws.rs.Path; import javax.ws.rs.PathParam; import javax.ws.rs.Produces; @@ -20,10 +28,12 @@ public class BuildingsResource { private RetrieveBuildings retrieveBuildings; + private ModifyAny modifyAny; @Autowired - private BuildingsResource(RetrieveBuildings retrieveBuildings) { + private BuildingsResource(RetrieveBuildings retrieveBuildings, ModifyAny modifyAny) { this.retrieveBuildings = retrieveBuildings; + this.modifyAny = modifyAny; } @GET @@ -51,4 +61,23 @@ public Response getBuildingsByName(@PathParam("name") String name) { .orElseGet(() -> Response.status(Response.Status.NOT_FOUND) .build()); } + + @PUT + @ApiResponses(value = { + @ApiResponse(code = 200, message = "the changed building"), + @ApiResponse(code = 400, message = "the provided changed building is not valid"), + @ApiResponse(code = 401, message = "not authorized to edit without providing credentials") + }) + @Produces(MediaType.APPLICATION_JSON) + @Consumes(MediaType.APPLICATION_JSON) + public Response putBuilding(Building building, @HeaderParam("X-WIKI-Edit-Summary") String editSummary) { + return modifyAny.modify(building, editSummary) + .map(a -> Response.ok() + .entity(a) + .header("Access-Control-Allow-Origin", "*") + .build()) + .recover(ValidationException.class, e -> Response.status(Response.Status.BAD_REQUEST).entity(e.getMessage()).build()) + .recover(e -> Response.serverError().build()) + .get(); + } } diff --git a/src/main/java/com/tibiawiki/serviceinterface/CorpsesResource.java b/src/main/java/com/tibiawiki/serviceinterface/CorpsesResource.java index 3d78548..f30d344 100644 --- a/src/main/java/com/tibiawiki/serviceinterface/CorpsesResource.java +++ b/src/main/java/com/tibiawiki/serviceinterface/CorpsesResource.java @@ -1,12 +1,20 @@ package com.tibiawiki.serviceinterface; +import com.tibiawiki.domain.objects.Corpse; +import com.tibiawiki.domain.objects.validation.ValidationException; +import com.tibiawiki.process.ModifyAny; import com.tibiawiki.process.RetrieveCorpses; import io.swagger.annotations.Api; +import io.swagger.annotations.ApiResponse; +import io.swagger.annotations.ApiResponses; import org.json.JSONObject; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; +import javax.ws.rs.Consumes; import javax.ws.rs.GET; +import javax.ws.rs.HeaderParam; +import javax.ws.rs.PUT; import javax.ws.rs.Path; import javax.ws.rs.PathParam; import javax.ws.rs.Produces; @@ -20,10 +28,12 @@ public class CorpsesResource { private RetrieveCorpses retrieveCorpses; + private ModifyAny modifyAny; @Autowired - private CorpsesResource(RetrieveCorpses retrieveCorpses) { + private CorpsesResource(RetrieveCorpses retrieveCorpses, ModifyAny modifyAny) { this.retrieveCorpses = retrieveCorpses; + this.modifyAny = modifyAny; } @GET @@ -51,4 +61,23 @@ public Response getCorpsesByName(@PathParam("name") String name) { .orElseGet(() -> Response.status(Response.Status.NOT_FOUND) .build()); } + + @PUT + @ApiResponses(value = { + @ApiResponse(code = 200, message = "the changed corpse"), + @ApiResponse(code = 400, message = "the provided changed corpse is not valid"), + @ApiResponse(code = 401, message = "not authorized to edit without providing credentials") + }) + @Produces(MediaType.APPLICATION_JSON) + @Consumes(MediaType.APPLICATION_JSON) + public Response putCorpse(Corpse corpse, @HeaderParam("X-WIKI-Edit-Summary") String editSummary) { + return modifyAny.modify(corpse, editSummary) + .map(a -> Response.ok() + .entity(a) + .header("Access-Control-Allow-Origin", "*") + .build()) + .recover(ValidationException.class, e -> Response.status(Response.Status.BAD_REQUEST).entity(e.getMessage()).build()) + .recover(e -> Response.serverError().build()) + .get(); + } } diff --git a/src/main/java/com/tibiawiki/serviceinterface/CreaturesResource.java b/src/main/java/com/tibiawiki/serviceinterface/CreaturesResource.java index ebf8774..5ebb0b6 100644 --- a/src/main/java/com/tibiawiki/serviceinterface/CreaturesResource.java +++ b/src/main/java/com/tibiawiki/serviceinterface/CreaturesResource.java @@ -1,12 +1,20 @@ package com.tibiawiki.serviceinterface; +import com.tibiawiki.domain.objects.Creature; +import com.tibiawiki.domain.objects.validation.ValidationException; +import com.tibiawiki.process.ModifyAny; import com.tibiawiki.process.RetrieveCreatures; import io.swagger.annotations.Api; +import io.swagger.annotations.ApiResponse; +import io.swagger.annotations.ApiResponses; import org.json.JSONObject; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; +import javax.ws.rs.Consumes; import javax.ws.rs.GET; +import javax.ws.rs.HeaderParam; +import javax.ws.rs.PUT; import javax.ws.rs.Path; import javax.ws.rs.PathParam; import javax.ws.rs.Produces; @@ -20,10 +28,12 @@ public class CreaturesResource { private RetrieveCreatures retrieveCreatures; + private ModifyAny modifyAny; @Autowired - private CreaturesResource(RetrieveCreatures retrieveCreatures) { + private CreaturesResource(RetrieveCreatures retrieveCreatures, ModifyAny modifyAny) { this.retrieveCreatures = retrieveCreatures; + this.modifyAny = modifyAny; } @GET @@ -51,4 +61,23 @@ public Response getCreatureByName(@PathParam("name") String name) { .orElseGet(() -> Response.status(Response.Status.NOT_FOUND) .build()); } + + @PUT + @ApiResponses(value = { + @ApiResponse(code = 200, message = "the changed creature"), + @ApiResponse(code = 400, message = "the provided changed creature is not valid"), + @ApiResponse(code = 401, message = "not authorized to edit without providing credentials") + }) + @Produces(MediaType.APPLICATION_JSON) + @Consumes(MediaType.APPLICATION_JSON) + public Response putCreature(Creature creature, @HeaderParam("X-WIKI-Edit-Summary") String editSummary) { + return modifyAny.modify(creature, editSummary) + .map(a -> Response.ok() + .entity(a) + .header("Access-Control-Allow-Origin", "*") + .build()) + .recover(ValidationException.class, e -> Response.status(Response.Status.BAD_REQUEST).entity(e.getMessage()).build()) + .recover(e -> Response.serverError().build()) + .get(); + } } diff --git a/src/main/java/com/tibiawiki/serviceinterface/EffectsResource.java b/src/main/java/com/tibiawiki/serviceinterface/EffectsResource.java index 9d24076..70e1d15 100644 --- a/src/main/java/com/tibiawiki/serviceinterface/EffectsResource.java +++ b/src/main/java/com/tibiawiki/serviceinterface/EffectsResource.java @@ -1,12 +1,20 @@ package com.tibiawiki.serviceinterface; +import com.tibiawiki.domain.objects.Effect; +import com.tibiawiki.domain.objects.validation.ValidationException; +import com.tibiawiki.process.ModifyAny; import com.tibiawiki.process.RetrieveEffects; import io.swagger.annotations.Api; +import io.swagger.annotations.ApiResponse; +import io.swagger.annotations.ApiResponses; import org.json.JSONObject; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; +import javax.ws.rs.Consumes; import javax.ws.rs.GET; +import javax.ws.rs.HeaderParam; +import javax.ws.rs.PUT; import javax.ws.rs.Path; import javax.ws.rs.PathParam; import javax.ws.rs.Produces; @@ -20,10 +28,12 @@ public class EffectsResource { private RetrieveEffects retrieveEffects; + private ModifyAny modifyAny; @Autowired - private EffectsResource(RetrieveEffects retrieveEffects) { + private EffectsResource(RetrieveEffects retrieveEffects, ModifyAny modifyAny) { this.retrieveEffects = retrieveEffects; + this.modifyAny = modifyAny; } @GET @@ -51,4 +61,23 @@ public Response getEffectsByName(@PathParam("name") String name) { .orElseGet(() -> Response.status(Response.Status.NOT_FOUND) .build()); } + + @PUT + @ApiResponses(value = { + @ApiResponse(code = 200, message = "the changed effect"), + @ApiResponse(code = 400, message = "the provided changed effect is not valid"), + @ApiResponse(code = 401, message = "not authorized to edit without providing credentials") + }) + @Produces(MediaType.APPLICATION_JSON) + @Consumes(MediaType.APPLICATION_JSON) + public Response putEffect(Effect effect, @HeaderParam("X-WIKI-Edit-Summary") String editSummary) { + return modifyAny.modify(effect, editSummary) + .map(a -> Response.ok() + .entity(a) + .header("Access-Control-Allow-Origin", "*") + .build()) + .recover(ValidationException.class, e -> Response.status(Response.Status.BAD_REQUEST).entity(e.getMessage()).build()) + .recover(e -> Response.serverError().build()) + .get(); + } } diff --git a/src/main/java/com/tibiawiki/serviceinterface/HuntingPlacesResource.java b/src/main/java/com/tibiawiki/serviceinterface/HuntingPlacesResource.java index 05c2da8..217d45e 100644 --- a/src/main/java/com/tibiawiki/serviceinterface/HuntingPlacesResource.java +++ b/src/main/java/com/tibiawiki/serviceinterface/HuntingPlacesResource.java @@ -1,12 +1,20 @@ package com.tibiawiki.serviceinterface; +import com.tibiawiki.domain.objects.HuntingPlace; +import com.tibiawiki.domain.objects.validation.ValidationException; +import com.tibiawiki.process.ModifyAny; import com.tibiawiki.process.RetrieveHuntingPlaces; import io.swagger.annotations.Api; +import io.swagger.annotations.ApiResponse; +import io.swagger.annotations.ApiResponses; import org.json.JSONObject; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; +import javax.ws.rs.Consumes; import javax.ws.rs.GET; +import javax.ws.rs.HeaderParam; +import javax.ws.rs.PUT; import javax.ws.rs.Path; import javax.ws.rs.PathParam; import javax.ws.rs.Produces; @@ -20,10 +28,12 @@ public class HuntingPlacesResource { private RetrieveHuntingPlaces retrieveHuntingPlaces; + private ModifyAny modifyAny; @Autowired - private HuntingPlacesResource(RetrieveHuntingPlaces retrieveHuntingPlaces) { + private HuntingPlacesResource(RetrieveHuntingPlaces retrieveHuntingPlaces, ModifyAny modifyAny) { this.retrieveHuntingPlaces = retrieveHuntingPlaces; + this.modifyAny = modifyAny; } @GET @@ -51,4 +61,23 @@ public Response getHuntingPlacesByName(@PathParam("name") String name) { .orElseGet(() -> Response.status(Response.Status.NOT_FOUND) .build()); } + + @PUT + @ApiResponses(value = { + @ApiResponse(code = 200, message = "the changed huntingPlace"), + @ApiResponse(code = 400, message = "the provided changed huntingPlace is not valid"), + @ApiResponse(code = 401, message = "not authorized to edit without providing credentials") + }) + @Produces(MediaType.APPLICATION_JSON) + @Consumes(MediaType.APPLICATION_JSON) + public Response putHuntingPlace(HuntingPlace huntingPlace, @HeaderParam("X-WIKI-Edit-Summary") String editSummary) { + return modifyAny.modify(huntingPlace, editSummary) + .map(a -> Response.ok() + .entity(a) + .header("Access-Control-Allow-Origin", "*") + .build()) + .recover(ValidationException.class, e -> Response.status(Response.Status.BAD_REQUEST).entity(e.getMessage()).build()) + .recover(e -> Response.serverError().build()) + .get(); + } } diff --git a/src/main/java/com/tibiawiki/serviceinterface/ItemsResource.java b/src/main/java/com/tibiawiki/serviceinterface/ItemsResource.java index bcb78c1..d0ea142 100644 --- a/src/main/java/com/tibiawiki/serviceinterface/ItemsResource.java +++ b/src/main/java/com/tibiawiki/serviceinterface/ItemsResource.java @@ -1,12 +1,20 @@ package com.tibiawiki.serviceinterface; +import com.tibiawiki.domain.objects.Item; +import com.tibiawiki.domain.objects.validation.ValidationException; +import com.tibiawiki.process.ModifyAny; import com.tibiawiki.process.RetrieveItems; import io.swagger.annotations.Api; +import io.swagger.annotations.ApiResponse; +import io.swagger.annotations.ApiResponses; import org.json.JSONObject; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; +import javax.ws.rs.Consumes; import javax.ws.rs.GET; +import javax.ws.rs.HeaderParam; +import javax.ws.rs.PUT; import javax.ws.rs.Path; import javax.ws.rs.PathParam; import javax.ws.rs.Produces; @@ -20,10 +28,12 @@ public class ItemsResource { private RetrieveItems retrieveItems; + private ModifyAny modifyAny; @Autowired - private ItemsResource(RetrieveItems retrieveItems) { + private ItemsResource(RetrieveItems retrieveItems, ModifyAny modifyAny) { this.retrieveItems = retrieveItems; + this.modifyAny = modifyAny; } @GET @@ -51,4 +61,23 @@ public Response getItemsByName(@PathParam("name") String name) { .orElseGet(() -> Response.status(Response.Status.NOT_FOUND) .build()); } + + @PUT + @ApiResponses(value = { + @ApiResponse(code = 200, message = "the changed item"), + @ApiResponse(code = 400, message = "the provided changed item is not valid"), + @ApiResponse(code = 401, message = "not authorized to edit without providing credentials") + }) + @Produces(MediaType.APPLICATION_JSON) + @Consumes(MediaType.APPLICATION_JSON) + public Response putItem(Item item, @HeaderParam("X-WIKI-Edit-Summary") String editSummary) { + return modifyAny.modify(item, editSummary) + .map(a -> Response.ok() + .entity(a) + .header("Access-Control-Allow-Origin", "*") + .build()) + .recover(ValidationException.class, e -> Response.status(Response.Status.BAD_REQUEST).entity(e.getMessage()).build()) + .recover(e -> Response.serverError().build()) + .get(); + } } diff --git a/src/main/java/com/tibiawiki/serviceinterface/KeysResource.java b/src/main/java/com/tibiawiki/serviceinterface/KeysResource.java index 2d0146c..c15c9e8 100644 --- a/src/main/java/com/tibiawiki/serviceinterface/KeysResource.java +++ b/src/main/java/com/tibiawiki/serviceinterface/KeysResource.java @@ -1,12 +1,20 @@ package com.tibiawiki.serviceinterface; +import com.tibiawiki.domain.objects.Key; +import com.tibiawiki.domain.objects.validation.ValidationException; +import com.tibiawiki.process.ModifyAny; import com.tibiawiki.process.RetrieveKeys; import io.swagger.annotations.Api; +import io.swagger.annotations.ApiResponse; +import io.swagger.annotations.ApiResponses; import org.json.JSONObject; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; +import javax.ws.rs.Consumes; import javax.ws.rs.GET; +import javax.ws.rs.HeaderParam; +import javax.ws.rs.PUT; import javax.ws.rs.Path; import javax.ws.rs.PathParam; import javax.ws.rs.Produces; @@ -20,10 +28,12 @@ public class KeysResource { private RetrieveKeys retrieveKeys; + private ModifyAny modifyAny; @Autowired - private KeysResource(RetrieveKeys retrieveKeys) { + private KeysResource(RetrieveKeys retrieveKeys, ModifyAny modifyAny) { this.retrieveKeys = retrieveKeys; + this.modifyAny = modifyAny; } @GET @@ -51,4 +61,23 @@ public Response getKeysByName(@PathParam("name") String name) { .orElseGet(() -> Response.status(Response.Status.NOT_FOUND) .build()); } + + @PUT + @ApiResponses(value = { + @ApiResponse(code = 200, message = "the changed key"), + @ApiResponse(code = 400, message = "the provided changed key is not valid"), + @ApiResponse(code = 401, message = "not authorized to edit without providing credentials") + }) + @Produces(MediaType.APPLICATION_JSON) + @Consumes(MediaType.APPLICATION_JSON) + public Response putKey(Key key, @HeaderParam("X-WIKI-Edit-Summary") String editSummary) { + return modifyAny.modify(key, editSummary) + .map(a -> Response.ok() + .entity(a) + .header("Access-Control-Allow-Origin", "*") + .build()) + .recover(ValidationException.class, e -> Response.status(Response.Status.BAD_REQUEST).entity(e.getMessage()).build()) + .recover(e -> Response.serverError().build()) + .get(); + } } diff --git a/src/main/java/com/tibiawiki/serviceinterface/LocationsResource.java b/src/main/java/com/tibiawiki/serviceinterface/LocationsResource.java index a0eae57..6746e46 100644 --- a/src/main/java/com/tibiawiki/serviceinterface/LocationsResource.java +++ b/src/main/java/com/tibiawiki/serviceinterface/LocationsResource.java @@ -1,12 +1,20 @@ package com.tibiawiki.serviceinterface; +import com.tibiawiki.domain.objects.Location; +import com.tibiawiki.domain.objects.validation.ValidationException; +import com.tibiawiki.process.ModifyAny; import com.tibiawiki.process.RetrieveLocations; import io.swagger.annotations.Api; +import io.swagger.annotations.ApiResponse; +import io.swagger.annotations.ApiResponses; import org.json.JSONObject; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; +import javax.ws.rs.Consumes; import javax.ws.rs.GET; +import javax.ws.rs.HeaderParam; +import javax.ws.rs.PUT; import javax.ws.rs.Path; import javax.ws.rs.PathParam; import javax.ws.rs.Produces; @@ -20,10 +28,12 @@ public class LocationsResource { private RetrieveLocations retrieveLocations; + private ModifyAny modifyAny; @Autowired - private LocationsResource(RetrieveLocations retrieveLocations) { + private LocationsResource(RetrieveLocations retrieveLocations, ModifyAny modifyAny) { this.retrieveLocations = retrieveLocations; + this.modifyAny = modifyAny; } @GET @@ -51,4 +61,23 @@ public Response getLocationsByName(@PathParam("name") String name) { .orElseGet(() -> Response.status(Response.Status.NOT_FOUND) .build()); } + + @PUT + @ApiResponses(value = { + @ApiResponse(code = 200, message = "the changed location"), + @ApiResponse(code = 400, message = "the provided changed location is not valid"), + @ApiResponse(code = 401, message = "not authorized to edit without providing credentials") + }) + @Produces(MediaType.APPLICATION_JSON) + @Consumes(MediaType.APPLICATION_JSON) + public Response putLocation(Location location, @HeaderParam("X-WIKI-Edit-Summary") String editSummary) { + return modifyAny.modify(location, editSummary) + .map(a -> Response.ok() + .entity(a) + .header("Access-Control-Allow-Origin", "*") + .build()) + .recover(ValidationException.class, e -> Response.status(Response.Status.BAD_REQUEST).entity(e.getMessage()).build()) + .recover(e -> Response.serverError().build()) + .get(); + } } diff --git a/src/main/java/com/tibiawiki/serviceinterface/MissilesResource.java b/src/main/java/com/tibiawiki/serviceinterface/MissilesResource.java index 1559010..8883673 100644 --- a/src/main/java/com/tibiawiki/serviceinterface/MissilesResource.java +++ b/src/main/java/com/tibiawiki/serviceinterface/MissilesResource.java @@ -1,12 +1,20 @@ package com.tibiawiki.serviceinterface; +import com.tibiawiki.domain.objects.Missile; +import com.tibiawiki.domain.objects.validation.ValidationException; +import com.tibiawiki.process.ModifyAny; import com.tibiawiki.process.RetrieveMissiles; import io.swagger.annotations.Api; +import io.swagger.annotations.ApiResponse; +import io.swagger.annotations.ApiResponses; import org.json.JSONObject; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; +import javax.ws.rs.Consumes; import javax.ws.rs.GET; +import javax.ws.rs.HeaderParam; +import javax.ws.rs.PUT; import javax.ws.rs.Path; import javax.ws.rs.PathParam; import javax.ws.rs.Produces; @@ -20,10 +28,12 @@ public class MissilesResource { private RetrieveMissiles retrieveMissiles; + private ModifyAny modifyAny; @Autowired - private MissilesResource(RetrieveMissiles retrieveMissiles) { + private MissilesResource(RetrieveMissiles retrieveMissiles, ModifyAny modifyAny) { this.retrieveMissiles = retrieveMissiles; + this.modifyAny = modifyAny; } @GET @@ -51,4 +61,23 @@ public Response getMissilesByName(@PathParam("name") String name) { .orElseGet(() -> Response.status(Response.Status.NOT_FOUND) .build()); } + + @PUT + @ApiResponses(value = { + @ApiResponse(code = 200, message = "the changed missile"), + @ApiResponse(code = 400, message = "the provided changed missile is not valid"), + @ApiResponse(code = 401, message = "not authorized to edit without providing credentials") + }) + @Produces(MediaType.APPLICATION_JSON) + @Consumes(MediaType.APPLICATION_JSON) + public Response putMissile(Missile missile, @HeaderParam("X-WIKI-Edit-Summary") String editSummary) { + return modifyAny.modify(missile, editSummary) + .map(a -> Response.ok() + .entity(a) + .header("Access-Control-Allow-Origin", "*") + .build()) + .recover(ValidationException.class, e -> Response.status(Response.Status.BAD_REQUEST).entity(e.getMessage()).build()) + .recover(e -> Response.serverError().build()) + .get(); + } } diff --git a/src/main/java/com/tibiawiki/serviceinterface/MountsResource.java b/src/main/java/com/tibiawiki/serviceinterface/MountsResource.java index 25908f7..b97cdd8 100644 --- a/src/main/java/com/tibiawiki/serviceinterface/MountsResource.java +++ b/src/main/java/com/tibiawiki/serviceinterface/MountsResource.java @@ -1,12 +1,20 @@ package com.tibiawiki.serviceinterface; +import com.tibiawiki.domain.objects.Mount; +import com.tibiawiki.domain.objects.validation.ValidationException; +import com.tibiawiki.process.ModifyAny; import com.tibiawiki.process.RetrieveMounts; import io.swagger.annotations.Api; +import io.swagger.annotations.ApiResponse; +import io.swagger.annotations.ApiResponses; import org.json.JSONObject; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; +import javax.ws.rs.Consumes; import javax.ws.rs.GET; +import javax.ws.rs.HeaderParam; +import javax.ws.rs.PUT; import javax.ws.rs.Path; import javax.ws.rs.PathParam; import javax.ws.rs.Produces; @@ -20,10 +28,12 @@ public class MountsResource { private RetrieveMounts retrieveMounts; + private ModifyAny modifyAny; @Autowired - private MountsResource(RetrieveMounts retrieveMounts) { + private MountsResource(RetrieveMounts retrieveMounts, ModifyAny modifyAny) { this.retrieveMounts = retrieveMounts; + this.modifyAny = modifyAny; } @GET @@ -51,4 +61,23 @@ public Response getMountsByName(@PathParam("name") String name) { .orElseGet(() -> Response.status(Response.Status.NOT_FOUND) .build()); } + + @PUT + @ApiResponses(value = { + @ApiResponse(code = 200, message = "the changed mount"), + @ApiResponse(code = 400, message = "the provided changed mount is not valid"), + @ApiResponse(code = 401, message = "not authorized to edit without providing credentials") + }) + @Produces(MediaType.APPLICATION_JSON) + @Consumes(MediaType.APPLICATION_JSON) + public Response putMount(Mount mount, @HeaderParam("X-WIKI-Edit-Summary") String editSummary) { + return modifyAny.modify(mount, editSummary) + .map(a -> Response.ok() + .entity(a) + .header("Access-Control-Allow-Origin", "*") + .build()) + .recover(ValidationException.class, e -> Response.status(Response.Status.BAD_REQUEST).entity(e.getMessage()).build()) + .recover(e -> Response.serverError().build()) + .get(); + } } diff --git a/src/main/java/com/tibiawiki/serviceinterface/NPCsResource.java b/src/main/java/com/tibiawiki/serviceinterface/NPCsResource.java index f342210..fdb7023 100644 --- a/src/main/java/com/tibiawiki/serviceinterface/NPCsResource.java +++ b/src/main/java/com/tibiawiki/serviceinterface/NPCsResource.java @@ -1,12 +1,20 @@ package com.tibiawiki.serviceinterface; +import com.tibiawiki.domain.objects.NPC; +import com.tibiawiki.domain.objects.validation.ValidationException; +import com.tibiawiki.process.ModifyAny; import com.tibiawiki.process.RetrieveNPCs; import io.swagger.annotations.Api; +import io.swagger.annotations.ApiResponse; +import io.swagger.annotations.ApiResponses; import org.json.JSONObject; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; +import javax.ws.rs.Consumes; import javax.ws.rs.GET; +import javax.ws.rs.HeaderParam; +import javax.ws.rs.PUT; import javax.ws.rs.Path; import javax.ws.rs.PathParam; import javax.ws.rs.Produces; @@ -20,10 +28,12 @@ public class NPCsResource { private RetrieveNPCs retrieveNPCs; + private ModifyAny modifyAny; @Autowired - private NPCsResource(RetrieveNPCs retrieveNPCs) { + private NPCsResource(RetrieveNPCs retrieveNPCs, ModifyAny modifyAny) { this.retrieveNPCs = retrieveNPCs; + this.modifyAny = modifyAny; } @GET @@ -51,4 +61,23 @@ public Response getNPCsByName(@PathParam("name") String name) { .orElseGet(() -> Response.status(Response.Status.NOT_FOUND) .build()); } + + @PUT + @ApiResponses(value = { + @ApiResponse(code = 200, message = "the changed npc"), + @ApiResponse(code = 400, message = "the provided changed npc is not valid"), + @ApiResponse(code = 401, message = "not authorized to edit without providing credentials") + }) + @Produces(MediaType.APPLICATION_JSON) + @Consumes(MediaType.APPLICATION_JSON) + public Response putNPC(NPC npc, @HeaderParam("X-WIKI-Edit-Summary") String editSummary) { + return modifyAny.modify(npc, editSummary) + .map(a -> Response.ok() + .entity(a) + .header("Access-Control-Allow-Origin", "*") + .build()) + .recover(ValidationException.class, e -> Response.status(Response.Status.BAD_REQUEST).entity(e.getMessage()).build()) + .recover(e -> Response.serverError().build()) + .get(); + } } diff --git a/src/main/java/com/tibiawiki/serviceinterface/ObjectsResource.java b/src/main/java/com/tibiawiki/serviceinterface/ObjectsResource.java index f17cea2..4fc05da 100644 --- a/src/main/java/com/tibiawiki/serviceinterface/ObjectsResource.java +++ b/src/main/java/com/tibiawiki/serviceinterface/ObjectsResource.java @@ -1,12 +1,20 @@ package com.tibiawiki.serviceinterface; +import com.tibiawiki.domain.objects.TibiaObject; +import com.tibiawiki.domain.objects.validation.ValidationException; +import com.tibiawiki.process.ModifyAny; import com.tibiawiki.process.RetrieveObjects; import io.swagger.annotations.Api; +import io.swagger.annotations.ApiResponse; +import io.swagger.annotations.ApiResponses; import org.json.JSONObject; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; +import javax.ws.rs.Consumes; import javax.ws.rs.GET; +import javax.ws.rs.HeaderParam; +import javax.ws.rs.PUT; import javax.ws.rs.Path; import javax.ws.rs.PathParam; import javax.ws.rs.Produces; @@ -20,10 +28,12 @@ public class ObjectsResource { private RetrieveObjects retrieveObjects; + private ModifyAny modifyAny; @Autowired - private ObjectsResource(RetrieveObjects retrieveObjects) { + private ObjectsResource(RetrieveObjects retrieveObjects, ModifyAny modifyAny) { this.retrieveObjects = retrieveObjects; + this.modifyAny = modifyAny; } @GET @@ -51,4 +61,23 @@ public Response getObjectsByName(@PathParam("name") String name) { .orElseGet(() -> Response.status(Response.Status.NOT_FOUND) .build()); } + + @PUT + @ApiResponses(value = { + @ApiResponse(code = 200, message = "the changed tibiaObject"), + @ApiResponse(code = 400, message = "the provided changed tibiaObject is not valid"), + @ApiResponse(code = 401, message = "not authorized to edit without providing credentials") + }) + @Produces(MediaType.APPLICATION_JSON) + @Consumes(MediaType.APPLICATION_JSON) + public Response putTibiaObject(TibiaObject tibiaObject, @HeaderParam("X-WIKI-Edit-Summary") String editSummary) { + return modifyAny.modify(tibiaObject, editSummary) + .map(a -> Response.ok() + .entity(a) + .header("Access-Control-Allow-Origin", "*") + .build()) + .recover(ValidationException.class, e -> Response.status(Response.Status.BAD_REQUEST).entity(e.getMessage()).build()) + .recover(e -> Response.serverError().build()) + .get(); + } } diff --git a/src/main/java/com/tibiawiki/serviceinterface/OutfitsResource.java b/src/main/java/com/tibiawiki/serviceinterface/OutfitsResource.java index a531d3a..9c5dd84 100644 --- a/src/main/java/com/tibiawiki/serviceinterface/OutfitsResource.java +++ b/src/main/java/com/tibiawiki/serviceinterface/OutfitsResource.java @@ -1,12 +1,20 @@ package com.tibiawiki.serviceinterface; +import com.tibiawiki.domain.objects.Outfit; +import com.tibiawiki.domain.objects.validation.ValidationException; +import com.tibiawiki.process.ModifyAny; import com.tibiawiki.process.RetrieveOutfits; import io.swagger.annotations.Api; +import io.swagger.annotations.ApiResponse; +import io.swagger.annotations.ApiResponses; import org.json.JSONObject; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; +import javax.ws.rs.Consumes; import javax.ws.rs.GET; +import javax.ws.rs.HeaderParam; +import javax.ws.rs.PUT; import javax.ws.rs.Path; import javax.ws.rs.PathParam; import javax.ws.rs.Produces; @@ -20,10 +28,12 @@ public class OutfitsResource { private RetrieveOutfits retrieveOutfits; + private ModifyAny modifyAny; @Autowired - private OutfitsResource(RetrieveOutfits retrieveOutfits) { + private OutfitsResource(RetrieveOutfits retrieveOutfits, ModifyAny modifyAny) { this.retrieveOutfits = retrieveOutfits; + this.modifyAny = modifyAny; } @GET @@ -51,4 +61,23 @@ public Response getOutfitsByName(@PathParam("name") String name) { .orElseGet(() -> Response.status(Response.Status.NOT_FOUND) .build()); } + + @PUT + @ApiResponses(value = { + @ApiResponse(code = 200, message = "the changed outfit"), + @ApiResponse(code = 400, message = "the provided changed outfit is not valid"), + @ApiResponse(code = 401, message = "not authorized to edit without providing credentials") + }) + @Produces(MediaType.APPLICATION_JSON) + @Consumes(MediaType.APPLICATION_JSON) + public Response putOutfit(Outfit outfit, @HeaderParam("X-WIKI-Edit-Summary") String editSummary) { + return modifyAny.modify(outfit, editSummary) + .map(a -> Response.ok() + .entity(a) + .header("Access-Control-Allow-Origin", "*") + .build()) + .recover(ValidationException.class, e -> Response.status(Response.Status.BAD_REQUEST).entity(e.getMessage()).build()) + .recover(e -> Response.serverError().build()) + .get(); + } } diff --git a/src/main/java/com/tibiawiki/serviceinterface/QuestsResource.java b/src/main/java/com/tibiawiki/serviceinterface/QuestsResource.java index c43780f..20f0f67 100644 --- a/src/main/java/com/tibiawiki/serviceinterface/QuestsResource.java +++ b/src/main/java/com/tibiawiki/serviceinterface/QuestsResource.java @@ -1,12 +1,20 @@ package com.tibiawiki.serviceinterface; +import com.tibiawiki.domain.objects.Quest; +import com.tibiawiki.domain.objects.validation.ValidationException; +import com.tibiawiki.process.ModifyAny; import com.tibiawiki.process.RetrieveQuests; import io.swagger.annotations.Api; +import io.swagger.annotations.ApiResponse; +import io.swagger.annotations.ApiResponses; import org.json.JSONObject; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; +import javax.ws.rs.Consumes; import javax.ws.rs.GET; +import javax.ws.rs.HeaderParam; +import javax.ws.rs.PUT; import javax.ws.rs.Path; import javax.ws.rs.PathParam; import javax.ws.rs.Produces; @@ -20,10 +28,12 @@ public class QuestsResource { private RetrieveQuests retrieveQuests; + private ModifyAny modifyAny; @Autowired - private QuestsResource(RetrieveQuests retrieveQuests) { + private QuestsResource(RetrieveQuests retrieveQuests, ModifyAny modifyAny) { this.retrieveQuests = retrieveQuests; + this.modifyAny = modifyAny; } @GET @@ -51,4 +61,23 @@ public Response getQuestsByName(@PathParam("name") String name) { .orElseGet(() -> Response.status(Response.Status.NOT_FOUND) .build()); } + + @PUT + @ApiResponses(value = { + @ApiResponse(code = 200, message = "the changed quest"), + @ApiResponse(code = 400, message = "the provided changed quest is not valid"), + @ApiResponse(code = 401, message = "not authorized to edit without providing credentials") + }) + @Produces(MediaType.APPLICATION_JSON) + @Consumes(MediaType.APPLICATION_JSON) + public Response putQuest(Quest quest, @HeaderParam("X-WIKI-Edit-Summary") String editSummary) { + return modifyAny.modify(quest, editSummary) + .map(a -> Response.ok() + .entity(a) + .header("Access-Control-Allow-Origin", "*") + .build()) + .recover(ValidationException.class, e -> Response.status(Response.Status.BAD_REQUEST).entity(e.getMessage()).build()) + .recover(e -> Response.serverError().build()) + .get(); + } } diff --git a/src/main/java/com/tibiawiki/serviceinterface/SpellsResource.java b/src/main/java/com/tibiawiki/serviceinterface/SpellsResource.java index 7d1116b..3f8e945 100644 --- a/src/main/java/com/tibiawiki/serviceinterface/SpellsResource.java +++ b/src/main/java/com/tibiawiki/serviceinterface/SpellsResource.java @@ -1,12 +1,20 @@ package com.tibiawiki.serviceinterface; +import com.tibiawiki.domain.objects.Spell; +import com.tibiawiki.domain.objects.validation.ValidationException; +import com.tibiawiki.process.ModifyAny; import com.tibiawiki.process.RetrieveSpells; import io.swagger.annotations.Api; +import io.swagger.annotations.ApiResponse; +import io.swagger.annotations.ApiResponses; import org.json.JSONObject; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; +import javax.ws.rs.Consumes; import javax.ws.rs.GET; +import javax.ws.rs.HeaderParam; +import javax.ws.rs.PUT; import javax.ws.rs.Path; import javax.ws.rs.PathParam; import javax.ws.rs.Produces; @@ -20,10 +28,12 @@ public class SpellsResource { private RetrieveSpells retrieveSpells; + private ModifyAny modifyAny; @Autowired - private SpellsResource(RetrieveSpells retrieveSpells) { + private SpellsResource(RetrieveSpells retrieveSpells, ModifyAny modifyAny) { this.retrieveSpells = retrieveSpells; + this.modifyAny = modifyAny; } @GET @@ -51,4 +61,23 @@ public Response getSpellsByName(@PathParam("name") String name) { .orElseGet(() -> Response.status(Response.Status.NOT_FOUND) .build()); } + + @PUT + @ApiResponses(value = { + @ApiResponse(code = 200, message = "the changed spell"), + @ApiResponse(code = 400, message = "the provided changed spell is not valid"), + @ApiResponse(code = 401, message = "not authorized to edit without providing credentials") + }) + @Produces(MediaType.APPLICATION_JSON) + @Consumes(MediaType.APPLICATION_JSON) + public Response putSpell(Spell spell, @HeaderParam("X-WIKI-Edit-Summary") String editSummary) { + return modifyAny.modify(spell, editSummary) + .map(a -> Response.ok() + .entity(a) + .header("Access-Control-Allow-Origin", "*") + .build()) + .recover(ValidationException.class, e -> Response.status(Response.Status.BAD_REQUEST).entity(e.getMessage()).build()) + .recover(e -> Response.serverError().build()) + .get(); + } } diff --git a/src/main/java/com/tibiawiki/serviceinterface/StreetsResource.java b/src/main/java/com/tibiawiki/serviceinterface/StreetsResource.java index 9423865..6ecadd8 100644 --- a/src/main/java/com/tibiawiki/serviceinterface/StreetsResource.java +++ b/src/main/java/com/tibiawiki/serviceinterface/StreetsResource.java @@ -1,12 +1,20 @@ package com.tibiawiki.serviceinterface; +import com.tibiawiki.domain.objects.Street; +import com.tibiawiki.domain.objects.validation.ValidationException; +import com.tibiawiki.process.ModifyAny; import com.tibiawiki.process.RetrieveStreets; import io.swagger.annotations.Api; +import io.swagger.annotations.ApiResponse; +import io.swagger.annotations.ApiResponses; import org.json.JSONObject; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; +import javax.ws.rs.Consumes; import javax.ws.rs.GET; +import javax.ws.rs.HeaderParam; +import javax.ws.rs.PUT; import javax.ws.rs.Path; import javax.ws.rs.PathParam; import javax.ws.rs.Produces; @@ -20,10 +28,12 @@ public class StreetsResource { private RetrieveStreets retrieveStreets; + private ModifyAny modifyAny; @Autowired - private StreetsResource(RetrieveStreets retrieveStreets) { + private StreetsResource(RetrieveStreets retrieveStreets, ModifyAny modifyAny) { this.retrieveStreets = retrieveStreets; + this.modifyAny = modifyAny; } @GET @@ -51,4 +61,23 @@ public Response getStreetsByName(@PathParam("name") String name) { .orElseGet(() -> Response.status(Response.Status.NOT_FOUND) .build()); } + + @PUT + @ApiResponses(value = { + @ApiResponse(code = 200, message = "the changed street"), + @ApiResponse(code = 400, message = "the provided changed street is not valid"), + @ApiResponse(code = 401, message = "not authorized to edit without providing credentials") + }) + @Produces(MediaType.APPLICATION_JSON) + @Consumes(MediaType.APPLICATION_JSON) + public Response putStreet(Street street, @HeaderParam("X-WIKI-Edit-Summary") String editSummary) { + return modifyAny.modify(street, editSummary) + .map(a -> Response.ok() + .entity(a) + .header("Access-Control-Allow-Origin", "*") + .build()) + .recover(ValidationException.class, e -> Response.status(Response.Status.BAD_REQUEST).entity(e.getMessage()).build()) + .recover(e -> Response.serverError().build()) + .get(); + } } From 61d509a68a6d3691da35ced3514f0311547ff71f Mon Sep 17 00:00:00 2001 From: Benjamin Komen Date: Sat, 8 Dec 2018 13:04:40 +0100 Subject: [PATCH 16/19] Fix in resource paths. --- .../java/com/tibiawiki/serviceinterface/BooksResource.java | 5 ++--- .../com/tibiawiki/serviceinterface/BuildingsResource.java | 5 ++--- .../java/com/tibiawiki/serviceinterface/CorpsesResource.java | 5 ++--- .../com/tibiawiki/serviceinterface/CreaturesResource.java | 5 ++--- .../java/com/tibiawiki/serviceinterface/EffectsResource.java | 5 ++--- .../tibiawiki/serviceinterface/HuntingPlacesResource.java | 5 ++--- .../java/com/tibiawiki/serviceinterface/ItemsResource.java | 5 ++--- .../java/com/tibiawiki/serviceinterface/KeysResource.java | 5 ++--- .../com/tibiawiki/serviceinterface/LocationsResource.java | 5 ++--- .../com/tibiawiki/serviceinterface/MissilesResource.java | 5 ++--- .../java/com/tibiawiki/serviceinterface/MountsResource.java | 5 ++--- .../java/com/tibiawiki/serviceinterface/NPCsResource.java | 5 ++--- .../java/com/tibiawiki/serviceinterface/ObjectsResource.java | 5 ++--- .../java/com/tibiawiki/serviceinterface/OutfitsResource.java | 5 ++--- .../java/com/tibiawiki/serviceinterface/QuestsResource.java | 5 ++--- .../java/com/tibiawiki/serviceinterface/SpellsResource.java | 5 ++--- .../java/com/tibiawiki/serviceinterface/StreetsResource.java | 5 ++--- .../com/tibiawiki/serviceinterface/config/JerseyConfig.java | 2 +- 18 files changed, 35 insertions(+), 52 deletions(-) diff --git a/src/main/java/com/tibiawiki/serviceinterface/BooksResource.java b/src/main/java/com/tibiawiki/serviceinterface/BooksResource.java index ea06d47..fdf7563 100644 --- a/src/main/java/com/tibiawiki/serviceinterface/BooksResource.java +++ b/src/main/java/com/tibiawiki/serviceinterface/BooksResource.java @@ -24,7 +24,7 @@ @Component @Api(value = "Books") -@Path("/") +@Path("/books") public class BooksResource { private RetrieveBooks retrieveBooks; @@ -37,7 +37,6 @@ private BooksResource(RetrieveBooks retrieveBooks, ModifyAny modifyAny) { } @GET - @Path("/books") @Produces(MediaType.APPLICATION_JSON) public Response getBooks(@QueryParam("expand") Boolean expand) { return Response.ok() @@ -50,7 +49,7 @@ public Response getBooks(@QueryParam("expand") Boolean expand) { } @GET - @Path("/books/{name}") + @Path("/{name}") @Produces(MediaType.APPLICATION_JSON) public Response getBooksByName(@PathParam("name") String name) { return retrieveBooks.getBookJSON(name) diff --git a/src/main/java/com/tibiawiki/serviceinterface/BuildingsResource.java b/src/main/java/com/tibiawiki/serviceinterface/BuildingsResource.java index 3bb4804..56f5fd7 100644 --- a/src/main/java/com/tibiawiki/serviceinterface/BuildingsResource.java +++ b/src/main/java/com/tibiawiki/serviceinterface/BuildingsResource.java @@ -24,7 +24,7 @@ @Component @Api(value = "Buildings") -@Path("/") +@Path("/buildings") public class BuildingsResource { private RetrieveBuildings retrieveBuildings; @@ -37,7 +37,6 @@ private BuildingsResource(RetrieveBuildings retrieveBuildings, ModifyAny modifyA } @GET - @Path("/buildings") @Produces(MediaType.APPLICATION_JSON) public Response getBuildings(@QueryParam("expand") Boolean expand) { return Response.ok() @@ -50,7 +49,7 @@ public Response getBuildings(@QueryParam("expand") Boolean expand) { } @GET - @Path("/buildings/{name}") + @Path("/{name}") @Produces(MediaType.APPLICATION_JSON) public Response getBuildingsByName(@PathParam("name") String name) { return retrieveBuildings.getBuildingJSON(name) diff --git a/src/main/java/com/tibiawiki/serviceinterface/CorpsesResource.java b/src/main/java/com/tibiawiki/serviceinterface/CorpsesResource.java index f30d344..2f7a6ce 100644 --- a/src/main/java/com/tibiawiki/serviceinterface/CorpsesResource.java +++ b/src/main/java/com/tibiawiki/serviceinterface/CorpsesResource.java @@ -24,7 +24,7 @@ @Component @Api(value = "Corpses") -@Path("/") +@Path("/corpses") public class CorpsesResource { private RetrieveCorpses retrieveCorpses; @@ -37,7 +37,6 @@ private CorpsesResource(RetrieveCorpses retrieveCorpses, ModifyAny modifyAny) { } @GET - @Path("/corpses") @Produces(MediaType.APPLICATION_JSON) public Response getCorpses(@QueryParam("expand") Boolean expand) { return Response.ok() @@ -50,7 +49,7 @@ public Response getCorpses(@QueryParam("expand") Boolean expand) { } @GET - @Path("/corpses/{name}") + @Path("/{name}") @Produces(MediaType.APPLICATION_JSON) public Response getCorpsesByName(@PathParam("name") String name) { return retrieveCorpses.getCorpseJSON(name) diff --git a/src/main/java/com/tibiawiki/serviceinterface/CreaturesResource.java b/src/main/java/com/tibiawiki/serviceinterface/CreaturesResource.java index 5ebb0b6..6da52a9 100644 --- a/src/main/java/com/tibiawiki/serviceinterface/CreaturesResource.java +++ b/src/main/java/com/tibiawiki/serviceinterface/CreaturesResource.java @@ -24,7 +24,7 @@ @Component @Api(value = "Creatures") -@Path("/") +@Path("/creatures") public class CreaturesResource { private RetrieveCreatures retrieveCreatures; @@ -37,7 +37,6 @@ private CreaturesResource(RetrieveCreatures retrieveCreatures, ModifyAny modifyA } @GET - @Path("/creatures") @Produces(MediaType.APPLICATION_JSON) public Response getCreatures(@QueryParam("expand") Boolean expand) { return Response.ok() @@ -50,7 +49,7 @@ public Response getCreatures(@QueryParam("expand") Boolean expand) { } @GET - @Path("/creatures/{name}") + @Path("/{name}") @Produces(MediaType.APPLICATION_JSON) public Response getCreatureByName(@PathParam("name") String name) { return retrieveCreatures.getCreatureJSON(name) diff --git a/src/main/java/com/tibiawiki/serviceinterface/EffectsResource.java b/src/main/java/com/tibiawiki/serviceinterface/EffectsResource.java index 70e1d15..e80b676 100644 --- a/src/main/java/com/tibiawiki/serviceinterface/EffectsResource.java +++ b/src/main/java/com/tibiawiki/serviceinterface/EffectsResource.java @@ -24,7 +24,7 @@ @Component @Api(value = "Effects") -@Path("/") +@Path("/effects") public class EffectsResource { private RetrieveEffects retrieveEffects; @@ -37,7 +37,6 @@ private EffectsResource(RetrieveEffects retrieveEffects, ModifyAny modifyAny) { } @GET - @Path("/effects") @Produces(MediaType.APPLICATION_JSON) public Response getEffects(@QueryParam("expand") Boolean expand) { return Response.ok() @@ -50,7 +49,7 @@ public Response getEffects(@QueryParam("expand") Boolean expand) { } @GET - @Path("/effects/{name}") + @Path("/{name}") @Produces(MediaType.APPLICATION_JSON) public Response getEffectsByName(@PathParam("name") String name) { return retrieveEffects.getEffectJSON(name) diff --git a/src/main/java/com/tibiawiki/serviceinterface/HuntingPlacesResource.java b/src/main/java/com/tibiawiki/serviceinterface/HuntingPlacesResource.java index 217d45e..3bbb4a3 100644 --- a/src/main/java/com/tibiawiki/serviceinterface/HuntingPlacesResource.java +++ b/src/main/java/com/tibiawiki/serviceinterface/HuntingPlacesResource.java @@ -24,7 +24,7 @@ @Component @Api(value = "Hunting Places") -@Path("/") +@Path("/huntingplaces") public class HuntingPlacesResource { private RetrieveHuntingPlaces retrieveHuntingPlaces; @@ -37,7 +37,6 @@ private HuntingPlacesResource(RetrieveHuntingPlaces retrieveHuntingPlaces, Modif } @GET - @Path("/huntingplaces") @Produces(MediaType.APPLICATION_JSON) public Response getHuntingPlaces(@QueryParam("expand") Boolean expand) { return Response.ok() @@ -50,7 +49,7 @@ public Response getHuntingPlaces(@QueryParam("expand") Boolean expand) { } @GET - @Path("/huntingplaces/{name}") + @Path("/{name}") @Produces(MediaType.APPLICATION_JSON) public Response getHuntingPlacesByName(@PathParam("name") String name) { return retrieveHuntingPlaces.getHuntingPlaceJSON(name) diff --git a/src/main/java/com/tibiawiki/serviceinterface/ItemsResource.java b/src/main/java/com/tibiawiki/serviceinterface/ItemsResource.java index d0ea142..08ae62b 100644 --- a/src/main/java/com/tibiawiki/serviceinterface/ItemsResource.java +++ b/src/main/java/com/tibiawiki/serviceinterface/ItemsResource.java @@ -24,7 +24,7 @@ @Component @Api(value = "Items") -@Path("/") +@Path("/items") public class ItemsResource { private RetrieveItems retrieveItems; @@ -37,7 +37,6 @@ private ItemsResource(RetrieveItems retrieveItems, ModifyAny modifyAny) { } @GET - @Path("/items") @Produces(MediaType.APPLICATION_JSON) public Response getItems(@QueryParam("expand") Boolean expand) { return Response.ok() @@ -50,7 +49,7 @@ public Response getItems(@QueryParam("expand") Boolean expand) { } @GET - @Path("/items/{name}") + @Path("/{name}") @Produces(MediaType.APPLICATION_JSON) public Response getItemsByName(@PathParam("name") String name) { return retrieveItems.getItemJSON(name) diff --git a/src/main/java/com/tibiawiki/serviceinterface/KeysResource.java b/src/main/java/com/tibiawiki/serviceinterface/KeysResource.java index c15c9e8..ada95ac 100644 --- a/src/main/java/com/tibiawiki/serviceinterface/KeysResource.java +++ b/src/main/java/com/tibiawiki/serviceinterface/KeysResource.java @@ -24,7 +24,7 @@ @Component @Api(value = "Keys") -@Path("/") +@Path("/keys") public class KeysResource { private RetrieveKeys retrieveKeys; @@ -37,7 +37,6 @@ private KeysResource(RetrieveKeys retrieveKeys, ModifyAny modifyAny) { } @GET - @Path("/keys") @Produces(MediaType.APPLICATION_JSON) public Response getKeys(@QueryParam("expand") Boolean expand) { return Response.ok() @@ -50,7 +49,7 @@ public Response getKeys(@QueryParam("expand") Boolean expand) { } @GET - @Path("/keys/{name}") + @Path("/{name}") @Produces(MediaType.APPLICATION_JSON) public Response getKeysByName(@PathParam("name") String name) { return retrieveKeys.getKeyJSON(name) diff --git a/src/main/java/com/tibiawiki/serviceinterface/LocationsResource.java b/src/main/java/com/tibiawiki/serviceinterface/LocationsResource.java index 6746e46..393b6db 100644 --- a/src/main/java/com/tibiawiki/serviceinterface/LocationsResource.java +++ b/src/main/java/com/tibiawiki/serviceinterface/LocationsResource.java @@ -24,7 +24,7 @@ @Component @Api(value = "Locations") -@Path("/") +@Path("/locations") public class LocationsResource { private RetrieveLocations retrieveLocations; @@ -37,7 +37,6 @@ private LocationsResource(RetrieveLocations retrieveLocations, ModifyAny modifyA } @GET - @Path("/locations") @Produces(MediaType.APPLICATION_JSON) public Response getLocations(@QueryParam("expand") Boolean expand) { return Response.ok() @@ -50,7 +49,7 @@ public Response getLocations(@QueryParam("expand") Boolean expand) { } @GET - @Path("/locations/{name}") + @Path("/{name}") @Produces(MediaType.APPLICATION_JSON) public Response getLocationsByName(@PathParam("name") String name) { return retrieveLocations.getLocationJSON(name) diff --git a/src/main/java/com/tibiawiki/serviceinterface/MissilesResource.java b/src/main/java/com/tibiawiki/serviceinterface/MissilesResource.java index 8883673..52b3975 100644 --- a/src/main/java/com/tibiawiki/serviceinterface/MissilesResource.java +++ b/src/main/java/com/tibiawiki/serviceinterface/MissilesResource.java @@ -24,7 +24,7 @@ @Component @Api(value = "Missiles") -@Path("/") +@Path("/missiles") public class MissilesResource { private RetrieveMissiles retrieveMissiles; @@ -37,7 +37,6 @@ private MissilesResource(RetrieveMissiles retrieveMissiles, ModifyAny modifyAny) } @GET - @Path("/missiles") @Produces(MediaType.APPLICATION_JSON) public Response getMissiles(@QueryParam("expand") Boolean expand) { return Response.ok() @@ -50,7 +49,7 @@ public Response getMissiles(@QueryParam("expand") Boolean expand) { } @GET - @Path("/missiles/{name}") + @Path("/{name}") @Produces(MediaType.APPLICATION_JSON) public Response getMissilesByName(@PathParam("name") String name) { return retrieveMissiles.getMissileJSON(name) diff --git a/src/main/java/com/tibiawiki/serviceinterface/MountsResource.java b/src/main/java/com/tibiawiki/serviceinterface/MountsResource.java index b97cdd8..57e9b5d 100644 --- a/src/main/java/com/tibiawiki/serviceinterface/MountsResource.java +++ b/src/main/java/com/tibiawiki/serviceinterface/MountsResource.java @@ -24,7 +24,7 @@ @Component @Api(value = "Mounts") -@Path("/") +@Path("/mounts") public class MountsResource { private RetrieveMounts retrieveMounts; @@ -37,7 +37,6 @@ private MountsResource(RetrieveMounts retrieveMounts, ModifyAny modifyAny) { } @GET - @Path("/mounts") @Produces(MediaType.APPLICATION_JSON) public Response getMounts(@QueryParam("expand") Boolean expand) { return Response.ok() @@ -50,7 +49,7 @@ public Response getMounts(@QueryParam("expand") Boolean expand) { } @GET - @Path("/mounts/{name}") + @Path("/{name}") @Produces(MediaType.APPLICATION_JSON) public Response getMountsByName(@PathParam("name") String name) { return retrieveMounts.getMountJSON(name) diff --git a/src/main/java/com/tibiawiki/serviceinterface/NPCsResource.java b/src/main/java/com/tibiawiki/serviceinterface/NPCsResource.java index fdb7023..fde35ef 100644 --- a/src/main/java/com/tibiawiki/serviceinterface/NPCsResource.java +++ b/src/main/java/com/tibiawiki/serviceinterface/NPCsResource.java @@ -24,7 +24,7 @@ @Component @Api(value = "NPCs") -@Path("/") +@Path("/npcs") public class NPCsResource { private RetrieveNPCs retrieveNPCs; @@ -37,7 +37,6 @@ private NPCsResource(RetrieveNPCs retrieveNPCs, ModifyAny modifyAny) { } @GET - @Path("/npcs") @Produces(MediaType.APPLICATION_JSON) public Response getNPCs(@QueryParam("expand") Boolean expand) { return Response.ok() @@ -50,7 +49,7 @@ public Response getNPCs(@QueryParam("expand") Boolean expand) { } @GET - @Path("/npcs/{name}") + @Path("/{name}") @Produces(MediaType.APPLICATION_JSON) public Response getNPCsByName(@PathParam("name") String name) { return retrieveNPCs.getNPCJSON(name) diff --git a/src/main/java/com/tibiawiki/serviceinterface/ObjectsResource.java b/src/main/java/com/tibiawiki/serviceinterface/ObjectsResource.java index 4fc05da..05c42d4 100644 --- a/src/main/java/com/tibiawiki/serviceinterface/ObjectsResource.java +++ b/src/main/java/com/tibiawiki/serviceinterface/ObjectsResource.java @@ -24,7 +24,7 @@ @Component @Api(value = "Objects") -@Path("/") +@Path("/objects") public class ObjectsResource { private RetrieveObjects retrieveObjects; @@ -37,7 +37,6 @@ private ObjectsResource(RetrieveObjects retrieveObjects, ModifyAny modifyAny) { } @GET - @Path("/objects") @Produces(MediaType.APPLICATION_JSON) public Response getObjects(@QueryParam("expand") Boolean expand) { return Response.ok() @@ -50,7 +49,7 @@ public Response getObjects(@QueryParam("expand") Boolean expand) { } @GET - @Path("/objects/{name}") + @Path("/{name}") @Produces(MediaType.APPLICATION_JSON) public Response getObjectsByName(@PathParam("name") String name) { return retrieveObjects.getObjectJSON(name) diff --git a/src/main/java/com/tibiawiki/serviceinterface/OutfitsResource.java b/src/main/java/com/tibiawiki/serviceinterface/OutfitsResource.java index 9c5dd84..a93f753 100644 --- a/src/main/java/com/tibiawiki/serviceinterface/OutfitsResource.java +++ b/src/main/java/com/tibiawiki/serviceinterface/OutfitsResource.java @@ -24,7 +24,7 @@ @Component @Api(value = "Outfits") -@Path("/") +@Path("/outfits") public class OutfitsResource { private RetrieveOutfits retrieveOutfits; @@ -37,7 +37,6 @@ private OutfitsResource(RetrieveOutfits retrieveOutfits, ModifyAny modifyAny) { } @GET - @Path("/outfits") @Produces(MediaType.APPLICATION_JSON) public Response getOutfits(@QueryParam("expand") Boolean expand) { return Response.ok() @@ -50,7 +49,7 @@ public Response getOutfits(@QueryParam("expand") Boolean expand) { } @GET - @Path("/outfits/{name}") + @Path("/{name}") @Produces(MediaType.APPLICATION_JSON) public Response getOutfitsByName(@PathParam("name") String name) { return retrieveOutfits.getOutfitJSON(name) diff --git a/src/main/java/com/tibiawiki/serviceinterface/QuestsResource.java b/src/main/java/com/tibiawiki/serviceinterface/QuestsResource.java index 20f0f67..124227f 100644 --- a/src/main/java/com/tibiawiki/serviceinterface/QuestsResource.java +++ b/src/main/java/com/tibiawiki/serviceinterface/QuestsResource.java @@ -24,7 +24,7 @@ @Component @Api(value = "Quests") -@Path("/") +@Path("/quests") public class QuestsResource { private RetrieveQuests retrieveQuests; @@ -37,7 +37,6 @@ private QuestsResource(RetrieveQuests retrieveQuests, ModifyAny modifyAny) { } @GET - @Path("/quests") @Produces(MediaType.APPLICATION_JSON) public Response getQuests(@QueryParam("expand") Boolean expand) { return Response.ok() @@ -50,7 +49,7 @@ public Response getQuests(@QueryParam("expand") Boolean expand) { } @GET - @Path("/quests/{name}") + @Path("/{name}") @Produces(MediaType.APPLICATION_JSON) public Response getQuestsByName(@PathParam("name") String name) { return retrieveQuests.getQuestJSON(name) diff --git a/src/main/java/com/tibiawiki/serviceinterface/SpellsResource.java b/src/main/java/com/tibiawiki/serviceinterface/SpellsResource.java index 3f8e945..8962c5e 100644 --- a/src/main/java/com/tibiawiki/serviceinterface/SpellsResource.java +++ b/src/main/java/com/tibiawiki/serviceinterface/SpellsResource.java @@ -24,7 +24,7 @@ @Component @Api(value = "Spells") -@Path("/") +@Path("/spells") public class SpellsResource { private RetrieveSpells retrieveSpells; @@ -37,7 +37,6 @@ private SpellsResource(RetrieveSpells retrieveSpells, ModifyAny modifyAny) { } @GET - @Path("/spells") @Produces(MediaType.APPLICATION_JSON) public Response getSpells(@QueryParam("expand") Boolean expand) { return Response.ok() @@ -50,7 +49,7 @@ public Response getSpells(@QueryParam("expand") Boolean expand) { } @GET - @Path("/spells/{name}") + @Path("/{name}") @Produces(MediaType.APPLICATION_JSON) public Response getSpellsByName(@PathParam("name") String name) { return retrieveSpells.getSpellJSON(name) diff --git a/src/main/java/com/tibiawiki/serviceinterface/StreetsResource.java b/src/main/java/com/tibiawiki/serviceinterface/StreetsResource.java index 6ecadd8..b497ffe 100644 --- a/src/main/java/com/tibiawiki/serviceinterface/StreetsResource.java +++ b/src/main/java/com/tibiawiki/serviceinterface/StreetsResource.java @@ -24,7 +24,7 @@ @Component @Api(value = "Streets") -@Path("/") +@Path("/streets") public class StreetsResource { private RetrieveStreets retrieveStreets; @@ -37,7 +37,6 @@ private StreetsResource(RetrieveStreets retrieveStreets, ModifyAny modifyAny) { } @GET - @Path("/streets") @Produces(MediaType.APPLICATION_JSON) public Response getStreets(@QueryParam("expand") Boolean expand) { return Response.ok() @@ -50,7 +49,7 @@ public Response getStreets(@QueryParam("expand") Boolean expand) { } @GET - @Path("/streets/{name}") + @Path("/{name}") @Produces(MediaType.APPLICATION_JSON) public Response getStreetsByName(@PathParam("name") String name) { return retrieveStreets.getStreetJSON(name) diff --git a/src/main/java/com/tibiawiki/serviceinterface/config/JerseyConfig.java b/src/main/java/com/tibiawiki/serviceinterface/config/JerseyConfig.java index 654f855..f0733f6 100644 --- a/src/main/java/com/tibiawiki/serviceinterface/config/JerseyConfig.java +++ b/src/main/java/com/tibiawiki/serviceinterface/config/JerseyConfig.java @@ -70,7 +70,7 @@ private void configureSwagger() { BeanConfig beanConfig = new BeanConfig(); beanConfig.setConfigId("tibiawikiapi"); beanConfig.setTitle("TibiaWikiApi"); - beanConfig.setVersion("1.2.0"); + beanConfig.setVersion("1.4.0"); beanConfig.setContact("B. Komen"); beanConfig.setSchemes(new String[]{"http", "https"}); beanConfig.setBasePath(this.apiPath); // location where dynamically created swagger.json is reachable From c7d287fbe42ddfe02c58971f5352a39c827fdeb7 Mon Sep 17 00:00:00 2001 From: Benjamin Komen Date: Sat, 8 Dec 2018 13:22:06 +0100 Subject: [PATCH 17/19] Fixing constructing of json for locations and streets which don't have list and getvalue params anymore. Fix datatype of position parameters of npcs. --- .../domain/factories/JsonFactory.java | 11 +++++++- .../com/tibiawiki/domain/objects/NPC.java | 27 ++++++++++--------- .../HuntingPlacesResource.java | 18 ++++++------- .../domain/factories/JsonFactoryTest.java | 16 ++--------- 4 files changed, 35 insertions(+), 37 deletions(-) diff --git a/src/main/java/com/tibiawiki/domain/factories/JsonFactory.java b/src/main/java/com/tibiawiki/domain/factories/JsonFactory.java index c1901b2..058c77c 100644 --- a/src/main/java/com/tibiawiki/domain/factories/JsonFactory.java +++ b/src/main/java/com/tibiawiki/domain/factories/JsonFactory.java @@ -15,6 +15,7 @@ import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.Objects; import java.util.Optional; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -32,6 +33,7 @@ public class JsonFactory { protected static final String TEMPLATE_TYPE_BOOK = "Book"; protected static final String TEMPLATE_TYPE_LOCATION = "Geography"; private static final String TEMPLATE_TYPE_HUNTING_PLACE = "Hunt"; + private static final String TEMPLATE_TYPE_STREET = "Street"; protected static final String TEMPLATE_TYPE_KEY = "Key"; private static final String SOUNDS = "sounds"; private static final String SPAWN_TYPE = "spawntype"; @@ -91,7 +93,14 @@ public String convertJsonToInfoboxPartOfArticle(@Nullable JSONObject jsonObject, StringBuilder stringBuilder = new StringBuilder(); stringBuilder.append("{{Infobox "); stringBuilder.append(jsonObject.get(TEMPLATE_TYPE)); - stringBuilder.append("|List={{{1|}}}|GetValue={{{GetValue|}}}").append("\n"); + + // Don't add this line with Location and Street templates + if (!Objects.equals(jsonObject.get(TEMPLATE_TYPE), TEMPLATE_TYPE_LOCATION) && + !Objects.equals(jsonObject.get(TEMPLATE_TYPE), TEMPLATE_TYPE_STREET)) { + stringBuilder.append("|List={{{1|}}}|GetValue={{{GetValue|}}}"); + } + + stringBuilder.append("\n"); constructKeyValuePairs(jsonObject, fieldOrder, stringBuilder); diff --git a/src/main/java/com/tibiawiki/domain/objects/NPC.java b/src/main/java/com/tibiawiki/domain/objects/NPC.java index ebde6ee..8419811 100644 --- a/src/main/java/com/tibiawiki/domain/objects/NPC.java +++ b/src/main/java/com/tibiawiki/domain/objects/NPC.java @@ -8,6 +8,7 @@ import lombok.Getter; import org.springframework.stereotype.Component; +import java.math.BigDecimal; import java.util.Arrays; import java.util.List; @@ -25,20 +26,20 @@ public class NPC extends WikiObject { private final City city; private final City city2; private final String street; - private final Double posx; - private final Double posy; + private final BigDecimal posx; + private final BigDecimal posy; private final Integer posz; - private final Double posx2; - private final Double posy2; + private final BigDecimal posx2; + private final BigDecimal posy2; private final Integer posz2; - private final Double posx3; - private final Double posy3; + private final BigDecimal posx3; + private final BigDecimal posy3; private final Integer posz3; - private final Double posx4; - private final Double posy4; + private final BigDecimal posx4; + private final BigDecimal posy4; private final Integer posz4; - private final Double posx5; - private final Double posy5; + private final BigDecimal posx5; + private final BigDecimal posy5; private final Integer posz5; private final Gender gender; private final String race; @@ -84,9 +85,9 @@ private NPC() { @Builder private NPC(String name, String actualname, String implemented, String notes, String history, Status status, String job, String job2, String job3, String job4, String job5, String job6, String location, City city, - City city2, String street, Double posx, Double posy, Integer posz, Double posx2, Double posy2, - Integer posz2, Double posx3, Double posy3, Integer posz3, Double posx4, Double posy4, Integer posz4, - Double posx5, Double posy5, Integer posz5, Gender gender, String race, YesNo buysell, String buys, + City city2, String street, BigDecimal posx, BigDecimal posy, Integer posz, BigDecimal posx2, BigDecimal posy2, + Integer posz2, BigDecimal posx3, BigDecimal posy3, Integer posz3, BigDecimal posx4, BigDecimal posy4, Integer posz4, + BigDecimal posx5, BigDecimal posy5, Integer posz5, Gender gender, String race, YesNo buysell, String buys, String sells, List sounds) { super(name, null, actualname, null, implemented, notes, history, status); this.job = job; diff --git a/src/main/java/com/tibiawiki/serviceinterface/HuntingPlacesResource.java b/src/main/java/com/tibiawiki/serviceinterface/HuntingPlacesResource.java index 3bbb4a3..09f2d6c 100644 --- a/src/main/java/com/tibiawiki/serviceinterface/HuntingPlacesResource.java +++ b/src/main/java/com/tibiawiki/serviceinterface/HuntingPlacesResource.java @@ -1,7 +1,6 @@ package com.tibiawiki.serviceinterface; import com.tibiawiki.domain.objects.HuntingPlace; -import com.tibiawiki.domain.objects.validation.ValidationException; import com.tibiawiki.process.ModifyAny; import com.tibiawiki.process.RetrieveHuntingPlaces; import io.swagger.annotations.Api; @@ -70,13 +69,14 @@ public Response getHuntingPlacesByName(@PathParam("name") String name) { @Produces(MediaType.APPLICATION_JSON) @Consumes(MediaType.APPLICATION_JSON) public Response putHuntingPlace(HuntingPlace huntingPlace, @HeaderParam("X-WIKI-Edit-Summary") String editSummary) { - return modifyAny.modify(huntingPlace, editSummary) - .map(a -> Response.ok() - .entity(a) - .header("Access-Control-Allow-Origin", "*") - .build()) - .recover(ValidationException.class, e -> Response.status(Response.Status.BAD_REQUEST).entity(e.getMessage()).build()) - .recover(e -> Response.serverError().build()) - .get(); + return Response.status(501).build(); +// return modifyAny.modify(huntingPlace, editSummary) +// .map(a -> Response.ok() +// .entity(a) +// .header("Access-Control-Allow-Origin", "*") +// .build()) +// .recover(ValidationException.class, e -> Response.status(Response.Status.BAD_REQUEST).entity(e.getMessage()).build()) +// .recover(e -> Response.serverError().build()) +// .get(); } } diff --git a/src/test/java/com/tibiawiki/domain/factories/JsonFactoryTest.java b/src/test/java/com/tibiawiki/domain/factories/JsonFactoryTest.java index 7c62d61..7f21ebb 100644 --- a/src/test/java/com/tibiawiki/domain/factories/JsonFactoryTest.java +++ b/src/test/java/com/tibiawiki/domain/factories/JsonFactoryTest.java @@ -863,10 +863,6 @@ private JSONObject makeMissileJson(Missile missile) { return new JSONObject(objectMapper.convertValue(missile, Map.class)).put("templateType", "Missile"); } - /** - * FIXME enable this test when the factory is make to work (not always List and GetValue parameters) - */ - @Disabled @Test void testConvertJsonToInfoboxPartOfArticle_Location() { final Location location = makeLocation(); @@ -889,10 +885,6 @@ private JSONObject makeMountJson(Mount mount) { return new JSONObject(objectMapper.convertValue(mount, Map.class)).put("templateType", "Mount"); } - /** - * FIXME enable this test when the factory is make to work (posx, posy etc. as doubles was a bad idea, can't set scale) - */ - @Disabled @Test void testConvertJsonToInfoboxPartOfArticle_NPC() { final NPC npc = makeNPC(); @@ -908,8 +900,8 @@ private NPC makeNPC() { .job2("Weapon Shopkeeper") .job3("Armor Shopkeeper") .location("[[Temple Street]] in [[Thais]].") - .posx(126.104) - .posy(125.200) + .posx(BigDecimal.valueOf(126.104).setScale(3, RoundingMode.HALF_UP)) + .posy(BigDecimal.valueOf(125.200).setScale(3, RoundingMode.HALF_UP)) .posz(7) .gender(Gender.MALE) .race("Human") @@ -926,10 +918,6 @@ private JSONObject makeNPCJson(NPC npc) { return new JSONObject(objectMapper.convertValue(npc, Map.class)).put("templateType", "NPC"); } - /** - * FIXME enable this test when the factory is make to work (not always List and GetValue parameters) - */ - @Disabled @Test void testConvertJsonToInfoboxPartOfArticle_Street() { final Street street = makeStreet(); From f3321bba75434aa1a1d2e639ac6fd9c2f6f521dd Mon Sep 17 00:00:00 2001 From: Benjamin Komen Date: Sat, 8 Dec 2018 14:03:55 +0100 Subject: [PATCH 18/19] Also support hunting place modifications. --- .../domain/factories/JsonFactory.java | 48 ++++++++---- .../domain/objects/HuntingPlaceSkills.java | 2 +- .../HuntingPlacesResource.java | 18 ++--- .../domain/factories/JsonFactoryTest.java | 74 ++++++++++++------- 4 files changed, 92 insertions(+), 50 deletions(-) diff --git a/src/main/java/com/tibiawiki/domain/factories/JsonFactory.java b/src/main/java/com/tibiawiki/domain/factories/JsonFactory.java index 058c77c..b284029 100644 --- a/src/main/java/com/tibiawiki/domain/factories/JsonFactory.java +++ b/src/main/java/com/tibiawiki/domain/factories/JsonFactory.java @@ -1,6 +1,7 @@ package com.tibiawiki.domain.factories; import com.google.common.base.Strings; +import com.tibiawiki.domain.objects.HuntingPlaceSkills; import com.tibiawiki.domain.utils.TemplateUtils; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -133,14 +134,10 @@ private void constructKeyValuePairs(@NotNull JSONObject jsonObject, List } else if (ITEM_ID.equals(key)) { sb.append(makeCommaSeparatedStringList(jsonObject, key, (JSONArray) value)); } else if (LOWER_LEVELS.equals(key)) { - sb.append(makeSkillsTable(jsonObject, key, (JSONArray) value)); + sb.append(makeSkillsTable(jsonObject, key, (JSONArray) value, HuntingPlaceSkills.fieldOrder())); } else { sb.append(makeCommaSeparatedStringList(jsonObject, key, (JSONArray) value)); } - - } else if (value instanceof JSONObject) { - // TODO check if this works - constructKeyValuePairs(((JSONObject) value), fieldOrder, sb); } else { String paddedKey = Strings.padEnd(key, getMaxFieldLength(jsonObject), ' '); sb.append("| ") @@ -349,6 +346,13 @@ private int getMaxFieldLength(@NotNull JSONObject jsonObject) { .orElse(0); } + private int getMaxFieldLength(@NotNull Map map) { + return map.keySet().stream() + .filter(String.class::isInstance) + .mapToInt(s -> String.valueOf(s).length()) + .max() + .orElse(0); + } @NotNull private String makeTemplateList(JSONObject jsonObject, String key, JSONArray jsonArray, String templateName) { @@ -378,16 +382,34 @@ private String makeLootTable(JSONObject jsonObject, String key, JSONArray jsonAr return "| " + paddedKey + " = {{Loot Table\n |" + value + "\n}}\n"; } - /** - * TODO implement this method correctly - */ - private String makeSkillsTable(JSONObject jsonObject, String key, JSONArray jsonArray) { + private String makeSkillsTable(JSONObject jsonObject, String key, JSONArray jsonArray, List fieldOrder) { + final StringBuilder result = new StringBuilder("| "); final String paddedKey = Strings.padEnd(key, getMaxFieldLength(jsonObject), ' '); - final String value = jsonArray.toList().stream() - .map(o -> ((Map) o).get("").toString()) - .collect(Collectors.joining("\n |")); + result.append(paddedKey); + result.append(" = \n"); + + for (Object huntSkillsJsonObject : jsonArray.toList()) { + result.append(" {{Infobox Hunt Skills\n"); + + Map map = (Map) huntSkillsJsonObject; + + for (String huntSkillsKey : fieldOrder) { + String paddedHuntSkillsKey = Strings.padEnd(huntSkillsKey, getMaxFieldLength(map), ' '); + Object value = map.get(huntSkillsKey); + + if (value != null) { + result.append(" | ") + .append(paddedHuntSkillsKey) + .append(" = ") + .append(value) + .append("\n"); + } + } + + result.append(" }}\n"); + } - return "| " + paddedKey + " = \n {{Infobox Hunt Skills\n |" + value + "\n}}\n"; + return result.toString(); } private String makeLootItem(Object obj) { diff --git a/src/main/java/com/tibiawiki/domain/objects/HuntingPlaceSkills.java b/src/main/java/com/tibiawiki/domain/objects/HuntingPlaceSkills.java index c4d1acf..c26f423 100644 --- a/src/main/java/com/tibiawiki/domain/objects/HuntingPlaceSkills.java +++ b/src/main/java/com/tibiawiki/domain/objects/HuntingPlaceSkills.java @@ -44,7 +44,7 @@ private HuntingPlaceSkills() { @JsonBackReference private HuntingPlace huntingPlace; - public List fieldOrder() { + public static List fieldOrder() { return Arrays.asList("areaname", "lvlknights", "lvlpaladins", "lvlmages", "skknights", "skpaladins", "skmages", "defknights", "defpaladins", "defmages"); } diff --git a/src/main/java/com/tibiawiki/serviceinterface/HuntingPlacesResource.java b/src/main/java/com/tibiawiki/serviceinterface/HuntingPlacesResource.java index 09f2d6c..3bbb4a3 100644 --- a/src/main/java/com/tibiawiki/serviceinterface/HuntingPlacesResource.java +++ b/src/main/java/com/tibiawiki/serviceinterface/HuntingPlacesResource.java @@ -1,6 +1,7 @@ package com.tibiawiki.serviceinterface; import com.tibiawiki.domain.objects.HuntingPlace; +import com.tibiawiki.domain.objects.validation.ValidationException; import com.tibiawiki.process.ModifyAny; import com.tibiawiki.process.RetrieveHuntingPlaces; import io.swagger.annotations.Api; @@ -69,14 +70,13 @@ public Response getHuntingPlacesByName(@PathParam("name") String name) { @Produces(MediaType.APPLICATION_JSON) @Consumes(MediaType.APPLICATION_JSON) public Response putHuntingPlace(HuntingPlace huntingPlace, @HeaderParam("X-WIKI-Edit-Summary") String editSummary) { - return Response.status(501).build(); -// return modifyAny.modify(huntingPlace, editSummary) -// .map(a -> Response.ok() -// .entity(a) -// .header("Access-Control-Allow-Origin", "*") -// .build()) -// .recover(ValidationException.class, e -> Response.status(Response.Status.BAD_REQUEST).entity(e.getMessage()).build()) -// .recover(e -> Response.serverError().build()) -// .get(); + return modifyAny.modify(huntingPlace, editSummary) + .map(a -> Response.ok() + .entity(a) + .header("Access-Control-Allow-Origin", "*") + .build()) + .recover(ValidationException.class, e -> Response.status(Response.Status.BAD_REQUEST).entity(e.getMessage()).build()) + .recover(e -> Response.serverError().build()) + .get(); } } diff --git a/src/test/java/com/tibiawiki/domain/factories/JsonFactoryTest.java b/src/test/java/com/tibiawiki/domain/factories/JsonFactoryTest.java index 7f21ebb..9b5e14f 100644 --- a/src/test/java/com/tibiawiki/domain/factories/JsonFactoryTest.java +++ b/src/test/java/com/tibiawiki/domain/factories/JsonFactoryTest.java @@ -43,7 +43,6 @@ import org.json.JSONArray; import org.json.JSONObject; import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; import java.math.BigDecimal; @@ -385,16 +384,28 @@ void testConvertJsonToInfoboxPartOfArticle_Key() { "| defmages = 1\n" + "| lowerlevels = \n" + " {{Infobox Hunt Skills\n" + - " | areaname = Demons\n" + - " | lvlknights = 130\n" + - " | lvlpaladins = 130\n" + - " | lvlmages = 130\n" + - " | skknights = 1\n" + - " | skpaladins = 1\n" + - " | skmages = 1\n" + - " | defknights = 1\n" + - " | defpaladins = 1\n" + - " | defmages = 1\n" + + " | areaname = Demons\n" + + " | lvlknights = 130\n" + + " | lvlpaladins = 130\n" + + " | lvlmages = 130\n" + + " | skknights = 1\n" + + " | skpaladins = 1\n" + + " | skmages = 1\n" + + " | defknights = 1\n" + + " | defpaladins = 1\n" + + " | defmages = 1\n" + + " }}\n" + + " {{Infobox Hunt Skills\n" + + " | areaname = Another Area (Past Teleporter)\n" + + " | lvlknights = 230\n" + + " | lvlpaladins = 230\n" + + " | lvlmages = 230\n" + + " | skknights = 2\n" + + " | skpaladins = 2\n" + + " | skmages = 2\n" + + " | defknights = 2\n" + + " | defpaladins = 2\n" + + " | defmages = 2\n" + " }}\n" + "| loot = Good\n" + "| exp = Good\n" + @@ -837,10 +848,6 @@ private JSONObject makeLocationJson(Location location) { return new JSONObject(objectMapper.convertValue(location, Map.class)).put("templateType", "Geography"); } - /** - * FIXME enable this test when the factory is make to work - */ - @Disabled @Test void testConvertJsonToInfoboxPartOfArticle_HuntingPlace() { final HuntingPlace huntingPlace = makeHuntingPlace(); @@ -1057,18 +1064,31 @@ private HuntingPlace makeHuntingPlace() { .defknights("75") .defpaladins("1") .defmages("1") - .lowerlevels(Collections.singletonList(HuntingPlaceSkills.builder() - .areaname("Demons") - .lvlknights("130") - .lvlpaladins("130") - .lvlmages("130") - .skknights("1") - .skpaladins("1") - .skmages("1") - .defknights("1") - .defpaladins("1") - .defmages("1") - .build())) + .lowerlevels(Arrays.asList(HuntingPlaceSkills.builder() + .areaname("Demons") + .lvlknights("130") + .lvlpaladins("130") + .lvlmages("130") + .skknights("1") + .skpaladins("1") + .skmages("1") + .defknights("1") + .defpaladins("1") + .defmages("1") + .build(), + HuntingPlaceSkills.builder() + .areaname("Another Area (Past Teleporter)") + .lvlknights("230") + .lvlpaladins("230") + .lvlmages("230") + .skknights("2") + .skpaladins("2") + .skmages("2") + .defknights("2") + .defpaladins("2") + .defmages("2") + .build()) + ) .exp("Good") .loot("Good") .bestloot("Reins") From 9b7f2bed35d366fa71ead228004a94305d8e1fc8 Mon Sep 17 00:00:00 2001 From: Benjamin Komen Date: Sat, 8 Dec 2018 14:14:57 +0100 Subject: [PATCH 19/19] Removing CORS headers and adding one global filter. --- .../serviceinterface/AchievementsResource.java | 3 --- .../serviceinterface/BooksResource.java | 3 --- .../serviceinterface/BuildingsResource.java | 3 --- .../serviceinterface/CorpsesResource.java | 3 --- .../serviceinterface/CreaturesResource.java | 3 --- .../serviceinterface/EffectsResource.java | 3 --- .../HuntingPlacesResource.java | 3 --- .../serviceinterface/ItemsResource.java | 3 --- .../serviceinterface/KeysResource.java | 3 --- .../serviceinterface/LocationsResource.java | 3 --- .../serviceinterface/MissilesResource.java | 3 --- .../serviceinterface/MountsResource.java | 3 --- .../serviceinterface/NPCsResource.java | 3 --- .../serviceinterface/ObjectsResource.java | 3 --- .../serviceinterface/OutfitsResource.java | 3 --- .../serviceinterface/QuestsResource.java | 3 --- .../serviceinterface/SpellsResource.java | 3 --- .../serviceinterface/StreetsResource.java | 3 --- .../config/CORSResponseFilter.java | 18 ++++++++++++++++++ .../serviceinterface/config/JerseyConfig.java | 1 + 20 files changed, 19 insertions(+), 54 deletions(-) create mode 100644 src/main/java/com/tibiawiki/serviceinterface/config/CORSResponseFilter.java diff --git a/src/main/java/com/tibiawiki/serviceinterface/AchievementsResource.java b/src/main/java/com/tibiawiki/serviceinterface/AchievementsResource.java index 2a26650..e833256 100644 --- a/src/main/java/com/tibiawiki/serviceinterface/AchievementsResource.java +++ b/src/main/java/com/tibiawiki/serviceinterface/AchievementsResource.java @@ -51,7 +51,6 @@ public Response getAchievements(@ApiParam(value = "optionally expands the result ? retrieveAchievements.getAchievementsJSON().map(JSONObject::toMap) : retrieveAchievements.getAchievementsList() ) - .header("Access-Control-Allow-Origin", "*") .build(); } @@ -67,7 +66,6 @@ public Response getAchievementsByName(@PathParam("name") String name) { return retrieveAchievements.getAchievementJSON(name) .map(a -> Response.ok() .entity(a.toString(2)) - .header("Access-Control-Allow-Origin", "*") .build()) .orElseGet(() -> Response.status(Response.Status.NOT_FOUND) .build()); @@ -85,7 +83,6 @@ public Response putAchievement(Achievement achievement, @HeaderParam("X-WIKI-Edi return modifyAny.modify(achievement, editSummary) .map(a -> Response.ok() .entity(a) - .header("Access-Control-Allow-Origin", "*") .build()) .recover(ValidationException.class, e -> Response.status(Response.Status.BAD_REQUEST).entity(e.getMessage()).build()) .recover(e -> Response.serverError().build()) diff --git a/src/main/java/com/tibiawiki/serviceinterface/BooksResource.java b/src/main/java/com/tibiawiki/serviceinterface/BooksResource.java index fdf7563..b3df405 100644 --- a/src/main/java/com/tibiawiki/serviceinterface/BooksResource.java +++ b/src/main/java/com/tibiawiki/serviceinterface/BooksResource.java @@ -44,7 +44,6 @@ public Response getBooks(@QueryParam("expand") Boolean expand) { ? retrieveBooks.getBooksJSON().map(JSONObject::toMap) : retrieveBooks.getBooksList() ) - .header("Access-Control-Allow-Origin", "*") .build(); } @@ -55,7 +54,6 @@ public Response getBooksByName(@PathParam("name") String name) { return retrieveBooks.getBookJSON(name) .map(a -> Response.ok() .entity(a.toString(2)) - .header("Access-Control-Allow-Origin", "*") .build()) .orElseGet(() -> Response.status(Response.Status.NOT_FOUND) .build()); @@ -73,7 +71,6 @@ public Response putBook(Book book, @HeaderParam("X-WIKI-Edit-Summary") String ed return modifyAny.modify(book, editSummary) .map(a -> Response.ok() .entity(a) - .header("Access-Control-Allow-Origin", "*") .build()) .recover(ValidationException.class, e -> Response.status(Response.Status.BAD_REQUEST).entity(e.getMessage()).build()) .recover(e -> Response.serverError().build()) diff --git a/src/main/java/com/tibiawiki/serviceinterface/BuildingsResource.java b/src/main/java/com/tibiawiki/serviceinterface/BuildingsResource.java index 56f5fd7..c894cc3 100644 --- a/src/main/java/com/tibiawiki/serviceinterface/BuildingsResource.java +++ b/src/main/java/com/tibiawiki/serviceinterface/BuildingsResource.java @@ -44,7 +44,6 @@ public Response getBuildings(@QueryParam("expand") Boolean expand) { ? retrieveBuildings.getBuildingsJSON().map(JSONObject::toMap) : retrieveBuildings.getBuildingsList() ) - .header("Access-Control-Allow-Origin", "*") .build(); } @@ -55,7 +54,6 @@ public Response getBuildingsByName(@PathParam("name") String name) { return retrieveBuildings.getBuildingJSON(name) .map(a -> Response.ok() .entity(a.toString(2)) - .header("Access-Control-Allow-Origin", "*") .build()) .orElseGet(() -> Response.status(Response.Status.NOT_FOUND) .build()); @@ -73,7 +71,6 @@ public Response putBuilding(Building building, @HeaderParam("X-WIKI-Edit-Summary return modifyAny.modify(building, editSummary) .map(a -> Response.ok() .entity(a) - .header("Access-Control-Allow-Origin", "*") .build()) .recover(ValidationException.class, e -> Response.status(Response.Status.BAD_REQUEST).entity(e.getMessage()).build()) .recover(e -> Response.serverError().build()) diff --git a/src/main/java/com/tibiawiki/serviceinterface/CorpsesResource.java b/src/main/java/com/tibiawiki/serviceinterface/CorpsesResource.java index 2f7a6ce..bbf006b 100644 --- a/src/main/java/com/tibiawiki/serviceinterface/CorpsesResource.java +++ b/src/main/java/com/tibiawiki/serviceinterface/CorpsesResource.java @@ -44,7 +44,6 @@ public Response getCorpses(@QueryParam("expand") Boolean expand) { ? retrieveCorpses.getCorpsesJSON().map(JSONObject::toMap) : retrieveCorpses.getCorpsesList() ) - .header("Access-Control-Allow-Origin", "*") .build(); } @@ -55,7 +54,6 @@ public Response getCorpsesByName(@PathParam("name") String name) { return retrieveCorpses.getCorpseJSON(name) .map(a -> Response.ok() .entity(a.toString(2)) - .header("Access-Control-Allow-Origin", "*") .build()) .orElseGet(() -> Response.status(Response.Status.NOT_FOUND) .build()); @@ -73,7 +71,6 @@ public Response putCorpse(Corpse corpse, @HeaderParam("X-WIKI-Edit-Summary") Str return modifyAny.modify(corpse, editSummary) .map(a -> Response.ok() .entity(a) - .header("Access-Control-Allow-Origin", "*") .build()) .recover(ValidationException.class, e -> Response.status(Response.Status.BAD_REQUEST).entity(e.getMessage()).build()) .recover(e -> Response.serverError().build()) diff --git a/src/main/java/com/tibiawiki/serviceinterface/CreaturesResource.java b/src/main/java/com/tibiawiki/serviceinterface/CreaturesResource.java index 6da52a9..1719aa5 100644 --- a/src/main/java/com/tibiawiki/serviceinterface/CreaturesResource.java +++ b/src/main/java/com/tibiawiki/serviceinterface/CreaturesResource.java @@ -44,7 +44,6 @@ public Response getCreatures(@QueryParam("expand") Boolean expand) { ? retrieveCreatures.getCreaturesJSON().map(JSONObject::toMap) : retrieveCreatures.getCreaturesList() ) - .header("Access-Control-Allow-Origin", "*") .build(); } @@ -55,7 +54,6 @@ public Response getCreatureByName(@PathParam("name") String name) { return retrieveCreatures.getCreatureJSON(name) .map(a -> Response.ok() .entity(a.toString(2)) - .header("Access-Control-Allow-Origin", "*") .build()) .orElseGet(() -> Response.status(Response.Status.NOT_FOUND) .build()); @@ -73,7 +71,6 @@ public Response putCreature(Creature creature, @HeaderParam("X-WIKI-Edit-Summary return modifyAny.modify(creature, editSummary) .map(a -> Response.ok() .entity(a) - .header("Access-Control-Allow-Origin", "*") .build()) .recover(ValidationException.class, e -> Response.status(Response.Status.BAD_REQUEST).entity(e.getMessage()).build()) .recover(e -> Response.serverError().build()) diff --git a/src/main/java/com/tibiawiki/serviceinterface/EffectsResource.java b/src/main/java/com/tibiawiki/serviceinterface/EffectsResource.java index e80b676..c38f5d5 100644 --- a/src/main/java/com/tibiawiki/serviceinterface/EffectsResource.java +++ b/src/main/java/com/tibiawiki/serviceinterface/EffectsResource.java @@ -44,7 +44,6 @@ public Response getEffects(@QueryParam("expand") Boolean expand) { ? retrieveEffects.getEffectsJSON().map(JSONObject::toMap) : retrieveEffects.getEffectsList() ) - .header("Access-Control-Allow-Origin", "*") .build(); } @@ -55,7 +54,6 @@ public Response getEffectsByName(@PathParam("name") String name) { return retrieveEffects.getEffectJSON(name) .map(a -> Response.ok() .entity(a.toString(2)) - .header("Access-Control-Allow-Origin", "*") .build()) .orElseGet(() -> Response.status(Response.Status.NOT_FOUND) .build()); @@ -73,7 +71,6 @@ public Response putEffect(Effect effect, @HeaderParam("X-WIKI-Edit-Summary") Str return modifyAny.modify(effect, editSummary) .map(a -> Response.ok() .entity(a) - .header("Access-Control-Allow-Origin", "*") .build()) .recover(ValidationException.class, e -> Response.status(Response.Status.BAD_REQUEST).entity(e.getMessage()).build()) .recover(e -> Response.serverError().build()) diff --git a/src/main/java/com/tibiawiki/serviceinterface/HuntingPlacesResource.java b/src/main/java/com/tibiawiki/serviceinterface/HuntingPlacesResource.java index 3bbb4a3..f4b1f32 100644 --- a/src/main/java/com/tibiawiki/serviceinterface/HuntingPlacesResource.java +++ b/src/main/java/com/tibiawiki/serviceinterface/HuntingPlacesResource.java @@ -44,7 +44,6 @@ public Response getHuntingPlaces(@QueryParam("expand") Boolean expand) { ? retrieveHuntingPlaces.getHuntingPlacesJSON().map(JSONObject::toMap) : retrieveHuntingPlaces.getHuntingPlacesList() ) - .header("Access-Control-Allow-Origin", "*") .build(); } @@ -55,7 +54,6 @@ public Response getHuntingPlacesByName(@PathParam("name") String name) { return retrieveHuntingPlaces.getHuntingPlaceJSON(name) .map(a -> Response.ok() .entity(a.toString(2)) - .header("Access-Control-Allow-Origin", "*") .build()) .orElseGet(() -> Response.status(Response.Status.NOT_FOUND) .build()); @@ -73,7 +71,6 @@ public Response putHuntingPlace(HuntingPlace huntingPlace, @HeaderParam("X-WIKI- return modifyAny.modify(huntingPlace, editSummary) .map(a -> Response.ok() .entity(a) - .header("Access-Control-Allow-Origin", "*") .build()) .recover(ValidationException.class, e -> Response.status(Response.Status.BAD_REQUEST).entity(e.getMessage()).build()) .recover(e -> Response.serverError().build()) diff --git a/src/main/java/com/tibiawiki/serviceinterface/ItemsResource.java b/src/main/java/com/tibiawiki/serviceinterface/ItemsResource.java index 08ae62b..74ff03b 100644 --- a/src/main/java/com/tibiawiki/serviceinterface/ItemsResource.java +++ b/src/main/java/com/tibiawiki/serviceinterface/ItemsResource.java @@ -44,7 +44,6 @@ public Response getItems(@QueryParam("expand") Boolean expand) { ? retrieveItems.getItemsJSON().map(JSONObject::toMap) : retrieveItems.getItemsList() ) - .header("Access-Control-Allow-Origin", "*") .build(); } @@ -55,7 +54,6 @@ public Response getItemsByName(@PathParam("name") String name) { return retrieveItems.getItemJSON(name) .map(a -> Response.ok() .entity(a.toString(2)) - .header("Access-Control-Allow-Origin", "*") .build()) .orElseGet(() -> Response.status(Response.Status.NOT_FOUND) .build()); @@ -73,7 +71,6 @@ public Response putItem(Item item, @HeaderParam("X-WIKI-Edit-Summary") String ed return modifyAny.modify(item, editSummary) .map(a -> Response.ok() .entity(a) - .header("Access-Control-Allow-Origin", "*") .build()) .recover(ValidationException.class, e -> Response.status(Response.Status.BAD_REQUEST).entity(e.getMessage()).build()) .recover(e -> Response.serverError().build()) diff --git a/src/main/java/com/tibiawiki/serviceinterface/KeysResource.java b/src/main/java/com/tibiawiki/serviceinterface/KeysResource.java index ada95ac..47b732b 100644 --- a/src/main/java/com/tibiawiki/serviceinterface/KeysResource.java +++ b/src/main/java/com/tibiawiki/serviceinterface/KeysResource.java @@ -44,7 +44,6 @@ public Response getKeys(@QueryParam("expand") Boolean expand) { ? retrieveKeys.getKeysJSON().map(JSONObject::toMap) : retrieveKeys.getKeysList() ) - .header("Access-Control-Allow-Origin", "*") .build(); } @@ -55,7 +54,6 @@ public Response getKeysByName(@PathParam("name") String name) { return retrieveKeys.getKeyJSON(name) .map(a -> Response.ok() .entity(a.toString(2)) - .header("Access-Control-Allow-Origin", "*") .build()) .orElseGet(() -> Response.status(Response.Status.NOT_FOUND) .build()); @@ -73,7 +71,6 @@ public Response putKey(Key key, @HeaderParam("X-WIKI-Edit-Summary") String editS return modifyAny.modify(key, editSummary) .map(a -> Response.ok() .entity(a) - .header("Access-Control-Allow-Origin", "*") .build()) .recover(ValidationException.class, e -> Response.status(Response.Status.BAD_REQUEST).entity(e.getMessage()).build()) .recover(e -> Response.serverError().build()) diff --git a/src/main/java/com/tibiawiki/serviceinterface/LocationsResource.java b/src/main/java/com/tibiawiki/serviceinterface/LocationsResource.java index 393b6db..7ec1637 100644 --- a/src/main/java/com/tibiawiki/serviceinterface/LocationsResource.java +++ b/src/main/java/com/tibiawiki/serviceinterface/LocationsResource.java @@ -44,7 +44,6 @@ public Response getLocations(@QueryParam("expand") Boolean expand) { ? retrieveLocations.getLocationsJSON().map(JSONObject::toMap) : retrieveLocations.getLocationsList() ) - .header("Access-Control-Allow-Origin", "*") .build(); } @@ -55,7 +54,6 @@ public Response getLocationsByName(@PathParam("name") String name) { return retrieveLocations.getLocationJSON(name) .map(a -> Response.ok() .entity(a.toString(2)) - .header("Access-Control-Allow-Origin", "*") .build()) .orElseGet(() -> Response.status(Response.Status.NOT_FOUND) .build()); @@ -73,7 +71,6 @@ public Response putLocation(Location location, @HeaderParam("X-WIKI-Edit-Summary return modifyAny.modify(location, editSummary) .map(a -> Response.ok() .entity(a) - .header("Access-Control-Allow-Origin", "*") .build()) .recover(ValidationException.class, e -> Response.status(Response.Status.BAD_REQUEST).entity(e.getMessage()).build()) .recover(e -> Response.serverError().build()) diff --git a/src/main/java/com/tibiawiki/serviceinterface/MissilesResource.java b/src/main/java/com/tibiawiki/serviceinterface/MissilesResource.java index 52b3975..9ea88bd 100644 --- a/src/main/java/com/tibiawiki/serviceinterface/MissilesResource.java +++ b/src/main/java/com/tibiawiki/serviceinterface/MissilesResource.java @@ -44,7 +44,6 @@ public Response getMissiles(@QueryParam("expand") Boolean expand) { ? retrieveMissiles.getMissilesJSON().map(JSONObject::toMap) : retrieveMissiles.getMissilesList() ) - .header("Access-Control-Allow-Origin", "*") .build(); } @@ -55,7 +54,6 @@ public Response getMissilesByName(@PathParam("name") String name) { return retrieveMissiles.getMissileJSON(name) .map(a -> Response.ok() .entity(a.toString(2)) - .header("Access-Control-Allow-Origin", "*") .build()) .orElseGet(() -> Response.status(Response.Status.NOT_FOUND) .build()); @@ -73,7 +71,6 @@ public Response putMissile(Missile missile, @HeaderParam("X-WIKI-Edit-Summary") return modifyAny.modify(missile, editSummary) .map(a -> Response.ok() .entity(a) - .header("Access-Control-Allow-Origin", "*") .build()) .recover(ValidationException.class, e -> Response.status(Response.Status.BAD_REQUEST).entity(e.getMessage()).build()) .recover(e -> Response.serverError().build()) diff --git a/src/main/java/com/tibiawiki/serviceinterface/MountsResource.java b/src/main/java/com/tibiawiki/serviceinterface/MountsResource.java index 57e9b5d..e205e0b 100644 --- a/src/main/java/com/tibiawiki/serviceinterface/MountsResource.java +++ b/src/main/java/com/tibiawiki/serviceinterface/MountsResource.java @@ -44,7 +44,6 @@ public Response getMounts(@QueryParam("expand") Boolean expand) { ? retrieveMounts.getMountsJSON().map(JSONObject::toMap) : retrieveMounts.getMountsList() ) - .header("Access-Control-Allow-Origin", "*") .build(); } @@ -55,7 +54,6 @@ public Response getMountsByName(@PathParam("name") String name) { return retrieveMounts.getMountJSON(name) .map(a -> Response.ok() .entity(a.toString(2)) - .header("Access-Control-Allow-Origin", "*") .build()) .orElseGet(() -> Response.status(Response.Status.NOT_FOUND) .build()); @@ -73,7 +71,6 @@ public Response putMount(Mount mount, @HeaderParam("X-WIKI-Edit-Summary") String return modifyAny.modify(mount, editSummary) .map(a -> Response.ok() .entity(a) - .header("Access-Control-Allow-Origin", "*") .build()) .recover(ValidationException.class, e -> Response.status(Response.Status.BAD_REQUEST).entity(e.getMessage()).build()) .recover(e -> Response.serverError().build()) diff --git a/src/main/java/com/tibiawiki/serviceinterface/NPCsResource.java b/src/main/java/com/tibiawiki/serviceinterface/NPCsResource.java index fde35ef..1ce6a95 100644 --- a/src/main/java/com/tibiawiki/serviceinterface/NPCsResource.java +++ b/src/main/java/com/tibiawiki/serviceinterface/NPCsResource.java @@ -44,7 +44,6 @@ public Response getNPCs(@QueryParam("expand") Boolean expand) { ? retrieveNPCs.getNPCsJSON().map(JSONObject::toMap) : retrieveNPCs.getNPCsList() ) - .header("Access-Control-Allow-Origin", "*") .build(); } @@ -55,7 +54,6 @@ public Response getNPCsByName(@PathParam("name") String name) { return retrieveNPCs.getNPCJSON(name) .map(a -> Response.ok() .entity(a.toString(2)) - .header("Access-Control-Allow-Origin", "*") .build()) .orElseGet(() -> Response.status(Response.Status.NOT_FOUND) .build()); @@ -73,7 +71,6 @@ public Response putNPC(NPC npc, @HeaderParam("X-WIKI-Edit-Summary") String editS return modifyAny.modify(npc, editSummary) .map(a -> Response.ok() .entity(a) - .header("Access-Control-Allow-Origin", "*") .build()) .recover(ValidationException.class, e -> Response.status(Response.Status.BAD_REQUEST).entity(e.getMessage()).build()) .recover(e -> Response.serverError().build()) diff --git a/src/main/java/com/tibiawiki/serviceinterface/ObjectsResource.java b/src/main/java/com/tibiawiki/serviceinterface/ObjectsResource.java index 05c42d4..c09f422 100644 --- a/src/main/java/com/tibiawiki/serviceinterface/ObjectsResource.java +++ b/src/main/java/com/tibiawiki/serviceinterface/ObjectsResource.java @@ -44,7 +44,6 @@ public Response getObjects(@QueryParam("expand") Boolean expand) { ? retrieveObjects.getObjectsJSON().map(JSONObject::toMap) : retrieveObjects.getObjectsList() ) - .header("Access-Control-Allow-Origin", "*") .build(); } @@ -55,7 +54,6 @@ public Response getObjectsByName(@PathParam("name") String name) { return retrieveObjects.getObjectJSON(name) .map(a -> Response.ok() .entity(a.toString(2)) - .header("Access-Control-Allow-Origin", "*") .build()) .orElseGet(() -> Response.status(Response.Status.NOT_FOUND) .build()); @@ -73,7 +71,6 @@ public Response putTibiaObject(TibiaObject tibiaObject, @HeaderParam("X-WIKI-Edi return modifyAny.modify(tibiaObject, editSummary) .map(a -> Response.ok() .entity(a) - .header("Access-Control-Allow-Origin", "*") .build()) .recover(ValidationException.class, e -> Response.status(Response.Status.BAD_REQUEST).entity(e.getMessage()).build()) .recover(e -> Response.serverError().build()) diff --git a/src/main/java/com/tibiawiki/serviceinterface/OutfitsResource.java b/src/main/java/com/tibiawiki/serviceinterface/OutfitsResource.java index a93f753..3a8c7bd 100644 --- a/src/main/java/com/tibiawiki/serviceinterface/OutfitsResource.java +++ b/src/main/java/com/tibiawiki/serviceinterface/OutfitsResource.java @@ -44,7 +44,6 @@ public Response getOutfits(@QueryParam("expand") Boolean expand) { ? retrieveOutfits.getOutfitsJSON().map(JSONObject::toMap) : retrieveOutfits.getOutfitsList() ) - .header("Access-Control-Allow-Origin", "*") .build(); } @@ -55,7 +54,6 @@ public Response getOutfitsByName(@PathParam("name") String name) { return retrieveOutfits.getOutfitJSON(name) .map(a -> Response.ok() .entity(a.toString(2)) - .header("Access-Control-Allow-Origin", "*") .build()) .orElseGet(() -> Response.status(Response.Status.NOT_FOUND) .build()); @@ -73,7 +71,6 @@ public Response putOutfit(Outfit outfit, @HeaderParam("X-WIKI-Edit-Summary") Str return modifyAny.modify(outfit, editSummary) .map(a -> Response.ok() .entity(a) - .header("Access-Control-Allow-Origin", "*") .build()) .recover(ValidationException.class, e -> Response.status(Response.Status.BAD_REQUEST).entity(e.getMessage()).build()) .recover(e -> Response.serverError().build()) diff --git a/src/main/java/com/tibiawiki/serviceinterface/QuestsResource.java b/src/main/java/com/tibiawiki/serviceinterface/QuestsResource.java index 124227f..4725665 100644 --- a/src/main/java/com/tibiawiki/serviceinterface/QuestsResource.java +++ b/src/main/java/com/tibiawiki/serviceinterface/QuestsResource.java @@ -44,7 +44,6 @@ public Response getQuests(@QueryParam("expand") Boolean expand) { ? retrieveQuests.getQuestsJSON().map(JSONObject::toMap) : retrieveQuests.getQuestsList() ) - .header("Access-Control-Allow-Origin", "*") .build(); } @@ -55,7 +54,6 @@ public Response getQuestsByName(@PathParam("name") String name) { return retrieveQuests.getQuestJSON(name) .map(a -> Response.ok() .entity(a.toString(2)) - .header("Access-Control-Allow-Origin", "*") .build()) .orElseGet(() -> Response.status(Response.Status.NOT_FOUND) .build()); @@ -73,7 +71,6 @@ public Response putQuest(Quest quest, @HeaderParam("X-WIKI-Edit-Summary") String return modifyAny.modify(quest, editSummary) .map(a -> Response.ok() .entity(a) - .header("Access-Control-Allow-Origin", "*") .build()) .recover(ValidationException.class, e -> Response.status(Response.Status.BAD_REQUEST).entity(e.getMessage()).build()) .recover(e -> Response.serverError().build()) diff --git a/src/main/java/com/tibiawiki/serviceinterface/SpellsResource.java b/src/main/java/com/tibiawiki/serviceinterface/SpellsResource.java index 8962c5e..c62ae37 100644 --- a/src/main/java/com/tibiawiki/serviceinterface/SpellsResource.java +++ b/src/main/java/com/tibiawiki/serviceinterface/SpellsResource.java @@ -44,7 +44,6 @@ public Response getSpells(@QueryParam("expand") Boolean expand) { ? retrieveSpells.getSpellsJSON().map(JSONObject::toMap) : retrieveSpells.getSpellsList() ) - .header("Access-Control-Allow-Origin", "*") .build(); } @@ -55,7 +54,6 @@ public Response getSpellsByName(@PathParam("name") String name) { return retrieveSpells.getSpellJSON(name) .map(a -> Response.ok() .entity(a.toString(2)) - .header("Access-Control-Allow-Origin", "*") .build()) .orElseGet(() -> Response.status(Response.Status.NOT_FOUND) .build()); @@ -73,7 +71,6 @@ public Response putSpell(Spell spell, @HeaderParam("X-WIKI-Edit-Summary") String return modifyAny.modify(spell, editSummary) .map(a -> Response.ok() .entity(a) - .header("Access-Control-Allow-Origin", "*") .build()) .recover(ValidationException.class, e -> Response.status(Response.Status.BAD_REQUEST).entity(e.getMessage()).build()) .recover(e -> Response.serverError().build()) diff --git a/src/main/java/com/tibiawiki/serviceinterface/StreetsResource.java b/src/main/java/com/tibiawiki/serviceinterface/StreetsResource.java index b497ffe..52fd38f 100644 --- a/src/main/java/com/tibiawiki/serviceinterface/StreetsResource.java +++ b/src/main/java/com/tibiawiki/serviceinterface/StreetsResource.java @@ -44,7 +44,6 @@ public Response getStreets(@QueryParam("expand") Boolean expand) { ? retrieveStreets.getStreetsJSON().map(JSONObject::toMap) : retrieveStreets.getStreetsList() ) - .header("Access-Control-Allow-Origin", "*") .build(); } @@ -55,7 +54,6 @@ public Response getStreetsByName(@PathParam("name") String name) { return retrieveStreets.getStreetJSON(name) .map(a -> Response.ok() .entity(a.toString(2)) - .header("Access-Control-Allow-Origin", "*") .build()) .orElseGet(() -> Response.status(Response.Status.NOT_FOUND) .build()); @@ -73,7 +71,6 @@ public Response putStreet(Street street, @HeaderParam("X-WIKI-Edit-Summary") Str return modifyAny.modify(street, editSummary) .map(a -> Response.ok() .entity(a) - .header("Access-Control-Allow-Origin", "*") .build()) .recover(ValidationException.class, e -> Response.status(Response.Status.BAD_REQUEST).entity(e.getMessage()).build()) .recover(e -> Response.serverError().build()) diff --git a/src/main/java/com/tibiawiki/serviceinterface/config/CORSResponseFilter.java b/src/main/java/com/tibiawiki/serviceinterface/config/CORSResponseFilter.java new file mode 100644 index 0000000..de37927 --- /dev/null +++ b/src/main/java/com/tibiawiki/serviceinterface/config/CORSResponseFilter.java @@ -0,0 +1,18 @@ +package com.tibiawiki.serviceinterface.config; + +import javax.ws.rs.container.ContainerRequestContext; +import javax.ws.rs.container.ContainerResponseContext; +import javax.ws.rs.container.ContainerResponseFilter; +import javax.ws.rs.core.MultivaluedMap; +import java.io.IOException; + +public class CORSResponseFilter implements ContainerResponseFilter { + + public void filter(ContainerRequestContext requestContext, ContainerResponseContext responseContext) throws IOException { + + MultivaluedMap headers = responseContext.getHeaders(); + headers.add("Access-Control-Allow-Origin", "*"); + headers.add("Access-Control-Allow-Methods", "GET, POST, DELETE, PUT"); + headers.add("Access-Control-Allow-Headers", "X-Requested-With, Content-Type"); + } +} diff --git a/src/main/java/com/tibiawiki/serviceinterface/config/JerseyConfig.java b/src/main/java/com/tibiawiki/serviceinterface/config/JerseyConfig.java index f0733f6..2b4a675 100644 --- a/src/main/java/com/tibiawiki/serviceinterface/config/JerseyConfig.java +++ b/src/main/java/com/tibiawiki/serviceinterface/config/JerseyConfig.java @@ -44,6 +44,7 @@ public void init() { } private void registerEndpoints() { + register(CORSResponseFilter.class); register(AchievementsResource.class); register(BooksResource.class); register(BuildingsResource.class);