def validate(self, data):
    appstruct = self.structure.validate(data)
    new_appstruct = {}
    _remove_protected_fields(appstruct)
    for key in ['group', 'groupid', 'userid', 'references']:
        appstruct.pop(key, '')
    if ('uri' in appstruct):
        new_uri = appstruct.pop('uri').strip()
        if (not new_uri):
            raise ValidationError(('uri: ' + _("'uri' is a required property")))
        new_appstruct['target_uri'] = new_uri
    if ('permissions' in appstruct):
        new_appstruct['shared'] = _shared(appstruct.pop('permissions'), self.groupid)
    if ('target' in appstruct):
        new_appstruct['target_selectors'] = _target_selectors(appstruct.pop('target'))
    for key in ['text', 'tags']:
        if (key in appstruct):
            new_appstruct[key] = appstruct.pop(key)
    if ('document' in appstruct):
        new_appstruct['document'] = _document(appstruct.pop('document'), new_appstruct.get('target_uri', self.existing_target_uri))
    new_appstruct['extra'] = appstruct
    return new_appstruct
def validate(self, data):
    appstruct = self.structure.validate(data)
    new_appstruct = {}
    _remove_protected_fields(appstruct)
    for key in ['group', 'groupid', 'userid', 'references']:
        appstruct.pop(key, )
    if ('uri' in appstruct):
        new_uri = appstruct.pop('uri').strip()
        if (not new_uri):
            raise ValidationError(('uri: ' + _("'uri' is a required property")))
        new_appstruct['target_uri'] = new_uri
    if ('permissions' in appstruct):
        new_appstruct['shared'] = _shared(appstruct.pop('permissions'), self.groupid)
    if ('target' in appstruct):
        new_appstruct['target_selectors'] = _target_selectors(appstruct.pop('target'))
    for key in ['text', 'tags']:
        if (key in appstruct):
            new_appstruct[key] = appstruct.pop(key)
    if ('document' in appstruct):
        new_appstruct['document'] = _document(appstruct.pop('document'), new_appstruct.get('target_uri', self.existing_target_uri))
    new_appstruct['extra'] = appstruct
    return new_appstruct