Skip to content

Commit

Permalink
Implemented and tested #78
Browse files Browse the repository at this point in the history
  • Loading branch information
jeaf-anaptecs committed Jul 5, 2024
1 parent 07ab4cc commit 981f727
Show file tree
Hide file tree
Showing 180 changed files with 2,077 additions and 1,599 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -488,6 +488,8 @@ public class GeneratorMojo extends AbstractMojo {
@Parameter(required = false, defaultValue = "false")
private Boolean generateEqualsAndHashCodeForCompositeDataTypes;

// Properties

/**
* Switch defines if <code>equals()</code> and <code>hashCode()</code> should be generated for OpenAPI data type POJOs
* and ServiceObjects.
Expand Down Expand Up @@ -521,6 +523,58 @@ public class GeneratorMojo extends AbstractMojo {
@Parameter(required = false)
private String notEmptyAnnotationNameForMultiValuedProperties = "";

// Services

/**
* Switch can be used to enable that <code>NotNull</code> annotation is generated for service operations.
*/
@Parameter(required = false, defaultValue = "false")
private Boolean generateNotNullAnnotationForSingleValuedServiceParameters;

/**
* Parameter defines the name of the <code>NotNull</code> annotation that should be used for for service operations.
*/
@Parameter(required = false)
private String notNullAnnotationNameForSingleValuedServiceParameters = "";

/**
* Switch can be used to enable that <code>NotEmpty</code> annotation is generated for service operations.
*/
@Parameter(required = false, defaultValue = "false")
private Boolean generateNotEmptyAnnotationForMultiValuedServiceParameters;

/**
* Parameter defines the name of the <code>NotEmpty</code> annotation that should be used for service operations.
*/
@Parameter(required = false)
private String notEmptyAnnotationNameForMultiValuedServiceParameters = "";

// REST Controller

/**
* Switch can be used to enable that <code>NotEmpty</code> annotation is generated for REST resources.
*/
@Parameter(required = false, defaultValue = "false")
private Boolean generateNotNullAnnotationForSingleValuedRESTParameters;

/**
* Parameter defines the name of the <code>NotEmpty</code> annotation that should be used for REST resources.
*/
@Parameter(required = false)
private String notNullAnnotationNameForSingleValuedRESTParameters = "";

/**
* Switch can be used to enable that <code>NotEmpty</code> annotation is generated for for REST resources.
*/
@Parameter(required = false, defaultValue = "false")
private Boolean generateNotEmptyAnnotationForMultiValuedRESTParameters;

/**
* Parameter defines the name of the <code>NotEmpty</code> annotation that should be used for REST resources.
*/
@Parameter(required = false)
private String notEmptyAnnotationNameForMultiValuedRESTParameters = "";

/**
* Switch defines whether POJO's should be serializable or not.
*/
Expand Down Expand Up @@ -1543,12 +1597,45 @@ private void showStartupInfo( ) {
}

if (generateNotEmptyAnnotationForMultiValuedProperties) {
lLog.info("Generate NotNull annotation for ");
lLog.info("Generate NotEmpty annotation for ");
lLog.info(
"multi valued properties: " + generateNotEmptyAnnotationForMultiValuedProperties);
lLog.info("NotEmpty annotation name: " + notEmptyAnnotationNameForMultiValuedProperties);
}

if (generateNotNullAnnotationForSingleValuedServiceParameters) {
lLog.info("Generate NotNull annotation for ");
lLog.info("single valued service parameters: "
+ generateNotNullAnnotationForSingleValuedServiceParameters);
lLog.info(
"NotNull annotation name: " + notNullAnnotationNameForSingleValuedServiceParameters);
}

if (generateNotEmptyAnnotationForMultiValuedServiceParameters) {
lLog.info("Generate NotEmpty annotation for ");
lLog.info("multi valued service parameters: "
+ generateNotEmptyAnnotationForMultiValuedServiceParameters);
lLog.info(
"NotEmpty annotation name: " + notEmptyAnnotationNameForMultiValuedServiceParameters);
}

if (generateNotNullAnnotationForSingleValuedRESTParameters) {
lLog.info("Generate NotNull annotation for ");
lLog.info(
"single valued REST parameters: "
+ generateNotNullAnnotationForSingleValuedRESTParameters);
lLog.info(
"NotNull annotation name: " + notNullAnnotationNameForSingleValuedRESTParameters);
}

if (generateNotEmptyAnnotationForMultiValuedRESTParameters) {
lLog.info("Generate NotEmpty annotation for ");
lLog.info("multi valued REST parameters: "
+ generateNotEmptyAnnotationForMultiValuedRESTParameters);
lLog.info(
"NotEmpty annotation name: " + notEmptyAnnotationNameForMultiValuedRESTParameters);
}

if (generateDomainObjects) {
lLog.info("Generate Domain Objects: " + generateDomainObjects);
lLog.info("Generate Constants for Attribute Names: " + generateConstantsForAttributeNames);
Expand Down Expand Up @@ -1884,6 +1971,7 @@ private boolean runUMLGenerator( ) throws MojoFailureException {
System.setProperty("switch.gen.equalsAndHashCode.openapi.datatype",
generateEqualsAndHashCodeForOpenAPIDataTypes.toString());

// NotNull / NotEmpty annotations for properties / POJOs / ServiceObjects
System.setProperty(PROPERTY_PREFIX + "generateNotNullAnnotationForSingleValuedProperties",
generateNotNullAnnotationForSingleValuedProperties.toString());
System.setProperty(PROPERTY_PREFIX + "notNullAnnotationNameForSingleValuedProperties",
Expand All @@ -1893,6 +1981,26 @@ private boolean runUMLGenerator( ) throws MojoFailureException {
System.setProperty(PROPERTY_PREFIX + "notEmptyAnnotationNameForMultiValuedProperties",
notEmptyAnnotationNameForMultiValuedProperties.toString());

// NotNull / NotEmpty annotations for services
System.setProperty(PROPERTY_PREFIX + "generateNotNullAnnotationForSingleValuedServiceParameters",
generateNotNullAnnotationForSingleValuedServiceParameters.toString());
System.setProperty(PROPERTY_PREFIX + "notNullAnnotationNameForSingleValuedServiceParameters",
notNullAnnotationNameForSingleValuedServiceParameters);
System.setProperty(PROPERTY_PREFIX + "generateNotEmptyAnnotationForMultiValuedServiceParameters",
generateNotEmptyAnnotationForMultiValuedServiceParameters.toString());
System.setProperty(PROPERTY_PREFIX + "notEmptyAnnotationNameForMultiValuedServiceParameters",
notEmptyAnnotationNameForMultiValuedServiceParameters.toString());

// NotNull / NotEmpty annotations for REST parameters
System.setProperty(PROPERTY_PREFIX + "generateNotNullAnnotationForSingleValuedRESTParameters",
generateNotNullAnnotationForSingleValuedRESTParameters.toString());
System.setProperty(PROPERTY_PREFIX + "notNullAnnotationNameForSingleValuedRESTParameters",
notNullAnnotationNameForSingleValuedRESTParameters);
System.setProperty(PROPERTY_PREFIX + "generateNotEmptyAnnotationForMultiValuedRESTParameters",
generateNotEmptyAnnotationForMultiValuedRESTParameters.toString());
System.setProperty(PROPERTY_PREFIX + "notEmptyAnnotationNameForMultiValuedRESTParameters",
notEmptyAnnotationNameForMultiValuedRESTParameters.toString());

System.setProperty("switch.gen.immutable.classes", generateImmutableClasses.toString());
System.setProperty("switch.gen.serializable.pojos", makePOJOsSerializable.toString());
System.setProperty("switch.gen.heavy.extensible.enums", generateHeavyExtensibleEnums.toString());
Expand Down
18 changes: 15 additions & 3 deletions jeaf-generator-test-open-api-service-objects/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -155,11 +155,23 @@
<javaGenericSoftLinkType>com.anaptecs.jeaf.junit.openapi.base.SoftLink</javaGenericSoftLinkType>
<softLinkSuffix>ID</softLinkSuffix>

<!-- NotNull / NotEmpty congfiguration for properties -->
<generateNotNullAnnotationForSingleValuedProperties>true</generateNotNullAnnotationForSingleValuedProperties>
<notNullAnnotationNameForSingleValuedProperties>com.anaptecs.annotations.MyNotNull</notNullAnnotationNameForSingleValuedProperties>

<notNullAnnotationNameForSingleValuedProperties>com.anaptecs.annotations.MyNotNullProperty</notNullAnnotationNameForSingleValuedProperties>
<generateNotEmptyAnnotationForMultiValuedProperties>true</generateNotEmptyAnnotationForMultiValuedProperties>
<notEmptyAnnotationNameForMultiValuedProperties>com.anaptecs.annotations.MyNotEmpty</notEmptyAnnotationNameForMultiValuedProperties>
<notEmptyAnnotationNameForMultiValuedProperties>com.anaptecs.annotations.MyNotEmptyProperty</notEmptyAnnotationNameForMultiValuedProperties>

<!-- NotNull / NotEmpty congfiguration for services -->
<generateNotNullAnnotationForSingleValuedServiceParameters>true</generateNotNullAnnotationForSingleValuedServiceParameters>
<notNullAnnotationNameForSingleValuedServiceParameters>com.anaptecs.annotations.MyNotNullServiceParam</notNullAnnotationNameForSingleValuedServiceParameters>
<generateNotEmptyAnnotationForMultiValuedServiceParameters>true</generateNotEmptyAnnotationForMultiValuedServiceParameters>
<notEmptyAnnotationNameForMultiValuedServiceParameters>com.anaptecs.annotations.MyNotEmptyServiceParam</notEmptyAnnotationNameForMultiValuedServiceParameters>

<!-- NotNull / NotEmpty congfiguration for REST -->
<generateNotNullAnnotationForSingleValuedRESTParameters>true</generateNotNullAnnotationForSingleValuedRESTParameters>
<notNullAnnotationNameForSingleValuedRESTParameters>com.anaptecs.annotations.MyNotNullRESTParam</notNullAnnotationNameForSingleValuedRESTParameters>
<generateNotEmptyAnnotationForMultiValuedRESTParameters>true</generateNotEmptyAnnotationForMultiValuedRESTParameters>
<notEmptyAnnotationNameForMultiValuedRESTParameters>com.anaptecs.annotations.MyNotEmptyRESTParam</notEmptyAnnotationNameForMultiValuedRESTParameters>

<!-- Define information that are written to file headers -->
<fileHeaderCompany>anaptecs GmbH, Ricarda-Huch-Str. 71, 72760 Reutlingen, Germany</fileHeaderCompany>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import javax.validation.Valid;
import javax.validation.constraints.NotNull;

import com.anaptecs.annotations.MyNotNull;
import com.anaptecs.annotations.MyNotNullProperty;
import com.anaptecs.jeaf.core.api.ServiceObject;
import com.anaptecs.jeaf.tools.api.validation.ValidationTools;
import com.anaptecs.jeaf.xfun.api.checks.Check;
Expand Down Expand Up @@ -94,7 +94,7 @@ protected Builder( BankAccount pObject ) {
* @param pIban Value to which {@link #iban} should be set.
* @return {@link Builder} Instance of this builder to support chaining setters. Method never returns null.
*/
public Builder setIban( @MyNotNull String pIban ) {
public Builder setIban( @MyNotNullProperty String pIban ) {
// Assign value to attribute
iban = pIban;
return this;
Expand Down Expand Up @@ -129,7 +129,7 @@ public BankAccount buildValidated( ) throws ConstraintViolationException {
*
* @return {@link String} Value to which {@link #iban} is set.
*/
@MyNotNull
@MyNotNullProperty
public String getIban( ) {
return iban;
}
Expand All @@ -139,7 +139,7 @@ public String getIban( ) {
*
* @param pIban Value to which {@link #iban} should be set.
*/
public void setIban( @MyNotNull String pIban ) {
public void setIban( @MyNotNullProperty String pIban ) {
// Assign value to attribute
iban = pIban;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import javax.ws.rs.HeaderParam;
import javax.ws.rs.QueryParam;

import com.anaptecs.annotations.MyNotNull;
import com.anaptecs.annotations.MyNotNullProperty;
import com.anaptecs.jeaf.core.api.ServiceObject;
import com.anaptecs.jeaf.tools.api.validation.ValidationTools;
import com.anaptecs.jeaf.xfun.api.checks.Check;
Expand Down Expand Up @@ -123,7 +123,7 @@ protected Builder( BeanParameter pObject ) {
* @param pAccessToken Value to which {@link #accessToken} should be set.
* @return {@link Builder} Instance of this builder to support chaining setters. Method never returns null.
*/
public Builder setAccessToken( @MyNotNull String pAccessToken ) {
public Builder setAccessToken( @MyNotNullProperty String pAccessToken ) {
// Assign value to attribute
accessToken = pAccessToken;
return this;
Expand All @@ -135,7 +135,7 @@ public Builder setAccessToken( @MyNotNull String pAccessToken ) {
* @param pLanguage Value to which {@link #language} should be set.
* @return {@link Builder} Instance of this builder to support chaining setters. Method never returns null.
*/
public Builder setLanguage( @MyNotNull Locale pLanguage ) {
public Builder setLanguage( @MyNotNullProperty Locale pLanguage ) {
// Assign value to attribute
language = pLanguage;
return this;
Expand All @@ -148,7 +148,7 @@ public Builder setLanguage( @MyNotNull Locale pLanguage ) {
* @return {@link Builder} Instance of this builder to support chaining setters. Method never returns null.
*/
@Deprecated
public Builder setOldStyle( @MyNotNull String pOldStyle ) {
public Builder setOldStyle( @MyNotNullProperty String pOldStyle ) {
// Assign value to attribute
oldStyle = pOldStyle;
return this;
Expand Down Expand Up @@ -183,7 +183,7 @@ public BeanParameter buildValidated( ) throws ConstraintViolationException {
*
* @return {@link String} Value to which {@link #accessToken} is set.
*/
@MyNotNull
@MyNotNullProperty
public String getAccessToken( ) {
return accessToken;
}
Expand All @@ -193,7 +193,7 @@ public String getAccessToken( ) {
*
* @param pAccessToken Value to which {@link #accessToken} should be set.
*/
public void setAccessToken( @MyNotNull String pAccessToken ) {
public void setAccessToken( @MyNotNullProperty String pAccessToken ) {
// Assign value to attribute
accessToken = pAccessToken;
}
Expand All @@ -203,7 +203,7 @@ public void setAccessToken( @MyNotNull String pAccessToken ) {
*
* @return {@link Locale} Value to which {@link #language} is set.
*/
@MyNotNull
@MyNotNullProperty
public Locale getLanguage( ) {
return language;
}
Expand All @@ -213,7 +213,7 @@ public Locale getLanguage( ) {
*
* @param pLanguage Value to which {@link #language} should be set.
*/
public void setLanguage( @MyNotNull Locale pLanguage ) {
public void setLanguage( @MyNotNullProperty Locale pLanguage ) {
// Assign value to attribute
language = pLanguage;
}
Expand All @@ -224,7 +224,7 @@ public void setLanguage( @MyNotNull Locale pLanguage ) {
* @return {@link String} Value to which {@link #oldStyle} is set.
*/
@Deprecated
@MyNotNull
@MyNotNullProperty
public String getOldStyle( ) {
return oldStyle;
}
Expand All @@ -235,7 +235,7 @@ public String getOldStyle( ) {
* @param pOldStyle Value to which {@link #oldStyle} should be set.
*/
@Deprecated
public void setOldStyle( @MyNotNull String pOldStyle ) {
public void setOldStyle( @MyNotNullProperty String pOldStyle ) {
// Assign value to attribute
oldStyle = pOldStyle;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import javax.validation.Valid;
import javax.validation.constraints.NotNull;

import com.anaptecs.annotations.MyNotNull;
import com.anaptecs.annotations.MyNotNullProperty;
import com.anaptecs.jeaf.core.api.ServiceObject;
import com.anaptecs.jeaf.tools.api.validation.ValidationTools;
import com.anaptecs.jeaf.xfun.api.checks.Check;
Expand Down Expand Up @@ -118,7 +118,7 @@ protected Builder( BidirectA pObject ) {
* @param pParent Value to which {@link #parent} should be set.
* @return {@link Builder} Instance of this builder to support chaining setters. Method never returns null.
*/
public Builder setParent( @MyNotNull BidirectA pParent ) {
public Builder setParent( @MyNotNullProperty BidirectA pParent ) {
parent = pParent;
return this;
}
Expand Down Expand Up @@ -214,7 +214,7 @@ void clearTransientBs( ) {
*
* @return {@link BidirectA} Value to which {@link #parent} is set.
*/
@MyNotNull
@MyNotNullProperty
public BidirectA getParent( ) {
// Due to restrictions in JSON serialization / deserialization bi-directional associations need a special handling
// after an object was deserialized.
Expand All @@ -230,7 +230,7 @@ public BidirectA getParent( ) {
*
* @param pParent Value to which {@link #parent} should be set.
*/
public void setParent( @MyNotNull BidirectA pParent ) {
public void setParent( @MyNotNullProperty BidirectA pParent ) {
// Release already referenced object before setting a new association.
if (parent != null) {
parent.unsetTransientChild();
Expand Down Expand Up @@ -261,7 +261,7 @@ public final void unsetParent( ) {
*
* @return {@link BidirectA} Value to which {@link #transientChild} is set.
*/
@MyNotNull
@MyNotNullProperty
public BidirectA getTransientChild( ) {
return transientChild;
}
Expand All @@ -271,7 +271,7 @@ public BidirectA getTransientChild( ) {
*
* @param pTransientChild Value to which {@link #transientChild} should be set.
*/
void setTransientChild( @MyNotNull BidirectA pTransientChild ) {
void setTransientChild( @MyNotNullProperty BidirectA pTransientChild ) {
// Release already referenced object before setting a new association.
if (transientChild != null) {
transientChild.unsetParent();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import javax.validation.Valid;
import javax.validation.constraints.NotNull;

import com.anaptecs.annotations.MyNotNull;
import com.anaptecs.annotations.MyNotNullProperty;
import com.anaptecs.jeaf.core.api.ServiceObject;
import com.anaptecs.jeaf.tools.api.validation.ValidationTools;
import com.anaptecs.jeaf.xfun.api.checks.Check;
Expand Down Expand Up @@ -113,7 +113,7 @@ protected Builder( BidirectB pObject ) {
* @param pA Value to which {@link #a} should be set.
* @return {@link Builder} Instance of this builder to support chaining setters. Method never returns null.
*/
public Builder setA( @MyNotNull BidirectA pA ) {
public Builder setA( @MyNotNullProperty BidirectA pA ) {
a = pA;
return this;
}
Expand Down Expand Up @@ -147,7 +147,7 @@ public BidirectB buildValidated( ) throws ConstraintViolationException {
*
* @return {@link BidirectA} Value to which {@link #a} is set.
*/
@MyNotNull
@MyNotNullProperty
public BidirectA getA( ) {
// Due to restrictions in JSON serialization / deserialization bi-directional associations need a special handling
// after an object was deserialized.
Expand All @@ -164,7 +164,7 @@ public BidirectA getA( ) {
*
* @param pA Value to which {@link #a} should be set.
*/
public void setA( @MyNotNull BidirectA pA ) {
public void setA( @MyNotNullProperty BidirectA pA ) {
// Release already referenced object before setting a new association.
if (a != null) {
a.removeFromTransientBs((BidirectB) this);
Expand Down
Loading

0 comments on commit 981f727

Please sign in to comment.