1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.maxur.perfmodel.backend.rest.dto;
17
18 import com.fasterxml.jackson.annotation.JsonRawValue;
19 import com.fasterxml.jackson.databind.JsonNode;
20 import org.jsondoc.core.annotation.ApiObject;
21 import org.jsondoc.core.annotation.ApiObjectField;
22 import org.maxur.perfmodel.backend.domain.Project;
23
24 import javax.xml.bind.annotation.XmlRootElement;
25 import java.io.Serializable;
26 import java.util.Collection;
27 import java.util.List;
28
29 import static java.util.stream.Collectors.toList;
30
31
32
33
34
35 @SuppressWarnings("unused")
36 @XmlRootElement
37 @ApiObject(name = "Project")
38 public class ProjectDto implements Serializable {
39
40 private static final long serialVersionUID = -5236202133124299315L;
41
42 @ApiObjectField(required = true, description = "The project identifier")
43 private String id;
44
45 @ApiObjectField(required = true, description = "The project name")
46 private String name;
47
48 @ApiObjectField(required = true, description = "The project version")
49 private int version;
50
51 @ApiObjectField(required = false, description = "The project description")
52 private String description;
53
54 @ApiObjectField(required = false, description = "The Serialized presentation of the object's models", format="[]")
55 @JsonRawValue
56 private String models;
57
58 @ApiObjectField(required = false, description = "The Serialized presentation of the object's view", format="{}")
59 @JsonRawValue
60 private String view;
61
62 @SuppressWarnings("UnusedDeclaration")
63 public ProjectDto() {
64 }
65
66 public ProjectDto(final String id, final String name, final int version, final String description) {
67 this.id = id;
68 this.name = name;
69 this.version = version;
70 this.description = description;
71 }
72
73 public String getId() {
74 return id;
75 }
76
77
78 public String getName() {
79 return name;
80 }
81
82 public int getVersion() {
83 return version;
84 }
85
86 public String getDescription() {
87 return description;
88 }
89
90 public String getModels() {
91 return models;
92 }
93
94 public String getView() {
95 return view;
96 }
97
98 public void setModels(final JsonNode models) {
99 this.models = models == null ? null : models.toString();
100 }
101
102 public void setView(final JsonNode view) {
103 this.view = view == null ? null : view.toString();
104 }
105
106
107
108
109
110
111
112 public static List<ProjectDto> dtoList(final Collection<Project> all) {
113 return all.stream().map(ProjectDto::dto).collect(toList());
114 }
115
116
117
118
119
120
121
122 public static ProjectDto dto(final Project project) {
123 final ProjectDto dto =
124 new ProjectDto(project.getId(), project.getName(), project.getVersion(), project.getDescription());
125 dto.models = project.getModels();
126 dto.view = project.getView();
127 return dto;
128 }
129
130
131
132
133
134
135 public Project assemble() {
136 final Project result = new Project(id, name, version, description);
137 result.setModels(models);
138 result.setView(view);
139 return result;
140 }
141 }