Project

General

Profile

« Previous | Next » 

Revision 56127

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

View differences:

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

  
3
import java.text.Normalizer;
4

  
5
import org.apache.commons.lang3.StringEscapeUtils;
6
import org.junit.Ignore;
7
import org.junit.Test;
8

  
9
import static org.junit.Assert.assertEquals;
10
import static org.junit.Assert.assertFalse;
11

  
12
public class PublisherMiscTest {
13

  
14
	@Ignore
15
	@Test
16
	//FIXME: do we really need to change © into © ?
17
	public void test() {
18
		String id = "NonavCreation.filmportal.de/DIF_NonAVCreation_EUROPA_TM & © Aardman Animations, LTD";
19
		String newId = StringEscapeUtils.escapeXml11(id);
20
		assertEquals("NonavCreation.filmportal.de/DIF_NonAVCreation_EUROPA_TM & © Aardman Animations, LTD", newId);
21
		assertFalse(id.equals(newId));
22
	}
23

  
24
	@Test
25
	public void test2() {
26
		// Hochschulschriftenserver - Universität Frankfurt am Main
27
		String s = "Publikationenserver der Georg-August-Universität Göttingen";
28
		System.out.println("String to normalize: " + s);
29
		s = StringEscapeUtils.unescapeXml(s);
30
		System.out.println("unescaped: " + s);
31
		s = Normalizer.normalize(s, Normalizer.Form.NFD);
32
		System.out.println("normalized: " + s);
33
		// remove tilde, dots... over letters
34
		s = s.replaceAll("[\\p{InCombiningDiacriticalMarks}&&[^-_]]", "");
35
		// change punctuation into an underscore
36
		s = s.replaceAll("[\\p{Punct}&&[^-_]]", "_");
37
		// remove all non-word charcheters
38
		s = s.replaceAll("[\\W&&[^-_]]", "");
39
		System.out.println("Converted setSpec to: " + s);
40
	}
41

  
42
}
modules/cnr-data-information-oai-publisher/tags/cnr-data-information-oai-publisher-8.0.2/src/test/resources/log4j.properties
1
org.apache.cxf.Logger=org.apache.cxf.common.logging.Log4jLogger
2

  
3
log4j.rootLogger=WARN, CONSOLE
4
log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender
5
log4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayout
6
log4j.appender.CONSOLE.layout.ConversionPattern=%-4r [%t] %-5p %c %x - %m%n
7

  
8
log4j.logger.eu.dnetlib=INFO
9
log4j.logger.eu.dnetlib.data=DEBUG
modules/cnr-data-information-oai-publisher/tags/cnr-data-information-oai-publisher-8.0.2/src/main/java/eu/dnetlib/data/information/oai/publisher/core/CoreInterceptor.java
1
package eu.dnetlib.data.information.oai.publisher.core;
2

  
3
import org.aopalliance.intercept.MethodInvocation;
4
import org.apache.commons.logging.Log;
5
import org.springframework.aop.interceptor.CustomizableTraceInterceptor;
6

  
7
/**
8
 * This class intercepts calls to the OAICore to measure its execution time. It uses Spring AOP.
9
 * 
10
 * @author alessia
11
 * 
12
 */
13
public class CoreInterceptor extends CustomizableTraceInterceptor {
14

  
15
	private static final long serialVersionUID = -9063818317778608736L;
16

  
17
	@Override
18
	protected void writeToLog(final Log logger, final String message, final Throwable ex) {
19
		if (ex != null) {
20
			logger.error(message, ex);
21
		} else {
22
			logger.debug(message);
23
		}
24
	}
25

  
26
	@Override
27
	protected boolean isInterceptorEnabled(final MethodInvocation invocation, final Log logger) {
28
		return true;
29
	}
30
}
modules/cnr-data-information-oai-publisher/tags/cnr-data-information-oai-publisher-8.0.2/src/main/java/eu/dnetlib/data/information/oai/publisher/core/DNetOAICore.java
1
package eu.dnetlib.data.information.oai.publisher.core;
2

  
3
import java.util.Iterator;
4
import java.util.List;
5
import javax.annotation.Resource;
6

  
7
import com.google.common.collect.Lists;
8
import eu.dnetlib.data.information.oai.publisher.*;
9
import eu.dnetlib.data.information.oai.publisher.conf.OAIConfigurationReader;
10
import eu.dnetlib.data.information.oai.publisher.info.ListDocumentsInfo;
11
import eu.dnetlib.data.information.oai.publisher.info.MDFInfo;
12
import eu.dnetlib.data.information.oai.publisher.info.RecordInfo;
13
import eu.dnetlib.data.information.oai.publisher.info.ResumptionTokenImpl;
14
import eu.dnetlib.data.oai.store.Cursor;
15
import eu.dnetlib.data.oai.store.PublisherStore;
16
import eu.dnetlib.data.oai.store.PublisherStoreDAO;
17
import eu.dnetlib.miscutils.functional.UnaryFunction;
18
import org.apache.commons.lang3.StringUtils;
19
import org.apache.commons.logging.Log;
20
import org.apache.commons.logging.LogFactory;
21

  
22
public class DNetOAICore extends AbstractOAICore {
23

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

  
26
	@Resource(name = "mongodbPublisherStoreDao")
27
	private PublisherStoreDAO<PublisherStore<Cursor>, Cursor> publisherStoreDAO;
28

  
29
	private String defaultDate = "2008-01-01T12:00:00Z";
30

  
31
	@Override
32
	protected RecordInfo getRecordById(final MDFInfo mdf, final String id) throws OaiPublisherException {
33
		PublisherStore<Cursor> store = this.publisherStoreDAO.getStoreFor(mdf.getPrefix(), getCurrentDBName());
34
		if (store == null)
35
			throw new OaiPublisherRuntimeException("Missing store for metadata prefix " + mdf.getPrefix() + ". Please check OAI publisher configuration.");
36
		RecordInfo record = null;
37
		if (StringUtils.isBlank(mdf.getTransformationRuleID())) {
38
			record = store.getRecord(id);
39
		} else {
40
			UnaryFunction<String, String> function = getLookupClient().getUnaryFunctionFromTDSRule(mdf.getTransformationRuleID());
41
			record = store.getRecord(id, function);
42
		}
43
		if (record != null) {
44
			record.setPrefix(mdf.getPrefix());
45
		}
46
		return record;
47
	}
48

  
49
	/**
50
	 * 
51
	 * {@inheritDoc}
52
	 * 
53
	 * @see eu.dnetlib.data.information.oai.publisher.core.AbstractOAICore#getDocuments(boolean, java.lang.String, java.lang.String,
54
	 *      java.lang.String, java.lang.String)
55
	 */
56
	@Override
57
	protected ListDocumentsInfo getDocuments(final boolean onlyIdentifiers, final String set, final String metadataPrefix, final String from, final String until)
58
			throws OaiPublisherException {
59
		MDFInfo mdf = obtainMDFInfo(metadataPrefix);
60
		boolean hasDateRange = StringUtils.isNotBlank(from) || StringUtils.isNotBlank(until);
61
		String query = this.generateQuery(mdf, set, from, until, hasDateRange);
62
		int total = this.countTotal(hasDateRange, query, set, mdf);
63
		log.debug("Total number of records: " + total);
64
		Cursor results = this.getCursor(query, onlyIdentifiers, mdf);
65
		ListDocumentsInfo res = this.prepareListDocumentsInfo(results, mdf, query, set, 0, total, hasDateRange);
66
		log.debug("Delivering " + res.getDocs().size() + " in a page");
67
		return res;
68
	}
69

  
70
	@Override
71
	protected ListDocumentsInfo getDocuments(final boolean onlyIdentifiers, final String resumptionToken) throws OaiPublisherException {
72
		ResumptionTokenImpl resToken = new ResumptionTokenImpl();
73
		resToken.deserialize(resumptionToken);
74

  
75
		log.debug(resToken.toString());
76

  
77
		MDFInfo mdf = obtainMDFInfo(resToken.getMetadataPrefix());
78
		String lastID = resToken.getLastObjIdentifier();
79
		String query = resToken.getQuery();
80
		String newQuery = "";
81
		if (StringUtils.isNotBlank(query)) {
82
			newQuery = query + " AND ";
83
		}
84
		newQuery += " _id > \"" + lastID + "\"";
85
		log.debug("NEW QUERY BECAUSE of resumptionToken: " + newQuery);
86
		int total = this.countTotal(resToken.hasDateRange(), query, resToken.getRequestedSet(), mdf);
87
		Cursor results = this.getCursor(newQuery, onlyIdentifiers, mdf);
88
		int oldCount = resToken.getnMaxElements();
89
		// if the number of records changed, then for sure we can invalidate the resumption token, unless we have a new total of -1 (date
90
		// range queries can't be counted for performance reasons)
91
		if ((total != -1) && (oldCount != total)) throw new BadResumptionTokenException(resumptionToken);
92
		long start = System.currentTimeMillis();
93
		ListDocumentsInfo res = this.prepareListDocumentsInfo(results, mdf, query, resToken.getRequestedSet(), resToken.getnRead(), resToken.getnMaxElements(),
94
				resToken.hasDateRange());
95
		res.setCursor(resToken.getnRead());
96
		long end = System.currentTimeMillis();
97
		log.debug("ListDocumentInfo ready in (ms): " + (end - start));
98
		return res;
99
	}
100

  
101
	protected ListDocumentsInfo prepareListDocumentsInfo(final Cursor results,
102
			final MDFInfo mdf,
103
			final String query,
104
			final String requestedSet,
105
			final int read,
106
			final int totalNumber,
107
			final boolean hasDateRange) throws OaiPublisherException {
108
		ListDocumentsInfo documentList = new ListDocumentsInfo();
109
		documentList.setnMaxElements(totalNumber);
110
		documentList.setMetadataPrefix(mdf.getPrefix());
111
		documentList.setCursor(0);
112
		if (documentList.getnMaxElements() == 0) throw new NoRecordsMatchException(OAIError.noRecordsMatch.getMessage());
113

  
114
		List<RecordInfo> theRecords = this.generateOAIRecords(mdf, requestedSet, results);
115
		documentList.setDocs(theRecords);
116

  
117
		if ((theRecords == null) || theRecords.isEmpty()) throw new NoRecordsMatchException("noRecordsMatch: 'documents' is null or empty");
118

  
119
		if ((documentList.getnMaxElements() > (read + theRecords.size())) || (documentList.getnMaxElements() == -1)) {
120
			String lastID = theRecords.get(theRecords.size() - 1).getInternalId();
121
			ResumptionTokenImpl nextToken = new ResumptionTokenImpl();
122
			nextToken.setDateRange(hasDateRange);
123
			nextToken.setLastObjIdentifier(lastID);
124
			nextToken.setMetadataPrefix(mdf.getPrefix());
125
			nextToken.setnMaxElements(totalNumber);
126
			nextToken.setnRead(read + theRecords.size());
127
			nextToken.setQuery(query);
128
			nextToken.setRequestedSet(requestedSet);
129
			documentList.setResumptionToken(nextToken);
130
		}
131

  
132
		return documentList;
133
	}
134

  
135
	protected Cursor getCursor(final String query, final boolean onlyIdentifiers, final MDFInfo mdfInfo) {
136
		PublisherStore<Cursor> store = this.publisherStoreDAO.getStore(mdfInfo.getSourceFormatName(), mdfInfo.getSourceFormatInterpretation(),
137
				mdfInfo.getSourceFormatLayout(), getCurrentDBName());
138
		if (store == null)
139
			throw new OaiPublisherRuntimeException("Missing store for metadata prefix " + mdfInfo.getPrefix() + ". Please check OAI publisher configuration.");
140
		Cursor results = null;
141
		if (StringUtils.isBlank(mdfInfo.getTransformationRuleID())) {
142
			results = store.getRecords(query, !onlyIdentifiers, pageSize);
143
		} else {
144
			UnaryFunction<String, String> function = getLookupClient().getUnaryFunctionFromTDSRule(mdfInfo.getTransformationRuleID());
145
			results = store.getRecords(query, function, !onlyIdentifiers, pageSize);
146
		}
147
		log.debug("Got cursor");
148
		return results;
149
	}
150

  
151
	/**
152
	 * Generates the List of RecordInfo to be delivered.
153
	 *
154
	 * @param mdf
155
	 *            MDFInfo, the requested metadata format information.
156
	 * @param requestedSet
157
	 *            set specified in the request. It is blank if no set was requested.
158
	 * @param cursor
159
	 *            Cursor instance to use to get the records.
160
	 * @return List of RecordInfo instances
161
	 */
162
	protected List<RecordInfo> generateOAIRecords(final MDFInfo mdf, final String requestedSet, final Cursor cursor) {
163
		final List<RecordInfo> documents = Lists.newArrayList();
164
		Iterator<RecordInfo> cursorIterator = cursor.iterator();
165
		while (cursorIterator.hasNext()) {
166
			RecordInfo current = cursorIterator.next();
167
			current.addSetspec(requestedSet);
168
			current.setPrefix(mdf.getPrefix());
169
			documents.add(current);
170
		}
171
		return documents;
172
	}
173

  
174
	protected String generateQuery(final MDFInfo mdf, final String set, final String from, final String until, final boolean hasDateRange) {
175
		String datestampIndexName = OAIConfigurationReader.DATESTAMP_FIELD;
176

  
177
		String query = mdf.getBaseQuery();
178
		if (!StringUtils.isBlank(set)) {
179
			if (!StringUtils.isBlank(query)) {
180
				query += " AND ";
181
			}
182
			query += getSetCollection().getSetQuery(set, getCurrentDBName());
183
		}
184
		if (hasDateRange) {
185
			if (!StringUtils.isBlank(query)) {
186
				query += " AND ";
187
			}
188
			if ((from != null) && (until != null)) {
189
				query += datestampIndexName + " >= " + from + " AND " + datestampIndexName + " <= " + until;
190
			} else if (from != null) {
191
				query += datestampIndexName + " >= " + from;
192
			} else if (until != null) {
193
				query += datestampIndexName + " <= " + until;
194
			}
195
		}
196

  
197
		log.info("QUERY GENERATED: \n" + query);
198
		return query;
199
	}
200

  
201
	private int countTotal(final boolean hasDateRange, final String query, final String set, final MDFInfo mdFormat) {
202
		int total = 0;
203
		if (hasDateRange) {
204
			// Counting in the store by date ranges is too expensive and delays to much the response
205
			total = -1;
206
		} else {
207
			String theSet = set;
208
			if (StringUtils.isBlank(set)) {
209
				theSet = "ALL";
210
			}
211
			log.debug("SET::: " + theSet);
212
			total = getSetCollection().count(theSet, mdFormat.getPrefix(), getCurrentDBName());
213
		}
214
		return total;
215
	}
216

  
217
	public String getDefaultDate() {
218
		return defaultDate;
219
	}
220

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

  
225
	public PublisherStoreDAO<PublisherStore<Cursor>, Cursor> getPublisherStoreDAO() {
226
		return publisherStoreDAO;
227
	}
228

  
229
	public void setPublisherStoreDAO(final PublisherStoreDAO<PublisherStore<Cursor>, Cursor> publisherStoreDAO) {
230
		this.publisherStoreDAO = publisherStoreDAO;
231
	}
232

  
233
	public int getPageSize() {
234
		return pageSize;
235
	}
236

  
237
	public void setPageSize(final int pageSize) {
238
		this.pageSize = pageSize;
239
	}
240

  
241
}
modules/cnr-data-information-oai-publisher/tags/cnr-data-information-oai-publisher-8.0.2/src/main/resources/eu/dnetlib/data/information/oai/publisher/applicationContext-dnet-oaipublisher.properties
1
services.oai.publisher.dnet.pagesize			=	100
2
services.oai.publisher.repo.name				=	D-NET Service for supporting Open Archive Initiative requests
3
services.oai.publisher.repo.email				=	bardi@isti.cnr.it
4
services.oai.publisher.repo.granularity			= 	YYYY-MM-DDThh:mm:ssZ
5
services.oai.publisher.repo.earliestdatestamp	=	2013-10-03T15:53:06Z
6
services.oai.publisher.baseUrl					=
7
#do we support deleted records? NO, TRANSIENT, PERSISTENT
8
services.oai.publisher.deletedrecords			=	TRANSIENT	
9

  
modules/cnr-data-information-oai-publisher/tags/cnr-data-information-oai-publisher-8.0.2/src/main/resources/eu/dnetlib/data/information/oai/publisher/applicationContext-dnet-oaipublisher.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:jaxws="http://cxf.apache.org/jaxws"
4
	xmlns:sec="http://cxf.apache.org/configuration/security" xmlns:wsa="http://cxf.apache.org/ws/addressing"
