From 8b6b958d4a728b73142fd6387cf8a28c40e2ad63 Mon Sep 17 00:00:00 2001 From: nls-jajuko Date: Fri, 29 Dec 2023 10:31:47 +0200 Subject: [PATCH] canprocess-npe-check --- .../datastore/OGCFeatDataStoreFactory.java | 61 +++++++++---------- 1 file changed, 29 insertions(+), 32 deletions(-) diff --git a/src/main/java/org/geoserver/extension/ogcfeat/datastore/OGCFeatDataStoreFactory.java b/src/main/java/org/geoserver/extension/ogcfeat/datastore/OGCFeatDataStoreFactory.java index beb308a..18f280b 100644 --- a/src/main/java/org/geoserver/extension/ogcfeat/datastore/OGCFeatDataStoreFactory.java +++ b/src/main/java/org/geoserver/extension/ogcfeat/datastore/OGCFeatDataStoreFactory.java @@ -26,16 +26,10 @@ public class OGCFeatDataStoreFactory implements DataStoreFactorySpi, DataAccessF private static final List parameterInfos = new ArrayList<>(10); - public static final String DBTYPE_STRING = "OGCFeat"; - - public static final Param DBTYPE = - new Param( - "dbtype", - String.class, - "Fixed value '" + DBTYPE_STRING + "'", - true, - DBTYPE_STRING, - Collections.singletonMap(Parameter.LEVEL, "program")); + public static final String DBTYPE_STRING = "OGCFeat"; + + public static final Param DBTYPE = new Param("dbtype", String.class, "Fixed value '" + DBTYPE_STRING + "'", true, + DBTYPE_STRING, Collections.singletonMap(Parameter.LEVEL, "program")); public static final Param NS_PARAM = new Param("namespace", String.class, "Namespace for OGCFeat type", true); public static final Param URL_PARAM = new Param("url", String.class, "OGCFeat landing page", true); public static final Param USER_PARAM = new Param("username", String.class, "username", false, null); @@ -66,42 +60,47 @@ public class OGCFeatDataStoreFactory implements DataStoreFactorySpi, DataAccessF public OGCFeatDataStore createNewDataStore(Map params) throws UnsupportedOperationException { throw new UnsupportedOperationException(); } - + @Override public boolean canProcess(Map params) { LOGGER.info("CANPROCESS"); - params.forEach((k,v)->{ - LOGGER.info("CANPROCESS parmams "+k+" -> "+v); + params.forEach((k, v) -> { + LOGGER.info("CANPROCESS parmams " + k + " -> " + v); }); - + try { - Object dbType = DBTYPE.lookUp(params); - if( !DBTYPE_STRING.equals(dbType)) { - LOGGER.info("DBTYPE"+dbType+" NOT EQUAL TO REQUIRED "+dbType); - return false; - }; - - URL url = new URL((String) params.get(OGCFeatDataStoreFactory.URL_PARAM.key)); - - - if(!url.getProtocol().startsWith("http")) { + Object dbType = DBTYPE.lookUp(params); + if (dbType == null) { + return false; + } + if (!DBTYPE_STRING.equals(dbType)) { + LOGGER.info("DBTYPE" + dbType + " NOT EQUAL TO REQUIRED " + dbType); + return false; + } + ; + + String urlStr = (String) params.get(OGCFeatDataStoreFactory.URL_PARAM.key); + if (urlStr == null) { + LOGGER.info("URL missing"); + return false; + } + + URL url = new URL(urlStr); + + if (!url.getProtocol().startsWith("http")) { LOGGER.info("URL is not http(s)"); return false; } - } catch (MalformedURLException e) { - LOGGER.info("URL failed "+e.toString()); + LOGGER.info("URL failed " + e.toString()); return false; } catch (IOException e) { - LOGGER.info("LOOKUP failed "+e.toString()); + LOGGER.info("LOOKUP failed " + e.toString()); return false; } LOGGER.info("URL OK"); - - - return true; } @@ -160,8 +159,6 @@ public Param[] getParametersInfo() { return (Param[]) parameterInfos.toArray(new Param[parameterInfos.size()]); } - - @Override public boolean isAvailable() { return true;