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