use of org.apache.syncope.core.persistence.api.dao.search.MembershipCond in project syncope by apache.
the class AnySearchTest method issueSYNCOPE980.
@Test
public void issueSYNCOPE980() {
AnyType service = entityFactory.newEntity(AnyType.class);
service.setKey("SERVICE");
service.setKind(AnyTypeKind.ANY_OBJECT);
service = anyTypeDAO.save(service);
Group citizen = groupDAO.findByName("citizen");
assertNotNull(citizen);
AnyObject anyObject = entityFactory.newEntity(AnyObject.class);
anyObject.setName("one");
anyObject.setType(service);
anyObject.setRealm(realmDAO.findByFullPath(SyncopeConstants.ROOT_REALM));
AMembership membership = entityFactory.newEntity(AMembership.class);
membership.setRightEnd(citizen);
membership.setLeftEnd(anyObject);
anyObject.add(membership);
anyObjectDAO.save(anyObject);
anyObject = anyObjectDAO.find("fc6dbc3a-6c07-4965-8781-921e7401a4a5");
membership = entityFactory.newEntity(AMembership.class);
membership.setRightEnd(citizen);
membership.setLeftEnd(anyObject);
anyObject.add(membership);
anyObjectDAO.save(anyObject);
anyObjectDAO.flush();
MembershipCond groupCond = new MembershipCond();
groupCond.setGroup("citizen");
SearchCond searchCondition = SearchCond.getLeafCond(groupCond);
List<AnyObject> matching = searchDAO.search(searchCondition, AnyTypeKind.ANY_OBJECT);
assertEquals(2, matching.size());
AnyTypeCond anyTypeCond = new AnyTypeCond();
anyTypeCond.setAnyTypeKey(service.getKey());
searchCondition = SearchCond.getAndCond(SearchCond.getLeafCond(groupCond), SearchCond.getLeafCond(anyTypeCond));
matching = searchDAO.search(searchCondition, AnyTypeKind.ANY_OBJECT);
assertEquals(1, matching.size());
}
use of org.apache.syncope.core.persistence.api.dao.search.MembershipCond in project syncope by apache.
the class AnySearchTest method searchByGroup.
@Test
public void searchByGroup() {
MembershipCond groupCond = new MembershipCond();
groupCond.setGroup("root");
List<User> users = searchDAO.search(SearchCond.getLeafCond(groupCond), AnyTypeKind.USER);
assertNotNull(users);
assertEquals(2, users.size());
groupCond = new MembershipCond();
groupCond.setGroup("secretary");
users = searchDAO.search(SearchCond.getNotLeafCond(groupCond), AnyTypeKind.USER);
assertNotNull(users);
assertEquals(5, users.size());
}
use of org.apache.syncope.core.persistence.api.dao.search.MembershipCond in project syncope by apache.
the class AnySearchTest method searchCaseInsensitiveWithLikeCondition.
@Test
public void searchCaseInsensitiveWithLikeCondition() {
AttributeCond fullnameLeafCond = new AttributeCond(AttributeCond.Type.ILIKE);
fullnameLeafCond.setSchema("fullname");
fullnameLeafCond.setExpression("%O%");
MembershipCond groupCond = new MembershipCond();
groupCond.setGroup("root");
AttributeCond loginDateCond = new AttributeCond(AttributeCond.Type.EQ);
loginDateCond.setSchema("loginDate");
loginDateCond.setExpression("2009-05-26");
SearchCond subCond = SearchCond.getAndCond(SearchCond.getLeafCond(fullnameLeafCond), SearchCond.getLeafCond(groupCond));
assertTrue(subCond.isValid());
SearchCond cond = SearchCond.getAndCond(subCond, SearchCond.getLeafCond(loginDateCond));
assertTrue(cond.isValid());
List<User> users = searchDAO.search(cond, AnyTypeKind.USER);
assertNotNull(users);
assertEquals(1, users.size());
}
use of org.apache.syncope.core.persistence.api.dao.search.MembershipCond in project syncope by apache.
the class AnySearchTest method searchWithLikeCondition.
@Test
public void searchWithLikeCondition() {
AttributeCond fullnameLeafCond = new AttributeCond(AttributeCond.Type.LIKE);
fullnameLeafCond.setSchema("fullname");
fullnameLeafCond.setExpression("%o%");
MembershipCond groupCond = new MembershipCond();
groupCond.setGroup("root");
AttributeCond loginDateCond = new AttributeCond(AttributeCond.Type.EQ);
loginDateCond.setSchema("loginDate");
loginDateCond.setExpression("2009-05-26");
SearchCond subCond = SearchCond.getAndCond(SearchCond.getLeafCond(fullnameLeafCond), SearchCond.getLeafCond(groupCond));
assertTrue(subCond.isValid());
SearchCond cond = SearchCond.getAndCond(subCond, SearchCond.getLeafCond(loginDateCond));
assertTrue(cond.isValid());
List<User> users = searchDAO.search(cond, AnyTypeKind.USER);
assertNotNull(users);
assertEquals(1, users.size());
}
use of org.apache.syncope.core.persistence.api.dao.search.MembershipCond in project syncope by apache.
the class GroupServiceImpl method replace.
@Override
public Response replace(final String id, final SCIMGroup group) {
if (!id.equals(group.getId())) {
throw new BadRequestException(ErrorType.invalidPath, "Expected " + id + ", found " + group.getId());
}
ResponseBuilder builder = checkETag(Resource.Group, id);
if (builder != null) {
return builder.build();
}
// save current group members
Set<String> beforeMembers = new HashSet<>();
MembershipCond membCond = new MembershipCond();
membCond.setGroup(id);
SearchCond searchCond = SearchCond.getLeafCond(membCond);
int count = userLogic().search(searchCond, 1, 1, Collections.<OrderByClause>emptyList(), SyncopeConstants.ROOT_REALM, false).getLeft();
for (int page = 1; page <= (count / AnyDAO.DEFAULT_PAGE_SIZE) + 1; page++) {
beforeMembers.addAll(userLogic().search(searchCond, page, AnyDAO.DEFAULT_PAGE_SIZE, Collections.<OrderByClause>emptyList(), SyncopeConstants.ROOT_REALM, false).getRight().stream().map(EntityTO::getKey).collect(Collectors.toSet()));
}
// update group, don't change members
ProvisioningResult<GroupTO> result = groupLogic().update(AnyOperations.diff(binder().toGroupTO(group), groupLogic().read(id), false), false);
// assign new members
Set<String> afterMembers = new HashSet<>();
group.getMembers().forEach(member -> {
afterMembers.add(member.getValue());
if (!beforeMembers.contains(member.getValue())) {
UserPatch patch = new UserPatch();
patch.setKey(member.getValue());
patch.getMemberships().add(new MembershipPatch.Builder().operation(PatchOperation.ADD_REPLACE).group(result.getEntity().getKey()).build());
try {
userLogic().update(patch, false);
} catch (Exception e) {
LOG.error("While setting membership of {} to {}", result.getEntity().getKey(), member.getValue(), e);
}
}
});
// remove unconfirmed members
beforeMembers.stream().filter(member -> !afterMembers.contains(member)).forEach(user -> {
UserPatch patch = new UserPatch();
patch.setKey(user);
patch.getMemberships().add(new MembershipPatch.Builder().operation(PatchOperation.DELETE).group(result.getEntity().getKey()).build());
try {
userLogic().update(patch, false);
} catch (Exception e) {
LOG.error("While removing membership of {} from {}", result.getEntity().getKey(), user, e);
}
});
return updateResponse(result.getEntity().getKey(), binder().toSCIMGroup(result.getEntity(), uriInfo.getAbsolutePathBuilder().path(result.getEntity().getKey()).build().toASCIIString(), Collections.<String>emptyList(), Collections.<String>emptyList()));
}
Aggregations