Search in sources :

Example 96 with NotFoundException

use of org.apache.syncope.core.persistence.api.dao.NotFoundException in project syncope by apache.

the class GroupLogic method bulkMembersAction.

@PreAuthorize("hasRole('" + StandardEntitlement.TASK_CREATE + "') " + "and hasRole('" + StandardEntitlement.TASK_EXECUTE + "')")
@Transactional
public ExecTO bulkMembersAction(final String key, final BulkMembersActionType actionType) {
    Group group = groupDAO.find(key);
    if (group == null) {
        throw new NotFoundException("Group " + key);
    }
    Implementation jobDelegate = implementationDAO.find(ImplementationType.TASKJOB_DELEGATE).stream().filter(impl -> GroupMemberProvisionTaskJobDelegate.class.getName().equals(impl.getBody())).findFirst().orElse(null);
    if (jobDelegate == null) {
        jobDelegate = entityFactory.newEntity(Implementation.class);
        jobDelegate.setKey(GroupMemberProvisionTaskJobDelegate.class.getSimpleName());
        jobDelegate.setEngine(ImplementationEngine.JAVA);
        jobDelegate.setType(ImplementationType.TASKJOB_DELEGATE);
        jobDelegate.setBody(GroupMemberProvisionTaskJobDelegate.class.getName());
        jobDelegate = implementationDAO.save(jobDelegate);
    }
    SchedTask task = entityFactory.newEntity(SchedTask.class);
    task.setName("Bulk member provision for group " + group.getName());
    task.setActive(true);
    task.setJobDelegate(jobDelegate);
    task = taskDAO.save(task);
    try {
        Map<String, Object> jobDataMap = jobManager.register(task, null, confDAO.find("tasks.interruptMaxRetries", 1L));
        jobDataMap.put(TaskJob.DRY_RUN_JOBDETAIL_KEY, false);
        jobDataMap.put(GroupMemberProvisionTaskJobDelegate.GROUP_KEY_JOBDETAIL_KEY, key);
        jobDataMap.put(GroupMemberProvisionTaskJobDelegate.ACTION_TYPE_JOBDETAIL_KEY, actionType);
        scheduler.getScheduler().triggerJob(JobNamer.getJobKey(task), new JobDataMap(jobDataMap));
    } catch (Exception e) {
        LOG.error("While executing task {}", task, e);
        SyncopeClientException sce = SyncopeClientException.build(ClientExceptionType.Scheduling);
        sce.getElements().add(e.getMessage());
        throw sce;
    }
    ExecTO result = new ExecTO();
    result.setJobType(JobType.TASK);
    result.setRefKey(task.getKey());
    result.setRefDesc(taskDataBinder.buildRefDesc(task));
    result.setStart(new Date());
    result.setStatus("JOB_FIRED");
    result.setMessage("Job fired; waiting for results...");
    return result;
}
Also used : Group(org.apache.syncope.core.persistence.api.entity.group.Group) JobDataMap(org.quartz.JobDataMap) ExecTO(org.apache.syncope.common.lib.to.ExecTO) SyncopeClientException(org.apache.syncope.common.lib.SyncopeClientException) NotFoundException(org.apache.syncope.core.persistence.api.dao.NotFoundException) Implementation(org.apache.syncope.core.persistence.api.entity.Implementation) GroupMemberProvisionTaskJobDelegate(org.apache.syncope.core.provisioning.java.job.GroupMemberProvisionTaskJobDelegate) SyncopeClientException(org.apache.syncope.common.lib.SyncopeClientException) NotFoundException(org.apache.syncope.core.persistence.api.dao.NotFoundException) DelegatedAdministrationException(org.apache.syncope.core.spring.security.DelegatedAdministrationException) Date(java.util.Date) SchedTask(org.apache.syncope.core.persistence.api.entity.task.SchedTask) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) Transactional(org.springframework.transaction.annotation.Transactional)

Example 97 with NotFoundException

use of org.apache.syncope.core.persistence.api.dao.NotFoundException in project syncope by apache.

the class ImplementationLogic method read.

@PreAuthorize("hasRole('" + StandardEntitlement.IMPLEMENTATION_READ + "')")
@Transactional(readOnly = true)
public ImplementationTO read(final ImplementationType type, final String key) {
    Implementation implementation = implementationDAO.find(key);
    if (implementation == null) {
        LOG.error("Could not find implementation '" + key + "'");
        throw new NotFoundException(key);
    }
    if (implementation.getType() != type) {
        SyncopeClientException sce = SyncopeClientException.build(ClientExceptionType.InvalidRequest);
        sce.getElements().add("Found " + type + ", expected " + implementation.getType());
        throw sce;
    }
    return binder.getImplementationTO(implementation);
}
Also used : SyncopeClientException(org.apache.syncope.common.lib.SyncopeClientException) NotFoundException(org.apache.syncope.core.persistence.api.dao.NotFoundException) Implementation(org.apache.syncope.core.persistence.api.entity.Implementation) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) Transactional(org.springframework.transaction.annotation.Transactional)

Example 98 with NotFoundException

use of org.apache.syncope.core.persistence.api.dao.NotFoundException in project syncope by apache.

the class ImplementationLogic method delete.

