package com.chinasoft.xuzs.portal;
public class ActivateTest {
/**
* 根据传入的Request,生成对应的Response
* @param request
* @return
*/
public Response createResponse(Request request) {
// 简单初始化Response,防止空指针
Response response = new Response();
// 保证构造的Response无误
if (!buildResponse(response)) {
return response;
}
// 保证传过来的Request无误
if (!validate(request, response)) {
return response;
}
// 获取Request中的核心数据uids
String uids = request.getUids();
// 处理uids并返回结果对象
Result result = process(uids);
// 若失败,说明Request处有误
if(!result.isSuccess()){
response.setStatus("request");
return response;
}
// 此处无法判定是Request还是Response有错,暂定Response
if(result.getFailedUids().length()>0){
response.setStatus("response");
response.setStatusMessage(uids);
return response;
}
response.setStatus("success");
return response;
}
/**
* 构造一个缺省的Response
*
* @param response
* @return 是否构造成功
*/
private boolean buildResponse(Response response) {
// TODO
return true;
}
/**
* 校验Request有效性
* @param request
* @param response
* @return 是否有效
*/
private boolean validate(Request request, Response response) {
// TODO
return true;
}
/**
* 核心逻辑
* @param uids
* @return 结果处理对象
*/
private Result process(String uids) {
// TODO
return null;
}
}
class Response {
String status;
String statusMessage;
public String getStatus() {
return status;
}
public void setStatus(String status) {
this.status = status;
}
public String getStatusMessage() {
return statusMessage;
}
public void setStatusMessage(String statusMessage) {
this.statusMessage = statusMessage;
}
}
class Request {
String uids;
public String getUids() {
return uids;
}
public void setUids(String uids) {
this.uids = uids;
}
}
class Result {
boolean success;
String failedUids;
public boolean isSuccess() {
return success;
}
public void setSuccess(boolean success) {
this.success = success;
}
public String getFailedUids() {
return failedUids;
}
public void setFailedUids(String failedUids) {
this.failedUids = failedUids;
}
}