1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
|
/**
* Copyright (c) 2017-2018 ZTE Corporation.
* All rights reserved. This program and the accompanying materials
* are made available under the Apache License, Version 2.0
* and the Eclipse Public License v1.0 which both accompany this distribution,
* and are available at http://www.eclipse.org/legal/epl-v10.html
* and http://www.apache.org/licenses/LICENSE-2.0
*
* Contributors:
* ZTE - initial API and implementation and/or initial documentation
*/
package org.onap.sdc.workflowdesigner;
//import org.glassfish.jersey.media.multipart.MultiPartFeature;
import org.onap.sdc.workflowdesigner.config.AdapterType;
import org.onap.sdc.workflowdesigner.config.AppConfig;
import org.onap.sdc.workflowdesigner.resources.ExtendActivityResource;
import org.onap.sdc.workflowdesigner.resources.WorkflowModelerResource;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.fasterxml.jackson.annotation.JsonInclude;
import io.dropwizard.Application;
import io.dropwizard.assets.AssetsBundle;
import io.dropwizard.server.SimpleServerFactory;
import io.dropwizard.setup.Bootstrap;
import io.dropwizard.setup.Environment;
import io.swagger.jaxrs.config.BeanConfig;
import io.swagger.jaxrs.listing.ApiListingResource;
public class WorkflowDesignerApp extends Application<WorkflowDesignerConfiguration> {
private static final Logger LOGGER = LoggerFactory.getLogger(WorkflowDesignerApp.class);
public static void main(String[] args) throws Exception {
new WorkflowDesignerApp().run(args);
}
@Override
public String getName() {
return "Workflow Designer";
}
@Override
public void initialize(Bootstrap<WorkflowDesignerConfiguration> bootstrap) {
bootstrap.addBundle(new AssetsBundle("/api-doc", "/api-doc", "index.html", "api-doc"));
bootstrap.addBundle(new AssetsBundle("/workflow-modeler", "/workflow-modeler", "index.html",
"workflow-modeler"));
bootstrap.addBundle(new AssetsBundle("/workflow-modeler", "/", "index.html", "ng"));
}
@Override
public void run(WorkflowDesignerConfiguration configuration, Environment environment) {
LOGGER.info("Start to initialize Workflow Designer.");
saveAppConfig(configuration);
environment.jersey().register(new WorkflowModelerResource());
environment.jersey().register(new ExtendActivityResource());
// register rest interface
environment.jersey().packages("org.onap.sdc.workflowdesigner.resources");
// // upload file by inputstream need to register MultiPartFeature
// environment.jersey().register(MultiPartFeature.class);
initSwaggerConfig(environment, configuration);
LOGGER.info("Initialize catalogue finished.");
}
/**
* @param configuration
*/
private void saveAppConfig(WorkflowDesignerConfiguration configuration) {
AppConfig.setAdapterType(AdapterType.valueOf(configuration.getAdapterType()));
AppConfig.setSdcServiceProxy(configuration.getSdcServiceProxy());
}
/**
* initialize swagger configuration.
*
* @param environment environment information
* @param configuration catalogue configuration
*/
private void initSwaggerConfig(Environment environment,
WorkflowDesignerConfiguration configuration) {
environment.jersey().register(new ApiListingResource());
environment.getObjectMapper().setSerializationInclusion(JsonInclude.Include.NON_NULL);
BeanConfig config = new BeanConfig();
config.setTitle("Workflow Designer rest API");
config.setVersion("1.0.0");
config.setResourcePackage("org.onap.sdc.workflowdesigner.resources");
// set rest api basepath in swagger
SimpleServerFactory simpleServerFactory =
(SimpleServerFactory) configuration.getServerFactory();
String basePath = simpleServerFactory.getApplicationContextPath();
String rootPath = simpleServerFactory.getJerseyRootPath().get();
rootPath = rootPath.substring(0, rootPath.indexOf("/*"));
basePath = basePath.equals("/") ? rootPath
: (new StringBuilder()).append(basePath).append(rootPath).toString();
config.setBasePath(basePath);
config.setScan(true);
}
}
|