Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EVA-2623: Variant history common changes #71

Merged
merged 4 commits into from
Nov 23, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
*/
package uk.ac.ebi.ampt2d.commons.accession.core.models;

import sun.reflect.generics.reflectiveObjects.NotImplementedException;
import uk.ac.ebi.ampt2d.commons.accession.persistence.models.IAccessionedObject;

import java.time.LocalDateTime;
Expand All @@ -33,16 +32,22 @@ public class HistoryEvent<MODEL, ACCESSION> implements IEvent<MODEL, ACCESSION>

private ACCESSION mergedInto;

private ACCESSION splitInto;

private LocalDateTime localDateTime;

private MODEL data;

public HistoryEvent(EventType eventType, ACCESSION accession, Integer version, ACCESSION mergedInto,
public HistoryEvent(EventType eventType, ACCESSION accession, Integer version, ACCESSION destinationAccession,
LocalDateTime localDateTime, MODEL data) {
this.eventType = eventType;
this.accession = accession;
this.version = version;
this.mergedInto = mergedInto;
if(this.eventType == EventType.MERGED){
this.mergedInto = destinationAccession;
}else if(this.eventType == EventType.RS_SPLIT){
this.splitInto = destinationAccession;
}
this.localDateTime = localDateTime;
this.data = data;
}
Expand All @@ -61,13 +66,14 @@ public Integer getVersion() {
return version;
}

@Override
public ACCESSION getMergedInto() {
return mergedInto;
}

@Override
public ACCESSION getSplitInto() {
throw new NotImplementedException();
return splitInto;
}

@Override
Expand Down Expand Up @@ -113,6 +119,11 @@ public static <MODEL, ACCESSION> HistoryEvent<MODEL, ACCESSION> merged(ACCESSION
return new HistoryEvent<>(EventType.MERGED, accession, null, mergedInto, localDateTime, null);
}

public static <MODEL, ACCESSION> HistoryEvent<MODEL, ACCESSION> split(ACCESSION accession, ACCESSION splitInto,
LocalDateTime localDateTime) {
return new HistoryEvent<>(EventType.RS_SPLIT, accession, null, splitInto, localDateTime, null);
}

public static <MODEL, ACCESSION> HistoryEvent<MODEL, ACCESSION> updated(ACCESSION accession, int version,
MODEL data, LocalDateTime localDateTime) {
return new HistoryEvent<>(EventType.UPDATED, accession, version, null, localDateTime, data);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,13 @@ public interface IEvent<MODEL, ACCESSION> {
*/
ACCESSION getSplitInto();

/**
* @return Accession of the target object resulted because of the event (merged, rs-split etc)
*/
default ACCESSION getDestinationAccession() {
return getMergedInto() != null ? getMergedInto() : getSplitInto();
}

/**
* @return Type of the event like creation, update, etc, executed on the accessioned object
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,9 @@ public interface IHistoryRepository<ACCESSION, OPERATION_ENTITY, ID extends Seri

List<OPERATION_ENTITY> findAllByAccession(ACCESSION accession);

}
List<OPERATION_ENTITY> findAllByAccessionOrMergeIntoOrSplitInto(ACCESSION accession, ACCESSION mergeInto, ACCESSION splitInto);

default List<OPERATION_ENTITY> findAllInvolvedIn(ACCESSION accession) {
return findAllByAccessionOrMergeIntoOrSplitInto(accession, accession, accession);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,11 @@ protected List<HistoryEvent<MODEL, ACCESSION>> generateHistory(
newEvent = HistoryEvent.merged(operation.getAccession(),
operation.getMergedInto(), operation.getCreatedDate());
break;
case RS_SPLIT:
versionMap = mapVersions(operation.getInactiveObjects());
newEvent = HistoryEvent.split(operation.getAccession(), operation.getSplitInto(),
operation.getCreatedDate());
break;
case UPDATED:
IAccessionedObject<MODEL, ?, ACCESSION> dataBeforeUpdate = operation.getInactiveObjects().get(0);
int version = dataBeforeUpdate.getVersion();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,5 @@ public interface InactiveAccessionService<

List<? extends IEvent<MODEL, ACCESSION>> getEvents(ACCESSION accession);

List<? extends IEvent<MODEL, ACCESSION>> getAllEventsInvolvedIn(ACCESSION accession);
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,26 @@ public class HistoryEventDTO<ACCESSION, DTO> {

private Integer version;

private ACCESSION splitInto;

private ACCESSION mergedInto;

private LocalDateTime localDateTime;

private DTO data;

public HistoryEventDTO(){
nitin-ebi marked this conversation as resolved.
Show resolved Hide resolved

}

public <MODEL> HistoryEventDTO(HistoryEvent<MODEL, ACCESSION> event, Function<MODEL, DTO> modelToDTO) {
this.type = event.getEventType();
this.accession = event.getAccession();
if(event.getEventType() == EventType.MERGED){
this.mergedInto = event.getMergedInto();
}else if(event.getEventType() == EventType.RS_SPLIT){
this.splitInto = event.getSplitInto();
}
this.mergedInto = event.getMergedInto();
this.localDateTime = event.getLocalDateTime();
this.data = modelToDTO.apply(event.getData());
Expand All @@ -61,6 +72,20 @@ public ACCESSION getMergedInto() {
return mergedInto;
}

public ACCESSION getSplitInto(){
return splitInto;
}

public ACCESSION getDestinationAccession(){
if(this.type == EventType.MERGED){
return mergedInto;
}else if(this.type == EventType.RS_SPLIT){
return splitInto;
}else{
return null;
}
}

public LocalDateTime getLocalDateTime() {
return localDateTime;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ public abstract class OperationEntity<ACCESSION> {
@Column
private ACCESSION mergeInto;

@Column
private ACCESSION splitInto;

@Enumerated(value = EnumType.STRING)
@Column(nullable = false)
private EventType eventType;
Expand All @@ -74,6 +77,10 @@ public ACCESSION getMergeInto() {
return mergeInto;
}

public ACCESSION getSplitInto() {
return splitInto;
}

public EventType getEventType() {
return eventType;
}
Expand All @@ -89,7 +96,11 @@ public LocalDateTime getCreatedDate() {
public void fill(EventType type, ACCESSION origin, ACCESSION destination, String reason) {
this.eventType = type;
this.accession = origin;
this.mergeInto = destination;
if (type == EventType.MERGED) {
this.mergeInto = destination;
} else if (type == EventType.RS_SPLIT) {
this.splitInto = destination;
}
this.reason = reason;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,11 @@
*/
package uk.ac.ebi.ampt2d.commons.accession.persistence.jpa.models;

import sun.reflect.generics.reflectiveObjects.NotImplementedException;
import uk.ac.ebi.ampt2d.commons.accession.core.models.EventType;
import uk.ac.ebi.ampt2d.commons.accession.persistence.models.IAccessionedObject;
import uk.ac.ebi.ampt2d.commons.accession.core.models.IEvent;
import uk.ac.ebi.ampt2d.commons.accession.persistence.jpa.entities.InactiveAccessionEntity;
import uk.ac.ebi.ampt2d.commons.accession.persistence.jpa.entities.OperationEntity;
import uk.ac.ebi.ampt2d.commons.accession.persistence.models.IAccessionedObject;

import java.io.Serializable;
import java.time.LocalDateTime;
Expand All @@ -34,6 +33,8 @@ public class JpaEvent<MODEL, ACCESSION extends Serializable> implements IEvent<M

private ACCESSION mergeInto;

private ACCESSION splitInto;

private EventType eventType;

private String reason;
Expand All @@ -45,8 +46,12 @@ public class JpaEvent<MODEL, ACCESSION extends Serializable> implements IEvent<M
public JpaEvent(OperationEntity<ACCESSION> lastOperation,
List<? extends InactiveAccessionEntity<MODEL, ACCESSION>> inactiveEntities) {
this.accession = lastOperation.getAccession();
this.mergeInto = lastOperation.getMergeInto();
this.eventType = lastOperation.getEventType();
if(this.eventType == EventType.MERGED){
this.mergeInto = lastOperation.getMergeInto();
}else if(this.eventType == EventType.RS_SPLIT){
this.splitInto = lastOperation.getSplitInto();
}
this.reason = lastOperation.getReason();
this.createdDate = lastOperation.getCreatedDate();
this.inactiveEntities = inactiveEntities;
Expand All @@ -64,7 +69,7 @@ public ACCESSION getMergedInto() {

@Override
public ACCESSION getSplitInto() {
throw new NotImplementedException();
return splitInto;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,16 @@
*/
package uk.ac.ebi.ampt2d.commons.accession.persistence.jpa.service;

import sun.reflect.generics.reflectiveObjects.NotImplementedException;
import uk.ac.ebi.ampt2d.commons.accession.core.models.EventType;
import uk.ac.ebi.ampt2d.commons.accession.persistence.services.BasicInactiveAccessionService;
import uk.ac.ebi.ampt2d.commons.accession.persistence.models.IAccessionedObject;
import uk.ac.ebi.ampt2d.commons.accession.persistence.repositories.IHistoryRepository;
import uk.ac.ebi.ampt2d.commons.accession.core.models.IEvent;
import uk.ac.ebi.ampt2d.commons.accession.persistence.jpa.repositories.InactiveAccessionRepository;
import uk.ac.ebi.ampt2d.commons.accession.persistence.jpa.entities.InactiveAccessionEntity;
import uk.ac.ebi.ampt2d.commons.accession.persistence.jpa.entities.OperationEntity;
import uk.ac.ebi.ampt2d.commons.accession.persistence.jpa.models.JpaEvent;
import uk.ac.ebi.ampt2d.commons.accession.persistence.jpa.repositories.InactiveAccessionRepository;
import uk.ac.ebi.ampt2d.commons.accession.persistence.models.IAccessionedObject;
import uk.ac.ebi.ampt2d.commons.accession.persistence.repositories.IHistoryRepository;
import uk.ac.ebi.ampt2d.commons.accession.persistence.services.BasicInactiveAccessionService;

import java.io.Serializable;
import java.util.List;
Expand Down Expand Up @@ -67,7 +68,7 @@ protected void saveHistory(EventType type, ACCESSION accession, ACCESSION mergeI
OPERATION_ENTITY operation = historyEntitySupplier.get();
operation.fill(type, accession, mergeInto, reason);
final OPERATION_ENTITY savedOperation = historyRepository.save(operation);
if(accessionInactiveEntities!=null) {
if (accessionInactiveEntities != null) {
accessionInactiveEntities.forEach(entity -> entity.setHistoryId(savedOperation.getId()));
inactiveAccessionRepository.saveAll(accessionInactiveEntities);
}
Expand Down Expand Up @@ -99,4 +100,9 @@ public List<IEvent<MODEL, ACCESSION>> getEvents(ACCESSION accession) {
return operations.stream().map(this::toJpaOperation).collect(Collectors.toList());
}

@Override
public List<? extends IEvent<MODEL, ACCESSION>> getAllEventsInvolvedIn(ACCESSION accession) {
throw new NotImplementedException();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -78,4 +78,9 @@ public IEvent<MODEL, ACCESSION> getLastEvent(ACCESSION accession) {
public List<? extends IEvent<MODEL, ACCESSION>> getEvents(ACCESSION accession) {
return historyRepository.findAllByAccession(accession);
}

@Override
public List<? extends IEvent<MODEL, ACCESSION>> getAllEventsInvolvedIn(ACCESSION accession) {
return historyRepository.findAllInvolvedIn(accession);
}
}