9 changed files with 261 additions and 6 deletions
@ -0,0 +1,9 @@ |
|||||||
|
package dto; |
||||||
|
|
||||||
|
import java.io.Serializable; |
||||||
|
|
||||||
|
//interface for the scan objects
|
||||||
|
|
||||||
|
public interface ScanInterface extends Serializable{ |
||||||
|
public String constructPayload(); |
||||||
|
} |
||||||
@ -0,0 +1,43 @@ |
|||||||
|
package rest; |
||||||
|
|
||||||
|
import javax.persistence.Entity; |
||||||
|
|
||||||
|
public class Scan { |
||||||
|
private int scanId; |
||||||
|
private String productId; |
||||||
|
private String eventId; |
||||||
|
private String isManagedService; |
||||||
|
private String componentList; |
||||||
|
|
||||||
|
public int getScanId() { |
||||||
|
return scanId; |
||||||
|
} |
||||||
|
public void setScanId(int scanId) { |
||||||
|
this.scanId = scanId; |
||||||
|
} |
||||||
|
public String getProductId() { |
||||||
|
return productId; |
||||||
|
} |
||||||
|
public void setProductId(String productId) { |
||||||
|
this.productId = productId; |
||||||
|
} |
||||||
|
public String getEventId() { |
||||||
|
return eventId; |
||||||
|
} |
||||||
|
public void setEventId(String eventId) { |
||||||
|
this.eventId = eventId; |
||||||
|
} |
||||||
|
public String getIsManagedService(){ |
||||||
|
return isManagedService; |
||||||
|
} |
||||||
|
public void setIsManagedService(String isManagedService){ |
||||||
|
this.isManagedService = isManagedService; |
||||||
|
} |
||||||
|
public String getComponentList(){ |
||||||
|
return componentList; |
||||||
|
} |
||||||
|
public void setComponentList(String componentList){ |
||||||
|
this.componentList = componentList; |
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
@ -0,0 +1,124 @@ |
|||||||
|
package rest; |
||||||
|
|
||||||
|
|
||||||
|
import java.util.Collections; |
||||||
|
import java.util.LinkedHashMap; |
||||||
|
import java.util.Set; |
||||||
|
import dto.ScanObj; |
||||||
|
// import dto.ConnectDB;
|
||||||
|
// import dto.Scan;
|
||||||
|
|
||||||
|
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; |
||||||
|
|
||||||
|
import javax.ws.rs.DELETE; |
||||||
|
import javax.ws.rs.GET; |
||||||
|
import javax.ws.rs.POST; |
||||||
|
import javax.ws.rs.Path; |
||||||
|
import javax.inject.Inject; |
||||||
|
import javax.ws.rs.GET; |
||||||
|
import javax.ws.rs.Path; |
||||||
|
import javax.ws.rs.PathParam; |
||||||
|
import java.util.Set; |
||||||
|
import java.util.stream.Collectors; |
||||||
|
import javax.inject.Inject; |
||||||
|
import javax.ws.rs.Consumes; |
||||||
|
|
||||||
|
import java.sql.*; |
||||||
|
|
||||||
|
import com.fasterxml.jackson.databind.ObjectMapper; |
||||||
|
import com.fasterxml.jackson.databind.ObjectWriter; |
||||||
|
|
||||||
|
import org.hibernate.Session; |
||||||
|
import org.hibernate.SessionFactory; |
||||||
|
import org.hibernate.Transaction; |
||||||
|
import org.hibernate.boot.Metadata; |
||||||
|
import org.hibernate.boot.MetadataSources; |
||||||
|
import org.hibernate.boot.registry.StandardServiceRegistry; |
||||||
|
import org.hibernate.boot.registry.StandardServiceRegistryBuilder; |
||||||
|
// import org.hibernate.EntityManager;
|
||||||
|
import jakarta.persistence.EntityManager; |
||||||
|
import jakarta.persistence.Cacheable; |
||||||
|
import jakarta.persistence.Column; |
||||||
|
import jakarta.persistence.Entity; |
||||||
|
import jakarta.persistence.GeneratedValue; |
||||||
|
import jakarta.persistence.Id; |
||||||
|
import jakarta.persistence.NamedQuery; |
||||||
|
import jakarta.persistence.QueryHint; |
||||||
|
import jakarta.persistence.SequenceGenerator; |
||||||
|
import jakarta.persistence.Table; |
||||||
|
|
||||||
|
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("/storeData") |
||||||
|
public class StoreData { |
||||||
|
|
||||||
|
//all of these need cleaning up to be a more sensible soution
|
||||||
|
// @RestClient
|
||||||
|
// CreateScanService createScanService;
|
||||||
|
|
||||||
|
@GET |
||||||
|
public void Store() { |
||||||
|
System.out.println("hmm"); |
||||||
|
|
||||||
|
//Create typesafe ServiceRegistry object
|
||||||
|
StandardServiceRegistry ssr = new StandardServiceRegistryBuilder().configure("hibernate.cfg.xml").build(); |
||||||
|
|
||||||
|
Metadata meta = new MetadataSources(ssr).getMetadataBuilder().build(); |
||||||
|
|
||||||
|
SessionFactory factory = meta.getSessionFactoryBuilder().build(); |
||||||
|
Session session = factory.openSession(); |
||||||
|
Transaction t = session.beginTransaction(); |
||||||
|
System.out.println("i assume we fail before here?"); |
||||||
|
Scan e1=new Scan(); |
||||||
|
e1.setScanId(2); |
||||||
|
e1.setProductId("1"); |
||||||
|
e1.setEventId("Chawla"); |
||||||
|
e1.setIsManagedService("aa"); |
||||||
|
e1.setComponentList("aaa"); |
||||||
|
|
||||||
|
session.save(e1); |
||||||
|
t.commit(); |
||||||
|
System.out.println("successfully saved"); |
||||||
|
factory.close(); |
||||||
|
session.close(); |
||||||
|
|
||||||
|
} |
||||||
|
} |
||||||
@ -0,0 +1,19 @@ |
|||||||
|
<?xml version='1.0' encoding='UTF-8'?> |
||||||
|
<!DOCTYPE hibernate-configuration PUBLIC |
||||||
|
"-//Hibernate/Hibernate Configuration DTD 3.0//EN" |
||||||
|
"http://www.hibernate.org/dtd/hibernate-mapping-5.3.dtd"> |
||||||
|
|
||||||
|
<hibernate-mapping> |
||||||
|
<class name="rest.Scan" table="scans"> |
||||||
|
<id name="ScanId"> |
||||||
|
<generator class="increment"/> |
||||||
|
</id> |
||||||
|
<!-- <property name="scanId"></property> --> |
||||||
|
<property name="ProductId"></property> |
||||||
|
<property name="EventId"></property> |
||||||
|
<property name="IsManagedService"></property> |
||||||
|
<property name="ComponentList"></property> |
||||||
|
|
||||||
|
</class> |
||||||
|
|
||||||
|
</hibernate-mapping> |
||||||
@ -0,0 +1,21 @@ |
|||||||
|
<?xml version='1.0' encoding='UTF-8'?> |
||||||
|
<!DOCTYPE hibernate-configuration PUBLIC |
||||||
|
"-//Hibernate/Hibernate Configuration DTD 3.0//EN" |
||||||
|
"http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd"> |
||||||
|
|
||||||
|
<hibernate-configuration> |
||||||
|
|
||||||
|
<session-factory> |
||||||
|
<property name="hbm2ddl.auto">update</property> |
||||||
|
<property name="dialect">org.hibernate.dialect.PostgreSQLDialect</property> |
||||||
|
<property name="connection.driver_class">org.postgresql.Driver</property> |
||||||
|
<property name="connection.url">jdbc:postgresql://localhost:5432/mydb</property> |
||||||
|
<property name="connection.username">postgres</property> |
||||||
|
<property name="connection.password">password</property> |
||||||
|
<!-- <property name="connection.driver_class">oracle.jdbc.driver.OracleDriver</property> --> |
||||||
|
<property name="show_sql">true</property> <!-- Show SQL in console --> |
||||||
|
<property name="format_sql">true</property> <!-- Show SQL formatted --> |
||||||
|
<mapping resource="Scan.hbm.xml"/> |
||||||
|
</session-factory> |
||||||
|
|
||||||
|
</hibernate-configuration> |
||||||
Loading…
Reference in new issue