Search in sources :

Example 16 with ConstraintViolationException

use of jakarta.validation.ConstraintViolationException in project Clownfish by rawdog71.

the class ContentList method onCreateContent.

public void onCreateContent(ActionEvent actionEvent) {
    try {
        CfClasscontent newclasscontent = new CfClasscontent();
        contentName = contentName.replaceAll("\\s+", "_");
        newclasscontent.setName(contentName);
        newclasscontent.setClassref(selectedClass);
        cfclasscontentService.create(newclasscontent);
        List<CfAttribut> attributlist = cfattributService.findByClassref(newclasscontent.getClassref());
        attributlist.stream().forEach((attribut) -> {
            if (attribut.getAutoincrementor() == true) {
                List<CfClasscontent> classcontentlist2 = cfclasscontentService.findByClassref(newclasscontent.getClassref());
                long max = 0;
                int last = classcontentlist2.size();
                if (1 == last) {
                    max = 0;
                } else {
                    CfClasscontent classcontent = classcontentlist2.get(last - 2);
                    CfAttributcontent attributcontent = cfattributcontentService.findByAttributrefAndClasscontentref(attribut, classcontent);
                    if (attributcontent.getContentInteger().longValue() > max) {
                        max = attributcontent.getContentInteger().longValue();
                    }
                }
                CfAttributcontent newcontent = new CfAttributcontent();
                newcontent.setAttributref(attribut);
                newcontent.setClasscontentref(newclasscontent);
                newcontent.setContentInteger(BigInteger.valueOf(max + 1));
                cfattributcontentService.create(newcontent);
            } else {
                CfAttributcontent newcontent = new CfAttributcontent();
                newcontent.setAttributref(attribut);
                newcontent.setClasscontentref(newclasscontent);
                cfattributcontentService.create(newcontent);
            }
        });
        hibernateUtil.insertContent(newclasscontent);
        classcontentlist.clear();
        classcontentlist = cfclasscontentService.findByMaintenance(true);
        FacesMessage message = new FacesMessage("Content created");
        FacesContext.getCurrentInstance().addMessage(null, message);
    } catch (ConstraintViolationException ex) {
        LOGGER.error(ex.getMessage());
    }
}
Also used : CfAttribut(io.clownfish.clownfish.dbentities.CfAttribut) CfAttributcontent(io.clownfish.clownfish.dbentities.CfAttributcontent) ConstraintViolationException(jakarta.validation.ConstraintViolationException) FacesMessage(javax.faces.application.FacesMessage) CfClasscontent(io.clownfish.clownfish.dbentities.CfClasscontent)

Example 17 with ConstraintViolationException

use of jakarta.validation.ConstraintViolationException in project Clownfish by rawdog71.

the class DatasourceList method onCreateContent.

/**
 * Creates an external datasource
 * @param actionEvent
 */
public void onCreateContent(ActionEvent actionEvent) {
    try {
        CfDatasource newdatasourcecontent = new CfDatasource();
        newdatasourcecontent.setName(datasourceName);
        newdatasourcecontent.setDatabasename(datasourceDatabasename);
        newdatasourcecontent.setDriverclass(datasourceDriverclass);
        newdatasourcecontent.setPassword(datasourcePassword);
        newdatasourcecontent.setPort(datasourcePort);
        newdatasourcecontent.setServer(datasourceServer);
        newdatasourcecontent.setUrl(datasourceURL);
        newdatasourcecontent.setUser(datasourceUser);
        cfdatasourceService.create(newdatasourcecontent);
        datasourcelist = cfdatasourceService.findAll();
    } catch (ConstraintViolationException ex) {
        LOGGER.error(ex.getMessage());
    }
}
Also used : ConstraintViolationException(jakarta.validation.ConstraintViolationException) CfDatasource(io.clownfish.clownfish.dbentities.CfDatasource)

Example 18 with ConstraintViolationException

use of jakarta.validation.ConstraintViolationException in project geo-platform by geosdi.

the class GPValidatingMongoEventListener method onBeforeSave.

/**
 * Captures {@link BeforeSaveEvent}.
 *
 * @param event will never be {@literal null}.
 * @since 1.8
 */
