<file_sep>/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package model;

import java.util.ArrayList;
import java.util.List;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.ManyToMany;
import javax.persistence.OneToMany;
import javax.persistence.SequenceGenerator;

/**
 *
 * @author Philip
 */
@Entity
@SequenceGenerator(name = "routeseq", sequenceName = "route_seq", initialValue = 1, allocationSize = 1)
public class Route {
    @Id
    @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "routeseq")
    private long id;
    private String source;
    private String destination;
    @OneToMany(mappedBy = "route")
    private List<CompanyRoute> companies = new ArrayList<>();
    @OneToMany(mappedBy = "route")
    private List<Journey> journeys = new ArrayList<>();
    @Enumerated(EnumType.STRING)
    private Status status;

    public Route() {
    }

    
    
    public Route(String source, String destination, Status status) {
        this.source = source;
        this.destination = destination;
        this.status = status;
    }
    
    

    public long getId() {
        return id;
    }

    public void setId(long id) {
        this.id = id;
    }

    public String getSource() {
        return source;
    }

    public void setSource(String source) {
        this.source = source;
    }

    public String getDestination() {
        return destination;
    }

    public void setDestination(String destination) {
        this.destination = destination;
    }

    public List<CompanyRoute> getCompanies() {
        return companies;
    }

    public void setCompanies(List<CompanyRoute> companies) {
        this.companies = companies;
    }

    public List<Journey> getJourneys() {
        return journeys;
    }

    public void setJourneys(List<Journey> journeys) {
        this.journeys = journeys;
    }

    public Status getStatus() {
        return status;
    }

    public void setStatus(Status status) {
        this.status = status;
    }
    
}
<file_sep>/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package testing;

import dao.DBUtil;
import dao.GeneralDao;
import dao.PassengerDao;
import java.util.Date;
import java.util.List;
import javax.servlet.Registration;
import model.AccountState;
import model.AdminAccount;
import model.Company;
import model.CompanyRoute;
import model.CompanyState;
import model.Gender;
import model.Journey;
import model.Manager;
import model.ManagerAccount;
import model.Passenger;
import model.Route;
import model.Status;
import model.Ticket;
import org.testng.Assert;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;

/**
 *
 * @author Philip
 */
public class IntTest extends DBSetupConfig {
    GeneralDao<Company> studentDao = new GeneralDao<>();
    GeneralDao<CompanyRoute> comRouteDao = new GeneralDao<>();
    GeneralDao<AdminAccount> adminAccDao = new GeneralDao<>();
    GeneralDao<Manager> managerDao = new GeneralDao<>();
    GeneralDao<ManagerAccount> managerAccDao = new GeneralDao<>();
    GeneralDao<CompanyState> companyStateDao = new GeneralDao<>();
    GeneralDao<Company> companyDao = new GeneralDao<>();
    GeneralDao<Route> routeDao = new GeneralDao<>();
    GeneralDao<AccountState> accStateDao = new GeneralDao<>();
    GeneralDao<Ticket> ticketDao = new GeneralDao<>();
    GeneralDao<Passenger> passengerDao = new GeneralDao<>();
    PassengerDao passDao = new PassengerDao();
    GeneralDao<Journey> journeyDao = new GeneralDao<>();


    @BeforeTest
    public void init() {
        DBUtil.getSessionFactory();
        System.out.println("Tables created");
    }

    @BeforeMethod
    public void initializeTest() {
        executeOperation(TestData.INSERT_ADMIN_ACCOUNT);
        executeOperation(TestData.INSERT_MANAGER);
        executeOperation(TestData.INSERT_COMPANY);
        executeOperation(TestData.INSERT_COMPANY_STATE);
        executeOperation(TestData.INSERT_MANAGER_ACCOUNT);
        executeOperation(TestData.INSERT_ACCOUNT_STATE);
        executeOperation(TestData.INSERT_ROUTE);
        executeOperation(TestData.INSERT_COMPANY_ROUTE);
        executeOperation(TestData.INSERT_JOURNEY);
        executeOperation(TestData.INSERT_PASSENGER);
        executeOperation(TestData.INSERT_TICKET);
        System.out.println("test initialized");
    }

    @AfterMethod
    public void cleanTestData() {
        executeOperation(TestData.DELETE_TICKET);
        executeOperation(TestData.DELETE_PASSENGER);
        executeOperation(TestData.DELETE_JOURNEY);
        executeOperation(TestData.DELETE_COMPANY_ROUTE);
        executeOperation(TestData.DELETE_ROUTE);
        executeOperation(TestData.DELETE_ACCOUNT_STATE);
        executeOperation(TestData.DELETE_MANAGER_ACCOUNT);
        executeOperation(TestData.DELETE_COMPANY_STATE);
        executeOperation(TestData.DELETE_COMPANY);
        executeOperation(TestData.DELETE_MANAGER);
        executeOperation(TestData.DELETE_ADMIN_ACCOUNT);
        executeOperation(TestData.DELETE_TICKET);
        System.out.println("test data cleaned");
    }
    
    @Test
    public void testCreateRoute() {
        String result = routeDao.create(new Route("kayonza", "huye", Status.ACTIVE));
        Assert.assertEquals(result, "created");
        System.out.println("route created");
    }
    
    @Test
    public void testReadRoutes() {
        List<Journey> routelist = journeyDao.findAll(new Journey());
        Assert.assertEquals(routelist.size(), 2);
        System.out.println("routes viewed");
    }

    @Test
    public void testUpdateRoute() {
        Route route = routeDao.findOne(Route.class, 100L);
        route.setSource("nosource");
        String result = routeDao.update(route);
        Assert.assertEquals(result, "updated");
        System.out.println("route updated");
    }
    
    @Test
    public void testDeleteRoute() {
        Route route = routeDao.findOne(Route.class, 100L);
        String result = routeDao.delete(route);
        Assert.assertEquals(result, "deleted");
        System.out.println("route deleted");
    }
    
//    @Test(expectedExceptions = {NullPointerException.class})
//    public void testWrongCourseCode() {
//        Course course = courseDao.findOne(Course.class, "c11");
//        course.getName();
//        System.out.println("wrong course tested");
//    }

    @Test
    public void testReadTickets() {
        List<Ticket> ticketlist = ticketDao.findAll(new Ticket());
        Assert.assertEquals(ticketlist.size(), 2);
        System.out.println("tickets viewed");
    }

    @Test
    public void testUpdateTicket() {
        Ticket ticket = ticketDao.findOne(Ticket.class, 1L);
        ticket.setAmount(2000);
        String result = ticketDao.update(ticket);
        Assert.assertEquals(result, "updated");
        System.out.println("tickets updated");
    }
    
    @Test
    public void testDeleteTicket() {
        Ticket ticket = ticketDao.findOne(Ticket.class, 1L);
        String result = ticketDao.delete(ticket);
        Assert.assertEquals(result, "deleted");
        System.out.println("ticket deleted");
    }
    
    @Test
    public void testReadJourney() {
        List<Journey> journeylist = journeyDao.findAll(new Journey());
        Assert.assertEquals(journeylist.size(), 2);
        System.out.println("journeys viewed");
    }

    @Test
    public void testUpdateJourney() {
        Journey journey = journeyDao.findOne(Journey.class, 1L);
        journey.setPrice(2000);
        String result = journeyDao.update(journey);
        Assert.assertEquals(result, "updated");
        System.out.println("journey updated");
    }
    
    @Test
    public void testDeleteJourney() {
        Journey journey = journeyDao.findOne(Journey.class, 1L);
        String result = journeyDao.delete(journey);
        Assert.assertEquals(result, "deleted");
        System.out.println("Journey deleted");
    }
    
    

//    @Test
//    public void testCreateStudent() {
//        String result = studentDao.create(new Student("21100", "blue", Gender.MALE, new Date(2000, 05, 23)));
//        Assert.assertEquals(result, "success");
//        System.out.println("student created");
//    }
//    
//    @Test
//    public void testReadStudents() {
//        List<Student> studentlist = studentDao.findAll(new Student());
//        Assert.assertEquals(studentlist.size(), 3);
//        System.out.println("students viewed");
//    }
//
//    @Test
//    public void testUpdateStudent() {
//        Student student = studentDao.findOne(Student.class, "21208");
//        student.setName("philip");
//        String result = studentDao.update(student);
//        Assert.assertEquals(result, "success");
//        System.out.println("student updated");
//    }
//    
//    @Test(expectedExceptions = {NullPointerException.class})
//    public void testFindWrongStudent() {
//        Student student = studentDao.findOne(Student.class, "111111");
//        student.getName();
//        System.out.println("student not found");
//    }
//
//    @Test
//    public void testDeleteStudent() {
//        Student student = studentDao.findOne(Student.class, "21208");
//        List<Registration> registrations = registrationDao.findbyStudent(Registration.class, "21208");
//        registrations.forEach((reg) -> {
//            registrationDao.delete(reg);
//        });
//        String result = studentDao.delete(student);
//        Assert.assertEquals(result, "success");
//        System.out.println("student deleted");
//    }
//    
//    
//
//    @Test
//    public void testCreateRegistration() {
//        Student student = studentDao.findOne(Student.class, "21208");
//        Course course = courseDao.findOne(Course.class, "INSY312");
//        String result = registrationDao.create(new Registration(24L, student, course));
//        Assert.assertEquals(result, "success");
//        System.out.println("registered successfully");
//    }
//    
//    @Test
//    public void testReadRegistration() {
//        List<Registration> registrations = registrationDao.findAll(new Registration());
//        Assert.assertEquals(registrations.size(), 3);
//        System.out.println("registrations viewed");
//    }
//
//    @Test
//    public void testUpdateRegistration() {
//        Student student = studentDao.findOne(Student.class, "21179");
//        Registration registration = registrationDao.findOne(Registration.class, 24L);
//        registration.setStudent(student);
//        String result = registrationDao.update(registration);
//        Assert.assertEquals(result, "success");
//        System.out.println("registration updated");
//    }
//
//    @Test
//    public void testDeleteRegistration() {
//        Registration registration = registrationDao.findRegistration(Registration.class, 24L);
//        String result = registrationDao.delete(registration);
//        Assert.assertEquals(result, "success");
//        System.out.println("registration deleted");
//    }
//    
//    @Test(expectedExceptions = {NullPointerException.class})
//    public void testDeleteWrongRegistration() {
//        Registration registration = registrationDao.findRegistration(Registration.class, 4L);
//        registration.getCourse();
//        System.out.println("wrong registration");
//    }

}
<file_sep>/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package model;

import java.util.Date;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.persistence.OneToOne;
import javax.persistence.SequenceGenerator;
import javax.persistence.Temporal;

/**
 *
 * @author Philip
 */
@Entity
@SequenceGenerator(name="companystateseq", sequenceName = "companystate_seq", initialValue = 1,allocationSize = 1)
public class CompanyState {
    @Id
    @GeneratedValue(strategy=GenerationType.SEQUENCE, generator="companystateseq")
    private Long id;
    @Enumerated(EnumType.STRING)
    private CompanyStatus companyStatus;
    @ManyToOne
    private Company company;
    @OneToOne
    private AdminAccount doneBy;
    @Temporal(javax.persistence.TemporalType.DATE)
    private Date updateOn;

    public CompanyState() {
    }

    public CompanyState(CompanyStatus companyStatus, Company company, AdminAccount doneBy, Date updateOn) {
        this.companyStatus = companyStatus;
        this.company = company;
        this.doneBy = doneBy;
        this.updateOn = updateOn;
    }
    
    

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public CompanyStatus getCompanyStatus() {
        return companyStatus;
    }

    public void setCompanyStatus(CompanyStatus companyStatus) {
        this.companyStatus = companyStatus;
    }

    public Company getCompany() {
        return company;
    }

    public void setCompany(Company company) {
        this.company = company;
    }

    public AdminAccount getDoneBy() {
        return doneBy;
    }

    public void setDoneBy(AdminAccount doneBy) {
        this.doneBy = doneBy;
    }

    public Date getUpdateOn() {
        return updateOn;
    }

    public void setUpdateOn(Date updateOn) {
        this.updateOn = updateOn;
    }
    
    
}
<file_sep>/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package testing;

import com.ninja_squad.dbsetup.DbSetup;
import com.ninja_squad.dbsetup.destination.DriverManagerDestination;
import com.ninja_squad.dbsetup.operation.Operation;

/**
 *
 * @author Philip
 */
public class DBSetupConfig {
    public void executeOperation(Operation operation) {
        DbSetup dbSetup = new DbSetup(new DriverManagerDestination(
                "jdbc:postgresql://localhost:5432/boobus", 
                "postgres", 
                "philip12"), operation);
        dbSetup.launch();
    }
}
<file_sep>/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package model;

import javax.persistence.Column;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.GeneratedValue;
import javax.persistence.MappedSuperclass;

/**
 *
 * @author Philip
 */
@MappedSuperclass
public class Account {
    private String email;
    private String password;
    @Enumerated(EnumType.STRING)
    @Column(name = "account_role")
    private Role accountRole;
    
    @Column(nullable = false)
    @Enumerated(EnumType.STRING)
    private AccountStatus accountStatus;

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public AccountStatus getAccountStatus() {
        return accountStatus;
    }

    public void setAccountStatus(AccountStatus accountStatus) {
        this.accountStatus = accountStatus;
    }

    public Role getAccountRole() {
        return accountRole;
    }

    public void setAccountRole(Role accountRole) {
        this.accountRole = accountRole;
    }

    
}
<file_sep>package org.apache.jsp;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.jsp.*;
import model.Route;
import java.util.List;
import dao.GeneralDao;
import model.Company;

public final class routes_jsp extends org.apache.jasper.runtime.HttpJspBase
    implements org.apache.jasper.runtime.JspSourceDependent {

  private static final JspFactory _jspxFactory = JspFactory.getDefaultFactory();

  private static java.util.List<String> _jspx_dependants;

  private org.glassfish.jsp.api.ResourceInjector _jspx_resourceInjector;

  public java.util.List<String> getDependants() {
    return _jspx_dependants;
  }

  public void _jspService(HttpServletRequest request, HttpServletResponse response)
        throws java.io.IOException, ServletException {

    PageContext pageContext = null;
    HttpSession session = null;
    ServletContext application = null;
    ServletConfig config = null;
    JspWriter out = null;
    Object page = this;
    JspWriter _jspx_out = null;
    PageContext _jspx_page_context = null;

    try {
      response.setContentType("text/html;charset=UTF-8");
      pageContext = _jspxFactory.getPageContext(this, request, response,
      			null, true, 8192, true);
      _jspx_page_context = pageContext;
      application = pageContext.getServletContext();
      config = pageContext.getServletConfig();
      session = pageContext.getSession();
      out = pageContext.getOut();
      _jspx_out = out;
      _jspx_resourceInjector = (org.glassfish.jsp.api.ResourceInjector) application.getAttribute("com.sun.appserv.jsp.resource.injector");

      out.write("\n");
      out.write("\n");
      out.write("\n");
      out.write("\n");
      out.write("\n");
      out.write("\n");
      out.write("\n");
      out.write("\n");
      out.write("\n");
      out.write("<!DOCTYPE html>\n");
      out.write("<html lang=\"en\">\n");
      out.write("    <head>\n");
      out.write("        <meta charset=\"utf-8\" />\n");
      out.write("        <meta http-equiv=\"X-UA-Compatible\" content=\"IE=edge\" />\n");
      out.write("        <meta name=\"viewport\" content=\"width=device-width, initial-scale=1\" />\n");
      out.write("        <link rel=\"stylesheet\" href=\"assets/tailwind.css\">\n");
      out.write("        <link rel=\"stylesheet\" href=\"assets/css/bootstrap.min.css\">\n");
      out.write("    </head>\n");
      out.write("    <body class=\"h-screen overflow-hidden flex items-center justify-start\" style=\"background: #edf2f7\">\n");
      out.write("        ");

            GeneralDao<Company> companyDao = new GeneralDao<>();
            GeneralDao<Route> routeDao = new GeneralDao<>();
            List<Company> companylist = companyDao.findAll(new Company());
            List<Route> routes = routeDao.findAll(new Route());

        
      out.write("\n");
      out.write("        <script\n");
      out.write("            src=\"https://cdn.jsdelivr.net/gh/alpinejs/alpine@v2.x.x/dist/alpine.min.js\"\n");
      out.write("            defer\n");
      out.write("        ></script>\n");
      out.write("\n");
      out.write("        <div class=\"bg-gray-200 font-sans\">\n");
      out.write("            <div class=\"flex flex-col sm:flex-row sm:justify-around\">\n");
      out.write("                <div class=\"w-64 h-screen bg-gray-800\">\n");
      out.write("                    <div class=\"flex items-center justify-center mt-10\">\n");
      out.write("                        <!--<img class=\"h-6\" src=\"https://premium-tailwindcomponents.netlify.app/assets/svg/tailwindcomponent-light.svg\">--> \n");
      out.write("                    </div>\n");
      out.write("\n");
      out.write("                    <nav class=\"mt-10\">\n");
      out.write("                        <div x-data=\"{ open: false }\">\n");
      out.write("                            <button\n");
      out.write("                                @click=\"open = !open\"\n");
      out.write("                                class=\"w-full flex justify-between items-center py-3 px-6 text-gray-100 cursor-pointer hover:bg-gray-700 hover:text-gray-100 focus:outline-none\"\n");
      out.write("                                >\n");
      out.write("                                <span class=\"flex items-center\">\n");
      out.write("                                    <svg\n");
      out.write("                                        class=\"h-5 w-5\"\n");
      out.write("                                        viewBox=\"0 0 24 24\"\n");
      out.write("                                        fill=\"none\"\n");
      out.write("                                        xmlns=\"http://www.w3.org/2000/svg\"\n");
      out.write("                                        >\n");
      out.write("                                    <path\n");
      out.write("                                        d=\"M19 11H5M19 11C20.1046 11 21 11.8954 21 13V19C21 20.1046 20.1046 21 19 21H5C3.89543 21 3 20.1046 3 19V13C3 11.8954 3.89543 11 5 11M19 11V9C19 7.89543 18.1046 7 17 7M5 11V9C5 7.89543 5.89543 7 7 7M7 7V5C7 3.89543 7.89543 3 9 3H15C16.1046 3 17 3.89543 17 5V7M7 7H17\"\n");
      out.write("                                        stroke=\"currentColor\"\n");
      out.write("                                        stroke-width=\"2\"\n");
      out.write("                                        stroke-linecap=\"round\"\n");
      out.write("                                        stroke-linejoin=\"round\"\n");
      out.write("                                        ></path>\n");
      out.write("                                    </svg>\n");
      out.write("\n");
      out.write("                                    <span class=\"mx-4 font-medium\">Dashboard</span>\n");
      out.write("                                </span>\n");
      out.write("\n");
      out.write("                                <span>\n");
      out.write("                                    <svg\n");
      out.write("                                        class=\"h-4 w-4\"\n");
      out.write("                                        viewBox=\"0 0 24 24\"\n");
      out.write("                                        fill=\"none\"\n");
      out.write("                                        xmlns=\"http://www.w3.org/2000/svg\"\n");
      out.write("                                        >\n");
      out.write("                                    <path\n");
      out.write("                                        x-show=\"! open\"\n");
      out.write("                                        d=\"M9 5L16 12L9 19\"\n");
      out.write("                                        stroke=\"currentColor\"\n");
      out.write("                                        stroke-width=\"2\"\n");
      out.write("                                        stroke-linecap=\"round\"\n");
      out.write("                                        stroke-linejoin=\"round\"\n");
      out.write("                                        style=\"display: none\"\n");
      out.write("                                        ></path>\n");
      out.write("                                    <path\n");
      out.write("                                        x-show=\"open\"\n");
      out.write("                                        d=\"M19 9L12 16L5 9\"\n");
      out.write("                                        stroke=\"currentColor\"\n");
      out.write("                                        stroke-width=\"2\"\n");
      out.write("                                        stroke-linecap=\"round\"\n");
      out.write("                                        stroke-linejoin=\"round\"\n");
      out.write("                                        ></path>\n");
      out.write("                                    </svg>\n");
      out.write("                                </span>\n");
      out.write("                            </button>\n");
      out.write("\n");
      out.write("                            <div x-show=\"open\" class=\"bg-gray-700\">\n");
      out.write("                                <a\n");
      out.write("                                    class=\"py-2 px-16 block text-sm text-gray-100 hover:bg-blue-500 hover:text-white\"\n");
      out.write("                                    href=\"#\"\n");
      out.write("                                    >Manage Accounts</a\n");
      out.write("                                >\n");
      out.write("                            </div>\n");
      out.write("                        </div>\n");
      out.write("\n");
      out.write("                        <div x-data=\"{ open: false }\">\n");
      out.write("                            <button\n");
      out.write("                                @click=\"open = !open\"\n");
      out.write("                                class=\"w-full flex justify-between items-center py-3 px-6 text-gray-100 cursor-pointer hover:bg-gray-700 hover:text-gray-100 focus:outline-none\"\n");
      out.write("                                >\n");
      out.write("                                <span class=\"flex items-center\">\n");
      out.write("                                    <svg\n");
      out.write("                                        class=\"h-5 w-5\"\n");
      out.write("                                        viewBox=\"0 0 24 24\"\n");
      out.write("                                        fill=\"none\"\n");
      out.write("                                        xmlns=\"http://www.w3.org/2000/svg\"\n");
      out.write("                                        >\n");
      out.write("                                    <path\n");
      out.write("                                        d=\"M16 7C16 9.20914 14.2091 11 12 11C9.79086 11 8 9.20914 8 7C8 4.79086 9.79086 3 12 3C14.2091 3 16 4.79086 16 7Z\"\n");
      out.write("                                        stroke=\"currentColor\"\n");
      out.write("                                        stroke-width=\"2\"\n");
      out.write("                                        stroke-linecap=\"round\"\n");
      out.write("                                        stroke-linejoin=\"round\"\n");
      out.write("                                        ></path>\n");
      out.write("                                    <path\n");
      out.write("                                        d=\"M12 14C8.13401 14 5 17.134 5 21H19C19 17.134 15.866 14 12 14Z\"\n");
      out.write("                                        stroke=\"currentColor\"\n");
      out.write("                                        stroke-width=\"2\"\n");
      out.write("                                        stroke-linecap=\"round\"\n");
      out.write("                                        stroke-linejoin=\"round\"\n");
      out.write("                                        ></path>\n");
      out.write("                                    </svg>\n");
      out.write("\n");
      out.write("                                    <span class=\"mx-4 font-medium\">Journeys</span>\n");
      out.write("                                </span>\n");
      out.write("\n");
      out.write("                                <span>\n");
      out.write("                                    <svg\n");
      out.write("                                        class=\"h-4 w-4\"\n");
      out.write("                                        viewBox=\"0 0 24 24\"\n");
      out.write("                                        fill=\"none\"\n");
      out.write("                                        xmlns=\"http://www.w3.org/2000/svg\"\n");
      out.write("                                        >\n");
      out.write("                                    <path\n");
      out.write("                                        x-show=\"! open\"\n");
      out.write("                                        d=\"M9 5L16 12L9 19\"\n");
      out.write("                                        stroke=\"currentColor\"\n");
      out.write("                                        stroke-width=\"2\"\n");
      out.write("                                        stroke-linecap=\"round\"\n");
      out.write("                                        stroke-linejoin=\"round\"\n");
      out.write("                                        style=\"display: none\"\n");
      out.write("                                        ></path>\n");
      out.write("                                    <path\n");
      out.write("                                        x-show=\"open\"\n");
      out.write("                                        d=\"M19 9L12 16L5 9\"\n");
      out.write("                                        stroke=\"currentColor\"\n");
      out.write("                                        stroke-width=\"2\"\n");
      out.write("                                        stroke-linecap=\"round\"\n");
      out.write("                                        stroke-linejoin=\"round\"\n");
      out.write("                                        ></path>\n");
      out.write("                                    </svg>\n");
      out.write("                                </span>\n");
      out.write("                            </button>\n");
      out.write("\n");
      out.write("                            <div x-show=\"open\" class=\"bg-gray-700\">\n");
      out.write("                                <a\n");
      out.write("                                    class=\"py-2 px-16 block text-sm text-gray-100 hover:bg-blue-500 hover:text-white\"\n");
      out.write("                                    href=\"#\">Add Journey\n");
      out.write("                                </a\n");
      out.write("                                <a\n");
      out.write("                                    class=\"py-2 px-16 block text-sm text-gray-100 hover:bg-blue-500 hover:text-white\"\n");
      out.write("                                    href=\"#\">All Journey\n");
      out.write("                                </a\n");
      out.write("                            </div>\n");
      out.write("                        </div>\n");
      out.write("\n");
      out.write("                        <div x-data=\"{ open: false }\">\n");
      out.write("                            <button\n");
      out.write("                                @click=\"open = !open\"\n");
      out.write("                                class=\"w-full flex justify-between items-center py-3 px-6 text-gray-100 cursor-pointer hover:bg-gray-700 hover:text-gray-100 focus:outline-none\"\n");
      out.write("                                >\n");
      out.write("                                <span class=\"flex items-center\">\n");
      out.write("                                    <svg\n");
      out.write("                                        class=\"h-5 w-5\"\n");
      out.write("                                        viewBox=\"0 0 24 24\"\n");
      out.write("                                        fill=\"none\"\n");
      out.write("                                        xmlns=\"http://www.w3.org/2000/svg\"\n");
      out.write("                                        >\n");
      out.write("                                    <path\n");
      out.write("                                        d=\"M15 5V7M15 11V13M15 17V19M5 5C3.89543 5 3 5.89543 3 7V10C4.10457 10 5 10.8954 5 12C5 13.1046 4.10457 14 3 14V17C3 18.1046 3.89543 19 5 19H19C20.1046 19 21 18.1046 21 17V14C19.8954 14 19 13.1046 19 12C19 10.8954 19.8954 10 21 10V7C21 5.89543 20.1046 5 19 5H5Z\"\n");
      out.write("                                        stroke=\"currentColor\"\n");
      out.write("                                        stroke-width=\"2\"\n");
      out.write("                                        stroke-linecap=\"round\"\n");
      out.write("                                        stroke-linejoin=\"round\"\n");
      out.write("                                        ></path>\n");
      out.write("                                    </svg>\n");
      out.write("\n");
      out.write("                                    <span class=\"mx-4 font-medium\">Tickets</span>\n");
      out.write("                                </span>\n");
      out.write("\n");
      out.write("                                <span>\n");
      out.write("                                    <svg\n");
      out.write("                                        class=\"h-4 w-4\"\n");
      out.write("                                        viewBox=\"0 0 24 24\"\n");
      out.write("                                        fill=\"none\"\n");
      out.write("                                        xmlns=\"http://www.w3.org/2000/svg\"\n");
      out.write("                                        >\n");
      out.write("                                    <path\n");
      out.write("                                        x-show=\"! open\"\n");
      out.write("                                        d=\"M9 5L16 12L9 19\"\n");
      out.write("                                        stroke=\"currentColor\"\n");
      out.write("                                        stroke-width=\"2\"\n");
      out.write("                                        stroke-linecap=\"round\"\n");
      out.write("                                        stroke-linejoin=\"round\"\n");
      out.write("                                        style=\"display: none\"\n");
      out.write("                                        ></path>\n");
      out.write("                                    <path\n");
      out.write("                                        x-show=\"open\"\n");
      out.write("                                        d=\"M19 9L12 16L5 9\"\n");
      out.write("                                        stroke=\"currentColor\"\n");
      out.write("                                        stroke-width=\"2\"\n");
      out.write("                                        stroke-linecap=\"round\"\n");
      out.write("                                        stroke-linejoin=\"round\"\n");
      out.write("                                        ></path>\n");
      out.write("                                    </svg>\n");
      out.write("                                </span>\n");
      out.write("                            </button>\n");
      out.write("\n");
      out.write("                            <div x-show=\"open\" class=\"bg-gray-700\">\n");
      out.write("                                <a\n");
      out.write("                                    class=\"py-2 px-16 block text-sm text-gray-100 hover:bg-blue-500 hover:text-white\"\n");
      out.write("                                    href=\"#\"\n");
      out.write("                                    >All Tickets</a\n");
      out.write("                                >\n");
      out.write("                                <a\n");
      out.write("                                    class=\"py-2 px-16 block text-sm text-gray-100 hover:bg-blue-500 hover:text-white\"\n");
      out.write("                                    href=\"#\"\n");
      out.write("                                    >Create Ticket</a\n");
      out.write("                                >\n");
      out.write("                            </div>\n");
      out.write("                        </div>\n");
      out.write("                    </nav>\n");
      out.write("\n");
      out.write("                    <div class=\"absolute bottom-0 my-8\">\n");
      out.write("                        <a\n");
      out.write("                            class=\"flex items-center py-2 px-8 text-gray-100 hover:text-gray-200\"\n");
      out.write("                            href=\"#\"\n");
      out.write("                            >\n");
      out.write("                            <img\n");
      out.write("                                class=\"h-6 w-6 rounded-full mr-3 object-cover\"\n");
      out.write("                                src=\"https://lh3.googleusercontent.com/a-/AOh14Gi0DgItGDTATTFV6lPiVrqtja6RZ_qrY91zg42o-g\"\n");
      out.write("                                alt=\"avatar\"\n");
      out.write("                                />\n");
      out.write("                            <span>Khatabwedaa</span>\n");
      out.write("                        </a>\n");
      out.write("                    </div>\n");
      out.write("                </div>\n");
      out.write("            </div>\n");
      out.write("        </div>\n");
      out.write("\n");
      out.write("\n");
      out.write("        <!-- <div class=\"grid w-full min-h-screen place-items-center\"> -->\n");
      out.write("\n");
      out.write("\n");
      out.write("        <div class=\"overflow-x-auto bg-white w-5/6 h-screen mt-0 md:mt-0 md:col-span-2 view-routes\" id=\"admin-tab\">\n");
      out.write("            ");
                if (request.getAttribute("message") != null) {
                    String message = (String) request.getAttribute("message");
            
      out.write("\n");
      out.write("            <div class=\"container px-4 py-1\" id=\"alertbox\">\n");
      out.write("                <div class=\"container bg-blue-500 flex items-center text-white text-sm font-bold px-4 py-3 relative\"\n");
      out.write("                     role=\"alert\">\n");
      out.write("                    <svg class=\"fill-current w-4 h-4 mr-2\" xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 20 20\">\n");
      out.write("                    <path\n");
      out.write("                        d=\"M12.432 0c1.34 0 2.01.912 2.01 1.957 0 1.305-1.164 2.512-2.679 2.512-1.269 0-2.009-.75-1.974-1.99C9.789 1.436 10.67 0 12.432 0zM8.309 20c-1.058 0-1.833-.652-1.093-3.524l1.214-5.092c.211-.814.246-1.141 0-1.141-.317 0-1.689.562-2.502 1.117l-.528-.88c2.572-2.186 5.531-3.467 6.801-3.467 1.057 0 1.233 1.273.705 3.23l-1.391 5.352c-.246.945-.141 1.271.106 1.271.317 0 1.357-.392 2.379-1.207l.6.814C12.098 19.02 9.365 20 8.309 20z\" />\n");
      out.write("                    </svg>\n");
      out.write("                    <p>");
      out.print(message);
      out.write("</p>\n");
      out.write("\n");
      out.write("                    <span class=\"absolute top-0 bottom-0 right-0 px-4 py-3 closealertbutton\">\n");
      out.write("                        <svg class=\"fill-current h-6 w-6 text-white\" role=\"button\" xmlns=\"http://www.w3.org/2000/svg\"\n");
      out.write("                             viewBox=\"0 0 20 20\">\n");
      out.write("                        <title>Close</title>\n");
      out.write("                        <path\n");
      out.write("                            d=\"M14.348 14.849a1.2 1.2 0 0 1-1.697 0L10 11.819l-2.651 3.029a1.2 1.2 0 1 1-1.697-1.697l2.758-3.15-2.759-3.152a1.2 1.2 0 1 1 1.697-1.697L10 8.183l2.651-3.031a1.2 1.2 0 1 1 1.697 1.697l-2.758 3.152 2.758 3.15a1.2 1.2 0 0 1 0 1.698z\" />\n");
      out.write("                        </svg>\n");
      out.write("                    </span>\n");
      out.write("                </div>\n");
      out.write("            </div>\n");
      out.write("            ");
}
      out.write("\n");
      out.write("            <form action=\"RoutesControl\" method=\"POST\">\n");
      out.write("                <h3 class=\"block text-base text-center font-medium text-gray-700\"> Add Route</h3>\n");
      out.write("                <div class=\"flex flex-col items-center shadow overflow-hidden sm:rounded-md\">\n");
      out.write("                    <div class=\"px-4 py-5  sm:p-6\">\n");
      out.write("                        <div class=\"grid grid-cols-6 gap-6\">\n");
      out.write("                            <div class=\"col-span-6 sm:col-span-3\">\n");
      out.write("                                <label for=\"source\" class=\"block text-sm font-medium text-gray-700\">First name</label>\n");
      out.write("                                <input type=\"text\" name=\"source\" id=\"source\" class=\"mt-1 focus:ring-indigo-500 focus:border-indigo-500 block w-full shadow-sm sm:text-sm border-gray-300 rounded-md\">\n");
      out.write("                            </div>\n");
      out.write("\n");
      out.write("                            <div class=\"col-span-6 sm:col-span-3\">\n");
      out.write("                                <label for=\"destination\" class=\"block text-sm font-medium text-gray-700\">Last name</label>\n");
      out.write("                                <input type=\"text\" name=\"destination\" id=\"destination\" class=\"mt-1 focus:ring-indigo-500 focus:border-indigo-500 block w-full shadow-sm sm:text-sm border-gray-300 rounded-md\">\n");
      out.write("                            </div>\n");
      out.write("                        </div>\n");
      out.write("                    </div>\n");
      out.write("                    <input type=\"text\" name=\"action\" hidden=\"\" value=\"addroute\">\n");
      out.write("                    <div class=\"px-4 py-3 bg-gray-50 text-right sm:px-6\">\n");
      out.write("                        <button type=\"submit\" class=\"inline-flex justify-center py-2 px-4 border border-transparent shadow-sm text-sm font-medium rounded-md text-white bg-indigo-600 hover:bg-indigo-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-indigo-500\">\n");
      out.write("                            Save\n");
      out.write("                        </button>\n");
      out.write("                    </div>\n");
      out.write("                </div>\n");
      out.write("            </form>\n");
      out.write("            <h3 class=\"block text-base text-center font-medium text-gray-700 py-3\"> All Routes</h3>\n");
      out.write("            <table class=\"min-w-max w-full table-auto\">\n");
      out.write("                <thead>\n");
      out.write("                    <tr class=\"bg-gray-200 text-gray-600 uppercase text-sm leading-normal\">\n");
      out.write("                        <th class=\"py-3 px-6 text-left\">Route Id</th>\n");
      out.write("                        <th class=\"py-3 px-6 text-left\">Source</th>\n");
      out.write("                        <th class=\"py-3 px-6 text-left\">Destination</th>\n");
      out.write("                        <th class=\"py-3 px-6 text-center\">Actions</th>\n");
      out.write("                    </tr>\n");
      out.write("                </thead>\n");
      out.write("                <tbody class=\"text-gray-600 text-sm font-light\">\n");
      out.write("                    ");

                        for (Route route : routes) {
                    
      out.write("\n");
      out.write("                    <tr class=\"border-b border-gray-200 hover:bg-gray-100\">\n");
      out.write("                        <td class=\"py-3 px-6 text-left whitespace-nowrap font-medium\">#");
      out.print(route.getId());
      out.write("</td>\n");
      out.write("                        <td class=\"py-3 px-6 text-left text-blue-600 whitespace-nowrap font-medium\">");
      out.print(route.getSource());
      out.write("</td>\n");
      out.write("                        <td class=\"py-3 px-6 text-left text-purple-600 whitespace-nowrap font-medium\">");
      out.print(route.getDestination());
      out.write("</td>\n");
      out.write("                        <td class=\"py-3 px-6 text-center\">\n");
      out.write("                            <div class=\"flex item-center justify-center\">\n");
      out.write("                                <a href=\"updateroute.jsp?id=");
      out.print(route.getId());
      out.write("\">\n");
      out.write("                                    <div class=\"w-4 mr-2 transform hover:text-purple-500 hover:scale-110\">\n");
      out.write("                                        <svg xmlns=\"http://www.w3.org/2000/svg\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\">\n");
      out.write("                                        <path stroke-linecap=\"round\" stroke-linejoin=\"round\" stroke-width=\"2\" d=\"M15.232 5.232l3.536 3.536m-2.036-5.036a2.5 2.5 0 113.536 3.536L6.5 21.036H3v-3.572L16.732 3.732z\" />\n");
      out.write("                                        </svg>\n");
      out.write("                                    </div></a>\n");
      out.write("                                <div class=\"w-4 mr-2 transform hover:text-purple-500 hover:scale-110\">\n");
      out.write("                                    <svg xmlns=\"http://www.w3.org/2000/svg\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\">\n");
      out.write("                                    <path stroke-linecap=\"round\" stroke-linejoin=\"round\" stroke-width=\"2\" d=\"M19 7l-.867 12.142A2 2 0 0116.138 21H7.862a2 2 0 01-1.995-1.858L5 7m5 4v6m4-6v6m1-10V4a1 1 0 00-1-1h-4a1 1 0 00-1 1v3M4 7h16\" />\n");
      out.write("                                    </svg>\n");
      out.write("                                </div>\n");
      out.write("                            </div>\n");
      out.write("                        </td>\n");
      out.write("                    </tr>\n");
      out.write("                    ");
}
      out.write("\n");
      out.write("                </tbody>\n");
      out.write("            </table>\n");
      out.write("        </div>\n");
      out.write("\n");
      out.write("        <!-- </div> -->\n");
      out.write("        <script src=\"assets/js/vendor/jquery-1.12.4.min.js\"\n");
      out.write("                \n");
      out.write("        </script>\n");
      out.write("        <script src=\"./assets/js/bootstrap.min.js\"></script>\n");
      out.write("\n");
      out.write("\n");
      out.write("        <script>\n");
      out.write("            function openMenu(evt, MenuName) {\n");
      out.write("                var i, x, tablinks;\n");
      out.write("                x = document.getElementsByClassName(\"admin-tab\");\n");
      out.write("                for (i = 0; i < x.length; i++) {\n");
      out.write("                    x[i].style.display = \"none\";\n");
      out.write("                }\n");
      out.write("                document.getElementById(MenuName).style.display = \"block\";\n");
      out.write("                evt.currentTarget.className += \" w3-grey\";\n");
      out.write("            }\n");
      out.write("            $(\".closealertbutton\").click(function (e) {\n");
      out.write("\n");
      out.write("                pid = $(this).parent().parent().hide(500)\n");
      out.write("                console.log(pid)\n");
      out.write("            })\n");
      out.write("            if (window.history.replaceState) {\n");
      out.write("                window.history.replaceState(null, null, window.location.href);\n");
      out.write("            }\n");
      out.write("        </script>\n");
      out.write("    </body>\n");
      out.write("</html>\n");
      out.write("\n");
      out.write("\n");
    } catch (Throwable t) {
      if (!(t instanceof SkipPageException)){
        out = _jspx_out;
        if (out != null && out.getBufferSize() != 0)
          out.clearBuffer();
        if (_jspx_page_context != null) _jspx_page_context.handlePageException(t);
        else throw new ServletException(t);
      }
    } finally {
      _jspxFactory.releasePageContext(_jspx_page_context);
    }
  }
}
<file_sep>/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package model;

import java.util.ArrayList;
import java.util.List;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Inheritance;
import javax.persistence.InheritanceType;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import javax.persistence.SequenceGenerator;

/**
 *
 * @author Philip
 */
@Entity
@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
@SequenceGenerator(name="claccountseq", sequenceName = "claccount_seq", initialValue = 1,allocationSize = 1)
public class ManagerAccount extends Account {
    @Id
    @GeneratedValue(strategy=GenerationType.SEQUENCE, generator="claccountseq")
    private long id;
    
    @OneToOne
    private Manager manager;
    @OneToMany(mappedBy = "managerAccount")
    private List<AccountState> accountState = new ArrayList<>();
    
    @OneToOne
    private Company company;

    public long getId() {
        return id;
    }

    public void setId(long id) {
        this.id = id;
    }

    public Manager getManager() {
        return manager;
    }

    public void setManager(Manager manager) {
        this.manager = manager;
    }
    
    

    public Company getCompany() {
        return company;
    }

    public void setCompany(Company company) {
        this.company = company;
    }

    public List<AccountState> getAccountState() {
        return accountState;
    }

    public void setAccountState(List<AccountState> accountState) {
        this.accountState = accountState;
    }
    
    
    
    
}
<file_sep>/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package controller;

import dao.GeneralDao;
import dao.RouteDao;
import java.io.IOException;
import java.sql.Timestamp;
import java.text.SimpleDateFormat;
import java.util.Date;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import model.Company;
import model.CompanyRoute;
import model.ManagerAccount;
import model.Route;
import model.RouteStatus;
import model.Status;

/**
 *
 * @author Philip
 */
@WebServlet(name = "RoutesControl", urlPatterns = {"/RoutesControl"})
public class RoutesControl extends HttpServlet {

