Skip to content

Commit

Permalink
Merge pull request #69 from KPMP/develop
Browse files Browse the repository at this point in the history
Release for v2.0
  • Loading branch information
rlreamy authored Oct 25, 2018
2 parents 0f1ae7a + 9d6204d commit b531f54
Show file tree
Hide file tree
Showing 94 changed files with 2,582 additions and 2,670 deletions.
23 changes: 20 additions & 3 deletions .classpath
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,42 @@
<classpathentry kind="src" output="bin/main" path="src/main/java">
<attributes>
<attribute name="gradle_scope" value="main"/>
<attribute name="gradle_used_by_scope" value="main,test"/>
<attribute name="gradle_used_by_scope" value="main,test,integrationTest"/>
<attribute name="FROM_GRADLE_MODEL" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" output="bin/main" path="src/main/resources">
<attributes>
<attribute name="gradle_scope" value="main"/>
<attribute name="gradle_used_by_scope" value="main,test"/>
<attribute name="gradle_used_by_scope" value="main,test,integrationTest"/>
<attribute name="FROM_GRADLE_MODEL" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" output="bin/test" path="src/test/java">
<attributes>
<attribute name="gradle_scope" value="test"/>
<attribute name="gradle_used_by_scope" value="test"/>
<attribute name="gradle_used_by_scope" value="test,integrationTest"/>
<attribute name="FROM_GRADLE_MODEL" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" output="bin/integrationTest" path="src/integration-test/java">
<attributes>
<attribute name="gradle_scope" value="integrationTest"/>
<attribute name="gradle_used_by_scope" value="integrationTest"/>
<attribute name="FROM_GRADLE_MODEL" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8/"/>
<classpathentry kind="con" path="org.eclipse.buildship.core.gradleclasspathcontainer"/>
<classpathentry kind="lib" path="/Users/rlreamy/.gradle/caches/modules-2/files-2.1/org.springframework.boot/spring-boot/2.0.1.RELEASE/b8c5b14cbb0e52fdded8f98a8c1493cc74c7cf59/spring-boot-2.0.1.RELEASE.jar" sourcepath="/Users/rlreamy/.gradle/caches/modules-2/files-2.1/org.springframework.boot/spring-boot/2.0.1.RELEASE/6256c81ff81377b54b95e89817b93ba408513918/spring-boot-2.0.1.RELEASE-sources.jar">
<attributes>
<attribute name="gradle_used_by_scope" value="integrationTest,main,test"/>
</attributes>
</classpathentry>
<classpathentry kind="lib" path="/Users/rlreamy/.gradle/caches/modules-2/files-2.1/org.springframework.boot/spring-boot-autoconfigure/2.0.1.RELEASE/b0bf9d34ed70c6987a86cd58a009065e5fa02545/spring-boot-autoconfigure-2.0.1.RELEASE.jar" sourcepath="/Users/rlreamy/.gradle/caches/modules-2/files-2.1/org.springframework.boot/spring-boot-autoconfigure/2.0.1.RELEASE/e4f10fbe21036deaf8a127b5cff982cbde0be845/spring-boot-autoconfigure-2.0.1.RELEASE-sources.jar">
<attributes>
<attribute name="gradle_used_by_scope" value="integrationTest,main,test"/>
</attributes>
</classpathentry>
<classpathentry kind="output" path="bin/default"/>
</classpath>
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,5 @@
.mvn
build
/bin/
.embedmongo
.oracle_jre_usage
17 changes: 17 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
language: java

jdk:
- oraclejdk8

install: true

script:
- ./gradlew build

notifications:
email:
- [email protected]
- [email protected]
- [email protected]
- [email protected]
- [email protected]
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
# orion-data

[![Build Status](https://travis-ci.org/KPMP/orion-data.svg?branch=develop)](https://travis-ci.org/KPMP/orion-data)

Repo for the KPMP upload tool back-end


80 changes: 70 additions & 10 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,45 @@ buildscript {
}
}

plugins {
id "org.asciidoctor.convert" version "1.5.3"
}

apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'idea'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'

jar {
dependsOn asciidoctor
from ("${asciidoctor.outputDir}/html5") {
into 'static/docs'
}
baseName='orion-data'
version= '1.0'
version= '2.0'
}

repositories {
mavenCentral()
}

sourceSets {
integrationTest {
java {
compileClasspath += main.output + test.output
runtimeClasspath += main.output + test.output
srcDir file('src/integration-test/java')
}
resources.srcDir file('src/integration-test/resources')
}
}

configurations {
integrationTestCompile.extendsFrom testCompile
integrationTestRuntime.extendsFrom testRuntime
}

processResources {
filesMatching('application.properties') {
expand(project.properties)
Expand All @@ -32,16 +56,52 @@ sourceCompatibility = 1.8
targetCompatibility = 1.8

dependencies {
compile("org.springframework.boot:spring-boot-starter-web")
compile('commons-io:commons-io:2.6')
testCompile("junit:junit")
compile 'org.springframework.boot:spring-boot-starter-data-jpa'
asciidoctor 'org.springframework.restdocs:spring-restdocs-asciidoctor:2.0.1.RELEASE'
compile 'org.springframework.restdocs:spring-restdocs-mockmvc:2.0.1.RELEASE'
compile 'org.springframework.boot:spring-boot-starter-web'
compile 'commons-io:commons-io:2.6'
compile 'org.mockito:mockito-core'
compile 'org.junit.jupiter:junit-jupiter-engine:5.2.0'
compile 'mysql:mysql-connector-java:6.0.5'
compile 'org.hibernate:hibernate-core:5.2.16.Final'
testCompile('org.springframework.boot:spring-boot-starter-test')
testCompile('org.springframework:spring-test:5.0.5.RELEASE')
compile 'org.springframework.boot:spring-boot-starter-test'
compile 'org.springframework:spring-test:5.0.5.RELEASE'
compile 'org.springframework.data:spring-data-mongodb:2.0.8.RELEASE'
compile 'org.springframework.boot:spring-boot-starter-data-mongodb'
testCompile 'de.flapdoodle.embed:de.flapdoodle.embed.mongo:2.1.1'
testCompile 'cz.jirutka.spring:embedmongo-spring:1.3.1'
compile 'org.apache.commons:commons-compress:1.17'
}

ext {
snippetsDir = file('build/generated-snippets')
}

bootRun {
systemProperty 'spring.profiles.active', System.properties['spring.profiles.active']
test {
outputs.dir snippetsDir
}

tasks.withType(Test) {
testLogging {
exceptionFormat "full"
events "skipped", "passed", "failed"
showStandardStreams false
}
}

asciidoctor {
inputs.dir snippetsDir
dependsOn test
}

task integrationTest(type: Test) {
testClassesDirs = sourceSets.integrationTest.output.classesDirs
classpath = sourceSets.integrationTest.runtimeClasspath
outputs.upToDateWhen { false }
}

check.dependsOn integrationTest
integrationTest.mustRunAfter test

springBoot {
mainClassName = "org.kpmp.Application"
}
15 changes: 7 additions & 8 deletions migrations/v1/040_addOtherPackageTypes.sql
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
ALTER TABLE case_demographics RENAME TO upload_package;
CREATE TABLE `upload_package_to_package_type_other` (
`upload_package_id` INT UNSIGNED NOT NULL,
`package_type_other_id` INT UNSIGNED NOT NULL,
Expand All @@ -13,24 +12,24 @@ CREATE TABLE `package_type_other` (
)
ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

ALTER TABLE `upload_package_to_package_type_other`
ALTER TABLE case_demographics RENAME TO upload_package;

ALTER TABLE `upload_package_to_package_type_other`
ADD INDEX `upload_package_to_ptother_package_type_other_foreign_idx` (`package_type_other_id` ASC);
ALTER TABLE `upload_package_to_package_type_other`
ALTER TABLE `upload_package_to_package_type_other`
ADD CONSTRAINT `upload_package_to_ptother_package_type_other_id_foreign`
FOREIGN KEY (`package_type_other_id`)
REFERENCES `package_type_other` (`id`);

ALTER TABLE `upload_package_to_package_type_other`
ALTER TABLE `upload_package_to_package_type_other`
ADD CONSTRAINT `upload_package_to_ptother_upload_package_id_foreign`
FOREIGN KEY (`upload_package_id`)
REFERENCES `upload_package` (`id`);


ALTER TABLE `file_submissions`
DROP FOREIGN KEY `file_submissions_case_id_foreign`;
ALTER TABLE `file_submissions`
ALTER TABLE `file_submissions`
CHANGE COLUMN `case_id` `upload_package_id` INT(10) UNSIGNED NOT NULL ;
ALTER TABLE `file_submissions`
ALTER TABLE `file_submissions`
ADD CONSTRAINT `file_submissions_case_id_foreign`
FOREIGN KEY (`upload_package_id`)
REFERENCES `upload_package` (`id`);
5 changes: 5 additions & 0 deletions migrations/v2/010_addUUIDs.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
ALTER TABLE `orion`.`file_submissions`
ADD COLUMN `uuid` VARCHAR(50) NOT NULL AFTER `updated_at`;

ALTER TABLE `orion`.`upload_package`
ADD COLUMN `uuid` VARCHAR(50) NOT NULL AFTER `updated_at`;
48 changes: 48 additions & 0 deletions scripts/2.0/000_Directions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#!/usr/bin/python

print ""
print ""
print "These scripts are to do the migration of data from v1.75 to v2.0"
print "We are migrating from MySql to Mongo, and also changing the directory names where the data are stored."
print ""
print "Directions:"
print ""
print "With a clean dataLake database in mongo"
print ""
print "1) Generate a file containing the unique set of users from the metadata files on disk"
print " cd ~/apps/orion-data/scripts/2.0"
print " ./010_migrateUsers.py"
print ""
print "2) Load users into mongo"
print " cd ~/orionstack"
print " docker cp /data/combinedUserData.json mongodb:."
print " docker exec -it mongodb bash"
print " mongoimport --db dataLake --collection users --file combinedUserData.json"
print ""
print "3) Export user info from mongo so we can get the ids for the users"
print " Inside mongodb container: mongoexport --db dataLake --collection users > exportedUsers.json"
print " exit the container"
print " docker cp mongodb:/exportedUsers.json /data/."
print ""
print "4) Generate the package metadata"
print " cd ~/apps/orion-data/scripts/2.0"
print " ./020_migratePackageMetadata.py"
print ""
print "5) Load package metadata into mongo"
print " cd ~/orionstack"
print " docker cp /data/combinedcombinedMetadata.json mongodb:."
print " docker exec -it mongodb bash"
print " mongoimport --db dataLake --collection packages --file combinedMetadata.json"
print ""
print "6) Migrate directories"
print " cd ~/apps/orion-data/scripts/2.0"
print " ./030_migrateDirectories.py"
print ""
print "7) Regenerate zip files"
print " cd ~/orionstack"
print " docker exec -it spring bash"
print " ./gradlew build"
print " java -cp build/libs/orion-data.jar -Dloader.main=org.kpmp.RegenerateZipFiles org.springframework.boot.loader.PropertiesLauncher"
print ""


26 changes: 26 additions & 0 deletions scripts/2.0/010_migrateUsers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/usr/bin/python

import json
import os

rootdir = "/data"
output = open ("/data/combinedUserData.json", "w+")

userNames = []
for subdir, dirs, files in os.walk(rootdir):
for potentialFile in files:
if potentialFile == 'metadata.json':
with open(os.path.join(subdir, potentialFile), "r") as f:
data = json.load(f)
user = {};
submitterName = data["submitterFirstName"] + data["submitterLastName"]
if submitterName in userNames:
continue
else:
user["firstName"] = data["submitterFirstName"]
user["lastName"] = data["submitterLastName"]
user["displayName"] = ""
user["email"] = ""
userNames.append(submitterName)
output.write(json.dumps(user) + "\n")

58 changes: 58 additions & 0 deletions scripts/2.0/020_migratePackageMetadata.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
#!/usr/bin/python

from collections import OrderedDict
import json
import os

rootdir = "/data"
output = open ("/data/combinedMetadata.json", "w+")
outputPretty = open ("/data/combinedMetadata.pretty.json", "w+")
userInput = open("/data/exportedUsers.json")
userDataStr = "[" + ",".join([line.strip() for line in userInput.readlines()]) + "]"
userData = dict([(user["lastName"], user["_id"]) for user in json.loads(userDataStr)])
for subdir, dirs, files in os.walk(rootdir):
for potentialFile in files:
if potentialFile == 'metadata.json':
with open(os.path.join(subdir, potentialFile), "r") as f:
data = json.load(f)
metadata = {}
metadata["_id"] = data["id"]
createdAt = data["createdAt"]
createdAt = createdAt.replace(" UTC", ".000Z")
createdAt = createdAt.replace(" ", "T")
metadata["createdAt"] = {"$date" : createdAt}
metadata["packageType"] = data["packageType"]
metadata["institution"] = data["institution"]
metadata["protocol"] = data["protocol"]
metadata["subjectId"] = data["subjectId"]
experimentDate = data["experimentDate"]

if experimentDate is not None:
experimentDate = experimentDate + ".000Z"
experimentDate = experimentDate.replace(" ", "T")
metadata["experimentDate"] = {"$date" : experimentDate}
else:
metadata["experimentDate"] = None
attachments = []
descriptions = []
for item in data["files"]:
attachment = {}
attachment["_id"]= item["universalId"]
attachment["fileName"] = item["fileName"]
attachment["size"] = item["size"]
descriptions.append(item["description"])
attachments.append(attachment)

if len(set(descriptions)) == 1:
metadata["description"] = descriptions[0]
else:
metadata["description"] = "|".join(descriptions)

metadata["files"] = attachments
submitter = OrderedDict()
submitter["$ref"] = "users"
submitter["$id"] = userData[data["submitterLastName"]]
metadata["submitter"] = submitter

output.write(json.dumps(metadata) + "\n")
outputPretty.write(json.dumps(metadata, indent=2) + "\n")
21 changes: 21 additions & 0 deletions scripts/2.0/030_migrateDirectories.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/usr/bin/python

import os
import json
import shutil

rootdir = "/data"

for subdir, dirs, files in os.walk(rootdir):
for potentialFile in files:
if potentialFile == 'metadata.json':
with open(os.path.join(subdir, potentialFile), "r") as f:
data = json.load(f)
universalId = data["id"]
newDirectoryName = os.path.join(rootdir,"package_" + universalId)
shutil.copytree(subdir, newDirectoryName)

currentMetadataFile = os.path.join(subdir, 'metadata.json')
newMetadataFileName = os.path.join(subdir, 'metadata.json.deprecated')
shutil.move(currentMetadataFile, newMetadataFileName)
os.remove(os.path.join(newDirectoryName, 'metadata.json'))
Loading

0 comments on commit b531f54

Please sign in to comment.