Project

General

Profile

1
package eu.dnetlib.rmi.data;
2

    
3
import java.util.Date;
4

    
5
import com.google.gson.Gson;
6
import eu.dnetlib.miscutils.functional.hash.Hashing;
7

    
8
// TODO: Auto-generated Javadoc
9

    
10
/**
11
 * Download Item Class that serialize information in the resultset.
12
 */
13

    
14
public class DownloadItem {
15

    
16
	/**
17
	 * The id item metadata.
18
	 */
19
	private String idItemMetadata;
20
	/**
21
	 * The Url.
22
	 */
23
	private String Url;
24
	/**
25
	 * The file name.
26
	 */
27
	private String fileName;
28
	/**
29
	 * The original URL should be appear instead of the downloaded URL.
30
	 */
31
	private String originalUrl;
32
	/**
33
	 * The open access.
34
	 */
35
	private OpenAccessValues openAccess;
36
	/**
37
	 * The embargo date.
38
	 */
39
	private Date embargoDate;
40

    
41
	/**
42
	 * From json.
43
	 *
44
	 * @param inputJson the input json
45
	 * @return the download item
46
	 */
47
	public static DownloadItem newObjectfromJSON(final String inputJson) {
48
		Gson g = new Gson();
49
		DownloadItem instance = g.fromJson(inputJson, DownloadItem.class);
50
		return instance;
51
	}
52

    
53
	/**
54
	 * To json.
55
	 *
56
	 * @return the string
57
	 */
58
	public String toJSON() {
59
		return new Gson().toJson(this).replace("\\u003d", "=").replace("\\u0026", "&");
60
	}
61

    
62
	/**
63
	 * Gets the id item metadata.
64
	 *
65
	 * @return the id item metadata
66
	 */
67
	public String getIdItemMetadata() {
68
		return idItemMetadata;
69
	}
70

    
71
	/**
72
	 * Sets the id item metadata.
73
	 *
74
	 * @param idItemMetadata the new id item metadata
75
	 */
76
	public void setIdItemMetadata(final String idItemMetadata) {
77
		this.idItemMetadata = idItemMetadata;
78
	}
79

    
80
	/**
81
	 * Gets the url.
82
	 *
83
	 * @return the url
84
	 */
85
	public String getUrl() {
86
		if (Url == null) return null;
87
		return Url.replace("\\u003d", "=").replace("\\u0026", "&");
88
	}
89

    
90
	/**
91
	 * Sets the url.
92
	 *
93
	 * @param url the new url
94
	 */
95
	public void setUrl(final String url) {
96
		if (url == null) {
97
			Url = null;
98
		} else {
99
			Url = url.replace("\\u003d", "=Date").replace("\\u0026", "&");
100
		}
101
	}
102

    
103
	/**
104
	 * Gets the original url.
105
	 *
106
	 * @return the originalUrl
107
	 */
108
	public String getOriginalUrl() {
109
		if (originalUrl == null) return null;
110
		return originalUrl.replace("\\u003d", "=").replace("\\u0026", "&");
111
	}
112

    
113
	/**
114
	 * Sets the original url.
115
	 *
116
	 * @param originalUrl the originalUrl to set
117
	 */
118
	public void setOriginalUrl(final String originalUrl) {
119
		if (originalUrl == null) {
120
			this.originalUrl = null;
121
		} else {
122
			this.originalUrl = originalUrl.replace("\\u003d", "=").replace("\\u0026", "&");
123
		}
124
	}
125

    
126
	/**
127
	 * Gets the file name.
128
	 *
129
	 * @return the file name
130
	 */
131
	public String getFileName() {
132
		if ((fileName == null) || "".equals(fileName)) return getIdItemMetadata() + "::" + Hashing.md5(getOriginalUrl());
133
		return fileName;
134
	}
135

    
136
	/**
137
	 * Sets the file name.
138
	 *
139
	 * @param fileName the new file name
140
	 */
141
	public void setFileName(final String fileName) {
142
		this.fileName = fileName;
143
	}
144

    
145
	/**
146
	 * Gets the open access.
147
	 *
148
	 * @return the openAccess
149
	 */
150
	public String getOpenAccess() {
151
		return openAccess.toString();
152
	}
153

    
154
	/**
155
	 * Sets the open access.
156
	 *
157
	 * @param openAccess the openAccess to set
158
	 */
159
	public void setOpenAccess(final String openAccess) {
160
		for (OpenAccessValues oaValue : OpenAccessValues.values()) {
161
			if (oaValue.toString().trim().toLowerCase().equals(openAccess.trim().toLowerCase())) {
162
				this.openAccess = oaValue;
163
				return;
164
			}
165
		}
166
		this.openAccess = OpenAccessValues.UNKNOWN;
167
	}
168

    
169
	/**
170
	 * Gets the embargo date.
171
	 *
172
	 * @return the embargoDate
173
	 */
174
	public Date getEmbargoDate() {
175
		return embargoDate;
176
	}
177

    
178
	/**
179
	 * Sets the embargo date.
180
	 *
181
	 * @param embargoDate the embargoDate to set
182
	 */
183
	public void setEmbargoDate(final Date embargoDate) {
184
		this.embargoDate = embargoDate;
185
	}
186

    
187
	public enum OpenAccessValues {
188
		OPEN, RESTRICTED, CLOSED, EMBARGO, UNKNOWN
189
	}
190
}
(14-14/42)