Commit 6fafef63 authored by Matija Obreza's avatar Matija Obreza

Unlinked entity PDCI from AccessionId

parent 9d0edef9
......@@ -77,7 +77,7 @@ public abstract class AccessionData implements IdUUID, Serializable {
private Date lastModifiedDate;
@MapsId
@OneToOne(cascade = { CascadeType.PERSIST, CascadeType.MERGE }, optional = false, orphanRemoval = false)
@OneToOne(cascade = { CascadeType.PERSIST, CascadeType.MERGE }, fetch = FetchType.EAGER, optional = false, orphanRemoval = false)
@JoinColumn(name = "id")
private AccessionId accessionId;
......
......@@ -29,7 +29,6 @@ import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import javax.persistence.PrePersist;
import javax.persistence.Table;
......@@ -54,14 +53,11 @@ public class AccessionId extends VersionedAuditedModel implements IdUUID {
@Column(columnDefinition = "binary(16)")
protected UUID uuid;
@OneToOne(cascade = {}, fetch = FetchType.LAZY, mappedBy = "accession", optional = true, orphanRemoval = true)
private PDCI pdci;
@OneToMany(cascade = {}, fetch = FetchType.LAZY, mappedBy = "accession", orphanRemoval = false)
private List<AccessionTrait> traits;
@ManyToMany(cascade = {}, fetch = FetchType.LAZY)
@JoinTable(name = "accelistitems", joinColumns = @JoinColumn(name = "acceid") , inverseJoinColumns = @JoinColumn(name = "listid") )
@JoinTable(name = "accelistitems", joinColumns = @JoinColumn(name = "acceid"), inverseJoinColumns = @JoinColumn(name = "listid"))
private Set<AccessionList> lists;
@PrePersist
......@@ -80,14 +76,6 @@ public class AccessionId extends VersionedAuditedModel implements IdUUID {
this.uuid = uuid;
}
public PDCI getPdci() {
return pdci;
}
public void setPdci(PDCI pdci) {
this.pdci = pdci;
}
public Set<AccessionList> getLists() {
return lists;
}
......@@ -95,12 +83,12 @@ public class AccessionId extends VersionedAuditedModel implements IdUUID {
public void setLists(Set<AccessionList> lists) {
this.lists = lists;
}
//
// public List<AccessionTrait> getTraits() {
// return traits;
// }
//
// public void setTraits(List<AccessionTrait> traits) {
// this.traits = traits;
// }
//
// public List<AccessionTrait> getTraits() {
// return traits;
// }
//
// public void setTraits(List<AccessionTrait> traits) {
// this.traits = traits;
// }
}
......@@ -28,7 +28,7 @@ public interface AccessionIdRepository extends JpaRepository<AccessionId, Long>
@Query("select aid from AccessionId aid where aid.uuid is null")
List<AccessionId> findMissingUuid(Pageable pageable);
@Query("select aid from AccessionId aid left join aid.pdci pdci where pdci.score is null")
@Query("select aid from AccessionId aid, PDCI pdci where pdci.accession=aid and pdci.score is null")
List<AccessionId> findMissingPDCI(Pageable pageable);
}
......@@ -40,7 +40,7 @@ public interface PDCIRepository extends JpaRepository<PDCI, Long> {
* @return [ Float min(pdci.score), Float max(pdci.score), Double
* avg(pdci.score), Long count(pdci) ]
*/
@Query("select min(pdci.score), max(pdci.score), avg(pdci.score), count(pdci) from Accession a join a.accessionId.pdci pdci where a.institute = ?1 and a.historic = false")
@Query("select min(pdci.score), max(pdci.score), avg(pdci.score), count(pdci) from Accession a, PDCI pdci where a.institute = ?1 and a.historic = false and pdci.accession=a")
Object statistics(FaoInstitute faoInstitute);
/**
......@@ -50,7 +50,7 @@ public interface PDCIRepository extends JpaRepository<PDCI, Long> {
* @param faoInstitute
* @return List of [ scoreHist, count ]
*/
@Query("select pdci.scoreHist, count(pdci) from Accession a join a.accessionId.pdci pdci where a.institute = ?1 group by pdci.scoreHist")
@Query("select pdci.scoreHist, count(pdci) from Accession a, PDCI pdci where a.institute = ?1 and pdci.accession=a group by pdci.scoreHist")
List<Object[]> histogram(FaoInstitute faoInstitute);
}
......@@ -250,8 +250,6 @@ public interface GenesysService {
AccessionHistoric getHistoricAccession(UUID uuid);
void updatePDCI(Collection<AccessionDetails> ads);
PDCI loadPDCI(Long accessionId);
PDCI updatePDCI(Long id);
......
......@@ -1666,44 +1666,6 @@ public class GenesysServiceImpl implements GenesysService, DatasetService {
return repoPdci.save(pdciCalculator.updatePdci(pdci, accessionId));
}
@Override
@Transactional
@CacheEvict(value = "statistics", allEntries = true)
public void updatePDCI(Collection<AccessionDetails> ads) {
if (pdciCalculator == null) {
return;
}
Set<Long> accessionIds = new HashSet<Long>();
for (AccessionDetails accessionDetails : ads) {
if (accessionDetails != null) {
accessionIds.add(accessionDetails.getId());
}
}
List<PDCI> pdcis = new ArrayList<PDCI>();
pdcis.addAll(repoPdci.findByAccessionId(accessionIds));
for (AccessionDetails accessionDetails : ads) {
if (accessionDetails == null) {
continue;
}
PDCI pdci = null;
for (PDCI existing : pdcis) {
if (existing.getAccession().getId().equals(accessionDetails.getId())) {
pdci = existing;
break;
}
}
if (pdci == null) {
pdci = new PDCI();
pdci.setAccession(accessionIdRepository.findOne(accessionDetails.getId()));
pdcis.add(pdci);
}
pdciCalculator.updatePdci(pdci, accessionDetails);
}
repoPdci.save(pdcis);
}
@Override
public PDCIStatistics statisticsPDCI(FaoInstitute faoInstitute) {
PDCIStatistics stats = new PDCIStatistics();
......
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