//String staTime =(String) iterationData[3];
//String endTime =(String) iterationData[4];
mMetadataOutputBlockWriter = getOutput(METADATA);
ListIterator parameters=(ListIterator) iterationData[0];
parametersMap=extractParameters(parameters);
BlockWriter output = getOutput();
ArrayList<File> fileList=new ArrayList<File>();
try {
String homeDir=mResource.getHomeDirectory().getAbsolutePath();
final String station=(String) parametersMap.get(STATION);
String channel=(String) parametersMap.get(CHANNEL);
Calendar eCal=GregorianCalendar.getInstance();
Calendar sCal=GregorianCalendar.getInstance();
SimpleDateFormat dateFormatter = new SimpleDateFormat("yyyy-MM-dd");
Date sDate=dateFormatter.parse((String)parametersMap.get(START_TIME));
Date eDate=dateFormatter.parse((String)parametersMap.get(END_TIME));
sCal.setTime(sDate);
eCal.setTime(eDate);
StringBuffer dirName=new StringBuffer();
File homeDirectory=mResource.getHomeDirectory();
File[] stationDir=homeDirectory.listFiles(
new FilenameFilter() {
public boolean accept(File dir, String name) {
return name.contains(station);
};
});
if (stationDir.length==0 || !stationDir[0].exists()||!stationDir[0].isDirectory())
{
System.out.println("station: "+station+" not found");
outmap.put(ERROR,"station: "+station+" not found");
throw new ActivityUserException(new Throwable("station: "+station+" not found"));
}
// dirName.append(stationDir[0].getPath()).append(File.separatorChar);
String stationPath=stationDir[0].getPath().substring(homeDir.length());
while(eCal.compareTo(sCal)>=0){
dirName.append(stationPath).append(File.separatorChar)
.append(eCal.get(Calendar.YEAR)).append(File.separatorChar)
.append(String.format("%tm", eCal));
String dName=dirName.toString();
dirName.setLength(0);
// System.out.println("dirname: "+dName);
File directory = mResource.getFileForReading(dName);
// System.out.println("directory check: "+directory.getAbsolutePath());
if (!directory.exists())
{
System.out.println(dName+" "+" DIRECTORY_NOT_FOUND");
eCal.add(Calendar.MONTH, - 1);
continue;
}
else if (!directory.isDirectory())
{
throw new ActivityUserException(ErrorID.NOT_A_DIRECTORY);
}
File[] files = directory.listFiles(new WFileFilter(dateFormatter.format(eCal.getTime()), "",station.toUpperCase(), channel.toUpperCase()));
for(File file:files)
{
System.out.println("adding file: "+file.getName());
fileList.add(file);
}
eCal.add(Calendar.DAY_OF_MONTH, - 1);
}
output.write(ControlBlock.LIST_BEGIN);
for (Iterator<File> it = fileList.iterator(); it.hasNext();)
{
String outFile=it.next().getAbsolutePath().substring(homeDir.length());
System.out.println("file: "+outFile);
output.write(outFile );
}
output.write(ControlBlock.LIST_END);
}catch (ActivityUserException ae) {
try {
output.write(ControlBlock.LIST_BEGIN);
output.write("");
output.write(ControlBlock.LIST_END);
} catch (PipeClosedException e)
{
iterativeStageComplete();
}