[GeoNetwork-devel] [GeoNetwork-commit] SF.net SVN: geonetwork: [1187] trunk/src/org/fao/geonet

Hi Jeroen, that's useful to get the metadata based on the uuid.

The change is using the DB to search for the uuid. And the uuid is also
indexed by lucene.

Could we have in some configuration (harvesting? gast import/export?
migration), a uuid in the xml different from the uuid in the metadata
table ?

Francois

ticheler@anonymised.com wrote:

Revision: 1187
          http://geonetwork.svn.sourceforge.net/geonetwork/?rev=1187&view=rev
Author: ticheler
Date: 2008-03-05 07:59:04 -0800 (Wed, 05 Mar 2008)

Log Message:
-----------
Added the option to retrieve metadata records based on the uuid (using the uuid as parameter on metadata.show)

Modified Paths:
--------------
    trunk/src/org/fao/geonet/kernel/DataManager.java
    trunk/src/org/fao/geonet/services/metadata/Show.java

Modified: trunk/src/org/fao/geonet/kernel/DataManager.java

--- trunk/src/org/fao/geonet/kernel/DataManager.java 2008-03-04 16:10:10 UTC (rev 1186)
+++ trunk/src/org/fao/geonet/kernel/DataManager.java 2008-03-05 15:59:04 UTC (rev 1187)
@@ -480,7 +480,19 @@

     return record.getChildText("id");
   }
+
+ //--------------------------------------------------------------------------

+ public String getMetadataId(ServiceContext srvContext, String uuid) throws Exception {
+ Dbms dbms = (Dbms) srvContext.getResourceManager().open(Geonet.Res.MAIN_DB);
+ String query = "SELECT id FROM Metadata WHERE uuid=?";
+ List list = dbms.select(query, uuid).getChildren();
+ if (list.size() == 0)
+ return null;
+ Element record = (Element) list.get(0);
+ return record.getChildText("id");
+ }
+
   //--------------------------------------------------------------------------

   public String getMetadataUuid(Dbms dbms, String id) throws Exception

Modified: trunk/src/org/fao/geonet/services/metadata/Show.java

--- trunk/src/org/fao/geonet/services/metadata/Show.java 2008-03-04 16:10:10 UTC (rev 1186)
+++ trunk/src/org/fao/geonet/services/metadata/Show.java 2008-03-05 15:59:04 UTC (rev 1187)
@@ -23,6 +23,7 @@

package org.fao.geonet.services.metadata;

+import jeeves.exceptions.MissingParameterEx;
import jeeves.interfaces.Service;
import jeeves.resources.dbms.Dbms;
import jeeves.server.ServiceConfig;
@@ -82,13 +83,32 @@
     GeonetContext gc = (GeonetContext) context.getHandlerContext(Geonet.CONTEXT_NAME);
     DataManager dm = gc.getDataManager();

- String id = Util.getParam(params, Params.ID);
-
+ // the metadata ID
+ String id;
+
+ // does the request contain a UUID ?
+ try {
+ String uuid = Util.getParam(params, Params.UUID);
+ // lookup ID by UUID
+ id = dm.getMetadataId(context, uuid);
+ }
+ catch(MissingParameterEx x) {
+ // request does not contain UUID; use ID from request
+ try {
+ id = Util.getParam(params, Params.ID);
+ }
+ // request does not contain ID
+ catch(MissingParameterEx xx) {
+ // give up
+ throw new Exception("Request must contain a UUID or an ID");
+ }
+ }
+
     Lib.resource.checkPrivilege(context, id, AccessManager.OPER_VIEW);

     //-----------------------------------------------------------------------
     //--- get metadata
-
+
     Element elMd = dm.getMetadata(context, id, false);

     if (elMd == null)

This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.

-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
GeoNetwork-commit mailing list
GeoNetwork-commit@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/geonetwork-commit

Hi Francois,
Good question! I'm sure that there could be cases where the indexes are messed up and thus indexes could be misaligned with respect to the metadata in the database. However, it is unlikely to happen unnoticed (probably someone forced metadata straight into the metadata table instead of through the appropriate services) and would require a rebuilding of the indexes.
I don't think that UUID in metadata and in the table could be different, as long as GN is aware of the schema and of where it is supposed to extract the UUID to insert into the table. Harvesting, gast import/export and migration all extract the UUID from metadata and insert it in the table, or a UUID is generated and inserted in both metadata and table.
(I could us use the Lucene index to match the UUID with the local ID, but that's not really the issue here and more of an implementation choice).
Ciao,
Jeroen

On Mar 5, 2008, at 5:23 PM, Francois-Xavier Prunayre wrote:

Hi Jeroen, that's useful to get the metadata based on the uuid.

The change is using the DB to search for the uuid. And the uuid is also
indexed by lucene.

Could we have in some configuration (harvesting? gast import/export?
migration), a uuid in the xml different from the uuid in the metadata
table ?

Francois

Hi, I asked the question because when linking metadata for services and
metadata for data, I had to make a link between the two using the
OperatesOn tag :
* uuid attribute was fine
* but I also made and xlink using internal id and using uuid instead
will be better.

<srv:operatesOn>
        <gmd:MD_DataIdentification uuid='xyz'
xlink:href="http://mygeonetwork/geonetwork/srv/en/metadata.show?id=15&quot;
xlink:title="Layer title"/>
</srv:operatesOn>

<srv:operatesOn>
        <gmd:MD_DataIdentification uuid='xyz'
xlink:href="http://mygeonetwork/geonetwork/srv/en/metadata.show?uuid=xyz&quot;
xlink:title="Layer title"/>
</srv:operatesOn>

Jeroen Ticheler wrote:

Hi Francois,
Good question! I'm sure that there could be cases where the indexes are
messed up and thus indexes could be misaligned with respect to the
metadata in the database. However, it is unlikely to happen unnoticed
(probably someone forced metadata straight into the metadata table
instead of through the appropriate services) and would require a
rebuilding of the indexes.

I've set up a "force rebuild lucene index" button from the admin
interface in one project, so users don't have to stop jetty, remove
lucene to eventually overwrite the lucene index. That could be added?

Francois

I don't think that UUID in metadata and in the table could be different,
as long as GN is aware of the schema and of where it is supposed to
extract the UUID to insert into the table. Harvesting, gast
import/export and migration all extract the UUID from metadata and
insert it in the table, or a UUID is generated and inserted in both
metadata and table.
(I could us use the Lucene index to match the UUID with the local ID,
but that's not really the issue here and more of an implementation choice).
Ciao,
Jeroen

On Mar 5, 2008, at 5:23 PM, Francois-Xavier Prunayre wrote:

Hi Jeroen, that's useful to get the metadata based on the uuid.

The change is using the DB to search for the uuid. And the uuid is also
indexed by lucene.

Could we have in some configuration (harvesting? gast import/export?
migration), a uuid in the xml different from the uuid in the metadata
table ?

Francois