-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #193 from sparc-request/ac-klok-import
Ac klok import
- Loading branch information
Showing
14 changed files
with
373 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
require 'active_support/concern' | ||
|
||
module KlokShard | ||
|
||
extend ActiveSupport::Concern | ||
|
||
included do | ||
|
||
octopus_establish_connection(Octopus.config[Rails.env][:klok]) | ||
|
||
allow_shard :klok | ||
|
||
def self.inherited(child) | ||
child.octopus_establish_connection Octopus.config[Rails.env][:klok] | ||
super | ||
end | ||
|
||
def readonly? | ||
Rails.env.production? | ||
end | ||
|
||
def self.klok_record? | ||
true | ||
end | ||
|
||
# Allow queries (in particular, JOINs) across both Klok and | ||
# CWF databases by explicitly prefixing the appropriate Klok | ||
# database name to tables belonging to it. | ||
def self.table_name_prefix | ||
Octopus.config[Rails.env][:klok][:database] + '.' | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
class Klok::Entry < ActiveRecord::Base | ||
include KlokShard | ||
|
||
self.primary_key = 'entry_id' | ||
|
||
belongs_to :klok_person, class_name: 'Klok::Person', foreign_key: :resource_id | ||
belongs_to :klok_project, class_name: 'Klok::Project', foreign_key: :project_id | ||
has_one :service, through: :klok_project | ||
|
||
delegate :local_protocol, | ||
to: :klok_project, | ||
allow_nil: true | ||
|
||
delegate :local_identity, | ||
to: :klok_person, | ||
allow_nil: true | ||
|
||
def start_time_stamp=(value) | ||
super(DateTime.strptime(value,'%Q')) | ||
end | ||
|
||
def end_time_stamp=(value) | ||
super(DateTime.strptime(value,'%Q')) | ||
end | ||
|
||
def rounded_duration | ||
minutes = duration/60000.0 | ||
(minutes/15.0).ceil * 15.0 | ||
end | ||
|
||
def decimal_duration | ||
rounded_duration/60.0 | ||
end | ||
|
||
def is_valid? | ||
self.klok_project.present? && | ||
self.klok_project.ssr_id && | ||
self.klok_project.ssr_id.match(/\d\d\d\d-\d\d\d\d/) && | ||
self.local_protocol.present? && | ||
self.service.present? && | ||
self.klok_person.present? && | ||
self.local_identity.present? | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
class Klok::Person < ActiveRecord::Base | ||
include KlokShard | ||
|
||
self.primary_key = 'resource_id' | ||
|
||
has_many :klok_entries, class_name: 'Klok::Entry', foreign_key: :resource_id | ||
has_many :klok_projects, class_name: 'Klok::Project', foreign_key: :resource_id, through: :klok_entries | ||
|
||
def local_identity | ||
ldap_uid = name.split(" ").last.gsub(/[\(\)]*/, '') | ||
ldap_uid += "@musc.edu" #### TODO, update Klok so that @musc.edu is added | ||
Identity.where(ldap_uid: ldap_uid).first | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
class Klok::Project < ActiveRecord::Base | ||
include KlokShard | ||
|
||
self.primary_key = 'project_id' | ||
|
||
has_many :klok_entries, class_name: 'Klok::Entry', foreign_key: :project_id | ||
has_many :klok_people, class_name: 'Klok::Person', foreign_key: :resource_id, through: :klok_entries | ||
belongs_to :parent_project, class_name: 'Klok::Project', foreign_key: :parent_id | ||
has_many :child_projects, class_name: 'Klok::Project', foreign_key: :parent_id | ||
belongs_to :service, foreign_key: :code | ||
|
||
def ssr_id | ||
parent_project.try(:code) || code | ||
end | ||
|
||
def local_protocol | ||
sparc_id, ssr_version = ssr_id.split('-') | ||
Protocol.where(sparc_id: sparc_id).select{|p| p.sub_service_request.ssr_id == ssr_version}.first | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,9 @@ | ||
json.(fulfillment) | ||
|
||
json.id fulfillment.id | ||
json.fulfillment_date format_date(fulfillment.fulfilled_at) | ||
json.fulfillment_date fulfillment_date_formatter(fulfillment) | ||
json.quantity fulfillment.quantity | ||
json.quantity_type fulfillment.line_item.quantity_type | ||
json.performed_by fulfillment.performer.full_name if fulfillment.performer | ||
json.components fulfillment_components_dropdown(fulfillment.components) | ||
json.options fulfillment_options_buttons(fulfillment) | ||
json.options fulfillment_options_buttons(fulfillment) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
-- MySQL dump 10.13 Distrib 5.7.12, for osx10.11 (x86_64) | ||
-- | ||
-- Host: localhost Database: klok_development | ||
-- ------------------------------------------------------ | ||
-- Server version 5.7.12 | ||
|
||
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */; | ||
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */; | ||
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */; | ||
/*!40101 SET NAMES utf8 */; | ||
/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */; | ||
/*!40103 SET TIME_ZONE='+00:00' */; | ||
/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */; | ||
/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */; | ||
/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */; | ||
/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */; | ||
|
||
-- | ||
-- Table structure for table `entries` | ||
-- | ||
|
||
DROP TABLE IF EXISTS `entries`; | ||
/*!40101 SET @saved_cs_client = @@character_set_client */; | ||
/*!40101 SET character_set_client = utf8 */; | ||
CREATE TABLE `entries` ( | ||
`created_at` timestamp NULL DEFAULT NULL, | ||
`project_id` int(11) NOT NULL, | ||
`resource_id` int(11) DEFAULT NULL, | ||
`rate` int(11) DEFAULT NULL, | ||
`date` date DEFAULT NULL, | ||
`start_time_stamp_formatted` varchar(255) DEFAULT NULL, | ||
`start_time_stamp` timestamp NULL DEFAULT NULL, | ||
`entry_id` int(11) NOT NULL, | ||
`duration` int(11) DEFAULT NULL, | ||
`submission_id` int(11) DEFAULT NULL, | ||
`device_id` int(11) DEFAULT NULL, | ||
`comments` text, | ||
`end_time_stamp_formatted` varchar(255) DEFAULT NULL, | ||
`end_time_stamp` timestamp NULL DEFAULT NULL, | ||
`rollup_to` int(11) DEFAULT NULL, | ||
PRIMARY KEY (`entry_id`) | ||
) ENGINE=InnoDB DEFAULT CHARSET=utf8; | ||
/*!40101 SET character_set_client = @saved_cs_client */; | ||
|
||
-- | ||
-- Table structure for table `people` | ||
-- | ||
|
||
DROP TABLE IF EXISTS `people`; | ||
/*!40101 SET @saved_cs_client = @@character_set_client */; | ||
/*!40101 SET character_set_client = utf8 */; | ||
CREATE TABLE `people` ( | ||
`resource_id` int(11) NOT NULL, | ||
`name` varchar(255) DEFAULT NULL, | ||
`username` varchar(255) DEFAULT NULL, | ||
`created_at` timestamp NULL DEFAULT NULL, | ||
PRIMARY KEY (`resource_id`) | ||
) ENGINE=InnoDB DEFAULT CHARSET=utf8; | ||
/*!40101 SET character_set_client = @saved_cs_client */; | ||
|
||
-- | ||
-- Table structure for table `projects` | ||
-- | ||
|
||
DROP TABLE IF EXISTS `projects`; | ||
/*!40101 SET @saved_cs_client = @@character_set_client */; | ||
/*!40101 SET character_set_client = utf8 */; | ||
CREATE TABLE `projects` ( | ||
`contact_email` varchar(255) DEFAULT NULL, | ||
`project_id` int(11) NOT NULL, | ||
`path` int(11) DEFAULT NULL, | ||
`code` varchar(255) DEFAULT NULL, | ||
`contact_phone` varchar(255) DEFAULT NULL, | ||
`updated_at` timestamp NULL DEFAULT NULL, | ||
`project_type` varchar(255) DEFAULT NULL, | ||
`name` varchar(255) DEFAULT NULL, | ||
`parent_id` int(11) DEFAULT NULL, | ||
`created_at` timestamp NULL DEFAULT NULL, | ||
`contact_name` varchar(255) DEFAULT NULL, | ||
`rollup_to` int(11) DEFAULT NULL, | ||
PRIMARY KEY (`project_id`) | ||
) ENGINE=InnoDB DEFAULT CHARSET=utf8; | ||
/*!40101 SET character_set_client = @saved_cs_client */; | ||
|
||
-- | ||
-- Table structure for table `schema_migrations` | ||
-- | ||
|
||
DROP TABLE IF EXISTS `schema_migrations`; | ||
/*!40101 SET @saved_cs_client = @@character_set_client */; | ||
/*!40101 SET character_set_client = utf8 */; | ||
CREATE TABLE `schema_migrations` ( | ||
`version` varchar(255) NOT NULL, | ||
UNIQUE KEY `unique_schema_migrations` (`version`) | ||
) ENGINE=InnoDB DEFAULT CHARSET=utf8; | ||
/*!40101 SET character_set_client = @saved_cs_client */; | ||
/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */; | ||
|
||
/*!40101 SET SQL_MODE=@OLD_SQL_MODE */; | ||
/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */; | ||
/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */; | ||
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */; | ||
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */; | ||
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; | ||
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */; | ||
|
||
-- Dump completed on 2016-07-11 17:43:07 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
class AddKlokEntryIdToLineItems < ActiveRecord::Migration | ||
def change | ||
add_column :fulfillments, :klok_entry_id, :integer | ||
add_index :fulfillments, :klok_entry_id | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.