diff --git a/src/main/java/info/bukova/isspst/services/requirement/RequirementTypeService.java b/src/main/java/info/bukova/isspst/services/requirement/RequirementTypeService.java index cfbf4104..1db54348 100644 --- a/src/main/java/info/bukova/isspst/services/requirement/RequirementTypeService.java +++ b/src/main/java/info/bukova/isspst/services/requirement/RequirementTypeService.java @@ -1,10 +1,14 @@ package info.bukova.isspst.services.requirement; import info.bukova.isspst.data.RequirementType; +import info.bukova.isspst.data.Workgroup; import info.bukova.isspst.services.Service; +import java.util.List; + public interface RequirementTypeService extends Service { public RequirementType getTypeById(String id); + public List filterCentres(RequirementType reqType, List source); } diff --git a/src/main/java/info/bukova/isspst/services/requirement/RequirementTypeServiceImpl.java b/src/main/java/info/bukova/isspst/services/requirement/RequirementTypeServiceImpl.java index c48d6501..62de731d 100644 --- a/src/main/java/info/bukova/isspst/services/requirement/RequirementTypeServiceImpl.java +++ b/src/main/java/info/bukova/isspst/services/requirement/RequirementTypeServiceImpl.java @@ -1,8 +1,12 @@ package info.bukova.isspst.services.requirement; +import java.util.ArrayList; +import java.util.List; + import org.springframework.transaction.annotation.Transactional; import info.bukova.isspst.data.RequirementType; +import info.bukova.isspst.data.Workgroup; import info.bukova.isspst.services.AbstractOwnedService; public class RequirementTypeServiceImpl extends AbstractOwnedService implements RequirementTypeService { @@ -13,4 +17,23 @@ public class RequirementTypeServiceImpl extends AbstractOwnedService filterCentres(RequirementType reqType, + List source) { + + if (!reqType.getLimitCentres()) { + return source; + } + + List filtered = new ArrayList(); + + for (Workgroup wg : source) { + if (reqType.getOfferedCentres().contains(wg)) { + filtered.add(wg); + } + } + + return filtered; + } + } diff --git a/src/main/java/info/bukova/isspst/ui/main/orders/requirements/RequirementForm.java b/src/main/java/info/bukova/isspst/ui/main/orders/requirements/RequirementForm.java index 7b353114..794d0d7b 100644 --- a/src/main/java/info/bukova/isspst/ui/main/orders/requirements/RequirementForm.java +++ b/src/main/java/info/bukova/isspst/ui/main/orders/requirements/RequirementForm.java @@ -5,6 +5,7 @@ import info.bukova.isspst.data.Requirement; import info.bukova.isspst.data.RequirementItem; import info.bukova.isspst.data.RequirementSubject; import info.bukova.isspst.data.Workgroup; +import info.bukova.isspst.services.requirement.RequirementTypeService; import info.bukova.isspst.services.users.UserService; import info.bukova.isspst.services.workgroups.WorkgroupService; import info.bukova.isspst.ui.BigDecimalConverter; @@ -36,6 +37,9 @@ public class RequirementForm extends FormViewModel @WireVariable private WorkgroupService workgroupService; + + @WireVariable + private RequirementTypeService reqTypeService; private RequirementItem selectedItem; @@ -46,10 +50,12 @@ public class RequirementForm extends FormViewModel private RequirementFormValidator requirementFormValidator; private List syncItems; + + private List centres; public List getCentres() { - return workgroupService.getUserCentres(userService.getCurrent()); + return centres; } public RequirementItem getSelectedItem() @@ -91,7 +97,7 @@ public class RequirementForm extends FormViewModel { this.requirementFormValidator = requirementFormValidator; } - + @Init(superclass = true) public void init() { @@ -99,6 +105,7 @@ public class RequirementForm extends FormViewModel this.setBigDecimalConverter(new BigDecimalConverter()); this.setRequirementFormValidator(new RequirementFormValidator()); this.setSyncItems(this.getDataBean().getItems()); + this.centres = reqTypeService.filterCentres(getDataBean().getType(), workgroupService.getUserCentres(userService.getCurrent())); } public List getSyncItems() diff --git a/src/main/java/info/bukova/isspst/ui/requirement/TripRequirementForm.java b/src/main/java/info/bukova/isspst/ui/requirement/TripRequirementForm.java index 49eb8deb..872a9cc1 100644 --- a/src/main/java/info/bukova/isspst/ui/requirement/TripRequirementForm.java +++ b/src/main/java/info/bukova/isspst/ui/requirement/TripRequirementForm.java @@ -12,6 +12,7 @@ import info.bukova.isspst.data.SettingsData; import info.bukova.isspst.data.TripRequirement; import info.bukova.isspst.data.User; import info.bukova.isspst.data.Workgroup; +import info.bukova.isspst.services.requirement.RequirementTypeService; import info.bukova.isspst.services.settings.GlobalSettingsService; import info.bukova.isspst.services.users.UserService; import info.bukova.isspst.services.workgroups.WorkgroupService; @@ -26,6 +27,8 @@ public class TripRequirementForm extends FormViewModel { private WorkgroupService workgroupService; @WireVariable private GlobalSettingsService settingsService; + @WireVariable + private RequirementTypeService reqTypeService; private List centres; private List users; private List passengers; @@ -34,7 +37,7 @@ public class TripRequirementForm extends FormViewModel { @Init(superclass = true) public void init() { - centres = workgroupService.getUserCentres(userService.getCurrent()); + centres = reqTypeService.filterCentres(getDataBean().getType(), workgroupService.getUserCentres(userService.getCurrent())); users = userService.getAll(); passengers = getDataBean().getPassengers(); validator = new TripRequirementFormValidator();