-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
320047c
commit d0cb896
Showing
7 changed files
with
176 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package com.tibiawiki.domain.enums; | ||
|
||
import com.fasterxml.jackson.annotation.JsonValue; | ||
import com.tibiawiki.domain.interfaces.Description; | ||
|
||
public enum QuestType implements Description { | ||
|
||
WORLD_CHANGE("change"), | ||
MINI_WORLD_CHANGE("mwc"), | ||
WORLD_EVENT("event"), | ||
WORLD_TASK("task"); | ||
|
||
private String description; | ||
|
||
QuestType(String description) { | ||
this.description = description; | ||
} | ||
|
||
@JsonValue | ||
public String getDescription() { | ||
return description; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package com.tibiawiki.domain.objects; | ||
|
||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties; | ||
import com.tibiawiki.domain.enums.QuestType; | ||
import com.tibiawiki.domain.enums.YesNo; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
import java.util.Arrays; | ||
import java.util.List; | ||
|
||
@JsonIgnoreProperties({"objectType"}) | ||
@Getter | ||
@NoArgsConstructor | ||
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; | ||
|
||
@Override | ||
public List<String> fieldOrder() { | ||
return Arrays.asList("name", "aka", "reward", "location", "rookgaardquest", "type", "lvl", "lvlrec", "lvlnote", | ||
"log", "time", "timealloc", "premium", "transcripts", "dangers", "legend", "history", "status"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package com.tibiawiki.process; | ||
|
||
import com.tibiawiki.domain.factories.ArticleFactory; | ||
import com.tibiawiki.domain.factories.JsonFactory; | ||
import com.tibiawiki.domain.repositories.ArticleRepository; | ||
import org.json.JSONObject; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.Optional; | ||
import java.util.stream.Collectors; | ||
import java.util.stream.Stream; | ||
|
||
public class RetrieveQuests extends RetrieveAny { | ||
|
||
private static final String CATEGORY = "Quest Overview Pages"; | ||
|
||
public RetrieveQuests() { | ||
super(); | ||
} | ||
|
||
public RetrieveQuests(ArticleRepository articleRepository, ArticleFactory articleFactory, JsonFactory jsonFactory) { | ||
super(articleRepository, articleFactory, jsonFactory); | ||
} | ||
|
||
public List<String> getQuestsList() { | ||
final List<String> npcsCategory = new ArrayList<>(); | ||
for (String pageName : articleRepository.getMembersFromCategory(CATEGORY)) { | ||
npcsCategory.add(pageName); | ||
} | ||
|
||
final List<String> listsCategory = new ArrayList<>(); | ||
for (String pageName : articleRepository.getMembersFromCategory(CATEGORY_LISTS)) { | ||
listsCategory.add(pageName); | ||
} | ||
|
||
return npcsCategory.stream() | ||
.filter(page -> !listsCategory.contains(page)) | ||
.collect(Collectors.toList()); | ||
} | ||
|
||
public Stream<JSONObject> getQuestsJSON() { | ||
return getQuestsJSON(ONE_BY_ONE); | ||
} | ||
|
||
public Stream<JSONObject> getQuestsJSON(boolean oneByOne) { | ||
final List<String> npcsList = getQuestsList(); | ||
|
||
return oneByOne | ||
? obtainArticlesOneByOne(npcsList) | ||
: obtainArticlesInBulk(npcsList); | ||
} | ||
|
||
public Optional<JSONObject> getQuestJSON(String pageName) { | ||
return super.getArticleJSON(pageName); | ||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
src/main/java/com/tibiawiki/serviceinterface/QuestsResource.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package com.tibiawiki.serviceinterface; | ||
|
||
import com.tibiawiki.process.RetrieveQuests; | ||
import org.json.JSONObject; | ||
|
||
import javax.ws.rs.*; | ||
import javax.ws.rs.core.MediaType; | ||
import javax.ws.rs.core.Response; | ||
|
||
@Path("/") | ||
public class QuestsResource { | ||
|
||
private RetrieveQuests retrieveQuests; | ||
|
||
public QuestsResource() { | ||
retrieveQuests = new RetrieveQuests(); | ||
} | ||
|
||
@GET | ||
@Path("/quests") | ||
@Produces(MediaType.APPLICATION_JSON) | ||
public Response getQuests(@QueryParam("expand") Boolean expand) { | ||
return Response.ok() | ||
.entity(expand != null && expand | ||
? retrieveQuests.getQuestsJSON().map(JSONObject::toMap) | ||
: retrieveQuests.getQuestsList() | ||
) | ||
.header("Access-Control-Allow-Origin", "*") | ||
.build(); | ||
} | ||
|
||
@GET | ||
@Path("/quests/{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()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters