#91 Added skeleton for naked-objects example using Apache Isis SimpleApp archetype

This commit is contained in:
Ilkka Seppala
2015-07-13 15:19:16 +03:00
parent aa491b2458
commit 5337ecdc35
62 changed files with 5304 additions and 6 deletions

View File

@ -0,0 +1,76 @@
/*
* 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 domainapp.fixture;
import java.util.List;
import org.apache.isis.applib.annotation.Action;
import org.apache.isis.applib.annotation.ActionLayout;
import org.apache.isis.applib.annotation.DomainService;
import org.apache.isis.applib.annotation.DomainServiceLayout;
import org.apache.isis.applib.annotation.MemberOrder;
import org.apache.isis.applib.annotation.RestrictTo;
import org.apache.isis.applib.fixturescripts.FixtureResult;
import org.apache.isis.applib.fixturescripts.FixtureScript;
import org.apache.isis.applib.fixturescripts.FixtureScripts;
import domainapp.fixture.scenarios.RecreateSimpleObjects;
/**
* Enables fixtures to be installed from the application.
*/
@DomainService
@DomainServiceLayout(
named="Prototyping",
menuBar = DomainServiceLayout.MenuBar.SECONDARY,
menuOrder = "500"
)
public class DomainAppFixturesService extends FixtureScripts {
public DomainAppFixturesService() {
super(DomainAppFixturesService.class.getPackage().getName(), MultipleExecutionStrategy.EXECUTE);
}
@Override
public FixtureScript default0RunFixtureScript() {
return findFixtureScriptFor(RecreateSimpleObjects.class);
}
@Override
public List<FixtureScript> choices0RunFixtureScript() {
return super.choices0RunFixtureScript();
}
// //////////////////////////////////////
@Action(
restrictTo = RestrictTo.PROTOTYPING
)
@ActionLayout(
cssClassFa="fa fa-refresh"
)
@MemberOrder(sequence="20")
public Object recreateObjectsAndReturnFirst() {
final List<FixtureResult> run = findFixtureScriptFor(RecreateSimpleObjects.class).run(null);
return run.get(0).getObject();
}
}

View File

@ -0,0 +1,71 @@
/*
* 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 domainapp.fixture.modules.simple;
import org.apache.isis.applib.fixturescripts.FixtureScript;
import domainapp.dom.modules.simple.SimpleObject;
import domainapp.dom.modules.simple.SimpleObjects;
public class SimpleObjectCreate extends FixtureScript {
//region > name (input)
private String name;
/**
* Name of the object (required)
*/
public String getName() {
return name;
}
public SimpleObjectCreate setName(final String name) {
this.name = name;
return this;
}
//endregion
//region > simpleObject (output)
private SimpleObject simpleObject;
/**
* The created simple object (output).
* @return
*/
public SimpleObject getSimpleObject() {
return simpleObject;
}
//endregion
@Override
protected void execute(final ExecutionContext ec) {
String name = checkParam("name", ec, String.class);
this.simpleObject = wrap(simpleObjects).create(name);
// also make available to UI
ec.addResult(this, simpleObject);
}
@javax.inject.Inject
private SimpleObjects simpleObjects;
}

View File

@ -0,0 +1,36 @@
/*
* 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 domainapp.fixture.modules.simple;
import org.apache.isis.applib.fixturescripts.FixtureScript;
import org.apache.isis.applib.services.jdosupport.IsisJdoSupport;
public class SimpleObjectsTearDown extends FixtureScript {
@Override
protected void execute(ExecutionContext executionContext) {
isisJdoSupport.executeUpdate("delete from simple.\"SimpleObject\"");
}
@javax.inject.Inject
private IsisJdoSupport isisJdoSupport;
}

View File

@ -0,0 +1,92 @@
/*
* 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 domainapp.fixture.scenarios;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import com.google.common.collect.Lists;
import org.apache.isis.applib.fixturescripts.FixtureScript;
import domainapp.dom.modules.simple.SimpleObject;
import domainapp.fixture.modules.simple.SimpleObjectCreate;
import domainapp.fixture.modules.simple.SimpleObjectsTearDown;
public class RecreateSimpleObjects extends FixtureScript {
public final List<String> NAMES = Collections.unmodifiableList(Arrays.asList(
"Foo", "Bar", "Baz", "Frodo", "Froyo", "Fizz", "Bip", "Bop", "Bang", "Boo"));
public RecreateSimpleObjects() {
withDiscoverability(Discoverability.DISCOVERABLE);
}
//region > number (optional input)
private Integer number;
/**
* The number of objects to create, up to 10; optional, defaults to 3.
*/
public Integer getNumber() {
return number;
}
public RecreateSimpleObjects setNumber(final Integer number) {
this.number = number;
return this;
}
//endregion
//region > simpleObjects (output)
private final List<SimpleObject> simpleObjects = Lists.newArrayList();
/**
* The simpleobjects created by this fixture (output).
*/
public List<SimpleObject> getSimpleObjects() {
return simpleObjects;
}
//endregion
@Override
protected void execute(final ExecutionContext ec) {
// defaults
final int number = defaultParam("number", ec, 3);
// validate
if(number < 0 || number > NAMES.size()) {
throw new IllegalArgumentException(String.format("number must be in range [0,%d)", NAMES.size()));
}
//
// execute
//
ec.executeChild(this, new SimpleObjectsTearDown());
for (int i = 0; i < number; i++) {
final SimpleObjectCreate fs = new SimpleObjectCreate().setName(NAMES.get(i));
ec.executeChild(this, fs.getName(), fs);
simpleObjects.add(fs.getSimpleObject());
}
}
}