id
stringlengths 36
36
| text
stringlengths 1
1.25M
|
---|---|
5864d8a4-bd7b-44d9-b36c-cb4fd6a279ce
|
public final String back() {
incrementPopContextOnNextPauseCounter();
onBack();
return nextView();
}
|
312f9c6e-9911-4181-88d6-b2f328e868d2
|
protected void onBack() {
}
|
af29a31a-5449-426c-b747-c7b36ad7d5c6
|
private void incrementPopContextOnNextPauseCounter() {
getCurrentConversation().incrementPopContextOnNextPauseCounter();
}
|
1ee3045a-5b57-47f1-af2b-5a2dcb4dc512
|
private String nextView() {
return getCurrentConversation().nextView();
}
|
57d963f1-6693-42d4-9827-ebdd69a3e769
|
public static Conversation newConversation(HttpSession session) {
AtomicInteger counter = (AtomicInteger) session.getAttribute(CONVERSATION_COUNTER_KEY);
if (counter == null) {
counter = new AtomicInteger(0);
session.setAttribute(CONVERSATION_COUNTER_KEY, counter);
}
return new Conversation(String.valueOf(counter.incrementAndGet()));
}
|
922cb1f3-05a8-48ac-ba57-5b960b257fff
|
public static Conversation newConversation(HttpSession session, ConversationContext<?> conversationContext) {
Conversation newInstance = newConversation(session);
newInstance.setNextContext(conversationContext);
return newInstance;
}
|
9fc98a8e-8ea4-4df5-928e-72f91fe1323b
|
public Conversation() {
}
|
d3476b0b-efac-46b0-80b2-92ca53534ad3
|
public Conversation(String id) {
this.id = id;
}
|
0073da0b-311e-448c-b4b7-b8857a8a8615
|
public String getId() {
return id;
}
|
966de78e-1843-451b-8d63-35c31a923c04
|
public String getCid() {
return cidParamValue(id, nextContext().getId());
}
|
a94e4f6e-c365-4e53-b09d-3eaefcc3636a
|
public void addBean(String name, Object bean) {
beans.put(name, bean);
}
|
f62c9439-c412-4a6a-bceb-8bca9b208a09
|
public Object getBean(String name) {
return beans.get(name);
}
|
9fb066e9-cf75-4bd2-9fde-bb441abccc33
|
protected void handleOutOfSynchContext(String ccid, HttpServletRequest request) throws UnexpectedConversationException {
ConversationContext<?> requestedContext = null;
for (ConversationContext<?> ctx : contextes) {
if (requestedContext == null) {
if (ctx.getId().equals(ccid)) {
requestedContext = ctx;
}
} else {
// we pop all contextes that are placed after the contexId requested
incrementPopContextOnNextPauseCounter();
}
}
if (requestedContext != null) {
popContextesIfNeeded();
} else {
throw new UnexpectedConversationException("Uri not in sync with conversation expecting _ccid_=" + getCurrentContext().getId() + " but got " + ccid,
request.getRequestURI(), getUrl());
}
}
|
7ad04039-1f9d-4ba6-b26c-91697118e4bb
|
public void incrementPopContextOnNextPauseCounter() {
popContextOnNextPauseCounter++;
}
|
bd7626df-87f7-48d8-844c-817329455386
|
public int getPopContextOnNextPauseCounter() {
return popContextOnNextPauseCounter;
}
|
ca2deeca-a516-490f-a123-4a36fcf05b72
|
public void setNextContext(ConversationContext<?> newContext) {
newContext.setId(String.valueOf(++conversationContextIdCounter));
newContext.setConversationId(getId());
// we delay the context push because apparently some EL is invoked after bean action is performed
// which it leads in some cases to re-creation of 'conversation scoped' bean.
nextContext = newContext; // will be pushed at next request during resuming...
}
|
87ffced7-f90e-4be9-af54-a133e2ca11b1
|
public ConversationContext<?> nextContext(ConversationContext<?> newContext) {
setNextContext(newContext);
return newContext;
}
|
ae3eacab-cab7-44d8-babc-358c4e0515dd
|
protected void pushNextContextIfNeeded() {
if (nextContext != null) {
contextes.push(nextContext);
log.debug("pushed 1 context on stack: {}", nextContext.getLabel());
nextContext = null;
}
}
|
a626782b-deff-4fcf-a8f5-f4ea48168cfb
|
public void setNextContextSub(ConversationContext<?> newContext) {
setNextContext(newContext.sub());
}
|
73a9b0cd-3daf-43e2-b7ec-8d5551953f2a
|
public void setNextContextSubReadOnly(ConversationContext<?> newContext) {
setNextContext(newContext.sub().readonly());
}
|
fa5072f2-7942-4e79-864c-68ad9c16ec19
|
public void setNextContextReadOnly(ConversationContext<?> newContext) {
setNextContext(newContext.readonly());
}
|
03aadcd4-ff48-4895-9519-5f2a38765011
|
public final int getConversationContextesCount() {
return contextes.size();
}
|
f6da9dd8-ed71-48f7-8359-c90f846bf11c
|
@SuppressWarnings("unchecked")
public <T extends ConversationContext<?>> T getCurrentContext() {
return (T) contextes.peek();
}
|
ac6428ce-da19-4f8d-89bf-d37065d1185e
|
protected Stack<ConversationContext<?>> getConversationContextes() {
return contextes;
}
|
0883e0c8-7c84-44ef-a190-1b9db7de1ec0
|
protected void popContextesIfNeeded() {
if (popContextOnNextPauseCounter > 1) {
log.debug("There are {} to pop from the stack", popContextOnNextPauseCounter);
}
for (int i = 0; i < popContextOnNextPauseCounter; i++) {
if (!contextes.isEmpty()) {
ConversationContext<?> ccPopped = contextes.pop();
log.debug("popped 1 context from stack: {}", ccPopped.getLabel());
} else {
log.warn("Attention, too many pop requested! Could be source of potential bug");
}
}
popContextOnNextPauseCounter = 0;
if (contextes.isEmpty()) {
log.info("All contextes have been popped. Natural conversation ending will be performed");
}
}
|
36928f49-c0b2-466d-bedc-5ae1b627dd8a
|
public String nextView() {
ConversationContext<?> context = nextContext();
return context != null ? context.view() : "/home.faces?faces-redirect=true";
}
|
d016a9ae-3cc1-483c-805a-9556ce6c1717
|
public String nextUrl() {
ConversationContext<?> context = nextContext();
return context != null ? context.getUrl() : "/home.faces";
}
|
c7e1bdba-ec4d-4bad-9d62-338803d1d37d
|
@SuppressWarnings("unchecked")
public <T extends ConversationContext<?>> T nextContext() {
if (nextContext != null) {
return (T) nextContext;
}
if (popContextOnNextPauseCounter > 0) {
int nextActiveContextIndex = contextes.size() - 1 - popContextOnNextPauseCounter;
if (nextActiveContextIndex >= 0) {
ConversationContext<?> contextOnTopOfStackOnNextResume = contextes.elementAt(nextActiveContextIndex);
return (T) contextOnTopOfStackOnNextResume;
} else {
return null;
}
}
return (T) contextes.peek();
}
|
d55746e3-a31b-47b6-932c-37bcec00292c
|
public String getLabel() {
return contextes.peek().getLabel();
}
|
d1985c63-9b68-4f31-87c5-152bf675e396
|
public String getUrl() {
return contextes.peek().getUrl();
}
|
fd188d88-1620-4240-aa41-b3f7dab6ff04
|
public String getViewUri() {
return contextes.peek().getViewUri();
}
|
96c28826-66b2-4889-b6f2-c2f7b39b1da7
|
public void setVar(String name, Object var) {
contextes.peek().setVar(name, var);
}
|
d7b8b3e7-747b-44ee-9e39-5d8ee7f41f3c
|
public Object getVar(String name) {
return contextes.peek().getVar(name);
}
|
5d1b8de2-a99f-4962-8a17-ab8b80073ad5
|
public <T> T getVar(String name, Class<T> expectedType) {
return contextes.peek().getVar(name, expectedType);
}
|
8d3722e4-354e-4509-b949-ae5313f00adf
|
public ConversationContext() {
}
|
fa9f0c04-0396-4c2e-bdd5-f631d7da100c
|
public ConversationContext(String viewUri) {
this.viewUri = viewUri;
}
|
e684f399-ed90-4e61-97d8-79aaa40015ee
|
protected void setId(String id) {
this.id = id;
}
|
813b93c9-d4d9-4d1f-8b61-361fa69b71bb
|
public ConversationContext<T> id(String id) {
setId(id);
return this;
}
|
3faaf24d-815a-4d98-a228-58eb3c03746f
|
public String getId() {
return id;
}
|
37a52579-5f19-4631-8815-d7a1792b9d8f
|
protected void setConversationId(String conversationId) {
this.conversationId = conversationId;
}
|
5d2513cb-a25b-4e64-9373-f190a0d48322
|
public ConversationContext<T> conversationId(String conversationId) {
setConversationId(conversationId);
return this;
}
|
355b9989-688e-4f8c-8fc4-f91a55705c2f
|
public void setEntity(T entity) {
setVar("_entity", entity);
}
|
a167427c-29eb-4a0c-a0e7-ad398fb094de
|
public ConversationContext<T> entity(T entity) {
setEntity(entity);
return this;
}
|
96d2e99e-89ec-4bc5-a42a-6e5589996572
|
@SuppressWarnings("unchecked")
public T getEntity() {
return (T) vars.get("_entity");
}
|
c1103c2a-10d2-4ffe-af3a-3ea662d2cf06
|
public void setIsNewEntity(boolean isNewEntity) {
this.isNewEntity = isNewEntity;
}
|
d5815722-5fa8-4f50-b087-169bd3a59575
|
public ConversationContext<T> isNewEntity(boolean isNewEntity) {
setIsNewEntity(isNewEntity);
return this;
}
|
53363f4a-36ba-43df-907a-bfe627e79103
|
public ConversationContext<T> newEntity() {
return isNewEntity(true);
}
|
92f372a4-5e22-45fa-8d63-89c70e184f91
|
public boolean isNewEntity() {
return isNewEntity;
}
|
5878a573-4f49-4fb5-8c28-037f409fa0ce
|
public void setEntityId(Serializable entityId) {
setVar("entityId", entityId);
}
|
6df9820e-261d-42f8-a8d2-b35de6fbb039
|
public ConversationContext<T> entityId(Serializable entityId) {
setEntityId(entityId);
return this;
}
|
b05d0572-f541-48df-95c9-dac2aa54490f
|
@SuppressWarnings("unchecked")
public <PK> PK getEntityIdAndRemove() {
return (PK) vars.remove("entityId");
}
|
94339f08-4ba2-46e3-9305-feebc7483c3d
|
public void setLabelKey(String labelKey, Object... labelKeyArgs) {
this.labelKey = labelKey;
this.labelKeyArgs = labelKeyArgs;
}
|
690fcd0e-c4c8-45a8-8123-7cfa8e68e8c4
|
public ConversationContext<T> labelKey(String labelKey, Object... labelKeyArgs) {
setLabelKey(labelKey, labelKeyArgs);
return this;
}
|
efb067d1-7ffd-4ff9-af73-f16b49dc4bef
|
public String getLabel() {
return getProperty(labelKey, labelKeyArgs);
}
|
65a28fa1-bc87-462a-b2af-fc9cbbf49553
|
public abstract String getProperty(String labelKey, Object[] labelKeyArgs);
|
62eb3ff7-a2fc-4043-8de9-1626e86b50b0
|
public void setViewUri(String viewUri) {
this.viewUri = viewUri;
}
|
0407d81a-6368-42f4-af93-dfa7ace3c0fb
|
public ConversationContext<T> viewUri(String viewUri) {
setViewUri(viewUri);
return this;
}
|
3d77b075-8d88-45af-b6a4-dd7882cf789f
|
public String getViewUri() {
return viewUri;
}
|
53ba5afe-7be2-4de6-880b-23de2d2faafa
|
public void setSub(boolean sub) {
setVar("sub", sub);
}
|
c0076838-1ca4-437a-b671-14714af9ec99
|
public ConversationContext<T> sub(boolean sub) {
setSub(sub);
return this;
}
|
57b563b4-e901-4dee-baf1-e5437e73470a
|
public ConversationContext<T> sub() {
return sub(true);
}
|
d5a4240a-3622-4081-a322-c93d2d6696fa
|
public boolean isSub() {
return getVar("sub", Boolean.class) != null ? getVar("sub", Boolean.class) : false;
}
|
cd3ae602-78e1-411e-a366-2f2f2d699eb9
|
public void setReadonly(boolean readonly) {
setVar("readonly", readonly);
}
|
53f00f65-30c8-4f67-8a41-82d6c150446b
|
public ConversationContext<T> readonly(boolean readonly) {
setReadonly(readonly);
return this;
}
|
7499950f-1d75-4020-8421-87ad137f3d96
|
public ConversationContext<T> readonly() {
return readonly(true);
}
|
abda7411-9ec9-473c-8e27-3f85f3a3c2c5
|
public boolean isReadOnly() {
return getVar("readonly", Boolean.class) != null ? getVar("readonly", Boolean.class) : false;
}
|
0b15578d-ec2c-46a3-9e5f-c6f4a937614e
|
public void setPrint(boolean print) {
setVar("print", print);
}
|
5ef07ee8-4caf-4a89-82f8-7fe3476ba6f0
|
public ConversationContext<T> print(boolean print) {
setPrint(print);
return this;
}
|
97b11bd8-91d9-460a-bcb6-2a6ece1f4bd7
|
public ConversationContext<T> print() {
return print(true);
}
|
277f1e25-c8c5-4df3-ad3e-6f6b74ff881a
|
public boolean isPrint() {
return getVar("print", Boolean.class) != null ? getVar("print", Boolean.class) : false;
}
|
932afc87-b88a-489d-a5e9-c2553bdf272e
|
public void setCallBack(ConversationCallBack<T> callBack) {
this.callBack = callBack;
}
|
91bcd794-3ff5-4b52-ac91-dea09d78d887
|
public ConversationContext<T> callBack(ConversationCallBack<T> callBack) {
setCallBack(callBack);
return this;
}
|
004f1d64-f9ff-4a5a-9d72-8257f368798b
|
public ConversationCallBack<T> getCallBack() {
return callBack;
}
|
ad953c5d-5012-474f-9dc5-32bae99ea1fb
|
public String getUrl() {
checkViewUriAndConversationId();
return viewUri + "?" + cidParamNameValue(conversationId, getId());
}
|
f4567c4c-8448-4f0e-bbf9-b92eaf00c673
|
public String view() {
checkViewUriAndConversationId();
return viewUri + "?faces-redirect=true&" + cidParamNameValue(conversationId, getId());
}
|
3a5d917b-2cc9-4498-ac85-be91a5a36065
|
private void checkViewUriAndConversationId() {
if (viewUri == null) {
throw new IllegalStateException("Developer! viewUri is null, it must be set before calling view() or getUrl() methods");
}
if (conversationId == null) {
throw new IllegalStateException("Developer! conversationId is null, it must be set before calling view() or getUrl() methods");
}
}
|
df3c10f0-4340-485d-9349-578cb5fd5b9c
|
public void addBean(String name, Object bean) {
beans.put(name, bean);
}
|
95e5ffbb-b1fb-43c7-bd0d-1652098ecae3
|
@SuppressWarnings("unchecked")
public <E> E getBean(String name, Class<E> expectedType) {
return (E) beans.get(name);
}
|
c974fe7e-f65d-4cf2-9f05-44d844c71a90
|
public void setVar(String name, Object var) {
vars.put(name, var);
}
|
e1d5d3bb-631c-4a0d-bec6-2aae528d6b33
|
public Object getVar(String name) {
return vars.get(name);
}
|
fe9d5605-b3e0-47e8-927d-47ffad5f1354
|
@SuppressWarnings("unchecked")
public <E> E getVar(String name, Class<E> expectedType) {
return (E) vars.get(name);
}
|
f1c864dc-3823-4034-b57b-5f513ffc67ac
|
public List<Entry<String, Object>> getBeanEntries() {
return newArrayList(beans.entrySet());
}
|
3f6876fb-0c05-4c99-aaa2-f863ea3e202c
|
public List<Entry<String, Object>> getVarEntries() {
return newArrayList(vars.entrySet());
}
|
72ea574c-a9eb-43ec-9469-13dbeca4a0fc
|
public static Conversation getCurrentConversation() {
return currentConversationHolder.get();
}
|
e834c755-bedb-4724-819c-bcaccc816a5c
|
public static void setCurrentConversation(Conversation conversation) {
currentConversationHolder.set(conversation);
}
|
67ef9aaf-4aad-43fe-8647-6c91c5ad2b37
|
public static String cidParamValue(String conversationId, String conversationContextId) {
return conversationId + CID_PARAM_SEPARATOR + conversationContextId;
}
|
4be1f26b-50f5-481d-b745-414fb9d444d6
|
public static String cidParamNameValue(String conversationId, String conversationContextId) {
return CID_PARAM_NAME + "=" + cidParamValue(conversationId, conversationContextId);
}
|
d15314be-991b-4e46-85a6-b1a258393a31
|
public static String getConversationId(HttpServletRequest request) {
String _cid = request.getParameter(CID_PARAM_NAME);
return _cid != null ? substringBefore(_cid, CID_PARAM_SEPARATOR) : null;
}
|
6a582b91-870e-456f-8204-1e5f903d6a74
|
public static String getConversationContextId(HttpServletRequest request) {
String _cid = request.getParameter(CID_PARAM_NAME);
return _cid != null ? substringAfter(_cid, CID_PARAM_SEPARATOR) : null;
}
|
27985c0d-7f81-4535-b2cc-5912daa0b2fc
|
@Override
public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
HttpServletRequest request = (HttpServletRequest) servletRequest;
HttpServletResponse response = (HttpServletResponse) servletResponse;
String cid = getConversationId(request);
if (cid != null) {
String ccid = getConversationContextId(request);
// -----------------------------
// RESUME existing conversation
// -----------------------------
try {
conversationManager.resumeConversation(cid, ccid, request);
log.debug("Conv. {} resumed. Nb ctx: {}", cid, getCurrentConversation().getConversationContextesCount());
} catch (UnexpectedConversationException uue) {
log.error(uue.getMessage());
response.sendRedirect(request.getContextPath() + uue.getRedirectUrl());
return;
}
try {
filterChain.doFilter(request, response);
} finally {
conversationManager.pauseCurrentConversation(request);
}
} else if (!request.getRequestURI().contains("/javax.faces.resource/") && "true".equals(request.getParameter("_ncid_"))) {
throw new IllegalArgumentException("This version does not support ncid parameter");
} else {
// -----------------------------
// Not related to conversations
// -----------------------------
filterChain.doFilter(request, response);
}
}
|
1f1e1bc7-be4f-421b-a215-468a9f8c7c7b
|
@Override
public void init(FilterConfig filterConfig) throws ServletException {
}
|
7d604fe2-3024-428b-a380-c23e61215a0d
|
@Override
public void destroy() {
}
|
fd934772-ff3b-4534-b4c6-0205c1ae5232
|
public UnexpectedConversationException(String reason, String unexpectedUrl, String redirectUrl) {
super(reason + ". requested url: " + unexpectedUrl + " => we redirect her to " + redirectUrl);
this.redirectUrl = redirectUrl;
}
|
17afb3ad-c3ce-4163-a135-4939a4f2c394
|
public String getRedirectUrl() {
return redirectUrl;
}
|
24953cd7-112c-4086-9bd7-9e27ae4112ce
|
public HttpRequest(OpenMRSDataProperties properties) {
this.properties = properties;
}
|
9c346fdc-1851-479f-bf36-be989d44c3b5
|
public void post(String relativeUrl, String postContent) throws IOException {
Response execute = Request.Post(properties.getOpenMRSUrl() + relativeUrl)
.addHeader("Content-Type", "application/json")
.addHeader("Accept", "application/json")
.addHeader("Authorization", basicAuthHeader())
.bodyString(postContent, ContentType.APPLICATION_JSON)
.execute();
System.out.println(execute.returnContent().asString());
}
|
a67dcedf-1873-4bd5-8489-cb23c6328722
|
private String basicAuthHeader() {
return "Basic " + new String(Base64.encodeBase64(identity()));
}
|
c203529e-d77e-4c81-9b7a-8f0e66fa203a
|
private byte[] identity() {
return (properties.getOpenMRSUser() + ":" + properties.getOpenMRSPassword()).getBytes();
}
|
3b2c2bfb-9506-4087-98ea-6b7d6abfc849
|
public static String createConcept(String name, ConceptDataType dataType, ConceptClass conceptClass, List<String> setMembers) throws JSONException {
JSONObject jsonObject = new JSONObject();
jsonObject.append("names", new JSONObject().put("name", name).put("locale", "en")
.put("conceptNameType", "FULLY_SPECIFIED"))
.put("datatype", dataType)
.put("conceptClass", conceptClass);
if (setMembers == null || setMembers.size() < 1) return jsonObject.toString();
jsonObject.put("set", true)
.put("setMembers", setMembers);
return jsonObject.toString();
}
|
0e6937cc-502c-4c59-b870-000a24bd76f4
|
public static String createConcept(String name, ConceptDataType dataType, ConceptClass conceptClass) throws JSONException {
return createConcept(name, dataType, conceptClass, null);
}
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.