diff --git a/dep-sandbox/src/main/java/com/wso2telco/services/dep/sandbox/dao/model/custom/RetrieveSenderAddressServiceRequestWrapper.java b/dep-sandbox/src/main/java/com/wso2telco/services/dep/sandbox/dao/model/custom/RetrieveSenderAddressServiceRequestWrapper.java new file mode 100644 index 00000000..14fa6c1f --- /dev/null +++ b/dep-sandbox/src/main/java/com/wso2telco/services/dep/sandbox/dao/model/custom/RetrieveSenderAddressServiceRequestWrapper.java @@ -0,0 +1,16 @@ +package com.wso2telco.services.dep.sandbox.dao.model.custom; + +public class RetrieveSenderAddressServiceRequestWrapper extends RequestDTO{ + + private static final long serialVersionUID = -3609438606243268257L; + + private String endUserId; + + public String getEndUserId() { + return endUserId; + } + + public void setEndUserId(String endUserId) { + this.endUserId = endUserId; + } +} diff --git a/dep-sandbox/src/main/java/com/wso2telco/services/dep/sandbox/service/Application.java b/dep-sandbox/src/main/java/com/wso2telco/services/dep/sandbox/service/Application.java index 48e63127..2f328e84 100644 --- a/dep-sandbox/src/main/java/com/wso2telco/services/dep/sandbox/service/Application.java +++ b/dep-sandbox/src/main/java/com/wso2telco/services/dep/sandbox/service/Application.java @@ -38,6 +38,7 @@ protected List getRestFulComponents() { listOfObject.add(new CreditService()); listOfObject.add(new WalletService()); listOfObject.add(new WalletConfigurationService()); + listOfObject.add(new CommonService()); return listOfObject; } diff --git a/dep-sandbox/src/main/java/com/wso2telco/services/dep/sandbox/service/CommonService.java b/dep-sandbox/src/main/java/com/wso2telco/services/dep/sandbox/service/CommonService.java new file mode 100644 index 00000000..9d476726 --- /dev/null +++ b/dep-sandbox/src/main/java/com/wso2telco/services/dep/sandbox/service/CommonService.java @@ -0,0 +1,67 @@ +package com.wso2telco.services.dep.sandbox.service; + + +import com.wordnik.swagger.annotations.*; +import com.wso2telco.services.dep.sandbox.dao.model.custom.APIServiceCallRequestWrapperDTO; +import com.wso2telco.services.dep.sandbox.dao.model.custom.RetrieveSenderAddressServiceRequestWrapper; +import com.wso2telco.services.dep.sandbox.exception.SandboxException; +import com.wso2telco.services.dep.sandbox.servicefactory.RequestBuilderFactory; +import com.wso2telco.services.dep.sandbox.servicefactory.RequestHandleable; +import com.wso2telco.services.dep.sandbox.servicefactory.Returnable; +import com.wso2telco.services.dep.sandbox.util.RequestType; +import jdk.nashorn.internal.objects.annotations.Getter; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +import javax.servlet.http.HttpServletRequest; +import javax.ws.rs.*; +import javax.ws.rs.core.Context; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; + +@Path("/common/{v1}/utilities") +@Consumes({ MediaType.APPLICATION_JSON }) +@Produces({ MediaType.APPLICATION_JSON }) +@Api(value = "/{v1}/utilities", description = "Rest Service for Sandbox UI ") +public class CommonService { + + Log LOG = LogFactory.getLog(CommonService.class); + + @GET + @Path("/{endUserId}/senderAddress") + @ApiOperation(value = "listSenderAddresses", notes = "List of available sender addresses", response = Response.class) + @ApiImplicitParams({ @ApiImplicitParam(name = "sandbox", value = "username", required = true, dataType = "string", paramType = "header") }) + public Response getSenderAddressesList( + @ApiParam(value = "endUserId", required = false) @PathParam("endUserId") String endUserId, + @Context HttpServletRequest httpRequest) { + RetrieveSenderAddressServiceRequestWrapper requestDTO = new RetrieveSenderAddressServiceRequestWrapper(); + requestDTO.setRequestType(RequestType.GENERIC); + requestDTO.setHttpRequest(httpRequest); + requestDTO.setEndUserId(endUserId); + RequestHandleable handler = RequestBuilderFactory + .getInstance(requestDTO); + Returnable returnable = null; + + try { + returnable = handler.execute(requestDTO); + Response response = Response.status(returnable.getHttpStatus()) + .entity(returnable.getResponse()).build(); + LOG.debug("GET Sender Address list RESPONSE : " + response); + return response; + } catch (SandboxException ex) { + LOG.error( + "###USER### Error encountered in getSenderAddress Service : ", + ex); + return Response + .status(Response.Status.BAD_REQUEST) + .entity(ex.getErrorType().getCode() + " " + + ex.getErrorType().getMessage()).build(); + } catch (Exception ex) { + LOG.error( + "###USER### Error encountered in RretriveSenderAddress list Service : ", + ex); + return Response.status(Response.Status.BAD_REQUEST) + .entity(ex.getMessage()).build(); + }} + +} diff --git a/dep-sandbox/src/main/java/com/wso2telco/services/dep/sandbox/servicefactory/RequestBuilderFactory.java b/dep-sandbox/src/main/java/com/wso2telco/services/dep/sandbox/servicefactory/RequestBuilderFactory.java index 4bd5c2b4..23788282 100644 --- a/dep-sandbox/src/main/java/com/wso2telco/services/dep/sandbox/servicefactory/RequestBuilderFactory.java +++ b/dep-sandbox/src/main/java/com/wso2telco/services/dep/sandbox/servicefactory/RequestBuilderFactory.java @@ -1,5 +1,6 @@ package com.wso2telco.services.dep.sandbox.servicefactory; +import com.wso2telco.services.dep.sandbox.servicefactory.generic.GenericServiceFactory; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -76,6 +77,10 @@ public static RequestHandleable getInstance(final RequestDTO requestDTO) { LOG.debug("LOADING WALLET CONFIGURATION FACTORY"); requestHandler = WalletConfigServiceFactory.getInstance(requestDTO); break; + case GENERIC: + LOG.debug("LOADING GENERIC FACTORY"); + requestHandler = GenericServiceFactory.getInstance(requestDTO); + break; default: LOG.debug("APPROPIATE FACTORY CLASS NOT FOUND"); break; diff --git a/dep-sandbox/src/main/java/com/wso2telco/services/dep/sandbox/servicefactory/generic/GenericServiceFactory.java b/dep-sandbox/src/main/java/com/wso2telco/services/dep/sandbox/servicefactory/generic/GenericServiceFactory.java new file mode 100644 index 00000000..7f3942fc --- /dev/null +++ b/dep-sandbox/src/main/java/com/wso2telco/services/dep/sandbox/servicefactory/generic/GenericServiceFactory.java @@ -0,0 +1,27 @@ +package com.wso2telco.services.dep.sandbox.servicefactory.generic; + + +import com.wso2telco.services.dep.sandbox.dao.model.custom.RequestDTO; +import com.wso2telco.services.dep.sandbox.servicefactory.RequestHandleable; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + + +public class GenericServiceFactory { + + private static Log LOG = LogFactory.getLog(GenericServiceFactory.class); + + public static RequestHandleable getInstance(RequestDTO requestDTO) { + + final String SENDER_ADDRESS = "senderAddress"; + + + if (requestDTO.getRequestPath().contains(SENDER_ADDRESS) + && requestDTO.isGet()) { + LOG.debug("LOADING SENDER ADDRESS LIST SERVICE CALL"); + return new RetrieveSenderAddressServiceServiceHandler(); + } + LOG.debug("NO ANY SERVICE FOUND FOR REQUESTED PATH"); + return null; + } +} diff --git a/dep-sandbox/src/main/java/com/wso2telco/services/dep/sandbox/servicefactory/generic/RetrieveSenderAddressServiceResponseWrapper.java b/dep-sandbox/src/main/java/com/wso2telco/services/dep/sandbox/servicefactory/generic/RetrieveSenderAddressServiceResponseWrapper.java new file mode 100644 index 00000000..12dda413 --- /dev/null +++ b/dep-sandbox/src/main/java/com/wso2telco/services/dep/sandbox/servicefactory/generic/RetrieveSenderAddressServiceResponseWrapper.java @@ -0,0 +1,44 @@ +package com.wso2telco.services.dep.sandbox.servicefactory.generic; + + +import com.wso2telco.services.dep.sandbox.servicefactory.AbstractReturnWrapperDTO; +import java.util.List; + +public class RetrieveSenderAddressServiceResponseWrapper extends AbstractReturnWrapperDTO { + + + private SenderAddresses senderAddresses; + + @Override + public Object getResponse() { + if (getRequestError() != null) { + return getRequestError(); + } + return getSenderAddressList(); + } + + + public void setSenderAddressList( SenderAddresses senderAddresses) { + this.senderAddresses = senderAddresses; + } + + public SenderAddresses getSenderAddressList() { + return senderAddresses; + } + + public static class SenderAddresses { + + private List senderAddressList; + + public void setSenderAddressList(List senderAddressList) { + this.senderAddressList = senderAddressList; + } + + public List getSenderAddressList() { + return senderAddressList; + } + + } + + +} diff --git a/dep-sandbox/src/main/java/com/wso2telco/services/dep/sandbox/servicefactory/generic/RetrieveSenderAddressServiceServiceHandler.java b/dep-sandbox/src/main/java/com/wso2telco/services/dep/sandbox/servicefactory/generic/RetrieveSenderAddressServiceServiceHandler.java new file mode 100644 index 00000000..a51ffa04 --- /dev/null +++ b/dep-sandbox/src/main/java/com/wso2telco/services/dep/sandbox/servicefactory/generic/RetrieveSenderAddressServiceServiceHandler.java @@ -0,0 +1,89 @@ +package com.wso2telco.services.dep.sandbox.servicefactory.generic; + +import com.wso2telco.core.dbutils.exception.ServiceError; +import com.wso2telco.services.dep.sandbox.dao.model.custom.RetrieveSenderAddressServiceRequestWrapper; +import com.wso2telco.services.dep.sandbox.dao.model.domain.SenderAddress; +import com.wso2telco.services.dep.sandbox.dao.model.domain.User; +import com.wso2telco.services.dep.sandbox.servicefactory.AbstractRequestHandler; +import com.wso2telco.services.dep.sandbox.servicefactory.Returnable; +import org.apache.commons.logging.LogFactory; + +import com.wso2telco.services.dep.sandbox.servicefactory.generic.RetrieveSenderAddressServiceResponseWrapper.SenderAddresses; + +import javax.ws.rs.core.Response; +import java.util.ArrayList; +import java.util.List; + +public class RetrieveSenderAddressServiceServiceHandler extends AbstractRequestHandler { + + private RetrieveSenderAddressServiceResponseWrapper responseWrapper; + private RetrieveSenderAddressServiceRequestWrapper requestWrapper; + + { + LOG = LogFactory.getLog(RetrieveSenderAddressServiceServiceHandler.class); + } + + @Override + protected Returnable getResponseDTO() { + return responseWrapper; + } + + @Override + protected List getAddress() { + List address = new ArrayList(); + address.add(requestWrapper.getEndUserId()); + return address; + } + + @Override + protected boolean validate(RetrieveSenderAddressServiceRequestWrapper wrapperDTO) throws Exception { + return true; + } + + @Override + protected Returnable process(RetrieveSenderAddressServiceRequestWrapper extendedRequestDTO) throws Exception { + + if (responseWrapper.getRequestError() != null) { + responseWrapper.setHttpStatus(Response.Status.BAD_REQUEST); + return responseWrapper; + } + + User user = extendedRequestDTO.getUser(); + List senderAddressList = new ArrayList(); + SenderAddresses senderAddressesObj = new SenderAddresses(); + List senderAddress = user.getSenderAddressList(); + + try { + + if (senderAddress != null && !senderAddress.isEmpty()) { + for (SenderAddress senderAddr : senderAddress) { + senderAddressList.add(senderAddr.getShortCode()); + } + } else { + responseWrapper.setRequestError(constructRequestError( + SERVICEEXCEPTION, ServiceError.INVALID_INPUT_VALUE, + "No any sender addresses are available")); + responseWrapper.setHttpStatus(Response.Status.BAD_REQUEST); + + LOG.error("###USER### No any SenderAddresses are available"); + } + senderAddressesObj.setSenderAddressList(senderAddressList); + responseWrapper.setSenderAddressList(senderAddressesObj); + responseWrapper.setHttpStatus(Response.Status.ACCEPTED); + }catch(Exception ex){ + LOG.error( + "###USER### Error in processing send addresses retrieve request. ", + ex); + responseWrapper.setHttpStatus(Response.Status.BAD_REQUEST); + } + + return responseWrapper; + } + + @Override + protected void init(RetrieveSenderAddressServiceRequestWrapper extendedRequestDTO) throws Exception { + requestWrapper = extendedRequestDTO; + responseWrapper = new RetrieveSenderAddressServiceResponseWrapper(); + } + +} diff --git a/dep-sandbox/src/main/java/com/wso2telco/services/dep/sandbox/util/RequestType.java b/dep-sandbox/src/main/java/com/wso2telco/services/dep/sandbox/util/RequestType.java index 46c5edfc..f647e9c2 100644 --- a/dep-sandbox/src/main/java/com/wso2telco/services/dep/sandbox/util/RequestType.java +++ b/dep-sandbox/src/main/java/com/wso2telco/services/dep/sandbox/util/RequestType.java @@ -1,6 +1,6 @@ package com.wso2telco.services.dep.sandbox.util; public enum RequestType { - SMSMESSAGING, PAYMENT, USSD, LOCATION, MOBILEID, PROVISIONING,PROVISIONINGCONFIG, USER, CUSTOMERINFO,CUSTOMERINFOCONFIG, CREDIT, WALLET, WALLETCONFIG; + SMSMESSAGING, PAYMENT, USSD, LOCATION, MOBILEID, PROVISIONING,PROVISIONINGCONFIG, USER, CUSTOMERINFO,CUSTOMERINFOCONFIG, CREDIT, WALLET, WALLETCONFIG , GENERIC; }