com.elephantdrummer.trigger.AtTrigger Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of drummer Show documentation
Show all versions of drummer Show documentation
Elephant Drummer Java Job Scheduler
The newest version!
package com.elephantdrummer.trigger;
import java.util.Date;
import java.util.logging.Level;
import com.elephantdrummer.container.ContainerElement;
import com.elephantdrummer.exception.DrummerException;
import com.elephantdrummer.parser.ParserDateMaskToDate;
import com.elephantdrummer.parser.ParserDateMaskToStep;
import com.elephantdrummer.trigger.base.DrumTrigger;
import com.elephantdrummer.trigger.base.TriggerType;
import com.elephantdrummer.validator.IValidatorDrummerJob;
/**
* Copyright 2018 Elephant Software Klaudiusz Wojtkowiak e-mail: [email protected]
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
public class AtTrigger extends DrumTrigger implements ContainerElement{
@Override
public String getDescription() {
return "Executes at fixed datetime.";
}
@Override
public Date getNextRunTime(Date currDate) {
Date retVal=null;
try{
retVal= calculateForDate(currDate);
}catch(DrummerException dr){
log.log(Level.SEVERE, ""+dr.getDrummerError().toString()+" - "+dr.getMessage());
}
return retVal;
}
@Override
public final TriggerType getTriggerType() {
return TriggerType.AT;
}
protected Date calculateForDate(Date dt) {
if (dt==null) return null;
// String ddhh=ParserDate.parse(currDate, "ddHH");
// System.out.println(ddhh);
// boolean debug=ParserString.toInteger(ddhh).intValue()==2923;
if (dt.before(new Date())){
dt=new Date();
}
Date rv=dt;
if (IValidatorDrummerJob.isAtNonDefault(getAt())){
// Datete covered by AT map
Date atdt=ParserDateMaskToDate.applyAtToDate(getAt(),dt);
//Is After provided
if (IValidatorDrummerJob.isAfterNotDefault(getAfter())){
//Date covered by AFTER map
Date afterdt=ParserDateMaskToDate.applyAfterToDate(getAfter(),dt);
if (afterdt.after(atdt)){
atdt=ParserDateMaskToDate.applyAtToDate(getAt(), afterdt);
}
}
if (dt.before(atdt)){
rv= atdt;
}else{
rv=ParserDateMaskToStep.addDateStepToDate(atdt,dt,getAt());
}
}
Date from=ParserDateMaskToDate.applyAfterToDate(getAfter(),rv);
Date to=ParserDateMaskToDate.applyBeforeToDate(getBefore(),rv);
if (to==null==false&&to.before(rv)){
rv=to;
from=ParserDateMaskToStep.addDateStepToDate(to,rv,getBefore());
rv=ParserDateMaskToDate.applyAfterToDate(getAfter(),from);
from=rv;
}
if (from==null==false&&rv.before(from)){
Date atmask=ParserDateMaskToDate.applyAtToDate(getAt(),rv);
rv=ParserDateMaskToStep.addDateStepToDate(atmask,rv,getAt());
}else{
rv=ParserDateMaskToDate.applyAtToDate(getAt(),rv);
}
if (IValidatorDrummerJob.isAfterNotDefault(getAfter())){
Date aftermask=ParserDateMaskToDate.applyAfterToDate(getAfter(),rv);
if (aftermask.after(rv)){
rv=ParserDateMaskToDate.applyAtToDate(getAt(), aftermask);
}
}
return rv;
}
}