package routines;

import java.io.IOException;

/*
 * user specification: the function's comment should contain keys as follows: 1. write about the function's comment.but
 * it must be before the "{talendTypes}" key.
 * 
 * 2. {talendTypes} 's value must be talend Type, it is required . its value should be one of: String, char | Character,
 * long | Long, int | Integer, boolean | Boolean, byte | Byte, Date, double | Double, float | Float, Object, short |
 * Short
 * 
 * 3. {Category} define a category for the Function. it is required. its value is user-defined .
 * 
 * 4. {param} 's format is: {param} <type>[(<default value or closed list values>)] <name>[ : <comment>]
 * 
 * <type> 's value should be one of: string, int, list, double, object, boolean, long, char, date. <name>'s value is the
 * Function's parameter name. the {param} is optional. so if you the Function without the parameters. the {param} don't
 * added. you can have many parameters for the Function.
 * 
 * 5. {example} gives a example for the Function. it is optional.
 */
public class SystemEnvironmentUtil {

	private static final String DELIMITER = "___";
	
    /**
     * helloExample: not return value, only print "hello" + message.
     * 
     * 
     * {talendTypes} String
     * 
     * {Category} SystemEnvironmentUtil
     * 
     * {param} string(jobName) input: The string need to be printed.
     * 
     * {example} getCoreJobName("jobToBeDone#init") # jobToBeDone !.
     */
    public static String getJobPackageName(String jobName) {
    	int pos = jobName.lastIndexOf(DELIMITER);
    	if (pos > 0) {
    		return jobName.substring(0, pos);
    	} else {
    		return jobName;
    	}
    }
    public static void checkPrerequisits(java.util.Properties context)
    {
  		// put given time into calender with environment time zone
		java.util.Calendar envCalendar = java.util.Calendar.getInstance();
		
		// bail out when job is not running in UTC,
		// since this would result in wrong toString function of sql components
        java.util.TimeZone envZone = envCalendar.getTimeZone();
		if (!"UTC".equals(envZone.getID())) {
			throw new RuntimeException("JVM is not in UTC time zone. Please add -Duser.timezone=UTC to JVM parameters of job.") ;
		}
    }
    
    public static boolean isWindows()
    {
  		return (System.getProperty("os.name").toLowerCase().indexOf("win") >= 0);
    }
}