5
	xmlns:p="http://www.springframework.org/schema/p" xmlns:http="http://cxf.apache.org/transports/http/configuration"
6
	xmlns:t="http://dnetlib.eu/springbeans/t" xmlns:template="http://dnetlib.eu/springbeans/template"
7
	xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
8
    http://cxf.apache.org/ws/addressing http://cxf.apache.org/schemas/ws-addr-conf.xsd 
9
    http://cxf.apache.org/configuration/security http://cxf.apache.org/schemas/configuration/security.xsd 
10
    http://cxf.apache.org/transports/http/configuration http://cxf.apache.org/schemas/configuration/http-conf.xsd 
11
    http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd 
12
    http://dnetlib.eu/springbeans/template http://dnetlib.eu/springbeans/template.xsd">
13

  
14
	<!-- beans -->
15
	<bean id="oaiProperties" class="eu.dnetlib.data.information.oai.publisher.OAIProperties"
16
		p:repoEmail="${services.oai.publisher.repo.email}" p:repoName="${services.oai.publisher.repo.name}"
17
		p:earliestDatestamp="${services.oai.publisher.repo.earliestdatestamp}"
18
		p:baseUrl="${services.oai.publisher.baseUrl}" p:deletedRecordSupport="${services.oai.publisher.deletedrecords}"
