Repository: jhipster/generator-jhipster (ts)

Issue:
import-jdl broken with react when using microservices


##### **Overview of the issue**
As of the old (and currently supported) JDL standard, it is possible to use the 

```
microservice FooEntity with FooService
```

statement in JDL to specify the source microservice for the gateways endpoints. 

This still works great for Angular 6. But in React it's broken, as it does wrong import statements in the models.

Here is my app.jh

```

entity Book {
    title String required,
    author String,
    year Integer,
    price Integer
}

entity Category {
    title String required
}

entity Customer {
    streetName String,
    streetNumber String,
    postalCode String,
    city String
}


enum OrderStatus {
    NEW,
    PAYED,
    SHIPPED
}

entity BookOrder {
    status OrderStatus required
}

relationship ManyToOne {
    Book{category} to Category

}

relationship OneToMany {
    Customer{order} to BookOrder
}

relationship OneToOne {
    Customer{user} to User{customer}
}

relationship ManyToMany {
    BookOrder{book} to Book{order}
}

microservice BookOrder with OrderService
microservice Customer with uaa
microservice Book with BookService
microservice Category with BookService
```

This generates a model like this one:

```
import { ICategory } from './category.model';
import {IBookOrder} from "./book-order.model";

export interface IBook {
  id?: number;
  title?: string;
  author?: string;
  year?: number;
  price?: number;
  category?: ICategory;
  orders?: IBookOrder[];
}

export const defaultValue: Readonly<IBook> = {};
```

The generator doesn't consider to do a different import for this line:


```
import {IBookOrder} from "./book-order.model";
```

which should be

```
import {IBookOrder} from "app/shared/model/OrderService/book-order.model";
```

or

```
import {IBookOrder} from "../OrderService/book-order.model";
```


<!-- Explain the bug, if an error is being thrown a stack trace helps -->

##### **Motivation for or Use Case**

Both frontends, NG and react should bring the same experience, and this microservice thing is a crucial feature for that.

<!-- Explain why this is a bug for you -->

##### **Reproduce the error**

Generate a JHipster Gateway using react. Use the provided JDL for ```jhipster import-jdl app.jh```
Repeat the same for an Angular based Gateway and it works.

##### **Suggest a Fix**

Do a further check if `microserviceName` is present and do a correct import in the models

<!-- If you can't fix the bug yourself, perhaps you can point to what might be
  causing the problem (line of code or commit) -->

##### **JHipster Version(s)**
Current master
<!--
Which version of JHipster are you using, is it a regression?
-->

##### **JHipster configuration**

<!--
To provide all information we need, you should run `jhipster info` in the project root folder, and
copy/paste the result here.
The `.yo-rc.json` file generated in the root folder is mandatory for bug reports. This will help us to replicate the scenario.
You should remove any sensitive information like the rememberMe key or the jwtSecretKey key.
-->

##### **Entity configuration(s) `entityName.json` files generated in the `.jhipster` directory**

<!--
If the error is during an entity creation or associated with a specific entity.
If you are using JDL, please share that configuration as well.
-->

##### **Browsers and Operating System**

<!-- What OS are you on? is this a problem with all browsers or only IE8? -->

- [x] Checking this box is mandatory (this is just to show you read everything)

<!-- Love JHipster? Please consider supporting our collective:
👉  https://opencollective.com/generator-jhipster/donate -->


Pull request description:
Made the imports for both angularX & react relationships the same
Fixes #7891

---

- Please make sure the below checklist is followed for Pull Requests.

- [x] [Travis tests](https://travis-ci.org/jhipster/generator-jhipster/pull_requests) are green
- [X] Tests are added where necessary
- [X] Documentation is added/updated where necessary
- [X] Coding Rules & Commit Guidelines as per our [CONTRIBUTING.md document](https://github.com/jhipster/generator-jhipster/blob/master/CONTRIBUTING.md) are followed



Patch:
diff --git a/generators/client/templates/angular/package.json.ejs b/generators/client/templates/angular/package.json.ejs
index 3147e16cd2..7104e94ca5 100644
--- a/generators/client/templates/angular/package.json.ejs
+++ b/generators/client/templates/angular/package.json.ejs
@@ -42,7 +42,7 @@
     "core-js": "2.5.3",
     "jquery": "3.3.1",
     "moment": "2.21.0",
-    "ng-jhipster": "0.5.4",
+    "ng-jhipster": "0.5.3",
     "ngx-cookie": "2.0.1",
     "ngx-infinite-scroll": "0.5.1",
     "ngx-webstorage": "2.0.1",
diff --git a/generators/generator-base-private.js b/generators/generator-base-private.js
index ab16678ff0..d32667ad92 100644
--- a/generators/generator-base-private.js
+++ b/generators/generator-base-private.js
@@ -987,6 +987,7 @@ module.exports = class extends Generator {
      *
      * @param {Array|Object} relationships - array of relationships
      * @param {string} dto - dto
+     * @param {string} clientFramework the client framework, 'angularX' or 'react'.
      * @returns typeImports: Map
      */
     generateEntityClientImports(relationships, dto, clientFramework = this.clientFramework) {
@@ -1012,7 +1013,7 @@ module.exports = class extends Generator {
                 if (otherEntityAngularName === 'User') {
                     importPath = clientFramework === 'angularX' ? 'app/core/user/user.model' : './user.model';
                 } else {
-                    importPath = clientFramework === 'angularX' ? `app/shared/model/${relationship.otherEntityClientRootFolder}${relationship.otherEntityFileName}.model` : `./${relationship.otherEntityFileName}.model`;
+                    importPath = `app/shared/model/${relationship.otherEntityClientRootFolder}${relationship.otherEntityFileName}.model`;
                 }
                 typeImports.set(importType, importPath);
             }
diff --git a/generators/kubernetes/files.js b/generators/kubernetes/files.js
index a6ec0fbf92..29affded20 100644
--- a/generators/kubernetes/files.js
+++ b/generators/kubernetes/files.js
@@ -38,9 +38,9 @@ function writeFiles() {
                 }
                 if ((this.app.applicationType === 'gateway' || this.app.applicationType === 'monolith') && this.kubernetesServiceType === 'Ingress') {
                     this.template('ingress.yml.ejs', `${appName}/${appName}-ingress.yml`);
-                }
-                if (!this.app.serviceDiscoveryType && this.app.authenticationType === 'jwt') {
-                    this.template('secret/jwt-secret.yml.ejs', `${appName}/jwt-secret.yml`);
+                    if (!this.app.serviceDiscoveryType && this.app.authenticationType === 'jwt') {
+                        this.template('secret/jwt-secret.yml.ejs', `${appName}/jwt-secret.yml`);
+                    }
                 }
                 if (this.monitoring === 'prometheus') {
                     this.template('monitoring/jhipster-prometheus-sm.yml.ejs', `${appName}/${appName}-prometheus-sm.yml`);
diff --git a/generators/server/templates/gradle.properties.ejs b/generators/server/templates/gradle.properties.ejs
index 871b3663b8..11217b1c52 100644
--- a/generators/server/templates/gradle.properties.ejs
+++ b/generators/server/templates/gradle.properties.ejs
@@ -25,7 +25,7 @@ npm_version=<%= NPM_VERSION %>
 yarn_version=<%= YARN_VERSION %>
 
 # Dependency versions
-jhipster_dependencies_version=2.0.14
+jhipster_dependencies_version=2.0.13
 # The spring-boot version should match the one managed by
 # https://mvnrepository.com/artifact/io.github.jhipster/jhipster-dependencies/${jhipster_dependencies_version}
 spring_boot_version=2.0.3.RELEASE
diff --git a/generators/server/templates/pom.xml.ejs b/generators/server/templates/pom.xml.ejs
index d89ba9d32e..243d568e11 100644
--- a/generators/server/templates/pom.xml.ejs
+++ b/generators/server/templates/pom.xml.ejs
@@ -69,7 +69,7 @@
         <profile.swagger />
 
         <!-- Dependency versions -->
-        <jhipster-dependencies.version>2.0.14</jhipster-dependencies.version>
+        <jhipster-dependencies.version>2.0.13</jhipster-dependencies.version>
         <!-- The spring-boot version should match the one managed by
         https://mvnrepository.com/artifact/io.github.jhipster/jhipster-dependencies/${jhipster-dependencies.version} -->
         <spring-boot.version>2.0.3.RELEASE</spring-boot.version>
diff --git a/generators/server/templates/src/main/java/package/web/rest/GatewayResource.java.ejs b/generators/server/templates/src/main/java/package/web/rest/GatewayResource.java.ejs
index f1f3078db4..b8a6a417ce 100644
--- a/generators/server/templates/src/main/java/package/web/rest/GatewayResource.java.ejs
+++ b/generators/server/templates/src/main/java/package/web/rest/GatewayResource.java.ejs
@@ -27,8 +27,6 @@ import org.springframework.cloud.client.discovery.DiscoveryClient;
 import org.springframework.cloud.netflix.zuul.filters.Route;
 import org.springframework.cloud.netflix.zuul.filters.RouteLocator;
 import org.springframework.http.*;
-import org.springframework.security.access.annotation.Secured;
-import <%=packageName%>.security.AuthoritiesConstants;
 import org.springframework.web.bind.annotation.*;
 
 import com.codahale.metrics.annotation.Timed;
@@ -56,7 +54,6 @@ public class GatewayResource {
      */
     @GetMapping("/routes")
     @Timed
-    @Secured(AuthoritiesConstants.ADMIN)
     public ResponseEntity<List<RouteVM>> activeRoutes() {
         List<Route> routes = routeLocator.getRoutes();
         List<RouteVM> routeVMs = new ArrayList<>();
diff --git a/generators/server/templates/src/main/java/package/web/rest/UserResource.java.ejs b/generators/server/templates/src/main/java/package/web/rest/UserResource.java.ejs
index 36ddf899d8..464c8c7b3b 100644
--- a/generators/server/templates/src/main/java/package/web/rest/UserResource.java.ejs
+++ b/generators/server/templates/src/main/java/package/web/rest/UserResource.java.ejs
@@ -196,7 +196,6 @@ public class UserResource {
      */
     @GetMapping("/users")
     @Timed
-    @Secured(AuthoritiesConstants.ADMIN)
     <%_ if (databaseType === 'sql' || databaseType === 'mongodb' || databaseType === 'couchbase') { _%>
     public ResponseEntity<List<UserDTO>> getAllUsers(Pageable pageable) {
         final Page<UserDTO> page = userService.getAllManagedUsers(pageable);
diff --git a/package.json b/package.json
index 12632191d1..11fbe97ebe 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
 {
   "name": "generator-jhipster",
-  "version": "5.0.2",
+  "version": "5.0.1",
   "description": "Spring Boot + Angular/React in one handy generator",
   "files": [
     "cli",
@@ -84,8 +84,8 @@
     "yeoman-test": "1.8.0"
   },
   "engines": {
-    "node": ">=8.10.0",
-    "npm": ">=5.6.0"
+    "node": ">=8.9.0",
+    "npm": ">=5.5.1"
   },
   "license": "Apache-2.0",
   "collective": {


Test patch:
diff --git a/test/generator-base-private.spec.js b/test/generator-base-private.spec.js
index 3168699060..ebfb6388b7 100644
--- a/test/generator-base-private.spec.js
+++ b/test/generator-base-private.spec.js
@@ -62,40 +62,69 @@ export * from './entityFolderName/entityFileName.state';`;
     });
 
     describe('generateEntityClientImports', () => {
-        const relationships = [
-            {
-                otherEntityAngularName: 'User'
-            },
-            {
-                otherEntityAngularName: 'AnEntity'
-            }
-        ];
-        describe('when called with dto option', () => {
-            it('return an empty Map', () => {
-                const imports = BaseGenerator.generateEntityClientImports(relationships, 'yes');
-                expect(imports.size).to.eql(0);
-            });
-        });
-        describe('when called with 2 distinct relationships without dto option', () => {
-            it('return a Map with 2 imports', () => {
-                const imports = BaseGenerator.generateEntityClientImports(relationships, 'no');
-                expect(imports).to.have.all.keys('IUser', 'IAnEntity');
-                expect(imports.size).to.eql(relationships.length);
-            });
-        });
-        describe('when called with 2 identical relationships without dto option', () => {
+        describe('with relationships from or to the User', () => {
             const relationships = [
                 {
                     otherEntityAngularName: 'User'
                 },
                 {
-                    otherEntityAngularName: 'User'
+                    otherEntityAngularName: 'AnEntity'
                 }
             ];
-            it('return a Map with 1 import', () => {
-                const imports = BaseGenerator.generateEntityClientImports(relationships, 'no');
-                expect(imports).to.have.key('IUser');
-                expect(imports.size).to.eql(1);
+            describe('when called with dto option', () => {
+                it('return an empty Map', () => {
+                    const imports = BaseGenerator.generateEntityClientImports(relationships, 'yes');
+                    expect(imports.size).to.eql(0);
+                });
+            });
+            describe('when called with 2 distinct relationships without dto option', () => {
+                it('return a Map with 2 imports', () => {
+                    const imports = BaseGenerator.generateEntityClientImports(relationships, 'no');
+                    expect(imports).to.have.all.keys('IUser', 'IAnEntity');
+                    expect(imports.size).to.eql(relationships.length);
+                });
+            });
+            describe('when called with 2 identical relationships without dto option', () => {
+                const relationships = [
+                    {
+                        otherEntityAngularName: 'User'
+                    },
+                    {
+                        otherEntityAngularName: 'User'
+                    }
+                ];
+                it('return a Map with 1 import', () => {
+                    const imports = BaseGenerator.generateEntityClientImports(relationships, 'no');
+                    expect(imports).to.have.key('IUser');
+                    expect(imports.size).to.eql(1);
+                });
+            });
+        });
+        describe('with no relationship from or to the User', () => {
+            describe('when called to have models to be imported in the templates', () => {
+                let importsForAngular = null;
+                let importsForReact = null;
+                const relationships = [
+                    {
+                        otherEntityAngularName: 'AnEntity',
+                        otherEntityFileName: 'AnEntity',
+                        otherEntityClientRootFolder: 'anEntity'
+                    },
+                    {
+                        otherEntityAngularName: 'AnotherEntity',
+                        otherEntityFileName: 'AnotherEntity',
+                        otherEntityClientRootFolder: 'anotherEntity'
+                    }
+                ];
+
+                before(() => {
+                    importsForAngular = BaseGenerator.generateEntityClientImports(relationships, 'no', 'angularX');
+                    importsForReact = BaseGenerator.generateEntityClientImports(relationships, 'no', 'react');
+                });
+
+                it('adds the same imports regardless of the client framework', () => {
+                    expect(importsForAngular).to.eql(importsForReact);
+                });
             });
         });
     });