FINERACT-628 Products APIs
This commit is contained in:
File diff suppressed because it is too large
Load Diff
+2
@@ -21,5 +21,7 @@ package org.apache.fineract.portfolio.self.client.service;
|
||||
public interface AppuserClientMapperReadService {
|
||||
|
||||
public Boolean isClientMappedToUser(Long clientId, Long appUserId);
|
||||
|
||||
public void validateAppuserClientsMapping(final Long clientId);
|
||||
|
||||
}
|
||||
|
||||
+19
-1
@@ -19,6 +19,9 @@
|
||||
package org.apache.fineract.portfolio.self.client.service;
|
||||
|
||||
import org.apache.fineract.infrastructure.core.service.RoutingDataSource;
|
||||
import org.apache.fineract.infrastructure.security.service.PlatformSecurityContext;
|
||||
import org.apache.fineract.portfolio.client.exception.ClientNotFoundException;
|
||||
import org.apache.fineract.useradministration.domain.AppUser;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
import org.springframework.stereotype.Service;
|
||||
@@ -28,10 +31,12 @@ public class AppuserClientMapperReadServiceImpl implements
|
||||
AppuserClientMapperReadService {
|
||||
|
||||
private final JdbcTemplate jdbcTemplate;
|
||||
private final PlatformSecurityContext context;
|
||||
|
||||
@Autowired
|
||||
public AppuserClientMapperReadServiceImpl(final RoutingDataSource dataSource) {
|
||||
public AppuserClientMapperReadServiceImpl(final RoutingDataSource dataSource, final PlatformSecurityContext context) {
|
||||
this.jdbcTemplate = new JdbcTemplate(dataSource);
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -42,5 +47,18 @@ public class AppuserClientMapperReadServiceImpl implements
|
||||
+ " from m_selfservice_user_client_mapping where client_id = ? and appuser_id = ?",
|
||||
new Object[] { clientId, appUserId }, Boolean.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void validateAppuserClientsMapping(final Long clientId) {
|
||||
AppUser user = this.context.authenticatedUser();
|
||||
if (clientId != null) {
|
||||
final boolean mappedClientId = isClientMappedToUser(clientId, user.getId());
|
||||
if (!mappedClientId) {
|
||||
throw new ClientNotFoundException(clientId);
|
||||
}
|
||||
} else
|
||||
throw new ClientNotFoundException(clientId);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+77
@@ -0,0 +1,77 @@
|
||||
/**
|
||||
* 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.portfolio.self.products.api;
|
||||
|
||||
import javax.ws.rs.Consumes;
|
||||
import javax.ws.rs.GET;
|
||||
import javax.ws.rs.Path;
|
||||
import javax.ws.rs.PathParam;
|
||||
import javax.ws.rs.Produces;
|
||||
import javax.ws.rs.QueryParam;
|
||||
import javax.ws.rs.core.Context;
|
||||
import javax.ws.rs.core.MediaType;
|
||||
import javax.ws.rs.core.UriInfo;
|
||||
|
||||
import org.apache.fineract.portfolio.loanaccount.api.LoanApiConstants;
|
||||
import org.apache.fineract.portfolio.loanproduct.api.LoanProductsApiResource;
|
||||
import org.apache.fineract.portfolio.self.client.service.AppuserClientMapperReadService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Scope;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Path("/self/loanproducts")
|
||||
@Component
|
||||
@Scope("singleton")
|
||||
public class SelfLoanProductsApiResource {
|
||||
|
||||
private final LoanProductsApiResource loanProductsApiResource;
|
||||
private final AppuserClientMapperReadService appUserClientMapperReadService;
|
||||
|
||||
@Autowired
|
||||
public SelfLoanProductsApiResource(final LoanProductsApiResource loanProductsApiResource,
|
||||
final AppuserClientMapperReadService appUserClientMapperReadService) {
|
||||
this.loanProductsApiResource = loanProductsApiResource;
|
||||
this.appUserClientMapperReadService = appUserClientMapperReadService;
|
||||
|
||||
}
|
||||
|
||||
@GET
|
||||
@Consumes({ MediaType.APPLICATION_JSON })
|
||||
@Produces({ MediaType.APPLICATION_JSON })
|
||||
public String retrieveAllLoanProducts(@QueryParam(LoanApiConstants.clientIdParameterName) final Long clientId,
|
||||
@Context final UriInfo uriInfo) {
|
||||
|
||||
this.appUserClientMapperReadService.validateAppuserClientsMapping(clientId);
|
||||
return this.loanProductsApiResource.retrieveAllLoanProducts(uriInfo);
|
||||
|
||||
}
|
||||
|
||||
@GET
|
||||
@Path("{productId}")
|
||||
@Consumes({ MediaType.APPLICATION_JSON })
|
||||
@Produces({ MediaType.APPLICATION_JSON })
|
||||
public String retrieveLoanProductDetails(@QueryParam(LoanApiConstants.clientIdParameterName) final Long clientId,
|
||||
@PathParam(LoanApiConstants.productIdParameterName) final Long productId, @Context final UriInfo uriInfo) {
|
||||
|
||||
this.appUserClientMapperReadService.validateAppuserClientsMapping(clientId);
|
||||
return this.loanProductsApiResource.retrieveLoanProductDetails(productId, uriInfo);
|
||||
}
|
||||
|
||||
}
|
||||
+78
@@ -0,0 +1,78 @@
|
||||
/**
|
||||
* 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.portfolio.self.products.api;
|
||||
|
||||
import javax.ws.rs.Consumes;
|
||||
import javax.ws.rs.GET;
|
||||
import javax.ws.rs.Path;
|
||||
import javax.ws.rs.PathParam;
|
||||
import javax.ws.rs.Produces;
|
||||
import javax.ws.rs.QueryParam;
|
||||
import javax.ws.rs.core.Context;
|
||||
import javax.ws.rs.core.MediaType;
|
||||
import javax.ws.rs.core.UriInfo;
|
||||
|
||||
import org.apache.fineract.portfolio.savings.SavingsApiConstants;
|
||||
import org.apache.fineract.portfolio.savings.api.SavingsProductsApiResource;
|
||||
import org.apache.fineract.portfolio.self.client.service.AppuserClientMapperReadService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Scope;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Path("/self/savingsproducts")
|
||||
@Component
|
||||
@Scope("singleton")
|
||||
public class SelfSavingsProductsApiResource {
|
||||
|
||||
private final SavingsProductsApiResource savingsProductsApiResource;
|
||||
private final AppuserClientMapperReadService appUserClientMapperReadService;
|
||||
|
||||
@Autowired
|
||||
public SelfSavingsProductsApiResource(final SavingsProductsApiResource savingsProductsApiResource,
|
||||
final AppuserClientMapperReadService appUserClientMapperReadService) {
|
||||
this.savingsProductsApiResource = savingsProductsApiResource;
|
||||
this.appUserClientMapperReadService = appUserClientMapperReadService;
|
||||
|
||||
}
|
||||
|
||||
@GET
|
||||
@Consumes({ MediaType.APPLICATION_JSON })
|
||||
@Produces({ MediaType.APPLICATION_JSON })
|
||||
public String retrieveAll(@QueryParam(SavingsApiConstants.clientIdParamName) final Long clientId,
|
||||
@Context final UriInfo uriInfo) {
|
||||
|
||||
this.appUserClientMapperReadService.validateAppuserClientsMapping(clientId);
|
||||
return this.savingsProductsApiResource.retrieveAll(uriInfo);
|
||||
|
||||
}
|
||||
|
||||
@GET
|
||||
@Path("{productId}")
|
||||
@Consumes({ MediaType.APPLICATION_JSON })
|
||||
@Produces({ MediaType.APPLICATION_JSON })
|
||||
public String retrieveOne(@PathParam(SavingsApiConstants.productIdParamName) final Long productId,
|
||||
@QueryParam(SavingsApiConstants.clientIdParamName) final Long clientId, @Context final UriInfo uriInfo) {
|
||||
|
||||
this.appUserClientMapperReadService.validateAppuserClientsMapping(clientId);
|
||||
return this.savingsProductsApiResource.retrieveOne(productId, uriInfo);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
+79
@@ -0,0 +1,79 @@
|
||||
/**
|
||||
* 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.portfolio.self.products.api;
|
||||
|
||||
import javax.ws.rs.Consumes;
|
||||
import javax.ws.rs.GET;
|
||||
import javax.ws.rs.Path;
|
||||
import javax.ws.rs.PathParam;
|
||||
import javax.ws.rs.Produces;
|
||||
import javax.ws.rs.QueryParam;
|
||||
import javax.ws.rs.core.Context;
|
||||
import javax.ws.rs.core.MediaType;
|
||||
import javax.ws.rs.core.UriInfo;
|
||||
|
||||
import org.apache.fineract.portfolio.accounts.constants.ShareAccountApiConstants;
|
||||
import org.apache.fineract.portfolio.products.api.ProductsApiResource;
|
||||
import org.apache.fineract.portfolio.self.client.service.AppuserClientMapperReadService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Scope;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Path("/self/products/share")
|
||||
@Component
|
||||
@Scope("singleton")
|
||||
public class SelfShareProductsApiResource {
|
||||
|
||||
private final ProductsApiResource productsApiResource;
|
||||
private final AppuserClientMapperReadService appUserClientMapperReadService;
|
||||
|
||||
@Autowired
|
||||
public SelfShareProductsApiResource(final ProductsApiResource productsApiResource,
|
||||
final AppuserClientMapperReadService appUserClientMapperReadService) {
|
||||
this.productsApiResource = productsApiResource;
|
||||
this.appUserClientMapperReadService = appUserClientMapperReadService;
|
||||
|
||||
}
|
||||
|
||||
@GET
|
||||
@Path("{productId}")
|
||||
@Consumes({ MediaType.APPLICATION_JSON })
|
||||
@Produces({ MediaType.APPLICATION_JSON })
|
||||
public String retrieveProduct(@QueryParam(ShareAccountApiConstants.clientid_paramname) final Long clientId,
|
||||
@PathParam("productId") final Long productId, @PathParam("type") final String productType,
|
||||
@Context final UriInfo uriInfo) {
|
||||
this.appUserClientMapperReadService.validateAppuserClientsMapping(clientId);
|
||||
return this.productsApiResource.retrieveProduct(productId, ShareAccountApiConstants.shareEntityType, uriInfo);
|
||||
|
||||
}
|
||||
|
||||
@GET
|
||||
@Consumes({ MediaType.APPLICATION_JSON })
|
||||
@Produces({ MediaType.APPLICATION_JSON })
|
||||
public String retrieveAllProducts(@QueryParam(ShareAccountApiConstants.clientid_paramname) final Long clientId,
|
||||
@QueryParam("offset") final Integer offset, @QueryParam("limit") final Integer limit,
|
||||
@Context final UriInfo uriInfo) {
|
||||
this.appUserClientMapperReadService.validateAppuserClientsMapping(clientId);
|
||||
return this.productsApiResource.retrieveAllProducts(ShareAccountApiConstants.shareEntityType, offset, limit,
|
||||
uriInfo);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user