Commit dd1dc702 authored by Marco Descher's avatar Marco Descher

[21001] LockStatusDialog is not updated

parent f07a1728
Pipeline #16059 failed with stages
in 32 seconds
......@@ -446,7 +446,7 @@ public class CoreHub implements BundleActivator {
* @since 3.8
*/
public static void reconfigureServices() {
ElexisServerServiceHolder.get().reconfigure();
ElexisServerServiceHolder.get().validateElexisServerConnection();
}
/**
......
......@@ -3,8 +3,8 @@ package ch.elexis.core.data.propertyTester;
import org.eclipse.core.expressions.PropertyTester;
import ch.elexis.core.data.service.LocalLockServiceHolder;
import ch.elexis.core.services.ILocalLockService.Status;
import ch.elexis.core.services.IElexisServerService.ConnectionStatus;
import ch.elexis.core.services.holder.ElexisServerServiceHolder;
public class ElexisPropertyTester extends PropertyTester {
......@@ -15,7 +15,7 @@ public class ElexisPropertyTester extends PropertyTester {
public boolean test(Object receiver, String property, Object[] args, Object expectedValue){
if (PROP_STANDALONE.equals(property))
{
return Status.STANDALONE.equals(LocalLockServiceHolder.get().getStatus());
return ConnectionStatus.STANDALONE.equals(ElexisServerServiceHolder.get().getConnectionStatus());
}
return false;
}
......
......@@ -29,7 +29,6 @@ import ch.elexis.core.lock.types.LockRequest.Type;
import ch.elexis.core.lock.types.LockResponse;
import ch.elexis.core.model.IUser;
import ch.elexis.core.model.Identifiable;
import ch.elexis.core.server.ILockService;
import ch.elexis.core.services.IElexisServerService;
import ch.elexis.core.services.ILocalLockService;
import ch.elexis.data.PersistentObject;
......@@ -404,17 +403,6 @@ public class LocalLockService implements ILocalLockService {
}
}
@Override
public Status getStatus(){
if (elexisServerService.isStandalone()) {
return Status.STANDALONE;
} else if (elexisServerService == null) {
// TODO verify
return Status.LOCAL;
}
return Status.REMOTE;
}
@Override
public void shutdown(){
timer.cancel();
......
......@@ -21,6 +21,7 @@ import org.slf4j.LoggerFactory;
import com.eclipsesource.jaxrs.consumer.ConsumerFactory;
import ch.elexis.core.common.ElexisEvent;
import ch.elexis.core.common.ElexisEventTopics;
import ch.elexis.core.common.InstanceStatus;
import ch.elexis.core.constants.Elexis;
import ch.elexis.core.constants.ElexisSystemPropertyConstants;
......@@ -42,14 +43,16 @@ public class ElexisServerService implements IElexisServerService {
private Logger log = LoggerFactory.getLogger(getClass());
private static final UUID systemUuid = UUID.randomUUID();
private boolean standalone = false;
private static boolean standalone;
private String restUrl;
private Timer timer;
private IEventService eventService = new NoRemoteEventService();
private IEventService eventService;
private IInstanceService instanceService;
private ILockService lockService = new DenyAllLockService();
private ILockService lockService;
private ConnectionStatus connectionStatus;
@Reference
private IConfigService configService;
......@@ -58,9 +61,19 @@ public class ElexisServerService implements IElexisServerService {
@Activate
public void activate(){
reconfigure();
standalone = false;
lockService = new DenyAllLockService();
eventService = new NoRemoteEventService();
instanceService = new NoRemoteInstanceService();
initializeProperties();
if (!standalone) {
if (standalone) {
// standalone mode, mock services
eventService = new NoRemoteEventService();
instanceService = new NoRemoteInstanceService();
lockService = new AcceptAllLockService();
} else {
timer = new Timer();
timer.schedule(new RefreshTask(this), 5000, 5000);
......@@ -70,8 +83,8 @@ public class ElexisServerService implements IElexisServerService {
}
@Deactivate
public void deactivate() {
if(timer != null) {
public void deactivate(){
if (timer != null) {
timer.cancel();
}
}
......@@ -81,8 +94,7 @@ public class ElexisServerService implements IElexisServerService {
return systemUuid;
}
@Override
public String reconfigure(){
private void initializeProperties(){
restUrl =
System.getProperty(ElexisSystemPropertyConstants.ELEXIS_SERVER_REST_INTERFACE_URL);
if (restUrl != null && restUrl.length() > 0) {
......@@ -92,43 +104,14 @@ public class ElexisServerService implements IElexisServerService {
log.error("Invalid elexis-server url [{}], not initializing remote es services.",
restUrl);
restUrl = null;
return null;
}
connectionStatus = ConnectionStatus.LOCAL;
log.info("Operating against elexis-server instance on " + restUrl);
} else {
standalone = true;
connectionStatus = ConnectionStatus.STANDALONE;
log.debug("No elexis-server url provided, operating in stand-alone mode.");
}
verifyAndUpdateConnection();
return restUrl;
}
protected void verifyAndUpdateConnection() {
if(standalone) {
// standalone mode, mock services
eventService = new NoRemoteEventService();
instanceService = new NoRemoteInstanceService();
lockService = new AcceptAllLockService();
return;
}
if (validateConnection()) {
// connected to elexis-server, connection is up
eventService = ConsumerFactory.createConsumer(restUrl, new ElexisServerClientConfig(),
IEventService.class);
instanceService = ConsumerFactory.createConsumer(restUrl,
new ElexisServerClientConfig(), IInstanceService.class);
lockService = ConsumerFactory.createConsumer(restUrl, new ElexisServerClientConfig(),
ILockService.class);
} else {
// connected to elexis-server, connection is down
eventService = new NoRemoteEventService();
// TODO should we react otherwise here?
instanceService = new NoRemoteInstanceService();
lockService = new DenyAllLockService();
}
}
@Override
......@@ -195,24 +178,59 @@ public class ElexisServerService implements IElexisServerService {
return lockService.getLockInfo(storeToString);
}
/**
* Test the connection to the server, by a specific server url
*
* @return <code>false</code> if connection could not be made
*/
private boolean validateConnection(){
@Override
public synchronized boolean validateElexisServerConnection(){
if (ConnectionStatus.STANDALONE == connectionStatus) {
throw new IllegalStateException();
}
boolean connectionOk = false;
try {
String testRestUrl = restUrl + "/elexis/lockservice/lockInfo";
URL url = new URL(testRestUrl);
HttpURLConnection urlConn = (HttpURLConnection) url.openConnection();
urlConn.setConnectTimeout(1000);
urlConn.setReadTimeout(1500);
urlConn.connect();
return (urlConn.getResponseCode() >= 200 && urlConn.getResponseCode() < 300);
connectionOk = (urlConn.getResponseCode() >= 200 && urlConn.getResponseCode() < 300);
} catch (IOException e) {
log.warn("Error connecting to elexis-server", e);
}
return false;
if (connectionOk && connectionStatus != ConnectionStatus.REMOTE) {
// connected to elexis-server, connection is up
connectionStatus = ConnectionStatus.REMOTE;
eventService = ConsumerFactory.createConsumer(restUrl, new ElexisServerClientConfig(),
IEventService.class);
contextService.postEvent(ElexisEventTopics.EVENT_RELOAD, IEventService.class);
instanceService = ConsumerFactory.createConsumer(restUrl,
new ElexisServerClientConfig(), IInstanceService.class);
contextService.postEvent(ElexisEventTopics.EVENT_RELOAD, IInstanceService.class);
lockService = ConsumerFactory.createConsumer(restUrl, new ElexisServerClientConfig(),
ILockService.class);
contextService.postEvent(ElexisEventTopics.EVENT_RELOAD, ILockService.class);
}
if (!connectionOk && connectionStatus != ConnectionStatus.LOCAL) {
// connected to elexis-server, connection is down
connectionStatus = ConnectionStatus.LOCAL;
eventService = new NoRemoteEventService();
contextService.postEvent(ElexisEventTopics.EVENT_RELOAD, IEventService.class);
// TODO should we react otherwise here?
instanceService = new NoRemoteInstanceService();
contextService.postEvent(ElexisEventTopics.EVENT_RELOAD, IInstanceService.class);
lockService = new DenyAllLockService();
contextService.postEvent(ElexisEventTopics.EVENT_RELOAD, ILockService.class);
}
return connectionOk;
}
@Override
public ConnectionStatus getConnectionStatus(){
return connectionStatus;
}
}
......@@ -14,7 +14,7 @@ public class RefreshTask extends TimerTask {
@Override
public void run(){
elexisServerService.verifyAndUpdateConnection();
elexisServerService.validateElexisServerConnection();
InstanceStatus instanceStatus = elexisServerService.createInstanceStatus();
elexisServerService.updateInstanceStatus(instanceStatus);
......
......@@ -19,8 +19,8 @@ import org.eclipse.ui.ISaveablePart2;
import org.eclipse.ui.part.ViewPart;
import ch.elexis.core.data.events.ElexisEventDispatcher;
import ch.elexis.core.data.service.LocalLockServiceHolder;
import ch.elexis.core.services.ILocalLockService;
import ch.elexis.core.services.IElexisServerService.ConnectionStatus;
import ch.elexis.core.services.holder.ElexisServerServiceHolder;
import ch.elexis.core.ui.actions.GlobalActions;
import ch.elexis.core.ui.actions.GlobalEventDispatcher;
import ch.elexis.core.ui.actions.IActivationListener;
......@@ -99,7 +99,7 @@ public class PatientDetailView2 extends ViewPart implements ISaveablePart2, IAct
public void activation(boolean mode){
if (!mode) {
// save does not happen via locking in standalone mode
if (LocalLockServiceHolder.get().getStatus() == ILocalLockService.Status.STANDALONE) {
if (ElexisServerServiceHolder.get().getConnectionStatus() == ConnectionStatus.STANDALONE) {
pb.save();
}
} else {
......
......@@ -95,4 +95,5 @@ Service-Component: OSGI-INF/ch.elexis.core.ui.util.CoreUiUtil.xml,
OSGI-INF/ch.elexis.core.ui.compatibility.UiStartupHandler.xml,
OSGI-INF/ch.elexis.core.ui.internal.CoreOperationAdvisor.xml,
OSGI-INF/ch.elexis.core.ui.services.EncounterServiceHolder.xml,
OSGI-INF/ch.elexis.core.ui.startup.StartupHandler.xml
OSGI-INF/ch.elexis.core.ui.startup.StartupHandler.xml,
OSGI-INF/ch.elexis.core.ui.locks.LockStatusDialogHandler.xml
<?xml version="1.0" encoding="UTF-8"?>
<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0" name="ch.elexis.core.ui.locks.LockStatusDialogHandler">
<property name="event.topics" value="info/elexis/model/reload"/>
<service>
<provide interface="org.eclipse.ui.commands.IElementUpdater"/>
<provide interface="org.osgi.service.event.EventHandler"/>
</service>
<implementation class="ch.elexis.core.ui.locks.LockStatusDialogHandler"/>
</scr:component>
\ No newline at end of file
......@@ -17,15 +17,15 @@ import org.eclipse.ui.PlatformUI;
import ch.elexis.core.data.activator.CoreHub;
import ch.elexis.core.data.interfaces.IPersistentObject;
import ch.elexis.core.data.service.LocalLockServiceHolder;
import ch.elexis.core.data.util.BriefExternUtil;
import ch.elexis.core.data.util.LocalLock;
import ch.elexis.core.data.util.NoPoUtil;
import ch.elexis.core.model.IDocumentLetter;
import ch.elexis.core.model.Identifiable;
import ch.elexis.core.services.IConflictHandler;
import ch.elexis.core.services.IElexisServerService.ConnectionStatus;
import ch.elexis.core.services.ILocalDocumentService;
import ch.elexis.core.services.ILocalLockService.Status;
import ch.elexis.core.services.holder.ElexisServerServiceHolder;
import ch.elexis.core.ui.locks.AcquireLockUi;
import ch.elexis.core.ui.locks.ILockHandler;
import ch.elexis.core.ui.services.LocalDocumentServiceHolder;
......@@ -60,7 +60,7 @@ public class StartEditLocalDocumentHandler extends AbstractHandler implements IH
LocalDocumentServiceHolder.getService();
if (localDocumentService.isPresent()) {
ILocalDocumentService service = localDocumentService.get();
if (LocalLockServiceHolder.get().getStatus() == Status.REMOTE) {
if (ElexisServerServiceHolder.get().getConnectionStatus() == ConnectionStatus.REMOTE) {
if (object instanceof IPersistentObject) {
IPersistentObject lockObject = (IPersistentObject) object;
AcquireLockUi.aquireAndRun(lockObject, new ILockHandler() {
......
......@@ -13,13 +13,14 @@ import ch.elexis.core.data.interfaces.IPersistentObject;
import ch.elexis.core.data.service.LocalLockServiceHolder;
import ch.elexis.core.lock.types.LockResponse;
import ch.elexis.core.model.Identifiable;
import ch.elexis.core.services.ILocalLockService;
import ch.elexis.core.services.IElexisServerService.ConnectionStatus;
import ch.elexis.core.services.holder.ElexisServerServiceHolder;
public class AcquireLockBlockingUi {
private static Logger logger = LoggerFactory.getLogger(AcquireLockBlockingUi.class);
public static void aquireAndRun(IPersistentObject lockPo, ILockHandler handler){
if (LocalLockServiceHolder.get().getStatus() == ILocalLockService.Status.STANDALONE) {
if (ElexisServerServiceHolder.get().getConnectionStatus() == ConnectionStatus.STANDALONE) {
handler.lockAcquired();
return;
}
......
......@@ -20,7 +20,8 @@ import ch.elexis.core.data.activator.CoreHub;
import ch.elexis.core.data.service.LocalLockServiceHolder;
import ch.elexis.core.lock.types.LockInfo;
import ch.elexis.core.lock.types.LockResponse;
import ch.elexis.core.services.ILocalLockService.Status;
import ch.elexis.core.services.IElexisServerService.ConnectionStatus;
import ch.elexis.core.services.holder.ElexisServerServiceHolder;
import ch.elexis.data.PersistentObject;
public class LockStatusDialog extends TitleAreaDialog {
......@@ -71,10 +72,10 @@ public class LockStatusDialog extends TitleAreaDialog {
lblSystemUuid.setText("System UUID: " + LocalLockServiceHolder.get().getSystemUuid());
Label lblLockStatus = new Label(container, SWT.NONE);
Status status = LocalLockServiceHolder.get().getStatus();
ConnectionStatus connectinStatus = ElexisServerServiceHolder.get().getConnectionStatus();
StringBuilder statusString = new StringBuilder();
statusString.append("Lock-Service: " + status.name());
if (status != Status.STANDALONE) {
statusString.append("Lock-Service: " + connectinStatus.name());
if (connectinStatus != ConnectionStatus.STANDALONE) {
statusString.append(" @ " + System
.getProperty(ElexisSystemPropertyConstants.ELEXIS_SERVER_REST_INTERFACE_URL));
}
......@@ -92,7 +93,7 @@ public class LockStatusDialog extends TitleAreaDialog {
LockInfo lockInfo = (LockInfo) object;
LockResponse lockResponse = LocalLockServiceHolder.get().releaseLock(lockInfo);
if (!lockResponse.isOk()) {
setErrorMessage("Error releasing lock "+lockInfo.getElementStoreToString());
setErrorMessage("Error releasing lock " + lockInfo.getElementStoreToString());
error = true;
break;
}
......
......@@ -10,17 +10,23 @@ import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.commands.ICommandService;
import org.eclipse.ui.commands.IElementUpdater;
import org.eclipse.ui.menus.UIElement;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.event.Event;
import org.osgi.service.event.EventHandler;
import ch.elexis.core.data.events.ElexisEvent;
import ch.elexis.core.data.events.ElexisEventDispatcher;
import ch.elexis.core.data.service.LocalLockServiceHolder;
import ch.elexis.core.services.ILocalLockService;
import ch.elexis.core.services.ILocalLockService.Status;
import com.google.common.base.Objects;
import ch.elexis.core.common.ElexisEventTopics;
import ch.elexis.core.server.ILockService;
import ch.elexis.core.services.IElexisServerService.ConnectionStatus;
import ch.elexis.core.services.holder.ElexisServerServiceHolder;
import ch.elexis.core.ui.Hub;
import ch.elexis.core.ui.events.ElexisUiEventListenerImpl;
import ch.elexis.core.ui.icons.Images;
public class LockStatusDialogHandler extends AbstractHandler implements IElementUpdater {
@Component(property = org.osgi.service.event.EventConstants.EVENT_TOPIC + "="
+ ElexisEventTopics.EVENT_RELOAD)
public class LockStatusDialogHandler extends AbstractHandler
implements IElementUpdater, EventHandler {
public static final String COMMAND_ID = "ch.elexis.core.ui.locks.LockStatusDialog";
......@@ -28,23 +34,6 @@ public class LockStatusDialogHandler extends AbstractHandler implements IElement
private ImageDescriptor remoteIcon;
private ImageDescriptor standaloneIcon;
public LockStatusDialogHandler(){
ElexisEventDispatcher.getInstance().addListeners(
new ElexisUiEventListenerImpl(ILocalLockService.class, ElexisEvent.EVENT_RELOAD) {
private ICommandService commandService;
@Override
public void runInUi(ElexisEvent ev){
if (commandService == null) {
commandService = (ICommandService) PlatformUI.getWorkbench()
.getService(ICommandService.class);
}
commandService.refreshElements(COMMAND_ID, null);
}
});
}
@Override
public Object execute(ExecutionEvent event) throws ExecutionException{
LockStatusDialog lockStatusDialog = new LockStatusDialog(Hub.getActiveShell());
......@@ -63,14 +52,24 @@ public class LockStatusDialogHandler extends AbstractHandler implements IElement
if (localIcon == null || remoteIcon == null || standaloneIcon == null) {
prepareIcons();
}
ILocalLockService.Status status = LocalLockServiceHolder.get().getStatus();
ConnectionStatus connectionStatus = ElexisServerServiceHolder.get().getConnectionStatus();
if (status == Status.STANDALONE) {
if (connectionStatus == ConnectionStatus.STANDALONE) {
element.setIcon(standaloneIcon);
} else if (status == Status.LOCAL) {
} else if (connectionStatus == ConnectionStatus.LOCAL) {
element.setIcon(localIcon);
} else if (status == Status.REMOTE) {
} else if (connectionStatus == ConnectionStatus.REMOTE) {
element.setIcon(remoteIcon);
}
}
@Override
public void handleEvent(Event event){
Object property = event.getProperty(ElexisEventTopics.ECLIPSE_E4_DATA);
if (Objects.equal(property, ILockService.class)) {
ICommandService commandService =
(ICommandService) PlatformUI.getWorkbench().getService(ICommandService.class);
commandService.refreshElements(COMMAND_ID, null);
}
}
}
......@@ -61,8 +61,9 @@ import ch.elexis.core.data.interfaces.IPersistentObject;
import ch.elexis.core.data.service.LocalLockServiceHolder;
import ch.elexis.core.lock.types.LockResponse;
import ch.elexis.core.model.IUser;
import ch.elexis.core.services.ILocalLockService.Status;
import ch.elexis.core.services.IElexisServerService.ConnectionStatus;
import ch.elexis.core.services.holder.ContextServiceHolder;
import ch.elexis.core.services.holder.ElexisServerServiceHolder;
import ch.elexis.core.ui.Hub;
import ch.elexis.core.ui.UiDesk;
import ch.elexis.core.ui.actions.RestrictedAction;
......@@ -193,7 +194,7 @@ public class UserManagementPreferencePage extends PreferencePage
@Override
public void doRun(User user){
IUser currentUser = ContextServiceHolder.get().getActiveUser().orElse(null);
IUser currentUser = ContextServiceHolder.get().getActiveUser().orElse(null);
if (currentUser != null) {
if (currentUser.getId().equals(user.getId())) {
MessageDialog.openWarning(getShell(), "Warnung",
......@@ -209,7 +210,8 @@ public class UserManagementPreferencePage extends PreferencePage
};
popManager.add(deleteUserAction);
if (!(Status.STANDALONE == LocalLockServiceHolder.get().getStatus())) {
if (!(ConnectionStatus.STANDALONE == ElexisServerServiceHolder.get()
.getConnectionStatus())) {
lockUserAction = new RestrictedAction(AccessControlDefaults.USER_CREATE,
Messages.Leistungscodes_editItem) {
......@@ -265,7 +267,8 @@ public class UserManagementPreferencePage extends PreferencePage
}
});
if (!(Status.STANDALONE == LocalLockServiceHolder.get().getStatus())) {
if (!(ConnectionStatus.STANDALONE == ElexisServerServiceHolder.get()
.getConnectionStatus())) {
Button btnLock = new Button(compositeButtons, SWT.FLAT | SWT.TOGGLE);
btnLock.setSelection(
LocalLockServiceHolder.get().isLocked((IPersistentObject) wvUser.getValue()));
......@@ -317,7 +320,8 @@ public class UserManagementPreferencePage extends PreferencePage
StructuredSelection ss = (StructuredSelection) e.getSelection();
wvUser.setValue(ss == null ? null : (User) ss.getFirstElement());
setUnlocked(Status.STANDALONE == LocalLockServiceHolder.get().getStatus());
setUnlocked(ConnectionStatus.STANDALONE == ElexisServerServiceHolder.get()
.getConnectionStatus());
compositeEdit.layout(true, true);
});
......@@ -497,10 +501,11 @@ public class UserManagementPreferencePage extends PreferencePage
"Der selektierte Kontakt ist kein Mandant.");
return;
}
KontaktSelektor ks =
new KontaktSelektor(UiDesk.getTopShell(), Kontakt.class, "Rechnungs-Kontakt auswählen",
"Bitte selektieren Sie den dem Mandant zugeordneten Rechnungs-Kontakt", new String[] {});
KontaktSelektor ks = new KontaktSelektor(UiDesk.getTopShell(), Kontakt.class,
"Rechnungs-Kontakt auswählen",
"Bitte selektieren Sie den dem Mandant zugeordneten Rechnungs-Kontakt",
new String[] {});
int ret = ks.open();
if (ret == Window.OK) {
Kontakt kontakt = (Kontakt) ks.getSelection();
......@@ -650,7 +655,8 @@ public class UserManagementPreferencePage extends PreferencePage
updateUserList();
setUnlocked(Status.STANDALONE == LocalLockServiceHolder.get().getStatus());
setUnlocked(
ConnectionStatus.STANDALONE == ElexisServerServiceHolder.get().getConnectionStatus());
sash.setWeights(new int[] {
1, 5
......
......@@ -14,12 +14,14 @@ import ch.elexis.core.lock.types.LockResponse;
public interface IElexisServerService {
/**
* Reconfigure the connection to the server
*
* @return the elexis-server URL this service is operating against, or <code>null</code>
*/
public String reconfigure();
public enum ConnectionStatus {
/** Not connected to an ES */
STANDALONE,
/** Connected to an ES, and connection is live */
REMOTE,
/** Connected to an ES, but connection */
LOCAL
}
/**
* A unique id for this instance of Elexis. Changes on every restart.
......@@ -53,6 +55,7 @@ public interface IElexisServerService {
/**
* Create a fresh, populated {@link InstanceStatus} object
*
* @return
*/
public InstanceStatus createInstanceStatus();
......@@ -95,4 +98,19 @@ public interface IElexisServerService {
* @return
*/
public LockInfo getLockInfo(String storeToString);
/**
* Validate the connection to the server (applicable in non-standalone mode only). If the
* connection to the server fails, switches to Local Mode
*
*
* @return <code>true</code> if the connection to ES is live, else <code>false</code>
*/
public boolean validateElexisServerConnection();
/**
*
* @return
*/
public ConnectionStatus getConnectionStatus();
}
......@@ -9,17 +9,11 @@ import ch.elexis.core.lock.types.LockResponse;
import ch.elexis.core.server.ILockService;
/**
* Additional convinience methods for locking with PersistentObject.
*
* @author thomas
* Additional convenience methods for locking with PersistentObject.
*
*/
public interface ILocalLockService extends ILockService {
public enum Status {
LOCAL, REMOTE, STANDALONE
}
public LockResponse acquireLock(Object object);
public LockResponse releaseLock(Object object);
......@@ -46,7 +40,5 @@ public interface ILocalLockService extends ILockService {
public LockResponse acquireLockBlocking(Object po, int msTimeout,
IProgressMonitor monitor);
public Status getStatus();
public void shutdown();
}