All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.ikasan.spec.scheduled.context.model.ContextTemplate Maven / Gradle / Ivy

Go to download

All specifications packaged up in a single uber jar for convenience of use in the Enterprise Integration Platform

The newest version!
package org.ikasan.spec.scheduled.context.model;

import com.fasterxml.jackson.annotation.JsonIgnore;
import org.apache.commons.lang3.SerializationUtils;
import org.ikasan.spec.scheduled.job.model.SchedulerJob;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

public interface ContextTemplate extends Context, Serializable {

    /**
     * Set context template to disabled.
     *
     * @param disabled
     */
    void setDisabled(boolean disabled);

    /**
     * Determine if the context template is disabled.
     *
     * @return
     */
    boolean isDisabled();


    /**
     * Retrieve all instances of SchedulerJob from the current ContextTemplate and its child Contexts.
     *
     * @return a list of SchedulerJob instances
     */
    @JsonIgnore
    default List getAllSchedulerJobs() {
        ArrayList results = new ArrayList<>();

        if(this.getScheduledJobs() != null && !this.getScheduledJobsMap().isEmpty()) {
            this.getScheduledJobs().forEach(job ->
            {
                SchedulerJob clone = SerializationUtils.clone(job);
                results.add(clone);
            });
        }

        if(this.getContexts() != null && !this.getContexts().isEmpty()) {
            this.getContexts().forEach(contextInstance -> results.addAll(contextInstance.getAllSchedulerJobs()));
        }

        return results;
    }

    /**
     * Retrieves all context names where a job with the given identifier resides.
     *
     * @param jobIdentifier the identifier of the job
     * @return a list of context names
     */
    @JsonIgnore
    default List getAllContextNamesWhereJobResides(String jobIdentifier) {
        ArrayList results = new ArrayList<>();

        if(this.getScheduledJobs() != null && !this.getScheduledJobsMap().isEmpty()) {
            if(this.getScheduledJobsMap().containsKey(jobIdentifier)) {
                results.add(this.getName());
            }
        }

        if(this.getContexts() != null && !this.getContexts().isEmpty()) {
            this.getContexts().forEach(contextInstance -> results
                .addAll(contextInstance.getAllContextNamesWhereJobResides(jobIdentifier)));
        }

        return results.stream().distinct().collect(Collectors.toList());
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy