private void populateRulesValueCondition(RuleLogicalCondition condition, DynamicGridRow parentRow, int j) { RuleValueCondition ruleValueCondition = (RuleValueCondition) condition.getConditions().get(j); // Entry, Comparator, ComparedValue RuleValueConditionEntry entry = ruleValueCondition.getEntry(); RuleValueComparator comparator = ruleValueCondition.getComparator(); String comparatedValue = ruleValueCondition.getComparedValue(); DynamicGridRow row = addValueCondition(parentRow, false); int count = row.getIdentifier() != null ? (row.getIdentifier() instanceof RuleConditionRowVo ? (((RuleConditionRowVo) row.getIdentifier()).getNumberOfColumns()) : 0) : 0; count++; try { addRuleValueConditionCell(row, entry.getChild() != null ? entry.getChild() : entry, count, comparator, comparatedValue); } catch (ParseException e) { e.printStackTrace(); } }
private boolean checkRowForAnyCollection(DynamicGridCell cell) { // Was selected a empty value so clear everything RuleConditionRowVo vo = (RuleConditionRowVo) cell.getRow().getIdentifier(); int totalColls = vo.getNumberOfColumns(); int collNumber = (Integer) cell.getColumn().getIdentifier(); boolean found = false; do { if (collNumber < 2) break; if (getColByIndex(totalColls) != null && cell.getRow().getCells().get(getColByIndex(totalColls)) != null) { if (cell.getRow().getCells().get(getColByIndex(totalColls)).getIdentifier() != null) { form.getLocalContext().setAlreadyAddedCollection(true); found = true; break; } } collNumber--; } while (found == false && collNumber < 2); return found; }
private void addEntityField() { DynamicGridRow entityFieldInstanceRow = form.lyrRules().tabActions().dyngrdActions().getSelectedRow().getRows().newRow(); entityFieldInstanceRow.setSelectable(true); RuleConditionRowVo vo = (RuleConditionRowVo) entityFieldInstanceRow.getIdentifier(); int count = 1; if (vo != null) count = vo.getNumberOfColumns(); setRowIdentifier(entityFieldInstanceRow, count, null); DynamicGridColumn valueColl = getColByIndexForActionGrid(count); if (valueColl == null) { valueColl = createColumnForActionGrid("", count); } setRowIdentifier(entityFieldInstanceRow, count, null); DynamicGridCell valueCell = entityFieldInstanceRow.getCells().newCell(valueColl, DynamicCellType.ENUMERATION); List<RulesEngineEntity> entities = new Entities().getAllPublicEntities(); for (int i = 0; i < entities.size(); i++) { valueCell.getItems().newItem().setValue(entities.get(i).getName()); valueCell.getItems().get(i).setIdentifier(entities.get(i)); } valueCell.setValue(form.lyrRules().tabConditions().cmbRootEntity().getValue().getName()); valueCell.setReadOnly(true); onDyngrdActionsCellValueChanged(valueCell); valueCell.setAutoPostBack(true); valueCell.setWidth(0); }
private ArrayList<String> checkRow(DynamicGridRow row, ArrayList<String> errors) { if (row.getIdentifier() != null && row.getIdentifier() instanceof RuleConditionRowVo) { RuleConditionRowVo vo = (RuleConditionRowVo) row.getIdentifier(); int collNumbers = vo.getNumberOfColumns(); if (vo.getType().equals(RuleConditionType.FIRST_LOGICAL) || vo.getType().equals(RuleConditionType.LOGICAL)) { if (row.getRows() == null || (row.getRows() != null && row.getRows().size() == 0)) { errors.add("Rule contains Logical Condition(s) without Value Condition(s)!"); } } for (int i = 1; i <= collNumbers; i++) { if (getColByIndex(i) != null) { DynamicGridCell cell = row.getCells().get(getColByIndex(i)); if (cell != null && cell.getValue() == null) { errors.add("Rule not valid! Your rule contain empty cell(s). Please check again."); return errors; } } } if (row.getRows() != null) { for (int j = 0; j < row.getRows().size(); j++) { checkRow(row.getRows().get(j), errors); } } } return errors; }
private void populateRulesNotificationEntry(RuleValueConditionEntry entry, DynamicGridRow parentRow) { DynamicGridRow row = parentRow.getRows().newRow(); DynamicGridColumn valueColl = getColByIndexForActionGrid(1); if (valueColl == null) { valueColl = createColumnForActionGrid("", 1); } setRowIdentifier(row, 1, RuleConditionType.VALUE); DynamicGridCell valueCell = row.getCells().newCell(valueColl, DynamicCellType.ENUMERATION); List<RulesEngineEntity> entities = new Entities().getAllPublicEntities(); for (int i = 0; i < entities.size(); i++) { valueCell.getItems().newItem().setValue(entities.get(i).getName()); valueCell.getItems().get(i).setIdentifier(entities.get(i)); } valueCell.setValue(form.lyrRules().tabConditions().cmbRootEntity().getValue().getName()); valueCell.setReadOnly(true); valueCell.setAutoPostBack(true); valueCell.setWidth(0); int count = row.getIdentifier() != null ? (row.getIdentifier() instanceof RuleConditionRowVo ? (((RuleConditionRowVo) row.getIdentifier()).getNumberOfColumns()) : 0) : 0; count++; try { addRuleNotificationCell(row, entry.getChild() != null ? entry.getChild() : entry, count); } catch (ParseException e) { e.printStackTrace(); } }
private void updateContextMenu() { DynamicGridRow selectedRow = form.lyrRules().tabConditions().dyngrdConditions().getSelectedRow(); DynamicGridRow selectedActionRow = form.lyrRules().tabActions().dyngrdActions().getSelectedRow(); boolean suportUserNotification = form.lyrRules().tabConditions().cmbRootEntity().getValue() != null ? (form.lyrRules().tabConditions().cmbRootEntity().getValue().supportsNotifications()) : false; form.getLocalContext().setUsersEntityAdded(false); if (selectedActionRow != null) { for (int i = 0; i < selectedActionRow.getRows().size(); i++) { if (selectedActionRow.getRows().get(i).getIdentifier() != null && selectedActionRow.getRows().get(i).getIdentifier().equals(NOTIFICATION_USER_ENTITY_INSTANCE)) { form.getLocalContext().setUsersEntityAdded(true); break; } } } boolean canMoveUp = selectedActionRow != null ? (selectedActionRow.canMoveUp() ? selectedActionRow.canMoveUp() : false) : false; boolean canMoveDown = selectedActionRow != null ? (selectedActionRow.canMoveDown() ? selectedActionRow.canMoveDown() : false) : false; boolean isEditMode = form.getMode().equals(FormMode.EDIT) ? true : false; boolean isRowSelectedOnGridCondition = selectedRow != null ? true : false; boolean isRowSelectedOnGridAction = form.lyrRules().tabActions().dyngrdActions().getSelectedRow() != null ? true : false; boolean isNotificationUser = isRowSelectedOnGridAction && (form.lyrRules().tabActions().dyngrdActions().getSelectedRow().getIdentifier() != null ? (form.lyrRules().tabActions().dyngrdActions().getSelectedRow().getIdentifier().equals(NOTIFICATION_USER) ? true : false) : false); boolean isNotificationUserInstance = isRowSelectedOnGridAction && (form.lyrRules().tabActions().dyngrdActions().getSelectedRow().getIdentifier() != null ? (form.lyrRules().tabActions().dyngrdActions().getSelectedRow().getIdentifier() instanceof AppUserShortVo ? true : false) : false); boolean isNotificationUserEntityInstance = isRowSelectedOnGridAction && (form.lyrRules().tabActions().dyngrdActions().getSelectedRow().getIdentifier() != null ? (form.lyrRules().tabActions().dyngrdActions().getSelectedRow().getIdentifier().equals(NOTIFICATION_USER_ENTITY_INSTANCE) ? true : false) : false); boolean isNotificationMessage = isRowSelectedOnGridAction && (form.lyrRules().tabActions().dyngrdActions().getSelectedRow().getIdentifier() != null ? (form.lyrRules().tabActions().dyngrdActions().getSelectedRow().getIdentifier().equals(NOTIFICATION_MESSAGE) ? true : false) : false); boolean isNotificationMessageInstance = isRowSelectedOnGridAction && (form.lyrRules().tabActions().dyngrdActions().getSelectedRow().getIdentifier() != null ? (form.lyrRules().tabActions().dyngrdActions().getSelectedRow().getIdentifier().equals(NOTIFICATION_MESSAGE_INSTANCE) ? true : false) : false); boolean isNotificationLineSeparatorInstance = isRowSelectedOnGridAction && (form.lyrRules().tabActions().dyngrdActions().getSelectedRow().getIdentifier() != null ? (form.lyrRules().tabActions().dyngrdActions().getSelectedRow().getIdentifier().equals(NOTIFICATION_LINE_SEPARATOR_INSTANCE) ? true : false) : false); boolean isNotificationEntityFieldInstance = isRowSelectedOnGridAction && (form.lyrRules().tabActions().dyngrdActions().getSelectedRow().getIdentifier() != null ? (form.lyrRules().tabActions().dyngrdActions().getSelectedRow().getIdentifier() instanceof RuleConditionRowVo ? true : false) : false); boolean isNotificationOption = isRowSelectedOnGridAction && (form.lyrRules().tabActions().dyngrdActions().getSelectedRow().getIdentifier() != null ? (form.lyrRules().tabActions().dyngrdActions().getSelectedRow().getIdentifier().equals(NOTIFICATION_OPTION) ? true : false) : false); boolean isLogicCondition = selectedRow != null ? (selectedRow.getIdentifier() != null ? (((RuleConditionRowVo) selectedRow.getIdentifier()).getType().equals(RuleConditionType.LOGICAL) ? true : false) : false) : false; boolean isValueCondition = selectedRow != null ? (selectedRow.getIdentifier() != null ? (((RuleConditionRowVo) selectedRow.getIdentifier()).getType().equals(RuleConditionType.VALUE) ? true : false) : false) : false; boolean isFirstRow = selectedRow != null ? (selectedRow.getIdentifier() != null ? (((RuleConditionRowVo) selectedRow.getIdentifier()).getType().equals(RuleConditionType.FIRST_LOGICAL) ? true : false) : false) : false; boolean isGridConditionEmpty = form.lyrRules().tabConditions().dyngrdConditions().getRows().size() > 0 ? true : false; boolean isGridActionEmpty = form.lyrRules().tabActions().dyngrdActions().getRows().size() > 0 ? true : false; form.getContextMenus().Admin.getRulesEditorAddLogicalConditionItem().setVisible(isEditMode && isRowSelectedOnGridCondition && !isValueCondition); form.getContextMenus().Admin.getRulesEditorAddValueConditionItem().setVisible(isEditMode && isRowSelectedOnGridCondition && !isValueCondition && (isLogicCondition || isFirstRow) && form.lyrRules().tabConditions().dyngrdConditions().getSelectedRow() != null); form.getContextMenus().Admin.getRulesEditorRemoveAllItem().setVisible(isEditMode && isGridConditionEmpty); form.getContextMenus().Admin.getRulesEditorRemoveItem().setVisible(isEditMode && isRowSelectedOnGridCondition && !isFirstRow); form.getContextMenus().Rules.getRulesEditorActionsAddActionItem().setVisible(isEditMode); form.getContextMenus().Rules.getRulesEditorActionsRemoveActionItem().setVisible(isEditMode && isRowSelectedOnGridAction && !isNotificationOption); form.getContextMenus().Rules.getRulesEditorActionsRemoveAllItem().setVisible(isEditMode && isGridActionEmpty); if (isNotificationUser || isNotificationUserInstance || isNotificationUserEntityInstance || isNotificationMessage || isNotificationMessageInstance || isNotificationLineSeparatorInstance || isNotificationEntityFieldInstance) { form.getContextMenus().Rules.hideAllRulesEditorActionsMenuItems(); } form.getContextMenus().Rules.getRulesEditorActionsAddUserItem().setVisible(isEditMode && isNotificationUser); form.getContextMenus().Rules.getRulesEditorActionsAddEntityUsersItem().setVisible(isEditMode && isNotificationUser && suportUserNotification && suportUserNotification && !form.getLocalContext().getUsersEntityAdded()); form.getContextMenus().Rules.getRulesEditorActionsRemoveEntityUsersItem().setVisible(isEditMode && isNotificationUserEntityInstance); form.getContextMenus().Rules.getRulesEditorActionsRemoveUserItem().setVisible(isEditMode && isNotificationUserInstance); form.getContextMenus().Rules.getRulesEditorActionsAddMessageItem().setVisible(isEditMode && isNotificationMessage); form.getContextMenus().Rules.getRulesEditorActionsRemoveMessageItem().setVisible(isEditMode && isNotificationMessageInstance); form.getContextMenus().Rules.getRulesEditorActionsAddLineSeparatorItem().setVisible(isEditMode && isNotificationMessage); form.getContextMenus().Rules.getRulesEditorActionsRemoveLineSeparatorItem().setVisible(isEditMode && isNotificationLineSeparatorInstance); form.getContextMenus().Rules.getRulesEditorActionsAddEntityFieldItem().setVisible(isEditMode && isNotificationMessage); form.getContextMenus().Rules.getRulesEditorActionsRemoveEntityFieldItem().setVisible(isEditMode && isNotificationEntityFieldInstance); form.getContextMenus().Rules.getRulesEditorActionsMoveUPItem().setVisible(isEditMode && canMoveUp && (isNotificationMessageInstance || isNotificationLineSeparatorInstance || isNotificationEntityFieldInstance)); form.getContextMenus().Rules.getRulesEditorActionsMoveDownItem().setVisible(isEditMode && canMoveDown && (isNotificationMessageInstance || isNotificationLineSeparatorInstance || isNotificationEntityFieldInstance)); }
private void createCellsByType(RulesEngineField identifier, DynamicGridCell cell) { int nextCollAvaible = clearRightCells((Integer) cell.getColumn().getIdentifier(), cell.getRow()); RulesEngineFieldType type = identifier.getType(); DynamicGridRow row = cell.getRow(); RuleConditionRowVo vo = (RuleConditionRowVo) row.getIdentifier(); int count = vo.getNumberOfColumns(); DynamicGridColumn coll = null; if (nextCollAvaible != 0) { coll = getColByIndex(nextCollAvaible); if (coll == null) { coll = createColumn("", nextCollAvaible); } } else { count++; coll = getColByIndex(count); if (coll == null) { coll = createColumn("", count); } } setRowIdentifier(row, count, RuleConditionType.VALUE); count++; DynamicGridCell conditionValueCell = cell.getRow().getCells().newCell(coll, DynamicCellType.ENUMERATION); for (int j = 0; j < type.getComparators().length; j++) { if (checkRowForAnyCollection(cell)) { if (type.getComparators()[j].equals(RuleValueComparator.NOTEQUALS)) continue; } DynamicGridCellItem item = conditionValueCell.getItems().newItem(type.getComparators()[j]); item.setIdentifier(type.getComparators()[j]); conditionValueCell.setValue(type.getComparators()[j]); conditionValueCell.setIdentifier(type.getComparators()[j]); } setRowIdentifier(row, count, RuleConditionType.VALUE); conditionValueCell.setAutoPostBack(true); count++; DynamicGridColumn colll = getColByIndex(count); DynamicGridCell cellValue = null; if (colll == null) { colll = createColumn("", count); } setRowIdentifier(row, count, RuleConditionType.VALUE); createCellByType(identifier, cell, type, colll, cellValue); }
private DynamicGridRow addValueCondition(DynamicGridRow parentRow, boolean isNewValueCondition) { DynamicGridRow row = parentRow.getRows().newRow(); row.setSelectable(true); RuleConditionRowVo vo = (RuleConditionRowVo) row.getIdentifier(); int count = 1; if (vo != null) count = vo.getNumberOfColumns(); setRowIdentifier(row, count, RuleConditionType.VALUE); DynamicGridCell ifCell = row.getCells().newCell(getColByIndex(count), DynamicCellType.HTMLVIEW); ifCell.setValue(" <b>IF</b> "); ifCell.setWidth(30); count++; DynamicGridColumn valueColl = getColByIndex(count); if (valueColl == null) { valueColl = createColumn("", count); } setRowIdentifier(row, count, RuleConditionType.VALUE); DynamicGridCell valueCell = row.getCells().newCell(valueColl, DynamicCellType.ENUMERATION); List<RulesEngineEntity> entities = new Entities().getAllPublicEntities(); for (int i = 0; i < entities.size(); i++) { valueCell.getItems().newItem().setValue(entities.get(i).getName()); valueCell.getItems().get(i).setIdentifier(entities.get(i)); } valueCell.setValue(form.lyrRules().tabConditions().cmbRootEntity().getValue().getName()); valueCell.setReadOnly(true); if (isNewValueCondition) onDyngrdConditionsCellValueChanged(valueCell); valueCell.setAutoPostBack(true); valueCell.setWidth(0); return row; }
private ArrayList<String> validateSendNotificationMessageRow(DynamicGridRow row, ArrayList<String> errors) { if (row == null) throw new CodingRuntimeException("Logical error - a non null row was expected"); if (errors == null) { errors = new ArrayList<String>(); } DynamicGridRow messageRow = row.getRows().get(1); if (messageRow == null || !(new Integer(NOTIFICATION_MESSAGE).equals(messageRow.getIdentifier()))) throw new CodingRuntimeException("Logical error - message row expected"); for (int i = 0; i < messageRow.getRows().size(); i++) { DynamicGridRow childRow = messageRow.getRows().get(i); if (childRow == null || childRow.getIdentifier() == null) throw new CodingRuntimeException("Logical error - message row expected to have at least one child row with one cell"); if (childRow.getIdentifier().equals(NOTIFICATION_MESSAGE_INSTANCE)) { DynamicGridCell messageCell = childRow.getCells().get(getColByIndexForActionGrid(0)); if (messageCell == null) throw new CodingRuntimeException("Logical error - message cell missing"); if (messageCell.getValue() == null) errors.add("Message for Send Notification action is mandatory"); } else if (childRow.getIdentifier() instanceof RuleConditionRowVo) { for (DynamicGridCell cell : childRow.getCellArray()) { if (cell.getValue() == null) { errors.add("Entity fields for Send Notification action are mandatory."); } } } } return errors; }
private IRule getRuleFromScreen() { Rule rule = new Rule(); rule.setName(form.lyrRules().tabGeneral().txtName().getValue()); rule.setDescription(form.lyrRules().tabGeneral().txtDescription().getValue()); rule.setPriority(0); if (form.lyrRules().tabGeneral().chkDateRange().getValue()) { rule.setValidFrom(form.lyrRules().tabGeneral().dteValidFrom().getValue()); rule.setValidTo(form.lyrRules().tabGeneral().dteValidTo().getValue()); } else { rule.setValidFrom(null); rule.setValidTo(null); } rule.setRootEntity(form.lyrRules().tabConditions().cmbRootEntity().getValue()); List<IRuleCondition> conditions = new ArrayList<IRuleCondition>(); List<IRuleCondition> valueConditions = new ArrayList<IRuleCondition>(); int numberOfRows = form.lyrRules().tabConditions().dyngrdConditions().getRows().size(); RuleLogicalCondition logicalCondition = null; RuleValueConditionEntry entry = null; for (int i = 0; i < numberOfRows; i++) { DynamicGridRow row = form.lyrRules().tabConditions().dyngrdConditions().getRows().get(i); RuleConditionRowVo rowIdentifier = (RuleConditionRowVo) row.getIdentifier(); int numberOfColums = rowIdentifier.getNumberOfColumns(); if (rowIdentifier != null) { logicalCondition = checkForLogicalCondition(logicalCondition, row, rowIdentifier, numberOfColums); if (row.getRows() != null) { entry = checkForChildValueCondition(valueConditions, entry, row); } } } if (entry == null) return null; logicalCondition.setConditions(valueConditions); conditions.add(logicalCondition); rule.setConditions(conditions); rule.setActions(getActions()); return rule; }