1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 package org.opencastproject.job.api;
23
24 import static org.opencastproject.util.data.Collections.nullToNil;
25
26 import org.opencastproject.job.api.Incident.Severity;
27 import org.opencastproject.util.data.Tuple;
28 import org.opencastproject.util.jaxb.UtcTimestampAdapter;
29
30 import java.util.Date;
31 import java.util.List;
32 import java.util.Map;
33 import java.util.Map.Entry;
34 import java.util.stream.Collectors;
35
36 import javax.xml.bind.annotation.XmlAccessType;
37 import javax.xml.bind.annotation.XmlAccessorType;
38 import javax.xml.bind.annotation.XmlAttribute;
39 import javax.xml.bind.annotation.XmlElement;
40 import javax.xml.bind.annotation.XmlElementWrapper;
41 import javax.xml.bind.annotation.XmlRootElement;
42 import javax.xml.bind.annotation.XmlType;
43 import javax.xml.bind.annotation.XmlValue;
44 import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
45
46
47 @XmlAccessorType(XmlAccessType.NONE)
48 @XmlType(name = "incident", namespace = "http://job.opencastproject.org")
49 @XmlRootElement(name = "incident", namespace = "http://job.opencastproject.org")
50 public final class JaxbIncident {
51 @XmlElement(name = "id")
52 private long id;
53
54 @XmlElement(name = "jobId")
55 private long jobId;
56
57 @XmlElement(name = "serviceType")
58 private String serviceType;
59
60 @XmlElement(name = "processingHost")
61 private String processingHost;
62
63 @XmlElement(name = "timestamp")
64 @XmlJavaTypeAdapter(UtcTimestampAdapter.class)
65 private Date timestamp;
66
67 @XmlElement(name = "severity")
68 private Severity severity;
69
70 @XmlElement(name = "code")
71 private String code;
72
73 @XmlElementWrapper(name = "descriptionParameters")
74 @XmlElement(name = "param")
75 private List<Param> descriptionParameters;
76
77 @XmlElementWrapper(name = "details")
78 @XmlElement(name = "detail")
79 private List<JaxbIncidentDetail> details;
80
81
82 public JaxbIncident() {
83 }
84
85 public JaxbIncident(Incident incident) {
86 this.id = incident.getId();
87 this.jobId = incident.getJobId();
88 this.serviceType = incident.getServiceType();
89 this.processingHost = incident.getProcessingHost();
90 this.timestamp = new Date(incident.getTimestamp().getTime());
91 this.severity = incident.getSeverity();
92 this.code = incident.getCode();
93 this.descriptionParameters = incident.getDescriptionParameters().entrySet().stream()
94 .map(Param::mk)
95 .collect(Collectors.toList());
96 this.details = incident.getDetails().stream()
97 .map(JaxbIncidentDetail::new)
98 .collect(Collectors.toList());
99 }
100
101 public Incident toIncident() {
102 List<Tuple<String, String>> mappedDetails = nullToNil(details).stream()
103 .map(JaxbIncidentDetail::toDetail)
104 .collect(Collectors.toList());
105
106 Map<String, String> paramMap = nullToNil(descriptionParameters).stream()
107 .collect(Collectors.toMap(
108 Param::getName,
109 Param::getValue
110 ));
111
112 return new IncidentImpl(
113 id,
114 jobId,
115 serviceType,
116 processingHost,
117 timestamp,
118 severity,
119 code,
120 mappedDetails,
121 paramMap
122 );
123 }
124
125
126
127
128 @XmlAccessorType(XmlAccessType.FIELD)
129 @XmlType(name = "param", namespace = "http://job.opencastproject.org")
130 public static final class Param {
131 @XmlAttribute(name = "name")
132 private String name;
133
134 @XmlValue
135 private String value;
136
137 public static Param mk(Entry<String, String> entry) {
138 final Param dto = new Param();
139 dto.name = entry.getKey();
140 dto.value = entry.getValue();
141 return dto;
142 }
143
144 public String getName() {
145 return name;
146 }
147
148 public String getValue() {
149 return value;
150 }
151 }
152 }