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

be.looorent.ponto.client.http.JsonApi Maven / Gradle / Ivy

The newest version!
package be.looorent.ponto.client.http;

import be.looorent.ponto.client.CollectionResponse;
import be.looorent.ponto.client.Page;
import be.looorent.ponto.synchronization.Synchronization;
import lombok.Value;

import java.net.URL;
import java.time.LocalDateTime;
import java.util.Optional;
import java.util.UUID;

import static java.util.Optional.ofNullable;

public class JsonApi {
    @Value
    static class Single {
        private T data;
    }

    @Value
    static class Collection implements CollectionResponse {
        private Meta meta;
        private Links links;
        private java.util.Collection data;

        @Override
        public Page getPage() {
            return meta.getPaging();
        }

        @Override
        public java.util.Collection getEntities() {
            return data;
        }

        @Override
        public Optional getSynchronizedAt() {
            return ofNullable(meta)
                    .map(Meta::getSynchronizedAt);
        }

        @Override
        public Optional getLatestSynchronization() {
            return ofNullable(meta)
                    .map(Meta::getLatestSynchronization)
                    .map(JsonMapping::toEntity);
        }
    }

    @Value
    static class Links {
        private URL first;
        private URL prev;
        private URL next;
    }

    @Value
    static class Meta {
        private Page paging;
        private SynchronizationMapping.Data latestSynchronization;
        private LocalDateTime synchronizedAt;
    }

    @Value
    static class RelationshipLinks {
        private URL related;
    }

    @Value
    static class CollectionRelationship {
        private RelationshipLinks links;
    }

    @Value
    static class SingleRelationship {
        private Data data;
        private RelationshipLinks links;

        @Value
        static class Data {
            private String type;
            private UUID id;
        }

        public UUID getId() {
            return data.getId();
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy