package net.sourceforge.fenixedu.presentationTier.backBeans.softplanning; import java.util.ArrayList; import java.util.List; import java.util.ResourceBundle; import javax.faces.model.SelectItem; import net.sourceforge.fenixedu.applicationTier.Filtro.exception.FenixFilterException; import net.sourceforge.fenixedu.applicationTier.Servico.exceptions.FenixServiceException; import net.sourceforge.fenixedu.domain.exceptions.DomainException; import net.sourceforge.fenixedu.domain.teacher.Category; import net.sourceforge.fenixedu.domain.teacher.Rebides; import net.sourceforge.fenixedu.domain.teacher.TeacherProfessionalSituation; import net.sourceforge.fenixedu.presentationTier.Action.exceptions.FenixActionException; import net.sourceforge.fenixedu.presentationTier.Action.resourceAllocationManager.utils.ServiceUtils; import net.sourceforge.fenixedu.presentationTier.backBeans.base.FenixBackingBean; import net.sourceforge.fenixedu.util.RegimeType; /** * @author Paulo Costa (paulo.costa@iscte.pt) * */ public class RebidesTable extends FenixBackingBean { private final ResourceBundle softplanningBundle = getResourceBundle("resources/SoftplanningResources"); // the list of already associated rebides private List rebidesTable; private Integer selectedCategory; private String selectedRegime; private Integer selectedPercentage; private Double major; private Double minor; private Rebides chosenRebides; private String message; public RebidesTable() { super(); } public List getRebides() { if (rebidesTable == null) { rebidesTable = rootDomainObject.getRebides(); } return rebidesTable; } public void setRebides(final List rebides) { this.rebidesTable = rebides; } public List getRebidesTable() { if (rebidesTable == null) { rebidesTable = rootDomainObject.getRebides(); } return rebidesTable; } public void setRebidesTable(final List rebidesTable) { this.rebidesTable = rebidesTable; } public Integer getSelectedCategory() { if (selectedCategory == null && getChosenRebides() != null) { selectedCategory = getChosenRebides().getCategory().getIdInternal(); } return selectedCategory; } public void setSelectedCategory(final Integer selectedCategory) { this.selectedCategory = selectedCategory; } public String getSelectedRegime() { if (selectedRegime == null && getChosenRebides() != null) { selectedRegime = getChosenRebides().getRegimeType().name(); } return selectedRegime; } public void setSelectedRegime(final String selectedRegime) { this.selectedRegime = selectedRegime; } public List getCategories() { final List categories = new ArrayList(); categories.add(new SelectItem(-1, softplanningBundle.getString("label.select.one"))); for (final Category category : Category.readTeacherCategories()) { categories.add(new SelectItem(category.getIdInternal(), category.getShortName())); } return categories; } public List getRegimeTypes() { final List regimeTypes = new ArrayList(); regimeTypes.add(new SelectItem("none", softplanningBundle.getString("label.select.one"))); for (final RegimeType rtype : RegimeType.values()) { regimeTypes.add(new SelectItem(rtype.name(), rtype.getLocalizedName())); } return regimeTypes; } public List getPercentages() { final List percentages = new ArrayList(); percentages.add(new SelectItem(-1, softplanningBundle.getString("label.select.one"))); for (final Integer percent : TeacherProfessionalSituation.getPercentageList()) { percentages.add(new SelectItem(percent, percent + " %")); } return percentages; } public Double getMajor() { if(major == null && getChosenRebides() != null){ major = getChosenRebides().getMajor(); } return major; } public void setMajor(final Double major) { this.major = major; } public Double getMinor() { if(minor == null && getChosenRebides() != null){ minor = getChosenRebides().getMinor(); } return minor; } public void setMinor(final Double minor) { this.minor = minor; } public void setChosenRebides(final Rebides chosenRebides) { this.chosenRebides = chosenRebides; } public Rebides getChosenRebides() { if (chosenRebides == null) { chosenRebides = rootDomainObject.readRebidesByOID(readRebidesId()); } return chosenRebides; } public void setSelectedPercentage(final Integer selectedPercentage) { this.selectedPercentage = selectedPercentage; } public Integer getSelectedPercentage() { if (selectedPercentage == null && getChosenRebides() != null) { selectedPercentage = getChosenRebides().getPercentage(); } return selectedPercentage; } public boolean getIsCreateAction() { return getChosenRebides() == null; } public void setMessage(final String message) { this.message = message; } public String getMessage() { if (message != null && message.length() == 0) { message = null; } return message; } public Double getDefaultMax(){ return Rebides.getDefaultMaxRebides(); } public Double getDefaultMin(){ return Rebides.getDefaultMinRebides(); } // ACTIONS public String createRebides() { return createOrEditRebides(null, "success.create.rebides"); } public String editRebides() { return createOrEditRebides(getChosenRebides(), "success.edit.rebides"); } private String createOrEditRebides(final Rebides chosenRebides, final String sucessMessageLabel) { setErrorMessage(""); message = null; final Object[] args = new Object[] { getSelectedCategory(), getSelectedRegime(), getSelectedPercentage(), getMinor(), getMajor(), chosenRebides, userView.getUtilizador() }; try { ServiceUtils.executeService( "CreateOrEditRebides", args); setMessage(softplanningBundle.getString(sucessMessageLabel)); return "success"; } catch (FenixFilterException e) { e.printStackTrace(); setErrorMessage(e.getLocalizedMessage()); } catch (FenixServiceException e) { e.printStackTrace(); setErrorMessage(e.getLocalizedMessage()); } catch (DomainException e) { setErrorMessage(softplanningBundle.getString(e.getLocalizedMessage())); } return ""; } public String deleteRebides() throws FenixActionException{ try { if ((Boolean) ServiceUtils.executeService( "DeleteRebides", readRebidesId())) { setMessage(softplanningBundle.getString("success.delete.rebides")); } else { setMessage(softplanningBundle.getString("no.success.delete.rebides")); } return "success"; } catch (FenixFilterException e) { e.printStackTrace(); setErrorMessage(e.getLocalizedMessage()); } catch (FenixServiceException e) { e.printStackTrace(); setErrorMessage(e.getLocalizedMessage()); } catch (DomainException e) { setErrorMessage(e.getLocalizedMessage()); } return ""; } private Integer readRebidesId() { Integer param = getAndHoldIntegerParameter("spCreateRebides:rebidesId"); if (param == null) { param = getAndHoldIntegerParameter("rebidesId"); } if (param == null) { param = getAndHoldIntegerParameter("spDeleteRebides:rebidesId"); } return param; } }