Skip to content

Commit

Permalink
JNG-5593 Add support of Create / Update mask support (#26)
Browse files Browse the repository at this point in the history
* JNG-5593 Add Mask support for create / update

* Method definition moved out as fragment

* Add mask as header parameter
  • Loading branch information
robertcsakany authored Mar 8, 2024
1 parent 0d47c75 commit 291e542
Show file tree
Hide file tree
Showing 24 changed files with 752 additions and 296 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,18 @@ public static boolean isQueryOrDefaultValueOrDataPropertyAttribute(TransferAttri
|| isDataProperty(transferAttribute);
}

public static boolean isRequestAttribute(TransferAttribute transferAttribute) {
return (isParametrizedAttribute(transferAttribute)
|| hasQueryWithoutParamAnnotation(transferAttribute)
|| hasDefaultValueAnnotation(transferAttribute))
|| isDefaultValueAttribute(transferAttribute);
}

public static boolean isResponseAttribute(TransferAttribute transferAttribute) {
return (isParametrizedAttribute(transferAttribute)
|| hasDefaultValueAnnotation(transferAttribute))
|| isDefaultValueAttribute(transferAttribute);
}

public static boolean isParametrizedAttribute(TransferAttribute transferAttribute) {
return transferAttribute.getBinding() != null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import java.util.Optional;

import static hu.blackbelt.judo.psm.generator.jaxrs.api.JavaNamespaceHelper.*;
import static hu.blackbelt.judo.psm.generator.jaxrs.api.ObjectTypeHelper.isRangeInputType;

@TemplateHelper
public class JavaApiHelper extends StaticMethodValueResolver {
Expand Down Expand Up @@ -82,6 +83,7 @@ public static String className(NamedElement namedElement) {
return StringUtils.capitalize(safeName(namedElement.getName()));
}


public static String firstToLower(String input) {
return StringUtils.uncapitalize(safeName(input));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,10 @@ public static String classifierAsmFqName(TransferObjectType transferObjectType)
return fqName(transferObjectType.getNamespace(), ".", false) + '.' + transferObjectType.getName();
}

public static String logicalFullName(TransferObjectType transferObjectType) {
return Arrays.stream(classifierAsmFqName(transferObjectType).split("\\.")).map(s -> StringUtils.capitalize(s)).collect(Collectors.joining());
}

public static String attributeAsmFqName(TransferAttribute transferAttribute) {
TransferObjectType transferObjectType = (TransferObjectType) transferAttribute.eContainer();
NamedElement namedElement = transferObjectType;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,22 @@
* #L%
*/

import com.github.jknack.handlebars.internal.lang3.StringUtils;
import hu.blackbelt.judo.generator.commons.StaticMethodValueResolver;
import hu.blackbelt.judo.generator.commons.annotations.TemplateHelper;
import hu.blackbelt.judo.meta.psm.accesspoint.AbstractActorType;
import hu.blackbelt.judo.meta.psm.data.EntityType;
import hu.blackbelt.judo.meta.psm.namespace.Model;
import hu.blackbelt.judo.meta.psm.namespace.NamedElement;
import hu.blackbelt.judo.meta.psm.service.*;
import hu.blackbelt.judo.psm.generator.jaxrs.api.OperationHelper;

import java.util.HashSet;
import java.util.Map;
import java.util.Set;

import static hu.blackbelt.judo.psm.generator.jaxrs.api.JavaNamespaceHelper.logicalFullName;
import static hu.blackbelt.judo.psm.generator.jaxrs.api.JavaNamespaceHelper.safeName;
import static hu.blackbelt.judo.psm.generator.jaxrs.api.ModelHelper.*;

@TemplateHelper
Expand Down Expand Up @@ -83,4 +87,66 @@ public static boolean isRangeInputType(TransferObjectType transferObjectType) {
&& o.getInput().getType().equals(transferObjectType)
);
}

public static String classNameForCreateRequestPostfix(TransferObjectType transferObjectType) {
if (!transferObjectType.isQueryCustomizer() && !isRangeInputType(transferObjectType)) {
return "CreateRequest";
} else if (!transferObjectType.isQueryCustomizer()) {
return "Request";
}
return "";
}

public static String classNameForRangeRequestPostfix(TransferObjectType transferObjectType) {
if (!transferObjectType.isQueryCustomizer()) {
return "RangeRequest";
} else if (transferObjectType.isQueryCustomizer()) {
return "Request";
}
return "";
}

public static String classNameForRequestPostfix(TransferObjectType transferObjectType) {
if (!transferObjectType.isQueryCustomizer()) {
return "Request";
}
return "";
}

public static String classNameForResponsePostfix(TransferObjectType transferObjectType) {
return "Response";
}

public static String classNameForCreateRequest(TransferObjectType transferObjectType) {
return StringUtils.capitalize(safeName(transferObjectType.getName()) + classNameForCreateRequestPostfix(transferObjectType));
}

public static String classNameForRangeRequest(TransferObjectType transferObjectType) {
return StringUtils.capitalize(safeName(transferObjectType.getName() + classNameForRangeRequestPostfix(transferObjectType)));
}

public static String classNameForRequest(TransferObjectType transferObjectType) {
return StringUtils.capitalize(safeName(transferObjectType.getName() + classNameForRequestPostfix(transferObjectType)));
}

public static String classNameForResponse(TransferObjectType transferObjectType) {
return StringUtils.capitalize(safeName(transferObjectType.getName() + classNameForResponsePostfix(transferObjectType)));
}

public static String classNameLogicalFullNameForRangeRequest(TransferObjectType transferObjectType) {
return logicalFullName(transferObjectType) + classNameForRangeRequestPostfix(transferObjectType);
}

public static String classNameLogicalFullNameForRequest(TransferObjectType transferObjectType) {
return logicalFullName(transferObjectType) + classNameForRequestPostfix(transferObjectType);
}

public static String classNameLogicalFullNameForCreateRequest(TransferObjectType transferObjectType) {
return logicalFullName(transferObjectType) + classNameForCreateRequestPostfix(transferObjectType);
}

public static String classNameLogicalFullNameForResponse(TransferObjectType transferObjectType) {
return logicalFullName(transferObjectType) + classNameForResponsePostfix(transferObjectType);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
*/


import com.github.jknack.handlebars.internal.lang3.StringUtils;
import hu.blackbelt.judo.generator.commons.StaticMethodValueResolver;
import hu.blackbelt.judo.generator.commons.annotations.TemplateHelper;

Expand All @@ -32,10 +33,12 @@
import hu.blackbelt.judo.meta.psm.namespace.Namespace;
import hu.blackbelt.judo.meta.psm.service.*;

import static hu.blackbelt.judo.psm.generator.jaxrs.api.JavaApiHelper.className;
import static hu.blackbelt.judo.psm.generator.jaxrs.api.JavaApiHelper.namedElementApiParentPath;
import java.util.Arrays;
import java.util.stream.Collectors;

import static hu.blackbelt.judo.psm.generator.jaxrs.api.JavaApiHelper.*;
import static hu.blackbelt.judo.psm.generator.jaxrs.api.JavaNamespaceHelper.*;
import static hu.blackbelt.judo.psm.generator.jaxrs.api.ObjectTypeHelper.getEntity;
import static hu.blackbelt.judo.psm.generator.jaxrs.api.ObjectTypeHelper.*;

@TemplateHelper
public class OperationHelper extends StaticMethodValueResolver {
Expand Down Expand Up @@ -174,9 +177,26 @@ public static Boolean operationOutputTypeDefined(TransferOperation transferOpera
return transferOperation.getOutput().getType() != null;
}

public static String getOperationInputFQName(TransferOperation transferOperation) {
public static String getOperationInputFQNameForCreateRequest(TransferOperation transferOperation) {
TransferObjectType transferObjectType = transferOperation.getInput().getType();
String className = className(transferObjectType);
String className = classNameForCreateRequest(transferObjectType);
String fqName = namedElementApiParentPath(transferObjectType) + "." + className;
return fqName.replaceAll("/", ".");
}

public static String getOperationInputFQNameForRequest(TransferOperation transferOperation) {
if (transferOperation.getBehaviour() != null && transferOperation.getBehaviour().getBehaviourType().equals(TransferOperationBehaviourType.GET_RANGE)) {
return getOperationInputFQNameForRangeRequest(transferOperation);
}
TransferObjectType transferObjectType = transferOperation.getInput().getType();
String className = classNameForRequest(transferObjectType);
String fqName = namedElementApiParentPath(transferObjectType) + "." + className;
return fqName.replaceAll("/", ".");
}

public static String getOperationInputFQNameForRangeRequest(TransferOperation transferOperation) {
TransferObjectType transferObjectType = transferOperation.getInput().getType();
String className = classNameForRangeRequest(transferObjectType);
String fqName = namedElementApiParentPath(transferObjectType) + "." + className;
return fqName.replaceAll("/", ".");
}
Expand All @@ -188,6 +208,13 @@ public static String getOperationOutputFQName(TransferOperation transferOperatio
return fqName.replaceAll("/", ".");
}

public static String getOperationOutputFQNameForResponse(TransferOperation transferOperation) {
TransferObjectType transferObjectType = transferOperation.getOutput().getType();
String className = classNameForResponse(transferObjectType);
String fqName = namedElementApiParentPath(transferObjectType) + "." + className;
return fqName.replaceAll("/", ".");
}

public static boolean isCreateOperation(TransferOperation transferOperation) {
return transferOperation.getName().startsWith("_createInstance");
}
Expand All @@ -197,4 +224,22 @@ public static boolean isExportOperation(TransferOperation transferOperation) {
&& transferOperation.getBehaviour().getBehaviourType() == TransferOperationBehaviourType.EXPORT;
}

public static String getOperationInputLogicalFullName(TransferOperation transferOperation) {
TransferObjectType transferObjectType = transferOperation.getInput().getType();
if (transferOperation.getBehaviour() != null && transferOperation.getBehaviour().getBehaviourType().equals(TransferOperationBehaviourType.GET_RANGE)) {
return logicalFullName(transferObjectType) + classNameForRangeRequestPostfix(transferObjectType);
}
return logicalFullName(transferObjectType) + classNameForRequestPostfix(transferObjectType);
}

public static String getOperationOutputLogicalFullName(TransferOperation transferOperation) {
TransferObjectType transferObjectType = transferOperation.getOutput().getType();
return logicalFullName(transferObjectType) + classNameForResponsePostfix(transferObjectType);
}

public static String getOperationTagName(TransferOperation transferOperation) {
TransferObjectType transferObjectType = (TransferObjectType) transferOperation.eContainer();
return logicalFullName(transferObjectType);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -20,27 +20,54 @@

@TemplateHelper
public class RelationHelper extends StaticMethodValueResolver {
public static String relationTargetTypeDefinition(TransferObjectRelation transferObjectRelation, boolean stored) {
String relatedType = relationTargetBareTypeDefinition(transferObjectRelation);
if (!stored && !transferObjectRelation.getTarget().isQueryCustomizer() && !isRangeInputType(transferObjectRelation.getTarget())) {
relatedType = relatedType + "NotStored";
}
public static String decorateWrapperType(TransferObjectRelation transferObjectRelation, String type) {
String relatedType = type;
if (transferObjectRelation.isCollection()) {
relatedType = "java.util.List<" + relatedType + ">";
relatedType = "java.util.Optional<java.util.List<" + relatedType + ">>";
} else if (isRelationOptionalType(transferObjectRelation)) {
relatedType = "java.util.Optional<" + relatedType + ">";
}
return relatedType;
}

public static String relationTargetTypeDefinitionForResponse(TransferObjectRelation transferObjectRelation) {
String relatedType = relationTargetBareTypeDefinition(transferObjectRelation) + "ForResponse";
if (transferObjectRelation.isCollection()) {
relatedType = "java.util.List<" + relatedType + ">";
} else if (isRelationOptionalType(transferObjectRelation)) {
relatedType = "java.util.Optional<" + relatedType + ">";
public static String relationTargetTypeDefinitionForCreateRequest(TransferObjectRelation transferObjectRelation) {
String relatedType = relationTargetBareTypeDefinition(transferObjectRelation);
if (!transferObjectRelation.getTarget().isQueryCustomizer()) {
relatedType = relatedType + "CreateRequest";
} else if (!transferObjectRelation.getTarget().isQueryCustomizer() && !isRangeInputType(transferObjectRelation.getTarget())) {
relatedType = relatedType + "Request";
} else if (!transferObjectRelation.getTarget().isQueryCustomizer() && isRangeInputType(transferObjectRelation.getTarget())) {
relatedType = relatedType + "RangeRequest";
}
return relatedType;
return decorateWrapperType(transferObjectRelation, relatedType);
}

public static String relationTargetTypeDefinitionForRequest(TransferObjectRelation transferObjectRelation) {
String relatedType = relationTargetBareTypeDefinition(transferObjectRelation);
if (!transferObjectRelation.getTarget().isQueryCustomizer()) {
relatedType = relatedType + "Request";
}
return decorateWrapperType(transferObjectRelation, relatedType);
}

public static String relationTargetTypeDefinitionForRangeRequest(TransferObjectRelation transferObjectRelation) {
String relatedType = relationTargetBareTypeDefinition(transferObjectRelation);
if (!transferObjectRelation.getTarget().isQueryCustomizer() && !isRangeInputType(transferObjectRelation.getTarget())) {
relatedType = relatedType + "Request";
} else if (!transferObjectRelation.getTarget().isQueryCustomizer() && isRangeInputType(transferObjectRelation.getTarget())) {
relatedType = relatedType + "RangeRequest";
}
return decorateWrapperType(transferObjectRelation, relatedType);
}

public static String relationTargetTypeDefinitionForOperationInput(TransferObjectRelation transferObjectRelation) {
String relatedType = relationTargetBareTypeDefinition(transferObjectRelation) + "OperationInput";
return decorateWrapperType(transferObjectRelation, relatedType);
}

public static String relationTargetTypeDefinitionForResponse(TransferObjectRelation transferObjectRelation) {
String relatedType = relationTargetBareTypeDefinition(transferObjectRelation) + "Response";
return decorateWrapperType(transferObjectRelation, relatedType);
}

public static String relationTargetBareTypeDefinition(TransferObjectRelation transferObjectRelation) {
Expand All @@ -62,6 +89,7 @@ public static boolean mappedRelationIsAssociation(TransferObjectRelation transfe
&& (transferObjectRelation.getBinding() instanceof AssociationEnd);
}

/*
public static List<TransferObjectRelation> allEmbeddedOrMappedRelation(TransferObjectType transferObjectType) {
return transferObjectType.getRelations().stream()
.filter(r -> r.isEmbedded()
Expand All @@ -70,9 +98,20 @@ public static List<TransferObjectRelation> allEmbeddedOrMappedRelation(TransferO
.collect(Collectors.toList());
}
public static List<TransferObjectRelation> allEmbeddedOrMappedRelationForNotStoredDTO(TransferObjectType transferObjectType) {
*/

public static List<TransferObjectRelation> allEmbeddedOrMappedRelation(TransferObjectType transferObjectType) {
return transferObjectType.getRelations().stream()
.filter(r -> r.isEmbedded()
&& !isParameterizedRelation(r)
&& isMapped(r.getTarget()))
.collect(Collectors.toList());
}

public static List<TransferObjectRelation> allEmbeddedOrMappedRelationForCreate(TransferObjectType transferObjectType) {
return transferObjectType.getRelations().stream()
.filter(r -> r.isEmbedded() || (r.getBinding() != null && (r.getBinding() instanceof AssociationEnd || r.getBinding() instanceof Containment)))
.filter(r ->!isParameterizedRelation(r) && (r.isEmbedded()
|| (r.getBinding() != null && (r.getBinding() instanceof AssociationEnd || r.getBinding() instanceof Containment))))
.collect(Collectors.toList());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,9 @@ public static synchronized Boolean isGenerateOptionalTypes() {
return Boolean.parseBoolean((String) ThreadLocalContextHolder.getVariable("generateOptionalTypes"));
}

public static synchronized Boolean isGenerateOpenApiAnnotations() {
return Boolean.parseBoolean((String) ThreadLocalContextHolder.getVariable("generateOpenApiAnnotations"));
}


}
20 changes: 10 additions & 10 deletions judo-psm-generator-jaxrs-api/src/main/resources/psm-jaxrs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,27 +11,27 @@ templates:
factoryExpression: "#allExposedTransferObjectWithOperation(#model)"
actorTypeBased: false

- name: dtoNotStored.java
pathExpression: "'/' + #namedElementApiParentPath(#self) + '/' + #className(#self) + 'NotStored.java'"
templateName: rest/api/dtoNotStored.java.hbs
- name: dtoForCreateRequest.java
pathExpression: "'/' + #namedElementApiParentPath(#self) + '/' + #classNameForCreateRequest(#self) + '.java'"
templateName: rest/api/dtoForCreateRequest.java.hbs
factoryExpression: "#allTransferObject(#model)"
actorTypeBased: false

- name: dtoForResponse.java
pathExpression: "'/' + #namedElementApiParentPath(#self) + '/' + #className(#self) + 'ForResponse.java'"
pathExpression: "'/' + #namedElementApiParentPath(#self) + '/' + #classNameForResponse(#self) + '.java'"
templateName: rest/api/dtoForResponse.java.hbs
factoryExpression: "#allTransferObject(#model)"
actorTypeBased: false

- name: dto.java
pathExpression: "'/' + #namedElementApiParentPath(#self) + '/' + #className(#self) + '.java'"
templateName: rest/api/dto.java.hbs
- name: dtoForRequest.java
pathExpression: "'/' + #namedElementApiParentPath(#self) + '/' + #classNameForRequest(#self) + '.java'"
templateName: rest/api/dtoForRequest.java.hbs
factoryExpression: "#allTransferObject(#model)"
actorTypeBased: false

- name: range.java
pathExpression: "'/' + #namedElementApiParentPath(#self) + '/' + #className(#self) + '.java'"
templateName: rest/api/range.java.hbs
pathExpression: "'/' + #namedElementApiParentPath(#self) + '/' + #classNameForRangeRequest(#self) + '.java'"
templateName: rest/api/dtoForRangeRequest.java.hbs
factoryExpression: "#allRange(#model)"
actorTypeBased: false

Expand All @@ -43,7 +43,7 @@ templates:

- name: querycustomizer.java
pathExpression: "'/' + #namedElementApiParentPath(#self) + '/' + #queryCustomizerName(#self) + '.java'"
templateName: rest/api/querycustomizer.java.hbs
templateName: rest/api/dtoForQueryCustomizer.java.hbs
factoryExpression: "#allQueryCustomizer(#model)"
actorTypeBased: false

Expand Down
Loading

0 comments on commit 291e542

Please sign in to comment.