001: /**
002: *
003: */package com.bostechcorp.cbesb.console.server;
004:
005: import java.sql.SQLException;
006: import java.util.ArrayList;
007: import java.util.List;
008:
009: import com.bostechcorp.cbesb.common.i18n.CoreMessageConstants;
010: import com.bostechcorp.cbesb.common.i18n.Messages;
011: import com.bostechcorp.cbesb.console.common.BaseRPCResultInfo;
012: import com.bostechcorp.cbesb.console.common.ServerSideException;
013: import com.bostechcorp.cbesb.console.common.errordb.AttachmentContentInfo;
014: import com.bostechcorp.cbesb.console.common.errordb.AttachmentInfo;
015: import com.bostechcorp.cbesb.console.common.errordb.ErrorInfo;
016: import com.bostechcorp.cbesb.console.common.errordb.ErrorListInfo;
017: import com.bostechcorp.cbesb.console.common.errordb.ExchangeInfo;
018: import com.bostechcorp.cbesb.console.common.errordb.ExchangePropertyInfo;
019: import com.bostechcorp.cbesb.console.common.errordb.MessagePropertyInfo;
020: import com.bostechcorp.cbesb.console.common.errordb.NormalizedMessageInfo;
021: import com.bostechcorp.cbesb.console.rpc.ErrorDbOperations;
022: import com.bostechcorp.cbesb.runtime.ccsl.errordb.AttachmentVO;
023: import com.bostechcorp.cbesb.runtime.ccsl.errordb.ByteContentVO;
024: import com.bostechcorp.cbesb.runtime.ccsl.errordb.DaoConfig;
025: import com.bostechcorp.cbesb.runtime.ccsl.errordb.ErrorVO;
026: import com.bostechcorp.cbesb.runtime.ccsl.errordb.ExchangePropertyVO;
027: import com.bostechcorp.cbesb.runtime.ccsl.errordb.ExchangeVO;
028: import com.bostechcorp.cbesb.runtime.ccsl.errordb.MessagePropertyVO;
029: import com.bostechcorp.cbesb.runtime.ccsl.errordb.NormalizedMessageVO;
030: import com.bostechcorp.cbesb.runtime.ccsl.errordb.StringContentVO;
031: import com.ibatis.common.util.PaginatedList;
032: import com.ibatis.sqlmap.client.SqlMapClient;
033:
034: /**
035: * @author LPS
036: *
037: */
038: public class ErrorDbOperationsImpl extends ConsoleRemoteServiceServlet
039: implements ErrorDbOperations {
040:
041: private static final long serialVersionUID = 692664184052300297L;
042:
043: private static DaoConfig daoConfig;
044:
045: private static SqlMapClient sqlMap;
046:
047: private static PaginatedList errorList;
048:
049: static {
050: if (daoConfig == null) {
051: daoConfig = new DaoConfig();
052: sqlMap = daoConfig.getSqlMapInstance();
053: }
054: }
055:
056: private static int count = 0;
057:
058: public ErrorDbOperationsImpl() {
059: }
060:
061: public BaseRPCResultInfo delete(String[] idArray)
062: throws ServerSideException {
063: BaseRPCResultInfo result = new BaseRPCResultInfo();
064: if (sqlMap != null) {
065: try {
066: ExchangeVO exchangeVO = new ExchangeVO();
067: ErrorVO error = new ErrorVO();
068: for (int i = 0; i < idArray.length; i++) {
069: long id = 0;
070: try {
071: id = Long.parseLong(idArray[i]);
072: } catch (NumberFormatException nfe) {
073: break;
074: }
075: exchangeVO.setExchangeId(id);
076: error.setErrorId(id);
077: sqlMap.delete("deleteExchange", exchangeVO);
078: sqlMap.delete("deleteErrorByErrorId", error);
079: }
080: return result;
081: } catch (Exception e) {
082: result
083: .setException(
084: (Messages
085: .get(CoreMessageConstants.FAILED_DELETE_ERROR_RECORD)),
086: e);
087: }
088: } else
089: result.setException(new ServerSideException((Messages
090: .get(CoreMessageConstants.SQLMAP_NULL_EXCEPTION))));
091: return result;
092: }
093:
094: public ErrorListInfo readErrorTable(int currentPage)
095: throws ServerSideException {
096: if (sqlMap != null) {
097: ErrorVO errorVO = new ErrorVO();
098: try {
099:
100: errorList = sqlMap.queryForPaginatedList(
101: "selectAllErrors", errorVO, getRowsPerPage());
102: count = countErrorTableRows();
103: //errorList.gotoPage(currentPage);
104:
105: } catch (Exception e) {
106: ErrorListInfo result = new ErrorListInfo();
107: result
108: .setException(
109: (Messages
110: .get(CoreMessageConstants.FAILED_READ_ERROR_RECORD)),
111: e);
112: return result;
113: }
114: }
115: int rpp = getRowsPerPage();
116: int totalPages = (count % rpp == 0) ? count / rpp : count / rpp
117: + 1;
118: ErrorListInfo eli = new ErrorListInfo(errorList.getPageSize(),
119: errorList.getPageIndex(), count, totalPages, errorList
120: .isFirstPage(), errorList.isLastPage(),
121: transformErrorList(errorList));
122: return eli;
123: }
124:
125: private int countErrorTableRows() throws Exception {
126: Object result = sqlMap.queryForObject("counter", null);
127: return ((Integer) result).intValue();
128: }
129:
130: private List transformErrorList(PaginatedList errorList2) {
131: ArrayList<ErrorInfo> l = new ArrayList<ErrorInfo>();
132: for (Object o : errorList2) {
133: l.add(transformErrorVO(o));
134: }
135: return l;
136: }
137:
138: private ErrorInfo transformErrorVO(Object o) {
139: if (o instanceof ErrorVO) {
140: ErrorVO err = (ErrorVO) o;
141: return new ErrorInfo(err.getExceptionString(), err
142: .getStackTrace(), err.getErrorDateTime()
143: .toLocaleString(), err.getExchangeId(), err
144: .getErrorId());
145: }
146: return null;
147: }
148:
149: public ExchangeInfo readExchange(int exchangeId)
150: throws ServerSideException {
151: ExchangeInfo exchangeInfo = new ExchangeInfo();
152: try {
153: Object exchangeVOObject = sqlMap.queryForObject(
154: "selectExchangeByExchangeId", new Long(exchangeId));
155: exchangeInfo = transformExchangeVO(exchangeVOObject);
156:
157: List exchangePropertyList = sqlMap.queryForList(
158: "selectExchangePropertyByExchangeId",
159: exchangeVOObject);
160: List<ExchangePropertyInfo> exchangePropertyInfoList = transformExchangePropertyList(exchangePropertyList);
161: exchangeInfo.setExchangeProperty(exchangePropertyInfoList);
162:
163: List normalizedMessageList = sqlMap.queryForList(
164: "selectNormalizedMessageByExchangeId",
165: exchangeVOObject);
166: List<NormalizedMessageInfo> normalizedMessageInfoList = transformNormalizedMessageList(normalizedMessageList);
167: exchangeInfo
168: .setNormalizedMessages(normalizedMessageInfoList);
169: } catch (Exception e) {
170: exchangeInfo
171: .setException(
172: (Messages
173: .get(CoreMessageConstants.FAILED_READ_EXCHANGE)),
174: e);
175: }
176: return exchangeInfo;
177: }
178:
179: private ExchangeInfo transformExchangeVO(Object exchangeVOObject) {
180: if (exchangeVOObject instanceof ExchangeVO) {
181: ExchangeInfo exchangeInfo = new ExchangeInfo();
182: ExchangeVO exchangeVO = (ExchangeVO) exchangeVOObject;
183: exchangeInfo.setExchangeId(exchangeVO.getExchangeId());
184: exchangeInfo.setRole(exchangeVO.getRole());
185: exchangeInfo.setEndpointService(exchangeVO
186: .getEndpointService());
187: exchangeInfo.setEndpointName(exchangeVO.getEndpointName());
188: exchangeInfo.setExchangeContainerId(exchangeVO
189: .getExchangeContainerId());
190: exchangeInfo
191: .setInterfaceName(exchangeVO.getInterfaceName());
192: exchangeInfo.setOperation(exchangeVO.getOperation());
193: exchangeInfo.setPattern(exchangeVO.getPattern());
194: exchangeInfo.setService(exchangeVO.getService());
195: exchangeInfo.setExchangeStatus(exchangeVO
196: .getExchangeStatus());
197: return exchangeInfo;
198: }
199: return null;
200: }
201:
202: private List<ExchangePropertyInfo> transformExchangePropertyList(
203: List exchangePropertyList) {
204: List<ExchangePropertyInfo> exchangePropertyInfoList = new ArrayList<ExchangePropertyInfo>();
205: for (Object exchangePropertyObject : exchangePropertyList) {
206: ExchangePropertyVO exchangePropertyVO = (ExchangePropertyVO) exchangePropertyObject;
207: ExchangePropertyInfo exchangePropertyInfo = new ExchangePropertyInfo(
208: exchangePropertyVO.getExchangeId(),
209: exchangePropertyVO.getName(), exchangePropertyVO
210: .getValue());
211: exchangePropertyInfoList.add(exchangePropertyInfo);
212: }
213: return exchangePropertyInfoList;
214: }
215:
216: private List<NormalizedMessageInfo> transformNormalizedMessageList(
217: List normalizedMessageList) throws SQLException {
218: List<NormalizedMessageInfo> normalizedMessageInfoList = new ArrayList<NormalizedMessageInfo>();
219: for (Object normalizedMessageObject : normalizedMessageList) {
220: NormalizedMessageInfo normalizedMessageInfo;
221: NormalizedMessageVO normalizedMessageVO = (NormalizedMessageVO) normalizedMessageObject;
222: List messagePropertyList = sqlMap.queryForList(
223: "selectMessagePropertyByExchangeId",
224: normalizedMessageVO);
225: normalizedMessageInfo = new NormalizedMessageInfo(
226: normalizedMessageVO.getExchangeId(),
227: normalizedMessageVO.getType(), normalizedMessageVO
228: .getContent());
229: List<MessagePropertyInfo> messagePropertyInfoList = transformMessagePropertyList(messagePropertyList);
230: normalizedMessageInfo
231: .setNormalizedMessagePropertyList(messagePropertyInfoList);
232: List attachmentList = sqlMap
233: .queryForList("selectAttachmentByExchangeId",
234: normalizedMessageVO);
235: List<AttachmentInfo> attachmentInfoList = transformAttachmentList(attachmentList);
236: normalizedMessageInfo
237: .setAttachementList(attachmentInfoList);
238: normalizedMessageInfoList.add(normalizedMessageInfo);
239: }
240: return normalizedMessageInfoList;
241: }
242:
243: private List<MessagePropertyInfo> transformMessagePropertyList(
244: List messagePropertyList) {
245: List<MessagePropertyInfo> messagePropertyInfoList = new ArrayList<MessagePropertyInfo>();
246: for (Object messagePropertyObject : messagePropertyList) {
247: MessagePropertyInfo messagePropertyInfo;
248: MessagePropertyVO messagePropertyVO = (MessagePropertyVO) messagePropertyObject;
249: messagePropertyInfo = new MessagePropertyInfo(
250: messagePropertyVO.getExchangeId(),
251: messagePropertyVO.getType(), messagePropertyVO
252: .getName(), messagePropertyVO.getValue());
253: messagePropertyInfoList.add(messagePropertyInfo);
254: }
255: return messagePropertyInfoList;
256: }
257:
258: private List<AttachmentInfo> transformAttachmentList(
259: List attachmentList) throws SQLException {
260: List<AttachmentInfo> attachmentInfoList = new ArrayList<AttachmentInfo>();
261: for (Object attachmentObject : attachmentList) {
262: AttachmentInfo attachmentInfo;
263: AttachmentVO attachmentVO = (AttachmentVO) attachmentObject;
264: AttachmentContentInfo attachmentContentInfo;
265: if ("byte".equalsIgnoreCase(attachmentVO.getContentType())) {
266: ByteContentVO byteContentVO = (ByteContentVO) sqlMap
267: .queryForObject(
268: "selectByteContentByExchangeId",
269: attachmentVO);
270: attachmentContentInfo = new AttachmentContentInfo(
271: byteContentVO.getExchangeId(), byteContentVO
272: .getType(), byteContentVO.getName(),
273: new String(byteContentVO.getContent()));
274: } else if ("string".equalsIgnoreCase(attachmentVO
275: .getContentType())) {
276: StringContentVO stringContentVO = (StringContentVO) sqlMap
277: .queryForObject(
278: "selectStringContentByExchangeId",
279: attachmentVO);
280: attachmentContentInfo = new AttachmentContentInfo(
281: stringContentVO.getExchangeId(),
282: stringContentVO.getType(), stringContentVO
283: .getName(), new String(stringContentVO
284: .getContent()));
285: } else {
286: attachmentContentInfo = new AttachmentContentInfo();
287: }
288: attachmentInfo = new AttachmentInfo(attachmentVO
289: .getExchangeId(), attachmentVO.getType(),
290: attachmentVO.getName(), attachmentVO
291: .getContentType(), attachmentContentInfo);
292: attachmentInfoList.add(attachmentInfo);
293: }
294: return attachmentInfoList;
295: }
296:
297: /**
298: * @return the numbers of rows per page, from the current Session
299: */
300: protected int getRowsPerPage() {
301:
302: try {
303: return ConsoleSettingUtil.getErrorDbPageSize(super
304: .getCurrentUserId());
305: } catch (Exception e) {
306:
307: e.printStackTrace();
308:
309: }
310: return ConsoleSettingUtil.DEFAULT_PAGESIZE;
311: }
312:
313: public ErrorListInfo readErrorTableNextPage(int page)
314: throws ServerSideException {
315: return gotoPage(page + 1);
316: }
317:
318: public ErrorListInfo readErrorTablePreviousPage(int page)
319: throws ServerSideException {
320: return gotoPage(page - 1);
321: }
322:
323: public ErrorListInfo readErrorTableGotoPage(int page)
324: throws ServerSideException {
325: return gotoPage(page);
326: }
327:
328: private ErrorListInfo gotoPage(int page) {
329: errorList.gotoPage(page);
330: ErrorListInfo eli = new ErrorListInfo(errorList.getPageSize(),
331: errorList.getPageIndex(), count, (count
332: % errorList.getPageSize() == 0) ? count
333: / errorList.getPageSize() : count
334: / errorList.getPageSize() + 1, errorList
335: .isFirstPage(), errorList.isLastPage(),
336: transformErrorList(errorList));
337: return eli;
338: }
339:
340: public BaseRPCResultInfo deleteAll() throws ServerSideException {
341: BaseRPCResultInfo result = new BaseRPCResultInfo();
342: try {
343: sqlMap.delete("deleteAllFromExchange", null);
344: sqlMap.delete("deleteAllFromError", null);
345: } catch (SQLException e) {
346: result.setException((Messages
347: .get(CoreMessageConstants.FAILED_DELETE)), e);
348: }
349: // throw new ServerSideException("SqlMap is Null,Could not Delete Error & Exchange");
350: return result;
351:
352: }
353:
354: }
|