Professional Documents
Culture Documents
action;
import id.co.ahm.report.authorization.dao.AuthorizationDao;
import id.co.ahm.report.authorization.dao.UserSessionDao;
import id.co.ahm.report.generator.model.*;
import id.co.ahm.report.generator.util.*;
import org.apache.commons.lang.RandomStringUtils;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.UUID;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import org.springframework.http.HttpEntity;
import org.springframework.http.MediaType;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.http.ResponseEntity;
import org.springframework.web.client.RestTemplate;
/**
* Created with IntelliJ IDEA. User: andri.khrisharyadi Date: 10/23/13 Time:
* 1:19 PM
* <p/>
* Running Report Generator to call rwwebservice
*/
public class RunReport extends BaseActionServlet {
/**
* call Rwwebservice to generate report
*
* @param request
* @param response
* @return
*/
private AjaxReportResponse generateReport(HttpServletRequest request,
HttpServletResponse response) {
AjaxReportResponse ajaxReportResponse = new AjaxReportResponse();
return ajaxReportResponse;
}
/**
* Get AppName
*
* @param request
* @return
*/
private String getAppName(String reportName) {
String appName = null;
//int titik = reportName.indexOf(".");
if (!reportName.isEmpty() || !reportName.equals("")) {
appName = substring(reportName, 8, 9); // Standard check
if (appName.equalsIgnoreCase("r")) { // Old standard
appName = substring(reportName, 0, 8) // Module name
+ substring(reportName, 9, 12); // Application number
} else { // New standard
if (reportName.lastIndexOf("\\") > -1) {
appName = substring(reportName, // D:\\data\\ahmXXYYYNNNrNN ==>
ahmXXYYYNNN
reportName.lastIndexOf("\\") + 1,
reportName.lastIndexOf("\\") + 12);
} else if (reportName.lastIndexOf("/") > -1) {
appName = substring(reportName, // /data/ahmXXYYYNNNrNN ==>
ahmXXYYYNNN
reportName.lastIndexOf("/") + 1,
reportName.lastIndexOf("/") + 12);
} else {
appName = substring(reportName, 0, 11); // Module name +
Application number
}
}
}
return appName;
}
/**
* create report parameter
*
* @param request
* @param serverHostname
* @return
*/
private ReportRequest createReportParam(HttpServletRequest request,
ServerHostname serverHostname) {
String destType =
StringUtils.stringNvl(request.getParameter(Constants.ParamaterName.DEST_TYPE),
Constants.DEFAULT_DEST_TYPE);
//reportRequest.setHostname(prop.getProperty("report.server.host")
+":"+prop.getProperty("report.server.port"));
reportRequest.setHostname(serverHostname.getHostName() + ":" +
prop.getProperty("report.server.port"));
reportRequest.setReportServer(serverHostname.getServerName());
String sourceRdf =
request.getParameter(Constants.ParamaterName.SOURCE_FILE);
int titik = sourceRdf.indexOf(".");
if (titik > 0) {
try {
sourceRdf = sourceRdf.substring(0, titik);
} catch (Exception e) {
sourceRdf =
request.getParameter(Constants.ParamaterName.SOURCE_FILE);
}
}
reportRequest.setSourceFile(propConnection.getProperty("report.source.folder")
+ sourceRdf + "." + Constants.DEFAULT_REPORT_EXT);
reportRequest.setDestType(destType);
if (ext != null) {
//jika destFormatnya honda1 / honda2 maka akan langsung diarakan ke
dflt
if
(request.getParameter(Constants.ParamaterName.DEST_FORMAT).equalsIgnoreCase(Constan
ts.DestFormatType.HONDA_1)
||
request.getParameter(Constants.ParamaterName.DEST_FORMAT).equalsIgnoreCase(Constant
s.DestFormatType.HONDA_2)) {
reportRequest.setDestFormat(Constants.DestFormatType.DFLT);
} else {
reportRequest.setDestFormat(request.getParameter(Constants.ParamaterName.DEST_FORMA
T));
}
} else {
reportRequest.setDestFormat(Constants.DEFAULT_DEST_FORMAT);
}
reportRequest.setDestFile(propConnection.getProperty("report.destination.folder") +
filename); // request.getParameter("destName"));
reportRequest.setFilename(filename);
return reportRequest;
}
/**
* Get File name
*
* @param request
* @return
*/
private String getDestinationFilename(HttpServletRequest request) {
if (request.getParameter(Constants.ParamaterName.DEST_NAME) != null && !
request.getParameter(Constants.ParamaterName.DEST_NAME).isEmpty()) {
return request.getParameter(Constants.ParamaterName.DEST_NAME);
} else {
String ext =
StringUtils.stringNvl(request.getParameter(Constants.ParamaterName.DEST_FORMAT),
Constants.DEFAULT_DEST_FORMAT);
if (ext.equals(Constants.DestFormatType.DFLT)) {
ext = Constants.FileExtension.HONDA1;
}
if (ext.equals(Constants.DestFormatType.SPREADSHEET)) {
ext = Constants.FileExtension.XLS;
}
String reportName =
ReportUtils.getFilenameWitoutExt(request.getParameter(Constants.ParamaterName.SOURC
E_FILE));
/**
* Check Authorization
*
* @param request
* @param userId
* @return
*/
private Boolean checkAuthorization(HttpServletRequest request, String userId,
String appName) {
AuthorizationDao authorizationDao = new AuthorizationDao();
Boolean authorized = authorizationDao.getAuthorizationJPA(
request.getParameter(Constants.ParamaterName.V_MODULE_NAME),
appName, userId
);
return authorized;
}
/**
* Get User id by
*
* @param request by session id
* @return
*/
private String getSessionUserId(HttpServletRequest request) {
String userId =
userSessionDao.getVUserId(request.getParameter(Constants.ParamaterName.J_SESSION_ID
));
return userId;
}
/**
* Get nama ldap form JSessionId
*
* @param request
* @return
*/
private String getNameLdap(HttpServletRequest request) {
return userSessionDao.getUsernameLdapFromSession(request.getParameter(
Constants.ParamaterName.J_SESSION_ID));
}
/**
*
* @param request
*/
private void deleteSession(String jsessionid) {
userSessionDao.deleteSession(jsessionid);
}
/**
* Send a email
*
* @param mailTo
* @param urlReport
*/
private void sendMailtoUser(final String mailTo, final String urlReport) {
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
instantiateProperties();
instantiateProperties(request);
AjaxReportResponse result = generateReport(request, response);
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
instantiateProperties();
instantiateProperties(request);
AjaxReportResponse result = generateReport(request, response);
/**
* Substring string
*
* @param sourceData
* @param beginIndex
* @param endIndex
* @return
*/
public static String substring(String sourceData, int beginIndex, int endIndex)
{
int length = 0;
try {
if (sourceData == null) {
return "";
} else {
length = sourceData.length();
return sourceData.substring(beginIndex, endIndex);
}
} catch (StringIndexOutOfBoundsException sex) {
if ((beginIndex >= length) || (endIndex <= 0)) {
return "";
} else if ((beginIndex < 0) && (endIndex > length)) {
return sourceData;
} else if ((beginIndex < 0) && (endIndex <= length)) {
return substring(sourceData, 0, endIndex);
} else if (endIndex > length) {
return substring(sourceData, beginIndex, length);
} else {
throw sex;
}
}
}