Service annotations

The @Service annotation and its companions, with a real example from the manufacturing application.

Source: framework/service/src/com/ilscipio/scipio/service/def/.

@Service#

Defines one service. Place it on a nested public interface inside a container class; the interface itself carries no members.

AttributeTypeDefaultMeaning
nameString""Service name. Defaults to the method or class name in camelCase.
descriptionString""Service description.
deprecatedString""Deprecation note.
deprecatedSinceString""Version the service was deprecated in.
deprecatedByString""Replacement service name.
implementedImplements[]{}Interfaces this service implements.
entityAttributesEntityAttributes[]{}Attributes generated from an entity’s fields.
attributesAttribute[]{}Explicit attribute list.
overrideAttributesOverrideAttribute[]{}Overrides for attributes an implemented interface already declares.
authString"false"Whether a user login is required for the call to succeed.
permissionServicePermissionService[]{}Permission services to check.
permissionPermission[]{}Permissions to check.
permissionsPermissions[]{}Grouped permission checks with a join type.
exportString"false"Whether to export the service as a web service.
validateString"true"Whether to validate attributes on invocation.
defaultEntityNameString""Entity that entityAttributes reads by default.
useTransactionString"true"Whether to wrap the call in a database transaction.
requireNewTransactionString"false"Whether to force a new transaction.
hideResultInLogString"false"Whether to hide the result in the log.
transactionTimeoutString"0"Transaction timeout in seconds. 0 uses the transaction factory default.
maxRetryString"-1"Max retries when run as a job. -1 means no limit.
debugString""Debug flag. Empty means the engine default, "false".
semaphoreString"none""none", "fail" or "wait".
semaphoreWaitSecondsString"300"Wait time for a "wait" semaphore.
semaphoreSleepString"500"Sleep interval while waiting.
logString""Logging verbosity: "normal", "debug" or "quiet". Empty means "normal".
logEcaString""Logging verbosity when invoked from an ECA. Empty means "normal".
priorityString""Default job priority for async or scheduled runs.
startDelayString""Fixed start delay in milliseconds.
engineString""Service engine, for example "java", "simple", "groovy".
locationString""Class or script location the engine invokes.
invokeString""Method or entry-point name the engine invokes.
invokesGroupInvoke[]{}For a "group" engine, the ordered list of services to run.
accessorLocationString""Location of the accessor the engine uses.
accessorInvokeString""Accessor method the engine invokes.
namespaceString""Namespace, for a service exported as a web service.
namespacePrefixString""Namespace prefix, for a service exported as a web service.
jobPoolPersistString""Job pool a persisted async run is queued on.
logTraceExcludeDispatcherRegexString""Dispatcher names excluded from trace logging, as a regular expression.
metricsMetric[]{}Metrics collected for this service.
propertiesProperty[]{}Free-form properties, read with @Property.

@Attribute#

One explicit service parameter, inside @Service(attributes = {...}).

AttributeTypeDefaultMeaning
nameStringrequiredAttribute name.
descriptionString""Attribute description.
typeString""Java type name.
typeClsClassObject.classJava type as a class literal.
modeString"""IN", "OUT" or "INOUT".
optionalString"false"Whether the attribute is optional.
defaultValueString""Default value when not optional and no value is passed.
formLabelString""Label for auto-generated forms.
entityNameString""Entity the attribute maps to.
fieldNameString""Entity field the attribute maps to.
requestAttributeNameString""Request attribute name to read from.
sessionAttributeNameString""Session attribute name to read from.
stringMapPrefixString""Prefix used to collect a string map from request parameters.
stringListSuffixString""Suffix used to collect a string list from request parameters.
formDisplayString"true"Whether to include the attribute in auto-generated forms.
allowHtmlString"none""none" or "any".
typeConvertString""Whether to convert the value to the declared type.
typeValidateTypeValidate[]{}Validation methods to run.
accessString"""public" or "internal".
eventAccessString""Access level from an event context.
injectString""Whether to inject the default value onto a protected field.

@EntityAttributes#

Generates a block of attributes from an entity’s own fields, inside @Service(entityAttributes = {...}).

AttributeTypeDefaultMeaning
entityNameString""Entity to read fields from. Defaults to the service’s defaultEntityName.
prefixString""Prefix added to each generated attribute name.
modeStringrequired"IN", "OUT" or "INOUT".
includeString"all""all", "pk" or "nonpk".
optionalString"false"Whether the generated attributes are optional.
formDisplayString"true"Whether to include the attributes in auto-generated forms.
allowHtmlString"none""none" or "any".
typeConvertString""Whether to convert values to the declared type.
excludeFieldsString[]{}Fields to exclude from generation.
accessString"""public" or "internal".
eventAccessString""Access level from an event context.

@OverrideAttribute#

Overrides one attribute an implemented interface already declares, inside @Service(overrideAttributes = {...}). Same attribute names as @Attribute except name and type keep their meaning and every other field defaults to "" (unset, meaning inherit).

@Implements#

Declares that this service reuses another service’s interface, inside @Service(implemented = {...}).

AttributeTypeDefaultMeaning
serviceString""Service whose interface (attributes) this service implements.
optionalString"false"Whether the implemented definition may be missing.

@Permission / @Permissions / @PermissionService#

AnnotationAttributeTypeDefaultMeaning
@PermissionpermissionStringrequiredPermission id to check.
@PermissionactionString""Action suffix, for example _VIEW.
@PermissionsjoinTypeString"""OR" or "AND" across the group. Empty means "OR".
@PermissionspermissionsPermission[]{}Permissions in the group.
@PermissionsservicesPermissionService[]{}Permission services in the group.
@PermissionServiceserviceStringrequiredService that checks the permission.
@PermissionServiceresourceDescriptionString""Text used in error messages. Defaults to the service name.
@PermissionServicemainActionString""Action passed to the permission service.

@Property#

One property passed to the service engine, inside @Service(properties = {...}).

AttributeTypeDefaultMeaning
nameStringrequiredProperty name.
descriptionString""Property description.
typeString""Property type.
valueString""Property value.

@TypeValidate#

One validation method, inside @Attribute(typeValidate = {...}).

AttributeTypeDefaultMeaning
methodStringrequiredStatic method name to call.
classNameString"org.ofbiz.base.util.UtilValidate"Class the method lives on.
failMessageString""Message on failure.
failPropertyString""Properties key for the failure message.
failResourceString""Resource bundle the failure message comes from.

@Seca and @SecaAction#

A SECA (Service Event Condition Action) runs one or more actions when a source service reaches an event. Source: framework/service/src/com/ilscipio/scipio/service/def/seca/.

AnnotationAttributeTypeDefaultMeaning
@SecaserviceString""Source service to attach to. Defaults to the annotated service.
@SecaeventStringrequiredglobal-commit, global-commit-post-run, global-rollback, auth, in-validate, out-validate, invoke, commit, return.
@SecarunOnFailureString"false"Run the action if the source service returns failure.
@SecarunOnErrorString"false"Run the action if the source service returns error.
@SecaenabledString"true"Enables or disables the SECA.
@SecaconditionString""Condition expression.
@SecaassignmentsSecaSet[]{}Field assignments before the action runs.
@SecaactionsSecaAction[]{}Actions to run.
@SecaActionserviceString""Service to invoke. Defaults to the annotated service.
@SecaActionmodeString"sync""sync" or "async".
@SecaActionrunAsUserString""User to run as. Defaults to the currently running user.
@SecaActionresultMapNameString""Name to store the result under.
@SecaActionnewTransactionString"false"Whether to run in a new transaction.
@SecaActionresultToContextString"true"Whether to inject the result into the next service’s context.
@SecaActionresultToResultString"false"Whether to copy the result into the source service’s own result.
@SecaActionignoreFailure, ignoreErrorString""Ignore a failure or error result.
@SecaActionpersistString""Persist the job.
@SecaActionpriorityString""Job priority, 0-100. Defaults to 50.
@SecaActionjobPoolString""Job pool to run in, when persist="false".
@SecaActionassignmentsSecaSet[]{}Field assignments before the invocation.

@Eeca and @EecaAction#

An EECA (Entity Event Condition Action) runs one or more actions when an entity operation reaches an event. Source: framework/service/src/com/ilscipio/scipio/service/def/eeca/.

AnnotationAttributeTypeDefaultMeaning
@EecaentityStringrequiredEntity name.
@EecaoperationStringrequiredcreate, store, remove, find, create-store, create-remove, store-remove, create-store-remove or any.
@EecaeventStringrequiredvalidate, run, return, cache-check, cache-put, cache-clear.
@EecarunOnErrorString"false"Run the action if the entity operation returns error.
@EecaenabledString"true"Enables or disables the EECA.
@EecaconditionString""Condition expression.
@EecaassignmentsEecaSet[]{}Field assignments before the action runs.
@EecaactionsEecaAction[]{}Actions to run.
@EecaActionserviceString""Service to invoke. Defaults to the annotated service.
@EecaActionmodeString"sync""sync" or "async".
@EecaActionresultToValueString"true"Transfer the service result onto the entity value.
@EecaActionabortOnErrorString"false"Abort on error.
@EecaActionrollbackOnErrorString"false"Roll back the transaction on error.
@EecaActionpersistString"false"Persist the job.
@EecaActionrunAsUserString""User to run as. Defaults to "system".
@EecaActionvalueAttrString""Attribute name the entity value is passed under.
@EecaActionpriorityString""Job priority, 0-100. Defaults to 50.
@EecaActionjobPoolString""Job pool to run in, when persist="false".
@EecaActionreloadValueString"false"Reload the value before running.
@EecaActionassignmentsEecaSet[]{}Field assignments before the invocation.

Example: createBOMAssoc#

applications/manufacturing/src/com/ilscipio/scipio/manufacturing/service/BomServices.java, lines 33-51.

java
@Service(
    name = "createBOMAssoc",
    engine = "java",
    location = "com.ilscipio.scipio.manufacturing.event.BomSimpleMethods",
    invoke = "createBOMAssoc",
    description = "Add Product to Product Association",
    defaultEntityName = "ProductAssoc",
    auth = "true",
    entityAttributes = {
        @EntityAttributes(mode = "IN", include = "pk"),
        @EntityAttributes(mode = "IN", include = "nonpk", optional = "true")
    },
    attributes = {
        @Attribute(name = "errorMessage", type = "String", mode = "OUT", optional = "true")
    },
    overrideAttributes = {
        @OverrideAttribute(name = "fromDate", optional = "true")
    }
)
public interface CreateBOMAssoc {}

The equivalent XML <service> element:

xml
<service name="createBOMAssoc" engine="java"
    location="com.ilscipio.scipio.manufacturing.event.BomSimpleMethods" invoke="createBOMAssoc"
    default-entity-name="ProductAssoc" auth="true"
    description="Add Product to Product Association">
    <auto-attributes include="pk" mode="IN" optional="false"/>
    <auto-attributes include="nonpk" mode="IN" optional="true"/>
    <override name="fromDate" optional="true"/>
    <attribute name="errorMessage" type="String" mode="OUT" optional="true"/>
</service>

Ask the people who wrote it.

Support, development and training from the team that builds Scipio ERP.