Skip to content

Commit

Permalink
updating dependencies, removing unused code, some small optimizations.
Browse files Browse the repository at this point in the history
  • Loading branch information
benjaminkomen committed Mar 31, 2018
1 parent 94880eb commit a73f083
Show file tree
Hide file tree
Showing 10 changed files with 56 additions and 137 deletions.
45 changes: 22 additions & 23 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,39 +9,30 @@
<name>TibiaWikiApi</name>
<url>https://github.com/benjaminkomen/TibiaWikiApi</url>

<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>

<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<spring.boot.starter>1.5.10.RELEASE</spring.boot.starter>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
</properties>

<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.10.RELEASE</version>
<version>2.0.0.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>

<dependencies>
<!-- Spring boot -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<version>${spring.boot.starter}</version>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jersey</artifactId>
<version>${spring.boot.starter}</version>
</dependency>

<!-- MediaWiki -->
Expand All @@ -60,7 +51,7 @@
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>1.6.2</version>
<version>1.7.25</version>

<exclusions>
<exclusion>
Expand All @@ -74,22 +65,22 @@
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>20160810</version>
<version>20180130</version>
</dependency>

<!-- Lombok -->
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.16.16</version>
<version>1.16.20</version>
<scope>provided</scope>
</dependency>

<!-- JetBrains Annotations -->
<dependency>
<groupId>org.jetbrains</groupId>
<artifactId>annotations</artifactId>
<version>15.0</version>
<version>16.0.1</version>
</dependency>

<!-- StreamEx -->
Expand All @@ -101,9 +92,9 @@

<!-- Test -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>5.1.0</version>
<scope>test</scope>
</dependency>

Expand Down Expand Up @@ -131,16 +122,24 @@
<dependency>
<groupId>org.objenesis</groupId>
<artifactId>objenesis</artifactId>
<version>1.3</version>
<version>2.6</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<version>${spring.boot.starter}</version>
<scope>test</scope>
</dependency>

</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
15 changes: 0 additions & 15 deletions src/main/java/com/tibiawiki/Application.java

This file was deleted.

