use of org.apache.syncope.common.lib.to.DerSchemaTO in project syncope by apache.
the class SchemaDataBinderImpl method getDerSchemaTO.
@Override
public DerSchemaTO getDerSchemaTO(final DerSchema schema) {
DerSchemaTO schemaTO = new DerSchemaTO();
BeanUtils.copyProperties(schema, schemaTO, IGNORE_PROPERTIES);
schemaTO.setAnyTypeClass(schema.getAnyTypeClass() == null ? null : schema.getAnyTypeClass().getKey());
return schemaTO;
}
use of org.apache.syncope.common.lib.to.DerSchemaTO in project syncope by apache.
the class GroupITCase method issueSYNCOPE632.
@Test
public void issueSYNCOPE632() {
DerSchemaTO orig = schemaService.read(SchemaType.DERIVED, "displayProperty");
DerSchemaTO modified = SerializationUtils.clone(orig);
modified.setExpression("icon + '_' + show");
GroupTO groupTO = GroupITCase.getSampleTO("lastGroup");
try {
schemaService.update(SchemaType.DERIVED, modified);
// 0. create group
groupTO.getPlainAttrs().add(attrTO("icon", "anIcon"));
groupTO.getPlainAttrs().add(attrTO("show", "true"));
groupTO.getResources().clear();
groupTO = createGroup(groupTO).getEntity();
assertNotNull(groupTO);
// 1. create new LDAP resource having ConnObjectKey mapped to a derived attribute
ResourceTO newLDAP = resourceService.read(RESOURCE_NAME_LDAP);
newLDAP.setKey("new-ldap");
newLDAP.setPropagationPriority(0);
for (ProvisionTO provision : newLDAP.getProvisions()) {
provision.getVirSchemas().clear();
}
MappingTO mapping = newLDAP.getProvision(AnyTypeKind.GROUP.name()).get().getMapping();
ItemTO connObjectKey = mapping.getConnObjectKeyItem();
connObjectKey.setIntAttrName("displayProperty");
connObjectKey.setPurpose(MappingPurpose.PROPAGATION);
mapping.setConnObjectKeyItem(connObjectKey);
mapping.setConnObjectLink("'cn=' + displayProperty + ',ou=groups,o=isp'");
ItemTO description = new ItemTO();
description.setIntAttrName("key");
description.setExtAttrName("description");
description.setPurpose(MappingPurpose.PROPAGATION);
mapping.add(description);
newLDAP = createResource(newLDAP);
assertNotNull(newLDAP);
// 2. update group and give the resource created above
GroupPatch patch = new GroupPatch();
patch.setKey(groupTO.getKey());
patch.getResources().add(new StringPatchItem.Builder().operation(PatchOperation.ADD_REPLACE).value("new-ldap").build());
groupTO = updateGroup(patch).getEntity();
assertNotNull(groupTO);
// 3. update the group
GroupPatch groupPatch = new GroupPatch();
groupPatch.setKey(groupTO.getKey());
groupPatch.getPlainAttrs().add(attrAddReplacePatch("icon", "anotherIcon"));
groupTO = updateGroup(groupPatch).getEntity();
assertNotNull(groupTO);
// 4. check that a single group exists in LDAP for the group created and updated above
int entries = 0;
DirContext ctx = null;
try {
ctx = getLdapResourceDirContext(null, null);
SearchControls ctls = new SearchControls();
ctls.setReturningAttributes(new String[] { "*", "+" });
ctls.setSearchScope(SearchControls.SUBTREE_SCOPE);
NamingEnumeration<SearchResult> result = ctx.search("ou=groups,o=isp", "(description=" + groupTO.getKey() + ")", ctls);
while (result.hasMore()) {
result.next();
entries++;
}
} catch (Exception e) {
// ignore
} finally {
if (ctx != null) {
try {
ctx.close();
} catch (NamingException e) {
// ignore
}
}
}
assertEquals(1, entries);
} finally {
schemaService.update(SchemaType.DERIVED, orig);
if (groupTO.getKey() != null) {
groupService.delete(groupTO.getKey());
}
resourceService.delete("new-ldap");
}
}
use of org.apache.syncope.common.lib.to.DerSchemaTO in project syncope by apache.
the class DerSchemaITCase method issueSYNCOPE323.
@Test
public void issueSYNCOPE323() {
DerSchemaTO actual = schemaService.read(SchemaType.DERIVED, "rderiveddata");
assertNotNull(actual);
try {
createSchema(SchemaType.DERIVED, actual);
fail("This should not happen");
} catch (SyncopeClientException e) {
assertEquals(Response.Status.CONFLICT, e.getType().getResponseStatus());
assertEquals(ClientExceptionType.EntityExists, e.getType());
}
actual.setKey(null);
try {
createSchema(SchemaType.DERIVED, actual);
fail("This should not happen");
} catch (SyncopeClientException e) {
assertEquals(Response.Status.BAD_REQUEST, e.getType().getResponseStatus());
assertEquals(ClientExceptionType.RequiredValuesMissing, e.getType());
}
}
use of org.apache.syncope.common.lib.to.DerSchemaTO in project syncope by apache.
the class DerSchemaITCase method create.
@Test
public void create() {
DerSchemaTO schema = new DerSchemaTO();
schema.setKey("derived");
schema.setExpression("derived_sx + '_' + derived_dx");
DerSchemaTO actual = createSchema(SchemaType.DERIVED, schema);
assertNotNull(actual);
actual = schemaService.read(SchemaType.DERIVED, actual.getKey());
assertNotNull(actual);
assertEquals(actual.getExpression(), "derived_sx + '_' + derived_dx");
}
use of org.apache.syncope.common.lib.to.DerSchemaTO in project syncope by apache.
the class DerSchemaITCase method read.
@Test
public void read() {
DerSchemaTO derivedSchemaTO = schemaService.read(SchemaType.DERIVED, "cn");
assertNotNull(derivedSchemaTO);
}
Aggregations