Skip to content

Commit

Permalink
canprocess-npe-check
Browse files Browse the repository at this point in the history
  • Loading branch information
nls-jajuko committed Dec 29, 2023
1 parent 3485d8f commit 8b6b958
Showing 1 changed file with 29 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,10 @@ public class OGCFeatDataStoreFactory implements DataStoreFactorySpi, DataAccessF

private static final List<Param> 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);
Expand Down Expand Up @@ -66,42 +60,47 @@ public class OGCFeatDataStoreFactory implements DataStoreFactorySpi, DataAccessF
public OGCFeatDataStore createNewDataStore(Map<String, ?> params) throws UnsupportedOperationException {
throw new UnsupportedOperationException();
}

@Override
public boolean canProcess(Map<String, ?> 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;
}
Expand Down Expand Up @@ -160,8 +159,6 @@ public Param[] getParametersInfo() {
return (Param[]) parameterInfos.toArray(new Param[parameterInfos.size()]);
}



@Override
public boolean isAvailable() {
return true;
Expand Down

0 comments on commit 8b6b958

Please sign in to comment.