From: <tic...@us...> - 2008-02-21 15:16:11
|
Revision: 1129 http://geonetwork.svn.sourceforge.net/geonetwork/?rev=1129&view=rev Author: ticheler Date: 2008-02-21 07:16:15 -0800 (Thu, 21 Feb 2008) Log Message: ----------- Add and remove parent - child relations between metadata records. (No GUI is provided with this service and the functionality relates to the already existing xml.relation.get search function) Modified Paths: -------------- branches/2.2.x/src/org/fao/geonet/constants/Params.java branches/2.2.x/web/geonetwork/WEB-INF/config.xml branches/2.2.x/web/geonetwork/xml/user-profiles.xml Added Paths: ----------- branches/2.2.x/src/org/fao/geonet/services/relations/Insert.java branches/2.2.x/src/org/fao/geonet/services/relations/Remove.java Modified: branches/2.2.x/src/org/fao/geonet/constants/Params.java =================================================================== --- branches/2.2.x/src/org/fao/geonet/constants/Params.java 2008-02-21 15:14:47 UTC (rev 1128) +++ branches/2.2.x/src/org/fao/geonet/constants/Params.java 2008-02-21 15:16:15 UTC (rev 1129) @@ -44,6 +44,8 @@ public static final String GROUP = "group"; public static final String GROUPS = "groups"; public static final String ID = "id"; + public static final String PARENT_ID = "parentId"; + public static final String CHILD_ID = "childId"; public static final String UUID = "uuid"; public static final String URI = "uri"; public static final String NAME = "name"; Added: branches/2.2.x/src/org/fao/geonet/services/relations/Insert.java =================================================================== --- branches/2.2.x/src/org/fao/geonet/services/relations/Insert.java (rev 0) +++ branches/2.2.x/src/org/fao/geonet/services/relations/Insert.java 2008-02-21 15:16:15 UTC (rev 1129) @@ -0,0 +1,85 @@ +//============================================================================= +//=== Copyright (C) 2001-2007 Food and Agriculture Organization of the +//=== United Nations (FAO-UN), United Nations World Food Programme (WFP) +//=== and United Nations Environment Programme (UNEP) +//=== +//=== This program is free software; you can redistribute it and/or modify +//=== it under the terms of the GNU General Public License as published by +//=== the Free Software Foundation; either version 2 of the License, or (at +//=== your option) any later version. +//=== +//=== This program is distributed in the hope that it will be useful, but +//=== WITHOUT ANY WARRANTY; without even the implied warranty of +//=== MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +//=== General Public License for more details. +//=== +//=== You should have received a copy of the GNU General Public License +//=== along with this program; if not, write to the Free Software +//=== Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA +//=== +//=== Contact: Jeroen Ticheler - FAO - Viale delle Terme di Caracalla 2, +//=== Rome - Italy. email: geo...@os... +//============================================================================== + +package org.fao.geonet.services.relations; + +import jeeves.constants.Jeeves; +import jeeves.interfaces.Service; +import jeeves.resources.dbms.Dbms; +import jeeves.server.ServiceConfig; +import jeeves.server.context.ServiceContext; +import jeeves.utils.Util; +import org.fao.geonet.constants.Geonet; +import org.fao.geonet.constants.Params; +import org.jdom.Element; + +//============================================================================= + +/** Insert the relation between two metadata records + * + */ + +public class Insert implements Service +{ + //-------------------------------------------------------------------------- + //--- + //--- Init + //--- + //-------------------------------------------------------------------------- + + public void init(String appPath, ServiceConfig params) throws Exception {} + + //-------------------------------------------------------------------------- + //--- + //--- Service + //--- + //-------------------------------------------------------------------------- + + + /* Insert the relation between two metadata records + * @see jeeves.interfaces.Service#exec(org.jdom.Element, jeeves.server.context.ServiceContext) + * Parameter name: parentId - Parent metadata identifier + * Parameter name: childId - Child metadata identifier + */ + public Element exec(Element params, ServiceContext context) throws Exception + { + int parentId = Util.getParamAsInt(params, Params.PARENT_ID); + int childId = Util.getParamAsInt(params, Params.CHILD_ID); + + Dbms dbms = (Dbms) context.getResourceManager().open (Geonet.Res.MAIN_DB); + + // Add new relation + String query = "INSERT INTO Relations (id, relatedId) "+"VALUES (?, ?)"; + + dbms.execute(query, parentId, childId); + + Element response = new Element(Jeeves.Elem.RESPONSE) + .addContent(new Element("parentId").setText(String.valueOf(parentId))) + .addContent(new Element("childId").setText(String.valueOf(childId))); + + return response; + } +} + +//============================================================================= + Added: branches/2.2.x/src/org/fao/geonet/services/relations/Remove.java =================================================================== --- branches/2.2.x/src/org/fao/geonet/services/relations/Remove.java (rev 0) +++ branches/2.2.x/src/org/fao/geonet/services/relations/Remove.java 2008-02-21 15:16:15 UTC (rev 1129) @@ -0,0 +1,73 @@ +//============================================================================= +//=== Copyright (C) 2001-2007 Food and Agriculture Organization of the +//=== United Nations (FAO-UN), United Nations World Food Programme (WFP) +//=== and United Nations Environment Programme (UNEP) +//=== +//=== This program is free software; you can redistribute it and/or modify +//=== it under the terms of the GNU General Public License as published by +//=== the Free Software Foundation; either version 2 of the License, or (at +//=== your option) any later version. +//=== +//=== This program is distributed in the hope that it will be useful, but +//=== WITHOUT ANY WARRANTY; without even the implied warranty of +//=== MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +//=== General Public License for more details. +//=== +//=== You should have received a copy of the GNU General Public License +//=== along with this program; if not, write to the Free Software +//=== Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA +//=== +//=== Contact: Jeroen Ticheler - FAO - Viale delle Terme di Caracalla 2, +//=== Rome - Italy. email: geo...@os... +//============================================================================== + +package org.fao.geonet.services.relations; + +import org.jdom.*; + +import jeeves.constants.*; +import jeeves.interfaces.*; +import jeeves.resources.dbms.*; +import jeeves.server.*; +import jeeves.server.context.*; +import jeeves.utils.*; + +import org.fao.geonet.constants.*; + +//============================================================================= + +/** Removes a user from the system. It removes the relationship to a group too + */ + +public class Remove implements Service +{ + //-------------------------------------------------------------------------- + //--- + //--- Init + //--- + //-------------------------------------------------------------------------- + + public void init(String appPath, ServiceConfig params) throws Exception {} + + //-------------------------------------------------------------------------- + //--- + //--- Service to delete a related resource + //--- + //-------------------------------------------------------------------------- + + public Element exec(Element params, ServiceContext context) throws Exception + { + int parentId = Util.getParamAsInt(params, Params.PARENT_ID); + int childId = Util.getParamAsInt(params, Params.CHILD_ID); + + Dbms dbms = (Dbms) context.getResourceManager().open (Geonet.Res.MAIN_DB); + + dbms.execute ("DELETE FROM Relations WHERE id=" + String.valueOf(parentId) + + " AND relatedId=" + String.valueOf(childId)); + + return new Element(Jeeves.Elem.RESPONSE); + } +} + +//============================================================================= + Modified: branches/2.2.x/web/geonetwork/WEB-INF/config.xml =================================================================== --- branches/2.2.x/web/geonetwork/WEB-INF/config.xml 2008-02-21 15:14:47 UTC (rev 1128) +++ branches/2.2.x/web/geonetwork/WEB-INF/config.xml 2008-02-21 15:16:15 UTC (rev 1129) @@ -773,6 +773,20 @@ </output> </service> + <service name="xml.relation.insert"> + <class name=".services.relations.Insert" /> + <error id="insert" sheet="error.xsl"> + <xml name="error" file="xml/error.xml" /> + </error> + </service> + + <service name="xml.relation.delete"> + <class name=".services.relations.Remove" /> + <error id="delete" sheet="error.xsl"> + <xml name="error" file="xml/error.xml" /> + </error> + </service> + <!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - --> <!-- Thesaurus services --> <!-- Search Keywords services --> Modified: branches/2.2.x/web/geonetwork/xml/user-profiles.xml =================================================================== --- branches/2.2.x/web/geonetwork/xml/user-profiles.xml 2008-02-21 15:14:47 UTC (rev 1128) +++ branches/2.2.x/web/geonetwork/xml/user-profiles.xml 2008-02-21 15:16:15 UTC (rev 1129) @@ -152,6 +152,10 @@ <!-- MEF facilities --> <allow service="mef.import"/> + <!-- Relation services --> + <allow service="xml.relation.insert"/> + <allow service="xml.relation.delete"/> + </profile> <!-- ====================================================================== --> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |