Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement composite id support at Java backend. #13864

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@
limitations under the License.
-%>
<%_
const tsKeyId = generateTestEntityId(user.primaryKey.type);
const tsKeyId = generateTestEntityId(user.primaryKey.trackByField.fieldType);
const testEntityPrimaryKey0 = generateTestEntityPrimaryKey(user.primaryKey, 0);
const testEntityPrimaryKey1 = generateTestEntityPrimaryKey(user.primaryKey, 1);
_%>
import { TestBed } from '@angular/core/testing';
import { HttpErrorResponse } from '@angular/common/http';
Expand Down Expand Up @@ -81,50 +83,50 @@ describe('Service Tests', () => {

describe('addUserToCollectionIfMissing', () => {
it('should add a User to an empty array', () => {
const user: IUser = <%- generateTestEntityPrimaryKey(user.primaryKey, 0) %>;
const user: IUser = <%- testEntityPrimaryKey0 %>;
expectedResult = service.addUserToCollectionIfMissing([], user);
expect(expectedResult).toHaveLength(1);
expect(expectedResult).toContain(user);
});

it('should not add a User to an array that contains it', () => {
const user: IUser = <%- generateTestEntityPrimaryKey(user.primaryKey, 0) %>;
const user: IUser = <%- testEntityPrimaryKey0 %>;
const userCollection: IUser[] = [
{
...user,
},
<%- generateTestEntityPrimaryKey(user.primaryKey, 1) %>,
<%- testEntityPrimaryKey1 %>,
];
expectedResult = service.addUserToCollectionIfMissing(userCollection, user);
expect(expectedResult).toHaveLength(2);
});

it("should add a User to an array that doesn't contain it", () => {
const user: IUser = <%- generateTestEntityPrimaryKey(user.primaryKey, 0) %>;
const userCollection: IUser[] = [<%- generateTestEntityPrimaryKey(user.primaryKey, 1) %>];
const user: IUser = <%- testEntityPrimaryKey0 %>;
const userCollection: IUser[] = [<%- testEntityPrimaryKey1 %>];
expectedResult = service.addUserToCollectionIfMissing(userCollection, user);
expect(expectedResult).toHaveLength(2);
expect(expectedResult).toContain(user);
});

it('should add only unique User to an array', () => {
const userArray: IUser[] = [<%- generateTestEntityPrimaryKey(user.primaryKey, 0) %>, <%- generateTestEntityPrimaryKey(user.primaryKey, 1) %>, <%- generateTestEntityPrimaryKey(user.primaryKey) %>];
const userCollection: IUser[] = [<%- generateTestEntityPrimaryKey(user.primaryKey, 1) %>];
const userArray: IUser[] = [<%- testEntityPrimaryKey0 %>, <%- testEntityPrimaryKey1 %>, <%- generateTestEntityPrimaryKey(user.primaryKey) %>];
const userCollection: IUser[] = [<%- testEntityPrimaryKey1 %>];
expectedResult = service.addUserToCollectionIfMissing(userCollection, ...userArray);
expect(expectedResult).toHaveLength(3);
});

it("should accept varargs", () => {
const user: IUser = <%- generateTestEntityPrimaryKey(user.primaryKey, 0) %>;
const user2: IUser = <%- generateTestEntityPrimaryKey(user.primaryKey, 1) %>;
const user: IUser = <%- testEntityPrimaryKey0 %>;
const user2: IUser = <%- testEntityPrimaryKey1 %>;
expectedResult = service.addUserToCollectionIfMissing([], user, user2);
expect(expectedResult).toHaveLength(2);
expect(expectedResult).toContain(user);
expect(expectedResult).toContain(user2);
});

it("should accept null and undefined values", () => {
const user: IUser = <%- generateTestEntityPrimaryKey(user.primaryKey, 0) %>;
const user: IUser = <%- testEntityPrimaryKey0 %>;
expectedResult = service.addUserToCollectionIfMissing([], null, user, undefined);
expect(expectedResult).toHaveLength(1);
expect(expectedResult).toContain(user);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@
<%_ }
} _%>
<%_ for (relationship of relationships) {
if (relationship.relationshipType === 'many-to-one' || (relationship.relationshipType === 'one-to-one' && relationship.ownerSide === true
&& (relationship.id == null || relationship.id === false))) {
relationship.otherEntity.idFields.forEach(idField => {
if ((relationship.relationshipType === 'many-to-one' || (relationship.relationshipType === 'one-to-one' && relationship.ownerSide === true))
&& !relationship.id) {
relationship.otherEntity.primaryKey.ownFields.forEach(idField => {
const uniqueConstraintName = relationship.relationshipType === 'one-to-one' ? getUXConstraintName(entity.entityTableName, relationship.columnName + '_' + idField.columnName, entity.prodDatabaseType) : null;
_%>
<column name="<%= relationship.columnName %>_<%= idField.columnName %>" type="<%= idField.columnType %>">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@
let baseColumnNames;
let referencedColumnNames;
if (relationshipType === 'one-to-one' && ownerSide && relationship.id === true) {
baseColumnNames = relationship.otherEntity.idFields.map(field => getColumnName(field.columnName)).join(',');
referencedColumnNames = relationship.otherEntity.idFields.map(field => getColumnName(field.columnName)).join(',');
baseColumnNames = relationship.otherEntity.primaryKey.ownFields.map(field => getColumnName(field.columnName)).join(',');
referencedColumnNames = relationship.otherEntity.primaryKey.ownFields.map(field => getColumnName(field.columnName)).join(',');
} else if (relationship.otherEntity) {
baseColumnNames = relationship.otherEntity.idFields.map(field => getColumnName(relationshipName + '_' + field.columnName)).join(',');
referencedColumnNames = relationship.otherEntity.idFields.map(field => getColumnName(field.columnName)).join(',');
baseColumnNames = relationship.otherEntity.primaryKey.ownFields.map(field => getColumnName(relationshipName + '_' + field.columnName)).join(',');
referencedColumnNames = relationship.otherEntity.primaryKey.ownFields.map(field => getColumnName(field.columnName)).join(',');
} %>
<addForeignKeyConstraint baseColumnNames="<%= baseColumnNames %>"
baseTableName="<%= entity.entityTableName %>"
Expand Down
2 changes: 1 addition & 1 deletion generators/entity-client/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ module.exports = class extends BaseBlueprintGenerator {
return {
setup() {
if (!this.embedded) {
this.tsKeyType = this.getTypescriptKeyType(this.primaryKey.type);
this.tsKeyType = this.getTypescriptKeyType(this.primaryKey.trackByField.fieldType);
}
},
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
See the License for the specific language governing permissions and
limitations under the License.
-%>
<form *ngIf="<%= entityInstance %>" name="deleteForm" (ngSubmit)="confirmDelete(<%= entityInstance %>.<%= primaryKey.name %>!)">
<form *ngIf="<%= entityInstance %>" name="deleteForm" (ngSubmit)="confirmDelete(<%= entityInstance %>.<%= primaryKey.trackByField.fieldName %>!)">
<div class="modal-header">
<h4 class="modal-title" data-cy="<%= entityInstance %>DeleteDialogHeading" <%= jhiPrefix %>Translate="entity.delete.title">Confirm delete operation</h4>

Expand All @@ -27,7 +27,7 @@
<div class="modal-body">
<<%= jhiPrefixDashed %>-alert-error></<%= jhiPrefixDashed %>-alert-error>

<p id="<%= jhiPrefixDashed %>-delete-<%= entityInstance %>-heading" <%= jhiPrefix %>Translate="<%= i18nKeyPrefix %>.delete.question" [translateValues]="{ id: <%= entityInstance %>.<%= primaryKey.name %> }">Are you sure you want to delete this <%= entityClassHumanized %>?</p>
<p id="<%= jhiPrefixDashed %>-delete-<%= entityInstance %>-heading" <%= jhiPrefix %>Translate="<%= i18nKeyPrefix %>.delete.question" [translateValues]="{ id: <%= entityInstance %>.<%= primaryKey.trackByField.fieldName %> }">Are you sure you want to delete this <%= entityClassHumanized %>?</p>
</div>

<div class="modal-footer">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
limitations under the License.
-%>
<%_
const tsKeyId = generateTestEntityId(primaryKey.type);
const tsKeyId = generateTestEntityId(primaryKey.trackByField.fieldType);
_%>
jest.mock('@ng-bootstrap/ng-bootstrap');

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
<<%= jhiPrefixDashed %>-alert></<%= jhiPrefixDashed %>-alert>

<dl class="row-md jh-entity-details">
<%_ for (const field of fields) {
<%_ for (const field of fields.filter(field => !field.hidden)) {
const fieldName = field.fieldName;
const fieldType = field.fieldType;
const fieldTypeBlobContent = field.fieldTypeBlobContent;
Expand Down Expand Up @@ -89,11 +89,11 @@
<%_ } else { _%>
<%_ if (relationshipType === 'many-to-many') { _%>
<span *ngFor="let <%= relationshipFieldName %> of <%= entityInstance %>.<%= relationshipFieldNamePlural %>; let last = last">
<a [routerLink]="['/<%= otherEntityStateName %>', <%= relationshipFieldName %>?.<%= relationship.otherEntity.primaryKey.name %>, 'view']">{{ <%= relationshipFieldName %>.<%= otherEntityField %> }}</a>{{ last ? '' : ', ' }}
<a [routerLink]="['/<%= otherEntityStateName %>', <%= relationshipFieldName %>?.<%= relationship.otherEntity.primaryKey.trackByField.fieldName %>, 'view']">{{ <%= relationshipFieldName %>.<%= otherEntityField %> }}</a>{{ last ? '' : ', ' }}
</span>
<%_ } else { _%>
<div *ngIf="<%= entityInstance + '.' + relationshipFieldName %>">
<a [routerLink]="['/<%= otherEntityStateName %>', <%= entityInstance + '.' + relationshipFieldName + '?.' + relationship.otherEntity.primaryKey.name %>, 'view']">{{ <%= entityInstance + "." + relationshipFieldName + "?." + otherEntityField %> }}</a>
<a [routerLink]="['/<%= otherEntityStateName %>', <%= entityInstance + '.' + relationshipFieldName + '?.' + relationship.otherEntity.primaryKey.trackByField.fieldName %>, 'view']">{{ <%= entityInstance + "." + relationshipFieldName + "?." + otherEntityField %> }}</a>
</div>
<%_ } _%>
<%_ } _%>
Expand All @@ -113,7 +113,7 @@
<%_ if (!readOnly) { _%>

<button type="button"
[routerLink]="['/<%= entityUrl %>', <%= entityInstance %>.<%= primaryKey.name %>, 'edit']"
[routerLink]="['/<%= entityUrl %>', <%= entityInstance %>.<%= primaryKey.trackByField.fieldName %>, 'edit']"
class="btn btn-primary">
<fa-icon icon="pencil-alt"></fa-icon>&nbsp;<span <%= jhiPrefix %>Translate="entity.action.edit">Edit</span>
</button>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@
limitations under the License.
-%>
<%_
const tsKeyId = generateTestEntityId(primaryKey.type);
const tsKeyId = generateTestEntityId(primaryKey.trackByField.fieldType);
const testEntity = generateTestEntityPrimaryKey(primaryKey, 0);
_%>
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { ActivatedRoute } from '@angular/router';
import { of } from 'rxjs';

import { <%= entityAngularName %> } from '../<%= entityFileName %>.model';
<%_ if (fieldsContainBlob) { _%>
import { DataUtils } from 'app/core/util/data-util.service';
<%_ } _%>
Expand All @@ -44,7 +44,7 @@ describe('Component Tests', () => {
providers: [
{
provide: ActivatedRoute,
useValue: { data: of({ <%= entityInstance %>: new <%= entityAngularName %>(<%- tsKeyId %>) }) }
useValue: { data: of({ <%= entityInstance %>: <%- testEntity %> }) }
}
]
})
Expand All @@ -63,7 +63,7 @@ describe('Component Tests', () => {
comp.ngOnInit();

// THEN
expect(comp.<%= entityInstance %>).toEqual(jasmine.objectContaining({ <%- primaryKey.name %>: <%- tsKeyId %> }));
expect(comp.<%= entityInstance %>).toEqual(jasmine.objectContaining(<%- testEntity %>));
});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export class <%= entityAngularName %> implements I<%= entityAngularName %> {
}
<%_ if (primaryKey) { _%>

export function get<%= entityAngularName %>Identifier(<%= entityInstance %>: I<%= entityAngularName %>): <%= primaryKey.tsType %> | undefined {
return <%= entityInstance %>.<%= primaryKey.name %>;
export function get<%= entityAngularName %>Identifier(<%= entityInstance %>: I<%= entityAngularName %>): <%= primaryKey.trackByField.tsType %> | undefined {
return <%= entityInstance %>.<%= primaryKey.trackByField.fieldName %>;
}
<%_ } _%>
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ _%>
<table class="table table-striped" aria-describedby="page-heading">
<thead>
<tr<% if (pagination !== 'no') { %> <%= jhiPrefix %>Sort [(predicate)]="predicate" [(ascending)]="ascending" [callback]="<%= pagination !== 'infinite-scroll' ? 'loadPage.bind(this)' : 'reset.bind(this)'%>"<% } %>>
<%_ for (const field of fields) { _%>
<%_ for (const field of fields.filter(field => !field.hidden)) { _%>
<th scope="col"<% if (pagination !== 'no') { %> <%= jhiPrefix %>SortBy="<%= field.fieldName %>"<% } %>><span <%= jhiPrefix %>Translate="<%= field.fieldTranslationKey %>"><%= field.fieldNameHumanized %></span><% if (pagination !== 'no') { %> <fa-icon icon="sort"></fa-icon><% } %></th>
<%_ } _%>
<%_ for (const relationship of relationships) { _%>
Expand All @@ -97,9 +97,8 @@ _%>
<tbody<% if (pagination === 'infinite-scroll') { %> infinite-scroll (scrolled)="loadPage(page + 1)" [infiniteScrollDisabled]="page >= links['last']" [infiniteScrollDistance]="0"<% } %>>
<tr *ngFor="let <%= entityInstance %> of <%= entityInstancePlural %>; trackBy: track<%= primaryKey.nameCapitalized %>" data-cy="entityTable">
<%_
const keys = idFields.map(idField => `${entityInstance}.${idField.fieldName}`);
const routerLink = idFields.length === 0 ? '' : ` [routerLink]="['/${ entityUrl }', ${ keys.join(', ') }, 'view']"`;
for ([idx, field] of fields.entries()) {
const routerLink = ` [routerLink]="['/${ entityUrl }', ${entityInstance}.${primaryKey.trackByField.fieldName}, 'view']"`;
for (field of fields.filter(field => !field.hidden)) {
const fieldName = field.fieldName;
const fieldNameCapitalized = field.fieldNameCapitalized;
const fieldType = field.fieldType;
Expand Down Expand Up @@ -155,11 +154,11 @@ _%>
<%_ } else { _%>
<%_ if (relationshipType === 'many-to-many') { _%>
<span *ngFor="let <%= relationshipFieldName %> of <%= entityInstance %>.<%= relationshipFieldNamePlural %>; let last = last">
<a class="form-control-static" [routerLink]="['/<%= otherEntityStateName %>', <%= relationshipFieldName %>?.<%= relationship.otherEntity.primaryKey.name %>, 'view']">{{ <%= relationshipFieldName %>.<%= otherEntityField %> }}</a>{{ last ? '' : ', ' }}
<a class="form-control-static" [routerLink]="['/<%= otherEntityStateName %>', <%= relationshipFieldName %>.<%= relationship.otherEntity.primaryKey.trackByField.fieldName %>, 'view']">{{ <%= relationshipFieldName %>.<%= otherEntityField %> }}</a>{{ last ? '' : ', ' }}
</span>
<%_ } else { _%>
<div *ngIf="<%= entityInstance + "." + relationshipFieldName %>">
<a [routerLink]="['/<%= otherEntityStateName %>', <%= entityInstance + "." + relationshipFieldName + "?." + relationship.otherEntity.primaryKey.name %>, 'view']" >{{ <%= entityInstance + "." + relationshipFieldName + "?." + otherEntityField %> }}</a>
<a [routerLink]="['/<%= otherEntityStateName %>', <%= entityInstance %>.<%= relationshipFieldName %>?.<%= relationship.otherEntity.primaryKey.trackByField.fieldName %>, 'view']">{{ <%= entityInstance + "." + relationshipFieldName + "?." + otherEntityField %> }}</a>
</div>
<%_ } _%>
<%_ } _%>
Expand All @@ -169,7 +168,7 @@ _%>
<td class="text-right">
<div class="btn-group">
<button type="submit"
[routerLink]="['/<%= entityUrl %>', <%= entityInstance %>.<%= primaryKey.name %>, 'view']"
[routerLink]="['/<%= entityUrl %>', <%= entityInstance %>.<%= primaryKey.trackByField.fieldName %>, 'view']"
class="btn btn-info btn-sm"
data-cy="entityDetailsButton">
<fa-icon icon="eye"></fa-icon>
Expand All @@ -178,7 +177,7 @@ _%>
<%_ if (!readOnly) { _%>

<button type="submit"
[routerLink]="['/<%= entityUrl %>', <%= entityInstance %>.<%= primaryKey.name %>, 'edit']"
[routerLink]="['/<%= entityUrl %>', <%= entityInstance %>.<%= primaryKey.trackByField.fieldName %>, 'edit']"
class="btn btn-primary btn-sm"
data-cy="entityEditButton">
<fa-icon icon="pencil-alt"></fa-icon>
Expand Down
Loading