fixed OrientationCheck
This commit is contained in:
parent
0f8910bb3f
commit
ca1cf4b329
1 changed files with 28 additions and 2 deletions
|
@ -11,7 +11,9 @@ package ch.ethz.seb.sebserver.webservice.datalayer.checks;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
import org.mybatis.dynamic.sql.SqlBuilder;
|
||||||
import org.springframework.context.annotation.Lazy;
|
import org.springframework.context.annotation.Lazy;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
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.profile.WebServiceProfile;
|
||||||
import ch.ethz.seb.sebserver.gbl.util.Result;
|
import ch.ethz.seb.sebserver.gbl.util.Result;
|
||||||
import ch.ethz.seb.sebserver.webservice.DBIntegrityCheck;
|
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.mapper.OrientationRecordMapper;
|
||||||
import ch.ethz.seb.sebserver.webservice.datalayer.batis.model.OrientationRecord;
|
import ch.ethz.seb.sebserver.webservice.datalayer.batis.model.OrientationRecord;
|
||||||
|
|
||||||
|
@ -68,10 +71,15 @@ public class OrientationTableDuplicatesCheck implements DBIntegrityCheck {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tryFix) {
|
if (tryFix) {
|
||||||
toDelete
|
final List<Long> checkedToDelete = toDelete
|
||||||
|
.stream()
|
||||||
|
.filter(this::doubleCheck)
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
|
||||||
|
checkedToDelete
|
||||||
.stream()
|
.stream()
|
||||||
.forEach(this.orientationRecordMapper::deleteByPrimaryKey);
|
.forEach(this.orientationRecordMapper::deleteByPrimaryKey);
|
||||||
return "Fixed duplicates by deletion: " + toDelete;
|
return "Fixed duplicates by deletion: " + checkedToDelete + " from findings:" + toDelete;
|
||||||
} else {
|
} else {
|
||||||
return "Found duplicates: " + toDelete;
|
return "Found duplicates: " + 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
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
final StringBuilder builder = new StringBuilder();
|
final StringBuilder builder = new StringBuilder();
|
||||||
|
|
Loading…
Reference in a new issue