
prerna.algorithm.impl.specific.tap.SysOptUtilityMethods Maven / Gradle / Ivy
/*******************************************************************************
* Copyright 2015 Defense Health Agency (DHA)
*
* If your use of this software does not include any GPLv2 components:
* 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.
* ----------------------------------------------------------------------------
* If your use of this software includes any GPLv2 components:
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*******************************************************************************/
package prerna.algorithm.impl.specific.tap;
import java.util.ArrayList;
import prerna.engine.api.IEngine;
import prerna.engine.api.ISelectStatement;
import prerna.engine.api.ISelectWrapper;
import prerna.rdf.engine.wrappers.WrapperManager;
import prerna.util.Utility;
public final class SysOptUtilityMethods {
public static String makeBindingString(String type,ArrayList vals) {
String bindings = "";
for(String val : vals)
{
bindings+= "()";
}
return bindings;
}
/**
* Runs a query on a specific engine to make a list of systems to report on
* @param engineName String containing the name of the database engine to be queried
* @param query String containing the SPARQL query to run
*/
public static Object runSingleResultQuery(IEngine engine, String query){
if(!query.isEmpty()) {
ISelectWrapper wrapper = null;
try {
wrapper = WrapperManager.getInstance().getSWrapper(engine, query);
String[] names = wrapper.getVariables();
while (wrapper.hasNext()) {
ISelectStatement sjss = wrapper.next();
return sjss.getVar(names[0]);
}
} catch (Exception e) {
e.printStackTrace();
} finally {
if(wrapper != null) {
wrapper.cleanUp();
}
}
}
return null;
}
/**
* Runs a query on a specific engine to make a list of systems to report on
* @param engineName String containing the name of the database engine to be queried
* @param query String containing the SPARQL query to run
*/
public static ArrayList runListQuery(IEngine engine, String query){
ArrayList list = new ArrayList();
if(!query.isEmpty()) {
ISelectWrapper wrapper = null;
try {
wrapper = WrapperManager.getInstance().getSWrapper(engine, query);
String[] names = wrapper.getVariables();
while (wrapper.hasNext()) {
ISelectStatement sjss = wrapper.next();
list.add((String) sjss.getVar(names[0]));
}
} catch (Exception e) {
e.printStackTrace();
} finally {
if(wrapper != null) {
wrapper.cleanUp();
}
}
}
return list;
}
// /** TODO remove
// * Gets the list of all capabilities for a selected functional area
// * @param sparqlQuery String containing the query to get all capabilities for a selected functional area
// * @return capabilities Vector containing list of all capabilities for a selected functional area
// */
// public static Vector getList(IEngine engine, String type, String sparqlQuery)
// {
// Vector retList=new Vector();
// try{
// EntityFiller filler = new EntityFiller();
// filler.engineName = engine.getEngineName();
// filler.type = type;
// filler.setExternalQuery(sparqlQuery);
// filler.run();
// Vector names = filler.nameVector;
// for (int i = 0;i runQuery (IEngine engine, String query){
ArrayList
© 2015 - 2025 Weber Informatics LLC | Privacy Policy