Project

General

Profile

« Previous | Next » 

Revision 34424

[maven-release-plugin] copy for tag cnr-data-information-oai-publisher-common-5.0.2

View differences:

modules/cnr-data-information-oai-publisher-common/tags/cnr-data-information-oai-publisher-common-5.0.2/deploy.info
1
{"type_source": "SVN", "goal": "package -U -T 4C source:jar", "url": "http://svn-public.driver.research-infrastructures.eu/driver/dnet40/modules/cnr-data-information-oai-publisher-common/trunk/", "deploy_repository": "dnet4-snapshots", "version": "4", "mail": "sandro.labruzzo@isti.cnr.it,michele.artini@isti.cnr.it, claudio.atzori@isti.cnr.it, alessia.bardi@isti.cnr.it", "deploy_repository_url": "http://maven.research-infrastructures.eu/nexus/content/repositories/dnet4-snapshots", "name": "cnr-data-information-oai-publisher-common"}
modules/cnr-data-information-oai-publisher-common/tags/cnr-data-information-oai-publisher-common-5.0.2/src/main/java/eu/dnetlib/data/information/oai/publisher/OAIProperties.java
1
package eu.dnetlib.data.information.oai.publisher;
2

  
3
import eu.dnetlib.data.information.oai.publisher.OAIController.DELETED_SUPPORT;
4

  
5
public class OAIProperties {
6

  
7
	/**
8
	 * forwarded url header name, default "X-Forwarded-Url".
9
	 */
10
	private String forwardedUrlHeaderName = "X-Forwarded-Url";
11

  
12
	/**
13
	 * optional base url. If present it overrides the X-Forwarded-Url.
14
	 */
15
	private String baseUrl;
16
	private String repoName = "Driver Service for supporting Open Archive Initiative requests";
17
	private String repoEmail = "artini@isti.cnr.it";
18
	private String earliestDatestamp = "1970-01-01";
19
	private DELETED_SUPPORT deletedRecordSupport;
20
	private String dateGranularity = "YYYY-MM-DD";
21

  
22
	public String getBaseUrl() {
23
		return baseUrl;
24
	}
25

  
26
	public void setBaseUrl(String baseUrl) {
27
		this.baseUrl = baseUrl;
28
	}
29

  
30
	public String getRepoName() {
31
		return repoName;
32
	}
33

  
34
	public void setRepoName(String repoName) {
35
		this.repoName = repoName;
36
	}
37

  
38
	public String getRepoEmail() {
39
		return repoEmail;
40
	}
41

  
42
	public void setRepoEmail(String repoEmail) {
43
		this.repoEmail = repoEmail;
44
	}
45

  
46
	public String getEarliestDatestamp() {
47
		return earliestDatestamp;
48
	}
49

  
50
	public void setEarliestDatestamp(String earliestDatestamp) {
51
		this.earliestDatestamp = earliestDatestamp;
52
	}
53

  
54
	public String getDeletedRecordSupport() {
55
		return deletedRecordSupport.toString();
56
	}
57

  
58
	public void setDeletedRecordSupport(String deletedRecordSupport) {
59
		this.deletedRecordSupport = DELETED_SUPPORT.valueOf(deletedRecordSupport.trim().toUpperCase());
60
	}
61

  
62
	public String getDateGranularity() {
63
		return dateGranularity;
64
	}
65

  
66
	public void setDateGranularity(String dateGranularity) {
67
		this.dateGranularity = dateGranularity;
68
	}
69

  
70
	public String getForwardedUrlHeaderName() {
71
		return forwardedUrlHeaderName;
72
	}
73

  
74
	public void setForwardedUrlHeaderName(String forwardedUrlHeaderName) {
75
		this.forwardedUrlHeaderName = forwardedUrlHeaderName;
76
	}
77

  
78
}
modules/cnr-data-information-oai-publisher-common/tags/cnr-data-information-oai-publisher-common-5.0.2/src/main/java/eu/dnetlib/data/information/oai/publisher/OaiPublisherException.java
1
package eu.dnetlib.data.information.oai.publisher;
2

  
3
import javax.xml.ws.WebFault;
4

  
5
import eu.dnetlib.common.rmi.RMIException;
6

  
7
/**
8
 * OAI publisher specific exception.
9
 * 
10
 * @author michele
11
 * 
12
 */
13
@WebFault
14
public class OaiPublisherException extends RMIException {
15

  
16
	/**
17
	 * serialization.
18
	 */
19
	private static final long serialVersionUID = 6833698764790681184L;
20

  
21
	/**
22
	 * Creates an exception.
23
	 * 
24
	 * @param e
25
	 *            exception
26
	 */
27
	public OaiPublisherException(final Throwable e) {
28
		super(e);
29
	}
30

  
31
	/**
32
	 * Creates an exception.
33
	 * 
34
	 * @param message
35
	 *            message
36
	 * @param e
37
	 *            exception
38
	 */
39
	public OaiPublisherException(final String message, final Throwable e) {
40
		super(message, e);
41
	}
42

  
43
	/**
44
	 * Creates an exception.
45
	 * 
46
	 * @param message
47
	 *            message
48
	 */
49
	public OaiPublisherException(final String message) {
50
		super(message);
51
	}
52

  
53
}
modules/cnr-data-information-oai-publisher-common/tags/cnr-data-information-oai-publisher-common-5.0.2/src/main/java/eu/dnetlib/data/information/oai/publisher/core/AbstractOAICore.java
1
package eu.dnetlib.data.information.oai.publisher.core;
2

  
3
import java.util.List;
4

  
5
import javax.annotation.Resource;
6

  
7
import org.apache.commons.lang.StringUtils;
8
import org.apache.commons.logging.Log;
9
import org.apache.commons.logging.LogFactory;
10
import org.springframework.beans.factory.annotation.Autowired;
11

  
12
import eu.dnetlib.data.information.oai.publisher.CannotDisseminateFormatException;
13
import eu.dnetlib.data.information.oai.publisher.OaiPublisherException;
14
import eu.dnetlib.data.information.oai.publisher.conf.ISLookUpClient;
15
import eu.dnetlib.data.information.oai.publisher.conf.OAIConfigurationExistReader;
16
import eu.dnetlib.data.information.oai.publisher.info.ListDocumentsInfo;
17
import eu.dnetlib.data.information.oai.publisher.info.ListRecordsInfo;
18
import eu.dnetlib.data.information.oai.publisher.info.MDFInfo;
19
import eu.dnetlib.data.information.oai.publisher.info.RecordInfo;
20
import eu.dnetlib.data.information.oai.publisher.info.ResumptionToken;
21
import eu.dnetlib.data.information.oai.publisher.info.SetInfo;
22
import eu.dnetlib.data.information.oai.sets.SetCollection;
23
import eu.dnetlib.miscutils.cache.EhCache;
24

  
25
/**
26
 * Core OAI servlet implementation.
27
 * 
28
 * @author michele,alessia
29
 * 
30
 */
