use of org.apache.syncope.core.persistence.api.dao.GroupDAO 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.GroupDAO in project syncope by apache.
the class JPAAnyObjectDAO method findDynGroups.
@Transactional(propagation = Propagation.REQUIRES_NEW, readOnly = true)
@Override
@SuppressWarnings("unchecked")
public List<Group> findDynGroups(final String key) {
Query query = entityManager().createNativeQuery("SELECT group_id FROM " + JPAGroupDAO.ADYNMEMB_TABLE + " WHERE any_id=?");
query.setParameter(1, key);
List<Group> result = new ArrayList<>();
query.getResultList().stream().map(resultKey -> resultKey instanceof Object[] ? (String) ((Object[]) resultKey)[0] : ((String) resultKey)).forEachOrdered(actualKey -> {
Group group = groupDAO().find(actualKey.toString());
if (group == null) {
LOG.error("Could not find group with id {}, even though returned by the native query", actualKey);
} else if (!result.contains(group)) {
result.add(group);
}
});
return result;
}
use of org.apache.syncope.core.persistence.api.dao.GroupDAO in project syncope by apache.
the class JPAUserDAO method findDynGroups.
@Transactional(propagation = Propagation.REQUIRES_NEW, readOnly = true)
@Override
@SuppressWarnings("unchecked")
public List<Group> findDynGroups(final String key) {
Query query = entityManager().createNativeQuery("SELECT group_id FROM " + JPAGroupDAO.UDYNMEMB_TABLE + " WHERE any_id=?");
query.setParameter(1, key);
List<Group> result = new ArrayList<>();
query.getResultList().stream().map(resultKey -> resultKey instanceof Object[] ? (String) ((Object[]) resultKey)[0] : ((String) resultKey)).forEachOrdered(actualKey -> {
Group group = groupDAO().find(actualKey.toString());
if (group == null) {
LOG.error("Could not find group with id {}, even though returned by the native query", actualKey);
} else if (!result.contains(group)) {
result.add(group);
}
});
return result;
}
Aggregations