12 changed files with 178 additions and 119 deletions
@ -1,19 +1,20 @@
|
||||
package dto; |
||||
|
||||
import java.net.URISyntaxException; |
||||
import org.json.JSONException; |
||||
import org.json.JSONObject; |
||||
|
||||
import static constants.HttpHeaders.AUTHORIZATION_STRING; |
||||
|
||||
public class BrewObjPayload { |
||||
public static BrewObj constructScanPayload(JSONObject brewObj) throws URISyntaxException { |
||||
|
||||
public static BrewObj constructScanPayload(JSONObject jsonObj) throws JSONException { |
||||
return new BrewObj( |
||||
brewObj.getString("buildSystemType"), |
||||
brewObj.getString("brewId"), |
||||
brewObj.getString("brewNVR"), |
||||
brewObj.getString("pncId"), |
||||
brewObj.getString("artifactType"), |
||||
brewObj.getString("fileName"), |
||||
brewObj.getBoolean("builtfromSource")); |
||||
jsonObj.getString("buildSystemType"), |
||||
jsonObj.getString("brewId"), |
||||
jsonObj.getString("brewNVR"), |
||||
jsonObj.getString("pncId"), |
||||
jsonObj.getString("artifactType"), |
||||
jsonObj.getString("fileName"), |
||||
jsonObj.getBoolean("builtfromSource")); |
||||
} |
||||
|
||||
private BrewObjPayload() {} |
||||
} |
||||
|
||||
@ -1,16 +1,17 @@
|
||||
package dto; |
||||
|
||||
import java.net.URISyntaxException; |
||||
import org.json.JSONException; |
||||
import org.json.JSONObject; |
||||
|
||||
import static constants.HttpHeaders.AUTHORIZATION_STRING; |
||||
|
||||
public class GitObjPayload { |
||||
public static GitObj constructScanPayload(JSONObject gitObj) throws URISyntaxException { |
||||
|
||||
public static GitObj constructScanPayload(JSONObject jsonObj) throws JSONException { |
||||
return new GitObj( |
||||
gitObj.getString("buildSystemType"), |
||||
gitObj.getString("repository"), |
||||
gitObj.getString("reference"), |
||||
gitObj.getString("commitId")); |
||||
jsonObj.getString("buildSystemType"), |
||||
jsonObj.getString("repository"), |
||||
jsonObj.getString("reference"), |
||||
jsonObj.getString("commitId")); |
||||
} |
||||
|
||||
private GitObjPayload() {} |
||||
} |
||||
|
||||
@ -1,14 +1,15 @@
|
||||
package dto; |
||||
|
||||
import java.net.URISyntaxException; |
||||
import org.json.JSONException; |
||||
import org.json.JSONObject; |
||||
|
||||
import static constants.HttpHeaders.AUTHORIZATION_STRING; |
||||
|
||||
public class PncObjPayload { |
||||
public static PncObj constructScanPayload(JSONObject pncObj) throws URISyntaxException { |
||||
|
||||
public static PncObj constructScanPayload(JSONObject jsonObj) throws JSONException { |
||||
return new PncObj( |
||||
pncObj.getString("buildSystemType"), |
||||
pncObj.getString("buildId")); |
||||
jsonObj.getString("buildSystemType"), |
||||
jsonObj.getString("buildId")); |
||||
} |
||||
|
||||
private PncObjPayload() {} |
||||
} |
||||
|
||||
@ -1,15 +1,17 @@
|
||||
package dto; |
||||
|
||||
import java.net.URISyntaxException; |
||||
import org.json.JSONException; |
||||
import org.json.JSONObject; |
||||
|
||||
public class ScanObjPayload { |
||||
public static ScanObj constructScanPayload(JSONObject scanObj) throws URISyntaxException { |
||||
public static ScanObj constructScanPayload(JSONObject jsonObj) throws JSONException { |
||||
return new ScanObj( |
||||
scanObj.getString("scanID"), |
||||
scanObj.getString("offeringId"), |
||||
scanObj.getString("eventID"), |
||||
scanObj.getString("isManagedService"), |
||||
scanObj.getString("componentList")); |
||||
jsonObj.getString("scanID"), |
||||
jsonObj.getString("offeringId"), |
||||
jsonObj.getString("eventID"), |
||||
jsonObj.getString("isManagedService"), |
||||
jsonObj.getString("componentList")); |
||||
} |
||||
|
||||
private ScanObjPayload() {} |
||||
} |
||||
|
||||
@ -1,70 +1,38 @@
|
||||
package rest; |
||||
|
||||
import dto.ConnectDB; |
||||
|
||||
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.PreparedStatement; |
||||
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 { |
||||
public boolean invokeScanAnalyze(@PathParam("scanId") String scanId) { |
||||
Boolean rc = false; |
||||
//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
|
||||
String qry = "DELETE FROM scans WHERE scanid=?"; |
||||
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
|
||||
conn.close(); |
||||
} catch (SQLException e){ |
||||
System.out.println(e); |
||||
} |
||||
success = true; |
||||
return success; |
||||
try(Connection conn = connectDB.connect(); |
||||
PreparedStatement pstmt = conn.prepareStatement(qry)) { |
||||
pstmt.setString(1, scanId); |
||||
pstmt.executeUpdate(); |
||||
rc = true; |
||||
} catch (SQLException e) { |
||||
System.out.println(e.getMessage()); |
||||
} |
||||
return rc; |
||||
} |
||||
} |
||||
|
||||
@ -0,0 +1,75 @@
|
||||
package dto; |
||||
|
||||
import org.json.JSONObject; |
||||
import org.junit.jupiter.api.Test; |
||||
|
||||
class TestPayload { |
||||
|
||||
@Test |
||||
void TestBrew() { |
||||
JSONObject jsonObject = new JSONObject(); |
||||
jsonObject.put("buildSystemType", "brew"); |
||||
jsonObject.put("brewId", "1"); |
||||
jsonObject.put("brewNVR", "1.1.0"); |
||||
jsonObject.put("pncId", "153"); |
||||
jsonObject.put("artifactType", "arti1"); |
||||
jsonObject.put("fileName", "myfile1"); |
||||
jsonObject.put("builtfromSource", true); |
||||
|
||||
BrewObj brewObj1 = BrewObjPayload.constructScanPayload(jsonObject); |
||||
BrewObj brewObj2 = new BrewObj( |
||||
jsonObject.getString("buildSystemType"), |
||||
jsonObject.getString("brewId"), |
||||
jsonObject.getString("brewNVR"), |
||||
jsonObject.getString("pncId"), |
||||
jsonObject.getString("artifactType"), |
||||
jsonObject.getString("fileName"), |
||||
jsonObject.getBoolean("builtfromSource")); |
||||
System.out.println("BrewObj1: " + brewObj1.toString()); |
||||
System.out.println("BrewObj2: " + brewObj2.toString()); |
||||
assert(brewObj1.getBuildSystemType().equals(brewObj2.getBuildSystemType())); |
||||
assert(brewObj1.getBrewId().equals(brewObj2.getBrewId())); |
||||
assert(brewObj1.getBrewNvr().equals(brewObj2.getBrewNvr())); |
||||
assert(brewObj1.getPncId().equals(brewObj2.getPncId())); |
||||
assert(brewObj1.getArtifactType().equals(brewObj2.getArtifactType())); |
||||
assert(brewObj1.getFileName().equals(brewObj2.getFileName())); |
||||
assert(brewObj1.getBuiltFromSource() == brewObj2.getBuiltFromSource()); |
||||
} |
||||
|
||||
@Test |
||||
void TestGit() { |
||||
JSONObject jsonObject = new JSONObject(); |
||||
jsonObject.put("buildSystemType", "git"); |
||||
jsonObject.put("repository", "repo"); |
||||
jsonObject.put("reference", "ref"); |
||||
jsonObject.put("commitId", "comid"); |
||||
|
||||
GitObj gitObj1 = GitObjPayload.constructScanPayload(jsonObject); |
||||
GitObj gitObj2 = new GitObj( |
||||
jsonObject.getString("buildSystemType"), |
||||
jsonObject.getString("repository"), |
||||
jsonObject.getString("reference"), |
||||
jsonObject.getString("commitId")); |
||||
System.out.println("GitObj1: " + gitObj1.toString()); |
||||
System.out.println("GitObj2: " + gitObj2.toString()); |
||||
assert(gitObj1.getBuildSystemType().equals(gitObj2.getBuildSystemType())); |
||||
assert(gitObj1.getRepository().equals(gitObj2.getRepository())); |
||||
assert(gitObj1.getReference().equals(gitObj2.getReference())); |
||||
assert(gitObj1.getCommitId().equals(gitObj2.getCommitId())); |
||||
} |
||||
|
||||
@Test |
||||
void TestPnc() { |
||||
JSONObject jsonObject = new JSONObject(); |
||||
jsonObject.put("buildSystemType", "pnc"); |
||||
jsonObject.put("buildId", "153"); |
||||
|
||||
PncObj pncObj1 = PncObjPayload.constructScanPayload(jsonObject); |
||||
PncObj pncObj2 = new PncObj(jsonObject.getString("buildSystemType"), jsonObject.getString("buildId")); |
||||
System.out.println("PncObj1: " + pncObj1.toString()); |
||||
System.out.println("PncObj2: " + pncObj2.toString()); |
||||
assert(pncObj1.getBuildSystemType().equals(pncObj2.getBuildSystemType())); |
||||
assert(pncObj1.getBuildId().equals(pncObj2.getBuildId())); |
||||
} |
||||
|
||||
} |
||||
Loading…
Reference in new issue