-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
SEBSERV-398 - add bulk delete for exam config
- Loading branch information
Nadim Ritter
committed
Feb 7, 2024
1 parent
25e9b9b
commit f191d59
Showing
6 changed files
with
271 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
132 changes: 132 additions & 0 deletions
132
src/main/java/ch/ethz/seb/sebserver/gui/content/configs/SEBExamConfigBatchDeletePopup.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,132 @@ | ||
package ch.ethz.seb.sebserver.gui.content.configs; | ||
|
||
import ch.ethz.seb.sebserver.gbl.Constants; | ||
import ch.ethz.seb.sebserver.gbl.api.API; | ||
import ch.ethz.seb.sebserver.gbl.api.API.BatchActionType; | ||
import ch.ethz.seb.sebserver.gbl.api.EntityType; | ||
import ch.ethz.seb.sebserver.gbl.model.BatchAction; | ||
import ch.ethz.seb.sebserver.gbl.model.Domain; | ||
import ch.ethz.seb.sebserver.gbl.model.EntityKey; | ||
import ch.ethz.seb.sebserver.gbl.model.sebconfig.ConfigurationNode; | ||
import ch.ethz.seb.sebserver.gbl.profile.GuiProfile; | ||
import ch.ethz.seb.sebserver.gui.content.action.ActionDefinition; | ||
import ch.ethz.seb.sebserver.gui.form.FormBuilder; | ||
import ch.ethz.seb.sebserver.gui.form.FormHandle; | ||
import ch.ethz.seb.sebserver.gui.service.ResourceService; | ||
import ch.ethz.seb.sebserver.gui.service.i18n.LocTextKey; | ||
import ch.ethz.seb.sebserver.gui.service.page.AbstractBatchActionWizard; | ||
import ch.ethz.seb.sebserver.gui.service.page.PageContext; | ||
import ch.ethz.seb.sebserver.gui.service.page.PageService; | ||
import ch.ethz.seb.sebserver.gui.service.push.ServerPushService; | ||
import ch.ethz.seb.sebserver.gui.service.remote.webservice.api.RestCall; | ||
import ch.ethz.seb.sebserver.gui.service.remote.webservice.api.RestService; | ||
import ch.ethz.seb.sebserver.gui.service.remote.webservice.api.seb.examconfig.GetExamConfigNodesByIds; | ||
import ch.ethz.seb.sebserver.gui.table.ColumnDefinition; | ||
import org.apache.tomcat.util.buf.StringUtils; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.springframework.context.annotation.Lazy; | ||
import org.springframework.stereotype.Component; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Collections; | ||
import java.util.List; | ||
import java.util.Set; | ||
import java.util.function.Supplier; | ||
import java.util.stream.Collectors; | ||
|
||
@Lazy | ||
@Component | ||
@GuiProfile | ||
public class SEBExamConfigBatchDeletePopup extends AbstractBatchActionWizard { | ||
|
||
private static final Logger log = LoggerFactory.getLogger(SEBExamConfigBatchDeletePopup.class); | ||
|
||
private final static LocTextKey FORM_TITLE = new LocTextKey("sebserver.examconfig.list.batch.delete.title"); | ||
private final static LocTextKey FORM_INFO = new LocTextKey("sebserver.examconfig.list.batch.delete.info"); | ||
private final static LocTextKey ACTION_DO_DELETE = new LocTextKey("sebserver.examconfig.list.batch.action.delete"); | ||
|
||
protected SEBExamConfigBatchDeletePopup( | ||
final PageService pageService, | ||
final ServerPushService serverPushService) { | ||
|
||
super(pageService, serverPushService); | ||
} | ||
|
||
@Override | ||
protected LocTextKey getTitle() { | ||
return FORM_TITLE; | ||
} | ||
|
||
@Override | ||
protected LocTextKey getBatchActionInfo() { | ||
return FORM_INFO; | ||
} | ||
|
||
@Override | ||
protected LocTextKey getBatchActionTitle() { | ||
return ACTION_DO_DELETE; | ||
} | ||
|
||
@Override | ||
protected BatchActionType getBatchActionType() { | ||
return BatchActionType.EXAM_CONFIG_DELETE; | ||
} | ||
|
||
@Override | ||
protected Supplier<PageContext> createResultPageSupplier(PageContext pageContext, FormHandle<ConfigurationNode> formHandle) { | ||
return () -> pageContext; | ||
} | ||
|
||
@Override | ||
protected void extendBatchActionRequest(PageContext pageContext, RestCall<BatchAction>.RestCallBuilder batchActionRequestBuilder) { | ||
// Nothing to do here | ||
} | ||
|
||
@Override | ||
protected FormBuilder buildSpecificFormFields(PageContext formContext, FormBuilder formHead, boolean readonly) { | ||
return formHead; | ||
} | ||
|
||
@Override | ||
protected void processUpdateListAction(PageContext formContext) { | ||
this.pageService.executePageAction(this.pageService.pageActionBuilder(formContext) | ||
.newAction(ActionDefinition.SEB_EXAM_CONFIG_LIST) | ||
.create()); | ||
} | ||
|
||
@Override | ||
protected void applySelectionList( | ||
final PageContext formContext, | ||
final Set<EntityKey> multiSelection) { | ||
|
||
final ResourceService resourceService = this.pageService.getResourceService(); | ||
|
||
final String ids = StringUtils.join( | ||
multiSelection.stream().map(EntityKey::getModelId).collect(Collectors.toList()), | ||
Constants.LIST_SEPARATOR_CHAR); | ||
|
||
final RestService restService = this.pageService.getRestService(); | ||
final List<ConfigurationNode> selected = new ArrayList<>(restService.getBuilder(GetExamConfigNodesByIds.class) | ||
.withQueryParam(API.PARAM_MODEL_ID_LIST, ids) | ||
.call() | ||
.getOr(Collections.emptyList())); | ||
|
||
selected.sort((examConfig1, examConfig2) -> examConfig1.name.compareTo(examConfig2.name)); | ||
|
||
this.pageService.staticListTableBuilder(selected, EntityType.CONFIGURATION_NODE) | ||
.withPaging(10) | ||
.withColumn(new ColumnDefinition<>( | ||
Domain.CONFIGURATION_NODE.ATTR_NAME, | ||
SEBExamConfigList.NAME_TEXT_KEY, | ||
ConfigurationNode::getName)) | ||
|
||
.withColumn(new ColumnDefinition<>( | ||
Domain.CONFIGURATION_NODE.ATTR_STATUS, | ||
SEBExamConfigList.STATUS_TEXT_KEY, | ||
resourceService::localizedExamConfigStatusName) | ||
) | ||
|
||
.compose(formContext); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
...b/sebserver/gui/service/remote/webservice/api/seb/examconfig/GetExamConfigNodesByIds.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package ch.ethz.seb.sebserver.gui.service.remote.webservice.api.seb.examconfig; | ||
|
||
import ch.ethz.seb.sebserver.gbl.api.API; | ||
import ch.ethz.seb.sebserver.gbl.api.EntityType; | ||
import ch.ethz.seb.sebserver.gbl.model.sebconfig.ConfigurationNode; | ||
import ch.ethz.seb.sebserver.gbl.profile.GuiProfile; | ||
import ch.ethz.seb.sebserver.gui.service.remote.webservice.api.RestCall; | ||
import com.fasterxml.jackson.core.type.TypeReference; | ||
import org.springframework.context.annotation.Lazy; | ||
import org.springframework.http.HttpMethod; | ||
import org.springframework.http.MediaType; | ||
import org.springframework.stereotype.Component; | ||
|
||
import java.util.Collection; | ||
|
||
@Lazy | ||
@Component | ||
@GuiProfile | ||
public class GetExamConfigNodesByIds extends RestCall<Collection<ConfigurationNode>> { | ||
|
||
public GetExamConfigNodesByIds() { | ||
super(new TypeKey<>( | ||
CallType.GET_LIST, | ||
EntityType.CONFIGURATION_NODE, | ||
new TypeReference<Collection<ConfigurationNode>>() { | ||
}), | ||
HttpMethod.GET, | ||
MediaType.APPLICATION_FORM_URLENCODED, | ||
API.CONFIGURATION_NODE_ENDPOINT + API.LIST_PATH_SEGMENT | ||
); | ||
} | ||
} |
82 changes: 82 additions & 0 deletions
82
.../java/ch/ethz/seb/sebserver/webservice/servicelayer/bulkaction/impl/ExamConfigDelete.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
package ch.ethz.seb.sebserver.webservice.servicelayer.bulkaction.impl; | ||
|
||
import ch.ethz.seb.sebserver.gbl.api.API.BatchActionType; | ||
import ch.ethz.seb.sebserver.gbl.api.APIMessage; | ||
import ch.ethz.seb.sebserver.gbl.api.EntityType; | ||
import ch.ethz.seb.sebserver.gbl.api.authorization.PrivilegeType; | ||
import ch.ethz.seb.sebserver.gbl.model.BatchAction; | ||
import ch.ethz.seb.sebserver.gbl.api.APIMessage.APIMessageException; | ||
import ch.ethz.seb.sebserver.gbl.model.EntityKey; | ||
import ch.ethz.seb.sebserver.gbl.model.sebconfig.ConfigurationNode; | ||
import ch.ethz.seb.sebserver.gbl.profile.WebServiceProfile; | ||
import ch.ethz.seb.sebserver.gbl.util.Result; | ||
import ch.ethz.seb.sebserver.webservice.servicelayer.authorization.AuthorizationService; | ||
import ch.ethz.seb.sebserver.webservice.servicelayer.bulkaction.BatchActionExec; | ||
import ch.ethz.seb.sebserver.webservice.servicelayer.dao.ConfigurationNodeDAO; | ||
import ch.ethz.seb.sebserver.webservice.servicelayer.dao.ExamConfigurationMapDAO; | ||
import ch.ethz.seb.sebserver.webservice.servicelayer.sebconfig.ExamConfigService; | ||
import org.springframework.context.annotation.Lazy; | ||
import org.springframework.stereotype.Component; | ||
|
||
import java.util.Arrays; | ||
import java.util.HashSet; | ||
import java.util.Map; | ||
import java.util.stream.Collectors; | ||
|
||
@Lazy | ||
@Component | ||
@WebServiceProfile | ||
public class ExamConfigDelete implements BatchActionExec { | ||
|
||
private final ConfigurationNodeDAO configurationNodeDAO; | ||
private final AuthorizationService authorizationService; | ||
private final ExamConfigurationMapDAO examConfigurationMapDAO; | ||
|
||
public ExamConfigDelete( | ||
final ExamConfigService sebExamConfigService, | ||
final ConfigurationNodeDAO configurationNodeDAO, | ||
final AuthorizationService authorizationService, | ||
final ExamConfigurationMapDAO examConfigurationMapDAO) { | ||
|
||
this.configurationNodeDAO = configurationNodeDAO; | ||
this.authorizationService = authorizationService; | ||
this.examConfigurationMapDAO = examConfigurationMapDAO; | ||
} | ||
|
||
@Override | ||
public BatchActionType actionType() { | ||
return BatchActionType.EXAM_CONFIG_DELETE; | ||
} | ||
|
||
@Override | ||
public APIMessage checkConsistency(final Map<String, String> actionAttributes) { | ||
// no additional check here | ||
return null; | ||
} | ||
|
||
@Override | ||
public Result<EntityKey> doSingleAction(final String modelId, final BatchAction batchAction) { | ||
return this.configurationNodeDAO | ||
.byModelId(modelId) | ||
.flatMap(examConfig -> this.authorizationService.check(PrivilegeType.MODIFY, examConfig)) | ||
.flatMap(examConfig -> checkDeletionRequirements(examConfig)) | ||
.flatMap(examConfig -> this.configurationNodeDAO.delete(new HashSet<>(Arrays.asList(new EntityKey( | ||
modelId, | ||
EntityType.CONFIGURATION_NODE)))) | ||
) | ||
.map(res -> res.stream().collect(Collectors.toList()).get(0)); | ||
} | ||
|
||
private Result<ConfigurationNode> checkDeletionRequirements(ConfigurationNode examConfig){ | ||
Result<Boolean> isNotActive = this.examConfigurationMapDAO.checkNoActiveExamReferences(examConfig.id); | ||
if(!isNotActive.getOrThrow()){ | ||
return Result.ofError(new APIMessageException( | ||
APIMessage.ErrorMessage.INTEGRITY_VALIDATION | ||
.of("Exam Configuration has active Exam references") | ||
)); | ||
} | ||
|
||
return Result.of(examConfig); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters