Skip to content

Commit

Permalink
Only copy ModelItem indices within datamodel and referencedatamodel p…
Browse files Browse the repository at this point in the history
…lugins
  • Loading branch information
joe-crawford committed Mar 6, 2022
1 parent 7be034f commit f9d35be
Show file tree
Hide file tree
Showing 7 changed files with 174 additions and 81 deletions.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -956,6 +956,7 @@ class DataModelServiceIntegrationSpec extends BaseDataModelIntegrationSpec {
EnumerationType copiedEnumerationType = copiedDataElement.dataType

then:
copiedEnumerationType.domainType == 'EnumerationType'
copiedEnumerationType.enumerationValues.every {ev ->
ev.key.startsWith('Key') && ev.key.endsWith((ev.idx + 1).toString()) &&
ev.value.startsWith('Value') && ev.value.endsWith((ev.idx + 1).toString())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -494,7 +494,7 @@ class DataClassFunctionalSpec extends OrderedResourceFunctionalSpec<DataClass> {
responseBody().items.any { it.label == 'string' }
}

void 'CC06: test copying a dataclass with ordered dataclasses, dataelements and enumerationvalues'() {
void 'CC06 : test copying a dataclass with ordered dataclasses, dataelements and enumerationvalues'() {
given:
POST('', validJson)
verifyResponse CREATED, response
Expand Down Expand Up @@ -527,7 +527,7 @@ class DataClassFunctionalSpec extends OrderedResourceFunctionalSpec<DataClass> {
}

when:
GET("$id/dataClasses")
GET("$id/dataClasses?sort=idx")

then:
verifyResponse OK, response
Expand Down Expand Up @@ -566,7 +566,7 @@ class DataClassFunctionalSpec extends OrderedResourceFunctionalSpec<DataClass> {
String copyId = responseBody().id

when:
GET("${getResourcePath(otherDataModelId)}/$copyId/dataClasses", MAP_ARG, true)
GET("${getResourcePath(otherDataModelId)}/$copyId/dataClasses?sort=idx", MAP_ARG, true)

then:
verifyResponse OK, response
Expand Down Expand Up @@ -606,6 +606,55 @@ class DataClassFunctionalSpec extends OrderedResourceFunctionalSpec<DataClass> {
verifyResponse NO_CONTENT, response
}

void 'CC07 : test copying a dataclass without index order'() {
given:
POST('', validJson)
verifyResponse CREATED, response
String id = responseBody().id

for (int i in 1..5) {
POST("$id/dataClasses", [label: 'Child Data Class ' + i, idx: i])
verifyResponse CREATED, response
}

when:
GET("$id/dataClasses?sort=idx")

then:
verifyResponse OK, response
responseBody().items.size() == 5
responseBody().items.eachWithIndex {dc, i ->
assert dc.domainType == 'DataClass'
assert dc.label.startsWith('Child Data Class') && dc.label.endsWith((i + 1).toString())
}

when:
String originalId = responseBody().items[0].id
POST("$id/dataClasses/$dataModelId/$originalId", [copyLabel: 'Child Copied Class'])

then:
verifyResponse CREATED, response
responseBody().label == 'Child Copied Class'

when:
GET("$id/dataClasses?sort=idx")

then:
verifyResponse OK, response
responseBody().items.size() == 6
responseBody().items.take(5).eachWithIndex {dc, i ->
assert dc.domainType == 'DataClass'
assert dc.label.startsWith('Child Data Class') && dc.label.endsWith((i + 1).toString())
}

and:
responseBody().items[5].domainType == 'DataClass'
responseBody().items[5].label == 'Child Copied Class'

cleanup:
cleanUpData()
}

@Rollback
void 'test searching for metadata "mdk1" in content dataclass'() {
given:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import uk.ac.ox.softeng.maurodatamapper.core.bootstrap.StandardEmailAddress
import uk.ac.ox.softeng.maurodatamapper.core.facet.Metadata
import uk.ac.ox.softeng.maurodatamapper.core.facet.SemanticLink
import uk.ac.ox.softeng.maurodatamapper.core.facet.SemanticLinkType
import uk.ac.ox.softeng.maurodatamapper.core.rest.transport.model.CopyInformation
import uk.ac.ox.softeng.maurodatamapper.datamodel.DataModel
import uk.ac.ox.softeng.maurodatamapper.datamodel.DataModelService
import uk.ac.ox.softeng.maurodatamapper.datamodel.DataModelType
Expand Down Expand Up @@ -575,12 +576,50 @@ class DataClassServiceIntegrationSpec extends BaseDataModelIntegrationSpec {
EnumerationType copiedEnumerationType = copiedDataElement.dataType

then:
copiedEnumerationType.domainType == 'EnumerationType'
copiedEnumerationType.enumerationValues.every {ev ->
ev.key.startsWith('Key') && ev.key.endsWith((ev.idx + 1).toString()) &&
ev.value.startsWith('Value') && ev.value.endsWith((ev.idx + 1).toString())
}
}

void 'test copying dataclass without index order'() {
given:
setupData()
setupDataModelWithMultipleDataClassesAndDataElementsAndEnumerationValues()

when:
DataClass parentClass = dataModel.childDataClasses.find {it.label == 'Root Data Class'}

then:
parentClass.dataClasses.size() == 5
parentClass.dataClasses.every {dc ->
dc.label.startsWith('Child Data Class') && dc.label.endsWith((dc.idx + 1).toString())
}

when:
DataClass original = parentClass.dataClasses.sort().first()
dataClassService.copyDataClass(dataModel, original, editor, userSecurityPolicyManager, parentClass, false, new CopyInformation(copyLabel: 'Child Copied Class'))

then:
original.idx == 0
checkAndSave(dataModel)

when:
DataClass copied = parentClass.dataClasses.find {it.label == 'Child Copied Class'}
List<DataClass> dataClasses = parentClass.dataClasses.sort()

then:
copied.label == 'Child Copied Class'
copied.idx != original.idx
copied.idx == 5
dataClasses.size() == 6
dataClasses.take(5).every {dc ->
dc.label.startsWith('Child Data Class') && dc.label.endsWith((dc.idx + 1).toString())
}
dataClasses.last() == copied
}

void 'LIST01 : test getting all DataClasses inside a DataClass with importing involved'() {
// This addresses the issue gh-226 where we were getting the correct data for DC with no imported DEs and a DC with only imported DEs but incorrect
// when a DCs DEs were imported into other DEs. The join was causing non-distinct results.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ import uk.ac.ox.softeng.maurodatamapper.core.model.ModelService
import uk.ac.ox.softeng.maurodatamapper.core.provider.dataloader.DataLoaderProviderService
import uk.ac.ox.softeng.maurodatamapper.core.provider.importer.ModelImporterProviderService
import uk.ac.ox.softeng.maurodatamapper.core.provider.importer.parameter.ModelImporterProviderServiceParameters
import uk.ac.ox.softeng.maurodatamapper.core.rest.transport.model.CopyInformation
import uk.ac.ox.softeng.maurodatamapper.path.Path
import uk.ac.ox.softeng.maurodatamapper.path.PathNode
import uk.ac.ox.softeng.maurodatamapper.security.User
Expand Down Expand Up @@ -247,10 +246,9 @@ class CodeSetService extends ModelService<CodeSet> {

copy.trackChanges()

CopyInformation copyTermsInformation = new CopyInformation(copyIndex: true)
List<Term> terms = termService.findAllByCodeSetId(original.id)
terms.sort().each {term ->
termService.copyTerm(copy, term, copier, userSecurityPolicyManager, copyTermsInformation)
terms.each {term ->
copy.addToTerms(term)
}
log.debug('Copy of codeset took {}', Utils.timeTaken(start))
copy
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ class TerminologyService extends ModelService<Terminology> {
List<TermRelationshipType> termRelationshipTypes = TermRelationshipType.byTerminologyId(original.id).join('classifiers').list()
List<Term> originalTerms = Term.byTerminologyId(original.id).join('classifiers').list()
List<TermRelationship> termRelationships = []
CopyInformation termsCachedInformation = new CopyInformation(copyIndex: true)
CopyInformation termsCachedInformation = new CopyInformation()

if (originalTerms) {
List<UUID> originalTermIds = originalTerms.collect { it.id }
Expand All @@ -369,19 +369,19 @@ class TerminologyService extends ModelService<Terminology> {
}

// Copy all the TermRelationshipType
termRelationshipTypes.sort().each { trt ->
termRelationshipTypes.each { trt ->
termRelationshipTypeService.copyTermRelationshipType(copy, trt, copier)
}

// Copy all the terms
originalTerms.sort().each { term ->
originalTerms.each { term ->
termService.copyTerm(copy, term, copier, userSecurityPolicyManager, termsCachedInformation)
}

// Copy all the term relationships
// We need all the terms to exist so we can create the links
// Only copy source relationships as this will propagate the target relationships
termRelationships.sort().each { relationship ->
termRelationships.each { relationship ->
termRelationshipService.copyTermRelationship(copy, relationship, new TreeMap(copy.terms.collectEntries {[it.code, it]}), copier)
}
log.debug('Copy of terminology took {}', Utils.timeTaken(start))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -236,12 +236,19 @@ class TermService extends ModelItemService<Term> {
copy
}

Term copyTerm(CodeSet copiedCodeSet, Term original, User copier, UserSecurityPolicyManager userSecurityPolicyManager,
CopyInformation copyInformation = null) {
Term copy = copyTerm(original, copier, userSecurityPolicyManager, copyInformation)
copiedCodeSet.addToTerms(copy)
copy
}

Term copyTerm(Term original, User copier, UserSecurityPolicyManager userSecurityPolicyManager, CopyInformation copyInformation = null) {
if (!original) throw new ApiInternalException('DCSXX', 'Cannot copy non-existent Term')
Term copy = new Term(createdBy: copier.emailAddress, code: original.code, definition: original.definition, url: original.url,
isParent: original.isParent,
depth: original.depth)
copy = copyModelItemInformation(original, copy, copier, userSecurityPolicyManager, copyInformation)
copy = copyCatalogueItemInformation(original, copy, copier, userSecurityPolicyManager, copyInformation)
setCatalogueItemRefinesCatalogueItem(copy, original, copier)
copy
}
Expand Down

0 comments on commit f9d35be

Please sign in to comment.