1 /**
2 * Copyright 2005-2014 The Kuali Foundation
3 *
4 * Licensed under the Educational Community License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.opensource.org/licenses/ecl2.php
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16 package org.kuali.rice.ksb.testclient1;
17
18 import java.util.ArrayList;
19 import java.util.List;
20 import java.util.Map;
21 import java.util.concurrent.ConcurrentHashMap;
22 import java.util.concurrent.atomic.AtomicInteger;
23
24 import org.apache.cxf.message.Message;
25 import org.apache.cxf.phase.PhaseInterceptorChain;
26 import org.kuali.rice.ksb.messaging.remotedservices.BaseballCard;
27 import org.kuali.rice.ksb.messaging.remotedservices.BaseballCardCollectionService;
28 import org.kuali.rice.ksb.messaging.remotedservices.ServiceCallInformationHolder;
29
30 import javax.annotation.Resource;
31 import javax.ws.rs.core.Context;
32 import javax.ws.rs.core.HttpHeaders;
33 import javax.xml.ws.WebServiceContext;
34
35 /**
36 * Implementation for {@link BaseballCardCollectionService}
37 *
38 * @author Kuali Rice Team (rice.collab@kuali.org)
39 *
40 */
41 public class BaseballCardCollectionServiceImpl implements BaseballCardCollectionService {
42 // annotations on impl not supported by RESTServiceExporter/RestServiceDefinition
43 // @Context HttpHeaders headers;
44
45 private Map<Integer, BaseballCard> cards = new ConcurrentHashMap<Integer, BaseballCard>();
46 private AtomicInteger nextId = new AtomicInteger(1);
47
48 /**
49 * @see org.kuali.rice.ksb.messaging.remotedservices.BaseballCardCollectionService#add(org.kuali.rice.ksb.messaging.remotedservices.BaseballCard)
50 */
51 public Integer add(BaseballCard card) {
52 Integer result = null;
53 if (card != null) {
54 int id = nextId.addAndGet(1);
55 cards.put(id, card);
56 result = id;
57 }
58 return result;
59 }
60
61 /**
62 * @see org.kuali.rice.ksb.messaging.remotedservices.BaseballCardCollectionService#delete(java.lang.Integer)
63 */
64 public void delete(Integer id) {
65 cards.remove(id);
66 }
67
68 /**
69 * @see org.kuali.rice.ksb.messaging.remotedservices.BaseballCardCollectionService#get(java.lang.Integer)
70 */
71 public BaseballCard get(Integer id) {
72 return cards.get(id);
73 }
74
75 /**
76 * @see org.kuali.rice.ksb.messaging.remotedservices.BaseballCardCollectionService#get(java.lang.String)
77 */
78 public List<BaseballCard> get(String playerName) {
79 List<BaseballCard> results = new ArrayList<BaseballCard>();
80 for (BaseballCard card : cards.values()) {
81 if (playerName.equals(card.getPlayerName())) results.add(card);
82 }
83 return results;
84 }
85
86 /**
87 * @see org.kuali.rice.ksb.messaging.remotedservices.BaseballCardCollectionService#getAll()
88 */
89 public List<BaseballCard> getAll() {
90 // excuse me while we exploit this service to test service call version headers
91 // annotations on impl not supported by RESTServiceExporter/RestServiceDefinition
92 ServiceCallInformationHolder.multiValues = (Map<String, List<String>>)PhaseInterceptorChain.getCurrentMessage().get(Message.PROTOCOL_HEADERS);
93 return new ArrayList<BaseballCard>(cards.values());
94 }
95
96 /**
97 * @see org.kuali.rice.ksb.messaging.remotedservices.BaseballCardCollectionService#update(java.lang.Integer, org.kuali.rice.ksb.messaging.remotedservices.BaseballCard)
98 */
99 public void update(Integer id, BaseballCard card) {
100 cards.put(id, card);
101 }
102
103 /**
104 * This method lacks JAX-RS annotations in the {@link BaseballCardCollectionService} interface
105 *
106 * @see org.kuali.rice.ksb.messaging.remotedservices.BaseballCardCollectionService#unannotatedMethod()
107 */
108 public void unannotatedMethod() {
109 // do nothing
110 }
111
112 }