Package org.apache.isis.applib.services.command

Examples of org.apache.isis.applib.services.command.Command


        final CommandContext commandContext = getServiceOrNull(CommandContext.class);
        if(commandContext == null) {
            return;
        }
        final CommandService commandService = getServiceOrNull(CommandService.class);
        final Command command =
                commandService != null
                    ? commandService.create()
                    : new CommandDefault();
        commandContext.setCommand(command);

        if(command.getTimestamp() == null) {
            command.setTimestamp(Clock.getTimeAsJavaSqlTimestamp());
        }
        if(command.getUser() == null) {
            command.setUser(getAuthenticationSession().getUserName());
        }
       
        // the remaining properties are set further down the call-stack, if an action is actually performed
    }
View Full Code Here


        }
        final CommandService commandService = getServiceOrNull(CommandService.class);
        if(commandService == null) {
            return;
        }
        final Command command = commandContext.getCommand();
        commandService.startTransaction(command, transactionId);
    }
View Full Code Here

            final RootOid adapterOid = (RootOid) currentInvocation.getTarget().getOid();
            final String oidStr = getOidMarshaller().marshal(adapterOid);
            final Identifier actionIdentifier = action.getIdentifier();
            final String title = oidStr + ": " + actionIdentifier.toNameParmsIdentityString();
           
            final Command command = currentInvocation.getCommand();
            final String targetClass = command.getTargetClass();
            final String targetAction = command.getTargetAction();
            final Bookmark target = command.getTarget();
            final String memberIdentifier = command.getMemberIdentifier();
           
            final EventMetadata metadata = newEventMetadata(EventType.ACTION_INVOCATION, currentUser, timestamp, title, targetClass, targetAction, target, memberIdentifier);
            publishingService.publishAction(payloadFactory, metadata, currentInvocation, objectStringifier());
        } finally {
            // ensures that cannot publish this action more than once
View Full Code Here

    private void completeCommandIfConfigured() {
        final CommandContext commandContext = getServiceOrNull(CommandContext.class);
        if(commandContext != null) {
            final CommandService commandService = getServiceOrNull(CommandService.class);
            if(commandService != null) {
                final Command command = commandContext.getCommand();
                commandService.complete(command);
            }
        }
    }
View Full Code Here

                final List<Class<?>> argTypes = Lists.newArrayList();
                final List<Object> argObjs = Lists.newArrayList();
                CommandUtil.buildMementoArgLists(mementoService, bookmarkService, proxiedMethod, args, argTypes, argObjs);

                final Command command = commandContext.getCommand();
               
                final ActionInvocationMemento aim =
                        new ActionInvocationMemento(mementoService,
                                actionIdentifier,
                                domainObjectBookmark,
View Full Code Here

            final ObjectAdapter targetAdapter,
            final ObjectAdapter[] arguments) {
     
        final Bulk.InteractionContext bulkInteractionContext = getServicesInjector().lookupService(Bulk.InteractionContext.class);
        final CommandContext commandContext = getServicesInjector().lookupService(CommandContext.class);
        final Command command = commandContext != null ? commandContext.getCommand() : null;

        try {
            final Object[] executionParameters = new Object[arguments.length];
            for (int i = 0; i < arguments.length; i++) {
                executionParameters[i] = unwrap(arguments[i]);
            }

            final Object object = unwrap(targetAdapter);
           
            final BulkFacet bulkFacet = getFacetHolder().getFacet(BulkFacet.class);
            if (bulkFacet != null &&
                bulkInteractionContext != null &&
                bulkInteractionContext.getInvokedAs() == null) {
               
                bulkInteractionContext.setInvokedAs(InvokedAs.REGULAR);
                bulkInteractionContext.setDomainObjects(Collections.singletonList(object));
            }

            if(command != null && command.getExecutor() == Executor.USER && owningAction != null) {

                if(command.getTarget() != null) {
                    // already set up by a ObjectActionContributee;
                    // don't overwrite
                } else {
                    command.setTargetClass(CommandUtil.targetClassNameFor(targetAdapter));
                    command.setTargetAction(CommandUtil.targetActionNameFor(owningAction));
                    command.setArguments(CommandUtil.argDescriptionFor(owningAction, arguments));
                   
                    final Bookmark targetBookmark = CommandUtil.bookmarkFor(targetAdapter);
                    command.setTarget(targetBookmark);
                }

                command.setMemberIdentifier(CommandUtil.actionIdentifierFor(owningAction));

                // the background service is used here merely as a means to capture an invocation memento
                final BackgroundService backgroundService = getServicesInjector().lookupService(BackgroundService.class);
                if(backgroundService != null) {
                    final Object targetObject = unwrap(targetAdapter);
                    final Object[] args = CommandUtil.objectsFor(arguments);
                    ActionInvocationMemento aim = backgroundService.asActionInvocationMemento(method, targetObject, args);

                    if(aim != null) {
                        command.setMemento(aim.asMementoString());
                    } else {
                        throw new IsisException(
                            "Unable to build memento for action " +
                            owningAction.getIdentifier().toClassAndNameIdentityString());
                    }
                }

                // copy over the command execution 'context' (if available)
                final CommandFacet commandFacet = getFacetHolder().getFacet(CommandFacet.class);
                if(commandFacet != null && !commandFacet.isDisabled()) {
                    command.setExecuteIn(commandFacet.executeIn());
                    command.setPersistence(commandFacet.persistence());
                } else {
                    // if no facet, assume do want to execute right now, but only persist (eventually) if hinted.
                    command.setExecuteIn(ExecuteIn.FOREGROUND);
                    command.setPersistence(Persistence.IF_HINTED);
                }
            }
           
           
            if( command != null &&
                command.getExecutor() == Executor.USER &&
                command.getExecuteIn() == ExecuteIn.BACKGROUND) {
               
                // persist command so can be this command can be in the 'background'
                final CommandService commandService = getServicesInjector().lookupService(CommandService.class);
                if(commandService.persistIfPossible(command)) {
                    // force persistence, then return the command itself.
                    final ObjectAdapter resultAdapter = getAdapterManager().adapterFor(command);
                    return InvocationResult.forActionThatReturned(resultAdapter);
                } else {
                    throw new IsisException(
                            "Unable to schedule action '"
                            + owningAction.getIdentifier().toClassAndNameIdentityString() + "' to run in background: "
                            + "CommandService does not support persistent commands " );
                }
            } else {
               
                // otherwise, go ahead and execute action in the 'foreground'

                if(command != null) {
                    command.setStartedAt(Clock.getTimeAsJavaSqlTimestamp());
                }
               
                final Object result = method.invoke(object, executionParameters);

                if (LOG.isDebugEnabled()) {
                    LOG.debug(" action result " + result);
                }
                if (result == null) {
                  return InvocationResult.forActionThatReturned(null);
                }

                final ObjectAdapter resultAdapter = getAdapterManager().adapterFor(result);

                // copy over TypeOfFacet if required
                final TypeOfFacet typeOfFacet = getFacetHolder().getFacet(TypeOfFacet.class);
                resultAdapter.setElementSpecificationProvider(ElementSpecificationProviderFromTypeOfFacet.createFrom(typeOfFacet));

                if(command != null) {
                    if(!resultAdapter.getSpecification().containsDoOpFacet(ViewModelFacet.class)) {
                        final Bookmark bookmark = CommandUtil.bookmarkFor(resultAdapter);
                        command.setResult(bookmark);
                    }
                }
               
                final PublishedActionFacet publishedActionFacet = getIdentified().getFacet(PublishedActionFacet.class);
                ActionInvocationFacet.currentInvocation.set(
View Full Code Here

            bulkInteractionContext.setInvokedAs(InvokedAs.REGULAR);
            bulkInteractionContext.setDomainObjects(Collections.singletonList(contributee.getObject()));
        }

        final CommandContext commandContext = getServicesProvider().lookupService(CommandContext.class);
        final Command command = commandContext != null ? commandContext.getCommand() : null;

        if(command != null && command.getExecutor() == Executor.USER) {

            command.setTargetClass(CommandUtil.targetClassNameFor(contributee));
            command.setTargetAction(CommandUtil.targetActionNameFor(this));
            command.setArguments(CommandUtil.argDescriptionFor(this, arguments));
           
            final Bookmark targetBookmark = CommandUtil.bookmarkFor(contributee);
            command.setTarget(targetBookmark);
        }
       
        return serviceAction.execute(serviceAdapter, argsPlusContributee(contributee, arguments));
    }
View Full Code Here

            final ObjectAdapter targetAdapter,
            final ObjectAdapter[] arguments) {

        final Bulk.InteractionContext bulkInteractionContext = getServicesInjector().lookupService(Bulk.InteractionContext.class);
        final CommandContext commandContext = getServicesInjector().lookupService(CommandContext.class);
        final Command command = commandContext != null ? commandContext.getCommand() : null;

        try {
            final Object[] executionParameters = new Object[arguments.length];
            for (int i = 0; i < arguments.length; i++) {
                executionParameters[i] = unwrap(arguments[i]);
            }

            final Object object = unwrap(targetAdapter);
           
            final BulkFacet bulkFacet = getFacetHolder().getFacet(BulkFacet.class);
            if (bulkFacet != null &&
                bulkInteractionContext != null &&
                bulkInteractionContext.getInvokedAs() == null) {
               
                bulkInteractionContext.setInvokedAs(InvokedAs.REGULAR);
                bulkInteractionContext.setDomainObjects(Collections.singletonList(object));
            }

            if(command != null && command.getExecutor() == Executor.USER && owningAction != null) {

                command.setMemberIdentifier(CommandUtil.actionIdentifierFor(owningAction));
                command.setTargetClass(CommandUtil.targetClassNameFor(targetAdapter));
                command.setTargetAction(CommandUtil.targetActionNameFor(owningAction));
                command.setArguments(CommandUtil.argDescriptionFor(owningAction, arguments));
               
                final Bookmark targetBookmark = CommandUtil.bookmarkFor(targetAdapter);
                command.setTarget(targetBookmark);
               
                // the background service is used here merely as a means to capture an invocation memento
                final BackgroundService backgroundService = getServicesInjector().lookupService(BackgroundService.class);
                if(backgroundService != null) {
                    final Object targetObject = unwrap(targetAdapter);
                    final Object[] args = CommandUtil.objectsFor(arguments);
                    ActionInvocationMemento aim = backgroundService.asActionInvocationMemento(method, targetObject, args);

                    if(aim != null) {
                        command.setMemento(aim.asMementoString());
                    } else {
                        throw new IsisException(
                            "Unable to build memento for action " +
                            owningAction.getIdentifier().toClassAndNameIdentityString());
                    }
                }

                // copy over the command execution 'context' (if available)
                final CommandFacet commandFacet = getFacetHolder().getFacet(CommandFacet.class);
                if(commandFacet != null && !commandFacet.isDisabled()) {
                    command.setExecuteIn(commandFacet.executeIn());
                    command.setPersistence(commandFacet.persistence());
                } else {
                    // if no facet, assume do want to execute right now, but only persist (eventually) if hinted.
                    command.setExecuteIn(ExecuteIn.FOREGROUND);
                    command.setPersistence(Persistence.IF_HINTED);
                }
            }
           
           
            if( command != null &&
                command.getExecutor() == Executor.USER &&
                command.getExecuteIn() == ExecuteIn.BACKGROUND) {
               
                // persist command so can be this command can be in the 'background'
                final CommandService commandService = getServicesInjector().lookupService(CommandService.class);
                if(commandService.persistIfPossible(command)) {
                    // force persistence, then return the command itself.
                    final ObjectAdapter resultAdapter = getAdapterManager().adapterFor(command);
                    return resultAdapter;
                } else {
                    throw new IsisException(
                            "Unable to schedule action '"
                            + owningAction.getIdentifier().toClassAndNameIdentityString() + "' to run in background: "
                            + "CommandService does not support persistent commands " );
                }
            } else {
               
                // otherwise, go ahead and execute action in the 'foreground'

                if(command != null) {
                    command.setStartedAt(Clock.getTimeAsJavaSqlTimestamp());
                }
               
                final Object result = method.invoke(object, executionParameters);

                if (LOG.isDebugEnabled()) {
                    LOG.debug(" action result " + result);
                }
                if (result == null) {
                    return null;
                }

                final ObjectAdapter resultAdapter = getAdapterManager().adapterFor(result);

                // copy over TypeOfFacet if required
                final TypeOfFacet typeOfFacet = getFacetHolder().getFacet(TypeOfFacet.class);
                resultAdapter.setElementSpecificationProvider(ElementSpecificationProviderFromTypeOfFacet.createFrom(typeOfFacet));

                if(command != null) {
                    if(!resultAdapter.getSpecification().containsDoOpFacet(ViewModelFacet.class)) {
                        final Bookmark bookmark = CommandUtil.bookmarkFor(resultAdapter);
                        command.setResult(bookmark);
                    }
                }
               
                final PublishedActionFacet publishedActionFacet = getIdentified().getFacet(PublishedActionFacet.class);
                ActionInvocationFacet.currentInvocation.set(
View Full Code Here

        final CommandContext commandContext = getServiceOrNull(CommandContext.class);
        if(commandContext == null) {
            return;
        }
        final CommandService commandService = getServiceOrNull(CommandService.class);
        final Command command =
                commandService != null
                    ? commandService.create()
                    : new CommandDefault();
        commandContext.setCommand(command);

        if(command.getTimestamp() == null) {
            command.setTimestamp(Clock.getTimeAsJavaSqlTimestamp());
        }
        if(command.getUser() == null) {
            command.setUser(getAuthenticationSession().getUserName());
        }
       
        // the remaining properties are set further down the call-stack, if an action is actually performed
    }
View Full Code Here

        }
        final CommandService commandService = getServiceOrNull(CommandService.class);
        if(commandService == null) {
            return;
        }
        final Command command = commandContext.getCommand();
        commandService.startTransaction(command, transactionId);
    }
View Full Code Here

TOP

Related Classes of org.apache.isis.applib.services.command.Command

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.