SEBSERV-133 institution

This commit is contained in:
anhefti 2022-05-04 16:22:55 +02:00
parent 53f4d8363a
commit ebcbc134af
5 changed files with 51 additions and 19 deletions

View file

@ -81,7 +81,6 @@ import ch.ethz.seb.sebserver.gui.service.remote.webservice.api.institution.GetIn
import ch.ethz.seb.sebserver.gui.service.remote.webservice.api.lmssetup.GetLmsSetupNames;
import ch.ethz.seb.sebserver.gui.service.remote.webservice.api.seb.cert.GetCertificateNames;
import ch.ethz.seb.sebserver.gui.service.remote.webservice.api.seb.examconfig.GetExamConfigNodeNames;
import ch.ethz.seb.sebserver.gui.service.remote.webservice.api.seb.examconfig.GetExamConfigNodes;
import ch.ethz.seb.sebserver.gui.service.remote.webservice.api.seb.examconfig.GetViews;
import ch.ethz.seb.sebserver.gui.service.remote.webservice.api.useraccount.GetUserAccountNames;
import ch.ethz.seb.sebserver.gui.service.remote.webservice.auth.CurrentUser;
@ -748,7 +747,7 @@ public class ResourceService {
public List<Tuple<String>> getExamConfigTemplateResourcesSelection(final boolean withEmpty) {
final UserInfo userInfo = this.currentUser.get();
final List<Tuple<String>> collect = this.restService.getBuilder(GetExamConfigNodes.class)
final List<Tuple<String>> collect = this.restService.getBuilder(GetExamConfigNodeNames.class)
.withQueryParam(Entity.FILTER_ATTR_INSTITUTION, String.valueOf(userInfo.getInstitutionId()))
.withQueryParam(ConfigurationNode.FILTER_ATTR_TYPE, ConfigurationType.TEMPLATE.name())
.call()

View file

@ -258,13 +258,13 @@ public class BulkActionServiceImpl implements BulkActionService {
this.supporter.get(EntityType.CERTIFICATE),
this.supporter.get(EntityType.BATCH_ACTION),
this.supporter.get(EntityType.USER),
this.supporter.get(EntityType.EXAM_TEMPLATE),
this.supporter.get(EntityType.EXAM),
this.supporter.get(EntityType.INDICATOR),
this.supporter.get(EntityType.SEB_CLIENT_CONFIGURATION),
this.supporter.get(EntityType.EXAM_CONFIGURATION_MAP),
this.supporter.get(EntityType.CLIENT_CONNECTION),
this.supporter.get(EntityType.CONFIGURATION_NODE));
this.supporter.get(EntityType.CONFIGURATION_NODE),
this.supporter.get(EntityType.EXAM_CONFIGURATION_MAP),
this.supporter.get(EntityType.EXAM_TEMPLATE));
case USER:
return Arrays.asList(
this.supporter.get(EntityType.EXAM),

View file

@ -254,17 +254,20 @@ public class ConfigurationNodeDAOImpl implements ConfigurationNodeDAO {
.build()
.execute();
// delete all ConfigurationValue's that belongs to the Configuration's to delete
this.configurationValueRecordMapper.deleteByExample()
.where(ConfigurationValueRecordDynamicSqlSupport.configurationId, isIn(configurationIds))
.build()
.execute();
if (!configurationIds.isEmpty()) {
// delete all Configuration's
this.configurationRecordMapper.deleteByExample()
.where(ConfigurationRecordDynamicSqlSupport.id, isIn(configurationIds))
.build()
.execute();
// delete all ConfigurationValue's that belongs to the Configuration's to delete
this.configurationValueRecordMapper.deleteByExample()
.where(ConfigurationValueRecordDynamicSqlSupport.configurationId, isIn(configurationIds))
.build()
.execute();
// delete all Configuration's
this.configurationRecordMapper.deleteByExample()
.where(ConfigurationRecordDynamicSqlSupport.id, isIn(configurationIds))
.build()
.execute();
}
// and finally delete the requested ConfigurationNode's
this.configurationNodeRecordMapper.deleteByExample()

View file

@ -385,6 +385,11 @@ public class ExamTemplateDAOImpl implements ExamTemplateDAO {
@Override
public Set<EntityDependency> getDependencies(final BulkAction bulkAction) {
// all of institution
if (bulkAction.sourceType == EntityType.INSTITUTION) {
return getDependencies(bulkAction, this::allIdsOfInstitution);
}
return Collections.emptySet();
}
@ -553,4 +558,19 @@ public class ExamTemplateDAOImpl implements ExamTemplateDAO {
.orElse(-1L) + 1;
}
private Result<Collection<EntityDependency>> allIdsOfInstitution(final EntityKey institutionKey) {
return Result.tryCatch(() -> this.examTemplateRecordMapper.selectByExample()
.where(ExamTemplateRecordDynamicSqlSupport.institutionId,
isEqualTo(Long.valueOf(institutionKey.modelId)))
.build()
.execute()
.stream()
.map(rec -> new EntityDependency(
institutionKey,
new EntityKey(rec.getId(), EntityType.EXAM_TEMPLATE),
rec.getName(),
rec.getDescription()))
.collect(Collectors.toList()));
}
}

View file

@ -142,7 +142,7 @@ public class SEBClientConnectionServiceImpl implements SEBClientConnectionServic
}
if (examId != null) {
checkExamIntegrity(examId);
checkExamIntegrity(examId, institutionId);
}
// Create ClientConnection in status CONNECTION_REQUESTED for further processing
@ -226,7 +226,7 @@ public class SEBClientConnectionServiceImpl implements SEBClientConnectionServic
}
if (examId != null) {
checkExamIntegrity(examId);
checkExamIntegrity(examId, institutionId);
}
if (log.isDebugEnabled()) {
@ -412,7 +412,7 @@ public class SEBClientConnectionServiceImpl implements SEBClientConnectionServic
.getOrThrow();
// check exam integrity for established connection
checkExamIntegrity(establishedClientConnection.examId);
checkExamIntegrity(establishedClientConnection.examId, institutionId);
// initialize distributed indicator value caches if possible and needed
if (examId != null && this.isDistributedSetup) {
@ -828,7 +828,7 @@ public class SEBClientConnectionServiceImpl implements SEBClientConnectionServic
return clientConnection;
}
private void checkExamIntegrity(final Long examId) {
private void checkExamIntegrity(final Long examId, final Long institutionId) {
if (this.isDistributedSetup) {
// if the cached Exam is not up to date anymore, we have to update the cache first
final Result<Exam> updateExamCache = this.examSessionService.updateExamCache(examId);
@ -844,6 +844,16 @@ public class SEBClientConnectionServiceImpl implements SEBClientConnectionServic
"Exam is currently on update and locked for new SEB Client connections");
}
// check Exam is within the correct institution
if (this.examSessionService.getRunningExam(examId)
.map(e -> !e.institutionId.equals(institutionId))
.onError(error -> log.error("Failed to get running exam: ", error))
.getOr(true)) {
throw new APIConstraintViolationException(
"Exam institution mismatch. The requested exam is not within the expected institution");
}
// check Exam has a default SEB Exam configuration attached
if (!this.examSessionService.hasDefaultConfigurationAttached(examId)) {
throw new APIConstraintViolationException(