diff --git a/src/main/java/ch/ethz/seb/sebserver/webservice/datalayer/checks/OrientationTableDuplicatesCheck.java b/src/main/java/ch/ethz/seb/sebserver/webservice/datalayer/checks/OrientationTableDuplicatesCheck.java index 0a391e44..9a61513b 100644 --- a/src/main/java/ch/ethz/seb/sebserver/webservice/datalayer/checks/OrientationTableDuplicatesCheck.java +++ b/src/main/java/ch/ethz/seb/sebserver/webservice/datalayer/checks/OrientationTableDuplicatesCheck.java @@ -11,7 +11,9 @@ package ch.ethz.seb.sebserver.webservice.datalayer.checks; import java.util.HashSet; import java.util.List; import java.util.Set; +import java.util.stream.Collectors; +import org.mybatis.dynamic.sql.SqlBuilder; import org.springframework.context.annotation.Lazy; import org.springframework.stereotype.Component; import org.springframework.transaction.annotation.Transactional; @@ -19,6 +21,7 @@ import org.springframework.transaction.annotation.Transactional; import ch.ethz.seb.sebserver.gbl.profile.WebServiceProfile; import ch.ethz.seb.sebserver.gbl.util.Result; import ch.ethz.seb.sebserver.webservice.DBIntegrityCheck; +import ch.ethz.seb.sebserver.webservice.datalayer.batis.mapper.OrientationRecordDynamicSqlSupport; import ch.ethz.seb.sebserver.webservice.datalayer.batis.mapper.OrientationRecordMapper; import ch.ethz.seb.sebserver.webservice.datalayer.batis.model.OrientationRecord; @@ -68,7 +71,12 @@ public class OrientationTableDuplicatesCheck implements DBIntegrityCheck { } if (tryFix) { - toDelete + final List checkedToDelete = toDelete + .stream() + .filter(this::doubleCheck) + .collect(Collectors.toList()); + + checkedToDelete .stream() .forEach(this.orientationRecordMapper::deleteByPrimaryKey); return "Fixed duplicates by deletion: " + toDelete; @@ -79,6 +87,24 @@ public class OrientationTableDuplicatesCheck implements DBIntegrityCheck { }); } + private boolean doubleCheck(final Long id) { + try { + final OrientationRecord selectByPrimaryKey = this.orientationRecordMapper.selectByPrimaryKey(id); + final Long count = this.orientationRecordMapper.countByExample() + .where( + OrientationRecordDynamicSqlSupport.configAttributeId, + SqlBuilder.isEqualTo(selectByPrimaryKey.getConfigAttributeId())) + .and( + OrientationRecordDynamicSqlSupport.templateId, + SqlBuilder.isEqualTo(selectByPrimaryKey.getTemplateId())) + .build() + .execute(); + return count != null && count.longValue() > 1; + } catch (final Exception e) { + return false; + } + } + @Override public String toString() { final StringBuilder builder = new StringBuilder(); diff --git a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/session/impl/indicator/PingIntervalClientIndicator.java b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/session/impl/indicator/PingIntervalClientIndicator.java index 4461963a..7b2c80b5 100644 --- a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/session/impl/indicator/PingIntervalClientIndicator.java +++ b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/session/impl/indicator/PingIntervalClientIndicator.java @@ -87,7 +87,8 @@ public final class PingIntervalClientIndicator extends AbstractPingIndicator { this.lastUpdate = this.distributedIndicatorValueService.lastUpdate(); } - return currentTimeMillis - value; + final double res = currentTimeMillis - value; + return res >= 0.0D ? res : 0.0D; } @Override diff --git a/src/main/java/ch/ethz/seb/sebserver/webservice/weblayer/api/ExamAPI_V1_Controller.java b/src/main/java/ch/ethz/seb/sebserver/webservice/weblayer/api/ExamAPI_V1_Controller.java index 04918acb..a6a042b1 100644 --- a/src/main/java/ch/ethz/seb/sebserver/webservice/weblayer/api/ExamAPI_V1_Controller.java +++ b/src/main/java/ch/ethz/seb/sebserver/webservice/weblayer/api/ExamAPI_V1_Controller.java @@ -286,23 +286,23 @@ public class ExamAPI_V1_Controller { public void ping(final HttpServletRequest request, final HttpServletResponse response) { final String connectionToken = request.getHeader(API.EXAM_API_SEB_CONNECTION_TOKEN); - final String timeStampString = request.getParameter(API.EXAM_API_PING_TIMESTAMP); + //final String timeStampString = request.getParameter(API.EXAM_API_PING_TIMESTAMP); final String pingNumString = request.getParameter(API.EXAM_API_PING_NUMBER); final String instructionConfirm = request.getParameter(API.EXAM_API_PING_INSTRUCTION_CONFIRM); - long pingTime; - try { - pingTime = Long.parseLong(timeStampString); - } catch (final Exception e) { - log.error("Invalid ping request: {}", connectionToken); - response.setStatus(HttpStatus.INTERNAL_SERVER_ERROR.value()); - return; - } +// long pingTime; +// try { +// pingTime = Long.parseLong(timeStampString); +// } catch (final Exception e) { +// log.error("Invalid ping request: {}", connectionToken); +// response.setStatus(HttpStatus.INTERNAL_SERVER_ERROR.value()); +// return; +// } final String instruction = this.sebClientConnectionService .notifyPing( connectionToken, - pingTime, + Utils.getMillisecondsNow(), pingNumString != null ? Integer.parseInt(pingNumString) : -1, instructionConfirm);