summaryrefslogtreecommitdiffstats
path: root/sdnr/wt/data-provider/provider/src
diff options
context:
space:
mode:
authorMichael DÜrre <michael.duerre@highstreet-technologies.com>2021-08-24 06:16:11 +0200
committerMichael DÜrre <michael.duerre@highstreet-technologies.com>2021-08-24 06:17:47 +0200
commitc8f7e3f376992b202ba26464b9b329d6c4b2821d (patch)
treec61507b22b28ccc536485a8bf291826d0461b031 /sdnr/wt/data-provider/provider/src
parent2a55fbf61c4450bfc2bb3f90b060c3aa65af91f3 (diff)
fix some sdnr sonar bugs
sonar fixes for some sdnr components Issue-ID: SDNC-1590 Change-Id: I02e44b6f5477bcd0490c3499caf20228eb9772ed Signed-off-by: Michael DÜrre <michael.duerre@highstreet-technologies.com>
Diffstat (limited to 'sdnr/wt/data-provider/provider/src')
-rw-r--r--sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/elasticsearch/EsDataObjectReaderWriter2.java6
-rw-r--r--sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/elasticsearch/data/rpctypehelper/QueryByFilter.java13
-rw-r--r--sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/http/DataTreeHttpServlet.java43
-rw-r--r--sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/http/UserdataHttpServlet.java39
-rw-r--r--sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/http/about/AboutHttpServlet.java42
-rw-r--r--sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/http/about/MarkdownTable.java19
-rw-r--r--sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/impl/DataProviderServiceImpl.java27
7 files changed, 96 insertions, 93 deletions
diff --git a/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/elasticsearch/EsDataObjectReaderWriter2.java b/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/elasticsearch/EsDataObjectReaderWriter2.java
index a86ecdde1..cb0f22da1 100644
--- a/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/elasticsearch/EsDataObjectReaderWriter2.java
+++ b/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/elasticsearch/EsDataObjectReaderWriter2.java
@@ -53,7 +53,7 @@ import org.slf4j.LoggerFactory;
*/
public class EsDataObjectReaderWriter2<T extends DataObject> {
- private final Logger LOG = LoggerFactory.getLogger(EsDataObjectReaderWriter2.class);
+ private static final Logger LOG = LoggerFactory.getLogger(EsDataObjectReaderWriter2.class);
/** Typename for elastic search data schema **/
private String dataTypeName;
@@ -202,7 +202,7 @@ public class EsDataObjectReaderWriter2<T extends DataObject> {
*
* @param writeInterfaceClazz
*/
- public EsDataObjectReaderWriter2<T> setWriteInterface(@Nonnull Class<? extends DataObject> writeInterfaceClazz) {
+ public EsDataObjectReaderWriter2<T> setWriteInterface(Class<? extends DataObject> writeInterfaceClazz) {
LOG.debug("Set write interface to {}", writeInterfaceClazz);
if (writeInterfaceClazz == null) {
throw new IllegalArgumentException("Null not allowed here.");
@@ -359,7 +359,7 @@ public class EsDataObjectReaderWriter2<T extends DataObject> {
if(this.doFullsizeRequest) {
query.doFullsizeRequest();
}
- SearchResult<T> res = new SearchResult<T>();
+ SearchResult<T> res = new SearchResult<>();
SearchResult<SearchHit> result;
List<SearchHit> hits;
if (query != null) {
diff --git a/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/elasticsearch/data/rpctypehelper/QueryByFilter.java b/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/elasticsearch/data/rpctypehelper/QueryByFilter.java
index eef61e09c..69f9bcc29 100644
--- a/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/elasticsearch/data/rpctypehelper/QueryByFilter.java
+++ b/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/elasticsearch/data/rpctypehelper/QueryByFilter.java
@@ -96,10 +96,10 @@ public class QueryByFilter {
if (fromPage < 0 || pageSize > 10000)
throw new IllegalArgumentException("mismatching input parameters. From:" + fromPage + " size:" + pageSize);
- filterList = YangHelper.getList(input.getFilter());
+ filterList = input == null ? null : YangHelper.getList(input.getFilter());
if (filterList == null)
filterList = emptyFilterList;
- sortOrder = YangHelper.getList(input.getSortorder());
+ sortOrder = input == null ? null : YangHelper.getList(input.getSortorder());
if (sortOrder == null)
sortOrder = emptySortOrderList;
@@ -167,7 +167,7 @@ public class QueryByFilter {
* Private and static implementations
*/
private static QueryBuilder setSortOrder(QueryBuilder query, @Nullable List<Sortorder> sortorder, String prefix) {
- if (sortorder != null && sortorder.size() > 0) {
+ if (sortorder != null && !sortorder.isEmpty()) {
for (Sortorder so : sortorder) {
query.sort(handlePrefix(prefix, so.getProperty()), convert(so.getSortorder()));
}
@@ -179,7 +179,7 @@ public class QueryByFilter {
return sortOrder == SortOrder.Ascending
? org.onap.ccsdk.features.sdnr.wt.common.database.queries.SortOrder.ASCENDING
: org.onap.ccsdk.features.sdnr.wt.common.database.queries.SortOrder.DESCENDING;
- };
+ }
private static Sortorder getSortOrder(@Nullable List<Sortorder> list, String prop) {
if (list == null) {
@@ -353,7 +353,7 @@ public class QueryByFilter {
}
private static List<String> collectValues(Filter filter) {
- List<String> values = new ArrayList<String>();
+ List<String> values = new ArrayList<>();
if (filter.getFiltervalue() != null) {
values.add(filter.getFiltervalue());
}
@@ -364,7 +364,7 @@ public class QueryByFilter {
}
private static QueryBuilder fromFilter(@Nullable List<Filter> filters, String prefix) {
- if (filters == null || filters.size() == 0) {
+ if (filters == null || filters.isEmpty()) {
return QueryBuilders.matchAllQuery();
} else if (filters.size() == 1) {
@@ -399,7 +399,6 @@ public class QueryByFilter {
tmpQuery.should(getSinglePropertyQuery(p, v, prefix));
}
query.must(tmpQuery);
- tmpQuery = QueryBuilders.boolQuery();
}
}
LOG.trace("Query result. {}", query.toJSON());
diff --git a/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/http/DataTreeHttpServlet.java b/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/http/DataTreeHttpServlet.java
index 115ff4f40..3c4a7621b 100644
--- a/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/http/DataTreeHttpServlet.java
+++ b/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/http/DataTreeHttpServlet.java
@@ -29,6 +29,7 @@ import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.util.ArrayList;
import java.util.List;
+import java.util.Optional;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import javax.servlet.ServletException;
@@ -70,9 +71,9 @@ public class DataTreeHttpServlet extends HttpServlet {
String body = null;
StringBuilder stringBuilder = new StringBuilder();
BufferedReader bufferedReader = null;
+ IOException toThrow = null;
+ try (InputStream inputStream = request.getInputStream()) {
- try {
- InputStream inputStream = request.getInputStream();
if (inputStream != null) {
bufferedReader = new BufferedReader(new InputStreamReader(inputStream));
char[] charBuffer = new char[128];
@@ -84,17 +85,20 @@ public class DataTreeHttpServlet extends HttpServlet {
stringBuilder.append("");
}
} catch (IOException ex) {
- throw ex;
+ toThrow = ex;
} finally {
if (bufferedReader != null) {
try {
bufferedReader.close();
} catch (IOException ex) {
- throw ex;
+ LOG.debug("problem closing reader:", ex);
+ toThrow = ex;
}
}
}
-
+ if (toThrow != null) {
+ throw toThrow;
+ }
body = stringBuilder.toString();
return body;
}
@@ -164,13 +168,16 @@ public class DataTreeHttpServlet extends HttpServlet {
final String regex = "^\\/tree\\/read-(.*)-tree\\/?(.*)$";
final Pattern pattern = Pattern.compile(regex);
final Matcher matcher = pattern.matcher(uri);
- Entity e = null;
if (matcher.find() && matcher.groupCount() > 0) {
try {
- e = Entity.forName(matcher.group(1)).get();
- return new EntityWithTree(e, matcher.groupCount() > 1 ? matcher.group(2) : null);
+ Optional<Entity> oe = Entity.forName(matcher.group(1));
+ if (oe.isPresent()) {
+ return new EntityWithTree(oe.get(), matcher.groupCount() > 1 ? matcher.group(2) : null);
+ } else {
+ LOG.warn("unable to find entity for name {}", matcher.group(1));
+ }
} catch (Exception e2) {
- LOG.warn("unable to parse {} into entity: {}", matcher.group(2), e2);
+ LOG.warn("unable to parse {} into entity: ", matcher.group(2), e2);
}
}
return null;
@@ -182,7 +189,7 @@ public class DataTreeHttpServlet extends HttpServlet {
try {
resp.getWriter().write(data.toJSON());
} catch (IOException e) {
- LOG.warn("problem sending response: {}", e);
+ LOG.warn("problem sending response: ", e);
}
}
@@ -196,14 +203,14 @@ public class DataTreeHttpServlet extends HttpServlet {
}
/**
- *
- * @param e database enttity to access
- * @param tree tree description
- * e.g. nodeA => tree entry for node-id=nodeA
- * nodeA/key0 => tree entry for node-id=nodeA and uuid=key0 and tree-level=0
- * nodeA/key0/key1 => tree entry for node-id=nodeA and uuid=key1 and tree-level=1
- *
- */
+ *
+ * @param e database enttity to access
+ * @param tree tree description
+ * e.g. nodeA => tree entry for node-id=nodeA
+ * nodeA/key0 => tree entry for node-id=nodeA and uuid=key0 and tree-level=0
+ * nodeA/key0/key1 => tree entry for node-id=nodeA and uuid=key1 and tree-level=1
+ *
+ */
public EntityWithTree(Entity e, String tree) {
this.entity = e;
if (tree != null) {
diff --git a/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/http/UserdataHttpServlet.java b/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/http/UserdataHttpServlet.java
index 09a81c381..b51d2a6df 100644
--- a/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/http/UserdataHttpServlet.java
+++ b/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/http/UserdataHttpServlet.java
@@ -43,7 +43,7 @@ public class UserdataHttpServlet extends HttpServlet {
private static final String REGEX = "^\\/userdata[\\/]?([a-zA-Z0-9]+)?$";
private static final Pattern PATTERN = Pattern.compile(REGEX);
private static final String JWT_PAYLOAD_USERNAME_PROPERTYKEY = "sub";
- private HtUserdataManager dbUserManager;
+ private static HtUserdataManager dbUserManager;
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
@@ -91,47 +91,46 @@ public class UserdataHttpServlet extends HttpServlet {
private void handleGetRequest(HttpServletRequest req, HttpServletResponse resp, String key) {
final String username = this.getUsername(req);
- if(username==null) {
+ if (username == null) {
resp.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
return;
}
sendJsonResponse(resp,
- key == null ? this.dbUserManager.getUserdata(username) : this.dbUserManager.getUserdata(username, key));
+ key == null ? dbUserManager.getUserdata(username) : dbUserManager.getUserdata(username, key));
}
private void handlePutRequest(HttpServletRequest req, HttpServletResponse resp, String data, String key) {
final String username = this.getUsername(req);
- if(username==null) {
+ if (username == null) {
resp.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
return;
}
- boolean success = key == null ? this.dbUserManager.setUserdata(username, data)
- : this.dbUserManager.setUserdata(username, key, data);
+ boolean success = key == null ? dbUserManager.setUserdata(username, data)
+ : dbUserManager.setUserdata(username, key, data);
resp.setStatus(success ? HttpServletResponse.SC_OK : HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
}
private void handleDeleteRequest(HttpServletRequest req, HttpServletResponse resp, String key) {
final String username = this.getUsername(req);
- if(username==null) {
+ if (username == null) {
resp.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
return;
}
- boolean success = key == null ? this.dbUserManager.removeUserdata(username)
- : this.dbUserManager.removeUserdata(username, key);
+ boolean success =
+ key == null ? dbUserManager.removeUserdata(username) : dbUserManager.removeUserdata(username, key);
resp.setStatus(success ? HttpServletResponse.SC_OK : HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
}
private String getUsername(HttpServletRequest req) {
final String authHeader = req.getHeader("Authorization");
- if(authHeader==null) {
+ if (authHeader == null) {
return null;
}
String username = null;
- if(authHeader.startsWith("Basic")) {
+ if (authHeader.startsWith("Basic")) {
username = BaseHTTPClient.decodeBasicAuthHeaderUsername(authHeader);
- }
- else if(authHeader.startsWith("Bearer")) {
+ } else if (authHeader.startsWith("Bearer")) {
username = decodeJWTPayloadUsername(authHeader, JWT_PAYLOAD_USERNAME_PROPERTYKEY);
}
return username;
@@ -139,16 +138,16 @@ public class UserdataHttpServlet extends HttpServlet {
public static String decodeJWTPayloadUsername(String authHeader, String key) {
String username = null;
- if(authHeader.startsWith("Bearer")) {
+ if (authHeader.startsWith("Bearer")) {
authHeader = authHeader.substring(7);
}
String[] tmp = authHeader.split("\\.");
- if(tmp.length==3) {
+ if (tmp.length == 3) {
final String decoded = new String(Base64.getDecoder().decode(tmp[1]));
- JSONObject o = new JSONObject(decoded);
- if(o.has(key)) {
+ JSONObject o = new JSONObject(decoded);
+ if (o.has(key)) {
username = o.getString(key);
- if(username!=null && username.contains("@")) {
+ if (username != null && username.contains("@")) {
username = username.split("@")[0];
}
}
@@ -168,8 +167,8 @@ public class UserdataHttpServlet extends HttpServlet {
}
- public void setDatabaseClient(HtUserdataManager dbUserManager) {
- this.dbUserManager = dbUserManager;
+ public void setDatabaseClient(HtUserdataManager dbMgr) {
+ dbUserManager = dbMgr;
}
}
diff --git a/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/http/about/AboutHttpServlet.java b/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/http/about/AboutHttpServlet.java
index 64b5fab9f..cd75ca2a8 100644
--- a/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/http/about/AboutHttpServlet.java
+++ b/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/http/about/AboutHttpServlet.java
@@ -34,8 +34,6 @@ import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.http.HttpHeaders;
-//import org.apache.karaf.bundle.core.BundleInfo;
-//import org.apache.karaf.bundle.core.BundleService;
import org.onap.ccsdk.features.sdnr.wt.common.Resources;
import org.onap.ccsdk.features.sdnr.wt.common.file.PomFile;
import org.onap.ccsdk.features.sdnr.wt.common.file.PomPropertiesFile;
@@ -83,8 +81,7 @@ public class AboutHttpServlet extends HttpServlet {
private final Map<Integer, String> BUNDLESTATE_LUT;
private final Map<String, String> data;
private final String readmeContent;
- // private BundleService bundleService;
- private String jsonContent;
+ private final String jsonContent;
public AboutHttpServlet() {
@@ -114,10 +111,6 @@ public class AboutHttpServlet extends HttpServlet {
return def;
}
- // public void setBundleService(BundleService bundleService) {
- // this.bundleService = bundleService;
- // }
-
/**
* collect static versioning data
*/
@@ -152,22 +145,11 @@ public class AboutHttpServlet extends HttpServlet {
resp.setStatus(HttpServletResponse.SC_OK);
resp.setContentLength(output.length);
resp.setContentType(ctype.getMimeType());
- ServletOutputStream os = null;
- try {
- os = resp.getOutputStream();
+ try (ServletOutputStream os = resp.getOutputStream()) {
os.write(output);
} catch (IOException e) {
LOG.warn("problem writing response for {}: {}", uri, e);
- } finally {
- if (os != null) {
- try {
- os.close();
- } catch (IOException e) {
- LOG.warn("problem closing response stream: {}", e);
- }
- }
}
-
} else {
this.doGetFile(uri, resp);
}
@@ -183,7 +165,7 @@ public class AboutHttpServlet extends HttpServlet {
if (content == null) {
return def;
}
- String lines[] = content.split("\n");
+ String[] lines = content.split("\n");
for (String line : lines) {
if (line.startsWith("git.commit.id")) {
def = line.substring("git.commit.id=".length());
@@ -207,7 +189,7 @@ public class AboutHttpServlet extends HttpServlet {
this.data.put(PLACEHOLDER_KARAF_INFO, SystemInfo.get());
this.data.put(PLACEHOLDER_DEVICEMANAGER_TABLE, this.getDevicemanagerBundles(ctype));
} catch (Exception e) {
- LOG.warn("problem collecting system data: {}", e);
+ LOG.warn("problem collecting system data: ", e);
}
}
@@ -228,7 +210,7 @@ public class AboutHttpServlet extends HttpServlet {
Attributes attr = manifest.getMainAttributes();
return attr.getValue(key);
} catch (IOException e) {
- LOG.warn("problem reading manifest: {}", e);
+ LOG.warn("problem reading manifest: ", e);
}
return null;
@@ -282,12 +264,12 @@ public class AboutHttpServlet extends HttpServlet {
BundleContext context = thisbundle == null ? null : thisbundle.getBundleContext();
if (context == null) {
LOG.debug("no bundle context available");
- return ctype==ContentType.MARKDOWN?"":"[]";
+ return ctype == ContentType.MARKDOWN ? "" : "[]";
}
Bundle[] bundles = context.getBundles();
if (bundles == null || bundles.length <= 0) {
LOG.debug("no bundles found");
- return ctype==ContentType.MARKDOWN?NO_DEVICEMANAGERS_RUNNING_MESSAGE:"[]";
+ return ctype == ContentType.MARKDOWN ? NO_DEVICEMANAGERS_RUNNING_MESSAGE : "[]";
}
LOG.debug("found {} bundles", bundles.length);
MarkdownTable table = new MarkdownTable();
@@ -302,10 +284,10 @@ public class AboutHttpServlet extends HttpServlet {
continue;
}
table.addRow(new String[] {String.valueOf(bundle.getBundleId()), bundle.getVersion().toString(), name,
- BUNDLESTATE_LUT.getOrDefault(bundle.getState(), "unknown")});
+ BUNDLESTATE_LUT.getOrDefault(bundle.getState(), UNKNOWN)});
}
- return ctype==ContentType.MARKDOWN?table.toMarkDown():table.toJson();
+ return ctype == ContentType.MARKDOWN ? table.toMarkDown() : table.toJson();
}
/**
@@ -329,7 +311,7 @@ public class AboutHttpServlet extends HttpServlet {
try {
resp.getOutputStream().write(data);
} catch (IOException e) {
- LOG.debug("unable to send data : {}", e);
+ LOG.debug("unable to send data: ", e);
}
}
@@ -352,7 +334,7 @@ public class AboutHttpServlet extends HttpServlet {
case "bmp":
return "image/" + ext;
case "json":
- return "application/json";
+ return MIMETYPE_JSON;
case "html":
case "htm":
return "text/html";
@@ -382,7 +364,7 @@ public class AboutHttpServlet extends HttpServlet {
*/
private String render(ContentType ctype, String content) {
if (content == null) {
- content = ctype==ContentType.MARKDOWN? this.readmeContent:this.jsonContent;
+ content = ctype == ContentType.MARKDOWN ? this.readmeContent : this.jsonContent;
}
if (content == null) {
return null;
diff --git a/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/http/about/MarkdownTable.java b/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/http/about/MarkdownTable.java
index 1580a0fe3..e13ca8203 100644
--- a/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/http/about/MarkdownTable.java
+++ b/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/http/about/MarkdownTable.java
@@ -47,10 +47,20 @@ public class MarkdownTable {
this.rows.add(values);
}
+ private int getColNumbers() {
+ int cols = 0;
+ if (this.columns != null) {
+ cols = this.columns.length;
+ } else {
+ cols = !this.rows.isEmpty() ? this.rows.get(0).length : 0;
+ }
+ return cols;
+ }
+
public String toMarkDown() {
StringBuilder sb = new StringBuilder();
- final int cols =
- this.columns != null ? this.columns.length : this.rows.size() > 0 ? this.rows.get(0).length : 0;
+
+ final int cols = this.getColNumbers();
if (cols > 0) {
sb.append("|");
for (int i = 0; i < cols; i++) {
@@ -75,9 +85,8 @@ public class MarkdownTable {
public String toJson() {
JSONArray a = new JSONArray();
- final int cols =
- this.columns != null ? this.columns.length : this.rows.size() > 0 ? this.rows.get(0).length : 0;
- if (cols > 0) {
+ final int cols = this.getColNumbers();
+ if (cols > 0 && this.columns!=null) {
for (String[] row : this.rows) {
JSONObject o = new JSONObject();
for (int i = 0; i < cols; i++) {
diff --git a/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/impl/DataProviderServiceImpl.java b/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/impl/DataProviderServiceImpl.java
index 2bf67fde9..5a99c8ab3 100644
--- a/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/impl/DataProviderServiceImpl.java
+++ b/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/impl/DataProviderServiceImpl.java
@@ -45,6 +45,7 @@ import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.HtUserdataManager;
import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.IEsConfig;
import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.SdnrDbType;
import org.opendaylight.mdsal.binding.api.DataBroker;
+import org.opendaylight.mdsal.binding.api.ReadTransaction;
import org.opendaylight.mdsal.binding.api.RpcProviderService;
import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.keystore.rev171017.Keystore;
@@ -136,6 +137,7 @@ public class DataProviderServiceImpl implements DataProviderService, AutoCloseab
private final HtUserdataManager dbUserManager;
private final DataBroker dataBroker;
private final MsServlet mediatorServerServlet;
+
public DataProviderServiceImpl(final RpcProviderService rpcProviderService, MsServlet mediatorServerServlet,
DataBroker dataBroker) throws Exception {
this.configuration = new ConfigurationFileRepresentation(CONFIGURATIONFILE);
@@ -151,7 +153,7 @@ public class DataProviderServiceImpl implements DataProviderService, AutoCloseab
mediatorServerServlet.setDataProvider(this.dataProvider.getHtDatabaseMediatorServer());
this.dbUserManager = new HtUserdataManagerImpl(this.dataProvider.getRawClient());
// Register ourselves as the REST API RPC implementation
- LOG.info("Register RPC Service " + DataProviderServiceImpl.class.getSimpleName());
+ LOG.info("Register RPC Service {}", DataProviderServiceImpl.class.getSimpleName());
this.rpcReg = rpcProviderService.registerRpcImplementation(DataProviderService.class, this);
}
@@ -425,11 +427,15 @@ public class DataProviderServiceImpl implements DataProviderService, AutoCloseab
private ReadTlsKeyEntryOutputBuilder readTlsKeys(ReadTlsKeyEntryInput input) {
Optional<Keystore> result = Optional.empty();
- try {
- result = this.dataBroker.newReadOnlyTransaction().read(LogicalDatastoreType.CONFIGURATION, KEYSTORE_IIF)
- .get();
- } catch (InterruptedException | ExecutionException e) {
+ try (ReadTransaction transaction = this.dataBroker.newReadOnlyTransaction()) {
+ result = transaction.read(LogicalDatastoreType.CONFIGURATION, KEYSTORE_IIF).get();
+ } catch (ExecutionException e) {
LOG.warn("problem reading netconf-keystore: ", e);
+
+ } catch (InterruptedException e) {
+ LOG.warn("Interrupted!", e);
+ // Restore interrupted state...
+ Thread.currentThread().interrupt();
}
ReadTlsKeyEntryOutputBuilder output = new ReadTlsKeyEntryOutputBuilder();
if (result.isEmpty()) {
@@ -439,11 +445,12 @@ public class DataProviderServiceImpl implements DataProviderService, AutoCloseab
if (keyCredential == null) {
return output.setData(Arrays.asList()).setPagination(EMPTY_PAGINATION);
}
- long pageNum = input.getPagination() == null ? DEFAULT_PAGE
- : input.getPagination().getPage() == null ? DEFAULT_PAGE : input.getPagination().getPage().longValue();
- long size = input.getPagination() == null ? DEFAULT_PAGESIZE
- : input.getPagination().getSize() == null ? DEFAULT_PAGESIZE
- : input.getPagination().getSize().longValue();
+ org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.entity.input.Pagination pagination =
+ input.getPagination();
+ long pageNum = pagination == null ? DEFAULT_PAGE
+ : pagination.getPage() == null ? DEFAULT_PAGE : pagination.getPage().longValue();
+ long size = pagination == null ? DEFAULT_PAGESIZE
+ : pagination.getSize() == null ? DEFAULT_PAGESIZE : pagination.getSize().longValue();
long from = pageNum > 0 ? (pageNum - 1) * size : 0;
output.setData(keyCredential.keySet().stream().skip(from).limit(size).map(e -> e.getKeyId())
.collect(Collectors.toList()));