use of org.apache.syncope.core.persistence.api.entity.anyobject.AnyObject in project syncope by apache.
the class AbstractAnySearchDAO method check.
protected String check(final RelationshipCond cond) {
String rightAnyObjectKey;
if (SyncopeConstants.UUID_PATTERN.matcher(cond.getAnyObject()).matches()) {
rightAnyObjectKey = cond.getAnyObject();
} else {
AnyObject anyObject = anyObjectDAO.findByName(cond.getAnyObject());
rightAnyObjectKey = anyObject == null ? null : anyObject.getKey();
}
if (rightAnyObjectKey == null) {
LOG.error("Could not find any object for '" + cond.getAnyObject() + "'");
throw new IllegalArgumentException();
}
return rightAnyObjectKey;
}
use of org.apache.syncope.core.persistence.api.entity.anyobject.AnyObject in project syncope by apache.
the class JPAAnyObjectDAO method doSave.
private Pair<AnyObject, Pair<Set<String>, Set<String>>> doSave(final AnyObject anyObject) {
AnyObject merged = super.save(anyObject);
publisher.publishEvent(new AnyCreatedUpdatedEvent<>(this, merged, AuthContextUtils.getDomain()));
Pair<Set<String>, Set<String>> dynGroupMembs = groupDAO().refreshDynMemberships(merged);
dynRealmDAO().refreshDynMemberships(merged);
return Pair.of(merged, dynGroupMembs);
}
use of org.apache.syncope.core.persistence.api.entity.anyobject.AnyObject in project syncope by apache.
the class GroupTest method findDynGroups.
/**
* Static copy of {@link org.apache.syncope.core.persistence.jpa.dao.JPAAnyObjectDAO} method with same signature:
* required for avoiding creating of a new transaction - good for general use case but bad for the way how
* this test class is architected.
*/
@SuppressWarnings("unchecked")
public List<Group> findDynGroups(final AnyObject anyObject) {
Query query = entityManager().createNativeQuery("SELECT group_id FROM " + JPAGroupDAO.ADYNMEMB_TABLE + " WHERE any_id=?");
query.setParameter(1, anyObject.getKey());
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) {
} else if (!result.contains(group)) {
result.add(group);
}
});
return result;
}
use of org.apache.syncope.core.persistence.api.entity.anyobject.AnyObject in project syncope by apache.
the class AnySearchTest method searchByType.
@Test
public void searchByType() {
AnyTypeCond tcond = new AnyTypeCond();
tcond.setAnyTypeKey("PRINTER");
SearchCond searchCondition = SearchCond.getLeafCond(tcond);
assertTrue(searchCondition.isValid());
List<AnyObject> printers = searchDAO.search(searchCondition, AnyTypeKind.ANY_OBJECT);
assertNotNull(printers);
assertEquals(3, printers.size());
tcond.setAnyTypeKey("UNEXISTING");
printers = searchDAO.search(searchCondition, AnyTypeKind.ANY_OBJECT);
assertNotNull(printers);
assertTrue(printers.isEmpty());
}
use of org.apache.syncope.core.persistence.api.entity.anyobject.AnyObject in project syncope by apache.
the class AnySearchTest method anyObjectMatch.
@Test
public void anyObjectMatch() {
AnyObject anyObject = anyObjectDAO.find("fc6dbc3a-6c07-4965-8781-921e7401a4a5");
assertNotNull(anyObject);
RelationshipCond relationshipCond = new RelationshipCond();
relationshipCond.setAnyObject("Canon MF 8030cn");
assertTrue(searchDAO.matches(anyObject, SearchCond.getLeafCond(relationshipCond)));
RelationshipTypeCond relationshipTypeCond = new RelationshipTypeCond();
relationshipTypeCond.setRelationshipTypeKey("neighborhood");
assertTrue(searchDAO.matches(anyObject, SearchCond.getLeafCond(relationshipTypeCond)));
}
Aggregations