Package: JobEventXml
JobEventXml
name | instruction | branch | complexity | line | method | ||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
JobEventXml(JobEvent) |
|
|
|
|
|
||||||||||||||||||||
lambda$toJobEvents$0(JobEventXml) |
|
|
|
|
|
||||||||||||||||||||
toBuilder() |
|
|
|
|
|
||||||||||||||||||||
toJobEvents(List) |
|
|
|
|
|
Coverage
1: /*
2: * *************************************************************************************************************************************************************
3: *
4: * blueHour: open source accounting
5: * http://tidalwave.it/projects/bluehour
6: *
7: * Copyright (C) 2013 - 2024 by Tidalwave s.a.s. (http://tidalwave.it)
8: *
9: * *************************************************************************************************************************************************************
10: *
11: * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License.
12: * You may obtain a copy of the License at
13: *
14: * http://www.apache.org/licenses/LICENSE-2.0
15: *
16: * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
17: * CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
18: *
19: * *************************************************************************************************************************************************************
20: *
21: * git clone https://bitbucket.org/tidalwave/bluehour-src
22: * git clone https://github.com/tidalwave-it/bluehour-src
23: *
24: * *************************************************************************************************************************************************************
25: */
26: package it.tidalwave.accounting.exporter.xml.impl.xml;
27:
28: import javax.annotation.Nonnull;
29: import javax.annotation.Nullable;
30: import java.time.LocalDateTime;
31: import java.util.Collections;
32: import java.util.List;
33: import javax.xml.bind.annotation.XmlAccessorOrder;
34: import javax.xml.bind.annotation.XmlAccessorType;
35: import javax.xml.bind.annotation.XmlAttribute;
36: import javax.xml.bind.annotation.XmlElement;
37: import javax.xml.bind.annotation.XmlElementWrapper;
38: import javax.xml.bind.annotation.XmlID;
39: import javax.xml.bind.annotation.XmlRootElement;
40: import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
41: import it.tidalwave.accounting.exporter.xml.impl.adapters.EventTypeAdapter;
42: import it.tidalwave.accounting.exporter.xml.impl.adapters.IdAdapter;
43: import it.tidalwave.accounting.exporter.xml.impl.adapters.LocalDateTimeAdapter;
44: import it.tidalwave.accounting.exporter.xml.impl.adapters.MoneyAdapter;
45: import it.tidalwave.accounting.model.JobEvent;
46: import it.tidalwave.accounting.model.types.Money;
47: import it.tidalwave.util.Id;
48: import lombok.NoArgsConstructor;
49: import lombok.ToString;
50: import static javax.xml.bind.annotation.XmlAccessOrder.ALPHABETICAL;
51: import static javax.xml.bind.annotation.XmlAccessType.FIELD;
52: import static java.util.stream.Collectors.*;
53:
54: /***************************************************************************************************************************************************************
55: *
56: * @author Fabrizio Giudici
57: *
58: **************************************************************************************************************************************************************/
59: @NoArgsConstructor @ToString
60: @XmlRootElement(name = "event") @XmlAccessorType(FIELD) @XmlAccessorOrder(ALPHABETICAL)
61: public class JobEventXml
62: {
63: @XmlAttribute(name = "id")
64: @XmlID
65: @XmlJavaTypeAdapter(IdAdapter.class)
66: private Id id;
67:
68: @XmlElement(name = "type")
69: @XmlJavaTypeAdapter(EventTypeAdapter.class)
70: private JobEvent.Type type;
71:
72: @XmlElement(name = "startDateTime")
73: @XmlJavaTypeAdapter(LocalDateTimeAdapter.class)
74: private LocalDateTime startDateTime;
75:
76: @XmlElement(name = "endDateTime")
77: @XmlJavaTypeAdapter(LocalDateTimeAdapter.class)
78: private LocalDateTime endDateTime;
79:
80: @XmlElement(name = "name")
81: private String name;
82:
83: @XmlElement(name = "description")
84: private String description;
85:
86: @XmlElement(name = "earnings")
87: @XmlJavaTypeAdapter(MoneyAdapter.class)
88: private Money earnings;
89:
90: @XmlElement(name = "hourlyRate")
91: @XmlJavaTypeAdapter(MoneyAdapter.class)
92: private Money hourlyRate;
93:
94: @XmlElementWrapper(name = "events")
95: @XmlElement(name = "event")
96: private List<JobEventXml> jobEventsXml;
97:
98: public JobEventXml (@Nonnull final JobEvent jobEvent)
99: {
100: final var builder = jobEvent.toBuilder();
101: this.id = builder.getId();
102: this.type = builder.getType();
103: this.startDateTime = builder.getStartDateTime();
104: this.endDateTime = builder.getEndDateTime();
105: this.name = builder.getName();
106: this.description = builder.getDescription();
107: this.earnings = builder.getEarnings();
108: this.hourlyRate = builder.getHourlyRate();
109:• this.jobEventsXml = builder.getEvents().isEmpty()
110: ? null
111: : builder.getEvents().stream().map(JobEventXml::new).collect(toList());
112: }
113:
114: @Nonnull
115: public JobEvent.Builder toBuilder()
116: {
117: return JobEvent.builder().withId(id)
118: .withType(type)
119: .withStartDateTime(startDateTime)
120: .withEndDateTime(endDateTime)
121: .withName(name)
122: .withDescription(description)
123: .withEarnings(earnings)
124: .withHourlyRate(hourlyRate)
125: .withEvents(toJobEvents(jobEventsXml));
126: }
127:
128: @Nonnull
129: public static List<JobEvent> toJobEvents (@Nullable final List<? extends JobEventXml> jobEventsXml)
130: {
131:• return (jobEventsXml == null)
132: ? Collections.emptyList()
133: : jobEventsXml.stream().map(jobEventXml -> jobEventXml.toBuilder().create()).collect(toList());
134: }
135: }