Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package lapr.project.controller;
- import java.util.ArrayList;
- import java.util.List;
- import lapr.project.model.*;
- import lapr.project.utils.*;
- /**
- *
- * @João Ribeiro 1171164@isep.ipp.pt
- */
- public class SubmitAppToEventController {
- private User user;
- private EventCenter eventCenter;
- private EventRegister eventRegister;
- private List<Event> eventList;
- private Event chosenEvent;
- private Application newApp;
- private boolean updatedState;
- public SubmitAppToEventController() {
- }
- public void setEventCenter(EventCenter eventCenter) {
- this.eventCenter = eventCenter;
- }
- public void setUser(User user) {
- this.user = user;
- }
- public void setChosenEvent(Event e) {
- this.chosenEvent = e;
- }
- public EventCenter getEventCenter() {
- return this.eventCenter;
- }
- public User getUser() {
- return this.user;
- }
- public List<Event> getListEvent() {
- eventRegister = eventCenter.getEventRegister();
- eventList = eventRegister.getEventList();
- return eventList;
- }
- public boolean getUpdatedState() {
- return this.updatedState;
- }
- public Application insertData(String companyText, int vat, int number, int area, int invites) {
- newApp = chosenEvent.submitAppToEvent();
- newApp.setData(companyText, vat, number, area, invites);
- newApp.setApplicantRepresentative(this.user);
- return newApp;
- }
- public boolean insertTopics(List<Product> listProducts, String Work_description, String Work_duration, String topic1, String topic2, String topic3, String topic4, String topic5) {
- newApp.setWorkshop(listProducts, Work_description, Work_duration);
- List<String> topics = validateTopics(topic1, topic2, topic3, topic4, topic5);
- if (topics.size() > 1) {
- newApp.insertTopics(topics);
- return true;
- } else {
- throw new InvalidTopicAppDescriptionException();
- }
- }
- public boolean registerAppToEvent(Event chosenEvent, Application newApp) {
- chosenEvent.registerAppToEvent(newApp);
- ApplicationRegister aR = eventCenter.getApplicationRegister();
- return aR.addApp(newApp);
- }
- public List<Product> listProductsInList(String txtField) {
- String[] splited = txtField.split(",");
- List<Product> productList = new ArrayList<>();
- for (int i = 0; i < splited.length; i++) {
- productList.add(new Product(splited[i].trim()));
- }
- return productList;
- }
- public List<String> validateTopics(String topic1, String topic2, String topic3, String topic4, String topic5) {
- List<String> listTopics = new ArrayList<>();
- if (!topic1.equals("")) {
- listTopics.add(topic1.trim());
- }
- if (!topic2.equals("")) {
- listTopics.add(topic2.trim());
- }
- if (!topic3.equals("")) {
- listTopics.add(topic3.trim());
- }
- if (!topic4.equals("")) {
- listTopics.add(topic4.trim());
- }
- if (!topic5.equals("")) {
- listTopics.add(topic5.trim());
- }
- return listTopics;
- }
- public void setApplicationUpdate(Application app) {
- this.newApp = app;
- this.updatedState = true;
- }
- public void setData(String companyText, int vat, int number, int area, int invites) {
- newApp.setData(companyText, vat, number, area, invites);
- }
- public String getCompany() {
- return newApp.getTheCompany();
- }
- public String getVAT() {
- return "" + newApp.getVATnumber();
- }
- public String getNumber() {
- return "" + newApp.getContactPhoneNumber();
- }
- public String getArea() {
- return "" + newApp.getIntendedStandArea();
- }
- public String getInvites() {
- return "" + newApp.getNumberOfInvitations();
- }
- public String getWorkshopDescription() {
- return newApp.getWorkshop().getWorkshopDescription();
- }
- public String getWorkshopDuration() {
- return newApp.getWorkshop().getWorkshopDuration();
- }
- public String getListProductsToString() {
- return newApp.getListProductsToString();
- }
- public String getTopic1() {
- try {
- String topic = newApp.getTopics().get(0);
- return topic;
- } catch (NullPointerException e) {
- return "";
- }
- }
- public String getTopic2() {
- try {
- String topic = newApp.getTopics().get(1);
- return topic;
- } catch (NullPointerException e) {
- return "";
- }
- }
- public String getTopic3() {
- try {
- String topic = newApp.getTopics().get(2);
- return topic;
- } catch (NullPointerException e) {
- return "";
- }
- }
- public String getTopic4() {
- try {
- String topic = newApp.getTopics().get(3);
- return topic;
- } catch (NullPointerException e) {
- return "";
- }
- }
- public String getTopic5() {
- try {
- String topic = newApp.getTopics().get(4);
- return topic;
- } catch (NullPointerException e) {
- return "";
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement