Revision 39076
Added by Antonis Lempesis over 8 years ago
ProjectDAO.java | ||
---|---|---|
7 | 7 |
import org.springframework.beans.factory.annotation.Autowired; |
8 | 8 |
import org.springframework.jdbc.core.JdbcTemplate; |
9 | 9 |
import org.springframework.jdbc.core.RowMapper; |
10 |
import org.springframework.transaction.annotation.Propagation; |
|
11 |
import org.springframework.transaction.annotation.Transactional; |
|
12 | 10 |
|
13 | 11 |
import javax.sql.DataSource; |
14 | 12 |
import java.sql.ResultSet; |
... | ... | |
22 | 20 |
*/ |
23 | 21 |
public class ProjectDAO { |
24 | 22 |
|
25 |
@Autowired
|
|
23 |
@Autowired
|
|
26 | 24 |
private DataSource dataSource; |
27 | 25 |
|
28 |
private long expirationOk;
|
|
26 |
private long expirationOk;
|
|
29 | 27 |
|
30 |
private final String SEARCH_PROJECTS = "select id, acronym, title, \"grant\" from project where lower(acronym) like lower(?) or lower(title) like lower(?) or lower(\"grant\") like lower(?)";
|
|
28 |
private final String SEARCH_PROJECTS = "select id, acronym, title, \"grant\" from project where lower(acronym) like lower(?) or lower(title) like lower(?) or lower(\"grant\") like lower(?)";
|
|
31 | 29 |
private final String GET_PROJECT = |
32 | 30 |
"select id, acronym, title, funder, fundingstream, scientificarea, call, \"grant\", startdate, enddate, sc39, url, source, array_agg(distinct pc.coordinator) as coordinators, array_agg(distinct po.organization) as organizations\n" + |
33 | 31 |
"from project p\n" + |
34 | 32 |
"left join project_organization po on po.project=p.id\n" + |
35 |
"left join project_coordinator pc on pc.project=p.id\n" +
|
|
33 |
"left join project_coordinator pc on pc.project=p.id\n" +
|
|
36 | 34 |
"where p.id=?\n" + |
37 | 35 |
"group by id, acronym, title, funder, fundingstream, scientificarea, call, \"grant\", startdate, enddate, sc39, url, source"; |
38 |
private final String GET_PROJECTS_FOR_ORGANIZATION =
|
|
39 |
"select id, acronym, title, funder, fundingstream, scientificarea, call, \"grant\", startdate, enddate, sc39, url, source, array_agg(distinct pc.coordinator) as coordinators, array_agg(distinct po.organization) as organizations\n" +
|
|
40 |
"from project p\n" +
|
|
41 |
"left join project_organization po on po.project=p.id\n" +
|
|
42 |
"left join project_coordinator pc on pc.project=p.id\n" +
|
|
43 |
"where po.organization=? and p.enddate > now() - (? || ' months')::interval and p.enddate < now() \n" +
|
|
44 |
"group by id, acronym, title, funder, fundingstream, scientificarea, call, \"grant\", startdate, enddate, sc39, url, source";
|
|
45 |
private final String GET_FUTURE_PROJECTS_FOR_ORGANIZATION=
|
|
46 |
"select id, acronym, title, funder, fundingstream, scientificarea, call, \"grant\", startdate, enddate, sc39, url, source, array_agg(distinct pc.coordinator) as coordinators, array_agg(distinct po.organization) as organizations\n" +
|
|
47 |
"from project p\n" +
|
|
48 |
"left join project_organization po on po.project=p.id\n" +
|
|
49 |
"left join project_coordinator pc on pc.project=p.id\n" +
|
|
50 |
"where po.organization=? and p.enddate > now() \n" +
|
|
51 |
"group by id, acronym, title, funder, fundingstream, scientificarea, call, \"grant\", startdate, enddate, sc39, url, source";
|
|
36 |
private final String GET_PROJECTS_FOR_ORGANIZATION =
|
|
37 |
"select id, acronym, title, funder, fundingstream, scientificarea, call, \"grant\", startdate, enddate, sc39, url, source, array_agg(distinct pc.coordinator) as coordinators, array_agg(distinct po.organization) as organizations\n" +
|
|
38 |
"from project p\n" +
|
|
39 |
"left join project_organization po on po.project=p.id\n" +
|
|
40 |
"left join project_coordinator pc on pc.project=p.id\n" +
|
|
41 |
"where po.organization=? and p.enddate > now() - (? || ' months')::interval and p.enddate < now() \n" +
|
|
42 |
"group by id, acronym, title, funder, fundingstream, scientificarea, call, \"grant\", startdate, enddate, sc39, url, source";
|
|
43 |
private final String GET_FUTURE_PROJECTS_FOR_ORGANIZATION =
|
|
44 |
"select id, acronym, title, funder, fundingstream, scientificarea, call, \"grant\", startdate, enddate, sc39, url, source, array_agg(distinct pc.coordinator) as coordinators, array_agg(distinct po.organization) as organizations\n" +
|
|
45 |
"from project p\n" +
|
|
46 |
"left join project_organization po on po.project=p.id\n" +
|
|
47 |
"left join project_coordinator pc on pc.project=p.id\n" +
|
|
48 |
"where po.organization=? and p.enddate > now() \n" +
|
|
49 |
"group by id, acronym, title, funder, fundingstream, scientificarea, call, \"grant\", startdate, enddate, sc39, url, source";
|
|
52 | 50 |
|
53 |
private RowMapper<Project> rowMapper = new RowMapper<Project>() {
|
|
54 |
@Override
|
|
55 |
public Project mapRow(ResultSet rs, int rowNum) throws SQLException {
|
|
56 |
Project project = new Project();
|
|
51 |
private RowMapper<Project> rowMapper = new RowMapper<Project>() {
|
|
52 |
@Override
|
|
53 |
public Project mapRow(ResultSet rs, int rowNum) throws SQLException {
|
|
54 |
Project project = new Project();
|
|
57 | 55 |
|
58 |
project.setId(rs.getString("id"));
|
|
59 |
project.setTitle(rs.getString("title"));
|
|
60 |
project.setAcronym(rs.getString("acronym"));
|
|
61 |
project.setFunder(rs.getString("funder"));
|
|
62 |
project.setFundingString(rs.getString("fundingstream"));
|
|
63 |
project.setScientificArea(rs.getString("scientificarea"));
|
|
64 |
project.setCall(rs.getString("call"));
|
|
65 |
project.setGrant(rs.getString("grant"));
|
|
66 |
project.setStartDate(rs.getTimestamp("startdate"));
|
|
67 |
project.setEndDate(rs.getTimestamp("enddate"));
|
|
68 |
project.setSc39(rs.getBoolean("sc39"));
|
|
69 |
project.setUrl(rs.getString("url"));
|
|
56 |
project.setId(rs.getString("id"));
|
|
57 |
project.setTitle(rs.getString("title"));
|
|
58 |
project.setAcronym(rs.getString("acronym"));
|
|
59 |
project.setFunder(rs.getString("funder"));
|
|
60 |
project.setFundingString(rs.getString("fundingstream"));
|
|
61 |
project.setScientificArea(rs.getString("scientificarea"));
|
|
62 |
project.setCall(rs.getString("call"));
|
|
63 |
project.setGrant(rs.getString("grant"));
|
|
64 |
project.setStartDate(rs.getTimestamp("startdate"));
|
|
65 |
project.setEndDate(rs.getTimestamp("enddate"));
|
|
66 |
project.setSc39(rs.getBoolean("sc39"));
|
|
67 |
project.setUrl(rs.getString("url"));
|
|
70 | 68 |
|
71 | 69 |
|
72 |
project.setCoordinators(new ArrayList<Person>());
|
|
73 |
for (String coordinatorId : (String[]) rs.getArray("coordinators").getArray())
|
|
74 |
project.getCoordinators().add(new Person(coordinatorId));
|
|
70 |
project.setCoordinators(new ArrayList<Person>());
|
|
71 |
for (String coordinatorId : (String[]) rs.getArray("coordinators").getArray())
|
|
72 |
project.getCoordinators().add(new Person(coordinatorId));
|
|
75 | 73 |
|
76 |
project.setOrganizations(new ArrayList<Organization>());
|
|
77 |
for (String organizationId : (String[]) rs.getArray("organizations").getArray())
|
|
78 |
project.getOrganizations().add(new Organization(organizationId));
|
|
74 |
project.setOrganizations(new ArrayList<Organization>());
|
|
75 |
for (String organizationId : (String[]) rs.getArray("organizations").getArray())
|
|
76 |
project.getOrganizations().add(new Organization(organizationId));
|
|
79 | 77 |
|
80 |
return project;
|
|
81 |
}
|
|
82 |
};
|
|
78 |
return project;
|
|
79 |
}
|
|
80 |
};
|
|
83 | 81 |
|
84 | 82 |
public List<Project> getProjectsCoordinatedBy(String personId) { |
85 | 83 |
return new ArrayList<Project>(); |
... | ... | |
98 | 96 |
return new JdbcTemplate(dataSource).queryForObject(GET_PROJECT, new Object[]{projectId}, new int[]{Types.VARCHAR}, rowMapper); |
99 | 97 |
} |
100 | 98 |
|
101 |
public DataSource getDataSource() {
|
|
102 |
return dataSource;
|
|
103 |
}
|
|
99 |
public DataSource getDataSource() {
|
|
100 |
return dataSource;
|
|
101 |
}
|
|
104 | 102 |
|
105 |
public void setDataSource(DataSource dataSource) {
|
|
106 |
this.dataSource = dataSource;
|
|
107 |
}
|
|
103 |
public void setDataSource(DataSource dataSource) {
|
|
104 |
this.dataSource = dataSource;
|
|
105 |
}
|
|
108 | 106 |
|
109 |
public List<Project> getEligibleProjectsForOrganization(String organizationId) {
|
|
110 |
return new JdbcTemplate(dataSource).query(GET_PROJECTS_FOR_ORGANIZATION, new Object[] {organizationId, this.expirationOk}, new int[] {Types.VARCHAR, Types.INTEGER}, rowMapper);
|
|
111 |
}
|
|
107 |
public List<Project> getEligibleProjectsForOrganization(String organizationId) {
|
|
108 |
return new JdbcTemplate(dataSource).query(GET_PROJECTS_FOR_ORGANIZATION, new Object[]{organizationId, this.expirationOk}, new int[]{Types.VARCHAR, Types.INTEGER}, rowMapper);
|
|
109 |
}
|
|
112 | 110 |
|
113 |
public List<Project> getFutureEligibleProjectsForOrganization(String organizationId) {
|
|
114 |
return new JdbcTemplate(dataSource).query(GET_FUTURE_PROJECTS_FOR_ORGANIZATION, new String[] {organizationId}, new int[] {Types.VARCHAR}, rowMapper);
|
|
115 |
}
|
|
111 |
public List<Project> getFutureEligibleProjectsForOrganization(String organizationId) {
|
|
112 |
return new JdbcTemplate(dataSource).query(GET_FUTURE_PROJECTS_FOR_ORGANIZATION, new String[]{organizationId}, new int[]{Types.VARCHAR}, rowMapper);
|
|
113 |
}
|
|
116 | 114 |
|
117 |
public long getExpirationOk() {
|
|
118 |
return expirationOk;
|
|
119 |
}
|
|
115 |
public long getExpirationOk() {
|
|
116 |
return expirationOk;
|
|
117 |
}
|
|
120 | 118 |
|
121 |
public void setExpirationOk(long expirationOk) {
|
|
122 |
this.expirationOk = expirationOk;
|
|
123 |
}
|
|
119 |
public void setExpirationOk(long expirationOk) {
|
|
120 |
this.expirationOk = expirationOk;
|
|
121 |
}
|
|
124 | 122 |
} |
Also available in: Unified diff
reformatted code