Ejemplo n.º 1
0
 @Override
 public AbstractAuditTrailEntity createAuditTrail(ServiceName serviceName, Object entity) {
   Contact contact = null;
   if (entity instanceof Contact) {
     contact = (Contact) entity;
   } else {
     return null;
   }
   ContactAuditTrail contactAuditTrail = new ContactAuditTrail();
   contactAuditTrail.setEntityId(contact.getId());
   contactAuditTrail.setFirstname(contact.getFirstname());
   contactAuditTrail.setSurname(contact.getSurname());
   contactAuditTrail.setHomeTelNumber(contact.getHomeTelNumber());
   contactAuditTrail.setWorkTelNumber(contact.getWorkTelNumber());
   contactAuditTrail.setCellNumber(contact.getCellNumber());
   contactAuditTrail.setFaxNumber(contact.getFaxNumber());
   contactAuditTrail.setWorkEmail(contact.getWorkEmail());
   contactAuditTrail.setPersonalEmail(contact.getPersonalEmail());
   contactAuditTrail.setIdNumber(contact.getIdNumber());
   contactAuditTrail.setPassportNumber(contact.getPassportNumber());
   contactAuditTrail.setMaritalStatus(contact.getMaritalStatus().getId());
   contactAuditTrail.setTaxNumber(contact.getTaxNumber());
   contactAuditTrail.setSaCitizen(contact.getSaCitizen());
   StringConvertor stringConvertor = new StringDataConvertor();
   String convertedServiceName =
       stringConvertor.convertCamelCaseToTitleCase(serviceName.getValue());
   contactAuditTrail.setAuditServiceName(convertedServiceName);
   if (serviceName == ServiceName.ADD_CONTACT) {
     contactAuditTrail.setAuditTrailDate(contact.getCreateDate());
     contactAuditTrail.setAuditTrailUser(contact.getCreatedBy());
   } else if (serviceName == ServiceName.UPDATE_CONTACT) {
     contactAuditTrail.setAuditTrailDate(contact.getLastModifyDate());
     contactAuditTrail.setAuditTrailUser(contact.getLastModifiedBy());
   }
   contactAuditTrail.setDeleted(contact.isDeleted());
   return contactAuditTrail;
 }
  @SecurityPermission(serviceName = ServiceName.SEARCH_CONTRACTORS)
  @UserActivityMonitor(serviceName = ServiceName.SEARCH_CONTRACTORS)
  @Override
  public List<Contractor> searchContractors(ContractorSearchCriteria contractorSearchCriteria) {
    List<Contractor> contractors = new ArrayList<>();
    if (contractorSearchCriteria != null) {
      /* Service logic */
      StringConvertor stringConvertor = new StringDataConvertor();
      StringBuilder searchContactsStringBuilder = new StringBuilder();
      StringValidator stringValidator = new StringDataValidator();

      searchContactsStringBuilder.append("SELECT c FROM Contractor c ");
      searchContactsStringBuilder.append("WHERE c.name like :name ");
      searchContactsStringBuilder.append("AND c.workDescription like :workDescription ");
      //            searchContactsStringBuilder.append("AND c.contacts.firstname like :firstname ");
      //            searchContactsStringBuilder.append("AND c.contacts.surname like :surname ");
      //            searchContactsStringBuilder.append("AND c.contacts.workEmail like :workEmail ");
      //            searchContactsStringBuilder.append("AND c.contacts.personalEmail like
      // :personalEmail ");
      String name =
          stringConvertor.convertForDatabaseSearch(
              contractorSearchCriteria.getName(), contractorSearchCriteria.getSearchType());
      String workDescription =
          stringConvertor.convertForDatabaseSearch(
              contractorSearchCriteria.getWorkDescription(),
              contractorSearchCriteria.getSearchType());
      String firstname = "%%";
      String surname = "%%";
      String workEmail = "%%";
      String personalEmail = "%%";
      if (contractorSearchCriteria.getContactSearchCriteria() != null) {
        firstname =
            stringConvertor.convertForDatabaseSearch(
                contractorSearchCriteria.getContactSearchCriteria().getFirstname(),
                contractorSearchCriteria.getSearchType());
        surname =
            stringConvertor.convertForDatabaseSearch(
                contractorSearchCriteria.getContactSearchCriteria().getSurname(),
                contractorSearchCriteria.getSearchType());
        workEmail =
            stringConvertor.convertForDatabaseSearch(
                contractorSearchCriteria.getContactSearchCriteria().getWorkEmail(),
                contractorSearchCriteria.getSearchType());
        personalEmail =
            stringConvertor.convertForDatabaseSearch(
                contractorSearchCriteria.getContactSearchCriteria().getPersonalEmail(),
                contractorSearchCriteria.getSearchType());
      }
      contractors =
          getEntityManager()
              .createQuery(searchContactsStringBuilder.toString())
              .setParameter("name", name)
              .setParameter("workDescription", workDescription)
              //                .setParameter("firstname", firstname)
              //                .setParameter("surname", surname)
              //                .setParameter("workEmail", workEmail)
              //                .setParameter("personalEmail", personalEmail)
              .getResultList();
    } else {
      throw new ServiceBeanException("Contractor search criteria not provided");
    }
    return contractors;
  }