Skip to content

Commit

Permalink
Chemotion Repository 2.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
cllde8 committed Jan 18, 2024
1 parent ac68a80 commit 290d1bb
Show file tree
Hide file tree
Showing 735 changed files with 3,532 additions and 102,345 deletions.
2 changes: 1 addition & 1 deletion .env.production.example
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ DEVISE_DISABLED_SIGN_UP=''
DEVISE_NEW_ACCOUNT_INACTIVE=false

# Application's title
APPLICATION_TITLE='Chemotion'
APPLICATION_TITLE='Chemotion Repository'

DATA_CITE_BASE_URI=https://api.test.datacite.org
DATA_CITE_PREFIX=prefix
Expand Down
794 changes: 69 additions & 725 deletions CHANGELOG.md

Large diffs are not rendered by default.

37 changes: 13 additions & 24 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,22 @@

Empowering chemists with a comprehensive solution for storing, managing, and analyzing samples, reactions, and research data.

---
## Usage

Initiate your exploration of the Chemotion Repository by visiting our official website: **[Chemotion Repository](https://www.chemotion-repository.net/welcome)**.

For a comprehensive understanding of the Chemotion Repository, refer to our online **[Documentation](https://www.chemotion.net/docs/repo/)**.

## Acknowledgments

Funded by the [Deutsche Forschungsgemeinschaft (DFG, German Research Foundation)](https://www.dfg.de/) under the [National Research Data Infrastructure – NFDI4Chem](https://nfdi4chem.de/) – Projektnummer **441958208**.

<a href="https://www.dfg.de/" target="_blank"><img src="./public/images/repo/dfg_logo_schriftzug_blau_foerderung_en.jpg" width="50%" alt="DFG Logo"></a>

## License

**Copyright © `2015` - `2023`[Nicole Jung]** <br>
of the **[Karlsruhe Institute of Technology]**.
**Copyright © `2015` - `2024`[Nicole Jung](mailto:[email protected])** <br>
of the **[Karlsruhe Institute of Technology](https://www.kit.edu/english/)**.

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
Expand All @@ -21,24 +31,3 @@ of the **[Karlsruhe Institute of Technology]**.

You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.

---

## Acknowledgments

## User Documentation

This project has been funded by the **[DFG]**.

[![DFG Logo]][DFG]

## User Documentation

see online **[Documentation]**

<!----------------------------------------------------------------------------->
[Documentation]: https://www.chemotion.net/docs/repo/
[DFG]: https://www.dfg.de/en/
[DFG Logo]: https://www.dfg.de/zentralablage/bilder/service/logos_corporate_design/logo_negativ_267.png
[Nicole Jung]: mailto:[email protected]
[Karlsruhe Institute of Technology]: https://www.kit.edu/english/
112 changes: 0 additions & 112 deletions app/api/chemotion/attachment_api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,6 @@ def remove_duplicated(att)

old_att&.destroy
end

def validate_uuid_format(uuid)
uuid_regex = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-5][0-9a-f]{3}-[089ab][0-9a-f]{3}-[0-9a-f]{12}$/i
return true if uuid_regex.match?(uuid.to_s.downcase)

return false
end
end

rescue_from ActiveRecord::RecordNotFound do |_error|
Expand Down Expand Up @@ -151,20 +144,6 @@ def validate_uuid_format(uuid)
(ElementPolicy.new(current_user, element).read? &&
ElementPermissionProxy.new(current_user, element, user_ids).read_dataset?)
end

if !can_dwnld && @attachment.attachable_type == 'SegmentProps'
element = Segment.find(@attachment.attachable_id)&.element
can_dwnld = @attachment.created_for == current_user.id ||
(ElementPolicy.new(current_user, element).read? &&
ElementPermissionProxy.new(current_user, element, user_ids).read_dataset?)
end

if !can_dwnld && @attachment.attachable_type == 'SegmentProps'
element = Segment.find(@attachment.attachable_id)&.element
can_dwnld = @attachment.created_for == current_user.id ||
(ElementPolicy.new(current_user, element).read? &&
ElementPermissionProxy.new(current_user, element, user_ids).read_dataset?)
end
end
error!('401 Unauthorized', 401) unless can_dwnld
end
Expand Down Expand Up @@ -514,97 +493,6 @@ def validate_uuid_format(uuid)
{ status: true }
end

desc 'Regenerate edited spectra'
params do
requires :edited, type: Array[Integer]
optional :molfile, type: String
end
post 'regenerate_edited_spectrum' do
pm = to_rails_snake_case(params)
pm[:edited].each do |g_id|
att = Attachment.find(g_id)
next unless att
can_edit = writable?(att)

next unless writable?(att)

remove_duplicated(att)

abs_path = att.abs_path
molfile = pm[:molfile]
result = Tempfile.create('molfile') do |t_molfile|
t_molfile.write(molfile)
t_molfile.rewind
Chemotion::Jcamp::RegenerateJcamp.spectrum(
abs_path, t_molfile.path
)
end

att.file_data = result
att.rewrite_file_data!
{ status: true }

end
end

desc 'Regenerate edited spectra'
params do
requires :edited, type: Array[Integer]
optional :molfile, type: String
end
post 'regenerate_edited_spectrum' do
pm = to_rails_snake_case(params)
pm[:edited].each do |g_id|
att = Attachment.find(g_id)
next unless att
can_edit = writable?(att)
if can_edit
abs_path = att.abs_path
molfile = pm[:molfile]
result = Tempfile.create('molfile') do |t_molfile|
t_molfile.write(molfile)
t_molfile.rewind
Chemotion::Jcamp::RegenerateJcamp.spectrum(
abs_path, t_molfile.path
)
end

att.file_data = result
att.rewrite_file_data!
{ status: true }
end
end
end

desc 'Regenerate edited spectra'
params do
requires :edited, type: Array[Integer]
optional :molfile, type: String
end
post 'regenerate_edited_spectrum' do
pm = to_rails_snake_case(params)
pm[:edited].each do |g_id|
att = Attachment.find(g_id)
next unless att
can_edit = writable?(att)
if can_edit
abs_path = att.abs_path
molfile = pm[:molfile]
result = Tempfile.create('molfile') do |t_molfile|
t_molfile.write(molfile)
t_molfile.rewind
Chemotion::Jcamp::RegenerateJcamp.spectrum(
abs_path, t_molfile.path
)
end

att.file_data = result
att.rewrite_file_data!
{ status: true }
end
end
end

desc 'Save spectra to file'
params do
requires :attachment_id, type: Integer
Expand Down
29 changes: 1 addition & 28 deletions app/api/chemotion/collection_api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,34 +27,6 @@ class CollectionAPI < Grape::API
end
end

namespace :all_as_tree do
desc "Return the 'All' collection of the current user"
get do
current_user.collections.arrange_serializable do |parent, children|
{
title: parent.label,
value: parent.id,
key: parent.id,
children: children
}
end
end
end

namespace :all_as_tree do
desc "Return the 'All' collection of the current user"
get do
current_user.collections.arrange_serializable do |parent, children|
{
title: parent.label,
value: parent.id,
key: parent.id,
children: children
}
end
end
end

desc "Return collection by id"
params do
requires :id, type: Integer, desc: "Collection id"
Expand Down Expand Up @@ -350,6 +322,7 @@ class CollectionAPI < Grape::API
ui_state[:checkedIds] = ui_state[:checkedIds].presence || ui_state[:included_ids]
ui_state[:uncheckedIds] = ui_state[:uncheckedIds].presence || ui_state[:excluded_ids]
next unless ui_state[:checkedAll] || ui_state[:checkedIds].present?

collections_element_klass = ('collections_' + element).classify.constantize
element_klass = element.classify.constantize
ids = element_klass.by_collection_id(from_collection.id).by_ui_state(ui_state).pluck(:id)
Expand Down
68 changes: 0 additions & 68 deletions app/api/chemotion/converter_api.rb

This file was deleted.

7 changes: 0 additions & 7 deletions app/api/chemotion/element_api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -100,13 +100,6 @@ class ElementAPI < Grape::API
deleted[klass.name] = @collection.send('elements').by_ui_state(params[klass.name]).destroy_all.map(&:id)
end

sql_pub = "(element_id in (?) and element_type = 'Sample') or (element_id in (?) and element_type = 'Reaction')"
Publication.where(sql_pub, deleted['sample'], deleted['reaction'])
.map(&:root).uniq.each do |e|
e.update_state(Publication::STATE_DECLINED)
e.proces_element(Publication::STATE_DECLINED)
e.inform_users(Publication::STATE_DECLINED, current_user.id)
end
{ selecteds: params[:selecteds].select { |sel| !deleted.fetch(sel['type'], []).include?(sel['id']) } }
end

Expand Down
72 changes: 0 additions & 72 deletions app/api/chemotion/gate_api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -159,78 +159,6 @@ def self.parsed?(value)
end


desc <<~DESC
receive sample and reaction data from a remote eln and import them into a designated
collection according to JWT info. (authentication through JWT)
DESC
namespace :receiving_zip do
params do
requires :data, type: File
end

before do
http_token = if request.headers['Authorization'].present?
request.headers['Authorization'].split(' ').last
end
error!('Unauthorized', 401) unless http_token
secret = Rails.application.secrets.secret_key_base
begin
@auth_token = HashWithIndifferentAccess.new(
JWT.decode(http_token, secret)[0]
)
rescue JWT::VerificationError, JWT::DecodeError, JWT::ExpiredSignature => e
error!("#{e}", 401)
end
@user = Person.find_by(email: @auth_token[:iss])
error!('Unauthorized', 401) unless @user
@collection = Collection.find_by(
id: @auth_token[:collection], user_id: @user.id, is_shared: false
)
error!('Unauthorized access to collection', 401) unless @collection

@origin = @auth_token["origin"]
end

post do
db_file = params[:data]&.fetch('tempfile', nil)
# file = params[:file]
tempfile = db_file
att = Attachment.new(
filename: params[:data][:filename],
key: File.basename(tempfile.path),
file_path: tempfile,
created_by: @user.id,
created_for: @user.id,
content_type: 'application/zip'
)
begin
att.save!
ensure
tempfile.close
tempfile.unlink
end

begin
import = Import::ImportCollections.new(att, @user.id, true, @collection.id, @origin)
import.extract
import.import!
rescue => e
Delayed::Worker.logger.error e
Message.create_msg_notification(
channel_subject: Channel::COLLECTION_ZIP_FAIL,
message_from: @user&.id,
data_args: { col_labels: '', operation: 'import' },
autoDismiss: 5
)
@success = false
ensure
att&.destroy!
end
status(200)
end
end


desc <<~DESC
receive sample and reaction data from a remote eln and import them into a designated
collection according to JWT info. (authentication through JWT)
Expand Down
Loading

0 comments on commit 290d1bb

Please sign in to comment.