Unverified Commit fac4bca5 authored by Jhoan Manuel Muñoz Serrano's avatar Jhoan Manuel Muñoz Serrano Committed by GitHub

Pivotal ID # 172918296: Views Metadata Export (#141)

* Pivotal ID # 172918296: Views Metadata Export

Export submission views stats
parent e9f3fa49
Pipeline #82003 passed with stages
in 5 minutes and 3 seconds
......@@ -12,12 +12,11 @@ import lombok.NoArgsConstructor;
@Data
@NoArgsConstructor
@JsonPropertyOrder({"id", "accno", "title", "seckey", "relPath", "rtime", "ctime", "mtime", "type", "accessTags",
"attributes", "section"})
@JsonPropertyOrder({"id", "accno", "title", "seckey", "relPath", "rtime", "ctime", "mtime", "views", "type",
"accessTags", "attributes", "section"})
@XmlRootElement(name = "submission")
@XmlAccessorType(XmlAccessType.NONE)
public class Submission {
private static final String SUBMISSION_TYPE = "submission";
@JsonProperty("id")
......@@ -44,6 +43,9 @@ public class Submission {
@JsonProperty("mtime")
private String mTime;
@JsonProperty("views")
private Integer views;
@JsonIgnore
private long owner_id;
......
......@@ -40,4 +40,5 @@ public class Queries {
private String pendingRelease;
private String releaseSubmission;
private String addPublicAccessTag;
private String submissionStatsQuery;
}
package uk.ac.ebi.biostd.exporter.persistence.dao;
import com.google.common.collect.ImmutableMap;
import lombok.AllArgsConstructor;
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
import org.springframework.stereotype.Component;
import uk.ac.ebi.biostd.exporter.persistence.Queries;
@Component
@AllArgsConstructor
public class StatsDao {
private static final String VIEW_TYPE = "VIEWS";
private final Queries queries;
private final NamedParameterJdbcTemplate template;
public Integer getViews(String accNo) {
return template.queryForObject(
queries.getSubmissionStatsQuery(),
ImmutableMap.of("accNo", accNo, "type", VIEW_TYPE),
Integer.class);
}
}
......@@ -17,6 +17,7 @@ import uk.ac.ebi.biostd.exporter.model.Submission;
import uk.ac.ebi.biostd.exporter.persistence.dao.FilesDao;
import uk.ac.ebi.biostd.exporter.persistence.dao.LinksDao;
import uk.ac.ebi.biostd.exporter.persistence.dao.SectionDao;
import uk.ac.ebi.biostd.exporter.persistence.dao.StatsDao;
import uk.ac.ebi.biostd.exporter.persistence.dao.SubmissionDao;
@Slf4j
......@@ -27,6 +28,7 @@ public class SubmissionService {
private final SectionDao sectionDao;
private final FilesDao filesDao;
private final LinksDao linksDao;
private final StatsDao statsDao;
public List<Submission> getUpdatedSubmissions(long syncTime) {
List<Submission> submissions = submissionDao.getUpdatedSubmissions(syncTime);
......@@ -46,6 +48,7 @@ public class SubmissionService {
submission.setAccessTags(getAccessTags(submission, accessTags));
submission.setAttributes(attributes);
submission.setViews(statsDao.getViews(submission.getAccno()));
if (submission.getRootSection_id() != 0) {
submission.setSection(processSection(sectionDao.getSection(submission.getRootSection_id())));
......
......@@ -209,4 +209,7 @@
select accNo from Section sec where sec.type = 'Publication' and sec.submission_id = :submissionId
</entry>
<entry key="submissionStatsQuery">
SELECT IFNULL((SELECT value from SubmissionStat where accNo = :accNo and type = :type), 0)
</entry>
</properties>
......@@ -101,7 +101,7 @@ public class FullExportTest extends BaseIntegrationTest {
Arrays.sort(files, Comparator.comparing(File::getName));
assertThatJsonFile(files[0], EXPECTED_PUBLIC_ONLY_JSON_PATH);
assertThatJsonFile(files[1], FullExportTest.EXPECTED_FULL_JSON_PATH);
assertThatJsonFile(files[1], EXPECTED_FULL_JSON_PATH);
}
private void assertThatJsonFile(File file, String expectedFilePath) {
......
......@@ -662,6 +662,14 @@ CREATE INDEX FKidqs3m2ntuqyuiophfwikw81a ON Submission (owner_id);
CREATE INDEX released_idx ON Submission (released);
CREATE INDEX rtime_idx ON Submission (RTime);
CREATE TABLE SubmissionStat(
id BIGINT AUTO_INCREMENT PRIMARY KEY,
accNo VARCHAR(255) NOT NULL,
value BIGINT NOT NULL,
type LONGTEXT NOT NULL,
CONSTRAINT Submission_Stat_FRG_KEY FOREIGN KEY (accNo) REFERENCES Submission (accNo) ON DELETE CASCADE
);
ALTER TABLE AttributeSubscriptionMatchEvent ADD CONSTRAINT FKb13xop3ik6im4c9ibudfx7pu0
FOREIGN KEY (submission_id) REFERENCES Submission (id);
......
......@@ -70,3 +70,5 @@ VALUES ('affiliation', null, true, 'o1', null, 14, 1);
INSERT INTO SectionAttribute (name, nameQualifierString, reference, value, valueQualifierString, section_id, ord)
VALUES ('Name', null, false, 'MRC Laboratory of Molecular Biology, Hills Road, Cambridge, CB0QH, UK', null, 15, 0);
INSERT INTO SubmissionStat(accNo, type, value) VALUES('S-EPMC3343634', 'VIEWS', 714);
......@@ -64,3 +64,5 @@ VALUES ('affiliation', null, true, 'o1', null, 9, 1);
INSERT INTO SectionAttribute (name, nameQualifierString, reference, value, valueQualifierString, section_id, ord)
VALUES ('Name', null, false, 'MRC Laboratory of Molecular Biology, Hills Road, Cambridge, CB0QH, UK', null, 10, 0);
INSERT INTO SubmissionStat(accNo, type, value) VALUES('S-EPMC3343633', 'VIEWS', 314);
......@@ -8,6 +8,7 @@
"rtime":"1460402396",
"ctime":"1460402396",
"mtime":"1460402396",
"views": 0,
"type":"submission",
"filesCount": 1,
"accessTags":[
......@@ -126,6 +127,7 @@
"rtime":"1460389106",
"ctime":"1460389106",
"mtime":"1460389106",
"views": 314,
"type":"submission",
"filesCount": 1,
"accessTags":[
......@@ -240,6 +242,7 @@
"rtime":"1460389106",
"ctime":"1460389106",
"mtime":"1460389106",
"views": 714,
"type":"submission",
"filesCount": 1,
"accessTags":[
......
......@@ -8,6 +8,7 @@
"rtime":"1460389106",
"ctime":"1460389106",
"mtime":"1460389106",
"views": 314,
"type":"submission",
"filesCount": 1,
"accessTags":[
......@@ -122,6 +123,7 @@
"rtime":"1460389106",
"ctime":"1460389106",
"mtime":"1460389106",
"views": 714,
"type":"submission",
"filesCount": 1,
"accessTags":[
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment