Revision 54627
Added by Claudio Atzori over 5 years ago
modules/dnet-modular-index-service/tags/dnet-modular-index-service-2.5.3/deploy.info | ||
---|---|---|
1 |
{ "type_source": "SVN", "goal": "package -U -T 4C source:jar", "url": "http://svn-public.driver.research-infrastructures.eu/driver/dnet45/modules/dnet-modular-index-service/trunk/", "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", "deploy_repository_url": "http://maven.research-infrastructures.eu/nexus/content/repositories/dnet45-snapshots", "name": "dnet-modular-index-service" } |
modules/dnet-modular-index-service/tags/dnet-modular-index-service-2.5.3/src/main/java/eu/dnetlib/functionality/index/IndexServerDAOMap.java | ||
---|---|---|
1 |
package eu.dnetlib.functionality.index; |
|
2 |
|
|
3 |
|
|
4 |
public interface IndexServerDAOMap { |
|
5 |
|
|
6 |
/** |
|
7 |
* Gets the index server dao. |
|
8 |
* |
|
9 |
* @param backendIdentifier |
|
10 |
* the backend identifier |
|
11 |
* @return the index server dao |
|
12 |
*/ |
|
13 |
public IndexServerDAO getIndexServerDAO(String backendIdentifier); |
|
14 |
|
|
15 |
} |
modules/dnet-modular-index-service/tags/dnet-modular-index-service-2.5.3/src/main/java/eu/dnetlib/functionality/index/utils/ServiceAddressGetter.java | ||
---|---|---|
1 |
package eu.dnetlib.functionality.index.utils; |
|
2 |
|
|
3 |
import javax.xml.ws.Endpoint; |
|
4 |
|
|
5 |
import org.springframework.beans.BeansException; |
|
6 |
import org.springframework.beans.factory.annotation.Required; |
|
7 |
import org.springframework.context.ApplicationContext; |
|
8 |
import org.springframework.context.ApplicationContextAware; |
|
9 |
|
|
10 |
import eu.dnetlib.soap.EndpointReferenceBuilder; |
|
11 |
|
|
12 |
public class ServiceAddressGetter implements ApplicationContextAware { |
|
13 |
|
|
14 |
private ApplicationContext applicationContext; |
|
15 |
|
|
16 |
private EndpointReferenceBuilder<Endpoint> eprBuilder; |
|
17 |
|
|
18 |
@Override |
|
19 |
public void setApplicationContext(final ApplicationContext applicationContext) throws BeansException { |
|
20 |
|
|
21 |
this.applicationContext = applicationContext; |
|
22 |
} |
|
23 |
|
|
24 |
public String getServiceAddress() { |
|
25 |
|
|
26 |
return getEprBuilder().getAddress(applicationContext.getBean("modularIndexServiceEndpoint", Endpoint.class)); |
|
27 |
} |
|
28 |
|
|
29 |
@Required |
|
30 |
public void setEprBuilder(final EndpointReferenceBuilder<Endpoint> eprBuilder) { |
|
31 |
this.eprBuilder = eprBuilder; |
|
32 |
} |
|
33 |
|
|
34 |
public EndpointReferenceBuilder<Endpoint> getEprBuilder() { |
|
35 |
return eprBuilder; |
|
36 |
} |
|
37 |
|
|
38 |
} |
modules/dnet-modular-index-service/tags/dnet-modular-index-service-2.5.3/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.5.3/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.5.3/src/main/java/eu/dnetlib/functionality/index/IndexBackendEnumerator.java | ||
---|---|---|
1 |
package eu.dnetlib.functionality.index; |
|
2 |
|
|
3 |
import java.util.Map; |
|
4 |
|
|
5 |
import org.springframework.beans.BeansException; |
|
6 |
import org.springframework.beans.factory.BeanFactory; |
|
7 |
import org.springframework.beans.factory.BeanFactoryAware; |
|
8 |
import org.springframework.beans.factory.ListableBeanFactory; |
|
9 |
|
|
10 |
import com.google.common.collect.Maps; |
|
11 |
|
|
12 |
/** |
|
13 |
* The Class IndexBackendEnumerator. |
|
14 |
*/ |
|
15 |
public class IndexBackendEnumerator implements BeanFactoryAware { |
|
16 |
|
|
17 |
/** The bean factory. */ |
|
18 |
private ListableBeanFactory beanFactory; |
|
19 |
|
|
20 |
/** |
|
21 |
* Gets the all. |
|
22 |
* |
|
23 |
* @return the all |
|
24 |
*/ |
|
25 |
public Map<String, IndexBackendDescriptor> getAll() { |
|
26 |
return beanFactory.getBeansOfType(IndexBackendDescriptor.class); |
|
27 |
} |
|
28 |
|
|
29 |
/** |
|
30 |
* {@inheritDoc} |
|
31 |
* |
|
32 |
* @see org.springframework.beans.factory.BeanFactoryAware#setBeanFactory(org.springframework.beans.factory.BeanFactory) |
|
33 |
*/ |
|
34 |
@Override |
|
35 |
public void setBeanFactory(final BeanFactory beanFactory) throws BeansException { |
|
36 |
this.beanFactory = (ListableBeanFactory) beanFactory; |
|
37 |
|
|
38 |
} |
|
39 |
|
|
40 |
/** |
|
41 |
* Gets the bean factory. |
|
42 |
* |
|
43 |
* @return the beanFactory |
|
44 |
*/ |
|
45 |
public ListableBeanFactory getBeanFactory() { |
|
46 |
return beanFactory; |
|
47 |
} |
|
48 |
|
|
49 |
/** |
|
50 |
* Gets the all protocols. |
|
51 |
* |
|
52 |
* @return the all protocols |
|
53 |
*/ |
|
54 |
public Map<String, String> getAllProtocols() { |
|
55 |
final Map<String, String> res = Maps.newHashMap(); |
|
56 |
for (IndexBackendDescriptor desc : getAll().values()) { |
|
57 |
String id = desc.getEndpoint().get(IndexBackendDescriptor.ID); |
|
58 |
String address = desc.getEndpoint().get(IndexBackendDescriptor.ADDRESS); |
|
59 |
res.put(id, address); |
|
60 |
} |
|
61 |
return res; |
|
62 |
} |
|
63 |
|
|
64 |
/** |
|
65 |
* Gets the all service properties. |
|
66 |
* |
|
67 |
* @return the all service properties |
|
68 |
*/ |
|
69 |
public Map<String, String> getAllServiceProperties() { |
|
70 |
final Map<String, String> res = Maps.newHashMap(); |
|
71 |
for (IndexBackendDescriptor desc : getAll().values()) { |
|
72 |
String name = desc.getEndpoint().get(IndexBackendDescriptor.ID); |
|
73 |
if (name == null) throw new IllegalStateException("Missing field name"); |
|
74 |
Map<String, String> currentProp = desc.getServiceProperties(); |
|
75 |
for (String key : currentProp.keySet()) { |
|
76 |
// Append Prefix Name to each property key |
|
77 |
res.put(name + ":" + key, currentProp.get(key)); |
|
78 |
} |
|
79 |
} |
|
80 |
return res; |
|
81 |
} |
|
82 |
|
|
83 |
@SuppressWarnings("unchecked") |
|
84 |
public <T extends IndexBackendDescriptor> T getDescriptor(final String identifier) { |
|
85 |
// TODO implement a faster access to the IndexBackendDescriptor |
|
86 |
for (IndexBackendDescriptor desc : getAll().values()) { |
|
87 |
String name = desc.getEndpoint().get(IndexBackendDescriptor.ID); |
|
88 |
if (name.equals(identifier)) return (T) desc; |
|
89 |
} |
|
90 |
return null; |
|
91 |
} |
|
92 |
|
|
93 |
} |
modules/dnet-modular-index-service/tags/dnet-modular-index-service-2.5.3/src/main/java/eu/dnetlib/functionality/index/IndexServerDAO.java | ||
---|---|---|
1 |
/* |
|
2 |
* |
|
3 |
*/ |
|
4 |
package eu.dnetlib.functionality.index; |
|
5 |
|
|
6 |
import java.util.Map; |
|
7 |
|
|
8 |
import eu.dnetlib.functionality.cql.CqlValueTransformerMap; |
|
9 |
import org.dom4j.Document; |
|
10 |
|
|
11 |
import eu.dnetlib.data.provision.index.rmi.IndexServiceException; |
|
12 |
import eu.dnetlib.functionality.index.feed.DocumentMapperFactory; |
|
13 |
import eu.dnetlib.functionality.index.model.Any.ValueType; |
|
14 |
import eu.dnetlib.functionality.index.query.IndexQueryFactory; |
|
15 |
import eu.dnetlib.functionality.index.utils.MetadataReference; |
|
16 |
|
|
17 |
/** |
|
18 |
* The Interface IndexServerDAO. |
|
19 |
*/ |
|
20 |
public interface IndexServerDAO extends IndexBackendDescriptor { |
|
21 |
|
|
22 |
/** |
|
23 |
* Creates the index collection. |
|
24 |
* |
|
25 |
* @param mdref |
|
26 |
* the mdref |
|
27 |
* @param fields |
|
28 |
* the fields |
|
29 |
* @return the index collection |
|
30 |
* @throws IndexServiceException |
|
31 |
* the index service exception |
|
32 |
*/ |
|
33 |
public void createIndexCollection(final MetadataReference mdref, final String fields) throws IndexServiceException; |
|
34 |
|
|
35 |
/** |
|
36 |
* Update index collection. |
|
37 |
* |
|
38 |
* @param mdRef |
|
39 |
* the md ref |
|
40 |
* @param fields |
|
41 |
* the fields |
|
42 |
* @throws IndexServiceException |
|
43 |
* the index service exception |
|
44 |
*/ |
|
45 |
public void updateIndexCollection(final MetadataReference mdRef, final Document fields) throws IndexServiceException; |
|
46 |
|
|
47 |
/** |
|
48 |
* Gets the index collection. |
|
49 |
* |
|
50 |
* @param mdRef |
|
51 |
* the md ref |
|
52 |
* @return the index collection |
|
53 |
* @throws IndexServiceException |
|
54 |
* the index service exception |
|
55 |
*/ |
|
56 |
public IndexCollection getIndexCollection(final MetadataReference mdRef) throws IndexServiceException; |
|
57 |
|
|
58 |
/** |
|
59 |
* Gets the schema. |
|
60 |
* |
|
61 |
* @param mdRef |
|
62 |
* the md ref |
|
63 |
* @return the schema |
|
64 |
* @throws IndexServiceException |
|
65 |
* the index service exception |
|
66 |
*/ |
|
67 |
public Map<String, ValueType> getSchema(final MetadataReference mdRef) throws IndexServiceException;; |
|
68 |
|
|
69 |
/** |
|
70 |
* Gets the cql value transformer map. |
|
71 |
* |
|
72 |
* @param mdRef |
|
73 |
* the md ref |
|
74 |
* @return the cql value transformer map |
|
75 |
* @throws IndexServiceException |
|
76 |
* the index service exception |
|
77 |
*/ |
|
78 |
public CqlValueTransformerMap getCqlValueTransformerMap(final MetadataReference mdRef) throws IndexServiceException; |
|
79 |
|
|
80 |
/** |
|
81 |
* Gets the document mapper factory. |
|
82 |
* |
|
83 |
* @return the document mapper factory |
|
84 |
* @throws IndexServiceException |
|
85 |
* the index service exception |
|
86 |
*/ |
|
87 |
public DocumentMapperFactory getDocumentMapperFactory() throws IndexServiceException; |
|
88 |
|
|
89 |
/** |
|
90 |
* Gets the index query factory. |
|
91 |
* |
|
92 |
* @return the index query factory |
|
93 |
*/ |
|
94 |
public IndexQueryFactory getIndexQueryFactory(); |
|
95 |
|
|
96 |
/** |
|
97 |
* Shutdown the index server. |
|
98 |
* |
|
99 |
* @param mdRef |
|
100 |
* the md ref |
|
101 |
* @throws IndexServiceException |
|
102 |
* the index service exception |
|
103 |
*/ |
|
104 |
public void shutdown(final MetadataReference mdRef) throws IndexServiceException; |
|
105 |
|
|
106 |
} |
modules/dnet-modular-index-service/tags/dnet-modular-index-service-2.5.3/src/main/java/eu/dnetlib/functionality/index/IndexServerDAOMapImpl.java | ||
---|---|---|
1 |
package eu.dnetlib.functionality.index; |
|
2 |
|
|
3 |
import org.springframework.beans.factory.annotation.Required; |
|
4 |
|
|
5 |
/** |
|
6 |
* The Class IndexServerDAOMapImpl. |
|
7 |
*/ |
|
8 |
public class IndexServerDAOMapImpl implements IndexServerDAOMap { |
|
9 |
|
|
10 |
/** The index enumerator. */ |
|
11 |
private IndexBackendEnumerator indexEnumerator; |
|
12 |
|
|
13 |
/** |
|
14 |
* |
|
15 |
* {@inheritDoc} |
|
16 |
* |
|
17 |
* @see eu.dnetlib.functionality.index.IndexServerDAOMap#getIndexServerDAO(java.lang.String) |
|
18 |
*/ |
|
19 |
@Override |
|
20 |
public IndexServerDAO getIndexServerDAO(final String backendIdentifier) { |
|
21 |
return indexEnumerator.getDescriptor(backendIdentifier); |
|
22 |
} |
|
23 |
|
|
24 |
/** |
|
25 |
* Gets the index enumerator. |
|
26 |
* |
|
27 |
* @return the indexEnumerator |
|
28 |
*/ |
|
29 |
public IndexBackendEnumerator getIndexEnumerator() { |
|
30 |
return indexEnumerator; |
|
31 |
} |
|
32 |
|
|
33 |
/** |
|
34 |
* Sets the index enumerator. |
|
35 |
* |
|
36 |
* @param indexEnumerator |
|
37 |
* the indexEnumerator to set |
|
38 |
*/ |
|
39 |
@Required |
|
40 |
public void setIndexEnumerator(final IndexBackendEnumerator indexEnumerator) { |
|
41 |
this.indexEnumerator = indexEnumerator; |
|
42 |
} |
|
43 |
|
|
44 |
} |
modules/dnet-modular-index-service/tags/dnet-modular-index-service-2.5.3/src/main/java/eu/dnetlib/functionality/index/IndexCollection.java | ||
---|---|---|
1 |
package eu.dnetlib.functionality.index; |
|
2 |
|
|
3 |
import java.util.Collection; |
|
4 |
import java.util.Iterator; |
|
5 |
|
|
6 |
import eu.dnetlib.data.provision.index.rmi.IndexServiceException; |
|
7 |
import eu.dnetlib.functionality.index.model.document.IndexDocument; |
|
8 |
|
|
9 |
/** |
|
10 |
* The Interface IndexCollection. |
|
11 |
*/ |
|
12 |
public interface IndexCollection { |
|
13 |
|
|
14 |
/** |
|
15 |
* Adds an input Document to the index. |
|
16 |
* |
|
17 |
* @param doc |
|
18 |
* the doc |
|
19 |
* @return the solr update response |
|
20 |
* @throws IndexServiceException |
|
21 |
* the index service exception |
|
22 |
*/ |
|
23 |
public boolean add(final IndexDocument doc) throws IndexServiceException; |
|
24 |
|
|
25 |
/** |
|
26 |
* Adds all the documents to the index giving an iterator of input documents. |
|
27 |
* |
|
28 |
* @param docs |
|
29 |
* the iterator of input documents |
|
30 |
* @return the solr update response |
|
31 |
* @throws IndexServiceException |
|
32 |
* the index service exception |
|
33 |
*/ |
|
34 |
public boolean addAll(final Iterator<IndexDocument> docs) throws IndexServiceException; |
|
35 |
|
|
36 |
/** |
|
37 |
* Adds the all. |
|
38 |
* |
|
39 |
* @param docs |
|
40 |
* the docs |
|
41 |
* @return the update response |
|
42 |
* @throws IndexServiceException |
|
43 |
* the index service exception |
|
44 |
*/ |
|
45 |
public boolean addAll(final Collection<IndexDocument> docs) throws IndexServiceException; |
|
46 |
|
|
47 |
/** |
|
48 |
* Delete index. |
|
49 |
* |
|
50 |
* @param dsId |
|
51 |
* the ds id |
|
52 |
* @return true, if successful |
|
53 |
* @throws IndexServiceException |
|
54 |
* the index service exception |
|
55 |
*/ |
|
56 |
public boolean deleteIndex(final String dsId) throws IndexServiceException; |
|
57 |
|
|
58 |
/** |
|
59 |
* Delete data from the index by query. |
|
60 |
* |
|
61 |
* @param query |
|
62 |
* the query |
|
63 |
* @param dsId |
|
64 |
* the ds id |
|
65 |
* @return true, if successful |
|
66 |
* @throws IndexServiceException |
|
67 |
* the index service exception |
|
68 |
*/ |
|
69 |
public boolean deleteByQuery(final String query, final String dsId) throws IndexServiceException; |
|
70 |
|
|
71 |
/** |
|
72 |
* Commit the data. |
|
73 |
* |
|
74 |
* @return true, if successful |
|
75 |
* @throws IndexServiceException |
|
76 |
* the index service exception |
|
77 |
*/ |
|
78 |
public boolean commit() throws IndexServiceException; |
|
79 |
|
|
80 |
/** |
|
81 |
* Releases resources and closes connections. |
|
82 |
*/ |
|
83 |
public void shutdown(); |
|
84 |
} |
modules/dnet-modular-index-service/tags/dnet-modular-index-service-2.5.3/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.5.3/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.5.3/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.5.3/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.5.3/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.5.3/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.5.3/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.5.3/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.5.3/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.cql.CqlTranslator; |
|
7 |
import eu.dnetlib.functionality.index.IndexCollection; |
|
8 |
import eu.dnetlib.functionality.index.IndexServerDAO; |
|
9 |
import eu.dnetlib.functionality.index.IndexServerDAOMap; |
|
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.5.3/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.5.3/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().getJobKey().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.5.3/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 akka.actor.ActorSystem; |
|
6 |
import akka.actor.TypedActor; |
|
7 |
import akka.actor.TypedProps; |
|
8 |
import akka.japi.Creator; |
|
9 |
import eu.dnetlib.functionality.cql.CqlTranslator; |
|
10 |
import eu.dnetlib.functionality.index.IndexServerDAOMap; |
|
11 |
import eu.dnetlib.functionality.index.utils.ServiceTools; |
|
12 |
import eu.dnetlib.miscutils.factory.Factory; |
|
13 |
import org.springframework.beans.factory.annotation.Required; |
|
14 |
|
|
15 |
// TODO springify actor parameter with a prototype bean |
|
16 |
/** |
|
17 |
* A factory for creating IndexFeedActor objects. |
|
18 |
*/ |
|
19 |
public class IndexFeedActorFactory implements Factory<IndexFeedActor> { |
|
20 |
|
|
21 |
/** The index server dao map. */ |
|
22 |
private IndexServerDAOMap indexServerDAOMap; |
|
23 |
|
|
24 |
/** The service tools. */ |
|
25 |
private ServiceTools serviceTools; |
|
26 |
|
|
27 |
/** The actor system. */ |
|
28 |
private ActorSystem actorSystem; |
|
29 |
|
|
30 |
/** CqlTranslator. */ |
|
31 |
@Resource |
|
32 |
private CqlTranslator translator; |
|
33 |
|
|
34 |
/** |
|
35 |
* {@inheritDoc} |
|
36 |
* |
|
37 |
* @see eu.dnetlib.miscutils.factory.Factory#newInstance() |
|
38 |
*/ |
|
39 |
@Override |
|
40 |
public IndexFeedActor newInstance() { |
|
41 |
return TypedActor.get(getActorSystem()).typedActorOf(new TypedProps<IndexFeedActorImpl>(IndexFeedActor.class, new Creator<IndexFeedActorImpl>() { |
|
42 |
|
|
43 |
@Override |
|
44 |
public IndexFeedActorImpl create() throws Exception { |
|
45 |
return new IndexFeedActorImpl(getIndexServerDAOMap(), getServiceTools(), translator); |
|
46 |
} |
|
47 |
})); |
|
48 |
} |
|
49 |
|
|
50 |
/** |
|
51 |
* Sets the service tools. |
|
52 |
* |
|
53 |
* @param serviceTools |
|
54 |
* the new service tools |
|
55 |
*/ |
|
56 |
@Required |
|
57 |
public void setServiceTools(final ServiceTools serviceTools) { |
|
58 |
this.serviceTools = serviceTools; |
|
59 |
} |
|
60 |
|
|
61 |
/** |
|
62 |
* Gets the service tools. |
|
63 |
* |
|
64 |
* @return the service tools |
|
65 |
*/ |
|
66 |
public ServiceTools getServiceTools() { |
|
67 |
return serviceTools; |
|
68 |
} |
|
69 |
|
|
70 |
/** |
|
71 |
* Gets the actor system. |
|
72 |
* |
|
73 |
* @return the actor system |
|
74 |
*/ |
|
75 |
public ActorSystem getActorSystem() { |
|
76 |
return actorSystem; |
|
77 |
} |
|
78 |
|
|
79 |
/** |
|
80 |
* Sets the actor system. |
|
81 |
* |
|
82 |
* @param actorSystem |
|
83 |
* the new actor system |
|
84 |
*/ |
|
85 |
@Required |
|
86 |
public void setActorSystem(final ActorSystem actorSystem) { |
|
87 |
this.actorSystem = actorSystem; |
|
88 |
} |
|
89 |
|
|
90 |
/** |
|
91 |
* Gets the index server dao map. |
|
92 |
* |
|
93 |
* @return the indexServerDAOMap |
|
94 |
*/ |
|
95 |
public IndexServerDAOMap getIndexServerDAOMap() { |
|
96 |
return indexServerDAOMap; |
|
97 |
} |
|
98 |
|
|
99 |
/** |
|
100 |
* Sets the index server dao map. |
|
101 |
* |
|
102 |
* @param indexServerDAOMap |
|
103 |
* the indexServerDAOMap to set |
|
104 |
*/ |
|
105 |
@Required |
|
106 |
public void setIndexServerDAOMap(final IndexServerDAOMap indexServerDAOMap) { |
|
107 |
this.indexServerDAOMap = indexServerDAOMap; |
|
108 |
} |
|
109 |
|
|
110 |
} |
modules/dnet-modular-index-service/tags/dnet-modular-index-service-2.5.3/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.5.3/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.5.3/src/main/java/eu/dnetlib/functionality/index/action/DeleteByQueryAction.java | ||
---|---|---|
1 |
package eu.dnetlib.functionality.index.action; |
|
2 |
|
|
3 |
import org.apache.commons.logging.Log; |
|
4 |
import org.apache.commons.logging.LogFactory; |
|
5 |
import org.springframework.beans.factory.annotation.Autowired; |
|
6 |
|
|
7 |
import eu.dnetlib.data.provision.index.rmi.IndexServiceException; |
|
8 |
import eu.dnetlib.enabling.tools.blackboard.BlackboardJob; |
|
9 |
import eu.dnetlib.enabling.tools.blackboard.BlackboardServerAction; |
|
10 |
import eu.dnetlib.enabling.tools.blackboard.BlackboardServerHandler; |
|
11 |
import eu.dnetlib.functionality.index.IndexCollection; |
|
12 |
import eu.dnetlib.functionality.index.IndexServerDAOMap; |
|
13 |
import eu.dnetlib.functionality.index.utils.MetadataReference; |
|
14 |
|
|
15 |
/** |
|
16 |
* The Delete by Query Action. It expects the query to be in Solr/Lucene format. |
|
17 |
*/ |
|
18 |
public class DeleteByQueryAction extends AbstractIndexAction implements BlackboardServerAction<IndexAction> { |
|
19 |
|
|
20 |
/** |
|
21 |
* logger. |
|
22 |
*/ |
|
23 |
private static final Log log = LogFactory.getLog(DeleteByQueryAction.class); |
|
24 |
|
|
25 |
/** The index server dao map. */ |
|
26 |
@Autowired |
|
27 |
private IndexServerDAOMap indexServerDAOMap; |
|
28 |
|
|
29 |
/** |
|
30 |
* {@inheritDoc} |
|
31 |
* |
|
32 |
* @see eu.dnetlib.enabling.tools.blackboard.BlackboardServerAction#execute(eu.dnetlib.enabling.tools.blackboard.BlackboardServerHandler, |
|
33 |
* eu.dnetlib.enabling.tools.blackboard.BlackboardJob) |
|
34 |
*/ |
|
35 |
@Override |
|
36 |
public void execute(final BlackboardServerHandler handler, final BlackboardJob job) throws IndexServiceException { |
|
37 |
final String dsId = getIndexDSId(job); |
|
38 |
if (dsId == null) throw new IndexServiceException("dsId Blackboard parameter is missing in DELETE BY QUERY message"); |
|
39 |
final MetadataReference mdRef = getMetadataReference(dsId); |
|
40 |
final String backendId = getBackend(job); |
|
41 |
if (backendId == null) throw new IndexServiceException("No backend identifier information in DELETE BY QUERY message"); |
|
42 |
final IndexCollection indexCollection = indexServerDAOMap.getIndexServerDAO(backendId).getIndexCollection(mdRef); |
|
43 |
|
|
44 |
// TODO The query should be passed in CQL format |
|
45 |
final String query = getQuery(job); |
|
46 |
|
|
47 |
log.info("DELETE BY QUERY: '" + query + "' on index '" + mdRef + "'"); |
|
48 |
|
|
49 |
// here we pass the query as it is, no dsId. |
|
50 |
if (indexCollection.deleteByQuery(query, null) == false) |
|
51 |
throw new IndexServiceException(String.format("Error to delete on index '%s', query '%s'", mdRef, query)); |
|
52 |
if (indexCollection.commit() == false) |
|
53 |
throw new IndexServiceException(String.format("Error to commit on index '%s'", mdRef)); |
|
54 |
|
|
55 |
log.info("DELETE BY QUERY done"); |
|
56 |
indexCollection.shutdown(); |
|
57 |
handler.done(job); |
|
58 |
} |
|
59 |
|
|
60 |
} |
modules/dnet-modular-index-service/tags/dnet-modular-index-service-2.5.3/src/main/java/eu/dnetlib/functionality/index/action/BBParam.java | ||
---|---|---|
1 |
package eu.dnetlib.functionality.index.action; |
|
2 |
|
|
3 |
/** |
|
4 |
* Blackboard parameter names shortcuts. |
|
5 |
* |
|
6 |
* @author claudio |
|
7 |
* |
|
8 |
*/ |
|
9 |
public final class BBParam { |
|
10 |
|
|
11 |
/** |
|
12 |
* Service id BB param name. |
|
13 |
*/ |
|
14 |
public static final String SERVICE_ID = "service_id"; |
|
15 |
|
|
16 |
/** |
|
17 |
* ResultSet epr BB param name. |
|
18 |
*/ |
|
19 |
public static final String RS_EPR = "resultset_epr"; |
|
20 |
|
|
21 |
/** |
|
22 |
* Index epr BB param name. |
Also available in: Unified diff
[maven-release-plugin] copy for tag dnet-modular-index-service-2.5.3