use of org.apache.syncope.core.persistence.api.entity.DerSchema in project syncope by apache.
the class SchemaLogic method resolveReference.
@Override
protected SchemaTO resolveReference(final Method method, final Object... args) throws UnresolvedReferenceException {
String key = null;
if (ArrayUtils.isNotEmpty(args)) {
for (int i = 0; key == null && i < args.length; i++) {
if (args[i] instanceof String) {
key = (String) args[i];
} else if (args[i] instanceof SchemaTO) {
key = ((SchemaTO) args[i]).getKey();
}
}
}
if (key != null) {
try {
SchemaTO result = null;
PlainSchema plainSchema = plainSchemaDAO.find(key);
if (plainSchema == null) {
DerSchema derSchema = derSchemaDAO.find(key);
if (derSchema == null) {
VirSchema virSchema = virSchemaDAO.find(key);
if (virSchema != null) {
result = binder.getVirSchemaTO(virSchema);
}
} else {
result = binder.getDerSchemaTO(derSchema);
}
} else {
result = binder.getPlainSchemaTO(plainSchema);
}
return result;
} catch (Throwable ignore) {
LOG.debug("Unresolved reference", ignore);
throw new UnresolvedReferenceException(ignore);
}
}
throw new UnresolvedReferenceException();
}
use of org.apache.syncope.core.persistence.api.entity.DerSchema in project syncope by apache.
the class SchemaLogic method update.
@PreAuthorize("hasRole('" + StandardEntitlement.SCHEMA_UPDATE + "')")
public <T extends SchemaTO> void update(final SchemaType schemaType, final T schemaTO) {
if (!doesSchemaExist(schemaType, schemaTO.getKey())) {
throw new NotFoundException(schemaType + "/" + schemaTO.getKey());
}
switch(schemaType) {
case VIRTUAL:
VirSchema virSchema = virSchemaDAO.find(schemaTO.getKey());
if (virSchema == null) {
throw new NotFoundException("Virtual Schema '" + schemaTO.getKey() + "'");
}
virSchemaDAO.save(binder.update((VirSchemaTO) schemaTO, virSchema));
break;
case DERIVED:
DerSchema derSchema = derSchemaDAO.find(schemaTO.getKey());
if (derSchema == null) {
throw new NotFoundException("Derived schema '" + schemaTO.getKey() + "'");
}
derSchemaDAO.save(binder.update((DerSchemaTO) schemaTO, derSchema));
break;
case PLAIN:
default:
PlainSchema plainSchema = plainSchemaDAO.find(schemaTO.getKey());
if (plainSchema == null) {
throw new NotFoundException("Schema '" + schemaTO.getKey() + "'");
}
plainSchemaDAO.save(binder.update((PlainSchemaTO) schemaTO, plainSchema));
}
}
use of org.apache.syncope.core.persistence.api.entity.DerSchema in project syncope by apache.
the class SchemaLogic method read.
@PreAuthorize("isAuthenticated()")
@SuppressWarnings("unchecked")
public <T extends SchemaTO> T read(final SchemaType schemaType, final String schemaKey) {
T read;
switch(schemaType) {
case VIRTUAL:
VirSchema virSchema = virSchemaDAO.find(schemaKey);
if (virSchema == null) {
throw new NotFoundException("Virtual Schema '" + schemaKey + "'");
}
read = (T) binder.getVirSchemaTO(virSchema);
break;
case DERIVED:
DerSchema derSchema = derSchemaDAO.find(schemaKey);
if (derSchema == null) {
throw new NotFoundException("Derived schema '" + schemaKey + "'");
}
read = (T) binder.getDerSchemaTO(derSchema);
break;
case PLAIN:
default:
PlainSchema schema = plainSchemaDAO.find(schemaKey);
if (schema == null) {
throw new NotFoundException("Schema '" + schemaKey + "'");
}
read = (T) binder.getPlainSchemaTO(schema);
}
return read;
}
use of org.apache.syncope.core.persistence.api.entity.DerSchema in project syncope by apache.
the class UserTest method issueSYNCOPE800.
/**
* Search by derived attribute.
*/
@Test
public void issueSYNCOPE800() {
// create derived attribute (literal as prefix)
DerSchema prefix = entityFactory.newEntity(DerSchema.class);
prefix.setKey("kprefix");
prefix.setExpression("'k' + firstname");
derSchemaDAO.save(prefix);
derSchemaDAO.flush();
// create derived attribute (literal as suffix)
DerSchema suffix = entityFactory.newEntity(DerSchema.class);
suffix.setKey("ksuffix");
suffix.setExpression("firstname + 'k'");
derSchemaDAO.save(suffix);
derSchemaDAO.flush();
// add derived attributes to user
User owner = userDAO.findByUsername("vivaldi");
assertNotNull(owner);
String firstname = owner.getPlainAttr("firstname").get().getValuesAsStrings().iterator().next();
assertNotNull(firstname);
// search by ksuffix derived attribute
List<User> list = userDAO.findByDerAttrValue("ksuffix", firstname + "k");
assertEquals(1, list.size());
// search by kprefix derived attribute
list = userDAO.findByDerAttrValue("kprefix", "k" + firstname);
assertEquals(1, list.size());
}
use of org.apache.syncope.core.persistence.api.entity.DerSchema in project syncope by apache.
the class DerSchemaTest method save.
@Test
public void save() {
DerSchema derivedAttributeSchema = entityFactory.newEntity(DerSchema.class);
derivedAttributeSchema.setKey("cn2");
derivedAttributeSchema.setExpression("firstname surname");
derSchemaDAO.save(derivedAttributeSchema);
DerSchema actual = derSchemaDAO.find("cn2");
assertNotNull(actual);
assertEquals(derivedAttributeSchema, actual);
}
Aggregations