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