Skip to content

Commit

Permalink
Merge pull request #24350 from mshima/neo4j
Browse files Browse the repository at this point in the history
add persistableRelationship and adjust Neo4j
  • Loading branch information
DanielFran authored Nov 23, 2023
2 parents 2b99f9e + fee5942 commit 35b76f8
Show file tree
Hide file tree
Showing 27 changed files with 162 additions and 102 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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<I<%= otherEntity.entityAngularName %>, '<%= 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) { _%>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
_%>
<dt><span <%= jhiPrefix %>Translate="<%= i18nKeyPrefix %>.<%= relationshipName %>">__jhiTransformTranslate__('<%- i18nKeyPrefix %>.<%- relationshipName %>')</span></dt>
<dd>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,7 @@
</th>
<%_ } _%>
<%_ 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;
_%>
<th scope="col" <%= jhiPrefix %>SortBy="<%= relationship.relationshipName + (fieldName) %>">
Expand Down Expand Up @@ -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)) { _%>
<td>
<%_ if (relationship.otherEntityUser) { _%>
<%_ if (relationship.collection) { _%>
Expand Down Expand Up @@ -182,7 +176,7 @@ _%>
<td class="text-end">
<div class="btn-group">
<%_ 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;
_%>
<button type="submit"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ describe('<%= entityAngularName %> Form Service', () => {
<%_ for (const field of fields) { _%>
<%= field.fieldName %>: expect.any(Object),
<%_ } _%>
<%_ for (const relationship of relationships.filter(relationship => relationship.ownerSide || relationship.relationshipManyToMany)) { _%>
<%_ for (const relationship of relationships.filter(relationship => relationship.persistableRelationship)) { _%>
<%= relationship.propertyName %>: expect.any(Object),
<%_ } _%>
})
Expand All @@ -54,7 +54,7 @@ describe('<%= entityAngularName %> Form Service', () => {
<%_ for (const field of fields) { _%>
<%= field.fieldName %>: expect.any(Object),
<%_ } _%>
<%_ for (const relationship of relationships.filter(relationship => relationship.ownerSide || relationship.relationshipManyToMany)) { _%>
<%_ for (const relationship of relationships.filter(relationship => relationship.persistableRelationship)) { _%>
<%= relationship.propertyName %>: expect.any(Object),
<%_ } _%>
}));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,11 @@
<%_
const formDefaultProperties = [
...fields.filter(field => field.fieldTypeTimed || field.fieldTypeBoolean || field.id).map(field => field.fieldName),
...relationships.filter(relationship => relationship.collection && (relationship.relationshipManyToMany || relationship.ownerSide)).map(relationship => relationship.propertyName)
...relationships.filter(relationship => relationship.collection && relationship.persistableRelationship).map(relationship => relationship.propertyName)
];
const containDefaultProperties = formDefaultProperties.length > 0;
const entityFormName = anyFieldIsTimeDerived ? `${entityAngularName}FormRawValue` : `I${entityAngularName}`;
const newEntityFormName = anyFieldIsTimeDerived ? `New${entityAngularName}FormRawValue` : `New${entityAngularName}`;
const noPropertyEntity = fields.filter(field => !field.id).length === 0 && relationships.filter(relationship => relationship.ownerSide || relationship.relationshipManyToMany).length === 0;
_%>
import { Injectable } from '@angular/core';
import { FormGroup, FormControl, Validators } from '@angular/forms';
Expand Down Expand Up @@ -74,7 +73,7 @@ _%>
<%= fieldName %>ContentType: FormControl<<%= entityFormName %>['<%= fieldName %>ContentType']>;
<%_ } _%>
<%_ } _%>
<%_ for (const relationship of relationships.filter(relationship => relationship.ownerSide || relationship.relationshipManyToMany)) {
<%_ for (const relationship of relationships.filter(relationship => relationship.persistableRelationship)) {
const { propertyName, otherEntity } = relationship;
_%>
<%= propertyName %>: FormControl<<%= entityFormName %>['<%= propertyName %>']>;
Expand Down Expand Up @@ -146,7 +145,7 @@ _%>
<%= fieldName %>ContentType: new FormControl(<%= entityInstance %>RawValue.<%= fieldName %>ContentType),
<%_ } _%>
<%_ } _%>
<%_ for (const relationship of relationships.filter(relationship => relationship.ownerSide || relationship.relationshipManyToMany)) {
<%_ for (const relationship of relationships.filter(relationship => relationship.persistableRelationship)) {
const { relationshipRequired, propertyName, relationshipName, collection, otherEntity } = relationship;
_%>
<%= propertyName %>: new FormControl(
Expand All @@ -162,12 +161,6 @@ _%>
}

get<%= entityAngularName %>(form: <%= entityAngularName %>FormGroup): I<%= entityAngularName %> | New<%= entityAngularName %> {
<%_ if (noPropertyEntity) { _%>
if (form.controls.<%= primaryKey.name %>.disabled) {
// form.value returns <%= primaryKey.name %> with null value for FormGroup with only one FormControl
return { <%= primaryKey.name %>: null };
}
<%_ } _%>
<%_ if (anyFieldIsTimeDerived) { _%>
return this.convert<%= entityAngularName %>RawValueTo<%= entityAngularName %>(form.getRawValue() as <%= entityAngularName %>FormRawValue | New<%= entityAngularName %>FormRawValue);
<%_ } else { _%>
Expand Down Expand Up @@ -215,7 +208,7 @@ _%>
<%= fieldName %>: currentTime,
<%_ } _%>
<%_ } _%>
<%_ for (const relationship of relationships.filter(({ ownerSide, relationshipManyToMany }) => ownerSide || relationshipManyToMany)) {
<%_ for (const relationship of relationships.filter(({ persistableRelationship }) => persistableRelationship)) {
const { relationshipRequired, propertyName, collection, otherEntity, relationshipName } = relationship;
_%>
<%_ if (collection) { _%>
Expand Down Expand Up @@ -250,7 +243,7 @@ _%>
<%= fieldName %>: <%= entityInstance %>.<%= fieldName %> ? <%= entityInstance %>.<%= fieldName %>.format(DATE_TIME_FORMAT) : undefined,
<%_ } _%>
<%_ } _%>
<%_ for (const relationship of relationships.filter(({ ownerSide, relationshipManyToMany }) => ownerSide || relationshipManyToMany)) {
<%_ for (const relationship of relationships.filter(({ persistableRelationship }) => persistableRelationship)) {
const { relationshipRequired, propertyName, collection } = relationship;
_%>
<%_ if (collection) { _%>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,13 +162,13 @@ _%>
<% if (field.autoGenerate) { %>}<% } %>
<%_ } _%>
<%_ for (const relationship of relationships.filter(rel => rel.otherEntity.primaryKey)) {
const { otherEntity, ownerSide, relationshipName, propertyName, otherEntityField, relationshipRequired } = relationship;
const { otherEntity, relationshipName, propertyName, otherEntityField, relationshipRequired } = relationship;
const otherEntityName = relationship.otherEntityName;
const relationshipFieldName = relationship.relationshipFieldName;
const relationshipFieldNamePlural = relationship.relationshipFieldNamePlural;
const translationKey = `${i18nKeyPrefix}.${relationshipName}`;
_%>
<%_ if (relationship.relationshipManyToOne || (relationship.relationshipOneToOne && ownerSide)) { _%>
<%_ if (relationship.persistableRelationship && !relationship.collection) { _%>
<div class="mb-3">
<label class="form-label" <%= jhiPrefix %>Translate="<%= translationKey %>" for="field_<%= relationshipName %>">__jhiTransformTranslate__('<%- translationKey %>')</label>
Expand All @@ -189,7 +189,7 @@ _%>
}
</select>
</div>
<%_ } else if (relationship.relationshipManyToMany && ownerSide) { _%>
<%_ } else if (relationship.persistableRelationship) { _%>
<div class="mb-3">
<label <%= jhiPrefix %>Translate="<%= translationKey %>" for="field_<%= relationshipFieldNamePlural %>">__jhiTransformTranslate__('<%- translationKey %>')</label>
Expand All @@ -200,7 +200,7 @@ _%>
</select>
</div>
<%_ } _%>
<%_ if (relationship.relationshipValidate && (relationship.relationshipManyToOne || ownerSide)) { _%>
<%_ if (relationship.relationshipValidate && relationship.persistableRelationship) { _%>
@if (editForm.get([<%- this.buildAngularFormPath(relationship.reference) %>])!.invalid && (editForm.get([<%- this.buildAngularFormPath(relationship.reference) %>])!.dirty || editForm.get([<%- this.buildAngularFormPath(relationship.reference) %>])!.touched)) {
<div>
<%_ if (relationshipRequired) { _%>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
const tsKeyId = this.generateTestEntityId(primaryKey.type);
const allRelationshipsByEntityNeedingOptions = Object
.values(differentRelationships)
.map(relationships => relationships.filter(rel => rel.ownerSide))
.map(relationships => relationships.filter(rel => rel.persistableRelationship))
.filter(relationships => relationships.length > 0);
const testEntityPrimaryKey0 = this.generateTestEntityPrimaryKey(primaryKey, 0);
const testEntityPrimaryKey1 = this.generateTestEntityPrimaryKey(primaryKey, 1);
Expand Down Expand Up @@ -249,7 +249,7 @@ describe('<%= entityAngularName %> Management Update Component', () => {
});
});

<%_ const trackedRelationships = Object.values(differentRelationships).filter(arr => arr.some(rel => rel.ownerSide && rel.otherEntity.primaryKey));
<%_ const trackedRelationships = Object.values(differentRelationships).filter(arr => arr.some(rel => rel.persistableRelationship && rel.otherEntity.primaryKey));
if (trackedRelationships.length > 0) {
_%>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@
<%_
const allRelationshipsByEntityNeedingOptions = Object
.values(differentRelationships)
.map(relationships => relationships.filter(rel => rel.ownerSide))
.map(relationships => relationships.filter(rel => rel.persistableRelationship))
.filter(relationships => relationships.length > 0);
_%>
import { Component, OnInit<% if (anyFieldHasImageContentType) { %>, ElementRef<% } %> } from '@angular/core';
import { HttpResponse } from '@angular/common/http';
import { ActivatedRoute } from '@angular/router';
import { Observable } from 'rxjs';
import { finalize<% if (relationships.some(rel => rel.ownerSide === true)) { %>, map<% } %> } from 'rxjs/operators';
import { finalize<% if (relationships.some(rel => rel.persistableRelationship)) { %>, map<% } %> } from 'rxjs/operators';

import SharedModule from 'app/shared/shared.module';
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
Expand All @@ -41,7 +41,7 @@ import { DataUtils, FileLoadError } from 'app/core/util/data-util.service';
<%_ } _%>
<%_
Object.keys(differentRelationships).forEach(key => {
if (differentRelationships[key].some(rel => rel.reference.owned)) {
if (differentRelationships[key].some(rel => rel.persistableRelationship)) {
const uniqueRel = differentRelationships[key][0];
if (uniqueRel.otherEntityAngularName !== entityAngularName) {
if (uniqueRel.otherEntity.builtInUser) {
Expand Down Expand Up @@ -77,7 +77,7 @@ export class <%= entityAngularName %>UpdateComponent implements OnInit {
<%- this._.lowerFirst(importedType) %>Values = Object.keys(<%- importedType %>);
<%_ }); _%>

<%_ for (const relationshipsByEntityNeedingOptions of Object.values(differentRelationships).map(relationships => relationships.filter(rel => rel.ownerSide)).filter(relationships => relationships.length > 0)) { _%>
<%_ for (const relationshipsByEntityNeedingOptions of Object.values(differentRelationships).map(relationships => relationships.filter(rel => rel.persistableRelationship)).filter(relationships => relationships.length > 0)) { _%>
<%_ const relationshipsWithCustomUniqueOptions = relationshipsByEntityNeedingOptions.filter(rel => rel.relationshipOneToOne && rel.otherRelationship); _%>
<%_ if (relationshipsByEntityNeedingOptions.length > relationshipsWithCustomUniqueOptions.length) { _%>
<%_ const otherEntity = relationshipsByEntityNeedingOptions[0].otherEntity _%>
Expand All @@ -99,7 +99,7 @@ export class <%= entityAngularName %>UpdateComponent implements OnInit {
protected <%= entityInstance %>FormService: <%= entityAngularName %>FormService,
<%_
Object.keys(differentRelationships).forEach(key => {
if (differentRelationships[key].some(rel => rel.relationshipManyToOne || rel.relationshipOneToOne && rel.ownerSide || rel.relationshipManyToMany && rel.ownerSide)) {
if (differentRelationships[key].some(rel => rel.persistableRelationship)) {
const uniqueRel = differentRelationships[key][0];
if (uniqueRel.otherEntityAngularName !== entityAngularName) {
_%>
Expand All @@ -114,7 +114,7 @@ _%>
<%_ } _%>
protected activatedRoute: ActivatedRoute,
) {}
<%_ for (const relationshipsByEntity of Object.values(differentRelationships).filter(arr => arr.some(rel => rel.ownerSide && rel.otherEntity.primaryKey))) {
<%_ for (const relationshipsByEntity of Object.values(differentRelationships).filter(arr => arr.some(rel => rel.persistableRelationship && rel.otherEntity.primaryKey))) {
const { otherEntity } = relationshipsByEntity[0];
_%>

Expand All @@ -129,7 +129,7 @@ _%>
this.updateForm(<%= entityInstance %>);
}

<%_ if (relationships.filter(rel => rel.ownerSide && !rel.otherEntityIsEmbedded).length > 0) { _%>
<%_ if (relationships.filter(rel => rel.persistableRelationship && !rel.otherEntityIsEmbedded).length > 0) { _%>
this.loadRelationshipsOptions();
<%_ } _%>
});
Expand Down Expand Up @@ -202,7 +202,7 @@ _%>
protected updateForm(<%= entityInstance %>: I<%= entityAngularName %>): void {
this.<%= entityInstance %> = <%= entityInstance %>;
this.<%= entityInstance %>FormService.resetForm(this.editForm, <%= entityInstance %>);
<%_ if (relationships.filter(rel => rel.ownerSide).length > 0) { _%>
<%_ if (relationships.filter(rel => rel.persistableRelationship).length > 0) { _%>

<%_ for (const relationshipsByEntityNeedingOptions of allRelationshipsByEntityNeedingOptions) { _%>
<%_ const relationshipsWithCustomUniqueOptions = relationshipsByEntityNeedingOptions.filter(rel => rel.relationshipOneToOne && rel.otherRelationship); _%>
Expand All @@ -226,9 +226,9 @@ _%>
<%_ } _%>
}
<%_ if (relationships.filter(rel => rel.ownerSide && !rel.otherEntityIsEmbedded).length > 0) { _%>
<%_ if (relationships.filter(rel => rel.persistableRelationship && !rel.otherEntityIsEmbedded).length > 0) { _%>
protected loadRelationshipsOptions(): void {
<%_ for (const relationshipsByEntityNeedingOptions of Object.values(differentRelationships).map(relationships => relationships.filter(rel => rel.ownerSide)).filter(relationships => relationships.length > 0)) { _%>
<%_ for (const relationshipsByEntityNeedingOptions of Object.values(differentRelationships).map(relationships => relationships.filter(rel => rel.persistableRelationship)).filter(relationships => relationships.length > 0)) { _%>
<%_ const relationshipsWithCustomUniqueOptions = relationshipsByEntityNeedingOptions.filter(rel => rel.relationshipOneToOne && rel.otherRelationship); %>
<%_ const relationshipsWithCustomSharedOptions = relationshipsByEntityNeedingOptions.filter(rel => !relationshipsWithCustomUniqueOptions.includes(rel)); %>
<%_ const { otherEntity } = relationshipsByEntityNeedingOptions[0] _%>
Expand Down
1 change: 0 additions & 1 deletion generators/base-application/support/prepare-entity.mts
Original file line number Diff line number Diff line change
Expand Up @@ -573,7 +573,6 @@ function preparePostEntityCommonDerivedPropertiesNotTyped(entity: any) {
entity.anyPropertyHasValidation || relationships.some(({ relationshipValidate }) => relationshipValidate);

const relationshipsByOtherEntity = relationships
.filter(rel => !rel.otherEntity.embedded)
.map(relationship => [relationship.otherEntity.entityNameCapitalized, relationship])
.reduce((relationshipsByOtherEntity: any, [type, relationship]) => {
if (!relationshipsByOtherEntity[type]) {
Expand Down
Loading

0 comments on commit 35b76f8

Please sign in to comment.