Skip to content

Commit

Permalink
Merge pull request #1371 from MetadataConsulting/test/2.3.2.5-MET-2481
Browse files Browse the repository at this point in the history
Test/2.3.2.5 met 2481
  • Loading branch information
davidmilward authored Aug 23, 2018
2 parents 7629698 + 2cbcac9 commit 159af16
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 43 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package org.modelcatalogue.core

import org.modelcatalogue.core.persistence.DataClassGormService

import static org.modelcatalogue.core.util.HibernateHelper.getEntityClass
import com.google.common.base.Function
import com.google.common.collect.ImmutableSet
Expand Down Expand Up @@ -32,8 +34,6 @@ abstract class CatalogueElement implements Extendible<ExtensionValue>, Publishe

transient dataModelAclService

transient topLevelDataClassService

DataModel dataModel
Boolean topLevel = false

Expand Down Expand Up @@ -451,19 +451,12 @@ abstract class CatalogueElement implements Extendible<ExtensionValue>, Publishe
if ( !(this instanceof User) ) {
auditService.logElementCreated(this)
}

if (this instanceof DataClass) {
// mark top level
topLevelDataClassService.markTopLevel((DataClass) this) // This won't work as it reloads the dataClass as a new object...
// this.topLevel = true
// DataClass.withNewSession {
// final Long dataClassId = this.id
// topLevelDataClassService.markTopLevel(dataClassId)
// }
}
}

void beforeInsert() {
if (this instanceof DataClass) {
this.topLevel = true
}
removeModelCatalogueIdIfDefault()
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.modelcatalogue.core

import org.modelcatalogue.core.persistence.DataClassGormService
import org.modelcatalogue.core.util.*

/*
Expand Down Expand Up @@ -32,7 +33,7 @@ class Relationship implements Extendible<RelationshipMetadata>, org.modelcatalog
def auditService
def relationshipService

transient topLevelDataClassService
transient dataClassGormService

CatalogueElement source
CatalogueElement destination
Expand All @@ -56,8 +57,9 @@ class Relationship implements Extendible<RelationshipMetadata>, org.modelcatalog
Relationship.withNewSession {
if (relationshipType.id == RelationshipType.getHierarchyType().id) {
if (!destination) {throw new Exception("afterInsert of ${id}:No destination in hierarchy relationship ${id}")}
topLevelDataClassService.unmarkTopLevel((DataClass) destination)

if (destination instanceof DataClass) {
dataClassGormService.updateTopLevel(((DataClass) destination).id, false)
}
}
}
}
Expand All @@ -69,7 +71,9 @@ class Relationship implements Extendible<RelationshipMetadata>, org.modelcatalog
Relationship.withNewSession {
if (relationshipType.id == RelationshipType.getHierarchyType().id) {
if (!destination) {throw new Exception("beforeDelete of ${id}: No destination in hierarchy relationship ${id}; may have been deleted in the process of deleting relationship")}
topLevelDataClassService.markTopLevel((DataClass) destination)
if (destination instanceof DataClass) {
dataClassGormService.updateTopLevel(((DataClass) destination).id, true)
}

}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,27 +23,6 @@ class TopLevelDataClassService {
DataClassGormService dataClassGormService
DataClassService dataClassService

/**
* Marks a DataClass as Top-Level
* @param dataClass
* @return
*/
@Transactional
def markTopLevel(DataClass dataClass) {
dataClass.topLevel = true
}

/**
* Unmarks a DataClass as Top-Level
* @param dataClass
* @return
*/
@Transactional
def unmarkTopLevel(DataClass dataClass) {
dataClass.topLevel = false
}


/**
* Retrieve all Top-Level DataClasses of a DataModel by their extension value, recalculating with the old query if there are none.
* @param dataModel
Expand Down Expand Up @@ -205,9 +184,10 @@ class TopLevelDataClassService {
def calculateAndMarkTopLevelDataClassesForDataModel(DataModel dataModel) {
DataModelFilter dataModelFilter = DataModelFilter.create(ImmutableSet.<DataModel> of(dataModel), ImmutableSet.<DataModel> of())
ListWithTotalAndType<DataClass> topLevelDataClasses = dataClassService.getTopLevelDataClasses(dataModelFilter, [:])
for (DataClass dataClass : topLevelDataClasses.items) {
markTopLevel(dataClass)
}

List<Long> ids = topLevelDataClasses.items*.id as List<Long>
dataClassGormService.updateTopLevel(ids, true)

log.info "Calculated and marked top-level DataClasses for ${dataModel.toString()}"
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,19 @@ class DataClassGormService implements WarnGormErrors {

MessageSource messageSource

@Transactional
Number updateTopLevel(List<Long> ids, boolean topLevel) {
if (!ids) {
return 0
}
DataClass.where { id in ids }.updateAll(topLevel: topLevel)
}

@Transactional
Number updateTopLevel(Long dataClassId, boolean topLevel) {
updateTopLevel([dataClassId], topLevel)
}

@Transactional(readOnly = true)
DataClass findById(long id) {
DataClass.get(id)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -205,14 +205,15 @@ class ConfigExcelLoader extends ExcelLoader {
Iterator<Row> rowIt = sheet.rowIterator()
List<String> headers
List<Map<String, String>> rowMaps = []
int rowNum = 1
int rowNum = 1 // start counting from 1 rather than 0 (very un-computer-science-y)
while (rowIt.hasNext()) {
// println("processing row" + counter)
if(rowNum % EXCEL_BATCH_SIZE == 0 ) {
if(rowNum % EXCEL_BATCH_SIZE == 0 ) { // on every EXCEL_BATCH_SIZE (default 1000th) row, do processRowMaps.
processRowMaps(rowMaps, headersMap)
rowMaps.clear()
}
Row row = rowIt.next()
// now row is rowMaps[rowNum-1]. i.e. the first row is when rowNum = 1.
if (rowNum == headerRow) {
headers = getRowData(row)
log.info("Headers are ${headers as String}")
Expand Down Expand Up @@ -813,7 +814,7 @@ class ConfigExcelLoader extends ExcelLoader {
*/
def processRowMaps(List<Map<String, String>> rowMaps, Map<String, Object> headersMap, String dataModelName = this.dataModelName) {
int rowNum = 1
if (rowMaps && headersMap) {
if (rowMaps != null && headersMap) {
DataModel dataModel = processDataModel(dataModelName)

for (Map<String, String> rowMap in rowMaps) {
Expand Down

0 comments on commit 159af16

Please sign in to comment.