Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent field profile delete when submission list column is in use #1894

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@
import edu.tamu.weaver.validation.aspect.annotation.WeaverValidatedModel;
import edu.tamu.weaver.validation.aspect.annotation.WeaverValidation;
import java.util.Optional;

import javax.transaction.Transactional;

import org.hibernate.exception.ConstraintViolationException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.PathVariable;
Expand Down Expand Up @@ -130,6 +134,7 @@ public ApiResponse removeFieldProfile(@PathVariable Long requestingOrgId, @PathV

@PostMapping(value = "/{requestingOrgId}/{workflowStepId}/remove-field-profile/{fieldProfileId}")
@PreAuthorize("hasRole('MANAGER')")
@Transactional(rollbackOn = ConstraintViolationException.class)
public ApiResponse removeFieldProfileById(@PathVariable Long requestingOrgId, @PathVariable Long workflowStepId, @PathVariable Long fieldProfileId) throws WorkflowStepNonOverrideableException, HeritableModelNonOverrideableException, ComponentNotPresentOnOrgException {
Optional<Organization> organization = organizationRepo.findById(requestingOrgId);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import javax.persistence.EntityNotFoundException;

import org.hibernate.exception.ConstraintViolationException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
Expand Down Expand Up @@ -44,6 +45,15 @@ public class CustomResponseEntityExceptionHandler extends ResponseEntityExceptio
@Value("${spring.servlet.multipart.max-file-size:20MB}")
private String maxFileSize;

@ExceptionHandler(ConstraintViolationException.class)
@ResponseStatus(value = HttpStatus.CONFLICT)
@ResponseBody
public ApiResponse handleConstraintViolationException(ConstraintViolationException exception) {
logger.error(exception.getMessage());
logger.debug(exception.getMessage(), exception);
return new ApiResponse(ERROR, exception.getMessage());
}

@ExceptionHandler(DataIntegrityViolationException.class)
@ResponseStatus(value = HttpStatus.CONFLICT)
@ResponseBody
Expand Down
Loading