diff --git a/ispyb-ejb/src/main/java/ispyb/server/common/services/ws/rest/session/SessionServiceBean.java b/ispyb-ejb/src/main/java/ispyb/server/common/services/ws/rest/session/SessionServiceBean.java index c27271a0c..60336089c 100644 --- a/ispyb-ejb/src/main/java/ispyb/server/common/services/ws/rest/session/SessionServiceBean.java +++ b/ispyb-ejb/src/main/java/ispyb/server/common/services/ws/rest/session/SessionServiceBean.java @@ -57,32 +57,12 @@ public class SessionServiceBean extends WsServiceBean implements SessionService private String ByProposalAndDates = getViewTableQuery() + " where v_session.proposalId = :proposalId and " + dateClause + " order by v_session.sessionId DESC"; - private String ByBeamlineOperator = getViewTableQuery() + " where v_session.beamLineOperator LIKE :beamlineOperator order by v_session.sessionId DESC"; private String getViewTableQuery(){ return this.getQueryFromResourceFile("/queries/session/getViewTableQuery.sql"); } - /** - * Query from the view v_session - * @return - */ -// private String getViewTableQuery(){ -// return "select *,\n" + -// "(select count(*) from EnergyScan where EnergyScan.sessionId = v_session.sessionId) as energyScanCount,\n" -// + " (select count(distinct(blSampleId)) from DataCollectionGroup where DataCollectionGroup.sessionId = v_session.sessionId) as sampleCount," -// + " (select sum(DataCollection.numberOfImages) from DataCollectionGroup, DataCollection where DataCollectionGroup.sessionId = v_session.sessionId and DataCollection.dataCollectionGroupId = DataCollectionGroup.dataCollectionGroupId) as imagesCount," -// + " (select count(*) from DataCollectionGroup, DataCollection where DataCollectionGroup.sessionId = v_session.sessionId and DataCollection.dataCollectionGroupId = DataCollectionGroup.dataCollectionGroupId and DataCollection.numberOfImages < 5) as testDataCollectionGroupCount," -// + " (select count(*) from DataCollectionGroup, DataCollection where DataCollectionGroup.sessionId = v_session.sessionId and DataCollection.dataCollectionGroupId = DataCollectionGroup.dataCollectionGroupId and DataCollection.numberOfImages > 4) as dataCollectionGroupCount," -// + " (select count(*) from XFEFluorescenceSpectrum where XFEFluorescenceSpectrum.sessionId = v_session.sessionId) as xrfSpectrumCount,\n" -// + " (select count(*) from Experiment exp1 where v_session.sessionId = exp1.sessionId and exp1.experimentType='HPLC') as hplcCount," -// + " (select count(*) from Experiment exp2 where v_session.sessionId = exp2.sessionId and exp2.experimentType='STATIC') as sampleChangerCount," -// + " (select count(*) from Experiment exp3 where v_session.sessionId = exp3.sessionId and exp3.experimentType='CALIBRATION') as calibrationCount," -// + " (select experimentType from DataCollectionGroup where DataCollectionGroup.dataCollectionGroupId = (select max(dataCollectionGroupId) from DataCollectionGroup dg2 where dg2.sessionId = v_session.sessionId)) as lastExperimentDataCollectionGroup,\n" -// + " (select endTime from DataCollectionGroup where DataCollectionGroup.dataCollectionGroupId = (select max(dataCollectionGroupId) from DataCollectionGroup dg2 where dg2.sessionId = v_session.sessionId)) as lastEndTimeDataCollectionGroup\n" -// + "from v_session"; -// } @Override public List> getSessionViewBySessionId(int proposalId, int sessionId) { @@ -113,12 +93,6 @@ public List> getSessionViewByDates(String startDate, String return executeSQLQuery(query); } -// private List> executeSQLQuery(SQLQuery query ){ -// query.setResultTransformer(AliasToEntityMapResultTransformer.INSTANCE); -// List> aliasToValueMapList = query.list(); -// return aliasToValueMapList; -// } - @Override public List> getSessionViewByProposalAndDates(int proposalId, String startDate, String endDate) { Session session = (Session) this.entityManager.getDelegate(); diff --git a/ispyb-ws/src/main/java/ispyb/ws/rest/RestWebService.java b/ispyb-ws/src/main/java/ispyb/ws/rest/RestWebService.java index 5d7950888..4ec371512 100644 --- a/ispyb-ws/src/main/java/ispyb/ws/rest/RestWebService.java +++ b/ispyb-ws/src/main/java/ispyb/ws/rest/RestWebService.java @@ -1,5 +1,10 @@ package ispyb.ws.rest; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +import ispyb.server.common.vos.login.Login3VO; import ispyb.ws.ParentWebService; import javax.ws.rs.Path; @@ -9,5 +14,25 @@ public class RestWebService extends ParentWebService { protected long now; + protected List> getProposalsFromToken (String token) throws Exception { + Login3VO login3VO = this.getLogin3Service().findByToken(token); + List> proposals = new ArrayList>(); + + if (login3VO != null){ + if (login3VO.isValid()){ + + if (login3VO.isLocalContact() || login3VO.isManager()){ + proposals = this.getProposal3Service().findProposals(); + } + else{ + proposals = this.getProposal3Service().findProposals(login3VO.getUsername()); + } + } + } else { + throw new Exception("Token is not valid"); + } + return (proposals); + + } } \ No newline at end of file diff --git a/ispyb-ws/src/main/java/ispyb/ws/rest/mx/MXRestWebService.java b/ispyb-ws/src/main/java/ispyb/ws/rest/mx/MXRestWebService.java index db6e0863d..83dfc44c3 100644 --- a/ispyb-ws/src/main/java/ispyb/ws/rest/mx/MXRestWebService.java +++ b/ispyb-ws/src/main/java/ispyb/ws/rest/mx/MXRestWebService.java @@ -2,12 +2,14 @@ import java.util.ArrayList; import java.util.List; +import java.util.Map; import javax.naming.NamingException; import ispyb.server.biosaxs.services.core.experiment.Experiment3Service; import ispyb.server.biosaxs.services.core.structure.Structure3Service; import ispyb.server.common.util.ejb.Ejb3ServiceLocator; +import ispyb.server.common.vos.login.Login3VO; import ispyb.server.mx.services.autoproc.AutoProc3Service; import ispyb.server.mx.services.autoproc.AutoProcIntegration3Service; import ispyb.server.mx.services.autoproc.AutoProcProgram3Service; @@ -53,7 +55,8 @@ protected AutoProcessingDataParser getAutoprocessingParserByAutoProcIntegrationL } } return new AutoProcessingDataParser(lists); - } + } + protected Experiment3Service getExperiment3Service() throws NamingException { return (Experiment3Service) Ejb3ServiceLocator.getInstance().getLocalService(Experiment3Service.class); diff --git a/ispyb-ws/src/main/java/ispyb/ws/rest/proposal/ProposalRestWebService.java b/ispyb-ws/src/main/java/ispyb/ws/rest/proposal/ProposalRestWebService.java index 5f59ab3aa..fb7433b7c 100644 --- a/ispyb-ws/src/main/java/ispyb/ws/rest/proposal/ProposalRestWebService.java +++ b/ispyb-ws/src/main/java/ispyb/ws/rest/proposal/ProposalRestWebService.java @@ -5,7 +5,6 @@ import ispyb.server.biosaxs.vos.dataAcquisition.StockSolution3VO; import ispyb.server.biosaxs.vos.dataAcquisition.plate.Platetype3VO; import ispyb.server.common.exceptions.AccessDeniedException; -import ispyb.server.common.vos.login.Login3VO; import ispyb.server.common.vos.proposals.LabContact3VO; import ispyb.server.common.vos.proposals.Proposal3VO; import ispyb.server.mx.vos.collections.Session3VO; @@ -171,26 +170,6 @@ public Response listProposal(@PathParam("token") String token, @PathParam("propo } } - private List> getProposalsFromToken (String token) throws Exception { - Login3VO login3VO = this.getLogin3Service().findByToken(token); - List> proposals = new ArrayList>(); - - if (login3VO != null){ - if (login3VO.isValid()){ - - if (login3VO.isLocalContact() || login3VO.isManager()){ - proposals = this.getProposal3Service().findProposals(); - } - else{ - proposals = this.getProposal3Service().findProposals(login3VO.getUsername()); - } - } - } else { - throw new Exception("Token is not valid"); - } - return (proposals); - - } @RolesAllowed({"User", "Manager", "Industrial", "Localcontact"}) @GET diff --git a/ispyb-ws/src/main/java/ispyb/ws/rest/proposal/SessionRestWebService.java b/ispyb-ws/src/main/java/ispyb/ws/rest/proposal/SessionRestWebService.java index 67ca6aab1..e91685163 100644 --- a/ispyb-ws/src/main/java/ispyb/ws/rest/proposal/SessionRestWebService.java +++ b/ispyb-ws/src/main/java/ispyb/ws/rest/proposal/SessionRestWebService.java @@ -54,6 +54,29 @@ public Response saveSessionComments( return this.sendResponse(true); } + + @RolesAllowed({"User", "Manager", "Industrial", "Localcontact"}) + @GET + @Path("{token}/session/list") + @Produces({ "application/json" }) + public Response getSessionList(@PathParam("token") String token) throws Exception { + String methodName = "getSessionList"; + long id = this.logInit(methodName, logger, token); + try { + List> proposals = this.getProposalsFromToken(token); + List> sessions = new ArrayList>(); + for (Map proposal : proposals) { + logger.info("Getting sessions from proposal " + proposal.get("Proposal_proposalId")); + sessions.addAll(getSessionService().getSessionViewByProposalId((int) proposal.get("Proposal_proposalId"))); + } + this.logFinish(methodName, id, logger); + return this.sendResponse(sessions); + } catch (Exception e) { + return this.logError("getSessionList", e, id, logger); + } + } + + @RolesAllowed({ "User", "Manager", "Industrial", "Localcontact" }) @GET @GZIP