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 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/pom.xml b/pom.xml index aaf8ce3..0b6dddb 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 @@ -27,14 +27,17 @@ 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 6.2.1 1.5.21 1.1.1 + 0.9.2 @@ -147,6 +150,14 @@ ${swagger.jersey2.jaxrs.version} + + + io.vavr + vavr + ${vavr.version} + + + @@ -243,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(); + } +} 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/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/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/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..b284029 100644 --- a/src/main/java/com/tibiawiki/domain/factories/JsonFactory.java +++ b/src/main/java/com/tibiawiki/domain/factories/JsonFactory.java @@ -1,5 +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; @@ -14,23 +16,25 @@ 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; import java.util.stream.Collectors; /** - * Conversion from infoboxPartOfArticle to JSON. + * Conversion from infoboxPartOfArticle to JSON and back. */ @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"; 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"; @@ -42,6 +46,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 @@ -73,6 +80,75 @@ public JSONObject convertInfoboxPartOfArticleToJson(@Nullable final String infob return enhanceJsonObject(new JSONObject(parametersAndValues)); } + @NotNull + 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 stringBuilder = new StringBuilder(); + stringBuilder.append("{{Infobox "); + stringBuilder.append(jsonObject.get(TEMPLATE_TYPE)); + + // 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); + + 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 + // 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 (TEMPLATE_TYPE.equals(key) || !jsonObject.has(key)) { + continue; + } + + Object value = jsonObject.get(key); + + if (value instanceof JSONArray) { + + if (SOUNDS.equals(key)) { + 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, HuntingPlaceSkills.fieldOrder())); + } else { + sb.append(makeCommaSeparatedStringList(jsonObject, key, (JSONArray) value)); + } + } else { + String paddedKey = Strings.padEnd(key, getMaxFieldLength(jsonObject), ' '); + sb.append("| ") + .append(paddedKey) + .append(" = ") + .append(value) + .append("\n"); + } + } + } + /** * Extracts template type from input. Allows cases of e.g. {{Infobox_Hunt|}} (with an underscore) or without an underscore. */ @@ -85,7 +161,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; }); } @@ -168,7 +244,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(); } @@ -201,7 +277,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)); @@ -217,11 +293,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); @@ -262,4 +338,92 @@ 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); + } + + 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) { + final String paddedKey = Strings.padEnd(key, getMaxFieldLength(jsonObject), ' '); + final String value = jsonArray.toList().stream() + .map(String::valueOf) + .collect(Collectors.joining("|")); + + 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) { + 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 makeSkillsTable(JSONObject jsonObject, String key, JSONArray jsonArray, List fieldOrder) { + final StringBuilder result = new StringBuilder("| "); + final String paddedKey = Strings.padEnd(key, getMaxFieldLength(jsonObject), ' '); + 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 result.toString(); + } + + 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/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/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/jackson/WikiObjectMixin.java b/src/main/java/com/tibiawiki/domain/jackson/WikiObjectMixin.java new file mode 100644 index 0000000..dd6ab98 --- /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", visible = true) +@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 03ee183..04b89e8 100644 --- a/src/main/java/com/tibiawiki/domain/objects/Achievement.java +++ b/src/main/java/com/tibiawiki/domain/objects/Achievement.java @@ -1,35 +1,68 @@ 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 lombok.AccessLevel; +import com.tibiawiki.domain.objects.validation.ValidationResult; +import com.tibiawiki.domain.utils.ListUtil; +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 { - 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() { return Arrays.asList("grade", "name", "description", "spoiler", "premium", "points", "secret", "coincideswith", "implemented", "achievementid", "relatedpages", "history", "status"); } + + @Override + public List validate() { + 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/Building.java b/src/main/java/com/tibiawiki/domain/objects/Building.java index 0b9fee8..50e5c90 100644 --- a/src/main/java/com/tibiawiki/domain/objects/Building.java +++ b/src/main/java/com/tibiawiki/domain/objects/Building.java @@ -1,44 +1,94 @@ 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; 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 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/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/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/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..c26f423 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 static 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..20fd993 100644 --- a/src/main/java/com/tibiawiki/domain/objects/Item.java +++ b/src/main/java/com/tibiawiki/domain/objects/Item.java @@ -1,95 +1,307 @@ 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.math.BigDecimal; +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 BigDecimal 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 String npcvaluerook; + private final String 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, 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, String npcvaluerook, + String 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", "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/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..bd5a8b8 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 String 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, 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); + 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/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/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..8419811 100644 --- a/src/main/java/com/tibiawiki/domain/objects/NPC.java +++ b/src/main/java/com/tibiawiki/domain/objects/NPC.java @@ -1,56 +1,133 @@ 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.math.BigDecimal; +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 BigDecimal posx; + private final BigDecimal posy; + private final Integer posz; + private final BigDecimal posx2; + private final BigDecimal posy2; + private final Integer posz2; + private final BigDecimal posx3; + private final BigDecimal posy3; + private final Integer posz3; + private final BigDecimal posx4; + private final BigDecimal posy4; + private final Integer posz4; + private final BigDecimal posx5; + private final BigDecimal 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, 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; + 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", "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/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/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/main/java/com/tibiawiki/domain/objects/Quest.java b/src/main/java/com/tibiawiki/domain/objects/Quest.java index f365547..bf665b8 100644 --- a/src/main/java/com/tibiawiki/domain/objects/Quest.java +++ b/src/main/java/com/tibiawiki/domain/objects/Quest.java @@ -1,40 +1,79 @@ 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() { 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/main/java/com/tibiawiki/domain/objects/Spell.java b/src/main/java/com/tibiawiki/domain/objects/Spell.java index 21ed11d..3f616ed 100644 --- a/src/main/java/com/tibiawiki/domain/objects/Spell.java +++ b/src/main/java/com/tibiawiki/domain/objects/Spell.java @@ -1,109 +1,525 @@ 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.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 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; + } + + @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, + 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 diff --git a/src/main/java/com/tibiawiki/domain/objects/WikiObject.java b/src/main/java/com/tibiawiki/domain/objects/WikiObject.java index 9076470..7df0c49 100644 --- a/src/main/java/com/tibiawiki/domain/objects/WikiObject.java +++ b/src/main/java/com/tibiawiki/domain/objects/WikiObject.java @@ -3,95 +3,53 @@ 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 com.tibiawiki.domain.interfaces.Validatable; +import com.tibiawiki.domain.objects.validation.ValidationResult; import lombok.Getter; -import java.lang.reflect.Field; -import java.util.ArrayList; import java.util.Arrays; +import java.util.Collections; 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; +public abstract class WikiObject implements Validatable { + + private final String templateType; + 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 - } - - 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()); + templateType = null; + name = null; + article = null; + actualname = null; + plural = null; + implemented = null; + notes = null; + history = null; + status = null; } - 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.templateType = null; + 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() { @@ -103,6 +61,11 @@ public String toString() { return "Class: " + getClassName() + ", name: " + getName(); } + @Override + public List validate() { + return Collections.emptyList(); + } + public static class WikiObjectImpl extends WikiObject { public WikiObjectImpl() { @@ -113,12 +76,10 @@ public WikiObjectImpl() { 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); + @Override + public List validate() { + return Collections.emptyList(); } } } 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..96ecc42 --- /dev/null +++ b/src/main/java/com/tibiawiki/domain/objects/validation/ValidationException.java @@ -0,0 +1,43 @@ +package com.tibiawiki.domain.objects.validation; + +import java.util.List; +import java.util.stream.Collectors; + +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); + } + + 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/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/domain/repositories/ArticleRepository.java b/src/main/java/com/tibiawiki/domain/repositories/ArticleRepository.java index f89a7ad..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; @@ -34,6 +35,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 +55,12 @@ public String getArticle(String pageName) { return wiki.getPageText(pageName); } + public boolean modifyArticle(String pageName, String pageContent, String editSummary) { + return IS_DEBUG_ENABLED + ? true + : wiki.edit(pageName, pageContent, editSummary); + } + private boolean login(Wiki wiki) { String username = PropertiesUtil.getUsername(); String password = PropertiesUtil.getPassword(); @@ -61,4 +71,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/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/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/ModifyAny.java b/src/main/java/com/tibiawiki/process/ModifyAny.java new file mode 100644 index 0000000..5dac376 --- /dev/null +++ b/src/main/java/com/tibiawiki/process/ModifyAny.java @@ -0,0 +1,60 @@ +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.WikiObject; +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; + +import java.util.List; + +/** + * 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 ModifyAny { + + private WikiObjectFactory wikiObjectFactory; + private JsonFactory jsonFactory; + private ArticleFactory articleFactory; + private ArticleRepository articleRepository; + + @Autowired + 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(WikiObject wikiObject, String editSummary) { + final String originalWikiObject = articleRepository.getArticle(wikiObject.getName()); + + 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(wikiObject) + : Try.failure(new ValidationException("Unable to edit wikiObject.")) + ); + } + + private Try validate(WikiObject wikiObject) { + final List validationResults = wikiObject.validate(); + + return validationResults.isEmpty() + ? Try.success(wikiObject) + : Try.failure(ValidationException.fromResults(validationResults)); + } +} 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 d369fe5..e833256 100644 --- a/src/main/java/com/tibiawiki/serviceinterface/AchievementsResource.java +++ b/src/main/java/com/tibiawiki/serviceinterface/AchievementsResource.java @@ -1,5 +1,8 @@ package com.tibiawiki.serviceinterface; +import com.tibiawiki.domain.objects.Achievement; +import com.tibiawiki.domain.objects.validation.ValidationException; +import com.tibiawiki.process.ModifyAny; import com.tibiawiki.process.RetrieveAchievements; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; @@ -10,7 +13,10 @@ 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,18 +26,19 @@ @Component @Api(value = "Achievements") -@Path("/") +@Path("/achievements") public class AchievementsResource { - @Autowired private RetrieveAchievements retrieveAchievements; + private ModifyAny modifyAny; - private AchievementsResource() { - // nothing to do, all dependencies are injected + @Autowired + private AchievementsResource(RetrieveAchievements retrieveAchievements, ModifyAny modifyAny) { + this.retrieveAchievements = retrieveAchievements; + this.modifyAny = modifyAny; } @GET - @Path("/achievements") @ApiResponses(value = { @ApiResponse(code = 200, message = "list of achievements retrieved") }) @@ -44,12 +51,11 @@ public Response getAchievements(@ApiParam(value = "optionally expands the result ? retrieveAchievements.getAchievementsJSON().map(JSONObject::toMap) : retrieveAchievements.getAchievementsList() ) - .header("Access-Control-Allow-Origin", "*") .build(); } @GET - @Path("/achievements/{name}") + @Path("/{name}") @ApiOperation(value = "achievements") @ApiResponses(value = { @ApiResponse(code = 200, message = "achievement with specified name found"), @@ -60,9 +66,26 @@ 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()); } + + @PUT + @ApiResponses(value = { + @ApiResponse(code = 200, message = "the changed achievement"), + @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, @HeaderParam("X-WIKI-Edit-Summary") String editSummary) { + return modifyAny.modify(achievement, editSummary) + .map(a -> Response.ok() + .entity(a) + .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/BooksResource.java b/src/main/java/com/tibiawiki/serviceinterface/BooksResource.java index 61caac7..b3df405 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; @@ -16,18 +24,19 @@ @Component @Api(value = "Books") -@Path("/") +@Path("/books") public class BooksResource { - @Autowired private RetrieveBooks retrieveBooks; + private ModifyAny modifyAny; - private BooksResource() { - // nothing to do, all dependencies are injected + @Autowired + private BooksResource(RetrieveBooks retrieveBooks, ModifyAny modifyAny) { + this.retrieveBooks = retrieveBooks; + this.modifyAny = modifyAny; } @GET - @Path("/books") @Produces(MediaType.APPLICATION_JSON) public Response getBooks(@QueryParam("expand") Boolean expand) { return Response.ok() @@ -35,20 +44,36 @@ public Response getBooks(@QueryParam("expand") Boolean expand) { ? retrieveBooks.getBooksJSON().map(JSONObject::toMap) : retrieveBooks.getBooksList() ) - .header("Access-Control-Allow-Origin", "*") .build(); } @GET - @Path("/books/{name}") + @Path("/{name}") @Produces(MediaType.APPLICATION_JSON) 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()); } + + @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) + .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 d793482..c894cc3 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; @@ -16,18 +24,19 @@ @Component @Api(value = "Buildings") -@Path("/") +@Path("/buildings") public class BuildingsResource { - @Autowired private RetrieveBuildings retrieveBuildings; + private ModifyAny modifyAny; - private BuildingsResource() { - // nothing to do, all dependencies are injected + @Autowired + private BuildingsResource(RetrieveBuildings retrieveBuildings, ModifyAny modifyAny) { + this.retrieveBuildings = retrieveBuildings; + this.modifyAny = modifyAny; } @GET - @Path("/buildings") @Produces(MediaType.APPLICATION_JSON) public Response getBuildings(@QueryParam("expand") Boolean expand) { return Response.ok() @@ -35,20 +44,36 @@ public Response getBuildings(@QueryParam("expand") Boolean expand) { ? retrieveBuildings.getBuildingsJSON().map(JSONObject::toMap) : retrieveBuildings.getBuildingsList() ) - .header("Access-Control-Allow-Origin", "*") .build(); } @GET - @Path("/buildings/{name}") + @Path("/{name}") @Produces(MediaType.APPLICATION_JSON) 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()); } + + @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) + .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 a8195be..bbf006b 100644 --- a/src/main/java/com/tibiawiki/serviceinterface/CorpsesResource.java +++ b/src/main/java/com/tibiawiki/serviceinterface/CorpsesResource.java @@ -1,29 +1,42 @@ 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.*; +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; +import javax.ws.rs.QueryParam; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; @Component @Api(value = "Corpses") -@Path("/") +@Path("/corpses") public class CorpsesResource { - @Autowired private RetrieveCorpses retrieveCorpses; + private ModifyAny modifyAny; - private CorpsesResource() { - // nothing to do, all dependencies are injected + @Autowired + private CorpsesResource(RetrieveCorpses retrieveCorpses, ModifyAny modifyAny) { + this.retrieveCorpses = retrieveCorpses; + this.modifyAny = modifyAny; } @GET - @Path("/corpses") @Produces(MediaType.APPLICATION_JSON) public Response getCorpses(@QueryParam("expand") Boolean expand) { return Response.ok() @@ -31,20 +44,36 @@ public Response getCorpses(@QueryParam("expand") Boolean expand) { ? retrieveCorpses.getCorpsesJSON().map(JSONObject::toMap) : retrieveCorpses.getCorpsesList() ) - .header("Access-Control-Allow-Origin", "*") .build(); } @GET - @Path("/corpses/{name}") + @Path("/{name}") @Produces(MediaType.APPLICATION_JSON) 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()); } + + @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) + .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 735f4d9..1719aa5 100644 --- a/src/main/java/com/tibiawiki/serviceinterface/CreaturesResource.java +++ b/src/main/java/com/tibiawiki/serviceinterface/CreaturesResource.java @@ -1,29 +1,42 @@ 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.*; +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; +import javax.ws.rs.QueryParam; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; @Component @Api(value = "Creatures") -@Path("/") +@Path("/creatures") public class CreaturesResource { - @Autowired private RetrieveCreatures retrieveCreatures; + private ModifyAny modifyAny; - private CreaturesResource() { - // nothing to do, all dependencies are injected + @Autowired + private CreaturesResource(RetrieveCreatures retrieveCreatures, ModifyAny modifyAny) { + this.retrieveCreatures = retrieveCreatures; + this.modifyAny = modifyAny; } @GET - @Path("/creatures") @Produces(MediaType.APPLICATION_JSON) public Response getCreatures(@QueryParam("expand") Boolean expand) { return Response.ok() @@ -31,20 +44,36 @@ public Response getCreatures(@QueryParam("expand") Boolean expand) { ? retrieveCreatures.getCreaturesJSON().map(JSONObject::toMap) : retrieveCreatures.getCreaturesList() ) - .header("Access-Control-Allow-Origin", "*") .build(); } @GET - @Path("/creatures/{name}") + @Path("/{name}") @Produces(MediaType.APPLICATION_JSON) 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()); } + + @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) + .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 9d822d7..c38f5d5 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; @@ -16,18 +24,19 @@ @Component @Api(value = "Effects") -@Path("/") +@Path("/effects") public class EffectsResource { - @Autowired private RetrieveEffects retrieveEffects; + private ModifyAny modifyAny; - private EffectsResource() { - // nothing to do, all dependencies are injected + @Autowired + private EffectsResource(RetrieveEffects retrieveEffects, ModifyAny modifyAny) { + this.retrieveEffects = retrieveEffects; + this.modifyAny = modifyAny; } @GET - @Path("/effects") @Produces(MediaType.APPLICATION_JSON) public Response getEffects(@QueryParam("expand") Boolean expand) { return Response.ok() @@ -35,20 +44,36 @@ public Response getEffects(@QueryParam("expand") Boolean expand) { ? retrieveEffects.getEffectsJSON().map(JSONObject::toMap) : retrieveEffects.getEffectsList() ) - .header("Access-Control-Allow-Origin", "*") .build(); } @GET - @Path("/effects/{name}") + @Path("/{name}") @Produces(MediaType.APPLICATION_JSON) 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()); } + + @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) + .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 93b47c3..f4b1f32 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; @@ -16,18 +24,19 @@ @Component @Api(value = "Hunting Places") -@Path("/") +@Path("/huntingplaces") public class HuntingPlacesResource { - @Autowired private RetrieveHuntingPlaces retrieveHuntingPlaces; + private ModifyAny modifyAny; - private HuntingPlacesResource() { - // nothing to do, all dependencies are injected + @Autowired + private HuntingPlacesResource(RetrieveHuntingPlaces retrieveHuntingPlaces, ModifyAny modifyAny) { + this.retrieveHuntingPlaces = retrieveHuntingPlaces; + this.modifyAny = modifyAny; } @GET - @Path("/huntingplaces") @Produces(MediaType.APPLICATION_JSON) public Response getHuntingPlaces(@QueryParam("expand") Boolean expand) { return Response.ok() @@ -35,20 +44,36 @@ public Response getHuntingPlaces(@QueryParam("expand") Boolean expand) { ? retrieveHuntingPlaces.getHuntingPlacesJSON().map(JSONObject::toMap) : retrieveHuntingPlaces.getHuntingPlacesList() ) - .header("Access-Control-Allow-Origin", "*") .build(); } @GET - @Path("/huntingplaces/{name}") + @Path("/{name}") @Produces(MediaType.APPLICATION_JSON) 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()); } + + @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) + .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 a41de76..74ff03b 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; @@ -16,18 +24,19 @@ @Component @Api(value = "Items") -@Path("/") +@Path("/items") public class ItemsResource { - @Autowired private RetrieveItems retrieveItems; + private ModifyAny modifyAny; - private ItemsResource() { - // nothing to do, all dependencies are injected + @Autowired + private ItemsResource(RetrieveItems retrieveItems, ModifyAny modifyAny) { + this.retrieveItems = retrieveItems; + this.modifyAny = modifyAny; } @GET - @Path("/items") @Produces(MediaType.APPLICATION_JSON) public Response getItems(@QueryParam("expand") Boolean expand) { return Response.ok() @@ -35,20 +44,36 @@ public Response getItems(@QueryParam("expand") Boolean expand) { ? retrieveItems.getItemsJSON().map(JSONObject::toMap) : retrieveItems.getItemsList() ) - .header("Access-Control-Allow-Origin", "*") .build(); } @GET - @Path("/items/{name}") + @Path("/{name}") @Produces(MediaType.APPLICATION_JSON) 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()); } + + @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) + .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 6a94f7d..47b732b 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; @@ -16,18 +24,19 @@ @Component @Api(value = "Keys") -@Path("/") +@Path("/keys") public class KeysResource { - @Autowired private RetrieveKeys retrieveKeys; + private ModifyAny modifyAny; - private KeysResource() { - // nothing to do, all dependencies are injected + @Autowired + private KeysResource(RetrieveKeys retrieveKeys, ModifyAny modifyAny) { + this.retrieveKeys = retrieveKeys; + this.modifyAny = modifyAny; } @GET - @Path("/keys") @Produces(MediaType.APPLICATION_JSON) public Response getKeys(@QueryParam("expand") Boolean expand) { return Response.ok() @@ -35,20 +44,36 @@ public Response getKeys(@QueryParam("expand") Boolean expand) { ? retrieveKeys.getKeysJSON().map(JSONObject::toMap) : retrieveKeys.getKeysList() ) - .header("Access-Control-Allow-Origin", "*") .build(); } @GET - @Path("/keys/{name}") + @Path("/{name}") @Produces(MediaType.APPLICATION_JSON) 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()); } + + @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) + .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 151d063..7ec1637 100644 --- a/src/main/java/com/tibiawiki/serviceinterface/LocationsResource.java +++ b/src/main/java/com/tibiawiki/serviceinterface/LocationsResource.java @@ -1,29 +1,42 @@ 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.*; +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; +import javax.ws.rs.QueryParam; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; @Component @Api(value = "Locations") -@Path("/") +@Path("/locations") public class LocationsResource { - @Autowired private RetrieveLocations retrieveLocations; + private ModifyAny modifyAny; - private LocationsResource() { - // nothing to do, all dependencies are injected + @Autowired + private LocationsResource(RetrieveLocations retrieveLocations, ModifyAny modifyAny) { + this.retrieveLocations = retrieveLocations; + this.modifyAny = modifyAny; } @GET - @Path("/locations") @Produces(MediaType.APPLICATION_JSON) public Response getLocations(@QueryParam("expand") Boolean expand) { return Response.ok() @@ -31,20 +44,36 @@ public Response getLocations(@QueryParam("expand") Boolean expand) { ? retrieveLocations.getLocationsJSON().map(JSONObject::toMap) : retrieveLocations.getLocationsList() ) - .header("Access-Control-Allow-Origin", "*") .build(); } @GET - @Path("/locations/{name}") + @Path("/{name}") @Produces(MediaType.APPLICATION_JSON) 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()); } + + @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) + .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 new file mode 100644 index 0000000..9ea88bd --- /dev/null +++ b/src/main/java/com/tibiawiki/serviceinterface/MissilesResource.java @@ -0,0 +1,79 @@ +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; +import javax.ws.rs.QueryParam; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; + +@Component +@Api(value = "Missiles") +@Path("/missiles") +public class MissilesResource { + + private RetrieveMissiles retrieveMissiles; + private ModifyAny modifyAny; + + @Autowired + private MissilesResource(RetrieveMissiles retrieveMissiles, ModifyAny modifyAny) { + this.retrieveMissiles = retrieveMissiles; + this.modifyAny = modifyAny; + } + + @GET + @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() + ) + .build(); + } + + @GET + @Path("/{name}") + @Produces(MediaType.APPLICATION_JSON) + public Response getMissilesByName(@PathParam("name") String name) { + return retrieveMissiles.getMissileJSON(name) + .map(a -> Response.ok() + .entity(a.toString(2)) + .build()) + .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) + .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 4555e07..e205e0b 100644 --- a/src/main/java/com/tibiawiki/serviceinterface/MountsResource.java +++ b/src/main/java/com/tibiawiki/serviceinterface/MountsResource.java @@ -1,29 +1,42 @@ 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.*; +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; +import javax.ws.rs.QueryParam; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; @Component @Api(value = "Mounts") -@Path("/") +@Path("/mounts") public class MountsResource { - @Autowired private RetrieveMounts retrieveMounts; + private ModifyAny modifyAny; - private MountsResource() { - // nothing to do, all dependencies are injected + @Autowired + private MountsResource(RetrieveMounts retrieveMounts, ModifyAny modifyAny) { + this.retrieveMounts = retrieveMounts; + this.modifyAny = modifyAny; } @GET - @Path("/mounts") @Produces(MediaType.APPLICATION_JSON) public Response getMounts(@QueryParam("expand") Boolean expand) { return Response.ok() @@ -31,20 +44,36 @@ public Response getMounts(@QueryParam("expand") Boolean expand) { ? retrieveMounts.getMountsJSON().map(JSONObject::toMap) : retrieveMounts.getMountsList() ) - .header("Access-Control-Allow-Origin", "*") .build(); } @GET - @Path("/mounts/{name}") + @Path("/{name}") @Produces(MediaType.APPLICATION_JSON) 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()); } + + @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) + .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 4fc7434..1ce6a95 100644 --- a/src/main/java/com/tibiawiki/serviceinterface/NPCsResource.java +++ b/src/main/java/com/tibiawiki/serviceinterface/NPCsResource.java @@ -1,29 +1,42 @@ 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.*; +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; +import javax.ws.rs.QueryParam; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; @Component @Api(value = "NPCs") -@Path("/") +@Path("/npcs") public class NPCsResource { - @Autowired private RetrieveNPCs retrieveNPCs; + private ModifyAny modifyAny; - private NPCsResource() { - // nothing to do, all dependencies are injected + @Autowired + private NPCsResource(RetrieveNPCs retrieveNPCs, ModifyAny modifyAny) { + this.retrieveNPCs = retrieveNPCs; + this.modifyAny = modifyAny; } @GET - @Path("/npcs") @Produces(MediaType.APPLICATION_JSON) public Response getNPCs(@QueryParam("expand") Boolean expand) { return Response.ok() @@ -31,20 +44,36 @@ public Response getNPCs(@QueryParam("expand") Boolean expand) { ? retrieveNPCs.getNPCsJSON().map(JSONObject::toMap) : retrieveNPCs.getNPCsList() ) - .header("Access-Control-Allow-Origin", "*") .build(); } @GET - @Path("/npcs/{name}") + @Path("/{name}") @Produces(MediaType.APPLICATION_JSON) 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()); } + + @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) + .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 23aaafb..c09f422 100644 --- a/src/main/java/com/tibiawiki/serviceinterface/ObjectsResource.java +++ b/src/main/java/com/tibiawiki/serviceinterface/ObjectsResource.java @@ -1,29 +1,42 @@ 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.*; +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; +import javax.ws.rs.QueryParam; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; @Component @Api(value = "Objects") -@Path("/") +@Path("/objects") public class ObjectsResource { - @Autowired private RetrieveObjects retrieveObjects; + private ModifyAny modifyAny; - private ObjectsResource() { - // nothing to do, all dependencies are injected + @Autowired + private ObjectsResource(RetrieveObjects retrieveObjects, ModifyAny modifyAny) { + this.retrieveObjects = retrieveObjects; + this.modifyAny = modifyAny; } @GET - @Path("/objects") @Produces(MediaType.APPLICATION_JSON) public Response getObjects(@QueryParam("expand") Boolean expand) { return Response.ok() @@ -31,20 +44,36 @@ public Response getObjects(@QueryParam("expand") Boolean expand) { ? retrieveObjects.getObjectsJSON().map(JSONObject::toMap) : retrieveObjects.getObjectsList() ) - .header("Access-Control-Allow-Origin", "*") .build(); } @GET - @Path("/objects/{name}") + @Path("/{name}") @Produces(MediaType.APPLICATION_JSON) 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()); } + + @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) + .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 f08a072..3a8c7bd 100644 --- a/src/main/java/com/tibiawiki/serviceinterface/OutfitsResource.java +++ b/src/main/java/com/tibiawiki/serviceinterface/OutfitsResource.java @@ -1,29 +1,42 @@ 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.*; +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; +import javax.ws.rs.QueryParam; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; @Component @Api(value = "Outfits") -@Path("/") +@Path("/outfits") public class OutfitsResource { - @Autowired private RetrieveOutfits retrieveOutfits; + private ModifyAny modifyAny; - private OutfitsResource() { - // nothing to do, all dependencies are injected + @Autowired + private OutfitsResource(RetrieveOutfits retrieveOutfits, ModifyAny modifyAny) { + this.retrieveOutfits = retrieveOutfits; + this.modifyAny = modifyAny; } @GET - @Path("/outfits") @Produces(MediaType.APPLICATION_JSON) public Response getOutfits(@QueryParam("expand") Boolean expand) { return Response.ok() @@ -31,20 +44,36 @@ public Response getOutfits(@QueryParam("expand") Boolean expand) { ? retrieveOutfits.getOutfitsJSON().map(JSONObject::toMap) : retrieveOutfits.getOutfitsList() ) - .header("Access-Control-Allow-Origin", "*") .build(); } @GET - @Path("/outfits/{name}") + @Path("/{name}") @Produces(MediaType.APPLICATION_JSON) 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()); } + + @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) + .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 1393202..4725665 100644 --- a/src/main/java/com/tibiawiki/serviceinterface/QuestsResource.java +++ b/src/main/java/com/tibiawiki/serviceinterface/QuestsResource.java @@ -1,29 +1,42 @@ 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.*; +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; +import javax.ws.rs.QueryParam; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; @Component @Api(value = "Quests") -@Path("/") +@Path("/quests") public class QuestsResource { - @Autowired private RetrieveQuests retrieveQuests; + private ModifyAny modifyAny; - private QuestsResource() { - // nothing to do, all dependencies are injected + @Autowired + private QuestsResource(RetrieveQuests retrieveQuests, ModifyAny modifyAny) { + this.retrieveQuests = retrieveQuests; + this.modifyAny = modifyAny; } @GET - @Path("/quests") @Produces(MediaType.APPLICATION_JSON) public Response getQuests(@QueryParam("expand") Boolean expand) { return Response.ok() @@ -31,20 +44,36 @@ public Response getQuests(@QueryParam("expand") Boolean expand) { ? retrieveQuests.getQuestsJSON().map(JSONObject::toMap) : retrieveQuests.getQuestsList() ) - .header("Access-Control-Allow-Origin", "*") .build(); } @GET - @Path("/quests/{name}") + @Path("/{name}") @Produces(MediaType.APPLICATION_JSON) 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()); } + + @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) + .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 964b9d9..c62ae37 100644 --- a/src/main/java/com/tibiawiki/serviceinterface/SpellsResource.java +++ b/src/main/java/com/tibiawiki/serviceinterface/SpellsResource.java @@ -1,29 +1,42 @@ 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.*; +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; +import javax.ws.rs.QueryParam; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; @Component @Api(value = "Spells") -@Path("/") +@Path("/spells") public class SpellsResource { - @Autowired private RetrieveSpells retrieveSpells; + private ModifyAny modifyAny; - private SpellsResource() { - // nothing to do, all dependencies are injected + @Autowired + private SpellsResource(RetrieveSpells retrieveSpells, ModifyAny modifyAny) { + this.retrieveSpells = retrieveSpells; + this.modifyAny = modifyAny; } @GET - @Path("/spells") @Produces(MediaType.APPLICATION_JSON) public Response getSpells(@QueryParam("expand") Boolean expand) { return Response.ok() @@ -31,20 +44,36 @@ public Response getSpells(@QueryParam("expand") Boolean expand) { ? retrieveSpells.getSpellsJSON().map(JSONObject::toMap) : retrieveSpells.getSpellsList() ) - .header("Access-Control-Allow-Origin", "*") .build(); } @GET - @Path("/spells/{name}") + @Path("/{name}") @Produces(MediaType.APPLICATION_JSON) 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()); } + + @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) + .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 da75fec..52fd38f 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; @@ -16,18 +24,19 @@ @Component @Api(value = "Streets") -@Path("/") +@Path("/streets") public class StreetsResource { - @Autowired private RetrieveStreets retrieveStreets; + private ModifyAny modifyAny; - private StreetsResource() { - // nothing to do, all dependencies are injected + @Autowired + private StreetsResource(RetrieveStreets retrieveStreets, ModifyAny modifyAny) { + this.retrieveStreets = retrieveStreets; + this.modifyAny = modifyAny; } @GET - @Path("/streets") @Produces(MediaType.APPLICATION_JSON) public Response getStreets(@QueryParam("expand") Boolean expand) { return Response.ok() @@ -35,20 +44,36 @@ public Response getStreets(@QueryParam("expand") Boolean expand) { ? retrieveStreets.getStreetsJSON().map(JSONObject::toMap) : retrieveStreets.getStreetsList() ) - .header("Access-Control-Allow-Origin", "*") .build(); } @GET - @Path("/streets/{name}") + @Path("/{name}") @Produces(MediaType.APPLICATION_JSON) 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()); } + + @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) + .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/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 76fd60a..2b4a675 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; @@ -27,6 +44,7 @@ public void init() { } private void registerEndpoints() { + register(CORSResponseFilter.class); register(AchievementsResource.class); register(BooksResource.class); register(BuildingsResource.class); @@ -37,6 +55,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); @@ -52,7 +71,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 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 diff --git a/src/test/java/com/tibiawiki/domain/factories/JsonFactoryTest.java b/src/test/java/com/tibiawiki/domain/factories/JsonFactoryTest.java index 447427f..9b5e14f 100644 --- a/src/test/java/com/tibiawiki/domain/factories/JsonFactoryTest.java +++ b/src/test/java/com/tibiawiki/domain/factories/JsonFactoryTest.java @@ -1,10 +1,53 @@ package com.tibiawiki.domain.factories; +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.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; +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.HuntingPlaceSkills; +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; 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; @@ -15,11 +58,13 @@ public class JsonFactoryTest { private JsonFactory target; + private ObjectMapper objectMapper; @BeforeEach public void setup() { target = new JsonFactory(); + objectMapper = new ObjectMapper(); } @Test @@ -30,7 +75,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")); @@ -177,10 +222,290 @@ 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_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)); + } + + @Test + void testConvertJsonToInfoboxPartOfArticle_Building() { + final Building building = makeBuilding(); + String result = target.convertJsonToInfoboxPartOfArticle(makeBuildingJson(building), building.fieldOrder()); + 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)); + } + + @Test + void testConvertJsonToInfoboxPartOfArticle_Creature() { + final Creature creature = makeCreature(); + String result = target.convertJsonToInfoboxPartOfArticle(makeCreatureJson(creature), creature.fieldOrder()); + 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)); + } + + 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"; + + @Test + void testConvertJsonToInfoboxPartOfArticle_Item() { + final Item item = makeItem(); + String result = target.convertJsonToInfoboxPartOfArticle(makeItemJson(item), item.fieldOrder()); + assertThat(result, is(INFOBOX_ITEM_TEXT)); + } + + @Test + void testConvertJsonToInfoboxPartOfArticle_Key() { + final Key key = makeKey(); + String result = target.convertJsonToInfoboxPartOfArticle(makeKeyJson(key), key.fieldOrder()); + assertThat(result, is(INFOBOX_KEY_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" + + " {{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" + + "| 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"; + + @Test + void testConvertJsonToInfoboxPartOfArticle_Missile() { + final Missile missile = makeMissile(); + String result = target.convertJsonToInfoboxPartOfArticle(makeMissileJson(missile), missile.fieldOrder()); + assertThat(result, is(INFOBOX_MISSILE_TEXT)); + } + + @Test + void testConvertJsonToInfoboxPartOfArticle_Mount() { + final Mount mount = makeMount(); + String result = target.convertJsonToInfoboxPartOfArticle(makeMountJson(mount), mount.fieldOrder()); + assertThat(result, is(INFOBOX_MOUNT_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"; + + @Test + void testConvertJsonToInfoboxPartOfArticle_Object() { + final TibiaObject tibiaObject = makeTibiaObject(); + String result = target.convertJsonToInfoboxPartOfArticle(makeTibiaObjectJson(tibiaObject), tibiaObject.fieldOrder()); + assertThat(result, is(INFOBOX_OBJECT_TEXT)); + } + + @Test + void testConvertJsonToInfoboxPartOfArticle_Outfit() { + final Outfit outfit = makeOutfit(); + String result = target.convertJsonToInfoboxPartOfArticle(makeOutfitJson(outfit), outfit.fieldOrder()); + assertThat(result, is(INFOBOX_OUTFIT_TEXT)); + } + + @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)); + } + + 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" + "}}"; @@ -191,57 +516,697 @@ 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" + + 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" + - "}}"; + "| 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" + - "| 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 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 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" + + "| 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" + + "| 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"); + } -} \ No newline at end of file + 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 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" + + "| 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_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_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 JSONObject makeItemJson(Item item) { + return new JSONObject(objectMapper.convertValue(item, Map.class)).put("templateType", "Item"); + } + + 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() { + 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_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() + .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"); + } + + @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() + .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"); + } + + @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() + .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"); + } + + @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() + .name("Sam") + .implemented("Pre-6.0") + .job("Artisan") + .job2("Weapon Shopkeeper") + .job3("Armor Shopkeeper") + .location("[[Temple Street]] in [[Thais]].") + .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") + .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"); + } + + @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() + .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 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() + .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 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(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") + .bestloot2("Foobar") + .bestloot3("Foobar") + .bestloot4("Foobar") + .bestloot5("Foobar") + .map("Hero Cave 3.png") + .map2("Hero Cave 6.png") + .build(); + } + + 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(); + } + + 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" + + "| mana = 20\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.\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 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() + .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"); + } +} 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; - } -}