/**
* MailArchiver is an application that provides services for storing and managing e-mail messages through a Web Services SOAP interface.
* Copyright (C) 2012 Marcio Andre Scholl Levien and Fernando Alberto Reuter Wendt and Jose Ronaldo Nogueira Fonseca Junior
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see .
*/
/******************************************************************************\
*
* This product was developed by
*
* SERVIÇO FEDERAL DE PROCESSAMENTO DE DADOS (SERPRO),
*
* a government company established under Brazilian law (5.615/70),
* at Department of Development of Porto Alegre.
*
\******************************************************************************/
package serpro.mailarchiver.service.web;
import javax.jdo.annotations.PersistenceAware;
import javax.jws.WebService;
import org.springframework.beans.factory.annotation.Autowired;
import static com.google.common.base.Strings.*;
import serpro.mailarchiver.service.BaseService;
import serpro.mailarchiver.service.dto.TAttachment;
import serpro.mailarchiver.service.dto.TFault;
import serpro.mailarchiver.service.dto.TFolder;
import serpro.mailarchiver.service.dto.TMessage;
import serpro.mailarchiver.service.dto.TSession;
import serpro.mailarchiver.session.Session;
import serpro.mailarchiver.session.SessionMap;
import serpro.mailarchiver.util.Logger;
@WebService(
endpointInterface = "serpro.mailarchiver.service.web.ArchiveServices",
serviceName = "ArchiveServices")
@PersistenceAware
public class DefaultArchiveServices
extends BaseService
implements ArchiveServices
{
private static final Logger log = Logger.getLocalLogger();
private static final String[] EMPTY_MESSAGES_ID = new String[0];
public DefaultArchiveServices() {
log.debug("Instanciando bean DefaultArchiveServices");
}
//
//==========================================================================
@Autowired
private GetFaultInfoOperation getFaultInfo;
@Override
public TFault getFaultInfo(String sessionId) {
sessionId = nullToEmpty(sessionId).trim();
Session session = SessionMap.get(sessionId);
if(session == null) {
return null;
}
Session.setThreadSession(session);
return getFaultInfo.apply();
}
//
//
//==========================================================================
@Autowired
private LoginOperation login;
@Override
public TSession login(String userId, String password, String phpSessId, String balanceId) throws ServiceFault {
userId = nullToEmpty(userId).trim();
password = nullToEmpty(password).trim();
phpSessId = nullToEmpty(phpSessId).trim();
balanceId = nullToEmpty(balanceId).trim();
try {
TSession ret = login.apply(userId, password, phpSessId, balanceId);
return ret;
}
catch(Throwable t) {
ServiceFault e;
if(t instanceof ServiceFault) {
e = (ServiceFault) t;
}
else {
e = ServiceFault.runtimeException()
.setActor("login")
.setCause(t)
.create();
}
TFault faultInfo = e.getFaultInfo();
if(faultInfo != null) {
log.error(faultInfo);
}
log.error(e, "login\n\tuserId: %s", userId);
throw e;
}
}
//
//
//==========================================================================
@Autowired
private LogoutOperation logout;
@Override
public Integer logout(String sessionId) throws ServiceFault {
long time1 = System.currentTimeMillis();
sessionId = nullToEmpty(sessionId).trim();
Session session = SessionMap.get(sessionId);
if(session == null) {
return null;
}
Session.setThreadSession(session);
long time2 = System.currentTimeMillis();
session.enroll();
long time3 = System.currentTimeMillis();
try {
session.incStatistics("logout-Total");
Integer ret = logout.apply();
session.incStatistics("logout-Success");
return ret;
}
catch(Throwable t) {
session.incStatistics("logout-Failure");
ServiceFault e;
if(t instanceof ServiceFault) {
e = (ServiceFault) t;
}
else {
e = ServiceFault.runtimeException()
.setActor("logout")
.setCause(t)
.create();
}
TFault faultInfo = e.getFaultInfo();
if(faultInfo != null) {
log.error(faultInfo);
}
log.error(e, "logout\n\tsessionId: %s", sessionId);
session.setLastFault(faultInfo);
throw e;
}
finally {
long time4 = System.currentTimeMillis();
session.depart();
long time5 = System.currentTimeMillis();
log.info("Execution time profile logout: [i12=%1$d] [i23=%2$d] [i34=%3$d] [i45=%4$d]",
time2-time1, time3-time2, time4-time3, time5-time4);
}
}
//
//
//==========================================================================
@Autowired
private ListFoldersOperation listFolders;
@Override
public TFolder[] listFolders(String sessionId, String folderId) throws ServiceFault {
long time1 = System.currentTimeMillis();
sessionId = nullToEmpty(sessionId).trim();
folderId = nullToEmpty(folderId).trim();
Session session = SessionMap.get(sessionId);
if(session == null) {
return null;
}
Session.setThreadSession(session);
long time2 = System.currentTimeMillis();
session.enroll();
long time3 = System.currentTimeMillis();
try {
session.incStatistics("listFolders-Total");
TFolder[] ret = listFolders.apply(folderId);
session.incStatistics("listFolders-Success");
return ret;
}
catch(Throwable t) {
session.incStatistics("listFolders-Failure");
ServiceFault e;
if(t instanceof ServiceFault) {
e = (ServiceFault) t;
}
else {
e = ServiceFault.runtimeException()
.setActor("listFolders")
.setCause(t)
.create();
}
TFault faultInfo = e.getFaultInfo();
if(faultInfo != null) {
log.error(faultInfo);
}
log.error(e, "listFolders\n\tsessionId: %s\n\tfolderId: %s", sessionId, folderId);
session.setLastFault(faultInfo);
throw e;
}
finally {
long time4 = System.currentTimeMillis();
session.depart();
long time5 = System.currentTimeMillis();
log.info("Execution time profile listFolders: [i12=%1$d] [i23=%2$d] [i34=%3$d] [i45=%4$d]",
time2-time1, time3-time2, time4-time3, time5-time4);
}
}
//
//
//==========================================================================
@Autowired
private ListMessagesOperation listMessages;
@Override
public TMessage[] listMessages(String sessionId, String queryConfig) throws ServiceFault {
long time1 = System.currentTimeMillis();
sessionId = nullToEmpty(sessionId).trim();
queryConfig = nullToEmpty(queryConfig).trim();
Session session = SessionMap.get(sessionId);
if(session == null) {
return null;
}
Session.setThreadSession(session);
long time2 = System.currentTimeMillis();
session.enroll();
long time3 = System.currentTimeMillis();
try {
session.incStatistics("listMessages-Total");
TMessage[] ret = listMessages.apply(queryConfig);
session.incStatistics("listMessages-Success");
return ret;
}
catch(Throwable t) {
session.incStatistics("listMessages-Failure");
ServiceFault e;
if(t instanceof ServiceFault) {
e = (ServiceFault) t;
}
else {
e = ServiceFault.runtimeException()
.setActor("listMessages")
.setCause(t)
.create();
}
TFault faultInfo = e.getFaultInfo();
if(faultInfo != null) {
log.error(faultInfo);
}
log.error(e, "listMessages\n\tsessionId: %s\n\tqueryConfig: %s", sessionId, queryConfig);
session.setLastFault(faultInfo);
throw e;
}
finally {
long time4 = System.currentTimeMillis();
session.depart();
long time5 = System.currentTimeMillis();
log.info("Execution time profile listMessages: [i12=%1$d] [i23=%2$d] [i34=%3$d] [i45=%4$d]",
time2-time1, time3-time2, time4-time3, time5-time4);
}
}
//
//
//==========================================================================
//TODO: avaliar necessidade
@Autowired
private ListAttachmentsOperation listAttachments;
@Override
public TAttachment[] listAttachments(String sessionId, String messageId) throws ServiceFault {
long time1 = System.currentTimeMillis();
sessionId = nullToEmpty(sessionId).trim();
messageId = nullToEmpty(messageId).trim();
Session session = SessionMap.get(sessionId);
if(session == null) {
return null;
}
Session.setThreadSession(session);
long time2 = System.currentTimeMillis();
session.enroll();
long time3 = System.currentTimeMillis();
try {
session.incStatistics("listAttachments-Total");
TAttachment[] ret = listAttachments.apply(messageId);
session.incStatistics("listAttachments-Success");
return ret;
}
catch(Throwable t) {
session.incStatistics("listAttachments-Failure");
ServiceFault e;
if(t instanceof ServiceFault) {
e = (ServiceFault) t;
}
else {
e = ServiceFault.runtimeException()
.setActor("listAttachments")
.setCause(t)
.create();
}
TFault faultInfo = e.getFaultInfo();
if(faultInfo != null) {
log.error(faultInfo);
}
log.error(e, "listAttachments\n\tsessionId: %s\n\tmessageId: %s", sessionId, messageId);
session.setLastFault(faultInfo);
throw e;
}
finally {
long time4 = System.currentTimeMillis();
session.depart();
long time5 = System.currentTimeMillis();
log.info("Execution time profile listAttachments: [i12=%1$d] [i23=%2$d] [i34=%3$d] [i45=%4$d]",
time2-time1, time3-time2, time4-time3, time5-time4);
}
}
//
//
//==========================================================================
@Autowired
private GetMessageBodyOperation getMessageBody;
@Override
public String getMessageBody(String sessionId, String messageId) throws ServiceFault {
long time1 = System.currentTimeMillis();
sessionId = nullToEmpty(sessionId).trim();
messageId = nullToEmpty(messageId).trim();
Session session = SessionMap.get(sessionId);
if(session == null) {
return null;
}
Session.setThreadSession(session);
long time2 = System.currentTimeMillis();
session.enroll();
long time3 = System.currentTimeMillis();
try {
session.incStatistics("getMessageBody-Total");
String ret = getMessageBody.apply(messageId);
session.incStatistics("getMessageBody-Success");
return ret;
}
catch(Throwable t) {
session.incStatistics("getMessageBody-Failure");
ServiceFault e;
if(t instanceof ServiceFault) {
e = (ServiceFault) t;
}
else {
e = ServiceFault.runtimeException()
.setActor("getMessageBody")
.setCause(t)
.create();
}
TFault faultInfo = e.getFaultInfo();
if(faultInfo != null) {
log.error(faultInfo);
}
log.error(e, "getMessageBody\n\tsessionId: %s\n\tmessageId: %s", sessionId, messageId);
session.setLastFault(faultInfo);
throw e;
}
finally {
long time4 = System.currentTimeMillis();
session.depart();
long time5 = System.currentTimeMillis();
log.info("Execution time profile getMessageBody: [i12=%1$d] [i23=%2$d] [i34=%3$d] [i45=%4$d]",
time2-time1, time3-time2, time4-time3, time5-time4);
}
}
//
//
//==========================================================================
@Autowired
private GetRawBinaryBodyOperation getRawBinaryBody;
@Override
public String getRawBinaryBody(String sessionId, String bodyId) throws ServiceFault {
long time1 = System.currentTimeMillis();
sessionId = nullToEmpty(sessionId).trim();
bodyId = nullToEmpty(bodyId).trim();
Session session = SessionMap.get(sessionId);
if(session == null) {
return null;
}
Session.setThreadSession(session);
long time2 = System.currentTimeMillis();
session.enroll();
long time3 = System.currentTimeMillis();
try {
session.incStatistics("getRawBinaryBody-Total");
String ret = getRawBinaryBody.apply(bodyId);
session.incStatistics("getRawBinaryBody-Success");
return ret;
}
catch(Throwable t) {
session.incStatistics("getRawBinaryBody-Failure");
ServiceFault e;
if(t instanceof ServiceFault) {
e = (ServiceFault) t;
}
else {
e = ServiceFault.runtimeException()
.setActor("getRawBinaryBody")
.setCause(t)
.create();
}
TFault faultInfo = e.getFaultInfo();
if(faultInfo != null) {
log.error(faultInfo);
}
log.error(e, "getRawBinaryBody\n\tsessionId: %s\n\tbodyId: %s", sessionId, bodyId);
session.setLastFault(faultInfo);
throw e;
}
finally {
long time4 = System.currentTimeMillis();
session.depart();
long time5 = System.currentTimeMillis();
log.info("Execution time profile getRawBinaryBody: [i12=%1$d] [i23=%2$d] [i34=%3$d] [i45=%4$d]",
time2-time1, time3-time2, time4-time3, time5-time4);
}
}
//
//
//==========================================================================
@Autowired
private CopyMessagesOperation copyMessages;
@Override
public Integer copyMessages(String sessionId, String folderId, String... messagesId) throws ServiceFault {
long time1 = System.currentTimeMillis();
sessionId = nullToEmpty(sessionId).trim();
folderId = nullToEmpty(folderId).trim();
if(messagesId == null) {
messagesId = EMPTY_MESSAGES_ID;
}
Session session = SessionMap.get(sessionId);
if(session == null) {
return null;
}
Session.setThreadSession(session);
long time2 = System.currentTimeMillis();
session.enroll();
long time3 = System.currentTimeMillis();
try {
session.incStatistics("copyMessages-Total");
Integer ret = copyMessages.apply(folderId, messagesId);
session.incStatistics("copyMessages-Success");
return ret;
}
catch(Throwable t) {
session.incStatistics("copyMessages-Failure");
ServiceFault e;
if(t instanceof ServiceFault) {
e = (ServiceFault) t;
}
else {
e = ServiceFault.runtimeException()
.setActor("copyMessages")
.setCause(t)
.create();
}
TFault faultInfo = e.getFaultInfo();
if(faultInfo != null) {
log.error(faultInfo);
}
StringBuilder sb = new StringBuilder();
sb.append("copyMessages\n\tsessionId: ").append(sessionId).append("\n\tfolderId: ").append(folderId);
for(int i = 0; i < messagesId.length; i++) {
sb.append("\n\tmessagesId[").append(i).append("]: ").append(messagesId[i]);
}
log.error(e, sb.toString());
session.setLastFault(faultInfo);
throw e;
}
finally {
long time4 = System.currentTimeMillis();
session.depart();
long time5 = System.currentTimeMillis();
log.info("Execution time profile copyMessages: [i12=%1$d] [i23=%2$d] [i34=%3$d] [i45=%4$d]",
time2-time1, time3-time2, time4-time3, time5-time4);
}
}
//
//
//==========================================================================
@Autowired
private MoveMessagesOperation moveMessages;
@Override
public Integer moveMessages(String sessionId, String folderId, String... messagesId) throws ServiceFault {
long time1 = System.currentTimeMillis();
sessionId = nullToEmpty(sessionId).trim();
folderId = nullToEmpty(folderId).trim();
if(messagesId == null) {
messagesId = EMPTY_MESSAGES_ID;
}
Session session = SessionMap.get(sessionId);
if(session == null) {
return null;
}
Session.setThreadSession(session);
long time2 = System.currentTimeMillis();
session.enroll();
long time3 = System.currentTimeMillis();
try {
session.incStatistics("moveMessages-Total");
Integer ret = moveMessages.apply(folderId, messagesId);
session.incStatistics("moveMessages-Failure");
return ret;
}
catch(Throwable t) {
session.incStatistics("moveMessages-Failure");
ServiceFault e;
if(t instanceof ServiceFault) {
e = (ServiceFault) t;
}
else {
e = ServiceFault.runtimeException()
.setActor("moveMessages")
.setCause(t)
.create();
}
TFault faultInfo = e.getFaultInfo();
if(faultInfo != null) {
log.error(faultInfo);
}
StringBuilder sb = new StringBuilder();
sb.append("moveMessages\n\tsessionId: ").append(sessionId).append("\n\tfolderId: ").append(folderId);
for(int i = 0; i < messagesId.length; i++) {
sb.append("\n\tmessagesId[").append(i).append("]: ").append(messagesId[i]);
}
log.error(e, sb.toString());
session.setLastFault(faultInfo);
throw e;
}
finally {
long time4 = System.currentTimeMillis();
session.depart();
long time5 = System.currentTimeMillis();
log.info("Execution time profile moveMessages: [i12=%1$d] [i23=%2$d] [i34=%3$d] [i45=%4$d]",
time2-time1, time3-time2, time4-time3, time5-time4);
}
}
//
//
//==========================================================================
@Autowired
private DeleteMessagesOperation deleteMessages;
@Override
public Integer deleteMessages(String sessionId, String... messagesId) throws ServiceFault {
long time1 = System.currentTimeMillis();
sessionId = nullToEmpty(sessionId).trim();
if(messagesId == null) {
messagesId = EMPTY_MESSAGES_ID;
}
Session session = SessionMap.get(sessionId);
if(session == null) {
return null;
}
Session.setThreadSession(session);
long time2 = System.currentTimeMillis();
session.enroll();
long time3 = System.currentTimeMillis();
try {
session.incStatistics("deleteMessages-Total");
Integer ret = deleteMessages.apply(messagesId);
session.incStatistics("deleteMessages-Success");
return ret;
}
catch(Throwable t) {
session.incStatistics("deleteMessages-Failure");
ServiceFault e;
if(t instanceof ServiceFault) {
e = (ServiceFault) t;
}
else {
e = ServiceFault.runtimeException()
.setActor("deleteMessages")
.setCause(t)
.create();
}
TFault faultInfo = e.getFaultInfo();
if(faultInfo != null) {
log.error(faultInfo);
}
StringBuilder sb = new StringBuilder();
sb.append("deleteMessages\n\tsessionId: ").append(sessionId);
for(int i = 0; i < messagesId.length; i++) {
sb.append("\n\tmessagesId[").append(i).append("]: ").append(messagesId[i]);
}
log.error(e, sb.toString());
session.setLastFault(faultInfo);
throw e;
}
finally {
long time4 = System.currentTimeMillis();
session.depart();
long time5 = System.currentTimeMillis();
log.info("Execution time profile deleteMessages: [i12=%1$d] [i23=%2$d] [i34=%3$d] [i45=%4$d]",
time2-time1, time3-time2, time4-time3, time5-time4);
}
}
//
//
//==========================================================================
@Autowired
private TagMessagesOperation tagMessages;
@Override
public Integer tagMessages(String sessionId, String tagConfig) throws ServiceFault {
long time1 = System.currentTimeMillis();
sessionId = nullToEmpty(sessionId).trim();
tagConfig = nullToEmpty(tagConfig).trim();
Session session = SessionMap.get(sessionId);
if(session == null) {
return null;
}
Session.setThreadSession(session);
long time2 = System.currentTimeMillis();
session.enroll();
long time3 = System.currentTimeMillis();
try {
session.incStatistics("tagMessages-Total");
Integer ret = tagMessages.apply(tagConfig);
session.incStatistics("tagMessages-Success");
return ret;
}
catch(Throwable t) {
session.incStatistics("tagMessages-Failure");
ServiceFault e;
if(t instanceof ServiceFault) {
e = (ServiceFault) t;
}
else {
e = ServiceFault.runtimeException()
.setActor("tagMessages")
.setCause(t)
.create();
}
TFault faultInfo = e.getFaultInfo();
if(faultInfo != null) {
log.error(faultInfo);
}
log.error(e, "tagMessages\n\tsessionId: %s\n\ttagConfig: %s", sessionId, tagConfig);
session.setLastFault(faultInfo);
throw e;
}
finally {
long time4 = System.currentTimeMillis();
session.depart();
long time5 = System.currentTimeMillis();
log.info("Execution time profile tagMessages: [i12=%1$d] [i23=%2$d] [i34=%3$d] [i45=%4$d]",
time2-time1, time3-time2, time4-time3, time5-time4);
}
}
//
//
//==========================================================================
@Autowired
private ZipMessagesOperation zipMessages;
@Override
public String zipMessages(String sessionId, String zipConfig) throws ServiceFault {
long time1 = System.currentTimeMillis();
sessionId = nullToEmpty(sessionId).trim();
zipConfig = nullToEmpty(zipConfig).trim();
Session session = SessionMap.get(sessionId);
if(session == null) {
return null;
}
Session.setThreadSession(session);
long time2 = System.currentTimeMillis();
session.enroll();
long time3 = System.currentTimeMillis();
try {
session.incStatistics("zipMessages-Total");
String ret = zipMessages.apply(zipConfig);
session.incStatistics("zipMessages-Success");
return ret;
}
catch(Throwable t) {
session.incStatistics("zipMessages-Failure");
ServiceFault e;
if(t instanceof ServiceFault) {
e = (ServiceFault) t;
}
else {
e = ServiceFault.runtimeException()
.setActor("zipMessages")
.setCause(t)
.create();
}
TFault faultInfo = e.getFaultInfo();
if(faultInfo != null) {
log.error(faultInfo);
}
log.error(e, "zipMessages\n\tsessionId: %s\n\tzipConfig: %s", sessionId, zipConfig);
session.setLastFault(faultInfo);
throw e;
}
finally {
long time4 = System.currentTimeMillis();
session.depart();
long time5 = System.currentTimeMillis();
log.info("Execution time profile zipMessages: [i12=%1$d] [i23=%2$d] [i34=%3$d] [i45=%4$d]",
time2-time1, time3-time2, time4-time3, time5-time4);
}
}
//
//
//==========================================================================
@Autowired
private CreateFolderOperation createFolder;
@Override
public TFolder createFolder(String sessionId, String parentFolderId, String name) throws ServiceFault {
long time1 = System.currentTimeMillis();
sessionId = nullToEmpty(sessionId).trim();
parentFolderId = nullToEmpty(parentFolderId).trim();
name = nullToEmpty(name).trim();
Session session = SessionMap.get(sessionId);
if(session == null) {
return null;
}
Session.setThreadSession(session);
long time2 = System.currentTimeMillis();
session.enroll();
long time3 = System.currentTimeMillis();
try {
session.incStatistics("createFolder-Total");
TFolder ret = createFolder.apply(parentFolderId, name);
session.incStatistics("createFolder-Success");
return ret;
}
catch(Throwable t) {
session.incStatistics("createFolder-Failure");
ServiceFault e;
if(t instanceof ServiceFault) {
e = (ServiceFault) t;
}
else {
e = ServiceFault.runtimeException()
.setActor("createFolder")
.setCause(t)
.create();
}
TFault faultInfo = e.getFaultInfo();
if(faultInfo != null) {
log.error(faultInfo);
}
log.error(e, "createFolder\n\tsessionId: %s\n\tparentFolderId: %s\n\tname: %s", sessionId, parentFolderId, name);
session.setLastFault(faultInfo);
throw e;
}
finally {
long time4 = System.currentTimeMillis();
session.depart();
long time5 = System.currentTimeMillis();
log.info("Execution time profile createFolder: [i12=%1$d] [i23=%2$d] [i34=%3$d] [i45=%4$d]",
time2-time1, time3-time2, time4-time3, time5-time4);
}
}
//
//
//==========================================================================
@Autowired
private CreateAbsoluteFolderOperation createAbsoluteFolder;
@Override
public TFolder createAbsoluteFolder(String sessionId, String path) throws ServiceFault {
long time1 = System.currentTimeMillis();
sessionId = nullToEmpty(sessionId).trim();
path = nullToEmpty(path).trim();
Session session = SessionMap.get(sessionId);
if(session == null) {
return null;
}
Session.setThreadSession(session);
long time2 = System.currentTimeMillis();
session.enroll();
long time3 = System.currentTimeMillis();
try {
session.incStatistics("createAbsoluteFolder-Total");
TFolder ret = createAbsoluteFolder.apply(path);
session.incStatistics("createAbsoluteFolder-Success");
return ret;
}
catch(Throwable t) {
session.incStatistics("createAbsoluteFolder-Failure");
ServiceFault e;
if(t instanceof ServiceFault) {
e = (ServiceFault) t;
}
else {
e = ServiceFault.runtimeException()
.setActor("createAbsoluteFolder")
.setCause(t)
.create();
}
TFault faultInfo = e.getFaultInfo();
if(faultInfo != null) {
log.error(faultInfo);
}
log.error(e, "createAbsoluteFolder\n\tsessionId: %s\n\tpath: %s", sessionId, path);
session.setLastFault(faultInfo);
throw e;
}
finally {
long time4 = System.currentTimeMillis();
session.depart();
long time5 = System.currentTimeMillis();
log.info("Execution time profile createAbsoluteFolder: [i12=%1$d] [i23=%2$d] [i34=%3$d] [i45=%4$d]",
time2-time1, time3-time2, time4-time3, time5-time4);
}
}
//
//
//==========================================================================
@Autowired
private RenameFolderOperation renameFolder;
@Override
public TFolder renameFolder(String sessionId, String folderId, String newName) throws ServiceFault {
long time1 = System.currentTimeMillis();
sessionId = nullToEmpty(sessionId).trim();
folderId = nullToEmpty(folderId).trim();
newName = nullToEmpty(newName).trim();
Session session = SessionMap.get(sessionId);
if(session == null) {
return null;
}
Session.setThreadSession(session);
long time2 = System.currentTimeMillis();
session.enroll();
long time3 = System.currentTimeMillis();
try {
session.incStatistics("renameFolder-Total");
TFolder ret = renameFolder.apply(folderId, newName);
session.incStatistics("renameFolder-Success");
return ret;
}
catch(Throwable t) {
session.incStatistics("renameFolder-Failure");
ServiceFault e;
if(t instanceof ServiceFault) {
e = (ServiceFault) t;
}
else {
e = ServiceFault.runtimeException()
.setActor("renameFolder")
.setCause(t)
.create();
}
TFault faultInfo = e.getFaultInfo();
if(faultInfo != null) {
log.error(faultInfo);
}
log.error(e, "renameFolder\n\tsessionId: %s\n\tfolderId: %s\n\tnewName: %s", sessionId, folderId, newName);
session.setLastFault(faultInfo);
throw e;
}
finally {
long time4 = System.currentTimeMillis();
session.depart();
long time5 = System.currentTimeMillis();
log.info("Execution time profile renameFolder: [i12=%1$d] [i23=%2$d] [i34=%3$d] [i45=%4$d]",
time2-time1, time3-time2, time4-time3, time5-time4);
}
}
//
//
//==========================================================================
@Autowired
private MoveFolderOperation moveFolder;
@Override
public TFolder moveFolder(String sessionId, String newParentFolderId, String folderId) throws ServiceFault {
long time1 = System.currentTimeMillis();
sessionId = nullToEmpty(sessionId).trim();
newParentFolderId = nullToEmpty(newParentFolderId).trim();
folderId = nullToEmpty(folderId).trim();
Session session = SessionMap.get(sessionId);
if(session == null) {
return null;
}
Session.setThreadSession(session);
long time2 = System.currentTimeMillis();
session.enroll();
long time3 = System.currentTimeMillis();
try {
session.incStatistics("moveFolder-Total");
TFolder ret = moveFolder.apply(newParentFolderId, folderId);
session.incStatistics("moveFolder-Success");
return ret;
}
catch(Throwable t) {
session.incStatistics("moveFolder-Failure");
ServiceFault e;
if(t instanceof ServiceFault) {
e = (ServiceFault) t;
}
else {
e = ServiceFault.runtimeException()
.setActor("moveFolder")
.setCause(t)
.create();
}
TFault faultInfo = e.getFaultInfo();
if(faultInfo != null) {
log.error(faultInfo);
}
log.error(e, "moveFolder\n\tsessionId: %s\n\tfolderId: %s\n\tnewParentFolderId: %s", sessionId, folderId, newParentFolderId);
session.setLastFault(faultInfo);
throw e;
}
finally {
long time4 = System.currentTimeMillis();
session.depart();
long time5 = System.currentTimeMillis();
log.info("Execution time profile moveFolder: [i12=%1$d] [i23=%2$d] [i34=%3$d] [i45=%4$d]",
time2-time1, time3-time2, time4-time3, time5-time4);
}
}
//
//
//==========================================================================
@Autowired
private DeleteFolderOperation deleteFolder;
@Override
public Integer deleteFolder(String sessionId, String folderId, boolean recursive) throws ServiceFault {
long time1 = System.currentTimeMillis();
sessionId = nullToEmpty(sessionId).trim();
folderId = nullToEmpty(folderId).trim();
Session session = SessionMap.get(sessionId);
if(session == null) {
return null;
}
Session.setThreadSession(session);
long time2 = System.currentTimeMillis();
session.enroll();
long time3 = System.currentTimeMillis();
try {
session.incStatistics("deleteFolder-Total");
Integer ret = deleteFolder.apply(folderId, recursive);
session.incStatistics("deleteFolder-Success");
return ret;
}
catch(Throwable t) {
session.incStatistics("deleteFolder-Failure");
ServiceFault e;
if(t instanceof ServiceFault) {
e = (ServiceFault) t;
}
else {
e = ServiceFault.runtimeException()
.setActor("deleteFolder")
.setCause(t)
.create();
}
TFault faultInfo = e.getFaultInfo();
if(faultInfo != null) {
log.error(faultInfo);
}
log.error(e, "deleteFolder\n\tsessionId: %s\n\tfolderId: %s\n\trecursive: %b", sessionId, folderId, recursive);
session.setLastFault(faultInfo);
throw e;
}
finally {
long time4 = System.currentTimeMillis();
session.depart();
long time5 = System.currentTimeMillis();
log.info("Execution time profile deleteFolder: [i12=%1$d] [i23=%2$d] [i34=%3$d] [i45=%4$d]",
time2-time1, time3-time2, time4-time3, time5-time4);
}
}
//
//
//==========================================================================
@Autowired
private ArchiveOperation archive;
@Override
public TMessage archive(String sessionId, String folderId, String message) throws ServiceFault {
long time1 = System.currentTimeMillis();
sessionId = nullToEmpty(sessionId).trim();
folderId = nullToEmpty(folderId).trim();
message = nullToEmpty(message);
Session session = SessionMap.get(sessionId);
if(session == null) {
return null;
}
Session.setThreadSession(session);
long time2 = System.currentTimeMillis();
session.enroll();
long time3 = System.currentTimeMillis();
try {
session.incStatistics("archive-Total");
TMessage ret = archive.apply(folderId, message);
session.incStatistics("archive-Success");
return ret;
}
catch(Throwable t) {
session.incStatistics("archive-Failure");
ServiceFault e;
if(t instanceof ServiceFault) {
e = (ServiceFault) t;
}
else {
e = ServiceFault.runtimeException()
.setActor("archive")
.setCause(t)
.create();
}
TFault faultInfo = e.getFaultInfo();
if(faultInfo != null) {
log.error(faultInfo);
}
log.error(e, "archive\n\tsessionId: %s\n\tfolderId: %s\n\tmessage:\n%s", sessionId, folderId, message);
session.setLastFault(faultInfo);
throw e;
}
finally {
long time4 = System.currentTimeMillis();
session.depart();
long time5 = System.currentTimeMillis();
log.info("Execution time profile archive: [i12=%1$d] [i23=%2$d] [i34=%3$d] [i45=%4$d]",
time2-time1, time3-time2, time4-time3, time5-time4);
}
}
//
//
//==========================================================================
@Autowired
private GetFolderInfoOperation getFolderInfo;
@Override
public TFolder getFolderInfo(String sessionId, String folderId) throws ServiceFault {
long time1 = System.currentTimeMillis();
sessionId = nullToEmpty(sessionId).trim();
folderId = nullToEmpty(folderId).trim();
Session session = SessionMap.get(sessionId);
if(session == null) {
return null;
}
Session.setThreadSession(session);
long time2 = System.currentTimeMillis();
session.enroll();
long time3 = System.currentTimeMillis();
try {
session.incStatistics("getFolderInfo-Total");
TFolder ret = getFolderInfo.apply(folderId);
session.incStatistics("getFolderInfo-Success");
return ret;
}
catch(Throwable t) {
session.incStatistics("getFolderInfo-Failure");
ServiceFault e;
if(t instanceof ServiceFault) {
e = (ServiceFault) t;
}
else {
e = ServiceFault.runtimeException()
.setActor("getFolderInfo")
.setCause(t)
.create();
}
TFault faultInfo = e.getFaultInfo();
if(faultInfo != null) {
log.error(faultInfo);
}
log.error(e, "getFolderInfo\n\tsessionId: %s\n\tfolderId: %s", sessionId, folderId);
session.setLastFault(faultInfo);
throw e;
}
finally {
long time4 = System.currentTimeMillis();
session.depart();
long time5 = System.currentTimeMillis();
log.info("Execution time profile getFolderInfo: [i12=%1$d] [i23=%2$d] [i34=%3$d] [i45=%4$d]",
time2-time1, time3-time2, time4-time3, time5-time4);
}
}
//
//
//==========================================================================
@Autowired
private GetMessageInfoOperation getMessageInfo;
@Override
public TMessage getMessageInfo(String sessionId, String messageId) throws ServiceFault {
long time1 = System.currentTimeMillis();
sessionId = nullToEmpty(sessionId).trim();
messageId = nullToEmpty(messageId).trim();
Session session = SessionMap.get(sessionId);
if(session == null) {
return null;
}
Session.setThreadSession(session);
long time2 = System.currentTimeMillis();
session.enroll();
long time3 = System.currentTimeMillis();
try {
session.incStatistics("getMessageInfo-Total");
TMessage ret = getMessageInfo.apply(messageId);
session.incStatistics("getMessageInfo-Success");
return ret;
}
catch(Throwable t) {
session.incStatistics("getMessageInfo-Failure");
ServiceFault e;
if(t instanceof ServiceFault) {
e = (ServiceFault) t;
}
else {
e = ServiceFault.runtimeException()
.setActor("getMessageInfo")
.setCause(t)
.create();
}
TFault faultInfo = e.getFaultInfo();
if(faultInfo != null) {
log.error(faultInfo);
}
log.error(e, "getMessageInfo\n\tsessionId: %s\n\tmessageId: %s", sessionId, messageId);
session.setLastFault(faultInfo);
throw e;
}
finally {
long time4 = System.currentTimeMillis();
session.depart();
long time5 = System.currentTimeMillis();
log.info("Execution time profile getMessageInfo: [i12=%1$d] [i23=%2$d] [i34=%3$d] [i45=%4$d]",
time2-time1, time3-time2, time4-time3, time5-time4);
}
}
//
//
//==========================================================================
@Autowired
private GetStateOperation getState;
@Override
public String getState() throws ServiceFault {
return getState.apply();
}
//
}