labimotion 0.1.15 → 0.1.16

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9a72bc36d304bce71f181b4a5b8b5bcb81532cd21c204efee6f75fa3fb85a29f
4
- data.tar.gz: d9fe725cf70b07074df5a045dcb5025090a1160c3c04621f8d13fe4e14a5cfbc
3
+ metadata.gz: 95752e2c3001d5de57f899a05dc5e348611cd3408a7fe1a1448ee426edf56437
4
+ data.tar.gz: b8715b44806c7586c71c05534e83147ec33a0648f771bd3867b0212440cdaa69
5
5
  SHA512:
6
- metadata.gz: dfffccf852420e3d9aac5ec9bb36ce9f10f738a4d814633d0a07a31a3dba9eabd712955dec68b9e18644fc888adf47b6967075b9994e1eb59a6fc4176eb4ffb0
7
- data.tar.gz: 23c5d2ce7d797a86f29c29c6fcee85dfb78e61dca82a9b0dc4535b9e9098cda085b33089bcd2c2cb72b702df13a8805e29ff93ae27dc1efea7a65e756a37db07
6
+ metadata.gz: 45faeec9d12b78dec9838b47ac863f4492ae1808f84e4777f38d9a3137e60b74c238827ceff45639a003535906e6ec9a339d669cbc935eba62bbcb0e1157533f
7
+ data.tar.gz: a19c0cd0422952d57e1151ffe87ddc032e1e18f2029ab860284a094f6ad5d645665771f7705dd7a39bfd139d524ab67a0635c936f1a46f981f55ef16b7188ed1
@@ -30,7 +30,7 @@ module Labimotion
30
30
  namespace :fetch_repo do
31
31
  desc 'fetch Generic Dataset Klass from Chemotion Repository'
32
32
  get do
33
- fetch_repo('DatasetKlass')
33
+ fetch_repo('DatasetKlass', current_user)
34
34
  end
35
35
  end
36
36
 
@@ -40,8 +40,9 @@ module Labimotion
40
40
  requires :identifier, type: String, desc: 'Identifier'
41
41
  end
42
42
  post do
43
- create_repo_klass(params, current_user)
44
- present DatasetKlass.all, with: Labimotion::DatasetKlassEntity, root: 'klass'
43
+ msg = create_repo_klass(params, current_user, request.headers['Origin'])
44
+ klass = Labimotion::DatasetKlassEntity.represent(DatasetKlass.all)
45
+ { status: msg[:status], message: msg[:message], klass: klass }
45
46
  rescue StandardError => e
46
47
  Labimotion.log_exception(e, current_user)
47
48
  { error: e.message }
@@ -196,7 +196,7 @@ module Labimotion
196
196
  namespace :fetch_repo do
197
197
  desc 'fetch Generic Element Klass from Chemotion Repository'
198
198
  get do
199
- fetch_repo('ElementKlass')
199
+ fetch_repo('ElementKlass', current_user)
200
200
  rescue StandardError => e
201
201
  Labimotion.log_exception(e, current_user)
202
202
  []
@@ -209,8 +209,9 @@ module Labimotion
209
209
  requires :identifier, type: String, desc: 'Identifier'
210
210
  end
211
211
  post do
212
- create_repo_klass(params, current_user)
213
- present ElementKlass.all, with: Labimotion::ElementKlassEntity, root: 'klass'
212
+ msg = create_repo_klass(params, current_user, request.headers['Origin'])
213
+ klass = Labimotion::ElementKlassEntity.represent(ElementKlass.all)
214
+ { status: msg[:status], message: msg[:message], klass: klass }
214
215
  rescue StandardError => e
215
216
  Labimotion.log_exception(e, current_user)
216
217
  { error: e.message }
@@ -118,7 +118,7 @@ module Labimotion
118
118
  namespace :fetch_repo do
119
119
  desc 'fetch Generic Segment Klass from Chemotion Repository'
120
120
  get do
121
- fetch_repo('SegmentKlass')
121
+ fetch_repo('SegmentKlass', current_user)
122
122
  rescue StandardError => e
123
123
  Labimotion.log_exception(e, current_user)
124
124
  { error: e.message }
@@ -131,8 +131,9 @@ module Labimotion
131
131
  requires :identifier, type: String, desc: 'Identifier'
132
132
  end
133
133
  post do
134
- create_repo_klass(params, current_user)
135
- present SegmentKlass.all, with: Labimotion::SegmentKlassEntity, root: 'klass'
134
+ msg = create_repo_klass(params, current_user, request.headers['Origin'])
135
+ klass = Labimotion::SegmentKlassEntity.represent(SegmentKlass.all)
136
+ { status: msg[:status], message: msg[:message], klass: klass }
136
137
  rescue StandardError => e
137
138
  Labimotion.log_exception(e, current_user)
138
139
  ## { error: e.message }
@@ -13,8 +13,8 @@ module Labimotion
13
13
  end
14
14
  end
15
15
 
16
- def create_repo_klass(params, current_user)
17
- response = Labimotion::TemplateHub.fetch_identifier('DatasetKlass', params[:identifier])
16
+ def create_repo_klass(params, current_user, origin)
17
+ response = Labimotion::TemplateHub.fetch_identifier('DatasetKlass', params[:identifier], origin)
18
18
  attributes = response.slice('ols_term_id', 'label', 'desc', 'uuid', 'identifier', 'properties_release', 'version') # .except(:id, :is_active, :place, :created_by, :created_at, :updated_at)
19
19
  attributes['properties_release']['identifier'] = attributes['identifier']
20
20
  attributes['properties_template'] = attributes['properties_release']
@@ -23,14 +23,22 @@ module Labimotion
23
23
  attributes['updated_by'] = current_user.id
24
24
  attributes['sync_by'] = current_user.id
25
25
  attributes['sync_time'] = DateTime.now
26
- if Labimotion::DatasetKlass.find_by(ols_term_id: attributes['ols_term_id']).present?
27
- ds = Labimotion::DatasetKlass.find_by(ols_term_id: attributes['ols_term_id'])
28
- ds.update!(attributes)
26
+ dataset_klass = Labimotion::DatasetKlass.find_by(ols_term_id: attributes['ols_term_id'])
27
+ if dataset_klass.present?
28
+ if dataset_klass['uuid'] == attributes['uuid'] && dataset_klass['version'] == attributes['version']
29
+ { status: 'success', message: "This dataset: #{attributes['label']} has the latest version!" }
30
+ else
31
+ ds = Labimotion::DatasetKlass.find_by(ols_term_id: attributes['ols_term_id'])
32
+ ds.update!(attributes)
33
+ ds.create_klasses_revision(current_user)
34
+ { status: 'success', message: "This dataset: [#{attributes['label']}] has been upgraded to the version: #{attributes['version']}!" }
35
+ end
29
36
  else
30
37
  attributes['created_by'] = current_user.id
31
38
  ds = Labimotion::DatasetKlass.create!(attributes)
39
+ ds.create_klasses_revision(current_user)
40
+ { status: 'success', message: "The dataset: #{attributes['label']} has been created using version: #{attributes['version']}!" }
32
41
  end
33
- ds.create_klasses_revision(current_user)
34
42
  rescue StandardError => e
35
43
  Labimotion.log_exception(e, current_user)
36
44
  # { error: e.message }
@@ -289,9 +289,9 @@ module Labimotion
289
289
  raise e
290
290
  end
291
291
 
292
- def create_repo_klass(params, current_user)
293
- response = Labimotion::TemplateHub.fetch_identifier('ElementKlass', params[:identifier])
294
- attributes = response.slice('name', 'label', 'desc', 'icon_name', 'klass_prefix', 'is_generic', 'identifier', 'properties_release', 'version')
292
+ def create_repo_klass(params, current_user, origin)
293
+ response = Labimotion::TemplateHub.fetch_identifier('ElementKlass', params[:identifier], origin)
294
+ attributes = response.slice('name', 'label', 'desc', 'icon_name', 'uuid', 'klass_prefix', 'is_generic', 'identifier', 'properties_release', 'version')
295
295
  attributes['properties_release']['identifier'] = attributes['identifier']
296
296
  attributes['properties_template'] = attributes['properties_release']
297
297
  attributes['place'] = ((Labimotion::DatasetKlass.all.length * 10) || 0) + 10
@@ -302,12 +302,24 @@ module Labimotion
302
302
 
303
303
  element_klass = Labimotion::ElementKlass.find_by(identifier: attributes['identifier'])
304
304
  if element_klass.present?
305
- element_klass.update!(attributes)
305
+ if element_klass['uuid'] == attributes['uuid'] && element_klass['version'] == attributes['version']
306
+ { status: 'success', message: "This element: #{attributes['name']} has the latest version!" }
307
+ else
308
+ element_klass.update!(attributes)
309
+ element_klass.create_klasses_revision(current_user)
310
+ { status: 'success', message: "This element: [#{attributes['name']}] has been upgraded to the version: #{attributes['version']}!" }
311
+ end
306
312
  else
307
- attributes['created_by'] = current_user.id
308
- element_klass = Labimotion::ElementKlass.create!(attributes)
313
+ exist_klass = Labimotion::ElementKlass.find_by(name: attributes['name'])
314
+ if exist_klass.present?
315
+ { status: 'error', message: "The name [#{attributes['name']}] is already in use." }
316
+ else
317
+ attributes['created_by'] = current_user.id
318
+ element_klass = Labimotion::ElementKlass.create!(attributes)
319
+ element_klass.create_klasses_revision(current_user)
320
+ { status: 'success', message: "The element: #{attributes['name']} has been created using version: #{attributes['version']}!" }
321
+ end
309
322
  end
310
- element_klass.create_klasses_revision(current_user)
311
323
  rescue StandardError => e
312
324
  Labimotion.log_exception(e, current_user)
313
325
  # { error: e.message }
@@ -230,15 +230,16 @@ module Labimotion
230
230
  Chemotion::Generic::Fetch::Template.list(API::TARGET, name)
231
231
  end
232
232
 
233
- def fetch_repo(name)
234
- current_klasses = "Labimotion::#{name}".constantize.where.not(identifier: nil)&.pluck(:identifier) || []
233
+ def fetch_repo(name, current_user)
234
+ # current_klasses = "Labimotion::#{name}".constantize.where.not(identifier: nil)&.pluck(:identifier) || []
235
235
  response = Labimotion::TemplateHub.list(name)
236
- if response && response['list'].present? && response['list'].length.positive?
237
- filter_list = response['list']&.reject do |ds|
238
- current_klasses.include?(ds['identifier'])
239
- end || []
240
- end
241
- filter_list || []
236
+ # if response && response['list'].present? && response['list'].length.positive?
237
+ # filter_list = response['list']&.reject do |ds|
238
+ # current_klasses.include?(ds['identifier'])
239
+ # end || []
240
+ # end
241
+ # filter_list || []
242
+ (response && response['list']) || []
242
243
  rescue StandardError => e
243
244
  Labimotion.log_exception(e, current_user)
244
245
  { error: 'Cannot connect to Chemotion Repository' }
@@ -63,8 +63,8 @@ module Labimotion
63
63
  raise e
64
64
  end
65
65
 
66
- def create_repo_klass(params, current_user)
67
- response = Labimotion::TemplateHub.fetch_identifier('SegmentKlass', params[:identifier])
66
+ def create_repo_klass(params, current_user, origin)
67
+ response = Labimotion::TemplateHub.fetch_identifier('SegmentKlass', params[:identifier], origin)
68
68
  attributes = response.slice('label', 'desc', 'uuid', 'identifier', 'released_at', 'properties_release', 'version')
69
69
  attributes['properties_release']['identifier'] = attributes['identifier']
70
70
  attributes['properties_template'] = attributes['properties_release']
@@ -75,8 +75,8 @@ module Labimotion
75
75
  attributes['sync_time'] = DateTime.now
76
76
 
77
77
  element_klass = Labimotion::ElementKlass.find_by(identifier: response['element_klass']['identifier'])
78
- element_klass = Labimotion::ElementKlass.find_by(name: response['element_klass']['name']) if element_klass.nil?
79
- return { error: 'ElementKlass not found' } if element_klass.nil?
78
+ element_klass = Labimotion::ElementKlass.find_by(name: response['element_klass']['name'], is_generic: false) if element_klass.nil?
79
+ return { status: 'error', message: "The element [#{response['element_klass']['name']}] does not exist in this instance" } if element_klass.nil?
80
80
 
81
81
  # el_attributes = response['element_klass'].slice('name', 'label', 'desc', 'uuid', 'identifier', 'icon_name', 'klass_prefix', 'is_generic', 'released_at')
82
82
  # el_attributes['properties_template'] = response['element_klass']['properties_release']
@@ -85,12 +85,24 @@ module Labimotion
85
85
  attributes['element_klass_id'] = element_klass.id
86
86
  segment_klass = Labimotion::SegmentKlass.find_by(identifier: attributes['identifier'])
87
87
  if segment_klass.present?
88
- segment_klass.update!(attributes)
88
+ if segment_klass['uuid'] == attributes['uuid'] && segment_klass['version'] == attributes['version']
89
+ { status: 'success', message: "This segment: #{attributes['label']} has the latest version!" }
90
+ else
91
+ segment_klass.update!(attributes)
92
+ segment_klass.create_klasses_revision(current_user)
93
+ { status: 'success', message: "This segment: [#{attributes['label']}] has been upgraded to the version: #{attributes['version']}!" }
94
+ end
89
95
  else
90
- attributes['created_by'] = current_user.id
91
- segment_klass = Labimotion::SegmentKlass.create!(attributes)
96
+ exist_klass = Labimotion::SegmentKlass.find_by(label: attributes['label'], element_klass_id: element_klass.id)
97
+ if exist_klass.present?
98
+ { status: 'error', message: "The segment [#{attributes['label']}] is already in use." }
99
+ else
100
+ attributes['created_by'] = current_user.id
101
+ segment_klass = Labimotion::SegmentKlass.create!(attributes)
102
+ segment_klass.create_klasses_revision(current_user)
103
+ { status: 'success', message: "The segment: #{attributes['label']} has been created using version: #{attributes['version']}!" }
104
+ end
92
105
  end
93
- segment_klass.create_klasses_revision(current_user)
94
106
  rescue StandardError => e
95
107
  Labimotion.log_exception(e, current_user)
96
108
  raise e
@@ -43,11 +43,15 @@ module Labimotion
43
43
  error!('Cannot connect to Chemotion Repository', 401)
44
44
  end
45
45
 
46
- def self.fetch_identifier(klass, identifier)
47
- # body = { klass: klass, identifier: identifier }
48
- response = HTTParty.get("#{uri('fetch')}?klass=#{klass}&identifier=#{identifier}", timeout: 10)
46
+ def self.fetch_identifier(klass, identifier, origin)
47
+ body = { klass: klass, identifier: identifier, origin: origin }
48
+ response = HTTParty.post(
49
+ uri('fetch'),
50
+ body: body,
51
+ timeout: 10
52
+ )
49
53
  # response.parsed_response if response.code == 200
50
- JSON.parse(response.body) if response.code == 200
54
+ JSON.parse(response.body) if response.code == 201
51
55
  rescue StandardError => e
52
56
  Labimotion.log_exception(e)
53
57
  error!('Cannot connect to Chemotion Repository', 401)
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Labimotion
4
4
  IS_RAILS5 = true
5
- VERSION = '0.1.15' if Labimotion::IS_RAILS5 == true
5
+ VERSION = '0.1.16' if Labimotion::IS_RAILS5 == true
6
6
  VERSION = '1.0.1' if Labimotion::IS_RAILS5 == false
7
7
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: labimotion
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.15
4
+ version: 0.1.16
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chia-Lin Lin