31

  
32
public abstract class AbstractOAICore {
33

  
34
	private static final Log log = LogFactory.getLog(AbstractOAICore.class); // NOPMD by marko on 11/24/08 5:02 PM
35

  
36
	private String currentDBName;
37

  
38
	@Autowired
39
	private SetCollection setCollection;
40

  
41
	@Autowired
42
	private OAIConfigurationExistReader oaiConfigurationExistReader;
43

  
44
	@Autowired
45
	private ISLookUpClient lookupClient;
46

  
47
	@Resource
48
	private EhCache<String, MDFInfo> mdFormatsCache;
49

  
50
	/**
51
	 * page size.
52
	 */
53
	protected int pageSize = 100;
54

  
55
	/**
56
	 * Returns informations about a record. It contains basic information about a record, such as "prefix", "identifier", "datestamp",
57
	 * "setspec", "metadata".
58
	 * 
59
	 * @param identifier
60
	 *            record identifier
61
	 * @param prefix
62
	 *            metadata prefix
63
	 * @return a recordInfo instance
64
	 * @throws OaiPublisherException
65
	 *             could happen
66
	 */
67
	public RecordInfo getInfoRecord(final String identifier, final String prefix) throws OaiPublisherException {
68
		MDFInfo mdf = obtainMDFInfo(prefix);
69
		return getRecordById(mdf, identifier);
70
	}
71

  
72
	/**
73
	 * List records.
74
	 * 
75
	 * @param onlyIdentifiers
76
	 *            only return record identifiers
77
	 * @param metadataPrefix
78
	 *            metadata prefix
79
	 * @param set
80
	 *            set name
81
	 * @param from
82
	 *            from date
83
	 * @param until
84
	 *            to date
85
	 * @return ListRecordsInfo
86
	 * @throws OaiPublisherException
87
	 *             could happen
88
	 */
89
	public ListRecordsInfo listRecords(final boolean onlyIdentifiers, final String metadataPrefix, final String set, final String from, final String until)
90
			throws OaiPublisherException {
91
		final ListRecordsInfo res = new ListRecordsInfo();
92

  
93
		if (from != null) {
94
			res.setFrom(from);
95
			res.setWithSize(false);
96
		}
97
		if (until != null) {
98
			res.setUntil(until);
99
			res.setWithSize(false);
100
		}
101
		if (metadataPrefix != null) {
102
			res.setMetadataprefix(metadataPrefix);
103
		}
104
		if (set != null) {
105
			res.setSet(set);
106
		}
107

  
108
		ListDocumentsInfo documents = getDocuments(onlyIdentifiers, set, metadataPrefix, from, until);
109
		ResumptionToken resumptionToken = documents.getResumptionToken();
110
		int cursor = documents.getCursor();
111
		int nMaxElements = documents.getnMaxElements();
112

  
113
		if (onlyIdentifiers) {
114
			res.setIdentifiers(documents.getDocs());
115
		} else {
116
			res.setDocuments(documents.getDocs());
117
		}
118

  
119
		if ((resumptionToken != null)) {
120
			res.setResumptiontoken(resumptionToken.serialize());
121
			res.setCursor(cursor);
122
			res.setSize(nMaxElements);
123
		}
124
		return res;
125
	}
126

  
127
	/**
128
	 * List records.
129
	 * 
130
	 * @param onlyIdentifiers
131
	 *            only resource identifiers.
132
	 * @param resumptionTokenParameter
133
	 *            resumption token
134
	 * @return ListRecordsInfo
135
	 * @throws OaiPublisherException
136
	 *             could happen
137
	 */
138
	public ListRecordsInfo listRecords(final boolean onlyIdentifiers, final String resumptionToken) throws OaiPublisherException {
139
		ListDocumentsInfo docs = getDocuments(onlyIdentifiers, resumptionToken);
140

  
141
		final ListRecordsInfo res = new ListRecordsInfo();
142

  
143
		if (docs.getMetadataPrefix() != null) {
144
			res.setMetadataprefix(docs.getMetadataPrefix());
145
		}
146

  
147
		if (onlyIdentifiers) {
148
			res.setIdentifiers(docs.getDocs());
149
		} else {
150
			res.setDocuments(docs.getDocs());
151
		}
152

  
153
		ResumptionToken newResumptionToken = docs.getResumptionToken();
154
		if ((newResumptionToken != null)) {
155
			res.setResumptiontoken(newResumptionToken.serialize());
156
			res.setCursor(docs.getCursor());
157
			res.setSize(docs.getnMaxElements());
158
			res.setWithSize(!newResumptionToken.hasDateRange());
159
		}
160
		return res;
161
	}
162

  
163
	public List<? extends SetInfo> listSets() throws OaiPublisherException {
164
		return this.setCollection.getAllSets(true, getCurrentDBName());
165
	}
166

  
167
	public List<MDFInfo> listMetadataFormats() throws OaiPublisherException {
168
		return this.oaiConfigurationExistReader.getMetadataFormatInfo(true);
169
	}
170

  
171
	public boolean existSet(final String setSpec) {
172
		return this.setCollection.containEnabledSet(setSpec, getCurrentDBName());
173
	}
174

  
175
	protected MDFInfo obtainMDFInfo(final String metadataPrefix) throws OaiPublisherException {
176
		MDFInfo mdf = this.mdFormatsCache.get(metadataPrefix);
177
		if (mdf == null) {
178
			log.fatal("Not using cache for " + metadataPrefix);
179
			mdf = oaiConfigurationExistReader.getMetadataFormatInfo(metadataPrefix);
180
			if (mdf == null) throw new CannotDisseminateFormatException("Invalid metadataPrefix " + metadataPrefix);
181
			this.mdFormatsCache.put(metadataPrefix, mdf);
182
		}
183
		return mdf;
184
	}
185

  
186
	/**
187
	 * Set the current DB from the configuration on the IS.
188
	 * <p>
189
	 * If force is false, the value is updated only if blank
190
	 * 
191
	 * @param force
192
	 *            true to update the currentDB when the current value is not blank
193
	 * @throws OaiPublisherException
194
	 */
195
	public void setCurrentDBFromIS(final boolean force) throws OaiPublisherException {
196
		try {
197
			if (force || StringUtils.isBlank(currentDBName)) {
198
				currentDBName = getLookupClient().getCurrentDB();
199
				log.fatal("Set " + currentDBName + " as current DB");
200
			}
201
		} catch (Exception e) {
202
			log.error("Can't set the current db for OAI, check configuration");
203
			throw new OaiPublisherException(e);
204
		}
205
	}
206

  
207
	protected abstract RecordInfo getRecordById(final MDFInfo mdf, final String id) throws OaiPublisherException;
208

  
209
	protected abstract ListDocumentsInfo getDocuments(final boolean onlyIdentifiers,
210
			final String set,
211
			final String metadataPrefix,
212
			final String from,
213
			final String until) throws OaiPublisherException;
214

  
215
	protected abstract ListDocumentsInfo getDocuments(final boolean onlyIdentifiers, final String resumptionToken) throws OaiPublisherException;
216

  
217
	public String getCurrentDBName() {
218
		return currentDBName;
219
	}
220

  
221
	public void setCurrentDBName(final String currentDBName) {
222
		this.currentDBName = currentDBName;
223
	}
224

  
225
	public SetCollection getSetCollection() {
226
		return setCollection;
227
	}
228

  
229
	public void setSetCollection(final SetCollection setCollection) {
230
		this.setCollection = setCollection;
231
	}
232

  
233
	public OAIConfigurationExistReader getOaiConfigurationExistReader() {
234
		return oaiConfigurationExistReader;
235
	}
236

  
237
	public void setOaiConfigurationExistReader(final OAIConfigurationExistReader oaiConfigurationExistReader) {
238
		this.oaiConfigurationExistReader = oaiConfigurationExistReader;
239
	}
240

  
241
	public ISLookUpClient getLookupClient() {
242
		return lookupClient;
243
	}
244

  
245
	public void setLookupClient(final ISLookUpClient lookupClient) {
246
		this.lookupClient = lookupClient;
247
	}
248

  
249
	public EhCache<String, MDFInfo> getMdFormatsCache() {
250
		return mdFormatsCache;
251
	}
252

  
253
	public void setMdFormatsCache(final EhCache<String, MDFInfo> mdFormatsCache) {
254
		this.mdFormatsCache = mdFormatsCache;
255
	}
256
}
modules/cnr-data-information-oai-publisher-common/tags/cnr-data-information-oai-publisher-common-5.0.2/src/main/java/eu/dnetlib/data/information/oai/publisher/OaiPublisherRuntimeException.java
1
package eu.dnetlib.data.information.oai.publisher;
2

  
3
public class OaiPublisherRuntimeException extends RuntimeException {
4

  
5
	/**
6
	 * 
7
	 */
8
	private static final long serialVersionUID = -4295850381530160166L;
9

  
10
	public OaiPublisherRuntimeException() {
11
		super();
12
	}
13

  
14
	public OaiPublisherRuntimeException(final Throwable e) {
15
		super(e);
16
	}
17

  
18
	public OaiPublisherRuntimeException(final String msg, final Throwable e) {
19
		super(msg, e);
20
	}
21

  
22
	public OaiPublisherRuntimeException(final String msg) {
23
		super(msg);
24
	}
25

  
26
}
modules/cnr-data-information-oai-publisher-common/tags/cnr-data-information-oai-publisher-common-5.0.2/src/main/java/eu/dnetlib/data/information/oai/publisher/OAIController.java
1
package eu.dnetlib.data.information.oai.publisher;
2

  
3
import java.text.SimpleDateFormat;
4
import java.util.Date;
5
import java.util.HashMap;
6
import java.util.Iterator;
7
import java.util.Map;
8
import java.util.Map.Entry;
9
import java.util.TimeZone;
10

  
11
import javax.servlet.http.HttpServletRequest;
12
import javax.servlet.http.HttpServletResponse;
13

  
14
import org.apache.commons.lang.StringUtils;
15
import org.apache.commons.logging.Log;
16
import org.apache.commons.logging.LogFactory;
17
import org.springframework.beans.factory.annotation.Autowired;
18
import org.springframework.stereotype.Controller;
19
import org.springframework.ui.ModelMap;
20
import org.springframework.web.bind.annotation.ModelAttribute;
21
import org.springframework.web.bind.annotation.RequestMapping;
22

  
23
import eu.dnetlib.data.information.oai.publisher.core.AbstractOAICore;
24
import eu.dnetlib.data.information.oai.publisher.info.ListRecordsInfo;
25

  
26
/**
27
 * OAI Servlet.
28
 * 
29
 * @author michele
30
 * 
31
 */
