Advertisement
Guest User

Untitled

a guest
Jun 19th, 2018
206
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.37 KB | None | 0 0
  1. package lapr.project.controller;
  2.  
  3. import java.util.ArrayList;
  4. import java.util.List;
  5. import lapr.project.model.*;
  6. import lapr.project.utils.*;
  7.  
  8. /**
  9. *
  10. * @João Ribeiro 1171164@isep.ipp.pt
  11. */
  12. public class SubmitAppToEventController {
  13.  
  14. private User user;
  15. private EventCenter eventCenter;
  16. private EventRegister eventRegister;
  17. private List<Event> eventList;
  18. private Event chosenEvent;
  19. private Application newApp;
  20. private boolean updatedState;
  21.  
  22. public SubmitAppToEventController() {
  23. }
  24.  
  25. public void setEventCenter(EventCenter eventCenter) {
  26. this.eventCenter = eventCenter;
  27. }
  28.  
  29. public void setUser(User user) {
  30. this.user = user;
  31. }
  32.  
  33. public void setChosenEvent(Event e) {
  34. this.chosenEvent = e;
  35. }
  36.  
  37. public EventCenter getEventCenter() {
  38. return this.eventCenter;
  39. }
  40.  
  41. public User getUser() {
  42. return this.user;
  43. }
  44.  
  45. public List<Event> getListEvent() {
  46. eventRegister = eventCenter.getEventRegister();
  47. eventList = eventRegister.getEventList();
  48. return eventList;
  49. }
  50.  
  51. public boolean getUpdatedState() {
  52. return this.updatedState;
  53. }
  54.  
  55. public Application insertData(String companyText, int vat, int number, int area, int invites) {
  56. newApp = chosenEvent.submitAppToEvent();
  57. newApp.setData(companyText, vat, number, area, invites);
  58. newApp.setApplicantRepresentative(this.user);
  59. return newApp;
  60. }
  61.  
  62. public boolean insertTopics(List<Product> listProducts, String Work_description, String Work_duration, String topic1, String topic2, String topic3, String topic4, String topic5) {
  63. newApp.setWorkshop(listProducts, Work_description, Work_duration);
  64. List<String> topics = validateTopics(topic1, topic2, topic3, topic4, topic5);
  65. if (topics.size() > 1) {
  66. newApp.insertTopics(topics);
  67. return true;
  68. } else {
  69. throw new InvalidTopicAppDescriptionException();
  70. }
  71.  
  72. }
  73.  
  74. public boolean registerAppToEvent(Event chosenEvent, Application newApp) {
  75. chosenEvent.registerAppToEvent(newApp);
  76. ApplicationRegister aR = eventCenter.getApplicationRegister();
  77. return aR.addApp(newApp);
  78. }
  79.  
  80. public List<Product> listProductsInList(String txtField) {
  81. String[] splited = txtField.split(",");
  82. List<Product> productList = new ArrayList<>();
  83. for (int i = 0; i < splited.length; i++) {
  84. productList.add(new Product(splited[i].trim()));
  85. }
  86. return productList;
  87. }
  88.  
  89. public List<String> validateTopics(String topic1, String topic2, String topic3, String topic4, String topic5) {
  90. List<String> listTopics = new ArrayList<>();
  91. if (!topic1.equals("")) {
  92. listTopics.add(topic1.trim());
  93. }
  94. if (!topic2.equals("")) {
  95. listTopics.add(topic2.trim());
  96. }
  97. if (!topic3.equals("")) {
  98. listTopics.add(topic3.trim());
  99. }
  100. if (!topic4.equals("")) {
  101. listTopics.add(topic4.trim());
  102. }
  103. if (!topic5.equals("")) {
  104. listTopics.add(topic5.trim());
  105. }
  106. return listTopics;
  107. }
  108.  
  109. public void setApplicationUpdate(Application app) {
  110. this.newApp = app;
  111. this.updatedState = true;
  112. }
  113.  
  114. public void setData(String companyText, int vat, int number, int area, int invites) {
  115. newApp.setData(companyText, vat, number, area, invites);
  116. }
  117.  
  118. public String getCompany() {
  119. return newApp.getTheCompany();
  120. }
  121.  
  122. public String getVAT() {
  123. return "" + newApp.getVATnumber();
  124. }
  125.  
  126. public String getNumber() {
  127. return "" + newApp.getContactPhoneNumber();
  128. }
  129.  
  130. public String getArea() {
  131. return "" + newApp.getIntendedStandArea();
  132. }
  133.  
  134. public String getInvites() {
  135. return "" + newApp.getNumberOfInvitations();
  136. }
  137.  
  138. public String getWorkshopDescription() {
  139. return newApp.getWorkshop().getWorkshopDescription();
  140. }
  141.  
  142. public String getWorkshopDuration() {
  143. return newApp.getWorkshop().getWorkshopDuration();
  144. }
  145.  
  146. public String getListProductsToString() {
  147. return newApp.getListProductsToString();
  148. }
  149.  
  150. public String getTopic1() {
  151. try {
  152. String topic = newApp.getTopics().get(0);
  153. return topic;
  154. } catch (NullPointerException e) {
  155. return "";
  156. }
  157. }
  158.  
  159. public String getTopic2() {
  160. try {
  161. String topic = newApp.getTopics().get(1);
  162. return topic;
  163. } catch (NullPointerException e) {
  164. return "";
  165. }
  166. }
  167.  
  168. public String getTopic3() {
  169. try {
  170. String topic = newApp.getTopics().get(2);
  171. return topic;
  172. } catch (NullPointerException e) {
  173. return "";
  174. }
  175. }
  176.  
  177. public String getTopic4() {
  178. try {
  179. String topic = newApp.getTopics().get(3);
  180. return topic;
  181. } catch (NullPointerException e) {
  182. return "";
  183. }
  184. }
  185.  
  186. public String getTopic5() {
  187. try {
  188. String topic = newApp.getTopics().get(4);
  189. return topic;
  190. } catch (NullPointerException e) {
  191. return "";
  192. }
  193. }
  194.  
  195. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement