class SecurityFunctionServiceImpl implements SecurityFunctionService {

    @Override
    public SecurityFunction createSecurityFunction(SecurityFunctionCreateRequest request)
    {
        // Perform the validation.
        validateSecurityFunctionCreateRequest(request);

        // Ensure a security function with the specified security function name doesn't already exist.
        SecurityFunctionEntity securityFunctionEntity = securityFunctionDao.getSecurityFunctionByName(request.getSecurityFunctionName());
        if (securityFunctionEntity != null)
        {
            throw new AlreadyExistsException(
                String.format("Unable to create security function \"%s\" because it already exists.", request.getSecurityFunctionName()));
        }

        // Create a security function entity from the request information.
        securityFunctionEntity = createSecurityFunctionEntity(request);

        // Persist the new entity.
        securityFunctionEntity = securityFunctionDao.saveAndRefresh(securityFunctionEntity);

        // Create and return the security function object from the persisted entity.
        return createSecurityFunctionFromEntity(securityFunctionEntity);
    }

}