Skip to content

Commit

Permalink
adjusts
Browse files Browse the repository at this point in the history
  • Loading branch information
mshima committed Jan 26, 2024
1 parent 3a51841 commit d3e72bf
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 25 deletions.
3 changes: 3 additions & 0 deletions generators/base-application/support/prepare-entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,9 @@ export function prepareEntityPrimaryKeyForTemplates(
get fieldName() {
return idCount === 1 ? field.fieldName : `${relationship.relationshipName}${field.fieldNameCapitalized}`;
},
get fieldType() {
return field.fieldType;
},
get fieldNameCapitalized() {
return idCount === 1
? field.fieldNameCapitalized
Expand Down
2 changes: 1 addition & 1 deletion generators/java/generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ export default class JavaGenerator extends BaseApplicationGenerator<GeneratorDef
return this.asPreparingEachEntityFieldTaskGroup({
prepareEntity({ entity, field }) {
field.propertyJavaBeanName = javaBeanCase(field.propertyName);
if (entity.dtoMapstruct) {
if (entity.dtoMapstruct || entity.builtIn) {
field.propertyDtoJavaType = field.blobContentTypeText ? 'String' : field.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.
-%>
package <%= entityAbsolutePackage %>.service.dto;
package <%- entityAbsolutePackage %>.service.dto;
import java.util.Objects;
<%_ if (entityApiDescription || importApiModelProperty) { _%>
Expand Down Expand Up @@ -55,21 +55,21 @@ import java.util.UUID;
import jakarta.persistence.Lob;
<%_ } _%>
<%_ Object.keys(uniqueEnums).forEach(function(element) { _%>
import <%= entityAbsolutePackage %>.domain.enumeration.<%= element %>;
import <%- entityAbsolutePackage %>.domain.enumeration.<%- element %>;
<%_ }); _%>
<%_ for (const otherEntity of otherEntities.filter(otherEntity => otherEntity.entityPackage !== entityPackage)) { _%>
import <%= `${otherEntity.entityAbsolutePackage}.service.dto.${otherEntity.dtoClass}` %>;
import <%- `${otherEntity.entityAbsolutePackage}.service.dto.${otherEntity.dtoClass}` %>;
<%_ } _%>
/**
* A DTO for the {@link <%= entityAbsolutePackage %>.domain.<%= persistClass %>} entity.
* A DTO for the {@link <%- entityAbsolutePackage %>.domain.<%- persistClass %>} entity.
*/
<%_ if (entityApiDescription) { _%>
@Schema(description = "<%- entityApiDescription %>")
<%_ } _%>
@SuppressWarnings("common-java:DuplicatedBlocks")
public class <%= dtoClass %> implements Serializable {
public class <%- dtoClass %> implements Serializable {
<%_ for (property of restProperties) {
if (typeof property.propertyJavadoc) {
Expand All @@ -90,34 +90,30 @@ _%>
<%_ if (property.fieldTypeBytes && databaseTypeSql) { _%>
@Lob
<%_ } _%>
<%_ if (property.collection && relationship) { _%>
private Set<<%= relationship.otherEntity.dtoClass %>> <%= property.propertyName %> = new HashSet<>();
<%_ } else { _%>
private <%= property.propertyDtoJavaType %> <%= property.propertyName %>;
<%_ } _%>
private <%- property.propertyDtoJavaType %> <%- property.propertyName %><% if (property.collection && relationship) { %> = new HashSet<>()<% } %>;
<%_ if (property.fieldWithContentType) { _%>
private String <%= property.propertyName %>ContentType;
private String <%- property.propertyName %>ContentType;
<%_ }
}
_%>
<%_ for (property of restProperties) { _%>
public <%- property.propertyDtoJavaType %> get<%- property.propertyJavaBeanName %>() {
return <%= property.propertyName %>;
return <%- property.propertyName %>;
}
public void set<%- property.propertyJavaBeanName %>(<%- property.propertyDtoJavaType %> <%- property.propertyName %>) %> {
this.<%= property.propertyName %> = <%= property.propertyName %>;
this.<%- property.propertyName %> = <%- property.propertyName %>;
}
<%_ if (property.fieldWithContentType) { _%>
public String get<%= property.propertyJavaBeanName %>ContentType() {
return <%= property.propertyName %>ContentType;
public String get<%- property.propertyJavaBeanName %>ContentType() {
return <%- property.propertyName %>ContentType;
}
public void set<%= property.propertyJavaBeanName %>ContentType(String <%= property.propertyName %>ContentType) {
this.<%= property.propertyName %>ContentType = <%= property.propertyName %>ContentType;
public void set<%- property.propertyJavaBeanName %>ContentType(String <%- property.propertyName %>ContentType) {
this.<%- property.propertyName %>ContentType = <%- property.propertyName %>ContentType;
}
<%_ } _%>
<%_ } _%>
Expand All @@ -128,12 +124,12 @@ _%>
if (this == o) {
return true;
}
if (!(o instanceof <%= dtoClass %>)) {
if (!(o instanceof <%- dtoClass %>)) {
return false;
}
<%_ if (!embedded) { _%>
<%= dtoClass %> <%= dtoInstance %> = (<%= dtoClass %>) o;
<%- dtoClass %> <%- dtoInstance %> = (<%- dtoClass %>) o;
if (<%- idNames.map(n => `this.${n} == null`).join(' && ') %>){
return false;
}
Expand All @@ -155,10 +151,10 @@ _%>
// prettier-ignore
@Override
public String toString() {
return "<%= dtoClass %>{" +
return "<%- dtoClass %>{" +
<%_ for ([idx, property] of restProperties.entries()) {
const isQuoted = property.fieldName && !property.fieldTypeNumeric _%>
"<%= idx === 0 ? '' : ', ' %><%= property.propertyName %>=<% if (isQuoted) { %>'<% } %>" + get<%- property.propertyJavaBeanName %>() <% if (isQuoted) { %>+ "'" <% } %>+
"<%- idx === 0 ? '' : ', ' %><%- property.propertyName %>=<% if (isQuoted) { %>'<% } %>" + get<%- property.propertyJavaBeanName %>() <% if (isQuoted) { %>+ "'" <% } %>+
<%_ } _%>
"}";
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ package <%= entityAbsolutePackage %>.service.mapper;
<%_
const getOriginalField = field => field.originalField || field;
const uuidMapMethod = dtoReferences.some(reference => reference.valueReference && reference.valueReference.field && reference.valueReference.field.fieldTypeUUID);
const byteMapMethod = dtoReferences.some(reference => reference.valueReference && reference.valueReference.field && reference.valueReference.field.fieldTypeBytes);
const dtoRelationships = dtoReferences.filter(reference => reference.relationship && !reference.relationship.otherEntity.embedded).map(reference => reference.relationship);
const uuidMapMethod = restProperties.some(property => property.relatedField?.fieldTypeUUID);
const byteMapMethod = restProperties.some(property => property.relatedField?.fieldTypeBytes);
const dtoRelationships = restProperties.filter(property => property.relationshipName && !relationship.otherEntity.embedded);
let otherEntitiesFields = otherEntities
.filter(otherEntity => dtoRelationships.some(relationship => relationship.otherEntity === otherEntity))
.map(otherEntity =>
Expand Down

0 comments on commit d3e72bf

Please sign in to comment.