Search in sources :

Example 41 with NotFoundException

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

the class ReportLogic method execute.

@PreAuthorize("hasRole('" + StandardEntitlement.REPORT_EXECUTE + "')")
@Override
public ExecTO execute(final String key, final Date startAt, final boolean dryRun) {
    Report report = reportDAO.find(key);
    if (report == null) {
        throw new NotFoundException("Report " + key);
    }
    if (!report.isActive()) {
        SyncopeClientException sce = SyncopeClientException.build(ClientExceptionType.Scheduling);
        sce.getElements().add("Report " + key + " is not active");
        throw sce;
    }
    try {
        jobManager.register(report, startAt, confDAO.find("tasks.interruptMaxRetries", 1L));
        scheduler.getScheduler().triggerJob(JobNamer.getJobKey(report));
    } catch (Exception e) {
        LOG.error("While executing report {}", report, e);
        SyncopeClientException sce = SyncopeClientException.build(ClientExceptionType.Scheduling);
        sce.getElements().add(e.getMessage());
        throw sce;
    }
    ExecTO result = new ExecTO();
    result.setJobType(JobType.REPORT);
    result.setRefKey(report.getKey());
    result.setRefDesc(binder.buildRefDesc(report));
    result.setStart(new Date());
    result.setStatus(ReportExecStatus.STARTED.name());
    result.setMessage("Job fired; waiting for results...");
    return result;
}
Also used : ExecTO(org.apache.syncope.common.lib.to.ExecTO) Report(org.apache.syncope.core.persistence.api.entity.Report) SyncopeClientException(org.apache.syncope.common.lib.SyncopeClientException) NotFoundException(org.apache.syncope.core.persistence.api.dao.NotFoundException) SyncopeClientException(org.apache.syncope.common.lib.SyncopeClientException) NotFoundException(org.apache.syncope.core.persistence.api.dao.NotFoundException) SchedulerException(org.quartz.SchedulerException) Date(java.util.Date) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Example 42 with NotFoundException

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

the class ReportLogic method update.

@PreAuthorize("hasRole('" + StandardEntitlement.REPORT_UPDATE + "')")
public ReportTO update(final ReportTO reportTO) {
    Report report = reportDAO.find(reportTO.getKey());
    if (report == null) {
        throw new NotFoundException("Report " + reportTO.getKey());
    }
    binder.getReport(report, reportTO);
    report = reportDAO.save(report);
    try {
        jobManager.register(report, null, confDAO.find("tasks.interruptMaxRetries", 1L));
    } catch (Exception e) {
        LOG.error("While registering quartz job for report " + report.getKey(), e);
        SyncopeClientException sce = SyncopeClientException.build(ClientExceptionType.Scheduling);
        sce.getElements().add(e.getMessage());
        throw sce;
    }
    return binder.getReportTO(report);
}
Also used : Report(org.apache.syncope.core.persistence.api.entity.Report) SyncopeClientException(org.apache.syncope.common.lib.SyncopeClientException) NotFoundException(org.apache.syncope.core.persistence.api.dao.NotFoundException) SyncopeClientException(org.apache.syncope.common.lib.SyncopeClientException) NotFoundException(org.apache.syncope.core.persistence.api.dao.NotFoundException) SchedulerException(org.quartz.SchedulerException) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Example 43 with NotFoundException

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

the class ReportLogic method delete.

@PreAuthorize("hasRole('" + StandardEntitlement.REPORT_DELETE + "')")
public ReportTO delete(final String key) {
    Report report = reportDAO.find(key);
    if (report == null) {
        throw new NotFoundException("Report " + key);
    }
    ReportTO deletedReport = binder.getReportTO(report);
    jobManager.unregister(report);
    reportDAO.delete(report);
    return deletedReport;
}
Also used : Report(org.apache.syncope.core.persistence.api.entity.Report) NotFoundException(org.apache.syncope.core.persistence.api.dao.NotFoundException) ReportTO(org.apache.syncope.common.lib.to.ReportTO) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Example 44 with NotFoundException

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

the class ReportLogic method listExecutions.

