Project

General

Profile

1
package eu.dnetlib.openaire.exporter.model.project;
2

    
3
import java.sql.Date;
4
import java.util.ArrayList;
5
import javax.persistence.Entity;
6
import javax.persistence.Id;
7
import javax.persistence.Table;
8

    
9
import com.fasterxml.jackson.annotation.JsonIgnore;
10
import com.google.common.base.Splitter;
11
import com.google.common.collect.Lists;
12
import io.swagger.annotations.ApiModel;
13
import org.apache.commons.lang3.StringUtils;
14

    
15
/**
16
 * Created by claudio on 20/09/16.
17
 */
18
@Entity
19
@Table(name = "projects_api")
20
@ApiModel(value = "Project api model", description = "Project api model used by DSpace and Eprints exporter")
21
public class ProjectApi {
22

    
23
	public static final String INFO_EU_REPO_GRANT_AGREEMENT = "info:eu-repo/grantAgreement/";
24

    
25
	@Id
26
	@JsonIgnore
27
	private String id;
28

    
29
	private String code;
30
	private String acronym;
31
	private String title;
32
	private String funder;
33
	private String jurisdiction;
34
	private Date startdate;
35
	private Date enddate;
36
	private String fundingpathid;
37

    
38
	public ProjectApi() { }
39

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

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

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

    
66
	private String escapeCode(final String code) {
67
		return replaceSlash(code);
68
	}
69

    
70
	private String asFundingProgram(final String fundingpathid) {
71
		final ArrayList<String> strings = Lists.newArrayList(Splitter.on("::").split(fundingpathid));
72
		if(strings.size() <= 1) throw new IllegalStateException("Unexpected funding id: "+fundingpathid);
73
		if(strings.size() == 2) return "";
74
		else return replaceSlash(strings.get(2));
75
	}
76

    
77
	private String replaceSlash(final String s) {
78
		return s.replaceAll("/", "%2F");
79
	}
80

    
81
	public String getId() {
82
		return id;
83
	}
84

    
85
	public void setId(final String id) {
86
		this.id = id;
87
	}
88

    
89
	public String getCode() {
90
		return code;
91
	}
92

    
93
	public void setCode(final String code) {
94
		this.code = code;
95
	}
96

    
97
	public String getAcronym() {
98
		return acronym;
99
	}
100

    
101
	public void setAcronym(final String acronym) {
102
		this.acronym = acronym;
103
	}
104

    
105
	public String getTitle() {
106
		return title;
107
	}
108

    
109
	public void setTitle(final String title) {
110
		this.title = title;
111
	}
112

    
113
	public String getFunder() {
114
		return funder;
115
	}
116

    
117
	public void setFunder(final String funder) {
118
		this.funder = funder;
119
	}
120

    
121
	public String getJurisdiction() {
122
		return jurisdiction;
123
	}
124

    
125
	public void setJurisdiction(final String jurisdiction) {
126
		this.jurisdiction = jurisdiction;
127
	}
128

    
129
	public Date getStartdate() {
130
		return startdate;
131
	}
132

    
133
	public void setStartdate(final Date startdate) {
134
		this.startdate = startdate;
135
	}
136

    
137
	public Date getEnddate() {
138
		return enddate;
139
	}
140

    
141
	public void setEnddate(final Date enddate) {
142
		this.enddate = enddate;
143
	}
144

    
145
	public String getFundingpathid() {
146
		return fundingpathid;
147
	}
148

    
149
	public void setFundingpathid(final String fundingpathid) {
150
		this.fundingpathid = fundingpathid;
151
	}
152
}
(2-2/4)