Search in sources :

Example 76 with NotFoundException

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

the class ReportTemplateLogic method getFormat.

@PreAuthorize("hasRole('" + StandardEntitlement.REPORT_TEMPLATE_READ + "')")
public String getFormat(final String key, final ReportTemplateFormat format) {
    ReportTemplate reportTemplate = reportTemplateDAO.find(key);
    if (reportTemplate == null) {
        LOG.error("Could not find report template '" + key + "'");
        throw new NotFoundException(key);
    }
    String template = format == ReportTemplateFormat.HTML ? reportTemplate.getHTMLTemplate() : format == ReportTemplateFormat.CSV ? reportTemplate.getCSVTemplate() : reportTemplate.getFOTemplate();
    if (StringUtils.isBlank(template)) {
        LOG.error("Could not find report template '" + key + "' in " + format + " format");
        throw new NotFoundException(key + " in " + format);
    }
    return template;
}
Also used : ReportTemplate(org.apache.syncope.core.persistence.api.entity.ReportTemplate) NotFoundException(org.apache.syncope.core.persistence.api.dao.NotFoundException) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Example 77 with NotFoundException

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

the class ReportTemplateLogic method delete.

@PreAuthorize("hasRole('" + StandardEntitlement.REPORT_TEMPLATE_DELETE + "')")
public ReportTemplateTO delete(final String key) {
    ReportTemplate reportTemplate = reportTemplateDAO.find(key);
    if (reportTemplate == null) {
        LOG.error("Could not find report template '" + key + "'");
        throw new NotFoundException(key);
    }
    List<Report> reports = reportDAO.findByTemplate(reportTemplate);
    if (!reports.isEmpty()) {
        SyncopeClientException sce = SyncopeClientException.build(ClientExceptionType.InUse);
        sce.getElements().addAll(reports.stream().map(Entity::getKey).collect(Collectors.toList()));
        throw sce;
    }
    ReportTemplateTO deleted = getReportTemplateTO(key);
    reportTemplateDAO.delete(key);
    return deleted;
}
Also used : Entity(org.apache.syncope.core.persistence.api.entity.Entity) ReportTemplateTO(org.apache.syncope.common.lib.to.ReportTemplateTO) Report(org.apache.syncope.core.persistence.api.entity.Report) ReportTemplate(org.apache.syncope.core.persistence.api.entity.ReportTemplate) SyncopeClientException(org.apache.syncope.common.lib.SyncopeClientException) NotFoundException(org.apache.syncope.core.persistence.api.dao.NotFoundException) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Example 78 with NotFoundException

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

the class ReportTemplateLogic method setFormat.

@PreAuthorize("hasRole('" + StandardEntitlement.REPORT_TEMPLATE_UPDATE + "')")
public void setFormat(final String key, final ReportTemplateFormat format, final String template) {
    ReportTemplate reportTemplate = reportTemplateDAO.find(key);
    if (reportTemplate == null) {
        LOG.error("Could not find report template '" + key + "'");
        throw new NotFoundException(key);
    }
    switch(format) {
        case CSV:
            reportTemplate.setCSVTemplate(template);
            break;
        case FO:
            reportTemplate.setFOTemplate(template);
            break;
        case HTML:
            reportTemplate.setHTMLTemplate(template);
            break;
        default:
    }
    reportTemplateDAO.save(reportTemplate);
}
Also used : ReportTemplate(org.apache.syncope.core.persistence.api.entity.ReportTemplate) NotFoundException(org.apache.syncope.core.persistence.api.dao.NotFoundException) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Example 79 with NotFoundException

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

the class ResourceLogic method connObjectInit.

private Triple<ExternalResource, AnyType, Provision> connObjectInit(final String resourceKey, final String anyTypeKey) {
    ExternalResource resource = resourceDAO.authFind(resourceKey);
    if (resource == null) {
        throw new NotFoundException("Resource '" + resourceKey + "'");
    }
    AnyType anyType = anyTypeDAO.find(anyTypeKey);
    if (anyType == null) {
        throw new NotFoundException("AnyType '" + anyTypeKey + "'");
    }
    Optional<? extends Provision> provision = resource.getProvision(anyType);
    if (!provision.isPresent()) {
        throw new NotFoundException("Provision on resource '" + resourceKey + "' for type '" + anyTypeKey + "'");
    }
    return ImmutableTriple.of(resource, anyType, provision.get());
}
Also used : NotFoundException(org.apache.syncope.core.persistence.api.dao.NotFoundException) ExternalResource(org.apache.syncope.core.persistence.api.entity.resource.ExternalResource) AnyType(org.apache.syncope.core.persistence.api.entity.AnyType)

Example 80 with NotFoundException

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

the class SecurityQuestionLogic method delete.

@PreAuthorize("hasRole('" + StandardEntitlement.SECURITY_QUESTION_DELETE + "')")
public SecurityQuestionTO delete(final String key) {
    SecurityQuestion securityQuestion = securityQuestionDAO.find(key);
    if (securityQuestion == null) {
        LOG.error("Could not find security question '" + key + "'");
        throw new NotFoundException(String.valueOf(key));
    }
    SecurityQuestionTO deleted = binder.getSecurityQuestionTO(securityQuestion);
    securityQuestionDAO.delete(key);
    return deleted;
}
Also used : NotFoundException(org.apache.syncope.core.persistence.api.dao.NotFoundException) SecurityQuestion(org.apache.syncope.core.persistence.api.entity.user.SecurityQuestion) SecurityQuestionTO(org.apache.syncope.common.lib.to.SecurityQuestionTO) 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