Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
cleaning-portalmec
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Harbor Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Richard Fernando Heise Ferreira
cleaning-portalmec
Commits
c7468ae9
Commit
c7468ae9
authored
9 years ago
by
Giovanne Marcelo
Browse files
Options
Downloads
Patches
Plain Diff
Fixing bug
parent
d04f50e7
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
app/models/topic.rb
+2
-2
2 additions, 2 deletions
app/models/topic.rb
app/services/topics_importer.rb
+35
-11
35 additions, 11 deletions
app/services/topics_importer.rb
with
37 additions
and
13 deletions
app/models/topic.rb
+
2
−
2
View file @
c7468ae9
class
Topic
<
ActiveRecord
::
Base
has_and_belongs_to_many
:learning_objects
has_many
:topic_relationships
,
foreign_key:
"parent_id"
,
dependent: :destroy
,
autosave:
true
has_many
:subtopics
,
through: :topic_relationships
,
source: :child
,
autosave:
true
has_many
:topic_relationships
,
foreign_key:
"parent_id"
,
dependent: :destroy
has_many
:subtopics
,
through: :topic_relationships
,
source: :child
has_many
:topic_highlights
,
dependent: :destroy
...
...
This diff is collapsed.
Click to expand it.
app/services/topics_importer.rb
+
35
−
11
View file @
c7468ae9
...
...
@@ -4,38 +4,63 @@ class TopicsImporter
def
initialize
items
@items
=
items
@@topics
=
{}
@@topics_relations
=
[]
end
def
import
topic
s
=
[]
relation
s
=
[]
@items
.
each
do
|
learning_object
|
lo_topics
=
parse_topics
(
learning_object
.
get_metadata_values_of
"dc.subject.category"
)
lo_topics
.
each_with_index
do
|
topic_name
,
i
|
next
if
topic_exists?
topic_name
topic
=
Topic
.
where
(
name:
topic_name
).
new
topic
.
learning_objects
<<
learning_object
create_relations
(
@@topics
[
lo_topics
[
i
-
1
]],
topic
)
unless
i
==
0
create_relations
(
lo_topics
[
i
-
1
],
topic_name
)
unless
i
==
0
@@topics
[
topic_name
]
=
topic
end
end
separate_relations
()
end
Topic
.
import
@@topics
.
values
,
recursive:
true
Topic
.
import
@@topics
.
values
import_topics_relations
()
end
private
def
create_relations
parent_topic
,
topic
parent_topic
.
subtopics
<<
topic
def
create_relations
parent_name
,
child_name
@@topics_relations
.
push
(
parent_name
)
@@topics_relations
.
push
(
child_name
)
end
def
separate_relations
@@topics_relations
.
push
nil
end
def
import_topics_relations
relations
=
[]
@@topics_relations
.
each_with_index
do
|
relation
,
i
|
unless
relation
.
nil?
||
@@topics_relations
[
i
-
1
].
nil?
parent_id
=
Topic
.
find_by_name
(
@@topics_relations
[
i
-
1
]).
id
child_id
=
Topic
.
find_by_name
(
relation
).
id
unless
TopicRelationship
.
exists?
(
parent_id:
parent_id
,
child_id:
child_id
)
||
i
==
0
relations
.
push
TopicRelationship
.
where
(
parent_id:
parent_id
,
child_id:
child_id
).
new
end
end
end
TopicRelationship
.
import
relations
end
def
parse_topics
values
...
...
@@ -44,12 +69,11 @@ class TopicsImporter
values
.
each
do
|
value
|
topics
=
value
.
split
(
'::'
)
end
topics
topics
.
map
{
|
topic
|
topic
.
strip
}
end
def
topic_exists?
(
topic_name
)
Topic
.
exists?
name:
topic_name
||
!
@@topics
[
topic_name
].
nil?
end
end
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment