SHARE
TWEET

Untitled

a guest Nov 6th, 2018 95 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. @Entity
  2. @Transactional
  3. public class FisicHost {
  4.  
  5.     @Id
  6.     @GeneratedValue(strategy = GenerationType.IDENTITY)
  7.     private Long id;
  8.  
  9.     @ManyToOne(fetch=FetchType.EAGER)
  10.     private Datacenter datacenter;
  11.  
  12.     @OneToMany(mappedBy = "fisicHost")
  13.     @LazyCollection(LazyCollectionOption.FALSE)
  14.     private List<Credential> credentials;
  15.  
  16.     private String name;
  17.     private String ip;
  18.     private String operatingSystem;
  19.     private String notes;
  20.  
  21.     public FisicHost(){
  22.  
  23.     }
  24.  
  25.     public FisicHost(Long id, Datacenter datacenter, List<Credential> credentials, String name, String ip, String operatingSystem, String notes) {
  26.         this.id = id;
  27.         this.datacenter = datacenter;
  28.         this.credentials = credentials;
  29.         this.name = name;
  30.         this.ip = ip;
  31.         this.operatingSystem = operatingSystem;
  32.         this.notes = notes;
  33.     }
  34.  
  35.     public Long getId() {
  36.         return id;
  37.     }
  38.  
  39.     public void setId(Long id) {
  40.         this.id = id;
  41.     }
  42.  
  43.     public Datacenter getDatacenter() {
  44.         return datacenter;
  45.     }
  46.  
  47.     public void setDatacenter(Datacenter datacenter) {
  48.         this.datacenter = datacenter;
  49.     }
  50.  
  51.     public List<Credential> getCredentials() {
  52.         return credentials;
  53.     }
  54.  
  55.     public void setCredentials(List<Credential> credentials) {
  56.         this.credentials = credentials;
  57.     }
  58.  
  59.     public String getName() {
  60.         return name;
  61.     }
  62.  
  63.     public void setName(String name) {
  64.         this.name = name;
  65.     }
  66.  
  67.     public String getIp() {
  68.         return ip;
  69.     }
  70.  
  71.     public void setIp(String ip) {
  72.         this.ip = ip;
  73.     }
  74.  
  75.     public String getOperatingSystem() {
  76.         return operatingSystem;
  77.     }
  78.  
  79.     public void setOperatingSystem(String operatingSystem) {
  80.         this.operatingSystem = operatingSystem;
  81.     }
  82.  
  83.     public String getNotes() {
  84.         return notes;
  85.     }
  86.  
  87.     public void setNotes(String notes) {
  88.         this.notes = notes;
  89.     }
  90. }
  91.    
  92. @Entity
  93. public class Credential {
  94.  
  95.     @Id
  96.     private int id;
  97.  
  98.     @ManyToOne(fetch= FetchType.EAGER)
  99.     private FisicHost fisicHost;
  100.  
  101.     private String user;
  102.     private String password;
  103.     private String notes;
  104.     private String role;
  105.  
  106.     public Credential(){
  107.  
  108.     }
  109.  
  110.     public Credential(int id, FisicHost fisicHost, String user, String password, String notes, String role) {
  111.         this.id = id;
  112.         this.fisicHost = fisicHost;
  113.         this.user = user;
  114.         this.password = password;
  115.         this.notes = notes;
  116.         this.role = role;
  117.     }
  118.  
  119.     public int getId() {
  120.         return id;
  121.     }
  122.  
  123.     public void setId(int id) {
  124.         this.id = id;
  125.     }
  126.  
  127.     public FisicHost getFisicHost() {
  128.         return fisicHost;
  129.     }
  130.  
  131.     public void setFisicHost(FisicHost fisicHost) {
  132.         this.fisicHost = fisicHost;
  133.     }
  134.  
  135.     public String getUser() {
  136.         return user;
  137.     }
  138.  
  139.     public void setUser(String user) {
  140.         this.user = user;
  141.     }
  142.  
  143.     public String getPassword() {
  144.         return password;
  145.     }
  146.  
  147.     public void setPassword(String password) {
  148.         this.password = password;
  149.     }
  150.  
  151.     public String getNotes() {
  152.         return notes;
  153.     }
  154.  
  155.     public void setNotes(String notes) {
  156.         this.notes = notes;
  157.     }
  158.  
  159.     public String getRole() {
  160.         return role;
  161.     }
  162.  
  163.     public void setRole(String role) {
  164.         this.role = role;
  165.     }
  166. }
  167.    
  168. @Repository
  169. public class CredentialDaoImpl implements CredentialDao {
  170.  
  171.     @Autowired
  172.     private SessionFactory sessionFactory;
  173.  
  174.     @Override
  175.     public List<Credential> getAllCredentialsByFisicHost(FisicHost fisicHost) {
  176.         // Open a session
  177.         Session session = sessionFactory.openSession();
  178.  
  179.         Criteria c = session.createCriteria(Credential.class).add(Restrictions.eq("fisicHost", fisicHost.getId()));
  180.  
  181.         List<Credential> allCredentials = c.list();
  182.  
  183.         // Close the session
  184.         session.close();
  185.  
  186.         return allCredentials;
  187.     }
  188.    
  189. @RequestMapping(value = "/chosenDatacenter", method = RequestMethod.POST)
  190. public String datacenterPostHandler(@RequestParam("datacenterList") String name, ModelMap modelMap){
  191.     List<Datacenter> allDatacenters = datacenterDao.getAllDatacenters();
  192.     for (Datacenter dc : allDatacenters) {
  193.         if (dc.getName().equals(name)) {
  194.         modelMap.put("datacenter", dc);
  195.         if(dc.getFisicHostList().size() != 0) {
  196.             List<FisicHost> datacenterFisicHosts = dc.getFisicHostList();
  197.             modelMap.put("datacenterFisicHosts", datacenterFisicHosts);
  198.             for(FisicHost fh : datacenterFisicHosts){
  199.                 if(fh.getCredentials().size() != 0){
  200.                     modelMap.put("fisicHostCredentialsList", credentialDao.getAllCredentialsByFisicHost(fh));
  201.                 }
  202.             }
  203.         }
  204.         return "chosenDatacenter";
  205.         }
  206.     }
  207.         return null;
  208. }
  209.    
  210. Criteria c = session.createCriteria(Credential.class).add(Restrictions.eq("fisicHost", fisicHost.getId()));
  211.    
  212. Criteria c = session.createCriteria(Credential.class).add(Restrictions.eq("fisicHost.id", fisicHost.getId()));
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top