use of org.apache.syncope.core.persistence.api.entity.anyobject.AnyObject in project syncope by apache.
the class JPAGroupDAO method save.
@Override
public Group save(final Group group) {
Group merged = super.save(group);
publisher.publishEvent(new AnyCreatedUpdatedEvent<>(this, merged, AuthContextUtils.getDomain()));
// refresh dynamic memberships
clearUDynMembers(merged);
if (merged.getUDynMembership() != null) {
SearchCond cond = buildDynMembershipCond(merged.getUDynMembership().getFIQLCond(), merged.getRealm());
int count = searchDAO().count(Collections.<String>singleton(merged.getRealm().getFullPath()), cond, AnyTypeKind.USER);
for (int page = 1; page <= (count / AnyDAO.DEFAULT_PAGE_SIZE) + 1; page++) {
List<User> matching = searchDAO().search(Collections.<String>singleton(merged.getRealm().getFullPath()), cond, page, AnyDAO.DEFAULT_PAGE_SIZE, Collections.<OrderByClause>emptyList(), AnyTypeKind.USER);
matching.forEach(user -> {
Query insert = entityManager().createNativeQuery("INSERT INTO " + UDYNMEMB_TABLE + " VALUES(?, ?)");
insert.setParameter(1, user.getKey());
insert.setParameter(2, merged.getKey());
insert.executeUpdate();
publisher.publishEvent(new AnyCreatedUpdatedEvent<>(this, user, AuthContextUtils.getDomain()));
});
}
}
clearADynMembers(merged);
merged.getADynMemberships().stream().forEach(memb -> {
SearchCond cond = buildDynMembershipCond(memb.getFIQLCond(), merged.getRealm());
int count = searchDAO().count(Collections.<String>singleton(merged.getRealm().getFullPath()), cond, AnyTypeKind.ANY_OBJECT);
for (int page = 1; page <= (count / AnyDAO.DEFAULT_PAGE_SIZE) + 1; page++) {
List<AnyObject> matching = searchDAO().search(Collections.<String>singleton(merged.getRealm().getFullPath()), cond, page, AnyDAO.DEFAULT_PAGE_SIZE, Collections.<OrderByClause>emptyList(), AnyTypeKind.ANY_OBJECT);
matching.forEach(anyObject -> {
Query insert = entityManager().createNativeQuery("INSERT INTO " + ADYNMEMB_TABLE + " VALUES(?, ?, ?)");
insert.setParameter(1, anyObject.getType().getKey());
insert.setParameter(2, anyObject.getKey());
insert.setParameter(3, merged.getKey());
insert.executeUpdate();
publisher.publishEvent(new AnyCreatedUpdatedEvent<>(this, anyObject, AuthContextUtils.getDomain()));
});
}
});
dynRealmDAO().refreshDynMemberships(merged);
return merged;
}
use of org.apache.syncope.core.persistence.api.entity.anyobject.AnyObject in project syncope by apache.
the class JPAGroupDAO method delete.
@Override
public void delete(final Group group) {
dynRealmDAO().removeDynMemberships(group.getKey());
findAMemberships(group).forEach(membership -> {
AnyObject leftEnd = membership.getLeftEnd();
leftEnd.getMemberships().remove(membership);
membership.setRightEnd(null);
leftEnd.getPlainAttrs(membership).stream().map(attr -> {
leftEnd.remove(attr);
attr.setOwner(null);
attr.setMembership(null);
return attr;
}).forEachOrdered(attr -> plainAttrDAO.delete(attr));
anyObjectDAO().save(leftEnd);
publisher.publishEvent(new AnyCreatedUpdatedEvent<>(this, leftEnd, AuthContextUtils.getDomain()));
});
findUMemberships(group).forEach(membership -> {
User leftEnd = membership.getLeftEnd();
leftEnd.getMemberships().remove(membership);
membership.setRightEnd(null);
leftEnd.getPlainAttrs(membership).stream().map(attr -> {
leftEnd.remove(attr);
attr.setOwner(null);
attr.setMembership(null);
return attr;
}).forEachOrdered(attr -> plainAttrDAO.delete(attr));
userDAO().save(leftEnd);
publisher.publishEvent(new AnyCreatedUpdatedEvent<>(this, leftEnd, AuthContextUtils.getDomain()));
});
clearUDynMembers(group);
clearADynMembers(group);
entityManager().remove(group);
publisher.publishEvent(new AnyDeletedEvent(this, AnyTypeKind.GROUP, group.getKey(), AuthContextUtils.getDomain()));
}
use of org.apache.syncope.core.persistence.api.entity.anyobject.AnyObject in project syncope by apache.
the class NotificationManagerImpl method createTasks.
@Override
public List<NotificationTask> createTasks(final AuditElements.EventCategoryType type, final String category, final String subcategory, final String event, final Result condition, final Object before, final Object output, final Object... input) {
Any<?> any = null;
if (before instanceof UserTO) {
any = userDAO.find(((UserTO) before).getKey());
} else if (output instanceof UserTO) {
any = userDAO.find(((UserTO) output).getKey());
} else if (output instanceof Pair && ((Pair) output).getRight() instanceof UserTO) {
any = userDAO.find(((UserTO) ((Pair) output).getRight()).getKey());
} else if (output instanceof ProvisioningResult && ((ProvisioningResult) output).getEntity() instanceof UserTO) {
any = userDAO.find(((ProvisioningResult) output).getEntity().getKey());
} else if (before instanceof AnyObjectTO) {
any = anyObjectDAO.find(((AnyObjectTO) before).getKey());
} else if (output instanceof AnyObjectTO) {
any = anyObjectDAO.find(((AnyObjectTO) output).getKey());
} else if (output instanceof ProvisioningResult && ((ProvisioningResult) output).getEntity() instanceof AnyObjectTO) {
any = anyObjectDAO.find(((ProvisioningResult) output).getEntity().getKey());
} else if (before instanceof GroupTO) {
any = groupDAO.find(((GroupTO) before).getKey());
} else if (output instanceof GroupTO) {
any = groupDAO.find(((GroupTO) output).getKey());
} else if (output instanceof ProvisioningResult && ((ProvisioningResult) output).getEntity() instanceof GroupTO) {
any = groupDAO.find(((ProvisioningResult) output).getEntity().getKey());
}
AnyType anyType = any == null ? null : any.getType();
LOG.debug("Search notification for [{}]{}", anyType, any);
List<NotificationTask> notifications = new ArrayList<>();
for (Notification notification : notificationDAO.findAll()) {
if (LOG.isDebugEnabled()) {
notification.getAbouts().forEach(about -> {
LOG.debug("Notification about {} defined: {}", about.getAnyType(), about.get());
});
}
if (notification.isActive()) {
String currentEvent = AuditLoggerName.buildEvent(type, category, subcategory, event, condition);
if (!notification.getEvents().contains(currentEvent)) {
LOG.debug("No events found about {}", any);
} else if (anyType == null || any == null || !notification.getAbout(anyType).isPresent() || searchDAO.matches(any, SearchCondConverter.convert(notification.getAbout(anyType).get().get()))) {
LOG.debug("Creating notification task for event {} about {}", currentEvent, any);
final Map<String, Object> model = new HashMap<>();
model.put("type", type);
model.put("category", category);
model.put("subcategory", subcategory);
model.put("event", event);
model.put("condition", condition);
model.put("before", before);
model.put("output", output);
model.put("input", input);
if (any instanceof User) {
model.put("user", userDataBinder.getUserTO((User) any, true));
} else if (any instanceof Group) {
model.put("group", groupDataBinder.getGroupTO((Group) any, true));
} else if (any instanceof AnyObject) {
model.put("group", anyObjectDataBinder.getAnyObjectTO((AnyObject) any, true));
}
NotificationTask notificationTask = getNotificationTask(notification, any, model);
notificationTask = taskDAO.save(notificationTask);
notifications.add(notificationTask);
}
} else {
LOG.debug("Notification {} is not active, task will not be created", notification.getKey());
}
}
return notifications;
}
use of org.apache.syncope.core.persistence.api.entity.anyobject.AnyObject in project syncope by apache.
the class AbstractPushResultHandler method update.
protected void update(final Any<?> any, final ProvisioningReport result) {
boolean changepwd;
Collection<String> resourceKeys;
if (any instanceof User) {
changepwd = true;
resourceKeys = userDAO.findAllResourceKeys(any.getKey());
} else if (any instanceof AnyObject) {
changepwd = false;
resourceKeys = anyObjectDAO.findAllResourceKeys(any.getKey());
} else {
changepwd = false;
resourceKeys = groupDAO.findAllResourceKeys(any.getKey());
}
List<String> noPropResources = new ArrayList<>(resourceKeys);
noPropResources.remove(profile.getTask().getResource().getKey());
PropagationByResource propByRes = new PropagationByResource();
propByRes.add(ResourceOperation.CREATE, profile.getTask().getResource().getKey());
PropagationReporter reporter = taskExecutor.execute(propagationManager.getUpdateTasks(any.getType().getKind(), any.getKey(), changepwd, null, propByRes, null, noPropResources), false);
reportPropagation(result, reporter);
}
use of org.apache.syncope.core.persistence.api.entity.anyobject.AnyObject in project syncope by apache.
the class PullUtils method findByConnObjectKey.
private List<String> findByConnObjectKey(final ConnectorObject connObj, final Provision provision, final AnyUtils anyUtils) {
String connObjectKey = null;
Optional<MappingItem> connObjectKeyItem = MappingUtils.getConnObjectKeyItem(provision);
if (connObjectKeyItem.isPresent()) {
Attribute connObjectKeyAttr = connObj.getAttributeByName(connObjectKeyItem.get().getExtAttrName());
if (connObjectKeyAttr != null) {
connObjectKey = AttributeUtil.getStringValue(connObjectKeyAttr);
}
}
if (connObjectKey == null) {
return Collections.emptyList();
}
for (ItemTransformer transformer : MappingUtils.getItemTransformers(connObjectKeyItem.get())) {
List<Object> output = transformer.beforePull(connObjectKeyItem.get(), null, Collections.<Object>singletonList(connObjectKey));
if (output != null && !output.isEmpty()) {
connObjectKey = output.get(0).toString();
}
}
List<String> result = new ArrayList<>();
IntAttrName intAttrName;
try {
intAttrName = intAttrNameParser.parse(connObjectKeyItem.get().getIntAttrName(), provision.getAnyType().getKind());
} catch (ParseException e) {
LOG.error("Invalid intAttrName '{}' specified, ignoring", connObjectKeyItem.get().getIntAttrName(), e);
return result;
}
if (intAttrName.getField() != null) {
switch(intAttrName.getField()) {
case "key":
Any<?> any = getAnyDAO(provision.getAnyType().getKind()).find(connObjectKey);
if (any != null) {
result.add(any.getKey());
}
break;
case "username":
User user = userDAO.findByUsername(connObjectKey);
if (user != null) {
result.add(user.getKey());
}
break;
case "name":
Group group = groupDAO.findByName(connObjectKey);
if (group != null) {
result.add(group.getKey());
}
AnyObject anyObject = anyObjectDAO.findByName(connObjectKey);
if (anyObject != null) {
result.add(anyObject.getKey());
}
break;
default:
}
} else if (intAttrName.getSchemaType() != null) {
switch(intAttrName.getSchemaType()) {
case PLAIN:
PlainAttrValue value = anyUtils.newPlainAttrValue();
PlainSchema schema = plainSchemaDAO.find(intAttrName.getSchemaName());
if (schema == null) {
value.setStringValue(connObjectKey);
} else {
try {
value.parseValue(schema, connObjectKey);
} catch (ParsingValidationException e) {
LOG.error("While parsing provided __UID__ {}", value, e);
value.setStringValue(connObjectKey);
}
}
result.addAll(getAnyDAO(provision.getAnyType().getKind()).findByPlainAttrValue(intAttrName.getSchemaName(), value).stream().map(Entity::getKey).collect(Collectors.toList()));
break;
case DERIVED:
result.addAll(getAnyDAO(provision.getAnyType().getKind()).findByDerAttrValue(intAttrName.getSchemaName(), connObjectKey).stream().map(Entity::getKey).collect(Collectors.toList()));
break;
default:
}
}
return result;
}
Aggregations