'org.blueoxygen.workshop.item.SaveItem'

From BlueOxygen Wiki

Jump to: navigation, search
package org.blueoxygen.workshop.item;
 
 
import java.lang.reflect.InvocationTargetException;
import java.sql.Timestamp;
import org.apache.commons.beanutils.PropertyUtils;
import org.blueoxygen.cimande.LogInformation;
import org.blueoxygen.workshop.entity.Item;
 
 
public class SaveItem extends ItemForm{
	public String execute(){
		if(getItem().getName() == null ||
				"".equalsIgnoreCase(getItem().getName())){
			addActionError("Nama tidak boleh kosong");
		}
		if(hasErrors()){
			return INPUT;
		}
		LogInformation log;
 
		if(getItem().getId() == null ||
			"".equalsIgnoreCase(getItem().getId())){
			log = new LogInformation();
			log.setCreateBy(sessionCredentials.getCurrentUser().getId());
			log.setCreateDate(new Timestamp(System.currentTimeMillis()));
			getItem().setId(null);
		} else {
			Item temp = getItem();
			setItem((Item) manager.getById(Item.class, getItem().getId()));
			log = getItem().getLogInformation();
		try {
			PropertyUtils.copyProperties(getItem(), temp);
		} catch (IllegalAccessException e) {
			e.printStackTrace();
		} catch (InvocationTargetException e) {
			e.printStackTrace();
		} catch (NoSuchMethodException e) {
			e.printStackTrace();
		}
		}
			log.setLastUpdateBy(sessionCredentials.getCurrentUser().getId());
			log.setLastUpdateDate(new Timestamp(System.currentTimeMillis()));
			log.setActiveFlag(1);
			getItem().setLogInformation(log);
 
			manager.save(getItem());
			return SUCCESS;
		}
 
}
Personal tools