use of org.apache.syncope.core.persistence.api.entity.group.Group in project syncope by apache.
the class GroupDataBinderImpl method create.
@Override
public void create(final Group group, final GroupTO groupTO) {
SyncopeClientCompositeException scce = SyncopeClientException.buildComposite();
// name
SyncopeClientException invalidGroups = SyncopeClientException.build(ClientExceptionType.InvalidGroup);
if (groupTO.getName() == null) {
LOG.error("No name specified for this group");
invalidGroups.getElements().add("No name specified for this group");
} else {
group.setName(groupTO.getName());
}
// realm
Realm realm = realmDAO.findByFullPath(groupTO.getRealm());
if (realm == null) {
SyncopeClientException noRealm = SyncopeClientException.build(ClientExceptionType.InvalidRealm);
noRealm.getElements().add("Invalid or null realm specified: " + groupTO.getRealm());
scce.addException(noRealm);
}
group.setRealm(realm);
// attributes and resources
fill(group, groupTO, anyUtilsFactory.getInstance(AnyTypeKind.GROUP), scce);
// owner
if (groupTO.getUserOwner() != null) {
User owner = userDAO.find(groupTO.getUserOwner());
if (owner == null) {
LOG.warn("Ignoring invalid user specified as owner: {}", groupTO.getUserOwner());
} else {
group.setUserOwner(owner);
}
}
if (groupTO.getGroupOwner() != null) {
Group owner = groupDAO.find(groupTO.getGroupOwner());
if (owner == null) {
LOG.warn("Ignoring invalid group specified as owner: {}", groupTO.getGroupOwner());
} else {
group.setGroupOwner(owner);
}
}
// dynamic membership
if (groupTO.getUDynMembershipCond() != null) {
setDynMembership(group, anyTypeDAO.findUser(), groupTO.getUDynMembershipCond());
}
groupTO.getADynMembershipConds().forEach((type, fiql) -> {
AnyType anyType = anyTypeDAO.find(type);
if (anyType == null) {
LOG.warn("Ignoring invalid {}: {}", AnyType.class.getSimpleName(), type);
} else {
setDynMembership(group, anyType, fiql);
}
});
// type extensions
groupTO.getTypeExtensions().forEach(typeExtTO -> {
AnyType anyType = anyTypeDAO.find(typeExtTO.getAnyType());
if (anyType == null) {
LOG.warn("Ignoring invalid {}: {}", AnyType.class.getSimpleName(), typeExtTO.getAnyType());
} else {
TypeExtension typeExt = entityFactory.newEntity(TypeExtension.class);
typeExt.setAnyType(anyType);
typeExt.setGroup(group);
group.add(typeExt);
typeExtTO.getAuxClasses().forEach(name -> {
AnyTypeClass anyTypeClass = anyTypeClassDAO.find(name);
if (anyTypeClass == null) {
LOG.warn("Ignoring invalid {}: {}", AnyTypeClass.class.getSimpleName(), name);
} else {
typeExt.add(anyTypeClass);
}
});
if (typeExt.getAuxClasses().isEmpty()) {
group.getTypeExtensions().remove(typeExt);
typeExt.setGroup(null);
}
}
});
// Throw composite exception if there is at least one element set in the composing exceptions
if (scce.hasExceptions()) {
throw scce;
}
}
use of org.apache.syncope.core.persistence.api.entity.group.Group in project syncope by apache.
the class GroupDataBinderImpl method findUsersWithTransitiveResources.
@Transactional(readOnly = true)
@Override
public Map<String, PropagationByResource> findUsersWithTransitiveResources(final String groupKey) {
Group group = groupDAO.authFind(groupKey);
Map<String, PropagationByResource> result = new HashMap<>();
groupDAO.findUMemberships(group).forEach((membership) -> {
populateTransitiveResources(group, membership.getLeftEnd(), result);
});
return result;
}
use of org.apache.syncope.core.persistence.api.entity.group.Group in project syncope by apache.
the class GroupDataBinderImpl method findAnyObjectsWithTransitiveResources.
@Transactional(readOnly = true)
@Override
public Map<String, PropagationByResource> findAnyObjectsWithTransitiveResources(final String groupKey) {
Group group = groupDAO.authFind(groupKey);
Map<String, PropagationByResource> result = new HashMap<>();
groupDAO.findAMemberships(group).forEach((membership) -> {
populateTransitiveResources(group, membership.getLeftEnd(), result);
});
return result;
}
use of org.apache.syncope.core.persistence.api.entity.group.Group in project syncope by apache.
the class SyncopeLogic method searchAssignableGroups.
@PreAuthorize("isAuthenticated()")
public Pair<Integer, List<GroupTO>> searchAssignableGroups(final String realm, final String term, final int page, final int size) {
AssignableCond assignableCond = new AssignableCond();
assignableCond.setRealmFullPath(realm);
SearchCond searchCond;
if (StringUtils.isNotBlank(term)) {
AnyCond termCond = new AnyCond(AttributeCond.Type.ILIKE);
termCond.setSchema("name");
String termSearchableValue = (term.startsWith("*") && !term.endsWith("*")) ? term + "%" : (!term.startsWith("*") && term.endsWith("*")) ? "%" + term : (term.startsWith("*") && term.endsWith("*") ? term : "%" + term + "%");
termCond.setExpression(termSearchableValue);
searchCond = SearchCond.getAndCond(SearchCond.getLeafCond(assignableCond), SearchCond.getLeafCond(termCond));
} else {
searchCond = SearchCond.getLeafCond(assignableCond);
}
int count = searchDAO.count(SyncopeConstants.FULL_ADMIN_REALMS, searchCond, AnyTypeKind.GROUP);
OrderByClause orderByClause = new OrderByClause();
orderByClause.setField("name");
orderByClause.setDirection(OrderByClause.Direction.ASC);
List<Group> matching = searchDAO.search(SyncopeConstants.FULL_ADMIN_REALMS, searchCond, page, size, Collections.singletonList(orderByClause), AnyTypeKind.GROUP);
List<GroupTO> result = matching.stream().map(group -> groupDataBinder.getGroupTO(group, false)).collect(Collectors.toList());
return Pair.of(count, result);
}
use of org.apache.syncope.core.persistence.api.entity.group.Group in project syncope by apache.
the class JPAAnyObjectDAO method countByRealm.
@Override
public Map<String, Integer> countByRealm(final AnyType anyType) {
Query query = entityManager().createQuery("SELECT e.realm, COUNT(e) FROM " + JPAAnyObject.class.getSimpleName() + " e " + "WHERE e.type=:type GROUP BY e.realm");
query.setParameter("type", anyType);
@SuppressWarnings("unchecked") List<Object[]> results = query.getResultList();
return results.stream().collect(Collectors.toMap(result -> ((Realm) result[0]).getFullPath(), result -> ((Number) result[1]).intValue()));
}
Aggregations