001 /** 002 * Copyright 2005-2014 The Kuali Foundation 003 * 004 * Licensed under the Educational Community License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.opensource.org/licenses/ecl2.php 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016 package org.kuali.rice.ksb.testclient1; 017 018 import java.util.ArrayList; 019 import java.util.List; 020 import java.util.Map; 021 import java.util.concurrent.ConcurrentHashMap; 022 import java.util.concurrent.atomic.AtomicInteger; 023 024 import org.apache.cxf.message.Message; 025 import org.apache.cxf.phase.PhaseInterceptorChain; 026 import org.kuali.rice.ksb.messaging.remotedservices.BaseballCard; 027 import org.kuali.rice.ksb.messaging.remotedservices.BaseballCardCollectionService; 028 import org.kuali.rice.ksb.messaging.remotedservices.ServiceCallInformationHolder; 029 030 import javax.annotation.Resource; 031 import javax.ws.rs.core.Context; 032 import javax.ws.rs.core.HttpHeaders; 033 import javax.xml.ws.WebServiceContext; 034 035 /** 036 * Implementation for {@link BaseballCardCollectionService} 037 * 038 * @author Kuali Rice Team (rice.collab@kuali.org) 039 * 040 */ 041 public class BaseballCardCollectionServiceImpl implements BaseballCardCollectionService { 042 // annotations on impl not supported by RESTServiceExporter/RestServiceDefinition 043 // @Context HttpHeaders headers; 044 045 private Map<Integer, BaseballCard> cards = new ConcurrentHashMap<Integer, BaseballCard>(); 046 private AtomicInteger nextId = new AtomicInteger(1); 047 048 /** 049 * @see org.kuali.rice.ksb.messaging.remotedservices.BaseballCardCollectionService#add(org.kuali.rice.ksb.messaging.remotedservices.BaseballCard) 050 */ 051 public Integer add(BaseballCard card) { 052 Integer result = null; 053 if (card != null) { 054 int id = nextId.addAndGet(1); 055 cards.put(id, card); 056 result = id; 057 } 058 return result; 059 } 060 061 /** 062 * @see org.kuali.rice.ksb.messaging.remotedservices.BaseballCardCollectionService#delete(java.lang.Integer) 063 */ 064 public void delete(Integer id) { 065 cards.remove(id); 066 } 067 068 /** 069 * @see org.kuali.rice.ksb.messaging.remotedservices.BaseballCardCollectionService#get(java.lang.Integer) 070 */ 071 public BaseballCard get(Integer id) { 072 return cards.get(id); 073 } 074 075 /** 076 * @see org.kuali.rice.ksb.messaging.remotedservices.BaseballCardCollectionService#get(java.lang.String) 077 */ 078 public List<BaseballCard> get(String playerName) { 079 List<BaseballCard> results = new ArrayList<BaseballCard>(); 080 for (BaseballCard card : cards.values()) { 081 if (playerName.equals(card.getPlayerName())) results.add(card); 082 } 083 return results; 084 } 085 086 /** 087 * @see org.kuali.rice.ksb.messaging.remotedservices.BaseballCardCollectionService#getAll() 088 */ 089 public List<BaseballCard> getAll() { 090 // excuse me while we exploit this service to test service call version headers 091 // annotations on impl not supported by RESTServiceExporter/RestServiceDefinition 092 ServiceCallInformationHolder.multiValues = (Map<String, List<String>>)PhaseInterceptorChain.getCurrentMessage().get(Message.PROTOCOL_HEADERS); 093 return new ArrayList<BaseballCard>(cards.values()); 094 } 095 096 /** 097 * @see org.kuali.rice.ksb.messaging.remotedservices.BaseballCardCollectionService#update(java.lang.Integer, org.kuali.rice.ksb.messaging.remotedservices.BaseballCard) 098 */ 099 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 }