From ebcbc134af91f5b840df10253a3a367674e9da36 Mon Sep 17 00:00:00 2001 From: anhefti Date: Wed, 4 May 2022 16:22:55 +0200 Subject: [PATCH] SEBSERV-133 institution --- .../gui/service/ResourceService.java | 3 +-- .../impl/BulkActionServiceImpl.java | 6 ++--- .../dao/impl/ConfigurationNodeDAOImpl.java | 23 +++++++++++-------- .../dao/impl/ExamTemplateDAOImpl.java | 20 ++++++++++++++++ .../impl/SEBClientConnectionServiceImpl.java | 18 +++++++++++---- 5 files changed, 51 insertions(+), 19 deletions(-) diff --git a/src/main/java/ch/ethz/seb/sebserver/gui/service/ResourceService.java b/src/main/java/ch/ethz/seb/sebserver/gui/service/ResourceService.java index 0799b45b..59422e38 100644 --- a/src/main/java/ch/ethz/seb/sebserver/gui/service/ResourceService.java +++ b/src/main/java/ch/ethz/seb/sebserver/gui/service/ResourceService.java @@ -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> getExamConfigTemplateResourcesSelection(final boolean withEmpty) { final UserInfo userInfo = this.currentUser.get(); - final List> collect = this.restService.getBuilder(GetExamConfigNodes.class) + final List> collect = this.restService.getBuilder(GetExamConfigNodeNames.class) .withQueryParam(Entity.FILTER_ATTR_INSTITUTION, String.valueOf(userInfo.getInstitutionId())) .withQueryParam(ConfigurationNode.FILTER_ATTR_TYPE, ConfigurationType.TEMPLATE.name()) .call() diff --git a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/bulkaction/impl/BulkActionServiceImpl.java b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/bulkaction/impl/BulkActionServiceImpl.java index ae9aa095..b782532b 100644 --- a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/bulkaction/impl/BulkActionServiceImpl.java +++ b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/bulkaction/impl/BulkActionServiceImpl.java @@ -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), diff --git a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/dao/impl/ConfigurationNodeDAOImpl.java b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/dao/impl/ConfigurationNodeDAOImpl.java index 36dfed99..148a868a 100644 --- a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/dao/impl/ConfigurationNodeDAOImpl.java +++ b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/dao/impl/ConfigurationNodeDAOImpl.java @@ -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() diff --git a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/dao/impl/ExamTemplateDAOImpl.java b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/dao/impl/ExamTemplateDAOImpl.java index a4fae45a..240ad1ac 100644 --- a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/dao/impl/ExamTemplateDAOImpl.java +++ b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/dao/impl/ExamTemplateDAOImpl.java @@ -385,6 +385,11 @@ public class ExamTemplateDAOImpl implements ExamTemplateDAO { @Override public Set 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> 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())); + } + } diff --git a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/session/impl/SEBClientConnectionServiceImpl.java b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/session/impl/SEBClientConnectionServiceImpl.java index 619df19e..4e326223 100644 --- a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/session/impl/SEBClientConnectionServiceImpl.java +++ b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/session/impl/SEBClientConnectionServiceImpl.java @@ -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 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(