[Major] removed project li.strolch.persistence.api
Moved all classes to li.strolch.runtime
This commit is contained in:
parent
cb89abd469
commit
f0f98ebd4a
4
pom.xml
4
pom.xml
|
@ -35,10 +35,6 @@
|
||||||
<groupId>li.strolch</groupId>
|
<groupId>li.strolch</groupId>
|
||||||
<artifactId>li.strolch.model</artifactId>
|
<artifactId>li.strolch.model</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
|
||||||
<groupId>li.strolch</groupId>
|
|
||||||
<artifactId>li.strolch.persistence.api</artifactId>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>li.strolch</groupId>
|
<groupId>li.strolch</groupId>
|
||||||
<artifactId>li.strolch.runtime</artifactId>
|
<artifactId>li.strolch.runtime</artifactId>
|
||||||
|
|
|
@ -1,60 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright 2013 Robert von Burg <eitch@eitchnet.ch>
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
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 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 Command.class.getName();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @see ch.eitchnet.privilege.model.Restrictable#getPrivilegeValue()
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public Object getPrivilegeValue() {
|
|
||||||
return this.getClass().getName();
|
|
||||||
}
|
|
||||||
|
|
||||||
public abstract void doCommand();
|
|
||||||
}
|
|
|
@ -1,142 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright 2013 Robert von Burg <eitch@eitchnet.ch>
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
package li.strolch.service;
|
|
||||||
|
|
||||||
import java.text.MessageFormat;
|
|
||||||
|
|
||||||
import li.strolch.exception.StrolchException;
|
|
||||||
import li.strolch.runtime.agent.api.OrderMap;
|
|
||||||
import li.strolch.runtime.agent.api.ResourceMap;
|
|
||||||
import li.strolch.runtime.configuration.RuntimeConfiguration;
|
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Robert von Burg <eitch@eitchnet.ch>
|
|
||||||
*/
|
|
||||||
public abstract class AbstractService<T extends ServiceArgument, U extends ServiceResult> implements Service<T, U> {
|
|
||||||
|
|
||||||
protected static final Logger logger = LoggerFactory.getLogger(AbstractService.class);
|
|
||||||
private static final long serialVersionUID = 1L;
|
|
||||||
|
|
||||||
private DefaultServiceHandler serviceHandler;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param serviceHandler
|
|
||||||
* the serviceHandler to set
|
|
||||||
*/
|
|
||||||
public void setServiceHandler(DefaultServiceHandler serviceHandler) {
|
|
||||||
this.serviceHandler = serviceHandler;
|
|
||||||
}
|
|
||||||
|
|
||||||
public <V> V getComponent(Class<V> clazz) {
|
|
||||||
return this.serviceHandler.getComponent(clazz);
|
|
||||||
}
|
|
||||||
|
|
||||||
public RuntimeConfiguration getRuntimeConfiguration() {
|
|
||||||
return this.serviceHandler.getRuntimeConfiguration();
|
|
||||||
}
|
|
||||||
|
|
||||||
public ResourceMap getResourceMap(String realm) {
|
|
||||||
return this.serviceHandler.getResourceMap(realm);
|
|
||||||
}
|
|
||||||
|
|
||||||
public OrderMap getOrderMap(String realm) {
|
|
||||||
return this.serviceHandler.getOrderMap(realm);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public final U doService(T argument) {
|
|
||||||
|
|
||||||
if (isArgumentRequired() && argument == null) {
|
|
||||||
|
|
||||||
String msg = "Failed to perform service {0} because no argument was passed although it is required!"; //$NON-NLS-1$
|
|
||||||
msg = MessageFormat.format(msg, getClass());
|
|
||||||
logger.error(msg);
|
|
||||||
|
|
||||||
U result = getResultInstance();
|
|
||||||
result.setState(ServiceResultState.FAILED);
|
|
||||||
result.setMessage(msg);
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
|
|
||||||
U serviceResult = internalDoService(argument);
|
|
||||||
if (serviceResult == null) {
|
|
||||||
String msg = "Service {0} is not properly implemented as it returned a null result!"; //$NON-NLS-1$
|
|
||||||
msg = MessageFormat.format(msg, this.getClass().getName());
|
|
||||||
throw new StrolchException(msg);
|
|
||||||
}
|
|
||||||
|
|
||||||
return serviceResult;
|
|
||||||
|
|
||||||
} catch (Exception e) {
|
|
||||||
|
|
||||||
String msg = "Failed to perform service {0} due to {1}"; //$NON-NLS-1$
|
|
||||||
msg = MessageFormat.format(msg, getClass(), e.getMessage());
|
|
||||||
logger.error(msg, e);
|
|
||||||
|
|
||||||
U result = getResultInstance();
|
|
||||||
result.setState(ServiceResultState.FAILED);
|
|
||||||
result.setMessage(msg);
|
|
||||||
result.setThrowable(e);
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return if true, then an argument must be set to execute the service. If the argument is missing, then the
|
|
||||||
* service execution fails immediately
|
|
||||||
*/
|
|
||||||
protected boolean isArgumentRequired() {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This method is called if the service execution fails and an instance of the expected {@link ServiceResult} is
|
|
||||||
* required to return to the caller
|
|
||||||
*
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
protected abstract U getResultInstance();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Internal method to perform the {@link Service}. The implementor does not need to handle exceptions as this is
|
|
||||||
* done in the {@link #doService(ServiceArgument)} which calls this method
|
|
||||||
*
|
|
||||||
* @param arg
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
protected abstract U internalDoService(T arg);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @see ch.eitchnet.privilege.model.Restrictable#getPrivilegeName()
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public String getPrivilegeName() {
|
|
||||||
return Service.class.getName();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @see ch.eitchnet.privilege.model.Restrictable#getPrivilegeValue()
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public Object getPrivilegeValue() {
|
|
||||||
return this.getClass().getName();
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -13,16 +13,16 @@
|
||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
package li.strolch.service.model;
|
package li.strolch.service;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import li.strolch.model.Order;
|
import li.strolch.model.Order;
|
||||||
import li.strolch.persistence.api.StrolchTransaction;
|
import li.strolch.persistence.api.StrolchTransaction;
|
||||||
import li.strolch.runtime.agent.api.OrderMap;
|
import li.strolch.runtime.agent.api.OrderMap;
|
||||||
import li.strolch.service.AbstractService;
|
import li.strolch.service.api.AbstractService;
|
||||||
import li.strolch.service.ServiceArgument;
|
import li.strolch.service.api.ServiceArgument;
|
||||||
import li.strolch.service.ServiceResult;
|
import li.strolch.service.api.ServiceResult;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Robert von Burg <eitch@eitchnet.ch>
|
* @author Robert von Burg <eitch@eitchnet.ch>
|
|
@ -13,14 +13,14 @@
|
||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
package li.strolch.service.model;
|
package li.strolch.service;
|
||||||
|
|
||||||
import li.strolch.model.Order;
|
import li.strolch.model.Order;
|
||||||
import li.strolch.persistence.api.StrolchTransaction;
|
import li.strolch.persistence.api.StrolchTransaction;
|
||||||
import li.strolch.runtime.agent.api.OrderMap;
|
import li.strolch.runtime.agent.api.OrderMap;
|
||||||
import li.strolch.service.AbstractService;
|
import li.strolch.service.api.AbstractService;
|
||||||
import li.strolch.service.ServiceArgument;
|
import li.strolch.service.api.ServiceArgument;
|
||||||
import li.strolch.service.ServiceResult;
|
import li.strolch.service.api.ServiceResult;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Robert von Burg <eitch@eitchnet.ch>
|
* @author Robert von Burg <eitch@eitchnet.ch>
|
|
@ -13,16 +13,16 @@
|
||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
package li.strolch.service.model;
|
package li.strolch.service;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import li.strolch.model.Resource;
|
import li.strolch.model.Resource;
|
||||||
import li.strolch.persistence.api.StrolchTransaction;
|
import li.strolch.persistence.api.StrolchTransaction;
|
||||||
import li.strolch.runtime.agent.api.ResourceMap;
|
import li.strolch.runtime.agent.api.ResourceMap;
|
||||||
import li.strolch.service.AbstractService;
|
import li.strolch.service.api.AbstractService;
|
||||||
import li.strolch.service.ServiceArgument;
|
import li.strolch.service.api.ServiceArgument;
|
||||||
import li.strolch.service.ServiceResult;
|
import li.strolch.service.api.ServiceResult;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Robert von Burg <eitch@eitchnet.ch>
|
* @author Robert von Burg <eitch@eitchnet.ch>
|
|
@ -13,14 +13,14 @@
|
||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
package li.strolch.service.model;
|
package li.strolch.service;
|
||||||
|
|
||||||
import li.strolch.model.Resource;
|
import li.strolch.model.Resource;
|
||||||
import li.strolch.persistence.api.StrolchTransaction;
|
import li.strolch.persistence.api.StrolchTransaction;
|
||||||
import li.strolch.runtime.agent.api.ResourceMap;
|
import li.strolch.runtime.agent.api.ResourceMap;
|
||||||
import li.strolch.service.AbstractService;
|
import li.strolch.service.api.AbstractService;
|
||||||
import li.strolch.service.ServiceArgument;
|
import li.strolch.service.api.ServiceArgument;
|
||||||
import li.strolch.service.ServiceResult;
|
import li.strolch.service.api.ServiceResult;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Robert von Burg <eitch@eitchnet.ch>
|
* @author Robert von Burg <eitch@eitchnet.ch>
|
|
@ -1,127 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright 2013 Robert von Burg <eitch@eitchnet.ch>
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
package li.strolch.service;
|
|
||||||
|
|
||||||
import java.text.MessageFormat;
|
|
||||||
|
|
||||||
import li.strolch.exception.StrolchException;
|
|
||||||
import li.strolch.runtime.agent.api.OrderMap;
|
|
||||||
import li.strolch.runtime.agent.api.ResourceMap;
|
|
||||||
import li.strolch.runtime.agent.api.StrolchComponent;
|
|
||||||
import li.strolch.runtime.agent.impl.ComponentContainerImpl;
|
|
||||||
import li.strolch.runtime.configuration.ComponentConfiguration;
|
|
||||||
import li.strolch.runtime.configuration.RuntimeConfiguration;
|
|
||||||
import li.strolch.runtime.privilege.StrolchPrivilegeHandler;
|
|
||||||
import ch.eitchnet.privilege.model.Certificate;
|
|
||||||
import ch.eitchnet.privilege.model.PrivilegeContext;
|
|
||||||
import ch.eitchnet.utils.helper.StringHelper;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Robert von Burg <eitch@eitchnet.ch>
|
|
||||||
*/
|
|
||||||
public class DefaultServiceHandler extends StrolchComponent implements ServiceHandler {
|
|
||||||
|
|
||||||
private RuntimeConfiguration runtimeConfiguration;
|
|
||||||
private StrolchPrivilegeHandler privilegeHandler;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param container
|
|
||||||
* @param componentName
|
|
||||||
*/
|
|
||||||
public DefaultServiceHandler(ComponentContainerImpl container, String componentName) {
|
|
||||||
super(container, componentName);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void initialize(ComponentConfiguration configuration) {
|
|
||||||
if (getContainer().hasComponent(StrolchPrivilegeHandler.class))
|
|
||||||
this.privilegeHandler = getContainer().getComponent(StrolchPrivilegeHandler.class);
|
|
||||||
this.runtimeConfiguration = configuration.getRuntimeConfiguration();
|
|
||||||
super.initialize(configuration);
|
|
||||||
}
|
|
||||||
|
|
||||||
public <T> T getComponent(Class<T> clazz) {
|
|
||||||
return getContainer().getComponent(clazz);
|
|
||||||
}
|
|
||||||
|
|
||||||
public RuntimeConfiguration getRuntimeConfiguration() {
|
|
||||||
return this.runtimeConfiguration;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ResourceMap getResourceMap(String realm) {
|
|
||||||
return this.getContainer().getResourceMap(realm);
|
|
||||||
}
|
|
||||||
|
|
||||||
public OrderMap getOrderMap(String realm) {
|
|
||||||
return this.getContainer().getOrderMap(realm);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public <U extends ServiceResult> U doService(Certificate certificate, Service<ServiceArgument, U> service) {
|
|
||||||
return doService(certificate, service, null);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public <T extends ServiceArgument, U extends ServiceResult> U doService(Certificate certificate,
|
|
||||||
Service<T, U> service, T argument) {
|
|
||||||
|
|
||||||
long start = System.nanoTime();
|
|
||||||
|
|
||||||
// first check that the caller may perform this service
|
|
||||||
if (this.privilegeHandler != null) {
|
|
||||||
// XXX Bad bad bad: remove the need for thread locals...
|
|
||||||
try {
|
|
||||||
PrivilegeContext privilegeContext = this.privilegeHandler.getPrivilegeContext(certificate);
|
|
||||||
PrivilegeContext.set(privilegeContext);
|
|
||||||
privilegeContext.validateAction(service);
|
|
||||||
} finally {
|
|
||||||
PrivilegeContext.set(null);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
// then perform the service
|
|
||||||
if (service instanceof AbstractService)
|
|
||||||
((AbstractService<?, ?>) service).setServiceHandler(this);
|
|
||||||
U serviceResult = service.doService(argument);
|
|
||||||
if (serviceResult == null) {
|
|
||||||
String msg = "Service {0} is not properly implemented as it returned a null result!"; //$NON-NLS-1$
|
|
||||||
msg = MessageFormat.format(msg, service);
|
|
||||||
throw new StrolchException(msg);
|
|
||||||
}
|
|
||||||
|
|
||||||
// log the result
|
|
||||||
long end = System.nanoTime();
|
|
||||||
String msg = "Service {0} took {1}"; //$NON-NLS-1$
|
|
||||||
msg = MessageFormat.format(msg, service, StringHelper.formatNanoDuration(end - start));
|
|
||||||
if (serviceResult.getState() == ServiceResultState.SUCCESS)
|
|
||||||
logger.info(msg);
|
|
||||||
else if (serviceResult.getState() == ServiceResultState.WARNING)
|
|
||||||
logger.warn(msg);
|
|
||||||
else if (serviceResult.getState() == ServiceResultState.FAILED)
|
|
||||||
logger.error(msg);
|
|
||||||
|
|
||||||
return serviceResult;
|
|
||||||
|
|
||||||
} catch (Exception e) {
|
|
||||||
long end = System.nanoTime();
|
|
||||||
String msg = "Failed to perform service {0} after {1} due to {2}"; //$NON-NLS-1$
|
|
||||||
msg = MessageFormat.format(msg, service, StringHelper.formatNanoDuration(end - start), e.getMessage());
|
|
||||||
logger.error(msg, e);
|
|
||||||
throw new StrolchException(msg, e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -13,7 +13,7 @@
|
||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
package li.strolch.service.model;
|
package li.strolch.service;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.text.MessageFormat;
|
import java.text.MessageFormat;
|
||||||
|
@ -25,9 +25,9 @@ import li.strolch.persistence.api.StrolchTransaction;
|
||||||
import li.strolch.runtime.agent.api.OrderMap;
|
import li.strolch.runtime.agent.api.OrderMap;
|
||||||
import li.strolch.runtime.agent.api.ResourceMap;
|
import li.strolch.runtime.agent.api.ResourceMap;
|
||||||
import li.strolch.runtime.agent.impl.InMemoryElementListener;
|
import li.strolch.runtime.agent.impl.InMemoryElementListener;
|
||||||
import li.strolch.service.AbstractService;
|
import li.strolch.service.api.AbstractService;
|
||||||
import li.strolch.service.ServiceArgument;
|
import li.strolch.service.api.ServiceArgument;
|
||||||
import li.strolch.service.ServiceResult;
|
import li.strolch.service.api.ServiceResult;
|
||||||
import ch.eitchnet.utils.helper.StringHelper;
|
import ch.eitchnet.utils.helper.StringHelper;
|
||||||
|
|
||||||
/**
|
/**
|
|
@ -1,28 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright 2013 Robert von Burg <eitch@eitchnet.ch>
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
package li.strolch.service;
|
|
||||||
|
|
||||||
import java.io.Serializable;
|
|
||||||
|
|
||||||
import ch.eitchnet.privilege.model.Restrictable;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Robert von Burg <eitch@eitchnet.ch>
|
|
||||||
*/
|
|
||||||
public interface Service<T extends ServiceArgument, U extends ServiceResult> extends Serializable, Restrictable {
|
|
||||||
|
|
||||||
public U doService(T argument);
|
|
||||||
}
|
|
|
@ -1,42 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright 2013 Robert von Burg <eitch@eitchnet.ch>
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
package li.strolch.service;
|
|
||||||
|
|
||||||
import java.io.Serializable;
|
|
||||||
|
|
||||||
import li.strolch.runtime.StrolchConstants;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Base argument to be used when performing {@link Service Services}. The realm parameter is set to
|
|
||||||
* {@link StrolchConstants#DEFAULT_REALM} and can be overridden when the caller of the service wants to perform the
|
|
||||||
* service in a different realm
|
|
||||||
*
|
|
||||||
* @author Robert von Burg <eitch@eitchnet.ch>
|
|
||||||
*/
|
|
||||||
public class ServiceArgument implements Serializable {
|
|
||||||
private static final long serialVersionUID = 1L;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* <p>
|
|
||||||
* Set this to the realm in which the service should operate
|
|
||||||
* </p>
|
|
||||||
*
|
|
||||||
* <p>
|
|
||||||
* realm = StrolchConstants.DEFAULT_REALM
|
|
||||||
* </p>
|
|
||||||
*/
|
|
||||||
public String realm = StrolchConstants.DEFAULT_REALM;
|
|
||||||
}
|
|
|
@ -1,26 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright 2013 Robert von Burg <eitch@eitchnet.ch>
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
package li.strolch.service;
|
|
||||||
|
|
||||||
import ch.eitchnet.privilege.model.Certificate;
|
|
||||||
|
|
||||||
public interface ServiceHandler {
|
|
||||||
|
|
||||||
public <T extends ServiceArgument, U extends ServiceResult> U doService(Certificate certificate,
|
|
||||||
Service<T, U> service, T argument);
|
|
||||||
|
|
||||||
public <U extends ServiceResult> U doService(Certificate certificate, Service<ServiceArgument, U> service);
|
|
||||||
}
|
|
|
@ -1,122 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright 2013 Robert von Burg <eitch@eitchnet.ch>
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
package li.strolch.service;
|
|
||||||
|
|
||||||
import java.io.Serializable;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Robert von Burg <eitch@eitchnet.ch>
|
|
||||||
*/
|
|
||||||
public class ServiceResult implements Serializable {
|
|
||||||
private static final long serialVersionUID = 1L;
|
|
||||||
private ServiceResultState state;
|
|
||||||
private String message;
|
|
||||||
private Throwable throwable;
|
|
||||||
|
|
||||||
public ServiceResult() {
|
|
||||||
//
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param state
|
|
||||||
*/
|
|
||||||
public ServiceResult(ServiceResultState state) {
|
|
||||||
this.state = state;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param state
|
|
||||||
* @param message
|
|
||||||
* @param throwable
|
|
||||||
*/
|
|
||||||
public ServiceResult(ServiceResultState state, String message, Throwable throwable) {
|
|
||||||
this.state = state;
|
|
||||||
this.message = message;
|
|
||||||
this.throwable = throwable;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return true if the state is {@link ServiceResultState#SUCCESS}
|
|
||||||
*/
|
|
||||||
public boolean isOk() {
|
|
||||||
return this.state == ServiceResultState.SUCCESS;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return the state
|
|
||||||
*/
|
|
||||||
public ServiceResultState getState() {
|
|
||||||
return this.state;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param state
|
|
||||||
* the state to set
|
|
||||||
*/
|
|
||||||
public void setState(ServiceResultState state) {
|
|
||||||
this.state = state;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return the message
|
|
||||||
*/
|
|
||||||
public String getMessage() {
|
|
||||||
return this.message;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param message
|
|
||||||
* the message to set
|
|
||||||
*/
|
|
||||||
public void setMessage(String message) {
|
|
||||||
this.message = message;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return the throwable
|
|
||||||
*/
|
|
||||||
public Throwable getThrowable() {
|
|
||||||
return this.throwable;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param throwable
|
|
||||||
* the throwable to set
|
|
||||||
*/
|
|
||||||
public void setThrowable(Throwable throwable) {
|
|
||||||
this.throwable = throwable;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static ServiceResult success() {
|
|
||||||
return new ServiceResult(ServiceResultState.SUCCESS, null, null);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static ServiceResult success(String msg) {
|
|
||||||
return new ServiceResult(ServiceResultState.SUCCESS, msg, null);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static ServiceResult warning(String warning) {
|
|
||||||
return new ServiceResult(ServiceResultState.WARNING, warning, null);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static ServiceResult warning(String warning, Throwable t) {
|
|
||||||
return new ServiceResult(ServiceResultState.WARNING, warning, t);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static ServiceResult failed(String error, Throwable t) {
|
|
||||||
return new ServiceResult(ServiceResultState.FAILED, error, t);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,25 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright 2013 Robert von Burg <eitch@eitchnet.ch>
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
package li.strolch.service;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Robert von Burg <eitch@eitchnet.ch>
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public enum ServiceResultState {
|
|
||||||
|
|
||||||
SUCCESS, WARNING, FAILED;
|
|
||||||
}
|
|
|
@ -17,7 +17,7 @@ package li.strolch.service.test;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
|
||||||
import li.strolch.service.ServiceHandler;
|
import li.strolch.service.api.ServiceHandler;
|
||||||
import li.strolch.testbase.runtime.RuntimeMock;
|
import li.strolch.testbase.runtime.RuntimeMock;
|
||||||
|
|
||||||
import org.junit.AfterClass;
|
import org.junit.AfterClass;
|
||||||
|
|
|
@ -15,8 +15,8 @@
|
||||||
*/
|
*/
|
||||||
package li.strolch.service.test;
|
package li.strolch.service.test;
|
||||||
|
|
||||||
import li.strolch.service.ServiceResult;
|
import li.strolch.service.api.ServiceResult;
|
||||||
import li.strolch.service.ServiceResultState;
|
import li.strolch.service.api.ServiceResultState;
|
||||||
|
|
||||||
public class GreetingResult extends ServiceResult {
|
public class GreetingResult extends ServiceResult {
|
||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
|
@ -17,8 +17,8 @@ package li.strolch.service.test;
|
||||||
|
|
||||||
import java.text.MessageFormat;
|
import java.text.MessageFormat;
|
||||||
|
|
||||||
import li.strolch.service.AbstractService;
|
import li.strolch.service.api.AbstractService;
|
||||||
import li.strolch.service.ServiceArgument;
|
import li.strolch.service.api.ServiceArgument;
|
||||||
import li.strolch.service.test.GreetingService.GreetingArgument;
|
import li.strolch.service.test.GreetingService.GreetingArgument;
|
||||||
import ch.eitchnet.utils.helper.StringHelper;
|
import ch.eitchnet.utils.helper.StringHelper;
|
||||||
|
|
||||||
|
|
|
@ -20,7 +20,7 @@ import static org.junit.Assert.assertThat;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
|
||||||
import li.strolch.service.ServiceHandler;
|
import li.strolch.service.api.ServiceHandler;
|
||||||
import li.strolch.service.test.GreetingService.GreetingArgument;
|
import li.strolch.service.test.GreetingService.GreetingArgument;
|
||||||
import li.strolch.testbase.runtime.RuntimeMock;
|
import li.strolch.testbase.runtime.RuntimeMock;
|
||||||
|
|
||||||
|
|
|
@ -60,7 +60,7 @@ public class ServiceTest extends AbstractServiceTest {
|
||||||
@Test
|
@Test
|
||||||
public void shouldFailWithNoAccess() {
|
public void shouldFailWithNoAccess() {
|
||||||
this.thrown.expect(AccessDeniedException.class);
|
this.thrown.expect(AccessDeniedException.class);
|
||||||
this.thrown.expectMessage("User jill does not have Privilege li.strolch.service.Service"); //$NON-NLS-1$
|
this.thrown.expectMessage("User jill does not have Privilege li.strolch.service.api.Service"); //$NON-NLS-1$
|
||||||
|
|
||||||
Certificate certificate = runtimeMock.getPrivilegeHandler().authenticate("jill", "jill".getBytes()); //$NON-NLS-1$//$NON-NLS-2$
|
Certificate certificate = runtimeMock.getPrivilegeHandler().authenticate("jill", "jill".getBytes()); //$NON-NLS-1$//$NON-NLS-2$
|
||||||
try {
|
try {
|
||||||
|
|
|
@ -15,9 +15,9 @@
|
||||||
*/
|
*/
|
||||||
package li.strolch.service.test;
|
package li.strolch.service.test;
|
||||||
|
|
||||||
import li.strolch.service.AbstractService;
|
import li.strolch.service.api.AbstractService;
|
||||||
import li.strolch.service.ServiceArgument;
|
import li.strolch.service.api.ServiceArgument;
|
||||||
import li.strolch.service.ServiceResult;
|
import li.strolch.service.api.ServiceResult;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Robert von Burg <eitch@eitchnet.ch>
|
* @author Robert von Burg <eitch@eitchnet.ch>
|
||||||
|
|
|
@ -56,7 +56,7 @@
|
||||||
<Role name="PrivilegeAdmin" />
|
<Role name="PrivilegeAdmin" />
|
||||||
|
|
||||||
<Role name="AppUser">
|
<Role name="AppUser">
|
||||||
<Privilege name="li.strolch.service.Service" policy="DefaultPrivilege">
|
<Privilege name="li.strolch.service.api.Service" policy="DefaultPrivilege">
|
||||||
<AllAllowed>true</AllAllowed>
|
<AllAllowed>true</AllAllowed>
|
||||||
</Privilege>
|
</Privilege>
|
||||||
</Role>
|
</Role>
|
||||||
|
@ -65,7 +65,7 @@
|
||||||
</Role>
|
</Role>
|
||||||
|
|
||||||
<Role name="OnlyGreetingServiceRole">
|
<Role name="OnlyGreetingServiceRole">
|
||||||
<Privilege name="li.strolch.service.Service" policy="DefaultPrivilege">
|
<Privilege name="li.strolch.service.api.Service" policy="DefaultPrivilege">
|
||||||
<Allow>li.strolch.service.test.GreetingService</Allow>
|
<Allow>li.strolch.service.test.GreetingService</Allow>
|
||||||
</Privilege>
|
</Privilege>
|
||||||
</Role>
|
</Role>
|
||||||
|
|
|
@ -9,8 +9,8 @@
|
||||||
</Runtime>
|
</Runtime>
|
||||||
<Component>
|
<Component>
|
||||||
<name>ServiceHandler</name>
|
<name>ServiceHandler</name>
|
||||||
<api>li.strolch.service.ServiceHandler</api>
|
<api>li.strolch.service.api.ServiceHandler</api>
|
||||||
<impl>li.strolch.service.DefaultServiceHandler</impl>
|
<impl>li.strolch.service.api.DefaultServiceHandler</impl>
|
||||||
<Properties>
|
<Properties>
|
||||||
<verbose>true</verbose>
|
<verbose>true</verbose>
|
||||||
</Properties>
|
</Properties>
|
||||||
|
|
|
@ -9,8 +9,8 @@
|
||||||
</Runtime>
|
</Runtime>
|
||||||
<Component>
|
<Component>
|
||||||
<name>ServiceHandler</name>
|
<name>ServiceHandler</name>
|
||||||
<api>li.strolch.service.ServiceHandler</api>
|
<api>li.strolch.service.api.ServiceHandler</api>
|
||||||
<impl>li.strolch.service.DefaultServiceHandler</impl>
|
<impl>li.strolch.service.api.DefaultServiceHandler</impl>
|
||||||
<Properties>
|
<Properties>
|
||||||
<verbose>true</verbose>
|
<verbose>true</verbose>
|
||||||
</Properties>
|
</Properties>
|
||||||
|
|
Loading…
Reference in New Issue