Browse Source

updated exceptions to throw on unimplemented fu nctionality

exception_work
Nicholas Caughey 3 years ago
parent
commit
5de2051b86
  1. 65
      src/main/java/rest/CreateScanRequest.java
  2. 33
      src/main/java/rest/CreateScanResource.java
  3. 56
      src/main/java/rest/CreateStartScan.java

65
src/main/java/rest/CreateScanRequest.java

@ -68,44 +68,45 @@ public class CreateScanRequest {
@POST @POST
@Path("/git") @Path("/git")
@Consumes({ "application/json" }) @Consumes({ "application/json" })
public GitObj invokeGitScanAnalyze(@Valid String scanInvocation)throws URISyntaxException { public void invokeGitScanAnalyze(@Valid String scanInvocation)throws URISyntaxException {
throw new exception ("unImplemented fucntionality"); throw new UnsupportedOperationException("unImplemented fucntionality");
JSONObject jsonData = new JSONObject(scanInvocation);
GitObj gitObj = GitObjPayload.constructScanPayload(jsonData);
ConnectDB connectDB = new ConnectDB(); // JSONObject jsonData = new JSONObject(scanInvocation);
Connection conn = connectDB.connect(); // GitObj gitObj = GitObjPayload.constructScanPayload(jsonData);
Statement stmt = null;
String sql = "INSERT INTO gitscans (buildsystemtype, repository, reference, commitid) VALUES ('"+gitObj.buildSystemType+"','"+gitObj.repository+"','"+gitObj.reference+"','"+gitObj.commitId+"')"; // ConnectDB connectDB = new ConnectDB();
try{ // Connection conn = connectDB.connect();
stmt = conn.createStatement(); // Statement stmt = null;
ResultSet rs = stmt.executeQuery(sql); // String sql = "INSERT INTO gitscans (buildsystemtype, repository, reference, commitid) VALUES ('"+gitObj.buildSystemType+"','"+gitObj.repository+"','"+gitObj.reference+"','"+gitObj.commitId+"')";
conn.close(); // try{
} catch (SQLException e){ // stmt = conn.createStatement();
System.out.println(e); // ResultSet rs = stmt.executeQuery(sql);
} // conn.close();
return gitObj; // } catch (SQLException e){
// System.out.println(e);
// }
// return gitObj;
} }
@POST @POST
@Path("/pnc") @Path("/pnc")
@Consumes({ "application/json" }) @Consumes({ "application/json" })
public PncObj invokePncScanAnalyze(@Valid String scanInvocation)throws URISyntaxException { public void invokePncScanAnalyze(@Valid String scanInvocation)throws URISyntaxException {
throw new exception ("unImplemented fucntionality"); throw new UnsupportedOperationException("unImplemented fucntionality");
JSONObject jsonData = new JSONObject(scanInvocation); // JSONObject jsonData = new JSONObject(scanInvocation);
PncObj pncObj = PncObjPayload.constructScanPayload(jsonData); // PncObj pncObj = PncObjPayload.constructScanPayload(jsonData);
ConnectDB connectDB = new ConnectDB(); // ConnectDB connectDB = new ConnectDB();
Connection conn = connectDB.connect(); // Connection conn = connectDB.connect();
Statement stmt = null; // Statement stmt = null;
String sql = "INSERT INTO pncscans (buildsystemtype, buildid) VALUES ('"+pncObj.buildSystemType+"','"+pncObj.buildId+"')"; // String sql = "INSERT INTO pncscans (buildsystemtype, buildid) VALUES ('"+pncObj.buildSystemType+"','"+pncObj.buildId+"')";
try{ // try{
stmt = conn.createStatement(); // stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery(sql); // ResultSet rs = stmt.executeQuery(sql);
conn.close(); // conn.close();
} catch (SQLException e){ // } catch (SQLException e){
System.out.println(e); // System.out.println(e);
} // }
return pncObj; // return pncObj;
} }
} }

33
src/main/java/rest/CreateScanResource.java

@ -39,22 +39,21 @@ public class CreateScanResource {
@POST @POST
@Consumes({ "application/json" }) @Consumes({ "application/json" })
//in theory should take List<String> to clean it up //in theory should take List<String> to clean it up
public ScanObj invokeScanAnalyze(@Valid String scanInvocation) throws URISyntaxException { public void invokeScanAnalyze(@Valid String scanInvocation) throws URISyntaxException {
throw new exception ("unImplemented fucntionality"); throw new UnsupportedOperationException("unImplemented fucntionality");
// JSONObject jsonData = new JSONObject(scanInvocation);
JSONObject jsonData = new JSONObject(scanInvocation); // ScanObj scanObj = ScanObjPayload.constructScanPayload(jsonData);
ScanObj scanObj = ScanObjPayload.constructScanPayload(jsonData); // ConnectDB connectDB = new ConnectDB();
ConnectDB connectDB = new ConnectDB(); // Connection conn = connectDB.connect();
Connection conn = connectDB.connect(); // Statement stmt = null;
Statement stmt = null; // String sql = "INSERT INTO scans (scanid, productid, eventid, ismanagedservice, componentlist) VALUES ('" +scanObj.scanId+"', '"+scanObj.productId+"', '"+scanObj.eventId+"', '"+scanObj.isManagedService+"', '"+scanObj.componentList+"')";
String sql = "INSERT INTO scans (scanid, productid, eventid, ismanagedservice, componentlist) VALUES ('" +scanObj.scanId+"', '"+scanObj.productId+"', '"+scanObj.eventId+"', '"+scanObj.isManagedService+"', '"+scanObj.componentList+"')"; // try{
try{ // stmt = conn.createStatement();
stmt = conn.createStatement(); // ResultSet rs = stmt.executeQuery(sql);
ResultSet rs = stmt.executeQuery(sql); // conn.close();
conn.close(); // } catch (SQLException e){
} catch (SQLException e){ // System.out.println(e);
System.out.println(e); // }
} // return scanObj;
return scanObj;
} }
} }

56
src/main/java/rest/CreateStartScan.java

@ -41,37 +41,37 @@ public class CreateStartScan {
@PUT @PUT
@Path("/{scanId}") @Path("/{scanId}")
public ScanObj invokeScanAnalyze(@PathParam("scanId") String scanId) throws URISyntaxException { public void invokeScanAnalyze(@PathParam("scanId") String scanId) throws URISyntaxException {
throw new exception ("unImplemented fucntionality"); throw new UnsupportedOperationException("unImplemented fucntionality");
ConnectDB connectDB = new ConnectDB(); // ConnectDB connectDB = new ConnectDB();
Connection conn = connectDB.connect(); // Connection conn = connectDB.connect();
//this is ugly needs to berewritten // //this is ugly needs to berewritten
Statement stmt = null; // Statement stmt = null;
ScanObj finalScan = null; // ScanObj finalScan = null;
String sql = "SELECT * FROM scans WHERE scanid=" + scanId; // String sql = "SELECT * FROM scans WHERE scanid=" + scanId;
//need to add figure out an archieve system and wether its nessacery (archieve value??) // //need to add figure out an archieve system and wether its nessacery (archieve value??)
try{ // try{
stmt = conn.createStatement(); // stmt = conn.createStatement();
//terrible solution has to be a better way of doing this // //terrible solution has to be a better way of doing this
ResultSet rs = stmt.executeQuery(sql); // ResultSet rs = stmt.executeQuery(sql);
//fix for individual results (not resultset) // //fix for individual results (not resultset)
//TODO: need to add unique keys to DBs // //TODO: need to add unique keys to DBs
finalScan = new ScanObj(rs.getString("scanid"),rs.getString("productid"),rs.getString("eventid"),rs.getString("ismanagedservice"),rs.getString("componentlist")); // finalScan = new ScanObj(rs.getString("scanid"),rs.getString("productid"),rs.getString("eventid"),rs.getString("ismanagedservice"),rs.getString("componentlist"));
String copySql = "INSERT INTO archive (scanid, productid, eventid, ismanagedservice, componentlist) VALUES ('" +finalScan.scanId+"', '"+finalScan.productId+"', '"+finalScan.eventId+"', '"+finalScan.isManagedService+"', '"+finalScan.componentList+"')"; // String copySql = "INSERT INTO archive (scanid, productid, eventid, ismanagedservice, componentlist) VALUES ('" +finalScan.scanId+"', '"+finalScan.productId+"', '"+finalScan.eventId+"', '"+finalScan.isManagedService+"', '"+finalScan.componentList+"')";
stmt.executeUpdate(copySql); // stmt.executeUpdate(copySql);
//TODO add proper checks // //TODO add proper checks
String deleteSql = "DELETE FROM scans WHERE scanid=" + scanId; // String deleteSql = "DELETE FROM scans WHERE scanid=" + scanId;
stmt.executeUpdate(deleteSql); // stmt.executeUpdate(deleteSql);
//send task to the actual interface here using the resultset returned (should multiple scanids be allowed): // //send task to the actual interface here using the resultset returned (should multiple scanids be allowed):
//once the task is complete AND we have confirmation that the scan is done run the following sql // //once the task is complete AND we have confirmation that the scan is done run the following sql
conn.close(); // conn.close();
} catch (SQLException e){ // } catch (SQLException e){
System.out.println(e); // System.out.println(e);
} // }
return finalScan; // return finalScan;
} }
} }

Loading…
Cancel
Save