Project

General

Profile

« Previous | Next » 

Revision 40678

[maven-release-plugin] copy for tag dnet-modular-index-service-2.4.1

View differences:

modules/dnet-modular-index-service/tags/dnet-modular-index-service-2.4.1/src/main/resources/eu/dnetlib/functionality/index/index-ds-template.st
1
<?xml version="1.0"?>
2
<RESOURCE_PROFILE>
3
	<HEADER>
4
		<RESOURCE_IDENTIFIER value="" />
5
		<RESOURCE_TYPE value="IndexDSResourceType" />
6
		<RESOURCE_KIND value="IndexDSResources" />
7
		<RESOURCE_URI value="$serviceUri$?wsdl" />
8
		<DATE_OF_CREATION value="" />
9
	</HEADER>
10
	<BODY>
11
		<CONFIGURATION>
12
			<METADATA_FORMAT>$format$</METADATA_FORMAT>
13
			<METADATA_FORMAT_INTERPRETATION>$interpretation$</METADATA_FORMAT_INTERPRETATION>
14
			<METADATA_FORMAT_LAYOUT>$layout$</METADATA_FORMAT_LAYOUT>
15
			<BACKEND ID="$backendID$">$backendNAME$</BACKEND> 
16
			<INDEX_SIZE>0</INDEX_SIZE>
17
			<INDEX_STALE>false</INDEX_STALE>
18
		</CONFIGURATION>
19
		<STATUS>
20
			<INDEX_LAST_UPDATE />
21
		</STATUS>
22
		<SECURITY_PARAMETERS />
23
	</BODY>
24
</RESOURCE_PROFILE>
modules/dnet-modular-index-service/tags/dnet-modular-index-service-2.4.1/pom.xml
1
<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/xsd/maven-4.0.0.xsd">
2
	<modelVersion>4.0.0</modelVersion>
3
	<parent>
4
		<groupId>eu.dnetlib</groupId>
5
		<artifactId>dnet-parent</artifactId>
6
		<version>1.0.0</version>
7
	</parent>
8
	<groupId>eu.dnetlib</groupId>
9
	<artifactId>dnet-modular-index-service</artifactId>
10
	<version>2.4.1</version>
11
	<scm>
12
		<developerConnection>scm:svn:https://svn.driver.research-infrastructures.eu/driver/dnet40/modules/dnet-modular-index-service/tags/dnet-modular-index-service-2.4.1</developerConnection>
13
	</scm>
14
	<repositories>
15
		<!-- repo for Akka Actors -->
16
		<repository>
17
			<id>typesafe</id>
18
			<name>typesafe-releases</name>
19
			<url>http://maven.research-infrastructures.eu/nexus/content/repositories/typesafe</url>
20
		</repository>
21
	</repositories>
22

  
23
	<dependencies>
24
		<dependency>
25
			<groupId>eu.dnetlib</groupId>
26
			<artifactId>dnet-data-provision-rmi</artifactId>
27
			<version>[1.0.0,2.0.0)</version>
28
		</dependency>
29
		<dependency>
30
			<groupId>eu.dnetlib</groupId>
31
			<artifactId>cnr-misc-utils</artifactId>
32
			<version>[1.0.0,2.0.0)</version>
33
		</dependency>
34
		<dependency>
35
			<groupId>com.google.guava</groupId>
36
			<artifactId>guava</artifactId>
37
			<version>${google.guava.version}</version>
38
		</dependency>
39
		<dependency>
40
			<groupId>org.springframework</groupId>
41
			<artifactId>spring-beans</artifactId>
42
			<version>${spring.version}</version>
43
		</dependency>
44
		<dependency>
45
			<groupId>eu.dnetlib</groupId>
46
			<artifactId>cnr-blackboard-common</artifactId>
47
			<version>[2.1.0,3.0.0)</version>
48
		</dependency>
49

  
50
		<dependency>
51
			<groupId>eu.dnetlib</groupId>
52
			<artifactId>cnr-resultset-service</artifactId>
53
			<version>[2.0.0,3.0.0)</version>
54
		</dependency>
55

  
56
		<dependency>
57
			<groupId>eu.dnetlib</groupId>
58
			<artifactId>cnr-resultset-client</artifactId>
59
			<version>[2.0.0,3.0.0)</version>
60
		</dependency>
61
		<dependency>
62
			<groupId>eu.dnetlib</groupId>
63
			<artifactId>cnr-cql-utils</artifactId>
64
			<version>[1.0.0,2.0.0)</version>
65
		</dependency>
66

  
67
		<dependency>
68
			<groupId>apache</groupId>
69
			<artifactId>oro</artifactId>
70
			<version>2.0.8</version>
71
		</dependency>
72
		<!-- Akka Actors deps -->
73
		<dependency>
74
			<groupId>org.scala-lang</groupId>
75
			<artifactId>scala-library</artifactId>
76
			<version>2.9.2</version>
77
		</dependency>
78
		<dependency>
79
			<groupId>com.typesafe</groupId>
80
			<artifactId>config</artifactId>
81
			<version>0.3.1</version>
82
		</dependency>
83
		<dependency>
84
			<groupId>com.typesafe.akka</groupId>
85
			<artifactId>akka-actor</artifactId>
86
			<version>${akka.version}</version>
87
		</dependency>
88
		<!-- / Akka Actors deps -->
89

  
90
		<dependency>
91
			<groupId>com.google.code.gson</groupId>
92
			<artifactId>gson</artifactId>
93
			<version>${google.gson.version}</version>
94
		</dependency>
95

  
96
		<dependency>
97
			<groupId>com.mycila</groupId>
98
			<artifactId>xmltool</artifactId>
99
			<version>3.3</version>
100
		</dependency>
101

  
102
		<dependency>
103
			<groupId>junit</groupId>
104
			<artifactId>junit</artifactId>
105
			<version>${junit.version}</version>
106
			<scope>test</scope>
107
		</dependency>
108

  
109
		<dependency>
110
			<groupId>eu.dnetlib</groupId>
111
			<artifactId>dnet-index-client</artifactId>
112
			<version>[2.2.0-SNAPSHOT,3.0.0)</version>
113
		</dependency>
114
	</dependencies>
115

  
116
</project>
modules/dnet-modular-index-service/tags/dnet-modular-index-service-2.4.1/src/main/java/eu/dnetlib/functionality/index/utils/IndexDateUtility.java
1
package eu.dnetlib.functionality.index.utils;
2

  
3
import java.text.ParseException;
4
import java.text.SimpleDateFormat;
5
import java.util.Arrays;
6
import java.util.List;
7

  
8
/**
9
 * The Class IndexDateUtility.
10
 */
11
public class IndexDateUtility {
12

  
13
	/** The Constant dateFormats. */
14
	private final static List<String> dateFormats = Arrays.asList("yyyy-MM-dd'T'HH:mm:ss", "yyyy-MM-dd", "dd-MM-yyyy", "dd/MM/yyyy", "yyyy");
15

  
16
	/** The Constant outFormat. */
17
	private static final String outFormat = new String("yyyy-MM-dd'T'HH:mm:ss'Z'");
18

  
19
	/**
20
	 * method return a solr-compatible string representation of a date.
21
	 * 
22
	 * @param date
23
	 *            the date
24
	 * @return the parsed date field
25
	 */
26
	public static String getParsedDateField(final String date) {
27
		for (String formatString : dateFormats) {
28
			try {
29
				return new SimpleDateFormat(outFormat).format(new SimpleDateFormat(formatString).parse(date));
30
			} catch (ParseException e) {}
31
		}
32
		throw new IllegalStateException("unable to parse date: " + date);
33
	}
34

  
35
}
modules/dnet-modular-index-service/tags/dnet-modular-index-service-2.4.1/src/main/java/eu/dnetlib/functionality/index/feed/DocumentMapperFactory.java
1
package eu.dnetlib.functionality.index.feed;
2

  
3
import com.google.common.base.Function;
4
import eu.dnetlib.functionality.index.model.Any.ValueType;
5
import eu.dnetlib.functionality.index.model.document.IndexDocument;
6
import eu.dnetlib.functionality.index.utils.MetadataReference;
7

  
8
import java.util.Map;
9

  
10
/**
11
 * A factory for creating DocumentMapper objects.
12
 */
13
public interface DocumentMapperFactory {
14

  
15

  
16
    public Function<String, IndexDocument> getRecordMapper(final Map<String, ValueType> schema,
17
                                                           final MetadataReference mdRef,
18
                                                           final String dsId,
19
                                                           final String version,
20
                                                           final boolean emptyResult);
21

  
22

  
23
}
modules/dnet-modular-index-service/tags/dnet-modular-index-service-2.4.1/src/main/java/eu/dnetlib/functionality/index/utils/HighlightUtils.java
1
package eu.dnetlib.functionality.index.utils;
2

  
3
import org.apache.oro.text.perl.Perl5Util;
4

  
5
import eu.dnetlib.miscutils.functional.UnaryFunction;
6

  
7
/**
8
 * This function removes extra highlight tags from the given document, 
9
 * according to the CLEAN_REGEX regular expression
10
 * 
11
 * @param document
12
 * 			the document 
13
 * @return
14
 * 			cleaned document
15
 * 
16
 * @author claudio
17
 *
18
 */
19
public class HighlightUtils implements UnaryFunction<String, String> {
20
	
21
	public final static String DEFAULT_HL_PRE  = "[hl]";
22
	
23
	public final static String DEFAULT_HL_POST = "[/hl]";
24

  
25
	private static String CLEAN_HEADER = "s#\\[/?hl\\]##gm"; 
26
	private static String CLEAN_REGEX_OPEN = "<([^>]*)\\[hl\\]([^>]*)>";
27
	private static String CLEAN_REGEX_CLOSE = "<([^>]*)\\[\\/hl\\]([^>]*)>";
28
	
29
//	private static String CLEAN_REGEX_OPEN = "s#<([^>]*)\\[hl\\]([^>]*)>#<$1$2>#gm";
30
//	private static String CLEAN_REGEX_CLOSE = "s#<([^>]*)\\[\\/hl\\]([^>]*)>#<$1$2>#gm";	
31
	
32
	private Perl5Util p5util = new Perl5Util();
33
	
34
	@Override
35
	public String evaluate(String doc) {
36
		String[] chunk = doc.split("</header>");
37
		String string = cleanHeader(chunk[0]) + "</header>" + cleanBody(chunk[1]);
38
		return  string;
39
	}
40
	
41
	private String cleanHeader(String header) {
42
		return p5util.substitute(CLEAN_HEADER, header);
43
	}
44
	
45
	//TODO: implement a faster way to do this
46
	private String cleanBody(String body) {
47
		String res = body.replaceAll(CLEAN_REGEX_OPEN, "<$1$2>").replaceAll(CLEAN_REGEX_CLOSE, "<$1$2>");
48

  
49
		if (res.equals(body))
50
			return res;
51
		
52
		return cleanBody(res);
53
	}	
54
	
55
}
modules/dnet-modular-index-service/tags/dnet-modular-index-service-2.4.1/src/main/java/eu/dnetlib/functionality/index/feed/DocumentFeeder.java
1
package eu.dnetlib.functionality.index.feed;
2

  
3
import java.util.concurrent.Callable;
4

  
5
import org.apache.commons.logging.Log;
6
import org.apache.commons.logging.LogFactory;
7

  
8
import eu.dnetlib.functionality.index.IndexCollection;
9
import eu.dnetlib.functionality.index.model.document.IndexDocument;
10
import eu.dnetlib.functionality.index.utils.IndexFieldUtility;
11

  
12
/**
13
 * The Class DocumentFeeder.
14
 */
15
public class DocumentFeeder implements Callable<FeedResult> {
16

  
17
	/** The Constant log. */
18
	private static final Log log = LogFactory.getLog(DocumentFeeder.class);
19

  
20
	/** The index collection. */
21
	private IndexCollection indexCollection;
22

  
23
	/** The records. */
24
	private Iterable<IndexDocument> records;
25

  
26
	/**
27
	 * Instantiates a new document feeder.
28
	 * 
29
	 * @param indexCollection
30
	 *            the index collection
31
	 * @param records
32
	 *            the records
33
	 */
34
	public DocumentFeeder(final IndexCollection indexCollection, final Iterable<IndexDocument> records) {
35
		this.indexCollection = indexCollection;
36
		this.records = records;
37
	}
38

  
39
	/**
40
	 * {@inheritDoc}
41
	 * 
42
	 * @see java.util.concurrent.Callable#call()
43
	 */
44
	@Override
45
	public FeedResult call() throws Exception {
46
		final FeedResult res = new FeedResult(System.currentTimeMillis());
47
		for (IndexDocument doc : records) {
48
			boolean rsp;
49
			switch (doc.getStatus()) {
50

  
51
			case OK:
52
				rsp = indexCollection.add(doc);
53
				if (rsp) {
54
					res.add();
55
				} else {
56
					res.mark();
57
				}
58
				break;
59

  
60
			case MARKED:
61
				res.mark();
62
				log.debug("skipping record: " + doc.getFieldValue(IndexFieldUtility.INDEX_RECORD_ID));
63
				break;
64

  
65
			case ERROR:
66
				res.skip();
67
				log.info("Error on record: " + doc.getFieldValue(IndexFieldUtility.INDEX_RECORD_ID));
68
				break;
69

  
70
			default:
71
				throw new IllegalStateException("unknow document status");
72
			}
73
		}
74
		return res;
75
	}
76

  
77
}
modules/dnet-modular-index-service/tags/dnet-modular-index-service-2.4.1/src/main/java/eu/dnetlib/functionality/index/feed/FeedResult.java
1
package eu.dnetlib.functionality.index.feed;
2

  
3

  
4
/**
5
 * FeedResult helps verifying feeding operations
6
 * 
7
 * @author claudio
8
 * 
9
 */
