/* * @(#)VehiclItem.java * * Copyright 2010 Instituto Superior Tecnico * Founding Authors: Luis Cruz, Nuno Ochoa, Paulo Abrantes * * https://fenix-ashes.ist.utl.pt/ * * This file is part of the Expenditure Tracking Module. * * The Expenditure Tracking Module is free software: you can * redistribute it and/or modify it under the terms of the GNU Lesser General * Public License as published by the Free Software Foundation, either version * 3 of the License, or (at your option) any later version. * * The Expenditure Tracking Module is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with the Expenditure Tracking Module. If not, see <http://www.gnu.org/licenses/>. * */ package module.mission.domain; import jvstm.cps.ConsistencyPredicate; import module.mission.domain.activity.ItemActivityInformation; import pt.ist.expenditureTrackingSystem._development.Bundle; import pt.ist.expenditureTrackingSystem.domain.util.DomainException; import pt.ist.fenixframework.Atomic; /** * * @author Luis Cruz * */ public abstract class VehiclItem extends VehiclItem_Base { public VehiclItem() { super(); new VehiclItemJustification(this); setAuthorized(false); } @Override public void delete() { final VehiclItemJustification vehiclItemJustification = getVehiclItemJustification(); if (vehiclItemJustification != null) { vehiclItemJustification.delete(); } setDriver(null); super.delete(); } @Override public boolean isVehicleItem() { return true; } public boolean isAuthorized() { return getAuthorized() != null && getAuthorized(); } @Atomic public void authorize() { setAuthorized(true); } @Atomic public void unauthorize() { setAuthorized(false); } @Override public void setInfo(final ItemActivityInformation itemActivityInformation) { final Mission mission = itemActivityInformation.getProcess().getMission(); if (mission.getParticipantesSet().size() == 1) { super.setInfo(itemActivityInformation); setDriver(mission.getParticipantes().iterator().next()); } else { if (itemActivityInformation.getDriver() == null) { throw new DomainException(Bundle.EXPENDITURE, "A vehicle item must have a driver"); } super.setInfo(itemActivityInformation); setDriver(itemActivityInformation.getDriver()); addPeople(itemActivityInformation.getDriver()); } } @Override protected void setNewVersionInformation(final MissionItem missionItem) { super.setNewVersionInformation(missionItem); final VehiclItem vehiclItem = (VehiclItem) missionItem; getVehiclItemJustification().copy(vehiclItem.getVehiclItemJustification()); vehiclItem.setDriver(getDriver()); vehiclItem.setAuthorized(getAuthorized()); } @ConsistencyPredicate public boolean checkIsTemporaryXorHasDriver() { if (!isTemporary() && hasDriver()) { return true; } if (isTemporary() && !hasDriver()) { return true; } return false; } @Deprecated public boolean hasAuthorized() { return getAuthorized() != null; } @Deprecated public boolean hasVehiclItemJustification() { return getVehiclItemJustification() != null; } @Deprecated public boolean hasDriver() { return getDriver() != null; } }