SEBSERV-44 added Controllers
This commit is contained in:
parent
998c31e418
commit
c0f68c1340
14 changed files with 466 additions and 40 deletions
|
@ -70,8 +70,11 @@ public final class API {
|
|||
public static final String CONFIGURATION_NODE_ENDPOINT = "/configuration_node";
|
||||
|
||||
public static final String CONFIGURATION_ENDPOINT = "/configuration";
|
||||
public static final String CONFIGURATION_SAVE_TO_HISTORY_PATH_SEGMENT = "/save_to_history";
|
||||
public static final String CONFIGURATION_RESTORE_FROM_HISTORY_PATH_SEGMENT = "/restore";
|
||||
|
||||
public static final String CONFIGURATION_VALUE_ENDPOINT = "/configuration_value";
|
||||
public static final String CONFIGURATION_TABLE_VALUE_PATH_SEGMENT = "/table";
|
||||
|
||||
public static final String CONFIGURATION_ATTRIBUTE_ENDPOINT = "/configuration_attribute";
|
||||
|
||||
|
|
|
@ -18,8 +18,10 @@ import com.fasterxml.jackson.annotation.JsonProperty;
|
|||
|
||||
import ch.ethz.seb.sebserver.gbl.Constants;
|
||||
import ch.ethz.seb.sebserver.gbl.api.EntityType;
|
||||
import ch.ethz.seb.sebserver.gbl.model.GrantEntity;
|
||||
import ch.ethz.seb.sebserver.gbl.api.POSTMapper;
|
||||
import ch.ethz.seb.sebserver.gbl.model.Domain;
|
||||
import ch.ethz.seb.sebserver.gbl.model.Domain.CONFIGURATION;
|
||||
import ch.ethz.seb.sebserver.gbl.model.GrantEntity;
|
||||
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public final class Configuration implements GrantEntity {
|
||||
|
@ -67,6 +69,15 @@ public final class Configuration implements GrantEntity {
|
|||
this.followup = followup;
|
||||
}
|
||||
|
||||
public Configuration(final Long institutionId, final POSTMapper postParams) {
|
||||
this.id = null;
|
||||
this.institutionId = institutionId;
|
||||
this.configurationNodeId = postParams.getLong(Domain.CONFIGURATION.ATTR_CONFIGURATION_NODE_ID);
|
||||
this.version = postParams.getString(Domain.CONFIGURATION.ATTR_VERSION);
|
||||
this.versionDate = postParams.getDateTime(Domain.CONFIGURATION.ATTR_VERSION_DATE);
|
||||
this.followup = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public EntityType entityType() {
|
||||
return EntityType.CONFIGURATION;
|
||||
|
|
|
@ -16,7 +16,9 @@ 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.Activatable;
|
||||
import ch.ethz.seb.sebserver.gbl.model.Domain;
|
||||
import ch.ethz.seb.sebserver.gbl.model.Domain.CONFIGURATION_NODE;
|
||||
import ch.ethz.seb.sebserver.gbl.model.GrantEntity;
|
||||
|
||||
|
@ -78,11 +80,21 @@ public final class ConfigurationNode implements GrantEntity, Activatable {
|
|||
this.name = name;
|
||||
this.description = description;
|
||||
this.type = type;
|
||||
|
||||
this.owner = owner;
|
||||
this.active = active;
|
||||
}
|
||||
|
||||
public ConfigurationNode(final Long institutionId, final POSTMapper postParams) {
|
||||
this.id = null;
|
||||
this.institutionId = institutionId;
|
||||
this.templateId = postParams.getLong(Domain.CONFIGURATION_NODE.ATTR_TEMPLATE_ID);
|
||||
this.name = postParams.getString(Domain.CONFIGURATION_NODE.ATTR_NAME);
|
||||
this.description = postParams.getString(Domain.CONFIGURATION_NODE.ATTR_DESCRIPTION);
|
||||
this.type = postParams.getEnum(Domain.CONFIGURATION_NODE.ATTR_TYPE, ConfigurationType.class);
|
||||
this.owner = postParams.getString(Domain.CONFIGURATION_NODE.ATTR_OWNER);
|
||||
this.active = postParams.getBoolean(Domain.CONFIGURATION_NODE.ATTR_ACTIVE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public EntityType entityType() {
|
||||
return EntityType.CONFIGURATION_NODE;
|
||||
|
|
|
@ -18,8 +18,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.model.GrantEntity;
|
||||
import ch.ethz.seb.sebserver.gbl.model.Domain.CONFIGURATION_VALUE;
|
||||
import ch.ethz.seb.sebserver.gbl.model.GrantEntity;
|
||||
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public final class ConfigurationTableValue implements GrantEntity {
|
||||
|
@ -31,9 +31,11 @@ public final class ConfigurationTableValue implements GrantEntity {
|
|||
@JsonProperty(CONFIGURATION_VALUE.ATTR_INSTITUTION_ID)
|
||||
public final Long institutionId;
|
||||
|
||||
@NotNull
|
||||
@JsonProperty(CONFIGURATION_VALUE.ATTR_CONFIGURATION_ID)
|
||||
public final Long configurationId;
|
||||
|
||||
@NotNull
|
||||
@JsonProperty(CONFIGURATION_VALUE.ATTR_CONFIGURATION_ATTRIBUTE_ID)
|
||||
public final Long attributeId;
|
||||
|
||||
|
|
|
@ -15,8 +15,10 @@ 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.model.GrantEntity;
|
||||
import ch.ethz.seb.sebserver.gbl.api.POSTMapper;
|
||||
import ch.ethz.seb.sebserver.gbl.model.Domain;
|
||||
import ch.ethz.seb.sebserver.gbl.model.Domain.CONFIGURATION_VALUE;
|
||||
import ch.ethz.seb.sebserver.gbl.model.GrantEntity;
|
||||
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public final class ConfigurationValue implements GrantEntity {
|
||||
|
@ -60,6 +62,15 @@ public final class ConfigurationValue implements GrantEntity {
|
|||
this.value = value;
|
||||
}
|
||||
|
||||
public ConfigurationValue(final Long institutionId, final POSTMapper postParams) {
|
||||
this.id = null;
|
||||
this.institutionId = institutionId;
|
||||
this.configurationId = postParams.getLong(Domain.CONFIGURATION_VALUE.ATTR_CONFIGURATION_ID);
|
||||
this.attributeId = postParams.getLong(Domain.CONFIGURATION_VALUE.ATTR_CONFIGURATION_ATTRIBUTE_ID);
|
||||
this.listIndex = postParams.getInteger(Domain.CONFIGURATION_VALUE.ATTR_LIST_INDEX);
|
||||
this.value = postParams.getString(Domain.CONFIGURATION_VALUE.ATTR_VALUE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getModelId() {
|
||||
return (this.id != null)
|
||||
|
|
|
@ -40,7 +40,7 @@ public interface ConfigurationDAO extends EntityDAO<Configuration, Configuration
|
|||
* @param configurationNodeId the identifier of the ConfigurationNode to create a new history entry form current
|
||||
* follow-up
|
||||
* @return the new follow-up Configuration model */
|
||||
Result<Configuration> saveInHistory(Long configurationNodeId);
|
||||
Result<Configuration> saveToHistory(Long configurationNodeId);
|
||||
|
||||
/** Restores the current follow-up Configuration to the values of a given Configuration
|
||||
* in the history of the specified ConfigurationNode.
|
||||
|
|
|
@ -8,15 +8,27 @@
|
|||
|
||||
package ch.ethz.seb.sebserver.webservice.servicelayer.dao;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Set;
|
||||
|
||||
import ch.ethz.seb.sebserver.gbl.model.EntityKey;
|
||||
import ch.ethz.seb.sebserver.gbl.model.sebconfig.ConfigurationTableValue;
|
||||
import ch.ethz.seb.sebserver.gbl.model.sebconfig.ConfigurationValue;
|
||||
import ch.ethz.seb.sebserver.gbl.util.Result;
|
||||
|
||||
public interface ConfigurationValueDAO extends EntityDAO<ConfigurationValue, ConfigurationValue> {
|
||||
|
||||
/** NOTE: Deletion is not supported for ConfigurationValue.
|
||||
* A ConfigurationValue get automatically deleted on deletion of a Configuration */
|
||||
@Override
|
||||
default Result<Collection<EntityKey>> delete(final Set<EntityKey> all) {
|
||||
throw new UnsupportedOperationException(
|
||||
"Deletion is not supported for ConfigurationValue. A ConfigurationValue get automatically deleted on deletion of a Configuration");
|
||||
}
|
||||
|
||||
Result<ConfigurationTableValue> getTableValue(
|
||||
Long institutionId,
|
||||
Long attributeId,
|
||||
final Long institutionId,
|
||||
final Long attributeId,
|
||||
final Long configurationId);
|
||||
|
||||
Result<ConfigurationTableValue> saveTableValue(ConfigurationTableValue value);
|
||||
|
|
|
@ -142,7 +142,7 @@ public class ConfigurationDAOImpl implements ConfigurationDAO {
|
|||
|
||||
@Override
|
||||
@Transactional
|
||||
public Result<Configuration> saveInHistory(final Long configurationNodeId) {
|
||||
public Result<Configuration> saveToHistory(final Long configurationNodeId) {
|
||||
return Result.tryCatch(() -> {
|
||||
|
||||
// get follow-up configuration...
|
||||
|
|
|
@ -441,14 +441,16 @@ public class ConfigurationNodeDAOImpl implements ConfigurationNodeDAO {
|
|||
attrRec.getId(),
|
||||
attrRec.getDefaultValue());
|
||||
|
||||
batchValueMapper.insert(new ConfigurationValueRecord(
|
||||
null,
|
||||
configNode.institutionId,
|
||||
config.getId(),
|
||||
attrRec.getId(),
|
||||
0,
|
||||
bigValue ? null : value,
|
||||
bigValue ? value : null));
|
||||
if (StringUtils.isNoneBlank(value)) {
|
||||
batchValueMapper.insert(new ConfigurationValueRecord(
|
||||
null,
|
||||
configNode.institutionId,
|
||||
config.getId(),
|
||||
attrRec.getId(),
|
||||
0,
|
||||
bigValue ? null : value,
|
||||
bigValue ? value : null));
|
||||
}
|
||||
});
|
||||
|
||||
batchSession.flushStatements();
|
||||
|
|
|
@ -20,13 +20,13 @@ import java.util.Set;
|
|||
import java.util.function.Predicate;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.apache.commons.lang3.BooleanUtils;
|
||||
import org.mybatis.dynamic.sql.SqlBuilder;
|
||||
import org.springframework.context.annotation.Lazy;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import ch.ethz.seb.sebserver.gbl.api.EntityType;
|
||||
import ch.ethz.seb.sebserver.gbl.model.EntityKey;
|
||||
import ch.ethz.seb.sebserver.gbl.model.sebconfig.AttributeType;
|
||||
import ch.ethz.seb.sebserver.gbl.model.sebconfig.AttributeValueType;
|
||||
import ch.ethz.seb.sebserver.gbl.model.sebconfig.ConfigurationTableValue;
|
||||
|
@ -123,8 +123,11 @@ public class ConfigurationValueDAOImpl implements ConfigurationValueDAO {
|
|||
@Transactional
|
||||
public Result<ConfigurationValue> createNew(final ConfigurationValue data) {
|
||||
return checkInstitutionalIntegrity(data)
|
||||
.flatMap(v -> attributeRecordById(v.attributeId))
|
||||
.map(this::checkFollowUpIntegrity)
|
||||
.map(this::checkCreationIntegrity)
|
||||
.flatMap(this::attributeRecord)
|
||||
.map(attributeRecord -> {
|
||||
|
||||
final String value = (data.value != null)
|
||||
? data.value
|
||||
: attributeRecord.getDefaultValue();
|
||||
|
@ -148,8 +151,11 @@ public class ConfigurationValueDAOImpl implements ConfigurationValueDAO {
|
|||
@Override
|
||||
@Transactional
|
||||
public Result<ConfigurationValue> save(final ConfigurationValue data) {
|
||||
return attributeRecordById(data.attributeId)
|
||||
return checkInstitutionalIntegrity(data)
|
||||
.map(this::checkFollowUpIntegrity)
|
||||
.flatMap(this::attributeRecord)
|
||||
.map(attributeRecord -> {
|
||||
|
||||
final boolean bigValue = isBigValue(attributeRecord);
|
||||
final ConfigurationValueRecord newRecord = new ConfigurationValueRecord(
|
||||
data.id,
|
||||
|
@ -167,24 +173,6 @@ public class ConfigurationValueDAOImpl implements ConfigurationValueDAO {
|
|||
.onErrorDo(TransactionHandler::rollback);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public Result<Collection<EntityKey>> delete(final Set<EntityKey> all) {
|
||||
return Result.tryCatch(() -> {
|
||||
|
||||
final List<Long> ids = extractListOfPKs(all);
|
||||
|
||||
this.configurationValueRecordMapper.deleteByExample()
|
||||
.where(ConfigurationValueRecordDynamicSqlSupport.id, isIn(ids))
|
||||
.build()
|
||||
.execute();
|
||||
|
||||
return ids.stream()
|
||||
.map(id -> new EntityKey(id, EntityType.CONFIGURATION_VALUE))
|
||||
.collect(Collectors.toList());
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(readOnly = true)
|
||||
public Result<ConfigurationTableValue> getTableValue(
|
||||
|
@ -257,14 +245,16 @@ public class ConfigurationValueDAOImpl implements ConfigurationValueDAO {
|
|||
new ArrayList<>(valueMapping.keySet()),
|
||||
values);
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public Result<ConfigurationTableValue> saveTableValue(final ConfigurationTableValue value) {
|
||||
return attributeRecordById(value.attributeId)
|
||||
return checkInstitutionalIntegrity(value)
|
||||
.map(this::checkFollowUpIntegrity)
|
||||
.flatMap(val -> attributeRecordById(val.attributeId))
|
||||
.map(attributeRecord -> {
|
||||
|
||||
final List<ConfigurationAttributeRecord> columnAttributes =
|
||||
this.configurationAttributeRecordMapper.selectByExample()
|
||||
.where(
|
||||
|
@ -317,6 +307,10 @@ public class ConfigurationValueDAOImpl implements ConfigurationValueDAO {
|
|||
});
|
||||
}
|
||||
|
||||
private Result<ConfigurationAttributeRecord> attributeRecord(final ConfigurationValue value) {
|
||||
return attributeRecordById(value.attributeId);
|
||||
}
|
||||
|
||||
private Result<ConfigurationAttributeRecord> attributeRecordById(final Long id) {
|
||||
return Result.tryCatch(() -> {
|
||||
final ConfigurationAttributeRecord record = this.configurationAttributeRecordMapper
|
||||
|
@ -373,4 +367,56 @@ public class ConfigurationValueDAOImpl implements ConfigurationValueDAO {
|
|||
});
|
||||
}
|
||||
|
||||
private Result<ConfigurationTableValue> checkInstitutionalIntegrity(final ConfigurationTableValue data) {
|
||||
return Result.tryCatch(() -> {
|
||||
final ConfigurationRecord r = this.configurationRecordMapper.selectByPrimaryKey(data.configurationId);
|
||||
if (r.getInstitutionId().longValue() != data.institutionId.longValue()) {
|
||||
throw new IllegalArgumentException("Institutional integrity constraint violation");
|
||||
}
|
||||
return data;
|
||||
});
|
||||
}
|
||||
|
||||
private ConfigurationTableValue checkFollowUpIntegrity(final ConfigurationTableValue data) {
|
||||
checkFollowUp(data.configurationId);
|
||||
return data;
|
||||
}
|
||||
|
||||
private ConfigurationValue checkFollowUpIntegrity(final ConfigurationValue data) {
|
||||
checkFollowUp(data.configurationId);
|
||||
return data;
|
||||
}
|
||||
|
||||
private void checkFollowUp(final Long configurationId) {
|
||||
final ConfigurationRecord config = this.configurationRecordMapper
|
||||
.selectByPrimaryKey(configurationId);
|
||||
|
||||
if (!BooleanUtils.toBoolean(config.getFollowup())) {
|
||||
throw new IllegalArgumentException(
|
||||
"Forbidden to modify an configuration value of a none follow-up configuration");
|
||||
}
|
||||
}
|
||||
|
||||
private ConfigurationValue checkCreationIntegrity(final ConfigurationValue data) {
|
||||
final Long exists = this.configurationValueRecordMapper.countByExample()
|
||||
.where(
|
||||
ConfigurationValueRecordDynamicSqlSupport.configurationId,
|
||||
isEqualTo(data.configurationId))
|
||||
.and(
|
||||
ConfigurationValueRecordDynamicSqlSupport.configurationAttributeId,
|
||||
isEqualTo(data.attributeId))
|
||||
.and(
|
||||
ConfigurationValueRecordDynamicSqlSupport.listIndex,
|
||||
isEqualTo(data.listIndex))
|
||||
.build()
|
||||
.execute();
|
||||
|
||||
if (exists != null && exists.longValue() > 0) {
|
||||
throw new IllegalArgumentException(
|
||||
"The configuration value already exists");
|
||||
}
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -49,7 +49,6 @@ public class ConfigurationAttributeController extends EntityController<Configura
|
|||
|
||||
@Override
|
||||
protected ConfigurationAttribute createNew(final POSTMapper postParams) {
|
||||
// TODO Auto-generated method stub
|
||||
return new ConfigurationAttribute(postParams);
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,135 @@
|
|||
/*
|
||||
* Copyright (c) 2019 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.Collection;
|
||||
|
||||
import org.mybatis.dynamic.sql.SqlTable;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.util.MultiValueMap;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import ch.ethz.seb.sebserver.gbl.api.API;
|
||||
import ch.ethz.seb.sebserver.gbl.api.API.BulkActionType;
|
||||
import ch.ethz.seb.sebserver.gbl.api.EntityType;
|
||||
import ch.ethz.seb.sebserver.gbl.api.POSTMapper;
|
||||
import ch.ethz.seb.sebserver.gbl.model.EntityKey;
|
||||
import ch.ethz.seb.sebserver.gbl.model.EntityProcessingReport;
|
||||
import ch.ethz.seb.sebserver.gbl.model.GrantEntity;
|
||||
import ch.ethz.seb.sebserver.gbl.model.sebconfig.Configuration;
|
||||
import ch.ethz.seb.sebserver.gbl.profile.WebServiceProfile;
|
||||
import ch.ethz.seb.sebserver.webservice.datalayer.batis.mapper.ConfigurationRecordDynamicSqlSupport;
|
||||
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.ConfigurationDAO;
|
||||
import ch.ethz.seb.sebserver.webservice.servicelayer.dao.ConfigurationNodeDAO;
|
||||
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.CONFIGURATION_ENDPOINT)
|
||||
public class ConfigurationController extends EntityController<Configuration, Configuration> {
|
||||
|
||||
private final ConfigurationDAO configurationDAO;
|
||||
private final ConfigurationNodeDAO configurationNodeDAO;
|
||||
|
||||
protected ConfigurationController(
|
||||
final AuthorizationService authorization,
|
||||
final BulkActionService bulkActionService,
|
||||
final ConfigurationDAO entityDAO,
|
||||
final UserActivityLogDAO userActivityLogDAO,
|
||||
final PaginationService paginationService,
|
||||
final BeanValidationService beanValidationService,
|
||||
final ConfigurationNodeDAO configurationNodeDAO) {
|
||||
|
||||
super(authorization,
|
||||
bulkActionService,
|
||||
entityDAO,
|
||||
userActivityLogDAO,
|
||||
paginationService,
|
||||
beanValidationService);
|
||||
|
||||
this.configurationDAO = entityDAO;
|
||||
this.configurationNodeDAO = configurationNodeDAO;
|
||||
}
|
||||
|
||||
@RequestMapping(
|
||||
path = API.CONFIGURATION_SAVE_TO_HISTORY_PATH_SEGMENT + API.MODEL_ID_VAR_PATH_SEGMENT,
|
||||
method = RequestMethod.POST,
|
||||
consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE,
|
||||
produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
|
||||
public Configuration saveToHistory(@PathVariable final String configId) {
|
||||
|
||||
return this.entityDAO.byModelId(configId)
|
||||
.flatMap(this::checkModifyAccess)
|
||||
.flatMap(config -> this.configurationDAO.saveToHistory(config.configurationNodeId))
|
||||
.getOrThrow();
|
||||
}
|
||||
|
||||
@RequestMapping(
|
||||
path = API.CONFIGURATION_RESTORE_FROM_HISTORY_PATH_SEGMENT + API.MODEL_ID_VAR_PATH_SEGMENT,
|
||||
method = RequestMethod.POST,
|
||||
consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE,
|
||||
produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
|
||||
public Configuration restoreFormHistory(
|
||||
@PathVariable final String configId,
|
||||
@RequestParam(name = API.PARAM_PARENT_MODEL_ID, required = true) final Long configurationNodeId) {
|
||||
|
||||
return this.entityDAO.byModelId(configId)
|
||||
.flatMap(this::checkModifyAccess)
|
||||
.flatMap(config -> this.configurationDAO.restoreToVersion(configurationNodeId, config.getId()))
|
||||
.getOrThrow();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<EntityKey> getDependencies(final String modelId, final BulkActionType bulkActionType) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Configuration create(final MultiValueMap<String, String> allRequestParams, final Long institutionId) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public EntityProcessingReport hardDelete(final String modelId) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Configuration createNew(final POSTMapper postParams) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected SqlTable getSQLTableOfEntity() {
|
||||
return ConfigurationRecordDynamicSqlSupport.configurationRecord;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected GrantEntity toGrantEntity(final Configuration entity) {
|
||||
if (entity == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return this.configurationNodeDAO.byPK(entity.configurationNodeId)
|
||||
.getOrThrow();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected EntityType getGrantEntityType() {
|
||||
return EntityType.CONFIGURATION_NODE;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,59 @@
|
|||
/*
|
||||
* Copyright (c) 2019 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 org.mybatis.dynamic.sql.SqlTable;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import ch.ethz.seb.sebserver.gbl.api.API;
|
||||
import ch.ethz.seb.sebserver.gbl.api.POSTMapper;
|
||||
import ch.ethz.seb.sebserver.gbl.model.sebconfig.ConfigurationNode;
|
||||
import ch.ethz.seb.sebserver.gbl.profile.WebServiceProfile;
|
||||
import ch.ethz.seb.sebserver.webservice.datalayer.batis.mapper.ConfigurationNodeRecordDynamicSqlSupport;
|
||||
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.ConfigurationNodeDAO;
|
||||
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.CONFIGURATION_NODE_ENDPOINT)
|
||||
public class ConfigurationNodeController extends EntityController<ConfigurationNode, ConfigurationNode> {
|
||||
|
||||
protected ConfigurationNodeController(
|
||||
final AuthorizationService authorization,
|
||||
final BulkActionService bulkActionService,
|
||||
final ConfigurationNodeDAO entityDAO,
|
||||
final UserActivityLogDAO userActivityLogDAO,
|
||||
final PaginationService paginationService,
|
||||
final BeanValidationService beanValidationService) {
|
||||
|
||||
super(authorization,
|
||||
bulkActionService,
|
||||
entityDAO,
|
||||
userActivityLogDAO,
|
||||
paginationService,
|
||||
beanValidationService);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ConfigurationNode createNew(final POSTMapper postParams) {
|
||||
final Long institutionId = postParams.getLong(API.PARAM_INSTITUTION_ID);
|
||||
return new ConfigurationNode(institutionId, postParams);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected SqlTable getSQLTableOfEntity() {
|
||||
return ConfigurationNodeRecordDynamicSqlSupport.configurationNodeRecord;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,134 @@
|
|||
/*
|
||||
* Copyright (c) 2019 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 javax.validation.Valid;
|
||||
|
||||
import org.mybatis.dynamic.sql.SqlTable;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import ch.ethz.seb.sebserver.gbl.api.API;
|
||||
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.EntityProcessingReport;
|
||||
import ch.ethz.seb.sebserver.gbl.model.GrantEntity;
|
||||
import ch.ethz.seb.sebserver.gbl.model.sebconfig.ConfigurationTableValue;
|
||||
import ch.ethz.seb.sebserver.gbl.model.sebconfig.ConfigurationValue;
|
||||
import ch.ethz.seb.sebserver.gbl.profile.WebServiceProfile;
|
||||
import ch.ethz.seb.sebserver.webservice.datalayer.batis.mapper.ConfigurationValueRecordDynamicSqlSupport;
|
||||
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.ConfigurationDAO;
|
||||
import ch.ethz.seb.sebserver.webservice.servicelayer.dao.ConfigurationValueDAO;
|
||||
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.CONFIGURATION_VALUE_ENDPOINT)
|
||||
public class ConfigurationValueController extends EntityController<ConfigurationValue, ConfigurationValue> {
|
||||
|
||||
private final ConfigurationDAO configurationDAO;
|
||||
private final ConfigurationValueDAO configurationValueDAO;
|
||||
|
||||
protected ConfigurationValueController(
|
||||
final AuthorizationService authorization,
|
||||
final BulkActionService bulkActionService,
|
||||
final ConfigurationValueDAO entityDAO,
|
||||
final UserActivityLogDAO userActivityLogDAO,
|
||||
final PaginationService paginationService,
|
||||
final BeanValidationService beanValidationService,
|
||||
final ConfigurationDAO configurationDAO) {
|
||||
|
||||
super(authorization,
|
||||
bulkActionService,
|
||||
entityDAO,
|
||||
userActivityLogDAO,
|
||||
paginationService,
|
||||
beanValidationService);
|
||||
|
||||
this.configurationDAO = configurationDAO;
|
||||
this.configurationValueDAO = entityDAO;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ConfigurationValue createNew(final POSTMapper postParams) {
|
||||
final Long institutionId = postParams.getLong(API.PARAM_INSTITUTION_ID);
|
||||
return new ConfigurationValue(institutionId, postParams);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected SqlTable getSQLTableOfEntity() {
|
||||
return ConfigurationValueRecordDynamicSqlSupport.configurationValueRecord;
|
||||
}
|
||||
|
||||
@Override
|
||||
public EntityProcessingReport hardDelete(final String modelId) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@RequestMapping(
|
||||
path = API.CONFIGURATION_TABLE_VALUE_PATH_SEGMENT,
|
||||
method = RequestMethod.GET,
|
||||
consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE,
|
||||
produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
|
||||
public ConfigurationTableValue getTableValueBy(
|
||||
@RequestParam(
|
||||
name = Domain.CONFIGURATION_VALUE.ATTR_CONFIGURATION_ATTRIBUTE_ID,
|
||||
required = true) final Long attributeId,
|
||||
@RequestParam(
|
||||
name = Domain.CONFIGURATION_VALUE.ATTR_CONFIGURATION_ID,
|
||||
required = true) final Long configurationId) {
|
||||
|
||||
return this.configurationDAO.byPK(configurationId)
|
||||
.flatMap(this.authorization::checkRead)
|
||||
.flatMap(config -> this.configurationValueDAO.getTableValue(
|
||||
config.institutionId,
|
||||
attributeId,
|
||||
configurationId))
|
||||
.getOrThrow();
|
||||
}
|
||||
|
||||
@RequestMapping(
|
||||
path = API.CONFIGURATION_TABLE_VALUE_PATH_SEGMENT,
|
||||
method = RequestMethod.PUT,
|
||||
consumes = MediaType.APPLICATION_JSON_UTF8_VALUE,
|
||||
produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
|
||||
public ConfigurationTableValue savePut(
|
||||
@Valid @RequestBody final ConfigurationTableValue tableValue) {
|
||||
|
||||
return this.configurationDAO.byPK(tableValue.configurationId)
|
||||
.flatMap(this.authorization::checkModify)
|
||||
.flatMap(config -> this.configurationValueDAO.saveTableValue(tableValue))
|
||||
.getOrThrow();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected GrantEntity toGrantEntity(final ConfigurationValue entity) {
|
||||
if (entity == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return this.configurationDAO.byPK(entity.configurationId)
|
||||
.getOrThrow();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected EntityType getGrantEntityType() {
|
||||
return EntityType.CONFIGURATION;
|
||||
}
|
||||
|
||||
}
|
Loading…
Add table
Reference in a new issue