summaryrefslogtreecommitdiffstats
path: root/sandbox/travelsample/shared-contributions/payment-java-contribution/src/main/java/scatours/customer
diff options
context:
space:
mode:
Diffstat (limited to 'sandbox/travelsample/shared-contributions/payment-java-contribution/src/main/java/scatours/customer')
-rw-r--r--sandbox/travelsample/shared-contributions/payment-java-contribution/src/main/java/scatours/customer/CustomerNotFoundException.java58
-rw-r--r--sandbox/travelsample/shared-contributions/payment-java-contribution/src/main/java/scatours/customer/CustomerRegistry.java2
-rw-r--r--sandbox/travelsample/shared-contributions/payment-java-contribution/src/main/java/scatours/customer/CustomerRegistryImpl.java17
3 files changed, 72 insertions, 5 deletions
diff --git a/sandbox/travelsample/shared-contributions/payment-java-contribution/src/main/java/scatours/customer/CustomerNotFoundException.java b/sandbox/travelsample/shared-contributions/payment-java-contribution/src/main/java/scatours/customer/CustomerNotFoundException.java
new file mode 100644
index 0000000000..ebfb104650
--- /dev/null
+++ b/sandbox/travelsample/shared-contributions/payment-java-contribution/src/main/java/scatours/customer/CustomerNotFoundException.java
@@ -0,0 +1,58 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package scatours.customer;
+
+
+public class CustomerNotFoundException extends Exception {
+ private static final long serialVersionUID = -129752837478357452L;
+
+ /**
+ *
+ */
+ public CustomerNotFoundException() {
+
+ }
+
+ /**
+ * @param message
+ */
+ public CustomerNotFoundException(String message) {
+ super(message);
+
+ }
+
+ /**
+ * @param cause
+ */
+ public CustomerNotFoundException(Throwable cause) {
+ super(cause);
+
+ }
+
+ /**
+ * @param message
+ * @param cause
+ */
+ public CustomerNotFoundException(String message, Throwable cause) {
+ super(message, cause);
+
+ }
+
+}
diff --git a/sandbox/travelsample/shared-contributions/payment-java-contribution/src/main/java/scatours/customer/CustomerRegistry.java b/sandbox/travelsample/shared-contributions/payment-java-contribution/src/main/java/scatours/customer/CustomerRegistry.java
index 0a23f6a81a..c7c9f11a6c 100644
--- a/sandbox/travelsample/shared-contributions/payment-java-contribution/src/main/java/scatours/customer/CustomerRegistry.java
+++ b/sandbox/travelsample/shared-contributions/payment-java-contribution/src/main/java/scatours/customer/CustomerRegistry.java
@@ -31,7 +31,7 @@ public interface CustomerRegistry {
boolean updateCustomer(Customer customer);
- Customer getCustomer(String id);
+ Customer getCustomer(String id) throws CustomerNotFoundException;
Collection<Customer> getAllCustomers();
diff --git a/sandbox/travelsample/shared-contributions/payment-java-contribution/src/main/java/scatours/customer/CustomerRegistryImpl.java b/sandbox/travelsample/shared-contributions/payment-java-contribution/src/main/java/scatours/customer/CustomerRegistryImpl.java
index 8a55e43fc5..615f0ef1b9 100644
--- a/sandbox/travelsample/shared-contributions/payment-java-contribution/src/main/java/scatours/customer/CustomerRegistryImpl.java
+++ b/sandbox/travelsample/shared-contributions/payment-java-contribution/src/main/java/scatours/customer/CustomerRegistryImpl.java
@@ -85,15 +85,24 @@ public class CustomerRegistryImpl implements CustomerRegistry {
return customers.values();
}
- public Customer getCustomer(String id) {
- return customers.get(id);
+ public Customer getCustomer(String id) throws CustomerNotFoundException {
+ Customer customer = customers.get(id);
+
+ if (customer == null){
+ throw new CustomerNotFoundException("Customer " + id + " not found");
+ }
+
+ return customer;
}
public boolean updateCustomer(Customer customer) {
- Customer current = getCustomer(customer.getId());
- if (current == null) {
+ Customer current = null;
+ try {
+ current = getCustomer(customer.getId());
+ } catch (Exception ex) {
return false;
}
+
current.setEmail(customer.getEmail());
current.setName(customer.getName());
current.setCreditCard(customer.getCreditCard());