Package org.apache.syncope.core.persistence.beans

Examples of org.apache.syncope.core.persistence.beans.AbstractNormalSchema


        if (subjectField == null) {
            LOG.warn("Ignoring invalid schema '{}'", cond.getSchema());
            return EMPTY_ATTR_QUERY;
        }

        AbstractNormalSchema schema = attrUtil.newSchema();
        schema.setName(subjectField.getName());
        for (AttributeSchemaType attrSchemaType : AttributeSchemaType.values()) {
            if (subjectField.getType().isAssignableFrom(attrSchemaType.getType())) {
                schema.setType(attrSchemaType);
            }
        }

        // Deal with subject Integer fields logically mapping to boolean values
        // (SyncopeRole.inheritAttrs, for example)
        boolean foundBooleanMin = false;
        boolean foundBooleanMax = false;
        if (Integer.class.equals(subjectField.getType())) {
            for (Annotation annotation : subjectField.getAnnotations()) {
                if (Min.class.equals(annotation.annotationType())) {
                    foundBooleanMin = ((Min) annotation).value() == 0;
                } else if (Max.class.equals(annotation.annotationType())) {
                    foundBooleanMax = ((Max) annotation).value() == 1;
                }
            }
        }
        if (foundBooleanMin && foundBooleanMax) {
            schema.setType(AttributeSchemaType.Boolean);
        }

        // Deal with subject fields representing relationships to other entities
        // Only _id and _name are suppored
        if (subjectField.getType().getAnnotation(Entity.class) != null) {
            if (BeanUtils.findDeclaredMethodWithMinimalParameters(subjectField.getType(), "getId") != null) {
                cond.setSchema(cond.getSchema() + "_id");
                schema.setType(AttributeSchemaType.Long);
            }
            if (BeanUtils.findDeclaredMethodWithMinimalParameters(subjectField.getType(), "getName") != null) {
                cond.setSchema(cond.getSchema() + "_name");
                schema.setType(AttributeSchemaType.String);
            }
        }

        AbstractAttrValue attrValue = attrUtil.newAttrValue();
        if (cond.getType() != AttributeCond.Type.LIKE && cond.getType() != AttributeCond.Type.ISNULL
                && cond.getType() != AttributeCond.Type.ISNOTNULL) {

            try {
                schema.getValidator().validate(cond.getExpression(), attrValue);
            } catch (ValidationException e) {
                LOG.error("Could not validate expression '" + cond.getExpression() + "'", e);
                return EMPTY_ATTR_QUERY;
            }
        }
View Full Code Here


        // Create several clauses: one for eanch identifiers
        for (int i = 0; i < identifiers.size(); i++) {
            if (!used.contains(identifiers.get(i))) {

                // verify schema existence and get schema type
                AbstractNormalSchema schema = schemaDAO.find(identifiers.get(i), attrUtil.schemaClass());
                if (schema == null) {
                    LOG.error("Invalid schema name '{}'", identifiers.get(i));
                    throw new IllegalArgumentException("Invalid schema name " + identifiers.get(i));
                }

                // clear builder
                bld.delete(0, bld.length());

                bld.append("(");

                // set schema name
                bld.append("s.name = '").append(identifiers.get(i)).append("'");

                bld.append(" AND ");

                bld.append("s.name = a.schema_name").append(" AND ");

                bld.append("a.id = v.attribute_id");

                bld.append(" AND ");

                // use a value clause different for eanch different schema type
                switch (schema.getType()) {
                    case Boolean:
                        bld.append("v.booleanValue = '").append(attrValues.get(i)).append("'");
                        break;
                    case Long:
                        bld.append("v.longValue = ").append(attrValues.get(i));
View Full Code Here

    @Override
    public <T extends AbstractSubject> List<T> findByAttrValue(final String schemaName,
            final AbstractAttrValue attrValue, final AttributableUtil attrUtil) {

        AbstractNormalSchema schema = schemaDAO.find(schemaName, attrUtil.schemaClass());
        if (schema == null) {
            LOG.error("Invalid schema name '{}'", schemaName);
            return Collections.<T>emptyList();
        }

        final String entityName = schema.isUniqueConstraint()
                ? attrUtil.attrUniqueValueClass().getName()
                : attrUtil.attrValueClass().getName();

        TypedQuery<AbstractAttrValue> query = findByAttrValueQuery(entityName);
View Full Code Here

    @Override
    public <T extends AbstractSubject> T findByAttrUniqueValue(final String schemaName,
            final AbstractAttrValue attrUniqueValue, final AttributableUtil attrUtil) {

        AbstractNormalSchema schema = schemaDAO.find(schemaName, attrUtil.schemaClass());
        if (schema == null) {
            LOG.error("Invalid schema name '{}'", schemaName);
            return null;
        }
        if (!schema.isUniqueConstraint()) {
            LOG.error("This schema has not unique constraint: '{}'", schemaName);
            return null;
        }

        List<T> result = findByAttrValue(schemaName, attrUniqueValue, attrUtil);
View Full Code Here

    }

    @Override
    @SuppressWarnings("unchecked")
    public void delete(final String name, final AttributableUtil attributableUtil) {
        AbstractNormalSchema schema = find(name, attributableUtil.schemaClass());
        if (schema == null) {
            return;
        }

        final Set<Long> attrIds = new HashSet<Long>();
        for (AbstractAttr attr : findAttrs(schema, attributableUtil.attrClass())) {
            attrIds.add(attr.getId());
        }
        for (Long attrId : attrIds) {
            attrDAO.delete(attrId, attributableUtil.attrClass());
        }

        if (attributableUtil.getType() == AttributableType.ROLE
                || attributableUtil.getType() == AttributableType.MEMBERSHIP) {

            for (Iterator<Number> it = attrTemplateDAO.
                    findBySchemaName(schema.getName(), attributableUtil.attrTemplateClass()).iterator();
                    it.hasNext();) {

                attrTemplateDAO.delete(it.next().longValue(), attributableUtil.attrTemplateClass());
            }
        }
View Full Code Here

                case UserSchema:
                case RoleSchema:
                    attributeTO = new AttributeTO();
                    attributeTO.setSchema(item.getIntAttrName());

                    AbstractNormalSchema schema = schemaDAO.find(item.getIntAttrName(), attrUtil.schemaClass());

                    for (Object value : attribute == null || attribute.getValue() == null
                            ? Collections.emptyList()
                            : attribute.getValue()) {

                        if (value != null) {
                            final AbstractAttrValue attrValue = attrUtil.newAttrValue();
                            if (schema == null) {
                                attrValue.setStringValue(value.toString());
                            } else if (schema.getType() == AttributeSchemaType.Binary) {
                                attrValue.setBinaryValue((byte[]) value);
                            } else {
                                try {
                                    attrValue.parseValue(schema, value.toString());
                                } catch (ParsingValidationException e) {
                                    LOG.error("While parsing provided value {}", value, e);
                                    attrValue.setStringValue(value.toString());
                                }
                            }
                            attributeTO.getValues().add(attrValue.getValueAsString(
                                    schema == null ? AttributeSchemaType.String : schema.getType()));
                        }
                    }

                    subjectTO.getAttrs().add(attributeTO);
                    break;
View Full Code Here

TOP

Related Classes of org.apache.syncope.core.persistence.beans.AbstractNormalSchema

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.