@Override
public void onBeforeSave(@Nonnull(when = NEVER) BeforeSaveEvent<Object> event) {
    checkArgument(event != null, "The Parameter event must not be null.");
    Object source = event.getSource();
    logger.debug("@@@@@@@@@@@@@@@@@@@@@@@Validating object: {}", source);
    Set violations = validator.validate(source);
    if (!violations.isEmpty()) {
        logger.info("############During object: {} validation violations found: {}", source, violations);
        throw new ConstraintViolationException(violations);
    }
}
Also used : Set(java.util.Set) ConstraintViolationException(jakarta.validation.ConstraintViolationException)

Example 19 with ConstraintViolationException

use of jakarta.validation.ConstraintViolationException in project glassfish-hk2 by eclipse-ee4j.

the class ValidationTest method testValidDocumentWithInvalidListChild.

/**
 * Tests that validation on an invalid list child fails
 * @throws Exception
 */
@Test
public // @org.junit.Ignore
void testValidDocumentWithInvalidListChild() throws Exception {
    ServiceLocator locator = Utilities.createLocator();
    XmlService xmlService = locator.getService(XmlService.class);
    URL url = getClass().getClassLoader().getResource(INVALID2_FILE);
    XmlRootHandle<ValidationRootBean> rootHandle = xmlService.unmarshal(url.toURI(), ValidationRootBean.class);
    try {
        rootHandle.startValidating();
        Assert.fail("Should have failed");
    } catch (ConstraintViolationException me) {
    // Expected
    }
}
Also used : ServiceLocator(org.glassfish.hk2.api.ServiceLocator) XmlService(org.glassfish.hk2.xml.api.XmlService) ConstraintViolationException(jakarta.validation.ConstraintViolationException) URL(java.net.URL) Test(org.junit.Test)

Example 20 with ConstraintViolationException

use of jakarta.validation.ConstraintViolationException in project glassfish-hk2 by eclipse-ee4j.

the class ValidationTest method testValidDocumentWithInvalidArrayChild.

/**
 * Tests that validation on an invalid list child fails
 * @throws Exception
 */
@Test
public // @org.junit.Ignore
void testValidDocumentWithInvalidArrayChild() throws Exception {
    ServiceLocator locator = Utilities.createLocator();
    XmlService xmlService = locator.getService(XmlService.class);
    URL url = getClass().getClassLoader().getResource(INVALID3_FILE);
    XmlRootHandle<ValidationRootBean> rootHandle = xmlService.unmarshal(url.toURI(), ValidationRootBean.class);
    try {
        rootHandle.startValidating();
        Assert.fail("Should have failed");
    } catch (ConstraintViolationException me) {
    // Expected
    }
}
Also used : ServiceLocator(org.glassfish.hk2.api.ServiceLocator) XmlService(org.glassfish.hk2.xml.api.XmlService) ConstraintViolationException(jakarta.validation.ConstraintViolationException) URL(java.net.URL) Test(org.junit.Test)

Aggregations

ConstraintViolationException (jakarta.validation.ConstraintViolationException)114 Test (org.testng.annotations.Test)55 ConstraintMapping (org.hibernate.validator.cfg.ConstraintMapping)35 ConstraintViolation (jakarta.validation.ConstraintViolation)32 Validator (jakarta.validation.Validator)29 TestForIssue (org.hibernate.validator.testutil.TestForIssue)26 HibernateValidator (org.hibernate.validator.HibernateValidator)19 Size (jakarta.validation.constraints.Size)16 SizeDef (org.hibernate.validator.cfg.defs.SizeDef)15 Test (org.junit.Test)14 Session (org.hibernate.Session)10 Transaction (org.hibernate.Transaction)10 NotNullDef (org.hibernate.validator.cfg.defs.NotNullDef)10 CustomerRepositoryImpl (org.hibernate.validator.test.internal.engine.methodvalidation.service.CustomerRepositoryImpl)10 Customer (org.hibernate.validator.test.internal.engine.methodvalidation.model.Customer)9 FacesMessage (javax.faces.application.FacesMessage)8 NotNull (jakarta.validation.constraints.NotNull)7 BigDecimal (java.math.BigDecimal)7 Set (java.util.Set)7 EntityManager (jakarta.persistence.EntityManager)6