コード例 #1
0
  /** Creates a new Customer */
  @WebMethod
  public @WebResult CreateCustomerWebServiceResponse createCustomer(
      @WebParam(name = "credentials") WebServiceCredentials credentials,
      @WebParam(name = "customer") Customer customer) {
    MessageSource messageSource = (MessageSource) SpringUtil.getBean("messageSource");

    Locale locale = LocaleUtil.getDefaultLocale();
    if (StringUtils.isNotBlank(customer.getCustomerLang())) {
      locale = LocaleUtil.getLocale(customer.getCustomerLang());
    }

    CreateCustomerWebServiceResponse response = new CreateCustomerWebServiceResponse();
    try {

      // check credentials
      validateCredentials(locale, credentials);

      String[] validationErrorList = validate(customer, locale, messageSource);
      if (validationErrorList != null && validationErrorList.length > 0) {
        response.setMessages(validationErrorList);
        response.setStatus(2);
        return response;
      }

      CustomerService cservice =
          (CustomerService) ServiceFactory.getService(ServiceFactory.CustomerService);

      // if customer has customer id >0 check that it belongs to this merchant id
      com.salesmanager.core.entity.customer.Customer tmpCustomer = null;
      if (customer.getCustomerId() > 0) {
        tmpCustomer = cservice.getCustomer(customer.getCustomerId());
        if (tmpCustomer != null) {
          if (tmpCustomer.getMerchantId() != credentials.getMerchantId()) {
            response.setMessages(
                new String[] {messageSource.getMessage("messages.authorization", null, locale)});
            response.setStatus(0);
          }
        }
      }

      com.salesmanager.core.entity.customer.Customer newCustomer =
          new com.salesmanager.core.entity.customer.Customer();

      if (tmpCustomer != null) { // modify existing customer
        newCustomer = tmpCustomer;
      }
      BeanUtils.copyProperties(newCustomer, customer);

      // copy properties to billing
      newCustomer.setCustomerBillingCity(customer.getCustomerCity());
      newCustomer.setCustomerBillingCountryId(customer.getCustomerCountryId());
      newCustomer.setCustomerBillingCountryName(newCustomer.getBillingCountry());
      newCustomer.setCustomerBillingFirstName(customer.getCustomerFirstname());
      newCustomer.setCustomerBillingLastName(customer.getCustomerLastname());
      newCustomer.setCustomerBillingPostalCode(customer.getCustomerPostalCode());
      newCustomer.setCustomerBillingState(newCustomer.getStateProvinceName());
      newCustomer.setCustomerBillingStreetAddress(customer.getCustomerStreetAddress());
      newCustomer.setCustomerBillingZoneId(customer.getCustomerZoneId());

      newCustomer.setLocale(locale);
      newCustomer.setMerchantId(credentials.getMerchantId());

      if (StringUtils.isBlank(customer.getZoneName()) && customer.getCustomerZoneId() > 0) {
        java.util.Map zones =
            (java.util.Map)
                RefCache.getAllZonesmap(LanguageUtil.getLanguageNumberCode(locale.getLanguage()));
        if (zones != null) {
          Zone z = (Zone) zones.get(customer.getCustomerZoneId());
          if (z != null) {
            newCustomer.setCustomerState(z.getZoneName());
          }
        }
      }

      if (StringUtils.isBlank(newCustomer.getBillingState())
          && newCustomer.getCustomerZoneId() > 0) {
        java.util.Map zones =
            (java.util.Map)
                RefCache.getAllZonesmap(LanguageUtil.getLanguageNumberCode(locale.getLanguage()));
        if (zones != null) {
          Zone z = (Zone) zones.get(newCustomer.getCustomerZoneId());
          if (z != null) {
            newCustomer.setCustomerBillingState(z.getZoneName());
          }
        }
      }

      cservice.saveOrUpdateCustomer(newCustomer, SystemUrlEntryType.WEB, locale);

      response.setMessages(
          new String[] {
            messageSource.getMessage("messages.customer.customerregistered", null, locale)
          });
      response.setStatus(1);
      response.setCustomerId(newCustomer.getCustomerId());

    } catch (Exception e) {

      if (e instanceof ServiceException) {
        String msg[] = {((ServiceException) e).getMessage()};
        response.setMessages(msg);
        response.setStatus(0);
      } else {

        log.error("Exception occurred while creating Customer", e);
        response.setMessages(
            new String[] {messageSource.getMessage("errors.technical", null, locale)});
        response.setStatus(0);
      }
    }
    return response;
  }
コード例 #2
0
ファイル: SubscriptionAction.java プロジェクト: dmonga/work
  public void validateCustomer() {

    if (StringUtils.isBlank(customer.getCustomerEmailAddress())) {
      addFieldError("customer.customerEmailAddress", getText("messages.required.email"));
      super.addFieldMessage("customer.customerEmailAddress", "messages.required.email");
    } else {
      if (!CustomerUtil.validateEmail(customer.getCustomerEmailAddress())) {
        addFieldError("customer.customerEmailAddress", getText("messages.invalid.email"));
        super.addFieldMessage("customer.customerEmailAddress", "messages.invalid.email");
      }
    }
    /*
     * if(StringUtils.isBlank(customer.getCustomerPassword())) {
     * addFieldError("customer.customerPassword",
     * getText("messages.required.password")); }
     * if(StringUtils.isBlank(getConfirmEmailAddress())) {
     * addFieldError("confirmEmailAddress",
     * getText("messages.required.email.confirm")); }else{
     * if(!getConfirmEmailAddress
     * ().equals(customer.getCustomerEmailAddress())){
     * addFieldError("confirmEmailAddress",
     * getText("messages.unequal.email.confirm")); } }
     * if(StringUtils.isBlank(getConfirmPassword())) {
     * addFieldError("confirmPassword",
     * getText("messages.required.password.confirm")); }else{
     * if(!getConfirmPassword().equals(customer.getCustomerPassword())){
     * addFieldError("confirmPassword",
     * getText("messages.unequal.password.confirm")); } }
     */
    if (StringUtils.isBlank(customer.getCustomerFirstname())) {
      addFieldError("customer.customerFirstname", getText("messages.required.firstname"));
      super.addFieldMessage("customer.customerFirstname", "messages.required.firstname");
    }
    if (StringUtils.isBlank(customer.getCustomerLastname())) {
      addFieldError("customer.customerLastname", getText("messages.required.lastname"));
      super.addFieldMessage("customer.customerLastname", "messages.required.lastname");
    }
    if (StringUtils.isBlank(customer.getCustomerBillingStreetAddress())) {
      addFieldError(
          "customer.customerBillingStreetAddress", getText("messages.required.streetaddress"));
      super.addFieldMessage(
          "customer.customerBillingStreetAddress", "messages.required.streetaddress");
    }
    if (StringUtils.isBlank(customer.getCustomerBillingCity())) {
      addFieldError("customer.customerBillingCity", getText("messages.required.city"));
      super.addFieldMessage("customer.customerBillingCity", "messages.required.city");
    }
    if (!StringUtils.isBlank(this.getFormstate()) && this.getFormstate().equals("text")) {
      if (StringUtils.isBlank(customer.getCustomerBillingState())) {
        addFieldError("customer.customerBillingState", getText("messages.required.stateprovince"));
        super.addFieldMessage("customer.customerBillingState", "messages.required.stateprovince");
      }
    }
    if (StringUtils.isBlank(customer.getCustomerBillingPostalCode())) {
      addFieldError("customer.customerBillingPostalCode", getText("messages.required.postalcode"));
      super.addFieldMessage("customer.customerBillingPostalCode", "messages.required.postalcode");
    }

    if (StringUtils.isBlank(customer.getCustomerTelephone())) {
      addFieldError("customer.customerTelephone", getText("messages.required.phone"));
      super.addFieldMessage("customer.customerTelephone", "messages.required.phone");
    }
    /**
     * else if(!CustomerUtil.ValidatePhoneNumber(customer.getCustomerTelephone ())){
     * addFieldError("customer.customerTelephone", getText("messages.invalid.phone"));
     * super.addFieldMessage("customer.customerTelephone", "messages.invalid.phone"); }
     */
    String cName = "";
    Map lcountries = RefCache.getCountriesMap();
    if (lcountries != null) {
      Country country = (Country) lcountries.get(customer.getCustomerBillingCountryId());
      Set descriptions = country.getDescriptions();
      if (descriptions != null) {
        Iterator cIterator = descriptions.iterator();
        while (cIterator.hasNext()) {
          CountryDescription desc = (CountryDescription) cIterator.next();
          cName = desc.getCountryName();
          if (desc.getId().getLanguageId()
              == LanguageUtil.getLanguageNumberCode(super.getLocale().getLanguage())) {
            cName = desc.getCountryName();
            break;
          }
        }
      }
    }

    if (StringUtils.isBlank(customer.getCustomerBillingState())) {
      Map lzones =
          RefCache.getAllZonesmap(
              LanguageUtil.getLanguageNumberCode(super.getLocale().getLanguage()));
      if (lzones != null) {
        Zone z = (Zone) lzones.get(customer.getCustomerBillingZoneId());
        if (z != null) {
          customer.setCustomerBillingState(z.getZoneName());
          customer.setCustomerState(z.getZoneName());
        }
      }
    }

    String lang = super.getLocale().getLanguage();

    customer.setCountryName(cName);
    customer.setCustomerBillingCountryName(cName);
    customer.setCustomerLang(lang);

    customer.setCountryName(customer.getBillingCountry());
    customer.setCustomerCity(customer.getCustomerBillingCity());
    customer.setCustomerCountryId(customer.getCustomerBillingCountryId());
    customer.setCustomerLang(super.getLocale().getLanguage());
    customer.setCustomerPostalCode(customer.getCustomerBillingPostalCode());
    customer.setCustomerStreetAddress(customer.getCustomerBillingStreetAddress());
    customer.setCustomerState(customer.getBillingState());
    customer.setCustomerZoneId(customer.getCustomerBillingZoneId());
  }