Revision 45853
Added by Michele Artini almost 8 years ago
modules/dnet-springboot-apps/trunk/dnet-simple-aggregation-worker/src/main/java/eu/dnetlib/msro/workers/controller/MsroWorkerController.java | ||
---|---|---|
1 |
package eu.dnetlib.msro.workers.controller; |
|
2 |
|
|
3 |
import java.util.Arrays; |
|
4 |
import java.util.List; |
|
5 |
|
|
6 |
import org.apache.commons.lang3.StringUtils; |
|
7 |
import org.dom4j.DocumentHelper; |
|
8 |
import org.dom4j.Element; |
|
9 |
import org.springframework.beans.BeansException; |
|
10 |
import org.springframework.context.ApplicationContext; |
|
11 |
import org.springframework.context.ApplicationContextAware; |
|
12 |
import org.springframework.web.bind.annotation.RequestMapping; |
|
13 |
import org.springframework.web.bind.annotation.RestController; |
|
14 |
|
|
15 |
import eu.dnetlib.enabling.annotations.DnetService; |
|
16 |
import eu.dnetlib.enabling.annotations.DnetServiceType; |
|
17 |
import eu.dnetlib.msro.annotations.ProcessNode; |
|
18 |
import eu.dnetlib.msro.workers.aggregation.collect.plugins.CollectorPlugin; |
|
19 |
import eu.dnetlib.msro.workers.aggregation.collect.plugins.DnetCollectorParam; |
|
20 |
import eu.dnetlib.msro.workers.aggregation.collect.plugins.DnetCollectorPlugin; |
|
21 |
import eu.dnetlib.msro.workers.aggregation.collect.plugins.ProtocolParameterType; |
|
22 |
import eu.dnetlib.msro.workflows.nodes.AbstractProcessNode; |
|
23 |
import eu.dnetlib.services.BaseService; |
|
24 |
|
|
25 |
@RestController |
|
26 |
@RequestMapping("/worker") |
|
27 |
@DnetService(DnetServiceType.msroWorker) |
|
28 |
public class MsroWorkerController extends BaseService implements ApplicationContextAware { |
|
29 |
|
|
30 |
private ApplicationContext applicationContext; |
|
31 |
|
|
32 |
@Override |
|
33 |
public void setApplicationContext(final ApplicationContext applicationContext) throws BeansException { |
|
34 |
this.applicationContext = applicationContext; |
|
35 |
} |
|
36 |
|
|
37 |
@Override |
|
38 |
public List<Element> geXmlProfileSections() { |
|
39 |
final Element nodes = DocumentHelper.createElement("WORKFLOW_NODES"); |
|
40 |
applicationContext.getBeansOfType(AbstractProcessNode.class) |
|
41 |
.values() |
|
42 |
.stream() |
|
43 |
.map(Object::getClass) |
|
44 |
.filter(cl -> cl.isAnnotationPresent(ProcessNode.class)) |
|
45 |
.forEach(cl -> { |
|
46 |
final Element n = nodes.addElement("NODE"); |
|
47 |
n.addAttribute("type", cl.getAnnotation(ProcessNode.class).value()); |
|
48 |
n.addAttribute("class", cl.getName()); |
|
49 |
}); |
|
50 |
|
|
51 |
final Element collPlugins = DocumentHelper.createElement("COLLECTOR_PLUGINS"); |
|
52 |
applicationContext.getBeansOfType(CollectorPlugin.class) |
|
53 |
.values() |
|
54 |
.stream() |
|
55 |
.map(Object::getClass) |
|
56 |
.filter(cl -> cl.isAnnotationPresent(DnetCollectorPlugin.class)) |
|
57 |
.map(cl -> cl.getAnnotation(DnetCollectorPlugin.class)) |
|
58 |
.forEach(ann -> { |
|
59 |
final Element plugin = collPlugins.addElement("PLUGIN"); |
|
60 |
plugin.addAttribute("protocol", ann.value()); |
|
61 |
for (final DnetCollectorParam ap : ann.parameters()) { |
|
62 |
final Element p = plugin.addElement("PARAM"); |
|
63 |
p.addAttribute("name", ap.value()); |
|
64 |
p.addAttribute("type", ap.type().toString()); |
|
65 |
p.addAttribute("optional", Boolean.toString(ap.optional())); |
|
66 |
if (StringUtils.isNotBlank(ap.regex()) && (ap.type() == ProtocolParameterType.TEXT)) { |
|
67 |
p.addAttribute("regex", ap.regex()); |
|
68 |
} |
|
69 |
} |
|
70 |
}); |
|
71 |
|
|
72 |
return Arrays.asList(nodes, collPlugins); |
|
73 |
} |
|
74 |
} |
modules/dnet-springboot-apps/trunk/dnet-is-application/src/main/java/eu/dnetlib/enabling/app/MainConfiguration.java | ||
---|---|---|
3 | 3 |
import org.springframework.context.annotation.Bean; |
4 | 4 |
import org.springframework.context.annotation.Configuration; |
5 | 5 |
|
6 |
import springfox.documentation.builders.PathSelectors; |
|
7 |
import springfox.documentation.builders.RequestHandlerSelectors; |
|
8 |
import springfox.documentation.spi.DocumentationType; |
|
6 |
import eu.dnetlib.services.ApiDocUtils; |
|
9 | 7 |
import springfox.documentation.spring.web.plugins.Docket; |
10 | 8 |
|
11 | 9 |
@Configuration |
... | ... | |
13 | 11 |
|
14 | 12 |
@Bean |
15 | 13 |
public Docket api() { |
16 |
return new Docket(DocumentationType.SWAGGER_2) |
|
17 |
.select() |
|
18 |
.apis(RequestHandlerSelectors.any()) |
|
19 |
.paths(PathSelectors.any()) |
|
20 |
.build(); |
|
14 |
return ApiDocUtils.newSwaggerDocket(); |
|
21 | 15 |
} |
22 | 16 |
} |
modules/dnet-springboot-apps/trunk/pom.xml | ||
---|---|---|
6 | 6 |
<parent> |
7 | 7 |
<groupId>org.springframework.boot</groupId> |
8 | 8 |
<artifactId>spring-boot-starter-parent</artifactId> |
9 |
<version>1.4.3.RELEASE</version>
|
|
9 |
<version>1.4.4.RELEASE</version>
|
|
10 | 10 |
</parent> |
11 | 11 |
|
12 | 12 |
<artifactId>dnet-springboot-apps</artifactId> |
modules/dnet-springboot-apps/trunk/dnet-simple-aggregation-worker/src/main/java/eu/dnetlib/msro/WorkerConfiguration.java | ||
---|---|---|
1 | 1 |
package eu.dnetlib.msro; |
2 | 2 |
|
3 |
import org.springframework.context.annotation.Bean; |
|
3 | 4 |
import org.springframework.context.annotation.Configuration; |
4 | 5 |
|
6 |
import eu.dnetlib.services.ApiDocUtils; |
|
7 |
import springfox.documentation.spring.web.plugins.Docket; |
|
8 |
|
|
5 | 9 |
@Configuration |
6 | 10 |
public class WorkerConfiguration { |
7 | 11 |
|
12 |
@Bean |
|
13 |
public Docket api() { |
|
14 |
return ApiDocUtils.newSwaggerDocket(); |
|
15 |
} |
|
8 | 16 |
} |
modules/dnet-springboot-apps/trunk/dnet-simple-aggregation-worker/src/main/java/eu/dnetlib/msro/controllers/CollectorController.java | ||
---|---|---|
1 |
package eu.dnetlib.msro.controllers; |
|
2 |
|
|
3 |
import java.util.List; |
|
4 |
import java.util.stream.Collectors; |
|
5 |
|
|
6 |
import org.springframework.beans.factory.annotation.Autowired; |
|
7 |
import org.springframework.web.bind.annotation.RequestMapping; |
|
8 |
import org.springframework.web.bind.annotation.RequestMethod; |
|
9 |
import org.springframework.web.bind.annotation.RestController; |
|
10 |
|
|
11 |
import eu.dnetlib.msro.workers.aggregation.collect.CollectorPluginEnumerator; |
|
12 |
import eu.dnetlib.msro.workers.aggregation.collect.plugins.CollectorPlugin; |
|
13 |
|
|
14 |
@RestController |
|
15 |
@RequestMapping(value = "/collector", method = RequestMethod.GET) |
|
16 |
public class CollectorController { |
|
17 |
|
|
18 |
@Autowired |
|
19 |
private CollectorPluginEnumerator plugins; |
|
20 |
|
|
21 |
@RequestMapping("plugins") |
|
22 |
private List<String> plugins() { |
|
23 |
return plugins.getAll().stream().map(CollectorPlugin::getProtocol).sorted().collect(Collectors.toList()); |
|
24 |
} |
|
25 |
|
|
26 |
} |
modules/dnet-springboot-apps/trunk/dnet-simple-aggregation-worker/src/main/java/eu/dnetlib/msro/controllers/MsroWorkerController.java | ||
---|---|---|
1 |
package eu.dnetlib.msro.controllers; |
|
2 |
|
|
3 |
import java.util.Arrays; |
|
4 |
import java.util.List; |
|
5 |
|
|
6 |
import org.apache.commons.lang3.StringUtils; |
|
7 |
import org.dom4j.DocumentHelper; |
|
8 |
import org.dom4j.Element; |
|
9 |
import org.springframework.beans.BeansException; |
|
10 |
import org.springframework.context.ApplicationContext; |
|
11 |
import org.springframework.context.ApplicationContextAware; |
|
12 |
import org.springframework.web.bind.annotation.RequestMapping; |
|
13 |
import org.springframework.web.bind.annotation.RestController; |
|
14 |
|
|
15 |
import eu.dnetlib.enabling.annotations.DnetService; |
|
16 |
import eu.dnetlib.enabling.annotations.DnetServiceType; |
|
17 |
import eu.dnetlib.msro.annotations.ProcessNode; |
|
18 |
import eu.dnetlib.msro.workers.aggregation.collect.plugins.CollectorPlugin; |
|
19 |
import eu.dnetlib.msro.workers.aggregation.collect.plugins.DnetCollectorParam; |
|
20 |
import eu.dnetlib.msro.workers.aggregation.collect.plugins.DnetCollectorPlugin; |
|
21 |
import eu.dnetlib.msro.workers.aggregation.collect.plugins.ProtocolParameterType; |
|
22 |
import eu.dnetlib.msro.workflows.nodes.AbstractProcessNode; |
|
23 |
import eu.dnetlib.services.BaseService; |
|
24 |
|
|
25 |
@RestController |
|
26 |
@RequestMapping("/worker") |
|
27 |
@DnetService(DnetServiceType.msroWorker) |
|
28 |
public class MsroWorkerController extends BaseService implements ApplicationContextAware { |
|
29 |
|
|
30 |
private ApplicationContext applicationContext; |
|
31 |
|
|
32 |
@Override |
|
33 |
public void setApplicationContext(final ApplicationContext applicationContext) throws BeansException { |
|
34 |
this.applicationContext = applicationContext; |
|
35 |
} |
|
36 |
|
|
37 |
@Override |
|
38 |
public List<Element> geXmlProfileSections() { |
|
39 |
final Element nodes = DocumentHelper.createElement("WORKFLOW_NODES"); |
|
40 |
final Element collPlugins = DocumentHelper.createElement("COLLECTOR_PLUGINS"); |
|
41 |
|
|
42 |
applicationContext.getBeansOfType(AbstractProcessNode.class) |
|
43 |
.values() |
|
44 |
.stream() |
|
45 |
.map(Object::getClass) |
|
46 |
.filter(cl -> cl.isAnnotationPresent(ProcessNode.class)) |
|
47 |
.forEach(cl -> { |
|
48 |
final Element n = nodes.addElement("NODE"); |
|
49 |
n.addAttribute("type", cl.getAnnotation(ProcessNode.class).value()); |
|
50 |
n.addAttribute("class", cl.getName()); |
|
51 |
}); |
|
52 |
|
|
53 |
applicationContext.getBeansOfType(CollectorPlugin.class) |
|
54 |
.values() |
|
55 |
.stream() |
|
56 |
.map(Object::getClass) |
|
57 |
.filter(cl -> cl.isAnnotationPresent(DnetCollectorPlugin.class)) |
|
58 |
.map(cl -> cl.getAnnotation(DnetCollectorPlugin.class)) |
|
59 |
.forEach(ann -> { |
|
60 |
final Element plugin = collPlugins.addElement("PLUGIN"); |
|
61 |
plugin.addAttribute("protocol", ann.value()); |
|
62 |
for (final DnetCollectorParam ap : ann.parameters()) { |
|
63 |
final Element p = plugin.addElement("PARAM"); |
|
64 |
p.addAttribute("name", ap.value()); |
|
65 |
p.addAttribute("type", ap.type().toString()); |
|
66 |
p.addAttribute("optional", Boolean.toString(ap.optional())); |
|
67 |
if (StringUtils.isNotBlank(ap.regex()) && (ap.type() == ProtocolParameterType.TEXT)) { |
|
68 |
p.addAttribute("regex", ap.regex()); |
|
69 |
} |
|
70 |
} |
|
71 |
}); |
|
72 |
|
|
73 |
return Arrays.asList(nodes, collPlugins); |
|
74 |
} |
|
75 |
} |
modules/dnet-springboot-apps/trunk/dnet-simple-aggregation-worker/src/main/java/eu/dnetlib/msro/DnetSimpleAggregationWorkerApplication.java | ||
---|---|---|
5 | 5 |
import org.springframework.context.annotation.ComponentScan; |
6 | 6 |
import org.springframework.scheduling.annotation.EnableScheduling; |
7 | 7 |
|
8 |
import springfox.documentation.swagger2.annotations.EnableSwagger2; |
|
9 |
|
|
8 | 10 |
@SpringBootApplication |
9 | 11 |
@ComponentScan("eu.dnetlib") |
10 | 12 |
@EnableScheduling |
13 |
@EnableSwagger2 |
|
11 | 14 |
public class DnetSimpleAggregationWorkerApplication { |
12 | 15 |
|
13 | 16 |
public static void main(final String[] args) { |
modules/dnet-springboot-apps/trunk/dnet-simple-aggregation-worker/src/main/java/eu/dnetlib/msro/workers/aggregation/collect/CollectorPluginEnumerator.java | ||
---|---|---|
7 | 7 |
import org.springframework.beans.factory.BeanFactory; |
8 | 8 |
import org.springframework.beans.factory.BeanFactoryAware; |
9 | 9 |
import org.springframework.beans.factory.ListableBeanFactory; |
10 |
import org.springframework.web.bind.annotation.RequestMapping; |
|
11 |
import org.springframework.web.bind.annotation.RestController; |
|
10 |
import org.springframework.stereotype.Component; |
|
12 | 11 |
|
13 | 12 |
import eu.dnetlib.msro.workers.aggregation.collect.plugins.CollectorPlugin; |
14 | 13 |
import eu.dnetlib.msro.workers.aggregation.collect.plugins.DnetCollectorPlugin; |
15 | 14 |
|
16 |
@RestController |
|
17 |
@RequestMapping("/collector") |
|
15 |
@Component |
|
18 | 16 |
public class CollectorPluginEnumerator implements BeanFactoryAware { |
19 | 17 |
|
20 | 18 |
// private static final Log log = LogFactory.getLog(CollectorPluginEnumerator.class); // NOPMD by marko on 11/24/08 5:02 PM |
... | ... | |
29 | 27 |
* |
30 | 28 |
* @return |
31 | 29 |
*/ |
32 |
@RequestMapping("/plugins") |
|
33 | 30 |
public List<CollectorPlugin> getAll() { |
34 | 31 |
return beanFactory.getBeansOfType(CollectorPlugin.class) |
35 | 32 |
.values() |
modules/dnet-springboot-apps/trunk/dnet-common-utils/src/main/java/eu/dnetlib/services/ApiDocUtils.java | ||
---|---|---|
1 |
package eu.dnetlib.services; |
|
2 |
|
|
3 |
import springfox.documentation.builders.RequestHandlerSelectors; |
|
4 |
import springfox.documentation.spi.DocumentationType; |
|
5 |
import springfox.documentation.spring.web.plugins.Docket; |
|
6 |
|
|
7 |
public class ApiDocUtils { |
|
8 |
|
|
9 |
public static Docket newSwaggerDocket() { |
|
10 |
return new Docket(DocumentationType.SWAGGER_2) |
|
11 |
.select() |
|
12 |
.apis(RequestHandlerSelectors.any()) |
|
13 |
.paths(p -> !(p.equals("/") || p.startsWith("/error"))) |
|
14 |
.build(); |
|
15 |
} |
|
16 |
} |
modules/dnet-springboot-apps/trunk/dnet-common-utils/src/main/java/eu/dnetlib/services/ApiDocController.java | ||
---|---|---|
1 |
package eu.dnetlib.services; |
|
2 |
|
|
3 |
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; |
|
4 |
import org.springframework.stereotype.Controller; |
|
5 |
import org.springframework.web.bind.annotation.RequestMapping; |
|
6 |
import org.springframework.web.bind.annotation.RequestMethod; |
|
7 |
|
|
8 |
import springfox.documentation.spring.web.plugins.Docket; |
|
9 |
|
|
10 |
@Controller |
|
11 |
@ConditionalOnBean(Docket.class) |
|
12 |
public class ApiDocController { |
|
13 |
|
|
14 |
@RequestMapping(value = "/", method = RequestMethod.GET) |
|
15 |
public String redirect() { |
|
16 |
return "redirect:swagger-ui.html"; |
|
17 |
} |
|
18 |
|
|
19 |
} |
modules/dnet-springboot-apps/trunk/dnet-common-utils/src/main/java/eu/dnetlib/services/BaseService.java | ||
---|---|---|
17 | 17 |
import org.springframework.beans.factory.annotation.Autowired; |
18 | 18 |
import org.springframework.context.Lifecycle; |
19 | 19 |
import org.springframework.web.bind.annotation.RequestMapping; |
20 |
import org.springframework.web.bind.annotation.RequestMethod; |
|
20 | 21 |
import org.springframework.web.bind.annotation.RestController; |
21 | 22 |
|
22 | 23 |
import eu.dnetlib.conf.DnetGenericApplicationProperties; |
... | ... | |
87 | 88 |
log.info("Stopping service " + this); |
88 | 89 |
} |
89 | 90 |
|
90 |
@RequestMapping("")
|
|
91 |
@RequestMapping(value = "", method = RequestMethod.GET)
|
|
91 | 92 |
public ServiceRunningInstance identify() { |
92 | 93 |
final File f = new File(containerConfiguration.getBaseDir()); |
93 | 94 |
final Runtime runtime = Runtime.getRuntime(); |
modules/dnet-springboot-apps/trunk/dnet-common-utils/src/main/java/eu/dnetlib/services/HCMController.java | ||
---|---|---|
29 | 29 |
import org.springframework.core.io.ResourceLoader; |
30 | 30 |
import org.springframework.core.io.support.ResourcePatternUtils; |
31 | 31 |
import org.springframework.web.bind.annotation.RequestMapping; |
32 |
import org.springframework.web.bind.annotation.RequestMethod; |
|
32 | 33 |
import org.springframework.web.bind.annotation.RestController; |
33 | 34 |
|
34 | 35 |
import com.google.common.collect.Maps; |
... | ... | |
41 | 42 |
import eu.dnetlib.miscutils.streams.DnetStreamSupport; |
42 | 43 |
|
43 | 44 |
@RestController |
44 |
@RequestMapping("/hcm")
|
|
45 |
@RequestMapping(value = "/hcm", method = RequestMethod.GET)
|
|
45 | 46 |
@DnetService(DnetServiceType.hcm) |
46 | 47 |
public class HCMController extends BaseService implements ResourceLoaderAware { |
47 | 48 |
|
modules/dnet-springboot-apps/trunk/dnet-common-utils/pom.xml | ||
---|---|---|
39 | 39 |
<groupId>org.springframework</groupId> |
40 | 40 |
<artifactId>spring-webmvc</artifactId> |
41 | 41 |
<version>4.2.5.RELEASE</version> |
42 |
<scope>provided</scope> |
|
42 | 43 |
</dependency> |
43 | 44 |
<dependency> |
44 | 45 |
<groupId>org.springframework</groupId> |
45 | 46 |
<artifactId>spring-context</artifactId> |
46 | 47 |
<version>4.2.5.RELEASE</version> |
48 |
<scope>provided</scope> |
|
47 | 49 |
</dependency> |
48 | 50 |
<dependency> |
49 | 51 |
<groupId>org.springframework</groupId> |
50 | 52 |
<artifactId>spring-beans</artifactId> |
51 | 53 |
<version>4.2.5.RELEASE</version> |
54 |
<scope>provided</scope> |
|
52 | 55 |
</dependency> |
53 | 56 |
<dependency> |
57 |
<groupId>org.springframework.boot</groupId> |
|
58 |
<artifactId>spring-boot-autoconfigure</artifactId> |
|
59 |
<version>1.4.4.RELEASE</version> |
|
60 |
<scope>provided</scope> |
|
61 |
</dependency> |
|
62 |
<dependency> |
|
54 | 63 |
<groupId>org.springframework</groupId> |
55 | 64 |
<artifactId>spring-context-support</artifactId> |
56 | 65 |
<version>4.2.5.RELEASE</version> |
Also available in: Unified diff
swagger