@Override public <G extends CustomerAttribute> CreateResponse<G> createOrRetrieveCopyInstance(MultiTenantCopyContext context) throws CloneNotSupportedException { CreateResponse<G> createResponse = context.createOrRetrieveCopyInstance(this); if (createResponse.isAlreadyPopulated()) { return createResponse; } CustomerAttribute cloned = createResponse.getClone(); // dont clone cloned.setCustomer(customer); cloned.setName(name); cloned.setValue(value); return createResponse; } }
CustomerAttribute clonedEntry = entry.getValue().createOrRetrieveCopyInstance(context).getClone(); clonedEntry.setCustomer(cloned); cloned.getCustomerAttributes().put(entry.getKey(), clonedEntry);
@Override public String retrieveCustomerAttributeFromCustomer(Long customerId, String customerAttributeKey) { Customer currentCustomer = CustomerState.getCustomer(); Long currentCustomerId = currentCustomer.getId(); if (customerId != null && !currentCustomerId.equals(customerId)) { logWarningIfCustomerMismatch(currentCustomerId, customerId); currentCustomer = customerService.readCustomerById(customerId); } if (currentCustomer.getCustomerAttributes().containsKey(customerAttributeKey)) { return currentCustomer.getCustomerAttributes().get(customerAttributeKey).getValue(); } return null; }
@Override public void addCustomerAttributeToCustomer(Long customerId, String customerAttributeKey, String customerAttributeValue) throws PaymentException { Customer currentCustomer = CustomerState.getCustomer(); Long currentCustomerId = currentCustomer.getId(); if (customerId != null && !currentCustomerId.equals(customerId)) { logWarningIfCustomerMismatch(currentCustomerId, customerId); currentCustomer = customerService.readCustomerById(customerId); } CustomerAttribute customerAttribute = new CustomerAttributeImpl(); customerAttribute.setName(customerAttributeKey); customerAttribute.setValue(customerAttributeValue); customerAttribute.setCustomer(currentCustomer); currentCustomer.getCustomerAttributes().put(customerAttributeKey, customerAttribute); customerService.saveCustomer(currentCustomer); }