001/**
002 * Copyright 2005-2016 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 */
016package org.kuali.rice.location.api.state;
017
018import org.kuali.rice.core.api.criteria.QueryByCriteria;
019import org.kuali.rice.core.api.exception.RiceIllegalArgumentException;
020import org.kuali.rice.core.api.exception.RiceIllegalStateException;
021import org.kuali.rice.location.api.LocationConstants;
022import org.springframework.cache.annotation.Cacheable;
023
024import javax.jws.WebMethod;
025import javax.jws.WebParam;
026import javax.jws.WebResult;
027import javax.jws.WebService;
028import javax.jws.soap.SOAPBinding;
029import javax.xml.bind.annotation.XmlElement;
030import javax.xml.bind.annotation.XmlElementWrapper;
031import java.util.List;
032
033/**
034 * Service for interacting with {@link State States}.
035 *
036 * @author Kuali Rice Team (rice.collab@kuali.org)
037 */
038@WebService(name = "StateService", targetNamespace = LocationConstants.Namespaces.LOCATION_NAMESPACE_2_0)
039@SOAPBinding(style = SOAPBinding.Style.DOCUMENT, use = SOAPBinding.Use.LITERAL, parameterStyle = SOAPBinding.ParameterStyle.WRAPPED)
040public interface StateService {
041
042    /**
043     * Gets a {@link State} from a postal country code and postal state code.
044     * <p/>
045     * <p>
046     * This method will return null if the state does not exist.
047     * </p>
048     * <p/>
049     * <p>
050     * This method will return active or inactive states.
051     * </p>
052     *
053     * @param countryCode country code. cannot be blank.
054     * @param code        state code. cannot be blank.
055     * @return a {@link State} or null
056     * @throws RiceIllegalArgumentException country code or state code is blank
057     */
058    @WebMethod(operationName = "getState")
059    @WebResult(name = "state")
060    @Cacheable(value=State.Cache.NAME, key="'countryCode=' + #p0 + '|' + 'code=' + #p1")
061    State getState(@WebParam(name = "countryCode") String countryCode, @WebParam(name = "code") String code)
062            throws RiceIllegalArgumentException;
063
064    /**
065     * Finds all the {@link State States} for postal country code.
066     * <p/>
067     * <p>
068     * This method will always return an <b>immutable</b> Collection
069     * even when no values exist.
070     * </p>
071     * <p/>
072     * <p>
073     * This method will only return active states.
074     * </p>
075     *
076     * @param countryCode state code. cannot be blank.
077     * @return an immutable collection of states
078     * @throws RiceIllegalArgumentException country code is blank
079     */
080    @WebMethod(operationName = "findAllStatesInCountry")
081    @XmlElementWrapper(name = "states", required = true)
082    @XmlElement(name = "state", required = false)
083    @WebResult(name = "states")
084    @Cacheable(value=State.Cache.NAME, key="'countryCode=' + #p0")
085    List<State> findAllStatesInCountry(@WebParam(name = "countryCode") String countryCode)
086            throws RiceIllegalArgumentException;
087    
088    /**
089     * Finds all the {@link State States} for alternate postal country code.
090     * <p/>
091     * <p>
092     * This method will always return an <b>immutable</b> Collection
093     * even when no values exist.
094     * </p>
095     * <p/>
096     * <p>
097     * This method will only return active states.
098     * </p>
099     *
100     * @param alternateCode cannot be blank.
101     * @return an immutable collection of states
102     * @throws RiceIllegalArgumentException alternate country code is null
103     * @throws RiceIllegalStateException when no countries are found for alternate country code
104     */
105    @WebMethod(operationName = "findAllStatesInCountryByAltCode")
106    @XmlElementWrapper(name = "states", required = true)
107    @XmlElement(name = "state", required = false)
108    @WebResult(name = "states")
109    @Cacheable(value=State.Cache.NAME, key="'alternateCode=' + #p0")
110    List<State> findAllStatesInCountryByAltCode(@WebParam(name = "alternateCode") String alternateCode)
111            throws RiceIllegalArgumentException, RiceIllegalStateException;
112
113    /**
114     * This method find States based on a query criteria.  The criteria cannot be null.
115     *
116     * @since 2.0.1
117     * @param queryByCriteria the criteria.  Cannot be null.
118     * @return query results.  will never return null.
119     * @throws IllegalArgumentException if the queryByCriteria is null
120     */
121    @WebMethod(operationName = "findStates")
122    @WebResult(name = "results")
123    StateQueryResults findStates(@WebParam(name = "query") QueryByCriteria queryByCriteria) throws RiceIllegalArgumentException;
124}