1   package com.terradue.jcatalogue.client;
2   
3   
4   
5   
6   
7   
8   
9   
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  import static com.terradue.jcatalogue.client.MimeTypes.ATOM_XML;
20  
21  import java.net.URI;
22  import java.util.ArrayList;
23  import java.util.Date;
24  import java.util.List;
25  
26  import com.terradue.jcatalogue.client.internal.collections.Enclosures;
27  
28  import lombok.AccessLevel;
29  import lombok.Data;
30  import lombok.EqualsAndHashCode;
31  import lombok.Getter;
32  
33  @Data
34  @EqualsAndHashCode( callSuper = false )
35  abstract class AtomEntity
36      extends CatalogueEntity
37  {
38  
39      private static final String NEXT = "next";
40  
41      private static final String ENCLOSURE = "enclosure";
42  
43      @Getter( AccessLevel.PACKAGE )
44      private final List<String> enitiesUrls = new ArrayList<String>();
45  
46      private String title;
47  
48      private String subtitle;
49  
50      private String content;
51  
52      private Date published;
53  
54      private Date updated;
55  
56      private String id;
57  
58      private int totalResults;
59  
60      private int startIndex;
61  
62      private int itemsPerPage;
63  
64      @Getter( AccessLevel.PACKAGE )
65      private String nextResultsUri;
66  
67      @Getter( AccessLevel.PACKAGE )
68      private final Enclosures enclosures = new Enclosures();
69  
70      public void addLink( String rel, String type, String href, Integer priority )
71      {
72          if ( NEXT.equals( rel ) && ATOM_XML.equals( type ) )
73          {
74              nextResultsUri = href;
75          }
76          else if ( ENCLOSURE.equals( rel ) )
77          {
78              enclosures.addEnclosure( URI.create( href ), priority );
79          }
80      }
81  
82      public final boolean hasMoreResults()
83      {
84          return nextResultsUri != null;
85      }
86  
87      public final void addEntityUrl( String serieUrl )
88      {
89          enitiesUrls.add( serieUrl );
90      }
91  
92  }