DCTM:xCP:Extension Getting session from expression editor

/**
	 * Get the session object of the current user
	 * @return the DFC session object
	 */
	private static IDfSession getSession() {
		Object value = ExpressionExecutionContext
				.getContext(ExpressionExecutionContext.SESSION);
		IDfSession session = null;
		if (value != null && value instanceof IDfSession) {
			session = (IDfSession) value;
		} else {
			throw new RuntimeException(
					"Docbase session cannot be null. Set the Expression execution context before invoking the function.");
		}
		return session;
	}
@XcpFunction(name = "getTicket", category = STR_MYINSIGHT)
	public static String getTicket() {
		GetTicketFunction gtf = new GetTicketFunction();
		DfLogger.info(gtf, String.format(STR_FUNCTION + STR_START, gtf
				.getClass().getSimpleName()), null, null);
		String result = "";
		IDfSession session = getSession();
		try {
			result = session.getLoginTicket();
		} catch (DfException e) {
			throw new RuntimeException("Could not execute custom funcation", e);
		}
		DfLogger.info(gtf, String.format(STR_FUNCTION + STR_END, gtf.getClass()
				.getSimpleName()), null, null);
		return result;
	}

Leave a Reply

Your email address will not be published.