<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:

def _do_element_present(name, elem_type, data, server=None):
    '''
    Generic function to create or update an element
    '''
    ret = {'changes': {}, 'update': False, 'create': False, 'error': None}
    try:
        elements = __salt__['glassfish.enum_{0}'.format(elem_type)]()
    except requests.ConnectionError as error:
        if __opts__['test']:
            ret['changes'] = {'Name': name, 'Params': data}
            ret['create'] = True
            return ret
        else:
            ret['error'] = "Can't connect to the server"
            return ret

    if not elements or name not in elements:
        ret['changes'] = {'Name': name, 'Params': data}
        ret['create'] = True
        if not __opts__['test']:
            try:
                __salt__['glassfish.create_{0}'.format(elem_type)](name, server=server, **data)
            except CommandExecutionError as error:
                ret['error'] = error
                return ret
    elif elements and any(data):
        current_data = __salt__['glassfish.get_{0}'.format(elem_type)](name, server=server)
        data_diff = _is_updated(current_data, data)
        if data_diff:
            ret['update'] = True
            ret['changes'] = data_diff
            if not __opts__['test']:
                try:
                    __salt__['glassfish.update_{0}'.format(elem_type)](name, server=server, **data)
                except CommandExecutionError as error:
                    ret['error'] = error
    return ret