Guest User

Untitled

a guest
Dec 12th, 2017
417
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.22 KB | None | 0 0
  1. @Entity
  2. @Table(name="subscribers")
  3. public class Subscriber {
  4.  
  5. @Id
  6. @GeneratedValue(strategy=GenerationType.AUTO)
  7. private long subscriber_id;
  8.  
  9. @Column(name= "firstname")
  10. @Size(min = 3, max = 20, message = "Please enter a valid first name")
  11. @NotEmpty(message = "First Name is required.")
  12. public String firstname;
  13.  
  14. @Column(name= "lastname")
  15. @Size(min = 3, max = 20, message = "Please enter a valid first name")
  16. @NotEmpty(message = "Last Name is required.")
  17. public String lastname;
  18.  
  19. private Set<Cluster> clusters;
  20.  
  21.  
  22. @Pattern(
  23. regexp = "^(?:[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*|"(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21\x23-\x5b\x5d-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])*")@(?:(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?|\[(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?|[a-z0-9-]*[a-z0-9]:(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21-\x5a\x53-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])+)\])$",
  24. message = "Invalid Email address. Enter Correct Email Address"
  25. )
  26. @Column(name= "emailaddress")
  27. @NotEmpty(message = "Email is required.")
  28. public String email;
  29.  
  30. public Subscriber()
  31. {
  32. super();
  33. }
  34.  
  35. public Subscriber(String firstname, String lastname, String email, Set<Cluster> clusters)
  36. {
  37. this.firstname = firstname;
  38. this.lastname = lastname;
  39. this.email = email;
  40.  
  41. }
  42.  
  43. public long getSubscriberId()
  44. {
  45. return subscriber_id;
  46. }
  47.  
  48. public void setSubscriberId(long subscriber_id)
  49. {
  50. this.subscriber_id = subscriber_id;
  51. }
  52.  
  53. public String getFirstname() {
  54. return firstname;
  55. }
  56.  
  57. public void setFirstname(String firstname) {
  58. this.firstname = firstname;
  59. }
  60.  
  61. public String getLastname()
  62. {
  63. return lastname;
  64. }
  65.  
  66. public void setLastname(String lastname)
  67. {
  68. this.lastname = lastname;
  69. }
  70.  
  71. public String getEmail()
  72. {
  73. return email;
  74. }
  75.  
  76. public void setEmail(String email)
  77. {
  78. this.email = email;
  79. }
  80.  
  81. @ManyToMany(mappedBy = "subscribers")
  82. public Set<Cluster> getClusters()
  83. {
  84. return clusters;
  85. }
  86.  
  87. public void setClusters (Set<Cluster> clusters)
  88. {
  89. this.clusters = clusters;
  90. }
  91.  
  92. @Entity
  93. public class Cluster {
  94.  
  95. @Id
  96. @GeneratedValue(strategy=GenerationType.AUTO)
  97. public long cluster_id;
  98.  
  99. @Column(name= "clustername")
  100. @NotNull
  101. public String clusterName;
  102.  
  103. @Column(name= "location")
  104. public String location;
  105.  
  106. @Column(name= "apiaddress")
  107. public String apiAddress;
  108.  
  109. @Column(name= "contact")
  110. @NotNull
  111. public String contact;
  112.  
  113. public Date creationDate;
  114.  
  115. public Set<Subscriber> subscribers;
  116.  
  117. public Cluster()
  118. {
  119.  
  120. }
  121.  
  122. public Cluster(String clusterName, String location, String apiAddress, String contact, Set<Subscriber> subscribers)
  123. {
  124. super();
  125. this.clusterName = clusterName;
  126. this.location = location;
  127. this.apiAddress = apiAddress;
  128. this.contact = contact;
  129.  
  130. }
  131.  
  132. public long getClusterId()
  133. {
  134. return cluster_id;
  135. }
  136.  
  137. public void setClusterId(long cluster_id)
  138. {
  139. this.cluster_id = cluster_id;
  140. }
  141.  
  142. public String getClusterName()
  143. {
  144. return clusterName;
  145. }
  146.  
  147. public void setClusterName (String clusterName)
  148. {
  149. this.clusterName = clusterName;
  150. }
  151.  
  152. public String getLocation()
  153. {
  154. return location;
  155. }
  156.  
  157. public void setLocation (String location)
  158. {
  159. this.location = location;
  160. }
  161.  
  162. public String getApiAddress()
  163. {
  164. return apiAddress;
  165. }
  166.  
  167. public void setApiAddress (String apiAddress)
  168. {
  169. this.apiAddress = apiAddress;
  170. }
  171.  
  172. public String getContact()
  173. {
  174. return contact;
  175. }
  176.  
  177. public void setContact (String contact)
  178. {
  179. this.contact = contact;
  180. }
  181.  
  182. public Date getCreationDate()
  183. {
  184. return creationDate;
  185. }
  186.  
  187. public void setCreationDate(Date creationDate)
  188. {
  189. this.creationDate = creationDate;
  190. }
  191.  
  192. @ManyToMany(cascade = CascadeType.ALL)
  193. @JoinTable(name="cluster_subscriber", joinColumns = @JoinColumn(name="cluster_id", referencedColumnName = "id"), inverseJoinColumns = @JoinColumn(name = "subscriber_id", referencedColumnName = "id"))
  194. public Set<Subscriber> getSubscribers()
  195. {
  196. return subscribers;
  197. }
  198.  
  199. public void setSubscribers(Set<Subscriber> subscribers)
  200. {
  201. this.subscribers =subscribers;
  202. }
  203.  
  204. @SpringBootApplication
  205. public class AiAdminApplication {
  206.  
  207. public static void main(String[] args) {
  208. SpringApplication.run(AiAdminApplication.class, args);
  209. /*ApplicationContext ctx = SpringApplication.run(AiAdminApplication.class, args);
  210.  
  211.  
  212. String [] beanNames = ctx.getBeanDefinitionNames();
  213. Arrays.sort(beanNames);
  214. for (String name: beanNames){
  215. System.out.println(name);
  216. }*/
  217. }
  218.  
  219. @Component
  220. public class DatabaseLoader implements CommandLineRunner {
  221. private final SubscriberRepository subscriberRepository;
  222. private final ClusterRepository clusterRepository;
  223.  
  224. @Autowired
  225. public DatabaseLoader(SubscriberRepository subscriberRepository, ClusterRepository clusterRepository) {
  226.  
  227. this.subscriberRepository = subscriberRepository;
  228. this.clusterRepository = clusterRepository;
  229. }
  230.  
  231. public void run (String...strings) throws Exception {
  232. this.subscriberRepository.save(new Subscriber("Olalekan Samuel", "Ogunleye", "olalekan@aithenticate.za.com", 1));
  233. this.subscriberRepository.save(new Subscriber("Pieter", "Erasmus", "pieter@aithenticate.za.com", 2));
  234. this.subscriberRepository.save(new Subscriber("Nico", "Boss", "nicoboss@aithenticate.za.com", 3));
  235. this.subscriberRepository.save(new Subscriber("Felix Parfait", "Tandem", "parfait@aithenticate.za.com", 4));
  236. this.subscriberRepository.save(new Subscriber("Nkosinathi", "Nkosinatthi", "nathi@aithenticate.za.com", 5));
  237. this.subscriberRepository.save(new Subscriber("Balleng", "Balleng", "balleng@aithenticate.za.com", 6));
  238. this.subscriberRepository.save(new Subscriber("Nicolas", "Immelman", "nicolas@aithenticate.za.com", 7));
  239. this.subscriberRepository.save(new Subscriber("Nicolo", "Carzavallian", "nicolo@aithenticate.za.com", 8));
  240. this.subscriberRepository.save(new Subscriber("Shaun", "chang", "shaun@aithenticate.za.com", 9));
  241. this.subscriberRepository.save(new Subscriber("Andre", "Immelman", "ali@aithenticate.za.com", 10));
  242. this.subscriberRepository.save(new Subscriber("Michel", "Immelman", "michel@aithenticate.za.com", 11));
  243.  
  244. this.clusterRepository.save(new Cluster("Aws-eu-west-1", "Ireland", "123.98.45", "Olalekan Samuel", 1));
  245. this.clusterRepository.save(new Cluster("Azure", "United State", "123.98.45", "Pieter Erasmus", 1));
  246. this.clusterRepository.save(new Cluster("Google Cloud", "United State", "123.98.45", "Nico Boss", 1));
  247. this.clusterRepository.save(new Cluster("herekou", "United Kingdom", "123.98.45", "Felix Parfait", 2));
  248. this.clusterRepository.save(new Cluster("IBM", "United State", "123.98.45", "Nkosinathi Nkosinathi", 4));
  249. this.clusterRepository.save(new Cluster("herekou", "United Kingdom", "123.98.45", "Balleng Immelman", 5));
  250. this.clusterRepository.save(new Cluster("Aws-eu-west-1", "Ireland", "123.98.45", "Nicolas Immelman", 6));
  251. this.clusterRepository.save(new Cluster("Azure", "United State", "123.98.45", "Nicolo Carzavallian", 6));
  252. this.clusterRepository.save(new Cluster("Google Cloud", "United State", "123.98.45", "Shaun Chang", 5));
  253. this.clusterRepository.save(new Cluster("herekou", "United Kingdom", "123.98.45", "Andre Immelman", 7));
  254. this.clusterRepository.save(new Cluster("IBM", "United State", "123.98.45", "Michel Immelman"));
  255.  
  256.  
  257. }
  258. }
Add Comment
Please, Sign In to add comment