Search in sources :

Example 31 with DataIntegrityViolationException

use of org.springframework.dao.DataIntegrityViolationException in project elastest-torm by elastest.

the class TestLinkService method syncProjectTestCase.

public void syncProjectTestCase(TestCase testCase, ExternalTJob externalTJob) {
    ExternalTestCase externalTestCase = new ExternalTestCase(new Long(0));
    externalTestCase.setExTJob(externalTJob);
    externalTestCase.setName(testCase.getName());
    externalTestCase.setFields(this.getTestCaseFields(testCase));
    externalTestCase.setExternalId(testCase.getId().toString());
    externalTestCase.setExternalSystemId(this.getSystemId());
    try {
        externalTestCase = externalTestCaseRepository.save(externalTestCase);
    } catch (DataIntegrityViolationException existException) {
        ExternalTestCase savedTestCase = externalTestCaseRepository.findByExternalIdAndExternalSystemId(externalTestCase.getExternalId(), externalTestCase.getExternalSystemId());
        externalTestCase.setId(savedTestCase.getId());
        externalTestCase = externalTestCaseRepository.save(externalTestCase);
    }
    this.syncTestCaseExecs(testCase.getId(), externalTestCase);
}
Also used : ExternalTestCase(io.elastest.etm.model.external.ExternalTestCase) DataIntegrityViolationException(org.springframework.dao.DataIntegrityViolationException)

Example 32 with DataIntegrityViolationException

use of org.springframework.dao.DataIntegrityViolationException in project elastest-torm by elastest.

the class TestLinkService method syncProject.

public void syncProject(TestProject project) {
    ExternalProject externalProject = new ExternalProject(new Long(0));
    externalProject.setName(project.getName());
    externalProject.setType(TypeEnum.TESTLINK);
    externalProject.setExternalId(project.getId().toString());
    externalProject.setExternalSystemId(this.getSystemId());
    try {
        externalProject = externalProjectRepository.save(externalProject);
    } catch (DataIntegrityViolationException existException) {
        ExternalProject savedPj = externalProjectRepository.findByExternalIdAndExternalSystemId(externalProject.getExternalId(), externalProject.getExternalSystemId());
        externalProject.setId(savedPj.getId());
        externalProject = externalProjectRepository.save(externalProject);
    }
    this.syncProjectTestPlans(project.getId(), externalProject);
}
Also used : ExternalProject(io.elastest.etm.model.external.ExternalProject) DataIntegrityViolationException(org.springframework.dao.DataIntegrityViolationException)

Example 33 with DataIntegrityViolationException

use of org.springframework.dao.DataIntegrityViolationException in project elastest-torm by elastest.

the class TestLinkService method syncProjectTestPlan.

public void syncProjectTestPlan(TestPlan testPlan, ExternalProject externalProject) {
    ExternalTJob externalTJob = new ExternalTJob(new Long(0));
    externalTJob.setExProject(externalProject);
    externalTJob.setName(testPlan.getName());
    externalTJob.setExternalId(testPlan.getId().toString());
    externalTJob.setExternalSystemId(this.getSystemId());
    try {
        externalTJob = externalTJobRepository.save(externalTJob);
    } catch (DataIntegrityViolationException existException) {
        ExternalTJob savedTJob = externalTJobRepository.findByExternalIdAndExternalSystemId(externalTJob.getExternalId(), externalTJob.getExternalSystemId());
        externalTJob.setId(savedTJob.getId());
        externalTJob.setSut(savedTJob.getSut());
        externalTJob.setExecDashboardConfig(savedTJob.getExecDashboardConfig());
        externalTJob = externalTJobRepository.save(externalTJob);
    }
    this.syncTestPlanCases(testPlan.getId(), externalTJob);
}
Also used : ExternalTJob(io.elastest.etm.model.external.ExternalTJob) DataIntegrityViolationException(org.springframework.dao.DataIntegrityViolationException)

Example 34 with DataIntegrityViolationException

use of org.springframework.dao.DataIntegrityViolationException in project trainning by fernandotomasio.

the class CursosController method saveCurso.

