FINERACT-2169: Apply DTO instead String json in AdHocApiResource
This commit is contained in:
committed by
Adam Saghy
parent
6b5641f474
commit
a0a0c15efa
+19
-35
@@ -28,22 +28,19 @@ import jakarta.ws.rs.PUT;
|
||||
import jakarta.ws.rs.Path;
|
||||
import jakarta.ws.rs.PathParam;
|
||||
import jakarta.ws.rs.Produces;
|
||||
import jakarta.ws.rs.core.Context;
|
||||
import jakarta.ws.rs.core.MediaType;
|
||||
import jakarta.ws.rs.core.UriInfo;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.apache.fineract.adhocquery.data.AdHocData;
|
||||
import org.apache.fineract.adhocquery.data.AdHocRequest;
|
||||
import org.apache.fineract.adhocquery.service.AdHocReadPlatformService;
|
||||
import org.apache.fineract.commands.domain.CommandWrapper;
|
||||
import org.apache.fineract.commands.service.CommandWrapperBuilder;
|
||||
import org.apache.fineract.commands.service.PortfolioCommandSourceWritePlatformService;
|
||||
import org.apache.fineract.infrastructure.core.api.ApiRequestParameterHelper;
|
||||
import org.apache.fineract.infrastructure.core.data.CommandProcessingResult;
|
||||
import org.apache.fineract.infrastructure.core.serialization.ApiRequestJsonSerializationSettings;
|
||||
import org.apache.fineract.infrastructure.core.serialization.DefaultToApiJsonSerializer;
|
||||
import org.apache.fineract.infrastructure.security.service.PlatformSecurityContext;
|
||||
import org.springframework.stereotype.Component;
|
||||
@@ -63,70 +60,59 @@ public class AdHocApiResource {
|
||||
private final PlatformSecurityContext context;
|
||||
private final AdHocReadPlatformService adHocReadPlatformService;
|
||||
private final DefaultToApiJsonSerializer<AdHocData> toApiJsonSerializer;
|
||||
private final ApiRequestParameterHelper apiRequestParameterHelper;
|
||||
private final PortfolioCommandSourceWritePlatformService commandsSourceWritePlatformService;
|
||||
|
||||
@GET
|
||||
@Consumes({ MediaType.APPLICATION_JSON })
|
||||
@Produces({ MediaType.APPLICATION_JSON })
|
||||
public String retrieveAll(@Context final UriInfo uriInfo) {
|
||||
public List<AdHocData> retrieveAll() {
|
||||
|
||||
this.context.authenticatedUser();
|
||||
final Collection<AdHocData> adhocs = this.adHocReadPlatformService.retrieveAllAdHocQuery();
|
||||
final ApiRequestJsonSerializationSettings settings = this.apiRequestParameterHelper.process(uriInfo.getQueryParameters());
|
||||
return this.toApiJsonSerializer.serialize(settings, adhocs, RESPONSE_DATA_PARAMETERS);
|
||||
return adHocReadPlatformService.retrieveAllAdHocQuery();
|
||||
}
|
||||
|
||||
@GET
|
||||
@Consumes({ MediaType.APPLICATION_JSON })
|
||||
@Produces({ MediaType.APPLICATION_JSON })
|
||||
@Path("template")
|
||||
public String template(@Context final UriInfo uriInfo) {
|
||||
public AdHocData template() {
|
||||
this.context.authenticatedUser();
|
||||
final AdHocData user = this.adHocReadPlatformService.retrieveNewAdHocDetails();
|
||||
final ApiRequestJsonSerializationSettings settings = this.apiRequestParameterHelper.process(uriInfo.getQueryParameters());
|
||||
return this.toApiJsonSerializer.serialize(settings, user, RESPONSE_DATA_PARAMETERS);
|
||||
return adHocReadPlatformService.retrieveNewAdHocDetails();
|
||||
}
|
||||
|
||||
@POST
|
||||
@Consumes({ MediaType.APPLICATION_JSON })
|
||||
@Produces({ MediaType.APPLICATION_JSON })
|
||||
public String createAdHocQuery(final String apiRequestBodyAsJson) {
|
||||
public CommandProcessingResult createAdHocQuery(final AdHocRequest adHocRequest) {
|
||||
|
||||
final CommandWrapper commandRequest = new CommandWrapperBuilder().createAdHoc().withJson(apiRequestBodyAsJson).build();
|
||||
final CommandWrapper commandRequest = new CommandWrapperBuilder().createAdHoc()
|
||||
.withJson(toApiJsonSerializer.serialize(adHocRequest)).build();
|
||||
|
||||
final CommandProcessingResult result = this.commandsSourceWritePlatformService.logCommandSource(commandRequest);
|
||||
|
||||
return this.toApiJsonSerializer.serialize(result);
|
||||
return commandsSourceWritePlatformService.logCommandSource(commandRequest);
|
||||
}
|
||||
|
||||
@GET
|
||||
@Path("{adHocId}")
|
||||
@Consumes({ MediaType.APPLICATION_JSON })
|
||||
@Produces({ MediaType.APPLICATION_JSON })
|
||||
public String retrieveAdHocQuery(@PathParam("adHocId") @Parameter(description = "adHocId") final Long adHocId,
|
||||
@Context final UriInfo uriInfo) {
|
||||
public AdHocData retrieveAdHocQuery(@PathParam("adHocId") @Parameter(description = "adHocId") final Long adHocId) {
|
||||
|
||||
this.context.authenticatedUser();
|
||||
|
||||
final ApiRequestJsonSerializationSettings settings = this.apiRequestParameterHelper.process(uriInfo.getQueryParameters());
|
||||
|
||||
final AdHocData adhoc = this.adHocReadPlatformService.retrieveOne(adHocId);
|
||||
|
||||
return this.toApiJsonSerializer.serialize(settings, adhoc, RESPONSE_DATA_PARAMETERS);
|
||||
return adHocReadPlatformService.retrieveOne(adHocId);
|
||||
}
|
||||
|
||||
@PUT
|
||||
@Path("{adHocId}")
|
||||
@Consumes({ MediaType.APPLICATION_JSON })
|
||||
@Produces({ MediaType.APPLICATION_JSON })
|
||||
public String update(@PathParam("adHocId") @Parameter(description = "adHocId") final Long adHocId, final String apiRequestBodyAsJson) {
|
||||
public CommandProcessingResult update(@PathParam("adHocId") @Parameter(description = "adHocId") final Long adHocId,
|
||||
final AdHocRequest adHocRequest) {
|
||||
|
||||
final CommandWrapper commandRequest = new CommandWrapperBuilder().updateAdHoc(adHocId).withJson(apiRequestBodyAsJson).build();
|
||||
final CommandWrapper commandRequest = new CommandWrapperBuilder().updateAdHoc(adHocId)
|
||||
.withJson(toApiJsonSerializer.serialize(adHocRequest)).build();
|
||||
|
||||
final CommandProcessingResult result = this.commandsSourceWritePlatformService.logCommandSource(commandRequest);
|
||||
|
||||
return this.toApiJsonSerializer.serialize(result);
|
||||
return commandsSourceWritePlatformService.logCommandSource(commandRequest);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -139,13 +125,11 @@ public class AdHocApiResource {
|
||||
@Path("{adHocId}")
|
||||
@Consumes({ MediaType.APPLICATION_JSON })
|
||||
@Produces({ MediaType.APPLICATION_JSON })
|
||||
public String deleteAdHocQuery(@PathParam("adHocId") @Parameter(description = "adHocId") final Long adHocId) {
|
||||
public CommandProcessingResult deleteAdHocQuery(@PathParam("adHocId") @Parameter(description = "adHocId") final Long adHocId) {
|
||||
|
||||
final CommandWrapper commandRequest = new CommandWrapperBuilder().deleteAdHoc(adHocId).build();
|
||||
|
||||
final CommandProcessingResult result = this.commandsSourceWritePlatformService.logCommandSource(commandRequest);
|
||||
|
||||
return this.toApiJsonSerializer.serialize(result);
|
||||
return commandsSourceWritePlatformService.logCommandSource(commandRequest);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
*/
|
||||
package org.apache.fineract.adhocquery.data;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import java.time.ZonedDateTime;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
@@ -43,6 +44,7 @@ public class AdHocData {
|
||||
private String tableName;
|
||||
private String tableFields;
|
||||
private String email;
|
||||
@JsonProperty("isActive")
|
||||
private boolean isActive;
|
||||
private ZonedDateTime createdOn;
|
||||
private Long createdById;
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
/**
|
||||
* 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.adhocquery.data;
|
||||
|
||||
import java.io.Serial;
|
||||
import java.io.Serializable;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class AdHocRequest implements Serializable {
|
||||
|
||||
@Serial
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private Long id;
|
||||
private String name;
|
||||
private String query;
|
||||
private String tableName;
|
||||
private String tableFields;
|
||||
private String email;
|
||||
private Long reportRunFrequency;
|
||||
private Long reportRunEvery;
|
||||
private Boolean isActive;
|
||||
}
|
||||
+3
-3
@@ -18,14 +18,14 @@
|
||||
*/
|
||||
package org.apache.fineract.adhocquery.service;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import org.apache.fineract.adhocquery.data.AdHocData;
|
||||
|
||||
public interface AdHocReadPlatformService {
|
||||
|
||||
Collection<AdHocData> retrieveAllAdHocQuery();
|
||||
List<AdHocData> retrieveAllAdHocQuery();
|
||||
|
||||
Collection<AdHocData> retrieveAllActiveAdHocQuery();
|
||||
List<AdHocData> retrieveAllActiveAdHocQuery();
|
||||
|
||||
AdHocData retrieveOne(Long adHocId);
|
||||
|
||||
|
||||
+3
-3
@@ -21,7 +21,7 @@ package org.apache.fineract.adhocquery.service;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.time.ZonedDateTime;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.apache.fineract.adhocquery.data.AdHocData;
|
||||
import org.apache.fineract.adhocquery.exception.AdHocNotFoundException;
|
||||
@@ -39,14 +39,14 @@ public class AdHocReadPlatformServiceImpl implements AdHocReadPlatformService {
|
||||
private final AdHocMapper adHocRowMapper;
|
||||
|
||||
@Override
|
||||
public Collection<AdHocData> retrieveAllAdHocQuery() {
|
||||
public List<AdHocData> retrieveAllAdHocQuery() {
|
||||
final String sql = "select " + this.adHocRowMapper.schema() + " order by r.id";
|
||||
|
||||
return this.jdbcTemplate.query(sql, this.adHocRowMapper); // NOSONAR
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<AdHocData> retrieveAllActiveAdHocQuery() {
|
||||
public List<AdHocData> retrieveAllActiveAdHocQuery() {
|
||||
final String sql = "select " + adHocRowMapper.schema() + " where r." + sqlGenerator.escape("is_active") + " = true order by r.id";
|
||||
|
||||
return jdbcTemplate.query(sql, adHocRowMapper); // NOSONAR
|
||||
|
||||
Reference in New Issue
Block a user