/*
 * Created on Dec 26, 2006
 */
package org.griphyn.vdl.karajan.lib;

import java.util.Map;

import org.globus.cog.karajan.arguments.Arg;
import org.globus.cog.karajan.stack.VariableStack;
import org.globus.cog.karajan.util.TypeUtil;
import org.globus.cog.karajan.workflow.ExecutionException;
import org.globus.cog.karajan.workflow.nodes.restartLog.LogEntry;
import org.globus.cog.karajan.workflow.nodes.restartLog.MutableInteger;
import org.griphyn.vdl.mapping.DSHandle;
import org.griphyn.vdl.mapping.Path;

public class IsLogged extends VDLFunction {
	static {
		setArguments(IsLogged.class, new Arg[] { PA_VAR, PA_PATH });
	}

	public Object function(VariableStack stack) throws ExecutionException {		
		DSHandle var = (DSHandle) PA_VAR.getValue(stack);
		Path path;
		Object p = PA_PATH.getValue(stack);
		if (p instanceof Path) {
			path = (Path) p;
		}
		else {
			path = Path.parse(TypeUtil.toString(p));
		}
		String file = var.getMapper().map(path).toString();
		LogEntry entry = LogEntry.build(file);
		Map map = getLogData(stack);
		boolean found = false;
		synchronized (map) {
			MutableInteger count = (MutableInteger) map.get(entry);
			if (count != null && count.getValue() > 0) {
				found = true;
			}
		}
		return Boolean.valueOf(found);
	}
}

@@ -912,16 +912,61 @@
 ));%0A%09%09%7D%0A
+%09%09path = var.getPathFromRoot().append(path);%0A
 %09%09String

use correct path for the mapper