use of net.runelite.http.service.util.exception.NotFoundException in project runelite by runelite.
the class CacheController method listArchives.
@RequestMapping("{cacheId}/{indexId}")
public List<CacheArchive> listArchives(@PathVariable int cacheId, @PathVariable int indexId) {
CacheEntry cache = cacheService.findCache(cacheId);
if (cache == null) {
throw new NotFoundException();
}
IndexEntry indexEntry = cacheService.findIndexForCache(cache, indexId);
if (indexEntry == null) {
throw new NotFoundException();
}
List<ArchiveEntry> archives = cacheService.findArchivesForIndex(indexEntry);
return archives.stream().map(archive -> new CacheArchive(archive.getArchiveId(), archive.getNameHash(), archive.getRevision())).collect(Collectors.toList());
}
use of net.runelite.http.service.util.exception.NotFoundException in project runelite by runelite.
the class HiscoreService method lookupUsername.
public HiscoreResultBuilder lookupUsername(String username, HttpUrl hiscoreUrl) throws IOException {
HttpUrl url = hiscoreUrl.newBuilder().addQueryParameter("player", username).build();
log.debug("Built URL {}", url);
Request okrequest = new Request.Builder().url(url).build();
String responseStr;
try (Response okresponse = RuneLiteAPI.CLIENT.newCall(okrequest).execute()) {
if (!okresponse.isSuccessful()) {
switch(HttpStatus.valueOf(okresponse.code())) {
case NOT_FOUND:
throw new NotFoundException();
default:
throw new InternalServerErrorException("Error retrieving data from Jagex Hiscores: " + okresponse.message());
}
}
responseStr = okresponse.body().string();
}
CSVParser parser = CSVParser.parse(responseStr, CSVFormat.DEFAULT);
HiscoreResultBuilder hiscoreBuilder = new HiscoreResultBuilder();
hiscoreBuilder.setPlayer(username);
int count = 0;
for (CSVRecord record : parser.getRecords()) {
if (count++ >= HiscoreSkill.values().length) {
log.warn("Jagex Hiscore API returned unexpected data");
// rest is other things?
break;
}
// rank, level, experience
int rank = Integer.parseInt(record.get(0));
int level = Integer.parseInt(record.get(1));
// items that are not skills do not have an experience parameter
long experience = -1;
if (record.size() == 3) {
experience = Long.parseLong(record.get(2));
}
Skill skill = new Skill(rank, level, experience);
hiscoreBuilder.setNextSkill(skill);
}
return hiscoreBuilder;
}
use of net.runelite.http.service.util.exception.NotFoundException in project runelite by runelite.
the class CacheController method findConfig.
private ArchiveEntry findConfig(ConfigType config) {
CacheEntry cache = cacheService.findMostRecent();
if (cache == null) {
throw new NotFoundException();
}
IndexEntry indexEntry = cacheService.findIndexForCache(cache, IndexType.CONFIGS.getNumber());
if (indexEntry == null) {
throw new NotFoundException();
}
ArchiveEntry archiveEntry = cacheService.findArchiveForIndex(indexEntry, config.getId());
if (archiveEntry == null) {
throw new NotFoundException();
}
return archiveEntry;
}
use of net.runelite.http.service.util.exception.NotFoundException in project runelite by runelite.
the class CacheController method getObject.
@RequestMapping("object/{objectId}")
public ObjectDefinition getObject(@PathVariable int objectId) throws IOException {
ArchiveEntry archiveEntry = findConfig(ConfigType.OBJECT);
ArchiveFiles archiveFiles = cacheService.getArchiveFiles(archiveEntry);
if (archiveFiles == null) {
throw new NotFoundException();
}
FSFile file = archiveFiles.findFile(objectId);
if (file == null) {
throw new NotFoundException();
}
ObjectDefinition objectdef = new ObjectLoader().load(objectId, file.getContents());
return objectdef;
}
use of net.runelite.http.service.util.exception.NotFoundException in project runelite by runelite.
the class CacheController method getCacheArchive.
@RequestMapping("{cacheId}/{indexId}/{archiveId}")
public CacheArchive getCacheArchive(@PathVariable int cacheId, @PathVariable int indexId, @PathVariable int archiveId) {
CacheEntry cache = cacheService.findCache(cacheId);
if (cache == null) {
throw new NotFoundException();
}
IndexEntry indexEntry = cacheService.findIndexForCache(cache, indexId);
if (indexEntry == null) {
throw new NotFoundException();
}
ArchiveEntry archiveEntry = cacheService.findArchiveForIndex(indexEntry, archiveId);
if (archiveEntry == null) {
throw new NotFoundException();
}
return new CacheArchive(archiveEntry.getArchiveId(), archiveEntry.getNameHash(), archiveEntry.getRevision());
}
Aggregations