19
		p:dateGranularity="${services.oai.publisher.repo.granularity}" />
20

  
21
	<bean id="dnetOAICore"
22
		class="eu.dnetlib.data.information.oai.publisher.core.DNetOAICore"
23
		p:pageSize="${services.oai.publisher.dnet.pagesize}"/>
24

  
25
	<!-- Tracing -->
26

  
27
	<bean name="oaiControllerInterceptor"
28
		class="eu.dnetlib.data.information.oai.publisher.core.CoreInterceptor">
29
		<property name="enterMessage"
30
			value="ENTER: $[targetClassShortName].$[methodName]($[arguments])" />
31
		<property name="exitMessage"
32
			value="EXIT: $[targetClassShortName].$[methodName]($[arguments]) : $[invocationTime]ms" />
33
	</bean>
34

  
35
	<bean
36
		class="org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator">
37
		<property name="beanNames" value="dnetOAICore" />
38
		<property name="proxyTargetClass" value="true" />
39
		<property name="interceptorNames">
40
			<list>
41
				<value>oaiControllerInterceptor</value>
42
			</list>
43
		</property>
44
	</bean>
45

  
46
</beans>
modules/cnr-data-information-oai-publisher/tags/cnr-data-information-oai-publisher-8.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>dnet45-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</artifactId>
12
	<packaging>jar</packaging>
13
	<version>8.0.2</version>
14
	<scm>
15
		<developerConnection>scm:svn:https://svn.driver.research-infrastructures.eu/driver/dnet45/modules/cnr-data-information-oai-publisher/tags/cnr-data-information-oai-publisher-8.0.2</developerConnection>
16
	</scm>
17
	<dependencies>
18
		<dependency>
19
			<groupId>eu.dnetlib</groupId>
20
			<artifactId>cnr-data-information-oai-publisher-common</artifactId>
21
			<version>[6.0.0,7.0.0)</version>
22
		</dependency>
23
		<dependency>
24
			<groupId>eu.dnetlib</groupId>
25
			<artifactId>dnet-oai-store-service</artifactId>
26
			<version>[8.0.0,9.0.0)</version>
27
		</dependency>
28
		<dependency>
29
			<groupId>org.springframework</groupId>
30
			<artifactId>spring-aop</artifactId>
31
			<version>${spring.version}</version>
32
		</dependency>
33
		<dependency>
34
			<groupId>junit</groupId>
35
			<artifactId>junit</artifactId>
36
			<version>${junit.version}</version>
37
			<scope>test</scope>
38
		</dependency>
39

  
40
	</dependencies>
41
</project>

Also available in: Unified diff