/*
 * 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 com.arrebol.taxiservicios.controller.admin;

import com.arrebol.taxiservicios.controller.util.HibernateUtil;
import com.arrebol.taxiservicios.model.admin.Contract;
import com.arrebol.taxiservicios.model.admin.ContractHasService;
import com.arrebol.taxiservicios.model.admin.ContractHasServiceId;
import com.arrebol.taxiservicios.model.admin.Service;
import com.arrebol.taxiservicios.model.admin.Taxi;
import com.arrebol.taxiservicios.model.catalog.Color;
import com.arrebol.taxiservicios.model.catalog.Location;
import com.arrebol.taxiservicios.model.catalog.Vehicle;
import com.arrebol.taxiservicios.model.core.Person;
import com.arrebol.taxiservicios.model.core.User;
import com.arrebol.taxiservicios.model.enums.BasicType;
import com.arrebol.taxiservicios.model.enums.PersonType;
import com.arrebol.taxiservicios.model.enums.PlatformType;
import com.arrebol.taxiservicios.model.view.dashboard.MaintenanceView;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Set;
import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaDelete;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.CriteriaUpdate;
import javax.persistence.criteria.Path;
import javax.persistence.criteria.Predicate;
import javax.persistence.criteria.Root;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.hibernate.Transaction;
import org.hibernate.query.Query;

/**
 *
 * @author oscarvargas
 */
public class TaxiController extends GenericPersonController implements Serializable {

    public List<Taxi> findAllTaxisByCustomer(String customerId) {
        logger.info("findAllTaxisByCustomer");

        Transaction transaction = null;
        List<Taxi> result = null;

        try {
            logger.info("Searching all taxis by customer..");
            Session session = HibernateUtil.getSessionFactory().getCurrentSession();
            transaction = session.beginTransaction();
            String hql = "SELECT taxi FROM Taxi taxi where taxi.active = 1 AND taxi.apc = 'DISABLED' AND taxi.customer.id = '" + customerId + "'";
            Query query = session.createQuery(hql, Taxi.class);

            result = query.getResultList();
            transaction.commit();
            logger.info("Total of avalilables taxis found : " + (null == result ? -1 : result.size()));
        } catch (HibernateException e) {
            rollback(transaction);
            logger.error("Can not load list of find All Taxis by customer ", e);
        } catch (Exception e) {
            rollback(transaction);
            logger.error("Method findAllTaxisByCustomer", e);
        }

        return result;
    }

    /**
     *
     * Searching all taxis for list.
     *
     * @return
     */
    public List<Taxi> fillTaxiDatatable() {

        Transaction transaction = null;
        List<Taxi> result = null;

        try {
            logger.info("Searching all taxis..");
            Session session = HibernateUtil.getSessionFactory().getCurrentSession();
            transaction = session.beginTransaction();
            CriteriaBuilder builder = session.getCriteriaBuilder();

            CriteriaQuery<Taxi> criteria = builder.createQuery(Taxi.class);
            Root<Taxi> root = criteria.from(Taxi.class);

            Path<String> idPath = root.get("id");
            Path<String> economicNumberPath = root.get("economicNumber");
            Path<String> driverPath = root.get("driver");
            Path<String> customerPath = root.get("customer");
            Path<String> vehiclePath = root.get("vehicle");

            criteria.select(
                    builder.construct(Taxi.class, idPath, economicNumberPath, driverPath, customerPath, vehiclePath
                    ));

            criteria.where(builder.equal(root.get("active"), Boolean.TRUE));
            result = session.createQuery(criteria).getResultList();

            transaction.commit();
            logger.info("Total of taxis found : " + (null == result ? -1 : result.size()));
        } catch (HibernateException e) {
            rollback(transaction);
            logger.error("Can not load list of taxis ", e);
        } catch (Exception e) {
            rollback(transaction);
            logger.error("Method fillTaxiDatatable of Taxi", e);
        }

        return result;
    }

    public List<Taxi> fillTaxiDatatable2() {

        Transaction transaction = null;
        List<Taxi> result = null;

        try {
            logger.info("Searching all taxis..");
            Session session = HibernateUtil.getSessionFactory().getCurrentSession();
            transaction = session.beginTransaction();
            CriteriaBuilder builder = session.getCriteriaBuilder();

            CriteriaQuery<Taxi> criteria = builder.createQuery(Taxi.class);
            Root<Taxi> root = criteria.from(Taxi.class);

            Path<String> idPath = root.get("id");
            Path<String> economicNumberPath = root.get("economicNumber");
            Path<String> driverPath = root.get("driver");
            Path<String> customerPath = root.get("customer");
            Path<String> vehiclePath = root.get("vehicle");
            Path<String> year = root.get("year");
            Path<String> color = root.get("color");

            criteria.select(builder.construct(Taxi.class, idPath, economicNumberPath, driverPath, customerPath, vehiclePath, year, color));

            criteria.where(builder.equal(root.get("active"), Boolean.TRUE));
            result = session.createQuery(criteria).getResultList();

            transaction.commit();
            logger.info("Total of taxis found : " + (null == result ? -1 : result.size()));
        } catch (HibernateException e) {
            rollback(transaction);
            logger.error("Can not load list of taxis ", e);
        } catch (Exception e) {
            rollback(transaction);
            logger.error("Method fillTaxiDatatable of Taxi", e);
        }

        return result;
    }

    /**
     *
     * @return
     */
    public List<Taxi> findAllTaxisAvailables() {
        logger.info("findAllTaxisAvailables");

        Transaction transaction = null;
        List<Taxi> result = null;

        try {
            logger.info("Searching all taxis..");
            Session session = HibernateUtil.getSessionFactory().getCurrentSession();
            transaction = session.beginTransaction();
            String hql = "SELECT taxi FROM Taxi taxi WHERE taxi.active = :active";
            Query query = session.createQuery(hql, Taxi.class);

            query.setParameter("active", true);

            result = query.getResultList();
            transaction.commit();
            logger.info("Total of avalilables taxis found : " + (null == result ? -1 : result.size()));
        } catch (HibernateException e) {
            rollback(transaction);
            logger.error("Can not load list of find All Taxis Availables ", e);
        } catch (Exception e) {
            rollback(transaction);
            logger.error("Method findAllTaxisAvailables", e);
        }

        return result;
    }

    public List<Taxi> findAllTaxis(String locationId) {
        logger.info("findAllTaxisAvailables");

        Transaction transaction = null;
        List<Taxi> result = null;

        try {
            logger.info("Searching all taxis..");
            Session session = HibernateUtil.getSessionFactory().getCurrentSession();
            transaction = session.beginTransaction();
            String hql = "SELECT taxi FROM Taxi taxi where taxi.active = 1 AND taxi.apc = 'DISABLED' AND taxi.location.id = '" + locationId + "'";
            Query query = session.createQuery(hql, Taxi.class);

            result = query.getResultList();
            transaction.commit();
            logger.info("Total of avalilables taxis found : " + (null == result ? -1 : result.size()));
        } catch (HibernateException e) {
            rollback(transaction);
            logger.error("Can not load list of find All Taxis Availables ", e);
        } catch (Exception e) {
            rollback(transaction);
            logger.error("Method findAllTaxisAvailables", e);
        }

        return result;
    }

    public List<Taxi> findAllTaxisByLocation(Location location) {
        logger.info("findAllTaxisByLocation");
        List<Taxi> results = new ArrayList<>();
        Transaction transaction = null;
        try {
            Session session = HibernateUtil.getSessionFactory().getCurrentSession();
            transaction = session.beginTransaction();
            CriteriaBuilder builder = session.getCriteriaBuilder();

            CriteriaQuery<Taxi> query = builder.createQuery(Taxi.class);
            Root<Taxi> root = query.from(Taxi.class);

            Predicate predicate = builder.equal(root.get("location"), location);
            Predicate predicate1 = builder.equal(root.get("active"), Boolean.TRUE);
            Predicate predicate2 = builder.equal(root.get("customer").get("active"), Boolean.TRUE);
            query.where(builder.and(predicate, predicate1, predicate2));
            query.orderBy(builder.asc(root.get("createdOn")));

            results = session.createQuery(query).getResultList();
            transaction.commit();
            logger.info("Taxi list " + results.size());
        } catch (HibernateException e) {
            logger.error("Can not load taxi list ", e);
            rollback(transaction);
        } catch (Exception e) {
            logger.error("Method findAllTaxisByLocation() ", e);
            rollback(transaction);
        }
        return results;
    }

    public List<Taxi> findAllTaxisBanca(String locationId) {
        logger.info("findAllTaxisBanca");

        Transaction transaction = null;
        List<Taxi> result = null;

        try {
            logger.info("Searching all taxis..");
            Session session = HibernateUtil.getSessionFactory().getCurrentSession();
            transaction = session.beginTransaction();
            String hql = "SELECT taxi FROM Taxi taxi where taxi.driver is null AND taxi.apc = 'DISABLED' AND taxi.location.id = '" + locationId + "' AND taxi.active = 1 AND (SELECT COUNT(so.id) FROM ServiceOrder so WHERE so.serviceOrderType IN ('PENDING','APPROVED','PROGRESS',"
                    + "'PASE_TALLER') AND so.taxi.id = taxi.id) = 0";
            Query query = session.createQuery(hql, Taxi.class);

            result = query.getResultList();
            transaction.commit();
            logger.info("Total of banca taxis found : " + (null == result ? -1 : result.size()));
        } catch (HibernateException e) {
            rollback(transaction);
            logger.error("Can not load list of find All Taxis banca ", e);
        } catch (Exception e) {
            rollback(transaction);
            logger.error("Method findAllTaxisBanca", e);
        }

        return result;
    }

    public List<Taxi> findAllTaxisActivos(String locationId) {
        logger.info("findAllTaxisBanca");

        Transaction transaction = null;
        List<Taxi> result = null;

        try {
            logger.info("Searching all taxis..");
            Session session = HibernateUtil.getSessionFactory().getCurrentSession();
            transaction = session.beginTransaction();
            String hql = "SELECT taxi FROM Taxi taxi where taxi.driver is not null and taxi.apc = 'DISABLED' and taxi.active = 1 AND taxi.location.id = '" + locationId + "'";
            Query query = session.createQuery(hql, Taxi.class);

            result = query.getResultList();
            transaction.commit();
            logger.info("Total of banca taxis found : " + (null == result ? -1 : result.size()));
        } catch (HibernateException e) {
            rollback(transaction);
            logger.error("Can not load list of find All Taxis banca ", e);
        } catch (Exception e) {
            rollback(transaction);
            logger.error("Method findAllTaxisBanca", e);
        }

        return result;
    }

    public List<Taxi> findAllTaxisTaller(String locationId) {
        logger.info("findAllTaxisBanca");

        Transaction transaction = null;
        List<Taxi> result = null;

        try {
            logger.info("Searching all taxis..");
            Session session = HibernateUtil.getSessionFactory().getCurrentSession();
            transaction = session.beginTransaction();
            String hql = "SELECT taxi FROM Taxi taxi where (SELECT COUNT(so.id) FROM ServiceOrder so WHERE so.serviceOrderType IN ('PENDING','APPROVED','PROGRESS',"
                    + "'PASE_TALLER') AND so.taxi.id = taxi.id AND tallerExterno = 'DISABLED') > 0 AND taxi.apc = 'DISABLED' AND taxi.location.id = '" + locationId + "'";
            Query query = session.createQuery(hql, Taxi.class);

            result = query.getResultList();
            transaction.commit();
            logger.info("Total of banca taxis found : " + (null == result ? -1 : result.size()));
        } catch (HibernateException e) {
            rollback(transaction);
            logger.error("Can not load list of find All Taxis banca ", e);
        } catch (Exception e) {
            rollback(transaction);
            logger.error("Method findAllTaxisBanca", e);
        }

        return result;
    }

    public List<Taxi> findAllTaxisTallerExterno(String locationId) {
        logger.info("findAllTaxisBanca");

        Transaction transaction = null;
        List<Taxi> result = null;

        try {
            logger.info("Searching all taxis..");
            Session session = HibernateUtil.getSessionFactory().getCurrentSession();
            transaction = session.beginTransaction();
            String hql = "SELECT taxi FROM Taxi taxi where (SELECT COUNT(so.id) FROM ServiceOrder so WHERE so.serviceOrderType IN ('PENDING','APPROVED','PROGRESS',"
                    + "'PASE_TALLER') AND so.taxi.id = taxi.id AND tallerExterno = 'ENEBLED') > 0 AND taxi.apc = 'DISABLED' AND taxi.location.id = '" + locationId + "'";
            Query query = session.createQuery(hql, Taxi.class);

            result = query.getResultList();
            transaction.commit();
            logger.info("Total of banca taxis found : " + (null == result ? -1 : result.size()));
        } catch (HibernateException e) {
            rollback(transaction);
            logger.error("Can not load list of find All Taxis banca ", e);
        } catch (Exception e) {
            rollback(transaction);
            logger.error("Method findAllTaxisBanca", e);
        }

        return result;
    }

    public List<Taxi> findAllTaxisApc(String locationId) {
        logger.info("findAllTaxisApc");

        Transaction transaction = null;
        List<Taxi> result = null;

        try {
            logger.info("Searching all taxis..");
            Session session = HibernateUtil.getSessionFactory().getCurrentSession();
            transaction = session.beginTransaction();
            String hql = "SELECT taxi FROM Taxi taxi where (SELECT COUNT(so.id) FROM ServiceOrder so WHERE so.serviceOrderType IN ('PENDING','APPROVED','PROGRESS',"
                    + "'PASE_TALLER') AND so.taxi.id = taxi.id) = 0 AND taxi.apc = 'ENEBLED' AND taxi.location.id = '" + locationId + "'";
            Query query = session.createQuery(hql, Taxi.class);

            result = query.getResultList();
            transaction.commit();
            logger.info("Total of apc taxis found : " + (null == result ? -1 : result.size()));
        } catch (HibernateException e) {
            rollback(transaction);
            logger.error("Can not load list of find All Taxis apc ", e);
        } catch (Exception e) {
            rollback(transaction);
            logger.error("Method findAllTaxisApc", e);
        }

        return result;
    }

    public List<Taxi> findAllTaxisSinContrato(String locationId) {
        logger.info("findAllTaxisSinContrato");

        Transaction transaction = null;
        List<Taxi> result = null;

        try {
            logger.info("Searching all taxis..");
            Session session = HibernateUtil.getSessionFactory().getCurrentSession();
            transaction = session.beginTransaction();
            String hql = "SELECT taxi FROM Taxi taxi where taxi.active = 0 AND taxi.apc = 'DISABLED' AND taxi.location.id = '" + locationId + "'";
            Query query = session.createQuery(hql, Taxi.class);

            result = query.getResultList();
            transaction.commit();
            logger.info("Total of sin contrato taxis found : " + (null == result ? -1 : result.size()));
        } catch (HibernateException e) {
            rollback(transaction);
            logger.error("Can not load list of find All Taxis Sin contrato ", e);
        } catch (Exception e) {
            rollback(transaction);
            logger.error("Method findAllTaxisSinContrato", e);
        }

        return result;
    }

    /**
     *
     * @return
     */
    public List<MaintenanceView> findAllTaxisAvailablesMaintenance() {
        logger.info("findAllTaxisAvailablesMaintenance");

        Transaction transaction = null;
        List<MaintenanceView> result = null;

        try {
            Session session = HibernateUtil.getSessionFactory().getCurrentSession();

            transaction = session.beginTransaction();
            result = session.createQuery("FROM MaintenanceView", MaintenanceView.class).getResultList();

            transaction.commit();

            logger.info("Total of avalilables taxis found : " + (null == result ? -1 : result.size()));
        } catch (HibernateException e) {
            rollback(transaction);
            logger.error("Can not load list of find All Taxis Availables ", e);
        } catch (Exception e) {
            rollback(transaction);
            logger.error("Method findAllTaxisAvailablesMaintenance", e);
        }

        return result;
    }

    /**
     * Do a logical delete from an taxi in the system
     *
     * @param taxiId
     * @param userName
     * @return True if taxi was logical deleted otherwise false.
     */
    public boolean deleteTaxiById(String taxiId, String userName) {
        logger.info("deletePersonById");

        boolean success = false;
        Transaction transaction = null;
        try {
            Session session = HibernateUtil.getSessionFactory().getCurrentSession();
            transaction = session.beginTransaction();

            CriteriaBuilder builder = session.getCriteriaBuilder();

            CriteriaUpdate<Taxi> update = builder.createCriteriaUpdate(Taxi.class);
            Root<Taxi> rootUpdate = update.from(Taxi.class);

            update.set("driver", null);
            update.set("active", false);
            update.set("lastUpdatedBy", new User(userName, ""));
            update.set("lastUpdatedOn", new Date());
            update.where(builder.equal(rootUpdate.get("id"), taxiId));

            int total = session.createQuery(update).executeUpdate();

            if (1 == total) {
                transaction.commit();
                success = true;
                logger.info("Taxi " + taxiId + " deleted");
            } else {
                transaction.rollback();
                logger.error("Error Taxi deleted total: " + total);
            }
        } catch (HibernateException e) {
            logger.error("Taxi can not be deleted ", e);
            rollback(transaction);
        } catch (Exception e) {
            logger.error("Method deleteTaxiById() ", e);
            rollback(transaction);
        }
        return success;
    }

    public boolean deleteTaxiById(String taxiId, String userName, String comments) {
        logger.info("deletePersonById");

        boolean success = false;
        Transaction transaction = null;
        try {
            Session session = HibernateUtil.getSessionFactory().getCurrentSession();
            transaction = session.beginTransaction();

            CriteriaBuilder builder = session.getCriteriaBuilder();

            CriteriaUpdate<Taxi> update = builder.createCriteriaUpdate(Taxi.class);
            Root<Taxi> rootUpdate = update.from(Taxi.class);

            update.set("driver", null);
            update.set("active", false);
            update.set("lastUpdatedBy", new User(userName, ""));
            update.set("lastUpdatedOn", new Date());
            update.set("deletedOn", new Date());
            update.set("commentsDeleted", comments);
            update.where(builder.equal(rootUpdate.get("id"), taxiId));

            int total = session.createQuery(update).executeUpdate();

            if (1 == total) {
                transaction.commit();
                success = true;
                logger.info("Taxi " + taxiId + " deleted");
            } else {
                transaction.rollback();
                logger.error("Error Taxi deleted total: " + total);
            }
        } catch (HibernateException e) {
            logger.error("Taxi can not be deleted ", e);
            rollback(transaction);
        } catch (Exception e) {
            logger.error("Method deleteTaxiById() ", e);
            rollback(transaction);
        }
        return success;
    }

    public boolean activeTaxiById(String taxiId, String userName) {
        logger.info("activeTaxiById");

        boolean success = false;
        Transaction transaction = null;
        try {
            Session session = HibernateUtil.getSessionFactory().getCurrentSession();
            transaction = session.beginTransaction();

            CriteriaBuilder builder = session.getCriteriaBuilder();

            CriteriaUpdate<Taxi> update = builder.createCriteriaUpdate(Taxi.class);
            Root<Taxi> rootUpdate = update.from(Taxi.class);

            update.set("active", true);
            update.set("lastUpdatedBy", new User(userName, ""));
            update.set("lastUpdatedOn", new Date());
            update.where(builder.equal(rootUpdate.get("id"), taxiId));

            int total = session.createQuery(update).executeUpdate();

            if (1 == total) {
                transaction.commit();
                success = true;
                logger.info("Taxi " + taxiId + " active");
            } else {
                transaction.rollback();
                logger.error("Error Taxi acrtive total: " + total);
            }
        } catch (HibernateException e) {
            logger.error("Taxi can not be active ", e);
            rollback(transaction);
        } catch (Exception e) {
            logger.error("Method activeTaxiById() ", e);
            rollback(transaction);
        }
        return success;
    }

    /**
     * Save/Update an taxi in the system.
     *
     * @param taxi Taxi to be saved
     * @param userId User to load and use to set createBy/updateBy user in the
     * record.
     * @param save true save otherwise update.
     * @param vehicleId
     * @param driverId
     * @param customerId
     * @param colorId
     *
     * @return True if taxi was saved/updated otherwise false.
     */
    public boolean addTaxi(Taxi taxi, String userId, boolean save, String vehicleId, String driverId, String customerId, String colorId) {
        logger.info("addTaxi");

        boolean success = false;
        Transaction transaction = null;

        try {
            taxi.setColor(new Color(colorId));
            taxi.setCustomer(new Person(customerId));
            taxi.setVehicle(new Vehicle(vehicleId));

            User user = new User(userId, "");
            Person driver = null;

            if (null != driverId && !"".equals(driverId)) {
                driver = new Person(driverId);
                taxi.setDriver(driver);
            } else {
                taxi.setDriver(driver);
            }

            Session session = HibernateUtil.getSessionFactory().getCurrentSession();
            transaction = session.beginTransaction();

            if (save) {
                taxi.setCreatedBy(user);

                session.save(taxi);
                transaction.commit();

                logger.info("Taxi saved " + taxi.getId());
            } else {
                taxi.setLastUpdatedBy(user);

                session.update(taxi);
                transaction.commit();
                logger.info("Taxi updated " + taxi.getId());
            }

            success = true;
        } catch (HibernateException e) {
            logger.error("Taxi can not be added ", e);
            rollback(transaction);
        } catch (Exception e) {
            logger.error("Method addTaxi() ", e);
            rollback(transaction);
        }
        return success;
    }

    /**
     *
     * @return
     */
    public List<Vehicle> fillVehicleComboBox() {

        Transaction transaction = null;
        List<Vehicle> result = null;

        try {
            logger.info("Searching all vehicles to select..");
            Session session = HibernateUtil.getSessionFactory().getCurrentSession();
            transaction = session.beginTransaction();
            CriteriaBuilder builder = session.getCriteriaBuilder();

            CriteriaQuery<Vehicle> criteria = builder.createQuery(Vehicle.class);
            Root<Vehicle> root = criteria.from(Vehicle.class);

            Path<String> idPath = root.get("id");
            Path<String> namePath = root.get("name");

            criteria.select(
                    builder.construct(Vehicle.class, idPath, namePath
                    ));

            result = session.createQuery(criteria).getResultList();

            transaction.commit();
            logger.info("Total of vehicles found for ComboBox: " + (null == result ? -1 : result.size()));
        } catch (HibernateException e) {
            rollback(transaction);
            logger.error("Can not load list of vehicles for ComboBox ", e);
        } catch (Exception e) {
            rollback(transaction);
            logger.error("Method fillVehicleComboBox of Taxi", e);
        }

        return result;
    }

    public List<Vehicle> findAllVehicles() {
        logger.info("findAllVehicles");
        List<Vehicle> results = new ArrayList<>();
        Transaction transaction = null;
        try {
            Session session = HibernateUtil.getSessionFactory().getCurrentSession();
            transaction = session.beginTransaction();
            CriteriaBuilder builder = session.getCriteriaBuilder();
            CriteriaQuery<Vehicle> query = builder.createQuery(Vehicle.class);
            Root<Vehicle> root = query.from(Vehicle.class);

            query.orderBy(builder.asc(root.get("createdOn")));

            results = session.createQuery(query).getResultList();
            transaction.commit();
            logger.info("TipoPoliza's list " + results.size());
        } catch (HibernateException e) {
            logger.error("Can not load vehicles list ", e);
            rollback(transaction);
        } catch (Exception e) {
            logger.error("Method findAllVehicles() ", e);
            rollback(transaction);
        }
        return results;
    }

    /**
     *
     * @return
     */
    public List<Person> fillDriversComboBox() {

        Transaction transaction = null;
        List<Person> result = null;

        try {
            logger.info("Searching all drivers to select..");
            Session session = HibernateUtil.getSessionFactory().getCurrentSession();
            transaction = session.beginTransaction();
            CriteriaBuilder builder = session.getCriteriaBuilder();

            CriteriaQuery<Person> criteria = builder.createQuery(Person.class);
            Root<Person> root = criteria.from(Person.class);

            Path<String> idPath = root.get("id");
            Path<String> firstNamePath = root.get("firstName");
            Path<String> secondNamePath = root.get("secondName");
            Path<String> lastNamePath = root.get("lastName");
            Path<String> middleNamePath = root.get("middleName");

            criteria.select(
                    builder.construct(Person.class, idPath, firstNamePath, secondNamePath, lastNamePath, middleNamePath
                    ));

            criteria.where(builder.equal(root.get("personType"), PersonType.DRIVER),
                    builder.and(
                            builder.equal(root.get("active"), Boolean.TRUE)
                    ));

            result = session.createQuery(criteria).getResultList();

            transaction.commit();
            logger.info("Total of drivers found for ComboBox: " + (null == result ? -1 : result.size()));
        } catch (HibernateException e) {
            rollback(transaction);
            logger.error("Can not load list of drivers for ComboBox ", e);
        } catch (Exception e) {
            rollback(transaction);
            logger.error("Method fillDriversComboBox of Taxi", e);
        }

        return result;
    }

    /**
     *
     * @return
     */
    public List<Person> findAllActiveDriversWithoutTaxi() {

        Transaction transaction = null;
        List<Person> result = null;

        try {
            logger.info("Searching all drivers to select..");
            Session session = HibernateUtil.getSessionFactory().getCurrentSession();
            transaction = session.beginTransaction();

            String hql = "SELECT person FROM Person person "
                    + "LEFT JOIN Taxi taxi ON person.id = taxi.driver "
                    + "WHERE "
                    + "     taxi.driver IS NULL "
                    + "     AND person.personType = :personType "
                    + "     AND person.active = :active";

            Query query = session.createQuery(hql, Person.class);

            query.setParameter("personType", PersonType.DRIVER);
            query.setParameter("active", true);

            result = query.getResultList();

            transaction.commit();
            logger.info("Total of find All Active Drivers Without found for ComboBox: " + (null == result ? -1 : result.size()));
        } catch (HibernateException e) {
            rollback(transaction);
            logger.error("Can not load list of find All Active Drivers Without Taxi ComboBox ", e);
        } catch (Exception e) {
            rollback(transaction);
            logger.error("Method findAllActiveDriversWithoutTaxi of Taxi", e);
        }

        return result;
    }

    public List<Person> findAllActiveAndBancaDriversWithoutTaxi(String idLocation) {

        Transaction transaction = null;
        List<Person> result = null;

        try {
            logger.info("Searching all drivers to select..");
            Session session = HibernateUtil.getSessionFactory().getCurrentSession();
            transaction = session.beginTransaction();

            String hql = "SELECT person FROM Person person "
                    + "LEFT JOIN Taxi taxi ON person.id = taxi.driver "
                    + "WHERE "
                    + "     taxi.driver IS NULL "
                    + "     AND person.personType = :personType AND (person.blackList IS NULL OR person.blackList = 'DISABLED') AND person.location.id = :idLocation";

            Query query = session.createQuery(hql, Person.class);

            query.setParameter("personType", PersonType.DRIVER);
            query.setParameter("idLocation", idLocation);
            result = query.getResultList();

            transaction.commit();
            logger.info("Total of find All Active Drivers Without found for ComboBox: " + (null == result ? -1 : result.size()));
        } catch (HibernateException e) {
            rollback(transaction);
            logger.error("Can not load list of find All Active Drivers Without Taxi ComboBox ", e);
        } catch (Exception e) {
            rollback(transaction);
            logger.error("Method findAllActiveDriversWithoutTaxi of Taxi", e);
        }

        return result;
    }

    public List<Service> findAllActiveService(String idTaxi) {

        Transaction transaction = null;
        List<Service> result = null;

        try {
            logger.info("Searching all services to select..");
            Session session = HibernateUtil.getSessionFactory().getCurrentSession();
            transaction = session.beginTransaction();

            String hql = "select srvc "
                    + "from Contract cntrct inner join ContractHasService chs on cntrct = chs.contract "
                    + "inner join Service srvc on chs.service = srvc "
                    + "where cntrct.taxi.id = :idTaxi and cntrct.active = 1";

            Query query = session.createQuery(hql, Service.class);

            query.setParameter("idTaxi", idTaxi);
            result = query.getResultList();

            transaction.commit();
            logger.info("Total of find All Service: " + (null == result ? -1 : result.size()));
        } catch (HibernateException e) {
            rollback(transaction);
            logger.error("Can not load list of find All Active Service", e);
        } catch (Exception e) {
            rollback(transaction);
            logger.error("Method findAllActiveService of Taxi", e);
        }

        return result;
    }

    public Taxi getTaxiByIdInvoice(String taxiId) {

        Transaction transaction = null;
        Taxi result = null;

        try {
            logger.info("Searching taxi by id..");
            Session session = HibernateUtil.getSessionFactory().getCurrentSession();
            transaction = session.beginTransaction();
            CriteriaBuilder builder = session.getCriteriaBuilder();

            CriteriaQuery<Taxi> criteria = builder.createQuery(Taxi.class);
            Root<Taxi> root = criteria.from(Taxi.class);

            Path<String> idPath = root.get("id");
            Path<String> economicNumberPath = root.get("economicNumber");
            Path<String> customerPath = root.get("customer");
            Path<String> vehiclePath = root.get("vehicle");
            Path<String> colorPath = root.get("color");
            Path<String> placaPath = root.get("placa");
            Path<String> serialNumberPath = root.get("serialNumber");
            Path<String> motorNmumberPath = root.get("motorNmumber");
            Path<String> commentsPath = root.get("comments");
            Path<String> yearPath = root.get("year");
            Path<String> insuranceNumber = root.get("insuranceNumber");
            Path<Date> insuranceEndDate = root.get("insuranceEndDate");

            criteria.select(
                    builder.construct(Taxi.class, idPath, economicNumberPath,
                            customerPath, vehiclePath, colorPath,
                            placaPath, serialNumberPath, motorNmumberPath,
                            commentsPath, yearPath, insuranceNumber, insuranceEndDate
                    ));

            criteria.where(builder.equal(root.get("id"), taxiId));

            result = session.createQuery(criteria).uniqueResult();

            transaction.commit();
            logger.info("Taxi founds");
        } catch (HibernateException e) {
            rollback(transaction);
            logger.error("Can not load taxi object ", e);
        } catch (Exception e) {
            rollback(transaction);
            logger.error("Method getTaxiById of Taxi", e);
        }

        return result;
    }

    /**
     *
     * @return
     */
    public List<Person> fillCustomersComboBox() {

        Transaction transaction = null;
        List<Person> result = null;

        try {
            logger.info("Searching all customers to select..");
            Session session = HibernateUtil.getSessionFactory().getCurrentSession();
            transaction = session.beginTransaction();
            CriteriaBuilder builder = session.getCriteriaBuilder();

            CriteriaQuery<Person> criteria = builder.createQuery(Person.class);
            Root<Person> root = criteria.from(Person.class);

            Path<String> idPath = root.get("id");
            Path<String> firstNamePath = root.get("firstName");
            Path<String> secondNamePath = root.get("secondName");
            Path<String> lastNamePath = root.get("lastName");
            Path<String> middleNamePath = root.get("middleName");

            criteria.select(
                    builder.construct(Person.class, idPath, firstNamePath, secondNamePath, lastNamePath, middleNamePath
                    ));

            criteria.where(builder.equal(root.get("personType"), PersonType.CUSTOMER));

            result = session.createQuery(criteria).getResultList();

            transaction.commit();
            logger.info("Total of customers found for ComboBox: " + (null == result ? -1 : result.size()));
        } catch (HibernateException e) {
            rollback(transaction);
            logger.error("Can not load list of customers for ComboBox ", e);
        } catch (Exception e) {
            rollback(transaction);
            logger.error("Method fillCustomersComboBox of Taxi", e);
        }

        return result;
    }

    /**
     *
     * @return
     */
    public List<Color> fillColorsComboBox() {

        Transaction transaction = null;
        List<Color> result = null;

        try {
            logger.info("Searching all colors to select..");
            Session session = HibernateUtil.getSessionFactory().getCurrentSession();
            transaction = session.beginTransaction();
            CriteriaBuilder builder = session.getCriteriaBuilder();

            CriteriaQuery<Color> criteria = builder.createQuery(Color.class);
            Root<Color> root = criteria.from(Color.class);

            Path<String> idPath = root.get("id");
            Path<String> namePath = root.get("name");

            criteria.select(
                    builder.construct(Color.class, idPath, namePath
                    ));

            result = session.createQuery(criteria).getResultList();

            transaction.commit();
            logger.info("Total of colors found for ComboBox: " + (null == result ? -1 : result.size()));
        } catch (HibernateException e) {
            rollback(transaction);
            logger.error("Can not load list of colors for ComboBox ", e);
        } catch (Exception e) {
            rollback(transaction);
            logger.error("Method fillColorsComboBox of Taxi", e);
        }

        return result;
    }

    /**
     *
     * @param taxiId
     * @return
     */
    public Taxi getTaxiById(String taxiId) {

        Transaction transaction = null;
        Taxi result = null;

        try {
            logger.info("Searching taxi by id..");
            Session session = HibernateUtil.getSessionFactory().getCurrentSession();
            transaction = session.beginTransaction();
            CriteriaBuilder builder = session.getCriteriaBuilder();

            CriteriaQuery<Taxi> criteria = builder.createQuery(Taxi.class);
            Root<Taxi> root = criteria.from(Taxi.class);

            Path<String> idPath = root.get("id");
            Path<String> economicNumberPath = root.get("economicNumber");
            Path<String> driverPath = root.get("driver");
            Path<String> customerPath = root.get("customer");
            Path<String> vehiclePath = root.get("vehicle");
            Path<String> colorPath = root.get("color");
            Path<String> placaPath = root.get("placa");
            Path<String> serialNumberPath = root.get("serialNumber");
            Path<String> motorNmumberPath = root.get("motorNmumber");
            Path<String> commentsPath = root.get("comments");
            Path<String> yearPath = root.get("year");
            Path<String> insuranceNumber = root.get("insuranceNumber");
            Path<Date> insuranceEndDate = root.get("insuranceEndDate");

            criteria.select(
                    builder.construct(Taxi.class, idPath, economicNumberPath,
                            driverPath, customerPath, vehiclePath, colorPath,
                            placaPath, serialNumberPath, motorNmumberPath,
                            commentsPath, yearPath, insuranceNumber, insuranceEndDate
                    ));

            criteria.where(builder.equal(root.get("id"), taxiId));

            result = session.createQuery(criteria).uniqueResult();

            transaction.commit();
            logger.info("Taxi founds");
        } catch (HibernateException e) {
            rollback(transaction);
            logger.error("Can not load taxi object ", e);
        } catch (Exception e) {
            rollback(transaction);
            logger.error("Method getTaxiById of Taxi", e);
        }

        return result;
    }

    public Taxi getTaxiByIdReport(String taxiId) {

        Transaction transaction = null;
        Taxi result = null;

        try {
            logger.info("Searching taxi by id..");
            Session session = HibernateUtil.getSessionFactory().getCurrentSession();
            transaction = session.beginTransaction();
            CriteriaBuilder builder = session.getCriteriaBuilder();

            CriteriaQuery<Taxi> criteria = builder.createQuery(Taxi.class);
            Root<Taxi> root = criteria.from(Taxi.class);

            Path<String> idPath = root.get("id");
            Path<String> economicNumberPath = root.get("economicNumber");
            //Path<String> driverPath = root.get("driver");
            Path<String> customerPath = root.get("customer");
            Path<String> vehiclePath = root.get("vehicle");
            Path<String> colorPath = root.get("color");
            Path<String> placaPath = root.get("placa");
            Path<String> serialNumberPath = root.get("serialNumber");
            Path<String> motorNmumberPath = root.get("motorNmumber");
            Path<String> commentsPath = root.get("comments");
            Path<String> yearPath = root.get("year");
            Path<String> insuranceNumber = root.get("insuranceNumber");
            Path<Date> insuranceEndDate = root.get("insuranceEndDate");
            Path<Float> kmPath = root.get("km");
            Path<Double> paymentCarPath = root.get("paymentCar");

            criteria.select(
                    builder.construct(Taxi.class, idPath, economicNumberPath,
                            customerPath, vehiclePath, colorPath,
                            placaPath, serialNumberPath, motorNmumberPath,
                            commentsPath, yearPath, insuranceNumber, insuranceEndDate, kmPath, paymentCarPath
                    ));

            criteria.where(builder.equal(root.get("id"), taxiId));

            result = session.createQuery(criteria).uniqueResult();

            transaction.commit();
            logger.info("Taxi founds");
        } catch (HibernateException e) {
            rollback(transaction);
            logger.error("Can not load taxi object ", e);
        } catch (Exception e) {
            rollback(transaction);
            logger.error("Method getTaxiById of Taxi", e);
        }

        return result;
    }

    public Taxi getTaxiByIdReport2(String id) {
        logger.info("getTaxiByIdReport2");
        Taxi result = null;
        Transaction transaction = null;
        try {
            Session session = HibernateUtil.getSessionFactory().getCurrentSession();
            transaction = session.beginTransaction();
            CriteriaBuilder builder = session.getCriteriaBuilder();

            CriteriaQuery<Taxi> criteria = builder.createQuery(Taxi.class);
            Root<Taxi> root = criteria.from(Taxi.class);

            Predicate criterio = builder.equal(root.get("id"), id);
            criteria.where(builder.and(criterio));
            result = session.createQuery(criteria).uniqueResult();

            transaction.commit();
        } catch (HibernateException e) {
            rollback(transaction);
            logger.error("Unable to load Taxi list ", e);
        } catch (Exception e) {
            rollback(transaction);
            logger.error("Method getTaxiByIdReport2", e);
        }
        return result;
    }

    /**
     *
     * @param taxiId
     * @return
     */
    public Taxi getTaxiDetailsByTaxiId(String taxiId) {

        Transaction transaction = null;
        Taxi result = null;

        try {
            logger.info("Searching taxi by id..");

            Session session = HibernateUtil.getSessionFactory().getCurrentSession();
            transaction = session.beginTransaction();

            result = session.get(Taxi.class, taxiId);

            transaction.commit();
            logger.info("Taxi founds");
        } catch (HibernateException e) {
            rollback(transaction);
            logger.error("Can not load taxi object ", e);
        } catch (Exception e) {
            rollback(transaction);
            logger.error("Method getTaxiById of Taxi", e);
        }

        return result;
    }

    /**
     * Save Taxi details.
     *
     * @param taxi
     * @param vehicleId
     * @param driverId
     * @param customerId
     * @param colorId
     *
     *
     * @return True if taxi details were updated otherwise false.
     */
    public boolean updateTaxiById(Taxi taxi, String vehicleId,
            String driverId, String customerId, String colorId) {
        logger.info("updateTaxiById");

        boolean success = false;
        Transaction transaction = null;
        try {
            Session session = HibernateUtil.getSessionFactory().getCurrentSession();
            transaction = session.beginTransaction();

            CriteriaBuilder builder = session.getCriteriaBuilder();

            CriteriaUpdate<Taxi> update = builder.createCriteriaUpdate(Taxi.class);
            Root<Taxi> rootPerson = update.from(Taxi.class);

            update.set("placa", taxi.getPlaca());
            update.set("economicNumber", taxi.getEconomicNumber());
            update.set("serialNumber", taxi.getSerialNumber());
            update.set("motorNmumber", taxi.getMotorNmumber());
            update.set("comments", taxi.getComments());
            update.set("year", taxi.getYear());
            update.set("km", taxi.getKm());
            update.set("kmMaintenance", taxi.getKmMaintenance());
            update.set("payDay", taxi.getPayDay());
            update.set("paySaving", taxi.getPaySaving());
            update.set("adeudo", taxi.getAdeudo());
            update.set("payAccident", taxi.getPayAccident());
            if (null != taxi.getPaymentCar()) {
                update.set("paymentCar", taxi.getPaymentCar());
            }
            update.set("vehicle", new Vehicle(vehicleId));
            update.set("customer", new Person(customerId));

            if (null != driverId && !"".equals(driverId)) {
                update.set("driver", new Person(driverId));
            } else {
                update.set("driver", null);
            }

            update.set("color", new Color(colorId));
            update.set("insuranceNumber", taxi.getInsuranceNumber());
            update.set("insuranceEndDate", taxi.getInsuranceEndDate());
            update.set("insuranceName", taxi.getInsuranceName());
            update.set("insuranceCobertura", taxi.getInsuranceCobertura());
            update.set("gps", taxi.getGps());
            update.set("apc", taxi.getApc());
            update.set("gpsNumber", taxi.getGpsNumber());
            update.set("workDays", taxi.getWorkDays());

            update.where(builder.equal(rootPerson.get("id"), taxi.getId()));

            int total = session.createQuery(update).executeUpdate();

            if (1 == total) {
                logger.info("Taxi updated taxi_id: " + taxi.getId());
                transaction.commit();

                success = true;
            } else {
                logger.error("Taxi can not be updated " + taxi.getId());
                transaction.rollback();
            }
        } catch (HibernateException e) {
            logger.error("Taxi cannot be updated " + taxi.getId(), e);
            rollback(transaction);
        } catch (Exception e) {
            logger.error("Method updateTaxiById(" + taxi.getId() + ") ", e);
            rollback(transaction);
        }
        return success;
    }

    /**
     * Save contract, the contrac is signed for 1 year.
     *
     * @param contract Cotract to be saved.
     * @param services List of services that contrac has for a year..
     *
     * @return True is contract was saved successfully otherwise false.
     */
    public boolean saveContract(Contract contract, List<Service> services) {
        logger.info("updateTaxiById");

        boolean success = false;
        Transaction transaction = null;
        try {
            Session session = HibernateUtil.getSessionFactory().getCurrentSession();
            transaction = session.beginTransaction();

            session.save(contract);

            services.forEach((Service service) -> {
                ContractHasServiceId id = new ContractHasServiceId(
                        contract.getId(), service.getId());

                session.save(new ContractHasService(id));
            });

            transaction.commit();

            success = true;

            logger.info("Contract saved");
        } catch (HibernateException e) {
            logger.error("Taxi cannot be saved " + contract, e);
            rollback(transaction);
        } catch (Exception e) {
            logger.error("Method saveContract(" + contract + ") ", e);
            rollback(transaction);
        }
        return success;
    }

    /**
     *
     * @param contracts
     * @return
     */
    public List<ContractHasService> getAllContractsForTaxi(Set<Contract> contracts) {
        logger.info("getAllContractsForTaxi");

        Transaction transaction = null;
        List<ContractHasService> contractHasServices = new ArrayList<>();
        try {
            Session session = HibernateUtil.getSessionFactory().getCurrentSession();
            transaction = session.beginTransaction();
            CriteriaBuilder builder = session.getCriteriaBuilder();

            CriteriaQuery<ContractHasService> query = builder.createQuery(ContractHasService.class);
            Root<ContractHasService> root = query.from(ContractHasService.class);

            contracts.forEach((Contract contract) -> {
                query.where(builder.equal(root.get("contract"), contract));

                contractHasServices.addAll(session.createQuery(query).getResultList());
            });

            transaction.commit();

            logger.info("Contract loaded");
        } catch (HibernateException e) {
            logger.error("Contracts cannot be loaded ", e);
            rollback(transaction);
        } catch (Exception e) {
            logger.error("Method getAllContractsForTaxi(" + contracts + ") ", e);
            rollback(transaction);
        }
        return contractHasServices;
    }

    /**
     * Delete all services by contract id and the contract.
     *
     * @param contract Contract Identification number.
     * @return True is contract and contract details were deleted otherwise
     * false.
     */
    public boolean deleteContractAndContractDetailsById(Contract contract) {
        logger.info("deleteContractAndContractDetailsById");

        boolean success = false;
        Transaction transaction = null;

        try {
            Session session = HibernateUtil.getSessionFactory().getCurrentSession();
            transaction = session.beginTransaction();

            CriteriaBuilder builder = session.getCriteriaBuilder();
            CriteriaDelete<ContractHasService> delete = builder.createCriteriaDelete(ContractHasService.class);
            Root<ContractHasService> root = delete.from(ContractHasService.class);

            delete.where(builder.equal(root.get("contract"), contract));

            int total = session.createQuery(delete).executeUpdate();

            logger.info("ContractHasService total: " + total);

            CriteriaDelete<Contract> deleteContract = builder.createCriteriaDelete(Contract.class);
            Root<Contract> rootContract = deleteContract.from(Contract.class);

            deleteContract.where(builder.equal(rootContract.get("id"), contract.getId()));
            total = session.createQuery(deleteContract).executeUpdate();

            logger.info("Contract total: " + total);
            transaction.commit();
            logger.info("Contract deleted");

            success = true;
        } catch (HibernateException e) {
            logger.error("Contract cannot be deleted ", e);
            rollback(transaction);
        } catch (Exception e) {
            logger.error("Method deleteContractAndContractDetailsById(" + contract + ") ", e);
            rollback(transaction);
        }
        return success;
    }

    /**
     *
     * @param taxiId
     * @param userId
     * @param platform
     * @param monday
     * @param tuesday
     * @param wednesday
     * @param thursday
     * @param friday
     * @param saturday
     * @param sunday
     * @return
     */
    public boolean updateWeekWorkTaxiById(
            String taxiId, String userId, PlatformType platform,
            boolean monday,
            boolean tuesday,
            boolean wednesday,
            boolean thursday,
            boolean friday,
            boolean saturday,
            boolean sunday
    ) {
        logger.info("updateWeekWorkTaxiById");

        boolean success = false;
        Transaction transaction = null;
        try {
            Session session = HibernateUtil.getSessionFactory().getCurrentSession();
            transaction = session.beginTransaction();

            CriteriaBuilder builder = session.getCriteriaBuilder();

            CriteriaUpdate<Taxi> update = builder.createCriteriaUpdate(Taxi.class);
            Root<Taxi> rootUpdate = update.from(Taxi.class);

            update.set("platform", platform);
            update.set("monday", monday ? BasicType.ENEBLED : BasicType.DISABLED);
            update.set("tuesday", tuesday ? BasicType.ENEBLED : BasicType.DISABLED);
            update.set("wednesday", wednesday ? BasicType.ENEBLED : BasicType.DISABLED);
            update.set("thursday", thursday ? BasicType.ENEBLED : BasicType.DISABLED);
            update.set("friday", friday ? BasicType.ENEBLED : BasicType.DISABLED);
            update.set("saturday", saturday ? BasicType.ENEBLED : BasicType.DISABLED);
            update.set("sunday", sunday ? BasicType.ENEBLED : BasicType.DISABLED);
            update.set("lastUpdatedBy", new User(userId, ""));

            update.where(builder.equal(rootUpdate.get("id"), taxiId));

            int total = session.createQuery(update).executeUpdate();

            if (1 == total) {
                transaction.commit();
                success = true;
                logger.info("Taxi " + taxiId + " week work updated");
            } else {
                transaction.rollback();
                logger.error("Error: Taxi " + taxiId + " week work wasnot updated");
            }
        } catch (HibernateException e) {
            logger.error("Taxi week work can not be updated ", e);
            rollback(transaction);
        } catch (Exception e) {
            logger.error("Method updateWeekWorkTaxiById() ", e);
            rollback(transaction);
        }
        return success;
    }

    /**
     *
     * @param taxiId
     * @return
     */
    public Taxi getDriverByTaxiId(String taxiId) {
        Transaction transaction = null;
        Taxi result = null;

        try {
            logger.info("Searching driver  by id..");
            Session session = HibernateUtil.getSessionFactory().getCurrentSession();
            transaction = session.beginTransaction();
            CriteriaBuilder builder = session.getCriteriaBuilder();

            CriteriaQuery<Taxi> criteria = builder.createQuery(Taxi.class);
            Root<Taxi> root = criteria.from(Taxi.class);

            Path<Person> driver = root.get("driver");

            criteria.select(
                    builder.construct(Taxi.class, driver));

            criteria.where(builder.equal(root.get("id"), taxiId));

            result = session.createQuery(criteria).uniqueResult();

            transaction.commit();
            logger.info("getDriverByTaxiId founds");
        } catch (HibernateException e) {
            rollback(transaction);
            logger.error("Can not load getDriverByTaxiId object ", e);
        } catch (Exception e) {
            rollback(transaction);
            logger.error("Method getDriverByTaxiId of Taxi", e);
        }

        return result;
    }

    public boolean updateLocationByTaxi(String taxiId, String locationId) {
        logger.info("updateLocationByTaxi");

        boolean success = false;
        Transaction transaction = null;
        try {
            Session session = HibernateUtil.getSessionFactory().getCurrentSession();
            transaction = session.beginTransaction();

            CriteriaBuilder builder = session.getCriteriaBuilder();

            CriteriaUpdate<Taxi> update = builder.createCriteriaUpdate(Taxi.class);
            Root<Taxi> rootUpdate = update.from(Taxi.class);

            update.set("location", new Location(locationId));
            update.where(builder.equal(rootUpdate.get("id"), taxiId));

            int total = session.createQuery(update).executeUpdate();

            if (1 == total) {
                transaction.commit();
                success = true;
                logger.info("Taxi " + taxiId + " active");
            } else {
                transaction.rollback();
                logger.error("Error taxiId acrtive total: " + taxiId);
            }
        } catch (HibernateException e) {
            logger.error("taxiId can not be updated ", e);
            rollback(transaction);
        } catch (Exception e) {
            logger.error("Method updateLocationByTaxi() ", e);
            rollback(transaction);
        }
        return success;
    }

    private static final long serialVersionUID = -5443528487241194807L;

    final Logger logger = LogManager.getLogger(TaxiController.class);

    public TaxiController() {
    }

}
