protected Constraint cloneConstraint(Constraint constraint, Group group) { Constraint resultConstraint = metadata.create(Constraint.class); resultConstraint.setEntityName(constraint.getEntityName()); resultConstraint.setCode(constraint.getCode()); resultConstraint.setCheckType(constraint.getCheckType()); resultConstraint.setOperationType(constraint.getOperationType()); resultConstraint.setJoinClause(constraint.getJoinClause()); resultConstraint.setWhereClause(constraint.getWhereClause()); resultConstraint.setGroovyScript(constraint.getGroovyScript()); resultConstraint.setFilterXml(constraint.getFilterXml()); resultConstraint.setIsActive(constraint.getIsActive()); resultConstraint.setGroup(group); return resultConstraint; }
public ConstraintData(Constraint constraint) { this.id = constraint.getId(); this.code = constraint.getCode(); this.join = constraint.getJoinClause(); this.whereClause = constraint.getWhereClause(); this.groovyScript = constraint.getGroovyScript(); this.operationType = constraint.getOperationType(); this.checkType = constraint.getCheckType(); }
/** * INTERNAL */ public void removeConstraint(Constraint constraintToRemove) { String entityName = constraintToRemove.getEntityName(); List<ConstraintData> constraintDataList = this.constraints.get(entityName); if (constraintDataList != null && !constraintDataList.isEmpty()) { for (ConstraintData constraintData : new ArrayList<>(constraintDataList)) { if (constraintToRemove.getId().equals(constraintData.getId())) constraintDataList.remove(constraintData); } } }
protected void setupVisibility() { Constraint item = getItem(); asList(groovyScript, groovyScriptLabel) .forEach(component -> component.setVisible(item.getCheckType().memory())); asList(joinClause, joinClauseLabel, whereClause, whereClauseLabel) .forEach(component -> component.setVisible(item.getCheckType().database() && item.getOperationType() != ConstraintOperationType.CREATE && item.getOperationType() != ConstraintOperationType.DELETE && item.getOperationType() != ConstraintOperationType.UPDATE)); asList(code, codeLabel) .forEach(component -> component.setVisible(item.getOperationType() == ConstraintOperationType.CUSTOM)); if (item.getOperationType() != ConstraintOperationType.ALL && item.getOperationType() != ConstraintOperationType.CUSTOM && item.getOperationType() != ConstraintOperationType.READ) { item.setCheckType(ConstraintCheckType.MEMORY); type.setEnabled(false); } else { type.setEnabled(true); } if (!item.getCheckType().database()) { item.setJoinClause(null); item.setWhereClause(null); } }
Constraint constraint = getItem(); final Filter fakeFilter = fakeFilterSupport.createFakeFilter(); final FilterEntity filterEntity = fakeFilterSupport.createFakeFilterEntity(constraint.getFilterXml()); final ConditionsTree conditionsTree = fakeFilterSupport.createFakeConditionsTree(fakeFilter, filterEntity); params.put("conditions", conditionsTree); params.put("useShortConditionForm", true); params.put("hideDynamicAttributes", constraint.getCheckType() != ConstraintCheckType.DATABASE); params.put("hideCustomConditions", constraint.getCheckType() != ConstraintCheckType.DATABASE); if (item.getCheckType().database()) { String jpql = new SecurityJpqlGenerator().generateJpql(filterParser.getRoot()); constraint.setWhereClause(jpql); Set<String> joins = filterParser.getRoot().getJoins(); if (!joins.isEmpty()) { String joinsStr = new TextStringBuilder().appendWithSeparators(joins, " ").toString(); constraint.setJoinClause(joinsStr); if (item.getCheckType().memory()) { String groovy = new GroovyGenerator().generateGroovy(filterParser.getRoot()); constraint.setGroovyScript(groovy); constraint.setFilterXml(filterEntity.getXml());
public void testConstraint() { Constraint constraint = getItem(); String entityName = constraint.getEntityName(); if (validateAll()) { if (!Strings.isNullOrEmpty(constraint.getWhereClause())) { String baseQueryString = "select e from " + entityName + " e"; try { QueryTransformer transformer = QueryTransformerFactory.createTransformer(baseQueryString); if (StringUtils.isNotBlank(constraint.getJoinClause())) { transformer.addJoinAndWhere(constraint.getJoinClause(), constraint.getWhereClause()); } else { transformer.addWhere(constraint.getWhereClause()); if (!Strings.isNullOrEmpty(constraint.getGroovyScript())) { try { security.evaluateConstraintScript(metadata.create(entityName), constraint.getGroovyScript()); } catch (CompilationFailedException e) { showMessageDialog(getMessage("notification.error"),
Constraint constraint = constraintsTable.getSingleSelected(); if (constraint != null) { constraint.setIsActive(!Boolean.TRUE.equals(constraint.getIsActive())); constraintsDs.commit(); constraintsDs.refresh(); activateAction.setCaption(Boolean.TRUE.equals(e.getItem().getIsActive()) ? getMessage("deactivate") : getMessage("activate")); "entityName", constraint -> { if (StringUtils.isEmpty(constraint.getEntityName())) { return componentsFactory.createComponent(Label.class); MetaClass metaClass = metadata.getClassNN(constraint.getEntityName()); MetaClass effectiveMetaClass = metadata.getExtendedEntities().getEffectiveMetaClass(metaClass); Label label = componentsFactory.createComponent(Label.class);
protected void internalOpenEditor(Constraint constraint) { LocalizedConstraintMessage localization = constraintLocalizationService.findLocalizedConstraintMessage( constraint.getEntityName(), constraint.getOperationType()); if (localization == null) { localization = metadata.create(LocalizedConstraintMessage.class); localization.setEntityName(constraint.getEntityName()); localization.setOperationType(constraint.getOperationType()); } openEditor(localization, openType); }
/** * INTERNAL */ public void addConstraint(Constraint constraint) { String entityName = constraint.getEntityName(); List<ConstraintData> list = constraints.computeIfAbsent(entityName, k -> new ArrayList<>()); list.add(new ConstraintData(constraint)); }
protected void compileConstraints(UserSession session, Group group) { EntityManager em = persistence.getEntityManager(); TypedQuery<Constraint> q = em.createQuery("select c from sec$GroupHierarchy h join h.parent.constraints c " + "where h.group.id = ?1", Constraint.class); q.setParameter(1, group.getId()); List<Constraint> constraints = q.getResultList(); List<Constraint> list = new ArrayList<>(constraints); list.addAll(group.getConstraints()); for (Constraint constraint : list) { if (Boolean.TRUE.equals(constraint.getIsActive())) { session.addConstraint(constraint); } } }