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 java.util.List;
027: import java.util.StringTokenizer;
028: import jeeves.constants.Jeeves;
029: import jeeves.interfaces.Service;
030: import jeeves.resources.dbms.Dbms;
031: import jeeves.server.ServiceConfig;
032: import jeeves.server.UserSession;
033: import jeeves.server.context.ServiceContext;
034: import jeeves.utils.Util;
035: import org.fao.geonet.GeonetContext;
036: import org.fao.geonet.constants.Geonet;
037: import org.fao.geonet.constants.Params;
038: import org.fao.geonet.exceptions.MetadataNotFoundEx;
039: import org.fao.geonet.kernel.DataManager;
040: import org.fao.geonet.kernel.MdInfo;
041: import org.jdom.Element;
042:
043: //=============================================================================
044:
045: /** Stores all operations allowed for a metadata. Called by the metadata.admin service
046: */
047:
048: public class UpdateAdminOper implements Service {
049: //--------------------------------------------------------------------------
050: //---
051: //--- Init
052: //---
053: //--------------------------------------------------------------------------
054:
055: public void init(String appPath, ServiceConfig params)
056: throws Exception {
057: }
058:
059: //--------------------------------------------------------------------------
060: //---
061: //--- Service
062: //---
063: //--------------------------------------------------------------------------
064:
065: public Element exec(Element params, ServiceContext context)
066: throws Exception {
067: GeonetContext gc = (GeonetContext) context
068: .getHandlerContext(Geonet.CONTEXT_NAME);
069: DataManager dm = gc.getDataManager();
070: UserSession us = context.getUserSession();
071:
072: Dbms dbms = (Dbms) context.getResourceManager().open(
073: Geonet.Res.MAIN_DB);
074:
075: String id = Util.getParam(params, Params.ID);
076:
077: //-----------------------------------------------------------------------
078: //--- check access
079:
080: MdInfo info = dm.getMetadataInfo(dbms, id);
081:
082: if (info == null)
083: throw new MetadataNotFoundEx(id);
084:
085: //-----------------------------------------------------------------------
086: //--- remove old operations
087:
088: boolean skip = false;
089:
090: //--- in case of owner, privileges for groups 0,1 are disabled and
091: //--- are not sent to the server. So we cannot remove them
092:
093: boolean isAdmin = Geonet.Profile.ADMINISTRATOR.equals(us
094: .getProfile());
095: boolean isReviewer = Geonet.Profile.REVIEWER.equals(us
096: .getProfile());
097:
098: if (us.getUserId().equals(info.owner) && !isAdmin
099: && !isReviewer)
100: skip = true;
101:
102: dm.deleteMetadataOper(dbms, id, skip);
103:
104: //-----------------------------------------------------------------------
105: //--- set new ones
106:
107: List list = params.getChildren();
108:
109: for (int i = 0; i < list.size(); i++) {
110: Element el = (Element) list.get(i);
111:
112: String name = el.getName();
113:
114: if (name.startsWith("_")) {
115: StringTokenizer st = new StringTokenizer(name, "_");
116:
117: String groupId = st.nextToken();
118: String operId = st.nextToken();
119:
120: dm.setOperation(dbms, id, groupId, operId);
121: }
122: }
123:
124: //-----------------------------------------------------------------------
125: //--- index metadata
126:
127: dm.indexMetadata(dbms, id);
128:
129: //-----------------------------------------------------------------------
130: //--- return id for showing
131:
132: return new Element(Jeeves.Elem.RESPONSE)
133: .addContent(new Element(Geonet.Elem.ID).setText(id));
134: }
135: }
136:
137: //=============================================================================
|