package edu.ucsf.lava.core.importer.controller;

import java.util.Map;

import org.springframework.validation.BindingResult;
import org.springframework.webflow.execution.RequestContext;

import edu.ucsf.lava.core.controller.BaseEntityComponentHandler;
import edu.ucsf.lava.core.controller.ComponentCommand;
import edu.ucsf.lava.core.controller.ScrollablePagedListHolder;
import edu.ucsf.lava.core.importer.model.ImportLog;

/**
 * ImportLogHandler
 * 
 * Handles the CRUD for ImportLog. Only view is supported for ImportLog, i.e. no add, edit, delete
 * as each ImportLog is created by the import action, and being a log, is not editable thereafter.
 * 
 * @author ctoohey
 *
 */
public class ImportLogHandler extends BaseEntityComponentHandler {

	public ImportLogHandler() {
		super();
		setHandledEntity("importLog", ImportLog.class);
	}

	public Map addReferenceData(RequestContext context, Object command, BindingResult errors, Map model)
	{
		// put individual log messages in a component for the view to display
	 	ImportLog importLog = (ImportLog) ((ComponentCommand)command).getComponents().get("importLog");
		ScrollablePagedListHolder logMessagesListHolder = new ScrollablePagedListHolder();
		logMessagesListHolder.setSourceFromEntityList(importLog.getMessages());
		((ComponentCommand)command).getComponents().put("importLogMessages", logMessagesListHolder);

		return model;
	}

}

@@ -370,24 +370,122 @@
 istHolder;%0D%0A
+import edu.ucsf.lava.core.file.model.ImportFile;%0D%0Aimport edu.ucsf.lava.core.file.model.LavaFile;%0D%0A
 import edu.u
@@ -525,16 +525,16 @@
 rtLog;%0D%0A
-
 %0D%0A/**%0D%0A 
@@ -955,16 +955,56 @@
 lass);%0D%0A
+%09%09this.setSupportsAttachedFiles(true);%0D%0A
 %09%7D%0D%0A%0D%0A%09p
@@ -1563,11 +1563,459 @@
 %0D%0A%09%7D%0D%0A%0D%0A
+%09/**%0D%0A%09 * Override so that the download event downloads the importLog data file.%0D%0A%09 */%0D%0A%09protected LavaFile getLavaFileBackingObject(RequestContext context, Map components, BindingResult errors) throws Exception%7B%0D%0A%09%09ImportLog importLog = (ImportLog) components.get(getDefaultObjectName());%0D%0A%09%09if(ImportFile.class.isAssignableFrom(importLog.getDataFile().getClass()))%7B%0D%0A%09%09%09return (ImportFile)importLog.getDataFile();%0D%0A%09%09%7D%0D%0A%09%09return null;%0D%0A%09%7D%0D%0A%09%0D%0A%09%0D%0A
 %7D%0D%0A

support downloading dataFile