Project

General

Profile

1
package eu.dnetlib.openaire.exporter.tmpModel;
2

    
3
import java.util.ArrayList;
4
import java.util.List;
5

    
6
import com.google.common.base.Splitter;
7
import com.google.common.collect.Lists;
8
import org.apache.commons.lang3.StringUtils;
9

    
10
/**
11
 * Created by claudio on 20/09/16.
12
 */
13
public class Project {
14

    
15
	public static final String INFO_EU_REPO_GRANT_AGREEMENT = "info:eu-repo/grantAgreement/";
16
	private String code;
17
	private String acronym;
18
	private String title;
19
	private String callIdentifier;
20
	private String startdate;
21
	private String enddate;
22
	private boolean oaMandateForPublications;
23
	private boolean oaMandateForDatasets;
24
	private String fundingpathid;
25
	private String description;
26
	private String funder;
27
	private String jurisdiction;
28
	private String orgLegalname;
29
	private String orgCountry;
30
	private String orgRole;
31
	private String firstname;
32
	private String secondnames;
33
	private String email;
34

    
35
	public Project() {
36
	}
37

    
38
	public String getIdnamespace() {
39
		String res = INFO_EU_REPO_GRANT_AGREEMENT + getFunder()+"/";
40
		final String fundingProgram = asFundingProgram(getFundingpathid());
41
		if (StringUtils.isNotBlank(fundingProgram)) {
42
			res += fundingProgram;
43
		}
44
		res += "/" + escapeCode(getCode());
45
		if (StringUtils.isNotBlank(getJurisdiction())) {
46
			res += "/" + getJurisdiction();
47
		}
48
		return res;
49
	}
50

    
51
	public String getListLabel() {
52
		return String.format("for:value:component:_%s_project_id", asFunder(getFunder()));
53
	}
54

    
55
	private String asFunder(final String legalshortname) {
56
		switch (legalshortname.toLowerCase()) {
57
		case "ec":
58
			return asFundingProgram(getFundingpathid()).toLowerCase();
59
		default:
60
			return legalshortname.toLowerCase();
61
		}
62
	}
63

    
64
	public List<String> asList() {
65
		return Lists.newArrayList(
66
				clean(getCode()),
67
				clean(getAcronym()),
68
				clean(getTitle()),
69
				clean(getCallIdentifier()),
70
				clean(getStartdate()),
71
				clean(getEnddate()),
72
				String.valueOf(isOaMandateForPublications()),
73
				String.valueOf(isOaMandateForDatasets()),
74
				clean(getDescription()),
75
				clean(getOrgLegalname()),
76
				clean(getOrgCountry()),
77
				clean(getOrgRole()),
78
				clean(getFirstname()),
79
				clean(getSecondnames()),
80
				clean(getEmail()));
81
	}
82

    
83
	private String clean(final String s) {
84
		return StringUtils.isNotBlank(s) ? "\"" + s.replaceAll("\\n|\\t|\\s+", " ").replace("\"","\"\"").trim() + "\"" : "";
85
	}
86

    
87
	private String escapeCode(final String code) {
88
		return replaceSlash(code);
89
	}
90

    
91
	private String asFundingProgram(final String fundingpathid) {
92
		final ArrayList<String> strings = Lists.newArrayList(Splitter.on("::").split(fundingpathid));
93
		if(strings.size() <= 1) throw new IllegalStateException("Unexpected funding id: "+fundingpathid);
94
		if(strings.size() == 2) return "";
95
		else return replaceSlash(strings.get(2));
96
	}
97

    
98
	private String replaceSlash(final String s) {
99
		return s.replaceAll("/", "%2F");
100
	}
101

    
102
	public String getCode() {
103
		return code;
104
	}
105

    
106
	public Project setCode(final String code) {
107
		this.code = code;
108
		return this;
109
	}
110

    
111
	public String getAcronym() {
112
		return acronym;
113
	}
114

    
115
	public Project setAcronym(final String acronym) {
116
		this.acronym = acronym;
117
		return this;
118
	}
119

    
120
	public String getTitle() {
121
		return title;
122
	}
123

    
124
	public Project setTitle(final String title) {
125
		this.title = title;
126
		return this;
127
	}
128

    
129
	public String getCallIdentifier() {
130
		return callIdentifier;
131
	}
132

    
133
	public Project setCallIdentifier(final String call_identifier) {
134
		this.callIdentifier = call_identifier;
135
		return this;
136
	}
137

    
138
	public String getStartdate() {
139
		return startdate;
140
	}
141

    
142
	public Project setStartdate(final String startdate) {
143
		this.startdate = startdate;
144
		return this;
145
	}
146

    
147
	public String getEnddate() {
148
		return enddate;
149
	}
150

    
151
	public Project setEnddate(final String enddate) {
152
		this.enddate = enddate;
153
		return this;
154
	}
155

    
156
	public boolean isOaMandateForPublications() {
157
		return oaMandateForPublications;
158
	}
159

    
160
	public Project setOaMandateForPublications(final boolean oaMandateForPublications) {
161
		this.oaMandateForPublications = oaMandateForPublications;
162
		return this;
163
	}
164

    
165
	public boolean isOaMandateForDatasets() {
166
		return oaMandateForDatasets;
167
	}
168

    
169
	public Project setOaMandateForDatasets(final boolean oaMandateForDatasets) {
170
		this.oaMandateForDatasets = oaMandateForDatasets;
171
		return this;
172
	}
173

    
174

    
175
	public String getFundingpathid() {
176
		return fundingpathid;
177
	}
178

    
179
	public Project setFundingpathid(final String fundingpathid) {
180
		this.fundingpathid = fundingpathid;
181
		return this;
182
	}
183

    
184
	public String getDescription() {
185
		return description;
186
	}
187

    
188
	public Project setDescription(final String description) {
189
		this.description = description;
190
		return this;
191
	}
192

    
193
	public String getJurisdiction() {
194
		return jurisdiction;
195
	}
196

    
197
	public Project setJurisdiction(final String jurisdiction) {
198
		this.jurisdiction = jurisdiction;
199
		return this;
200
	}
201

    
202
	public String getOrgLegalname() {
203
		return orgLegalname;
204
	}
205

    
206
	public Project setOrgLegalname(final String legalname) {
207
		this.orgLegalname = legalname;
208
		return this;
209
	}
210

    
211
	public String getOrgCountry() {
212
		return orgCountry;
213
	}
214

    
215
	public Project setOrgCountry(final String country) {
216
		this.orgCountry = country;
217
		return this;
218
	}
219

    
220
	public String getOrgRole() {
221
		return orgRole;
222
	}
223

    
224
	public Project setOrgRole(final String role) {
225
		this.orgRole = role;
226
		return this;
227
	}
228

    
229
	public String getFirstname() {
230
		return firstname;
231
	}
232

    
233
	public Project setFirstname(final String firstname) {
234
		this.firstname = firstname;
235
		return this;
236
	}
237

    
238
	public String getSecondnames() {
239
		return secondnames;
240
	}
241

    
242
	public Project setSecondnames(final String secondnames) {
243
		this.secondnames = secondnames;
244
		return this;
245
	}
246

    
247
	public String getEmail() {
248
		return email;
249
	}
250

    
251
	public Project setEmail(final String email) {
252
		this.email = email;
253
		return this;
254
	}
255

    
256
	public String getFunder() {
257
		return funder;
258
	}
259

    
260
	public Project setFunder(final String funder) {
261
		this.funder = funder;
262
		return this;
263
	}
264
}
(1-1/2)