Commit d71ccfe8 authored by Marco Descher's avatar Marco Descher 🏔

[16515] Remove message parties

parent f7a7eef2
Pipeline #11269 passed with stages
in 4 minutes and 29 seconds
......@@ -8,7 +8,6 @@ import javax.persistence.Entity;
import javax.persistence.EntityListeners;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.Lob;
import javax.persistence.Table;
......@@ -33,11 +32,11 @@ public class Message extends AbstractEntityWithId implements EntityWithId, Entit
@Convert(converter = BooleanCharacterConverterSafe.class)
protected boolean deleted = false;
@JoinColumn(name = "ORIGIN")
protected Kontakt origin;
@Column(length = 25)
protected String origin;
@JoinColumn(name = "DESTINATION")
protected Kontakt destination;
@Column(length = 25)
protected String destination;
@Column
protected LocalDateTime dateTime;
......@@ -50,19 +49,19 @@ public class Message extends AbstractEntityWithId implements EntityWithId, Entit
@Lob
protected String messageCodes;
public Kontakt getOrigin(){
public String getOrigin(){
return origin;
}
public void setOrigin(Kontakt origin){
public void setOrigin(String origin){
this.origin = origin;
}
public Kontakt getDestination(){
public String getDestination(){
return destination;
}
public void setDestination(Kontakt destination){
public void setDestination(String destination){
this.destination = destination;
}
......
package ch.elexis.core.model;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
......@@ -14,11 +13,8 @@ import com.google.gson.Gson;
import ch.elexis.core.jpa.entities.Kontakt;
import ch.elexis.core.jpa.model.adapter.AbstractIdDeleteModelAdapter;
import ch.elexis.core.jpa.model.adapter.AbstractIdModelAdapter;
import ch.elexis.core.model.message.MessageParty;
import ch.elexis.core.model.util.internal.ModelUtil;
import ch.elexis.core.services.INamedQuery;
import ch.elexis.core.services.holder.CoreModelServiceHolder;
public class Message extends AbstractIdDeleteModelAdapter<ch.elexis.core.jpa.entities.Message>
implements Identifiable, IMessage {
......@@ -31,25 +27,13 @@ public class Message extends AbstractIdDeleteModelAdapter<ch.elexis.core.jpa.ent
}
@Override
public IMessageParty getSender(){
Kontakt origin = getEntity().getOrigin();
return findFirstUserForContact(origin).map(e -> new MessageParty(e.getId(), 0))
.orElse(null);
public String getSender(){
return getEntity().getOrigin();
}
@SuppressWarnings("unchecked")
@Override
public void setSender(IMessageParty value){
String identifier = value.getIdentifier();
if (value.getType() == 0) {
Optional<IUser> user = CoreModelServiceHolder.get().load(identifier, IUser.class);
if (user.isPresent()) {
IContact assignedContact = user.get().getAssignedContact();
Kontakt entity = ((AbstractIdModelAdapter<Kontakt>) assignedContact).getEntity();
getEntityMarkDirty().setOrigin(entity);
}
}
// TODO support for station, silently ignored by now
public void setSender(String identifier){
getEntityMarkDirty().setOrigin(identifier);
}
/**
......@@ -59,34 +43,22 @@ public class Message extends AbstractIdDeleteModelAdapter<ch.elexis.core.jpa.ent
*/
@Override
public void setSender(IUser user){
setSender(new MessageParty(user.getId(), 0));
setSender(user.getId());
}
@Override
public List<IMessageParty> getReceiver(){
// TODO support for station
Kontakt destination = getEntity().getDestination();
Optional<MessageParty> messageParty =
findFirstUserForContact(destination).map(e -> new MessageParty(e.getId(), 0));
return (messageParty.isPresent()) ? Collections.singletonList(messageParty.get())
: new ArrayList<>();
public List<String> getReceiver(){
return Collections.singletonList(getEntity().getDestination());
}
@SuppressWarnings("unchecked")
@Override
public void addReceiver(IMessageParty messageParty){
List<IMessageParty> receiver = getReceiver();
receiver.add(messageParty);
// TODO suppport multiple receivers
String identifier = messageParty.getIdentifier();
if (messageParty.getType() == 0) {
Optional<IUser> user = CoreModelServiceHolder.get().load(identifier, IUser.class);
if (user.isPresent()) {
Kontakt contact =
((AbstractIdModelAdapter<Kontakt>) user.get().getAssignedContact()).getEntity();
getEntityMarkDirty().setDestination(contact);
}
}
public void addReceiver(String receiver){
getEntityMarkDirty().setDestination(receiver);
}
@Override
public void addReceiver(IUser receiver){
addReceiver(receiver.getId());
}
@Override
......
......@@ -7,7 +7,6 @@ import org.junit.Before;
import org.junit.Test;
import ch.elexis.core.model.message.MessageCode;
import ch.elexis.core.model.message.MessageParty;
import ch.elexis.core.test.AbstractTest;
public class MessageTest extends AbstractTest {
......@@ -28,7 +27,7 @@ public class MessageTest extends AbstractTest {
IMessage message = coreModelService.create(IMessage.class);
message.setSender(user);
message.addReceiver(new MessageParty(user.getId()));
message.addReceiver(user);
message.setCreateDateTime(LocalDateTime.now());
message.setMessageText(
"That makes me angry, and when Dr. Evil gets angry Mr. Bigglesworth gets upset. And when Mr. Bigglesworth gets upset, people DIE!");
......
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