001: //=============================================================================
002: //=== Copyright (C) 2001-2007 Food and Agriculture Organization of the
003: //=== United Nations (FAO-UN), United Nations World Food Programme (WFP)
004: //=== and United Nations Environment Programme (UNEP)
005: //===
006: //=== This program is free software; you can redistribute it and/or modify
007: //=== it under the terms of the GNU General Public License as published by
008: //=== the Free Software Foundation; either version 2 of the License, or (at
009: //=== your option) any later version.
010: //===
011: //=== This program is distributed in the hope that it will be useful, but
012: //=== WITHOUT ANY WARRANTY; without even the implied warranty of
013: //=== MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: //=== General Public License for more details.
015: //===
016: //=== You should have received a copy of the GNU General Public License
017: //=== along with this program; if not, write to the Free Software
018: //=== Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
019: //===
020: //=== Contact: Jeroen Ticheler - FAO - Viale delle Terme di Caracalla 2,
021: //=== Rome - Italy. email: geonetwork@osgeo.org
022: //==============================================================================
023:
024: package org.fao.geonet.services.thumbnail;
025:
026: import java.util.List;
027: import jeeves.interfaces.Service;
028: import jeeves.resources.dbms.Dbms;
029: import jeeves.server.ServiceConfig;
030: import jeeves.server.context.ServiceContext;
031: import jeeves.utils.Util;
032: import org.fao.geonet.GeonetContext;
033: import org.fao.geonet.constants.Geonet;
034: import org.fao.geonet.constants.Params;
035: import org.fao.geonet.kernel.DataManager;
036: import org.fao.geonet.services.metadata.Update;
037: import org.jdom.Element;
038:
039: //=============================================================================
040:
041: public class Get implements Service {
042: private Update update = new Update();
043:
044: //--------------------------------------------------------------------------
045: //---
046: //--- Init
047: //---
048: //--------------------------------------------------------------------------
049:
050: public void init(String appPath, ServiceConfig params)
051: throws Exception {
052: update.init(appPath, params);
053: }
054:
055: //--------------------------------------------------------------------------
056: //---
057: //--- Service
058: //---
059: //--------------------------------------------------------------------------
060:
061: public Element exec(Element params, ServiceContext context)
062: throws Exception {
063: //--- store changed fields if we arrive here from the editing form
064: //--- the update service uses the following parameters:
065: //--- id, data, validate, currTab, version
066:
067: if (saveEditData(params))
068: //--- data is not saved if someone else has changed the metadata
069: update.exec(params, context);
070:
071: GeonetContext gc = (GeonetContext) context
072: .getHandlerContext(Geonet.CONTEXT_NAME);
073:
074: DataManager dataMan = gc.getDataManager();
075:
076: Dbms dbms = (Dbms) context.getResourceManager().open(
077: Geonet.Res.MAIN_DB);
078:
079: String id = Util.getParam(params, Params.ID);
080:
081: //-----------------------------------------------------------------------
082: //--- get metadata
083:
084: Element result = dataMan.getThumbnails(dbms, id);
085:
086: if (result == null)
087: throw new IllegalArgumentException(
088: "Metadata not found --> " + id);
089:
090: result.addContent(new Element("version").setText(dataMan
091: .getNewVersion(id)));
092:
093: return result;
094: }
095:
096: //--------------------------------------------------------------------------
097: //---
098: //--- Private methods
099: //---
100: //--------------------------------------------------------------------------
101:
102: private boolean saveEditData(Element params) {
103: List list = params.getChildren();
104:
105: for (int i = 0; i < list.size(); i++) {
106: Element el = (Element) list.get(i);
107:
108: if (el.getName().startsWith("_"))
109: return true;
110: }
111:
112: return false;
113: }
114: }
115:
116: //=============================================================================
|