001    /**
002     * Copyright 2012 The Kuali Foundation Licensed under the Educational Community License, Version 2.0 (the "License"); you may not
003     * use this file except in compliance with the License. You may obtain a copy of the License at
004     *
005     * http://www.osedu.org/licenses/ECL-2.0
006     *
007     * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS"
008     * BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language
009     * governing permissions and limitations under the License.
010     *
011     */
012    package org.kuali.student.enrollment.state.service.impl;
013    
014    import java.util.Map;
015    import javax.xml.namespace.QName;
016    import org.apache.log4j.Logger;
017    import org.kuali.rice.core.api.resourceloader.GlobalResourceLoader;
018    import org.kuali.rice.krad.inquiry.InquirableImpl;
019    import org.kuali.student.enrollment.common.util.ContextBuilder;
020    import org.kuali.student.r2.common.dto.ContextInfo;
021    import org.kuali.student.r2.common.exceptions.DoesNotExistException;
022    import org.kuali.student.r2.common.exceptions.InvalidParameterException;
023    import org.kuali.student.r2.common.exceptions.MissingParameterException;
024    import org.kuali.student.r2.common.exceptions.OperationFailedException;
025    import org.kuali.student.r2.common.exceptions.PermissionDeniedException;
026    import org.kuali.student.r2.core.constants.StateServiceConstants;
027    import org.kuali.student.r2.core.class1.state.dto.StateInfo;
028    import org.kuali.student.r2.core.class1.state.service.StateService;
029    
030    /**
031     * This class 
032     *
033     * @author Kuali Student Team
034     */
035    public class StateInfoAdminInquirableImpl
036            extends InquirableImpl {
037    
038        private final static String KEY = "key";
039        private transient StateService stateService;
040        final Logger logger = Logger.getLogger(StateInfoAdminInquirableImpl.class);
041    
042        @Override
043        public StateInfo retrieveDataObject(Map<String, String> parameters) {
044            try {
045                return getStateService().getState(parameters.get(KEY), getContextInfo());
046            } catch (DoesNotExistException ex) {
047                throw new RuntimeException (ex);
048            } catch (InvalidParameterException ex) {
049                throw new RuntimeException (ex);
050            } catch (MissingParameterException ex) {
051                throw new RuntimeException (ex);
052            } catch (OperationFailedException ex) {
053                throw new RuntimeException (ex);
054            } catch (PermissionDeniedException ex) {
055                throw new RuntimeException (ex);
056            }
057        }
058    
059        public void setStateService(StateService stateService) {
060            this.stateService = stateService;
061        }
062    
063        public StateService getStateService() {
064            if (stateService == null) {
065                stateService = (StateService) GlobalResourceLoader.getService(new QName(StateServiceConstants.NAMESPACE,
066                        StateServiceConstants.SERVICE_NAME_LOCAL_PART));
067            }
068            return this.stateService;
069        }
070    
071        private ContextInfo getContextInfo() {
072            return ContextBuilder.loadContextInfo();
073        }
074    }