@Override public A findByPlainAttrUniqueValue( final String schemaKey, final PlainAttrValue attrUniqueValue, final boolean ignoreCaseMatch) { PlainSchema schema = plainSchemaDAO.find(schemaKey); if (schema == null) { LOG.error("Invalid schema '{}'", schemaKey); return null; } if (!schema.isUniqueConstraint()) { LOG.error("This schema has not unique constraint: '{}'", schemaKey); return null; } List<A> result = findByPlainAttrValue(schemaKey, attrUniqueValue, ignoreCaseMatch); return result.isEmpty() ? null : result.get(0); }
switch (cond.getType()) { case ISNOTNULL: query.append(checked.getLeft().isUniqueConstraint() ? svs.asSearchViewSupport().uniqueAttr().name : svs.asSearchViewSupport().attr().name). append("("). append("SELECT DISTINCT any_id FROM "). append(checked.getLeft().isUniqueConstraint() ? svs.asSearchViewSupport().uniqueAttr().name : svs.asSearchViewSupport().attr().name). query.append(svs.field().name).append(" WHERE "); } else { if (checked.getLeft().isUniqueConstraint()) { query.append(svs.asSearchViewSupport().uniqueAttr().name); } else {
protected void parseOrderByForPlainSchema( final SearchSupport svs, final OrderBySupport obs, final OrderBySupport.Item item, final OrderByClause clause, final PlainSchema schema, final String fieldName) { // keep track of involvement of non-mandatory schemas in the order by clauses obs.nonMandatorySchemas = !"true".equals(schema.getMandatoryCondition()); if (schema.isUniqueConstraint()) { obs.views.add(svs.asSearchViewSupport().uniqueAttr()); item.select = new StringBuilder(). append(svs.asSearchViewSupport().uniqueAttr().alias).append('.'). append(svs.fieldName(schema.getType())). append(" AS ").append(fieldName).toString(); item.where = new StringBuilder(). append(svs.asSearchViewSupport().uniqueAttr().alias). append(".schema_id='").append(fieldName).append("'").toString(); item.orderBy = fieldName + " " + clause.getDirection().name(); } else { obs.views.add(svs.asSearchViewSupport().attr()); item.select = new StringBuilder(). append(svs.asSearchViewSupport().attr().alias).append('.').append(svs.fieldName(schema.getType())). append(" AS ").append(fieldName).toString(); item.where = new StringBuilder(). append(svs.asSearchViewSupport().attr().alias). append(".schema_id='").append(fieldName).append("'").toString(); item.orderBy = fieldName + " " + clause.getDirection().name(); } }
String entityName = schema.isUniqueConstraint() ? anyUtils().plainAttrUniqueValueClass().getName() : anyUtils().plainAttrValueClass().getName();
@Override public Conf save(final CPlainAttr attr) { Conf instance = get(); Optional<? extends CPlainAttr> old = instance.getPlainAttr(attr.getSchema().getKey()); if (old.isPresent() && (!attr.getSchema().isUniqueConstraint() || (!attr.getUniqueValue().getStringValue().equals(old.get().getUniqueValue().getStringValue())))) { old.get().setOwner(null); instance.remove(old.get()); } instance.add(attr); attr.setOwner(instance); return entityManager().merge(instance); }
if (schema.isUniqueConstraint()) { query.append(svs.asSearchViewSupport().uniqueAttr().name); } else {
try { PlainAttrValue attrValue; if (schema.isUniqueConstraint()) { attrValue = entityFactory.newEntity(CPlainAttrUniqueValue.class); ((PlainAttrUniqueValue) attrValue).setSchema(schema);
protected Pair<PlainSchema, PlainAttrValue> check(final AttributeCond cond, final AnyTypeKind kind) { AnyUtils anyUtils = anyUtilsFactory.getInstance(kind); PlainSchema schema = schemaDAO.find(cond.getSchema()); if (schema == null) { LOG.warn("Ignoring invalid schema '{}'", cond.getSchema()); throw new IllegalArgumentException(); } PlainAttrValue attrValue = schema.isUniqueConstraint() ? anyUtils.newPlainAttrUniqueValue() : anyUtils.newPlainAttrValue(); try { if (cond.getType() != AttributeCond.Type.LIKE && cond.getType() != AttributeCond.Type.ILIKE && cond.getType() != AttributeCond.Type.ISNULL && cond.getType() != AttributeCond.Type.ISNOTNULL) { ((JPAPlainSchema) schema).validator().validate(cond.getExpression(), attrValue); } } catch (ValidationException e) { LOG.error("Could not validate expression '" + cond.getExpression() + "'", e); throw new IllegalArgumentException(); } return Pair.of(schema, attrValue); }
PlainSchema schema = schemaDAO.find(clause.getField()); if (schema != null) { if (schema.isUniqueConstraint()) { orderByUniquePlainSchemas.add(schema.getKey()); } else {
case ADD_REPLACE: if (attr.getSchema().isUniqueConstraint()) { if (attr.getUniqueValue() != null && !patch.getAttrTO().getValues().isEmpty() && (!schema.isUniqueConstraint() || attr.getUniqueValue() == null || !valuesToBeAdded.get(0).equals(attr.getUniqueValue().getValueAsString()))) {
isValid = true; } else { if (attr.getSchema().isUniqueConstraint()) { isValid = attr.getValues().isEmpty() && attr.getUniqueValue() != null; } else {
@Override public PlainSchema update(final PlainSchemaTO schemaTO, final PlainSchema schema) { SyncopeClientCompositeException scce = SyncopeClientException.buildComposite(); boolean hasAttrs = false; for (AnyTypeKind anyTypeKind : AnyTypeKind.values()) { AnyUtils anyUtils = anyUtilsFactory.getInstance(anyTypeKind); hasAttrs |= plainSchemaDAO.findAttrs(schema, anyUtils.plainAttrClass()).isEmpty(); } if (hasAttrs) { if (schema.getType() != schemaTO.getType()) { SyncopeClientException e = SyncopeClientException.build(ClientExceptionType.InvalidPlainSchema); e.getElements().add("Cannot change type since " + schema.getKey() + " has attributes"); scce.addException(e); } if (schema.isUniqueConstraint() != schemaTO.isUniqueConstraint()) { SyncopeClientException e = SyncopeClientException.build(ClientExceptionType.InvalidPlainSchema); e.getElements().add("Cannot alter unique contraint since " + schema.getKey() + " has attributes"); scce.addException(e); } } if (scce.hasExceptions()) { throw scce; } return fill(schema, schemaTO); }
addPropertyNode("secretKey").addPropertyNode("cipherAlgorithm").addConstraintViolation(); } else { isValid = !schema.isMultivalue() || !schema.isUniqueConstraint(); if (!isValid) { context.disableDefaultConstraintViolation();
@Override public PlainSchemaTO getPlainSchemaTO(final String key) { PlainSchema schema = plainSchemaDAO.find(key); if (schema == null) { throw new NotFoundException("Schema '" + key + "'"); } PlainSchemaTO schemaTO = new PlainSchemaTO(); schemaTO.setKey(schema.getKey()); schemaTO.setType(schema.getType()); schemaTO.setCipherAlgorithm(schema.getCipherAlgorithm()); schemaTO.setConversionPattern(schema.getConversionPattern()); schemaTO.setEnumerationKeys(schema.getEnumerationKeys()); schemaTO.setEnumerationValues(schema.getEnumerationValues()); schemaTO.setMandatoryCondition(schema.getMandatoryCondition()); schemaTO.setMimeType(schema.getMimeType()); schemaTO.setMultivalue(schema.isMultivalue()); schemaTO.setReadonly(schema.isReadonly()); schemaTO.setSecretKey(schema.getSecretKey()); schemaTO.setUniqueConstraint(schema.isUniqueConstraint()); labels(schema, schemaTO); schemaTO.setAnyTypeClass(schema.getAnyTypeClass() == null ? null : schema.getAnyTypeClass().getKey()); if (schema.getValidator() != null) { schemaTO.setValidator(schema.getValidator().getKey()); } return schemaTO; }