Skip to content

Commit

Permalink
Implemented and tested #189
Browse files Browse the repository at this point in the history
  • Loading branch information
jeaf-anaptecs committed Jun 3, 2024
1 parent 3cf6529 commit a142357
Show file tree
Hide file tree
Showing 152 changed files with 22,964 additions and 20,351 deletions.
2 changes: 1 addition & 1 deletion jeaf-generator-code-styles/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<parent>
<groupId>com.anaptecs.jeaf.generator</groupId>
<artifactId>jeaf-generator-project</artifactId>
<version>1.20.3-SNAPSHOT</version>
<version>1.21.0-SNAPSHOT</version>
</parent>

<name>JEAF Generator Code Styles</name>
Expand Down
2 changes: 1 addition & 1 deletion jeaf-generator-maven-plugin/.factorypath
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<factorypath>
<factorypathentry kind="VARJAR" id="M2_REPO/com/anaptecs/jeaf/generator/jeaf-generator/1.20.1-SNAPSHOT/jeaf-generator-1.20.1-SNAPSHOT.jar" enabled="true" runInBatchMode="false"/>
<factorypathentry kind="VARJAR" id="M2_REPO/com/anaptecs/jeaf/generator/jeaf-generator/1.20.3-SNAPSHOT/jeaf-generator-1.20.3-SNAPSHOT.jar" enabled="true" runInBatchMode="false"/>
<factorypathentry kind="VARJAR" id="M2_REPO/com/anaptecs/jeaf/generator/jeaf-generator-messages/1.6.13/jeaf-generator-messages-1.6.13.jar" enabled="true" runInBatchMode="false"/>
<factorypathentry kind="VARJAR" id="M2_REPO/org/apache/poi/poi-ooxml/5.2.3/poi-ooxml-5.2.3.jar" enabled="true" runInBatchMode="false"/>
<factorypathentry kind="VARJAR" id="M2_REPO/org/apache/poi/poi/5.2.3/poi-5.2.3.jar" enabled="true" runInBatchMode="false"/>
Expand Down
2 changes: 1 addition & 1 deletion jeaf-generator-maven-plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<groupId>com.anaptecs.jeaf.generator</groupId>
<artifactId>jeaf-generator-project</artifactId>
<version>1.20.3-SNAPSHOT</version>
<version>1.21.0-SNAPSHOT</version>
</parent>

<artifactId>jeaf-generator-maven-plugin</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion jeaf-generator-test-activities-api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<groupId>com.anaptecs.jeaf.generator</groupId>
<artifactId>jeaf-generator-project</artifactId>
<version>1.20.3-SNAPSHOT</version>
<version>1.21.0-SNAPSHOT</version>
</parent>

<name>JEAF Generator Test Activities API</name>
Expand Down
2 changes: 1 addition & 1 deletion jeaf-generator-test-activities-impl/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<groupId>com.anaptecs.jeaf.generator</groupId>
<artifactId>jeaf-generator-project</artifactId>
<version>1.20.3-SNAPSHOT</version>
<version>1.21.0-SNAPSHOT</version>
</parent>

<name>JEAF Generator Test Activities Impl</name>
Expand Down
2 changes: 1 addition & 1 deletion jeaf-generator-test-custom-extension-usage/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<groupId>com.anaptecs.jeaf.generator</groupId>
<artifactId>jeaf-generator-project</artifactId>
<version>1.20.3-SNAPSHOT</version>
<version>1.21.0-SNAPSHOT</version>
</parent>

<name>JEAF Generator Test Custom Extension Usage</name>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.anaptecs.jeaf.junit.openapi.base;

