Search in sources :

Example 1 with InvalidFileTypeException

use of org.openmrs.api.InvalidFileTypeException in project openmrs-core by openmrs.

the class FormServiceImpl method saveFormResource.

/**
 * @see org.openmrs.api.FormService#saveFormResource(org.openmrs.FormResource)
 */
@Override
public FormResource saveFormResource(FormResource formResource) throws APIException {
    if (formResource == null) {
        return null;
    }
    // If a form resource with same name exists, replace it with current value
    FormResource toPersist = formResource;
    FormResource original = Context.getFormService().getFormResource(formResource.getForm(), formResource.getName());
    if (original != null) {
        original.setName(formResource.getName());
        original.setValue(formResource.getValue());
        original.setDatatypeClassname(formResource.getDatatypeClassname());
        original.setDatatypeConfig(formResource.getDatatypeConfig());
        original.setPreferredHandlerClassname(formResource.getPreferredHandlerClassname());
        toPersist = original;
    }
    try {
        CustomDatatypeUtil.saveIfDirty(toPersist);
    } catch (ConstraintViolationException ex) {
        throw new InvalidFileTypeException(ex.getMessage(), ex);
    }
    return dao.saveFormResource(toPersist);
}
Also used : InvalidFileTypeException(org.openmrs.api.InvalidFileTypeException) FormResource(org.openmrs.FormResource) ConstraintViolationException(org.hibernate.exception.ConstraintViolationException)

Aggregations

ConstraintViolationException (org.hibernate.exception.ConstraintViolationException)1 FormResource (org.openmrs.FormResource)1 InvalidFileTypeException (org.openmrs.api.InvalidFileTypeException)1