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
c14a58b4
"db/migrate/20180406125006_add_ip_to_views.rb" did not exist on "0fe9f3f86001bfee14320aebd8761ac0534e864f"
Commit
c14a58b4
authored
9 years ago
by
Bruno Nocera Zanette
Browse files
Options
Downloads
Patches
Plain Diff
Fix merges on LearningObject Repository
parent
10866bf0
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
app/repositories/orient_db/learning_object_repository.rb
+65
-78
65 additions, 78 deletions
app/repositories/orient_db/learning_object_repository.rb
with
65 additions
and
78 deletions
app/repositories/orient_db/learning_object_repository.rb
+
65
−
78
View file @
c14a58b4
module
OrientDb
class
LearningObjectRepository
<
Base
include
OrientDb
::
Methods
::
EdgeMethods
include
RepositoriesProxy
def
increment_views
(
user
,
learning_object
)
create_edge
"Views"
,
user
.
rid
,
learning_object
.
id
...
...
@@ -8,7 +9,7 @@ module OrientDb
#
# Usage:
# repository.for(:learning_objects).like @learning_object
, current_user
# repository.for(:learning_objects).like
current_user,
@learning_object
#
def
like
(
user
,
learning_object
)
create_edge
"Likes"
,
user
.
rid
,
learning_object
.
id
...
...
@@ -24,73 +25,80 @@ module OrientDb
learning_objects
=
build_learning_objects
(
learning_objects_hash
)
||
[]
end
# Example:
# list = repository.for(:learning_objects).all
# list.each do |learning_object|
# learning_object.inspect <LearningObject model>
# end
def
all_ids
(
limit
=
100
,
offset
=
0
)
learning_objects_hash
=
connection
.
query
"SELECT @rid FROM LearningObject LIMIT
#{
limit
}
OFFSET
#{
offset
}
"
,
{
limit:
limit
}
learning_objects_ids
=
[]
learning_objects_hash
.
each
do
|
id
|
learning_objects_ids
<<
id
[
"rid"
]
end
learning_objects_ids
end
# Usage:
# learning_object = repository.for(:learning_objects).get_by_dspace_id 123
#
def
get_by_dspace_id
(
id_dspace
)
result
=
connection
.
query
"SELECT FROM LearningObject WHERE
id_dspace
=
#{
id_dspace
}
"
build_
learning_
object
result
.
first
result
=
select_by_property
(
odb_class
,
"
id_dspace
"
,
id_dspace
)
build_object
result
.
first
end
# Usage:
# learning_object = repository.for(:learning_objects).get_by_dspace_id 123
#
def
find
(
id
)
result
=
connection
.
query
"SELECT FROM
#{
id
}
"
build_learning_object
result
.
first
def
get_subjects
(
learning_object
)
result
=
get_edges_end
(
"IsAbout"
,
"out"
,
learning_object
.
id
)
subject_repository
.
build_objects
(
result
)
end
def
get_attributes
(
learning_object
)
result
=
get_edges_end
(
"HasAttr"
,
"out"
,
learning_object
.
id
)
attribute_repository
.
build_objects
(
result
)
end
def
create
(
name
,
url
)
connection
.
command
sprintf
(
"INSERT INTO LearningObject (name,URL) VALUES ('%s','%s')"
,
name
,
url
)
def
create_relations
(
learning_object
)
edges
=
create_edges_from_array
(
"IsAbout"
,
learning_object
.
id
,
learning_object
.
subjects
,
true
)
edges
<<
create_edges_from_array
(
"HasAttr"
,
learning_object
.
id
,
learning_object
.
attributes
,
true
)
edges
.
flatten
end
# Usage:
# repository.for(:learning_objects).destroy learning_object
#
def
destroy
(
learning_object
)
connection
.
command
sprintf
(
"DELETE VERTEX
LearningObject
where @rid = '%s'"
,
learning_object
.
id
)
connection
.
command
sprintf
(
"DELETE VERTEX
#{
odb_class
}
where @rid = '%s'"
,
learning_object
.
id
)
end
##
# To create "index:learningobject_search" on OrientDB, use the following command:
# CREATE INDEX learningobject_search
# ON LearningObject (name, description)
# FULLTEXT ENGINE LUCENE
# METADATA {"analyzer":"org.apache.lucene.analysis.br.BrazilianAnalyzer"}
def
search
(
qry
)
# TO CREATE "index:learningobject_search" ON OrientDB, USE THE COMMAND:
# CREATE INDEX learningobject_search
# ON LearningObject (name, description)
# FULLTEXT ENGINE LUCENE
# METADATA {"analyzer":"org.apache.lucene.analysis.br.BrazilianAnalyzer"}
learning_objects_hash
=
connection
.
query
"
SELECT EXPAND(rid)
FROM index:learningobject_search
WHERE key LUCENE '
#{
qry
}
'
"
,
limit:
-
1
learning_objects
=
build_learning
_objects
(
learning_objects_hash
)
||
[]
build
_objects
(
learning_objects_hash
)
||
[]
end
#def author_of(rid)
# connection.query "SELECT expand(in) FROM (SELECT expand(out_author_of) FROM User WHERE @rid=#{rid})"
#end
#def has(rid)
# connection.query "SELECT expand(in) FROM (SELECT expand(out_has) FROM User WHERE @rid=#{rid})"
#end
def
build_object
(
args
=
{})
lo
=
nil
unless
args
.
nil?
lo
=
LearningObject
.
new
(
:id
=>
args
[
"@rid"
],
:name
=>
args
[
"name"
],
:description
=>
args
[
"description"
],
:thumbnail
=>
args
[
"thumbnail"
],
:created_at
=>
args
[
"created_at"
],
:id_dspace
=>
args
[
"id_dspace"
],
:type
=>
args
[
"type"
],
:bitstreams
=>
args
[
"bitstreams"
],
:metadata
=>
args
[
"metadata"
],
:last_modified
=>
args
[
"last_modified"
])
lo
.
likes
=
args
.
has_key?
(
"in_Likes"
)
?
args
[
"in_Likes"
].
size
:
0
lo
.
views
=
args
.
has_key?
(
"in_Views"
)
?
args
[
"in_Views"
].
size
:
0
end
lo
end
#def get_likes(id)
# likes = connection.query "select outE('Likes') from #{id}"
# likes[0]["outE"]
#end
def
build_hash
hash
=
super
hash
.
delete
(
"likes"
)
hash
.
delete
(
"views"
)
hash
.
delete
(
"downloads"
)
hash
.
delete
(
"subjects"
)
hash
.
delete
(
"attributes"
)
hash
end
private
...
...
@@ -98,47 +106,26 @@ module OrientDb
[
'thumbnail'
]
end
def
count_likes
(
learning_object
)
get_in_edges_count
"Likes"
,
learning_object
.
id
def
create_edges_from_array
(
edge_class
,
id
,
array
,
unique
=
false
)
edges
=
[]
array
.
each
do
|
o
|
unless
unique
&&
edge_exists?
(
edge_class
,
id
,
o
.
id
)
edges
<<
create_edge
(
edge_class
,
id
,
o
.
id
)
end
end
edges
end
def
count_views
(
learning_object
)
get_in_edges_count
"Views"
,
l
earning
_o
bject
.
id
def
odb_class
"L
earning
O
bject
"
end
def
build_learning_object
(
args
=
{})
lo
=
LearningObject
.
new
(
:id
=>
args
[
"@rid"
],
:name
=>
args
[
"name"
],
:description
=>
args
[
"description"
],
:thumbnail
=>
args
[
"thumbnail"
],
:date_creation
=>
args
[
"date_creation"
],
:id_dspace
=>
args
[
"id_dspace"
],
:type
=>
args
[
"type"
],
:bitstreams
=>
args
[
"bitstreams"
],
:metadata
=>
args
[
"metadata"
],
:last_modified
=>
args
[
"last_modified"
])
unless
args
[
"in_Likes"
].
nil?
lo
.
likes
=
args
[
"in_Likes"
].
count
else
lo
.
likes
=
0
end
unless
args
[
"in_Views"
].
nil?
lo
.
views
=
args
[
"in_Views"
].
count
else
lo
.
views
=
0
end
lo
def
count_likes
(
learning_object
)
get_in_edges_count
"Likes"
,
learning_object
.
id
end
def
build_learning_objects
(
hash
=
[])
learning_objects
=
[]
hash
.
each
do
|
h
|
learning_objects
<<
build_learning_object
(
h
)
end
learning_objects
def
count_views
(
learning_object
)
get_in_edges_count
"Views"
,
learning_object
.
id
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