Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement retrieve sender address api for sand-box ui #79

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
@@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ protected List<Object> getRestFulComponents() {
listOfObject.add(new CreditService());
listOfObject.add(new WalletService());
listOfObject.add(new WalletConfigurationService());
listOfObject.add(new CommonService());
return listOfObject;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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();
}}

}
Original file line number Diff line number Diff line change
@@ -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;

Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
}
}
Original file line number Diff line number Diff line change
@@ -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<String> senderAddressList;

public void setSenderAddressList(List<String> senderAddressList) {
this.senderAddressList = senderAddressList;
}

public List<String> getSenderAddressList() {
return senderAddressList;
}

}


}
Original file line number Diff line number Diff line change
@@ -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<RetrieveSenderAddressServiceRequestWrapper> {

private RetrieveSenderAddressServiceResponseWrapper responseWrapper;
private RetrieveSenderAddressServiceRequestWrapper requestWrapper;

{
LOG = LogFactory.getLog(RetrieveSenderAddressServiceServiceHandler.class);
}

@Override
protected Returnable getResponseDTO() {
return responseWrapper;
}

@Override
protected List<String> getAddress() {
List<String> address = new ArrayList<String>();
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<String> senderAddressList = new ArrayList<String>();
SenderAddresses senderAddressesObj = new SenderAddresses();
List<SenderAddress> 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();
}

}
Original file line number Diff line number Diff line change
@@ -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;

}