32
@Controller
33
public final class OAIController {
34

  
35
	public enum OAI_VERBS {
36
		IDENTIFY, LIST_IDENTIFIERS, LIST_RECORDS, LIST_METADATA_FORMATS, LIST_SETS, GET_RECORD, UNSUPPORTED_VERB;
37

  
38
		public static OAI_VERBS getVerb(final String theVerb) {
39
			if (StringUtils.isBlank(theVerb)) return UNSUPPORTED_VERB;
40
			if (theVerb.equalsIgnoreCase("Identify")) return IDENTIFY;
41
			if (theVerb.equalsIgnoreCase("ListIdentifiers")) return LIST_IDENTIFIERS;
42
			if (theVerb.equalsIgnoreCase("ListRecords")) return LIST_RECORDS;
43
			if (theVerb.equalsIgnoreCase("ListMetadataFormats")) return LIST_METADATA_FORMATS;
44
			if (theVerb.equalsIgnoreCase("ListSets")) return LIST_SETS;
45
			if (theVerb.equalsIgnoreCase("GetRecord")) return GET_RECORD;
46
			if (theVerb.equalsIgnoreCase("listidentifiers")) return LIST_IDENTIFIERS;
47
			return UNSUPPORTED_VERB;
48

  
49
		}
50
	}
51

  
52
	public enum DELETED_SUPPORT {
53
		NO, TRANSIENT, PERSISTENT;
54

  
55
		@Override
56
		public String toString() {
57
			switch (this) {
58
			case TRANSIENT:
59
				return "transient";
60
			case PERSISTENT:
61
				return "persistent";
62
			default:
63
				return "no";
64
			}
65
		}
66

  
67
	}
68

  
69
	/**
70
	 * logger.
71
	 */
72
	private static final Log log = LogFactory.getLog(OAIController.class); // NOPMD by marko on 11/24/08 5:02 PM
73

  
74
	/**
75
	 * Default content type.
76
	 */
77
	private static final String DEFAULT_CONTENT_TYPE = "text/xml;charset=utf-8";
78

  
79
	/**
80
	 * error messages map.
81
	 */
82
	private static Map<String, String> errMessages = new HashMap<String, String>();
83

  
84
	/**
85
	 * OAI servlet core. Most of the logic is here
86
	 */
87
	@Autowired
88
	private AbstractOAICore core;
89

  
90
	@Autowired
91
	private OAIProperties oaiProperties;
92

  
93
	static {
94
		OAIController.errMessages
95
				.put("badArgument",
96
						"The request includes illegal arguments, is missing required arguments, includes a repeated argument, or values for arguments have an illegal syntax.");
97
		OAIController.errMessages.put("badVerb",
98
				"Value of the verb argument is not a legal OAI-PMH verb, the verb argument is missing, or the verb argument is repeated.");
99
		OAIController.errMessages.put("cannotDisseminateFormat",
100
				"The metadata format identified by the value given for the metadataPrefix argument is not supported by the item or by the repository.");
101
		OAIController.errMessages.put("idDoesNotExist", "The value of the identifier argument is unknown or illegal in this repository.");
102
		OAIController.errMessages.put("noMetadataFormats", "There are no metadata formats available for the specified item.");
103
		OAIController.errMessages.put("noSetHierarchy", "The repository does not support sets.");
104
		OAIController.errMessages.put("noRecordsMatch",
105
				"The combination of the values of the from, until, set and metadataPrefix arguments results in an empty list.");
106
		OAIController.errMessages.put("badResumptionToken", "The value of the resumptionToken argument is invalid or expired.");
107
	}
108

  
109
	@RequestMapping("/oai/oai.do")
110
	public String oai(final ModelMap map, final HttpServletRequest request, final HttpServletResponse response) throws Exception {
111
		response.setContentType(OAIController.DEFAULT_CONTENT_TYPE);
112
		String theVerb = "";
113
		try {
114
			final Map<String, String> params = cleanParameters(request.getParameterMap());
115
			if (params == null) return oaiError("badArgument", map);
116
			theVerb = params.get("verb");
117
			OAI_VERBS requestedVerb = OAI_VERBS.getVerb(theVerb);
118
			switch (requestedVerb) {
119
			case IDENTIFY:
120
				return oaiIdentify(params, map);
121
			case LIST_METADATA_FORMATS:
122
				return oaiListMetadataFormats(params, map);
123
			case LIST_SETS:
124
				return oaiListSets(params, map);
125
			case GET_RECORD:
126
				return oaiGetRecord(params, map);
127
			case LIST_IDENTIFIERS:
128
				return oaiListIdentifiersOrRecords(params, map);
129
			case LIST_RECORDS:
130
				return oaiListIdentifiersOrRecords(params, map);
131
			default:
132
				return oaiError("badVerb", map);
133
			}
134
		} catch (final CannotDisseminateFormatException e) {
135
			log.error("ERROR", e);
136
			return oaiError("cannotDisseminateFormat", theVerb, map);
137
		} catch (final NoRecordsMatchException e) {
138
			log.error("ERROR", e);
139
			return oaiError("noRecordsMatch", theVerb, map);
140
		} catch (final BadResumptionTokenException e) {
141
			log.error("ERROR", e);
142
			return oaiError("badResumptionToken", theVerb, map);
143
		} catch (final Exception e) {
144
			log.error("ERROR", e);
145
			return oaiError(e, map);
146
		}
147
	}
148

  
149
	private Map<String, String> cleanParameters(final Map<?, ?> startParams) {
150
		final HashMap<String, String> params = new HashMap<String, String>();
151
		final Iterator<?> iter = startParams.entrySet().iterator();
152
		while (iter.hasNext()) {
153
			final Entry<?, ?> entry = (Entry<?, ?>) iter.next();
154
			final String key = entry.getKey().toString();
155
			final String[] arr = (String[]) entry.getValue();
156
			if (arr.length == 0) return null;
157
			final String value = arr[0];
158
			if (key.equals("verb")) {
159
				params.put("verb", value);
160
			} else if (key.equals("from")) {
161
				params.put("from", value);
162
			} else if (key.equals("until")) {
163
				params.put("until", value);
164
			} else if (key.equals("metadataPrefix")) {
165
				params.put("metadataPrefix", value);
166
			} else if (key.equals("identifier")) {
167
				params.put("identifier", value);
168
			} else if (key.equals("set")) {
169
				params.put("set", value);
170
			} else if (key.equals("resumptionToken")) {
171
				params.put("resumptionToken", value);
172
			} else return null;
173
		}
174
		return params;
175
	}
176

  
177
	private String oaiIdentify(final Map<String, String> params, final ModelMap map) throws Exception {
178
		String verb = null;
179
		if (params.containsKey("verb")) {
180
			verb = params.get("verb");
181
			params.remove("verb");
182
		}
183
		if (params.entrySet().size() > 0) return oaiError("badArgument", verb, map);
184
		return "oai/OAI_Identify";
185
	}
186

  
187
	private String oaiGetRecord(final Map<String, String> params, final ModelMap map) throws Exception {
188
		String verb = null;
189
		String prefix = null;
190
		String identifier = null;
191
		if (params.containsKey("verb")) {
192
			verb = params.get("verb");
193
			params.remove("verb");
194
		}
195
		if (params.containsKey("metadataPrefix")) {
196
			prefix = params.get("metadataPrefix");
197
			params.remove("metadataPrefix");
198
		} else return oaiError("badArgument", verb, map);
199
		if (params.containsKey("identifier")) {
200
			identifier = params.get("identifier");
201
			params.remove("identifier");
202
		} else return oaiError("badArgument", verb, map);
203
		if (params.entrySet().size() > 0) return oaiError("badArgument", verb, map);
204
		this.core.setCurrentDBFromIS(true);
205
		map.addAttribute("record", core.getInfoRecord(identifier, prefix));
206

  
207
		return "oai/OAI_GetRecord";
208
	}
209

  
210
	private String oaiListIdentifiersOrRecords(final Map<String, String> params, final ModelMap map) throws Exception {
211
		OAI_VERBS verb = null;
212
		String metadataPrefix = null;
213
		String resumptionToken = null;
214
		String set = null;
215
		String from = null;
216
		String until = null;
217

  
218
		if (params.containsKey("verb")) {
219
			verb = OAI_VERBS.getVerb(params.get("verb"));
220
			params.remove("verb");
221
		}
222

  
223
		if (params.containsKey("resumptionToken")) {
224
			resumptionToken = params.get("resumptionToken");
225
			params.remove("resumptionToken");
226
			this.core.setCurrentDBFromIS(false);
227
		} else {
228
			this.core.setCurrentDBFromIS(true);
229
			if (params.containsKey("metadataPrefix")) {
230
				metadataPrefix = params.get("metadataPrefix");
231
				params.remove("metadataPrefix");
232
			} else return oaiError("badArgument", verb.toString(), map);
233
			if (params.containsKey("from")) {
234
				from = params.get("from");
235
				params.remove("from");
236
			}
237
			if (params.containsKey("until")) {
238
				until = params.get("until");
239
				params.remove("until");
240
			}
241
			if (params.containsKey("set")) {
242
				set = params.get("set");
243
				params.remove("set");
244
			}
245
		}
246
		if (params.entrySet().size() > 0) return oaiError("badArgument", verb.toString(), map);
247
		if (StringUtils.isNotBlank(set) && !this.core.existSet(set)) return oaiError("badArgument", verb.toString(), map);
248

  
249
		boolean onlyIdentifiers = true;
250
		if (verb == OAI_VERBS.LIST_RECORDS) {
251
			onlyIdentifiers = false;
252
		}
253

  
254
		ListRecordsInfo infos;
255

  
256
		if (StringUtils.isBlank(resumptionToken)) {
257
			infos = core.listRecords(onlyIdentifiers, metadataPrefix, set, from, until);
258
		} else {
259
			infos = core.listRecords(onlyIdentifiers, resumptionToken);
260
		}
261

  
262
		map.addAttribute("info", infos);
263

  
264
		if (verb == OAI_VERBS.LIST_RECORDS) return "oai/OAI_ListRecords";
265

  
266
		return "oai/OAI_ListIdentifiers";
267
	}
268

  
269
	private String oaiListSets(final Map<String, String> params, final ModelMap map) throws Exception {
270
		String verb = null;
271
		if (params.containsKey("verb")) {
272
			verb = params.get("verb");
273
			params.remove("verb");
274
		}
275
		if (params.entrySet().size() > 0) return oaiError("badArgument", verb, map);
276
		this.core.setCurrentDBFromIS(true);
277
		map.addAttribute("sets", core.listSets());
278
		return "oai/OAI_ListSets";
279
	}
280

  
281
	private String oaiListMetadataFormats(final Map<String, String> params, final ModelMap map) throws Exception {
282
		String id = null;
283
		String verb = null;
284
		if (params.containsKey("verb")) {
285
			verb = params.get("verb");
286
			params.remove("verb");
287
		}
288
		if (params.containsKey("identifier")) {
289
			id = params.get("identifier");
290
			params.remove("identifier");
291
		}
292
		if (params.entrySet().size() > 0) return oaiError("badArgument", verb, map);
293
		this.core.setCurrentDBFromIS(true);
294
		map.addAttribute("formats", core.listMetadataFormats());
295
		if (id != null) {
296
			map.addAttribute("identifier", id);
297
			return "oai/OAI_ListMetadataFormats_withid";
298
		}
299
		return "oai/OAI_ListMetadataFormats";
300
	}
301

  
302
	private String oaiError(final String errCode, final String verb, final ModelMap map) throws Exception {
303
		if (StringUtils.isBlank(verb)) return oaiError(errCode, map);
304
		map.addAttribute("verb", verb);
305
		map.addAttribute("errcode", errCode);
306
		map.addAttribute("errmsg", OAIController.errMessages.get(errCode));
307
		return "oai/OAI_Error";
308
	}
309

  
310
	private String oaiError(final String errCode, final ModelMap map) throws Exception {
311
		map.addAttribute("errcode", errCode);
312
		map.addAttribute("errmsg", OAIController.errMessages.get(errCode));
313
		return "oai/OAI_Error_noverb";
314
	}
315

  
316
	private String oaiError(final Exception e, final ModelMap map) throws Exception {
317
		map.addAttribute("errcode", "InternalException");
318
		map.addAttribute("errmsg", e.getMessage());
319
		return "oai/OAI_Error_noverb";
320
	}
321

  
322
	/*
323
	 * Default Attribute
324
	 */
325
	@ModelAttribute("url")
326
	public String url(final HttpServletRequest request) {
327
		String forwardedUrl = request.getHeader(getForwardedUrlHeaderName());
328
		String baseURL = getBaseUrl();
329
		if (StringUtils.isNotBlank(baseURL)) return baseURL;
330
		else if (StringUtils.isNotBlank(forwardedUrl)) return forwardedUrl;
331
		else return request.getRequestURL() + "";
332
	}
333

  
334
	/**
335
	 * Model attribute for the date of response.
336
	 * <p>
337
	 * According to OAI-PMH protocol, it must be in UTC with format YYYY-MM-DDThh:mm:ssZ, where Z is the time zone ('Z' for "Zulu Time",
338
	 * i.e. UTC).
339
	 * </p>
340
	 * <p>
341
	 * See http://www.openarchives.org/OAI/openarchivesprotocol.html#Dates
342
	 * </p>
343
	 */
344
	@ModelAttribute("date")
345
	public String date() {
346
		SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ");
347
		formatter.setTimeZone(TimeZone.getTimeZone("UTC"));
348
		String date = formatter.format(new Date());
349
		return date.replace("+0000", "Z");
350
	}
351

  
352
	@ModelAttribute("repoName")
353
	public String getRepoName() {
354
		return oaiProperties.getRepoName();
355
	}
356

  
357
	@ModelAttribute("email")
358
	public String getRepoEmail() {
359
		return oaiProperties.getRepoEmail();
360
	}
361

  
362
	@ModelAttribute("earliestDatestamp")
363
	public String getEarliestDatestamp() {
364
		return oaiProperties.getEarliestDatestamp();
365
	}
366

  
367
	public String getBaseUrl() {
368
		return oaiProperties.getBaseUrl();
369
	}
370

  
371
	public String getForwardedUrlHeaderName() {
372
		return oaiProperties.getForwardedUrlHeaderName();
373
	}
374

  
375
	@ModelAttribute("deletedRecord")
376
	public String getDeletedRecordSupport() {
377
		return oaiProperties.getDeletedRecordSupport();
378
	}
379

  
380
	@ModelAttribute("granularity")
381
	public String getDateGranularity() {
382
		return oaiProperties.getDateGranularity();
383
	}
384
}
modules/cnr-data-information-oai-publisher-common/tags/cnr-data-information-oai-publisher-common-5.0.2/src/main/resources/eu/dnetlib/enabling/views/oai/OAI_Error_noverb.st
1
<?xml version="1.0" encoding="UTF-8"?>
2
<OAI-PMH xmlns="http://www.openarchives.org/OAI/2.0/" 
3
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4
         xsi:schemaLocation="http://www.openarchives.org/OAI/2.0/
5
         http://www.openarchives.org/OAI/2.0/OAI-PMH.xsd">
6
  <responseDate>$date$</responseDate>
7
  <request>$url$</request>
8
  <error code="$errcode$">$errmsg$</error>
9
</OAI-PMH>
modules/cnr-data-information-oai-publisher-common/tags/cnr-data-information-oai-publisher-common-5.0.2/src/main/resources/eu/dnetlib/enabling/views/oai/OAI_ListMetadataFormats.st
1
<?xml version="1.0" encoding="UTF-8"?>
2
<OAI-PMH xmlns="http://www.openarchives.org/OAI/2.0/" 
3
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4
         xsi:schemaLocation="http://www.openarchives.org/OAI/2.0/
5
         http://www.openarchives.org/OAI/2.0/OAI-PMH.xsd">
6
 
7
 	<responseDate>$date$</responseDate>
8
	<request verb="ListMetadataFormats">$url$</request>
9
 
10
 	<ListMetadataFormats>
11
	$formats:{
12
		<metadataFormat>
13
			<metadataPrefix>$it.prefix$</metadataPrefix>
14
			<schema>$it.schema$</schema>
15
			<metadataNamespace>$it.namespace$</metadataNamespace>
16
		</metadataFormat>
17
	}$
18
	</ListMetadataFormats>
19

  
20
</OAI-PMH>
modules/cnr-data-information-oai-publisher-common/tags/cnr-data-information-oai-publisher-common-5.0.2/src/main/resources/eu/dnetlib/enabling/views/oai/OAI_Error.st
1
<?xml version="1.0" encoding="UTF-8"?>
2
<OAI-PMH xmlns="http://www.openarchives.org/OAI/2.0/" 
3
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4
         xsi:schemaLocation="http://www.openarchives.org/OAI/2.0/
5
         http://www.openarchives.org/OAI/2.0/OAI-PMH.xsd">
6
  <responseDate>$date$</responseDate>
7
  <request verb="$verb$">$url$</request>
8
  <error code="$errcode$">$errmsg$</error>
9
</OAI-PMH>
modules/cnr-data-information-oai-publisher-common/tags/cnr-data-information-oai-publisher-common-5.0.2/src/main/resources/eu/dnetlib/enabling/views/oai/OAI_ListSets.st
1
<?xml version="1.0" encoding="UTF-8"?>
2
<OAI-PMH xmlns="http://www.openarchives.org/OAI/2.0/"
3
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4
	xsi:schemaLocation="http://www.openarchives.org/OAI/2.0/
5
         http://www.openarchives.org/OAI/2.0/OAI-PMH.xsd">
6
<responseDate>$date$</responseDate>
7
<request verb="ListSets">$url$</request>
8
<ListSets>
9
$sets:{
10
<set>
11
	<setSpec>$it.setSpec$</setSpec>
12
	<setName>$it.setName$</setName>
13
	$if(it.setDescription)$
14
	<setDescription>
15
		<oaidc:dc xmlns:oaidc="http://www.openarchives.org/OAI/2.0/oai_dc/" 
16
  			xmlns="http://purl.org/dc/elements/1.1/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
17
        	xsi:schemaLocation="http://www.openarchives.org/OAI/2.0/oai_dc/ http://www.openarchives.org/OAI/2.0/oai_dc.xsd">
18
        	<description>$it.setDescription$</description>
19
    	</oaidc:dc>
20
	</setDescription>
21
	$endif$
22
</set>
23
}$
24

  
25
</ListSets>
26
</OAI-PMH>
modules/cnr-data-information-oai-publisher-common/tags/cnr-data-information-oai-publisher-common-5.0.2/src/main/resources/eu/dnetlib/enabling/views/oai/OAI_Identify.st
1
<?xml version="1.0" encoding="UTF-8"?>
2
<OAI-PMH xmlns="http://www.openarchives.org/OAI/2.0/"
3
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4
	xsi:schemaLocation="http://www.openarchives.org/OAI/2.0/ http://www.openarchives.org/OAI/2.0/OAI-PMH.xsd">
5
<responseDate>$date$</responseDate>
6
<request verb="Identify">$url$</request>
7
<Identify>
8
<repositoryName>$repoName$</repositoryName>
9
<baseURL>$url$</baseURL>
10
<protocolVersion>2.0</protocolVersion>
11
<adminEmail>$email$</adminEmail>
12
<earliestDatestamp>$earliestDatestamp$</earliestDatestamp>
13
<deletedRecord>$deletedRecord$</deletedRecord>
14
<granularity>$granularity$</granularity>
15
</Identify>
16
</OAI-PMH>
modules/cnr-data-information-oai-publisher-common/tags/cnr-data-information-oai-publisher-common-5.0.2/src/main/resources/eu/dnetlib/enabling/views/oai/OAI_ListRecords.st
1
<?xml version="1.0" encoding="UTF-8"?>
2
<oai:OAI-PMH xmlns:oai="http://www.openarchives.org/OAI/2.0/"
3
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4
	xsi:schemaLocation="http://www.openarchives.org/OAI/2.0/
5
         http://www.openarchives.org/OAI/2.0/OAI-PMH.xsd">
6

  
7
	<oai:responseDate>$date$</oai:responseDate>
8
	<oai:request verb="ListRecords" $info.from$ $info.until$ $info.metadataprefix$ $info.set$>$url$</oai:request>
9

  
10
	<oai:ListRecords>
11
	$info.documents:{
12
	<oai:record>
13
        $if(it.deleted)$
14
		<oai:header status="deleted">
15
		$else$
16
		<oai:header>
17
		$endif$
18
			<oai:identifier>$it.identifier$</oai:identifier>
19
					<oai:datestamp>$it.normalizedDatestamp$</oai:datestamp>
20
            $it.setspecs:{set|
21
			<oai:setSpec>$set$</oai:setSpec>
22
			}$
23
            </oai:header>
24
            $if(!it.deleted)$
25
            <oai:metadata>
26
			 $it.metadata$ 
27
			</oai:metadata>
28
			$endif$
29
		
30
		</oai:record>
31
	}$
32
	
33
	$if(info.resumptiontoken)$
34
	<oai:resumptionToken cursor="$info.cursor$" 
35
	$if(info.withSize)$
36
		completeListSize="$info.size$" 
37
	$endif$ 
38
	>$info.resumptiontoken$</oai:resumptionToken>
39
$endif$
40
</oai:ListRecords>
41
</oai:OAI-PMH>
modules/cnr-data-information-oai-publisher-common/tags/cnr-data-information-oai-publisher-common-5.0.2/src/main/resources/eu/dnetlib/enabling/views/oai/OAI_GetRecord.st
1
<?xml version="1.0" encoding="UTF-8"?>
2
<oai:OAI-PMH xmlns:oai="http://www.openarchives.org/OAI/2.0/"
3
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4
	xsi:schemaLocation="http://www.openarchives.org/OAI/2.0/
5
				http://www.openarchives.org/OAI/2.0/OAI-PMH.xsd">
6

  
7
<oai:responseDate>$date$</oai:responseDate>
8
<oai:request verb="GetRecord" identifier="$record.identifier$"
9
	metadataPrefix="$record.prefix$">$url$</oai:request>
10
<oai:GetRecord>
11
<oai:record>
12
$if(record.deleted)$
13
	<oai:header status="deleted">
14
$else$
15
	<oai:header>
16
$endif$
17
	<oai:identifier>$record.identifier$</oai:identifier>
18
	<oai:datestamp>$record.normalizedDatestamp$</oai:datestamp>
19
	$record.setspecs:{set|
20
	<oai:setSpec>$set$</oai:setSpec>
21
	}$ 
22
</oai:header>
23
$if(!record.deleted)$
24
<oai:metadata>
25
	$record.metadata$ 
26
</oai:metadata>
27
$endif$
28

  
29
</oai:record>
30
</oai:GetRecord>
31
</oai:OAI-PMH>
modules/cnr-data-information-oai-publisher-common/tags/cnr-data-information-oai-publisher-common-5.0.2/src/main/resources/eu/dnetlib/enabling/views/oai/OAI_ListMetadataFormats_withid.st
1
<?xml version="1.0" encoding="UTF-8"?>
2
<OAI-PMH xmlns="http://www.openarchives.org/OAI/2.0/" 
3
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4
         xsi:schemaLocation="http://www.openarchives.org/OAI/2.0/
5
         http://www.openarchives.org/OAI/2.0/OAI-PMH.xsd">
6
 
7
 	<responseDate>$date$</responseDate>
8
	<request verb="ListMetadataFormats" identifier="$identifier$">$url$</request>
9
 
10
 	<ListMetadataFormats>
11
	$formats:{
12
		<metadataFormat>
13
			<metadataPrefix>$it.prefix$</metadataPrefix>
14
			<schema>$it.schema$</schema>
15
			<metadataNamespace>$it.namespace$</metadataNamespace>
16
		</metadataFormat>
17
	}$
18
	</ListMetadataFormats>
19

  
20
</OAI-PMH>
modules/cnr-data-information-oai-publisher-common/tags/cnr-data-information-oai-publisher-common-5.0.2/src/main/resources/eu/dnetlib/enabling/views/oai/OAI_ListIdentifiers.st
1
<?xml version="1.0" encoding="UTF-8"?>
2
<oai:OAI-PMH xmlns:oai="http://www.openarchives.org/OAI/2.0/"
3
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4
	xsi:schemaLocation="http://www.openarchives.org/OAI/2.0/ http://www.openarchives.org/OAI/2.0/OAI-PMH.xsd">
5

  
6
<oai:responseDate>$date$</oai:responseDate>
7
<oai:request verb="ListIdentifiers" $info.from$ $info.until$ $info.metadataprefix$ $info.set$>$url$</oai:request>
8

  
9
<oai:ListIdentifiers>
10
$info.identifiers:{
11
	$if(it.deleted)$ 
12
  	<oai:header status="deleted">
13
  	$else$
14
	<oai:header>
15
	$endif$
16
		<oai:identifier>$it.identifier$</oai:identifier>
17
		<oai:datestamp>$it.normalizedDatestamp$</oai:datestamp>
18
		$it.setspecs:{set|
19
		<oai:setSpec>$set$</oai:setSpec>
20
	}$ 
21
	</oai:header>
22
}$ 
23
$if(info.resumptiontoken)$
24
	<oai:resumptionToken cursor="$info.cursor$" 
25
	$if(info.withSize)$
26
		completeListSize="$info.size$" 
27
	$endif$ 
28
	>$info.resumptiontoken$</oai:resumptionToken>
29
$endif$
30

  
31
</oai:ListIdentifiers>
32
</oai:OAI-PMH>
modules/cnr-data-information-oai-publisher-common/tags/cnr-data-information-oai-publisher-common-5.0.2/src/main/resources/eu/dnetlib/data/information/oai/cache/ehcache.xml
1
<ehcache>
2

  
3
	<!-- Sets the path to the directory where cache .data files are created. 
4
		If the path is a Java System Property it is replaced by its value in the 
5
		running VM. The following properties are translated: user.home - User's home 
6
		directory user.dir - User's current working directory java.io.tmpdir - Default 
7
		temp file path -->
8
	<diskStore path="java.io.tmpdir" />
9

  
10

  
11
	<!--Default Cache configuration. These will applied to caches programmatically 
12
		created through the CacheManager. The following attributes are required for 
13
		defaultCache: maxInMemory - Sets the maximum number of objects that will 
14
		be created in memory eternal - Sets whether elements are eternal. If eternal, 
15
		timeouts are ignored and the element is never expired. timeToIdleSeconds 
16
		- Sets the time to idle for an element before it expires. i.e. The maximum 
17
		amount of time between accesses before an element expires Is only used if 
18
		the element is not eternal. Optional attribute. A value of 0 means that an 
19
		Element can idle for infinity timeToLiveSeconds - Sets the time to live for 
20
		an element before it expires. i.e. The maximum time between creation time 
21
		and when an element expires. Is only used if the element is not eternal. 
22
		overflowToDisk - Sets whether elements can overflow to disk when the in-memory 
23
		cache has reached the maxInMemory limit. -->
24

  
25
<!-- 	<defaultCache maxElementsInMemory="1000" overflowToDisk="true" -->
26
<!-- 		eternal="true" diskPersistent="false" timeToIdleSeconds="0" -->
27
<!-- 		timeToLiveSeconds="0" memoryStoreEvictionPolicy="LRU" -->
28
<!-- 		diskExpiryThreadIntervalSeconds="120" diskSpoolBufferSizeMB="5" /> -->
29

  
30
	<cache name="metadataFormats" maxElementsInMemory="10" eternal="false"
31
		timeToIdleSeconds="300" timeToLiveSeconds="500" overflowToDisk="false" />
32

  
33
</ehcache>
34

  
modules/cnr-data-information-oai-publisher-common/tags/cnr-data-information-oai-publisher-common-5.0.2/src/main/resources/eu/dnetlib/data/information/oai/applicationContext-oai-publisher-common.xml
1
<?xml version="1.0" encoding="UTF-8"?>
2
<beans xmlns="http://www.springframework.org/schema/beans"
3
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"
4
	xmlns:util="http://www.springframework.org/schema/util"
5
	xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd 
6
	http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd">
7

  
8
	<bean id="oaiCacheManager"
9
		class="org.springframework.cache.ehcache.EhCacheManagerFactoryBean"
10
		p:cacheManagerName="oaiCacheManger"
11
		p:configLocation="classpath:/eu/dnetlib/data/information/oai/cache/ehcache.xml" />
12

  
13
	<bean id="mdformatsEhCache" class="net.sf.ehcache.Cache"
14
		factory-bean="oaiCacheManager" factory-method="getCache">
15
		<constructor-arg value="metadataFormats" />
16
	</bean>
17
	
18
	<bean id="mdFormatsCache" class="eu.dnetlib.miscutils.cache.EhCache"
19
		p:cache-ref="mdformatsEhCache" />
20

  
21
</beans>
modules/cnr-data-information-oai-publisher-common/tags/cnr-data-information-oai-publisher-common-5.0.2/pom.xml
1
<?xml version="1.0" encoding="UTF-8"?>
2
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
3
	<parent>
4
		<groupId>eu.dnetlib</groupId>
5
		<artifactId>dnet-parent</artifactId>
6
		<version>1.0.0</version>
7
		<relativePath />
8
	</parent>
9
	<modelVersion>4.0.0</modelVersion>
10
	<groupId>eu.dnetlib</groupId>
11
	<artifactId>cnr-data-information-oai-publisher-common</artifactId>
12
	<packaging>jar</packaging>
13
	<version>5.0.2</version>
14
	<scm>
15
		<developerConnection>scm:svn:https://svn.driver.research-infrastructures.eu/driver/dnet40/modules/cnr-data-information-oai-publisher-common/tags/cnr-data-information-oai-publisher-common-5.0.2</developerConnection>
16
	</scm>
17
	<dependencies>
18
		<dependency>
19
			<groupId>eu.dnetlib</groupId>
20
			<artifactId>dnet-oai-utils</artifactId>
21
			<version>[3.0.0,4.0.0)</version>
22
		</dependency>
23
		<dependency>
24
			<groupId>javax.servlet</groupId>
25
			<artifactId>javax.servlet-api</artifactId>
26
			<version>${javax.servlet.version}</version>
27
			<scope>provided</scope>
28
		</dependency>
29
	</dependencies>
30
</project>

Also available in: Unified diff