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

de.escalon.hypermedia.spring.siren.SirenEmbeddedRepresentation Maven / Gradle / Ivy

There is a newer version: 0.4.2
Show newest version
package de.escalon.hypermedia.spring.siren;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * Created by Dietrich on 17.04.2016.
 */
public class SirenEmbeddedRepresentation extends SirenSubEntity implements SirenEntityContainer {

    private Map properties;
    private List entities;
    private List links;
    private List actions;


    SirenEmbeddedRepresentation() {
        super();
    }

    /**
     * Siren entity.
     *
     * @param sirenClasses
     *         Describes the nature of an entity's content based on the current representation. Possible values are
     *         implementation-dependent and should be documented. MUST be an array of strings. Optional.
     * @param properties
     *         A set of key-value pairs that describe the state of an entity. In JSON Siren, this is an object such as
     *         { "name": "Kevin", "age": 30 }. Optional.
     * @param entities
     *         A collection of related sub-entities. If a sub-entity contains an href value, it should be treated as an
     *         embedded link. Clients may choose to optimistically load embedded links. If no href value exists, the
     *         sub-entity is an embedded entity representation that contains all the characteristics of a typical
     *         entity. One difference is that a sub-entity MUST contain a rel attribute to describe its relationship to
     *         the parent entity. In JSON Siren, this is represented as an array. Optional.
     * @param links
     *         A collection of items that describe navigational links, distinct from entity relationships. Link items
     *         should contain a rel attribute to describe the relationship and an href attribute to point to the target
     *         URI. Entities should include a link rel to self. In JSON Siren, this is represented as "links": [{
     *         "rel":
     *         ["self"], "href": "http://api.x.io/orders/1234" }] Optional.
     * @param actions
     *         A collection of action objects, represented in JSON Siren as an array such as { "actions": [{ ... }] }.
     *         See Actions. Optional
     * @param rels
     *         Defines the relationship of the sub-entity to its parent, per Web Linking (RFC5899). MUST be an array of
     *         strings. Required.
     * @param title
     *         Descriptive text about the entity. Optional.
     */
    public SirenEmbeddedRepresentation(List sirenClasses, Map properties,
                                       List entities,
                                       List actions, List links, List rels, String
                                               title) {

        super(rels, title, sirenClasses);
        this.properties = properties;
        this.entities = entities;
        this.actions = actions;
        this.links = links;
    }

    public Map getProperties() {
        return properties;
    }

    @Override
    public List getEntities() {
        @SuppressWarnings("unchecked")
        List ret = (List) entities;
        return ret;
    }

    public List getLinks() {
        return links;
    }

    public List getActions() {
        return actions;
    }

    public void setLinks(List links) {
        this.links = links;
    }

    public void setProperties(Map properties) {
        this.properties = properties;
    }

    @Override
    public void addSubEntity(SirenSubEntity sirenSubEntity) {
        if (this.entities == null) {
            this.entities = new ArrayList();
        }
        entities.add(sirenSubEntity);
    }

    public void setEmbeddedLinks(List embeddedLinks) {
        if (this.entities == null) {
            this.entities = new ArrayList();
        }
        this.entities.addAll(embeddedLinks);
    }

    public void setActions(List actions) {
        this.actions = actions;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy