Skip to content

Commit 9e8df87

Browse files
committedMar 29, 2019
Added retrieval for CRIS Metrics indicators on SOAP API
1 parent dfb1af8 commit 9e8df87

File tree

8 files changed

+256
-126
lines changed

8 files changed

+256
-126
lines changed
 

‎dspace-cris-ametrics/metrics/retrieve-api/src/main/java/org/dspace/app/cris/metrics/common/model/ConstantMetrics.java

+4
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ public class ConstantMetrics
2525
public static final String STATS_INDICATOR_TYPE_SCOPUS = "scopus";
2626
public static final String STATS_INDICATOR_TYPE_VIEW = "view";
2727
public static final String STATS_INDICATOR_TYPE_DOWNLOAD = "download";
28+
29+
public static final String STATS_INDICATOR_TYPE_TIME = "_time";
30+
public static final String STATS_INDICATOR_TYPE_STARTTIME = "_starttime";
31+
public static final String STATS_INDICATOR_TYPE_ENDTIME = "_endtime";
2832

2933
public static final String STATS_INDICATOR_TYPE_ERROR = "ERROR";
3034
}

‎dspace-cris/webservices/dspace-cris-webservices-api/src/main/java/org/dspace/app/cris/ws/WSServicesPublications.java

+23-3
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,19 @@
77
*/
88
package org.dspace.app.cris.ws;
99

10+
import java.sql.Timestamp;
11+
import java.text.DateFormat;
12+
import java.text.SimpleDateFormat;
1013
import java.util.ArrayList;
14+
import java.util.Date;
1115
import java.util.LinkedList;
1216
import java.util.List;
1317

1418
import org.apache.log4j.Logger;
1519
import org.apache.solr.client.solrj.SolrQuery;
1620
import org.apache.solr.client.solrj.response.QueryResponse;
1721
import org.apache.solr.common.SolrDocument;
22+
import org.dspace.app.cris.metrics.common.model.ConstantMetrics;
1823
import org.dspace.app.cris.ws.discovery.CrisWebservicesExtraIndexPlugin;
1924
import org.dspace.app.cris.ws.marshaller.bean.WSItem;
2025
import org.dspace.app.cris.ws.marshaller.bean.WSMetadata;
@@ -25,7 +30,8 @@ public class WSServicesPublications extends AWSServices<WSItem>
2530
{
2631

2732
private static Logger log = Logger.getLogger(WSServicesPublications.class);
28-
33+
private final static DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");
34+
2935
@Override
3036
protected List<WSItem> getWSObject(QueryResponse response)
3137
{
@@ -51,6 +57,12 @@ public void internalBuildFieldList(SolrQuery solrQuery,
5157

5258
for (int j = 0; j < projection.length; j++)
5359
{
60+
if (projection[j].startsWith(ConstantMetrics.PREFIX_FIELD))
61+
{
62+
solrQuery.addField(projection[j] + ConstantMetrics.STATS_INDICATOR_TYPE_TIME);
63+
solrQuery.addField(projection[j] + ConstantMetrics.STATS_INDICATOR_TYPE_STARTTIME);
64+
solrQuery.addField(projection[j] + ConstantMetrics.STATS_INDICATOR_TYPE_ENDTIME);
65+
}
5466
solrQuery.addField(projection[j]);
5567
}
5668

@@ -78,7 +90,7 @@ private WSItem getItemFromSolrDoc(SolrDocument sd)
7890

7991
for (String m : sd.getFieldNames())
8092
{
81-
if (!m.startsWith("dc."))
93+
if (!m.startsWith("dc.") && !m.startsWith(ConstantMetrics.PREFIX_FIELD))
8294
{
8395
continue;
8496
}
@@ -87,7 +99,15 @@ private WSItem getItemFromSolrDoc(SolrDocument sd)
8799
int place = 1;
88100
for (Object v : sd.getFieldValues(m))
89101
{
90-
String value = (String) v;
102+
103+
String value = String.valueOf(v);
104+
if(m.startsWith(ConstantMetrics.PREFIX_FIELD)) {
105+
if(m.endsWith("time")) {
106+
Date vv = (Date)v;
107+
value = dateFormat.format(vv);
108+
}
109+
}
110+
91111
String[] mv = value.split("\\|\\|\\|");
92112
WSMetadataValue mvalue = new WSMetadataValue();
93113
mvalue.setValue(mv[0]);

‎dspace-cris/webservices/dspace-cris-webservices-api/src/main/java/org/dspace/app/cris/ws/marshaller/MarshallerPublications.java

+71-24
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
import java.util.List;
1212

13+
import org.dspace.app.cris.metrics.common.model.ConstantMetrics;
1314
import org.dspace.app.cris.util.UtilsXSD;
1415
import org.dspace.app.cris.ws.marshaller.bean.WSItem;
1516
import org.dspace.app.cris.ws.marshaller.bean.WSMetadata;
@@ -100,42 +101,88 @@ public Element buildResponse(List<WSItem> docList, long start, long hit,
100101
List<WSMetadata> fieldsName = doc.getMetadata();
101102
for (WSMetadata field : fieldsName)
102103
{
104+
if (!field.getName().startsWith(ConstantMetrics.PREFIX_FIELD))
105+
{
106+
Element metadata = new Element("metadata", echoNamespace);
103107

104-
Element metadata = new Element("metadata", echoNamespace);
108+
Element term = new Element("term", echoNamespace);
109+
term.addContent(field.getName());
105110

106-
Element term = new Element("term", echoNamespace);
107-
term.addContent(field.getName());
111+
Element values = new Element("values", echoNamespace);
108112

109-
Element values = new Element("values", echoNamespace);
113+
for (WSMetadataValue mValue : field.getValues())
114+
{
110115

111-
for (WSMetadataValue mValue : field.getValues())
112-
{
116+
Element value = new Element("value", echoNamespace);
117+
if (mValue.getAuthority() != null
118+
&& !mValue.getAuthority().isEmpty())
119+
{
120+
value.setAttribute("authority", mValue.getAuthority());
121+
}
113122

114-
Element value = new Element("value", echoNamespace);
115-
if (mValue.getAuthority() != null
116-
&& !mValue.getAuthority().isEmpty())
117-
{
118-
value.setAttribute("authority", mValue.getAuthority());
119-
}
123+
value.setAttribute("place", "" + mValue.getPlace());
124+
if (mValue.getShare() != null)
125+
{
126+
value.setAttribute("share", "" + mValue.getShare());
127+
}
120128

121-
value.setAttribute("place", "" + mValue.getPlace());
122-
if (mValue.getShare() != null)
123-
{
124-
value.setAttribute("share", "" + mValue.getShare());
125-
}
129+
value.addContent(mValue.getValue());
126130

127-
value.addContent(mValue.getValue());
131+
values.addContent(value);
128132

129-
values.addContent(value);
133+
}
130134

135+
metadata.addContent(term);
136+
metadata.addContent(values);
137+
metadataItem.addContent(metadata);
131138
}
132-
133-
metadata.addContent(term);
134-
metadata.addContent(values);
135-
metadataItem.addContent(metadata);
136-
137139
}
138140
row.addContent(metadataItem);
141+
142+
Element metrics = new Element("metrics", echoNamespace);
143+
for (WSMetadata field : fieldsName)
144+
{
145+
String fieldMetadataName = field.getName();
146+
if (fieldMetadataName.startsWith(ConstantMetrics.PREFIX_FIELD)
147+
&& !fieldMetadataName.endsWith(ConstantMetrics.STATS_INDICATOR_TYPE_TIME)
148+
&& !fieldMetadataName.endsWith(ConstantMetrics.STATS_INDICATOR_TYPE_STARTTIME)
149+
&& !fieldMetadataName.endsWith(ConstantMetrics.STATS_INDICATOR_TYPE_ENDTIME))
150+
{
151+
Element metric = new Element("metric", echoNamespace);
152+
String metricName = fieldMetadataName.replace(ConstantMetrics.PREFIX_FIELD, "");
153+
metric.setAttribute("type", metricName);
154+
155+
Element value = new Element("value", echoNamespace);
156+
value.addContent(field.getValues().get(0).getValue());
157+
metric.addContent(value);
158+
159+
for (WSMetadata subField : fieldsName)
160+
{
161+
String subFieldMetadataName = subField.getName();
162+
if (subFieldMetadataName.equals(ConstantMetrics.PREFIX_FIELD + metricName + ConstantMetrics.STATS_INDICATOR_TYPE_TIME))
163+
{
164+
Element subValue = new Element("observation_time", echoNamespace);
165+
subValue.addContent(subField.getValues().get(0).getValue());
166+
metric.addContent(subValue);
167+
}
168+
else if (subFieldMetadataName.equals(ConstantMetrics.PREFIX_FIELD + metricName + ConstantMetrics.STATS_INDICATOR_TYPE_STARTTIME))
169+
{
170+
Element subValue = new Element("start_time", echoNamespace);
171+
subValue.addContent(subField.getValues().get(0).getValue());
172+
metric.addContent(subValue);
173+
}
174+
else if (subFieldMetadataName.equals(ConstantMetrics.PREFIX_FIELD + metricName + ConstantMetrics.STATS_INDICATOR_TYPE_ENDTIME))
175+
{
176+
Element subValue = new Element("end_time", echoNamespace);
177+
subValue.addContent(subField.getValues().get(0).getValue());
178+
metric.addContent(subValue);
179+
}
180+
}
181+
metrics.addContent(metric);
182+
}
183+
}
184+
row.addContent(metrics);
185+
139186
child.addContent(row);
140187
}
141188
root.addContent(child);

‎dspace-solr/src/main/java/org/dspace/solr/handler/component/CrisMetricsExtractComponent.java

+8
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,14 @@ public void process(ResponseBuilder rb) throws IOException
109109
{
110110
sdoc.addField(metric+"_time", extraInfo.acquisitionTime);
111111
}
112+
if (extraInfo != null && extraInfo.startTime != null)
113+
{
114+
sdoc.addField(metric+"_starttime", extraInfo.startTime);
115+
}
116+
if (extraInfo != null && extraInfo.endTime != null)
117+
{
118+
sdoc.addField(metric+"_endtime", extraInfo.endTime);
119+
}
112120
}
113121
rl.add(sdoc);
114122
}

‎dspace-solr/src/main/java/org/dspace/solr/util/CrisMetricsUpdateListener.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,8 @@
2121
import java.util.Set;
2222

2323
import org.apache.commons.lang.StringUtils;
24-
import org.apache.lucene.index.Term;
2524
import org.apache.lucene.search.MatchAllDocsQuery;
2625
import org.apache.lucene.search.ScoreDoc;
27-
import org.apache.lucene.search.TermQuery;
2826
import org.apache.solr.common.util.NamedList;
2927
import org.apache.solr.core.SolrCore;
3028
import org.apache.solr.core.SolrEventListener;
@@ -238,7 +236,7 @@ private void populateRanks(String coreName, SolrIndexSearcher searcher)
238236
dbprops.get("database.username"),
239237
dbprops.get("database.password"));
240238
ps = conn.prepareStatement(
241-
"select resourceid, resourcetypeid, metrictype, remark, metriccount,timestampcreated from cris_metrics where last = true");
239+
"select resourceid, resourcetypeid, metrictype, remark, metriccount, timestampcreated, startdate, enddate from cris_metrics where last = true");
242240
rs = ps.executeQuery();
243241
log.debug("QUERY TIME:" + (new Date().getTime()-startQuery.getTime()));
244242

@@ -253,6 +251,8 @@ private void populateRanks(String coreName, SolrIndexSearcher searcher)
253251
String type = rs.getString(3);
254252
String remark = rs.getString(4);
255253
Date acqTime = rs.getDate(6);
254+
Date startTime = rs.getDate(7);
255+
Date endTime = rs.getDate(8);
256256
Integer docId = searchIDCache.get(resourceTypeId+"-"+resourceId);
257257
if (docId != null) {
258258
String key = new StringBuffer("crismetrics_").append(type.toLowerCase()).toString();
@@ -270,7 +270,7 @@ private void populateRanks(String coreName, SolrIndexSearcher searcher)
270270
}
271271

272272
tmpSubMap.put(docId, count);
273-
tmpSubRemarkMap.put(docId, new ExtraInfo(remark, acqTime));
273+
tmpSubRemarkMap.put(docId, new ExtraInfo(remark, acqTime, startTime, endTime));
274274

275275
if(add) {
276276
metricsCopy.put(key, tmpSubMap);

‎dspace-solr/src/main/java/org/dspace/solr/util/ExtraInfo.java

+5-1
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,17 @@
1111

1212
public class ExtraInfo
1313
{
14-
public ExtraInfo(String remark, Date acquisitionTime)
14+
public ExtraInfo(String remark, Date acquisitionTime, Date startTime, Date endTime)
1515
{
1616
super();
1717
this.remark = remark;
1818
this.acquisitionTime = acquisitionTime;
19+
this.startTime = startTime;
20+
this.endTime = endTime;
1921
}
2022

2123
public String remark;
2224
public Date acquisitionTime;
25+
public Date startTime;
26+
public Date endTime;
2327
}

‎dspace/etc/webservice/xsd/staticrequestpublications.xsd

+35
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,41 @@
6161
<xs:enumeration value="dc.contributor.inventor" />
6262
<xs:enumeration value="dc.contributor.editor" />
6363
<xs:enumeration value="dc.contributor.author" />
64+
65+
<xs:enumeration value="crismetrics_pubmed" />
66+
<xs:enumeration value="crismetrics_pubmed_last1" />
67+
<xs:enumeration value="crismetrics_pubmed_last2" />
68+
<xs:enumeration value="crismetrics_pubmed_aggregate" />
69+
<xs:enumeration value="crismetrics_pubmed_count" />
70+
<xs:enumeration value="crismetrics_pubmed_ranking" />
71+
72+
<xs:enumeration value="crismetrics_scopus" />
73+
<xs:enumeration value="crismetrics_scopus_last1" />
74+
<xs:enumeration value="crismetrics_scopus_last2" />
75+
<xs:enumeration value="crismetrics_scopus_aggregate" />
76+
<xs:enumeration value="crismetrics_scopus_count" />
77+
<xs:enumeration value="crismetrics_scopus_ranking" />
78+
79+
<xs:enumeration value="crismetrics_wos" />
80+
<xs:enumeration value="crismetrics_wos_last1" />
81+
<xs:enumeration value="crismetrics_wos_last2" />
82+
<xs:enumeration value="crismetrics_wos_aggregate" />
83+
<xs:enumeration value="crismetrics_wos_count" />
84+
<xs:enumeration value="crismetrics_wos_ranking" />
85+
86+
<xs:enumeration value="crismetrics_view" />
87+
<xs:enumeration value="crismetrics_view_last1" />
88+
<xs:enumeration value="crismetrics_view_last2" />
89+
<xs:enumeration value="crismetrics_view_aggregate" />
90+
<xs:enumeration value="crismetrics_view_count" />
91+
<xs:enumeration value="crismetrics_view_ranking" />
92+
93+
<xs:enumeration value="crismetrics_download" />
94+
<xs:enumeration value="crismetrics_download_last1" />
95+
<xs:enumeration value="crismetrics_download_last2" />
96+
<xs:enumeration value="crismetrics_download_aggregate" />
97+
<xs:enumeration value="crismetrics_download_count" />
98+
<xs:enumeration value="crismetrics_download_ranking" />
6499
</xs:restriction>
65100
</xs:simpleType>
66101

Original file line numberDiff line numberDiff line change
@@ -1,95 +1,107 @@
1-
<?xml version="1.0" encoding="UTF-8"?>
2-
<xs:schema xmlns:item="http://4science.github.io/dspace-cris/publications/schemas"
3-
xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified"
4-
targetNamespace="http://4science.github.io/dspace-cris/publications/schemas">
5-
6-
<xs:element name="crisobjects" type="item:ItemValueList"></xs:element>
7-
8-
<xs:complexType name="ItemValueList">
9-
<xs:sequence>
10-
<xs:element ref="item:crisobject" maxOccurs="unbounded"></xs:element>
11-
</xs:sequence>
12-
</xs:complexType>
13-
14-
<xs:element name="crisobject">
15-
<xs:complexType>
16-
<xs:sequence>
17-
<xs:element name="communities" type="item:communities"
18-
maxOccurs="1"></xs:element>
19-
<xs:element name="collections" type="item:collections"
20-
maxOccurs="1"></xs:element>
21-
<xs:element name="metadataitem" type="item:wsMetadata"
22-
nillable="true" minOccurs="0" maxOccurs="1"></xs:element>
23-
</xs:sequence>
24-
<xs:attribute name="itemID" type="xs:int" use="required" />
25-
<xs:attribute name="handle" type="xs:string" />
26-
</xs:complexType>
27-
</xs:element>
28-
29-
<xs:complexType name="communities">
30-
<xs:sequence>
31-
<xs:element name="community" type="item:community"
32-
minOccurs="0" maxOccurs="unbounded"></xs:element>
33-
</xs:sequence>
34-
</xs:complexType>
35-
36-
<xs:complexType name="community">
37-
<xs:sequence>
38-
<xs:element ref="item:name"></xs:element>
39-
<xs:element ref="item:handle"></xs:element>
40-
</xs:sequence>
41-
<xs:attribute name="id" type="xs:string" />
42-
</xs:complexType>
43-
44-
<xs:complexType name="collections">
45-
<xs:sequence>
46-
<xs:element name="collection" type="item:collection"
47-
minOccurs="0" maxOccurs="unbounded"></xs:element>
48-
</xs:sequence>
49-
</xs:complexType>
50-
51-
<xs:complexType name="collection">
52-
<xs:sequence>
53-
<xs:element ref="item:name"></xs:element>
54-
<xs:element ref="item:handle"></xs:element>
55-
</xs:sequence>
56-
<xs:attribute name="id" type="xs:string" />
57-
</xs:complexType>
58-
59-
60-
<xs:element name="name" type="xs:string"></xs:element>
61-
<xs:element name="handle" type="xs:string"></xs:element>
62-
63-
<xs:complexType name="wsMetadata">
64-
<xs:sequence>
65-
<xs:element name="metadata" type="item:wsMetadataValue"
66-
maxOccurs="unbounded"></xs:element>
67-
</xs:sequence>
68-
<xs:attribute name="name" type="xs:string" />
69-
</xs:complexType>
70-
71-
<xs:complexType name="wsMetadataValue">
72-
<xs:sequence>
73-
<xs:element name="term" type="xs:string"></xs:element>
74-
<xs:element name="values" type="item:wsMetadataSingleValue"
75-
minOccurs="0" maxOccurs="1"></xs:element>
76-
</xs:sequence>
77-
</xs:complexType>
78-
79-
<xs:complexType name="wsMetadataSingleValue">
80-
<xs:sequence>
81-
<xs:element name="value" maxOccurs="unbounded">
82-
<xs:complexType>
83-
<xs:simpleContent>
84-
<xs:extension base="xs:string">
85-
<xs:attribute name="authority" type="xs:string" />
86-
<xs:attribute name="place" type="xs:int" />
87-
<xs:attribute name="share" type="xs:int" />
88-
</xs:extension>
89-
</xs:simpleContent>
90-
</xs:complexType>
91-
</xs:element>
92-
</xs:sequence>
93-
</xs:complexType>
94-
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<xs:schema xmlns:item="http://4science.github.io/dspace-cris/publications/schemas"
3+
xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified"
4+
targetNamespace="http://4science.github.io/dspace-cris/publications/schemas">
5+
6+
<xs:element name="crisobjects" type="item:ItemValueList"></xs:element>
7+
8+
<xs:complexType name="ItemValueList">
9+
<xs:sequence>
10+
<xs:element ref="item:crisobject" maxOccurs="unbounded"></xs:element>
11+
</xs:sequence>
12+
</xs:complexType>
13+
14+
<xs:element name="crisobject">
15+
<xs:complexType>
16+
<xs:sequence>
17+
<xs:element name="communities" type="item:communities"
18+
maxOccurs="1"></xs:element>
19+
<xs:element name="collections" type="item:collections"
20+
maxOccurs="1"></xs:element>
21+
<xs:element name="metadataitem" type="item:wsMetadata"
22+
nillable="true" minOccurs="0" maxOccurs="1"></xs:element>
23+
<xs:element name="metrics" type="item:metric"
24+
nillable="true" minOccurs="0" maxOccurs="unbounded"></xs:element>
25+
</xs:sequence>
26+
<xs:attribute name="itemID" type="xs:int" use="required" />
27+
<xs:attribute name="handle" type="xs:string" />
28+
</xs:complexType>
29+
</xs:element>
30+
31+
<xs:complexType name="communities">
32+
<xs:sequence>
33+
<xs:element name="community" type="item:community"
34+
minOccurs="0" maxOccurs="unbounded"></xs:element>
35+
</xs:sequence>
36+
</xs:complexType>
37+
38+
<xs:complexType name="community">
39+
<xs:sequence>
40+
<xs:element ref="item:name"></xs:element>
41+
<xs:element ref="item:handle"></xs:element>
42+
</xs:sequence>
43+
<xs:attribute name="id" type="xs:string" />
44+
</xs:complexType>
45+
46+
<xs:complexType name="collections">
47+
<xs:sequence>
48+
<xs:element name="collection" type="item:collection"
49+
minOccurs="0" maxOccurs="unbounded"></xs:element>
50+
</xs:sequence>
51+
</xs:complexType>
52+
53+
<xs:complexType name="collection">
54+
<xs:sequence>
55+
<xs:element ref="item:name"></xs:element>
56+
<xs:element ref="item:handle"></xs:element>
57+
</xs:sequence>
58+
<xs:attribute name="id" type="xs:string" />
59+
</xs:complexType>
60+
61+
62+
<xs:element name="name" type="xs:string"></xs:element>
63+
<xs:element name="handle" type="xs:string"></xs:element>
64+
65+
<xs:complexType name="wsMetadata">
66+
<xs:sequence>
67+
<xs:element name="metadata" type="item:wsMetadataValue"
68+
maxOccurs="unbounded"></xs:element>
69+
</xs:sequence>
70+
<xs:attribute name="name" type="xs:string" />
71+
</xs:complexType>
72+
73+
<xs:complexType name="wsMetadataValue">
74+
<xs:sequence>
75+
<xs:element name="term" type="xs:string"></xs:element>
76+
<xs:element name="values" type="item:wsMetadataSingleValue"
77+
minOccurs="0" maxOccurs="1"></xs:element>
78+
</xs:sequence>
79+
</xs:complexType>
80+
81+
<xs:complexType name="wsMetadataSingleValue">
82+
<xs:sequence>
83+
<xs:element name="value" maxOccurs="unbounded">
84+
<xs:complexType>
85+
<xs:simpleContent>
86+
<xs:extension base="xs:string">
87+
<xs:attribute name="authority" type="xs:string" />
88+
<xs:attribute name="place" type="xs:int" />
89+
<xs:attribute name="share" type="xs:int" />
90+
</xs:extension>
91+
</xs:simpleContent>
92+
</xs:complexType>
93+
</xs:element>
94+
</xs:sequence>
95+
</xs:complexType>
96+
97+
<xs:complexType name="metric">
98+
<xs:sequence>
99+
<xs:element name="start_time" type="xs:string"></xs:element>
100+
<xs:element name="end_time" type="xs:string"></xs:element>
101+
<xs:element name="value" type="xs:string"></xs:element>
102+
<xs:element name="observation_time" type="xs:string"></xs:element>
103+
</xs:sequence>
104+
<xs:attribute name="type" type="xs:string" use="required" />
105+
</xs:complexType>
106+
95107
</xs:schema>

0 commit comments

Comments
 (0)
Please sign in to comment.