diff --git a/README.md b/README.md index 12844930..93e823bc 100644 --- a/README.md +++ b/README.md @@ -6,20 +6,20 @@ ## Installing and Using the Active Development Version -This currently active development branch is based on the latest production release of JHipster - v7.9.3 +This currently active development branch is based on the latest production release of JHipster - v7.9.3. As a pre-requisite, you must have NodeJS v16.x installed, along with the bundled version of NPM. 1. Start by installing JHipster v7.9.3 with ``` -npm install -g generator-jhipster +npm install -g generator-jhipster@7 ``` 2. Then install this in-development blueprint by ``` -git clone https://github.com/jeremyg484/generator-jhipster-micronaut.git +git clone https://github.com/jhipster/generator-jhipster-micronaut.git cd generator-jhipster-micronaut git checkout micronaut-3 npm link generator-jhipster @@ -133,7 +133,8 @@ docker run -it --rm -v $PWD:/home/jhipster/app jhipster-generator-micronaut /bin ## Compatibility | Micronaut Blueprint | Micronaut | JHipster | -| ------------------- | --------- | -------- | +|---------------------|-----------|----------| +| 2.0.0 | 3.10.1 | 7.9.3 | | 1.0.2 | 2.4.4 | 6.10.5 | | 0.8.0 | 2.3.0 | 6.10.5 | diff --git a/generators/entity-server/templates_back/src/main/java/package/domain/Entity.java.ejs b/generators/entity-server/templates_back/src/main/java/package/domain/Entity.java.ejs deleted file mode 100644 index 7e0cc214..00000000 --- a/generators/entity-server/templates_back/src/main/java/package/domain/Entity.java.ejs +++ /dev/null @@ -1,564 +0,0 @@ -<%# - Copyright 2019-2023 the original author or authors from the JHipster project. - - This file is part of the JHipster project, see https://www.jhipster.tech/ - for more information. - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. --%> -package <%= packageName %>.domain; - -<%_ -let hasDto = dto === 'mapstruct'; -let isUsingMapsId = false; -let hasTextBlob = false; -let hasRelationship = relationships.length !== 0; -_%> -<%_ -for (idx in relationships) { - isUsingMapsId = relationships[idx].useJPADerivedIdentifier; - if ( isUsingMapsId === true) { - break; - } - isUsingMapsId = false; -} -for (idx in fields) { - if ((prodDatabaseType === 'postgresql' || devDatabaseType === 'postgresql') && fields[idx].fieldTypeBlobContent === 'text') { - hasTextBlob = true; - break; - } -} -_%> -<%_ if (databaseType === 'cassandra') { _%> -// import org.springframework.data.annotation.Id; - <%_ if (fieldsContainBlob) { _%> -// import org.springframework.data.cassandra.core.mapping.Column; - <%_ } _%> -// import org.springframework.data.cassandra.core.mapping.Table; -<%_ } if (importJsonIgnore === true) { _%> -import com.fasterxml.jackson.annotation.JsonIgnore; -<%_ } if (importJsonIgnoreProperties === true) { _%> -import com.fasterxml.jackson.annotation.JsonIgnoreProperties; -<%_ } if (!hasDto && (typeof javadoc != 'undefined' || importApiModelProperty)) { _%> -import io.swagger.v3.oas.annotations.media.Schema; -<%_ } if (enableHibernateCache) { _%> -import org.hibernate.annotations.Cache; -import org.hibernate.annotations.CacheConcurrencyStrategy; -<%_ } if (hasTextBlob === true || (fieldsContainUUID === true && ['mysql', 'mariadb'].includes(prodDatabaseType))) { _%> -import org.hibernate.annotations.Type; -<%_ } if (databaseType === 'mongodb') { _%> -// import org.springframework.data.annotation.Id; -// import org.springframework.data.mongodb.core.mapping.Field; -// import org.springframework.data.mongodb.core.mapping.Document; - <%_ if (hasRelationship) { _%> -// import org.springframework.data.mongodb.core.mapping.DBRef; - <%_ } _%> -<%_ } else if (databaseType === 'couchbase') { _%> -// import org.springframework.data.annotation.Id; -import com.couchbase.client.java.repository.annotation.Field; -// import org.springframework.data.couchbase.core.mapping.Document; -// import org.springframework.data.couchbase.core.mapping.id.GeneratedValue; -// import org.springframework.data.couchbase.core.mapping.id.IdPrefix; - <%_ if (hasRelationship) { _%> -// import org.springframework.data.couchbase.core.query.FetchType; -// import org.springframework.data.couchbase.core.query.N1qlJoin; - <%_ } _%> -<%_ } if (databaseType === 'sql') { _%> - -import javax.persistence.*; -<%_ } if (validation) { _%> -import javax.validation.constraints.*; -<%_ } _%> - -<%_ if (searchEngine === 'elasticsearch') { _%> -// import org.springframework.data.elasticsearch.annotations.FieldType; -<%_ } _%> -import java.io.Serializable; -<%_ if (fieldsContainBigDecimal === true) { _%> -import java.math.BigDecimal; -<%_ } if (fieldsContainBlob && databaseType === 'cassandra') { _%> -import java.nio.ByteBuffer; -<%_ } if (fieldsContainInstant === true) { _%> -import java.time.Instant; -<%_ } if (fieldsContainLocalDate === true) { _%> -import java.time.LocalDate; -<%_ } if (fieldsContainZonedDateTime === true) { _%> -import java.time.ZonedDateTime; -<%_ } if (fieldsContainDuration === true) { _%> -import java.time.Duration; -<%_ } if (importSet === true) { _%> -import java.util.HashSet; -import java.util.Set; -<%_ } if (databaseType === 'couchbase' && hasRelationship) { _%> -import java.util.stream.Collectors; -<%_ } _%> -<%_ if (databaseType === 'cassandra' || fieldsContainUUID === true) { _%> -import java.util.UUID; -<%_ } -Object.keys(uniqueEnums).forEach(function(element) { _%> - -import <%= packageName %>.domain.enumeration.<%= element %>; -<%_ }); _%> - -<%_ if (databaseType === 'couchbase') { _%> -import static <%= packageName %>.config.Constants.ID_DELIMITER; -// import static org.springframework.data.couchbase.core.mapping.id.GenerationStrategy.UNIQUE; - -<%_ } _%> -<%_ if (typeof javadoc == 'undefined') { _%> -/** - * A <%= asEntity(entityClass) %>. - */ -<%_ } else { _%> -<%- formatAsClassJavadoc(javadoc) %> - <%_ if (!hasDto) { _%> -@Schema(description = "<%- formatAsApiDescription(javadoc) %>") - <%_ } _%> -<%_ } _%> -<%_ if (databaseType === 'sql') { _%> -@Entity -@Table(name = "<%= entityTableName %>") -<%_ if (enableHibernateCache) { - if (cacheProvider === 'infinispan') { _%> -@Cache(usage = CacheConcurrencyStrategy.READ_WRITE) -<%_ } else { _%> -@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE) -<%_ } - } -} if (databaseType === 'mongodb') { _%> -@Document(collection = "<%= entityTableName %>") -<%_ } if (databaseType === 'couchbase') { _%> -@Document -<%_ } if (databaseType === 'cassandra') { _%> -@Table("<%= entityInstance %>") -<%_ } if (searchEngine === 'elasticsearch') { _%> -// @org.springframework.data.elasticsearch.annotations.Document(indexName = "<%= entityInstance.toLowerCase() %>") -<%_ } _%> -public class <%= asEntity(entityClass) %> implements Serializable { - - private static final long serialVersionUID = 1L; - <%_ if (databaseType === 'couchbase') { _%> - public static final String PREFIX = "<%= entityInstance.toLowerCase() %>"; - - @SuppressWarnings("unused") - @IdPrefix - private String prefix = PREFIX; - <%_ } _%> - - @Id - <%_ if (databaseType === 'sql' && isUsingMapsId === false) { _%> - <%_ if (prodDatabaseType === 'mysql' || prodDatabaseType === 'mariadb') { _%> - @GeneratedValue(strategy = GenerationType.IDENTITY) - <%_ } else { _%> - @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "sequenceGenerator") - @SequenceGenerator(name = "sequenceGenerator") - <%_ } _%> - <%_ } _%> - <%_ if (databaseType === 'couchbase') { _%> - @GeneratedValue(strategy = UNIQUE, delimiter = ID_DELIMITER) - <%_ } _%> - private <%= primaryKey.type %> id; - -<%_ for (idx in fields) { - if (typeof fields[idx].javadoc !== 'undefined') { _%> -<%- formatAsFieldJavadoc(fields[idx].javadoc) %> - <%_ } - let required = false; - let unique = false; - const fieldValidate = fields[idx].fieldValidate; - const fieldValidateRules = fields[idx].fieldValidateRules; - const fieldValidateRulesMaxlength = fields[idx].fieldValidateRulesMaxlength; - const fieldType = fields[idx].fieldType; - const fieldTypeBlobContent = fields[idx].fieldTypeBlobContent; - const fieldName = fields[idx].fieldName; - const fieldNameUnderscored = fields[idx].fieldNameUnderscored; - const fieldNameAsDatabaseColumn = fields[idx].fieldNameAsDatabaseColumn; - if (fieldValidate === true) { - if (fieldValidateRules.includes('required')) { - required = true; - } - if (fieldValidateRules.includes('unique')) { - unique = true; - } _%> - <%- include('../common/field_validators') -%> - <%_ } _%> - <%_ if (!hasDto && typeof fields[idx].javadoc != 'undefined') { _%> - @Schema(description = "<%- formatAsApiDescription(fields[idx].javadoc) %>"<% if (required) { %>, required = true<% } %>) - <%_ } _%> - <%_ if (databaseType === 'sql') { - if (fields[idx].fieldIsEnum) { _%> - @Enumerated(EnumType.STRING) - <%_ } - if (fieldType === 'byte[]') { _%> - @Lob - <%_ if ((prodDatabaseType === 'postgresql' || devDatabaseType === 'postgresql') && fieldTypeBlobContent === 'text' ) { _%> - @Type(type = "org.hibernate.type.TextType") - <%_ } - } - if (['Instant', 'ZonedDateTime', 'LocalDate', 'Duration'].includes(fieldType)) { _%> - @Column(name = "<%- fieldNameAsDatabaseColumn %>"<% if (required) { %>, nullable = false<% } %><% if (unique) { %>, unique = true<% } %>) - <%_ } else if (fieldType === 'BigDecimal') { _%> - @Column(name = "<%- fieldNameAsDatabaseColumn %>", precision = 21, scale = 2<% if (required) { %>, nullable = false<% } %><% if (unique) { %>, unique = true<% } %>) - <%_ } else if (fieldType === 'UUID' && ['mysql', 'mariadb'].includes(prodDatabaseType)) { _%> - @Type(type = "uuid-char") - @Column(name = "<%- fieldNameAsDatabaseColumn %>", length = 36<% if (required) { %>, nullable = false<% } %><% if (unique) { %>, unique = true<% } %>) - <%_ } else { _%> - @Column(name = "<%- fieldNameAsDatabaseColumn %>"<% if (fieldValidate === true) { %><% if (fieldValidateRules.includes('maxlength')) { %>, length = <%= fieldValidateRulesMaxlength %><% } %><% if (required) { %>, nullable = false<% } %><% if (unique) { %>, unique = true<% } %><% } %>) - <%_ } - } _%> - <%_ if (databaseType === 'mongodb' || databaseType === 'couchbase') { _%> - @Field("<%= fieldNameUnderscored %>") - <%_ } _%> - <%_ if (fieldTypeBlobContent !== 'text') { _%> - private <%= fieldType %> <%= fieldName %>; - <%_ } else { _%> - private String <%= fieldName %>; - <%_ } _%> - - <%_ if ((fieldType === 'byte[]' || fieldType === 'ByteBuffer') && fieldTypeBlobContent !== 'text') { _%> - <%_ if (databaseType === 'sql' || databaseType === 'cassandra') { _%> - @Column(<% if (databaseType !== 'cassandra') { %>name = <% } %>"<%- fieldNameAsDatabaseColumn %>_content_type"<% if (required && databaseType !== 'cassandra') { %>, nullable = false<% } %>) - <%_ if (required && databaseType === 'cassandra') { _%> - @NotNull - <%_ } _%> - <%_ } _%> - <%_ if (databaseType === 'mongodb' || databaseType === 'couchbase') { _%> - @Field("<%= fieldNameUnderscored %>_content_type") - <%_ } _%> - private String <%= fieldName %>ContentType; - - <%_ } - } - - for (idx in relationships) { - const otherEntityRelationshipName = relationships[idx].otherEntityRelationshipName; - const otherEntityRelationshipNamePlural = relationships[idx].otherEntityRelationshipNamePlural; - const relationshipName = relationships[idx].relationshipName; - const relationshipFieldName = relationships[idx].relationshipFieldName; - const relationshipFieldNamePlural = relationships[idx].relationshipFieldNamePlural; - const joinTableName = getJoinTableName(entityTableName, relationshipName, prodDatabaseType); - const relationshipType = relationships[idx].relationshipType; - const relationshipValidate = relationships[idx].relationshipValidate; - const relationshipRequired = relationships[idx].relationshipRequired; - const otherEntityNameCapitalized = relationships[idx].otherEntityNameCapitalized; - const ownerSide = relationships[idx].ownerSide; - const isUsingMapsId = relationships[idx].useJPADerivedIdentifier; - if (otherEntityRelationshipName) { - mappedBy = otherEntityRelationshipName.charAt(0).toLowerCase() + otherEntityRelationshipName.slice(1) - } - if (typeof relationships[idx].javadoc != 'undefined') { _%> -<%- formatAsFieldJavadoc(relationships[idx].javadoc) %> - <%_ if (!hasDto) { _%> - @Schema(description = "<%- formatAsApiDescription(relationships[idx].javadoc) %>") - <%_ } _%> - <%_ } - if (relationshipType === 'one-to-many') { - if (databaseType === 'sql') { - _%> - @OneToMany(mappedBy = "<%= otherEntityRelationshipName %>") - <%_ if (enableHibernateCache) { - if (cacheProvider === 'infinispan') { _%> - @Cache(usage = CacheConcurrencyStrategy.READ_WRITE) - <%_ } else { _%> - @Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE) - <%_ } - } - } else if (databaseType === 'mongodb' || databaseType === 'couchbase') { - if (databaseType === 'mongodb') { _%> - @DBRef - <%_ } _%> - @Field("<%= relationshipFieldName %>") - <%_ if (databaseType === 'couchbase') { _%> - private Set <%= relationshipFieldName %>Ids = new HashSet<>(); - - @N1qlJoin(on = "lks.<%= relationshipFieldName %>=meta(rks).id", fetchType = FetchType.IMMEDIATE) - <%_ } _%> - <%_ } _%> - private Set<<%= asEntity(otherEntityNameCapitalized) %>> <%= relationshipFieldNamePlural %> = new HashSet<>(); - - <%_ } else if (relationshipType === 'many-to-one') { - if (databaseType === 'sql') { - _%> - @ManyToOne<% if (relationshipRequired) { %>(optional = false)<% } %> - <%_ if (relationshipValidate) { _%> - <%- include('relationship_validators') -%> - <%_ } - } else if (databaseType === 'mongodb' || databaseType === 'couchbase') { - if (databaseType === 'mongodb') { _%> - @DBRef - <%_ } _%> - @Field("<%= relationshipFieldName %>") - <%_ if (databaseType === 'couchbase') { _%> - private String <%= relationshipFieldName %>Id; - - @N1qlJoin(on = "lks.<%= relationshipFieldName %>=meta(rks).id", fetchType = FetchType.IMMEDIATE) - <%_ } - } - _%> - <%_ if (otherEntityRelationshipNamePlural !== undefined && otherEntityRelationshipNamePlural !== '') { _%> - @JsonIgnoreProperties("<%= otherEntityRelationshipNamePlural %>") - <%_ } _%> - private <%= asEntity(otherEntityNameCapitalized) %> <%= relationshipFieldName %>; - - <%_ } else if (relationshipType === 'many-to-many') { - if (databaseType === 'sql') { _%> - @ManyToMany<% if (ownerSide === false) { %>(mappedBy = "<%= otherEntityRelationshipNamePlural %>")<% } %> - <%_ if (enableHibernateCache) { - if (cacheProvider === 'infinispan') { _%> - @Cache(usage = CacheConcurrencyStrategy.READ_WRITE) - <%_ } else { _%> - @Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE) - <%_ } - } if (ownerSide === true) { - if (relationshipValidate) { _%> - <%- include('relationship_validators') -%> - <%_ } _%> - @JoinTable(name = "<%= joinTableName %>", - joinColumns = @JoinColumn(name = "<%= getColumnName(name) %>_id", referencedColumnName = "id"), - inverseJoinColumns = @JoinColumn(name = "<%= getColumnName(relationships[idx].relationshipName) %>_id", referencedColumnName = "id")) - <%_ } - } else if (databaseType === 'mongodb' || databaseType === 'couchbase') { - if (databaseType === 'mongodb') { _%> - @DBRef - <%_ } _%> - @Field("<%= relationshipFieldNamePlural %>") - <%_ if (databaseType === 'couchbase') { _%> - private Set <%= relationshipFieldName %>Ids = new HashSet<>(); - - @N1qlJoin(on = "lks.<%= relationshipFieldNamePlural %>=meta(rks).id", fetchType = FetchType.IMMEDIATE) - <%_ } - } if (ownerSide === false) { _%> - @JsonIgnore - <%_ } _%> - private Set<<%= asEntity(otherEntityNameCapitalized) %>> <%= relationshipFieldNamePlural %> = new HashSet<>(); - - <%_ } else { - if (databaseType === 'sql') { - if (ownerSide) { _%> - @OneToOne<% if (relationshipRequired) { %>(optional = false)<% } %> - <%_ if (relationshipValidate) { _%> - <%- include('relationship_validators') -%> - <%_ } _%> - <%_ if (isUsingMapsId === true) { %> - @MapsId - @JoinColumn(name = "id") - <%_ } else { _%> - @JoinColumn(unique = true) - <%_ } _%> - <%_ } else { _%> - @OneToOne(mappedBy = "<%= otherEntityRelationshipName %>") - @JsonIgnore - <%_ } - } else if (databaseType === 'mongodb' || databaseType === 'couchbase') { - if (databaseType === 'mongodb') { _%> - @DBRef - <%_ } _%> - @Field("<%= relationshipFieldName %>") - <%_ if (databaseType === 'couchbase') { _%> - private String <%= relationshipFieldName %>Id; - - @N1qlJoin(on = "lks.<%= relationshipFieldName %>=meta(rks).id", fetchType = FetchType.IMMEDIATE) - <%_ } - if (ownerSide === false) { _%> - @com.fasterxml.jackson.annotation.JsonBackReference - <%_ } - } _%> - private <%= asEntity(otherEntityNameCapitalized) %> <%= relationshipFieldName %>; - - <%_ } - } _%> - // jhipster-needle-entity-add-field - JHipster will add fields here, do not remove - public <% if (databaseType === 'sql') { %><%= primaryKey.type %><% } %><% if (databaseType === 'mongodb' || databaseType === 'couchbase') { %>String<% } %><% if (databaseType === 'cassandra') { %>UUID<% } %> getId() { - return id; - } - - public void setId(<% if (databaseType === 'sql') { %><%= primaryKey.type %><% } %><% if (databaseType === 'mongodb' || databaseType === 'couchbase') { %>String<% } %><% if (databaseType === 'cassandra') { %>UUID<% } %> id) { - this.id = id; - } -<%_ for (idx in fields) { - const fieldType = fields[idx].fieldType; - const fieldTypeBlobContent = fields[idx].fieldTypeBlobContent; - const fieldName = fields[idx].fieldName; - const fieldInJavaBeanMethod = fields[idx].fieldInJavaBeanMethod; _%> - - <%_ if (fieldTypeBlobContent !== 'text') { _%> - public <%= fieldType %> <% if (fieldType.toLowerCase() === 'boolean') { %>is<% } else { %>get<%_ } _%><%= fieldInJavaBeanMethod %>() { - <%_ } else { _%> - public String get<%= fieldInJavaBeanMethod %>() { - <%_ } _%> - return <%= fieldName %>; - } - <%_ if (fluentMethods) { _%> - - <%_ if (fieldTypeBlobContent !== 'text') { _%> - public <%= asEntity(entityClass) %> <%= fieldName %>(<%= fieldType %> <%= fieldName %>) { - <%_ } else { _%> - public <%= asEntity(entityClass) %> <%= fieldName %>(String <%= fieldName %>) { - <%_ } _%> - this.<%= fieldName %> = <%= fieldName %>; - return this; - } - <%_ } _%> - - <%_ if (fieldTypeBlobContent !== 'text') { _%> - public void set<%= fieldInJavaBeanMethod %>(<%= fieldType %> <%= fieldName %>) { - <%_ } else { _%> - public void set<%= fieldInJavaBeanMethod %>(String <%= fieldName %>) { - <%_ } _%> - this.<%= fieldName %> = <%= fieldName %>; - } - <%_ if ((fieldType === 'byte[]' || fieldType === 'ByteBuffer') && fieldTypeBlobContent !== 'text') { _%> - - public String get<%= fieldInJavaBeanMethod %>ContentType() { - return <%= fieldName %>ContentType; - } - <%_ if (fluentMethods) { _%> - - public <%= asEntity(entityClass) %> <%= fieldName %>ContentType(String <%= fieldName %>ContentType) { - this.<%= fieldName %>ContentType = <%= fieldName %>ContentType; - return this; - } - <%_ } _%> - - public void set<%= fieldInJavaBeanMethod %>ContentType(String <%= fieldName %>ContentType) { - this.<%= fieldName %>ContentType = <%= fieldName %>ContentType; - } - <%_ } _%> -<%_ } _%> -<%_ - for (idx in relationships) { - const relationshipFieldName = relationships[idx].relationshipFieldName; - const relationshipFieldNamePlural = relationships[idx].relationshipFieldNamePlural; - const relationshipType = relationships[idx].relationshipType; - const otherEntityNameCapitalized = relationships[idx].otherEntityNameCapitalized; - const relationshipNameCapitalized = relationships[idx].relationshipNameCapitalized; - const relationshipNameCapitalizedPlural = relationships[idx].relationshipNameCapitalizedPlural; - const otherEntityName = relationships[idx].otherEntityName; - const otherEntityNamePlural = relationships[idx].otherEntityNamePlural; - const otherEntityRelationshipNameCapitalized = relationships[idx].otherEntityRelationshipNameCapitalized; - const otherEntityRelationshipNameCapitalizedPlural = relationships[idx].otherEntityRelationshipNameCapitalizedPlural; - _%> - <%_ if (relationshipType === 'one-to-many' || relationshipType === 'many-to-many') { _%> - - public Set<<%= asEntity(otherEntityNameCapitalized) %>> get<%= relationshipNameCapitalizedPlural %>() { - return <%= relationshipFieldNamePlural %>; - } - <%_ if (fluentMethods) { _%> - - public <%= asEntity(entityClass) %> <%= relationshipFieldNamePlural %>(Set<<%= asEntity(otherEntityNameCapitalized) %>> <%= otherEntityNamePlural %>) { - this.<%= relationshipFieldNamePlural %> = <%= otherEntityNamePlural %>; - <%_ if (databaseType === 'couchbase') { _%> - this.<%= relationshipFieldName %>Ids = <%= otherEntityNamePlural %>.stream() - .map(<%= asEntity(otherEntityNameCapitalized) %>::getId) - .collect(Collectors.toSet()); - <%_ } _%> - return this; - } - - public <%= asEntity(entityClass) %> add<%= relationshipNameCapitalized %>(<%= asEntity(otherEntityNameCapitalized) %> <%= otherEntityName %>) { - this.<%= relationshipFieldNamePlural %>.add(<%= otherEntityName %>); - <%_ if (databaseType === 'couchbase') { _%> - this.<%= relationshipFieldName %>Ids.add(<%= otherEntityName %>.getId()); - <%_ } _%> - <%_ if (relationshipType === 'one-to-many') { _%> - <%= otherEntityName %>.set<%= otherEntityRelationshipNameCapitalized %>(this); - <%_ } else if (otherEntityRelationshipNameCapitalizedPlural !== '' && asEntity(otherEntityNameCapitalized)!=='User' && relationshipType === 'many-to-many') { - // JHipster version < 3.6.0 didn't ask for this relationship name _%> - <%= otherEntityName %>.get<%= otherEntityRelationshipNameCapitalizedPlural %>().add(this); - <%_ } _%> - return this; - } - - public <%= asEntity(entityClass) %> remove<%= relationshipNameCapitalized %>(<%= asEntity(otherEntityNameCapitalized) %> <%= otherEntityName %>) { - this.<%= relationshipFieldNamePlural %>.remove(<%= otherEntityName %>); - <%_ if (databaseType === 'couchbase') { _%> - this.<%= relationshipFieldName %>Ids.remove(<%= otherEntityName %>.getId()); - <%_ } _%> - <%_ if (relationshipType === 'one-to-many') { _%> - <%= otherEntityName %>.set<%= otherEntityRelationshipNameCapitalized %>(null); - <%_ } else if (otherEntityRelationshipNameCapitalizedPlural !== '' && asEntity(otherEntityNameCapitalized)!=='User' && relationshipType === 'many-to-many') { - // JHipster version < 3.6.0 didn't ask for this relationship name _%> - <%= otherEntityName %>.get<%= otherEntityRelationshipNameCapitalizedPlural %>().remove(this); - <%_ } _%> - return this; - } - <%_ } _%> - - public void set<%= relationshipNameCapitalizedPlural %>(Set<<%= asEntity(otherEntityNameCapitalized) %>> <%= otherEntityNamePlural %>) { - this.<%= relationshipFieldNamePlural %> = <%= otherEntityNamePlural %>; - <%_ if (databaseType === 'couchbase') { _%> - this.<%= relationshipFieldName %>Ids = <%= otherEntityNamePlural %>.stream() - .map(<%= asEntity(otherEntityNameCapitalized) %>::getId) - .collect(Collectors.toSet()); - <%_ } _%> - } - <%_ } else { _%> - - public <%= asEntity(otherEntityNameCapitalized) %> get<%= relationshipNameCapitalized %>() { - return <%= relationshipFieldName %>; - } - <%_ if (fluentMethods) { _%> - - public <%= asEntity(entityClass) %> <%= relationshipFieldName %>(<%= asEntity(otherEntityNameCapitalized) %> <%= otherEntityName %>) { - this.<%= relationshipFieldName %> = <%= otherEntityName %>; - <%_ if (databaseType === 'couchbase') { _%> - this.<%= relationshipFieldName %>Id = <%= otherEntityName %>.getId(); - <%_ } _%> - return this; - } - <%_ } _%> - - public void set<%= relationshipNameCapitalized %>(<%= asEntity(otherEntityNameCapitalized) %> <%= otherEntityName %>) { - this.<%= relationshipFieldName %> = <%= otherEntityName %>; - <%_ if (databaseType === 'couchbase') { _%> - this.<%= relationshipFieldName %>Id = <%= otherEntityName %>.getId(); - <%_ } _%> - } - <%_ } _%> -<%_ } _%> - // jhipster-needle-entity-add-getters-setters - JHipster will add getters and setters here, do not remove - - @Override - public boolean equals(Object o) { - if (this == o) { - return true; - } - if (!(o instanceof <%= asEntity(entityClass) %>)) { - return false; - } - return id != null && id.equals(((<%= asEntity(entityClass) %>) o).id); - } - - @Override - public int hashCode() { - return 31; - } - - @Override - public String toString() { - return "<%= asEntity(entityClass) %>{" + - "id=" + getId() + - <%_ for (idx in fields) { - const fieldType = fields[idx].fieldType; - const fieldTypeBlobContent = fields[idx].fieldTypeBlobContent; - const fieldName = fields[idx].fieldName; - const fieldInJavaBeanMethod = fields[idx].fieldInJavaBeanMethod; - const isNumeric = ['integer', 'long', 'float', 'double', 'bigdecimal'].includes(fieldType.toLowerCase()); _%> - ", <%= fieldName %>=<% if (! isNumeric) { %>'<% } %>" + <% if (fieldType.toLowerCase() === 'boolean') { %>is<% } else { %>get<% } %><%= fieldInJavaBeanMethod %>() <% if (! isNumeric) { %>+ "'" <% } %>+ - <%_ if ((fieldType === 'byte[]' || fieldType === 'ByteBuffer') && fieldTypeBlobContent !== 'text') { _%> - ", <%= fieldName %>ContentType='" + get<%= fieldInJavaBeanMethod %>ContentType() + "'" + - <%_ } _%> - <%_ } _%> - "}"; - } -} diff --git a/generators/entity-server/templates_back/src/main/java/package/domain/enumeration/Enum.java.ejs b/generators/entity-server/templates_back/src/main/java/package/domain/enumeration/Enum.java.ejs deleted file mode 100644 index 9ba809a7..00000000 --- a/generators/entity-server/templates_back/src/main/java/package/domain/enumeration/Enum.java.ejs +++ /dev/null @@ -1,26 +0,0 @@ -<%# - Copyright 2019-2023 the original author or authors from the JHipster project. - - This file is part of the JHipster project, see https://www.jhipster.tech/ - for more information. - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. --%> -package <%= packageName %>.domain.enumeration; - -/** - * The <%= enumName %> enumeration. - */ -public enum <%= enumName %> { - <%= enumValues %> -} diff --git a/generators/entity-server/templates_back/src/main/java/package/domain/imports.ejs b/generators/entity-server/templates_back/src/main/java/package/domain/imports.ejs deleted file mode 100644 index a533ed88..00000000 --- a/generators/entity-server/templates_back/src/main/java/package/domain/imports.ejs +++ /dev/null @@ -1,62 +0,0 @@ -<%# - Copyright 2019-2023 the original author or authors from the JHipster project. - - This file is part of the JHipster project, see https://www.jhipster.tech/ - for more information. - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. --%> -<%# Checks which imports are needed -%> -<%_ - -for (idx in relationships) { - if (typeof relationships[idx].javadoc != 'undefined') { - importApiModelProperty = true; - break; - } -} -if (!importApiModelProperty) { - for (idx in fields) { - if (typeof fields[idx].javadoc != 'undefined') { - importApiModelProperty = true; - break; - } - } -} - -for (idx in relationships) { - if (relationships[idx].ownerSide === false && ['one-to-many', 'one-to-one', 'many-to-many'].includes(relationships[idx].relationshipType)) { - importJsonIgnore = true; - } else if (relationships[idx].relationshipType === 'many-to-one') { - importJsonIgnoreProperties = true; - } - if (importJsonIgnore && importJsonIgnoreProperties) { - break; - } -} - -for (idx in relationships) { - if (relationships[idx].relationshipType === 'one-to-many' || relationships[idx].relationshipType === 'many-to-many') { - importSet = true; - break; - } -} - -for (idx in fields) { - if (fields[idx].fieldIsEnum && ( - !uniqueEnums[fields[idx].fieldType] || (uniqueEnums[fields[idx].fieldType] && fields[idx].fieldValues.length !== 0))) { - uniqueEnums[fields[idx].fieldType] = fields[idx].fieldType; - } -} - -_%> diff --git a/generators/entity-server/templates_back/src/main/java/package/domain/relationship_validators.ejs b/generators/entity-server/templates_back/src/main/java/package/domain/relationship_validators.ejs deleted file mode 100644 index 82e50659..00000000 --- a/generators/entity-server/templates_back/src/main/java/package/domain/relationship_validators.ejs +++ /dev/null @@ -1,31 +0,0 @@ -<%# - Copyright 2019-2023 the original author or authors from the JHipster project. - - This file is part of the JHipster project, see https://www.jhipster.tech/ - for more information. - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. --%> -<%# Returns a string of all validator annotations for the entity relationships. -%> -<% -const relationship = relationships[idx]; -let result = ''; -if (relationship.relationshipValidate === true) { - const validators = []; - if (relationship.relationshipRequired) { - validators.push('@NotNull'); - } - result = validators.join('\n '); - result += '\n'; -} -%> -<%- result -%> diff --git a/generators/entity-server/templates_back/src/main/java/package/service/dto/EntityCriteria.java.ejs b/generators/entity-server/templates_back/src/main/java/package/service/dto/EntityCriteria.java.ejs deleted file mode 100644 index f12b5f00..00000000 --- a/generators/entity-server/templates_back/src/main/java/package/service/dto/EntityCriteria.java.ejs +++ /dev/null @@ -1,174 +0,0 @@ -package <%= packageName %>.service.dto; - -import java.io.Serializable; -import java.util.Objects; -import io.github.jhipster.service.Criteria; -<%_ for (idx in fields) { if (fields[idx].fieldIsEnum === true) { _%> -import <%= packageName %>.domain.enumeration.<%= fields[idx].fieldType %>; -<%_ } } _%> -import io.github.jhipster.service.filter.BooleanFilter; -import io.github.jhipster.service.filter.DoubleFilter; -import io.github.jhipster.service.filter.Filter; -import io.github.jhipster.service.filter.FloatFilter; -import io.github.jhipster.service.filter.IntegerFilter; -import io.github.jhipster.service.filter.LongFilter; -import io.github.jhipster.service.filter.StringFilter; -<%_ if (fieldsContainBigDecimal === true) { _%> -import io.github.jhipster.service.filter.BigDecimalFilter; -<%_ } _%> -<%_ if (fieldsContainDuration === true) { _%> -import io.github.jhipster.service.filter.DurationFilter; -<%_ } _%> -<%_ if (fieldsContainInstant === true) { _%> -import io.github.jhipster.service.filter.InstantFilter; -<%_ } _%> -<%_ if (fieldsContainLocalDate === true) { _%> -import io.github.jhipster.service.filter.LocalDateFilter; -<%_ } _%> -<%_ if (fieldsContainUUID === true) { _%> -import io.github.jhipster.service.filter.UUIDFilter; -<%_ } _%> -<%_ if (fieldsContainZonedDateTime === true) { _%> -import io.github.jhipster.service.filter.ZonedDateTimeFilter; -<%_ } _%> - -<%_ -const referenceFilterType = '' + primaryKey.type + 'Filter'; -var filterVariables = [{name:'id', type: primaryKey.type, filterType:referenceFilterType,fieldInJavaBeanMethod:'Id' } ]; -var extraFilters = {}; -fields.forEach((field) => { -const fieldType = field.fieldType; -if (isFilterableType(fieldType)) { - var filterType; - if (field.fieldIsEnum == true) { - filterType = fieldType + 'Filter'; - extraFilters[fieldType] = {type: filterType, superType: 'Filter<' + fieldType + '>', fieldType: fieldType}; - } else if (['Duration', 'UUID', 'LocalDate', 'ZonedDateTime', 'Instant', 'String', 'Long', 'Integer', 'Float', 'Double', 'BigDecimal', 'Boolean'].includes(fieldType)) { - filterType = fieldType + 'Filter'; - } else { - filterType = 'Filter<' + fieldType + '>'; - } - filterVariables.push( { filterType : filterType, - name: field.fieldName, - type: fieldType, - fieldInJavaBeanMethod: field.fieldInJavaBeanMethod }); -} -}); -relationships.forEach((relationship) => { -const relationshipType = relationship.relationshipType; -// user has a String PK when using OAuth, so change relationships accordingly -let oauthAwareReferenceFilterType = referenceFilterType; -if (relationship.otherEntityName === 'user' && authenticationType === 'oauth2') { - oauthAwareReferenceFilterType = 'StringFilter'; -} -filterVariables.push({ filterType : oauthAwareReferenceFilterType, - name: relationship.relationshipFieldName + 'Id', - type: relationshipType, - fieldInJavaBeanMethod: relationship.relationshipNameCapitalized + 'Id' }); -}); -_%> -/** - * Criteria class for the {@link <%= packageName %>.domain.<%= asEntity(entityClass) %>} entity. This class is used - * in {@link <%= packageName %>.web.rest.<%= entityClass %>Resource} to receive all the possible filtering options from - * the Http GET request parameters. - * For example the following could be a valid request: - * {@code /<%= entityApiUrl %>?id.greaterThan=5&attr1.contains=something&attr2.specified=false} - * As Spring is unable to properly convert the types, unless specific {@link Filter} class are used, we need to use - * fix type specific filters. - */ -public class <%= entityClass %>Criteria implements Serializable, Criteria { -<%_ Object.keys(extraFilters).forEach((key) => { - extraFilter = extraFilters[key]; _%> - /** - * Class for filtering <%= key %> - */ - public static class <%= extraFilter.type %> extends <%- extraFilter.superType %> { - - public <%= extraFilter.type %>() { - } - - public <%= extraFilter.type %>(<%= extraFilter.type %> filter) { - super(filter); - } - - @Override - public <%= extraFilter.type %> copy() { - return new <%= extraFilter.type %>(this); - } - - } -<%_ }); _%> - - private static final long serialVersionUID = 1L; -<%_ filterVariables.forEach((filterVariable) => { _%> - - private <%- filterVariable.filterType %> <%= filterVariable.name %>; -<%_ }); _%> - - public <%= entityClass %>Criteria() { - } - - public <%= entityClass %>Criteria(<%= entityClass %>Criteria other) { -<%_ filterVariables.forEach((filterVariable) => { _%> - this.<%= filterVariable.name %> = other.<%= filterVariable.name %> == null ? null : other.<%= filterVariable.name %>.copy(); -<%_ }); _%> - } - - @Override - public <%= entityClass %>Criteria copy() { - return new <%= entityClass %>Criteria(this); - } - -<%_ filterVariables.forEach((filterVariable) => { _%> - public <%- filterVariable.filterType %> get<%= filterVariable.fieldInJavaBeanMethod %>() { - return <%= filterVariable.name %>; - } - - public void set<%= filterVariable.fieldInJavaBeanMethod %>(<%- filterVariable.filterType %> <%= filterVariable.name %>) { - this.<%= filterVariable.name %> = <%= filterVariable.name %>; - } - -<%_ }); _%> - - @Override - public boolean equals(Object o) { - if (this == o) { - return true; - } - if (o == null || getClass() != o.getClass()) { - return false; - } - final <%= entityClass %>Criteria that = (<%= entityClass %>Criteria) o; - return -<%_ filterVariables.forEach((filterVariable, index) => { _%> - <%_ if (filterVariables.length === index + 1) { _%> - Objects.equals(<%= filterVariable.name %>, that.<%= filterVariable.name %>); - <%_ } else { _%> - Objects.equals(<%= filterVariable.name %>, that.<%= filterVariable.name %>) && - <%_ } _%> -<%_ }); _%> - } - - @Override - public int hashCode() { - return Objects.hash( -<%_ filterVariables.forEach((filterVariable, index) => { _%> - <%_ if (filterVariables.length === (index + 1)) { _%> - <%= filterVariable.name %> - <%_ } else { _%> - <%= filterVariable.name %>, - <%_ } _%> -<%_ }); _%> - ); - } - - @Override - public String toString() { - return "<%= entityClass %>Criteria{" + -<%_ filterVariables.forEach((field) => { _%> - (<%= field.name %> != null ? "<%= field.name %>=" + <%= field.name %> + ", " : "") + -<%_ }); _%> - "}"; - } - -} diff --git a/generators/entity-server/templates_back/src/main/java/package/service/dto/EntityDTO.java.ejs b/generators/entity-server/templates_back/src/main/java/package/service/dto/EntityDTO.java.ejs deleted file mode 100644 index ec0e15dd..00000000 --- a/generators/entity-server/templates_back/src/main/java/package/service/dto/EntityDTO.java.ejs +++ /dev/null @@ -1,273 +0,0 @@ -<%# - Copyright 2019-2023 the original author or authors from the JHipster project. - - This file is part of the JHipster project, see https://www.jhipster.tech/ - for more information. - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. --%> -package <%= packageName %>.service.dto; - -import io.micronaut.core.annotation.Introspected; -<%_ -_%> -<%_ if (typeof javadoc != 'undefined' || importApiModelProperty) { _%> -import io.swagger.v3.oas.annotations.media.Schema; -<%_ } _%> -<%_ if (fieldsContainInstant) { _%> -import java.time.Instant; -<%_ } _%> -<%_ if (fieldsContainLocalDate) { _%> -import java.time.LocalDate; -<%_ } _%> -<%_ if (fieldsContainZonedDateTime) { _%> -import java.time.ZonedDateTime; -<%_ } _%> -<%_ if (fieldsContainDuration) { _%> -import java.time.Duration; -<%_ } _%> -<%_ if (validation) { _%> -import javax.validation.constraints.*; -<%_ } _%> -import java.io.Serializable; -<%_ if (fieldsContainBigDecimal) { _%> -import java.math.BigDecimal; -<%_ } _%> -<%_ if (fieldsContainBlob && databaseType === 'cassandra') { _%> -import java.nio.ByteBuffer; -<%_ } _%> -<%_ if (fieldsContainOwnerManyToMany) { _%> -import java.util.HashSet; -import java.util.Set; -<%_ } _%> -import java.util.Objects; -<%_ if (databaseType === 'cassandra' || fieldsContainUUID === true) { _%> -import java.util.UUID; -<%_ } _%> -<%_ if (fieldsContainBlob && databaseType === 'sql') { _%> -import javax.persistence.Lob; -<%_ } _%> -<%_ Object.keys(uniqueEnums).forEach(function(element) { _%> -import <%= packageName %>.domain.enumeration.<%= element %>; -<%_ }); _%> - -/** - * A DTO for the {@link <%= packageName %>.domain.<%= asEntity(entityClass) %>} entity. - */ -<%_ if (typeof javadoc !== 'undefined') { _%> -@Schema(description = "<%- formatAsApiDescription(javadoc) %>") -<%_ } _%> -@Introspected -public class <%= asDto(entityClass) %> implements Serializable { - - private <%= primaryKey.type %> id; - - <%_ for (idx in fields) { - if (typeof fields[idx].javadoc !== 'undefined') { _%> -<%- formatAsFieldJavadoc(fields[idx].javadoc) %> - <%_ } - let required = false; - const fieldValidate = fields[idx].fieldValidate; - const fieldValidateRules = fields[idx].fieldValidateRules; - const fieldValidateRulesMinlength = fields[idx].fieldValidateRulesMinlength; - const fieldValidateRulesMaxlength = fields[idx].fieldValidateRulesMaxlength; - const fieldValidateRulesMinbytes = fields[idx].fieldValidateRulesMinbytes; - const fieldValidateRulesMaxbytes = fields[idx].fieldValidateRulesMaxbytes; - const fieldValidateRulesMin = fields[idx].fieldValidateRulesMin; - const fieldValidateRulesMax = fields[idx].fieldValidateRulesMax; - const fieldValidateRulesPatternJava = fields[idx].fieldValidateRulesPatternJava; - const fieldType = fields[idx].fieldType; - const fieldTypeBlobContent = fields[idx].fieldTypeBlobContent; - const fieldName = fields[idx].fieldName; _%> - <%_ if (fieldValidate === true) { - if (fieldValidateRules.includes('required')) { - required = true; - } _%> - <%- include('../../common/field_validators') -%> - <%_ } _%> - <%_ if (typeof fields[idx].javadoc != 'undefined') { _%> - @Schema(description = "<%- formatAsApiDescription(fields[idx].javadoc) %>"<% if (required) { %>, required = true<% } %>) - <%_ } _%> - <%_ if (fieldType === 'byte[]' && databaseType === 'sql') { _%> - @Lob - <%_ } _%> - <%_ if (fieldTypeBlobContent !== 'text') { _%> - private <%= fieldType %> <%= fieldName %>; - <%_ } else { _%> - private String <%= fieldName %>; - <%_ } _%> - - <%_ if ((fieldType === 'byte[]' || fieldType === 'ByteBuffer') && fieldTypeBlobContent !== 'text') { _%> - private String <%= fieldName %>ContentType; - <%_ } _%> - <%_ } _%> - <%_ for (idx in relationships) { - const otherEntityRelationshipName = relationships[idx].otherEntityRelationshipName; - const relationshipFieldName = relationships[idx].relationshipFieldName; - const relationshipFieldNamePlural = relationships[idx].relationshipFieldNamePlural; - const relationshipType = relationships[idx].relationshipType; - const otherEntityName = relationships[idx].otherEntityName; - const otherEntityNameCapitalized = relationships[idx].otherEntityNameCapitalized; - const otherEntityFieldCapitalized = relationships[idx].otherEntityFieldCapitalized; - const ownerSide = relationships[idx].ownerSide; - if (typeof relationships[idx].javadoc != 'undefined') { _%> -<%- formatAsFieldJavadoc(relationships[idx].javadoc) %> - @Schema(description = "<%- formatAsApiDescription(relationships[idx].javadoc) %>") - <%_ } - if (relationshipType === 'many-to-many' && ownerSide === true) { _%> - - private Set<<%= asDto(otherEntityNameCapitalized) %>> <%= relationshipFieldNamePlural %> = new HashSet<>(); - <%_ } else if (relationshipType === 'many-to-one' || (relationshipType === 'one-to-one' && ownerSide === true)) { _%> - - private <% if (otherEntityName === 'user' && authenticationType === 'oauth2') { %>String<% } else { %><%= primaryKey.type %><% } %> <%= relationshipFieldName %>Id; - <%_ if (otherEntityFieldCapitalized !== 'Id' && otherEntityFieldCapitalized !== '') { _%> - - private String <%= relationshipFieldName %><%= otherEntityFieldCapitalized %>; - <%_ } } } _%> - - public <%= primaryKey.type %> getId() { - return id; - } - - public void setId(<%= primaryKey.type %> id) { - this.id = id; - } - <%_ for (idx in fields) { - const fieldType = fields[idx].fieldType; - const fieldTypeBlobContent = fields[idx].fieldTypeBlobContent; - const fieldInJavaBeanMethod = fields[idx].fieldInJavaBeanMethod; - const fieldName = fields[idx].fieldName; _%> - <%_ if (fieldTypeBlobContent !== 'text') { _%> - - public <%= fieldType %> <% if (fieldType.toLowerCase() === 'boolean') { %>is<% } else { %>get<%_ } _%><%= fieldInJavaBeanMethod %>() { - <%_ } else { _%> - - public String get<%= fieldInJavaBeanMethod %>() { - <%_ } _%> - return <%= fieldName %>; - } - - <%_ if (fieldTypeBlobContent !== 'text') { _%> - public void set<%= fieldInJavaBeanMethod %>(<%= fieldType %> <%= fieldName %>) { - <%_ } else { _%> - public void set<%= fieldInJavaBeanMethod %>(String <%= fieldName %>) { - <%_ } _%> - this.<%= fieldName %> = <%= fieldName %>; - } - <%_ if ((fieldType === 'byte[]' || fieldType === 'ByteBuffer') && fieldTypeBlobContent !== 'text') { _%> - - public String get<%= fieldInJavaBeanMethod %>ContentType() { - return <%= fieldName %>ContentType; - } - - public void set<%= fieldInJavaBeanMethod %>ContentType(String <%= fieldName %>ContentType) { - this.<%= fieldName %>ContentType = <%= fieldName %>ContentType; - } - <%_ } _%> - <%_ } _%> - <%_ for (idx in relationships) { - relationshipFieldName = relationships[idx].relationshipFieldName, - relationshipFieldNamePlural = relationships[idx].relationshipFieldNamePlural, - otherEntityName = relationships[idx].otherEntityName, - otherEntityNamePlural = relationships[idx].otherEntityNamePlural, - relationshipType = relationships[idx].relationshipType, - otherEntityNameCapitalized = relationships[idx].otherEntityNameCapitalized, - otherEntityFieldCapitalized = relationships[idx].otherEntityFieldCapitalized, - relationshipNameCapitalized = relationships[idx].relationshipNameCapitalized, - relationshipNameCapitalizedPlural = relationships[idx].relationshipNameCapitalizedPlural, - ownerSide = relationships[idx].ownerSide; - if (relationshipType === 'many-to-many' && ownerSide === true) { _%> - - public Set<<%= asDto(otherEntityNameCapitalized) %>> get<%= relationshipNameCapitalizedPlural %>() { - return <%= relationshipFieldNamePlural %>; - } - - public void set<%= relationshipNameCapitalizedPlural %>(Set<<%= asDto(otherEntityNameCapitalized) %>> <%= otherEntityNamePlural %>) { - this.<%= relationshipFieldNamePlural %> = <%= otherEntityNamePlural %>; - } - <%_ } else if (relationshipType === 'many-to-one' || (relationshipType === 'one-to-one' && ownerSide === true)) { _%> - - <%_ if (relationshipNameCapitalized.length > 1) { _%> - public <% if (otherEntityName === 'user' && authenticationType === 'oauth2') { %>String<% } else { %><%= primaryKey.type %><% } %> get<%= relationshipNameCapitalized %>Id() { - return <%= relationshipFieldName %>Id; - } - - public void set<%= relationshipNameCapitalized %>Id(<% if (otherEntityName === 'user' && authenticationType === 'oauth2') { %>String<% } else { %><%= primaryKey.type %><% } %> <%= otherEntityName %>Id) { - this.<%= relationshipFieldName %>Id = <%= otherEntityName %>Id; - } - <%_ } else { // special case when the entity name has one character _%> - public <%= primaryKey.type %> get<%= relationshipNameCapitalized.toLowerCase() %>Id() { - return <%= relationshipFieldName %>Id; - } - - public void set<%= relationshipNameCapitalized.toLowerCase() %>Id(<%= primaryKey.type %> <%= otherEntityName %>Id) { - this.<%= relationshipFieldName %>Id = <%= otherEntityName %>Id; - } - <%_ } _%> - <%_ if (otherEntityFieldCapitalized !== 'Id' && otherEntityFieldCapitalized !== '') { _%> - - public String get<%= relationshipNameCapitalized %><%= otherEntityFieldCapitalized %>() { - return <%= relationshipFieldName %><%= otherEntityFieldCapitalized %>; - } - - public void set<%= relationshipNameCapitalized %><%= otherEntityFieldCapitalized %>(String <%= otherEntityName %><%= otherEntityFieldCapitalized %>) { - this.<%= relationshipFieldName %><%= otherEntityFieldCapitalized %> = <%= otherEntityName %><%= otherEntityFieldCapitalized %>; - } - <%_ } } } _%> - - @Override - public boolean equals(Object o) { - if (this == o) { - return true; - } - if (o == null || getClass() != o.getClass()) { - return false; - } - - <%= asDto(entityClass) %> <%= asDto(entityInstance) %> = (<%= asDto(entityClass) %>) o; - if (<%= asDto(entityInstance) %>.getId() == null || getId() == null) { - return false; - } - return Objects.equals(getId(), <%= asDto(entityInstance) %>.getId()); - } - - @Override - public int hashCode() { - return Objects.hashCode(getId()); - } - - @Override - public String toString() { - return "<%= asDto(entityClass) %>{" + - "id=" + getId() + - <%_ for (idx in fields) { - const fieldName = fields[idx].fieldName; - const fieldType = fields[idx].fieldType; - const isNumeric = ['integer', 'long', 'float', 'double', 'bigdecimal'].includes(fieldType.toLowerCase()); _%> - ", <%= fieldName %>=<% if (! isNumeric) { %>'<% } %>" + <% if (fieldType.toLowerCase() === 'boolean') { %>is<% } else { %>get<% } %><%= fields[idx].fieldInJavaBeanMethod %>() <% if (! isNumeric) { %>+ "'" <% } %>+ - <%_ } _%> - <%_ for (idx in relationships) { - const relationshipFieldName = relationships[idx].relationshipFieldName; - const relationshipType = relationships[idx].relationshipType; - const relationshipNameCapitalized = relationships[idx].relationshipNameCapitalized; - const otherEntityName = relationships[idx].otherEntityName; - const otherEntityFieldCapitalized = relationships[idx].otherEntityFieldCapitalized; - const ownerSide = relationships[idx].ownerSide; _%> - <%_ if (relationshipType === 'many-to-one' || (relationshipType === 'one-to-one' && ownerSide === true)) { _%> - ", <%= relationshipFieldName %>Id=<% if (otherEntityName === 'user' && authenticationType === 'oauth2') { %>'<% } %>" + get<%= relationshipNameCapitalized %>Id() <% if (otherEntityName === 'user' && authenticationType === 'oauth2') { %>+ "'" <% } %>+ - <%_ if (otherEntityFieldCapitalized !== 'Id' && otherEntityFieldCapitalized !== '') { _%> - ", <%= relationshipFieldName %><%= otherEntityFieldCapitalized %>='" + get<%= relationshipNameCapitalized %><%= otherEntityFieldCapitalized %>() + "'" + - <%_ } } } _%> - "}"; - } -} diff --git a/generators/entity-server/templates_back/src/main/java/package/service/mapper/BaseEntityMapper.java.ejs b/generators/entity-server/templates_back/src/main/java/package/service/mapper/BaseEntityMapper.java.ejs deleted file mode 100644 index 49a75184..00000000 --- a/generators/entity-server/templates_back/src/main/java/package/service/mapper/BaseEntityMapper.java.ejs +++ /dev/null @@ -1,39 +0,0 @@ -<%# - Copyright 2019-2023 the original author or authors from the JHipster project. - - This file is part of the JHipster project, see https://www.jhipster.tech/ - for more information. - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. --%> -package <%= packageName %>.service.mapper; - -import java.util.List; - -/** - * Contract for a generic dto to entity mapper. - * - * @param - DTO type parameter. - * @param - Entity type parameter. - */ - -public interface EntityMapper { - - E toEntity(D dto); - - D toDto(E entity); - - List toEntity(List dtoList); - - List toDto(List entityList); -} diff --git a/generators/entity-server/templates_back/src/main/java/package/service/mapper/EntityMapper.java.ejs b/generators/entity-server/templates_back/src/main/java/package/service/mapper/EntityMapper.java.ejs deleted file mode 100644 index df3602e9..00000000 --- a/generators/entity-server/templates_back/src/main/java/package/service/mapper/EntityMapper.java.ejs +++ /dev/null @@ -1,137 +0,0 @@ -<%# - Copyright 2019-2023 the original author or authors from the JHipster project. - - This file is part of the JHipster project, see https://www.jhipster.tech/ - for more information. - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. --%> -package <%= packageName %>.service.mapper; - -<%_ -let existingMappings = []; -let uuidMapMethod = false; -let byteMapMethod = false; -for (idx in relationships) { - if ((relationships[idx].relationshipType === 'many-to-many' && relationships[idx].ownerSide === true) || relationships[idx].relationshipType === 'many-to-one' || (relationships[idx].relationshipType === 'one-to-one' && relationships[idx].ownerSide === true)) { - // if the entity is mapped twice, we should implement the mapping once - if (!existingMappings.includes(relationships[idx].otherEntityNameCapitalized) && asEntity(relationships[idx].otherEntityNameCapitalized) !== asEntity(entityClass)) { - existingMappings.push(relationships[idx].otherEntityNameCapitalized); - } - let otherEntity = getExistingEntities().find(e => e.name === relationships[idx].otherEntityNameCapitalized); - if (otherEntity) { - let otherEntityField = otherEntity.definition.fields.find(f => f.fieldName === relationships[idx].otherEntityField); - if (otherEntityField) { - if (otherEntityField.fieldType === 'UUID') { - uuidMapMethod = true; - } - if (otherEntityField.fieldType === 'byte[]') { - byteMapMethod = true; - } - } - } - } -} -_%> - -import <%= packageName %>.domain.*; -import <%= packageName %>.service.dto.<%= asDto(entityClass) %>; - -import org.mapstruct.*; -<%_ if (uuidMapMethod) { _%> - -import java.util.Objects; -import java.util.UUID; -<%_ } _%> - -/** - * Mapper for the entity {@link <%= asEntity(entityClass) %>} and its DTO {@link <%= asDto(entityClass) %>}. - */ -@Mapper(componentModel = "jsr330", uses = {<%= existingMappings.map(otherEntityNameCapitalized => otherEntityNameCapitalized + 'Mapper.class').join(', ') %>}) -public interface <%= entityClass %>Mapper extends EntityMapper<<%= asDto(entityClass) %>, <%= asEntity(entityClass) %>> { - -<%_ -// entity -> DTO mapping -var renMapAnotEnt = false; //Render Mapping Annotation during Entity to DTO conversion? -for (idx in relationships) { - const relationshipType = relationships[idx].relationshipType; - const relationshipName = relationships[idx].relationshipName; - const ownerSide = relationships[idx].ownerSide; - if (relationshipType === 'many-to-one' || (relationshipType === 'one-to-one' && ownerSide === true)) { - renMapAnotEnt = true; -_%> - @Mapping(source = "<%= relationshipName %>.id", target = "<%= relationships[idx].relationshipFieldName %>Id") - <%_ if (relationships[idx].otherEntityFieldCapitalized !='Id' && relationships[idx].otherEntityFieldCapitalized !== '') { _%> - @Mapping(source = "<%= relationshipName %>.<%= relationships[idx].otherEntityField %>", target = "<%= relationships[idx].relationshipFieldName %><%= relationships[idx].otherEntityFieldCapitalized %>") - <%_ } _%> - <%_ } _%> - <%_ } _%> - <%_ if (renMapAnotEnt === true) { _%> - <%= asDto(entityClass) %> toDto(<%= asEntity(entityClass) %> <%= asEntity(entityInstance) %>); - <%_ } _%> - -<%_ -// DTO -> entity mapping -var renMapAnotDto = false; //Render Mapping Annotation during DTO to Entity conversion? -// var hasOAuthUser = false; // if OAuthUser, use a String id in fromId() method -for (idx in relationships) { - const relationshipType = relationships[idx].relationshipType; - const relationshipName = relationships[idx].relationshipName; - const otherEntityName = relationships[idx].otherEntityName; - const relationshipNamePlural = relationships[idx].relationshipNamePlural; - const relationshipNameCapitalized = relationships[idx].relationshipNameCapitalized; - const ownerSide = relationships[idx].ownerSide; - const isUsingMapsId = relationships[idx].useJPADerivedIdentifier; - primaryKey.type = (isUsingMapsId === true && otherEntityName === 'user' && authenticationType === 'oauth2') ? 'String' : primaryKey.type; - if (relationshipType === 'many-to-one' || (relationshipType === 'one-to-one' && ownerSide === true)) { - renMapAnotDto = true; -_%> - @Mapping(source = "<%= relationshipName %>Id", target = "<%= relationshipName %>") - <%_ } else if (relationshipType === 'many-to-many' && ownerSide === false) { renMapAnotDto = true; _%> - @Mapping(target = "<%= relationshipNamePlural %>", ignore = true) - <%_ } else if (relationshipType === 'one-to-many') { renMapAnotDto = true; _%> - @Mapping(target = "<%= relationshipNamePlural %>", ignore = true) - <%_ } else if (relationshipType === 'one-to-one' && ownerSide === false) { renMapAnotDto = true; _%> - @Mapping(target = "<%= relationshipName %>", ignore = true) - <%_ } - if ((relationshipType === 'one-to-many' || relationshipType === 'many-to-many') && fluentMethods) { _%> - @Mapping(target = "remove<%= relationshipNameCapitalized %>", ignore = true) - <%_ } _%> - <%_ } _%> - <%_ if (renMapAnotDto === true) { _%> - <%= asEntity(entityClass) %> toEntity(<%= asDto(entityClass) %> <%= asDto(entityInstance) %>); - <%_ } _%> - <%_ if (databaseType === 'sql' || databaseType === 'mongodb' || databaseType === 'couchbase') { _%> - - default <%= asEntity(entityClass) %> fromId(<%= primaryKey.type %> id) { - if (id == null) { - return null; - } - <%= asEntity(entityClass) %> <%= asEntity(entityInstance) %> = new <%= asEntity(entityClass) %>(); - <%= asEntity(entityInstance) %>.setId(id); - return <%= asEntity(entityInstance) %>; - } -<%_ } _%> - <%_ if (uuidMapMethod) { _%> - - default String map(UUID value) { - return Objects.toString(value, null); - } - <%_ } _%> - <%_ if (byteMapMethod) { _%> - - default String map(byte[] value) { - return new String(value); - } - <%_ } _%> -} diff --git a/generators/entity-server/templates_back/src/test/java/package/domain/EntityTest.java.ejs b/generators/entity-server/templates_back/src/test/java/package/domain/EntityTest.java.ejs deleted file mode 100644 index dee6ae89..00000000 --- a/generators/entity-server/templates_back/src/test/java/package/domain/EntityTest.java.ejs +++ /dev/null @@ -1,53 +0,0 @@ -<%# - Copyright 2019-2023 the original author or authors from the JHipster project. - - This file is part of the JHipster project, see https://www.jhipster.tech/ - for more information. - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. --%> -package <%= packageName %>.domain; - -import org.junit.jupiter.api.Test; -import static org.assertj.core.api.Assertions.assertThat; -import <%= packageName %>.web.rest.TestUtil; -<%_ -let hasOauthUser = false; -for (idx in relationships) { - isUsingMapsId = relationships[idx].useJPADerivedIdentifier; - if (isUsingMapsId === true) { - hasOauthUser = relationships[idx].otherEntityName === 'user' && authenticationType === 'oauth2'; - break; - } -} -_%> -<%_ if (databaseType === 'cassandra' || (databaseType === 'sql' && hasOauthUser === true)) { _%> -import java.util.UUID; -<%_ } _%> - -public class <%= entityClass %>Test { - - @Test - public void equalsVerifier() throws Exception { - TestUtil.equalsVerifier(<%= asEntity(entityClass) %>.class); - <%= asEntity(entityClass) %> <%= asEntity(entityInstance) %>1 = new <%= asEntity(entityClass) %>(); - <%= asEntity(entityInstance) %>1.setId(<% if (databaseType === 'sql' && hasOauthUser === true) { %>UUID.randomUUID().toString()<% } else if (databaseType === 'sql') { %>1L<% } else if (databaseType === 'mongodb' || databaseType === 'couchbase') { %>"id1"<% } else if (databaseType === 'cassandra') { %>UUID.randomUUID()<% } %>); - <%= asEntity(entityClass) %> <%= asEntity(entityInstance) %>2 = new <%= asEntity(entityClass) %>(); - <%= asEntity(entityInstance) %>2.setId(<%= asEntity(entityInstance) %>1.getId()); - assertThat(<%= asEntity(entityInstance) %>1).isEqualTo(<%= asEntity(entityInstance) %>2); - <%= asEntity(entityInstance) %>2.setId(<% if (databaseType === 'sql' && hasOauthUser === true) { %>UUID.randomUUID().toString()<% } else if (databaseType === 'sql') { %>2L<% } else if (databaseType === 'mongodb' || databaseType === 'couchbase') { %>"id2"<% } else if (databaseType === 'cassandra') { %>UUID.randomUUID()<% } %>); - assertThat(<%= asEntity(entityInstance) %>1).isNotEqualTo(<%= asEntity(entityInstance) %>2); - <%= asEntity(entityInstance) %>1.setId(null); - assertThat(<%= asEntity(entityInstance) %>1).isNotEqualTo(<%= asEntity(entityInstance) %>2); - } -} diff --git a/generators/entity-server/templates_back/src/test/java/package/service/dto/EntityDTOTest.java.ejs b/generators/entity-server/templates_back/src/test/java/package/service/dto/EntityDTOTest.java.ejs deleted file mode 100644 index a791c246..00000000 --- a/generators/entity-server/templates_back/src/test/java/package/service/dto/EntityDTOTest.java.ejs +++ /dev/null @@ -1,48 +0,0 @@ -<%# - Copyright 2019-2023 the original author or authors from the JHipster project. - - This file is part of the JHipster project, see https://www.jhipster.tech/ - for more information. - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. --%> -package <%= packageName %>.service.dto; - -import org.junit.jupiter.api.Test; -import static org.assertj.core.api.Assertions.assertThat; -import <%= packageName %>.web.rest.TestUtil; -<%_ -let id1 = getPrimaryKeyValue(primaryKey.type, databaseType, '1'); -let id2 = getPrimaryKeyValue(primaryKey.type, databaseType, '2'); -_%> -<%_ if (id1.includes('UUID')) { _%> -import java.util.UUID; -<%_ } _%> - -public class <%= asDto(entityClass) %>Test { - - @Test - public void dtoEqualsVerifier() throws Exception { - TestUtil.equalsVerifier(<%= asDto(entityClass) %>.class); - <%= asDto(entityClass) %> <%= asDto(entityInstance) %>1 = new <%= asDto(entityClass) %>(); - <%= asDto(entityInstance) %>1.setId(<%- id1 %>); - <%= asDto(entityClass) %> <%= asDto(entityInstance) %>2 = new <%= asDto(entityClass) %>(); - assertThat(<%= asDto(entityInstance) %>1).isNotEqualTo(<%= asDto(entityInstance) %>2); - <%= asDto(entityInstance) %>2.setId(<%= asDto(entityInstance) %>1.getId()); - assertThat(<%= asDto(entityInstance) %>1).isEqualTo(<%= asDto(entityInstance) %>2); - <%= asDto(entityInstance) %>2.setId(<%- id2 %>); - assertThat(<%= asDto(entityInstance) %>1).isNotEqualTo(<%= asDto(entityInstance) %>2); - <%= asDto(entityInstance) %>1.setId(null); - assertThat(<%= asDto(entityInstance) %>1).isNotEqualTo(<%= asDto(entityInstance) %>2); - } -} diff --git a/generators/entity-server/templates_back/src/test/java/package/service/mapper/EntityMapperTest.java.ejs b/generators/entity-server/templates_back/src/test/java/package/service/mapper/EntityMapperTest.java.ejs deleted file mode 100644 index 0bf10db6..00000000 --- a/generators/entity-server/templates_back/src/test/java/package/service/mapper/EntityMapperTest.java.ejs +++ /dev/null @@ -1,46 +0,0 @@ -<%# - Copyright 2019-2023 the original author or authors from the JHipster project. - - This file is part of the JHipster project, see https://www.jhipster.tech/ - for more information. - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. --%> -package <%= packageName %>.service.mapper; - -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; -import static org.assertj.core.api.Assertions.assertThat; -<%_ -let id = getPrimaryKeyValue(primaryKey.type, databaseType, '1'); -_%> -<%_ if (id.includes('UUID')) { _%> -import java.util.UUID; -<%_ } _%> - -public class <%= entityClass %>MapperTest { - - private <%= entityClass %>Mapper <%= entityInstance %>Mapper; - - @BeforeEach - public void setUp() { - <%= entityInstance %>Mapper = new <%= entityClass %>MapperImpl(); - } - - @Test - public void testEntityFromId() { - <%= primaryKey.type %> id = <%- id %>; - assertThat(<%= entityInstance %>Mapper.fromId(id).getId()).isEqualTo(id); - assertThat(<%= entityInstance %>Mapper.fromId(null)).isNull(); - } -}