1
|
package eu.dnetlib.functionality.modular.ui.workflows.objects.sections;
|
2
|
|
3
|
import java.util.List;
|
4
|
import java.util.Set;
|
5
|
|
6
|
import com.google.common.collect.Sets;
|
7
|
import eu.dnetlib.functionality.modular.ui.workflows.objects.WorkflowItem;
|
8
|
import eu.dnetlib.functionality.modular.ui.workflows.util.ISLookupClient;
|
9
|
import eu.dnetlib.miscutils.datetime.DateUtils;
|
10
|
import org.springframework.beans.factory.annotation.Autowired;
|
11
|
|
12
|
public class WorkflowSectionGrouper {
|
13
|
|
14
|
private static final long CACHE_DURATION = 600000; // 10 minutes
|
15
|
private Set<String> cache = Sets.newHashSet();
|
16
|
private long cacheDate = 0;
|
17
|
@Autowired
|
18
|
private ISLookupClient isLookupClient;
|
19
|
|
20
|
public List<WorkflowItem> listWorflowsForDatasource(String dsId) {
|
21
|
return isLookupClient.listWorflowsForDatasource(dsId);
|
22
|
}
|
23
|
|
24
|
public List<WorkflowItem> listWorflowsForSection(String name) {
|
25
|
return isLookupClient.listWorflowsForSection(name);
|
26
|
}
|
27
|
|
28
|
public String getDatasourceName(String dsId) {
|
29
|
return isLookupClient.getDatasourceName(dsId);
|
30
|
}
|
31
|
|
32
|
public Set<String> getAllSectionNames() {
|
33
|
synchronized (cache) {
|
34
|
if (cache.isEmpty() || DateUtils.now() - cacheDate > CACHE_DURATION) {
|
35
|
cache.clear();
|
36
|
cache.addAll(isLookupClient.listSimpleWorflowSections());
|
37
|
cacheDate = DateUtils.now();
|
38
|
}
|
39
|
}
|
40
|
|
41
|
final Set<String> res = Sets.newHashSet(cache);
|
42
|
|
43
|
res.remove("datasources");
|
44
|
|
45
|
return res;
|
46
|
}
|
47
|
|
48
|
}
|