01: //=============================================================================
02: //=== Copyright (C) 2001-2007 Food and Agriculture Organization of the
03: //=== United Nations (FAO-UN), United Nations World Food Programme (WFP)
04: //=== and United Nations Environment Programme (UNEP)
05: //===
06: //=== This program is free software; you can redistribute it and/or modify
07: //=== it under the terms of the GNU General Public License as published by
08: //=== the Free Software Foundation; either version 2 of the License, or (at
09: //=== your option) any later version.
10: //===
11: //=== This program is distributed in the hope that it will be useful, but
12: //=== WITHOUT ANY WARRANTY; without even the implied warranty of
13: //=== MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14: //=== General Public License for more details.
15: //===
16: //=== You should have received a copy of the GNU General Public License
17: //=== along with this program; if not, write to the Free Software
18: //=== Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19: //===
20: //=== Contact: Jeroen Ticheler - FAO - Viale delle Terme di Caracalla 2,
21: //=== Rome - Italy. email: geonetwork@osgeo.org
22: //==============================================================================
23:
24: package org.fao.geonet.kernel.oaipmh.services;
25:
26: import java.util.List;
27: import jeeves.constants.Jeeves;
28: import jeeves.resources.dbms.Dbms;
29: import jeeves.server.context.ServiceContext;
30: import org.fao.geonet.constants.Geonet;
31: import org.fao.geonet.kernel.oaipmh.OaiPmhService;
32: import org.fao.geonet.kernel.setting.SettingInfo;
33: import org.fao.geonet.util.ISODate;
34: import org.fao.oaipmh.requests.AbstractRequest;
35: import org.fao.oaipmh.requests.IdentifyRequest;
36: import org.fao.oaipmh.responses.AbstractResponse;
37: import org.fao.oaipmh.responses.IdentifyResponse;
38: import org.fao.oaipmh.responses.IdentifyResponse.DeletedRecord;
39: import org.fao.oaipmh.responses.IdentifyResponse.Granularity;
40: import org.jdom.Element;
41:
42: //=============================================================================
43:
44: public class Identify implements OaiPmhService {
45: public String getVerb() {
46: return IdentifyRequest.VERB;
47: }
48:
49: //---------------------------------------------------------------------------
50: //---
51: //--- Service
52: //---
53: //---------------------------------------------------------------------------
54:
55: public AbstractResponse execute(AbstractRequest request,
56: ServiceContext context) throws Exception {
57: IdentifyResponse res = new IdentifyResponse();
58: SettingInfo si = new SettingInfo(context);
59:
60: String baseUrl = si.getSiteUrl() + context.getBaseUrl() + "/"
61: + Jeeves.Prefix.SERVICE + "/en/" + context.getService();
62:
63: res.setRepositoryName(si.getSiteName());
64: res.setBaseUrl(baseUrl);
65: res.setEarliestDateStamp(getEarliestDS(context));
66: res.setDeletedRecord(DeletedRecord.NO);
67: res.setGranularity(Granularity.LONG);
68: res.addAdminEmail(si.getFeedbackEmail());
69:
70: return res;
71: }
72:
73: //---------------------------------------------------------------------------
74:
75: private ISODate getEarliestDS(ServiceContext context)
76: throws Exception {
77: Dbms dbms = (Dbms) context.getResourceManager().open(
78: Geonet.Res.MAIN_DB);
79:
80: String query = "SELECT min(changeDate) as mcd FROM Metadata";
81:
82: List list = dbms.select(query).getChildren();
83:
84: //--- if we don't have metadata, just return 'now'
85: if (list.size() == 0)
86: return new ISODate();
87:
88: Element rec = (Element) list.get(0);
89:
90: return new ISODate(rec.getChildText("mcd"));
91: }
92: }
93:
94: //=============================================================================
|