Revision 50661
Added by Michele Artini over 5 years ago
modules/dnet-isti/trunk/src/main/java/eu/dnetlib/msro/workflows/nodes/ObtainISTIDataSourceParamsJobNode.java | ||
---|---|---|
1 |
package eu.dnetlib.msro.workflows.nodes; |
|
2 |
|
|
3 |
import javax.annotation.Resource; |
|
4 |
|
|
5 |
import eu.dnetlib.enabling.locators.UniqueServiceLocator; |
|
6 |
import eu.dnetlib.miscutils.datetime.DateUtils; |
|
7 |
import eu.dnetlib.msro.workflows.graph.Arc; |
|
8 |
import eu.dnetlib.msro.workflows.procs.Env; |
|
9 |
import eu.dnetlib.msro.workflows.util.WorkflowsConstants; |
|
10 |
import eu.dnetlib.rmi.enabling.ISLookUpService; |
|
11 |
|
|
12 |
/** |
|
13 |
* Created by sandro on 9/23/16. |
|
14 |
*/ |
|
15 |
public class ObtainISTIDataSourceParamsJobNode extends SimpleJobNode { |
|
16 |
|
|
17 |
private String providerId; |
|
18 |
|
|
19 |
@Resource |
|
20 |
private UniqueServiceLocator serviceLocator; |
|
21 |
|
|
22 |
@Override |
|
23 |
protected String execute(final Env env) throws Exception { |
|
24 |
final String query = "let $x := /*[.//RESOURCE_IDENTIFIER/@value='" + providerId + "']//EXTRA_FIELDS\n" |
|
25 |
+ "return concat($x/FIELD[./key='OpenAireDataSourceId']/value, ' @@@ ', $x/FIELD[./key='NamespacePrefix']/value)"; |
|
26 |
|
|
27 |
final String[] arr = serviceLocator.getService(ISLookUpService.class).getResourceProfileByQuery(query).split("@@@"); |
|
28 |
|
|
29 |
final String origId = arr[0].trim(); |
|
30 |
final String nsPrefix = arr[1].trim(); |
|
31 |
// this is needed by the mdbuilder |
|
32 |
// TODO: update mdbuilder to use the env attributes below, whose names are defined in WorkflowConstants |
|
33 |
env.setAttribute("parentDatasourceId", origId); |
|
34 |
env.setAttribute("namespacePrefix", nsPrefix); |
|
35 |
env.setAttribute("dateOfCollection", DateUtils.now_ISO8601()); |
|
36 |
|
|
37 |
// these are needed for validation and fill hostedby |
|
38 |
env.setAttribute(WorkflowsConstants.LOG_DATASOURCE_ID, origId); |
|
39 |
env.setAttribute(WorkflowsConstants.DATASOURCE_PREFIX, nsPrefix); |
|
40 |
|
|
41 |
return Arc.DEFAULT_ARC; |
|
42 |
|
|
43 |
} |
|
44 |
|
|
45 |
public String getProviderId() { |
|
46 |
return providerId; |
|
47 |
} |
|
48 |
|
|
49 |
public void setProviderId(final String providerId) { |
|
50 |
this.providerId = providerId; |
|
51 |
} |
|
52 |
|
|
53 |
} |
modules/dnet-isti/trunk/src/main/java/eu/dnetlib/msro/workflows/nodes/GeneratePersonReportJobNode.java | ||
---|---|---|
1 |
package eu.dnetlib.msro.workflows.nodes; |
|
2 |
|
|
3 |
import java.io.PrintWriter; |
|
4 |
import java.io.StringReader; |
|
5 |
import java.io.StringWriter; |
|
6 |
import java.nio.charset.StandardCharsets; |
|
7 |
import java.nio.file.Files; |
|
8 |
import java.nio.file.Paths; |
|
9 |
import java.text.SimpleDateFormat; |
|
10 |
import java.util.ArrayList; |
|
11 |
import java.util.Date; |
|
12 |
import java.util.List; |
|
13 |
import java.util.stream.StreamSupport; |
|
14 |
|
|
15 |
import org.apache.commons.lang3.StringUtils; |
|
16 |
import org.apache.commons.logging.Log; |
|
17 |
import org.apache.commons.logging.LogFactory; |
|
18 |
import org.dom4j.Document; |
|
19 |
import org.dom4j.Node; |
|
20 |
import org.dom4j.io.SAXReader; |
|
21 |
import org.springframework.beans.factory.annotation.Autowired; |
|
22 |
|
|
23 |
import eu.dnetlib.data.transformation.service.DataTransformerFactory; |
|
24 |
import eu.dnetlib.data.transformation.service.SimpleDataTransformer; |
|
25 |
import eu.dnetlib.enabling.resultset.client.ResultSetClient; |
|
26 |
import eu.dnetlib.msro.workflows.graph.Arc; |
|
27 |
import eu.dnetlib.msro.workflows.procs.Env; |
|
28 |
import eu.dnetlib.msro.workflows.util.WorkflowsConstants; |
|
29 |
import eu.dnetlib.rmi.common.ResultSet; |
|
30 |
|
|
31 |
public class GeneratePersonReportJobNode extends SimpleJobNode { |
|
32 |
|
|
33 |
private String inputEprParam; |
|
34 |
|
|
35 |
private String ruleId; |
|
36 |
|
|
37 |
@Autowired |
|
38 |
private DataTransformerFactory dataTransformerFactory; |
|
39 |
|
|
40 |
@Autowired |
|
41 |
private ResultSetClient resultSetClient; |
|
42 |
|
|
43 |
private static final Log log = LogFactory.getLog(GeneratePersonReportJobNode.class); |
|
44 |
|
|
45 |
protected class SinglePersonReport { |
|
46 |
|
|
47 |
private final String id; |
|
48 |
private final String title; |
|
49 |
private final List<String> oldCreators = new ArrayList<>(); |
|
50 |
private final List<String> newCreators = new ArrayList<>(); |
|
51 |
|
|
52 |
public SinglePersonReport(final String id, final String title) { |
|
53 |
this.id = id; |
|
54 |
this.title = title; |
|
55 |
} |
|
56 |
|
|
57 |
public String getId() { |
|
58 |
return id; |
|
59 |
} |
|
60 |
|
|
61 |
public String getTitle() { |
|
62 |
return title; |
|
63 |
} |
|
64 |
|
|
65 |
public List<String> getOldCreators() { |
|
66 |
return oldCreators; |
|
67 |
} |
|
68 |
|
|
69 |
public List<String> getNewCreators() { |
|
70 |
return newCreators; |
|
71 |
} |
|
72 |
|
|
73 |
public SinglePersonReport removeDuplicates() { |
|
74 |
|
|
75 |
final List<String> list = new ArrayList<>(); |
|
76 |
list.addAll(oldCreators); |
|
77 |
list.addAll(newCreators); |
|
78 |
|
|
79 |
for (final String s : list) { |
|
80 |
if (oldCreators.contains(s) && newCreators.contains(s)) { |
|
81 |
newCreators.remove(s); |
|
82 |
oldCreators.remove(s); |
|
83 |
} |
|
84 |
} |
|
85 |
|
|
86 |
return this; |
|
87 |
} |
|
88 |
|
|
89 |
public boolean hasCorrections() { |
|
90 |
return (oldCreators.size() > 0) || (newCreators.size() > 0); |
|
91 |
} |
|
92 |
|
|
93 |
@Override |
|
94 |
public String toString() { |
|
95 |
final StringWriter sw = new StringWriter(); |
|
96 |
sw.write("** "); |
|
97 |
sw.write(id); |
|
98 |
sw.write(" - "); |
|
99 |
sw.write(title); |
|
100 |
sw.write(" **\n"); |
|
101 |
|
|
102 |
if (oldCreators.size() > 0) { |
|
103 |
sw.write("ORIGINAL:\n"); |
|
104 |
for (int i = 0; i < oldCreators.size(); i++) { |
|
105 |
final String s = oldCreators.get(i); |
|
106 |
sw.write(String.format("%5d) %s\n", i + 1, StringUtils.isNotBlank(s) ? s : "[empty]")); |
|
107 |
} |
|
108 |
} |
|
109 |
if (newCreators.size() > 0) { |
|
110 |
sw.write("CORRECTED:\n"); |
|
111 |
for (int i = 0; i < newCreators.size(); i++) { |
|
112 |
final String s = newCreators.get(i); |
|
113 |
sw.write(String.format("%5d) %s\n", i + 1, StringUtils.isNotBlank(s) ? s : "[empty]")); |
|
114 |
} |
|
115 |
} |
|
116 |
return sw.toString(); |
|
117 |
} |
|
118 |
|
|
119 |
} |
|
120 |
|
|
121 |
@Override |
|
122 |
protected String execute(final Env env) throws Exception { |
|
123 |
|
|
124 |
@SuppressWarnings("unchecked") |
|
125 |
final ResultSet<String> rsIn = env.getAttribute(inputEprParam, ResultSet.class); |
|
126 |
|
|
127 |
final SimpleDataTransformer f = dataTransformerFactory.createTransformer(ruleId); |
|
128 |
final SAXReader reader = new SAXReader(); |
|
129 |
|
|
130 |
final String fileName = "/tmp/report_" + (new SimpleDateFormat("yyyyMMdd_HHmmss_S")).format(new Date()) + ".txt"; |
|
131 |
|
|
132 |
try (PrintWriter pw = new PrintWriter(Files.newBufferedWriter(Paths.get(fileName), StandardCharsets.UTF_8))) { |
|
133 |
StreamSupport.stream(resultSetClient.iter(rsIn, String.class).spliterator(), false).map( |
|
134 |
xml -> { |
|
135 |
try { |
|
136 |
final Document docOld = reader.read(new StringReader(xml)); |
|
137 |
final Document docNew = reader.read(new StringReader(f.apply(xml))); |
|
138 |
|
|
139 |
final String id = docNew.valueOf("//*[local-name() = 'recordIdentifier']"); |
|
140 |
final String title = docNew.valueOf("//*[local-name() = 'title']"); |
|
141 |
|
|
142 |
final SinglePersonReport report = new SinglePersonReport(id, title); |
|
143 |
for (final Object o : docOld.selectNodes("//*[local-name() = 'creator']")) { |
|
144 |
final String p1 = ((Node) o).valueOf("./*[local-name() = 'surname']").trim(); |
|
145 |
final String p2 = ((Node) o).valueOf("./*[local-name() = 'name']").trim(); |
|
146 |
final String author = StringUtils.isEmpty(p1) && StringUtils.isEmpty(p2) ? ((Node) o).getText().trim() : (p1 + " " + p2).trim(); |
|
147 |
report.getOldCreators().add(author); |
|
148 |
} |
|
149 |
for (final Object o : docNew.selectNodes("//*[local-name() = 'creator']")) { |
|
150 |
final String author = ((Node) o).valueOf("./*[local-name() = 'creatorName']").trim(); |
|
151 |
report.getNewCreators().add(author); |
|
152 |
} |
|
153 |
return report; |
|
154 |
} catch (final Exception e) { |
|
155 |
throw new RuntimeException(e); |
|
156 |
} |
|
157 |
}) |
|
158 |
.map(SinglePersonReport::removeDuplicates) |
|
159 |
.filter(SinglePersonReport::hasCorrections) |
|
160 |
.forEach(pw::println); |
|
161 |
} |
|
162 |
|
|
163 |
env.setAttribute(WorkflowsConstants.MAIN_LOG_PREFIX + "report", fileName); |
|
164 |
|
|
165 |
log.info("Saved a person report in " + fileName); |
|
166 |
|
|
167 |
return Arc.DEFAULT_ARC; |
|
168 |
} |
|
169 |
|
|
170 |
public String getInputEprParam() { |
|
171 |
return inputEprParam; |
|
172 |
} |
|
173 |
|
|
174 |
public void setInputEprParam(final String inputEprParam) { |
|
175 |
this.inputEprParam = inputEprParam; |
|
176 |
} |
|
177 |
|
|
178 |
public String getRuleId() { |
|
179 |
return ruleId; |
|
180 |
} |
|
181 |
|
|
182 |
public void setRuleId(final String ruleId) { |
|
183 |
this.ruleId = ruleId; |
|
184 |
} |
|
185 |
|
|
186 |
} |
modules/dnet-isti/trunk/src/main/java/eu/dnetlib/data/db/AffiliationsDao.java | ||
---|---|---|
103 | 103 |
jdbcTemplate.update("INSERT into affiliations(pid, gid, year) VALUES (?, ?, ?)", pid, gid, year); |
104 | 104 |
} |
105 | 105 |
|
106 |
public void updateUnknownAffiliation(final String pid, final String gid, final int year) { |
|
107 |
jdbcTemplate.update("UPDATE affiliations SET gid=? WHERE gid='UNKNOWN' AND pid=? AND year=?", gid, pid, year); |
|
108 |
} |
|
109 |
|
|
106 | 110 |
public JdbcTemplate getJdbcTemplate() { |
107 | 111 |
return jdbcTemplate; |
108 | 112 |
} |
modules/dnet-isti/trunk/src/main/java/eu/dnetlib/data/db/ui/AffiliationsAjaxController.java | ||
---|---|---|
6 | 6 |
import java.util.stream.Collectors; |
7 | 7 |
|
8 | 8 |
import org.springframework.beans.factory.annotation.Autowired; |
9 |
import org.springframework.web.bind.annotation.RequestBody; |
|
9 | 10 |
import org.springframework.web.bind.annotation.RequestMapping; |
10 | 11 |
import org.springframework.web.bind.annotation.RequestMethod; |
11 | 12 |
import org.springframework.web.bind.annotation.RestController; |
12 | 13 |
|
14 |
import eu.dnetlib.data.db.Affiliation; |
|
13 | 15 |
import eu.dnetlib.data.db.AffiliationsDao; |
14 | 16 |
import eu.dnetlib.data.db.Group; |
15 | 17 |
import eu.dnetlib.data.db.Person; |
... | ... | |
30 | 32 |
return dao.listGroups(); |
31 | 33 |
} |
32 | 34 |
|
35 |
@RequestMapping(value = "/ui/portal/addAffiliation", method = RequestMethod.POST) |
|
36 |
public boolean updateAffiliation(@RequestBody final Affiliation aff) { |
|
37 |
System.out.println(aff.getPid()); |
|
38 |
System.out.println(aff.getGid()); |
|
39 |
System.out.println(aff.getYear()); |
|
40 |
|
|
41 |
dao.updateUnknownAffiliation(aff.getPid(), aff.getGid(), aff.getYear()); |
|
42 |
|
|
43 |
return true; |
|
44 |
} |
|
45 |
|
|
33 | 46 |
} |
modules/dnet-isti/trunk/src/main/resources/eu/dnetlib/isti/applicationContext-isti.xml | ||
---|---|---|
5 | 5 |
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd"> |
6 | 6 |
|
7 | 7 |
<!-- Wf Nodes --> |
8 |
<bean id="wfNodeObtainISTIDataSourceParams" |
|
9 |
class="eu.dnetlib.msro.workflows.nodes.ObtainISTIDataSourceParamsJobNode" |
|
10 |
scope="prototype" /> |
|
11 |
|
|
12 |
<bean id="wfNodeGeneratePersonReport" |
|
13 |
class="eu.dnetlib.msro.workflows.nodes.GeneratePersonReportJobNode" |
|
14 |
scope="prototype" /> |
|
15 |
|
|
16 | 8 |
<bean id="wfNodePimpaUpdate" |
17 | 9 |
class="eu.dnetlib.msro.workflows.nodes.PimpaUpdateJobNode" |
18 | 10 |
scope="prototype" /> |
modules/dnet-isti/trunk/src/main/resources/eu/dnetlib/isti/workflows/repo-hi/pubs_aggregation_wf.xml.st | ||
---|---|---|
136 | 136 |
</PARAM> |
137 | 137 |
</PARAMETERS> |
138 | 138 |
<ARCS> |
139 |
<ARC to="report"/> |
|
140 |
</ARCS> |
|
141 |
</NODE> |
|
142 |
|
|
143 |
<NODE name="report" type="LaunchWorkflowTemplate"> |
|
144 |
<DESCRIPTION>Prepare report</DESCRIPTION> |
|
145 |
<PARAMETERS> |
|
146 |
<PARAM name="wfTemplateId" value="d6463488-6090-4581-a046-663753c554bb_V29ya2Zsb3dUZW1wbGF0ZURTUmVzb3VyY2VzL1dvcmtmbG93VGVtcGxhdGVEU1Jlc291cmNlVHlwZQ==" /> |
|
147 |
<PARAM name="wfTemplateParams"> |
|
148 |
<MAP> |
|
149 |
<ENTRY key="dsId" value="$dsId$" /> |
|
150 |
<ENTRY key="interface" value="$interface$" /> |
|
151 |
<ENTRY key="collMdstoreId" ref="collMdstoreId" /> |
|
152 |
<ENTRY key="transformRuleId" ref="transformationRuleId" /> |
|
153 |
</MAP> |
|
154 |
</PARAM> |
|
155 |
</PARAMETERS> |
|
156 |
<ARCS> |
|
157 | 139 |
<ARC to="success"/> |
158 | 140 |
</ARCS> |
159 | 141 |
</NODE> |
modules/dnet-isti/trunk/src/main/resources/eu/dnetlib/bootstrap/profiles/workflows/common/report.xml | ||
---|---|---|
1 |
<RESOURCE_PROFILE> |
|
2 |
<HEADER> |
|
3 |
<RESOURCE_IDENTIFIER value="d6463488-6090-4581-a046-663753c554bb_V29ya2Zsb3dUZW1wbGF0ZURTUmVzb3VyY2VzL1dvcmtmbG93VGVtcGxhdGVEU1Jlc291cmNlVHlwZQ=="/> |
|
4 |
<RESOURCE_TYPE value="WorkflowTemplateDSResourceType"/> |
|
5 |
<RESOURCE_KIND value="WorkflowTemplateDSResources"/> |
|
6 |
<RESOURCE_URI value=""/> |
|
7 |
<DATE_OF_CREATION value="2001-12-31T12:00:00"/> |
|
8 |
</HEADER> |
|
9 |
<BODY> |
|
10 |
<CONFIGURATION> |
|
11 |
<PARAMETERS> |
|
12 |
<PARAM name="dsId" description="Datasource Id" required="true" type="string"/> |
|
13 |
<PARAM name="interface" description="Datasource Interface" required="true" type="string"/> |
|
14 |
<PARAM name="collMdstoreId" description="Store for collected records" required="true" type="string"/> |
|
15 |
<PARAM name="transformRuleId" description="Transformation Rule Id" required="true" type="string"/> |
|
16 |
</PARAMETERS> |
|
17 |
<WORKFLOW> |
|
18 |
<NODE name="fetchOriginals" type="FetchMDStoreRecords" isStart="true"> |
|
19 |
<DESCRIPTION>Fetch records from MDStore</DESCRIPTION> |
|
20 |
<PARAMETERS> |
|
21 |
<PARAM name="mdId" ref="collMdstoreId"/> |
|
22 |
<PARAM name="eprParam" value="orig_epr"/> |
|
23 |
</PARAMETERS> |
|
24 |
<ARCS> |
|
25 |
<ARC to="report"/> |
|
26 |
</ARCS> |
|
27 |
</NODE> |
|
28 |
<NODE name="report" type="GeneratePersonReport"> |
|
29 |
<DESCRIPTION>Clean original records</DESCRIPTION> |
|
30 |
<PARAMETERS> |
|
31 |
<PARAM name="ruleId" ref="transformRuleId"/> |
|
32 |
<PARAM name="inputEprParam" value="orig_epr"/> |
|
33 |
</PARAMETERS> |
|
34 |
<ARCS> |
|
35 |
<ARC to="success"/> |
|
36 |
</ARCS> |
|
37 |
</NODE> |
|
38 |
</WORKFLOW> |
|
39 |
</CONFIGURATION> |
|
40 |
</BODY> |
|
41 |
</RESOURCE_PROFILE> |
modules/dnet-isti/trunk/src/main/resources/eu/dnetlib/web/resources/js/portal/affiliations.js | ||
---|---|---|
37 | 37 |
} |
38 | 38 |
} |
39 | 39 |
|
40 |
$scope.saveAffiliation = function(aff) { alert('TODO'); } |
|
40 |
$scope.saveAffiliation = function(aff) { |
|
41 |
|
|
42 |
delete $scope.tempAffiliation['pname']; |
|
43 |
|
|
44 |
if (!aff.gid) { |
|
45 |
show_notification("error","Group not selected"); |
|
46 |
return; |
|
47 |
} |
|
48 |
|
|
49 |
showSpinner(); |
|
50 |
$http.post('portal/addAffiliation', aff).success(function(data) { |
|
51 |
hideSpinner(); |
|
52 |
$scope.refresh(); |
|
53 |
}).error(function() { |
|
54 |
hideSpinner(); |
|
55 |
show_notification("error","An error occurred saving affiliations"); |
|
56 |
}); |
|
57 |
} |
|
41 | 58 |
|
42 | 59 |
$scope.refresh(); |
43 | 60 |
|
Also available in: Unified diff