use of org.apache.syncope.core.persistence.api.entity.VirSchema in project syncope by apache.
the class UserDataBinderImpl method getUserTO.
@Transactional(readOnly = true)
@Override
public UserTO getUserTO(final User user, final boolean details) {
UserTO userTO = new UserTO();
BeanUtils.copyProperties(user, userTO, IGNORE_PROPERTIES);
userTO.setSuspended(BooleanUtils.isTrue(user.isSuspended()));
if (user.getSecurityQuestion() != null) {
userTO.setSecurityQuestion(user.getSecurityQuestion().getKey());
}
Map<VirSchema, List<String>> virAttrValues = details ? virAttrHandler.getValues(user) : Collections.<VirSchema, List<String>>emptyMap();
fillTO(userTO, user.getRealm().getFullPath(), user.getAuxClasses(), user.getPlainAttrs(), derAttrHandler.getValues(user), virAttrValues, userDAO.findAllResources(user), details);
if (details) {
// dynamic realms
userTO.getDynRealms().addAll(userDAO.findDynRealms(user.getKey()));
// roles
userTO.getRoles().addAll(user.getRoles().stream().map(Entity::getKey).collect(Collectors.toList()));
// dynamic roles
userTO.getDynRoles().addAll(userDAO.findDynRoles(user.getKey()).stream().map(Entity::getKey).collect(Collectors.toList()));
// privileges
userTO.getPrivileges().addAll(userDAO.findAllRoles(user).stream().flatMap(role -> role.getPrivileges().stream()).map(Entity::getKey).collect(Collectors.toSet()));
// relationships
userTO.getRelationships().addAll(user.getRelationships().stream().map(relationship -> getRelationshipTO(relationship.getType().getKey(), relationship.getRightEnd())).collect(Collectors.toList()));
// memberships
userTO.getMemberships().addAll(user.getMemberships().stream().map(membership -> {
return getMembershipTO(user.getPlainAttrs(membership), derAttrHandler.getValues(user, membership), virAttrHandler.getValues(user, membership), membership);
}).collect(Collectors.toList()));
// dynamic memberships
userTO.getDynMemberships().addAll(userDAO.findDynGroups(user.getKey()).stream().map(group -> {
return new MembershipTO.Builder().group(group.getKey(), group.getName()).build();
}).collect(Collectors.toList()));
}
return userTO;
}
use of org.apache.syncope.core.persistence.api.entity.VirSchema in project syncope by apache.
the class SchemaLogic method create.
@PreAuthorize("hasRole('" + StandardEntitlement.SCHEMA_CREATE + "')")
@SuppressWarnings("unchecked")
public <T extends SchemaTO> T create(final SchemaType schemaType, final T schemaTO) {
if (StringUtils.isBlank(schemaTO.getKey())) {
SyncopeClientException sce = SyncopeClientException.build(ClientExceptionType.RequiredValuesMissing);
sce.getElements().add("Schema key");
throw sce;
}
if (doesSchemaExist(schemaType, schemaTO.getKey())) {
throw new DuplicateException(schemaType + "/" + schemaTO.getKey());
}
T created;
switch(schemaType) {
case VIRTUAL:
VirSchema virSchema = virSchemaDAO.save(binder.create((VirSchemaTO) schemaTO));
created = (T) binder.getVirSchemaTO(virSchema);
break;
case DERIVED:
DerSchema derSchema = derSchemaDAO.save(binder.create((DerSchemaTO) schemaTO));
created = (T) binder.getDerSchemaTO(derSchema);
break;
case PLAIN:
default:
PlainSchema plainSchema = plainSchemaDAO.save(binder.create((PlainSchemaTO) schemaTO));
created = (T) binder.getPlainSchemaTO(plainSchema);
}
return created;
}
use of org.apache.syncope.core.persistence.api.entity.VirSchema in project syncope by apache.
the class SchemaLogic method search.
@PreAuthorize("isAuthenticated()")
@Transactional(readOnly = true)
public <T extends SchemaTO> List<T> search(final SchemaType schemaType, final List<String> anyTypeClasses, final String keyword) {
List<AnyTypeClass> classes = new ArrayList<>(anyTypeClasses == null ? 0 : anyTypeClasses.size());
if (anyTypeClasses != null) {
anyTypeClasses.remove(AnyTypeKind.USER.name());
anyTypeClasses.remove(AnyTypeKind.GROUP.name());
anyTypeClasses.forEach(anyTypeClass -> {
AnyTypeClass clazz = anyTypeClassDAO.find(anyTypeClass);
if (clazz == null) {
LOG.warn("Ignoring invalid {}: {}", AnyTypeClass.class.getSimpleName(), anyTypeClass);
} else {
classes.add(clazz);
}
});
}
List<T> result;
switch(schemaType) {
case VIRTUAL:
result = (classes.isEmpty() ? keyword == null ? virSchemaDAO.findAll() : virSchemaDAO.findByKeyword(keyword) : virSchemaDAO.findByAnyTypeClasses(classes)).stream().map(new Function<VirSchema, T>() {
@Override
public T apply(final VirSchema schema) {
return (T) binder.getVirSchemaTO(schema);
}
}).collect(Collectors.toList());
break;
case DERIVED:
result = (classes.isEmpty() ? keyword == null ? derSchemaDAO.findAll() : derSchemaDAO.findByKeyword(keyword) : derSchemaDAO.findByAnyTypeClasses(classes)).stream().map(new Function<DerSchema, T>() {
@Override
public T apply(final DerSchema schema) {
return (T) binder.getDerSchemaTO(schema);
}
}).collect(Collectors.toList());
break;
case PLAIN:
default:
result = (classes.isEmpty() ? keyword == null ? plainSchemaDAO.findAll() : plainSchemaDAO.findByKeyword(keyword) : plainSchemaDAO.findByAnyTypeClasses(classes)).stream().map(new Function<PlainSchema, T>() {
@Override
public T apply(final PlainSchema schema) {
return (T) binder.getPlainSchemaTO(schema);
}
}).collect(Collectors.toList());
}
return result;
}
use of org.apache.syncope.core.persistence.api.entity.VirSchema in project syncope by apache.
the class JPAAnyTypeClassDAO method delete.
@Override
public void delete(final String key) {
AnyTypeClass anyTypeClass = find(key);
if (anyTypeClass == null) {
return;
}
for (PlainSchema schema : plainSchemaDAO.findByAnyTypeClasses(Collections.singletonList(anyTypeClass))) {
schema.setAnyTypeClass(null);
}
for (DerSchema schema : derSchemaDAO.findByAnyTypeClasses(Collections.singletonList(anyTypeClass))) {
schema.setAnyTypeClass(null);
}
for (VirSchema schema : virSchemaDAO.findByAnyTypeClasses(Collections.singletonList(anyTypeClass))) {
schema.setAnyTypeClass(null);
}
for (AnyType type : anyTypeDAO.findByTypeClass(anyTypeClass)) {
type.getClasses().remove(anyTypeClass);
}
for (TypeExtension typeExt : groupDAO.findTypeExtensions(anyTypeClass)) {
typeExt.getAuxClasses().remove(anyTypeClass);
if (typeExt.getAuxClasses().isEmpty()) {
typeExt.getGroup().getTypeExtensions().remove(typeExt);
typeExt.setGroup(null);
}
}
for (Provision provision : resourceDAO.findProvisionsByAuxClass(anyTypeClass)) {
provision.getAuxClasses().remove(anyTypeClass);
}
entityManager().remove(anyTypeClass);
}
use of org.apache.syncope.core.persistence.api.entity.VirSchema in project syncope by apache.
the class VirSchemaTest method deal.
@Test
public void deal() {
Provision provision = resourceDAO.find("ws-target-resource-1").getProvision(anyTypeDAO.findUser()).get();
assertNotNull(provision);
assertTrue(virSchemaDAO.findByProvision(provision).isEmpty());
VirSchema virSchema = entityFactory.newEntity(VirSchema.class);
virSchema.setKey("vSchema");
virSchema.setReadonly(true);
virSchema.setExtAttrName("EXT_ATTR");
virSchema.setProvision(provision);
virSchemaDAO.save(virSchema);
virSchemaDAO.flush();
virSchema = virSchemaDAO.find("vSchema");
assertNotNull(virSchema);
assertTrue(virSchema.isReadonly());
assertEquals("EXT_ATTR", virSchema.getExtAttrName());
provision = resourceDAO.find("ws-target-resource-1").getProvision(anyTypeDAO.findUser()).get();
assertNotNull(provision);
assertFalse(virSchemaDAO.findByProvision(provision).isEmpty());
assertTrue(virSchemaDAO.findByProvision(provision).contains(virSchema));
MappingItem item = virSchema.asLinkingMappingItem();
assertNotNull(item);
assertEquals(virSchema.getKey(), item.getIntAttrName());
}
Aggregations