Project

General

Profile

« Previous | Next » 

Revision 45147

codebase used to migrate to java8 the production system

View differences:

modules/cnr-data-information-oai-publisher-common/trunk/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/trunk/src/main/java/eu/dnetlib/data/information/oai/publisher/OAIError.java
1
package eu.dnetlib.data.information.oai.publisher;
2

  
3
public enum OAIError {
4
	badArgument {
5

  
6
		@Override
7
		public String getMessage() {
8
			return "The request includes illegal arguments, is missing required arguments, includes a repeated argument, or values for arguments have an illegal syntax.";
9
		}
10
	},
11
	badVerb {
12

  
13
		@Override
14
		public String getMessage() {
15
			return "Value of the verb argument is not a legal OAI-PMH verb, the verb argument is missing, or the verb argument is repeated.";
16
		}
17
	},
18
	cannotDisseminateFormat {
19

  
20
		@Override
21
		public String getMessage() {
22
			return "The metadata format identified by the value given for the metadataPrefix argument is not supported by the item or by the repository.";
23
		}
24
	},
25
	idDoesNotExist {
26

  
27
		@Override
28
		public String getMessage() {
29
			return "The value of the identifier argument is unknown or illegal in this repository.";
30
		}
31
	},
32
	noMetadataFormats {
33

  
34
		@Override
35
		public String getMessage() {
36
			return "There are no metadata formats available for the specified item.";
37
		}
38
	},
39
	noSetHierarchy {
40

  
41
		@Override
42
		public String getMessage() {
43
			return "The repository does not support sets.";
44
		}
45
	},
46
	noRecordsMatch {
47

  
48
		@Override
49
		public String getMessage() {
50
			return "The combination of the values of the from, until, set and metadataPrefix arguments results in an empty list.";
51
		}
52
	},
53
	badResumptionToken {
54

  
55
		@Override
56
		public String getMessage() {
57
			return "The value of the resumptionToken argument is invalid or expired.";
58
		}
59
	};
60

  
61
	public abstract String getMessage();
62

  
63
}
modules/cnr-data-information-oai-publisher-common/trunk/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/trunk/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/trunk/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.logging.Log;
8
import org.apache.commons.logging.LogFactory;
9
import org.springframework.beans.factory.annotation.Autowired;
10

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

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

  
31
public abstract class AbstractOAICore {
32

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

  
35
	private String currentDBName;
36

  
37
	@Autowired
38
	private SetCollection setCollection;
39

  
40
	@Autowired
41
	private OAIConfigurationExistReader oaiConfigurationExistReader;
42

  
43
	@Autowired
44
	private ISLookUpClient lookupClient;
45

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

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

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

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

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

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

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

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

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

  
140
		final ListRecordsInfo res = new ListRecordsInfo();
141

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

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

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

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

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

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

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

  
185
	/**
186
	 * Set the current DB from the configuration on the IS.
187
	 */
188
	public void setCurrentDBFromIS() throws OaiPublisherException {
189
		try {
190
			currentDBName = getLookupClient().getCurrentDB();
191
		} catch (Exception e) {
192
			throw new OaiPublisherException(e);
193
		}
194
	}
195

  
196
	protected abstract RecordInfo getRecordById(final MDFInfo mdf, final String id) throws OaiPublisherException;
197

  
198
	protected abstract ListDocumentsInfo getDocuments(final boolean onlyIdentifiers,
199
			final String set,
200
			final String metadataPrefix,
201
			final String from,
202
			final String until) throws OaiPublisherException;
203

  
204
	protected abstract ListDocumentsInfo getDocuments(final boolean onlyIdentifiers, final String resumptionToken) throws OaiPublisherException;
205

  
206
	public String getCurrentDBName() {
207
		return currentDBName;
208
	}
209

  
210
	public void setCurrentDBName(final String currentDBName) {
211
		this.currentDBName = currentDBName;
212
	}
213

  
214
	public SetCollection getSetCollection() {
215
		return setCollection;
216
	}
217

  
218
	public void setSetCollection(final SetCollection setCollection) {
219
		this.setCollection = setCollection;
220
	}
221

  
222
	public OAIConfigurationExistReader getOaiConfigurationExistReader() {
223
		return oaiConfigurationExistReader;
224
	}
225

  
226
	public void setOaiConfigurationExistReader(final OAIConfigurationExistReader oaiConfigurationExistReader) {
227
		this.oaiConfigurationExistReader = oaiConfigurationExistReader;
228
	}
229

  
230
	public ISLookUpClient getLookupClient() {
231
		return lookupClient;
232
	}
233

  
234
	public void setLookupClient(final ISLookUpClient lookupClient) {
235
		this.lookupClient = lookupClient;
236
	}
237

  
238
	public EhCache<String, MDFInfo> getMdFormatsCache() {
239
		return mdFormatsCache;
240
	}
241

  
242
	public void setMdFormatsCache(final EhCache<String, MDFInfo> mdFormatsCache) {
243
		this.mdFormatsCache = mdFormatsCache;
244
	}
245
}
modules/cnr-data-information-oai-publisher-common/trunk/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/trunk/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.*;
5
import java.util.Map.Entry;
6
import javax.servlet.http.HttpServletRequest;
7
import javax.servlet.http.HttpServletResponse;
8

  
9
import eu.dnetlib.data.information.oai.publisher.core.AbstractOAICore;
10
import eu.dnetlib.data.information.oai.publisher.info.ListRecordsInfo;
11
import eu.dnetlib.data.information.oai.publisher.info.RecordInfo;
12
import org.apache.commons.lang.StringUtils;
13
import org.apache.commons.logging.Log;
14
import org.apache.commons.logging.LogFactory;
15
import org.springframework.beans.factory.annotation.Autowired;
16
import org.springframework.stereotype.Controller;
17
import org.springframework.ui.ModelMap;
18
import org.springframework.web.bind.annotation.ModelAttribute;
19
import org.springframework.web.bind.annotation.RequestMapping;
20

  
21
/**
22
 * OAI Servlet.
23
 * 
24
 * @author michele
25
 * 
26
 */
27
@Controller
28
public final class OAIController {
29

  
30
	public enum OAI_VERBS {
31
		IDENTIFY, LIST_IDENTIFIERS, LIST_RECORDS, LIST_METADATA_FORMATS, LIST_SETS, GET_RECORD, UNSUPPORTED_VERB;
32

  
33
		public static OAI_VERBS getVerb(final String theVerb) {
34
			if (StringUtils.isBlank(theVerb)) return UNSUPPORTED_VERB;
35
			if (theVerb.equalsIgnoreCase("Identify")) return IDENTIFY;
36
			if (theVerb.equalsIgnoreCase("ListIdentifiers")) return LIST_IDENTIFIERS;
37
			if (theVerb.equalsIgnoreCase("ListRecords")) return LIST_RECORDS;
38
			if (theVerb.equalsIgnoreCase("ListMetadataFormats")) return LIST_METADATA_FORMATS;
39
			if (theVerb.equalsIgnoreCase("ListSets")) return LIST_SETS;
40
			if (theVerb.equalsIgnoreCase("GetRecord")) return GET_RECORD;
41
			if (theVerb.equalsIgnoreCase("listidentifiers")) return LIST_IDENTIFIERS;
42
			return UNSUPPORTED_VERB;
43

  
44
		}
45
	}
46

  
47
	public enum DELETED_SUPPORT {
48
		NO, TRANSIENT, PERSISTENT;
49

  
50
		@Override
51
		public String toString() {
52
			switch (this) {
53
			case TRANSIENT:
54
				return "transient";
55
			case PERSISTENT:
56
				return "persistent";
57
			default:
58
				return "no";
59
			}
60
		}
61

  
62
	}
63

  
64
	/**
65
	 * logger.
66
	 */
67
	private static final Log log = LogFactory.getLog(OAIController.class); // NOPMD by marko on 11/24/08 5:02 PM
68

  
69
	/**
70
	 * Default content type.
71
	 */
72
	private static final String DEFAULT_CONTENT_TYPE = "text/xml;charset=utf-8";
73

  
74
	/**
75
	 * OAI servlet core. Most of the logic is here
76
	 */
77
	@Autowired
78
	private AbstractOAICore core;
79

  
80
	@Autowired
81
	private OAIProperties oaiProperties;
82

  
83
	@RequestMapping("/oai/clearCaches.do")
84
	public void clearOaiCaches() throws OaiPublisherException {
85
		core.getMdFormatsCache().clear();
86
		core.setCurrentDBFromIS();
87
		core.getLookupClient().evictCaches();
88
	}
89

  
90
	@RequestMapping("/oai/oai.do")
91
	public String oai(final ModelMap map, final HttpServletRequest request, final HttpServletResponse response) throws Exception {
92
		response.setContentType(OAIController.DEFAULT_CONTENT_TYPE);
93
		String theVerb = "";
94
		try {
95
			final Map<String, String> params = cleanParameters(request.getParameterMap());
96
			if (params == null) return oaiError(OAIError.badArgument, map);
97
			theVerb = params.get("verb");
98
			OAI_VERBS requestedVerb = OAI_VERBS.getVerb(theVerb);
99
			switch (requestedVerb) {
100
			case IDENTIFY:
101
				return oaiIdentify(params, map);
102
			case LIST_METADATA_FORMATS:
103
				return oaiListMetadataFormats(params, map);
104
			case LIST_SETS:
105
				return oaiListSets(params, map);
106
			case GET_RECORD:
107
				return oaiGetRecord(params, map);
108
			case LIST_IDENTIFIERS:
109
				return oaiListIdentifiersOrRecords(params, map);
110
			case LIST_RECORDS:
111
				return oaiListIdentifiersOrRecords(params, map);
112
			default:
113
				return oaiError(OAIError.badVerb, map);
114
			}
115
		} catch (final CannotDisseminateFormatException e) {
116
			log.debug("ERROR", e);
117
			return oaiError(OAIError.cannotDisseminateFormat, theVerb, map);
118
		} catch (final NoRecordsMatchException e) {
119
			log.debug("ERROR", e);
120
			return oaiError(OAIError.noRecordsMatch, theVerb, map);
121
		} catch (final BadResumptionTokenException e) {
122
			log.debug("ERROR", e);
123
			return oaiError(OAIError.badResumptionToken, theVerb, map);
124
		} catch (final Exception e) {
125
			log.error("ERROR", e);
126
			return oaiError(e, map);
127
		}
128
	}
129

  
130
	private Map<String, String> cleanParameters(final Map<?, ?> startParams) {
131
		final HashMap<String, String> params = new HashMap<String, String>();
132
		final Iterator<?> iter = startParams.entrySet().iterator();
133
		while (iter.hasNext()) {
134
			final Entry<?, ?> entry = (Entry<?, ?>) iter.next();
135
			final String key = entry.getKey().toString();
136
			final String[] arr = (String[]) entry.getValue();
137
			if (arr.length == 0) return null;
138
			final String value = arr[0];
139
			if (key.equals("verb")) {
140
				params.put("verb", value);
141
			} else if (key.equals("from")) {
142
				params.put("from", value);
143
			} else if (key.equals("until")) {
144
				params.put("until", value);
145
			} else if (key.equals("metadataPrefix")) {
146
				params.put("metadataPrefix", value);
147
			} else if (key.equals("identifier")) {
148
				params.put("identifier", value);
149
			} else if (key.equals("set")) {
150
				params.put("set", value);
151
			} else if (key.equals("resumptionToken")) {
152
				params.put("resumptionToken", value);
153
			} else return null;
154
		}
155
		return params;
156
	}
157

  
158
	private String oaiIdentify(final Map<String, String> params, final ModelMap map) throws Exception {
159
		String verb = null;
160
		if (params.containsKey("verb")) {
161
			verb = params.get("verb");
162
			params.remove("verb");
163
		}
164
		if (params.entrySet().size() > 0) return oaiError(OAIError.badArgument, verb, map);
165
		return "oai/OAI_Identify";
166
	}
167

  
168
	private String oaiGetRecord(final Map<String, String> params, final ModelMap map) throws Exception {
169
		String verb = null;
170
		String prefix = null;
171
		String identifier = null;
172
		if (params.containsKey("verb")) {
173
			verb = params.get("verb");
174
			params.remove("verb");
175
		}
176
		if (params.containsKey("metadataPrefix")) {
177
			prefix = params.get("metadataPrefix");
178
			params.remove("metadataPrefix");
179
		} else return oaiError(OAIError.badArgument, verb, map);
180
		if (params.containsKey("identifier")) {
181
			identifier = params.get("identifier");
182
			params.remove("identifier");
183
		} else return oaiError(OAIError.badArgument, verb, map);
184
		if (params.entrySet().size() > 0) return oaiError(OAIError.badArgument, verb, map);
185
		this.core.setCurrentDBFromIS();
186
		RecordInfo record = core.getInfoRecord(identifier, prefix);
187
		if (record == null) return oaiError(OAIError.idDoesNotExist, map);
188
		map.addAttribute("record", record);
189

  
190
		return "oai/OAI_GetRecord";
191
	}
192

  
193
	private String oaiListIdentifiersOrRecords(final Map<String, String> params, final ModelMap map) throws Exception {
194
		OAI_VERBS verb = null;
195
		String metadataPrefix = null;
196
		String resumptionToken = null;
197
		String set = null;
198
		String from = null;
199
		String until = null;
200

  
201
		if (params.containsKey("verb")) {
202
			verb = OAI_VERBS.getVerb(params.get("verb"));
203
			params.remove("verb");
204
		}
205

  
206
		if (params.containsKey("resumptionToken")) {
207
			resumptionToken = params.get("resumptionToken");
208
			params.remove("resumptionToken");
209
			this.core.setCurrentDBFromIS();
210
		} else {
211
			this.core.setCurrentDBFromIS();
212
			if (params.containsKey("metadataPrefix")) {
213
				metadataPrefix = params.get("metadataPrefix");
214
				params.remove("metadataPrefix");
215
			} else return oaiError(OAIError.badArgument, verb.toString(), map);
216
			if (params.containsKey("from")) {
217
				from = params.get("from");
218
				params.remove("from");
219
			}
220
			if (params.containsKey("until")) {
221
				until = params.get("until");
222
				params.remove("until");
223
			}
224
			if (params.containsKey("set")) {
225
				set = params.get("set");
226
				params.remove("set");
227
			}
228
		}
229
		if (params.entrySet().size() > 0) return oaiError(OAIError.badArgument, verb.toString(), map);
230
		if (StringUtils.isNotBlank(set) && !this.core.existSet(set)) return oaiError(OAIError.badArgument, verb.toString(), map);
231

  
232
		boolean onlyIdentifiers = true;
233
		if (verb == OAI_VERBS.LIST_RECORDS) {
234
			onlyIdentifiers = false;
235
		}
236

  
237
		ListRecordsInfo infos;
238

  
239
		if (StringUtils.isBlank(resumptionToken)) {
240
			infos = core.listRecords(onlyIdentifiers, metadataPrefix, set, from, until);
241
		} else {
242
			infos = core.listRecords(onlyIdentifiers, resumptionToken);
243
		}
244

  
245
		map.addAttribute("info", infos);
246

  
247
		if (verb == OAI_VERBS.LIST_RECORDS) return "oai/OAI_ListRecords";
248

  
249
		return "oai/OAI_ListIdentifiers";
250
	}
251

  
252
	private String oaiListSets(final Map<String, String> params, final ModelMap map) throws Exception {
253
		String verb = null;
254
		if (params.containsKey("verb")) {
255
			verb = params.get("verb");
256
			params.remove("verb");
257
		}
258
		if (params.entrySet().size() > 0) return oaiError(OAIError.badArgument, verb, map);
259
		this.core.setCurrentDBFromIS();
260
		map.addAttribute("sets", core.listSets());
261
		return "oai/OAI_ListSets";
262
	}
263

  
264
	private String oaiListMetadataFormats(final Map<String, String> params, final ModelMap map) throws Exception {
265
		String id = null;
266
		String verb = null;
267
		if (params.containsKey("verb")) {
268
			verb = params.get("verb");
269
			params.remove("verb");
270
		}
271
		if (params.containsKey("identifier")) {
272
			id = params.get("identifier");
273
			params.remove("identifier");
274
		}
275
		if (params.entrySet().size() > 0) return oaiError(OAIError.badArgument, verb, map);
276
		this.core.setCurrentDBFromIS();
277
		map.addAttribute("formats", core.listMetadataFormats());
278
		if (id != null) {
279
			map.addAttribute("identifier", id);
280
			return "oai/OAI_ListMetadataFormats_withid";
281
		}
282
		return "oai/OAI_ListMetadataFormats";
283
	}
284

  
285
	private String oaiError(final OAIError errCode, final String verb, final ModelMap map) throws Exception {
286
		if (StringUtils.isBlank(verb)) return oaiError(errCode, map);
287
		map.addAttribute("verb", verb);
288
		map.addAttribute("errcode", errCode.name());
289
		map.addAttribute("errmsg", errCode.getMessage());
290
		return "oai/OAI_Error";
291
	}
292

  
293
	private String oaiError(final OAIError errCode, final ModelMap map) throws Exception {
294
		map.addAttribute("errcode", errCode.name());
295
		map.addAttribute("errmsg", errCode.getMessage());
296
		return "oai/OAI_Error_noverb";
297
	}
298

  
299
	private String oaiError(final Exception e, final ModelMap map) throws Exception {
300
		map.addAttribute("errcode", "InternalException");
301
		map.addAttribute("errmsg", e.getMessage());
302
		return "oai/OAI_Error_noverb";
303
	}
304

  
305
	/*
306
	 * Default Attribute
307
	 */
308
	@ModelAttribute("url")
309
	public String url(final HttpServletRequest request) {
310
		String forwardedUrl = request.getHeader(getForwardedUrlHeaderName());
311
		String baseURL = getBaseUrl();
312
		if (StringUtils.isNotBlank(baseURL)) return baseURL;
313
		else if (StringUtils.isNotBlank(forwardedUrl)) return forwardedUrl;
314
		else return request.getRequestURL() + "";
315
	}
316

  
317
	/**
318
	 * Model attribute for the date of response.
319
	 * <p>
320
	 * 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",
321
	 * i.e. UTC).
322
	 * </p>
323
	 * <p>
324
	 * See http://www.openarchives.org/OAI/openarchivesprotocol.html#Dates
325
	 * </p>
326
	 */
327
	@ModelAttribute("date")
328
	public String date() {
329
		SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ");
330
		formatter.setTimeZone(TimeZone.getTimeZone("UTC"));
331
		String date = formatter.format(new Date());
332
		return date.replace("+0000", "Z");
333
	}
334

  
335
	@ModelAttribute("repoName")
336
	public String getRepoName() {
337
		return oaiProperties.getRepoName();
338
	}
339

  
340
	@ModelAttribute("email")
341
	public String getRepoEmail() {
342
		return oaiProperties.getRepoEmail();
343
	}
344

  
345
	@ModelAttribute("earliestDatestamp")
346
	public String getEarliestDatestamp() {
347
		return oaiProperties.getEarliestDatestamp();
348
	}
349

  
350
	public String getBaseUrl() {
351
		return oaiProperties.getBaseUrl();
352
	}
353

  
354
	public String getForwardedUrlHeaderName() {
355
		return oaiProperties.getForwardedUrlHeaderName();
356
	}
357

  
358
	@ModelAttribute("deletedRecord")
359
	public String getDeletedRecordSupport() {
360
		return oaiProperties.getDeletedRecordSupport();
361
	}
362

  
363
	@ModelAttribute("granularity")
364
	public String getDateGranularity() {
365
		return oaiProperties.getDateGranularity();
366
	}
367
}
modules/cnr-data-information-oai-publisher-common/trunk/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/trunk/src/main/resources/eu/dnetlib/enabling/views/oai/clearcaches.st
1
CACHES CLEARED
modules/cnr-data-information-oai-publisher-common/trunk/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/trunk/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/trunk/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/trunk/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/trunk/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
			$if(it.provenance)$
31
        	<oai:about>$it.provenance$</oai:about>
32
        	$endif$
33
		</oai:record>
34
	}$
35
	
36
	$if(info.resumptiontoken)$
37
	<oai:resumptionToken cursor="$info.cursor$" 
38
	$if(info.withSize)$
39
		completeListSize="$info.size$" 
40
	$endif$ 
41
	>$info.resumptiontoken$</oai:resumptionToken>
42
$endif$
43
</oai:ListRecords>
44
</oai:OAI-PMH>
modules/cnr-data-information-oai-publisher-common/trunk/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
$if(record.provenance)$
30
<oai:about>
31
$record.provenance$
32
</oai:about>
33
$endif$
34

  
35
</oai:record>
36
</oai:GetRecord>
37
</oai:OAI-PMH>
modules/cnr-data-information-oai-publisher-common/trunk/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/trunk/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/trunk/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/trunk/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/trunk/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-SNAPSHOT</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.2.1-SNAPSHOT</version>
14
	<scm>
15
		<developerConnection>scm:svn:https://svn.driver.research-infrastructures.eu/driver/dnet40/modules/cnr-data-information-oai-publisher-common/trunk</developerConnection>
16
	</scm>
17
	<dependencies>
18
		<dependency>
19
			<groupId>eu.dnetlib</groupId>
20
			<artifactId>dnet-oai-utils</artifactId>
21
			<version>[3.2.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>
modules/cnr-data-information-oai-publisher-common/branches/4.x/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/branches/4.x/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/branches/4.x/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/branches/4.x/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();
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff