
prerna.reactor.utils.BQReactor Maven / Gradle / Ivy
The newest version!
package prerna.reactor.utils;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import prerna.engine.impl.rdbms.RDBMSNativeEngine;
import prerna.reactor.AbstractReactor;
import prerna.sablecc2.om.PixelDataType;
import prerna.sablecc2.om.PixelOperationType;
import prerna.sablecc2.om.nounmeta.NounMetadata;
import prerna.util.Constants;
import prerna.util.Utility;
public class BQReactor extends AbstractReactor {
private static final Logger classLogger = LogManager.getLogger(BQReactor.class);
public BQReactor() {
this.keysToGet = new String[]{"fancy"};
}
@Override
public NounMetadata execute() {
organizeKeys();
RDBMSNativeEngine engine = (RDBMSNativeEngine) Utility.getDatabase(Constants.LOCAL_MASTER_DB);
Connection conn = null;
try {
conn = engine.makeConnection();
} catch (SQLException e) {
classLogger.error(Constants.STACKTRACE, e);
throw new IllegalArgumentException("Could not make connection to engine.");
}
String embed = "";
Statement stmt = null;
try {
// check to see if such a fancy name exists
stmt = conn.createStatement();
String query = "SELECT embed from bitly where fancy='" + this.keyValue.get("fancy") + "'";
ResultSet rs = stmt.executeQuery(query);
// if there is a has next not sure what
if(rs.next()) {
embed = Utility.decodeURIComponent(rs.getString(1));
}
} catch (SQLException e) {
// TODO Auto-generated catch block
classLogger.error(Constants.STACKTRACE, e);
} finally {
if(stmt != null) {
try {
stmt.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
classLogger.error(Constants.STACKTRACE, e);
}
}
if(engine.isConnectionPooling() && conn != null) {
try {
conn.close();
} catch (SQLException e) {
classLogger.error(Constants.STACKTRACE, e);
}
}
}
if(!embed.isEmpty()) {
return new NounMetadata(embed, PixelDataType.CONST_STRING);
} else {
return new NounMetadata("No URL Found for " + this.keyValue.get("fancy"), PixelDataType.CONST_STRING, PixelOperationType.ERROR);
}
}
public String getName()
{
return "bq";
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy