<commit_before>require 'caruby/util/validation'
require 'catissue/resource'
require 'catissue/util/person'

module CaTissue
  # import the Java class
  resource_import Java::edu.wustl.catissuecore.domain.User

  # The User domain class.
  class User
    include Person

    # caTissue alert - work-around for caTissue Bug #66 - Client missing CSException class et al.
    # caTissue User class initializes roleId to "", which triggers a client exception on subsequent
    # getRoleId call. Use a private variable instead and bypass getRoleId.
    def role_id
      # TODO - uncomment following and get rid of @role_id i.v. when bug is fixed.
      #value = send(old_method)
      #return if value == ''
      #value.to_i
      @role_id
    end

    # Sets the role id to the given value, which can be either a String or an Integer.
    # An empty or zero value is converted to nil.
    #
    # caTissue alert - caTissue API roleId is a String although the intended value domain is the
    # integer csm_role.identifier.
    def role_id=(value)
      # value as an integer (nil is zero)
      value_i = value.to_i
      # set the Bug #66 work-around i.v.
      @role_id = value_i.zero? ? nil : value_i
      # value as a String (if non-nil)
      value_s = @role_id.to_s if @role_id
      # call Java with a String
      setRoleId(value_s)
    end

    # caTissue alert - caTissue 1.2 User has an adminuser Java property, but caTissue throws an
    # UnsupportedOperationException if they are called.
    if attribute_defined?(:adminuser) then remove_attribute(:adminuser) end

    # make the convenience Person name a first-class attribute
    add_attribute(:name)

    # caTissue alert - clinical study is unsupported by 1.1.x caTissue, removed in 1.2.
    if attribute_defined?(:clinical_studies) then remove_attribute(:clinical_studies) end

    # clarify that collection_protocols is a coordinator -> protocol association.
    # make assigned protocol and site attribute names consistent.
    add_attribute_aliases(:coordinated_protocols => :collection_protocols, :protocols => :assigned_protocols, :assigned_sites => :sites)

    # login_name is a database unique key.
    set_secondary_key_attributes(:login_name)

    # email_address is expected to be unique, and is enforced by the caTissue business logic.
    set_alternate_key_attributes(:email_address)

    # Set defaults as follows:
    # * page_of is the value set when creating a User in the GUI
    # * role id is 7 = Scientist (public)
    # * initial password is '<PASSWORD>'
    add_attribute_defaults(:activity_status => 'Active', :page_of => 'pageOfUserAdmin', :role_id => 7, :new_password => '<PASSWORD>')
<commit_msg>Add attribute type.<commit_after>require 'caruby/util/validation'
require 'catissue/resource'
require 'catissue/util/person'

module CaTissue
  # import the Java class
  resource_import Java::edu.wustl.catissuecore.domain.User

  # The User domain class.
  class User
    include Person

    # caTissue alert - work-around for caTissue Bug #66 - Client missing CSException class et al.
    # caTissue User class initializes roleId to "", which triggers a client exception on subsequent
    # getRoleId call. Use a private variable instead and bypass getRoleId.
    def role_id
      # TODO - uncomment following and get rid of @role_id i.v. when bug is fixed.
      #value = send(old_method)
      #return if value == ''
      #value.to_i
      @role_id
    end

    # Sets the role id to the given value, which can be either a String or an Integer.
    # An empty or zero value is converted to nil.
    #
    # caTissue alert - caTissue API roleId is a String although the intended value domain is the
    # integer csm_role.identifier.
    def role_id=(value)
      # value as an integer (nil is zero)
      value_i = value.to_i
      # set the Bug #66 work-around i.v.
      @role_id = value_i.zero? ? nil : value_i
      # value as a String (if non-nil)
      value_s = @role_id.to_s if @role_id
      # call Java with a String
      setRoleId(value_s)
    end

    # caTissue alert - caTissue 1.2 User has an adminuser Java property, but caTissue throws an
    # UnsupportedOperationException if they are called.
    if attribute_defined?(:adminuser) then remove_attribute(:adminuser) end

    # make the convenience {, CaRuby::Person::Name} name a first-class attribute
    add_attribute(:name, CaRuby::Person::Name)

    # caTissue alert - clinical study is unsupported by 1.1.x caTissue, removed in 1.2.
    if attribute_defined?(:clinical_studies) then remove_attribute(:clinical_studies) end

    # clarify that collection_protocols is a coordinator -> protocol association.
    # make assigned protocol and site attribute names consistent.
    add_attribute_aliases(:coordinated_protocols => :collection_protocols, :protocols => :assigned_protocols, :assigned_sites => :sites)

    # login_name is a database unique key.
    set_secondary_key_attributes(:login_name)

    # email_address is expected to be unique, and is enforced by the caTissue business logic.
    set_alternate_key_attributes(:email_address)

    # Set defaults as follows:
    # * page_of is the value set when creating a User in the GUI
    # * role id is 7 = Scientist (public)
    # * initial password is '<PASSWORD>'
    add_attribute_defaults(:activity_status => 'Active', :page_of => 'pageOfUserAdmin', :role_id => 7, :new_password => '<PASSWORD>')

{'fraction_non_alphanumeric': 0.07611500184297826, 'fraction_numerical': 0.0044231478068558795, 'mean_word_length': 3.3836833602584813, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 23, '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': '92672', 'n_tokens_mistral': 1626, 'n_tokens_neox': 1561, 'n_words': 583}