Package org.fao.geonet.services.region

Source Code of org.fao.geonet.services.region.List

//=============================================================================
//===  Copyright (C) 2001-2007 Food and Agriculture Organization of the
//===  United Nations (FAO-UN), United Nations World Food Programme (WFP)
//===  and United Nations Environment Programme (UNEP)
//===
//===  This program is free software; you can redistribute it and/or modify
//===  it under the terms of the GNU General Public License as published by
//===  the Free Software Foundation; either version 2 of the License, or (at
//===  your option) any later version.
//===
//===  This program is distributed in the hope that it will be useful, but
//===  WITHOUT ANY WARRANTY; without even the implied warranty of
//===  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
//===  General Public License for more details.
//===
//===  You should have received a copy of the GNU General Public License
//===  along with this program; if not, write to the Free Software
//===  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
//===
//===  Contact: Jeroen Ticheler - FAO - Viale delle Terme di Caracalla 2,
//===  Rome - Italy. email: geonetwork@osgeo.org
//==============================================================================

package org.fao.geonet.services.region;

import jeeves.interfaces.Service;
import jeeves.server.ServiceConfig;
import jeeves.server.context.ServiceContext;
import org.fao.geonet.Util;

import org.fao.geonet.kernel.region.RegionParams;
import org.fao.geonet.kernel.region.RegionsDAO;
import org.fao.geonet.kernel.region.Request;
import org.jdom.Element;

import java.util.Collection;

//=============================================================================

/**
* Returns a specific region and coordinates given its id
*/

public class List implements Service {

    public void init(String appPath, ServiceConfig params) throws Exception {
    }

    // --------------------------------------------------------------------------
    // ---
    // --- Service
    // ---
    // --------------------------------------------------------------------------

    public Element exec(Element params, ServiceContext context) throws Exception {
        String labelParam = Util.getParam(params, RegionParams.LABEL_SEARCH, null);
        String categoryIdParam = Util.getParam(params, RegionParams.CATEGORY_SEARCH, null);
        int maxRecordsParam = Util.getParam(params, RegionParams.MAX_RECORDS, -1);

        Collection<RegionsDAO> daos = context.getApplicationContext().getBeansOfType(RegionsDAO.class).values();
        Element regions = null;
        for (RegionsDAO dao : daos) {
            if (dao.includeInListing()) {
                Request request = dao.createSearchRequest(context);
                if (labelParam != null) {
                    request.label(labelParam);
                }
                if (categoryIdParam != null) {
                    request.categoryId(categoryIdParam);
                }
                if (maxRecordsParam > 0) {
                    request.maxRecords(maxRecordsParam);
                }
                Element tmp = request.xmlResult();
                if (regions != null) {
                    @SuppressWarnings("unchecked")
                    java.util.List<Element> children = tmp.getChildren();
                    for (Element element : children) {
                        regions.addContent(element);
                    }
                } else {
                    regions = tmp;
                }
            }
        }

        return regions;
    }

}

// =============================================================================
TOP

Related Classes of org.fao.geonet.services.region.List

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.