Search in sources :

Example 31 with RequestCycle

use of org.apache.wicket.request.cycle.RequestCycle in project webanno by webanno.

the class RelationRenderer method render.

@Override
public void render(final JCas aJcas, List<AnnotationFeature> aFeatures, VDocument aResponse, AnnotatorState aBratAnnotatorModel) {
    List<AnnotationFeature> visibleFeatures = aFeatures.stream().filter(f -> f.isVisible() && f.isEnabled()).collect(Collectors.toList());
    ArcAdapter typeAdapter = getTypeAdapter();
    Type type = getType(aJcas.getCas(), typeAdapter.getAnnotationTypeName());
    int windowBegin = aBratAnnotatorModel.getWindowBeginOffset();
    int windowEnd = aBratAnnotatorModel.getWindowEndOffset();
    Feature dependentFeature = type.getFeatureByBaseName(typeAdapter.getTargetFeatureName());
    Feature governorFeature = type.getFeatureByBaseName(typeAdapter.getSourceFeatureName());
    Type spanType = getType(aJcas.getCas(), typeAdapter.getAttachTypeName());
    Feature arcSpanFeature = spanType.getFeatureByBaseName(typeAdapter.getAttachFeatureName());
    FeatureStructure dependentFs;
    FeatureStructure governorFs;
    Map<Integer, Set<Integer>> relationLinks = getRelationLinks(aJcas, windowBegin, windowEnd, type, dependentFeature, governorFeature, arcSpanFeature);
    // if this is a governor for more than one dependent, avoid duplicate yield
    List<Integer> yieldDeps = new ArrayList<>();
    for (AnnotationFS fs : selectCovered(aJcas.getCas(), type, windowBegin, windowEnd)) {
        if (typeAdapter.getAttachFeatureName() != null) {
            dependentFs = fs.getFeatureValue(dependentFeature).getFeatureValue(arcSpanFeature);
            governorFs = fs.getFeatureValue(governorFeature).getFeatureValue(arcSpanFeature);
        } else {
            dependentFs = fs.getFeatureValue(dependentFeature);
            governorFs = fs.getFeatureValue(governorFeature);
        }
        String bratTypeName = TypeUtil.getUiTypeName(typeAdapter);
        Map<String, String> features = getFeatures(typeAdapter, fs, visibleFeatures);
        if (dependentFs == null || governorFs == null) {
            RequestCycle requestCycle = RequestCycle.get();
            IPageRequestHandler handler = PageRequestHandlerTracker.getLastHandler(requestCycle);
            Page page = (Page) handler.getPage();
            StringBuilder message = new StringBuilder();
            message.append("Relation [" + typeAdapter.getLayer().getName() + "] with id [" + getAddr(fs) + "] has loose ends - cannot render.");
            if (typeAdapter.getAttachFeatureName() != null) {
                message.append("\nRelation [" + typeAdapter.getLayer().getName() + "] attached to feature [" + typeAdapter.getAttachFeatureName() + "].");
            }
            message.append("\nDependent: " + dependentFs);
            message.append("\nGovernor: " + governorFs);
            page.warn(message.toString());
            continue;
        }
        aResponse.add(new VArc(typeAdapter.getLayer(), fs, bratTypeName, governorFs, dependentFs, features));
        // Render errors if required features are missing
        renderRequiredFeatureErrors(visibleFeatures, fs, aResponse);
        if (relationLinks.keySet().contains(getAddr(governorFs)) && !yieldDeps.contains(getAddr(governorFs))) {
            yieldDeps.add(getAddr(governorFs));
            // sort the annotations (begin, end)
            List<Integer> sortedDepFs = new ArrayList<>(relationLinks.get(getAddr(governorFs)));
            sortedDepFs.sort(comparingInt(arg0 -> selectByAddr(aJcas, arg0).getBegin()));
            String cm = getYieldMessage(aJcas, sortedDepFs);
            aResponse.add(new VComment(governorFs, VCommentType.YIELD, cm));
        }
    }
}
Also used : AnnotationFS(org.apache.uima.cas.text.AnnotationFS) Page(org.apache.wicket.Page) AnnotatorState(de.tudarmstadt.ukp.clarin.webanno.api.annotation.model.AnnotatorState) VCommentType(de.tudarmstadt.ukp.clarin.webanno.api.annotation.rendering.model.VCommentType) WebAnnoCasUtil.selectByAddr(de.tudarmstadt.ukp.clarin.webanno.api.annotation.util.WebAnnoCasUtil.selectByAddr) LoggerFactory(org.slf4j.LoggerFactory) Feature(org.apache.uima.cas.Feature) ArrayList(java.util.ArrayList) Type(org.apache.uima.cas.Type) RequestCycle(org.apache.wicket.request.cycle.RequestCycle) Map(java.util.Map) PageRequestHandlerTracker(org.apache.wicket.request.cycle.PageRequestHandlerTracker) FeatureStructure(org.apache.uima.cas.FeatureStructure) JCas(org.apache.uima.jcas.JCas) WebAnnoCasUtil.getAddr(de.tudarmstadt.ukp.clarin.webanno.api.annotation.util.WebAnnoCasUtil.getAddr) Comparator.comparingInt(java.util.Comparator.comparingInt) Logger(org.slf4j.Logger) VArc(de.tudarmstadt.ukp.clarin.webanno.api.annotation.rendering.model.VArc) VComment(de.tudarmstadt.ukp.clarin.webanno.api.annotation.rendering.model.VComment) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Set(java.util.Set) Collectors(java.util.stream.Collectors) ArcAdapter(de.tudarmstadt.ukp.clarin.webanno.api.annotation.adapter.ArcAdapter) CasUtil.selectCovered(org.apache.uima.fit.util.CasUtil.selectCovered) List(java.util.List) ConcurrentSkipListSet(java.util.concurrent.ConcurrentSkipListSet) TypeUtil(de.tudarmstadt.ukp.clarin.webanno.api.annotation.util.TypeUtil) AnnotationFeature(de.tudarmstadt.ukp.clarin.webanno.model.AnnotationFeature) IPageRequestHandler(org.apache.wicket.core.request.handler.IPageRequestHandler) CasUtil.getType(org.apache.uima.fit.util.CasUtil.getType) VDocument(de.tudarmstadt.ukp.clarin.webanno.api.annotation.rendering.model.VDocument) FeatureSupportRegistry(de.tudarmstadt.ukp.clarin.webanno.api.annotation.feature.FeatureSupportRegistry) Set(java.util.Set) ConcurrentSkipListSet(java.util.concurrent.ConcurrentSkipListSet) ArcAdapter(de.tudarmstadt.ukp.clarin.webanno.api.annotation.adapter.ArcAdapter) RequestCycle(org.apache.wicket.request.cycle.RequestCycle) ArrayList(java.util.ArrayList) IPageRequestHandler(org.apache.wicket.core.request.handler.IPageRequestHandler) Page(org.apache.wicket.Page) VComment(de.tudarmstadt.ukp.clarin.webanno.api.annotation.rendering.model.VComment) Feature(org.apache.uima.cas.Feature) AnnotationFeature(de.tudarmstadt.ukp.clarin.webanno.model.AnnotationFeature) FeatureStructure(org.apache.uima.cas.FeatureStructure) AnnotationFS(org.apache.uima.cas.text.AnnotationFS) VCommentType(de.tudarmstadt.ukp.clarin.webanno.api.annotation.rendering.model.VCommentType) Type(org.apache.uima.cas.Type) CasUtil.getType(org.apache.uima.fit.util.CasUtil.getType) VArc(de.tudarmstadt.ukp.clarin.webanno.api.annotation.rendering.model.VArc) AnnotationFeature(de.tudarmstadt.ukp.clarin.webanno.model.AnnotationFeature)

Example 32 with RequestCycle

use of org.apache.wicket.request.cycle.RequestCycle in project midpoint by Evolveum.

the class AsyncWebProcessManagerImpl method createProcessIdentifier.

private Key createProcessIdentifier(String processId) {
    RequestCycle rc = RequestCycle.get();
    Request req = rc.getRequest();
    HttpSession session = ((ServletWebRequest) req).getContainerRequest().getSession();
    return new Key(session.getId(), processId);
}
Also used : RequestCycle(org.apache.wicket.request.cycle.RequestCycle) HttpSession(javax.servlet.http.HttpSession) ServletWebRequest(org.apache.wicket.protocol.http.servlet.ServletWebRequest) Request(org.apache.wicket.request.Request)

Example 33 with RequestCycle

use of org.apache.wicket.request.cycle.RequestCycle in project the-app by devops-dojo.

the class DirectBuyRequestCycleListener method removeDirectBuyFromUrl.

private Url removeDirectBuyFromUrl(RequestCycle cycle) {
    Url requestUrl = cycle.getRequest().getUrl();
    Optional<Url.QueryParameter> directBuyParamter = requestUrl.getQueryParameters().stream().filter(p -> DIRECT_BUY_PARAMETER.equals(p.getName())).findFirst();
    if (directBuyParamter.isPresent()) {
        Url requestUrlWithoutDirectBuy = new Url(requestUrl);
        // TODO-BERND: make change request for wicket - contextpath is removed in wicket implementation
        requestUrlWithoutDirectBuy.getSegments().add(0, cycle.getRequest().getContextPath().replaceAll("/", ""));
        requestUrlWithoutDirectBuy.getQueryParameters().remove(directBuyParamter.get());
        return requestUrlWithoutDirectBuy;
    }
    return requestUrl;
}
Also used : SpringBean(org.apache.wicket.spring.injection.annot.SpringBean) Logger(org.slf4j.Logger) LoggerFactory(org.slf4j.LoggerFactory) ProductInfo(io.github.zutherb.appstash.shop.service.product.model.ProductInfo) RequestCycle(org.apache.wicket.request.cycle.RequestCycle) Injector(org.apache.wicket.injection.Injector) Cart(io.github.zutherb.appstash.shop.service.cart.api.Cart) AbstractRequestCycleListener(org.apache.wicket.request.cycle.AbstractRequestCycleListener) WebResponse(org.apache.wicket.request.http.WebResponse) Optional(java.util.Optional) ProductService(io.github.zutherb.appstash.shop.service.product.api.ProductService) Url(org.apache.wicket.request.Url) StringValue(org.apache.wicket.util.string.StringValue) ProductQuery(io.github.zutherb.appstash.shop.repository.product.model.ProductQuery) Url(org.apache.wicket.request.Url)

