added get Exam GrandEntity to DAO and use it in Controller

This commit is contained in:
anhefti 2020-10-05 15:36:34 +02:00
parent 73a27cb003
commit fcef3c08df
3 changed files with 17 additions and 1 deletions

View file

@ -12,6 +12,7 @@ import java.util.Collection;
import org.springframework.cache.annotation.CacheEvict;
import ch.ethz.seb.sebserver.gbl.model.GrantEntity;
import ch.ethz.seb.sebserver.gbl.model.exam.Exam;
import ch.ethz.seb.sebserver.gbl.model.exam.Exam.ExamStatus;
import ch.ethz.seb.sebserver.gbl.util.Result;
@ -21,6 +22,13 @@ import ch.ethz.seb.sebserver.webservice.servicelayer.session.impl.ExamSessionCac
/** Concrete EntityDAO interface of Exam entities */
public interface ExamDAO extends ActivatableEntityDAO<Exam, Exam>, BulkActionSupportDAO<Exam> {
/** Get a GrantEntity for the exam of specified id (PK)
* This is actually a Exam instance but with no course data loaded.
*
* @param id The id of the exam (PK)
* @return Result referring to the GrantEntity of the exam or to an error when happened */
Result<GrantEntity> examGrantEntityByPK(final Long id);
/** Get all active Exams for a given institution.
*
* @param institutionId the identifier of the institution

View file

@ -33,6 +33,7 @@ import org.springframework.transaction.annotation.Transactional;
import ch.ethz.seb.sebserver.gbl.Constants;
import ch.ethz.seb.sebserver.gbl.api.EntityType;
import ch.ethz.seb.sebserver.gbl.model.EntityKey;
import ch.ethz.seb.sebserver.gbl.model.GrantEntity;
import ch.ethz.seb.sebserver.gbl.model.exam.Exam;
import ch.ethz.seb.sebserver.gbl.model.exam.Exam.ExamStatus;
import ch.ethz.seb.sebserver.gbl.model.exam.Exam.ExamType;
@ -82,6 +83,13 @@ public class ExamDAOImpl implements ExamDAO {
.flatMap(this::toDomainModel);
}
@Override
@Transactional(readOnly = true)
public Result<GrantEntity> examGrantEntityByPK(final Long id) {
return recordById(id)
.map(record -> toDomainModel(record, null).getOrThrow());
}
@Override
@Transactional(readOnly = true)
public Result<Exam> byClientConnection(final Long connectionId) {

View file

@ -108,7 +108,7 @@ public class ExamConfigurationMappingController extends EntityController<ExamCon
}
return this.examDao
.byPK(entity.examId)
.examGrantEntityByPK(entity.examId)
.getOrThrow();
}