@PreAuthorize("hasRole('" + StandardEntitlement.REPORT_READ + "')")
@Override
public Pair<Integer, List<ExecTO>> listExecutions(final String key, final int page, final int size, final List<OrderByClause> orderByClauses) {
    Report report = reportDAO.find(key);
    if (report == null) {
        throw new NotFoundException("Report " + key);
    }
    Integer count = reportExecDAO.count(key);
    List<ExecTO> result = reportExecDAO.findAll(report, page, size, orderByClauses).stream().map(reportExec -> binder.getExecTO(reportExec)).collect(Collectors.toList());
    return Pair.of(count, result);
}
Also used : ReportExecExportFormat(org.apache.syncope.common.lib.types.ReportExecExportFormat) SyncopeClientException(org.apache.syncope.common.lib.SyncopeClientException) Date(java.util.Date) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) Autowired(org.springframework.beans.factory.annotation.Autowired) TextSerializer(org.apache.syncope.core.logic.cocoon.TextSerializer) ByteArrayInputStream(java.io.ByteArrayInputStream) Pair(org.apache.commons.lang3.tuple.Pair) Map(java.util.Map) XMLGenerator(org.apache.cocoon.sax.component.XMLGenerator) Method(java.lang.reflect.Method) Triple(org.apache.commons.lang3.tuple.Triple) XMLSerializer(org.apache.cocoon.sax.component.XMLSerializer) ExecTO(org.apache.syncope.common.lib.to.ExecTO) MimeConstants(org.apache.xmlgraphics.util.MimeConstants) BulkActionResult(org.apache.syncope.common.lib.to.BulkActionResult) JobNamer(org.apache.syncope.core.provisioning.api.job.JobNamer) Pipeline(org.apache.cocoon.pipeline.Pipeline) Collectors(java.util.stream.Collectors) NotFoundException(org.apache.syncope.core.persistence.api.dao.NotFoundException) StandardCharsets(java.nio.charset.StandardCharsets) IOUtils(org.apache.commons.io.IOUtils) EntityFactory(org.apache.syncope.core.persistence.api.entity.EntityFactory) List(java.util.List) JobAction(org.apache.syncope.common.lib.types.JobAction) ReportTO(org.apache.syncope.common.lib.to.ReportTO) ConfDAO(org.apache.syncope.core.persistence.api.dao.ConfDAO) XSLTTransformer(org.apache.syncope.core.logic.cocoon.XSLTTransformer) SAXPipelineComponent(org.apache.cocoon.sax.SAXPipelineComponent) StandardEntitlement(org.apache.syncope.common.lib.types.StandardEntitlement) ZipInputStream(java.util.zip.ZipInputStream) ReportExecStatus(org.apache.syncope.common.lib.types.ReportExecStatus) FopSerializer(org.apache.syncope.core.logic.cocoon.FopSerializer) StreamSource(javax.xml.transform.stream.StreamSource) OrderByClause(org.apache.syncope.core.persistence.api.dao.search.OrderByClause) HashMap(java.util.HashMap) ArrayUtils(org.apache.commons.lang3.ArrayUtils) JobKey(org.quartz.JobKey) ReportExecDAO(org.apache.syncope.core.persistence.api.dao.ReportExecDAO) SchedulerException(org.quartz.SchedulerException) ReportDataBinder(org.apache.syncope.core.provisioning.api.data.ReportDataBinder) ClientExceptionType(org.apache.syncope.common.lib.types.ClientExceptionType) JobTO(org.apache.syncope.common.lib.to.JobTO) OutputStream(java.io.OutputStream) Report(org.apache.syncope.core.persistence.api.entity.Report) ReportDAO(org.apache.syncope.core.persistence.api.dao.ReportDAO) NonCachingPipeline(org.apache.cocoon.pipeline.NonCachingPipeline) Component(org.springframework.stereotype.Component) ReportExec(org.apache.syncope.core.persistence.api.entity.ReportExec) JobType(org.apache.syncope.common.lib.types.JobType) Transactional(org.springframework.transaction.annotation.Transactional) ExecTO(org.apache.syncope.common.lib.to.ExecTO) Report(org.apache.syncope.core.persistence.api.entity.Report) NotFoundException(org.apache.syncope.core.persistence.api.dao.NotFoundException) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Example 45 with NotFoundException

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

the class ReportLogic method getJob.

@PreAuthorize("hasRole('" + StandardEntitlement.REPORT_READ + "')")
@Override
public JobTO getJob(final String key) {
    Report report = reportDAO.find(key);
    if (report == null) {
        throw new NotFoundException("Report " + key);
    }
    JobTO jobTO = null;
    try {
        jobTO = getJobTO(JobNamer.getJobKey(report));
    } catch (SchedulerException e) {
        LOG.error("Problems while retrieving scheduled job {}", JobNamer.getJobKey(report), e);
        SyncopeClientException sce = SyncopeClientException.build(ClientExceptionType.Scheduling);
        sce.getElements().add(e.getMessage());
        throw sce;
    }
    if (jobTO == null) {
        throw new NotFoundException("Job for report " + key);
    }
    return jobTO;
}
Also used : SchedulerException(org.quartz.SchedulerException) Report(org.apache.syncope.core.persistence.api.entity.Report) SyncopeClientException(org.apache.syncope.common.lib.SyncopeClientException) NotFoundException(org.apache.syncope.core.persistence.api.dao.NotFoundException) JobTO(org.apache.syncope.common.lib.to.JobTO) 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