source: main/trunk/greenstone3/src/java/org/greenstone/gsdl3/core/OAIMessageRouter.java@ 31915

Last change on this file since 31915 was 31915, checked in by ak19, 7 years ago

Dr Bainbridge thought about it and decided that the correct solution is that, since a collection will always have an oai-inf db from now on, the earliest datestamp of a collection should not fall back to either buildconfig's earliestdatestamp field or else buildconfig's lastmodified. However, the latter are used as the publishing date by the RSS service, and so still stored as Collection.java's earliestDatestamp. Now OAICollection has a new additional field, earliestOAIDatestamp which contains the earliest timestamp in oai-inf db. The OAIReceptionist now determines the earliestDatestamp of the entire OAIRepository solely based on the earliestOAIDatestamp values across all OAICollections, also with no fallbacks on Collections' earliestDatestamp or lastModified fields.

File size: 6.2 KB
Line 
1/*
2 * OAIMessageRouter.java
3 * Copyright (C) 2002 New Zealand Digital Library, http://www.nzdl.org
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 */
19package org.greenstone.gsdl3.core;
20
21import java.io.File;
22import java.net.Authenticator;
23import java.net.PasswordAuthentication;
24import java.util.HashMap;
25import java.util.Map;
26import java.util.Iterator;
27
28import org.apache.commons.lang3.StringUtils;
29import org.apache.log4j.Logger;
30import org.greenstone.gsdl3.collection.OAICollection;
31import org.greenstone.gsdl3.collection.ServiceCluster;
32import org.greenstone.gsdl3.comms.Communicator;
33import org.greenstone.gsdl3.comms.SOAPCommunicator;
34import org.greenstone.gsdl3.service.ServiceRack;
35import org.greenstone.gsdl3.util.GSFile;
36import org.greenstone.gsdl3.util.GSPath;
37import org.greenstone.gsdl3.util.GSXML;
38import org.greenstone.gsdl3.util.OAIXML;
39import org.greenstone.gsdl3.util.UserContext;
40import org.greenstone.gsdl3.util.XMLConverter;
41import org.greenstone.util.GlobalProperties;
42import org.w3c.dom.Document;
43import org.w3c.dom.Element;
44import org.w3c.dom.Node;
45import org.w3c.dom.NodeList;
46
47/**
48 * The hub of a Greenstone OAI server.
49 *
50 * A simplified version of MessageRouter for OAIServer. Only loads up collections that have OAI services.
51 */
52public class OAIMessageRouter extends MessageRouter
53{
54
55 static Logger logger = Logger.getLogger(org.greenstone.gsdl3.core.MessageRouter.class.getName());
56
57 public Element oai_config = null;
58 //***************************************************************
59 // public methods
60 //***************************************************************
61
62 /** constructor */
63 public OAIMessageRouter()
64 {
65 }
66
67 /**
68 * read thru own site config file - create services and connect to sites
69 */
70 protected boolean configureLocalSite()
71 {
72
73 // this may be a reconfigure, so clean up the old moduleMap
74 cleanUpModuleMapEntire();
75
76 // for oai, we don't do anything with the site config file. But we'll read it in and keep it in case need it later, eg for replace elements when retrieving metadata - which I don't think has been implemented
77 File configFile = new File(GSFile.siteConfigFile(this.site_home));
78
79 if (!configFile.exists())
80 {
81 logger.error(" site config file: " + configFile.getPath() + " not found!");
82 return false;
83 }
84
85 Document config_doc = XMLConverter.getDOM(configFile);
86 if (config_doc == null)
87 {
88 logger.error(" couldn't parse site config file: " + configFile.getPath());
89 return false;
90 }
91
92 this.config_info = config_doc.getDocumentElement();
93
94 // this is the receptionists OAIConfig.xml. Need to rethink how the MR gets this this if we ever talk to remote site, and whether it should be using it anyway
95 this.oai_config = OAIXML.getOAIConfigXML();
96 if (this.oai_config == null)
97 {
98 logger.error("Couldn't load in OAIConfig.xml");
99 return false;
100 }
101 Document doc = XMLConverter.newDOM();
102 // load up the collections
103 this.collection_list = doc.createElement(GSXML.COLLECTION_ELEM + GSXML.LIST_MODIFIER);
104 configureCollections();
105
106 return true;
107
108 }
109
110
111 /**
112 * creates and configures a new collection if this is done for a
113 * reconfigure, the collection should be deactivated first.
114 *
115 * @param col_name
116 * the name of the collection
117 * @return true if collection created ok
118 */
119 protected boolean activateCollectionByName(String col_name)
120 {
121
122 logger.info("Activating collection: " + col_name + ".");
123 Document doc = this.collection_list.getOwnerDocument();
124 // use our special OAICollection - this will only load in oai services
125 OAICollection c = new OAICollection();
126
127 c.setCollectionName(col_name);
128 c.setSiteHome(this.site_home);
129 c.setSiteAddress(this.site_http_address);
130 c.setMessageRouter(this);
131 if (!c.configure()) {
132 logger.error("Couldn't configure collection: " + col_name + ".");
133 return false;
134 }
135
136 logger.info("have just configured collection " + col_name);
137 if (!c.hasOAI()) {
138 logger.info ("collection "+col_name+" has no OAI services. Not keeping it loaded");
139 return false;
140 }
141 if (!c.configureOAI(this.oai_config)) {
142 logger.info("couldn't configure the collection : "+col_name +" with the oai config info");
143 return false;
144 }
145 // add to list of collections
146 this.module_map.put(col_name, c);
147 Element e = doc.createElement(GSXML.COLLECTION_ELEM);
148 e.setAttribute(GSXML.NAME_ATT, col_name);
149 e.setAttribute(OAIXML.LASTMODIFIED, "" + c.getLastmodified());
150 e.setAttribute(OAIXML.EARLIEST_DATESTAMP, "" + c.getEarliestDatestamp());
151 e.setAttribute(OAIXML.EARLIEST_OAI_DATESTAMP, "" + c.getEarliestOAIDatestamp());
152 this.collection_list.appendChild(e);
153 return true;
154
155 }
156
157
158
159 //*****************************************************************
160 // auxiliary process methods
161 //*****************************************************************
162
163 /**
164 * handles requests made to the MessageRouter itself
165 *
166 * @param req
167 * - the request Element- <request>
168 * @return the result Element - should be <response>
169 */
170 protected Element processMessage(Element req) {
171 Document doc = XMLConverter.newDOM();
172 String type = req.getAttribute(GSXML.TYPE_ATT);
173 Element response = doc.createElement(GSXML.RESPONSE_ELEM);
174 response.setAttribute(GSXML.FROM_ATT, "");
175
176 if (type.equals(OAIXML.OAI_SET_LIST))
177 {
178 logger.info("oaiSetList request received");
179 //this is the oai receptionist asking for a list of oai-support collections
180 response.setAttribute(GSXML.TYPE_ATT, OAIXML.OAI_SET_LIST);
181 response.appendChild(doc.importNode(this.collection_list, true));
182 return response;
183 }
184 return super.processMessage(req);
185 }
186
187
188}
Note: See TracBrowser for help on using the repository browser.