Author: kmorin Date: 2014-10-28 18:17:15 +0100 (Tue, 28 Oct 2014) New Revision: 683 Url: http://forge.codelutin.com/projects/faxtomail/repository/revisions/683 Log: fix import archives Added: trunk/faxtomail-ui-web/src/main/java/com/franciaflex/faxtomail/web/action/SearchAction.java trunk/faxtomail-ui-web/src/main/webapp/WEB-INF/content/admin/import-archive-wait.jsp trunk/faxtomail-ui-web/src/main/webapp/WEB-INF/content/search-input.jsp Removed: trunk/faxtomail-ui-web/src/main/java/com/franciaflex/faxtomail/web/action/ArchiveSearchAction.java trunk/faxtomail-ui-web/src/main/webapp/WEB-INF/content/archive-search-input.jsp Modified: trunk/faxtomail-service/src/main/java/com/franciaflex/faxtomail/services/service/EmailServiceImpl.java trunk/faxtomail-ui-swing/src/license/THIRD-PARTY.properties trunk/faxtomail-ui-web/src/main/java/com/franciaflex/faxtomail/web/FaxToMailInterceptor.java trunk/faxtomail-ui-web/src/main/java/com/franciaflex/faxtomail/web/action/admin/ImportArchiveAction.java trunk/faxtomail-ui-web/src/main/java/com/franciaflex/faxtomail/web/action/admin/LdapAction.java trunk/faxtomail-ui-web/src/main/webapp/WEB-INF/content/admin/import-archive-input.jsp trunk/faxtomail-ui-web/src/main/webapp/WEB-INF/content/demand-detail.jsp trunk/faxtomail-ui-web/src/main/webapp/WEB-INF/decorators/layout.jsp Modified: trunk/faxtomail-service/src/main/java/com/franciaflex/faxtomail/services/service/EmailServiceImpl.java =================================================================== --- trunk/faxtomail-service/src/main/java/com/franciaflex/faxtomail/services/service/EmailServiceImpl.java 2014-10-20 09:43:51 UTC (rev 682) +++ trunk/faxtomail-service/src/main/java/com/franciaflex/faxtomail/services/service/EmailServiceImpl.java 2014-10-28 17:17:15 UTC (rev 683) @@ -1685,6 +1685,8 @@ } finally { IOUtils.closeQuietly(importer); IOUtils.closeQuietly(inputStream); + transaction.rollback(); + statelessSession.close(); } if (!notImportedBeans.isEmpty()) { Modified: trunk/faxtomail-ui-swing/src/license/THIRD-PARTY.properties =================================================================== --- trunk/faxtomail-ui-swing/src/license/THIRD-PARTY.properties 2014-10-20 09:43:51 UTC (rev 682) +++ trunk/faxtomail-ui-swing/src/license/THIRD-PARTY.properties 2014-10-28 17:17:15 UTC (rev 683) @@ -1,24 +1,3 @@ -### -# #%L -# FaxToMail :: UI -# %% -# Copyright (C) 2014 Mac-Groupe, Code Lutin -# %% -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU 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 General Public License for more details. -# -# You should have received a copy of the GNU General Public -# License along with this program. If not, see -# <http://www.gnu.org/licenses/gpl-3.0.html>. -# #L% -### # Generated by org.codehaus.mojo.license.AddThirdPartyMojo #------------------------------------------------------------------------------- # Already used licenses in project : @@ -61,7 +40,7 @@ # Please fill the missing licenses for dependencies : # # -#Wed Oct 01 15:25:35 CEST 2014 +#Wed Oct 15 19:01:07 CEST 2014 commons-primitives--commons-primitives--1.0=The Apache Software License, Version 2.0 dom4j--dom4j--1.6.1=BSD License javax.media.jai--com.springsource.javax.media.jai.codec--1.1.3=Apache License Modified: trunk/faxtomail-ui-web/src/main/java/com/franciaflex/faxtomail/web/FaxToMailInterceptor.java =================================================================== --- trunk/faxtomail-ui-web/src/main/java/com/franciaflex/faxtomail/web/FaxToMailInterceptor.java 2014-10-20 09:43:51 UTC (rev 682) +++ trunk/faxtomail-ui-web/src/main/java/com/franciaflex/faxtomail/web/FaxToMailInterceptor.java 2014-10-28 17:17:15 UTC (rev 683) @@ -80,6 +80,7 @@ if (CollectionUtils.isNotEmpty(faxToMailSession.getMessages())) { for (String message : faxToMailSession.getMessages()) { + log.info(message); faxToMailAction.addActionMessage(message); } faxToMailSession.getMessages().clear(); @@ -113,6 +114,7 @@ } else if (FaxToMailConfiguration.class.isAssignableFrom(propertyType)) { toInject = getFaxToMailApplicationContext(invocation).getApplicationConfig(); + } else if (FaxToMailApplicationContext.class.isAssignableFrom(propertyType)) { toInject = getFaxToMailApplicationContext(invocation); } @@ -126,6 +128,7 @@ } return invocation.invoke(); + } finally { if (serviceContext != null) { serviceContext.getPersistenceContext().close(); Deleted: trunk/faxtomail-ui-web/src/main/java/com/franciaflex/faxtomail/web/action/ArchiveSearchAction.java =================================================================== --- trunk/faxtomail-ui-web/src/main/java/com/franciaflex/faxtomail/web/action/ArchiveSearchAction.java 2014-10-20 09:43:51 UTC (rev 682) +++ trunk/faxtomail-ui-web/src/main/java/com/franciaflex/faxtomail/web/action/ArchiveSearchAction.java 2014-10-28 17:17:15 UTC (rev 683) @@ -1,374 +0,0 @@ -package com.franciaflex.faxtomail.web.action; - -import com.franciaflex.faxtomail.persistence.entities.Attachment; -import com.franciaflex.faxtomail.persistence.entities.Client; -import com.franciaflex.faxtomail.persistence.entities.Email; -import com.franciaflex.faxtomail.persistence.entities.EmailGroup; -import com.franciaflex.faxtomail.persistence.entities.FaxToMailUser; -import com.franciaflex.faxtomail.persistence.entities.HasLabel; -import com.franciaflex.faxtomail.persistence.entities.MailField; -import com.franciaflex.faxtomail.persistence.entities.RangeRow; -import com.franciaflex.faxtomail.persistence.entities.Reply; -import com.franciaflex.faxtomail.services.DecoratorService; -import com.franciaflex.faxtomail.services.service.ConfigurationService; -import com.franciaflex.faxtomail.services.service.EmailService; -import com.franciaflex.faxtomail.web.FaxToMailActionSupport; -import com.google.common.base.Function; -import com.google.common.collect.Collections2; -import com.google.common.collect.Lists; -import org.apache.commons.collections4.CollectionUtils; -import org.apache.commons.lang3.StringUtils; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.apache.struts2.convention.annotation.Action; -import org.apache.struts2.convention.annotation.InterceptorRef; -import org.apache.struts2.convention.annotation.InterceptorRefs; -import org.apache.struts2.convention.annotation.Result; -import org.nuiton.decorator.Decorator; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.List; -import java.util.Map; -import java.util.Set; - -import static org.nuiton.i18n.I18n.t; - -/** - * @author Kevin Morin (Code Lutin) - * @since 1.1 - */ - -@InterceptorRefs({ - @InterceptorRef("faxToMailInterceptor"), - @InterceptorRef("paramsPrepareParamsStack") -}) -public class ArchiveSearchAction extends FaxToMailActionSupport { - - private static final Log log = LogFactory.getLog(ArchiveSearchAction.class); - - protected EmailService emailService; - protected ConfigurationService configurationService; - protected DecoratorService decoratorService; - - protected String commandQuotationNb; - protected String company; - protected List<Email> results; - protected String singleResultId; - protected Map<MailField, String> tableMailFields; - - public void setEmailService(EmailService emailService) { - this.emailService = emailService; - } - - public void setConfigurationService(ConfigurationService configurationService) { - this.configurationService = configurationService; - } - - public void setDecoratorService(DecoratorService decoratorService) { - this.decoratorService = decoratorService; - } - - @Override - @Action("archive-search-input") - public String input() throws Exception { - return INPUT; - } - - @Override - @Action(value = "archive-search", - results = { - @Result(name="detail", - type="redirectAction", - params = {"actionName", "demand-detail", "id", "%{singleResultId}"}) - }) - public String execute() throws Exception { - String result = INPUT; - if (commandQuotationNb != null && company != null) { - results = new ArrayList<>(emailService.searchArchives(commandQuotationNb, company)); - if (results.size() == 1) { - singleResultId = results.get(0).getTopiaId(); - result = "detail"; - - } else { - List<MailField> mailFields = configurationService.getSearchDisplayColumns(); - if (CollectionUtils.isEmpty(mailFields)) { - mailFields = Lists.newArrayList(MailField.getTableFields()); - } - tableMailFields = getEnumAsMap(mailFields.toArray(new MailField[mailFields.size()])); - } - } - return result; - } - - public String getCommandQuotationNb() { - return commandQuotationNb; - } - - public void setCommandQuotationNb(String commandQuotationNb) { - this.commandQuotationNb = commandQuotationNb; - } - - public String getCompany() { - return company; - } - - public void setCompany(String company) { - this.company = company; - } - - public List<Email> getResults() { - return results; - } - - public void setResults(List<Email> results) { - this.results = results; - } - - public String getSingleResultId() { - return singleResultId; - } - - public Map<MailField, String> getTableMailFields() { - return tableMailFields; - } - - public String getAttr(MailField field, Email email) { - Object attrValue = null; - switch (field) { - case PRIORITY: - attrValue = email.getPriority(); - break; - case DEMAND_TYPE: - attrValue = email.getDemandType(); - break; - case OBJECT: - attrValue = email.getObject(); - break; - case CLIENT_CODE: - Client client = email.getClient(); - attrValue = client == null ? null : client.getCode(); - break; - case CLIENT_BRAND: - client = email.getClient(); - attrValue = client == null ? null : client.getBrand(); - break; - case SENDER: - attrValue = email.getSender(); - break; - case PROJECT_REFERENCE: - attrValue = email.getProjectReference(); - break; - case COMPANY_REFERENCE: - attrValue = email.getCompanyReference(); - break; - case REFERENCE: - attrValue = email.getReference(); - break; - case RECEPTION_DATE: - attrValue = email.getReceptionDate(); - break; - case RECIPIENT: - attrValue = email.getRecipient(); - break; - case DEMAND_STATUS: - attrValue = email.getDemandStatus(); - break; - case WAITING_STATE: - attrValue = email.getWaitingState(); - break; - case PF_NB: - int intAttrValue = 0; - for (RangeRow rr : email.getRangeRow()) { - Integer productQuantity = rr.getProductQuantity(); - if (productQuantity != null) { - intAttrValue += productQuantity; - } - } - attrValue = intAttrValue; - break; - case SAV_NB: - intAttrValue = 0; - for (RangeRow rr : email.getRangeRow()) { - Integer savQuantity = rr.getSavQuantity(); - if (savQuantity != null) { - intAttrValue += savQuantity; - } - } - attrValue = intAttrValue; - break; - case QUOTATION_NB: - intAttrValue = 0; - for (RangeRow rr : email.getRangeRow()) { - Integer quotationQuantity = rr.getQuotationQuantity(); - if (quotationQuantity != null) { - intAttrValue += quotationQuantity; - } - } - attrValue = intAttrValue; - break; - case TAKEN_BY: - attrValue = email.getTakenBy(); - break; - case COMMENT: - attrValue = email.getComment(); - break; - case EDI_RETURN: - attrValue = email.getEdiError(); - break; - case LAST_ATTACHMENT_OPENING_IN_THIS_FOLDER_USER: - attrValue = email.getLastAttachmentOpener(); - break; - case REPLIES: - attrValue = "<span class='fa fa-envelope-o'></span> " + email.sizeReplies(); - break; - case ATTACHMENT: - attrValue = "<span class='fa fa-paperclip'></span> " + email.sizeAttachment(); - break; - case GROUP: - EmailGroup emailGroup = email.getEmailGroup(); - attrValue = "<span class='fa fa-link'></span> " + (emailGroup == null ? 1 : emailGroup.sizeEmail()); - break; - } - - String result; - if (attrValue == null || StringUtils.isBlank(attrValue.toString())) { - result = " "; - - } else { - Decorator decorator = decoratorService.getDecorator(attrValue); - if (decorator != null) { - result = decorator.toString(attrValue); - } else { - result = attrValue.toString(); - } - } - return result; - } - - public String getTooltip(MailField field, Email email) { - String tooltipText = null; - switch (field) { - case PF_NB: - List<String> ranges = new ArrayList<String>(); - Collection<RangeRow> rangeRows = email.getRangeRow(); - if (rangeRows != null) { - for (RangeRow rangeRow : rangeRows) { - Integer qty = rangeRow.getProductQuantity(); - if (qty != null && qty > 0) { - ranges.add(rangeRow.getRange().getLabel() + " : " + qty); - } - } - } - - if (!ranges.isEmpty()) { - tooltipText = StringUtils.join(ranges, "\n"); - } - break; - - case SAV_NB: - ranges = new ArrayList<String>(); - rangeRows = email.getRangeRow(); - if (rangeRows != null) { - for (RangeRow rangeRow : rangeRows) { - Integer qty = rangeRow.getSavQuantity(); - if (qty != null && qty > 0) { - ranges.add(rangeRow.getRange().getLabel() + " : " + qty); - } - } - } - - if (!ranges.isEmpty()) { - tooltipText = StringUtils.join(ranges, "\n"); - } - break; - - case QUOTATION_NB: - ranges = new ArrayList<String>(); - rangeRows = email.getRangeRow(); - if (rangeRows != null) { - for (RangeRow rangeRow : rangeRows) { - Integer qty = rangeRow.getQuotationQuantity(); - if (qty != null && qty > 0) { - ranges.add(rangeRow.getRange().getLabel() + " : " + qty); - } - } - } - - if (!ranges.isEmpty()) { - tooltipText = StringUtils.join(ranges, "\n"); - } - break; - - case REPLIES: - List<Reply> replies = email.getReplies(); - if (CollectionUtils.isNotEmpty(replies)) { - final Decorator<Reply> decorator = decoratorService.getDecoratorByType(Reply.class); - - List<String> replyNames = Lists.transform(replies, new Function<Reply, String>() { - @Override - public String apply(Reply attachment) { - return decorator.toString(attachment); - } - }); - tooltipText = StringUtils.join(replyNames, "\n"); - } - break; - - case ATTACHMENT: - List<Attachment> attachments = email.getAttachment(); - if (CollectionUtils.isNotEmpty(attachments)) { - final Decorator<Attachment> decorator = decoratorService.getDecoratorByType(Attachment.class); - - List<String> attachmentNames = Lists.transform(attachments, new Function<Attachment, String>() { - @Override - public String apply(Attachment attachment) { - String name = decorator.toString(attachment); - if (attachment.getEditedFileName() != null) { - name += " (+ édité)"; - } - return name; - } - }); - tooltipText = StringUtils.join(attachmentNames, "\n"); - } - break; - - case GROUP: - - EmailGroup emailGroup = email.getEmailGroup(); - Collection<Email> emails = new ArrayList<>(); - if (emailGroup != null) { - Collection<Email> groupEmails = emailGroup.getEmail(); - if (CollectionUtils.isNotEmpty(groupEmails)) { - emails.addAll(groupEmails); - } - } - if (emails.isEmpty()) { - emails.add(email); - } - Collection<String> emailTitles = Collections2.transform(emails, new Function<Email, String>() { - @Override - public String apply(Email email) { - String result = email.getObject(); - String ref = email.getReference(); - if (!ref.isEmpty()) { - result = ref + " - " + result; - } - return result; - } - }); - tooltipText = StringUtils.join(emailTitles, "\n"); - break; - - default: - tooltipText = getAttr(field, email); - } - - if (tooltipText == null) { - tooltipText = " "; - } - - return tooltipText; - } -} Copied: trunk/faxtomail-ui-web/src/main/java/com/franciaflex/faxtomail/web/action/SearchAction.java (from rev 682, trunk/faxtomail-ui-web/src/main/java/com/franciaflex/faxtomail/web/action/ArchiveSearchAction.java) =================================================================== --- trunk/faxtomail-ui-web/src/main/java/com/franciaflex/faxtomail/web/action/SearchAction.java (rev 0) +++ trunk/faxtomail-ui-web/src/main/java/com/franciaflex/faxtomail/web/action/SearchAction.java 2014-10-28 17:17:15 UTC (rev 683) @@ -0,0 +1,369 @@ +package com.franciaflex.faxtomail.web.action; + +import com.franciaflex.faxtomail.persistence.entities.Attachment; +import com.franciaflex.faxtomail.persistence.entities.Client; +import com.franciaflex.faxtomail.persistence.entities.Email; +import com.franciaflex.faxtomail.persistence.entities.EmailGroup; +import com.franciaflex.faxtomail.persistence.entities.MailField; +import com.franciaflex.faxtomail.persistence.entities.RangeRow; +import com.franciaflex.faxtomail.persistence.entities.Reply; +import com.franciaflex.faxtomail.services.DecoratorService; +import com.franciaflex.faxtomail.services.service.ConfigurationService; +import com.franciaflex.faxtomail.services.service.EmailService; +import com.franciaflex.faxtomail.web.FaxToMailActionSupport; +import com.google.common.base.Function; +import com.google.common.collect.Collections2; +import com.google.common.collect.Lists; +import org.apache.commons.collections4.CollectionUtils; +import org.apache.commons.lang3.StringUtils; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.apache.struts2.convention.annotation.Action; +import org.apache.struts2.convention.annotation.InterceptorRef; +import org.apache.struts2.convention.annotation.InterceptorRefs; +import org.apache.struts2.convention.annotation.Result; +import org.nuiton.decorator.Decorator; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; +import java.util.Map; + +/** + * @author Kevin Morin (Code Lutin) + * @since 1.1 + */ + +@InterceptorRefs({ + @InterceptorRef("faxToMailInterceptor"), + @InterceptorRef("paramsPrepareParamsStack") +}) +public class SearchAction extends FaxToMailActionSupport { + + private static final Log log = LogFactory.getLog(SearchAction.class); + + protected EmailService emailService; + protected ConfigurationService configurationService; + protected DecoratorService decoratorService; + + protected String element; + protected String company; + protected List<Email> results; + protected String singleResultId; + protected Map<MailField, String> tableMailFields; + + public void setEmailService(EmailService emailService) { + this.emailService = emailService; + } + + public void setConfigurationService(ConfigurationService configurationService) { + this.configurationService = configurationService; + } + + public void setDecoratorService(DecoratorService decoratorService) { + this.decoratorService = decoratorService; + } + + @Override + @Action("search-input") + public String input() throws Exception { + return INPUT; + } + + @Override + @Action(value = "search", + results = { + @Result(name="detail", + type="redirectAction", + params = {"actionName", "demand-detail", "id", "%{singleResultId}"}) + }) + public String execute() throws Exception { + String result = INPUT; + if (element != null && company != null) { + results = new ArrayList<>(emailService.searchArchives(element, company)); + if (results.size() == 1) { + singleResultId = results.get(0).getTopiaId(); + result = "detail"; + + } else { + List<MailField> mailFields = configurationService.getSearchDisplayColumns(); + if (CollectionUtils.isEmpty(mailFields)) { + mailFields = Lists.newArrayList(MailField.getTableFields()); + } + tableMailFields = getEnumAsMap(mailFields.toArray(new MailField[mailFields.size()])); + } + } + return result; + } + + public String getElement() { + return element; + } + + public void setElement(String element) { + this.element = element; + } + + public String getCompany() { + return company; + } + + public void setCompany(String company) { + this.company = company; + } + + public List<Email> getResults() { + return results; + } + + public void setResults(List<Email> results) { + this.results = results; + } + + public String getSingleResultId() { + return singleResultId; + } + + public Map<MailField, String> getTableMailFields() { + return tableMailFields; + } + + public String getAttr(MailField field, Email email) { + Object attrValue = null; + switch (field) { + case PRIORITY: + attrValue = email.getPriority(); + break; + case DEMAND_TYPE: + attrValue = email.getDemandType(); + break; + case OBJECT: + attrValue = email.getObject(); + break; + case CLIENT_CODE: + Client client = email.getClient(); + attrValue = client == null ? null : client.getCode(); + break; + case CLIENT_BRAND: + client = email.getClient(); + attrValue = client == null ? null : client.getBrand(); + break; + case SENDER: + attrValue = email.getSender(); + break; + case PROJECT_REFERENCE: + attrValue = email.getProjectReference(); + break; + case COMPANY_REFERENCE: + attrValue = email.getCompanyReference(); + break; + case REFERENCE: + attrValue = email.getReference(); + break; + case RECEPTION_DATE: + attrValue = email.getReceptionDate(); + break; + case RECIPIENT: + attrValue = email.getRecipient(); + break; + case DEMAND_STATUS: + attrValue = email.getDemandStatus(); + break; + case WAITING_STATE: + attrValue = email.getWaitingState(); + break; + case PF_NB: + int intAttrValue = 0; + for (RangeRow rr : email.getRangeRow()) { + Integer productQuantity = rr.getProductQuantity(); + if (productQuantity != null) { + intAttrValue += productQuantity; + } + } + attrValue = intAttrValue; + break; + case SAV_NB: + intAttrValue = 0; + for (RangeRow rr : email.getRangeRow()) { + Integer savQuantity = rr.getSavQuantity(); + if (savQuantity != null) { + intAttrValue += savQuantity; + } + } + attrValue = intAttrValue; + break; + case QUOTATION_NB: + intAttrValue = 0; + for (RangeRow rr : email.getRangeRow()) { + Integer quotationQuantity = rr.getQuotationQuantity(); + if (quotationQuantity != null) { + intAttrValue += quotationQuantity; + } + } + attrValue = intAttrValue; + break; + case TAKEN_BY: + attrValue = email.getTakenBy(); + break; + case COMMENT: + attrValue = email.getComment(); + break; + case EDI_RETURN: + attrValue = email.getEdiError(); + break; + case LAST_ATTACHMENT_OPENING_IN_THIS_FOLDER_USER: + attrValue = email.getLastAttachmentOpener(); + break; + case REPLIES: + attrValue = "<span class='fa fa-envelope-o'></span> " + email.sizeReplies(); + break; + case ATTACHMENT: + attrValue = "<span class='fa fa-paperclip'></span> " + email.sizeAttachment(); + break; + case GROUP: + EmailGroup emailGroup = email.getEmailGroup(); + attrValue = "<span class='fa fa-link'></span> " + (emailGroup == null ? 1 : emailGroup.sizeEmail()); + break; + } + + String result; + if (attrValue == null || StringUtils.isBlank(attrValue.toString())) { + result = " "; + + } else { + Decorator decorator = decoratorService.getDecorator(attrValue); + if (decorator != null) { + result = decorator.toString(attrValue); + } else { + result = attrValue.toString(); + } + } + return result; + } + + public String getTooltip(MailField field, Email email) { + String tooltipText = null; + switch (field) { + case PF_NB: + List<String> ranges = new ArrayList<String>(); + Collection<RangeRow> rangeRows = email.getRangeRow(); + if (rangeRows != null) { + for (RangeRow rangeRow : rangeRows) { + Integer qty = rangeRow.getProductQuantity(); + if (qty != null && qty > 0) { + ranges.add(rangeRow.getRange().getLabel() + " : " + qty); + } + } + } + + if (!ranges.isEmpty()) { + tooltipText = StringUtils.join(ranges, "\n"); + } + break; + + case SAV_NB: + ranges = new ArrayList<String>(); + rangeRows = email.getRangeRow(); + if (rangeRows != null) { + for (RangeRow rangeRow : rangeRows) { + Integer qty = rangeRow.getSavQuantity(); + if (qty != null && qty > 0) { + ranges.add(rangeRow.getRange().getLabel() + " : " + qty); + } + } + } + + if (!ranges.isEmpty()) { + tooltipText = StringUtils.join(ranges, "\n"); + } + break; + + case QUOTATION_NB: + ranges = new ArrayList<String>(); + rangeRows = email.getRangeRow(); + if (rangeRows != null) { + for (RangeRow rangeRow : rangeRows) { + Integer qty = rangeRow.getQuotationQuantity(); + if (qty != null && qty > 0) { + ranges.add(rangeRow.getRange().getLabel() + " : " + qty); + } + } + } + + if (!ranges.isEmpty()) { + tooltipText = StringUtils.join(ranges, "\n"); + } + break; + + case REPLIES: + List<Reply> replies = email.getReplies(); + if (CollectionUtils.isNotEmpty(replies)) { + final Decorator<Reply> decorator = decoratorService.getDecoratorByType(Reply.class); + + List<String> replyNames = Lists.transform(replies, new Function<Reply, String>() { + @Override + public String apply(Reply attachment) { + return decorator.toString(attachment); + } + }); + tooltipText = StringUtils.join(replyNames, "\n"); + } + break; + + case ATTACHMENT: + List<Attachment> attachments = email.getAttachment(); + if (CollectionUtils.isNotEmpty(attachments)) { + final Decorator<Attachment> decorator = decoratorService.getDecoratorByType(Attachment.class); + + List<String> attachmentNames = Lists.transform(attachments, new Function<Attachment, String>() { + @Override + public String apply(Attachment attachment) { + String name = decorator.toString(attachment); + if (attachment.getEditedFileName() != null) { + name += " (+ édité)"; + } + return name; + } + }); + tooltipText = StringUtils.join(attachmentNames, "\n"); + } + break; + + case GROUP: + + EmailGroup emailGroup = email.getEmailGroup(); + Collection<Email> emails = new ArrayList<>(); + if (emailGroup != null) { + Collection<Email> groupEmails = emailGroup.getEmail(); + if (CollectionUtils.isNotEmpty(groupEmails)) { + emails.addAll(groupEmails); + } + } + if (emails.isEmpty()) { + emails.add(email); + } + Collection<String> emailTitles = Collections2.transform(emails, new Function<Email, String>() { + @Override + public String apply(Email email) { + String result = email.getObject(); + String ref = email.getReference(); + if (!ref.isEmpty()) { + result = ref + " - " + result; + } + return result; + } + }); + tooltipText = StringUtils.join(emailTitles, "\n"); + break; + + default: + tooltipText = getAttr(field, email); + } + + if (tooltipText == null) { + tooltipText = " "; + } + + return tooltipText; + } +} Modified: trunk/faxtomail-ui-web/src/main/java/com/franciaflex/faxtomail/web/action/admin/ImportArchiveAction.java =================================================================== --- trunk/faxtomail-ui-web/src/main/java/com/franciaflex/faxtomail/web/action/admin/ImportArchiveAction.java 2014-10-20 09:43:51 UTC (rev 682) +++ trunk/faxtomail-ui-web/src/main/java/com/franciaflex/faxtomail/web/action/admin/ImportArchiveAction.java 2014-10-28 17:17:15 UTC (rev 683) @@ -29,6 +29,9 @@ import java.io.InputStream; import java.nio.file.Files; +import com.franciaflex.faxtomail.FaxToMailApplicationContext; +import com.franciaflex.faxtomail.persistence.entities.FaxToMailTopiaPersistenceContext; +import com.franciaflex.faxtomail.services.FaxToMailServiceContext; import com.franciaflex.faxtomail.services.service.imports.ArchiveImportResult; import org.apache.commons.lang3.StringUtils; import org.apache.commons.logging.Log; @@ -50,7 +53,9 @@ @InterceptorRefs({ @InterceptorRef("faxToMailInterceptor"), @InterceptorRef("loginInterceptor"), - @InterceptorRef("paramsPrepareParamsStack") + @InterceptorRef("paramsPrepareParamsStack"), + @InterceptorRef(value="execAndWait", + params={"excludeMethods", "input,downloadImportErrorFile"}) }) public class ImportArchiveAction extends FaxToMailActionSupport implements Preparable { @@ -60,7 +65,7 @@ protected File archiveFile; - protected EmailService emailService; + protected FaxToMailApplicationContext applicationContext; protected ArchiveImportResult importResult; @@ -68,10 +73,6 @@ protected String fileName; protected String contentType; - public void setEmailService(EmailService emailService) { - this.emailService = emailService; - } - public void setArchiveFile(File archiveFile) { this.archiveFile = archiveFile; } @@ -80,6 +81,10 @@ this.attachmentBase = attachmentBase; } + public void setApplicationContext(FaxToMailApplicationContext applicationContext) { + this.applicationContext = applicationContext; + } + @Override public void prepare() throws Exception { // check authorization @@ -95,30 +100,51 @@ } @Override - public void validate() { + @Action(results = { + @Result(name="wait", location="/WEB-INF/content/admin/import-archive-wait.jsp"), + @Result(name="*", type = "chain", params = {"actionName", "import-archive-input"})}) + public String execute() throws Exception { + String result = SUCCESS; + if (StringUtils.isBlank(fileName)) { if (StringUtils.isNotBlank(attachmentBase) && !new File(attachmentBase).isDirectory()) { - addActionError("Le répertoire de base des pièces jointes n'est pas un répertoire lisible !"); + getSession().addErrorMessages("Le répertoire de base des pièces jointes n'est pas un répertoire lisible !"); + return ERROR; } if (archiveFile == null) { - addActionError("Le fichier d'archive est obligatoire !"); + getSession().addErrorMessages("Le fichier d'archive est obligatoire !"); + return ERROR; } } - } - @Override - @Action("import-archive") - public String execute() throws Exception { - String result = INPUT; - try (InputStream is = new FileInputStream(archiveFile)) { - File file = StringUtils.isNotBlank(attachmentBase) ? new File(attachmentBase) : null; - importResult = emailService.importArchive(is, file); + // cette methode doit ouvrir sa propre connexion sinon l'interceptor va la fermer + // and cause du execAndWait + FaxToMailTopiaPersistenceContext persistenceContext = applicationContext.newPersistenceContext(); - } catch (Exception ex) { - if (log.isErrorEnabled()) { - log.error("Can't import archive file", ex); + try { + persistenceContext = applicationContext.newPersistenceContext(); + FaxToMailServiceContext serviceContext = applicationContext.newServiceContext(persistenceContext); + EmailService emailService = serviceContext.getEmailService(); + + try (InputStream is = new FileInputStream(archiveFile)) { + File file = StringUtils.isNotBlank(attachmentBase) ? new File(attachmentBase) : null; + + importResult = emailService.importArchive(is, file); + if (log.isInfoEnabled()) { + log.info(importResult.getNbImportedArchives()); + } + + } catch (Exception ex) { + if (log.isErrorEnabled()) { + log.error("Can't import archive file", ex); + } + getSession().addErrorMessages("Erreur lors de l'import : " + ex.getMessage()); + + result = ERROR; } - addActionError("Erreur lors de l'import : " + ex.getMessage()); + + } finally { + persistenceContext.close(); } return result; @@ -136,7 +162,9 @@ }) public String downloadImportErrorFile() throws Exception { File file = new File(getApplicationConfig().getDataDirectory(), fileName); - log.info(fileName + " exists : " + file.exists()); + if (log.isDebugEnabled()) { + log.debug(fileName + " exists : " + file.exists()); + } contentType = Files.probeContentType(file.toPath()); inputStream = new FileInputStream(file); return SUCCESS; @@ -146,6 +174,11 @@ return importResult; } + public void setImportResult(ArchiveImportResult importResult) { + this.importResult = importResult; + log.info(importResult); + } + public InputStream getInputStream() { return inputStream; } Modified: trunk/faxtomail-ui-web/src/main/java/com/franciaflex/faxtomail/web/action/admin/LdapAction.java =================================================================== --- trunk/faxtomail-ui-web/src/main/java/com/franciaflex/faxtomail/web/action/admin/LdapAction.java 2014-10-20 09:43:51 UTC (rev 682) +++ trunk/faxtomail-ui-web/src/main/java/com/franciaflex/faxtomail/web/action/admin/LdapAction.java 2014-10-28 17:17:15 UTC (rev 683) @@ -98,7 +98,7 @@ try { persistenceContext = applicationContext.newPersistenceContext(); FaxToMailServiceContext serviceContext = applicationContext.newServiceContext(persistenceContext); - LdapService ldapService2 = serviceContext.newService(LdapService.class); + LdapService ldapService2 = serviceContext.getLdapService(); ldapService2.updateLdapData(); } finally { persistenceContext.close(); Modified: trunk/faxtomail-ui-web/src/main/webapp/WEB-INF/content/admin/import-archive-input.jsp =================================================================== --- trunk/faxtomail-ui-web/src/main/webapp/WEB-INF/content/admin/import-archive-input.jsp 2014-10-20 09:43:51 UTC (rev 682) +++ trunk/faxtomail-ui-web/src/main/webapp/WEB-INF/content/admin/import-archive-input.jsp 2014-10-28 17:17:15 UTC (rev 683) @@ -63,7 +63,7 @@ <div class="form-group"> <label for="archiveFile" class="control-label">Fichier d'archive :</label> - <input type="file" id="archiveFile" name="archiveFile" class="form-control"> + <input type="file" id="archiveFile" name="archiveFile" class="form-control" required> <p class="help-block">Format du fichier csv : <code>receptionDate;projectReference;sender;fax;recipient;object;archiveDate;companyReference;originalEmail;comment;etatAttente;demandType;priority;mailFolder;client-code;client-brand;attachments</code><br /> Encodage du fichier csv : <code>${applicationConfig.importFileEncoding}</code></p> </div> Added: trunk/faxtomail-ui-web/src/main/webapp/WEB-INF/content/admin/import-archive-wait.jsp =================================================================== --- trunk/faxtomail-ui-web/src/main/webapp/WEB-INF/content/admin/import-archive-wait.jsp (rev 0) +++ trunk/faxtomail-ui-web/src/main/webapp/WEB-INF/content/admin/import-archive-wait.jsp 2014-10-28 17:17:15 UTC (rev 683) @@ -0,0 +1,21 @@ +<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%> +<!DOCTYPE html> +<%@taglib uri="/struts-tags" prefix="s" %> + +<html> + <head> + <title>Reprise des archives</title> + <meta http-equiv="refresh" content="5;url=<s:url />"/> + </head> + + <body> + + <div id="main-container" class="container"> + + <h1 class="page-header">Reprise des archives</h1> + + <em>L'import des archives est en cours, merci de patienter...</em> + + </div> + </body> +</html> Deleted: trunk/faxtomail-ui-web/src/main/webapp/WEB-INF/content/archive-search-input.jsp =================================================================== --- trunk/faxtomail-ui-web/src/main/webapp/WEB-INF/content/archive-search-input.jsp 2014-10-20 09:43:51 UTC (rev 682) +++ trunk/faxtomail-ui-web/src/main/webapp/WEB-INF/content/archive-search-input.jsp 2014-10-28 17:17:15 UTC (rev 683) @@ -1,70 +0,0 @@ -<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%> -<!DOCTYPE html> -<%@taglib uri="/struts-tags" prefix="s" %> - -<html> - <head> - <title>Recherche d'archives</title> - <link rel="stylesheet" type="text/css" href="<s:url value='/nuiton-js/faxtomail-archive-search.css' />" /> - </head> - - <body> - - <div id="main-container" class="container"> - - <h1 class="page-header">Recherche d'archives</h1> - - <s:form id="main_form" action="archive-search" method="get" theme="simple"> - <s:actionmessage/> - <s:actionerror/> - - <label for="commandQuotationNbField" class="control-label">Numéro de commande / devis :</label> - <s:textfield type="text" id="commandQuotationNbField" name="commandQuotationNb" required="true" class="form-control"/> - <label for="companyField" class="control-label">Société :</label> - <s:textfield type="text" id="companyField" name="company" required="true" class="form-control"/> - <s:submit cssClass="btn btn-primary" value="Valider"/> - - </s:form> - - <s:if test="results != null"> - - <div style="overflow-x: auto; margin-top: 20px"> - - <s:if test="results.isEmpty()"> - <em>Aucun résultat pour cette recherche.</em> - </s:if> - <s:else> - <table class="table table-bordered"> - <thead> - <tr> - <th></th> - <s:iterator value="tableMailFields"> - <th><s:property value="value"/></th> - </s:iterator> - </tr> - </thead> - <tbody> - <s:iterator value="results" var="result"> - <tr> - <td> - <s:url id="detailUrlId" value="demand-detail.action"> - <s:param name="id" value="%{topiaId}" /> - </s:url> - <s:a href="%{detailUrlId}"><span class="fa fa-eye"></span></s:a> - </td> - <s:iterator value="tableMailFields"> - <td class="cut-eol" title="<s:text name="%{getTooltip(key, #result)}"/>"><s:text name="%{getAttr(key, #result)}"/></td> - </s:iterator> - </tr> - </s:iterator> - </tbody> - </table> - </s:else> - - </div> - - </s:if> - - </div> - </body> -</html> \ No newline at end of file Modified: trunk/faxtomail-ui-web/src/main/webapp/WEB-INF/content/demand-detail.jsp =================================================================== --- trunk/faxtomail-ui-web/src/main/webapp/WEB-INF/content/demand-detail.jsp 2014-10-20 09:43:51 UTC (rev 682) +++ trunk/faxtomail-ui-web/src/main/webapp/WEB-INF/content/demand-detail.jsp 2014-10-28 17:17:15 UTC (rev 683) @@ -232,7 +232,7 @@ <dt>Contenu de l'email</dt> <dd class="well well-sm"><s:property value="emailUIModel.content" escapeHtml="false"/></dd> <dt>Message</dt> - <dd><s:text name="%{decorate(demand.comment)}" /> + <dd class="well well-sm"><s:text name="%{decorate(demand.comment)}" /> </dl> </div> </div> Copied: trunk/faxtomail-ui-web/src/main/webapp/WEB-INF/content/search-input.jsp (from rev 682, trunk/faxtomail-ui-web/src/main/webapp/WEB-INF/content/archive-search-input.jsp) =================================================================== --- trunk/faxtomail-ui-web/src/main/webapp/WEB-INF/content/search-input.jsp (rev 0) +++ trunk/faxtomail-ui-web/src/main/webapp/WEB-INF/content/search-input.jsp 2014-10-28 17:17:15 UTC (rev 683) @@ -0,0 +1,70 @@ +<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%> +<!DOCTYPE html> +<%@taglib uri="/struts-tags" prefix="s" %> + +<html> + <head> + <title>Recherche d'archives</title> + <link rel="stylesheet" type="text/css" href="<s:url value='/nuiton-js/faxtomail-archive-search.css' />" /> + </head> + + <body> + + <div id="main-container" class="container"> + + <h1 class="page-header">Recherche d'archives</h1> + + <s:form id="main_form" action="search" method="get" theme="simple"> + <s:actionmessage/> + <s:actionerror/> + + <label for="elementField" class="control-label">Numéro de commande / devis :</label> + <s:textfield type="text" id="elementField" name="element" required="true" class="form-control"/> + <label for="companyField" class="control-label">Société :</label> + <s:textfield type="text" id="companyField" name="company" required="true" class="form-control"/> + <s:submit cssClass="btn btn-primary" value="Valider"/> + + </s:form> + + <s:if test="results != null"> + + <div style="overflow-x: auto; margin-top: 20px"> + + <s:if test="results.isEmpty()"> + <em>Aucun résultat pour cette recherche.</em> + </s:if> + <s:else> + <table class="table table-bordered"> + <thead> + <tr> + <th></th> + <s:iterator value="tableMailFields"> + <th><s:property value="value"/></th> + </s:iterator> + </tr> + </thead> + <tbody> + <s:iterator value="results" var="result"> + <tr> + <td> + <s:url id="detailUrlId" value="demand-detail.action"> + <s:param name="id" value="%{topiaId}" /> + </s:url> + <s:a href="%{detailUrlId}"><span class="fa fa-eye"></span></s:a> + </td> + <s:iterator value="tableMailFields"> + <td class="cut-eol" title="<s:text name="%{getTooltip(key, #result)}"/>"><s:text name="%{getAttr(key, #result)}"/></td> + </s:iterator> + </tr> + </s:iterator> + </tbody> + </table> + </s:else> + + </div> + + </s:if> + + </div> + </body> +</html> \ No newline at end of file Modified: trunk/faxtomail-ui-web/src/main/webapp/WEB-INF/decorators/layout.jsp =================================================================== --- trunk/faxtomail-ui-web/src/main/webapp/WEB-INF/decorators/layout.jsp 2014-10-20 09:43:51 UTC (rev 682) +++ trunk/faxtomail-ui-web/src/main/webapp/WEB-INF/decorators/layout.jsp 2014-10-28 17:17:15 UTC (rev 683) @@ -78,7 +78,7 @@ </s:if> - <li><a href="<s:url action='archive-search-input' />"> + <li><a href="<s:url action='search-input' namespace="/" />"> <span class="fa fa-search"></span> Recherche archive</a></li> </ul> @@ -90,10 +90,6 @@ <li><a href="<s:url action='logout' namespace="/" />"> <span class="fa fa-power-off"></span> Déconnexion</a></li> </s:if> - <s:else> - <li><a href="<s:url action='login-input' namespace="/" />"> - <span class="fa fa-power-off"></span> Connexion</a></li> - </s:else> </ul> </nav> </div>