From cf6b5bbea948472173797cd44a13671c32a99674 Mon Sep 17 00:00:00 2001 From: Robert von Burg Date: Wed, 23 Oct 2013 10:48:13 -0700 Subject: [PATCH 01/65] Initial commit --- .gitignore | 1 + LICENSE | 191 +++++++++++++++++++++++++++++++++++++++++++++++++++++ README.md | 4 ++ 3 files changed, 196 insertions(+) create mode 100644 .gitignore create mode 100644 LICENSE create mode 100644 README.md diff --git a/.gitignore b/.gitignore new file mode 100644 index 000000000..2f7896d1d --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +target/ diff --git a/LICENSE b/LICENSE new file mode 100644 index 000000000..37ec93a14 --- /dev/null +++ b/LICENSE @@ -0,0 +1,191 @@ +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: + +You must give any other recipients of the Work or Derivative Works a copy of +this License; and +You must cause any modified files to carry prominent notices stating that You +changed the files; and +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 +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/README.md b/README.md new file mode 100644 index 000000000..7b20d2d05 --- /dev/null +++ b/README.md @@ -0,0 +1,4 @@ +li.strolch.service +================== + +Service API for Strolch From c7ce6ead764e499c4b904fd094904bb15da1199d Mon Sep 17 00:00:00 2001 From: Robert von Burg Date: Wed, 23 Oct 2013 19:59:32 +0200 Subject: [PATCH 02/65] Initial Commit --- .gitignore | 3 + pom.xml | 185 ++++++++++++++++++ .../li/strolch/command/AbstractCommand.java | 48 +++++ .../li/strolch/service/AbstractService.java | 44 +++++ src/main/java/li/strolch/service/Service.java | 35 ++++ .../li/strolch/service/ServiceArgument.java | 31 +++ .../li/strolch/service/ServiceResult.java | 107 ++++++++++ .../strolch/service/ServiceResultState.java | 29 +++ .../strolch/service/SimpleServiceHandler.java | 47 +++++ 9 files changed, 529 insertions(+) create mode 100644 pom.xml create mode 100644 src/main/java/li/strolch/command/AbstractCommand.java create mode 100644 src/main/java/li/strolch/service/AbstractService.java create mode 100644 src/main/java/li/strolch/service/Service.java create mode 100644 src/main/java/li/strolch/service/ServiceArgument.java create mode 100644 src/main/java/li/strolch/service/ServiceResult.java create mode 100644 src/main/java/li/strolch/service/ServiceResultState.java create mode 100644 src/main/java/li/strolch/service/SimpleServiceHandler.java diff --git a/.gitignore b/.gitignore index 2f7896d1d..b284c6517 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,4 @@ target/ +.project +.settings +.classpath diff --git a/pom.xml b/pom.xml new file mode 100644 index 000000000..9031f06a2 --- /dev/null +++ b/pom.xml @@ -0,0 +1,185 @@ + + + 4.0.0 + + li.strolch + li.strolch.service + 0.1.0-SNAPSHOT + + Service API for Strolch + Service API for Strolch + + https://github.com/eitch/li.strolch.service + + + UTF-8 + + + + + 2011 + + + GNU Lesser General Public License + http://www.gnu.org/licenses/lgpl.html + repo + + + + eitchnet.ch + http://blog.eitchnet.ch + + + + eitch + Robert von Vurg + eitch@eitchnet.ch + http://blog.eitchnet.ch + eitchnet.ch + http://blog.eitchnet.ch + + architect + developer + + +1 + + http://localhost + + + + + + Github Issues + https://github.com/eitch/li.strolch.service/issues + + + + + + scm:git:https://github.com/eitch/li.strolch.service.git + scm:git:git@github.com:eitch/li.strolch.service.git + https://github.com/eitch/li.strolch.service + + + + + + + + li.strolch + li.strolch.model + 1.0-SNAPSHOT + + + li.strolch + li.strolch.persistence.api + 0.1.0-SNAPSHOT + + + + ch.eitchnet + ch.eitchnet.xmlpers + 0.2.0-SNAPSHOT + + + ch.eitchnet + ch.eitchnet.privilege + 0.2.0-SNAPSHOT + + + + junit + junit + 4.10 + test + + + ch.eitchnet + ch.eitchnet.utils + 0.2.0-SNAPSHOT + + + org.slf4j + slf4j-api + 1.7.2 + + + org.slf4j + slf4j-log4j12 + 1.7.2 + test + + + + + + + org.apache.maven.plugins + maven-eclipse-plugin + 2.9 + + true + true + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.0 + + 1.7 + 1.7 + + + + + org.apache.maven.plugins + maven-source-plugin + 2.1.2 + + + attach-sources + verify + + jar-no-fork + + + + + + + org.apache.maven.plugins + maven-jar-plugin + 2.4 + + + + true + true + + + + + + + + org.apache.maven.plugins + maven-site-plugin + 2.3 + + UTF-8 + + + + + \ No newline at end of file diff --git a/src/main/java/li/strolch/command/AbstractCommand.java b/src/main/java/li/strolch/command/AbstractCommand.java new file mode 100644 index 000000000..69fd43018 --- /dev/null +++ b/src/main/java/li/strolch/command/AbstractCommand.java @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2012 + * + * This file is part of ??????????????? + * + * ?????????????? is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Privilege is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with ????????????????. If not, see . + * + */ +package ch.eitchnet.command; + +import ch.eitchnet.privilege.model.Restrictable; + + +/** + * @author Robert von Burg + * + */ +public abstract class AbstractCommand implements Restrictable { + + /** + * @see ch.eitchnet.privilege.model.Restrictable#getPrivilegeName() + */ + @Override + public String getPrivilegeName() { + return AbstractCommand.class.getName(); + } + + /** + * @see ch.eitchnet.privilege.model.Restrictable#getPrivilegeValue() + */ + @Override + public Object getPrivilegeValue() { + return this.getClass().getName(); + } + + public abstract void doCommand(); +} diff --git a/src/main/java/li/strolch/service/AbstractService.java b/src/main/java/li/strolch/service/AbstractService.java new file mode 100644 index 000000000..11f520316 --- /dev/null +++ b/src/main/java/li/strolch/service/AbstractService.java @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2012 + * + * This file is part of ??????????????? + * + * ?????????????? is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Privilege is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with ????????????????. If not, see . + * + */ +package ch.eitchnet.service; + +/** + * @author Robert von Burg + * + */ +public abstract class AbstractService implements Service { + private static final long serialVersionUID = 1L; + + /** + * @see ch.eitchnet.privilege.model.Restrictable#getPrivilegeName() + */ + @Override + public String getPrivilegeName() { + return Service.class.getName(); + } + + /** + * @see ch.eitchnet.privilege.model.Restrictable#getPrivilegeValue() + */ + @Override + public Object getPrivilegeValue() { + return this.getClass().getName(); + } +} diff --git a/src/main/java/li/strolch/service/Service.java b/src/main/java/li/strolch/service/Service.java new file mode 100644 index 000000000..4b4a5ce5d --- /dev/null +++ b/src/main/java/li/strolch/service/Service.java @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2012 + * + * This file is part of ??????????????? + * + * ?????????????? is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Privilege is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with ????????????????. If not, see . + * + */ +package ch.eitchnet.service; + +import java.io.Serializable; + +import ch.eitchnet.privilege.model.Restrictable; + +/** + * @author Robert von Burg + * + */ +public interface Service extends Serializable, Restrictable { + + public ServiceResult doService(ServiceArgument argument); + + public ServiceArgument getServiceArgument(); +} diff --git a/src/main/java/li/strolch/service/ServiceArgument.java b/src/main/java/li/strolch/service/ServiceArgument.java new file mode 100644 index 000000000..95841dbac --- /dev/null +++ b/src/main/java/li/strolch/service/ServiceArgument.java @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2012 + * + * This file is part of ??????????????? + * + * ?????????????? is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Privilege is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with ????????????????. If not, see . + * + */ +package ch.eitchnet.service; + +import java.io.Serializable; + +/** + * @author Robert von Burg + * + */ +public interface ServiceArgument extends Serializable { + + // marker interface +} diff --git a/src/main/java/li/strolch/service/ServiceResult.java b/src/main/java/li/strolch/service/ServiceResult.java new file mode 100644 index 000000000..6a7fde078 --- /dev/null +++ b/src/main/java/li/strolch/service/ServiceResult.java @@ -0,0 +1,107 @@ +/* + * Copyright (c) 2012 + * + * This file is part of ??????????????? + * + * ?????????????? is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Privilege is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with ????????????????. If not, see . + * + */ +package ch.eitchnet.service; + +/** + * @author Robert von Burg + * + */ +public class ServiceResult { + + private ServiceResultState state; + private String message; + private Throwable throwable; + + /** + * @param state + * @param message + * @param throwable + */ + public ServiceResult(ServiceResultState state, String message, Throwable throwable) { + this.state = state; + this.message = message; + this.throwable = throwable; + } + + /** + * @return the state + */ + public ServiceResultState getState() { + return this.state; + } + + /** + * @param state + * the state to set + */ + public void setState(ServiceResultState state) { + this.state = state; + } + + /** + * @return the message + */ + public String getMessage() { + return this.message; + } + + /** + * @param message + * the message to set + */ + public void setMessage(String message) { + this.message = message; + } + + /** + * @return the throwable + */ + public Throwable getThrowable() { + return this.throwable; + } + + /** + * @param throwable + * the throwable to set + */ + public void setThrowable(Throwable throwable) { + this.throwable = throwable; + } + + public static ServiceResult success() { + return new ServiceResult(ServiceResultState.SUCCESS, null, null); + } + + public static ServiceResult success(String msg) { + return new ServiceResult(ServiceResultState.SUCCESS, msg, null); + } + + public static ServiceResult warning(String warning) { + return new ServiceResult(ServiceResultState.WARNING, warning, null); + } + + public static ServiceResult warning(String warning, Throwable t) { + return new ServiceResult(ServiceResultState.WARNING, warning, t); + } + + public static ServiceResult failed(String error, Throwable t) { + return new ServiceResult(ServiceResultState.FAILED, error, t); + } +} diff --git a/src/main/java/li/strolch/service/ServiceResultState.java b/src/main/java/li/strolch/service/ServiceResultState.java new file mode 100644 index 000000000..d6e7981e1 --- /dev/null +++ b/src/main/java/li/strolch/service/ServiceResultState.java @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2012 + * + * This file is part of ??????????????? + * + * ?????????????? is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Privilege is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with ????????????????. If not, see . + * + */ +package ch.eitchnet.service; + +/** + * @author Robert von Burg + * + */ +public enum ServiceResultState { + + SUCCESS, WARNING, FAILED; +} diff --git a/src/main/java/li/strolch/service/SimpleServiceHandler.java b/src/main/java/li/strolch/service/SimpleServiceHandler.java new file mode 100644 index 000000000..54ef842b4 --- /dev/null +++ b/src/main/java/li/strolch/service/SimpleServiceHandler.java @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2012 + * + * This file is part of ??????????????? + * + * ?????????????? is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Privilege is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with ????????????????. If not, see . + * + */ +package ch.eitchnet.service; + +import ch.eitchnet.privilege.handler.PrivilegeHandler; +import ch.eitchnet.privilege.model.Certificate; + +/** + * @author Robert von Burg + * + */ +public class SimpleServiceHandler { + + private PrivilegeHandler privilegeHandler; + + public ServiceResult doService(Certificate certificate, Service service, ServiceArgument argument) { + + try { + + this.privilegeHandler.getPrivilegeContext(certificate).validateAction(service); + + return service.doService(argument); + + } catch (Exception e) { + String error = "Failed to perform service " + service.getClass().getName() + " due to exception " + + e.getLocalizedMessage(); + return ServiceResult.failed(error, e); + } + } +} From 55462432b6a0d1ced5df4276cb2ae3bca3e32c85 Mon Sep 17 00:00:00 2001 From: Robert von Burg Date: Wed, 23 Oct 2013 21:11:49 +0200 Subject: [PATCH 03/65] [Project] set a parent to li.strolch.parent for easier managing --- pom.xml | 117 ++---------------- .../li/strolch/command/AbstractCommand.java | 2 +- .../li/strolch/service/AbstractService.java | 2 +- src/main/java/li/strolch/service/Service.java | 2 +- .../li/strolch/service/ServiceArgument.java | 2 +- .../li/strolch/service/ServiceResult.java | 2 +- .../strolch/service/ServiceResultState.java | 2 +- .../strolch/service/SimpleServiceHandler.java | 9 +- 8 files changed, 18 insertions(+), 120 deletions(-) diff --git a/pom.xml b/pom.xml index 9031f06a2..b2a94ae31 100644 --- a/pom.xml +++ b/pom.xml @@ -1,123 +1,54 @@ - 4.0.0 - li.strolch + + li.strolch + li.strolch.parent + 0.1.0-SNAPSHOT + ../li.strolch.parent/pom.xml + + li.strolch.service - 0.1.0-SNAPSHOT Service API for Strolch Service API for Strolch https://github.com/eitch/li.strolch.service - - UTF-8 - - - - 2011 - - - GNU Lesser General Public License - http://www.gnu.org/licenses/lgpl.html - repo - - - - eitchnet.ch - http://blog.eitchnet.ch - - - - eitch - Robert von Vurg - eitch@eitchnet.ch - http://blog.eitchnet.ch - eitchnet.ch - http://blog.eitchnet.ch - - architect - developer - - +1 - - http://localhost - - - Github Issues https://github.com/eitch/li.strolch.service/issues - - scm:git:https://github.com/eitch/li.strolch.service.git scm:git:git@github.com:eitch/li.strolch.service.git https://github.com/eitch/li.strolch.service - - li.strolch li.strolch.model - 1.0-SNAPSHOT li.strolch li.strolch.persistence.api - 0.1.0-SNAPSHOT ch.eitchnet ch.eitchnet.xmlpers - 0.2.0-SNAPSHOT ch.eitchnet ch.eitchnet.privilege - 0.2.0-SNAPSHOT - - junit - junit - 4.10 - test - - - ch.eitchnet - ch.eitchnet.utils - 0.2.0-SNAPSHOT - - - org.slf4j - slf4j-api - 1.7.2 - - - org.slf4j - slf4j-log4j12 - 1.7.2 - test - @@ -125,60 +56,26 @@ org.apache.maven.plugins maven-eclipse-plugin - 2.9 - - true - true - org.apache.maven.plugins maven-compiler-plugin - 3.0 - - 1.7 - 1.7 - org.apache.maven.plugins maven-source-plugin - 2.1.2 - - - attach-sources - verify - - jar-no-fork - - - org.apache.maven.plugins maven-jar-plugin - 2.4 - - - - true - true - - - - org.apache.maven.plugins maven-site-plugin - 2.3 - - UTF-8 - diff --git a/src/main/java/li/strolch/command/AbstractCommand.java b/src/main/java/li/strolch/command/AbstractCommand.java index 69fd43018..304f62381 100644 --- a/src/main/java/li/strolch/command/AbstractCommand.java +++ b/src/main/java/li/strolch/command/AbstractCommand.java @@ -17,7 +17,7 @@ * along with ????????????????. If not, see . * */ -package ch.eitchnet.command; +package li.strolch.command; import ch.eitchnet.privilege.model.Restrictable; diff --git a/src/main/java/li/strolch/service/AbstractService.java b/src/main/java/li/strolch/service/AbstractService.java index 11f520316..53409944a 100644 --- a/src/main/java/li/strolch/service/AbstractService.java +++ b/src/main/java/li/strolch/service/AbstractService.java @@ -17,7 +17,7 @@ * along with ????????????????. If not, see . * */ -package ch.eitchnet.service; +package li.strolch.service; /** * @author Robert von Burg diff --git a/src/main/java/li/strolch/service/Service.java b/src/main/java/li/strolch/service/Service.java index 4b4a5ce5d..3c84a533a 100644 --- a/src/main/java/li/strolch/service/Service.java +++ b/src/main/java/li/strolch/service/Service.java @@ -17,7 +17,7 @@ * along with ????????????????. If not, see . * */ -package ch.eitchnet.service; +package li.strolch.service; import java.io.Serializable; diff --git a/src/main/java/li/strolch/service/ServiceArgument.java b/src/main/java/li/strolch/service/ServiceArgument.java index 95841dbac..1e0aca9c7 100644 --- a/src/main/java/li/strolch/service/ServiceArgument.java +++ b/src/main/java/li/strolch/service/ServiceArgument.java @@ -17,7 +17,7 @@ * along with ????????????????. If not, see . * */ -package ch.eitchnet.service; +package li.strolch.service; import java.io.Serializable; diff --git a/src/main/java/li/strolch/service/ServiceResult.java b/src/main/java/li/strolch/service/ServiceResult.java index 6a7fde078..8c55fb5f1 100644 --- a/src/main/java/li/strolch/service/ServiceResult.java +++ b/src/main/java/li/strolch/service/ServiceResult.java @@ -17,7 +17,7 @@ * along with ????????????????. If not, see . * */ -package ch.eitchnet.service; +package li.strolch.service; /** * @author Robert von Burg diff --git a/src/main/java/li/strolch/service/ServiceResultState.java b/src/main/java/li/strolch/service/ServiceResultState.java index d6e7981e1..5b9fd233e 100644 --- a/src/main/java/li/strolch/service/ServiceResultState.java +++ b/src/main/java/li/strolch/service/ServiceResultState.java @@ -17,7 +17,7 @@ * along with ????????????????. If not, see . * */ -package ch.eitchnet.service; +package li.strolch.service; /** * @author Robert von Burg diff --git a/src/main/java/li/strolch/service/SimpleServiceHandler.java b/src/main/java/li/strolch/service/SimpleServiceHandler.java index 54ef842b4..7f38de053 100644 --- a/src/main/java/li/strolch/service/SimpleServiceHandler.java +++ b/src/main/java/li/strolch/service/SimpleServiceHandler.java @@ -17,14 +17,15 @@ * along with ????????????????. If not, see . * */ -package ch.eitchnet.service; +package li.strolch.service; + +import java.text.MessageFormat; import ch.eitchnet.privilege.handler.PrivilegeHandler; import ch.eitchnet.privilege.model.Certificate; /** * @author Robert von Burg - * */ public class SimpleServiceHandler { @@ -39,8 +40,8 @@ public class SimpleServiceHandler { return service.doService(argument); } catch (Exception e) { - String error = "Failed to perform service " + service.getClass().getName() + " due to exception " - + e.getLocalizedMessage(); + String msg = "Failed to perform service {0} due to exception {1}"; //$NON-NLS-1$ + String error = MessageFormat.format(msg, service.getClass().getName(), e.getMessage()); return ServiceResult.failed(error, e); } } From 181e3dfdffc2a5bdca812ce0bb7d07d5463f13af Mon Sep 17 00:00:00 2001 From: Robert von Burg Date: Sun, 27 Oct 2013 03:27:18 +0100 Subject: [PATCH 04/65] [Minor] Added StrolchComponent interface to SimpleServiceHandler --- pom.xml | 4 ++++ .../{AbstractCommand.java => Command.java} | 23 +++++++++++++++---- .../li/strolch/service/AbstractService.java | 2 +- src/main/java/li/strolch/service/Service.java | 6 ++--- .../li/strolch/service/ServiceHandler.java | 8 +++++++ .../strolch/service/SimpleServiceHandler.java | 10 +++++--- 6 files changed, 41 insertions(+), 12 deletions(-) rename src/main/java/li/strolch/command/{AbstractCommand.java => Command.java} (71%) create mode 100644 src/main/java/li/strolch/service/ServiceHandler.java diff --git a/pom.xml b/pom.xml index b2a94ae31..267f0a731 100644 --- a/pom.xml +++ b/pom.xml @@ -39,6 +39,10 @@ li.strolch li.strolch.persistence.api + + li.strolch + li.strolch.runtime + ch.eitchnet diff --git a/src/main/java/li/strolch/command/AbstractCommand.java b/src/main/java/li/strolch/command/Command.java similarity index 71% rename from src/main/java/li/strolch/command/AbstractCommand.java rename to src/main/java/li/strolch/command/Command.java index 304f62381..f447f41c9 100644 --- a/src/main/java/li/strolch/command/AbstractCommand.java +++ b/src/main/java/li/strolch/command/Command.java @@ -19,21 +19,36 @@ */ package li.strolch.command; +import li.strolch.persistence.api.StrolchTransaction; import ch.eitchnet.privilege.model.Restrictable; - /** * @author Robert von Burg * */ -public abstract class AbstractCommand implements Restrictable { +public abstract class Command implements Restrictable { + + private final StrolchTransaction tx; + + public Command(StrolchTransaction tx) { + this.tx = tx; + } + + /** + * Returns the {@link StrolchTransaction} bound to this {@link Command}'s runtime + * + * @return the {@link StrolchTransaction} bound to this {@link Command}'s runtime + */ + protected StrolchTransaction tx() { + return this.tx; + } /** * @see ch.eitchnet.privilege.model.Restrictable#getPrivilegeName() */ @Override public String getPrivilegeName() { - return AbstractCommand.class.getName(); + return Command.class.getName(); } /** @@ -43,6 +58,6 @@ public abstract class AbstractCommand implements Restrictable { public Object getPrivilegeValue() { return this.getClass().getName(); } - + public abstract void doCommand(); } diff --git a/src/main/java/li/strolch/service/AbstractService.java b/src/main/java/li/strolch/service/AbstractService.java index 53409944a..b96b68f55 100644 --- a/src/main/java/li/strolch/service/AbstractService.java +++ b/src/main/java/li/strolch/service/AbstractService.java @@ -23,7 +23,7 @@ package li.strolch.service; * @author Robert von Burg * */ -public abstract class AbstractService implements Service { +public abstract class AbstractService implements Service { private static final long serialVersionUID = 1L; /** diff --git a/src/main/java/li/strolch/service/Service.java b/src/main/java/li/strolch/service/Service.java index 3c84a533a..42446cb49 100644 --- a/src/main/java/li/strolch/service/Service.java +++ b/src/main/java/li/strolch/service/Service.java @@ -27,9 +27,7 @@ import ch.eitchnet.privilege.model.Restrictable; * @author Robert von Burg * */ -public interface Service extends Serializable, Restrictable { +public interface Service extends Serializable, Restrictable { - public ServiceResult doService(ServiceArgument argument); - - public ServiceArgument getServiceArgument(); + public ServiceResult doService(T argument); } diff --git a/src/main/java/li/strolch/service/ServiceHandler.java b/src/main/java/li/strolch/service/ServiceHandler.java new file mode 100644 index 000000000..917a9f51a --- /dev/null +++ b/src/main/java/li/strolch/service/ServiceHandler.java @@ -0,0 +1,8 @@ +package li.strolch.service; + +import ch.eitchnet.privilege.model.Certificate; + +public interface ServiceHandler { + + public ServiceResult doService(Certificate certificate, Service service, T argument); +} \ No newline at end of file diff --git a/src/main/java/li/strolch/service/SimpleServiceHandler.java b/src/main/java/li/strolch/service/SimpleServiceHandler.java index 7f38de053..61c221f76 100644 --- a/src/main/java/li/strolch/service/SimpleServiceHandler.java +++ b/src/main/java/li/strolch/service/SimpleServiceHandler.java @@ -21,23 +21,27 @@ package li.strolch.service; import java.text.MessageFormat; +import li.strolch.runtime.component.StrolchComponent; import ch.eitchnet.privilege.handler.PrivilegeHandler; import ch.eitchnet.privilege.model.Certificate; /** * @author Robert von Burg */ -public class SimpleServiceHandler { +public class SimpleServiceHandler extends StrolchComponent implements ServiceHandler { private PrivilegeHandler privilegeHandler; - public ServiceResult doService(Certificate certificate, Service service, ServiceArgument argument) { + @Override + public ServiceResult doService(Certificate certificate, Service service, T argument) { try { this.privilegeHandler.getPrivilegeContext(certificate).validateAction(service); - return service.doService(argument); + ServiceResult serviceResult = service.doService(argument); + + return serviceResult; } catch (Exception e) { String msg = "Failed to perform service {0} due to exception {1}"; //$NON-NLS-1$ From d90c698176923798d7a22f554456b17c8dd51394 Mon Sep 17 00:00:00 2001 From: Robert von Burg Date: Sun, 27 Oct 2013 04:13:05 +0100 Subject: [PATCH 05/65] [Minor] code cleanup --- src/main/java/li/strolch/service/SimpleServiceHandler.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/main/java/li/strolch/service/SimpleServiceHandler.java b/src/main/java/li/strolch/service/SimpleServiceHandler.java index 61c221f76..21ddb8522 100644 --- a/src/main/java/li/strolch/service/SimpleServiceHandler.java +++ b/src/main/java/li/strolch/service/SimpleServiceHandler.java @@ -38,9 +38,7 @@ public class SimpleServiceHandler extends StrolchComponent implements ServiceHan try { this.privilegeHandler.getPrivilegeContext(certificate).validateAction(service); - ServiceResult serviceResult = service.doService(argument); - return serviceResult; } catch (Exception e) { From 9d29dff6c9d72e9b908fbac69b1233375c09a733 Mon Sep 17 00:00:00 2001 From: Robert von Burg Date: Sun, 27 Oct 2013 04:17:48 +0100 Subject: [PATCH 06/65] [Minor] code cleanup --- src/main/java/li/strolch/service/SimpleServiceHandler.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/java/li/strolch/service/SimpleServiceHandler.java b/src/main/java/li/strolch/service/SimpleServiceHandler.java index 21ddb8522..b34e96c03 100644 --- a/src/main/java/li/strolch/service/SimpleServiceHandler.java +++ b/src/main/java/li/strolch/service/SimpleServiceHandler.java @@ -36,7 +36,6 @@ public class SimpleServiceHandler extends StrolchComponent implements ServiceHan public ServiceResult doService(Certificate certificate, Service service, T argument) { try { - this.privilegeHandler.getPrivilegeContext(certificate).validateAction(service); ServiceResult serviceResult = service.doService(argument); return serviceResult; From f04dcdb43e97187da4c8ca881630fab1dd7660aa Mon Sep 17 00:00:00 2001 From: Robert von Burg Date: Mon, 28 Oct 2013 22:07:28 +0100 Subject: [PATCH 07/65] [Minor] added constructor to SimpleServiceHandler --- src/main/java/li/strolch/service/SimpleServiceHandler.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/main/java/li/strolch/service/SimpleServiceHandler.java b/src/main/java/li/strolch/service/SimpleServiceHandler.java index b34e96c03..e525ba69d 100644 --- a/src/main/java/li/strolch/service/SimpleServiceHandler.java +++ b/src/main/java/li/strolch/service/SimpleServiceHandler.java @@ -32,6 +32,10 @@ public class SimpleServiceHandler extends StrolchComponent implements ServiceHan private PrivilegeHandler privilegeHandler; + public SimpleServiceHandler() { + super(ServiceHandler.class.getName()); + } + @Override public ServiceResult doService(Certificate certificate, Service service, T argument) { From 34692df5860cb8fb2f77f618f9c9ee8dc9d908fe Mon Sep 17 00:00:00 2001 From: Robert von Burg Date: Tue, 5 Nov 2013 20:42:20 +0100 Subject: [PATCH 08/65] [Devel] busy implementing a component directed acyclic dependency tree This is needed to start/stop in the right order --- src/main/java/li/strolch/service/SimpleServiceHandler.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/main/java/li/strolch/service/SimpleServiceHandler.java b/src/main/java/li/strolch/service/SimpleServiceHandler.java index e525ba69d..d81b7631c 100644 --- a/src/main/java/li/strolch/service/SimpleServiceHandler.java +++ b/src/main/java/li/strolch/service/SimpleServiceHandler.java @@ -21,6 +21,7 @@ package li.strolch.service; import java.text.MessageFormat; +import li.strolch.runtime.component.ComponentContainer; import li.strolch.runtime.component.StrolchComponent; import ch.eitchnet.privilege.handler.PrivilegeHandler; import ch.eitchnet.privilege.model.Certificate; @@ -32,8 +33,8 @@ public class SimpleServiceHandler extends StrolchComponent implements ServiceHan private PrivilegeHandler privilegeHandler; - public SimpleServiceHandler() { - super(ServiceHandler.class.getName()); + public SimpleServiceHandler(ComponentContainer container) { + super(container, ServiceHandler.class.getName()); } @Override From 30db53611b0cabdc3bee748b2f47e907487e83f7 Mon Sep 17 00:00:00 2001 From: Robert von Burg Date: Thu, 14 Nov 2013 21:36:49 +0100 Subject: [PATCH 09/65] [Minor] fixed an incorrect constructor on SimpleServiceHandler --- src/main/java/li/strolch/service/SimpleServiceHandler.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/li/strolch/service/SimpleServiceHandler.java b/src/main/java/li/strolch/service/SimpleServiceHandler.java index d81b7631c..f11772c6e 100644 --- a/src/main/java/li/strolch/service/SimpleServiceHandler.java +++ b/src/main/java/li/strolch/service/SimpleServiceHandler.java @@ -33,8 +33,8 @@ public class SimpleServiceHandler extends StrolchComponent implements ServiceHan private PrivilegeHandler privilegeHandler; - public SimpleServiceHandler(ComponentContainer container) { - super(container, ServiceHandler.class.getName()); + public SimpleServiceHandler(ComponentContainer container, String componentName) { + super(container, componentName); } @Override From 86db450fb6e248a8052c190e575806d060b66070 Mon Sep 17 00:00:00 2001 From: Robert von Burg Date: Sat, 16 Nov 2013 01:13:13 +0100 Subject: [PATCH 10/65] [New] Implemented ServiceHandler with Privilege validation Performing a Service is as simple as this: GreetingService greetingService = new GreetingService(); GreetingArgument greetingArgument = new GreetingArgument(); greetingArgument.name = "Robert"; GreetingResult greetingResult = serviceHandler. doService(null, greetingService, greetingArgument); assertThat(greetingResult.getGreeting(), containsString("Hello Robert. Nice to meet you!")); --- pom.xml | 5 + .../li/strolch/service/AbstractService.java | 67 +++++++++- .../service/DefaultServiceHandler.java | 106 ++++++++++++++++ src/main/java/li/strolch/service/Service.java | 4 +- .../li/strolch/service/ServiceArgument.java | 4 +- .../li/strolch/service/ServiceHandler.java | 5 +- .../li/strolch/service/ServiceResult.java | 17 ++- .../strolch/service/SimpleServiceHandler.java | 54 -------- .../service/test/AbstractServiceTest.java | 57 +++++++++ .../strolch/service/test/GreetingResult.java | 49 ++++++++ .../strolch/service/test/GreetingService.java | 59 +++++++++ .../service/test/GreetingServiceTest.java | 45 +++++++ .../service/test/NoPrivilegeServiceTest.java | 74 +++++++++++ .../li/strolch/service/test/ServiceTest.java | 119 ++++++++++++++++++ .../li/strolch/service/test/TestService.java | 44 +++++++ src/test/resources/log4j.xml | 29 +++++ .../config/PrivilegeConfig.xml | 53 ++++++++ .../config/PrivilegeModel.xml | 80 ++++++++++++ .../config/StrolchConfiguration.xml | 25 ++++ .../config/StrolchConfiguration.xml | 17 +++ 20 files changed, 851 insertions(+), 62 deletions(-) create mode 100644 src/main/java/li/strolch/service/DefaultServiceHandler.java delete mode 100644 src/main/java/li/strolch/service/SimpleServiceHandler.java create mode 100644 src/test/java/li/strolch/service/test/AbstractServiceTest.java create mode 100644 src/test/java/li/strolch/service/test/GreetingResult.java create mode 100644 src/test/java/li/strolch/service/test/GreetingService.java create mode 100644 src/test/java/li/strolch/service/test/GreetingServiceTest.java create mode 100644 src/test/java/li/strolch/service/test/NoPrivilegeServiceTest.java create mode 100644 src/test/java/li/strolch/service/test/ServiceTest.java create mode 100644 src/test/java/li/strolch/service/test/TestService.java create mode 100644 src/test/resources/log4j.xml create mode 100644 src/test/resources/withPrivilegeRuntime/config/PrivilegeConfig.xml create mode 100644 src/test/resources/withPrivilegeRuntime/config/PrivilegeModel.xml create mode 100644 src/test/resources/withPrivilegeRuntime/config/StrolchConfiguration.xml create mode 100644 src/test/resources/withoutPrivilegeRuntime/config/StrolchConfiguration.xml diff --git a/pom.xml b/pom.xml index 267f0a731..b5515a09e 100644 --- a/pom.xml +++ b/pom.xml @@ -52,6 +52,11 @@ ch.eitchnet ch.eitchnet.privilege + + + li.strolch + li.strolch.testbase + diff --git a/src/main/java/li/strolch/service/AbstractService.java b/src/main/java/li/strolch/service/AbstractService.java index b96b68f55..0480a295d 100644 --- a/src/main/java/li/strolch/service/AbstractService.java +++ b/src/main/java/li/strolch/service/AbstractService.java @@ -19,13 +19,78 @@ */ package li.strolch.service; +import java.text.MessageFormat; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + /** * @author Robert von Burg * */ -public abstract class AbstractService implements Service { +public abstract class AbstractService implements Service { + + protected static final Logger logger = LoggerFactory.getLogger(AbstractService.class); private static final long serialVersionUID = 1L; + @Override + public final U doService(T argument) { + + if (isArgumentRequired() && argument == null) { + + String msg = "Failed to perform service {0} because no argument was passed although it is required!"; //$NON-NLS-1$ + msg = MessageFormat.format(msg, getClass()); + logger.error(msg); + + U result = getResultInstance(); + result.setState(ServiceResultState.FAILED); + result.setMessage(msg); + return result; + } + + try { + + return internalDoService(argument); + + } catch (Exception e) { + + String msg = "Failed to perform service {0} due to {1}"; //$NON-NLS-1$ + msg = MessageFormat.format(msg, getClass(), e.getMessage()); + logger.error(msg, e); + + U result = getResultInstance(); + result.setState(ServiceResultState.FAILED); + result.setMessage(msg); + result.setThrowable(e); + return result; + } + } + + /** + * @return if true, then an argument must be set to execute the service. If the argument is missing, then the + * service execution fails immediately + */ + protected boolean isArgumentRequired() { + return true; + } + + /** + * This method is called if the service execution fails and an instance of the expected {@link ServiceResult} is + * required to return to the caller + * + * @return + */ + protected abstract U getResultInstance(); + + /** + * Internal method to perform the {@link Service}. The implementor does not need to handle exceptions as this is + * done in the {@link #doService(ServiceArgument)} which calls this method + * + * @param argument + * @return + */ + protected abstract U internalDoService(T argument); + /** * @see ch.eitchnet.privilege.model.Restrictable#getPrivilegeName() */ diff --git a/src/main/java/li/strolch/service/DefaultServiceHandler.java b/src/main/java/li/strolch/service/DefaultServiceHandler.java new file mode 100644 index 000000000..530a79aaf --- /dev/null +++ b/src/main/java/li/strolch/service/DefaultServiceHandler.java @@ -0,0 +1,106 @@ +/* + * Copyright (c) 2012, Robert von Burg + * + * All rights reserved. + * + * This file is part of the XXX. + * + * XXX is free software: you can redistribute + * it and/or modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the License, + * or (at your option) any later version. + * + * XXX is distributed in the hope that it will + * be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with XXX. If not, see + * . + */ +package li.strolch.service; + +import java.text.MessageFormat; + +import li.strolch.exception.StrolchException; +import li.strolch.runtime.component.ComponentContainer; +import li.strolch.runtime.component.StrolchComponent; +import li.strolch.runtime.configuration.ComponentConfiguration; +import li.strolch.runtime.privilege.StrolchPrivilegeHandler; +import ch.eitchnet.privilege.model.Certificate; +import ch.eitchnet.privilege.model.PrivilegeContext; +import ch.eitchnet.utils.helper.StringHelper; + +/** + * @author Robert von Burg + * + */ +public class DefaultServiceHandler extends StrolchComponent implements ServiceHandler { + + private StrolchPrivilegeHandler privilegeHandler; + + /** + * @param container + * @param componentName + */ + public DefaultServiceHandler(ComponentContainer container, String componentName) { + super(container, componentName); + } + + @Override + public U doService(Certificate certificate, Service service) { + return doService(certificate, service, null); + } + + @Override + public U doService(Certificate certificate, + Service service, T argument) { + + long start = System.nanoTime(); + + // first check that the caller may perform this service + if (this.privilegeHandler != null) { + // XXX Bad bad bad: remove the need for thread locals... + try { + PrivilegeContext privilegeContext = this.privilegeHandler.getPrivilegeContext(certificate); + PrivilegeContext.set(privilegeContext); + privilegeContext.validateAction(service); + } finally { + PrivilegeContext.set(null); + } + } + + try { + // then perform the service + U serviceResult = service.doService(argument); + + // log the result + long end = System.nanoTime(); + String msg = "Service {0} took {1}"; //$NON-NLS-1$ + msg = MessageFormat.format(msg, service, StringHelper.formatNanoDuration(end - start)); + if (serviceResult.getState() == ServiceResultState.SUCCESS) + logger.info(msg); + else if (serviceResult.getState() == ServiceResultState.WARNING) + logger.warn(msg); + else if (serviceResult.getState() == ServiceResultState.FAILED) + logger.error(msg); + + return serviceResult; + + } catch (Exception e) { + long end = System.nanoTime(); + String msg = "Failed to perform service {0} after {1} due to {2}"; //$NON-NLS-1$ + msg = MessageFormat.format(msg, service, StringHelper.formatNanoDuration(end - start), e.getMessage()); + logger.error(msg, e); + throw new StrolchException(msg, e); + } + } + + @Override + public void initialize(ComponentConfiguration configuration) { + if (getContainer().hasComponent(StrolchPrivilegeHandler.class)) + this.privilegeHandler = getContainer().getComponent(StrolchPrivilegeHandler.class); + super.initialize(configuration); + } +} diff --git a/src/main/java/li/strolch/service/Service.java b/src/main/java/li/strolch/service/Service.java index 42446cb49..51d5b4456 100644 --- a/src/main/java/li/strolch/service/Service.java +++ b/src/main/java/li/strolch/service/Service.java @@ -27,7 +27,7 @@ import ch.eitchnet.privilege.model.Restrictable; * @author Robert von Burg * */ -public interface Service extends Serializable, Restrictable { +public interface Service extends Serializable, Restrictable { - public ServiceResult doService(T argument); + public U doService(T argument); } diff --git a/src/main/java/li/strolch/service/ServiceArgument.java b/src/main/java/li/strolch/service/ServiceArgument.java index 1e0aca9c7..c596f2895 100644 --- a/src/main/java/li/strolch/service/ServiceArgument.java +++ b/src/main/java/li/strolch/service/ServiceArgument.java @@ -23,9 +23,9 @@ import java.io.Serializable; /** * @author Robert von Burg - * */ -public interface ServiceArgument extends Serializable { +public class ServiceArgument implements Serializable { + private static final long serialVersionUID = 1L; // marker interface } diff --git a/src/main/java/li/strolch/service/ServiceHandler.java b/src/main/java/li/strolch/service/ServiceHandler.java index 917a9f51a..1daf1c983 100644 --- a/src/main/java/li/strolch/service/ServiceHandler.java +++ b/src/main/java/li/strolch/service/ServiceHandler.java @@ -4,5 +4,8 @@ import ch.eitchnet.privilege.model.Certificate; public interface ServiceHandler { - public ServiceResult doService(Certificate certificate, Service service, T argument); + public U doService(Certificate certificate, + Service service, T argument); + + public U doService(Certificate certificate, Service service); } \ No newline at end of file diff --git a/src/main/java/li/strolch/service/ServiceResult.java b/src/main/java/li/strolch/service/ServiceResult.java index 8c55fb5f1..d9b6b3c3e 100644 --- a/src/main/java/li/strolch/service/ServiceResult.java +++ b/src/main/java/li/strolch/service/ServiceResult.java @@ -19,16 +19,29 @@ */ package li.strolch.service; +import java.io.Serializable; + /** * @author Robert von Burg * */ -public class ServiceResult { - +public class ServiceResult implements Serializable { + private static final long serialVersionUID = 1L; private ServiceResultState state; private String message; private Throwable throwable; + public ServiceResult() { + // + } + + /** + * @param state + */ + public ServiceResult(ServiceResultState state) { + this.state = state; + } + /** * @param state * @param message diff --git a/src/main/java/li/strolch/service/SimpleServiceHandler.java b/src/main/java/li/strolch/service/SimpleServiceHandler.java deleted file mode 100644 index f11772c6e..000000000 --- a/src/main/java/li/strolch/service/SimpleServiceHandler.java +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Copyright (c) 2012 - * - * This file is part of ??????????????? - * - * ?????????????? is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Privilege is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with ????????????????. If not, see . - * - */ -package li.strolch.service; - -import java.text.MessageFormat; - -import li.strolch.runtime.component.ComponentContainer; -import li.strolch.runtime.component.StrolchComponent; -import ch.eitchnet.privilege.handler.PrivilegeHandler; -import ch.eitchnet.privilege.model.Certificate; - -/** - * @author Robert von Burg - */ -public class SimpleServiceHandler extends StrolchComponent implements ServiceHandler { - - private PrivilegeHandler privilegeHandler; - - public SimpleServiceHandler(ComponentContainer container, String componentName) { - super(container, componentName); - } - - @Override - public ServiceResult doService(Certificate certificate, Service service, T argument) { - - try { - this.privilegeHandler.getPrivilegeContext(certificate).validateAction(service); - ServiceResult serviceResult = service.doService(argument); - return serviceResult; - - } catch (Exception e) { - String msg = "Failed to perform service {0} due to exception {1}"; //$NON-NLS-1$ - String error = MessageFormat.format(msg, service.getClass().getName(), e.getMessage()); - return ServiceResult.failed(error, e); - } - } -} diff --git a/src/test/java/li/strolch/service/test/AbstractServiceTest.java b/src/test/java/li/strolch/service/test/AbstractServiceTest.java new file mode 100644 index 000000000..fddced1d2 --- /dev/null +++ b/src/test/java/li/strolch/service/test/AbstractServiceTest.java @@ -0,0 +1,57 @@ +/* + * Copyright (c) 2012, Robert von Burg + * + * All rights reserved. + * + * This file is part of the XXX. + * + * XXX is free software: you can redistribute + * it and/or modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the License, + * or (at your option) any later version. + * + * XXX is distributed in the hope that it will + * be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with XXX. If not, see + * . + */ +package li.strolch.service.test; + +import java.io.File; + +import li.strolch.service.ServiceHandler; +import li.strolch.testbase.runtime.RuntimeMock; + +import org.junit.AfterClass; +import org.junit.BeforeClass; + +/** + * @author Robert von Burg + */ +public abstract class AbstractServiceTest extends RuntimeMock { + + private static final String RUNTIME_PATH = "target/strolchRuntime/"; //$NON-NLS-1$ + private static final String CONFIG_SRC = "src/test/resources/withPrivilegeRuntime/config"; //$NON-NLS-1$ + protected static ServiceHandler serviceHandler; + + @BeforeClass + public static void beforeClass() { + + File rootPath = new File(RUNTIME_PATH); + File configSrc = new File(CONFIG_SRC); + RuntimeMock.mockRuntime(rootPath, configSrc); + RuntimeMock.startContainer(rootPath); + + // initialize the component configuration + serviceHandler = getContainer().getComponent(ServiceHandler.class); + } + + @AfterClass + public static void afterClass() { + RuntimeMock.destroyRuntime(); + } +} diff --git a/src/test/java/li/strolch/service/test/GreetingResult.java b/src/test/java/li/strolch/service/test/GreetingResult.java new file mode 100644 index 000000000..452dbc850 --- /dev/null +++ b/src/test/java/li/strolch/service/test/GreetingResult.java @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2012, Robert von Burg + * + * All rights reserved. + * + * This file is part of the XXX. + * + * XXX is free software: you can redistribute + * it and/or modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the License, + * or (at your option) any later version. + * + * XXX is distributed in the hope that it will + * be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with XXX. If not, see + * . + */ +package li.strolch.service.test; + +import li.strolch.service.ServiceResult; +import li.strolch.service.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/src/test/java/li/strolch/service/test/GreetingService.java b/src/test/java/li/strolch/service/test/GreetingService.java new file mode 100644 index 000000000..99149f2e7 --- /dev/null +++ b/src/test/java/li/strolch/service/test/GreetingService.java @@ -0,0 +1,59 @@ +/* + * Copyright (c) 2012, Robert von Burg + * + * All rights reserved. + * + * This file is part of the XXX. + * + * XXX is free software: you can redistribute + * it and/or modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the License, + * or (at your option) any later version. + * + * XXX is distributed in the hope that it will + * be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with XXX. If not, see + * . + */ +package li.strolch.service.test; + +import java.text.MessageFormat; + +import li.strolch.service.AbstractService; +import li.strolch.service.ServiceArgument; +import li.strolch.service.test.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/src/test/java/li/strolch/service/test/GreetingServiceTest.java b/src/test/java/li/strolch/service/test/GreetingServiceTest.java new file mode 100644 index 000000000..9a1f32b3f --- /dev/null +++ b/src/test/java/li/strolch/service/test/GreetingServiceTest.java @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2012, Robert von Burg + * + * All rights reserved. + * + * This file is part of the XXX. + * + * XXX is free software: you can redistribute + * it and/or modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the License, + * or (at your option) any later version. + * + * XXX is distributed in the hope that it will + * be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with XXX. If not, see + * . + */ +package li.strolch.service.test; + +import static org.hamcrest.Matchers.containsString; +import static org.junit.Assert.assertThat; +import li.strolch.service.test.GreetingService.GreetingArgument; + +import org.junit.Test; + +/** + * @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$ + + GreetingResult greetingResult = serviceHandler.doService(null, greetingService, greetingArgument); + assertThat(greetingResult.getGreeting(), containsString("Hello Robert. Nice to meet you!")); //$NON-NLS-1$ + } +} diff --git a/src/test/java/li/strolch/service/test/NoPrivilegeServiceTest.java b/src/test/java/li/strolch/service/test/NoPrivilegeServiceTest.java new file mode 100644 index 000000000..19aed9f51 --- /dev/null +++ b/src/test/java/li/strolch/service/test/NoPrivilegeServiceTest.java @@ -0,0 +1,74 @@ +/* + * Copyright (c) 2012, Robert von Burg + * + * All rights reserved. + * + * This file is part of the XXX. + * + * XXX is free software: you can redistribute + * it and/or modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the License, + * or (at your option) any later version. + * + * XXX is distributed in the hope that it will + * be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with XXX. If not, see + * . + */ +package li.strolch.service.test; + +import static org.hamcrest.Matchers.containsString; +import static org.junit.Assert.assertThat; + +import java.io.File; + +import li.strolch.service.ServiceHandler; +import li.strolch.service.test.GreetingService.GreetingArgument; +import li.strolch.testbase.runtime.RuntimeMock; + +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.Test; + +/** + * @author Robert von Burg + * + */ +public class NoPrivilegeServiceTest extends RuntimeMock { + + private static final String RUNTIME_PATH = "target/strolchRuntime/"; //$NON-NLS-1$ + private static final String CONFIG_SRC = "src/test/resources/withoutPrivilegeRuntime/config"; //$NON-NLS-1$ + protected static ServiceHandler serviceHandler; + + @BeforeClass + public static void beforeClass() { + + File rootPath = new File(RUNTIME_PATH); + File configSrc = new File(CONFIG_SRC); + RuntimeMock.mockRuntime(rootPath, configSrc); + RuntimeMock.startContainer(rootPath); + + // initialize the component configuration + serviceHandler = getContainer().getComponent(ServiceHandler.class); + } + + @AfterClass + public static void afterClass() { + RuntimeMock.destroyRuntime(); + } + + @Test + public void shouldPerformSimpleService() { + + GreetingService greetingService = new GreetingService(); + GreetingArgument greetingArgument = new GreetingArgument(); + greetingArgument.name = "Robert"; //$NON-NLS-1$ + + GreetingResult greetingResult = serviceHandler.doService(null, greetingService, greetingArgument); + assertThat(greetingResult.getGreeting(), containsString("Hello Robert. Nice to meet you!")); //$NON-NLS-1$ + } +} diff --git a/src/test/java/li/strolch/service/test/ServiceTest.java b/src/test/java/li/strolch/service/test/ServiceTest.java new file mode 100644 index 000000000..2faa1a9b9 --- /dev/null +++ b/src/test/java/li/strolch/service/test/ServiceTest.java @@ -0,0 +1,119 @@ +/* + * Copyright (c) 2012, Robert von Burg + * + * All rights reserved. + * + * This file is part of the XXX. + * + * XXX is free software: you can redistribute + * it and/or modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the License, + * or (at your option) any later version. + * + * XXX is distributed in the hope that it will + * be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with XXX. If not, see + * . + */ +package li.strolch.service.test; + +import static org.hamcrest.Matchers.equalTo; +import static org.junit.Assert.assertThat; +import li.strolch.service.test.GreetingService.GreetingArgument; + +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(); + serviceHandler.doService(null, testService); + } + + @Test + public void shouldFailInvalidCertificate1() { + this.thrown.expect(PrivilegeException.class); + TestService testService = new TestService(); + serviceHandler.doService(new Certificate(null, 0, 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", "dsdf", "dferg", null, null); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ + serviceHandler.doService(badCert, testService); + } + + @Test + public void shouldFailWithNoAccess() { + this.thrown.expect(AccessDeniedException.class); + this.thrown.expectMessage("User jill does not have Privilege li.strolch.service.Service"); //$NON-NLS-1$ + + Certificate certificate = getPrivilegeHandler().authenticate("jill", "jill".getBytes()); //$NON-NLS-1$//$NON-NLS-2$ + try { + TestService testService = new TestService(); + serviceHandler.doService(certificate, testService); + } finally { + getPrivilegeHandler().invalidateSession(certificate); + } + } + + @Test + public void shouldNotFailWithAccess() { + Certificate certificate = 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 = serviceHandler.doService(certificate, service, argument); + assertThat(greetingResult.getGreeting(), equalTo("Hello Jill. Nice to meet you!")); //$NON-NLS-1$ + } finally { + getPrivilegeHandler().invalidateSession(certificate); + } + } + + @Test + public void shouldNotFailWithLogin1() { + + Certificate certificate = getPrivilegeHandler().authenticate("bob", "bob".getBytes()); //$NON-NLS-1$//$NON-NLS-2$ + try { + TestService testService = new TestService(); + serviceHandler.doService(certificate, testService); + } finally { + getPrivilegeHandler().invalidateSession(certificate); + } + } + + @Test + public void shouldNotFailWithLogin2() { + Certificate certificate = 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 = serviceHandler.doService(certificate, service, argument); + assertThat(greetingResult.getGreeting(), equalTo("Hello Bob. Nice to meet you!")); //$NON-NLS-1$ + } finally { + getPrivilegeHandler().invalidateSession(certificate); + } + } +} diff --git a/src/test/java/li/strolch/service/test/TestService.java b/src/test/java/li/strolch/service/test/TestService.java new file mode 100644 index 000000000..908f3447d --- /dev/null +++ b/src/test/java/li/strolch/service/test/TestService.java @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2012, Robert von Burg + * + * All rights reserved. + * + * This file is part of the XXX. + * + * XXX is free software: you can redistribute + * it and/or modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the License, + * or (at your option) any later version. + * + * XXX is distributed in the hope that it will + * be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with XXX. If not, see + * . + */ +package li.strolch.service.test; + +import li.strolch.service.AbstractService; +import li.strolch.service.ServiceArgument; +import li.strolch.service.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/src/test/resources/log4j.xml b/src/test/resources/log4j.xml new file mode 100644 index 000000000..a35a3c351 --- /dev/null +++ b/src/test/resources/log4j.xml @@ -0,0 +1,29 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/test/resources/withPrivilegeRuntime/config/PrivilegeConfig.xml b/src/test/resources/withPrivilegeRuntime/config/PrivilegeConfig.xml new file mode 100644 index 000000000..53c39f016 --- /dev/null +++ b/src/test/resources/withPrivilegeRuntime/config/PrivilegeConfig.xml @@ -0,0 +1,53 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/test/resources/withPrivilegeRuntime/config/PrivilegeModel.xml b/src/test/resources/withPrivilegeRuntime/config/PrivilegeModel.xml new file mode 100644 index 000000000..b4d091961 --- /dev/null +++ b/src/test/resources/withPrivilegeRuntime/config/PrivilegeModel.xml @@ -0,0 +1,80 @@ + + + + + + + + Application + Administrator + ENABLED + en_GB + + PrivilegeAdmin + AppUser + + + + + + + + + Bob + Bernstein + ENABLED + en_GB + + AppUser + + + + + Jill + Johnson + ENABLED + en_GB + + OnlyGreetingServiceRole + + + + + System User + Administrator + SYSTEM + en_GB + + sysAdmin + AppUser + + + + + + + + + + + + true + + + + + + + + + li.strolch.service.test.GreetingService + + + + + \ No newline at end of file diff --git a/src/test/resources/withPrivilegeRuntime/config/StrolchConfiguration.xml b/src/test/resources/withPrivilegeRuntime/config/StrolchConfiguration.xml new file mode 100644 index 000000000..fc75c2c82 --- /dev/null +++ b/src/test/resources/withPrivilegeRuntime/config/StrolchConfiguration.xml @@ -0,0 +1,25 @@ + + + + StrolchPersistenceTest + + true + + + + ServiceHandler + li.strolch.service.ServiceHandler + li.strolch.service.DefaultServiceHandler + + true + + + + PrivilegeHandler + li.strolch.runtime.privilege.StrolchPrivilegeHandler + li.strolch.runtime.privilege.DefaultStrolchPrivilegeHandler + + PrivilegeConfig.xml + + + \ No newline at end of file diff --git a/src/test/resources/withoutPrivilegeRuntime/config/StrolchConfiguration.xml b/src/test/resources/withoutPrivilegeRuntime/config/StrolchConfiguration.xml new file mode 100644 index 000000000..86fd69ae1 --- /dev/null +++ b/src/test/resources/withoutPrivilegeRuntime/config/StrolchConfiguration.xml @@ -0,0 +1,17 @@ + + + + StrolchPersistenceTest + + true + + + + ServiceHandler + li.strolch.service.ServiceHandler + li.strolch.service.DefaultServiceHandler + + true + + + \ No newline at end of file From f49f113b708ca6a9843b57058c61f65ac3646627 Mon Sep 17 00:00:00 2001 From: Robert von Burg Date: Mon, 25 Nov 2013 18:53:53 +0100 Subject: [PATCH 11/65] [New] Implemented EMPTY and TRANSIENT dataStoreModes. Refactored Agent to be responsible for starting the container. And it requires the runtime configuration. --- .../li/strolch/service/test/GreetingServiceTest.java | 11 +++++++++-- .../config/StrolchConfiguration.xml | 1 + .../config/StrolchConfiguration.xml | 1 + 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/test/java/li/strolch/service/test/GreetingServiceTest.java b/src/test/java/li/strolch/service/test/GreetingServiceTest.java index 9a1f32b3f..2a4f11602 100644 --- a/src/test/java/li/strolch/service/test/GreetingServiceTest.java +++ b/src/test/java/li/strolch/service/test/GreetingServiceTest.java @@ -27,6 +27,8 @@ import li.strolch.service.test.GreetingService.GreetingArgument; import org.junit.Test; +import ch.eitchnet.privilege.model.Certificate; + /** * @author Robert von Burg */ @@ -39,7 +41,12 @@ public class GreetingServiceTest extends AbstractServiceTest { GreetingArgument greetingArgument = new GreetingArgument(); greetingArgument.name = "Robert"; //$NON-NLS-1$ - GreetingResult greetingResult = serviceHandler.doService(null, greetingService, greetingArgument); - assertThat(greetingResult.getGreeting(), containsString("Hello Robert. Nice to meet you!")); //$NON-NLS-1$ + Certificate certificate = getPrivilegeHandler().authenticate("jill", "jill".getBytes()); //$NON-NLS-1$//$NON-NLS-2$ + try { + GreetingResult greetingResult = serviceHandler.doService(certificate, greetingService, greetingArgument); + assertThat(greetingResult.getGreeting(), containsString("Hello Robert. Nice to meet you!")); //$NON-NLS-1$ + } finally { + getPrivilegeHandler().invalidateSession(certificate); + } } } diff --git a/src/test/resources/withPrivilegeRuntime/config/StrolchConfiguration.xml b/src/test/resources/withPrivilegeRuntime/config/StrolchConfiguration.xml index fc75c2c82..fb9ed15a5 100644 --- a/src/test/resources/withPrivilegeRuntime/config/StrolchConfiguration.xml +++ b/src/test/resources/withPrivilegeRuntime/config/StrolchConfiguration.xml @@ -3,6 +3,7 @@ StrolchPersistenceTest + EMPTY true diff --git a/src/test/resources/withoutPrivilegeRuntime/config/StrolchConfiguration.xml b/src/test/resources/withoutPrivilegeRuntime/config/StrolchConfiguration.xml index 86fd69ae1..76e96a2c8 100644 --- a/src/test/resources/withoutPrivilegeRuntime/config/StrolchConfiguration.xml +++ b/src/test/resources/withoutPrivilegeRuntime/config/StrolchConfiguration.xml @@ -3,6 +3,7 @@ StrolchPersistenceTest + EMPTY true From 2008fb49c64f75931c61dcd7df04b4586832aa1d Mon Sep 17 00:00:00 2001 From: Robert von Burg Date: Sun, 15 Dec 2013 13:10:27 +0100 Subject: [PATCH 12/65] [Project] Changed all licence references to Apache License 2.0 --- LICENSE | 309 +++++++++--------- src/main/java/li/strolch/command/Command.java | 29 +- .../li/strolch/service/AbstractService.java | 28 +- .../service/DefaultServiceHandler.java | 32 +- src/main/java/li/strolch/service/Service.java | 28 +- .../li/strolch/service/ServiceArgument.java | 28 +- .../li/strolch/service/ServiceHandler.java | 15 + .../li/strolch/service/ServiceResult.java | 28 +- .../strolch/service/ServiceResultState.java | 28 +- .../service/test/AbstractServiceTest.java | 32 +- .../strolch/service/test/GreetingResult.java | 32 +- .../strolch/service/test/GreetingService.java | 32 +- .../service/test/GreetingServiceTest.java | 32 +- .../service/test/NoPrivilegeServiceTest.java | 32 +- .../li/strolch/service/test/ServiceTest.java | 32 +- .../li/strolch/service/test/TestService.java | 32 +- .../config/PrivilegeConfig.xml | 23 -- .../config/PrivilegeModel.xml | 6 - 18 files changed, 352 insertions(+), 426 deletions(-) diff --git a/LICENSE b/LICENSE index 37ec93a14..d64569567 100644 --- a/LICENSE +++ b/LICENSE @@ -1,180 +1,191 @@ -Apache License -Version 2.0, January 2004 -http://www.apache.org/licenses/ -TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ -1. Definitions. + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION -"License" shall mean the terms and conditions for use, reproduction, and -distribution as defined by Sections 1 through 9 of this document. + 1. Definitions. -"Licensor" shall mean the copyright owner or entity authorized by the copyright -owner that is granting the License. + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. -"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. + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. -"You" (or "Your") shall mean an individual or Legal Entity exercising -permissions granted by this 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. -"Source" form shall mean the preferred form for making modifications, including -but not limited to software source code, documentation source, and configuration -files. + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. -"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. + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. -"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). + "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. -"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. + "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). -"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." + "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. -"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. + "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." -2. Grant of Copyright License. + "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. -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. + 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. + 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. -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: -4. Redistribution. + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and -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: + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and -You must give any other recipients of the Work or Derivative Works a copy of -this License; and -You must cause any modified files to carry prominent notices stating that You -changed the files; and -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 -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. + (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 -5. Submission of Contributions. + (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. -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. + 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. -6. Trademarks. + 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. -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. + 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. + 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. -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. -8. Limitation of Liability. + 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. -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. + END OF TERMS AND CONDITIONS -9. Accepting Warranty or Additional Liability. + APPENDIX: How to apply the Apache License to your work. -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. + 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] @@ -182,7 +193,7 @@ third-party archives. 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 + 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, diff --git a/src/main/java/li/strolch/command/Command.java b/src/main/java/li/strolch/command/Command.java index f447f41c9..e9edfcf41 100644 --- a/src/main/java/li/strolch/command/Command.java +++ b/src/main/java/li/strolch/command/Command.java @@ -1,22 +1,19 @@ /* - * Copyright (c) 2012 - * - * This file is part of ??????????????? - * - * ?????????????? is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Privilege is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with ????????????????. If not, see . + * 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.persistence.api.StrolchTransaction; diff --git a/src/main/java/li/strolch/service/AbstractService.java b/src/main/java/li/strolch/service/AbstractService.java index 0480a295d..e2d296e48 100644 --- a/src/main/java/li/strolch/service/AbstractService.java +++ b/src/main/java/li/strolch/service/AbstractService.java @@ -1,21 +1,17 @@ /* - * Copyright (c) 2012 - * - * This file is part of ??????????????? - * - * ?????????????? is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Privilege is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with ????????????????. If not, see . + * 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; diff --git a/src/main/java/li/strolch/service/DefaultServiceHandler.java b/src/main/java/li/strolch/service/DefaultServiceHandler.java index 530a79aaf..6b940408f 100644 --- a/src/main/java/li/strolch/service/DefaultServiceHandler.java +++ b/src/main/java/li/strolch/service/DefaultServiceHandler.java @@ -1,23 +1,17 @@ /* - * Copyright (c) 2012, Robert von Burg - * - * All rights reserved. - * - * This file is part of the XXX. - * - * XXX is free software: you can redistribute - * it and/or modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation, either version 3 of the License, - * or (at your option) any later version. - * - * XXX is distributed in the hope that it will - * be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with XXX. If not, see - * . + * 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; diff --git a/src/main/java/li/strolch/service/Service.java b/src/main/java/li/strolch/service/Service.java index 51d5b4456..174d8d26e 100644 --- a/src/main/java/li/strolch/service/Service.java +++ b/src/main/java/li/strolch/service/Service.java @@ -1,21 +1,17 @@ /* - * Copyright (c) 2012 - * - * This file is part of ??????????????? - * - * ?????????????? is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Privilege is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with ????????????????. If not, see . + * 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; diff --git a/src/main/java/li/strolch/service/ServiceArgument.java b/src/main/java/li/strolch/service/ServiceArgument.java index c596f2895..560717086 100644 --- a/src/main/java/li/strolch/service/ServiceArgument.java +++ b/src/main/java/li/strolch/service/ServiceArgument.java @@ -1,21 +1,17 @@ /* - * Copyright (c) 2012 - * - * This file is part of ??????????????? - * - * ?????????????? is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Privilege is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with ????????????????. If not, see . + * 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; diff --git a/src/main/java/li/strolch/service/ServiceHandler.java b/src/main/java/li/strolch/service/ServiceHandler.java index 1daf1c983..334ca95c0 100644 --- a/src/main/java/li/strolch/service/ServiceHandler.java +++ b/src/main/java/li/strolch/service/ServiceHandler.java @@ -1,3 +1,18 @@ +/* + * 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 ch.eitchnet.privilege.model.Certificate; diff --git a/src/main/java/li/strolch/service/ServiceResult.java b/src/main/java/li/strolch/service/ServiceResult.java index d9b6b3c3e..5ce54d75d 100644 --- a/src/main/java/li/strolch/service/ServiceResult.java +++ b/src/main/java/li/strolch/service/ServiceResult.java @@ -1,21 +1,17 @@ /* - * Copyright (c) 2012 - * - * This file is part of ??????????????? - * - * ?????????????? is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Privilege is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with ????????????????. If not, see . + * 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; diff --git a/src/main/java/li/strolch/service/ServiceResultState.java b/src/main/java/li/strolch/service/ServiceResultState.java index 5b9fd233e..9037211e9 100644 --- a/src/main/java/li/strolch/service/ServiceResultState.java +++ b/src/main/java/li/strolch/service/ServiceResultState.java @@ -1,21 +1,17 @@ /* - * Copyright (c) 2012 - * - * This file is part of ??????????????? - * - * ?????????????? is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Privilege is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with ????????????????. If not, see . + * 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; diff --git a/src/test/java/li/strolch/service/test/AbstractServiceTest.java b/src/test/java/li/strolch/service/test/AbstractServiceTest.java index fddced1d2..89d1659f3 100644 --- a/src/test/java/li/strolch/service/test/AbstractServiceTest.java +++ b/src/test/java/li/strolch/service/test/AbstractServiceTest.java @@ -1,23 +1,17 @@ /* - * Copyright (c) 2012, Robert von Burg - * - * All rights reserved. - * - * This file is part of the XXX. - * - * XXX is free software: you can redistribute - * it and/or modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation, either version 3 of the License, - * or (at your option) any later version. - * - * XXX is distributed in the hope that it will - * be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with XXX. If not, see - * . + * 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; diff --git a/src/test/java/li/strolch/service/test/GreetingResult.java b/src/test/java/li/strolch/service/test/GreetingResult.java index 452dbc850..656dedc4e 100644 --- a/src/test/java/li/strolch/service/test/GreetingResult.java +++ b/src/test/java/li/strolch/service/test/GreetingResult.java @@ -1,23 +1,17 @@ /* - * Copyright (c) 2012, Robert von Burg - * - * All rights reserved. - * - * This file is part of the XXX. - * - * XXX is free software: you can redistribute - * it and/or modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation, either version 3 of the License, - * or (at your option) any later version. - * - * XXX is distributed in the hope that it will - * be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with XXX. If not, see - * . + * 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; diff --git a/src/test/java/li/strolch/service/test/GreetingService.java b/src/test/java/li/strolch/service/test/GreetingService.java index 99149f2e7..b599034fd 100644 --- a/src/test/java/li/strolch/service/test/GreetingService.java +++ b/src/test/java/li/strolch/service/test/GreetingService.java @@ -1,23 +1,17 @@ /* - * Copyright (c) 2012, Robert von Burg - * - * All rights reserved. - * - * This file is part of the XXX. - * - * XXX is free software: you can redistribute - * it and/or modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation, either version 3 of the License, - * or (at your option) any later version. - * - * XXX is distributed in the hope that it will - * be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with XXX. If not, see - * . + * 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; diff --git a/src/test/java/li/strolch/service/test/GreetingServiceTest.java b/src/test/java/li/strolch/service/test/GreetingServiceTest.java index 2a4f11602..f426cea9c 100644 --- a/src/test/java/li/strolch/service/test/GreetingServiceTest.java +++ b/src/test/java/li/strolch/service/test/GreetingServiceTest.java @@ -1,23 +1,17 @@ /* - * Copyright (c) 2012, Robert von Burg - * - * All rights reserved. - * - * This file is part of the XXX. - * - * XXX is free software: you can redistribute - * it and/or modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation, either version 3 of the License, - * or (at your option) any later version. - * - * XXX is distributed in the hope that it will - * be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with XXX. If not, see - * . + * 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; diff --git a/src/test/java/li/strolch/service/test/NoPrivilegeServiceTest.java b/src/test/java/li/strolch/service/test/NoPrivilegeServiceTest.java index 19aed9f51..cb8b22f48 100644 --- a/src/test/java/li/strolch/service/test/NoPrivilegeServiceTest.java +++ b/src/test/java/li/strolch/service/test/NoPrivilegeServiceTest.java @@ -1,23 +1,17 @@ /* - * Copyright (c) 2012, Robert von Burg - * - * All rights reserved. - * - * This file is part of the XXX. - * - * XXX is free software: you can redistribute - * it and/or modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation, either version 3 of the License, - * or (at your option) any later version. - * - * XXX is distributed in the hope that it will - * be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with XXX. If not, see - * . + * 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; diff --git a/src/test/java/li/strolch/service/test/ServiceTest.java b/src/test/java/li/strolch/service/test/ServiceTest.java index 2faa1a9b9..0e01e58d0 100644 --- a/src/test/java/li/strolch/service/test/ServiceTest.java +++ b/src/test/java/li/strolch/service/test/ServiceTest.java @@ -1,23 +1,17 @@ /* - * Copyright (c) 2012, Robert von Burg - * - * All rights reserved. - * - * This file is part of the XXX. - * - * XXX is free software: you can redistribute - * it and/or modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation, either version 3 of the License, - * or (at your option) any later version. - * - * XXX is distributed in the hope that it will - * be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with XXX. If not, see - * . + * 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; diff --git a/src/test/java/li/strolch/service/test/TestService.java b/src/test/java/li/strolch/service/test/TestService.java index 908f3447d..d53d59291 100644 --- a/src/test/java/li/strolch/service/test/TestService.java +++ b/src/test/java/li/strolch/service/test/TestService.java @@ -1,23 +1,17 @@ /* - * Copyright (c) 2012, Robert von Burg - * - * All rights reserved. - * - * This file is part of the XXX. - * - * XXX is free software: you can redistribute - * it and/or modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation, either version 3 of the License, - * or (at your option) any later version. - * - * XXX is distributed in the hope that it will - * be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with XXX. If not, see - * . + * 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; diff --git a/src/test/resources/withPrivilegeRuntime/config/PrivilegeConfig.xml b/src/test/resources/withPrivilegeRuntime/config/PrivilegeConfig.xml index 53c39f016..9d7a227e3 100644 --- a/src/test/resources/withPrivilegeRuntime/config/PrivilegeConfig.xml +++ b/src/test/resources/withPrivilegeRuntime/config/PrivilegeConfig.xml @@ -1,27 +1,4 @@ - - diff --git a/src/test/resources/withPrivilegeRuntime/config/PrivilegeModel.xml b/src/test/resources/withPrivilegeRuntime/config/PrivilegeModel.xml index b4d091961..28c007077 100644 --- a/src/test/resources/withPrivilegeRuntime/config/PrivilegeModel.xml +++ b/src/test/resources/withPrivilegeRuntime/config/PrivilegeModel.xml @@ -1,10 +1,4 @@ - From 2b1dd1b0a31917b7b16551500dc0593a2232f832 Mon Sep 17 00:00:00 2001 From: Robert von Burg Date: Mon, 23 Dec 2013 18:42:54 +0100 Subject: [PATCH 13/65] [Major] refactored Element maps for better handling Now they are not components, now there is an ElementMapHandler which is the component and the OrderMap and ResourceMap can be retrieved from the ElementMapHandler --- src/main/java/li/strolch/service/DefaultServiceHandler.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/li/strolch/service/DefaultServiceHandler.java b/src/main/java/li/strolch/service/DefaultServiceHandler.java index 6b940408f..efbcc7250 100644 --- a/src/main/java/li/strolch/service/DefaultServiceHandler.java +++ b/src/main/java/li/strolch/service/DefaultServiceHandler.java @@ -18,8 +18,8 @@ package li.strolch.service; import java.text.MessageFormat; import li.strolch.exception.StrolchException; -import li.strolch.runtime.component.ComponentContainer; -import li.strolch.runtime.component.StrolchComponent; +import li.strolch.runtime.agent.ComponentContainerImpl; +import li.strolch.runtime.agent.StrolchComponent; import li.strolch.runtime.configuration.ComponentConfiguration; import li.strolch.runtime.privilege.StrolchPrivilegeHandler; import ch.eitchnet.privilege.model.Certificate; @@ -38,7 +38,7 @@ public class DefaultServiceHandler extends StrolchComponent implements ServiceHa * @param container * @param componentName */ - public DefaultServiceHandler(ComponentContainer container, String componentName) { + public DefaultServiceHandler(ComponentContainerImpl container, String componentName) { super(container, componentName); } From 2b69c965501ea485a94435bd6a0f5514287ce284 Mon Sep 17 00:00:00 2001 From: Robert von Burg Date: Tue, 24 Dec 2013 02:44:04 +0100 Subject: [PATCH 14/65] [Minor] set artifact name to artifactId for easier reading of build log --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index b5515a09e..5fe0b2055 100644 --- a/pom.xml +++ b/pom.xml @@ -11,7 +11,7 @@ li.strolch.service - Service API for Strolch + li.strolch.service Service API for Strolch https://github.com/eitch/li.strolch.service From ee622567718259671674ad4ae66b001c404154b0 Mon Sep 17 00:00:00 2001 From: Robert von Burg Date: Wed, 25 Dec 2013 11:56:19 +0100 Subject: [PATCH 15/65] [Minor] fixed issue where eclipse couldn't validate log4j.xml --- src/test/resources/log4j.xml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/test/resources/log4j.xml b/src/test/resources/log4j.xml index a35a3c351..0a2a73d06 100644 --- a/src/test/resources/log4j.xml +++ b/src/test/resources/log4j.xml @@ -1,5 +1,6 @@ - + From 446c25050096bb44207f37bbe262ce4079d4eb9b Mon Sep 17 00:00:00 2001 From: Robert von Burg Date: Wed, 25 Dec 2013 17:02:19 +0100 Subject: [PATCH 16/65] [Minor] refactored tests for persistence layers to remove duplicate code --- .../service/test/AbstractServiceTest.java | 18 ++++++----- .../service/test/GreetingServiceTest.java | 7 +++-- .../service/test/NoPrivilegeServiceTest.java | 20 +++++++------ .../li/strolch/service/test/ServiceTest.java | 30 +++++++++---------- 4 files changed, 40 insertions(+), 35 deletions(-) diff --git a/src/test/java/li/strolch/service/test/AbstractServiceTest.java b/src/test/java/li/strolch/service/test/AbstractServiceTest.java index 89d1659f3..bba601be0 100644 --- a/src/test/java/li/strolch/service/test/AbstractServiceTest.java +++ b/src/test/java/li/strolch/service/test/AbstractServiceTest.java @@ -26,26 +26,28 @@ import org.junit.BeforeClass; /** * @author Robert von Burg */ -public abstract class AbstractServiceTest extends RuntimeMock { +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/config"; //$NON-NLS-1$ - protected static ServiceHandler serviceHandler; + protected static RuntimeMock runtimeMock; @BeforeClass public static void beforeClass() { File rootPath = new File(RUNTIME_PATH); File configSrc = new File(CONFIG_SRC); - RuntimeMock.mockRuntime(rootPath, configSrc); - RuntimeMock.startContainer(rootPath); - - // initialize the component configuration - serviceHandler = getContainer().getComponent(ServiceHandler.class); + runtimeMock = new RuntimeMock(); + runtimeMock.mockRuntime(rootPath, configSrc); + runtimeMock.startContainer(rootPath); } @AfterClass public static void afterClass() { - RuntimeMock.destroyRuntime(); + runtimeMock.destroyRuntime(); + } + + public static ServiceHandler getServiceHandler() { + return runtimeMock.getContainer().getComponent(ServiceHandler.class); } } diff --git a/src/test/java/li/strolch/service/test/GreetingServiceTest.java b/src/test/java/li/strolch/service/test/GreetingServiceTest.java index f426cea9c..7cb3ac2ae 100644 --- a/src/test/java/li/strolch/service/test/GreetingServiceTest.java +++ b/src/test/java/li/strolch/service/test/GreetingServiceTest.java @@ -35,12 +35,13 @@ public class GreetingServiceTest extends AbstractServiceTest { GreetingArgument greetingArgument = new GreetingArgument(); greetingArgument.name = "Robert"; //$NON-NLS-1$ - Certificate certificate = getPrivilegeHandler().authenticate("jill", "jill".getBytes()); //$NON-NLS-1$//$NON-NLS-2$ + Certificate certificate = runtimeMock.getPrivilegeHandler().authenticate("jill", "jill".getBytes()); //$NON-NLS-1$//$NON-NLS-2$ try { - GreetingResult greetingResult = serviceHandler.doService(certificate, greetingService, greetingArgument); + GreetingResult greetingResult = getServiceHandler().doService(certificate, greetingService, + greetingArgument); assertThat(greetingResult.getGreeting(), containsString("Hello Robert. Nice to meet you!")); //$NON-NLS-1$ } finally { - getPrivilegeHandler().invalidateSession(certificate); + runtimeMock.getPrivilegeHandler().invalidateSession(certificate); } } } diff --git a/src/test/java/li/strolch/service/test/NoPrivilegeServiceTest.java b/src/test/java/li/strolch/service/test/NoPrivilegeServiceTest.java index cb8b22f48..64271e13c 100644 --- a/src/test/java/li/strolch/service/test/NoPrivilegeServiceTest.java +++ b/src/test/java/li/strolch/service/test/NoPrivilegeServiceTest.java @@ -32,27 +32,29 @@ import org.junit.Test; * @author Robert von Burg * */ -public class NoPrivilegeServiceTest extends RuntimeMock { +public class NoPrivilegeServiceTest { private static final String RUNTIME_PATH = "target/strolchRuntime/"; //$NON-NLS-1$ private static final String CONFIG_SRC = "src/test/resources/withoutPrivilegeRuntime/config"; //$NON-NLS-1$ - protected static ServiceHandler serviceHandler; + protected static RuntimeMock runtimeMock; @BeforeClass public static void beforeClass() { File rootPath = new File(RUNTIME_PATH); File configSrc = new File(CONFIG_SRC); - RuntimeMock.mockRuntime(rootPath, configSrc); - RuntimeMock.startContainer(rootPath); - - // initialize the component configuration - serviceHandler = getContainer().getComponent(ServiceHandler.class); + runtimeMock = new RuntimeMock(); + runtimeMock.mockRuntime(rootPath, configSrc); + runtimeMock.startContainer(rootPath); } @AfterClass public static void afterClass() { - RuntimeMock.destroyRuntime(); + runtimeMock.destroyRuntime(); + } + + public static ServiceHandler getServiceHandler() { + return runtimeMock.getContainer().getComponent(ServiceHandler.class); } @Test @@ -62,7 +64,7 @@ public class NoPrivilegeServiceTest extends RuntimeMock { GreetingArgument greetingArgument = new GreetingArgument(); greetingArgument.name = "Robert"; //$NON-NLS-1$ - GreetingResult greetingResult = serviceHandler.doService(null, greetingService, greetingArgument); + GreetingResult greetingResult = getServiceHandler().doService(null, greetingService, greetingArgument); assertThat(greetingResult.getGreeting(), containsString("Hello Robert. Nice to meet you!")); //$NON-NLS-1$ } } diff --git a/src/test/java/li/strolch/service/test/ServiceTest.java b/src/test/java/li/strolch/service/test/ServiceTest.java index 0e01e58d0..8a72a5bd3 100644 --- a/src/test/java/li/strolch/service/test/ServiceTest.java +++ b/src/test/java/li/strolch/service/test/ServiceTest.java @@ -39,14 +39,14 @@ public class ServiceTest extends AbstractServiceTest { public void shouldFailNoCertificate() { this.thrown.expect(PrivilegeException.class); TestService testService = new TestService(); - serviceHandler.doService(null, testService); + getServiceHandler().doService(null, testService); } @Test public void shouldFailInvalidCertificate1() { this.thrown.expect(PrivilegeException.class); TestService testService = new TestService(); - serviceHandler.doService(new Certificate(null, 0, null, null, null, null, null), testService); + getServiceHandler().doService(new Certificate(null, 0, null, null, null, null, null), testService); } @Test @@ -54,7 +54,7 @@ public class ServiceTest extends AbstractServiceTest { this.thrown.expect(AccessDeniedException.class); TestService testService = new TestService(); Certificate badCert = new Certificate("1", System.currentTimeMillis(), "bob", "dsdf", "dferg", null, null); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ - serviceHandler.doService(badCert, testService); + getServiceHandler().doService(badCert, testService); } @Test @@ -62,52 +62,52 @@ public class ServiceTest extends AbstractServiceTest { this.thrown.expect(AccessDeniedException.class); this.thrown.expectMessage("User jill does not have Privilege li.strolch.service.Service"); //$NON-NLS-1$ - Certificate certificate = getPrivilegeHandler().authenticate("jill", "jill".getBytes()); //$NON-NLS-1$//$NON-NLS-2$ + Certificate certificate = runtimeMock.getPrivilegeHandler().authenticate("jill", "jill".getBytes()); //$NON-NLS-1$//$NON-NLS-2$ try { TestService testService = new TestService(); - serviceHandler.doService(certificate, testService); + getServiceHandler().doService(certificate, testService); } finally { - getPrivilegeHandler().invalidateSession(certificate); + runtimeMock.getPrivilegeHandler().invalidateSession(certificate); } } @Test public void shouldNotFailWithAccess() { - Certificate certificate = getPrivilegeHandler().authenticate("jill", "jill".getBytes()); //$NON-NLS-1$//$NON-NLS-2$ + Certificate certificate = runtimeMock.getPrivilegeHandler().authenticate("jill", "jill".getBytes()); //$NON-NLS-1$//$NON-NLS-2$ try { GreetingService service = new GreetingService(); GreetingArgument argument = new GreetingArgument(); argument.name = "Jill"; //$NON-NLS-1$ - GreetingResult greetingResult = serviceHandler.doService(certificate, service, argument); + GreetingResult greetingResult = getServiceHandler().doService(certificate, service, argument); assertThat(greetingResult.getGreeting(), equalTo("Hello Jill. Nice to meet you!")); //$NON-NLS-1$ } finally { - getPrivilegeHandler().invalidateSession(certificate); + runtimeMock.getPrivilegeHandler().invalidateSession(certificate); } } @Test public void shouldNotFailWithLogin1() { - Certificate certificate = getPrivilegeHandler().authenticate("bob", "bob".getBytes()); //$NON-NLS-1$//$NON-NLS-2$ + Certificate certificate = runtimeMock.getPrivilegeHandler().authenticate("bob", "bob".getBytes()); //$NON-NLS-1$//$NON-NLS-2$ try { TestService testService = new TestService(); - serviceHandler.doService(certificate, testService); + getServiceHandler().doService(certificate, testService); } finally { - getPrivilegeHandler().invalidateSession(certificate); + runtimeMock.getPrivilegeHandler().invalidateSession(certificate); } } @Test public void shouldNotFailWithLogin2() { - Certificate certificate = getPrivilegeHandler().authenticate("bob", "bob".getBytes()); //$NON-NLS-1$//$NON-NLS-2$ + 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 = serviceHandler.doService(certificate, service, argument); + GreetingResult greetingResult = getServiceHandler().doService(certificate, service, argument); assertThat(greetingResult.getGreeting(), equalTo("Hello Bob. Nice to meet you!")); //$NON-NLS-1$ } finally { - getPrivilegeHandler().invalidateSession(certificate); + runtimeMock.getPrivilegeHandler().invalidateSession(certificate); } } } From 1a6df8bca4d87b4919c05892258ccb0e106ac783 Mon Sep 17 00:00:00 2001 From: Robert von Burg Date: Wed, 25 Dec 2013 19:04:53 +0100 Subject: [PATCH 17/65] [Major] RuntimeMock now also copies data --- src/test/java/li/strolch/service/test/AbstractServiceTest.java | 2 +- .../java/li/strolch/service/test/NoPrivilegeServiceTest.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/test/java/li/strolch/service/test/AbstractServiceTest.java b/src/test/java/li/strolch/service/test/AbstractServiceTest.java index bba601be0..b8aa565fb 100644 --- a/src/test/java/li/strolch/service/test/AbstractServiceTest.java +++ b/src/test/java/li/strolch/service/test/AbstractServiceTest.java @@ -29,7 +29,7 @@ import org.junit.BeforeClass; 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/config"; //$NON-NLS-1$ + private static final String CONFIG_SRC = "src/test/resources/withPrivilegeRuntime"; //$NON-NLS-1$ protected static RuntimeMock runtimeMock; @BeforeClass diff --git a/src/test/java/li/strolch/service/test/NoPrivilegeServiceTest.java b/src/test/java/li/strolch/service/test/NoPrivilegeServiceTest.java index 64271e13c..8f1fbd2a0 100644 --- a/src/test/java/li/strolch/service/test/NoPrivilegeServiceTest.java +++ b/src/test/java/li/strolch/service/test/NoPrivilegeServiceTest.java @@ -35,7 +35,7 @@ import org.junit.Test; public class NoPrivilegeServiceTest { private static final String RUNTIME_PATH = "target/strolchRuntime/"; //$NON-NLS-1$ - private static final String CONFIG_SRC = "src/test/resources/withoutPrivilegeRuntime/config"; //$NON-NLS-1$ + private static final String CONFIG_SRC = "src/test/resources/withoutPrivilegeRuntime"; //$NON-NLS-1$ protected static RuntimeMock runtimeMock; @BeforeClass From 66920308d006ff9c84212373e936c065133f28f6 Mon Sep 17 00:00:00 2001 From: Robert von Burg Date: Wed, 25 Dec 2013 22:31:01 +0100 Subject: [PATCH 18/65] [Minor] reorganized classes for Agent into api and impl packages --- src/main/java/li/strolch/service/DefaultServiceHandler.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/li/strolch/service/DefaultServiceHandler.java b/src/main/java/li/strolch/service/DefaultServiceHandler.java index efbcc7250..6cb211047 100644 --- a/src/main/java/li/strolch/service/DefaultServiceHandler.java +++ b/src/main/java/li/strolch/service/DefaultServiceHandler.java @@ -18,8 +18,8 @@ package li.strolch.service; import java.text.MessageFormat; import li.strolch.exception.StrolchException; -import li.strolch.runtime.agent.ComponentContainerImpl; -import li.strolch.runtime.agent.StrolchComponent; +import li.strolch.runtime.agent.api.StrolchComponent; +import li.strolch.runtime.agent.impl.ComponentContainerImpl; import li.strolch.runtime.configuration.ComponentConfiguration; import li.strolch.runtime.privilege.StrolchPrivilegeHandler; import ch.eitchnet.privilege.model.Certificate; From 19c7a120ca3da1e998749d6c7041e1e6707e27b4 Mon Sep 17 00:00:00 2001 From: Robert von Burg Date: Sat, 28 Dec 2013 10:29:43 +0100 Subject: [PATCH 19/65] [New] injecting ComponentContainer into Services at execution time --- .../li/strolch/service/AbstractService.java | 17 ++++++++++++++++- .../strolch/service/DefaultServiceHandler.java | 15 ++++++++------- src/main/java/li/strolch/service/Service.java | 4 +++- 3 files changed, 27 insertions(+), 9 deletions(-) diff --git a/src/main/java/li/strolch/service/AbstractService.java b/src/main/java/li/strolch/service/AbstractService.java index e2d296e48..bef92cdf4 100644 --- a/src/main/java/li/strolch/service/AbstractService.java +++ b/src/main/java/li/strolch/service/AbstractService.java @@ -17,18 +17,33 @@ package li.strolch.service; import java.text.MessageFormat; +import li.strolch.runtime.agent.api.ComponentContainer; + import org.slf4j.Logger; import org.slf4j.LoggerFactory; /** * @author Robert von Burg - * */ public abstract class AbstractService implements Service { protected static final Logger logger = LoggerFactory.getLogger(AbstractService.class); private static final long serialVersionUID = 1L; + private ComponentContainer container; + + /** + * @return the container + */ + protected ComponentContainer getContainer() { + return this.container; + } + + @Override + public void setContainer(ComponentContainer container) { + this.container = container; + } + @Override public final U doService(T argument) { diff --git a/src/main/java/li/strolch/service/DefaultServiceHandler.java b/src/main/java/li/strolch/service/DefaultServiceHandler.java index 6cb211047..0ff6c98c3 100644 --- a/src/main/java/li/strolch/service/DefaultServiceHandler.java +++ b/src/main/java/li/strolch/service/DefaultServiceHandler.java @@ -42,6 +42,13 @@ public class DefaultServiceHandler extends StrolchComponent implements ServiceHa super(container, componentName); } + @Override + public void initialize(ComponentConfiguration configuration) { + if (getContainer().hasComponent(StrolchPrivilegeHandler.class)) + this.privilegeHandler = getContainer().getComponent(StrolchPrivilegeHandler.class); + super.initialize(configuration); + } + @Override public U doService(Certificate certificate, Service service) { return doService(certificate, service, null); @@ -67,6 +74,7 @@ public class DefaultServiceHandler extends StrolchComponent implements ServiceHa try { // then perform the service + service.setContainer(getContainer()); U serviceResult = service.doService(argument); // log the result @@ -90,11 +98,4 @@ public class DefaultServiceHandler extends StrolchComponent implements ServiceHa throw new StrolchException(msg, e); } } - - @Override - public void initialize(ComponentConfiguration configuration) { - if (getContainer().hasComponent(StrolchPrivilegeHandler.class)) - this.privilegeHandler = getContainer().getComponent(StrolchPrivilegeHandler.class); - super.initialize(configuration); - } } diff --git a/src/main/java/li/strolch/service/Service.java b/src/main/java/li/strolch/service/Service.java index 174d8d26e..03c76703e 100644 --- a/src/main/java/li/strolch/service/Service.java +++ b/src/main/java/li/strolch/service/Service.java @@ -17,13 +17,15 @@ package li.strolch.service; import java.io.Serializable; +import li.strolch.runtime.agent.api.ComponentContainer; import ch.eitchnet.privilege.model.Restrictable; /** * @author Robert von Burg - * */ public interface Service extends Serializable, Restrictable { public U doService(T argument); + + public void setContainer(ComponentContainer container); } From aa5ac4f7da25d635a2c51f9d79e667d3bad8d311 Mon Sep 17 00:00:00 2001 From: Robert von Burg Date: Sat, 28 Dec 2013 13:00:26 +0100 Subject: [PATCH 20/65] [Minor] better exception handling if Service returns null service result --- .../java/li/strolch/service/AbstractService.java | 14 +++++++++++--- .../li/strolch/service/DefaultServiceHandler.java | 5 +++++ 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/src/main/java/li/strolch/service/AbstractService.java b/src/main/java/li/strolch/service/AbstractService.java index bef92cdf4..9682676ca 100644 --- a/src/main/java/li/strolch/service/AbstractService.java +++ b/src/main/java/li/strolch/service/AbstractService.java @@ -17,6 +17,7 @@ package li.strolch.service; import java.text.MessageFormat; +import li.strolch.exception.StrolchException; import li.strolch.runtime.agent.api.ComponentContainer; import org.slf4j.Logger; @@ -61,7 +62,14 @@ public abstract class AbstractService Date: Sun, 29 Dec 2013 23:13:15 +0100 Subject: [PATCH 21/65] [Minor] fixed compile error due to change in privilege --- src/test/java/li/strolch/service/test/ServiceTest.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/test/java/li/strolch/service/test/ServiceTest.java b/src/test/java/li/strolch/service/test/ServiceTest.java index 8a72a5bd3..37e1d91f3 100644 --- a/src/test/java/li/strolch/service/test/ServiceTest.java +++ b/src/test/java/li/strolch/service/test/ServiceTest.java @@ -46,14 +46,14 @@ public class ServiceTest extends AbstractServiceTest { public void shouldFailInvalidCertificate1() { this.thrown.expect(PrivilegeException.class); TestService testService = new TestService(); - getServiceHandler().doService(new Certificate(null, 0, null, null, null, null, null), testService); + getServiceHandler().doService(new Certificate(null, 0, 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", "dsdf", "dferg", null, null); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ + Certificate badCert = new Certificate("1", System.currentTimeMillis(), "bob", "dsdf", null, null); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ getServiceHandler().doService(badCert, testService); } From cb89abd4699497a890ca5881ba5ebaedec94e083 Mon Sep 17 00:00:00 2001 From: Robert von Burg Date: Wed, 1 Jan 2014 02:19:21 +0100 Subject: [PATCH 22/65] [New] Added new services AddResource*Service, AddOrder*Service, ImportModelFromXmlService --- .../li/strolch/service/AbstractService.java | 30 +++++-- .../service/DefaultServiceHandler.java | 25 +++++- src/main/java/li/strolch/service/Service.java | 3 - .../li/strolch/service/ServiceArgument.java | 17 +++- .../li/strolch/service/ServiceHandler.java | 2 +- .../li/strolch/service/ServiceResult.java | 8 +- .../model/AddOrderCollectionService.java | 57 +++++++++++++ .../service/model/AddOrderService.java | 52 ++++++++++++ .../model/AddResourceCollectionService.java | 57 +++++++++++++ .../service/model/AddResourceService.java | 52 ++++++++++++ .../model/ImportModelFromXmlService.java | 81 +++++++++++++++++++ 11 files changed, 368 insertions(+), 16 deletions(-) create mode 100644 src/main/java/li/strolch/service/model/AddOrderCollectionService.java create mode 100644 src/main/java/li/strolch/service/model/AddOrderService.java create mode 100644 src/main/java/li/strolch/service/model/AddResourceCollectionService.java create mode 100644 src/main/java/li/strolch/service/model/AddResourceService.java create mode 100644 src/main/java/li/strolch/service/model/ImportModelFromXmlService.java diff --git a/src/main/java/li/strolch/service/AbstractService.java b/src/main/java/li/strolch/service/AbstractService.java index 9682676ca..7fe175264 100644 --- a/src/main/java/li/strolch/service/AbstractService.java +++ b/src/main/java/li/strolch/service/AbstractService.java @@ -18,7 +18,9 @@ package li.strolch.service; import java.text.MessageFormat; import li.strolch.exception.StrolchException; -import li.strolch.runtime.agent.api.ComponentContainer; +import li.strolch.runtime.agent.api.OrderMap; +import li.strolch.runtime.agent.api.ResourceMap; +import li.strolch.runtime.configuration.RuntimeConfiguration; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -31,18 +33,30 @@ public abstract class AbstractService V getComponent(Class clazz) { + return this.serviceHandler.getComponent(clazz); + } + + public RuntimeConfiguration getRuntimeConfiguration() { + return this.serviceHandler.getRuntimeConfiguration(); + } + + public ResourceMap getResourceMap(String realm) { + return this.serviceHandler.getResourceMap(realm); + } + + public OrderMap getOrderMap(String realm) { + return this.serviceHandler.getOrderMap(realm); } @Override diff --git a/src/main/java/li/strolch/service/DefaultServiceHandler.java b/src/main/java/li/strolch/service/DefaultServiceHandler.java index 3dbe77c5c..9e0963dc9 100644 --- a/src/main/java/li/strolch/service/DefaultServiceHandler.java +++ b/src/main/java/li/strolch/service/DefaultServiceHandler.java @@ -18,9 +18,12 @@ package li.strolch.service; import java.text.MessageFormat; import li.strolch.exception.StrolchException; +import li.strolch.runtime.agent.api.OrderMap; +import li.strolch.runtime.agent.api.ResourceMap; import li.strolch.runtime.agent.api.StrolchComponent; import li.strolch.runtime.agent.impl.ComponentContainerImpl; import li.strolch.runtime.configuration.ComponentConfiguration; +import li.strolch.runtime.configuration.RuntimeConfiguration; import li.strolch.runtime.privilege.StrolchPrivilegeHandler; import ch.eitchnet.privilege.model.Certificate; import ch.eitchnet.privilege.model.PrivilegeContext; @@ -28,10 +31,10 @@ import ch.eitchnet.utils.helper.StringHelper; /** * @author Robert von Burg - * */ public class DefaultServiceHandler extends StrolchComponent implements ServiceHandler { + private RuntimeConfiguration runtimeConfiguration; private StrolchPrivilegeHandler privilegeHandler; /** @@ -46,9 +49,26 @@ public class DefaultServiceHandler extends StrolchComponent implements ServiceHa public void initialize(ComponentConfiguration configuration) { if (getContainer().hasComponent(StrolchPrivilegeHandler.class)) this.privilegeHandler = getContainer().getComponent(StrolchPrivilegeHandler.class); + this.runtimeConfiguration = configuration.getRuntimeConfiguration(); super.initialize(configuration); } + public T getComponent(Class clazz) { + return getContainer().getComponent(clazz); + } + + public RuntimeConfiguration getRuntimeConfiguration() { + return this.runtimeConfiguration; + } + + public ResourceMap getResourceMap(String realm) { + return this.getContainer().getResourceMap(realm); + } + + public OrderMap getOrderMap(String realm) { + return this.getContainer().getOrderMap(realm); + } + @Override public U doService(Certificate certificate, Service service) { return doService(certificate, service, null); @@ -74,7 +94,8 @@ public class DefaultServiceHandler extends StrolchComponent implements ServiceHa try { // then perform the service - service.setContainer(getContainer()); + if (service instanceof AbstractService) + ((AbstractService) service).setServiceHandler(this); U serviceResult = service.doService(argument); if (serviceResult == null) { String msg = "Service {0} is not properly implemented as it returned a null result!"; //$NON-NLS-1$ diff --git a/src/main/java/li/strolch/service/Service.java b/src/main/java/li/strolch/service/Service.java index 03c76703e..de558710b 100644 --- a/src/main/java/li/strolch/service/Service.java +++ b/src/main/java/li/strolch/service/Service.java @@ -17,7 +17,6 @@ package li.strolch.service; import java.io.Serializable; -import li.strolch.runtime.agent.api.ComponentContainer; import ch.eitchnet.privilege.model.Restrictable; /** @@ -26,6 +25,4 @@ import ch.eitchnet.privilege.model.Restrictable; public interface Service extends Serializable, Restrictable { public U doService(T argument); - - public void setContainer(ComponentContainer container); } diff --git a/src/main/java/li/strolch/service/ServiceArgument.java b/src/main/java/li/strolch/service/ServiceArgument.java index 560717086..c81eb5622 100644 --- a/src/main/java/li/strolch/service/ServiceArgument.java +++ b/src/main/java/li/strolch/service/ServiceArgument.java @@ -17,11 +17,26 @@ package li.strolch.service; import java.io.Serializable; +import li.strolch.runtime.StrolchConstants; + /** + * Base argument to be used when performing {@link Service Services}. The realm parameter is set to + * {@link StrolchConstants#DEFAULT_REALM} and can be overridden when the caller of the service wants to perform the + * service in a different realm + * * @author Robert von Burg */ public class ServiceArgument implements Serializable { private static final long serialVersionUID = 1L; - // marker interface + /** + *

+ * Set this to the realm in which the service should operate + *

+ * + *

+ * realm = StrolchConstants.DEFAULT_REALM + *

+ */ + public String realm = StrolchConstants.DEFAULT_REALM; } diff --git a/src/main/java/li/strolch/service/ServiceHandler.java b/src/main/java/li/strolch/service/ServiceHandler.java index 334ca95c0..32ca19a46 100644 --- a/src/main/java/li/strolch/service/ServiceHandler.java +++ b/src/main/java/li/strolch/service/ServiceHandler.java @@ -18,7 +18,7 @@ package li.strolch.service; import ch.eitchnet.privilege.model.Certificate; public interface ServiceHandler { - + public U doService(Certificate certificate, Service service, T argument); diff --git a/src/main/java/li/strolch/service/ServiceResult.java b/src/main/java/li/strolch/service/ServiceResult.java index 5ce54d75d..5b846b200 100644 --- a/src/main/java/li/strolch/service/ServiceResult.java +++ b/src/main/java/li/strolch/service/ServiceResult.java @@ -19,7 +19,6 @@ import java.io.Serializable; /** * @author Robert von Burg - * */ public class ServiceResult implements Serializable { private static final long serialVersionUID = 1L; @@ -49,6 +48,13 @@ public class ServiceResult implements Serializable { this.throwable = throwable; } + /** + * @return true if the state is {@link ServiceResultState#SUCCESS} + */ + public boolean isOk() { + return this.state == ServiceResultState.SUCCESS; + } + /** * @return the state */ diff --git a/src/main/java/li/strolch/service/model/AddOrderCollectionService.java b/src/main/java/li/strolch/service/model/AddOrderCollectionService.java new file mode 100644 index 000000000..41144c01a --- /dev/null +++ b/src/main/java/li/strolch/service/model/AddOrderCollectionService.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.model; + +import java.util.List; + +import li.strolch.model.Order; +import li.strolch.persistence.api.StrolchTransaction; +import li.strolch.runtime.agent.api.OrderMap; +import li.strolch.service.AbstractService; +import li.strolch.service.ServiceArgument; +import li.strolch.service.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) { + + OrderMap orderMap = getOrderMap(arg.realm); + try (StrolchTransaction tx = orderMap.openTx(arg.realm)) { + for (Order order : arg.orders) { + orderMap.add(tx, order); + } + } + + return ServiceResult.success(); + } + + public static class AddOrderCollectionArg extends ServiceArgument { + private static final long serialVersionUID = 1L; + public List orders; + } +} diff --git a/src/main/java/li/strolch/service/model/AddOrderService.java b/src/main/java/li/strolch/service/model/AddOrderService.java new file mode 100644 index 000000000..af7869bf0 --- /dev/null +++ b/src/main/java/li/strolch/service/model/AddOrderService.java @@ -0,0 +1,52 @@ +/* + * 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.model; + +import li.strolch.model.Order; +import li.strolch.persistence.api.StrolchTransaction; +import li.strolch.runtime.agent.api.OrderMap; +import li.strolch.service.AbstractService; +import li.strolch.service.ServiceArgument; +import li.strolch.service.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) { + + OrderMap orderMap = getOrderMap(arg.realm); + try (StrolchTransaction tx = orderMap.openTx(arg.realm)) { + orderMap.add(tx, arg.order); + } + + return ServiceResult.success(); + } + + public static class AddOrderArg extends ServiceArgument { + private static final long serialVersionUID = 1L; + public Order order; + } +} diff --git a/src/main/java/li/strolch/service/model/AddResourceCollectionService.java b/src/main/java/li/strolch/service/model/AddResourceCollectionService.java new file mode 100644 index 000000000..377534fb9 --- /dev/null +++ b/src/main/java/li/strolch/service/model/AddResourceCollectionService.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.model; + +import java.util.List; + +import li.strolch.model.Resource; +import li.strolch.persistence.api.StrolchTransaction; +import li.strolch.runtime.agent.api.ResourceMap; +import li.strolch.service.AbstractService; +import li.strolch.service.ServiceArgument; +import li.strolch.service.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) { + + ResourceMap resourceMap = getResourceMap(arg.realm); + try (StrolchTransaction tx = resourceMap.openTx(arg.realm)) { + for (Resource resource : arg.resources) { + resourceMap.add(tx, resource); + } + } + + return ServiceResult.success(); + } + + public static class AddResourceCollectionArg extends ServiceArgument { + private static final long serialVersionUID = 1L; + public List resources; + } +} diff --git a/src/main/java/li/strolch/service/model/AddResourceService.java b/src/main/java/li/strolch/service/model/AddResourceService.java new file mode 100644 index 000000000..3dc33791a --- /dev/null +++ b/src/main/java/li/strolch/service/model/AddResourceService.java @@ -0,0 +1,52 @@ +/* + * 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.model; + +import li.strolch.model.Resource; +import li.strolch.persistence.api.StrolchTransaction; +import li.strolch.runtime.agent.api.ResourceMap; +import li.strolch.service.AbstractService; +import li.strolch.service.ServiceArgument; +import li.strolch.service.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) { + + ResourceMap resourceMap = getResourceMap(arg.realm); + try (StrolchTransaction tx = resourceMap.openTx(arg.realm)) { + resourceMap.add(tx, arg.resource); + } + + return ServiceResult.success(); + } + + public static class AddResourceArg extends ServiceArgument { + private static final long serialVersionUID = 1L; + public Resource resource; + } +} diff --git a/src/main/java/li/strolch/service/model/ImportModelFromXmlService.java b/src/main/java/li/strolch/service/model/ImportModelFromXmlService.java new file mode 100644 index 000000000..9b4bf5837 --- /dev/null +++ b/src/main/java/li/strolch/service/model/ImportModelFromXmlService.java @@ -0,0 +1,81 @@ +/* + * 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.model; + +import java.io.File; +import java.text.MessageFormat; + +import li.strolch.exception.StrolchException; +import li.strolch.model.xml.XmlModelDefaultHandler.XmlModelStatistics; +import li.strolch.model.xml.XmlModelFileHandler; +import li.strolch.persistence.api.StrolchTransaction; +import li.strolch.runtime.agent.api.OrderMap; +import li.strolch.runtime.agent.api.ResourceMap; +import li.strolch.runtime.agent.impl.InMemoryElementListener; +import li.strolch.service.AbstractService; +import li.strolch.service.ServiceArgument; +import li.strolch.service.ServiceResult; +import ch.eitchnet.utils.helper.StringHelper; + +/** + * @author Robert von Burg + */ +public class ImportModelFromXmlService extends + AbstractService { + + private static final long serialVersionUID = 1L; + + @Override + protected ServiceResult getResultInstance() { + return new ServiceResult(); + } + + @Override + protected ServiceResult internalDoService(ImportModelFromXmlArg arg) { + + ResourceMap resourceMap = getResourceMap(arg.realm); + OrderMap orderMap = getOrderMap(arg.realm); + + File dataPath = getRuntimeConfiguration().getDataPath(); + File modelFile = new File(dataPath, arg.fileName); + 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.fileName, dataPath); + throw new StrolchException(msg); + } + + XmlModelStatistics statistics; + try (StrolchTransaction tx = resourceMap.openTx(arg.realm)) { + InMemoryElementListener elementListener = new InMemoryElementListener(tx, resourceMap, orderMap); + XmlModelFileHandler handler = new XmlModelFileHandler(elementListener, modelFile); + handler.parseFile(); + statistics = handler.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(); + } + + public static class ImportModelFromXmlArg extends ServiceArgument { + private static final long serialVersionUID = 1L; + public String fileName; + } +} From f0f98ebd4afda3c49ffd7608223340fc56785950 Mon Sep 17 00:00:00 2001 From: Robert von Burg Date: Fri, 10 Jan 2014 16:50:27 +0100 Subject: [PATCH 23/65] [Major] removed project li.strolch.persistence.api Moved all classes to li.strolch.runtime --- pom.xml | 4 - src/main/java/li/strolch/command/Command.java | 60 -------- .../li/strolch/service/AbstractService.java | 142 ------------------ .../AddOrderCollectionService.java | 8 +- .../service/{model => }/AddOrderService.java | 8 +- .../AddResourceCollectionService.java | 8 +- .../{model => }/AddResourceService.java | 8 +- .../service/DefaultServiceHandler.java | 127 ---------------- .../ImportModelFromXmlService.java | 8 +- src/main/java/li/strolch/service/Service.java | 28 ---- .../li/strolch/service/ServiceArgument.java | 42 ------ .../li/strolch/service/ServiceHandler.java | 26 ---- .../li/strolch/service/ServiceResult.java | 122 --------------- .../strolch/service/ServiceResultState.java | 25 --- .../service/test/AbstractServiceTest.java | 2 +- .../strolch/service/test/GreetingResult.java | 4 +- .../strolch/service/test/GreetingService.java | 4 +- .../service/test/NoPrivilegeServiceTest.java | 2 +- .../li/strolch/service/test/ServiceTest.java | 2 +- .../li/strolch/service/test/TestService.java | 6 +- .../config/PrivilegeModel.xml | 4 +- .../config/StrolchConfiguration.xml | 4 +- .../config/StrolchConfiguration.xml | 4 +- 23 files changed, 36 insertions(+), 612 deletions(-) delete mode 100644 src/main/java/li/strolch/command/Command.java delete mode 100644 src/main/java/li/strolch/service/AbstractService.java rename src/main/java/li/strolch/service/{model => }/AddOrderCollectionService.java (90%) rename src/main/java/li/strolch/service/{model => }/AddOrderService.java (89%) rename src/main/java/li/strolch/service/{model => }/AddResourceCollectionService.java (90%) rename src/main/java/li/strolch/service/{model => }/AddResourceService.java (89%) delete mode 100644 src/main/java/li/strolch/service/DefaultServiceHandler.java rename src/main/java/li/strolch/service/{model => }/ImportModelFromXmlService.java (94%) delete mode 100644 src/main/java/li/strolch/service/Service.java delete mode 100644 src/main/java/li/strolch/service/ServiceArgument.java delete mode 100644 src/main/java/li/strolch/service/ServiceHandler.java delete mode 100644 src/main/java/li/strolch/service/ServiceResult.java delete mode 100644 src/main/java/li/strolch/service/ServiceResultState.java diff --git a/pom.xml b/pom.xml index 5fe0b2055..d2bae58dd 100644 --- a/pom.xml +++ b/pom.xml @@ -35,10 +35,6 @@ li.strolch li.strolch.model - - li.strolch - li.strolch.persistence.api - li.strolch li.strolch.runtime diff --git a/src/main/java/li/strolch/command/Command.java b/src/main/java/li/strolch/command/Command.java deleted file mode 100644 index e9edfcf41..000000000 --- a/src/main/java/li/strolch/command/Command.java +++ /dev/null @@ -1,60 +0,0 @@ -/* - * 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.persistence.api.StrolchTransaction; -import ch.eitchnet.privilege.model.Restrictable; - -/** - * @author Robert von Burg - * - */ -public abstract class Command implements Restrictable { - - private final StrolchTransaction tx; - - public Command(StrolchTransaction tx) { - this.tx = tx; - } - - /** - * Returns the {@link StrolchTransaction} bound to this {@link Command}'s runtime - * - * @return the {@link StrolchTransaction} bound to this {@link Command}'s runtime - */ - protected StrolchTransaction tx() { - return this.tx; - } - - /** - * @see ch.eitchnet.privilege.model.Restrictable#getPrivilegeName() - */ - @Override - public String getPrivilegeName() { - return Command.class.getName(); - } - - /** - * @see ch.eitchnet.privilege.model.Restrictable#getPrivilegeValue() - */ - @Override - public Object getPrivilegeValue() { - return this.getClass().getName(); - } - - public abstract void doCommand(); -} diff --git a/src/main/java/li/strolch/service/AbstractService.java b/src/main/java/li/strolch/service/AbstractService.java deleted file mode 100644 index 7fe175264..000000000 --- a/src/main/java/li/strolch/service/AbstractService.java +++ /dev/null @@ -1,142 +0,0 @@ -/* - * 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.exception.StrolchException; -import li.strolch.runtime.agent.api.OrderMap; -import li.strolch.runtime.agent.api.ResourceMap; -import li.strolch.runtime.configuration.RuntimeConfiguration; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * @author Robert von Burg - */ -public abstract class AbstractService implements Service { - - protected static final Logger logger = LoggerFactory.getLogger(AbstractService.class); - private static final long serialVersionUID = 1L; - - private DefaultServiceHandler serviceHandler; - - /** - * @param serviceHandler - * the serviceHandler to set - */ - public void setServiceHandler(DefaultServiceHandler serviceHandler) { - this.serviceHandler = serviceHandler; - } - - public V getComponent(Class clazz) { - return this.serviceHandler.getComponent(clazz); - } - - public RuntimeConfiguration getRuntimeConfiguration() { - return this.serviceHandler.getRuntimeConfiguration(); - } - - public ResourceMap getResourceMap(String realm) { - return this.serviceHandler.getResourceMap(realm); - } - - public OrderMap getOrderMap(String realm) { - return this.serviceHandler.getOrderMap(realm); - } - - @Override - public final U doService(T argument) { - - if (isArgumentRequired() && argument == null) { - - String msg = "Failed to perform service {0} because no argument was passed although it is required!"; //$NON-NLS-1$ - msg = MessageFormat.format(msg, getClass()); - logger.error(msg); - - U result = getResultInstance(); - result.setState(ServiceResultState.FAILED); - result.setMessage(msg); - return result; - } - - try { - - U serviceResult = internalDoService(argument); - if (serviceResult == null) { - String msg = "Service {0} is not properly implemented as it returned a null result!"; //$NON-NLS-1$ - msg = MessageFormat.format(msg, this.getClass().getName()); - throw new StrolchException(msg); - } - - return serviceResult; - - } catch (Exception e) { - - String msg = "Failed to perform service {0} due to {1}"; //$NON-NLS-1$ - msg = MessageFormat.format(msg, getClass(), e.getMessage()); - logger.error(msg, e); - - U result = getResultInstance(); - result.setState(ServiceResultState.FAILED); - result.setMessage(msg); - result.setThrowable(e); - return result; - } - } - - /** - * @return if true, then an argument must be set to execute the service. If the argument is missing, then the - * service execution fails immediately - */ - protected boolean isArgumentRequired() { - return true; - } - - /** - * This method is called if the service execution fails and an instance of the expected {@link ServiceResult} is - * required to return to the caller - * - * @return - */ - protected abstract U getResultInstance(); - - /** - * Internal method to perform the {@link Service}. The implementor does not need to handle exceptions as this is - * done in the {@link #doService(ServiceArgument)} which calls this method - * - * @param arg - * @return - */ - protected abstract U internalDoService(T arg); - - /** - * @see ch.eitchnet.privilege.model.Restrictable#getPrivilegeName() - */ - @Override - public String getPrivilegeName() { - return Service.class.getName(); - } - - /** - * @see ch.eitchnet.privilege.model.Restrictable#getPrivilegeValue() - */ - @Override - public Object getPrivilegeValue() { - return this.getClass().getName(); - } -} diff --git a/src/main/java/li/strolch/service/model/AddOrderCollectionService.java b/src/main/java/li/strolch/service/AddOrderCollectionService.java similarity index 90% rename from src/main/java/li/strolch/service/model/AddOrderCollectionService.java rename to src/main/java/li/strolch/service/AddOrderCollectionService.java index 41144c01a..a2e41533e 100644 --- a/src/main/java/li/strolch/service/model/AddOrderCollectionService.java +++ b/src/main/java/li/strolch/service/AddOrderCollectionService.java @@ -13,16 +13,16 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package li.strolch.service.model; +package li.strolch.service; import java.util.List; import li.strolch.model.Order; import li.strolch.persistence.api.StrolchTransaction; import li.strolch.runtime.agent.api.OrderMap; -import li.strolch.service.AbstractService; -import li.strolch.service.ServiceArgument; -import li.strolch.service.ServiceResult; +import li.strolch.service.api.AbstractService; +import li.strolch.service.api.ServiceArgument; +import li.strolch.service.api.ServiceResult; /** * @author Robert von Burg diff --git a/src/main/java/li/strolch/service/model/AddOrderService.java b/src/main/java/li/strolch/service/AddOrderService.java similarity index 89% rename from src/main/java/li/strolch/service/model/AddOrderService.java rename to src/main/java/li/strolch/service/AddOrderService.java index af7869bf0..56d7335d4 100644 --- a/src/main/java/li/strolch/service/model/AddOrderService.java +++ b/src/main/java/li/strolch/service/AddOrderService.java @@ -13,14 +13,14 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package li.strolch.service.model; +package li.strolch.service; import li.strolch.model.Order; import li.strolch.persistence.api.StrolchTransaction; import li.strolch.runtime.agent.api.OrderMap; -import li.strolch.service.AbstractService; -import li.strolch.service.ServiceArgument; -import li.strolch.service.ServiceResult; +import li.strolch.service.api.AbstractService; +import li.strolch.service.api.ServiceArgument; +import li.strolch.service.api.ServiceResult; /** * @author Robert von Burg diff --git a/src/main/java/li/strolch/service/model/AddResourceCollectionService.java b/src/main/java/li/strolch/service/AddResourceCollectionService.java similarity index 90% rename from src/main/java/li/strolch/service/model/AddResourceCollectionService.java rename to src/main/java/li/strolch/service/AddResourceCollectionService.java index 377534fb9..e251d6620 100644 --- a/src/main/java/li/strolch/service/model/AddResourceCollectionService.java +++ b/src/main/java/li/strolch/service/AddResourceCollectionService.java @@ -13,16 +13,16 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package li.strolch.service.model; +package li.strolch.service; import java.util.List; import li.strolch.model.Resource; import li.strolch.persistence.api.StrolchTransaction; import li.strolch.runtime.agent.api.ResourceMap; -import li.strolch.service.AbstractService; -import li.strolch.service.ServiceArgument; -import li.strolch.service.ServiceResult; +import li.strolch.service.api.AbstractService; +import li.strolch.service.api.ServiceArgument; +import li.strolch.service.api.ServiceResult; /** * @author Robert von Burg diff --git a/src/main/java/li/strolch/service/model/AddResourceService.java b/src/main/java/li/strolch/service/AddResourceService.java similarity index 89% rename from src/main/java/li/strolch/service/model/AddResourceService.java rename to src/main/java/li/strolch/service/AddResourceService.java index 3dc33791a..1129c548c 100644 --- a/src/main/java/li/strolch/service/model/AddResourceService.java +++ b/src/main/java/li/strolch/service/AddResourceService.java @@ -13,14 +13,14 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package li.strolch.service.model; +package li.strolch.service; import li.strolch.model.Resource; import li.strolch.persistence.api.StrolchTransaction; import li.strolch.runtime.agent.api.ResourceMap; -import li.strolch.service.AbstractService; -import li.strolch.service.ServiceArgument; -import li.strolch.service.ServiceResult; +import li.strolch.service.api.AbstractService; +import li.strolch.service.api.ServiceArgument; +import li.strolch.service.api.ServiceResult; /** * @author Robert von Burg diff --git a/src/main/java/li/strolch/service/DefaultServiceHandler.java b/src/main/java/li/strolch/service/DefaultServiceHandler.java deleted file mode 100644 index 9e0963dc9..000000000 --- a/src/main/java/li/strolch/service/DefaultServiceHandler.java +++ /dev/null @@ -1,127 +0,0 @@ -/* - * 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.exception.StrolchException; -import li.strolch.runtime.agent.api.OrderMap; -import li.strolch.runtime.agent.api.ResourceMap; -import li.strolch.runtime.agent.api.StrolchComponent; -import li.strolch.runtime.agent.impl.ComponentContainerImpl; -import li.strolch.runtime.configuration.ComponentConfiguration; -import li.strolch.runtime.configuration.RuntimeConfiguration; -import li.strolch.runtime.privilege.StrolchPrivilegeHandler; -import ch.eitchnet.privilege.model.Certificate; -import ch.eitchnet.privilege.model.PrivilegeContext; -import ch.eitchnet.utils.helper.StringHelper; - -/** - * @author Robert von Burg - */ -public class DefaultServiceHandler extends StrolchComponent implements ServiceHandler { - - private RuntimeConfiguration runtimeConfiguration; - private StrolchPrivilegeHandler privilegeHandler; - - /** - * @param container - * @param componentName - */ - public DefaultServiceHandler(ComponentContainerImpl container, String componentName) { - super(container, componentName); - } - - @Override - public void initialize(ComponentConfiguration configuration) { - if (getContainer().hasComponent(StrolchPrivilegeHandler.class)) - this.privilegeHandler = getContainer().getComponent(StrolchPrivilegeHandler.class); - this.runtimeConfiguration = configuration.getRuntimeConfiguration(); - super.initialize(configuration); - } - - public T getComponent(Class clazz) { - return getContainer().getComponent(clazz); - } - - public RuntimeConfiguration getRuntimeConfiguration() { - return this.runtimeConfiguration; - } - - public ResourceMap getResourceMap(String realm) { - return this.getContainer().getResourceMap(realm); - } - - public OrderMap getOrderMap(String realm) { - return this.getContainer().getOrderMap(realm); - } - - @Override - public U doService(Certificate certificate, Service service) { - return doService(certificate, service, null); - } - - @Override - public U doService(Certificate certificate, - Service service, T argument) { - - long start = System.nanoTime(); - - // first check that the caller may perform this service - if (this.privilegeHandler != null) { - // XXX Bad bad bad: remove the need for thread locals... - try { - PrivilegeContext privilegeContext = this.privilegeHandler.getPrivilegeContext(certificate); - PrivilegeContext.set(privilegeContext); - privilegeContext.validateAction(service); - } finally { - PrivilegeContext.set(null); - } - } - - try { - // then perform the service - if (service instanceof AbstractService) - ((AbstractService) service).setServiceHandler(this); - U serviceResult = service.doService(argument); - if (serviceResult == null) { - String msg = "Service {0} is not properly implemented as it returned a null result!"; //$NON-NLS-1$ - msg = MessageFormat.format(msg, service); - throw new StrolchException(msg); - } - - // log the result - long end = System.nanoTime(); - String msg = "Service {0} took {1}"; //$NON-NLS-1$ - msg = MessageFormat.format(msg, service, StringHelper.formatNanoDuration(end - start)); - if (serviceResult.getState() == ServiceResultState.SUCCESS) - logger.info(msg); - else if (serviceResult.getState() == ServiceResultState.WARNING) - logger.warn(msg); - else if (serviceResult.getState() == ServiceResultState.FAILED) - logger.error(msg); - - return serviceResult; - - } catch (Exception e) { - long end = System.nanoTime(); - String msg = "Failed to perform service {0} after {1} due to {2}"; //$NON-NLS-1$ - msg = MessageFormat.format(msg, service, StringHelper.formatNanoDuration(end - start), e.getMessage()); - logger.error(msg, e); - throw new StrolchException(msg, e); - } - } -} diff --git a/src/main/java/li/strolch/service/model/ImportModelFromXmlService.java b/src/main/java/li/strolch/service/ImportModelFromXmlService.java similarity index 94% rename from src/main/java/li/strolch/service/model/ImportModelFromXmlService.java rename to src/main/java/li/strolch/service/ImportModelFromXmlService.java index 9b4bf5837..bf78622e9 100644 --- a/src/main/java/li/strolch/service/model/ImportModelFromXmlService.java +++ b/src/main/java/li/strolch/service/ImportModelFromXmlService.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package li.strolch.service.model; +package li.strolch.service; import java.io.File; import java.text.MessageFormat; @@ -25,9 +25,9 @@ import li.strolch.persistence.api.StrolchTransaction; import li.strolch.runtime.agent.api.OrderMap; import li.strolch.runtime.agent.api.ResourceMap; import li.strolch.runtime.agent.impl.InMemoryElementListener; -import li.strolch.service.AbstractService; -import li.strolch.service.ServiceArgument; -import li.strolch.service.ServiceResult; +import li.strolch.service.api.AbstractService; +import li.strolch.service.api.ServiceArgument; +import li.strolch.service.api.ServiceResult; import ch.eitchnet.utils.helper.StringHelper; /** diff --git a/src/main/java/li/strolch/service/Service.java b/src/main/java/li/strolch/service/Service.java deleted file mode 100644 index de558710b..000000000 --- a/src/main/java/li/strolch/service/Service.java +++ /dev/null @@ -1,28 +0,0 @@ -/* - * 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.Serializable; - -import ch.eitchnet.privilege.model.Restrictable; - -/** - * @author Robert von Burg - */ -public interface Service extends Serializable, Restrictable { - - public U doService(T argument); -} diff --git a/src/main/java/li/strolch/service/ServiceArgument.java b/src/main/java/li/strolch/service/ServiceArgument.java deleted file mode 100644 index c81eb5622..000000000 --- a/src/main/java/li/strolch/service/ServiceArgument.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * 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.Serializable; - -import li.strolch.runtime.StrolchConstants; - -/** - * Base argument to be used when performing {@link Service Services}. The realm parameter is set to - * {@link StrolchConstants#DEFAULT_REALM} and can be overridden when the caller of the service wants to perform the - * service in a different realm - * - * @author Robert von Burg - */ -public class ServiceArgument implements Serializable { - private static final long serialVersionUID = 1L; - - /** - *

- * Set this to the realm in which the service should operate - *

- * - *

- * realm = StrolchConstants.DEFAULT_REALM - *

- */ - public String realm = StrolchConstants.DEFAULT_REALM; -} diff --git a/src/main/java/li/strolch/service/ServiceHandler.java b/src/main/java/li/strolch/service/ServiceHandler.java deleted file mode 100644 index 32ca19a46..000000000 --- a/src/main/java/li/strolch/service/ServiceHandler.java +++ /dev/null @@ -1,26 +0,0 @@ -/* - * 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 ch.eitchnet.privilege.model.Certificate; - -public interface ServiceHandler { - - public U doService(Certificate certificate, - Service service, T argument); - - public U doService(Certificate certificate, Service service); -} \ No newline at end of file diff --git a/src/main/java/li/strolch/service/ServiceResult.java b/src/main/java/li/strolch/service/ServiceResult.java deleted file mode 100644 index 5b846b200..000000000 --- a/src/main/java/li/strolch/service/ServiceResult.java +++ /dev/null @@ -1,122 +0,0 @@ -/* - * 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.Serializable; - -/** - * @author Robert von Burg - */ -public class ServiceResult implements Serializable { - private static final long serialVersionUID = 1L; - private ServiceResultState state; - private String message; - private Throwable throwable; - - public ServiceResult() { - // - } - - /** - * @param state - */ - public ServiceResult(ServiceResultState state) { - this.state = state; - } - - /** - * @param state - * @param message - * @param throwable - */ - public ServiceResult(ServiceResultState state, String message, Throwable throwable) { - this.state = state; - this.message = message; - this.throwable = throwable; - } - - /** - * @return true if the state is {@link ServiceResultState#SUCCESS} - */ - public boolean isOk() { - return this.state == ServiceResultState.SUCCESS; - } - - /** - * @return the state - */ - public ServiceResultState getState() { - return this.state; - } - - /** - * @param state - * the state to set - */ - public void setState(ServiceResultState state) { - this.state = state; - } - - /** - * @return the message - */ - public String getMessage() { - return this.message; - } - - /** - * @param message - * the message to set - */ - public void setMessage(String message) { - this.message = message; - } - - /** - * @return the throwable - */ - public Throwable getThrowable() { - return this.throwable; - } - - /** - * @param throwable - * the throwable to set - */ - public void setThrowable(Throwable throwable) { - this.throwable = throwable; - } - - public static ServiceResult success() { - return new ServiceResult(ServiceResultState.SUCCESS, null, null); - } - - public static ServiceResult success(String msg) { - return new ServiceResult(ServiceResultState.SUCCESS, msg, null); - } - - public static ServiceResult warning(String warning) { - return new ServiceResult(ServiceResultState.WARNING, warning, null); - } - - public static ServiceResult warning(String warning, Throwable t) { - return new ServiceResult(ServiceResultState.WARNING, warning, t); - } - - public static ServiceResult failed(String error, Throwable t) { - return new ServiceResult(ServiceResultState.FAILED, error, t); - } -} diff --git a/src/main/java/li/strolch/service/ServiceResultState.java b/src/main/java/li/strolch/service/ServiceResultState.java deleted file mode 100644 index 9037211e9..000000000 --- a/src/main/java/li/strolch/service/ServiceResultState.java +++ /dev/null @@ -1,25 +0,0 @@ -/* - * 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; - -/** - * @author Robert von Burg - * - */ -public enum ServiceResultState { - - SUCCESS, WARNING, FAILED; -} diff --git a/src/test/java/li/strolch/service/test/AbstractServiceTest.java b/src/test/java/li/strolch/service/test/AbstractServiceTest.java index b8aa565fb..0dff3b8a1 100644 --- a/src/test/java/li/strolch/service/test/AbstractServiceTest.java +++ b/src/test/java/li/strolch/service/test/AbstractServiceTest.java @@ -17,7 +17,7 @@ package li.strolch.service.test; import java.io.File; -import li.strolch.service.ServiceHandler; +import li.strolch.service.api.ServiceHandler; import li.strolch.testbase.runtime.RuntimeMock; import org.junit.AfterClass; diff --git a/src/test/java/li/strolch/service/test/GreetingResult.java b/src/test/java/li/strolch/service/test/GreetingResult.java index 656dedc4e..6b37c252b 100644 --- a/src/test/java/li/strolch/service/test/GreetingResult.java +++ b/src/test/java/li/strolch/service/test/GreetingResult.java @@ -15,8 +15,8 @@ */ package li.strolch.service.test; -import li.strolch.service.ServiceResult; -import li.strolch.service.ServiceResultState; +import li.strolch.service.api.ServiceResult; +import li.strolch.service.api.ServiceResultState; public class GreetingResult extends ServiceResult { private static final long serialVersionUID = 1L; diff --git a/src/test/java/li/strolch/service/test/GreetingService.java b/src/test/java/li/strolch/service/test/GreetingService.java index b599034fd..da5a1af29 100644 --- a/src/test/java/li/strolch/service/test/GreetingService.java +++ b/src/test/java/li/strolch/service/test/GreetingService.java @@ -17,8 +17,8 @@ package li.strolch.service.test; import java.text.MessageFormat; -import li.strolch.service.AbstractService; -import li.strolch.service.ServiceArgument; +import li.strolch.service.api.AbstractService; +import li.strolch.service.api.ServiceArgument; import li.strolch.service.test.GreetingService.GreetingArgument; import ch.eitchnet.utils.helper.StringHelper; diff --git a/src/test/java/li/strolch/service/test/NoPrivilegeServiceTest.java b/src/test/java/li/strolch/service/test/NoPrivilegeServiceTest.java index 8f1fbd2a0..7acdea3a8 100644 --- a/src/test/java/li/strolch/service/test/NoPrivilegeServiceTest.java +++ b/src/test/java/li/strolch/service/test/NoPrivilegeServiceTest.java @@ -20,7 +20,7 @@ import static org.junit.Assert.assertThat; import java.io.File; -import li.strolch.service.ServiceHandler; +import li.strolch.service.api.ServiceHandler; import li.strolch.service.test.GreetingService.GreetingArgument; import li.strolch.testbase.runtime.RuntimeMock; diff --git a/src/test/java/li/strolch/service/test/ServiceTest.java b/src/test/java/li/strolch/service/test/ServiceTest.java index 37e1d91f3..616f8c041 100644 --- a/src/test/java/li/strolch/service/test/ServiceTest.java +++ b/src/test/java/li/strolch/service/test/ServiceTest.java @@ -60,7 +60,7 @@ public class ServiceTest extends AbstractServiceTest { @Test public void shouldFailWithNoAccess() { this.thrown.expect(AccessDeniedException.class); - this.thrown.expectMessage("User jill does not have Privilege li.strolch.service.Service"); //$NON-NLS-1$ + this.thrown.expectMessage("User jill does not have Privilege li.strolch.service.api.Service"); //$NON-NLS-1$ Certificate certificate = runtimeMock.getPrivilegeHandler().authenticate("jill", "jill".getBytes()); //$NON-NLS-1$//$NON-NLS-2$ try { diff --git a/src/test/java/li/strolch/service/test/TestService.java b/src/test/java/li/strolch/service/test/TestService.java index d53d59291..a3e2df4e8 100644 --- a/src/test/java/li/strolch/service/test/TestService.java +++ b/src/test/java/li/strolch/service/test/TestService.java @@ -15,9 +15,9 @@ */ package li.strolch.service.test; -import li.strolch.service.AbstractService; -import li.strolch.service.ServiceArgument; -import li.strolch.service.ServiceResult; +import li.strolch.service.api.AbstractService; +import li.strolch.service.api.ServiceArgument; +import li.strolch.service.api.ServiceResult; /** * @author Robert von Burg diff --git a/src/test/resources/withPrivilegeRuntime/config/PrivilegeModel.xml b/src/test/resources/withPrivilegeRuntime/config/PrivilegeModel.xml index 28c007077..848bbe71d 100644 --- a/src/test/resources/withPrivilegeRuntime/config/PrivilegeModel.xml +++ b/src/test/resources/withPrivilegeRuntime/config/PrivilegeModel.xml @@ -56,7 +56,7 @@ - + true @@ -65,7 +65,7 @@ - + li.strolch.service.test.GreetingService diff --git a/src/test/resources/withPrivilegeRuntime/config/StrolchConfiguration.xml b/src/test/resources/withPrivilegeRuntime/config/StrolchConfiguration.xml index fb9ed15a5..27d4a47bc 100644 --- a/src/test/resources/withPrivilegeRuntime/config/StrolchConfiguration.xml +++ b/src/test/resources/withPrivilegeRuntime/config/StrolchConfiguration.xml @@ -9,8 +9,8 @@ ServiceHandler - li.strolch.service.ServiceHandler - li.strolch.service.DefaultServiceHandler + li.strolch.service.api.ServiceHandler + li.strolch.service.api.DefaultServiceHandler true diff --git a/src/test/resources/withoutPrivilegeRuntime/config/StrolchConfiguration.xml b/src/test/resources/withoutPrivilegeRuntime/config/StrolchConfiguration.xml index 76e96a2c8..c250eb161 100644 --- a/src/test/resources/withoutPrivilegeRuntime/config/StrolchConfiguration.xml +++ b/src/test/resources/withoutPrivilegeRuntime/config/StrolchConfiguration.xml @@ -9,8 +9,8 @@ ServiceHandler - li.strolch.service.ServiceHandler - li.strolch.service.DefaultServiceHandler + li.strolch.service.api.ServiceHandler + li.strolch.service.api.DefaultServiceHandler true From 971d25640c802bc9e92a8307f5b48a2407223d36 Mon Sep 17 00:00:00 2001 From: Robert von Burg Date: Fri, 10 Jan 2014 17:17:01 +0100 Subject: [PATCH 24/65] [Major] renamed project li.strolch.runtime to li.strolch.agent --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index d2bae58dd..5e4218c1e 100644 --- a/pom.xml +++ b/pom.xml @@ -37,7 +37,7 @@
li.strolch - li.strolch.runtime + li.strolch.agent From fbcbed4a0069f3f3bc1d72dde5b5f0389631c02b Mon Sep 17 00:00:00 2001 From: Robert von Burg Date: Fri, 10 Jan 2014 19:10:56 +0100 Subject: [PATCH 25/65] [Major] refactored how transactions are opened Now the ElementMapHandler is the central object and clients do not use access DAOs or the PersistenceHandler anymore. This is now transparent. --- .../command/AddOrderCollectionCommand.java | 68 +++++++++++++++++++ .../li/strolch/command/AddOrderCommand.java | 61 +++++++++++++++++ .../command/AddResourceCollectionCommand.java | 68 +++++++++++++++++++ .../strolch/command/AddResourceCommand.java | 61 +++++++++++++++++ .../service/AddOrderCollectionService.java | 11 ++- .../li/strolch/service/AddOrderService.java | 9 +-- .../service/AddResourceCollectionService.java | 11 ++- .../strolch/service/AddResourceService.java | 9 +-- .../service/ImportModelFromXmlService.java | 9 +-- 9 files changed, 280 insertions(+), 27 deletions(-) create mode 100644 src/main/java/li/strolch/command/AddOrderCollectionCommand.java create mode 100644 src/main/java/li/strolch/command/AddOrderCommand.java create mode 100644 src/main/java/li/strolch/command/AddResourceCollectionCommand.java create mode 100644 src/main/java/li/strolch/command/AddResourceCommand.java diff --git a/src/main/java/li/strolch/command/AddOrderCollectionCommand.java b/src/main/java/li/strolch/command/AddOrderCollectionCommand.java new file mode 100644 index 000000000..76d622233 --- /dev/null +++ b/src/main/java/li/strolch/command/AddOrderCollectionCommand.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.command; + +import java.util.List; + +import li.strolch.exception.StrolchException; +import li.strolch.model.Order; +import li.strolch.persistence.api.StrolchTransaction; +import li.strolch.runtime.agent.api.ComponentContainer; +import li.strolch.runtime.agent.api.OrderMap; +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 doCommand() { + + DBC.PRE.assertNotNull("Order list may not be null!", this.orders); + + OrderMap orderMap = tx().getOrderMap(); + for (Order order : orders) { + if (orderMap.hasElement(tx(), order.getType(), order.getId())) { + String msg = "The Order " + order.getLocator() + " already exists!"; + throw new StrolchException(msg); + } + + } + + for (Order order : orders) { + orderMap.add(tx(), order); + } + } +} diff --git a/src/main/java/li/strolch/command/AddOrderCommand.java b/src/main/java/li/strolch/command/AddOrderCommand.java new file mode 100644 index 000000000..e6713d6cb --- /dev/null +++ b/src/main/java/li/strolch/command/AddOrderCommand.java @@ -0,0 +1,61 @@ +/* + * 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.exception.StrolchException; +import li.strolch.model.Order; +import li.strolch.persistence.api.StrolchTransaction; +import li.strolch.runtime.agent.api.ComponentContainer; +import li.strolch.runtime.agent.api.OrderMap; +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 doCommand() { + + DBC.PRE.assertNotNull("Order may not be null!", this.order); + + OrderMap orderMap = tx().getOrderMap(); + if (orderMap.hasElement(tx(), this.order.getType(), this.order.getId())) { + String msg = "The Order " + this.order.getLocator() + " already exists!"; + throw new StrolchException(msg); + } + + orderMap.add(tx(), this.order); + } +} diff --git a/src/main/java/li/strolch/command/AddResourceCollectionCommand.java b/src/main/java/li/strolch/command/AddResourceCollectionCommand.java new file mode 100644 index 000000000..a44eb4207 --- /dev/null +++ b/src/main/java/li/strolch/command/AddResourceCollectionCommand.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.command; + +import java.util.List; + +import li.strolch.exception.StrolchException; +import li.strolch.model.Resource; +import li.strolch.persistence.api.StrolchTransaction; +import li.strolch.runtime.agent.api.ComponentContainer; +import li.strolch.runtime.agent.api.ResourceMap; +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 doCommand() { + + DBC.PRE.assertNotNull("Resource list may not be null!", this.resources); + + ResourceMap resourceMap = tx().getResourceMap(); + for (Resource resource : resources) { + if (resourceMap.hasElement(tx(), resource.getType(), resource.getId())) { + String msg = "The Resource " + resource.getLocator() + " already exists!"; + throw new StrolchException(msg); + } + + } + + for (Resource resource : resources) { + resourceMap.add(tx(), resource); + } + } +} diff --git a/src/main/java/li/strolch/command/AddResourceCommand.java b/src/main/java/li/strolch/command/AddResourceCommand.java new file mode 100644 index 000000000..aa1a74d3f --- /dev/null +++ b/src/main/java/li/strolch/command/AddResourceCommand.java @@ -0,0 +1,61 @@ +/* + * 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.exception.StrolchException; +import li.strolch.model.Resource; +import li.strolch.persistence.api.StrolchTransaction; +import li.strolch.runtime.agent.api.ComponentContainer; +import li.strolch.runtime.agent.api.ResourceMap; +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 doCommand() { + + DBC.PRE.assertNotNull("Resource may not be null!", this.resource); + + ResourceMap resourceMap = tx().getResourceMap(); + if (resourceMap.hasElement(tx(), this.resource.getType(), this.resource.getId())) { + String msg = "The Resource " + this.resource.getLocator() + " already exists!"; + throw new StrolchException(msg); + } + + resourceMap.add(tx(), this.resource); + } +} diff --git a/src/main/java/li/strolch/service/AddOrderCollectionService.java b/src/main/java/li/strolch/service/AddOrderCollectionService.java index a2e41533e..5da01c5a9 100644 --- a/src/main/java/li/strolch/service/AddOrderCollectionService.java +++ b/src/main/java/li/strolch/service/AddOrderCollectionService.java @@ -17,9 +17,9 @@ 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.runtime.agent.api.OrderMap; import li.strolch.service.api.AbstractService; import li.strolch.service.api.ServiceArgument; import li.strolch.service.api.ServiceResult; @@ -40,11 +40,10 @@ public class AddOrderCollectionService extends @Override protected ServiceResult internalDoService(AddOrderCollectionArg arg) { - OrderMap orderMap = getOrderMap(arg.realm); - try (StrolchTransaction tx = orderMap.openTx(arg.realm)) { - for (Order order : arg.orders) { - orderMap.add(tx, order); - } + try (StrolchTransaction tx = openTx(arg.realm)) { + AddOrderCollectionCommand command = new AddOrderCollectionCommand(getContainer(), tx); + command.setOrders(arg.orders); + command.doCommand(); } return ServiceResult.success(); diff --git a/src/main/java/li/strolch/service/AddOrderService.java b/src/main/java/li/strolch/service/AddOrderService.java index 56d7335d4..483310f9a 100644 --- a/src/main/java/li/strolch/service/AddOrderService.java +++ b/src/main/java/li/strolch/service/AddOrderService.java @@ -15,9 +15,9 @@ */ package li.strolch.service; +import li.strolch.command.AddOrderCommand; import li.strolch.model.Order; import li.strolch.persistence.api.StrolchTransaction; -import li.strolch.runtime.agent.api.OrderMap; import li.strolch.service.api.AbstractService; import li.strolch.service.api.ServiceArgument; import li.strolch.service.api.ServiceResult; @@ -37,9 +37,10 @@ public class AddOrderService extends AbstractService Date: Fri, 10 Jan 2014 23:23:29 +0100 Subject: [PATCH 26/65] [Major] moved the package li.strolch.runtime.agent to li.strolch.agent --- .../java/li/strolch/command/AddOrderCollectionCommand.java | 4 ++-- src/main/java/li/strolch/command/AddOrderCommand.java | 4 ++-- .../java/li/strolch/command/AddResourceCollectionCommand.java | 4 ++-- src/main/java/li/strolch/command/AddResourceCommand.java | 4 ++-- .../java/li/strolch/service/ImportModelFromXmlService.java | 2 +- 5 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/main/java/li/strolch/command/AddOrderCollectionCommand.java b/src/main/java/li/strolch/command/AddOrderCollectionCommand.java index 76d622233..559560d1a 100644 --- a/src/main/java/li/strolch/command/AddOrderCollectionCommand.java +++ b/src/main/java/li/strolch/command/AddOrderCollectionCommand.java @@ -17,11 +17,11 @@ package li.strolch.command; 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.runtime.agent.api.ComponentContainer; -import li.strolch.runtime.agent.api.OrderMap; import li.strolch.service.api.Command; import ch.eitchnet.utils.dbc.DBC; diff --git a/src/main/java/li/strolch/command/AddOrderCommand.java b/src/main/java/li/strolch/command/AddOrderCommand.java index e6713d6cb..b21d5d02a 100644 --- a/src/main/java/li/strolch/command/AddOrderCommand.java +++ b/src/main/java/li/strolch/command/AddOrderCommand.java @@ -15,11 +15,11 @@ */ package li.strolch.command; +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.runtime.agent.api.ComponentContainer; -import li.strolch.runtime.agent.api.OrderMap; import li.strolch.service.api.Command; import ch.eitchnet.utils.dbc.DBC; diff --git a/src/main/java/li/strolch/command/AddResourceCollectionCommand.java b/src/main/java/li/strolch/command/AddResourceCollectionCommand.java index a44eb4207..d1a71b3da 100644 --- a/src/main/java/li/strolch/command/AddResourceCollectionCommand.java +++ b/src/main/java/li/strolch/command/AddResourceCollectionCommand.java @@ -17,11 +17,11 @@ package li.strolch.command; 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.runtime.agent.api.ComponentContainer; -import li.strolch.runtime.agent.api.ResourceMap; import li.strolch.service.api.Command; import ch.eitchnet.utils.dbc.DBC; diff --git a/src/main/java/li/strolch/command/AddResourceCommand.java b/src/main/java/li/strolch/command/AddResourceCommand.java index aa1a74d3f..f7f5ec17f 100644 --- a/src/main/java/li/strolch/command/AddResourceCommand.java +++ b/src/main/java/li/strolch/command/AddResourceCommand.java @@ -15,11 +15,11 @@ */ package li.strolch.command; +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.runtime.agent.api.ComponentContainer; -import li.strolch.runtime.agent.api.ResourceMap; import li.strolch.service.api.Command; import ch.eitchnet.utils.dbc.DBC; diff --git a/src/main/java/li/strolch/service/ImportModelFromXmlService.java b/src/main/java/li/strolch/service/ImportModelFromXmlService.java index 6a1a935b8..e4a7dfd35 100644 --- a/src/main/java/li/strolch/service/ImportModelFromXmlService.java +++ b/src/main/java/li/strolch/service/ImportModelFromXmlService.java @@ -18,11 +18,11 @@ package li.strolch.service; import java.io.File; import java.text.MessageFormat; +import li.strolch.agent.impl.InMemoryElementListener; import li.strolch.exception.StrolchException; import li.strolch.model.xml.XmlModelDefaultHandler.XmlModelStatistics; import li.strolch.model.xml.XmlModelFileHandler; import li.strolch.persistence.api.StrolchTransaction; -import li.strolch.runtime.agent.impl.InMemoryElementListener; import li.strolch.service.api.AbstractService; import li.strolch.service.api.ServiceArgument; import li.strolch.service.api.ServiceResult; From 08185b415fe9f5135694f6e9939abbac0a40a945 Mon Sep 17 00:00:00 2001 From: Robert von Burg Date: Sat, 11 Jan 2014 23:14:28 +0100 Subject: [PATCH 27/65] [New] Added Update and Remove services and commands --- .../command/AddOrderCollectionCommand.java | 8 +-- .../li/strolch/command/AddOrderCommand.java | 4 +- .../command/AddResourceCollectionCommand.java | 8 +-- .../strolch/command/AddResourceCommand.java | 4 +- .../command/RemoveOrderCollectionCommand.java | 67 +++++++++++++++++++ .../strolch/command/RemoveOrderCommand.java | 64 ++++++++++++++++++ .../RemoveResourceCollectionCommand.java | 67 +++++++++++++++++++ .../command/RemoveResourceCommand.java | 64 ++++++++++++++++++ .../command/UpdateOrderCollectionCommand.java | 67 +++++++++++++++++++ .../strolch/command/UpdateOrderCommand.java | 64 ++++++++++++++++++ .../UpdateResourceCollectionCommand.java | 67 +++++++++++++++++++ .../command/UpdateResourceCommand.java | 64 ++++++++++++++++++ .../service/RemoveOrderCollectionService.java | 56 ++++++++++++++++ .../strolch/service/RemoveOrderService.java | 53 +++++++++++++++ .../RemoveResourceCollectionService.java | 56 ++++++++++++++++ .../service/RemoveResourceService.java | 53 +++++++++++++++ .../service/UpdateOrderCollectionService.java | 56 ++++++++++++++++ .../strolch/service/UpdateOrderService.java | 53 +++++++++++++++ .../UpdateResourceCollectionService.java | 56 ++++++++++++++++ .../service/UpdateResourceService.java | 53 +++++++++++++++ 20 files changed, 972 insertions(+), 12 deletions(-) create mode 100644 src/main/java/li/strolch/command/RemoveOrderCollectionCommand.java create mode 100644 src/main/java/li/strolch/command/RemoveOrderCommand.java create mode 100644 src/main/java/li/strolch/command/RemoveResourceCollectionCommand.java create mode 100644 src/main/java/li/strolch/command/RemoveResourceCommand.java create mode 100644 src/main/java/li/strolch/command/UpdateOrderCollectionCommand.java create mode 100644 src/main/java/li/strolch/command/UpdateOrderCommand.java create mode 100644 src/main/java/li/strolch/command/UpdateResourceCollectionCommand.java create mode 100644 src/main/java/li/strolch/command/UpdateResourceCommand.java create mode 100644 src/main/java/li/strolch/service/RemoveOrderCollectionService.java create mode 100644 src/main/java/li/strolch/service/RemoveOrderService.java create mode 100644 src/main/java/li/strolch/service/RemoveResourceCollectionService.java create mode 100644 src/main/java/li/strolch/service/RemoveResourceService.java create mode 100644 src/main/java/li/strolch/service/UpdateOrderCollectionService.java create mode 100644 src/main/java/li/strolch/service/UpdateOrderService.java create mode 100644 src/main/java/li/strolch/service/UpdateResourceCollectionService.java create mode 100644 src/main/java/li/strolch/service/UpdateResourceService.java diff --git a/src/main/java/li/strolch/command/AddOrderCollectionCommand.java b/src/main/java/li/strolch/command/AddOrderCollectionCommand.java index 559560d1a..3e284a391 100644 --- a/src/main/java/li/strolch/command/AddOrderCollectionCommand.java +++ b/src/main/java/li/strolch/command/AddOrderCollectionCommand.java @@ -15,6 +15,7 @@ */ package li.strolch.command; +import java.text.MessageFormat; import java.util.List; import li.strolch.agent.api.ComponentContainer; @@ -55,14 +56,11 @@ public class AddOrderCollectionCommand extends Command { OrderMap orderMap = tx().getOrderMap(); for (Order order : orders) { if (orderMap.hasElement(tx(), order.getType(), order.getId())) { - String msg = "The Order " + order.getLocator() + " already exists!"; + String msg = MessageFormat.format("The Order {0} already exists!", order.getLocator()); throw new StrolchException(msg); } - } - for (Order order : orders) { - orderMap.add(tx(), order); - } + orderMap.addAll(tx(), orders); } } diff --git a/src/main/java/li/strolch/command/AddOrderCommand.java b/src/main/java/li/strolch/command/AddOrderCommand.java index b21d5d02a..028c0e470 100644 --- a/src/main/java/li/strolch/command/AddOrderCommand.java +++ b/src/main/java/li/strolch/command/AddOrderCommand.java @@ -15,6 +15,8 @@ */ 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; @@ -52,7 +54,7 @@ public class AddOrderCommand extends Command { OrderMap orderMap = tx().getOrderMap(); if (orderMap.hasElement(tx(), this.order.getType(), this.order.getId())) { - String msg = "The Order " + this.order.getLocator() + " already exists!"; + String msg = MessageFormat.format("The Order {0} already exists!", this.order.getLocator()); throw new StrolchException(msg); } diff --git a/src/main/java/li/strolch/command/AddResourceCollectionCommand.java b/src/main/java/li/strolch/command/AddResourceCollectionCommand.java index d1a71b3da..16fb3c6ce 100644 --- a/src/main/java/li/strolch/command/AddResourceCollectionCommand.java +++ b/src/main/java/li/strolch/command/AddResourceCollectionCommand.java @@ -15,6 +15,7 @@ */ package li.strolch.command; +import java.text.MessageFormat; import java.util.List; import li.strolch.agent.api.ComponentContainer; @@ -55,14 +56,11 @@ public class AddResourceCollectionCommand extends Command { ResourceMap resourceMap = tx().getResourceMap(); for (Resource resource : resources) { if (resourceMap.hasElement(tx(), resource.getType(), resource.getId())) { - String msg = "The Resource " + resource.getLocator() + " already exists!"; + String msg = MessageFormat.format("The Resource {0} already exists!", resource.getLocator()); throw new StrolchException(msg); } - } - for (Resource resource : resources) { - resourceMap.add(tx(), resource); - } + resourceMap.addAll(tx(), resources); } } diff --git a/src/main/java/li/strolch/command/AddResourceCommand.java b/src/main/java/li/strolch/command/AddResourceCommand.java index f7f5ec17f..6543c6753 100644 --- a/src/main/java/li/strolch/command/AddResourceCommand.java +++ b/src/main/java/li/strolch/command/AddResourceCommand.java @@ -15,6 +15,8 @@ */ 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; @@ -52,7 +54,7 @@ public class AddResourceCommand extends Command { ResourceMap resourceMap = tx().getResourceMap(); if (resourceMap.hasElement(tx(), this.resource.getType(), this.resource.getId())) { - String msg = "The Resource " + this.resource.getLocator() + " already exists!"; + String msg = MessageFormat.format("The Resource {0} already exists!", this.resource.getLocator()); throw new StrolchException(msg); } diff --git a/src/main/java/li/strolch/command/RemoveOrderCollectionCommand.java b/src/main/java/li/strolch/command/RemoveOrderCollectionCommand.java new file mode 100644 index 000000000..6cb111893 --- /dev/null +++ b/src/main/java/li/strolch/command/RemoveOrderCollectionCommand.java @@ -0,0 +1,67 @@ +/* + * 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 doCommand() { + + DBC.PRE.assertNotNull("Order list may not be null!", this.orders); + + OrderMap orderMap = tx().getOrderMap(); + for (Order order : 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(), orders); + } +} diff --git a/src/main/java/li/strolch/command/RemoveOrderCommand.java b/src/main/java/li/strolch/command/RemoveOrderCommand.java new file mode 100644 index 000000000..1c115d4d2 --- /dev/null +++ b/src/main/java/li/strolch/command/RemoveOrderCommand.java @@ -0,0 +1,64 @@ +/* + * 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 doCommand() { + + DBC.PRE.assertNotNull("Order may not be null!", 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); + } +} diff --git a/src/main/java/li/strolch/command/RemoveResourceCollectionCommand.java b/src/main/java/li/strolch/command/RemoveResourceCollectionCommand.java new file mode 100644 index 000000000..7d9b972c6 --- /dev/null +++ b/src/main/java/li/strolch/command/RemoveResourceCollectionCommand.java @@ -0,0 +1,67 @@ +/* + * 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 doCommand() { + + DBC.PRE.assertNotNull("Resource list may not be null!", this.resources); + + ResourceMap resourceMap = tx().getResourceMap(); + for (Resource resource : 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(), resources); + } +} diff --git a/src/main/java/li/strolch/command/RemoveResourceCommand.java b/src/main/java/li/strolch/command/RemoveResourceCommand.java new file mode 100644 index 000000000..d9fd28cbd --- /dev/null +++ b/src/main/java/li/strolch/command/RemoveResourceCommand.java @@ -0,0 +1,64 @@ +/* + * 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 doCommand() { + + DBC.PRE.assertNotNull("Resource may not be null!", 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); + } +} diff --git a/src/main/java/li/strolch/command/UpdateOrderCollectionCommand.java b/src/main/java/li/strolch/command/UpdateOrderCollectionCommand.java new file mode 100644 index 000000000..72e59601d --- /dev/null +++ b/src/main/java/li/strolch/command/UpdateOrderCollectionCommand.java @@ -0,0 +1,67 @@ +/* + * 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; + + /** + * @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 doCommand() { + + DBC.PRE.assertNotNull("Order list may not be null!", this.orders); + + OrderMap orderMap = tx().getOrderMap(); + for (Order order : 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); + } + } + + orderMap.updateAll(tx(), orders); + } +} diff --git a/src/main/java/li/strolch/command/UpdateOrderCommand.java b/src/main/java/li/strolch/command/UpdateOrderCommand.java new file mode 100644 index 000000000..69085a778 --- /dev/null +++ b/src/main/java/li/strolch/command/UpdateOrderCommand.java @@ -0,0 +1,64 @@ +/* + * 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; + + /** + * @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 doCommand() { + + DBC.PRE.assertNotNull("Order may not be null!", 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); + } + + orderMap.update(tx(), this.order); + } +} diff --git a/src/main/java/li/strolch/command/UpdateResourceCollectionCommand.java b/src/main/java/li/strolch/command/UpdateResourceCollectionCommand.java new file mode 100644 index 000000000..043253d24 --- /dev/null +++ b/src/main/java/li/strolch/command/UpdateResourceCollectionCommand.java @@ -0,0 +1,67 @@ +/* + * 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; + + /** + * @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 doCommand() { + + DBC.PRE.assertNotNull("Resource list may not be null!", this.resources); + + ResourceMap resourceMap = tx().getResourceMap(); + for (Resource resource : 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); + } + } + + resourceMap.updateAll(tx(), resources); + } +} diff --git a/src/main/java/li/strolch/command/UpdateResourceCommand.java b/src/main/java/li/strolch/command/UpdateResourceCommand.java new file mode 100644 index 000000000..f6a479752 --- /dev/null +++ b/src/main/java/li/strolch/command/UpdateResourceCommand.java @@ -0,0 +1,64 @@ +/* + * 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; + + /** + * @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 doCommand() { + + DBC.PRE.assertNotNull("Resource may not be null!", 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); + } + + resourceMap.update(tx(), this.resource); + } +} diff --git a/src/main/java/li/strolch/service/RemoveOrderCollectionService.java b/src/main/java/li/strolch/service/RemoveOrderCollectionService.java new file mode 100644 index 000000000..ac23bd144 --- /dev/null +++ b/src/main/java/li/strolch/service/RemoveOrderCollectionService.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.RemoveOrderCollectionCommand; +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(AddOrderCollectionArg arg) { + + try (StrolchTransaction tx = openTx(arg.realm)) { + RemoveOrderCollectionCommand command = new RemoveOrderCollectionCommand(getContainer(), tx); + command.setOrders(arg.orders); + command.doCommand(); + } + + return ServiceResult.success(); + } + + public static class AddOrderCollectionArg extends ServiceArgument { + private static final long serialVersionUID = 1L; + public List orders; + } +} diff --git a/src/main/java/li/strolch/service/RemoveOrderService.java b/src/main/java/li/strolch/service/RemoveOrderService.java new file mode 100644 index 000000000..e7e7e7b33 --- /dev/null +++ b/src/main/java/li/strolch/service/RemoveOrderService.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.RemoveOrderCommand; +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(AddOrderArg arg) { + + try (StrolchTransaction tx = openTx(arg.realm)) { + RemoveOrderCommand command = new RemoveOrderCommand(getContainer(), tx); + command.setOrder(arg.order); + command.doCommand(); + } + + return ServiceResult.success(); + } + + public static class AddOrderArg extends ServiceArgument { + private static final long serialVersionUID = 1L; + public Order order; + } +} diff --git a/src/main/java/li/strolch/service/RemoveResourceCollectionService.java b/src/main/java/li/strolch/service/RemoveResourceCollectionService.java new file mode 100644 index 000000000..48df83a93 --- /dev/null +++ b/src/main/java/li/strolch/service/RemoveResourceCollectionService.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.RemoveResourceCollectionCommand; +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(AddResourceCollectionArg arg) { + + try (StrolchTransaction tx = openTx(arg.realm)) { + RemoveResourceCollectionCommand command = new RemoveResourceCollectionCommand(getContainer(), tx); + command.setResources(arg.resources); + command.doCommand(); + } + + return ServiceResult.success(); + } + + public static class AddResourceCollectionArg extends ServiceArgument { + private static final long serialVersionUID = 1L; + public List resources; + } +} diff --git a/src/main/java/li/strolch/service/RemoveResourceService.java b/src/main/java/li/strolch/service/RemoveResourceService.java new file mode 100644 index 000000000..4e9585731 --- /dev/null +++ b/src/main/java/li/strolch/service/RemoveResourceService.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.RemoveResourceCommand; +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(AddResourceArg arg) { + + try (StrolchTransaction tx = openTx(arg.realm)) { + RemoveResourceCommand command = new RemoveResourceCommand(getContainer(), tx); + command.setResource(arg.resource); + command.doCommand(); + } + + return ServiceResult.success(); + } + + public static class AddResourceArg extends ServiceArgument { + private static final long serialVersionUID = 1L; + public Resource resource; + } +} diff --git a/src/main/java/li/strolch/service/UpdateOrderCollectionService.java b/src/main/java/li/strolch/service/UpdateOrderCollectionService.java new file mode 100644 index 000000000..3e4bcac91 --- /dev/null +++ b/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(AddOrderCollectionArg arg) { + + try (StrolchTransaction tx = openTx(arg.realm)) { + UpdateOrderCollectionCommand command = new UpdateOrderCollectionCommand(getContainer(), tx); + command.setOrders(arg.orders); + command.doCommand(); + } + + return ServiceResult.success(); + } + + public static class AddOrderCollectionArg extends ServiceArgument { + private static final long serialVersionUID = 1L; + public List orders; + } +} diff --git a/src/main/java/li/strolch/service/UpdateOrderService.java b/src/main/java/li/strolch/service/UpdateOrderService.java new file mode 100644 index 000000000..47db84604 --- /dev/null +++ b/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(AddOrderArg arg) { + + try (StrolchTransaction tx = openTx(arg.realm)) { + UpdateOrderCommand command = new UpdateOrderCommand(getContainer(), tx); + command.setOrder(arg.order); + command.doCommand(); + } + + return ServiceResult.success(); + } + + public static class AddOrderArg extends ServiceArgument { + private static final long serialVersionUID = 1L; + public Order order; + } +} diff --git a/src/main/java/li/strolch/service/UpdateResourceCollectionService.java b/src/main/java/li/strolch/service/UpdateResourceCollectionService.java new file mode 100644 index 000000000..1d982588f --- /dev/null +++ b/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(AddResourceCollectionArg arg) { + + try (StrolchTransaction tx = openTx(arg.realm)) { + UpdateResourceCollectionCommand command = new UpdateResourceCollectionCommand(getContainer(), tx); + command.setResources(arg.resources); + command.doCommand(); + } + + return ServiceResult.success(); + } + + public static class AddResourceCollectionArg extends ServiceArgument { + private static final long serialVersionUID = 1L; + public List resources; + } +} diff --git a/src/main/java/li/strolch/service/UpdateResourceService.java b/src/main/java/li/strolch/service/UpdateResourceService.java new file mode 100644 index 000000000..56e13c1f9 --- /dev/null +++ b/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(AddResourceArg arg) { + + try (StrolchTransaction tx = openTx(arg.realm)) { + UpdateResourceCommand command = new UpdateResourceCommand(getContainer(), tx); + command.setResource(arg.resource); + command.doCommand(); + } + + return ServiceResult.success(); + } + + public static class AddResourceArg extends ServiceArgument { + private static final long serialVersionUID = 1L; + public Resource resource; + } +} From 45a7020126ca65cd9d86e554225bc73e902b6882 Mon Sep 17 00:00:00 2001 From: Robert von Burg Date: Mon, 13 Jan 2014 19:12:04 +0100 Subject: [PATCH 28/65] [New] Implemented Add* and RemoveParameterService and Command --- .../parameter/AddParameterCommand.java | 74 +++++++++++++++++++ .../parameter/RemoveParameterCommand.java | 72 ++++++++++++++++++ .../parameter/AddParameterService.java | 60 +++++++++++++++ .../parameter/RemoveParameterService.java | 59 +++++++++++++++ 4 files changed, 265 insertions(+) create mode 100644 src/main/java/li/strolch/command/parameter/AddParameterCommand.java create mode 100644 src/main/java/li/strolch/command/parameter/RemoveParameterCommand.java create mode 100644 src/main/java/li/strolch/service/parameter/AddParameterService.java create mode 100644 src/main/java/li/strolch/service/parameter/RemoveParameterService.java diff --git a/src/main/java/li/strolch/command/parameter/AddParameterCommand.java b/src/main/java/li/strolch/command/parameter/AddParameterCommand.java new file mode 100644 index 000000000..f1e162ba8 --- /dev/null +++ b/src/main/java/li/strolch/command/parameter/AddParameterCommand.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.command.parameter; + +import java.text.MessageFormat; + +import ch.eitchnet.utils.dbc.DBC; +import li.strolch.agent.api.ComponentContainer; +import li.strolch.model.ParameterizedElement; +import li.strolch.model.parameter.Parameter; +import li.strolch.persistence.api.StrolchPersistenceException; +import li.strolch.persistence.api.StrolchTransaction; +import li.strolch.service.api.Command; + +/** + * @author Robert von Burg + */ +public class AddParameterCommand extends Command { + + private ParameterizedElement element; + private Parameter parameter; + + /** + * @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 doCommand() { + DBC.PRE.assertNotNull("Element may not be null!", element); + DBC.PRE.assertNotNull("Parameter may not be null!", parameter); + + if (element.hasParameter(this.parameter.getId())) { + String msg = "The Parameter {0} already exists on element {1}"; + msg = MessageFormat.format(msg, parameter.getId(), element.getLocator()); + throw new StrolchPersistenceException(msg); + } + + this.element.addParameter(parameter); + } + +} diff --git a/src/main/java/li/strolch/command/parameter/RemoveParameterCommand.java b/src/main/java/li/strolch/command/parameter/RemoveParameterCommand.java new file mode 100644 index 000000000..7b45ee04b --- /dev/null +++ b/src/main/java/li/strolch/command/parameter/RemoveParameterCommand.java @@ -0,0 +1,72 @@ +/* + * 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.model.ParameterizedElement; +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; + + /** + * @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 doCommand() { + DBC.PRE.assertNotNull("Element may not be null!", element); + DBC.PRE.assertNotEmpty("ParameterId must be set!", parameterId); + + if (!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, parameterId, element.getLocator()); + throw new StrolchPersistenceException(msg); + } + + this.element.removeParameter(parameterId); + } +} diff --git a/src/main/java/li/strolch/service/parameter/AddParameterService.java b/src/main/java/li/strolch/service/parameter/AddParameterService.java new file mode 100644 index 000000000..57670a7fb --- /dev/null +++ b/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); + command.doCommand(); + } + + return ServiceResult.success(); + } + + public static class AddParameterArg extends ServiceArgument { + private static final long serialVersionUID = 1L; + public Locator locator; + public Parameter parameter; + } +} diff --git a/src/main/java/li/strolch/service/parameter/RemoveParameterService.java b/src/main/java/li/strolch/service/parameter/RemoveParameterService.java new file mode 100644 index 000000000..a274a88e8 --- /dev/null +++ b/src/main/java/li/strolch/service/parameter/RemoveParameterService.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.parameter; + +import li.strolch.command.parameter.RemoveParameterCommand; +import li.strolch.model.Locator; +import li.strolch.model.ParameterizedElement; +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(AddParameterArg arg) { + + try (StrolchTransaction tx = openTx(arg.realm)) { + + ParameterizedElement element = tx.findElement(arg.locator); + + RemoveParameterCommand command = new RemoveParameterCommand(getContainer(), tx); + command.setElement(element); + command.setParameterId(arg.parameterId); + command.doCommand(); + } + + return ServiceResult.success(); + } + + public static class AddParameterArg extends ServiceArgument { + private static final long serialVersionUID = 1L; + public Locator locator; + public String parameterId; + } +} From c0d043f06e4496c318e16be563681b4213d7d4c7 Mon Sep 17 00:00:00 2001 From: Robert von Burg Date: Thu, 23 Jan 2014 22:01:31 +0100 Subject: [PATCH 29/65] [New] added version info metadata to agent --- pom.xml | 6 +++++- src/main/resources/componentVersion.properties | 6 ++++++ 2 files changed, 11 insertions(+), 1 deletion(-) create mode 100644 src/main/resources/componentVersion.properties diff --git a/pom.xml b/pom.xml index 5e4218c1e..c55d5b9d3 100644 --- a/pom.xml +++ b/pom.xml @@ -48,7 +48,7 @@ ch.eitchnet ch.eitchnet.privilege - + li.strolch li.strolch.testbase @@ -58,6 +58,10 @@ + + org.codehaus.mojo + buildnumber-maven-plugin + org.apache.maven.plugins maven-eclipse-plugin diff --git a/src/main/resources/componentVersion.properties b/src/main/resources/componentVersion.properties new file mode 100644 index 000000000..1f050160f --- /dev/null +++ b/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 From 9dcd88df64b1572d5b535cc53a582d8545e92f22 Mon Sep 17 00:00:00 2001 From: Robert von Burg Date: Thu, 23 Jan 2014 22:52:50 +0100 Subject: [PATCH 30/65] [Project] added Jenkins build badge to README.md --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 7b20d2d05..94a8d96bb 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,6 @@ 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 From 2f203e72005bffca60e89cbb38f31fad1c7cf8cf Mon Sep 17 00:00:00 2001 From: Robert von Burg Date: Sat, 25 Jan 2014 22:15:37 +0100 Subject: [PATCH 31/65] [Minor] code cleanup --- .../java/li/strolch/command/parameter/AddParameterCommand.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/li/strolch/command/parameter/AddParameterCommand.java b/src/main/java/li/strolch/command/parameter/AddParameterCommand.java index f1e162ba8..494afe7e5 100644 --- a/src/main/java/li/strolch/command/parameter/AddParameterCommand.java +++ b/src/main/java/li/strolch/command/parameter/AddParameterCommand.java @@ -17,13 +17,13 @@ package li.strolch.command.parameter; import java.text.MessageFormat; -import ch.eitchnet.utils.dbc.DBC; import li.strolch.agent.api.ComponentContainer; import li.strolch.model.ParameterizedElement; 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 From 03cdee30129fab022a1c6a4fe6d7d9e9f43fc0e0 Mon Sep 17 00:00:00 2001 From: Robert von Burg Date: Thu, 30 Jan 2014 00:21:34 +0100 Subject: [PATCH 32/65] [New] Implemented Export and Import model services and commands --- .../command/XmlExportModelCommand.java | 188 ++++++++++++++++++ .../command/XmlImportModelCommand.java | 134 +++++++++++++ .../service/XmlExportModelArgument.java | 31 +++ .../service/XmlExportModelService.java | 73 +++++++ .../service/XmlImportModelArgument.java | 33 +++ ...ervice.java => XmlImportModelService.java} | 35 ++-- 6 files changed, 476 insertions(+), 18 deletions(-) create mode 100644 src/main/java/li/strolch/command/XmlExportModelCommand.java create mode 100644 src/main/java/li/strolch/command/XmlImportModelCommand.java create mode 100644 src/main/java/li/strolch/service/XmlExportModelArgument.java create mode 100644 src/main/java/li/strolch/service/XmlExportModelService.java create mode 100644 src/main/java/li/strolch/service/XmlImportModelArgument.java rename src/main/java/li/strolch/service/{ImportModelFromXmlService.java => XmlImportModelService.java} (67%) diff --git a/src/main/java/li/strolch/command/XmlExportModelCommand.java b/src/main/java/li/strolch/command/XmlExportModelCommand.java new file mode 100644 index 000000000..447ec93c1 --- /dev/null +++ b/src/main/java/li/strolch/command/XmlExportModelCommand.java @@ -0,0 +1,188 @@ +/* + * 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.io.FileOutputStream; +import java.text.MessageFormat; +import java.util.Date; +import java.util.Set; +import java.util.TreeSet; + +import javanet.staxutils.IndentingXMLStreamWriter; + +import javax.xml.stream.XMLOutputFactory; +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.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.model.xml.XmlModelSaxReader.XmlModelStatistics; +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 { + + // input + private File modelFile; + private boolean doOrders; + private boolean doResources; + private Set orderTypes; + private Set resourceTypes; + + // output + private XmlModelStatistics statistics; + + /** + * @param container + * @param tx + */ + public XmlExportModelCommand(ComponentContainer container, StrolchTransaction tx) { + super(container, tx); + } + + @Override + public void doCommand() { + DBC.PRE.assertNotExists("Model may not already exist!", this.modelFile); + + this.statistics = new XmlModelStatistics(); + this.statistics.startTime = new Date(); + long start = System.nanoTime(); + + try (FileOutputStream out = new FileOutputStream(this.modelFile)) { + + 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); + + if (doResources) { + ResourceMap resourceMap = tx().getResourceMap(); + Set resourceTypesToExport = resourceMap.getTypes(tx()); + if (!this.resourceTypes.isEmpty()) + resourceTypesToExport.retainAll(resourceTypes); + + resourceTypesToExport = new TreeSet<>(resourceTypesToExport); + ResourceVisitor visitor = new ResourceToSaxWriterVisitor(writer); + for (String type : resourceTypesToExport) { + Set keysByType = new TreeSet<>(resourceMap.getKeysBy(tx(), type)); + for (String id : keysByType) { + Resource resource = resourceMap.getBy(tx(), type, id); + visitor.visit(resource); + statistics.nrOfResources++; + } + } + } + + if (doOrders) { + OrderMap orderMap = tx().getOrderMap(); + Set orderTypesToExport = orderMap.getTypes(tx()); + if (!this.orderTypes.isEmpty()) + orderTypesToExport.retainAll(orderTypes); + + orderTypesToExport = new TreeSet<>(orderTypesToExport); + OrderVisitor visitor = new OrderToSaxWriterVisitor(writer); + for (String type : orderTypesToExport) { + Set keysByType = new TreeSet<>(orderMap.getKeysBy(tx(), type)); + for (String id : keysByType) { + Order order = orderMap.getBy(tx(), type, id); + visitor.visit(order); + statistics.nrOfOrders++; + } + } + } + + // and now end + writer.writeEndElement(); + writer.writeEndDocument(); + writer.flush(); + + writer.close(); + + this.statistics.durationNanos = System.nanoTime() - start; + + } catch (Exception e) { + if (modelFile.exists()) + modelFile.delete(); + String msg = "Failed to write model to file {0} due to {1}"; + msg = MessageFormat.format(msg, modelFile, e.getMessage()); + throw new StrolchException(msg, e); + } + } + + /** + * @param modelFile + * the modelFile to set + */ + public void setModelFile(File modelFile) { + this.modelFile = modelFile; + } + + /** + * @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 XmlModelStatistics getStatistics() { + return this.statistics; + } +} diff --git a/src/main/java/li/strolch/command/XmlImportModelCommand.java b/src/main/java/li/strolch/command/XmlImportModelCommand.java new file mode 100644 index 000000000..a5d00eeae --- /dev/null +++ b/src/main/java/li/strolch/command/XmlImportModelCommand.java @@ -0,0 +1,134 @@ +/* + * 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.xml.XmlModelSaxFileReader; +import li.strolch.model.xml.XmlModelSaxReader.XmlModelStatistics; +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 XmlModelStatistics statistics; + + /** + * @param container + * @param tx + */ + public XmlImportModelCommand(ComponentContainer container, StrolchTransaction tx) { + super(container, tx); + } + + @Override + public void doCommand() { + DBC.PRE.assertExists("Model must exist!", this.modelFile); + + InMemoryElementListener elementListener = new InMemoryElementListener(tx()); + + elementListener.setAddOrders(addOrders); + elementListener.setAddResources(addResources); + elementListener.setUpdateOrders(updateOrders); + elementListener.setUpdateResources(updateResources); + elementListener.setOrderTypes(orderTypes); + elementListener.setResourceTypes(resourceTypes); + + XmlModelSaxFileReader handler = new XmlModelSaxFileReader(elementListener, modelFile); + handler.parseFile(); + + statistics = handler.getStatistics(); + } + + /** + * @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 XmlModelStatistics getStatistics() { + return this.statistics; + } +} diff --git a/src/main/java/li/strolch/service/XmlExportModelArgument.java b/src/main/java/li/strolch/service/XmlExportModelArgument.java new file mode 100644 index 000000000..6993d79b3 --- /dev/null +++ b/src/main/java/li/strolch/service/XmlExportModelArgument.java @@ -0,0 +1,31 @@ +/* + * 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 doOrders = true; + public boolean doResources = true; + public Set orderTypes = new HashSet<>(); + public Set resourceTypes = new HashSet<>(); +} \ No newline at end of file diff --git a/src/main/java/li/strolch/service/XmlExportModelService.java b/src/main/java/li/strolch/service/XmlExportModelService.java new file mode 100644 index 000000000..8716ee4cb --- /dev/null +++ b/src/main/java/li/strolch/service/XmlExportModelService.java @@ -0,0 +1,73 @@ +/* + * 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.xml.XmlModelSaxReader.XmlModelStatistics; +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 XmlExportModelService extends AbstractService { + + private static final long serialVersionUID = 1L; + + @Override + protected ServiceResult getResultInstance() { + return new ServiceResult(); + } + + @Override + protected ServiceResult internalDoService(XmlExportModelArgument arg) { + + File dataPath = getRuntimeConfiguration().getDataPath(); + File modelFile = new File(dataPath, arg.modelFileName); + if (modelFile.exists()) { + 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); + } + + XmlModelStatistics statistics; + try (StrolchTransaction tx = openTx(arg.realm)) { + + XmlExportModelCommand command = new XmlExportModelCommand(getContainer(), tx); + command.setModelFile(modelFile); + command.setDoOrders(arg.doOrders); + command.setDoResources(arg.doResources); + command.setOrderTypes(arg.orderTypes); + command.setResourceTypes(arg.resourceTypes); + command.doCommand(); + statistics = command.getStatistics(); + } + + String durationS = StringHelper.formatNanoDuration(statistics.durationNanos); + logger.info(MessageFormat + .format("Writing XML Model file {0} for realm {1} took {2} at path: {3}", modelFile.getName(), arg.realm, durationS, modelFile.getAbsolutePath())); //$NON-NLS-1$ + logger.info(MessageFormat.format("Wrote {0} Orders", statistics.nrOfOrders)); //$NON-NLS-1$ + logger.info(MessageFormat.format("Wrote {0} Resources", statistics.nrOfResources)); //$NON-NLS-1$ + + return ServiceResult.success(); + } +} diff --git a/src/main/java/li/strolch/service/XmlImportModelArgument.java b/src/main/java/li/strolch/service/XmlImportModelArgument.java new file mode 100644 index 000000000..853165c32 --- /dev/null +++ b/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/src/main/java/li/strolch/service/ImportModelFromXmlService.java b/src/main/java/li/strolch/service/XmlImportModelService.java similarity index 67% rename from src/main/java/li/strolch/service/ImportModelFromXmlService.java rename to src/main/java/li/strolch/service/XmlImportModelService.java index e4a7dfd35..50dfe92cd 100644 --- a/src/main/java/li/strolch/service/ImportModelFromXmlService.java +++ b/src/main/java/li/strolch/service/XmlImportModelService.java @@ -18,21 +18,18 @@ package li.strolch.service; import java.io.File; import java.text.MessageFormat; -import li.strolch.agent.impl.InMemoryElementListener; +import li.strolch.command.XmlImportModelCommand; import li.strolch.exception.StrolchException; -import li.strolch.model.xml.XmlModelDefaultHandler.XmlModelStatistics; -import li.strolch.model.xml.XmlModelFileHandler; +import li.strolch.model.xml.XmlModelSaxReader.XmlModelStatistics; import li.strolch.persistence.api.StrolchTransaction; import li.strolch.service.api.AbstractService; -import li.strolch.service.api.ServiceArgument; import li.strolch.service.api.ServiceResult; import ch.eitchnet.utils.helper.StringHelper; /** * @author Robert von Burg */ -public class ImportModelFromXmlService extends - AbstractService { +public class XmlImportModelService extends AbstractService { private static final long serialVersionUID = 1L; @@ -42,22 +39,29 @@ public class ImportModelFromXmlService extends } @Override - protected ServiceResult internalDoService(ImportModelFromXmlArg arg) { + protected ServiceResult internalDoService(XmlImportModelArgument arg) { File dataPath = getRuntimeConfiguration().getDataPath(); - File modelFile = new File(dataPath, arg.fileName); + 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.fileName, dataPath); + msg = MessageFormat.format(msg, arg.modelFileName, dataPath); throw new StrolchException(msg); } XmlModelStatistics statistics; try (StrolchTransaction tx = openTx(arg.realm)) { - InMemoryElementListener elementListener = new InMemoryElementListener(tx); - XmlModelFileHandler handler = new XmlModelFileHandler(elementListener, modelFile); - handler.parseFile(); - statistics = handler.getStatistics(); + + XmlImportModelCommand 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); + command.doCommand(); + statistics = command.getStatistics(); } String durationS = StringHelper.formatNanoDuration(statistics.durationNanos); @@ -68,9 +72,4 @@ public class ImportModelFromXmlService extends return ServiceResult.success(); } - - public static class ImportModelFromXmlArg extends ServiceArgument { - private static final long serialVersionUID = 1L; - public String fileName; - } } From 8e273b13063a59dc1a851430773a2e8504f359f9 Mon Sep 17 00:00:00 2001 From: Robert von Burg Date: Thu, 13 Feb 2014 22:22:04 +0100 Subject: [PATCH 33/65] [Minor] there is no getDefaultRealm() method anymore --- .../service/XmlExportModelArgument.java | 25 +++++++++++++++++++ .../service/XmlExportModelService.java | 12 ++++----- .../service/test/AbstractServiceTest.java | 2 +- .../service/test/NoPrivilegeServiceTest.java | 2 +- 4 files changed, 32 insertions(+), 9 deletions(-) diff --git a/src/main/java/li/strolch/service/XmlExportModelArgument.java b/src/main/java/li/strolch/service/XmlExportModelArgument.java index 6993d79b3..e50fca6e3 100644 --- a/src/main/java/li/strolch/service/XmlExportModelArgument.java +++ b/src/main/java/li/strolch/service/XmlExportModelArgument.java @@ -28,4 +28,29 @@ public class XmlExportModelArgument extends ServiceArgument { 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 ["); + + if (this.doResources) + builder.append("resources"); + if (this.doOrders) + builder.append(", orders"); + + if (this.resourceTypes != null) { + builder.append(", resourceTypes="); + builder.append(this.resourceTypes); + } + if (this.orderTypes != null) { + builder.append(", orderTypes="); + builder.append(this.orderTypes); + } + + builder.append(", modelFileName="); + builder.append(this.modelFileName); + builder.append("]"); + return builder.toString(); + } } \ No newline at end of file diff --git a/src/main/java/li/strolch/service/XmlExportModelService.java b/src/main/java/li/strolch/service/XmlExportModelService.java index 8716ee4cb..ec40d72fe 100644 --- a/src/main/java/li/strolch/service/XmlExportModelService.java +++ b/src/main/java/li/strolch/service/XmlExportModelService.java @@ -24,7 +24,6 @@ import li.strolch.model.xml.XmlModelSaxReader.XmlModelStatistics; 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 @@ -49,6 +48,9 @@ public class XmlExportModelService extends AbstractService Date: Fri, 14 Feb 2014 21:18:14 +0100 Subject: [PATCH 34/65] [New] XmlExportModelService now has multi file support Also added tests for exporting model --- .../command/XmlExportModelCommand.java | 126 +++++++++++++----- .../service/XmlExportModelArgument.java | 14 +- .../service/XmlExportModelService.java | 4 + .../service/test/GreetingServiceTest.java | 4 +- .../service/test/NoPrivilegeServiceTest.java | 4 +- .../li/strolch/service/test/ServiceTest.java | 5 +- .../service/test/XmlExportServiceTest.java | 122 +++++++++++++++++ .../test/{ => model}/GreetingResult.java | 2 +- .../test/{ => model}/GreetingService.java | 4 +- .../service/test/{ => model}/TestService.java | 2 +- .../config/StrolchConfiguration.xml | 19 +++ .../resources/transienttest/data/Enums.xml | 34 +++++ .../resources/transienttest/data/Orders.xml | 14 ++ .../transienttest/data/Resources.xml | 14 ++ .../transienttest/data/StrolchModel.xml | 30 +++++ 15 files changed, 357 insertions(+), 41 deletions(-) create mode 100644 src/test/java/li/strolch/service/test/XmlExportServiceTest.java rename src/test/java/li/strolch/service/test/{ => model}/GreetingResult.java (96%) rename src/test/java/li/strolch/service/test/{ => model}/GreetingService.java (93%) rename src/test/java/li/strolch/service/test/{ => model}/TestService.java (96%) create mode 100644 src/test/resources/transienttest/config/StrolchConfiguration.xml create mode 100644 src/test/resources/transienttest/data/Enums.xml create mode 100644 src/test/resources/transienttest/data/Orders.xml create mode 100644 src/test/resources/transienttest/data/Resources.xml create mode 100644 src/test/resources/transienttest/data/StrolchModel.xml diff --git a/src/main/java/li/strolch/command/XmlExportModelCommand.java b/src/main/java/li/strolch/command/XmlExportModelCommand.java index 447ec93c1..aec0416eb 100644 --- a/src/main/java/li/strolch/command/XmlExportModelCommand.java +++ b/src/main/java/li/strolch/command/XmlExportModelCommand.java @@ -15,16 +15,21 @@ */ package li.strolch.command; +import static ch.eitchnet.utils.helper.StringHelper.UNDERLINE; + import java.io.File; import java.io.FileOutputStream; import java.text.MessageFormat; import java.util.Date; +import java.util.HashSet; import java.util.Set; import java.util.TreeSet; 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; @@ -49,6 +54,8 @@ import ch.eitchnet.utils.dbc.DBC; */ public class XmlExportModelCommand extends Command { + public static final String XML_FILE_SUFFIX = ".xml"; + // input private File modelFile; private boolean doOrders; @@ -58,11 +65,8 @@ public class XmlExportModelCommand extends Command { // output private XmlModelStatistics statistics; + private boolean multiFile; - /** - * @param container - * @param tx - */ public XmlExportModelCommand(ComponentContainer container, StrolchTransaction tx) { super(container, tx); } @@ -70,53 +74,72 @@ public class XmlExportModelCommand extends Command { @Override public void doCommand() { DBC.PRE.assertNotExists("Model may not already exist!", this.modelFile); + String fileName = this.modelFile.getName(); + DBC.PRE.assertTrue("Model file must end with .xml", fileName.endsWith(XML_FILE_SUFFIX)); + long start = System.nanoTime(); this.statistics = new XmlModelStatistics(); this.statistics.startTime = new Date(); - long start = System.nanoTime(); + + String exportName = fileName.substring(0, fileName.indexOf(XML_FILE_SUFFIX)); + Set createdFiles = new HashSet<>(); try (FileOutputStream out = new FileOutputStream(this.modelFile)) { + createdFiles.add(this.modelFile); - XMLOutputFactory factory = XMLOutputFactory.newInstance(); - XMLStreamWriter writer = factory.createXMLStreamWriter(out, StrolchConstants.DEFAULT_ENCODING); - writer = new IndentingXMLStreamWriter(writer); + XMLStreamWriter writer = openXmlStreamWriter(out); - // start document - writer.writeStartDocument(StrolchConstants.DEFAULT_ENCODING, StrolchConstants.DEFAULT_XML_VERSION); - writer.writeStartElement(Tags.STROLCH_MODEL); - - if (doResources) { + if (this.doResources) { ResourceMap resourceMap = tx().getResourceMap(); Set resourceTypesToExport = resourceMap.getTypes(tx()); if (!this.resourceTypes.isEmpty()) - resourceTypesToExport.retainAll(resourceTypes); + resourceTypesToExport.retainAll(this.resourceTypes); resourceTypesToExport = new TreeSet<>(resourceTypesToExport); - ResourceVisitor visitor = new ResourceToSaxWriterVisitor(writer); for (String type : resourceTypesToExport) { - Set keysByType = new TreeSet<>(resourceMap.getKeysBy(tx(), type)); - for (String id : keysByType) { - Resource resource = resourceMap.getBy(tx(), type, id); - visitor.visit(resource); - statistics.nrOfResources++; + + if (!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(modelFile.getParentFile(), typeXmlFile); + try (FileOutputStream typeOut = new FileOutputStream(typeXmlFileF)) { + createdFiles.add(typeXmlFileF); + XMLStreamWriter typeWriter = openXmlStreamWriter(typeOut); + writeResourcesByType(typeWriter, resourceMap, type); + typeWriter.writeEndDocument(); + } } } } - if (doOrders) { + if (this.doOrders) { OrderMap orderMap = tx().getOrderMap(); Set orderTypesToExport = orderMap.getTypes(tx()); if (!this.orderTypes.isEmpty()) - orderTypesToExport.retainAll(orderTypes); + orderTypesToExport.retainAll(this.orderTypes); orderTypesToExport = new TreeSet<>(orderTypesToExport); - OrderVisitor visitor = new OrderToSaxWriterVisitor(writer); for (String type : orderTypesToExport) { - Set keysByType = new TreeSet<>(orderMap.getKeysBy(tx(), type)); - for (String id : keysByType) { - Order order = orderMap.getBy(tx(), type, id); - visitor.visit(order); - statistics.nrOfOrders++; + + if (!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(modelFile.getParentFile(), typeXmlFile); + try (FileOutputStream typeOut = new FileOutputStream(typeXmlFileF)) { + createdFiles.add(typeXmlFileF); + XMLStreamWriter typeWriter = openXmlStreamWriter(typeOut); + writeOrdersByType(typeWriter, orderMap, type); + typeWriter.writeEndDocument(); + } } } } @@ -131,14 +154,48 @@ public class XmlExportModelCommand extends Command { this.statistics.durationNanos = System.nanoTime() - start; } catch (Exception e) { - if (modelFile.exists()) - modelFile.delete(); + 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, modelFile, e.getMessage()); + msg = MessageFormat.format(msg, this.modelFile, e.getMessage()); throw new StrolchException(msg, e); } } + 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++; + } + } + + 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++; + } + } + + 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 @@ -147,6 +204,13 @@ public class XmlExportModelCommand extends Command { this.modelFile = modelFile; } + /** + * @param multiFile + */ + public void setMultiFile(boolean multiFile) { + this.multiFile = multiFile; + } + /** * @param doOrders * the doOrders to set diff --git a/src/main/java/li/strolch/service/XmlExportModelArgument.java b/src/main/java/li/strolch/service/XmlExportModelArgument.java index e50fca6e3..a8693d0b1 100644 --- a/src/main/java/li/strolch/service/XmlExportModelArgument.java +++ b/src/main/java/li/strolch/service/XmlExportModelArgument.java @@ -24,6 +24,7 @@ public class XmlExportModelArgument extends ServiceArgument { private static final long serialVersionUID = 1L; public String modelFileName; + public boolean multiFile; public boolean doOrders = true; public boolean doResources = true; public Set orderTypes = new HashSet<>(); @@ -34,18 +35,25 @@ public class XmlExportModelArgument extends ServiceArgument { StringBuilder builder = new StringBuilder(); builder.append("XmlExportModelArgument ["); + builder.append("multiFile="); + builder.append(this.multiFile); + if (this.doResources) - builder.append("resources"); + builder.append(", resources"); if (this.doOrders) builder.append(", orders"); - if (this.resourceTypes != null) { + if (this.resourceTypes != null && !this.resourceTypes.isEmpty()) { builder.append(", resourceTypes="); builder.append(this.resourceTypes); + } else { + builder.append(", resourceTypes=*"); } - if (this.orderTypes != null) { + if (this.orderTypes != null && !this.orderTypes.isEmpty()) { builder.append(", orderTypes="); builder.append(this.orderTypes); + } else { + builder.append(", orderTypes=*"); } builder.append(", modelFileName="); diff --git a/src/main/java/li/strolch/service/XmlExportModelService.java b/src/main/java/li/strolch/service/XmlExportModelService.java index ec40d72fe..64f3eded5 100644 --- a/src/main/java/li/strolch/service/XmlExportModelService.java +++ b/src/main/java/li/strolch/service/XmlExportModelService.java @@ -24,6 +24,7 @@ import li.strolch.model.xml.XmlModelSaxReader.XmlModelStatistics; 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 @@ -40,6 +41,8 @@ public class XmlExportModelService extends AbstractService + * + * 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.model.Tags; +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; + +/** + * @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; + + @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(); + } + + @Test + public void shouldExportToXmlSingleFile() { + + XmlExportModelService service = new XmlExportModelService(); + XmlExportModelArgument arg = new XmlExportModelArgument(); + arg.modelFileName = "TestExportSingle.xml"; + arg.multiFile = false; + ServiceResult result = runtimeMock.getServiceHandler().doService(null, 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(null, 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(Tags.TEMPLATE); + arg.multiFile = true; + ServiceResult result = runtimeMock.getServiceHandler().doService(null, 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(null, 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/src/test/java/li/strolch/service/test/GreetingResult.java b/src/test/java/li/strolch/service/test/model/GreetingResult.java similarity index 96% rename from src/test/java/li/strolch/service/test/GreetingResult.java rename to src/test/java/li/strolch/service/test/model/GreetingResult.java index 6b37c252b..2ada7e3fc 100644 --- a/src/test/java/li/strolch/service/test/GreetingResult.java +++ b/src/test/java/li/strolch/service/test/model/GreetingResult.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package li.strolch.service.test; +package li.strolch.service.test.model; import li.strolch.service.api.ServiceResult; import li.strolch.service.api.ServiceResultState; diff --git a/src/test/java/li/strolch/service/test/GreetingService.java b/src/test/java/li/strolch/service/test/model/GreetingService.java similarity index 93% rename from src/test/java/li/strolch/service/test/GreetingService.java rename to src/test/java/li/strolch/service/test/model/GreetingService.java index da5a1af29..656d53abe 100644 --- a/src/test/java/li/strolch/service/test/GreetingService.java +++ b/src/test/java/li/strolch/service/test/model/GreetingService.java @@ -13,13 +13,13 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package li.strolch.service.test; +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.GreetingService.GreetingArgument; +import li.strolch.service.test.model.GreetingService.GreetingArgument; import ch.eitchnet.utils.helper.StringHelper; /** diff --git a/src/test/java/li/strolch/service/test/TestService.java b/src/test/java/li/strolch/service/test/model/TestService.java similarity index 96% rename from src/test/java/li/strolch/service/test/TestService.java rename to src/test/java/li/strolch/service/test/model/TestService.java index a3e2df4e8..4fedaf110 100644 --- a/src/test/java/li/strolch/service/test/TestService.java +++ b/src/test/java/li/strolch/service/test/model/TestService.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package li.strolch.service.test; +package li.strolch.service.test.model; import li.strolch.service.api.AbstractService; import li.strolch.service.api.ServiceArgument; diff --git a/src/test/resources/transienttest/config/StrolchConfiguration.xml b/src/test/resources/transienttest/config/StrolchConfiguration.xml new file mode 100644 index 000000000..d799c11b8 --- /dev/null +++ b/src/test/resources/transienttest/config/StrolchConfiguration.xml @@ -0,0 +1,19 @@ + + + + StrolchRuntimeTest + + TRANSIENT + StrolchModel.xml + true + + + + ServiceHandler + li.strolch.service.api.ServiceHandler + li.strolch.service.api.DefaultServiceHandler + + true + + + \ No newline at end of file diff --git a/src/test/resources/transienttest/data/Enums.xml b/src/test/resources/transienttest/data/Enums.xml new file mode 100644 index 000000000..62ddb9c61 --- /dev/null +++ b/src/test/resources/transienttest/data/Enums.xml @@ -0,0 +1,34 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/test/resources/transienttest/data/Orders.xml b/src/test/resources/transienttest/data/Orders.xml new file mode 100644 index 000000000..55358bcaa --- /dev/null +++ b/src/test/resources/transienttest/data/Orders.xml @@ -0,0 +1,14 @@ + + + + + + + + + + + + + + diff --git a/src/test/resources/transienttest/data/Resources.xml b/src/test/resources/transienttest/data/Resources.xml new file mode 100644 index 000000000..e6259cb83 --- /dev/null +++ b/src/test/resources/transienttest/data/Resources.xml @@ -0,0 +1,14 @@ + + + + + + + + + + + + + + diff --git a/src/test/resources/transienttest/data/StrolchModel.xml b/src/test/resources/transienttest/data/StrolchModel.xml new file mode 100644 index 000000000..9fd6b2020 --- /dev/null +++ b/src/test/resources/transienttest/data/StrolchModel.xml @@ -0,0 +1,30 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file From af33df7503aba5833edab99b60f7ecbaaa49d050 Mon Sep 17 00:00:00 2001 From: Robert von Burg Date: Fri, 14 Feb 2014 21:45:48 +0100 Subject: [PATCH 35/65] [Minor] added logging of work done when exporting model --- .../command/XmlExportModelCommand.java | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/src/main/java/li/strolch/command/XmlExportModelCommand.java b/src/main/java/li/strolch/command/XmlExportModelCommand.java index aec0416eb..d4a469975 100644 --- a/src/main/java/li/strolch/command/XmlExportModelCommand.java +++ b/src/main/java/li/strolch/command/XmlExportModelCommand.java @@ -67,6 +67,9 @@ public class XmlExportModelCommand extends Command { private XmlModelStatistics statistics; private boolean multiFile; + private int nrOfResourcesToExport; + private int nrOfOrdersToExport; + public XmlExportModelCommand(ComponentContainer container, StrolchTransaction tx) { super(container, tx); } @@ -84,6 +87,31 @@ public class XmlExportModelCommand extends Command { String exportName = fileName.substring(0, fileName.indexOf(XML_FILE_SUFFIX)); 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) { + nrOfResourcesToExport += resourceMap.querySize(tx(), type); + } + logger.info("Exporting " + nrOfResourcesToExport + " Resources..."); + } + + if (this.doOrders) { + OrderMap orderMap = tx().getOrderMap(); + Set orderTypesToExport = orderMap.getTypes(tx()); + if (!this.orderTypes.isEmpty()) + orderTypesToExport.retainAll(this.orderTypes); + + for (String type : orderTypesToExport) { + nrOfOrdersToExport += orderMap.querySize(tx(), type); + } + logger.info("Exporting " + nrOfOrdersToExport + " Orders..."); + } + + logger.info("Exporting " + (nrOfResourcesToExport + nrOfOrdersToExport) + " Elements..."); + try (FileOutputStream out = new FileOutputStream(this.modelFile)) { createdFiles.add(this.modelFile); @@ -107,6 +135,8 @@ public class XmlExportModelCommand extends Command { writer.writeAttribute(Tags.FILE, typeXmlFile); File typeXmlFileF = new File(modelFile.getParentFile(), typeXmlFile); + 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); @@ -134,6 +164,8 @@ public class XmlExportModelCommand extends Command { writer.writeAttribute(Tags.FILE, typeXmlFile); File typeXmlFileF = new File(modelFile.getParentFile(), typeXmlFile); + 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); From 1f4755939af26ce41c1aeca37b70457fe410bd16 Mon Sep 17 00:00:00 2001 From: Robert von Burg Date: Mon, 17 Feb 2014 22:08:24 +0100 Subject: [PATCH 36/65] [New] Implemented separate DataStoreMode for each StrolchRealm --- .../transienttest/config/StrolchConfiguration.xml | 11 +++++++++-- .../withPrivilegeRuntime/config/PrivilegeModel.xml | 2 +- .../config/StrolchConfiguration.xml | 10 +++++++++- .../config/StrolchConfiguration.xml | 9 ++++++++- 4 files changed, 27 insertions(+), 5 deletions(-) diff --git a/src/test/resources/transienttest/config/StrolchConfiguration.xml b/src/test/resources/transienttest/config/StrolchConfiguration.xml index d799c11b8..5ed86883e 100644 --- a/src/test/resources/transienttest/config/StrolchConfiguration.xml +++ b/src/test/resources/transienttest/config/StrolchConfiguration.xml @@ -3,11 +3,18 @@ StrolchRuntimeTest - TRANSIENT - StrolchModel.xml true + + RealmHandler + li.strolch.agent.api.RealmHandler + li.strolch.agent.impl.DefaultRealmHandler + + TRANSIENT + StrolchModel.xml + + ServiceHandler li.strolch.service.api.ServiceHandler diff --git a/src/test/resources/withPrivilegeRuntime/config/PrivilegeModel.xml b/src/test/resources/withPrivilegeRuntime/config/PrivilegeModel.xml index 848bbe71d..c4e79dd20 100644 --- a/src/test/resources/withPrivilegeRuntime/config/PrivilegeModel.xml +++ b/src/test/resources/withPrivilegeRuntime/config/PrivilegeModel.xml @@ -66,7 +66,7 @@ - li.strolch.service.test.GreetingService + li.strolch.service.test.model.GreetingService diff --git a/src/test/resources/withPrivilegeRuntime/config/StrolchConfiguration.xml b/src/test/resources/withPrivilegeRuntime/config/StrolchConfiguration.xml index 27d4a47bc..03c9d0070 100644 --- a/src/test/resources/withPrivilegeRuntime/config/StrolchConfiguration.xml +++ b/src/test/resources/withPrivilegeRuntime/config/StrolchConfiguration.xml @@ -3,14 +3,22 @@ StrolchPersistenceTest - EMPTY true + + RealmHandler + li.strolch.agent.api.RealmHandler + li.strolch.agent.impl.DefaultRealmHandler + + EMPTY + + ServiceHandler li.strolch.service.api.ServiceHandler li.strolch.service.api.DefaultServiceHandler + PrivilegeHandler true diff --git a/src/test/resources/withoutPrivilegeRuntime/config/StrolchConfiguration.xml b/src/test/resources/withoutPrivilegeRuntime/config/StrolchConfiguration.xml index c250eb161..4ba1722ff 100644 --- a/src/test/resources/withoutPrivilegeRuntime/config/StrolchConfiguration.xml +++ b/src/test/resources/withoutPrivilegeRuntime/config/StrolchConfiguration.xml @@ -3,10 +3,17 @@ StrolchPersistenceTest - EMPTY true + + RealmHandler + li.strolch.agent.api.RealmHandler + li.strolch.agent.impl.DefaultRealmHandler + + EMPTY + + ServiceHandler li.strolch.service.api.ServiceHandler From 069361f476a93b9d6c188090f7628dd390ce8433 Mon Sep 17 00:00:00 2001 From: Robert von Burg Date: Mon, 24 Feb 2014 21:49:24 +0100 Subject: [PATCH 37/65] [New] Implemented locking for Strolch elements Also cleaned up hierarchy of StrolchTransaction by moving up everything into AbstractTransaction as made sense and added special delegation methods for the actual commit() and rollback() ind the concrete implementations. --- .../li/strolch/service/test/LockingTest.java | 183 ++++++++++++++++++ .../config/StrolchConfiguration.xml | 2 + 2 files changed, 185 insertions(+) create mode 100644 src/test/java/li/strolch/service/test/LockingTest.java diff --git a/src/test/java/li/strolch/service/test/LockingTest.java b/src/test/java/li/strolch/service/test/LockingTest.java new file mode 100644 index 000000000..bf32bbc1c --- /dev/null +++ b/src/test/java/li/strolch/service/test/LockingTest.java @@ -0,0 +1,183 @@ +/* + * 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; + +/** + * @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 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); + } + + @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(null, 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(null, svc, 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/src/test/resources/transienttest/config/StrolchConfiguration.xml b/src/test/resources/transienttest/config/StrolchConfiguration.xml index 5ed86883e..a4f856d75 100644 --- a/src/test/resources/transienttest/config/StrolchConfiguration.xml +++ b/src/test/resources/transienttest/config/StrolchConfiguration.xml @@ -11,6 +11,8 @@ li.strolch.agent.api.RealmHandler li.strolch.agent.impl.DefaultRealmHandler + SECONDS + 1 TRANSIENT StrolchModel.xml From c3a556df81e5a76b88e5dc95cd9b5d8fdd72ee4a Mon Sep 17 00:00:00 2001 From: Robert von Burg Date: Mon, 24 Feb 2014 21:57:57 +0100 Subject: [PATCH 38/65] [Minor] trying to fix broken LockingTest which has an infinite loop --- src/test/java/li/strolch/service/test/LockingTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/java/li/strolch/service/test/LockingTest.java b/src/test/java/li/strolch/service/test/LockingTest.java index bf32bbc1c..3d6e5c944 100644 --- a/src/test/java/li/strolch/service/test/LockingTest.java +++ b/src/test/java/li/strolch/service/test/LockingTest.java @@ -48,7 +48,7 @@ public class LockingTest { private static final String RESOURCE_LOCATOR = "Resource/TestType/MyTestResource"; protected static RuntimeMock runtimeMock; - private boolean run; + private volatile boolean run; @BeforeClass public static void beforeClass() { From 2446682c9a8a10dfd45ef1aa13570b09e6673de3 Mon Sep 17 00:00:00 2001 From: Robert von Burg Date: Mon, 24 Feb 2014 22:29:02 +0100 Subject: [PATCH 39/65] [New] Added SetParameterService and Command --- .../parameter/SetParameterCommand.java | 129 ++++++++++++++++++ .../parameter/SetParameterService.java | 74 ++++++++++ 2 files changed, 203 insertions(+) create mode 100644 src/main/java/li/strolch/command/parameter/SetParameterCommand.java create mode 100644 src/main/java/li/strolch/service/parameter/SetParameterService.java diff --git a/src/main/java/li/strolch/command/parameter/SetParameterCommand.java b/src/main/java/li/strolch/command/parameter/SetParameterCommand.java new file mode 100644 index 000000000..9fb8c1821 --- /dev/null +++ b/src/main/java/li/strolch/command/parameter/SetParameterCommand.java @@ -0,0 +1,129 @@ +/* + * 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.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; + + /** + * @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 doCommand() { + DBC.PRE.assertNotNull("Parameter may not be null!", parameter); + + if (this.name != null) { + this.parameter.setName(name); + } + if (this.interpretation != null) { + this.parameter.setInterpretation(interpretation); + } + if (this.uom != null) { + this.parameter.setUom(uom); + } + if (this.hidden != null) { + this.parameter.setHidden(this.hidden); + } + if (this.index != null) { + this.parameter.setIndex(this.index.intValue()); + } + + if (this.valueAsString != null) { + SetParameterValueVisitor visitor = new SetParameterValueVisitor(); + visitor.setValue(parameter, valueAsString); + } + } +} diff --git a/src/main/java/li/strolch/service/parameter/SetParameterService.java b/src/main/java/li/strolch/service/parameter/SetParameterService.java new file mode 100644 index 000000000..005778de3 --- /dev/null +++ b/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); + + command.doCommand(); + } + + 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; + } +} From 20f0417d938c420c12f4d9b0b3b6b228dbf0cd92 Mon Sep 17 00:00:00 2001 From: Robert von Burg Date: Tue, 25 Feb 2014 21:19:41 +0100 Subject: [PATCH 40/65] [New] Implemented Command.undo() for all commands --- .../command/AddOrderCollectionCommand.java | 16 +++++- .../li/strolch/command/AddOrderCommand.java | 9 ++++ .../command/AddResourceCollectionCommand.java | 12 +++++ .../strolch/command/AddResourceCommand.java | 9 ++++ .../command/RemoveOrderCollectionCommand.java | 12 +++++ .../strolch/command/RemoveOrderCommand.java | 9 ++++ .../RemoveResourceCollectionCommand.java | 12 +++++ .../command/RemoveResourceCommand.java | 9 ++++ .../command/UpdateOrderCollectionCommand.java | 11 ++++- .../strolch/command/UpdateOrderCommand.java | 10 +++- .../UpdateResourceCollectionCommand.java | 11 ++++- .../command/UpdateResourceCommand.java | 10 +++- .../command/XmlExportModelCommand.java | 5 ++ .../command/XmlImportModelCommand.java | 5 ++ .../parameter/AddParameterCommand.java | 18 +++++-- .../parameter/RemoveParameterCommand.java | 20 ++++++-- .../parameter/SetParameterCommand.java | 49 +++++++++++++++++-- 17 files changed, 206 insertions(+), 21 deletions(-) diff --git a/src/main/java/li/strolch/command/AddOrderCollectionCommand.java b/src/main/java/li/strolch/command/AddOrderCollectionCommand.java index 3e284a391..373250c1d 100644 --- a/src/main/java/li/strolch/command/AddOrderCollectionCommand.java +++ b/src/main/java/li/strolch/command/AddOrderCollectionCommand.java @@ -54,13 +54,25 @@ public class AddOrderCollectionCommand extends Command { DBC.PRE.assertNotNull("Order list may not be null!", this.orders); OrderMap orderMap = tx().getOrderMap(); - for (Order order : orders) { + 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(), orders); + 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/src/main/java/li/strolch/command/AddOrderCommand.java b/src/main/java/li/strolch/command/AddOrderCommand.java index 028c0e470..e2c8983b9 100644 --- a/src/main/java/li/strolch/command/AddOrderCommand.java +++ b/src/main/java/li/strolch/command/AddOrderCommand.java @@ -60,4 +60,13 @@ public class AddOrderCommand extends Command { 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/src/main/java/li/strolch/command/AddResourceCollectionCommand.java b/src/main/java/li/strolch/command/AddResourceCollectionCommand.java index 16fb3c6ce..eec9eb121 100644 --- a/src/main/java/li/strolch/command/AddResourceCollectionCommand.java +++ b/src/main/java/li/strolch/command/AddResourceCollectionCommand.java @@ -63,4 +63,16 @@ public class AddResourceCollectionCommand extends Command { resourceMap.addAll(tx(), 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/src/main/java/li/strolch/command/AddResourceCommand.java b/src/main/java/li/strolch/command/AddResourceCommand.java index 6543c6753..b14480bbb 100644 --- a/src/main/java/li/strolch/command/AddResourceCommand.java +++ b/src/main/java/li/strolch/command/AddResourceCommand.java @@ -60,4 +60,13 @@ public class AddResourceCommand extends Command { 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/src/main/java/li/strolch/command/RemoveOrderCollectionCommand.java b/src/main/java/li/strolch/command/RemoveOrderCollectionCommand.java index 6cb111893..bae598102 100644 --- a/src/main/java/li/strolch/command/RemoveOrderCollectionCommand.java +++ b/src/main/java/li/strolch/command/RemoveOrderCollectionCommand.java @@ -64,4 +64,16 @@ public class RemoveOrderCollectionCommand extends Command { orderMap.removeAll(tx(), 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/src/main/java/li/strolch/command/RemoveOrderCommand.java b/src/main/java/li/strolch/command/RemoveOrderCommand.java index 1c115d4d2..330601f0f 100644 --- a/src/main/java/li/strolch/command/RemoveOrderCommand.java +++ b/src/main/java/li/strolch/command/RemoveOrderCommand.java @@ -61,4 +61,13 @@ public class RemoveOrderCommand extends Command { 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/src/main/java/li/strolch/command/RemoveResourceCollectionCommand.java b/src/main/java/li/strolch/command/RemoveResourceCollectionCommand.java index 7d9b972c6..aa51585f7 100644 --- a/src/main/java/li/strolch/command/RemoveResourceCollectionCommand.java +++ b/src/main/java/li/strolch/command/RemoveResourceCollectionCommand.java @@ -64,4 +64,16 @@ public class RemoveResourceCollectionCommand extends Command { resourceMap.removeAll(tx(), 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/src/main/java/li/strolch/command/RemoveResourceCommand.java b/src/main/java/li/strolch/command/RemoveResourceCommand.java index d9fd28cbd..445e5dae2 100644 --- a/src/main/java/li/strolch/command/RemoveResourceCommand.java +++ b/src/main/java/li/strolch/command/RemoveResourceCommand.java @@ -61,4 +61,13 @@ public class RemoveResourceCommand extends Command { 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/src/main/java/li/strolch/command/UpdateOrderCollectionCommand.java b/src/main/java/li/strolch/command/UpdateOrderCollectionCommand.java index 72e59601d..807369068 100644 --- a/src/main/java/li/strolch/command/UpdateOrderCollectionCommand.java +++ b/src/main/java/li/strolch/command/UpdateOrderCollectionCommand.java @@ -32,6 +32,7 @@ import ch.eitchnet.utils.dbc.DBC; public class UpdateOrderCollectionCommand extends Command { private List orders; + private List replacedElements; /** * @param tx @@ -62,6 +63,14 @@ public class UpdateOrderCollectionCommand extends Command { } } - orderMap.updateAll(tx(), orders); + replacedElements = orderMap.updateAll(tx(), orders); + } + + @Override + public void undo() { + if (this.replacedElements != null && tx().isRollingBack()) { + OrderMap orderMap = tx().getOrderMap(); + orderMap.updateAll(tx(), replacedElements); + } } } diff --git a/src/main/java/li/strolch/command/UpdateOrderCommand.java b/src/main/java/li/strolch/command/UpdateOrderCommand.java index 69085a778..b02bb6c70 100644 --- a/src/main/java/li/strolch/command/UpdateOrderCommand.java +++ b/src/main/java/li/strolch/command/UpdateOrderCommand.java @@ -31,6 +31,7 @@ import ch.eitchnet.utils.dbc.DBC; public class UpdateOrderCommand extends Command { private Order order; + private Order replacedElement; /** * @param tx @@ -59,6 +60,13 @@ public class UpdateOrderCommand extends Command { throw new StrolchException(msg); } - orderMap.update(tx(), this.order); + this.replacedElement = orderMap.update(tx(), this.order); + } + + @Override + public void undo() { + if (this.replacedElement != null && tx().isRollingBack()) { + tx().getOrderMap().update(tx(), replacedElement); + } } } diff --git a/src/main/java/li/strolch/command/UpdateResourceCollectionCommand.java b/src/main/java/li/strolch/command/UpdateResourceCollectionCommand.java index 043253d24..0a70c2cf4 100644 --- a/src/main/java/li/strolch/command/UpdateResourceCollectionCommand.java +++ b/src/main/java/li/strolch/command/UpdateResourceCollectionCommand.java @@ -32,6 +32,7 @@ import ch.eitchnet.utils.dbc.DBC; public class UpdateResourceCollectionCommand extends Command { private List resources; + private List replacedElements; /** * @param tx @@ -62,6 +63,14 @@ public class UpdateResourceCollectionCommand extends Command { } } - resourceMap.updateAll(tx(), resources); + this.replacedElements = resourceMap.updateAll(tx(), resources); + } + + @Override + public void undo() { + if (this.replacedElements != null && tx().isRollingBack()) { + ResourceMap resourceMap = tx().getResourceMap(); + resourceMap.updateAll(tx(), replacedElements); + } } } diff --git a/src/main/java/li/strolch/command/UpdateResourceCommand.java b/src/main/java/li/strolch/command/UpdateResourceCommand.java index f6a479752..3b4b3dddd 100644 --- a/src/main/java/li/strolch/command/UpdateResourceCommand.java +++ b/src/main/java/li/strolch/command/UpdateResourceCommand.java @@ -31,6 +31,7 @@ import ch.eitchnet.utils.dbc.DBC; public class UpdateResourceCommand extends Command { private Resource resource; + private Resource replacedElement; /** * @param tx @@ -59,6 +60,13 @@ public class UpdateResourceCommand extends Command { throw new StrolchException(msg); } - resourceMap.update(tx(), this.resource); + this.replacedElement = resourceMap.update(tx(), this.resource); + } + + @Override + public void undo() { + if (this.replacedElement != null && tx().isRollingBack()) { + tx().getResourceMap().update(tx(), replacedElement); + } } } diff --git a/src/main/java/li/strolch/command/XmlExportModelCommand.java b/src/main/java/li/strolch/command/XmlExportModelCommand.java index d4a469975..5d2284883 100644 --- a/src/main/java/li/strolch/command/XmlExportModelCommand.java +++ b/src/main/java/li/strolch/command/XmlExportModelCommand.java @@ -74,6 +74,11 @@ public class XmlExportModelCommand extends Command { super(container, tx); } + @Override + public void undo() { + logger.warn("Not undoing export to file " + this.modelFile); + } + @Override public void doCommand() { DBC.PRE.assertNotExists("Model may not already exist!", this.modelFile); diff --git a/src/main/java/li/strolch/command/XmlImportModelCommand.java b/src/main/java/li/strolch/command/XmlImportModelCommand.java index a5d00eeae..5c03d71c4 100644 --- a/src/main/java/li/strolch/command/XmlImportModelCommand.java +++ b/src/main/java/li/strolch/command/XmlImportModelCommand.java @@ -51,6 +51,11 @@ public class XmlImportModelCommand extends Command { super(container, tx); } + @Override + public void undo() { + logger.warn("Not undoing import of file " + this.modelFile); + } + @Override public void doCommand() { DBC.PRE.assertExists("Model must exist!", this.modelFile); diff --git a/src/main/java/li/strolch/command/parameter/AddParameterCommand.java b/src/main/java/li/strolch/command/parameter/AddParameterCommand.java index 494afe7e5..274b8c9c7 100644 --- a/src/main/java/li/strolch/command/parameter/AddParameterCommand.java +++ b/src/main/java/li/strolch/command/parameter/AddParameterCommand.java @@ -59,16 +59,24 @@ public class AddParameterCommand extends Command { @Override public void doCommand() { - DBC.PRE.assertNotNull("Element may not be null!", element); - DBC.PRE.assertNotNull("Parameter may not be null!", parameter); + DBC.PRE.assertNotNull("Element may not be null!", this.element); + DBC.PRE.assertNotNull("Parameter may not be null!", this.parameter); - if (element.hasParameter(this.parameter.getId())) { + if (this.element.hasParameter(this.parameter.getId())) { String msg = "The Parameter {0} already exists on element {1}"; - msg = MessageFormat.format(msg, parameter.getId(), element.getLocator()); + msg = MessageFormat.format(msg, this.parameter.getId(), this.element.getLocator()); throw new StrolchPersistenceException(msg); } - this.element.addParameter(parameter); + this.element.addParameter(this.parameter); } + @Override + public void undo() { + if (this.parameter != null) { + if (this.element.hasParameter(this.parameter.getId())) { + this.element.removeParameter(this.parameter.getId()); + } + } + } } diff --git a/src/main/java/li/strolch/command/parameter/RemoveParameterCommand.java b/src/main/java/li/strolch/command/parameter/RemoveParameterCommand.java index 7b45ee04b..f8f6e76e3 100644 --- a/src/main/java/li/strolch/command/parameter/RemoveParameterCommand.java +++ b/src/main/java/li/strolch/command/parameter/RemoveParameterCommand.java @@ -19,6 +19,7 @@ import java.text.MessageFormat; import li.strolch.agent.api.ComponentContainer; import li.strolch.model.ParameterizedElement; +import li.strolch.model.parameter.Parameter; import li.strolch.persistence.api.StrolchPersistenceException; import li.strolch.persistence.api.StrolchTransaction; import li.strolch.service.api.Command; @@ -32,6 +33,8 @@ public class RemoveParameterCommand extends Command { private ParameterizedElement element; private String parameterId; + private Parameter removedParameter; + /** * @param container * @param tx @@ -58,15 +61,22 @@ public class RemoveParameterCommand extends Command { @Override public void doCommand() { - DBC.PRE.assertNotNull("Element may not be null!", element); - DBC.PRE.assertNotEmpty("ParameterId must be set!", parameterId); + DBC.PRE.assertNotNull("Element may not be null!", this.element); + DBC.PRE.assertNotEmpty("ParameterId must be set!", this.parameterId); - if (!element.hasParameter(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, parameterId, element.getLocator()); + msg = MessageFormat.format(msg, this.parameterId, this.element.getLocator()); throw new StrolchPersistenceException(msg); } - this.element.removeParameter(parameterId); + this.removedParameter = this.element.removeParameter(this.parameterId); + } + + @Override + public void undo() { + if (this.removedParameter != null) { + this.element.addParameter(this.removedParameter); + } } } diff --git a/src/main/java/li/strolch/command/parameter/SetParameterCommand.java b/src/main/java/li/strolch/command/parameter/SetParameterCommand.java index 9fb8c1821..234f9c02f 100644 --- a/src/main/java/li/strolch/command/parameter/SetParameterCommand.java +++ b/src/main/java/li/strolch/command/parameter/SetParameterCommand.java @@ -37,6 +37,13 @@ public class SetParameterCommand extends Command { private String valueAsString; + private String oldName; + private String oldInterpretation; + private String oldUom; + private Boolean oldHidden; + private Integer oldIndex; + private String oldValueAsString; + /** * @param container * @param tx @@ -103,27 +110,59 @@ public class SetParameterCommand extends Command { @Override public void doCommand() { - DBC.PRE.assertNotNull("Parameter may not be null!", parameter); + DBC.PRE.assertNotNull("Parameter may not be null!", this.parameter); if (this.name != null) { - this.parameter.setName(name); + this.oldName = this.parameter.getName(); + this.parameter.setName(this.name); } if (this.interpretation != null) { - this.parameter.setInterpretation(interpretation); + this.oldInterpretation = this.parameter.getInterpretation(); + this.parameter.setInterpretation(this.interpretation); } if (this.uom != null) { - this.parameter.setUom(uom); + 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(parameter, valueAsString); + visitor.setValue(this.parameter, this.valueAsString); + } + } + + @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); + } } } } From b1e24f8a5944c535742e5bd133ba55efed2bf1b7 Mon Sep 17 00:00:00 2001 From: Robert von Burg Date: Wed, 26 Feb 2014 21:13:47 +0100 Subject: [PATCH 41/65] [New] Implemented StrolchTransaction.addCommand(), Command.undo() Commands are now supposed to be added to the StrolchTransaction so that when a TX is committed, the commands are first verified and then Command.doCommand() is called. But most important of all, in case of an exception, Command.undo() is called so that each Command can properly undo its changes so that also in memory changes are rolled back. Now all Services call tx.addCommand(Command) instead of directly calling Command.doCommand() --- .../command/AddOrderCollectionCommand.java | 7 ++- .../li/strolch/command/AddOrderCommand.java | 7 ++- .../command/AddResourceCollectionCommand.java | 7 ++- .../strolch/command/AddResourceCommand.java | 7 ++- .../command/RemoveOrderCollectionCommand.java | 7 ++- .../strolch/command/RemoveOrderCommand.java | 7 ++- .../RemoveResourceCollectionCommand.java | 7 ++- .../command/RemoveResourceCommand.java | 7 ++- .../command/UpdateOrderCollectionCommand.java | 7 ++- .../strolch/command/UpdateOrderCommand.java | 7 ++- .../UpdateResourceCollectionCommand.java | 7 ++- .../command/UpdateResourceCommand.java | 7 ++- .../command/XmlExportModelCommand.java | 12 +++-- .../command/XmlImportModelCommand.java | 10 ++-- .../parameter/AddParameterCommand.java | 14 ++++- .../parameter/RemoveParameterCommand.java | 14 ++++- .../parameter/SetParameterCommand.java | 25 ++++++++- .../command/visitor/UpdateElementVisitor.java | 51 +++++++++++++++++++ .../service/AddOrderCollectionService.java | 2 +- .../li/strolch/service/AddOrderService.java | 2 +- .../service/AddResourceCollectionService.java | 2 +- .../strolch/service/AddResourceService.java | 2 +- .../service/RemoveOrderCollectionService.java | 8 +-- .../strolch/service/RemoveOrderService.java | 8 +-- .../RemoveResourceCollectionService.java | 8 +-- .../service/RemoveResourceService.java | 8 +-- .../service/UpdateOrderCollectionService.java | 8 +-- .../strolch/service/UpdateOrderService.java | 8 +-- .../UpdateResourceCollectionService.java | 8 +-- .../service/UpdateResourceService.java | 8 +-- .../service/XmlExportModelService.java | 8 +-- .../service/XmlImportModelService.java | 8 +-- .../parameter/AddParameterService.java | 2 +- .../parameter/RemoveParameterService.java | 2 +- .../parameter/SetParameterService.java | 2 +- 35 files changed, 223 insertions(+), 81 deletions(-) create mode 100644 src/main/java/li/strolch/command/visitor/UpdateElementVisitor.java diff --git a/src/main/java/li/strolch/command/AddOrderCollectionCommand.java b/src/main/java/li/strolch/command/AddOrderCollectionCommand.java index 373250c1d..0106df9e7 100644 --- a/src/main/java/li/strolch/command/AddOrderCollectionCommand.java +++ b/src/main/java/li/strolch/command/AddOrderCollectionCommand.java @@ -49,9 +49,12 @@ public class AddOrderCollectionCommand extends Command { } @Override - public void doCommand() { - + public void validate() { DBC.PRE.assertNotNull("Order list may not be null!", this.orders); + } + + @Override + public void doCommand() { OrderMap orderMap = tx().getOrderMap(); for (Order order : this.orders) { diff --git a/src/main/java/li/strolch/command/AddOrderCommand.java b/src/main/java/li/strolch/command/AddOrderCommand.java index e2c8983b9..a2b2d972d 100644 --- a/src/main/java/li/strolch/command/AddOrderCommand.java +++ b/src/main/java/li/strolch/command/AddOrderCommand.java @@ -48,9 +48,12 @@ public class AddOrderCommand extends Command { } @Override - public void doCommand() { - + public void validate() { DBC.PRE.assertNotNull("Order may not be null!", this.order); + } + + @Override + public void doCommand() { OrderMap orderMap = tx().getOrderMap(); if (orderMap.hasElement(tx(), this.order.getType(), this.order.getId())) { diff --git a/src/main/java/li/strolch/command/AddResourceCollectionCommand.java b/src/main/java/li/strolch/command/AddResourceCollectionCommand.java index eec9eb121..1b709bb1a 100644 --- a/src/main/java/li/strolch/command/AddResourceCollectionCommand.java +++ b/src/main/java/li/strolch/command/AddResourceCollectionCommand.java @@ -49,9 +49,12 @@ public class AddResourceCollectionCommand extends Command { } @Override - public void doCommand() { - + public void validate() { DBC.PRE.assertNotNull("Resource list may not be null!", this.resources); + } + + @Override + public void doCommand() { ResourceMap resourceMap = tx().getResourceMap(); for (Resource resource : resources) { diff --git a/src/main/java/li/strolch/command/AddResourceCommand.java b/src/main/java/li/strolch/command/AddResourceCommand.java index b14480bbb..e7e78ea31 100644 --- a/src/main/java/li/strolch/command/AddResourceCommand.java +++ b/src/main/java/li/strolch/command/AddResourceCommand.java @@ -48,9 +48,12 @@ public class AddResourceCommand extends Command { } @Override - public void doCommand() { - + public void validate() { DBC.PRE.assertNotNull("Resource may not be null!", this.resource); + } + + @Override + public void doCommand() { ResourceMap resourceMap = tx().getResourceMap(); if (resourceMap.hasElement(tx(), this.resource.getType(), this.resource.getId())) { diff --git a/src/main/java/li/strolch/command/RemoveOrderCollectionCommand.java b/src/main/java/li/strolch/command/RemoveOrderCollectionCommand.java index bae598102..7ff557e06 100644 --- a/src/main/java/li/strolch/command/RemoveOrderCollectionCommand.java +++ b/src/main/java/li/strolch/command/RemoveOrderCollectionCommand.java @@ -49,9 +49,12 @@ public class RemoveOrderCollectionCommand extends Command { } @Override - public void doCommand() { - + public void validate() { DBC.PRE.assertNotNull("Order list may not be null!", this.orders); + } + + @Override + public void doCommand() { OrderMap orderMap = tx().getOrderMap(); for (Order order : orders) { diff --git a/src/main/java/li/strolch/command/RemoveOrderCommand.java b/src/main/java/li/strolch/command/RemoveOrderCommand.java index 330601f0f..02d5bcf5a 100644 --- a/src/main/java/li/strolch/command/RemoveOrderCommand.java +++ b/src/main/java/li/strolch/command/RemoveOrderCommand.java @@ -48,9 +48,12 @@ public class RemoveOrderCommand extends Command { } @Override - public void doCommand() { - + public void validate() { DBC.PRE.assertNotNull("Order may not be null!", this.order); + } + + @Override + public void doCommand() { OrderMap orderMap = tx().getOrderMap(); if (!orderMap.hasElement(tx(), this.order.getType(), this.order.getId())) { diff --git a/src/main/java/li/strolch/command/RemoveResourceCollectionCommand.java b/src/main/java/li/strolch/command/RemoveResourceCollectionCommand.java index aa51585f7..6be5f7d1f 100644 --- a/src/main/java/li/strolch/command/RemoveResourceCollectionCommand.java +++ b/src/main/java/li/strolch/command/RemoveResourceCollectionCommand.java @@ -49,9 +49,12 @@ public class RemoveResourceCollectionCommand extends Command { } @Override - public void doCommand() { - + public void validate() { DBC.PRE.assertNotNull("Resource list may not be null!", this.resources); + } + + @Override + public void doCommand() { ResourceMap resourceMap = tx().getResourceMap(); for (Resource resource : resources) { diff --git a/src/main/java/li/strolch/command/RemoveResourceCommand.java b/src/main/java/li/strolch/command/RemoveResourceCommand.java index 445e5dae2..b20972d76 100644 --- a/src/main/java/li/strolch/command/RemoveResourceCommand.java +++ b/src/main/java/li/strolch/command/RemoveResourceCommand.java @@ -48,9 +48,12 @@ public class RemoveResourceCommand extends Command { } @Override - public void doCommand() { - + public void validate() { DBC.PRE.assertNotNull("Resource may not be null!", this.resource); + } + + @Override + public void doCommand() { ResourceMap resourceMap = tx().getResourceMap(); if (!resourceMap.hasElement(tx(), this.resource.getType(), this.resource.getId())) { diff --git a/src/main/java/li/strolch/command/UpdateOrderCollectionCommand.java b/src/main/java/li/strolch/command/UpdateOrderCollectionCommand.java index 807369068..0021a63b2 100644 --- a/src/main/java/li/strolch/command/UpdateOrderCollectionCommand.java +++ b/src/main/java/li/strolch/command/UpdateOrderCollectionCommand.java @@ -50,9 +50,12 @@ public class UpdateOrderCollectionCommand extends Command { } @Override - public void doCommand() { - + public void validate() { DBC.PRE.assertNotNull("Order list may not be null!", this.orders); + } + + @Override + public void doCommand() { OrderMap orderMap = tx().getOrderMap(); for (Order order : orders) { diff --git a/src/main/java/li/strolch/command/UpdateOrderCommand.java b/src/main/java/li/strolch/command/UpdateOrderCommand.java index b02bb6c70..a7ad7cde3 100644 --- a/src/main/java/li/strolch/command/UpdateOrderCommand.java +++ b/src/main/java/li/strolch/command/UpdateOrderCommand.java @@ -49,9 +49,12 @@ public class UpdateOrderCommand extends Command { } @Override - public void doCommand() { - + public void validate() { DBC.PRE.assertNotNull("Order may not be null!", this.order); + } + + @Override + public void doCommand() { OrderMap orderMap = tx().getOrderMap(); if (!orderMap.hasElement(tx(), this.order.getType(), this.order.getId())) { diff --git a/src/main/java/li/strolch/command/UpdateResourceCollectionCommand.java b/src/main/java/li/strolch/command/UpdateResourceCollectionCommand.java index 0a70c2cf4..e34f30673 100644 --- a/src/main/java/li/strolch/command/UpdateResourceCollectionCommand.java +++ b/src/main/java/li/strolch/command/UpdateResourceCollectionCommand.java @@ -50,9 +50,12 @@ public class UpdateResourceCollectionCommand extends Command { } @Override - public void doCommand() { - + public void validate() { DBC.PRE.assertNotNull("Resource list may not be null!", this.resources); + } + + @Override + public void doCommand() { ResourceMap resourceMap = tx().getResourceMap(); for (Resource resource : resources) { diff --git a/src/main/java/li/strolch/command/UpdateResourceCommand.java b/src/main/java/li/strolch/command/UpdateResourceCommand.java index 3b4b3dddd..7c1931549 100644 --- a/src/main/java/li/strolch/command/UpdateResourceCommand.java +++ b/src/main/java/li/strolch/command/UpdateResourceCommand.java @@ -49,9 +49,12 @@ public class UpdateResourceCommand extends Command { } @Override - public void doCommand() { - + public void validate() { DBC.PRE.assertNotNull("Resource may not be null!", this.resource); + } + + @Override + public void doCommand() { ResourceMap resourceMap = tx().getResourceMap(); if (!resourceMap.hasElement(tx(), this.resource.getType(), this.resource.getId())) { diff --git a/src/main/java/li/strolch/command/XmlExportModelCommand.java b/src/main/java/li/strolch/command/XmlExportModelCommand.java index 5d2284883..6dee62320 100644 --- a/src/main/java/li/strolch/command/XmlExportModelCommand.java +++ b/src/main/java/li/strolch/command/XmlExportModelCommand.java @@ -75,15 +75,14 @@ public class XmlExportModelCommand extends Command { } @Override - public void undo() { - logger.warn("Not undoing export to file " + this.modelFile); + public void validate() { + 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)); } @Override public void doCommand() { - DBC.PRE.assertNotExists("Model may not already exist!", this.modelFile); String fileName = this.modelFile.getName(); - DBC.PRE.assertTrue("Model file must end with .xml", fileName.endsWith(XML_FILE_SUFFIX)); long start = System.nanoTime(); this.statistics = new XmlModelStatistics(); @@ -201,6 +200,11 @@ public class XmlExportModelCommand extends Command { } } + @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)); diff --git a/src/main/java/li/strolch/command/XmlImportModelCommand.java b/src/main/java/li/strolch/command/XmlImportModelCommand.java index 5c03d71c4..b89798b75 100644 --- a/src/main/java/li/strolch/command/XmlImportModelCommand.java +++ b/src/main/java/li/strolch/command/XmlImportModelCommand.java @@ -52,13 +52,12 @@ public class XmlImportModelCommand extends Command { } @Override - public void undo() { - logger.warn("Not undoing import of file " + this.modelFile); + public void validate() { + DBC.PRE.assertExists("Model must exist!", this.modelFile); } @Override public void doCommand() { - DBC.PRE.assertExists("Model must exist!", this.modelFile); InMemoryElementListener elementListener = new InMemoryElementListener(tx()); @@ -75,6 +74,11 @@ public class XmlImportModelCommand extends Command { statistics = handler.getStatistics(); } + @Override + public void undo() { + logger.warn("Not undoing import of file " + this.modelFile); + } + /** * @param modelFileName */ diff --git a/src/main/java/li/strolch/command/parameter/AddParameterCommand.java b/src/main/java/li/strolch/command/parameter/AddParameterCommand.java index 274b8c9c7..675afcea7 100644 --- a/src/main/java/li/strolch/command/parameter/AddParameterCommand.java +++ b/src/main/java/li/strolch/command/parameter/AddParameterCommand.java @@ -18,7 +18,9 @@ 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; @@ -32,6 +34,7 @@ public class AddParameterCommand extends Command { private ParameterizedElement element; private Parameter parameter; + private StrolchRootElement replacedElement; /** * @param container @@ -58,7 +61,7 @@ public class AddParameterCommand extends Command { } @Override - public void doCommand() { + public void validate() { DBC.PRE.assertNotNull("Element may not be null!", this.element); DBC.PRE.assertNotNull("Parameter may not be null!", this.parameter); @@ -67,8 +70,13 @@ public class AddParameterCommand extends Command { msg = MessageFormat.format(msg, this.parameter.getId(), this.element.getLocator()); throw new StrolchPersistenceException(msg); } + } + @Override + public void doCommand() { this.element.addParameter(this.parameter); + StrolchRootElement rootElement = this.element.getRootElement(); + replacedElement = new UpdateElementVisitor(tx()).update(rootElement); } @Override @@ -78,5 +86,9 @@ public class AddParameterCommand extends Command { this.element.removeParameter(this.parameter.getId()); } } + + if (this.replacedElement != null && this.element != this.replacedElement) { + new UpdateElementVisitor(tx()).update(this.replacedElement); + } } } diff --git a/src/main/java/li/strolch/command/parameter/RemoveParameterCommand.java b/src/main/java/li/strolch/command/parameter/RemoveParameterCommand.java index f8f6e76e3..e5c9ec04c 100644 --- a/src/main/java/li/strolch/command/parameter/RemoveParameterCommand.java +++ b/src/main/java/li/strolch/command/parameter/RemoveParameterCommand.java @@ -18,7 +18,9 @@ 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; @@ -34,6 +36,7 @@ public class RemoveParameterCommand extends Command { private String parameterId; private Parameter removedParameter; + private StrolchRootElement replacedElement; /** * @param container @@ -60,7 +63,7 @@ public class RemoveParameterCommand extends Command { } @Override - public void doCommand() { + public void validate() { DBC.PRE.assertNotNull("Element may not be null!", this.element); DBC.PRE.assertNotEmpty("ParameterId must be set!", this.parameterId); @@ -69,8 +72,13 @@ public class RemoveParameterCommand extends Command { msg = MessageFormat.format(msg, this.parameterId, this.element.getLocator()); throw new StrolchPersistenceException(msg); } + } + @Override + public void doCommand() { this.removedParameter = this.element.removeParameter(this.parameterId); + StrolchRootElement rootElement = this.element.getRootElement(); + replacedElement = new UpdateElementVisitor(tx()).update(rootElement); } @Override @@ -78,5 +86,9 @@ public class RemoveParameterCommand extends Command { 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/src/main/java/li/strolch/command/parameter/SetParameterCommand.java b/src/main/java/li/strolch/command/parameter/SetParameterCommand.java index 234f9c02f..3740ad4c4 100644 --- a/src/main/java/li/strolch/command/parameter/SetParameterCommand.java +++ b/src/main/java/li/strolch/command/parameter/SetParameterCommand.java @@ -16,6 +16,8 @@ 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; @@ -44,6 +46,8 @@ public class SetParameterCommand extends Command { private Integer oldIndex; private String oldValueAsString; + private StrolchRootElement replacedElement; + /** * @param container * @param tx @@ -109,8 +113,12 @@ public class SetParameterCommand extends Command { } @Override - public void doCommand() { + public void validate() { DBC.PRE.assertNotNull("Parameter may not be null!", this.parameter); + } + + @Override + public void doCommand() { if (this.name != null) { this.oldName = this.parameter.getName(); @@ -138,10 +146,21 @@ public class SetParameterCommand extends Command { SetParameterValueVisitor visitor = new SetParameterValueVisitor(); visitor.setValue(this.parameter, this.valueAsString); } + + if (hasChanges()) { + StrolchRootElement rootElement = this.parameter.getRootElement(); + 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); @@ -163,6 +182,10 @@ public class SetParameterCommand extends Command { SetParameterValueVisitor visitor = new SetParameterValueVisitor(); visitor.setValue(this.parameter, this.oldValueAsString); } + + if (hasChanges() && this.replacedElement != null && this.replacedElement != this.parameter.getRootElement()) { + new UpdateElementVisitor(tx()).update(replacedElement); + } } } } diff --git a/src/main/java/li/strolch/command/visitor/UpdateElementVisitor.java b/src/main/java/li/strolch/command/visitor/UpdateElementVisitor.java new file mode 100644 index 000000000..3fb059b84 --- /dev/null +++ b/src/main/java/li/strolch/command/visitor/UpdateElementVisitor.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.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); + } + + @SuppressWarnings("unchecked") + @Override + public T visitOrder(Order order) { + return (T) tx.getOrderMap().update(tx, order); + } + + @SuppressWarnings("unchecked") + @Override + public T visitResource(Resource resource) { + return (T) tx.getResourceMap().update(tx, resource); + } +} diff --git a/src/main/java/li/strolch/service/AddOrderCollectionService.java b/src/main/java/li/strolch/service/AddOrderCollectionService.java index 5da01c5a9..77affbd3e 100644 --- a/src/main/java/li/strolch/service/AddOrderCollectionService.java +++ b/src/main/java/li/strolch/service/AddOrderCollectionService.java @@ -43,7 +43,7 @@ public class AddOrderCollectionService extends try (StrolchTransaction tx = openTx(arg.realm)) { AddOrderCollectionCommand command = new AddOrderCollectionCommand(getContainer(), tx); command.setOrders(arg.orders); - command.doCommand(); + tx.addCommand(command); } return ServiceResult.success(); diff --git a/src/main/java/li/strolch/service/AddOrderService.java b/src/main/java/li/strolch/service/AddOrderService.java index 483310f9a..01d82e678 100644 --- a/src/main/java/li/strolch/service/AddOrderService.java +++ b/src/main/java/li/strolch/service/AddOrderService.java @@ -40,7 +40,7 @@ public class AddOrderService extends AbstractService */ public class RemoveOrderCollectionService extends - AbstractService { + AbstractService { private static final long serialVersionUID = 1L; @@ -38,18 +38,18 @@ public class RemoveOrderCollectionService extends } @Override - protected ServiceResult internalDoService(AddOrderCollectionArg arg) { + protected ServiceResult internalDoService(RemoveOrderCollectionArg arg) { try (StrolchTransaction tx = openTx(arg.realm)) { RemoveOrderCollectionCommand command = new RemoveOrderCollectionCommand(getContainer(), tx); command.setOrders(arg.orders); - command.doCommand(); + tx.addCommand(command); } return ServiceResult.success(); } - public static class AddOrderCollectionArg extends ServiceArgument { + public static class RemoveOrderCollectionArg extends ServiceArgument { private static final long serialVersionUID = 1L; public List orders; } diff --git a/src/main/java/li/strolch/service/RemoveOrderService.java b/src/main/java/li/strolch/service/RemoveOrderService.java index e7e7e7b33..472511bd6 100644 --- a/src/main/java/li/strolch/service/RemoveOrderService.java +++ b/src/main/java/li/strolch/service/RemoveOrderService.java @@ -25,7 +25,7 @@ import li.strolch.service.api.ServiceResult; /** * @author Robert von Burg */ -public class RemoveOrderService extends AbstractService { +public class RemoveOrderService extends AbstractService { private static final long serialVersionUID = 1L; @@ -35,18 +35,18 @@ public class RemoveOrderService extends AbstractService */ public class RemoveResourceCollectionService extends - AbstractService { + AbstractService { private static final long serialVersionUID = 1L; @@ -38,18 +38,18 @@ public class RemoveResourceCollectionService extends } @Override - protected ServiceResult internalDoService(AddResourceCollectionArg arg) { + protected ServiceResult internalDoService(RemoveResourceCollectionArg arg) { try (StrolchTransaction tx = openTx(arg.realm)) { RemoveResourceCollectionCommand command = new RemoveResourceCollectionCommand(getContainer(), tx); command.setResources(arg.resources); - command.doCommand(); + tx.addCommand(command); } return ServiceResult.success(); } - public static class AddResourceCollectionArg extends ServiceArgument { + public static class RemoveResourceCollectionArg extends ServiceArgument { private static final long serialVersionUID = 1L; public List resources; } diff --git a/src/main/java/li/strolch/service/RemoveResourceService.java b/src/main/java/li/strolch/service/RemoveResourceService.java index 4e9585731..66434e52c 100644 --- a/src/main/java/li/strolch/service/RemoveResourceService.java +++ b/src/main/java/li/strolch/service/RemoveResourceService.java @@ -25,7 +25,7 @@ import li.strolch.service.api.ServiceResult; /** * @author Robert von Burg */ -public class RemoveResourceService extends AbstractService { +public class RemoveResourceService extends AbstractService { private static final long serialVersionUID = 1L; @@ -35,18 +35,18 @@ public class RemoveResourceService extends AbstractService */ public class UpdateOrderCollectionService extends - AbstractService { + AbstractService { private static final long serialVersionUID = 1L; @@ -38,18 +38,18 @@ public class UpdateOrderCollectionService extends } @Override - protected ServiceResult internalDoService(AddOrderCollectionArg arg) { + protected ServiceResult internalDoService(UpdateOrderCollectionArg arg) { try (StrolchTransaction tx = openTx(arg.realm)) { UpdateOrderCollectionCommand command = new UpdateOrderCollectionCommand(getContainer(), tx); command.setOrders(arg.orders); - command.doCommand(); + tx.addCommand(command); } return ServiceResult.success(); } - public static class AddOrderCollectionArg extends ServiceArgument { + public static class UpdateOrderCollectionArg extends ServiceArgument { private static final long serialVersionUID = 1L; public List orders; } diff --git a/src/main/java/li/strolch/service/UpdateOrderService.java b/src/main/java/li/strolch/service/UpdateOrderService.java index 47db84604..3d6aa8052 100644 --- a/src/main/java/li/strolch/service/UpdateOrderService.java +++ b/src/main/java/li/strolch/service/UpdateOrderService.java @@ -25,7 +25,7 @@ import li.strolch.service.api.ServiceResult; /** * @author Robert von Burg */ -public class UpdateOrderService extends AbstractService { +public class UpdateOrderService extends AbstractService { private static final long serialVersionUID = 1L; @@ -35,18 +35,18 @@ public class UpdateOrderService extends AbstractService */ public class UpdateResourceCollectionService extends - AbstractService { + AbstractService { private static final long serialVersionUID = 1L; @@ -38,18 +38,18 @@ public class UpdateResourceCollectionService extends } @Override - protected ServiceResult internalDoService(AddResourceCollectionArg arg) { + protected ServiceResult internalDoService(UpdateResourceCollectionArg arg) { try (StrolchTransaction tx = openTx(arg.realm)) { UpdateResourceCollectionCommand command = new UpdateResourceCollectionCommand(getContainer(), tx); command.setResources(arg.resources); - command.doCommand(); + tx.addCommand(command); } return ServiceResult.success(); } - public static class AddResourceCollectionArg extends ServiceArgument { + public static class UpdateResourceCollectionArg extends ServiceArgument { private static final long serialVersionUID = 1L; public List resources; } diff --git a/src/main/java/li/strolch/service/UpdateResourceService.java b/src/main/java/li/strolch/service/UpdateResourceService.java index 56e13c1f9..bcbd210e1 100644 --- a/src/main/java/li/strolch/service/UpdateResourceService.java +++ b/src/main/java/li/strolch/service/UpdateResourceService.java @@ -25,7 +25,7 @@ import li.strolch.service.api.ServiceResult; /** * @author Robert von Burg */ -public class UpdateResourceService extends AbstractService { +public class UpdateResourceService extends AbstractService { private static final long serialVersionUID = 1L; @@ -35,18 +35,18 @@ public class UpdateResourceService extends AbstractService Date: Wed, 26 Feb 2014 21:32:12 +0100 Subject: [PATCH 42/65] [Minor] all commands now lock their elements before doing their work --- .../java/li/strolch/command/AddOrderCollectionCommand.java | 4 ++++ src/main/java/li/strolch/command/AddOrderCommand.java | 2 ++ .../li/strolch/command/AddResourceCollectionCommand.java | 4 ++++ src/main/java/li/strolch/command/AddResourceCommand.java | 2 ++ .../li/strolch/command/RemoveOrderCollectionCommand.java | 4 ++++ src/main/java/li/strolch/command/RemoveOrderCommand.java | 2 ++ .../li/strolch/command/RemoveResourceCollectionCommand.java | 4 ++++ src/main/java/li/strolch/command/RemoveResourceCommand.java | 2 ++ .../li/strolch/command/UpdateOrderCollectionCommand.java | 4 ++++ src/main/java/li/strolch/command/UpdateOrderCommand.java | 2 ++ .../li/strolch/command/UpdateResourceCollectionCommand.java | 4 ++++ src/main/java/li/strolch/command/UpdateResourceCommand.java | 2 ++ .../li/strolch/command/parameter/AddParameterCommand.java | 5 ++++- .../li/strolch/command/parameter/RemoveParameterCommand.java | 5 ++++- .../li/strolch/command/parameter/SetParameterCommand.java | 4 +++- 15 files changed, 47 insertions(+), 3 deletions(-) diff --git a/src/main/java/li/strolch/command/AddOrderCollectionCommand.java b/src/main/java/li/strolch/command/AddOrderCollectionCommand.java index 0106df9e7..b8cda78ed 100644 --- a/src/main/java/li/strolch/command/AddOrderCollectionCommand.java +++ b/src/main/java/li/strolch/command/AddOrderCollectionCommand.java @@ -56,6 +56,10 @@ public class AddOrderCollectionCommand extends Command { @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())) { diff --git a/src/main/java/li/strolch/command/AddOrderCommand.java b/src/main/java/li/strolch/command/AddOrderCommand.java index a2b2d972d..4a740f9c2 100644 --- a/src/main/java/li/strolch/command/AddOrderCommand.java +++ b/src/main/java/li/strolch/command/AddOrderCommand.java @@ -55,6 +55,8 @@ public class AddOrderCommand extends Command { @Override public void doCommand() { + tx().lock(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()); diff --git a/src/main/java/li/strolch/command/AddResourceCollectionCommand.java b/src/main/java/li/strolch/command/AddResourceCollectionCommand.java index 1b709bb1a..5c4474f49 100644 --- a/src/main/java/li/strolch/command/AddResourceCollectionCommand.java +++ b/src/main/java/li/strolch/command/AddResourceCollectionCommand.java @@ -56,6 +56,10 @@ public class AddResourceCollectionCommand extends Command { @Override public void doCommand() { + for (Resource resource : this.resources) { + tx().lock(resource); + } + ResourceMap resourceMap = tx().getResourceMap(); for (Resource resource : resources) { if (resourceMap.hasElement(tx(), resource.getType(), resource.getId())) { diff --git a/src/main/java/li/strolch/command/AddResourceCommand.java b/src/main/java/li/strolch/command/AddResourceCommand.java index e7e78ea31..a3fb5c032 100644 --- a/src/main/java/li/strolch/command/AddResourceCommand.java +++ b/src/main/java/li/strolch/command/AddResourceCommand.java @@ -55,6 +55,8 @@ public class AddResourceCommand extends Command { @Override public void doCommand() { + tx().lock(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()); diff --git a/src/main/java/li/strolch/command/RemoveOrderCollectionCommand.java b/src/main/java/li/strolch/command/RemoveOrderCollectionCommand.java index 7ff557e06..fd0e84c7f 100644 --- a/src/main/java/li/strolch/command/RemoveOrderCollectionCommand.java +++ b/src/main/java/li/strolch/command/RemoveOrderCollectionCommand.java @@ -56,6 +56,10 @@ public class RemoveOrderCollectionCommand extends Command { @Override public void doCommand() { + for (Order order : this.orders) { + tx().lock(order); + } + OrderMap orderMap = tx().getOrderMap(); for (Order order : orders) { if (!orderMap.hasElement(tx(), order.getType(), order.getId())) { diff --git a/src/main/java/li/strolch/command/RemoveOrderCommand.java b/src/main/java/li/strolch/command/RemoveOrderCommand.java index 02d5bcf5a..63d434927 100644 --- a/src/main/java/li/strolch/command/RemoveOrderCommand.java +++ b/src/main/java/li/strolch/command/RemoveOrderCommand.java @@ -55,6 +55,8 @@ public class RemoveOrderCommand extends Command { @Override public void doCommand() { + tx().lock(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!"; diff --git a/src/main/java/li/strolch/command/RemoveResourceCollectionCommand.java b/src/main/java/li/strolch/command/RemoveResourceCollectionCommand.java index 6be5f7d1f..4f21762a7 100644 --- a/src/main/java/li/strolch/command/RemoveResourceCollectionCommand.java +++ b/src/main/java/li/strolch/command/RemoveResourceCollectionCommand.java @@ -56,6 +56,10 @@ public class RemoveResourceCollectionCommand extends Command { @Override public void doCommand() { + for (Resource resource : this.resources) { + tx().lock(resource); + } + ResourceMap resourceMap = tx().getResourceMap(); for (Resource resource : resources) { if (!resourceMap.hasElement(tx(), resource.getType(), resource.getId())) { diff --git a/src/main/java/li/strolch/command/RemoveResourceCommand.java b/src/main/java/li/strolch/command/RemoveResourceCommand.java index b20972d76..796e49acc 100644 --- a/src/main/java/li/strolch/command/RemoveResourceCommand.java +++ b/src/main/java/li/strolch/command/RemoveResourceCommand.java @@ -55,6 +55,8 @@ public class RemoveResourceCommand extends Command { @Override public void doCommand() { + tx().lock(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!!"; diff --git a/src/main/java/li/strolch/command/UpdateOrderCollectionCommand.java b/src/main/java/li/strolch/command/UpdateOrderCollectionCommand.java index 0021a63b2..35035950a 100644 --- a/src/main/java/li/strolch/command/UpdateOrderCollectionCommand.java +++ b/src/main/java/li/strolch/command/UpdateOrderCollectionCommand.java @@ -57,6 +57,10 @@ public class UpdateOrderCollectionCommand extends Command { @Override public void doCommand() { + for (Order order : this.orders) { + tx().lock(order); + } + OrderMap orderMap = tx().getOrderMap(); for (Order order : orders) { if (!orderMap.hasElement(tx(), order.getType(), order.getId())) { diff --git a/src/main/java/li/strolch/command/UpdateOrderCommand.java b/src/main/java/li/strolch/command/UpdateOrderCommand.java index a7ad7cde3..2eb297d62 100644 --- a/src/main/java/li/strolch/command/UpdateOrderCommand.java +++ b/src/main/java/li/strolch/command/UpdateOrderCommand.java @@ -56,6 +56,8 @@ public class UpdateOrderCommand extends Command { @Override public void doCommand() { + tx().lock(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!"; diff --git a/src/main/java/li/strolch/command/UpdateResourceCollectionCommand.java b/src/main/java/li/strolch/command/UpdateResourceCollectionCommand.java index e34f30673..2b6b65d67 100644 --- a/src/main/java/li/strolch/command/UpdateResourceCollectionCommand.java +++ b/src/main/java/li/strolch/command/UpdateResourceCollectionCommand.java @@ -57,6 +57,10 @@ public class UpdateResourceCollectionCommand extends Command { @Override public void doCommand() { + for (Resource resource : this.resources) { + tx().lock(resource); + } + ResourceMap resourceMap = tx().getResourceMap(); for (Resource resource : resources) { if (!resourceMap.hasElement(tx(), resource.getType(), resource.getId())) { diff --git a/src/main/java/li/strolch/command/UpdateResourceCommand.java b/src/main/java/li/strolch/command/UpdateResourceCommand.java index 7c1931549..e3d2c830f 100644 --- a/src/main/java/li/strolch/command/UpdateResourceCommand.java +++ b/src/main/java/li/strolch/command/UpdateResourceCommand.java @@ -56,6 +56,8 @@ public class UpdateResourceCommand extends Command { @Override public void doCommand() { + tx().lock(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!!"; diff --git a/src/main/java/li/strolch/command/parameter/AddParameterCommand.java b/src/main/java/li/strolch/command/parameter/AddParameterCommand.java index 675afcea7..f666bc33b 100644 --- a/src/main/java/li/strolch/command/parameter/AddParameterCommand.java +++ b/src/main/java/li/strolch/command/parameter/AddParameterCommand.java @@ -74,8 +74,11 @@ public class AddParameterCommand extends Command { @Override public void doCommand() { + + StrolchRootElement rootElement = this.parameter.getRootElement(); + tx().lock(rootElement); + this.element.addParameter(this.parameter); - StrolchRootElement rootElement = this.element.getRootElement(); replacedElement = new UpdateElementVisitor(tx()).update(rootElement); } diff --git a/src/main/java/li/strolch/command/parameter/RemoveParameterCommand.java b/src/main/java/li/strolch/command/parameter/RemoveParameterCommand.java index e5c9ec04c..1b20520df 100644 --- a/src/main/java/li/strolch/command/parameter/RemoveParameterCommand.java +++ b/src/main/java/li/strolch/command/parameter/RemoveParameterCommand.java @@ -76,8 +76,11 @@ public class RemoveParameterCommand extends Command { @Override public void doCommand() { - this.removedParameter = this.element.removeParameter(this.parameterId); + StrolchRootElement rootElement = this.element.getRootElement(); + tx().lock(rootElement); + + this.removedParameter = this.element.removeParameter(this.parameterId); replacedElement = new UpdateElementVisitor(tx()).update(rootElement); } diff --git a/src/main/java/li/strolch/command/parameter/SetParameterCommand.java b/src/main/java/li/strolch/command/parameter/SetParameterCommand.java index 3740ad4c4..a6f576882 100644 --- a/src/main/java/li/strolch/command/parameter/SetParameterCommand.java +++ b/src/main/java/li/strolch/command/parameter/SetParameterCommand.java @@ -120,6 +120,9 @@ public class SetParameterCommand extends Command { @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); @@ -148,7 +151,6 @@ public class SetParameterCommand extends Command { } if (hasChanges()) { - StrolchRootElement rootElement = this.parameter.getRootElement(); replacedElement = new UpdateElementVisitor(tx()).update(rootElement); } } From 411b7e00dffcb5a5bb341466925d6b52fb8c5caf Mon Sep 17 00:00:00 2001 From: Robert von Burg Date: Mon, 3 Mar 2014 23:35:17 +0100 Subject: [PATCH 43/65] [Major] Implemented tests for all Services These tests are simple success tests, failure tests come later. Each tests makes tests that the service works in CACHED, TRANSACTIONAL and TRANSIENT data store mode. --- pom.xml | 5 + .../parameter/AddParameterCommand.java | 2 +- .../service/RemoveOrderCollectionService.java | 13 +- .../strolch/service/RemoveOrderService.java | 8 +- .../RemoveResourceCollectionService.java | 13 +- .../service/RemoveResourceService.java | 8 +- .../parameter/RemoveParameterService.java | 15 +-- .../AddOrderCollectionServiceTest.java | 63 +++++++++ .../strolch/service/AddOrderServiceTest.java | 53 ++++++++ .../AddResourceCollectionServiceTest.java | 63 +++++++++ .../service/AddResourceServiceTest.java | 53 ++++++++ .../RemoveOrderCollectionServiceTest.java | 63 +++++++++ .../service/RemoveOrderServiceTest.java | 54 ++++++++ .../RemoveResourceCollectionServiceTest.java | 64 +++++++++ .../service/RemoveResourceServiceTest.java | 54 ++++++++ .../UpdateOrderCollectionServiceTest.java | 65 ++++++++++ .../service/UpdateOrderServiceTest.java | 53 ++++++++ .../UpdateResourceCollectionServiceTest.java | 65 ++++++++++ .../service/UpdateResourceServiceTest.java | 53 ++++++++ .../service/XmlExportModelServiceTest.java | 62 +++++++++ .../service/XmlImportModelServiceTest.java | 51 ++++++++ .../test/AbstractRealmServiceTest.java | 121 ++++++++++++++++++ .../service/test/XmlExportServiceTest.java | 8 +- .../parameter/AddParameterServiceTest.java | 60 +++++++++ .../parameter/RemoveParameterServiceTest.java | 54 ++++++++ .../parameter/SetParameterServiceTest.java | 60 +++++++++ .../svctest/config/StrolchConfiguration.xml | 81 ++++++++++++ src/test/resources/svctest/data/Enums.xml | 34 +++++ src/test/resources/svctest/data/Orders.xml | 58 +++++++++ src/test/resources/svctest/data/Resources.xml | 8 ++ .../resources/svctest/data/StrolchModel.xml | 8 ++ .../resources/transienttest/data/Enums.xml | 30 ++--- 32 files changed, 1366 insertions(+), 36 deletions(-) create mode 100644 src/test/java/li/strolch/service/AddOrderCollectionServiceTest.java create mode 100644 src/test/java/li/strolch/service/AddOrderServiceTest.java create mode 100644 src/test/java/li/strolch/service/AddResourceCollectionServiceTest.java create mode 100644 src/test/java/li/strolch/service/AddResourceServiceTest.java create mode 100644 src/test/java/li/strolch/service/RemoveOrderCollectionServiceTest.java create mode 100644 src/test/java/li/strolch/service/RemoveOrderServiceTest.java create mode 100644 src/test/java/li/strolch/service/RemoveResourceCollectionServiceTest.java create mode 100644 src/test/java/li/strolch/service/RemoveResourceServiceTest.java create mode 100644 src/test/java/li/strolch/service/UpdateOrderCollectionServiceTest.java create mode 100644 src/test/java/li/strolch/service/UpdateOrderServiceTest.java create mode 100644 src/test/java/li/strolch/service/UpdateResourceCollectionServiceTest.java create mode 100644 src/test/java/li/strolch/service/UpdateResourceServiceTest.java create mode 100644 src/test/java/li/strolch/service/XmlExportModelServiceTest.java create mode 100644 src/test/java/li/strolch/service/XmlImportModelServiceTest.java create mode 100644 src/test/java/li/strolch/service/test/AbstractRealmServiceTest.java create mode 100644 src/test/java/li/strolch/service/test/parameter/AddParameterServiceTest.java create mode 100644 src/test/java/li/strolch/service/test/parameter/RemoveParameterServiceTest.java create mode 100644 src/test/java/li/strolch/service/test/parameter/SetParameterServiceTest.java create mode 100644 src/test/resources/svctest/config/StrolchConfiguration.xml create mode 100644 src/test/resources/svctest/data/Enums.xml create mode 100644 src/test/resources/svctest/data/Orders.xml create mode 100644 src/test/resources/svctest/data/Resources.xml create mode 100644 src/test/resources/svctest/data/StrolchModel.xml diff --git a/pom.xml b/pom.xml index c55d5b9d3..338d30048 100644 --- a/pom.xml +++ b/pom.xml @@ -53,6 +53,11 @@ li.strolch li.strolch.testbase + + li.strolch + li.strolch.persistence.postgresql + test + diff --git a/src/main/java/li/strolch/command/parameter/AddParameterCommand.java b/src/main/java/li/strolch/command/parameter/AddParameterCommand.java index f666bc33b..115157884 100644 --- a/src/main/java/li/strolch/command/parameter/AddParameterCommand.java +++ b/src/main/java/li/strolch/command/parameter/AddParameterCommand.java @@ -75,7 +75,7 @@ public class AddParameterCommand extends Command { @Override public void doCommand() { - StrolchRootElement rootElement = this.parameter.getRootElement(); + StrolchRootElement rootElement = this.element.getRootElement(); tx().lock(rootElement); this.element.addParameter(this.parameter); diff --git a/src/main/java/li/strolch/service/RemoveOrderCollectionService.java b/src/main/java/li/strolch/service/RemoveOrderCollectionService.java index df7d4a707..dc26539d9 100644 --- a/src/main/java/li/strolch/service/RemoveOrderCollectionService.java +++ b/src/main/java/li/strolch/service/RemoveOrderCollectionService.java @@ -15,9 +15,11 @@ */ 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; @@ -41,8 +43,15 @@ public class RemoveOrderCollectionService extends 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(arg.orders); + command.setOrders(orders); tx.addCommand(command); } @@ -51,6 +60,6 @@ public class RemoveOrderCollectionService extends public static class RemoveOrderCollectionArg extends ServiceArgument { private static final long serialVersionUID = 1L; - public List orders; + public List locators; } } diff --git a/src/main/java/li/strolch/service/RemoveOrderService.java b/src/main/java/li/strolch/service/RemoveOrderService.java index 472511bd6..b13cc2b1e 100644 --- a/src/main/java/li/strolch/service/RemoveOrderService.java +++ b/src/main/java/li/strolch/service/RemoveOrderService.java @@ -16,6 +16,7 @@ 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; @@ -38,8 +39,11 @@ public class RemoveOrderService extends AbstractService 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(arg.resources); + command.setResources(resources); tx.addCommand(command); } @@ -51,6 +60,6 @@ public class RemoveResourceCollectionService extends public static class RemoveResourceCollectionArg extends ServiceArgument { private static final long serialVersionUID = 1L; - public List resources; + public List locators; } } diff --git a/src/main/java/li/strolch/service/RemoveResourceService.java b/src/main/java/li/strolch/service/RemoveResourceService.java index 66434e52c..eb273c815 100644 --- a/src/main/java/li/strolch/service/RemoveResourceService.java +++ b/src/main/java/li/strolch/service/RemoveResourceService.java @@ -16,6 +16,7 @@ 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; @@ -38,8 +39,11 @@ public class RemoveResourceService extends AbstractService */ -public class RemoveParameterService extends AbstractService { +public class RemoveParameterService extends AbstractService { private static final long serialVersionUID = 1L; @@ -36,24 +36,23 @@ public class RemoveParameterService extends AbstractService parameter = tx.findElement(arg.locator); RemoveParameterCommand command = new RemoveParameterCommand(getContainer(), tx); - command.setElement(element); - command.setParameterId(arg.parameterId); + command.setElement(parameter.getParent()); + command.setParameterId(parameter.getId()); tx.addCommand(command); } return ServiceResult.success(); } - public static class AddParameterArg extends ServiceArgument { + public static class RemoveParameterArg extends ServiceArgument { private static final long serialVersionUID = 1L; public Locator locator; - public String parameterId; } } diff --git a/src/test/java/li/strolch/service/AddOrderCollectionServiceTest.java b/src/test/java/li/strolch/service/AddOrderCollectionServiceTest.java new file mode 100644 index 000000000..1bb829372 --- /dev/null +++ b/src/test/java/li/strolch/service/AddOrderCollectionServiceTest.java @@ -0,0 +1,63 @@ +/* + * 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.api.Service; +import li.strolch.service.api.ServiceArgument; +import li.strolch.service.api.ServiceResult; +import li.strolch.service.test.AbstractRealmServiceTest; + +import org.junit.Before; + +/** + * @author Robert von Burg + */ +public class AddOrderCollectionServiceTest extends AbstractRealmServiceTest { + + private AddOrderCollectionService svc; + private AddOrderCollectionArg arg; + private ArrayList orders; + + @Before + public void before() { + svc = new AddOrderCollectionService(); + arg = new AddOrderCollectionArg(); + + 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; + } + + @Override + @SuppressWarnings("unchecked") + public T getArg() { + return (T) this.arg; + } + + @Override + @SuppressWarnings("unchecked") + public Service getSvc() { + return (Service) this.svc; + } +} diff --git a/src/test/java/li/strolch/service/AddOrderServiceTest.java b/src/test/java/li/strolch/service/AddOrderServiceTest.java new file mode 100644 index 000000000..11cfae90a --- /dev/null +++ b/src/test/java/li/strolch/service/AddOrderServiceTest.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.model.ModelGenerator; +import li.strolch.service.AddOrderService.AddOrderArg; +import li.strolch.service.api.Service; +import li.strolch.service.api.ServiceArgument; +import li.strolch.service.api.ServiceResult; +import li.strolch.service.test.AbstractRealmServiceTest; + +import org.junit.Before; + +/** + * @author Robert von Burg + */ +public class AddOrderServiceTest extends AbstractRealmServiceTest { + + private AddOrderService svc; + private AddOrderArg arg; + + @Before + public void before() { + svc = new AddOrderService(); + arg = new AddOrderArg(); + arg.order = ModelGenerator.createOrder("firstOrder", "First Order", "AdditionalOrders"); + } + + @Override + @SuppressWarnings("unchecked") + public T getArg() { + return (T) this.arg; + } + + @Override + @SuppressWarnings("unchecked") + public Service getSvc() { + return (Service) this.svc; + } +} diff --git a/src/test/java/li/strolch/service/AddResourceCollectionServiceTest.java b/src/test/java/li/strolch/service/AddResourceCollectionServiceTest.java new file mode 100644 index 000000000..aa3f8716a --- /dev/null +++ b/src/test/java/li/strolch/service/AddResourceCollectionServiceTest.java @@ -0,0 +1,63 @@ +/* + * 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.api.Service; +import li.strolch.service.api.ServiceArgument; +import li.strolch.service.api.ServiceResult; +import li.strolch.service.test.AbstractRealmServiceTest; + +import org.junit.Before; + +/** + * @author Robert von Burg + */ +public class AddResourceCollectionServiceTest extends AbstractRealmServiceTest { + + private AddResourceCollectionService svc; + private AddResourceCollectionArg arg; + private ArrayList resources; + + @Before + public void before() { + svc = new AddResourceCollectionService(); + arg = new AddResourceCollectionArg(); + + 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; + } + + @Override + @SuppressWarnings("unchecked") + public T getArg() { + return (T) this.arg; + } + + @Override + @SuppressWarnings("unchecked") + public Service getSvc() { + return (Service) this.svc; + } +} diff --git a/src/test/java/li/strolch/service/AddResourceServiceTest.java b/src/test/java/li/strolch/service/AddResourceServiceTest.java new file mode 100644 index 000000000..d8646c286 --- /dev/null +++ b/src/test/java/li/strolch/service/AddResourceServiceTest.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.model.ModelGenerator; +import li.strolch.service.AddResourceService.AddResourceArg; +import li.strolch.service.api.Service; +import li.strolch.service.api.ServiceArgument; +import li.strolch.service.api.ServiceResult; +import li.strolch.service.test.AbstractRealmServiceTest; + +import org.junit.Before; + +/** + * @author Robert von Burg + */ +public class AddResourceServiceTest extends AbstractRealmServiceTest { + + private AddResourceService svc; + private AddResourceArg arg; + + @Before + public void before() { + svc = new AddResourceService(); + arg = new AddResourceArg(); + arg.resource = ModelGenerator.createResource("firstRes", "First Resource", "AdditionalResources"); + } + + @Override + @SuppressWarnings("unchecked") + public T getArg() { + return (T) this.arg; + } + + @Override + @SuppressWarnings("unchecked") + public Service getSvc() { + return (Service) this.svc; + } +} diff --git a/src/test/java/li/strolch/service/RemoveOrderCollectionServiceTest.java b/src/test/java/li/strolch/service/RemoveOrderCollectionServiceTest.java new file mode 100644 index 000000000..5af7de9d7 --- /dev/null +++ b/src/test/java/li/strolch/service/RemoveOrderCollectionServiceTest.java @@ -0,0 +1,63 @@ +/* + * 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.api.Service; +import li.strolch.service.api.ServiceArgument; +import li.strolch.service.api.ServiceResult; +import li.strolch.service.test.AbstractRealmServiceTest; + +import org.junit.Before; + +/** + * @author Robert von Burg + */ +public class RemoveOrderCollectionServiceTest extends AbstractRealmServiceTest { + + private RemoveOrderCollectionService svc; + private RemoveOrderCollectionArg arg; + private ArrayList locators; + + @Before + public void before() { + svc = new RemoveOrderCollectionService(); + arg = new RemoveOrderCollectionArg(); + + locators = new ArrayList<>(); + locators.add(Locator.newBuilder(Tags.ORDER).append("TestType").append("@1").build()); + locators.add(Locator.newBuilder(Tags.ORDER).append("TestType").append("@2").build()); + locators.add(Locator.newBuilder(Tags.ORDER).append("TestType").append("@3").build()); + + arg.locators = locators; + } + + @Override + @SuppressWarnings("unchecked") + public T getArg() { + return (T) this.arg; + } + + @Override + @SuppressWarnings("unchecked") + public Service getSvc() { + return (Service) this.svc; + } +} diff --git a/src/test/java/li/strolch/service/RemoveOrderServiceTest.java b/src/test/java/li/strolch/service/RemoveOrderServiceTest.java new file mode 100644 index 000000000..afcefc4e8 --- /dev/null +++ b/src/test/java/li/strolch/service/RemoveOrderServiceTest.java @@ -0,0 +1,54 @@ +/* + * 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.api.Service; +import li.strolch.service.api.ServiceArgument; +import li.strolch.service.api.ServiceResult; +import li.strolch.service.test.AbstractRealmServiceTest; + +import org.junit.Before; + +/** + * @author Robert von Burg + */ +public class RemoveOrderServiceTest extends AbstractRealmServiceTest { + + private RemoveOrderService svc; + private RemoveOrderArg arg; + + @Before + public void before() { + svc = new RemoveOrderService(); + arg = new RemoveOrderArg(); + arg.locator = Locator.newBuilder(Tags.ORDER).append("TestType").append("@3").build(); + } + + @Override + @SuppressWarnings("unchecked") + public T getArg() { + return (T) this.arg; + } + + @Override + @SuppressWarnings("unchecked") + public Service getSvc() { + return (Service) this.svc; + } +} diff --git a/src/test/java/li/strolch/service/RemoveResourceCollectionServiceTest.java b/src/test/java/li/strolch/service/RemoveResourceCollectionServiceTest.java new file mode 100644 index 000000000..cbb2bfad2 --- /dev/null +++ b/src/test/java/li/strolch/service/RemoveResourceCollectionServiceTest.java @@ -0,0 +1,64 @@ +/* + * 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.Locator; +import li.strolch.model.Tags; +import li.strolch.service.RemoveResourceCollectionService.RemoveResourceCollectionArg; +import li.strolch.service.api.Service; +import li.strolch.service.api.ServiceArgument; +import li.strolch.service.api.ServiceResult; +import li.strolch.service.test.AbstractRealmServiceTest; + +import org.junit.Before; + +/** + * @author Robert von Burg + */ +public class RemoveResourceCollectionServiceTest extends AbstractRealmServiceTest { + + private RemoveResourceCollectionService svc; + private RemoveResourceCollectionArg arg; + private List locators; + + @Before + public void before() { + svc = new RemoveResourceCollectionService(); + arg = new RemoveResourceCollectionArg(); + + locators = new ArrayList<>(); + locators.add(Locator.newBuilder(Tags.RESOURCE).append("Enumeration").append("salutations").build()); + locators.add(Locator.newBuilder(Tags.RESOURCE).append("Enumeration").append("sex").build()); + locators.add(Locator.newBuilder(Tags.RESOURCE).append("Enumeration").append("religions").build()); + + arg.locators = locators; + } + + @Override + @SuppressWarnings("unchecked") + public T getArg() { + return (T) this.arg; + } + + @Override + @SuppressWarnings("unchecked") + public Service getSvc() { + return (Service) this.svc; + } +} diff --git a/src/test/java/li/strolch/service/RemoveResourceServiceTest.java b/src/test/java/li/strolch/service/RemoveResourceServiceTest.java new file mode 100644 index 000000000..98ce143a8 --- /dev/null +++ b/src/test/java/li/strolch/service/RemoveResourceServiceTest.java @@ -0,0 +1,54 @@ +/* + * 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.api.Service; +import li.strolch.service.api.ServiceArgument; +import li.strolch.service.api.ServiceResult; +import li.strolch.service.test.AbstractRealmServiceTest; + +import org.junit.Before; + +/** + * @author Robert von Burg + */ +public class RemoveResourceServiceTest extends AbstractRealmServiceTest { + + private RemoveResourceService svc; + private RemoveResourceArg arg; + + @Before + public void before() { + svc = new RemoveResourceService(); + arg = new RemoveResourceArg(); + arg.locator = Locator.newBuilder(Tags.RESOURCE).append("Enumeration").append("sex").build(); + } + + @Override + @SuppressWarnings("unchecked") + public T getArg() { + return (T) this.arg; + } + + @Override + @SuppressWarnings("unchecked") + public Service getSvc() { + return (Service) this.svc; + } +} diff --git a/src/test/java/li/strolch/service/UpdateOrderCollectionServiceTest.java b/src/test/java/li/strolch/service/UpdateOrderCollectionServiceTest.java new file mode 100644 index 000000000..94ef7f2d0 --- /dev/null +++ b/src/test/java/li/strolch/service/UpdateOrderCollectionServiceTest.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.model.ModelGenerator; +import li.strolch.model.Order; +import li.strolch.service.UpdateOrderCollectionService.UpdateOrderCollectionArg; +import li.strolch.service.api.Service; +import li.strolch.service.api.ServiceArgument; +import li.strolch.service.api.ServiceResult; +import li.strolch.service.test.AbstractRealmServiceTest; + +import org.junit.Before; + +/** + * @author Robert von Burg + */ +public class UpdateOrderCollectionServiceTest extends AbstractRealmServiceTest { + + private UpdateOrderCollectionService svc; + private UpdateOrderCollectionArg arg; + + private List orders; + + @Before + public void before() { + svc = new UpdateOrderCollectionService(); + arg = new UpdateOrderCollectionArg(); + + 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; + } + + @Override + @SuppressWarnings("unchecked") + public T getArg() { + return (T) this.arg; + } + + @Override + @SuppressWarnings("unchecked") + public Service getSvc() { + return (Service) this.svc; + } +} diff --git a/src/test/java/li/strolch/service/UpdateOrderServiceTest.java b/src/test/java/li/strolch/service/UpdateOrderServiceTest.java new file mode 100644 index 000000000..0b5108add --- /dev/null +++ b/src/test/java/li/strolch/service/UpdateOrderServiceTest.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.model.ModelGenerator; +import li.strolch.service.UpdateOrderService.UpdateOrderArg; +import li.strolch.service.api.Service; +import li.strolch.service.api.ServiceArgument; +import li.strolch.service.api.ServiceResult; +import li.strolch.service.test.AbstractRealmServiceTest; + +import org.junit.Before; + +/** + * @author Robert von Burg + */ +public class UpdateOrderServiceTest extends AbstractRealmServiceTest { + + private UpdateOrderService svc; + private UpdateOrderArg arg; + + @Before + public void before() { + svc = new UpdateOrderService(); + arg = new UpdateOrderArg(); + arg.order = ModelGenerator.createOrder("myCarOrder", "Modified Car Order", "ProductionOrder"); + } + + @Override + @SuppressWarnings("unchecked") + public T getArg() { + return (T) this.arg; + } + + @Override + @SuppressWarnings("unchecked") + public Service getSvc() { + return (Service) this.svc; + } +} diff --git a/src/test/java/li/strolch/service/UpdateResourceCollectionServiceTest.java b/src/test/java/li/strolch/service/UpdateResourceCollectionServiceTest.java new file mode 100644 index 000000000..9ad7c3edc --- /dev/null +++ b/src/test/java/li/strolch/service/UpdateResourceCollectionServiceTest.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.model.ModelGenerator; +import li.strolch.model.Resource; +import li.strolch.service.UpdateResourceCollectionService.UpdateResourceCollectionArg; +import li.strolch.service.api.Service; +import li.strolch.service.api.ServiceArgument; +import li.strolch.service.api.ServiceResult; +import li.strolch.service.test.AbstractRealmServiceTest; + +import org.junit.Before; + +/** + * @author Robert von Burg + */ +public class UpdateResourceCollectionServiceTest extends AbstractRealmServiceTest { + + private UpdateResourceCollectionService svc; + private UpdateResourceCollectionArg arg; + + private List resources; + + @Before + public void before() { + svc = new UpdateResourceCollectionService(); + arg = new UpdateResourceCollectionArg(); + + 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; + } + + @Override + @SuppressWarnings("unchecked") + public T getArg() { + return (T) this.arg; + } + + @Override + @SuppressWarnings("unchecked") + public Service getSvc() { + return (Service) this.svc; + } +} diff --git a/src/test/java/li/strolch/service/UpdateResourceServiceTest.java b/src/test/java/li/strolch/service/UpdateResourceServiceTest.java new file mode 100644 index 000000000..7fde7735d --- /dev/null +++ b/src/test/java/li/strolch/service/UpdateResourceServiceTest.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.model.ModelGenerator; +import li.strolch.service.UpdateResourceService.UpdateResourceArg; +import li.strolch.service.api.Service; +import li.strolch.service.api.ServiceArgument; +import li.strolch.service.api.ServiceResult; +import li.strolch.service.test.AbstractRealmServiceTest; + +import org.junit.Before; + +/** + * @author Robert von Burg + */ +public class UpdateResourceServiceTest extends AbstractRealmServiceTest { + + private UpdateResourceService svc; + private UpdateResourceArg arg; + + @Before + public void before() { + svc = new UpdateResourceService(); + arg = new UpdateResourceArg(); + arg.resource = ModelGenerator.createResource("yellow", "Modified Yellow Ball", "Ball"); + } + + @Override + @SuppressWarnings("unchecked") + public T getArg() { + return (T) this.arg; + } + + @Override + @SuppressWarnings("unchecked") + public Service getSvc() { + return (Service) this.svc; + } +} diff --git a/src/test/java/li/strolch/service/XmlExportModelServiceTest.java b/src/test/java/li/strolch/service/XmlExportModelServiceTest.java new file mode 100644 index 000000000..56d778a08 --- /dev/null +++ b/src/test/java/li/strolch/service/XmlExportModelServiceTest.java @@ -0,0 +1,62 @@ +/* + * 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 li.strolch.service.api.Service; +import li.strolch.service.api.ServiceArgument; +import li.strolch.service.api.ServiceResult; +import li.strolch.service.test.AbstractRealmServiceTest; + +import org.junit.After; +import org.junit.Before; + +/** + * @author Robert von Burg + */ +public class XmlExportModelServiceTest extends AbstractRealmServiceTest { + + private static final String TMP_XML_EXPORT_XML = "tmpXmlExport.xml"; + private XmlExportModelService svc; + private XmlExportModelArgument arg; + + @Before + public void before() { + svc = new XmlExportModelService(); + arg = new XmlExportModelArgument(); + arg.modelFileName = TMP_XML_EXPORT_XML; + } + + @After + public void after() { + File file = new File(RUNTIME_PATH + "/data", TMP_XML_EXPORT_XML); + if (file.exists()) + file.delete(); + } + + @Override + @SuppressWarnings("unchecked") + public T getArg() { + return (T) this.arg; + } + + @Override + @SuppressWarnings("unchecked") + public Service getSvc() { + return (Service) this.svc; + } +} diff --git a/src/test/java/li/strolch/service/XmlImportModelServiceTest.java b/src/test/java/li/strolch/service/XmlImportModelServiceTest.java new file mode 100644 index 000000000..800e1c421 --- /dev/null +++ b/src/test/java/li/strolch/service/XmlImportModelServiceTest.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.service; + +import li.strolch.service.api.Service; +import li.strolch.service.api.ServiceArgument; +import li.strolch.service.api.ServiceResult; +import li.strolch.service.test.AbstractRealmServiceTest; + +import org.junit.Before; + +/** + * @author Robert von Burg + */ +public class XmlImportModelServiceTest extends AbstractRealmServiceTest { + + private XmlImportModelService svc; + private XmlImportModelArgument arg; + + @Before + public void before() { + svc = new XmlImportModelService(); + arg = new XmlImportModelArgument(); + arg.modelFileName = "Enums.xml"; + } + + @Override + @SuppressWarnings("unchecked") + public T getArg() { + return (T) this.arg; + } + + @Override + @SuppressWarnings("unchecked") + public Service getSvc() { + return (Service) this.svc; + } +} diff --git a/src/test/java/li/strolch/service/test/AbstractRealmServiceTest.java b/src/test/java/li/strolch/service/test/AbstractRealmServiceTest.java new file mode 100644 index 000000000..0125979ae --- /dev/null +++ b/src/test/java/li/strolch/service/test/AbstractRealmServiceTest.java @@ -0,0 +1,121 @@ +/* + * 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.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.AfterClass; +import org.junit.BeforeClass; +import org.junit.Test; + +/** + * @author Robert von Burg + */ +public abstract class AbstractRealmServiceTest { + + protected static final String REALM_CACHED = "svcCached"; + protected static final String REALM_TRANSACTIONAL = "svcTransactional"; + protected static final String REALM_TRANSIENT = "svcTransient"; + protected static final String RUNTIME_PATH = "target/svcTestRuntime/"; //$NON-NLS-1$ + protected static final String CONFIG_SRC = "src/test/resources/svctest"; //$NON-NLS-1$ + + protected static RuntimeMock runtimeMock; + + @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(); + + importFromXml(REALM_CACHED); + importFromXml(REALM_TRANSACTIONAL); + } + + private 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(); + } + } + + private static void importFromXml(String realm) { + + XmlImportModelService svc = new XmlImportModelService(); + XmlImportModelArgument arg = new XmlImportModelArgument(); + arg.realm = realm; + arg.modelFileName = "StrolchModel.xml"; + ServiceResult result = getServiceHandler().doService(null, svc, arg); + assertServiceResult(ServiceResultState.SUCCESS, ServiceResult.class, result); + } + + protected void doService(String realm, + ServiceResultState expectedState, Class expectedServiceResultType, Service svc, T arg) { + + arg.realm = realm; + ServiceResult result = getServiceHandler().doService(null, svc, arg); + assertServiceResult(expectedState, expectedServiceResultType, result); + } + + @AfterClass + public static void afterClass() { + runtimeMock.destroyRuntime(); + } + + public static ServiceHandler getServiceHandler() { + return runtimeMock.getContainer().getComponent(ServiceHandler.class); + } + + @Test + public void shouldPerformServiceTransient() { + doService(REALM_TRANSIENT, ServiceResultState.SUCCESS, ServiceResult.class, getSvc(), getArg()); + } + + public abstract T getArg(); + + public abstract Service getSvc(); + + @Test + public void shouldPerformServiceCached() { + doService(REALM_CACHED, ServiceResultState.SUCCESS, ServiceResult.class, getSvc(), getArg()); + } + + @Test + public void shouldPerformServiceTransactional() { + doService(REALM_TRANSACTIONAL, ServiceResultState.SUCCESS, ServiceResult.class, getSvc(), getArg()); + } +} diff --git a/src/test/java/li/strolch/service/test/XmlExportServiceTest.java b/src/test/java/li/strolch/service/test/XmlExportServiceTest.java index 397c2b7c8..356fd27d6 100644 --- a/src/test/java/li/strolch/service/test/XmlExportServiceTest.java +++ b/src/test/java/li/strolch/service/test/XmlExportServiceTest.java @@ -65,7 +65,7 @@ public class XmlExportServiceTest { arg.modelFileName = "TestExportSingle.xml"; arg.multiFile = false; ServiceResult result = runtimeMock.getServiceHandler().doService(null, service, arg); - runtimeMock.assertServiceResult(ServiceResultState.SUCCESS, ServiceResult.class, result); + RuntimeMock.assertServiceResult(ServiceResultState.SUCCESS, ServiceResult.class, result); assertNumberOfFilesCreated(arg.modelFileName.split("\\.")[0], 1); importModel(arg.modelFileName); @@ -79,7 +79,7 @@ public class XmlExportServiceTest { arg.modelFileName = "TestExportMulti.xml"; arg.multiFile = true; ServiceResult result = runtimeMock.getServiceHandler().doService(null, service, arg); - runtimeMock.assertServiceResult(ServiceResultState.SUCCESS, ServiceResult.class, result); + RuntimeMock.assertServiceResult(ServiceResultState.SUCCESS, ServiceResult.class, result); assertNumberOfFilesCreated(arg.modelFileName.split("\\.")[0], 6); importModel(arg.modelFileName); @@ -95,7 +95,7 @@ public class XmlExportServiceTest { arg.resourceTypes.add(Tags.TEMPLATE); arg.multiFile = true; ServiceResult result = runtimeMock.getServiceHandler().doService(null, service, arg); - runtimeMock.assertServiceResult(ServiceResultState.SUCCESS, ServiceResult.class, result); + RuntimeMock.assertServiceResult(ServiceResultState.SUCCESS, ServiceResult.class, result); assertNumberOfFilesCreated(arg.modelFileName.split("\\.")[0], 2); importModel(arg.modelFileName); @@ -106,7 +106,7 @@ public class XmlExportServiceTest { XmlImportModelArgument importArgument = new XmlImportModelArgument(); importArgument.modelFileName = modelFileName; ServiceResult result = runtimeMock.getServiceHandler().doService(null, importService, importArgument); - runtimeMock.assertServiceResult(ServiceResultState.SUCCESS, ServiceResult.class, result); + RuntimeMock.assertServiceResult(ServiceResultState.SUCCESS, ServiceResult.class, result); } private void assertNumberOfFilesCreated(final String modelFileName, int nrOfExpectedFiles) { diff --git a/src/test/java/li/strolch/service/test/parameter/AddParameterServiceTest.java b/src/test/java/li/strolch/service/test/parameter/AddParameterServiceTest.java new file mode 100644 index 000000000..1a6117506 --- /dev/null +++ b/src/test/java/li/strolch/service/test/parameter/AddParameterServiceTest.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.test.parameter; + +import li.strolch.model.Locator; +import li.strolch.model.parameter.FloatParameter; +import li.strolch.service.api.Service; +import li.strolch.service.api.ServiceArgument; +import li.strolch.service.api.ServiceResult; +import li.strolch.service.parameter.AddParameterService; +import li.strolch.service.parameter.AddParameterService.AddParameterArg; +import li.strolch.service.test.AbstractRealmServiceTest; + +import org.junit.Before; + +/** + * @author Robert von Burg + */ +public class AddParameterServiceTest extends AbstractRealmServiceTest { + + private AddParameterService svc; + private AddParameterArg arg; + private FloatParameter parameter; + + @Before + public void before() { + svc = new AddParameterService(); + arg = new AddParameterArg(); + arg.locator = Locator.valueOf("Resource/Ball/yellow/parameters"); + parameter = new FloatParameter("diameter", "Diameter", 22.0); + parameter.setInterpretation("Dimension"); + parameter.setUom("cm"); + arg.parameter = parameter; + } + + @Override + @SuppressWarnings("unchecked") + public T getArg() { + return (T) this.arg; + } + + @Override + @SuppressWarnings("unchecked") + public Service getSvc() { + return (Service) this.svc; + } +} diff --git a/src/test/java/li/strolch/service/test/parameter/RemoveParameterServiceTest.java b/src/test/java/li/strolch/service/test/parameter/RemoveParameterServiceTest.java new file mode 100644 index 000000000..601fc4399 --- /dev/null +++ b/src/test/java/li/strolch/service/test/parameter/RemoveParameterServiceTest.java @@ -0,0 +1,54 @@ +/* + * 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.api.Service; +import li.strolch.service.api.ServiceArgument; +import li.strolch.service.api.ServiceResult; +import li.strolch.service.parameter.RemoveParameterService; +import li.strolch.service.parameter.RemoveParameterService.RemoveParameterArg; +import li.strolch.service.test.AbstractRealmServiceTest; + +import org.junit.Before; + +/** + * @author Robert von Burg + */ +public class RemoveParameterServiceTest extends AbstractRealmServiceTest { + + private RemoveParameterService svc; + private RemoveParameterArg arg; + + @Before + public void before() { + svc = new RemoveParameterService(); + arg = new RemoveParameterArg(); + arg.locator = Locator.valueOf("Resource/Ball/yellow/parameters/owner"); + } + + @Override + @SuppressWarnings("unchecked") + public T getArg() { + return (T) this.arg; + } + + @Override + @SuppressWarnings("unchecked") + public Service getSvc() { + return (Service) this.svc; + } +} diff --git a/src/test/java/li/strolch/service/test/parameter/SetParameterServiceTest.java b/src/test/java/li/strolch/service/test/parameter/SetParameterServiceTest.java new file mode 100644 index 000000000..4427d546c --- /dev/null +++ b/src/test/java/li/strolch/service/test/parameter/SetParameterServiceTest.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.test.parameter; + +import li.strolch.model.Locator; +import li.strolch.service.api.Service; +import li.strolch.service.api.ServiceArgument; +import li.strolch.service.api.ServiceResult; +import li.strolch.service.parameter.SetParameterService; +import li.strolch.service.parameter.SetParameterService.SetParameterArg; +import li.strolch.service.test.AbstractRealmServiceTest; + +import org.junit.Before; + +/** + * @author Robert von Burg + */ +public class SetParameterServiceTest extends AbstractRealmServiceTest { + + private SetParameterService svc; + private SetParameterArg arg; + + @Before + public void before() { + svc = new SetParameterService(); + arg = new SetParameterArg(); + arg.locator = Locator.valueOf("Resource/Ball/yellow/parameters/owner"); + arg.name = "The Owner"; + arg.interpretation = "Changing The Interpretation"; + arg.uom = "Owners"; + arg.hidden = true; + arg.index = 99; + arg.valueAsString = "someotherdude"; + } + + @Override + @SuppressWarnings("unchecked") + public T getArg() { + return (T) this.arg; + } + + @Override + @SuppressWarnings("unchecked") + public Service getSvc() { + return (Service) this.svc; + } +} diff --git a/src/test/resources/svctest/config/StrolchConfiguration.xml b/src/test/resources/svctest/config/StrolchConfiguration.xml new file mode 100644 index 000000000..2c35ebaad --- /dev/null +++ b/src/test/resources/svctest/config/StrolchConfiguration.xml @@ -0,0 +1,81 @@ + + + + StrolchRuntimeTest + + true + + + + RealmHandler + li.strolch.agent.api.RealmHandler + li.strolch.agent.impl.DefaultRealmHandler + PersistenceHandler + + svcTransient, svcCached, svcTransactional + + SECONDS + 1 + TRANSIENT + StrolchModel.xml + + SECONDS + 1 + CACHED + + SECONDS + 1 + TRANSACTIONAL + + + + + PersistenceHandler + li.strolch.persistence.api.PersistenceHandler + li.strolch.persistence.postgresql.PostgreSqlPersistenceHandler + + true + true + + jdbc:postgresql://localhost/cacheduserdb + cacheduser + test + + jdbc:postgresql://localhost/transactionaluserdb + transactionaluser + test + + + + + + + + ServiceHandler + li.strolch.service.api.ServiceHandler + li.strolch.service.api.DefaultServiceHandler + + true + + + \ No newline at end of file diff --git a/src/test/resources/svctest/data/Enums.xml b/src/test/resources/svctest/data/Enums.xml new file mode 100644 index 000000000..eb80fda34 --- /dev/null +++ b/src/test/resources/svctest/data/Enums.xml @@ -0,0 +1,34 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/test/resources/svctest/data/Orders.xml b/src/test/resources/svctest/data/Orders.xml new file mode 100644 index 000000000..6db28be23 --- /dev/null +++ b/src/test/resources/svctest/data/Orders.xml @@ -0,0 +1,58 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/test/resources/svctest/data/Resources.xml b/src/test/resources/svctest/data/Resources.xml new file mode 100644 index 000000000..b97a4c05a --- /dev/null +++ b/src/test/resources/svctest/data/Resources.xml @@ -0,0 +1,8 @@ + + + + + + + + diff --git a/src/test/resources/svctest/data/StrolchModel.xml b/src/test/resources/svctest/data/StrolchModel.xml new file mode 100644 index 000000000..12a264f80 --- /dev/null +++ b/src/test/resources/svctest/data/StrolchModel.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/src/test/resources/transienttest/data/Enums.xml b/src/test/resources/transienttest/data/Enums.xml index 62ddb9c61..eb80fda34 100644 --- a/src/test/resources/transienttest/data/Enums.xml +++ b/src/test/resources/transienttest/data/Enums.xml @@ -3,31 +3,31 @@ - - - + + + - - - + + + - - - - - - - - - + + + + + + + + + From 5e088b7a520507c50c88abefaf174ac526e9a991 Mon Sep 17 00:00:00 2001 From: Robert von Burg Date: Mon, 10 Mar 2014 22:34:36 +0100 Subject: [PATCH 44/65] [New] Added tests for Command.undo() for all Command implementations Except for the XML Import and Export commands... --- .../command/AbstractRealmCommandTest.java | 145 ++++++++++++++++++ .../AddOrderCollectionCommandTest.java | 51 ++++++ .../strolch/command/AddOrderCommandTest.java | 45 ++++++ .../AddResourceCollectionCommandTest.java | 51 ++++++ .../command/AddResourceCommandTest.java | 45 ++++++ .../RemoveOrderCollectionCommandTest.java | 57 +++++++ .../command/RemoveOrderCommandTest.java | 48 ++++++ .../RemoveResourceCollectionCommandTest.java | 57 +++++++ .../command/RemoveResourceCommandTest.java | 48 ++++++ .../UpdateOrderCollectionCommandTest.java | 51 ++++++ .../command/UpdateOrderCommandTest.java | 45 ++++++ .../UpdateResourceCollectionCommandTest.java | 51 ++++++ .../command/UpdateResourceCommandTest.java | 45 ++++++ .../parameter/AddParameterCommandTest.java | 54 +++++++ .../parameter/RemoveParameterCommandTest.java | 51 ++++++ .../parameter/SetParameterCommandTest.java | 52 +++++++ .../test/AbstractRealmServiceTest.java | 40 ++--- 17 files changed, 916 insertions(+), 20 deletions(-) create mode 100644 src/test/java/li/strolch/command/AbstractRealmCommandTest.java create mode 100644 src/test/java/li/strolch/command/AddOrderCollectionCommandTest.java create mode 100644 src/test/java/li/strolch/command/AddOrderCommandTest.java create mode 100644 src/test/java/li/strolch/command/AddResourceCollectionCommandTest.java create mode 100644 src/test/java/li/strolch/command/AddResourceCommandTest.java create mode 100644 src/test/java/li/strolch/command/RemoveOrderCollectionCommandTest.java create mode 100644 src/test/java/li/strolch/command/RemoveOrderCommandTest.java create mode 100644 src/test/java/li/strolch/command/RemoveResourceCollectionCommandTest.java create mode 100644 src/test/java/li/strolch/command/RemoveResourceCommandTest.java create mode 100644 src/test/java/li/strolch/command/UpdateOrderCollectionCommandTest.java create mode 100644 src/test/java/li/strolch/command/UpdateOrderCommandTest.java create mode 100644 src/test/java/li/strolch/command/UpdateResourceCollectionCommandTest.java create mode 100644 src/test/java/li/strolch/command/UpdateResourceCommandTest.java create mode 100644 src/test/java/li/strolch/command/parameter/AddParameterCommandTest.java create mode 100644 src/test/java/li/strolch/command/parameter/RemoveParameterCommandTest.java create mode 100644 src/test/java/li/strolch/command/parameter/SetParameterCommandTest.java diff --git a/src/test/java/li/strolch/command/AbstractRealmCommandTest.java b/src/test/java/li/strolch/command/AbstractRealmCommandTest.java new file mode 100644 index 000000000..e1fb0b3d7 --- /dev/null +++ b/src/test/java/li/strolch/command/AbstractRealmCommandTest.java @@ -0,0 +1,145 @@ +/* + * 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; + +/** + * @author Robert von Burg + */ +public abstract class AbstractRealmCommandTest { + + protected static RuntimeMock runtimeMock; + + @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(); + + importFromXml(REALM_CACHED, getServiceHandler()); + importFromXml(REALM_TRANSACTIONAL, 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) { + expectedException.expect(RuntimeException.class); + expectedException.expectMessage("Fail on purpose after do command!"); + + StrolchRealm realm = runtimeMock.getContainer().getRealm(realmName); + try (StrolchTransaction tx = realm.openTx()) { + + 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()) { + 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/src/test/java/li/strolch/command/AddOrderCollectionCommandTest.java b/src/test/java/li/strolch/command/AddOrderCollectionCommandTest.java new file mode 100644 index 000000000..9e3206010 --- /dev/null +++ b/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() { + 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")); + } + + @Override + protected Command getCommandInstance(ComponentContainer container, StrolchTransaction tx) { + + AddOrderCollectionCommand command = new AddOrderCollectionCommand(container, tx); + command.setOrders(orders); + return command; + } +} diff --git a/src/test/java/li/strolch/command/AddOrderCommandTest.java b/src/test/java/li/strolch/command/AddOrderCommandTest.java new file mode 100644 index 000000000..43a92c659 --- /dev/null +++ b/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() { + order = ModelGenerator.createOrder("firstOrder", "First Order", "AdditionalOrders"); + } + + @Override + protected Command getCommandInstance(ComponentContainer container, StrolchTransaction tx) { + + AddOrderCommand command = new AddOrderCommand(container, tx); + command.setOrder(order); + return command; + } +} diff --git a/src/test/java/li/strolch/command/AddResourceCollectionCommandTest.java b/src/test/java/li/strolch/command/AddResourceCollectionCommandTest.java new file mode 100644 index 000000000..00c39607a --- /dev/null +++ b/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() { + 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")); + } + + @Override + protected Command getCommandInstance(ComponentContainer container, StrolchTransaction tx) { + + AddResourceCollectionCommand command = new AddResourceCollectionCommand(container, tx); + command.setResources(resources); + return command; + } +} diff --git a/src/test/java/li/strolch/command/AddResourceCommandTest.java b/src/test/java/li/strolch/command/AddResourceCommandTest.java new file mode 100644 index 000000000..d76adbc7f --- /dev/null +++ b/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() { + resource = ModelGenerator.createResource("firstRes", "First Resource", "AdditionalResources"); + } + + @Override + protected Command getCommandInstance(ComponentContainer container, StrolchTransaction tx) { + + AddResourceCommand command = new AddResourceCommand(container, tx); + command.setResource(resource); + return command; + } +} diff --git a/src/test/java/li/strolch/command/RemoveOrderCollectionCommandTest.java b/src/test/java/li/strolch/command/RemoveOrderCollectionCommandTest.java new file mode 100644 index 000000000..df4cf4f3b --- /dev/null +++ b/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() { + locators = new ArrayList<>(); + locators.add(Locator.newBuilder(Tags.ORDER).append("TestType").append("@1").build()); + locators.add(Locator.newBuilder(Tags.ORDER).append("TestType").append("@2").build()); + locators.add(Locator.newBuilder(Tags.ORDER).append("TestType").append("@3").build()); + } + + @Override + protected Command getCommandInstance(ComponentContainer container, StrolchTransaction tx) { + + List orders = new ArrayList<>(locators.size()); + for (Locator locator : locators) { + orders.add((Order) tx.findElement(locator)); + } + + RemoveOrderCollectionCommand command = new RemoveOrderCollectionCommand(container, tx); + command.setOrders(orders); + return command; + } +} diff --git a/src/test/java/li/strolch/command/RemoveOrderCommandTest.java b/src/test/java/li/strolch/command/RemoveOrderCommandTest.java new file mode 100644 index 000000000..a64b41098 --- /dev/null +++ b/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() { + locator = Locator.newBuilder(Tags.ORDER).append("TestType").append("@3").build(); + } + + @Override + protected Command getCommandInstance(ComponentContainer container, StrolchTransaction tx) { + + Order order = tx.findElement(locator); + + RemoveOrderCommand command = new RemoveOrderCommand(container, tx); + command.setOrder(order); + return command; + } +} diff --git a/src/test/java/li/strolch/command/RemoveResourceCollectionCommandTest.java b/src/test/java/li/strolch/command/RemoveResourceCollectionCommandTest.java new file mode 100644 index 000000000..1e71c85f5 --- /dev/null +++ b/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() { + locators = new ArrayList<>(); + locators.add(Locator.newBuilder(Tags.RESOURCE).append("Enumeration").append("salutations").build()); + locators.add(Locator.newBuilder(Tags.RESOURCE).append("Enumeration").append("sex").build()); + locators.add(Locator.newBuilder(Tags.RESOURCE).append("Enumeration").append("religions").build()); + } + + @Override + protected Command getCommandInstance(ComponentContainer container, StrolchTransaction tx) { + + List resources = new ArrayList<>(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/src/test/java/li/strolch/command/RemoveResourceCommandTest.java b/src/test/java/li/strolch/command/RemoveResourceCommandTest.java new file mode 100644 index 000000000..b55e2122e --- /dev/null +++ b/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() { + locator = Locator.newBuilder(Tags.RESOURCE).append("Enumeration").append("sex").build(); + } + + @Override + protected Command getCommandInstance(ComponentContainer container, StrolchTransaction tx) { + + Resource resource = tx.findElement(locator); + + RemoveResourceCommand command = new RemoveResourceCommand(container, tx); + command.setResource(resource); + return command; + } +} diff --git a/src/test/java/li/strolch/command/UpdateOrderCollectionCommandTest.java b/src/test/java/li/strolch/command/UpdateOrderCollectionCommandTest.java new file mode 100644 index 000000000..81b315c59 --- /dev/null +++ b/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() { + 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")); + } + + @Override + protected Command getCommandInstance(ComponentContainer container, StrolchTransaction tx) { + + UpdateOrderCollectionCommand command = new UpdateOrderCollectionCommand(container, tx); + command.setOrders(orders); + return command; + } +} diff --git a/src/test/java/li/strolch/command/UpdateOrderCommandTest.java b/src/test/java/li/strolch/command/UpdateOrderCommandTest.java new file mode 100644 index 000000000..25a01e21e --- /dev/null +++ b/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() { + order = ModelGenerator.createOrder("myCarOrder", "Modified Car Order", "ProductionOrder"); + } + + @Override + protected Command getCommandInstance(ComponentContainer container, StrolchTransaction tx) { + + UpdateOrderCommand command = new UpdateOrderCommand(container, tx); + command.setOrder(order); + return command; + } +} diff --git a/src/test/java/li/strolch/command/UpdateResourceCollectionCommandTest.java b/src/test/java/li/strolch/command/UpdateResourceCollectionCommandTest.java new file mode 100644 index 000000000..c2c576991 --- /dev/null +++ b/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() { + 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")); + } + + @Override + protected Command getCommandInstance(ComponentContainer container, StrolchTransaction tx) { + + UpdateResourceCollectionCommand command = new UpdateResourceCollectionCommand(container, tx); + command.setResources(resources); + return command; + } +} diff --git a/src/test/java/li/strolch/command/UpdateResourceCommandTest.java b/src/test/java/li/strolch/command/UpdateResourceCommandTest.java new file mode 100644 index 000000000..85156d5f8 --- /dev/null +++ b/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() { + resource = ModelGenerator.createResource("yellow", "Modified Yellow Ball", "Ball"); + } + + @Override + protected Command getCommandInstance(ComponentContainer container, StrolchTransaction tx) { + + UpdateResourceCommand command = new UpdateResourceCommand(container, tx); + command.setResource(resource); + return command; + } +} diff --git a/src/test/java/li/strolch/command/parameter/AddParameterCommandTest.java b/src/test/java/li/strolch/command/parameter/AddParameterCommandTest.java new file mode 100644 index 000000000..0c09e6592 --- /dev/null +++ b/src/test/java/li/strolch/command/parameter/AddParameterCommandTest.java @@ -0,0 +1,54 @@ +/* + * 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.command.parameter.AddParameterCommand; +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/parameters"); + this.parameter = new BooleanParameter("newParam", "New Param", false); + } + + @Override + protected Command getCommandInstance(ComponentContainer container, StrolchTransaction tx) { + + ParameterizedElement element = tx.findElement(locator); + + AddParameterCommand command = new AddParameterCommand(container, tx); + command.setElement(element); + command.setParameter(parameter); + return command; + } +} diff --git a/src/test/java/li/strolch/command/parameter/RemoveParameterCommandTest.java b/src/test/java/li/strolch/command/parameter/RemoveParameterCommandTest.java new file mode 100644 index 000000000..d55abfbb3 --- /dev/null +++ b/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/parameters"); + this.parameterId = "owner"; + } + + @Override + protected Command getCommandInstance(ComponentContainer container, StrolchTransaction tx) { + + ParameterizedElement element = tx.findElement(locator); + + RemoveParameterCommand command = new RemoveParameterCommand(container, tx); + command.setElement(element); + command.setParameterId(parameterId); + return command; + } +} diff --git a/src/test/java/li/strolch/command/parameter/SetParameterCommandTest.java b/src/test/java/li/strolch/command/parameter/SetParameterCommandTest.java new file mode 100644 index 000000000..623227b5a --- /dev/null +++ b/src/test/java/li/strolch/command/parameter/SetParameterCommandTest.java @@ -0,0 +1,52 @@ +/* + * 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.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.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/parameters/owner"); + this.valueAsString = "someOtherDude"; + } + + @Override + protected Command getCommandInstance(ComponentContainer container, StrolchTransaction tx) { + + Parameter parameter = tx.findElement(locator); + + SetParameterCommand command = new SetParameterCommand(container, tx); + command.setValueAsString(valueAsString); + command.setParameter(parameter); + return command; + } +} diff --git a/src/test/java/li/strolch/service/test/AbstractRealmServiceTest.java b/src/test/java/li/strolch/service/test/AbstractRealmServiceTest.java index 0125979ae..4e77aa7cf 100644 --- a/src/test/java/li/strolch/service/test/AbstractRealmServiceTest.java +++ b/src/test/java/li/strolch/service/test/AbstractRealmServiceTest.java @@ -41,11 +41,11 @@ import org.junit.Test; */ public abstract class AbstractRealmServiceTest { - protected static final String REALM_CACHED = "svcCached"; - protected static final String REALM_TRANSACTIONAL = "svcTransactional"; - protected static final String REALM_TRANSIENT = "svcTransient"; - protected static final String RUNTIME_PATH = "target/svcTestRuntime/"; //$NON-NLS-1$ - protected static final String CONFIG_SRC = "src/test/resources/svctest"; //$NON-NLS-1$ + 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; @@ -61,11 +61,16 @@ public abstract class AbstractRealmServiceTest { runtimeMock.mockRuntime(rootPath, configSrc); runtimeMock.startContainer(); - importFromXml(REALM_CACHED); - importFromXml(REALM_TRANSACTIONAL); + importFromXml(REALM_CACHED, getServiceHandler()); + importFromXml(REALM_TRANSACTIONAL, getServiceHandler()); } - private static void dropSchema(String dbUrl, String dbUsername, String dbPassword) throws SQLException { + @AfterClass + public static void afterClass() { + 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)) { @@ -73,13 +78,13 @@ public abstract class AbstractRealmServiceTest { } } - private static void importFromXml(String realm) { + public static void importFromXml(String realm, ServiceHandler serviceHandler) { XmlImportModelService svc = new XmlImportModelService(); XmlImportModelArgument arg = new XmlImportModelArgument(); arg.realm = realm; arg.modelFileName = "StrolchModel.xml"; - ServiceResult result = getServiceHandler().doService(null, svc, arg); + ServiceResult result = serviceHandler.doService(null, svc, arg); assertServiceResult(ServiceResultState.SUCCESS, ServiceResult.class, result); } @@ -91,24 +96,19 @@ public abstract class AbstractRealmServiceTest { assertServiceResult(expectedState, expectedServiceResultType, result); } - @AfterClass - public static void afterClass() { - runtimeMock.destroyRuntime(); - } - public static ServiceHandler getServiceHandler() { return runtimeMock.getContainer().getComponent(ServiceHandler.class); } - @Test - public void shouldPerformServiceTransient() { - doService(REALM_TRANSIENT, ServiceResultState.SUCCESS, ServiceResult.class, getSvc(), getArg()); - } - public abstract T getArg(); public abstract Service getSvc(); + @Test + public void shouldPerformServiceTransient() { + doService(REALM_TRANSIENT, ServiceResultState.SUCCESS, ServiceResult.class, getSvc(), getArg()); + } + @Test public void shouldPerformServiceCached() { doService(REALM_CACHED, ServiceResultState.SUCCESS, ServiceResult.class, getSvc(), getArg()); From 53ea7bc7de804c95996a6630bfec89ed26e4d800 Mon Sep 17 00:00:00 2001 From: Robert von Burg Date: Fri, 14 Mar 2014 14:37:06 +0100 Subject: [PATCH 45/65] [Project] fixed urls of projects --- pom.xml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pom.xml b/pom.xml index 338d30048..1d132c6e3 100644 --- a/pom.xml +++ b/pom.xml @@ -14,19 +14,19 @@ li.strolch.service Service API for Strolch - https://github.com/eitch/li.strolch.service + https://github.com/eitchnet/li.strolch.service 2011 Github Issues - https://github.com/eitch/li.strolch.service/issues + https://github.com/eitchnet/li.strolch.service/issues - scm:git:https://github.com/eitch/li.strolch.service.git + scm:git:https://github.com/eitchnet/li.strolch.service.git scm:git:git@github.com:eitch/li.strolch.service.git - https://github.com/eitch/li.strolch.service + https://github.com/eitchnet/li.strolch.service From ac8c76868aeb753b0df231cdc5003d31a22233ea Mon Sep 17 00:00:00 2001 From: Robert von Burg Date: Thu, 27 Mar 2014 18:53:32 +0100 Subject: [PATCH 46/65] [Minor] added more debugging when exporting This is useful for long running exports --- .../command/XmlExportModelCommand.java | 22 ++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/src/main/java/li/strolch/command/XmlExportModelCommand.java b/src/main/java/li/strolch/command/XmlExportModelCommand.java index 6dee62320..62f56ce49 100644 --- a/src/main/java/li/strolch/command/XmlExportModelCommand.java +++ b/src/main/java/li/strolch/command/XmlExportModelCommand.java @@ -24,6 +24,7 @@ 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; @@ -55,6 +56,7 @@ import ch.eitchnet.utils.dbc.DBC; public class XmlExportModelCommand extends Command { public static final String XML_FILE_SUFFIX = ".xml"; + private static final long LOG_INTERVAL = TimeUnit.SECONDS.toMillis(1); // input private File modelFile; @@ -67,9 +69,12 @@ public class XmlExportModelCommand extends Command { private XmlModelStatistics statistics; private boolean multiFile; + private int elementsToWrite; private int nrOfResourcesToExport; private int nrOfOrdersToExport; + private long nextLogTime; + public XmlExportModelCommand(ComponentContainer container, StrolchTransaction tx) { super(container, tx); } @@ -82,6 +87,7 @@ public class XmlExportModelCommand extends Command { @Override public void doCommand() { + this.nextLogTime = System.currentTimeMillis() + LOG_INTERVAL; String fileName = this.modelFile.getName(); long start = System.nanoTime(); @@ -99,7 +105,6 @@ public class XmlExportModelCommand extends Command { for (String type : resourceTypesToExport) { nrOfResourcesToExport += resourceMap.querySize(tx(), type); } - logger.info("Exporting " + nrOfResourcesToExport + " Resources..."); } if (this.doOrders) { @@ -111,10 +116,12 @@ public class XmlExportModelCommand extends Command { for (String type : orderTypesToExport) { nrOfOrdersToExport += orderMap.querySize(tx(), type); } - logger.info("Exporting " + nrOfOrdersToExport + " Orders..."); } - logger.info("Exporting " + (nrOfResourcesToExport + nrOfOrdersToExport) + " Elements..."); + this.elementsToWrite = nrOfResourcesToExport + nrOfOrdersToExport; + logger.info("Exporting " + elementsToWrite + " Elements..."); + logger.info("Exporting " + nrOfResourcesToExport + " Resources..."); + logger.info("Exporting " + nrOfOrdersToExport + " Orders..."); try (FileOutputStream out = new FileOutputStream(this.modelFile)) { createdFiles.add(this.modelFile); @@ -212,6 +219,14 @@ public class XmlExportModelCommand extends Command { 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; } } @@ -222,6 +237,7 @@ public class XmlExportModelCommand extends Command { Resource resource = resourceMap.getBy(tx(), type, id); visitor.visit(resource); this.statistics.nrOfResources++; + logElementsWritten(); } } From ff9b864ee90a5683450e0cef213c3984f6afef1b Mon Sep 17 00:00:00 2001 From: Robert von Burg Date: Fri, 28 Mar 2014 18:43:31 +0100 Subject: [PATCH 47/65] [Minor] only log message every 10 seconds when exporting XML model --- src/main/java/li/strolch/command/XmlExportModelCommand.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/li/strolch/command/XmlExportModelCommand.java b/src/main/java/li/strolch/command/XmlExportModelCommand.java index 62f56ce49..b5e2c300f 100644 --- a/src/main/java/li/strolch/command/XmlExportModelCommand.java +++ b/src/main/java/li/strolch/command/XmlExportModelCommand.java @@ -56,7 +56,7 @@ import ch.eitchnet.utils.dbc.DBC; public class XmlExportModelCommand extends Command { public static final String XML_FILE_SUFFIX = ".xml"; - private static final long LOG_INTERVAL = TimeUnit.SECONDS.toMillis(1); + private static final long LOG_INTERVAL = TimeUnit.SECONDS.toMillis(10); // input private File modelFile; From f12d731145237748d6aeeb7703143e8012cbd317 Mon Sep 17 00:00:00 2001 From: Robert von Burg Date: Fri, 13 Jun 2014 17:53:42 +0200 Subject: [PATCH 48/65] [Minor] documenting how to run tests by adding user for postgresql --- README.md | 21 ++++++++++++++++++ .../svctest/config/StrolchConfiguration.xml | 22 ------------------- 2 files changed, 21 insertions(+), 22 deletions(-) diff --git a/README.md b/README.md index 94a8d96bb..1cdf15eff 100644 --- a/README.md +++ b/README.md @@ -4,3 +4,24 @@ 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; + +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/src/test/resources/svctest/config/StrolchConfiguration.xml b/src/test/resources/svctest/config/StrolchConfiguration.xml index 2c35ebaad..85ca1805d 100644 --- a/src/test/resources/svctest/config/StrolchConfiguration.xml +++ b/src/test/resources/svctest/config/StrolchConfiguration.xml @@ -45,28 +45,6 @@ transactionaluser test - - From 40de765eca381f72343287dde56117695939e136 Mon Sep 17 00:00:00 2001 From: Robert von Burg Date: Fri, 13 Jun 2014 18:12:35 +0200 Subject: [PATCH 49/65] [Minor] documenting how to run tests by adding user for postgresql --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 1cdf15eff..fd16544bf 100644 --- a/README.md +++ b/README.md @@ -18,6 +18,7 @@ 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; From 14d9c66a787ad395da632e6da239388493a0003e Mon Sep 17 00:00:00 2001 From: Robert von Burg Date: Thu, 31 Jul 2014 16:12:31 +0200 Subject: [PATCH 50/65] [Major] added ClearModelCommand and Service --- .../li/strolch/command/ClearModelCommand.java | 95 +++++++++++++++++++ .../command/XmlExportModelCommand.java | 8 +- .../command/XmlImportModelCommand.java | 6 +- .../strolch/service/ClearModelArgument.java | 25 +++++ .../li/strolch/service/ClearModelService.java | 60 ++++++++++++ .../service/XmlExportModelService.java | 4 +- .../service/XmlImportModelService.java | 4 +- 7 files changed, 191 insertions(+), 11 deletions(-) create mode 100644 src/main/java/li/strolch/command/ClearModelCommand.java create mode 100644 src/main/java/li/strolch/service/ClearModelArgument.java create mode 100644 src/main/java/li/strolch/service/ClearModelService.java diff --git a/src/main/java/li/strolch/command/ClearModelCommand.java b/src/main/java/li/strolch/command/ClearModelCommand.java new file mode 100644 index 000000000..f2d935c9b --- /dev/null +++ b/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/src/main/java/li/strolch/command/XmlExportModelCommand.java b/src/main/java/li/strolch/command/XmlExportModelCommand.java index b5e2c300f..ff8edaaf7 100644 --- a/src/main/java/li/strolch/command/XmlExportModelCommand.java +++ b/src/main/java/li/strolch/command/XmlExportModelCommand.java @@ -37,6 +37,7 @@ 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; @@ -44,7 +45,6 @@ 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.model.xml.XmlModelSaxReader.XmlModelStatistics; import li.strolch.persistence.api.StrolchTransaction; import li.strolch.runtime.StrolchConstants; import li.strolch.service.api.Command; @@ -66,7 +66,7 @@ public class XmlExportModelCommand extends Command { private Set resourceTypes; // output - private XmlModelStatistics statistics; + private ModelStatistics statistics; private boolean multiFile; private int elementsToWrite; @@ -91,7 +91,7 @@ public class XmlExportModelCommand extends Command { String fileName = this.modelFile.getName(); long start = System.nanoTime(); - this.statistics = new XmlModelStatistics(); + this.statistics = new ModelStatistics(); this.statistics.startTime = new Date(); String exportName = fileName.substring(0, fileName.indexOf(XML_FILE_SUFFIX)); @@ -303,7 +303,7 @@ public class XmlExportModelCommand extends Command { /** * @return the statistics */ - public XmlModelStatistics getStatistics() { + public ModelStatistics getStatistics() { return this.statistics; } } diff --git a/src/main/java/li/strolch/command/XmlImportModelCommand.java b/src/main/java/li/strolch/command/XmlImportModelCommand.java index b89798b75..cba03a295 100644 --- a/src/main/java/li/strolch/command/XmlImportModelCommand.java +++ b/src/main/java/li/strolch/command/XmlImportModelCommand.java @@ -20,8 +20,8 @@ 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.model.xml.XmlModelSaxReader.XmlModelStatistics; import li.strolch.persistence.api.StrolchTransaction; import li.strolch.service.api.Command; import ch.eitchnet.utils.dbc.DBC; @@ -41,7 +41,7 @@ public class XmlImportModelCommand extends Command { private Set resourceTypes; // output - private XmlModelStatistics statistics; + private ModelStatistics statistics; /** * @param container @@ -137,7 +137,7 @@ public class XmlImportModelCommand extends Command { /** * @return the statistics */ - public XmlModelStatistics getStatistics() { + public ModelStatistics getStatistics() { return this.statistics; } } diff --git a/src/main/java/li/strolch/service/ClearModelArgument.java b/src/main/java/li/strolch/service/ClearModelArgument.java new file mode 100644 index 000000000..6dd57b921 --- /dev/null +++ b/src/main/java/li/strolch/service/ClearModelArgument.java @@ -0,0 +1,25 @@ +/* + * 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 = true; + public boolean clearResources = true; +} \ No newline at end of file diff --git a/src/main/java/li/strolch/service/ClearModelService.java b/src/main/java/li/strolch/service/ClearModelService.java new file mode 100644 index 000000000..3f73a93ef --- /dev/null +++ b/src/main/java/li/strolch/service/ClearModelService.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; + +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 {1} took {2}.", 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/src/main/java/li/strolch/service/XmlExportModelService.java b/src/main/java/li/strolch/service/XmlExportModelService.java index bc501925f..6d8ea7418 100644 --- a/src/main/java/li/strolch/service/XmlExportModelService.java +++ b/src/main/java/li/strolch/service/XmlExportModelService.java @@ -20,7 +20,7 @@ import java.text.MessageFormat; import li.strolch.command.XmlExportModelCommand; import li.strolch.exception.StrolchException; -import li.strolch.model.xml.XmlModelSaxReader.XmlModelStatistics; +import li.strolch.model.ModelStatistics; import li.strolch.persistence.api.StrolchTransaction; import li.strolch.service.api.AbstractService; import li.strolch.service.api.ServiceResult; @@ -67,7 +67,7 @@ public class XmlExportModelService extends AbstractService Date: Thu, 31 Jul 2014 16:34:58 +0200 Subject: [PATCH 51/65] [New] Added ClearModelServiceTest --- .../service/ClearModelServiceTest.java | 52 +++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 src/test/java/li/strolch/service/ClearModelServiceTest.java diff --git a/src/test/java/li/strolch/service/ClearModelServiceTest.java b/src/test/java/li/strolch/service/ClearModelServiceTest.java new file mode 100644 index 000000000..e89041802 --- /dev/null +++ b/src/test/java/li/strolch/service/ClearModelServiceTest.java @@ -0,0 +1,52 @@ +/* + * 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.Service; +import li.strolch.service.api.ServiceArgument; +import li.strolch.service.api.ServiceResult; +import li.strolch.service.test.AbstractRealmServiceTest; + +import org.junit.Before; + +/** + * @author Robert von Burg + */ +public class ClearModelServiceTest extends AbstractRealmServiceTest { + + private ClearModelService svc; + private ClearModelArgument arg; + + @Before + public void before() { + svc = new ClearModelService(); + arg = new ClearModelArgument(); + arg.clearOrders = true; + arg.clearResources = true; + } + + @Override + @SuppressWarnings("unchecked") + public T getArg() { + return (T) this.arg; + } + + @Override + @SuppressWarnings("unchecked") + public Service getSvc() { + return (Service) this.svc; + } +} From b1622eab478674e91aadd5f8dd20f38dc4e9994d Mon Sep 17 00:00:00 2001 From: Robert von Burg Date: Thu, 31 Jul 2014 17:02:11 +0200 Subject: [PATCH 52/65] [Major] refactored Service tests for easier re-use It is now also very easy to inject a before, after and validator to validate the services execution --- .../li/strolch/service/ClearModelService.java | 3 +- .../AddOrderCollectionServiceTest.java | 30 ++----- .../strolch/service/AddOrderServiceTest.java | 27 ++----- .../AddResourceCollectionServiceTest.java | 30 ++----- .../service/AddResourceServiceTest.java | 27 ++----- .../service/ClearModelServiceTest.java | 79 ++++++++++++++----- .../RemoveOrderCollectionServiceTest.java | 30 ++----- .../service/RemoveOrderServiceTest.java | 27 ++----- .../RemoveResourceCollectionServiceTest.java | 31 ++------ .../service/RemoveResourceServiceTest.java | 27 ++----- .../UpdateOrderCollectionServiceTest.java | 31 ++------ .../service/UpdateOrderServiceTest.java | 27 ++----- .../UpdateResourceCollectionServiceTest.java | 32 ++------ .../service/UpdateResourceServiceTest.java | 27 ++----- .../service/XmlExportModelServiceTest.java | 47 +++++------ .../service/XmlImportModelServiceTest.java | 29 ++----- .../test/AbstractRealmServiceTest.java | 67 +++++++++++----- .../parameter/AddParameterServiceTest.java | 30 ++----- .../parameter/RemoveParameterServiceTest.java | 27 ++----- .../parameter/SetParameterServiceTest.java | 27 ++----- 20 files changed, 230 insertions(+), 425 deletions(-) diff --git a/src/main/java/li/strolch/service/ClearModelService.java b/src/main/java/li/strolch/service/ClearModelService.java index 3f73a93ef..ed455660a 100644 --- a/src/main/java/li/strolch/service/ClearModelService.java +++ b/src/main/java/li/strolch/service/ClearModelService.java @@ -50,8 +50,7 @@ public class ClearModelService extends AbstractService */ public class AddOrderCollectionServiceTest extends AbstractRealmServiceTest { - private AddOrderCollectionService svc; - private AddOrderCollectionArg arg; - private ArrayList orders; + @Test + public void runTest() { - @Before - public void before() { - svc = new AddOrderCollectionService(); - arg = new AddOrderCollectionArg(); + AddOrderCollectionService svc = new AddOrderCollectionService(); + AddOrderCollectionArg arg = new AddOrderCollectionArg(); - orders = new ArrayList<>(); + 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; - } - @Override - @SuppressWarnings("unchecked") - public T getArg() { - return (T) this.arg; - } - - @Override - @SuppressWarnings("unchecked") - public Service getSvc() { - return (Service) this.svc; + runServiceInAllRealmTypes(svc, arg); } } diff --git a/src/test/java/li/strolch/service/AddOrderServiceTest.java b/src/test/java/li/strolch/service/AddOrderServiceTest.java index 11cfae90a..84ec6e38d 100644 --- a/src/test/java/li/strolch/service/AddOrderServiceTest.java +++ b/src/test/java/li/strolch/service/AddOrderServiceTest.java @@ -17,37 +17,22 @@ package li.strolch.service; import li.strolch.model.ModelGenerator; import li.strolch.service.AddOrderService.AddOrderArg; -import li.strolch.service.api.Service; -import li.strolch.service.api.ServiceArgument; -import li.strolch.service.api.ServiceResult; import li.strolch.service.test.AbstractRealmServiceTest; -import org.junit.Before; +import org.junit.Test; /** * @author Robert von Burg */ public class AddOrderServiceTest extends AbstractRealmServiceTest { - private AddOrderService svc; - private AddOrderArg arg; + @Test + public void runTest() { - @Before - public void before() { - svc = new AddOrderService(); - arg = new AddOrderArg(); + AddOrderService svc = new AddOrderService(); + AddOrderArg arg = new AddOrderArg(); arg.order = ModelGenerator.createOrder("firstOrder", "First Order", "AdditionalOrders"); - } - @Override - @SuppressWarnings("unchecked") - public T getArg() { - return (T) this.arg; - } - - @Override - @SuppressWarnings("unchecked") - public Service getSvc() { - return (Service) this.svc; + runServiceInAllRealmTypes(svc, arg); } } diff --git a/src/test/java/li/strolch/service/AddResourceCollectionServiceTest.java b/src/test/java/li/strolch/service/AddResourceCollectionServiceTest.java index aa3f8716a..3e9943797 100644 --- a/src/test/java/li/strolch/service/AddResourceCollectionServiceTest.java +++ b/src/test/java/li/strolch/service/AddResourceCollectionServiceTest.java @@ -20,44 +20,28 @@ import java.util.ArrayList; import li.strolch.model.ModelGenerator; import li.strolch.model.Resource; import li.strolch.service.AddResourceCollectionService.AddResourceCollectionArg; -import li.strolch.service.api.Service; -import li.strolch.service.api.ServiceArgument; -import li.strolch.service.api.ServiceResult; import li.strolch.service.test.AbstractRealmServiceTest; -import org.junit.Before; +import org.junit.Test; /** * @author Robert von Burg */ public class AddResourceCollectionServiceTest extends AbstractRealmServiceTest { - private AddResourceCollectionService svc; - private AddResourceCollectionArg arg; - private ArrayList resources; + @Test + public void runTest() { - @Before - public void before() { - svc = new AddResourceCollectionService(); - arg = new AddResourceCollectionArg(); + AddResourceCollectionService svc = new AddResourceCollectionService(); + AddResourceCollectionArg arg = new AddResourceCollectionArg(); - resources = new ArrayList<>(); + 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; - } - @Override - @SuppressWarnings("unchecked") - public T getArg() { - return (T) this.arg; - } - - @Override - @SuppressWarnings("unchecked") - public Service getSvc() { - return (Service) this.svc; + runServiceInAllRealmTypes(svc, arg); } } diff --git a/src/test/java/li/strolch/service/AddResourceServiceTest.java b/src/test/java/li/strolch/service/AddResourceServiceTest.java index d8646c286..1f4e131ce 100644 --- a/src/test/java/li/strolch/service/AddResourceServiceTest.java +++ b/src/test/java/li/strolch/service/AddResourceServiceTest.java @@ -17,37 +17,22 @@ package li.strolch.service; import li.strolch.model.ModelGenerator; import li.strolch.service.AddResourceService.AddResourceArg; -import li.strolch.service.api.Service; -import li.strolch.service.api.ServiceArgument; -import li.strolch.service.api.ServiceResult; import li.strolch.service.test.AbstractRealmServiceTest; -import org.junit.Before; +import org.junit.Test; /** * @author Robert von Burg */ public class AddResourceServiceTest extends AbstractRealmServiceTest { - private AddResourceService svc; - private AddResourceArg arg; + @Test + public void runTest() { - @Before - public void before() { - svc = new AddResourceService(); - arg = new AddResourceArg(); + AddResourceService svc = new AddResourceService(); + AddResourceArg arg = new AddResourceArg(); arg.resource = ModelGenerator.createResource("firstRes", "First Resource", "AdditionalResources"); - } - @Override - @SuppressWarnings("unchecked") - public T getArg() { - return (T) this.arg; - } - - @Override - @SuppressWarnings("unchecked") - public Service getSvc() { - return (Service) this.svc; + runServiceInAllRealmTypes(svc, arg); } } diff --git a/src/test/java/li/strolch/service/ClearModelServiceTest.java b/src/test/java/li/strolch/service/ClearModelServiceTest.java index e89041802..d3d291da4 100644 --- a/src/test/java/li/strolch/service/ClearModelServiceTest.java +++ b/src/test/java/li/strolch/service/ClearModelServiceTest.java @@ -15,38 +15,81 @@ */ package li.strolch.service; -import li.strolch.service.api.Service; -import li.strolch.service.api.ServiceArgument; -import li.strolch.service.api.ServiceResult; +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.Before; +import org.junit.Test; /** * @author Robert von Burg */ public class ClearModelServiceTest extends AbstractRealmServiceTest { - private ClearModelService svc; - private ClearModelArgument arg; + @Test + public void runClearTest() { - @Before - public void before() { - svc = new ClearModelService(); - arg = new ClearModelArgument(); + Runner validator = new Runner() { + @Override + public void run(StrolchRealm strolchRealm, ComponentContainer container) { + try (StrolchTransaction tx = strolchRealm.openTx()) { + assertEquals(0, tx.getResourceMap().querySize(tx)); + assertEquals(0, tx.getOrderMap().querySize(tx)); + } + } + }; + + ClearModelService svc = new ClearModelService(); + ClearModelArgument arg = new ClearModelArgument(); arg.clearOrders = true; arg.clearResources = true; + + runServiceInAllRealmTypes(svc, arg, null, validator, null); } - @Override - @SuppressWarnings("unchecked") - public T getArg() { - return (T) this.arg; + @Test + public void runClearOnlyOrdersTest() { + + Runner validator = new Runner() { + @Override + public void run(StrolchRealm strolchRealm, ComponentContainer container) { + try (StrolchTransaction tx = strolchRealm.openTx()) { + assertNotEquals(0, tx.getResourceMap().querySize(tx)); + assertEquals(0, tx.getOrderMap().querySize(tx)); + } + } + }; + + ClearModelService svc = new ClearModelService(); + ClearModelArgument arg = new ClearModelArgument(); + arg.clearOrders = true; + arg.clearResources = false; + + runServiceInAllRealmTypes(svc, arg, null, validator, null); } - @Override - @SuppressWarnings("unchecked") - public Service getSvc() { - return (Service) this.svc; + @Test + public void runClearOnlyResourcesTest() { + + Runner validator = new Runner() { + @Override + public void run(StrolchRealm strolchRealm, ComponentContainer container) { + try (StrolchTransaction tx = strolchRealm.openTx()) { + assertNotEquals(0, tx.getOrderMap().querySize(tx)); + assertEquals(0, tx.getResourceMap().querySize(tx)); + } + } + }; + + ClearModelService svc = new ClearModelService(); + ClearModelArgument arg = new ClearModelArgument(); + arg.clearOrders = false; + arg.clearResources = true; + + runServiceInAllRealmTypes(svc, arg, null, validator, null); } + } diff --git a/src/test/java/li/strolch/service/RemoveOrderCollectionServiceTest.java b/src/test/java/li/strolch/service/RemoveOrderCollectionServiceTest.java index 5af7de9d7..09cec4633 100644 --- a/src/test/java/li/strolch/service/RemoveOrderCollectionServiceTest.java +++ b/src/test/java/li/strolch/service/RemoveOrderCollectionServiceTest.java @@ -20,44 +20,28 @@ import java.util.ArrayList; import li.strolch.model.Locator; import li.strolch.model.Tags; import li.strolch.service.RemoveOrderCollectionService.RemoveOrderCollectionArg; -import li.strolch.service.api.Service; -import li.strolch.service.api.ServiceArgument; -import li.strolch.service.api.ServiceResult; import li.strolch.service.test.AbstractRealmServiceTest; -import org.junit.Before; +import org.junit.Test; /** * @author Robert von Burg */ public class RemoveOrderCollectionServiceTest extends AbstractRealmServiceTest { - private RemoveOrderCollectionService svc; - private RemoveOrderCollectionArg arg; - private ArrayList locators; + @Test + public void runTest() { - @Before - public void before() { - svc = new RemoveOrderCollectionService(); - arg = new RemoveOrderCollectionArg(); + RemoveOrderCollectionService svc = new RemoveOrderCollectionService(); + RemoveOrderCollectionArg arg = new RemoveOrderCollectionArg(); - locators = new ArrayList<>(); + ArrayList locators = new ArrayList<>(); locators.add(Locator.newBuilder(Tags.ORDER).append("TestType").append("@1").build()); locators.add(Locator.newBuilder(Tags.ORDER).append("TestType").append("@2").build()); locators.add(Locator.newBuilder(Tags.ORDER).append("TestType").append("@3").build()); arg.locators = locators; - } - @Override - @SuppressWarnings("unchecked") - public T getArg() { - return (T) this.arg; - } - - @Override - @SuppressWarnings("unchecked") - public Service getSvc() { - return (Service) this.svc; + runServiceInAllRealmTypes(svc, arg); } } diff --git a/src/test/java/li/strolch/service/RemoveOrderServiceTest.java b/src/test/java/li/strolch/service/RemoveOrderServiceTest.java index afcefc4e8..3c2fd97f3 100644 --- a/src/test/java/li/strolch/service/RemoveOrderServiceTest.java +++ b/src/test/java/li/strolch/service/RemoveOrderServiceTest.java @@ -18,37 +18,22 @@ package li.strolch.service; import li.strolch.model.Locator; import li.strolch.model.Tags; import li.strolch.service.RemoveOrderService.RemoveOrderArg; -import li.strolch.service.api.Service; -import li.strolch.service.api.ServiceArgument; -import li.strolch.service.api.ServiceResult; import li.strolch.service.test.AbstractRealmServiceTest; -import org.junit.Before; +import org.junit.Test; /** * @author Robert von Burg */ public class RemoveOrderServiceTest extends AbstractRealmServiceTest { - private RemoveOrderService svc; - private RemoveOrderArg arg; + @Test + public void runTest() { - @Before - public void before() { - svc = new RemoveOrderService(); - arg = new RemoveOrderArg(); + RemoveOrderService svc = new RemoveOrderService(); + RemoveOrderArg arg = new RemoveOrderArg(); arg.locator = Locator.newBuilder(Tags.ORDER).append("TestType").append("@3").build(); - } - @Override - @SuppressWarnings("unchecked") - public T getArg() { - return (T) this.arg; - } - - @Override - @SuppressWarnings("unchecked") - public Service getSvc() { - return (Service) this.svc; + runServiceInAllRealmTypes(svc, arg); } } diff --git a/src/test/java/li/strolch/service/RemoveResourceCollectionServiceTest.java b/src/test/java/li/strolch/service/RemoveResourceCollectionServiceTest.java index cbb2bfad2..149d19411 100644 --- a/src/test/java/li/strolch/service/RemoveResourceCollectionServiceTest.java +++ b/src/test/java/li/strolch/service/RemoveResourceCollectionServiceTest.java @@ -16,49 +16,32 @@ package li.strolch.service; import java.util.ArrayList; -import java.util.List; import li.strolch.model.Locator; import li.strolch.model.Tags; import li.strolch.service.RemoveResourceCollectionService.RemoveResourceCollectionArg; -import li.strolch.service.api.Service; -import li.strolch.service.api.ServiceArgument; -import li.strolch.service.api.ServiceResult; import li.strolch.service.test.AbstractRealmServiceTest; -import org.junit.Before; +import org.junit.Test; /** * @author Robert von Burg */ public class RemoveResourceCollectionServiceTest extends AbstractRealmServiceTest { - private RemoveResourceCollectionService svc; - private RemoveResourceCollectionArg arg; - private List locators; + @Test + public void runTest() { - @Before - public void before() { - svc = new RemoveResourceCollectionService(); - arg = new RemoveResourceCollectionArg(); + RemoveResourceCollectionService svc = new RemoveResourceCollectionService(); + RemoveResourceCollectionArg arg = new RemoveResourceCollectionArg(); - locators = new ArrayList<>(); + ArrayList locators = new ArrayList<>(); locators.add(Locator.newBuilder(Tags.RESOURCE).append("Enumeration").append("salutations").build()); locators.add(Locator.newBuilder(Tags.RESOURCE).append("Enumeration").append("sex").build()); locators.add(Locator.newBuilder(Tags.RESOURCE).append("Enumeration").append("religions").build()); arg.locators = locators; - } - @Override - @SuppressWarnings("unchecked") - public T getArg() { - return (T) this.arg; - } - - @Override - @SuppressWarnings("unchecked") - public Service getSvc() { - return (Service) this.svc; + runServiceInAllRealmTypes(svc, arg); } } diff --git a/src/test/java/li/strolch/service/RemoveResourceServiceTest.java b/src/test/java/li/strolch/service/RemoveResourceServiceTest.java index 98ce143a8..61bc612cf 100644 --- a/src/test/java/li/strolch/service/RemoveResourceServiceTest.java +++ b/src/test/java/li/strolch/service/RemoveResourceServiceTest.java @@ -18,37 +18,22 @@ package li.strolch.service; import li.strolch.model.Locator; import li.strolch.model.Tags; import li.strolch.service.RemoveResourceService.RemoveResourceArg; -import li.strolch.service.api.Service; -import li.strolch.service.api.ServiceArgument; -import li.strolch.service.api.ServiceResult; import li.strolch.service.test.AbstractRealmServiceTest; -import org.junit.Before; +import org.junit.Test; /** * @author Robert von Burg */ public class RemoveResourceServiceTest extends AbstractRealmServiceTest { - private RemoveResourceService svc; - private RemoveResourceArg arg; + @Test + public void runTest() { - @Before - public void before() { - svc = new RemoveResourceService(); - arg = new RemoveResourceArg(); + RemoveResourceService svc = new RemoveResourceService(); + RemoveResourceArg arg = new RemoveResourceArg(); arg.locator = Locator.newBuilder(Tags.RESOURCE).append("Enumeration").append("sex").build(); - } - @Override - @SuppressWarnings("unchecked") - public T getArg() { - return (T) this.arg; - } - - @Override - @SuppressWarnings("unchecked") - public Service getSvc() { - return (Service) this.svc; + runServiceInAllRealmTypes(svc, arg); } } diff --git a/src/test/java/li/strolch/service/UpdateOrderCollectionServiceTest.java b/src/test/java/li/strolch/service/UpdateOrderCollectionServiceTest.java index 94ef7f2d0..f759184b9 100644 --- a/src/test/java/li/strolch/service/UpdateOrderCollectionServiceTest.java +++ b/src/test/java/li/strolch/service/UpdateOrderCollectionServiceTest.java @@ -21,45 +21,28 @@ import java.util.List; import li.strolch.model.ModelGenerator; import li.strolch.model.Order; import li.strolch.service.UpdateOrderCollectionService.UpdateOrderCollectionArg; -import li.strolch.service.api.Service; -import li.strolch.service.api.ServiceArgument; -import li.strolch.service.api.ServiceResult; import li.strolch.service.test.AbstractRealmServiceTest; -import org.junit.Before; +import org.junit.Test; /** * @author Robert von Burg */ public class UpdateOrderCollectionServiceTest extends AbstractRealmServiceTest { - private UpdateOrderCollectionService svc; - private UpdateOrderCollectionArg arg; + @Test + public void runTest() { - private List orders; + UpdateOrderCollectionService svc = new UpdateOrderCollectionService(); + UpdateOrderCollectionArg arg = new UpdateOrderCollectionArg(); - @Before - public void before() { - svc = new UpdateOrderCollectionService(); - arg = new UpdateOrderCollectionArg(); - - orders = new ArrayList<>(); + 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; - } - @Override - @SuppressWarnings("unchecked") - public T getArg() { - return (T) this.arg; - } - - @Override - @SuppressWarnings("unchecked") - public Service getSvc() { - return (Service) this.svc; + runServiceInAllRealmTypes(svc, arg); } } diff --git a/src/test/java/li/strolch/service/UpdateOrderServiceTest.java b/src/test/java/li/strolch/service/UpdateOrderServiceTest.java index 0b5108add..8d8ac54de 100644 --- a/src/test/java/li/strolch/service/UpdateOrderServiceTest.java +++ b/src/test/java/li/strolch/service/UpdateOrderServiceTest.java @@ -17,37 +17,22 @@ package li.strolch.service; import li.strolch.model.ModelGenerator; import li.strolch.service.UpdateOrderService.UpdateOrderArg; -import li.strolch.service.api.Service; -import li.strolch.service.api.ServiceArgument; -import li.strolch.service.api.ServiceResult; import li.strolch.service.test.AbstractRealmServiceTest; -import org.junit.Before; +import org.junit.Test; /** * @author Robert von Burg */ public class UpdateOrderServiceTest extends AbstractRealmServiceTest { - private UpdateOrderService svc; - private UpdateOrderArg arg; + @Test + public void runTest() { - @Before - public void before() { - svc = new UpdateOrderService(); - arg = new UpdateOrderArg(); + UpdateOrderService svc = new UpdateOrderService(); + UpdateOrderArg arg = new UpdateOrderArg(); arg.order = ModelGenerator.createOrder("myCarOrder", "Modified Car Order", "ProductionOrder"); - } - @Override - @SuppressWarnings("unchecked") - public T getArg() { - return (T) this.arg; - } - - @Override - @SuppressWarnings("unchecked") - public Service getSvc() { - return (Service) this.svc; + runServiceInAllRealmTypes(svc, arg); } } diff --git a/src/test/java/li/strolch/service/UpdateResourceCollectionServiceTest.java b/src/test/java/li/strolch/service/UpdateResourceCollectionServiceTest.java index 9ad7c3edc..a8ff7ed23 100644 --- a/src/test/java/li/strolch/service/UpdateResourceCollectionServiceTest.java +++ b/src/test/java/li/strolch/service/UpdateResourceCollectionServiceTest.java @@ -16,50 +16,32 @@ package li.strolch.service; import java.util.ArrayList; -import java.util.List; import li.strolch.model.ModelGenerator; import li.strolch.model.Resource; import li.strolch.service.UpdateResourceCollectionService.UpdateResourceCollectionArg; -import li.strolch.service.api.Service; -import li.strolch.service.api.ServiceArgument; -import li.strolch.service.api.ServiceResult; import li.strolch.service.test.AbstractRealmServiceTest; -import org.junit.Before; +import org.junit.Test; /** * @author Robert von Burg */ public class UpdateResourceCollectionServiceTest extends AbstractRealmServiceTest { - private UpdateResourceCollectionService svc; - private UpdateResourceCollectionArg arg; + @Test + public void runTest() { - private List resources; + UpdateResourceCollectionService svc = new UpdateResourceCollectionService(); + UpdateResourceCollectionArg arg = new UpdateResourceCollectionArg(); - @Before - public void before() { - svc = new UpdateResourceCollectionService(); - arg = new UpdateResourceCollectionArg(); - - resources = new ArrayList<>(); + 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; - } - @Override - @SuppressWarnings("unchecked") - public T getArg() { - return (T) this.arg; - } - - @Override - @SuppressWarnings("unchecked") - public Service getSvc() { - return (Service) this.svc; + runServiceInAllRealmTypes(svc, arg); } } diff --git a/src/test/java/li/strolch/service/UpdateResourceServiceTest.java b/src/test/java/li/strolch/service/UpdateResourceServiceTest.java index 7fde7735d..526d20b5e 100644 --- a/src/test/java/li/strolch/service/UpdateResourceServiceTest.java +++ b/src/test/java/li/strolch/service/UpdateResourceServiceTest.java @@ -17,37 +17,22 @@ package li.strolch.service; import li.strolch.model.ModelGenerator; import li.strolch.service.UpdateResourceService.UpdateResourceArg; -import li.strolch.service.api.Service; -import li.strolch.service.api.ServiceArgument; -import li.strolch.service.api.ServiceResult; import li.strolch.service.test.AbstractRealmServiceTest; -import org.junit.Before; +import org.junit.Test; /** * @author Robert von Burg */ public class UpdateResourceServiceTest extends AbstractRealmServiceTest { - private UpdateResourceService svc; - private UpdateResourceArg arg; + @Test + public void runTest() { - @Before - public void before() { - svc = new UpdateResourceService(); - arg = new UpdateResourceArg(); + UpdateResourceService svc = new UpdateResourceService(); + UpdateResourceArg arg = new UpdateResourceArg(); arg.resource = ModelGenerator.createResource("yellow", "Modified Yellow Ball", "Ball"); - } - @Override - @SuppressWarnings("unchecked") - public T getArg() { - return (T) this.arg; - } - - @Override - @SuppressWarnings("unchecked") - public Service getSvc() { - return (Service) this.svc; + runServiceInAllRealmTypes(svc, arg); } } diff --git a/src/test/java/li/strolch/service/XmlExportModelServiceTest.java b/src/test/java/li/strolch/service/XmlExportModelServiceTest.java index 56d778a08..68bc89c17 100644 --- a/src/test/java/li/strolch/service/XmlExportModelServiceTest.java +++ b/src/test/java/li/strolch/service/XmlExportModelServiceTest.java @@ -17,13 +17,11 @@ package li.strolch.service; import java.io.File; -import li.strolch.service.api.Service; -import li.strolch.service.api.ServiceArgument; -import li.strolch.service.api.ServiceResult; +import li.strolch.agent.api.ComponentContainer; +import li.strolch.agent.api.StrolchRealm; import li.strolch.service.test.AbstractRealmServiceTest; -import org.junit.After; -import org.junit.Before; +import org.junit.Test; /** * @author Robert von Burg @@ -31,32 +29,23 @@ import org.junit.Before; public class XmlExportModelServiceTest extends AbstractRealmServiceTest { private static final String TMP_XML_EXPORT_XML = "tmpXmlExport.xml"; - private XmlExportModelService svc; - private XmlExportModelArgument arg; - @Before - public void before() { - svc = new XmlExportModelService(); - arg = new XmlExportModelArgument(); + @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(); + } + }; + + XmlExportModelService svc = new XmlExportModelService(); + XmlExportModelArgument arg = new XmlExportModelArgument(); arg.modelFileName = TMP_XML_EXPORT_XML; - } - @After - public void after() { - File file = new File(RUNTIME_PATH + "/data", TMP_XML_EXPORT_XML); - if (file.exists()) - file.delete(); - } - - @Override - @SuppressWarnings("unchecked") - public T getArg() { - return (T) this.arg; - } - - @Override - @SuppressWarnings("unchecked") - public Service getSvc() { - return (Service) this.svc; + runServiceInAllRealmTypes(svc, arg, before, null, null); } } diff --git a/src/test/java/li/strolch/service/XmlImportModelServiceTest.java b/src/test/java/li/strolch/service/XmlImportModelServiceTest.java index 800e1c421..5dab73c82 100644 --- a/src/test/java/li/strolch/service/XmlImportModelServiceTest.java +++ b/src/test/java/li/strolch/service/XmlImportModelServiceTest.java @@ -15,37 +15,22 @@ */ package li.strolch.service; -import li.strolch.service.api.Service; -import li.strolch.service.api.ServiceArgument; -import li.strolch.service.api.ServiceResult; import li.strolch.service.test.AbstractRealmServiceTest; -import org.junit.Before; +import org.junit.Test; /** * @author Robert von Burg */ -public class XmlImportModelServiceTest extends AbstractRealmServiceTest { +public class XmlImportModelServiceTest extends AbstractRealmServiceTest { - private XmlImportModelService svc; - private XmlImportModelArgument arg; + @Test + public void runTest() { - @Before - public void before() { - svc = new XmlImportModelService(); - arg = new XmlImportModelArgument(); + XmlImportModelService svc = new XmlImportModelService(); + XmlImportModelArgument arg = new XmlImportModelArgument(); arg.modelFileName = "Enums.xml"; - } - - @Override - @SuppressWarnings("unchecked") - public T getArg() { - return (T) this.arg; - } - @Override - @SuppressWarnings("unchecked") - public Service getSvc() { - return (Service) this.svc; + runServiceInAllRealmTypes(svc, arg); } } diff --git a/src/test/java/li/strolch/service/test/AbstractRealmServiceTest.java b/src/test/java/li/strolch/service/test/AbstractRealmServiceTest.java index 4e77aa7cf..cd078da43 100644 --- a/src/test/java/li/strolch/service/test/AbstractRealmServiceTest.java +++ b/src/test/java/li/strolch/service/test/AbstractRealmServiceTest.java @@ -22,6 +22,8 @@ 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; @@ -32,9 +34,8 @@ 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 org.junit.After; +import org.junit.Before; /** * @author Robert von Burg @@ -49,8 +50,8 @@ public abstract class AbstractRealmServiceTest { protected static RuntimeMock runtimeMock; - @BeforeClass - public static void beforeClass() throws SQLException { + @Before + public void beforeClass() throws SQLException { dropSchema("jdbc:postgresql://localhost/cacheduserdb", "cacheduser", "test"); dropSchema("jdbc:postgresql://localhost/transactionaluserdb", "transactionaluser", "test"); @@ -65,8 +66,8 @@ public abstract class AbstractRealmServiceTest { importFromXml(REALM_TRANSACTIONAL, getServiceHandler()); } - @AfterClass - public static void afterClass() { + @After + public void afterClass() { runtimeMock.destroyRuntime(); } @@ -89,33 +90,57 @@ public abstract class AbstractRealmServiceTest { } protected void doService(String realm, - ServiceResultState expectedState, Class expectedServiceResultType, Service svc, T arg) { + 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(null, 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 abstract T getArg(); - - public abstract Service getSvc(); - - @Test - public void shouldPerformServiceTransient() { - doService(REALM_TRANSIENT, ServiceResultState.SUCCESS, ServiceResult.class, getSvc(), getArg()); + public interface Runner { + public void run(StrolchRealm strolchRealm, ComponentContainer container); } - @Test - public void shouldPerformServiceCached() { - doService(REALM_CACHED, ServiceResultState.SUCCESS, ServiceResult.class, getSvc(), getArg()); + protected void runServiceInAllRealmTypes(Service svc, + T arg) { + runServiceInAllRealmTypes(svc, arg, null, null, null); } - @Test - public void shouldPerformServiceTransactional() { - doService(REALM_TRANSACTIONAL, ServiceResultState.SUCCESS, ServiceResult.class, getSvc(), getArg()); + protected void runServiceInAllRealmTypes(Service svc, + T arg, Runner before, Runner validator, Runner after) { + + runTransient(svc, arg, before, validator, after); + runCached(svc, arg, before, validator, after); + runTransactional(svc, arg, before, validator, after); + } + + 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/src/test/java/li/strolch/service/test/parameter/AddParameterServiceTest.java b/src/test/java/li/strolch/service/test/parameter/AddParameterServiceTest.java index 1a6117506..1f2c19240 100644 --- a/src/test/java/li/strolch/service/test/parameter/AddParameterServiceTest.java +++ b/src/test/java/li/strolch/service/test/parameter/AddParameterServiceTest.java @@ -17,44 +17,28 @@ package li.strolch.service.test.parameter; import li.strolch.model.Locator; import li.strolch.model.parameter.FloatParameter; -import li.strolch.service.api.Service; -import li.strolch.service.api.ServiceArgument; -import li.strolch.service.api.ServiceResult; import li.strolch.service.parameter.AddParameterService; import li.strolch.service.parameter.AddParameterService.AddParameterArg; import li.strolch.service.test.AbstractRealmServiceTest; -import org.junit.Before; +import org.junit.Test; /** * @author Robert von Burg */ public class AddParameterServiceTest extends AbstractRealmServiceTest { - private AddParameterService svc; - private AddParameterArg arg; - private FloatParameter parameter; + @Test + public void runTest() { - @Before - public void before() { - svc = new AddParameterService(); - arg = new AddParameterArg(); + AddParameterService svc = new AddParameterService(); + AddParameterArg arg = new AddParameterArg(); arg.locator = Locator.valueOf("Resource/Ball/yellow/parameters"); - parameter = new FloatParameter("diameter", "Diameter", 22.0); + FloatParameter parameter = new FloatParameter("diameter", "Diameter", 22.0); parameter.setInterpretation("Dimension"); parameter.setUom("cm"); arg.parameter = parameter; - } - @Override - @SuppressWarnings("unchecked") - public T getArg() { - return (T) this.arg; - } - - @Override - @SuppressWarnings("unchecked") - public Service getSvc() { - return (Service) this.svc; + runServiceInAllRealmTypes(svc, arg); } } diff --git a/src/test/java/li/strolch/service/test/parameter/RemoveParameterServiceTest.java b/src/test/java/li/strolch/service/test/parameter/RemoveParameterServiceTest.java index 601fc4399..be70d6ec8 100644 --- a/src/test/java/li/strolch/service/test/parameter/RemoveParameterServiceTest.java +++ b/src/test/java/li/strolch/service/test/parameter/RemoveParameterServiceTest.java @@ -16,39 +16,24 @@ package li.strolch.service.test.parameter; import li.strolch.model.Locator; -import li.strolch.service.api.Service; -import li.strolch.service.api.ServiceArgument; -import li.strolch.service.api.ServiceResult; import li.strolch.service.parameter.RemoveParameterService; import li.strolch.service.parameter.RemoveParameterService.RemoveParameterArg; import li.strolch.service.test.AbstractRealmServiceTest; -import org.junit.Before; +import org.junit.Test; /** * @author Robert von Burg */ public class RemoveParameterServiceTest extends AbstractRealmServiceTest { - private RemoveParameterService svc; - private RemoveParameterArg arg; + @Test + public void runTest() { - @Before - public void before() { - svc = new RemoveParameterService(); - arg = new RemoveParameterArg(); + RemoveParameterService svc = new RemoveParameterService(); + RemoveParameterArg arg = new RemoveParameterArg(); arg.locator = Locator.valueOf("Resource/Ball/yellow/parameters/owner"); - } - @Override - @SuppressWarnings("unchecked") - public T getArg() { - return (T) this.arg; - } - - @Override - @SuppressWarnings("unchecked") - public Service getSvc() { - return (Service) this.svc; + runServiceInAllRealmTypes(svc, arg); } } diff --git a/src/test/java/li/strolch/service/test/parameter/SetParameterServiceTest.java b/src/test/java/li/strolch/service/test/parameter/SetParameterServiceTest.java index 4427d546c..658e51279 100644 --- a/src/test/java/li/strolch/service/test/parameter/SetParameterServiceTest.java +++ b/src/test/java/li/strolch/service/test/parameter/SetParameterServiceTest.java @@ -16,27 +16,22 @@ package li.strolch.service.test.parameter; import li.strolch.model.Locator; -import li.strolch.service.api.Service; -import li.strolch.service.api.ServiceArgument; -import li.strolch.service.api.ServiceResult; import li.strolch.service.parameter.SetParameterService; import li.strolch.service.parameter.SetParameterService.SetParameterArg; import li.strolch.service.test.AbstractRealmServiceTest; -import org.junit.Before; +import org.junit.Test; /** * @author Robert von Burg */ public class SetParameterServiceTest extends AbstractRealmServiceTest { - private SetParameterService svc; - private SetParameterArg arg; + @Test + public void runTest() { - @Before - public void before() { - svc = new SetParameterService(); - arg = new SetParameterArg(); + SetParameterService svc = new SetParameterService(); + SetParameterArg arg = new SetParameterArg(); arg.locator = Locator.valueOf("Resource/Ball/yellow/parameters/owner"); arg.name = "The Owner"; arg.interpretation = "Changing The Interpretation"; @@ -44,17 +39,7 @@ public class SetParameterServiceTest extends AbstractRealmServiceTest { arg.hidden = true; arg.index = 99; arg.valueAsString = "someotherdude"; - } - @Override - @SuppressWarnings("unchecked") - public T getArg() { - return (T) this.arg; - } - - @Override - @SuppressWarnings("unchecked") - public Service getSvc() { - return (Service) this.svc; + runServiceInAllRealmTypes(svc, arg); } } From ef15d4af1f2c0017243215a097c1e020e78a1663 Mon Sep 17 00:00:00 2001 From: Robert von Burg Date: Thu, 31 Jul 2014 20:05:54 +0200 Subject: [PATCH 53/65] [New] extended XmlExportModelService to handle overwriting existing --- .../command/XmlExportModelCommand.java | 32 ++++++++++- .../strolch/service/ClearModelArgument.java | 5 +- .../service/XmlExportModelArgument.java | 12 +++-- .../service/XmlExportModelService.java | 10 ++-- .../service/XmlExportModelServiceTest.java | 53 +++++++++++++++++++ .../test/AbstractRealmServiceTest.java | 4 +- 6 files changed, 102 insertions(+), 14 deletions(-) diff --git a/src/main/java/li/strolch/command/XmlExportModelCommand.java b/src/main/java/li/strolch/command/XmlExportModelCommand.java index ff8edaaf7..6835feac0 100644 --- a/src/main/java/li/strolch/command/XmlExportModelCommand.java +++ b/src/main/java/li/strolch/command/XmlExportModelCommand.java @@ -19,6 +19,7 @@ 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; @@ -60,6 +61,8 @@ public class XmlExportModelCommand extends Command { // input private File modelFile; + private boolean multiFile; + private boolean overwrite; private boolean doOrders; private boolean doResources; private Set orderTypes; @@ -67,7 +70,6 @@ public class XmlExportModelCommand extends Command { // output private ModelStatistics statistics; - private boolean multiFile; private int elementsToWrite; private int nrOfResourcesToExport; @@ -81,10 +83,25 @@ public class XmlExportModelCommand extends Command { @Override public void validate() { - DBC.PRE.assertNotExists("Model may not already exist!", this.modelFile); + 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; @@ -95,6 +112,8 @@ public class XmlExportModelCommand extends Command { this.statistics.startTime = new Date(); String exportName = fileName.substring(0, fileName.indexOf(XML_FILE_SUFFIX)); + cleanUpExisting(exportName); + Set createdFiles = new HashSet<>(); if (this.doResources) { @@ -146,6 +165,7 @@ public class XmlExportModelCommand extends Command { writer.writeAttribute(Tags.FILE, typeXmlFile); File typeXmlFileF = new File(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)) { @@ -175,6 +195,7 @@ public class XmlExportModelCommand extends Command { writer.writeAttribute(Tags.FILE, typeXmlFile); File typeXmlFileF = new File(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)) { @@ -306,4 +327,11 @@ public class XmlExportModelCommand extends Command { public ModelStatistics getStatistics() { return this.statistics; } + + /** + * @param overwrite + */ + public void setOverwrite(boolean overwrite) { + this.overwrite = overwrite; + } } diff --git a/src/main/java/li/strolch/service/ClearModelArgument.java b/src/main/java/li/strolch/service/ClearModelArgument.java index 6dd57b921..42cfe9555 100644 --- a/src/main/java/li/strolch/service/ClearModelArgument.java +++ b/src/main/java/li/strolch/service/ClearModelArgument.java @@ -19,7 +19,6 @@ import li.strolch.service.api.ServiceArgument; public class ClearModelArgument extends ServiceArgument { private static final long serialVersionUID = 1L; - - public boolean clearOrders = true; - public boolean clearResources = true; + public boolean clearOrders; + public boolean clearResources; } \ No newline at end of file diff --git a/src/main/java/li/strolch/service/XmlExportModelArgument.java b/src/main/java/li/strolch/service/XmlExportModelArgument.java index a8693d0b1..ffa15f294 100644 --- a/src/main/java/li/strolch/service/XmlExportModelArgument.java +++ b/src/main/java/li/strolch/service/XmlExportModelArgument.java @@ -24,6 +24,7 @@ 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; @@ -33,9 +34,14 @@ public class XmlExportModelArgument extends ServiceArgument { @Override public String toString() { StringBuilder builder = new StringBuilder(); - builder.append("XmlExportModelArgument ["); + builder.append("XmlExportModelArgument [ "); - builder.append("multiFile="); + builder.append("modelFileName="); + builder.append(this.modelFileName); + + builder.append(", overwrite="); + builder.append(this.overwrite); + builder.append(", multiFile="); builder.append(this.multiFile); if (this.doResources) @@ -56,8 +62,6 @@ public class XmlExportModelArgument extends ServiceArgument { builder.append(", orderTypes=*"); } - builder.append(", modelFileName="); - builder.append(this.modelFileName); builder.append("]"); return builder.toString(); } diff --git a/src/main/java/li/strolch/service/XmlExportModelService.java b/src/main/java/li/strolch/service/XmlExportModelService.java index 6d8ea7418..79e05413d 100644 --- a/src/main/java/li/strolch/service/XmlExportModelService.java +++ b/src/main/java/li/strolch/service/XmlExportModelService.java @@ -46,9 +46,12 @@ public class XmlExportModelService extends AbstractService Date: Mon, 4 Aug 2014 14:51:09 +0200 Subject: [PATCH 54/65] [New] added StrolchQuery.getSelection() and cleaned up some constants --- .../li/strolch/command/UpdateResourceCollectionCommand.java | 2 +- .../java/li/strolch/service/test/XmlExportServiceTest.java | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/li/strolch/command/UpdateResourceCollectionCommand.java b/src/main/java/li/strolch/command/UpdateResourceCollectionCommand.java index 2b6b65d67..b72b599ee 100644 --- a/src/main/java/li/strolch/command/UpdateResourceCollectionCommand.java +++ b/src/main/java/li/strolch/command/UpdateResourceCollectionCommand.java @@ -62,7 +62,7 @@ public class UpdateResourceCollectionCommand extends Command { } ResourceMap resourceMap = tx().getResourceMap(); - for (Resource resource : resources) { + 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()); diff --git a/src/test/java/li/strolch/service/test/XmlExportServiceTest.java b/src/test/java/li/strolch/service/test/XmlExportServiceTest.java index 356fd27d6..43e517e3a 100644 --- a/src/test/java/li/strolch/service/test/XmlExportServiceTest.java +++ b/src/test/java/li/strolch/service/test/XmlExportServiceTest.java @@ -20,7 +20,7 @@ import static org.junit.Assert.assertEquals; import java.io.File; import java.io.FilenameFilter; -import li.strolch.model.Tags; +import li.strolch.runtime.StrolchConstants; import li.strolch.service.XmlExportModelArgument; import li.strolch.service.XmlExportModelService; import li.strolch.service.XmlImportModelArgument; @@ -92,7 +92,7 @@ public class XmlExportServiceTest { XmlExportModelArgument arg = new XmlExportModelArgument(); arg.modelFileName = "TestExportOnlyResTemplates.xml"; arg.doOrders = false; - arg.resourceTypes.add(Tags.TEMPLATE); + arg.resourceTypes.add(StrolchConstants.TEMPLATE); arg.multiFile = true; ServiceResult result = runtimeMock.getServiceHandler().doService(null, service, arg); RuntimeMock.assertServiceResult(ServiceResultState.SUCCESS, ServiceResult.class, result); From 2033c6b942991605f172263e8023575c1e533f3b Mon Sep 17 00:00:00 2001 From: Robert von Burg Date: Wed, 13 Aug 2014 16:06:23 +0200 Subject: [PATCH 55/65] [Major] Refactored StrolchConfiguration.xml to use environments Now the agent requires an environment parameter to start, and the configuration of that environment is used to load different sections of the configuration file --- .../svctest/config/StrolchConfiguration.xml | 98 ++++++++++--------- .../config/StrolchConfiguration.xml | 52 +++++----- .../config/StrolchConfiguration.xml | 64 ++++++------ .../config/StrolchConfiguration.xml | 46 ++++----- 4 files changed, 134 insertions(+), 126 deletions(-) diff --git a/src/test/resources/svctest/config/StrolchConfiguration.xml b/src/test/resources/svctest/config/StrolchConfiguration.xml index 85ca1805d..32aa61182 100644 --- a/src/test/resources/svctest/config/StrolchConfiguration.xml +++ b/src/test/resources/svctest/config/StrolchConfiguration.xml @@ -1,59 +1,61 @@ - - StrolchRuntimeTest - - true - - - - RealmHandler - li.strolch.agent.api.RealmHandler - li.strolch.agent.impl.DefaultRealmHandler - PersistenceHandler - - svcTransient, svcCached, svcTransactional + + + StrolchRuntimeTest + + true + + + + RealmHandler + li.strolch.agent.api.RealmHandler + li.strolch.agent.impl.DefaultRealmHandler + PersistenceHandler + + svcTransient, svcCached, svcTransactional - SECONDS - 1 - TRANSIENT - StrolchModel.xml + SECONDS + 1 + TRANSIENT + StrolchModel.xml - SECONDS - 1 - CACHED + SECONDS + 1 + CACHED - SECONDS - 1 - TRANSACTIONAL - - + SECONDS + 1 + TRANSACTIONAL + + - - PersistenceHandler - li.strolch.persistence.api.PersistenceHandler - li.strolch.persistence.postgresql.PostgreSqlPersistenceHandler - - true - true + + PersistenceHandler + li.strolch.persistence.api.PersistenceHandler + li.strolch.persistence.postgresql.PostgreSqlPersistenceHandler + + true + true - jdbc:postgresql://localhost/cacheduserdb - cacheduser - test + jdbc:postgresql://localhost/cacheduserdb + cacheduser + test - jdbc:postgresql://localhost/transactionaluserdb - transactionaluser - test + jdbc:postgresql://localhost/transactionaluserdb + transactionaluser + test - - + + - - ServiceHandler - li.strolch.service.api.ServiceHandler - li.strolch.service.api.DefaultServiceHandler - - true - - + + ServiceHandler + li.strolch.service.api.ServiceHandler + li.strolch.service.api.DefaultServiceHandler + + true + + + \ No newline at end of file diff --git a/src/test/resources/transienttest/config/StrolchConfiguration.xml b/src/test/resources/transienttest/config/StrolchConfiguration.xml index a4f856d75..86118942a 100644 --- a/src/test/resources/transienttest/config/StrolchConfiguration.xml +++ b/src/test/resources/transienttest/config/StrolchConfiguration.xml @@ -1,28 +1,30 @@ - - StrolchRuntimeTest - - true - - - - RealmHandler - li.strolch.agent.api.RealmHandler - li.strolch.agent.impl.DefaultRealmHandler - - SECONDS - 1 - TRANSIENT - StrolchModel.xml - - - - ServiceHandler - li.strolch.service.api.ServiceHandler - li.strolch.service.api.DefaultServiceHandler - - true - - + + + StrolchRuntimeTest + + true + + + + RealmHandler + li.strolch.agent.api.RealmHandler + li.strolch.agent.impl.DefaultRealmHandler + + SECONDS + 1 + TRANSIENT + StrolchModel.xml + + + + ServiceHandler + li.strolch.service.api.ServiceHandler + li.strolch.service.api.DefaultServiceHandler + + true + + + \ No newline at end of file diff --git a/src/test/resources/withPrivilegeRuntime/config/StrolchConfiguration.xml b/src/test/resources/withPrivilegeRuntime/config/StrolchConfiguration.xml index 03c9d0070..f9d6bfb1a 100644 --- a/src/test/resources/withPrivilegeRuntime/config/StrolchConfiguration.xml +++ b/src/test/resources/withPrivilegeRuntime/config/StrolchConfiguration.xml @@ -1,34 +1,36 @@ - - StrolchPersistenceTest - - true - - - - RealmHandler - li.strolch.agent.api.RealmHandler - li.strolch.agent.impl.DefaultRealmHandler - - EMPTY - - - - ServiceHandler - li.strolch.service.api.ServiceHandler - li.strolch.service.api.DefaultServiceHandler - PrivilegeHandler - - true - - - - PrivilegeHandler - li.strolch.runtime.privilege.StrolchPrivilegeHandler - li.strolch.runtime.privilege.DefaultStrolchPrivilegeHandler - - PrivilegeConfig.xml - - + + + StrolchPersistenceTest + + true + + + + RealmHandler + li.strolch.agent.api.RealmHandler + li.strolch.agent.impl.DefaultRealmHandler + + EMPTY + + + + ServiceHandler + li.strolch.service.api.ServiceHandler + li.strolch.service.api.DefaultServiceHandler + PrivilegeHandler + + true + + + + PrivilegeHandler + li.strolch.runtime.privilege.StrolchPrivilegeHandler + li.strolch.runtime.privilege.DefaultStrolchPrivilegeHandler + + PrivilegeConfig.xml + + + \ No newline at end of file diff --git a/src/test/resources/withoutPrivilegeRuntime/config/StrolchConfiguration.xml b/src/test/resources/withoutPrivilegeRuntime/config/StrolchConfiguration.xml index 4ba1722ff..9248f6f3e 100644 --- a/src/test/resources/withoutPrivilegeRuntime/config/StrolchConfiguration.xml +++ b/src/test/resources/withoutPrivilegeRuntime/config/StrolchConfiguration.xml @@ -1,25 +1,27 @@ - - StrolchPersistenceTest - - true - - - - RealmHandler - li.strolch.agent.api.RealmHandler - li.strolch.agent.impl.DefaultRealmHandler - - EMPTY - - - - ServiceHandler - li.strolch.service.api.ServiceHandler - li.strolch.service.api.DefaultServiceHandler - - true - - + + + StrolchPersistenceTest + + true + + + + RealmHandler + li.strolch.agent.api.RealmHandler + li.strolch.agent.impl.DefaultRealmHandler + + EMPTY + + + + ServiceHandler + li.strolch.service.api.ServiceHandler + li.strolch.service.api.DefaultServiceHandler + + true + + + \ No newline at end of file From 3a62c76ae0706ad16795316f152006b73a0ccd3b Mon Sep 17 00:00:00 2001 From: Robert von Burg Date: Wed, 13 Aug 2014 23:38:59 +0200 Subject: [PATCH 56/65] [Minor] fixed compiler warning --- src/main/java/li/strolch/command/XmlExportModelCommand.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/li/strolch/command/XmlExportModelCommand.java b/src/main/java/li/strolch/command/XmlExportModelCommand.java index 6835feac0..8bc55471f 100644 --- a/src/main/java/li/strolch/command/XmlExportModelCommand.java +++ b/src/main/java/li/strolch/command/XmlExportModelCommand.java @@ -234,7 +234,7 @@ public class XmlExportModelCommand extends Command { } private void writeOrdersByType(XMLStreamWriter writer, OrderMap orderMap, String type) { - OrderVisitor visitor = new OrderToSaxWriterVisitor(writer); + OrderVisitor visitor = new OrderToSaxWriterVisitor(writer); Set keysByType = new TreeSet<>(orderMap.getKeysBy(tx(), type)); for (String id : keysByType) { Order order = orderMap.getBy(tx(), type, id); @@ -252,7 +252,7 @@ public class XmlExportModelCommand extends Command { } private void writeResourcesByType(XMLStreamWriter writer, ResourceMap resourceMap, String type) { - ResourceVisitor visitor = new ResourceToSaxWriterVisitor(writer); + ResourceVisitor visitor = new ResourceToSaxWriterVisitor(writer); Set keysByType = new TreeSet<>(resourceMap.getKeysBy(tx(), type)); for (String id : keysByType) { Resource resource = resourceMap.getBy(tx(), type, id); From 5e181fe5c3d514532a0fb6e256338091a0f719db Mon Sep 17 00:00:00 2001 From: Robert von Burg Date: Wed, 13 Aug 2014 23:39:05 +0200 Subject: [PATCH 57/65] [Project] added resource filtering for componentVersion.properties --- pom.xml | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/pom.xml b/pom.xml index 1d132c6e3..0e01bddc6 100644 --- a/pom.xml +++ b/pom.xml @@ -62,6 +62,15 @@ + + + src/main/resources + true + + **/componentVersion.properties + + + org.codehaus.mojo From a5f00f990c82ccbe554613e4e7972ed87ee80c6c Mon Sep 17 00:00:00 2001 From: Robert von Burg Date: Thu, 21 Aug 2014 17:42:26 +0200 Subject: [PATCH 58/65] [Major] added missing parsing of StrolchTimedState and fixed locators Locators are now a bit different, to handle finding StrolchTimedState as well, the Locator has the form: Resource///State/ Resource///Bag// --- .../parameter/AddParameterCommandTest.java | 2 +- .../parameter/RemoveParameterCommandTest.java | 2 +- .../parameter/SetParameterCommandTest.java | 2 +- .../parameter/AddParameterServiceTest.java | 2 +- .../parameter/RemoveParameterServiceTest.java | 2 +- .../parameter/SetParameterServiceTest.java | 2 +- src/test/resources/svctest/data/Orders.xml | 2 ++ src/test/resources/svctest/data/Resources.xml | 23 +++++++++++++++++++ 8 files changed, 31 insertions(+), 6 deletions(-) diff --git a/src/test/java/li/strolch/command/parameter/AddParameterCommandTest.java b/src/test/java/li/strolch/command/parameter/AddParameterCommandTest.java index 0c09e6592..2eff247d1 100644 --- a/src/test/java/li/strolch/command/parameter/AddParameterCommandTest.java +++ b/src/test/java/li/strolch/command/parameter/AddParameterCommandTest.java @@ -37,7 +37,7 @@ public class AddParameterCommandTest extends AbstractRealmCommandTest { @Before public void before() { - this.locator = Locator.valueOf("Resource/Ball/yellow/parameters"); + this.locator = Locator.valueOf("Resource/Ball/yellow/Bag/parameters"); this.parameter = new BooleanParameter("newParam", "New Param", false); } diff --git a/src/test/java/li/strolch/command/parameter/RemoveParameterCommandTest.java b/src/test/java/li/strolch/command/parameter/RemoveParameterCommandTest.java index d55abfbb3..cd6a9bee8 100644 --- a/src/test/java/li/strolch/command/parameter/RemoveParameterCommandTest.java +++ b/src/test/java/li/strolch/command/parameter/RemoveParameterCommandTest.java @@ -34,7 +34,7 @@ public class RemoveParameterCommandTest extends AbstractRealmCommandTest { @Before public void before() { - this.locator = Locator.valueOf("Resource/Ball/yellow/parameters"); + this.locator = Locator.valueOf("Resource/Ball/yellow/Bag/parameters"); this.parameterId = "owner"; } diff --git a/src/test/java/li/strolch/command/parameter/SetParameterCommandTest.java b/src/test/java/li/strolch/command/parameter/SetParameterCommandTest.java index 623227b5a..d75344e4c 100644 --- a/src/test/java/li/strolch/command/parameter/SetParameterCommandTest.java +++ b/src/test/java/li/strolch/command/parameter/SetParameterCommandTest.java @@ -35,7 +35,7 @@ public class SetParameterCommandTest extends AbstractRealmCommandTest { @Before public void before() { - this.locator = Locator.valueOf("Resource/Ball/yellow/parameters/owner"); + this.locator = Locator.valueOf("Resource/Ball/yellow/Bag/parameters/owner"); this.valueAsString = "someOtherDude"; } diff --git a/src/test/java/li/strolch/service/test/parameter/AddParameterServiceTest.java b/src/test/java/li/strolch/service/test/parameter/AddParameterServiceTest.java index 1f2c19240..173184569 100644 --- a/src/test/java/li/strolch/service/test/parameter/AddParameterServiceTest.java +++ b/src/test/java/li/strolch/service/test/parameter/AddParameterServiceTest.java @@ -33,7 +33,7 @@ public class AddParameterServiceTest extends AbstractRealmServiceTest { AddParameterService svc = new AddParameterService(); AddParameterArg arg = new AddParameterArg(); - arg.locator = Locator.valueOf("Resource/Ball/yellow/parameters"); + arg.locator = Locator.valueOf("Resource/Ball/yellow/Bag/parameters"); FloatParameter parameter = new FloatParameter("diameter", "Diameter", 22.0); parameter.setInterpretation("Dimension"); parameter.setUom("cm"); diff --git a/src/test/java/li/strolch/service/test/parameter/RemoveParameterServiceTest.java b/src/test/java/li/strolch/service/test/parameter/RemoveParameterServiceTest.java index be70d6ec8..4ffbd1103 100644 --- a/src/test/java/li/strolch/service/test/parameter/RemoveParameterServiceTest.java +++ b/src/test/java/li/strolch/service/test/parameter/RemoveParameterServiceTest.java @@ -32,7 +32,7 @@ public class RemoveParameterServiceTest extends AbstractRealmServiceTest { RemoveParameterService svc = new RemoveParameterService(); RemoveParameterArg arg = new RemoveParameterArg(); - arg.locator = Locator.valueOf("Resource/Ball/yellow/parameters/owner"); + arg.locator = Locator.valueOf("Resource/Ball/yellow/Bag/parameters/owner"); runServiceInAllRealmTypes(svc, arg); } diff --git a/src/test/java/li/strolch/service/test/parameter/SetParameterServiceTest.java b/src/test/java/li/strolch/service/test/parameter/SetParameterServiceTest.java index 658e51279..35e01a24a 100644 --- a/src/test/java/li/strolch/service/test/parameter/SetParameterServiceTest.java +++ b/src/test/java/li/strolch/service/test/parameter/SetParameterServiceTest.java @@ -32,7 +32,7 @@ public class SetParameterServiceTest extends AbstractRealmServiceTest { SetParameterService svc = new SetParameterService(); SetParameterArg arg = new SetParameterArg(); - arg.locator = Locator.valueOf("Resource/Ball/yellow/parameters/owner"); + arg.locator = Locator.valueOf("Resource/Ball/yellow/Bag/parameters/owner"); arg.name = "The Owner"; arg.interpretation = "Changing The Interpretation"; arg.uom = "Owners"; diff --git a/src/test/resources/svctest/data/Orders.xml b/src/test/resources/svctest/data/Orders.xml index 6db28be23..45edd36f4 100644 --- a/src/test/resources/svctest/data/Orders.xml +++ b/src/test/resources/svctest/data/Orders.xml @@ -54,5 +54,7 @@ + + diff --git a/src/test/resources/svctest/data/Resources.xml b/src/test/resources/svctest/data/Resources.xml index b97a4c05a..2bcda50b1 100644 --- a/src/test/resources/svctest/data/Resources.xml +++ b/src/test/resources/svctest/data/Resources.xml @@ -4,5 +4,28 @@ + + + + + + + + + + + + + + + + + + + + + + + From 0fbd156929742fe91f888bebdbb0d1b77f0f15c2 Mon Sep 17 00:00:00 2001 From: Robert von Burg Date: Thu, 21 Aug 2014 17:52:00 +0200 Subject: [PATCH 59/65] [New] Added convenience method Locator.newLocatorBuilder(String...) --- .../strolch/command/RemoveOrderCollectionCommandTest.java | 6 +++--- .../java/li/strolch/command/RemoveOrderCommandTest.java | 2 +- .../command/RemoveResourceCollectionCommandTest.java | 6 +++--- .../java/li/strolch/command/RemoveResourceCommandTest.java | 2 +- .../strolch/service/RemoveOrderCollectionServiceTest.java | 6 +++--- .../java/li/strolch/service/RemoveOrderServiceTest.java | 2 +- .../service/RemoveResourceCollectionServiceTest.java | 6 +++--- .../java/li/strolch/service/RemoveResourceServiceTest.java | 2 +- 8 files changed, 16 insertions(+), 16 deletions(-) diff --git a/src/test/java/li/strolch/command/RemoveOrderCollectionCommandTest.java b/src/test/java/li/strolch/command/RemoveOrderCollectionCommandTest.java index df4cf4f3b..246bf8461 100644 --- a/src/test/java/li/strolch/command/RemoveOrderCollectionCommandTest.java +++ b/src/test/java/li/strolch/command/RemoveOrderCollectionCommandTest.java @@ -37,9 +37,9 @@ public class RemoveOrderCollectionCommandTest extends AbstractRealmCommandTest { @Before public void before() { locators = new ArrayList<>(); - locators.add(Locator.newBuilder(Tags.ORDER).append("TestType").append("@1").build()); - locators.add(Locator.newBuilder(Tags.ORDER).append("TestType").append("@2").build()); - locators.add(Locator.newBuilder(Tags.ORDER).append("TestType").append("@3").build()); + 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()); } @Override diff --git a/src/test/java/li/strolch/command/RemoveOrderCommandTest.java b/src/test/java/li/strolch/command/RemoveOrderCommandTest.java index a64b41098..abb4c7b2f 100644 --- a/src/test/java/li/strolch/command/RemoveOrderCommandTest.java +++ b/src/test/java/li/strolch/command/RemoveOrderCommandTest.java @@ -33,7 +33,7 @@ public class RemoveOrderCommandTest extends AbstractRealmCommandTest { @Before public void before() { - locator = Locator.newBuilder(Tags.ORDER).append("TestType").append("@3").build(); + locator = Locator.newBuilder(Tags.ORDER, "TestType", "@3").build(); } @Override diff --git a/src/test/java/li/strolch/command/RemoveResourceCollectionCommandTest.java b/src/test/java/li/strolch/command/RemoveResourceCollectionCommandTest.java index 1e71c85f5..c84024b51 100644 --- a/src/test/java/li/strolch/command/RemoveResourceCollectionCommandTest.java +++ b/src/test/java/li/strolch/command/RemoveResourceCollectionCommandTest.java @@ -37,9 +37,9 @@ public class RemoveResourceCollectionCommandTest extends AbstractRealmCommandTes @Before public void before() { locators = new ArrayList<>(); - locators.add(Locator.newBuilder(Tags.RESOURCE).append("Enumeration").append("salutations").build()); - locators.add(Locator.newBuilder(Tags.RESOURCE).append("Enumeration").append("sex").build()); - locators.add(Locator.newBuilder(Tags.RESOURCE).append("Enumeration").append("religions").build()); + 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()); } @Override diff --git a/src/test/java/li/strolch/command/RemoveResourceCommandTest.java b/src/test/java/li/strolch/command/RemoveResourceCommandTest.java index b55e2122e..803430df3 100644 --- a/src/test/java/li/strolch/command/RemoveResourceCommandTest.java +++ b/src/test/java/li/strolch/command/RemoveResourceCommandTest.java @@ -33,7 +33,7 @@ public class RemoveResourceCommandTest extends AbstractRealmCommandTest { @Before public void before() { - locator = Locator.newBuilder(Tags.RESOURCE).append("Enumeration").append("sex").build(); + locator = Locator.newBuilder(Tags.RESOURCE, "Enumeration", "sex").build(); } @Override diff --git a/src/test/java/li/strolch/service/RemoveOrderCollectionServiceTest.java b/src/test/java/li/strolch/service/RemoveOrderCollectionServiceTest.java index 09cec4633..136a14dbd 100644 --- a/src/test/java/li/strolch/service/RemoveOrderCollectionServiceTest.java +++ b/src/test/java/li/strolch/service/RemoveOrderCollectionServiceTest.java @@ -36,9 +36,9 @@ public class RemoveOrderCollectionServiceTest extends AbstractRealmServiceTest { RemoveOrderCollectionArg arg = new RemoveOrderCollectionArg(); ArrayList locators = new ArrayList<>(); - locators.add(Locator.newBuilder(Tags.ORDER).append("TestType").append("@1").build()); - locators.add(Locator.newBuilder(Tags.ORDER).append("TestType").append("@2").build()); - locators.add(Locator.newBuilder(Tags.ORDER).append("TestType").append("@3").build()); + 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; diff --git a/src/test/java/li/strolch/service/RemoveOrderServiceTest.java b/src/test/java/li/strolch/service/RemoveOrderServiceTest.java index 3c2fd97f3..c5058c8e2 100644 --- a/src/test/java/li/strolch/service/RemoveOrderServiceTest.java +++ b/src/test/java/li/strolch/service/RemoveOrderServiceTest.java @@ -32,7 +32,7 @@ public class RemoveOrderServiceTest extends AbstractRealmServiceTest { RemoveOrderService svc = new RemoveOrderService(); RemoveOrderArg arg = new RemoveOrderArg(); - arg.locator = Locator.newBuilder(Tags.ORDER).append("TestType").append("@3").build(); + arg.locator = Locator.newBuilder(Tags.ORDER, "TestType", "@3").build(); runServiceInAllRealmTypes(svc, arg); } diff --git a/src/test/java/li/strolch/service/RemoveResourceCollectionServiceTest.java b/src/test/java/li/strolch/service/RemoveResourceCollectionServiceTest.java index 149d19411..6a901120a 100644 --- a/src/test/java/li/strolch/service/RemoveResourceCollectionServiceTest.java +++ b/src/test/java/li/strolch/service/RemoveResourceCollectionServiceTest.java @@ -36,9 +36,9 @@ public class RemoveResourceCollectionServiceTest extends AbstractRealmServiceTes RemoveResourceCollectionArg arg = new RemoveResourceCollectionArg(); ArrayList locators = new ArrayList<>(); - locators.add(Locator.newBuilder(Tags.RESOURCE).append("Enumeration").append("salutations").build()); - locators.add(Locator.newBuilder(Tags.RESOURCE).append("Enumeration").append("sex").build()); - locators.add(Locator.newBuilder(Tags.RESOURCE).append("Enumeration").append("religions").build()); + 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; diff --git a/src/test/java/li/strolch/service/RemoveResourceServiceTest.java b/src/test/java/li/strolch/service/RemoveResourceServiceTest.java index 61bc612cf..ea92445ae 100644 --- a/src/test/java/li/strolch/service/RemoveResourceServiceTest.java +++ b/src/test/java/li/strolch/service/RemoveResourceServiceTest.java @@ -32,7 +32,7 @@ public class RemoveResourceServiceTest extends AbstractRealmServiceTest { RemoveResourceService svc = new RemoveResourceService(); RemoveResourceArg arg = new RemoveResourceArg(); - arg.locator = Locator.newBuilder(Tags.RESOURCE).append("Enumeration").append("sex").build(); + arg.locator = Locator.newBuilder(Tags.RESOURCE, "Enumeration", "sex").build(); runServiceInAllRealmTypes(svc, arg); } From a70218f0287bfb4426c45d48603de6a89153a9dd Mon Sep 17 00:00:00 2001 From: Robert von Burg Date: Sat, 23 Aug 2014 20:50:21 +0200 Subject: [PATCH 60/65] [New] Implemented opt-in audit trail in Strolch The audit trail has its own map on the Realm and a trail is written by realm at the end of the transaction. You can write your own audit trail using tx.getAuditTrail(). Enable the audit trail by setting the realm configuration value 'enableAuditTrail'. --- .../command/visitor/UpdateElementVisitor.java | 13 ++-- .../command/AbstractRealmCommandTest.java | 13 ++-- .../AddOrderCollectionServiceTest.java | 3 +- .../strolch/service/AddOrderServiceTest.java | 3 +- .../AddResourceCollectionServiceTest.java | 3 +- .../service/AddResourceServiceTest.java | 3 +- .../service/ClearModelServiceTest.java | 15 ++-- .../RemoveOrderCollectionServiceTest.java | 3 +- .../service/RemoveOrderServiceTest.java | 3 +- .../RemoveResourceCollectionServiceTest.java | 3 +- .../service/RemoveResourceServiceTest.java | 3 +- .../UpdateOrderCollectionServiceTest.java | 3 +- .../service/UpdateOrderServiceTest.java | 3 +- .../UpdateResourceCollectionServiceTest.java | 3 +- .../service/UpdateResourceServiceTest.java | 3 +- .../service/XmlExportModelServiceTest.java | 7 +- .../service/XmlImportModelServiceTest.java | 3 +- .../test/AbstractRealmServiceTest.java | 35 +++++---- .../li/strolch/service/test/LockingTest.java | 10 ++- .../service/test/NoPrivilegeServiceTest.java | 72 ------------------- .../li/strolch/service/test/ServiceTest.java | 5 +- .../service/test/XmlExportServiceTest.java | 13 ++-- .../parameter/AddParameterServiceTest.java | 3 +- .../parameter/RemoveParameterServiceTest.java | 3 +- .../parameter/SetParameterServiceTest.java | 3 +- .../svctest/config/PrivilegeConfig.xml | 30 ++++++++ .../svctest/config/PrivilegeModel.xml | 36 ++++++++++ .../svctest/config/StrolchConfiguration.xml | 9 +++ .../transienttest/config/PrivilegeConfig.xml | 30 ++++++++ .../transienttest/config/PrivilegeModel.xml | 36 ++++++++++ .../config/StrolchConfiguration.xml | 9 +++ .../config/PrivilegeModel.xml | 23 +++--- .../config/StrolchConfiguration.xml | 17 ++--- .../config/StrolchConfiguration.xml | 27 ------- 34 files changed, 255 insertions(+), 193 deletions(-) delete mode 100644 src/test/java/li/strolch/service/test/NoPrivilegeServiceTest.java create mode 100644 src/test/resources/svctest/config/PrivilegeConfig.xml create mode 100644 src/test/resources/svctest/config/PrivilegeModel.xml create mode 100644 src/test/resources/transienttest/config/PrivilegeConfig.xml create mode 100644 src/test/resources/transienttest/config/PrivilegeModel.xml delete mode 100644 src/test/resources/withoutPrivilegeRuntime/config/StrolchConfiguration.xml diff --git a/src/main/java/li/strolch/command/visitor/UpdateElementVisitor.java b/src/main/java/li/strolch/command/visitor/UpdateElementVisitor.java index 3fb059b84..97a2e1e93 100644 --- a/src/main/java/li/strolch/command/visitor/UpdateElementVisitor.java +++ b/src/main/java/li/strolch/command/visitor/UpdateElementVisitor.java @@ -23,9 +23,8 @@ import li.strolch.persistence.api.StrolchTransaction; /** * @author Robert von Burg - * */ -public class UpdateElementVisitor implements StrolchRootElementVisitor { +public class UpdateElementVisitor implements StrolchRootElementVisitor { private StrolchTransaction tx; @@ -37,15 +36,13 @@ public class UpdateElementVisitor implements StrolchRootElementVisitor { return rootElement.accept(this); } - @SuppressWarnings("unchecked") @Override - public T visitOrder(Order order) { - return (T) tx.getOrderMap().update(tx, order); + public StrolchRootElement visitOrder(Order order) { + return tx.getOrderMap().update(tx, order); } - @SuppressWarnings("unchecked") @Override - public T visitResource(Resource resource) { - return (T) tx.getResourceMap().update(tx, resource); + public StrolchRootElement visitResource(Resource resource) { + return tx.getResourceMap().update(tx, resource); } } diff --git a/src/test/java/li/strolch/command/AbstractRealmCommandTest.java b/src/test/java/li/strolch/command/AbstractRealmCommandTest.java index e1fb0b3d7..c353dd255 100644 --- a/src/test/java/li/strolch/command/AbstractRealmCommandTest.java +++ b/src/test/java/li/strolch/command/AbstractRealmCommandTest.java @@ -39,6 +39,8 @@ import org.junit.Rule; import org.junit.Test; import org.junit.rules.ExpectedException; +import ch.eitchnet.privilege.model.Certificate; + /** * @author Robert von Burg */ @@ -46,6 +48,8 @@ public abstract class AbstractRealmCommandTest { protected static RuntimeMock runtimeMock; + protected static Certificate certificate; + @Rule public ExpectedException expectedException = ExpectedException.none(); @@ -61,8 +65,9 @@ public abstract class AbstractRealmCommandTest { runtimeMock.mockRuntime(rootPath, configSrc); runtimeMock.startContainer(); - importFromXml(REALM_CACHED, getServiceHandler()); - importFromXml(REALM_TRANSACTIONAL, getServiceHandler()); + certificate = runtimeMock.getPrivilegeHandler().authenticate("test", "test".getBytes()); + importFromXml(REALM_CACHED, certificate, getServiceHandler()); + importFromXml(REALM_TRANSACTIONAL, certificate, getServiceHandler()); } @AfterClass @@ -81,7 +86,7 @@ public abstract class AbstractRealmCommandTest { expectedException.expectMessage("Fail on purpose after do command!"); StrolchRealm realm = runtimeMock.getContainer().getRealm(realmName); - try (StrolchTransaction tx = realm.openTx()) { + try (StrolchTransaction tx = realm.openTx(certificate, "test")) { Command command = getCommandInstance(runtimeMock.getContainer(), tx); @@ -92,7 +97,7 @@ public abstract class AbstractRealmCommandTest { protected void doCommand(String realmName) { StrolchRealm realm = runtimeMock.getContainer().getRealm(realmName); - try (StrolchTransaction tx = realm.openTx()) { + try (StrolchTransaction tx = realm.openTx(certificate, "test")) { Command command = getCommandInstance(runtimeMock.getContainer(), tx); tx.addCommand(command); } diff --git a/src/test/java/li/strolch/service/AddOrderCollectionServiceTest.java b/src/test/java/li/strolch/service/AddOrderCollectionServiceTest.java index 4a9155be5..2033be036 100644 --- a/src/test/java/li/strolch/service/AddOrderCollectionServiceTest.java +++ b/src/test/java/li/strolch/service/AddOrderCollectionServiceTest.java @@ -32,7 +32,6 @@ public class AddOrderCollectionServiceTest extends AbstractRealmServiceTest { @Test public void runTest() { - AddOrderCollectionService svc = new AddOrderCollectionService(); AddOrderCollectionArg arg = new AddOrderCollectionArg(); ArrayList orders = new ArrayList<>(); @@ -42,6 +41,6 @@ public class AddOrderCollectionServiceTest extends AbstractRealmServiceTest { arg.orders = orders; - runServiceInAllRealmTypes(svc, arg); + runServiceInAllRealmTypes(AddOrderCollectionService.class, arg); } } diff --git a/src/test/java/li/strolch/service/AddOrderServiceTest.java b/src/test/java/li/strolch/service/AddOrderServiceTest.java index 84ec6e38d..f0e3b5da5 100644 --- a/src/test/java/li/strolch/service/AddOrderServiceTest.java +++ b/src/test/java/li/strolch/service/AddOrderServiceTest.java @@ -29,10 +29,9 @@ public class AddOrderServiceTest extends AbstractRealmServiceTest { @Test public void runTest() { - AddOrderService svc = new AddOrderService(); AddOrderArg arg = new AddOrderArg(); arg.order = ModelGenerator.createOrder("firstOrder", "First Order", "AdditionalOrders"); - runServiceInAllRealmTypes(svc, arg); + runServiceInAllRealmTypes(AddOrderService.class, arg); } } diff --git a/src/test/java/li/strolch/service/AddResourceCollectionServiceTest.java b/src/test/java/li/strolch/service/AddResourceCollectionServiceTest.java index 3e9943797..42f7bb61c 100644 --- a/src/test/java/li/strolch/service/AddResourceCollectionServiceTest.java +++ b/src/test/java/li/strolch/service/AddResourceCollectionServiceTest.java @@ -32,7 +32,6 @@ public class AddResourceCollectionServiceTest extends AbstractRealmServiceTest { @Test public void runTest() { - AddResourceCollectionService svc = new AddResourceCollectionService(); AddResourceCollectionArg arg = new AddResourceCollectionArg(); ArrayList resources = new ArrayList<>(); @@ -42,6 +41,6 @@ public class AddResourceCollectionServiceTest extends AbstractRealmServiceTest { arg.resources = resources; - runServiceInAllRealmTypes(svc, arg); + runServiceInAllRealmTypes(AddResourceCollectionService.class, arg); } } diff --git a/src/test/java/li/strolch/service/AddResourceServiceTest.java b/src/test/java/li/strolch/service/AddResourceServiceTest.java index 1f4e131ce..bb53f6491 100644 --- a/src/test/java/li/strolch/service/AddResourceServiceTest.java +++ b/src/test/java/li/strolch/service/AddResourceServiceTest.java @@ -29,10 +29,9 @@ public class AddResourceServiceTest extends AbstractRealmServiceTest { @Test public void runTest() { - AddResourceService svc = new AddResourceService(); AddResourceArg arg = new AddResourceArg(); arg.resource = ModelGenerator.createResource("firstRes", "First Resource", "AdditionalResources"); - runServiceInAllRealmTypes(svc, arg); + runServiceInAllRealmTypes(AddResourceService.class, arg); } } diff --git a/src/test/java/li/strolch/service/ClearModelServiceTest.java b/src/test/java/li/strolch/service/ClearModelServiceTest.java index d3d291da4..2e4238b77 100644 --- a/src/test/java/li/strolch/service/ClearModelServiceTest.java +++ b/src/test/java/li/strolch/service/ClearModelServiceTest.java @@ -35,19 +35,18 @@ public class ClearModelServiceTest extends AbstractRealmServiceTest { Runner validator = new Runner() { @Override public void run(StrolchRealm strolchRealm, ComponentContainer container) { - try (StrolchTransaction tx = strolchRealm.openTx()) { + try (StrolchTransaction tx = strolchRealm.openTx(certificate, "test")) { assertEquals(0, tx.getResourceMap().querySize(tx)); assertEquals(0, tx.getOrderMap().querySize(tx)); } } }; - ClearModelService svc = new ClearModelService(); ClearModelArgument arg = new ClearModelArgument(); arg.clearOrders = true; arg.clearResources = true; - runServiceInAllRealmTypes(svc, arg, null, validator, null); + runServiceInAllRealmTypes(ClearModelService.class, arg, null, validator, null); } @Test @@ -56,19 +55,18 @@ public class ClearModelServiceTest extends AbstractRealmServiceTest { Runner validator = new Runner() { @Override public void run(StrolchRealm strolchRealm, ComponentContainer container) { - try (StrolchTransaction tx = strolchRealm.openTx()) { + try (StrolchTransaction tx = strolchRealm.openTx(certificate, "test")) { assertNotEquals(0, tx.getResourceMap().querySize(tx)); assertEquals(0, tx.getOrderMap().querySize(tx)); } } }; - ClearModelService svc = new ClearModelService(); ClearModelArgument arg = new ClearModelArgument(); arg.clearOrders = true; arg.clearResources = false; - runServiceInAllRealmTypes(svc, arg, null, validator, null); + runServiceInAllRealmTypes(ClearModelService.class, arg, null, validator, null); } @Test @@ -77,19 +75,18 @@ public class ClearModelServiceTest extends AbstractRealmServiceTest { Runner validator = new Runner() { @Override public void run(StrolchRealm strolchRealm, ComponentContainer container) { - try (StrolchTransaction tx = strolchRealm.openTx()) { + try (StrolchTransaction tx = strolchRealm.openTx(certificate, "test")) { assertNotEquals(0, tx.getOrderMap().querySize(tx)); assertEquals(0, tx.getResourceMap().querySize(tx)); } } }; - ClearModelService svc = new ClearModelService(); ClearModelArgument arg = new ClearModelArgument(); arg.clearOrders = false; arg.clearResources = true; - runServiceInAllRealmTypes(svc, arg, null, validator, null); + runServiceInAllRealmTypes(ClearModelService.class, arg, null, validator, null); } } diff --git a/src/test/java/li/strolch/service/RemoveOrderCollectionServiceTest.java b/src/test/java/li/strolch/service/RemoveOrderCollectionServiceTest.java index 136a14dbd..5f1a2169c 100644 --- a/src/test/java/li/strolch/service/RemoveOrderCollectionServiceTest.java +++ b/src/test/java/li/strolch/service/RemoveOrderCollectionServiceTest.java @@ -32,7 +32,6 @@ public class RemoveOrderCollectionServiceTest extends AbstractRealmServiceTest { @Test public void runTest() { - RemoveOrderCollectionService svc = new RemoveOrderCollectionService(); RemoveOrderCollectionArg arg = new RemoveOrderCollectionArg(); ArrayList locators = new ArrayList<>(); @@ -42,6 +41,6 @@ public class RemoveOrderCollectionServiceTest extends AbstractRealmServiceTest { arg.locators = locators; - runServiceInAllRealmTypes(svc, arg); + runServiceInAllRealmTypes(RemoveOrderCollectionService.class, arg); } } diff --git a/src/test/java/li/strolch/service/RemoveOrderServiceTest.java b/src/test/java/li/strolch/service/RemoveOrderServiceTest.java index c5058c8e2..483958aff 100644 --- a/src/test/java/li/strolch/service/RemoveOrderServiceTest.java +++ b/src/test/java/li/strolch/service/RemoveOrderServiceTest.java @@ -30,10 +30,9 @@ public class RemoveOrderServiceTest extends AbstractRealmServiceTest { @Test public void runTest() { - RemoveOrderService svc = new RemoveOrderService(); RemoveOrderArg arg = new RemoveOrderArg(); arg.locator = Locator.newBuilder(Tags.ORDER, "TestType", "@3").build(); - runServiceInAllRealmTypes(svc, arg); + runServiceInAllRealmTypes(RemoveOrderService.class, arg); } } diff --git a/src/test/java/li/strolch/service/RemoveResourceCollectionServiceTest.java b/src/test/java/li/strolch/service/RemoveResourceCollectionServiceTest.java index 6a901120a..13dfb3d31 100644 --- a/src/test/java/li/strolch/service/RemoveResourceCollectionServiceTest.java +++ b/src/test/java/li/strolch/service/RemoveResourceCollectionServiceTest.java @@ -32,7 +32,6 @@ public class RemoveResourceCollectionServiceTest extends AbstractRealmServiceTes @Test public void runTest() { - RemoveResourceCollectionService svc = new RemoveResourceCollectionService(); RemoveResourceCollectionArg arg = new RemoveResourceCollectionArg(); ArrayList locators = new ArrayList<>(); @@ -42,6 +41,6 @@ public class RemoveResourceCollectionServiceTest extends AbstractRealmServiceTes arg.locators = locators; - runServiceInAllRealmTypes(svc, arg); + runServiceInAllRealmTypes(RemoveResourceCollectionService.class, arg); } } diff --git a/src/test/java/li/strolch/service/RemoveResourceServiceTest.java b/src/test/java/li/strolch/service/RemoveResourceServiceTest.java index ea92445ae..3db54698d 100644 --- a/src/test/java/li/strolch/service/RemoveResourceServiceTest.java +++ b/src/test/java/li/strolch/service/RemoveResourceServiceTest.java @@ -30,10 +30,9 @@ public class RemoveResourceServiceTest extends AbstractRealmServiceTest { @Test public void runTest() { - RemoveResourceService svc = new RemoveResourceService(); RemoveResourceArg arg = new RemoveResourceArg(); arg.locator = Locator.newBuilder(Tags.RESOURCE, "Enumeration", "sex").build(); - runServiceInAllRealmTypes(svc, arg); + runServiceInAllRealmTypes(RemoveResourceService.class, arg); } } diff --git a/src/test/java/li/strolch/service/UpdateOrderCollectionServiceTest.java b/src/test/java/li/strolch/service/UpdateOrderCollectionServiceTest.java index f759184b9..f22096b78 100644 --- a/src/test/java/li/strolch/service/UpdateOrderCollectionServiceTest.java +++ b/src/test/java/li/strolch/service/UpdateOrderCollectionServiceTest.java @@ -33,7 +33,6 @@ public class UpdateOrderCollectionServiceTest extends AbstractRealmServiceTest { @Test public void runTest() { - UpdateOrderCollectionService svc = new UpdateOrderCollectionService(); UpdateOrderCollectionArg arg = new UpdateOrderCollectionArg(); List orders = new ArrayList<>(); @@ -43,6 +42,6 @@ public class UpdateOrderCollectionServiceTest extends AbstractRealmServiceTest { arg.orders = orders; - runServiceInAllRealmTypes(svc, arg); + runServiceInAllRealmTypes(UpdateOrderCollectionService.class, arg); } } diff --git a/src/test/java/li/strolch/service/UpdateOrderServiceTest.java b/src/test/java/li/strolch/service/UpdateOrderServiceTest.java index 8d8ac54de..a9706d264 100644 --- a/src/test/java/li/strolch/service/UpdateOrderServiceTest.java +++ b/src/test/java/li/strolch/service/UpdateOrderServiceTest.java @@ -29,10 +29,9 @@ public class UpdateOrderServiceTest extends AbstractRealmServiceTest { @Test public void runTest() { - UpdateOrderService svc = new UpdateOrderService(); UpdateOrderArg arg = new UpdateOrderArg(); arg.order = ModelGenerator.createOrder("myCarOrder", "Modified Car Order", "ProductionOrder"); - runServiceInAllRealmTypes(svc, arg); + runServiceInAllRealmTypes(UpdateOrderService.class, arg); } } diff --git a/src/test/java/li/strolch/service/UpdateResourceCollectionServiceTest.java b/src/test/java/li/strolch/service/UpdateResourceCollectionServiceTest.java index a8ff7ed23..76ebbc0fb 100644 --- a/src/test/java/li/strolch/service/UpdateResourceCollectionServiceTest.java +++ b/src/test/java/li/strolch/service/UpdateResourceCollectionServiceTest.java @@ -32,7 +32,6 @@ public class UpdateResourceCollectionServiceTest extends AbstractRealmServiceTes @Test public void runTest() { - UpdateResourceCollectionService svc = new UpdateResourceCollectionService(); UpdateResourceCollectionArg arg = new UpdateResourceCollectionArg(); ArrayList resources = new ArrayList<>(); @@ -42,6 +41,6 @@ public class UpdateResourceCollectionServiceTest extends AbstractRealmServiceTes arg.resources = resources; - runServiceInAllRealmTypes(svc, arg); + runServiceInAllRealmTypes(UpdateResourceCollectionService.class, arg); } } diff --git a/src/test/java/li/strolch/service/UpdateResourceServiceTest.java b/src/test/java/li/strolch/service/UpdateResourceServiceTest.java index 526d20b5e..d8c763577 100644 --- a/src/test/java/li/strolch/service/UpdateResourceServiceTest.java +++ b/src/test/java/li/strolch/service/UpdateResourceServiceTest.java @@ -29,10 +29,9 @@ public class UpdateResourceServiceTest extends AbstractRealmServiceTest { @Test public void runTest() { - UpdateResourceService svc = new UpdateResourceService(); UpdateResourceArg arg = new UpdateResourceArg(); arg.resource = ModelGenerator.createResource("yellow", "Modified Yellow Ball", "Ball"); - runServiceInAllRealmTypes(svc, arg); + runServiceInAllRealmTypes(UpdateResourceService.class, arg); } } diff --git a/src/test/java/li/strolch/service/XmlExportModelServiceTest.java b/src/test/java/li/strolch/service/XmlExportModelServiceTest.java index cb7b0a969..0c7f4970a 100644 --- a/src/test/java/li/strolch/service/XmlExportModelServiceTest.java +++ b/src/test/java/li/strolch/service/XmlExportModelServiceTest.java @@ -49,12 +49,11 @@ public class XmlExportModelServiceTest extends AbstractRealmServiceTest { } }; - XmlExportModelService svc = new XmlExportModelService(); XmlExportModelArgument arg = new XmlExportModelArgument(); arg.modelFileName = TMP_XML_EXPORT_XML; arg.multiFile = true; - runServiceInAllRealmTypes(svc, arg, before, null, null); + runServiceInAllRealmTypes(XmlExportModelService.class, arg, before, null, null); } @Test @@ -75,7 +74,7 @@ public class XmlExportModelServiceTest extends AbstractRealmServiceTest { arg.multiFile = true; arg.modelFileName = TMP_XML_EXPORT_XML; - ServiceResult result = getServiceHandler().doService(null, svc, arg); + ServiceResult result = getServiceHandler().doService(certificate, svc, arg); assertServiceResult(ServiceResultState.FAILED, ServiceResult.class, result); assertThat(result.getMessage(), containsString("Model File already exists with name")); } @@ -98,7 +97,7 @@ public class XmlExportModelServiceTest extends AbstractRealmServiceTest { arg.multiFile = true; arg.modelFileName = TMP_XML_EXPORT_XML; - ServiceResult result = getServiceHandler().doService(null, svc, arg); + ServiceResult result = getServiceHandler().doService(certificate, svc, arg); assertServiceResult(ServiceResultState.SUCCESS, ServiceResult.class, result); } } diff --git a/src/test/java/li/strolch/service/XmlImportModelServiceTest.java b/src/test/java/li/strolch/service/XmlImportModelServiceTest.java index 5dab73c82..71041c263 100644 --- a/src/test/java/li/strolch/service/XmlImportModelServiceTest.java +++ b/src/test/java/li/strolch/service/XmlImportModelServiceTest.java @@ -27,10 +27,9 @@ public class XmlImportModelServiceTest extends AbstractRealmServiceTest { @Test public void runTest() { - XmlImportModelService svc = new XmlImportModelService(); XmlImportModelArgument arg = new XmlImportModelArgument(); arg.modelFileName = "Enums.xml"; - runServiceInAllRealmTypes(svc, arg); + runServiceInAllRealmTypes(XmlImportModelService.class, arg); } } diff --git a/src/test/java/li/strolch/service/test/AbstractRealmServiceTest.java b/src/test/java/li/strolch/service/test/AbstractRealmServiceTest.java index c6e5fcf29..11214b6a2 100644 --- a/src/test/java/li/strolch/service/test/AbstractRealmServiceTest.java +++ b/src/test/java/li/strolch/service/test/AbstractRealmServiceTest.java @@ -37,6 +37,8 @@ import li.strolch.testbase.runtime.RuntimeMock; import org.junit.After; import org.junit.Before; +import ch.eitchnet.privilege.model.Certificate; + /** * @author Robert von Burg */ @@ -49,6 +51,7 @@ public abstract class AbstractRealmServiceTest { 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 { @@ -62,8 +65,9 @@ public abstract class AbstractRealmServiceTest { runtimeMock.mockRuntime(rootPath, configSrc); runtimeMock.startContainer(); - importFromXml(REALM_CACHED, getServiceHandler()); - importFromXml(REALM_TRANSACTIONAL, getServiceHandler()); + certificate = runtimeMock.getPrivilegeHandler().authenticate("test", "test".getBytes()); + importFromXml(REALM_CACHED, certificate, getServiceHandler()); + importFromXml(REALM_TRANSACTIONAL, certificate, getServiceHandler()); } @After @@ -79,13 +83,13 @@ public abstract class AbstractRealmServiceTest { } } - public static void importFromXml(String realm, ServiceHandler serviceHandler) { + 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(null, svc, arg); + ServiceResult result = serviceHandler.doService(certificate, svc, arg); assertServiceResult(ServiceResultState.SUCCESS, ServiceResult.class, result); } @@ -97,7 +101,8 @@ public abstract class AbstractRealmServiceTest { before.run(runtimeMock.getContainer().getRealm(realm), runtimeMock.getContainer()); arg.realm = realm; - ServiceResult result = getServiceHandler().doService(null, svc, arg); + + ServiceResult result = getServiceHandler().doService(certificate, svc, arg); assertServiceResult(expectedState, expectedServiceResultType, result); if (validator != null) @@ -115,17 +120,21 @@ public abstract class AbstractRealmServiceTest { public void run(StrolchRealm strolchRealm, ComponentContainer container); } - protected void runServiceInAllRealmTypes(Service svc, - T arg) { - runServiceInAllRealmTypes(svc, arg, null, null, null); + protected void runServiceInAllRealmTypes( + Class> svcClass, T arg) { + runServiceInAllRealmTypes(svcClass, arg, null, null, null); } - protected void runServiceInAllRealmTypes(Service svc, - T arg, Runner before, Runner validator, Runner after) { + protected void runServiceInAllRealmTypes( + Class> svcClass, T arg, Runner before, Runner validator, Runner after) { - runTransient(svc, arg, before, validator, after); - runCached(svc, arg, before, validator, after); - runTransactional(svc, arg, before, validator, 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, diff --git a/src/test/java/li/strolch/service/test/LockingTest.java b/src/test/java/li/strolch/service/test/LockingTest.java index 3d6e5c944..dae86accf 100644 --- a/src/test/java/li/strolch/service/test/LockingTest.java +++ b/src/test/java/li/strolch/service/test/LockingTest.java @@ -37,6 +37,8 @@ import org.junit.AfterClass; import org.junit.BeforeClass; import org.junit.Test; +import ch.eitchnet.privilege.model.Certificate; + /** * @author Robert von Burg */ @@ -69,6 +71,10 @@ public class LockingTest { return runtimeMock.getContainer().getComponent(ServiceHandler.class); } + public static Certificate login() { + return runtimeMock.getPrivilegeHandler().authenticate("admin", "admin".getBytes()); + } + @Test public void shouldLockElements() throws InterruptedException { @@ -112,7 +118,7 @@ public class LockingTest { LockingArgumentTest arg = new LockingArgumentTest(); arg.longRunning = false; arg.resourceLoc = Locator.valueOf(RESOURCE_LOCATOR); - ServiceResult result = getServiceHandler().doService(null, svc, arg); + ServiceResult result = getServiceHandler().doService(login(), svc, arg); assertEquals(ServiceResultState.SUCCESS, result.getState()); } @@ -140,7 +146,7 @@ public class LockingTest { continue; } - this.result = getServiceHandler().doService(null, svc, arg); + this.result = getServiceHandler().doService(login(), svc, arg); } public ServiceResult getResult() { diff --git a/src/test/java/li/strolch/service/test/NoPrivilegeServiceTest.java b/src/test/java/li/strolch/service/test/NoPrivilegeServiceTest.java deleted file mode 100644 index 247b08deb..000000000 --- a/src/test/java/li/strolch/service/test/NoPrivilegeServiceTest.java +++ /dev/null @@ -1,72 +0,0 @@ -/* - * 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 java.io.File; - -import li.strolch.service.api.ServiceHandler; -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.testbase.runtime.RuntimeMock; - -import org.junit.AfterClass; -import org.junit.BeforeClass; -import org.junit.Test; - -/** - * @author Robert von Burg - * - */ -public class NoPrivilegeServiceTest { - - private static final String RUNTIME_PATH = "target/strolchRuntime/"; //$NON-NLS-1$ - private static final String CONFIG_SRC = "src/test/resources/withoutPrivilegeRuntime"; //$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); - } - - @Test - public void shouldPerformSimpleService() { - - GreetingService greetingService = new GreetingService(); - GreetingArgument greetingArgument = new GreetingArgument(); - greetingArgument.name = "Robert"; //$NON-NLS-1$ - - GreetingResult greetingResult = getServiceHandler().doService(null, greetingService, greetingArgument); - assertThat(greetingResult.getGreeting(), containsString("Hello Robert. Nice to meet you!")); //$NON-NLS-1$ - } -} diff --git a/src/test/java/li/strolch/service/test/ServiceTest.java b/src/test/java/li/strolch/service/test/ServiceTest.java index 0446c5ee5..f42d240fc 100644 --- a/src/test/java/li/strolch/service/test/ServiceTest.java +++ b/src/test/java/li/strolch/service/test/ServiceTest.java @@ -49,14 +49,15 @@ public class ServiceTest extends AbstractServiceTest { public void shouldFailInvalidCertificate1() { this.thrown.expect(PrivilegeException.class); TestService testService = new TestService(); - getServiceHandler().doService(new Certificate(null, 0, null, null, null, null), 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", "dsdf", null, null); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ + 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); } diff --git a/src/test/java/li/strolch/service/test/XmlExportServiceTest.java b/src/test/java/li/strolch/service/test/XmlExportServiceTest.java index 43e517e3a..bdba1736d 100644 --- a/src/test/java/li/strolch/service/test/XmlExportServiceTest.java +++ b/src/test/java/li/strolch/service/test/XmlExportServiceTest.java @@ -33,6 +33,8 @@ import org.junit.AfterClass; import org.junit.BeforeClass; import org.junit.Test; +import ch.eitchnet.privilege.model.Certificate; + /** * @author Robert von Burg */ @@ -41,6 +43,7 @@ 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() { @@ -50,6 +53,8 @@ public class XmlExportServiceTest { runtimeMock = new RuntimeMock(); runtimeMock.mockRuntime(rootPath, configSrc); runtimeMock.startContainer(); + + certificate = runtimeMock.getPrivilegeHandler().authenticate("admin", "admin".getBytes()); } @AfterClass @@ -64,7 +69,7 @@ public class XmlExportServiceTest { XmlExportModelArgument arg = new XmlExportModelArgument(); arg.modelFileName = "TestExportSingle.xml"; arg.multiFile = false; - ServiceResult result = runtimeMock.getServiceHandler().doService(null, service, arg); + ServiceResult result = runtimeMock.getServiceHandler().doService(certificate, service, arg); RuntimeMock.assertServiceResult(ServiceResultState.SUCCESS, ServiceResult.class, result); assertNumberOfFilesCreated(arg.modelFileName.split("\\.")[0], 1); @@ -78,7 +83,7 @@ public class XmlExportServiceTest { XmlExportModelArgument arg = new XmlExportModelArgument(); arg.modelFileName = "TestExportMulti.xml"; arg.multiFile = true; - ServiceResult result = runtimeMock.getServiceHandler().doService(null, service, arg); + ServiceResult result = runtimeMock.getServiceHandler().doService(certificate, service, arg); RuntimeMock.assertServiceResult(ServiceResultState.SUCCESS, ServiceResult.class, result); assertNumberOfFilesCreated(arg.modelFileName.split("\\.")[0], 6); @@ -94,7 +99,7 @@ public class XmlExportServiceTest { arg.doOrders = false; arg.resourceTypes.add(StrolchConstants.TEMPLATE); arg.multiFile = true; - ServiceResult result = runtimeMock.getServiceHandler().doService(null, service, arg); + ServiceResult result = runtimeMock.getServiceHandler().doService(certificate, service, arg); RuntimeMock.assertServiceResult(ServiceResultState.SUCCESS, ServiceResult.class, result); assertNumberOfFilesCreated(arg.modelFileName.split("\\.")[0], 2); @@ -105,7 +110,7 @@ public class XmlExportServiceTest { XmlImportModelService importService = new XmlImportModelService(); XmlImportModelArgument importArgument = new XmlImportModelArgument(); importArgument.modelFileName = modelFileName; - ServiceResult result = runtimeMock.getServiceHandler().doService(null, importService, importArgument); + ServiceResult result = runtimeMock.getServiceHandler().doService(certificate, importService, importArgument); RuntimeMock.assertServiceResult(ServiceResultState.SUCCESS, ServiceResult.class, result); } diff --git a/src/test/java/li/strolch/service/test/parameter/AddParameterServiceTest.java b/src/test/java/li/strolch/service/test/parameter/AddParameterServiceTest.java index 173184569..88b8c287b 100644 --- a/src/test/java/li/strolch/service/test/parameter/AddParameterServiceTest.java +++ b/src/test/java/li/strolch/service/test/parameter/AddParameterServiceTest.java @@ -31,7 +31,6 @@ public class AddParameterServiceTest extends AbstractRealmServiceTest { @Test public void runTest() { - AddParameterService svc = new AddParameterService(); AddParameterArg arg = new AddParameterArg(); arg.locator = Locator.valueOf("Resource/Ball/yellow/Bag/parameters"); FloatParameter parameter = new FloatParameter("diameter", "Diameter", 22.0); @@ -39,6 +38,6 @@ public class AddParameterServiceTest extends AbstractRealmServiceTest { parameter.setUom("cm"); arg.parameter = parameter; - runServiceInAllRealmTypes(svc, arg); + runServiceInAllRealmTypes(AddParameterService.class, arg); } } diff --git a/src/test/java/li/strolch/service/test/parameter/RemoveParameterServiceTest.java b/src/test/java/li/strolch/service/test/parameter/RemoveParameterServiceTest.java index 4ffbd1103..c67dc683c 100644 --- a/src/test/java/li/strolch/service/test/parameter/RemoveParameterServiceTest.java +++ b/src/test/java/li/strolch/service/test/parameter/RemoveParameterServiceTest.java @@ -30,10 +30,9 @@ public class RemoveParameterServiceTest extends AbstractRealmServiceTest { @Test public void runTest() { - RemoveParameterService svc = new RemoveParameterService(); RemoveParameterArg arg = new RemoveParameterArg(); arg.locator = Locator.valueOf("Resource/Ball/yellow/Bag/parameters/owner"); - runServiceInAllRealmTypes(svc, arg); + runServiceInAllRealmTypes(RemoveParameterService.class, arg); } } diff --git a/src/test/java/li/strolch/service/test/parameter/SetParameterServiceTest.java b/src/test/java/li/strolch/service/test/parameter/SetParameterServiceTest.java index 35e01a24a..02edd123a 100644 --- a/src/test/java/li/strolch/service/test/parameter/SetParameterServiceTest.java +++ b/src/test/java/li/strolch/service/test/parameter/SetParameterServiceTest.java @@ -30,7 +30,6 @@ public class SetParameterServiceTest extends AbstractRealmServiceTest { @Test public void runTest() { - SetParameterService svc = new SetParameterService(); SetParameterArg arg = new SetParameterArg(); arg.locator = Locator.valueOf("Resource/Ball/yellow/Bag/parameters/owner"); arg.name = "The Owner"; @@ -40,6 +39,6 @@ public class SetParameterServiceTest extends AbstractRealmServiceTest { arg.index = 99; arg.valueAsString = "someotherdude"; - runServiceInAllRealmTypes(svc, arg); + runServiceInAllRealmTypes(SetParameterService.class, arg); } } diff --git a/src/test/resources/svctest/config/PrivilegeConfig.xml b/src/test/resources/svctest/config/PrivilegeConfig.xml new file mode 100644 index 000000000..9d7a227e3 --- /dev/null +++ b/src/test/resources/svctest/config/PrivilegeConfig.xml @@ -0,0 +1,30 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/test/resources/svctest/config/PrivilegeModel.xml b/src/test/resources/svctest/config/PrivilegeModel.xml new file mode 100644 index 000000000..14af39def --- /dev/null +++ b/src/test/resources/svctest/config/PrivilegeModel.xml @@ -0,0 +1,36 @@ + + + + + + SYSTEM + + agent + + + + Application + Administrator + ENABLED + en_GB + + PrivilegeAdmin + AppUser + + + + + + + + + true + + + + + true + + + + \ No newline at end of file diff --git a/src/test/resources/svctest/config/StrolchConfiguration.xml b/src/test/resources/svctest/config/StrolchConfiguration.xml index 32aa61182..05ece3354 100644 --- a/src/test/resources/svctest/config/StrolchConfiguration.xml +++ b/src/test/resources/svctest/config/StrolchConfiguration.xml @@ -7,10 +7,19 @@ true + + PrivilegeHandler + li.strolch.runtime.privilege.PrivilegeHandler + li.strolch.runtime.privilege.DefaultStrolchPrivilegeHandler + + PrivilegeConfig.xml + + RealmHandler li.strolch.agent.api.RealmHandler li.strolch.agent.impl.DefaultRealmHandler + PrivilegeHandler PersistenceHandler svcTransient, svcCached, svcTransactional diff --git a/src/test/resources/transienttest/config/PrivilegeConfig.xml b/src/test/resources/transienttest/config/PrivilegeConfig.xml new file mode 100644 index 000000000..9d7a227e3 --- /dev/null +++ b/src/test/resources/transienttest/config/PrivilegeConfig.xml @@ -0,0 +1,30 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/test/resources/transienttest/config/PrivilegeModel.xml b/src/test/resources/transienttest/config/PrivilegeModel.xml new file mode 100644 index 000000000..bac84f10c --- /dev/null +++ b/src/test/resources/transienttest/config/PrivilegeModel.xml @@ -0,0 +1,36 @@ + + + + + + SYSTEM + + agent + + + + Application + Administrator + ENABLED + en_GB + + PrivilegeAdmin + AppUser + + + + + + + + + true + + + + + true + + + + \ No newline at end of file diff --git a/src/test/resources/transienttest/config/StrolchConfiguration.xml b/src/test/resources/transienttest/config/StrolchConfiguration.xml index 86118942a..39d3e63c9 100644 --- a/src/test/resources/transienttest/config/StrolchConfiguration.xml +++ b/src/test/resources/transienttest/config/StrolchConfiguration.xml @@ -7,10 +7,19 @@ true + + PrivilegeHandler + li.strolch.runtime.privilege.PrivilegeHandler + li.strolch.runtime.privilege.DefaultStrolchPrivilegeHandler + + PrivilegeConfig.xml + + RealmHandler li.strolch.agent.api.RealmHandler li.strolch.agent.impl.DefaultRealmHandler + PrivilegeHandler SECONDS 1 diff --git a/src/test/resources/withPrivilegeRuntime/config/PrivilegeModel.xml b/src/test/resources/withPrivilegeRuntime/config/PrivilegeModel.xml index c4e79dd20..cdcdf2886 100644 --- a/src/test/resources/withPrivilegeRuntime/config/PrivilegeModel.xml +++ b/src/test/resources/withPrivilegeRuntime/config/PrivilegeModel.xml @@ -2,10 +2,16 @@ + + SYSTEM + + agent + + Application - Administrator + Administrator ENABLED en_GB @@ -20,7 +26,7 @@ Bob - Bernstein + Bernstein ENABLED en_GB @@ -30,7 +36,7 @@ Jill - Johnson + Johnson ENABLED en_GB @@ -40,7 +46,7 @@ System User - Administrator + Administrator SYSTEM en_GB @@ -52,18 +58,19 @@ - - + + + true + + true - - li.strolch.service.test.model.GreetingService diff --git a/src/test/resources/withPrivilegeRuntime/config/StrolchConfiguration.xml b/src/test/resources/withPrivilegeRuntime/config/StrolchConfiguration.xml index f9d6bfb1a..011cff011 100644 --- a/src/test/resources/withPrivilegeRuntime/config/StrolchConfiguration.xml +++ b/src/test/resources/withPrivilegeRuntime/config/StrolchConfiguration.xml @@ -7,10 +7,19 @@ true + + PrivilegeHandler + li.strolch.runtime.privilege.PrivilegeHandler + li.strolch.runtime.privilege.DefaultStrolchPrivilegeHandler + + PrivilegeConfig.xml + + RealmHandler li.strolch.agent.api.RealmHandler li.strolch.agent.impl.DefaultRealmHandler + PrivilegeHandler EMPTY @@ -24,13 +33,5 @@ true - - PrivilegeHandler - li.strolch.runtime.privilege.StrolchPrivilegeHandler - li.strolch.runtime.privilege.DefaultStrolchPrivilegeHandler - - PrivilegeConfig.xml - - \ No newline at end of file diff --git a/src/test/resources/withoutPrivilegeRuntime/config/StrolchConfiguration.xml b/src/test/resources/withoutPrivilegeRuntime/config/StrolchConfiguration.xml deleted file mode 100644 index 9248f6f3e..000000000 --- a/src/test/resources/withoutPrivilegeRuntime/config/StrolchConfiguration.xml +++ /dev/null @@ -1,27 +0,0 @@ - - - - - StrolchPersistenceTest - - true - - - - RealmHandler - li.strolch.agent.api.RealmHandler - li.strolch.agent.impl.DefaultRealmHandler - - EMPTY - - - - ServiceHandler - li.strolch.service.api.ServiceHandler - li.strolch.service.api.DefaultServiceHandler - - true - - - - \ No newline at end of file From b623d4ce32bed61e0573447fc3b12f98cdff14a0 Mon Sep 17 00:00:00 2001 From: Robert von Burg Date: Sun, 24 Aug 2014 17:24:06 +0200 Subject: [PATCH 61/65] [Project] set version to 1.0.0-SNAPSHOT --- pom.xml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index 0e01bddc6..fff3be74b 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ li.strolch li.strolch.parent - 0.1.0-SNAPSHOT + 1.0.0-SNAPSHOT ../li.strolch.parent/pom.xml @@ -30,7 +30,7 @@ - + li.strolch li.strolch.model @@ -49,6 +49,7 @@ ch.eitchnet.privilege + li.strolch li.strolch.testbase From 757a2c6a2a6f0ad6e9781a1a5a36e07fad7bd6e3 Mon Sep 17 00:00:00 2001 From: Robert von Burg Date: Sun, 24 Aug 2014 18:28:04 +0200 Subject: [PATCH 62/65] [Project] set version to 1.0.0-SNAPSHOT --- pom.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/pom.xml b/pom.xml index fff3be74b..af7876f4f 100644 --- a/pom.xml +++ b/pom.xml @@ -72,6 +72,7 @@ + org.codehaus.mojo From 9b70f04b5390f4829de544eb87793279cc33091e Mon Sep 17 00:00:00 2001 From: Robert von Burg Date: Mon, 8 Sep 2014 13:36:07 +0200 Subject: [PATCH 63/65] [New] Added privilege checking for StrolchQueries --- src/test/resources/svctest/config/PrivilegeModel.xml | 3 +++ src/test/resources/transienttest/config/PrivilegeModel.xml | 3 +++ .../resources/withPrivilegeRuntime/config/PrivilegeModel.xml | 3 +++ 3 files changed, 9 insertions(+) diff --git a/src/test/resources/svctest/config/PrivilegeModel.xml b/src/test/resources/svctest/config/PrivilegeModel.xml index 14af39def..0ed6ce7b2 100644 --- a/src/test/resources/svctest/config/PrivilegeModel.xml +++ b/src/test/resources/svctest/config/PrivilegeModel.xml @@ -31,6 +31,9 @@ true + + true +
\ No newline at end of file diff --git a/src/test/resources/transienttest/config/PrivilegeModel.xml b/src/test/resources/transienttest/config/PrivilegeModel.xml index bac84f10c..45d20b677 100644 --- a/src/test/resources/transienttest/config/PrivilegeModel.xml +++ b/src/test/resources/transienttest/config/PrivilegeModel.xml @@ -31,6 +31,9 @@ true + + true + \ No newline at end of file diff --git a/src/test/resources/withPrivilegeRuntime/config/PrivilegeModel.xml b/src/test/resources/withPrivilegeRuntime/config/PrivilegeModel.xml index cdcdf2886..997ed3810 100644 --- a/src/test/resources/withPrivilegeRuntime/config/PrivilegeModel.xml +++ b/src/test/resources/withPrivilegeRuntime/config/PrivilegeModel.xml @@ -68,6 +68,9 @@ true + + true + From dd7eef9cf368f5a930fb242bdc0ccb63d78c4810 Mon Sep 17 00:00:00 2001 From: Robert von Burg Date: Sun, 14 Sep 2014 12:20:53 +0200 Subject: [PATCH 64/65] [Minor] code cleanup --- .../li/strolch/command/AddOrderCommand.java | 2 +- .../command/AddResourceCollectionCommand.java | 4 ++-- .../strolch/command/AddResourceCommand.java | 2 +- .../command/RemoveOrderCollectionCommand.java | 4 ++-- .../strolch/command/RemoveOrderCommand.java | 2 +- .../RemoveResourceCollectionCommand.java | 4 ++-- .../command/RemoveResourceCommand.java | 2 +- .../command/UpdateOrderCollectionCommand.java | 6 +++--- .../strolch/command/UpdateOrderCommand.java | 4 ++-- .../UpdateResourceCollectionCommand.java | 4 ++-- .../command/UpdateResourceCommand.java | 4 ++-- .../command/XmlExportModelCommand.java | 20 +++++++++---------- .../command/XmlImportModelCommand.java | 16 +++++++-------- .../parameter/AddParameterCommand.java | 2 +- .../parameter/RemoveParameterCommand.java | 2 +- .../parameter/SetParameterCommand.java | 6 +++--- .../command/visitor/UpdateElementVisitor.java | 4 ++-- .../command/AbstractRealmCommandTest.java | 4 ++-- .../AddOrderCollectionCommandTest.java | 10 +++++----- .../strolch/command/AddOrderCommandTest.java | 4 ++-- .../AddResourceCollectionCommandTest.java | 10 +++++----- .../command/AddResourceCommandTest.java | 4 ++-- .../RemoveOrderCollectionCommandTest.java | 12 +++++------ .../command/RemoveOrderCommandTest.java | 4 ++-- .../RemoveResourceCollectionCommandTest.java | 10 +++++----- .../command/RemoveResourceCommandTest.java | 4 ++-- .../UpdateOrderCollectionCommandTest.java | 10 +++++----- .../command/UpdateOrderCommandTest.java | 4 ++-- .../UpdateResourceCollectionCommandTest.java | 10 +++++----- .../command/UpdateResourceCommandTest.java | 4 ++-- .../parameter/AddParameterCommandTest.java | 5 ++--- .../parameter/RemoveParameterCommandTest.java | 4 ++-- .../parameter/SetParameterCommandTest.java | 5 ++--- .../service/ClearModelServiceTest.java | 6 +++--- .../service/XmlExportModelServiceTest.java | 4 ++-- .../test/AbstractRealmServiceTest.java | 8 ++++---- .../li/strolch/service/test/LockingTest.java | 2 +- .../li/strolch/service/test/ServiceTest.java | 2 +- 38 files changed, 106 insertions(+), 108 deletions(-) diff --git a/src/main/java/li/strolch/command/AddOrderCommand.java b/src/main/java/li/strolch/command/AddOrderCommand.java index 4a740f9c2..96a12dcde 100644 --- a/src/main/java/li/strolch/command/AddOrderCommand.java +++ b/src/main/java/li/strolch/command/AddOrderCommand.java @@ -55,7 +55,7 @@ public class AddOrderCommand extends Command { @Override public void doCommand() { - tx().lock(order); + tx().lock(this.order); OrderMap orderMap = tx().getOrderMap(); if (orderMap.hasElement(tx(), this.order.getType(), this.order.getId())) { diff --git a/src/main/java/li/strolch/command/AddResourceCollectionCommand.java b/src/main/java/li/strolch/command/AddResourceCollectionCommand.java index 5c4474f49..e3c15b5fa 100644 --- a/src/main/java/li/strolch/command/AddResourceCollectionCommand.java +++ b/src/main/java/li/strolch/command/AddResourceCollectionCommand.java @@ -61,14 +61,14 @@ public class AddResourceCollectionCommand extends Command { } ResourceMap resourceMap = tx().getResourceMap(); - for (Resource resource : resources) { + 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(), resources); + resourceMap.addAll(tx(), this.resources); } @Override diff --git a/src/main/java/li/strolch/command/AddResourceCommand.java b/src/main/java/li/strolch/command/AddResourceCommand.java index a3fb5c032..efed9e001 100644 --- a/src/main/java/li/strolch/command/AddResourceCommand.java +++ b/src/main/java/li/strolch/command/AddResourceCommand.java @@ -55,7 +55,7 @@ public class AddResourceCommand extends Command { @Override public void doCommand() { - tx().lock(resource); + tx().lock(this.resource); ResourceMap resourceMap = tx().getResourceMap(); if (resourceMap.hasElement(tx(), this.resource.getType(), this.resource.getId())) { diff --git a/src/main/java/li/strolch/command/RemoveOrderCollectionCommand.java b/src/main/java/li/strolch/command/RemoveOrderCollectionCommand.java index fd0e84c7f..fd0b73b9e 100644 --- a/src/main/java/li/strolch/command/RemoveOrderCollectionCommand.java +++ b/src/main/java/li/strolch/command/RemoveOrderCollectionCommand.java @@ -61,7 +61,7 @@ public class RemoveOrderCollectionCommand extends Command { } OrderMap orderMap = tx().getOrderMap(); - for (Order order : orders) { + 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()); @@ -69,7 +69,7 @@ public class RemoveOrderCollectionCommand extends Command { } } - orderMap.removeAll(tx(), orders); + orderMap.removeAll(tx(), this.orders); } @Override diff --git a/src/main/java/li/strolch/command/RemoveOrderCommand.java b/src/main/java/li/strolch/command/RemoveOrderCommand.java index 63d434927..908aa7958 100644 --- a/src/main/java/li/strolch/command/RemoveOrderCommand.java +++ b/src/main/java/li/strolch/command/RemoveOrderCommand.java @@ -55,7 +55,7 @@ public class RemoveOrderCommand extends Command { @Override public void doCommand() { - tx().lock(order); + tx().lock(this.order); OrderMap orderMap = tx().getOrderMap(); if (!orderMap.hasElement(tx(), this.order.getType(), this.order.getId())) { diff --git a/src/main/java/li/strolch/command/RemoveResourceCollectionCommand.java b/src/main/java/li/strolch/command/RemoveResourceCollectionCommand.java index 4f21762a7..438746af5 100644 --- a/src/main/java/li/strolch/command/RemoveResourceCollectionCommand.java +++ b/src/main/java/li/strolch/command/RemoveResourceCollectionCommand.java @@ -61,7 +61,7 @@ public class RemoveResourceCollectionCommand extends Command { } ResourceMap resourceMap = tx().getResourceMap(); - for (Resource resource : resources) { + 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()); @@ -69,7 +69,7 @@ public class RemoveResourceCollectionCommand extends Command { } } - resourceMap.removeAll(tx(), resources); + resourceMap.removeAll(tx(), this.resources); } @Override diff --git a/src/main/java/li/strolch/command/RemoveResourceCommand.java b/src/main/java/li/strolch/command/RemoveResourceCommand.java index 796e49acc..1a0e5b2b4 100644 --- a/src/main/java/li/strolch/command/RemoveResourceCommand.java +++ b/src/main/java/li/strolch/command/RemoveResourceCommand.java @@ -55,7 +55,7 @@ public class RemoveResourceCommand extends Command { @Override public void doCommand() { - tx().lock(resource); + tx().lock(this.resource); ResourceMap resourceMap = tx().getResourceMap(); if (!resourceMap.hasElement(tx(), this.resource.getType(), this.resource.getId())) { diff --git a/src/main/java/li/strolch/command/UpdateOrderCollectionCommand.java b/src/main/java/li/strolch/command/UpdateOrderCollectionCommand.java index 35035950a..693af78dd 100644 --- a/src/main/java/li/strolch/command/UpdateOrderCollectionCommand.java +++ b/src/main/java/li/strolch/command/UpdateOrderCollectionCommand.java @@ -62,7 +62,7 @@ public class UpdateOrderCollectionCommand extends Command { } OrderMap orderMap = tx().getOrderMap(); - for (Order order : orders) { + 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()); @@ -70,14 +70,14 @@ public class UpdateOrderCollectionCommand extends Command { } } - replacedElements = orderMap.updateAll(tx(), orders); + this.replacedElements = orderMap.updateAll(tx(), this.orders); } @Override public void undo() { if (this.replacedElements != null && tx().isRollingBack()) { OrderMap orderMap = tx().getOrderMap(); - orderMap.updateAll(tx(), replacedElements); + orderMap.updateAll(tx(), this.replacedElements); } } } diff --git a/src/main/java/li/strolch/command/UpdateOrderCommand.java b/src/main/java/li/strolch/command/UpdateOrderCommand.java index 2eb297d62..48c81ffd2 100644 --- a/src/main/java/li/strolch/command/UpdateOrderCommand.java +++ b/src/main/java/li/strolch/command/UpdateOrderCommand.java @@ -56,7 +56,7 @@ public class UpdateOrderCommand extends Command { @Override public void doCommand() { - tx().lock(order); + tx().lock(this.order); OrderMap orderMap = tx().getOrderMap(); if (!orderMap.hasElement(tx(), this.order.getType(), this.order.getId())) { @@ -71,7 +71,7 @@ public class UpdateOrderCommand extends Command { @Override public void undo() { if (this.replacedElement != null && tx().isRollingBack()) { - tx().getOrderMap().update(tx(), replacedElement); + tx().getOrderMap().update(tx(), this.replacedElement); } } } diff --git a/src/main/java/li/strolch/command/UpdateResourceCollectionCommand.java b/src/main/java/li/strolch/command/UpdateResourceCollectionCommand.java index b72b599ee..031ca510c 100644 --- a/src/main/java/li/strolch/command/UpdateResourceCollectionCommand.java +++ b/src/main/java/li/strolch/command/UpdateResourceCollectionCommand.java @@ -70,14 +70,14 @@ public class UpdateResourceCollectionCommand extends Command { } } - this.replacedElements = resourceMap.updateAll(tx(), resources); + this.replacedElements = resourceMap.updateAll(tx(), this.resources); } @Override public void undo() { if (this.replacedElements != null && tx().isRollingBack()) { ResourceMap resourceMap = tx().getResourceMap(); - resourceMap.updateAll(tx(), replacedElements); + resourceMap.updateAll(tx(), this.replacedElements); } } } diff --git a/src/main/java/li/strolch/command/UpdateResourceCommand.java b/src/main/java/li/strolch/command/UpdateResourceCommand.java index e3d2c830f..6c3194ee9 100644 --- a/src/main/java/li/strolch/command/UpdateResourceCommand.java +++ b/src/main/java/li/strolch/command/UpdateResourceCommand.java @@ -56,7 +56,7 @@ public class UpdateResourceCommand extends Command { @Override public void doCommand() { - tx().lock(resource); + tx().lock(this.resource); ResourceMap resourceMap = tx().getResourceMap(); if (!resourceMap.hasElement(tx(), this.resource.getType(), this.resource.getId())) { @@ -71,7 +71,7 @@ public class UpdateResourceCommand extends Command { @Override public void undo() { if (this.replacedElement != null && tx().isRollingBack()) { - tx().getResourceMap().update(tx(), replacedElement); + tx().getResourceMap().update(tx(), this.replacedElement); } } } diff --git a/src/main/java/li/strolch/command/XmlExportModelCommand.java b/src/main/java/li/strolch/command/XmlExportModelCommand.java index 8bc55471f..7f2408b0c 100644 --- a/src/main/java/li/strolch/command/XmlExportModelCommand.java +++ b/src/main/java/li/strolch/command/XmlExportModelCommand.java @@ -122,7 +122,7 @@ public class XmlExportModelCommand extends Command { if (!this.resourceTypes.isEmpty()) resourceTypesToExport.retainAll(this.resourceTypes); for (String type : resourceTypesToExport) { - nrOfResourcesToExport += resourceMap.querySize(tx(), type); + this.nrOfResourcesToExport += resourceMap.querySize(tx(), type); } } @@ -133,14 +133,14 @@ public class XmlExportModelCommand extends Command { orderTypesToExport.retainAll(this.orderTypes); for (String type : orderTypesToExport) { - nrOfOrdersToExport += orderMap.querySize(tx(), type); + this.nrOfOrdersToExport += orderMap.querySize(tx(), type); } } - this.elementsToWrite = nrOfResourcesToExport + nrOfOrdersToExport; - logger.info("Exporting " + elementsToWrite + " Elements..."); - logger.info("Exporting " + nrOfResourcesToExport + " Resources..."); - logger.info("Exporting " + nrOfOrdersToExport + " Orders..."); + 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); @@ -156,7 +156,7 @@ public class XmlExportModelCommand extends Command { resourceTypesToExport = new TreeSet<>(resourceTypesToExport); for (String type : resourceTypesToExport) { - if (!multiFile) { + if (!this.multiFile) { writeResourcesByType(writer, resourceMap, type); } else { String typeXmlFile = exportName + UNDERLINE + Tags.RESOURCE + UNDERLINE + type @@ -164,7 +164,7 @@ public class XmlExportModelCommand extends Command { writer.writeEmptyElement(Tags.INCLUDE_FILE); writer.writeAttribute(Tags.FILE, typeXmlFile); - File typeXmlFileF = new File(modelFile.getParentFile(), 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() + "..."); @@ -187,14 +187,14 @@ public class XmlExportModelCommand extends Command { orderTypesToExport = new TreeSet<>(orderTypesToExport); for (String type : orderTypesToExport) { - if (!multiFile) { + 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(modelFile.getParentFile(), 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() + "..."); diff --git a/src/main/java/li/strolch/command/XmlImportModelCommand.java b/src/main/java/li/strolch/command/XmlImportModelCommand.java index cba03a295..802321513 100644 --- a/src/main/java/li/strolch/command/XmlImportModelCommand.java +++ b/src/main/java/li/strolch/command/XmlImportModelCommand.java @@ -61,17 +61,17 @@ public class XmlImportModelCommand extends Command { InMemoryElementListener elementListener = new InMemoryElementListener(tx()); - elementListener.setAddOrders(addOrders); - elementListener.setAddResources(addResources); - elementListener.setUpdateOrders(updateOrders); - elementListener.setUpdateResources(updateResources); - elementListener.setOrderTypes(orderTypes); - elementListener.setResourceTypes(resourceTypes); + 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, modelFile); + XmlModelSaxFileReader handler = new XmlModelSaxFileReader(elementListener, this.modelFile); handler.parseFile(); - statistics = handler.getStatistics(); + this.statistics = handler.getStatistics(); } @Override diff --git a/src/main/java/li/strolch/command/parameter/AddParameterCommand.java b/src/main/java/li/strolch/command/parameter/AddParameterCommand.java index 115157884..491220c54 100644 --- a/src/main/java/li/strolch/command/parameter/AddParameterCommand.java +++ b/src/main/java/li/strolch/command/parameter/AddParameterCommand.java @@ -79,7 +79,7 @@ public class AddParameterCommand extends Command { tx().lock(rootElement); this.element.addParameter(this.parameter); - replacedElement = new UpdateElementVisitor(tx()).update(rootElement); + this.replacedElement = new UpdateElementVisitor(tx()).update(rootElement); } @Override diff --git a/src/main/java/li/strolch/command/parameter/RemoveParameterCommand.java b/src/main/java/li/strolch/command/parameter/RemoveParameterCommand.java index 1b20520df..5ce3c0347 100644 --- a/src/main/java/li/strolch/command/parameter/RemoveParameterCommand.java +++ b/src/main/java/li/strolch/command/parameter/RemoveParameterCommand.java @@ -81,7 +81,7 @@ public class RemoveParameterCommand extends Command { tx().lock(rootElement); this.removedParameter = this.element.removeParameter(this.parameterId); - replacedElement = new UpdateElementVisitor(tx()).update(rootElement); + this.replacedElement = new UpdateElementVisitor(tx()).update(rootElement); } @Override diff --git a/src/main/java/li/strolch/command/parameter/SetParameterCommand.java b/src/main/java/li/strolch/command/parameter/SetParameterCommand.java index a6f576882..a40b415f3 100644 --- a/src/main/java/li/strolch/command/parameter/SetParameterCommand.java +++ b/src/main/java/li/strolch/command/parameter/SetParameterCommand.java @@ -114,7 +114,7 @@ public class SetParameterCommand extends Command { @Override public void validate() { - DBC.PRE.assertNotNull("Parameter may not be null!", this.parameter); + DBC.PRE.assertNotNull("Parameter may not be null!", this.parameter); //$NON-NLS-1$ } @Override @@ -151,7 +151,7 @@ public class SetParameterCommand extends Command { } if (hasChanges()) { - replacedElement = new UpdateElementVisitor(tx()).update(rootElement); + this.replacedElement = new UpdateElementVisitor(tx()).update(rootElement); } } @@ -186,7 +186,7 @@ public class SetParameterCommand extends Command { } if (hasChanges() && this.replacedElement != null && this.replacedElement != this.parameter.getRootElement()) { - new UpdateElementVisitor(tx()).update(replacedElement); + new UpdateElementVisitor(tx()).update(this.replacedElement); } } } diff --git a/src/main/java/li/strolch/command/visitor/UpdateElementVisitor.java b/src/main/java/li/strolch/command/visitor/UpdateElementVisitor.java index 97a2e1e93..347f98840 100644 --- a/src/main/java/li/strolch/command/visitor/UpdateElementVisitor.java +++ b/src/main/java/li/strolch/command/visitor/UpdateElementVisitor.java @@ -38,11 +38,11 @@ public class UpdateElementVisitor implements StrolchRootElementVisitor(); - orders.add(ModelGenerator.createOrder("firstOrder", "First Order", "AdditionalOrders")); - orders.add(ModelGenerator.createOrder("secondOrder", "Second Order", "AdditionalOrders")); - orders.add(ModelGenerator.createOrder("thirdOrder", "Third Order", "AdditionalOrders")); + 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(orders); + command.setOrders(this.orders); return command; } } diff --git a/src/test/java/li/strolch/command/AddOrderCommandTest.java b/src/test/java/li/strolch/command/AddOrderCommandTest.java index 43a92c659..b5c1f9e4a 100644 --- a/src/test/java/li/strolch/command/AddOrderCommandTest.java +++ b/src/test/java/li/strolch/command/AddOrderCommandTest.java @@ -32,14 +32,14 @@ public class AddOrderCommandTest extends AbstractRealmCommandTest { @Before public void before() { - order = ModelGenerator.createOrder("firstOrder", "First Order", "AdditionalOrders"); + this.order = ModelGenerator.createOrder("firstOrder", "First Order", "AdditionalOrders"); } @Override protected Command getCommandInstance(ComponentContainer container, StrolchTransaction tx) { AddOrderCommand command = new AddOrderCommand(container, tx); - command.setOrder(order); + command.setOrder(this.order); return command; } } diff --git a/src/test/java/li/strolch/command/AddResourceCollectionCommandTest.java b/src/test/java/li/strolch/command/AddResourceCollectionCommandTest.java index 00c39607a..6ec764e60 100644 --- a/src/test/java/li/strolch/command/AddResourceCollectionCommandTest.java +++ b/src/test/java/li/strolch/command/AddResourceCollectionCommandTest.java @@ -35,17 +35,17 @@ public class AddResourceCollectionCommandTest extends AbstractRealmCommandTest { @Before public void before() { - 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")); + 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(resources); + command.setResources(this.resources); return command; } } diff --git a/src/test/java/li/strolch/command/AddResourceCommandTest.java b/src/test/java/li/strolch/command/AddResourceCommandTest.java index d76adbc7f..fde80a188 100644 --- a/src/test/java/li/strolch/command/AddResourceCommandTest.java +++ b/src/test/java/li/strolch/command/AddResourceCommandTest.java @@ -32,14 +32,14 @@ public class AddResourceCommandTest extends AbstractRealmCommandTest { @Before public void before() { - resource = ModelGenerator.createResource("firstRes", "First Resource", "AdditionalResources"); + this.resource = ModelGenerator.createResource("firstRes", "First Resource", "AdditionalResources"); } @Override protected Command getCommandInstance(ComponentContainer container, StrolchTransaction tx) { AddResourceCommand command = new AddResourceCommand(container, tx); - command.setResource(resource); + command.setResource(this.resource); return command; } } diff --git a/src/test/java/li/strolch/command/RemoveOrderCollectionCommandTest.java b/src/test/java/li/strolch/command/RemoveOrderCollectionCommandTest.java index 246bf8461..d8ee42a12 100644 --- a/src/test/java/li/strolch/command/RemoveOrderCollectionCommandTest.java +++ b/src/test/java/li/strolch/command/RemoveOrderCollectionCommandTest.java @@ -36,17 +36,17 @@ public class RemoveOrderCollectionCommandTest extends AbstractRealmCommandTest { @Before public void before() { - 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()); + 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<>(locators.size()); - for (Locator locator : locators) { + List orders = new ArrayList<>(this.locators.size()); + for (Locator locator : this.locators) { orders.add((Order) tx.findElement(locator)); } diff --git a/src/test/java/li/strolch/command/RemoveOrderCommandTest.java b/src/test/java/li/strolch/command/RemoveOrderCommandTest.java index abb4c7b2f..bfd9ade35 100644 --- a/src/test/java/li/strolch/command/RemoveOrderCommandTest.java +++ b/src/test/java/li/strolch/command/RemoveOrderCommandTest.java @@ -33,13 +33,13 @@ public class RemoveOrderCommandTest extends AbstractRealmCommandTest { @Before public void before() { - locator = Locator.newBuilder(Tags.ORDER, "TestType", "@3").build(); + this.locator = Locator.newBuilder(Tags.ORDER, "TestType", "@3").build(); } @Override protected Command getCommandInstance(ComponentContainer container, StrolchTransaction tx) { - Order order = tx.findElement(locator); + Order order = tx.findElement(this.locator); RemoveOrderCommand command = new RemoveOrderCommand(container, tx); command.setOrder(order); diff --git a/src/test/java/li/strolch/command/RemoveResourceCollectionCommandTest.java b/src/test/java/li/strolch/command/RemoveResourceCollectionCommandTest.java index c84024b51..9df74efd8 100644 --- a/src/test/java/li/strolch/command/RemoveResourceCollectionCommandTest.java +++ b/src/test/java/li/strolch/command/RemoveResourceCollectionCommandTest.java @@ -36,16 +36,16 @@ public class RemoveResourceCollectionCommandTest extends AbstractRealmCommandTes @Before public void before() { - 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()); + 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<>(locators.size()); + List resources = new ArrayList<>(this.locators.size()); for (Locator locator : this.locators) { resources.add((Resource) tx.findElement(locator)); } diff --git a/src/test/java/li/strolch/command/RemoveResourceCommandTest.java b/src/test/java/li/strolch/command/RemoveResourceCommandTest.java index 803430df3..6731f2e3f 100644 --- a/src/test/java/li/strolch/command/RemoveResourceCommandTest.java +++ b/src/test/java/li/strolch/command/RemoveResourceCommandTest.java @@ -33,13 +33,13 @@ public class RemoveResourceCommandTest extends AbstractRealmCommandTest { @Before public void before() { - locator = Locator.newBuilder(Tags.RESOURCE, "Enumeration", "sex").build(); + this.locator = Locator.newBuilder(Tags.RESOURCE, "Enumeration", "sex").build(); } @Override protected Command getCommandInstance(ComponentContainer container, StrolchTransaction tx) { - Resource resource = tx.findElement(locator); + Resource resource = tx.findElement(this.locator); RemoveResourceCommand command = new RemoveResourceCommand(container, tx); command.setResource(resource); diff --git a/src/test/java/li/strolch/command/UpdateOrderCollectionCommandTest.java b/src/test/java/li/strolch/command/UpdateOrderCollectionCommandTest.java index 81b315c59..f05219655 100644 --- a/src/test/java/li/strolch/command/UpdateOrderCollectionCommandTest.java +++ b/src/test/java/li/strolch/command/UpdateOrderCollectionCommandTest.java @@ -35,17 +35,17 @@ public class UpdateOrderCollectionCommandTest extends AbstractRealmCommandTest { @Before public void before() { - 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")); + 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(orders); + command.setOrders(this.orders); return command; } } diff --git a/src/test/java/li/strolch/command/UpdateOrderCommandTest.java b/src/test/java/li/strolch/command/UpdateOrderCommandTest.java index 25a01e21e..0bc9c40c9 100644 --- a/src/test/java/li/strolch/command/UpdateOrderCommandTest.java +++ b/src/test/java/li/strolch/command/UpdateOrderCommandTest.java @@ -32,14 +32,14 @@ public class UpdateOrderCommandTest extends AbstractRealmCommandTest { @Before public void before() { - order = ModelGenerator.createOrder("myCarOrder", "Modified Car Order", "ProductionOrder"); + 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(order); + command.setOrder(this.order); return command; } } diff --git a/src/test/java/li/strolch/command/UpdateResourceCollectionCommandTest.java b/src/test/java/li/strolch/command/UpdateResourceCollectionCommandTest.java index c2c576991..cfaaa636d 100644 --- a/src/test/java/li/strolch/command/UpdateResourceCollectionCommandTest.java +++ b/src/test/java/li/strolch/command/UpdateResourceCollectionCommandTest.java @@ -35,17 +35,17 @@ public class UpdateResourceCollectionCommandTest extends AbstractRealmCommandTes @Before public void before() { - 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")); + 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(resources); + command.setResources(this.resources); return command; } } diff --git a/src/test/java/li/strolch/command/UpdateResourceCommandTest.java b/src/test/java/li/strolch/command/UpdateResourceCommandTest.java index 85156d5f8..a144a62aa 100644 --- a/src/test/java/li/strolch/command/UpdateResourceCommandTest.java +++ b/src/test/java/li/strolch/command/UpdateResourceCommandTest.java @@ -32,14 +32,14 @@ public class UpdateResourceCommandTest extends AbstractRealmCommandTest { @Before public void before() { - resource = ModelGenerator.createResource("yellow", "Modified Yellow Ball", "Ball"); + 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(resource); + command.setResource(this.resource); return command; } } diff --git a/src/test/java/li/strolch/command/parameter/AddParameterCommandTest.java b/src/test/java/li/strolch/command/parameter/AddParameterCommandTest.java index 2eff247d1..7689a162e 100644 --- a/src/test/java/li/strolch/command/parameter/AddParameterCommandTest.java +++ b/src/test/java/li/strolch/command/parameter/AddParameterCommandTest.java @@ -17,7 +17,6 @@ package li.strolch.command.parameter; import li.strolch.agent.api.ComponentContainer; import li.strolch.command.AbstractRealmCommandTest; -import li.strolch.command.parameter.AddParameterCommand; import li.strolch.model.Locator; import li.strolch.model.ParameterizedElement; import li.strolch.model.parameter.BooleanParameter; @@ -44,11 +43,11 @@ public class AddParameterCommandTest extends AbstractRealmCommandTest { @Override protected Command getCommandInstance(ComponentContainer container, StrolchTransaction tx) { - ParameterizedElement element = tx.findElement(locator); + ParameterizedElement element = tx.findElement(this.locator); AddParameterCommand command = new AddParameterCommand(container, tx); command.setElement(element); - command.setParameter(parameter); + command.setParameter(this.parameter); return command; } } diff --git a/src/test/java/li/strolch/command/parameter/RemoveParameterCommandTest.java b/src/test/java/li/strolch/command/parameter/RemoveParameterCommandTest.java index cd6a9bee8..060f3c60c 100644 --- a/src/test/java/li/strolch/command/parameter/RemoveParameterCommandTest.java +++ b/src/test/java/li/strolch/command/parameter/RemoveParameterCommandTest.java @@ -41,11 +41,11 @@ public class RemoveParameterCommandTest extends AbstractRealmCommandTest { @Override protected Command getCommandInstance(ComponentContainer container, StrolchTransaction tx) { - ParameterizedElement element = tx.findElement(locator); + ParameterizedElement element = tx.findElement(this.locator); RemoveParameterCommand command = new RemoveParameterCommand(container, tx); command.setElement(element); - command.setParameterId(parameterId); + command.setParameterId(this.parameterId); return command; } } diff --git a/src/test/java/li/strolch/command/parameter/SetParameterCommandTest.java b/src/test/java/li/strolch/command/parameter/SetParameterCommandTest.java index d75344e4c..0562101f5 100644 --- a/src/test/java/li/strolch/command/parameter/SetParameterCommandTest.java +++ b/src/test/java/li/strolch/command/parameter/SetParameterCommandTest.java @@ -17,7 +17,6 @@ package li.strolch.command.parameter; import li.strolch.agent.api.ComponentContainer; import li.strolch.command.AbstractRealmCommandTest; -import li.strolch.command.parameter.SetParameterCommand; import li.strolch.model.Locator; import li.strolch.model.parameter.Parameter; import li.strolch.persistence.api.StrolchTransaction; @@ -42,10 +41,10 @@ public class SetParameterCommandTest extends AbstractRealmCommandTest { @Override protected Command getCommandInstance(ComponentContainer container, StrolchTransaction tx) { - Parameter parameter = tx.findElement(locator); + Parameter parameter = tx.findElement(this.locator); SetParameterCommand command = new SetParameterCommand(container, tx); - command.setValueAsString(valueAsString); + command.setValueAsString(this.valueAsString); command.setParameter(parameter); return command; } diff --git a/src/test/java/li/strolch/service/ClearModelServiceTest.java b/src/test/java/li/strolch/service/ClearModelServiceTest.java index 2e4238b77..682c55cf7 100644 --- a/src/test/java/li/strolch/service/ClearModelServiceTest.java +++ b/src/test/java/li/strolch/service/ClearModelServiceTest.java @@ -35,7 +35,7 @@ public class ClearModelServiceTest extends AbstractRealmServiceTest { Runner validator = new Runner() { @Override public void run(StrolchRealm strolchRealm, ComponentContainer container) { - try (StrolchTransaction tx = strolchRealm.openTx(certificate, "test")) { + try (StrolchTransaction tx = strolchRealm.openTx(ClearModelServiceTest.this.certificate, "test")) { assertEquals(0, tx.getResourceMap().querySize(tx)); assertEquals(0, tx.getOrderMap().querySize(tx)); } @@ -55,7 +55,7 @@ public class ClearModelServiceTest extends AbstractRealmServiceTest { Runner validator = new Runner() { @Override public void run(StrolchRealm strolchRealm, ComponentContainer container) { - try (StrolchTransaction tx = strolchRealm.openTx(certificate, "test")) { + try (StrolchTransaction tx = strolchRealm.openTx(ClearModelServiceTest.this.certificate, "test")) { assertNotEquals(0, tx.getResourceMap().querySize(tx)); assertEquals(0, tx.getOrderMap().querySize(tx)); } @@ -75,7 +75,7 @@ public class ClearModelServiceTest extends AbstractRealmServiceTest { Runner validator = new Runner() { @Override public void run(StrolchRealm strolchRealm, ComponentContainer container) { - try (StrolchTransaction tx = strolchRealm.openTx(certificate, "test")) { + try (StrolchTransaction tx = strolchRealm.openTx(ClearModelServiceTest.this.certificate, "test")) { assertNotEquals(0, tx.getOrderMap().querySize(tx)); assertEquals(0, tx.getResourceMap().querySize(tx)); } diff --git a/src/test/java/li/strolch/service/XmlExportModelServiceTest.java b/src/test/java/li/strolch/service/XmlExportModelServiceTest.java index 0c7f4970a..45b9ec6dd 100644 --- a/src/test/java/li/strolch/service/XmlExportModelServiceTest.java +++ b/src/test/java/li/strolch/service/XmlExportModelServiceTest.java @@ -74,7 +74,7 @@ public class XmlExportModelServiceTest extends AbstractRealmServiceTest { arg.multiFile = true; arg.modelFileName = TMP_XML_EXPORT_XML; - ServiceResult result = getServiceHandler().doService(certificate, svc, arg); + ServiceResult result = getServiceHandler().doService(this.certificate, svc, arg); assertServiceResult(ServiceResultState.FAILED, ServiceResult.class, result); assertThat(result.getMessage(), containsString("Model File already exists with name")); } @@ -97,7 +97,7 @@ public class XmlExportModelServiceTest extends AbstractRealmServiceTest { arg.multiFile = true; arg.modelFileName = TMP_XML_EXPORT_XML; - ServiceResult result = getServiceHandler().doService(certificate, svc, arg); + ServiceResult result = getServiceHandler().doService(this.certificate, svc, arg); assertServiceResult(ServiceResultState.SUCCESS, ServiceResult.class, result); } } diff --git a/src/test/java/li/strolch/service/test/AbstractRealmServiceTest.java b/src/test/java/li/strolch/service/test/AbstractRealmServiceTest.java index 11214b6a2..9812160ff 100644 --- a/src/test/java/li/strolch/service/test/AbstractRealmServiceTest.java +++ b/src/test/java/li/strolch/service/test/AbstractRealmServiceTest.java @@ -65,9 +65,9 @@ public abstract class AbstractRealmServiceTest { runtimeMock.mockRuntime(rootPath, configSrc); runtimeMock.startContainer(); - certificate = runtimeMock.getPrivilegeHandler().authenticate("test", "test".getBytes()); - importFromXml(REALM_CACHED, certificate, getServiceHandler()); - importFromXml(REALM_TRANSACTIONAL, certificate, getServiceHandler()); + this.certificate = runtimeMock.getPrivilegeHandler().authenticate("test", "test".getBytes()); + importFromXml(REALM_CACHED, this.certificate, getServiceHandler()); + importFromXml(REALM_TRANSACTIONAL, this.certificate, getServiceHandler()); } @After @@ -102,7 +102,7 @@ public abstract class AbstractRealmServiceTest { arg.realm = realm; - ServiceResult result = getServiceHandler().doService(certificate, svc, arg); + ServiceResult result = getServiceHandler().doService(this.certificate, svc, arg); assertServiceResult(expectedState, expectedServiceResultType, result); if (validator != null) diff --git a/src/test/java/li/strolch/service/test/LockingTest.java b/src/test/java/li/strolch/service/test/LockingTest.java index dae86accf..f4348d228 100644 --- a/src/test/java/li/strolch/service/test/LockingTest.java +++ b/src/test/java/li/strolch/service/test/LockingTest.java @@ -146,7 +146,7 @@ public class LockingTest { continue; } - this.result = getServiceHandler().doService(login(), svc, arg); + this.result = getServiceHandler().doService(login(), this.svc, this.arg); } public ServiceResult getResult() { diff --git a/src/test/java/li/strolch/service/test/ServiceTest.java b/src/test/java/li/strolch/service/test/ServiceTest.java index f42d240fc..f7963a9d4 100644 --- a/src/test/java/li/strolch/service/test/ServiceTest.java +++ b/src/test/java/li/strolch/service/test/ServiceTest.java @@ -19,8 +19,8 @@ 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.TestService; import li.strolch.service.test.model.GreetingService.GreetingArgument; +import li.strolch.service.test.model.TestService; import org.junit.Rule; import org.junit.Test; From fadafe0599119282dbd363776374b66c3a3787ad Mon Sep 17 00:00:00 2001 From: Robert von Burg Date: Tue, 16 Sep 2014 08:53:28 +0200 Subject: [PATCH 65/65] moved everything to a subdirectory for repo merge --- .gitignore => li.strolch.service/.gitignore | 0 LICENSE => li.strolch.service/LICENSE | 0 README.md => li.strolch.service/README.md | 0 pom.xml => li.strolch.service/pom.xml | 0 .../main/java/li/strolch/command/AddOrderCollectionCommand.java | 0 .../src}/main/java/li/strolch/command/AddOrderCommand.java | 0 .../java/li/strolch/command/AddResourceCollectionCommand.java | 0 .../src}/main/java/li/strolch/command/AddResourceCommand.java | 0 .../src}/main/java/li/strolch/command/ClearModelCommand.java | 0 .../java/li/strolch/command/RemoveOrderCollectionCommand.java | 0 .../src}/main/java/li/strolch/command/RemoveOrderCommand.java | 0 .../java/li/strolch/command/RemoveResourceCollectionCommand.java | 0 .../src}/main/java/li/strolch/command/RemoveResourceCommand.java | 0 .../java/li/strolch/command/UpdateOrderCollectionCommand.java | 0 .../src}/main/java/li/strolch/command/UpdateOrderCommand.java | 0 .../java/li/strolch/command/UpdateResourceCollectionCommand.java | 0 .../src}/main/java/li/strolch/command/UpdateResourceCommand.java | 0 .../src}/main/java/li/strolch/command/XmlExportModelCommand.java | 0 .../src}/main/java/li/strolch/command/XmlImportModelCommand.java | 0 .../java/li/strolch/command/parameter/AddParameterCommand.java | 0 .../java/li/strolch/command/parameter/RemoveParameterCommand.java | 0 .../java/li/strolch/command/parameter/SetParameterCommand.java | 0 .../java/li/strolch/command/visitor/UpdateElementVisitor.java | 0 .../main/java/li/strolch/service/AddOrderCollectionService.java | 0 .../src}/main/java/li/strolch/service/AddOrderService.java | 0 .../java/li/strolch/service/AddResourceCollectionService.java | 0 .../src}/main/java/li/strolch/service/AddResourceService.java | 0 .../src}/main/java/li/strolch/service/ClearModelArgument.java | 0 .../src}/main/java/li/strolch/service/ClearModelService.java | 0 .../java/li/strolch/service/RemoveOrderCollectionService.java | 0 .../src}/main/java/li/strolch/service/RemoveOrderService.java | 0 .../java/li/strolch/service/RemoveResourceCollectionService.java | 0 .../src}/main/java/li/strolch/service/RemoveResourceService.java | 0 .../java/li/strolch/service/UpdateOrderCollectionService.java | 0 .../src}/main/java/li/strolch/service/UpdateOrderService.java | 0 .../java/li/strolch/service/UpdateResourceCollectionService.java | 0 .../src}/main/java/li/strolch/service/UpdateResourceService.java | 0 .../src}/main/java/li/strolch/service/XmlExportModelArgument.java | 0 .../src}/main/java/li/strolch/service/XmlExportModelService.java | 0 .../src}/main/java/li/strolch/service/XmlImportModelArgument.java | 0 .../src}/main/java/li/strolch/service/XmlImportModelService.java | 0 .../java/li/strolch/service/parameter/AddParameterService.java | 0 .../java/li/strolch/service/parameter/RemoveParameterService.java | 0 .../java/li/strolch/service/parameter/SetParameterService.java | 0 .../src}/main/resources/componentVersion.properties | 0 .../test/java/li/strolch/command/AbstractRealmCommandTest.java | 0 .../java/li/strolch/command/AddOrderCollectionCommandTest.java | 0 .../src}/test/java/li/strolch/command/AddOrderCommandTest.java | 0 .../java/li/strolch/command/AddResourceCollectionCommandTest.java | 0 .../src}/test/java/li/strolch/command/AddResourceCommandTest.java | 0 .../java/li/strolch/command/RemoveOrderCollectionCommandTest.java | 0 .../src}/test/java/li/strolch/command/RemoveOrderCommandTest.java | 0 .../li/strolch/command/RemoveResourceCollectionCommandTest.java | 0 .../test/java/li/strolch/command/RemoveResourceCommandTest.java | 0 .../java/li/strolch/command/UpdateOrderCollectionCommandTest.java | 0 .../src}/test/java/li/strolch/command/UpdateOrderCommandTest.java | 0 .../li/strolch/command/UpdateResourceCollectionCommandTest.java | 0 .../test/java/li/strolch/command/UpdateResourceCommandTest.java | 0 .../li/strolch/command/parameter/AddParameterCommandTest.java | 0 .../li/strolch/command/parameter/RemoveParameterCommandTest.java | 0 .../li/strolch/command/parameter/SetParameterCommandTest.java | 0 .../java/li/strolch/service/AddOrderCollectionServiceTest.java | 0 .../src}/test/java/li/strolch/service/AddOrderServiceTest.java | 0 .../java/li/strolch/service/AddResourceCollectionServiceTest.java | 0 .../src}/test/java/li/strolch/service/AddResourceServiceTest.java | 0 .../src}/test/java/li/strolch/service/ClearModelServiceTest.java | 0 .../java/li/strolch/service/RemoveOrderCollectionServiceTest.java | 0 .../src}/test/java/li/strolch/service/RemoveOrderServiceTest.java | 0 .../li/strolch/service/RemoveResourceCollectionServiceTest.java | 0 .../test/java/li/strolch/service/RemoveResourceServiceTest.java | 0 .../java/li/strolch/service/UpdateOrderCollectionServiceTest.java | 0 .../src}/test/java/li/strolch/service/UpdateOrderServiceTest.java | 0 .../li/strolch/service/UpdateResourceCollectionServiceTest.java | 0 .../test/java/li/strolch/service/UpdateResourceServiceTest.java | 0 .../test/java/li/strolch/service/XmlExportModelServiceTest.java | 0 .../test/java/li/strolch/service/XmlImportModelServiceTest.java | 0 .../java/li/strolch/service/test/AbstractRealmServiceTest.java | 0 .../test/java/li/strolch/service/test/AbstractServiceTest.java | 0 .../test/java/li/strolch/service/test/GreetingServiceTest.java | 0 .../src}/test/java/li/strolch/service/test/LockingTest.java | 0 .../src}/test/java/li/strolch/service/test/ServiceTest.java | 0 .../test/java/li/strolch/service/test/XmlExportServiceTest.java | 0 .../test/java/li/strolch/service/test/model/GreetingResult.java | 0 .../test/java/li/strolch/service/test/model/GreetingService.java | 0 .../src}/test/java/li/strolch/service/test/model/TestService.java | 0 .../strolch/service/test/parameter/AddParameterServiceTest.java | 0 .../service/test/parameter/RemoveParameterServiceTest.java | 0 .../strolch/service/test/parameter/SetParameterServiceTest.java | 0 {src => li.strolch.service/src}/test/resources/log4j.xml | 0 .../src}/test/resources/svctest/config/PrivilegeConfig.xml | 0 .../src}/test/resources/svctest/config/PrivilegeModel.xml | 0 .../src}/test/resources/svctest/config/StrolchConfiguration.xml | 0 .../src}/test/resources/svctest/data/Enums.xml | 0 .../src}/test/resources/svctest/data/Orders.xml | 0 .../src}/test/resources/svctest/data/Resources.xml | 0 .../src}/test/resources/svctest/data/StrolchModel.xml | 0 .../src}/test/resources/transienttest/config/PrivilegeConfig.xml | 0 .../src}/test/resources/transienttest/config/PrivilegeModel.xml | 0 .../test/resources/transienttest/config/StrolchConfiguration.xml | 0 .../src}/test/resources/transienttest/data/Enums.xml | 0 .../src}/test/resources/transienttest/data/Orders.xml | 0 .../src}/test/resources/transienttest/data/Resources.xml | 0 .../src}/test/resources/transienttest/data/StrolchModel.xml | 0 .../resources/withPrivilegeRuntime/config/PrivilegeConfig.xml | 0 .../test/resources/withPrivilegeRuntime/config/PrivilegeModel.xml | 0 .../withPrivilegeRuntime/config/StrolchConfiguration.xml | 0 106 files changed, 0 insertions(+), 0 deletions(-) rename .gitignore => li.strolch.service/.gitignore (100%) rename LICENSE => li.strolch.service/LICENSE (100%) rename README.md => li.strolch.service/README.md (100%) rename pom.xml => li.strolch.service/pom.xml (100%) rename {src => li.strolch.service/src}/main/java/li/strolch/command/AddOrderCollectionCommand.java (100%) rename {src => li.strolch.service/src}/main/java/li/strolch/command/AddOrderCommand.java (100%) rename {src => li.strolch.service/src}/main/java/li/strolch/command/AddResourceCollectionCommand.java (100%) rename {src => li.strolch.service/src}/main/java/li/strolch/command/AddResourceCommand.java (100%) rename {src => li.strolch.service/src}/main/java/li/strolch/command/ClearModelCommand.java (100%) rename {src => li.strolch.service/src}/main/java/li/strolch/command/RemoveOrderCollectionCommand.java (100%) rename {src => li.strolch.service/src}/main/java/li/strolch/command/RemoveOrderCommand.java (100%) rename {src => li.strolch.service/src}/main/java/li/strolch/command/RemoveResourceCollectionCommand.java (100%) rename {src => li.strolch.service/src}/main/java/li/strolch/command/RemoveResourceCommand.java (100%) rename {src => li.strolch.service/src}/main/java/li/strolch/command/UpdateOrderCollectionCommand.java (100%) rename {src => li.strolch.service/src}/main/java/li/strolch/command/UpdateOrderCommand.java (100%) rename {src => li.strolch.service/src}/main/java/li/strolch/command/UpdateResourceCollectionCommand.java (100%) rename {src => li.strolch.service/src}/main/java/li/strolch/command/UpdateResourceCommand.java (100%) rename {src => li.strolch.service/src}/main/java/li/strolch/command/XmlExportModelCommand.java (100%) rename {src => li.strolch.service/src}/main/java/li/strolch/command/XmlImportModelCommand.java (100%) rename {src => li.strolch.service/src}/main/java/li/strolch/command/parameter/AddParameterCommand.java (100%) rename {src => li.strolch.service/src}/main/java/li/strolch/command/parameter/RemoveParameterCommand.java (100%) rename {src => li.strolch.service/src}/main/java/li/strolch/command/parameter/SetParameterCommand.java (100%) rename {src => li.strolch.service/src}/main/java/li/strolch/command/visitor/UpdateElementVisitor.java (100%) rename {src => li.strolch.service/src}/main/java/li/strolch/service/AddOrderCollectionService.java (100%) rename {src => li.strolch.service/src}/main/java/li/strolch/service/AddOrderService.java (100%) rename {src => li.strolch.service/src}/main/java/li/strolch/service/AddResourceCollectionService.java (100%) rename {src => li.strolch.service/src}/main/java/li/strolch/service/AddResourceService.java (100%) rename {src => li.strolch.service/src}/main/java/li/strolch/service/ClearModelArgument.java (100%) rename {src => li.strolch.service/src}/main/java/li/strolch/service/ClearModelService.java (100%) rename {src => li.strolch.service/src}/main/java/li/strolch/service/RemoveOrderCollectionService.java (100%) rename {src => li.strolch.service/src}/main/java/li/strolch/service/RemoveOrderService.java (100%) rename {src => li.strolch.service/src}/main/java/li/strolch/service/RemoveResourceCollectionService.java (100%) rename {src => li.strolch.service/src}/main/java/li/strolch/service/RemoveResourceService.java (100%) rename {src => li.strolch.service/src}/main/java/li/strolch/service/UpdateOrderCollectionService.java (100%) rename {src => li.strolch.service/src}/main/java/li/strolch/service/UpdateOrderService.java (100%) rename {src => li.strolch.service/src}/main/java/li/strolch/service/UpdateResourceCollectionService.java (100%) rename {src => li.strolch.service/src}/main/java/li/strolch/service/UpdateResourceService.java (100%) rename {src => li.strolch.service/src}/main/java/li/strolch/service/XmlExportModelArgument.java (100%) rename {src => li.strolch.service/src}/main/java/li/strolch/service/XmlExportModelService.java (100%) rename {src => li.strolch.service/src}/main/java/li/strolch/service/XmlImportModelArgument.java (100%) rename {src => li.strolch.service/src}/main/java/li/strolch/service/XmlImportModelService.java (100%) rename {src => li.strolch.service/src}/main/java/li/strolch/service/parameter/AddParameterService.java (100%) rename {src => li.strolch.service/src}/main/java/li/strolch/service/parameter/RemoveParameterService.java (100%) rename {src => li.strolch.service/src}/main/java/li/strolch/service/parameter/SetParameterService.java (100%) rename {src => li.strolch.service/src}/main/resources/componentVersion.properties (100%) rename {src => li.strolch.service/src}/test/java/li/strolch/command/AbstractRealmCommandTest.java (100%) rename {src => li.strolch.service/src}/test/java/li/strolch/command/AddOrderCollectionCommandTest.java (100%) rename {src => li.strolch.service/src}/test/java/li/strolch/command/AddOrderCommandTest.java (100%) rename {src => li.strolch.service/src}/test/java/li/strolch/command/AddResourceCollectionCommandTest.java (100%) rename {src => li.strolch.service/src}/test/java/li/strolch/command/AddResourceCommandTest.java (100%) rename {src => li.strolch.service/src}/test/java/li/strolch/command/RemoveOrderCollectionCommandTest.java (100%) rename {src => li.strolch.service/src}/test/java/li/strolch/command/RemoveOrderCommandTest.java (100%) rename {src => li.strolch.service/src}/test/java/li/strolch/command/RemoveResourceCollectionCommandTest.java (100%) rename {src => li.strolch.service/src}/test/java/li/strolch/command/RemoveResourceCommandTest.java (100%) rename {src => li.strolch.service/src}/test/java/li/strolch/command/UpdateOrderCollectionCommandTest.java (100%) rename {src => li.strolch.service/src}/test/java/li/strolch/command/UpdateOrderCommandTest.java (100%) rename {src => li.strolch.service/src}/test/java/li/strolch/command/UpdateResourceCollectionCommandTest.java (100%) rename {src => li.strolch.service/src}/test/java/li/strolch/command/UpdateResourceCommandTest.java (100%) rename {src => li.strolch.service/src}/test/java/li/strolch/command/parameter/AddParameterCommandTest.java (100%) rename {src => li.strolch.service/src}/test/java/li/strolch/command/parameter/RemoveParameterCommandTest.java (100%) rename {src => li.strolch.service/src}/test/java/li/strolch/command/parameter/SetParameterCommandTest.java (100%) rename {src => li.strolch.service/src}/test/java/li/strolch/service/AddOrderCollectionServiceTest.java (100%) rename {src => li.strolch.service/src}/test/java/li/strolch/service/AddOrderServiceTest.java (100%) rename {src => li.strolch.service/src}/test/java/li/strolch/service/AddResourceCollectionServiceTest.java (100%) rename {src => li.strolch.service/src}/test/java/li/strolch/service/AddResourceServiceTest.java (100%) rename {src => li.strolch.service/src}/test/java/li/strolch/service/ClearModelServiceTest.java (100%) rename {src => li.strolch.service/src}/test/java/li/strolch/service/RemoveOrderCollectionServiceTest.java (100%) rename {src => li.strolch.service/src}/test/java/li/strolch/service/RemoveOrderServiceTest.java (100%) rename {src => li.strolch.service/src}/test/java/li/strolch/service/RemoveResourceCollectionServiceTest.java (100%) rename {src => li.strolch.service/src}/test/java/li/strolch/service/RemoveResourceServiceTest.java (100%) rename {src => li.strolch.service/src}/test/java/li/strolch/service/UpdateOrderCollectionServiceTest.java (100%) rename {src => li.strolch.service/src}/test/java/li/strolch/service/UpdateOrderServiceTest.java (100%) rename {src => li.strolch.service/src}/test/java/li/strolch/service/UpdateResourceCollectionServiceTest.java (100%) rename {src => li.strolch.service/src}/test/java/li/strolch/service/UpdateResourceServiceTest.java (100%) rename {src => li.strolch.service/src}/test/java/li/strolch/service/XmlExportModelServiceTest.java (100%) rename {src => li.strolch.service/src}/test/java/li/strolch/service/XmlImportModelServiceTest.java (100%) rename {src => li.strolch.service/src}/test/java/li/strolch/service/test/AbstractRealmServiceTest.java (100%) rename {src => li.strolch.service/src}/test/java/li/strolch/service/test/AbstractServiceTest.java (100%) rename {src => li.strolch.service/src}/test/java/li/strolch/service/test/GreetingServiceTest.java (100%) rename {src => li.strolch.service/src}/test/java/li/strolch/service/test/LockingTest.java (100%) rename {src => li.strolch.service/src}/test/java/li/strolch/service/test/ServiceTest.java (100%) rename {src => li.strolch.service/src}/test/java/li/strolch/service/test/XmlExportServiceTest.java (100%) rename {src => li.strolch.service/src}/test/java/li/strolch/service/test/model/GreetingResult.java (100%) rename {src => li.strolch.service/src}/test/java/li/strolch/service/test/model/GreetingService.java (100%) rename {src => li.strolch.service/src}/test/java/li/strolch/service/test/model/TestService.java (100%) rename {src => li.strolch.service/src}/test/java/li/strolch/service/test/parameter/AddParameterServiceTest.java (100%) rename {src => li.strolch.service/src}/test/java/li/strolch/service/test/parameter/RemoveParameterServiceTest.java (100%) rename {src => li.strolch.service/src}/test/java/li/strolch/service/test/parameter/SetParameterServiceTest.java (100%) rename {src => li.strolch.service/src}/test/resources/log4j.xml (100%) rename {src => li.strolch.service/src}/test/resources/svctest/config/PrivilegeConfig.xml (100%) rename {src => li.strolch.service/src}/test/resources/svctest/config/PrivilegeModel.xml (100%) rename {src => li.strolch.service/src}/test/resources/svctest/config/StrolchConfiguration.xml (100%) rename {src => li.strolch.service/src}/test/resources/svctest/data/Enums.xml (100%) rename {src => li.strolch.service/src}/test/resources/svctest/data/Orders.xml (100%) rename {src => li.strolch.service/src}/test/resources/svctest/data/Resources.xml (100%) rename {src => li.strolch.service/src}/test/resources/svctest/data/StrolchModel.xml (100%) rename {src => li.strolch.service/src}/test/resources/transienttest/config/PrivilegeConfig.xml (100%) rename {src => li.strolch.service/src}/test/resources/transienttest/config/PrivilegeModel.xml (100%) rename {src => li.strolch.service/src}/test/resources/transienttest/config/StrolchConfiguration.xml (100%) rename {src => li.strolch.service/src}/test/resources/transienttest/data/Enums.xml (100%) rename {src => li.strolch.service/src}/test/resources/transienttest/data/Orders.xml (100%) rename {src => li.strolch.service/src}/test/resources/transienttest/data/Resources.xml (100%) rename {src => li.strolch.service/src}/test/resources/transienttest/data/StrolchModel.xml (100%) rename {src => li.strolch.service/src}/test/resources/withPrivilegeRuntime/config/PrivilegeConfig.xml (100%) rename {src => li.strolch.service/src}/test/resources/withPrivilegeRuntime/config/PrivilegeModel.xml (100%) rename {src => li.strolch.service/src}/test/resources/withPrivilegeRuntime/config/StrolchConfiguration.xml (100%) diff --git a/.gitignore b/li.strolch.service/.gitignore similarity index 100% rename from .gitignore rename to li.strolch.service/.gitignore diff --git a/LICENSE b/li.strolch.service/LICENSE similarity index 100% rename from LICENSE rename to li.strolch.service/LICENSE diff --git a/README.md b/li.strolch.service/README.md similarity index 100% rename from README.md rename to li.strolch.service/README.md diff --git a/pom.xml b/li.strolch.service/pom.xml similarity index 100% rename from pom.xml rename to li.strolch.service/pom.xml diff --git a/src/main/java/li/strolch/command/AddOrderCollectionCommand.java b/li.strolch.service/src/main/java/li/strolch/command/AddOrderCollectionCommand.java similarity index 100% rename from src/main/java/li/strolch/command/AddOrderCollectionCommand.java rename to li.strolch.service/src/main/java/li/strolch/command/AddOrderCollectionCommand.java diff --git a/src/main/java/li/strolch/command/AddOrderCommand.java b/li.strolch.service/src/main/java/li/strolch/command/AddOrderCommand.java similarity index 100% rename from src/main/java/li/strolch/command/AddOrderCommand.java rename to li.strolch.service/src/main/java/li/strolch/command/AddOrderCommand.java diff --git a/src/main/java/li/strolch/command/AddResourceCollectionCommand.java b/li.strolch.service/src/main/java/li/strolch/command/AddResourceCollectionCommand.java similarity index 100% rename from src/main/java/li/strolch/command/AddResourceCollectionCommand.java rename to li.strolch.service/src/main/java/li/strolch/command/AddResourceCollectionCommand.java diff --git a/src/main/java/li/strolch/command/AddResourceCommand.java b/li.strolch.service/src/main/java/li/strolch/command/AddResourceCommand.java similarity index 100% rename from src/main/java/li/strolch/command/AddResourceCommand.java rename to li.strolch.service/src/main/java/li/strolch/command/AddResourceCommand.java diff --git a/src/main/java/li/strolch/command/ClearModelCommand.java b/li.strolch.service/src/main/java/li/strolch/command/ClearModelCommand.java similarity index 100% rename from src/main/java/li/strolch/command/ClearModelCommand.java rename to li.strolch.service/src/main/java/li/strolch/command/ClearModelCommand.java diff --git a/src/main/java/li/strolch/command/RemoveOrderCollectionCommand.java b/li.strolch.service/src/main/java/li/strolch/command/RemoveOrderCollectionCommand.java similarity index 100% rename from src/main/java/li/strolch/command/RemoveOrderCollectionCommand.java rename to li.strolch.service/src/main/java/li/strolch/command/RemoveOrderCollectionCommand.java diff --git a/src/main/java/li/strolch/command/RemoveOrderCommand.java b/li.strolch.service/src/main/java/li/strolch/command/RemoveOrderCommand.java similarity index 100% rename from src/main/java/li/strolch/command/RemoveOrderCommand.java rename to li.strolch.service/src/main/java/li/strolch/command/RemoveOrderCommand.java diff --git a/src/main/java/li/strolch/command/RemoveResourceCollectionCommand.java b/li.strolch.service/src/main/java/li/strolch/command/RemoveResourceCollectionCommand.java similarity index 100% rename from src/main/java/li/strolch/command/RemoveResourceCollectionCommand.java rename to li.strolch.service/src/main/java/li/strolch/command/RemoveResourceCollectionCommand.java diff --git a/src/main/java/li/strolch/command/RemoveResourceCommand.java b/li.strolch.service/src/main/java/li/strolch/command/RemoveResourceCommand.java similarity index 100% rename from src/main/java/li/strolch/command/RemoveResourceCommand.java rename to li.strolch.service/src/main/java/li/strolch/command/RemoveResourceCommand.java diff --git a/src/main/java/li/strolch/command/UpdateOrderCollectionCommand.java b/li.strolch.service/src/main/java/li/strolch/command/UpdateOrderCollectionCommand.java similarity index 100% rename from src/main/java/li/strolch/command/UpdateOrderCollectionCommand.java rename to li.strolch.service/src/main/java/li/strolch/command/UpdateOrderCollectionCommand.java diff --git a/src/main/java/li/strolch/command/UpdateOrderCommand.java b/li.strolch.service/src/main/java/li/strolch/command/UpdateOrderCommand.java similarity index 100% rename from src/main/java/li/strolch/command/UpdateOrderCommand.java rename to li.strolch.service/src/main/java/li/strolch/command/UpdateOrderCommand.java diff --git a/src/main/java/li/strolch/command/UpdateResourceCollectionCommand.java b/li.strolch.service/src/main/java/li/strolch/command/UpdateResourceCollectionCommand.java similarity index 100% rename from src/main/java/li/strolch/command/UpdateResourceCollectionCommand.java rename to li.strolch.service/src/main/java/li/strolch/command/UpdateResourceCollectionCommand.java diff --git a/src/main/java/li/strolch/command/UpdateResourceCommand.java b/li.strolch.service/src/main/java/li/strolch/command/UpdateResourceCommand.java similarity index 100% rename from src/main/java/li/strolch/command/UpdateResourceCommand.java rename to li.strolch.service/src/main/java/li/strolch/command/UpdateResourceCommand.java diff --git a/src/main/java/li/strolch/command/XmlExportModelCommand.java b/li.strolch.service/src/main/java/li/strolch/command/XmlExportModelCommand.java similarity index 100% rename from src/main/java/li/strolch/command/XmlExportModelCommand.java rename to li.strolch.service/src/main/java/li/strolch/command/XmlExportModelCommand.java diff --git a/src/main/java/li/strolch/command/XmlImportModelCommand.java b/li.strolch.service/src/main/java/li/strolch/command/XmlImportModelCommand.java similarity index 100% rename from src/main/java/li/strolch/command/XmlImportModelCommand.java rename to li.strolch.service/src/main/java/li/strolch/command/XmlImportModelCommand.java diff --git a/src/main/java/li/strolch/command/parameter/AddParameterCommand.java b/li.strolch.service/src/main/java/li/strolch/command/parameter/AddParameterCommand.java similarity index 100% rename from src/main/java/li/strolch/command/parameter/AddParameterCommand.java rename to li.strolch.service/src/main/java/li/strolch/command/parameter/AddParameterCommand.java diff --git a/src/main/java/li/strolch/command/parameter/RemoveParameterCommand.java b/li.strolch.service/src/main/java/li/strolch/command/parameter/RemoveParameterCommand.java similarity index 100% rename from src/main/java/li/strolch/command/parameter/RemoveParameterCommand.java rename to li.strolch.service/src/main/java/li/strolch/command/parameter/RemoveParameterCommand.java diff --git a/src/main/java/li/strolch/command/parameter/SetParameterCommand.java b/li.strolch.service/src/main/java/li/strolch/command/parameter/SetParameterCommand.java similarity index 100% rename from src/main/java/li/strolch/command/parameter/SetParameterCommand.java rename to li.strolch.service/src/main/java/li/strolch/command/parameter/SetParameterCommand.java diff --git a/src/main/java/li/strolch/command/visitor/UpdateElementVisitor.java b/li.strolch.service/src/main/java/li/strolch/command/visitor/UpdateElementVisitor.java similarity index 100% rename from src/main/java/li/strolch/command/visitor/UpdateElementVisitor.java rename to li.strolch.service/src/main/java/li/strolch/command/visitor/UpdateElementVisitor.java diff --git a/src/main/java/li/strolch/service/AddOrderCollectionService.java b/li.strolch.service/src/main/java/li/strolch/service/AddOrderCollectionService.java similarity index 100% rename from src/main/java/li/strolch/service/AddOrderCollectionService.java rename to li.strolch.service/src/main/java/li/strolch/service/AddOrderCollectionService.java diff --git a/src/main/java/li/strolch/service/AddOrderService.java b/li.strolch.service/src/main/java/li/strolch/service/AddOrderService.java similarity index 100% rename from src/main/java/li/strolch/service/AddOrderService.java rename to li.strolch.service/src/main/java/li/strolch/service/AddOrderService.java diff --git a/src/main/java/li/strolch/service/AddResourceCollectionService.java b/li.strolch.service/src/main/java/li/strolch/service/AddResourceCollectionService.java similarity index 100% rename from src/main/java/li/strolch/service/AddResourceCollectionService.java rename to li.strolch.service/src/main/java/li/strolch/service/AddResourceCollectionService.java diff --git a/src/main/java/li/strolch/service/AddResourceService.java b/li.strolch.service/src/main/java/li/strolch/service/AddResourceService.java similarity index 100% rename from src/main/java/li/strolch/service/AddResourceService.java rename to li.strolch.service/src/main/java/li/strolch/service/AddResourceService.java diff --git a/src/main/java/li/strolch/service/ClearModelArgument.java b/li.strolch.service/src/main/java/li/strolch/service/ClearModelArgument.java similarity index 100% rename from src/main/java/li/strolch/service/ClearModelArgument.java rename to li.strolch.service/src/main/java/li/strolch/service/ClearModelArgument.java diff --git a/src/main/java/li/strolch/service/ClearModelService.java b/li.strolch.service/src/main/java/li/strolch/service/ClearModelService.java similarity index 100% rename from src/main/java/li/strolch/service/ClearModelService.java rename to li.strolch.service/src/main/java/li/strolch/service/ClearModelService.java diff --git a/src/main/java/li/strolch/service/RemoveOrderCollectionService.java b/li.strolch.service/src/main/java/li/strolch/service/RemoveOrderCollectionService.java similarity index 100% rename from src/main/java/li/strolch/service/RemoveOrderCollectionService.java rename to li.strolch.service/src/main/java/li/strolch/service/RemoveOrderCollectionService.java diff --git a/src/main/java/li/strolch/service/RemoveOrderService.java b/li.strolch.service/src/main/java/li/strolch/service/RemoveOrderService.java similarity index 100% rename from src/main/java/li/strolch/service/RemoveOrderService.java rename to li.strolch.service/src/main/java/li/strolch/service/RemoveOrderService.java diff --git a/src/main/java/li/strolch/service/RemoveResourceCollectionService.java b/li.strolch.service/src/main/java/li/strolch/service/RemoveResourceCollectionService.java similarity index 100% rename from src/main/java/li/strolch/service/RemoveResourceCollectionService.java rename to li.strolch.service/src/main/java/li/strolch/service/RemoveResourceCollectionService.java diff --git a/src/main/java/li/strolch/service/RemoveResourceService.java b/li.strolch.service/src/main/java/li/strolch/service/RemoveResourceService.java similarity index 100% rename from src/main/java/li/strolch/service/RemoveResourceService.java rename to li.strolch.service/src/main/java/li/strolch/service/RemoveResourceService.java diff --git a/src/main/java/li/strolch/service/UpdateOrderCollectionService.java b/li.strolch.service/src/main/java/li/strolch/service/UpdateOrderCollectionService.java similarity index 100% rename from src/main/java/li/strolch/service/UpdateOrderCollectionService.java rename to li.strolch.service/src/main/java/li/strolch/service/UpdateOrderCollectionService.java diff --git a/src/main/java/li/strolch/service/UpdateOrderService.java b/li.strolch.service/src/main/java/li/strolch/service/UpdateOrderService.java similarity index 100% rename from src/main/java/li/strolch/service/UpdateOrderService.java rename to li.strolch.service/src/main/java/li/strolch/service/UpdateOrderService.java diff --git a/src/main/java/li/strolch/service/UpdateResourceCollectionService.java b/li.strolch.service/src/main/java/li/strolch/service/UpdateResourceCollectionService.java similarity index 100% rename from src/main/java/li/strolch/service/UpdateResourceCollectionService.java rename to li.strolch.service/src/main/java/li/strolch/service/UpdateResourceCollectionService.java diff --git a/src/main/java/li/strolch/service/UpdateResourceService.java b/li.strolch.service/src/main/java/li/strolch/service/UpdateResourceService.java similarity index 100% rename from src/main/java/li/strolch/service/UpdateResourceService.java rename to li.strolch.service/src/main/java/li/strolch/service/UpdateResourceService.java diff --git a/src/main/java/li/strolch/service/XmlExportModelArgument.java b/li.strolch.service/src/main/java/li/strolch/service/XmlExportModelArgument.java similarity index 100% rename from src/main/java/li/strolch/service/XmlExportModelArgument.java rename to li.strolch.service/src/main/java/li/strolch/service/XmlExportModelArgument.java diff --git a/src/main/java/li/strolch/service/XmlExportModelService.java b/li.strolch.service/src/main/java/li/strolch/service/XmlExportModelService.java similarity index 100% rename from src/main/java/li/strolch/service/XmlExportModelService.java rename to li.strolch.service/src/main/java/li/strolch/service/XmlExportModelService.java diff --git a/src/main/java/li/strolch/service/XmlImportModelArgument.java b/li.strolch.service/src/main/java/li/strolch/service/XmlImportModelArgument.java similarity index 100% rename from src/main/java/li/strolch/service/XmlImportModelArgument.java rename to li.strolch.service/src/main/java/li/strolch/service/XmlImportModelArgument.java diff --git a/src/main/java/li/strolch/service/XmlImportModelService.java b/li.strolch.service/src/main/java/li/strolch/service/XmlImportModelService.java similarity index 100% rename from src/main/java/li/strolch/service/XmlImportModelService.java rename to li.strolch.service/src/main/java/li/strolch/service/XmlImportModelService.java diff --git a/src/main/java/li/strolch/service/parameter/AddParameterService.java b/li.strolch.service/src/main/java/li/strolch/service/parameter/AddParameterService.java similarity index 100% rename from src/main/java/li/strolch/service/parameter/AddParameterService.java rename to li.strolch.service/src/main/java/li/strolch/service/parameter/AddParameterService.java diff --git a/src/main/java/li/strolch/service/parameter/RemoveParameterService.java b/li.strolch.service/src/main/java/li/strolch/service/parameter/RemoveParameterService.java similarity index 100% rename from src/main/java/li/strolch/service/parameter/RemoveParameterService.java rename to li.strolch.service/src/main/java/li/strolch/service/parameter/RemoveParameterService.java diff --git a/src/main/java/li/strolch/service/parameter/SetParameterService.java b/li.strolch.service/src/main/java/li/strolch/service/parameter/SetParameterService.java similarity index 100% rename from src/main/java/li/strolch/service/parameter/SetParameterService.java rename to li.strolch.service/src/main/java/li/strolch/service/parameter/SetParameterService.java diff --git a/src/main/resources/componentVersion.properties b/li.strolch.service/src/main/resources/componentVersion.properties similarity index 100% rename from src/main/resources/componentVersion.properties rename to li.strolch.service/src/main/resources/componentVersion.properties diff --git a/src/test/java/li/strolch/command/AbstractRealmCommandTest.java b/li.strolch.service/src/test/java/li/strolch/command/AbstractRealmCommandTest.java similarity index 100% rename from src/test/java/li/strolch/command/AbstractRealmCommandTest.java rename to li.strolch.service/src/test/java/li/strolch/command/AbstractRealmCommandTest.java diff --git a/src/test/java/li/strolch/command/AddOrderCollectionCommandTest.java b/li.strolch.service/src/test/java/li/strolch/command/AddOrderCollectionCommandTest.java similarity index 100% rename from src/test/java/li/strolch/command/AddOrderCollectionCommandTest.java rename to li.strolch.service/src/test/java/li/strolch/command/AddOrderCollectionCommandTest.java diff --git a/src/test/java/li/strolch/command/AddOrderCommandTest.java b/li.strolch.service/src/test/java/li/strolch/command/AddOrderCommandTest.java similarity index 100% rename from src/test/java/li/strolch/command/AddOrderCommandTest.java rename to li.strolch.service/src/test/java/li/strolch/command/AddOrderCommandTest.java diff --git a/src/test/java/li/strolch/command/AddResourceCollectionCommandTest.java b/li.strolch.service/src/test/java/li/strolch/command/AddResourceCollectionCommandTest.java similarity index 100% rename from src/test/java/li/strolch/command/AddResourceCollectionCommandTest.java rename to li.strolch.service/src/test/java/li/strolch/command/AddResourceCollectionCommandTest.java diff --git a/src/test/java/li/strolch/command/AddResourceCommandTest.java b/li.strolch.service/src/test/java/li/strolch/command/AddResourceCommandTest.java similarity index 100% rename from src/test/java/li/strolch/command/AddResourceCommandTest.java rename to li.strolch.service/src/test/java/li/strolch/command/AddResourceCommandTest.java diff --git a/src/test/java/li/strolch/command/RemoveOrderCollectionCommandTest.java b/li.strolch.service/src/test/java/li/strolch/command/RemoveOrderCollectionCommandTest.java similarity index 100% rename from src/test/java/li/strolch/command/RemoveOrderCollectionCommandTest.java rename to li.strolch.service/src/test/java/li/strolch/command/RemoveOrderCollectionCommandTest.java diff --git a/src/test/java/li/strolch/command/RemoveOrderCommandTest.java b/li.strolch.service/src/test/java/li/strolch/command/RemoveOrderCommandTest.java similarity index 100% rename from src/test/java/li/strolch/command/RemoveOrderCommandTest.java rename to li.strolch.service/src/test/java/li/strolch/command/RemoveOrderCommandTest.java diff --git a/src/test/java/li/strolch/command/RemoveResourceCollectionCommandTest.java b/li.strolch.service/src/test/java/li/strolch/command/RemoveResourceCollectionCommandTest.java similarity index 100% rename from src/test/java/li/strolch/command/RemoveResourceCollectionCommandTest.java rename to li.strolch.service/src/test/java/li/strolch/command/RemoveResourceCollectionCommandTest.java diff --git a/src/test/java/li/strolch/command/RemoveResourceCommandTest.java b/li.strolch.service/src/test/java/li/strolch/command/RemoveResourceCommandTest.java similarity index 100% rename from src/test/java/li/strolch/command/RemoveResourceCommandTest.java rename to li.strolch.service/src/test/java/li/strolch/command/RemoveResourceCommandTest.java diff --git a/src/test/java/li/strolch/command/UpdateOrderCollectionCommandTest.java b/li.strolch.service/src/test/java/li/strolch/command/UpdateOrderCollectionCommandTest.java similarity index 100% rename from src/test/java/li/strolch/command/UpdateOrderCollectionCommandTest.java rename to li.strolch.service/src/test/java/li/strolch/command/UpdateOrderCollectionCommandTest.java diff --git a/src/test/java/li/strolch/command/UpdateOrderCommandTest.java b/li.strolch.service/src/test/java/li/strolch/command/UpdateOrderCommandTest.java similarity index 100% rename from src/test/java/li/strolch/command/UpdateOrderCommandTest.java rename to li.strolch.service/src/test/java/li/strolch/command/UpdateOrderCommandTest.java diff --git a/src/test/java/li/strolch/command/UpdateResourceCollectionCommandTest.java b/li.strolch.service/src/test/java/li/strolch/command/UpdateResourceCollectionCommandTest.java similarity index 100% rename from src/test/java/li/strolch/command/UpdateResourceCollectionCommandTest.java rename to li.strolch.service/src/test/java/li/strolch/command/UpdateResourceCollectionCommandTest.java diff --git a/src/test/java/li/strolch/command/UpdateResourceCommandTest.java b/li.strolch.service/src/test/java/li/strolch/command/UpdateResourceCommandTest.java similarity index 100% rename from src/test/java/li/strolch/command/UpdateResourceCommandTest.java rename to li.strolch.service/src/test/java/li/strolch/command/UpdateResourceCommandTest.java diff --git a/src/test/java/li/strolch/command/parameter/AddParameterCommandTest.java b/li.strolch.service/src/test/java/li/strolch/command/parameter/AddParameterCommandTest.java similarity index 100% rename from src/test/java/li/strolch/command/parameter/AddParameterCommandTest.java rename to li.strolch.service/src/test/java/li/strolch/command/parameter/AddParameterCommandTest.java diff --git a/src/test/java/li/strolch/command/parameter/RemoveParameterCommandTest.java b/li.strolch.service/src/test/java/li/strolch/command/parameter/RemoveParameterCommandTest.java similarity index 100% rename from src/test/java/li/strolch/command/parameter/RemoveParameterCommandTest.java rename to li.strolch.service/src/test/java/li/strolch/command/parameter/RemoveParameterCommandTest.java diff --git a/src/test/java/li/strolch/command/parameter/SetParameterCommandTest.java b/li.strolch.service/src/test/java/li/strolch/command/parameter/SetParameterCommandTest.java similarity index 100% rename from src/test/java/li/strolch/command/parameter/SetParameterCommandTest.java rename to li.strolch.service/src/test/java/li/strolch/command/parameter/SetParameterCommandTest.java diff --git a/src/test/java/li/strolch/service/AddOrderCollectionServiceTest.java b/li.strolch.service/src/test/java/li/strolch/service/AddOrderCollectionServiceTest.java similarity index 100% rename from src/test/java/li/strolch/service/AddOrderCollectionServiceTest.java rename to li.strolch.service/src/test/java/li/strolch/service/AddOrderCollectionServiceTest.java diff --git a/src/test/java/li/strolch/service/AddOrderServiceTest.java b/li.strolch.service/src/test/java/li/strolch/service/AddOrderServiceTest.java similarity index 100% rename from src/test/java/li/strolch/service/AddOrderServiceTest.java rename to li.strolch.service/src/test/java/li/strolch/service/AddOrderServiceTest.java diff --git a/src/test/java/li/strolch/service/AddResourceCollectionServiceTest.java b/li.strolch.service/src/test/java/li/strolch/service/AddResourceCollectionServiceTest.java similarity index 100% rename from src/test/java/li/strolch/service/AddResourceCollectionServiceTest.java rename to li.strolch.service/src/test/java/li/strolch/service/AddResourceCollectionServiceTest.java diff --git a/src/test/java/li/strolch/service/AddResourceServiceTest.java b/li.strolch.service/src/test/java/li/strolch/service/AddResourceServiceTest.java similarity index 100% rename from src/test/java/li/strolch/service/AddResourceServiceTest.java rename to li.strolch.service/src/test/java/li/strolch/service/AddResourceServiceTest.java diff --git a/src/test/java/li/strolch/service/ClearModelServiceTest.java b/li.strolch.service/src/test/java/li/strolch/service/ClearModelServiceTest.java similarity index 100% rename from src/test/java/li/strolch/service/ClearModelServiceTest.java rename to li.strolch.service/src/test/java/li/strolch/service/ClearModelServiceTest.java diff --git a/src/test/java/li/strolch/service/RemoveOrderCollectionServiceTest.java b/li.strolch.service/src/test/java/li/strolch/service/RemoveOrderCollectionServiceTest.java similarity index 100% rename from src/test/java/li/strolch/service/RemoveOrderCollectionServiceTest.java rename to li.strolch.service/src/test/java/li/strolch/service/RemoveOrderCollectionServiceTest.java diff --git a/src/test/java/li/strolch/service/RemoveOrderServiceTest.java b/li.strolch.service/src/test/java/li/strolch/service/RemoveOrderServiceTest.java similarity index 100% rename from src/test/java/li/strolch/service/RemoveOrderServiceTest.java rename to li.strolch.service/src/test/java/li/strolch/service/RemoveOrderServiceTest.java diff --git a/src/test/java/li/strolch/service/RemoveResourceCollectionServiceTest.java b/li.strolch.service/src/test/java/li/strolch/service/RemoveResourceCollectionServiceTest.java similarity index 100% rename from src/test/java/li/strolch/service/RemoveResourceCollectionServiceTest.java rename to li.strolch.service/src/test/java/li/strolch/service/RemoveResourceCollectionServiceTest.java diff --git a/src/test/java/li/strolch/service/RemoveResourceServiceTest.java b/li.strolch.service/src/test/java/li/strolch/service/RemoveResourceServiceTest.java similarity index 100% rename from src/test/java/li/strolch/service/RemoveResourceServiceTest.java rename to li.strolch.service/src/test/java/li/strolch/service/RemoveResourceServiceTest.java diff --git a/src/test/java/li/strolch/service/UpdateOrderCollectionServiceTest.java b/li.strolch.service/src/test/java/li/strolch/service/UpdateOrderCollectionServiceTest.java similarity index 100% rename from src/test/java/li/strolch/service/UpdateOrderCollectionServiceTest.java rename to li.strolch.service/src/test/java/li/strolch/service/UpdateOrderCollectionServiceTest.java diff --git a/src/test/java/li/strolch/service/UpdateOrderServiceTest.java b/li.strolch.service/src/test/java/li/strolch/service/UpdateOrderServiceTest.java similarity index 100% rename from src/test/java/li/strolch/service/UpdateOrderServiceTest.java rename to li.strolch.service/src/test/java/li/strolch/service/UpdateOrderServiceTest.java diff --git a/src/test/java/li/strolch/service/UpdateResourceCollectionServiceTest.java b/li.strolch.service/src/test/java/li/strolch/service/UpdateResourceCollectionServiceTest.java similarity index 100% rename from src/test/java/li/strolch/service/UpdateResourceCollectionServiceTest.java rename to li.strolch.service/src/test/java/li/strolch/service/UpdateResourceCollectionServiceTest.java diff --git a/src/test/java/li/strolch/service/UpdateResourceServiceTest.java b/li.strolch.service/src/test/java/li/strolch/service/UpdateResourceServiceTest.java similarity index 100% rename from src/test/java/li/strolch/service/UpdateResourceServiceTest.java rename to li.strolch.service/src/test/java/li/strolch/service/UpdateResourceServiceTest.java diff --git a/src/test/java/li/strolch/service/XmlExportModelServiceTest.java b/li.strolch.service/src/test/java/li/strolch/service/XmlExportModelServiceTest.java similarity index 100% rename from src/test/java/li/strolch/service/XmlExportModelServiceTest.java rename to li.strolch.service/src/test/java/li/strolch/service/XmlExportModelServiceTest.java diff --git a/src/test/java/li/strolch/service/XmlImportModelServiceTest.java b/li.strolch.service/src/test/java/li/strolch/service/XmlImportModelServiceTest.java similarity index 100% rename from src/test/java/li/strolch/service/XmlImportModelServiceTest.java rename to li.strolch.service/src/test/java/li/strolch/service/XmlImportModelServiceTest.java diff --git a/src/test/java/li/strolch/service/test/AbstractRealmServiceTest.java b/li.strolch.service/src/test/java/li/strolch/service/test/AbstractRealmServiceTest.java similarity index 100% rename from src/test/java/li/strolch/service/test/AbstractRealmServiceTest.java rename to li.strolch.service/src/test/java/li/strolch/service/test/AbstractRealmServiceTest.java diff --git a/src/test/java/li/strolch/service/test/AbstractServiceTest.java b/li.strolch.service/src/test/java/li/strolch/service/test/AbstractServiceTest.java similarity index 100% rename from src/test/java/li/strolch/service/test/AbstractServiceTest.java rename to li.strolch.service/src/test/java/li/strolch/service/test/AbstractServiceTest.java diff --git a/src/test/java/li/strolch/service/test/GreetingServiceTest.java b/li.strolch.service/src/test/java/li/strolch/service/test/GreetingServiceTest.java similarity index 100% rename from src/test/java/li/strolch/service/test/GreetingServiceTest.java rename to li.strolch.service/src/test/java/li/strolch/service/test/GreetingServiceTest.java diff --git a/src/test/java/li/strolch/service/test/LockingTest.java b/li.strolch.service/src/test/java/li/strolch/service/test/LockingTest.java similarity index 100% rename from src/test/java/li/strolch/service/test/LockingTest.java rename to li.strolch.service/src/test/java/li/strolch/service/test/LockingTest.java diff --git a/src/test/java/li/strolch/service/test/ServiceTest.java b/li.strolch.service/src/test/java/li/strolch/service/test/ServiceTest.java similarity index 100% rename from src/test/java/li/strolch/service/test/ServiceTest.java rename to li.strolch.service/src/test/java/li/strolch/service/test/ServiceTest.java diff --git a/src/test/java/li/strolch/service/test/XmlExportServiceTest.java b/li.strolch.service/src/test/java/li/strolch/service/test/XmlExportServiceTest.java similarity index 100% rename from src/test/java/li/strolch/service/test/XmlExportServiceTest.java rename to li.strolch.service/src/test/java/li/strolch/service/test/XmlExportServiceTest.java diff --git a/src/test/java/li/strolch/service/test/model/GreetingResult.java b/li.strolch.service/src/test/java/li/strolch/service/test/model/GreetingResult.java similarity index 100% rename from src/test/java/li/strolch/service/test/model/GreetingResult.java rename to li.strolch.service/src/test/java/li/strolch/service/test/model/GreetingResult.java diff --git a/src/test/java/li/strolch/service/test/model/GreetingService.java b/li.strolch.service/src/test/java/li/strolch/service/test/model/GreetingService.java similarity index 100% rename from src/test/java/li/strolch/service/test/model/GreetingService.java rename to li.strolch.service/src/test/java/li/strolch/service/test/model/GreetingService.java diff --git a/src/test/java/li/strolch/service/test/model/TestService.java b/li.strolch.service/src/test/java/li/strolch/service/test/model/TestService.java similarity index 100% rename from src/test/java/li/strolch/service/test/model/TestService.java rename to li.strolch.service/src/test/java/li/strolch/service/test/model/TestService.java diff --git a/src/test/java/li/strolch/service/test/parameter/AddParameterServiceTest.java b/li.strolch.service/src/test/java/li/strolch/service/test/parameter/AddParameterServiceTest.java similarity index 100% rename from src/test/java/li/strolch/service/test/parameter/AddParameterServiceTest.java rename to li.strolch.service/src/test/java/li/strolch/service/test/parameter/AddParameterServiceTest.java diff --git a/src/test/java/li/strolch/service/test/parameter/RemoveParameterServiceTest.java b/li.strolch.service/src/test/java/li/strolch/service/test/parameter/RemoveParameterServiceTest.java similarity index 100% rename from src/test/java/li/strolch/service/test/parameter/RemoveParameterServiceTest.java rename to li.strolch.service/src/test/java/li/strolch/service/test/parameter/RemoveParameterServiceTest.java diff --git a/src/test/java/li/strolch/service/test/parameter/SetParameterServiceTest.java b/li.strolch.service/src/test/java/li/strolch/service/test/parameter/SetParameterServiceTest.java similarity index 100% rename from src/test/java/li/strolch/service/test/parameter/SetParameterServiceTest.java rename to li.strolch.service/src/test/java/li/strolch/service/test/parameter/SetParameterServiceTest.java diff --git a/src/test/resources/log4j.xml b/li.strolch.service/src/test/resources/log4j.xml similarity index 100% rename from src/test/resources/log4j.xml rename to li.strolch.service/src/test/resources/log4j.xml diff --git a/src/test/resources/svctest/config/PrivilegeConfig.xml b/li.strolch.service/src/test/resources/svctest/config/PrivilegeConfig.xml similarity index 100% rename from src/test/resources/svctest/config/PrivilegeConfig.xml rename to li.strolch.service/src/test/resources/svctest/config/PrivilegeConfig.xml diff --git a/src/test/resources/svctest/config/PrivilegeModel.xml b/li.strolch.service/src/test/resources/svctest/config/PrivilegeModel.xml similarity index 100% rename from src/test/resources/svctest/config/PrivilegeModel.xml rename to li.strolch.service/src/test/resources/svctest/config/PrivilegeModel.xml diff --git a/src/test/resources/svctest/config/StrolchConfiguration.xml b/li.strolch.service/src/test/resources/svctest/config/StrolchConfiguration.xml similarity index 100% rename from src/test/resources/svctest/config/StrolchConfiguration.xml rename to li.strolch.service/src/test/resources/svctest/config/StrolchConfiguration.xml diff --git a/src/test/resources/svctest/data/Enums.xml b/li.strolch.service/src/test/resources/svctest/data/Enums.xml similarity index 100% rename from src/test/resources/svctest/data/Enums.xml rename to li.strolch.service/src/test/resources/svctest/data/Enums.xml diff --git a/src/test/resources/svctest/data/Orders.xml b/li.strolch.service/src/test/resources/svctest/data/Orders.xml similarity index 100% rename from src/test/resources/svctest/data/Orders.xml rename to li.strolch.service/src/test/resources/svctest/data/Orders.xml diff --git a/src/test/resources/svctest/data/Resources.xml b/li.strolch.service/src/test/resources/svctest/data/Resources.xml similarity index 100% rename from src/test/resources/svctest/data/Resources.xml rename to li.strolch.service/src/test/resources/svctest/data/Resources.xml diff --git a/src/test/resources/svctest/data/StrolchModel.xml b/li.strolch.service/src/test/resources/svctest/data/StrolchModel.xml similarity index 100% rename from src/test/resources/svctest/data/StrolchModel.xml rename to li.strolch.service/src/test/resources/svctest/data/StrolchModel.xml diff --git a/src/test/resources/transienttest/config/PrivilegeConfig.xml b/li.strolch.service/src/test/resources/transienttest/config/PrivilegeConfig.xml similarity index 100% rename from src/test/resources/transienttest/config/PrivilegeConfig.xml rename to li.strolch.service/src/test/resources/transienttest/config/PrivilegeConfig.xml diff --git a/src/test/resources/transienttest/config/PrivilegeModel.xml b/li.strolch.service/src/test/resources/transienttest/config/PrivilegeModel.xml similarity index 100% rename from src/test/resources/transienttest/config/PrivilegeModel.xml rename to li.strolch.service/src/test/resources/transienttest/config/PrivilegeModel.xml diff --git a/src/test/resources/transienttest/config/StrolchConfiguration.xml b/li.strolch.service/src/test/resources/transienttest/config/StrolchConfiguration.xml similarity index 100% rename from src/test/resources/transienttest/config/StrolchConfiguration.xml rename to li.strolch.service/src/test/resources/transienttest/config/StrolchConfiguration.xml diff --git a/src/test/resources/transienttest/data/Enums.xml b/li.strolch.service/src/test/resources/transienttest/data/Enums.xml similarity index 100% rename from src/test/resources/transienttest/data/Enums.xml rename to li.strolch.service/src/test/resources/transienttest/data/Enums.xml diff --git a/src/test/resources/transienttest/data/Orders.xml b/li.strolch.service/src/test/resources/transienttest/data/Orders.xml similarity index 100% rename from src/test/resources/transienttest/data/Orders.xml rename to li.strolch.service/src/test/resources/transienttest/data/Orders.xml diff --git a/src/test/resources/transienttest/data/Resources.xml b/li.strolch.service/src/test/resources/transienttest/data/Resources.xml similarity index 100% rename from src/test/resources/transienttest/data/Resources.xml rename to li.strolch.service/src/test/resources/transienttest/data/Resources.xml diff --git a/src/test/resources/transienttest/data/StrolchModel.xml b/li.strolch.service/src/test/resources/transienttest/data/StrolchModel.xml similarity index 100% rename from src/test/resources/transienttest/data/StrolchModel.xml rename to li.strolch.service/src/test/resources/transienttest/data/StrolchModel.xml diff --git a/src/test/resources/withPrivilegeRuntime/config/PrivilegeConfig.xml b/li.strolch.service/src/test/resources/withPrivilegeRuntime/config/PrivilegeConfig.xml similarity index 100% rename from src/test/resources/withPrivilegeRuntime/config/PrivilegeConfig.xml rename to li.strolch.service/src/test/resources/withPrivilegeRuntime/config/PrivilegeConfig.xml diff --git a/src/test/resources/withPrivilegeRuntime/config/PrivilegeModel.xml b/li.strolch.service/src/test/resources/withPrivilegeRuntime/config/PrivilegeModel.xml similarity index 100% rename from src/test/resources/withPrivilegeRuntime/config/PrivilegeModel.xml rename to li.strolch.service/src/test/resources/withPrivilegeRuntime/config/PrivilegeModel.xml diff --git a/src/test/resources/withPrivilegeRuntime/config/StrolchConfiguration.xml b/li.strolch.service/src/test/resources/withPrivilegeRuntime/config/StrolchConfiguration.xml similarity index 100% rename from src/test/resources/withPrivilegeRuntime/config/StrolchConfiguration.xml rename to li.strolch.service/src/test/resources/withPrivilegeRuntime/config/StrolchConfiguration.xml