use of org.pentaho.platform.api.engine.IPentahoSession in project pentaho-platform by pentaho.
the class PentahoHttpSessionListener method sessionDestroyed.
public void sessionDestroyed(final HttpSessionEvent event) {
HttpSession session = event.getSession();
try {
if (session != null) {
String sessionId = event.getSession().getId();
// $NON-NLS-1$
Object obj = session.getAttribute(PentahoSystem.PENTAHO_SESSION_KEY);
if (obj != null) {
IPentahoSession userSession = (IPentahoSession) obj;
PentahoSystem.invokeLogoutListeners(userSession);
userSession.destroy();
} else {
String[] info = PentahoHttpSessionListener.getSessionInfo(sessionId);
if (info != null) {
String instanceId = info[5];
String userId = info[3];
String activityId = info[1];
String objectType = info[2];
String processId = info[0];
String messageType = MessageTypes.SESSION_END;
// $NON-NLS-1$
String message = "http ";
// $NON-NLS-1$
String value = "";
long startTime = Long.parseLong(info[4]);
long endTime = new Date().getTime();
if (!"anonymousUser".equals(userId)) {
AuditHelper.audit(instanceId, userId, activityId, objectType, processId, messageType, message, value, ((endTime - startTime) / 1000), null);
}
}
}
}
} catch (Throwable e) {
Logger.error(this, Messages.getInstance().getErrorString("HttpSessionListener.ERROR_0001_ERROR_DESTROYING_SESSION"), // $NON-NLS-1$
e);
}
}
use of org.pentaho.platform.api.engine.IPentahoSession in project pentaho-platform by pentaho.
the class UserConsoleResource method setSessionVariable.
@POST
@Path("/session-variable")
@Facet(name = "Unsupported")
public Response setSessionVariable(@QueryParam("key") String key, @QueryParam("value") String value) {
if (setSessionVarWhiteList.contains(key)) {
IPentahoSession session = UserConsoleService.getPentahoSession();
session.setAttribute(key, value);
return Response.ok(session.getAttribute(key)).build();
}
return Response.status(FORBIDDEN).build();
}
use of org.pentaho.platform.api.engine.IPentahoSession in project pentaho-platform by pentaho.
the class SystemRefreshResource method flushMondrianSchemaCache.
@GET
@Path("/mondrianSchemaCache")
@Produces({ MediaType.TEXT_PLAIN, MediaType.APPLICATION_JSON })
@Facet(name = "Unsupported")
public Response flushMondrianSchemaCache() {
if (canAdminister()) {
IPentahoSession pentahoSession = PentahoSessionHolder.getSession();
if (canAdminister()) {
// Flush the catalog helper (legacy)
IMondrianCatalogService mondrianCatalogService = // $NON-NLS-1$
PentahoSystem.get(IMondrianCatalogService.class, "IMondrianCatalogService", pentahoSession);
mondrianCatalogService.reInit(pentahoSession);
// Flush the IOlapService
IOlapService olapService = // $NON-NLS-1$
PentahoSystem.get(IOlapService.class, "IOlapService", pentahoSession);
olapService.flushAll(pentahoSession);
}
return Response.ok().type(MediaType.TEXT_PLAIN).build();
} else {
return Response.status(UNAUTHORIZED).build();
}
}
use of org.pentaho.platform.api.engine.IPentahoSession in project pentaho-platform by pentaho.
the class SystemRefreshResource method refreshMetadata.
@GET
@Path("/metadata")
@Facet(name = "Unsupported")
@Produces(TEXT_PLAIN)
public String refreshMetadata() {
String result = null;
IPentahoSession pentahoSession = PentahoSessionHolder.getSession();
if (canAdminister()) {
result = PentahoSystem.publish(pentahoSession, org.pentaho.platform.engine.services.metadata.MetadataPublisher.class.getName());
}
return result;
}
use of org.pentaho.platform.api.engine.IPentahoSession in project pentaho-platform by pentaho.
the class SchedulerServiceTest method testGetJobState.
@Test
public void testGetJobState() throws Exception {
JobRequest mockJobRequest = mock(JobRequest.class);
String jobId = "jobId";
doReturn(jobId).when(mockJobRequest).getJobId();
IPentahoSession mockSession = mock(IPentahoSession.class);
doReturn(mockSession).when(schedulerService).getSession();
Job mockJob = mock(Job.class);
doReturn(mockJob).when(schedulerService).getJob(jobId);
doReturn(Job.JobState.BLOCKED).when(mockJob).getState();
String username = "username";
doReturn(username).when(mockJob).getUserName();
doReturn(username).when(mockSession).getName();
// Test 1
doReturn(true).when(schedulerService).isScheduleAllowed();
Job.JobState testState = schedulerService.getJobState(mockJobRequest);
assertEquals(Job.JobState.BLOCKED, testState);
// Test 2
doReturn(false).when(schedulerService).isScheduleAllowed();
testState = schedulerService.getJobState(mockJobRequest);
assertEquals(Job.JobState.BLOCKED, testState);
verify(mockJobRequest, times(2)).getJobId();
verify(schedulerService, times(1)).getSession();
verify(schedulerService, times(2)).getJob(jobId);
verify(mockJob, times(2)).getState();
verify(mockJob, times(1)).getUserName();
verify(mockSession, times(1)).getName();
}
Aggregations