Data Commands
You can now model more advanced actions with DataOperations. Data operationsData Operation (DataOperation). A type-safe action (e.g., Create, Update, Custom) executed on DataElement instances to modify data or trigger business logic. are the official replacement for DataCommands. Both operations and commands serve the same goal of modeling actions on data elementsData Element (DataElement). A fundamental data concept or entity within an application's domain, acting as an anthropomorphic translation of a real-life object or concept.. operations offer a more elaborate model and an easier way to implement custom actions.
A DataCommand is a form of data-input for a given data elementData Element (DataElement). A fundamental data concept or entity within an application's domain, acting as an anthropomorphic translation of a real-life object or concept.. Commands can have one or more ConnectorFieldsFieldA property of a DataElement expanded to a database column and user interface input element., which are similar to regular fieldsFieldA property of a DataElement expanded to a database column and user interface input element..
When a command is defined, a dedicated parameter object will be generated, together with a method stub in the data elementData Element (DataElement). A fundamental data concept or entity within an application's domain, acting as an anthropomorphic translation of a real-life object or concept.'s bean class that allows you to implement the command.
Commands have no return type and are therefore only suited for inserting data.
<dataElement name="Starship">
<dataCommands>
<dataCommand name="startNewVoyage">
<!-- If hasTargetInstance is true, this command requires an instance as a target to run -->
<hasTargetInstance>true</hasTargetInstance>
<connectorFields>
<connectorField name="departure">
<fieldType>VALUE_FIELD</fieldType>
<valueField>
<valueFieldType component="" name="Date"/>
</valueField>
</connectorField>
<connectorField name="destination">
<fieldType>LINK_FIELD</fieldType>
<linkField>
<targetElement component="space" name="Planet"/>
<linkFieldType name="Ln01"/>
</linkField>
</connectorField>
</connectorFields>
</dataCommand>
</dataCommands>
</dataElement>
After expanding, the bean class will contain a method stub to implement the command:
public CommandResult startNewVoyage(ParameterContext<StarshipCommand.StartNewVoyage> commandParameter) {
StarshipCommand.StartNewVoyage startNewVoyageCommand = commandParameter.getValue();
CommandResult commandResult = CommandResult.success(startNewVoyageCommand);
// anchor:custom-command-startNewVoyage-before:start
// anchor:custom-command-startNewVoyage-before:end
IParameterContextFactory parameterFactory = commandParameter.getFactory();
CrudsResult<StarshipDetails> targetResult = getDetailsFromDataRef(parameterFactory.construct(startNewVoyageCommand.getTarget()));
StarshipDetails starshipDetails = targetResult.getValue();
// anchor:custom-command-startNewVoyage:start
StarshipVoyageDetails voyage = new StarshipVoyageDetails();
voyage.setStarship(starshipDetails.getDataRef());
voyage.setDeparture(startNewVoyageCommand.getDeparture());
voyage.setDestination(startNewVoyageCommand.getDestination());
CrudsResult<DataRef> result = StarshipVoyageLocalAgent.getStarshipVoyageAgent(commandParameter.getContext())
.create(voyage);
if (result.isError()) {
commandResult = CommandResult.error(startNewVoyageCommand, "Failed to create a new Voyage");
}
// anchor:custom-command-startNewVoyage:end
// anchor:custom-command-startNewVoyage-after:start
// anchor:custom-command-startNewVoyage-after:end
return commandResult;
}