/**
* Test for enums with dynamic literals.
*
* @author JEAF Generator
* @version JEAF Release 1.6.x
*/
public enum DynamicEnum {
STATIC_LITERAL,
/**
* This is a fake dynamic literal.
*/
FAKE;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,200 @@
package com.anaptecs.jeaf.junit.openapi.base;

import com.anaptecs.jeaf.xfun.api.checks.Check;

public final class DynamicExtensibleEnum {
public static enum DynamicExtensibleEnumType {
STATIC_LITERAL,
/**
* Literal UNKNOWN is used in case that an unknown literal of this enumeration is received e.g. via an external
* interface.
*/
UNKNOWN;
}

public static final DynamicExtensibleEnum STATIC_LITERAL =
new DynamicExtensibleEnum(DynamicExtensibleEnumType.STATIC_LITERAL);

/**
* Literal of the enumeration that is represented by this instance.
*/
private DynamicExtensibleEnumType literal;

/**
* In case that the literal is unknown then also it's actual name is still available as
* <code>unknownLiteralName</code>
*/
private String unknownLiteralName;

/**
* Method returns extensible enumeration based on the passed name. If the literal name is unknown then an instance
* representing "unknown" will be returned.
*
* @param pLiteral Enumeration literal that should be used to initialize the extensible enumeration. The parameter
* must not be null.
* @return
*/
public static DynamicExtensibleEnum valueOf( String pLiteralName ) {
DynamicExtensibleEnum lEnum;
try {
DynamicExtensibleEnumType lEnumValue = Enum.valueOf(DynamicExtensibleEnumType.class, pLiteralName);
switch (lEnumValue) {
case STATIC_LITERAL:
lEnum = STATIC_LITERAL;
break;
default:
lEnum = new DynamicExtensibleEnum(lEnumValue);
}
}
catch (IllegalArgumentException e) {
lEnum = new DynamicExtensibleEnum(pLiteralName);
}
return lEnum;
}

/**
* Default constructor is only intended to be used for deserialization as many frameworks required that. For "normal"
* object creation available constructors {@link #DynamicExtensibleEnum(DynamicExtensibleEnumType)} and
* {@link #DynamicExtensibleEnum(String)} should be used.
*/
DynamicExtensibleEnum( ) {
}

/**
* Initialize object from real enumeration literal
*
* @param pLiteral Enumeration literal that should be used to initialize the extensible enumeration. The parameter
* must not be null.
*/
public DynamicExtensibleEnum( DynamicExtensibleEnumType pLiteral ) {
Check.checkInvalidParameterNull(pLiteral, "pLiteral");
literal = pLiteral;
unknownLiteralName = null;
}

/**
* Initialize object using the name of the literal.
*
* @param pLiteralName Literal name that should be used to initialize the extensible enumeration. If the parameter is
* null or has an unknown literal name then a "unknown" version will be created.
*
* @see DynamicExtensibleEnum#isUnknownLiteral()
*/
public DynamicExtensibleEnum( String pLiteralName ) {
try {
literal = Enum.valueOf(DynamicExtensibleEnumType.class, pLiteralName);
unknownLiteralName = null;
}
// Literal is unknown
catch (IllegalArgumentException e) {
literal = DynamicExtensibleEnumType.UNKNOWN;
unknownLiteralName = pLiteralName;
}
}

/**
* Method returns the literal that is represented by this object.
*
* @return {@link DynamicExtensibleEnum} Literal that is represented by this object. The method never returns null.
*/
public DynamicExtensibleEnumType getLiteral( ) {
return literal;
}

/**
* Method checks if the represented literal is actually unknown or not.
*
* @return boolean Method returns true if this object represents an unknown literal.
*/
public boolean isUnknownLiteral( ) {
return literal == DynamicExtensibleEnumType.UNKNOWN;
}

/**
* Method returns the actual name of the unknown literal
*
* @return {@link String} Name of the unknown literal or null in case that the literal is known.
*/
public String getUnknownLiteralName( ) {
return unknownLiteralName;
}

/**
* {@link Object#hashCode()}
*/
@Override
public int hashCode( ) {
int lHashCode;
if (unknownLiteralName != null && this.isUnknownLiteral() == true) {
lHashCode = unknownLiteralName.hashCode();
}
else {
lHashCode = literal.hashCode();
}
return lHashCode;
}

/**
* {@link Object#equals(Object)}
*/
@Override
public boolean equals( Object pObject ) {
boolean lEquals;
if (pObject != null) {
if (this == pObject) {
lEquals = true;
}
// Passed object is of same type
else if (this.getClass() == pObject.getClass()) {
DynamicExtensibleEnum lEnum = (DynamicExtensibleEnum) pObject;
// Compare if unknown literal is the same
if (this.isUnknownLiteral() && lEnum.isUnknownLiteral()) {
if (this.unknownLiteralName != null) {
lEquals = this.unknownLiteralName.equals(lEnum.unknownLiteralName);
}
else if (lEnum.unknownLiteralName == null) {
lEquals = true;
}
else {
lEquals = false;
}
}
// Compare based on literals
else {
lEquals = this.literal == lEnum.literal;
}
}
// Passed object is of different type
else {
lEquals = false;
}
}
// Passed object is null.
else {
lEquals = false;
}
return lEquals;
}

/**
* {@link Object#toString()}
*/
@Override
public String toString( ) {
String lLiteralName;
if (this.isUnknownLiteral() == false) {
lLiteralName = this.getLiteral().name();
}
// Object represents unknown literal.
else {
String lUnknownLiteralName = this.getUnknownLiteralName();
if (lUnknownLiteralName != null) {
lLiteralName = lUnknownLiteralName;
}
else {
lLiteralName = this.getLiteral().name();
}
}
return lLiteralName;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -695,6 +695,23 @@ components:
timeUnit:
$ref: '#/components/schemas/TimeUnit'

# com.anaptecs.jeaf.junit.openapi.base.DynamicEnum
DynamicEnum:
description: >-
Test for enums with dynamic literals.
type: string
enum:
- STATIC_LITERAL
- FAKE

# com.anaptecs.jeaf.junit.openapi.base.DynamicExtensibleEnum
DynamicExtensibleEnum:
description: >-
type: string
x-extensible-enum:
- STATIC_LITERAL
- FAKE

# com.anaptecs.jeaf.junit.openapi.base.Entity
Entity:
type: string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ openapi: 3.1.0

info:
title: DataTypeUsage
version: 1.20.3-SNAPSHOT
version: 1.21.0-SNAPSHOT
termsOfService: https://www.jeaf-generator.io/terms-of-use
contact:
name: Maven Contact
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ openapi: 3.1.0

info:
title: Datatypes
version: 1.20.3-SNAPSHOT
version: 1.21.0-SNAPSHOT
termsOfService: https://www.jeaf-generator.io/terms-of-use
contact:
name: Maven Contact
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ openapi: 3.1.0

info:
title: Product Services
version: 1.20.3-SNAPSHOT
version: 1.21.0-SNAPSHOT
description: >-
This component represents the OpenAPI interface of the accounting service.
Expand Down
2 changes: 1 addition & 1 deletion jeaf-generator-test-custom-extension/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<groupId>com.anaptecs.jeaf.generator</groupId>
<artifactId>jeaf-generator-project</artifactId>
<version>1.20.3-SNAPSHOT</version>
<version>1.21.0-SNAPSHOT</version>
</parent>

<name>JEAF Generator Test Custom Extension</name>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
«IMPORT uml»
«IMPORT JMM»

«DEFINE AddDynamicLiterals FOR JEAFEnumeration»
«IF !ownedLiteral.isEmpty», «ENDIF»
/**
* This is a fake dynamic literal.
*/
FAKE
«ENDDEFINE»
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@

cached List[String] getDynamicLiteralNames(JMM::OpenAPIEnumeration enum):
{"FAKE"}.toList();

cached List[String] getDynamicLiteralDescriptions(JMM::OpenAPIEnumeration enum):
{"Fake literal"}.toList();

cached List[boolean] getDynamicLiteralDeprecations(JMM::OpenAPIEnumeration enum):
{true}.toList();
2 changes: 1 addition & 1 deletion jeaf-generator-test-deprecation-report/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<groupId>com.anaptecs.jeaf.generator</groupId>
<artifactId>jeaf-generator-project</artifactId>
<version>1.20.3-SNAPSHOT</version>
<version>1.21.0-SNAPSHOT</version>
</parent>

<name>JEAF Generator Test Deprecation Report</name>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,8 @@ DirectedEdge | | Just a simple comment. |
DiscountOffer | | |
DoubleCode | | |
DoubleCodeType | | |
DynamicEnum | | Test for enums with dynamic literals. |
DynamicExtensibleEnum | | |
Entity | | |
EnumTest | | |
EnumWithProperties | | |
Expand Down Expand Up @@ -370,6 +372,8 @@ DirectedEdge | | Just a simple comment. |
DiscountOffer | | |
DoubleCode | | |
DoubleCodeType | | |
DynamicEnum | | Test for enums with dynamic literals. |
DynamicExtensibleEnum | | |
Entity | | |
EnumTest | | |
ExtensibleEnum | | |
Expand Down
2 changes: 1 addition & 1 deletion jeaf-generator-test-domain-objects/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<groupId>com.anaptecs.jeaf.generator</groupId>
<artifactId>jeaf-generator-project</artifactId>
<version>1.20.3-SNAPSHOT</version>
<version>1.21.0-SNAPSHOT</version>
</parent>

<name>JEAF Generator Test Domain Objects</name>
Expand Down
Loading

0 comments on commit a142357

Please sign in to comment.