Skip to content

Commit

Permalink
Merge pull request #505 from delageniere/504-esrf-change-beamlineEnum
Browse files Browse the repository at this point in the history
add a boolean to set a beamline to be protected
  • Loading branch information
delageniere authored Nov 16, 2020
2 parents f2414d5 + 5b3fbf0 commit 5017ee1
Show file tree
Hide file tree
Showing 4 changed files with 103 additions and 35 deletions.
9 changes: 2 additions & 7 deletions ispyb-ejb/src/main/java/ispyb/common/util/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -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" };
Expand All @@ -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"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,63 +30,64 @@
public enum ESRFBeamlineEnum {
ID14_1("ID14-1", "id14eh1", new String[] { "ID14 1" },
"<font style='color:#6888A8;font-size:90%'>+3347688<font style='color:#0000FF;font-weight:bold;'>2323</font></font>",
null, false, false),
null, false, false, false),
ID14_2("ID14-2", "id14eh2", new String[] { "ID14 2" },
"<font style='color:#000080;font-size:90%'>+3347688<font style='color:#0000FF;font-weight:bold;'>2565</font></font>",
null, false, false),
null, false, false, false),
ID14_3("ID14-3", "id14eh3", new String[] { "ID14 3" },
"<font style='color:#000080;font-size:90%'>+3347688<font style='color:#0000FF;font-weight:bold;'>2786</font></font>",
null, false, false),
null, false, false, false),
ID14_4("ID14-4", "id14eh4", new String[] { "ID14 4" },
"<font style='color:#000080;font-size:90%'>+3347688<font style='color:#0000FF;font-weight:bold;'>2322</font></font>",
null, false, false),
null, false, false, false),
ID23_1("ID23-1", "id23eh1", new String[] { "ID23 1" },
"<font style='color:#000080;font-size:90%'>+3347688<font style='color:#0000FF;font-weight:bold;'>2261</font></font>",
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" },
"<font style='color:#000080;font-size:90%'>+3347688<font style='color:#0000FF;font-weight:bold;'>2590</font></font>",
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" },
"<font style='color:#000080;font-size:90%'>+3347688<font style='color:#0000FF;font-weight:bold;'>2805</font></font>",
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" },
"<font style='color:#000080;font-size:90%'>+3347688<font style='color:#0000FF;font-weight:bold;'>****</font></font>",
null, true, true),
null, true, true, true),
ID30A2("ID30A-2", "id30a2", new String[] { "ID30A2" },
"<font style='color:#000080;font-size:90%'>+3347688<font style='color:#0000FF;font-weight:bold;'>****</font></font>",
null, true, true),
null, true, true, true),
ID30A3("ID30A-3", "id30a3", new String[] { "ID30A3" },
"<font style='color:#000080;font-size:90%'>+3347688<font style='color:#0000FF;font-weight:bold;'>****</font></font>",
null, true, true),
null, true, true, true),
ID30B("ID30B", "id30b", null,
"<font style='color:#000080;font-size:90%'>+3347688<font style='color:#0000FF;font-weight:bold;'>****</font></font>",
null, true, true),
null, true, true, true),
BM14("BM14", "bm14", new String[] { "BM14U" },
"<font style='color:#000080;font-size:90%'>+3347688<font style='color:#0000FF;font-weight:bold;'>2703</font></font>",
null, false, true),
null, false, true, false),
BM16("BM16", "bm16", null,
"<font style='color:#000080;font-size:90%'>+3347688<font style='color:#0000FF;font-weight:bold;'>2614</font></font>",
null, false, false),
null, false, false, false),
BM29("BM29", "bm29", null,
"<font style='color:#000080;font-size:90%'>+3347688<font style='color:#0000FF;font-weight:bold;'>2628</font></font>",
null, false, true),
null, false, true, false),
BM30A("BM30A", "bm30a", null,
"<font style='color:#000080;font-size:90%'>+3347688<font style='color:#0000FF;font-weight:bold;'>2787</font></font>",
null, false, true),
null, false, true, false),
ID19("ID19", "id19", null,
"<font style='color:#000080;font-size:90%'>+3347688<font style='color:#0000FF;font-weight:bold;'>2700</font></font>",
null, false, true),
CM01("CM01", "cm01", null,"<font style='color:#000080;font-size:90%'>+3347688<font style='color:#0000FF;font-weight:bold;'>****</font></font>", null, false, true);
null, false, true, false),
CM01("CM01", "cm01", null,"<font style='color:#000080;font-size:90%'>+3347688<font style='color:#0000FF;font-weight:bold;'>****</font></font>", 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;
this.phoneNumber = phoneNumber;
this.correctionFiles = correctionFiles;
this.emailNotification = emailNotification;
this.inActivity = inActivity;
this.toBeProtected = toBeProtected;
}

/**
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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()) {
Expand Down Expand Up @@ -241,5 +251,16 @@ public static boolean isBeamlineEmailNotification(String aName) {
}
return false;
}

public static String[] getBeamlineNamesToBeProtected() {
List<String> listBeamlinesToBeProtected = new ArrayList<String>();
for (ESRFBeamlineEnum b : ESRFBeamlineEnum.values()) {
if (b.inActivity && b.toBeProtected)
listBeamlinesToBeProtected.add(b.getBeamlineName());
}
String[] list = listBeamlinesToBeProtected.toArray(new String[listBeamlinesToBeProtected.size()]);

return list;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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 ";

Expand All @@ -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;
Expand Down Expand Up @@ -572,7 +569,6 @@ public Session3VO findByAutoProcProgramId(int autoProcProgramId) {
return null;
}



/**
* launch the data confidentiality for the specified session
Expand All @@ -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();
Expand Down Expand Up @@ -692,7 +696,18 @@ private List<Session3VO> 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*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down

0 comments on commit 5017ee1

Please sign in to comment.