Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Copyright 2005-2013 The Kuali Foundation Licensed under the Educational Community License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.opensource.org/licenses/ecl2.php Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
 
 package org.kuali.rice.location.service.impl;
 
 import static org.kuali.rice.core.api.criteria.PredicateFactory.equal;
 
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
 
 
 public class LocationModuleService extends ModuleServiceBase {
 
     private CampusService campusService;
     private StateService stateService;
     private CountryService countryService;
     private CountyService countyService;
 
 
     public <T extends ExternalizableBusinessObject> T getExternalizableBusinessObject(Class<T> businessObjectClassMap<StringObjectfieldValues) {
         if(CampusEbo.class.isAssignableFrom(businessObjectClass)){
             if(isNonBlankValueForKey(fieldValues..)){
                 Campus campus = getCampusService().getCampus((StringfieldValues.get(
                         ..));
                 return (T) CampusBo.from(campus);
             }
         } else if(StateEbo.class.isAssignableFrom(businessObjectClass)){
                     && isNonBlankValueForKey(fieldValues..)) {
                 State state = getStateService().getState((StringfieldValues.get(
                         ..), (StringfieldValues.get(
                         ..));
                 return (T) StateBo.from(state);
             }
         } else if(CountryEbo.class.isAssignableFrom(businessObjectClass)){
             if(isNonBlankValueForKey(fieldValues..)) {
                 Country country = getCountryService().getCountry((StringfieldValues.get(
                         ..));
                 return (T) CountryBo.from(country);
             }
         } else if (CountyEbo.class.isAssignableFrom(businessObjectClass)) {
             if (isNonBlankValueForKey(fieldValues..)
                     && isNonBlankValueForKey(fieldValues..)
                     && isNonBlankValueForKey(fieldValues..)) {
                 County county = getCountyService().getCounty((StringfieldValues.get(
                         ..), (StringfieldValues.get(
                         ..), (StringfieldValues.get(
                         ..));
 
                 CountyBo countyBo = CountyBo.from(county);
                 // get referenced objects too
                StateBo stateBo = StateBo.from(getStateService().getState(countyBo.getCountryCode(), countyBo.getStateCode()));
                CountryBo countryBo = CountryBo.from(getCountryService().getCountry(countyBo.getCountryCode()));
                countyBo.setState(stateBo);
                countyBo.setCountry(countryBo);
                return (T) countyBo;
            }
        } else if (PostalCodeEbo.class.isAssignableFrom(businessObjectClass)) {
            if (isNonBlankValueForKey(fieldValues..)
                    && isNonBlankValueForKey(fieldValues..)) {
                PostalCode postalCode = getPostalCodeService().getPostalCode((StringfieldValues.get(
                        ..), (StringfieldValues.get(
                        ..));
                return (T)PostalCodeBo.from(postalCode);
            }
        }
        // otherwise, use the default implementation
        return super.getExternalizableBusinessObjectbusinessObjectClassfieldValues );
    }

    
	@SuppressWarnings("unchecked")
			Class<T> externalizableBusinessObjectClassMap<StringObjectfieldValues) {
		if ( StateEbo.class.isAssignableFromexternalizableBusinessObjectClass ) ) {
            Collection<StateBostates = getBusinessObjectService().findMatching(StateBo.classfieldValues);
            List<StateEbostateEbos = new ArrayList<StateEbo>(states.size());
            for (StateBo state : states) {
                stateEbos.add(StateBo.from(State.Builder.create(state).build()));
            }
            return (List<T>)stateEbos;
else if ( CampusEbo.class.isAssignableFromexternalizableBusinessObjectClass ) ) {
            Collection<CampusBocampuses = getBusinessObjectService().findMatching(CampusBo.classfieldValues);
            List<CampusEbocampusEbos = new ArrayList<CampusEbo>(campuses.size());
            for (CampusBo campus : campuses) {
                campusEbos.add(CampusBo.from(Campus.Builder.create(campus).build()));
            }
            return (List<T>)campusEbos;
else if ( CountryEbo.class.isAssignableFromexternalizableBusinessObjectClass ) ) {
            Collection<CountryBocountries = getBusinessObjectService().findMatching(CountryBo.classfieldValues);
            List<CountryEbocountryEbos = new ArrayList<CountryEbo>(countries.size());
            for (CountryBo country : countries) {
                countryEbos.add(CountryBo.from(Country.Builder.create(country).build()));
            }
            return (List<T>)countryEbos;
else if ( CountyEbo.class.isAssignableFromexternalizableBusinessObjectClass ) ) {
            Collection<CountyBocounties = getBusinessObjectService().findMatching(CountyBo.classfieldValues);
            List<CountyEbocountyEbos = new ArrayList<CountyEbo>(counties.size());
            for (CountyBo county : counties) {
                countyEbos.add(CountyBo.from(County.Builder.create(county).build()));
            }
            return (List<T>)countyEbos;
else if ( PostalCodeEbo.class.isAssignableFromexternalizableBusinessObjectClass ) ) {
            Collection<PostalCodeBopostalCodes = getBusinessObjectService().findMatching(PostalCodeBo.classfieldValues);
            List<PostalCodeEbopostalCodeEbos = new ArrayList<PostalCodeEbo>(postalCodes.size());
            for (PostalCodeBo postalCode : postalCodes) {
                postalCodeEbos.add(PostalCodeBo.from(PostalCode.Builder.create(postalCode).build()));
            }
            return (List<T>)postalCodeEbos;
		}
		// otherwise, use the default implementation
		return super.getExternalizableBusinessObjectsListexternalizableBusinessObjectClassfieldValues );
	}

	@SuppressWarnings("unchecked")
			Class<T> externalizableBusinessObjectClassMap<StringObjectfieldValuesboolean unbounded) {
        Map<StringStringsearchCriteria = new HashMap<StringString>();
			for (Map.Entry<StringObjectfieldValue : fieldValues.entrySet()) {
				if (fieldValue.getValue() != null) {
					searchCriteria.put(fieldValue.getKey(), fieldValue.getValue().toString());
				}
				else {
					searchCriteria.put(fieldValue.getKey(), null);
				}
			}
		// for Person objects (which are not real PersistableBOs) pull them through the person service
		if ( StateEbo.class.isAssignableFromexternalizableBusinessObjectClass ) ) {
            Collection<StateBostates = getLookupService().findCollectionBySearchHelper(StateBo.classsearchCriteria,
                    unbounded);
            List<StateEbostateEbos = new ArrayList<StateEbo>(states.size());
            for (StateBo state : states) {
                stateEbos.add(StateBo.from(State.Builder.create(state).build()));
            }
            return (List<T>)stateEbos;
else if ( CampusEbo.class.isAssignableFromexternalizableBusinessObjectClass ) ) {
            Collection<CampusBocampuses = getLookupService().findCollectionBySearchHelper(CampusBo.class,
                    searchCriteriaunbounded);
            List<CampusEbocampusEbos = new ArrayList<CampusEbo>(campuses.size());
            for (CampusBo campus : campuses) {
                campusEbos.add(CampusBo.from(Campus.Builder.create(campus).build()));
            }
            return (List<T>)campusEbos;
else if ( CountryEbo.class.isAssignableFromexternalizableBusinessObjectClass ) ) {
            Collection<CountryBocountries = getLookupService().findCollectionBySearchHelper(CountryBo.class,
                    searchCriteriaunbounded);
            List<CountryEbocountryEbos = new ArrayList<CountryEbo>(countries.size());
            for (CountryBo country : countries) {
                countryEbos.add(CountryBo.from(Country.Builder.create(country).build()));
            }
            return (List<T>)countryEbos;
else if ( CountyEbo.class.isAssignableFromexternalizableBusinessObjectClass ) ) {
            Collection<CountyBocounties = getLookupService().findCollectionBySearchHelper(CountyBo.class,
                    searchCriteriaunbounded);
            List<CountyEbocountyEbos = new ArrayList<CountyEbo>(counties.size());
            for (CountyBo county : counties) {
                countyEbos.add(CountyBo.from(County.Builder.create(county).build()));
            }
            return (List<T>)countyEbos;
else if ( PostalCodeEbo.class.isAssignableFromexternalizableBusinessObjectClass ) ) {
            Collection<PostalCodeBopostalCodes = getLookupService().findCollectionBySearchHelper(PostalCodeBo.class,
                    searchCriteriaunbounded);
            List<PostalCodeEbopostalCodeEbos = new ArrayList<PostalCodeEbo>(postalCodes.size());
            for (PostalCodeBo postalCode : postalCodes) {
                postalCodeEbos.add(PostalCodeBo.from(PostalCode.Builder.create(postalCode).build()));
            }
            return (List<T>)postalCodeEbos;
		}
		// otherwise, use the default implementation
		return super.getExternalizableBusinessObjectsListForLookup(externalizableBusinessObjectClassfieldValuesunbounded);
	}
    @Override
    protected String getInquiryUrl(Class inquiryBusinessObjectClass) {
        String riceBaseUrl = KRADServiceLocator.getKualiConfigurationService().getPropertyValueAsString(
                .);
        String inquiryUrl = riceBaseUrl;
        if (!inquiryUrl.endsWith("/")) {
            inquiryUrl = inquiryUrl + "/";
        }
        return inquiryUrl + .;
    }

    
    @Deprecated
    @Override
    public String getExternalizableBusinessObjectLookupUrl(Class inquiryBusinessObjectClass,
            Map<StringStringparameters) {
        Properties urlParameters = new Properties();
        String riceBaseUrl = KRADServiceLocator.getKualiConfigurationService().getPropertyValueAsString(
                .);
        String lookupUrl = riceBaseUrl;
        if (!lookupUrl.endsWith("/")) {
            lookupUrl = lookupUrl + "/";
        }
        if (parameters.containsKey(.)) {
            lookupUrl = lookupUrl + .;
        } else {
            lookupUrl = lookupUrl + .;
        }
        for (String paramName : parameters.keySet()) {
            urlParameters.put(paramNameparameters.get(paramName));
        }
        Class clazz = getExternalizableBusinessObjectImplementation(inquiryBusinessObjectClass);
        urlParameters.put(.clazz == null ? "" : clazz.getName());
        return UrlFactory.parameterizeUrl(lookupUrlurlParameters);
    }
    protected CampusService getCampusService() {
        if ( == null) {
             = LocationApiServiceLocator.getCampusService();
        }
        return ;
    }
    protected StateService getStateService() {
        if ( == null) {
             = LocationApiServiceLocator.getStateService();
        }
        return ;
    }
    protected CountryService getCountryService() {
        if ( == null) {
             = LocationApiServiceLocator.getCountryService();
        }
        return ;
    }
    protected CountyService getCountyService() {
        if ( == null) {
             = LocationApiServiceLocator.getCountyService();
        }
        return ;
    }
        if ( == null) {
             = LocationApiServiceLocator.getPostalCodeService();
        }
        return ;
    }
    private QueryByCriteria toQuery(Map<String,?> fieldValues) {
        Set<Predicatepreds = new HashSet<Predicate>();
        for (Map.Entry<String, ?> entry : fieldValues.entrySet()) {
            preds.add(equal(entry.getKey(), entry.getValue()));
        }
        Predicate[] predicates = new Predicate[0];
        predicates = preds.toArray(predicates);
        return QueryByCriteria.Builder.fromPredicates(predicates);
    }
New to GrepCode? Check out our FAQ X