001package com.identityworksllc.iiq.common.plugin.vo;
002
003import com.fasterxml.jackson.annotation.JsonInclude;
004import com.fasterxml.jackson.annotation.JsonProperty;
005
006import java.util.ArrayList;
007import java.util.List;
008
009/**
010 * An abstract REST object implementing the <a href="https://spring.io/understanding/HATEOAS">HATEOAS</a> standard.
011 *
012 * This is one of the output types allowed by default in {@link com.identityworksllc.iiq.common.plugin.BaseCommonPluginResource},
013 * as extending this class indicates that you have considered its implications as an API response.
014 */
015public abstract class RestObject {
016    /**
017     * The list of external URL links to other resources
018     */
019    private List<Link> links;
020
021    /**
022     * Basic constructor to initialize the links list
023     */
024    public RestObject() {
025        links = new ArrayList<>();
026    }
027
028    /**
029     * Non-REST method to add a new Link to this object for return
030     * @param rel The link type
031     * @param href The link URL
032     */
033    public void addLink(String rel, String href) {
034        Link l = new Link();
035        l.setRel(rel);
036        l.setHref(href);
037        links.add(l);
038    }
039
040    /**
041     * The list of links
042     * @return The list of links
043     */
044    @JsonProperty
045    @JsonInclude(JsonInclude.Include.NON_EMPTY)
046    public List<Link> getLinks() {
047        return links;
048    }
049
050    /**
051     * Sets the list of links to the given one
052     * @param links The list of links to add
053     */
054    public void setLinks(List<Link> links) {
055        this.links = links;
056    }
057}