Skip to content

Commit

Permalink
Merge pull request #1894 from wwelling/4.2.6_staging-remove-field-pro…
Browse files Browse the repository at this point in the history
…file

Prevent field profile delete when submission list column is in use
  • Loading branch information
cstarcher committed Jan 23, 2024
2 parents b92af7e + a988be4 commit c106eda
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
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

0 comments on commit c106eda

Please sign in to comment.