Search in sources :

Example 1 with Entity

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);
    }
}
Also used : ProvidedKeyEntity(org.apache.syncope.core.persistence.api.entity.ProvidedKeyEntity) Entity(org.apache.syncope.core.persistence.api.entity.Entity) AnnotatedEntity(org.apache.syncope.core.persistence.api.entity.AnnotatedEntity) ProvidedKeyEntity(org.apache.syncope.core.persistence.api.entity.ProvidedKeyEntity) Task(org.apache.syncope.core.persistence.api.entity.task.Task) GroupableRelatable(org.apache.syncope.core.persistence.api.entity.GroupableRelatable) DynMembership(org.apache.syncope.core.persistence.api.entity.DynMembership) ConstraintViolation(javax.validation.ConstraintViolation) Validator(javax.validation.Validator) InvalidEntityException(org.apache.syncope.core.persistence.api.attrvalue.validation.InvalidEntityException) PrePersist(javax.persistence.PrePersist) PreUpdate(javax.persistence.PreUpdate)

Example 2 with Entity

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;
}
Also used : Entity(org.apache.syncope.core.persistence.api.entity.Entity) Attribute(org.identityconnectors.framework.common.objects.Attribute) ItemTransformer(org.apache.syncope.core.provisioning.api.data.ItemTransformer) ArrayList(java.util.ArrayList) ConnectorObject(org.identityconnectors.framework.common.objects.ConnectorObject) AnyObject(org.apache.syncope.core.persistence.api.entity.anyobject.AnyObject) Realm(org.apache.syncope.core.persistence.api.entity.Realm)

Example 3 with Entity

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;
}
Also used : SyncopeClientException(org.apache.syncope.common.lib.SyncopeClientException) TaskTO(org.apache.syncope.common.lib.to.TaskTO) LoggerFactory(org.slf4j.LoggerFactory) AnyType(org.apache.syncope.core.persistence.api.entity.AnyType) Autowired(org.springframework.beans.factory.annotation.Autowired) NotificationTask(org.apache.syncope.core.persistence.api.entity.task.NotificationTask) Entity(org.apache.syncope.core.persistence.api.entity.Entity) StringUtils(org.apache.commons.lang3.StringUtils) PropagationTask(org.apache.syncope.core.persistence.api.entity.task.PropagationTask) Scheduler(org.quartz.Scheduler) PropagationTaskTO(org.apache.syncope.common.lib.to.PropagationTaskTO) SchedTaskTO(org.apache.syncope.common.lib.to.SchedTaskTO) ProvisioningTaskTO(org.apache.syncope.common.lib.to.ProvisioningTaskTO) TaskExecDAO(org.apache.syncope.core.persistence.api.dao.TaskExecDAO) SchedulerFactoryBean(org.springframework.scheduling.quartz.SchedulerFactoryBean) ImplementationDAO(org.apache.syncope.core.persistence.api.dao.ImplementationDAO) NotificationTaskTO(org.apache.syncope.common.lib.to.NotificationTaskTO) PullJobDelegate(org.apache.syncope.core.provisioning.java.pushpull.PullJobDelegate) ExecTO(org.apache.syncope.common.lib.to.ExecTO) Task(org.apache.syncope.core.persistence.api.entity.task.Task) JobNamer(org.apache.syncope.core.provisioning.api.job.JobNamer) Implementation(org.apache.syncope.core.persistence.api.entity.Implementation) Collectors(java.util.stream.Collectors) UnmatchingRule(org.apache.syncope.common.lib.types.UnmatchingRule) NotFoundException(org.apache.syncope.core.persistence.api.dao.NotFoundException) AnyTypeDAO(org.apache.syncope.core.persistence.api.dao.AnyTypeDAO) ImplementationEngine(org.apache.syncope.common.lib.types.ImplementationEngine) EntityFactory(org.apache.syncope.core.persistence.api.entity.EntityFactory) AnyTemplatePullTask(org.apache.syncope.core.persistence.api.entity.task.AnyTemplatePullTask) TaskUtilsFactory(org.apache.syncope.core.persistence.api.entity.task.TaskUtilsFactory) ProvisioningTask(org.apache.syncope.core.persistence.api.entity.task.ProvisioningTask) TriggerKey(org.quartz.TriggerKey) ExternalResourceDAO(org.apache.syncope.core.persistence.api.dao.ExternalResourceDAO) TaskDataBinder(org.apache.syncope.core.provisioning.api.data.TaskDataBinder) BeanUtils(org.apache.syncope.core.spring.BeanUtils) PullTask(org.apache.syncope.core.persistence.api.entity.task.PullTask) SchedulerException(org.quartz.SchedulerException) Trigger(org.quartz.Trigger) ImplementationType(org.apache.syncope.common.lib.types.ImplementationType) TaskExec(org.apache.syncope.core.persistence.api.entity.task.TaskExec) ClientExceptionType(org.apache.syncope.common.lib.types.ClientExceptionType) SchedTask(org.apache.syncope.core.persistence.api.entity.task.SchedTask) RealmDAO(org.apache.syncope.core.persistence.api.dao.RealmDAO) TemplateUtils(org.apache.syncope.core.provisioning.java.utils.TemplateUtils) PushJobDelegate(org.apache.syncope.core.provisioning.java.pushpull.PushJobDelegate) PushTaskTO(org.apache.syncope.common.lib.to.PushTaskTO) Logger(org.slf4j.Logger) PushTaskAnyFilter(org.apache.syncope.core.persistence.api.entity.task.PushTaskAnyFilter) TaskUtils(org.apache.syncope.core.persistence.api.entity.task.TaskUtils) ExternalResource(org.apache.syncope.core.persistence.api.entity.resource.ExternalResource) PushTask(org.apache.syncope.core.persistence.api.entity.task.PushTask) Component(org.springframework.stereotype.Component) PullTaskTO(org.apache.syncope.common.lib.to.PullTaskTO) JobType(org.apache.syncope.common.lib.types.JobType) MatchingRule(org.apache.syncope.common.lib.types.MatchingRule) TaskType(org.apache.syncope.common.lib.types.TaskType) Entity(org.apache.syncope.core.persistence.api.entity.Entity) NotificationTask(org.apache.syncope.core.persistence.api.entity.task.NotificationTask) PropagationTask(org.apache.syncope.core.persistence.api.entity.task.PropagationTask) PropagationTaskTO(org.apache.syncope.common.lib.to.PropagationTaskTO) PushTask(org.apache.syncope.core.persistence.api.entity.task.PushTask) SchedTask(org.apache.syncope.core.persistence.api.entity.task.SchedTask) SchedTaskTO(org.apache.syncope.common.lib.to.SchedTaskTO) AnyTemplatePullTask(org.apache.syncope.core.persistence.api.entity.task.AnyTemplatePullTask) PullTask(org.apache.syncope.core.persistence.api.entity.task.PullTask) TaskExec(org.apache.syncope.core.persistence.api.entity.task.TaskExec) PushTaskTO(org.apache.syncope.common.lib.to.PushTaskTO) PullTaskTO(org.apache.syncope.common.lib.to.PullTaskTO) NotificationTaskTO(org.apache.syncope.common.lib.to.NotificationTaskTO)

