1   package com.atlassian.plugins.rest.test;
2   
3   import com.atlassian.plugins.rest.common.expand.Expandable;
4   import com.atlassian.plugins.rest.common.expand.entity.ListWrapperCallBacks;
5   import com.google.common.collect.ImmutableList;
6   
7   import javax.ws.rs.core.UriInfo;
8   import javax.xml.bind.annotation.XmlAccessType;
9   import javax.xml.bind.annotation.XmlAccessorType;
10  import javax.xml.bind.annotation.XmlAttribute;
11  import javax.xml.bind.annotation.XmlElement;
12  import javax.xml.bind.annotation.XmlRootElement;
13  import java.util.Collections;
14  import java.util.List;
15  
16  @XmlRootElement
17  @XmlAccessorType(XmlAccessType.FIELD)
18  public class Project
19  {
20      @XmlAttribute
21      private String expand;
22  
23      @XmlAttribute
24      private final String name;
25  
26      @XmlElement
27      private final String description;
28  
29      @XmlElement
30      @Expandable
31      private ProjectInformation information;
32  
33      @XmlElement
34      @Expandable
35      private Developers developers;
36  
37      // For JAXB
38      private Project()
39      {
40          this.name = null;
41          this.description = null;
42      }
43  
44      public Project(String name, String description)
45      {
46          this.name = name;
47          this.description = description;
48      }
49  
50      public String getName()
51      {
52          return name;
53      }
54  
55      public String getDescription()
56      {
57          return description;
58      }
59  
60      public ProjectInformation getInformation()
61      {
62          return information;
63      }
64  
65      public void setInformation(ProjectInformation information)
66      {
67          this.information = information;
68      }
69  
70      public List<Developer> getDevelopers()
71      {
72          return developers.getDevelopers() != null ? ImmutableList.copyOf(developers.getDevelopers()) : Collections.<Developer>emptyList();
73      }
74  
75      public void setDevelopers(Developers developers)
76      {
77          this.developers = developers;
78      }
79  
80      public Project build(UriInfo uriInfo)
81      {
82          setInformation(ProjectInformation.getInformation(uriInfo));
83  
84          final List<Developer> developerList = DeveloperStore.getDevelopers(uriInfo);
85          setDevelopers(new Developers(developerList.size(), ListWrapperCallBacks.ofList(developerList)));
86          return this;
87      }
88  }