Startseite / Plugin-Entwicklung / Server-Plugins / Auftragsaktionen / Anwendung

Application

Application Class

Interface: de.espirit.firstspirit.scheduling.ScheduleTaskApplication
FirstSpirit Access API: ScheduleTaskApplication <D extends ScheduleTaskData>

The schedule task application represents the core of a schedule task definition. It provides metadata about the task, such as name and description, and may optionally specify an icon and whether or not it may run outside of a project context. The class implementation of ScheduleTaskApplication must be parameterized with the type of the custom data object.

/**
* This class specifies the task application including its metadata such as name and description,
* and indicates in which contexts the task may be used.
*/
public class MyScheduleTaskApplication implements ScheduleTaskApplication<MyScheduleTaskData> {

private final ApplicationAspectMap _aspects;

public MyScheduleTaskApplication() {
_aspects = new ApplicationAspectMap();
_aspects.put(IconProviding.TYPE, new MyIconProvidingApplicationAspect());
_aspects.put(ProjectRequirementOverriding.TYPE, new MyProjectRequirementOverridingApplicationAspect());
}

@NotNull
@Override
public String getName(@NotNull final Locale locale) {
return "My Example Schedule Task";
}

@Nullable
@Override
public String getDescription(@NotNull final Locale locale) {
return "Provides example functionality that may be run on a schedule.";
}

@Nullable
@Override
public <A> A getAspect(final ApplicationAspectType<A> type) {
return _aspects.get(type);
}

/**
* This method indicates that the task may only be used in contexts where a project is available.
*/
@Override
public boolean isApplicable(@NotNull final ScheduleTaskDefinitionContext context) {
return context.hasProject();
}

/**
* Instantiate and return an executor object.
*/
@NotNull
@Override
public ScheduleTaskExecutor getExecutor() {
return new MyScheduleTaskExecutor();
}

/**
* Instantiate and return a custom data object of the type this ScheduleTaskApplication
* implementation is parameterized with. If no custom data is required by this task, null may be returned.
*/
@Nullable
@Override
public MyScheduleTaskData createData() {
return new MyScheduleTaskData();
}

/**
* Aspect implementation which provides an icon that may be shown with the task in UIs.
*/
private static class MyIconProvidingApplicationAspect implements IconProviding {

@NotNull
@Override
public Icon getIcon() {
return new ImageIcon(getClass().getResource("myScheduleTaskApplicationIcon.png"));
}
}

/**
* Aspect implementation which overrides the default setting that the task application is
* only available in schedule entries defined within project contexts.
*
* Because MyScheduleTaskApplication#isApplicable(...) is hardcoded to return true only
* if the request to that method happens within a project context, this aspect doesn't even
* need to be implemented, but we're doing that nonetheless to illustrate where the aspect
* may be implemented.
*/
private static class MyProjectRequirementOverridingApplicationAspect implements ProjectRequirementOverriding {

@Override
public boolean tasksMayOperateWithoutProject() {
return false;
}
}
}

Aspects

The schedule task application class may provide implementations of two aspects which are used for additional, optional functionality:

  • Interface: de.espirit.firstspirit.scheduling.aspects.IconProviding
    FirstSpirit Access API: IconProviding

    Specifies an icon for the schedule task application.
  • Interface: de.espirit.firstspirit.scheduling.aspects.ProjectRequirementOverriding
    FirstSpirit Access API: ProjectRequirementOverriding

    By default, custom schedule task applications may only run in a project context (i.e. in a schedule defined in project settings). This aspect allows developers to specify a schedule task application which may also run in a server context without association with a project.

Task Definition Context

FirstSpirit Access API: ScheduleTaskDefinitionContext

In order to determine if a schedule task application may be added to a schedule entry while assembling that entry, the application task method isApplicable receives a ScheduleTaskDefinitionContext object as a parameter which indicates if the schedule entry is being assembled in the context of a project (boolean ScheduleTaskDefinitionContext#hasProject()).

The context object also provides access to agents via the methods requestSpecialist(SpecialistType<S> type) and requireSpecialist(SpecialistType<S> type). For more information on obtaining agents, see the section "Obtaining Agents" in Accessing FirstSpirit Functionality.

Agents Available Via Task Definition Context

Using the ScheduleTaskDefinitionContext object, the following agent may be obtained:

  • ScheduleTaskDefinitionsAgent
    FirstSpirit Access API: ScheduleTaskDefinitionAgent

    This agent provides information about the tasks which have already been added to the schedule entry to which the current schedule task application should be added.

© 2005 - 2024 Crownpeak Technology GmbH | Alle Rechte vorbehalten. | FirstSpirit 2024.12 | Datenschutz