Search in sources :

Example 6 with ReportTemplate

use of org.apache.syncope.core.persistence.api.entity.ReportTemplate 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 7 with ReportTemplate

use of org.apache.syncope.core.persistence.api.entity.ReportTemplate 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 8 with ReportTemplate

use of org.apache.syncope.core.persistence.api.entity.ReportTemplate 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)

Aggregations

ReportTemplate (org.apache.syncope.core.persistence.api.entity.ReportTemplate)8 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)4 NotFoundException (org.apache.syncope.core.persistence.api.dao.NotFoundException)3 SyncopeClientException (org.apache.syncope.common.lib.SyncopeClientException)2 AbstractTest (org.apache.syncope.core.persistence.jpa.AbstractTest)2 Test (org.junit.jupiter.api.Test)2 ReportTemplateTO (org.apache.syncope.common.lib.to.ReportTemplateTO)1 DuplicateException (org.apache.syncope.core.persistence.api.dao.DuplicateException)1 Entity (org.apache.syncope.core.persistence.api.entity.Entity)1 Implementation (org.apache.syncope.core.persistence.api.entity.Implementation)1 Report (org.apache.syncope.core.persistence.api.entity.Report)1 JPAReportTemplate (org.apache.syncope.core.persistence.jpa.entity.JPAReportTemplate)1