SEBSERV-162, SEBSERV-153 implementation break again...
This commit is contained in:
parent
e49a713f72
commit
3143d9ed16
5 changed files with 144 additions and 9 deletions
|
@ -204,4 +204,6 @@ public final class API {
|
|||
public static final String CERTIFICATE_ALIAS = "alias";
|
||||
public static final String CERTIFICATE_ALIAS_VAR_PATH_SEGMENT = "/{" + CERTIFICATE_ALIAS + "}";
|
||||
|
||||
public static final String EXAM_TEMPLATE_ENDPOINT = "/exam-template";
|
||||
|
||||
}
|
||||
|
|
|
@ -9,6 +9,7 @@
|
|||
package ch.ethz.seb.sebserver.gbl.model.exam;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.validation.constraints.NotNull;
|
||||
|
@ -19,6 +20,8 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
|||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
|
||||
import ch.ethz.seb.sebserver.gbl.api.EntityType;
|
||||
import ch.ethz.seb.sebserver.gbl.api.POSTMapper;
|
||||
import ch.ethz.seb.sebserver.gbl.model.Domain;
|
||||
import ch.ethz.seb.sebserver.gbl.model.Domain.EXAM_TEMPLATE;
|
||||
import ch.ethz.seb.sebserver.gbl.model.GrantEntity;
|
||||
import ch.ethz.seb.sebserver.gbl.util.Utils;
|
||||
|
@ -72,6 +75,20 @@ public class ExamTemplate implements GrantEntity {
|
|||
this.examAttributes = Utils.immutableMapOf(examAttributes);
|
||||
}
|
||||
|
||||
public ExamTemplate(
|
||||
final Long institutionId,
|
||||
final Map<String, String> examAttributes,
|
||||
final POSTMapper mapper) {
|
||||
|
||||
this.id = null;
|
||||
this.institutionId = institutionId;
|
||||
this.name = mapper.getString(Domain.EXAM_TEMPLATE.ATTR_NAME);
|
||||
this.description = mapper.getString(Domain.EXAM_TEMPLATE.ATTR_DESCRIPTION);
|
||||
this.configTemplateId = mapper.getLong(Domain.EXAM_TEMPLATE.ATTR_CONFIGURATION_TEMPLATE_ID);
|
||||
this.indicatorTemplates = Collections.emptyList();
|
||||
this.examAttributes = Utils.immutableMapOf(examAttributes);
|
||||
}
|
||||
|
||||
@Override
|
||||
public EntityType entityType() {
|
||||
return EntityType.EXAM_TEMPLATE;
|
||||
|
|
|
@ -12,6 +12,7 @@ import static org.mybatis.dynamic.sql.SqlBuilder.*;
|
|||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.function.Predicate;
|
||||
|
@ -145,15 +146,52 @@ public class ExamTemplateDAOImpl implements ExamTemplateDAO {
|
|||
@Override
|
||||
@Transactional
|
||||
public Result<ExamTemplate> save(final ExamTemplate data) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
return Result.tryCatch(() -> {
|
||||
|
||||
checkUniqueName(data);
|
||||
|
||||
final Collection<Indicator> indicatorTemplates = data.getIndicatorTemplates();
|
||||
final String indicatorsJSON = (indicatorTemplates != null && !indicatorTemplates.isEmpty())
|
||||
? this.jsonMapper.writeValueAsString(indicatorTemplates)
|
||||
: null;
|
||||
|
||||
final Map<String, String> examAttributes = data.getExamAttributes();
|
||||
final String examAttributesJSON = (examAttributes != null && !examAttributes.isEmpty())
|
||||
? this.jsonMapper.writeValueAsString(examAttributes)
|
||||
: null;
|
||||
|
||||
final ExamTemplateRecord newRecord = new ExamTemplateRecord(
|
||||
null,
|
||||
data.institutionId,
|
||||
data.configTemplateId,
|
||||
data.name,
|
||||
data.description,
|
||||
indicatorsJSON,
|
||||
examAttributesJSON);
|
||||
|
||||
this.examTemplateRecordMapper.updateByPrimaryKeySelective(newRecord);
|
||||
return this.examTemplateRecordMapper.selectByPrimaryKey(data.id);
|
||||
})
|
||||
.flatMap(this::toDomainModel)
|
||||
.onError(TransactionHandler::rollback);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public Result<Collection<EntityKey>> delete(final Set<EntityKey> all) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
return Result.tryCatch(() -> {
|
||||
|
||||
final List<Long> ids = extractListOfPKs(all);
|
||||
|
||||
this.examTemplateRecordMapper.deleteByExample()
|
||||
.where(ExamTemplateRecordDynamicSqlSupport.id, isIn(ids))
|
||||
.build()
|
||||
.execute();
|
||||
|
||||
return ids.stream()
|
||||
.map(id -> new EntityKey(id, EntityType.EXAM_TEMPLATE))
|
||||
.collect(Collectors.toList());
|
||||
});
|
||||
}
|
||||
|
||||
private Result<ExamTemplateRecord> recordById(final Long id) {
|
||||
|
|
|
@ -324,11 +324,6 @@ public class ConfigurationNodeController extends EntityController<ConfigurationN
|
|||
this.entityDAO.byPK(modelId)
|
||||
.flatMap(this.authorization::checkModify);
|
||||
|
||||
// final Configuration newConfig = this.configurationDAO
|
||||
// .saveToHistory(modelId)
|
||||
// .flatMap(this.configurationDAO::restoreToDefaultValues)
|
||||
// .getOrThrow();
|
||||
|
||||
final Configuration newConfig = this.configurationDAO
|
||||
.getFollowupConfiguration(modelId)
|
||||
.getOrThrow();
|
||||
|
|
|
@ -0,0 +1,83 @@
|
|||
/*
|
||||
* Copyright (c) 2021 ETH Zürich, Educational Development and Technology (LET)
|
||||
*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
|
||||
package ch.ethz.seb.sebserver.webservice.weblayer.api;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.mybatis.dynamic.sql.SqlTable;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
|
||||
import ch.ethz.seb.sebserver.gbl.api.API;
|
||||
import ch.ethz.seb.sebserver.gbl.api.JSONMapper;
|
||||
import ch.ethz.seb.sebserver.gbl.api.POSTMapper;
|
||||
import ch.ethz.seb.sebserver.gbl.model.Domain;
|
||||
import ch.ethz.seb.sebserver.gbl.model.exam.ExamTemplate;
|
||||
import ch.ethz.seb.sebserver.gbl.profile.WebServiceProfile;
|
||||
import ch.ethz.seb.sebserver.webservice.datalayer.batis.mapper.ExamTemplateRecordDynamicSqlSupport;
|
||||
import ch.ethz.seb.sebserver.webservice.servicelayer.PaginationService;
|
||||
import ch.ethz.seb.sebserver.webservice.servicelayer.authorization.AuthorizationService;
|
||||
import ch.ethz.seb.sebserver.webservice.servicelayer.bulkaction.BulkActionService;
|
||||
import ch.ethz.seb.sebserver.webservice.servicelayer.dao.EntityDAO;
|
||||
import ch.ethz.seb.sebserver.webservice.servicelayer.dao.UserActivityLogDAO;
|
||||
import ch.ethz.seb.sebserver.webservice.servicelayer.validation.BeanValidationService;
|
||||
|
||||
@WebServiceProfile
|
||||
@RestController
|
||||
@RequestMapping("${sebserver.webservice.api.admin.endpoint}" + API.EXAM_TEMPLATE_ENDPOINT)
|
||||
public class ExamTemplateController extends EntityController<ExamTemplate, ExamTemplate> {
|
||||
|
||||
private static final Logger log = LoggerFactory.getLogger(ExamTemplateController.class);
|
||||
|
||||
private final JSONMapper jsonMapper;
|
||||
|
||||
protected ExamTemplateController(
|
||||
final AuthorizationService authorization,
|
||||
final BulkActionService bulkActionService,
|
||||
final EntityDAO<ExamTemplate, ExamTemplate> entityDAO,
|
||||
final UserActivityLogDAO userActivityLogDAO,
|
||||
final PaginationService paginationService,
|
||||
final BeanValidationService beanValidationService,
|
||||
final JSONMapper jsonMapper) {
|
||||
|
||||
super(authorization, bulkActionService, entityDAO, userActivityLogDAO, paginationService,
|
||||
beanValidationService);
|
||||
this.jsonMapper = jsonMapper;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ExamTemplate createNew(final POSTMapper postParams) {
|
||||
final Long institutionId = postParams.getLong(API.PARAM_INSTITUTION_ID);
|
||||
final String attributesJson = postParams.getString(Domain.EXAM_TEMPLATE.ATTR_EXAM_ATTRIBUTES);
|
||||
Map<String, String> examAttributes;
|
||||
try {
|
||||
examAttributes = (StringUtils.isNotBlank(attributesJson))
|
||||
? this.jsonMapper.readValue(attributesJson, new TypeReference<Map<String, String>>() {
|
||||
})
|
||||
: null;
|
||||
return new ExamTemplate(institutionId, examAttributes, postParams);
|
||||
|
||||
} catch (final JsonProcessingException e) {
|
||||
log.error("Failed to parse exam template attributes: ", e);
|
||||
return new ExamTemplate(institutionId, null, postParams);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected SqlTable getSQLTableOfEntity() {
|
||||
return ExamTemplateRecordDynamicSqlSupport.examTemplateRecord;
|
||||
}
|
||||
|
||||
}
|
Loading…
Add table
Reference in a new issue