Source:
public void onAdd() { AdElementListModel model = (AdElementListModel) getWindow(); if (model.getProgress() != null) { return; } if (model.getSelectedItems() == null && model.getSearchType() != AdSearchType.EVERYONE) { model.setIsValid(false); model.setMessage(ConstantsManager.getInstance().getConstants().selectUserOrGroup()); return; } ArrayList<DbUser> items = new ArrayList<>(); if (model.getSearchType() == AdSearchType.EVERYONE) { DbUser tempVar = new DbUser(); tempVar.setId(ApplicationGuids.everyone.asGuid()); items.add(tempVar); } else { for (Object item : model.getItems()) { EntityModel entityModel = (EntityModel) item; if (entityModel.getIsSelected()) { items.add((DbUser) entityModel.getEntity()); } } } if(items.isEmpty()){ model.setIsValid(false); model.setMessage(ConstantsManager.getInstance().getConstants().selectUserOrGroup()); return; } model.startProgress(); ArrayList<ActionParametersBase> list = new ArrayList<>(); PermissionsOperationsParameters permissionParams; for (DbUser user : items) { Permission perm = new Permission( user.getId(), ApplicationGuids.quotaConsumer.asGuid(), getEntity().getId(), VdcObjectType.Quota); permissionParams = new PermissionsOperationsParameters(); if (user.isGroup()) { DbGroup group = new DbGroup(); group.setId(user.getId()); group.setExternalId(user.getExternalId()); group.setName(user.getFirstName()); group.setDomain(user.getDomain()); permissionParams.setGroup(group); } else { permissionParams.setUser(user); } permissionParams.setPermission(perm); list.add(permissionParams); } Frontend.getInstance() .runMultipleAction(ActionType.AddPermission, list, result -> { model.stopProgress(); cancel(); }); cancel(); }

Target:
public void onAdd() { AdElementListModel model = (AdElementListModel) getWindow(); if (model.getProgress() != null) { return; } ArrayList<DbUser> items = new ArrayList<>(); if (model.getSearchType() == AdSearchType.EVERYONE) { DbUser tempVar = new DbUser(); tempVar.setId(ApplicationGuids.everyone.asGuid()); items.add(tempVar); } else if (model.getItems() != null) { for (Object item : model.getItems()) { EntityModel entityModel = (EntityModel) item; if (entityModel.getIsSelected()) { items.add((DbUser) entityModel.getEntity()); } } } if(items.isEmpty()){ model.setIsValid(false); model.setMessage(ConstantsManager.getInstance().getConstants().selectUserOrGroup()); return; } model.startProgress(); ArrayList<ActionParametersBase> list = new ArrayList<>(); PermissionsOperationsParameters permissionParams; for (DbUser user : items) { Permission perm = new Permission( user.getId(), ApplicationGuids.quotaConsumer.asGuid(), getEntity().getId(), VdcObjectType.Quota); permissionParams = new PermissionsOperationsParameters(); if (user.isGroup()) { DbGroup group = new DbGroup(); group.setId(user.getId()); group.setExternalId(user.getExternalId()); group.setName(user.getFirstName()); group.setDomain(user.getDomain()); permissionParams.setGroup(group); } else { permissionParams.setUser(user); } permissionParams.setPermission(perm); list.add(permissionParams); } Frontend.getInstance() .runMultipleAction(ActionType.AddPermission, list, result -> { model.stopProgress(); cancel(); }); cancel(); }