Example 34 with RequestCycle

use of org.apache.wicket.request.cycle.RequestCycle in project hale by halestudio.

the class BaseWebApplication method init.

@Override
public void init() {
    super.init();
    BootstrapSettings settings = new BootstrapSettings();
    final ThemeProvider themeProvider = new BootswatchThemeProvider() {

        {
            add(new MetroTheme());
            add(new GoogleTheme());
            add(new WicketTheme());
            add(new Bootstrap3Theme());
            defaultTheme("bootstrap-responsive");
        // defaultTheme("bootstrap");
        }
    };
    settings.setThemeProvider(themeProvider);
    Bootstrap.install(this, settings);
    BootstrapLess.install(this);
    configureResourceBundles();
    IPackageResourceGuard packageResourceGuard = getResourceSettings().getPackageResourceGuard();
    if (packageResourceGuard instanceof SecurePackageResourceGuard) {
        SecurePackageResourceGuard guard = (SecurePackageResourceGuard) packageResourceGuard;
        guard.addPattern("+org/apache/wicket/resource/jquery/*.map");
    }
    // enforce mounts so security interceptors based on URLs can't be fooled
    getSecuritySettings().setEnforceMounts(true);
    getSecuritySettings().setAuthorizationStrategy(new SimplePageAuthorizationStrategy(SecuredPage.class, getLoginPageClass()) {

        @Override
        protected boolean isAuthorized() {
            SecurityContext securityContext = SecurityContextHolder.getContext();
            if (securityContext != null) {
                Authentication authentication = securityContext.getAuthentication();
                if (authentication != null && authentication.isAuthenticated()) {
                    for (GrantedAuthority authority : authentication.getAuthorities()) {
                        if (authority.getAuthority().equals(UserConstants.ROLE_USER) || authority.getAuthority().equals(UserConstants.ROLE_ADMIN)) {
                            // allow access only for users/admins
                            return true;
                        }
                    }
                }
            }
            return false;
        }
    });
    getComponentInstantiationListeners().add(new SpringComponentInjector(this));
    getRequestCycleListeners().add(new AbstractRequestCycleListener() {

        @Override
        public IRequestHandler onException(RequestCycle cycle, Exception ex) {
            return new RenderPageRequestHandler(new PageProvider(new ExceptionPage(ex)));
        }
    });
    // add login page to every application based on this one (if enabled)
    Class<? extends BasePage> loginClass = getLoginPageClass();
    if (loginClass != null) {
        // login page
        mountPage("/login", loginClass);
        // user settings
        mountPage("/settings", UserSettingsPage.class);
        // about
        mountPage("/about", AboutPage.class);
        // contact
        mountPage("/contact", ContactPage.class);
        if (OpenIdLoginPage.class.equals(loginClass)) {
            // for OpenID auth also add page for new users
            mountPage("/new", NewUserPage.class);
        }
    }
}
Also used : WicketTheme(de.agilecoders.wicket.themes.markup.html.wicket.WicketTheme) IRequestHandler(org.apache.wicket.request.IRequestHandler) RenderPageRequestHandler(org.apache.wicket.core.request.handler.RenderPageRequestHandler) GoogleTheme(de.agilecoders.wicket.themes.markup.html.google.GoogleTheme) RequestCycle(org.apache.wicket.request.cycle.RequestCycle) GrantedAuthority(org.springframework.security.core.GrantedAuthority) SimplePageAuthorizationStrategy(org.apache.wicket.authorization.strategies.page.SimplePageAuthorizationStrategy) MetroTheme(de.agilecoders.wicket.themes.markup.html.metro.MetroTheme) Bootstrap3Theme(de.agilecoders.wicket.themes.markup.html.bootstrap3.Bootstrap3Theme) BootstrapSettings(de.agilecoders.wicket.core.settings.BootstrapSettings) IPackageResourceGuard(org.apache.wicket.markup.html.IPackageResourceGuard) SecurePackageResourceGuard(org.apache.wicket.markup.html.SecurePackageResourceGuard) Authentication(org.springframework.security.core.Authentication) PageProvider(org.apache.wicket.core.request.handler.PageProvider) AbstractRequestCycleListener(org.apache.wicket.request.cycle.AbstractRequestCycleListener) SecurityContext(org.springframework.security.core.context.SecurityContext) ExceptionPage(eu.esdihumboldt.hale.server.webapp.pages.ExceptionPage) SecuredPage(eu.esdihumboldt.hale.server.webapp.pages.SecuredPage) BootswatchThemeProvider(de.agilecoders.wicket.themes.settings.BootswatchThemeProvider) SpringComponentInjector(org.apache.wicket.spring.injection.annot.SpringComponentInjector) BootswatchThemeProvider(de.agilecoders.wicket.themes.settings.BootswatchThemeProvider) ThemeProvider(de.agilecoders.wicket.core.settings.ThemeProvider)

Example 35 with RequestCycle

use of org.apache.wicket.request.cycle.RequestCycle in project webanno by webanno.

the class ApplicationPageBase method isBrowserWarningVisible.

private boolean isBrowserWarningVisible(Properties settings) {
    RequestCycle requestCycle = RequestCycle.get();
    WebClientInfo clientInfo;
    if (Session.exists()) {
        WebSession session = WebSession.get();
        clientInfo = session.getClientInfo();
    } else {
        clientInfo = new WebClientInfo(requestCycle);
    }
    ClientProperties clientProperties = clientInfo.getProperties();
    boolean isUsingUnsupportedBrowser = !clientProperties.isBrowserSafari() && !clientProperties.isBrowserChrome();
    boolean ignoreWarning = "false".equalsIgnoreCase(settings.getProperty(SettingsUtil.CFG_WARNINGS_UNSUPPORTED_BROWSER));
    return isUsingUnsupportedBrowser && !ignoreWarning;
}
Also used : WebClientInfo(org.apache.wicket.protocol.http.request.WebClientInfo) ClientProperties(org.apache.wicket.protocol.http.ClientProperties) WebSession(org.apache.wicket.protocol.http.WebSession) RequestCycle(org.apache.wicket.request.cycle.RequestCycle)

Aggregations

RequestCycle (org.apache.wicket.request.cycle.RequestCycle)69 WebResponse (org.apache.wicket.request.http.WebResponse)14 IRequestHandler (org.apache.wicket.request.IRequestHandler)9 Url (org.apache.wicket.request.Url)9 Response (org.apache.wicket.request.Response)8 WicketRuntimeException (org.apache.wicket.WicketRuntimeException)7 BufferedWebResponse (org.apache.wicket.protocol.http.BufferedWebResponse)7 Page (org.apache.wicket.Page)6 Request (org.apache.wicket.request.Request)6 RenderPageRequestHandler (org.apache.wicket.core.request.handler.RenderPageRequestHandler)5 IRequestCycle (org.apache.wicket.request.IRequestCycle)5 AbstractRequestCycleListener (org.apache.wicket.request.cycle.AbstractRequestCycleListener)5 Test (org.junit.Test)5 Application (org.apache.wicket.Application)4 IHeaderResponse (org.apache.wicket.markup.head.IHeaderResponse)4 WebClientInfo (org.apache.wicket.protocol.http.request.WebClientInfo)4 WebRequest (org.apache.wicket.request.http.WebRequest)4 HttpServletResponse (javax.servlet.http.HttpServletResponse)3 WebApplication (org.apache.wicket.protocol.http.WebApplication)3 UrlRenderer (org.apache.wicket.request.UrlRenderer)3