001/** 002 * Licensed to the Apache Software Foundation (ASF) under one or more 003 * contributor license agreements. See the NOTICE file distributed with 004 * this work for additional information regarding copyright ownership. 005 * The ASF licenses this file to You under the Apache License, Version 2.0 006 * (the "License"); you may not use this file except in compliance with 007 * the License. You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017package org.apache.isis.objectstore.jdo.applib.service.background; 018 019import java.util.Collections; 020import java.util.List; 021 022import org.apache.isis.applib.AbstractFactoryAndRepository; 023import org.apache.isis.applib.annotation.ActionSemantics; 024import org.apache.isis.applib.annotation.ActionSemantics.Of; 025import org.apache.isis.applib.annotation.NotContributed; 026import org.apache.isis.applib.annotation.NotContributed.As; 027import org.apache.isis.applib.annotation.NotInServiceMenu; 028import org.apache.isis.applib.annotation.Render; 029import org.apache.isis.applib.annotation.Render.Type; 030import org.apache.isis.applib.services.command.Command; 031import org.apache.isis.objectstore.jdo.applib.service.command.CommandJdo; 032 033 034/** 035 * This service contributes a <tt>childCommands</tt> collection and a <tt>sublingCommands</tt> collection to 036 * any {@link CommandJdo} entity. 037 * 038 * <p> 039 * Because this service influences the UI, it must be explicitly registered as a service 040 * (eg using <tt>isis.properties</tt>). 041 */ 042public class BackgroundCommandServiceJdoContributions extends AbstractFactoryAndRepository { 043 044 @ActionSemantics(Of.SAFE) 045 @NotInServiceMenu 046 @NotContributed(As.ACTION) 047 @Render(Type.EAGERLY) 048 public List<CommandJdo> childCommands(final CommandJdo parent) { 049 return backgroundCommandRepository.findByParent(parent); 050 } 051 052 @ActionSemantics(Of.SAFE) 053 @NotInServiceMenu 054 @NotContributed(As.ACTION) 055 @Render(Type.EAGERLY) 056 public List<CommandJdo> siblingCommands(final CommandJdo siblingCommand) { 057 final Command parent = siblingCommand.getParent(); 058 if(parent == null || !(parent instanceof CommandJdo)) { 059 return Collections.emptyList(); 060 } 061 final CommandJdo parentJdo = (CommandJdo) parent; 062 final List<CommandJdo> siblingCommands = backgroundCommandRepository.findByParent(parentJdo); 063 siblingCommands.remove(siblingCommand); 064 return siblingCommands; 065 } 066 067 068 // ////////////////////////////////////// 069 070 @javax.inject.Inject 071 private BackgroundCommandServiceJdoRepository backgroundCommandRepository; 072 073}