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

Pivotal ID #173016435 : Add attach to attributes artificially (#140)

* added atttributes

* code review changes
parent feed7f8b
Pipeline #79245 passed with stages
in 2 minutes and 54 seconds
package uk.ac.ebi.biostd.exporter.service;
import static java.lang.Long.parseLong;
import static java.util.stream.Collectors.toList;
import static uk.ac.ebi.biostd.exporter.utils.DateUtils.getFromEpochSeconds;
import java.util.ArrayList;
import java.util.List;
......@@ -16,7 +18,6 @@ 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.SubmissionDao;
import uk.ac.ebi.biostd.exporter.utils.DateUtils;
@Slf4j
@Service
......@@ -39,9 +40,11 @@ public class SubmissionService {
public Submission processSubmission(Submission submission) {
log.debug("processing submissions with accno: '{}' and id '{}'", submission.getAccno(), submission.getId());
List<Attribute> attributes = getAttributes(submission);
submission.setAccessTags(getAccessTags(submission));
List<String> accessTags = submissionDao.getAccessTags(submission.getId());
List<Attribute> attributes = getAttributes(submission, accessTags);
submission.setAccessTags(getAccessTags(submission, accessTags));
submission.setAttributes(attributes);
if (submission.getRootSection_id() != 0) {
......@@ -57,52 +60,53 @@ public class SubmissionService {
return submission;
}
private List<String> getAccessTags(Submission submission) {
private List<String> getAccessTags(Submission submission, List<String> accessTags) {
List<String> tags = new ArrayList<>();
tags.add(submissionDao.getUserEmail(submission.getOwner_id()));
tags.addAll(submissionDao.getAccessTags(submission.getId()));
tags.addAll(accessTags);
tags.add("#" + submission.getOwner_id());
return tags;
}
private List<Attribute> getAttributes(Submission submission) {
private List<Attribute> getAttributes(Submission submission, List<String> accessTags) {
List<Attribute> subAttributes = submissionDao.getAttributes(submission.getId());
subAttributes
.add(new Attribute("ReleaseDate", DateUtils.getFromEpochSeconds(Long.valueOf(submission.getRTime()))));
subAttributes.add(new Attribute("ReleaseDate", getFromEpochSeconds(parseLong(submission.getRTime()))));
subAttributes.add(new Attribute("Title", submission.getTitle()));
accessTags.forEach(tag -> addProjectAttribute(subAttributes, tag));
return subAttributes;
}
private void addProjectAttribute(List<Attribute> subAttributes, String accessTag) {
if (accessTag.equals("Public")) {
return;
}
if (subAttributes.stream().noneMatch(attribute -> attribute.getName().equals(accessTag))) {
subAttributes.add(new Attribute("AttachTo", accessTag));
}
}
private Section processSection(Section section) {
long sectionId = section.getId();
section.setAttributes(sectionDao.getSectionAttributes(section.getId()));
section.setFiles(getSectionFiles(sectionId));
section.setLinks(getSectionLinks(sectionId));
section.setSubsections(getSubsections(sectionId));
return section;
}
private List<File> getSectionFiles(long sectionId) {
return sectionDao.getSectionFiles(sectionId)
.stream()
.map(file -> {
file.setAttributes(filesDao.getFilesAttributes(file.getId()));
return file;
})
.collect(toList());
.stream()
.peek(file -> file.setAttributes(filesDao.getFilesAttributes(file.getId())))
.collect(toList());
}
private List<Link> getSectionLinks(long sectionId) {
return linksDao.getLinks(sectionId)
.stream()
.map(link -> {
link.setAttributes(linksDao.getLinkAttributes(link.getId()));
return link;
})
.collect(toList());
.stream()
.peek(link -> link.setAttributes(linksDao.getLinkAttributes(link.getId())))
.collect(toList());
}
private List<Section> getSubsections(long sectionId) {
......
......@@ -18,18 +18,18 @@ public class DateUtils {
return ZonedDateTime.now(ZoneId.of("Europe/London"));
}
public String getFromEpochSeconds(long seconds) {
public static 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) {
public static 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());
dateTime.getDayOfMonth(), dateTime.getHour(), dateTime.getMinute(), dateTime.getSecond());
}
public String getElapsedTime(long milliseconds) {
public static String getElapsedTime(long milliseconds) {
long hours = MILLISECONDS.toHours(milliseconds);
long minute = MILLISECONDS.toMinutes(milliseconds) - HOURS.toMinutes(hours);
long second = MILLISECONDS.toSeconds(milliseconds) - HOURS.toSeconds(hours) - MINUTES.toSeconds(minute);
......
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