Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
import org.apache.fineract.client.services.ClientApi;
import org.apache.fineract.client.services.ClientChargesApi;
import org.apache.fineract.client.services.ClientIdentifierApi;
import org.apache.fineract.client.services.ClientSearchV2Api;
import org.apache.fineract.client.services.ClientTransactionApi;
import org.apache.fineract.client.services.ClientsAddressApi;
import org.apache.fineract.client.services.CodeValuesApi;
Expand Down Expand Up @@ -153,7 +154,7 @@
import retrofit2.converter.scalars.ScalarsConverterFactory;

/**
* Fineract Client Java SDK API entry point. Use this instead of the {@link ApiClient}.
* Fineract Client Java SDK API entry point.
*
* @author Michael Vorburger.ch
*/
Expand Down Expand Up @@ -187,6 +188,8 @@ public final class FineractClient {
public final CentersApi centers;
public final ChargesApi charges;
public final ClientApi clients;

public final ClientSearchV2Api clientSearchV2;
public final ClientChargesApi clientCharges;
public final ClientIdentifierApi clientIdentifiers;
public final ClientsAddressApi clientAddresses;
Expand Down Expand Up @@ -305,6 +308,7 @@ private FineractClient(OkHttpClient okHttpClient, Retrofit retrofit) {
centers = retrofit.create(CentersApi.class);
charges = retrofit.create(ChargesApi.class);
clients = retrofit.create(ClientApi.class);
clientSearchV2 = retrofit.create(ClientSearchV2Api.class);
clientCharges = retrofit.create(ClientChargesApi.class);
clientIdentifiers = retrofit.create(ClientIdentifierApi.class);
clientAddresses = retrofit.create(ClientsAddressApi.class);
Expand Down Expand Up @@ -537,7 +541,6 @@ public FineractClient build() {
* Obtain the internal Retrofit Builder. This method is typically not required to be invoked for simple API
* usages, but can be a handy back door for non-trivial advanced customizations of the API client.
*
* @return the {@link ApiClient} which {@link #build()} will use.
*/
public retrofit2.Retrofit.Builder getRetrofitBuilder() {
return retrofitBuilder;
Expand All @@ -547,7 +550,6 @@ public retrofit2.Retrofit.Builder getRetrofitBuilder() {
* Obtain the internal OkHttp Builder. This method is typically not required to be invoked for simple API
* usages, but can be a handy back door for non-trivial advanced customizations of the API client.
*
* @return the {@link ApiClient} which {@link #build()} will use.
*/
public okhttp3.OkHttpClient.Builder getOkBuilder() {
return okBuilder;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@
import java.util.Date;
import okhttp3.RequestBody;
import okhttp3.ResponseBody;
import org.apache.fineract.client.models.ExternalId;
import org.apache.fineract.client.util.adapter.ExternalIdAdapter;
import retrofit2.Converter;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;
Expand All @@ -51,12 +53,14 @@ public class JSON {
private final SqlDateTypeAdapter sqlDateTypeAdapter = new SqlDateTypeAdapter();
private final OffsetDateTimeTypeAdapter offsetDateTimeTypeAdapter = new OffsetDateTimeTypeAdapter();
private final LocalDateTypeAdapter localDateTypeAdapter = new LocalDateTypeAdapter();
private final ExternalIdAdapter externalIdAdapter = new ExternalIdAdapter();

public JSON() {
gson = new GsonFireBuilder().createGsonBuilder().registerTypeAdapter(Date.class, dateTypeAdapter)
.registerTypeAdapter(java.sql.Date.class, sqlDateTypeAdapter)
.registerTypeAdapter(OffsetDateTime.class, offsetDateTimeTypeAdapter)
.registerTypeAdapter(LocalDate.class, localDateTypeAdapter).create();
.registerTypeAdapter(LocalDate.class, localDateTypeAdapter).registerTypeAdapter(ExternalId.class, externalIdAdapter)
.create();
}

public Gson getGson() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.fineract.client.util.adapter;

import com.google.gson.TypeAdapter;
import com.google.gson.stream.JsonReader;
import com.google.gson.stream.JsonWriter;
import java.io.IOException;
import org.apache.fineract.client.models.ExternalId;

public class ExternalIdAdapter extends TypeAdapter<ExternalId> {

@Override
public void write(JsonWriter out, ExternalId value) throws IOException {
if (value != null && Boolean.FALSE.equals(value.getEmpty())) {
out.value(value.getValue());
} else {
out.nullValue();
}
}

@Override
public ExternalId read(JsonReader in) throws IOException {
ExternalId result = new ExternalId().empty(true);
switch (in.peek()) {
case NULL:
in.nextNull();
return result;
default:
String value = in.nextString();
return new ExternalId().empty(false).value(value);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.fineract.infrastructure.core.jpa;

import java.util.ArrayList;
import java.util.List;
import java.util.function.Supplier;
import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.Order;
import javax.persistence.criteria.Root;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.stereotype.Component;

@Component
public class CriteriaQueryFactory {

public List<Order> fromPageable(Pageable pageable, CriteriaBuilder cb, Root<?> root) {
return fromPageable(pageable, cb, root, () -> null);
}

public List<Order> fromPageable(Pageable pageable, CriteriaBuilder cb, Root<?> root, Supplier<Order> defaultOrderSupplier) {
List<Order> orders = new ArrayList<>();
Sort sort = pageable.getSort();
if (sort.isSorted()) {
for (Sort.Order order : sort) {
if (order.isAscending()) {
orders.add(cb.asc(root.get(order.getProperty())));
} else {
orders.add(cb.desc(root.get(order.getProperty())));
}
}
} else {
Order defaultOrder = defaultOrderSupplier.get();
if (defaultOrder != null) {
orders.add(defaultOrder);
}
}
return orders;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.fineract.infrastructure.core.service;

import static org.apache.commons.collections4.CollectionUtils.isEmpty;

import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import lombok.Data;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;

@Data
public class PagedRequest<T> {

public static final int DEFAULT_PAGE_SIZE = 50;

private T request;

private int page;
private int size = DEFAULT_PAGE_SIZE;

private List<SortOrder> sorts = new ArrayList<>();

public Optional<T> getRequest() {
return Optional.ofNullable(request);
}

public Pageable toPageable() {
if (isEmpty(sorts)) {
return PageRequest.of(page, size);
} else {
List<Sort.Order> orders = sorts.stream().map(SortOrder::toOrder).toList();
return PageRequest.of(page, size, Sort.by(orders));
}
}

@Data
@SuppressWarnings({ "unused" })
private static class SortOrder {

private Direction direction;
private String property;

private enum Direction {
ASC, DESC;
}

private Sort.Order toOrder() {
Sort.Direction d = Sort.Direction.fromString(direction.name());
return new Sort.Order(d, property);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* under the License.
*/

package org.apache.fineract.infrastructure.core.config;
package org.apache.fineract.infrastructure.core.jersey;

import javax.annotation.PostConstruct;
import javax.ws.rs.ApplicationPath;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.fineract.infrastructure.core.jersey;

import com.fasterxml.jackson.databind.JsonDeserializer;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.MapperFeature;
import com.fasterxml.jackson.module.paramnames.ParameterNamesModule;
import java.util.ArrayList;
import java.util.List;
import org.apache.fineract.infrastructure.core.jersey.converter.JsonConverter;
import org.apache.fineract.infrastructure.core.jersey.serializer.JacksonDeserializerAdapter;
import org.apache.fineract.infrastructure.core.jersey.serializer.JacksonSerializerAdapter;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder;
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;

@Configuration
public class JerseyJacksonConverterConfig {

@Bean
public MappingJackson2HttpMessageConverter jacksonHttpConverter(List<JsonSerializer<?>> serializers,
List<JsonDeserializer<?>> deserializers, List<JsonConverter<?>> jsonConverters) {
List<JsonSerializer<?>> mergedSerializers = new ArrayList<>(serializers);
mergedSerializers.addAll(jsonConverters.stream().map(JacksonSerializerAdapter::new).toList());

List<JsonDeserializer<?>> mergedDeserializers = new ArrayList<>(deserializers);
mergedDeserializers.addAll(jsonConverters.stream().map(JacksonDeserializerAdapter::new).toList());

return new MappingJackson2HttpMessageConverter(new Jackson2ObjectMapperBuilder().indentOutput(true)
.serializers(mergedSerializers.toArray(new JsonSerializer[0]))
.deserializers(mergedDeserializers.toArray(new JsonDeserializer[0]))
.featuresToEnable(MapperFeature.ACCEPT_CASE_INSENSITIVE_ENUMS).modulesToInstall(new ParameterNamesModule()).build());
}
}
Loading