10
public class FeedResult {
11

  
12
	/**
13
	 * counter of added documents.
14
	 */
15
	private Integer added = null;
16

  
17
	/**
18
	 * counter of skipped documents
19
	 */
20
	private Integer skipped = null;
21

  
22
	/**
23
	 * counter of marked-for-deletion documents.
24
	 */
25
	private Integer marked = null;
26

  
27
	/**
28
	 * marks the start of feed process.
29
	 */
30
	private long timeStart;
31

  
32
	/**
33
	 * time elapsed to complete the feeding.
34
	 */
35
	private long timeElapsed;
36

  
37
	/**
38
	 * builds a new FeedResult
39
	 * 
40
	 * @param timeStart
41
	 *            the start time of feed process.
42
	 */
43
	public FeedResult(final long timeStart) {
44
		this.added = 0;
45
		this.skipped = 0;
46
		this.marked = 0;
47
		this.timeStart = timeElapsed = timeStart;
48
	}
49

  
50
	/**
51
	 * increments added counter.
52
	 */
53
	public void add() {
54
		added++;
55
	}
56

  
57
	/**
58
	 * increments marked counter.
59
	 */
60
	public void mark() {
61
		marked++;
62
	}
63

  
64
	/**
65
	 * increments skipped counter.
66
	 */
67
	public void skip() {
68
		skipped++;
69
	}
70

  
71
	public int getAdded() {
72
		return added;
73
	}
74

  
75
	public int getSkipped() {
76
		return skipped;
77
	}
78

  
79
	public int getMarked() {
80
		return marked;
81
	}
82

  
83
	/**
84
	 * method calculates the time elapsed since the feed process has started.
85
	 * 
86
	 * @return the time elapsed since the feed process has started.
87
	 */
88
	public long getTime() {
89
		if (timeElapsed > 0) return timeElapsed - timeStart;
90
		return System.currentTimeMillis() - timeStart;
91
	}
92

  
93
	public FeedResult setTimeElapsed(final long timeElapsed) {
94
		this.timeElapsed = timeElapsed;
95
		return this;
96
	}
97

  
98
	@Override
99
	public String toString() {
100
		return "[added: " + getAdded() + " skipped: " + getSkipped() + " marked: " + getMarked() + " time: " + (getTime() / 1000) + " sec]";
101
	}
102

  
103
}
modules/dnet-modular-index-service/tags/dnet-modular-index-service-2.4.1/src/main/java/eu/dnetlib/functionality/index/IndexModularService.java
1
package eu.dnetlib.functionality.index;
2

  
3
import java.util.List;
4

  
5
import org.apache.commons.logging.Log;
6
import org.apache.commons.logging.LogFactory;
7
import org.springframework.beans.factory.annotation.Autowired;
8
import org.springframework.beans.factory.annotation.Required;
9

  
10
import eu.dnetlib.data.provision.index.rmi.IndexService;
11
import eu.dnetlib.data.provision.index.rmi.IndexServiceException;
12
import eu.dnetlib.enabling.tools.AbstractBaseService;
13
import eu.dnetlib.enabling.tools.blackboard.NotificationHandler;
14
import eu.dnetlib.functionality.index.utils.ServiceTools;
15

  
16
/**
17
 * The Class IndexModularService.
18
 */
19
public class IndexModularService extends AbstractBaseService implements IndexService {
20

  
21
	/** The Constant log. */
22
	private static final Log log = LogFactory.getLog(IndexService.class);
23

  
24
	/** The notification handler. */
25
	private NotificationHandler notificationHandler;
26

  
27
	/** The service tools. */
28
	@Autowired
29
	private ServiceTools serviceTools;
30

  
31
	/**
32
	 * {@inheritDoc}
33
	 *
34
	 * @see eu.dnetlib.common.rmi.BaseService#notify(java.lang.String, java.lang.String, java.lang.String, java.lang.String)
35
	 */
36
	@Override
37
	public void notify(final String subscriptionId, final String topic, final String isId, final String message) {
38
		log.debug("Notify method is called");
39
		getNotificationHandler().notified(subscriptionId, topic, isId, message);
40

  
41
	}
42

  
43
	/**
44
	 * {@inheritDoc}
45
	 *
46
	 * @see eu.dnetlib.common.rmi.BaseService#identify()
47
	 */
48
	@Override
49
	public String identify() {
50
		log.debug("Identify method is called");
51
		return this.getClass().toString();
52
	}
53

  
54
	/**
55
	 * {@inheritDoc}
56
	 *
57
	 * @throws IndexServiceException
58
	 *
59
	 * @see eu.dnetlib.data.provision.index.rmi.IndexService#getListOfIndices()
60
	 */
61
	@Override
62
	public List<String> getListOfIndices() throws IndexServiceException {
63

  
64
		return serviceTools.listDsIds();
65
	}
66

  
67
	/**
68
	 * Gets the notification handler.
69
	 *
70
	 * @return the notificationHandler
71
	 */
72
	public NotificationHandler getNotificationHandler() {
73
		return notificationHandler;
74
	}
75

  
76
	/**
77
	 * Sets the notification handler.
78
	 *
79
	 * @param notificationHandler
80
	 *            the notificationHandler to set
81
	 */
82
	@Required
83
	public void setNotificationHandler(final NotificationHandler notificationHandler) {
84
		this.notificationHandler = notificationHandler;
85
	}
86

  
87
}
modules/dnet-modular-index-service/tags/dnet-modular-index-service-2.4.1/src/main/java/eu/dnetlib/functionality/index/feed/FeedMode.java
1
package eu.dnetlib.functionality.index.feed;
2

  
3
/**
4
 * Allowed feed mode.
5
 * 
6
 * @author claudio
7
 * 
8
 */
9
public enum FeedMode {
10
	REFRESH, INCREMENTAL;
11
};
modules/dnet-modular-index-service/tags/dnet-modular-index-service-2.4.1/src/main/java/eu/dnetlib/functionality/index/AbstractBackendDescriptor.java
1
package eu.dnetlib.functionality.index;
2

  
3
import java.lang.reflect.Type;
4
import java.net.URI;
5
import java.util.Map;
6

  
7
import org.springframework.beans.factory.annotation.Required;
8

  
9
import com.google.common.base.Predicate;
10
import com.google.common.collect.Maps;
11
import com.google.gson.Gson;
12
import com.google.gson.reflect.TypeToken;
13

  
14
import eu.dnetlib.data.provision.index.rmi.IndexServiceException;
15

  
16
public abstract class AbstractBackendDescriptor implements IndexServerDAO {
17

  
18
	protected Type typeToken = new TypeToken<Map<String, String>>() {}.getType();
19

  
20
	private Map<String, String> serviceProperties;
21

  
22
	private String jsonConfiguration;
23

  
24
	public void init() throws IndexServiceException {
25
		try {
26
			serviceProperties = new Gson().fromJson(getJsonConfiguration(), typeToken);
27
		} catch (Throwable e) {
28
			throw new IndexServiceException("unable to parse configuration: " + jsonConfiguration, e);
29
		}
30
	}
31

  
32
	public String getJsonConfiguration() {
33
		return jsonConfiguration;
34
	}
35

  
36
	protected URI getEndpointURL() {
37
		return URI.create(getEndpoint().get(ADDRESS));
38
	}
39

  
40
	@Required
41
	public void setJsonConfiguration(final String jsonConfiguration) {
42
		this.jsonConfiguration = jsonConfiguration;
43
	}
44

  
45
	@Override
46
	public Map<String, String> getServiceProperties() {
47
		return serviceProperties;
48
	}
49

  
50
	@Override
51
	public String getBackendId() {
52
		return getServiceProperties().get(ID);
53
	}
54

  
55
	@Override
56
	public Map<String, String> getEndpoint() {
57
		return Maps.filterKeys(getServiceProperties(), new Predicate<String>() {
58

  
59
			@Override
60
			public boolean apply(final String key) {
61
				return key.equals(ID) || key.equals(ADDRESS);
62
			}
63
		});
64
	}
65

  
66
}
modules/dnet-modular-index-service/tags/dnet-modular-index-service-2.4.1/src/main/java/eu/dnetlib/functionality/index/actors/IndexFeedActor.java
1
package eu.dnetlib.functionality.index.actors;
2

  
3
import eu.dnetlib.functionality.index.feed.FeedMode;
4

  
5
/**
6
 * The Interface IndexFeedActor.
7
 */
8
public interface IndexFeedActor {
9

  
10
    /**
11
     * Feed index.
12
     *
13
     * @param dsId          the ds id
14
     * @param feedMode      the feed mode
15
     * @param docIterator   the doc iterator
16
     * @param startCallback the start callback
17
     * @param endCallback   the end callback
18
     * @param backendId     the backend identifier
19
     */
20
    void feedIndex(String dsId,
21
                   FeedMode feedMode,
22
                   Iterable<String> docIterator,
23
                   ResultsetKeepAliveCallback startCallback,
24
                   BlackboardActorCallback endCallback,
25
                   final String backendId,
26
                   boolean emptyResult);
27

  
28
}
modules/dnet-modular-index-service/tags/dnet-modular-index-service-2.4.1/src/main/java/eu/dnetlib/functionality/index/actors/IndexFeedActorImpl.java
1
package eu.dnetlib.functionality.index.actors;
2

  
3
import com.google.common.base.Function;
4
import com.google.common.collect.Iterables;
5
import eu.dnetlib.data.provision.index.rmi.IndexServiceException;
6
import eu.dnetlib.functionality.index.IndexCollection;
7
import eu.dnetlib.functionality.index.IndexServerDAO;
8
import eu.dnetlib.functionality.index.IndexServerDAOMap;
9
import eu.dnetlib.functionality.index.cql.CqlTranslator;
10
import eu.dnetlib.functionality.index.feed.DocumentFeeder;
11
import eu.dnetlib.functionality.index.feed.DocumentMapperFactory;
12
import eu.dnetlib.functionality.index.feed.FeedMode;
13
import eu.dnetlib.functionality.index.feed.FeedResult;
14
import eu.dnetlib.functionality.index.model.document.IndexDocument;
15
import eu.dnetlib.functionality.index.utils.IndexDateUtility;
16
import eu.dnetlib.functionality.index.utils.IndexFieldUtility;
17
import eu.dnetlib.functionality.index.utils.MetadataReference;
18
import eu.dnetlib.functionality.index.utils.ServiceTools;
19
import eu.dnetlib.miscutils.datetime.DateUtils;
20
import org.apache.commons.logging.Log;
21
import org.apache.commons.logging.LogFactory;
22
import org.z3950.zing.cql.CQLParseException;
23

  
24
import java.io.IOException;
25
import java.util.concurrent.ExecutorService;
26
import java.util.concurrent.Executors;
27

  
28
/**
29
 * The Class IndexFeedActorImpl.
30
 */
31
public class IndexFeedActorImpl implements IndexFeedActor {
32

  
33
    /**
34
     * The Constant log.
35
     */
36
    private static final Log log = LogFactory.getLog(IndexFeedActorImpl.class); // NOPMD by marko on 11/24/08 5:02 PM
37

  
38
    /**
39
     * The index server dao map.
40
     */
41
    private final transient IndexServerDAOMap indexServerDAOMap;
42

  
43
    /**
44
     * The service tools.
45
     */
46
    private final transient ServiceTools serviceTools;
47
    /**
48
     * Thread pool used for the feeding process.
49
     */
50
    private final transient ExecutorService threadPool = Executors.newCachedThreadPool();
51
    /**
52
     * CqlTranslator.
53
     */
54
    private CqlTranslator translator;
55

  
56
    /**
57
     * Instantiates a new index feed actor impl.
58
     *
59
     * @param indexServerDAOMap the index server dao map
60
     * @param serviceTools      the service tools
61
     */
62
    public IndexFeedActorImpl(final IndexServerDAOMap indexServerDAOMap, final ServiceTools serviceTools, final CqlTranslator translator) {
63
        super();
64
        this.indexServerDAOMap = indexServerDAOMap;
65
        this.serviceTools = serviceTools;
66
        this.translator = translator;
67
    }
68

  
69
    /**
70
     * {@inheritDoc}
71
     *
72
     * @see eu.dnetlib.functionality.index.actors.IndexFeedActor#feedIndex(java.lang.String, eu.dnetlib.functionality.index.feed.FeedMode,
73
     * java.lang.Iterable, eu.dnetlib.functionality.index.actors.ResultsetKeepAliveCallback,
74
     * eu.dnetlib.functionality.index.actors.BlackboardActorCallback)
75
     */
76
    @Override
77
    public void feedIndex(final String dsId,
78
                          final FeedMode feedMode,
79
                          final Iterable<String> docIterator,
80
                          final ResultsetKeepAliveCallback startCallback,
81
                          final BlackboardActorCallback endCallback,
82
                          final String backendId, final boolean emptyResult) {
83
        IndexCollection indexCollection = null;
84
        try {
85
            startCallback.unschedule();
86
            final MetadataReference mdref = serviceTools.getMetadataRef(dsId);
87

  
88
            final IndexServerDAO serverDAO = indexServerDAOMap.getIndexServerDAO(backendId);
89
            final DocumentMapperFactory docMapperFactory = serverDAO.getDocumentMapperFactory();
90
            final String version = DateUtils.now_ISO8601();
91
            final Function<String, IndexDocument> docMapper = docMapperFactory.getRecordMapper(serverDAO.getSchema(mdref), mdref, dsId, version, emptyResult);
92
            Iterable<IndexDocument> result = Iterables.transform(docIterator, docMapper);
93
            indexCollection = serverDAO.getIndexCollection(mdref);
94
            final FeedResult res = threadPool.submit(new DocumentFeeder(indexCollection, result)).get();
95

  
96
            cleanMarkedDocuments(indexCollection, dsId);
97
            if (feedMode.equals(FeedMode.REFRESH)) {
98
                deleteByVersion(indexCollection, dsId, version);
99
            }
100

  
101
            indexCollection.commit();
102
            indexCollection.shutdown();
103

  
104
            log.info("FeedResult: " + res.setTimeElapsed(System.currentTimeMillis()));
105
            endCallback.setJobDone();
106
        } catch (final Exception e) {
107
            endCallback.setJobFailed(e);
108
            log.error("feed index job failed", e);
109
        } finally {
110
            if (indexCollection != null) {
111
                indexCollection.shutdown();
112
            }
113
        }
114

  
115
    }
116

  
117
    /**
118
     * method deletes all the documents of a specified dsId whose {@link IndexMap}.DS_VERSION field is older than the specified
119
     * mdFormatVersion.
120
     *
121
     * @param indexCollection the server dao
122
     * @param dsId            the ds id
123
     * @param version         the version
124
     * @throws IndexServiceException the index service exception
125
     */
126
    private void deleteByVersion(final IndexCollection indexCollection, final String dsId, final String version) throws IndexServiceException {
127
        final String cqlQuery = IndexFieldUtility.DS_VERSION + " < \"" + IndexDateUtility.getParsedDateField(version) + "\"";
128
        try {
129
            String luceneQuerty = translator.getTranslatedQuery(cqlQuery).asLucene();
130
            indexCollection.deleteByQuery(luceneQuerty, dsId);
131
        } catch (CQLParseException e) {
132
            throw new IndexServiceException("Cannot parse CQL query into lucene query: " + cqlQuery, e);
133
        } catch (IOException e) {
134
            throw new IndexServiceException("Cannot parse CQL query into lucene query: " + cqlQuery, e);
135
        }
136

  
137
    }
138

  
139
    /**
140
     * method delete documents where IndexMap.DELETE_DOCUMENT field is true
141
     *
142
     * @param indexCollection the server dao
143
     * @param dsId            the ds id
144
     * @return the time elapsed to complete the operation.
145
     * @throws IndexServiceException the index service exception
146
     */
147
    public void cleanMarkedDocuments(final IndexCollection indexCollection, final String dsId) throws IndexServiceException {
148

  
149
        final String cqlQuery = IndexFieldUtility.DELETE_DOCUMENT + " all true ";
150
        try {
151
            String luceneQuery = translator.getTranslatedQuery(cqlQuery).asLucene();
152
            indexCollection.deleteByQuery(luceneQuery, dsId);
153
        } catch (CQLParseException e) {
154
            throw new IndexServiceException("Cannot parse CQL query into lucene query: " + cqlQuery, e);
155
        } catch (IOException e) {
156
            throw new IndexServiceException("Cannot parse CQL query into lucene query: " + cqlQuery, e);
157
        }
158
    }
159

  
160
}
modules/dnet-modular-index-service/tags/dnet-modular-index-service-2.4.1/src/main/resources/eu/dnetlib/functionality/index/applicationContext-index-service.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
	xmlns:util="http://www.springframework.org/schema/util"
