use of org.apache.syncope.core.persistence.api.dao.RealmDAO 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);
}
Aggregations