ItEr30S06CUAltaMaquina: [FixBug] Changed Criterions Machines ZUL page to adapt to CriterionSatisfactionDTO interface
This commit is contained in:
parent
0de0ad951f
commit
6468fca4b4
4 changed files with 162 additions and 42 deletions
|
|
@ -1,5 +1,7 @@
|
|||
package org.navalplanner.web.resources.machine;
|
||||
|
||||
import static org.navalplanner.web.I18nHelper._;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.HashSet;
|
||||
|
|
@ -37,6 +39,9 @@ import org.zkoss.zk.ui.WrongValueException;
|
|||
@Scope(BeanDefinition.SCOPE_PROTOTYPE)
|
||||
public class AssignedMachineCriterionsModel implements IAssignedMachineCriterionsModel {
|
||||
|
||||
private ClassValidator<CriterionSatisfactionDTO> satisfactionDTOValidator = new ClassValidator<CriterionSatisfactionDTO>(
|
||||
CriterionSatisfactionDTO.class);
|
||||
|
||||
private ClassValidator<CriterionSatisfactionDTO> satisfactionValidator = new ClassValidator<CriterionSatisfactionDTO>(
|
||||
CriterionSatisfactionDTO.class);
|
||||
|
||||
|
|
@ -342,4 +347,61 @@ public class AssignedMachineCriterionsModel implements IAssignedMachineCriterion
|
|||
satisfaction.setEndDate(newEndDate);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void validate() throws ValidationException, IllegalStateException {
|
||||
validateDTOs();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void confirm() throws ValidationException, IllegalStateException {
|
||||
updateDTOs();
|
||||
}
|
||||
|
||||
private void validateDTOs() throws ValidationException {
|
||||
Set<CriterionSatisfactionDTO> listDTOs = new HashSet<CriterionSatisfactionDTO>(
|
||||
criterionSatisfactionDTOs);
|
||||
for (CriterionSatisfactionDTO satisfactionDTO : listDTOs) {
|
||||
InvalidValue[] invalidValues;
|
||||
invalidValues = satisfactionDTOValidator
|
||||
.getInvalidValues(satisfactionDTO);
|
||||
if (invalidValues.length > 0) {
|
||||
throw new ValidationException(invalidValues);
|
||||
}
|
||||
Criterion criterion = satisfactionDTO.getCriterionWithItsType()
|
||||
.getCriterion();
|
||||
if (checkSameCriterionAndSameInterval(satisfactionDTO)) {
|
||||
throw new IllegalStateException(_("The {0} can not be assigned to this resource. Its interval overlap with other criterion", criterion.getName()));
|
||||
}
|
||||
if (checkNotAllowSimultaneousCriterionsPerResource(satisfactionDTO)) {
|
||||
throw new IllegalStateException(_("The {0} is not valid, criterionType overlaps with other criterionSatisfaction from the same criterionType", criterion.getName()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void updateDTOs() throws ValidationException, IllegalStateException {
|
||||
// Create a new list of Criterion satisfaction
|
||||
Set<CriterionSatisfaction> newList = new HashSet<CriterionSatisfaction>();
|
||||
for (CriterionSatisfactionDTO satisfactionDTO : criterionSatisfactionDTOs) {
|
||||
CriterionSatisfaction satisfaction;
|
||||
if (satisfactionDTO.isIsNewObject()) {
|
||||
Criterion criterion = satisfactionDTO.getCriterionWithItsType()
|
||||
.getCriterion();
|
||||
Interval interval = satisfactionDTO.getInterval();
|
||||
satisfaction = CriterionSatisfaction.create(criterion,
|
||||
resource, interval);
|
||||
|
||||
} else {
|
||||
satisfaction = satisfactionDTO.getCriterionSatisfaction();
|
||||
if (satisfactionDTO.isIsDeleted()) {
|
||||
satisfaction.setIsDeleted(true);
|
||||
} else {
|
||||
satisfaction.setStartDate(satisfactionDTO.getStartDate());
|
||||
satisfaction.finish(satisfactionDTO.getEndDate());
|
||||
}
|
||||
}
|
||||
newList.add(satisfaction);
|
||||
}
|
||||
resource.addSatisfactions(newList);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -63,4 +63,8 @@ public interface IAssignedMachineCriterionsModel {
|
|||
CriterionWithItsType criterionAndType) throws WrongValueException;
|
||||
|
||||
void prepareForCreate(Resource resource);
|
||||
|
||||
void validate() throws ValidationException, IllegalStateException;
|
||||
|
||||
void confirm() throws ValidationException, IllegalStateException;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,25 +5,38 @@
|
|||
package org.navalplanner.web.resources.worker;
|
||||
|
||||
import static org.navalplanner.web.I18nHelper._;
|
||||
import static org.navalplanner.web.common.InvalidInputsChecker.isInvalid;
|
||||
import static org.navalplanner.web.common.InvalidInputsChecker.thereAreInvalidInputsOn;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import org.hibernate.validator.InvalidValue;
|
||||
import org.navalplanner.business.common.exceptions.ValidationException;
|
||||
import org.navalplanner.business.resources.entities.CriterionSatisfaction;
|
||||
import org.navalplanner.business.resources.entities.CriterionWithItsType;
|
||||
import org.navalplanner.business.resources.entities.Worker;
|
||||
import org.navalplanner.business.workreports.entities.WorkReportLine;
|
||||
import org.navalplanner.web.common.IMessagesForUser;
|
||||
import org.navalplanner.web.common.Level;
|
||||
import org.navalplanner.web.common.MessagesForUser;
|
||||
import org.navalplanner.web.common.Util;
|
||||
import org.zkoss.zk.ui.Component;
|
||||
import org.zkoss.zk.ui.WrongValueException;
|
||||
import org.zkoss.zk.ui.util.GenericForwardComposer;
|
||||
import org.zkoss.zul.Bandbox;
|
||||
import org.zkoss.zul.Column;
|
||||
import org.zkoss.zul.Combobox;
|
||||
import org.zkoss.zul.Comboitem;
|
||||
import org.zkoss.zul.Constraint;
|
||||
import org.zkoss.zul.Datebox;
|
||||
import org.zkoss.zul.Grid;
|
||||
import org.zkoss.zul.Hbox;
|
||||
import org.zkoss.zul.ListModelExt;
|
||||
import org.zkoss.zul.Listitem;
|
||||
import org.zkoss.zul.Row;
|
||||
import org.zkoss.zul.Rows;
|
||||
|
||||
/**
|
||||
*
|
||||
|
|
@ -32,30 +45,48 @@ import org.zkoss.zul.Row;
|
|||
public class CriterionsController extends GenericForwardComposer {
|
||||
|
||||
private IAssignedCriterionsModel assignedCriterionsModel;
|
||||
private Combobox comboboxFilter;
|
||||
private Combobox comboboxfilter;
|
||||
private Grid listingCriterions;
|
||||
private IMessagesForUser messages;
|
||||
private Component messagesContainer;
|
||||
|
||||
protected CriterionsController() {
|
||||
CriterionsController(IWorkerModel workerModel) {
|
||||
assignedCriterionsModel = workerModel.getAssignedCriterionsModel();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void doAfterCompose(Component comp) throws Exception {
|
||||
super.doAfterCompose(comp);
|
||||
if (messagesContainer == null)
|
||||
throw new RuntimeException(_("MessagesContainer is needed"));
|
||||
messages = new MessagesForUser(messagesContainer);
|
||||
comp.setVariable("assignedCriterionsController", this, true);
|
||||
comboboxFilter = (Combobox) comp.getFellow("comboboxfilter");
|
||||
listingCriterions = (Grid) comp.getFellow("listingCriterions");
|
||||
//comboboxFilter = (Combobox) comp.getFellow("comboboxfilter");
|
||||
//listingCriterions = (Grid) comp.getFellow("listingCriterions");
|
||||
}
|
||||
|
||||
public IAssignedCriterionsModel getModel(){
|
||||
return this.assignedCriterionsModel;
|
||||
}
|
||||
|
||||
public void prepareForEdit(Worker worker) {
|
||||
this.assignedCriterionsModel.prepareForEdit(worker);
|
||||
reload();
|
||||
}
|
||||
|
||||
public Set<CriterionSatisfactionDTO> getCriterionSatisfactionDTOs() {
|
||||
Comboitem comboitem = comboboxFilter.getSelectedItem();
|
||||
if((comboitem != null) && (comboitem.getLabel().equals("in force"))) {
|
||||
return assignedCriterionsModel.getFilterCriterionSatisfactions();
|
||||
}
|
||||
return assignedCriterionsModel.getAllCriterionSatisfactions();
|
||||
public void prepareForCreate(Worker worker) {
|
||||
this.assignedCriterionsModel.prepareForCreate(worker);
|
||||
}
|
||||
|
||||
public List<CriterionSatisfactionDTO> getCriterionSatisfactionDTOs() {
|
||||
List<CriterionSatisfactionDTO> list = new ArrayList<CriterionSatisfactionDTO>();
|
||||
Comboitem comboitem = comboboxfilter.getSelectedItem();
|
||||
if((comboitem != null) && (comboitem.getLabel().equals("Currents"))) {
|
||||
list.addAll(assignedCriterionsModel.getFilterCriterionSatisfactions());
|
||||
}else{
|
||||
list.addAll(assignedCriterionsModel.getAllCriterionSatisfactions());
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
public void addCriterionSatisfaction() {
|
||||
|
|
@ -69,6 +100,18 @@ public class CriterionsController extends GenericForwardComposer {
|
|||
|
||||
public void reload() {
|
||||
Util.reloadBindings(listingCriterions);
|
||||
forceSortGridSatisfaction();
|
||||
}
|
||||
|
||||
public void forceSortGridSatisfaction() {
|
||||
Column column = (Column) listingCriterions.getColumns().getFirstChild();
|
||||
ListModelExt model = (ListModelExt) listingCriterions.getModel();
|
||||
if ("ascending".equals(column.getSortDirection())) {
|
||||
model.sort(column.getSortAscending(), true);
|
||||
}
|
||||
if ("descending".equals(column.getSortDirection())) {
|
||||
model.sort(column.getSortDescending(), false);
|
||||
}
|
||||
}
|
||||
|
||||
public void remove(CriterionSatisfactionDTO criterionSatisfactionDTO){
|
||||
|
|
@ -108,7 +151,14 @@ public class CriterionsController extends GenericForwardComposer {
|
|||
}
|
||||
}
|
||||
|
||||
public void changeDate(Component comp){
|
||||
public void changeStartDate(Component comp,Date value){
|
||||
CriterionSatisfactionDTO criterionSatisfactionDTO =
|
||||
(CriterionSatisfactionDTO)((Row) comp.getParent()).getValue();
|
||||
validateCriterionWithItsType(criterionSatisfactionDTO,comp);
|
||||
reload();
|
||||
}
|
||||
|
||||
public void changeEndDate(Component comp,Date value){
|
||||
CriterionSatisfactionDTO criterionSatisfactionDTO =
|
||||
(CriterionSatisfactionDTO)((Row) comp.getParent()).getValue();
|
||||
validateCriterionWithItsType(criterionSatisfactionDTO,comp);
|
||||
|
|
@ -120,39 +170,47 @@ public class CriterionsController extends GenericForwardComposer {
|
|||
@Override
|
||||
public void validate(Component comp, Object value)
|
||||
throws WrongValueException {
|
||||
CriterionSatisfactionDTO criterionSatisfactionDTO =
|
||||
(CriterionSatisfactionDTO)((Row) comp.getParent()).getValue();
|
||||
if(!criterionSatisfactionDTO.isLessToEndDate((Date) value)){
|
||||
throw new WrongValueException(comp,
|
||||
_("Start date is not valid, the new start date must be lower than the end date"));
|
||||
}else if(!criterionSatisfactionDTO.isPreviousStartDate((Date) value)){
|
||||
throw new WrongValueException(comp,
|
||||
_("End date is not valid, the new end date must be later the current end date"));
|
||||
}
|
||||
validateStartDate(comp,value);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
private void validateStartDate(Component comp, Object value){
|
||||
CriterionSatisfactionDTO criterionSatisfactionDTO =
|
||||
(CriterionSatisfactionDTO)((Row) comp.getParent()).getValue();
|
||||
if(!criterionSatisfactionDTO.isLessToEndDate((Date) value)){
|
||||
throw new WrongValueException(comp,
|
||||
_("Start date is not valid, the new start date must be lower than the end date"));
|
||||
}else if(!criterionSatisfactionDTO.isPreviousStartDate((Date) value)){
|
||||
throw new WrongValueException(comp,
|
||||
_("End date is not valid, the new end date must be later the current end date"));
|
||||
}
|
||||
}
|
||||
|
||||
public Constraint validateEndDate(){
|
||||
return new Constraint() {
|
||||
@Override
|
||||
public void validate(Component comp, Object value)
|
||||
throws WrongValueException {
|
||||
CriterionSatisfactionDTO criterionSatisfactionDTO =
|
||||
(CriterionSatisfactionDTO)((Row) comp.getParent()).getValue();
|
||||
if(!criterionSatisfactionDTO.isGreaterStartDate((Date) value)){
|
||||
throw new WrongValueException(comp,
|
||||
_("End date is not valid, the new end date must be greater than the start date"));
|
||||
}else if(!criterionSatisfactionDTO.isPostEndDate((Date) value)){
|
||||
throw new WrongValueException(comp,
|
||||
_("End date is not valid, the new end date must be later the current end date"));
|
||||
}
|
||||
validateCriterionWithItsType(criterionSatisfactionDTO,comp);
|
||||
validateEndDate(comp,value);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
private void validateEndDate(Component comp, Object value){
|
||||
CriterionSatisfactionDTO criterionSatisfactionDTO =
|
||||
(CriterionSatisfactionDTO)((Row) comp.getParent()).getValue();
|
||||
if(!criterionSatisfactionDTO.isGreaterStartDate((Date) value)){
|
||||
throw new WrongValueException(comp,
|
||||
_("End date is not valid, the new end date must be greater than the start date"));
|
||||
}else if(!criterionSatisfactionDTO.isPostEndDate((Date) value)){
|
||||
throw new WrongValueException(comp,
|
||||
_("End date is not valid, the new end date must be later the current end date"));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Shows invalid values for {@link CriterionSatisfaction}
|
||||
* entities
|
||||
*
|
||||
|
|
@ -183,7 +241,7 @@ public class CriterionsController extends GenericForwardComposer {
|
|||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* Shows invalid inputs for {@link CriterionSatisfactionDTO} entities
|
||||
*
|
||||
* @param
|
||||
|
|
@ -265,7 +323,7 @@ public class CriterionsController extends GenericForwardComposer {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* Locates which {@link row} is bound to {@link WorkReportLine} in
|
||||
* rows
|
||||
*
|
||||
|
|
@ -314,8 +372,4 @@ public class CriterionsController extends GenericForwardComposer {
|
|||
return (Bandbox)((Hbox) row.getChildren().get(0))
|
||||
.getChildren().get(0);
|
||||
}
|
||||
|
||||
public void save() throws ValidationException{
|
||||
assignedCriterionsModel.save();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,8 +9,8 @@
|
|||
<label class="subtitulo" value="${i18n:_('Filters :')}" />
|
||||
<combobox id="comboboxFilter"
|
||||
onSelect="assignedCriterionsController.reload();">
|
||||
<comboitem label="all" />
|
||||
<comboitem label="in force" />
|
||||
<comboitem label="${i18n:_('All')}" />
|
||||
<comboitem label="${i18n:_('Currents')}" />
|
||||
</combobox>
|
||||
<separator bar="false" spacing="20px" orient="vertical"/>
|
||||
</hbox>
|
||||
|
|
@ -18,7 +18,7 @@
|
|||
model="@{assignedCriterionsController.criterionSatisfactionDTOs}"
|
||||
mold="paging" pageSize="5">
|
||||
<columns>
|
||||
<column label="${i18n:_('Criterion name')}"/>
|
||||
<column label="${i18n:_('Criterion name')}" sort="auto(criterionAndType)" sortDirection="ascending" />
|
||||
<column label="${i18n:_('Starting date')}" width="200px" align="center"/>
|
||||
<column label="${i18n:_('Ending date')}" width="200px" align="center"/>
|
||||
<column label="${i18n:_('State')}" width="70px" align="center"/>
|
||||
|
|
@ -48,7 +48,7 @@
|
|||
</bandpopup>
|
||||
</bandbox>
|
||||
<label visible="@{criterionSatisfactionDTO.isOldObject}"
|
||||
value="@{criterionSatisfactionDTO.nameAndType}"/>
|
||||
value="@{criterionSatisfactionDTO.criterionAndType}"/>
|
||||
</hbox>
|
||||
<datebox id="startDate" value="@{criterionSatisfactionDTO.startDate}"
|
||||
constraint="@{assignedCriterionsController.validateStartDate}"
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue