Revision 31477
Added by Alessia Bardi almost 10 years ago
modules/dnet-index-client/tags/dnet-index-client-1.1.0/pom.xml | ||
---|---|---|
1 |
<?xml version="1.0" encoding="UTF-8"?> |
|
2 |
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> |
|
3 |
<parent> |
|
4 |
<groupId>eu.dnetlib</groupId> |
|
5 |
<artifactId>dnet-parent</artifactId> |
|
6 |
<version>1.0.0</version> |
|
7 |
<relativePath /> |
|
8 |
</parent> |
|
9 |
<modelVersion>4.0.0</modelVersion> |
|
10 |
<groupId>eu.dnetlib</groupId> |
|
11 |
<artifactId>dnet-index-client</artifactId> |
|
12 |
<packaging>jar</packaging> |
|
13 |
<version>1.1.0</version> |
|
14 |
<scm> |
|
15 |
<developerConnection>scm:svn:https://svn.driver.research-infrastructures.eu/driver/dnet40/modules/dnet-index-client/tags/dnet-index-client-1.1.0</developerConnection> |
|
16 |
</scm> |
|
17 |
<dependencies> |
|
18 |
<dependency> |
|
19 |
<groupId>org.springframework</groupId> |
|
20 |
<artifactId>spring-beans</artifactId> |
|
21 |
<version>${spring.version}</version> |
|
22 |
</dependency> |
|
23 |
<dependency> |
|
24 |
<groupId>junit</groupId> |
|
25 |
<artifactId>junit</artifactId> |
|
26 |
<version>${junit.version}</version> |
|
27 |
<scope>test</scope> |
|
28 |
</dependency> |
|
29 |
<dependency> |
|
30 |
<groupId>org.mockito</groupId> |
|
31 |
<artifactId>mockito-core</artifactId> |
|
32 |
<version>1.6</version> |
|
33 |
<scope>test</scope> |
|
34 |
</dependency> |
|
35 |
<dependency> |
|
36 |
<groupId>com.google.code.gson</groupId> |
|
37 |
<artifactId>gson</artifactId> |
|
38 |
<version>${google.gson.version}</version> |
|
39 |
</dependency> |
|
40 |
|
|
41 |
<dependency> |
|
42 |
<groupId>com.mycila</groupId> |
|
43 |
<artifactId>xmltool</artifactId> |
|
44 |
<version>3.3</version> |
|
45 |
</dependency> |
|
46 |
<dependency> |
|
47 |
<groupId>eu.dnetlib</groupId> |
|
48 |
<artifactId>cnr-service-common</artifactId> |
|
49 |
<version>[1.0.0,2.0.0)</version> |
|
50 |
|
|
51 |
</dependency> |
|
52 |
<dependency> |
|
53 |
<groupId>eu.dnetlib</groupId> |
|
54 |
<artifactId>cnr-cql-utils</artifactId> |
|
55 |
<version>[1.0.0,2.0.0)</version> |
|
56 |
</dependency> |
|
57 |
<dependency> |
|
58 |
<groupId>eu.dnetlib</groupId> |
|
59 |
<artifactId>dnet-data-provision-rmi</artifactId> |
|
60 |
<version>[1.0.0,2.0.0)</version> |
|
61 |
</dependency> |
|
62 |
</dependencies> |
|
63 |
</project> |
modules/dnet-index-client/tags/dnet-index-client-1.1.0/src/main/java/eu/dnetlib/functionality/index/client/IndexClient.java | ||
---|---|---|
1 |
package eu.dnetlib.functionality.index.client; |
|
2 |
|
|
3 |
import java.util.List; |
|
4 |
|
|
5 |
import eu.dnetlib.functionality.index.client.response.BrowseEntry; |
|
6 |
import eu.dnetlib.functionality.index.client.response.LookupResponse; |
|
7 |
|
|
8 |
public interface IndexClient { |
|
9 |
|
|
10 |
LookupResponse lookup(String query, List<String> filterQuery, int from, int to) throws IndexClientException; |
|
11 |
|
|
12 |
List<BrowseEntry> browse(String query, List<String> browseFields, int max) throws IndexClientException; |
|
13 |
|
|
14 |
List<BrowseEntry> browse(String query, List<String> browseFields, int max, List<String> filterQuery) throws IndexClientException; |
|
15 |
|
|
16 |
long delete(String query) throws IndexClientException; |
|
17 |
|
|
18 |
void stop() throws IndexClientException; |
|
19 |
|
|
20 |
} |
modules/dnet-index-client/tags/dnet-index-client-1.1.0/src/main/java/eu/dnetlib/functionality/index/client/AbstractIndexClient.java | ||
---|---|---|
1 |
package eu.dnetlib.functionality.index.client; |
|
2 |
|
|
3 |
import java.util.Map; |
|
4 |
|
|
5 |
import eu.dnetlib.functionality.index.cql.CqlValueTransformerMap; |
|
6 |
import eu.dnetlib.functionality.index.query.IndexQueryFactory; |
|
7 |
import eu.dnetlib.functionality.index.utils.MetadataReference; |
|
8 |
|
|
9 |
public abstract class AbstractIndexClient implements IndexClient { |
|
10 |
|
|
11 |
protected static String INDEX_HOST = "host"; |
|
12 |
protected static String INDEX_PORT = "port"; |
|
13 |
protected static String INDEX_BACKEND_ID = "id"; |
|
14 |
protected static String ZK_ADDRESS = "address"; |
|
15 |
|
|
16 |
/** The format. */ |
|
17 |
private String format; |
|
18 |
|
|
19 |
/** The layout. */ |
|
20 |
private String layout; |
|
21 |
|
|
22 |
/** The interpretation. */ |
|
23 |
private String interpretation; |
|
24 |
|
|
25 |
protected Map<String, String> serviceProperties; |
|
26 |
|
|
27 |
public AbstractIndexClient(final String format, final String layout, final String interpretation, final Map<String, String> serviceProperties) { |
|
28 |
this.format = format; |
|
29 |
this.layout = layout; |
|
30 |
this.interpretation = interpretation; |
|
31 |
this.serviceProperties = serviceProperties; |
|
32 |
} |
|
33 |
|
|
34 |
public abstract CqlValueTransformerMap getCqlValueTransformerMap(MetadataReference mdRef) throws IndexClientException; |
|
35 |
|
|
36 |
public abstract IndexQueryFactory getIndexQueryFactory(); |
|
37 |
|
|
38 |
/** |
|
39 |
* Gets the format. |
|
40 |
* |
|
41 |
* @return the format |
|
42 |
*/ |
|
43 |
public String getFormat() { |
|
44 |
return format; |
|
45 |
} |
|
46 |
|
|
47 |
/** |
|
48 |
* Sets the format. |
|
49 |
* |
|
50 |
* @param format |
|
51 |
* the format |
|
52 |
*/ |
|
53 |
public void setFormat(final String format) { |
|
54 |
this.format = format; |
|
55 |
} |
|
56 |
|
|
57 |
/** |
|
58 |
* Gets the layout. |
|
59 |
* |
|
60 |
* @return the layout |
|
61 |
*/ |
|
62 |
public String getLayout() { |
|
63 |
return layout; |
|
64 |
} |
|
65 |
|
|
66 |
/** |
|
67 |
* Sets the layout. |
|
68 |
* |
|
69 |
* @param layout |
|
70 |
* the layout |
|
71 |
*/ |
|
72 |
public void setLayout(final String layout) { |
|
73 |
this.layout = layout; |
|
74 |
} |
|
75 |
|
|
76 |
/** |
|
77 |
* Gets the interpretation. |
|
78 |
* |
|
79 |
* @return the interpretation |
|
80 |
*/ |
|
81 |
public String getInterpretation() { |
|
82 |
return interpretation; |
|
83 |
} |
|
84 |
|
|
85 |
/** |
|
86 |
* Sets the interpretation. |
|
87 |
* |
|
88 |
* @param interpretation |
|
89 |
* the interpretation |
|
90 |
*/ |
|
91 |
public void setInterpretation(final String interpretation) { |
|
92 |
this.interpretation = interpretation; |
|
93 |
} |
|
94 |
|
|
95 |
public Map<String, String> getServiceProperties() { |
|
96 |
return serviceProperties; |
|
97 |
} |
|
98 |
|
|
99 |
public void setServiceProperties(final Map<String, String> serviceProperties) { |
|
100 |
this.serviceProperties = serviceProperties; |
|
101 |
} |
|
102 |
|
|
103 |
} |
modules/dnet-index-client/tags/dnet-index-client-1.1.0/src/main/java/eu/dnetlib/functionality/index/client/AbstractIndexClientFactory.java | ||
---|---|---|
1 |
package eu.dnetlib.functionality.index.client; |
|
2 |
|
|
3 |
import org.springframework.beans.factory.annotation.Autowired; |
|
4 |
|
|
5 |
import eu.dnetlib.functionality.index.utils.ServiceTools; |
|
6 |
|
|
7 |
/** |
|
8 |
* The Class AbstractIndexClientFactory. |
|
9 |
*/ |
|
10 |
public abstract class AbstractIndexClientFactory implements IndexClientFactory { |
|
11 |
|
|
12 |
/** The backend id. */ |
|
13 |
private String backendId; |
|
14 |
|
|
15 |
@Autowired |
|
16 |
protected ServiceTools isQueryTools; |
|
17 |
|
|
18 |
/** |
|
19 |
* Inits the class. |
|
20 |
*/ |
|
21 |
public abstract void init() throws IndexClientException; |
|
22 |
|
|
23 |
/** |
|
24 |
* {@inheritDoc} |
|
25 |
* |
|
26 |
* @see eu.dnetlib.functionality.index.client.IndexClientFactory#getBackendId() |
|
27 |
*/ |
|
28 |
@Override |
|
29 |
public String getBackendId() { |
|
30 |
return backendId; |
|
31 |
} |
|
32 |
|
|
33 |
/** |
|
34 |
* Sets the backend id. |
|
35 |
* |
|
36 |
* @param backendId |
|
37 |
* the backend id |
|
38 |
*/ |
|
39 |
public void setBackendId(final String backendId) { |
|
40 |
this.backendId = backendId; |
|
41 |
} |
|
42 |
|
|
43 |
} |
modules/dnet-index-client/tags/dnet-index-client-1.1.0/src/main/java/eu/dnetlib/functionality/index/client/IndexClientException.java | ||
---|---|---|
1 |
package eu.dnetlib.functionality.index.client; |
|
2 |
|
|
3 |
import eu.dnetlib.data.provision.index.rmi.IndexServiceException; |
|
4 |
|
|
5 |
public class IndexClientException extends IndexServiceException { |
|
6 |
|
|
7 |
/** |
|
8 |
* |
|
9 |
*/ |
|
10 |
private static final long serialVersionUID = 1851955470714206331L; |
|
11 |
|
|
12 |
public IndexClientException() { |
|
13 |
super(); |
|
14 |
} |
|
15 |
|
|
16 |
public IndexClientException(final String message) { |
|
17 |
super(message); |
|
18 |
} |
|
19 |
|
|
20 |
public IndexClientException(final Throwable cause) { |
|
21 |
super(cause); |
|
22 |
} |
|
23 |
|
|
24 |
public IndexClientException(final String message, final Throwable cause) { |
|
25 |
super(message, cause); |
|
26 |
} |
|
27 |
|
|
28 |
} |
modules/dnet-index-client/tags/dnet-index-client-1.1.0/src/main/java/eu/dnetlib/functionality/index/query/Weights.java | ||
---|---|---|
1 |
package eu.dnetlib.functionality.index.query; |
|
2 |
|
|
3 |
import java.util.HashMap; |
|
4 |
import java.util.Map; |
|
5 |
|
|
6 |
import org.apache.commons.logging.Log; |
|
7 |
import org.apache.commons.logging.LogFactory; |
|
8 |
import org.springframework.beans.factory.annotation.Autowired; |
|
9 |
|
|
10 |
import eu.dnetlib.functionality.index.client.IndexClientException; |
|
11 |
import eu.dnetlib.functionality.index.utils.MDFormatReader; |
|
12 |
import eu.dnetlib.functionality.index.utils.MetadataReference; |
|
13 |
import eu.dnetlib.functionality.index.utils.ServiceTools; |
|
14 |
|
|
15 |
public class Weights extends HashMap<MetadataReference, Map<String, String>> { |
|
16 |
|
|
17 |
private static final long serialVersionUID = -3517914310574484765L; |
|
18 |
|
|
19 |
private static final Log log = LogFactory.getLog(Weights.class); // NOPMD by marko on 11/24/08 5:02 PM |
|
20 |
|
|
21 |
@Autowired |
|
22 |
private ServiceTools serviceTools; |
|
23 |
|
|
24 |
@Autowired |
|
25 |
private MDFormatReader mdFormatReader; |
|
26 |
|
|
27 |
public Weights() { |
|
28 |
super(); |
|
29 |
} |
|
30 |
|
|
31 |
public void initialize() throws IndexClientException { |
|
32 |
log.info("initializing weights"); |
|
33 |
|
|
34 |
for (MetadataReference mdRef : serviceTools.listMDRefs()) { |
|
35 |
put(mdRef, mdFormatReader.getAttributeMap(mdRef, "weight")); |
|
36 |
} |
|
37 |
log.info("weights initialization completed"); |
|
38 |
|
|
39 |
} |
|
40 |
|
|
41 |
@Override |
|
42 |
public Map<String, String> put(final MetadataReference mdRef, final Map<String, String> w) { |
|
43 |
log.info("[" + mdRef + "]" + " adding weights: " + w); |
|
44 |
return super.put(mdRef, w); |
|
45 |
} |
|
46 |
|
|
47 |
@Override |
|
48 |
public Map<String, String> get(final Object mdRef) { |
|
49 |
Map<String, String> map = super.get(mdRef); |
|
50 |
return map != null ? map : initAndGet(mdRef); |
|
51 |
} |
|
52 |
|
|
53 |
private Map<String, String> initAndGet(final Object mdRef) { |
|
54 |
try { |
|
55 |
initialize(); |
|
56 |
} catch (IndexClientException e) { |
|
57 |
throw new RuntimeException(e); |
|
58 |
} |
|
59 |
return super.get(mdRef); |
|
60 |
} |
|
61 |
} |
modules/dnet-index-client/tags/dnet-index-client-1.1.0/src/main/java/eu/dnetlib/functionality/index/client/ResolvingIndexClientFactory.java | ||
---|---|---|
1 |
package eu.dnetlib.functionality.index.client; |
|
2 |
|
|
3 |
import java.util.List; |
|
4 |
|
|
5 |
import javax.annotation.Resource; |
|
6 |
|
|
7 |
import eu.dnetlib.enabling.is.lookup.rmi.ISLookUpService; |
|
8 |
import eu.dnetlib.enabling.tools.ServiceLocator; |
|
9 |
|
|
10 |
/** |
|
11 |
* The Class GlobalIndexClientFactory. |
|
12 |
*/ |
|
13 |
|
|
14 |
/** |
|
15 |
* The Class ResolvingIndexClientFactory. |
|
16 |
*/ |
|
17 |
public class ResolvingIndexClientFactory { |
|
18 |
|
|
19 |
/** The index client factories. */ |
|
20 |
@Resource |
|
21 |
private List<IndexClientFactory> indexClientFactories; |
|
22 |
|
|
23 |
/** The lookup locator. */ |
|
24 |
@Resource(name = "lookupLocator") |
|
25 |
private ServiceLocator<ISLookUpService> lookupLocator; |
|
26 |
|
|
27 |
/** |
|
28 |
* Gets the client. |
|
29 |
* |
|
30 |
* @param format |
|
31 |
* the format |
|
32 |
* @param layout |
|
33 |
* the layout |
|
34 |
* @param interpretation |
|
35 |
* the interpretation |
|
36 |
* @param backendId |
|
37 |
* the backend id |
|
38 |
* @return the client |
|
39 |
* @throws IndexClientException |
|
40 |
* the index client exception |
|
41 |
*/ |
|
42 |
public IndexClient getClient(final String format, final String layout, final String interpretation, final String backendId) throws IndexClientException { |
|
43 |
for (IndexClientFactory factory : indexClientFactories) { |
|
44 |
if (factory.getBackendId().equalsIgnoreCase(backendId)) return factory.getClient(format, layout, interpretation); |
|
45 |
} |
|
46 |
throw new IndexClientException("No client for bakendId: " + backendId); |
|
47 |
} |
|
48 |
|
|
49 |
} |
modules/dnet-index-client/tags/dnet-index-client-1.1.0/src/main/java/eu/dnetlib/functionality/index/client/IndexClientFactory.java | ||
---|---|---|
1 |
package eu.dnetlib.functionality.index.client; |
|
2 |
|
|
3 |
public interface IndexClientFactory { |
|
4 |
|
|
5 |
String getBackendId(); |
|
6 |
|
|
7 |
IndexClient getClient(String format, String layout, String interpretation) throws IndexClientException; |
|
8 |
|
|
9 |
} |
modules/dnet-index-client/tags/dnet-index-client-1.1.0/src/main/java/eu/dnetlib/functionality/index/client/response/LookupResponse.java | ||
---|---|---|
1 |
package eu.dnetlib.functionality.index.client.response; |
|
2 |
|
|
3 |
import java.util.List; |
|
4 |
|
|
5 |
import javax.xml.bind.annotation.XmlRootElement; |
|
6 |
|
|
7 |
import eu.dnetlib.functionality.index.query.QueryResponseParser; |
|
8 |
|
|
9 |
@XmlRootElement |
|
10 |
public class LookupResponse { |
|
11 |
|
|
12 |
private long total; |
|
13 |
private long from; |
|
14 |
private long to; |
|
15 |
private List<String> records; |
|
16 |
|
|
17 |
public LookupResponse() {} |
|
18 |
|
|
19 |
public LookupResponse(final QueryResponseParser parser) { |
|
20 |
this.total = parser.getNumFound(); |
|
21 |
this.from = parser.getStart(); |
|
22 |
this.to = parser.getStart() + parser.getResults().size(); |
|
23 |
this.records = parser.getResults(); |
|
24 |
|
|
25 |
} |
|
26 |
|
|
27 |
public LookupResponse(final long total, final long from, final long to, final List<String> records) { |
|
28 |
this.total = total; |
|
29 |
this.from = from; |
|
30 |
this.to = to; |
|
31 |
this.records = records; |
|
32 |
} |
|
33 |
|
|
34 |
public long getTotal() { |
|
35 |
return total; |
|
36 |
} |
|
37 |
|
|
38 |
public void setTotal(final long total) { |
|
39 |
this.total = total; |
|
40 |
} |
|
41 |
|
|
42 |
public long getFrom() { |
|
43 |
return from; |
|
44 |
} |
|
45 |
|
|
46 |
public void setFrom(final long from) { |
|
47 |
this.from = from; |
|
48 |
} |
|
49 |
|
|
50 |
public long getTo() { |
|
51 |
return to; |
|
52 |
} |
|
53 |
|
|
54 |
public void setTo(final long to) { |
|
55 |
this.to = to; |
|
56 |
} |
|
57 |
|
|
58 |
public List<String> getRecords() { |
|
59 |
return records; |
|
60 |
} |
|
61 |
|
|
62 |
public void setRecords(final List<String> records) { |
|
63 |
this.records = records; |
|
64 |
} |
|
65 |
|
|
66 |
} |
modules/dnet-index-client/tags/dnet-index-client-1.1.0/src/main/java/eu/dnetlib/functionality/index/client/response/BrowseValueEntry.java | ||
---|---|---|
1 |
package eu.dnetlib.functionality.index.client.response; |
|
2 |
|
|
3 |
import javax.xml.bind.annotation.XmlRootElement; |
|
4 |
|
|
5 |
@XmlRootElement |
|
6 |
public class BrowseValueEntry implements Comparable<BrowseValueEntry> { |
|
7 |
|
|
8 |
private String value; |
|
9 |
|
|
10 |
private int size; |
|
11 |
|
|
12 |
public BrowseValueEntry() {} |
|
13 |
|
|
14 |
public BrowseValueEntry(final String value, final int size) { |
|
15 |
this.value = value; |
|
16 |
this.size = size; |
|
17 |
} |
|
18 |
|
|
19 |
public String getValue() { |
|
20 |
return value; |
|
21 |
} |
|
22 |
|
|
23 |
public void setValue(final String value) { |
|
24 |
this.value = value; |
|
25 |
} |
|
26 |
|
|
27 |
public int getSize() { |
|
28 |
return size; |
|
29 |
} |
|
30 |
|
|
31 |
public void setSize(final int size) { |
|
32 |
this.size = size; |
|
33 |
} |
|
34 |
|
|
35 |
@Override |
|
36 |
public int compareTo(final BrowseValueEntry e) { |
|
37 |
return Integer.compare(getSize(), e.getSize()); |
|
38 |
} |
|
39 |
|
|
40 |
} |
modules/dnet-index-client/tags/dnet-index-client-1.1.0/src/main/java/eu/dnetlib/functionality/index/client/response/BrowseEntry.java | ||
---|---|---|
1 |
package eu.dnetlib.functionality.index.client.response; |
|
2 |
|
|
3 |
import java.util.List; |
|
4 |
|
|
5 |
public class BrowseEntry { |
|
6 |
private String field; |
|
7 |
private String label; |
|
8 |
private List<BrowseValueEntry> values; |
|
9 |
|
|
10 |
public BrowseEntry() {} |
|
11 |
|
|
12 |
public BrowseEntry(final String field, final String label,final List<BrowseValueEntry> values) { |
|
13 |
this.field = field; |
|
14 |
this.label = label; |
|
15 |
this.values = values; |
|
16 |
} |
|
17 |
|
|
18 |
public String getField() { |
|
19 |
return field; |
|
20 |
} |
|
21 |
|
|
22 |
public void setField(final String field) { |
|
23 |
this.field = field; |
|
24 |
} |
|
25 |
|
|
26 |
public String getLabel() { |
|
27 |
return label; |
|
28 |
} |
|
29 |
|
|
30 |
public void setLabel(final String label) { |
|
31 |
this.label = label; |
|
32 |
} |
|
33 |
|
|
34 |
public List<BrowseValueEntry> getValues() { |
|
35 |
return values; |
|
36 |
} |
|
37 |
|
|
38 |
public void setValues(final List<BrowseValueEntry> values) { |
|
39 |
this.values = values; |
|
40 |
} |
|
41 |
|
|
42 |
} |
modules/dnet-index-client/tags/dnet-index-client-1.1.0/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.model.document.IndexDocument; |
|
9 |
import eu.dnetlib.functionality.index.utils.IndexFieldUtility; |
|
10 |
|
|
11 |
/** |
|
12 |
* The Class DocumentFeeder. |
|
13 |
*/ |
|
14 |
public class DocumentFeeder implements Callable<FeedResult> { |
|
15 |
|
|
16 |
/** The Constant log. */ |
|
17 |
private static final Log log = LogFactory.getLog(DocumentFeeder.class); |
|
18 |
|
|
19 |
/** The index collection. */ |
|
20 |
private IndexFeederCollection indexCollection; |
|
21 |
|
|
22 |
/** The records. */ |
|
23 |
private Iterable<IndexDocument> records; |
|
24 |
|
|
25 |
/** |
|
26 |
* Instantiates a new document feeder. |
|
27 |
* |
|
28 |
* @param indexCollection |
|
29 |
* the index collection |
|
30 |
* @param records |
|
31 |
* the records |
|
32 |
*/ |
|
33 |
public DocumentFeeder(final IndexFeederCollection indexCollection, final Iterable<IndexDocument> records) { |
|
34 |
this.indexCollection = indexCollection; |
|
35 |
this.records = records; |
|
36 |
} |
|
37 |
|
|
38 |
/** |
|
39 |
* {@inheritDoc} |
|
40 |
* |
|
41 |
* @see java.util.concurrent.Callable#call() |
|
42 |
*/ |
|
43 |
@Override |
|
44 |
public FeedResult call() throws Exception { |
|
45 |
final FeedResult res = new FeedResult(System.currentTimeMillis()); |
|
46 |
for (IndexDocument doc : records) { |
|
47 |
boolean rsp; |
|
48 |
switch (doc.getStatus()) { |
|
49 |
|
|
50 |
case OK: |
|
51 |
rsp = indexCollection.add(doc); |
|
52 |
if (rsp) { |
|
53 |
res.add(); |
|
54 |
} else { |
|
55 |
res.mark(); |
|
56 |
} |
|
57 |
break; |
|
58 |
|
|
59 |
case MARKED: |
|
60 |
res.mark(); |
|
61 |
log.debug("skipping record: " + doc.getFieldValue(IndexFieldUtility.INDEX_RECORD_ID)); |
|
62 |
break; |
|
63 |
|
|
64 |
case ERROR: |
|
65 |
res.skip(); |
|
66 |
log.info("Error on record: " + doc.getFieldValue(IndexFieldUtility.INDEX_RECORD_ID)); |
|
67 |
break; |
|
68 |
|
|
69 |
default: |
|
70 |
throw new IllegalStateException("unknow document status"); |
|
71 |
} |
|
72 |
} |
|
73 |
return res; |
|
74 |
} |
|
75 |
|
|
76 |
} |
modules/dnet-index-client/tags/dnet-index-client-1.1.0/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-index-client/tags/dnet-index-client-1.1.0/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-index-client/tags/dnet-index-client-1.1.0/src/main/java/eu/dnetlib/functionality/index/feed/DocumentMapperFactory.java | ||
---|---|---|
1 |
package eu.dnetlib.functionality.index.feed; |
|
2 |
|
|
3 |
import java.util.Map; |
|
4 |
|
|
5 |
import com.google.common.base.Function; |
|
6 |
|
|
7 |
import eu.dnetlib.functionality.index.model.Any.ValueType; |
|
8 |
import eu.dnetlib.functionality.index.model.document.IndexDocument; |
|
9 |
import eu.dnetlib.functionality.index.utils.MetadataReference; |
|
10 |
|
|
11 |
/** |
|
12 |
* A factory for creating DocumentMapper objects. |
|
13 |
*/ |
|
14 |
public interface DocumentMapperFactory { |
|
15 |
|
|
16 |
/** |
|
17 |
* Gets the record mapper. |
|
18 |
* |
|
19 |
* @param schema |
|
20 |
* the schema |
|
21 |
* @param mdRef |
|
22 |
* the md ref |
|
23 |
* @param dsId |
|
24 |
* the ds id |
|
25 |
* @param version |
|
26 |
* the version |
|
27 |
* @return the record mapper |
|
28 |
*/ |
|
29 |
public Function<String, IndexDocument> getRecordMapper(final Map<String, ValueType> schema, |
|
30 |
final MetadataReference mdRef, |
|
31 |
final String dsId, |
|
32 |
final String version); |
|
33 |
|
|
34 |
} |
modules/dnet-index-client/tags/dnet-index-client-1.1.0/src/main/java/eu/dnetlib/functionality/index/feed/IndexFeederCollection.java | ||
---|---|---|
1 |
package eu.dnetlib.functionality.index.feed; |
|
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 |
public interface IndexFeederCollection { |
|
10 |
|
|
11 |
/** |
|
12 |
* Adds an input Document to the index. |
|
13 |
* |
|
14 |
* @param doc |
|
15 |
* the doc |
|
16 |
* @return the solr update response |
|
17 |
* @throws IndexServiceException |
|
18 |
* the index service exception |
|
19 |
*/ |
|
20 |
public boolean add(final IndexDocument doc) throws IndexServiceException; |
|
21 |
|
|
22 |
/** |
|
23 |
* Adds all the documents to the index giving an iterator of input documents. |
|
24 |
* |
|
25 |
* @param docs |
|
26 |
* the iterator of input documents |
|
27 |
* @return the solr update response |
|
28 |
* @throws IndexServiceException |
|
29 |
* the index service exception |
|
30 |
*/ |
|
31 |
public boolean addAll(final Iterator<IndexDocument> docs) throws IndexServiceException; |
|
32 |
|
|
33 |
/** |
|
34 |
* Adds the all. |
|
35 |
* |
|
36 |
* @param docs |
|
37 |
* the docs |
|
38 |
* @return the update response |
|
39 |
* @throws IndexServiceException |
|
40 |
* the index service exception |
|
41 |
*/ |
|
42 |
public boolean addAll(final Collection<IndexDocument> docs) throws IndexServiceException; |
|
43 |
|
|
44 |
/** |
|
45 |
* Delete index. |
|
46 |
* |
|
47 |
* @param dsId |
|
48 |
* the ds id |
|
49 |
* @return true, if successful |
|
50 |
* @throws IndexServiceException |
|
51 |
* the index service exception |
|
52 |
*/ |
|
53 |
public boolean deleteIndex(final String dsId) throws IndexServiceException; |
|
54 |
|
|
55 |
/** |
|
56 |
* Delete data from the index by query. |
|
57 |
* |
|
58 |
* @param query |
|
59 |
* the query |
|
60 |
* @param dsId |
|
61 |
* the ds id |
|
62 |
* @return true, if successful |
|
63 |
* @throws IndexServiceException |
|
64 |
* the index service exception |
|
65 |
*/ |
|
66 |
public boolean deleteByQuery(final String query, final String dsId) throws IndexServiceException; |
|
67 |
|
|
68 |
/** |
|
69 |
* Commit the data. |
|
70 |
* |
|
71 |
* @return true, if successful |
|
72 |
* @throws IndexServiceException |
|
73 |
* the index service exception |
|
74 |
*/ |
|
75 |
public boolean commit() throws IndexServiceException; |
|
76 |
|
|
77 |
} |
modules/dnet-index-client/tags/dnet-index-client-1.1.0/src/main/java/eu/dnetlib/functionality/index/utils/ServiceTools.java | ||
---|---|---|
1 |
package eu.dnetlib.functionality.index.utils; |
|
2 |
|
|
3 |
import java.util.HashMap; |
|
4 |
import java.util.List; |
|
5 |
import java.util.Map; |
|
6 |
|
|
7 |
import javax.annotation.Resource; |
|
8 |
|
|
9 |
import org.apache.commons.lang.StringUtils; |
|
10 |
import org.apache.commons.logging.Log; |
|
11 |
import org.apache.commons.logging.LogFactory; |
|
12 |
import org.springframework.beans.factory.annotation.Required; |
|
13 |
|
|
14 |
import com.google.common.base.Function; |
|
15 |
import com.google.common.collect.Iterables; |
|
16 |
import com.google.common.collect.Lists; |
|
17 |
|
|
18 |
import eu.dnetlib.data.provision.index.rmi.IndexServiceException; |
|
19 |
import eu.dnetlib.enabling.is.lookup.rmi.ISLookUpDocumentNotFoundException; |
|
20 |
import eu.dnetlib.enabling.is.lookup.rmi.ISLookUpException; |
|
21 |
import eu.dnetlib.enabling.is.lookup.rmi.ISLookUpService; |
|
22 |
import eu.dnetlib.enabling.is.registry.ISRegistryDocumentNotFoundException; |
|
23 |
import eu.dnetlib.enabling.is.registry.rmi.ISRegistryException; |
|
24 |
import eu.dnetlib.enabling.is.registry.rmi.ISRegistryService; |
|
25 |
import eu.dnetlib.enabling.tools.ServiceLocator; |
|
26 |
import eu.dnetlib.functionality.index.client.IndexClientException; |
|
27 |
|
|
28 |
public class ServiceTools { |
|
29 |
|
|
30 |
private static final Log log = LogFactory.getLog(ServiceTools.class); |
|
31 |
|
|
32 |
/** The lookup locator. */ |
|
33 |
@Resource(name = "lookupLocator") |
|
34 |
private ServiceLocator<ISLookUpService> lookupLocator; |
|
35 |
|
|
36 |
/** |
|
37 |
* registry locator. |
|
38 |
*/ |
|
39 |
private ServiceLocator<ISRegistryService> registryLocator; |
|
40 |
|
|
41 |
@Resource |
|
42 |
private MetadataReferenceFactory mdFactory; |
|
43 |
|
|
44 |
public List<MetadataReference> listMDRefs() throws IndexClientException { |
|
45 |
return Lists.newArrayList(Iterables.transform(listMDRefsAsString(), new Function<String, MetadataReference>() { |
|
46 |
|
|
47 |
@Override |
|
48 |
public MetadataReference apply(final String s) { |
|
49 |
return mdFactory.decodeMetadata(s); |
|
50 |
} |
|
51 |
})); |
|
52 |
} |
|
53 |
|
|
54 |
private List<String> quickSearchProfile(final String xquery) throws IndexClientException { |
|
55 |
try { |
|
56 |
return lookupLocator.getService().quickSearchProfile(xquery); |
|
57 |
} catch (ISLookUpException e) { |
|
58 |
throw new IndexClientException(e); |
|
59 |
} |
|
60 |
} |
|
61 |
|
|
62 |
public MetadataReference getMetadataRef(final String dsId) throws IndexServiceException { |
|
63 |
|
|
64 |
final String xquery = "for $x in //RESOURCE_PROFILE[.//RESOURCE_IDENTIFIER/@value='" + dsId + "']//CONFIGURATION " + "return concat(" |
|
65 |
+ "$x/METADATA_FORMAT/text(),'-'," + "$x/METADATA_FORMAT_LAYOUT/text(),'-'," + "$x/METADATA_FORMAT_INTERPRETATION/text())"; |
|
66 |
return mdFactory.decodeMetadata(getResourceProfileByQuery(xquery)); |
|
67 |
} |
|
68 |
|
|
69 |
private String getResourceProfileByQuery(final String xquery) throws IndexServiceException { |
|
70 |
try { |
|
71 |
return lookupLocator.getService().getResourceProfileByQuery(xquery); |
|
72 |
} catch (ISLookUpDocumentNotFoundException e) { |
|
73 |
throw new IndexServiceException(e); |
|
74 |
} catch (ISLookUpException e) { |
|
75 |
throw new IndexServiceException(e); |
|
76 |
} |
|
77 |
} |
|
78 |
|
|
79 |
public String getIndexFields(final String dsId) throws IndexServiceException { |
|
80 |
|
|
81 |
return getIndexFields(getMetadataRef(dsId)); |
|
82 |
} |
|
83 |
|
|
84 |
public String getIndexFields(final MetadataReference mdRef) { |
|
85 |
|
|
86 |
final String xquery = "for $x in collection('')/RESOURCE_PROFILE/BODY[CONFIGURATION/NAME='" + mdRef.getFormat() |
|
87 |
+ "'] return $x/STATUS/LAYOUTS/LAYOUT[@name='" + mdRef.getLayout() + "']/FIELDS"; |
|
88 |
try { |
|
89 |
return getResourceProfileByQuery(xquery); |
|
90 |
} catch (IndexServiceException e) { |
|
91 |
log.warn("couldn't find Metadata format profile matching specs: " + mdRef.toString()); |
|
92 |
return ""; |
|
93 |
} |
|
94 |
} |
|
95 |
|
|
96 |
public List<String> listDsIds() throws IndexClientException { |
|
97 |
final String xquery = "//RESOURCE_PROFILE[.//RESOURCE_TYPE/@value='IndexDSResourceType']//RESOURCE_IDENTIFIER/@value/string()"; |
|
98 |
return quickSearchProfile(xquery); |
|
99 |
} |
|
100 |
|
|
101 |
private List<String> listMDRefsAsString() throws IndexClientException { |
|
102 |
final String xquery = "for $x in //RESOURCE_PROFILE[.//RESOURCE_TYPE/@value='MDFormatDSResourceType'] " |
|
103 |
+ "let $format:= $x//CONFIGURATION/NAME/string() " + "for $y in $x//LAYOUTS/LAYOUT " + "let $layout:= $y//LAYOUT/@name/string() " |
|
104 |
+ "let $interpretation:= $x//CONFIGURATION/INTERPRETATION/text() " + "return concat($format,'-',$layout,'-',$interpretation) "; |
|
105 |
return quickSearchProfile(xquery); |
|
106 |
} |
|
107 |
|
|
108 |
public Map<String, String> getIndexProperties(final String backendId) throws IndexClientException { |
|
109 |
|
|
110 |
String query = "for $x in /RESOURCE_PROFILE[.//RESOURCE_TYPE/@value=\"IndexServiceResourceType\"]//SERVICE_PROPERTIES/PROPERTY" |
|
111 |
+ " return concat($x/@key/string(),\":::\", $x/@value/string())"; |
|
112 |
Map<String, String> indexProperties = new HashMap<String, String>(); |
|
113 |
try { |
|
114 |
List<String> results = lookupLocator.getService().quickSearchProfile(query); |
|
115 |
if (results != null) { |
|
116 |
for (String s : results) { |
|
117 |
String[] values = s.split(":::"); |
|
118 |
if ((values != null) && (values.length == 2)) { |
|
119 |
String key = values[0]; |
|
120 |
String value = values[1]; |
|
121 |
if (StringUtils.startsWith(key, backendId)) { |
|
122 |
indexProperties.put(StringUtils.substringAfter(key, backendId + ":"), value); |
|
123 |
} |
|
124 |
} |
|
125 |
} |
|
126 |
} |
|
127 |
return indexProperties; |
|
128 |
} catch (ISLookUpException e) { |
|
129 |
throw new IndexClientException(); |
|
130 |
} |
|
131 |
} |
|
132 |
|
|
133 |
public String registerProfile(final String resourceProfile) throws IndexServiceException { |
|
134 |
try { |
|
135 |
return getRegistryLocator().getService().registerProfile(resourceProfile); |
|
136 |
} catch (ISRegistryException e) { |
|
137 |
throw new IndexServiceException(e); |
|
138 |
} |
|
139 |
} |
|
140 |
|
|
141 |
@Required |
|
142 |
public void setRegistryLocator(final ServiceLocator<ISRegistryService> registryLocator) { |
|
143 |
this.registryLocator = registryLocator; |
|
144 |
} |
|
145 |
|
|
146 |
public ServiceLocator<ISRegistryService> getRegistryLocator() { |
|
147 |
return registryLocator; |
|
148 |
} |
|
149 |
|
|
150 |
public boolean incrementHandledDataStructures(final String backendId) throws IndexServiceException { |
|
151 |
final String xquery = "let $x := //RESOURCE_PROFILE[HEADER/PROTOCOLS/PROTOCOL/@name='" + backendId + "']," |
|
152 |
+ "$tot := $x//STATUS/HANDLED_DATASTRUCTURE/number() + 1 " + "return update replace $x//STATUS/HANDLED_DATASTRUCTURE with " |
|
153 |
+ "<HANDLED_DATASTRUCTURE>{$tot}</HANDLED_DATASTRUCTURE>"; |
|
154 |
|
|
155 |
log.info("performing increment of HANDLED_DATASTRUCTURE"); |
|
156 |
return executeXUpdate(xquery); |
|
157 |
} |
|
158 |
|
|
159 |
private boolean executeXUpdate(final String xquery) throws IndexServiceException { |
|
160 |
try { |
|
161 |
return getRegistryLocator().getService().executeXUpdate(xquery); |
|
162 |
} catch (ISRegistryException e) { |
|
163 |
throw new IndexServiceException(e); |
|
164 |
} |
|
165 |
} |
|
166 |
|
|
167 |
public String getServiceAddress(final String backendId) { |
|
168 |
final String xquery = "let $x := //RESOURCE_PROFILE[HEADER/PROTOCOLS/PROTOCOL/@name='" + backendId + "']" |
|
169 |
+ "return $x//PROTOCOL[./@name='SOAP']/@address/string()"; |
|
170 |
try { |
|
171 |
return getResourceProfileByQuery(xquery); |
|
172 |
} catch (IndexServiceException e) { |
|
173 |
log.warn("couldn't find service Address for index Service with protocol: " + backendId); |
|
174 |
return ""; |
|
175 |
} |
|
176 |
} |
|
177 |
|
|
178 |
public boolean deleteIndexDS(final String dsId) throws IndexServiceException { |
|
179 |
try { |
|
180 |
return getRegistryLocator().getService().deleteProfile(dsId); |
|
181 |
} catch (ISRegistryDocumentNotFoundException e) { |
|
182 |
throw new IndexServiceException(e); |
|
183 |
} catch (ISRegistryException e) { |
|
184 |
throw new IndexServiceException(e); |
|
185 |
} |
|
186 |
} |
|
187 |
|
|
188 |
public List<String> getBackendIds(final MetadataReference mdRef) throws IndexServiceException { |
|
189 |
String query = "distinct-values(//RESOURCE_PROFILE[.//METADATA_FORMAT='%s' and .//METADATA_FORMAT_LAYOUT='%s' and .//METADATA_FORMAT_INTERPRETATION='%s']//BACKEND/@ID/string())"; |
|
190 |
try { |
|
191 |
String instanceQuery = String.format(query, mdRef.getFormat(), mdRef.getLayout(), mdRef.getInterpretation()); |
|
192 |
log.debug("Executing query to IS: " + instanceQuery); |
|
193 |
return lookupLocator.getService().quickSearchProfile(instanceQuery); |
|
194 |
} catch (ISLookUpException e) { |
|
195 |
throw new IndexServiceException(e); |
|
196 |
} |
|
197 |
} |
|
198 |
} |
modules/dnet-index-client/tags/dnet-index-client-1.1.0/src/main/java/eu/dnetlib/functionality/index/utils/IndexFieldUtility.java | ||
---|---|---|
1 |
package eu.dnetlib.functionality.index.utils; |
|
2 |
|
|
3 |
/** |
|
4 |
* IndexMap keeps track of IndexDataStructure-to-physical index mappings and vice-versa. |
|
5 |
* |
|
6 |
* @author claudio |
|
7 |
* |
|
8 |
*/ |
|
9 |
public class IndexFieldUtility { |
|
10 |
|
|
11 |
public static final String INDEX_FIELD_PREFIX = "__"; |
|
12 |
|
|
13 |
public static final String INDEX_DSID_ALL = "ALL"; |
|
14 |
|
|
15 |
public static final String SCORE_FIELD = "score"; |
|
16 |
|
|
17 |
public static final String DS_ID = INDEX_FIELD_PREFIX + "dsid"; |
|
18 |
|
|
19 |
public static final String DS_VERSION = INDEX_FIELD_PREFIX + "dsversion"; |
|
20 |
|
|
21 |
public static final String RESULT = INDEX_FIELD_PREFIX + "result"; |
|
22 |
|
|
23 |
public static final String ALL_FIELDS = INDEX_FIELD_PREFIX + "all"; |
|
24 |
|
|
25 |
public static final String DELETE_DOCUMENT = INDEX_FIELD_PREFIX + "deleted"; |
|
26 |
|
|
27 |
public static final String INDEX_RECORD_ID = INDEX_FIELD_PREFIX + "indexrecordidentifier"; |
|
28 |
|
|
29 |
public static final String FULLTEXT_ID = INDEX_FIELD_PREFIX + "fulltext"; |
|
30 |
|
|
31 |
public static final String INDEXNAME_PARAM = INDEX_FIELD_PREFIX + "indexName"; |
|
32 |
|
|
33 |
public static final String queryAll = "*:*"; |
|
34 |
|
|
35 |
public static final String FIELD_NAME = "name"; |
|
36 |
|
|
37 |
public static final String FIELD_BROWSING_ALIAS_FOR = "browsingAliasFor"; |
|
38 |
|
|
39 |
public static final String XPATH_BROWSING_ALIAS_FOR = "//FIELD[@" + FIELD_BROWSING_ALIAS_FOR + "]"; |
|
40 |
|
|
41 |
} |
modules/dnet-index-client/tags/dnet-index-client-1.1.0/src/main/java/eu/dnetlib/functionality/index/utils/MetadataReference.java | ||
---|---|---|
1 |
package eu.dnetlib.functionality.index.utils; |
|
2 |
|
|
3 |
|
|
4 |
import com.google.common.collect.ComparisonChain; |
|
5 |
|
|
6 |
/** |
|
7 |
* Container class for metadata format, layout and interpretation. |
|
8 |
* |
|
9 |
* @author claudio |
|
10 |
* |
|
11 |
*/ |
|
12 |
public class MetadataReference { |
|
13 |
|
|
14 |
/** |
|
15 |
* Metadata format. |
|
16 |
*/ |
|
17 |
private String format; |
|
18 |
|
|
19 |
/** |
|
20 |
* Metadata layout. |
|
21 |
*/ |
|
22 |
private String layout; |
|
23 |
|
|
24 |
/** |
|
25 |
* Metadata interpretation. |
|
26 |
*/ |
|
27 |
private String interpretation; |
|
28 |
|
|
29 |
/** |
|
30 |
* Constructor for MetadataReference. |
|
31 |
* |
|
32 |
* @param format |
|
33 |
* Metadata format |
|
34 |
* @param layout |
|
35 |
* Metadata layout |
|
36 |
* @param interpretation |
|
37 |
* Metadata interpretation |
|
38 |
*/ |
|
39 |
public MetadataReference(final String format, final String layout, final String interpretation) { |
|
40 |
this.format = format; |
|
41 |
this.layout = layout; |
|
42 |
this.interpretation = interpretation; |
|
43 |
} |
|
44 |
|
|
45 |
public String getFormat() { |
|
46 |
return format; |
|
47 |
} |
|
48 |
|
|
49 |
public String getLayout() { |
|
50 |
return layout; |
|
51 |
} |
|
52 |
|
|
53 |
public String getInterpretation() { |
|
54 |
return interpretation; |
|
55 |
} |
|
56 |
|
|
57 |
@Override |
|
58 |
public boolean equals(final Object that) { |
|
59 |
|
|
60 |
if (!(that instanceof MetadataReference)) |
|
61 |
return false; |
|
62 |
|
|
63 |
final MetadataReference mdRef = (MetadataReference) that; |
|
64 |
|
|
65 |
return ComparisonChain.start() |
|
66 |
.compare(this.format, mdRef.getFormat()) |
|
67 |
.compare(this.layout, mdRef.getLayout()) |
|
68 |
.compare(this.interpretation, mdRef.getInterpretation()) |
|
69 |
.result() == 0; |
|
70 |
} |
|
71 |
|
|
72 |
@Override |
|
73 |
public int hashCode() { |
|
74 |
return getFormat().hashCode() + getLayout().hashCode() + getInterpretation().hashCode(); |
|
75 |
} |
|
76 |
|
|
77 |
@Override |
|
78 |
public String toString() { |
|
79 |
return getFormat() + "-" + getLayout() + "-" + getInterpretation(); |
|
80 |
} |
|
81 |
|
|
82 |
} |
modules/dnet-index-client/tags/dnet-index-client-1.1.0/src/main/java/eu/dnetlib/functionality/index/utils/MetadataReferenceFactory.java | ||
---|---|---|
1 |
package eu.dnetlib.functionality.index.utils; |
|
2 |
|
|
3 |
|
|
4 |
public class MetadataReferenceFactory { |
|
5 |
|
|
6 |
public MetadataReference getMetadata(final String format, final String layout, final String interpretation) { |
|
7 |
return new MetadataReference(format, layout, interpretation); |
|
8 |
} |
|
9 |
|
|
10 |
public MetadataReference decodeMetadata(final String encoded) { |
|
11 |
String[] split = encoded.split("-"); |
|
12 |
if (split.length == 3) return getMetadata(split[0], split[1], split[2]); |
|
13 |
|
|
14 |
throw new IllegalStateException("malformed metadata reference: " + encoded); |
|
15 |
} |
|
16 |
|
|
17 |
} |
modules/dnet-index-client/tags/dnet-index-client-1.1.0/src/main/java/eu/dnetlib/functionality/index/utils/MDFormatReader.java | ||
---|---|---|
1 |
package eu.dnetlib.functionality.index.utils; |
|
2 |
|
|
3 |
import java.io.StringReader; |
|
4 |
import java.util.List; |
|
5 |
import java.util.Map; |
|
6 |
|
|
7 |
import org.dom4j.Document; |
|
8 |
import org.dom4j.DocumentException; |
|
9 |
import org.dom4j.io.SAXReader; |
|
10 |
import org.springframework.beans.factory.annotation.Autowired; |
|
11 |
import org.xml.sax.InputSource; |
|
12 |
|
|
13 |
import com.google.common.collect.HashBasedTable; |
|
14 |
import com.google.common.collect.Table; |
|
15 |
import com.mycila.xmltool.CallBack; |
|
16 |
import com.mycila.xmltool.XMLDoc; |
|
17 |
import com.mycila.xmltool.XMLTag; |
|
18 |
|
|
19 |
import eu.dnetlib.data.provision.index.rmi.IndexServiceException; |
|
20 |
import eu.dnetlib.functionality.index.client.IndexClientException; |
|
21 |
|
|
22 |
public class MDFormatReader { |
|
23 |
|
|
24 |
static class XmlUtils { |
|
25 |
|
|
26 |
/** |
|
27 |
* helper method, parses a list of fields. |
|
28 |
* |
|
29 |
* @param fields |
|
30 |
* the given fields |
|
31 |
* @return the parsed fields |
|
32 |
* @throws IndexServiceException |
|
33 |
* if cannot parse the fields |
|
34 |
*/ |
|
35 |
public static Document parse(final String xml) { |
|
36 |
try { |
|
37 |
return new SAXReader().read(new StringReader(xml)); |
|
38 |
} catch (DocumentException e) { |
|
39 |
throw new IllegalArgumentException("cannot parse: " + xml); |
|
40 |
} |
|
41 |
} |
|
42 |
|
|
43 |
public static InputSource asInputSource(final String input) throws DocumentException { |
|
44 |
return new InputSource(new StringReader(parse(input).asXML())); |
|
45 |
} |
|
46 |
} |
|
47 |
|
|
48 |
@Autowired |
|
49 |
private ServiceTools serviceTools; |
|
50 |
|
|
51 |
@Autowired |
|
52 |
private MetadataReferenceFactory mdFactory; |
|
53 |
|
|
54 |
public List<MetadataReference> listMDRefs() throws IndexClientException { |
|
55 |
return serviceTools.listMDRefs(); |
|
56 |
} |
|
57 |
|
|
58 |
public Document getFields(final MetadataReference mdRef) { |
|
59 |
String fields = serviceTools.getIndexFields(mdRef); |
|
60 |
return (fields != null) && !fields.isEmpty() ? XmlUtils.parse(fields) : null; |
|
61 |
} |
|
62 |
|
|
63 |
public Map<String, String> getAttributeMap(final MetadataReference mdRef, final String attribute) throws IndexClientException { |
|
64 |
return getAttributeTable(mdRef, attribute).column(attribute); |
|
65 |
} |
|
66 |
|
|
67 |
public Table<String, String, String> getAttributeTable(final MetadataReference mdRef, final String... attributeList) throws IndexClientException { |
|
68 |
|
|
69 |
final String fields = serviceTools.getIndexFields(mdRef); |
|
70 |
if (fields.isEmpty()) throw new IndexClientException("No result getting index layout informations"); |
|
71 |
final Table<String, String, String> t = HashBasedTable.create(); |
|
72 |
XMLDoc.from(serviceTools.getIndexFields(mdRef), false).forEach("//FIELD", new CallBack() { |
|
73 |
|
|
74 |
@Override |
|
75 |
public void execute(final XMLTag field) { |
|
76 |
|
|
77 |
for (String attribute : attributeList) { |
|
78 |
String value = null; |
|
79 |
|
|
80 |
if ("xpath".equals(attribute)) { |
|
81 |
if (!(field.hasAttribute("xpath") || field.hasAttribute("value"))) return; |
|
82 |
|
|
83 |
value = field.hasAttribute("xpath") ? field.getAttribute("xpath") : field.getAttribute("value"); |
|
84 |
} |
|
85 |
|
|
86 |
if ("weight".equals(attribute)) { |
|
87 |
if (!(field.hasAttribute(attribute))) return; |
|
88 |
|
|
89 |
value = field.hasAttribute(attribute) ? field.getAttribute(attribute) : ""; |
|
90 |
} |
|
91 |
|
|
92 |
if (value == null) { |
|
93 |
value = field.getAttribute(attribute); |
|
94 |
} |
|
95 |
|
|
96 |
t.put(field.getAttribute("name").toLowerCase(), attribute, value); |
|
97 |
} |
|
98 |
} |
|
99 |
}); |
|
100 |
return t; |
|
101 |
} |
|
102 |
|
|
103 |
} |
modules/dnet-index-client/tags/dnet-index-client-1.1.0/src/main/java/eu/dnetlib/functionality/index/model/AnySeq.java | ||
---|---|---|
1 |
package eu.dnetlib.functionality.index.model; |
|
2 |
|
|
3 |
import java.util.Date; |
|
4 |
import java.util.List; |
|
5 |
|
|
6 |
/** |
|
7 |
* Interface for a sequence of Any objects. |
|
8 |
* |
|
9 |
* <p> |
|
10 |
* AnySeq does <b>not</b> allow <code>null</code> values! |
|
11 |
* </p> |
|
12 |
* |
|
13 |
*/ |
|
14 |
public interface AnySeq extends List<Any>, Any { |
|
15 |
|
|
16 |
/** |
|
17 |
* @param element |
|
18 |
* The string object to add |
|
19 |
* @return true if successfully added, false else |
|
20 |
*/ |
|
21 |
boolean add(String element); |
|
22 |
|
|
23 |
/** |
|
24 |
* Long, Integer, Short and Byte values will be converted to Value object of type LONG, all others to Value object |
|
25 |
* of type DOUBLE. |
|
26 |
* |
|
27 |
* @param number |
|
28 |
* The number object to add |
|
29 |
* @return true if successfully added, false else |
|
30 |
*/ |
|
31 |
boolean add(Number number); |
|
32 |
|
|
33 |
/** |
|
34 |
* @param index |
|
35 |
* The index where to add the any object |
|
36 |
* @param element |
|
37 |
* The any object to add |
|
38 |
*/ |
|
39 |
@Override |
|
40 |
void add(int index, Any element); |
|
41 |
|
|
42 |
/** |
|
43 |
* @param index |
|
44 |
* The index of the object to return |
|
45 |
* @return The AnyMap matching to the index, an InvalidValueTypeException is thrown if the value is not of type |
|
46 |
* AnyMap |
|
47 |
*/ |
|
48 |
AnyMap getMap(int index); |
|
49 |
|
|
50 |
/** |
|
51 |
* @param index |
|
52 |
* The index of the object to return |
|
53 |
* @return The AnySeq matching to this index, an InvalidValueTypeException is thrown if the value is not of type |
|
54 |
*/ |
|
55 |
AnySeq getSeq(int index); |
|
56 |
|
|
57 |
/** |
|
58 |
* @param index |
|
59 |
* The index of the object to return |
|
60 |
* @return The value matching to this index, an InvalidValueTypeException is thrown if the value is no value type. |
|
61 |
*/ |
|
62 |
Value getValue(int index); |
|
63 |
|
|
64 |
/** |
|
65 |
* @param index |
|
66 |
* The index of the object to return |
|
67 |
* @return The string value matching to this index, an InvalidValueTypeException is thrown if the value is not of |
|
68 |
* type string |
|
69 |
*/ |
|
70 |
String getStringValue(int index); |
|
71 |
|
|
72 |
/** |
|
73 |
* @param index |
|
74 |
* The index of the object to return |
|
75 |
* @return The double value matching to this index, an InvalidValueTypeException is thrown if the value is not of |
|
76 |
* type double |
|
77 |
*/ |
|
78 |
Double getDoubleValue(int index); |
|
79 |
|
|
80 |
/** |
|
81 |
* @param index |
|
82 |
* The index of the object to return |
|
83 |
* @return The long value matching to this index, an InvalidValueTypeException is thrown if the value is not of type |
|
84 |
* long |
|
85 |
*/ |
|
86 |
Long getLongValue(int index); |
|
87 |
|
|
88 |
/** |
|
89 |
* @param index |
|
90 |
* The index of the object to return |
|
91 |
* @return The boolean value matching to this index, an InvalidValueTypeException is thrown if the value is not of |
|
92 |
* type boolean |
|
93 |
*/ |
|
94 |
Boolean getBooleanValue(int index); |
|
95 |
|
|
96 |
/** |
|
97 |
* @param index |
|
98 |
* The index of the object to return |
|
99 |
* @return The date value matching to this index, an InvalidValueTypeException is thrown if the value is not of type |
|
100 |
* date |
|
101 |
*/ |
|
102 |
Date getDateValue(int index); |
|
103 |
|
|
104 |
/** |
|
105 |
* @param index |
|
106 |
* The index of the object to return |
|
107 |
* @return The date time value matching to this index, an InvalidValueTypeException is thrown if the value is not of |
|
108 |
* type date time |
|
109 |
*/ |
|
110 |
Date getDateTimeValue(int index); |
|
111 |
|
|
112 |
/** |
|
113 |
* returns all values as a List of Strings. |
|
114 |
* |
|
115 |
* @throws InvalidValueTypeException |
|
116 |
* if not all contained values are strings. |
|
117 |
*/ |
|
118 |
List<String> asStrings(); |
|
119 |
|
|
120 |
/** |
|
121 |
* returns all values as a List of Long. |
|
122 |
* |
|
123 |
* @throws InvalidValueTypeException |
|
124 |
* if not all contained values are Longs. |
Also available in: Unified diff
[maven-release-plugin] copy for tag dnet-index-client-1.1.0