diff --git a/li.strolch.service/.gitignore b/li.strolch.service/.gitignore
new file mode 100644
index 000000000..b284c6517
--- /dev/null
+++ b/li.strolch.service/.gitignore
@@ -0,0 +1,4 @@
+target/
+.project
+.settings
+.classpath
diff --git a/li.strolch.service/LICENSE b/li.strolch.service/LICENSE
new file mode 100644
index 000000000..d64569567
--- /dev/null
+++ b/li.strolch.service/LICENSE
@@ -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.
diff --git a/li.strolch.service/README.md b/li.strolch.service/README.md
new file mode 100644
index 000000000..fd16544bf
--- /dev/null
+++ b/li.strolch.service/README.md
@@ -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;
diff --git a/li.strolch.service/pom.xml b/li.strolch.service/pom.xml
new file mode 100644
index 000000000..af7876f4f
--- /dev/null
+++ b/li.strolch.service/pom.xml
@@ -0,0 +1,107 @@
+
+ 4.0.0
+
+
+ li.strolch
+ li.strolch.parent
+ 1.0.0-SNAPSHOT
+ ../li.strolch.parent/pom.xml
+
+
+ li.strolch.service
+
+ li.strolch.service
+ Service API for Strolch
+
+ https://github.com/eitchnet/li.strolch.service
+
+ 2011
+
+
+ Github Issues
+ https://github.com/eitchnet/li.strolch.service/issues
+
+
+
+ scm:git:https://github.com/eitchnet/li.strolch.service.git
+ scm:git:git@github.com:eitch/li.strolch.service.git
+ https://github.com/eitchnet/li.strolch.service
+
+
+
+
+
+ li.strolch
+ li.strolch.model
+
+
+ li.strolch
+ li.strolch.agent
+
+
+
+ ch.eitchnet
+ ch.eitchnet.xmlpers
+
+
+ ch.eitchnet
+ ch.eitchnet.privilege
+
+
+
+
+ li.strolch
+ li.strolch.testbase
+
+
+ li.strolch
+ li.strolch.persistence.postgresql
+ test
+
+
+
+
+
+
+
+ src/main/resources
+ true
+
+ **/componentVersion.properties
+
+
+
+
+
+
+ org.codehaus.mojo
+ buildnumber-maven-plugin
+
+
+ org.apache.maven.plugins
+ maven-eclipse-plugin
+
+
+
+ org.apache.maven.plugins
+ maven-compiler-plugin
+
+
+
+ org.apache.maven.plugins
+ maven-source-plugin
+
+
+
+ org.apache.maven.plugins
+ maven-jar-plugin
+
+
+
+ org.apache.maven.plugins
+ maven-site-plugin
+
+
+
+
\ No newline at end of file
diff --git a/li.strolch.service/src/main/java/li/strolch/command/AddOrderCollectionCommand.java b/li.strolch.service/src/main/java/li/strolch/command/AddOrderCollectionCommand.java
new file mode 100644
index 000000000..b8cda78ed
--- /dev/null
+++ b/li.strolch.service/src/main/java/li/strolch/command/AddOrderCollectionCommand.java
@@ -0,0 +1,85 @@
+/*
+ * Copyright 2013 Robert von Burg
+ *
+ * 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
+ */
+public class AddOrderCollectionCommand extends Command {
+
+ private List orders;
+
+ /**
+ * @param tx
+ */
+ public AddOrderCollectionCommand(ComponentContainer container, StrolchTransaction tx) {
+ super(container, tx);
+ }
+
+ /**
+ * @param orders
+ * the orders to set
+ */
+ public void setOrders(List 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);
+ }
+ }
+ }
+ }
+}
diff --git a/li.strolch.service/src/main/java/li/strolch/command/AddOrderCommand.java b/li.strolch.service/src/main/java/li/strolch/command/AddOrderCommand.java
new file mode 100644
index 000000000..96a12dcde
--- /dev/null
+++ b/li.strolch.service/src/main/java/li/strolch/command/AddOrderCommand.java
@@ -0,0 +1,77 @@
+/*
+ * Copyright 2013 Robert von Burg
+ *
+ * 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
+ */
+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);
+ }
+ }
+}
diff --git a/li.strolch.service/src/main/java/li/strolch/command/AddResourceCollectionCommand.java b/li.strolch.service/src/main/java/li/strolch/command/AddResourceCollectionCommand.java
new file mode 100644
index 000000000..e3c15b5fa
--- /dev/null
+++ b/li.strolch.service/src/main/java/li/strolch/command/AddResourceCollectionCommand.java
@@ -0,0 +1,85 @@
+/*
+ * Copyright 2013 Robert von Burg
+ *
+ * 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
+ */
+public class AddResourceCollectionCommand extends Command {
+
+ private List resources;
+
+ /**
+ * @param tx
+ */
+ public AddResourceCollectionCommand(ComponentContainer container, StrolchTransaction tx) {
+ super(container, tx);
+ }
+
+ /**
+ * @param resources
+ * the resources to set
+ */
+ public void setResources(List 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);
+ }
+ }
+ }
+ }
+}
diff --git a/li.strolch.service/src/main/java/li/strolch/command/AddResourceCommand.java b/li.strolch.service/src/main/java/li/strolch/command/AddResourceCommand.java
new file mode 100644
index 000000000..efed9e001
--- /dev/null
+++ b/li.strolch.service/src/main/java/li/strolch/command/AddResourceCommand.java
@@ -0,0 +1,77 @@
+/*
+ * Copyright 2013 Robert von Burg
+ *
+ * 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
+ */
+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);
+ }
+ }
+}
diff --git a/li.strolch.service/src/main/java/li/strolch/command/ClearModelCommand.java b/li.strolch.service/src/main/java/li/strolch/command/ClearModelCommand.java
new file mode 100644
index 000000000..f2d935c9b
--- /dev/null
+++ b/li.strolch.service/src/main/java/li/strolch/command/ClearModelCommand.java
@@ -0,0 +1,95 @@
+/*
+ * Copyright 2013 Robert von Burg
+ *
+ * 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
+ */
+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;
+ }
+}
diff --git a/li.strolch.service/src/main/java/li/strolch/command/RemoveOrderCollectionCommand.java b/li.strolch.service/src/main/java/li/strolch/command/RemoveOrderCollectionCommand.java
new file mode 100644
index 000000000..fd0b73b9e
--- /dev/null
+++ b/li.strolch.service/src/main/java/li/strolch/command/RemoveOrderCollectionCommand.java
@@ -0,0 +1,86 @@
+/*
+ * Copyright 2013 Robert von Burg
+ *
+ * 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
+ */
+public class RemoveOrderCollectionCommand extends Command {
+
+ private List orders;
+
+ /**
+ * @param tx
+ */
+ public RemoveOrderCollectionCommand(ComponentContainer container, StrolchTransaction tx) {
+ super(container, tx);
+ }
+
+ /**
+ * @param orders
+ * the orders to set
+ */
+ public void setOrders(List 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);
+ }
+ }
+ }
+ }
+}
diff --git a/li.strolch.service/src/main/java/li/strolch/command/RemoveOrderCommand.java b/li.strolch.service/src/main/java/li/strolch/command/RemoveOrderCommand.java
new file mode 100644
index 000000000..908aa7958
--- /dev/null
+++ b/li.strolch.service/src/main/java/li/strolch/command/RemoveOrderCommand.java
@@ -0,0 +1,78 @@
+/*
+ * Copyright 2013 Robert von Burg
+ *
+ * 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
+ */
+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);
+ }
+ }
+}
diff --git a/li.strolch.service/src/main/java/li/strolch/command/RemoveResourceCollectionCommand.java b/li.strolch.service/src/main/java/li/strolch/command/RemoveResourceCollectionCommand.java
new file mode 100644
index 000000000..438746af5
--- /dev/null
+++ b/li.strolch.service/src/main/java/li/strolch/command/RemoveResourceCollectionCommand.java
@@ -0,0 +1,86 @@
+/*
+ * Copyright 2013 Robert von Burg
+ *
+ * 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
+ */
+public class RemoveResourceCollectionCommand extends Command {
+
+ private List resources;
+
+ /**
+ * @param tx
+ */
+ public RemoveResourceCollectionCommand(ComponentContainer container, StrolchTransaction tx) {
+ super(container, tx);
+ }
+
+ /**
+ * @param resources
+ * the resources to set
+ */
+ public void setResources(List 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);
+ }
+ }
+ }
+ }
+}
diff --git a/li.strolch.service/src/main/java/li/strolch/command/RemoveResourceCommand.java b/li.strolch.service/src/main/java/li/strolch/command/RemoveResourceCommand.java
new file mode 100644
index 000000000..1a0e5b2b4
--- /dev/null
+++ b/li.strolch.service/src/main/java/li/strolch/command/RemoveResourceCommand.java
@@ -0,0 +1,78 @@
+/*
+ * Copyright 2013 Robert von Burg
+ *
+ * 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
+ */
+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);
+ }
+ }
+}
diff --git a/li.strolch.service/src/main/java/li/strolch/command/UpdateOrderCollectionCommand.java b/li.strolch.service/src/main/java/li/strolch/command/UpdateOrderCollectionCommand.java
new file mode 100644
index 000000000..693af78dd
--- /dev/null
+++ b/li.strolch.service/src/main/java/li/strolch/command/UpdateOrderCollectionCommand.java
@@ -0,0 +1,83 @@
+/*
+ * Copyright 2013 Robert von Burg
+ *
+ * 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
+ */
+public class UpdateOrderCollectionCommand extends Command {
+
+ private List orders;
+ private List replacedElements;
+
+ /**
+ * @param tx
+ */
+ public UpdateOrderCollectionCommand(ComponentContainer container, StrolchTransaction tx) {
+ super(container, tx);
+ }
+
+ /**
+ * @param orders
+ * the orders to set
+ */
+ public void setOrders(List 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);
+ }
+ }
+}
diff --git a/li.strolch.service/src/main/java/li/strolch/command/UpdateOrderCommand.java b/li.strolch.service/src/main/java/li/strolch/command/UpdateOrderCommand.java
new file mode 100644
index 000000000..48c81ffd2
--- /dev/null
+++ b/li.strolch.service/src/main/java/li/strolch/command/UpdateOrderCommand.java
@@ -0,0 +1,77 @@
+/*
+ * Copyright 2013 Robert von Burg
+ *
+ * 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
+ */
+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);
+ }
+ }
+}
diff --git a/li.strolch.service/src/main/java/li/strolch/command/UpdateResourceCollectionCommand.java b/li.strolch.service/src/main/java/li/strolch/command/UpdateResourceCollectionCommand.java
new file mode 100644
index 000000000..031ca510c
--- /dev/null
+++ b/li.strolch.service/src/main/java/li/strolch/command/UpdateResourceCollectionCommand.java
@@ -0,0 +1,83 @@
+/*
+ * Copyright 2013 Robert von Burg
+ *
+ * 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
+ */
+public class UpdateResourceCollectionCommand extends Command {
+
+ private List resources;
+ private List replacedElements;
+
+ /**
+ * @param tx
+ */
+ public UpdateResourceCollectionCommand(ComponentContainer container, StrolchTransaction tx) {
+ super(container, tx);
+ }
+
+ /**
+ * @param resources
+ * the resources to set
+ */
+ public void setResources(List 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);
+ }
+ }
+}
diff --git a/li.strolch.service/src/main/java/li/strolch/command/UpdateResourceCommand.java b/li.strolch.service/src/main/java/li/strolch/command/UpdateResourceCommand.java
new file mode 100644
index 000000000..6c3194ee9
--- /dev/null
+++ b/li.strolch.service/src/main/java/li/strolch/command/UpdateResourceCommand.java
@@ -0,0 +1,77 @@
+/*
+ * Copyright 2013 Robert von Burg
+ *
+ * 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
+ */
+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);
+ }
+ }
+}
diff --git a/li.strolch.service/src/main/java/li/strolch/command/XmlExportModelCommand.java b/li.strolch.service/src/main/java/li/strolch/command/XmlExportModelCommand.java
new file mode 100644
index 000000000..7f2408b0c
--- /dev/null
+++ b/li.strolch.service/src/main/java/li/strolch/command/XmlExportModelCommand.java
@@ -0,0 +1,337 @@
+/*
+ * Copyright 2013 Robert von Burg
+ *
+ * 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
+ */
+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 orderTypes;
+ private Set 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 createdFiles = new HashSet<>();
+
+ if (this.doResources) {
+ ResourceMap resourceMap = tx().getResourceMap();
+ Set 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 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 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 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 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 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 orderTypes) {
+ this.orderTypes = orderTypes;
+ }
+
+ /**
+ * @param resourceTypes
+ * the resourceTypes to set
+ */
+ public void setResourceTypes(Set resourceTypes) {
+ this.resourceTypes = resourceTypes;
+ }
+
+ /**
+ * @return the statistics
+ */
+ public ModelStatistics getStatistics() {
+ return this.statistics;
+ }
+
+ /**
+ * @param overwrite
+ */
+ public void setOverwrite(boolean overwrite) {
+ this.overwrite = overwrite;
+ }
+}
diff --git a/li.strolch.service/src/main/java/li/strolch/command/XmlImportModelCommand.java b/li.strolch.service/src/main/java/li/strolch/command/XmlImportModelCommand.java
new file mode 100644
index 000000000..802321513
--- /dev/null
+++ b/li.strolch.service/src/main/java/li/strolch/command/XmlImportModelCommand.java
@@ -0,0 +1,143 @@
+/*
+ * Copyright 2013 Robert von Burg
+ *
+ * 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
+ */
+public class XmlImportModelCommand extends Command {
+
+ // input
+ private File modelFile;
+ private boolean addOrders;
+ private boolean addResources;
+ private boolean updateOrders;
+ private boolean updateResources;
+ private Set orderTypes;
+ private Set 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 orderTypes) {
+ this.orderTypes = orderTypes;
+ }
+
+ /**
+ * @param resourceTypes
+ * the resourceTypes to set
+ */
+ public void setResourceTypes(Set resourceTypes) {
+ this.resourceTypes = resourceTypes;
+ }
+
+ /**
+ * @return the statistics
+ */
+ public ModelStatistics getStatistics() {
+ return this.statistics;
+ }
+}
diff --git a/li.strolch.service/src/main/java/li/strolch/command/parameter/AddParameterCommand.java b/li.strolch.service/src/main/java/li/strolch/command/parameter/AddParameterCommand.java
new file mode 100644
index 000000000..491220c54
--- /dev/null
+++ b/li.strolch.service/src/main/java/li/strolch/command/parameter/AddParameterCommand.java
@@ -0,0 +1,97 @@
+/*
+ * Copyright 2013 Robert von Burg
+ *
+ * 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
+ */
+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);
+ }
+ }
+}
diff --git a/li.strolch.service/src/main/java/li/strolch/command/parameter/RemoveParameterCommand.java b/li.strolch.service/src/main/java/li/strolch/command/parameter/RemoveParameterCommand.java
new file mode 100644
index 000000000..5ce3c0347
--- /dev/null
+++ b/li.strolch.service/src/main/java/li/strolch/command/parameter/RemoveParameterCommand.java
@@ -0,0 +1,97 @@
+/*
+ * Copyright 2013 Robert von Burg
+ *
+ * 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
+ */
+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);
+ }
+ }
+}
diff --git a/li.strolch.service/src/main/java/li/strolch/command/parameter/SetParameterCommand.java b/li.strolch.service/src/main/java/li/strolch/command/parameter/SetParameterCommand.java
new file mode 100644
index 000000000..a40b415f3
--- /dev/null
+++ b/li.strolch.service/src/main/java/li/strolch/command/parameter/SetParameterCommand.java
@@ -0,0 +1,193 @@
+/*
+ * Copyright 2013 Robert von Burg
+ *
+ * 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
+ */
+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);
+ }
+ }
+ }
+}
diff --git a/li.strolch.service/src/main/java/li/strolch/command/visitor/UpdateElementVisitor.java b/li.strolch.service/src/main/java/li/strolch/command/visitor/UpdateElementVisitor.java
new file mode 100644
index 000000000..347f98840
--- /dev/null
+++ b/li.strolch.service/src/main/java/li/strolch/command/visitor/UpdateElementVisitor.java
@@ -0,0 +1,48 @@
+/*
+ * Copyright 2013 Robert von Burg
+ *
+ * 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
+ */
+public class UpdateElementVisitor implements StrolchRootElementVisitor {
+
+ 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);
+ }
+}
diff --git a/li.strolch.service/src/main/java/li/strolch/service/AddOrderCollectionService.java b/li.strolch.service/src/main/java/li/strolch/service/AddOrderCollectionService.java
new file mode 100644
index 000000000..77affbd3e
--- /dev/null
+++ b/li.strolch.service/src/main/java/li/strolch/service/AddOrderCollectionService.java
@@ -0,0 +1,56 @@
+/*
+ * Copyright 2013 Robert von Burg
+ *
+ * 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
+ */
+public class AddOrderCollectionService extends
+ AbstractService {
+
+ 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 orders;
+ }
+}
diff --git a/li.strolch.service/src/main/java/li/strolch/service/AddOrderService.java b/li.strolch.service/src/main/java/li/strolch/service/AddOrderService.java
new file mode 100644
index 000000000..01d82e678
--- /dev/null
+++ b/li.strolch.service/src/main/java/li/strolch/service/AddOrderService.java
@@ -0,0 +1,53 @@
+/*
+ * Copyright 2013 Robert von Burg
+ *
+ * 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
+ */
+public class AddOrderService extends AbstractService {
+
+ 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;
+ }
+}
diff --git a/li.strolch.service/src/main/java/li/strolch/service/AddResourceCollectionService.java b/li.strolch.service/src/main/java/li/strolch/service/AddResourceCollectionService.java
new file mode 100644
index 000000000..6fd14a821
--- /dev/null
+++ b/li.strolch.service/src/main/java/li/strolch/service/AddResourceCollectionService.java
@@ -0,0 +1,56 @@
+/*
+ * Copyright 2013 Robert von Burg
+ *
+ * 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
+ */
+public class AddResourceCollectionService extends
+ AbstractService {
+
+ 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 resources;
+ }
+}
diff --git a/li.strolch.service/src/main/java/li/strolch/service/AddResourceService.java b/li.strolch.service/src/main/java/li/strolch/service/AddResourceService.java
new file mode 100644
index 000000000..623b2eb1f
--- /dev/null
+++ b/li.strolch.service/src/main/java/li/strolch/service/AddResourceService.java
@@ -0,0 +1,53 @@
+/*
+ * Copyright 2013 Robert von Burg
+ *
+ * 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
+ */
+public class AddResourceService extends AbstractService {
+
+ 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;
+ }
+}
diff --git a/li.strolch.service/src/main/java/li/strolch/service/ClearModelArgument.java b/li.strolch.service/src/main/java/li/strolch/service/ClearModelArgument.java
new file mode 100644
index 000000000..42cfe9555
--- /dev/null
+++ b/li.strolch.service/src/main/java/li/strolch/service/ClearModelArgument.java
@@ -0,0 +1,24 @@
+/*
+ * Copyright 2013 Robert von Burg
+ *
+ * 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;
+}
\ No newline at end of file
diff --git a/li.strolch.service/src/main/java/li/strolch/service/ClearModelService.java b/li.strolch.service/src/main/java/li/strolch/service/ClearModelService.java
new file mode 100644
index 000000000..ed455660a
--- /dev/null
+++ b/li.strolch.service/src/main/java/li/strolch/service/ClearModelService.java
@@ -0,0 +1,59 @@
+/*
+ * Copyright 2013 Robert von Burg
+ *
+ * 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
+ */
+public class ClearModelService extends AbstractService {
+
+ 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();
+ }
+}
diff --git a/li.strolch.service/src/main/java/li/strolch/service/RemoveOrderCollectionService.java b/li.strolch.service/src/main/java/li/strolch/service/RemoveOrderCollectionService.java
new file mode 100644
index 000000000..dc26539d9
--- /dev/null
+++ b/li.strolch.service/src/main/java/li/strolch/service/RemoveOrderCollectionService.java
@@ -0,0 +1,65 @@
+/*
+ * Copyright 2013 Robert von Burg
+ *
+ * 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
+ */
+public class RemoveOrderCollectionService extends
+ AbstractService {
+
+ 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 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 locators;
+ }
+}
diff --git a/li.strolch.service/src/main/java/li/strolch/service/RemoveOrderService.java b/li.strolch.service/src/main/java/li/strolch/service/RemoveOrderService.java
new file mode 100644
index 000000000..b13cc2b1e
--- /dev/null
+++ b/li.strolch.service/src/main/java/li/strolch/service/RemoveOrderService.java
@@ -0,0 +1,57 @@
+/*
+ * Copyright 2013 Robert von Burg
+ *
+ * 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
+ */
+public class RemoveOrderService extends AbstractService {
+
+ 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;
+ }
+}
diff --git a/li.strolch.service/src/main/java/li/strolch/service/RemoveResourceCollectionService.java b/li.strolch.service/src/main/java/li/strolch/service/RemoveResourceCollectionService.java
new file mode 100644
index 000000000..9675c8d2a
--- /dev/null
+++ b/li.strolch.service/src/main/java/li/strolch/service/RemoveResourceCollectionService.java
@@ -0,0 +1,65 @@
+/*
+ * Copyright 2013 Robert von Burg
+ *
+ * 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
+ */
+public class RemoveResourceCollectionService extends
+ AbstractService {
+
+ 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 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 locators;
+ }
+}
diff --git a/li.strolch.service/src/main/java/li/strolch/service/RemoveResourceService.java b/li.strolch.service/src/main/java/li/strolch/service/RemoveResourceService.java
new file mode 100644
index 000000000..eb273c815
--- /dev/null
+++ b/li.strolch.service/src/main/java/li/strolch/service/RemoveResourceService.java
@@ -0,0 +1,57 @@
+/*
+ * Copyright 2013 Robert von Burg
+ *
+ * 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
+ */
+public class RemoveResourceService extends AbstractService {
+
+ 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;
+ }
+}
diff --git a/li.strolch.service/src/main/java/li/strolch/service/UpdateOrderCollectionService.java b/li.strolch.service/src/main/java/li/strolch/service/UpdateOrderCollectionService.java
new file mode 100644
index 000000000..2da84553b
--- /dev/null
+++ b/li.strolch.service/src/main/java/li/strolch/service/UpdateOrderCollectionService.java
@@ -0,0 +1,56 @@
+/*
+ * Copyright 2013 Robert von Burg
+ *
+ * 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
+ */
+public class UpdateOrderCollectionService extends
+ AbstractService {
+
+ 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 orders;
+ }
+}
diff --git a/li.strolch.service/src/main/java/li/strolch/service/UpdateOrderService.java b/li.strolch.service/src/main/java/li/strolch/service/UpdateOrderService.java
new file mode 100644
index 000000000..3d6aa8052
--- /dev/null
+++ b/li.strolch.service/src/main/java/li/strolch/service/UpdateOrderService.java
@@ -0,0 +1,53 @@
+/*
+ * Copyright 2013 Robert von Burg
+ *
+ * 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
+ */
+public class UpdateOrderService extends AbstractService {
+
+ 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;
+ }
+}
diff --git a/li.strolch.service/src/main/java/li/strolch/service/UpdateResourceCollectionService.java b/li.strolch.service/src/main/java/li/strolch/service/UpdateResourceCollectionService.java
new file mode 100644
index 000000000..b49345851
--- /dev/null
+++ b/li.strolch.service/src/main/java/li/strolch/service/UpdateResourceCollectionService.java
@@ -0,0 +1,56 @@
+/*
+ * Copyright 2013 Robert von Burg
+ *
+ * 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
+ */
+public class UpdateResourceCollectionService extends
+ AbstractService {
+
+ 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 resources;
+ }
+}
diff --git a/li.strolch.service/src/main/java/li/strolch/service/UpdateResourceService.java b/li.strolch.service/src/main/java/li/strolch/service/UpdateResourceService.java
new file mode 100644
index 000000000..bcbd210e1
--- /dev/null
+++ b/li.strolch.service/src/main/java/li/strolch/service/UpdateResourceService.java
@@ -0,0 +1,53 @@
+/*
+ * Copyright 2013 Robert von Burg
+ *
+ * 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
+ */
+public class UpdateResourceService extends AbstractService {
+
+ 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;
+ }
+}
diff --git a/li.strolch.service/src/main/java/li/strolch/service/XmlExportModelArgument.java b/li.strolch.service/src/main/java/li/strolch/service/XmlExportModelArgument.java
new file mode 100644
index 000000000..ffa15f294
--- /dev/null
+++ b/li.strolch.service/src/main/java/li/strolch/service/XmlExportModelArgument.java
@@ -0,0 +1,68 @@
+/*
+ * Copyright 2013 Robert von Burg
+ *
+ * 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 orderTypes = new HashSet<>();
+ public Set 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();
+ }
+}
\ No newline at end of file
diff --git a/li.strolch.service/src/main/java/li/strolch/service/XmlExportModelService.java b/li.strolch.service/src/main/java/li/strolch/service/XmlExportModelService.java
new file mode 100644
index 000000000..79e05413d
--- /dev/null
+++ b/li.strolch.service/src/main/java/li/strolch/service/XmlExportModelService.java
@@ -0,0 +1,79 @@
+/*
+ * Copyright 2013 Robert von Burg
+ *
+ * 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
+ */
+public class XmlExportModelService extends AbstractService {
+
+ 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();
+ }
+}
diff --git a/li.strolch.service/src/main/java/li/strolch/service/XmlImportModelArgument.java b/li.strolch.service/src/main/java/li/strolch/service/XmlImportModelArgument.java
new file mode 100644
index 000000000..853165c32
--- /dev/null
+++ b/li.strolch.service/src/main/java/li/strolch/service/XmlImportModelArgument.java
@@ -0,0 +1,33 @@
+/*
+ * Copyright 2013 Robert von Burg
+ *
+ * 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 orderTypes = new HashSet<>();
+ public Set resourceTypes = new HashSet<>();
+}
\ No newline at end of file
diff --git a/li.strolch.service/src/main/java/li/strolch/service/XmlImportModelService.java b/li.strolch.service/src/main/java/li/strolch/service/XmlImportModelService.java
new file mode 100644
index 000000000..a26222657
--- /dev/null
+++ b/li.strolch.service/src/main/java/li/strolch/service/XmlImportModelService.java
@@ -0,0 +1,75 @@
+/*
+ * Copyright 2013 Robert von Burg
+ *
+ * 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
+ */
+public class XmlImportModelService extends AbstractService {
+
+ 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();
+ }
+}
diff --git a/li.strolch.service/src/main/java/li/strolch/service/parameter/AddParameterService.java b/li.strolch.service/src/main/java/li/strolch/service/parameter/AddParameterService.java
new file mode 100644
index 000000000..0f9e5ab34
--- /dev/null
+++ b/li.strolch.service/src/main/java/li/strolch/service/parameter/AddParameterService.java
@@ -0,0 +1,60 @@
+/*
+ * Copyright 2013 Robert von Burg
+ *
+ * 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
+ */
+public class AddParameterService extends AbstractService {
+
+ 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;
+ }
+}
diff --git a/li.strolch.service/src/main/java/li/strolch/service/parameter/RemoveParameterService.java b/li.strolch.service/src/main/java/li/strolch/service/parameter/RemoveParameterService.java
new file mode 100644
index 000000000..48848692f
--- /dev/null
+++ b/li.strolch.service/src/main/java/li/strolch/service/parameter/RemoveParameterService.java
@@ -0,0 +1,58 @@
+/*
+ * Copyright 2013 Robert von Burg
+ *
+ * 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
+ */
+public class RemoveParameterService extends AbstractService {
+
+ 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;
+ }
+}
diff --git a/li.strolch.service/src/main/java/li/strolch/service/parameter/SetParameterService.java b/li.strolch.service/src/main/java/li/strolch/service/parameter/SetParameterService.java
new file mode 100644
index 000000000..a1648b0f6
--- /dev/null
+++ b/li.strolch.service/src/main/java/li/strolch/service/parameter/SetParameterService.java
@@ -0,0 +1,74 @@
+/*
+ * Copyright 2013 Robert von Burg
+ *
+ * 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
+ */
+public class SetParameterService extends AbstractService {
+
+ 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;
+ }
+}
diff --git a/li.strolch.service/src/main/resources/componentVersion.properties b/li.strolch.service/src/main/resources/componentVersion.properties
new file mode 100644
index 000000000..1f050160f
--- /dev/null
+++ b/li.strolch.service/src/main/resources/componentVersion.properties
@@ -0,0 +1,6 @@
+groupId=${project.groupId}
+artifactId=${project.artifactId}
+artifactVersion=${project.version}
+scmRevision=r${buildNumber}
+scmBranch=${scmBranch}
+buildTimestamp=${buildTimestamp}
\ No newline at end of file
diff --git a/li.strolch.service/src/test/java/li/strolch/command/AbstractRealmCommandTest.java b/li.strolch.service/src/test/java/li/strolch/command/AbstractRealmCommandTest.java
new file mode 100644
index 000000000..5770d8290
--- /dev/null
+++ b/li.strolch.service/src/test/java/li/strolch/command/AbstractRealmCommandTest.java
@@ -0,0 +1,150 @@
+/*
+ * Copyright 2013 Robert von Burg
+ *
+ * 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
+ */
+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();
+ }
+ }
+}
diff --git a/li.strolch.service/src/test/java/li/strolch/command/AddOrderCollectionCommandTest.java b/li.strolch.service/src/test/java/li/strolch/command/AddOrderCollectionCommandTest.java
new file mode 100644
index 000000000..8c1a700d8
--- /dev/null
+++ b/li.strolch.service/src/test/java/li/strolch/command/AddOrderCollectionCommandTest.java
@@ -0,0 +1,51 @@
+/*
+ * Copyright 2013 Robert von Burg
+ *
+ * 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
+ */
+public class AddOrderCollectionCommandTest extends AbstractRealmCommandTest {
+
+ private List 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;
+ }
+}
diff --git a/li.strolch.service/src/test/java/li/strolch/command/AddOrderCommandTest.java b/li.strolch.service/src/test/java/li/strolch/command/AddOrderCommandTest.java
new file mode 100644
index 000000000..b5c1f9e4a
--- /dev/null
+++ b/li.strolch.service/src/test/java/li/strolch/command/AddOrderCommandTest.java
@@ -0,0 +1,45 @@
+/*
+ * Copyright 2013 Robert von Burg
+ *
+ * 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
+ */
+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;
+ }
+}
diff --git a/li.strolch.service/src/test/java/li/strolch/command/AddResourceCollectionCommandTest.java b/li.strolch.service/src/test/java/li/strolch/command/AddResourceCollectionCommandTest.java
new file mode 100644
index 000000000..6ec764e60
--- /dev/null
+++ b/li.strolch.service/src/test/java/li/strolch/command/AddResourceCollectionCommandTest.java
@@ -0,0 +1,51 @@
+/*
+ * Copyright 2013 Robert von Burg
+ *
+ * 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
+ */
+public class AddResourceCollectionCommandTest extends AbstractRealmCommandTest {
+
+ private List 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;
+ }
+}
diff --git a/li.strolch.service/src/test/java/li/strolch/command/AddResourceCommandTest.java b/li.strolch.service/src/test/java/li/strolch/command/AddResourceCommandTest.java
new file mode 100644
index 000000000..fde80a188
--- /dev/null
+++ b/li.strolch.service/src/test/java/li/strolch/command/AddResourceCommandTest.java
@@ -0,0 +1,45 @@
+/*
+ * Copyright 2013 Robert von Burg
+ *
+ * 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
+ */
+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;
+ }
+}
diff --git a/li.strolch.service/src/test/java/li/strolch/command/RemoveOrderCollectionCommandTest.java b/li.strolch.service/src/test/java/li/strolch/command/RemoveOrderCollectionCommandTest.java
new file mode 100644
index 000000000..d8ee42a12
--- /dev/null
+++ b/li.strolch.service/src/test/java/li/strolch/command/RemoveOrderCollectionCommandTest.java
@@ -0,0 +1,57 @@
+/*
+ * Copyright 2013 Robert von Burg
+ *
+ * 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
+ */
+public class RemoveOrderCollectionCommandTest extends AbstractRealmCommandTest {
+
+ private List 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 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;
+ }
+}
diff --git a/li.strolch.service/src/test/java/li/strolch/command/RemoveOrderCommandTest.java b/li.strolch.service/src/test/java/li/strolch/command/RemoveOrderCommandTest.java
new file mode 100644
index 000000000..bfd9ade35
--- /dev/null
+++ b/li.strolch.service/src/test/java/li/strolch/command/RemoveOrderCommandTest.java
@@ -0,0 +1,48 @@
+/*
+ * Copyright 2013 Robert von Burg
+ *
+ * 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
+ */
+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;
+ }
+}
diff --git a/li.strolch.service/src/test/java/li/strolch/command/RemoveResourceCollectionCommandTest.java b/li.strolch.service/src/test/java/li/strolch/command/RemoveResourceCollectionCommandTest.java
new file mode 100644
index 000000000..9df74efd8
--- /dev/null
+++ b/li.strolch.service/src/test/java/li/strolch/command/RemoveResourceCollectionCommandTest.java
@@ -0,0 +1,57 @@
+/*
+ * Copyright 2013 Robert von Burg
+ *
+ * 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
+ */
+public class RemoveResourceCollectionCommandTest extends AbstractRealmCommandTest {
+
+ private List 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 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;
+ }
+}
diff --git a/li.strolch.service/src/test/java/li/strolch/command/RemoveResourceCommandTest.java b/li.strolch.service/src/test/java/li/strolch/command/RemoveResourceCommandTest.java
new file mode 100644
index 000000000..6731f2e3f
--- /dev/null
+++ b/li.strolch.service/src/test/java/li/strolch/command/RemoveResourceCommandTest.java
@@ -0,0 +1,48 @@
+/*
+ * Copyright 2013 Robert von Burg
+ *
+ * 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
+ */
+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;
+ }
+}
diff --git a/li.strolch.service/src/test/java/li/strolch/command/UpdateOrderCollectionCommandTest.java b/li.strolch.service/src/test/java/li/strolch/command/UpdateOrderCollectionCommandTest.java
new file mode 100644
index 000000000..f05219655
--- /dev/null
+++ b/li.strolch.service/src/test/java/li/strolch/command/UpdateOrderCollectionCommandTest.java
@@ -0,0 +1,51 @@
+/*
+ * Copyright 2013 Robert von Burg
+ *
+ * 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
+ */
+public class UpdateOrderCollectionCommandTest extends AbstractRealmCommandTest {
+
+ private List 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;
+ }
+}
diff --git a/li.strolch.service/src/test/java/li/strolch/command/UpdateOrderCommandTest.java b/li.strolch.service/src/test/java/li/strolch/command/UpdateOrderCommandTest.java
new file mode 100644
index 000000000..0bc9c40c9
--- /dev/null
+++ b/li.strolch.service/src/test/java/li/strolch/command/UpdateOrderCommandTest.java
@@ -0,0 +1,45 @@
+/*
+ * Copyright 2013 Robert von Burg
+ *
+ * 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
+ */
+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;
+ }
+}
diff --git a/li.strolch.service/src/test/java/li/strolch/command/UpdateResourceCollectionCommandTest.java b/li.strolch.service/src/test/java/li/strolch/command/UpdateResourceCollectionCommandTest.java
new file mode 100644
index 000000000..cfaaa636d
--- /dev/null
+++ b/li.strolch.service/src/test/java/li/strolch/command/UpdateResourceCollectionCommandTest.java
@@ -0,0 +1,51 @@
+/*
+ * Copyright 2013 Robert von Burg
+ *
+ * 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
+ */
+public class UpdateResourceCollectionCommandTest extends AbstractRealmCommandTest {
+
+ private List 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;
+ }
+}
diff --git a/li.strolch.service/src/test/java/li/strolch/command/UpdateResourceCommandTest.java b/li.strolch.service/src/test/java/li/strolch/command/UpdateResourceCommandTest.java
new file mode 100644
index 000000000..a144a62aa
--- /dev/null
+++ b/li.strolch.service/src/test/java/li/strolch/command/UpdateResourceCommandTest.java
@@ -0,0 +1,45 @@
+/*
+ * Copyright 2013 Robert von Burg
+ *
+ * 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
+ */
+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;
+ }
+}
diff --git a/li.strolch.service/src/test/java/li/strolch/command/parameter/AddParameterCommandTest.java b/li.strolch.service/src/test/java/li/strolch/command/parameter/AddParameterCommandTest.java
new file mode 100644
index 000000000..7689a162e
--- /dev/null
+++ b/li.strolch.service/src/test/java/li/strolch/command/parameter/AddParameterCommandTest.java
@@ -0,0 +1,53 @@
+/*
+ * Copyright 2013 Robert von Burg
+ *
+ * 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
+ */
+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;
+ }
+}
diff --git a/li.strolch.service/src/test/java/li/strolch/command/parameter/RemoveParameterCommandTest.java b/li.strolch.service/src/test/java/li/strolch/command/parameter/RemoveParameterCommandTest.java
new file mode 100644
index 000000000..060f3c60c
--- /dev/null
+++ b/li.strolch.service/src/test/java/li/strolch/command/parameter/RemoveParameterCommandTest.java
@@ -0,0 +1,51 @@
+/*
+ * Copyright 2013 Robert von Burg
+ *
+ * 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
+ */
+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;
+ }
+}
diff --git a/li.strolch.service/src/test/java/li/strolch/command/parameter/SetParameterCommandTest.java b/li.strolch.service/src/test/java/li/strolch/command/parameter/SetParameterCommandTest.java
new file mode 100644
index 000000000..0562101f5
--- /dev/null
+++ b/li.strolch.service/src/test/java/li/strolch/command/parameter/SetParameterCommandTest.java
@@ -0,0 +1,51 @@
+/*
+ * Copyright 2013 Robert von Burg
+ *
+ * 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
+ */
+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;
+ }
+}
diff --git a/li.strolch.service/src/test/java/li/strolch/service/AddOrderCollectionServiceTest.java b/li.strolch.service/src/test/java/li/strolch/service/AddOrderCollectionServiceTest.java
new file mode 100644
index 000000000..2033be036
--- /dev/null
+++ b/li.strolch.service/src/test/java/li/strolch/service/AddOrderCollectionServiceTest.java
@@ -0,0 +1,46 @@
+/*
+ * Copyright 2013 Robert von Burg
+ *
+ * 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
+ */
+public class AddOrderCollectionServiceTest extends AbstractRealmServiceTest {
+
+ @Test
+ public void runTest() {
+
+ AddOrderCollectionArg arg = new AddOrderCollectionArg();
+
+ ArrayList 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);
+ }
+}
diff --git a/li.strolch.service/src/test/java/li/strolch/service/AddOrderServiceTest.java b/li.strolch.service/src/test/java/li/strolch/service/AddOrderServiceTest.java
new file mode 100644
index 000000000..f0e3b5da5
--- /dev/null
+++ b/li.strolch.service/src/test/java/li/strolch/service/AddOrderServiceTest.java
@@ -0,0 +1,37 @@
+/*
+ * Copyright 2013 Robert von Burg
+ *
+ * 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
+ */
+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);
+ }
+}
diff --git a/li.strolch.service/src/test/java/li/strolch/service/AddResourceCollectionServiceTest.java b/li.strolch.service/src/test/java/li/strolch/service/AddResourceCollectionServiceTest.java
new file mode 100644
index 000000000..42f7bb61c
--- /dev/null
+++ b/li.strolch.service/src/test/java/li/strolch/service/AddResourceCollectionServiceTest.java
@@ -0,0 +1,46 @@
+/*
+ * Copyright 2013 Robert von Burg
+ *
+ * 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
+ */
+public class AddResourceCollectionServiceTest extends AbstractRealmServiceTest {
+
+ @Test
+ public void runTest() {
+
+ AddResourceCollectionArg arg = new AddResourceCollectionArg();
+
+ ArrayList 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);
+ }
+}
diff --git a/li.strolch.service/src/test/java/li/strolch/service/AddResourceServiceTest.java b/li.strolch.service/src/test/java/li/strolch/service/AddResourceServiceTest.java
new file mode 100644
index 000000000..bb53f6491
--- /dev/null
+++ b/li.strolch.service/src/test/java/li/strolch/service/AddResourceServiceTest.java
@@ -0,0 +1,37 @@
+/*
+ * Copyright 2013 Robert von Burg
+ *
+ * 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
+ */
+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);
+ }
+}
diff --git a/li.strolch.service/src/test/java/li/strolch/service/ClearModelServiceTest.java b/li.strolch.service/src/test/java/li/strolch/service/ClearModelServiceTest.java
new file mode 100644
index 000000000..682c55cf7
--- /dev/null
+++ b/li.strolch.service/src/test/java/li/strolch/service/ClearModelServiceTest.java
@@ -0,0 +1,92 @@
+/*
+ * Copyright 2013 Robert von Burg
+ *
+ * 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
+ */
+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);
+ }
+
+}
diff --git a/li.strolch.service/src/test/java/li/strolch/service/RemoveOrderCollectionServiceTest.java b/li.strolch.service/src/test/java/li/strolch/service/RemoveOrderCollectionServiceTest.java
new file mode 100644
index 000000000..5f1a2169c
--- /dev/null
+++ b/li.strolch.service/src/test/java/li/strolch/service/RemoveOrderCollectionServiceTest.java
@@ -0,0 +1,46 @@
+/*
+ * Copyright 2013 Robert von Burg
+ *
+ * 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
+ */
+public class RemoveOrderCollectionServiceTest extends AbstractRealmServiceTest {
+
+ @Test
+ public void runTest() {
+
+ RemoveOrderCollectionArg arg = new RemoveOrderCollectionArg();
+
+ ArrayList 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);
+ }
+}
diff --git a/li.strolch.service/src/test/java/li/strolch/service/RemoveOrderServiceTest.java b/li.strolch.service/src/test/java/li/strolch/service/RemoveOrderServiceTest.java
new file mode 100644
index 000000000..483958aff
--- /dev/null
+++ b/li.strolch.service/src/test/java/li/strolch/service/RemoveOrderServiceTest.java
@@ -0,0 +1,38 @@
+/*
+ * Copyright 2013 Robert von Burg
+ *
+ * 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
+ */
+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);
+ }
+}
diff --git a/li.strolch.service/src/test/java/li/strolch/service/RemoveResourceCollectionServiceTest.java b/li.strolch.service/src/test/java/li/strolch/service/RemoveResourceCollectionServiceTest.java
new file mode 100644
index 000000000..13dfb3d31
--- /dev/null
+++ b/li.strolch.service/src/test/java/li/strolch/service/RemoveResourceCollectionServiceTest.java
@@ -0,0 +1,46 @@
+/*
+ * Copyright 2013 Robert von Burg
+ *
+ * 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
+ */
+public class RemoveResourceCollectionServiceTest extends AbstractRealmServiceTest {
+
+ @Test
+ public void runTest() {
+
+ RemoveResourceCollectionArg arg = new RemoveResourceCollectionArg();
+
+ ArrayList 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);
+ }
+}
diff --git a/li.strolch.service/src/test/java/li/strolch/service/RemoveResourceServiceTest.java b/li.strolch.service/src/test/java/li/strolch/service/RemoveResourceServiceTest.java
new file mode 100644
index 000000000..3db54698d
--- /dev/null
+++ b/li.strolch.service/src/test/java/li/strolch/service/RemoveResourceServiceTest.java
@@ -0,0 +1,38 @@
+/*
+ * Copyright 2013 Robert von Burg
+ *
+ * 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
+ */
+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);
+ }
+}
diff --git a/li.strolch.service/src/test/java/li/strolch/service/UpdateOrderCollectionServiceTest.java b/li.strolch.service/src/test/java/li/strolch/service/UpdateOrderCollectionServiceTest.java
new file mode 100644
index 000000000..f22096b78
--- /dev/null
+++ b/li.strolch.service/src/test/java/li/strolch/service/UpdateOrderCollectionServiceTest.java
@@ -0,0 +1,47 @@
+/*
+ * Copyright 2013 Robert von Burg
+ *
+ * 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
+ */
+public class UpdateOrderCollectionServiceTest extends AbstractRealmServiceTest {
+
+ @Test
+ public void runTest() {
+
+ UpdateOrderCollectionArg arg = new UpdateOrderCollectionArg();
+
+ List 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);
+ }
+}
diff --git a/li.strolch.service/src/test/java/li/strolch/service/UpdateOrderServiceTest.java b/li.strolch.service/src/test/java/li/strolch/service/UpdateOrderServiceTest.java
new file mode 100644
index 000000000..a9706d264
--- /dev/null
+++ b/li.strolch.service/src/test/java/li/strolch/service/UpdateOrderServiceTest.java
@@ -0,0 +1,37 @@
+/*
+ * Copyright 2013 Robert von Burg
+ *
+ * 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
+ */
+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);
+ }
+}
diff --git a/li.strolch.service/src/test/java/li/strolch/service/UpdateResourceCollectionServiceTest.java b/li.strolch.service/src/test/java/li/strolch/service/UpdateResourceCollectionServiceTest.java
new file mode 100644
index 000000000..76ebbc0fb
--- /dev/null
+++ b/li.strolch.service/src/test/java/li/strolch/service/UpdateResourceCollectionServiceTest.java
@@ -0,0 +1,46 @@
+/*
+ * Copyright 2013 Robert von Burg
+ *
+ * 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
+ */
+public class UpdateResourceCollectionServiceTest extends AbstractRealmServiceTest {
+
+ @Test
+ public void runTest() {
+
+ UpdateResourceCollectionArg arg = new UpdateResourceCollectionArg();
+
+ ArrayList 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);
+ }
+}
diff --git a/li.strolch.service/src/test/java/li/strolch/service/UpdateResourceServiceTest.java b/li.strolch.service/src/test/java/li/strolch/service/UpdateResourceServiceTest.java
new file mode 100644
index 000000000..d8c763577
--- /dev/null
+++ b/li.strolch.service/src/test/java/li/strolch/service/UpdateResourceServiceTest.java
@@ -0,0 +1,37 @@
+/*
+ * Copyright 2013 Robert von Burg
+ *
+ * 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
+ */
+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);
+ }
+}
diff --git a/li.strolch.service/src/test/java/li/strolch/service/XmlExportModelServiceTest.java b/li.strolch.service/src/test/java/li/strolch/service/XmlExportModelServiceTest.java
new file mode 100644
index 000000000..45b9ec6dd
--- /dev/null
+++ b/li.strolch.service/src/test/java/li/strolch/service/XmlExportModelServiceTest.java
@@ -0,0 +1,103 @@
+/*
+ * Copyright 2013 Robert von Burg
+ *
+ * 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
+ */
+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);
+ }
+}
diff --git a/li.strolch.service/src/test/java/li/strolch/service/XmlImportModelServiceTest.java b/li.strolch.service/src/test/java/li/strolch/service/XmlImportModelServiceTest.java
new file mode 100644
index 000000000..71041c263
--- /dev/null
+++ b/li.strolch.service/src/test/java/li/strolch/service/XmlImportModelServiceTest.java
@@ -0,0 +1,35 @@
+/*
+ * Copyright 2013 Robert von Burg
+ *
+ * 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
+ */
+public class XmlImportModelServiceTest extends AbstractRealmServiceTest {
+
+ @Test
+ public void runTest() {
+
+ XmlImportModelArgument arg = new XmlImportModelArgument();
+ arg.modelFileName = "Enums.xml";
+
+ runServiceInAllRealmTypes(XmlImportModelService.class, arg);
+ }
+}
diff --git a/li.strolch.service/src/test/java/li/strolch/service/test/AbstractRealmServiceTest.java b/li.strolch.service/src/test/java/li/strolch/service/test/AbstractRealmServiceTest.java
new file mode 100644
index 000000000..9812160ff
--- /dev/null
+++ b/li.strolch.service/src/test/java/li/strolch/service/test/AbstractRealmServiceTest.java
@@ -0,0 +1,155 @@
+/*
+ * Copyright 2013 Robert von Burg
+ *
+ * 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
+ */
+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 void doService(String realm,
+ ServiceResultState expectedState, Class> expectedServiceResultType, Service 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 void runServiceInAllRealmTypes(
+ Class extends Service> svcClass, T arg) {
+ runServiceInAllRealmTypes(svcClass, arg, null, null, null);
+ }
+
+ protected void runServiceInAllRealmTypes(
+ Class extends Service> 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 void runTransactional(Service svc, T arg,
+ Runner before, Runner validator, Runner after) {
+ doService(REALM_TRANSACTIONAL, ServiceResultState.SUCCESS, ServiceResult.class, svc, arg, before, validator,
+ after);
+ }
+
+ private void runCached(Service svc, T arg,
+ Runner before, Runner validator, Runner after) {
+ doService(REALM_CACHED, ServiceResultState.SUCCESS, ServiceResult.class, svc, arg, before, validator, after);
+ }
+
+ private void runTransient(Service svc, T arg,
+ Runner before, Runner validator, Runner after) {
+ doService(REALM_TRANSIENT, ServiceResultState.SUCCESS, ServiceResult.class, svc, arg, before, validator, after);
+ }
+}
diff --git a/li.strolch.service/src/test/java/li/strolch/service/test/AbstractServiceTest.java b/li.strolch.service/src/test/java/li/strolch/service/test/AbstractServiceTest.java
new file mode 100644
index 000000000..e33dd3833
--- /dev/null
+++ b/li.strolch.service/src/test/java/li/strolch/service/test/AbstractServiceTest.java
@@ -0,0 +1,53 @@
+/*
+ * Copyright 2013 Robert von Burg
+ *
+ * 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
+ */
+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);
+ }
+}
diff --git a/li.strolch.service/src/test/java/li/strolch/service/test/GreetingServiceTest.java b/li.strolch.service/src/test/java/li/strolch/service/test/GreetingServiceTest.java
new file mode 100644
index 000000000..ae9f2c278
--- /dev/null
+++ b/li.strolch.service/src/test/java/li/strolch/service/test/GreetingServiceTest.java
@@ -0,0 +1,49 @@
+/*
+ * Copyright 2013 Robert von Burg
+ *
+ * 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
+ */
+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);
+ }
+ }
+}
diff --git a/li.strolch.service/src/test/java/li/strolch/service/test/LockingTest.java b/li.strolch.service/src/test/java/li/strolch/service/test/LockingTest.java
new file mode 100644
index 000000000..f4348d228
--- /dev/null
+++ b/li.strolch.service/src/test/java/li/strolch/service/test/LockingTest.java
@@ -0,0 +1,189 @@
+/*
+ * Copyright 2013 Robert von Burg
+ *
+ * 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
+ */
+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 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 {
+ 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();
+ }
+ }
+}
diff --git a/li.strolch.service/src/test/java/li/strolch/service/test/ServiceTest.java b/li.strolch.service/src/test/java/li/strolch/service/test/ServiceTest.java
new file mode 100644
index 000000000..f7963a9d4
--- /dev/null
+++ b/li.strolch.service/src/test/java/li/strolch/service/test/ServiceTest.java
@@ -0,0 +1,117 @@
+/*
+ * Copyright 2013 Robert von Burg
+ *
+ * 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
+ */
+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);
+ }
+ }
+}
diff --git a/li.strolch.service/src/test/java/li/strolch/service/test/XmlExportServiceTest.java b/li.strolch.service/src/test/java/li/strolch/service/test/XmlExportServiceTest.java
new file mode 100644
index 000000000..bdba1736d
--- /dev/null
+++ b/li.strolch.service/src/test/java/li/strolch/service/test/XmlExportServiceTest.java
@@ -0,0 +1,127 @@
+/*
+ * Copyright 2013 Robert von Burg
+ *
+ * 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
+ */
+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);
+ }
+}
diff --git a/li.strolch.service/src/test/java/li/strolch/service/test/model/GreetingResult.java b/li.strolch.service/src/test/java/li/strolch/service/test/model/GreetingResult.java
new file mode 100644
index 000000000..2ada7e3fc
--- /dev/null
+++ b/li.strolch.service/src/test/java/li/strolch/service/test/model/GreetingResult.java
@@ -0,0 +1,43 @@
+/*
+ * Copyright 2013 Robert von Burg
+ *
+ * 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;
+ }
+}
\ No newline at end of file
diff --git a/li.strolch.service/src/test/java/li/strolch/service/test/model/GreetingService.java b/li.strolch.service/src/test/java/li/strolch/service/test/model/GreetingService.java
new file mode 100644
index 000000000..656d53abe
--- /dev/null
+++ b/li.strolch.service/src/test/java/li/strolch/service/test/model/GreetingService.java
@@ -0,0 +1,53 @@
+/*
+ * Copyright 2013 Robert von Burg
+ *
+ * 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
+ *
+ */
+public class GreetingService extends AbstractService {
+ 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;
+ }
+}
diff --git a/li.strolch.service/src/test/java/li/strolch/service/test/model/TestService.java b/li.strolch.service/src/test/java/li/strolch/service/test/model/TestService.java
new file mode 100644
index 000000000..4fedaf110
--- /dev/null
+++ b/li.strolch.service/src/test/java/li/strolch/service/test/model/TestService.java
@@ -0,0 +1,38 @@
+/*
+ * Copyright 2013 Robert von Burg
+ *
+ * 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
+ *
+ */
+public class TestService extends AbstractService {
+ private static final long serialVersionUID = 1L;
+
+ @Override
+ protected ServiceResult getResultInstance() {
+ return new ServiceResult();
+ }
+
+ @Override
+ protected ServiceResult internalDoService(ServiceArgument argument) {
+ return ServiceResult.success();
+ }
+}
diff --git a/li.strolch.service/src/test/java/li/strolch/service/test/parameter/AddParameterServiceTest.java b/li.strolch.service/src/test/java/li/strolch/service/test/parameter/AddParameterServiceTest.java
new file mode 100644
index 000000000..88b8c287b
--- /dev/null
+++ b/li.strolch.service/src/test/java/li/strolch/service/test/parameter/AddParameterServiceTest.java
@@ -0,0 +1,43 @@
+/*
+ * Copyright 2013 Robert von Burg
+ *
+ * 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
+ */
+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);
+ }
+}
diff --git a/li.strolch.service/src/test/java/li/strolch/service/test/parameter/RemoveParameterServiceTest.java b/li.strolch.service/src/test/java/li/strolch/service/test/parameter/RemoveParameterServiceTest.java
new file mode 100644
index 000000000..c67dc683c
--- /dev/null
+++ b/li.strolch.service/src/test/java/li/strolch/service/test/parameter/RemoveParameterServiceTest.java
@@ -0,0 +1,38 @@
+/*
+ * Copyright 2013 Robert von Burg
+ *
+ * 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
+ */
+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);
+ }
+}
diff --git a/li.strolch.service/src/test/java/li/strolch/service/test/parameter/SetParameterServiceTest.java b/li.strolch.service/src/test/java/li/strolch/service/test/parameter/SetParameterServiceTest.java
new file mode 100644
index 000000000..02edd123a
--- /dev/null
+++ b/li.strolch.service/src/test/java/li/strolch/service/test/parameter/SetParameterServiceTest.java
@@ -0,0 +1,44 @@
+/*
+ * Copyright 2013 Robert von Burg
+ *
+ * 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
+ */
+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);
+ }
+}
diff --git a/li.strolch.service/src/test/resources/log4j.xml b/li.strolch.service/src/test/resources/log4j.xml
new file mode 100644
index 000000000..0a2a73d06
--- /dev/null
+++ b/li.strolch.service/src/test/resources/log4j.xml
@@ -0,0 +1,30 @@
+
+
+
+
+
+