Java tutorial
/* * Copyright 2016 Jrg Rade * * Licensed under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES 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.isisaddons.wicket.timeline.fixture.scripts.todo; import org.isisaddons.wicket.timeline.fixture.dom.TimelineWicketToDoItem; import org.isisaddons.wicket.timeline.fixture.dom.TimelineWicketToDoItems; import org.joda.time.LocalDate; import org.apache.isis.applib.fixturescripts.FixtureScript; import org.apache.isis.applib.services.clock.ClockService; import org.apache.isis.applib.services.jdosupport.IsisJdoSupport; public class ToDoItemsFixture extends FixtureScript { @Override public void execute(ExecutionContext executionContext) { final String ownedBy = getContainer().getUser().getName(); installFor(ownedBy, executionContext); getContainer().flush(); } private void installFor(String user, ExecutionContext executionContext) { TimelineWicketToDoItem t1 = createToDoItemForUser("Buy bread", user, TimelineWicketToDoItem.Category.Domestic, executionContext); TimelineWicketToDoItem t2 = createToDoItemForUser("Buy milk", user, TimelineWicketToDoItem.Category.Domestic, executionContext); TimelineWicketToDoItem t3 = createToDoItemForUser("Buy stamps", user, TimelineWicketToDoItem.Category.Domestic, executionContext); TimelineWicketToDoItem t4 = createToDoItemForUser("Pick up laundry", user, TimelineWicketToDoItem.Category.Domestic, executionContext); createToDoItemForUser("Mow lawn", user, TimelineWicketToDoItem.Category.Domestic, executionContext); createToDoItemForUser("Vacuum house", user, TimelineWicketToDoItem.Category.Domestic, executionContext); createToDoItemForUser("Sharpen knives", user, TimelineWicketToDoItem.Category.Domestic, executionContext); createToDoItemForUser("Write to penpal", user, TimelineWicketToDoItem.Category.Other, executionContext); createToDoItemForUser("Write blog post", user, TimelineWicketToDoItem.Category.Professional, executionContext); createToDoItemForUser("Organize brown bag", user, TimelineWicketToDoItem.Category.Professional, executionContext); createToDoItemForUser("Submit conference session", user, TimelineWicketToDoItem.Category.Professional, executionContext); createToDoItemForUser("Stage Isis release", user, TimelineWicketToDoItem.Category.Professional, executionContext); // set up some dependencies t1.add(t2); t1.add(t3); t1.add(t4); getContainer().flush(); } // ////////////////////////////////////// private TimelineWicketToDoItem createToDoItemForUser(final String description, final String user, final TimelineWicketToDoItem.Category category, final ExecutionContext executionContext) { TimelineWicketToDoItem toDo = toDoItems.newToDo(description, user); LocalDate today = clockService.now(); toDo.setDueBy(today.plusDays(random(10) - 2)); toDo.setCategory(category); return executionContext.add(this, description, toDo); } private static int random(int n) { return (int) (Math.random() * n); } // ////////////////////////////////////// // Injected services // ////////////////////////////////////// @javax.inject.Inject private TimelineWicketToDoItems toDoItems; @javax.inject.Inject private IsisJdoSupport isisJdoSupport; @javax.inject.Inject private ClockService clockService; }