use of org.apache.syncope.core.persistence.api.entity.Entity in project syncope by apache.
the class EntityValidationListener method validate.
@PrePersist
@PreUpdate
public void validate(final Object object) {
final Validator validator = ApplicationContextProvider.getBeanFactory().getBean(Validator.class);
Set<ConstraintViolation<Object>> violations = validator.validate(object);
if (!violations.isEmpty()) {
LOG.warn("Bean validation errors found: {}", violations);
Class<?> entityInt = null;
for (Class<?> interf : ClassUtils.getAllInterfaces(object.getClass())) {
if (!Entity.class.equals(interf) && !AnnotatedEntity.class.equals(interf) && !ProvidedKeyEntity.class.equals(interf) && !Schema.class.equals(interf) && !Task.class.equals(interf) && !Policy.class.equals(interf) && !GroupableRelatable.class.equals(interf) && !Any.class.equals(interf) && !DynMembership.class.equals(interf) && Entity.class.isAssignableFrom(interf)) {
entityInt = interf;
}
}
throw new InvalidEntityException(entityInt == null ? "Entity" : entityInt.getSimpleName(), violations);
}
}
use of org.apache.syncope.core.persistence.api.entity.Entity in project syncope by apache.
the class PullUtils method match.
/**
* Finds internal realms based on external attributes and mapping.
*
* @param connObj external attributes
* @param orgUnit mapping
* @return list of matching realms' keys.
*/
public List<String> match(final ConnectorObject connObj, final OrgUnit orgUnit) {
String connObjectKey = null;
Optional<? extends OrgUnitItem> connObjectKeyItem = orgUnit.getConnObjectKeyItem();
if (connObjectKeyItem != null) {
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<>();
Realm realm;
switch(connObjectKeyItem.get().getIntAttrName()) {
case "key":
realm = realmDAO.find(connObjectKey);
if (realm != null) {
result.add(realm.getKey());
}
break;
case "name":
result.addAll(realmDAO.findByName(connObjectKey).stream().map(Entity::getKey).collect(Collectors.toList()));
break;
case "fullpath":
realm = realmDAO.findByFullPath(connObjectKey);
if (realm != null) {
result.add(realm.getKey());
}
break;
default:
}
return result;
}
use of org.apache.syncope.core.persistence.api.entity.Entity in project syncope by apache.
the class TaskDataBinderImpl method getTaskTO.
@Override
public <T extends TaskTO> T getTaskTO(final Task task, final TaskUtils taskUtils, final boolean details) {
T taskTO = taskUtils.newTaskTO();
BeanUtils.copyProperties(task, taskTO, IGNORE_TASK_PROPERTIES);
TaskExec latestExec = taskExecDAO.findLatestStarted(task);
if (latestExec == null) {
taskTO.setLatestExecStatus(StringUtils.EMPTY);
} else {
taskTO.setLatestExecStatus(latestExec.getStatus());
taskTO.setStart(latestExec.getStart());
taskTO.setEnd(latestExec.getEnd());
}
if (details) {
task.getExecs().stream().filter(execution -> execution != null).forEachOrdered(execution -> taskTO.getExecutions().add(getExecTO(execution)));
}
switch(taskUtils.getType()) {
case PROPAGATION:
PropagationTask propagationTask = (PropagationTask) task;
PropagationTaskTO propagationTaskTO = (PropagationTaskTO) taskTO;
propagationTaskTO.setAnyTypeKind(propagationTask.getAnyTypeKind());
propagationTaskTO.setEntityKey(propagationTask.getEntityKey());
propagationTaskTO.setResource(propagationTask.getResource().getKey());
propagationTaskTO.setAttributes(propagationTask.getSerializedAttributes());
break;
case SCHEDULED:
SchedTask schedTask = (SchedTask) task;
SchedTaskTO schedTaskTO = (SchedTaskTO) taskTO;
setExecTime(schedTaskTO, task);
if (schedTask.getJobDelegate() != null) {
schedTaskTO.setJobDelegate(schedTask.getJobDelegate().getKey());
}
break;
case PULL:
PullTask pullTask = (PullTask) task;
PullTaskTO pullTaskTO = (PullTaskTO) taskTO;
setExecTime(pullTaskTO, task);
pullTaskTO.setDestinationRealm(pullTask.getDestinatioRealm().getFullPath());
pullTaskTO.setResource(pullTask.getResource().getKey());
pullTaskTO.setMatchingRule(pullTask.getMatchingRule() == null ? MatchingRule.UPDATE : pullTask.getMatchingRule());
pullTaskTO.setUnmatchingRule(pullTask.getUnmatchingRule() == null ? UnmatchingRule.PROVISION : pullTask.getUnmatchingRule());
if (pullTask.getReconFilterBuilder() != null) {
pullTaskTO.setReconFilterBuilder(pullTask.getReconFilterBuilder().getKey());
}
pullTaskTO.getActions().addAll(pullTask.getActions().stream().map(Entity::getKey).collect(Collectors.toList()));
pullTask.getTemplates().forEach(template -> {
pullTaskTO.getTemplates().put(template.getAnyType().getKey(), template.get());
});
pullTaskTO.setRemediation(pullTask.isRemediation());
break;
case PUSH:
PushTask pushTask = (PushTask) task;
PushTaskTO pushTaskTO = (PushTaskTO) taskTO;
setExecTime(pushTaskTO, task);
pushTaskTO.setSourceRealm(pushTask.getSourceRealm().getFullPath());
pushTaskTO.setResource(pushTask.getResource().getKey());
pushTaskTO.setMatchingRule(pushTask.getMatchingRule() == null ? MatchingRule.LINK : pushTask.getMatchingRule());
pushTaskTO.setUnmatchingRule(pushTask.getUnmatchingRule() == null ? UnmatchingRule.ASSIGN : pushTask.getUnmatchingRule());
pushTaskTO.getActions().addAll(pushTask.getActions().stream().map(Entity::getKey).collect(Collectors.toList()));
pushTask.getFilters().forEach(filter -> {
pushTaskTO.getFilters().put(filter.getAnyType().getKey(), filter.getFIQLCond());
});
break;
case NOTIFICATION:
NotificationTask notificationTask = (NotificationTask) task;
NotificationTaskTO notificationTaskTO = (NotificationTaskTO) taskTO;
notificationTaskTO.setNotification(notificationTask.getNotification().getKey());
notificationTaskTO.setAnyTypeKind(notificationTask.getAnyTypeKind());
notificationTaskTO.setEntityKey(notificationTask.getEntityKey());
if (notificationTask.isExecuted() && StringUtils.isBlank(taskTO.getLatestExecStatus())) {
taskTO.setLatestExecStatus("[EXECUTED]");
}
break;
default:
}
return taskTO;
}
use of org.apache.syncope.core.persistence.api.entity.Entity in project syncope by apache.
the class AnyTypeClassDataBinderImpl method getAnyTypeClassTO.
@Override
public AnyTypeClassTO getAnyTypeClassTO(final AnyTypeClass anyTypeClass) {
AnyTypeClassTO anyTypeClassTO = new AnyTypeClassTO();
anyTypeClassTO.setKey(anyTypeClass.getKey());
anyTypeClassTO.getInUseByTypes().addAll(anyTypeDAO.findByTypeClass(anyTypeClass).stream().map(Entity::getKey).collect(Collectors.toList()));
anyTypeClassTO.getPlainSchemas().addAll(anyTypeClass.getPlainSchemas().stream().map(Entity::getKey).collect(Collectors.toList()));
anyTypeClassTO.getDerSchemas().addAll(anyTypeClass.getDerSchemas().stream().map(Entity::getKey).collect(Collectors.toList()));
anyTypeClassTO.getVirSchemas().addAll(anyTypeClass.getVirSchemas().stream().map(Entity::getKey).collect(Collectors.toList()));
return anyTypeClassTO;
}
use of org.apache.syncope.core.persistence.api.entity.Entity in project syncope by apache.
the class ReportDataBinderImpl method getReportTO.
@Override
public ReportTO getReportTO(final Report report) {
ReportTO reportTO = new ReportTO();
reportTO.setKey(report.getKey());
reportTO.setTemplate(report.getTemplate().getKey());
BeanUtils.copyProperties(report, reportTO, IGNORE_REPORT_PROPERTIES);
reportTO.getReportlets().addAll(report.getReportlets().stream().map(Entity::getKey).collect(Collectors.toList()));
ReportExec latestExec = reportExecDAO.findLatestStarted(report);
if (latestExec == null) {
reportTO.setLatestExecStatus(StringUtils.EMPTY);
} else {
reportTO.setLatestExecStatus(latestExec.getStatus());
reportTO.setStart(latestExec.getStart());
reportTO.setEnd(latestExec.getEnd());
reportTO.setLastExec(reportTO.getStart());
}
reportTO.getExecutions().addAll(report.getExecs().stream().map(reportExec -> getExecTO(reportExec)).collect(Collectors.toList()));
String triggerName = JobNamer.getTriggerName(JobNamer.getJobKey(report).getName());
try {
Trigger trigger = scheduler.getScheduler().getTrigger(new TriggerKey(triggerName, Scheduler.DEFAULT_GROUP));
if (trigger != null) {
reportTO.setLastExec(trigger.getPreviousFireTime());
reportTO.setNextExec(trigger.getNextFireTime());
}
} catch (SchedulerException e) {
LOG.warn("While trying to get to " + triggerName, e);
}
return reportTO;
}
Aggregations