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());
}
}
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());
}
}
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);
}
}
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
}
}
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
}
}
Aggregations