Search in sources :

Example 1 with ReportletConf

use of org.apache.syncope.common.lib.report.ReportletConf in project syncope by apache.

the class ImplementationDataBinderImpl method update.

@Override
public void update(final Implementation implementation, final ImplementationTO implementationTO) {
    SyncopeClientException sce = SyncopeClientException.build(ClientExceptionType.InvalidImplementation);
    if (implementation.getType() != null && implementation.getType() != implementationTO.getType()) {
        sce.getElements().add("ImplementationType cannot be changed");
        throw sce;
    }
    if (StringUtils.isBlank(implementationTO.getBody())) {
        sce.getElements().add("No actual implementation provided");
        throw sce;
    }
    BeanUtils.copyProperties(implementationTO, implementation);
    if (implementation.getEngine() == ImplementationEngine.JAVA) {
        Class<?> base = null;
        switch(implementation.getType()) {
            case REPORTLET:
                base = Reportlet.class;
                break;
            case ACCOUNT_RULE:
                base = AccountRule.class;
                break;
            case PASSWORD_RULE:
                base = PasswordRule.class;
                break;
            case ITEM_TRANSFORMER:
                base = ItemTransformer.class;
                break;
            case TASKJOB_DELEGATE:
                base = SchedTaskJobDelegate.class;
                break;
            case RECON_FILTER_BUILDER:
                base = ReconFilterBuilder.class;
                break;
            case LOGIC_ACTIONS:
                base = LogicActions.class;
                break;
            case PROPAGATION_ACTIONS:
                base = PropagationActions.class;
                break;
            case PULL_ACTIONS:
                base = PullActions.class;
                break;
            case PUSH_ACTIONS:
                base = PushActions.class;
                break;
            case PULL_CORRELATION_RULE:
                base = PullCorrelationRule.class;
                break;
            case VALIDATOR:
                base = Validator.class;
                break;
            case RECIPIENTS_PROVIDER:
                base = RecipientsProvider.class;
                break;
            default:
        }
        if (base == null) {
            sce.getElements().add("No Java interface found for " + implementation.getType());
            throw sce;
        }
        if (implementation.getType() == ImplementationType.REPORTLET) {
            ReportletConf reportlet = POJOHelper.deserialize(implementation.getBody(), ReportletConf.class);
            if (reportlet == null) {
                sce.getElements().add("Could not deserialize as ReportletConf");
                throw sce;
            }
        } else if (implementation.getType() == ImplementationType.ACCOUNT_RULE || implementation.getType() == ImplementationType.PASSWORD_RULE || implementation.getType() == ImplementationType.PULL_CORRELATION_RULE) {
            RuleConf rule = POJOHelper.deserialize(implementation.getBody(), RuleConf.class);
            if (rule == null) {
                sce.getElements().add("Could not deserialize as neither Account, Password nor PullCorrelation RuleConf");
                throw sce;
            }
        } else {
            Class<?> clazz = null;
            try {
                clazz = Class.forName(implementation.getBody());
            } catch (Exception e) {
                LOG.error("Class '{}' not found", implementation.getBody(), e);
                sce.getElements().add("No Java class found: " + implementation.getBody());
                throw sce;
            }
            if (!base.isAssignableFrom(clazz)) {
                sce.getElements().add("Java class " + implementation.getBody() + " must comply with " + base.getName());
                throw sce;
            }
            if (Modifier.isAbstract(clazz.getModifiers())) {
                sce.getElements().add("Java class " + implementation.getBody() + " is abstract");
                throw sce;
            }
        }
    }
}
Also used : RuleConf(org.apache.syncope.common.lib.policy.RuleConf) SyncopeClientException(org.apache.syncope.common.lib.SyncopeClientException) ReportletConf(org.apache.syncope.common.lib.report.ReportletConf) SyncopeClientException(org.apache.syncope.common.lib.SyncopeClientException)

Example 2 with ReportletConf

use of org.apache.syncope.common.lib.report.ReportletConf in project syncope by apache.

the class ImplementationManager method buildReportlet.

