X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=ms%2Fcontrollerblueprints%2Fmodules%2Fblueprint-core%2Fsrc%2Fmain%2Fkotlin%2Forg%2Fonap%2Fccsdk%2Fapps%2Fcontrollerblueprints%2Fcore%2Futils%2FResourceResolverUtils.kt;h=762e47fbf9175902d9a9bcf20e2f94a0710c99a8;hb=refs%2Fchanges%2F63%2F82863%2F2;hp=965e965c62fab8b72ef96da6337176aae13e8c69;hpb=2960fd72dc68665e4d518713528957ec9528907f;p=ccsdk%2Fapps.git diff --git a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/ResourceResolverUtils.kt b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/ResourceResolverUtils.kt index 965e965c..762e47fb 100644 --- a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/ResourceResolverUtils.kt +++ b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/ResourceResolverUtils.kt @@ -1,5 +1,6 @@ /* * Copyright © 2017-2018 AT&T Intellectual Property. + * Modifications Copyright © 2019 IBM. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,14 +17,13 @@ package org.onap.ccsdk.apps.controllerblueprints.core.utils -import org.apache.commons.io.FileUtils -import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException -import org.onap.ccsdk.apps.controllerblueprints.core.checkNotEmpty import com.att.eelf.configuration.EELFLogger import com.att.eelf.configuration.EELFManager +import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException +import org.onap.ccsdk.apps.controllerblueprints.core.checkNotEmpty import java.io.File import java.net.URL -import java.nio.charset.Charset + /** * * @@ -32,30 +32,30 @@ import java.nio.charset.Charset object ResourceResolverUtils { private val log: EELFLogger = EELFManager.getInstance().getLogger(this::class.toString()) - @JvmStatic - fun getFileContent(filename : String, basePath : String?): String { + fun getFileContent(filename: String, basePath: String?): String { log.trace("file ({}), basePath ({}) ", filename, basePath) - try{ - var resolvedFileName : String = filename - if(filename.startsWith("http", true) - || filename.startsWith("https", true)){ - val givenUrl : String = URL(filename).toString() - val systemUrl : String = File(".").toURI().toURL().toString() + try { + var resolvedFileName: String = filename + if (filename.startsWith("http", true) + || filename.startsWith("https", true)) { + val givenUrl: String = URL(filename).toString() + val systemUrl: String = File(".").toURI().toURL().toString() log.trace("givenUrl ({}), systemUrl ({}) ", givenUrl, systemUrl) - if(givenUrl.startsWith(systemUrl)){ + if (givenUrl.startsWith(systemUrl)) { } - }else{ - if(!filename.startsWith("/")){ + } else { + if (!filename.startsWith("/")) { if (checkNotEmpty(basePath)) { resolvedFileName = basePath.plus(File.separator).plus(filename) - }else{ + } else { resolvedFileName = javaClass.classLoader.getResource(".").path.plus(filename) } } } - return FileUtils.readFileToString(File(resolvedFileName), Charset.defaultCharset()) - }catch (e : Exception){ + //FIXME("Convert into reactive") + return JacksonUtils.getContent(resolvedFileName) + } catch (e: Exception) { throw BluePrintException(e, "failed to file (%s), basePath (%s) ", filename, basePath) } }