You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

112 lines
3.9 KiB

package rest;
import org.eclipse.microprofile.rest.client.inject.RestClient;
import dto.ScanObj;
import javax.inject.Inject;
import javax.validation.Valid;
import javax.ws.rs.Consumes;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.UUID;
import org.json.JSONObject;
import org.json.JSONArray;
import dto.ScanObj;
import dto.BrewObj;
import dto.ConnectDB;
import dto.ScanObjPayload;
import dto.BrewObjPayload;
import dto.GitObj;
import dto.GitObjPayload;
import dto.PncObj;
import dto.PncObjPayload;
import static constants.HttpHeaders.AUTHORIZATION_STRING;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
@Path("/scanRequest")
public class CreateScanRequest {
//all of these need cleaning up to be a more sensible soution
@RestClient
CreateScanService createScanService;
@POST
@Path("/brew")
@Consumes({ "application/json" })
//in theory should take List<String> to clean it up
public BrewObj invokeScanAnalyze(@Valid String scanInvocation) throws URISyntaxException {
JSONObject jsonData = new JSONObject(scanInvocation);
BrewObj brewObj = BrewObjPayload.constructScanPayload(jsonData);
ConnectDB connectDB = new ConnectDB();
Connection conn = connectDB.connect();
Statement stmt = null;
String sql = "INSERT INTO brewscans (buildsystemtype, brewid, brewnvr, pncid, artifacttype, filename, builtfromsource) VALUES ('"+brewObj.buildSystemType+"','"+brewObj.brewId+"','"+brewObj.brewNvr+"','"+brewObj.pncId+"','"+brewObj.artifactType+"','"+brewObj.fileName+"','"+brewObj.buildFromSource+"')";
try{
stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery(sql);
conn.close();
} catch (SQLException e){
System.out.println(e);
}
return brewObj;
}
@POST
@Path("/git")
@Consumes({ "application/json" })
public void invokeGitScanAnalyze(@Valid String scanInvocation)throws URISyntaxException {
throw new UnsupportedOperationException("unImplemented fucntionality");
// JSONObject jsonData = new JSONObject(scanInvocation);
// GitObj gitObj = GitObjPayload.constructScanPayload(jsonData);
// ConnectDB connectDB = new ConnectDB();
// Connection conn = connectDB.connect();
// Statement stmt = null;
// String sql = "INSERT INTO gitscans (buildsystemtype, repository, reference, commitid) VALUES ('"+gitObj.buildSystemType+"','"+gitObj.repository+"','"+gitObj.reference+"','"+gitObj.commitId+"')";
// try{
// stmt = conn.createStatement();
// ResultSet rs = stmt.executeQuery(sql);
// conn.close();
// } catch (SQLException e){
// System.out.println(e);
// }
// return gitObj;
}
@POST
@Path("/pnc")
@Consumes({ "application/json" })
public void invokePncScanAnalyze(@Valid String scanInvocation)throws URISyntaxException {
throw new UnsupportedOperationException("unImplemented fucntionality");
// JSONObject jsonData = new JSONObject(scanInvocation);
// PncObj pncObj = PncObjPayload.constructScanPayload(jsonData);
// ConnectDB connectDB = new ConnectDB();
// Connection conn = connectDB.connect();
// Statement stmt = null;
// String sql = "INSERT INTO pncscans (buildsystemtype, buildid) VALUES ('"+pncObj.buildSystemType+"','"+pncObj.buildId+"')";
// try{
// stmt = conn.createStatement();
// ResultSet rs = stmt.executeQuery(sql);
// conn.close();
// } catch (SQLException e){
// System.out.println(e);
// }
// return pncObj;
}
}