public static Optional<Reportlet> buildReportlet(final Implementation impl) throws InstantiationException, IllegalAccessException {
    switch(impl.getEngine()) {
        case GROOVY:
            return Optional.of(ImplementationManager.<Reportlet>buildGroovy(impl));
        case JAVA:
        default:
            Reportlet reportlet = null;
            ReportletConf reportletConf = POJOHelper.deserialize(impl.getBody(), ReportletConf.class);
            Class<? extends Reportlet> reportletClass = ApplicationContextProvider.getApplicationContext().getBean(ImplementationLookup.class).getReportletClass(reportletConf.getClass());
            if (reportletClass == null) {
                LOG.warn("Could not find matching reportlet for {}", reportletConf.getClass());
            } else {
                // fetch (or create) reportlet
                if (ApplicationContextProvider.getBeanFactory().containsSingleton(reportletClass.getName())) {
                    reportlet = (Reportlet) ApplicationContextProvider.getBeanFactory().getSingleton(reportletClass.getName());
                } else {
                    reportlet = (Reportlet) ApplicationContextProvider.getBeanFactory().createBean(reportletClass, AbstractBeanDefinition.AUTOWIRE_BY_TYPE, false);
                    ApplicationContextProvider.getBeanFactory().registerSingleton(reportletClass.getName(), reportlet);
                }
                reportlet.setConf(reportletConf);
            }
            return Optional.ofNullable(reportlet);
    }
}
Also used : Reportlet(org.apache.syncope.core.persistence.api.dao.Reportlet) ReportletConf(org.apache.syncope.common.lib.report.ReportletConf) ImplementationLookup(org.apache.syncope.core.persistence.api.ImplementationLookup)

Example 3 with ReportletConf

use of org.apache.syncope.common.lib.report.ReportletConf in project syncope by apache.

the class ClassPathScanImplementationLookup method load.

@SuppressWarnings("unchecked")
public void load() {
    pages = new ArrayList<>();
    previewers = new ArrayList<>();
    extPages = new ArrayList<>();
    extWidgets = new ArrayList<>();
    ssoLoginFormPanels = new ArrayList<>();
    reportletConfs = new HashMap<>();
    accountRuleConfs = new HashMap<>();
    passwordRuleConfs = new HashMap<>();
    pullCorrelationRuleConfs = new HashMap<>();
    ClassPathScanningCandidateComponentProvider scanner = new ClassPathScanningCandidateComponentProvider(false);
    scanner.addIncludeFilter(new AssignableTypeFilter(BasePage.class));
    scanner.addIncludeFilter(new AssignableTypeFilter(AbstractBinaryPreviewer.class));
    scanner.addIncludeFilter(new AssignableTypeFilter(BaseExtPage.class));
    scanner.addIncludeFilter(new AssignableTypeFilter(BaseExtWidget.class));
    scanner.addIncludeFilter(new AssignableTypeFilter(SSOLoginFormPanel.class));
    scanner.addIncludeFilter(new AssignableTypeFilter(ReportletConf.class));
    scanner.addIncludeFilter(new AssignableTypeFilter(AccountRuleConf.class));
    scanner.addIncludeFilter(new AssignableTypeFilter(PasswordRuleConf.class));
    scanner.addIncludeFilter(new AssignableTypeFilter(PullCorrelationRuleConf.class));
    scanner.findCandidateComponents(getBasePackage()).forEach(bd -> {
        try {
            Class<?> clazz = ClassUtils.resolveClassName(bd.getBeanClassName(), ClassUtils.getDefaultClassLoader());
            boolean isAbsractClazz = Modifier.isAbstract(clazz.getModifiers());
            if (!isAbsractClazz) {
                if (BaseExtPage.class.isAssignableFrom(clazz)) {
                    if (clazz.isAnnotationPresent(ExtPage.class)) {
                        extPages.add((Class<? extends BaseExtPage>) clazz);
                    } else {
                        LOG.error("Could not find annotation {} in {}, ignoring", ExtPage.class.getName(), clazz.getName());
                    }
                } else if (BaseExtWidget.class.isAssignableFrom(clazz)) {
                    if (clazz.isAnnotationPresent(ExtWidget.class)) {
                        extWidgets.add((Class<? extends BaseExtWidget>) clazz);
                    } else {
                        LOG.error("Could not find annotation {} in {}, ignoring", ExtWidget.class.getName(), clazz.getName());
                    }
                } else if (BasePage.class.isAssignableFrom(clazz)) {
                    pages.add((Class<? extends BasePage>) clazz);
                } else if (AbstractBinaryPreviewer.class.isAssignableFrom(clazz)) {
                    previewers.add((Class<? extends AbstractBinaryPreviewer>) clazz);
                } else if (SSOLoginFormPanel.class.isAssignableFrom(clazz)) {
                    ssoLoginFormPanels.add((Class<? extends SSOLoginFormPanel>) clazz);
                } else if (ReportletConf.class.isAssignableFrom(clazz)) {
                    reportletConfs.put(clazz.getName(), (Class<? extends ReportletConf>) clazz);
                } else if (AccountRuleConf.class.isAssignableFrom(clazz)) {
                    accountRuleConfs.put(clazz.getName(), (Class<? extends AccountRuleConf>) clazz);
                } else if (PasswordRuleConf.class.isAssignableFrom(clazz)) {
                    passwordRuleConfs.put(clazz.getName(), (Class<? extends PasswordRuleConf>) clazz);
                } else if (PullCorrelationRuleConf.class.isAssignableFrom(clazz)) {
                    pullCorrelationRuleConfs.put(clazz.getName(), (Class<? extends PullCorrelationRuleConf>) clazz);
                }
            }
        } catch (Throwable t) {
            LOG.warn("Could not inspect class {}", bd.getBeanClassName(), t);
        }
    });
    pages = Collections.unmodifiableList(pages);
    previewers = Collections.unmodifiableList(previewers);
    Collections.sort(extPages, (o1, o2) -> ObjectUtils.compare(o1.getAnnotation(ExtPage.class).priority(), o2.getAnnotation(ExtPage.class).priority()));
    extPages = Collections.unmodifiableList(extPages);
    Collections.sort(extWidgets, (o1, o2) -> ObjectUtils.compare(o1.getAnnotation(ExtWidget.class).priority(), o2.getAnnotation(ExtWidget.class).priority()));
    extWidgets = Collections.unmodifiableList(extWidgets);
    ssoLoginFormPanels = Collections.unmodifiableList(ssoLoginFormPanels);
    reportletConfs = Collections.unmodifiableMap(reportletConfs);
    accountRuleConfs = Collections.unmodifiableMap(accountRuleConfs);
    passwordRuleConfs = Collections.unmodifiableMap(passwordRuleConfs);
    pullCorrelationRuleConfs = Collections.unmodifiableMap(pullCorrelationRuleConfs);
    LOG.debug("Binary previewers found: {}", previewers);
    LOG.debug("Extension pages found: {}", extPages);
    LOG.debug("Extension widgets found: {}", extWidgets);
    LOG.debug("SSO Login pages found: {}", ssoLoginFormPanels);
    LOG.debug("Reportlet configurations found: {}", reportletConfs);
    LOG.debug("Account Rule configurations found: {}", accountRuleConfs);
    LOG.debug("Password Rule configurations found: {}", passwordRuleConfs);
    LOG.debug("Pull Correlation Rule configurations found: {}", pullCorrelationRuleConfs);
}
Also used : SSOLoginFormPanel(org.apache.syncope.client.console.panels.SSOLoginFormPanel) BaseExtPage(org.apache.syncope.client.console.pages.BaseExtPage) PasswordRuleConf(org.apache.syncope.common.lib.policy.PasswordRuleConf) BaseExtPage(org.apache.syncope.client.console.pages.BaseExtPage) ExtPage(org.apache.syncope.client.console.annotations.ExtPage) ClassPathScanningCandidateComponentProvider(org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider) AccountRuleConf(org.apache.syncope.common.lib.policy.AccountRuleConf) ReportletConf(org.apache.syncope.common.lib.report.ReportletConf) AbstractBinaryPreviewer(org.apache.syncope.client.console.wicket.markup.html.form.preview.AbstractBinaryPreviewer) PullCorrelationRuleConf(org.apache.syncope.common.lib.policy.PullCorrelationRuleConf) ExtWidget(org.apache.syncope.client.console.annotations.ExtWidget) BaseExtWidget(org.apache.syncope.client.console.widgets.BaseExtWidget) BasePage(org.apache.syncope.client.console.pages.BasePage) AssignableTypeFilter(org.springframework.core.type.filter.AssignableTypeFilter) BaseExtWidget(org.apache.syncope.client.console.widgets.BaseExtWidget)

Aggregations

ReportletConf (org.apache.syncope.common.lib.report.ReportletConf)3 ExtPage (org.apache.syncope.client.console.annotations.ExtPage)1 ExtWidget (org.apache.syncope.client.console.annotations.ExtWidget)1 BaseExtPage (org.apache.syncope.client.console.pages.BaseExtPage)1 BasePage (org.apache.syncope.client.console.pages.BasePage)1 SSOLoginFormPanel (org.apache.syncope.client.console.panels.SSOLoginFormPanel)1 AbstractBinaryPreviewer (org.apache.syncope.client.console.wicket.markup.html.form.preview.AbstractBinaryPreviewer)1 BaseExtWidget (org.apache.syncope.client.console.widgets.BaseExtWidget)1 SyncopeClientException (org.apache.syncope.common.lib.SyncopeClientException)1 AccountRuleConf (org.apache.syncope.common.lib.policy.AccountRuleConf)1 PasswordRuleConf (org.apache.syncope.common.lib.policy.PasswordRuleConf)1 PullCorrelationRuleConf (org.apache.syncope.common.lib.policy.PullCorrelationRuleConf)1 RuleConf (org.apache.syncope.common.lib.policy.RuleConf)1 ImplementationLookup (org.apache.syncope.core.persistence.api.ImplementationLookup)1 Reportlet (org.apache.syncope.core.persistence.api.dao.Reportlet)1 ClassPathScanningCandidateComponentProvider (org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider)1 AssignableTypeFilter (org.springframework.core.type.filter.AssignableTypeFilter)1