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

org.sklsft.generator.command.BackupCheckPrompter Maven / Gradle / Ivy

There is a newer version: 2.0.0-M2
Show newest version
package org.sklsft.generator.command;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.List;

import org.sklsft.generator.model.backup.check.BackupPlanPostExecutionWarning;
import org.sklsft.generator.model.backup.check.BackupPlanPreExecutionWarning;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class BackupCheckPrompter {
	
	private static final Logger logger = LoggerFactory.getLogger(BackupCheckPrompter.class);
	
	public void printPreExecutionWarnings(List warnings){
		logger.warn(warnings.size() + " warnings have been generated");
		
		for(BackupPlanPreExecutionWarning w : warnings){
			logger.warn(printPreExecutionWarning(w));
		}
		
	}
	
	public void printPostExecutionWarnings(List warnings){
		logger.warn(warnings.size() + " warnings have been generated");
		
		for(BackupPlanPostExecutionWarning w : warnings){
			logger.warn(printPostExecutionWarning(w));
		}
		
	}
	
	public void promptForConfirmation() throws IOException{
		System.out.println("Do you wish to continue? [Y/n]");
		BufferedReader bufferRead = new BufferedReader(new InputStreamReader(System.in));
		String input = bufferRead.readLine();
		
		if(!("Y".equals(input)||input.isEmpty())){
			logger.warn("Aborting ...");
			System.exit(0);
		}
	}
	
	private String printPreExecutionWarning(BackupPlanPreExecutionWarning w){
		String firstPart = w.getType().getDescription() + w.getTable().originalName;
		if(w.getStep()==BackupPlanPreExecutionWarning.NO_STEP){
			return firstPart;
		}else{
			return firstPart + " on step " + w.getStep();
		}
	}
	
	private String printPostExecutionWarning(BackupPlanPostExecutionWarning w){
		return w.getType().getDescription() + w.getTable().originalName;
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy