Class: ActiveStix::CourseOfAction
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- ActiveStix::CourseOfAction
- Defined in:
- app/models/active_stix/course_of_action.rb
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.ingest_json(obj) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'app/models/active_stix/course_of_action.rb', line 12 def self.ingest_json(obj) course_of_action = find_or_create_by(stix_id: obj['id'], name: obj['name'], description: obj['description']) if obj.has_key?('external_references') obj['external_references'].each do |er| external_reference = ExternalReference.ingest_json(er, obj['id']) course_of_action.external_references << external_reference unless ActiveStix::ReferenceItem.find_by(external_reference:external_reference, referrer: course_of_action) end end if obj.has_key?('object_marking_refs') # TODO # obj['object_marking_refs'].each do |mr| # marking_definition = MarkingDefinition.create_by_id(mr) # course_of_action.marking_definitions << marking_definition unless ActiveStix::ReferenceObjectMarkingCourse.find_by(stix_marking_definition_id:marking_definition.id, stix_course_of_action_id:course_of_action.id) # end end course_of_action.save course_of_action end |
Instance Method Details
#convert_to_json ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'app/models/active_stix/course_of_action.rb', line 31 def convert_to_json external_refs_arr = [] external_references.each do | x | external_refs_arr << x.convert_to_json end marking_def_arr = [] marking_definitions.each do | x | marking_def_arr << x.convert_to_json end { :external_references => external_refs_arr, :object_marking_refs => marking_def_arr, :id => stix_id, :name => name, :type => "course-of-action", :modified => updated_at.to_s, :created => created_at.to_s, :description => description } end |