Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#nan qeex rs service methods, qinclude #59

Merged
merged 1 commit into from
Nov 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

<groupId>it.n-ess.queryable</groupId>
<artifactId>queryable-maven-plugin</artifactId>
<version>3.0.2</version>
<version>3.0.3</version>
<packaging>maven-plugin</packaging>
<name>Queryable Maven Plugin</name>
<description>Queryable Maven Plugin.</description>
Expand Down
11 changes: 11 additions & 0 deletions src/main/java/it/ness/queryable/annotations/QInclude.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package it.ness.queryable.annotations;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.TYPE, ElementType.METHOD, ElementType.FIELD}) //on class field
public @interface QInclude {
}
22 changes: 21 additions & 1 deletion src/main/java/it/ness/queryable/util/ModelFilesV3.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public class ModelFilesV3 {
private Map<String, String> rsPathMap = new LinkedHashMap<>();
private Map<String, String> defaultOrderByMap = new LinkedHashMap<>();
private Map<String, Boolean> excludeClassMap = new LinkedHashMap<>();
private Map<String, Boolean> includeClassMap = new LinkedHashMap<>();
private Map<String, String> qualifiedClassName = new LinkedHashMap<>();
private Map<String, String> idFieldNameMap = new LinkedHashMap<>();
private Map<String, String> idFieldTypeMap = new LinkedHashMap<>();
Expand Down Expand Up @@ -54,7 +55,18 @@ public Set<FilterDefBase> getFilterDef(final String className, final FilterType
}

public String[] getModelFileNames() {
return modelFileNames;
if (includeClassMap.isEmpty()) {
return modelFileNames;
}
String[] filteredModelFiles = new String[includeClassMap.size()];
int i = 0;
for (String fileName : modelFileNames) {
String className = StringUtil.getClassNameFromFileName(fileName);
if (includeClassMap.containsKey(className)) {
filteredModelFiles[i++] = fileName;
}
}
return filteredModelFiles;
}
public String getIdFieldName(String className) {
return idFieldNameMap.get(className);
Expand Down Expand Up @@ -90,13 +102,18 @@ private void resolveConstant(Log log, Parameters parameters) {
String rsPath = defaultRsPath;
String orderBy = defaultOrderBy;
Boolean excludeClass = false;
Boolean includeClass = null;
// override if annotation is present
try {
JavaClassSource javaClass = Roaster.parse(JavaClassSource.class, new File(parameters.modelPath, fileName));
AnnotationSource<JavaClassSource> a = javaClass.getAnnotation("QExclude");
if (null != a) {
excludeClass = true;
}
a = javaClass.getAnnotation("QInclude");
if (null != a) {
includeClass = true;
}
a = javaClass.getAnnotation("QRs");
if (null != a) {
rsPath = a.getStringValue();
Expand Down Expand Up @@ -143,6 +160,9 @@ private void resolveConstant(Log log, Parameters parameters) {
rsPathMap.put(className, rsPath);
defaultOrderByMap.put(className, orderBy);
excludeClassMap.put(className, excludeClass);
if (includeClass != null) {
includeClassMap.put(className, excludeClass);
}
if (!excludeClass) {
if (defaultOrderBy.equals(orderBy)) {
if (log != null) log.warn(String.format("orderBy for class %s : %s", className, orderBy));
Expand Down
22 changes: 21 additions & 1 deletion src/main/java/it/ness/queryable/util/ModelFilesV4.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public class ModelFilesV4 {
private Map<String, String> rsPathMap = new LinkedHashMap<>();
private Map<String, String> defaultOrderByMap = new LinkedHashMap<>();
private Map<String, Boolean> excludeClassMap = new LinkedHashMap<>();
private Map<String, Boolean> includeClassMap = new LinkedHashMap<>();
private Map<String, String> qualifiedClassName = new LinkedHashMap<>();
private Map<String, String> idFieldNameMap = new LinkedHashMap<>();
private Map<String, String> idFieldTypeMap = new LinkedHashMap<>();
Expand Down Expand Up @@ -54,7 +55,18 @@ public Set<FilterBase> getFilter(final String className, final FilterType filter
}

public String[] getModelFileNames() {
return modelFileNames;
if (includeClassMap.isEmpty()) {
return modelFileNames;
}
String[] filteredModelFiles = new String[includeClassMap.size()];
int i = 0;
for (String fileName : modelFileNames) {
String className = StringUtil.getClassNameFromFileName(fileName);
if (includeClassMap.containsKey(className)) {
filteredModelFiles[i++] = fileName;
}
}
return filteredModelFiles;
}

public String getIdFieldName(String className) {
Expand Down Expand Up @@ -92,13 +104,18 @@ private void resolveConstant(Log log, Parameters parameters) {
String rsPath = defaultRsPath;
String orderBy = defaultOrderBy;
Boolean excludeClass = false;
Boolean includeClass = null;
// override if annotation is present
try {
JavaClassSource javaClass = Roaster.parse(JavaClassSource.class, new File(parameters.modelPath, fileName));
AnnotationSource<JavaClassSource> a = javaClass.getAnnotation("QExclude");
if (null != a) {
excludeClass = true;
}
a = javaClass.getAnnotation("QInclude");
if (null != a) {
includeClass = true;
}
a = javaClass.getAnnotation("QRs");
if (null != a) {
rsPath = a.getStringValue();
Expand Down Expand Up @@ -145,6 +162,9 @@ private void resolveConstant(Log log, Parameters parameters) {
rsPathMap.put(className, rsPath);
defaultOrderByMap.put(className, orderBy);
excludeClassMap.put(className, excludeClass);
if (includeClass != null) {
includeClassMap.put(className, excludeClass);
}
if (!excludeClass) {
if (defaultOrderBy.equals(orderBy)) {
if (log != null) log.warn(String.format("orderBy for class %s : %s", className, orderBy));
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/it/ness/queryable/util/MojoUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,12 @@ public static void addqeexapi(Parameters parameters, Log log) {
public static void addqeexbundle(Parameters parameters, Log log) {
FileUtils.createPath(parameters.outputDir, parameters.apiPath, parameters.logging ? log : null);
File exceptionPath = FileUtils.createPath(parameters.outputDir, parameters.projectPath + "service/exception/", parameters.logging ? log : null);
File servicePath = FileUtils.createPath(parameters.outputDir, parameters.apiPath + "/service/", parameters.logging ? log : null);
// exceptionPath: ExceptionBundle
Map<String, Object> data = Data.with("groupId", parameters.groupId).and("artifactId", parameters.artifactId).map();
FileUtils.createJavaClassFromTemplate(exceptionPath, "qeex-bundle", "ExceptionBundle", null, data, parameters.logging ? log : null);
FileUtils.deleteJavaClassFromTemplate(servicePath, "qeex-bundle", "RsResponseService");
FileUtils.createJavaClassFromTemplate(servicePath, "qeex-bundle", "RsResponseService", null, data, parameters.logging ? log : null);
}

public static void qeexsource(Parameters parameters, Log log) {
Expand Down
12 changes: 6 additions & 6 deletions src/main/resources/templates/qeex-bundle/ExceptionBundleImpl.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ import jakarta.inject.Inject;
@Generated(value = "dev.queryable.QuexGenerator", date = "${creationDate}", comments = "don't touch please")
public class ${className} implements ${interfaceName} {

// copied from application properties: qeex.project=FLW
String classProjectName = "${project}";
// copied from application properties: qeex.project=FLW
String classProjectName = "${project}";

@Inject
QeexConfig qeexConfig;
@Inject
QeexConfig qeexConfig;

@Inject
LanguageInterceptor languageInterceptor;
@Inject
LanguageInterceptor languageInterceptor;

<#list methods as method>
@Override
Expand Down
Loading