Skip to content

Commit

Permalink
enhanced the transformation of the fetched tuple fron List<Object[]> …
Browse files Browse the repository at this point in the history
…to List<MetadataEntity>
  • Loading branch information
waterflow80 committed May 17, 2024
1 parent c26668b commit fc9b52a
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 18 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package uk.ac.ebi.eva.evaseqcol.entities;

import lombok.Data;
import lombok.NoArgsConstructor;
import org.hibernate.annotations.CreationTimestamp;

import javax.persistence.Column;
Expand All @@ -13,6 +14,7 @@

@Data
@Embeddable
@NoArgsConstructor
public class SeqColMetadataEntity {

@Column(name = "source_id")
Expand All @@ -30,6 +32,14 @@ public class SeqColMetadataEntity {
@CreationTimestamp
private Date createdOn = new Date();

public SeqColMetadataEntity(String sourceIdentifier, String sourceUrl, SeqColEntity.NamingConvention namingConvention,
Date createdOn) {
this.sourceIdentifier = sourceIdentifier;
this.sourceUrl = sourceUrl;
this.namingConvention = namingConvention;
this.createdOn = createdOn;
}

public SeqColMetadataEntity setNamingConvention(SeqColEntity.NamingConvention namingConvention) {
this.namingConvention = namingConvention;
return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.stream.Collectors;

@Service
public class SeqColLevelOneService {
Expand Down Expand Up @@ -215,28 +216,20 @@ public List<SeqColExtendedDataEntity<List<Integer>>> constructIntegerListExtData
return integerListExtendedDataEntities;
}

public List<SeqColMetadataEntity> metadataObjectArrayListToMetadataList(List<Object[]> metadataArray) {
List<SeqColMetadataEntity> metadataList = new ArrayList<>();
for (Object[] metadataElements : metadataArray) {
SeqColMetadataEntity metadataEntity = new SeqColMetadataEntity();
metadataEntity.setSourceIdentifier((String) metadataElements[0]);
metadataEntity.setSourceUrl((String) metadataElements[1]);
metadataEntity.setNamingConvention(SeqColEntity.NamingConvention.valueOf(
(String) metadataElements[2]
));
metadataEntity.setCreatedOn((Date) metadataElements[3]);
metadataList.add(metadataEntity);
}
return metadataList;
public SeqColMetadataEntity transformToMetadataEntity(Object[] tuple) {
return new SeqColMetadataEntity(
(String) tuple[0],
(String) tuple[1],
SeqColEntity.NamingConvention.valueOf((String) tuple[2]),
(Date) tuple[3]
);
}

public List<SeqColMetadataEntity> getAllMetadata() {
List<Object[]> metadataArrayList = repository.findAllMetadata();
return metadataObjectArrayListToMetadataList(metadataArrayList);
return repository.findAllMetadata().stream().map(this::transformToMetadataEntity).collect(Collectors.toList());
}

public List<SeqColMetadataEntity> getMetadataBySeqcolDigest(String digest) {
List<Object[]> metadataArrayList = repository.findMetadataBySeqColDigest(digest);
return metadataObjectArrayListToMetadataList(metadataArrayList);
return repository.findMetadataBySeqColDigest(digest).stream().map(this::transformToMetadataEntity).collect(Collectors.toList());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ public IngestionResultEntity fetchAndInsertAllSeqColByAssemblyAccession(String a
boolean sourceIdExists = levelOneService.getAllMetadata().stream()
.anyMatch(md -> md.getSourceIdentifier().equals(assemblyAccession));
if (sourceIdExists) {
logger.warn("Seqcol objects for assembly" + assemblyAccession + " have been already ingested. Nothing to ingest !");
logger.warn("Seqcol objects for assembly " + assemblyAccession + " have been already ingested... Nothing to ingest !");
throw new AssemblyAlreadyIngestedException(assemblyAccession);
}
Optional<Map<String, Object>> seqColDataMap = ncbiSeqColDataSource.getAllPossibleSeqColExtendedData(assemblyAccession);
Expand Down

0 comments on commit fc9b52a

Please sign in to comment.