diff --git a/ispyb-ejb/src/main/java/ispyb/common/util/Constants.java b/ispyb-ejb/src/main/java/ispyb/common/util/Constants.java index 63f746a5e..cf19321d9 100644 --- a/ispyb-ejb/src/main/java/ispyb/common/util/Constants.java +++ b/ispyb-ejb/src/main/java/ispyb/common/util/Constants.java @@ -856,10 +856,8 @@ public static final boolean SITE_USERPORTAL_LINK_IS_SMIS() { /* * sets of constants */ - // public static final String[] BEAMLINE_LOCATION_ESRF = { "ID14-1", "ID14-2", "ID14-3", "ID14-4", "ID23-1", - // "ID23-2", - // "ID29", "BM14U", "BM16", "ID14 1", "ID14 2", "ID14 3", "ID14 4", "ID23 1", "ID23 2", "BM29", "BM30A" }; - + // for ESRF, it is replaced by ESRFBeamlineEnum + public static final String[] BEAMLINE_LOCATION_DLS = { "i02", "i03", "i04", "i04-1", "i24" }; public static final String[] BEAMLINE_LOCATION_MAXIV = { "BioMAX", "MX" }; @@ -885,9 +883,6 @@ public static String getSAXSBeamline() { } } - // public static final String[] BEAMLINE_LOCATION = (SITE_IS_ESRF()) ? BEAMLINE_LOCATION_ESRF - // : (SITE_IS_DLS()) ? BEAMLINE_LOCATION_DLS : BEAMLINE_LOCATION_DEFAULT; - public static final String[] BEAMLINE_LOCATION = BEAMLINE_LOCATION_DEFAULT; public static final int LOCATIONS_IN_SC = Integer.parseInt(getProperty("samplechanger.locations", "5")); diff --git a/ispyb-ejb/src/main/java/ispyb/common/util/beamlines/ESRFBeamlineEnum.java b/ispyb-ejb/src/main/java/ispyb/common/util/beamlines/ESRFBeamlineEnum.java index 13a97882c..da9ea9cd2 100644 --- a/ispyb-ejb/src/main/java/ispyb/common/util/beamlines/ESRFBeamlineEnum.java +++ b/ispyb-ejb/src/main/java/ispyb/common/util/beamlines/ESRFBeamlineEnum.java @@ -30,56 +30,56 @@ public enum ESRFBeamlineEnum { ID14_1("ID14-1", "id14eh1", new String[] { "ID14 1" }, "+33476882323", - null, false, false), + null, false, false, false), ID14_2("ID14-2", "id14eh2", new String[] { "ID14 2" }, "+33476882565", - null, false, false), + null, false, false, false), ID14_3("ID14-3", "id14eh3", new String[] { "ID14 3" }, "+33476882786", - null, false, false), + null, false, false, false), ID14_4("ID14-4", "id14eh4", new String[] { "ID14 4" }, "+33476882322", - null, false, false), + null, false, false, false), ID23_1("ID23-1", "id23eh1", new String[] { "ID23 1" }, "+33476882261", - new String[] { "x_geo_corr.cbf", "y_geo_corr.cbf" }, false, true), + new String[] { "x_geo_corr.cbf", "y_geo_corr.cbf" }, false, true, true), ID23_2("ID23-2", "id23eh2", new String[] { "ID23 2" }, "+33476882590", - new String[] { "x_geo_corr.cbf", "y_geo_corr.cbf" }, false, true), + new String[] { "x_geo_corr.cbf", "y_geo_corr.cbf" }, false, true, true), ID29("ID29", "id29", new String[] { "ID29" }, "+33476882805", - new String[] { "x_geo_corr.cbf", "y_geo_corr.cbf" }, false, true), + new String[] { "x_geo_corr.cbf", "y_geo_corr.cbf" }, false, true, true), ID30A1("ID30A-1", "id30a1", new String[] { "ID30A1" }, "+3347688****", - null, true, true), + null, true, true, true), ID30A2("ID30A-2", "id30a2", new String[] { "ID30A2" }, "+3347688****", - null, true, true), + null, true, true, true), ID30A3("ID30A-3", "id30a3", new String[] { "ID30A3" }, "+3347688****", - null, true, true), + null, true, true, true), ID30B("ID30B", "id30b", null, "+3347688****", - null, true, true), + null, true, true, true), BM14("BM14", "bm14", new String[] { "BM14U" }, "+33476882703", - null, false, true), + null, false, true, false), BM16("BM16", "bm16", null, "+33476882614", - null, false, false), + null, false, false, false), BM29("BM29", "bm29", null, "+33476882628", - null, false, true), + null, false, true, false), BM30A("BM30A", "bm30a", null, "+33476882787", - null, false, true), + null, false, true, false), ID19("ID19", "id19", null, "+33476882700", - null, false, true), - CM01("CM01", "cm01", null,"+3347688****", null, false, true); + null, false, true, false), + CM01("CM01", "cm01", null,"+3347688****", null, false, true, false); private ESRFBeamlineEnum(String beamlineName, String directoryName, String[] associatedName, String phoneNumber, - String[] correctionFiles, boolean emailNotification, boolean inActivity) { + String[] correctionFiles, boolean emailNotification, boolean inActivity, boolean toBeProtected) { this.beamlineName = beamlineName; this.directoryName = directoryName; this.associatedName = associatedName; @@ -87,6 +87,7 @@ private ESRFBeamlineEnum(String beamlineName, String directoryName, String[] ass this.correctionFiles = correctionFiles; this.emailNotification = emailNotification; this.inActivity = inActivity; + this.toBeProtected = toBeProtected; } /** @@ -127,6 +128,11 @@ private ESRFBeamlineEnum(String beamlineName, String directoryName, String[] ass * experiment tab. */ private final boolean inActivity; + + /** + * toBeProtected: true if the beamline data shall be protected by calling the dataprotection webservice. + */ + private final boolean toBeProtected; public String getBeamlineName() { return this.beamlineName; @@ -155,6 +161,10 @@ public boolean isEmailNotification() { public boolean isInActivity() { return inActivity; } + + public boolean isToBeProtected() { + return toBeProtected; + } public static ESRFBeamlineEnum retrieveBeamlineWithName(String aName) { for (ESRFBeamlineEnum b : ESRFBeamlineEnum.values()) { @@ -241,5 +251,16 @@ public static boolean isBeamlineEmailNotification(String aName) { } return false; } + + public static String[] getBeamlineNamesToBeProtected() { + List listBeamlinesToBeProtected = new ArrayList(); + for (ESRFBeamlineEnum b : ESRFBeamlineEnum.values()) { + if (b.inActivity && b.toBeProtected) + listBeamlinesToBeProtected.add(b.getBeamlineName()); + } + String[] list = listBeamlinesToBeProtected.toArray(new String[listBeamlinesToBeProtected.size()]); + + return list; + } } diff --git a/ispyb-ejb/src/main/java/ispyb/server/common/services/sessions/Session3ServiceBean.java b/ispyb-ejb/src/main/java/ispyb/server/common/services/sessions/Session3ServiceBean.java index 6ff09e981..101d7bc21 100644 --- a/ispyb-ejb/src/main/java/ispyb/server/common/services/sessions/Session3ServiceBean.java +++ b/ispyb-ejb/src/main/java/ispyb/server/common/services/sessions/Session3ServiceBean.java @@ -138,9 +138,6 @@ private static String getProposalCodeNumberOldQuery() { String query = "select * " + " FROM BLSession ses, Proposal pro " + "WHERE ses.proposalId = pro.proposalId AND pro.proposalCode like :code AND pro.proposalNumber = :number " - // + - // "AND ses.startDate <= " + now + " AND (ses.endDate >= " + now + - // " OR ses.endDate IS NULL) ORDER BY sessionId DESC "; + "AND ses.endDate >= " + Constants.MYSQL_ORACLE_CURRENT_DATE + " AND ses.startDate <= " + Constants.MYSQL_ORACLE_CURRENT_DATE + " ORDER BY sessionId DESC "; @@ -155,11 +152,11 @@ private static String getProposalCodeNumberOldQuery() { + " WHERE DataCollection.dataCollectionGroupId = DataCollectionGroup.dataCollectionGroupId" + " and DataCollection.numberOfImages <=4 and DataCollectionGroup.sessionId = :sessionId "; - private final String[] beamlinesToProtect = { "ID29", "ID23-1", "ID23-2", "ID30A-1", "ID30A-2","ID30A-3", "ID30B", "CM01" }; + //private final String[] beamlinesToProtect = { "ID29", "ID23-1", "ID23-2", "ID30A-1", "ID30A-2","ID30A-3", "ID30B" }; + private final String[] beamlinesToProtect = ESRFBeamlineEnum.getBeamlineNamesToBeProtected(); private final String[] account_not_to_protect = { "OPID", "OPD", "MXIHR" }; - @PersistenceContext(unitName = "ispyb_db") private EntityManager entityManager; @@ -572,7 +569,6 @@ public Session3VO findByAutoProcProgramId(int autoProcProgramId) { return null; } - /** * launch the data confidentiality for the specified session @@ -581,16 +577,24 @@ public void protectSession(Integer sessionId) throws Exception { if (sessionId != null) { Session3VO sessionVO = this.findByPk(sessionId, false, false, false); - LOG.info("session to be protected = " + sessionId); + LOG.info("session to be protected = " + sessionId); // Check if the session exists if (sessionVO == null) { - LOG.info("session does not exist"); + LOG.info("session does not exist"); + } + // Check if the beamline shall be protected + else if (ESRFBeamlineEnum.retrieveBeamlineWithName(sessionVO.getBeamlineName()) == null ) { + LOG.info("beamline shall not be protected : " + sessionVO.getBeamlineName()); + } + // Check if the beamline shall be protected + else if (!ESRFBeamlineEnum.retrieveBeamlineWithName(sessionVO.getBeamlineName()).isToBeProtected()) { + LOG.info("beamline shall not be protected : " + sessionVO.getBeamlineName()); } // Check if the session is already protected else if (sessionVO.getProtectedData() != null && sessionVO.getProtectedData().equals("OK")) { LOG.info("session is already protected : " + sessionVO.getProtectedData()); - } else { + } else { // Check the minimum delay to protect : 2 hours Date lastUpdate = sessionVO.getLastUpdate(); @@ -692,7 +696,18 @@ private List findSessionToBeProtected(Integer delay, Integer window) crit.add(Restrictions.ge("lastUpdate", date1)); if (date2 != null) crit.add(Restrictions.le("lastUpdate", date2)); - + + String[] beamlinesToProtect = ESRFBeamlineEnum.getBeamlineNamesToBeProtected(); + + if (LOG.isDebugEnabled()) { + String beamlines = ""; + for (String beamline: beamlinesToProtect) { + beamlines = beamlines + " " + beamline; + }; + LOG.debug("beamlinesToProtect: " + beamlines); + } + + crit.add(Restrictions.in("beamlineName", beamlinesToProtect)); // account not to protect: opid*, opd*, mxihr* diff --git a/ispyb-ws/src/main/java/ispyb/ws/soap/mx/ToolsForCollectionWebService.java b/ispyb-ws/src/main/java/ispyb/ws/soap/mx/ToolsForCollectionWebService.java index f7a59825b..2ffa41a1e 100644 --- a/ispyb-ws/src/main/java/ispyb/ws/soap/mx/ToolsForCollectionWebService.java +++ b/ispyb-ws/src/main/java/ispyb/ws/soap/mx/ToolsForCollectionWebService.java @@ -214,6 +214,43 @@ public SessionWS3VO[] findSessionsByProposalAndBeamLine(@WebParam(name = "code") throw e; } } + + /** + * returns the sessions to be protected afetr a dealy and in a particular window + * this WS is only used for tests on ESRF site + * + * @param delay + * @param window + * @return + * @throws Exception + */ + @WebMethod + @WebResult(name = "Sessions") + public SessionWS3VO[] findSessionsToBeProtected(@WebParam(name = "delay") Integer delay, + @WebParam(name = "window") Integer window) throws Exception { + + try { + LOG.debug("findSessionsToBeProtected( : delay= " + delay + ", window= " + window); + long startTime = System.currentTimeMillis(); + Session3Service sessionService = (Session3Service) ejb3ServiceLocator.getLocalService(Session3Service.class); + + SessionWS3VO[] ret = sessionService.findForWSToBeProtected(delay, window); + + if (ret == null || ret.length <1) { + LOG.debug("findSessionsToBeProtected no sessions found ") ; + } + + long endTime = System.currentTimeMillis(); + long duration = endTime - startTime; + LOG.debug("findSessionsToBeProtected(delay= " + delay + ", window= " + window + + " time = " + duration + " ms"); + return ret; + + } catch (Exception e) { + LOG.error("WS ERROR: findSessionsToBeProtected - " + StringUtils.getCurrentDate() + " - " + delay + ", " + window); + throw e; + } + } @WebMethod @WebResult(name = "session")