diff options
Diffstat (limited to 'src/main/java/org/onap')
5 files changed, 77 insertions, 36 deletions
diff --git a/src/main/java/org/onap/clamp/clds/Application.java b/src/main/java/org/onap/clamp/clds/Application.java index fd5deb91..0eb48075 100644 --- a/src/main/java/org/onap/clamp/clds/Application.java +++ b/src/main/java/org/onap/clamp/clds/Application.java @@ -26,10 +26,10 @@ package org.onap.clamp.clds; import com.att.eelf.configuration.EELFLogger; import com.att.eelf.configuration.EELFManager; -import org.apache.camel.component.servlet.CamelHttpTransportServlet; import org.apache.catalina.connector.Connector; import org.onap.clamp.clds.model.properties.Holmes; import org.onap.clamp.clds.model.properties.ModelProperties; +import org.onap.clamp.clds.util.ClampVersioning; import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; @@ -85,6 +85,7 @@ public class Application extends SpringBootServletInitializer { } public static void main(String[] args) { + EELF_LOGGER.info("Starting :: CLAMP :: (v"+ ClampVersioning.getCldsVersionFromProps()+")"); // This is to initialize some Onap Clamp components initializeComponents(); // Start the Spring application diff --git a/src/main/java/org/onap/clamp/clds/config/CamelConfiguration.java b/src/main/java/org/onap/clamp/clds/config/CamelConfiguration.java index 16cbd840..c80fd0ec 100644 --- a/src/main/java/org/onap/clamp/clds/config/CamelConfiguration.java +++ b/src/main/java/org/onap/clamp/clds/config/CamelConfiguration.java @@ -20,9 +20,10 @@ * =================================================================== */ package org.onap.clamp.clds.config; + import org.apache.camel.builder.RouteBuilder; import org.apache.camel.model.rest.RestBindingMode; -import org.onap.clamp.clds.model.CldsInfo; +import org.onap.clamp.clds.util.ClampVersioning; import org.springframework.stereotype.Component; @Component @@ -30,11 +31,13 @@ public class CamelConfiguration extends RouteBuilder { @Override public void configure() { - restConfiguration().component("servlet") - .bindingMode(RestBindingMode.json); - - rest("/clds") - .get("/test").description("Find user by id").outType(CldsInfo.class).produces("application/json") - .to("bean:org.onap.clamp.clds.service.CldsService?method=getCldsInfo()") ; + restConfiguration().component("servlet").bindingMode(RestBindingMode.json) + .dataFormatProperty("prettyPrint", "true")//.enableCORS(true) + // turn on swagger api-doc + .apiContextPath("api-doc") + .apiVendorExtension(true) + .apiProperty("api.title", "Clamp Rest API").apiProperty("api.version", ClampVersioning.getCldsVersionFromProps()) + .apiProperty("base.path", "/restservices/clds/v1/"); + //.apiProperty("cors", "true"); } } diff --git a/src/main/java/org/onap/clamp/clds/service/CldsInfoProvider.java b/src/main/java/org/onap/clamp/clds/service/CldsInfoProvider.java index 66890aa1..6bebde92 100644 --- a/src/main/java/org/onap/clamp/clds/service/CldsInfoProvider.java +++ b/src/main/java/org/onap/clamp/clds/service/CldsInfoProvider.java @@ -24,30 +24,22 @@ package org.onap.clamp.clds.service; -import static org.onap.clamp.clds.service.CldsService.RESOURCE_NAME; - -import com.att.eelf.configuration.EELFLogger; -import com.att.eelf.configuration.EELFManager; -import java.io.InputStream; -import java.util.Properties; import org.onap.clamp.clds.model.CldsInfo; -import org.onap.clamp.clds.util.ResourceFileUtil; +import org.onap.clamp.clds.util.ClampVersioning; class CldsInfoProvider { - private static final String CLDS_VERSION = "clds.version"; - private final CldsService cldsService; - private final EELFLogger logger = EELFManager.getInstance().getLogger(CldsInfoProvider.class); + private final CldsService cldsService; - CldsInfoProvider(CldsService cldsService) { + public CldsInfoProvider(CldsService cldsService) { this.cldsService = cldsService; } - CldsInfo getCldsInfo(){ + public CldsInfo getCldsInfo() { CldsInfo cldsInfo = new CldsInfo(); cldsInfo.setUserName(cldsService.getUserName()); - cldsInfo.setCldsVersion(getCldsVersionFromProps()); + cldsInfo.setCldsVersion(ClampVersioning.getCldsVersionFromProps()); cldsInfo.setPermissionReadCl(cldsService.isAuthorizedNoException(cldsService.permissionReadCl)); cldsInfo.setPermissionUpdateCl(cldsService.isAuthorizedNoException(cldsService.permissionUpdateCl)); @@ -55,16 +47,4 @@ class CldsInfoProvider { cldsInfo.setPermissionUpdateTemplate(cldsService.isAuthorizedNoException(cldsService.permissionUpdateTemplate)); return cldsInfo; } - - private String getCldsVersionFromProps() { - String cldsVersion = ""; - Properties props = new Properties(); - try (InputStream resourceStream = ResourceFileUtil.getResourceAsStream(RESOURCE_NAME)) { - props.load(resourceStream); - cldsVersion = props.getProperty(CLDS_VERSION); - } catch (Exception ex) { - logger.error("Exception caught during the clds.version reading", ex); - } - return cldsVersion; - } } diff --git a/src/main/java/org/onap/clamp/clds/service/CldsService.java b/src/main/java/org/onap/clamp/clds/service/CldsService.java index d6fbde35..74c78aee 100644 --- a/src/main/java/org/onap/clamp/clds/service/CldsService.java +++ b/src/main/java/org/onap/clamp/clds/service/CldsService.java @@ -36,10 +36,11 @@ import java.util.Date; import java.util.List; import java.util.Optional; import java.util.UUID; + import javax.ws.rs.BadRequestException; +import javax.ws.rs.NotAuthorizedException; import javax.xml.transform.TransformerException; - import org.apache.camel.Produce; import org.apache.commons.codec.DecoderException; import org.apache.commons.lang3.StringUtils; @@ -50,7 +51,6 @@ import org.onap.clamp.clds.client.DcaeInventoryServices; import org.onap.clamp.clds.client.req.sdc.SdcCatalogServices; import org.onap.clamp.clds.config.ClampProperties; import org.onap.clamp.clds.dao.CldsDao; - import org.onap.clamp.clds.exception.CldsConfigException; import org.onap.clamp.clds.exception.policy.PolicyClientException; import org.onap.clamp.clds.exception.sdc.SdcCommunicationException; @@ -89,7 +89,7 @@ public class CldsService extends SecureServiceBase { @Produce(uri = "direct:processSubmit") private CamelProxy camelProxy; protected static final EELFLogger securityLogger = EELFManager.getInstance().getSecurityLogger(); - static final String RESOURCE_NAME = "clds-version.properties"; + public static final String GLOBAL_PROPERTIES_KEY = "files.globalProperties"; private final String cldsPersmissionTypeCl; private final String cldsPermissionTypeClManage; diff --git a/src/main/java/org/onap/clamp/clds/util/ClampVersioning.java b/src/main/java/org/onap/clamp/clds/util/ClampVersioning.java new file mode 100644 index 00000000..06330091 --- /dev/null +++ b/src/main/java/org/onap/clamp/clds/util/ClampVersioning.java @@ -0,0 +1,57 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP CLAMP + * ================================================================================ + * Copyright (C) 2018 AT&T Intellectual Property. All rights + * reserved. + * ================================================================================ + * 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. + * ============LICENSE_END============================================ + * Modifications copyright (c) 2018 Nokia + * =================================================================== + * + */ + +package org.onap.clamp.clds.util; + +import com.att.eelf.configuration.EELFLogger; +import com.att.eelf.configuration.EELFManager; + +import java.io.InputStream; +import java.util.Properties; + +/** + * This class give a way to know the Clamp version easily, the version in that + * file is set by maven at build time. + * + */ +public class ClampVersioning { + private static final String RESOURCE_NAME = "clds-version.properties"; + private static final String CLDS_VERSION_PROPERTY = "clds.version"; + private static final EELFLogger LOGGER = EELFManager.getInstance().getLogger(ClampVersioning.class); + + private ClampVersioning() { + } + + public static String getCldsVersionFromProps() { + String cldsVersion = ""; + Properties props = new Properties(); + try (InputStream resourceStream = ResourceFileUtil.getResourceAsStream(RESOURCE_NAME)) { + props.load(resourceStream); + cldsVersion = props.getProperty(CLDS_VERSION_PROPERTY); + } catch (Exception ex) { + LOGGER.error("Exception caught during the "+CLDS_VERSION_PROPERTY+" property reading", ex); + } + return cldsVersion; + } +} |