/* (non-Javadoc)
@see de.chandre.admintool.quartz.AdminToolQuartzService#changeTriggerState(java.lang.String, java.lang.String, java.lang.String, java.lang.String)
350633
@Override
	public void changeTriggerState(String groupName, String jobName, final String triggerGroup, final String triggerName) throws SchedulerException {
		if (!config.isChangetTriggerStateAllowed()) {
			LOGGER.warn("not allowed to change any trigger state");
			return;
		}
		Trigger triggerFound = findTrigger(groupName, jobName, triggerGroup, triggerName);
		
		if (null != triggerFound) {
			// pause only the one trigger of job
			changeTriggerState(triggerFound);
			if (LOGGER.isDebugEnabled())
				LOGGER.debug(String.format("pausing trigger for group: %s, job: %s, trigger: %s ", groupName, jobName,
						triggerName));
		} else {
			if (LOGGER.isDebugEnabled())
				LOGGER.debug(String.format("pausing all triggers for group: %s, job: %s", groupName, jobName));
			List<? extends Trigger> triggers = scheduler.getTriggersOfJob(new JobKey(jobName, groupName));
			for (Trigger trigger : triggers) {
				// pause all triggers of job
				changeTriggerState(trigger);
			}
		}
	}
991612
public final void setCommitTrigger(CommitTrigger commitTrigger) {
        if (this.commitTrigger == commitTrigger) {
            return;
        }
        if (this.commitTrigger != null) {
            this.commitTrigger.removeCommitTriggerListener(commitTriggerHandler);
            this.commitTrigger = null;
        }
        if (commitTrigger != null) {
            if (this.commitTriggerHandler == null) {
                this.commitTriggerHandler = new CommitTriggerHandler();
            }
            this.commitTrigger = commitTrigger;
            this.commitTrigger.addCommitTriggerListener(commitTriggerHandler);
        }
    }
1297369
public void setTrigger(final DialogOpenTrigger trigger) {
		// pre-1.2.3 compatibilty only:
		if (this.hasLegacyTriggerButton()) {
			DialogOpenTrigger theTrigger = getTrigger();
			if (theTrigger instanceof WButton) {
				remove(theTrigger);
			}
			setLegacyTriggerButton(false);
		}
		// end of backwards compatibility code.
		getOrCreateComponentModel().trigger = trigger;
	}
849072
function diffUpdateTriggers(props, oldProps) {
  if (oldProps === null) {
    return 'oldProps is null, initial diff';
  }

  // If the 'all' updateTrigger fires, ignore testing others
  if ('all' in props.updateTriggers) {
    const diffReason = diffUpdateTrigger(props, oldProps, 'all');
    if (diffReason) {
      return {all: true};
    }
  }

  const triggerChanged = {};
  let reason = false;
  // If the 'all' updateTrigger didn't fire, need to check all others
  for (const triggerName in props.updateTriggers) {
    if (triggerName !== 'all') {
      const diffReason = diffUpdateTrigger(props, oldProps, triggerName);
      if (diffReason) {
        triggerChanged[triggerName] = true;
        reason = triggerChanged;
      }
    }
  }

  return reason;
}
298808
@Override
  public synchronized void addTrigger(final Trigger t) throws TriggerLoaderException {
    logger.info("Inserting trigger " + t.toString() + " into db.");

    final SQLTransaction<Long> insertAndGetLastID = transOperator -> {
      transOperator.update(ADD_TRIGGER, DateTime.now().getMillis());
      // This commit must be called in order to unlock trigger table and have last insert ID.
      transOperator.getConnection().commit();
      return transOperator.getLastInsertId();
    };

    try {
      final long id = this.dbOperator.transaction(insertAndGetLastID);
      t.setTriggerId((int) id);
      updateTrigger(t);
      logger.info("uploaded trigger " + t.getDescription());
    } catch (final SQLException ex) {
      logger.error("Adding Trigger " + t.getTriggerId() + " failed.");
      throw new TriggerLoaderException("trigger id is not properly created.", ex);
    }
  }
123469
@Override
    public Trigger.TriggerState getTriggerState(TriggerKey triggerKey, Jedis jedis){
        final String triggerHashKey = redisSchema.triggerHashKey(triggerKey);
        Pipeline pipe = jedis.pipelined();
        Map<RedisTriggerState, Response<Double>> scores = new HashMap<>(RedisTriggerState.values().length);
        for (RedisTriggerState redisTriggerState : RedisTriggerState.values()) {
            scores.put(redisTriggerState, pipe.zscore(redisSchema.triggerStateKey(redisTriggerState), triggerHashKey));
        }
        pipe.sync();
        for (Map.Entry<RedisTriggerState, Response<Double>> entry : scores.entrySet()) {
            if(entry.getValue().get() != null){
                return entry.getKey().getTriggerState();
            }
        }
        return Trigger.TriggerState.NONE;
    }
962584
@Override
  public Trigger getTrigger(String triggerKey) throws SchedulerException {

    validateState();

    return quartzSchedulerResources.getJobStore().retrieveTrigger(triggerKey);
  }
311720
@Override
	public boolean changeJob(JobTriggerTO triggerTO) throws SchedulerException {
		if (!config.isChangeJobInfoAllowed()) {
			LOGGER.warn("not allowed to change any job info");
			return false;
		}
		JobDetail detail = findJob(triggerTO.getOriginalJobGroup(), triggerTO.getOriginalJobName());
		if (null == detail) {
			return false;
		}
		JobBuilder builder = detail.getJobBuilder()
				.withIdentity(nvl(triggerTO.getJobName(), triggerTO.getOriginalJobName()),
						nvl(triggerTO.getJobGroup(), triggerTO.getOriginalJobGroup()))
				.withDescription(triggerTO.getDescription());
		
		//Builder don't have an interface :-/ so code duplication with triggers
		if (null != triggerTO.getJobData() && !triggerTO.getJobData().isEmpty()) {
			for (Entry<String, Object> entry : triggerTO.getJobData().entrySet()) {
				if (String.class.isAssignableFrom(entry.getValue().getClass())) {
					builder.usingJobData(entry.getKey(), (String)entry.getValue());
				} else if (Boolean.class.isAssignableFrom(entry.getValue().getClass())) {
					builder.usingJobData(entry.getKey(), (Boolean)entry.getValue());
				} else if (Integer.class.isAssignableFrom(entry.getValue().getClass())) {
					builder.usingJobData(entry.getKey(), (Integer)entry.getValue());
				} else if (Long.class.isAssignableFrom(entry.getValue().getClass())) {
					builder.usingJobData(entry.getKey(), (Long)entry.getValue());
				} else if (Double.class.isAssignableFrom(entry.getValue().getClass())) {
					builder.usingJobData(entry.getKey(), (Double)entry.getValue());
				} else if (Float.class.isAssignableFrom(entry.getValue().getClass())) {
					builder.usingJobData(entry.getKey(), (Float)entry.getValue());
				}
				if (LOGGER.isDebugEnabled())
					LOGGER.debug("jobDataEntry: " + entry.getKey() +", val: "+ entry.getValue() + ", class: " + entry.getValue().getClass());
			}
		}
		
		scheduler.addJob(builder.build(), true, true);
		return true;
	}
1039079
public void changeState(String jobName) throws MangooSchedulerException {
        Objects.requireNonNull(this.quartzScheduler, Required.SCHEDULER.toString());
        
        try {
            for (JobKey jobKey : getAllJobKeys()) {
                if (jobKey.getName().equalsIgnoreCase(jobName)) {
                    TriggerState triggerState = getTriggerState(jobKey);
                    if (TriggerState.NORMAL == triggerState) {
                        this.quartzScheduler.pauseJob(jobKey);                        
                    } else {
                        this.quartzScheduler.resumeJob(jobKey);
                    }
                }
            }            
        } catch (SchedulerException | MangooSchedulerException e) {
            throw new MangooSchedulerException(e);
        }
    }
1228581
@Override
    public void pauseTrigger(final TriggerKey triggerKey) throws JobPersistenceException {
        doWithLock(new LockCallbackWithoutResult() {
            @Override
            public Void doWithLock(JedisCommands jedis) throws JobPersistenceException {
                storage.pauseTrigger(triggerKey, jedis);
                return null;
            }
        }, "Could not pause trigger.");
    }
502300
public Trigger<? super S> getDeleteTrigger() {
        ForDelete<S> forDelete = mForDelete;
        return forDelete.isEmpty() ? null : forDelete;
    }
1053511
@Override
    public void resumeTrigger(TriggerKey triggerKey, JedisCluster jedis) throws JobPersistenceException {
        final String triggerHashKey = redisSchema.triggerHashKey(triggerKey);
        Boolean exists = jedis.sismember(redisSchema.triggersSet(), triggerHashKey);
        Double isPaused = jedis.zscore(redisSchema.triggerStateKey(RedisTriggerState.PAUSED), triggerHashKey);
        Double isPausedBlocked = jedis.zscore(redisSchema.triggerStateKey(RedisTriggerState.PAUSED_BLOCKED), triggerHashKey);

        if (!exists) {
            // Trigger does not exist.  Nothing to do.
            return;
        }
        if (isPaused == null && isPausedBlocked == null) {
            // Trigger is not paused. Nothing to do.
            return;
        }
        OperableTrigger trigger = retrieveTrigger(triggerKey, jedis);
        final String jobHashKey = redisSchema.jobHashKey(trigger.getJobKey());
        final Date nextFireTime = trigger.getNextFireTime();

        if (nextFireTime != null) {
            if (isBlockedJob(jobHashKey, jedis)) {
                setTriggerState(RedisTriggerState.BLOCKED, (double) nextFireTime.getTime(), triggerHashKey, jedis);
            } else {
                setTriggerState(RedisTriggerState.WAITING, (double) nextFireTime.getTime(), triggerHashKey, jedis);
            }
        }
        applyMisfire(trigger, jedis);
    }
23030
public void startTrigger(final FlowTrigger flowTrigger, final String flowId,
      final int flowVersion, final String submitUser, final Project project) {
    final TriggerInstance triggerInst = createTriggerInstance(flowTrigger, flowId, flowVersion,
        submitUser, project);
    this.flowTriggerExecutorService.submit(() -> {
      logger.info("Starting the flow trigger [trigger instance id: {}] by {}",
          triggerInst.getId(), submitUser);
      start(triggerInst);
    });
  }
405800
private void setState(State state) {
    if (this.state != state) {
      this.state = state;
      LOGGER.debug("State changed: {}", state);
      changeListeners.forEach(l -> l.accept(state));
    }
  }
1156024
function helper_updateTriggerRule(trigger, event)
{
	var rule = trigger.ruleTable[event.ruleIdentifier];
	if (rule && rule.ruleUpdateFunction)
	{
		rule.ruleUpdateFunction(rule, event.nearable, event);
		helper_updateRuleState(
			event.triggerIdentifier,
			event.ruleIdentifier,
			rule.state);
	}
}
711305
private void setupTrigger() {
		String label = drpTriggerType.getSelected() + " Trigger";

		WFieldLayout layout = new WFieldLayout();
		layout.setLabelWidth(LABEL_WIDTH);

		buildControlPanel.add(layout);

		switch ((TriggerType) drpTriggerType.getSelected()) {
			case RadioButtonGroup:

				trigger = new RadioButtonGroup();

				WFieldSet rbSet = new WFieldSet("Select an option");
				RadioButtonGroup group = (RadioButtonGroup) trigger;
				WRadioButton rb1 = group.addRadioButton("A");
				WRadioButton rb2 = group.addRadioButton("B");
				WRadioButton rb3 = group.addRadioButton("C");
				rbSet.add(group);
				rbSet.add(rb1);
				rbSet.add(new WLabel("A", rb1));
				rbSet.add(new WText("\u00a0"));
				rbSet.add(rb2);
				rbSet.add(new WLabel("B", rb2));
				rbSet.add(new WText("\u00a0"));
				rbSet.add(rb3);
				rbSet.add(new WLabel("C", rb3));
				layout.addField(label, rbSet);
				return;

			case CheckBox:
				trigger = new WCheckBox();
				break;

			case CheckBoxSelect:
				trigger = new WCheckBoxSelect(LOOKUP_TABLE_NAME);
				break;

			case DateField:
				trigger = new WDateField();
				break;

			case Dropdown:
				trigger = new WDropdown(new TableWithNullOption(LOOKUP_TABLE_NAME));
				break;

			case EmailField:
				trigger = new WEmailField();
				break;

			case MultiSelect:
				trigger = new WMultiSelect(LOOKUP_TABLE_NAME);
				break;

			case MultiSelectPair:
				trigger = new WMultiSelectPair(LOOKUP_TABLE_NAME);
				break;

			case NumberField:
				trigger = new WNumberField();
				break;

			case PartialDateField:
				trigger = new WPartialDateField();
				break;

			case PasswordField:
				trigger = new WPasswordField();
				break;

			case PhoneNumberField:
				trigger = new WPhoneNumberField();
				break;

			case RadioButtonSelect:
				trigger = new WRadioButtonSelect(LOOKUP_TABLE_NAME);
				break;

			case SingleSelect:
				trigger = new WSingleSelect(LOOKUP_TABLE_NAME);
				break;

			case TextArea:
				trigger = new WTextArea();
				((WTextArea) trigger).setMaxLength(1000);
				break;

			case TextField:
				trigger = new WTextField();
				break;

			default:
				throw new SystemException("Trigger type not valid");
		}
		layout.addField(label, trigger);
	}
1269356
protected function addTrigger()
    {
        if (!$this->isError()) {
            $state_id = $this->trigger->add($this->getSubmitted());
            if (empty($state_id)) {
                $this->errorAndExit($this->text('Unexpected result'));
            }
            $this->line($state_id);
        }
    }