[Minor] Added StrolchComponent interface to SimpleServiceHandler
This commit is contained in:
parent
55462432b6
commit
181e3dfdff
4
pom.xml
4
pom.xml
|
@ -39,6 +39,10 @@
|
|||
<groupId>li.strolch</groupId>
|
||||
<artifactId>li.strolch.persistence.api</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>li.strolch</groupId>
|
||||
<artifactId>li.strolch.runtime</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>ch.eitchnet</groupId>
|
||||
|
|
|
@ -19,21 +19,36 @@
|
|||
*/
|
||||
package li.strolch.command;
|
||||
|
||||
import li.strolch.persistence.api.StrolchTransaction;
|
||||
import ch.eitchnet.privilege.model.Restrictable;
|
||||
|
||||
|
||||
/**
|
||||
* @author Robert von Burg <eitch@eitchnet.ch>
|
||||
*
|
||||
*/
|
||||
public abstract class AbstractCommand implements Restrictable {
|
||||
public abstract class Command implements Restrictable {
|
||||
|
||||
private final StrolchTransaction tx;
|
||||
|
||||
public Command(StrolchTransaction tx) {
|
||||
this.tx = tx;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the {@link StrolchTransaction} bound to this {@link Command}'s runtime
|
||||
*
|
||||
* @return the {@link StrolchTransaction} bound to this {@link Command}'s runtime
|
||||
*/
|
||||
protected StrolchTransaction tx() {
|
||||
return this.tx;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see ch.eitchnet.privilege.model.Restrictable#getPrivilegeName()
|
||||
*/
|
||||
@Override
|
||||
public String getPrivilegeName() {
|
||||
return AbstractCommand.class.getName();
|
||||
return Command.class.getName();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -43,6 +58,6 @@ public abstract class AbstractCommand implements Restrictable {
|
|||
public Object getPrivilegeValue() {
|
||||
return this.getClass().getName();
|
||||
}
|
||||
|
||||
|
||||
public abstract void doCommand();
|
||||
}
|
|
@ -23,7 +23,7 @@ package li.strolch.service;
|
|||
* @author Robert von Burg <eitch@eitchnet.ch>
|
||||
*
|
||||
*/
|
||||
public abstract class AbstractService implements Service {
|
||||
public abstract class AbstractService<T extends ServiceArgument> implements Service<T> {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
|
|
|
@ -27,9 +27,7 @@ import ch.eitchnet.privilege.model.Restrictable;
|
|||
* @author Robert von Burg <eitch@eitchnet.ch>
|
||||
*
|
||||
*/
|
||||
public interface Service extends Serializable, Restrictable {
|
||||
public interface Service<T extends ServiceArgument> extends Serializable, Restrictable {
|
||||
|
||||
public ServiceResult doService(ServiceArgument argument);
|
||||
|
||||
public ServiceArgument getServiceArgument();
|
||||
public ServiceResult doService(T argument);
|
||||
}
|
||||
|
|
|
@ -0,0 +1,8 @@
|
|||
package li.strolch.service;
|
||||
|
||||
import ch.eitchnet.privilege.model.Certificate;
|
||||
|
||||
public interface ServiceHandler {
|
||||
|
||||
public <T extends ServiceArgument> ServiceResult doService(Certificate certificate, Service<T> service, T argument);
|
||||
}
|
|
@ -21,23 +21,27 @@ package li.strolch.service;
|
|||
|
||||
import java.text.MessageFormat;
|
||||
|
||||
import li.strolch.runtime.component.StrolchComponent;
|
||||
import ch.eitchnet.privilege.handler.PrivilegeHandler;
|
||||
import ch.eitchnet.privilege.model.Certificate;
|
||||
|
||||
/**
|
||||
* @author Robert von Burg <eitch@eitchnet.ch>
|
||||
*/
|
||||
public class SimpleServiceHandler {
|
||||
public class SimpleServiceHandler extends StrolchComponent implements ServiceHandler {
|
||||
|
||||
private PrivilegeHandler privilegeHandler;
|
||||
|
||||
public ServiceResult doService(Certificate certificate, Service service, ServiceArgument argument) {
|
||||
@Override
|
||||
public <T extends ServiceArgument> ServiceResult doService(Certificate certificate, Service<T> service, T argument) {
|
||||
|
||||
try {
|
||||
|
||||
this.privilegeHandler.getPrivilegeContext(certificate).validateAction(service);
|
||||
|
||||
return service.doService(argument);
|
||||
ServiceResult serviceResult = service.doService(argument);
|
||||
|
||||
return serviceResult;
|
||||
|
||||
} catch (Exception e) {
|
||||
String msg = "Failed to perform service {0} due to exception {1}"; //$NON-NLS-1$
|
||||
|
|
Loading…
Reference in New Issue