package siprp.database.cayenne.objects;

import siprp.database.cayenne.objects.auto._HsPostoRisco;

public class HsPostoRisco extends _HsPostoRisco {

	private static final long serialVersionUID = 1L;
	
	@Override
	public String toString()
	{
		return super.getToHsRisco().getDescription();
	}
	@Override
	public void save() throws Exception
	{
		HsPosto posto = getToHsPosto();
		if( posto != null )
		{
			Integer maxOrder = 0;
			for( HsPostoRisco rel : posto.getHsPostoRiscoArray() )
			{
				Integer currentOrder = rel.getOrder();
				if( currentOrder != null )
				{
					maxOrder = Math.max( currentOrder, maxOrder );
				}
			}
			this.setOrder( maxOrder + 1 );
		}
		super.save();
	}
	
}
