Package pl.zgora.uz.wmie.fe.sps.business.service

Examples of pl.zgora.uz.wmie.fe.sps.business.service.CompanyService


  @Override
  public DataResult tableAjax(Map<String, String> filters,
      String[] projections, String columnOrder, String columnOrderDir,
      int startIndex) throws Exception {
    CompanyService companyService = (CompanyService)BusinessUtil
      .findBusiness("CompanyService");
   
    List<Order> orders = null;
    // stala czesc sluzaca sortowaniu
    if (columnOrder.compareTo("null") != 0) {
      orders = new ArrayList<Order>();
      if (columnOrderDir.compareTo("desc") == 0) {
        orders.add(Order.desc(columnOrder));
      } else {
        orders.add(Order.asc(columnOrder));
      }
    }
   

    ProjectionList projectionList = Projections.projectionList();
    for (int i = 0; i < projections.length; i++) {
      projectionList.add(Projections.property(projections[i]));
    }
    List<Criterion> criterions = new ArrayList<Criterion>();
    startIndex = (startIndex - 1) * ROW_AMOUNT;
    DataResult dataResult=null;
   
    if (filters.size() > 0) {
     
    FiltersUtil filtersUtil = new FiltersUtil();
    criterions = filtersUtil.createCriteriaFromFilters(filters,Company.class);
     
//      if (!ValidatorUtil.isBlankOrNull(filters
//          .get(Company.PROPERTY_IDCOMPANY))) {
//        criterions.add(Restrictions.eq(Company.PROPERTY_IDCOMPANY,
//            Integer
//                .parseInt(filters
//                    .get(Company.PROPERTY_IDCOMPANY))));
//      }
//      if (!ValidatorUtil.isBlankOrNull(filters
//          .get(Company.PROPERTY_ADDRESS))) {
//        criterions.add(Restrictions.like(
//            Company.PROPERTY_ADDRESS, filters
//                .get(Company.PROPERTY_ADDRESS),
//            MatchMode.START));
//      }
//      if (!ValidatorUtil.isBlankOrNull(filters
//          .get(Company.PROPERTY_EMAIL))) {
//        criterions.add(Restrictions.like(
//            Company.PROPERTY_EMAIL, filters
//                .get(Company.PROPERTY_EMAIL),
//            MatchMode.START));
//      }
//      if (!ValidatorUtil.isBlankOrNull(filters
//          .get(Company.PROPERTY_FIRSTNAMECONTACT))) {
//        criterions.add(Restrictions.like(
//            Company.PROPERTY_FIRSTNAMECONTACT, filters
//            .get(Company.PROPERTY_FIRSTNAMECONTACT),
//            MatchMode.START));
//      }
//      if (!ValidatorUtil.isBlankOrNull(filters
//          .get(Company.PROPERTY_LASTNAMECONTACT))) {
//        criterions.add(Restrictions.like(
//            Company.PROPERTY_LASTNAMECONTACT, filters
//            .get(Company.PROPERTY_LASTNAMECONTACT),
//            MatchMode.START));
//      }
//      if (!ValidatorUtil.isBlankOrNull(filters
//          .get(Company.PROPERTY_NAME))) {
//        criterions.add(Restrictions.like(
//            Company.PROPERTY_NAME, filters
//            .get(Company.PROPERTY_NAME),
//            MatchMode.START));
//      }
//      if (!ValidatorUtil.isBlankOrNull(filters
//          .get(Company.PROPERTY_REGISTRATIONDATE))) {
//        criterions.add(Restrictions.like(
//            Company.PROPERTY_REGISTRATIONDATE, filters
//            .get(Company.PROPERTY_REGISTRATIONDATE),
//            MatchMode.START));
//      }
//      if (!ValidatorUtil.isBlankOrNull(filters
//          .get(Company.PROPERTY_STATUS))) {
//        criterions.add(Restrictions.like(
//            Company.PROPERTY_STATUS, filters
//            .get(Company.PROPERTY_STATUS).charAt(0)));
//      }
//      if (!ValidatorUtil.isBlankOrNull(filters
//          .get(Company.PROPERTY_USERLOGIN))) {
//        criterions.add(Restrictions.like(
//            Company.PROPERTY_USERLOGIN, filters
//            .get(Company.PROPERTY_USERLOGIN),
//            MatchMode.START));
//      }
//
//      if (!ValidatorUtil.isBlankOrNull(filters
//          .get(Company.PROPERTY_ADMINISTRATOR + "."
//              + Administrator.PROPERTY_LASTNAME))) {
//        criterions.add(Restrictions.like(
//            Company.PROPERTY_ADMINISTRATOR + "."
//                + Administrator.PROPERTY_LASTNAME, filters
//                .get(Company.PROPERTY_ADMINISTRATOR + "."
//                    + Administrator.PROPERTY_LASTNAME)));
//      }
    }
   
    if (orders==null) {
      dataResult = companyService.findByParams(projectionList,
          criterions, startIndex, ROW_AMOUNT)
    } else {
      dataResult = companyService.findByParams(projectionList,
          criterions, orders, startIndex, ROW_AMOUNT);
    }
    return dataResult;
   
  }
View Full Code Here


  protected void service(HttpServletRequest req, HttpServletResponse resp)
      throws ServletException, IOException {
    String targetPage = null;
    String method = getInitParameter("method");

    CompanyService companyService=null;
    try {
      companyService = (CompanyService) BusinessUtil
        .findBusiness("CompanyService");
    } catch (Exception e2) {
      e2.printStackTrace();
    }
   
   
    if (TABLE_ACTION.equals(method)) {
      targetPage = getInitParameter("page");
    } else if (PRE_ADD_ACTION.equals(method)) {
      //prepareDataForSelect(req); 
      targetPage = "/pages/company/companyForm.jsp";
    } else if (DETAILS.equals(method)) {
      try {
        //prepareDataForSelect(req);
        Company company = companyService.load(Integer.valueOf(req.getParameter("id")));
        req.setAttribute("id", String.valueOf(company.getIdCompany()));
        req.setAttribute("name", company.getName());
        req.setAttribute("address", company.getAddress());
        if (company.getUserLogin()!=null) {
          req.setAttribute("userLogin", company.getUserLogin());
        }
        else {
          req.setAttribute("userLogin", EMPTY);
        }
        //req.setAttribute("userPassword", company.getUserPassword());
        if(company.getLastNameContact()!=null) {
          req.setAttribute("lastNameContact", company.getLastNameContact());         
        } else {
          req.setAttribute("lastNameContact", EMPTY);
        }
        if(company.getFirstNameContact()!=null) {
          req.setAttribute("firstNameContact", company.getFirstNameContact());
        } else {
          req.setAttribute("firstNameContact", EMPTY);
        }
       
        if(company.getEmail()!=null) {
          req.setAttribute("email", company.getEmail());
        } else {
          req.setAttribute("email", EMPTY);
        }
       
        if(company.getPhone()!=null) {
          req.setAttribute("phone", company.getPhone());         
        } else {
          req.setAttribute("phone", EMPTY);
        }
        req.setAttribute("status", String.valueOf(company.getStatus()));
        req.setAttribute("registrationDate", company.getRegistrationDate().toString());
        if (company.getAdministrator()!=null) {
          req.setAttribute("administrator", String.valueOf(company.getAdministrator().getFirstName()+
              " "+String.valueOf(company.getAdministrator().getLastName())));
        } else {
          req.setAttribute("administrator", EMPTY);
        }
      } catch (NumberFormatException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      } catch (Exception e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      }
   
      //prepareDataForSelect(req); 
      targetPage = "/pages/company/companyDetails.jsp"; }
    else if (ADD_ACTION.equals(method)) {
      String name=prepareString(req.getParameter("name"));
      //String administratorData=req.getParameter("administratorData");
      String address=prepareString(req.getParameter("address"));
      String userLogin=prepareString(req.getParameter("userLogin"));
      String userPassword=prepareString(req.getParameter("userPassword"));
      String lastNameContact=prepareString(req.getParameter("lastNameContact"));
      String firstNameContact=prepareString(req.getParameter("firstNameContact"));
      String email=prepareString(req.getParameter("email"));
      String status=prepareString(req.getParameter("status"));
      String phone=prepareString(req.getParameter("phone"));
     
      Administrator administrator=null;
      /*AdministratorService administratorService;
      try {
        administratorService = (AdministratorService)BusinessUtil.findBusiness("AdministratorService");
        administrator=administratorService.load(1);
      } catch (Exception e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
      }*/

      Company company=new Company();
      company.setAddress(address);
      company.setAdministrator(administrator);
      company.setEmail(email);
      company.setFirstNameContact(firstNameContact);
      company.setLastNameContact(lastNameContact);
      company.setName(name);
      company.setPhone(phone);
      company.setRegistrationDate(new Date());
      company.setStatus(status.charAt(0));
      company.setUserLogin(userLogin);
      company.setUserPassword(userPassword);
     
      try {
        companyService.save(company);
      } catch (Exception e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      }
      req.setAttribute("refreshTableFunction", "refreshCompanyTabele");
      targetPage = "/pages/default/closeAndRefresh.jsp";
    } else if(PRE_EDIT_ACTION.equals(method)) {
      try {
        //prepareDataForSelect(req);
        Company company = companyService.load(Integer.valueOf(req.getParameter("id")));
        req.setAttribute("id", String.valueOf(company.getIdCompany()));
        req.setAttribute("name", company.getName());
        req.setAttribute("address", company.getAddress());
        req.setAttribute("userLogin", company.getUserLogin());
        req.setAttribute("userPassword", company.getUserPassword());
        req.setAttribute("lastNameContact", company.getLastNameContact());
        req.setAttribute("firstNameContant", company.getFirstNameContact());
        req.setAttribute("email", company.getEmail());
        req.setAttribute("phone", company.getPhone());
        req.setAttribute("status", String.valueOf(company.getStatus()));
        req.setAttribute("registrationDate", company.getRegistrationDate().toString());
        //if (company.getAdministrator()!=null) {
        //  req.setAttribute("selectedAdministrator", String.valueOf(company.getAdministrator().getIdAdministrator()));
        //}
      } catch (NumberFormatException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      } catch (Exception e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      }
      targetPage = "/pages/company/companyForm.jsp";
      req.setAttribute("isEdit", Boolean.TRUE);
    } else if (EDIT_ACTION.equals(method)) {
      String id=req.getParameter("id");
      String name=req.getParameter("name");
      //String administratorData=req.getParameter("administratorData");
      String address=req.getParameter("address");
      String userLogin=req.getParameter("userLogin");
      String userPassword=req.getParameter("userPassword");
      String lastNameContact=req.getParameter("lastNameContact");
      String firstNameContact=req.getParameter("firstNameContact");
      String email=req.getParameter("email");
      String status=req.getParameter("status");
      String phone=req.getParameter("phone");
      String date=req.getParameter("registrationDate");
     
      Administrator administrator=null;
      /*AdministratorService administratorService;
      try {
        administratorService = (AdministratorService)BusinessUtil.findBusiness("AdministratorService");
        administrator=administratorService.load(1);
      } catch (Exception e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
      }*/

      Company company=new Company();
      company.setIdCompany(Integer.valueOf(id));
      company.setAddress(address);
      company.setAdministrator(administrator);
      company.setEmail(email);
      company.setFirstNameContact(firstNameContact);
      company.setLastNameContact(lastNameContact);
      company.setName(name);
      company.setPhone(phone);
      company.setStatus(status.charAt(0));
     
      //DateFormat df = new SimpleDateFormat("yyyy-MM-dd");
      //Date today=null;
      //try {
      //  today = df.parse(date);
      //} catch (ParseException e1) {
        // TODO Auto-generated catch block
      //  e1.printStackTrace();
      //}          
      //company.setRegistrationDate(today);
     
      company.setUserLogin(userLogin);
      company.setUserPassword(userPassword);
     
      try {
        companyService.update(company);
      } catch (Exception e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      }
      req.setAttribute("refreshTableFunction", "refreshCompanyTabele");
View Full Code Here

import pl.zgora.uz.wmie.fe.sps.database.classes.Company;

public class CompanyAjaxAction {
 
  public void deleteSelectedCompany(Integer id) throws Exception {
    CompanyService companyService = (CompanyService) BusinessUtil
        .findBusiness("CompanyService");
    companyService.deleteById(id);
  }
View Full Code Here

        .findBusiness("CompanyService");
    companyService.deleteById(id);
  }
 
  public String isLoginUnique(String login) throws Exception {
    CompanyService companyService=(CompanyService) BusinessUtil
        .findBusiness("CompanyService");
    List<Criterion> criterions = new ArrayList<Criterion>();
    criterions.add(Restrictions.eq("userLogin", login));
    List<Company> lista=companyService.findByParams(criterions);
    if (lista.size()==0) {
      return "ok";
    } else {
      return String.valueOf(lista.get(0).getIdCompany());
    }
View Full Code Here

TOP

Related Classes of pl.zgora.uz.wmie.fe.sps.business.service.CompanyService

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.