package info.elexis.server.core.connector.elexis.jaxrs;

import java.util.Optional;

import org.osgi.service.component.annotations.Component;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import ch.elexis.core.lock.types.LockInfo;
import ch.elexis.core.lock.types.LockRequest;
import ch.elexis.core.lock.types.LockResponse;
import ch.elexis.core.lock.types.LockResponse.Status;
import ch.elexis.core.server.ILockService;
import info.elexis.server.core.connector.elexis.locking.LockServiceInstance;

@Component(service = LockService.class, immediate = true)
public class LockService implements ILockService {

	private Logger log = LoggerFactory.getLogger(LockService.class);

	@Override
	public boolean isLocked(LockRequest request) {
		return LockServiceInstance.INSTANCE.isLocked(request.getLockInfo());
	}

	@Override
	public LockInfo getLockInfo(String objectId) {
		Optional<LockInfo> li = LockServiceInstance.INSTANCE.getLockInfo(objectId);
		return (li.isPresent()) ? li.get() : null;
	}

	@Override
	public LockResponse acquireOrReleaseLocks(LockRequest request) {
		// System.out.println("******************** "+request.getRequestType()+"
		// "+request.getLockInfo().getElementStoreToString());
		LockResponse lr = new LockResponse(Status.ERROR, null);
		switch (request.getRequestType()) {
		case ACQUIRE:
			lr = LockServiceInstance.INSTANCE.acquireLock(request.getLockInfo());
			break;
		case RELEASE:
			lr = LockServiceInstance.INSTANCE.releaseLock(request.getLockInfo());
			break;
		default:
			break;
		}
		// System.out.println("******************** "+lr.getStatus()+"
		// "+request.getLockInfo().getElementStoreToString());
		return lr;
	}
}

@@ -874,16 +874,72 @@
 ctId) %7B%0A
+%09%09if (objectId == null) %7B%0A%09%09%09return null;%0A%09%09%7D%0A%0A%09%09try %7B%0A%09
 %09%09Option
@@ -1006,24 +1006,25 @@
 bjectId);%0A%09%09
+%09
 return (li.i
@@ -1054,16 +1054,79 @@
 : null;%0A
+%09%09%7D catch (IllegalArgumentException iae) %7B%0A%09%09%09return null;%0A%09%09%7D%0A
 %09%7D%0A%0A%09@Ov

Fix LockService