Example 4 with Entity

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;
}
Also used : Entity(org.apache.syncope.core.persistence.api.entity.Entity) AnyTypeClassTO(org.apache.syncope.common.lib.to.AnyTypeClassTO)

Example 5 with Entity

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;
}
Also used : TriggerKey(org.quartz.TriggerKey) Entity(org.apache.syncope.core.persistence.api.entity.Entity) Trigger(org.quartz.Trigger) SchedulerException(org.quartz.SchedulerException) ReportTO(org.apache.syncope.common.lib.to.ReportTO) ReportExec(org.apache.syncope.core.persistence.api.entity.ReportExec)

Aggregations

Entity (org.apache.syncope.core.persistence.api.entity.Entity)17 Collectors (java.util.stream.Collectors)5 SyncopeClientException (org.apache.syncope.common.lib.SyncopeClientException)5 ExternalResource (org.apache.syncope.core.persistence.api.entity.resource.ExternalResource)5 Autowired (org.springframework.beans.factory.annotation.Autowired)5 List (java.util.List)4 AnyTypeDAO (org.apache.syncope.core.persistence.api.dao.AnyTypeDAO)4 Realm (org.apache.syncope.core.persistence.api.entity.Realm)4 Collections (java.util.Collections)3 HashSet (java.util.HashSet)3 Set (java.util.Set)3 User (org.apache.syncope.core.persistence.api.entity.user.User)3 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)3 Transactional (org.springframework.transaction.annotation.Transactional)3 ArrayList (java.util.ArrayList)2 Date (java.util.Date)2 StringUtils (org.apache.commons.lang3.StringUtils)2 SyncopeClientCompositeException (org.apache.syncope.common.lib.SyncopeClientCompositeException)2 AnyTypeClassTO (org.apache.syncope.common.lib.to.AnyTypeClassTO)2 ClientExceptionType (org.apache.syncope.common.lib.types.ClientExceptionType)2