Skip to content

Commit

Permalink
Merge pull request #424 from antolinos/issue_423
Browse files Browse the repository at this point in the history
It fixes issue #423
  • Loading branch information
antolinos authored Feb 22, 2019
2 parents ea09e9c + a7d04c7 commit 5111745
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 48 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<Map<String, Object>> getSessionViewBySessionId(int proposalId, int sessionId) {
Expand Down Expand Up @@ -113,12 +93,6 @@ public List<Map<String, Object>> getSessionViewByDates(String startDate, String
return executeSQLQuery(query);
}

// private List<Map<String, Object>> executeSQLQuery(SQLQuery query ){
// query.setResultTransformer(AliasToEntityMapResultTransformer.INSTANCE);
// List<Map<String, Object>> aliasToValueMapList = query.list();
// return aliasToValueMapList;
// }

@Override
public List<Map<String, Object>> getSessionViewByProposalAndDates(int proposalId, String startDate, String endDate) {
Session session = (Session) this.entityManager.getDelegate();
Expand Down
25 changes: 25 additions & 0 deletions ispyb-ws/src/main/java/ispyb/ws/rest/RestWebService.java
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -9,5 +14,25 @@ public class RestWebService extends ParentWebService {
protected long now;


protected List<Map<String, Object>> getProposalsFromToken (String token) throws Exception {
Login3VO login3VO = this.getLogin3Service().findByToken(token);
List<Map<String, Object>> proposals = new ArrayList<Map<String,Object>>();

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);

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -53,7 +55,8 @@ protected AutoProcessingDataParser getAutoprocessingParserByAutoProcIntegrationL
}
}
return new AutoProcessingDataParser(lists);
}
}


protected Experiment3Service getExperiment3Service() throws NamingException {
return (Experiment3Service) Ejb3ServiceLocator.getInstance().getLocalService(Experiment3Service.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -171,26 +170,6 @@ public Response listProposal(@PathParam("token") String token, @PathParam("propo
}
}

private List<Map<String, Object>> getProposalsFromToken (String token) throws Exception {
Login3VO login3VO = this.getLogin3Service().findByToken(token);
List<Map<String, Object>> proposals = new ArrayList<Map<String,Object>>();

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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Map<String, Object>> proposals = this.getProposalsFromToken(token);
List<Map<String, Object>> sessions = new ArrayList<Map<String,Object>>();
for (Map<String, Object> 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
Expand Down

0 comments on commit 5111745

Please sign in to comment.