@PreAuthorize("hasRole('" + StandardEntitlement.IMPLEMENTATION_DELETE + "')")
public void delete(final ImplementationType type, final String key) {
    Implementation implementation = implementationDAO.find(key);
    if (implementation == null) {
        LOG.error("Could not find implementation '" + key + "'");
        throw new NotFoundException(key);
    }
    if (implementation.getType() != type) {
        SyncopeClientException sce = SyncopeClientException.build(ClientExceptionType.InvalidRequest);
        sce.getElements().add("Found " + type + ", expected " + implementation.getType());
        throw sce;
    }
    boolean inUse = false;
    switch(implementation.getType()) {
        case REPORTLET:
            inUse = !reportDAO.findByReportlet(implementation).isEmpty();
            break;
        case ACCOUNT_RULE:
            inUse = !policyDAO.findByAccountRule(implementation).isEmpty();
            break;
        case PASSWORD_RULE:
            inUse = !policyDAO.findByPasswordRule(implementation).isEmpty();
            break;
        case ITEM_TRANSFORMER:
            inUse = !resourceDAO.findByTransformer(implementation).isEmpty();
            break;
        case TASKJOB_DELEGATE:
            inUse = !taskDAO.findByDelegate(implementation).isEmpty();
            break;
        case RECON_FILTER_BUILDER:
            inUse = !taskDAO.findByReconFilterBuilder(implementation).isEmpty();
            break;
        case LOGIC_ACTIONS:
            inUse = !realmDAO.findByLogicActions(implementation).isEmpty();
            break;
        case PROPAGATION_ACTIONS:
            inUse = !resourceDAO.findByPropagationActions(implementation).isEmpty();
            break;
        case PULL_ACTIONS:
            inUse = !taskDAO.findByPullActions(implementation).isEmpty();
            break;
        case PUSH_ACTIONS:
            inUse = !taskDAO.findByPushActions(implementation).isEmpty();
            break;
        case PULL_CORRELATION_RULE:
            inUse = !policyDAO.findByCorrelationRule(implementation).isEmpty();
            break;
        case VALIDATOR:
            inUse = !plainSchemaDAO.findByValidator(implementation).isEmpty();
            break;
        case RECIPIENTS_PROVIDER:
            inUse = !notificationDAO.findByRecipientsProvider(implementation).isEmpty();
            break;
        default:
    }
    if (inUse) {
        SyncopeClientException sce = SyncopeClientException.build(ClientExceptionType.InUse);
        sce.getElements().add("This implementation is in use");
        throw sce;
    }
    implementationDAO.delete(key);
}
Also used : SyncopeClientException(org.apache.syncope.common.lib.SyncopeClientException) NotFoundException(org.apache.syncope.core.persistence.api.dao.NotFoundException) Implementation(org.apache.syncope.core.persistence.api.entity.Implementation) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Example 99 with NotFoundException

use of org.apache.syncope.core.persistence.api.dao.NotFoundException in project syncope by apache.

the class MailTemplateLogic method setFormat.

@PreAuthorize("hasRole('" + StandardEntitlement.MAIL_TEMPLATE_UPDATE + "')")
public void setFormat(final String key, final MailTemplateFormat format, final String template) {
    MailTemplate mailTemplate = mailTemplateDAO.find(key);
    if (mailTemplate == null) {
        LOG.error("Could not find mail template '" + key + "'");
        throw new NotFoundException(key);
    }
    if (format == MailTemplateFormat.HTML) {
        mailTemplate.setHTMLTemplate(template);
    } else {
        mailTemplate.setTextTemplate(template);
    }
    mailTemplateDAO.save(mailTemplate);
}
Also used : MailTemplate(org.apache.syncope.core.persistence.api.entity.MailTemplate) NotFoundException(org.apache.syncope.core.persistence.api.dao.NotFoundException) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Example 100 with NotFoundException

use of org.apache.syncope.core.persistence.api.dao.NotFoundException in project syncope by apache.

the class MailTemplateLogic method getFormat.

@PreAuthorize("hasRole('" + StandardEntitlement.MAIL_TEMPLATE_READ + "')")
public String getFormat(final String key, final MailTemplateFormat format) {
    MailTemplate mailTemplate = mailTemplateDAO.find(key);
    if (mailTemplate == null) {
        LOG.error("Could not find mail template '" + key + "'");
        throw new NotFoundException(key);
    }
    String template = format == MailTemplateFormat.HTML ? mailTemplate.getHTMLTemplate() : mailTemplate.getTextTemplate();
    if (StringUtils.isBlank(template)) {
        LOG.error("Could not find mail template '" + key + "' in " + format + " format");
        throw new NotFoundException(key + " in " + format);
    }
    return template;
}
Also used : MailTemplate(org.apache.syncope.core.persistence.api.entity.MailTemplate) NotFoundException(org.apache.syncope.core.persistence.api.dao.NotFoundException) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Aggregations

NotFoundException (org.apache.syncope.core.persistence.api.dao.NotFoundException)110 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)87 SyncopeClientException (org.apache.syncope.common.lib.SyncopeClientException)41 Transactional (org.springframework.transaction.annotation.Transactional)21 Date (java.util.Date)12 ExternalResource (org.apache.syncope.core.persistence.api.entity.resource.ExternalResource)10 SchedulerException (org.quartz.SchedulerException)10 ArrayList (java.util.ArrayList)8 List (java.util.List)8 AnyType (org.apache.syncope.core.persistence.api.entity.AnyType)8 Report (org.apache.syncope.core.persistence.api.entity.Report)8 SchedTask (org.apache.syncope.core.persistence.api.entity.task.SchedTask)8 User (org.apache.syncope.core.persistence.api.entity.user.User)8 HashMap (java.util.HashMap)7 Collectors (java.util.stream.Collectors)7 Pair (org.apache.commons.lang3.tuple.Pair)7 ExecTO (org.apache.syncope.common.lib.to.ExecTO)7 Autowired (org.springframework.beans.factory.annotation.Autowired)7 StringUtils (org.apache.commons.lang3.StringUtils)6 DuplicateException (org.apache.syncope.core.persistence.api.dao.DuplicateException)6