Revision 60657
Added by Michele Artini about 3 years ago
modules/dnet-isti/trunk/src/main/java/eu/dnetlib/msro/workflows/nodes/PimpaUpdateJobNode.java | ||
---|---|---|
13 | 13 |
import eu.dnetlib.clients.pimpa.PimpaStubFactory; |
14 | 14 |
import eu.dnetlib.data.db.AffiliationsDao; |
15 | 15 |
import eu.dnetlib.data.utils.IstiConstants; |
16 |
import eu.dnetlib.data.utils.XsltFunctions; |
|
17 | 16 |
import eu.dnetlib.msro.workflows.graph.Arc; |
18 | 17 |
import eu.dnetlib.msro.workflows.procs.Env; |
18 |
import eu.dnetlib.rmi.manager.MSROException; |
|
19 | 19 |
|
20 |
@Deprecated |
|
20 | 21 |
public class PimpaUpdateJobNode extends SimpleJobNode { |
21 | 22 |
|
22 | 23 |
@Autowired |
... | ... | |
33 | 34 |
|
34 | 35 |
@Override |
35 | 36 |
protected String execute(final Env env) throws Exception { |
37 |
throw new MSROException("THIS NODE IS DEPRECATED"); |
|
38 |
// return _execute(env); |
|
39 |
} |
|
40 |
|
|
41 |
private String _execute(final Env env) throws Exception { |
|
36 | 42 |
log.info("Reimport records from PIMPA - START"); |
37 | 43 |
|
38 | 44 |
final Map<String, Boolean> oldPids = dao.getPersonIds().stream().collect(Collectors.toMap(s -> s, s -> true)); |
... | ... | |
52 | 58 |
final String pid = "matricola:" + p.getCode().trim(); |
53 | 59 |
|
54 | 60 |
if (!oldPids.containsKey(pid)) { |
55 |
dao.registerPerson(pid, String.format("%s %s", p.getName().trim(), p.getSurname().trim()));
|
|
61 |
dao.registerPerson(pid, p.getName().trim(), p.getSurname().trim());
|
|
56 | 62 |
oldPids.put(pid, false); |
57 | 63 |
} else if (overridePersons && oldPids.get(pid)) { |
58 | 64 |
log.info("Overriding person " + pid); |
59 |
dao.updatePerson(pid, String.format("%s %s", p.getName().trim(), p.getSurname().trim()));
|
|
65 |
dao.updatePerson(pid, p.getName().trim(), p.getSurname().trim());
|
|
60 | 66 |
oldPids.put(pid, false); |
61 | 67 |
} |
62 | 68 |
p.getLabs().getList().forEach(lab -> { |
... | ... | |
77 | 83 |
}); |
78 | 84 |
|
79 | 85 |
if (capitalizeFullnames) { |
80 |
log.info("Capitalizing person fullnames"); |
|
81 |
dao.listPersons().forEach(p -> { |
|
82 |
dao.updatePerson(p.getId(), XsltFunctions.capitalize(p.getName())); |
|
83 |
});; |
|
86 |
log.info("Capitalizing person fullnames - DEPRECATED - NOT PERFROMED"); |
|
87 |
// dao.listPersons().forEach(p -> { dao.updatePerson(p.getId(), XsltFunctions.capitalize(p.getName())); });; |
|
84 | 88 |
} |
85 | 89 |
|
86 | 90 |
log.info("Reimport records from PIMPA - END"); |
modules/dnet-isti/trunk/src/main/java/eu/dnetlib/data/utils/XsltFunctions.java | ||
---|---|---|
81 | 81 |
public static String calculatePersonName(final String s) { |
82 | 82 |
final Pattern pattern = Pattern.compile("info:cnr-pdr\\/author\\/(.+):(.+)\\/(.+)\\/(.+)"); |
83 | 83 |
final Matcher matcher = pattern.matcher(s); |
84 |
return matcher.find() ? capitalize(String.format("%s %s", matcher.group(4), matcher.group(3))) : "";
|
|
84 |
return matcher.find() ? capitalize(String.format("%s, %s", matcher.group(3), matcher.group(4))) : "";
|
|
85 | 85 |
} |
86 | 86 |
|
87 | 87 |
public static String serverName(final String s) { |
modules/dnet-isti/trunk/src/main/java/eu/dnetlib/data/db/Person.java | ||
---|---|---|
7 | 7 |
public class Person { |
8 | 8 |
|
9 | 9 |
private String id; |
10 |
private String name; |
|
10 |
private String fullname;
|
|
11 | 11 |
private SortedMap<Integer, Set<Group>> affiliations = new TreeMap<>(); |
12 | 12 |
|
13 | 13 |
public Person() {} |
14 | 14 |
|
15 |
public Person(final String id, final String name) { |
|
15 |
public Person(final String id, final String fullname) {
|
|
16 | 16 |
this.id = id; |
17 |
this.name = name;
|
|
17 |
this.fullname = fullname;
|
|
18 | 18 |
} |
19 | 19 |
|
20 | 20 |
public String getId() { |
... | ... | |
25 | 25 |
this.id = id; |
26 | 26 |
} |
27 | 27 |
|
28 |
public String getName() {
|
|
29 |
return name; |
|
28 |
public String getFullname() {
|
|
29 |
return fullname;
|
|
30 | 30 |
} |
31 | 31 |
|
32 |
public void setName(final String name) {
|
|
33 |
this.name = name;
|
|
32 |
protected void setFullname(final String fullname) {
|
|
33 |
this.fullname = fullname;
|
|
34 | 34 |
} |
35 | 35 |
|
36 | 36 |
public SortedMap<Integer, Set<Group>> getAffiliations() { |
... | ... | |
43 | 43 |
|
44 | 44 |
@Override |
45 | 45 |
public String toString() { |
46 |
return "Person [id=" + id + ", name=" + name + ", affiliations=" + affiliations + "]";
|
|
46 |
return "Person [id=" + id + ", fullname=" + fullname + ", affiliations=" + affiliations + "]";
|
|
47 | 47 |
} |
48 | 48 |
|
49 | 49 |
} |
modules/dnet-isti/trunk/src/main/java/eu/dnetlib/data/db/AffiliationsDao.java | ||
---|---|---|
31 | 31 |
final Integer year = (Integer) map.get("year"); |
32 | 32 |
final Group group = new Group((String) map.get("gid"), (String) map.get("gname"), (String) map.get("gtype")); |
33 | 33 |
|
34 |
temp.putIfAbsent(pid, new Person(pid, (String) map.get("pname"))); |
|
34 |
temp.putIfAbsent(pid, new Person(pid, (String) map.get("pfullname")));
|
|
35 | 35 |
|
36 | 36 |
if (year != null) { |
37 | 37 |
temp.get(pid).getAffiliations().putIfAbsent(year, new TreeSet<>((g1, g2) -> { |
... | ... | |
45 | 45 |
|
46 | 46 |
return temp.values() |
47 | 47 |
.stream() |
48 |
.sorted((p1, p2) -> p1.getName().compareTo(p2.getName()))
|
|
48 |
.sorted((p1, p2) -> p1.getFullname().compareTo(p2.getFullname()))
|
|
49 | 49 |
.collect(Collectors.toList()); |
50 | 50 |
|
51 | 51 |
} |
... | ... | |
62 | 62 |
} |
63 | 63 |
} |
64 | 64 |
|
65 |
public List<Person> listPersons() { |
|
66 |
return jdbcTemplate.query("select * from persons", (RowMapper<Person>) (rs, rowNum) -> { |
|
67 |
return new Person(rs.getString("id"), rs.getString("fullname")); |
|
68 |
}); |
|
69 |
} |
|
70 |
|
|
71 | 65 |
public List<Group> listGroups() { |
72 | 66 |
return jdbcTemplate.query("select * from groups where id != 'UNKNOWN'", (RowMapper<Group>) (rs, rowNum) -> { |
73 | 67 |
return new Group(rs.getString("id"), rs.getString("name"), rs.getString("type")); |
... | ... | |
82 | 76 |
return new HashSet<>(jdbcTemplate.query("select id from groups", (RowMapper<String>) (rs, rowNum) -> rs.getString("id"))); |
83 | 77 |
} |
84 | 78 |
|
85 |
public void updatePerson(final String code, final String name) { |
|
86 |
jdbcTemplate.update("UPDATE persons SET fullname = ? WHERE id = ?", name, code); |
|
87 |
|
|
79 |
public void updatePerson(final String code, final String name, final String surname) { |
|
80 |
jdbcTemplate.update("UPDATE persons SET name=?, surname=? WHERE id=?", name, surname, code); |
|
88 | 81 |
} |
89 | 82 |
|
90 |
public void registerPerson(final String code, final String name) { |
|
91 |
jdbcTemplate.update("INSERT into persons(id, fullname) VALUES (?, ?)", code, name);
|
|
83 |
public void registerPerson(final String code, final String name, final String surname) {
|
|
84 |
jdbcTemplate.update("INSERT into persons(id, name, surname) VALUES (?, ?, ?)", code, name, surname);
|
|
92 | 85 |
} |
93 | 86 |
|
94 | 87 |
public void updateGroup(final String id, final String name, final String type) { |
95 |
jdbcTemplate.update("UPDATE groups SET (name, type) = (?, ?) WHERE id = ?", name, type, id);
|
|
88 |
jdbcTemplate.update("UPDATE groups SET name=?, type=? WHERE id=?", name, type, id);
|
|
96 | 89 |
} |
97 | 90 |
|
98 | 91 |
public void registerGroup(final String id, final String name, final String type) { |
modules/dnet-isti/trunk/src/main/java/eu/dnetlib/data/db/ui/AffiliationsAjaxController.java | ||
---|---|---|
9 | 9 |
import org.springframework.web.bind.annotation.RequestBody; |
10 | 10 |
import org.springframework.web.bind.annotation.RequestMapping; |
11 | 11 |
import org.springframework.web.bind.annotation.RequestMethod; |
12 |
import org.springframework.web.bind.annotation.RestController; |
|
13 | 12 |
|
14 | 13 |
import eu.dnetlib.data.db.Affiliation; |
15 | 14 |
import eu.dnetlib.data.db.AffiliationsDao; |
16 | 15 |
import eu.dnetlib.data.db.Group; |
17 | 16 |
import eu.dnetlib.data.db.Person; |
18 | 17 |
|
19 |
@RestController |
|
18 |
// @RestController |
|
19 |
@Deprecated |
|
20 | 20 |
public class AffiliationsAjaxController { |
21 | 21 |
|
22 | 22 |
@Autowired |
... | ... | |
24 | 24 |
|
25 | 25 |
@RequestMapping(value = "/ui/portal/aff_view", method = RequestMethod.GET) |
26 | 26 |
public Map<String, List<Person>> persons() { |
27 |
return dao.listPersonsWithAffiliations().stream().collect(Collectors.groupingBy(Person::getName, TreeMap::new, Collectors.toList()));
|
|
27 |
return dao.listPersonsWithAffiliations().stream().collect(Collectors.groupingBy(Person::getFullname, TreeMap::new, Collectors.toList()));
|
|
28 | 28 |
} |
29 | 29 |
|
30 | 30 |
@RequestMapping(value = "/ui/portal/groups", method = RequestMethod.GET) |
modules/dnet-isti/trunk/src/main/java/eu/dnetlib/data/db/ui/AffiliationsEntryPointController.java | ||
---|---|---|
7 | 7 |
|
8 | 8 |
import eu.dnetlib.functionality.modular.ui.ModuleEntryPoint; |
9 | 9 |
|
10 |
@Deprecated |
|
10 | 11 |
public class AffiliationsEntryPointController extends ModuleEntryPoint { |
11 | 12 |
|
12 | 13 |
@Override |
modules/dnet-isti/trunk/src/main/java/eu/dnetlib/data/mdstore/plugins/EnrichLabsPlugin.java | ||
---|---|---|
35 | 35 |
|
36 | 36 |
@Override |
37 | 37 |
protected void reconfigure(final Map<String, String> params) { |
38 |
affiliations = dao.listPersonsWithAffiliations() |
|
39 |
.stream() |
|
40 |
.collect(Collectors.toMap(Person::getId, a -> a)); |
|
38 |
affiliations = dao.listPersonsWithAffiliations().stream().collect(Collectors.toMap(Person::getId, a -> a)); |
|
41 | 39 |
} |
42 | 40 |
|
43 | 41 |
@Override |
... | ... | |
58 | 56 |
final Matcher matcher = pattern.matcher(infoId); |
59 | 57 |
if (matcher.find()) { |
60 | 58 |
final String code = matcher.group(1); |
61 |
final String fullname = XsltFunctions.capitalize(String.format("%s %s", matcher.group(3), matcher.group(2))); |
|
59 |
final String surname = matcher.group(2); |
|
60 |
final String name = matcher.group(3); |
|
62 | 61 |
|
63 | 62 |
final Person p = affiliations.get(code); |
64 | 63 |
|
65 | 64 |
if (p != null) { |
66 | 65 |
final Set<Group> groups = p.getAffiliations().get(year); |
67 | 66 |
if (groups != null) { |
68 |
cp.setName(p.getName());
|
|
67 |
cp.setName(p.getFullname());
|
|
69 | 68 |
for (final Group g : groups) { |
70 | 69 |
if (!g.getId().equals(UNKNOWN_GROUP.getId())) { |
71 |
cp.getAffiliations().add(new Affiliation(code, g.getType(), g.getId(), g.getName())); |
|
70 |
cp.getAffiliations().add(new Affiliation(code, |
|
71 |
g.getType(), g.getId(), g.getName())); |
|
72 | 72 |
} |
73 | 73 |
} |
74 | 74 |
} else { |
75 |
log.info("Affiliation not found, infoId: " + infoId + ", year: " + year); |
|
75 |
log.info("Affiliation not found, infoId: " + |
|
76 |
infoId + ", year: " + year); |
|
76 | 77 |
dao.registerAffiliation(code, UNKNOWN_GROUP.getId(), year); |
77 | 78 |
p.getAffiliations().put(year, Sets.newHashSet(UNKNOWN_GROUP)); |
78 | 79 |
} |
80 |
|
|
79 | 81 |
} else { |
80 | 82 |
log.info("Person not found, infoId: " + infoId + ", year: " + year); |
81 |
dao.registerPerson(code, fullname);
|
|
83 |
dao.registerPerson(code, XsltFunctions.capitalize(name), XsltFunctions.capitalize((surname)));
|
|
82 | 84 |
dao.registerAffiliation(code, UNKNOWN_GROUP.getId(), year); |
83 | 85 |
|
84 |
final Person np = new Person(code, fullname);
|
|
86 |
final Person np = new Person(code, String.format("%s, %s", surname, name));
|
|
85 | 87 |
np.getAffiliations().put(year, Sets.newHashSet(UNKNOWN_GROUP)); |
86 | 88 |
|
87 | 89 |
affiliations.put(code, np); |
modules/dnet-isti/trunk/src/main/resources/eu/dnetlib/isti/sql/create_affiliations_tables.sql | ||
---|---|---|
1 | 1 |
CREATE TABLE persons ( |
2 | 2 |
id varchar(32) PRIMARY KEY, |
3 |
fullname varchar(256) NOT NULL |
|
3 |
name varchar(256) NOT NULL, |
|
4 |
surname varchar(256) NOT NULL, |
|
5 |
suffix varchar(256) |
|
4 | 6 |
); |
5 | 7 |
|
6 | 8 |
CREATE TABLE groups ( |
... | ... | |
18 | 20 |
|
19 | 21 |
INSERT INTO groups(id, name, type) VALUES ('UNKNOWN', 'UNKNOWN', 'UNKNOWN'); |
20 | 22 |
|
21 |
CREATE VIEW affiliations_view AS SELECT |
|
22 |
p.id as pid, |
|
23 |
p.fullname as pname, |
|
24 |
g.id as gid, |
|
25 |
g.name as gname, |
|
26 |
g.type as gtype, |
|
27 |
a.year as year |
|
23 |
CREATE VIEW affiliations_view AS SELECT |
|
24 |
p.id as pid, |
|
25 |
TRIM(CONCAT(p.surname, ", ", p.name, " ", COALESCE(p.suffix, ''))) as pfullname, |
|
26 |
p.fullname as pname, //TODO DA TOGLIERE |
|
27 |
g.id as gid, |
|
28 |
g.name as gname, |
|
29 |
g.type as gtype, |
|
30 |
a.year as year |
|
28 | 31 |
FROM |
29 | 32 |
persons p |
30 | 33 |
LEFT OUTER JOIN affiliations a ON (p.id = a.pid) |
modules/dnet-isti/trunk/src/main/resources/eu/dnetlib/isti/webContext-modular-ui-isti.xml | ||
---|---|---|
4 | 4 |
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p" |
5 | 5 |
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd"> |
6 | 6 |
|
7 |
<bean name="/ui/affiliations.do" |
|
7 |
<!-- <bean name="/ui/affiliations.do"
|
|
8 | 8 |
class="eu.dnetlib.data.db.ui.AffiliationsEntryPointController" |
9 | 9 |
p:menu="Affiliations Database" |
10 | 10 |
p:title="Affiliations Database" |
... | ... | |
16 | 16 |
</set> |
17 | 17 |
</property> |
18 | 18 |
</bean> |
19 |
|
|
19 |
--> |
|
20 | 20 |
</beans> |
Also available in: Unified diff
author format: surname, name