use of org.apache.syncope.common.lib.to.DerSchemaTO in project syncope by apache.
the class DerAttrs method setAttrs.
@Override
protected void setAttrs(final MembershipTO membershipTO) {
List<AttrTO> attrs = new ArrayList<>();
Map<String, AttrTO> attrMap = EntityTOUtils.buildAttrMap(anyTO.getDerAttrs());
for (DerSchemaTO schema : membershipSchemas.get(membershipTO.getGroupKey()).values()) {
AttrTO attrTO = new AttrTO();
attrTO.setSchema(schema.getKey());
if (attrMap.containsKey(schema.getKey())) {
attrTO.getValues().addAll(attrMap.get(schema.getKey()).getValues());
}
attrs.add(attrTO);
}
membershipTO.getDerAttrs().clear();
membershipTO.getDerAttrs().addAll(attrs);
}
use of org.apache.syncope.common.lib.to.DerSchemaTO in project syncope by apache.
the class DerSchemaITCase method issueSYNCOPE418.
@Test
public void issueSYNCOPE418() {
DerSchemaTO schema = new DerSchemaTO();
schema.setKey("http://schemas.examples.org/security/authorization/organizationUnit");
schema.setExpression("derived_sx + '_' + derived_dx");
try {
createSchema(SchemaType.DERIVED, schema);
fail("This should not happen");
} catch (SyncopeClientException e) {
assertEquals(ClientExceptionType.InvalidDerSchema, e.getType());
assertTrue(e.getElements().iterator().next().contains(EntityViolationType.InvalidKey.name()));
}
}
use of org.apache.syncope.common.lib.to.DerSchemaTO in project syncope by apache.
the class NotificationWizardBuilder method getSchemas.
private List<String> getSchemas() {
AnyTypeTO type = null;
try {
type = anyTypeRestClient.read(AnyTypeKind.USER.name());
} catch (SyncopeClientException e) {
LOG.error("While reading all any types", e);
}
String[] anyTypeClasses = type == null ? new String[0] : type.getClasses().toArray(new String[] {});
List<String> result = new ArrayList<>();
result.add("username");
result.addAll(schemaRestClient.<PlainSchemaTO>getSchemas(SchemaType.PLAIN, null, anyTypeClasses).stream().map(EntityTO::getKey).collect(Collectors.toList()));
result.addAll(schemaRestClient.<DerSchemaTO>getSchemas(SchemaType.DERIVED, null, anyTypeClasses).stream().map(EntityTO::getKey).collect(Collectors.toList()));
result.addAll(schemaRestClient.<VirSchemaTO>getSchemas(SchemaType.VIRTUAL, null, anyTypeClasses).stream().map(EntityTO::getKey).collect(Collectors.toList()));
Collections.sort(result);
return result;
}
use of org.apache.syncope.common.lib.to.DerSchemaTO 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.common.lib.to.DerSchemaTO in project syncope by apache.
the class AnyTypeClassITCase method crud.
@Test
public void crud() {
// 1. create sample schemas
PlainSchemaTO plainSchema = new PlainSchemaTO();
plainSchema.setKey("new_plain_schema" + getUUIDString());
plainSchema.setType(AttrSchemaType.String);
plainSchema = createSchema(SchemaType.PLAIN, plainSchema);
DerSchemaTO derSchema = new DerSchemaTO();
derSchema.setKey("new_der_schema" + getUUIDString());
derSchema.setExpression(plainSchema.getKey() + " + '_' + derived_dx");
derSchema = createSchema(SchemaType.DERIVED, derSchema);
// 2. actual CRUD
AnyTypeClassTO newClass = new AnyTypeClassTO();
newClass.setKey("new class" + getUUIDString());
newClass.getPlainSchemas().add(plainSchema.getKey());
Response response = anyTypeClassService.create(newClass);
assertEquals(Response.Status.CREATED.getStatusCode(), response.getStatusInfo().getStatusCode());
newClass = getObject(response.getLocation(), AnyTypeClassService.class, AnyTypeClassTO.class);
assertNotNull(newClass);
assertFalse(newClass.getPlainSchemas().isEmpty());
assertTrue(newClass.getDerSchemas().isEmpty());
assertTrue(newClass.getVirSchemas().isEmpty());
newClass.getDerSchemas().add(derSchema.getKey());
anyTypeClassService.update(newClass);
newClass = anyTypeClassService.read(newClass.getKey());
assertNotNull(newClass);
assertFalse(newClass.getPlainSchemas().isEmpty());
assertFalse(newClass.getDerSchemas().isEmpty());
assertTrue(newClass.getVirSchemas().isEmpty());
assertEquals(newClass.getKey(), schemaService.read(SchemaType.PLAIN, plainSchema.getKey()).getAnyTypeClass());
assertEquals(newClass.getKey(), schemaService.read(SchemaType.DERIVED, derSchema.getKey()).getAnyTypeClass());
anyTypeClassService.delete(newClass.getKey());
try {
anyTypeClassService.read(newClass.getKey());
fail("This should not happen");
} catch (SyncopeClientException e) {
assertEquals(ClientExceptionType.NotFound, e.getType());
}
assertNull(schemaService.read(SchemaType.PLAIN, plainSchema.getKey()).getAnyTypeClass());
assertNull(schemaService.read(SchemaType.DERIVED, derSchema.getKey()).getAnyTypeClass());
}
Aggregations