use of org.apache.directory.api.ldap.model.schema.MutableObjectClass in project directory-ldap-api by apache.
the class SchemaManagerAddTest method testAddObjectClassSuperiorsAuxiliaryWithStructuralInSup.
/**
* Addition of an AUXILIARY OC with some STRUCTURAL superior
*/
@Test
public void testAddObjectClassSuperiorsAuxiliaryWithStructuralInSup() throws Exception {
SchemaManager schemaManager = loadSystem();
int ocrSize = schemaManager.getObjectClassRegistry().size();
int goidSize = schemaManager.getGlobalOidRegistry().size();
MutableObjectClass objectClass = new MutableObjectClass("1.1.1");
objectClass.setNames("Test");
objectClass.setType(ObjectClassTypeEnum.AUXILIARY);
objectClass.addSuperiorOids("referral");
assertFalse(schemaManager.add(objectClass));
assertTrue(schemaManager.getErrors().get(0) instanceof LdapSchemaException);
assertFalse(isOCPresent(schemaManager, "1.1.1"));
assertEquals(ocrSize, schemaManager.getObjectClassRegistry().size());
assertEquals(goidSize, schemaManager.getGlobalOidRegistry().size());
}
use of org.apache.directory.api.ldap.model.schema.MutableObjectClass in project directory-ldap-api by apache.
the class SchemaManagerAddTest method testAddObjectClassSuperiorsATInMustPresentInSuperiorsMay.
/**
* Addition of an OC with some AT present in MUST and in MAY in one of its
* superior
*/
@Test
public void testAddObjectClassSuperiorsATInMustPresentInSuperiorsMay() throws Exception {
SchemaManager schemaManager = loadSystem();
int ocrSize = schemaManager.getObjectClassRegistry().size();
int goidSize = schemaManager.getGlobalOidRegistry().size();
MutableObjectClass objectClass = new MutableObjectClass("1.1.1");
objectClass.setNames("Test");
objectClass.setType(ObjectClassTypeEnum.STRUCTURAL);
objectClass.addSuperiorOids("alias", "OpenLDAProotDSE");
objectClass.addMustAttributeTypeOids("aliasedObjectName", "cn");
assertTrue(schemaManager.add(objectClass));
assertEquals(0, schemaManager.getErrors().size());
ObjectClass added = schemaManager.lookupObjectClassRegistry("1.1.1");
assertNotNull(added);
assertTrue(added.getNames().contains("Test"));
assertNotNull(added.getSuperiors());
assertEquals(2, added.getSuperiors().size());
Set<String> expectedSups = new HashSet<String>();
expectedSups.add("alias");
expectedSups.add("OpenLDAProotDSE");
for (ObjectClass addedOC : added.getSuperiors()) {
assertTrue(expectedSups.contains(addedOC.getName()));
expectedSups.remove(addedOC.getName());
}
assertEquals(ocrSize + 1, schemaManager.getObjectClassRegistry().size());
assertEquals(goidSize + 1, schemaManager.getGlobalOidRegistry().size());
}
use of org.apache.directory.api.ldap.model.schema.MutableObjectClass in project directory-ldap-api by apache.
the class SchemaManagerAddTest method testAddObjectClassSuperiorsAbstractWithAuxiliaryInSup.
/**
* Addition of an ABSTRACT OC with some AUXILIARY superior
*/
@Test
public void testAddObjectClassSuperiorsAbstractWithAuxiliaryInSup() throws Exception {
SchemaManager schemaManager = loadSystem();
int ocrSize = schemaManager.getObjectClassRegistry().size();
int goidSize = schemaManager.getGlobalOidRegistry().size();
MutableObjectClass objectClass = new MutableObjectClass("1.1.1");
objectClass.setNames("Test");
objectClass.setType(ObjectClassTypeEnum.ABSTRACT);
objectClass.addSuperiorOids("extensibleObject");
assertFalse(schemaManager.add(objectClass));
assertTrue(schemaManager.getErrors().get(0) instanceof LdapSchemaException);
assertFalse(isOCPresent(schemaManager, "1.1.1"));
assertEquals(ocrSize, schemaManager.getObjectClassRegistry().size());
assertEquals(goidSize, schemaManager.getGlobalOidRegistry().size());
}
use of org.apache.directory.api.ldap.model.schema.MutableObjectClass in project directory-ldap-api by apache.
the class SchemaManagerAddTest method testAddObjectClassSuperiorsATInMayPresentInSuperiorsMust.
/**
* Addition of an OC with some AT present in MAY and in MUST in one of its
* superior : not allowed
*/
@Test
public void testAddObjectClassSuperiorsATInMayPresentInSuperiorsMust() throws Exception {
SchemaManager schemaManager = loadSystem();
int ocrSize = schemaManager.getObjectClassRegistry().size();
int goidSize = schemaManager.getGlobalOidRegistry().size();
MutableObjectClass objectClass = new MutableObjectClass("1.1.1");
objectClass.setNames("Test");
objectClass.setType(ObjectClassTypeEnum.STRUCTURAL);
objectClass.addSuperiorOids("alias", "OpenLDAProotDSE");
objectClass.addMayAttributeTypeOids("aliasedObjectName", "cn");
assertFalse(schemaManager.add(objectClass));
assertEquals(1, schemaManager.getErrors().size());
assertTrue(schemaManager.getErrors().get(0) instanceof LdapSchemaException);
assertFalse(isOCPresent(schemaManager, "1.1.1"));
assertEquals(ocrSize, schemaManager.getObjectClassRegistry().size());
assertEquals(goidSize, schemaManager.getGlobalOidRegistry().size());
}
use of org.apache.directory.api.ldap.model.schema.MutableObjectClass in project directory-ldap-api by apache.
the class SchemaEntityFactory method getObjectClass.
/**
* {@inheritDoc}
*/
@Override
public ObjectClass getObjectClass(SchemaManager schemaManager, Entry entry, Registries targetRegistries, String schemaName) throws LdapException {
checkEntry(entry, SchemaConstants.OBJECT_CLASS);
// The ObjectClass OID
String oid = getOid(entry, SchemaConstants.OBJECT_CLASS, schemaManager.isStrict());
// Get the schema
if (!schemaManager.isSchemaLoaded(schemaName)) {
// The schema is not loaded. We can't create the requested ObjectClass
String msg = I18n.err(I18n.ERR_16030_CANNOT_ADD_OC, entry.getDn().getName(), schemaName);
LOG.warn(msg);
throw new LdapUnwillingToPerformException(ResultCodeEnum.UNWILLING_TO_PERFORM, msg);
}
Schema schema = getSchema(schemaName, targetRegistries);
if (schema == null) {
// The schema is disabled. We still have to update the backend
String msg = I18n.err(I18n.ERR_16031_CANNOT_ADD_OC_IN_REGISTRY, entry.getDn().getName(), schemaName);
LOG.info(msg);
schema = schemaManager.getLoadedSchema(schemaName);
}
// Create the ObjectClass instance
MutableObjectClass oc = new MutableObjectClass(oid);
// The Sup field
Attribute mSuperiors = entry.get(MetaSchemaConstants.M_SUP_OBJECT_CLASS_AT);
if (mSuperiors != null) {
oc.setSuperiorOids(getStrings(mSuperiors));
}
// The May field
Attribute mMay = entry.get(MetaSchemaConstants.M_MAY_AT);
if (mMay != null) {
oc.setMayAttributeTypeOids(getStrings(mMay));
}
// The Must field
Attribute mMust = entry.get(MetaSchemaConstants.M_MUST_AT);
if (mMust != null) {
oc.setMustAttributeTypeOids(getStrings(mMust));
}
// The objectClassType field
Attribute mTypeObjectClass = entry.get(MetaSchemaConstants.M_TYPE_OBJECT_CLASS_AT);
if (mTypeObjectClass != null) {
String type = mTypeObjectClass.getString();
oc.setType(ObjectClassTypeEnum.getClassType(type));
}
// Common properties
setSchemaObjectProperties(oc, entry, schema);
return oc;
}
Aggregations