You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@isis.apache.org by da...@apache.org on 2017/12/07 15:00:59 UTC
[isis] 03/18: ISIS-1784: adds PersonaEnumPersistAll as
out-of-the-box fixture script implementation to use to persist all
instances of a enum implementing PersonaWithBuilderScript
This is an automated email from the ASF dual-hosted git repository.
danhaywood pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/isis.git
commit 5704a2b922e92b15014642e7a459da20ad492ac1
Author: Dan Haywood <da...@haywood-associates.co.uk>
AuthorDate: Mon Dec 4 08:40:21 2017 +0000
ISIS-1784: adds PersonaEnumPersistAll as out-of-the-box fixture script implementation to use to persist all instances of a enum implementing PersonaWithBuilderScript
---
.../setup/PersonaEnumPersistAll.java | 90 ++++++++++++++++++++++
1 file changed, 90 insertions(+)
diff --git a/core/applib/src/main/java/org/apache/isis/applib/fixturescripts/setup/PersonaEnumPersistAll.java b/core/applib/src/main/java/org/apache/isis/applib/fixturescripts/setup/PersonaEnumPersistAll.java
new file mode 100644
index 0000000..f2a1781
--- /dev/null
+++ b/core/applib/src/main/java/org/apache/isis/applib/fixturescripts/setup/PersonaEnumPersistAll.java
@@ -0,0 +1,90 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.isis.applib.fixturescripts.setup;
+
+import java.util.List;
+
+import com.google.common.collect.Lists;
+
+import org.apache.isis.applib.fixturescripts.BuilderScriptAbstract;
+import org.apache.isis.applib.fixturescripts.FixtureScript;
+import org.apache.isis.applib.fixturescripts.FixtureScriptWithExecutionStrategy;
+import org.apache.isis.applib.fixturescripts.FixtureScripts;
+import org.apache.isis.applib.fixturescripts.PersonaWithBuilderScript;
+import org.apache.isis.applib.services.registry.ServiceRegistry2;
+
+public class PersonaEnumPersistAll<E extends Enum<E> & PersonaWithBuilderScript<T,F>, T, F extends BuilderScriptAbstract<T,F>>
+ extends FixtureScript
+ implements FixtureScriptWithExecutionStrategy {
+
+ private final Class<E> personaEnumClass;
+
+ public PersonaEnumPersistAll(final Class<E> demoDataClass) {
+ this.personaEnumClass = demoDataClass;
+ }
+
+ /**
+ * The number of objects to create.
+ */
+ private Integer number;
+ public Integer getNumber() {
+ return number;
+ }
+
+ public void setNumber(final Integer number) {
+ this.number = number;
+ }
+
+ /**
+ * The objects created by this fixture (output).
+ */
+ private final List<T> objects = Lists.newArrayList();
+ public List<T> getObjects() {
+ return objects;
+ }
+
+ @Override
+ protected void execute(final FixtureScript.ExecutionContext ec) {
+
+ final E[] enumConstants = personaEnumClass.getEnumConstants();
+ final int max = enumConstants.length;
+
+ // defaults
+ final int number = defaultParam("number", ec, max);
+
+ // validate
+ if(number < 0 || number > max) {
+ throw new IllegalArgumentException(String.format("number must be in range [0,%d)", max));
+ }
+
+ for (int i = 0; i < number; i++) {
+ final F enumFixture = enumConstants[i].builder();
+ final T domainObject = ec.executeChildT(this, enumFixture).getObject();
+ ec.addResult(this, domainObject);
+ objects.add(domainObject);
+ }
+ }
+
+ @Override
+ public FixtureScripts.MultipleExecutionStrategy getMultipleExecutionStrategy() {
+ return FixtureScripts.MultipleExecutionStrategy.EXECUTE_ONCE_BY_VALUE;
+ }
+
+}
+
--
To stop receiving notification emails like this one, please contact
"commits@isis.apache.org" <co...@isis.apache.org>.