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.constants.Jeeves;
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 jeeves.utils.Xml;
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.ConcurrentUpdateEx;
037: import org.fao.geonet.kernel.AccessManager;
038: import org.fao.geonet.kernel.DataManager;
039: import org.jdom.Element;
040:
041: //=============================================================================
042:
043: /** For editing : update leaves information. Access is restricted
044: */
045:
046: public class Update implements Service {
047: private ServiceConfig config;
048:
049: //--------------------------------------------------------------------------
050: //---
051: //--- Init
052: //---
053: //--------------------------------------------------------------------------
054:
055: public void init(String appPath, ServiceConfig params)
056: throws Exception {
057: config = params;
058: }
059:
060: //--------------------------------------------------------------------------
061: //---
062: //--- Service
063: //---
064: //--------------------------------------------------------------------------
065:
066: public Element exec(Element params, ServiceContext context)
067: throws Exception {
068: EditUtils.preprocessUpdate(params, context);
069:
070: GeonetContext gc = (GeonetContext) context
071: .getHandlerContext(Geonet.CONTEXT_NAME);
072: DataManager dataMan = gc.getDataManager();
073:
074: Dbms dbms = (Dbms) context.getResourceManager().open(
075: Geonet.Res.MAIN_DB);
076:
077: String id = Util.getParam(params, Params.ID);
078: String version = Util.getParam(params, Params.VERSION);
079: String isTemplate = Util.getParam(params, Params.TEMPLATE, "n");
080: String title = params.getChildText(Params.TITLE);
081: String data = params.getChildText(Params.DATA);
082:
083: boolean validate = config.getValue(Params.VALIDATE, "no")
084: .equals("yes");
085:
086: if (data != null) {
087: Element md = Xml.loadString(data, false);
088:
089: if (!dataMan.updateMetadata(context.getUserSession(), dbms,
090: id, md, validate, version))
091: throw new ConcurrentUpdateEx(id);
092: } else
093: EditUtils.updateContent(params, context, validate);
094:
095: dataMan.setTemplate(dbms, Integer.parseInt(id), isTemplate,
096: title);
097:
098: //-----------------------------------------------------------------------
099: //--- update element and return status
100:
101: Element elResp = new Element(Jeeves.Elem.RESPONSE);
102: elResp.addContent(new Element(Geonet.Elem.ID).setText(id));
103: if (validate) {
104: Element schemaTronErrors = (Element) context
105: .getUserSession().getProperty("schematron_" + id);
106: if (schemaTronErrors != null) {
107: elResp.addContent(schemaTronErrors);
108: }
109: }
110:
111: return elResp;
112: }
113: }
114:
115: //=============================================================================
|