use of org.apache.syncope.core.persistence.api.dao.UserDAO in project syncope by apache.
the class JPAExternalResourceDAO method delete.
@Override
public void delete(final String name) {
ExternalResource resource = find(name);
if (resource == null) {
return;
}
taskDAO().deleteAll(resource, TaskType.PROPAGATION);
taskDAO().deleteAll(resource, TaskType.PULL);
taskDAO().deleteAll(resource, TaskType.PUSH);
realmDAO().findByResource(resource).forEach(realm -> realm.getResources().remove(resource));
anyObjectDAO().findByResource(resource).forEach(anyObject -> anyObject.getResources().remove(resource));
userDAO().findByResource(resource).forEach(user -> user.getResources().remove(resource));
groupDAO().findByResource(resource).forEach(group -> group.getResources().remove(resource));
policyDAO().findByResource(resource).forEach(policy -> policy.getResources().remove(resource));
resource.getProvisions().stream().filter(provision -> provision.getMapping() != null).peek(provision -> provision.getMapping().getItems().forEach(item -> item.setMapping(null))).peek(provision -> {
provision.getMapping().getItems().clear();
provision.setMapping(null);
provision.setResource(null);
}).forEachOrdered(provision -> virSchemaDAO().findByProvision(provision).forEach(schema -> virSchemaDAO().delete(schema.getKey())));
externalResourceHistoryConfDAO().deleteByEntity(resource);
if (resource.getConnector() != null && resource.getConnector().getResources() != null && !resource.getConnector().getResources().isEmpty()) {
resource.getConnector().getResources().remove(resource);
}
resource.setConnector(null);
entityManager().remove(resource);
}
use of org.apache.syncope.core.persistence.api.dao.UserDAO in project syncope by apache.
the class JPAGroupDAO method delete.
@Override
public void delete(final Group group) {
dynRealmDAO().removeDynMemberships(group.getKey());
findAMemberships(group).forEach(membership -> {
AnyObject leftEnd = membership.getLeftEnd();
leftEnd.getMemberships().remove(membership);
membership.setRightEnd(null);
leftEnd.getPlainAttrs(membership).stream().map(attr -> {
leftEnd.remove(attr);
attr.setOwner(null);
attr.setMembership(null);
return attr;
}).forEachOrdered(attr -> plainAttrDAO.delete(attr));
anyObjectDAO().save(leftEnd);
publisher.publishEvent(new AnyCreatedUpdatedEvent<>(this, leftEnd, AuthContextUtils.getDomain()));
});
findUMemberships(group).forEach(membership -> {
User leftEnd = membership.getLeftEnd();
leftEnd.getMemberships().remove(membership);
membership.setRightEnd(null);
leftEnd.getPlainAttrs(membership).stream().map(attr -> {
leftEnd.remove(attr);
attr.setOwner(null);
attr.setMembership(null);
return attr;
}).forEachOrdered(attr -> plainAttrDAO.delete(attr));
userDAO().save(leftEnd);
publisher.publishEvent(new AnyCreatedUpdatedEvent<>(this, leftEnd, AuthContextUtils.getDomain()));
});
clearUDynMembers(group);
clearADynMembers(group);
entityManager().remove(group);
publisher.publishEvent(new AnyDeletedEvent(this, AnyTypeKind.GROUP, group.getKey(), AuthContextUtils.getDomain()));
}
Aggregations