diff --git a/generators/angular/templates/src/main/webapp/app/entities/_entityFolder_/_entityFile_.model.ts.ejs b/generators/angular/templates/src/main/webapp/app/entities/_entityFolder_/_entityFile_.model.ts.ejs index 31d3c97f7c7..fbe1d65565b 100644 --- a/generators/angular/templates/src/main/webapp/app/entities/_entityFolder_/_entityFile_.model.ts.ejs +++ b/generators/angular/templates/src/main/webapp/app/entities/_entityFolder_/_entityFile_.model.ts.ejs @@ -22,7 +22,7 @@ const enumImports = this.generateEntityClientEnumImports(fields); <%_ if (anyFieldIsDateDerived) { _%> import dayjs from 'dayjs/esm'; <%_ } _%> -<%_ for (const relationshipsByType of Object.values(differentRelationships).filter(relationshipsByType => relationshipsByType.some(relationship => (relationship.ownerSide || relationship.relationshipManyToMany) && relationship.otherEntity.entityAngularName !== entityAngularName))) { +<%_ for (const relationshipsByType of Object.values(differentRelationships).filter(relationshipsByType => relationshipsByType.some(relationship => relationship.otherEntity.entityAngularName !== entityAngularName))) { const { otherEntity } = relationshipsByType[0]; _%> import { I<%- otherEntity.entityAngularName %> } from 'app/entities/<%= otherEntity.entityClientRootFolder %><%= otherEntity.entityFolderName %>/<%= otherEntity.entityFileName %>.model'; @@ -41,10 +41,10 @@ _%> <%= fieldName %>ContentType<% if (!id /* && !fieldValidationRequired */) { %>?<% } %>: string<% if (!id /* && !fieldValidationRequired */) { %> | null<% } %>, <%_ } _%> <%_ } _%> -<%_ for (const relationship of relationships.filter(relationship => relationship.ownerSide || relationship.relationshipManyToMany)) { - const { propertyName, relationshipRequired, otherEntity, id, collection, otherEntityField } = relationship; +<%_ for (const relationship of relationships) { + const { propertyName, relationshipRequired, otherEntity, collection, otherEntityField } = relationship; _%> - <%= propertyName %>?: Pick, '<%= otherEntity.primaryKey.name %>'<% if (otherEntity.primaryKey.name !== otherEntityField) { %> | '<%= otherEntityField %>'<% } %>><% if (collection) { %>[]<% } %> | null; + <%= propertyName %>?: <% if (!otherEntity.embedded && (dtoMapstruct || otherEntity.builtInUser)) { %>Pick<<% } %>I<%= otherEntity.entityAngularName %><% if (!otherEntity.embedded && (dtoMapstruct || otherEntity.builtInUser)) { %>, '<%= otherEntity.primaryKey.name %>'<% if (otherEntity.primaryKey.name !== otherEntityField) { %> | '<%= otherEntityField %>'<% } %>><% } %><% if (collection) { %>[]<% } %> | null; <%_ } _%> } <%_ if (primaryKey) { _%> diff --git a/generators/angular/templates/src/main/webapp/app/entities/_entityFolder_/detail/_entityFile_-detail.component.html.ejs b/generators/angular/templates/src/main/webapp/app/entities/_entityFolder_/detail/_entityFile_-detail.component.html.ejs index f4004e34978..430957142b5 100644 --- a/generators/angular/templates/src/main/webapp/app/entities/_entityFolder_/detail/_entityFile_-detail.component.html.ejs +++ b/generators/angular/templates/src/main/webapp/app/entities/_entityFolder_/detail/_entityFile_-detail.component.html.ejs @@ -67,14 +67,14 @@ _%> <%_ } _%> <%_ for (const relationship of relationships.filter(rel => !rel.otherEntityIsEmbedded)) { - const ownerSide = relationship.ownerSide; + const { persistableRelationship } = relationship; const relationshipName = relationship.relationshipName; const relationshipFieldName = relationship.relationshipFieldName; const relationshipFieldNamePlural = relationship.relationshipFieldNamePlural; const relationshipNameHumanized = relationship.relationshipNameHumanized; const otherEntityStateName = relationship.otherEntityStateName; const otherEntityField = relationship.otherEntityField; - if (ownerSide) { + if (persistableRelationship) { _%>
Translate="<%= i18nKeyPrefix %>.<%= relationshipName %>">__jhiTransformTranslate__('<%- i18nKeyPrefix %>.<%- relationshipName %>')
diff --git a/generators/angular/templates/src/main/webapp/app/entities/_entityFolder_/list/_entityFile_.component.html.ejs b/generators/angular/templates/src/main/webapp/app/entities/_entityFolder_/list/_entityFile_.component.html.ejs index a55bcbe62fa..e7bb54132a4 100644 --- a/generators/angular/templates/src/main/webapp/app/entities/_entityFolder_/list/_entityFile_.component.html.ejs +++ b/generators/angular/templates/src/main/webapp/app/entities/_entityFolder_/list/_entityFile_.component.html.ejs @@ -88,9 +88,7 @@ <%_ } _%> <%_ for (const relationship of relationships.filter(rel => !rel.otherEntityIsEmbedded)) { _%> - <%_ if (relationship.relationshipManyToOne - || (relationship.relationshipOneToOne && relationship.ownerSide) - || (relationship.relationshipManyToMany && relationship.ownerSide && paginationNo)) { + <%_ if (relationship.persistableRelationship && (!relationship.collection || paginationNo)) { const fieldName = "." + relationship.otherEntityField; _%> SortBy="<%= relationship.relationshipName + (fieldName) %>"> @@ -143,15 +141,11 @@ _%> <%_ } _%> <%_ } _%> <%_ for (const relationship of relationships.filter(rel => !rel.otherEntityIsEmbedded)) { - const ownerSide = relationship.ownerSide; const relationshipFieldName = relationship.relationshipFieldName; const relationshipFieldNamePlural = relationship.relationshipFieldNamePlural; const otherEntityField = relationship.otherEntityField; _%> - <%_ if (relationship.relationshipManyToOne - || (relationship.relationshipOneToOne && ownerSide) - || (relationship.relationshipManyToMany && ownerSide && paginationNo)) { - _%> + <%_ if (relationship.persistableRelationship && (!relationship.collection || paginationNo)) { _%> <%_ if (relationship.otherEntityUser) { _%> <%_ if (relationship.collection) { _%> @@ -182,7 +176,7 @@ _%>
<%_ for (const relationship of relationships.filter(rel => !rel.otherEntityIsEmbedded)) { _%> - <%_ if (relationship.otherEntity.jpaMetamodelFiltering && relationship.otherEntity.paginationPagination && (relationship.relationshipOneToMany || relationship.relationshipManyToMany) && !relationship.ownerSide) { + <%_ if (relationship.otherEntity.jpaMetamodelFiltering && relationship.otherEntity.paginationPagination && relationship.collection && !relationship.persistableRelationship) { const otherEntityTranslationKey = i18nKeyPrefix + '.' + relationship.relationshipName; _%>
<%_ } _%> <%_ for (relationship of relationships) { - const ownerSide = relationship.ownerSide; const relationshipName = relationship.relationshipName; const relationshipFieldName = relationship.relationshipFieldName; const relationshipFieldNamePlural = relationship.relationshipFieldNamePlural; const relationshipNameHumanized = relationship.relationshipNameHumanized; const otherEntityPkName = relationship.otherEntity.primaryKey && relationship.otherEntity.primaryKey.name || 'id'; const otherEntityField = relationship.otherEntityField; _%> - <%_ if (ownerSide) { _%> + <%_ if (relationship.persistableRelationship) { _%>
<%= relationshipNameHumanized %> diff --git a/generators/react/templates/src/main/webapp/app/entities/_entityFolder_/_entityFile_-update.tsx.ejs b/generators/react/templates/src/main/webapp/app/entities/_entityFolder_/_entityFile_-update.tsx.ejs index 64edaa9a004..23efcf31818 100644 --- a/generators/react/templates/src/main/webapp/app/entities/_entityFolder_/_entityFile_-update.tsx.ejs +++ b/generators/react/templates/src/main/webapp/app/entities/_entityFolder_/_entityFile_-update.tsx.ejs @@ -50,16 +50,16 @@ let uniqueRelationFields = new Set(); Object.keys(differentRelationships).forEach(key => { - const hasAnyRelationshipQuery = differentRelationships[key].some(rel => - (rel.relationshipOneToOne && rel.ownerSide && !rel.otherEntityUser) - || !rel.relationshipOneToMany); + const hasAnyRelationshipQuery = differentRelationships[key].some(rel => rel.persistableRelationship); if (hasAnyRelationshipQuery) { hasRelationshipQuery = true; differentRelationships[key].forEach(rel => { - if (rel.relationshipManyToMany && rel.ownerSide) { - manyToManyOwners.add(rel); - } else { - relFieldNames.add(rel); + if (rel.persistableRelationship) { + if (rel.relationshipManyToMany) { + manyToManyOwners.add(rel); + } else { + relFieldNames.add(rel); + } } }); } @@ -169,7 +169,7 @@ _%> <%= rel.relationshipFieldNamePlural %>: mapIdList(values.<%= rel.relationshipFieldNamePlural %>), <%_ }) _%> <%_ relFieldNames.forEach(rel => { _%> -<%_ if (rel.relationshipManyToOne || (rel.ownerSide && rel.relationshipOneToOne)) { _%> +<%_ if (rel.persistableRelationship && !rel.collection) { _%> <%= rel.relationshipFieldName %>: <%= rel.otherEntityNamePlural %>.find(it => it.<%= rel.otherEntity.primaryKey.name %>.toString() === values.<%= rel.relationshipFieldName %>.toString()), <%_ } _%> <%_ }) _%> @@ -213,9 +213,9 @@ _%> const otherEntityPkName = rel.otherEntity.primaryKey && rel.otherEntity.primaryKey.name || 'id'; const relationshipFieldName = rel.relationshipFieldName; const relationshipFieldNamePlural = rel.relationshipFieldNamePlural; - if (rel.relationshipManyToOne || (rel.relationshipOneToOne && rel.ownerSide)) { _%> + if (rel.persistableRelationship && !rel.collection) { _%> <%= relationshipFieldName %>: <%= entityInstance %>Entity?.<%= relationshipFieldName %>?.<%= otherEntityPkName %>, - <%_ } else if (rel.relationshipManyToMany && rel.ownerSide) { _%> + <%_ } else if (rel.persistableRelationship) { _%> <%= relationshipFieldNamePlural %>: <%= entityInstance %>Entity?.<%= relationshipFieldNamePlural %>?.map(e => e.<%= otherEntityPkName %>.toString()), <%_ } _%> <%_ }) _%> @@ -321,7 +321,6 @@ _%> <%_ } _%> <%_ } _%> <%_ relationships.forEach(rel => { - const ownerSide = rel.ownerSide; const otherEntityPkName = rel.otherEntity.primaryKey && rel.otherEntity.primaryKey.name || 'id'; const otherEntityNamePlural = rel.otherEntityNamePlural; const relationshipName = rel.relationshipName; @@ -331,7 +330,7 @@ _%> const otherEntityField = rel.otherEntityField; const relationshipRequired = rel.relationshipRequired; const translationKey = `${i18nKeyPrefix}.${relationshipName}`; _%> - <%_ if (rel.relationshipManyToOne || (rel.relationshipOneToOne && ownerSide)) { _%> + <%_ if (rel.persistableRelationship && !rel.collection) { _%> <%_ if (relationshipRequired) { _%> This field is required. <%_ } _%> - <%_ } else if (rel.relationshipManyToMany && rel.ownerSide) { _%> + <%_ } else if (rel.persistableRelationship) { _%> label={translate('<%= i18nKeyPrefix %>.<%= relationshipName %>')} diff --git a/generators/react/templates/src/main/webapp/app/entities/_entityFolder_/_entityFile_.tsx.ejs b/generators/react/templates/src/main/webapp/app/entities/_entityFolder_/_entityFile_.tsx.ejs index 512b9988d6c..46cb9f3ec13 100644 --- a/generators/react/templates/src/main/webapp/app/entities/_entityFolder_/_entityFile_.tsx.ejs +++ b/generators/react/templates/src/main/webapp/app/entities/_entityFolder_/_entityFile_.tsx.ejs @@ -376,9 +376,7 @@ export const <%= entityReactName %> = () => { ')} ><%= field.fieldNameHumanized %> ')} /> <%_ } _%> <%_ for (relationship of relationships) { _%> - <%_ if (relationship.relationshipManyToOne - || (relationship.relationshipOneToOne && relationship.ownerSide) - || (relationship.relationshipManyToMany && relationship.ownerSide && paginationNo)) { _%> + <%_ if (relationship.persistableRelationship && (paginationNo || !relationship.collection)) { _%> <%= relationship.relationshipNameHumanized %> <%_ } _%> <%_ } _%> @@ -442,14 +440,11 @@ _%> <%_ } _%> <%_ for (relationship of relationships) { const otherEntity = relationship.otherEntity; - const ownerSide = relationship.ownerSide; const relationshipFieldName = relationship.relationshipFieldName; const relationshipFieldNamePlural = relationship.relationshipFieldNamePlural; const otherEntityPkName = relationship.otherEntity.primaryKey && relationship.otherEntity.primaryKey.name || 'id'; const otherEntityField = relationship.otherEntityField; _%> - <%_ if (relationship.relationshipManyToOne - || (relationship.relationshipOneToOne && ownerSide) - || (relationship.relationshipManyToMany && ownerSide && paginationNo)) { _%> + <%_ if (relationship.persistableRelationship && (paginationNo || !relationship.collection)) { _%> <%_ if (relationship.otherEntityUser) { _%> <%_ if (relationship.relationshipManyToMany) { _%> diff --git a/generators/server/support/prepare-entity.mjs b/generators/server/support/prepare-entity.mjs index 6af56fb24ce..b07cdec31d0 100644 --- a/generators/server/support/prepare-entity.mjs +++ b/generators/server/support/prepare-entity.mjs @@ -91,7 +91,10 @@ export function preparePostEntityServerDerivedProperties(entity) { .filter(relationship => relationship.ignoreOtherSideProperty === undefined) .forEach(relationship => { relationship.ignoreOtherSideProperty = - !relationship.embedded && !!relationship.otherEntity && relationship.otherEntity.relationships.length > 0; + entity.databaseType !== 'neo4j' && + !relationship.embedded && + !!relationship.otherEntity && + relationship.otherEntity.relationships.length > 0; }); entity.relationshipsContainOtherSideIgnore = entity.relationships.some(relationship => relationship.ignoreOtherSideProperty); diff --git a/generators/spring-data-neo4j/generator.mts b/generators/spring-data-neo4j/generator.mts index ff338f4d1b5..94861ce01b4 100644 --- a/generators/spring-data-neo4j/generator.mts +++ b/generators/spring-data-neo4j/generator.mts @@ -18,7 +18,7 @@ */ import BaseApplicationGenerator from '../base-application/index.mjs'; -import { GENERATOR_BOOTSTRAP_APPLICATION, GENERATOR_LIQUIBASE, GENERATOR_SPRING_DATA_NEO4J } from '../generator-list.mjs'; +import { GENERATOR_BOOTSTRAP_APPLICATION, GENERATOR_JAVA, GENERATOR_LIQUIBASE, GENERATOR_SPRING_DATA_NEO4J } from '../generator-list.mjs'; import writeTask from './files.mjs'; import cleanupTask from './cleanup.mjs'; import writeEntitiesTask, { cleanupEntitiesTask } from './entity-files.mjs'; @@ -31,6 +31,8 @@ export default class Neo4jGenerator extends BaseApplicationGenerator { if (!this.delegateToBlueprint) { await this.dependsOnJHipster(GENERATOR_BOOTSTRAP_APPLICATION); + const javaGenerator: any = await this.dependsOnJHipster(GENERATOR_JAVA); + javaGenerator.useJacksonIdentityInfo = true; } } @@ -65,6 +67,56 @@ export default class Neo4jGenerator extends BaseApplicationGenerator { return this.delegateTasksToBlueprint(() => this.preparing); } + get configuringEachEntity() { + return this.asConfiguringEachEntityTaskGroup({ + async configuringEachEntity({ entityConfig }) { + if (entityConfig.dto && entityConfig.dto !== 'no') { + this.log.warn( + `The DTO option is not supported for Neo4j database. Neo4j persists the entire constelation, DTO causes the constelation to be incomplete. DTO is found in entity ${entityConfig.name}.`, + ); + } + }, + }); + } + + get [BaseApplicationGenerator.CONFIGURING_EACH_ENTITY]() { + return this.delegateTasksToBlueprint(() => this.configuringEachEntity); + } + + get preparingEachEntity() { + return this.asPreparingEachEntityTaskGroup({ + prepareEntity({ entity }) { + entity.relationships.forEach(relationship => { + if (relationship.persistableRelationship === undefined) { + relationship.persistableRelationship = true; + } + }); + }, + }); + } + + get [BaseApplicationGenerator.PREPARING_EACH_ENTITY]() { + return this.delegateTasksToBlueprint(() => this.preparingEachEntity); + } + + get default() { + return this.asDefaultTaskGroup({ + async checkUserRelationship({ entities }) { + entities.forEach(entity => { + if (entity.relationships.some(relationship => relationship.otherEntity.builtInUser)) { + this.log.warn( + `Relationship with User entity should be avoided for Neo4j database. Neo4j persists the entire constelation, related User entity will be updated causing security problems. Relationship with User entity is found in entity ${entity.name}.`, + ); + } + }); + }, + }); + } + + get [BaseApplicationGenerator.DEFAULT]() { + return this.delegateTasksToBlueprint(() => this.default); + } + get writing() { return this.asWritingTaskGroup({ cleanupTask, diff --git a/generators/spring-data-neo4j/templates/src/main/java/_package_/_entityPackage_/domain/_persistClass_.java.jhi.spring_data_neo4j.ejs b/generators/spring-data-neo4j/templates/src/main/java/_package_/_entityPackage_/domain/_persistClass_.java.jhi.spring_data_neo4j.ejs index 52cda8ab03c..ec1307956fc 100644 --- a/generators/spring-data-neo4j/templates/src/main/java/_package_/_entityPackage_/domain/_persistClass_.java.jhi.spring_data_neo4j.ejs +++ b/generators/spring-data-neo4j/templates/src/main/java/_package_/_entityPackage_/domain/_persistClass_.java.jhi.spring_data_neo4j.ejs @@ -57,7 +57,7 @@ import org.springframework.data.neo4j.core.schema.Relationship; <%_ if (relationship.relationshipLeftSide) { _%> @Relationship(value = "HAS_<%= this._.toUpper(this._.snakeCase(relationship.relationshipName)) %>", direction = Relationship.Direction.OUTGOING) <%_ } else { _%> - @Relationship(value = "IS_<%= this._.toUpper(this._.snakeCase(relationship.relationshipName)) %>_<%= this._.toUpper(this._.snakeCase(relationship.otherRelationship.relationshipName)) %>", direction = Relationship.Direction.INCOMING) + @Relationship(value = "HAS_<%= this._.toUpper(this._.snakeCase(relationship.otherRelationship.relationshipName)) %>", direction = Relationship.Direction.INCOMING) <%_ } _%> <&_ } -&> <%_ } -%> diff --git a/generators/vue/templates/src/main/webapp/app/entities/_entityFolder_/_entityFile_-details.vue.ejs b/generators/vue/templates/src/main/webapp/app/entities/_entityFolder_/_entityFile_-details.vue.ejs index 8e4f28f6439..6bcdd166a7f 100644 --- a/generators/vue/templates/src/main/webapp/app/entities/_entityFolder_/_entityFile_-details.vue.ejs +++ b/generators/vue/templates/src/main/webapp/app/entities/_entityFolder_/_entityFile_-details.vue.ejs @@ -35,7 +35,6 @@ <%_ } _%> <%_ for (relationship of relationships) { - const ownerSide = relationship.ownerSide; const relationshipName = relationship.relationshipName; const relationshipFieldName = relationship.relationshipFieldName; const relationshipFieldNamePlural = relationship.relationshipFieldNamePlural; @@ -43,7 +42,7 @@ const otherEntityName = relationship.otherEntityName; const otherEntityField = relationship.otherEntityField; const otherEntityAngularName = relationship.otherEntityAngularName; _%> - <%_ if (ownerSide) { _%> + <%_ if (relationship.persistableRelationship) { _%>
<%= relationshipNameHumanized %>
diff --git a/generators/vue/templates/src/main/webapp/app/entities/_entityFolder_/_entityFile_-update.component.spec.ts.ejs b/generators/vue/templates/src/main/webapp/app/entities/_entityFolder_/_entityFile_-update.component.spec.ts.ejs index 2b882c101be..dc5c9aab878 100644 --- a/generators/vue/templates/src/main/webapp/app/entities/_entityFolder_/_entityFile_-update.component.spec.ts.ejs +++ b/generators/vue/templates/src/main/webapp/app/entities/_entityFolder_/_entityFile_-update.component.spec.ts.ejs @@ -34,7 +34,7 @@ import AlertService from '@/shared/alert/alert.service'; <%_ const allRelationshipsThatNeedSelectOptions = Object .values(relationshipsByOtherEntity) - .map(relationships => relationships.filter(rel => rel.ownerSide)) + .map(relationships => relationships.filter(rel => rel.persistableRelationship)) .filter(relationships => relationships.length > 0); _%> <%_ for (const [relationship] of Object.values(allRelationshipsThatNeedSelectOptions)) { _%> diff --git a/generators/vue/templates/src/main/webapp/app/entities/_entityFolder_/_entityFile_-update.component.ts.ejs b/generators/vue/templates/src/main/webapp/app/entities/_entityFolder_/_entityFile_-update.component.ts.ejs index 5e1406bc30d..dd9118950eb 100644 --- a/generators/vue/templates/src/main/webapp/app/entities/_entityFolder_/_entityFile_-update.component.ts.ejs +++ b/generators/vue/templates/src/main/webapp/app/entities/_entityFolder_/_entityFile_-update.component.ts.ejs @@ -14,9 +14,9 @@ import { useAlertService } from '@/shared/alert/alert.service'; <%_ const allRelationshipsThatNeedSelectOptions = Object .values(relationshipsByOtherEntity) - .map(relationships => relationships.filter(rel => rel.ownerSide)) + .map(relationships => relationships.filter(rel => rel.persistableRelationship)) .filter(relationships => relationships.length > 0); - const relationshipsContainManyToOne = relationships.some(rel => !rel.otherEntityIsEmbedded && rel.collection && rel.ownerSide); + const relationshipsContainManyToOne = relationships.some(rel => !rel.otherEntityIsEmbedded && rel.collection && rel.persistableRelationship); _%> <%_ for (const [relationship] of Object.values(allRelationshipsThatNeedSelectOptions)) { _%> @@ -176,7 +176,7 @@ _%> <%_ if (relationshipsContainManyToOne) { _%> <%_ for (relationship of relationships) { - if (relationship.relationshipType === 'many-to-many' && relationship.ownerSide === true) { + if (relationship.collection && relationship.persistableRelationship) { const relationshipFieldNamePlural = relationship.relationshipFieldNamePlural; _%> this.<%= entityInstance %>.<%= relationshipFieldNamePlural %> = []; diff --git a/generators/vue/templates/src/main/webapp/app/entities/_entityFolder_/_entityFile_-update.vue.ejs b/generators/vue/templates/src/main/webapp/app/entities/_entityFolder_/_entityFile_-update.vue.ejs index b34cdeb5768..2e9f06d7823 100644 --- a/generators/vue/templates/src/main/webapp/app/entities/_entityFolder_/_entityFile_-update.vue.ejs +++ b/generators/vue/templates/src/main/webapp/app/entities/_entityFolder_/_entityFile_-update.vue.ejs @@ -121,7 +121,6 @@ _%> <%_ } _%> <%_ for (relationship of relationships) { - const ownerSide = relationship.ownerSide; const otherEntityName = relationship.otherEntityName; const otherEntityNamePlural = relationship.otherEntityNamePlural; const relationshipName = relationship.relationshipName; @@ -131,7 +130,7 @@ _%> const otherEntityField = relationship.otherEntityField; const relationshipRequired = relationship.relationshipRequired; const translationKey = `${i18nKeyPrefix}.${relationshipName}`; _%> - <%_ if (relationship.relationshipManyToOne || (relationship.relationshipOneToOne && ownerSide && relationship.otherEntityUser)) { _%> + <%_ if (!relationship.collection && relationship.persistableRelationship) { _%>
- <%_ } else if (relationship.relationshipOneToOne && ownerSide) { _%> -
- - -
- <%_ } else if (relationship.relationshipManyToMany && ownerSide) { _%> + <%_ } else if (relationship.persistableRelationship) { _%>