Search in sources :

Example 71 with IPentahoSession

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);
    }
}
Also used : HttpSession(javax.servlet.http.HttpSession) IPentahoSession(org.pentaho.platform.api.engine.IPentahoSession) Date(java.util.Date)

Example 72 with IPentahoSession

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();
}
Also used : IPentahoSession(org.pentaho.platform.api.engine.IPentahoSession) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Facet(org.codehaus.enunciate.Facet)

Example 73 with IPentahoSession

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();
    }
}
Also used : IOlapService(org.pentaho.platform.plugin.action.olap.IOlapService) IPentahoSession(org.pentaho.platform.api.engine.IPentahoSession) IMondrianCatalogService(org.pentaho.platform.plugin.action.mondrian.catalog.IMondrianCatalogService) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) Facet(org.codehaus.enunciate.Facet)

Example 74 with IPentahoSession

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;
}
Also used : IPentahoSession(org.pentaho.platform.api.engine.IPentahoSession) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) Facet(org.codehaus.enunciate.Facet)

Example 75 with IPentahoSession

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();
}
Also used : JobRequest(org.pentaho.platform.web.http.api.resources.JobRequest) IPentahoSession(org.pentaho.platform.api.engine.IPentahoSession) Matchers.anyString(org.mockito.Matchers.anyString) Job(org.pentaho.platform.api.scheduler2.Job) Test(org.junit.Test)

Aggregations

IPentahoSession (org.pentaho.platform.api.engine.IPentahoSession)231 StandaloneSession (org.pentaho.platform.engine.core.system.StandaloneSession)76 Test (org.junit.Test)70 Matchers.anyString (org.mockito.Matchers.anyString)40 ArrayList (java.util.ArrayList)32 ITenant (org.pentaho.platform.api.mt.ITenant)22 IOException (java.io.IOException)20 StandaloneObjectFactory (org.pentaho.platform.engine.core.system.objfac.StandaloneObjectFactory)18 File (java.io.File)17 RepositoryFile (org.pentaho.platform.api.repository2.unified.RepositoryFile)16 Before (org.junit.Before)14 OutputStream (java.io.OutputStream)13 HashMap (java.util.HashMap)13 InputStream (java.io.InputStream)12 IRuntimeContext (org.pentaho.platform.api.engine.IRuntimeContext)12 ModelInfo (org.pentaho.platform.dataaccess.datasource.wizard.models.ModelInfo)12 Domain (org.pentaho.metadata.model.Domain)11 ObjectFactoryException (org.pentaho.platform.api.engine.ObjectFactoryException)11 List (java.util.List)10 IPentahoResultSet (org.pentaho.commons.connection.IPentahoResultSet)10