Merge branch 'master' of ../service

This commit is contained in:
Robert von Burg 2014-09-16 09:03:47 +02:00
commit 0495fe0bf9
106 changed files with 6771 additions and 0 deletions

4
li.strolch.service/.gitignore vendored Normal file
View File

@ -0,0 +1,4 @@
target/
.project
.settings
.classpath

202
li.strolch.service/LICENSE Normal file
View File

@ -0,0 +1,202 @@
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.
"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:
(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.
You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS
APPENDIX: How to apply the Apache License to your work.
To apply the Apache License to your work, attach the following
boilerplate notice, with the fields enclosed by brackets "[]"
replaced with your own identifying information. (Don't include
the brackets!) The text should be enclosed in the appropriate
comment syntax for the file format. We also recommend that a
file or class name and description of purpose be included on the
same "printed page" as the copyright notice for easier
identification within third-party archives.
Copyright [yyyy] [name of copyright owner]
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.

View File

@ -0,0 +1,28 @@
li.strolch.service
==================
[![Build Status](http://jenkins.eitchnet.ch/buildStatus/icon?job=li.strolch.service)](http://jenkins.eitchnet.ch/view/strolch/job/li.strolch.service/)
Service API for Strolch
Running tests
==================
* Install PostgreSQL and create the following users:
create user cacheduser with password 'test';
create database cacheduserdb;
GRANT ALL PRIVILEGES ON DATABASE cacheduserdb to cacheduser;
GRANT CONNECT ON DATABASE cacheduserdb TO cacheduser;
create user transactionaluser with password 'test';
create database transactionaluserdb;
GRANT ALL PRIVILEGES ON DATABASE transactionaluserdb to transactionaluser;
GRANT CONNECT ON DATABASE transactionaluserdb TO transactionaluser;
# You can revoke the privileges with the following:
revoke ALL PRIVILEGES ON DATABASE cacheduserdb from cacheduser;
drop user cacheduser;
drop database cacheduserdb;
revoke ALL PRIVILEGES ON DATABASE transactionaluserdb from transactionaluser;
drop user transactionaluser;
drop database transactionaluserdb;

107
li.strolch.service/pom.xml Normal file
View File

@ -0,0 +1,107 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>li.strolch</groupId>
<artifactId>li.strolch.parent</artifactId>
<version>1.0.0-SNAPSHOT</version>
<relativePath>../li.strolch.parent/pom.xml</relativePath>
</parent>
<artifactId>li.strolch.service</artifactId>
<name>li.strolch.service</name>
<description>Service API for Strolch</description>
<url>https://github.com/eitchnet/li.strolch.service</url>
<inceptionYear>2011</inceptionYear>
<issueManagement>
<system>Github Issues</system>
<url>https://github.com/eitchnet/li.strolch.service/issues</url>
</issueManagement>
<scm>
<connection>scm:git:https://github.com/eitchnet/li.strolch.service.git</connection>
<developerConnection>scm:git:git@github.com:eitch/li.strolch.service.git</developerConnection>
<url>https://github.com/eitchnet/li.strolch.service</url>
</scm>
<dependencies>
<!-- main -->
<dependency>
<groupId>li.strolch</groupId>
<artifactId>li.strolch.model</artifactId>
</dependency>
<dependency>
<groupId>li.strolch</groupId>
<artifactId>li.strolch.agent</artifactId>
</dependency>
<dependency>
<groupId>ch.eitchnet</groupId>
<artifactId>ch.eitchnet.xmlpers</artifactId>
</dependency>
<dependency>
<groupId>ch.eitchnet</groupId>
<artifactId>ch.eitchnet.privilege</artifactId>
</dependency>
<!-- test -->
<dependency>
<groupId>li.strolch</groupId>
<artifactId>li.strolch.testbase</artifactId>
</dependency>
<dependency>
<groupId>li.strolch</groupId>
<artifactId>li.strolch.persistence.postgresql</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
<includes>
<include>**/componentVersion.properties</include>
</includes>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>buildnumber-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-eclipse-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-site-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>

View File

@ -0,0 +1,85 @@
/*
* 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 java.text.MessageFormat;
import java.util.List;
import li.strolch.agent.api.ComponentContainer;
import li.strolch.agent.api.OrderMap;
import li.strolch.exception.StrolchException;
import li.strolch.model.Order;
import li.strolch.persistence.api.StrolchTransaction;
import li.strolch.service.api.Command;
import ch.eitchnet.utils.dbc.DBC;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*/
public class AddOrderCollectionCommand extends Command {
private List<Order> orders;
/**
* @param tx
*/
public AddOrderCollectionCommand(ComponentContainer container, StrolchTransaction tx) {
super(container, tx);
}
/**
* @param orders
* the orders to set
*/
public void setOrders(List<Order> orders) {
this.orders = orders;
}
@Override
public void validate() {
DBC.PRE.assertNotNull("Order list may not be null!", this.orders);
}
@Override
public void doCommand() {
for (Order order : this.orders) {
tx().lock(order);
}
OrderMap orderMap = tx().getOrderMap();
for (Order order : this.orders) {
if (orderMap.hasElement(tx(), order.getType(), order.getId())) {
String msg = MessageFormat.format("The Order {0} already exists!", order.getLocator());
throw new StrolchException(msg);
}
}
orderMap.addAll(tx(), this.orders);
}
@Override
public void undo() {
if (this.orders != null && !this.orders.isEmpty() && tx().isRollingBack()) {
OrderMap orderMap = tx().getOrderMap();
for (Order order : this.orders) {
if (orderMap.hasElement(tx(), order.getType(), order.getId())) {
orderMap.remove(tx(), order);
}
}
}
}
}

View File

@ -0,0 +1,77 @@
/*
* 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 java.text.MessageFormat;
import li.strolch.agent.api.ComponentContainer;
import li.strolch.agent.api.OrderMap;
import li.strolch.exception.StrolchException;
import li.strolch.model.Order;
import li.strolch.persistence.api.StrolchTransaction;
import li.strolch.service.api.Command;
import ch.eitchnet.utils.dbc.DBC;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*/
public class AddOrderCommand extends Command {
private Order order;
/**
* @param tx
*/
public AddOrderCommand(ComponentContainer container, StrolchTransaction tx) {
super(container, tx);
}
/**
* @param order
* the order to set
*/
public void setOrder(Order order) {
this.order = order;
}
@Override
public void validate() {
DBC.PRE.assertNotNull("Order may not be null!", this.order);
}
@Override
public void doCommand() {
tx().lock(this.order);
OrderMap orderMap = tx().getOrderMap();
if (orderMap.hasElement(tx(), this.order.getType(), this.order.getId())) {
String msg = MessageFormat.format("The Order {0} already exists!", this.order.getLocator());
throw new StrolchException(msg);
}
orderMap.add(tx(), this.order);
}
@Override
public void undo() {
if (this.order != null && tx().isRollingBack()) {
OrderMap orderMap = tx().getOrderMap();
if (orderMap.hasElement(tx(), this.order.getType(), this.order.getId()))
orderMap.remove(tx(), this.order);
}
}
}

View File

@ -0,0 +1,85 @@
/*
* 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 java.text.MessageFormat;
import java.util.List;
import li.strolch.agent.api.ComponentContainer;
import li.strolch.agent.api.ResourceMap;
import li.strolch.exception.StrolchException;
import li.strolch.model.Resource;
import li.strolch.persistence.api.StrolchTransaction;
import li.strolch.service.api.Command;
import ch.eitchnet.utils.dbc.DBC;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*/
public class AddResourceCollectionCommand extends Command {
private List<Resource> resources;
/**
* @param tx
*/
public AddResourceCollectionCommand(ComponentContainer container, StrolchTransaction tx) {
super(container, tx);
}
/**
* @param resources
* the resources to set
*/
public void setResources(List<Resource> resources) {
this.resources = resources;
}
@Override
public void validate() {
DBC.PRE.assertNotNull("Resource list may not be null!", this.resources);
}
@Override
public void doCommand() {
for (Resource resource : this.resources) {
tx().lock(resource);
}
ResourceMap resourceMap = tx().getResourceMap();
for (Resource resource : this.resources) {
if (resourceMap.hasElement(tx(), resource.getType(), resource.getId())) {
String msg = MessageFormat.format("The Resource {0} already exists!", resource.getLocator());
throw new StrolchException(msg);
}
}
resourceMap.addAll(tx(), this.resources);
}
@Override
public void undo() {
if (this.resources != null && !this.resources.isEmpty() && tx().isRollingBack()) {
ResourceMap resourceMap = tx().getResourceMap();
for (Resource resource : this.resources) {
if (resourceMap.hasElement(tx(), resource.getType(), resource.getId())) {
resourceMap.remove(tx(), resource);
}
}
}
}
}

View File

@ -0,0 +1,77 @@
/*
* 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 java.text.MessageFormat;
import li.strolch.agent.api.ComponentContainer;
import li.strolch.agent.api.ResourceMap;
import li.strolch.exception.StrolchException;
import li.strolch.model.Resource;
import li.strolch.persistence.api.StrolchTransaction;
import li.strolch.service.api.Command;
import ch.eitchnet.utils.dbc.DBC;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*/
public class AddResourceCommand extends Command {
private Resource resource;
/**
* @param tx
*/
public AddResourceCommand(ComponentContainer container, StrolchTransaction tx) {
super(container, tx);
}
/**
* @param resource
* the resource to set
*/
public void setResource(Resource resource) {
this.resource = resource;
}
@Override
public void validate() {
DBC.PRE.assertNotNull("Resource may not be null!", this.resource);
}
@Override
public void doCommand() {
tx().lock(this.resource);
ResourceMap resourceMap = tx().getResourceMap();
if (resourceMap.hasElement(tx(), this.resource.getType(), this.resource.getId())) {
String msg = MessageFormat.format("The Resource {0} already exists!", this.resource.getLocator());
throw new StrolchException(msg);
}
resourceMap.add(tx(), this.resource);
}
@Override
public void undo() {
if (this.resource != null && tx().isRollingBack()) {
ResourceMap resourceMap = tx().getResourceMap();
if (resourceMap.hasElement(tx(), this.resource.getType(), this.resource.getId()))
resourceMap.remove(tx(), this.resource);
}
}
}

View File

@ -0,0 +1,95 @@
/*
* 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.agent.api.ComponentContainer;
import li.strolch.agent.api.OrderMap;
import li.strolch.agent.api.ResourceMap;
import li.strolch.model.ModelStatistics;
import li.strolch.persistence.api.StrolchTransaction;
import li.strolch.service.api.Command;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*/
public class ClearModelCommand extends Command {
// input
private boolean clearOrders;
private boolean clearResources;
// output
private ModelStatistics statistics;
/**
* @param container
* @param tx
*/
public ClearModelCommand(ComponentContainer container, StrolchTransaction tx) {
super(container, tx);
}
@Override
public void validate() {
// nothing to do
}
@Override
public void doCommand() {
ModelStatistics statistics = new ModelStatistics();
if (this.clearOrders) {
OrderMap orderMap = tx().getOrderMap();
statistics.nrOfOrders = orderMap.removeAll(tx());
}
if (this.clearResources) {
ResourceMap resourceMap = tx().getResourceMap();
statistics.nrOfResources = resourceMap.removeAll(tx());
}
this.statistics = statistics;
}
@Override
public void undo() {
logger.warn("Can not undo clearing of model!");
}
/**
* @param clearOrders
* the clearOrders to set
*/
public void setClearOrders(boolean clearOrders) {
this.clearOrders = clearOrders;
}
/**
* @param clearResources
* the clearResources to set
*/
public void setClearResources(boolean clearResources) {
this.clearResources = clearResources;
}
/**
* @return the statistics
*/
public ModelStatistics getStatistics() {
return this.statistics;
}
}

View File

@ -0,0 +1,86 @@
/*
* 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 java.text.MessageFormat;
import java.util.List;
import li.strolch.agent.api.ComponentContainer;
import li.strolch.agent.api.OrderMap;
import li.strolch.exception.StrolchException;
import li.strolch.model.Order;
import li.strolch.persistence.api.StrolchTransaction;
import li.strolch.service.api.Command;
import ch.eitchnet.utils.dbc.DBC;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*/
public class RemoveOrderCollectionCommand extends Command {
private List<Order> orders;
/**
* @param tx
*/
public RemoveOrderCollectionCommand(ComponentContainer container, StrolchTransaction tx) {
super(container, tx);
}
/**
* @param orders
* the orders to set
*/
public void setOrders(List<Order> orders) {
this.orders = orders;
}
@Override
public void validate() {
DBC.PRE.assertNotNull("Order list may not be null!", this.orders);
}
@Override
public void doCommand() {
for (Order order : this.orders) {
tx().lock(order);
}
OrderMap orderMap = tx().getOrderMap();
for (Order order : this.orders) {
if (!orderMap.hasElement(tx(), order.getType(), order.getId())) {
String msg = "The Order {0} can not be removed as it does not exist!";
msg = MessageFormat.format(msg, order.getLocator());
throw new StrolchException(msg);
}
}
orderMap.removeAll(tx(), this.orders);
}
@Override
public void undo() {
if (this.orders != null && !this.orders.isEmpty() && tx().isRollingBack()) {
OrderMap orderMap = tx().getOrderMap();
for (Order order : this.orders) {
if (!orderMap.hasElement(tx(), order.getType(), order.getId())) {
orderMap.add(tx(), order);
}
}
}
}
}

View File

@ -0,0 +1,78 @@
/*
* 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 java.text.MessageFormat;
import li.strolch.agent.api.ComponentContainer;
import li.strolch.agent.api.OrderMap;
import li.strolch.exception.StrolchException;
import li.strolch.model.Order;
import li.strolch.persistence.api.StrolchTransaction;
import li.strolch.service.api.Command;
import ch.eitchnet.utils.dbc.DBC;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*/
public class RemoveOrderCommand extends Command {
private Order order;
/**
* @param tx
*/
public RemoveOrderCommand(ComponentContainer container, StrolchTransaction tx) {
super(container, tx);
}
/**
* @param order
* the order to set
*/
public void setOrder(Order order) {
this.order = order;
}
@Override
public void validate() {
DBC.PRE.assertNotNull("Order may not be null!", this.order);
}
@Override
public void doCommand() {
tx().lock(this.order);
OrderMap orderMap = tx().getOrderMap();
if (!orderMap.hasElement(tx(), this.order.getType(), this.order.getId())) {
String msg = "The Order {0} can not be removed as it does not exist!";
msg = MessageFormat.format(msg, this.order.getLocator());
throw new StrolchException(msg);
}
orderMap.remove(tx(), this.order);
}
@Override
public void undo() {
if (this.order != null && tx().isRollingBack()) {
OrderMap orderMap = tx().getOrderMap();
if (!orderMap.hasElement(tx(), this.order.getType(), this.order.getId()))
orderMap.add(tx(), this.order);
}
}
}

View File

@ -0,0 +1,86 @@
/*
* 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 java.text.MessageFormat;
import java.util.List;
import li.strolch.agent.api.ComponentContainer;
import li.strolch.agent.api.ResourceMap;
import li.strolch.exception.StrolchException;
import li.strolch.model.Resource;
import li.strolch.persistence.api.StrolchTransaction;
import li.strolch.service.api.Command;
import ch.eitchnet.utils.dbc.DBC;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*/
public class RemoveResourceCollectionCommand extends Command {
private List<Resource> resources;
/**
* @param tx
*/
public RemoveResourceCollectionCommand(ComponentContainer container, StrolchTransaction tx) {
super(container, tx);
}
/**
* @param resources
* the resources to set
*/
public void setResources(List<Resource> resources) {
this.resources = resources;
}
@Override
public void validate() {
DBC.PRE.assertNotNull("Resource list may not be null!", this.resources);
}
@Override
public void doCommand() {
for (Resource resource : this.resources) {
tx().lock(resource);
}
ResourceMap resourceMap = tx().getResourceMap();
for (Resource resource : this.resources) {
if (!resourceMap.hasElement(tx(), resource.getType(), resource.getId())) {
String msg = "The Resource {0} can not be removed as it does not exist!";
msg = MessageFormat.format(msg, resource.getLocator());
throw new StrolchException(msg);
}
}
resourceMap.removeAll(tx(), this.resources);
}
@Override
public void undo() {
if (this.resources != null && !this.resources.isEmpty() && tx().isRollingBack()) {
ResourceMap resourceMap = tx().getResourceMap();
for (Resource resource : this.resources) {
if (!resourceMap.hasElement(tx(), resource.getType(), resource.getId())) {
resourceMap.add(tx(), resource);
}
}
}
}
}

View File

@ -0,0 +1,78 @@
/*
* 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 java.text.MessageFormat;
import li.strolch.agent.api.ComponentContainer;
import li.strolch.agent.api.ResourceMap;
import li.strolch.exception.StrolchException;
import li.strolch.model.Resource;
import li.strolch.persistence.api.StrolchTransaction;
import li.strolch.service.api.Command;
import ch.eitchnet.utils.dbc.DBC;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*/
public class RemoveResourceCommand extends Command {
private Resource resource;
/**
* @param tx
*/
public RemoveResourceCommand(ComponentContainer container, StrolchTransaction tx) {
super(container, tx);
}
/**
* @param resource
* the resource to set
*/
public void setResource(Resource resource) {
this.resource = resource;
}
@Override
public void validate() {
DBC.PRE.assertNotNull("Resource may not be null!", this.resource);
}
@Override
public void doCommand() {
tx().lock(this.resource);
ResourceMap resourceMap = tx().getResourceMap();
if (!resourceMap.hasElement(tx(), this.resource.getType(), this.resource.getId())) {
String msg = "The Resource {0} can not be removed as it does not exist!!";
msg = MessageFormat.format(msg, this.resource.getLocator());
throw new StrolchException(msg);
}
resourceMap.remove(tx(), this.resource);
}
@Override
public void undo() {
if (this.resource != null && tx().isRollingBack()) {
ResourceMap resourceMap = tx().getResourceMap();
if (!resourceMap.hasElement(tx(), this.resource.getType(), this.resource.getId()))
resourceMap.add(tx(), this.resource);
}
}
}

View File

@ -0,0 +1,83 @@
/*
* 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 java.text.MessageFormat;
import java.util.List;
import li.strolch.agent.api.ComponentContainer;
import li.strolch.agent.api.OrderMap;
import li.strolch.exception.StrolchException;
import li.strolch.model.Order;
import li.strolch.persistence.api.StrolchTransaction;
import li.strolch.service.api.Command;
import ch.eitchnet.utils.dbc.DBC;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*/
public class UpdateOrderCollectionCommand extends Command {
private List<Order> orders;
private List<Order> replacedElements;
/**
* @param tx
*/
public UpdateOrderCollectionCommand(ComponentContainer container, StrolchTransaction tx) {
super(container, tx);
}
/**
* @param orders
* the orders to set
*/
public void setOrders(List<Order> orders) {
this.orders = orders;
}
@Override
public void validate() {
DBC.PRE.assertNotNull("Order list may not be null!", this.orders);
}
@Override
public void doCommand() {
for (Order order : this.orders) {
tx().lock(order);
}
OrderMap orderMap = tx().getOrderMap();
for (Order order : this.orders) {
if (!orderMap.hasElement(tx(), order.getType(), order.getId())) {
String msg = "The Order {0} can not be updated as it does not exist!";
msg = MessageFormat.format(msg, order.getLocator());
throw new StrolchException(msg);
}
}
this.replacedElements = orderMap.updateAll(tx(), this.orders);
}
@Override
public void undo() {
if (this.replacedElements != null && tx().isRollingBack()) {
OrderMap orderMap = tx().getOrderMap();
orderMap.updateAll(tx(), this.replacedElements);
}
}
}

View File

@ -0,0 +1,77 @@
/*
* 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 java.text.MessageFormat;
import li.strolch.agent.api.ComponentContainer;
import li.strolch.agent.api.OrderMap;
import li.strolch.exception.StrolchException;
import li.strolch.model.Order;
import li.strolch.persistence.api.StrolchTransaction;
import li.strolch.service.api.Command;
import ch.eitchnet.utils.dbc.DBC;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*/
public class UpdateOrderCommand extends Command {
private Order order;
private Order replacedElement;
/**
* @param tx
*/
public UpdateOrderCommand(ComponentContainer container, StrolchTransaction tx) {
super(container, tx);
}
/**
* @param order
* the order to set
*/
public void setOrder(Order order) {
this.order = order;
}
@Override
public void validate() {
DBC.PRE.assertNotNull("Order may not be null!", this.order);
}
@Override
public void doCommand() {
tx().lock(this.order);
OrderMap orderMap = tx().getOrderMap();
if (!orderMap.hasElement(tx(), this.order.getType(), this.order.getId())) {
String msg = "The Order {0} can not be updated as it does not exist!";
msg = MessageFormat.format(msg, this.order.getLocator());
throw new StrolchException(msg);
}
this.replacedElement = orderMap.update(tx(), this.order);
}
@Override
public void undo() {
if (this.replacedElement != null && tx().isRollingBack()) {
tx().getOrderMap().update(tx(), this.replacedElement);
}
}
}

View File

@ -0,0 +1,83 @@
/*
* 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 java.text.MessageFormat;
import java.util.List;
import li.strolch.agent.api.ComponentContainer;
import li.strolch.agent.api.ResourceMap;
import li.strolch.exception.StrolchException;
import li.strolch.model.Resource;
import li.strolch.persistence.api.StrolchTransaction;
import li.strolch.service.api.Command;
import ch.eitchnet.utils.dbc.DBC;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*/
public class UpdateResourceCollectionCommand extends Command {
private List<Resource> resources;
private List<Resource> replacedElements;
/**
* @param tx
*/
public UpdateResourceCollectionCommand(ComponentContainer container, StrolchTransaction tx) {
super(container, tx);
}
/**
* @param resources
* the resources to set
*/
public void setResources(List<Resource> resources) {
this.resources = resources;
}
@Override
public void validate() {
DBC.PRE.assertNotNull("Resource list may not be null!", this.resources);
}
@Override
public void doCommand() {
for (Resource resource : this.resources) {
tx().lock(resource);
}
ResourceMap resourceMap = tx().getResourceMap();
for (Resource resource : this.resources) {
if (!resourceMap.hasElement(tx(), resource.getType(), resource.getId())) {
String msg = "The Resource {0} can not be updated as it does not exist!";
msg = MessageFormat.format(msg, resource.getLocator());
throw new StrolchException(msg);
}
}
this.replacedElements = resourceMap.updateAll(tx(), this.resources);
}
@Override
public void undo() {
if (this.replacedElements != null && tx().isRollingBack()) {
ResourceMap resourceMap = tx().getResourceMap();
resourceMap.updateAll(tx(), this.replacedElements);
}
}
}

View File

@ -0,0 +1,77 @@
/*
* 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 java.text.MessageFormat;
import li.strolch.agent.api.ComponentContainer;
import li.strolch.agent.api.ResourceMap;
import li.strolch.exception.StrolchException;
import li.strolch.model.Resource;
import li.strolch.persistence.api.StrolchTransaction;
import li.strolch.service.api.Command;
import ch.eitchnet.utils.dbc.DBC;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*/
public class UpdateResourceCommand extends Command {
private Resource resource;
private Resource replacedElement;
/**
* @param tx
*/
public UpdateResourceCommand(ComponentContainer container, StrolchTransaction tx) {
super(container, tx);
}
/**
* @param resource
* the resource to set
*/
public void setResource(Resource resource) {
this.resource = resource;
}
@Override
public void validate() {
DBC.PRE.assertNotNull("Resource may not be null!", this.resource);
}
@Override
public void doCommand() {
tx().lock(this.resource);
ResourceMap resourceMap = tx().getResourceMap();
if (!resourceMap.hasElement(tx(), this.resource.getType(), this.resource.getId())) {
String msg = "The Resource {0} can not be updated as it does not exist!!";
msg = MessageFormat.format(msg, this.resource.getLocator());
throw new StrolchException(msg);
}
this.replacedElement = resourceMap.update(tx(), this.resource);
}
@Override
public void undo() {
if (this.replacedElement != null && tx().isRollingBack()) {
tx().getResourceMap().update(tx(), this.replacedElement);
}
}
}

View File

@ -0,0 +1,337 @@
/*
* 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 static ch.eitchnet.utils.helper.StringHelper.UNDERLINE;
import java.io.File;
import java.io.FileOutputStream;
import java.io.FilenameFilter;
import java.text.MessageFormat;
import java.util.Date;
import java.util.HashSet;
import java.util.Set;
import java.util.TreeSet;
import java.util.concurrent.TimeUnit;
import javanet.staxutils.IndentingXMLStreamWriter;
import javax.xml.stream.FactoryConfigurationError;
import javax.xml.stream.XMLOutputFactory;
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamWriter;
import li.strolch.agent.api.ComponentContainer;
import li.strolch.agent.api.OrderMap;
import li.strolch.agent.api.ResourceMap;
import li.strolch.exception.StrolchException;
import li.strolch.model.ModelStatistics;
import li.strolch.model.Order;
import li.strolch.model.OrderVisitor;
import li.strolch.model.Resource;
import li.strolch.model.ResourceVisitor;
import li.strolch.model.Tags;
import li.strolch.model.xml.OrderToSaxWriterVisitor;
import li.strolch.model.xml.ResourceToSaxWriterVisitor;
import li.strolch.persistence.api.StrolchTransaction;
import li.strolch.runtime.StrolchConstants;
import li.strolch.service.api.Command;
import ch.eitchnet.utils.dbc.DBC;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*/
public class XmlExportModelCommand extends Command {
public static final String XML_FILE_SUFFIX = ".xml";
private static final long LOG_INTERVAL = TimeUnit.SECONDS.toMillis(10);
// input
private File modelFile;
private boolean multiFile;
private boolean overwrite;
private boolean doOrders;
private boolean doResources;
private Set<String> orderTypes;
private Set<String> resourceTypes;
// output
private ModelStatistics statistics;
private int elementsToWrite;
private int nrOfResourcesToExport;
private int nrOfOrdersToExport;
private long nextLogTime;
public XmlExportModelCommand(ComponentContainer container, StrolchTransaction tx) {
super(container, tx);
}
@Override
public void validate() {
if (!this.overwrite)
DBC.PRE.assertNotExists("Model may not already exist!", this.modelFile);
DBC.PRE.assertTrue("Model file must end with .xml", this.modelFile.getName().endsWith(XML_FILE_SUFFIX));
}
private void cleanUpExisting(final String exportName) {
File parentFile = this.modelFile.getParentFile();
File[] existingFiles = parentFile.listFiles(new FilenameFilter() {
@Override
public boolean accept(File dir, String name) {
return name.startsWith(exportName);
}
});
for (File file : existingFiles) {
file.delete();
}
}
@Override
public void doCommand() {
this.nextLogTime = System.currentTimeMillis() + LOG_INTERVAL;
String fileName = this.modelFile.getName();
long start = System.nanoTime();
this.statistics = new ModelStatistics();
this.statistics.startTime = new Date();
String exportName = fileName.substring(0, fileName.indexOf(XML_FILE_SUFFIX));
cleanUpExisting(exportName);
Set<File> createdFiles = new HashSet<>();
if (this.doResources) {
ResourceMap resourceMap = tx().getResourceMap();
Set<String> resourceTypesToExport = resourceMap.getTypes(tx());
if (!this.resourceTypes.isEmpty())
resourceTypesToExport.retainAll(this.resourceTypes);
for (String type : resourceTypesToExport) {
this.nrOfResourcesToExport += resourceMap.querySize(tx(), type);
}
}
if (this.doOrders) {
OrderMap orderMap = tx().getOrderMap();
Set<String> orderTypesToExport = orderMap.getTypes(tx());
if (!this.orderTypes.isEmpty())
orderTypesToExport.retainAll(this.orderTypes);
for (String type : orderTypesToExport) {
this.nrOfOrdersToExport += orderMap.querySize(tx(), type);
}
}
this.elementsToWrite = this.nrOfResourcesToExport + this.nrOfOrdersToExport;
logger.info("Exporting " + this.elementsToWrite + " Elements...");
logger.info("Exporting " + this.nrOfResourcesToExport + " Resources...");
logger.info("Exporting " + this.nrOfOrdersToExport + " Orders...");
try (FileOutputStream out = new FileOutputStream(this.modelFile)) {
createdFiles.add(this.modelFile);
XMLStreamWriter writer = openXmlStreamWriter(out);
if (this.doResources) {
ResourceMap resourceMap = tx().getResourceMap();
Set<String> resourceTypesToExport = resourceMap.getTypes(tx());
if (!this.resourceTypes.isEmpty())
resourceTypesToExport.retainAll(this.resourceTypes);
resourceTypesToExport = new TreeSet<>(resourceTypesToExport);
for (String type : resourceTypesToExport) {
if (!this.multiFile) {
writeResourcesByType(writer, resourceMap, type);
} else {
String typeXmlFile = exportName + UNDERLINE + Tags.RESOURCE + UNDERLINE + type
+ XML_FILE_SUFFIX;
writer.writeEmptyElement(Tags.INCLUDE_FILE);
writer.writeAttribute(Tags.FILE, typeXmlFile);
File typeXmlFileF = new File(this.modelFile.getParentFile(), typeXmlFile);
DBC.INTERIM.assertNotExists("The type file should not exist with name.", typeXmlFileF);
logger.info("Writing " + resourceMap.querySize(tx(), type) + " " + type
+ " Resources to path: " + typeXmlFileF.getAbsolutePath() + "...");
try (FileOutputStream typeOut = new FileOutputStream(typeXmlFileF)) {
createdFiles.add(typeXmlFileF);
XMLStreamWriter typeWriter = openXmlStreamWriter(typeOut);
writeResourcesByType(typeWriter, resourceMap, type);
typeWriter.writeEndDocument();
}
}
}
}
if (this.doOrders) {
OrderMap orderMap = tx().getOrderMap();
Set<String> orderTypesToExport = orderMap.getTypes(tx());
if (!this.orderTypes.isEmpty())
orderTypesToExport.retainAll(this.orderTypes);
orderTypesToExport = new TreeSet<>(orderTypesToExport);
for (String type : orderTypesToExport) {
if (!this.multiFile) {
writeOrdersByType(writer, orderMap, type);
} else {
String typeXmlFile = exportName + UNDERLINE + Tags.ORDER + UNDERLINE + type + XML_FILE_SUFFIX;
writer.writeEmptyElement(Tags.INCLUDE_FILE);
writer.writeAttribute(Tags.FILE, typeXmlFile);
File typeXmlFileF = new File(this.modelFile.getParentFile(), typeXmlFile);
DBC.INTERIM.assertNotExists("The type file should not exist with name.", typeXmlFileF);
logger.info("Writing " + orderMap.querySize(tx(), type) + " " + type + " Orders to path: "
+ typeXmlFileF.getAbsolutePath() + "...");
try (FileOutputStream typeOut = new FileOutputStream(typeXmlFileF)) {
createdFiles.add(typeXmlFileF);
XMLStreamWriter typeWriter = openXmlStreamWriter(typeOut);
writeOrdersByType(typeWriter, orderMap, type);
typeWriter.writeEndDocument();
}
}
}
}
// and now end
writer.writeEndElement();
writer.writeEndDocument();
writer.flush();
writer.close();
this.statistics.durationNanos = System.nanoTime() - start;
} catch (Exception e) {
for (File createdFile : createdFiles) {
if (createdFile.exists())
createdFile.delete();
}
String msg = "Failed to write model to file {0} due to {1}";
msg = MessageFormat.format(msg, this.modelFile, e.getMessage());
throw new StrolchException(msg, e);
}
}
@Override
public void undo() {
logger.warn("Not undoing export to file " + this.modelFile);
}
private void writeOrdersByType(XMLStreamWriter writer, OrderMap orderMap, String type) {
OrderVisitor<?> visitor = new OrderToSaxWriterVisitor(writer);
Set<String> keysByType = new TreeSet<>(orderMap.getKeysBy(tx(), type));
for (String id : keysByType) {
Order order = orderMap.getBy(tx(), type, id);
visitor.visit(order);
this.statistics.nrOfOrders++;
logElementsWritten();
}
}
private void logElementsWritten() {
if (this.nextLogTime < System.currentTimeMillis()) {
logger.info("Wrote " + this.statistics.getNrOfElements() + " of " + this.elementsToWrite + " Elements.");
this.nextLogTime = System.currentTimeMillis() + LOG_INTERVAL;
}
}
private void writeResourcesByType(XMLStreamWriter writer, ResourceMap resourceMap, String type) {
ResourceVisitor<?> visitor = new ResourceToSaxWriterVisitor(writer);
Set<String> keysByType = new TreeSet<>(resourceMap.getKeysBy(tx(), type));
for (String id : keysByType) {
Resource resource = resourceMap.getBy(tx(), type, id);
visitor.visit(resource);
this.statistics.nrOfResources++;
logElementsWritten();
}
}
private XMLStreamWriter openXmlStreamWriter(FileOutputStream out) throws FactoryConfigurationError,
XMLStreamException {
XMLOutputFactory factory = XMLOutputFactory.newInstance();
XMLStreamWriter writer = factory.createXMLStreamWriter(out, StrolchConstants.DEFAULT_ENCODING);
writer = new IndentingXMLStreamWriter(writer);
// start document
writer.writeStartDocument(StrolchConstants.DEFAULT_ENCODING, StrolchConstants.DEFAULT_XML_VERSION);
writer.writeStartElement(Tags.STROLCH_MODEL);
return writer;
}
/**
* @param modelFile
* the modelFile to set
*/
public void setModelFile(File modelFile) {
this.modelFile = modelFile;
}
/**
* @param multiFile
*/
public void setMultiFile(boolean multiFile) {
this.multiFile = multiFile;
}
/**
* @param doOrders
* the doOrders to set
*/
public void setDoOrders(boolean doOrders) {
this.doOrders = doOrders;
}
/**
* @param doResources
* the doResources to set
*/
public void setDoResources(boolean doResources) {
this.doResources = doResources;
}
/**
* @param orderTypes
* the orderTypes to set
*/
public void setOrderTypes(Set<String> orderTypes) {
this.orderTypes = orderTypes;
}
/**
* @param resourceTypes
* the resourceTypes to set
*/
public void setResourceTypes(Set<String> resourceTypes) {
this.resourceTypes = resourceTypes;
}
/**
* @return the statistics
*/
public ModelStatistics getStatistics() {
return this.statistics;
}
/**
* @param overwrite
*/
public void setOverwrite(boolean overwrite) {
this.overwrite = overwrite;
}
}

View File

@ -0,0 +1,143 @@
/*
* 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 java.io.File;
import java.util.Set;
import li.strolch.agent.api.ComponentContainer;
import li.strolch.agent.impl.InMemoryElementListener;
import li.strolch.model.ModelStatistics;
import li.strolch.model.xml.XmlModelSaxFileReader;
import li.strolch.persistence.api.StrolchTransaction;
import li.strolch.service.api.Command;
import ch.eitchnet.utils.dbc.DBC;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*/
public class XmlImportModelCommand extends Command {
// input
private File modelFile;
private boolean addOrders;
private boolean addResources;
private boolean updateOrders;
private boolean updateResources;
private Set<String> orderTypes;
private Set<String> resourceTypes;
// output
private ModelStatistics statistics;
/**
* @param container
* @param tx
*/
public XmlImportModelCommand(ComponentContainer container, StrolchTransaction tx) {
super(container, tx);
}
@Override
public void validate() {
DBC.PRE.assertExists("Model must exist!", this.modelFile);
}
@Override
public void doCommand() {
InMemoryElementListener elementListener = new InMemoryElementListener(tx());
elementListener.setAddOrders(this.addOrders);
elementListener.setAddResources(this.addResources);
elementListener.setUpdateOrders(this.updateOrders);
elementListener.setUpdateResources(this.updateResources);
elementListener.setOrderTypes(this.orderTypes);
elementListener.setResourceTypes(this.resourceTypes);
XmlModelSaxFileReader handler = new XmlModelSaxFileReader(elementListener, this.modelFile);
handler.parseFile();
this.statistics = handler.getStatistics();
}
@Override
public void undo() {
logger.warn("Not undoing import of file " + this.modelFile);
}
/**
* @param modelFileName
*/
public void setModelFile(File modelFileName) {
this.modelFile = modelFileName;
}
/**
* @param addOrders
* the addOrders to set
*/
public void setAddOrders(boolean addOrders) {
this.addOrders = addOrders;
}
/**
* @param addResources
* the addResources to set
*/
public void setAddResources(boolean addResources) {
this.addResources = addResources;
}
/**
* @param updateOrders
* the updateOrders to set
*/
public void setUpdateOrders(boolean updateOrders) {
this.updateOrders = updateOrders;
}
/**
* @param updateResources
* the updateResources to set
*/
public void setUpdateResources(boolean updateResources) {
this.updateResources = updateResources;
}
/**
* @param orderTypes
* the orderTypes to set
*/
public void setOrderTypes(Set<String> orderTypes) {
this.orderTypes = orderTypes;
}
/**
* @param resourceTypes
* the resourceTypes to set
*/
public void setResourceTypes(Set<String> resourceTypes) {
this.resourceTypes = resourceTypes;
}
/**
* @return the statistics
*/
public ModelStatistics getStatistics() {
return this.statistics;
}
}

View File

@ -0,0 +1,97 @@
/*
* 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.parameter;
import java.text.MessageFormat;
import li.strolch.agent.api.ComponentContainer;
import li.strolch.command.visitor.UpdateElementVisitor;
import li.strolch.model.ParameterizedElement;
import li.strolch.model.StrolchRootElement;
import li.strolch.model.parameter.Parameter;
import li.strolch.persistence.api.StrolchPersistenceException;
import li.strolch.persistence.api.StrolchTransaction;
import li.strolch.service.api.Command;
import ch.eitchnet.utils.dbc.DBC;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*/
public class AddParameterCommand extends Command {
private ParameterizedElement element;
private Parameter<?> parameter;
private StrolchRootElement replacedElement;
/**
* @param container
* @param tx
*/
public AddParameterCommand(ComponentContainer container, StrolchTransaction tx) {
super(container, tx);
}
/**
* @param element
* the element to set
*/
public void setElement(ParameterizedElement element) {
this.element = element;
}
/**
* @param parameter
* the parameter to set
*/
public void setParameter(Parameter<?> parameter) {
this.parameter = parameter;
}
@Override
public void validate() {
DBC.PRE.assertNotNull("Element may not be null!", this.element);
DBC.PRE.assertNotNull("Parameter may not be null!", this.parameter);
if (this.element.hasParameter(this.parameter.getId())) {
String msg = "The Parameter {0} already exists on element {1}";
msg = MessageFormat.format(msg, this.parameter.getId(), this.element.getLocator());
throw new StrolchPersistenceException(msg);
}
}
@Override
public void doCommand() {
StrolchRootElement rootElement = this.element.getRootElement();
tx().lock(rootElement);
this.element.addParameter(this.parameter);
this.replacedElement = new UpdateElementVisitor(tx()).update(rootElement);
}
@Override
public void undo() {
if (this.parameter != null) {
if (this.element.hasParameter(this.parameter.getId())) {
this.element.removeParameter(this.parameter.getId());
}
}
if (this.replacedElement != null && this.element != this.replacedElement) {
new UpdateElementVisitor(tx()).update(this.replacedElement);
}
}
}

View File

@ -0,0 +1,97 @@
/*
* 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.parameter;
import java.text.MessageFormat;
import li.strolch.agent.api.ComponentContainer;
import li.strolch.command.visitor.UpdateElementVisitor;
import li.strolch.model.ParameterizedElement;
import li.strolch.model.StrolchRootElement;
import li.strolch.model.parameter.Parameter;
import li.strolch.persistence.api.StrolchPersistenceException;
import li.strolch.persistence.api.StrolchTransaction;
import li.strolch.service.api.Command;
import ch.eitchnet.utils.dbc.DBC;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*/
public class RemoveParameterCommand extends Command {
private ParameterizedElement element;
private String parameterId;
private Parameter<?> removedParameter;
private StrolchRootElement replacedElement;
/**
* @param container
* @param tx
*/
public RemoveParameterCommand(ComponentContainer container, StrolchTransaction tx) {
super(container, tx);
}
/**
* @param element
* the element to set
*/
public void setElement(ParameterizedElement element) {
this.element = element;
}
/**
* @param parameterId
* the parameterId to set
*/
public void setParameterId(String parameterId) {
this.parameterId = parameterId;
}
@Override
public void validate() {
DBC.PRE.assertNotNull("Element may not be null!", this.element);
DBC.PRE.assertNotEmpty("ParameterId must be set!", this.parameterId);
if (!this.element.hasParameter(this.parameterId)) {
String msg = "The Parameter {0} can not be removed as it does not exist on element {1}";
msg = MessageFormat.format(msg, this.parameterId, this.element.getLocator());
throw new StrolchPersistenceException(msg);
}
}
@Override
public void doCommand() {
StrolchRootElement rootElement = this.element.getRootElement();
tx().lock(rootElement);
this.removedParameter = this.element.removeParameter(this.parameterId);
this.replacedElement = new UpdateElementVisitor(tx()).update(rootElement);
}
@Override
public void undo() {
if (this.removedParameter != null) {
this.element.addParameter(this.removedParameter);
}
if (this.replacedElement != null && this.element != this.replacedElement) {
new UpdateElementVisitor(tx()).update(this.replacedElement);
}
}
}

View File

@ -0,0 +1,193 @@
/*
* 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.parameter;
import li.strolch.agent.api.ComponentContainer;
import li.strolch.command.visitor.UpdateElementVisitor;
import li.strolch.model.StrolchRootElement;
import li.strolch.model.parameter.Parameter;
import li.strolch.model.visitor.SetParameterValueVisitor;
import li.strolch.persistence.api.StrolchTransaction;
import li.strolch.service.api.Command;
import ch.eitchnet.utils.dbc.DBC;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*/
public class SetParameterCommand extends Command {
private Parameter<?> parameter;
private String name;
private String interpretation;
private String uom;
private Boolean hidden;
private Integer index;
private String valueAsString;
private String oldName;
private String oldInterpretation;
private String oldUom;
private Boolean oldHidden;
private Integer oldIndex;
private String oldValueAsString;
private StrolchRootElement replacedElement;
/**
* @param container
* @param tx
*/
public SetParameterCommand(ComponentContainer container, StrolchTransaction tx) {
super(container, tx);
}
/**
* @param parameter
* the parameter to set
*/
public void setParameter(Parameter<?> parameter) {
this.parameter = parameter;
}
/**
* @param name
* the name to set
*/
public void setName(String name) {
this.name = name;
}
/**
* @param interpretation
* the interpretation to set
*/
public void setInterpretation(String interpretation) {
this.interpretation = interpretation;
}
/**
* @param uom
* the uom to set
*/
public void setUom(String uom) {
this.uom = uom;
}
/**
* @param hidden
* the hidden to set
*/
public void setHidden(Boolean hidden) {
this.hidden = hidden;
}
/**
* @param index
* the index to set
*/
public void setIndex(Integer index) {
this.index = index;
}
/**
* @param valueAsString
* the valueAsString to set
*/
public void setValueAsString(String valueAsString) {
this.valueAsString = valueAsString;
}
@Override
public void validate() {
DBC.PRE.assertNotNull("Parameter may not be null!", this.parameter); //$NON-NLS-1$
}
@Override
public void doCommand() {
StrolchRootElement rootElement = this.parameter.getRootElement();
tx().lock(rootElement);
if (this.name != null) {
this.oldName = this.parameter.getName();
this.parameter.setName(this.name);
}
if (this.interpretation != null) {
this.oldInterpretation = this.parameter.getInterpretation();
this.parameter.setInterpretation(this.interpretation);
}
if (this.uom != null) {
this.oldUom = this.parameter.getUom();
this.parameter.setUom(this.uom);
}
if (this.hidden != null) {
this.oldHidden = this.parameter.isHidden();
this.parameter.setHidden(this.hidden);
}
if (this.index != null) {
this.oldIndex = this.parameter.getIndex();
this.parameter.setIndex(this.index.intValue());
}
if (this.valueAsString != null) {
this.oldValueAsString = this.parameter.getValueAsString();
SetParameterValueVisitor visitor = new SetParameterValueVisitor();
visitor.setValue(this.parameter, this.valueAsString);
}
if (hasChanges()) {
this.replacedElement = new UpdateElementVisitor(tx()).update(rootElement);
}
}
private boolean hasChanges() {
return this.oldValueAsString != null || this.oldName != null || this.oldInterpretation != null
|| this.oldUom != null || this.oldHidden != null || this.oldIndex != null;
}
@Override
public void undo() {
if (this.parameter != null) {
if (this.oldName != null) {
this.parameter.setName(this.oldName);
}
if (this.oldInterpretation != null) {
this.parameter.setInterpretation(this.oldInterpretation);
}
if (this.oldUom != null) {
this.parameter.setUom(this.oldUom);
}
if (this.oldHidden != null) {
this.parameter.setHidden(this.oldHidden);
}
if (this.oldIndex != null) {
this.parameter.setIndex(this.oldIndex.intValue());
}
if (this.oldValueAsString != null) {
SetParameterValueVisitor visitor = new SetParameterValueVisitor();
visitor.setValue(this.parameter, this.oldValueAsString);
}
if (hasChanges() && this.replacedElement != null && this.replacedElement != this.parameter.getRootElement()) {
new UpdateElementVisitor(tx()).update(this.replacedElement);
}
}
}
}

View File

@ -0,0 +1,48 @@
/*
* 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.visitor;
import li.strolch.model.Order;
import li.strolch.model.Resource;
import li.strolch.model.StrolchRootElement;
import li.strolch.model.visitor.StrolchRootElementVisitor;
import li.strolch.persistence.api.StrolchTransaction;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*/
public class UpdateElementVisitor implements StrolchRootElementVisitor<StrolchRootElement> {
private StrolchTransaction tx;
public UpdateElementVisitor(StrolchTransaction tx) {
this.tx = tx;
}
public StrolchRootElement update(StrolchRootElement rootElement) {
return rootElement.accept(this);
}
@Override
public StrolchRootElement visitOrder(Order order) {
return this.tx.getOrderMap().update(this.tx, order);
}
@Override
public StrolchRootElement visitResource(Resource resource) {
return this.tx.getResourceMap().update(this.tx, resource);
}
}

View File

@ -0,0 +1,56 @@
/*
* 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.util.List;
import li.strolch.command.AddOrderCollectionCommand;
import li.strolch.model.Order;
import li.strolch.persistence.api.StrolchTransaction;
import li.strolch.service.api.AbstractService;
import li.strolch.service.api.ServiceArgument;
import li.strolch.service.api.ServiceResult;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*/
public class AddOrderCollectionService extends
AbstractService<AddOrderCollectionService.AddOrderCollectionArg, ServiceResult> {
private static final long serialVersionUID = 1L;
@Override
protected ServiceResult getResultInstance() {
return new ServiceResult();
}
@Override
protected ServiceResult internalDoService(AddOrderCollectionArg arg) {
try (StrolchTransaction tx = openTx(arg.realm)) {
AddOrderCollectionCommand command = new AddOrderCollectionCommand(getContainer(), tx);
command.setOrders(arg.orders);
tx.addCommand(command);
}
return ServiceResult.success();
}
public static class AddOrderCollectionArg extends ServiceArgument {
private static final long serialVersionUID = 1L;
public List<Order> orders;
}
}

View File

@ -0,0 +1,53 @@
/*
* 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 li.strolch.command.AddOrderCommand;
import li.strolch.model.Order;
import li.strolch.persistence.api.StrolchTransaction;
import li.strolch.service.api.AbstractService;
import li.strolch.service.api.ServiceArgument;
import li.strolch.service.api.ServiceResult;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*/
public class AddOrderService extends AbstractService<AddOrderService.AddOrderArg, ServiceResult> {
private static final long serialVersionUID = 1L;
@Override
protected ServiceResult getResultInstance() {
return new ServiceResult();
}
@Override
protected ServiceResult internalDoService(AddOrderArg arg) {
try (StrolchTransaction tx = openTx(arg.realm)) {
AddOrderCommand command = new AddOrderCommand(getContainer(), tx);
command.setOrder(arg.order);
tx.addCommand(command);
}
return ServiceResult.success();
}
public static class AddOrderArg extends ServiceArgument {
private static final long serialVersionUID = 1L;
public Order order;
}
}

View File

@ -0,0 +1,56 @@
/*
* 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.util.List;
import li.strolch.command.AddResourceCollectionCommand;
import li.strolch.model.Resource;
import li.strolch.persistence.api.StrolchTransaction;
import li.strolch.service.api.AbstractService;
import li.strolch.service.api.ServiceArgument;
import li.strolch.service.api.ServiceResult;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*/
public class AddResourceCollectionService extends
AbstractService<AddResourceCollectionService.AddResourceCollectionArg, ServiceResult> {
private static final long serialVersionUID = 1L;
@Override
protected ServiceResult getResultInstance() {
return new ServiceResult();
}
@Override
protected ServiceResult internalDoService(AddResourceCollectionArg arg) {
try (StrolchTransaction tx = openTx(arg.realm)) {
AddResourceCollectionCommand command = new AddResourceCollectionCommand(getContainer(), tx);
command.setResources(arg.resources);
tx.addCommand(command);
}
return ServiceResult.success();
}
public static class AddResourceCollectionArg extends ServiceArgument {
private static final long serialVersionUID = 1L;
public List<Resource> resources;
}
}

View File

@ -0,0 +1,53 @@
/*
* 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 li.strolch.command.AddResourceCommand;
import li.strolch.model.Resource;
import li.strolch.persistence.api.StrolchTransaction;
import li.strolch.service.api.AbstractService;
import li.strolch.service.api.ServiceArgument;
import li.strolch.service.api.ServiceResult;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*/
public class AddResourceService extends AbstractService<AddResourceService.AddResourceArg, ServiceResult> {
private static final long serialVersionUID = 1L;
@Override
protected ServiceResult getResultInstance() {
return new ServiceResult();
}
@Override
protected ServiceResult internalDoService(AddResourceArg arg) {
try (StrolchTransaction tx = openTx(arg.realm)) {
AddResourceCommand command = new AddResourceCommand(getContainer(), tx);
command.setResource(arg.resource);
tx.addCommand(command);
}
return ServiceResult.success();
}
public static class AddResourceArg extends ServiceArgument {
private static final long serialVersionUID = 1L;
public Resource resource;
}
}

View File

@ -0,0 +1,24 @@
/*
* 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 li.strolch.service.api.ServiceArgument;
public class ClearModelArgument extends ServiceArgument {
private static final long serialVersionUID = 1L;
public boolean clearOrders;
public boolean clearResources;
}

View File

@ -0,0 +1,59 @@
/*
* 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.command.ClearModelCommand;
import li.strolch.model.ModelStatistics;
import li.strolch.persistence.api.StrolchTransaction;
import li.strolch.service.api.AbstractService;
import li.strolch.service.api.ServiceResult;
import ch.eitchnet.utils.helper.StringHelper;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*/
public class ClearModelService extends AbstractService<ClearModelArgument, ServiceResult> {
private static final long serialVersionUID = 1L;
@Override
protected ServiceResult getResultInstance() {
return new ServiceResult();
}
@Override
protected ServiceResult internalDoService(ClearModelArgument arg) {
ClearModelCommand command;
try (StrolchTransaction tx = openTx(arg.realm)) {
command = new ClearModelCommand(getContainer(), tx);
command.setClearOrders(arg.clearOrders);
command.setClearResources(arg.clearResources);
tx.addCommand(command);
}
ModelStatistics statistics = command.getStatistics();
String durationS = StringHelper.formatNanoDuration(statistics.durationNanos);
logger.info(MessageFormat.format("Clearing Model for realm {0} took {1}.", arg.realm, durationS)); //$NON-NLS-1$
logger.info(MessageFormat.format("Cleared {0} Orders", statistics.nrOfOrders)); //$NON-NLS-1$
logger.info(MessageFormat.format("Cleared {0} Resources", statistics.nrOfResources)); //$NON-NLS-1$
return ServiceResult.success();
}
}

View File

@ -0,0 +1,65 @@
/*
* 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.util.ArrayList;
import java.util.List;
import li.strolch.command.RemoveOrderCollectionCommand;
import li.strolch.model.Locator;
import li.strolch.model.Order;
import li.strolch.persistence.api.StrolchTransaction;
import li.strolch.service.api.AbstractService;
import li.strolch.service.api.ServiceArgument;
import li.strolch.service.api.ServiceResult;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*/
public class RemoveOrderCollectionService extends
AbstractService<RemoveOrderCollectionService.RemoveOrderCollectionArg, ServiceResult> {
private static final long serialVersionUID = 1L;
@Override
protected ServiceResult getResultInstance() {
return new ServiceResult();
}
@Override
protected ServiceResult internalDoService(RemoveOrderCollectionArg arg) {
try (StrolchTransaction tx = openTx(arg.realm)) {
List<Order> orders = new ArrayList<>(arg.locators.size());
for (Locator locator : arg.locators) {
Order resource = tx.findElement(locator);
orders.add(resource);
}
RemoveOrderCollectionCommand command = new RemoveOrderCollectionCommand(getContainer(), tx);
command.setOrders(orders);
tx.addCommand(command);
}
return ServiceResult.success();
}
public static class RemoveOrderCollectionArg extends ServiceArgument {
private static final long serialVersionUID = 1L;
public List<Locator> locators;
}
}

View File

@ -0,0 +1,57 @@
/*
* 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 li.strolch.command.RemoveOrderCommand;
import li.strolch.model.Locator;
import li.strolch.model.Order;
import li.strolch.persistence.api.StrolchTransaction;
import li.strolch.service.api.AbstractService;
import li.strolch.service.api.ServiceArgument;
import li.strolch.service.api.ServiceResult;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*/
public class RemoveOrderService extends AbstractService<RemoveOrderService.RemoveOrderArg, ServiceResult> {
private static final long serialVersionUID = 1L;
@Override
protected ServiceResult getResultInstance() {
return new ServiceResult();
}
@Override
protected ServiceResult internalDoService(RemoveOrderArg arg) {
try (StrolchTransaction tx = openTx(arg.realm)) {
Order order = tx.findElement(arg.locator);
RemoveOrderCommand command = new RemoveOrderCommand(getContainer(), tx);
command.setOrder(order);
tx.addCommand(command);
}
return ServiceResult.success();
}
public static class RemoveOrderArg extends ServiceArgument {
private static final long serialVersionUID = 1L;
public Locator locator;
}
}

View File

@ -0,0 +1,65 @@
/*
* 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.util.ArrayList;
import java.util.List;
import li.strolch.command.RemoveResourceCollectionCommand;
import li.strolch.model.Locator;
import li.strolch.model.Resource;
import li.strolch.persistence.api.StrolchTransaction;
import li.strolch.service.api.AbstractService;
import li.strolch.service.api.ServiceArgument;
import li.strolch.service.api.ServiceResult;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*/
public class RemoveResourceCollectionService extends
AbstractService<RemoveResourceCollectionService.RemoveResourceCollectionArg, ServiceResult> {
private static final long serialVersionUID = 1L;
@Override
protected ServiceResult getResultInstance() {
return new ServiceResult();
}
@Override
protected ServiceResult internalDoService(RemoveResourceCollectionArg arg) {
try (StrolchTransaction tx = openTx(arg.realm)) {
List<Resource> resources = new ArrayList<>(arg.locators.size());
for (Locator locator : arg.locators) {
Resource resource = tx.findElement(locator);
resources.add(resource);
}
RemoveResourceCollectionCommand command = new RemoveResourceCollectionCommand(getContainer(), tx);
command.setResources(resources);
tx.addCommand(command);
}
return ServiceResult.success();
}
public static class RemoveResourceCollectionArg extends ServiceArgument {
private static final long serialVersionUID = 1L;
public List<Locator> locators;
}
}

View File

@ -0,0 +1,57 @@
/*
* 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 li.strolch.command.RemoveResourceCommand;
import li.strolch.model.Locator;
import li.strolch.model.Resource;
import li.strolch.persistence.api.StrolchTransaction;
import li.strolch.service.api.AbstractService;
import li.strolch.service.api.ServiceArgument;
import li.strolch.service.api.ServiceResult;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*/
public class RemoveResourceService extends AbstractService<RemoveResourceService.RemoveResourceArg, ServiceResult> {
private static final long serialVersionUID = 1L;
@Override
protected ServiceResult getResultInstance() {
return new ServiceResult();
}
@Override
protected ServiceResult internalDoService(RemoveResourceArg arg) {
try (StrolchTransaction tx = openTx(arg.realm)) {
Resource resource = tx.findElement(arg.locator);
RemoveResourceCommand command = new RemoveResourceCommand(getContainer(), tx);
command.setResource(resource);
tx.addCommand(command);
}
return ServiceResult.success();
}
public static class RemoveResourceArg extends ServiceArgument {
private static final long serialVersionUID = 1L;
public Locator locator;
}
}

View File

@ -0,0 +1,56 @@
/*
* 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.util.List;
import li.strolch.command.UpdateOrderCollectionCommand;
import li.strolch.model.Order;
import li.strolch.persistence.api.StrolchTransaction;
import li.strolch.service.api.AbstractService;
import li.strolch.service.api.ServiceArgument;
import li.strolch.service.api.ServiceResult;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*/
public class UpdateOrderCollectionService extends
AbstractService<UpdateOrderCollectionService.UpdateOrderCollectionArg, ServiceResult> {
private static final long serialVersionUID = 1L;
@Override
protected ServiceResult getResultInstance() {
return new ServiceResult();
}
@Override
protected ServiceResult internalDoService(UpdateOrderCollectionArg arg) {
try (StrolchTransaction tx = openTx(arg.realm)) {
UpdateOrderCollectionCommand command = new UpdateOrderCollectionCommand(getContainer(), tx);
command.setOrders(arg.orders);
tx.addCommand(command);
}
return ServiceResult.success();
}
public static class UpdateOrderCollectionArg extends ServiceArgument {
private static final long serialVersionUID = 1L;
public List<Order> orders;
}
}

View File

@ -0,0 +1,53 @@
/*
* 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 li.strolch.command.UpdateOrderCommand;
import li.strolch.model.Order;
import li.strolch.persistence.api.StrolchTransaction;
import li.strolch.service.api.AbstractService;
import li.strolch.service.api.ServiceArgument;
import li.strolch.service.api.ServiceResult;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*/
public class UpdateOrderService extends AbstractService<UpdateOrderService.UpdateOrderArg, ServiceResult> {
private static final long serialVersionUID = 1L;
@Override
protected ServiceResult getResultInstance() {
return new ServiceResult();
}
@Override
protected ServiceResult internalDoService(UpdateOrderArg arg) {
try (StrolchTransaction tx = openTx(arg.realm)) {
UpdateOrderCommand command = new UpdateOrderCommand(getContainer(), tx);
command.setOrder(arg.order);
tx.addCommand(command);
}
return ServiceResult.success();
}
public static class UpdateOrderArg extends ServiceArgument {
private static final long serialVersionUID = 1L;
public Order order;
}
}

View File

@ -0,0 +1,56 @@
/*
* 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.util.List;
import li.strolch.command.UpdateResourceCollectionCommand;
import li.strolch.model.Resource;
import li.strolch.persistence.api.StrolchTransaction;
import li.strolch.service.api.AbstractService;
import li.strolch.service.api.ServiceArgument;
import li.strolch.service.api.ServiceResult;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*/
public class UpdateResourceCollectionService extends
AbstractService<UpdateResourceCollectionService.UpdateResourceCollectionArg, ServiceResult> {
private static final long serialVersionUID = 1L;
@Override
protected ServiceResult getResultInstance() {
return new ServiceResult();
}
@Override
protected ServiceResult internalDoService(UpdateResourceCollectionArg arg) {
try (StrolchTransaction tx = openTx(arg.realm)) {
UpdateResourceCollectionCommand command = new UpdateResourceCollectionCommand(getContainer(), tx);
command.setResources(arg.resources);
tx.addCommand(command);
}
return ServiceResult.success();
}
public static class UpdateResourceCollectionArg extends ServiceArgument {
private static final long serialVersionUID = 1L;
public List<Resource> resources;
}
}

View File

@ -0,0 +1,53 @@
/*
* 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 li.strolch.command.UpdateResourceCommand;
import li.strolch.model.Resource;
import li.strolch.persistence.api.StrolchTransaction;
import li.strolch.service.api.AbstractService;
import li.strolch.service.api.ServiceArgument;
import li.strolch.service.api.ServiceResult;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*/
public class UpdateResourceService extends AbstractService<UpdateResourceService.UpdateResourceArg, ServiceResult> {
private static final long serialVersionUID = 1L;
@Override
protected ServiceResult getResultInstance() {
return new ServiceResult();
}
@Override
protected ServiceResult internalDoService(UpdateResourceArg arg) {
try (StrolchTransaction tx = openTx(arg.realm)) {
UpdateResourceCommand command = new UpdateResourceCommand(getContainer(), tx);
command.setResource(arg.resource);
tx.addCommand(command);
}
return ServiceResult.success();
}
public static class UpdateResourceArg extends ServiceArgument {
private static final long serialVersionUID = 1L;
public Resource resource;
}
}

View File

@ -0,0 +1,68 @@
/*
* 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.util.HashSet;
import java.util.Set;
import li.strolch.service.api.ServiceArgument;
public class XmlExportModelArgument extends ServiceArgument {
private static final long serialVersionUID = 1L;
public String modelFileName;
public boolean overwrite;
public boolean multiFile;
public boolean doOrders = true;
public boolean doResources = true;
public Set<String> orderTypes = new HashSet<>();
public Set<String> resourceTypes = new HashSet<>();
@Override
public String toString() {
StringBuilder builder = new StringBuilder();
builder.append("XmlExportModelArgument [ ");
builder.append("modelFileName=");
builder.append(this.modelFileName);
builder.append(", overwrite=");
builder.append(this.overwrite);
builder.append(", multiFile=");
builder.append(this.multiFile);
if (this.doResources)
builder.append(", resources");
if (this.doOrders)
builder.append(", orders");
if (this.resourceTypes != null && !this.resourceTypes.isEmpty()) {
builder.append(", resourceTypes=");
builder.append(this.resourceTypes);
} else {
builder.append(", resourceTypes=*");
}
if (this.orderTypes != null && !this.orderTypes.isEmpty()) {
builder.append(", orderTypes=");
builder.append(this.orderTypes);
} else {
builder.append(", orderTypes=*");
}
builder.append("]");
return builder.toString();
}
}

View File

@ -0,0 +1,79 @@
/*
* 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.File;
import java.text.MessageFormat;
import li.strolch.command.XmlExportModelCommand;
import li.strolch.exception.StrolchException;
import li.strolch.model.ModelStatistics;
import li.strolch.persistence.api.StrolchTransaction;
import li.strolch.service.api.AbstractService;
import li.strolch.service.api.ServiceResult;
import ch.eitchnet.utils.dbc.DBC;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*/
public class XmlExportModelService extends AbstractService<XmlExportModelArgument, ServiceResult> {
private static final long serialVersionUID = 1L;
@Override
protected ServiceResult getResultInstance() {
return new ServiceResult();
}
@Override
protected ServiceResult internalDoService(XmlExportModelArgument arg) {
DBC.PRE.assertNotEmpty("Modelfile must be set!", arg.modelFileName);
File dataPath = getRuntimeConfiguration().getDataPath();
File modelFile = new File(dataPath, arg.modelFileName);
if (modelFile.exists()) {
if (!arg.overwrite) {
String msg = "Model File already exists with name {0} in data path {1}"; //$NON-NLS-1$
msg = MessageFormat.format(msg, arg.modelFileName, dataPath);
throw new StrolchException(msg);
}
}
logger.info("Exporting: " + arg);
logger.info("Exporting model to real path: " + modelFile.getAbsolutePath());
XmlExportModelCommand command;
try (StrolchTransaction tx = openTx(arg.realm)) {
command = new XmlExportModelCommand(getContainer(), tx);
command.setModelFile(modelFile);
command.setOverwrite(arg.overwrite);
command.setMultiFile(arg.multiFile);
command.setDoOrders(arg.doOrders);
command.setDoResources(arg.doResources);
command.setOrderTypes(arg.orderTypes);
command.setResourceTypes(arg.resourceTypes);
tx.addCommand(command);
}
ModelStatistics statistics = command.getStatistics();
String msg = "Wrote XML Model file {0} for realm {1}: {2} at path: {3}";
logger.info(MessageFormat.format(msg, modelFile.getName(), arg.realm, statistics, modelFile.getAbsolutePath()));
return ServiceResult.success();
}
}

View File

@ -0,0 +1,33 @@
/*
* 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.util.HashSet;
import java.util.Set;
import li.strolch.service.api.ServiceArgument;
public class XmlImportModelArgument extends ServiceArgument {
private static final long serialVersionUID = 1L;
public String modelFileName;
public boolean addOrders = true;
public boolean addResources = true;
public boolean updateOrders = true;
public boolean updateResources = true;
public Set<String> orderTypes = new HashSet<>();
public Set<String> resourceTypes = new HashSet<>();
}

View File

@ -0,0 +1,75 @@
/*
* 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.File;
import java.text.MessageFormat;
import li.strolch.command.XmlImportModelCommand;
import li.strolch.exception.StrolchException;
import li.strolch.model.ModelStatistics;
import li.strolch.persistence.api.StrolchTransaction;
import li.strolch.service.api.AbstractService;
import li.strolch.service.api.ServiceResult;
import ch.eitchnet.utils.helper.StringHelper;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*/
public class XmlImportModelService extends AbstractService<XmlImportModelArgument, ServiceResult> {
private static final long serialVersionUID = 1L;
@Override
protected ServiceResult getResultInstance() {
return new ServiceResult();
}
@Override
protected ServiceResult internalDoService(XmlImportModelArgument arg) {
File dataPath = getRuntimeConfiguration().getDataPath();
File modelFile = new File(dataPath, arg.modelFileName);
if (!modelFile.exists()) {
String msg = "Model File does not exist with name {0} in data path {1}"; //$NON-NLS-1$
msg = MessageFormat.format(msg, arg.modelFileName, dataPath);
throw new StrolchException(msg);
}
XmlImportModelCommand command;
try (StrolchTransaction tx = openTx(arg.realm)) {
command = new XmlImportModelCommand(getContainer(), tx);
command.setModelFile(modelFile);
command.setAddOrders(arg.addOrders);
command.setAddResources(arg.addResources);
command.setUpdateOrders(arg.updateOrders);
command.setUpdateResources(arg.updateResources);
command.setOrderTypes(arg.orderTypes);
command.setResourceTypes(arg.resourceTypes);
tx.addCommand(command);
}
ModelStatistics statistics = command.getStatistics();
String durationS = StringHelper.formatNanoDuration(statistics.durationNanos);
logger.info(MessageFormat.format(
"Loading XML Model file {0} for realm {1} took {2}.", modelFile.getName(), arg.realm, durationS)); //$NON-NLS-1$
logger.info(MessageFormat.format("Loaded {0} Orders", statistics.nrOfOrders)); //$NON-NLS-1$
logger.info(MessageFormat.format("Loaded {0} Resources", statistics.nrOfResources)); //$NON-NLS-1$
return ServiceResult.success();
}
}

View File

@ -0,0 +1,60 @@
/*
* 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.parameter;
import li.strolch.command.parameter.AddParameterCommand;
import li.strolch.model.Locator;
import li.strolch.model.ParameterizedElement;
import li.strolch.model.parameter.Parameter;
import li.strolch.persistence.api.StrolchTransaction;
import li.strolch.service.api.AbstractService;
import li.strolch.service.api.ServiceArgument;
import li.strolch.service.api.ServiceResult;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*/
public class AddParameterService extends AbstractService<AddParameterService.AddParameterArg, ServiceResult> {
private static final long serialVersionUID = 1L;
@Override
protected ServiceResult getResultInstance() {
return new ServiceResult();
}
@Override
protected ServiceResult internalDoService(AddParameterArg arg) {
try (StrolchTransaction tx = openTx(arg.realm)) {
ParameterizedElement element = tx.findElement(arg.locator);
AddParameterCommand command = new AddParameterCommand(getContainer(), tx);
command.setElement(element);
command.setParameter(arg.parameter);
tx.addCommand(command);
}
return ServiceResult.success();
}
public static class AddParameterArg extends ServiceArgument {
private static final long serialVersionUID = 1L;
public Locator locator;
public Parameter<?> parameter;
}
}

View File

@ -0,0 +1,58 @@
/*
* 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.parameter;
import li.strolch.command.parameter.RemoveParameterCommand;
import li.strolch.model.Locator;
import li.strolch.model.parameter.Parameter;
import li.strolch.persistence.api.StrolchTransaction;
import li.strolch.service.api.AbstractService;
import li.strolch.service.api.ServiceArgument;
import li.strolch.service.api.ServiceResult;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*/
public class RemoveParameterService extends AbstractService<RemoveParameterService.RemoveParameterArg, ServiceResult> {
private static final long serialVersionUID = 1L;
@Override
protected ServiceResult getResultInstance() {
return new ServiceResult();
}
@Override
protected ServiceResult internalDoService(RemoveParameterArg arg) {
try (StrolchTransaction tx = openTx(arg.realm)) {
Parameter<?> parameter = tx.findElement(arg.locator);
RemoveParameterCommand command = new RemoveParameterCommand(getContainer(), tx);
command.setElement(parameter.getParent());
command.setParameterId(parameter.getId());
tx.addCommand(command);
}
return ServiceResult.success();
}
public static class RemoveParameterArg extends ServiceArgument {
private static final long serialVersionUID = 1L;
public Locator locator;
}
}

View File

@ -0,0 +1,74 @@
/*
* 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.parameter;
import li.strolch.command.parameter.SetParameterCommand;
import li.strolch.model.Locator;
import li.strolch.model.parameter.Parameter;
import li.strolch.persistence.api.StrolchTransaction;
import li.strolch.service.api.AbstractService;
import li.strolch.service.api.ServiceArgument;
import li.strolch.service.api.ServiceResult;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*/
public class SetParameterService extends AbstractService<SetParameterService.SetParameterArg, ServiceResult> {
public static final long serialVersionUID = 1L;
@Override
protected ServiceResult getResultInstance() {
return new ServiceResult();
}
@Override
protected ServiceResult internalDoService(SetParameterArg arg) {
try (StrolchTransaction tx = openTx(arg.realm)) {
Parameter<?> parameter = tx.findElement(arg.locator);
SetParameterCommand command = new SetParameterCommand(getContainer(), tx);
command.setParameter(parameter);
command.setName(arg.name);
command.setInterpretation(arg.interpretation);
command.setUom(arg.uom);
command.setHidden(arg.hidden);
command.setIndex(arg.index);
command.setValueAsString(arg.valueAsString);
tx.addCommand(command);
}
return ServiceResult.success();
}
public static class SetParameterArg extends ServiceArgument {
public static final long serialVersionUID = 1L;
public Locator locator;
public String name;
public String interpretation;
public String uom;
public Boolean hidden;
public Integer index;
public String valueAsString;
}
}

View File

@ -0,0 +1,6 @@
groupId=${project.groupId}
artifactId=${project.artifactId}
artifactVersion=${project.version}
scmRevision=r${buildNumber}
scmBranch=${scmBranch}
buildTimestamp=${buildTimestamp}

View File

@ -0,0 +1,150 @@
/*
* 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 static li.strolch.service.test.AbstractRealmServiceTest.CONFIG_SRC;
import static li.strolch.service.test.AbstractRealmServiceTest.REALM_CACHED;
import static li.strolch.service.test.AbstractRealmServiceTest.REALM_TRANSACTIONAL;
import static li.strolch.service.test.AbstractRealmServiceTest.REALM_TRANSIENT;
import static li.strolch.service.test.AbstractRealmServiceTest.RUNTIME_PATH;
import static li.strolch.service.test.AbstractRealmServiceTest.dropSchema;
import static li.strolch.service.test.AbstractRealmServiceTest.importFromXml;
import java.io.File;
import java.sql.SQLException;
import li.strolch.agent.api.ComponentContainer;
import li.strolch.agent.api.StrolchRealm;
import li.strolch.persistence.api.StrolchTransaction;
import li.strolch.service.api.Command;
import li.strolch.service.api.ServiceHandler;
import li.strolch.testbase.runtime.RuntimeMock;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import ch.eitchnet.privilege.model.Certificate;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*/
public abstract class AbstractRealmCommandTest {
protected static RuntimeMock runtimeMock;
protected static Certificate certificate;
@Rule
public ExpectedException expectedException = ExpectedException.none();
@BeforeClass
public static void beforeClass() throws SQLException {
dropSchema("jdbc:postgresql://localhost/cacheduserdb", "cacheduser", "test");
dropSchema("jdbc:postgresql://localhost/transactionaluserdb", "transactionaluser", "test");
File rootPath = new File(RUNTIME_PATH);
File configSrc = new File(CONFIG_SRC);
runtimeMock = new RuntimeMock();
runtimeMock.mockRuntime(rootPath, configSrc);
runtimeMock.startContainer();
certificate = runtimeMock.getPrivilegeHandler().authenticate("test", "test".getBytes());
importFromXml(REALM_CACHED, certificate, getServiceHandler());
importFromXml(REALM_TRANSACTIONAL, certificate, getServiceHandler());
}
@AfterClass
public static void afterClass() {
runtimeMock.destroyRuntime();
}
public static ServiceHandler getServiceHandler() {
return runtimeMock.getContainer().getComponent(ServiceHandler.class);
}
protected abstract Command getCommandInstance(ComponentContainer container, StrolchTransaction tx);
protected void doCommandAsFail(String realmName) {
this.expectedException.expect(RuntimeException.class);
this.expectedException.expectMessage("Fail on purpose after do command!");
StrolchRealm realm = runtimeMock.getContainer().getRealm(realmName);
try (StrolchTransaction tx = realm.openTx(certificate, "test")) {
Command command = getCommandInstance(runtimeMock.getContainer(), tx);
FailCommandFacade commandFacade = new FailCommandFacade(runtimeMock.getContainer(), tx, command);
tx.addCommand(commandFacade);
}
}
protected void doCommand(String realmName) {
StrolchRealm realm = runtimeMock.getContainer().getRealm(realmName);
try (StrolchTransaction tx = realm.openTx(certificate, "test")) {
Command command = getCommandInstance(runtimeMock.getContainer(), tx);
tx.addCommand(command);
}
}
@Test
public void shouldFailCommandTransient() {
doCommandAsFail(REALM_TRANSIENT);
}
@Test
public void shouldFailCommandCached() {
doCommandAsFail(REALM_CACHED);
}
@Test
public void shouldFailCommandTransactional() {
doCommandAsFail(REALM_TRANSACTIONAL);
}
private class FailCommandFacade extends Command {
private Command command;
/**
* @param container
* @param tx
*/
public FailCommandFacade(ComponentContainer container, StrolchTransaction tx, Command command) {
super(container, tx);
this.command = command;
}
@Override
public void validate() {
this.command.validate();
}
@Override
public void doCommand() {
this.command.doCommand();
throw new RuntimeException("Fail on purpose after do command!");
}
@Override
public void undo() {
this.command.undo();
}
}
}

View File

@ -0,0 +1,51 @@
/*
* 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 java.util.ArrayList;
import java.util.List;
import li.strolch.agent.api.ComponentContainer;
import li.strolch.model.ModelGenerator;
import li.strolch.model.Order;
import li.strolch.persistence.api.StrolchTransaction;
import li.strolch.service.api.Command;
import org.junit.Before;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*/
public class AddOrderCollectionCommandTest extends AbstractRealmCommandTest {
private List<Order> orders;
@Before
public void before() {
this.orders = new ArrayList<>();
this.orders.add(ModelGenerator.createOrder("firstOrder", "First Order", "AdditionalOrders"));
this.orders.add(ModelGenerator.createOrder("secondOrder", "Second Order", "AdditionalOrders"));
this.orders.add(ModelGenerator.createOrder("thirdOrder", "Third Order", "AdditionalOrders"));
}
@Override
protected Command getCommandInstance(ComponentContainer container, StrolchTransaction tx) {
AddOrderCollectionCommand command = new AddOrderCollectionCommand(container, tx);
command.setOrders(this.orders);
return command;
}
}

View File

@ -0,0 +1,45 @@
/*
* 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.agent.api.ComponentContainer;
import li.strolch.model.ModelGenerator;
import li.strolch.model.Order;
import li.strolch.persistence.api.StrolchTransaction;
import li.strolch.service.api.Command;
import org.junit.Before;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*/
public class AddOrderCommandTest extends AbstractRealmCommandTest {
private Order order;
@Before
public void before() {
this.order = ModelGenerator.createOrder("firstOrder", "First Order", "AdditionalOrders");
}
@Override
protected Command getCommandInstance(ComponentContainer container, StrolchTransaction tx) {
AddOrderCommand command = new AddOrderCommand(container, tx);
command.setOrder(this.order);
return command;
}
}

View File

@ -0,0 +1,51 @@
/*
* 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 java.util.ArrayList;
import java.util.List;
import li.strolch.agent.api.ComponentContainer;
import li.strolch.model.ModelGenerator;
import li.strolch.model.Resource;
import li.strolch.persistence.api.StrolchTransaction;
import li.strolch.service.api.Command;
import org.junit.Before;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*/
public class AddResourceCollectionCommandTest extends AbstractRealmCommandTest {
private List<Resource> resources;
@Before
public void before() {
this.resources = new ArrayList<>();
this.resources.add(ModelGenerator.createResource("firstRes", "First Resource", "AdditionalResources"));
this.resources.add(ModelGenerator.createResource("secondRes", "Second Resource", "AdditionalResources"));
this.resources.add(ModelGenerator.createResource("thirdRes", "Third Resource", "AdditionalResources"));
}
@Override
protected Command getCommandInstance(ComponentContainer container, StrolchTransaction tx) {
AddResourceCollectionCommand command = new AddResourceCollectionCommand(container, tx);
command.setResources(this.resources);
return command;
}
}

View File

@ -0,0 +1,45 @@
/*
* 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.agent.api.ComponentContainer;
import li.strolch.model.ModelGenerator;
import li.strolch.model.Resource;
import li.strolch.persistence.api.StrolchTransaction;
import li.strolch.service.api.Command;
import org.junit.Before;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*/
public class AddResourceCommandTest extends AbstractRealmCommandTest {
private Resource resource;
@Before
public void before() {
this.resource = ModelGenerator.createResource("firstRes", "First Resource", "AdditionalResources");
}
@Override
protected Command getCommandInstance(ComponentContainer container, StrolchTransaction tx) {
AddResourceCommand command = new AddResourceCommand(container, tx);
command.setResource(this.resource);
return command;
}
}

View File

@ -0,0 +1,57 @@
/*
* 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 java.util.ArrayList;
import java.util.List;
import li.strolch.agent.api.ComponentContainer;
import li.strolch.model.Locator;
import li.strolch.model.Order;
import li.strolch.model.Tags;
import li.strolch.persistence.api.StrolchTransaction;
import li.strolch.service.api.Command;
import org.junit.Before;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*/
public class RemoveOrderCollectionCommandTest extends AbstractRealmCommandTest {
private List<Locator> locators;
@Before
public void before() {
this.locators = new ArrayList<>();
this.locators.add(Locator.newBuilder(Tags.ORDER, "TestType", "@1").build());
this.locators.add(Locator.newBuilder(Tags.ORDER, "TestType", "@2").build());
this.locators.add(Locator.newBuilder(Tags.ORDER, "TestType", "@3").build());
}
@Override
protected Command getCommandInstance(ComponentContainer container, StrolchTransaction tx) {
List<Order> orders = new ArrayList<>(this.locators.size());
for (Locator locator : this.locators) {
orders.add((Order) tx.findElement(locator));
}
RemoveOrderCollectionCommand command = new RemoveOrderCollectionCommand(container, tx);
command.setOrders(orders);
return command;
}
}

View File

@ -0,0 +1,48 @@
/*
* 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.agent.api.ComponentContainer;
import li.strolch.model.Locator;
import li.strolch.model.Order;
import li.strolch.model.Tags;
import li.strolch.persistence.api.StrolchTransaction;
import li.strolch.service.api.Command;
import org.junit.Before;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*/
public class RemoveOrderCommandTest extends AbstractRealmCommandTest {
private Locator locator;
@Before
public void before() {
this.locator = Locator.newBuilder(Tags.ORDER, "TestType", "@3").build();
}
@Override
protected Command getCommandInstance(ComponentContainer container, StrolchTransaction tx) {
Order order = tx.findElement(this.locator);
RemoveOrderCommand command = new RemoveOrderCommand(container, tx);
command.setOrder(order);
return command;
}
}

View File

@ -0,0 +1,57 @@
/*
* 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 java.util.ArrayList;
import java.util.List;
import li.strolch.agent.api.ComponentContainer;
import li.strolch.model.Locator;
import li.strolch.model.Resource;
import li.strolch.model.Tags;
import li.strolch.persistence.api.StrolchTransaction;
import li.strolch.service.api.Command;
import org.junit.Before;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*/
public class RemoveResourceCollectionCommandTest extends AbstractRealmCommandTest {
private List<Locator> locators;
@Before
public void before() {
this.locators = new ArrayList<>();
this.locators.add(Locator.newBuilder(Tags.RESOURCE, "Enumeration", "salutations").build());
this.locators.add(Locator.newBuilder(Tags.RESOURCE, "Enumeration", "sex").build());
this.locators.add(Locator.newBuilder(Tags.RESOURCE, "Enumeration", "religions").build());
}
@Override
protected Command getCommandInstance(ComponentContainer container, StrolchTransaction tx) {
List<Resource> resources = new ArrayList<>(this.locators.size());
for (Locator locator : this.locators) {
resources.add((Resource) tx.findElement(locator));
}
RemoveResourceCollectionCommand command = new RemoveResourceCollectionCommand(container, tx);
command.setResources(resources);
return command;
}
}

View File

@ -0,0 +1,48 @@
/*
* 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.agent.api.ComponentContainer;
import li.strolch.model.Locator;
import li.strolch.model.Resource;
import li.strolch.model.Tags;
import li.strolch.persistence.api.StrolchTransaction;
import li.strolch.service.api.Command;
import org.junit.Before;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*/
public class RemoveResourceCommandTest extends AbstractRealmCommandTest {
private Locator locator;
@Before
public void before() {
this.locator = Locator.newBuilder(Tags.RESOURCE, "Enumeration", "sex").build();
}
@Override
protected Command getCommandInstance(ComponentContainer container, StrolchTransaction tx) {
Resource resource = tx.findElement(this.locator);
RemoveResourceCommand command = new RemoveResourceCommand(container, tx);
command.setResource(resource);
return command;
}
}

View File

@ -0,0 +1,51 @@
/*
* 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 java.util.ArrayList;
import java.util.List;
import li.strolch.agent.api.ComponentContainer;
import li.strolch.model.ModelGenerator;
import li.strolch.model.Order;
import li.strolch.persistence.api.StrolchTransaction;
import li.strolch.service.api.Command;
import org.junit.Before;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*/
public class UpdateOrderCollectionCommandTest extends AbstractRealmCommandTest {
private List<Order> orders;
@Before
public void before() {
this.orders = new ArrayList<>();
this.orders.add(ModelGenerator.createOrder("@1", "Modified Test Order", "TestType"));
this.orders.add(ModelGenerator.createOrder("@2", "Modified Test Order", "TestType"));
this.orders.add(ModelGenerator.createOrder("@3", "Modified Test Order", "TestType"));
}
@Override
protected Command getCommandInstance(ComponentContainer container, StrolchTransaction tx) {
UpdateOrderCollectionCommand command = new UpdateOrderCollectionCommand(container, tx);
command.setOrders(this.orders);
return command;
}
}

View File

@ -0,0 +1,45 @@
/*
* 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.agent.api.ComponentContainer;
import li.strolch.model.ModelGenerator;
import li.strolch.model.Order;
import li.strolch.persistence.api.StrolchTransaction;
import li.strolch.service.api.Command;
import org.junit.Before;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*/
public class UpdateOrderCommandTest extends AbstractRealmCommandTest {
private Order order;
@Before
public void before() {
this.order = ModelGenerator.createOrder("myCarOrder", "Modified Car Order", "ProductionOrder");
}
@Override
protected Command getCommandInstance(ComponentContainer container, StrolchTransaction tx) {
UpdateOrderCommand command = new UpdateOrderCommand(container, tx);
command.setOrder(this.order);
return command;
}
}

View File

@ -0,0 +1,51 @@
/*
* 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 java.util.ArrayList;
import java.util.List;
import li.strolch.agent.api.ComponentContainer;
import li.strolch.model.ModelGenerator;
import li.strolch.model.Resource;
import li.strolch.persistence.api.StrolchTransaction;
import li.strolch.service.api.Command;
import org.junit.Before;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*/
public class UpdateResourceCollectionCommandTest extends AbstractRealmCommandTest {
private List<Resource> resources;
@Before
public void before() {
this.resources = new ArrayList<>();
this.resources.add(ModelGenerator.createResource("salutations", "Modified Enumeration", "Enumeration"));
this.resources.add(ModelGenerator.createResource("sex", "Modified Enumeration", "Enumeration"));
this.resources.add(ModelGenerator.createResource("religions", "Modified Enumeration", "Enumeration"));
}
@Override
protected Command getCommandInstance(ComponentContainer container, StrolchTransaction tx) {
UpdateResourceCollectionCommand command = new UpdateResourceCollectionCommand(container, tx);
command.setResources(this.resources);
return command;
}
}

View File

@ -0,0 +1,45 @@
/*
* 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.agent.api.ComponentContainer;
import li.strolch.model.ModelGenerator;
import li.strolch.model.Resource;
import li.strolch.persistence.api.StrolchTransaction;
import li.strolch.service.api.Command;
import org.junit.Before;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*/
public class UpdateResourceCommandTest extends AbstractRealmCommandTest {
private Resource resource;
@Before
public void before() {
this.resource = ModelGenerator.createResource("yellow", "Modified Yellow Ball", "Ball");
}
@Override
protected Command getCommandInstance(ComponentContainer container, StrolchTransaction tx) {
UpdateResourceCommand command = new UpdateResourceCommand(container, tx);
command.setResource(this.resource);
return command;
}
}

View File

@ -0,0 +1,53 @@
/*
* 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.parameter;
import li.strolch.agent.api.ComponentContainer;
import li.strolch.command.AbstractRealmCommandTest;
import li.strolch.model.Locator;
import li.strolch.model.ParameterizedElement;
import li.strolch.model.parameter.BooleanParameter;
import li.strolch.model.parameter.Parameter;
import li.strolch.persistence.api.StrolchTransaction;
import li.strolch.service.api.Command;
import org.junit.Before;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*/
public class AddParameterCommandTest extends AbstractRealmCommandTest {
private Locator locator;
private Parameter<?> parameter;
@Before
public void before() {
this.locator = Locator.valueOf("Resource/Ball/yellow/Bag/parameters");
this.parameter = new BooleanParameter("newParam", "New Param", false);
}
@Override
protected Command getCommandInstance(ComponentContainer container, StrolchTransaction tx) {
ParameterizedElement element = tx.findElement(this.locator);
AddParameterCommand command = new AddParameterCommand(container, tx);
command.setElement(element);
command.setParameter(this.parameter);
return command;
}
}

View File

@ -0,0 +1,51 @@
/*
* 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.parameter;
import li.strolch.agent.api.ComponentContainer;
import li.strolch.command.AbstractRealmCommandTest;
import li.strolch.model.Locator;
import li.strolch.model.ParameterizedElement;
import li.strolch.persistence.api.StrolchTransaction;
import li.strolch.service.api.Command;
import org.junit.Before;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*/
public class RemoveParameterCommandTest extends AbstractRealmCommandTest {
private Locator locator;
private String parameterId;
@Before
public void before() {
this.locator = Locator.valueOf("Resource/Ball/yellow/Bag/parameters");
this.parameterId = "owner";
}
@Override
protected Command getCommandInstance(ComponentContainer container, StrolchTransaction tx) {
ParameterizedElement element = tx.findElement(this.locator);
RemoveParameterCommand command = new RemoveParameterCommand(container, tx);
command.setElement(element);
command.setParameterId(this.parameterId);
return command;
}
}

View File

@ -0,0 +1,51 @@
/*
* 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.parameter;
import li.strolch.agent.api.ComponentContainer;
import li.strolch.command.AbstractRealmCommandTest;
import li.strolch.model.Locator;
import li.strolch.model.parameter.Parameter;
import li.strolch.persistence.api.StrolchTransaction;
import li.strolch.service.api.Command;
import org.junit.Before;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*/
public class SetParameterCommandTest extends AbstractRealmCommandTest {
private Locator locator;
private String valueAsString;
@Before
public void before() {
this.locator = Locator.valueOf("Resource/Ball/yellow/Bag/parameters/owner");
this.valueAsString = "someOtherDude";
}
@Override
protected Command getCommandInstance(ComponentContainer container, StrolchTransaction tx) {
Parameter<?> parameter = tx.findElement(this.locator);
SetParameterCommand command = new SetParameterCommand(container, tx);
command.setValueAsString(this.valueAsString);
command.setParameter(parameter);
return command;
}
}

View File

@ -0,0 +1,46 @@
/*
* 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.util.ArrayList;
import li.strolch.model.ModelGenerator;
import li.strolch.model.Order;
import li.strolch.service.AddOrderCollectionService.AddOrderCollectionArg;
import li.strolch.service.test.AbstractRealmServiceTest;
import org.junit.Test;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*/
public class AddOrderCollectionServiceTest extends AbstractRealmServiceTest {
@Test
public void runTest() {
AddOrderCollectionArg arg = new AddOrderCollectionArg();
ArrayList<Order> orders = new ArrayList<>();
orders.add(ModelGenerator.createOrder("firstOrder", "First Order", "AdditionalOrders"));
orders.add(ModelGenerator.createOrder("secondOrder", "Second Order", "AdditionalOrders"));
orders.add(ModelGenerator.createOrder("thirdOrder", "Third Order", "AdditionalOrders"));
arg.orders = orders;
runServiceInAllRealmTypes(AddOrderCollectionService.class, arg);
}
}

View File

@ -0,0 +1,37 @@
/*
* 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 li.strolch.model.ModelGenerator;
import li.strolch.service.AddOrderService.AddOrderArg;
import li.strolch.service.test.AbstractRealmServiceTest;
import org.junit.Test;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*/
public class AddOrderServiceTest extends AbstractRealmServiceTest {
@Test
public void runTest() {
AddOrderArg arg = new AddOrderArg();
arg.order = ModelGenerator.createOrder("firstOrder", "First Order", "AdditionalOrders");
runServiceInAllRealmTypes(AddOrderService.class, arg);
}
}

View File

@ -0,0 +1,46 @@
/*
* 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.util.ArrayList;
import li.strolch.model.ModelGenerator;
import li.strolch.model.Resource;
import li.strolch.service.AddResourceCollectionService.AddResourceCollectionArg;
import li.strolch.service.test.AbstractRealmServiceTest;
import org.junit.Test;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*/
public class AddResourceCollectionServiceTest extends AbstractRealmServiceTest {
@Test
public void runTest() {
AddResourceCollectionArg arg = new AddResourceCollectionArg();
ArrayList<Resource> resources = new ArrayList<>();
resources.add(ModelGenerator.createResource("firstRes", "First Resource", "AdditionalResources"));
resources.add(ModelGenerator.createResource("secondRes", "Second Resource", "AdditionalResources"));
resources.add(ModelGenerator.createResource("thirdRes", "Third Resource", "AdditionalResources"));
arg.resources = resources;
runServiceInAllRealmTypes(AddResourceCollectionService.class, arg);
}
}

View File

@ -0,0 +1,37 @@
/*
* 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 li.strolch.model.ModelGenerator;
import li.strolch.service.AddResourceService.AddResourceArg;
import li.strolch.service.test.AbstractRealmServiceTest;
import org.junit.Test;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*/
public class AddResourceServiceTest extends AbstractRealmServiceTest {
@Test
public void runTest() {
AddResourceArg arg = new AddResourceArg();
arg.resource = ModelGenerator.createResource("firstRes", "First Resource", "AdditionalResources");
runServiceInAllRealmTypes(AddResourceService.class, arg);
}
}

View File

@ -0,0 +1,92 @@
/*
* 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 static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotEquals;
import li.strolch.agent.api.ComponentContainer;
import li.strolch.agent.api.StrolchRealm;
import li.strolch.persistence.api.StrolchTransaction;
import li.strolch.service.test.AbstractRealmServiceTest;
import org.junit.Test;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*/
public class ClearModelServiceTest extends AbstractRealmServiceTest {
@Test
public void runClearTest() {
Runner validator = new Runner() {
@Override
public void run(StrolchRealm strolchRealm, ComponentContainer container) {
try (StrolchTransaction tx = strolchRealm.openTx(ClearModelServiceTest.this.certificate, "test")) {
assertEquals(0, tx.getResourceMap().querySize(tx));
assertEquals(0, tx.getOrderMap().querySize(tx));
}
}
};
ClearModelArgument arg = new ClearModelArgument();
arg.clearOrders = true;
arg.clearResources = true;
runServiceInAllRealmTypes(ClearModelService.class, arg, null, validator, null);
}
@Test
public void runClearOnlyOrdersTest() {
Runner validator = new Runner() {
@Override
public void run(StrolchRealm strolchRealm, ComponentContainer container) {
try (StrolchTransaction tx = strolchRealm.openTx(ClearModelServiceTest.this.certificate, "test")) {
assertNotEquals(0, tx.getResourceMap().querySize(tx));
assertEquals(0, tx.getOrderMap().querySize(tx));
}
}
};
ClearModelArgument arg = new ClearModelArgument();
arg.clearOrders = true;
arg.clearResources = false;
runServiceInAllRealmTypes(ClearModelService.class, arg, null, validator, null);
}
@Test
public void runClearOnlyResourcesTest() {
Runner validator = new Runner() {
@Override
public void run(StrolchRealm strolchRealm, ComponentContainer container) {
try (StrolchTransaction tx = strolchRealm.openTx(ClearModelServiceTest.this.certificate, "test")) {
assertNotEquals(0, tx.getOrderMap().querySize(tx));
assertEquals(0, tx.getResourceMap().querySize(tx));
}
}
};
ClearModelArgument arg = new ClearModelArgument();
arg.clearOrders = false;
arg.clearResources = true;
runServiceInAllRealmTypes(ClearModelService.class, arg, null, validator, null);
}
}

View File

@ -0,0 +1,46 @@
/*
* 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.util.ArrayList;
import li.strolch.model.Locator;
import li.strolch.model.Tags;
import li.strolch.service.RemoveOrderCollectionService.RemoveOrderCollectionArg;
import li.strolch.service.test.AbstractRealmServiceTest;
import org.junit.Test;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*/
public class RemoveOrderCollectionServiceTest extends AbstractRealmServiceTest {
@Test
public void runTest() {
RemoveOrderCollectionArg arg = new RemoveOrderCollectionArg();
ArrayList<Locator> locators = new ArrayList<>();
locators.add(Locator.newBuilder(Tags.ORDER, "TestType", "@1").build());
locators.add(Locator.newBuilder(Tags.ORDER, "TestType", "@2").build());
locators.add(Locator.newBuilder(Tags.ORDER, "TestType", "@3").build());
arg.locators = locators;
runServiceInAllRealmTypes(RemoveOrderCollectionService.class, arg);
}
}

View File

@ -0,0 +1,38 @@
/*
* 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 li.strolch.model.Locator;
import li.strolch.model.Tags;
import li.strolch.service.RemoveOrderService.RemoveOrderArg;
import li.strolch.service.test.AbstractRealmServiceTest;
import org.junit.Test;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*/
public class RemoveOrderServiceTest extends AbstractRealmServiceTest {
@Test
public void runTest() {
RemoveOrderArg arg = new RemoveOrderArg();
arg.locator = Locator.newBuilder(Tags.ORDER, "TestType", "@3").build();
runServiceInAllRealmTypes(RemoveOrderService.class, arg);
}
}

View File

@ -0,0 +1,46 @@
/*
* 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.util.ArrayList;
import li.strolch.model.Locator;
import li.strolch.model.Tags;
import li.strolch.service.RemoveResourceCollectionService.RemoveResourceCollectionArg;
import li.strolch.service.test.AbstractRealmServiceTest;
import org.junit.Test;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*/
public class RemoveResourceCollectionServiceTest extends AbstractRealmServiceTest {
@Test
public void runTest() {
RemoveResourceCollectionArg arg = new RemoveResourceCollectionArg();
ArrayList<Locator> locators = new ArrayList<>();
locators.add(Locator.newBuilder(Tags.RESOURCE, "Enumeration", "salutations").build());
locators.add(Locator.newBuilder(Tags.RESOURCE, "Enumeration", "sex").build());
locators.add(Locator.newBuilder(Tags.RESOURCE, "Enumeration", "religions").build());
arg.locators = locators;
runServiceInAllRealmTypes(RemoveResourceCollectionService.class, arg);
}
}

View File

@ -0,0 +1,38 @@
/*
* 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 li.strolch.model.Locator;
import li.strolch.model.Tags;
import li.strolch.service.RemoveResourceService.RemoveResourceArg;
import li.strolch.service.test.AbstractRealmServiceTest;
import org.junit.Test;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*/
public class RemoveResourceServiceTest extends AbstractRealmServiceTest {
@Test
public void runTest() {
RemoveResourceArg arg = new RemoveResourceArg();
arg.locator = Locator.newBuilder(Tags.RESOURCE, "Enumeration", "sex").build();
runServiceInAllRealmTypes(RemoveResourceService.class, arg);
}
}

View File

@ -0,0 +1,47 @@
/*
* 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.util.ArrayList;
import java.util.List;
import li.strolch.model.ModelGenerator;
import li.strolch.model.Order;
import li.strolch.service.UpdateOrderCollectionService.UpdateOrderCollectionArg;
import li.strolch.service.test.AbstractRealmServiceTest;
import org.junit.Test;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*/
public class UpdateOrderCollectionServiceTest extends AbstractRealmServiceTest {
@Test
public void runTest() {
UpdateOrderCollectionArg arg = new UpdateOrderCollectionArg();
List<Order> orders = new ArrayList<>();
orders.add(ModelGenerator.createOrder("@1", "Modified Test Order", "TestType"));
orders.add(ModelGenerator.createOrder("@2", "Modified Test Order", "TestType"));
orders.add(ModelGenerator.createOrder("@3", "Modified Test Order", "TestType"));
arg.orders = orders;
runServiceInAllRealmTypes(UpdateOrderCollectionService.class, arg);
}
}

View File

@ -0,0 +1,37 @@
/*
* 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 li.strolch.model.ModelGenerator;
import li.strolch.service.UpdateOrderService.UpdateOrderArg;
import li.strolch.service.test.AbstractRealmServiceTest;
import org.junit.Test;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*/
public class UpdateOrderServiceTest extends AbstractRealmServiceTest {
@Test
public void runTest() {
UpdateOrderArg arg = new UpdateOrderArg();
arg.order = ModelGenerator.createOrder("myCarOrder", "Modified Car Order", "ProductionOrder");
runServiceInAllRealmTypes(UpdateOrderService.class, arg);
}
}

View File

@ -0,0 +1,46 @@
/*
* 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.util.ArrayList;
import li.strolch.model.ModelGenerator;
import li.strolch.model.Resource;
import li.strolch.service.UpdateResourceCollectionService.UpdateResourceCollectionArg;
import li.strolch.service.test.AbstractRealmServiceTest;
import org.junit.Test;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*/
public class UpdateResourceCollectionServiceTest extends AbstractRealmServiceTest {
@Test
public void runTest() {
UpdateResourceCollectionArg arg = new UpdateResourceCollectionArg();
ArrayList<Resource> resources = new ArrayList<>();
resources.add(ModelGenerator.createResource("salutations", "Modified Enumeration", "Enumeration"));
resources.add(ModelGenerator.createResource("sex", "Modified Enumeration", "Enumeration"));
resources.add(ModelGenerator.createResource("religions", "Modified Enumeration", "Enumeration"));
arg.resources = resources;
runServiceInAllRealmTypes(UpdateResourceCollectionService.class, arg);
}
}

View File

@ -0,0 +1,37 @@
/*
* 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 li.strolch.model.ModelGenerator;
import li.strolch.service.UpdateResourceService.UpdateResourceArg;
import li.strolch.service.test.AbstractRealmServiceTest;
import org.junit.Test;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*/
public class UpdateResourceServiceTest extends AbstractRealmServiceTest {
@Test
public void runTest() {
UpdateResourceArg arg = new UpdateResourceArg();
arg.resource = ModelGenerator.createResource("yellow", "Modified Yellow Ball", "Ball");
runServiceInAllRealmTypes(UpdateResourceService.class, arg);
}
}

View File

@ -0,0 +1,103 @@
/*
* 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 static li.strolch.testbase.runtime.RuntimeMock.assertServiceResult;
import static org.hamcrest.Matchers.containsString;
import static org.junit.Assert.assertThat;
import java.io.File;
import java.io.IOException;
import li.strolch.agent.api.ComponentContainer;
import li.strolch.agent.api.StrolchRealm;
import li.strolch.service.api.ServiceResult;
import li.strolch.service.api.ServiceResultState;
import li.strolch.service.test.AbstractRealmServiceTest;
import org.junit.Test;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*/
public class XmlExportModelServiceTest extends AbstractRealmServiceTest {
private static final String TMP_XML_EXPORT_XML = "tmpXmlExport.xml";
@Test
public void runTest() {
Runner before = new Runner() {
@Override
public void run(StrolchRealm strolchRealm, ComponentContainer container) {
File file = new File(RUNTIME_PATH + "/data", TMP_XML_EXPORT_XML);
if (file.exists())
file.delete();
}
};
XmlExportModelArgument arg = new XmlExportModelArgument();
arg.modelFileName = TMP_XML_EXPORT_XML;
arg.multiFile = true;
runServiceInAllRealmTypes(XmlExportModelService.class, arg, before, null, null);
}
@Test
public void runTestFailOnExisting() {
File file = new File(RUNTIME_PATH + "/data", TMP_XML_EXPORT_XML);
if (!file.exists()) {
try {
file.createNewFile();
} catch (IOException e) {
throw new RuntimeException(e);
}
}
XmlExportModelService svc = new XmlExportModelService();
XmlExportModelArgument arg = new XmlExportModelArgument();
arg.realm = REALM_TRANSIENT;
arg.overwrite = false;
arg.multiFile = true;
arg.modelFileName = TMP_XML_EXPORT_XML;
ServiceResult result = getServiceHandler().doService(this.certificate, svc, arg);
assertServiceResult(ServiceResultState.FAILED, ServiceResult.class, result);
assertThat(result.getMessage(), containsString("Model File already exists with name"));
}
@Test
public void runTestOverwrite() {
File file = new File(RUNTIME_PATH + "/data", TMP_XML_EXPORT_XML);
if (!file.exists()) {
try {
file.createNewFile();
} catch (IOException e) {
throw new RuntimeException(e);
}
}
XmlExportModelService svc = new XmlExportModelService();
XmlExportModelArgument arg = new XmlExportModelArgument();
arg.realm = REALM_TRANSIENT;
arg.overwrite = true;
arg.multiFile = true;
arg.modelFileName = TMP_XML_EXPORT_XML;
ServiceResult result = getServiceHandler().doService(this.certificate, svc, arg);
assertServiceResult(ServiceResultState.SUCCESS, ServiceResult.class, result);
}
}

View File

@ -0,0 +1,35 @@
/*
* 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 li.strolch.service.test.AbstractRealmServiceTest;
import org.junit.Test;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*/
public class XmlImportModelServiceTest extends AbstractRealmServiceTest {
@Test
public void runTest() {
XmlImportModelArgument arg = new XmlImportModelArgument();
arg.modelFileName = "Enums.xml";
runServiceInAllRealmTypes(XmlImportModelService.class, arg);
}
}

View File

@ -0,0 +1,155 @@
/*
* 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.test;
import static li.strolch.testbase.runtime.RuntimeMock.assertServiceResult;
import java.io.File;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import li.strolch.agent.api.ComponentContainer;
import li.strolch.agent.api.StrolchRealm;
import li.strolch.persistence.postgresql.DbSchemaVersionCheck;
import li.strolch.service.XmlImportModelArgument;
import li.strolch.service.XmlImportModelService;
import li.strolch.service.api.Service;
import li.strolch.service.api.ServiceArgument;
import li.strolch.service.api.ServiceHandler;
import li.strolch.service.api.ServiceResult;
import li.strolch.service.api.ServiceResultState;
import li.strolch.testbase.runtime.RuntimeMock;
import org.junit.After;
import org.junit.Before;
import ch.eitchnet.privilege.model.Certificate;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*/
public abstract class AbstractRealmServiceTest {
public static final String REALM_CACHED = "svcCached";
public static final String REALM_TRANSACTIONAL = "svcTransactional";
public static final String REALM_TRANSIENT = "svcTransient";
public static final String RUNTIME_PATH = "target/svcTestRuntime/"; //$NON-NLS-1$
public static final String CONFIG_SRC = "src/test/resources/svctest"; //$NON-NLS-1$
protected static RuntimeMock runtimeMock;
protected Certificate certificate;
@Before
public void before() throws SQLException {
dropSchema("jdbc:postgresql://localhost/cacheduserdb", "cacheduser", "test");
dropSchema("jdbc:postgresql://localhost/transactionaluserdb", "transactionaluser", "test");
File rootPath = new File(RUNTIME_PATH);
File configSrc = new File(CONFIG_SRC);
runtimeMock = new RuntimeMock();
runtimeMock.mockRuntime(rootPath, configSrc);
runtimeMock.startContainer();
this.certificate = runtimeMock.getPrivilegeHandler().authenticate("test", "test".getBytes());
importFromXml(REALM_CACHED, this.certificate, getServiceHandler());
importFromXml(REALM_TRANSACTIONAL, this.certificate, getServiceHandler());
}
@After
public void after() {
runtimeMock.destroyRuntime();
}
public static void dropSchema(String dbUrl, String dbUsername, String dbPassword) throws SQLException {
String dbVersion = DbSchemaVersionCheck.getExpectedDbVersion();
String sql = DbSchemaVersionCheck.getSql(dbVersion, "drop"); //$NON-NLS-1$
try (Connection connection = DriverManager.getConnection(dbUrl, dbUsername, dbPassword)) {
connection.prepareStatement(sql).execute();
}
}
public static void importFromXml(String realm, Certificate certificate, ServiceHandler serviceHandler) {
XmlImportModelService svc = new XmlImportModelService();
XmlImportModelArgument arg = new XmlImportModelArgument();
arg.realm = realm;
arg.modelFileName = "StrolchModel.xml";
ServiceResult result = serviceHandler.doService(certificate, svc, arg);
assertServiceResult(ServiceResultState.SUCCESS, ServiceResult.class, result);
}
protected <T extends ServiceArgument, U extends ServiceResult> void doService(String realm,
ServiceResultState expectedState, Class<?> expectedServiceResultType, Service<T, U> svc, T arg,
Runner before, Runner validator, Runner after) {
if (before != null)
before.run(runtimeMock.getContainer().getRealm(realm), runtimeMock.getContainer());
arg.realm = realm;
ServiceResult result = getServiceHandler().doService(this.certificate, svc, arg);
assertServiceResult(expectedState, expectedServiceResultType, result);
if (validator != null)
validator.run(runtimeMock.getContainer().getRealm(realm), runtimeMock.getContainer());
if (after != null)
after.run(runtimeMock.getContainer().getRealm(realm), runtimeMock.getContainer());
}
public static ServiceHandler getServiceHandler() {
return runtimeMock.getContainer().getComponent(ServiceHandler.class);
}
public interface Runner {
public void run(StrolchRealm strolchRealm, ComponentContainer container);
}
protected <T extends ServiceArgument, U extends ServiceResult> void runServiceInAllRealmTypes(
Class<? extends Service<T, U>> svcClass, T arg) {
runServiceInAllRealmTypes(svcClass, arg, null, null, null);
}
protected <T extends ServiceArgument, U extends ServiceResult> void runServiceInAllRealmTypes(
Class<? extends Service<T, U>> svcClass, T arg, Runner before, Runner validator, Runner after) {
try {
runTransient(svcClass.newInstance(), arg, before, validator, after);
runCached(svcClass.newInstance(), arg, before, validator, after);
runTransactional(svcClass.newInstance(), arg, before, validator, after);
} catch (InstantiationException | IllegalAccessException e) {
throw new RuntimeException("Failed to instantiate class " + svcClass.getName() + ": " + e.getMessage(), e);
}
}
private <T extends ServiceArgument, U extends ServiceResult> void runTransactional(Service<T, U> svc, T arg,
Runner before, Runner validator, Runner after) {
doService(REALM_TRANSACTIONAL, ServiceResultState.SUCCESS, ServiceResult.class, svc, arg, before, validator,
after);
}
private <T extends ServiceArgument, U extends ServiceResult> void runCached(Service<T, U> svc, T arg,
Runner before, Runner validator, Runner after) {
doService(REALM_CACHED, ServiceResultState.SUCCESS, ServiceResult.class, svc, arg, before, validator, after);
}
private <T extends ServiceArgument, U extends ServiceResult> void runTransient(Service<T, U> svc, T arg,
Runner before, Runner validator, Runner after) {
doService(REALM_TRANSIENT, ServiceResultState.SUCCESS, ServiceResult.class, svc, arg, before, validator, after);
}
}

View File

@ -0,0 +1,53 @@
/*
* 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.test;
import java.io.File;
import li.strolch.service.api.ServiceHandler;
import li.strolch.testbase.runtime.RuntimeMock;
import org.junit.AfterClass;
import org.junit.BeforeClass;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*/
public abstract class AbstractServiceTest {
private static final String RUNTIME_PATH = "target/strolchRuntime/"; //$NON-NLS-1$
private static final String CONFIG_SRC = "src/test/resources/withPrivilegeRuntime"; //$NON-NLS-1$
protected static RuntimeMock runtimeMock;
@BeforeClass
public static void beforeClass() {
File rootPath = new File(RUNTIME_PATH);
File configSrc = new File(CONFIG_SRC);
runtimeMock = new RuntimeMock();
runtimeMock.mockRuntime(rootPath, configSrc);
runtimeMock.startContainer();
}
@AfterClass
public static void afterClass() {
runtimeMock.destroyRuntime();
}
public static ServiceHandler getServiceHandler() {
return runtimeMock.getContainer().getComponent(ServiceHandler.class);
}
}

View File

@ -0,0 +1,49 @@
/*
* 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.test;
import static org.hamcrest.Matchers.containsString;
import static org.junit.Assert.assertThat;
import li.strolch.service.test.model.GreetingResult;
import li.strolch.service.test.model.GreetingService;
import li.strolch.service.test.model.GreetingService.GreetingArgument;
import org.junit.Test;
import ch.eitchnet.privilege.model.Certificate;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*/
public class GreetingServiceTest extends AbstractServiceTest {
@Test
public void shouldPerformSimpleService() {
GreetingService greetingService = new GreetingService();
GreetingArgument greetingArgument = new GreetingArgument();
greetingArgument.name = "Robert"; //$NON-NLS-1$
Certificate certificate = runtimeMock.getPrivilegeHandler().authenticate("jill", "jill".getBytes()); //$NON-NLS-1$//$NON-NLS-2$
try {
GreetingResult greetingResult = getServiceHandler().doService(certificate, greetingService,
greetingArgument);
assertThat(greetingResult.getGreeting(), containsString("Hello Robert. Nice to meet you!")); //$NON-NLS-1$
} finally {
runtimeMock.getPrivilegeHandler().invalidateSession(certificate);
}
}
}

View File

@ -0,0 +1,189 @@
/*
* 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.test;
import static org.hamcrest.CoreMatchers.containsString;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertThat;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
import li.strolch.model.Locator;
import li.strolch.model.Resource;
import li.strolch.persistence.api.StrolchTransaction;
import li.strolch.service.api.AbstractService;
import li.strolch.service.api.ServiceArgument;
import li.strolch.service.api.ServiceHandler;
import li.strolch.service.api.ServiceResult;
import li.strolch.service.api.ServiceResultState;
import li.strolch.testbase.runtime.RuntimeMock;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import ch.eitchnet.privilege.model.Certificate;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*/
public class LockingTest {
private static final String RUNTIME_PATH = "target/lockingTest/"; //$NON-NLS-1$
private static final String CONFIG_SRC = "src/test/resources/transienttest"; //$NON-NLS-1$
private static final String RESOURCE_LOCATOR = "Resource/TestType/MyTestResource";
protected static RuntimeMock runtimeMock;
private volatile boolean run;
@BeforeClass
public static void beforeClass() {
File rootPath = new File(RUNTIME_PATH);
File configSrc = new File(CONFIG_SRC);
runtimeMock = new RuntimeMock();
runtimeMock.mockRuntime(rootPath, configSrc);
runtimeMock.startContainer();
}
@AfterClass
public static void afterClass() {
runtimeMock.destroyRuntime();
}
public static ServiceHandler getServiceHandler() {
return runtimeMock.getContainer().getComponent(ServiceHandler.class);
}
public static Certificate login() {
return runtimeMock.getPrivilegeHandler().authenticate("admin", "admin".getBytes());
}
@Test
public void shouldLockElements() throws InterruptedException {
List<LockingRunner> runners = new ArrayList<>();
// create the long running service
LockingServiceTest longRunningService = new LockingServiceTest();
LockingArgumentTest longRunningArg = new LockingArgumentTest();
longRunningArg.longRunning = true;
longRunningArg.resourceLoc = Locator.valueOf(RESOURCE_LOCATOR);
runners.add(new LockingRunner(longRunningService, longRunningArg));
// create multiple services which try and modify the same service, but are not long running
for (int i = 0; i < 5; i++) {
LockingServiceTest svc = new LockingServiceTest();
LockingArgumentTest arg = new LockingArgumentTest();
arg.longRunning = false;
arg.resourceLoc = Locator.valueOf(RESOURCE_LOCATOR);
runners.add(new LockingRunner(svc, arg));
}
this.run = false;
for (LockingRunner lockingRunner : runners) {
lockingRunner.start();
}
this.run = true;
for (LockingRunner lockingRunner : runners) {
lockingRunner.join();
}
assertEquals(ServiceResultState.SUCCESS, runners.get(0).getResult().getState());
for (int i = 1; i < runners.size(); i++) {
ServiceResult result = runners.get(i).getResult();
assertEquals(ServiceResultState.FAILED, result.getState());
assertThat(result.getMessage(), containsString("Failed to acquire lock after"));
}
// now assert that we can perform another such service, thus validating that the resource is not locked any longer
LockingServiceTest svc = new LockingServiceTest();
LockingArgumentTest arg = new LockingArgumentTest();
arg.longRunning = false;
arg.resourceLoc = Locator.valueOf(RESOURCE_LOCATOR);
ServiceResult result = getServiceHandler().doService(login(), svc, arg);
assertEquals(ServiceResultState.SUCCESS, result.getState());
}
private class LockingRunner extends Thread {
private LockingServiceTest svc;
private LockingArgumentTest arg;
private ServiceResult result;
/**
* @param svc
* @param arg
*/
public LockingRunner(LockingServiceTest svc, LockingArgumentTest arg) {
super();
this.svc = svc;
this.arg = arg;
}
@Override
public void run() {
while (!LockingTest.this.run) {
continue;
}
this.result = getServiceHandler().doService(login(), this.svc, this.arg);
}
public ServiceResult getResult() {
return this.result;
}
}
private static class LockingArgumentTest extends ServiceArgument {
private static final long serialVersionUID = 1L;
public boolean longRunning;
public Locator resourceLoc;
}
private static class LockingServiceTest extends AbstractService<LockingArgumentTest, ServiceResult> {
private static final long serialVersionUID = 1L;
@Override
protected ServiceResult getResultInstance() {
return new ServiceResult();
}
@Override
protected ServiceResult internalDoService(LockingArgumentTest arg) throws Exception {
try (StrolchTransaction tx = openTx(arg.realm)) {
if (!arg.longRunning)
Thread.sleep(200l);
Resource res = tx.findElement(arg.resourceLoc);
tx.lock(res);
if (arg.longRunning)
Thread.sleep(5000l);
}
return ServiceResult.success();
}
}
}

View File

@ -0,0 +1,117 @@
/*
* 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.test;
import static org.hamcrest.Matchers.equalTo;
import static org.junit.Assert.assertThat;
import li.strolch.service.test.model.GreetingResult;
import li.strolch.service.test.model.GreetingService;
import li.strolch.service.test.model.GreetingService.GreetingArgument;
import li.strolch.service.test.model.TestService;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import ch.eitchnet.privilege.base.AccessDeniedException;
import ch.eitchnet.privilege.base.PrivilegeException;
import ch.eitchnet.privilege.model.Certificate;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*/
public class ServiceTest extends AbstractServiceTest {
@Rule
public ExpectedException thrown = ExpectedException.none();
@Test
public void shouldFailNoCertificate() {
this.thrown.expect(PrivilegeException.class);
TestService testService = new TestService();
getServiceHandler().doService(null, testService);
}
@Test
public void shouldFailInvalidCertificate1() {
this.thrown.expect(PrivilegeException.class);
TestService testService = new TestService();
getServiceHandler().doService(new Certificate(null, 0, null, null, null, null, null, null), testService);
}
@Test
public void shouldFailInvalidCertificate2() {
this.thrown.expect(AccessDeniedException.class);
TestService testService = new TestService();
Certificate badCert = new Certificate(
"1", System.currentTimeMillis(), "bob", "Bob", "Brown", "dsdf", null, null); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
getServiceHandler().doService(badCert, testService);
}
@Test
public void shouldFailWithNoAccess() {
this.thrown.expect(AccessDeniedException.class);
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$
try {
TestService testService = new TestService();
getServiceHandler().doService(certificate, testService);
} finally {
runtimeMock.getPrivilegeHandler().invalidateSession(certificate);
}
}
@Test
public void shouldNotFailWithAccess() {
Certificate certificate = runtimeMock.getPrivilegeHandler().authenticate("jill", "jill".getBytes()); //$NON-NLS-1$//$NON-NLS-2$
try {
GreetingService service = new GreetingService();
GreetingArgument argument = new GreetingArgument();
argument.name = "Jill"; //$NON-NLS-1$
GreetingResult greetingResult = getServiceHandler().doService(certificate, service, argument);
assertThat(greetingResult.getGreeting(), equalTo("Hello Jill. Nice to meet you!")); //$NON-NLS-1$
} finally {
runtimeMock.getPrivilegeHandler().invalidateSession(certificate);
}
}
@Test
public void shouldNotFailWithLogin1() {
Certificate certificate = runtimeMock.getPrivilegeHandler().authenticate("bob", "bob".getBytes()); //$NON-NLS-1$//$NON-NLS-2$
try {
TestService testService = new TestService();
getServiceHandler().doService(certificate, testService);
} finally {
runtimeMock.getPrivilegeHandler().invalidateSession(certificate);
}
}
@Test
public void shouldNotFailWithLogin2() {
Certificate certificate = runtimeMock.getPrivilegeHandler().authenticate("bob", "bob".getBytes()); //$NON-NLS-1$//$NON-NLS-2$
try {
GreetingService service = new GreetingService();
GreetingArgument argument = new GreetingArgument();
argument.name = "Bob"; //$NON-NLS-1$
GreetingResult greetingResult = getServiceHandler().doService(certificate, service, argument);
assertThat(greetingResult.getGreeting(), equalTo("Hello Bob. Nice to meet you!")); //$NON-NLS-1$
} finally {
runtimeMock.getPrivilegeHandler().invalidateSession(certificate);
}
}
}

View File

@ -0,0 +1,127 @@
/*
* 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.test;
import static org.junit.Assert.assertEquals;
import java.io.File;
import java.io.FilenameFilter;
import li.strolch.runtime.StrolchConstants;
import li.strolch.service.XmlExportModelArgument;
import li.strolch.service.XmlExportModelService;
import li.strolch.service.XmlImportModelArgument;
import li.strolch.service.XmlImportModelService;
import li.strolch.service.api.ServiceResult;
import li.strolch.service.api.ServiceResultState;
import li.strolch.testbase.runtime.RuntimeMock;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import ch.eitchnet.privilege.model.Certificate;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*/
public class XmlExportServiceTest {
private static final String RUNTIME_PATH = "target/transienttest/"; //$NON-NLS-1$
private static final String CONFIG_SRC = "src/test/resources/transienttest"; //$NON-NLS-1$
protected static RuntimeMock runtimeMock;
private static Certificate certificate;
@BeforeClass
public static void beforeClass() {
File rootPath = new File(RUNTIME_PATH);
File configSrc = new File(CONFIG_SRC);
runtimeMock = new RuntimeMock();
runtimeMock.mockRuntime(rootPath, configSrc);
runtimeMock.startContainer();
certificate = runtimeMock.getPrivilegeHandler().authenticate("admin", "admin".getBytes());
}
@AfterClass
public static void afterClass() {
runtimeMock.destroyRuntime();
}
@Test
public void shouldExportToXmlSingleFile() {
XmlExportModelService service = new XmlExportModelService();
XmlExportModelArgument arg = new XmlExportModelArgument();
arg.modelFileName = "TestExportSingle.xml";
arg.multiFile = false;
ServiceResult result = runtimeMock.getServiceHandler().doService(certificate, service, arg);
RuntimeMock.assertServiceResult(ServiceResultState.SUCCESS, ServiceResult.class, result);
assertNumberOfFilesCreated(arg.modelFileName.split("\\.")[0], 1);
importModel(arg.modelFileName);
}
@Test
public void shouldExportToXmlMultiFile() {
XmlExportModelService service = new XmlExportModelService();
XmlExportModelArgument arg = new XmlExportModelArgument();
arg.modelFileName = "TestExportMulti.xml";
arg.multiFile = true;
ServiceResult result = runtimeMock.getServiceHandler().doService(certificate, service, arg);
RuntimeMock.assertServiceResult(ServiceResultState.SUCCESS, ServiceResult.class, result);
assertNumberOfFilesCreated(arg.modelFileName.split("\\.")[0], 6);
importModel(arg.modelFileName);
}
@Test
public void shouldExportToXmlMultiFileOnlyResourceTemplates() {
XmlExportModelService service = new XmlExportModelService();
XmlExportModelArgument arg = new XmlExportModelArgument();
arg.modelFileName = "TestExportOnlyResTemplates.xml";
arg.doOrders = false;
arg.resourceTypes.add(StrolchConstants.TEMPLATE);
arg.multiFile = true;
ServiceResult result = runtimeMock.getServiceHandler().doService(certificate, service, arg);
RuntimeMock.assertServiceResult(ServiceResultState.SUCCESS, ServiceResult.class, result);
assertNumberOfFilesCreated(arg.modelFileName.split("\\.")[0], 2);
importModel(arg.modelFileName);
}
private void importModel(String modelFileName) {
XmlImportModelService importService = new XmlImportModelService();
XmlImportModelArgument importArgument = new XmlImportModelArgument();
importArgument.modelFileName = modelFileName;
ServiceResult result = runtimeMock.getServiceHandler().doService(certificate, importService, importArgument);
RuntimeMock.assertServiceResult(ServiceResultState.SUCCESS, ServiceResult.class, result);
}
private void assertNumberOfFilesCreated(final String modelFileName, int nrOfExpectedFiles) {
File dataPath = new File(RUNTIME_PATH, "data");
String[] list = dataPath.list(new FilenameFilter() {
@Override
public boolean accept(File dir, String name) {
return name.startsWith(modelFileName);
}
});
assertEquals(nrOfExpectedFiles, list.length);
}
}

View File

@ -0,0 +1,43 @@
/*
* 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.test.model;
import li.strolch.service.api.ServiceResult;
import li.strolch.service.api.ServiceResultState;
public class GreetingResult extends ServiceResult {
private static final long serialVersionUID = 1L;
private String greeting;
public GreetingResult() {
super(ServiceResultState.SUCCESS);
}
/**
* @return the greeting
*/
public String getGreeting() {
return this.greeting;
}
/**
* @param greeting
* the greeting to set
*/
public void setGreeting(String greeting) {
this.greeting = greeting;
}
}

View File

@ -0,0 +1,53 @@
/*
* 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.test.model;
import java.text.MessageFormat;
import li.strolch.service.api.AbstractService;
import li.strolch.service.api.ServiceArgument;
import li.strolch.service.test.model.GreetingService.GreetingArgument;
import ch.eitchnet.utils.helper.StringHelper;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*
*/
public class GreetingService extends AbstractService<GreetingArgument, GreetingResult> {
private static final long serialVersionUID = 1L;
@Override
protected GreetingResult internalDoService(GreetingArgument argument) {
if (StringHelper.isEmpty(argument.name))
throw new IllegalArgumentException("The name must always be set!"); //$NON-NLS-1$
GreetingResult greetingResult = new GreetingResult();
String greeting = MessageFormat.format("Hello {0}. Nice to meet you!", argument.name); //$NON-NLS-1$
greetingResult.setGreeting(greeting);
return greetingResult;
}
@Override
protected GreetingResult getResultInstance() {
return new GreetingResult();
}
public static class GreetingArgument extends ServiceArgument {
private static final long serialVersionUID = 1L;
public String name;
}
}

View File

@ -0,0 +1,38 @@
/*
* 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.test.model;
import li.strolch.service.api.AbstractService;
import li.strolch.service.api.ServiceArgument;
import li.strolch.service.api.ServiceResult;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*
*/
public class TestService extends AbstractService<ServiceArgument, ServiceResult> {
private static final long serialVersionUID = 1L;
@Override
protected ServiceResult getResultInstance() {
return new ServiceResult();
}
@Override
protected ServiceResult internalDoService(ServiceArgument argument) {
return ServiceResult.success();
}
}

View File

@ -0,0 +1,43 @@
/*
* 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.test.parameter;
import li.strolch.model.Locator;
import li.strolch.model.parameter.FloatParameter;
import li.strolch.service.parameter.AddParameterService;
import li.strolch.service.parameter.AddParameterService.AddParameterArg;
import li.strolch.service.test.AbstractRealmServiceTest;
import org.junit.Test;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*/
public class AddParameterServiceTest extends AbstractRealmServiceTest {
@Test
public void runTest() {
AddParameterArg arg = new AddParameterArg();
arg.locator = Locator.valueOf("Resource/Ball/yellow/Bag/parameters");
FloatParameter parameter = new FloatParameter("diameter", "Diameter", 22.0);
parameter.setInterpretation("Dimension");
parameter.setUom("cm");
arg.parameter = parameter;
runServiceInAllRealmTypes(AddParameterService.class, arg);
}
}

View File

@ -0,0 +1,38 @@
/*
* 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.test.parameter;
import li.strolch.model.Locator;
import li.strolch.service.parameter.RemoveParameterService;
import li.strolch.service.parameter.RemoveParameterService.RemoveParameterArg;
import li.strolch.service.test.AbstractRealmServiceTest;
import org.junit.Test;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*/
public class RemoveParameterServiceTest extends AbstractRealmServiceTest {
@Test
public void runTest() {
RemoveParameterArg arg = new RemoveParameterArg();
arg.locator = Locator.valueOf("Resource/Ball/yellow/Bag/parameters/owner");
runServiceInAllRealmTypes(RemoveParameterService.class, arg);
}
}

View File

@ -0,0 +1,44 @@
/*
* 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.test.parameter;
import li.strolch.model.Locator;
import li.strolch.service.parameter.SetParameterService;
import li.strolch.service.parameter.SetParameterService.SetParameterArg;
import li.strolch.service.test.AbstractRealmServiceTest;
import org.junit.Test;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*/
public class SetParameterServiceTest extends AbstractRealmServiceTest {
@Test
public void runTest() {
SetParameterArg arg = new SetParameterArg();
arg.locator = Locator.valueOf("Resource/Ball/yellow/Bag/parameters/owner");
arg.name = "The Owner";
arg.interpretation = "Changing The Interpretation";
arg.uom = "Owners";
arg.hidden = true;
arg.index = 99;
arg.valueAsString = "someotherdude";
runServiceInAllRealmTypes(SetParameterService.class, arg);
}
}

View File

@ -0,0 +1,30 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE log4j:configuration PUBLIC
"-//APACHE//DTD LOG4J 1.2//EN" "http://logging.apache.org/log4j/1.2/apidocs/org/apache/log4j/xml/doc-files/log4j.dtd">
<log4j:configuration debug="false" xmlns:log4j='http://jakarta.apache.org/log4j/'>
<appender name="CONSOLE" class="org.apache.log4j.ConsoleAppender">
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d %5p [%t] %C{1} %M - %m%n" />
</layout>
</appender>
<appender name="FILE" class="org.apache.log4j.FileAppender">
<param name="File" value="sample.log"/>
<param name="BufferedIO" value="true" />
<param name="Append" value="true" />
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d %5p [%t] %C{1} %M - %m%n" />
</layout>
</appender>
<logger name="ch.eitchnet">
<level value="info" />
</logger>
<root>
<priority value="info" />
<appender-ref ref="CONSOLE" />
<!-- appender-ref ref="FILE" / -->
</root>
</log4j:configuration>

View File

@ -0,0 +1,30 @@
<?xml version="1.0" encoding="UTF-8"?>
<Privilege>
<Container>
<Parameters>
<!-- parameters for the container itself -->
<Parameter name="autoPersistOnPasswordChange" value="true" />
</Parameters>
<EncryptionHandler class="ch.eitchnet.privilege.handler.DefaultEncryptionHandler">
<Parameters>
<Parameter name="hashAlgorithm" value="SHA-256" />
</Parameters>
</EncryptionHandler>
<PersistenceHandler class="ch.eitchnet.privilege.handler.XmlPersistenceHandler">
<Parameters>
<Parameter name="basePath" value="target/strolchRuntime/config" />
<Parameter name="modelXmlFile" value="PrivilegeModel.xml" />
</Parameters>
</PersistenceHandler>
</Container>
<Policies>
<Policy name="DefaultPrivilege" class="ch.eitchnet.privilege.policy.DefaultPrivilege" />
</Policies>
</Privilege>

View File

@ -0,0 +1,39 @@
<?xml version="1.0" encoding="UTF-8"?>
<UsersAndRoles>
<Users>
<User userId="1" username="agent">
<State>SYSTEM</State>
<Roles>
<Role>agent</Role>
</Roles>
</User>
<User userId="2" username="test" password="9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08">
<Firstname>Application</Firstname>
<Lastname>Administrator</Lastname>
<State>ENABLED</State>
<Locale>en_GB</Locale>
<Roles>
<Role>PrivilegeAdmin</Role>
<Role>AppUser</Role>
</Roles>
</User>
</Users>
<Roles>
<Role name="PrivilegeAdmin" />
<Role name="agent">
<Privilege name="li.strolch.agent.impl.StartRealms" policy="DefaultPrivilege">
<AllAllowed>true</AllAllowed>
</Privilege>
</Role>
<Role name="AppUser">
<Privilege name="li.strolch.service.api.Service" policy="DefaultPrivilege">
<AllAllowed>true</AllAllowed>
</Privilege>
<Privilege name="li.strolch.model.query.StrolchQuery" policy="DefaultPrivilege">
<AllAllowed>true</AllAllowed>
</Privilege>
</Role>
</Roles>
</UsersAndRoles>

View File

@ -0,0 +1,70 @@
<?xml version="1.0" encoding="UTF-8"?>
<StrolchConfiguration>
<env id="dev">
<Runtime>
<applicationName>StrolchRuntimeTest</applicationName>
<Properties>
<verbose>true</verbose>
</Properties>
</Runtime>
<Component>
<name>PrivilegeHandler</name>
<api>li.strolch.runtime.privilege.PrivilegeHandler</api>
<impl>li.strolch.runtime.privilege.DefaultStrolchPrivilegeHandler</impl>
<Properties>
<privilegeConfigFile>PrivilegeConfig.xml</privilegeConfigFile>
</Properties>
</Component>
<Component>
<name>RealmHandler</name>
<api>li.strolch.agent.api.RealmHandler</api>
<impl>li.strolch.agent.impl.DefaultRealmHandler</impl>
<depends>PrivilegeHandler</depends>
<depends>PersistenceHandler</depends>
<Properties>
<realms>svcTransient, svcCached, svcTransactional</realms>
<tryLockTimeUnit.svcTransient>SECONDS</tryLockTimeUnit.svcTransient>
<tryLockTime.svcTransient>1</tryLockTime.svcTransient>
<dataStoreMode.svcTransient>TRANSIENT</dataStoreMode.svcTransient>
<dataStoreFile.svcTransient>StrolchModel.xml</dataStoreFile.svcTransient>
<tryLockTimeUnit.svcCached>SECONDS</tryLockTimeUnit.svcCached>
<tryLockTime.svcCached>1</tryLockTime.svcCached>
<dataStoreMode.svcCached>CACHED</dataStoreMode.svcCached>
<tryLockTimeUnit.svcTransactional>SECONDS</tryLockTimeUnit.svcTransactional>
<tryLockTime.svcTransactional>1</tryLockTime.svcTransactional>
<dataStoreMode.svcTransactional>TRANSACTIONAL</dataStoreMode.svcTransactional>
</Properties>
</Component>
<Component>
<name>PersistenceHandler</name>
<api>li.strolch.persistence.api.PersistenceHandler</api>
<impl>li.strolch.persistence.postgresql.PostgreSqlPersistenceHandler</impl>
<Properties>
<allowSchemaCreation>true</allowSchemaCreation>
<allowSchemaDrop>true</allowSchemaDrop>
<db.url.svcCached>jdbc:postgresql://localhost/cacheduserdb</db.url.svcCached>
<db.username.svcCached>cacheduser</db.username.svcCached>
<db.password.svcCached>test</db.password.svcCached>
<db.url.svcTransactional>jdbc:postgresql://localhost/transactionaluserdb</db.url.svcTransactional>
<db.username.svcTransactional>transactionaluser</db.username.svcTransactional>
<db.password.svcTransactional>test</db.password.svcTransactional>
</Properties>
</Component>
<Component>
<name>ServiceHandler</name>
<api>li.strolch.service.api.ServiceHandler</api>
<impl>li.strolch.service.api.DefaultServiceHandler</impl>
<Properties>
<verbose>true</verbose>
</Properties>
</Component>
</env>
</StrolchConfiguration>

View File

@ -0,0 +1,34 @@
<?xml version="1.0" encoding="UTF-8"?>
<StrolchModel>
<Resource Id="salutations" Name="Salutations" Type="Enumeration">
<ParameterBag Id="en" Name="Salutations" Type="Enumeration">
<Parameter Id="mr" Name="Mr" Type="String" Value="Mr" />
<Parameter Id="mrs" Name="Mrs" Type="String" Value="Mrs" />
<Parameter Id="ms" Name="Ms" Type="String" Value="Ms" />
</ParameterBag>
</Resource>
<Resource Id="sex" Name="Sex" Type="Enumeration">
<ParameterBag Id="en" Name="Sex" Type="Enumeration">
<Parameter Id="male" Name="Male" Type="String" Value="male" />
<Parameter Id="female" Name="Female" Type="String" Value="female" />
<Parameter Id="both" Name="Both" Type="String" Value="both" />
</ParameterBag>
</Resource>
<Resource Id="religions" Name="Religions" Type="Enumeration">
<ParameterBag Id="en" Name="Religions" Type="Enumeration">
<Parameter Id="Roman Catholic" Name="Roman Catholic" Type="String" Value="Roman Catholic" />
<Parameter Id="Protestant" Name="Protestant" Type="String" Value="Protestant" />
<Parameter Id="Orthodox" Name="Orthodox" Type="String" Value="Orthodox" />
<Parameter Id="Christian" Name="Anglican" Type="String" Value="Anglican" />
<Parameter Id="Muslim" Name="Muslim" Type="String" Value="Muslim" />
<Parameter Id="Hindu" Name="Hindu" Type="String" Value="Hindu" />
<Parameter Id="Buddhist" Name="Buddhist" Type="String" Value="Buddhist" />
<Parameter Id="Jewish" Name="Jewish" Type="String" Value="Jewish" />
<Parameter Id="Atheist" Name="Atheist" Type="String" Value="Atheist" />
</ParameterBag>
</Resource>
</StrolchModel>

View File

@ -0,0 +1,60 @@
<?xml version="1.0" encoding="utf-8" standalone="no"?>
<StrolchModel>
<Order Id="myCarOrder" Name="Car Production Order" Type="ProductionOrder" Date="2013-11-20T07:42:57.699+01:00" State="CREATED">
<ParameterBag Id="@bag01" Name="Test Bag" Type="TestBag">
<Parameter Id="@param7" Name="StringList Param" Type="StringList" Value="Hello;World" />
<Parameter Id="@param6" Name="Date Param" Type="Date" Value="2012-11-30T18:12:05.628+01:00" />
<Parameter Id="@param5" Name="String Param" Type="String" Value="Strolch" />
<Parameter Id="@param4" Name="Long Param" Type="Long" Value="4453234566" />
<Parameter Id="@param3" Name="Integer Param" Type="Integer" Value="77" />
<Parameter Id="@param2" Name="Float Param" Type="Float" Value="44.3" />
<Parameter Id="@param1" Name="Boolean Param" Type="Boolean" Value="true" />
</ParameterBag>
</Order>
<Order Id="MyTestOrder" Name="Test Name" Type="TestType" Date="2013-11-20T07:42:57.699+01:00" State="CREATED">
<ParameterBag Id="@bag01" Name="Test Bag" Type="TestBag">
<Parameter Id="@param7" Name="StringList Param" Type="StringList" Value="Hello;World" />
<Parameter Id="@param6" Name="Date Param" Type="Date" Value="2012-11-30T18:12:05.628+01:00" />
<Parameter Id="@param5" Name="String Param" Type="String" Value="Strolch" />
<Parameter Id="@param4" Name="Long Param" Type="Long" Value="4453234566" />
<Parameter Id="@param3" Name="Integer Param" Type="Integer" Value="77" />
<Parameter Id="@param2" Name="Float Param" Type="Float" Value="44.3" />
<Parameter Id="@param1" Name="Boolean Param" Type="Boolean" Value="true" />
</ParameterBag>
</Order>
<Order Id="@1" Name="Test Name" Type="TestType" Date="2013-11-20T07:42:57.699+01:00" State="CREATED">
<ParameterBag Id="@bag01" Name="Test Bag" Type="TestBag">
<Parameter Id="@param7" Name="StringList Param" Type="StringList" Value="Hello;World" />
<Parameter Id="@param6" Name="Date Param" Type="Date" Value="2012-11-30T18:12:05.628+01:00" />
<Parameter Id="@param5" Name="String Param" Type="String" Value="Strolch" />
<Parameter Id="@param4" Name="Long Param" Type="Long" Value="4453234566" />
<Parameter Id="@param3" Name="Integer Param" Type="Integer" Value="77" />
<Parameter Id="@param2" Name="Float Param" Type="Float" Value="44.3" />
<Parameter Id="@param1" Name="Boolean Param" Type="Boolean" Value="true" />
</ParameterBag>
</Order>
<Order Id="@2" Name="Test Name" Type="TestType" Date="2013-11-20T07:42:57.699+01:00" State="CREATED">
<ParameterBag Id="@bag01" Name="Test Bag" Type="TestBag">
<Parameter Id="@param7" Name="StringList Param" Type="StringList" Value="Hello;World" />
<Parameter Id="@param6" Name="Date Param" Type="Date" Value="2012-11-30T18:12:05.628+01:00" />
<Parameter Id="@param5" Name="String Param" Type="String" Value="Strolch" />
<Parameter Id="@param4" Name="Long Param" Type="Long" Value="4453234566" />
<Parameter Id="@param3" Name="Integer Param" Type="Integer" Value="77" />
<Parameter Id="@param2" Name="Float Param" Type="Float" Value="44.3" />
<Parameter Id="@param1" Name="Boolean Param" Type="Boolean" Value="true" />
</ParameterBag>
</Order>
<Order Id="@3" Name="Test Name" Type="TestType" Date="2013-11-20T07:42:57.699+01:00" State="CREATED">
<ParameterBag Id="@bag01" Name="Test Bag" Type="TestBag">
<Parameter Id="@param7" Name="StringList Param" Type="StringList" Value="Hello;World" />
<Parameter Id="@param6" Name="Date Param" Type="Date" Value="2012-11-30T18:12:05.628+01:00" />
<Parameter Id="@param5" Name="String Param" Type="String" Value="Strolch" />
<Parameter Id="@param4" Name="Long Param" Type="Long" Value="4453234566" />
<Parameter Id="@param3" Name="Integer Param" Type="Integer" Value="77" />
<Parameter Id="@param2" Name="Float Param" Type="Float" Value="44.3" />
<Parameter Id="@param1" Name="Boolean Param" Type="Boolean" Value="true" />
</ParameterBag>
<ParameterBag Id="@bag02" Name="Test Bag" Type="TestBag" />
</Order>
<Order Id="@4" Name="Test Name" Type="Something" Date="2013-11-20T07:42:57.699+01:00" State="CREATED" />
</StrolchModel>

View File

@ -0,0 +1,31 @@
<?xml version="1.0" encoding="utf-8" standalone="no"?>
<StrolchModel>
<Resource Id="yellow" Name="Yellow Ball" Type="Ball">
<ParameterBag Id="parameters" Name="Parameters" Type="Parameters">
<Parameter Id="owner" Name="Owner" Type="String" Value="eitch" />
</ParameterBag>
<ParameterBag Id="something" Name="Something" Type="Something" />
<TimedState Id="@state1" Name="State" Type="FloatState" />
<TimedState Id="@state2" Name="State" Type="FloatState">
<Value Time="0" Value="0.0" />
<Value Time="1" Value="1.0" />
<Value Time="2" Value="2.0" />
<Value Time="3" Value="1.0" />
</TimedState>
<TimedState Id="@state3" Name="State" Type="IntegerState" />
<TimedState Id="@state4" Name="State" Type="IntegerState">
<Value Time="0" Value="0" />
<Value Time="1" Value="1" />
<Value Time="2" Value="2" />
<Value Time="3" Value="1" />
</TimedState>
<TimedState Id="@state5" Name="State" Type="BooleanState" />
<TimedState Id="@state6" Name="State" Type="BooleanState">
<Value Time="0" Value="false" />
<Value Time="1" Value="true" />
<Value Time="2" Value="false" />
<Value Time="3" Value="true" />
</TimedState>
</Resource>
<Resource Id="something" Name="Something" Type="Something" />
</StrolchModel>

View File

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<StrolchModel>
<IncludeFile file="Enums.xml" />
<IncludeFile file="Resources.xml" />
<IncludeFile file="Orders.xml" />
</StrolchModel>

View File

@ -0,0 +1,30 @@
<?xml version="1.0" encoding="UTF-8"?>
<Privilege>
<Container>
<Parameters>
<!-- parameters for the container itself -->
<Parameter name="autoPersistOnPasswordChange" value="true" />
</Parameters>
<EncryptionHandler class="ch.eitchnet.privilege.handler.DefaultEncryptionHandler">
<Parameters>
<Parameter name="hashAlgorithm" value="SHA-256" />
</Parameters>
</EncryptionHandler>
<PersistenceHandler class="ch.eitchnet.privilege.handler.XmlPersistenceHandler">
<Parameters>
<Parameter name="basePath" value="target/strolchRuntime/config" />
<Parameter name="modelXmlFile" value="PrivilegeModel.xml" />
</Parameters>
</PersistenceHandler>
</Container>
<Policies>
<Policy name="DefaultPrivilege" class="ch.eitchnet.privilege.policy.DefaultPrivilege" />
</Policies>
</Privilege>

View File

@ -0,0 +1,39 @@
<?xml version="1.0" encoding="UTF-8"?>
<UsersAndRoles>
<Users>
<User userId="1" username="agent">
<State>SYSTEM</State>
<Roles>
<Role>agent</Role>
</Roles>
</User>
<User userId="2" username="admin" password="8c6976e5b5410415bde908bd4dee15dfb167a9c873fc4bb8a81f6f2ab448a918">
<Firstname>Application</Firstname>
<Lastname>Administrator</Lastname>
<State>ENABLED</State>
<Locale>en_GB</Locale>
<Roles>
<Role>PrivilegeAdmin</Role>
<Role>AppUser</Role>
</Roles>
</User>
</Users>
<Roles>
<Role name="PrivilegeAdmin" />
<Role name="agent">
<Privilege name="li.strolch.agent.impl.StartRealms" policy="DefaultPrivilege">
<AllAllowed>true</AllAllowed>
</Privilege>
</Role>
<Role name="AppUser">
<Privilege name="li.strolch.service.api.Service" policy="DefaultPrivilege">
<AllAllowed>true</AllAllowed>
</Privilege>
<Privilege name="li.strolch.model.query.StrolchQuery" policy="DefaultPrivilege">
<AllAllowed>true</AllAllowed>
</Privilege>
</Role>
</Roles>
</UsersAndRoles>

View File

@ -0,0 +1,39 @@
<?xml version="1.0" encoding="UTF-8"?>
<StrolchConfiguration>
<env id="dev">
<Runtime>
<applicationName>StrolchRuntimeTest</applicationName>
<Properties>
<verbose>true</verbose>
</Properties>
</Runtime>
<Component>
<name>PrivilegeHandler</name>
<api>li.strolch.runtime.privilege.PrivilegeHandler</api>
<impl>li.strolch.runtime.privilege.DefaultStrolchPrivilegeHandler</impl>
<Properties>
<privilegeConfigFile>PrivilegeConfig.xml</privilegeConfigFile>
</Properties>
</Component>
<Component>
<name>RealmHandler</name>
<api>li.strolch.agent.api.RealmHandler</api>
<impl>li.strolch.agent.impl.DefaultRealmHandler</impl>
<depends>PrivilegeHandler</depends>
<Properties>
<tryLockTimeUnit>SECONDS</tryLockTimeUnit>
<tryLockTime>1</tryLockTime>
<dataStoreMode>TRANSIENT</dataStoreMode>
<dataStoreFile>StrolchModel.xml</dataStoreFile>
</Properties>
</Component>
<Component>
<name>ServiceHandler</name>
<api>li.strolch.service.api.ServiceHandler</api>
<impl>li.strolch.service.api.DefaultServiceHandler</impl>
<Properties>
<verbose>true</verbose>
</Properties>
</Component>
</env>
</StrolchConfiguration>

View File

@ -0,0 +1,34 @@
<?xml version="1.0" encoding="UTF-8"?>
<StrolchModel>
<Resource Id="salutations" Name="Salutations" Type="Enumeration">
<ParameterBag Id="en" Name="Salutations" Type="Enumeration">
<Parameter Id="mr" Name="Mr" Type="String" Value="Mr" />
<Parameter Id="mrs" Name="Mrs" Type="String" Value="Mrs" />
<Parameter Id="ms" Name="Ms" Type="String" Value="Ms" />
</ParameterBag>
</Resource>
<Resource Id="sex" Name="Sex" Type="Enumeration">
<ParameterBag Id="en" Name="Sex" Type="Enumeration">
<Parameter Id="male" Name="Male" Type="String" Value="male" />
<Parameter Id="female" Name="Female" Type="String" Value="female" />
<Parameter Id="both" Name="Both" Type="String" Value="both" />
</ParameterBag>
</Resource>
<Resource Id="religions" Name="Religions" Type="Enumeration">
<ParameterBag Id="en" Name="Religions" Type="Enumeration">
<Parameter Id="Roman Catholic" Name="Roman Catholic" Type="String" Value="Roman Catholic" />
<Parameter Id="Protestant" Name="Protestant" Type="String" Value="Protestant" />
<Parameter Id="Orthodox" Name="Orthodox" Type="String" Value="Orthodox" />
<Parameter Id="Christian" Name="Anglican" Type="String" Value="Anglican" />
<Parameter Id="Muslim" Name="Muslim" Type="String" Value="Muslim" />
<Parameter Id="Hindu" Name="Hindu" Type="String" Value="Hindu" />
<Parameter Id="Buddhist" Name="Buddhist" Type="String" Value="Buddhist" />
<Parameter Id="Jewish" Name="Jewish" Type="String" Value="Jewish" />
<Parameter Id="Atheist" Name="Atheist" Type="String" Value="Atheist" />
</ParameterBag>
</Resource>
</StrolchModel>

Some files were not shown because too many files have changed in this diff Show More