<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def map_to_resource(self, data_element, resource=None):
 """ Maps the given data element to a new resource or updates the given resource. :raises ValueError: If :param:`data_element` does not provide :class:`everest.representers.interfaces.IDataElement`. """

        if not IDataElement.providedBy(data_element): # pylint:disable=E1101
            raise ValueError('Expected data element, got %s.' % data_element)
        if resource is None:
            coll = \
                create_staging_collection(data_element.mapping.mapped_class)
            agg = coll.get_aggregate()
            agg.add(data_element)
            if IMemberDataElement.providedBy(data_element): # pylint: disable=E1101
                ent = next(iter(agg))
                resource = \
                    data_element.mapping.mapped_class.create_from_entity(ent)
            else:
                resource = coll
        else:
            resource.update(data_element)
        return resource