= Command
:Notice: 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.

Represents the _intention to_ invoke either an action or modify a property. There can be only one such intention per (web) request, so a command is in effect interaction-scoped.

Each Command holds a _CommandDto_ (see Apache Causewaycmdschema) which reifies all the details in a serializable form.

It also captures details of the corresponding action invocation (or property edit), specifically when that action/edit _Command#getStartedAt() started_ or _Command#getCompletedAt() completed_ , and its result, either a _Command#getResult() return value_ or an _Command#getException() exception_ . Also captures a stack of xref:refguide:applib:index/events/domain/ActionDomainEvent.adoc[ActionDomainEvent] s.

Note that when invoking an action, other actions may be invoked courtesy of the xref:refguide:applib:index/services/wrapper/WrapperFactory.adoc[WrapperFactory] . These "sub-actions" do _not_ modify the contents of the current command object; in other words think of the command object as representing the outer-most originating action.

That said, if the sub-action is invoked asynchronously (using _WrapperFactory#asyncWrap(Object, AsyncControl)_ or _WrapperFactory#asyncWrapMixin(Class, Object, AsyncControl)_ ), then a separate xref:refguide:applib:index/services/command/Command.adoc[Command] object is created, and the originating xref:refguide:applib:index/services/command/Command.adoc[Command] is set to be its _Command#getParentInteractionId() parent_ .

== API

[source,java]
.Command.java
----
class Command {
  Command(UUID interactionId)
  UUID getInteractionId()     // <.>
  String getUsername()     // <.>
  Timestamp getTimestamp()     // <.>
  CommandDto getCommandDto()     // <.>
  Bookmark getTarget()     // <.>
  String getLogicalMemberIdentifier()     // <.>
  Updater updater()     // <.>
}
----

<.> xref:#getInteractionId_[getInteractionId()]
+
--
The unique identifier of this command (inherited from xref:refguide:applib:index/mixins/system/HasInteractionId.adoc[HasInteractionId] )
--
<.> xref:#getUsername_[getUsername()]
+
--
The user that created the command.
--
<.> xref:#getTimestamp_[getTimestamp()]
+
--
The date/time at which this command was created.
--
<.> xref:#getCommandDto_[getCommandDto()]
+
--
Serializable representation of the action invocation/property edit.
--
<.> xref:#getTarget_[getTarget()]
+
--
Derived from _#getCommandDto()_ , is the xref:refguide:applib:index/services/bookmark/Bookmark.adoc[Bookmark] of the target object (entity or service) on which this action/edit was performed.
--
<.> xref:#getLogicalMemberIdentifier_[getLogicalMemberIdentifier()]
+
--
Derived from _#getCommandDto()_ , holds a string representation of the invoked action, or the edited property.
--
<.> xref:#updater_[updater()]
+
--
 *NOT API* : intended to be called only by the framework.
--

== Members

[#getInteractionId_]
=== getInteractionId()

The unique identifier of this command (inherited from xref:refguide:applib:index/mixins/system/HasInteractionId.adoc[HasInteractionId] )

In all cases this be the same as the xref:refguide:applib:index/services/iactn/Interaction.adoc[Interaction] that wraps the command, and can be used to correlate also to any audit records ( _org.apache.causeway.applib.services.publishing.spi.EntityPropertyChange_ s resulting from state changes occurring as a consequence of the command.

Note that this is immutable in almost all cases. The one exception is if the Command is being executed through the xref:refguide:applib:index/services/command/CommandExecutorService.adoc[CommandExecutorService] , for example when executing a async action that has been reified into a _CommandDto_ . In such cases, the _CommandExecutorService#executeCommand(CommandDto)_ will _replace_ the original Id with that of the DTO being executed.

[#getUsername_]
=== getUsername()

The user that created the command.

Derived from _#getCommandDto()_ 's _CommandDto#getUsername()_ ()}

[#getTimestamp_]
=== getTimestamp()

The date/time at which this command was created.

Derived from _#getCommandDto()_ 's _CommandDto#getTimestamp()_ .

[#getCommandDto_]
=== getCommandDto()

Serializable representation of the action invocation/property edit.

When the framework sets this (through an internal API), it is expected that the _CommandDto#getUsername() username_ , _CommandDto#getTimestamp() timestamp_ , _CommandDto#getTargets() target(s)_ and _CommandDto#getMember() member_ will be populated. The _#getInteractionId()_ , _#getUsername()_ , _#getTimestamp()_ and _#getTarget()_ are all derived from the provided _CommandDto_ .

[#getTarget_]
=== getTarget()

Derived from _#getCommandDto()_ , is the xref:refguide:applib:index/services/bookmark/Bookmark.adoc[Bookmark] of the target object (entity or service) on which this action/edit was performed.

[#getLogicalMemberIdentifier_]
=== getLogicalMemberIdentifier()

Derived from _#getCommandDto()_ , holds a string representation of the invoked action, or the edited property.

[#updater_]
=== updater()

 *NOT API* : intended to be called only by the framework.
