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

com.elephantdrummer.executor.base.structure.DrummerMethodJobWrapper Maven / Gradle / Ivy

There is a newer version: 1.2.5
Show newest version
package com.elephantdrummer.executor.base.structure;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

import com.elephantdrummer.annotation.DrummerJob;
import com.elephantdrummer.annotation.TestJob;
import com.elephantdrummer.classconfig.JobClassConfig;
import com.elephantdrummer.scope.DrummerObservable;


/**
 * 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 DrummerMethodJobWrapper implements DrummerJobProvider{
	
	private DrummerJob drummerJobAnnotation;
	private TestJob testJobAnnotation;
	private Method method;
	private DrummerObservable drummerObservable;
	private JobClassConfig configuration;
	private AfterJobExecution afterJob;
	private BeforeJobExecution beforeJob;
	
	@SuppressWarnings("unused")
	private DrummerMethodJobWrapper(){};
	
	public DrummerMethodJobWrapper(DrummerObservable drummerObservable,Method method,DrummerJob drummerJobAnnotation,TestJob testJobAnnotation) {
		setDrummerJobAnnotation(drummerJobAnnotation);
		setTestJobAnnotation(testJobAnnotation);
		//TODO: obligatoryjnosc
		setMethod(method);
		setDrummerObservable(drummerObservable);
		
	}
	
	public DrummerMethodJobWrapper(DrummerObservable drummerObservable,Method method,DrummerJob drummerJobAnnotation,TestJob testJobAnnotation,JobClassConfig configuration) {
		setDrummerJobAnnotation(drummerJobAnnotation);
		setTestJobAnnotation(testJobAnnotation);
		//TODO: obligatoryjnosc
		setMethod(method);
		setDrummerObservable(drummerObservable);
		setConfiguration(configuration);
	}
	

	@Override
	public void jobLogic() {
		try {
			getMethod().invoke(getDrummerObservable());
		} catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
	}

	public DrummerJob getDrummerJobAnnotation() {
		return drummerJobAnnotation;
	}

	public void setDrummerJobAnnotation(DrummerJob drummerJobAnnotation) {
		this.drummerJobAnnotation = drummerJobAnnotation;
	}

	public TestJob getTestJobAnnotation() {
		return testJobAnnotation;
	}

	public void setTestJobAnnotation(TestJob testJobAnnotation) {
		this.testJobAnnotation = testJobAnnotation;
	}

	public DrummerObservable getDrummerObservable() {
		return drummerObservable;
	}

	public void setDrummerObservable(DrummerObservable drummerObservable) {
		this.drummerObservable = drummerObservable;
	}

	public Method getMethod() {
		return method;
	}

	public void setMethod(Method method) {
		this.method = method;
	}

	 @Override
	public String toString() {
		String jobname=getDrummerJobAnnotation().name();
		return "Name:"+jobname+" - "+getDrummerObservable().getClass().getName()+"."+getMethod().getName();
	}

	public JobClassConfig getConfiguration() {
		return configuration;
	}

	public void setConfiguration(JobClassConfig configuration) {
		this.configuration = configuration;
	}

	 @Override
	public  JobClassConfig getCustomisedDrummerJobConfiguration() {
		return getConfiguration();
	}

	public AfterJobExecution getAfterJob() {
		return afterJob;
	}

	public void setAfterJob(AfterJobExecution afterJob) {
		this.afterJob = afterJob;
	}

	public BeforeJobExecution getBeforeJob() {
		return beforeJob;
	}

	public void setBeforeJob(BeforeJobExecution beforeJob) {
		this.beforeJob = beforeJob;
	}
	
	 @Override
	public void afterDrummerJobExecution() {
		if (getAfterJob()==null) return;
		getAfterJob().afterDrummerJobExecution();
	}
	
	 @Override
	public void beforeDrummerJobExecution() {
		if (getBeforeJob()==null) return;
		getBeforeJob().beforeDrummerJobExecution();
	}

//	public MultiTrigger getMultiTrigger() {
//		return multiTrigger;
//	}
//
//	public void setMultiTrigger(MultiTrigger multiTrigger) {
//		this.multiTrigger = multiTrigger;
//	}


}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy