001 /*
002 * Copyright 2011 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
017 /**
018 * Please modify this class to meet your needs
019 * This class is not complete
020 */
021
022 package org.kuali.kfs.module.external.kc.service.impl;
023
024
025 import java.net.MalformedURLException;
026 import java.util.ArrayList;
027 import java.util.Collection;
028 import java.util.Iterator;
029 import java.util.List;
030 import java.util.Map;
031
032 import javax.xml.ws.WebServiceException;
033
034 import org.kuali.kfs.integration.cg.ContractsAndGrantsUnit;
035 import org.kuali.kfs.integration.cg.dto.HashMapElement;
036 import org.kuali.kfs.module.external.kc.KcConstants;
037 import org.kuali.kfs.module.external.kc.service.ExternalizableBusinessObjectService;
038 import org.kuali.kfs.module.external.kc.service.KfsService;
039 import org.kuali.kfs.module.external.kc.util.GlobalVariablesExtractHelper;
040 import org.kuali.kfs.module.external.kc.webService.InstitutionalUnitService;
041 import org.kuali.kfs.module.external.kc.webService.InstitutionalUnitSoapService;
042 import org.kuali.rice.kns.bo.ExternalizableBusinessObject;
043
044 /**
045 * This class was generated by Apache CXF 2.2.10
046 * Thu Sep 30 05:29:28 HST 2010
047 * Generated source version: 2.2.10
048 *
049 */
050
051 public class UnitServiceImpl implements ExternalizableBusinessObjectService {
052 protected static org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(UnitServiceImpl.class);
053
054 protected InstitutionalUnitService getWebService() {
055 InstitutionalUnitSoapService ss = null;
056 try {
057 ss = new InstitutionalUnitSoapService();
058 }
059 catch (MalformedURLException ex) {
060 LOG.error("Could not intialize InstitutionalUnitSoapService: " + ex.getMessage());
061 throw new RuntimeException("Could not intialize InstitutionalUnitSoapService: " + ex.getMessage());
062 }
063 InstitutionalUnitService port = ss.getInstitutionalUnitServicePort();
064 return port;
065 }
066
067 public ExternalizableBusinessObject findByPrimaryKey(Map primaryKeys) {
068 ContractsAndGrantsUnit unitDTO = this.getWebService().getUnit((String)primaryKeys.get("unitNumber"));
069 return unitDTO;
070 }
071
072 public Collection findMatching(Map fieldValues) {
073 java.util.List <HashMapElement> hashMapList = new ArrayList<HashMapElement>();
074 List lookupUnitsReturn = null;
075
076 for (Iterator i = fieldValues.entrySet().iterator(); i.hasNext();) {
077 Map.Entry e = (Map.Entry) i.next();
078
079 String key = (String) e.getKey();
080 String val = (String) e.getValue();
081
082 if ( KcConstants.Unit.KC_ALLOWABLE_CRITERIA_PARAMETERS.contains(key) && (val.length() > 0)) {
083 HashMapElement hashMapElement = new HashMapElement();
084 hashMapElement.setKey(key);
085 hashMapElement.setValue(val);
086 hashMapList.add(hashMapElement);
087 }
088 }
089 try {
090 lookupUnitsReturn = this.getWebService().lookupUnits( hashMapList);
091 } catch (WebServiceException ex) {
092 GlobalVariablesExtractHelper.insertError(KcConstants.WEBSERVICE_UNREACHABLE, KfsService.getWebServiceServerName());
093 }
094
095 if (lookupUnitsReturn == null) lookupUnitsReturn = new ArrayList();
096 return lookupUnitsReturn;
097 }
098
099 }