// Path: src/fi/mamk/osa/stripes/OsaActionBeanContext.java
// public class OsaActionBeanContext extends ActionBeanContext {
// 
// 	public User getUser() {
// 		return (User) getRequest().getSession().getAttribute("user");
// 	}
// 	
// 	public void setUser(User user) {
// 		getRequest().getSession().setAttribute("user", user);
// 	}
// 	
// 	public Gui getGui() {
// 		return (Gui) getRequest().getSession().getAttribute("gui");
// 	}
// 	
// 	public void setGui(Gui gui) {
// 		getRequest().getSession().setAttribute("gui", gui);
// 	}
// 	
// 	public void setSearch(Search search) {
// 		getRequest().getSession().setAttribute("search", search);
// 	}
// 	
// 	public Search getSearch() {
// 		return (Search) getRequest().getSession().getAttribute("search");
// 	}
// 		
// }


import java.awt.image.BufferedImage;
import java.awt.image.ColorModel;
import java.awt.image.RenderedImage;
import java.awt.image.WritableRaster;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Hashtable;
import java.util.LinkedHashMap;
import javax.imageio.ImageIO;
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.FilenameUtils;
import org.apache.log4j.Logger;
import org.apache.pdfbox.pdmodel.PDDocument;
import org.apache.pdfbox.pdmodel.PDPage;
import org.imgscalr.Scalr;
import com.sun.media.jai.codec.FileSeekableStream;
import com.sun.media.jai.codec.ImageCodec;
import com.sun.media.jai.codec.ImageDecoder;
import com.sun.media.jai.codec.SeekableStream;
import com.sun.media.jai.codec.TIFFDecodeParam;
import fi.mamk.osa.stripes.OsaActionBeanContext;
                    fileOutputStream = new FileOutputStream(thumbnailPathAndName);
                    ImageIO.write(thumb, THUMB_EXTENSION, fileOutputStream);
                    
                } else {
                    bufferedImage = ImageIO.read(new File(filePath));
                    thumb = Scalr.resize(bufferedImage, 200); // Scale the original image around the width and height of 150 px, maintaining original aspect ratio
                    fileOutputStream = new FileOutputStream(thumbnailPathAndName);
                    ImageIO.write(thumb, THUMB_EXTENSION, fileOutputStream);
                    
                }
                
            } catch (IOException e) {
                logger.error("Error creating thumbnail for image file: "+e.getMessage());
            } 

        }
        
        thumbFile = new File(thumbnailPathAndName);
        
        if (thumbFile.canRead()) {
            try {
                fileOutputStream.close();
            } catch (IOException e) {
                logger.error("Error creating thumbnail file: "+e.getMessage());
            }
        }
                
        return thumbFile;
    }
    
// Path: src/fi/mamk/osa/stripes/OsaActionBeanContext.java
// public class OsaActionBeanContext extends ActionBeanContext {
// 
// 	public User getUser() {
// 		return (User) getRequest().getSession().getAttribute("user");
// 	}
// 	
// 	public void setUser(User user) {
// 		getRequest().getSession().setAttribute("user", user);
// 	}
// 	
// 	public Gui getGui() {
// 		return (Gui) getRequest().getSession().getAttribute("gui");
// 	}
// 	
// 	public void setGui(Gui gui) {
// 		getRequest().getSession().setAttribute("gui", gui);
// 	}
// 	
// 	public void setSearch(Search search) {
// 		getRequest().getSession().setAttribute("search", search);
// 	}
// 	
// 	public Search getSearch() {
// 		return (Search) getRequest().getSession().getAttribute("search");
// 	}
// 		
// }


// Path: src/fi/mamk/osa/bean/ThumbBean.java
import java.awt.image.BufferedImage;
import java.awt.image.ColorModel;
import java.awt.image.RenderedImage;
import java.awt.image.WritableRaster;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Hashtable;
import java.util.LinkedHashMap;
import javax.imageio.ImageIO;
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.FilenameUtils;
import org.apache.log4j.Logger;
import org.apache.pdfbox.pdmodel.PDDocument;
import org.apache.pdfbox.pdmodel.PDPage;
import org.imgscalr.Scalr;
import com.sun.media.jai.codec.FileSeekableStream;
import com.sun.media.jai.codec.ImageCodec;
import com.sun.media.jai.codec.ImageDecoder;
import com.sun.media.jai.codec.SeekableStream;
import com.sun.media.jai.codec.TIFFDecodeParam;
import fi.mamk.osa.stripes.OsaActionBeanContext;

                    fileOutputStream = new FileOutputStream(thumbnailPathAndName);
                    ImageIO.write(thumb, THUMB_EXTENSION, fileOutputStream);
                    
                } else {
                    bufferedImage = ImageIO.read(new File(filePath));
                    thumb = Scalr.resize(bufferedImage, 200); // Scale the original image around the width and height of 150 px, maintaining original aspect ratio
                    fileOutputStream = new FileOutputStream(thumbnailPathAndName);
                    ImageIO.write(thumb, THUMB_EXTENSION, fileOutputStream);
                    
                }
                
            } catch (IOException e) {
                logger.error("Error creating thumbnail for image file: "+e.getMessage());
            } 

        }
        
        thumbFile = new File(thumbnailPathAndName);
        
        if (thumbFile.canRead()) {
            try {
                fileOutputStream.close();
            } catch (IOException e) {
                logger.error("Error creating thumbnail file: "+e.getMessage());
            }
        }
                
        return thumbFile;
    }
    
    public static void createThumbFileAfterUpload(String mimeType, String filename, String dir, OsaActionBeanContext context) {