8
	xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
9
						http://cxf.apache.org/ws/addressing http://cxf.apache.org/schemas/ws-addr-conf.xsd
10
						http://cxf.apache.org/configuration/security http://cxf.apache.org/schemas/configuration/security.xsd
11
						http://cxf.apache.org/transports/http/configuration http://cxf.apache.org/schemas/configuration/http-conf.xsd
12
						http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd
13
						http://dnetlib.eu/springbeans/template http://dnetlib.eu/springbeans/template.xsd
14
						http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd">
15

  
16

  
17
	<bean id="indexDsTemplate"
18
		class="eu.dnetlib.springutils.stringtemplate.StringTemplateFactory"
19
		p:template="classpath:/eu/dnetlib/functionality/index/index-ds-template.st"
20
		scope="prototype" />
21

  
22
	<bean id="indexServerDAOMap" class="eu.dnetlib.functionality.index.IndexServerDAOMapImpl"
23
		p:indexEnumerator-ref="indexBackendEnumerator" />
24
	 
25
	
26

  
27
	<bean id="modularIndexService" class="eu.dnetlib.functionality.index.IndexModularService"
28
		p:notificationHandler-ref="indexNotificationHandler" init-method="start"		
29
		destroy-method="stop" />
30

  
31
	<bean id="indexNotificationHandler"
32
		class="eu.dnetlib.enabling.tools.blackboard.BlackboardServerExecutorNotificationHandler"
33
		p:blackboardExecutor-ref="indexBlackboardExecutor" />
34

  
35

  
36
	<bean id="indexBlackboardExecutor"
37
		class="eu.dnetlib.enabling.tools.blackboard.BlackboardServerActionExecutor"
38
		p:blackboardHandler-ref="blackboardHandler"
39
		p:actionType="eu.dnetlib.functionality.index.action.IndexAction"
40
		p:incomplete="false">
41
		<property name="actionMap">
42
			<map>
43
				<entry key="CREATE">
44
					<bean class="eu.dnetlib.functionality.index.action.CreateIndexAction"
45
						p:indexDsTemplate-ref="indexDsTemplate" />
46
				</entry>
47
				<entry key="FEED">
48
					<bean class="eu.dnetlib.functionality.index.action.FeedIndexAction"
49
						p:jobScheduler-ref="keepAliveResultsetJobScheduler"
50
						p:rsKeepaliveJob-ref="resultsetKeepaliveJob" p:repeatDelay="${service.index.feed.repeatDelay}" />
51
				</entry>
52
				<entry key="DELETE">
53
					<bean class="eu.dnetlib.functionality.index.action.DeleteIndexAction" />
54
				</entry>
55
				<entry key="DELETE_BY_QUERY">
56
					<bean class="eu.dnetlib.functionality.index.action.DeleteByQueryAction" />
57
				</entry>
58
				<entry key="IDENTIFY">
59
					<bean class="eu.dnetlib.functionality.index.action.IdentifyAction" />
60
				</entry>
61
			</map>
62
		</property>
63
	</bean>
64

  
65

  
66

  
67
	<bean id="iterableResultSetFactory" class="eu.dnetlib.enabling.resultset.IterableResultSetFactory"
68
		p:fetchSize="10" p:resultSetFactory-ref="openResultSetFactory" />
69

  
70
	<bean id="indexBackendEnumerator" class="eu.dnetlib.functionality.index.IndexBackendEnumerator" />
71

  
72

  
73

  
74
	<!-- p:indexResultSetFactory-ref="indexResultSetFactory" -->
75

  
76

  
77

  
78
	<bean id="mdFormatNotificationHandler"
79
		class="eu.dnetlib.functionality.index.MdFormatNotificationHandler"
80
		p:enabled="${service.index.solr.nh.mdformat.enable}"
81
		p:topicExpression="UPDATE/MDFormatDSResourceType/*/RESOURCE_PROFILE/BODY/STATUS" />
82

  
83
	<jaxws:endpoint id="modularIndexServiceEndpoint"
84
		implementor="#modularIndexService" implementorClass="eu.dnetlib.data.provision.index.rmi.IndexService"
85
		address="/IndexService" />
86

  
87
	<template:instance name="serviceRegistrationManager"
88
		t:serviceRegistrationManagerClass="eu.dnetlib.enabling.tools.registration.ValidatingServiceRegistrationManagerImpl"
89
		t:name="indexServiceRegistrationManager" t:service="modularIndexService"
90
		t:endpoint="modularIndexServiceEndpoint" t:jobScheduler="jobScheduler"
91
		t:serviceRegistrator="indexServiceRegistrator" />
92

  
93
	<bean id="indexServiceRegistrator" depends-on="indexBackendEnumerator"
94
		class="eu.dnetlib.enabling.tools.registration.BlackboardServiceRegistrator"
95
		p:serviceLocator-ref="uniqueServiceLocator" p:serviceNameResolver-ref="defaultServiceNameResolver"
96
		p:hnmLocator-ref="${services.registration.default.hnmlocator}"
97
		p:eprBuilder-ref="jaxwsEndpointReferenceBuilder">
98
		<property name="extraProtocols">
99
			<bean
100
				class="org.springframework.beans.factory.config.MethodInvokingFactoryBean"
101
				p:targetObject-ref="indexBackendEnumerator" p:targetMethod="getAllProtocols" />
102
		</property>
103
		<property name="serviceProperties">
104
			<bean
105
				class="org.springframework.beans.factory.config.MethodInvokingFactoryBean"
106
				p:targetObject-ref="indexBackendEnumerator" p:targetMethod="getAllServiceProperties" />
107
		</property>
108
	</bean>
109

  
110
</beans>
modules/dnet-modular-index-service/tags/dnet-modular-index-service-2.4.1/src/main/java/eu/dnetlib/functionality/index/actors/IndexFeedActorFactory.java
1
package eu.dnetlib.functionality.index.actors;
2

  
3
import javax.annotation.Resource;
4

  
5
import org.springframework.beans.factory.annotation.Required;
6

  
7
import akka.actor.ActorSystem;
8
import akka.actor.TypedActor;
9
import akka.actor.TypedProps;
10
import akka.japi.Creator;
11
import eu.dnetlib.functionality.index.IndexServerDAOMap;
12
import eu.dnetlib.functionality.index.cql.CqlTranslator;
13
import eu.dnetlib.functionality.index.utils.ServiceTools;
14
import eu.dnetlib.miscutils.factory.Factory;
15

  
16
// TODO: Auto-generated Javadoc
17
// TODO springify actor parameter with a prototype bean
18
/**
19
 * A factory for creating IndexFeedActor objects.
20
 */
21
public class IndexFeedActorFactory implements Factory<IndexFeedActor> {
22

  
23
	/** The index server dao map. */
24
	private IndexServerDAOMap indexServerDAOMap;
25

  
26
	/** The service tools. */
27
	private ServiceTools serviceTools;
28

  
29
	/** The actor system. */
30
	private ActorSystem actorSystem;
31
	
32
	/** CqlTranslator. */
33
	@Resource
34
	private CqlTranslator translator;
35

  
36
	/**
37
	 * {@inheritDoc}
38
	 *
39
	 * @see eu.dnetlib.miscutils.factory.Factory#newInstance()
40
	 */
41
	@Override
42
	public IndexFeedActor newInstance() {
43
		return TypedActor.get(getActorSystem()).typedActorOf(new TypedProps<IndexFeedActorImpl>(IndexFeedActor.class, new Creator<IndexFeedActorImpl>() {
44

  
45
			@Override
46
			public IndexFeedActorImpl create() throws Exception {
47
				return new IndexFeedActorImpl(getIndexServerDAOMap(), getServiceTools(), translator);
48
			}
49
		}));
50
	}
51

  
52
	/**
53
	 * Sets the service tools.
54
	 *
55
	 * @param serviceTools
56
	 *            the new service tools
57
	 */
58
	@Required
59
	public void setServiceTools(final ServiceTools serviceTools) {
60
		this.serviceTools = serviceTools;
61
	}
62

  
63
	/**
64
	 * Gets the service tools.
65
	 *
66
	 * @return the service tools
67
	 */
68
	public ServiceTools getServiceTools() {
69
		return serviceTools;
70
	}
71

  
72
	/**
73
	 * Gets the actor system.
74
	 *
75
	 * @return the actor system
76
	 */
77
	public ActorSystem getActorSystem() {
78
		return actorSystem;
79
	}
80

  
81
	/**
82
	 * Sets the actor system.
83
	 *
84
	 * @param actorSystem
85
	 *            the new actor system
86
	 */
87
	@Required
88
	public void setActorSystem(final ActorSystem actorSystem) {
89
		this.actorSystem = actorSystem;
90
	}
91

  
92
	/**
93
	 * Gets the index server dao map.
94
	 *
95
	 * @return the indexServerDAOMap
96
	 */
97
	public IndexServerDAOMap getIndexServerDAOMap() {
98
		return indexServerDAOMap;
99
	}
100

  
101
	/**
102
	 * Sets the index server dao map.
103
	 *
104
	 * @param indexServerDAOMap
105
	 *            the indexServerDAOMap to set
106
	 */
107
	@Required
108
	public void setIndexServerDAOMap(final IndexServerDAOMap indexServerDAOMap) {
109
		this.indexServerDAOMap = indexServerDAOMap;
110
	}
111

  
112
}
modules/dnet-modular-index-service/tags/dnet-modular-index-service-2.4.1/deploy.info
1
{ "type_source": "SVN", "goal": "package -U -T 4C source:jar", "url": "http://svn-public.driver.research-infrastructures.eu/driver/dnet40/modules/dnet-modular-index-service/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": "dnet-modular-index-service" }
modules/dnet-modular-index-service/tags/dnet-modular-index-service-2.4.1/src/main/java/eu/dnetlib/functionality/index/actors/ActorMap.java
1
package eu.dnetlib.functionality.index.actors;
2

  
3
import java.util.Map;
4

  
5
import com.google.common.collect.Maps;
6

  
7
import eu.dnetlib.data.provision.index.rmi.IndexServiceException;
8

  
9
// TODO: Auto-generated Javadoc
10
/**
11
 * The Class ActorMap.
12
 */
13
public class ActorMap {
14

  
15
	/** Map of Index actors. */
16
	private transient Map<String, IndexFeedActor> actorMap = Maps.newConcurrentMap();
17

  
18
	/**
19
	 * Checks for actor.
20
	 * 
21
	 * @param mdref
22
	 *            the mdref
23
	 * @return true, if successful
24
	 */
25
	public boolean hasActor(final String backendId) {
26
		return actorMap.containsKey(backendId);
27
	}
28

  
29
	/**
30
	 * Gets the actor.
31
	 * 
32
	 * @param mdref
33
	 *            the mdref
34
	 * @return the actor
35
	 * @throws IndexServiceException
36
	 *             the index service exception
37
	 */
38
	public IndexFeedActor getActor(final String backendId) throws IndexServiceException {
39
		if (!hasActor(backendId)) throw new IndexServiceException("Actor not found for protocol ID " + backendId);
40
		return actorMap.get(backendId);
41
	}
42

  
43
	/**
44
	 * Adds the actor.
45
	 * 
46
	 * @param mdref
47
	 *            the mdref
48
	 * @param actor
49
	 *            the actor
50
	 */
51
	public void addActor(final String backendId, final IndexFeedActor actor) {
52
		actorMap.put(backendId, actor);
53
	}
54

  
55
}
modules/dnet-modular-index-service/tags/dnet-modular-index-service-2.4.1/src/main/java/eu/dnetlib/functionality/index/actors/ActorSystemFactory.java
1
package eu.dnetlib.functionality.index.actors;
2

  
3
import org.apache.commons.logging.Log;
4
import org.apache.commons.logging.LogFactory;
5

  
6
import akka.actor.ActorSystem;
7
import eu.dnetlib.miscutils.factory.Factory;
8

  
9
public class ActorSystemFactory implements Factory<ActorSystem>{
10

  
11
	private static final Log log = LogFactory.getLog(ActorSystemFactory.class); // NOPMD by marko on 11/24/08 5:02 PM
12
	
13
	@Override
14
	public ActorSystem newInstance() {
15
		ActorSystem actorSystem = ActorSystem.create("dnet");
16
		log.info("created new actorSystem: " + actorSystem.name());
17
		return actorSystem;
18
	}
19

  
20
}
modules/dnet-modular-index-service/tags/dnet-modular-index-service-2.4.1/src/main/java/eu/dnetlib/functionality/index/actors/BlackboardActorCallback.java
1
package eu.dnetlib.functionality.index.actors;
2

  
3
public interface BlackboardActorCallback {
4

  
5
	void setJobDone();
6
	
7
	void setJobFailed(Throwable e);	
8
}
modules/dnet-modular-index-service/tags/dnet-modular-index-service-2.4.1/src/main/java/eu/dnetlib/functionality/index/actors/ResultsetKeepAliveJob.java
1
package eu.dnetlib.functionality.index.actors;
2

  
3
import javax.xml.ws.wsaddressing.W3CEndpointReference;
4

  
5
import org.apache.commons.logging.Log;
6
import org.apache.commons.logging.LogFactory;
7
import org.quartz.Job;
8
import org.quartz.JobExecutionContext;
9
import org.quartz.JobExecutionException;
10

  
11
import eu.dnetlib.enabling.resultset.client.utils.EPRUtils;
12
import eu.dnetlib.enabling.resultset.rmi.ResultSetException;
13
import eu.dnetlib.enabling.resultset.rmi.ResultSetService;
14
import eu.dnetlib.enabling.tools.ServiceResolver;
15
import eu.dnetlib.functionality.index.action.BBParam;
16

  
17
public class ResultsetKeepAliveJob implements Job {
18

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

  
21
	public static final String JOB_NAME = "resultsetKeepaliveJob";
22

  
23
	public static final String JOB_GROUP = "keepalive";
24

  
25
	/**
26
	 * used to resolve the epr references to the service endpoint
27
	 */
28
	private ServiceResolver serviceResolver;
29

  
30
	private EPRUtils eprUtils;
31

  
32
	@Override
33
	public void execute(final JobExecutionContext context) throws JobExecutionException {
34

  
35
		final String rsEpr = (String) context.getTrigger().getJobDataMap().get(BBParam.RS_EPR);
36
		final W3CEndpointReference epr = eprUtils.getEpr(rsEpr);
37

  
38
		final ResultSetService resultSet = getServiceResolver().getService(ResultSetService.class, epr);
39
		final String rsId = serviceResolver.getResourceIdentifier(epr);
40

  
41
		try {
42
			log.debug("\n\n keepalive resultset: " + rsId + " triggerId: " + context.getTrigger().getName() + "\n\n");
43

  
44
			// TODO: change to a getRSStatus call, getNumberOfElements could be potentially slow (ticket #1569)
45
			resultSet.getNumberOfElements(rsId);
46
		} catch (ResultSetException e) {
47
			log.warn("couldn't invoke the resultset call to keep-it-alive");
48
			throw new RuntimeException(e);
49
		}
50
	}
51

  
52
	public void setServiceResolver(final ServiceResolver serviceResolver) {
53
		this.serviceResolver = serviceResolver;
54
	}
55

  
56
	public ServiceResolver getServiceResolver() {
57
		return serviceResolver;
58
	}
59

  
60
	public void setEprUtils(final EPRUtils eprUtils) {
61
		this.eprUtils = eprUtils;
62
	}
63

  
64
	public EPRUtils getEprUtils() {
65
		return eprUtils;
66
	}
67

  
68
}
modules/dnet-modular-index-service/tags/dnet-modular-index-service-2.4.1/src/main/java/eu/dnetlib/functionality/index/actors/ResultsetKeepAliveCallback.java
1
package eu.dnetlib.functionality.index.actors;
2

  
3
public interface ResultsetKeepAliveCallback {
4
	
5
	void unschedule();
6
}
modules/dnet-modular-index-service/tags/dnet-modular-index-service-2.4.1/src/main/java/eu/dnetlib/functionality/index/action/FeedIndexAction.java
1
package eu.dnetlib.functionality.index.action;
2

  
3
import eu.dnetlib.data.provision.index.rmi.IndexServiceException;
4
import eu.dnetlib.enabling.resultset.client.IterableResultSetClient;
5
import eu.dnetlib.enabling.resultset.client.ResultSetClientFactory;
6
import eu.dnetlib.enabling.tools.blackboard.BlackboardJob;
7
import eu.dnetlib.enabling.tools.blackboard.BlackboardServerAction;
8
import eu.dnetlib.enabling.tools.blackboard.BlackboardServerHandler;
9
import eu.dnetlib.functionality.index.actors.*;
10
import eu.dnetlib.functionality.index.feed.FeedMode;
11
import org.apache.commons.logging.Log;
12
import org.apache.commons.logging.LogFactory;
13
import org.quartz.JobDetail;
14
import org.quartz.Scheduler;
15
import org.quartz.SchedulerException;
16
import org.quartz.SimpleTrigger;
17
import org.springframework.beans.factory.annotation.Autowired;
18
import org.springframework.beans.factory.annotation.Required;
19

  
20
import java.util.UUID;
21

  
22
/**
23
 * The Class FeedIndexAction.
24
 */
