Revision 48983
Added by Sandro La Bruzzo over 6 years ago
modules/dnet-wds/trunk/src/main/java/eu/dnetlib/msro/workflows/nodes/LoadContextsJobNode.java | ||
---|---|---|
1 |
package eu.dnetlib.msro.workflows.nodes; |
|
2 |
|
|
3 |
import eu.dnetlib.msro.workflows.graph.Arc; |
|
4 |
import eu.dnetlib.msro.workflows.nodes.index.ContextLoader; |
|
5 |
import eu.dnetlib.msro.workflows.procs.Env; |
|
6 |
import eu.dnetlib.rmi.manager.MSROException; |
|
7 |
import org.apache.commons.lang3.StringUtils; |
|
8 |
import org.apache.commons.logging.Log; |
|
9 |
import org.apache.commons.logging.LogFactory; |
|
10 |
import org.springframework.beans.factory.annotation.Autowired; |
|
11 |
|
|
12 |
public class LoadContextsJobNode extends SimpleJobNode { |
|
13 |
|
|
14 |
/** |
|
15 |
* logger. |
|
16 |
*/ |
|
17 |
private static final Log log = LogFactory.getLog(LoadContextsJobNode.class); // NOPMD by marko on 11/24/08 5:02 PM |
|
18 |
|
|
19 |
private String contextParam; |
|
20 |
|
|
21 |
@Autowired |
|
22 |
private ContextLoader contextLoader; |
|
23 |
|
|
24 |
@Override |
|
25 |
protected String execute(final Env env) throws Exception { |
|
26 |
|
|
27 |
log.info("start preparing job"); |
|
28 |
|
|
29 |
final String contexts = this.contextLoader.load(); |
|
30 |
|
|
31 |
if (StringUtils.isBlank(contexts)) { throw new MSROException("empty contexts"); } |
|
32 |
|
|
33 |
env.setAttribute(getContextParam(), contexts); |
|
34 |
|
|
35 |
return Arc.DEFAULT_ARC; |
|
36 |
} |
|
37 |
|
|
38 |
public String getContextParam() { |
|
39 |
return contextParam; |
|
40 |
} |
|
41 |
|
|
42 |
public void setContextParam(final String contextParam) { |
|
43 |
this.contextParam = contextParam; |
|
44 |
} |
|
45 |
} |
modules/dnet-wds/trunk/src/main/java/eu/dnetlib/msro/workflows/nodes/provision/FindIndexJobNode.java | ||
---|---|---|
1 |
package eu.dnetlib.msro.workflows.nodes.provision; |
|
2 |
|
|
3 |
import java.util.List; |
|
4 |
import javax.annotation.Resource; |
|
5 |
|
|
6 |
import com.google.common.collect.Iterables; |
|
7 |
import eu.dnetlib.enabling.locators.UniqueServiceLocator; |
|
8 |
import eu.dnetlib.msro.workflows.nodes.SimpleJobNode; |
|
9 |
import eu.dnetlib.msro.workflows.procs.Env; |
|
10 |
import eu.dnetlib.rmi.enabling.ISLookUpService; |
|
11 |
import org.apache.commons.logging.Log; |
|
12 |
import org.apache.commons.logging.LogFactory; |
|
13 |
|
|
14 |
public class FindIndexJobNode extends SimpleJobNode { |
|
15 |
|
|
16 |
/** |
|
17 |
* logger. |
|
18 |
*/ |
|
19 |
private static final Log log = LogFactory.getLog(FindIndexJobNode.class); // NOPMD by marko on 11/24/08 5:02 PM |
|
20 |
|
|
21 |
@Resource |
|
22 |
private UniqueServiceLocator serviceLocator; |
|
23 |
|
|
24 |
/** |
|
25 |
* if non null, overrides format from env. |
|
26 |
*/ |
|
27 |
private String mdFormat; |
|
28 |
|
|
29 |
/** |
|
30 |
* if non null, overrides format from env. |
|
31 |
*/ |
|
32 |
private String layout; |
|
33 |
|
|
34 |
/** |
|
35 |
* if non null, overrides format from env. |
|
36 |
*/ |
|
37 |
private String interpretation; |
|
38 |
|
|
39 |
/** |
|
40 |
* {@inheritDoc} |
|
41 |
*/ |
|
42 |
@Override |
|
43 |
public String execute(final Env env) { |
|
44 |
final String envFormat = env.getAttribute("format", String.class); |
|
45 |
final String envLayout = env.getAttribute("layout", String.class); |
|
46 |
final String envInterpretation = env.getAttribute("interpretation", String.class); |
|
47 |
|
|
48 |
final String format = handleOverride(env, "format", envFormat, getMdFormat()); |
|
49 |
final String layout = handleOverride(env, "layout", envLayout, getLayout()); |
|
50 |
final String interp = handleOverride(env, "interpretation", envInterpretation, getInterpretation()); |
|
51 |
|
|
52 |
String mdRef = format + "-" + layout + "-" + interp; |
|
53 |
log.info("searching index for [" + mdRef + "]"); |
|
54 |
|
|
55 |
final String indexId = findIndex(format, layout, interp); |
|
56 |
env.setAttribute("index_id", indexId); |
|
57 |
|
|
58 |
if (indexId == null || indexId.isEmpty()) { |
|
59 |
log.info("no index was found for [" + mdRef + "]"); |
|
60 |
return "notFound"; |
|
61 |
} else { |
|
62 |
log.info("index found for [" + mdRef + "]: " + indexId); |
|
63 |
return "found"; |
|
64 |
} |
|
65 |
} |
|
66 |
|
|
67 |
private String findIndex(final String format, final String layout, final String interp) { |
|
68 |
final String xquery = |
|
69 |
"for $x in /RESOURCE_PROFILE[.//RESOURCE_TYPE/@value='IndexDSResourceType']" + "return $x[.//METADATA_FORMAT = '" + format |
|
70 |
+ "' and .//METADATA_FORMAT_LAYOUT='" + layout + "' and .//METADATA_FORMAT_INTERPRETATION = '" + interp |
|
71 |
+ "']//RESOURCE_IDENTIFIER/@value/string()"; |
|
72 |
try { |
|
73 |
log.info("xquery: " + xquery); |
|
74 |
List<String> ids = serviceLocator.getService(ISLookUpService.class).quickSearchProfile(xquery); |
|
75 |
log.info("found indexDS ids: " + ids); |
|
76 |
if (ids == null || ids.isEmpty()) { return null; } |
|
77 |
if (ids.size() > 1) { |
|
78 |
throw new IllegalStateException("found more than one index of given format: " + format + ", layout: " + layout |
|
79 |
+ ", interpretation: " + interp); |
|
80 |
} |
|
81 |
return Iterables.getOnlyElement(ids); |
|
82 |
} catch (Exception e) { |
|
83 |
return null; |
|
84 |
} |
|
85 |
} |
|
86 |
|
|
87 |
private String handleOverride(final Env env, final String name, final String envParam, final String override) { |
|
88 |
if (override != null) { |
|
89 |
env.setAttribute(name, override); |
|
90 |
} |
|
91 |
return override != null ? override : envParam; |
|
92 |
} |
|
93 |
|
|
94 |
public String getMdFormat() { |
|
95 |
return mdFormat; |
|
96 |
} |
|
97 |
|
|
98 |
public void setMdFormat(final String mdFormat) { |
|
99 |
this.mdFormat = mdFormat; |
|
100 |
} |
|
101 |
|
|
102 |
public String getLayout() { |
|
103 |
return layout; |
|
104 |
} |
|
105 |
|
|
106 |
public void setLayout(final String layout) { |
|
107 |
this.layout = layout; |
|
108 |
} |
|
109 |
|
|
110 |
public String getInterpretation() { |
|
111 |
return interpretation; |
|
112 |
} |
|
113 |
|
|
114 |
public void setInterpretation(final String interpretation) { |
|
115 |
this.interpretation = interpretation; |
|
116 |
} |
|
117 |
|
|
118 |
} |
modules/dnet-wds/trunk/src/main/java/eu/dnetlib/msro/workflows/nodes/FetchRelClassesJobNode.java | ||
---|---|---|
1 |
package eu.dnetlib.msro.workflows.nodes; |
|
2 |
|
|
3 |
import java.util.List; |
|
4 |
import javax.annotation.Resource; |
|
5 |
|
|
6 |
import com.google.gson.Gson; |
|
7 |
import eu.dnetlib.enabling.locators.UniqueServiceLocator; |
|
8 |
import eu.dnetlib.msro.workflows.graph.Arc; |
|
9 |
import eu.dnetlib.msro.workflows.procs.Env; |
|
10 |
import eu.dnetlib.rmi.enabling.ISLookUpException; |
|
11 |
import eu.dnetlib.rmi.enabling.ISLookUpService; |
|
12 |
import org.apache.commons.logging.Log; |
|
13 |
import org.apache.commons.logging.LogFactory; |
|
14 |
|
|
15 |
public class FetchRelClassesJobNode extends SimpleJobNode { |
|
16 |
|
|
17 |
private static final Log log = LogFactory.getLog(FetchRelClassesJobNode.class); // NOPMD by marko on 11/24/08 5:02 PM |
|
18 |
|
|
19 |
private String xquery; |
|
20 |
|
|
21 |
private String relClassesName; |
|
22 |
|
|
23 |
@Resource |
|
24 |
private UniqueServiceLocator serviceLocator; |
|
25 |
|
|
26 |
@Override |
|
27 |
protected String execute(final Env env) throws Exception { |
|
28 |
|
|
29 |
final String relClasses = new Gson().toJson(fetchRelClasses()); |
|
30 |
|
|
31 |
log.info("loaded relClasses: " + relClasses); |
|
32 |
|
|
33 |
env.setAttribute(getRelClassesName(), relClasses); |
|
34 |
|
|
35 |
return Arc.DEFAULT_ARC; |
|
36 |
} |
|
37 |
|
|
38 |
private List<String> fetchRelClasses() throws ISLookUpException { |
|
39 |
|
|
40 |
log.info("Loading relClasses with xquery: " + getXquery()); |
|
41 |
|
|
42 |
return serviceLocator.getService(ISLookUpService.class).quickSearchProfile(getXquery()); |
|
43 |
} |
|
44 |
|
|
45 |
public String getRelClassesName() { |
|
46 |
return relClassesName; |
|
47 |
} |
|
48 |
|
|
49 |
public void setRelClassesName(final String relClassesName) { |
|
50 |
this.relClassesName = relClassesName; |
|
51 |
} |
|
52 |
|
|
53 |
public String getXquery() { |
|
54 |
return xquery; |
|
55 |
} |
|
56 |
|
|
57 |
public void setXquery(final String xquery) { |
|
58 |
this.xquery = xquery; |
|
59 |
} |
|
60 |
} |
modules/dnet-wds/trunk/src/main/java/eu/dnetlib/msro/workflows/nodes/vre/VREPostJobNode.java | ||
---|---|---|
1 |
package eu.dnetlib.msro.workflows.nodes.vre; |
|
2 |
|
|
3 |
import java.net.URI; |
|
4 |
|
|
5 |
import eu.dnetlib.msro.workflows.graph.Arc; |
|
6 |
import eu.dnetlib.msro.workflows.nodes.SimpleJobNode; |
|
7 |
import eu.dnetlib.msro.workflows.procs.Env; |
|
8 |
import org.apache.commons.logging.Log; |
|
9 |
import org.apache.commons.logging.LogFactory; |
|
10 |
import org.apache.http.client.methods.HttpPost; |
|
11 |
import org.apache.http.client.utils.URIBuilder; |
|
12 |
import org.apache.http.entity.ContentType; |
|
13 |
import org.apache.http.entity.StringEntity; |
|
14 |
import org.apache.http.impl.client.BasicResponseHandler; |
|
15 |
import org.apache.http.impl.client.CloseableHttpClient; |
|
16 |
import org.apache.http.impl.client.HttpClients; |
|
17 |
|
|
18 |
/** |
|
19 |
* Created by alessia on 24/03/16. |
|
20 |
*/ |
|
21 |
public class VREPostJobNode extends SimpleJobNode { |
|
22 |
|
|
23 |
private static final Log log = LogFactory.getLog(VREPostJobNode.class); |
|
24 |
private String scheme; |
|
25 |
private String host; |
|
26 |
private String postPath; |
|
27 |
|
|
28 |
// POST parameters |
|
29 |
private String appToken; |
|
30 |
private String previewTitle; |
|
31 |
private String previewDescription; |
|
32 |
private String text; |
|
33 |
private String httpImageUrl; |
|
34 |
private boolean enableNotification; |
|
35 |
|
|
36 |
@Override |
|
37 |
protected String execute(final Env env) throws Exception { |
|
38 |
final CloseableHttpClient httpclient = HttpClients.createDefault(); |
|
39 |
try { |
|
40 |
final URI postUri = new URIBuilder().setScheme(this.scheme).setHost(this.host).setPath(this.postPath).build(); |
|
41 |
final HttpPost postAction = new HttpPost(postUri); |
|
42 |
final StringBuilder strBuilder = new StringBuilder(); |
|
43 |
strBuilder.append("token=").append(this.appToken).append("&previewtitle=").append(this.previewTitle) |
|
44 |
.append("&previewdescription=").append(this.previewDescription).append("&text=").append(this.text) |
|
45 |
.append("&httpimageurl=").append(this.httpImageUrl).append("&enablenotification=").append(this.enableNotification); |
|
46 |
final String postBody = strBuilder.toString(); |
|
47 |
log.debug("POST body: " + postBody); |
|
48 |
final StringEntity ent = new StringEntity(postBody, ContentType.APPLICATION_FORM_URLENCODED); |
|
49 |
|
|
50 |
postAction.setEntity(ent); |
|
51 |
|
|
52 |
final BasicResponseHandler responseHandler = new BasicResponseHandler(); |
|
53 |
|
|
54 |
httpclient.execute(postAction, responseHandler); |
|
55 |
return Arc.DEFAULT_ARC; |
|
56 |
} finally { |
|
57 |
httpclient.close(); |
|
58 |
} |
|
59 |
|
|
60 |
} |
|
61 |
|
|
62 |
public String getScheme() { |
|
63 |
return this.scheme; |
|
64 |
} |
|
65 |
|
|
66 |
public void setScheme(final String scheme) { |
|
67 |
this.scheme = scheme; |
|
68 |
} |
|
69 |
|
|
70 |
public String getHost() { |
|
71 |
return this.host; |
|
72 |
} |
|
73 |
|
|
74 |
public void setHost(final String host) { |
|
75 |
this.host = host; |
|
76 |
} |
|
77 |
|
|
78 |
public String getPostPath() { |
|
79 |
return this.postPath; |
|
80 |
} |
|
81 |
|
|
82 |
public void setPostPath(final String postPath) { |
|
83 |
this.postPath = postPath; |
|
84 |
} |
|
85 |
|
|
86 |
public String getAppToken() { |
|
87 |
return this.appToken; |
|
88 |
} |
|
89 |
|
|
90 |
public void setAppToken(final String token) { |
|
91 |
this.appToken = token; |
|
92 |
} |
|
93 |
|
|
94 |
public String getPreviewTitle() { |
|
95 |
return this.previewTitle; |
|
96 |
} |
|
97 |
|
|
98 |
public void setPreviewTitle(final String previewTitle) { |
|
99 |
this.previewTitle = previewTitle; |
|
100 |
} |
|
101 |
|
|
102 |
public String getPreviewDescription() { |
|
103 |
return this.previewDescription; |
|
104 |
} |
|
105 |
|
|
106 |
public void setPreviewDescription(final String previewDescription) { |
|
107 |
this.previewDescription = previewDescription; |
|
108 |
} |
|
109 |
|
|
110 |
public String getText() { |
|
111 |
return this.text; |
|
112 |
} |
|
113 |
|
|
114 |
public void setText(final String text) { |
|
115 |
this.text = text; |
|
116 |
} |
|
117 |
|
|
118 |
public String getHttpImageUrl() { |
|
119 |
return this.httpImageUrl; |
|
120 |
} |
|
121 |
|
|
122 |
public void setHttpImageUrl(final String httpImageUrl) { |
|
123 |
this.httpImageUrl = httpImageUrl; |
|
124 |
} |
|
125 |
|
|
126 |
public boolean isEnableNotification() { |
|
127 |
return this.enableNotification; |
|
128 |
} |
|
129 |
|
|
130 |
public void setEnableNotification(final boolean enablenotification) { |
|
131 |
this.enableNotification = enablenotification; |
|
132 |
} |
|
133 |
} |
modules/dnet-wds/trunk/src/main/java/eu/dnetlib/msro/workflows/nodes/LoadMappingProfileJobNode.java | ||
---|---|---|
1 |
package eu.dnetlib.msro.workflows.nodes; |
|
2 |
|
|
3 |
import eu.dnetlib.enabling.locators.UniqueServiceLocator; |
|
4 |
import eu.dnetlib.msro.workflows.graph.Arc; |
|
5 |
import eu.dnetlib.msro.workflows.procs.Env; |
|
6 |
import eu.dnetlib.rmi.enabling.ISLookUpService; |
|
7 |
import org.apache.commons.lang3.StringUtils; |
|
8 |
import org.apache.commons.logging.Log; |
|
9 |
import org.apache.commons.logging.LogFactory; |
|
10 |
import org.springframework.beans.factory.annotation.Autowired; |
|
11 |
|
|
12 |
/** |
|
13 |
* Created by claudio on 20/06/16. |
|
14 |
*/ |
|
15 |
public class LoadMappingProfileJobNode extends SimpleJobNode { |
|
16 |
|
|
17 |
private static final Log log = LogFactory.getLog(LoadMappingProfileJobNode.class); |
|
18 |
|
|
19 |
@Autowired |
|
20 |
private UniqueServiceLocator serviceLocator; |
|
21 |
|
|
22 |
private String profileId; |
|
23 |
|
|
24 |
private String loadedMappingParam; |
|
25 |
|
|
26 |
@Override |
|
27 |
protected String execute(final Env env) throws Exception { |
|
28 |
|
|
29 |
log.info(String.format("loading mapping from: %s", profileId)); |
|
30 |
|
|
31 |
final String xquery = String.format("/RESOURCE_PROFILE[.//RESOURCE_IDENTIFIER/@value='%s']/BODY/CONFIGURATION/SCRIPT/CODE/*[local-name()='stylesheet']", |
|
32 |
getProfileId()); |
|
33 |
final String xslt = serviceLocator.getService(ISLookUpService.class).getResourceProfileByQuery(xquery); |
|
34 |
|
|
35 |
log.debug(String.format("mapping: %s", xslt)); |
|
36 |
|
|
37 |
if (StringUtils.isBlank(xslt)) { |
|
38 |
throw new IllegalStateException("unable to load mapping from profile: " + getProfileId()); |
|
39 |
} |
|
40 |
|
|
41 |
env.setAttribute(getLoadedMappingParam(), xslt); |
|
42 |
|
|
43 |
return Arc.DEFAULT_ARC; |
|
44 |
} |
|
45 |
|
|
46 |
public String getProfileId() { |
|
47 |
return profileId; |
|
48 |
} |
|
49 |
|
|
50 |
public void setProfileId(final String profileId) { |
|
51 |
this.profileId = profileId; |
|
52 |
} |
|
53 |
|
|
54 |
public String getLoadedMappingParam() { |
|
55 |
return loadedMappingParam; |
|
56 |
} |
|
57 |
|
|
58 |
public void setLoadedMappingParam(final String loadedMappingParam) { |
|
59 |
this.loadedMappingParam = loadedMappingParam; |
|
60 |
} |
|
61 |
} |
modules/dnet-wds/trunk/src/main/java/eu/dnetlib/msro/workflows/nodes/stats/RestoreStatsCacheJobNode.java | ||
---|---|---|
1 |
package eu.dnetlib.msro.workflows.nodes.stats; |
|
2 |
|
|
3 |
import eu.dnetlib.enabling.tools.blackboard.BlackboardJob; |
|
4 |
import eu.dnetlib.msro.workflows.procs.Token; |
|
5 |
import org.apache.commons.lang3.StringUtils; |
|
6 |
import org.apache.commons.logging.Log; |
|
7 |
import org.apache.commons.logging.LogFactory; |
|
8 |
|
|
9 |
/** |
|
10 |
* Ask the StatsManagerService to restore the cache of the portal specified by the additional BB parameter |
|
11 |
* <code>StatsManagerServiceBBAction.RESTORE_CACHE.getTargetPortalParamName()</code> to the last available backup. |
|
12 |
* <p> |
|
13 |
* To create a backup you must send a "backup" BB message. |
|
14 |
* </p> |
|
15 |
* |
|
16 |
* @author alessia |
|
17 |
* @see BackupStatsCacheJobNode |
|
18 |
*/ |
|
19 |
public class RestoreStatsCacheJobNode extends AbstractStatsJobNode { |
|
20 |
|
|
21 |
private static final Log log = LogFactory.getLog(RestoreStatsCacheJobNode.class); // NOPMD by marko on 11/24/08 5:02 PM |
|
22 |
|
|
23 |
@Override |
|
24 |
protected void prepareJob(final BlackboardJob job, final Token token) throws Exception { |
|
25 |
job.setAction(StatsManagerServiceBBAction.RESTORE_CACHE.action()); |
|
26 |
final String portal = getPortalName(token.getEnv()); |
|
27 |
if (StringUtils.isNotBlank(portal)) { |
|
28 |
job.getParameters().put(StatsManagerServiceBBAction.RESTORE_CACHE.getTargetPortalParamName(), portal); |
|
29 |
} else { |
|
30 |
log.warn(StatsManagerServiceBBAction.RESTORE_CACHE.getTargetPortalParamName() + " not set. The StatsManagerService will use its default."); |
|
31 |
} |
|
32 |
} |
|
33 |
|
|
34 |
} |
modules/dnet-wds/trunk/src/main/java/eu/dnetlib/msro/workflows/nodes/stats/BackupStatsCacheJobNode.java | ||
---|---|---|
1 |
package eu.dnetlib.msro.workflows.nodes.stats; |
|
2 |
|
|
3 |
import eu.dnetlib.enabling.tools.blackboard.BlackboardJob; |
|
4 |
import eu.dnetlib.msro.workflows.procs.Token; |
|
5 |
import org.apache.commons.lang3.StringUtils; |
|
6 |
import org.apache.commons.logging.Log; |
|
7 |
import org.apache.commons.logging.LogFactory; |
|
8 |
|
|
9 |
/** |
|
10 |
* Ask the StatsManagerService to backup the stats cache of the portal specified by the additional BB parameter |
|
11 |
* <code>StatsManagerServiceBBAction.BACKUP_CACHE.getTargetPortalParamName()</code>. The cache can be restored with the last generated |
|
12 |
* backup by sending a "restore" BB message. |
|
13 |
* |
|
14 |
* @author alessia |
|
15 |
* @see RestoreStatsCacheJobNode |
|
16 |
*/ |
|
17 |
public class BackupStatsCacheJobNode extends AbstractStatsJobNode { |
|
18 |
|
|
19 |
private static final Log log = LogFactory.getLog(BackupStatsCacheJobNode.class); // NOPMD by marko on 11/24/08 5:02 PM |
|
20 |
|
|
21 |
@Override |
|
22 |
protected void prepareJob(final BlackboardJob job, final Token token) throws Exception { |
|
23 |
job.setAction(StatsManagerServiceBBAction.BACKUP_CACHE.action()); |
|
24 |
final String portal = getPortalName(token.getEnv()); |
|
25 |
if (StringUtils.isNotBlank(portal)) { |
|
26 |
job.getParameters().put(StatsManagerServiceBBAction.BACKUP_CACHE.getTargetPortalParamName(), portal); |
|
27 |
} else { |
|
28 |
log.warn(StatsManagerServiceBBAction.BACKUP_CACHE.getTargetPortalParamName() + " not set. The StatsManagerService will use its default."); |
|
29 |
} |
|
30 |
} |
|
31 |
} |
modules/dnet-wds/trunk/src/main/java/eu/dnetlib/msro/workflows/nodes/stats/RefreshShadowCacheJobNode.java | ||
---|---|---|
1 |
package eu.dnetlib.msro.workflows.nodes.stats; |
|
2 |
|
|
3 |
import eu.dnetlib.enabling.tools.blackboard.BlackboardJob; |
|
4 |
import eu.dnetlib.msro.workflows.procs.Token; |
|
5 |
import org.apache.commons.lang3.StringUtils; |
|
6 |
import org.apache.commons.logging.Log; |
|
7 |
import org.apache.commons.logging.LogFactory; |
|
8 |
|
|
9 |
/** |
|
10 |
* Ask the StatsManagerService to refresh the shadow cache according to the content of the shadow stats db for the portal specified by the |
|
11 |
* additional BB parameter <code>StatsManagerServiceBBAction.REFRESH_SHADOW_CACHE.getTargetPortalParamName()</code>. |
|
12 |
* <p> |
|
13 |
* In order for the given portal to actually use the generated cache, we must promote the cache with the BB message 'promoteCache'. |
|
14 |
* </p> |
|
15 |
* |
|
16 |
* @author alessia |
|
17 |
* @see eu.dnetlib.msro.workflows.nodes.stats.PromoteShadowCacheStatsJobNode |
|
18 |
*/ |
|
19 |
public class RefreshShadowCacheJobNode extends AbstractStatsJobNode { |
|
20 |
|
|
21 |
private static final Log log = LogFactory.getLog(RefreshShadowCacheJobNode.class); // NOPMD by marko on 11/24/08 5:02 PM |
|
22 |
|
|
23 |
@Override |
|
24 |
protected void prepareJob(final BlackboardJob job, final Token token) throws Exception { |
|
25 |
job.setAction(StatsManagerServiceBBAction.REFRESH_SHADOW_CACHE.action()); |
|
26 |
final String portal = getPortalName(token.getEnv()); |
|
27 |
if (StringUtils.isNotBlank(portal)) { |
|
28 |
job.getParameters().put(StatsManagerServiceBBAction.REFRESH_SHADOW_CACHE.getTargetPortalParamName(), portal); |
|
29 |
} else { |
|
30 |
log.warn(StatsManagerServiceBBAction.REFRESH_SHADOW_CACHE.getTargetPortalParamName() + " not set. The StatsManagerService will use its default."); |
|
31 |
} |
|
32 |
} |
|
33 |
|
|
34 |
} |
modules/dnet-wds/trunk/src/main/java/eu/dnetlib/msro/workflows/nodes/stats/PromoteShadowStatsJobNode.java | ||
---|---|---|
1 |
package eu.dnetlib.msro.workflows.nodes.stats; |
|
2 |
|
|
3 |
import eu.dnetlib.enabling.tools.blackboard.BlackboardJob; |
|
4 |
import eu.dnetlib.msro.workflows.procs.Token; |
|
5 |
import org.apache.commons.lang3.StringUtils; |
|
6 |
import org.apache.commons.logging.Log; |
|
7 |
import org.apache.commons.logging.LogFactory; |
|
8 |
|
|
9 |
/** |
|
10 |
* Ask the StatsManagerService to promote the shadow stats db and cache to public for the portal specified by the additional BB parameter |
|
11 |
* <code>StatsManagerServiceBBAction.PROMOTE_SHADOW_STATS.getTargetPortalParamName()</code>. |
|
12 |
* <p> |
|
13 |
* <p> |
|
14 |
* According to the StatsManagerService specifications in https://issue.openaire.research-infrastructures.eu/issues/914#note-49, this BB |
|
15 |
* action will: |
|
16 |
* <ol> |
|
17 |
* <li>promote the shadow cache to public</li> |
|
18 |
* <li>make a backup of the current stats db schema under the name 'backup'</li> |
|
19 |
* <li>replace it with the new one</li> |
|
20 |
* </ol> |
|
21 |
* </p> |
|
22 |
* |
|
23 |
* @author alessia |
|
24 |
*/ |
|
25 |
public class PromoteShadowStatsJobNode extends AbstractStatsJobNode { |
|
26 |
|
|
27 |
private static final Log log = LogFactory.getLog(PromoteShadowStatsJobNode.class); // NOPMD by marko on 11/24/08 5:02 PM |
|
28 |
|
|
29 |
@Override |
|
30 |
protected void prepareJob(final BlackboardJob job, final Token token) throws Exception { |
|
31 |
job.setAction(StatsManagerServiceBBAction.PROMOTE_SHADOW_STATS.action()); |
|
32 |
final String portal = getPortalName(token.getEnv()); |
|
33 |
if (StringUtils.isNotBlank(portal)) { |
|
34 |
job.getParameters().put(StatsManagerServiceBBAction.PROMOTE_SHADOW_STATS.getTargetPortalParamName(), portal); |
|
35 |
} else { |
|
36 |
log.warn(StatsManagerServiceBBAction.PROMOTE_SHADOW_STATS.getTargetPortalParamName() + " not set. The StatsManagerService will use its default."); |
|
37 |
} |
|
38 |
} |
|
39 |
|
|
40 |
} |
modules/dnet-wds/trunk/src/main/java/eu/dnetlib/msro/workflows/nodes/stats/MigrateStatsCacheJobNode.java | ||
---|---|---|
1 |
package eu.dnetlib.msro.workflows.nodes.stats; |
|
2 |
|
|
3 |
import eu.dnetlib.enabling.tools.blackboard.BlackboardJob; |
|
4 |
import eu.dnetlib.msro.workflows.procs.Token; |
|
5 |
import eu.dnetlib.rmi.manager.MSROException; |
|
6 |
import org.apache.commons.lang3.StringUtils; |
|
7 |
import org.apache.commons.logging.Log; |
|
8 |
import org.apache.commons.logging.LogFactory; |
|
9 |
|
|
10 |
/** |
|
11 |
* Ask the StatsManagerService to copy a cache of a portal to another portal cache. |
|
12 |
* <p> |
|
13 |
* The source portal is specified in the BB parameter <code>StatsManagerServiceBBAction.MIGRATE_CACHE.getSourcePortalParamName()</code>. |
|
14 |
* </p> |
|
15 |
* <p> |
|
16 |
* The target portal is specified in the BB parameter <code>StatsManagerServiceBBAction.MIGRATE_CACHE.getTargetPortalParamName()</code> |
|
17 |
* </p> |
|
18 |
* |
|
19 |
* @author alessia |
|
20 |
*/ |
|
21 |
public class MigrateStatsCacheJobNode extends AbstractStatsJobNode { |
|
22 |
|
|
23 |
private static final Log log = LogFactory.getLog(MigrateStatsCacheJobNode.class); // NOPMD by marko on 11/24/08 5:02 PM |
|
24 |
|
|
25 |
/** |
|
26 |
* BB parameter defining which is the portal with the source cache to migrate. |
|
27 |
*/ |
|
28 |
private String sourcePortal; |
|
29 |
|
|
30 |
@Override |
|
31 |
protected void prepareJob(final BlackboardJob job, final Token token) throws Exception { |
|
32 |
job.setAction(StatsManagerServiceBBAction.MIGRATE_CACHE.action()); |
|
33 |
if (StringUtils.isBlank(this.sourcePortal)) { throw new MSROException("Parameter sourcePortal required to migrate the cache"); } |
|
34 |
job.getParameters().put(StatsManagerServiceBBAction.MIGRATE_CACHE.getSourcePortalParamName(), this.sourcePortal); |
|
35 |
final String targetPortal = getPortalName(token.getEnv()); |
|
36 |
if (StringUtils.isNotBlank(targetPortal)) { |
|
37 |
job.getParameters().put(StatsManagerServiceBBAction.MIGRATE_CACHE.getTargetPortalParamName(), targetPortal); |
|
38 |
} else { |
|
39 |
log.warn(StatsManagerServiceBBAction.MIGRATE_CACHE.getTargetPortalParamName() + " not set. The StatsManagerService will use its default."); |
|
40 |
} |
|
41 |
|
|
42 |
} |
|
43 |
|
|
44 |
public String getSourcePortal() { |
|
45 |
return this.sourcePortal; |
|
46 |
} |
|
47 |
|
|
48 |
public void setSourcePortal(final String sourcePortal) { |
|
49 |
this.sourcePortal = sourcePortal; |
|
50 |
} |
|
51 |
} |
modules/dnet-wds/trunk/src/main/java/eu/dnetlib/msro/workflows/nodes/stats/StatsManagerServiceBBAction.java | ||
---|---|---|
1 |
package eu.dnetlib.msro.workflows.nodes.stats; |
|
2 |
|
|
3 |
public enum StatsManagerServiceBBAction { |
|
4 |
PROMOTE_SHADOW_STATS { |
|
5 |
@Override |
|
6 |
public String action() { |
|
7 |
return "promoteShadow"; |
|
8 |
} |
|
9 |
}, |
|
10 |
PROMOTE_SHADOW_CACHE { |
|
11 |
@Override |
|
12 |
public String action() { |
|
13 |
return "promoteCache"; |
|
14 |
} |
|
15 |
}, |
|
16 |
REFRESH_SHADOW_CACHE { |
|
17 |
@Override |
|
18 |
public String action() { |
|
19 |
return "refreshCache"; |
|
20 |
} |
|
21 |
|
|
22 |
}, |
|
23 |
VALIDATE_SHADOW_STATS { |
|
24 |
@Override |
|
25 |
public String action() { |
|
26 |
return "validate"; |
|
27 |
} |
|
28 |
|
|
29 |
}, |
|
30 |
BACKUP_CACHE { |
|
31 |
@Override |
|
32 |
public String action() { |
|
33 |
return "backup"; |
|
34 |
} |
|
35 |
|
|
36 |
}, |
|
37 |
RESTORE_CACHE { |
|
38 |
@Override |
|
39 |
public String action() { |
|
40 |
return "restore"; |
|
41 |
} |
|
42 |
|
|
43 |
}, |
|
44 |
MIGRATE_CACHE { |
|
45 |
@Override |
|
46 |
public String action() { |
|
47 |
return "migrate"; |
|
48 |
} |
|
49 |
|
|
50 |
@Override |
|
51 |
public String getTargetPortalParamName() { |
|
52 |
return "targetCache"; |
|
53 |
} |
|
54 |
|
|
55 |
}; |
|
56 |
|
|
57 |
private static String DEFAULT_PORTAL_PARAM_NAME = "cache"; |
|
58 |
|
|
59 |
public abstract String action(); |
|
60 |
|
|
61 |
public String getSourcePortalParamName() { |
|
62 |
return DEFAULT_PORTAL_PARAM_NAME; |
|
63 |
} |
|
64 |
|
|
65 |
public String getTargetPortalParamName() { |
|
66 |
return DEFAULT_PORTAL_PARAM_NAME; |
|
67 |
} |
|
68 |
} |
modules/dnet-wds/trunk/src/main/java/eu/dnetlib/msro/workflows/nodes/stats/ValidateShadowStatsJobNode.java | ||
---|---|---|
1 |
package eu.dnetlib.msro.workflows.nodes.stats; |
|
2 |
|
|
3 |
import eu.dnetlib.enabling.tools.blackboard.BlackboardJob; |
|
4 |
import eu.dnetlib.msro.workflows.procs.Token; |
|
5 |
import org.apache.commons.lang3.StringUtils; |
|
6 |
import org.apache.commons.logging.Log; |
|
7 |
import org.apache.commons.logging.LogFactory; |
|
8 |
|
|
9 |
/** |
|
10 |
* Ask the StatsManagerService to perform the content validation between the shadow stats db and the preproduction index (using the |
|
11 |
* prepublic search service) and creates a report, which is serialized in the blackboard job parameters. |
|
12 |
* <p> |
|
13 |
* The report is relative to the shadow stats db related to the portal specified by the additional BB parameter |
|
14 |
* <code>StatsManagerServiceBBAction.VALIDATE_SHADOW_STATS.getTargetPortalParamName()</code> |
|
15 |
* </p> |
|
16 |
* |
|
17 |
* @author alessia |
|
18 |
*/ |
|
19 |
public class ValidateShadowStatsJobNode extends AbstractStatsJobNode { |
|
20 |
|
|
21 |
private static final Log log = LogFactory.getLog(ValidateShadowStatsJobNode.class); // NOPMD by marko on 11/24/08 5:02 PM |
|
22 |
|
|
23 |
@Override |
|
24 |
protected void prepareJob(final BlackboardJob job, final Token token) throws Exception { |
|
25 |
job.setAction(StatsManagerServiceBBAction.VALIDATE_SHADOW_STATS.action()); |
|
26 |
final String portal = getPortalName(token.getEnv()); |
|
27 |
if (StringUtils.isNotBlank(portal)) { |
|
28 |
job.getParameters().put(StatsManagerServiceBBAction.VALIDATE_SHADOW_STATS.getTargetPortalParamName(), portal); |
|
29 |
} else { |
|
30 |
log.warn(StatsManagerServiceBBAction.VALIDATE_SHADOW_STATS.getTargetPortalParamName() + " not set. The StatsManagerService will use its default."); |
|
31 |
} |
|
32 |
|
|
33 |
} |
|
34 |
|
|
35 |
} |
modules/dnet-wds/trunk/src/main/java/eu/dnetlib/msro/workflows/nodes/stats/PromoteShadowCacheStatsJobNode.java | ||
---|---|---|
1 |
package eu.dnetlib.msro.workflows.nodes.stats; |
|
2 |
|
|
3 |
import eu.dnetlib.enabling.tools.blackboard.BlackboardJob; |
|
4 |
import eu.dnetlib.msro.workflows.procs.Token; |
|
5 |
import org.apache.commons.lang3.StringUtils; |
|
6 |
import org.apache.commons.logging.Log; |
|
7 |
import org.apache.commons.logging.LogFactory; |
|
8 |
|
|
9 |
/** |
|
10 |
* Ask the StatsManagerService to promote the shadow cache so that its entries can be used by the portal specified by the additional BB |
|
11 |
* parameter <code>StatsManagerServiceBBAction.PROMOTE_SHADOW_CACHE.getTargetPortalParamName()</code>. |
|
12 |
* |
|
13 |
* @author alessia |
|
14 |
*/ |
|
15 |
public class PromoteShadowCacheStatsJobNode extends AbstractStatsJobNode { |
|
16 |
|
|
17 |
private static final Log log = LogFactory.getLog(PromoteShadowCacheStatsJobNode.class); // NOPMD by marko on 11/24/08 5:02 PM |
|
18 |
|
|
19 |
@Override |
|
20 |
protected void prepareJob(final BlackboardJob job, final Token token) throws Exception { |
|
21 |
job.setAction(StatsManagerServiceBBAction.PROMOTE_SHADOW_CACHE.action()); |
|
22 |
final String portal = getPortalName(token.getEnv()); |
|
23 |
if (StringUtils.isNotBlank(portal)) { |
|
24 |
job.getParameters().put(StatsManagerServiceBBAction.PROMOTE_SHADOW_CACHE.getTargetPortalParamName(), portal); |
|
25 |
} else { |
|
26 |
log.warn(StatsManagerServiceBBAction.PROMOTE_SHADOW_CACHE.getTargetPortalParamName() + " not set. The StatsManagerService will use its default."); |
|
27 |
} |
|
28 |
} |
|
29 |
|
|
30 |
} |
modules/dnet-wds/trunk/src/main/java/eu/dnetlib/msro/workflows/nodes/stats/FindStatsServiceJobNode.java | ||
---|---|---|
1 |
package eu.dnetlib.msro.workflows.nodes.stats; |
|
2 |
|
|
3 |
import java.util.List; |
|
4 |
import javax.annotation.Resource; |
|
5 |
|
|
6 |
import eu.dnetlib.enabling.locators.UniqueServiceLocator; |
|
7 |
import eu.dnetlib.msro.workflows.nodes.SimpleJobNode; |
|
8 |
import eu.dnetlib.msro.workflows.procs.Env; |
|
9 |
import eu.dnetlib.rmi.enabling.ISLookUpException; |
|
10 |
import eu.dnetlib.rmi.enabling.ISLookUpService; |
|
11 |
import eu.dnetlib.rmi.manager.MSROException; |
|
12 |
import org.apache.commons.logging.Log; |
|
13 |
import org.apache.commons.logging.LogFactory; |
|
14 |
import org.springframework.beans.factory.annotation.Value; |
|
15 |
|
|
16 |
public class FindStatsServiceJobNode extends SimpleJobNode { |
|
17 |
|
|
18 |
/** |
|
19 |
* logger. |
|
20 |
*/ |
|
21 |
private static final Log log = LogFactory.getLog(FindStatsServiceJobNode.class); // NOPMD by marko on 11/24/08 5:02 PM |
|
22 |
|
|
23 |
@Resource |
|
24 |
private UniqueServiceLocator serviceLocator; |
|
25 |
|
|
26 |
@Value(value = "${dnet.openaire.service.stats.lookup.xquery}") |
|
27 |
private String xquery; |
|
28 |
|
|
29 |
private String xqueryForServiceIdParam; |
|
30 |
|
|
31 |
/** |
|
32 |
* {@inheritDoc} |
|
33 |
* |
|
34 |
* @throws ISLookUpException |
|
35 |
* @throws MSROException |
|
36 |
* @see com.googlecode.sarasvati.mem.MemNode#execute(com.googlecode.sarasvati.Engine, com.googlecode.sarasvati.NodeToken) |
|
37 |
*/ |
|
38 |
@Override |
|
39 |
public String execute(final Env env) throws ISLookUpException, MSROException { |
|
40 |
|
|
41 |
log.info("lookup for stats service: " + getXquery()); |
|
42 |
|
|
43 |
final List<String> statsServiceIds = this.serviceLocator.getService(ISLookUpService.class).quickSearchProfile(getXquery()); |
|
44 |
|
|
45 |
if (statsServiceIds.size() > 1) { throw new MSROException("too many stats services: " + statsServiceIds); } |
|
46 |
|
|
47 |
if (statsServiceIds.isEmpty()) { |
|
48 |
return "notFound"; |
|
49 |
} else { |
|
50 |
env.setAttribute(getXqueryForServiceIdParam(), getXquery()); |
|
51 |
return "found"; |
|
52 |
} |
|
53 |
} |
|
54 |
|
|
55 |
public String getXquery() { |
|
56 |
return this.xquery; |
|
57 |
} |
|
58 |
|
|
59 |
public void setXquery(final String xquery) { |
|
60 |
this.xquery = xquery; |
|
61 |
} |
|
62 |
|
|
63 |
public String getXqueryForServiceIdParam() { |
|
64 |
return this.xqueryForServiceIdParam; |
|
65 |
} |
|
66 |
|
|
67 |
public void setXqueryForServiceIdParam(final String xqueryForServiceIdParam) { |
|
68 |
this.xqueryForServiceIdParam = xqueryForServiceIdParam; |
|
69 |
} |
|
70 |
|
|
71 |
} |
modules/dnet-wds/trunk/src/main/java/eu/dnetlib/msro/workflows/nodes/stats/AbstractStatsJobNode.java | ||
---|---|---|
1 |
package eu.dnetlib.msro.workflows.nodes.stats; |
|
2 |
|
|
3 |
import java.util.List; |
|
4 |
|
|
5 |
import eu.dnetlib.msro.workflows.nodes.BlackboardJobNode; |
|
6 |
import eu.dnetlib.msro.workflows.procs.Env; |
|
7 |
import eu.dnetlib.rmi.enabling.ISLookUpException; |
|
8 |
import eu.dnetlib.rmi.enabling.ISLookUpService; |
|
9 |
import org.apache.commons.lang3.StringUtils; |
|
10 |
|
|
11 |
/** |
|
12 |
* Abstract BBJob node for sending BB messages to the StatsManagerService. Subclasses must implement the prepareJob method. |
|
13 |
* |
|
14 |
* @author alessia |
|
15 |
*/ |
|
16 |
public abstract class AbstractStatsJobNode extends BlackboardJobNode { |
|
17 |
|
|
18 |
private String xqueryForServiceIdParam; |
|
19 |
/** |
|
20 |
* BB parameter defining which is the portal affected by the action. Overrides the value in the env parameter below. |
|
21 |
*/ |
|
22 |
private String portal; |
|
23 |
/** |
|
24 |
* Name of the env parameter where to find the target portal value. It is used only if the portal parameter above is not explicitly set |
|
25 |
* in the workflow. |
|
26 |
*/ |
|
27 |
private String portalParam; |
|
28 |
|
|
29 |
@Override |
|
30 |
protected String obtainServiceId(final Env env) { |
|
31 |
final String xquery = env.getAttribute(getXqueryForServiceIdParam(), String.class); |
|
32 |
List<String> statsServiceIds; |
|
33 |
try { |
|
34 |
statsServiceIds = getServiceLocator().getService(ISLookUpService.class).quickSearchProfile(xquery); |
|
35 |
if (statsServiceIds.size() > 1) { throw new RuntimeException("Too many StatsManagerService ids found using query: " + xquery); } |
|
36 |
if (statsServiceIds.size() < 1) { throw new RuntimeException("StatsManagerService id not found using query: " + xquery); } |
|
37 |
return statsServiceIds.get(0); |
|
38 |
} catch (final ISLookUpException e) { |
|
39 |
throw new RuntimeException(e); |
|
40 |
} |
|
41 |
} |
|
42 |
|
|
43 |
public String getPortalName(final Env env) { |
|
44 |
if (StringUtils.isNotBlank(this.portal)) { |
|
45 |
return this.portal; |
|
46 |
} else { |
|
47 |
return env.getAttribute(this.portalParam, String.class); |
|
48 |
} |
|
49 |
} |
|
50 |
|
|
51 |
public String getXqueryForServiceIdParam() { |
|
52 |
return this.xqueryForServiceIdParam; |
|
53 |
} |
|
54 |
|
|
55 |
public void setXqueryForServiceIdParam(final String xqueryForServiceIdParam) { |
|
56 |
this.xqueryForServiceIdParam = xqueryForServiceIdParam; |
|
57 |
} |
|
58 |
|
|
59 |
public String getPortal() { |
|
60 |
return this.portal; |
|
61 |
} |
|
62 |
|
|
63 |
public void setPortal(final String portal) { |
|
64 |
this.portal = portal; |
|
65 |
} |
|
66 |
|
|
67 |
public String getPortalParam() { |
|
68 |
return this.portalParam; |
|
69 |
} |
|
70 |
|
|
71 |
public void setPortalParam(final String portalParam) { |
|
72 |
this.portalParam = portalParam; |
|
73 |
} |
|
74 |
|
|
75 |
} |
modules/dnet-wds/trunk/src/main/java/eu/dnetlib/msro/workflows/nodes/LoadEntityLinksJobNode.java | ||
---|---|---|
1 |
package eu.dnetlib.msro.workflows.nodes; |
|
2 |
|
|
3 |
import eu.dnetlib.msro.workflows.graph.Arc; |
|
4 |
import eu.dnetlib.msro.workflows.nodes.index.EntityGrouperConfigurationLoader; |
|
5 |
import eu.dnetlib.msro.workflows.procs.Env; |
|
6 |
import eu.dnetlib.rmi.manager.MSROException; |
|
7 |
import org.apache.commons.lang3.StringUtils; |
|
8 |
import org.apache.commons.logging.Log; |
|
9 |
import org.apache.commons.logging.LogFactory; |
|
10 |
import org.springframework.beans.factory.annotation.Autowired; |
|
11 |
|
|
12 |
public class LoadEntityLinksJobNode extends SimpleJobNode { |
|
13 |
|
|
14 |
/** |
|
15 |
* logger. |
|
16 |
*/ |
|
17 |
private static final Log log = LogFactory.getLog(LoadEntityLinksJobNode.class); // NOPMD by marko on 11/24/08 5:02 PM |
|
18 |
|
|
19 |
private String entityLinksParam; |
|
20 |
|
|
21 |
@Autowired |
|
22 |
private EntityGrouperConfigurationLoader grouperConfLoader; |
|
23 |
|
|
24 |
@Override |
|
25 |
protected String execute(final Env env) throws Exception { |
|
26 |
|
|
27 |
log.info("loading entity link table"); |
|
28 |
|
|
29 |
final String links = this.grouperConfLoader.load(); |
|
30 |
|
|
31 |
if (StringUtils.isBlank(links)) { throw new MSROException("empty links table"); } |
|
32 |
|
|
33 |
env.setAttribute(getEntityLinksParam(), links); |
|
34 |
|
|
35 |
return Arc.DEFAULT_ARC; |
|
36 |
} |
|
37 |
|
|
38 |
public String getEntityLinksParam() { |
|
39 |
return entityLinksParam; |
|
40 |
} |
|
41 |
|
|
42 |
public void setEntityLinksParam(final String entityLinksParam) { |
|
43 |
this.entityLinksParam = entityLinksParam; |
|
44 |
} |
|
45 |
} |
modules/dnet-wds/trunk/src/main/java/eu/dnetlib/msro/workflows/nodes/ObtainOpenaireDataSourceParamsJobNode.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 |
public class ObtainOpenaireDataSourceParamsJobNode extends SimpleJobNode { |
|
13 |
|
|
14 |
private String providerId; |
|
15 |
|
|
16 |
@Resource |
|
17 |
private UniqueServiceLocator serviceLocator; |
|
18 |
|
|
19 |
@Override |
|
20 |
protected String execute(final Env env) throws Exception { |
|
21 |
final String query = "let $x := /*[.//RESOURCE_IDENTIFIER/@value='" + this.providerId + "']//EXTRA_FIELDS\n" |
|
22 |
+ "return concat($x/FIELD[./key='OpenAireDataSourceId']/value, ' @@@ ', $x/FIELD[./key='NamespacePrefix']/value)"; |
|
23 |
|
|
24 |
final String[] arr = this.serviceLocator.getService(ISLookUpService.class).getResourceProfileByQuery(query).split("@@@"); |
|
25 |
|
|
26 |
final String origId = arr[0].trim(); |
|
27 |
final String nsPrefix = arr[1].trim(); |
|
28 |
// this is needed by the mdbuilder |
|
29 |
// TODO: update mdbuilder to use the env attributes below, whose names are defined in WorkflowConstants |
|
30 |
env.setAttribute("parentDatasourceId", origId); |
|
31 |
env.setAttribute("namespacePrefix", nsPrefix); |
|
32 |
env.setAttribute("dateOfCollection", DateUtils.now_ISO8601()); |
|
33 |
|
|
34 |
// these are needed for validation and fill hostedby |
|
35 |
env.setAttribute(WorkflowsConstants.LOG_DATASOURCE_ID, origId); |
|
36 |
env.setAttribute(WorkflowsConstants.DATASOURCE_PREFIX, nsPrefix); |
|
37 |
|
|
38 |
return Arc.DEFAULT_ARC; |
|
39 |
|
|
40 |
} |
|
41 |
|
|
42 |
public String getProviderId() { |
|
43 |
return this.providerId; |
|
44 |
} |
|
45 |
|
|
46 |
public void setProviderId(final String providerId) { |
|
47 |
this.providerId = providerId; |
|
48 |
} |
|
49 |
|
|
50 |
} |
modules/dnet-wds/trunk/src/main/java/eu/dnetlib/msro/workflows/nodes/utils/CleaningXsltFunctions.java | ||
---|---|---|
1 |
package eu.dnetlib.msro.workflows.nodes.utils; |
|
2 |
|
|
3 |
import java.text.Normalizer; |
|
4 |
|
|
5 |
/** |
|
6 |
* Created by claudio on 14/06/16. |
|
7 |
*/ |
|
8 |
public class CleaningXsltFunctions { |
|
9 |
|
|
10 |
public static String clean(final String s) { |
|
11 |
return Normalizer.normalize(s, Normalizer.Form.NFD) |
|
12 |
.replaceAll("\\(.+\\)", "") |
|
13 |
.replaceAll("(\\W|\\p{InCombiningDiacriticalMarks}|\\p{Punct}|\\n|\\s)+", "") |
|
14 |
.toLowerCase() |
|
15 |
.trim(); |
|
16 |
} |
|
17 |
} |
modules/dnet-wds/trunk/src/main/java/eu/dnetlib/msro/workflows/nodes/utils/Similarity.java | ||
---|---|---|
1 |
package eu.dnetlib.msro.workflows.nodes.utils; |
|
2 |
|
|
3 |
import com.google.gson.Gson; |
|
4 |
import eu.dnetlib.data.proto.TypeProtos.Type; |
|
5 |
import eu.dnetlib.miscutils.collections.Pair; |
|
6 |
|
|
7 |
public class Similarity { |
|
8 |
|
|
9 |
private Pair<String, String> pair; |
|
10 |
private Type type; |
|
11 |
|
|
12 |
public Similarity(final Pair<String, String> pair, final Type type) { |
|
13 |
super(); |
|
14 |
this.setPair(pair); |
|
15 |
this.setType(type); |
|
16 |
} |
|
17 |
|
|
18 |
public Pair<String, String> getPair() { |
|
19 |
return pair; |
|
20 |
} |
|
21 |
|
|
22 |
public void setPair(final Pair<String, String> pair) { |
|
23 |
this.pair = pair; |
|
24 |
} |
|
25 |
|
|
26 |
public Type getType() { |
|
27 |
return type; |
|
28 |
} |
|
29 |
|
|
30 |
public void setType(final Type type) { |
|
31 |
this.type = type; |
|
32 |
} |
|
33 |
|
|
34 |
@Override |
|
35 |
public String toString() { |
|
36 |
return new Gson().toJson(this, Similarity.class); |
|
37 |
} |
|
38 |
} |
modules/dnet-wds/trunk/src/main/java/eu/dnetlib/msro/workflows/nodes/utils/SimilarityMeshBuilder.java | ||
---|---|---|
1 |
package eu.dnetlib.msro.workflows.nodes.utils; |
|
2 |
|
|
3 |
import java.util.List; |
|
4 |
|
|
5 |
import com.google.common.collect.Lists; |
|
6 |
import eu.dnetlib.data.proto.TypeProtos.Type; |
|
7 |
import eu.dnetlib.miscutils.collections.Pair; |
|
8 |
|
|
9 |
public class SimilarityMeshBuilder { |
|
10 |
|
|
11 |
public static List<Similarity> build(final Type type, final List<String> list) { |
|
12 |
|
|
13 |
return build(type, list, true); |
|
14 |
} |
|
15 |
|
|
16 |
public static List<Similarity> build(final Type type, final List<String> list, final boolean addTypePrefix) { |
|
17 |
final String typePrefix = String.valueOf(type.getNumber()); |
|
18 |
final List<Similarity> res = Lists.newArrayList(); |
|
19 |
for (int i = 0; i < list.size(); i++) { |
|
20 |
for (int j = 0; j < list.size(); j++) { |
|
21 |
|
|
22 |
if (!list.get(i).equals(list.get(j))) { |
|
23 |
|
|
24 |
final String source = addTypePrefix ? typePrefix + "|" + list.get(i) : list.get(i); |
|
25 |
final String target = addTypePrefix ? typePrefix + "|" + list.get(j) : list.get(j); |
|
26 |
|
|
27 |
res.add(new Similarity(new Pair<String, String>(source, target), type)); |
|
28 |
} |
|
29 |
} |
|
30 |
} |
|
31 |
return res; |
|
32 |
} |
|
33 |
} |
modules/dnet-wds/trunk/src/main/java/eu/dnetlib/msro/workflows/nodes/dedup/DedupConfigurationSetterJobNode.java | ||
---|---|---|
1 |
package eu.dnetlib.msro.workflows.nodes.dedup; |
|
2 |
|
|
3 |
import eu.dnetlib.msro.workflows.graph.Arc; |
|
4 |
import eu.dnetlib.msro.workflows.nodes.AsyncJobNode; |
|
5 |
import eu.dnetlib.msro.workflows.nodes.dedup.utils.DedupConfigurationOrchestration; |
|
6 |
import eu.dnetlib.msro.workflows.nodes.dedup.utils.DedupConfigurationOrchestrationLoader; |
|
7 |
import eu.dnetlib.msro.workflows.procs.Env; |
|
8 |
import org.apache.commons.lang3.StringUtils; |
|
9 |
import org.springframework.beans.factory.annotation.Autowired; |
|
10 |
|
|
11 |
public class DedupConfigurationSetterJobNode extends AsyncJobNode { |
|
12 |
|
|
13 |
private String dedupConfigSequence; |
|
14 |
|
|
15 |
private String dedupConfigSequenceParam; |
|
16 |
|
|
17 |
private String entityTypeNameParam; |
|
18 |
|
|
19 |
private String entityTypeIdParam; |
|
20 |
|
|
21 |
@Autowired |
|
22 |
private DedupConfigurationOrchestrationLoader dedupOrchestrationLoader; |
|
23 |
|
|
24 |
@Override |
|
25 |
protected String execute(final Env env) throws Exception { |
|
26 |
|
|
27 |
if (StringUtils.isBlank(getDedupConfigSequence())) throw new IllegalArgumentException("missing configuration sequence"); |
|
28 |
|
|
29 |
final DedupConfigurationOrchestration dedupOrchestration = dedupOrchestrationLoader.loadByActionSetId(getDedupConfigSequence()); |
|
30 |
|
|
31 |
env.setAttribute(getEntityTypeNameParam(), dedupOrchestration.getEntity().getName()); |
|
32 |
env.setAttribute(getEntityTypeIdParam(), dedupOrchestration.getEntity().getCode()); |
|
33 |
env.setAttribute(getDedupConfigSequenceParam(), dedupOrchestration); |
|
34 |
|
|
35 |
return Arc.DEFAULT_ARC; |
|
36 |
} |
|
37 |
|
|
38 |
public String getDedupConfigSequence() { |
|
39 |
return dedupConfigSequence; |
|
40 |
} |
|
41 |
|
|
42 |
public void setDedupConfigSequence(final String dedupConfigSequence) { |
|
43 |
this.dedupConfigSequence = dedupConfigSequence; |
|
44 |
} |
|
45 |
|
|
46 |
public String getDedupConfigSequenceParam() { |
|
47 |
return dedupConfigSequenceParam; |
|
48 |
} |
|
49 |
|
|
50 |
public void setDedupConfigSequenceParam(final String dedupConfigSequenceParam) { |
|
51 |
this.dedupConfigSequenceParam = dedupConfigSequenceParam; |
|
52 |
} |
|
53 |
|
|
54 |
public String getEntityTypeNameParam() { |
|
55 |
return entityTypeNameParam; |
|
56 |
} |
|
57 |
|
|
58 |
public void setEntityTypeNameParam(final String entityTypeNameParam) { |
|
59 |
this.entityTypeNameParam = entityTypeNameParam; |
|
60 |
} |
|
61 |
|
|
62 |
public String getEntityTypeIdParam() { |
|
63 |
return entityTypeIdParam; |
|
64 |
} |
|
65 |
|
|
66 |
public void setEntityTypeIdParam(final String entityTypeIdParam) { |
|
67 |
this.entityTypeIdParam = entityTypeIdParam; |
|
68 |
} |
|
69 |
} |
modules/dnet-wds/trunk/src/main/java/eu/dnetlib/msro/workflows/nodes/dedup/DedupConfigurationLoaderJobNode.java | ||
---|---|---|
1 |
package eu.dnetlib.msro.workflows.nodes.dedup; |
|
2 |
|
|
3 |
import eu.dnetlib.enabling.tools.blackboard.BlackboardJob; |
|
4 |
import eu.dnetlib.msro.workflows.nodes.dedup.utils.DedupConfigurationOrchestration; |
|
5 |
import eu.dnetlib.msro.workflows.nodes.dedup.utils.DedupConfigurationOrchestrationLoader; |
|
6 |
import eu.dnetlib.msro.workflows.nodes.hadoop.SubmitHadoopJobNode; |
|
7 |
import eu.dnetlib.msro.workflows.procs.Token; |
|
8 |
import eu.dnetlib.pace.config.DedupConfig; |
|
9 |
import org.apache.commons.logging.Log; |
|
10 |
import org.apache.commons.logging.LogFactory; |
|
11 |
import org.springframework.beans.factory.annotation.Autowired; |
|
12 |
|
|
13 |
import static eu.dnetlib.msro.workflows.nodes.dedup.DedupConfigurationAwareJobNode.DEDUP_CONF; |
|
14 |
|
|
15 |
public class DedupConfigurationLoaderJobNode extends SubmitHadoopJobNode { |
|
16 |
|
|
17 |
private static final Log log = LogFactory.getLog(DedupConfigurationLoaderJobNode.class); |
|
18 |
|
|
19 |
private String dedupConfigSequence; |
|
20 |
|
|
21 |
@Autowired |
|
22 |
private DedupConfigurationOrchestrationLoader dedupOrchestrationLoader; |
|
23 |
|
|
24 |
@Override |
|
25 |
protected void prepareJob(final BlackboardJob job, final Token token) throws Exception { |
|
26 |
super.prepareJob(job, token); |
|
27 |
|
|
28 |
final DedupConfigurationOrchestration dedupOrchestration = dedupOrchestrationLoader.loadByActionSetId(getDedupConfigSequence()); |
|
29 |
final DedupConfig currentConf = dedupOrchestration.getConfigurations().peek(); |
|
30 |
|
|
31 |
log.debug("using dedup configuration: '" + currentConf + "'"); |
|
32 |
|
|
33 |
job.getParameters().put(DEDUP_CONF, currentConf.toString()); |
|
34 |
} |
|
35 |
|
|
36 |
public String getDedupConfigSequence() { |
|
37 |
return dedupConfigSequence; |
|
38 |
} |
|
39 |
|
|
40 |
public void setDedupConfigSequence(final String dedupConfigSequence) { |
|
41 |
this.dedupConfigSequence = dedupConfigSequence; |
|
42 |
} |
|
43 |
|
|
44 |
} |
modules/dnet-wds/trunk/src/main/java/eu/dnetlib/msro/workflows/nodes/dedup/DedupDuplicateScanJobNode.java | ||
---|---|---|
1 |
package eu.dnetlib.msro.workflows.nodes.dedup; |
|
2 |
|
|
3 |
import eu.dnetlib.enabling.tools.blackboard.BlackboardJob; |
|
4 |
import eu.dnetlib.msro.workflows.graph.Arc; |
|
5 |
import eu.dnetlib.msro.workflows.nodes.blackboard.BlackboardWorkflowJobListener; |
|
6 |
import eu.dnetlib.msro.workflows.nodes.dedup.utils.DedupConfigurationOrchestration; |
|
7 |
import eu.dnetlib.msro.workflows.procs.Token; |
|
8 |
import org.apache.commons.collections.CollectionUtils; |
|
9 |
import org.apache.commons.logging.Log; |
|
10 |
import org.apache.commons.logging.LogFactory; |
|
11 |
|
|
12 |
public class DedupDuplicateScanJobNode extends DedupConfigurationAwareJobNode { |
|
13 |
|
|
14 |
private static final Log log = LogFactory.getLog(DedupDuplicateScanJobNode.class); // NOPMD by marko on 11/24/08 5:02 PM |
|
15 |
|
|
16 |
@Override |
|
17 |
protected BlackboardWorkflowJobListener generateBlackboardListener(final Token token) { |
|
18 |
return new DedupBlackboardWorkflowJobListener(token); |
|
19 |
} |
|
20 |
|
|
21 |
private class DedupBlackboardWorkflowJobListener extends BlackboardWorkflowJobListener { |
|
22 |
|
|
23 |
public DedupBlackboardWorkflowJobListener(final Token token) { |
|
24 |
super(token); |
|
25 |
} |
|
26 |
|
|
27 |
@Override |
|
28 |
protected void onDone(final BlackboardJob job) { |
|
29 |
|
|
30 |
final DedupConfigurationOrchestration confs = getDedupConfigurationOrchestration(); |
|
31 |
|
|
32 |
confs.getConfigurations().poll(); |
|
33 |
|
|
34 |
log.info("checking dedup configs queue, size: " + confs.getConfigurations().size()); |
|
35 |
|
|
36 |
if (CollectionUtils.isEmpty(confs.getConfigurations())) { |
|
37 |
log.info("dedup similarity scan done"); |
|
38 |
|
|
39 |
getToken().release("done"); |
|
40 |
} else { |
|
41 |
log.debug("remaining confs: " + confs); |
|
42 |
|
|
43 |
getToken().release(Arc.DEFAULT_ARC); |
|
44 |
} |
|
45 |
} |
|
46 |
} |
|
47 |
|
|
48 |
} |
modules/dnet-wds/trunk/src/main/java/eu/dnetlib/msro/workflows/nodes/dedup/SelectWfPathByDedupEntityJobNode.java | ||
---|---|---|
1 |
package eu.dnetlib.msro.workflows.nodes.dedup; |
|
2 |
|
|
3 |
import eu.dnetlib.msro.workflows.nodes.SimpleJobNode; |
|
4 |
import eu.dnetlib.msro.workflows.nodes.dedup.utils.DedupConfigurationOrchestration; |
|
5 |
import eu.dnetlib.msro.workflows.nodes.dedup.utils.DedupConfigurationOrchestrationLoader; |
|
6 |
import eu.dnetlib.msro.workflows.procs.Env; |
|
7 |
import org.apache.commons.lang3.StringUtils; |
|
8 |
import org.apache.commons.logging.Log; |
|
9 |
import org.apache.commons.logging.LogFactory; |
|
10 |
import org.springframework.beans.factory.annotation.Autowired; |
|
11 |
|
|
12 |
/** |
|
13 |
* Created by claudio on 13/07/16. |
|
14 |
*/ |
|
15 |
public class SelectWfPathByDedupEntityJobNode extends SimpleJobNode { |
|
16 |
|
|
17 |
private static final Log log = LogFactory.getLog(SelectWfPathByDedupEntityJobNode.class); |
|
18 |
|
|
19 |
@Autowired |
|
20 |
private DedupConfigurationOrchestrationLoader dedupOrchestrationLoader; |
|
21 |
|
|
22 |
private String dedupConfigSequence; |
|
23 |
|
|
24 |
@Override |
|
25 |
protected String execute(final Env env) throws Exception { |
|
26 |
|
|
27 |
if (StringUtils.isBlank(getDedupConfigSequence())) throw new IllegalArgumentException("missing configuration sequence"); |
|
28 |
|
|
29 |
final DedupConfigurationOrchestration dedupOrchestration = dedupOrchestrationLoader.loadByActionSetId(getDedupConfigSequence()); |
|
30 |
|
|
31 |
final String entityName = dedupOrchestration.getEntity().getName(); |
|
32 |
|
|
33 |
log.info("following workflow path: " + entityName); |
|
34 |
|
|
35 |
return entityName; |
|
36 |
} |
|
37 |
|
|
38 |
public String getDedupConfigSequence() { |
|
39 |
return dedupConfigSequence; |
|
40 |
} |
|
41 |
|
|
42 |
public void setDedupConfigSequence(final String dedupConfigSequence) { |
|
43 |
this.dedupConfigSequence = dedupConfigSequence; |
|
44 |
} |
|
45 |
|
|
46 |
} |
modules/dnet-wds/trunk/src/main/java/eu/dnetlib/msro/workflows/nodes/dedup/BuildSimilarityMeshJobNode.java | ||
---|---|---|
1 |
package eu.dnetlib.msro.workflows.nodes.dedup; |
|
2 |
|
|
3 |
import java.io.StringReader; |
|
4 |
import java.util.Iterator; |
|
5 |
import java.util.List; |
|
6 |
import java.util.Queue; |
|
7 |
|
|
8 |
import com.google.common.collect.Lists; |
|
9 |
import com.google.common.collect.Queues; |
|
10 |
import eu.dnetlib.data.proto.TypeProtos.Type; |
|
11 |
import eu.dnetlib.enabling.resultset.client.ResultSetClient; |
|
12 |
import eu.dnetlib.enabling.resultset.factory.ResultSetFactory; |
|
13 |
import eu.dnetlib.msro.workflows.graph.Arc; |
|
14 |
import eu.dnetlib.msro.workflows.nodes.AsyncJobNode; |
|
15 |
import eu.dnetlib.msro.workflows.nodes.utils.Similarity; |
|
16 |
import eu.dnetlib.msro.workflows.nodes.utils.SimilarityMeshBuilder; |
|
17 |
import eu.dnetlib.msro.workflows.procs.Env; |
|
18 |
import eu.dnetlib.rmi.common.ResultSet; |
|
19 |
import org.antlr.stringtemplate.StringTemplate; |
|
20 |
import org.apache.commons.logging.Log; |
|
21 |
import org.apache.commons.logging.LogFactory; |
|
22 |
import org.dom4j.Document; |
|
23 |
import org.dom4j.DocumentException; |
|
24 |
import org.dom4j.Node; |
|
25 |
import org.dom4j.io.SAXReader; |
|
26 |
import org.springframework.beans.factory.annotation.Autowired; |
|
27 |
import org.springframework.beans.factory.annotation.Required; |
|
28 |
|
|
29 |
public class BuildSimilarityMeshJobNode extends AsyncJobNode { |
|
30 |
|
|
31 |
private static final Log log = LogFactory.getLog(BuildSimilarityMeshJobNode.class); |
|
32 |
|
|
33 |
/** |
|
34 |
* The result set client factory. |
|
35 |
*/ |
|
36 |
@Autowired |
|
37 |
private ResultSetClient resultSetClient; |
|
38 |
|
|
39 |
@Autowired |
|
40 |
private ResultSetFactory resultSetFactory; |
|
41 |
|
|
42 |
private StringTemplate similarity; |
|
43 |
|
|
44 |
private String inputEprParam; |
|
45 |
|
|
46 |
private String outputEprParam; |
|
47 |
|
|
48 |
@Override |
|
49 |
protected String execute(final Env env) throws Exception { |
|
50 |
|
|
51 |
final ResultSet<?> inputRs = env.getAttribute(getInputEprParam(), ResultSet.class); |
|
52 |
final Iterator<String> it = resultSetClient.iter(inputRs, String.class).iterator(); |
|
53 |
|
|
54 |
final Queue<Object> queue = Queues.newLinkedBlockingQueue(); |
|
55 |
final SAXReader reader = new SAXReader(); |
|
56 |
|
|
57 |
if (it.hasNext()) { |
|
58 |
populateQueue(queue, reader, it.next()); |
|
59 |
} |
|
60 |
|
|
61 |
final ResultSet<String> rsOut = resultSetFactory.createResultSet(() -> { |
|
62 |
return new Iterator<String>() { |
|
63 |
|
|
64 |
@Override |
|
65 |
public boolean hasNext() { |
|
66 |
synchronized (queue) { |
|
67 |
return !queue.isEmpty(); |
|
68 |
} |
|
69 |
} |
|
70 |
|
|
71 |
@Override |
|
72 |
public String next() { |
|
73 |
synchronized (queue) { |
|
74 |
final Object o = queue.poll(); |
|
75 |
while (queue.isEmpty() && it.hasNext()) { |
|
76 |
populateQueue(queue, reader, it.next()); |
|
77 |
} |
|
78 |
return buildSimilarity((Similarity) o); |
|
79 |
} |
|
80 |
} |
|
81 |
|
|
82 |
@Override |
|
83 |
public void remove() { |
|
84 |
throw new UnsupportedOperationException(); |
|
85 |
} |
|
86 |
}; |
|
87 |
}); |
|
88 |
|
|
89 |
env.setAttribute(getOutputEprParam(), rsOut); |
|
90 |
|
|
91 |
return Arc.DEFAULT_ARC; |
|
92 |
} |
|
93 |
|
|
94 |
private void populateQueue(final Queue<Object> q, final SAXReader r, final String xml) { |
|
95 |
try { |
|
96 |
final Document d = r.read(new StringReader(xml)); |
|
97 |
final String groupid = d.valueOf("//FIELD[@name='id']"); |
|
98 |
final List<?> items = d.selectNodes("//FIELD[@name='group']/ITEM"); |
|
99 |
final String entitytype = d.valueOf("//FIELD[@name='entitytype']"); |
|
100 |
final List<String> group = Lists.newArrayList(); |
Also available in: Unified diff
New implementation of WDS