Search in sources :

Example 1 with SchemaEntry

use of org.gluu.model.SchemaEntry in project oxCore by GluuFederation.

the class SchemaService method removeObjectClassWithDefinition.

private void removeObjectClassWithDefinition(String objectClassDefinition) {
    SchemaEntry schemaEntry = new SchemaEntry();
    schemaEntry.setDn(getDnForSchema());
    schemaEntry.addObjectClass(objectClassDefinition);
    log.debug("Removing objectClass: {}", schemaEntry);
    PersistenceEntryManager ldapPersistenceEntryManager = getPersistenceEntryManager();
    ldapPersistenceEntryManager.remove(schemaEntry);
}
Also used : PersistenceEntryManager(org.gluu.persist.PersistenceEntryManager) SchemaEntry(org.gluu.model.SchemaEntry)

Example 2 with SchemaEntry

use of org.gluu.model.SchemaEntry in project oxCore by GluuFederation.

the class SchemaService method removeStringAttribute.

/**
 * Remove string attribute
 *
 * @param attributeType
 *            Attribute type name
 * @throws Exception
 */
public void removeStringAttribute(String attributeType) throws Exception {
    SchemaEntry schema = getSchema();
    String attributeTypeDefinition = getAttributeTypeDefinition(schema, attributeType);
    if (attributeTypeDefinition != null) {
        SchemaEntry schemaEntry = new SchemaEntry();
        schemaEntry.setDn(getDnForSchema());
        schemaEntry.addAttributeType(attributeTypeDefinition);
        log.debug("Removing attributeType: {}", schemaEntry);
        PersistenceEntryManager ldapPersistenceEntryManager = getPersistenceEntryManager();
        ldapPersistenceEntryManager.remove(schemaEntry);
    }
}
Also used : PersistenceEntryManager(org.gluu.persist.PersistenceEntryManager) SchemaEntry(org.gluu.model.SchemaEntry)

Example 3 with SchemaEntry

use of org.gluu.model.SchemaEntry in project oxCore by GluuFederation.

the class SchemaService method getSchema.

/**
 * Load schema from DS
 *
 * @return Schema
 */
public SchemaEntry getSchema() {
    String shemaDn = getDnForSchema();
    if (StringHelper.isNotEmpty(shemaDn)) {
        PersistenceEntryManager ldapPersistenceEntryManager = getPersistenceEntryManager();
        SchemaEntry schemaEntry = ldapPersistenceEntryManager.find(getDnForSchema(), SchemaEntry.class, null);
        return schemaEntry;
    }
    return null;
}
Also used : PersistenceEntryManager(org.gluu.persist.PersistenceEntryManager) SchemaEntry(org.gluu.model.SchemaEntry)

Example 4 with SchemaEntry

use of org.gluu.model.SchemaEntry in project oxCore by GluuFederation.

the class SchemaService method addStringAttribute.

/**
 * Add new attribute type
 */
public void addStringAttribute(String oid, String name, String schemaAddAttributeDefinition) throws Exception {
    log.info("getting a new instance SchemaEntry ");
    SchemaEntry schemaEntry = new SchemaEntry();
    log.info("setting the DN ");
    schemaEntry.setDn(getDnForSchema());
    log.info("adding attribute name ");
    log.info("applicationConfiguration.getSchemaAddAttributeDefinition() : ", schemaAddAttributeDefinition);
    log.info("oid : ", oid);
    log.info("name : ", name);
    schemaEntry.addAttributeType(String.format(schemaAddAttributeDefinition, oid, name));
    log.debug("Adding new attributeType: {}", schemaEntry);
    log.info("merging data");
    PersistenceEntryManager ldapPersistenceEntryManager = getPersistenceEntryManager();
    ldapPersistenceEntryManager.merge(schemaEntry);
}
Also used : PersistenceEntryManager(org.gluu.persist.PersistenceEntryManager) SchemaEntry(org.gluu.model.SchemaEntry)

Example 5 with SchemaEntry

use of org.gluu.model.SchemaEntry in project oxCore by GluuFederation.

the class SchemaService method removeAttributeTypeFromObjectClass.

/**
 * Remove attribute type from object class
 *
 * @param objectClass
 *            Object class name
 * @param attributeType
 *            Attribute type name
 * @throws Exception
 */
public void removeAttributeTypeFromObjectClass(String objectClass, String attributeType) throws Exception {
    SchemaEntry schema = getSchema();
    String objectClassDefinition = getObjectClassDefinition(schema, objectClass);
    if (objectClassDefinition == null) {
        throw new InvalidSchemaUpdateException(String.format("Can't add attributeType %s to objectClass %s because objectClass doesn't exist", attributeType, objectClass));
    }
    String attributeTypePattern = "$ " + attributeType + " ";
    int index = objectClassDefinition.indexOf(attributeTypePattern);
    if (index == -1) {
        attributeTypePattern = " " + attributeType + " $";
        index = objectClassDefinition.indexOf(attributeTypePattern);
        if (index == -1) {
            attributeTypePattern = " MAY ( " + attributeType + " )";
            index = objectClassDefinition.indexOf(attributeTypePattern);
            if (index == -1) {
                throw new InvalidSchemaUpdateException(String.format("Invalid objectClass definition format"));
            }
        }
    }
    String newObjectClassDefinition = objectClassDefinition.substring(0, index) + objectClassDefinition.substring(index + attributeTypePattern.length());
    // Remove OC definition
    removeObjectClassWithDefinition(objectClassDefinition);
    // Add updated OC definition
    SchemaEntry schemaEntry = new SchemaEntry();
    schemaEntry.setDn(getDnForSchema());
    schemaEntry.addObjectClass(newObjectClassDefinition);
    log.debug("Removing attributeType from objectClass: {}", schemaEntry);
    PersistenceEntryManager ldapPersistenceEntryManager = getPersistenceEntryManager();
    ldapPersistenceEntryManager.merge(schemaEntry);
}
Also used : PersistenceEntryManager(org.gluu.persist.PersistenceEntryManager) SchemaEntry(org.gluu.model.SchemaEntry) InvalidSchemaUpdateException(org.gluu.util.exception.InvalidSchemaUpdateException)

Aggregations

SchemaEntry (org.gluu.model.SchemaEntry)15 PersistenceEntryManager (org.gluu.persist.PersistenceEntryManager)7 AttributeTypeDefinition (com.unboundid.ldap.sdk.schema.AttributeTypeDefinition)4 ArrayList (java.util.ArrayList)4 HashMap (java.util.HashMap)2 GluuAttribute (org.gluu.model.GluuAttribute)2 InvalidSchemaUpdateException (org.gluu.util.exception.InvalidSchemaUpdateException)2 LinkedHashSet (java.util.LinkedHashSet)1 VelocityContext (org.apache.velocity.VelocityContext)1 InvalidConfigurationException (org.gluu.util.exception.InvalidConfigurationException)1