View Javadoc

1   package com.terradue.jcatalogue.client;
2   
3   /*
4    *    Copyright 2011-2012 Terradue srl
5    *
6    *    Licensed under the Apache License, Version 2.0 (the "License");
7    *    you may not use this file except in compliance with the License.
8    *    You may obtain a copy of the License at
9    *
10   *       http://www.apache.org/licenses/LICENSE-2.0
11   *
12   *    Unless required by applicable law or agreed to in writing, software
13   *    distributed under the License is distributed on an "AS IS" BASIS,
14   *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15   *    See the License for the specific language governing permissions and
16   *    limitations under the License.
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  }