Project

General

Profile

1
package eu.dnetlib.dli.resolver.model;
2

    
3
import java.util.List;
4

    
5
import eu.dnetlib.dli.DLIUtils;
6
import eu.dnetlib.miscutils.functional.xml.DnetXsltFunctions;
7
import eu.dnetlib.pid.resolver.model.ObjectType;
8
import org.apache.commons.lang3.StringEscapeUtils;
9

    
10
/**
11
 * The Class DLIRelation.
12
 */
13
public class DLIObjectRelation {
14

    
15
	/**
16
	 * The source doi.
17
	 */
18
	private String sourceRecordId;
19

    
20
	/**
21
	 * The source doi.
22
	 */
23
	private String sourcePid;
24

    
25
	/**
26
	 * The target type.
27
	 */
28
    private ObjectType targetType = ObjectType.unknown;
29

    
30
	/**
31
	 * The target pid.
32
	 */
33
	private PID targetPID;
34

    
35
	/**
36
	 * The target title.
37
	 */
38
	private String targetTitle;
39

    
40
	/**
41
	 * The authors.
42
	 */
43
	private List<String> authors;
44

    
45
	/**
46
	 * The relation semantics.
47
	 */
48
	private String relationSemantics;
49

    
50
	private String inverseRelation;
51

    
52
	/**
53
	 * The relation provenance.
54
	 */
55
    private List<DLIObjectProvenance> relationProvenance;
56

    
57
	/**
58
	 * The status.
59
	 */
60
	private String completionStatus = "incomplete";
61

    
62
    private DLIResolvedObject extraInfo;
63

    
64
	/**
65
	 * Gets the source do
66
	 *
67
	 * @return the source doi
68
	 */
69
	public String getSourceRecordId() {
70
		return sourceRecordId;
71
	}
72

    
73
	/**
74
	 * Sets the source doi.
75
	 *
76
	 * @param sourceRecordId the new source record id
77
	 */
78
	public void setSourceRecordId(final String sourceRecordId) {
79
		if (sourceRecordId != null) {
80
			this.sourceRecordId = sourceRecordId;
81
		}
82
	}
83

    
84
	/**
85
	 * Gets the escaped xmldoi.
86
	 *
87
	 * @return the escaped xmldoi
88
	 */
89
	public String getEscapedXMLDOI() {
90
        return StringEscapeUtils.escapeXml11(sourceRecordId);
91
    }
92

    
93
	/**
94
	 * Gets the target type.
95
	 *
96
	 * @return the target type
97
	 */
98
	public ObjectType getTargetType() {
99
		return targetType;
100
	}
101

    
102
	/**
103
	 * Sets the target type.
104
	 *
105
	 * @param targetType the new target type
106
	 */
107
	public void setTargetType(final ObjectType targetType) {
108
		this.targetType = targetType;
109
	}
110

    
111
	/**
112
	 * Gets the ID relation.
113
	 *
114
	 * @return the ID relation
115
	 */
116
	public String getIDRelation() {
117

    
118
		if ((this.getSourceRecordId() == null) || (this.getTargetPID() == null) || (this.getTargetPID().getId() == null))
119
			return null;
120
		return String.format("%s::%s", this.getSourceRecordId(), DnetXsltFunctions.md5(getTargetPID().getId().toLowerCase().trim()));
121
	}
122

    
123
	public String getIDRecord() {
124
		return (DnetXsltFunctions.md5(String.format("%s::%s", this.getTargetPID().getId(), this.getTargetPID().getType())));
125
	}
126

    
127
	/**
128
	 * Gets the target pid.
129
	 *
130
	 * @return the target pid
131
	 */
132
	public PID getTargetPID() {
133
		return targetPID;
134
	}
135

    
136
	/**
137
	 * Sets the target pid.
138
	 *
139
	 * @param targetPID the new target pid
140
	 */
141
	public void setTargetPID(final PID targetPID) {
142

    
143
		if (targetPID.getType() != null && "doi".equals(targetPID.getType().trim().toLowerCase()))
144
			targetPID.setId(DLIUtils.fixPID(targetPID.getId()));
145
		this.targetPID = targetPID;
146
	}
147

    
148
	/**
149
	 * Gets the target title.
150
	 *
151
	 * @return the target title
152
	 */
153
	public String getTargetTitle() {
154
		if (targetTitle == null) return null;
155
		String bf = targetTitle;
156
		bf = bf.replaceAll("&", "&amp;");
157
		bf = bf.replaceAll("\"", "&quot;");
158
		bf = bf.replaceAll("'", "&apos;");
159
		bf = bf.replaceAll("<", "&lt;");
160
		bf = bf.replaceAll(">", "&gt;");
161
		return bf;
162
	}
163

    
164
	/**
165
	 * Sets the target title.
166
	 *
167
	 * @param targetTitle the new target title
168
	 */
169
	public void setTargetTitle(final String targetTitle) {
170
		this.targetTitle = targetTitle;
171
	}
172

    
173
	/**
174
	 * Gets the relation semantics.
175
	 *
176
	 * @return the relation semantics
177
	 */
178
	public String getRelationSemantics() {
179
		return relationSemantics;
180
	}
181

    
182
	/**
183
	 * Sets the relation semantics.
184
	 *
185
	 * @param relationSemantics the new relation semantics
186
	 */
187
	public void setRelationSemantics(final String relationSemantics) {
188
		this.relationSemantics = relationSemantics;
189
	}
190

    
191
	public String getInverseRelation() {
192
		return inverseRelation;
193
	}
194

    
195
	public void setInverseRelation(String inverseRelation) {
196
		this.inverseRelation = inverseRelation;
197
	}
198

    
199
	/**
200
	 * Gets the relation provenance.
201
	 *
202
	 * @return the relationProvenance
203
	 */
204
    public List<DLIObjectProvenance> getRelationProvenance() {
205
        return relationProvenance;
206
	}
207

    
208
	/**
209
	 * Sets the relation provenance.
210
	 *
211
	 * @param relationProvenance the relationProvenance to set
212
	 */
213
    public void setRelationProvenance(final List<DLIObjectProvenance> relationProvenance) {
214
        this.relationProvenance = relationProvenance;
215
	}
216

    
217
	/**
218
	 * Gets the completion status.
219
	 *
220
	 * @return the completion status
221
	 */
222
	public String getCompletionStatus() {
223
		return this.completionStatus;
224
	}
225

    
226
	/**
227
	 * Sets the completion status.
228
	 *
229
	 * @param completionStatus the new completion status
230
	 */
231
	public void setCompletionStatus(final String completionStatus) {
232
		this.completionStatus = completionStatus;
233
	}
234

    
235
	/**
236
	 * Gets the source pid.
237
	 *
238
	 * @return the source pid
239
	 */
240
	public String getSourcePid() {
241
		return sourcePid;
242
	}
243

    
244
	/**
245
	 * Sets the source pid.
246
	 *
247
	 * @param sourcePid the new source pid
248
	 */
249
	public void setSourcePid(final String sourcePid) {
250
		this.sourcePid = sourcePid;
251
	}
252

    
253
	/**
254
	 * {@inheritDoc}
255
	 *
256
	 * @see Object#toString()
257
	 */
258
	@Override
259
	public String toString() {
260
		String format =
261
				"Relation: \n\tId:%s \n\tSourcePid%s \n\tTargetPid:%s \n\tTargetPidType:%s \n\ttitle:%s \n\tCompletionStatus:%s \n\t Relation Semantic:%s \n\tProvenances:%s";
262
		return String.format(format, this.getIDRelation(), this.getSourcePid(), this.getTargetPID() == null ? "" : this.getTargetPID(),
263
				this.getTargetType(), this.getTargetTitle(), this.getCompletionStatus(), this.getRelationSemantics(),
264
				this.getRelationProvenance());
265
	}
266

    
267
	/**
268
	 * Gets the authors.
269
	 *
270
	 * @return the authors
271
	 */
272
	public List<String> getAuthors() {
273
		return authors;
274
	}
275

    
276
	/**
277
	 * Sets the authors.
278
	 *
279
	 * @param authors the new authors
280
	 */
281
	public void setAuthors(final List<String> authors) {
282
		this.authors = authors;
283
	}
284

    
285
	/**
286
	 * Gets the escaped xml authors.
287
	 *
288
	 * @return the escaped xml authors
289
	 */
290
	public List<String> getEscapedXMLAuthors() {
291
		if (authors != null)
292
            return DLIResolvedObject.escapedArray(authors);
293
        return null;
294
	}
295

    
296
    public DLIResolvedObject getExtraInfo() {
297
        return extraInfo;
298
	}
299

    
300
    public void setExtraInfo(final DLIResolvedObject extraInfo) {
301
        this.extraInfo = extraInfo;
302
	}
303
}
(3-3/8)