12 changes: 12 additions & 0 deletions src/main/java/com/tibiawiki/TibiaWikiApiApplication.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.tibiawiki;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class TibiaWikiApiApplication {

public static void main(String[] args) {
SpringApplication.run(TibiaWikiApiApplication.class, args);
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +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.Creature;
Expand Down Expand Up @@ -31,7 +32,6 @@ public class ArticleFactory {
private static final String ITEM_ID = "itemid";
private static final List ITEMS_WITH_NO_DROPPEDBY_LIST = Arrays.asList("Gold Coin", "Platinum Coin");


private Article article;
private String articleName;
private String objectType;
Expand Down Expand Up @@ -170,6 +170,7 @@ private JSONObject enhanceJsonObject(JSONObject jsonObject) {
private <T> T mapJsonToObject(String wikiObjectJson, Class<T> clazz) {
ObjectMapper objectMapper = new ObjectMapper();
// objectMapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
objectMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
try {
return objectMapper.readValue(wikiObjectJson, clazz);
} catch (IOException e) {
Expand Down
21 changes: 0 additions & 21 deletions src/main/java/com/tibiawiki/domain/jackson/CustomDeserializer.java

This file was deleted.

26 changes: 0 additions & 26 deletions src/main/java/com/tibiawiki/domain/objects/TibiaWikiBot.java
Original file line number Diff line number Diff line change
@@ -1,38 +1,12 @@
package com.tibiawiki.domain.objects;

import net.sourceforge.jwbf.mediawiki.bots.MediaWikiBot;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.InputStream;
import java.util.Properties;

public class TibiaWikiBot extends MediaWikiBot {

private static final Logger log = LoggerFactory.getLogger(TibiaWikiBot.class);

private static final String DEFAULT_WIKI_URI = "https://tibia.wikia.com/";

public TibiaWikiBot() {
super(DEFAULT_WIKI_URI);
}

public void login() {
String username = this.getProperty("username");
String password = this.getProperty("password");
super.login(username, password);
}

private String getProperty(String propertyName) {
String output = "";
try {
Properties props = new Properties();
InputStream is = props.getClass().getResourceAsStream("/credentials.properties");
props.load(is);
return props.getProperty(propertyName);
} catch(Exception ex) {
log.error(String.valueOf(ex));
}
return output;
}
}
25 changes: 12 additions & 13 deletions src/main/java/com/tibiawiki/process/RetrieveCreatures.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import com.tibiawiki.domain.objects.Creature;
import com.tibiawiki.domain.objects.TibiaWikiBot;
import com.tibiawiki.domain.repositories.WikiArticleRepository;
import net.sourceforge.jwbf.mediawiki.actions.queries.CategoryMembersSimple;
import one.util.streamex.StreamEx;

import java.util.ArrayList;
Expand All @@ -20,31 +19,31 @@ public class RetrieveCreatures {
private WikiArticleRepository wikiArticleRepository;

public RetrieveCreatures() {
TibiaWikiBot tibiaWikiBot = new TibiaWikiBot();
// tibiaWikiBot.login();
wikiArticleRepository = new WikiArticleRepository(tibiaWikiBot);
wikiArticleRepository = new WikiArticleRepository(new TibiaWikiBot());
}

public List<Creature> getCreatures() {
CategoryMembersSimple pagesInCreaturesCategory = wikiArticleRepository.getMembersFromCategory(CATEGORY_CREATURES);
CategoryMembersSimple pagesInListsCategory = wikiArticleRepository.getMembersFromCategory(CATEGORY_LISTS);
return getCreatures(false);
}

List<String> creaturesCategory = new ArrayList<>();
for (String pageName : pagesInCreaturesCategory) {
public List<Creature> getCreatures(boolean oneByOne) {
final List<String> creaturesCategory = new ArrayList<>();
for (String pageName : wikiArticleRepository.getMembersFromCategory(CATEGORY_CREATURES)) {
creaturesCategory.add(pageName);
}

List<String> listsCategory = new ArrayList<>();
for (String pageName : pagesInListsCategory) {
final List<String> listsCategory = new ArrayList<>();
for (String pageName : wikiArticleRepository.getMembersFromCategory(CATEGORY_LISTS)) {
listsCategory.add(pageName);
}

List<String> pagesInCreaturesCategoryButNotLists = creaturesCategory.stream()
final List<String> pagesInCreaturesCategoryButNotLists = creaturesCategory.stream()
.filter(page -> !listsCategory.contains(page))
.collect(Collectors.toList());

return obtainCreaturesInBulk(pagesInCreaturesCategoryButNotLists);
// return obtainCreaturesOneByOne(pagesInCreaturesCategoryButNotLists);
return oneByOne
? obtainCreaturesOneByOne(pagesInCreaturesCategoryButNotLists)
: obtainCreaturesInBulk(pagesInCreaturesCategoryButNotLists);
}

public Optional<Creature> getCreature(String pageName) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.tibiawiki.serviceinterface;

import com.tibiawiki.domain.objects.Creature;
import com.tibiawiki.process.RetrieveCreatures;

import javax.ws.rs.GET;
Expand All @@ -9,8 +8,6 @@
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import java.util.List;
import java.util.Optional;

@Path("/")
public class CreaturesResource {
Expand All @@ -34,10 +31,8 @@ public Response getHome() {
@Path("/creatures")
@Produces(MediaType.APPLICATION_JSON)
public Response getCreatures() {
final List<Creature> creatures = retrieveCreatures.getCreatures();

return Response.ok()
.entity(creatures)
.entity(retrieveCreatures.getCreatures())
.header("Access-Control-Allow-Origin", "*")
.build();
}
Expand All @@ -46,16 +41,12 @@ public Response getCreatures() {
@Path("/creatures/{name}")
@Produces(MediaType.APPLICATION_JSON)
public Response getCreatureByName(@PathParam("name") String name) {
final Optional<Creature> creature = retrieveCreatures.getCreature(name);

if (!creature.isPresent()) {
return Response.status(Response.Status.NOT_FOUND)
.build();
} else {
return Response.ok()
.entity(creature.get())
.header("Access-Control-Allow-Origin", "*")
.build();
}
return retrieveCreatures.getCreature(name)
.map(c -> Response.ok()
.entity(c)
.header("Access-Control-Allow-Origin", "*")
.build())
.orElseGet(() -> Response.status(Response.Status.NOT_FOUND)
.build());
}
}
19 changes: 0 additions & 19 deletions src/main/java/com/tibiawiki/serviceinterface/TestResource.java

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.tibiawiki.serviceinterface.config;

import com.tibiawiki.serviceinterface.CreaturesResource;
import com.tibiawiki.serviceinterface.TestResource;
import org.glassfish.jersey.server.ResourceConfig;
import org.springframework.stereotype.Component;

Expand All @@ -13,7 +12,6 @@ public JerseyConfig() {
}

private void registerEndpoints() {
register(TestResource.class);
register(CreaturesResource.class);
}
}

0 comments on commit a73f083

Please sign in to comment.