<commit_before>### $Id$
### $URL$

from sfa.util.faults import *
from sfa.util.method import Method
from sfa.util.parameter import Parameter, Mixed
from sfa.trust.auth import Auth
from sfa.util.record import GeniRecord
from sfa.util.genitable import GeniTable
from sfa.trust.certificate import Keypair, convert_public_key
from sfa.trust.gid import *
from sfa.util.debug import log

class update(Method):
    """
    Update an object in the registry. Currently, this only updates the
    PLC information associated with the record. The Geni fields (name, type,
    GID) are fixed.
    
    @param cred credential string specifying rights of the caller
    @param record a record dictionary to be updated

    @return 1 if successful, faults otherwise 
    """

    interfaces = ['registry']
    
    accepts = [
        Parameter(str, "Credential string"),
        Parameter(dict, "Record dictionary to be updated")
        ]

    returns = Parameter(int, "1 if successful")
    
    def call(self, cred, record_dict):
        self.api.auth.check(cred, "update")
        new_record = GeniRecord(dict = record_dict)
        type = new_record['type']
        hrn = new_record['hrn']
        self.api.auth.verify_object_permission(hrn)
        table = GeniTable()
        # make sure the record exists
        records = table.find({'type': type, 'hrn': hrn})
        if not records:
            raise RecordNotFound(hrn)
        record = records[0]
         
        # Update_membership needs the membership lists in the existing record
        # filled in, so it can see if members were added or removed<commit_msg>bugfix<commit_after>### $Id$
### $URL$

from sfa.util.faults import *
from sfa.util.method import Method
from sfa.util.parameter import Parameter, Mixed
from sfa.trust.auth import Auth
from sfa.util.record import GeniRecord
from sfa.util.genitable import GeniTable
from sfa.trust.certificate import Keypair, convert_public_key
from sfa.trust.gid import *
from sfa.util.debug import log

class update(Method):
    """
    Update an object in the registry. Currently, this only updates the
    PLC information associated with the record. The Geni fields (name, type,
    GID) are fixed.
    
    @param cred credential string specifying rights of the caller
    @param record a record dictionary to be updated

    @return 1 if successful, faults otherwise 
    """

    interfaces = ['registry']
    
    accepts = [
        Parameter(str, "Credential string"),
        Parameter(dict, "Record dictionary to be updated")
        ]

    returns = Parameter(int, "1 if successful")
    
    def call(self, cred, record_dict):
        self.api.auth.check(cred, "update")
        new_record = GeniRecord(dict = record_dict)
        type = new_record['type']
        hrn = new_record['hrn']
        self.api.auth.verify_object_permission(hrn)
        table = GeniTable()
        # make sure the record exists
        records = table.findObjects({'type': type, 'hrn': hrn})
        if not records:
            raise RecordNotFound(hrn)
        record = records[0]
         
        # Update_membership needs the membership lists in the existing record
        # filled in, so it can see if members were added or removed
{'fraction_non_alphanumeric': 0.08622828784119106, 'fraction_numerical': 0.0018610421836228288, 'mean_word_length': 2.8530465949820787, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2319822', 'n_tokens_mistral': 925, 'n_tokens_neox': 896, 'n_words': 319}