Skip to content

Commit

Permalink
Merge pull request #916 from MetadataConsulting/import-refactor
Browse files Browse the repository at this point in the history
Adding in a relationship for the latestVersionId in the "adding relat…
  • Loading branch information
davidmilward authored Jan 23, 2017
2 parents f8eb6f8 + 5b99f06 commit 75d4c96
Showing 1 changed file with 21 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import grails.gorm.DetachedCriteria
import groovy.transform.CompileDynamic
import groovy.util.logging.Log4j
import org.modelcatalogue.core.*
import org.modelcatalogue.core.util.HibernateHelper
import org.modelcatalogue.core.api.ElementStatus
import org.modelcatalogue.core.publishing.DraftContext
import org.modelcatalogue.core.publishing.PublishingContext
Expand Down Expand Up @@ -602,8 +603,28 @@ class CatalogueElementProxyRepository {
relationship.destination.latestVersionId = relationship.source.latestVersionId
FriendlyErrors.failFriendlySave(relationship.destination)
}


if(HibernateHelper.getEntityClass(relationship.source) == DataModel){

// for each element which does the source data model declare
for (CatalogueElement element in (relationship.source as DataModel).declares) {
if(!element.latestVersionId){
element.latestVersionId = element.id
FriendlyErrors.failFriendlySave(element)
}

CatalogueElement other = CatalogueElement.findByNameAndDataModel(element.name, relationship.destination)
if (other && !other.latestVersionId) {
other.latestVersionId = element.latestVersionId
FriendlyErrors.failFriendlySave(other)
}
}
}
}



createdRelationships[hash] = relationship

return relationship
Expand Down

0 comments on commit 75d4c96

Please sign in to comment.