865 |
865 |
@Override
|
866 |
866 |
@Transactional(readOnly = false)
|
867 |
867 |
public boolean moveDerivate(SpecimenOrObservationBase<?> from, SpecimenOrObservationBase<?> to, DerivedUnit derivate) {
|
868 |
|
return moveDerivate(from.getUuid(), to.getUuid(), derivate.getUuid()).isOk();
|
|
868 |
return moveDerivate(from!=null?from.getUuid():null, to.getUuid(), derivate.getUuid()).isOk();
|
869 |
869 |
}
|
870 |
870 |
|
871 |
871 |
@Override
|
872 |
872 |
@Transactional(readOnly = false)
|
873 |
873 |
public UpdateResult moveDerivate(UUID specimenFromUuid, UUID specimenToUuid, UUID derivateUuid) {
|
874 |
874 |
// reload specimens to avoid session conflicts
|
875 |
|
SpecimenOrObservationBase<?> from = load(specimenFromUuid);
|
|
875 |
SpecimenOrObservationBase<?> from = null;
|
|
876 |
if(specimenFromUuid!=null){
|
|
877 |
from = load(specimenFromUuid);
|
|
878 |
}
|
876 |
879 |
SpecimenOrObservationBase<?> to = load(specimenToUuid);
|
877 |
880 |
DerivedUnit derivate = (DerivedUnit) load(derivateUuid);
|
878 |
881 |
|
879 |
|
if (from == null || to == null || derivate == null) {
|
|
882 |
if ((specimenFromUuid!=null && from == null) || to == null || derivate == null) {
|
880 |
883 |
throw new TransientObjectException("One of the CDM entities has not been saved to the data base yet. Moving only works for persisted/saved CDM entities.\n" +
|
881 |
884 |
"Operation was move "+derivate+ " from "+from+" to "+to);
|
882 |
885 |
}
|
... | ... | |
887 |
890 |
if(toType==SpecimenOrObservationType.FieldUnit //moving to FieldUnit always works
|
888 |
891 |
|| derivateType==SpecimenOrObservationType.Media //moving media always works
|
889 |
892 |
|| (derivateType.isKindOf(toType) && toType!=derivateType)){ //moving only to parent derivate type
|
890 |
|
// remove derivation event from parent specimen of dragged object
|
891 |
|
DerivationEvent eventToRemove = null;
|
892 |
|
for (DerivationEvent event : from.getDerivationEvents()) {
|
893 |
|
if (event.getDerivatives().contains(derivate)) {
|
894 |
|
eventToRemove = event;
|
895 |
|
break;
|
|
893 |
if(from!=null){
|
|
894 |
// remove derivation event from parent specimen of dragged object
|
|
895 |
DerivationEvent eventToRemove = null;
|
|
896 |
for (DerivationEvent event : from.getDerivationEvents()) {
|
|
897 |
if (event.getDerivatives().contains(derivate)) {
|
|
898 |
eventToRemove = event;
|
|
899 |
break;
|
|
900 |
}
|
|
901 |
}
|
|
902 |
from.removeDerivationEvent(eventToRemove);
|
|
903 |
if(eventToRemove!=null){
|
|
904 |
// add new derivation event to target and copy the event parameters of the old one
|
|
905 |
DerivationEvent derivedFromNewOriginalEvent = DerivationEvent.NewSimpleInstance(to, derivate, null);
|
|
906 |
derivedFromNewOriginalEvent.setActor(eventToRemove.getActor());
|
|
907 |
derivedFromNewOriginalEvent.setDescription(eventToRemove.getDescription());
|
|
908 |
derivedFromNewOriginalEvent.setInstitution(eventToRemove.getInstitution());
|
|
909 |
derivedFromNewOriginalEvent.setTimeperiod(eventToRemove.getTimeperiod());
|
|
910 |
derivedFromNewOriginalEvent.setType(eventToRemove.getType());
|
|
911 |
to.addDerivationEvent(derivedFromNewOriginalEvent);
|
|
912 |
derivate.setDerivedFrom(derivedFromNewOriginalEvent);
|
896 |
913 |
}
|
897 |
914 |
}
|
898 |
|
from.removeDerivationEvent(eventToRemove);
|
899 |
|
if(eventToRemove!=null){
|
900 |
|
// add new derivation event to target and copy the event parameters of the old one
|
|
915 |
else{
|
|
916 |
//derivative had no parent before so we use empty derivation event
|
901 |
917 |
DerivationEvent derivedFromNewOriginalEvent = DerivationEvent.NewSimpleInstance(to, derivate, null);
|
902 |
|
derivedFromNewOriginalEvent.setActor(eventToRemove.getActor());
|
903 |
|
derivedFromNewOriginalEvent.setDescription(eventToRemove.getDescription());
|
904 |
|
derivedFromNewOriginalEvent.setInstitution(eventToRemove.getInstitution());
|
905 |
|
derivedFromNewOriginalEvent.setTimeperiod(eventToRemove.getTimeperiod());
|
906 |
|
derivedFromNewOriginalEvent.setType(eventToRemove.getType());
|
907 |
918 |
to.addDerivationEvent(derivedFromNewOriginalEvent);
|
908 |
919 |
derivate.setDerivedFrom(derivedFromNewOriginalEvent);
|
909 |
920 |
}
|
Allow null for parent when moving derivatives