001: //=============================================================================
002: //=== Copyright (C) 2001-2005 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
019: //===
020: //=== Contact: Jeroen Ticheler - FAO - Viale delle Terme di Caracalla 2,
021: //=== Rome - Italy. email: GeoNetwork@fao.org
022: //==============================================================================
023:
024: package org.fao.geonet.services.thesaurus;
025:
026: import jeeves.constants.Jeeves;
027: import jeeves.interfaces.Service;
028: import jeeves.server.ServiceConfig;
029: import jeeves.server.context.ServiceContext;
030: import jeeves.utils.Util;
031:
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.Thesaurus;
036: import org.fao.geonet.kernel.ThesaurusManager;
037: import org.jdom.Element;
038:
039: //=============================================================================
040:
041: /**
042: * Update the information of a thesaurus
043: */
044:
045: public class UpdateElement implements Service {
046: public void init(String appPath, ServiceConfig params)
047: throws Exception {
048: }
049:
050: // --------------------------------------------------------------------------
051: // ---
052: // --- Service
053: // ---
054: // --------------------------------------------------------------------------
055:
056: /*
057: * TODO
058: */
059: public Element exec(Element params, ServiceContext context)
060: throws Exception {
061: GeonetContext gc = (GeonetContext) context
062: .getHandlerContext(Geonet.CONTEXT_NAME);
063:
064: String ref = Util.getParam(params, Params.REF);
065: String oldid = Util.getParam(params, "oldid");
066: String newid = Util.getParam(params, "newid");
067: String namespace = Util.getParam(params, "namespace");
068: String thesaType = Util.getParam(params, "refType");
069: String prefLab = Util.getParam(params, "prefLab");
070: String lang = Util.getParam(params, "lang");
071: String definition = Util.getParam(params, "definition");
072:
073: ThesaurusManager manager = gc.getThesaurusManager();
074: Thesaurus thesaurus = manager.getThesaurusByName(ref);
075:
076: if (!(oldid.equals(newid))) {
077: if (thesaurus.isFreeCode(namespace, newid)) {
078: thesaurus.updateCode(namespace, oldid, newid);
079: } else {
080: Element elResp = new Element(Jeeves.Elem.RESPONSE);
081: elResp
082: .addContent(new Element("error")
083: .addContent(new Element("message")
084: .setText("Code value already exists in thesaurus")));
085: return elResp;
086: }
087: }
088:
089: if (thesaType.equals("place")) {
090: String east = Util.getParam(params, "east");
091: String west = Util.getParam(params, "west");
092: String south = Util.getParam(params, "south");
093: String north = Util.getParam(params, "north");
094: thesaurus.updateElement(namespace, newid, prefLab,
095: definition, east, west, south, north, lang);
096: } else {
097: thesaurus.updateElement(namespace, newid, prefLab,
098: definition, lang);
099: }
100:
101: Element elResp = new Element(Jeeves.Elem.RESPONSE);
102: elResp.addContent(new Element("selected").setText(ref));
103: elResp.addContent(new Element("mode").setText("edit"));
104: return elResp;
105: }
106: }
107:
108: // =============================================================================
|