/*
 * Copyright (c) 2009 The openGion Project.
 *
 * 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 gf;

import org.opengion.fukurou.business.BizLogic_ENTRY;
import java.io.File;
import org.opengion.fukurou.util.ImageResizer;
import org.opengion.hayabusa.common.HybsSystem;

/**
 * ファイルリサイズ処理のテストロジックです
 *
 * @og.rev 5.4.3.7 (2012/01/20) 新規作成
 * @og.group 業務ロジック
 * 
 * @version 5.0
 * @author Takahashi Masakazu
 * @since JDK1.6,
 */

public class GF7140 extends BizLogic_ENTRY {

	private String filePathAbs = null;
	
	/**
	 * チェックロジックを定義します。
	 * 
	 * @return 処理が正常終了したか
	 */
	protected boolean check() {
		return must( "FILEPATH,DOCNM" );
	}

	/**
	 * メイン処理を定義します。
	 * 
	 * @return 処理が正常終了したか
	 */
	protected boolean logic() {
		filePathAbs = var( "FILEPATH" ).replace( '/', File.separatorChar );
		
		boolean rtn = makeResizeImage( filePathAbs+var("DOCNM"), filePathAbs+"rs_"+var("DOCNM"), 100 );
		File infile = new File(filePathAbs+var("DOCNM"));
		infile.delete();

		return rtn;
	}
	
	private boolean makeResizeImage( final String fileName, final String rszName, final int maxSize ) {
		File infile = new File(fileName);
		File outfile = new File(rszName);
		ImageResizer ir = new ImageResizer( infile.getAbsolutePath() );
		ir.resizeByPixel( outfile.getAbsolutePath(), maxSize );
		return true;
	}
}
