6 changed files with 252 additions and 0 deletions
@ -0,0 +1,23 @@ |
|||||||
|
package dto; |
||||||
|
|
||||||
|
import lombok.AllArgsConstructor; |
||||||
|
import lombok.Builder; |
||||||
|
import lombok.Getter; |
||||||
|
import lombok.ToString; |
||||||
|
import lombok.extern.jackson.Jacksonized; |
||||||
|
|
||||||
|
// import org.jboss.pnc.api.dto.Request;
|
||||||
|
|
||||||
|
import java.io.Serializable; |
||||||
|
|
||||||
|
@ToString |
||||||
|
@Getter |
||||||
|
@AllArgsConstructor |
||||||
|
@Jacksonized |
||||||
|
@Builder |
||||||
|
public class GitObj implements Serializable { |
||||||
|
public String buildSystemType; |
||||||
|
public String repository; |
||||||
|
public String reference; |
||||||
|
public String commitId; |
||||||
|
} |
||||||
@ -0,0 +1,23 @@ |
|||||||
|
package dto; |
||||||
|
|
||||||
|
import org.eclipse.microprofile.config.ConfigProvider; |
||||||
|
// import org.jboss.pnc.api.deliverablesanalyzer.dto.AnalyzePayload;
|
||||||
|
// import org.jboss.pnc.api.dto.HeartbeatConfig;
|
||||||
|
// import org.jboss.pnc.api.dto.Request;
|
||||||
|
|
||||||
|
import java.net.URI; |
||||||
|
import java.net.URISyntaxException; |
||||||
|
import java.nio.charset.StandardCharsets; |
||||||
|
import java.sql.Struct; |
||||||
|
import java.util.*; |
||||||
|
|
||||||
|
import org.json.JSONObject; |
||||||
|
import org.json.JSONArray; |
||||||
|
|
||||||
|
import static constants.HttpHeaders.AUTHORIZATION_STRING; |
||||||
|
|
||||||
|
public class GitObjPayload { |
||||||
|
public static GitObj constructScanPayload(JSONObject gitObj) throws URISyntaxException { |
||||||
|
return new GitObj(gitObj.getString("buildSystemType"),gitObj.getString("repository"),gitObj.getString("reference"),gitObj.getString("commitId")); |
||||||
|
} |
||||||
|
} |
||||||
@ -0,0 +1,21 @@ |
|||||||
|
package dto; |
||||||
|
|
||||||
|
import lombok.AllArgsConstructor; |
||||||
|
import lombok.Builder; |
||||||
|
import lombok.Getter; |
||||||
|
import lombok.ToString; |
||||||
|
import lombok.extern.jackson.Jacksonized; |
||||||
|
|
||||||
|
// import org.jboss.pnc.api.dto.Request;
|
||||||
|
|
||||||
|
import java.io.Serializable; |
||||||
|
|
||||||
|
@ToString |
||||||
|
@Getter |
||||||
|
@AllArgsConstructor |
||||||
|
@Jacksonized |
||||||
|
@Builder |
||||||
|
public class PncObj implements Serializable { |
||||||
|
public String buildSystemType; |
||||||
|
public String buildId; |
||||||
|
} |
||||||
@ -0,0 +1,23 @@ |
|||||||
|
package dto; |
||||||
|
|
||||||
|
import org.eclipse.microprofile.config.ConfigProvider; |
||||||
|
// import org.jboss.pnc.api.deliverablesanalyzer.dto.AnalyzePayload;
|
||||||
|
// import org.jboss.pnc.api.dto.HeartbeatConfig;
|
||||||
|
// import org.jboss.pnc.api.dto.Request;
|
||||||
|
|
||||||
|
import java.net.URI; |
||||||
|
import java.net.URISyntaxException; |
||||||
|
import java.nio.charset.StandardCharsets; |
||||||
|
import java.sql.Struct; |
||||||
|
import java.util.*; |
||||||
|
|
||||||
|
import org.json.JSONObject; |
||||||
|
import org.json.JSONArray; |
||||||
|
|
||||||
|
import static constants.HttpHeaders.AUTHORIZATION_STRING; |
||||||
|
|
||||||
|
public class PncObjPayload { |
||||||
|
public static PncObj constructScanPayload(JSONObject pncObj) throws URISyntaxException { |
||||||
|
return new PncObj(pncObj.getString("buildSystemType"),pncObj.getString("buildId")); |
||||||
|
} |
||||||
|
} |
||||||
@ -0,0 +1,90 @@ |
|||||||
|
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 javax.ws.rs.PUT; |
||||||
|
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.ConnectDB; |
||||||
|
import dto.ScanObjPayload; |
||||||
|
|
||||||
|
import javax.ws.rs.PathParam; |
||||||
|
|
||||||
|
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("/startScan") |
||||||
|
public class CreateStartScan { |
||||||
|
|
||||||
|
// @Inject
|
||||||
|
@RestClient |
||||||
|
CreateScanService createScanService; |
||||||
|
// ScanObjPayload scanObjPayload;
|
||||||
|
|
||||||
|
@PUT |
||||||
|
@Path("/{scanId}") |
||||||
|
public ScanObj invokeScanAnalyze(@PathParam("scanId") String scanId) throws URISyntaxException { |
||||||
|
ConnectDB connectDB = new ConnectDB(); |
||||||
|
Connection conn = connectDB.connect(); |
||||||
|
//this is ugly needs to berewritten
|
||||||
|
Statement stmt = null; |
||||||
|
ScanObj finalScan = null; |
||||||
|
|
||||||
|
String sql = "SELECT * FROM scans WHERE scanid=" + scanId; |
||||||
|
//need to add figure out an archieve system and wether its nessacery (archieve value??)
|
||||||
|
try{ |
||||||
|
stmt = conn.createStatement(); |
||||||
|
//terrible solution has to be a better way of doing this
|
||||||
|
ResultSet rs = stmt.executeQuery(sql); |
||||||
|
|
||||||
|
//fix for individual results (not resultset)
|
||||||
|
String a = null; |
||||||
|
String b = null; |
||||||
|
String c = null; |
||||||
|
String d = null; |
||||||
|
String e = null; |
||||||
|
while (rs.next()) { |
||||||
|
a = rs.getString("scanid"); |
||||||
|
b = rs.getString("productid"); |
||||||
|
c = rs.getString("eventid"); |
||||||
|
d = rs.getString("ismanagedservice"); |
||||||
|
e = rs.getString("componentlist"); |
||||||
|
} |
||||||
|
//TODO: need to add unique keys to DBs
|
||||||
|
finalScan = new ScanObj(a,b,c,d,e); |
||||||
|
String copySql = "INSERT INTO archive (scanid, productid, eventid, ismanagedservice, componentlist) VALUES ('" +finalScan.scanId+"', '"+finalScan.productId+"', '"+finalScan.eventId+"', '"+finalScan.isManagedService+"', '"+finalScan.componentList+"')"; |
||||||
|
stmt.executeUpdate(copySql); |
||||||
|
|
||||||
|
//TODO add proper checks
|
||||||
|
String deleteSql = "DELETE FROM scans WHERE scanid=" + scanId; |
||||||
|
stmt.executeUpdate(deleteSql); |
||||||
|
|
||||||
|
//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
|
||||||
|
|
||||||
|
} catch (SQLException e){ |
||||||
|
System.out.println(e); |
||||||
|
} |
||||||
|
return finalScan; |
||||||
|
} |
||||||
|
} |
||||||
@ -0,0 +1,72 @@ |
|||||||
|
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 javax.ws.rs.PUT; |
||||||
|
import javax.ws.rs.DELETE; |
||||||
|
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.ConnectDB; |
||||||
|
import dto.ScanObjPayload; |
||||||
|
|
||||||
|
import javax.ws.rs.PathParam; |
||||||
|
|
||||||
|
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("/deleteScan") |
||||||
|
public class RemoveScan { |
||||||
|
|
||||||
|
// @Inject
|
||||||
|
@RestClient |
||||||
|
CreateScanService createScanService; |
||||||
|
// ScanObjPayload scanObjPayload;
|
||||||
|
|
||||||
|
@DELETE |
||||||
|
@Path("/{scanId}") |
||||||
|
public boolean invokeScanAnalyze(@PathParam("scanId") String scanId) throws URISyntaxException { |
||||||
|
ConnectDB connectDB = new ConnectDB(); |
||||||
|
Connection conn = connectDB.connect(); |
||||||
|
//this is ugly needs to berewritten
|
||||||
|
Statement stmt = null; |
||||||
|
ScanObj finalScan = null; |
||||||
|
//fix this
|
||||||
|
Boolean success = false; |
||||||
|
String sql = "DELETE FROM scans WHERE scanid=" + scanId; |
||||||
|
//need to add figure out an archieve system and wether its nessacery (archieve value??)
|
||||||
|
try{ |
||||||
|
stmt = conn.createStatement(); |
||||||
|
|
||||||
|
//TODO add proper checks
|
||||||
|
stmt.executeUpdate(sql); |
||||||
|
|
||||||
|
//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
|
||||||
|
|
||||||
|
} catch (SQLException e){ |
||||||
|
System.out.println(e); |
||||||
|
} |
||||||
|
success = true; |
||||||
|
return success; |
||||||
|
} |
||||||
|
} |
||||||
Loading…
Reference in new issue