@RequestMapping("/save")
public String saveCurso(Model model, @Valid CursoForm cursoForm, BindingResult bindingResult, WebRequest request) {
    if (bindingResult.hasErrors()) {
        model.addAttribute("areas", initializeSelectableAreas());
        model.addAttribute("planos", initializeSelectablePlanos());
        return "cursos/form";
    }
    CursoDTO dto = new CursoDTO();
    dto.setId(cursoForm.getId());
    dto.setArea(trainningService.findArea(cursoForm.getAreaId()));
    dto.setPlano(trainningService.findPlano(cursoForm.getPlanoId()));
    dto.setCodigo(cursoForm.getCodigo());
    dto.setDescricao(cursoForm.getDescricao());
    dto.setCodigoVelho(cursoForm.getCodigoVelho());
    dto.setInstrucao(cursoForm.isInstrucao());
    dto.setQuantidadeVagas(cursoForm.getQuantidadeVagas());
    dto.setDuracao(cursoForm.getDuracao());
    dto.setAtivo(cursoForm.isAtivo());
    dto.setVisivel(cursoForm.isVisivel());
    dto.setEhGT(cursoForm.isEhGT());
    dto.setEstrangeiro(cursoForm.isEstrangeiro());
    FolhaRostoDTO folhaRosto = new FolhaRostoDTO();
    folhaRosto.setDisciplinas(cursoForm.getDisciplinas());
    folhaRosto.setObjetivo(cursoForm.getObjetivo());
    folhaRosto.setPreRequisitos(cursoForm.getPreRequisitos());
    folhaRosto.setObservacoes(cursoForm.getObservacoes());
    dto.setFolhaRosto(folhaRosto);
    if (dto.getId() > 0) {
        try {
            trainningService.updateCurso(dto);
            model.addAttribute("successMessage", "Curso atualizado com sucesso.");
            model.addAttribute("curso", dto);
            return "cursos/detail";
        } catch (CoreException e) {
            model.addAttribute("errorMessage", e.getMessage());
            model.addAttribute("areas", initializeSelectableAreas());
            model.addAttribute("planos", initializeSelectablePlanos());
            return "cursos/form";
        }
    } else {
        try {
            Long cursoId = trainningService.createCurso(dto);
            dto.setId(cursoId);
            model.addAttribute("successMessage", "Curso criado com sucesso.");
            model.addAttribute("curso", dto);
            return "cursos/detail";
        // } catch (CoreException e) {
        } catch (DataIntegrityViolationException e) {
            // model.addAttribute("errorMessage", e.getMessage());
            model.addAttribute("errorMessage", "O Curso " + dto.getCodigo() + " já existe Cadastrado no Sistema!");
            model.addAttribute("areas", initializeSelectableAreas());
            model.addAttribute("planos", initializeSelectablePlanos());
            return "cursos/form";
        }
    }
}
Also used : CoreException(com.tomasio.projects.trainning.exeption.CoreException) CursoDTO(com.tomasio.projects.trainning.dto.CursoDTO) FolhaRostoDTO(com.tomasio.projects.trainning.dto.FolhaRostoDTO) DataIntegrityViolationException(org.springframework.dao.DataIntegrityViolationException) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 35 with DataIntegrityViolationException

use of org.springframework.dao.DataIntegrityViolationException in project cloudbreak by hortonworks.

the class RdsConfigController method createRdsConfig.

private RDSConfigResponse createRdsConfig(IdentityUser user, RDSConfigRequest rdsConfigJson, boolean publicInAccount) {
    RDSConfig rdsConfig = conversionService.convert(rdsConfigJson, RDSConfig.class);
    rdsConfig.setPublicInAccount(publicInAccount);
    try {
        rdsConfig = rdsConfigService.create(user, rdsConfig);
        notify(user, ResourceEvent.RDS_CONFIG_CREATED);
    } catch (DataIntegrityViolationException ex) {
        String msg = String.format("Error with resource [%s], error: [%s]", APIResourceType.RDS_CONFIG, getProperSqlErrorMessage(ex));
        throw new BadRequestException(msg);
    }
    return conversionService.convert(rdsConfig, RDSConfigResponse.class);
}
Also used : RDSConfig(com.sequenceiq.cloudbreak.domain.RDSConfig) DataIntegrityViolationException(org.springframework.dao.DataIntegrityViolationException)

Aggregations

DataIntegrityViolationException (org.springframework.dao.DataIntegrityViolationException)117 Test (org.junit.Test)26 HashMap (java.util.HashMap)12 BadRequestException (com.sequenceiq.cloudbreak.controller.BadRequestException)11 Transactional (org.springframework.transaction.annotation.Transactional)11 Test (org.junit.jupiter.api.Test)10 Transactional (javax.transaction.Transactional)9 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)9 User (ca.corefacility.bioinformatics.irida.model.user.User)8 SQLException (java.sql.SQLException)8 ConstraintViolation (javax.validation.ConstraintViolation)8 HashSet (java.util.HashSet)7 Locale (java.util.Locale)6 ConstraintViolationException (javax.validation.ConstraintViolationException)6 Date (java.util.Date)5 List (java.util.List)5 Set (java.util.Set)5 EntityExistsException (ca.corefacility.bioinformatics.irida.exceptions.EntityExistsException)4 ConnectorException (com.netflix.metacat.common.server.connectors.exception.ConnectorException)4 InvalidMetaException (com.netflix.metacat.common.server.connectors.exception.InvalidMetaException)4