    GeneralDao<Route> routeDao = new GeneralDao<>();
    GeneralDao<CompanyRoute> CRDao = new GeneralDao<>();
    Route route;
    CompanyRoute companyRoute;
    RequestDispatcher dispatcher;

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        String action = request.getParameter("action");
        switch (action) {
            case "request":
                RouteDao rdao = new RouteDao();
                long id = Long.parseLong(request.getParameter("id"));
                route = routeDao.findOne(Route.class, id);
                ManagerAccount account = (ManagerAccount) request.getSession().getAttribute("user");
                Company company = account.getCompany();

                boolean status = rdao.checkRouteRequest(company.getId(), id);
                System.out.println("status is :" + status);

                if (status) {
                    request.setAttribute("message", "request has been sent before!!");
                    dispatcher = request.getRequestDispatcher("requestroute.jsp");
                    dispatcher.forward(request, response);

                } else {
                    CompanyRoute companyRoute = new CompanyRoute();
                    companyRoute.setRoute(route);
                    companyRoute.setCompany(company);
                    companyRoute.setRouteStatus(RouteStatus.REQUESTED);
                    Timestamp ts = new Timestamp(new Date().getTime());
                    SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                    companyRoute.setRegisteredDate(Timestamp.valueOf(formatter.format(ts)));
                    CRDao.create(companyRoute);
                    request.setAttribute("message", "request sent!!");
                    dispatcher = request.getRequestDispatcher("requestroute.jsp");
                    dispatcher.forward(request, response);
                }
                break;
            case "approve":
                companyRoute = CRDao.findOne(CompanyRoute.class, Long.parseLong(request.getParameter("id")));
                companyRoute.setRouteStatus(RouteStatus.APPROVED);
                CRDao.update(companyRoute);
                request.setAttribute("message", "route request is approved successfully");
                dispatcher = request.getRequestDispatcher("requestedroutes.jsp");
                dispatcher.forward(request, response);
                break;
            case "suspend":
                companyRoute = CRDao.findOne(CompanyRoute.class, Long.parseLong(request.getParameter("id")));
                companyRoute.setRouteStatus(RouteStatus.SUSPENDED);
                CRDao.update(companyRoute);
                request.setAttribute("message", "route is successfully suspended");
                dispatcher = request.getRequestDispatcher("requestedroutes.jsp");
                dispatcher.forward(request, response);
                break;

            default:
                System.out.println("no action specified");

        }
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {

        String action = request.getParameter("action");
        switch (action) {
            case "addroute":
                route = new Route();
                route.setSource(request.getParameter("source"));
                route.setDestination(request.getParameter("destination"));
                route.setStatus(Status.valueOf(request.getParameter("status")));
                routeDao.create(route);
                request.setAttribute("message", "route added successfully!!!");
                dispatcher = request.getRequestDispatcher("routes.jsp");
                dispatcher.forward(request, response);
                break;
            case "updateroute":
                route = routeDao.findOne(Route.class, Long.parseLong(request.getParameter("id")));
                route.setSource(request.getParameter("source"));
                route.setDestination(request.getParameter("destination"));
                route.setStatus(Status.valueOf(request.getParameter("status")));
                routeDao.update(route);
                request.setAttribute("message", "route updated successfully!!!");
                dispatcher = request.getRequestDispatcher("routes.jsp");
                dispatcher.forward(request, response);
                break;

            default:
                System.out.println("no action specified");
        }
    }

    /**
     * Returns a short description of the servlet.
     *
     * @return a String containing servlet description
     */
    @Override
    public String getServletInfo() {
        return "Short description";
    }// </editor-fold>

}
<file_sep>/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package dao;

import java.util.List;
import model.CompanyRoute;
import model.Journey;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.SessionFactory;

/**
 *
 * @author Philip
 */
public class JourneyDao {
    SessionFactory sf=DBUtil.getSessionFactory(); 
    Session session=null;
    
    public List<Journey> getCompanyJourneys(long id) {
        session = sf.openSession();
        Query query = session.createQuery("FROM Journey where company_id='"+id+"'" );
        List<Journey> companyJourneys = (List<Journey>) query.list();
        session.close();
        return companyJourneys;
    }
    
    //check previous request
    public boolean checkRouteRequest(long company_id, long route_id) {
        session = sf.openSession();
        Query query = session.createQuery("FROM CompanyRoute where company_id='"+company_id+"' and route_id='"+route_id+"'" );
        CompanyRoute companyRoute = (CompanyRoute) query.uniqueResult();
        session.close();
        try {
            long id = companyRoute.getId();
            return true;
        } catch (NullPointerException e) {
            return false;
        } 
    }
    
    public List<CompanyRoute> approvedRoutes(long id) {
        session = sf.openSession();
        Query query = session.createQuery("FROM CompanyRoute where company_id='"+id+"' and routestatus='APPROVED'" );
        List<CompanyRoute> companyRoutes = (List<CompanyRoute>) query.list();
        session.close();
        return companyRoutes;
    }
    
    public List<Journey> availableJourneys(long id) {
        session = sf.openSession();
        Query query = session.createQuery("FROM Journey where route_id='"+id+"' and journeystatus='BOOKING'" );
        List<Journey> journeys = (List<Journey>) query.list();
        session.close();
        return journeys;
    }
}
<file_sep>package org.apache.jsp;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.jsp.*;
import java.util.List;
import dao.GeneralDao;
import model.Company;

public final class updateroute_jsp extends org.apache.jasper.runtime.HttpJspBase
    implements org.apache.jasper.runtime.JspSourceDependent {

  private static final JspFactory _jspxFactory = JspFactory.getDefaultFactory();

  private static java.util.List<String> _jspx_dependants;

  private org.glassfish.jsp.api.ResourceInjector _jspx_resourceInjector;

  public java.util.List<String> getDependants() {
    return _jspx_dependants;
  }

  public void _jspService(HttpServletRequest request, HttpServletResponse response)
        throws java.io.IOException, ServletException {

    PageContext pageContext = null;
    HttpSession session = null;
    ServletContext application = null;
    ServletConfig config = null;
    JspWriter out = null;
    Object page = this;
    JspWriter _jspx_out = null;
    PageContext _jspx_page_context = null;

    try {
      response.setContentType("text/html;charset=UTF-8");
      pageContext = _jspxFactory.getPageContext(this, request, response,
      			null, true, 8192, true);
      _jspx_page_context = pageContext;
      application = pageContext.getServletContext();
      config = pageContext.getServletConfig();
      session = pageContext.getSession();
      out = pageContext.getOut();
      _jspx_out = out;
      _jspx_resourceInjector = (org.glassfish.jsp.api.ResourceInjector) application.getAttribute("com.sun.appserv.jsp.resource.injector");

      out.write('\n');
      out.write('\n');
      out.write('\n');
      out.write('\n');
      out.write("\n");
      out.write("\n");
      out.write("\n");
      out.write("\n");
      out.write("\n");
      out.write("\n");
      out.write("<!DOCTYPE html>\n");
      out.write("<html lang=\"en\">\n");
      out.write("    <head>\n");
      out.write("        <meta charset=\"utf-8\" />\n");
      out.write("        <meta http-equiv=\"X-UA-Compatible\" content=\"IE=edge\" />\n");
      out.write("        <meta name=\"viewport\" content=\"width=device-width, initial-scale=1\" />\n");
      out.write("        <link rel=\"stylesheet\" href=\"assets/tailwind.css\">\n");
      out.write("    </head>\n");
      out.write("    <body class=\"h-screen overflow-hidden flex items-center justify-start\" style=\"background: #edf2f7\">\n");
      out.write("        ");

//            GeneralDao<Company> companyDao = new GeneralDao<>();
//            List<Company> companylist = companyDao.findAll(new Company());

        
      out.write("\n");
      out.write("        <script\n");
      out.write("            src=\"https://cdn.jsdelivr.net/gh/alpinejs/alpine@v2.x.x/dist/alpine.min.js\"\n");
      out.write("            defer\n");
      out.write("        ></script>\n");
      out.write("\n");
      out.write("        <div class=\"bg-gray-200 font-sans\">\n");
      out.write("            <div class=\"flex flex-col sm:flex-row sm:justify-around\">\n");
      out.write("                <div class=\"w-64 h-screen bg-gray-800\">\n");
      out.write("                    <div class=\"flex items-center justify-center mt-10\">\n");
      out.write("                        <!--<img class=\"h-6\" src=\"https://premium-tailwindcomponents.netlify.app/assets/svg/tailwindcomponent-light.svg\">--> \n");
      out.write("                    </div>\n");
      out.write("\n");
      out.write("                    <nav class=\"mt-10\">\n");
      out.write("                        <div x-data=\"{ open: false }\">\n");
      out.write("                            <button\n");
      out.write("                                @click=\"open = !open\"\n");
      out.write("                                class=\"w-full flex justify-between items-center py-3 px-6 text-gray-100 cursor-pointer hover:bg-gray-700 hover:text-gray-100 focus:outline-none\"\n");
      out.write("                                >\n");
      out.write("                                <span class=\"flex items-center\">\n");
      out.write("                                    <svg\n");
      out.write("                                        class=\"h-5 w-5\"\n");
      out.write("                                        viewBox=\"0 0 24 24\"\n");
      out.write("                                        fill=\"none\"\n");
      out.write("                                        xmlns=\"http://www.w3.org/2000/svg\"\n");
      out.write("                                        >\n");
      out.write("                                    <path\n");
      out.write("                                        d=\"M19 11H5M19 11C20.1046 11 21 11.8954 21 13V19C21 20.1046 20.1046 21 19 21H5C3.89543 21 3 20.1046 3 19V13C3 11.8954 3.89543 11 5 11M19 11V9C19 7.89543 18.1046 7 17 7M5 11V9C5 7.89543 5.89543 7 7 7M7 7V5C7 3.89543 7.89543 3 9 3H15C16.1046 3 17 3.89543 17 5V7M7 7H17\"\n");
      out.write("                                        stroke=\"currentColor\"\n");
      out.write("                                        stroke-width=\"2\"\n");
      out.write("                                        stroke-linecap=\"round\"\n");
      out.write("                                        stroke-linejoin=\"round\"\n");
      out.write("                                        ></path>\n");
      out.write("                                    </svg>\n");
      out.write("\n");
      out.write("                                    <span class=\"mx-4 font-medium\">Dashboard</span>\n");
      out.write("                                </span>\n");
      out.write("\n");
      out.write("                                <span>\n");
      out.write("                                    <svg\n");
      out.write("                                        class=\"h-4 w-4\"\n");
      out.write("                                        viewBox=\"0 0 24 24\"\n");
      out.write("                                        fill=\"none\"\n");
      out.write("                                        xmlns=\"http://www.w3.org/2000/svg\"\n");
      out.write("                                        >\n");
      out.write("                                    <path\n");
      out.write("                                        x-show=\"! open\"\n");
      out.write("                                        d=\"M9 5L16 12L9 19\"\n");
      out.write("                                        stroke=\"currentColor\"\n");
      out.write("                                        stroke-width=\"2\"\n");
      out.write("                                        stroke-linecap=\"round\"\n");
      out.write("                                        stroke-linejoin=\"round\"\n");
      out.write("                                        style=\"display: none\"\n");
      out.write("                                        ></path>\n");
      out.write("                                    <path\n");
      out.write("                                        x-show=\"open\"\n");
      out.write("                                        d=\"M19 9L12 16L5 9\"\n");
      out.write("                                        stroke=\"currentColor\"\n");
      out.write("                                        stroke-width=\"2\"\n");
      out.write("                                        stroke-linecap=\"round\"\n");
      out.write("                                        stroke-linejoin=\"round\"\n");
      out.write("                                        ></path>\n");
      out.write("                                    </svg>\n");
      out.write("                                </span>\n");
      out.write("                            </button>\n");
      out.write("\n");
      out.write("                            <div x-show=\"open\" class=\"bg-gray-700\">\n");
      out.write("                                <a\n");
      out.write("                                    class=\"py-2 px-16 block text-sm text-gray-100 hover:bg-blue-500 hover:text-white\"\n");
      out.write("                                    href=\"#\"  onclick=\"openMenu(event, 'view-routes')\"\n");
      out.write("                                    >Manage Routes</a\n");
      out.write("                                >\n");
      out.write("                                <a\n");
      out.write("                                    class=\"py-2 px-16 block text-sm text-gray-100 hover:bg-blue-500 hover:text-white\"\n");
      out.write("                                    href=\"#\"\n");
      out.write("                                    >Manage Administrators</a\n");
      out.write("                                >\n");
      out.write("                            </div>\n");
      out.write("                        </div>\n");
      out.write("\n");
      out.write("                        <div x-data=\"{ open: false }\">\n");
      out.write("                            <button\n");
      out.write("                                @click=\"open = !open\"\n");
      out.write("                                class=\"w-full flex justify-between items-center py-3 px-6 text-gray-100 cursor-pointer hover:bg-gray-700 hover:text-gray-100 focus:outline-none\"\n");
      out.write("                                >\n");
      out.write("                                <span class=\"flex items-center\">\n");
      out.write("                                    <svg\n");
      out.write("                                        class=\"h-5 w-5\"\n");
      out.write("                                        viewBox=\"0 0 24 24\"\n");
      out.write("                                        fill=\"none\"\n");
      out.write("                                        xmlns=\"http://www.w3.org/2000/svg\"\n");
      out.write("                                        >\n");
      out.write("                                    <path\n");
      out.write("                                        d=\"M16 7C16 9.20914 14.2091 11 12 11C9.79086 11 8 9.20914 8 7C8 4.79086 9.79086 3 12 3C14.2091 3 16 4.79086 16 7Z\"\n");
      out.write("                                        stroke=\"currentColor\"\n");
      out.write("                                        stroke-width=\"2\"\n");
      out.write("                                        stroke-linecap=\"round\"\n");
      out.write("                                        stroke-linejoin=\"round\"\n");
      out.write("                                        ></path>\n");
      out.write("                                    <path\n");
      out.write("                                        d=\"M12 14C8.13401 14 5 17.134 5 21H19C19 17.134 15.866 14 12 14Z\"\n");
      out.write("                                        stroke=\"currentColor\"\n");
      out.write("                                        stroke-width=\"2\"\n");
      out.write("                                        stroke-linecap=\"round\"\n");
      out.write("                                        stroke-linejoin=\"round\"\n");
      out.write("                                        ></path>\n");
      out.write("                                    </svg>\n");
      out.write("\n");
      out.write("                                    <span class=\"mx-4 font-medium\">Companies</span>\n");
      out.write("                                </span>\n");
      out.write("\n");
      out.write("                                <span>\n");
      out.write("                                    <svg\n");
      out.write("                                        class=\"h-4 w-4\"\n");
      out.write("                                        viewBox=\"0 0 24 24\"\n");
      out.write("                                        fill=\"none\"\n");
      out.write("                                        xmlns=\"http://www.w3.org/2000/svg\"\n");
      out.write("                                        >\n");
      out.write("                                    <path\n");
      out.write("                                        x-show=\"! open\"\n");
      out.write("                                        d=\"M9 5L16 12L9 19\"\n");
      out.write("                                        stroke=\"currentColor\"\n");
      out.write("                                        stroke-width=\"2\"\n");
      out.write("                                        stroke-linecap=\"round\"\n");
      out.write("                                        stroke-linejoin=\"round\"\n");
      out.write("                                        style=\"display: none\"\n");
      out.write("                                        ></path>\n");
      out.write("                                    <path\n");
      out.write("                                        x-show=\"open\"\n");
      out.write("                                        d=\"M19 9L12 16L5 9\"\n");
      out.write("                                        stroke=\"currentColor\"\n");
      out.write("                                        stroke-width=\"2\"\n");
      out.write("                                        stroke-linecap=\"round\"\n");
      out.write("                                        stroke-linejoin=\"round\"\n");
      out.write("                                        ></path>\n");
      out.write("                                    </svg>\n");
      out.write("                                </span>\n");
      out.write("                            </button>\n");
      out.write("\n");
      out.write("                            <div x-show=\"open\" class=\"bg-gray-700\">\n");
      out.write("                                \n");
      out.write("\n");
      out.write("\n");
      out.write("                            </div>\n");
      out.write("                        </div>\n");
      out.write("\n");
      out.write("                        <div x-data=\"{ open: false }\">\n");
      out.write("                            <button\n");
      out.write("                                @click=\"open = !open\"\n");
      out.write("                                class=\"w-full flex justify-between items-center py-3 px-6 text-gray-100 cursor-pointer hover:bg-gray-700 hover:text-gray-100 focus:outline-none\"\n");
      out.write("                                >\n");
      out.write("                                <span class=\"flex items-center\">\n");
      out.write("                                    <svg\n");
      out.write("                                        class=\"h-5 w-5\"\n");
      out.write("                                        viewBox=\"0 0 24 24\"\n");
      out.write("                                        fill=\"none\"\n");
      out.write("                                        xmlns=\"http://www.w3.org/2000/svg\"\n");
      out.write("                                        >\n");
      out.write("                                    <path\n");
      out.write("                                        d=\"M15 5V7M15 11V13M15 17V19M5 5C3.89543 5 3 5.89543 3 7V10C4.10457 10 5 10.8954 5 12C5 13.1046 4.10457 14 3 14V17C3 18.1046 3.89543 19 5 19H19C20.1046 19 21 18.1046 21 17V14C19.8954 14 19 13.1046 19 12C19 10.8954 19.8954 10 21 10V7C21 5.89543 20.1046 5 19 5H5Z\"\n");
      out.write("                                        stroke=\"currentColor\"\n");
      out.write("                                        stroke-width=\"2\"\n");
      out.write("                                        stroke-linecap=\"round\"\n");
      out.write("                                        stroke-linejoin=\"round\"\n");
      out.write("                                        ></path>\n");
      out.write("                                    </svg>\n");
      out.write("\n");
      out.write("                                    <span class=\"mx-4 font-medium\">Tickets</span>\n");
      out.write("                                </span>\n");
      out.write("\n");
      out.write("                                <span>\n");
      out.write("                                    <svg\n");
      out.write("                                        class=\"h-4 w-4\"\n");
      out.write("                                        viewBox=\"0 0 24 24\"\n");
      out.write("                                        fill=\"none\"\n");
      out.write("                                        xmlns=\"http://www.w3.org/2000/svg\"\n");
      out.write("                                        >\n");
      out.write("                                    <path\n");
      out.write("                                        x-show=\"! open\"\n");
      out.write("                                        d=\"M9 5L16 12L9 19\"\n");
      out.write("                                        stroke=\"currentColor\"\n");
      out.write("                                        stroke-width=\"2\"\n");
      out.write("                                        stroke-linecap=\"round\"\n");
      out.write("                                        stroke-linejoin=\"round\"\n");
      out.write("                                        style=\"display: none\"\n");
      out.write("                                        ></path>\n");
      out.write("                                    <path\n");
      out.write("                                        x-show=\"open\"\n");
      out.write("                                        d=\"M19 9L12 16L5 9\"\n");
      out.write("                                        stroke=\"currentColor\"\n");
      out.write("                                        stroke-width=\"2\"\n");
      out.write("                                        stroke-linecap=\"round\"\n");
      out.write("                                        stroke-linejoin=\"round\"\n");
      out.write("                                        ></path>\n");
      out.write("                                    </svg>\n");
      out.write("                                </span>\n");
      out.write("                            </button>\n");
      out.write("\n");
      out.write("                            <div x-show=\"open\" class=\"bg-gray-700\">\n");
      out.write("                                <a\n");
      out.write("                                    class=\"py-2 px-16 block text-sm text-gray-100 hover:bg-blue-500 hover:text-white\"\n");
      out.write("                                    href=\"#\"\n");
      out.write("                                    >All Tickets</a\n");
      out.write("                                >\n");
      out.write("                                <a\n");
      out.write("                                    class=\"py-2 px-16 block text-sm text-gray-100 hover:bg-blue-500 hover:text-white\"\n");
      out.write("                                    href=\"#\"\n");
      out.write("                                    >Create Ticket</a\n");
      out.write("                                >\n");
      out.write("                            </div>\n");
      out.write("                        </div>\n");
      out.write("                    </nav>\n");
      out.write("\n");
      out.write("                    <div class=\"absolute bottom-0 my-8\">\n");
      out.write("                        <a\n");
      out.write("                            class=\"flex items-center py-2 px-8 text-gray-100 hover:text-gray-200\"\n");
      out.write("                            href=\"#\"\n");
      out.write("                            >\n");
      out.write("                            <img\n");
      out.write("                                class=\"h-6 w-6 rounded-full mr-3 object-cover\"\n");
      out.write("                                src=\"https://lh3.googleusercontent.com/a-/AOh14Gi0DgItGDTATTFV6lPiVrqtja6RZ_qrY91zg42o-g\"\n");
      out.write("                                alt=\"avatar\"\n");
      out.write("                                />\n");
      out.write("                            <span>Khatabwedaa</span>\n");
      out.write("                        </a>\n");
      out.write("                    </div>\n");
      out.write("                </div>\n");
      out.write("            </div>\n");
      out.write("        </div>\n");
      out.write("\n");
      out.write("\n");
      out.write("        <!-- <div class=\"grid w-full min-h-screen place-items-center\"> -->\n");
      out.write("        \n");
      out.write("        <div class=\"overflow-x-auto bg-white w-5/6 h-screen mt-0 md:mt-0 md:col-span-2 view-routes\" id=\"admin-tab\">\n");
      out.write("            <form action=\"#\" method=\"POST\">\n");
      out.write("                <h3 class=\"block text-base text-center font-medium text-gray-700\"> Add Route</h3>\n");
      out.write("                <div class=\"flex flex-col items-center shadow overflow-hidden sm:rounded-md\">\n");
      out.write("                    <div class=\"px-4 py-5  sm:p-6\">\n");
      out.write("                        <div class=\"grid grid-cols-6 gap-6\">\n");
      out.write("                            <div class=\"col-span-6 sm:col-span-3\">\n");
      out.write("                                <label for=\"id\" class=\"block text-sm font-medium text-gray-700\">id</label>\n");
      out.write("                                <input type=\"number\" name=\"id\" id=\"id\" value=\"\" autocomplete=\"given-name\" class=\"mt-1 focus:ring-indigo-500 focus:border-indigo-500 block w-full shadow-sm sm:text-sm border-gray-300 rounded-md\">\n");
      out.write("                            </div>\n");
      out.write("\n");
      out.write("                            <div class=\"col-span-6 sm:col-span-3\">\n");
      out.write("                                <label for=\"id\" class=\"block text-sm font-medium text-gray-700\">source</label>\n");
      out.write("                                <input type=\"number\" name=\"source\" id=\"source\" value=\"\" class=\"mt-1 focus:ring-indigo-500 focus:border-indigo-500 block w-full shadow-sm sm:text-sm border-gray-300 rounded-md\">\n");
      out.write("                            </div>\n");
      out.write("                            \n");
      out.write("                            <div class=\"col-span-6 sm:col-span-3\">\n");
      out.write("                                <label for=\"id\" class=\"block text-sm font-medium text-gray-700\">destination</label>\n");
      out.write("                                <input type=\"number\" name=\"destination\" id=\"destination\" value=\"\" class=\"mt-1 focus:ring-indigo-500 focus:border-indigo-500 block w-full shadow-sm sm:text-sm border-gray-300 rounded-md\">\n");
      out.write("                            </div>\n");
      out.write("                        </div>\n");
      out.write("                    </div>\n");
      out.write("                    <div class=\"px-4 py-3 bg-gray-50 text-right sm:px-6\">\n");
      out.write("                        <button type=\"submit\" class=\"inline-flex justify-center py-2 px-4 border border-transparent shadow-sm text-sm font-medium rounded-md text-white bg-indigo-600 hover:bg-indigo-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-indigo-500\">\n");
      out.write("                            Save\n");
      out.write("                        </button>\n");
      out.write("                    </div>\n");
      out.write("                </div>\n");
      out.write("            </form>\n");
      out.write("        </div>\n");
      out.write("        \n");
      out.write("        <!-- </div> -->\n");
      out.write("        \n");
      out.write("    </body>\n");
      out.write("</html>\n");
      out.write("\n");
      out.write("\n");
    } catch (Throwable t) {
      if (!(t instanceof SkipPageException)){
        out = _jspx_out;
        if (out != null && out.getBufferSize() != 0)
          out.clearBuffer();
        if (_jspx_page_context != null) _jspx_page_context.handlePageException(t);
        else throw new ServletException(t);
      }
    } finally {
      _jspxFactory.releasePageContext(_jspx_page_context);
    }
  }
}
<file_sep>/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package model;

import java.util.Date;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.persistence.OneToOne;
import javax.persistence.SequenceGenerator;

/**
 *
 * @author Philip
 */
@Entity
@SequenceGenerator(name = "ticketseq", sequenceName = "ticket_seq", initialValue = 1, allocationSize = 1)
public class Ticket {
    @Id
    @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "ticketseq")
    private Long id;
    @OneToOne
    private Passenger passenger;
    @ManyToOne
    private Journey journey;
    private double amount;
    private Date BoughtOn;
    private TicketStatus ticketStatus;
    @ManyToOne
    private Company company;

    public Ticket() {
    }

    public Ticket(Long id, Passenger passenger, Journey journey, double amount, Date BoughtOn, TicketStatus ticketStatus, Company company) {
        this.id = id;
        this.passenger = passenger;
        this.journey = journey;
        this.amount = amount;
        this.BoughtOn = BoughtOn;
        this.ticketStatus = ticketStatus;
        this.company = company;
    }
    
    

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public Passenger getPassenger() {
        return passenger;
    }

    public void setPassenger(Passenger passenger) {
        this.passenger = passenger;
    }

    public Journey getJourney() {
        return journey;
    }

    public void setJourney(Journey journey) {
        this.journey = journey;
    }

    public double getAmount() {
        return amount;
    }

    public void setAmount(double amount) {
        this.amount = amount;
    }

    public Date getBoughtOn() {
        return BoughtOn;
    }

    public void setBoughtOn(Date BoughtOn) {
        this.BoughtOn = BoughtOn;
    }

    public TicketStatus getTicketStatus() {
        return ticketStatus;
    }

    public void setTicketStatus(TicketStatus ticketStatus) {
        this.ticketStatus = ticketStatus;
    }

    public Company getCompany() {
        return company;
    }

    public void setCompany(Company company) {
        this.company = company;
    }
    
    
}
<file_sep>libs.CopyLibs.classpath=\
    ${base}/CopyLibs/org-netbeans-modules-java-j2seproject-copylibstask.jar
libs.CopyLibs.displayName=CopyLibs Task
libs.CopyLibs.prop-version=2.0
libs.Hibernate_4.3.x.classpath=\
    ${base}/Hibernate_4.3.x/antlr-2.7.7.jar;\
    ${base}/Hibernate_4.3.x/c3p0-0.9.2.1.jar;\
    ${base}/Hibernate_4.3.x/commons-collections-3.2.1.jar;\
    ${base}/Hibernate_4.3.x/dom4j-1.6.1.jar;\
    ${base}/Hibernate_4.3.x/ehcache-core-2.4.3.jar;\
    ${base}/Hibernate_4.3.x/hibernate-c3p0-4.3.1.Final.jar;\
    ${base}/Hibernate_4.3.x/hibernate-commons-annotations-4.0.4.Final.jar;\
    ${base}/Hibernate_4.3.x/hibernate-core-4.3.1.Final.jar;\
    ${base}/Hibernate_4.3.x/hibernate-ehcache-4.3.1.Final.jar;\
    ${base}/Hibernate_4.3.x/hibernate-entitymanager-4.3.1.Final.jar;\
    ${base}/Hibernate_4.3.x/hibernate-jpa-2.1-api-1.0.0.Final.jar;\
    ${base}/Hibernate_4.3.x/javassist-3.18.1-GA.jar;\
    ${base}/Hibernate_4.3.x/jboss-logging-3.1.3.GA.jar;\
    ${base}/Hibernate_4.3.x/jboss-transaction-api_1.2_spec-1.0.0.Final.jar;\
    ${base}/Hibernate_4.3.x/mchange-commons-java-0.2.3.4.jar
libs.Hibernate_4.3.x.displayName=Hibernate 4.3.x
libs.javaee-endorsed-api-7.0.classpath=\
    ${base}/javaee-endorsed-api-7.0/javax.annotation-api.jar;\
    ${base}/javaee-endorsed-api-7.0/javax.xml.soap-api.jar;\
    ${base}/javaee-endorsed-api-7.0/jaxb-api-osgi.jar;\
    ${base}/javaee-endorsed-api-7.0/jaxws-api.jar;\
    ${base}/javaee-endorsed-api-7.0/jsr181-api.jar
libs.javaee-endorsed-api-7.0.displayName=Java EE 7 Endorsed API Library
libs.javaee-endorsed-api-7.0.javadoc=\
    ${base}/javaee-endorsed-api-7.0/javaee-doc-api.jar
libs.PostgreSQLDriver.classpath=\
    ${base}/PostgreSQLDriver/postgresql-9.4.1209.jar
libs.PostgreSQLDriver.displayName=PostgreSQL JDBC Driver
libs.PostgreSQLDriver.prop-maven-dependencies=org.postgresql:postgresql:9.4.1209:jar
libs.testng.classpath=\
    ${base}/testng/testng-6.8.1-dist.jar
libs.testng.displayName=TestNG 6.8.1
libs.testng.javadoc=\
    ${base}/testng/testng-6.8.1-javadoc.zip
libs.testng.prop-maven-dependencies=org.testng:testng:6.8.1:jar
<file_sep>/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package controller;

import dao.AccountDao;
import dao.GeneralDao;
import java.io.IOException;
import java.sql.Timestamp;
import java.text.SimpleDateFormat;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import model.AccountState;
import model.AccountStatus;
import model.AdminAccount;
import model.Company;
import model.CompanyState;
import model.CompanyStatus;
import model.Manager;
import model.ManagerAccount;
import model.Role;

/**
 *
 * @author Philip
 */
@WebServlet(name = "CompanyControl", urlPatterns = {"/CompanyControl"})
public class CompanyControl extends HttpServlet {

    GeneralDao<CompanyState> companyStateDao = new GeneralDao<>();
    GeneralDao<AccountState> AccountStateDao = new GeneralDao<>();
    RequestDispatcher dispatcher;

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        AccountDao<ManagerAccount> accountDao = new AccountDao<>(ManagerAccount.class);
        HttpSession session = request.getSession();
        String action = request.getParameter("action");
        GeneralDao<Company> companyDao = new GeneralDao<>();
        java.util.Date date = new java.util.Date();
        Timestamp ts = new Timestamp(date.getTime());
        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        AdminAccount adminAccount;
        CompanyState companyState;
        Company company;
        switch (action) {
            case "login":
                String email = request.getParameter("email");
                String password = request.getParameter("password");
                ManagerAccount account = accountDao.getAccount(email, password);
                if (account == null) {
                    request.setAttribute("message", "username or password is invalid!!");
                    dispatcher = request.getRequestDispatcher("login.jsp");
                    dispatcher.forward(request, response);
                } else if (account.getCompany().getCompanyStatus().toString().equals("CREATED")) {
                    request.setAttribute("message", "Company account has not been approved yet");
                    dispatcher = request.getRequestDispatcher("login.jsp");
                    dispatcher.forward(request, response);
                } else if (account.getCompany().getCompanyStatus().toString().equals("SUSPENDED")) {
                    request.setAttribute("message", "Company account has been suspended");
                    dispatcher = request.getRequestDispatcher("login.jsp");
                    dispatcher.forward(request, response);
                } else if (account.getAccountStatus().toString().equals("CREATED")) {
                    request.setAttribute("message", "your account has not been approved yet");
                    dispatcher = request.getRequestDispatcher("login.jsp");
                    dispatcher.forward(request, response);
                } else if (account.getAccountStatus().toString().equals("SUSPENDED")) {
                    request.setAttribute("message", "your account has been suspended");
                    dispatcher = request.getRequestDispatcher("login.jsp");
                    dispatcher.forward(request, response);
                } else {
                    session.setAttribute("user", account);
                    String location = (String) session.getAttribute("trigger");
                    session.removeAttribute("trigger");
                    if (location == null) {
                        response.sendRedirect("dashboard.jsp");
                    } else {
                        response.sendRedirect(location + ".jsp");
                    }
                }

                break;

            case "logout":
                
                if (session.getAttribute("user") == null) {
                    request.getSession().removeAttribute("admin");
                    response.sendRedirect("adminlogin.jsp");
                } else {
                    request.getSession().removeAttribute("user");
                    response.sendRedirect("login.jsp");
                }
                
                break;

            case "approve":

                adminAccount = (AdminAccount) session.getAttribute("user");
                companyState = new CompanyState();

                company = companyDao.findOne(Company.class, Long.parseLong(request.getParameter("id")));
                company.setCompanyStatus(CompanyStatus.APPROVED);
                companyDao.update(company);

                companyState.setCompany(company);
                companyState.setCompanyStatus(CompanyStatus.APPROVED);
                companyState.setDoneBy(adminAccount);

                companyState.setUpdateOn(Timestamp.valueOf(formatter.format(ts)));
                companyStateDao.create(companyState);

                request.setAttribute("message", "company is approved successfully");
                dispatcher = request.getRequestDispatcher("allcompanies.jsp");
                dispatcher.forward(request, response);
                break;

            case "suspend":
                adminAccount = (AdminAccount) session.getAttribute("user");
                companyState = new CompanyState();

                company = companyDao.findOne(Company.class, Long.parseLong(request.getParameter("id")));
                company.setCompanyStatus(CompanyStatus.SUSPENDED);
                companyDao.update(company);

                companyState.setCompany(company);
                companyState.setCompanyStatus(CompanyStatus.SUSPENDED);
                companyState.setDoneBy(adminAccount);
                companyState.setUpdateOn(Timestamp.valueOf(formatter.format(ts)));
                companyStateDao.create(companyState);

                request.setAttribute("message", "company is suspended successfully");
                dispatcher = request.getRequestDispatcher("allcompanies.jsp");
                dispatcher.forward(request, response);
                break;

            default:
                System.out.println("no action specified");
        }

    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        GeneralDao<Company> companyDao = new GeneralDao<>();
        GeneralDao<Manager> managerDao = new GeneralDao<>();
        GeneralDao<ManagerAccount> accountDao = new GeneralDao<>();
        AccountDao<AdminAccount> adminaccDao = new AccountDao<>(AdminAccount.class);
        AdminAccount account = adminaccDao.getAccount("<EMAIL>", "<PASSWORD>");
        SimpleDateFormat sdftime = new SimpleDateFormat("hh:mm");
        String action = request.getParameter("action");

        java.util.Date date = new java.util.Date();
        Timestamp ts = new Timestamp(date.getTime());
        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

        Company company;
        Manager manager;
        ManagerAccount managerAccount;
        AccountState accountState;
        switch (action) {
            case "addcompany":
                company = new Company();
                manager = new Manager();
                managerAccount = new ManagerAccount();
                CompanyState companyState = new CompanyState();

                manager.setFirstName(request.getParameter("firstName"));
                manager.setLastName(request.getParameter("lastName"));
                manager.setPhoneNumber(request.getParameter("phoneNumber"));

                managerDao.create(manager);

                company.setName(request.getParameter("companyName"));
                company.setCompanySize(request.getParameter("companySize"));
                company.setCompanyStatus(CompanyStatus.CREATED);

                company.setCreatedOn(Timestamp.valueOf(formatter.format(ts)));
                company.setManager(manager);
                companyDao.create(company);

                companyState.setCompany(company);
                companyState.setCompanyStatus(CompanyStatus.CREATED);
                companyState.setDoneBy(account);
                companyState.setUpdateOn(Timestamp.valueOf(formatter.format(ts)));
                companyStateDao.create(companyState);

                managerAccount.setManager(manager);
                managerAccount.setCompany(company);
                managerAccount.setAccountStatus(AccountStatus.APPROVED);
                managerAccount.setEmail(request.getParameter("email"));
                managerAccount.setPassword(request.getParameter("password"));
                managerAccount.setAccountRole(Role.COMPANY);

                accountDao.create(managerAccount);

                accountState = new AccountState();
                accountState.setAccountStatus(AccountStatus.CREATED);
                accountState.setDoneBy(manager);
                accountState.setManagerAccount(managerAccount);
                accountState.setUpdateOn(Timestamp.valueOf(formatter.format(ts)));

                AccountStateDao.create(accountState);

                response.sendRedirect("login.jsp");
                break;
            case "createaccount":
                company = ((ManagerAccount) request.getSession().getAttribute("user")).getCompany();

                manager = new Manager();
                managerAccount = new ManagerAccount();
                manager.setFirstName(request.getParameter("firstname"));
                manager.setLastName(request.getParameter("lastname"));
                manager.setPhoneNumber(request.getParameter("phonenumber"));

                managerDao.create(manager);

                managerAccount.setManager(manager);
                managerAccount.setCompany(company);
                managerAccount.setAccountStatus(AccountStatus.valueOf(request.getParameter("accountstatus")));
                managerAccount.setEmail(request.getParameter("email"));
                managerAccount.setPassword(request.getParameter("password"));
                managerAccount.setAccountRole(Role.COMPANY);
                accountDao.create(managerAccount);

                accountState = new AccountState();
                accountState.setAccountStatus(AccountStatus.CREATED);
                accountState.setDoneBy(manager);
                accountState.setManagerAccount(managerAccount);
                accountState.setUpdateOn(Timestamp.valueOf(formatter.format(ts)));

                AccountStateDao.create(accountState);
                response.sendRedirect("dashboard.jsp");
                break;

            default:
                System.out.println("no action specified");
        }

    }

}
<file_sep>deploy.ant.properties.file=C:\\Users\\Philip\\AppData\\Roaming\\NetBeans\\8.2\\tomcat90.properties
j2ee.server.home=D:/Exe/apache-tomcat-9.0.30
j2ee.server.instance=tomcat90:home=D:\\Exe\\apache-tomcat-9.0.30
selected.browser=Chrome
user.properties.file=C:\\Users\\Philip\\AppData\\Roaming\\NetBeans\\8.2\\build.properties
<file_sep>/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package testing;

import com.ninja_squad.dbsetup.Operations;
import com.ninja_squad.dbsetup.operation.Operation;
import java.sql.Timestamp;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 *
 * @author Philip
 */
public class TestData {

    static java.sql.Date sqlDate;
    static java.sql.Timestamp sqlTime;
    java.sql.Timestamp now;
    
    public TestData() {
        java.util.Date date = new java.util.Date();
        sqlDate = new java.sql.Date(date.getTime());
        sqlTime = new java.sql.Timestamp(date.getTime());
    }

    static java.util.Date date = new java.util.Date();
    static Timestamp ts = new Timestamp(date.getTime());
    static SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

    public static Operation INSERT_ADMIN_ACCOUNT
            = Operations.insertInto("adminaccount")
                    .columns("id", "account_role", "accountstatus", "email", "password")
                    .values(1, "SUPER_ADMIN", "APPROVED", "<EMAIL>", "<PASSWORD>")
                    .build();

    public static Operation INSERT_MANAGER
            = Operations.insertInto("manager")
                    .columns("id", "firstname", "lastname", "phonenumber    ")
                    .values(1, "karenzi", "jack", "07888868768")
                    .values(2, "isimbi", "sonia", "0676768")
                    .build();

    public static Operation INSERT_COMPANY
            = Operations.insertInto("company")
                    .columns("id", "companysize", "companystatus", "createdon", "name", "manager_id")
                    .values(1, "11-50", "CREATED", new Date(), "sample", 1)
                    .values(2, "11-50", "CREATED", new Date(), "anothersample", 2)
                    .build();

    public static Operation INSERT_MANAGER_ACCOUNT
            = Operations.insertInto("manageraccount")
                    .columns("id", "account_role", "accountstatus", "email", "password", "company_id", "manager_id")
                    .values(1, "COMPANY", "CREATED", "<EMAIL>", "123456789", 1, 1)
                    .values(2, "COMPANY", "CREATED", "<EMAIL>", "murenzi123", 2, 2)
                    .build();

    public static Operation INSERT_COMPANY_STATE
            = Operations.insertInto("companystate")
                    .columns("id", "companystatus", "updateon", "company_id", "doneby_id")
                    .values(1, "CREATED", new Date(), 1, 1)
                    .values(2, "CREATED", new Date(), 2, 1)
                    .build();

    public static Operation INSERT_ACCOUNT_STATE
            = Operations.insertInto("accountstate")
                    .columns("id", "accountstatus", "updateon", "doneby_id", "manageraccount_id")
                    .values(1, "CREATED", Timestamp.valueOf(formatter.format(ts)), 1, 1)
                    .build();

    public static Operation INSERT_ROUTE
            = Operations.insertInto("route")
                    .columns("id", "destination", "source", "status")
                    .values(100, "kigali", "rwamagana", "ACTIVE")
                    .values(200, "kigali", "huye", "ACTIVE")
                    .values(300, "kigali", "kayonza", "ACTIVE")
                    .build();
    public static Operation INSERT_COMPANY_ROUTE
            = Operations.insertInto("companyroute")
                    .columns("company_route_id", "registered_date", "routestatus", "company_id", "route_id")
                    .values(1, new Date(), "APPROVED", 1, 100)
                    .values(2, new Date(), "APPROVED", 1, 200)
                    .build();

    public static Operation INSERT_JOURNEY
            = Operations.insertInto("journey")
                    .columns("id", "createdat", "departuredate", "departuretime", "journeystatus", "plateno", "price", "seats", "taken", "version", "company_id", "route_id")
                    .values(1, Timestamp.valueOf(formatter.format(ts)),sqlDate , sqlTime, "BOOKING", "RAB 312 C", 3000, 40, 0, 1, 1, 100)
                    .values(2, Timestamp.valueOf(formatter.format(ts)),sqlDate , sqlTime, "BOOKING", "RAB 219 C", 2000, 40, 0, 1, 1, 200)
                    .build();
    
    public static Operation INSERT_PASSENGER
            = Operations.insertInto("passenger")
                    .columns("id", "firstname", "lastname", "phonenumber")
                    .values(100, "mihigo", "yves", "07877689")
                    .values(200, "shyaka", "patrick", "07897089")
                    .values(300, "iradukunda", "alvaro", "088799")
                    .build();
    
    public static Operation INSERT_TICKET
            = Operations.insertInto("ticket")
                    .columns("id", "boughton", "amount", "ticketstatus", "company_id", "journey_id", "passenger_id")
                    .values(1, Timestamp.valueOf(formatter.format(ts)), 3000, 1, 1, 1, 100)
                    .values(2, Timestamp.valueOf(formatter.format(ts)), 2000, 1, 1, 2, 200)
                    .build();

    public static Operation DELETE_ADMIN_ACCOUNT
            = Operations.deleteAllFrom("adminaccount");

    public static Operation DELETE_MANAGER
            = Operations.deleteAllFrom("manager");

    public static Operation DELETE_COMPANY
            = Operations.deleteAllFrom("company");
    
    public static Operation DELETE_MANAGER_ACCOUNT
            = Operations.deleteAllFrom("manageraccount");
    
    public static Operation DELETE_COMPANY_STATE
            = Operations.deleteAllFrom("companystate");
    
    public static Operation DELETE_ACCOUNT_STATE
            = Operations.deleteAllFrom("accountstate");
    
    public static Operation DELETE_ROUTE
            = Operations.deleteAllFrom("route");
    
    public static Operation DELETE_COMPANY_ROUTE
            = Operations.deleteAllFrom("companyroute");
    
    public static Operation DELETE_JOURNEY
            = Operations.deleteAllFrom("journey");
    
    public static Operation DELETE_PASSENGER
            = Operations.deleteAllFrom("passenger");
    
    public static Operation DELETE_TICKET
            = Operations.deleteAllFrom("ticket");
    
    
}
