diff options
author | talasila <talasila@research.att.com> | 2017-02-08 10:13:29 -0500 |
---|---|---|
committer | talasila <talasila@research.att.com> | 2017-02-08 10:15:00 -0500 |
commit | f8a8d5192b1e5013d9e2f699be54b072ef39d5f0 (patch) | |
tree | b7a65bb0a7d70a9dc24c064113868e5f3b8e6a09 /dcae_dmaapbc_webapp/src/main/java/org/openecomp/fusionapp | |
parent | 72a80fbff7120630576ccd5aa67c20818c2943c7 (diff) |
Initial OpenECOMP UI/DMaapBC commit
Change-Id: Ia492e1b88311b9bed4c31f593b28deaaad73b7e4
Signed-off-by: talasila <talasila@research.att.com>
Diffstat (limited to 'dcae_dmaapbc_webapp/src/main/java/org/openecomp/fusionapp')
19 files changed, 1482 insertions, 0 deletions
diff --git a/dcae_dmaapbc_webapp/src/main/java/org/openecomp/fusionapp/conf/ExternalAppConfig.java b/dcae_dmaapbc_webapp/src/main/java/org/openecomp/fusionapp/conf/ExternalAppConfig.java new file mode 100644 index 0000000..fc0a54a --- /dev/null +++ b/dcae_dmaapbc_webapp/src/main/java/org/openecomp/fusionapp/conf/ExternalAppConfig.java @@ -0,0 +1,203 @@ +/*- + * ================================================================================ + * DCAE DMaaP Bus Controller Web Application + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ================================================================================ + */ +package org.openecomp.fusionapp.conf; + +import java.util.ArrayList; +import java.util.List; + +import javax.annotation.PostConstruct; + +import org.openecomp.fusionapp.uebhandler.InitUebHandler; +import org.openecomp.fusionapp.uebhandler.MainUebHandler; +import org.openecomp.fusionapp.uebhandler.WidgetNotificationHandler; +import org.openecomp.portalsdk.core.conf.AppConfig; +import org.openecomp.portalsdk.core.conf.Configurable; +import org.openecomp.portalsdk.core.logging.logic.EELFLoggerDelegate; +import org.openecomp.portalsdk.core.objectcache.AbstractCacheManager; +import org.openecomp.portalsdk.core.service.DataAccessService; +import org.openecomp.portalsdk.core.util.CacheManager; +import org.openecomp.portalsdk.core.util.SystemProperties; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.Import; +import org.springframework.context.annotation.Profile; +import org.springframework.context.annotation.PropertySource; +import org.springframework.scheduling.annotation.EnableAsync; +import org.springframework.scheduling.annotation.EnableScheduling; +import org.springframework.web.servlet.ViewResolver; +import org.springframework.web.servlet.config.annotation.EnableWebMvc; +import org.springframework.web.servlet.config.annotation.InterceptorRegistry; +import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry; + +/** + * Configures Spring features in the DMaaP Bus Control web application. + * Subclasses the ECOMP Portal SDK core AppConfig class to reuse interceptors, + * view resolvers and other features defined there. + */ +@Configuration +@EnableWebMvc +@ComponentScan(basePackages = { "org.openecomp" } ) +@PropertySource(value = { "${container.classpath:}/WEB-INF/conf/app/test.properties" }, ignoreResourceNotFound = true) +@Profile("src") +@EnableAsync +@EnableScheduling +public class ExternalAppConfig extends AppConfig implements Configurable { + + EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(ExternalAppConfig.class); + + // private RegistryAdapter schedulerRegistryAdapter; + + @Configuration + @Import(SystemProperties.class) + static class InnerConfiguration { + } + + /** + * @see org.openecomp.portalsdk.core.conf.AppConfig#viewResolver() + */ + public ViewResolver viewResolver() { + return super.viewResolver(); + } + + /** + * @see org.openecomp.portalsdk.core.conf.AppConfig#addResourceHandlers(ResourceHandlerRegistry) + * + * @param registry + */ + public void addResourceHandlers(ResourceHandlerRegistry registry) { + super.addResourceHandlers(registry); + } + + /** + * @see org.openecomp.portalsdk.core.conf.AppConfig#dataAccessService() + */ + public DataAccessService dataAccessService() { + return super.dataAccessService(); + } + + /** + * Creates a new list with entries that are external app + * definitions.xml paths. + * + * @return List of String + */ + public List<String> addTileDefinitions() { + List<String> definitions = new ArrayList<String>(); + definitions.add("/WEB-INF/defs/definitions.xml"); + definitions.add("/WEB-INF/dbcapp/dbcapp-definitions.xml"); + if (logger.isDebugEnabled()) + logger.debug(EELFLoggerDelegate.debugLogger, "addTileDefinitions: list is " + definitions); + return definitions; + } + + /** + * Adds request interceptors to the specified registry by calling + * {@link AppConfig#addInterceptors(InterceptorRegistry)}, but excludes + * certain paths from the session timeout interceptor. + */ + @Override + public void addInterceptors(InterceptorRegistry registry) { + super.setExcludeUrlPathsForSessionTimeout("/login_external", "*/login_external.htm", "login", "/login.htm", + "/api*","/single_signon.htm","/single_signon"); + super.addInterceptors(registry); + } + + /** + * Creates and returns a new instance of a {@link CacheManager} class. + * + * @return New instance of {@link CacheManager} + */ + @Bean + public AbstractCacheManager cacheManager() { + return new CacheManager(); + } + + @PostConstruct + public void initGlobalLocalContext() { + // logger.init(); + } + + + /** + * Creates and returns a new instance of a {@link MainUebHandler}. + * + * @return New instance of {@link MainUebHandler}. + */ + @Bean + public MainUebHandler mainUebHandler() { + + return new MainUebHandler(); + } + + /** + * Creates and returns a new instance of a {@link InitUebHandler}. + * + * @return New instance of {@link InitUebHandler}. + */ + @Bean + public InitUebHandler initUebHandler() { + + return new InitUebHandler(); + } + + /** + * Creates and returns a new instance of a {@link WidgetNotificationHandler} + * . + * + * @return New instance of {@link WidgetNotificationHandler}. + */ + @Bean + public WidgetNotificationHandler widgetNotificationHandler() { + return new WidgetNotificationHandler(); + } + + /** + * Creates and returns a new instance of a {@link SchedulerFactoryBean} and + * populates it with triggers. + * + * @return New instance of {@link SchedulerFactoryBean} + * @throws Exception + */ + // APPLICATIONS REQUIRING QUARTZ SHOULD RESTORE ANNOTATION + /* + @Bean // ANNOTATION COMMENTED OUT + public SchedulerFactoryBean schedulerFactoryBean() throws Exception { + SchedulerFactoryBean scheduler = new SchedulerFactoryBean(); + scheduler.setTriggers(schedulerRegistryAdapter.getTriggers()); + scheduler.setConfigLocation(appApplicationContext.getResource("WEB-INF/conf/quartz.properties")); + scheduler.setDataSource(dataSource()); + return scheduler; + } + */ + + + /** + * Sets the scheduler registry adapter. + * + * @param schedulerRegistryAdapter + */ + /* + @Autowired + public void setSchedulerRegistryAdapter(final RegistryAdapter schedulerRegistryAdapter) { + this.schedulerRegistryAdapter = schedulerRegistryAdapter; + } + */ +} diff --git a/dcae_dmaapbc_webapp/src/main/java/org/openecomp/fusionapp/conf/ExternalAppInitializer.java b/dcae_dmaapbc_webapp/src/main/java/org/openecomp/fusionapp/conf/ExternalAppInitializer.java new file mode 100644 index 0000000..f9d5065 --- /dev/null +++ b/dcae_dmaapbc_webapp/src/main/java/org/openecomp/fusionapp/conf/ExternalAppInitializer.java @@ -0,0 +1,60 @@ +/*- + * ================================================================================ + * DCAE DMaaP Bus Controller Web Application + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ================================================================================ + */ +package org.openecomp.fusionapp.conf; + +import java.util.Arrays; + +import org.openecomp.portalsdk.core.conf.AppInitializer; + +public class ExternalAppInitializer extends AppInitializer{ + + + @Override + protected Class<?>[] getRootConfigClasses() { + return super.getRootConfigClasses(); + } + + @Override + protected Class<?>[] getServletConfigClasses() { +// Class<?>[] configClasses = super.getServletConfigClasses(); +// Class<?>[] additionalConfigClasses = Arrays.copyOf(configClasses, configClasses.length); +// addConfigClass(additionalConfigClasses, ExternalAppConfig.class); +// return additionalConfigClasses; +// + return new Class[] {ExternalAppConfig.class}; + } + + static Class<?>[] addConfigClass(Class<?>[] a, Class<?> e) { + a = Arrays.copyOf(a, a.length + 1); + a[a.length - 1] = e; + return a; + } + + /* + * URL request will direct to the Spring dispatcher for processing + */ + @Override + protected String[] getServletMappings() { + return super.getServletMappings(); + } + +} + + diff --git a/dcae_dmaapbc_webapp/src/main/java/org/openecomp/fusionapp/conf/HibernateMappingLocations.java b/dcae_dmaapbc_webapp/src/main/java/org/openecomp/fusionapp/conf/HibernateMappingLocations.java new file mode 100644 index 0000000..bac61a6 --- /dev/null +++ b/dcae_dmaapbc_webapp/src/main/java/org/openecomp/fusionapp/conf/HibernateMappingLocations.java @@ -0,0 +1,45 @@ +/*- + * ================================================================================ + * DCAE DMaaP Bus Controller Web Application + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ================================================================================ + */ +package org.openecomp.fusionapp.conf; + +import org.openecomp.portalsdk.core.conf.HibernateMappingLocatable; +import org.springframework.context.annotation.Profile; +import org.springframework.core.io.ClassPathResource; +import org.springframework.core.io.Resource; +import org.springframework.stereotype.Component; + +@Component +@Profile("src") +public class HibernateMappingLocations implements HibernateMappingLocatable { + + public Resource[] getMappingLocations() { + return new Resource[] { + // Path is relative to WEB-INF/conf; + // a leading slash gets stripped so don't bother. + new ClassPathResource("../fusion/orm/Fusion.hbm.xml"), + // DBC does not use workflow nor RCloud + // new ClassPathResource("../fusion/orm/Workflow.hbm.xml"), + // new ClassPathResource("../fusion/orm/RNoteBookIntegration.hbm.xml"), + new ClassPathResource("../dbcapp/dbcapp.hbm.xml") + }; + } + + +} diff --git a/dcae_dmaapbc_webapp/src/main/java/org/openecomp/fusionapp/controller/AngularSinglePageController.java b/dcae_dmaapbc_webapp/src/main/java/org/openecomp/fusionapp/controller/AngularSinglePageController.java new file mode 100644 index 0000000..2a4c6d5 --- /dev/null +++ b/dcae_dmaapbc_webapp/src/main/java/org/openecomp/fusionapp/controller/AngularSinglePageController.java @@ -0,0 +1,48 @@ +/*- + * ================================================================================ + * DCAE DMaaP Bus Controller Web Application + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ================================================================================ + */ +package org.openecomp.fusionapp.controller; + +import java.util.HashMap; +import java.util.Map; + +import javax.servlet.http.HttpServletRequest; + +import org.openecomp.portalsdk.core.controller.RestrictedBaseController; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.servlet.ModelAndView; + +/** + * Controller for a single-page application sample. The view is restricted to + * authenticated users. The named view resolves to page singlePageSample.html, + * which uses Angular. + */ +@Controller +@RequestMapping("/") +public class AngularSinglePageController extends RestrictedBaseController { + + @RequestMapping(value = { "/singlePageSample" }, method = RequestMethod.GET) + public ModelAndView view(HttpServletRequest request) { + Map<String, Object> model = new HashMap<String, Object>(); + return new ModelAndView("single_page_sample", "model", model); + } + +} diff --git a/dcae_dmaapbc_webapp/src/main/java/org/openecomp/fusionapp/controller/CallflowController.java b/dcae_dmaapbc_webapp/src/main/java/org/openecomp/fusionapp/controller/CallflowController.java new file mode 100644 index 0000000..371284c --- /dev/null +++ b/dcae_dmaapbc_webapp/src/main/java/org/openecomp/fusionapp/controller/CallflowController.java @@ -0,0 +1,44 @@ +/*- + * ================================================================================ + * DCAE DMaaP Bus Controller Web Application + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ================================================================================ + */ +package org.openecomp.fusionapp.controller; + +import org.openecomp.portalsdk.core.controller.RestrictedBaseController; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.servlet.ModelAndView; + +/** + * Controller for a message sequence chart view. The view is restricted to + * authenticated users. The view name defaults to the request name with no + * suffix, "callflow", which resolves to page details.jsp. That page is an + * iframe around page details.html. + */ +@Controller +@RequestMapping("/") +public class CallflowController extends RestrictedBaseController { + + @RequestMapping(value = { "/callflow" }, method = RequestMethod.GET) + public ModelAndView plot() { + final String defaultViewName = null; + return new ModelAndView(defaultViewName); + } + +} diff --git a/dcae_dmaapbc_webapp/src/main/java/org/openecomp/fusionapp/controller/ElasticSearchController.java b/dcae_dmaapbc_webapp/src/main/java/org/openecomp/fusionapp/controller/ElasticSearchController.java new file mode 100644 index 0000000..5b59aa9 --- /dev/null +++ b/dcae_dmaapbc_webapp/src/main/java/org/openecomp/fusionapp/controller/ElasticSearchController.java @@ -0,0 +1,128 @@ +/*- + * ================================================================================ + * DCAE DMaaP Bus Controller Web Application + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ================================================================================ + */ +package org.openecomp.fusionapp.controller; + +import java.io.IOException; + +import org.json.JSONObject; +import org.openecomp.fusionapp.model.Result; +import org.openecomp.portalsdk.core.controller.RestrictedBaseController; +import org.springframework.http.HttpStatus; +import org.springframework.http.MediaType; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.servlet.ModelAndView; + +import io.searchbox.client.JestClient; +import io.searchbox.client.JestClientFactory; +import io.searchbox.client.config.HttpClientConfig; +import io.searchbox.core.Search; +import io.searchbox.core.SearchResult; +import io.searchbox.core.Suggest; +import io.searchbox.core.SuggestResult; +import io.searchbox.params.Parameters; + +/** + * Controller for views that demonstrate Elastic Search features. + */ +@RestController +public class ElasticSearchController extends RestrictedBaseController{ + + @RequestMapping(value = {"/es_search_demo" }, method = RequestMethod.GET) + public ModelAndView search() { + return new ModelAndView("es_search_demo"); + } + + @RequestMapping(value = {"/es_suggest_demo" }, method = RequestMethod.GET) + public ModelAndView suggest() { + return new ModelAndView("es_suggest_demo"); + } + + @RequestMapping(value="/es_suggest/{task}",method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE) + public ResponseEntity<Result> doSuggest(@PathVariable("task") String task) throws IOException { + JSONObject obj = new JSONObject(task); + String searchTerm = obj.getString("data"); + String searchSize = obj.getString("size"); + String searchFuzzy = obj.getString("fuzzy"); + String resultName = obj.getString("resultname"); + + JestClientFactory factory = new JestClientFactory(); + factory.setHttpClientConfig(new HttpClientConfig + .Builder("http://host:9200") + .multiThreaded(true) + .build()); + JestClient client = factory.getObject(); + + + Suggest suggest = new Suggest.Builder("{\n" + +"\"" + resultName +"\" : {\n" + +"\"text\" : \""+ searchTerm +"\",\n" + +"\"completion\" : {\n" + +"\"field\" : \"suggest\",\n" + +"\"size\" : " + searchSize + ",\n" + +"\"fuzzy\" : \"" + searchFuzzy + "\"\n" + +"}\n" + +"}\n" + +"}").addIndex("customer").build(); + + SuggestResult result = client.execute(suggest); + System.err.println(result.getJsonObject().toString()); + return new ResponseEntity<Result>(new Result(result.getJsonObject().toString()),HttpStatus.OK); + } + + @RequestMapping(value="/es_search/{task}",method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE) + public ResponseEntity<Result> doSearch(@PathVariable("task") String task) throws IOException { + JSONObject obj = new JSONObject(task); + String searchTerm = obj.getString("data"); + String searchSize = obj.getString("size"); + // String searchFuzzy = obj.getString("fuzzy"); + + JestClientFactory factory = new JestClientFactory(); + factory.setHttpClientConfig(new HttpClientConfig + .Builder("http://host:9200") + .multiThreaded(true) + .build()); + JestClient client = factory.getObject(); + + Search search = new Search.Builder("{\n" + +"\"query\" : {\n" + +"\"query_string\" : {\n" + +"\"query\" : \"name:"+ searchTerm +"\"\n" + +"}\n" + +"}\n" + +"}").addIndex("customer").setParameter(Parameters.SIZE,Integer.valueOf(searchSize)).build(); + + SearchResult result = client.execute(search); + System.err.println(result.getJsonObject().toString()); + return new ResponseEntity<Result>(new Result(result.getJsonObject().toString()),HttpStatus.OK); + } + + public ResponseEntity<Result> sendResult(Result result) { + return new ResponseEntity<Result>(result, HttpStatus.OK); + } + + @Override + public boolean isRESTfulCall() { + return true; + } +} diff --git a/dcae_dmaapbc_webapp/src/main/java/org/openecomp/fusionapp/controller/LeafletMapContoller.java b/dcae_dmaapbc_webapp/src/main/java/org/openecomp/fusionapp/controller/LeafletMapContoller.java new file mode 100644 index 0000000..3c461be --- /dev/null +++ b/dcae_dmaapbc_webapp/src/main/java/org/openecomp/fusionapp/controller/LeafletMapContoller.java @@ -0,0 +1,43 @@ +/*- + * ================================================================================ + * DCAE DMaaP Bus Controller Web Application + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ================================================================================ + */ +package org.openecomp.fusionapp.controller; + +import org.openecomp.portalsdk.core.controller.RestrictedBaseController; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.servlet.ModelAndView; + +/** + * Controller for geographic map view. The view is restricted to authenticated + * users. The view name defaults to the request name with no suffix, + * "leafletMap", which resolves to page leafletMap.jsp. + */ +@Controller +@RequestMapping("/") +public class LeafletMapContoller extends RestrictedBaseController { + + @RequestMapping(value = { "/leafletMap" }, method = RequestMethod.GET) + public ModelAndView plot() { + final String defaultViewName = null; + return new ModelAndView(defaultViewName); + } + +} diff --git a/dcae_dmaapbc_webapp/src/main/java/org/openecomp/fusionapp/controller/NetMapController.java b/dcae_dmaapbc_webapp/src/main/java/org/openecomp/fusionapp/controller/NetMapController.java new file mode 100644 index 0000000..fedd95f --- /dev/null +++ b/dcae_dmaapbc_webapp/src/main/java/org/openecomp/fusionapp/controller/NetMapController.java @@ -0,0 +1,57 @@ +/*- + * ================================================================================ + * DCAE DMaaP Bus Controller Web Application + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ================================================================================ + */ +package org.openecomp.fusionapp.controller; + +import java.util.HashMap; +import java.util.Map; + +import javax.servlet.http.HttpServletRequest; + +import org.openecomp.portalsdk.core.controller.RestrictedBaseController; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.servlet.ModelAndView; + +/** + * Controller for a network map view that uses iframes. The view is restricted + * to authenticated users. + */ +@Controller +@RequestMapping("/") +public class NetMapController extends RestrictedBaseController { + + @RequestMapping(value = { "/net_map" }, method = RequestMethod.GET) + public ModelAndView plot(HttpServletRequest request) { + Map<String, Object> model = new HashMap<String, Object>(); + model.put("frame_int", "net_map_int"); + // This view resolves to page frame_insert.jsp + return new ModelAndView("frame_insert", model); + } + + @RequestMapping(value = { "/net_map_int" }, method = RequestMethod.GET) + public ModelAndView plot2() { + // The view name defaults to the request without any suffix. + final String defaultViewName = null; + // This view resolves to page net_map.jsp + return new ModelAndView(defaultViewName); + } + +} diff --git a/dcae_dmaapbc_webapp/src/main/java/org/openecomp/fusionapp/controller/PostDroolsController.java b/dcae_dmaapbc_webapp/src/main/java/org/openecomp/fusionapp/controller/PostDroolsController.java new file mode 100644 index 0000000..0fd902e --- /dev/null +++ b/dcae_dmaapbc_webapp/src/main/java/org/openecomp/fusionapp/controller/PostDroolsController.java @@ -0,0 +1,138 @@ +/*- + * ================================================================================ + * DCAE DMaaP Bus Controller Web Application + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ================================================================================ + */ +package org.openecomp.fusionapp.controller; + +import java.io.IOException; +import java.io.PrintWriter; +import java.util.List; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.json.JSONObject; +import org.openecomp.portalsdk.core.command.PostDroolsBean; +import org.openecomp.portalsdk.core.controller.RestrictedBaseController; +import org.openecomp.portalsdk.core.service.PostDroolsService; +import org.openecomp.portalsdk.core.web.support.JsonMessage; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.servlet.ModelAndView; + +import com.fasterxml.jackson.core.JsonGenerationException; +import com.fasterxml.jackson.databind.DeserializationFeature; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; + +@Controller +@RequestMapping("/") +public class PostDroolsController extends RestrictedBaseController{ + + @Autowired + private PostDroolsService postDroolsService; + + @RequestMapping(value = {"/drools" }, method = RequestMethod.GET) + public ModelAndView drools(HttpServletRequest request) { + + return new ModelAndView(getViewName()); + } + + + @RequestMapping(value = {"/getDrools" }, method = RequestMethod.GET) + public void getDrools(HttpServletRequest request, HttpServletResponse response) { + // Map<String, Object> model = new HashMap<String, Object>(); + + ObjectMapper mapper = new ObjectMapper(); + try { + List<PostDroolsBean> beanList = postDroolsService.fetchDroolBeans(); + JsonMessage msg = new JsonMessage(mapper.writeValueAsString(beanList)); + JSONObject j = new JSONObject(msg); + response.getWriter().write(j.toString()); + + } catch (JsonGenerationException e) { + e.printStackTrace(); + } catch (JsonMappingException e) { + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + } catch (Exception e) { + e.printStackTrace(); + } + } + + @RequestMapping(value = {"/getDroolDetails" }, method = RequestMethod.GET) + public void getDroolDetails(HttpServletRequest request, HttpServletResponse response) { + + ObjectMapper mapper = new ObjectMapper(); + try { + + PostDroolsBean postDroolsBean = new PostDroolsBean(); + String selectedFile = request.getParameter("selectedFile"); + postDroolsBean.setDroolsFile(selectedFile);//sample populated + //postDroolsBean.setSelectedRules("[\"NJ\",\"NY\",\"KY\"]"); + postDroolsBean.setClassName(postDroolsService.retrieveClass(selectedFile)); + + JsonMessage msg = new JsonMessage(mapper.writeValueAsString(postDroolsBean)); + JSONObject j = new JSONObject(msg); + response.getWriter().write(j.toString()); + + } catch (JsonGenerationException e) { + e.printStackTrace(); + } catch (JsonMappingException e) { + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + } catch (Exception e) { + e.printStackTrace(); + } + } + + @RequestMapping(value = {"/post_drools/execute" }, method = RequestMethod.POST) + public ModelAndView search(HttpServletRequest request, + HttpServletResponse response) throws Exception { + try { + ObjectMapper mapper = new ObjectMapper(); + mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + JsonNode root = mapper.readTree(request.getReader()); + PostDroolsBean postDroolsBean = mapper.readValue(root.get("postDroolsBean").toString(), PostDroolsBean.class); + + String resultsString = postDroolsService.execute(postDroolsBean.getDroolsFile(), postDroolsBean.getClassName(), postDroolsBean.getSelectedRules()); + + response.setCharacterEncoding("UTF-8"); + response.setContentType("application / json"); + request.setCharacterEncoding("UTF-8"); + + PrintWriter out = response.getWriter(); + //String responseString = mapper.writeValueAsString(resultsString); + JSONObject j = new JSONObject("{resultsString: "+resultsString+"}"); + + out.write(j.toString()); + } catch (Exception e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + return null; + } + + +} diff --git a/dcae_dmaapbc_webapp/src/main/java/org/openecomp/fusionapp/controller/UserProfileController.java b/dcae_dmaapbc_webapp/src/main/java/org/openecomp/fusionapp/controller/UserProfileController.java new file mode 100644 index 0000000..cf5feb8 --- /dev/null +++ b/dcae_dmaapbc_webapp/src/main/java/org/openecomp/fusionapp/controller/UserProfileController.java @@ -0,0 +1,73 @@ +/*- + * ================================================================================ + * DCAE DMaaP Bus Controller Web Application + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ================================================================================ + */ +package org.openecomp.fusionapp.controller; + +import java.io.IOException; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import javax.servlet.http.HttpServletRequest; + +import org.openecomp.portalsdk.core.controller.RestrictedBaseController; +import org.openecomp.portalsdk.core.domain.Profile; +import org.openecomp.portalsdk.core.service.ProfileService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.servlet.ModelAndView; + +import com.fasterxml.jackson.core.JsonGenerationException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; + +/** + * Controller for user profile view. The view is restricted to authenticated + * users. The view name resolves to page user_profile.jsp which uses Angular. + */ + +@Controller +@RequestMapping("/") +public class UserProfileController extends RestrictedBaseController { + + @Autowired + ProfileService service; + + @RequestMapping(value = { "/user_profile" }, method = RequestMethod.GET) + public ModelAndView ProfileSearch(HttpServletRequest request) { + Map<String, Object> model = new HashMap<String, Object>(); + ObjectMapper mapper = new ObjectMapper(); + List<Profile> profileList = service.findAll(); + try { + model.put("customerInfo", mapper.writeValueAsString(profileList)); + } catch (JsonGenerationException e) { + e.printStackTrace(); + } catch (JsonMappingException e) { + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + } + + return new ModelAndView("user_profile", "model", model); + } + +} + diff --git a/dcae_dmaapbc_webapp/src/main/java/org/openecomp/fusionapp/controller/WelcomeController.java b/dcae_dmaapbc_webapp/src/main/java/org/openecomp/fusionapp/controller/WelcomeController.java new file mode 100644 index 0000000..510d154 --- /dev/null +++ b/dcae_dmaapbc_webapp/src/main/java/org/openecomp/fusionapp/controller/WelcomeController.java @@ -0,0 +1,44 @@ +/*- + * ================================================================================ + * DCAE DMaaP Bus Controller Web Application + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ================================================================================ + */ +package org.openecomp.fusionapp.controller; + +import javax.servlet.http.HttpServletRequest; + +import org.openecomp.portalsdk.core.controller.RestrictedBaseController; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.servlet.ModelAndView; + +/** + * Controller for welcome view. The view is restricted to authenticated users. + * If no view name is provided, the view name defaults to the request name with + * no suffix, "welcome", which is resolved by consulting a definitions.xml file. + */ +@Controller +@RequestMapping("/") +public class WelcomeController extends RestrictedBaseController { + @RequestMapping(value = { "/welcome" }, method = RequestMethod.GET) + public ModelAndView welcome(HttpServletRequest request) { + // The ECOMP SDK controller process_csp always redirects + // to welcome.htm, so map it to something useful. + return new ModelAndView("dbc_home_tdkey"); + } +} diff --git a/dcae_dmaapbc_webapp/src/main/java/org/openecomp/fusionapp/model/Result.java b/dcae_dmaapbc_webapp/src/main/java/org/openecomp/fusionapp/model/Result.java new file mode 100644 index 0000000..9dfd546 --- /dev/null +++ b/dcae_dmaapbc_webapp/src/main/java/org/openecomp/fusionapp/model/Result.java @@ -0,0 +1,37 @@ +/*- + * ================================================================================ + * DCAE DMaaP Bus Controller Web Application + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ================================================================================ + */ +package org.openecomp.fusionapp.model; + +public class Result { + private String result; + + public Result(String result) { + this.result = result; + } + + public String getResult() { + return result; + } + + public void setResult(String result) { + this.result = result; + } + +} diff --git a/dcae_dmaapbc_webapp/src/main/java/org/openecomp/fusionapp/service/AdminAuthExtension.java b/dcae_dmaapbc_webapp/src/main/java/org/openecomp/fusionapp/service/AdminAuthExtension.java new file mode 100644 index 0000000..d6e5193 --- /dev/null +++ b/dcae_dmaapbc_webapp/src/main/java/org/openecomp/fusionapp/service/AdminAuthExtension.java @@ -0,0 +1,34 @@ +/*- + * ================================================================================ + * DCAE DMaaP Bus Controller Web Application + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ================================================================================ + */ +package org.openecomp.fusionapp.service; + +import org.openecomp.portalsdk.core.domain.User; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +@Service("adminAuthExtension") +@Transactional +public class AdminAuthExtension { + + public void saveUserExtension(User user){ + //app's developer implement their own logic here, like updating app's related tables + } + +} diff --git a/dcae_dmaapbc_webapp/src/main/java/org/openecomp/fusionapp/uebhandler/InitUebHandler.java b/dcae_dmaapbc_webapp/src/main/java/org/openecomp/fusionapp/uebhandler/InitUebHandler.java new file mode 100644 index 0000000..1b50693 --- /dev/null +++ b/dcae_dmaapbc_webapp/src/main/java/org/openecomp/fusionapp/uebhandler/InitUebHandler.java @@ -0,0 +1,73 @@ +/*- + * ================================================================================ + * DCAE DMaaP Bus Controller Web Application + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ================================================================================ + */ +package org.openecomp.fusionapp.uebhandler; + +import java.util.concurrent.ConcurrentLinkedQueue; + +import javax.annotation.PostConstruct; + +import org.openecomp.portalsdk.core.logging.format.AlarmSeverityEnum; +import org.openecomp.portalsdk.core.logging.logic.EELFLoggerDelegate; +import org.openecomp.portalsdk.core.onboarding.crossapi.PortalApiConstants; +import org.openecomp.portalsdk.core.onboarding.crossapi.PortalApiProperties; +import org.openecomp.portalsdk.core.onboarding.ueb.UebManager; +import org.openecomp.portalsdk.core.onboarding.ueb.UebMsg; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.Configuration; + +// +// Adding this class for the sole purpose of insuring that the MainUebHandler really +// honors @Async and kicks off a thread. For more info google @Async and read about +// @Async only working if called from different class. +// +@Configuration +public class InitUebHandler { + + EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(InitUebHandler.class); + + + @Autowired + MainUebHandler mainUebHandler; + + public InitUebHandler() { + + } + + @PostConstruct + public void initUeb() { + + try { + String enableListenerThread = PortalApiProperties.getProperty(PortalApiConstants.UEB_LISTENERS_ENABLE); + if (enableListenerThread.equalsIgnoreCase("true")) { + ConcurrentLinkedQueue<UebMsg> inboxQueue = new ConcurrentLinkedQueue<UebMsg>(); + UebManager.getInstance().initListener(inboxQueue); + mainUebHandler.runHandler(inboxQueue); + logger.info(EELFLoggerDelegate.debugLogger, ("Returned from initiating mainUebHandler...")); + } + else { + logger.info(EELFLoggerDelegate.debugLogger, ("Not starting UEB listening thread because ueb_listeners_enable is not set to true in the properties file.")); + } + } + catch (Exception e) { + logger.error(EELFLoggerDelegate.debugLogger, ("Not starting UEB listening thread because property could not be read " + PortalApiConstants.UEB_LISTENERS_ENABLE),AlarmSeverityEnum.MAJOR); + } + + } +} diff --git a/dcae_dmaapbc_webapp/src/main/java/org/openecomp/fusionapp/uebhandler/MainUebHandler.java b/dcae_dmaapbc_webapp/src/main/java/org/openecomp/fusionapp/uebhandler/MainUebHandler.java new file mode 100644 index 0000000..604880b --- /dev/null +++ b/dcae_dmaapbc_webapp/src/main/java/org/openecomp/fusionapp/uebhandler/MainUebHandler.java @@ -0,0 +1,104 @@ +/*- + * ================================================================================ + * DCAE DMaaP Bus Controller Web Application + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ================================================================================ + */ +package org.openecomp.fusionapp.uebhandler; + +import java.util.concurrent.ConcurrentLinkedQueue; + +import org.openecomp.portalsdk.core.logging.logic.EELFLoggerDelegate; +import org.openecomp.portalsdk.core.onboarding.ueb.UebMsg; +import org.openecomp.portalsdk.core.onboarding.ueb.UebMsgTypes; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.scheduling.annotation.Async; +import org.springframework.stereotype.Component; + +//------------------------------------------------------------------------- +// Listens for received UEB messages and handles the messages +// +// Note: To implement a synchronous reply call getMsgId on the request +// and putMsgId on the reply (echoing the request MsgId). +// +//------------------------------------------------------------------------- +@Component("MainUebHandler") +public class MainUebHandler { + + EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(MainUebHandler.class); + + + ConcurrentLinkedQueue<UebMsg> inboxQueue = null; + + @Autowired + WidgetNotificationHandler widgetNotificationHandler; + + @Async + public void runHandler(ConcurrentLinkedQueue<UebMsg> queue) { + inboxQueue = queue; + + logger.info(EELFLoggerDelegate.debugLogger, ("==> MainUebHandler started")); + + while (true) { + UebMsg msg = null; + while ((msg = inboxQueue.poll()) != null) { + if (msg.getMsgType() != null) { + logger.debug(EELFLoggerDelegate.debugLogger, ("<== Received UEB message : " + msg.toString())); + + switch (msg.getMsgType()) { + /* + * Add your own defined handler objects, use @Component for + * the class. See WidgetNotificationHandler as an example. + * + * Use @Async on methods for performance + * + * For syncronous replies use UebManager publishReply and + * echo back the msgId in your response ie + * msg.putMsgId(requestMsg.getMsgId()) + * + * case UebMsgTypes.UEB_MSG_TYPE_XYZ: { + * XYZHandler.handleMsg(msg); break; } + */ + case UebMsgTypes.UEB_MSG_TYPE_WIDGET_NOTIFICATION: { + widgetNotificationHandler.handleWidgetNotification(msg); + break; + } + default: { + + logger.info(EELFLoggerDelegate.debugLogger, ("Unknown message type [" + msg.getMsgType() + "] from " + msg.getSourceTopicName())); + + break; + } + } + } + } + + if (Thread.interrupted()) { + + logger.info(EELFLoggerDelegate.debugLogger, ("==> UebMainHandler exiting")); + + break; + } + + try { + Thread.sleep(10); + } catch (InterruptedException e) { + logger.info(EELFLoggerDelegate.debugLogger, ("UebMainHandler interrupted during sleep" + e.getMessage())); + + } + } + } +} diff --git a/dcae_dmaapbc_webapp/src/main/java/org/openecomp/fusionapp/uebhandler/WidgetNotificationHandler.java b/dcae_dmaapbc_webapp/src/main/java/org/openecomp/fusionapp/uebhandler/WidgetNotificationHandler.java new file mode 100644 index 0000000..9b0ff58 --- /dev/null +++ b/dcae_dmaapbc_webapp/src/main/java/org/openecomp/fusionapp/uebhandler/WidgetNotificationHandler.java @@ -0,0 +1,46 @@ +/*- + * ================================================================================ + * DCAE DMaaP Bus Controller Web Application + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ================================================================================ + */ +package org.openecomp.fusionapp.uebhandler; + +import org.openecomp.portalsdk.core.logging.logic.EELFLoggerDelegate; +import org.openecomp.portalsdk.core.onboarding.ueb.UebMsg; +import org.springframework.scheduling.annotation.Async; +import org.springframework.stereotype.Component; + +@Component +public class WidgetNotificationHandler { + + EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(WidgetNotificationHandler.class); + + + public WidgetNotificationHandler() { + } + + @Async + public void handleWidgetNotification(UebMsg requestMsg) { + logger.debug(EELFLoggerDelegate.debugLogger, ("handleWidgetNotification received notification: " + requestMsg.toString())); + /* + * Here the notification msg can be handled + * + * requestMsg.getPayload() - returns string that contains the + * Application defined content + */ + } +} diff --git a/dcae_dmaapbc_webapp/src/main/java/org/openecomp/fusionapp/util/CustomLoggingFilter.java b/dcae_dmaapbc_webapp/src/main/java/org/openecomp/fusionapp/util/CustomLoggingFilter.java new file mode 100644 index 0000000..760460f --- /dev/null +++ b/dcae_dmaapbc_webapp/src/main/java/org/openecomp/fusionapp/util/CustomLoggingFilter.java @@ -0,0 +1,54 @@ +/*- + * ================================================================================ + * DCAE DMaaP Bus Controller Web Application + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ================================================================================ + */ +package org.openecomp.fusionapp.util; + +import ch.qos.logback.classic.Level; +import ch.qos.logback.classic.spi.ILoggingEvent; +import ch.qos.logback.core.filter.Filter; +import ch.qos.logback.core.spi.FilterReply; + +/** + * Custom Filter class bind with logback.xml + * configuration file to strip out certain log messages + * coming out of special packages or classes. + * + */ +public class CustomLoggingFilter extends Filter<ILoggingEvent> { + + /** + * Custom Filter is added to strip out the continuous U-EB logging messages + * But make sure we log the ERROR & WARNING Level messages. + */ + @Override + public FilterReply decide(ILoggingEvent event) { + try { + if ((event.getLevel() != Level.ERROR || event.getLevel() != Level.WARN) && + (event.getThreadName().equalsIgnoreCase("UEBConsumerThread")) && + (event.getLoggerName().contains("com.att.nsa") || event.getLoggerName().contains("org.apache.http")) + ) { + return FilterReply.DENY; + } else { + return FilterReply.NEUTRAL; + } + } catch(Exception e) { + return FilterReply.NEUTRAL; + } + } +} diff --git a/dcae_dmaapbc_webapp/src/main/java/org/openecomp/fusionapp/util/LoggerDemo.java b/dcae_dmaapbc_webapp/src/main/java/org/openecomp/fusionapp/util/LoggerDemo.java new file mode 100644 index 0000000..9bdff16 --- /dev/null +++ b/dcae_dmaapbc_webapp/src/main/java/org/openecomp/fusionapp/util/LoggerDemo.java @@ -0,0 +1,48 @@ +/*- + * ================================================================================ + * DCAE DMaaP Bus Controller Web Application + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ================================================================================ + */ +package org.openecomp.fusionapp.util; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import ch.qos.logback.classic.LoggerContext; + +public class LoggerDemo { + + private static final Logger log = LoggerFactory.getLogger(LoggerDemo.class); + + public static void main(String[] args) { + new LoggerDemo().new Parent().hello(); + new LoggerDemo().new Child().hello(); + // Flush messages before shutting down async logger + LoggerContext loggerContext = (LoggerContext) LoggerFactory.getILoggerFactory(); + loggerContext.stop(); + } + + public class Parent { + public void hello() { + log.info("Hello from " + getClass().getSimpleName()); + } + } + + public class Child extends Parent { + } + +} diff --git a/dcae_dmaapbc_webapp/src/main/java/org/openecomp/fusionapp/util/ValidateEncodingApp.java b/dcae_dmaapbc_webapp/src/main/java/org/openecomp/fusionapp/util/ValidateEncodingApp.java new file mode 100644 index 0000000..cd327b2 --- /dev/null +++ b/dcae_dmaapbc_webapp/src/main/java/org/openecomp/fusionapp/util/ValidateEncodingApp.java @@ -0,0 +1,203 @@ +/*- + * ================================================================================ + * DCAE DMaaP Bus Controller Web Application + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ================================================================================ + */ +package org.openecomp.fusionapp.util; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStreamReader; +import java.nio.charset.CharacterCodingException; +import java.nio.charset.Charset; +import java.nio.charset.CharsetDecoder; +import java.nio.charset.CodingErrorAction; + +/** + * Reads bytes from file using a decoder that throws an exception if the bytes + * cannot be decoded as UTF-8. Can be used to validate a single file or a + * directory of files with full recursion. Includes a feature to create a file + * with a non-UTF-8 byte sequence for testing. + */ +public class ValidateEncodingApp { + + private final String charsetName; + private final CharsetDecoder decoder; + private int filesPassed = 0, filesFailed = 0; + + /** + * Obtains a decoder and configures it to blow up on problems. + * + * @param charsetName + * Name of character set to use; e.g., UTF-8 + */ + public ValidateEncodingApp(String charsetName) { + this.charsetName = charsetName; + Charset charset = Charset.forName(charsetName); + decoder = charset.newDecoder(); + decoder.onMalformedInput(CodingErrorAction.REPORT); + decoder.onUnmappableCharacter(CodingErrorAction.REPORT); + } + + /** + * @return The character set name supplied to the constructor + */ + public String getCharsetName() { + return charsetName; + } + + /** + * @return The number of files that could not be validated for whatever + * reason. + */ + public int getFilesFailed() { + return filesFailed; + } + + /** + * @return The number of files successfully validated. + */ + public int getFilesPassed() { + return filesPassed; + } + + /** + * Reads and decodes bytes from the specified file, which will find byte + * sequences that cannot be decoded using the current system. Traps all + * exceptions and reports to System.err. + * + * @param file + * @return True on success, false on IOException or decoding error + */ + private boolean validateFile(File file) { + boolean result = true; + int lineNr = 1; + BufferedReader br = null; + try { + br = new BufferedReader(new InputStreamReader(new FileInputStream(file), decoder)); + while (br.readLine() != null) + ++lineNr; + ++filesPassed; + } catch (CharacterCodingException ex) { + ++filesFailed; + System.err.println("Failed at line " + lineNr + ", file " + file.getPath() + ": " + ex.toString()); + result = false; + } catch (IOException ex) { + ++filesFailed; + System.err.println("Failed to read file " + file.getPath() + ": " + ex.toString()); + result = false; + } finally { + if (br != null) + try { + br.close(); + } catch (IOException ex) { + System.err.println("Failed to close file: " + ex.toString()); + } + } + return result; + } + + /** + * Validates all files in the specified directory. Optionally recurses into + * subdirectories. Prints message to stdout when it starts and again when it + * finishes traversing a directory. + * + * @param dir + * Directory to traverse. + * @param isRecurse + * If true, will call itself to process subdirectories. + * @throws Exception + */ + private void validateDirectory(File dir, boolean isRecurse) throws Exception { + if (!dir.exists() || !dir.isDirectory()) + throw new IllegalArgumentException("Not found or not a directory: " + dir.getPath()); + System.out.println("Entering directory " + dir.getPath()); + File[] contents = dir.listFiles(); + for (File f : contents) { + if (f.isFile()) + validateFile(f); + else if (f.isDirectory() && isRecurse) + validateDirectory(f, isRecurse); + } + System.out.println("Leaving directory " + dir.getPath()); + } + + /** + * Prints message(s) and exits + * + * @param msg + */ + private static void usage(String msg) { + if (msg != null) + System.err.println(msg); + System.err.println("Usage: ValidateEncodingApp -validate (file|dir)"); + System.err.println(" ValidateEncodingApp -create filename"); + System.exit(0); + } + + public static void main(String[] args) throws Exception { + + // TODO: extend to accept encoding system name + // and recurse option as arguments. + String charsetName = "UTF-8"; + boolean recurse = true; + + if (args.length != 2) + usage("Unexpected number of arguments"); + + String cmd = args[0]; + File file = new File(args[1]); + + if ("-create".equals(cmd)) { + if (file.exists()) + usage("Will not overwrite existing file: " + file.getPath()); + System.out.println("Creating file with ISO-8859-1 content: " + file.getPath()); + try { + // The word "dolt" has an o with a diagonal slash thru it. + // The slash-o is valid in ISO-8859-1 but not in UTF-8. + final byte[] invalid = "d\u00f8lt\n".getBytes("iso-8859-1"); + FileOutputStream fis = new FileOutputStream(file); + fis.write(invalid); + fis.close(); + } catch (IOException ex) { + System.err.println("Failed to write file: " + ex.toString()); + } + } else if ("-validate".equals(cmd)) { + if (!file.exists()) + usage("Not found: " + file.getPath()); + + ValidateEncodingApp validator = new ValidateEncodingApp(charsetName); + if (file.isFile()) { + System.out.println("Validating decoding of bytes as " + charsetName + " for file " + file.getPath()); + validator.validateFile(file); + } else { + System.out.println("Validating decoding of bytes as " + charsetName + " for files in/below directory " + + file.getPath()); + validator.validateDirectory(file, recurse); + } + System.out.println("Validation success count is " + validator.getFilesPassed()); + System.out.println("Validation failure count is " + validator.getFilesFailed()); + } else { + usage("Unexpected command: " + cmd); + } + + } + +} |