/**
 * Copyright 2009-2012 OpenAIRE PROJECT (Bielefeld University)
 * Original author: Marek Imialek <marek.imialek at uni-bielefeld.de>
 *
 * 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.
 */
package eu.dnetlib.data.udm;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;

/**
 * @author <a href="mailto:marek.imialek at uni-bielefeld.de">Marek Imialek</a>
 *
 */
public class GenerateTestDirectoryTree {

	/**
	 * @param args
	 * @throws IOException 
	 */
	public static void main(String[] args) throws IOException {
		
		String mainDir = "/srv/udm/servlet";
		int howManyYears = 3;
		int currentYear = 2011;
		int lastYear = currentYear - howManyYears;
		
		for (int y=currentYear; y>=lastYear ;y--) {
			System.out.println("Year: "+ y);
			File year = new File (mainDir+"/"+y);
			
			if (!year.exists())
				year.mkdir();
			
			for (Integer m=1; m<13; m++){
				String monthDir = String.valueOf(m);
				if (m<10)
					monthDir = "0"+m;	
				System.out.println("Month: "+ monthDir);
				File month = new File (mainDir+"/"+y+"/"+monthDir);
				if (!month.exists()) month.mkdir();
				
				for (int d=01; d<31; d++){
					String dayDir = String.valueOf(d);
					if (d<10)
						dayDir = "0"+d;	
					System.out.println("Day: "+ dayDir);
					String filePath = mainDir+"/"+y+"/"+monthDir+"/"
						+y+"-"+monthDir+"-"+dayDir+".xml";
					System.out.println(filePath);
					BufferedWriter fos = 
						new BufferedWriter(new FileWriter(filePath));
					fos.write("<root><date>"+year+"-"+monthDir+"-"+dayDir+"</date></root>");
					fos.close();
				}
				
			}
		}
	}

}
