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
600a9341
Commit
600a9341
authored
9 years ago
by
Mauricio Giacomini Girardello
Browse files
Options
Downloads
Patches
Plain Diff
move some institution repository logic for explicity methods
parent
c6172417
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
app/builders/institution_builder.rb
+0
-2
0 additions, 2 deletions
app/builders/institution_builder.rb
app/repositories/orient_db/institution_repository.rb
+11
-4
11 additions, 4 deletions
app/repositories/orient_db/institution_repository.rb
with
11 additions
and
6 deletions
app/builders/institution_builder.rb
+
0
−
2
View file @
600a9341
...
@@ -10,9 +10,7 @@ class InstitutionBuilder
...
@@ -10,9 +10,7 @@ class InstitutionBuilder
institutions
.
each
do
|
institution
|
institutions
.
each
do
|
institution
|
unless
institution
[
'@rid'
].
blank?
unless
institution
[
'@rid'
].
blank?
o
=
Rails
.
cache
.
fetch
(
cache_key
(
institution
[
'@rid'
],
institution
[
'last_modified'
]))
unless
institution
[
'last_modified'
].
blank?
o
=
Rails
.
cache
.
fetch
(
cache_key
(
institution
[
'@rid'
],
institution
[
'last_modified'
]))
unless
institution
[
'last_modified'
].
blank?
o
=
institution_repository
.
find
institution
[
'@rid'
]
if
o
.
nil?
o
=
institution_repository
.
find
institution
[
'@rid'
]
if
o
.
nil?
array
<<
o
array
<<
o
end
end
end
end
...
...
This diff is collapsed.
Click to expand it.
app/repositories/orient_db/institution_repository.rb
+
11
−
4
View file @
600a9341
...
@@ -4,7 +4,7 @@ module OrientDb
...
@@ -4,7 +4,7 @@ module OrientDb
def
create
(
institution
)
def
create
(
institution
)
institution
=
connection
.
command
sprintf
(
"INSERT INTO Institution (name, created_at, last_modified, country, city, description, thumbnail, address) VALUES ('%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s')"
,
institution
=
connection
.
command
sprintf
(
"INSERT INTO Institution (name, created_at, last_modified, country, city, description, thumbnail, address) VALUES ('%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s')"
,
institution
.
name
,
Time
.
now
,
Time
.
now
,
institution
.
country
,
institution
.
city
,
institution
.
description
,
institution
.
thumbnail
,
institution
.
address
)
institution
.
name
,
Time
.
now
,
Time
.
now
,
institution
.
country
,
institution
.
city
,
institution
.
description
,
institution
.
thumbnail
,
institution
.
address
)
find
(
institution
[
"result"
][
0
][
"@rid"
])
||
false
find
(
institution
[
"result"
][
0
][
"@rid"
])
||
false
end
end
...
@@ -21,16 +21,23 @@ module OrientDb
...
@@ -21,16 +21,23 @@ module OrientDb
# else return nil
# else return nil
#
#
def
associated_with
(
object
)
def
associated_with
(
object
)
return
InstitutionBuilder
.
build
get_edges_end
(
'BelongsTo'
,
'out'
,
object
.
rid
)
if
object
.
class
==
User
return
associated_institutions
(
object
)
if
object
.
class
==
User
return
User
.
find
(
get_edges_end
(
'BelongsTo'
,
'in'
,
object
.
id
).
map
{
|
user
|
user
[
'p_id'
]}
)
if
object
.
class
==
Institution
return
associated_users
(
object
)
if
object
.
class
==
Institution
return
nil
return
nil
end
end
def
associated_institutions
(
user
)
InstitutionBuilder
.
build
get_edges_end
(
'BelongsTo'
,
'out'
,
user
.
rid
)
end
def
associated_users
(
institution
)
User
.
find
(
get_edges_end
(
'BelongsTo'
,
'in'
,
institution
.
id
).
map
{
|
user
|
user
[
'p_id'
]
})
end
def
add_user
(
user
,
institution
)
def
add_user
(
user
,
institution
)
unless
edge_exists?
"BelongsTo"
,
user
.
rid
,
institution
.
id
unless
edge_exists?
"BelongsTo"
,
user
.
rid
,
institution
.
id
create_edge
"BelongsTo"
,
user
.
rid
,
institution
.
id
create_edge
"BelongsTo"
,
user
.
rid
,
institution
.
id
end
end
institution
institution
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