From 291e54205a15bcabc06223b042187529c4e57f22 Mon Sep 17 00:00:00 2001 From: Robert Csakany Date: Fri, 8 Mar 2024 11:13:53 +0100 Subject: [PATCH] JNG-5593 Add support of Create / Update mask support (#26) * JNG-5593 Add Mask support for create / update * Method definition moved out as fragment * Add mask as header parameter --- .../api/AttributeHelper.java | 12 ++ .../{jackson => jaxrs}/api/JavaApiHelper.java | 2 + .../api/JavaNamespaceHelper.java | 4 + .../{jackson => jaxrs}/api/ModelHelper.java | 0 .../api/ObjectTypeHelper.java | 66 ++++++++++ .../api/OperationHelper.java | 55 +++++++- .../api/RelationHelper.java | 69 +++++++--- .../api/StoredVariableHelper.java | 5 + .../src/main/resources/psm-jaxrs.yaml | 20 +-- .../src/main/resources/rest/api/dto.java.hbs | 52 -------- .../rest/api/dtoForCreateRequest.java.hbs | 66 ++++++++++ .../rest/api/dtoForQueryCustomizer.java.hbs | 41 ++++++ .../rest/api/dtoForRangeRequest.java.hbs | 38 ++++++ .../resources/rest/api/dtoForRequest.java.hbs | 98 ++++++++++++++ .../rest/api/dtoForResponse.java.hbs | 113 +++++++++++++--- .../resources/rest/api/dtoNotStored.java.hbs | 29 ----- .../rest/api/querycustomizer.java.hbs | 19 --- .../main/resources/rest/api/range.java.hbs | 17 --- .../api/rest.service.constants.fragment.hbs | 24 ++++ .../resources/rest/api/rest.service.java.hbs | 17 +-- .../api/rest.service.operation.fragment.hbs | 105 +++++++++++++++ .../rest/impl/rest.service.impl.java.hbs | 123 +----------------- judo-psm-generator-jaxrs-test/pom.xml | 21 +++ .../psm/jaxrs/test/SerializationTest.java | 52 ++++++++ 24 files changed, 752 insertions(+), 296 deletions(-) rename judo-psm-generator-jaxrs-api/src/main/java/hu/blackbelt/judo/psm/generator/{jackson => jaxrs}/api/AttributeHelper.java (84%) rename judo-psm-generator-jaxrs-api/src/main/java/hu/blackbelt/judo/psm/generator/{jackson => jaxrs}/api/JavaApiHelper.java (98%) rename judo-psm-generator-jaxrs-api/src/main/java/hu/blackbelt/judo/psm/generator/{jackson => jaxrs}/api/JavaNamespaceHelper.java (96%) rename judo-psm-generator-jaxrs-api/src/main/java/hu/blackbelt/judo/psm/generator/{jackson => jaxrs}/api/ModelHelper.java (100%) rename judo-psm-generator-jaxrs-api/src/main/java/hu/blackbelt/judo/psm/generator/{jackson => jaxrs}/api/ObjectTypeHelper.java (53%) rename judo-psm-generator-jaxrs-api/src/main/java/hu/blackbelt/judo/psm/generator/{jackson => jaxrs}/api/OperationHelper.java (78%) rename judo-psm-generator-jaxrs-api/src/main/java/hu/blackbelt/judo/psm/generator/{jackson => jaxrs}/api/RelationHelper.java (52%) rename judo-psm-generator-jaxrs-api/src/main/java/hu/blackbelt/judo/psm/generator/{jackson => jaxrs}/api/StoredVariableHelper.java (91%) delete mode 100644 judo-psm-generator-jaxrs-api/src/main/resources/rest/api/dto.java.hbs create mode 100644 judo-psm-generator-jaxrs-api/src/main/resources/rest/api/dtoForCreateRequest.java.hbs create mode 100644 judo-psm-generator-jaxrs-api/src/main/resources/rest/api/dtoForQueryCustomizer.java.hbs create mode 100644 judo-psm-generator-jaxrs-api/src/main/resources/rest/api/dtoForRangeRequest.java.hbs create mode 100644 judo-psm-generator-jaxrs-api/src/main/resources/rest/api/dtoForRequest.java.hbs delete mode 100644 judo-psm-generator-jaxrs-api/src/main/resources/rest/api/dtoNotStored.java.hbs delete mode 100644 judo-psm-generator-jaxrs-api/src/main/resources/rest/api/querycustomizer.java.hbs delete mode 100644 judo-psm-generator-jaxrs-api/src/main/resources/rest/api/range.java.hbs create mode 100644 judo-psm-generator-jaxrs-api/src/main/resources/rest/api/rest.service.constants.fragment.hbs create mode 100644 judo-psm-generator-jaxrs-api/src/main/resources/rest/api/rest.service.operation.fragment.hbs create mode 100644 judo-psm-generator-jaxrs-test/src/test/java/hu/blackbelt/judo/generator/psm/jaxrs/test/SerializationTest.java diff --git a/judo-psm-generator-jaxrs-api/src/main/java/hu/blackbelt/judo/psm/generator/jackson/api/AttributeHelper.java b/judo-psm-generator-jaxrs-api/src/main/java/hu/blackbelt/judo/psm/generator/jaxrs/api/AttributeHelper.java similarity index 84% rename from judo-psm-generator-jaxrs-api/src/main/java/hu/blackbelt/judo/psm/generator/jackson/api/AttributeHelper.java rename to judo-psm-generator-jaxrs-api/src/main/java/hu/blackbelt/judo/psm/generator/jaxrs/api/AttributeHelper.java index b2b0a32..3d12089 100644 --- a/judo-psm-generator-jaxrs-api/src/main/java/hu/blackbelt/judo/psm/generator/jackson/api/AttributeHelper.java +++ b/judo-psm-generator-jaxrs-api/src/main/java/hu/blackbelt/judo/psm/generator/jaxrs/api/AttributeHelper.java @@ -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 diff --git a/judo-psm-generator-jaxrs-api/src/main/java/hu/blackbelt/judo/psm/generator/jackson/api/JavaApiHelper.java b/judo-psm-generator-jaxrs-api/src/main/java/hu/blackbelt/judo/psm/generator/jaxrs/api/JavaApiHelper.java similarity index 98% rename from judo-psm-generator-jaxrs-api/src/main/java/hu/blackbelt/judo/psm/generator/jackson/api/JavaApiHelper.java rename to judo-psm-generator-jaxrs-api/src/main/java/hu/blackbelt/judo/psm/generator/jaxrs/api/JavaApiHelper.java index d88da66..f85a800 100644 --- a/judo-psm-generator-jaxrs-api/src/main/java/hu/blackbelt/judo/psm/generator/jackson/api/JavaApiHelper.java +++ b/judo-psm-generator-jaxrs-api/src/main/java/hu/blackbelt/judo/psm/generator/jaxrs/api/JavaApiHelper.java @@ -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 { @@ -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)); } diff --git a/judo-psm-generator-jaxrs-api/src/main/java/hu/blackbelt/judo/psm/generator/jackson/api/JavaNamespaceHelper.java b/judo-psm-generator-jaxrs-api/src/main/java/hu/blackbelt/judo/psm/generator/jaxrs/api/JavaNamespaceHelper.java similarity index 96% rename from judo-psm-generator-jaxrs-api/src/main/java/hu/blackbelt/judo/psm/generator/jackson/api/JavaNamespaceHelper.java rename to judo-psm-generator-jaxrs-api/src/main/java/hu/blackbelt/judo/psm/generator/jaxrs/api/JavaNamespaceHelper.java index ce7d95c..4bb1ac6 100644 --- a/judo-psm-generator-jaxrs-api/src/main/java/hu/blackbelt/judo/psm/generator/jackson/api/JavaNamespaceHelper.java +++ b/judo-psm-generator-jaxrs-api/src/main/java/hu/blackbelt/judo/psm/generator/jaxrs/api/JavaNamespaceHelper.java @@ -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; diff --git a/judo-psm-generator-jaxrs-api/src/main/java/hu/blackbelt/judo/psm/generator/jackson/api/ModelHelper.java b/judo-psm-generator-jaxrs-api/src/main/java/hu/blackbelt/judo/psm/generator/jaxrs/api/ModelHelper.java similarity index 100% rename from judo-psm-generator-jaxrs-api/src/main/java/hu/blackbelt/judo/psm/generator/jackson/api/ModelHelper.java rename to judo-psm-generator-jaxrs-api/src/main/java/hu/blackbelt/judo/psm/generator/jaxrs/api/ModelHelper.java diff --git a/judo-psm-generator-jaxrs-api/src/main/java/hu/blackbelt/judo/psm/generator/jackson/api/ObjectTypeHelper.java b/judo-psm-generator-jaxrs-api/src/main/java/hu/blackbelt/judo/psm/generator/jaxrs/api/ObjectTypeHelper.java similarity index 53% rename from judo-psm-generator-jaxrs-api/src/main/java/hu/blackbelt/judo/psm/generator/jackson/api/ObjectTypeHelper.java rename to judo-psm-generator-jaxrs-api/src/main/java/hu/blackbelt/judo/psm/generator/jaxrs/api/ObjectTypeHelper.java index 8e591e8..41e97da 100644 --- a/judo-psm-generator-jaxrs-api/src/main/java/hu/blackbelt/judo/psm/generator/jackson/api/ObjectTypeHelper.java +++ b/judo-psm-generator-jaxrs-api/src/main/java/hu/blackbelt/judo/psm/generator/jaxrs/api/ObjectTypeHelper.java @@ -20,11 +20,13 @@ * #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; @@ -32,6 +34,8 @@ 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 @@ -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); + } + } diff --git a/judo-psm-generator-jaxrs-api/src/main/java/hu/blackbelt/judo/psm/generator/jackson/api/OperationHelper.java b/judo-psm-generator-jaxrs-api/src/main/java/hu/blackbelt/judo/psm/generator/jaxrs/api/OperationHelper.java similarity index 78% rename from judo-psm-generator-jaxrs-api/src/main/java/hu/blackbelt/judo/psm/generator/jackson/api/OperationHelper.java rename to judo-psm-generator-jaxrs-api/src/main/java/hu/blackbelt/judo/psm/generator/jaxrs/api/OperationHelper.java index 63682c3..fcdf5b2 100644 --- a/judo-psm-generator-jaxrs-api/src/main/java/hu/blackbelt/judo/psm/generator/jackson/api/OperationHelper.java +++ b/judo-psm-generator-jaxrs-api/src/main/java/hu/blackbelt/judo/psm/generator/jaxrs/api/OperationHelper.java @@ -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; @@ -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 { @@ -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("/", "."); } @@ -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"); } @@ -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); + } + } diff --git a/judo-psm-generator-jaxrs-api/src/main/java/hu/blackbelt/judo/psm/generator/jackson/api/RelationHelper.java b/judo-psm-generator-jaxrs-api/src/main/java/hu/blackbelt/judo/psm/generator/jaxrs/api/RelationHelper.java similarity index 52% rename from judo-psm-generator-jaxrs-api/src/main/java/hu/blackbelt/judo/psm/generator/jackson/api/RelationHelper.java rename to judo-psm-generator-jaxrs-api/src/main/java/hu/blackbelt/judo/psm/generator/jaxrs/api/RelationHelper.java index 0cded29..21ffc98 100644 --- a/judo-psm-generator-jaxrs-api/src/main/java/hu/blackbelt/judo/psm/generator/jackson/api/RelationHelper.java +++ b/judo-psm-generator-jaxrs-api/src/main/java/hu/blackbelt/judo/psm/generator/jaxrs/api/RelationHelper.java @@ -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>"; } 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) { @@ -62,6 +89,7 @@ public static boolean mappedRelationIsAssociation(TransferObjectRelation transfe && (transferObjectRelation.getBinding() instanceof AssociationEnd); } + /* public static List allEmbeddedOrMappedRelation(TransferObjectType transferObjectType) { return transferObjectType.getRelations().stream() .filter(r -> r.isEmbedded() @@ -70,9 +98,20 @@ public static List allEmbeddedOrMappedRelation(TransferO .collect(Collectors.toList()); } - public static List allEmbeddedOrMappedRelationForNotStoredDTO(TransferObjectType transferObjectType) { + */ + + public static List allEmbeddedOrMappedRelation(TransferObjectType transferObjectType) { + return transferObjectType.getRelations().stream() + .filter(r -> r.isEmbedded() + && !isParameterizedRelation(r) + && isMapped(r.getTarget())) + .collect(Collectors.toList()); + } + + public static List 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()); } } diff --git a/judo-psm-generator-jaxrs-api/src/main/java/hu/blackbelt/judo/psm/generator/jackson/api/StoredVariableHelper.java b/judo-psm-generator-jaxrs-api/src/main/java/hu/blackbelt/judo/psm/generator/jaxrs/api/StoredVariableHelper.java similarity index 91% rename from judo-psm-generator-jaxrs-api/src/main/java/hu/blackbelt/judo/psm/generator/jackson/api/StoredVariableHelper.java rename to judo-psm-generator-jaxrs-api/src/main/java/hu/blackbelt/judo/psm/generator/jaxrs/api/StoredVariableHelper.java index 3d5ec15..829efd4 100644 --- a/judo-psm-generator-jaxrs-api/src/main/java/hu/blackbelt/judo/psm/generator/jackson/api/StoredVariableHelper.java +++ b/judo-psm-generator-jaxrs-api/src/main/java/hu/blackbelt/judo/psm/generator/jaxrs/api/StoredVariableHelper.java @@ -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")); + } + + } diff --git a/judo-psm-generator-jaxrs-api/src/main/resources/psm-jaxrs.yaml b/judo-psm-generator-jaxrs-api/src/main/resources/psm-jaxrs.yaml index 2c386ee..3637ec4 100644 --- a/judo-psm-generator-jaxrs-api/src/main/resources/psm-jaxrs.yaml +++ b/judo-psm-generator-jaxrs-api/src/main/resources/psm-jaxrs.yaml @@ -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 @@ -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 diff --git a/judo-psm-generator-jaxrs-api/src/main/resources/rest/api/dto.java.hbs b/judo-psm-generator-jaxrs-api/src/main/resources/rest/api/dto.java.hbs deleted file mode 100644 index 1d6f8cb..0000000 --- a/judo-psm-generator-jaxrs-api/src/main/resources/rest/api/dto.java.hbs +++ /dev/null @@ -1,52 +0,0 @@ -{{> fragment.header.hbs }} - -package {{ namedElementApiPackageName self }}; - -{{# if (hasDocumentation self) }} -/** - * {{ self.documentation.decorateWithAsterisks }} - */ -{{/ if }} -public interface {{ className self }} { - - {{# each (allEmbeddedOrMappedRelation self) as | relation | }} - - {{# if relation.required }} - @io.swagger.v3.oas.annotations.media.Schema(required = true) - {{/ if }} - {{# if (mappedRelationIsAssociation relation)}} - {{{ relationTargetTypeDefinition relation true }}} get{{ relation.name.firstToUpperCase }}(); - {{ else }} - {{{ relationTargetTypeDefinition relation false }}} get{{ relation.name.firstToUpperCase }}(); - {{/ if }} - {{/ each }} - - {{# each self.attributes as | attribute | }} - {{# unless (isQueryOrDefaultValueOrDataPropertyAttribute attribute) }} - {{# if attribute.required }} - @io.swagger.v3.oas.annotations.media.Schema(required = true) - {{/ if }} - {{{ attributeTargetTypeDefinition attribute }}} get{{ attribute.name.firstToUpperCase }}(); - {{/ unless }} - {{/ each }} - -{{# if (isMapped self) }} - @io.swagger.v3.oas.annotations.media.Schema(name = "__deleteable") - boolean get__deleteable(); - - @io.swagger.v3.oas.annotations.media.Schema(name = "__updateable") - boolean get__updateable(); - - @io.swagger.v3.oas.annotations.media.Schema(name = "__entityType") - String get__entityType(); - - @io.swagger.v3.oas.annotations.media.Schema(name = "__identifier") - String get__identifier(); - - @io.swagger.v3.oas.annotations.media.Schema(name = "__signedIdentifier") - String get__signedIdentifier(); - - @io.swagger.v3.oas.annotations.media.Schema(name = "__version") - int get__version(); -{{/ if }} -} diff --git a/judo-psm-generator-jaxrs-api/src/main/resources/rest/api/dtoForCreateRequest.java.hbs b/judo-psm-generator-jaxrs-api/src/main/resources/rest/api/dtoForCreateRequest.java.hbs new file mode 100644 index 0000000..5ea303d --- /dev/null +++ b/judo-psm-generator-jaxrs-api/src/main/resources/rest/api/dtoForCreateRequest.java.hbs @@ -0,0 +1,66 @@ +package {{ namedElementApiPackageName self }}; + +{{# if (hasDocumentation self) }} +/** + * {{ self.documentation.decorateWithAsterisks }} + */ +{{/ if }} +@com.fasterxml.jackson.annotation.JsonInclude(com.fasterxml.jackson.annotation.JsonInclude.Include.NON_NULL) +@io.swagger.v3.oas.annotations.media.Schema(name = "{{ classNameLogicalFullNameForCreateRequest self }}") +public class {{ classNameForCreateRequest self }} { + +{{# if (isMapped self) }} + + private String __referenceId; + + @io.swagger.v3.oas.annotations.media.Schema(name = "__referenceId") + public String get__referenceId() { + return this.__referenceId; + } + + public void set__referenceId(String __referenceId) { + this.__referenceId = __referenceId; + } +{{/ if }} + + {{# each (allEmbeddedOrMappedRelationForCreate self) as | relation | }} + @io.swagger.v3.oas.annotations.media.Schema(name = "{{ relation.name }}"{{# if relation.required }}, required = true{{/ if }}) + {{# if (mappedRelationIsAssociation relation)}} + private {{{ relationTargetTypeDefinitionForCreateRequest relation}}} {{ safeName relation.name }}; + + public {{{ relationTargetTypeDefinitionForCreateRequest relation }}} get{{ relation.name.firstToUpperCase }}() { + return this.{{ safeName relation.name }}; + } + + public void set{{ relation.name.firstToUpperCase }}({{{ relationTargetTypeDefinitionForCreateRequest relation }}} {{ safeName relation.name }}) { + this.{{ safeName relation.name }} = {{ safeName relation.name }}; + } + {{ else }} + private {{{ relationTargetTypeDefinitionForRequest relation }}} {{ safeName relation.name }}; + + public {{{ relationTargetTypeDefinitionForRequest relation }}} get{{ relation.name.firstToUpperCase }}() { + return this.{{ safeName relation.name }}; + } + + public void set{{ relation.name.firstToUpperCase }}({{{ relationTargetTypeDefinitionForRequest relation }}} {{ safeName relation.name }}) { + this.{{ safeName relation.name }} = {{ safeName relation.name }}; + } + {{/ if }} + {{/ each }} + + {{# each self.attributes as | attribute | }} + {{# unless (isRequestAttribute attribute) }} + + private {{{ attributeTargetTypeDefinition attribute }}} {{ safeName attribute.name }}; + + @io.swagger.v3.oas.annotations.media.Schema(name = "{{ attribute.name }}"{{# if attribute.required }}, required = true{{/ if }}) + public {{{ attributeTargetTypeDefinition attribute }}} get{{ attribute.name.firstToUpperCase }}() { + return this.{{ safeName attribute.name }}; + }; + public void set{{ attribute.name.firstToUpperCase }}({{{ attributeTargetTypeDefinition attribute }}} {{ safeName attribute.name }}) { + this.{{ safeName attribute.name }} = {{ safeName attribute.name }}; + }; + + {{/ unless }} + {{/ each }} +} diff --git a/judo-psm-generator-jaxrs-api/src/main/resources/rest/api/dtoForQueryCustomizer.java.hbs b/judo-psm-generator-jaxrs-api/src/main/resources/rest/api/dtoForQueryCustomizer.java.hbs new file mode 100644 index 0000000..20ca189 --- /dev/null +++ b/judo-psm-generator-jaxrs-api/src/main/resources/rest/api/dtoForQueryCustomizer.java.hbs @@ -0,0 +1,41 @@ +{{> fragment.header.hbs }} + +package {{ queryCustomizerPackageName self }}; + +/** + * Query customizer for searching {@link {{ classFqName self }} } instances. + */ +@com.fasterxml.jackson.annotation.JsonInclude(com.fasterxml.jackson.annotation.JsonInclude.Include.NON_NULL) +@io.swagger.v3.oas.annotations.media.Schema(name = "{{ classNameLogicalFullNameForRequest self }}") +public class {{ queryCustomizerName self }} { + {{# each (allEmbeddedOrMappedRelation self) as | relation | }} + {{# unless (mappedRelationIsAssociation relation)}} + @io.swagger.v3.oas.annotations.media.Schema(name = "{{ relation.name }}"{{# if relation.required }}, required = true{{/ if }}) + private {{{ relationTargetTypeDefinitionForRequest relation }}} {{ safeName relation.name }}; + + public {{{ relationTargetTypeDefinitionForRequest relation }}} get{{ relation.name.firstToUpperCase }}() { + return this.{{ safeName relation.name }}; + } + + public void set{{ relation.name.firstToUpperCase }}({{{ relationTargetTypeDefinitionForRequest relation }}} {{ safeName relation.name }}) { + this.{{ safeName relation.name }} = {{ safeName relation.name }}; + } + {{/ unless }} + {{/ each }} + + {{# each self.attributes as | attribute | }} + {{# unless (isQueryOrDefaultValueOrDataPropertyAttribute attribute) }} + + private {{{ attributeTargetTypeDefinition attribute }}} {{ safeName attribute.name }}; + + @io.swagger.v3.oas.annotations.media.Schema(name = "{{ attribute.name }}"{{# if attribute.required }}, required = true{{/ if }}) + public {{{ attributeTargetTypeDefinition attribute }}} get{{ attribute.name.firstToUpperCase }}() { + return this.{{ safeName attribute.name }}; + }; + public void set{{ attribute.name.firstToUpperCase }}({{{ attributeTargetTypeDefinition attribute }}} {{ safeName attribute.name }}) { + this.{{ safeName attribute.name }} = {{ safeName attribute.name }}; + }; + + {{/ unless }} + {{/ each }} +} diff --git a/judo-psm-generator-jaxrs-api/src/main/resources/rest/api/dtoForRangeRequest.java.hbs b/judo-psm-generator-jaxrs-api/src/main/resources/rest/api/dtoForRangeRequest.java.hbs new file mode 100644 index 0000000..c27c0e1 --- /dev/null +++ b/judo-psm-generator-jaxrs-api/src/main/resources/rest/api/dtoForRangeRequest.java.hbs @@ -0,0 +1,38 @@ +package {{ namedElementApiPackageName self }}; + +{{# if (hasDocumentation self) }} +/** + * {{ self.documentation.decorateWithAsterisks }} + */ +{{/ if }} +@com.fasterxml.jackson.annotation.JsonInclude(com.fasterxml.jackson.annotation.JsonInclude.Include.NON_NULL) +@io.swagger.v3.oas.annotations.media.Schema(name = "{{ classNameLogicalFullNameForRangeRequest self }}") +public class {{ classNameForRangeRequest self }} { + + {{# each self.relations as | relation | }} + @io.swagger.v3.oas.annotations.media.Schema(name = "{{ relation.name }}"{{# if relation.required }}, required = true{{/ if }}) + private {{{ relationTargetTypeDefinitionForRequest relation }}} {{ safeName relation.name }}; + + public {{{ relationTargetTypeDefinitionForRequest relation }}} get{{ relation.name.firstToUpperCase }}() { + return this.{{ safeName relation.name }}; + } + + public void set{{ relation.name.firstToUpperCase }}({{{ relationTargetTypeDefinitionForRequest relation }}} {{ safeName relation.name }}) { + this.{{ safeName relation.name }} = {{ safeName relation.name }}; + } + {{/ each }} + + {{# each self.attributes as | attribute | }} + + private {{{ attributeTargetTypeDefinition attribute }}} {{ safeName attribute.name }}; + + @io.swagger.v3.oas.annotations.media.Schema(name = "{{ attribute.name }}"{{# if attribute.required }}, required = true{{/ if }}) + public {{{ attributeTargetTypeDefinition attribute }}} get{{ attribute.name.firstToUpperCase }}() { + return this.{{ safeName attribute.name }}; + }; + public void set{{ attribute.name.firstToUpperCase }}({{{ attributeTargetTypeDefinition attribute }}} {{ safeName attribute.name }}) { + this.{{ safeName attribute.name }} = {{ safeName attribute.name }}; + }; + {{/ each }} + +} diff --git a/judo-psm-generator-jaxrs-api/src/main/resources/rest/api/dtoForRequest.java.hbs b/judo-psm-generator-jaxrs-api/src/main/resources/rest/api/dtoForRequest.java.hbs new file mode 100644 index 0000000..2793870 --- /dev/null +++ b/judo-psm-generator-jaxrs-api/src/main/resources/rest/api/dtoForRequest.java.hbs @@ -0,0 +1,98 @@ +{{> fragment.header.hbs }} + +package {{ namedElementApiPackageName self }}; + +{{# if (hasDocumentation self) }} +/** + * {{ self.documentation.decorateWithAsterisks }} + */ +{{/ if }} +@com.fasterxml.jackson.annotation.JsonInclude(com.fasterxml.jackson.annotation.JsonInclude.Include.NON_NULL) +@io.swagger.v3.oas.annotations.media.Schema(name = "{{ classNameLogicalFullNameForRequest self }}") +public class {{ classNameForRequest self }} { + + {{# each (allEmbeddedOrMappedRelation self) as | relation | }} + {{# unless (mappedRelationIsAssociation relation)}} + @io.swagger.v3.oas.annotations.media.Schema(name = "{{ relation.name }}"{{# if relation.required }}, required = true{{/ if }}) + private {{{ relationTargetTypeDefinitionForRequest relation }}} {{ safeName relation.name }}; + + public {{{ relationTargetTypeDefinitionForRequest relation }}} get{{ relation.name.firstToUpperCase }}() { + return this.{{ safeName relation.name }}; + } + + public void set{{ relation.name.firstToUpperCase }}({{{ relationTargetTypeDefinitionForRequest relation }}} {{ safeName relation.name }}) { + this.{{ safeName relation.name }} = {{ safeName relation.name }}; + } + {{/ unless }} + {{/ each }} + + {{# each self.attributes as | attribute | }} + {{# unless (isRequestAttribute attribute) }} + + private {{{ attributeTargetTypeDefinition attribute }}} {{ safeName attribute.name }}; + + @io.swagger.v3.oas.annotations.media.Schema(name = "{{ attribute.name }}"{{# if attribute.required }}, required = true{{/ if }}) + public {{{ attributeTargetTypeDefinition attribute }}} get{{ attribute.name.firstToUpperCase }}() { + return this.{{ safeName attribute.name }}; + }; + public void set{{ attribute.name.firstToUpperCase }}({{{ attributeTargetTypeDefinition attribute }}} {{ safeName attribute.name }}) { + this.{{ safeName attribute.name }} = {{ safeName attribute.name }}; + }; + + {{/ unless }} + {{/ each }} + +{{# if (isMapped self) }} + + + private String __identifier; + + @io.swagger.v3.oas.annotations.media.Schema(name = "__identifier") + public String get__identifier() { + return this.__identifier; + } + + public void set__identifier(String __identifier) { + this.__identifier = __identifier; + } + + private String __signedIdentifier; + + @io.swagger.v3.oas.annotations.media.Schema(name = "__signedIdentifier") + public String get__signedIdentifier() { + return this.__signedIdentifier; + } + + public void set__signedIdentifier(String __signedIdentifier) { + this.__signedIdentifier = __signedIdentifier; + } + + private String __referenceId; + + @io.swagger.v3.oas.annotations.media.Schema(name = "__referenceId") + public String get__referenceId() { + return this.__referenceId; + } + + public void set__referenceId(String __referenceId) { + this.__referenceId = __referenceId; + } + +{{/ if }} + + public java.util.Map toMap() { + java.util.Map ret = new java.util.HashMap(); + {{# each self.attributes as | attribute | }} + {{# unless (isQueryOrDefaultValueOrDataPropertyAttribute attribute) }} + if (this.{{ safeName attribute.name }} != null) { + {{# if isOptionalAttribute attribute }} + ret.put("{{ safeName attribute.name }}", this.{{ safeName attribute.name }}.orElse(null)); + {{ else }} + ret.put("{{ safeName attribute.name }}", this.{{ safeName attribute.name }}); + {{/ if }} + } + {{/ unless }} + {{/ each }} + return ret; + } +} diff --git a/judo-psm-generator-jaxrs-api/src/main/resources/rest/api/dtoForResponse.java.hbs b/judo-psm-generator-jaxrs-api/src/main/resources/rest/api/dtoForResponse.java.hbs index e44e563..fa66a62 100644 --- a/judo-psm-generator-jaxrs-api/src/main/resources/rest/api/dtoForResponse.java.hbs +++ b/judo-psm-generator-jaxrs-api/src/main/resources/rest/api/dtoForResponse.java.hbs @@ -7,44 +7,121 @@ package {{ namedElementApiPackageName self }}; * {{ self.documentation.decorateWithAsterisks }} */ {{/ if }} -public interface {{ className self }}ForResponse { +@com.fasterxml.jackson.annotation.JsonInclude(com.fasterxml.jackson.annotation.JsonInclude.Include.NON_NULL) +@io.swagger.v3.oas.annotations.media.Schema(name = "{{ classNameLogicalFullNameForResponse self }}") +public class {{ classNameForResponse self }} { + +{{# if (isMapped self) }} +{{/ if }} {{# each (allEmbeddedOrMappedRelation self) as | relation | }} + {{# unless (mappedRelationIsAssociation relation)}} - {{# if (isMapped relation.target) }} - {{# if relation.required }} - @io.swagger.v3.oas.annotations.media.Schema(required = true) - {{/ if }} - {{{ relationTargetTypeDefinitionForResponse relation }}} get{{ relation.name.firstToUpperCase }}(); - {{/ if }} + private {{{ relationTargetTypeDefinitionForResponse relation }}} {{ safeName relation.name }}; + + @io.swagger.v3.oas.annotations.media.Schema(name = "{{ attribute.name }}"{{# if relation.required }}, required = true{{/ if }}) + public {{{ relationTargetTypeDefinitionForResponse relation }}} get{{ safeName relation.name.firstToUpperCase }}() { + return this.{{ safeName relation.name }}; + } + + public void set{{ relation.name.firstToUpperCase }}({{{ relationTargetTypeDefinitionForResponse relation true }}} {{ safeName relation.name }}) { + this.{{ safeName relation.name }} = {{ safeName relation.name }}; + } + {{/ unless }} {{/ each }} {{# each self.attributes as | attribute | }} - {{# unless (isQueryOrDefaultValueOrDataPropertyAttribute attribute) }} - {{# if attribute.required }} - @io.swagger.v3.oas.annotations.media.Schema(required = true) - {{/ if }} - {{{ attributeTargetTypeDefinition attribute }}} get{{ attribute.name.firstToUpperCase }}(); + {{# unless (isResponseAttribute attribute) }} + private {{{ attributeTargetTypeDefinition attribute }}} {{ safeName attribute.name }}; + + @io.swagger.v3.oas.annotations.media.Schema(name = "{{ attribute.name }}"{{# if attribute.required }}, required = true{{/ if }}) + public {{{ attributeTargetTypeDefinition attribute }}} get{{ attribute.name.firstToUpperCase }}() { + return this.{{ safeName attribute.name }}; + }; + public void set{{ attribute.name.firstToUpperCase }}({{{ attributeTargetTypeDefinition attribute }}} {{ safeName attribute.name }}) { + this.{{ safeName attribute.name }} = {{ safeName attribute.name }}; + }; {{/ unless }} {{/ each }} {{# if (isMapped self) }} + + private Boolean __deleteable; + @io.swagger.v3.oas.annotations.media.Schema(name = "__deleteable") - boolean get__deleteable(); + public Boolean get__deleteable() { + return this.__deleteable; + } + + public void set__deleteable(boolean __deleteable) { + this.__deleteable = __deleteable; + } + + private Boolean __updateable; @io.swagger.v3.oas.annotations.media.Schema(name = "__updateable") - boolean get__updateable(); + public Boolean get__updateable() { + return this.__updateable; + } + + public void set__updateable(boolean __updateable) { + this.__updateable = __updateable; + } + + private String __entityType; @io.swagger.v3.oas.annotations.media.Schema(name = "__entityType") - String get__entityType(); + public String get__entityType() { + return this.__entityType; + } + + public void set__entityType(String __entityType) { + this.__entityType = __entityType; + } + + private String __identifier; @io.swagger.v3.oas.annotations.media.Schema(name = "__identifier") - String get__identifier(); + public String get__identifier() { + return this.__identifier; + } + + public void set__identifier(String __identifier) { + this.__identifier = __identifier; + } + + private String __signedIdentifier; @io.swagger.v3.oas.annotations.media.Schema(name = "__signedIdentifier") - String get__signedIdentifier(); + public String get__signedIdentifier() { + return this.__signedIdentifier; + } + + public void set__signedIdentifier(String __signedIdentifier) { + this.__signedIdentifier = __signedIdentifier; + } + + private Integer __version; @io.swagger.v3.oas.annotations.media.Schema(name = "__version") - int get__version(); + public Integer get__version() { + return this.__version; + } + + public void set__version(Integer __version) { + this.__version = __version; + } + + private String __referenceId; + + @io.swagger.v3.oas.annotations.media.Schema(name = "__referenceId") + public String get__referenceId() { + return this.__referenceId; + } + + public void set__referenceId(String __referenceId) { + this.__referenceId = __referenceId; + } + {{/ if }} } diff --git a/judo-psm-generator-jaxrs-api/src/main/resources/rest/api/dtoNotStored.java.hbs b/judo-psm-generator-jaxrs-api/src/main/resources/rest/api/dtoNotStored.java.hbs deleted file mode 100644 index 00cc116..0000000 --- a/judo-psm-generator-jaxrs-api/src/main/resources/rest/api/dtoNotStored.java.hbs +++ /dev/null @@ -1,29 +0,0 @@ -package {{ namedElementApiPackageName self }}; - -{{# if (hasDocumentation self) }} -/** - * {{ self.documentation.decorateWithAsterisks }} - */ -{{/ if }} -public interface {{ className self }}NotStored { - - {{# each (allEmbeddedOrMappedRelationForNotStoredDTO self) as | relation | }} - {{# if relation.required }} - @io.swagger.v3.oas.annotations.media.Schema(required = true) - {{/ if }} - {{# if (mappedRelationIsAssociation relation)}} - {{{ relationTargetTypeDefinition relation true }}} get{{ relation.name.firstToUpperCase }}(); - {{ else }} - {{{ relationTargetTypeDefinition relation false }}} get{{ relation.name.firstToUpperCase }}(); - {{/ if }} - {{/ each }} - - {{# each self.attributes as | attribute | }} - {{# unless (isQueryOrDefaultValueOrDataPropertyAttribute attribute) }} - {{# if attribute.required }} - @io.swagger.v3.oas.annotations.media.Schema(required = true) - {{/ if }} - {{{ attributeTargetTypeDefinition attribute }}} get{{ attribute.name.firstToUpperCase }}(); - {{/ unless }} - {{/ each }} -} diff --git a/judo-psm-generator-jaxrs-api/src/main/resources/rest/api/querycustomizer.java.hbs b/judo-psm-generator-jaxrs-api/src/main/resources/rest/api/querycustomizer.java.hbs deleted file mode 100644 index 196cb00..0000000 --- a/judo-psm-generator-jaxrs-api/src/main/resources/rest/api/querycustomizer.java.hbs +++ /dev/null @@ -1,19 +0,0 @@ -{{> fragment.header.hbs }} - -package {{ queryCustomizerPackageName self }}; - -/** - * Query customizer for searching {@link {{ classFqName self }} } instances. - */ -public interface {{ queryCustomizerName self }} { - {{# each self.relations as | relation | }} - @io.swagger.v3.oas.annotations.media.Schema(name = "{{ relation.name }}") - {{{ relationTargetTypeDefinition relation false }}} get{{ relation.name.firstToUpperCase }}(); - {{/ each }} - - {{# each self.attributes as | attribute | }} - @io.swagger.v3.oas.annotations.media.Schema(name = "{{ attribute.name }}") - {{{ attributeTargetTypeDefinition attribute }}} get{{ attribute.name.firstToUpperCase }}(); - {{/ each }} - -} diff --git a/judo-psm-generator-jaxrs-api/src/main/resources/rest/api/range.java.hbs b/judo-psm-generator-jaxrs-api/src/main/resources/rest/api/range.java.hbs deleted file mode 100644 index 2ee4120..0000000 --- a/judo-psm-generator-jaxrs-api/src/main/resources/rest/api/range.java.hbs +++ /dev/null @@ -1,17 +0,0 @@ -package {{ namedElementApiPackageName self }}; - -{{# if (hasDocumentation self) }} -/** - * {{ self.documentation.decorateWithAsterisks }} - */ -{{/ if }} -public interface {{ className self }} { - - {{# each self.relations as | relation | }} - {{{ relationTargetTypeDefinition relation false }}} get{{ relation.name.firstToUpperCase }}(); - {{/ each }} - - {{# each self.attributes as | attribute | }} - {{{ attributeTargetTypeDefinition attribute }}} get{{ attribute.name.firstToUpperCase }}(); - {{/ each }} -} diff --git a/judo-psm-generator-jaxrs-api/src/main/resources/rest/api/rest.service.constants.fragment.hbs b/judo-psm-generator-jaxrs-api/src/main/resources/rest/api/rest.service.constants.fragment.hbs new file mode 100644 index 0000000..86fc2e4 --- /dev/null +++ b/judo-psm-generator-jaxrs-api/src/main/resources/rest/api/rest.service.constants.fragment.hbs @@ -0,0 +1,24 @@ +{{# if generateOpenApiAnnotations }} +public static final String ERROR_400_MESSAGES = "Missing object ID of operation" + + "\t\nToo few items in parameter." + + "\t\nNull item is not supported." + + "\t\nMissing required parameter." + + "\t\nConversion failed." + + "\t\nToo few items in relation." + + "\t\nToo many items in relation." + + "\t\nNull item is not supported." + + "\t\nInvalid content." + + "\t\nMissing requered relation." + + "\t\nMissing requered attribute." + + "\t\nValue is too long." + + "\t\nValue does not match pattern." + + "\t\nToo many digits." + + "\t\nInvalid scale." + + "\t\nInvalid identifier." + + "\t\nInvalid file token." + + "\t\nInvalid reference." + + "\t\nIdentifier attribute is not unique." + + "\t\nInvalid query mask." + + "\t\nInvalid identifier in query customizer." + + "\t\nEntity not found."; +{{/ if}} diff --git a/judo-psm-generator-jaxrs-api/src/main/resources/rest/api/rest.service.java.hbs b/judo-psm-generator-jaxrs-api/src/main/resources/rest/api/rest.service.java.hbs index 698cf9a..df3edcf 100644 --- a/judo-psm-generator-jaxrs-api/src/main/resources/rest/api/rest.service.java.hbs +++ b/judo-psm-generator-jaxrs-api/src/main/resources/rest/api/rest.service.java.hbs @@ -2,27 +2,16 @@ package {{ namedElementApiRestPackageName self }}; +@javax.ws.rs.Path("/") public interface {{ self.className }} { + {{> rest/api/rest.service.constants.fragment.hbs }}; public void __bindDispatcher(hu.blackbelt.judo.dispatcher.api.Dispatcher dispatcher); public void __unbindDispatcher(hu.blackbelt.judo.dispatcher.api.Dispatcher dispatcher); {{# each self.operations as | operation | }} - public javax.ws.rs.core.Response {{ safeName operation.name }}( - @javax.ws.rs.core.Context javax.ws.rs.core.SecurityContext securityContext - , @javax.ws.rs.HeaderParam("X-Judo-CountRecords") java.lang.String __countRecords - {{# if operation.isBoundOperation }} - , @javax.ws.rs.HeaderParam("X-Judo-SignedIdentifier") java.lang.String __signedIdentifier - {{/ if }} - {{# if operation.input }} - {{# if operation.input.isMany }} - , java.util.List> {{ safeName operation.input.name.firstToLower }} - {{ else }} - , java.util.Map {{ safeName operation.input.name.firstToLower }} - {{/ if }} - {{/ if }} - ); + {{> rest/api/rest.service.operation.fragment.hbs }}; {{/ each }} } diff --git a/judo-psm-generator-jaxrs-api/src/main/resources/rest/api/rest.service.operation.fragment.hbs b/judo-psm-generator-jaxrs-api/src/main/resources/rest/api/rest.service.operation.fragment.hbs new file mode 100644 index 0000000..888689b --- /dev/null +++ b/judo-psm-generator-jaxrs-api/src/main/resources/rest/api/rest.service.operation.fragment.hbs @@ -0,0 +1,105 @@ +{{# if operation.isStatelessAndHasNoInputParameter }} +@javax.ws.rs.GET +{{ else }} +@javax.ws.rs.POST +@javax.ws.rs.Consumes("application/json") +{{/ if }} +@javax.ws.rs.Produces({{# if operation.isExportOperation }}javax.ws.rs.core.MediaType.APPLICATION_OCTET_STREAM{{ else }}"application/json"{{/ if }}) +@javax.ws.rs.Path("/{{ toJAXRSPath operation model }}") +@hu.blackbelt.judo.dispatcher.api.JudoOperation("{{ operation.operationAsmFqName }}") +{{# if generateOpenApiAnnotations }} +@io.swagger.v3.oas.annotations.Operation(operationId = "{{ operation.operationAsmFqName }}", tags = {"{{ operation.getOperationTagName }}"}) +{{# if operation.output }} +{{# if operation.output.isMany }} +@io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "200", description = "Successful operation", + content = @io.swagger.v3.oas.annotations.media.Content( + array = + @io.swagger.v3.oas.annotations.media.ArraySchema( + schema = @io.swagger.v3.oas.annotations.media.Schema(name = "{{ getOperationOutputLogicalFullName operation }}", + implementation = {{ getOperationOutputFQNameForResponse operation }}.class + ) + ) + ) +) +{{ else }} +@io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "200", description = "Successful operation", + content = @io.swagger.v3.oas.annotations.media.Content( + schema = @io.swagger.v3.oas.annotations.media.Schema(name = "{{ getOperationOutputLogicalFullName operation }}", + implementation = {{ getOperationOutputFQNameForResponse operation }}.class + ) + ) +) +{{/ if }} +{{ else }} +@io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "204", description = "Successful operation") +{{/ if }} +@io.swagger.v3.oas.annotations.responses.ApiResponse( + responseCode = "400", + content = @io.swagger.v3.oas.annotations.media.Content( + array = @io.swagger.v3.oas.annotations.media.ArraySchema( + schema = @io.swagger.v3.oas.annotations.media.Schema( + implementation = {{ apiDefaultPackageName model }}.Error.class + ) + ) + ), + description = ERROR_400_MESSAGES + ) +@io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "401", description = "Authentication required." + + "\t\nToken expired.") +@io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "403", description = "Access denied." + + "\t\nUser not exists or disabled." + + "\t\nPermission denied.") +@io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "404", description = "Not found.") +@io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "422", description = "Business fault") +@io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "500", description = "Internal server error.") +{{/ if }} +public javax.ws.rs.core.Response {{ safeName operation.name }}( + @javax.ws.rs.core.Context + javax.ws.rs.core.SecurityContext securityContext, + @javax.ws.rs.HeaderParam("X-Judo-CountRecords") + java.lang.String __countRecords, + @javax.ws.rs.HeaderParam("X-Judo-Mask") + java.lang.String __mask + {{# if operation.isBoundOperation }} + , @javax.ws.rs.HeaderParam("X-Judo-SignedIdentifier") + java.lang.String __signedIdentifier + {{/ if }} + {{# if operation.input }} + {{# if operation.input.isMany }} + , + {{# if generateOpenApiAnnotations }} + @io.swagger.v3.oas.annotations.parameters.RequestBody( + content = @io.swagger.v3.oas.annotations.media.Content( + array = + @io.swagger.v3.oas.annotations.media.ArraySchema( + schema = @io.swagger.v3.oas.annotations.media.Schema(name = "{{ getOperationInputLogicalFullName operation }}", + {{# if operation.isCreateOperation}} + implementation = {{ getOperationInputFQNameForCreateRequest operation }}.class + {{ else }} + implementation = {{ getOperationInputFQNameForRequest operation }}.class + {{/ if }} + ) + ) + ) + ) + {{/ if }} + java.util.List> {{ safeName operation.input.name.firstToLower }} + {{ else }} + , + {{# if generateOpenApiAnnotations }} + @io.swagger.v3.oas.annotations.parameters.RequestBody( + content = @io.swagger.v3.oas.annotations.media.Content( + schema = @io.swagger.v3.oas.annotations.media.Schema(name = "{{ getOperationInputLogicalFullName operation }}", + {{# if operation.isCreateOperation}} + implementation = {{ getOperationInputFQNameForCreateRequest operation }}.class + {{ else }} + implementation = {{ getOperationInputFQNameForRequest operation }}.class + {{/ if }} + ) + ) + ) + {{/ if }} + java.util.Map {{ safeName operation.input.name.firstToLower }} + {{/ if }} + {{/ if }} +) \ No newline at end of file diff --git a/judo-psm-generator-jaxrs-impl/src/main/resources/rest/impl/rest.service.impl.java.hbs b/judo-psm-generator-jaxrs-impl/src/main/resources/rest/impl/rest.service.impl.java.hbs index fb44e69..48c74ba 100644 --- a/judo-psm-generator-jaxrs-impl/src/main/resources/rest/impl/rest.service.impl.java.hbs +++ b/judo-psm-generator-jaxrs-impl/src/main/resources/rest/impl/rest.service.impl.java.hbs @@ -2,8 +2,8 @@ package {{ namedElementImplRestPackageName self }}; -@javax.ws.rs.Path("/") public class {{ implClassName self }} implements {{ namedElementApiRestFqName self }} { + {{> rest/api/rest.service.constants.fragment.hbs }}; java.util.Optional __dispatcher = java.util.Optional.empty(); @@ -20,119 +20,7 @@ public class {{ implClassName self }} implements {{ namedElementApiRestFqName se {{# each self.operations as | operation | }} - {{# if operation.isStatelessAndHasNoInputParameter }} - @javax.ws.rs.GET - {{ else }} - @javax.ws.rs.POST - @javax.ws.rs.Consumes("application/json") - {{/ if }} - @javax.ws.rs.Produces({{# if operation.isExportOperation }}javax.ws.rs.core.MediaType.APPLICATION_OCTET_STREAM{{ else }}"application/json"{{/ if }}) - @javax.ws.rs.Path("/{{ toJAXRSPath operation model }}") - @hu.blackbelt.judo.dispatcher.api.JudoOperation("{{ operation.operationAsmFqName }}") - {{# if operation.output }} - {{# if operation.output.isMany }} - @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "200", description = "Successful operation", - content = @io.swagger.v3.oas.annotations.media.Content( - array = - @io.swagger.v3.oas.annotations.media.ArraySchema( - schema = @io.swagger.v3.oas.annotations.media.Schema( - implementation = {{ getOperationOutputFQName operation }}ForResponse.class - ) - ) - ) - ) - {{ else }} - @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "200", description = "Successful operation", - content = @io.swagger.v3.oas.annotations.media.Content( - schema = @io.swagger.v3.oas.annotations.media.Schema( - implementation = {{ getOperationOutputFQName operation }}ForResponse.class - ) - ) - ) - {{/ if }} - {{ else }} - @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "204", description = "Successful operation") - {{/ if }} - @io.swagger.v3.oas.annotations.responses.ApiResponse( - responseCode = "400", - content = @io.swagger.v3.oas.annotations.media.Content( - array = @io.swagger.v3.oas.annotations.media.ArraySchema( - schema = @io.swagger.v3.oas.annotations.media.Schema( - implementation = {{ apiDefaultPackageName model }}.Error.class - ) - ) - ), - description = "Missing object ID of operation" + - "\t\nToo few items in parameter." + - "\t\nNull item is not supported." + - "\t\nMissing required parameter." + - "\t\nConversion failed." + - "\t\nToo few items in relation." + - "\t\nToo many items in relation." + - "\t\nNull item is not supported." + - "\t\nInvalid content." + - "\t\nMissing requered relation." + - "\t\nMissing requered attribute." + - "\t\nValue is too long." + - "\t\nValue does not match pattern." + - "\t\nToo many digits." + - "\t\nInvalid scale." + - "\t\nInvalid identifier." + - "\t\nInvalid file token." + - "\t\nInvalid reference." + - "\t\nIdentifier attribute is not unique." + - "\t\nInvalid query mask." + - "\t\nInvalid identifier in query customizer." + - "\t\nEntity not found." - ) - @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "401", description = "Authentication required." + - "\t\nToken expired.") - @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "403", description = "Access denied." + - "\t\nUser not exists or disabled." + - "\t\nPermission denied.") - @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "404", description = "Not found.") - @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "422", description = "Business fault") - @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "500", description = "Internal server error.") - public javax.ws.rs.core.Response {{ safeName operation.name }}( - @javax.ws.rs.core.Context javax.ws.rs.core.SecurityContext securityContext, @javax.ws.rs.HeaderParam("X-Judo-CountRecords") java.lang.String __countRecords - {{# if operation.isBoundOperation }} - , @javax.ws.rs.HeaderParam("X-Judo-SignedIdentifier") java.lang.String __signedIdentifier - {{/ if }} - {{# if operation.input }} - {{# if operation.input.isMany }} - , - @io.swagger.v3.oas.annotations.parameters.RequestBody( - content = @io.swagger.v3.oas.annotations.media.Content( - array = - @io.swagger.v3.oas.annotations.media.ArraySchema( - schema = @io.swagger.v3.oas.annotations.media.Schema( - {{# if operation.isCreateOperation}} - implementation = {{ getOperationInputFQName operation }}NotStored.class - {{ else }} - implementation = {{ getOperationInputFQName operation }}.class - {{/ if }} - ) - ) - ) - ) - java.util.List> {{ safeName operation.input.name.firstToLower }} - {{ else }} - , - @io.swagger.v3.oas.annotations.parameters.RequestBody( - content = @io.swagger.v3.oas.annotations.media.Content( - schema = @io.swagger.v3.oas.annotations.media.Schema( - {{# if operation.isCreateOperation}} - implementation = {{ getOperationInputFQName operation }}NotStored.class - {{ else }} - implementation = {{ getOperationInputFQName operation }}.class - {{/ if }} - ) - ) - ) - java.util.Map {{ safeName operation.input.name.firstToLower }} - {{/ if }} - {{/ if }} - ) { + {{> rest/api/rest.service.operation.fragment.hbs }} { if (!__dispatcher.isPresent()) { return javax.ws.rs.core.Response.status(javax.ws.rs.core.Response.Status.SERVICE_UNAVAILABLE).build(); } @@ -141,6 +29,10 @@ public class {{ implClassName self }} implements {{ namedElementApiRestFqName se if (__countRecords != null && __countRecords.trim().length() > 0) { parameters.put("__countRecords", Boolean.TRUE); } + if (__mask != null && __mask.trim().length() > 0) { + parameters.put("__mask", __mask); + } + {{# if operation.isBoundOperation }} parameters.put("__signedIdentifier", __signedIdentifier); {{/ if }} @@ -180,8 +72,5 @@ public class {{ implClassName self }} implements {{ namedElementApiRestFqName se } return responseBuilder.build(); } - - {{/ each }} - } diff --git a/judo-psm-generator-jaxrs-test/pom.xml b/judo-psm-generator-jaxrs-test/pom.xml index 1799937..4de71f5 100644 --- a/judo-psm-generator-jaxrs-test/pom.xml +++ b/judo-psm-generator-jaxrs-test/pom.xml @@ -116,6 +116,26 @@ 3.1.0 + + org.junit.jupiter + junit-jupiter-engine + 5.9.2 + test + + + + org.hamcrest + hamcrest + 2.2 + test + + + com.fasterxml.jackson.datatype + jackson-datatype-jdk8 + 2.16.1 + test + + @@ -143,6 +163,7 @@ hu.blackbelt.judo.psm.generator.jaxrs.test.osgi true true + true diff --git a/judo-psm-generator-jaxrs-test/src/test/java/hu/blackbelt/judo/generator/psm/jaxrs/test/SerializationTest.java b/judo-psm-generator-jaxrs-test/src/test/java/hu/blackbelt/judo/generator/psm/jaxrs/test/SerializationTest.java new file mode 100644 index 0000000..16ab695 --- /dev/null +++ b/judo-psm-generator-jaxrs-test/src/test/java/hu/blackbelt/judo/generator/psm/jaxrs/test/SerializationTest.java @@ -0,0 +1,52 @@ +package hu.blackbelt.judo.generator.psm.jaxrs.test; + +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.datatype.jdk8.Jdk8Module; +import hu.blackbelt.judo.psm.generator.jaxrs.test.api.actiongrouptest.CreatureRequest; +import org.junit.jupiter.api.Test; + +import java.util.Optional; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.*; + +public class SerializationTest { + + @Test + public void testNullValueSerialization() + throws JsonProcessingException { + ObjectMapper mapper = new ObjectMapper(); + mapper.registerModule(new Jdk8Module()); + CreatureRequest creature = new CreatureRequest(); + + String creatureAsString = mapper.writeValueAsString(creature); + assertThat(creatureAsString, equalTo("{}")); + + creature.setName(Optional.empty()); + creatureAsString = mapper.writeValueAsString(creature); + assertThat(creatureAsString, equalTo("{\"name\":null}")); + + creature.setName(Optional.of("Test")); + creatureAsString = mapper.writeValueAsString(creature); + assertThat(creatureAsString, equalTo("{\"name\":\"Test\"}")); + } + + @Test + public void testNullValueDeserialization() + throws JsonProcessingException { + ObjectMapper mapper = new ObjectMapper(); + mapper.registerModule(new Jdk8Module()); + + CreatureRequest creature = mapper.readValue("{}", CreatureRequest.class); + assertThat(creature.getName(), nullValue()); + + creature = mapper.readValue("{\"name\":null}", CreatureRequest.class); + assertThat(creature.getName(), equalTo(Optional.empty())); + + creature = mapper.readValue("{\"name\":\"Test\"}", CreatureRequest.class); + assertThat(creature.getName(), equalTo(Optional.of("Test"))); + + } + +}