1515import java .util .Set ;
1616import java .util .UUID ;
1717
18- import javax .faces .event .AjaxBehaviorEvent ;
19-
2018import org .apache .commons .configuration .XMLConfiguration ;
2119import org .apache .commons .configuration .tree .xpath .XPathExpressionEngine ;
2220import org .apache .commons .lang .StringUtils ;
5755import io .goobi .workflow .api .vocabulary .VocabularyAPIManager ;
5856import io .goobi .workflow .api .vocabulary .helper .ExtendedVocabularyRecord ;
5957import io .goobi .workflow .locking .LockingBean ;
58+ import jakarta .faces .event .AjaxBehaviorEvent ;
6059import lombok .Getter ;
6160import lombok .Setter ;
6261import lombok .extern .log4j .Log4j2 ;
@@ -704,11 +703,7 @@ public void changeRelationship(Relationship relationship) {
704703 relationshipSourceType = relationship .getSourceType ();
705704 changeRelationshipEntity = new Entity (getConfiguration (), currentProcess );
706705 addRelationship (changeRelationshipEntity .getCurrentType ());
707- if (relationship .isReverse ()) {
708- setRelationship (relationship .getType ().getReversedRelationshipNameEn ());
709- } else {
710- setRelationship (relationship .getType ().getRelationshipNameEn ());
711- }
706+ setRelationship (relationship .getType ().getRelationshipNameEn ());
712707 }
713708
714709 public void changeRelationshipBetweenEntities () {
@@ -730,9 +725,18 @@ public void changeRelationshipBetweenEntities() {
730725 break ;
731726 }
732727 }
728+
729+ // find reverse relationship type
730+ Optional <RelationshipType > otherRelationshipType = entityType .getConfiguredRelations ().stream ()
731+ .filter (r -> !selectedRelationship .getReversedRelationshipNameEn ().isBlank () && selectedRelationship .getReversedRelationshipNameEn ().equals (r .getRelationshipNameEn ()))
732+ .findFirst ();
733+ if (otherRelationshipType .isEmpty ()) {
734+ otherRelationshipType = Optional .of (selectedRelationship );
735+ }
736+
733737 if (otherRelationship != null ) {
734738 // update other type
735- otherRelationship .setType (selectedRelationship );
739+ otherRelationship .setType (otherRelationshipType . get () );
736740 if (selectedRelationship .isDisplayAdditionalData ()) {
737741 otherRelationship .setAdditionalData (relationshipData );
738742 otherRelationship .setSourceType (relationshipSourceType );
@@ -795,11 +799,18 @@ public void addRelationshipBetweenEntities() {
795799 return ;
796800 }
797801
798- entity .addRelationship (selectedEntity , relationshipData , relationshipStartDate , relationshipEndDate , selectedRelationship , false ,
802+ entity .addRelationship (selectedEntity , relationshipData , relationshipStartDate , relationshipEndDate , selectedRelationship ,
799803 relationshipSourceType );
800804
805+ // find reverse relationship type
806+ Optional <RelationshipType > otherRelationshipType = entityType .getConfiguredRelations ().stream ()
807+ .filter (r -> !selectedRelationship .getReversedRelationshipNameEn ().isBlank () && selectedRelationship .getReversedRelationshipNameEn ().equals (r .getRelationshipNameEn ()))
808+ .findFirst ();
809+ if (otherRelationshipType .isEmpty ()) {
810+ otherRelationshipType = Optional .of (selectedRelationship );
811+ }
801812 // reverse relationship in other entity
802- selectedEntity .addRelationship (entity , relationshipData , relationshipStartDate , relationshipEndDate , selectedRelationship , true ,
813+ selectedEntity .addRelationship (entity , relationshipData , relationshipStartDate , relationshipEndDate , otherRelationshipType . get () ,
803814 relationshipSourceType );
804815
805816 // save both entities
0 commit comments