<commit_before>require 'hydra/datastream/non_indexed_rights_metadata'
require 'hydra/model_mixins/hybrid_delegator'
require 'role_controls'

class Admin::Collection < ActiveFedora::Base
  include Hydra::ModelMixins::CommonMetadata
  include ActiveFedora::Associations
  include Hydra::ModelMixins::RightsMetadata
  include Hydra::ModelMixins::HybridDelegator

  has_many :media_objects, property: :is_member_of_collection 
  has_metadata name: 'descMetadata', type: ActiveFedora::SimpleDatastream do |sds|
    sds.field :name, :string
    sds.field :unit, :string
    sds.field :description, :string
  end
  has_metadata name: 'inheritedRights', type: Hydra::Datastream::InheritableRightsMetadata
  has_metadata name: 'defaultRights', type: Hydra::Datastream::NonIndexedRightsMetadata

  validates :name, :uniqueness => { :solr_name => 'name_tesim'}, presence: true
  validates :unit, presence: true, inclusion: {in: proc{Admin::Collection.units}}
  validates :managers, length: {minimum: 1, message: 'Collection requires at least 1 manager'} 

  delegate :name, to: :descMetadata, unique: true
  delegate :unit, to: :descMetadata, unique: true
  delegate :description, to: :descMetadata, unique: true
  delegate :read_groups, :read_users, :access, :access=, :hidden?, :hidden=, :group_exceptions,
           :group_exceptions=, :user_exceptions, :user_exceptions=, to: :defaultRights, prefix: :default

  def self.units
    ["University Archives", "Black Film Center/Archive"]
  end

  def created_at
    @created_at ||= DateTime.parse(create_date)
  end

  def to_solr(solr_doc = Hash.new, opts = {})
    map = Solrizer::default_field_mapper
    solr_doc[ map.solr_name(:name, :stored_searchable, type: :string).to_sym ] = self.name
    super(solr_doc)
  end

  def managers
    edit_users & (RoleControls.users("manager") || [])
  end

  def managers= users<commit_msg>Autocreate defaultRights datastream<commit_after>require 'hydra/datastream/non_indexed_rights_metadata'
require 'hydra/model_mixins/hybrid_delegator'
require 'role_controls'

class Admin::Collection < ActiveFedora::Base
  include Hydra::ModelMixins::CommonMetadata
  include ActiveFedora::Associations
  include Hydra::ModelMixins::RightsMetadata
  include Hydra::ModelMixins::HybridDelegator

  has_many :media_objects, property: :is_member_of_collection 
  has_metadata name: 'descMetadata', type: ActiveFedora::SimpleDatastream do |sds|
    sds.field :name, :string
    sds.field :unit, :string
    sds.field :description, :string
  end
  has_metadata name: 'inheritedRights', type: Hydra::Datastream::InheritableRightsMetadata
  has_metadata name: 'defaultRights', type: Hydra::Datastream::NonIndexedRightsMetadata, autocreate: true

  validates :name, :uniqueness => { :solr_name => 'name_tesim'}, presence: true
  validates :unit, presence: true, inclusion: {in: proc{Admin::Collection.units}}
  validates :managers, length: {minimum: 1, message: 'Collection requires at least 1 manager'} 

  delegate :name, to: :descMetadata, unique: true
  delegate :unit, to: :descMetadata, unique: true
  delegate :description, to: :descMetadata, unique: true
  delegate :read_groups, :read_users, :access, :access=, :hidden?, :hidden=, :group_exceptions,
           :group_exceptions=, :user_exceptions, :user_exceptions=, to: :defaultRights, prefix: :default

  def self.units
    ["University Archives", "Black Film Center/Archive"]
  end

  def created_at
    @created_at ||= DateTime.parse(create_date)
  end

  def to_solr(solr_doc = Hash.new, opts = {})
    map = Solrizer::default_field_mapper
    solr_doc[ map.solr_name(:name, :stored_searchable, type: :string).to_sym ] = self.name
    super(solr_doc)
  end

  def managers
    edit_users & (RoleControls.users("manager") || [])
  end

  def managers= users
{'fraction_non_alphanumeric': 0.11469344608879492, 'fraction_numerical': 0.0010570824524312897, 'mean_word_length': 5.7229129662522205, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, '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': '2243378', 'n_tokens_mistral': 1257, 'n_tokens_neox': 1205, 'n_words': 287}