ItEr30S06CUAltaMaquina: Assigned criterions to Machine
This commit is contained in:
parent
114f09799f
commit
b272c256ba
9 changed files with 729 additions and 259 deletions
|
|
@ -0,0 +1,328 @@
|
|||
package org.navalplanner.web.resources.machine;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import org.hibernate.validator.ClassValidator;
|
||||
import org.hibernate.validator.InvalidValue;
|
||||
import org.navalplanner.business.common.exceptions.ValidationException;
|
||||
import org.navalplanner.business.resources.daos.ICriterionTypeDAO;
|
||||
import org.navalplanner.business.resources.daos.IResourceDAO;
|
||||
import org.navalplanner.business.resources.entities.Criterion;
|
||||
import org.navalplanner.business.resources.entities.CriterionSatisfaction;
|
||||
import org.navalplanner.business.resources.entities.CriterionType;
|
||||
import org.navalplanner.business.resources.entities.CriterionWithItsType;
|
||||
import org.navalplanner.business.resources.entities.ICriterionType;
|
||||
import org.navalplanner.business.resources.entities.Interval;
|
||||
import org.navalplanner.business.resources.entities.Resource;
|
||||
import org.navalplanner.web.resources.worker.CriterionSatisfactionDTO;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.config.BeanDefinition;
|
||||
import org.springframework.context.annotation.Scope;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.zkoss.zk.ui.WrongValueException;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Susana Montes Pedreira <smontes@wirelessgalicia.com>
|
||||
* @author Diego Pino Garcia <dpino@igalia.com>
|
||||
*/
|
||||
|
||||
@Service()
|
||||
@Scope(BeanDefinition.SCOPE_PROTOTYPE)
|
||||
public class AssignedMachineCriterionsModel implements IAssignedMachineCriterionsModel {
|
||||
|
||||
private ClassValidator<CriterionSatisfactionDTO> satisfactionValidator = new ClassValidator<CriterionSatisfactionDTO>(
|
||||
CriterionSatisfactionDTO.class);
|
||||
|
||||
@Autowired
|
||||
private IResourceDAO resourceDAO;
|
||||
|
||||
@Autowired
|
||||
private ICriterionTypeDAO criterionTypeDAO;
|
||||
|
||||
private List<CriterionWithItsType> criterionsWithItsTypes = new ArrayList<CriterionWithItsType>();
|
||||
|
||||
private Resource resource;
|
||||
|
||||
private Set<CriterionSatisfactionDTO> criterionSatisfactionDTOs = new HashSet<CriterionSatisfactionDTO>();
|
||||
|
||||
@Override
|
||||
@Transactional(readOnly = true)
|
||||
public void prepareForEdit(Resource resource) {
|
||||
this.resource = resource;
|
||||
if (resource != null) {
|
||||
reattachmentResource();
|
||||
initDTOs();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(readOnly = true)
|
||||
public void reattachmentResource() {
|
||||
resourceDAO.save(resource);
|
||||
initializeCriterionSatisfactions(resource.getCriterionSatisfactions());
|
||||
}
|
||||
|
||||
private void initializeCriterionSatisfactions(
|
||||
Set<CriterionSatisfaction> criterionsSatisfaction) {
|
||||
for (CriterionSatisfaction criterionSatisfaction : criterionsSatisfaction) {
|
||||
initializeCriterionSatisfaction(criterionSatisfaction);
|
||||
}
|
||||
}
|
||||
|
||||
private void initializeCriterionSatisfaction(
|
||||
CriterionSatisfaction criterionSatisfaction) {
|
||||
initializeCriterion(criterionSatisfaction.getCriterion());
|
||||
}
|
||||
|
||||
private void initializeCriterion(Criterion criterion) {
|
||||
criterion.getName();
|
||||
if (criterion.getParent() != null) {
|
||||
criterion.getParent().getName();
|
||||
}
|
||||
reattachCriterionType(criterion.getType());
|
||||
}
|
||||
|
||||
private void reattachCriterionType(CriterionType criterionType) {
|
||||
criterionTypeDAO.save(criterionType);
|
||||
}
|
||||
|
||||
private void initDTOs() {
|
||||
criterionSatisfactionDTOs = new HashSet<CriterionSatisfactionDTO>();
|
||||
for (CriterionSatisfaction criterionSatisfaction : resource
|
||||
.getCriterionSatisfactions()) {
|
||||
if (!criterionSatisfaction.isIsDeleted()) {
|
||||
CriterionSatisfactionDTO dto = new CriterionSatisfactionDTO(
|
||||
criterionSatisfaction);
|
||||
criterionSatisfactionDTOs.add(dto);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<CriterionSatisfactionDTO> getAllCriterionSatisfactions() {
|
||||
if (resource == null) {
|
||||
return new HashSet<CriterionSatisfactionDTO>();
|
||||
}
|
||||
return allSatisfactionsDTO();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<CriterionSatisfactionDTO> getFilterCriterionSatisfactions() {
|
||||
if (resource == null) {
|
||||
return new HashSet<CriterionSatisfactionDTO>();
|
||||
}
|
||||
return filterSatisfactionsDTO();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addCriterionSatisfaction() {
|
||||
CriterionSatisfactionDTO criterionSatisfactionDTO = new CriterionSatisfactionDTO();
|
||||
this.criterionSatisfactionDTOs.add(criterionSatisfactionDTO);
|
||||
}
|
||||
|
||||
private Set<CriterionSatisfactionDTO> allSatisfactionsDTO() {
|
||||
Set<CriterionSatisfactionDTO> satisfactions = new HashSet<CriterionSatisfactionDTO>();
|
||||
for (CriterionSatisfactionDTO criterionSatisfactionDTO : criterionSatisfactionDTOs) {
|
||||
if (!criterionSatisfactionDTO.isIsDeleted()) {
|
||||
satisfactions.add(criterionSatisfactionDTO);
|
||||
}
|
||||
}
|
||||
return satisfactions;
|
||||
}
|
||||
|
||||
private Set<CriterionSatisfactionDTO> filterSatisfactionsDTO() {
|
||||
Set<CriterionSatisfactionDTO> satisfactions = new HashSet<CriterionSatisfactionDTO>();
|
||||
for (CriterionSatisfactionDTO criterionSatisfactionDTO : criterionSatisfactionDTOs) {
|
||||
if ((!criterionSatisfactionDTO.isIsDeleted())
|
||||
&& (criterionSatisfactionDTO.isCurrent())) {
|
||||
satisfactions.add(criterionSatisfactionDTO);
|
||||
}
|
||||
}
|
||||
return satisfactions;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void remove(CriterionSatisfactionDTO criterionSatisfactionDTO) {
|
||||
if (criterionSatisfactionDTO.isIsNewObject()) {
|
||||
criterionSatisfactionDTOs.remove(criterionSatisfactionDTO);
|
||||
} else {
|
||||
criterionSatisfactionDTO.setIsDeleted(true);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(readOnly = true)
|
||||
public List<CriterionWithItsType> getCriterionWithItsType() {
|
||||
criterionsWithItsTypes = new ArrayList<CriterionWithItsType>();
|
||||
List<CriterionType> listTypes = criterionTypeDAO.getCriterionTypes();
|
||||
for (CriterionType criterionType : listTypes) {
|
||||
Set<Criterion> listCriterion = getDirectCriterions(criterionType);
|
||||
getCriterionWithItsType(criterionType, listCriterion);
|
||||
}
|
||||
return criterionsWithItsTypes;
|
||||
}
|
||||
|
||||
private void getCriterionWithItsType(CriterionType type,
|
||||
Set<Criterion> children) {
|
||||
for (Criterion criterion : children) {
|
||||
// Create the criterion with its criterionType and its Hierarchy
|
||||
// label
|
||||
CriterionWithItsType criterionAndType = new CriterionWithItsType(
|
||||
type, criterion);
|
||||
|
||||
// Add to the list
|
||||
criterionsWithItsTypes.add(criterionAndType);
|
||||
getCriterionWithItsType(type, criterion.getChildren());
|
||||
}
|
||||
}
|
||||
|
||||
private static Set<Criterion> getDirectCriterions(
|
||||
CriterionType criterionType) {
|
||||
Set<Criterion> criterions = new HashSet<Criterion>();
|
||||
for (Criterion criterion : criterionType.getCriterions()) {
|
||||
if (criterion.getParent() == null) {
|
||||
criterions.add(criterion);
|
||||
}
|
||||
}
|
||||
return criterions;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCriterionWithItsType(
|
||||
CriterionSatisfactionDTO criterionSatisfactionDTO,
|
||||
CriterionWithItsType criterionAndType) throws WrongValueException {
|
||||
criterionSatisfactionDTO.setCriterionWithItsType(criterionAndType);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean checkSameCriterionAndSameInterval(
|
||||
CriterionSatisfactionDTO satisfaction) {
|
||||
return existSameCriterionAndInterval(satisfaction);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean checkNotAllowSimultaneousCriterionsPerResource(
|
||||
CriterionSatisfactionDTO satisfaction) {
|
||||
ICriterionType<?> type = satisfaction.getCriterionWithItsType()
|
||||
.getType();
|
||||
if (type.isAllowSimultaneousCriterionsPerResource()) {
|
||||
return false;
|
||||
}
|
||||
return existSameCriterionTypeAndInterval(satisfaction);
|
||||
}
|
||||
|
||||
private boolean existSameCriterionTypeAndInterval(
|
||||
CriterionSatisfactionDTO satisfaction) {
|
||||
for (CriterionSatisfactionDTO otherSatisfaction : criterionSatisfactionDTOs) {
|
||||
if ((!otherSatisfaction.equals(satisfaction))
|
||||
&& (sameCriterionType(otherSatisfaction, satisfaction))
|
||||
&& (sameInterval(otherSatisfaction, satisfaction))) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private boolean existSameCriterionAndInterval(
|
||||
CriterionSatisfactionDTO satisfaction) {
|
||||
for (CriterionSatisfactionDTO otherSatisfaction : criterionSatisfactionDTOs) {
|
||||
if ((!otherSatisfaction.equals(satisfaction))
|
||||
&& (sameCriterion(otherSatisfaction, satisfaction))
|
||||
&& (sameInterval(otherSatisfaction, satisfaction))) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private boolean sameCriterion(CriterionSatisfactionDTO otherSatisfaction,
|
||||
CriterionSatisfactionDTO satisfaction) {
|
||||
if (otherSatisfaction.getCriterionWithItsType() == null)
|
||||
return false;
|
||||
Criterion otherCriterion = otherSatisfaction.getCriterionWithItsType()
|
||||
.getCriterion();
|
||||
if (otherCriterion.getId().equals(
|
||||
satisfaction.getCriterionWithItsType().getCriterion().getId()))
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
private boolean sameCriterionType(
|
||||
CriterionSatisfactionDTO otherSatisfaction,
|
||||
CriterionSatisfactionDTO satisfaction) {
|
||||
if (otherSatisfaction.getCriterionWithItsType() == null)
|
||||
return false;
|
||||
ICriterionType<?> criterionType = otherSatisfaction
|
||||
.getCriterionWithItsType().getType();
|
||||
if (criterionType.equals(satisfaction.getCriterionWithItsType()
|
||||
.getType()))
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
private boolean sameInterval(CriterionSatisfactionDTO otherSatisfaction,
|
||||
CriterionSatisfactionDTO satisfaction) {
|
||||
if (otherSatisfaction.getStartDate() == null)
|
||||
return false;
|
||||
Interval otherInterval = otherSatisfaction.getInterval();
|
||||
if (satisfaction.overlapsWith(otherInterval))
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
public void save() throws ValidationException {
|
||||
InvalidValue[] invalidValues;
|
||||
for (CriterionSatisfactionDTO satisfactionDTO : this.criterionSatisfactionDTOs) {
|
||||
invalidValues = satisfactionValidator
|
||||
.getInvalidValues(satisfactionDTO);
|
||||
if (invalidValues.length > 0)
|
||||
throw new ValidationException(invalidValues);
|
||||
save(satisfactionDTO);
|
||||
}
|
||||
System.out.println("### assignedMachine.save: "
|
||||
+ resource.getCriterionSatisfactions());
|
||||
}
|
||||
|
||||
private void save(CriterionSatisfactionDTO satisfactionDTO) {
|
||||
if (satisfactionDTO.isIsNewObject()) {
|
||||
addNewSatisfaction(satisfactionDTO);
|
||||
} else {
|
||||
if (satisfactionDTO.isIsDeleted()) {
|
||||
removeSatisfaction(satisfactionDTO);
|
||||
} else {
|
||||
updateSatisfaction(satisfactionDTO);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void addNewSatisfaction(CriterionSatisfactionDTO satisfactionDTO) {
|
||||
Interval interval = satisfactionDTO.getInterval();
|
||||
resource.addSatisfaction(satisfactionDTO.getCriterionWithItsType(),
|
||||
interval);
|
||||
}
|
||||
|
||||
private void removeSatisfaction(CriterionSatisfactionDTO satisfactionDTO) {
|
||||
CriterionSatisfaction satisfaction = satisfactionDTO
|
||||
.getCriterionSatisfaction();
|
||||
satisfaction.setIsDeleted(true);
|
||||
}
|
||||
|
||||
private void updateSatisfaction(CriterionSatisfactionDTO satisfactionDTO) {
|
||||
CriterionSatisfaction satisfaction = satisfactionDTO
|
||||
.getCriterionSatisfaction();
|
||||
Criterion newCriterion = satisfactionDTO.getCriterionWithItsType()
|
||||
.getCriterion();
|
||||
Date newStartDate = satisfactionDTO.getStartDate();
|
||||
Date newEndDate = satisfactionDTO.getEndDate();
|
||||
satisfaction.setCriterion(newCriterion);
|
||||
satisfaction.setStartDate(newStartDate);
|
||||
satisfaction.setEndDate(newEndDate);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,64 @@
|
|||
/*
|
||||
* This file is part of ###PROJECT_NAME###
|
||||
*
|
||||
* Copyright (C) 2009 Fundación para o Fomento da Calidade Industrial e
|
||||
* Desenvolvemento Tecnolóxico de Galicia
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program 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 Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package org.navalplanner.web.resources.machine;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import org.navalplanner.business.common.exceptions.ValidationException;
|
||||
import org.navalplanner.business.resources.entities.CriterionWithItsType;
|
||||
import org.navalplanner.business.resources.entities.Resource;
|
||||
import org.navalplanner.web.resources.worker.CriterionSatisfactionDTO;
|
||||
import org.zkoss.zk.ui.WrongValueException;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Susana Montes Pedreira <smontes@wirelessgalicia.com>
|
||||
* @author Diego Pino Garcia <dpino@igalia.com>
|
||||
*/
|
||||
public interface IAssignedMachineCriterionsModel {
|
||||
|
||||
void addCriterionSatisfaction();
|
||||
|
||||
public boolean checkNotAllowSimultaneousCriterionsPerResource(
|
||||
CriterionSatisfactionDTO satisfaction);
|
||||
|
||||
public boolean checkSameCriterionAndSameInterval(
|
||||
CriterionSatisfactionDTO satisfaction);
|
||||
|
||||
Set<CriterionSatisfactionDTO> getAllCriterionSatisfactions();
|
||||
|
||||
List<CriterionWithItsType> getCriterionWithItsType();
|
||||
|
||||
Set<CriterionSatisfactionDTO> getFilterCriterionSatisfactions();
|
||||
|
||||
void prepareForEdit(Resource resource);
|
||||
|
||||
void reattachmentResource();
|
||||
|
||||
void remove(CriterionSatisfactionDTO criterionSatisfactionDTO);
|
||||
|
||||
void save() throws ValidationException;
|
||||
|
||||
public void setCriterionWithItsType(
|
||||
CriterionSatisfactionDTO criterionSatisfactionDTO,
|
||||
CriterionWithItsType criterionAndType) throws WrongValueException;
|
||||
}
|
||||
|
|
@ -32,6 +32,8 @@ import org.navalplanner.web.common.MessagesForUser;
|
|||
import org.navalplanner.web.common.OnlyOneVisible;
|
||||
import org.navalplanner.web.common.Util;
|
||||
import org.navalplanner.web.common.entrypoints.IURLHandlerRegistry;
|
||||
import org.navalplanner.web.resources.worker.CriterionsController;
|
||||
import org.navalplanner.web.resources.worker.CriterionsMachineController;
|
||||
import org.zkoss.zk.ui.Component;
|
||||
import org.zkoss.zk.ui.util.GenericForwardComposer;
|
||||
import org.zkoss.zul.api.Window;
|
||||
|
|
@ -57,6 +59,8 @@ public class MachineCRUDController extends GenericForwardComposer {
|
|||
|
||||
private Component messagesContainer;
|
||||
|
||||
private CriterionsMachineController criterionsController;
|
||||
|
||||
public MachineCRUDController() {
|
||||
|
||||
}
|
||||
|
|
@ -66,9 +70,22 @@ public class MachineCRUDController extends GenericForwardComposer {
|
|||
super.doAfterCompose(comp);
|
||||
comp.setVariable("controller", this, true);
|
||||
messagesForUser = new MessagesForUser(messagesContainer);
|
||||
setupCriterionsController();
|
||||
showListWindow();
|
||||
}
|
||||
|
||||
private void setupCriterionsController() throws Exception {
|
||||
final Component comp = editWindow.getFellowIfAny("criterionsContainer");
|
||||
criterionsController = new CriterionsMachineController();
|
||||
criterionsController.doAfterCompose(comp);
|
||||
}
|
||||
|
||||
private CriterionsController getCriterionsController() {
|
||||
return (CriterionsController) editWindow.getFellow(
|
||||
"criterionsContainer").getAttribute(
|
||||
"assignedCriterionsController");
|
||||
}
|
||||
|
||||
private void showListWindow() {
|
||||
getVisibility().showOnly(listWindow);
|
||||
}
|
||||
|
|
@ -91,8 +108,15 @@ public class MachineCRUDController extends GenericForwardComposer {
|
|||
getVisibility().showOnly(editWindow);
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads {@link Machine} into model, shares loaded {@link Machine} with
|
||||
* {@link CriterionsController}
|
||||
*
|
||||
* @param machine
|
||||
*/
|
||||
public void goToEditForm(Machine machine) {
|
||||
machineModel.initEdit(machine);
|
||||
criterionsController.prepareForEdit(machineModel.getMachine());
|
||||
editWindow.setTitle(_("Edit machine"));
|
||||
showEditWindow();
|
||||
Util.reloadBindings(editWindow);
|
||||
|
|
@ -101,6 +125,9 @@ public class MachineCRUDController extends GenericForwardComposer {
|
|||
public void save() {
|
||||
validate();
|
||||
try {
|
||||
if (criterionsController != null) {
|
||||
criterionsController.save();
|
||||
}
|
||||
machineModel.confirmSave();
|
||||
goToList();
|
||||
messagesForUser.showMessage(Level.INFO, _("Machine saved"));
|
||||
|
|
|
|||
|
|
@ -21,6 +21,7 @@
|
|||
package org.navalplanner.web.resources.machine;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import org.apache.commons.lang.Validate;
|
||||
import org.hibernate.validator.ClassValidator;
|
||||
|
|
@ -29,6 +30,8 @@ import org.navalplanner.business.common.exceptions.InstanceNotFoundException;
|
|||
import org.navalplanner.business.common.exceptions.ValidationException;
|
||||
import org.navalplanner.business.resources.daos.IMachineDAO;
|
||||
import org.navalplanner.business.resources.daos.IResourceDAO;
|
||||
import org.navalplanner.business.resources.entities.Criterion;
|
||||
import org.navalplanner.business.resources.entities.CriterionSatisfaction;
|
||||
import org.navalplanner.business.resources.entities.Machine;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.config.BeanDefinition;
|
||||
|
|
@ -76,6 +79,8 @@ public class MachineModel implements IMachineModel {
|
|||
if (invalidValues.length > 0) {
|
||||
throw new ValidationException(invalidValues);
|
||||
}
|
||||
System.out.println("### criterionSatisfactions: "
|
||||
+ machine.getCriterionSatisfactions().size());
|
||||
resourceDAO.save(machine);
|
||||
}
|
||||
|
||||
|
|
@ -92,9 +97,33 @@ public class MachineModel implements IMachineModel {
|
|||
|
||||
private Machine getFromDB(Long id) {
|
||||
try {
|
||||
return (Machine) resourceDAO.find(id);
|
||||
Machine machine = (Machine) resourceDAO.find(id);
|
||||
initializeCriterionsSatisfactions(machine
|
||||
.getCriterionSatisfactions());
|
||||
return machine;
|
||||
} catch (InstanceNotFoundException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
private void initializeCriterionsSatisfactions(
|
||||
Set<CriterionSatisfaction> criterionSatisfactions) {
|
||||
for (CriterionSatisfaction criterionSatisfaction : criterionSatisfactions) {
|
||||
initializeCriterionSatisfaction(criterionSatisfaction);
|
||||
}
|
||||
}
|
||||
|
||||
private void initializeCriterionSatisfaction(
|
||||
CriterionSatisfaction criterionSatisfaction) {
|
||||
initializeCriterion(criterionSatisfaction.getCriterion());
|
||||
}
|
||||
|
||||
private void initializeCriterion(Criterion criterion) {
|
||||
criterion.getName();
|
||||
criterion.getName();
|
||||
if (criterion.getParent() != null) {
|
||||
criterion.getParent().getName();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,8 +9,8 @@ import java.util.ArrayList;
|
|||
import java.util.Date;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
import org.hibernate.validator.ClassValidator;
|
||||
import static org.navalplanner.web.I18nHelper._;
|
||||
import org.hibernate.validator.InvalidValue;
|
||||
|
|
@ -32,14 +32,13 @@ import org.springframework.context.annotation.Scope;
|
|||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.zkoss.zk.ui.WrongValueException;
|
||||
import org.zkoss.zul.Listbox;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Susana Montes Pedreira <smontes@wirelessgalicia.com>
|
||||
*/
|
||||
|
||||
@Service
|
||||
@Service()
|
||||
@Scope(BeanDefinition.SCOPE_PROTOTYPE)
|
||||
public class AssignedCriterionsModel implements IAssignedCriterionsModel {
|
||||
|
||||
|
|
|
|||
|
|
@ -4,38 +4,26 @@
|
|||
*/
|
||||
package org.navalplanner.web.resources.worker;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import static org.navalplanner.web.I18nHelper._;
|
||||
|
||||
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.CriterionWithItsType;
|
||||
import org.navalplanner.business.resources.entities.Worker;
|
||||
import org.navalplanner.web.common.Util;
|
||||
import org.zkoss.zk.ui.Component;
|
||||
import org.zkoss.zk.ui.WrongValueException;
|
||||
|
||||
import org.zkoss.zul.Constraint;
|
||||
import static org.navalplanner.web.I18nHelper._;
|
||||
import org.navalplanner.business.common.exceptions.ValidationException;
|
||||
import org.navalplanner.business.resources.entities.CriterionSatisfaction;
|
||||
import static org.navalplanner.web.common.InvalidInputsChecker.thereAreInvalidInputsOn;
|
||||
import static org.navalplanner.web.common.InvalidInputsChecker.isInvalid;
|
||||
import org.navalplanner.business.resources.entities.CriterionWithItsType;
|
||||
import org.navalplanner.business.resources.entities.Worker;
|
||||
import org.navalplanner.web.common.IMessagesForUser;
|
||||
import org.navalplanner.web.common.Level;
|
||||
import org.navalplanner.web.common.MessagesForUser;
|
||||
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.Datebox;
|
||||
import org.zkoss.zul.Constraint;
|
||||
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;
|
||||
|
||||
/**
|
||||
*
|
||||
|
|
@ -44,48 +32,30 @@ import org.zkoss.zul.Rows;
|
|||
public class CriterionsController extends GenericForwardComposer {
|
||||
|
||||
private IAssignedCriterionsModel assignedCriterionsModel;
|
||||
private Combobox comboboxfilter;
|
||||
private Combobox comboboxFilter;
|
||||
private Grid listingCriterions;
|
||||
private IMessagesForUser messages;
|
||||
private Component messagesContainer;
|
||||
|
||||
CriterionsController(IWorkerModel workerModel) {
|
||||
assignedCriterionsModel = workerModel.getAssignedCriterionsModel();
|
||||
protected CriterionsController() {
|
||||
}
|
||||
|
||||
@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");
|
||||
}
|
||||
|
||||
public IAssignedCriterionsModel getModel(){
|
||||
return this.assignedCriterionsModel;
|
||||
comboboxFilter = (Combobox) comp.getFellow("comboboxfilter");
|
||||
listingCriterions = (Grid) comp.getFellow("listingCriterions");
|
||||
}
|
||||
|
||||
public void prepareForEdit(Worker worker) {
|
||||
this.assignedCriterionsModel.prepareForEdit(worker);
|
||||
reload();
|
||||
}
|
||||
|
||||
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 Set<CriterionSatisfactionDTO> getCriterionSatisfactionDTOs() {
|
||||
Comboitem comboitem = comboboxFilter.getSelectedItem();
|
||||
if((comboitem != null) && (comboitem.getLabel().equals("in force"))) {
|
||||
return assignedCriterionsModel.getFilterCriterionSatisfactions();
|
||||
}
|
||||
return assignedCriterionsModel.getAllCriterionSatisfactions();
|
||||
}
|
||||
|
||||
public void addCriterionSatisfaction() {
|
||||
|
|
@ -99,18 +69,6 @@ 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){
|
||||
|
|
@ -150,14 +108,7 @@ public class CriterionsController extends GenericForwardComposer {
|
|||
}
|
||||
}
|
||||
|
||||
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){
|
||||
public void changeDate(Component comp){
|
||||
CriterionSatisfactionDTO criterionSatisfactionDTO =
|
||||
(CriterionSatisfactionDTO)((Row) comp.getParent()).getValue();
|
||||
validateCriterionWithItsType(criterionSatisfactionDTO,comp);
|
||||
|
|
@ -169,206 +120,39 @@ public class CriterionsController extends GenericForwardComposer {
|
|||
@Override
|
||||
public void validate(Component comp, Object value)
|
||||
throws WrongValueException {
|
||||
validateStartDate(comp,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"));
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
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 {
|
||||
validateEndDate(comp,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"));
|
||||
}
|
||||
validateCriterionWithItsType(criterionSatisfactionDTO,comp);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
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
|
||||
*
|
||||
* @param e
|
||||
*/
|
||||
public boolean validate() throws ValidationException{
|
||||
try{
|
||||
if(thereAreInvalidInputsOn(this.listingCriterions)){
|
||||
showInvalidInputs();
|
||||
return false;
|
||||
}
|
||||
assignedCriterionsModel.validate();
|
||||
reload();
|
||||
} catch (ValidationException e) {
|
||||
showInvalidValues(e);
|
||||
for (InvalidValue invalidValue : e.getInvalidValues()) {
|
||||
messages.showMessage(Level.ERROR, invalidValue.getPropertyName()+invalidValue.getMessage());
|
||||
return false;
|
||||
}
|
||||
} catch (IllegalStateException e) {
|
||||
messages.showMessage(Level.ERROR,e.getMessage());
|
||||
return false;
|
||||
}
|
||||
catch (IllegalArgumentException e) {
|
||||
messages.showMessage(Level.ERROR,e.getMessage());
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Shows invalid inputs for {@link CriterionSatisfactionDTO} entities
|
||||
*
|
||||
* @param
|
||||
*/
|
||||
private void showInvalidInputs(){
|
||||
if(listingCriterions != null){
|
||||
Rows rows = listingCriterions.getRows();
|
||||
List<Row> listRows = rows.getChildren();
|
||||
for(Row row : listRows){
|
||||
//Validate endDate Domain Restricctions.
|
||||
Datebox endDate = getEndDatebox(row);
|
||||
if(isInvalid(endDate)){
|
||||
validateEndDate(endDate, endDate.getValue());
|
||||
}
|
||||
//Validate startDate Domain Restricctions.
|
||||
Datebox startDate = getStartDatebox(row);
|
||||
if(isInvalid(startDate)){
|
||||
validateStartDate(startDate, startDate.getValue());
|
||||
}
|
||||
//Validate endDate Domain Restricctions.
|
||||
Bandbox bandCriterion = getBandType(row);
|
||||
if(isInvalid(bandCriterion)){
|
||||
CriterionSatisfactionDTO satisfactionDTO =
|
||||
(CriterionSatisfactionDTO)row.getValue();
|
||||
validateCriterionWithItsType(satisfactionDTO,bandCriterion);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Shows invalid values for {@link CriterionSatisfactionDTO} entities
|
||||
*
|
||||
* @param e
|
||||
*/
|
||||
private void showInvalidValues(ValidationException e) {
|
||||
for (InvalidValue invalidValue : e.getInvalidValues()) {
|
||||
Object value = invalidValue.getBean();
|
||||
if(value instanceof CriterionSatisfactionDTO){
|
||||
validateCriterionSatisfactionDTO(invalidValue,
|
||||
(CriterionSatisfactionDTO)value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Validates {@link CriterionSatisfactionDTO} data constraints
|
||||
*
|
||||
* @param invalidValue
|
||||
*/
|
||||
private void validateCriterionSatisfactionDTO(InvalidValue invalidValue,
|
||||
CriterionSatisfactionDTO satisfactionDTO) {
|
||||
if(listingCriterions != null){
|
||||
|
||||
// Find which listItem contains CriterionSatisfaction inside listBox
|
||||
Row row = findRowOfCriterionSatisfactionDTO(listingCriterions.getRows(),
|
||||
satisfactionDTO);
|
||||
|
||||
if (row != null) {
|
||||
String propertyName = invalidValue.getPropertyName();
|
||||
|
||||
if (CriterionSatisfactionDTO.START_DATE.equals(propertyName)) {
|
||||
// Locate TextboxResource
|
||||
Datebox startDate = getStartDatebox(row);
|
||||
// Value is incorrect, clear
|
||||
startDate.setValue(null);
|
||||
throw new WrongValueException(startDate,
|
||||
_("The start date cannot be null"));
|
||||
}
|
||||
if (CriterionSatisfactionDTO.CRITERION_WITH_ITS_TYPE.equals(propertyName)) {
|
||||
// Locate TextboxResource
|
||||
Bandbox bandType = getBandType(row);
|
||||
// Value is incorrect, clear
|
||||
bandType.setValue(null);
|
||||
throw new WrongValueException(bandType,
|
||||
_("The criterion and its type cannot be null"));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Locates which {@link row} is bound to {@link WorkReportLine} in
|
||||
* rows
|
||||
*
|
||||
* @param Rows
|
||||
* @param CriterionSatisfactionDTO
|
||||
* @return
|
||||
*/
|
||||
private Row findRowOfCriterionSatisfactionDTO(Rows rows,
|
||||
CriterionSatisfactionDTO satisfactionDTO) {
|
||||
List<Row> listRows = (List<Row>) rows.getChildren();
|
||||
for (Row row : listRows) {
|
||||
if (satisfactionDTO.equals(row.getValue())) {
|
||||
return row;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Locates {@link Datebox} criterion satisfaction in {@link row}
|
||||
*
|
||||
* @param row
|
||||
* @return
|
||||
*/
|
||||
private Datebox getStartDatebox(Row row) {
|
||||
return (Datebox) (row.getChildren().get(1));
|
||||
}
|
||||
|
||||
/**
|
||||
* Locates {@link Datebox} criterion satisfaction in {@link row}
|
||||
*
|
||||
* @param row
|
||||
* @return
|
||||
*/
|
||||
private Datebox getEndDatebox(Row row) {
|
||||
return (Datebox) (row.getChildren().get(2));
|
||||
}
|
||||
|
||||
/**
|
||||
* Locates {@link Bandbox} criterion satisfaction in {@link row}
|
||||
*
|
||||
* @param row
|
||||
* @return
|
||||
*/
|
||||
private Bandbox getBandType(Row row) {
|
||||
return (Bandbox)((Hbox) row.getChildren().get(0))
|
||||
.getChildren().get(0);
|
||||
public void save() throws ValidationException{
|
||||
assignedCriterionsModel.save();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,164 @@
|
|||
/*
|
||||
* To change this template, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package org.navalplanner.web.resources.worker;
|
||||
|
||||
import static org.navalplanner.web.I18nHelper._;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import org.navalplanner.business.common.exceptions.ValidationException;
|
||||
import org.navalplanner.business.resources.entities.CriterionWithItsType;
|
||||
import org.navalplanner.business.resources.entities.Machine;
|
||||
import org.navalplanner.web.common.Util;
|
||||
import org.navalplanner.web.resources.machine.IAssignedMachineCriterionsModel;
|
||||
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.Combobox;
|
||||
import org.zkoss.zul.Comboitem;
|
||||
import org.zkoss.zul.Constraint;
|
||||
import org.zkoss.zul.Grid;
|
||||
import org.zkoss.zul.Listitem;
|
||||
import org.zkoss.zul.Row;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Diego Pino García <dpino@igalia.com>
|
||||
*/
|
||||
public class CriterionsMachineController extends GenericForwardComposer {
|
||||
|
||||
private IAssignedMachineCriterionsModel assignedMachineCriterionsModel;
|
||||
|
||||
private Combobox comboboxFilter;
|
||||
|
||||
private Grid listingCriterions;
|
||||
|
||||
public CriterionsMachineController() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void doAfterCompose(Component comp) throws Exception {
|
||||
super.doAfterCompose(comp);
|
||||
comp.setVariable("assignedCriterionsController", this, true);
|
||||
}
|
||||
|
||||
public void prepareForEdit(Machine machine) {
|
||||
this.assignedMachineCriterionsModel.prepareForEdit(machine);
|
||||
}
|
||||
|
||||
public Set<CriterionSatisfactionDTO> getCriterionSatisfactionDTOs() {
|
||||
Comboitem comboitem = comboboxFilter.getSelectedItem();
|
||||
if((comboitem != null) && (comboitem.getLabel().equals("in force"))) {
|
||||
return assignedMachineCriterionsModel
|
||||
.getFilterCriterionSatisfactions();
|
||||
}
|
||||
return assignedMachineCriterionsModel.getAllCriterionSatisfactions();
|
||||
}
|
||||
|
||||
public void addCriterionSatisfaction() {
|
||||
assignedMachineCriterionsModel.addCriterionSatisfaction();
|
||||
reload();
|
||||
}
|
||||
|
||||
public List<CriterionWithItsType> getCriterionWithItsTypes(){
|
||||
return assignedMachineCriterionsModel.getCriterionWithItsType();
|
||||
}
|
||||
|
||||
public void reload() {
|
||||
Util.reloadBindings(listingCriterions);
|
||||
}
|
||||
|
||||
public void remove(CriterionSatisfactionDTO criterionSatisfactionDTO){
|
||||
assignedMachineCriterionsModel.remove(criterionSatisfactionDTO);
|
||||
reload();
|
||||
}
|
||||
|
||||
public void selectCriterionAndType(Listitem item,Bandbox bandbox,
|
||||
CriterionSatisfactionDTO criterionSatisfactionDTO){
|
||||
if(item != null){
|
||||
CriterionWithItsType criterionAndType = (CriterionWithItsType)item.getValue();
|
||||
bandbox.setValue(criterionAndType.getNameAndType());
|
||||
setCriterionWithItsType(criterionAndType,criterionSatisfactionDTO,bandbox);
|
||||
}else{
|
||||
bandbox.setValue("");
|
||||
}
|
||||
bandbox.close();
|
||||
}
|
||||
|
||||
public void setCriterionWithItsType(CriterionWithItsType criterionAndType,
|
||||
CriterionSatisfactionDTO satisfaction,Bandbox bandbox) throws WrongValueException{
|
||||
this.assignedMachineCriterionsModel.setCriterionWithItsType(
|
||||
satisfaction, criterionAndType);
|
||||
validateCriterionWithItsType(satisfaction,bandbox);
|
||||
}
|
||||
|
||||
private void validateCriterionWithItsType(CriterionSatisfactionDTO satisfaction,
|
||||
Component comp) throws WrongValueException{
|
||||
if(satisfaction.getCriterionWithItsType() == null) return;
|
||||
if(satisfaction.getStartDate() == null) return;
|
||||
if (assignedMachineCriterionsModel
|
||||
.checkSameCriterionAndSameInterval(satisfaction)) {
|
||||
throw new WrongValueException(comp,
|
||||
_("Criterion is not valid, the criterion overlap other criterionSatisfaction whith same criterion"));
|
||||
}
|
||||
if (assignedMachineCriterionsModel
|
||||
.checkNotAllowSimultaneousCriterionsPerResource(satisfaction)) {
|
||||
throw new WrongValueException(comp,
|
||||
_("CriterionType is not valid, the criterionType overlap other criterionSatisfaction whith same criterionType"));
|
||||
}
|
||||
}
|
||||
|
||||
public void changeDate(Component comp){
|
||||
CriterionSatisfactionDTO criterionSatisfactionDTO =
|
||||
(CriterionSatisfactionDTO)((Row) comp.getParent()).getValue();
|
||||
validateCriterionWithItsType(criterionSatisfactionDTO,comp);
|
||||
reload();
|
||||
}
|
||||
|
||||
public Constraint validateStartDate(){
|
||||
return new Constraint() {
|
||||
@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"));
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
public void save() throws ValidationException{
|
||||
assignedMachineCriterionsModel.save();
|
||||
}
|
||||
}
|
||||
|
|
@ -18,6 +18,7 @@
|
|||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
-->
|
||||
|
||||
<?component name="criterions" inline="true" macroURI="_machineCriterions.zul"?>
|
||||
<window id="editWindow" >
|
||||
<tabbox>
|
||||
<tabs>
|
||||
|
|
@ -54,6 +55,8 @@
|
|||
</tabpanel>
|
||||
<tabpanel>
|
||||
<!-- Assigned criterions -->
|
||||
<!-- <include src="_machineCriterions.zul" model="controller.machine"/> -->
|
||||
<criterions model="@{controller.machine}" />
|
||||
</tabpanel>
|
||||
<tabpanel visible="false">
|
||||
<!-- Calendar -->
|
||||
|
|
|
|||
|
|
@ -0,0 +1,72 @@
|
|||
<vbox id="criterionsContainer" style="padding: 10px" >
|
||||
<panel title="${i18n:_('Assigned Criterions')}" border="normal">
|
||||
<panelchildren>
|
||||
<hbox align="center">
|
||||
<separator bar="false" spacing="40px" orient="horizontal"/>
|
||||
<separator bar="false" spacing="20px" orient="vertical"/>
|
||||
<button onClick="assignedCriterionsController.addCriterionSatisfaction();"
|
||||
label="${i18n:_('Add criterion')}" />
|
||||
<label class="subtitulo" value="${i18n:_('Filters :')}" />
|
||||
<combobox id="comboboxFilter"
|
||||
onSelect="assignedCriterionsController.reload();">
|
||||
<comboitem label="all" />
|
||||
<comboitem label="in force" />
|
||||
</combobox>
|
||||
<separator bar="false" spacing="20px" orient="vertical"/>
|
||||
</hbox>
|
||||
<grid id="listingCriterions"
|
||||
model="@{assignedCriterionsController.criterionSatisfactionDTOs}"
|
||||
mold="paging" pageSize="5">
|
||||
<columns>
|
||||
<column label="${i18n:_('Criterion name')}"/>
|
||||
<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"/>
|
||||
<column label="${i18n:_('Operations')}" width="70px" align="center"/>
|
||||
</columns>
|
||||
<rows>
|
||||
<row self="@{each='criterionSatisfactionDTO'}" value="@{criterionSatisfactionDTO}">
|
||||
<hbox>
|
||||
<bandbox width="500px"
|
||||
visible="@{criterionSatisfactionDTO.isNewObject}"
|
||||
value = "@{criterionSatisfactionDTO.criterionAndType}">
|
||||
<bandpopup>
|
||||
<listbox width="500px" height="150px" fixedLayout="true"
|
||||
model="@{assignedCriterionsController.criterionWithItsTypes}"
|
||||
onSelect="assignedCriterionsController.selectCriterionAndType(self.selectedItem,
|
||||
self.parent.parent,self.parent.parent.parent.parent.value);">
|
||||
<listhead>
|
||||
<listheader label="Type" />
|
||||
<listheader label="Criterion" />
|
||||
</listhead>
|
||||
<listitem self="@{each='criterionWithItsType'}" value="@{criterionWithItsType}">
|
||||
<listcell label="@{criterionWithItsType.type.name}" />
|
||||
<listcell label="@{criterionWithItsType.nameHierarchy}" />
|
||||
</listitem>
|
||||
</listbox>
|
||||
</bandpopup>
|
||||
</bandbox>
|
||||
<label visible="@{criterionSatisfactionDTO.isOldObject}"
|
||||
value="@{criterionSatisfactionDTO.nameAndType}"/>
|
||||
</hbox>
|
||||
<datebox id="startDate" value="@{criterionSatisfactionDTO.startDate}"
|
||||
constraint="@{assignedCriterionsController.validateStartDate}"
|
||||
onChange="assignedCriterionsController.changeDate(self);" width="150px"/>
|
||||
|
||||
<datebox id="endDate" value="@{criterionSatisfactionDTO.endDate}"
|
||||
constraint="@{assignedCriterionsController.validateEndDate}"
|
||||
onChange="assignedCriterionsController.changeDate(self);" width="150px"/>
|
||||
|
||||
<label value="@{criterionSatisfactionDTO.state}"/>
|
||||
|
||||
<button sclass="icono" image="/common/img/ico_borrar1.png"
|
||||
hoverImage="/common/img/ico_borrar.png"
|
||||
tooltiptext="${i18n:_('Delete')}"
|
||||
onClick="assignedCriterionsController.remove(self.parent.value);">
|
||||
</button>
|
||||
</row>
|
||||
</rows>
|
||||
</grid>
|
||||
</panelchildren>
|
||||
</panel>
|
||||
</vbox>
|
||||
Loading…
Add table
Reference in a new issue