All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.qmetric.feed.consumer.DefaultResourceResolver Maven / Gradle / Ivy

Go to download

Java library for consuming HAL+JSON feeds (https://github.com/qmetric/hal-feed-server)

There is a newer version: 3.18
Show newest version
package com.qmetric.feed.consumer;

import com.theoryinpractise.halbuilder.api.ReadableRepresentation;
import com.theoryinpractise.halbuilder.api.RepresentationFactory;

import static java.lang.String.format;

public class DefaultResourceResolver implements ResourceResolver
{
    private static final String FEED_ENTRY_URL_TEMPLATE = "%s/%s";

    private final String feedUrl;

    private final RepresentationFactory representationFactory;

    private final FeedEndpointFactory endpoint;

    public DefaultResourceResolver(final String feedUrl, final FeedEndpointFactory endpoint, final RepresentationFactory representationFactory)
    {
        this.feedUrl = feedUrl;
        this.endpoint = endpoint;
        this.representationFactory = representationFactory;
    }

    @Override public ReadableRepresentation resolve(final EntryId id)
    {
        return representationFactory.readRepresentation(endpoint.create(buildUrlToFeedEntry(id)).get());
    }

    private String buildUrlToFeedEntry(final EntryId id)
    {
        return format(FEED_ENTRY_URL_TEMPLATE, feedUrl, id);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy