public AddressRepresentation(Address address) { this.company = address.getCompany(); this.fullName = address.getFullName(); this.street = address.getStreet(); this.streetComplement = address.getStreetComplement(); this.zip = address.getZip(); this.city = address.getCity(); this.country = address.getCountry(); }
int currentCustomer = 3; // get the customer at 3 Customer c = list.get(currentCustomer); // change his email c.setEmail("somethingelse@example.com");
@Override public Customer map(int index, ResultSet resultSet, StatementContext ctx) throws SQLException { Customer customer = new Customer(); customer.setId((UUID) resultSet.getObject("id")); customer.setSlug(resultSet.getString("slug")); customer.setEmail(resultSet.getString("email")); customer.setPhoneNumber(resultSet.getString("phone_number")); customer.setFirstName(resultSet.getString("first_name")); customer.setLastName(resultSet.getString("last_name")); customer.setCompany(resultSet.getString("company")); customer.setUserId((UUID) resultSet.getObject("agent_id")); return customer; } }
@Override public Address map(int index, ResultSet resultSet, StatementContext ctx) throws SQLException { Address address = new Address(); address.setId((UUID) resultSet.getObject("address_id")); address.setCustomerId((UUID) resultSet.getObject("customer_id")); address.setCompany(resultSet.getString("company")); address.setFullName(resultSet.getString("full_name")); address.setStreet(resultSet.getString("street")); address.setStreetComplement(resultSet.getString("street_complement")); address.setZip(resultSet.getString("zip")); address.setCity(resultSet.getString("city")); address.setCountry(resultSet.getString("country")); address.setType(resultSet.getString("type")); address.setNote(resultSet.getString("note")); return address; } }
private boolean updateCustomerIfNecessary(Customer existingCustomer, Customer customer) { boolean update = false; if (existingCustomer.getFirstName() == null || !existingCustomer.getFirstName().equals(customer.getFirstName())) { update = true; existingCustomer.setFirstName(customer.getFirstName()); } if (existingCustomer.getLastName() == null || !existingCustomer.getLastName().equals(customer.getLastName())) { update = true; existingCustomer.setLastName(customer.getLastName()); } if (existingCustomer.getPhoneNumber() == null || !existingCustomer.getPhoneNumber().equals(customer.getPhoneNumber())) { update = true; existingCustomer.setPhoneNumber(customer.getPhoneNumber()); } if (existingCustomer.getCompany() == null || !existingCustomer.getCompany().equals(customer.getCompany())) { update = true; existingCustomer.setCompany(customer.getCompany()); } return update; } }
public CustomerRepresentation(Customer customer) { setEmail(customer.getEmail()); setFirstName(customer.getFirstName()); setLastName(customer.getLastName()); setPhoneNumber(customer.getPhoneNumber()); }
@Override public Optional<GatewayCustomerData> getCustomerData(Customer customer, String gatewayId) { GatewayCustomerData result = dao.getCustomerData(customer.getId(), gatewayId); if (result == null) { return Optional.absent(); } return Optional.of(result); }
public Component getListCellRendererComponent( JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { if (value instanceof Customer) { Customer c = (Customer) value; StringBuffer sb = new StringBuffer(); if (c.getCompany() != null && c.getCompany().length() > 0) { sb.append(c.getCompany()); } sb.append(" - "); if (c.getCompany() != null && c.getCompany().length() > 0) { sb.append(c.getContact()); } sb.append(" - "); if (c.getCompany() != null && c.getCompany().length() > 0) { sb.append(c.getCity()); sb.append(", "); } if (c.getCompany() != null && c.getCompany().length() > 0) { sb.append(c.getState()); } value = sb.toString(); } return super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus); } }
@Override public Address create(@Valid Address address) throws EntityAlreadyExistsException, InvalidEntityException { UUID id = UUID.randomUUID(); address.setId(id); this.dao.createAddress(address); return address; }
@Override public Customer findById(UUID id) { Customer customer = this.dao.findById(CUSTOMER_TABLE_NAME, id); if (customer != null) { List<AddonGroup> addons = this.dao.findAddons(customer); customer.setAddons(asMap(addons)); } return customer; }
@Override public void delete(@Valid Address address) throws EntityDoesNotExistException { if (this.findById(address.getId()) == null) { throw new EntityDoesNotExistException(); } this.dao.deleteAddress(address); }
public boolean apply(@Nullable Address input) { return input.getCustomerId().equals(customerId) && input.getType().equals(type); } }).first().orNull();
public boolean apply(@Nullable Customer input) { return input.getUserId().equals(userId); } }).first().orNull();
/** * Prepares the context for an address * * @param address the address to get the context of * @return the prepared context */ private Map<String, Object> prepareAddressContext(Address address) { Map<String, Object> addressContext = Maps.newHashMap(); addressContext.put("street", address.getStreet()); addressContext.put("streetComplement", address.getStreetComplement()); addressContext.put("zip", address.getZip()); addressContext.put("city", address.getCity()); addressContext.put("country", address.getCountry()); addressContext.put("company", address.getCompany()); return addressContext; } }
@Override public Optional<GatewayCustomerData> getCustomerData(Customer customer, String gatewayId) { Key key = new Key(customer.getId(), gatewayId, "customer"); if (store.containsKey(key)) { return Optional.of((GatewayCustomerData) store.get(key)); } return Optional.absent(); }
Map<String,Customer> customers = new HashMap<String,Customer>(); //somewhere in the code you fill up the Map, assuming customer names are unique customers.put(customer.getName(), customer) // at some later point you retrieve it like this; // this is fast, given a good hash // been calculated for the "keys" in your map, in this case the keys are unique // String objects so the default hash algorithm should be fine Customer theCustomerYouLookFor = customers.get("Doe"); // modify it theCustomerYouLookFor.setEmail("newEmail@stackoverflow.com")
@Override public Customer findByUserId(UUID userId) { Customer customer = this.dao.findByUserId(userId); if (customer != null) { List<AddonGroup> addons = this.dao.findAddons(customer); customer.setAddons(asMap(addons)); } return customer; }
/** * Prepares the context for an address * * @param address the address to get the context of * @return the prepared context */ private Map<String, Object> prepareAddressContext(Address address) { Map<String, Object> addressContext = Maps.newHashMap(); addressContext.put("street", address.getStreet()); addressContext.put("streetComplement", address.getStreetComplement()); addressContext.put("zip", address.getZip()); addressContext.put("city", address.getCity()); addressContext.put("country", address.getCountry()); addressContext.put("company", address.getCompany()); return addressContext; } }
@Override public void delete(@Valid Customer entity) throws EntityDoesNotExistException { Integer updatedRows = 0; this.dao.begin(); updatedRows += this.dao.deleteEntityEntityById(CUSTOMER_TABLE_NAME, entity.getId()); updatedRows += this.dao.detachChildren(entity.getId()); updatedRows += this.dao.deleteEntityAndChildrenById(entity.getId()); this.dao.commit(); if (updatedRows <= 0) { throw new EntityDoesNotExistException("No rows was updated when trying to delete customer"); } }
@Override public Customer findBySlug(String slug) { Customer customer = this.dao.findBySlug(CUSTOMER_TABLE_NAME, slug, getTenant()); if (customer != null) { List<AddonGroup> addons = this.dao.findAddons(customer); customer.setAddons(asMap(addons)); } return customer; }