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.command; 018 019import java.util.UUID; 020import org.apache.isis.applib.AbstractFactoryAndRepository; 021import org.apache.isis.applib.annotation.MemberOrder; 022import org.apache.isis.applib.annotation.NotContributed; 023import org.apache.isis.applib.annotation.NotContributed.As; 024import org.apache.isis.applib.annotation.NotInServiceMenu; 025import org.apache.isis.applib.services.HasTransactionId; 026import org.apache.isis.applib.services.command.Command; 027 028 029/** 030 * This service contributes a <tt>command</tt> action to any (non-command) implementation of 031 * {@link org.apache.isis.applib.services.HasTransactionId}; that is: audit entries, and published events. Thus, it 032 * is possible to navigate from the effect back to the cause. 033 * 034 * <p> 035 * Because this service influences the UI, it must be explicitly registered as a service 036 * (eg using <tt>isis.properties</tt>). 037 */ 038public class CommandServiceJdoContributions extends AbstractFactoryAndRepository { 039 040 @NotInServiceMenu 041 @NotContributed(As.ASSOCIATION) // ie contributed as an action 042 @MemberOrder(name="transactionId", sequence="1") 043 public CommandJdo command(final HasTransactionId hasTransactionId) { 044 return commandServiceRepository.findByTransactionId(hasTransactionId.getTransactionId()); 045 } 046 /** 047 * Hide if the contributee is a {@link Command}, because {@link Command}s already have a 048 * {@link Command#getParent() parent} property. 049 */ 050 public boolean hideCommand(final HasTransactionId hasTransactionId) { 051 return (hasTransactionId instanceof Command); 052 } 053 public String disableCommand(final HasTransactionId hasTransactionId) { 054 if(hasTransactionId == null) { 055 return "No transaction Id"; 056 } 057 final UUID transactionId = hasTransactionId.getTransactionId(); 058 final boolean command = commandServiceRepository.findByTransactionId(transactionId) == null; 059 return command? "No command found for transaction Id": null; 060 } 061 062 063 // ////////////////////////////////////// 064 065 066 @javax.inject.Inject 067 private CommandServiceJdoRepository commandServiceRepository; 068 069 070}