Java Code Examples for org.apache.wicket.request.cycle.RequestCycle#setMetaData()

The following examples show how to use org.apache.wicket.request.cycle.RequestCycle#setMetaData() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RecommendationServiceImpl.java    From inception with Apache License 2.0 6 votes vote down vote up
@EventListener
public void onAnnotation(AnnotationEvent aEvent)
{
    RequestCycle requestCycle = RequestCycle.get();
    
    if (requestCycle == null) {
        return;
    }
    
    Set<RecommendationStateKey> dirties = requestCycle.getMetaData(DIRTIES);
    if (dirties == null) {
        dirties = new HashSet<>();
        requestCycle.setMetaData(DIRTIES, dirties);
    }
    
    dirties.add(new RecommendationStateKey(aEvent.getUser(), aEvent.getProject()));
}
 
Example 2
Source File: AbstractAuthorizingRealm.java    From onedev with MIT License 6 votes vote down vote up
@Override
protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principals) {
	Long userId = (Long) principals.getPrimaryPrincipal();						
	RequestCycle requestCycle = RequestCycle.get();
	if (requestCycle != null) {
		Map<Long, AuthorizationInfo> authorizationInfos = requestCycle.getMetaData(AUTHORIZATION_INFOS);
		if (authorizationInfos == null) {
			authorizationInfos = new HashMap<>();
			requestCycle.setMetaData(AUTHORIZATION_INFOS, authorizationInfos);
		}
		AuthorizationInfo authorizationInfo = authorizationInfos.get(userId);
		if (authorizationInfo == null) {
			authorizationInfo = newAuthorizationInfo(userId);
			authorizationInfos.put(userId, authorizationInfo);
		}
		return authorizationInfo;
	} else {
		return newAuthorizationInfo(userId);
	}
}
 
Example 3
Source File: LazyAuthorizationRequestCycleListener.java    From wicket-orientdb with Apache License 2.0 6 votes vote down vote up
@Override
public void onBeginRequest(RequestCycle cycle) {
	WebRequest request = (WebRequest) cycle.getRequest();
	String authorization = request.getHeader(AUTHORIZATION_HEADER);
	if(authorization!=null && authorization.startsWith("Basic"))
	{
		String[] pair = new String(Base64.getDecoder().decode(authorization.substring(6).trim())).split(":"); 
           if (pair.length == 2) { 
               String userName = pair[0]; 
               String password = pair[1]; 
               OrientDbWebSession session = OrientDbWebSession.get();
               if(!session.signIn(userName, password))
               {
               	cycle.setMetaData(LAZY_AUTHORIZED, false);
               }
           }
	}
}
 
Example 4
Source File: LazyAuthorizationRequestCycleListener.java    From wicket-orientdb with Apache License 2.0 5 votes vote down vote up
@Override
public void onRequestHandlerResolved(RequestCycle cycle,
		IRequestHandler handler) {
	Boolean lazyAuthorized = cycle.getMetaData(LAZY_AUTHORIZED);
	if(lazyAuthorized!=null && !lazyAuthorized)
	{
		cycle.setMetaData(LAZY_AUTHORIZED, null);
		throw new LazyAuthorizationException();
	}
}
 
Example 5
Source File: OMetricsRequestCycleListener.java    From Orienteer with Apache License 2.0 5 votes vote down vote up
@Override
public void onBeginRequest(RequestCycle cycle) {
	Histogram.Timer requestTimer = HISTOGRAM_REQUESTS
									.labels(Boolean.toString(((WebRequest)cycle.getRequest()).isAjax()))
									.startTimer();
	cycle.setMetaData(REQUESTS_HISTOGRAM_KEY, requestTimer);
}
 
Example 6
Source File: RecommendationServiceImpl.java    From inception with Apache License 2.0 4 votes vote down vote up
@EventListener
public void onAfterCasWritten(AfterCasWrittenEvent aEvent)
{
    RequestCycle requestCycle = RequestCycle.get();
    
    if (requestCycle == null) {
        return;
    }
    
    Set<RecommendationStateKey> committed = requestCycle.getMetaData(COMMITTED);
    if (committed == null) {
        committed = new HashSet<>();
        requestCycle.setMetaData(COMMITTED, committed);
    }

    committed.add(new RecommendationStateKey(aEvent.getDocument().getUser(),
            aEvent.getDocument().getProject()));        
    
    boolean containsTrainingTrigger = false;
    for (IRequestCycleListener listener : requestCycle.getListeners()) {
        if (listener instanceof TriggerTrainingTaskListener) {
            containsTrainingTrigger = true;
        }
    }
    
    if (!containsTrainingTrigger) {
        // Hack to figure out which annotations the user is viewing. This obviously works only 
        // if the user is viewing annotations through an AnnotationPageBase ... still not a 
        // bad guess
        IPageRequestHandler handler = PageRequestHandlerTracker
                .getLastHandler(requestCycle);
        Page page = (Page) handler.getPage();
        if (page instanceof AnnotationPageBase) {
            AnnotatorState state = ((AnnotationPageBase) page).getModelObject();
            requestCycle.getListeners()
                    .add(new TriggerTrainingTaskListener(state.getDocument()));
        }
        else {
            // Otherwise use the document from the event... mind that if there are multiple
            // events, we consider only the first one since after that the trigger listener
            // will be in the cycle and we do not add another one.
            // FIXME: This works as long as the user is working on a single document, but not if
            // the user is doing a bulk operation. If a bulk-operation is done, we get multiple
            // AfterCasWrittenEvent and we do not know which of them belongs to the document
            // which the user is currently viewing.
            requestCycle.getListeners()
                    .add(new TriggerTrainingTaskListener(aEvent.getDocument().getDocument()));
        }
    }
}
 
Example 7
Source File: AbstractContentAwareTransactionRequestCycleListener.java    From wicket-orientdb with Apache License 2.0 2 votes vote down vote up
/**
 * Change current state of 'transaction'
 * @param cycle current {@link RequestCycle}
 * @param inProgress state to set
 */
public void setInProgress(RequestCycle cycle, boolean inProgress)
{
	cycle.setMetaData(IN_PROGRESS_KEY, inProgress);
}