Skip to content

Commit

Permalink
Merge pull request #88 from folio-org/ERM-209-1to1
Browse files Browse the repository at this point in the history
Erm 209
  • Loading branch information
doytch authored Jun 11, 2019
2 parents 9e08b06 + 7c4aa43 commit 66cdba1
Show file tree
Hide file tree
Showing 7 changed files with 81 additions and 45 deletions.
2 changes: 1 addition & 1 deletion service/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ dependencies {

// Changed this to enable inline development of the includes listed below.
def includes = [
'web-toolkit-ce' : 'com.k_int.grails:web-toolkit-ce:3.5.1',
'web-toolkit-ce' : 'com.k_int.grails:web-toolkit-ce:3.5.2',
'grails-okapi' : 'com.k_int.okapi:grails-okapi:3.6.2'
]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,33 +5,28 @@ import com.k_int.web.toolkit.refdata.RefdataValue
import com.k_int.web.toolkit.refdata.Defaults
import org.olf.general.FileUpload

class DocumentAttachment implements MultiTenant<DocumentAttachment> {
class DocumentAttachment extends SingleFileAttachment implements MultiTenant<DocumentAttachment> {

String id
String name
String location
String url
String note
Date dateCreated
Date lastUpdated
FileUpload fileUpload

// @Defaults(['License', 'Misc', 'Consortium Negotiation Document'])
@Defaults(['Consortium authorization statement', 'Product data sheet', 'Vendor terms and conditions'])

RefdataValue atType

static mapping = {
id column: 'da_id', generator: 'uuid2', length:36
version column: 'da_version'
id column: 'da_id'
name column: 'da_name'
location column: 'da_location'
url column: 'da_url'
note column: 'da_note', type:'text'
atType column: 'da_type_rdv_fk'
dateCreated column: 'da_date_created'
lastUpdated column: 'da_last_updated'
fileUpload column: 'da_file_upload'
}

static constraints = {
Expand All @@ -42,8 +37,6 @@ class DocumentAttachment implements MultiTenant<DocumentAttachment> {
atType(nullable:true, blank:false)
dateCreated(nullable:true, blank:false)
lastUpdated(nullable:true, blank:false)
fileUpload(nullable:true, blank:false)

}

}
8 changes: 5 additions & 3 deletions service/grails-app/domain/org/olf/general/FileUpload.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,22 @@ class FileUpload implements MultiTenant<FileUpload> {
String fileContentType
String fileName
Long fileSize

Date lastModified
SingleFileAttachment owner

static constraints = {
fileContentBytes nullable: true
fileContentType nullable: true
fileContentType nullable: true, blank: false
lastModified nullable: true
'owner' nullable: true
}

static mapping = {
id column: 'fu_id', generator: 'uuid2', length: 36
fileContentBytes column: 'fu_bytes', sqlType: 'longblob'
fileName column: 'fu_filename'
fileSize column: 'fu_filesize'
lastModified column: 'fu_last_mod'
lastModified column: 'fu_last_mod'
owner column: 'fu_owner', cascade: 'save-update'
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package org.olf.general

import grails.gorm.MultiTenant
import grails.gorm.multitenancy.Tenants

class SingleFileAttachment implements MultiTenant<SingleFileAttachment> {

// Add transient peroperty for flagging file removal. Transients are ignored by the persistence
// layer.

String id
FileUpload fileUpload
static hasOne = [fileUpload: FileUpload]
static mappedBy = [fileUpload: 'owner']

static mapping = {
tablePerHierarchy false
id generator: 'uuid2', length:36
fileUpload cascade: 'all'
}

static constraints = {
fileUpload nullable: true
}
}
75 changes: 45 additions & 30 deletions service/grails-app/migrations/add-file-upload.groovy
Original file line number Diff line number Diff line change
@@ -1,44 +1,59 @@
databaseChangeLog = {
changeSet(author: "Kurt Nordstrom", id: "2019-05-14-0001") {
addColumn(tableName: "document_attachment") {
column(name: "da_file_upload", type: "VARCHAR(36)")
}

}

changeSet(author: "Kurt Nordstrom", id: "2019-05-14-0002") {
createTable(tableName: "file_upload") {
column(name: "fu_id", type: "VARCHAR(36)") {
constraints(nullable: "false")
}
changeSet(author: "sosguthorpe (generated)", id: "1560252507752-1") {
createTable(tableName: "file_upload") {
column(name: "fu_id", type: "VARCHAR(36)") {
constraints(nullable: "false")
}

column(name: "version", type: "BIGINT") {
constraints(nullable: "false")
}
column(name: "version", type: "BIGINT") {
constraints(nullable: "false")
}

column(name: "fu_filesize", type: "BIGINT") {
constraints(nullable: "false")
}
column(name: "fu_filesize", type: "BIGINT") {
constraints(nullable: "false")
}

column(name: "fu_last_mod", type: "timestamp")
column(name: "fu_last_mod", type: "TIMESTAMP WITHOUT TIME ZONE")

column(name: "file_content_type", type: "VARCHAR(255)")
column(name: "file_content_type", type: "VARCHAR(255)")

column(name: "fu_filename", type: "VARCHAR(255)") {
constraints(nullable: "false")
}
column(name: "fu_owner", type: "VARCHAR(36)")

column(name: "fu_bytes", type: "bytea")
}
column(name: "fu_filename", type: "VARCHAR(255)") {
constraints(nullable: "false")
}

column(name: "fu_bytes", type: "BYTEA")
}
}

changeSet(author: "kurt (generated)", id: "2019-05-14-0004") {
addPrimaryKey(columnNames: "fu_id", constraintName: "file_uploadPK", tableName: "file_upload")

changeSet(author: "sosguthorpe (generated)", id: "1560252507752-2") {
createTable(tableName: "single_file_attachment") {
column(name: "id", type: "VARCHAR(36)") {
constraints(nullable: "false")
}

column(name: "version", type: "BIGINT") {
constraints(nullable: "false")
}
}
}

changeSet(author: "sosguthorpe (generated)", id: "1560252507752-3") {
addPrimaryKey(columnNames: "fu_id", constraintName: "file_uploadPK", tableName: "file_upload")
}

changeSet(author: "kurt (generated)", id: "2019-05-14-0005") {
addForeignKeyConstraint(baseColumnNames: "da_file_upload", baseTableName: "document_attachment", constraintName: "FKsn3g0f85naqw4heh0rlqgo8x8", deferrable: "false", initiallyDeferred: "false", referencedColumnNames: "fu_id", referencedTableName: "file_upload")
changeSet(author: "sosguthorpe (generated)", id: "1560252507752-4") {
addPrimaryKey(columnNames: "id", constraintName: "single_file_attachmentPK", tableName: "single_file_attachment")
}

}
changeSet(author: "sosguthorpe (generated)", id: "1560252507752-5") {
addForeignKeyConstraint(baseColumnNames: "fu_owner", baseTableName: "file_upload", constraintName: "FK2kjo91mrq9mt35oo8a94c0p5o", deferrable: "false", initiallyDeferred: "false", referencedColumnNames: "id", referencedTableName: "single_file_attachment")
}

changeSet(author: "sosguthorpe (generated)", id: "1560252507752-6") {
dropColumn(columnName: "da_version", tableName: "document_attachment")
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ databaseChangeLog = {
include file: 'add-lisense-dates.groovy'
include file: 'update-mod-license-1-1-0.groovy'
include file: 'docs.groovy'
include file: 'add-file-upload.groovy'
include file: 'update-mod-license-1-5-0.groovy'
include file: 'update-mod-license-1-6.groovy'
include file: 'update-mod-license-1-7.groovy'
include file: 'add-file-upload.groovy'
}
3 changes: 2 additions & 1 deletion service/src/main/okapi/tenant/sample_data/_data.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ import com.k_int.web.toolkit.custprops.CustomPropertyDefinition
import com.k_int.web.toolkit.refdata.RefdataCategory
import com.k_int.web.toolkit.refdata.RefdataValue

log.info 'Importing sample data'
if (existing_tenant) {
log.info 'Skippping exisiting tenant'
log.info 'Skipping exisiting tenant'
return
}

Expand Down

0 comments on commit 66cdba1

Please sign in to comment.