12 changed files with 178 additions and 119 deletions
@ -1,19 +1,20 @@ |
|||||||
package dto; |
package dto; |
||||||
|
|
||||||
import java.net.URISyntaxException; |
import org.json.JSONException; |
||||||
import org.json.JSONObject; |
import org.json.JSONObject; |
||||||
|
|
||||||
import static constants.HttpHeaders.AUTHORIZATION_STRING; |
|
||||||
|
|
||||||
public class BrewObjPayload { |
public class BrewObjPayload { |
||||||
public static BrewObj constructScanPayload(JSONObject brewObj) throws URISyntaxException { |
|
||||||
|
public static BrewObj constructScanPayload(JSONObject jsonObj) throws JSONException { |
||||||
return new BrewObj( |
return new BrewObj( |
||||||
brewObj.getString("buildSystemType"), |
jsonObj.getString("buildSystemType"), |
||||||
brewObj.getString("brewId"), |
jsonObj.getString("brewId"), |
||||||
brewObj.getString("brewNVR"), |
jsonObj.getString("brewNVR"), |
||||||
brewObj.getString("pncId"), |
jsonObj.getString("pncId"), |
||||||
brewObj.getString("artifactType"), |
jsonObj.getString("artifactType"), |
||||||
brewObj.getString("fileName"), |
jsonObj.getString("fileName"), |
||||||
brewObj.getBoolean("builtfromSource")); |
jsonObj.getBoolean("builtfromSource")); |
||||||
} |
} |
||||||
|
|
||||||
|
private BrewObjPayload() {} |
||||||
} |
} |
||||||
|
|||||||
@ -1,16 +1,17 @@ |
|||||||
package dto; |
package dto; |
||||||
|
|
||||||
import java.net.URISyntaxException; |
import org.json.JSONException; |
||||||
import org.json.JSONObject; |
import org.json.JSONObject; |
||||||
|
|
||||||
import static constants.HttpHeaders.AUTHORIZATION_STRING; |
|
||||||
|
|
||||||
public class GitObjPayload { |
public class GitObjPayload { |
||||||
public static GitObj constructScanPayload(JSONObject gitObj) throws URISyntaxException { |
|
||||||
|
public static GitObj constructScanPayload(JSONObject jsonObj) throws JSONException { |
||||||
return new GitObj( |
return new GitObj( |
||||||
gitObj.getString("buildSystemType"), |
jsonObj.getString("buildSystemType"), |
||||||
gitObj.getString("repository"), |
jsonObj.getString("repository"), |
||||||
gitObj.getString("reference"), |
jsonObj.getString("reference"), |
||||||
gitObj.getString("commitId")); |
jsonObj.getString("commitId")); |
||||||
} |
} |
||||||
|
|
||||||
|
private GitObjPayload() {} |
||||||
} |
} |
||||||
|
|||||||
@ -1,14 +1,15 @@ |
|||||||
package dto; |
package dto; |
||||||
|
|
||||||
import java.net.URISyntaxException; |
import org.json.JSONException; |
||||||
import org.json.JSONObject; |
import org.json.JSONObject; |
||||||
|
|
||||||
import static constants.HttpHeaders.AUTHORIZATION_STRING; |
|
||||||
|
|
||||||
public class PncObjPayload { |
public class PncObjPayload { |
||||||
public static PncObj constructScanPayload(JSONObject pncObj) throws URISyntaxException { |
|
||||||
|
public static PncObj constructScanPayload(JSONObject jsonObj) throws JSONException { |
||||||
return new PncObj( |
return new PncObj( |
||||||
pncObj.getString("buildSystemType"), |
jsonObj.getString("buildSystemType"), |
||||||
pncObj.getString("buildId")); |
jsonObj.getString("buildId")); |
||||||
} |
} |
||||||
|
|
||||||
|
private PncObjPayload() {} |
||||||
} |
} |
||||||
|
|||||||
@ -1,15 +1,17 @@ |
|||||||
package dto; |
package dto; |
||||||
|
|
||||||
import java.net.URISyntaxException; |
import org.json.JSONException; |
||||||
import org.json.JSONObject; |
import org.json.JSONObject; |
||||||
|
|
||||||
public class ScanObjPayload { |
public class ScanObjPayload { |
||||||
public static ScanObj constructScanPayload(JSONObject scanObj) throws URISyntaxException { |
public static ScanObj constructScanPayload(JSONObject jsonObj) throws JSONException { |
||||||
return new ScanObj( |
return new ScanObj( |
||||||
scanObj.getString("scanID"), |
jsonObj.getString("scanID"), |
||||||
scanObj.getString("offeringId"), |
jsonObj.getString("offeringId"), |
||||||
scanObj.getString("eventID"), |
jsonObj.getString("eventID"), |
||||||
scanObj.getString("isManagedService"), |
jsonObj.getString("isManagedService"), |
||||||
scanObj.getString("componentList")); |
jsonObj.getString("componentList")); |
||||||
} |
} |
||||||
|
|
||||||
|
private ScanObjPayload() {} |
||||||
} |
} |
||||||
|
|||||||
@ -1,70 +1,38 @@ |
|||||||
package rest; |
package rest; |
||||||
|
|
||||||
|
import dto.ConnectDB; |
||||||
|
|
||||||
import org.eclipse.microprofile.rest.client.inject.RestClient; |
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.Path; |
||||||
import javax.ws.rs.PUT; |
|
||||||
import javax.ws.rs.DELETE; |
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 javax.ws.rs.PathParam; |
||||||
|
|
||||||
import static constants.HttpHeaders.AUTHORIZATION_STRING; |
|
||||||
import java.sql.Connection; |
import java.sql.Connection; |
||||||
import java.sql.DriverManager; |
import java.sql.PreparedStatement; |
||||||
import java.sql.SQLException; |
import java.sql.SQLException; |
||||||
|
|
||||||
import java.sql.Connection; |
|
||||||
import java.sql.DriverManager; |
|
||||||
import java.sql.ResultSet; |
|
||||||
import java.sql.Statement; |
|
||||||
|
|
||||||
@Path("/deleteScan") |
@Path("/deleteScan") |
||||||
public class RemoveScan { |
public class RemoveScan { |
||||||
|
|
||||||
// @Inject
|
// @Inject
|
||||||
@RestClient |
@RestClient |
||||||
CreateScanService createScanService; |
CreateScanService createScanService; |
||||||
// ScanObjPayload scanObjPayload;
|
|
||||||
|
|
||||||
@DELETE |
@DELETE |
||||||
@Path("/{scanId}") |
@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(); |
ConnectDB connectDB = new ConnectDB(); |
||||||
Connection conn = connectDB.connect(); |
try(Connection conn = connectDB.connect(); |
||||||
//this is ugly needs to berewritten
|
PreparedStatement pstmt = conn.prepareStatement(qry)) { |
||||||
Statement stmt = null; |
pstmt.setString(1, scanId); |
||||||
ScanObj finalScan = null; |
pstmt.executeUpdate(); |
||||||
//fix this
|
rc = true; |
||||||
Boolean success = false; |
} catch (SQLException e) { |
||||||
String sql = "DELETE FROM scans WHERE scanid=" + scanId; |
System.out.println(e.getMessage()); |
||||||
//need to add figure out an archieve system and wether its nessacery (archieve value??)
|
} |
||||||
try{ |
return rc; |
||||||
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; |
|
||||||
} |
} |
||||||
} |
} |
||||||
|
|||||||
@ -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