RemoveElementCommandExtensionExpander
Expands:
$componentRoot.directory$/$artifactSubFolders$/$dataElement.packageName;format="toPath"$/command/$dataElement.name;format="firstToLower"$
/Remove$dataElement.name$CommandExtension.java
if:
dataElement.component.getOption('enableJaxrs').defined and
dataElement.getOption('includeJaxrsConnector').defined and
dataElement.getOption('exposeDeleteEndpoint').defined and
!dataElement.dataCommands.{^ #this.name.equals('remove' + dataElement.name) }.empty
property | value |
---|---|
element type | DataElement |
qualified name | net.democritus.expander.rest.logic.command.extension.RemoveElementCommandExtensionExpander |
layer | LOGIC_LAYER |
technology | EJB3 |
sourceType | JAVA |
phase | expansion |
features | ValidateRemove |
Example
Some example of the content generated by the expander:
// expanded with nsx-expanders:4.16.3, expansionResource net.democritus:rest-expanders:2.4.2
package net.animals.command.catBreed;
import animals.command.CustomCommandResult;
import net.animals.CatBreedCommand;
import net.democritus.sys.Context;
import net.democritus.sys.ParameterContext;
import net.democritus.sys.DiagnosticFactory;
// anchor:default-implementation-imports:start
import net.animals.CatBreedDataRef;
import net.animals.CatBreedLocalAgent;
import net.animals.facade.CatBreedDataFacade;
import net.democritus.sys.CrudsResult;
import net.democritus.sys.SearchResult;
// anchor:default-implementation-imports:end
// @anchor:imports:start
// @anchor:imports:end
// anchor:custom-imports:start
// anchor:custom-imports:end
public class RemoveCatBreedCommandExtension {
private final DiagnosticFactory diagnosticFactory = new DiagnosticFactory("animals", "CatBreed");
// @anchor:fields:start
private RemoveCatBreedValidationCommand validationCommand = new RemoveCatBreedValidationCommand();
// @anchor:fields:end
// anchor:custom-fields:start
// anchor:custom-fields:end
public CustomCommandResult canExecute(ParameterContext<CatBreedCommand.RemoveCatBreed> commandParameter) {
Context context = commandParameter.getContext();
CatBreedCommand.RemoveCatBreed command = commandParameter.getValue();
CustomCommandResult result = CustomCommandResult.success(command.getCommandId());
// @anchor:can-execute:start
CustomCommandResult validate = validationCommand.validate(commandParameter);
if (validate.isError()) {
return validate;
}
// @anchor:can-execute:end
// anchor:custom-can-execute:start
// anchor:custom-can-execute:end
return result;
}
public CustomCommandResult execute(ParameterContext<CatBreedCommand.RemoveCatBreed> commandParameter) {
Context context = commandParameter.getContext();
CatBreedCommand.RemoveCatBreed command = commandParameter.getValue();
// @anchor:before-execute:start
// @anchor:before-execute:end
// anchor:custom-before-execute:start
// anchor:custom-before-execute:end
CustomCommandResult canExecuteResult = canExecute(commandParameter);
if (canExecuteResult.isError()) {
return canExecuteResult;
}
CustomCommandResult result = CustomCommandResult.success(command.getCommandId());
// @anchor:execute:start
// @anchor:execute:end
// anchor:custom-execute:start
// anchor:custom-execute:end
// anchor:default-implementation:start
CatBreedDataFacade facade = new CatBreedDataFacade(context);
SearchResult<CatBreedDataRef> catBreedSearchResult = facade.findById(command.getCatBreedId());
if (catBreedSearchResult.isError()) {
return CustomCommandResult.customError(command.getCommandId(), catBreedSearchResult.getDiagnostics());
}
if (catBreedSearchResult.getFirst().isEmpty()) {
return CustomCommandResult.customError(command.getCommandId(), diagnosticFactory.error("CatBreed.catBreedId.findFailed"));
}
CatBreedDataRef catBreedDataRef = catBreedSearchResult.getFirst().getValue();
// @anchor:before-delete:start
// @anchor:before-delete:end
// anchor:custom-before-delete:start
// anchor:custom-before-delete:end
CrudsResult<Void> deleteResult = CatBreedLocalAgent.getCatBreedAgent(context).delete(catBreedDataRef.getId());
if (deleteResult.isError()) {
return CustomCommandResult.customError(command.getCommandId(), deleteResult.getDiagnostics());
}
// @anchor:after-delete:start
// @anchor:after-delete:end
// anchor:custom-after-delete:start
// anchor:custom-after-delete:end
// anchor:default-implementation:end
return result;
}
// @anchor:methods:start
// @anchor:methods:end
// anchor:custom-methods:start
// anchor:custom-methods:end
}