|
|
|
|
@ -1,66 +1,48 @@
|
|
|
|
|
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 java.sql.*; |
|
|
|
|
import org.json.JSONObject; |
|
|
|
|
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
|
|
|
|
|
// all of these need cleaning up to be a more sensible solution
|
|
|
|
|
@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 { |
|
|
|
|
// in theory should take List<String> to clean it up
|
|
|
|
|
public BrewObj invokeBrewScanAnalyze(@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); |
|
|
|
|
try(Connection conn = connectDB.connect(); |
|
|
|
|
PreparedStatement pstmt = conn.prepareStatement(BrewObj.SQL)) { |
|
|
|
|
pstmt.setString(1, brewObj.getBuildSystemType()); |
|
|
|
|
pstmt.setString(2, brewObj.getBrewId()); |
|
|
|
|
pstmt.setString(3, brewObj.getBrewNvr()); |
|
|
|
|
pstmt.setString(4, brewObj.getPncId()); |
|
|
|
|
pstmt.setString(5, brewObj.getArtifactType()); |
|
|
|
|
pstmt.setString(6, brewObj.getFileName()); |
|
|
|
|
pstmt.setBoolean(7, brewObj.getBuiltFromSource()); |
|
|
|
|
pstmt.executeUpdate(); |
|
|
|
|
} catch (SQLException e) { |
|
|
|
|
System.out.println(e.getMessage()); |
|
|
|
|
} |
|
|
|
|
return brewObj; |
|
|
|
|
} |
|
|
|
|
@ -71,18 +53,17 @@ public class CreateScanRequest {
|
|
|
|
|
public GitObj invokeGitScanAnalyze(@Valid String scanInvocation)throws URISyntaxException { |
|
|
|
|
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); |
|
|
|
|
} |
|
|
|
|
try(Connection conn = connectDB.connect(); |
|
|
|
|
PreparedStatement pstmt = conn.prepareStatement(GitObj.SQL)) { |
|
|
|
|
pstmt.setString(1, gitObj.getBuildSystemType()); |
|
|
|
|
pstmt.setString(2, gitObj.getRepository()); |
|
|
|
|
pstmt.setString(3, gitObj.getReference()); |
|
|
|
|
pstmt.setString(4, gitObj.getCommitId()); |
|
|
|
|
pstmt.executeUpdate(); |
|
|
|
|
} catch (SQLException e) { |
|
|
|
|
System.out.println(e.getMessage()); |
|
|
|
|
} |
|
|
|
|
return gitObj; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@ -92,18 +73,15 @@ public class CreateScanRequest {
|
|
|
|
|
public PncObj invokePncScanAnalyze(@Valid String scanInvocation)throws URISyntaxException { |
|
|
|
|
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); |
|
|
|
|
} |
|
|
|
|
try(Connection conn = connectDB.connect(); |
|
|
|
|
PreparedStatement pstmt = conn.prepareStatement(PncObj.SQL)) { |
|
|
|
|
pstmt.setString(1, pncObj.getBuildSystemType()); |
|
|
|
|
pstmt.setString(2, pncObj.getBuildId()); |
|
|
|
|
pstmt.executeUpdate(); |
|
|
|
|
} catch (SQLException e) { |
|
|
|
|
System.out.println(e.getMessage()); |
|
|
|
|
} |
|
|
|
|
return pncObj; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|