You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
107 lines
3.8 KiB
107 lines
3.8 KiB
package rest; |
|
|
|
import dto.BrewObj; |
|
import dto.ConnectDB; |
|
import dto.BrewObjPayload; |
|
import dto.GitObj; |
|
import dto.GitObjPayload; |
|
import dto.PncObj; |
|
import dto.PncObjPayload; |
|
|
|
import org.eclipse.microprofile.rest.client.inject.RestClient; |
|
import org.json.JSONException; |
|
import org.json.JSONObject; |
|
import org.slf4j.Logger; |
|
import org.slf4j.LoggerFactory; |
|
|
|
import java.net.URISyntaxException; |
|
import io.quarkus.security.Authenticated; |
|
|
|
import javax.validation.Valid; |
|
import javax.ws.rs.Consumes; |
|
import javax.ws.rs.POST; |
|
import javax.ws.rs.Path; |
|
import java.sql.Connection; |
|
import java.sql.PreparedStatement; |
|
import java.sql.SQLException; |
|
|
|
@Authenticated |
|
@Path("/scanRequest") |
|
public class CreateScanRequest { |
|
|
|
private static final Logger logger = LoggerFactory.getLogger(CreateScanRequest.class); |
|
|
|
@RestClient |
|
CreateScanService createScanService; |
|
GreetingResource greetingResource; |
|
|
|
@POST |
|
@Path("/brew") |
|
@Consumes({ "application/json" }) |
|
// in theory should take List<String> to clean it up |
|
public BrewObj invokeBrewScanAnalyze(@Valid String scanInvocation) throws JSONException { |
|
JSONObject jsonData = new JSONObject(scanInvocation); |
|
BrewObj brewObj = BrewObjPayload.constructScanPayload(jsonData); |
|
ConnectDB connectDB = new ConnectDB(); |
|
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) { |
|
logger.error(e.getMessage()); |
|
} |
|
greetingResource.invokeScanTask(brewObj.getBrewNvr()); |
|
return brewObj; |
|
} |
|
|
|
@POST |
|
@Path("/git") |
|
@Consumes({ "application/json" }) |
|
public void invokeGitScanAnalyze(@Valid String scanInvocation)throws URISyntaxException { |
|
throw new UnsupportedOperationException("unImplemented fucntionality"); |
|
|
|
// 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); |
|
// } |
|
// return gitObj; |
|
} |
|
|
|
@POST |
|
@Path("/pnc") |
|
@Consumes({ "application/json" }) |
|
public void invokePncScanAnalyze(@Valid String scanInvocation)throws URISyntaxException { |
|
throw new UnsupportedOperationException("unImplemented fucntionality"); |
|
// 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); |
|
// } |
|
// return pncObj; |
|
} |
|
}
|
|
|