/** * Tests simple conversation in a jar archive */ @Test public void testConversation() { logger.info("start conversation test"); Conversation conversation = conversationBean.getConversation(); assertEquals("deafult timeout is 600000 millis", 600000, conversation.getTimeout()); assertEquals("when the conversation is not started it is transient", true, conversation.isTransient()); assertNull("I have not started the conversation so the id will be null", conversation.getId()); conversationBean.initConversation(); assertEquals("verifiing the openeded conversation", "1", conversation.getId()); assertEquals("when the conversation is started it is not transient", false, conversation.isTransient()); conversationBean.endConversation(); assertNull("when I close the conversation the id will be null", conversation.getId()); assertEquals("when the conversation is ended it is transient again", true, conversation.isTransient()); logger.info("end conversation test"); }
@Before public void setup() { model = spy(new SubscriptionWizardConversationModel()); sdm = mock(ServiceDetailsModel.class); conversation = mock(Conversation.class); ui = mock(UiDelegate.class); subscriptionService = mock(SubscriptionService.class); userGroupService = mock(UserGroupService.class); menuBean = mock(MenuBean.class); sessionBean = mock(SessionBean.class); subscriptionServiceInternal = mock(SubscriptionServiceInternal.class); jsonConverter = spy(new JsonConverter()); jsonConverter.setUiDelegate(ui); userBean = spy(new UserBean()); pabv = mock(PaymentAndBillingVisibleBean.class); accountService = mock(AccountService.class); unitCtrl = new SubscriptionUnitCtrl(); unitModel = new SubscriptionUnitModel(); unitCtrl.setModel(unitModel); bean = spy(new SubscriptionWizardConversation()); decorateBean(); }
@Inject @Valid public PersonHome(@NotNull PersistenceService persistenceService, @NotNull Conversation conversation, @NotNull Messages messages, @NotNull Logger logger, @NotNull ValidatorFactory validatorFactory) { this.persistenceService = persistenceService; this.conversation = conversation; this.messages = messages; this.logger = logger; this.validatorFactory = validatorFactory; discipleshipStatusValues = new LinkedHashMap<>(); discipleshipStatusValues.put(messages.getMessageFor("enumerations.DiscipleshipStatus.DISCIPLE_CANDIDATE"), DiscipleshipStatus.DISCIPLE_CANDIDATE.toString()); discipleshipStatusValues.put(messages.getMessageFor("enumerations.DiscipleshipStatus.NOT_INTERESTED"), DiscipleshipStatus.NOT_INTERESTED.toString()); discipleshipStatusValues.put(messages.getMessageFor("enumerations.DiscipleshipStatus.TEACHING_CANDIDATE"), DiscipleshipStatus.TEACHING_CANDIDATE.toString()); }
public static boolean isReservedType(Class<?> type) { return HttpRequest.class.isAssignableFrom(type) || Session.class.isAssignableFrom(type) || Flash.class.isAssignableFrom(type) || Conversation.class.isAssignableFrom(type) || ConversationState.class.isAssignableFrom(type) || UserPrincipal.class.isAssignableFrom(type) || Map.class.isAssignableFrom(type); }
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(); } }
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); }
@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); }
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(); }
@Override public HttpResponse handle(HttpRequest request, MiddlewareChain 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; }
/** * @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); }
/** * @see #startTask(String) * * this method allows to start a conversation if no conversation is active */ public Task startTask(String taskId, boolean beginConversation) { Conversation conversation = conversationInstance.get(); if(conversation.isTransient()) { conversation.begin(); } return startTask(taskId); }
/** * @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); }
public Conversation getConversation() { return conversation; }
public void setConversation(Conversation conversation) { this.conversation = conversation; }
/** * Getters and setters part */ public void setConversation(Conversation conversation) { this.conversation = conversation; }
@Override public HttpResponse handle(HttpRequest request, MiddlewareChain chain) { HttpResponse response = castToHttpResponse(chain.next(request)); if (TemplatedHttpResponse.class.isInstance(response)) { TemplatedHttpResponse tres = TemplatedHttpResponse.class.cast(response); if (exports.contains(REQUEST)) { tres.getContext().put(exports.getExportName(REQUEST), request); } if (exports.contains(PARAMS)) { tres.getContext().put(exports.getExportName(PARAMS), request.getParams()); } if (exports.contains(USER_PRINCIPAL)) { Stream.of(request) .filter(PrincipalAvailable.class::isInstance) .map(PrincipalAvailable.class::cast) .findAny() .ifPresent(principal -> tres.getContext() .put(exports.getExportName(USER_PRINCIPAL), principal.getPrincipal())); tres.getContext().put("hasPermission", templateEngine.createFunction(HAS_PERMISSION)); tres.getContext().put("hasAnyPermissions", templateEngine.createFunction(HAS_ANY_PERMISSIONS)); tres.getContext().put("hasAllPermissions", templateEngine.createFunction(HAS_ALL_PERMISSIONS)); } if (exports.contains(SESSION)) { tres.getContext().put(exports.getExportName(SESSION), request.getSession()); } if (exports.contains(CONVERSATION)) { Conversation conversation = request.getConversation(); if (conversation != null && !request.getConversation().isTransient()) { String token = conversation.getId() + "$" + hmacEncoder.encodeToHex(conversation.getId() + "$" + conversation.getTimeout()) + "$" + conversation.getTimeout(); tres.getContext().put("conversationToken", token); } tres.getContext().put(exports.getExportName(CONVERSATION), conversation); } if (exports.contains(CONVERSATION_STATE)) { ConversationState conversationState = request.getConversationState(); tres.getContext().put(exports.getExportName(CONVERSATION_STATE), conversationState); } userFunctions.entrySet().stream() .forEach(e -> tres.getContext().put(e.getKey(), templateEngine.createFunction(e.getValue()))); render(tres); } return response; }
@Override public boolean isApplicable(Class<?> type, HttpRequest request) { return Conversation.class.isAssignableFrom(type); }
@Override public Conversation getInjectObject(HttpRequest request) { return request.getConversation(); }
public HttpResponse loginForm(Parameters params, Conversation conversation) { if (conversation.isTransient()) conversation.begin(); return templateEngine.render("guestbook/login", "url", params.get("url")); }
public HttpResponse page3(Conversation conversation) { if (!conversation.isTransient()) conversation.end(); return templateEngine.render("conversationState/page3"); }
@Override public boolean equals(Object another) { return another != null && Conversation.class.isInstance(another) && Objects.equals(getId(), Conversation.class.cast(another).getId()); }
default Conversation getConversation() { return (Conversation) getExtension("conversation"); }
default void setConversation(Conversation conversation) { setExtension("conversation", conversation); }
public Conversation getConversation() { return this.conversation; }
public void setConversation(final Conversation conversation) { this.conversation = conversation; }
/** * @return a conversa atual */ public Conversation getConversa() { return conversa; }