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.metadata;
025:
026: import jeeves.exceptions.MissingParameterEx;
027: import jeeves.interfaces.Service;
028: import jeeves.resources.dbms.Dbms;
029: import jeeves.server.ServiceConfig;
030: import jeeves.server.UserSession;
031: import jeeves.server.context.ServiceContext;
032: import jeeves.utils.Util;
033: import org.fao.geonet.GeonetContext;
034: import org.fao.geonet.constants.Geonet;
035: import org.fao.geonet.constants.Params;
036: import org.fao.geonet.exceptions.MetadataNotFoundEx;
037: import org.fao.geonet.kernel.AccessManager;
038: import org.fao.geonet.kernel.DataManager;
039: import org.fao.geonet.lib.Lib;
040: import org.jdom.Element;
041:
042: //=============================================================================
043:
044: /** Retrieves a particular metadata. Access is restricted
045: */
046:
047: public class Show implements Service {
048: //--------------------------------------------------------------------------
049: //---
050: //--- Init
051: //---
052: //--------------------------------------------------------------------------
053:
054: public void init(String appPath, ServiceConfig params)
055: throws Exception {
056: String skip = params.getValue("skipPopularity", "n");
057:
058: skipPopularity = skip.equals("y");
059: }
060:
061: //--------------------------------------------------------------------------
062: //---
063: //--- Service
064: //---
065: //--------------------------------------------------------------------------
066:
067: public Element exec(Element params, ServiceContext context)
068: throws Exception {
069: UserSession session = context.getUserSession();
070:
071: //-----------------------------------------------------------------------
072: //--- handle current tab
073:
074: Element elCurrTab = params.getChild(Params.CURRTAB);
075:
076: if (elCurrTab != null)
077: session.setProperty(Geonet.Session.METADATA_SHOW, elCurrTab
078: .getText());
079:
080: //-----------------------------------------------------------------------
081: //--- check access
082:
083: GeonetContext gc = (GeonetContext) context
084: .getHandlerContext(Geonet.CONTEXT_NAME);
085: DataManager dm = gc.getDataManager();
086:
087: // the metadata ID
088: String id;
089:
090: // does the request contain a UUID ?
091: try {
092: String uuid = Util.getParam(params, Params.UUID);
093: // lookup ID by UUID
094: id = dm.getMetadataId(context, uuid);
095: } catch (MissingParameterEx x) {
096: // request does not contain UUID; use ID from request
097: try {
098: id = Util.getParam(params, Params.ID);
099: }
100: // request does not contain ID
101: catch (MissingParameterEx xx) {
102: // give up
103: throw new Exception(
104: "Request must contain a UUID or an ID");
105: }
106: }
107:
108: Lib.resource.checkPrivilege(context, id,
109: AccessManager.OPER_VIEW);
110:
111: //-----------------------------------------------------------------------
112: //--- get metadata
113:
114: Element elMd = dm.getMetadata(context, id, false);
115:
116: if (elMd == null)
117: throw new MetadataNotFoundEx(id);
118:
119: //--- increase metadata popularity
120:
121: Dbms dbms = (Dbms) context.getResourceManager().open(
122: Geonet.Res.MAIN_DB);
123:
124: if (!skipPopularity)
125: dm.increasePopularity(dbms, id);
126:
127: return elMd;
128: }
129:
130: //--------------------------------------------------------------------------
131: //---
132: //--- Variables
133: //---
134: //--------------------------------------------------------------------------
135:
136: private boolean skipPopularity;
137: }
138:
139: //=============================================================================
|