Skip to content

Commit

Permalink
Added support for Java 21, migrated to Jakarta namespace, updated ver…
Browse files Browse the repository at this point in the history
…sions of dependencies to latest.
  • Loading branch information
divjad--- committed Nov 29, 2023
1 parent fa97a41 commit 1d0096f
Show file tree
Hide file tree
Showing 13 changed files with 101 additions and 90 deletions.
2 changes: 1 addition & 1 deletion core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>kumuluzee-graphql-parent</artifactId>
<groupId>com.kumuluz.ee.graphql</groupId>
<version>1.2.0-SNAPSHOT</version>
<version>2.0.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public boolean isEnabled() {
public void load() {
List<GraphQLApplication> applications = new ArrayList<>();
ServiceLoader.load(GraphQLApplication.class).forEach(applications::add);
if(applications.size() > 1) {
if (applications.size() > 1) {
throw new KumuluzServerException("Found multiple declarations of GraphQLApplication. Please only provide one.");
}
}
Expand All @@ -77,11 +77,11 @@ public void init(KumuluzServerWrapper kumuluzServerWrapper, EeConfig eeConfig) {
try {
URI u = new URI(path);

if(u.isAbsolute()) {
if (u.isAbsolute()) {
LOG.severe("URL must be relative. Extension not initialized.");
return;
}
} catch(Exception E) {
} catch (Exception E) {
LOG.severe("Malformed url: " + path + ". Extension not initialized.");
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,11 @@
import graphql.schema.GraphQLSchema;
import io.leangen.graphql.GraphQLSchemaGenerator;

import javax.enterprise.inject.spi.CDI;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import jakarta.enterprise.inject.spi.CDI;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

import java.io.IOException;
import java.io.InputStream;
import java.util.*;
Expand Down Expand Up @@ -171,7 +172,7 @@ private GraphQLSchema buildSchema() {
configurationUtil.getList("kumuluzee.graphql.schema.base-packages")
.ifPresent(basePackages::addAll);

generator.withBasePackages(basePackages.toArray(new String [0]));
generator.withBasePackages(basePackages.toArray(new String[0]));

for (Class<?> c : classes) {
if (CDIfound) {
Expand Down
72 changes: 36 additions & 36 deletions core/src/main/java/com/kumuluz/ee/graphql/utils/GraphQLUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@
import graphql.GraphQLException;
import graphql.schema.DataFetchingEnvironment;
import io.leangen.graphql.execution.ResolutionEnvironment;
import jakarta.persistence.EntityManager;

import javax.persistence.EntityManager;
import java.time.Instant;
import java.time.format.DateTimeFormatter;
import java.time.temporal.TemporalAccessor;
Expand Down Expand Up @@ -72,7 +72,7 @@ public static <T> PaginationWrapper<T> process(List<T> list, Pagination p, Filte
}

private static Pagination getDefaultPagination() {
ConfigurationUtil configurationUtil = ConfigurationUtil.getInstance();
ConfigurationUtil configurationUtil = ConfigurationUtil.getInstance();
return new Pagination(configurationUtil.getInteger("kumuluzee.graphql.defaults.limit").orElse(20), configurationUtil.getInteger("kumuluzee.graphql.defaults.offset").orElse(0));
}

Expand Down Expand Up @@ -113,56 +113,56 @@ public static <T> List<T> processWithoutPagination(List<T> l, Sort s) {
}

private static List<String> getStringList(String stringArray, boolean ignoreCase) {
if(stringArray.charAt(0) == '[' && stringArray.charAt(stringArray.length()-1) == ']') {
stringArray = stringArray.substring(1, stringArray.length()-1);
if (stringArray.charAt(0) == '[' && stringArray.charAt(stringArray.length() - 1) == ']') {
stringArray = stringArray.substring(1, stringArray.length() - 1);
} else {
throw new GraphQLException("Value field must contain array ([item1,item2,...]).");
}
if(ignoreCase) {
if (ignoreCase) {
return Arrays.asList(stringArray.toLowerCase().split(","));
} else {
return Arrays.asList(stringArray.split(","));
}
}

public static QueryParameters queryParameters(Pagination p, Sort s, Filter f) {
return queryParameters(p,s,f, true);
return queryParameters(p, s, f, true);
}

public static QueryParameters queryParameters(Pagination p, Sort s, Filter f, boolean forcePagination) {
ConfigurationUtil configurationUtil = ConfigurationUtil.getInstance();
QueryParameters qs = new QueryParameters();
if(p == null && forcePagination) {
if (p == null && forcePagination) {
p = getDefaultPagination();
}

if(p != null) {
if (p != null) {
Integer offset = p.getOffset() == null ? configurationUtil.getInteger("kumuluzee.graphql.defaults.offset").orElse(0) : p.getOffset();
Integer limit = p.getLimit() == null ? configurationUtil.getInteger("kumuluzee.graphql.defaults.limit").orElse(20) : p.getLimit();
qs.setOffset(offset);
qs.setLimit(limit);
}
if(s != null) {
if (s != null) {
List<QueryOrder> queryOrderList = new ArrayList<>();
for(SortField sortField: s.getFields()) {
for (SortField sortField : s.getFields()) {
QueryOrder queryOrder = new QueryOrder();
queryOrder.setField(sortField.getField());
queryOrder.setOrder(sortField.getOrder());
queryOrderList.add(queryOrder);
}
qs.setOrder(queryOrderList);
}
if(f != null) {
if (f != null) {
List<QueryFilter> queryFilterList = new ArrayList<>();
for(FilterField filterField: f.getFields()) {
for (FilterField filterField : f.getFields()) {
QueryFilter queryFilter;
if(filterField.getType() == FilterType.DATE) {
if (filterField.getType() == FilterType.DATE) {
DateTimeFormatter timeFormatter = DateTimeFormatter.ISO_DATE_TIME;
TemporalAccessor accessor = timeFormatter.parse(filterField.getValue());
queryFilter = new QueryFilter(filterField.getField(), filterField.getOp(), Date.from(Instant.from(accessor)));
} else if(filterField.getOp() == FilterOperation.IN || filterField.getOp() == FilterOperation.NIN) {
} else if (filterField.getOp() == FilterOperation.IN || filterField.getOp() == FilterOperation.NIN) {
queryFilter = new QueryFilter(filterField.getField(), filterField.getOp(), getStringList(filterField.getValue(), false));
} else if(filterField.getOp() == FilterOperation.INIC ||filterField.getOp() == FilterOperation.NINIC) {
} else if (filterField.getOp() == FilterOperation.INIC || filterField.getOp() == FilterOperation.NINIC) {
queryFilter = new QueryFilter(filterField.getField(), filterField.getOp(), getStringList(filterField.getValue(), true));
} else {
queryFilter = new QueryFilter(filterField.getField(), filterField.getOp(), filterField.getValue());
Expand All @@ -175,7 +175,7 @@ public static QueryParameters queryParameters(Pagination p, Sort s, Filter f, bo
}

public static <T> PaginationWrapper<T> wrapList(List<T> list, Pagination pagination, Integer size) {
if(pagination == null) {
if (pagination == null) {
pagination = getDefaultPagination();
}
PaginationOutput paginationOutput = new PaginationOutput(pagination, size);
Expand All @@ -187,27 +187,27 @@ public static <T> PaginationWrapper<T> wrapList(List<T> list, Pagination paginat
}

public static <T> PaginationWrapper<T> process(EntityManager em, Class<T> tClass, ResolutionEnvironment resolutionEnvironment, Pagination pagination, Sort sort) {
return process(em, tClass, resolutionEnvironment, pagination, sort,null);
return process(em, tClass, resolutionEnvironment, pagination, sort, null);
}

public static <T> PaginationWrapper<T> process(EntityManager em, Class<T> tClass, ResolutionEnvironment resolutionEnvironment, Pagination pagination, Filter filter) {
return process(em, tClass, resolutionEnvironment, pagination, null, filter);
}

public static <T> PaginationWrapper<T> process(EntityManager em, Class<T> tClass, ResolutionEnvironment resolutionEnvironment, Pagination pagination) {
return process(em, tClass,resolutionEnvironment, pagination, null,null);
return process(em, tClass, resolutionEnvironment, pagination, null, null);
}

public static <T> PaginationWrapper<T> process(EntityManager em, Class<T> tClass, Pagination pagination, Sort sort) {
return process(em, tClass, null, pagination, sort,null);
return process(em, tClass, null, pagination, sort, null);
}

public static <T> PaginationWrapper<T> process(EntityManager em, Class<T> tClass, Pagination pagination, Filter filter) {
return process(em, tClass, null, pagination, null, filter);
}

public static <T> PaginationWrapper<T> process(EntityManager em, Class<T> tClass, Pagination pagination) {
return process(em, tClass,null, pagination, null,null);
return process(em, tClass, null, pagination, null, null);
}

public static <T> PaginationWrapper<T> process(EntityManager em, Class<T> tClass, Pagination pagination, Sort sort, Filter filter) {
Expand All @@ -216,45 +216,45 @@ public static <T> PaginationWrapper<T> process(EntityManager em, Class<T> tClass

public static <T> PaginationWrapper<T> process(EntityManager em, Class<T> tClass, ResolutionEnvironment resolutionEnvironment, Pagination pagination, Sort sort, Filter filter) {
QueryParameters queryParameters = queryParameters(pagination, sort, filter, true);
if(resolutionEnvironment != null) {
if (resolutionEnvironment != null) {
queryParameters.setFields(getFieldsFromResolutionEnvironment(resolutionEnvironment));
}
List<T> studentList = JPAUtils.queryEntities(em, tClass, queryParameters);
Long size = JPAUtils.queryEntitiesCount(em, tClass, queryParameters);
return GraphQLUtils.wrapList(studentList, pagination, size.intValue());
}

public static<T> List<T> processWithoutPagination(EntityManager em, Class<T> tClass) {
public static <T> List<T> processWithoutPagination(EntityManager em, Class<T> tClass) {
return processWithoutPagination(em, tClass, null, null, null);
}

public static<T> List<T> processWithoutPagination(EntityManager em, Class<T> tClass, ResolutionEnvironment resolutionEnvironment) {
public static <T> List<T> processWithoutPagination(EntityManager em, Class<T> tClass, ResolutionEnvironment resolutionEnvironment) {
return processWithoutPagination(em, tClass, resolutionEnvironment, null, null);
}

public static<T> List<T> processWithoutPagination(EntityManager em, Class<T> tClass, ResolutionEnvironment resolutionEnvironment, Sort sort) {
public static <T> List<T> processWithoutPagination(EntityManager em, Class<T> tClass, ResolutionEnvironment resolutionEnvironment, Sort sort) {
return processWithoutPagination(em, tClass, resolutionEnvironment, sort, null);
}

public static<T> List<T> processWithoutPagination(EntityManager em, Class<T> tClass, ResolutionEnvironment resolutionEnvironment, Filter filter) {
public static <T> List<T> processWithoutPagination(EntityManager em, Class<T> tClass, ResolutionEnvironment resolutionEnvironment, Filter filter) {
return processWithoutPagination(em, tClass, resolutionEnvironment, null, filter);
}

public static<T> List<T> processWithoutPagination(EntityManager em, Class<T> tClass, Sort sort) {
public static <T> List<T> processWithoutPagination(EntityManager em, Class<T> tClass, Sort sort) {
return processWithoutPagination(em, tClass, null, sort, null);
}

public static<T> List<T> processWithoutPagination(EntityManager em, Class<T> tClass, Filter filter) {
public static <T> List<T> processWithoutPagination(EntityManager em, Class<T> tClass, Filter filter) {
return processWithoutPagination(em, tClass, null, null, filter);
}

public static<T> List<T> processWithoutPagination(EntityManager em, Class<T> tClass, Sort sort, Filter filter) {
public static <T> List<T> processWithoutPagination(EntityManager em, Class<T> tClass, Sort sort, Filter filter) {
return processWithoutPagination(em, tClass, null, sort, filter);
}

public static<T> List<T> processWithoutPagination(EntityManager em, Class<T> tClass, ResolutionEnvironment resolutionEnvironment, Sort sort, Filter filter) {
public static <T> List<T> processWithoutPagination(EntityManager em, Class<T> tClass, ResolutionEnvironment resolutionEnvironment, Sort sort, Filter filter) {
QueryParameters queryParameters = queryParameters(null, sort, filter, false);
if(resolutionEnvironment != null) {
if (resolutionEnvironment != null) {
queryParameters.setFields(getFieldsFromResolutionEnvironment(resolutionEnvironment));
}
return JPAUtils.queryEntities(em, tClass, queryParameters);
Expand All @@ -264,19 +264,19 @@ private static List<String> getFieldsFromResolutionEnvironment(ResolutionEnviron
List<String> fields = new ArrayList<>();

DataFetchingEnvironment dataFetchingEnvironment = resolutionEnvironment.dataFetchingEnvironment;
Set<String> graphqlFields = dataFetchingEnvironment.getSelectionSet().get().keySet();
Set<String> graphqlFields = dataFetchingEnvironment.getSelectionSet().getFieldsGroupedByResultKey().keySet();

if(graphqlFields.contains("result")) {
for(String s: graphqlFields) {
if (graphqlFields.contains("result")) {
for (String s : graphqlFields) {
String[] split = s.split("/", 2);
if(split[0].equals("result") && split.length >= 2) {
if (split[0].equals("result") && split.length >= 2) {
fields.add(String.join(".", split[1].split("/")));
}
}
} else {
for(String s: graphqlFields) {
for (String s : graphqlFields) {
String[] split = s.split("/");
if(split.length >= 1) {
if (split.length >= 1) {
fields.add(String.join(".", split));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;

import javax.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletRequest;
import java.io.BufferedReader;
import java.io.IOException;
import java.util.Collections;
Expand Down
2 changes: 1 addition & 1 deletion graphql-ui/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>kumuluzee-graphql-parent</artifactId>
<groupId>com.kumuluz.ee.graphql</groupId>
<version>1.2.0-SNAPSHOT</version>
<version>2.0.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public void init(KumuluzServerWrapper kumuluzServerWrapper, EeConfig eeConfig) {
return;
}

if(configurationUtil.getBoolean("kumuluzee.graphql.ui.enabled").orElse(true)) {
if (configurationUtil.getBoolean("kumuluzee.graphql.ui.enabled").orElse(true)) {
String mapping = configurationUtil.get("kumuluzee.graphql.ui.mapping").orElse("graphiql");

// strip "/"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,11 @@

import com.kumuluz.ee.configuration.utils.ConfigurationUtil;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import jakarta.servlet.ServletException;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
Expand Down Expand Up @@ -63,11 +64,11 @@ protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws Se
try {
URI u = new URI(path);

if(u.isAbsolute()) {
if (u.isAbsolute()) {
resp.getWriter().println("URL must be relative. Extension not initialized.");
return;
}
} catch(Exception E) {
} catch (Exception E) {
resp.getWriter().println("Malformed url: " + path + ". Extension not initialized.");
return;
}
Expand Down
2 changes: 1 addition & 1 deletion microprofile/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>kumuluzee-graphql-parent</artifactId>
<groupId>com.kumuluz.ee.graphql</groupId>
<version>1.2.0-SNAPSHOT</version>
<version>2.0.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@
import com.kumuluz.ee.common.wrapper.KumuluzServerWrapper;
import com.kumuluz.ee.configuration.utils.ConfigurationUtil;
import com.kumuluz.ee.jetty.JettyServletServer;
import io.smallrye.graphql.servlet.ExecutionServlet;
import io.smallrye.graphql.servlet.SchemaServlet;
import io.smallrye.graphql.entry.http.ExecutionServlet;
import io.smallrye.graphql.entry.http.SchemaServlet;

import java.net.URI;
import java.util.logging.Logger;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import com.kumuluz.ee.configuration.ConfigurationSource;
import com.kumuluz.ee.configuration.utils.ConfigurationDispatcher;
import com.kumuluz.ee.configuration.utils.ConfigurationUtil;
import io.smallrye.graphql.cdi.config.ConfigKey;
import io.smallrye.graphql.config.ConfigKey;

import java.util.HashMap;
import java.util.List;
Expand All @@ -42,7 +42,7 @@ public class KumuluzConfigMapper implements ConfigurationSource {
private static final Map<String, String> CONFIG_MAP_LIST = new HashMap<>();
private static final String SHOW_ERROR_DEFAULTS_CONFIG_KEY =
"kumuluzee.graphql.exceptions.include-show-error-defaults";
private static final String[] SHOW_ERROR_DEFAULTS = new String[] {
private static final String[] SHOW_ERROR_DEFAULTS = new String[]{
"com.kumuluz.ee.rest.exceptions.InvalidEntityFieldException",
"com.kumuluz.ee.rest.exceptions.InvalidFieldValueException",
"com.kumuluz.ee.rest.exceptions.NoGenericTypeException",
Expand All @@ -57,7 +57,8 @@ public class KumuluzConfigMapper implements ConfigurationSource {
CONFIG_MAP.put(ConfigKey.SCHEMA_INCLUDE_DIRECTIVES, "kumuluzee.graphql.schema.include-directives");
CONFIG_MAP.put(ConfigKey.SCHEMA_INCLUDE_INTROSPECTION_TYPES, "kumuluzee.graphql.schema.include-introspection-types");
CONFIG_MAP.put(ConfigKey.ENABLE_METRICS, "kumuluzee.graphql.metrics.enabled");
CONFIG_MAP.put(ConfigKey.ENABLE_VALIDATION, "kumuluzee.graphql.bean-validation.enabled");
// CONFIG_MAP.put(ConfigKey.ENABLE_VALIDATION, "kumuluzee.graphql.bean-validation.enabled");
CONFIG_MAP.put("smallrye.graphql.validation.enabled", "kumuluzee.graphql.bean-validation.enabled");

CONFIG_MAP_LIST.put("mp.graphql.hideErrorMessage", "kumuluzee.graphql.exceptions.hide-error-message");
CONFIG_MAP_LIST.put("mp.graphql.showErrorMessage", "kumuluzee.graphql.exceptions.show-error-message");
Expand Down
Loading

0 comments on commit 1d0096f

Please sign in to comment.