1
|
package eu.dnetlib.actionmanager.set;
|
2
|
|
3
|
import java.io.Serializable;
|
4
|
import java.text.ParseException;
|
5
|
import java.util.*;
|
6
|
import javax.xml.bind.annotation.XmlRootElement;
|
7
|
|
8
|
import org.apache.commons.lang3.time.DateUtils;
|
9
|
|
10
|
@XmlRootElement
|
11
|
public class ActionManagerSet implements Serializable {
|
12
|
|
13
|
/**
|
14
|
*
|
15
|
*/
|
16
|
private static final long serialVersionUID = 7262893241919858735L;
|
17
|
public static final String[] DATE_PATTERNS = new String[]{"yyyy-MM-dd\'T\'hh:mm:ss+00:00", "yyyy-MM-dd\'T\'hh:mm:ssXXX"};
|
18
|
|
19
|
public enum ImpactTypes {
|
20
|
ONLY_INSERT, INSERT_UPDATE
|
21
|
}
|
22
|
|
23
|
private String id;
|
24
|
private String name;
|
25
|
private ImpactTypes impact = ImpactTypes.INSERT_UPDATE;
|
26
|
private String directory;
|
27
|
private String pathToLatest;
|
28
|
private RawSet latest;
|
29
|
private TreeSet<RawSet> expired;
|
30
|
|
31
|
public ActionManagerSet() {
|
32
|
this.expired = new TreeSet<RawSet>(getRawSetComparator());
|
33
|
}
|
34
|
|
35
|
public ActionManagerSet(final String id, final String name, final String directory) {
|
36
|
this(id, name, directory, ImpactTypes.INSERT_UPDATE, null);
|
37
|
}
|
38
|
|
39
|
public ActionManagerSet(final String id, final String name, final String directory, final ImpactTypes impact, final RawSet latest) {
|
40
|
this(id, name, directory, impact, null, latest);
|
41
|
}
|
42
|
|
43
|
public ActionManagerSet(final String id, final String name, final String directory, final ImpactTypes impact, final String pathToLatest, final RawSet latest) {
|
44
|
super();
|
45
|
this.id = id;
|
46
|
this.name = name;
|
47
|
this.directory = directory;
|
48
|
this.impact = impact;
|
49
|
this.pathToLatest = pathToLatest;
|
50
|
this.latest = latest;
|
51
|
this.expired = new TreeSet<RawSet>(getRawSetComparator());
|
52
|
}
|
53
|
|
54
|
public String getId() {
|
55
|
return id;
|
56
|
}
|
57
|
|
58
|
public void setId(final String id) {
|
59
|
this.id = id;
|
60
|
}
|
61
|
|
62
|
public String getName() {
|
63
|
return name;
|
64
|
}
|
65
|
|
66
|
public void setName(final String name) {
|
67
|
this.name = name;
|
68
|
}
|
69
|
|
70
|
public ImpactTypes getImpact() {
|
71
|
return impact;
|
72
|
}
|
73
|
|
74
|
public void setImpact(final ImpactTypes impact) {
|
75
|
this.impact = impact;
|
76
|
}
|
77
|
|
78
|
public String getPathToLatest() {
|
79
|
return pathToLatest;
|
80
|
}
|
81
|
|
82
|
public void setPathToLatest(final String pathToLatest) {
|
83
|
this.pathToLatest = pathToLatest;
|
84
|
}
|
85
|
|
86
|
@Override
|
87
|
public String toString() {
|
88
|
return "[ id: " + id + ", name: " + name + ", impact: " + impact + " ]";
|
89
|
}
|
90
|
|
91
|
public RawSet getLatest() {
|
92
|
return latest;
|
93
|
}
|
94
|
|
95
|
public void setLatest(final RawSet latest) {
|
96
|
this.latest = latest;
|
97
|
}
|
98
|
|
99
|
public void setLatest(final String rawSetId, final String creationDate, final String lastUpdate) {
|
100
|
setLatest(new RawSet(rawSetId.trim(), creationDate.trim(), lastUpdate.trim()));
|
101
|
}
|
102
|
|
103
|
private Comparator<RawSet> getRawSetComparator() {
|
104
|
return (o1, o2) -> {
|
105
|
try {
|
106
|
final Date d1 = DateUtils.parseDate(o1.getLastUpdate(), DATE_PATTERNS);
|
107
|
final Date d2 = DateUtils.parseDate(o2.getLastUpdate(), DATE_PATTERNS);
|
108
|
return d1.compareTo(d2);
|
109
|
} catch (ParseException e) {
|
110
|
throw new RuntimeException(
|
111
|
String.format("unable to parse dates: %s, %s. Known patterns: %s", o1.getLastUpdate(), o2.getLastUpdate(), Arrays.asList(DATE_PATTERNS)));
|
112
|
}
|
113
|
};
|
114
|
}
|
115
|
|
116
|
public Set<RawSet> getExpired() {
|
117
|
return expired;
|
118
|
}
|
119
|
|
120
|
public void addExpired(final String rawSetId, final String creationDate, final String lastUpdate) {
|
121
|
addExpired(new RawSet(rawSetId.trim(), creationDate.trim(), lastUpdate.trim()));
|
122
|
}
|
123
|
|
124
|
public void addExpired(final RawSet rawSet) {
|
125
|
getExpired().add(rawSet);
|
126
|
}
|
127
|
|
128
|
public String getDirectory() {
|
129
|
return directory;
|
130
|
}
|
131
|
|
132
|
public void setDirectory(final String directory) {
|
133
|
this.directory = directory;
|
134
|
}
|
135
|
}
|