1
|
package eu.dnetlib.parthenos.workflows.nodes;
|
2
|
|
3
|
import java.nio.file.Files;
|
4
|
import java.nio.file.Path;
|
5
|
import java.nio.file.Paths;
|
6
|
import java.util.List;
|
7
|
|
8
|
import eu.dnetlib.clients.enabling.ISLookUpClient;
|
9
|
import eu.dnetlib.enabling.locators.UniqueServiceLocator;
|
10
|
import eu.dnetlib.msro.workflows.graph.Arc;
|
11
|
import eu.dnetlib.msro.workflows.nodes.AsyncJobNode;
|
12
|
import eu.dnetlib.msro.workflows.procs.Env;
|
13
|
import eu.dnetlib.msro.workflows.util.WorkflowsConstants;
|
14
|
import eu.dnetlib.rmi.datasource.DatasourceManagerService;
|
15
|
import org.apache.commons.logging.Log;
|
16
|
import org.apache.commons.logging.LogFactory;
|
17
|
import org.springframework.beans.factory.annotation.Autowired;
|
18
|
|
19
|
/**
|
20
|
* Created by Alessia Bardi on 12/01/2018.
|
21
|
*
|
22
|
* @author Alessia Bardi
|
23
|
*/
|
24
|
public class ClarinAPIGeneratorJobNode extends AsyncJobNode {
|
25
|
|
26
|
private static final Log log = LogFactory.getLog(ClarinAPIGeneratorJobNode.class);
|
27
|
|
28
|
/** Path to a local folder containing the subfolders with Clarin mapping files **/
|
29
|
private String folderPath;
|
30
|
/** Path to a local folder containing the subfolders with Clarin input files **/
|
31
|
private String inputBaseUrlPrefix;
|
32
|
|
33
|
private String metadataIdentifierPath;
|
34
|
|
35
|
private String clarinDatasourceProfileID;
|
36
|
private String clarinDatasourceOriginalId;
|
37
|
|
38
|
@Autowired
|
39
|
private UniqueServiceLocator serviceLocator;
|
40
|
@Autowired
|
41
|
private ISLookUpClient isLookupClient;
|
42
|
|
43
|
|
44
|
@Override
|
45
|
protected String execute(final Env env) throws Exception {
|
46
|
Path folder = Paths.get(getFolderPath());
|
47
|
if (!Files.isDirectory(folder)){
|
48
|
throw new IllegalArgumentException(getFolderPath()+" must be a directory");
|
49
|
}
|
50
|
final DatasourceManagerService dsMan = getServiceLocator().getService(DatasourceManagerService.class);
|
51
|
|
52
|
List<String> apiIds = getIsLookupClient().search("//RESOURCE_PROFILE[./HEADER/RESOURCE_IDENTIFIER/@value='"+getClarinDatasourceProfileID()+"']//INTERFACE/@id/string()");
|
53
|
|
54
|
ClarinFileVisitor visitor = new ClarinFileVisitor(getClarinDatasourceProfileID(), getClarinDatasourceOriginalId(),
|
55
|
getInputBaseUrlPrefix(), getMetadataIdentifierPath(), apiIds, getServiceLocator(), getIsLookupClient());
|
56
|
Files.walkFileTree(folder, visitor);
|
57
|
|
58
|
env.setAttribute(WorkflowsConstants.MAIN_LOG_PREFIX +"visitedFiles", visitor.getCountVisitedFiles());
|
59
|
env.setAttribute(WorkflowsConstants.MAIN_LOG_PREFIX +"createdTDS", visitor.getCountCreatedTDS());
|
60
|
env.setAttribute(WorkflowsConstants.MAIN_LOG_PREFIX +"updatedTDS", visitor.getCountUpdatedTDS());
|
61
|
env.setAttribute(WorkflowsConstants.MAIN_LOG_PREFIX +"visitedFolders", visitor.getCountVisitedFolders());
|
62
|
env.setAttribute(WorkflowsConstants.MAIN_LOG_PREFIX +"createdInterfaces", visitor.getCountCreatedInterfaces());
|
63
|
return Arc.DEFAULT_ARC;
|
64
|
|
65
|
}
|
66
|
|
67
|
public String getFolderPath() {
|
68
|
return folderPath;
|
69
|
}
|
70
|
|
71
|
public void setFolderPath(final String folderPath) {
|
72
|
this.folderPath = folderPath;
|
73
|
}
|
74
|
|
75
|
public String getInputBaseUrlPrefix() {
|
76
|
return inputBaseUrlPrefix;
|
77
|
}
|
78
|
|
79
|
public void setInputBaseUrlPrefix(final String inputBaseUrlPrefix) {
|
80
|
this.inputBaseUrlPrefix = inputBaseUrlPrefix;
|
81
|
}
|
82
|
|
83
|
public String getMetadataIdentifierPath() {
|
84
|
return metadataIdentifierPath;
|
85
|
}
|
86
|
|
87
|
public void setMetadataIdentifierPath(final String metadataIdentifierPath) {
|
88
|
this.metadataIdentifierPath = metadataIdentifierPath;
|
89
|
}
|
90
|
|
91
|
public String getClarinDatasourceProfileID() {
|
92
|
return clarinDatasourceProfileID;
|
93
|
}
|
94
|
|
95
|
public void setClarinDatasourceProfileID(final String clarinDatasourceProfileID) {
|
96
|
this.clarinDatasourceProfileID = clarinDatasourceProfileID;
|
97
|
}
|
98
|
|
99
|
public String getClarinDatasourceOriginalId() {
|
100
|
return clarinDatasourceOriginalId;
|
101
|
}
|
102
|
|
103
|
public void setClarinDatasourceOriginalId(final String clarinDatasourceOriginalId) {
|
104
|
this.clarinDatasourceOriginalId = clarinDatasourceOriginalId;
|
105
|
}
|
106
|
|
107
|
public UniqueServiceLocator getServiceLocator() {
|
108
|
return serviceLocator;
|
109
|
}
|
110
|
|
111
|
public void setServiceLocator(final UniqueServiceLocator serviceLocator) {
|
112
|
this.serviceLocator = serviceLocator;
|
113
|
}
|
114
|
|
115
|
public ISLookUpClient getIsLookupClient() {
|
116
|
return isLookupClient;
|
117
|
}
|
118
|
|
119
|
public void setIsLookupClient(final ISLookUpClient isLookupClient) {
|
120
|
this.isLookupClient = isLookupClient;
|
121
|
}
|
122
|
}
|