Skip to content

Commit

Permalink
Merge pull request #10 from rovnanik-sk/add/special-entity-names-fix
Browse files Browse the repository at this point in the history
Add/special entity names fix
  • Loading branch information
mrovnanik authored Feb 2, 2025
2 parents f499930 + 23a3645 commit 45255fd
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 84 deletions.
2 changes: 1 addition & 1 deletion docker/build-scripts/gs-generate-pg-dump.bat
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ REM run DUMP script
type DumpDatabase.sql | docker exec -i dev-postgres su postgres

REM kill 'em
docker-compose -p pg-dump -f create-database.yml down --rmi local -v
docker compose -p pg-dump -f create-database.yml down --rmi local -v

REM return back to original dir
popd
Expand Down
5 changes: 3 additions & 2 deletions docker/build-scripts/gs-generate-pg-dump.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#! /bin/bash
#!/bin/bash

docker network create ars-int

Expand All @@ -12,7 +12,8 @@ docker compose -p pg-dump -f create-database.yml build --no-cache
docker compose -p pg-dump -f create-database.yml up -d

# store IP of host in order to use it for db import later on
ip4=$(/sbin/ip -o -4 addr list eth0 | awk '{print $4}' | cut -d/ -f1)
ip4=$(/sbin/ip -o -4 addr list | awk '!/ lo / {print $4; exit}' | cut -d/ -f1)
echo "Connecting to PG_LOAD_SERVER: $ip4"

# 2. run application component (inside separate component as well) - this is the component that is being built
# this will actually initialize the database, without running the component
Expand Down
2 changes: 1 addition & 1 deletion framework/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ test {
systemProperty 'moqui.runtime', '../runtime'
systemProperty 'moqui.conf', 'conf/MoquiDevConf.xml'
systemProperty 'moqui.init.static', 'true'
systemProperty 'moqui.log.directory', projectDir.absolutePath + '/../runtime/' + logDir
systemProperty 'moqui.log.directory', projectDir.absolutePath + '/runtime/' + logDir

classpath += files(sourceSets.main.output.classesDirs); classpath += files(projectDir.absolutePath)
// filter out classpath entries that don't exist (gradle adds a bunch of these), or ElasticSearch JarHell will blow up
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -469,10 +469,13 @@ class EntityDbMeta {

boolean tableExists(EntityDefinition ed) {
def performDbCheck = ed.isMultipleInstanceEntity
Boolean exists = entityTablesExist.get(ed.getFullEntityName())
// if table exists in `entityTableExist`
if (exists && performDbCheck) return true

// check in database for special entities
if (performDbCheck) return tableExistsInternal(ed)

Boolean exists = entityTablesExist.get(ed.getFullEntityName())
if (exists != null) return exists.booleanValue()

return tableExistsInternal(ed)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -856,12 +856,18 @@ class EntityFacadeImpl implements EntityFacade {
this.setDynamicRelationships(entityNode, entitySuffix)
}

// support for handling entities with set `table_name`
// support for handling entities with set `table-name`
// if `table-name` is not set, use {internal entity name} + {suffix}
def tableNameSet = entityNode.attribute("table-name")
if (tableNameSet){
tableNameSet = "${tableNameSet}_${EntityJavaUtil.camelCaseToUnderscored(entitySuffix)}".toString()
entityNode.attributes.replace("table-name", tableNameSet)
tableNameSet = "${tableNameSet}_${entitySuffix.toLowerCase()}".toString()
} else {
def internalEntityName = entityNode.attribute("entity-name")
tableNameSet = "${EntityJavaUtil.camelCaseToUnderscored(internalEntityName)}_${entitySuffix.toLowerCase()}".toString()
}
// set table-name
entityNode.attributes.replace("table-name", tableNameSet)

// log
logger.debug("Loading special entity ${specialEntityName}.")
}
Expand Down
76 changes: 0 additions & 76 deletions framework/src/main/resources/log4j2.xml

This file was deleted.

14 changes: 14 additions & 0 deletions framework/src/test/groovy/UtilsTests.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import org.moqui.impl.ViUtilities
import org.moqui.impl.context.ExecutionContextFactoryImpl
import org.moqui.impl.entity.EntityConditionFactoryImpl
import org.moqui.impl.entity.EntityDefinition
import org.moqui.impl.entity.EntityJavaUtil
import org.moqui.impl.entity.condition.ConditionField
import org.moqui.util.CollectionUtilities
import org.moqui.util.MNode
Expand Down Expand Up @@ -47,6 +48,19 @@ class UtilsTests extends Specification {
1 == 1
}

def test_camelCase_conversion() {
when:

// IT IS NOT FEASIBLE TO TRANSFORM `camelCaseToUnderscored` method to cover specifically
// cases of ClosureItem tables, this functionality has been moved aside
// def str1 = EntityJavaUtil.camelCaseToUnderscored('cl_i_out_entsoe_report_01__CZ12345678')
def str2 = EntityJavaUtil.camelCaseToUnderscored('entsoe_report_01_C_12345678')

then:
// str1 == 'CL_I_OUT_ENTSOE_REPORT_01__CZ12345678'
str2 == 'ENTSOE_REPORT_01__C_12345678'
}

def test_comma_splitting() {
when:

Expand Down

0 comments on commit 45255fd

Please sign in to comment.