25
public class FeedIndexAction extends AbstractIndexAction implements BlackboardServerAction<IndexAction> {
26

  
27
    /**
28
     * The Constant log.
29
     */
30
    private static final Log log = LogFactory.getLog(FeedIndexAction.class);
31

  
32
    /**
33
     * The actor map.
34
     */
35
    @Autowired
36
    private ActorMap actorMap;
37

  
38
    /**
39
     * The feed actor factory.
40
     */
41
    @Autowired
42
    private IndexFeedActorFactory feedActorFactory;
43

  
44
    /**
45
     * The result set client factory.
46
     */
47
    @Autowired
48
    private transient ResultSetClientFactory resultSetClientFactory;
49

  
50
    /**
51
     * Start deferred jobs, used to keep resultsets alive.
52
     */
53
    private Scheduler jobScheduler;
54

  
55
    /**
56
     * ResultSet keep alive JobDetail.
57
     */
58
    private transient JobDetail rsKeepaliveJob;
59

  
60
    /**
61
     * ResultSet keepAlive trigger's repeat delay.
62
     */
63

  
64
    private long repeatDelay;
65

  
66
    /**
67
     * {@inheritDoc}
68
     *
69
     * @see eu.dnetlib.enabling.tools.blackboard.BlackboardServerAction#execute(eu.dnetlib.enabling.tools.blackboard.BlackboardServerHandler,
70
     * eu.dnetlib.enabling.tools.blackboard.BlackboardJob)
71
     */
72
    @Override
73
    public void execute(final BlackboardServerHandler handler, final BlackboardJob job) throws Exception {
74
        handler.ongoing(job);
75
        log.info("FEED job set to ONGOING");
76

  
77
        final JobDetail tmp = getJobScheduler().getJobDetail(ResultsetKeepAliveJob.JOB_NAME, ResultsetKeepAliveJob.JOB_GROUP);
78
        final String epr = getEpr(job);
79
        final String triggerId = UUID.randomUUID().toString();
80
        final String dsId = getIndexDSId(job);
81
        final FeedMode feedMode = getFeedMode(job);
82
        final String backendId = getBackend(job);
83
        final boolean emptyResult = getEmptyResult(job);
84
        if (backendId == null) throw new IndexServiceException("No backend identifier information in CREATE message");
85

  
86
        if (tmp == null) {
87
            log.fatal("re-registering job detail");
88
            getJobScheduler().addJob(getRsKeepaliveJob(), true);
89
        }
90
        log.debug("\n\n scheduling resultSet keepalive trigger: " + triggerId + "\n\n");
91
        getJobScheduler().scheduleJob(getResultsetTrigger(epr, triggerId));
92
        if (!actorMap.hasActor(backendId)) {
93
            actorMap.addActor(backendId, feedActorFactory.newInstance());
94
        }
95
        IterableResultSetClient rsClient = resultSetClientFactory.getClient(epr);
96

  
97
        actorMap.getActor(backendId).feedIndex(dsId, feedMode, rsClient, newRSKeepAliveCallback(triggerId), newBBActorCallback(handler, job), backendId, emptyResult);
98
    }
99

  
100
    private boolean getEmptyResult(BlackboardJob job) {
101

  
102
        if (job.getParameters().containsKey("emptyResult")) {
103
            final String emptyResult = job.getParameters().get("emptyResult").toLowerCase().trim();
104
            return "true".equals(emptyResult);
105

  
106
        } else return false;
107
    }
108

  
109
    /**
110
     * Constructor for triggers used by the resultSet keepAlive job.
111
     *
112
     * @param rsEpr     resultSet epr to keep alive.
113
     * @param triggerId trigger identifier.
114
     * @return a new org.quartz.SimpleTrigger instance.
115
     */
116
    private SimpleTrigger getResultsetTrigger(final String rsEpr, final String triggerId) {
117
        final SimpleTrigger trigger = new SimpleTrigger(triggerId, ResultsetKeepAliveJob.JOB_GROUP, SimpleTrigger.REPEAT_INDEFINITELY, getRepeatDelay());
118
        trigger.getJobDataMap().put(BBParam.RS_EPR, rsEpr);
119
        trigger.setJobName(ResultsetKeepAliveJob.JOB_NAME);
120
        trigger.setJobGroup(ResultsetKeepAliveJob.JOB_GROUP);
121
        return trigger;
122
    }
123

  
124
    /**
125
     * Constructor for a blackboard callback to handle the job termination.
126
     *
127
     * @param handler the handler
128
     * @param job     the BB job.
129
     * @return a new eu.dnetlib.functionality.index.solr.actors.BlackboardActorCallback
130
     */
131
    private BlackboardActorCallback newBBActorCallback(final BlackboardServerHandler handler, final BlackboardJob job) {
132
        return new BlackboardActorCallback() {
133

  
134
            @Override
135
            public void setJobDone() {
136
                log.info(job.getAction() + " job set to DONE");
137
                handler.done(job);
138
            }
139

  
140
            @Override
141
            public void setJobFailed(final Throwable exception) {
142
                log.error(job.getAction() + " job set to FAILED ", exception);
143
                handler.failed(job, exception);
144
            }
145
        };
146
    }
147

  
148
    /**
149
     * Constructor for a resultSet keepAlive callbacks.
150
     *
151
     * @param triggerId trigger identifier.
152
     * @return a new eu.dnetlib.functionality.index.solr.actors.ResultsetKeepAliveCallback
153
     */
154
    private ResultsetKeepAliveCallback newRSKeepAliveCallback(final String triggerId) {
155
        return new ResultsetKeepAliveCallback() {
156

  
157
            @Override
158
            public void unschedule() {
159
                try {
160
                    log.info("\n\n unscheduling resultSet keepalive trigger: " + triggerId + "\n\n");
161
                    jobScheduler.unscheduleJob(triggerId, ResultsetKeepAliveJob.JOB_GROUP);
162
                } catch (SchedulerException e) {
163
                    log.warn("cannot unschedule RSKeepAlive triggerId: " + triggerId);
164
                    throw new RuntimeException(e); // NOPMD
165
                }
166
            }
167
        };
168
    }
169

  
170
    /**
171
     * Gets the rs keepalive job.
172
     *
173
     * @return the rsKeepaliveJob
174
     */
175
    public JobDetail getRsKeepaliveJob() {
176
        return rsKeepaliveJob;
177
    }
178

  
179
    /**
180
     * Sets the rs keepalive job.
181
     *
182
     * @param rsKeepaliveJob the rsKeepaliveJob to set
183
     */
184
    @Required
185
    public void setRsKeepaliveJob(final JobDetail rsKeepaliveJob) {
186
        this.rsKeepaliveJob = rsKeepaliveJob;
187
    }
188

  
189
    /**
190
     * Gets the job scheduler.
191
     *
192
     * @return the jobScheduler
193
     */
194
    public Scheduler getJobScheduler() {
195
        return jobScheduler;
196
    }
197

  
198
    /**
199
     * Sets the job scheduler.
200
     *
201
     * @param jobScheduler the jobScheduler to set
202
     */
203
    @Required
204
    public void setJobScheduler(final Scheduler jobScheduler) {
205
        this.jobScheduler = jobScheduler;
206
    }
207

  
208
    /**
209
     * Gets the repeat delay.
210
     *
211
     * @return the repeatDelay
212
     */
213
    public long getRepeatDelay() {
214
        return repeatDelay;
215
    }
216

  
217
    /**
218
     * Sets the repeat delay.
219
     *
220
     * @param repeatDelay the repeatDelay to set
221
     */
222
    @Required
223
    public void setRepeatDelay(final long repeatDelay) {
224
        this.repeatDelay = repeatDelay;
225
    }
226

  
227
}
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff