Search in sources :

Example 11 with PersistenceEntryManager

use of org.gluu.persist.PersistenceEntryManager 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 12 with PersistenceEntryManager

use of org.gluu.persist.PersistenceEntryManager 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 13 with PersistenceEntryManager

use of org.gluu.persist.PersistenceEntryManager 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)

Example 14 with PersistenceEntryManager

use of org.gluu.persist.PersistenceEntryManager in project oxTrust by GluuFederation.

the class AppInitializer method createMetricPersistenceEntryManager.

@Produces
@ApplicationScoped
@Named(ApplicationFactory.PERSISTENCE_METRIC_ENTRY_MANAGER_NAME)
@ReportMetric
public PersistenceEntryManager createMetricPersistenceEntryManager() {
    Properties connectionProperties = prepareCustomPersistanceProperties(ApplicationFactory.PERSISTENCE_METRIC_CONFIG_GROUP_NAME);
    PersistenceEntryManager persistenceEntryManager = applicationFactory.getPersistenceEntryManagerFactory().createEntryManager(connectionProperties);
    log.info("Created {}: {} with operation service: {}", new Object[] { ApplicationFactory.PERSISTENCE_METRIC_ENTRY_MANAGER_NAME, persistenceEntryManager, persistenceEntryManager.getOperationService() });
    externalPersistenceExtensionService.executePersistenceExtensionAfterCreate(connectionProperties, persistenceEntryManager);
    return persistenceEntryManager;
}
Also used : PersistenceEntryManager(org.gluu.persist.PersistenceEntryManager) Properties(java.util.Properties) Named(javax.inject.Named) Produces(javax.enterprise.inject.Produces) ReportMetric(org.gluu.service.metric.inject.ReportMetric) ApplicationScoped(javax.enterprise.context.ApplicationScoped)

Example 15 with PersistenceEntryManager

use of org.gluu.persist.PersistenceEntryManager in project oxTrust by GluuFederation.

the class AppInitializer method recreatePersistanceEntryManagerImpl.

protected void recreatePersistanceEntryManagerImpl(Instance<PersistenceEntryManager> instance, String persistenceEntryManagerName, Annotation... qualifiers) {
    // Get existing application scoped instance
    PersistenceEntryManager oldLdapEntryManager = CdiUtil.getContextBean(beanManager, PersistenceEntryManager.class, persistenceEntryManagerName, qualifiers);
    // Close existing connections
    closePersistenceEntryManager(oldLdapEntryManager, persistenceEntryManagerName);
    // Force to create new bean
    PersistenceEntryManager ldapEntryManager = instance.get();
    instance.destroy(ldapEntryManager);
    log.info("Recreated instance {}: {} with operation service: {}", persistenceEntryManagerName, ldapEntryManager, ldapEntryManager.getOperationService());
}
Also used : PersistenceEntryManager(org.gluu.persist.PersistenceEntryManager)

Aggregations

PersistenceEntryManager (org.gluu.persist.PersistenceEntryManager)38 Properties (java.util.Properties)8 SchemaEntry (org.gluu.model.SchemaEntry)7 ArrayList (java.util.ArrayList)6 ApplicationScoped (javax.enterprise.context.ApplicationScoped)5 Produces (javax.enterprise.inject.Produces)5 Named (javax.inject.Named)5 GluuSimplePerson (org.gluu.oxtrust.ldap.cache.model.GluuSimplePerson)5 BasePersistenceException (org.gluu.persist.exception.BasePersistenceException)5 PersistenceEntryManagerFactory (org.gluu.persist.PersistenceEntryManagerFactory)4 Filter (org.gluu.search.filter.Filter)4 GluuLdapConfiguration (org.gluu.model.ldap.GluuLdapConfiguration)3 GluuInumMap (org.gluu.oxtrust.ldap.cache.model.GluuInumMap)3 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 LinkedHashSet (java.util.LinkedHashSet)2 List (java.util.List)2 CustomScriptType (org.gluu.model.custom.script.CustomScriptType)2 CacheCompoundKey (org.gluu.oxtrust.ldap.cache.model.CacheCompoundKey)2 ApplicationInitializedEvent (org.gluu.service.cdi.event.ApplicationInitializedEvent)2