SEBSERV-296 fixed

This commit is contained in:
anhefti 2022-04-12 17:01:42 +02:00
parent 554be43828
commit 9956f1a122
4 changed files with 58 additions and 25 deletions

View file

@ -32,6 +32,7 @@ import ch.ethz.seb.sebserver.webservice.datalayer.batis.mapper.ClientConnectionR
import ch.ethz.seb.sebserver.webservice.datalayer.batis.mapper.ClientEventRecordDynamicSqlSupport;
import ch.ethz.seb.sebserver.webservice.datalayer.batis.mapper.ConfigurationNodeRecordDynamicSqlSupport;
import ch.ethz.seb.sebserver.webservice.datalayer.batis.mapper.ExamRecordDynamicSqlSupport;
import ch.ethz.seb.sebserver.webservice.datalayer.batis.mapper.ExamTemplateRecordDynamicSqlSupport;
import ch.ethz.seb.sebserver.webservice.datalayer.batis.mapper.InstitutionRecordDynamicSqlSupport;
import ch.ethz.seb.sebserver.webservice.datalayer.batis.mapper.LmsSetupRecordDynamicSqlSupport;
import ch.ethz.seb.sebserver.webservice.datalayer.batis.mapper.SebClientConfigRecordDynamicSqlSupport;
@ -203,11 +204,11 @@ public class PaginationServiceImpl implements PaginationService {
if (StringUtils.isNotBlank(sortColumnName)) {
switch (sortOrder) {
case DESCENDING: {
PageHelper.orderBy(sortColumnName + " DESC");
PageHelper.orderBy(sortColumnName + " DESC, id DESC");
break;
}
default: {
PageHelper.orderBy(sortColumnName);
PageHelper.orderBy(sortColumnName + ", id");
break;
}
}
@ -265,6 +266,18 @@ public class PaginationServiceImpl implements PaginationService {
this.sortColumnMapping.put(LmsSetupRecordDynamicSqlSupport.lmsSetupRecord.name(), lmsSetupTableMap);
this.defaultSortColumn.put(LmsSetupRecordDynamicSqlSupport.lmsSetupRecord.name(), Domain.LMS_SETUP.ATTR_ID);
// Exam Template Table
final Map<String, String> examTemplateTableMap = new HashMap<>();
examTemplateTableMap.put(Entity.FILTER_ATTR_INSTITUTION, institutionNameRef);
examTemplateTableMap.put(Domain.EXAM_TEMPLATE.ATTR_NAME, ExamTemplateRecordDynamicSqlSupport.name.name());
examTemplateTableMap.put(Domain.EXAM_TEMPLATE.ATTR_EXAM_TYPE,
ExamTemplateRecordDynamicSqlSupport.examType.name());
this.sortColumnMapping.put(ExamTemplateRecordDynamicSqlSupport.examTemplateRecord.name(), examTemplateTableMap);
this.defaultSortColumn.put(
ExamTemplateRecordDynamicSqlSupport.examTemplateRecord.name(),
Domain.EXAM_TEMPLATE.ATTR_ID);
// Exam Table
final Map<String, String> examTableMap = new HashMap<>();
examTableMap.put(Entity.FILTER_ATTR_INSTITUTION, institutionNameRef);

View file

@ -22,6 +22,9 @@ import java.util.stream.Collectors;
import org.apache.commons.lang3.BooleanUtils;
import org.apache.commons.lang3.StringUtils;
import org.mybatis.dynamic.sql.SqlBuilder;
import org.mybatis.dynamic.sql.select.MyBatis3SelectModelAdapter;
import org.mybatis.dynamic.sql.select.QueryExpressionDSL;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
@ -42,6 +45,7 @@ import ch.ethz.seb.sebserver.gbl.util.Result;
import ch.ethz.seb.sebserver.webservice.datalayer.batis.mapper.ExamTemplateRecordDynamicSqlSupport;
import ch.ethz.seb.sebserver.webservice.datalayer.batis.mapper.ExamTemplateRecordMapper;
import ch.ethz.seb.sebserver.webservice.datalayer.batis.mapper.IndicatorRecordDynamicSqlSupport;
import ch.ethz.seb.sebserver.webservice.datalayer.batis.mapper.InstitutionRecordDynamicSqlSupport;
import ch.ethz.seb.sebserver.webservice.datalayer.batis.model.ExamTemplateRecord;
import ch.ethz.seb.sebserver.webservice.servicelayer.bulkaction.impl.BulkAction;
import ch.ethz.seb.sebserver.webservice.servicelayer.dao.AdditionalAttributesDAO;
@ -140,24 +144,38 @@ public class ExamTemplateDAOImpl implements ExamTemplateDAO {
final FilterMap filterMap,
final Predicate<ExamTemplate> predicate) {
return Result.tryCatch(() -> this.examTemplateRecordMapper
.selectByExample()
.where(
ExamTemplateRecordDynamicSqlSupport.institutionId,
isEqualToWhenPresent(filterMap.getInstitutionId()))
.and(
ExamTemplateRecordDynamicSqlSupport.name,
isLikeWhenPresent(filterMap.getExamTemplateName()))
.and(
ExamTemplateRecordDynamicSqlSupport.examType,
isEqualToWhenPresent(filterMap.getString(ExamTemplate.FILTER_ATTR_EXAM_TYPE)))
.build()
.execute()
.stream()
.map(this::toDomainModel)
.flatMap(DAOLoggingSupport::logAndSkipOnError)
.filter(predicate)
.collect(Collectors.toList()));
return Result.tryCatch(() -> {
final QueryExpressionDSL<MyBatis3SelectModelAdapter<List<ExamTemplateRecord>>>.QueryExpressionWhereBuilder whereClause =
(filterMap.getBoolean(FilterMap.ATTR_ADD_INSITUTION_JOIN))
? this.examTemplateRecordMapper
.selectByExample()
.join(InstitutionRecordDynamicSqlSupport.institutionRecord)
.on(InstitutionRecordDynamicSqlSupport.id,
SqlBuilder.equalTo(ExamTemplateRecordDynamicSqlSupport.institutionId))
.where(
ExamTemplateRecordDynamicSqlSupport.institutionId,
isEqualToWhenPresent(filterMap.getInstitutionId()))
: this.examTemplateRecordMapper
.selectByExample()
.where(
ExamTemplateRecordDynamicSqlSupport.institutionId,
isEqualToWhenPresent(filterMap.getInstitutionId()));
return whereClause
.and(
ExamTemplateRecordDynamicSqlSupport.name,
isLikeWhenPresent(filterMap.getExamTemplateName()))
.and(
ExamTemplateRecordDynamicSqlSupport.examType,
isEqualToWhenPresent(filterMap.getString(ExamTemplate.FILTER_ATTR_EXAM_TYPE)))
.build()
.execute()
.stream()
.map(this::toDomainModel)
.flatMap(DAOLoggingSupport::logAndSkipOnError)
.filter(predicate)
.collect(Collectors.toList());
});
}
@Override

View file

@ -15,6 +15,7 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
@ -248,11 +249,12 @@ public abstract class AdministrationAPIIntegrationTester {
}
protected String getOrderedUUIDs(final Collection<? extends Entity> list) {
return list
final List<String> l = list
.stream()
.map(userInfo -> userInfo.getModelId())
.collect(Collectors.toList())
.toString();
.collect(Collectors.toList());
l.sort((s1, s2) -> s1.compareTo(s2));
return l.toString();
}
}

View file

@ -268,7 +268,7 @@ public class UserAPITest extends AdministrationAPIIntegrationTester {
assertTrue(userInfos.numberOfPages == 1);
assertNotNull(userInfos.content);
assertTrue(userInfos.content.size() == 3);
assertEquals("[user5, user2, user1]", getOrderedUUIDs(userInfos.content));
assertEquals("[user1, user2, user5]", getOrderedUUIDs(userInfos.content));
}
@Test
@ -347,7 +347,7 @@ public class UserAPITest extends AdministrationAPIIntegrationTester {
assertTrue(userInfos.numberOfPages == 2);
assertNotNull(userInfos.content);
assertTrue(userInfos.content.size() == 3);
assertEquals("[user7, user6, user4]", getOrderedUUIDs(userInfos.content));
assertEquals("[user4, user6, user7]", getOrderedUUIDs(userInfos.content));
}
@Test