Unverified Commit feed7f8b authored by Juan Rada's avatar Juan Rada Committed by GitHub

Pivotal #ID: 172585277: Allow folders in submission (#138)

* added directories support
parent cb7fb6fa
Pipeline #75888 passed with stages
in 7 minutes and 27 seconds
......@@ -3,19 +3,15 @@ package uk.ac.ebi.biostd.exporter.model;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
import java.util.List;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlRootElement;
import lombok.Data;
import lombok.NoArgsConstructor;
@Data
@NoArgsConstructor
@XmlRootElement(name = "file")
@XmlAccessorType(XmlAccessType.NONE)
public class File {
private static final String TYPE = "file";
private static final String DIRECTORY_TYPE = "directory";
private static final String FILE_TYPE = "file";
@JsonIgnore
private long id;
......@@ -29,9 +25,12 @@ public class File {
@JsonProperty("size")
private long size;
@JsonIgnore
private boolean directory;
@JsonProperty("type")
public String getType() {
return TYPE;
return directory ? DIRECTORY_TYPE : FILE_TYPE;
}
@JsonProperty("attributes")
......
package uk.ac.ebi.biostd.exporter.persistence.dao;
import static java.util.Collections.singletonMap;
import java.util.List;
import lombok.AllArgsConstructor;
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
import org.springframework.stereotype.Component;
......@@ -14,10 +11,17 @@ import uk.ac.ebi.biostd.exporter.persistence.mappers.AttributeMapper;
import uk.ac.ebi.biostd.exporter.persistence.mappers.FileMapper;
import uk.ac.ebi.biostd.exporter.persistence.mappers.SectionMapper;
import java.util.List;
import java.util.Map;
import static java.util.Collections.singletonMap;
@Component
@AllArgsConstructor
public class SectionDao {
private static final String SEC_ID_PARAM = "section_id";
private final Queries queries;
private final NamedParameterJdbcTemplate template;
private final AttributeMapper attributeMapper;
......@@ -25,29 +29,22 @@ public class SectionDao {
private final FileMapper fileMapper;
public List<Attribute> getSectionAttributes(long sectionId) {
return template.query(
queries.getSectionAttributesQuery(), singletonMap("section_id", sectionId), attributeMapper);
return template.query(queries.getSectionAttributesQuery(), sectionId(sectionId), attributeMapper);
}
public List<File> getSectionFiles(long sectionId) {
return template.query(queries.getSectionFilesQuery(), singletonMap("section_id", sectionId), fileMapper);
}
public Long getSectionFilesCount(long sectionId) {
Long files = template.queryForObject(
queries.getSectionFilesCountQuery(), singletonMap("section_id", sectionId), Long.class);
Long referencedFiles = template.queryForObject(
queries.getSectionReferencedFilesCountQuery(), singletonMap("section_id", sectionId), Long.class);
return files + referencedFiles;
return template.query(queries.getSectionFilesQuery(), sectionId(sectionId), fileMapper);
}
public Section getSection(long sectionId) {
return template.queryForObject(
queries.getSectionByIdQuery(), singletonMap("section_id", sectionId), sectionMapper);
return template.queryForObject(queries.getSectionByIdQuery(), sectionId(sectionId), sectionMapper);
}
public List<Section> getSectionSections(long sectionId) {
return template.query(queries.getSectionSectionsQuery(), singletonMap("section_id", sectionId), sectionMapper);
return template.query(queries.getSectionSectionsQuery(), sectionId(sectionId), sectionMapper);
}
private Map<String, ?> sectionId(long sectionId) {
return singletonMap(SEC_ID_PARAM, sectionId);
}
}
......@@ -16,6 +16,7 @@ public class FileMapper implements RowMapper<File> {
file.setPath(rs.getString("path"));
file.setName(rs.getString("name"));
file.setSize(rs.getLong("size"));
file.setDirectory(rs.getBoolean("directory"));
return file;
}
}
......@@ -20,13 +20,11 @@ public class DateUtils {
public String getFromEpochSeconds(long seconds) {
OffsetDateTime dateTime = Instant.ofEpochSecond(seconds).atOffset(ZoneOffset.UTC);
return String.format("%d-%02d-%02d", dateTime.getYear(), dateTime.getMonthValue(), dateTime.getDayOfMonth());
}
public String getFromEpochMilliseconds(long milliseconds) {
OffsetDateTime dateTime = Instant.ofEpochMilli(milliseconds).atOffset(ZoneOffset.UTC);
return String.format("%d-%02d-%02d %d:%02d:%02d", dateTime.getYear(), dateTime.getMonthValue(),
dateTime.getDayOfMonth(), dateTime.getHour(), dateTime.getMinute(), dateTime.getSecond());
}
......
......@@ -158,7 +158,7 @@
</entry>
<entry key="sectionFilesQuery">
select id, name, size, path from FileRef where sectionId = :section_id
select id, name, size, directory, path from FileRef where sectionId = :section_id
</entry>
<entry key="sectionFilesCountQuery">
......
......@@ -90,10 +90,10 @@ public class FullExportTest extends BaseIntegrationTest {
@Test
public void testFullExport() {
assertExportJobResults(EXPECTED_FULL_JSON_PATH);
assertExportJobResults();
}
private void assertExportJobResults(String expectedFullJson) {
private void assertExportJobResults() {
exportPipeline.execute();
File[] files = folder.getRoot().listFiles();
......@@ -101,10 +101,9 @@ public class FullExportTest extends BaseIntegrationTest {
Arrays.sort(files, Comparator.comparing(File::getName));
assertThatJsonFile(files[0], EXPECTED_PUBLIC_ONLY_JSON_PATH);
assertThatJsonFile(files[1], expectedFullJson);
assertThatJsonFile(files[1], FullExportTest.EXPECTED_FULL_JSON_PATH);
}
private void assertThatJsonFile(File file, String expectedFilePath) {
String content = FileUtil.readFile(file.getAbsolutePath());
String expected = FileUtil.readFile(getResource(expectedFilePath).getAbsolutePath());
......
......@@ -48,7 +48,7 @@ public class PartialSubmissionExporterTest {
@Mock
private RestTemplate mockRestTemplate;
private Submission updatedSubmission = new Submission();
private final Submission updatedSubmission = new Submission();
@InjectMocks
private PartialSubmissionExporter testInstance;
......@@ -56,7 +56,6 @@ public class PartialSubmissionExporterTest {
@Before
public void setup() throws Exception {
updatedSubmission.setAccno(ACCNO);
when(mockSubService.getUpdatedSubmissions(anyLong())).thenReturn(singletonList(updatedSubmission));
when(mockSubService.getDeletedSubmissions(anyLong())).thenReturn(singletonList(ACCNO));
when(mockProperties.getFilePath()).thenReturn(folder.getRoot().getAbsolutePath() + "/");
......
......@@ -157,16 +157,16 @@
],
"files":[
{
"path":null,
"name":"NIHMS40251-supplement-1.pdf",
"size":9170139,
"attributes":[
"path": null,
"name": "NIHMS40251-supplement-1.pdf",
"size": 9170139,
"attributes": [
{
"name":"Type",
"value":"application(pdf)"
"name": "Type",
"value": "application(pdf)"
}
],
"type":"file"
"type": "file"
}
],
"subsections":[
......
......@@ -39,16 +39,16 @@
],
"files":[
{
"path":null,
"name":"NIHMS40251-supplement-1.pdf",
"size":9170139,
"attributes":[
"path": null,
"name": "NIHMS40251-supplement-1.pdf",
"size": 9170139,
"attributes": [
{
"name":"Type",
"value":"application(pdf)"
"name": "Type",
"value": "application(pdf)"
}
],
"type":"file"
"type": "file"
}
],
"subsections":[
......
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