Java Code Examples for javax.enterprise.context.Conversation#isTransient()

The following examples show how to use javax.enterprise.context.Conversation#isTransient() . 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: BusinessProcess.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
/**
 * @see #startTask(String)
 * 
 *      this method allows to start a conversation if no conversation is active
 */
public Task startTask(String taskId, boolean beginConversation) {
  if (beginConversation) {
    Conversation conversation = conversationInstance.get();
    if (conversation.isTransient()) {
      conversation.begin();
    }
  }
  return startTask(taskId);
}
 
Example 2
Source File: LoginController.java    From enkan with Eclipse Public License 1.0 5 votes vote down vote up
public HttpResponse login(Parameters params, Conversation conversation) {
    if (!conversation.isTransient()) conversation.end();
    CustomerDao dao = daoProvider.getDao(CustomerDao.class);
    String email = params.get("email");
    Customer customer = dao.loginByPassword(email, params.get("password"));
    if (customer == null) {
        return templateEngine.render("guestbook/login");
    } else {
        Session session = new Session();
        session.put("principal", new LoginPrincipal(email));
        return builder(redirect(GuestbookController.class, "list", HttpResponseUtils.RedirectStatusCode.SEE_OTHER))
                .set(HttpResponse::setSession, session)
                .build();
    }
}
 
Example 3
Source File: GuestbookController.java    From enkan with Eclipse Public License 1.0 5 votes vote down vote up
public HttpResponse list(Conversation conversation) {
    if (conversation.isTransient()) conversation.begin();
    GuestbookDao dao = domaProvider.getDao(GuestbookDao.class);
    List<Guestbook> guestbooks = dao.selectAll();
    return templateEngine.render("guestbook/list",
            "guestbooks", guestbooks);
}
 
Example 4
Source File: GuestbookController.java    From enkan with Eclipse Public License 1.0 5 votes vote down vote up
@Transactional
public HttpResponse post(Parameters params, UserPrincipal principal, Conversation conversation) {
    if (!conversation.isTransient()) conversation.end();
    GuestbookDao dao = domaProvider.getDao(GuestbookDao.class);
    Guestbook guestbook = builder(new Guestbook())
            .set(Guestbook::setName,    principal.getName())
            .set(Guestbook::setMessage, params.get("message"))
            .set(Guestbook::setPostedAt, LocalDateTime.now())
            .build();
    dao.insert(guestbook);
    return redirect(GuestbookController.class, "list", SEE_OTHER);
}
 
Example 5
Source File: ConversationStateController.java    From enkan with Eclipse Public License 1.0 5 votes vote down vote up
public HttpResponse page1(Conversation conversation) {
    if (conversation.isTransient()) conversation.begin();
    int randomValue = new Random().nextInt();
    ConversationState conversationState = new ConversationState();
    conversationState.put("random", randomValue);
    return builder(templateEngine.render("conversationState/page1",
            "random", randomValue))
            .set(HttpResponse::setConversationState, conversationState)
            .build();
}
 
Example 6
Source File: ConversationMiddleware.java    From enkan with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public HttpResponse handle(HttpRequest request, MiddlewareChain<HttpRequest, NRES, ?, ?> chain) {
    ConversationToken token = parseToken(readTokenFunc.apply(request));

    if (!isGetRequest(request) && !token.isValid()) {
        return builder(HttpResponse.of("Invalid conversation."))
                .set(HttpResponse::setHeaders, Headers.of("Content-Type", "text/plain"))
                .set(HttpResponse::setStatus, 403)
                .build();
    }

    Conversation conversation;
    if (token.id == null) {
        conversation = new DefaultConversation();
    } else {
        conversation = new DefaultConversation(token.id);
        ConversationState state = (ConversationState) store.read(token.id);
        request.setConversationState(state);
    }
    request.setConversation(conversation);

    HttpResponse response = castToHttpResponse(chain.next(request));
    if (conversation.isTransient()) {
        if (conversation.getId() != null) {
            store.delete(conversation.getId());
        }
    } else if (response.getConversationState() != null) {
        store.write(conversation.getId(), response.getConversationState());
    }
    return response;
}
 
Example 7
Source File: BusinessProcess.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
/**
 * @see #startTask(String)
 * <p>
 * this method allows to start a conversation if no conversation is active
 */
public Task startTask(String taskId, boolean beginConversation) {
    if (beginConversation) {
        Conversation conversation = conversationInstance.get();
        if (conversation.isTransient()) {
            conversation.begin();
        }
    }
    return startTask(taskId);
}
 
Example 8
Source File: BusinessProcess.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
/**
 * @see #startTask(String)
 *
 * this method allows to start a conversation if no conversation is active
 */
public Task startTask(String taskId, boolean beginConversation) {
  if(beginConversation) {
    Conversation conversation = conversationInstance.get();
    if(conversation.isTransient()) {
     conversation.begin();
    }
  }
  return startTask(taskId);
}
 
Example 9
Source File: LoginController.java    From enkan with Eclipse Public License 1.0 4 votes vote down vote up
public HttpResponse loginForm(Parameters params, Conversation conversation) {
    if (conversation.isTransient()) conversation.begin();
    return templateEngine.render("guestbook/login",
            "url", params.get("url"));
}
 
Example 10
Source File: ConversationStateController.java    From enkan with Eclipse Public License 1.0 4 votes vote down vote up
public HttpResponse page3(Conversation conversation) {
    if (!conversation.isTransient()) conversation.end();
    return templateEngine.render("conversationState/page3");
}