Skip to content

Commit

Permalink
Merge pull request #316 from neicnordic/using-refrence-id-for-export
Browse files Browse the repository at this point in the history
use reference id for exporting data
  • Loading branch information
Parisa68 authored Nov 22, 2024
2 parents cfddbbe + 379bfaf commit 93ebe1e
Show file tree
Hide file tree
Showing 6 changed files with 110 additions and 7 deletions.
28 changes: 28 additions & 0 deletions src/main/java/no/uio/ifi/localega/doa/model/Dataset.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package no.uio.ifi.localega.doa.model;

import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.Id;
import jakarta.persistence.Table;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import lombok.Setter;
import lombok.ToString;
import org.hibernate.annotations.CacheConcurrencyStrategy;
import org.hibernate.annotations.Immutable;

@org.hibernate.annotations.Cache(usage = CacheConcurrencyStrategy.TRANSACTIONAL)
@Entity
@Immutable
@Getter
@Setter
@ToString
@RequiredArgsConstructor
@Table(name = "datasets", schema = "sda")
public class Dataset {
@Id
private Long id;

@Column(name = "stable_id", unique = true)
private String stableId;
}
32 changes: 32 additions & 0 deletions src/main/java/no/uio/ifi/localega/doa/model/DatasetReferences.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package no.uio.ifi.localega.doa.model;

import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.Id;
import jakarta.persistence.Table;
import lombok.*;
import org.hibernate.annotations.CacheConcurrencyStrategy;
import org.hibernate.annotations.Immutable;
import org.hibernate.proxy.HibernateProxy;

import java.time.LocalDateTime;
import java.util.Objects;

@org.hibernate.annotations.Cache(usage = CacheConcurrencyStrategy.TRANSACTIONAL)
@Entity
@Immutable
@Getter
@Setter
@ToString
@RequiredArgsConstructor
@Table(name = "dataset_references", schema = "sda")
public class DatasetReferences {
@Id
private Integer id;

@Column(name = "dataset_id", nullable = false)
private Integer datasetId;

@Column(name = "reference_id", nullable = false)
private String referenceId;
}
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,20 @@ public void listen(String message) {

String user = claims.get(Claims.SUBJECT).getAsString();
log.info("Export request received from user {}: {}", user, exportRequest);
Collection<String> datasetIds = aaiService.getDatasetIds(exportRequest.getJwtToken());
if (StringUtils.isNotEmpty(exportRequest.getDatasetId())) {
exportDataset(user, datasetIds, exportRequest.getDatasetId(), exportRequest.getPublicKey(), exportRequest.getStartCoordinate(), exportRequest.getEndCoordinate());
Collection<String> approvedDatasetIds = aaiService.getDatasetIds(exportRequest.getJwtToken());
String requestedDatasetId = exportRequest.getDatasetId();
if (StringUtils.isNotEmpty(requestedDatasetId)) {
if (metadataService.findByReferenceId(requestedDatasetId) != null) {
Integer datasetsDbTableId = metadataService.findByReferenceId(requestedDatasetId).getDatasetId();
String stableDatasetId = metadataService.getDataset(datasetsDbTableId).getStableId();
log.info("Reference id {} mapped to dataset id {}", requestedDatasetId, stableDatasetId);
requestedDatasetId = stableDatasetId; // use stable dataset id instead of reference to complete the export as normal
Collection<String> approvedMappedDatasetIds = approvedDatasetIds.stream().map(x -> metadataService.getDataset(metadataService.findByReferenceId(x).getDatasetId()).getStableId()).toList();
approvedDatasetIds = approvedMappedDatasetIds;
}
exportDataset(user, approvedDatasetIds, requestedDatasetId, exportRequest.getPublicKey(), exportRequest.getStartCoordinate(), exportRequest.getEndCoordinate());
} else if (StringUtils.isNotEmpty(exportRequest.getFileId())) {
exportFile(user, datasetIds, exportRequest.getFileId(), exportRequest.getPublicKey(), exportRequest.getStartCoordinate(), exportRequest.getEndCoordinate());
exportFile(user, approvedDatasetIds, exportRequest.getFileId(), exportRequest.getPublicKey(), exportRequest.getStartCoordinate(), exportRequest.getEndCoordinate());
} else {
throw new RuntimeException("Either Dataset ID or File ID should be specified");
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package no.uio.ifi.localega.doa.repositories;

import no.uio.ifi.localega.doa.model.DatasetReferences;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;

@Repository
public interface DatasetReferencesRepository extends JpaRepository<DatasetReferences, Integer> {
DatasetReferences findByReferenceId(String referenceId);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package no.uio.ifi.localega.doa.repositories;

import no.uio.ifi.localega.doa.model.Dataset;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;

@Repository
public interface DatasetsRepository extends JpaRepository<Dataset, Integer> {
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

import lombok.extern.slf4j.Slf4j;
import no.uio.ifi.localega.doa.dto.File;
import no.uio.ifi.localega.doa.model.Dataset;
import no.uio.ifi.localega.doa.model.DatasetEventLog;
import no.uio.ifi.localega.doa.model.DatasetReferences;
import no.uio.ifi.localega.doa.model.LEGADataset;
import no.uio.ifi.localega.doa.repositories.DatasetEventLogRepository;
import no.uio.ifi.localega.doa.repositories.DatasetRepository;
import no.uio.ifi.localega.doa.repositories.FileRepository;
import no.uio.ifi.localega.doa.repositories.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

Expand All @@ -32,6 +32,12 @@ public class MetadataService {
@Autowired
private DatasetEventLogRepository datasetEventLogRepository;

@Autowired
private DatasetReferencesRepository datasetReferencesRepository;

@Autowired
private DatasetsRepository datasetsRepository;

/**
* Returns collection of dataset IDs present in the databse.
*
Expand Down Expand Up @@ -88,4 +94,13 @@ public DatasetEventLog findLatestByDatasetId(String datasetId) {
return optionalDatasetEventLog.orElse(null);
}

public DatasetReferences findByReferenceId(String referenceId) {
Optional<DatasetReferences> optionalDatasetReferences = Optional.ofNullable(datasetReferencesRepository.findByReferenceId(referenceId));
return optionalDatasetReferences.orElse(null);
}

public Dataset getDataset(Integer id) {
return datasetsRepository.findById(id).orElse(null);
}

}

0 comments on commit 93ebe1e

Please sign in to comment.