Search in sources :

Example 1 with NotFoundException

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());
}
Also used : PathVariable(org.springframework.web.bind.annotation.PathVariable) RequestParam(org.springframework.web.bind.annotation.RequestParam) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ArchiveFiles(net.runelite.cache.fs.ArchiveFiles) TextureProvider(net.runelite.cache.definitions.providers.TextureProvider) Autowired(org.springframework.beans.factory.annotation.Autowired) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) Cache(net.runelite.http.api.cache.Cache) SpriteDefinition(net.runelite.cache.definitions.SpriteDefinition) SpriteLoader(net.runelite.cache.definitions.loaders.SpriteLoader) IndexEntry(net.runelite.http.service.cache.beans.IndexEntry) ImageIO(javax.imageio.ImageIO) CacheEntry(net.runelite.http.service.cache.beans.CacheEntry) ItemLoader(net.runelite.cache.definitions.loaders.ItemLoader) FSFile(net.runelite.cache.fs.FSFile) IndexType(net.runelite.cache.IndexType) ObjectDefinition(net.runelite.cache.definitions.ObjectDefinition) TextureDefinition(net.runelite.cache.definitions.TextureDefinition) TextureLoader(net.runelite.cache.definitions.loaders.TextureLoader) NpcLoader(net.runelite.cache.definitions.loaders.NpcLoader) BufferedImage(java.awt.image.BufferedImage) ArchiveEntry(net.runelite.http.service.cache.beans.ArchiveEntry) Container(net.runelite.cache.fs.Container) IOException(java.io.IOException) ObjectLoader(net.runelite.cache.definitions.loaders.ObjectLoader) Collectors(java.util.stream.Collectors) RestController(org.springframework.web.bind.annotation.RestController) SpriteProvider(net.runelite.cache.definitions.providers.SpriteProvider) CacheIndex(net.runelite.http.api.cache.CacheIndex) CacheArchive(net.runelite.http.api.cache.CacheArchive) ConfigType(net.runelite.cache.ConfigType) ItemProvider(net.runelite.cache.definitions.providers.ItemProvider) List(java.util.List) Slf4j(lombok.extern.slf4j.Slf4j) ItemDefinition(net.runelite.cache.definitions.ItemDefinition) ItemSpriteFactory(net.runelite.cache.item.ItemSpriteFactory) NotFoundException(net.runelite.http.service.util.exception.NotFoundException) NpcDefinition(net.runelite.cache.definitions.NpcDefinition) ResponseEntity(org.springframework.http.ResponseEntity) ModelLoader(net.runelite.cache.definitions.loaders.ModelLoader) ModelProvider(net.runelite.cache.definitions.providers.ModelProvider) ModelDefinition(net.runelite.cache.definitions.ModelDefinition) CacheArchive(net.runelite.http.api.cache.CacheArchive) NotFoundException(net.runelite.http.service.util.exception.NotFoundException) IndexEntry(net.runelite.http.service.cache.beans.IndexEntry) ArchiveEntry(net.runelite.http.service.cache.beans.ArchiveEntry) CacheEntry(net.runelite.http.service.cache.beans.CacheEntry) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 2 with NotFoundException

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;
}
Also used : Request(okhttp3.Request) NotFoundException(net.runelite.http.service.util.exception.NotFoundException) HttpUrl(okhttp3.HttpUrl) HiscoreEndpoint(net.runelite.http.api.hiscore.HiscoreEndpoint) Response(okhttp3.Response) Skill(net.runelite.http.api.hiscore.Skill) HiscoreSkill(net.runelite.http.api.hiscore.HiscoreSkill) CSVParser(org.apache.commons.csv.CSVParser) InternalServerErrorException(net.runelite.http.service.util.exception.InternalServerErrorException) CSVRecord(org.apache.commons.csv.CSVRecord)

Example 3 with NotFoundException

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;
}
Also used : NotFoundException(net.runelite.http.service.util.exception.NotFoundException) IndexEntry(net.runelite.http.service.cache.beans.IndexEntry) ArchiveEntry(net.runelite.http.service.cache.beans.ArchiveEntry) CacheEntry(net.runelite.http.service.cache.beans.CacheEntry)

Example 4 with NotFoundException

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;
}
Also used : ArchiveFiles(net.runelite.cache.fs.ArchiveFiles) NotFoundException(net.runelite.http.service.util.exception.NotFoundException) ArchiveEntry(net.runelite.http.service.cache.beans.ArchiveEntry) ObjectDefinition(net.runelite.cache.definitions.ObjectDefinition) ObjectLoader(net.runelite.cache.definitions.loaders.ObjectLoader) FSFile(net.runelite.cache.fs.FSFile) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 5 with NotFoundException

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());
}
Also used : CacheArchive(net.runelite.http.api.cache.CacheArchive) NotFoundException(net.runelite.http.service.util.exception.NotFoundException) IndexEntry(net.runelite.http.service.cache.beans.IndexEntry) ArchiveEntry(net.runelite.http.service.cache.beans.ArchiveEntry) CacheEntry(net.runelite.http.service.cache.beans.CacheEntry) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

NotFoundException (net.runelite.http.service.util.exception.NotFoundException)9 ArchiveEntry (net.runelite.http.service.cache.beans.ArchiveEntry)8 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)7 ArchiveFiles (net.runelite.cache.fs.ArchiveFiles)5 FSFile (net.runelite.cache.fs.FSFile)5 CacheEntry (net.runelite.http.service.cache.beans.CacheEntry)5 IndexEntry (net.runelite.http.service.cache.beans.IndexEntry)5 ItemDefinition (net.runelite.cache.definitions.ItemDefinition)3 NpcDefinition (net.runelite.cache.definitions.NpcDefinition)3 ObjectDefinition (net.runelite.cache.definitions.ObjectDefinition)3 ItemLoader (net.runelite.cache.definitions.loaders.ItemLoader)3 NpcLoader (net.runelite.cache.definitions.loaders.NpcLoader)3 ObjectLoader (net.runelite.cache.definitions.loaders.ObjectLoader)3 CacheArchive (net.runelite.http.api.cache.CacheArchive)3 BufferedImage (java.awt.image.BufferedImage)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 IOException (java.io.IOException)2 List (java.util.List)2 Collectors (java.util.stream.Collectors)2 ImageIO (javax.imageio.ImageIO)2