Revision 36089
Added by Antonis Lempesis about 9 years ago
modules/uoa-goldoa-service/trunk/src/main/java/eu/dnetlib/goldoa/service/PersonManager.java | ||
---|---|---|
42 | 42 |
public void rejectRole(String userId, String roleId); |
43 | 43 |
|
44 | 44 |
public List<Person> getUsers(); |
45 |
|
|
46 |
String generateId(Person person); |
|
45 | 47 |
} |
modules/uoa-goldoa-service/trunk/src/main/java/eu/dnetlib/goldoa/service/PersonManagerImpl.java | ||
---|---|---|
38 | 38 |
|
39 | 39 |
private int tokenTTL = 30; |
40 | 40 |
|
41 |
public static int generateId(Affiliation affiliation) { |
|
42 |
StringBuilder sb = new StringBuilder(); |
|
43 |
|
|
44 |
if (affiliation.getPerson()!= null) |
|
45 |
sb.append(affiliation.getPerson().getId()); |
|
46 |
if (affiliation.getOrganization() != null) |
|
47 |
sb.append(affiliation.getOrganization().getId()); |
|
48 |
|
|
49 |
return DigestUtils.md5Hex(sb.toString()).hashCode(); |
|
50 |
} |
|
51 |
|
|
41 | 52 |
@Override |
42 | 53 |
public Person getById(String personId) throws PersonManagerException { |
43 | 54 |
try { |
... | ... | |
68 | 79 |
public Person savePerson(final Person person) throws PersonManagerException { |
69 | 80 |
|
70 | 81 |
if (person.getId() == null) { |
71 |
StringBuilder sb = new StringBuilder(); |
|
72 |
|
|
73 |
sb.append(person.getName()).append(person.getLastname()).append(person.getEmail()); |
|
74 |
person.setId("portal::" + DigestUtils.md5Hex(sb.toString())); |
|
82 |
person.setId(generateId(person)); |
|
75 | 83 |
person.setSource("portal"); |
76 | 84 |
} |
77 | 85 |
|
... | ... | |
201 | 209 |
return persons; |
202 | 210 |
} |
203 | 211 |
|
212 |
@Override |
|
213 |
public String generateId(Person person) { |
|
214 |
StringBuilder sb = new StringBuilder(); |
|
215 |
|
|
216 |
sb.append(person.getName()).append(person.getLastname()).append(person.getEmail()); |
|
217 |
return "portal::" + DigestUtils.md5Hex(sb.toString()); |
|
218 |
} |
|
219 |
|
|
204 | 220 |
private void deletePersonRelations(final Person person) { |
205 | 221 |
personDAO.deleteAffiliations(person.getId()); |
206 | 222 |
personDAO.deletePersonRoles(person.getId()); |
modules/uoa-goldoa-service/trunk/src/main/java/eu/dnetlib/goldoa/service/dao/PersonDAO.java | ||
---|---|---|
1 | 1 |
package eu.dnetlib.goldoa.service.dao; |
2 | 2 |
|
3 | 3 |
import eu.dnetlib.goldoa.domain.*; |
4 |
import eu.dnetlib.goldoa.service.PersonManagerImpl; |
|
4 | 5 |
import org.springframework.beans.factory.annotation.Autowired; |
5 | 6 |
import org.springframework.jdbc.core.BatchPreparedStatementSetter; |
6 | 7 |
import org.springframework.jdbc.core.JdbcTemplate; |
... | ... | |
68 | 69 |
|
69 | 70 |
private static final String INSERT_PERSON_ROLE = "insert into person_role (person, role, approved) values (?, ? ,?)"; |
70 | 71 |
|
71 |
private static final String INSERT_AFFILIATION = "insert into affiliation (person, organization, startdate, enddate, department) values (?, ?, ?, ?, ?)";
|
|
72 |
private static final String INSERT_AFFILIATION = "insert into affiliation (id, person, organization, startdate, enddate, department) values (?, ?, ?, ?, ?, ?)";
|
|
72 | 73 |
|
73 | 74 |
private static final String INSERT_ACTIVATION_TOKEN = "insert into account_action (\"user\", type, token, date, expires) values (?, ?, ? , ?, ?)"; |
74 | 75 |
|
... | ... | |
293 | 294 |
public void setValues(PreparedStatement ps, int i) throws SQLException { |
294 | 295 |
Affiliation affiliation = affiliations.get(i); |
295 | 296 |
|
296 |
ps.setString(1, person.getId()); |
|
297 |
ps.setInt(1, PersonManagerImpl.generateId(affiliation)); |
|
298 |
ps.setString(2, person.getId()); |
|
297 | 299 |
|
298 | 300 |
if (affiliation.getOrganization() != null) |
299 |
ps.setString(2, affiliation.getOrganization().getId());
|
|
301 |
ps.setString(3, affiliation.getOrganization().getId());
|
|
300 | 302 |
else |
301 |
ps.setString(2, null);
|
|
303 |
ps.setString(3, null);
|
|
302 | 304 |
|
303 | 305 |
if (affiliation.getStart() != null) |
304 |
ps.setTimestamp(3, new Timestamp(affiliation.getStart().getTime()));
|
|
306 |
ps.setTimestamp(4, new Timestamp(affiliation.getStart().getTime()));
|
|
305 | 307 |
else |
306 |
ps.setTimestamp(3, null);
|
|
308 |
ps.setTimestamp(4, null);
|
|
307 | 309 |
|
308 | 310 |
if (affiliation.getEnd() != null) |
309 |
ps.setTimestamp(4, new Timestamp(affiliation.getEnd().getTime()));
|
|
311 |
ps.setTimestamp(5, new Timestamp(affiliation.getEnd().getTime()));
|
|
310 | 312 |
else |
311 |
ps.setTimestamp(4, null);
|
|
313 |
ps.setTimestamp(5, null);
|
|
312 | 314 |
|
313 |
ps.setString(5, affiliation.getDepartment());
|
|
315 |
ps.setString(6, affiliation.getDepartment());
|
|
314 | 316 |
} |
315 | 317 |
|
316 | 318 |
@Override |
modules/uoa-goldoa-service/trunk/src/main/java/eu/dnetlib/goldoa/service/dao/PublicationDAO.java | ||
---|---|---|
1 | 1 |
package eu.dnetlib.goldoa.service.dao; |
2 | 2 |
|
3 | 3 |
import eu.dnetlib.goldoa.domain.*; |
4 |
import eu.dnetlib.goldoa.service.PersonManagerImpl; |
|
4 | 5 |
import org.springframework.beans.factory.annotation.Autowired; |
5 | 6 |
import org.springframework.jdbc.core.BatchPreparedStatementSetter; |
6 | 7 |
import org.springframework.jdbc.core.JdbcTemplate; |
... | ... | |
29 | 30 |
"group by p.id, title, languages, subjects, doi, source, date, p.type, journal, publisher, repository, acceptancedate;"; |
30 | 31 |
|
31 | 32 |
private static final String INSERT_PUBLICATION_AFFILIATIONS = |
32 |
"with aff as (insert into affiliation (person, organization, startdate, enddate, department) values (?, ?, ?, ?, ?) returning id as affid) insert into publication_affiliation (publication, affiliation) select ?, affid from aff";
|
|
33 |
"with aff as (insert into affiliation (id, person, organization, startdate, enddate, department) values (?, ?, ?, ?, ?, ?) returning id as affid) insert into publication_affiliation (publication, affiliation) select ?, affid from aff";
|
|
33 | 34 |
|
34 | 35 |
private static final String UPDATE_PUBLICATION_AFFILIATIONS = |
35 | 36 |
"with aff as (select id from affiliation where person=? and organization=?) insert into publication_affiliation (publication, affiliation) select ?, aff.id from aff"; |
... | ... | |
124 | 125 |
for (Affiliation affiliation:publication.getAuthors()) { |
125 | 126 |
if (jdbcTemplate.update(UPDATE_PUBLICATION_AFFILIATIONS, new String[] {affiliation.getPerson().getId(), affiliation.getOrganization() != null? affiliation.getOrganization().getId(): null, publication.getId()}, new int[] {Types.VARCHAR, Types.VARCHAR, Types.VARCHAR}) == 0) { |
126 | 127 |
jdbcTemplate.update(INSERT_PUBLICATION_AFFILIATIONS, |
127 |
new Object[] {affiliation.getPerson().getId(), affiliation.getOrganization() != null?affiliation.getOrganization().getId():null, affiliation.getStart(), affiliation.getEnd(), affiliation.getDepartment(), publication.getId()}, |
|
128 |
new int[] {Types.VARCHAR, Types.VARCHAR, Types.TIMESTAMP, Types.TIMESTAMP, Types.VARCHAR, Types.VARCHAR}); |
|
128 |
new Object[] {PersonManagerImpl.generateId(affiliation), affiliation.getPerson().getId(), affiliation.getOrganization() != null?affiliation.getOrganization().getId():null, affiliation.getStart(), affiliation.getEnd(), affiliation.getDepartment(), publication.getId()},
|
|
129 |
new int[] {Types.INTEGER, Types.VARCHAR, Types.VARCHAR, Types.TIMESTAMP, Types.TIMESTAMP, Types.VARCHAR, Types.VARCHAR});
|
|
129 | 130 |
} |
130 | 131 |
} |
131 | 132 |
} |
modules/uoa-goldoa-service/trunk/src/main/java/eu/dnetlib/goldoa/service/PublicationManagerImpl.java | ||
---|---|---|
4 | 4 |
import com.fasterxml.jackson.databind.ObjectMapper; |
5 | 5 |
import eu.dnetlib.goldoa.domain.*; |
6 | 6 |
import eu.dnetlib.goldoa.service.dao.JournalDAO; |
7 |
import eu.dnetlib.goldoa.service.dao.PersonDAO; |
|
8 | 7 |
import eu.dnetlib.goldoa.service.dao.PublicationDAO; |
9 | 8 |
import eu.dnetlib.goldoa.service.dao.PublisherDAO; |
10 | 9 |
import org.apache.commons.codec.digest.DigestUtils; |
... | ... | |
94 | 93 |
|
95 | 94 |
if (publication.getAuthors() != null) |
96 | 95 |
for (Affiliation aff:publication.getAuthors()) { |
97 |
if (aff.getPerson() != null) |
|
98 |
personManager.savePerson(aff.getPerson()); |
|
99 |
if (aff.getOrganization() != null) |
|
100 |
organizationManager.saveOrganization(aff.getOrganization()); |
|
96 |
if (aff.getOrganization() != null && aff.getOrganization().getId() == null) |
|
97 |
aff.getOrganization().setId(organizationManager.saveOrganization(aff.getOrganization())); |
|
98 |
|
|
99 |
if (aff.getPerson() != null) { |
|
100 |
String personId = personManager.generateId(aff.getPerson()); |
|
101 |
|
|
102 |
try { |
|
103 |
boolean affiliationExists = false; |
|
104 |
Person temp = personManager.getById(personId); |
|
105 |
|
|
106 |
for (Affiliation a:temp.getAffiliations()) { |
|
107 |
if (a.getOrganization() != null && aff.getOrganization() != null && a.getOrganization().getId().equals(aff.getOrganization().getId())) |
|
108 |
affiliationExists = true; |
|
109 |
} |
|
110 |
|
|
111 |
if (!affiliationExists) { |
|
112 |
temp.getAffiliations().add(aff); |
|
113 |
|
|
114 |
personManager.savePerson(temp); |
|
115 |
} |
|
116 |
|
|
117 |
aff.setPerson(temp); |
|
118 |
} catch (PersonManagerException e) { |
|
119 |
if (e.getErrorCause() == PersonManagerException.ErrorCause.NOT_EXISTS) |
|
120 |
personManager.savePerson(aff.getPerson()); |
|
121 |
} |
|
122 |
} |
|
101 | 123 |
} |
102 | 124 |
|
103 | 125 |
publicationDAO.saveAffiliations(publication); |
modules/uoa-goldoa-service/trunk/src/main/java/eu/dnetlib/goldoa/domain/Affiliation.java | ||
---|---|---|
1 | 1 |
package eu.dnetlib.goldoa.domain; |
2 | 2 |
|
3 |
import org.apache.commons.codec.digest.DigestUtils; |
|
4 |
|
|
3 | 5 |
import java.io.Serializable; |
4 | 6 |
import java.util.Date; |
5 | 7 |
|
... | ... | |
77 | 79 |
public void setDepartment(String department) { |
78 | 80 |
this.department = department; |
79 | 81 |
} |
82 |
|
|
80 | 83 |
} |
Also available in: Unified diff
Affiliation id is no longer a sequence. Publication affiliations are now saved correctly