branch feature/java8 created (now ec1518c)
This is an automated email from the git hooks/post-receive script. New change to branch feature/java8 in repository faxtomail. See https://gitlab.nuiton.org/codelutin/faxtomail.git at ec1518c passage à java 8 : - utilisation de lambdas - remplacement de toutes les méthodes de guava possible This branch includes the following new commits: new ec1518c passage à java 8 : - utilisation de lambdas - remplacement de toutes les méthodes de guava possible The 1 revisions listed above as "new" are entirely new to this repository and will be described in separate emails. The revisions listed as "adds" were already present in the repository and have only been added to this reference. Detailed log of new commits: commit ec1518ce2da66696b546762723ff612f3c9310ef Author: Kevin Morin <morin@codelutin.com> Date: Fri Jan 6 16:01:49 2017 +0100 passage à java 8 : - utilisation de lambdas - remplacement de toutes les méthodes de guava possible -- To stop receiving notification emails like this one, please contact codelutin.com SCM administrator <admin+scm@codelutin.com>.
This is an automated email from the git hooks/post-receive script. New commit to branch feature/java8 in repository faxtomail. See https://gitlab.nuiton.org/codelutin/faxtomail.git commit ec1518ce2da66696b546762723ff612f3c9310ef Author: Kevin Morin <morin@codelutin.com> Date: Fri Jan 6 16:01:49 2017 +0100 passage à java 8 : - utilisation de lambdas - remplacement de toutes les méthodes de guava possible --- .../faxtomail/FaxToMailConfiguration.java | 32 +-- .../persistence/RessourceClassLoader.java | 28 +- .../persistence/entities/BrandsForDomainImpl.java | 4 +- .../faxtomail/persistence/entities/ClientImpl.java | 6 +- .../persistence/entities/ClientTopiaDao.java | 9 +- .../faxtomail/persistence/entities/EmailImpl.java | 30 +-- .../persistence/entities/EmailTopiaDao.java | 43 ++- .../entities/ExtensionCommandTopiaDao.java | 3 +- .../persistence/entities/HistoryImpl.java | 3 +- .../persistence/entities/MailFolderTopiaDao.java | 12 +- .../persistence/entities/SearchFilter.java | 3 +- .../persistence/hibernate/EnumListUserType.java | 2 +- .../persistence/hibernate/EnumSetUserType.java | 2 +- .../faxtomail/services/FaxToMailDecorator.java | 22 +- .../services/FaxToMailServiceContext.java | 15 +- .../FaxToMailServiceInvocationHandler.java | 3 +- .../faxtomail/services/FaxToMailServiceUtils.java | 6 +- .../services/service/ClientServiceImpl.java | 289 ++++++++++----------- .../services/service/ConfigurationService.java | 5 +- .../services/service/ConfigurationServiceImpl.java | 67 +++-- .../services/service/EmailServiceImpl.java | 277 ++++++++------------ .../services/service/InitFaxToMailServiceImpl.java | 63 +++-- .../services/service/MailFolderServiceImpl.java | 19 +- .../services/service/ReferentielServiceImpl.java | 7 +- .../services/service/UserServiceImpl.java | 16 +- .../services/service/ValidationServiceImpl.java | 3 +- .../service/imports/ClientImportModel.java | 34 +-- .../service/imports/EmailAccountImportModel.java | 23 +- .../service/imports/EmailFilterImportModel.java | 14 +- .../service/AbstractFaxToMailServiceTest.java | 57 ++-- .../services/service/ClientServiceTest.java | 65 +++-- .../services/service/EmailServiceTest.java | 9 +- .../services/service/MailFolderServiceTest.java | 10 +- .../faxtomail/services/service/MiscTest.java | 2 +- .../service/migration/FlywayMigrationTest.java | 2 +- .../faxtomail/ui/swing/FaxToMailActionFactory.java | 3 +- .../faxtomail/ui/swing/FaxToMailUIContext.java | 62 ++--- .../faxtomail/ui/swing/RunFaxToMail.java | 14 +- .../swing/actions/PrintOnDefaultPrinterAction.java | 4 +- .../ui/swing/actions/ShowDemandeAction.java | 11 +- .../faxtomail/ui/swing/content/MainUIHandler.java | 24 +- .../content/attachment/AttachmentCellEditor.java | 10 +- .../attachment/AttachmentEditorUIHandler.java | 45 ++-- .../attachment/AttachmentEditorUIModel.java | 27 +- .../attachment/actions/EditAttachmentAction.java | 15 +- .../content/demande/DemandeListTableFilter.java | 48 ++-- .../content/demande/DemandeListUIHandler.java | 208 +++++++-------- .../swing/content/demande/DemandeListUIModel.java | 2 +- .../ui/swing/content/demande/DemandeUIHandler.java | 36 +-- .../ui/swing/content/demande/DemandeUIModel.java | 117 ++++----- .../swing/content/demande/DemandesUIHandler.java | 33 ++- .../ui/swing/content/demande/DemandesUIModel.java | 4 +- .../demande/QuantitiesByRangeUIHandler.java | 11 +- .../content/demande/QuantitiesByRangeUIModel.java | 4 +- .../content/demande/actions/ArchiveAction.java | 18 +- .../demande/actions/ArchiveFromListAction.java | 17 +- .../demande/actions/LoadFolderEmailsAction.java | 24 +- .../OpenMailFolderChooserFromListAction.java | 17 +- .../demande/actions/OpenReplyFormAction.java | 17 +- .../actions/SaveAndOpenModalFrameAction.java | 13 +- .../actions/SaveAndOpenReplyFormAction.java | 2 +- .../content/demande/actions/SaveDemandeAction.java | 12 +- .../demandgroup/DemandGroupHighlightDialog.java | 6 +- .../demande/demandgroup/DemandGroupUIHandler.java | 21 +- .../demande/history/HistoryListUIHandler.java | 81 +++--- .../demande/replies/ButtonDemandReplies.java | 5 +- .../demande/replies/DemandRepliesUIHandler.java | 51 ++-- .../content/demande/replies/RepliesCellEditor.java | 10 +- .../demande/replies/actions/OpenReplyAction.java | 15 +- .../content/pdfeditor/PDFEditorUIHandler.java | 140 +++++----- .../print/AttachmentToPrintChooserUIHandler.java | 30 +-- .../print/AttachmentToPrintChooserUIModel.java | 8 +- .../ui/swing/content/reply/ReplyFormUIHandler.java | 183 ++++++------- .../ui/swing/content/reply/ReplyFormUIModel.java | 13 +- .../swing/content/reply/actions/ReplyAction.java | 12 +- .../content/reply/actions/SenderChangedAction.java | 2 +- .../content/search/SearchToGroupUIHandler.java | 73 ++---- .../ui/swing/content/search/SearchUIHandler.java | 39 +-- .../swing/content/search/actions/GroupAction.java | 3 +- .../swing/content/search/actions/SearchAction.java | 11 +- .../search/actions/SearchToGroupAction.java | 22 +- .../transmit/MailFolderChooserUIHandler.java | 29 +-- .../content/transmit/actions/TransmitAction.java | 29 +-- .../util/AbstractFaxToMailDemandListHandler.java | 35 +-- .../ui/swing/util/AbstractFaxToMailUIHandler.java | 93 ++++--- .../ui/swing/util/CheckBoxComboBoxModel.java | 13 +- .../ui/swing/util/CheckBoxListCellRenderer.java | 34 +-- .../faxtomail/ui/swing/util/DemandeTableModel.java | 109 ++++---- .../faxtomail/ui/swing/util/FaxToMailUIUtil.java | 187 ++++++------- .../faxtomail/FaxToMailApplicationContext.java | 4 +- .../faxtomail/web/FaxToMailActionSupport.java | 7 +- .../faxtomail/web/FaxToMailInterceptor.java | 9 +- .../faxtomail/web/FaxToMailJsonResultSupport.java | 2 +- .../faxtomail/web/FaxToMailSession.java | 6 +- .../faxtomail/web/action/DemandDetailAction.java | 23 +- .../faxtomail/web/action/SearchAction.java | 54 ++-- .../faxtomail/web/job/AbstractFaxToMailJob.java | 3 +- .../faxtomail/web/job/MailFilterJob.java | 23 +- .../faxtomail/web/json/TopiaEntityAdapter.java | 6 +- pom.xml | 18 +- 100 files changed, 1446 insertions(+), 1946 deletions(-) diff --git a/faxtomail-persistence/src/main/java/com/franciaflex/faxtomail/FaxToMailConfiguration.java b/faxtomail-persistence/src/main/java/com/franciaflex/faxtomail/FaxToMailConfiguration.java index 0b573e4..dbe89b1 100644 --- a/faxtomail-persistence/src/main/java/com/franciaflex/faxtomail/FaxToMailConfiguration.java +++ b/faxtomail-persistence/src/main/java/com/franciaflex/faxtomail/FaxToMailConfiguration.java @@ -24,8 +24,7 @@ package com.franciaflex.faxtomail; * #L% */ -import com.google.common.base.Charsets; -import com.google.common.collect.Maps; +import org.apache.commons.io.Charsets; import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.builder.ReflectionToStringBuilder; import org.apache.commons.logging.Log; @@ -39,11 +38,12 @@ import org.nuiton.jaxx.application.ApplicationIOUtil; import org.nuiton.jaxx.application.ApplicationTechnicalException; import org.nuiton.version.Version; -import javax.swing.*; -import java.awt.*; +import javax.swing.KeyStroke; +import java.awt.Color; import java.io.File; import java.io.IOException; import java.net.URL; +import java.util.HashMap; import java.util.List; import java.util.Locale; import java.util.Map; @@ -185,13 +185,11 @@ public class FaxToMailConfiguration extends ApplicationConfiguration { // OPTION GETTERS public boolean isDevMode() { - boolean isDevMode = applicationConfig.getOptionAsBoolean(FaxToMailConfigurationOption.DEV_MODE.getKey()); - return isDevMode; + return applicationConfig.getOptionAsBoolean(FaxToMailConfigurationOption.DEV_MODE.getKey()); } public boolean isUseFolderCache() { - boolean isUseFolderCache = applicationConfig.getOptionAsBoolean(FaxToMailConfigurationOption.USE_FOLDER_CACHE.getKey()); - return isUseFolderCache; + return applicationConfig.getOptionAsBoolean(FaxToMailConfigurationOption.USE_FOLDER_CACHE.getKey()); } /** @@ -200,7 +198,7 @@ public class FaxToMailConfiguration extends ApplicationConfiguration { * @return new sub map */ public Map<String, String> getTopiaProperties() { - Map<String, String> jpaParameters = Maps.newHashMap(); + Map<String, String> jpaParameters = new HashMap<>(); Properties hibernateProperties = applicationConfig.getOptionStartsWith("hibernate"); jpaParameters.putAll((Map) hibernateProperties); Properties topiaProperties = applicationConfig.getOptionStartsWith("topia"); @@ -289,9 +287,7 @@ public class FaxToMailConfiguration extends ApplicationConfiguration { } public boolean isLogConfigurationProvided() { - boolean logConfigurationProvided = - StringUtils.isNotBlank(applicationConfig.getOption(FaxToMailConfigurationOption.LOG_CONFIGURATION_FILE.getKey())); - return logConfigurationProvided; + return StringUtils.isNotBlank(applicationConfig.getOption(FaxToMailConfigurationOption.LOG_CONFIGURATION_FILE.getKey())); } public File getLogConfigurationFile() { @@ -326,20 +322,17 @@ public class FaxToMailConfiguration extends ApplicationConfiguration { /** @return {@link FaxToMailConfigurationOption#BASEDIR} value */ public File getBasedir() { - File result = applicationConfig.getOptionAsFile(FaxToMailConfigurationOption.BASEDIR.getKey()); - return result; + return applicationConfig.getOptionAsFile(FaxToMailConfigurationOption.BASEDIR.getKey()); } /** @return {@link FaxToMailConfigurationOption#DEMO_DIRECTORY} value */ public File getDemoDirectory() { - File result = applicationConfig.getOptionAsFile(FaxToMailConfigurationOption.DEMO_DIRECTORY.getKey()); - return result; + return applicationConfig.getOptionAsFile(FaxToMailConfigurationOption.DEMO_DIRECTORY.getKey()); } /** @return {@link FaxToMailConfigurationOption#DATA_DIRECTORY} value */ public File getDataDirectory() { - File result = applicationConfig.getOptionAsFile(FaxToMailConfigurationOption.DATA_DIRECTORY.getKey()); - return result; + return applicationConfig.getOptionAsFile(FaxToMailConfigurationOption.DATA_DIRECTORY.getKey()); } public char getCsvSeparator() { @@ -370,9 +363,8 @@ public class FaxToMailConfiguration extends ApplicationConfiguration { } public KeyStroke getShortCut(String actionName) { - KeyStroke result = applicationConfig.getOptionAsKeyStroke( + return applicationConfig.getOptionAsKeyStroke( "faxtomail.ui." + actionName); - return result; } public boolean isAutoPopupNumberEditor() { diff --git a/faxtomail-persistence/src/main/java/com/franciaflex/faxtomail/persistence/RessourceClassLoader.java b/faxtomail-persistence/src/main/java/com/franciaflex/faxtomail/persistence/RessourceClassLoader.java index e7b30f4..fdf7cf7 100644 --- a/faxtomail-persistence/src/main/java/com/franciaflex/faxtomail/persistence/RessourceClassLoader.java +++ b/faxtomail-persistence/src/main/java/com/franciaflex/faxtomail/persistence/RessourceClassLoader.java @@ -24,10 +24,6 @@ package com.franciaflex.faxtomail.persistence; * #L% */ -import com.google.common.base.Preconditions; -import com.google.common.base.Predicate; -import com.google.common.base.Predicates; -import com.google.common.collect.Lists; import org.apache.commons.io.FileUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -38,8 +34,11 @@ import java.io.File; import java.io.IOException; import java.net.URL; import java.net.URLClassLoader; +import java.util.ArrayList; import java.util.Enumeration; import java.util.List; +import java.util.Objects; +import java.util.function.Predicate; import static org.nuiton.i18n.I18n.t; @@ -68,12 +67,13 @@ public class RessourceClassLoader extends ClassLoader { // by default try in directories if there is some this.searchInDirectoriesPredicate = new Predicate<String>() { + @Override - public boolean apply(String input) { + public boolean test(String input) { return !directories.isEmpty(); } }; - directories = Lists.newArrayList(); + directories = new ArrayList<>(); loader = URLClassLoader.newInstance(EMPTY_URL_ARRAY); } @@ -101,14 +101,14 @@ public class RessourceClassLoader extends ClassLoader { } public void addSearchInDirectoriesPredicate(Predicate<String> predicate) { - Preconditions.checkNotNull(predicate, - "search predicate can not be null"); + Objects.requireNonNull(predicate, + "search predicate can not be null"); this.searchInDirectoriesPredicate = - Predicates.and(searchInDirectoriesPredicate, predicate); + searchInDirectoriesPredicate.and(predicate)::test; } public void setSearchInDirectoriesPredicate(Predicate<String> searchInDirectoriesPredicate) { - Preconditions.checkNotNull(searchInDirectoriesPredicate, + Objects.requireNonNull(searchInDirectoriesPredicate, "search predicate can not be null"); this.searchInDirectoriesPredicate = searchInDirectoriesPredicate; } @@ -116,7 +116,7 @@ public class RessourceClassLoader extends ClassLoader { @Override public URL findResource(String name) { URL result = null; - if (searchInDirectoriesPredicate.apply(name)) { + if (searchInDirectoriesPredicate.test(name)) { if (log.isDebugEnabled()) { log.debug("findResource [" + name + "] in " + directories); } @@ -131,7 +131,7 @@ public class RessourceClassLoader extends ClassLoader { @Override public Enumeration<URL> findResources(String name) throws IOException { Enumeration<URL> result = null; - if (searchInDirectoriesPredicate.apply(name)) { + if (searchInDirectoriesPredicate.test(name)) { if (log.isDebugEnabled()) { log.debug("findResources [" + name + "] in " + directories); } @@ -146,7 +146,7 @@ public class RessourceClassLoader extends ClassLoader { @Override public URL getResource(String name) { URL result = null; - if (searchInDirectoriesPredicate.apply(name)) { + if (searchInDirectoriesPredicate.test(name)) { if (log.isDebugEnabled()) { log.debug("getResource [" + name + "] in " + directories); @@ -162,7 +162,7 @@ public class RessourceClassLoader extends ClassLoader { @Override public Enumeration<URL> getResources(String name) throws IOException { Enumeration<URL> result = null; - if (searchInDirectoriesPredicate.apply(name)) { + if (searchInDirectoriesPredicate.test(name)) { if (log.isDebugEnabled()) { log.debug("getResources [" + name + "] in " + directories); } diff --git a/faxtomail-persistence/src/main/java/com/franciaflex/faxtomail/persistence/entities/BrandsForDomainImpl.java b/faxtomail-persistence/src/main/java/com/franciaflex/faxtomail/persistence/entities/BrandsForDomainImpl.java index 6d8eec9..07f8156 100644 --- a/faxtomail-persistence/src/main/java/com/franciaflex/faxtomail/persistence/entities/BrandsForDomainImpl.java +++ b/faxtomail-persistence/src/main/java/com/franciaflex/faxtomail/persistence/entities/BrandsForDomainImpl.java @@ -24,10 +24,10 @@ package com.franciaflex.faxtomail.persistence.entities; * #L% */ -import com.google.common.collect.Lists; import org.apache.commons.lang3.StringUtils; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; /** @@ -49,7 +49,7 @@ public class BrandsForDomainImpl extends BrandsForDomainAbstract { if (json == null) { brands = new ArrayList<>(); } else { - brands = Lists.newArrayList(json.split(",")); + brands = Arrays.asList(json.split(",")); } return brands; } diff --git a/faxtomail-persistence/src/main/java/com/franciaflex/faxtomail/persistence/entities/ClientImpl.java b/faxtomail-persistence/src/main/java/com/franciaflex/faxtomail/persistence/entities/ClientImpl.java index a1f7865..a258465 100644 --- a/faxtomail-persistence/src/main/java/com/franciaflex/faxtomail/persistence/entities/ClientImpl.java +++ b/faxtomail-persistence/src/main/java/com/franciaflex/faxtomail/persistence/entities/ClientImpl.java @@ -45,8 +45,7 @@ public class ClientImpl extends ClientAbstract { @Override public List<String> getEmailAddresses() { String json = getEmailAddressesJson(); - List<String> emailAddress = AbstractFaxToMailTopiaDao.GSON_INSTANCE.fromJson(json, LIST_STRING_GSON_TYPE); - return emailAddress; + return AbstractFaxToMailTopiaDao.GSON_INSTANCE.fromJson(json, LIST_STRING_GSON_TYPE); } @Override @@ -58,8 +57,7 @@ public class ClientImpl extends ClientAbstract { @Override public List<String> getFaxNumbers() { String json = getFaxNumbersJson(); - List<String> faxNumbers = AbstractFaxToMailTopiaDao.GSON_INSTANCE.fromJson(json, LIST_STRING_GSON_TYPE); - return faxNumbers; + return AbstractFaxToMailTopiaDao.GSON_INSTANCE.fromJson(json, LIST_STRING_GSON_TYPE); } } diff --git a/faxtomail-persistence/src/main/java/com/franciaflex/faxtomail/persistence/entities/ClientTopiaDao.java b/faxtomail-persistence/src/main/java/com/franciaflex/faxtomail/persistence/entities/ClientTopiaDao.java index eea5560..471b177 100644 --- a/faxtomail-persistence/src/main/java/com/franciaflex/faxtomail/persistence/entities/ClientTopiaDao.java +++ b/faxtomail-persistence/src/main/java/com/franciaflex/faxtomail/persistence/entities/ClientTopiaDao.java @@ -40,18 +40,15 @@ public class ClientTopiaDao extends AbstractClientTopiaDao<Client> { Map<String, Object> args = new HashMap<>(); args.put("propValue", "%\"" + value + "\"%"); - List<Client> result = findAll(query, args); - return result; + return findAll(query, args); } public List<Client> forEmailAddressesJsonLike(String emailAddress) { - List<Client> result = forPropertyJsonLike(Client.PROPERTY_EMAIL_ADDRESSES_JSON, emailAddress); - return result; + return forPropertyJsonLike(Client.PROPERTY_EMAIL_ADDRESSES_JSON, emailAddress); } public List<Client> forFaxNumbersJsonLike(String faxNumber) { - List<Client> result = forPropertyJsonLike(Client.PROPERTY_FAX_NUMBERS_JSON, faxNumber); - return result; + return forPropertyJsonLike(Client.PROPERTY_FAX_NUMBERS_JSON, faxNumber); } } //ClientTopiaDao diff --git a/faxtomail-persistence/src/main/java/com/franciaflex/faxtomail/persistence/entities/EmailImpl.java b/faxtomail-persistence/src/main/java/com/franciaflex/faxtomail/persistence/entities/EmailImpl.java index aab224b..2facb27 100644 --- a/faxtomail-persistence/src/main/java/com/franciaflex/faxtomail/persistence/entities/EmailImpl.java +++ b/faxtomail-persistence/src/main/java/com/franciaflex/faxtomail/persistence/entities/EmailImpl.java @@ -24,16 +24,15 @@ package com.franciaflex.faxtomail.persistence.entities; * #L% */ -import com.google.common.base.Function; -import com.google.common.base.Predicate; import com.google.common.base.Strings; -import com.google.common.collect.Collections2; import org.apache.commons.lang3.StringUtils; import java.util.ArrayList; import java.util.Collection; import java.util.Date; import java.util.List; +import java.util.Objects; +import java.util.stream.Collectors; /** * @author Kevin Morin (Code Lutin) @@ -90,15 +89,15 @@ public class EmailImpl extends EmailAbstract { Date modificationDate = history.getModificationDate(); if (HistoryType.ATTACHMENT_OPENING.equals(history.getType())) { if ((transmissionHistory == null - || transmissionHistory.getModificationDate().before(modificationDate)) - && (result == null + || transmissionHistory.getModificationDate().before(modificationDate)) + && (result == null || result.getModificationDate().before(modificationDate))) { result = history; } } else if (HistoryType.TRANSMISSION.equals(history.getType())) { if (transmissionHistory == null - || transmissionHistory.getModificationDate().before(modificationDate)) { + || transmissionHistory.getModificationDate().before(modificationDate)) { transmissionHistory = history; if (result != null && result.getModificationDate().before(transmissionHistory.getModificationDate())) { @@ -177,24 +176,17 @@ public class EmailImpl extends EmailAbstract { } public String getReference() { - List<String> reference = new ArrayList<String>(); + List<String> reference = new ArrayList<>(); if (StringUtils.isNotBlank(getCompanyReference())) { reference.add(getCompanyReference()); } Collection<RangeRow> rangeRow = getRangeRow(); if (rangeRow != null) { - Collection<String> commandNumbers = Collections2.transform(rangeRow, new Function<RangeRow, String>() { - @Override - public String apply(RangeRow input) { - return input != null ? input.getCommandNumber() : ""; - } - }); - Collections2.filter(commandNumbers, new Predicate<String>() { - @Override - public boolean apply(String input) { - return StringUtils.isNotBlank(input); - } - }); + Collection<String> commandNumbers = rangeRow.stream() + .filter(Objects::nonNull) + .map(RangeRow::getCommandNumber) + .filter(StringUtils::isNotBlank) + .collect(Collectors.toList()); reference.addAll(commandNumbers); } return StringUtils.join(reference, ", "); diff --git a/faxtomail-persistence/src/main/java/com/franciaflex/faxtomail/persistence/entities/EmailTopiaDao.java b/faxtomail-persistence/src/main/java/com/franciaflex/faxtomail/persistence/entities/EmailTopiaDao.java index 5ce2399..c60ccf0 100644 --- a/faxtomail-persistence/src/main/java/com/franciaflex/faxtomail/persistence/entities/EmailTopiaDao.java +++ b/faxtomail-persistence/src/main/java/com/franciaflex/faxtomail/persistence/entities/EmailTopiaDao.java @@ -24,24 +24,18 @@ package com.franciaflex.faxtomail.persistence.entities; * #L% */ -import com.google.common.base.Function; -import com.google.common.base.Objects; import com.google.common.base.Splitter; -import com.google.common.base.Strings; -import com.google.common.collect.Iterables; -import com.google.common.collect.Lists; -import com.google.common.collect.Maps; import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.time.DateUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.hibernate.Hibernate; -import org.nuiton.topia.persistence.TopiaEntities; import org.nuiton.topia.persistence.TopiaEntity; import org.nuiton.util.pagination.PaginationParameter; import org.nuiton.util.pagination.PaginationResult; +import java.util.ArrayList; import java.util.Calendar; import java.util.Collection; import java.util.Date; @@ -51,6 +45,8 @@ import java.util.LinkedHashMap; import java.util.List; import java.util.Map; import java.util.Set; +import java.util.function.Function; +import java.util.stream.Collectors; public class EmailTopiaDao extends AbstractEmailTopiaDao<Email> { @@ -421,9 +417,9 @@ public class EmailTopiaDao extends AbstractEmailTopiaDao<Email> { List<Email> sortedEntities; if (CollectionUtils.isEmpty(step1ResultTopiaIds)) { - sortedEntities = Lists.newArrayList(); + sortedEntities = new ArrayList<>(); } else { - Map<String, Object> step2Args = Maps.newHashMap(); + Map<String, Object> step2Args = new HashMap<>(); step2Args.put("topiaIdsForFetch_", step1ResultTopiaIds); List<Email> entities = forHql(hqlForFetchStep2, step2Args).findAll(); @@ -508,13 +504,13 @@ public class EmailTopiaDao extends AbstractEmailTopiaDao<Email> { query1.append(")"); - result.addAll(this.<Email>findAll(query1.toString(), args)); + result.addAll(this.findAll(query1.toString(), args)); StringBuilder query2 = new StringBuilder(query); query2.append(" AND (E." + Email.PROPERTY_COMPANY_REFERENCE + " LIKE :" + SearchFilter.PROPERTY_COMMAND_NB); query2.append(")"); - result.addAll(this.<Email>findAll(query2.toString(), args)); + result.addAll(this.findAll(query2.toString(), args)); return result; } @@ -575,9 +571,9 @@ public class EmailTopiaDao extends AbstractEmailTopiaDao<Email> { List<Email> sortedEntities; if (CollectionUtils.isEmpty(step1ResultTopiaIds)) { - sortedEntities = Lists.newArrayList(); + sortedEntities = new ArrayList<>(); } else { - Map<String, Object> step2Args = Maps.newHashMap(); + Map<String, Object> step2Args = new HashMap<>(); step2Args.put("topiaIdsForFetch_", step1ResultTopiaIds); time = new Date().getTime(); @@ -1026,7 +1022,7 @@ public class EmailTopiaDao extends AbstractEmailTopiaDao<Email> { StringBuilder hqlFromClauseBuilder = new StringBuilder(); //if (includeFetch) { int fetchedPropertiesAliasIndex = 0; - Map<String, String> aliases = Maps.newHashMap(); + Map<String, String> aliases = new HashMap<>(); for (String propertyName : fetchProperties) { // addAllFetches("a.b").addAllFetches("i.j.k") will produce: @@ -1043,7 +1039,7 @@ public class EmailTopiaDao extends AbstractEmailTopiaDao<Email> { // Look for the parent alias if already computed String previousPath = path.toString(); - String previousAlias = Objects.firstNonNull(aliases.get(previousPath), "E"); + String previousAlias = aliases.getOrDefault(previousPath, "E"); // Compute the current path and look for its alias if (path.length() > 0) { @@ -1054,7 +1050,7 @@ public class EmailTopiaDao extends AbstractEmailTopiaDao<Email> { String currentAlias = aliases.get(currentPath); // No current alias found, create and add it - if (Strings.isNullOrEmpty(currentAlias)) { + if (StringUtils.isEmpty(currentAlias)) { currentAlias = String.format("fetchedProp%d_", fetchedPropertiesAliasIndex++); aliases.put(currentPath, currentAlias); @@ -1074,16 +1070,11 @@ public class EmailTopiaDao extends AbstractEmailTopiaDao<Email> { protected <O extends TopiaEntity> List<O> sortAccordingToIds(List<O> entities, final List<String> idsList) { // Cannot sort on second query, will sort according to the first result list - final Map<String, O> entitiesIndex = Maps.uniqueIndex(entities, TopiaEntities.getTopiaIdFunction()); - Iterable<O> transformed = Iterables.transform(idsList, new Function<String, O>() { - @Override - public O apply(String input) { - return entitiesIndex.get(input); - } - }); - - List<O> result = Lists.newArrayList(transformed); - return result; + final Map<String, O> entitiesIndex = entities.stream() + .collect(Collectors.toMap(TopiaEntity::getTopiaId, Function.identity())); + return idsList.stream() + .map(entitiesIndex::get) + .collect(Collectors.toList()); } public Set<Object> getDistinctValues(MailFolder folder, String[] properties, boolean sum) { diff --git a/faxtomail-persistence/src/main/java/com/franciaflex/faxtomail/persistence/entities/ExtensionCommandTopiaDao.java b/faxtomail-persistence/src/main/java/com/franciaflex/faxtomail/persistence/entities/ExtensionCommandTopiaDao.java index 42672e6..a36f2c0 100644 --- a/faxtomail-persistence/src/main/java/com/franciaflex/faxtomail/persistence/entities/ExtensionCommandTopiaDao.java +++ b/faxtomail-persistence/src/main/java/com/franciaflex/faxtomail/persistence/entities/ExtensionCommandTopiaDao.java @@ -35,8 +35,7 @@ public class ExtensionCommandTopiaDao extends AbstractExtensionCommandTopiaDao<E Map<String, Object> args = new HashMap<>(); args.put("extension", extension); - ExtensionCommand result = findUniqueOrNull(query, args); - return result; + return findUniqueOrNull(query, args); } } //ExtensionCommandTopiaDao diff --git a/faxtomail-persistence/src/main/java/com/franciaflex/faxtomail/persistence/entities/HistoryImpl.java b/faxtomail-persistence/src/main/java/com/franciaflex/faxtomail/persistence/entities/HistoryImpl.java index 3e887fa..37d5e8b 100644 --- a/faxtomail-persistence/src/main/java/com/franciaflex/faxtomail/persistence/entities/HistoryImpl.java +++ b/faxtomail-persistence/src/main/java/com/franciaflex/faxtomail/persistence/entities/HistoryImpl.java @@ -45,8 +45,7 @@ public class HistoryImpl extends HistoryAbstract { @Override public Set<String> getFields() { String json = getFieldsJson(); - Set<String> fields = AbstractFaxToMailTopiaDao.GSON_INSTANCE.fromJson(json, SET_STRING_GSON_TYPE); - return fields; + return AbstractFaxToMailTopiaDao.GSON_INSTANCE.fromJson(json, SET_STRING_GSON_TYPE); } } diff --git a/faxtomail-persistence/src/main/java/com/franciaflex/faxtomail/persistence/entities/MailFolderTopiaDao.java b/faxtomail-persistence/src/main/java/com/franciaflex/faxtomail/persistence/entities/MailFolderTopiaDao.java index 47738fa..a9f934c 100644 --- a/faxtomail-persistence/src/main/java/com/franciaflex/faxtomail/persistence/entities/MailFolderTopiaDao.java +++ b/faxtomail-persistence/src/main/java/com/franciaflex/faxtomail/persistence/entities/MailFolderTopiaDao.java @@ -24,8 +24,6 @@ package com.franciaflex.faxtomail.persistence.entities; * #L% */ -import com.google.common.collect.Maps; - import java.util.Collection; import java.util.HashMap; @@ -56,20 +54,18 @@ public class MailFolderTopiaDao extends AbstractMailFolderTopiaDao<MailFolder> { public Collection<MailFolder> getReadableFolders(FaxToMailUser user) { String query = newFromClause("mf") + " where (:user in elements(mf.readRightUsers) or exists (from mf.readRightGroups g where g in (:groups))) and mf.archiveFolder = false"; - HashMap<String, Object> map = Maps.newHashMap(); + HashMap<String, Object> map = new HashMap<>(); map.put("user", user); map.put("groups", user.getUserGroups()); - Collection<MailFolder> folders = findAll(query, map); - return folders; + return findAll(query, map); } public Collection<MailFolder> getMoveableFolders(FaxToMailUser user) { String query = newFromClause("mf") + " where (:user in elements(mf.moveRightUsers) or exists (from mf.moveRightGroups g where g in (:groups))) and mf.archiveFolder = false"; - HashMap<String, Object> map = Maps.newHashMap(); + HashMap<String, Object> map = new HashMap<>(); map.put("user", user); map.put("groups", user.getUserGroups()); - Collection<MailFolder> folders = findAll(query, map); - return folders; + return findAll(query, map); } } //MailFolderTopiaDao diff --git a/faxtomail-persistence/src/main/java/com/franciaflex/faxtomail/persistence/entities/SearchFilter.java b/faxtomail-persistence/src/main/java/com/franciaflex/faxtomail/persistence/entities/SearchFilter.java index de934e2..5ddc683 100644 --- a/faxtomail-persistence/src/main/java/com/franciaflex/faxtomail/persistence/entities/SearchFilter.java +++ b/faxtomail-persistence/src/main/java/com/franciaflex/faxtomail/persistence/entities/SearchFilter.java @@ -225,9 +225,8 @@ public class SearchFilter extends AbstractSerializableBean { } public void setModifiedBy(FaxToMailUser modifiedBy) { - FaxToMailUser oldValue = modifiedBy; this.modifiedBy = modifiedBy; - firePropertyChange(PROPERTY_MODIFIED_BY, oldValue, modifiedBy); + firePropertyChange(PROPERTY_MODIFIED_BY, modifiedBy, modifiedBy); } public Date getMinModificationDate() { diff --git a/faxtomail-persistence/src/main/java/com/franciaflex/faxtomail/persistence/hibernate/EnumListUserType.java b/faxtomail-persistence/src/main/java/com/franciaflex/faxtomail/persistence/hibernate/EnumListUserType.java index 127ad39..9b5a6b5 100644 --- a/faxtomail-persistence/src/main/java/com/franciaflex/faxtomail/persistence/hibernate/EnumListUserType.java +++ b/faxtomail-persistence/src/main/java/com/franciaflex/faxtomail/persistence/hibernate/EnumListUserType.java @@ -83,7 +83,7 @@ public abstract class EnumListUserType<T extends Enum<T>> implements UserType { List<T> result = null; if (!rs.wasNull()) { String[] values = name.split(","); - result = new ArrayList<T>(); + result = new ArrayList<>(); for (String value : values) { if (!value.isEmpty()) { result.add(Enum.valueOf(typeClazz, value)); diff --git a/faxtomail-persistence/src/main/java/com/franciaflex/faxtomail/persistence/hibernate/EnumSetUserType.java b/faxtomail-persistence/src/main/java/com/franciaflex/faxtomail/persistence/hibernate/EnumSetUserType.java index a1c2213..718feba 100644 --- a/faxtomail-persistence/src/main/java/com/franciaflex/faxtomail/persistence/hibernate/EnumSetUserType.java +++ b/faxtomail-persistence/src/main/java/com/franciaflex/faxtomail/persistence/hibernate/EnumSetUserType.java @@ -84,7 +84,7 @@ public abstract class EnumSetUserType<T extends Enum<T>> implements UserType { EnumSet<T> result = null; if (!rs.wasNull()) { String[] values = name.split(","); - Set<T> enumList = new LinkedHashSet<T>(); + Set<T> enumList = new LinkedHashSet<>(); for (String value : values) { if (!value.isEmpty()) { enumList.add(Enum.valueOf(typeClazz, value)); diff --git a/faxtomail-service/src/main/java/com/franciaflex/faxtomail/services/FaxToMailDecorator.java b/faxtomail-service/src/main/java/com/franciaflex/faxtomail/services/FaxToMailDecorator.java index 7f06506..318f9a7 100644 --- a/faxtomail-service/src/main/java/com/franciaflex/faxtomail/services/FaxToMailDecorator.java +++ b/faxtomail-service/src/main/java/com/franciaflex/faxtomail/services/FaxToMailDecorator.java @@ -24,11 +24,9 @@ package com.franciaflex.faxtomail.services; * #L% */ -import com.google.common.base.Preconditions; import com.google.common.cache.CacheBuilder; import com.google.common.cache.CacheLoader; import com.google.common.cache.LoadingCache; -import com.google.common.collect.Maps; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.nuiton.decorator.DecoratorUtil; @@ -40,8 +38,10 @@ import java.beans.PropertyDescriptor; import java.io.Serializable; import java.lang.reflect.Method; import java.util.Arrays; +import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.Objects; import java.util.Set; import java.util.concurrent.ExecutionException; @@ -80,7 +80,7 @@ public class FaxToMailDecorator<O> extends MultiJXPathDecorator<O> implements Cl String expression, String separator, String separatorReplacement) { - return new FaxToMailDecorator<O>(internalClass, expression, separator, separatorReplacement); + return new FaxToMailDecorator<>(internalClass, expression, separator, separatorReplacement); } protected FaxToMailDecorator(Class<O> internalClass, @@ -91,10 +91,10 @@ public class FaxToMailDecorator<O> extends MultiJXPathDecorator<O> implements Cl expression, separator, separatorReplacement, - DecoratorUtil.<O>createMultiJXPathContextKeepingOrder(expression, - separator, - separatorReplacement)); - tokenMethods = Maps.newHashMap(); + DecoratorUtil.createMultiJXPathContextKeepingOrder(expression, + separator, + separatorReplacement)); + tokenMethods = new HashMap<>(); Set<PropertyDescriptor> descriptors = BeanUtil.getDescriptors(type, BeanUtil.IS_READ_DESCRIPTOR); @@ -115,7 +115,7 @@ public class FaxToMailDecorator<O> extends MultiJXPathDecorator<O> implements Cl int i = 0; for (Context<O> OContext : contexts) { - OContext.setComparator(new FaxToMailDecoratorComparator<O>(getProperty(i++))); + OContext.setComparator(new FaxToMailDecoratorComparator<>(getProperty(i++))); } this.cache = CacheBuilder.newBuilder().build(new CacheLoader<O, String>() { @@ -213,7 +213,7 @@ public class FaxToMailDecorator<O> extends MultiJXPathDecorator<O> implements Cl protected Object getValue(O bean, String token) { Method method = tokenMethods.get(token); - Preconditions.checkNotNull(method, + Objects.requireNonNull(method, "Could not find method for token " + token); Object result; try { @@ -273,9 +273,7 @@ public class FaxToMailDecorator<O> extends MultiJXPathDecorator<O> implements Cl @Override public FaxToMailDecoratorComparator<O> clone() { - FaxToMailDecoratorComparator<O> result = - new FaxToMailDecoratorComparator<O>(expression); - return result; + return new FaxToMailDecoratorComparator<>(expression); } public String getExpression() { diff --git a/faxtomail-service/src/main/java/com/franciaflex/faxtomail/services/FaxToMailServiceContext.java b/faxtomail-service/src/main/java/com/franciaflex/faxtomail/services/FaxToMailServiceContext.java index 108c022..6bb252f 100644 --- a/faxtomail-service/src/main/java/com/franciaflex/faxtomail/services/FaxToMailServiceContext.java +++ b/faxtomail-service/src/main/java/com/franciaflex/faxtomail/services/FaxToMailServiceContext.java @@ -38,7 +38,6 @@ import com.franciaflex.faxtomail.services.service.ReferentielService; import com.franciaflex.faxtomail.services.service.UserService; import com.franciaflex.faxtomail.services.service.ValidationService; import com.franciaflex.faxtomail.services.service.ldap.LdapServiceMock; -import com.google.common.base.Preconditions; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.nuiton.jaxx.application.ApplicationTechnicalException; @@ -49,6 +48,7 @@ import java.lang.reflect.Constructor; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Proxy; import java.util.Date; +import java.util.Objects; public class FaxToMailServiceContext implements Closeable { @@ -77,8 +77,8 @@ public class FaxToMailServiceContext implements Closeable { } private FaxToMailServiceContext(FaxToMailTopiaApplicationContext topiaApplicationContext, FaxToMailServiceFactory serviceFactory) { - Preconditions.checkNotNull(topiaApplicationContext, "Cannot create an ServiceContext without an ApplicationContext"); - Preconditions.checkNotNull(serviceFactory, "Cannot create an ServiceContext without a ServiceFactory"); + Objects.requireNonNull(topiaApplicationContext, "Cannot create an ServiceContext without an ApplicationContext"); + Objects.requireNonNull(serviceFactory, "Cannot create an ServiceContext without a ServiceFactory"); this.topiaApplicationContext = topiaApplicationContext; this.serviceFactory = serviceFactory; this.serviceFactory.setServiceContext(this); @@ -190,17 +190,14 @@ public class FaxToMailServiceContext implements Closeable { E realService = defaultServiceFactory.newService(serviceInterfaceClass); - E service = (E) Proxy.newProxyInstance(serviceInterfaceClass.getClassLoader(), new Class[]{serviceInterfaceClass}, - new FaxToMailServiceInvocationHandler(realService, serviceContext)); - - return service; + return (E) Proxy.newProxyInstance(serviceInterfaceClass.getClassLoader(), new Class[]{serviceInterfaceClass}, + new FaxToMailServiceInvocationHandler(realService, serviceContext)); } } public Date getNow() { - Date now = new Date(); - return now; + return new Date(); } public DecoratorService getDecoratorService() { diff --git a/faxtomail-service/src/main/java/com/franciaflex/faxtomail/services/FaxToMailServiceInvocationHandler.java b/faxtomail-service/src/main/java/com/franciaflex/faxtomail/services/FaxToMailServiceInvocationHandler.java index 493a1bf..fd6ff76 100644 --- a/faxtomail-service/src/main/java/com/franciaflex/faxtomail/services/FaxToMailServiceInvocationHandler.java +++ b/faxtomail-service/src/main/java/com/franciaflex/faxtomail/services/FaxToMailServiceInvocationHandler.java @@ -47,8 +47,7 @@ public class FaxToMailServiceInvocationHandler implements InvocationHandler { @Override public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { try { - Object result = method.invoke(wrappedService, args); - return result; + return method.invoke(wrappedService, args); } catch (InvocationTargetException ex) { throw ex.getCause(); } finally { diff --git a/faxtomail-service/src/main/java/com/franciaflex/faxtomail/services/FaxToMailServiceUtils.java b/faxtomail-service/src/main/java/com/franciaflex/faxtomail/services/FaxToMailServiceUtils.java index 636e576..4f15957 100644 --- a/faxtomail-service/src/main/java/com/franciaflex/faxtomail/services/FaxToMailServiceUtils.java +++ b/faxtomail-service/src/main/java/com/franciaflex/faxtomail/services/FaxToMailServiceUtils.java @@ -25,7 +25,6 @@ package com.franciaflex.faxtomail.services; */ import com.franciaflex.faxtomail.persistence.entities.MailFolder; -import com.google.common.base.Preconditions; import org.apache.commons.httpclient.URIException; import org.apache.commons.httpclient.util.URIUtil; import org.apache.commons.io.Charsets; @@ -47,6 +46,7 @@ import java.net.URL; import java.nio.charset.Charset; import java.nio.charset.UnsupportedCharsetException; import java.util.Collection; +import java.util.Objects; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -158,7 +158,7 @@ public class FaxToMailServiceUtils { } public static String getDecodedSubject(String subject) throws UnsupportedEncodingException { - Preconditions.checkNotNull(subject); + Objects.requireNonNull(subject); if (subject.startsWith("=?iso-")) { subject = subject.replaceAll(" ", "=20"); @@ -169,7 +169,7 @@ public class FaxToMailServiceUtils { } public static String getDomainForEmailAddress(String emailAddress) { - Preconditions.checkNotNull(emailAddress); + Objects.requireNonNull(emailAddress); return emailAddress.substring(emailAddress.lastIndexOf("@") + 1); } diff --git a/faxtomail-service/src/main/java/com/franciaflex/faxtomail/services/service/ClientServiceImpl.java b/faxtomail-service/src/main/java/com/franciaflex/faxtomail/services/service/ClientServiceImpl.java index 7382c76..c1de17f 100644 --- a/faxtomail-service/src/main/java/com/franciaflex/faxtomail/services/service/ClientServiceImpl.java +++ b/faxtomail-service/src/main/java/com/franciaflex/faxtomail/services/service/ClientServiceImpl.java @@ -33,11 +33,6 @@ import com.franciaflex.faxtomail.persistence.entities.FaxToMailUserTopiaDao; import com.franciaflex.faxtomail.persistence.entities.MailFolder; import com.franciaflex.faxtomail.persistence.entities.NewClient; import com.franciaflex.faxtomail.services.FaxToMailServiceSupport; -import com.google.common.base.Function; -import com.google.common.base.Preconditions; -import com.google.common.base.Predicate; -import com.google.common.collect.Collections2; -import com.google.common.collect.Lists; import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.collections4.map.MultiKeyMap; import org.apache.commons.lang3.StringUtils; @@ -45,11 +40,8 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.nuiton.topia.persistence.TopiaQueryBuilderAddCriteriaOrRunQueryStep; import org.nuiton.topia.persistence.support.TopiaSqlSupport; -import org.nuiton.topia.persistence.support.TopiaSqlWork; -import java.sql.Connection; import java.sql.ResultSet; -import java.sql.SQLException; import java.sql.Statement; import java.util.ArrayList; import java.util.Collection; @@ -57,6 +49,7 @@ import java.util.HashSet; import java.util.List; import java.util.Objects; import java.util.Set; +import java.util.stream.Collectors; /** * Service de gestion des clients. @@ -79,8 +72,8 @@ public class ClientServiceImpl extends FaxToMailServiceSupport implements Client */ @Override public List<Client> getClientForEmailAddress(String emailAddress, Email email, final String company, List<String> brands) { - Preconditions.checkNotNull(email); - Preconditions.checkNotNull(emailAddress); + Objects.requireNonNull(email); + Objects.requireNonNull(emailAddress); ClientTopiaDao clientDao = getPersistenceContext().getClientDao(); @@ -102,23 +95,15 @@ public class ClientServiceImpl extends FaxToMailServiceSupport implements Client if (CollectionUtils.isNotEmpty(clients)) { // transform the brand list into a list of lower case brands - final List<String> lowerCaseBrands = brands == null ? new ArrayList<String>() : - Lists.transform(brands, new Function<String, String>() { - @Override - public String apply(String s) { - return StringUtils.lowerCase(s); - } - }); - result = new ArrayList<>(Collections2.filter(clients, new Predicate<Client>() { - @Override - public boolean apply(Client client) { - boolean equalsCompany = StringUtils.isBlank(company) - || Objects.equals(company, client.getCompany()); - boolean inBrands = CollectionUtils.isEmpty(lowerCaseBrands) - || lowerCaseBrands.contains(StringUtils.lowerCase(client.getBrand())); - return equalsCompany && inBrands; - } - })); + final List<String> lowerCaseBrands = brands == null ? new ArrayList<>() : + brands.stream().map(StringUtils::lowerCase).collect(Collectors.toList()); + result = clients.stream().filter(client -> { + boolean equalsCompany = StringUtils.isBlank(company) + || Objects.equals(company, client.getCompany()); + boolean inBrands = CollectionUtils.isEmpty(lowerCaseBrands) + || lowerCaseBrands.contains(StringUtils.lowerCase(client.getBrand())); + return equalsCompany && inBrands; + }).collect(Collectors.toList()); } } @@ -157,8 +142,7 @@ public class ClientServiceImpl extends FaxToMailServiceSupport implements Client String company = folder.getCompany(); ClientTopiaDao clientDao = getPersistenceContext().getClientDao(); - List<Client> result = clientDao.forCompanyEquals(company).findAll(); - return result; + return clientDao.forCompanyEquals(company).findAll(); } /** @@ -171,139 +155,135 @@ public class ClientServiceImpl extends FaxToMailServiceSupport implements Client final FaxToMailUserTopiaDao faxToMailUserDao = getPersistenceContext().getFaxToMailUserDao(); TopiaSqlSupport sqlSupport = getPersistenceContext().getSqlSupport(); - sqlSupport.doSqlWork(new TopiaSqlWork() { - - @Override - public void execute(Connection connection) throws SQLException { - - int importedCount = 0; - - // attention, le sql à pour cible postgresql, mssql, h2, il doit rester simple - String query = String.format("SELECT %s, %s, %s, %s, %s, %s, %s, %s, %s, %s FROM %s", - NewClient.PROPERTY_NAME, - NewClient.PROPERTY_EMAIL_ADDRESS, - NewClient.PROPERTY_FAX_NUMBER, - NewClient.PROPERTY_CARACTERISTIC1, - NewClient.PROPERTY_CARACTERISTIC2, - NewClient.PROPERTY_CARACTERISTIC3, - NewClient.PROPERTY_CODE, - NewClient.PROPERTY_BRAND, - NewClient.PROPERTY_COMPANY, - NewClient.PROPERTY_PERSON_IN_CHARGE, - NewClient.class.getSimpleName()); - Statement stat = connection.createStatement(); - - // get query result set - ResultSet resultSet = stat.executeQuery(query); - // cache utilise pour mettre à jour les mêmes client dans le cas ou - // il reviennt plusieurs fois - MultiKeyMap<String, Client> clientCache = new MultiKeyMap<>(); - - // parse result set - while (resultSet.next()) { - String name = resultSet.getString(NewClient.PROPERTY_NAME); - String emailAddress = resultSet.getString(NewClient.PROPERTY_EMAIL_ADDRESS); - String faxNumber = resultSet.getString(NewClient.PROPERTY_FAX_NUMBER); - String caracteristic1 = resultSet.getString(NewClient.PROPERTY_CARACTERISTIC1); - String caracteristic2 = resultSet.getString(NewClient.PROPERTY_CARACTERISTIC2); - String caracteristic3 = resultSet.getString(NewClient.PROPERTY_CARACTERISTIC3); - String code = resultSet.getString(NewClient.PROPERTY_CODE); - String brand = resultSet.getString(NewClient.PROPERTY_BRAND); - String company = resultSet.getString(NewClient.PROPERTY_COMPANY); - String personInCharge = resultSet.getString(NewClient.PROPERTY_PERSON_IN_CHARGE); - - // clear some data - if ("null".equalsIgnoreCase(caracteristic1)) { - caracteristic1 = null; - } - if ("null".equalsIgnoreCase(caracteristic2)) { - caracteristic2 = null; - } - if ("null".equalsIgnoreCase(caracteristic3)) { - caracteristic3 = null; - } - if ("null".equalsIgnoreCase(brand)) { - brand = null; - } - if ("null".equalsIgnoreCase(emailAddress)) { - emailAddress = null; - } - if (faxNumber != null) { - faxNumber = StringUtils.removePattern(faxNumber, "[^0-9]"); - if (faxNumber.isEmpty() || faxNumber.equals("0")) { - faxNumber = null; - } + sqlSupport.doSqlWork(connection -> { + + int importedCount = 0; + + // attention, le sql à pour cible postgresql, mssql, h2, il doit rester simple + String query = String.format("SELECT %s, %s, %s, %s, %s, %s, %s, %s, %s, %s FROM %s", + NewClient.PROPERTY_NAME, + NewClient.PROPERTY_EMAIL_ADDRESS, + NewClient.PROPERTY_FAX_NUMBER, + NewClient.PROPERTY_CARACTERISTIC1, + NewClient.PROPERTY_CARACTERISTIC2, + NewClient.PROPERTY_CARACTERISTIC3, + NewClient.PROPERTY_CODE, + NewClient.PROPERTY_BRAND, + NewClient.PROPERTY_COMPANY, + NewClient.PROPERTY_PERSON_IN_CHARGE, + NewClient.class.getSimpleName()); + Statement stat = connection.createStatement(); + + // get query result set + ResultSet resultSet = stat.executeQuery(query); + // cache utilise pour mettre à jour les mêmes client dans le cas ou + // il reviennt plusieurs fois + MultiKeyMap<String, Client> clientCache = new MultiKeyMap<>(); + + // parse result set + while (resultSet.next()) { + String name = resultSet.getString(NewClient.PROPERTY_NAME); + String emailAddress = resultSet.getString(NewClient.PROPERTY_EMAIL_ADDRESS); + String faxNumber = resultSet.getString(NewClient.PROPERTY_FAX_NUMBER); + String caracteristic1 = resultSet.getString(NewClient.PROPERTY_CARACTERISTIC1); + String caracteristic2 = resultSet.getString(NewClient.PROPERTY_CARACTERISTIC2); + String caracteristic3 = resultSet.getString(NewClient.PROPERTY_CARACTERISTIC3); + String code = resultSet.getString(NewClient.PROPERTY_CODE); + String brand = resultSet.getString(NewClient.PROPERTY_BRAND); + String company = resultSet.getString(NewClient.PROPERTY_COMPANY); + String personInCharge = resultSet.getString(NewClient.PROPERTY_PERSON_IN_CHARGE); + + // clear some data + if ("null".equalsIgnoreCase(caracteristic1)) { + caracteristic1 = null; + } + if ("null".equalsIgnoreCase(caracteristic2)) { + caracteristic2 = null; + } + if ("null".equalsIgnoreCase(caracteristic3)) { + caracteristic3 = null; + } + if ("null".equalsIgnoreCase(brand)) { + brand = null; + } + if ("null".equalsIgnoreCase(emailAddress)) { + emailAddress = null; + } + if (faxNumber != null) { + faxNumber = StringUtils.removePattern(faxNumber, "[^0-9]"); + if (faxNumber.isEmpty() || faxNumber.equals("0")) { + faxNumber = null; } + } - // save data - Client client = clientCache.get(code, company); + // save data + Client client = clientCache.get(code, company); + if (client == null) { + client = clientDao.forCodeEquals(code).addEquals(Client.PROPERTY_COMPANY, company).findUniqueOrNull(); if (client == null) { - client = clientDao.forCodeEquals(code).addEquals(Client.PROPERTY_COMPANY, company).findUniqueOrNull(); - if (client == null) { - client = new ClientImpl(); - client.setCode(code); - client.setCompany(company); - } - - client.setName(name); - client.setCaracteristic1(caracteristic1); - client.setCaracteristic2(caracteristic2); - client.setCaracteristic3(caracteristic3); - client.setBrand(brand); - - // clear current adresses and fax numbers - client.setEmailAddresses(null); - client.setFaxNumbers(null); - - // look for personInCharge - FaxToMailUser faxToMailUserInCharge = null; - if (StringUtils.isNotBlank(personInCharge)) { - faxToMailUserInCharge = faxToMailUserDao.forLoginEquals(personInCharge).findUniqueOrNull(); - } - client.setPersonInCharge(faxToMailUserInCharge); - - if (client.isPersisted()) { - client = clientDao.update(client); - } else { - client = clientDao.create(client); - } - - // update cache - clientCache.put(code, company, client); + client = new ClientImpl(); + client.setCode(code); + client.setCompany(company); } - // only manage emailAdress and faxNumber in this case client is in cache - if (StringUtils.isNotBlank(emailAddress)) { - List<String> currentAddresses = client.getEmailAddresses(); - if (currentAddresses == null) { - currentAddresses = new ArrayList<String>(); - } - currentAddresses.add(emailAddress); - client.setEmailAddresses(currentAddresses); - client = clientDao.update(client); + client.setName(name); + client.setCaracteristic1(caracteristic1); + client.setCaracteristic2(caracteristic2); + client.setCaracteristic3(caracteristic3); + client.setBrand(brand); + + // clear current adresses and fax numbers + client.setEmailAddresses(null); + client.setFaxNumbers(null); + + // look for personInCharge + FaxToMailUser faxToMailUserInCharge = null; + if (StringUtils.isNotBlank(personInCharge)) { + faxToMailUserInCharge = faxToMailUserDao.forLoginEquals(personInCharge).findUniqueOrNull(); } - // and............................ faxNumber - if (StringUtils.isNotBlank(faxNumber)) { - List<String> faxNumbers = client.getFaxNumbers(); - if (faxNumbers == null) { - faxNumbers = new ArrayList<String>(); - } - faxNumbers.add(faxNumber); - client.setFaxNumbers(faxNumbers); + client.setPersonInCharge(faxToMailUserInCharge); + + if (client.isPersisted()) { client = clientDao.update(client); + } else { + client = clientDao.create(client); + } + + // update cache + clientCache.put(code, company, client); + } + + // only manage emailAdress and faxNumber in this case client is in cache + if (StringUtils.isNotBlank(emailAddress)) { + List<String> currentAddresses = client.getEmailAddresses(); + if (currentAddresses == null) { + currentAddresses = new ArrayList<>(); } - - importedCount++; + currentAddresses.add(emailAddress); + client.setEmailAddresses(currentAddresses); + client = clientDao.update(client); } - - // delete all rows - stat = connection.createStatement(); - stat.execute("DELETE FROM " + NewClient.class.getSimpleName()); - - // usefull log info (do not remove) - if (importedCount > 0 && log.isInfoEnabled()) { - log.info(String.format("Imported %d new client rows", importedCount)); + // and............................ faxNumber + if (StringUtils.isNotBlank(faxNumber)) { + List<String> faxNumbers = client.getFaxNumbers(); + if (faxNumbers == null) { + faxNumbers = new ArrayList<>(); + } + faxNumbers.add(faxNumber); + client.setFaxNumbers(faxNumbers); + client = clientDao.update(client); } + + importedCount++; + } + + // delete all rows + stat = connection.createStatement(); + stat.execute("DELETE FROM " + NewClient.class.getSimpleName()); + + // usefull log info (do not remove) + if (importedCount > 0 && log.isInfoEnabled()) { + log.info(String.format("Imported %d new client rows", importedCount)); } }); @@ -318,7 +298,7 @@ public class ClientServiceImpl extends FaxToMailServiceSupport implements Client for (MailFolder folder : folders) { MailFolder folderWithCompany = folder; - while (!folderWithCompany.isUseCurrentLevelCompany() && folderWithCompany != null) { + while (folderWithCompany != null && !folderWithCompany.isUseCurrentLevelCompany()) { folderWithCompany = folderWithCompany.getParent(); } @@ -330,8 +310,7 @@ public class ClientServiceImpl extends FaxToMailServiceSupport implements Client fetchCompaniesFromFolders(folders, companies); ClientTopiaDao clientDao = getPersistenceContext().getClientDao(); - List<Client> result = clientDao.forCompanyIn(companies).findAll(); - return result; + return clientDao.forCompanyIn(companies).findAll(); } protected void fetchCompaniesFromFolders(Collection<MailFolder> folders, Set<String> companies) { diff --git a/faxtomail-service/src/main/java/com/franciaflex/faxtomail/services/service/ConfigurationService.java b/faxtomail-service/src/main/java/com/franciaflex/faxtomail/services/service/ConfigurationService.java index b1c9960..dd20d77 100644 --- a/faxtomail-service/src/main/java/com/franciaflex/faxtomail/services/service/ConfigurationService.java +++ b/faxtomail-service/src/main/java/com/franciaflex/faxtomail/services/service/ConfigurationService.java @@ -37,7 +37,6 @@ import com.franciaflex.faxtomail.persistence.entities.SigningForDomain; import com.franciaflex.faxtomail.persistence.entities.Stamp; import com.franciaflex.faxtomail.persistence.entities.WaitingState; import com.franciaflex.faxtomail.services.FaxToMailService; -import com.google.common.base.Optional; import java.util.Collection; import java.util.List; @@ -86,8 +85,6 @@ public interface ConfigurationService extends FaxToMailService { List<SigningForDomain> getAllSigningsForDomains(); - Optional<SigningForDomain> getSigningForEmailAddress(String emailAddress); - - + SigningForDomain getSigningForEmailAddress(String emailAddress); } diff --git a/faxtomail-service/src/main/java/com/franciaflex/faxtomail/services/service/ConfigurationServiceImpl.java b/faxtomail-service/src/main/java/com/franciaflex/faxtomail/services/service/ConfigurationServiceImpl.java index 4c37309..50cd327 100644 --- a/faxtomail-service/src/main/java/com/franciaflex/faxtomail/services/service/ConfigurationServiceImpl.java +++ b/faxtomail-service/src/main/java/com/franciaflex/faxtomail/services/service/ConfigurationServiceImpl.java @@ -61,14 +61,9 @@ import com.franciaflex.faxtomail.persistence.entities.WaitingStateImpl; import com.franciaflex.faxtomail.persistence.entities.WaitingStateTopiaDao; import com.franciaflex.faxtomail.services.FaxToMailServiceSupport; import com.franciaflex.faxtomail.services.FaxToMailServiceUtils; -import com.google.common.base.Function; -import com.google.common.base.Optional; -import com.google.common.collect.Lists; -import com.google.common.collect.Maps; import org.apache.commons.lang3.StringUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.nuiton.topia.persistence.TopiaEntities; import org.nuiton.util.beans.Binder; import org.nuiton.util.beans.BinderFactory; @@ -84,6 +79,8 @@ import java.util.List; import java.util.Map; import java.util.Properties; import java.util.Set; +import java.util.function.Function; +import java.util.stream.Collectors; /** * @author kmorin - kmorin@codelutin.com @@ -93,12 +90,7 @@ public class ConfigurationServiceImpl extends FaxToMailServiceSupport implements private static final Log log = LogFactory.getLog(ConfigurationServiceImpl.class); - protected static final Function<MailFilter, String> GET_EXPRESSION = new Function<MailFilter, String>() { - @Override - public String apply(MailFilter input) { - return input == null ? null : input.getExpression(); - } - }; + protected static final Function<MailFilter, String> GET_EXPRESSION = input -> input == null ? null : input.getExpression(); /** * Return unique database configuration. @@ -123,8 +115,7 @@ public class ConfigurationServiceImpl extends FaxToMailServiceSupport implements @Override public List<MailFilter> getMailFilters() { MailFilterTopiaDao mailFilterDao = getPersistenceContext().getMailFilterDao(); - List<MailFilter> result = mailFilterDao.forAll().setOrderByArguments(MailFilter.PROPERTY_POSITION + " asc").findAll(); - return result; + return mailFilterDao.forAll().setOrderByArguments(MailFilter.PROPERTY_POSITION + " asc").findAll(); } /** @@ -189,7 +180,8 @@ public class ConfigurationServiceImpl extends FaxToMailServiceSupport implements DemandTypeTopiaDao demandTypeDAO = getPersistenceContext().getDemandTypeDao(); List<DemandType> allDemandType = demandTypeDAO.findAll(); - Map<String, DemandType> allDemandTypeIndex = new HashMap<>(Maps.uniqueIndex(allDemandType, TopiaEntities.getTopiaIdFunction())); + Map<String, DemandType> allDemandTypeIndex = allDemandType.stream() + .collect(Collectors.toMap(DemandType::getTopiaId, Function.identity())); for (DemandType demandType : demandTypes) { // get current etat attente DemandType currentDemandType; @@ -219,7 +211,8 @@ public class ConfigurationServiceImpl extends FaxToMailServiceSupport implements StampTopiaDao stampDao = getPersistenceContext().getStampDao(); List<Stamp> allStamps = stampDao.findAll(); - Map<String, Stamp> allStampsIndex = new HashMap<>(Maps.uniqueIndex(allStamps, TopiaEntities.getTopiaIdFunction())); + Map<String, Stamp> allStampsIndex = allStamps.stream() + .collect(Collectors.toMap(Stamp::getTopiaId, Function.identity())); for (Stamp stamp : stamps) { // get current etat attente Stamp currentStamp; @@ -259,7 +252,8 @@ public class ConfigurationServiceImpl extends FaxToMailServiceSupport implements WaitingStateTopiaDao waitingStateDAO = getPersistenceContext().getWaitingStateDao(); List<WaitingState> allWaitingStates = waitingStateDAO.findAll(); - Map<String, WaitingState> allWaitingStateIndex = new HashMap<>(Maps.uniqueIndex(allWaitingStates, TopiaEntities.getTopiaIdFunction())); + Map<String, WaitingState> allWaitingStateIndex = allWaitingStates.stream() + .collect(Collectors.toMap(WaitingState::getTopiaId, Function.identity())); for (WaitingState waitingState : waitingStates) { // get current etat attente WaitingState currentWaitingState; @@ -303,7 +297,8 @@ public class ConfigurationServiceImpl extends FaxToMailServiceSupport implements // get current folders MailFolderTopiaDao dao = getPersistenceContext().getMailFolderDao(); List<MailFolder> mailFolders = dao.findAll(); - Map<String, MailFolder> mailFolderMap = new HashMap<>(Maps.uniqueIndex(mailFolders, TopiaEntities.getTopiaIdFunction())); + Map<String, MailFolder> mailFolderMap = mailFolders.stream() + .collect(Collectors.toMap(MailFolder::getTopiaId, Function.identity())); // recursive update Map<String, MailFolder> mailFolderCache = new HashMap<>(); @@ -329,7 +324,7 @@ public class ConfigurationServiceImpl extends FaxToMailServiceSupport implements protected Collection<MailFolder> saveMailFolders(MailFolderTopiaDao dao, Map<String, WaitingState> waitingStateCache, Map<String, MailFolder> mailFolderMap, MailFolder parent, Collection<MailFolder> mailFolders, Map<String, MailFolder> mailFolderCache) { - Collection<MailFolder> result = Lists.newArrayList(); + Collection<MailFolder> result = new ArrayList<>(); if (mailFolders == null) { return result; } @@ -398,7 +393,8 @@ public class ConfigurationServiceImpl extends FaxToMailServiceSupport implements int position = 0; List<MailFilter> filters = dao.findAll(); // order by naturalId - Map<String, MailFilter> filterByExpression = new HashMap<>(Maps.uniqueIndex(filters, GET_EXPRESSION)); + Map<String, MailFilter> filterByExpression = filters.stream() + .collect(Collectors.toMap(GET_EXPRESSION, Function.identity())); for (MailFilter mailFilter : mailFilters) { MailFilter filter = filterByExpression.remove(mailFilter.getExpression().toLowerCase()); @@ -436,23 +432,18 @@ public class ConfigurationServiceImpl extends FaxToMailServiceSupport implements List<EmailAccount> accounts = getEmailAccounts(); // remove password information from bean final Binder<EmailAccount, EmailAccount> binderEmailAccount = BinderFactory.newBinder(EmailAccount.class); - List<EmailAccount> result = Lists.transform(accounts, new Function<EmailAccount, EmailAccount>() { - @Override - public EmailAccount apply(EmailAccount input) { - EmailAccount account = new EmailAccountImpl(); - binderEmailAccount.copyExcluding(input, account, EmailAccount.PROPERTY_PASSWORD); - return account; - } - }); - return result; + return accounts.stream().map(input -> { + EmailAccount account = new EmailAccountImpl(); + binderEmailAccount.copyExcluding(input, account, EmailAccount.PROPERTY_PASSWORD); + return account; + }).collect(Collectors.toList()); } @Override public List<EmailAccount> getEmailAccounts() { EmailAccountTopiaDao emailAccountTopiaDao = getPersistenceContext().getEmailAccountDao(); - List<EmailAccount> result = emailAccountTopiaDao.findAll(); - return result; + return emailAccountTopiaDao.findAll(); } /** @@ -463,7 +454,8 @@ public class ConfigurationServiceImpl extends FaxToMailServiceSupport implements protected void saveEmailAccounts(List<EmailAccount> newEmailAccounts) { EmailAccountTopiaDao emailAccountTopiaDao = getPersistenceContext().getEmailAccountDao(); List<EmailAccount> emailAccounts = emailAccountTopiaDao.findAll(); - Map<String, EmailAccount> emailAccountMap = new HashMap<>(Maps.uniqueIndex(emailAccounts, TopiaEntities.getTopiaIdFunction())); + Map<String, EmailAccount> emailAccountMap = emailAccounts.stream() + .collect(Collectors.toMap(EmailAccount::getTopiaId, Function.identity())); Binder<EmailAccount, EmailAccount> binder = BinderFactory.newBinder(EmailAccount.class); for (EmailAccount newEmailAccount : newEmailAccounts) { @@ -498,7 +490,8 @@ public class ConfigurationServiceImpl extends FaxToMailServiceSupport implements protected void saveBrandsForDomains(List<BrandsForDomain> newBrandsForDomains) { BrandsForDomainTopiaDao brandsForDomainTopiaDao = getPersistenceContext().getBrandsForDomainDao(); List<BrandsForDomain> brandsForDomains = brandsForDomainTopiaDao.findAll(); - Map<String, BrandsForDomain> brandsForDomainMap = new HashMap<>(Maps.uniqueIndex(brandsForDomains, TopiaEntities.getTopiaIdFunction())); + Map<String, BrandsForDomain> brandsForDomainMap = brandsForDomains.stream() + .collect(Collectors.toMap(BrandsForDomain::getTopiaId, Function.identity())); Binder<BrandsForDomain, BrandsForDomain> binder = BinderFactory.newBinder(BrandsForDomain.class); for (BrandsForDomain newBrandsForDomain : newBrandsForDomains) { @@ -529,7 +522,8 @@ public class ConfigurationServiceImpl extends FaxToMailServiceSupport implements SigningForDomainTopiaDao signingForDomainTopiaDao = getPersistenceContext().getSigningForDomainDao(); List<SigningForDomain> signingForDomains = signingForDomainTopiaDao.findAll(); - Map<String, SigningForDomain> signingsForDomainMap = new HashMap<>(Maps.uniqueIndex(signingForDomains, TopiaEntities.getTopiaIdFunction())); + Map<String, SigningForDomain> signingsForDomainMap = signingForDomains.stream() + .collect(Collectors.toMap(SigningForDomain::getTopiaId, Function.identity())); Binder<SigningForDomain, SigningForDomain> binder = BinderFactory.newBinder(SigningForDomain.class); for (SigningForDomain newSigningForDomain : newSigningForDomains) { @@ -579,8 +573,7 @@ public class ConfigurationServiceImpl extends FaxToMailServiceSupport implements @Override public ExtensionCommand getExtensionCommand(String extension) { ExtensionCommandTopiaDao extensionCommandDao = getPersistenceContext().getExtensionCommandDao(); - ExtensionCommand result = extensionCommandDao.findByExtension(extension); - return result; + return extensionCommandDao.findByExtension(extension); } /** @@ -744,8 +737,8 @@ public class ConfigurationServiceImpl extends FaxToMailServiceSupport implements } @Override - public Optional<SigningForDomain> getSigningForEmailAddress(String emailAddress) { + public SigningForDomain getSigningForEmailAddress(String emailAddress) { String domain = FaxToMailServiceUtils.getDomainForEmailAddress(emailAddress); - return getPersistenceContext().getSigningForDomainDao().forDomainNameEquals(domain).tryFindUnique(); + return getPersistenceContext().getSigningForDomainDao().forDomainNameEquals(domain).findUniqueOrNull(); } } diff --git a/faxtomail-service/src/main/java/com/franciaflex/faxtomail/services/service/EmailServiceImpl.java b/faxtomail-service/src/main/java/com/franciaflex/faxtomail/services/service/EmailServiceImpl.java index cc7c8b5..ddac7e3 100644 --- a/faxtomail-service/src/main/java/com/franciaflex/faxtomail/services/service/EmailServiceImpl.java +++ b/faxtomail-service/src/main/java/com/franciaflex/faxtomail/services/service/EmailServiceImpl.java @@ -81,16 +81,11 @@ import com.franciaflex.faxtomail.services.service.imports.InvalidArchiveImportBe import com.github.mustachejava.DefaultMustacheFactory; import com.github.mustachejava.Mustache; import com.github.mustachejava.MustacheFactory; -import com.google.common.base.Function; -import com.google.common.base.Optional; import com.google.common.base.Preconditions; import com.google.common.base.Splitter; import com.google.common.base.Strings; -import com.google.common.collect.Collections2; -import com.google.common.collect.Iterables; import com.google.common.collect.Maps; import com.google.common.collect.Sets; -import com.google.common.io.Files; import com.itextpdf.text.Document; import com.itextpdf.text.DocumentException; import com.itextpdf.text.Image; @@ -101,7 +96,6 @@ import com.itextpdf.text.pdf.PdfWriter; import gui.ava.html.Html2Image; import gui.ava.html.renderer.ImageRenderer; import org.apache.commons.collections4.CollectionUtils; -import org.apache.commons.collections4.Predicate; import org.apache.commons.io.FileUtils; import org.apache.commons.io.FilenameUtils; import org.apache.commons.io.IOUtils; @@ -128,7 +122,6 @@ import org.nuiton.topia.persistence.TopiaEntity; import org.nuiton.topia.persistence.TopiaQueryException; import org.nuiton.topia.persistence.support.TopiaHibernateSupport; import org.nuiton.topia.persistence.support.TopiaSqlSupport; -import org.nuiton.topia.persistence.support.TopiaSqlWork; import org.nuiton.util.FileUtil; import org.nuiton.util.StringUtil; import org.nuiton.util.beans.Binder; @@ -161,14 +154,12 @@ import java.io.UnsupportedEncodingException; import java.io.Writer; import java.nio.charset.Charset; import java.nio.charset.StandardCharsets; -import java.sql.Connection; +import java.nio.file.Files; import java.sql.ResultSet; -import java.sql.SQLException; import java.sql.Statement; import java.util.ArrayList; import java.util.Collection; import java.util.Collections; -import java.util.Comparator; import java.util.Date; import java.util.Enumeration; import java.util.HashMap; @@ -177,10 +168,13 @@ import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Map.Entry; +import java.util.Optional; import java.util.Set; import java.util.TreeMap; import java.util.UUID; +import java.util.function.Function; import java.util.regex.Pattern; +import java.util.stream.Collectors; import static org.nuiton.i18n.I18n.t; @@ -196,13 +190,11 @@ public class EmailServiceImpl extends FaxToMailServiceSupport implements EmailSe @Override public Email getEmailById(String id) { - Email email = getPersistenceContext().getEmailDao().forTopiaIdEquals(id).findUnique(); - return email; + return getPersistenceContext().getEmailDao().forTopiaIdEquals(id).findUnique(); } protected Email getEmailById(String id, String fetch, String... otherFetches) { - Email email = getPersistenceContext().getEmailDao().forTopiaIdEquals(id).addAllFetches(fetch, otherFetches).findUnique(); - return email; + return getPersistenceContext().getEmailDao().forTopiaIdEquals(id).addAllFetches(fetch, otherFetches).findUnique(); } @Override @@ -366,12 +358,7 @@ public class EmailServiceImpl extends FaxToMailServiceSupport implements EmailSe Set<String> fieldSet = Sets.newHashSet(modifiedFields); - History transmissionToEdi = CollectionUtils.find(histories, new Predicate<History>() { - @Override - public boolean evaluate(History object) { - return object.getType() == HistoryType.TRANSMISSION_TO_EDI; - } - }); + History transmissionToEdi = CollectionUtils.find(histories, object -> object.getType() == HistoryType.TRANSMISSION_TO_EDI); // we transmit to EDI if: // - it has never been transmitted before @@ -385,12 +372,9 @@ public class EmailServiceImpl extends FaxToMailServiceSupport implements EmailSe } if (histories != null) { - historyDao.createAll(Collections2.filter(histories, new com.google.common.base.Predicate<History>() { - @Override - public boolean apply(History history) { - return !history.isPersisted(); - } - })); + historyDao.createAll(histories.stream() + .filter(history -> !history.isPersisted()) + .collect(Collectors.toList())); } History history = null; @@ -441,7 +425,7 @@ public class EmailServiceImpl extends FaxToMailServiceSupport implements EmailSe protected void updateReplies(Email email) { ReplyTopiaDao replyTopiaDao = getPersistenceContext().getReplyDao(); - List<Reply> currentReplies = new ArrayList<Reply>(email.getReplies()); + List<Reply> currentReplies = new ArrayList<>(email.getReplies()); email.clearReplies(); for (Reply reply : currentReplies) { // normalement elle sont toutes persistée et non modifiées par l'ui @@ -467,8 +451,8 @@ public class EmailServiceImpl extends FaxToMailServiceSupport implements EmailSe if (currentAttachments == null) { currentAttachments = new ArrayList<>(); } - Map<String, Attachment> currentAttachmentIndex = new HashMap<>(Maps.uniqueIndex(currentAttachments, - TopiaEntities.getTopiaIdFunction())); + Map<String, Attachment> currentAttachmentIndex = currentAttachments.stream() + .collect(Collectors.toMap(TopiaEntity::getTopiaId, Function.identity())); Set<String> newFiles = new HashSet<>(); @@ -821,12 +805,7 @@ public class EmailServiceImpl extends FaxToMailServiceSupport implements EmailSe // convert topiaId to entities RangeTopiaDao rangeDao = getPersistenceContext().getRangeDao(); - Map<Range, Long[]> result = new TreeMap<Range, Long[]>(new Comparator<Range>() { - @Override - public int compare(Range o1, Range o2) { - return o1.getLabel().compareTo(o2.getLabel()); - } - }); + Map<Range, Long[]> result = new TreeMap<>((o1, o2) -> o1.getLabel().compareTo(o2.getLabel())); for (Entry<String, Long[]> entry : daoResult.entrySet()) { Range range = rangeDao.forTopiaIdEquals(entry.getKey()).findUnique(); result.put(range, entry.getValue()); @@ -1011,7 +990,7 @@ public class EmailServiceImpl extends FaxToMailServiceSupport implements EmailSe // compute rigths MailFolderTopiaDao mailFolderDao = getPersistenceContext().getMailFolderDao(); - Set<MailFolder> readMailFolders = new HashSet<MailFolder>(); + Set<MailFolder> readMailFolders = new HashSet<>(); // read rights for user Iterable<MailFolder> mailFolders = mailFolderDao.forReadRightUsersContains(user).findAll(); computeUserReadableFolder(readMailFolders, mailFolders); @@ -1025,8 +1004,7 @@ public class EmailServiceImpl extends FaxToMailServiceSupport implements EmailSe // compute search EmailTopiaDao emailDao = getPersistenceContext().getEmailDao(); - PaginationResult<Email> result = emailDao.search(emailFilter, readMailFolders, pagination); - return result; + return emailDao.search(emailFilter, readMailFolders, pagination); } @Override @@ -1300,8 +1278,7 @@ public class EmailServiceImpl extends FaxToMailServiceSupport implements EmailSe @Override public List<MailLock> getAllMailLocks() { MailLockTopiaDao mailLockDao = getPersistenceContext().getMailLockDao(); - List<MailLock> result = mailLockDao.findAll(); - return result; + return mailLockDao.findAll(); } /** @@ -1352,108 +1329,99 @@ public class EmailServiceImpl extends FaxToMailServiceSupport implements EmailSe final Set<Email> emailsToUpdate = new HashSet<>(); TopiaSqlSupport sqlSupport = getPersistenceContext().getSqlSupport(); - sqlSupport.doSqlWork(new TopiaSqlWork() { - - @Override - public void execute(Connection connection) throws SQLException { - - int importedCount = 0; - List<String> rangeRowTopiaIdsInEdiReturnToDelete = new ArrayList<String>(); - - // attention, le sql à pour cible postgresql, mssql, h2, il doit rester simple - String query = String.format("SELECT %s, %s, %s FROM %s", - EdiReturn.PROPERTY_RANGE_ROW_TOPIA_ID, - EdiReturn.PROPERTY_COMMAND_NUMBER, - EdiReturn.PROPERTY_ERROR, - EdiReturn.class.getSimpleName()); - Statement stat = connection.createStatement(); - - // execute query - ResultSet resultSet = stat.executeQuery(query); - while (resultSet.next()) { - - String rangeRowTopiaId = resultSet.getString(EdiReturn.PROPERTY_RANGE_ROW_TOPIA_ID); - String commandNumber = resultSet.getString(EdiReturn.PROPERTY_COMMAND_NUMBER); - String error = resultSet.getString(EdiReturn.PROPERTY_ERROR); - - // manage email and range row - RangeRow rangeRow = rangeRowTopiaDao.forTopiaIdEquals(rangeRowTopiaId).findUniqueOrNull(); - if (rangeRow == null) { - if (log.isErrorEnabled()) { - log.error("Can't find rangeRow " + rangeRowTopiaId + " to update"); - } - continue; + sqlSupport.doSqlWork(connection -> { + + int importedCount = 0; + List<String> rangeRowTopiaIdsInEdiReturnToDelete = new ArrayList<>(); + + // attention, le sql à pour cible postgresql, mssql, h2, il doit rester simple + String query = String.format("SELECT %s, %s, %s FROM %s", + EdiReturn.PROPERTY_RANGE_ROW_TOPIA_ID, + EdiReturn.PROPERTY_COMMAND_NUMBER, + EdiReturn.PROPERTY_ERROR, + EdiReturn.class.getSimpleName()); + Statement stat = connection.createStatement(); + + // execute query + ResultSet resultSet = stat.executeQuery(query); + while (resultSet.next()) { + + String rangeRowTopiaId = resultSet.getString(EdiReturn.PROPERTY_RANGE_ROW_TOPIA_ID); + String commandNumber = resultSet.getString(EdiReturn.PROPERTY_COMMAND_NUMBER); + String error = resultSet.getString(EdiReturn.PROPERTY_ERROR); + + // manage email and range row + RangeRow rangeRow = rangeRowTopiaDao.forTopiaIdEquals(rangeRowTopiaId).findUniqueOrNull(); + if (rangeRow == null) { + if (log.isErrorEnabled()) { + log.error("Can't find rangeRow " + rangeRowTopiaId + " to update"); } - Email email = emailTopiaDao.forRangeRowContains(rangeRow).findUniqueOrNull(); - if (email == null) { - if (log.isErrorEnabled()) { - log.error("Can't find email for " + rangeRowTopiaId + " to update"); - } - continue; + continue; + } + Email email = emailTopiaDao.forRangeRowContains(rangeRow).findUniqueOrNull(); + if (email == null) { + if (log.isErrorEnabled()) { + log.error("Can't find email for " + rangeRowTopiaId + " to update"); } + continue; + } - rangeRowTopiaIdsInEdiReturnToDelete.add(rangeRowTopiaId); - - Set<String> modifiedFields = new HashSet<>(); + rangeRowTopiaIdsInEdiReturnToDelete.add(rangeRowTopiaId); - if (StringUtils.isNotBlank(error)) { - //error - String oldError = email.getEdiError(); - if (StringUtils.isNotBlank(oldError)) { - error = oldError + ", " + error; - } - email.setEdiError(error); - modifiedFields.add(Email.PROPERTY_EDI_ERROR); + Set<String> modifiedFields = new HashSet<>(); - } else { - rangeRow.setCommandNumber(commandNumber); - rangeRowTopiaDao.update(rangeRow); - modifiedFields.add(Email.PROPERTY_RANGE_ROW); + if (StringUtils.isNotBlank(error)) { + //error + String oldError = email.getEdiError(); + if (StringUtils.isNotBlank(oldError)) { + error = oldError + ", " + error; } + email.setEdiError(error); + modifiedFields.add(Email.PROPERTY_EDI_ERROR); - History transmission = CollectionUtils.find(email.getHistory(), new Predicate<History>() { - @Override - public boolean evaluate(History object) { - return object.getType() == HistoryType.TRANSMISSION; - } - }); + } else { + rangeRow.setCommandNumber(commandNumber); + rangeRowTopiaDao.update(rangeRow); + modifiedFields.add(Email.PROPERTY_RANGE_ROW); + } - if (transmission != null) { - email.setDemandStatus(DemandStatus.QUALIFIED); + History transmission = CollectionUtils.find(email.getHistory(), object -> object.getType() == HistoryType.TRANSMISSION); - } else { - email.setDemandStatus(DemandStatus.IN_PROGRESS); - } - modifiedFields.add(Email.PROPERTY_DEMAND_STATUS); + if (transmission != null) { + email.setDemandStatus(DemandStatus.QUALIFIED); - History history = historyDao.create(History.PROPERTY_TYPE, HistoryType.MODIFICATION, - History.PROPERTY_MODIFICATION_DATE, new Date(), - History.PROPERTY_EMAIL, email, - History.PROPERTY_FIELDS_JSON, AbstractFaxToMailTopiaDao.GSON_INSTANCE.toJson(modifiedFields)); + } else { + email.setDemandStatus(DemandStatus.IN_PROGRESS); + } + modifiedFields.add(Email.PROPERTY_DEMAND_STATUS); - email.addHistory(history); + History history = historyDao.create(History.PROPERTY_TYPE, HistoryType.MODIFICATION, + History.PROPERTY_MODIFICATION_DATE, new Date(), + History.PROPERTY_EMAIL, email, + History.PROPERTY_FIELDS_JSON, AbstractFaxToMailTopiaDao.GSON_INSTANCE.toJson(modifiedFields)); - history = historyDao.create(History.PROPERTY_TYPE, HistoryType.EDI_RETURN, - History.PROPERTY_MODIFICATION_DATE, new Date(), - History.PROPERTY_EMAIL, email); + email.addHistory(history); - email.addHistory(history); + history = historyDao.create(History.PROPERTY_TYPE, HistoryType.EDI_RETURN, + History.PROPERTY_MODIFICATION_DATE, new Date(), + History.PROPERTY_EMAIL, email); - emailsToUpdate.add(email); - - importedCount++; - } - - // delete all rows - stat = connection.createStatement(); - stat.execute("DELETE FROM " + EdiReturn.class.getSimpleName() + - " WHERE " + EdiReturn.PROPERTY_RANGE_ROW_TOPIA_ID + - " IN ('" + StringUtils.join(rangeRowTopiaIdsInEdiReturnToDelete, "','") + "')"); - - // usefull log info (do not remove) - if (importedCount > 0 && log.isInfoEnabled()) { - log.info(String.format("Imported %d ediReturn rows", importedCount)); - } + email.addHistory(history); + + emailsToUpdate.add(email); + + importedCount++; + } + + // delete all rows + stat = connection.createStatement(); + stat.execute("DELETE FROM " + EdiReturn.class.getSimpleName() + + " WHERE " + EdiReturn.PROPERTY_RANGE_ROW_TOPIA_ID + + " IN ('" + StringUtils.join(rangeRowTopiaIdsInEdiReturnToDelete, "','") + "')"); + + // usefull log info (do not remove) + if (importedCount > 0 && log.isInfoEnabled()) { + log.info(String.format("Imported %d ediReturn rows", importedCount)); } }); @@ -1517,7 +1485,7 @@ public class EmailServiceImpl extends FaxToMailServiceSupport implements EmailSe protected String getEmailDetailAsHtml(Email email) { Decorator<FaxToMailUser> userDecorator = getDecoratorService().getDecoratorByType(FaxToMailUser.class); - Map<String, Object> scopes = new HashMap<String, Object>(); + Map<String, Object> scopes = new HashMap<>(); scopes.put("title", email.getTitle()); scopes.put("receivedDate", DateFormatUtils.format(email.getReceptionDate(), "dd/MM/yyyy HH:mm")); @@ -1589,32 +1557,12 @@ public class EmailServiceImpl extends FaxToMailServiceSupport implements EmailSe } // get referentiel map - Map<String, DemandType> allDemandTypes = Maps.uniqueIndex(demandTypedao, new Function<DemandType, String>() { - @Override - public String apply(DemandType input) { - return input.getLabel(); - } - }); - Map<String, Priority> allPriority = Maps.uniqueIndex(priorityDao, new Function<Priority, String>() { - @Override - public String apply(Priority input) { - return input.getLabel(); - } - }); - Map<String, WaitingState> allWaitingStates = Maps.uniqueIndex(waitingStateDao, new Function<WaitingState, String>() { - @Override - public String apply(WaitingState input) { - return input.getLabel(); - } - }); + Map<String, DemandType> allDemandTypes = Maps.uniqueIndex(demandTypedao, DemandType::getLabel); + Map<String, Priority> allPriority = Maps.uniqueIndex(priorityDao, Priority::getLabel); + Map<String, WaitingState> allWaitingStates = Maps.uniqueIndex(waitingStateDao, WaitingState::getLabel); // build folder map - Map<String, MailFolder> mailFolderMap = Maps.uniqueIndex(mailFolderDao, new Function<MailFolder, String>() { - @Override - public String apply(MailFolder input) { - return FaxToMailServiceUtils.getFullMailFolderPath(input); - } - }); + Map<String, MailFolder> mailFolderMap = Maps.uniqueIndex(mailFolderDao, FaxToMailServiceUtils::getFullMailFolderPath); // run import ArchiveImportExportModel archiveImportExportModel = new ArchiveImportExportModel(';', allWaitingStates, allDemandTypes, allPriority); @@ -1666,12 +1614,9 @@ public class EmailServiceImpl extends FaxToMailServiceSupport implements EmailSe if (!archiveFoldersByFolder.containsKey(folder)) { do { if (archiveChild == null && folder.getChildren() != null) { - Optional<MailFolder> optArchiveChild = Iterables.tryFind(folder.getChildren(), new com.google.common.base.Predicate<MailFolder>() { - @Override - public boolean apply(MailFolder mailFolder) { - return mailFolder.isArchiveFolder(); - } - }); + Optional<MailFolder> optArchiveChild = folder.getChildren().stream() + .filter(MailFolder::isArchiveFolder) + .findAny(); if (optArchiveChild.isPresent()) { archiveChild = optArchiveChild.get(); } @@ -1873,8 +1818,7 @@ public class EmailServiceImpl extends FaxToMailServiceSupport implements EmailSe @Override public long getArchivedMailCount() { EmailTopiaDao emailDao = getPersistenceContext().getEmailDao(); - long result = emailDao.forDemandStatusEquals(DemandStatus.ARCHIVED).count(); - return result; + return emailDao.forDemandStatusEquals(DemandStatus.ARCHIVED).count(); } @Override @@ -2011,8 +1955,7 @@ public class EmailServiceImpl extends FaxToMailServiceSupport implements EmailSe @Override public List<Attachment> extractAttachmentsFromMessage(MimeMessage message) throws Exception { - List<Attachment> attachments = extractAttachmentsFromMessage(message, 0); - return attachments; + return extractAttachmentsFromMessage(message, 0); } protected List<Attachment> extractAttachmentsFromMessage(MimeMessage message, int decomposingForwardedEmail) throws Exception { @@ -2129,7 +2072,7 @@ public class EmailServiceImpl extends FaxToMailServiceSupport implements EmailSe // get process command String command = extensionCommand.getConvertToPdfCommand(); String[] args = StringUtil.split(command, " "); - List<String> comArgs = new ArrayList<String>(); + List<String> comArgs = new ArrayList<>(); for (String arg : args) { String localArg = arg; localArg = localArg.replace("%f", file.getAbsolutePath()); @@ -2204,7 +2147,7 @@ public class EmailServiceImpl extends FaxToMailServiceSupport implements EmailSe File tempFile = File.createTempFile(name, ".pdf"); tempFile.createNewFile(); - Files.write(attachmentFileNew.getContent(), tempFile); + FileUtils.writeByteArrayToFile(tempFile, attachmentFileNew.getContent()); return attachment; } @@ -2213,11 +2156,11 @@ public class EmailServiceImpl extends FaxToMailServiceSupport implements EmailSe public Attachment convertHTMLToPdf(List<Attachment> attachments, List<String> contentList, String name) throws IOException { Attachment result = null; ByteArrayOutputStream os = new ByteArrayOutputStream(); - Collection<File> fileToDelete = new ArrayList<File>(); + Collection<File> fileToDelete = new ArrayList<>(); try { - List<String> contents = new ArrayList<String>(); + List<String> contents = new ArrayList<>(); if (contentList != null) { for (String content : contentList) { diff --git a/faxtomail-service/src/main/java/com/franciaflex/faxtomail/services/service/InitFaxToMailServiceImpl.java b/faxtomail-service/src/main/java/com/franciaflex/faxtomail/services/service/InitFaxToMailServiceImpl.java index 458a782..74c8e35 100644 --- a/faxtomail-service/src/main/java/com/franciaflex/faxtomail/services/service/InitFaxToMailServiceImpl.java +++ b/faxtomail-service/src/main/java/com/franciaflex/faxtomail/services/service/InitFaxToMailServiceImpl.java @@ -24,12 +24,36 @@ package com.franciaflex.faxtomail.services.service; * #L% */ -import com.franciaflex.faxtomail.persistence.entities.*; +import com.franciaflex.faxtomail.persistence.entities.Client; +import com.franciaflex.faxtomail.persistence.entities.DemandStatus; +import com.franciaflex.faxtomail.persistence.entities.DemandType; +import com.franciaflex.faxtomail.persistence.entities.DemandTypeTopiaDao; +import com.franciaflex.faxtomail.persistence.entities.Email; +import com.franciaflex.faxtomail.persistence.entities.EmailTopiaDao; +import com.franciaflex.faxtomail.persistence.entities.FaxToMailUser; +import com.franciaflex.faxtomail.persistence.entities.FaxToMailUserGroup; +import com.franciaflex.faxtomail.persistence.entities.FaxToMailUserGroupTopiaDao; +import com.franciaflex.faxtomail.persistence.entities.FaxToMailUserTopiaDao; +import com.franciaflex.faxtomail.persistence.entities.History; +import com.franciaflex.faxtomail.persistence.entities.HistoryTopiaDao; +import com.franciaflex.faxtomail.persistence.entities.HistoryType; +import com.franciaflex.faxtomail.persistence.entities.MailField; +import com.franciaflex.faxtomail.persistence.entities.MailFolder; +import com.franciaflex.faxtomail.persistence.entities.MailFolderTopiaDao; +import com.franciaflex.faxtomail.persistence.entities.OriginalEmail; +import com.franciaflex.faxtomail.persistence.entities.OriginalEmailTopiaDao; +import com.franciaflex.faxtomail.persistence.entities.Priority; +import com.franciaflex.faxtomail.persistence.entities.PriorityTopiaDao; +import com.franciaflex.faxtomail.persistence.entities.Range; +import com.franciaflex.faxtomail.persistence.entities.RangeRow; +import com.franciaflex.faxtomail.persistence.entities.RangeRowTopiaDao; +import com.franciaflex.faxtomail.persistence.entities.RangeTopiaDao; +import com.franciaflex.faxtomail.persistence.entities.WaitingState; +import com.franciaflex.faxtomail.persistence.entities.WaitingStateTopiaDao; import com.franciaflex.faxtomail.services.DecoratorService; import com.franciaflex.faxtomail.services.FaxToMailServiceSupport; import com.franciaflex.faxtomail.services.FaxToMailServiceUtils; import com.franciaflex.faxtomail.services.service.exceptions.InvalidClientException; -import com.google.common.collect.Lists; import com.google.common.collect.Sets; import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.lang3.RandomStringUtils; @@ -41,6 +65,7 @@ import java.io.File; import java.io.FileInputStream; import java.io.InputStream; import java.util.ArrayList; +import java.util.Arrays; import java.util.Calendar; import java.util.Collections; import java.util.Date; @@ -87,9 +112,9 @@ public class InitFaxToMailServiceImpl extends FaxToMailServiceSupport implements if (count == 0) { - List<DemandType> types = Lists.newArrayList( + List<DemandType> types = Arrays.asList( demandTypeDao.create(DemandType.PROPERTY_LABEL, "Commande", - DemandType.PROPERTY_REQUIRED_FIELDS, EnumSet.of(MailField.RANGE_ROW)), + DemandType.PROPERTY_REQUIRED_FIELDS, EnumSet.of(MailField.RANGE_ROW)), demandTypeDao.create(DemandType.PROPERTY_LABEL, "Commande Réponse"), demandTypeDao.create(DemandType.PROPERTY_LABEL, "Commande Annulation/Modification"), demandTypeDao.create(DemandType.PROPERTY_LABEL, "Devis Diffus"), @@ -101,7 +126,7 @@ public class InitFaxToMailServiceImpl extends FaxToMailServiceSupport implements ); WaitingStateTopiaDao waitingStateDao = getPersistenceContext().getWaitingStateDao(); - List<WaitingState> waitingStates = Lists.newArrayList( + List<WaitingState> waitingStates = Arrays.asList( waitingStateDao.create(WaitingState.PROPERTY_LABEL, "BAT attente retour BAT lettrage-logo"), waitingStateDao.create(WaitingState.PROPERTY_LABEL, "CLT attente réponse client"), waitingStateDao.create(WaitingState.PROPERTY_LABEL, "DAC attente pour assistance chantier"), @@ -120,13 +145,13 @@ public class InitFaxToMailServiceImpl extends FaxToMailServiceSupport implements ); PriorityTopiaDao priorityDao = getPersistenceContext().getPriorityDao(); - List<Priority> priorities = Lists.newArrayList( + List<Priority> priorities = Arrays.asList( priorityDao.create(Priority.PROPERTY_LABEL, "!"), priorityDao.create(Priority.PROPERTY_LABEL, "F") ); RangeTopiaDao rangeDao = getPersistenceContext().getRangeDao(); - List<Range> ranges = Lists.newArrayList( + List<Range> ranges = Arrays.asList( rangeDao.create(Range.PROPERTY_LABEL, "FFE VR"), rangeDao.create(Range.PROPERTY_LABEL, "FFE AUTRE"), rangeDao.create(Range.PROPERTY_LABEL, "FME FX DROIT"), @@ -206,7 +231,7 @@ public class InitFaxToMailServiceImpl extends FaxToMailServiceSupport implements // categories MailFolder chargesClientelle = folderDao.create(MailFolder.PROPERTY_NAME, "Chargés de clientèle", MailFolder.PROPERTY_PARENT, franciaflex, - MailFolder.PROPERTY_REPLY_ADDRESSES, Lists.newArrayList("no-reply@franciaflex.com")); + MailFolder.PROPERTY_REPLY_ADDRESSES, Arrays.asList("no-reply@franciaflex.com")); franciaflex.addChildren(chargesClientelle); folders.put("Chargés de clientèle", chargesClientelle); @@ -284,16 +309,14 @@ public class InitFaxToMailServiceImpl extends FaxToMailServiceSupport implements File clientFile = new File(demoDirectory, "fx_clients.csv"); try { InputStream fxClientsStream = new FileInputStream(clientFile); - if (fxClientsStream != null) { - List<Client> clients = getReferentielService().importClients(fxClientsStream); - - createEmails(random, historyDao, rangeRowDao, emailDao, originalEmailDao, ranges, clients, types, priorities, cyrilFolder, cyril); - createEmails(random, historyDao, rangeRowDao, emailDao, originalEmailDao, ranges, clients, types, priorities, claireFolder, claire); - createEmails(random, historyDao, rangeRowDao, emailDao, originalEmailDao, ranges, clients, types, priorities, agatheFolder, agathe); - createEmails(random, historyDao, rangeRowDao, emailDao, originalEmailDao, ranges, clients, types, priorities, marcFolder, marc); - createEmails(random, historyDao, rangeRowDao, emailDao, originalEmailDao, ranges, clients, types, priorities, fredericFolder, frederic); - createEmails(random, historyDao, rangeRowDao, emailDao, originalEmailDao, ranges, clients, types, priorities, jeanneFolder, jeanne); - } + List<Client> clients = getReferentielService().importClients(fxClientsStream); + + createEmails(random, historyDao, rangeRowDao, emailDao, originalEmailDao, ranges, clients, types, priorities, cyrilFolder, cyril); + createEmails(random, historyDao, rangeRowDao, emailDao, originalEmailDao, ranges, clients, types, priorities, claireFolder, claire); + createEmails(random, historyDao, rangeRowDao, emailDao, originalEmailDao, ranges, clients, types, priorities, agatheFolder, agathe); + createEmails(random, historyDao, rangeRowDao, emailDao, originalEmailDao, ranges, clients, types, priorities, marcFolder, marc); + createEmails(random, historyDao, rangeRowDao, emailDao, originalEmailDao, ranges, clients, types, priorities, fredericFolder, frederic); + createEmails(random, historyDao, rangeRowDao, emailDao, originalEmailDao, ranges, clients, types, priorities, jeanneFolder, jeanne); } catch(Exception e) { log.error("error getting the client file", e); @@ -368,7 +391,7 @@ public class InitFaxToMailServiceImpl extends FaxToMailServiceSupport implements Email.PROPERTY_RECEPTION_DATE, now, Email.PROPERTY_MAIL_FOLDER, folder, Email.PROPERTY_DEMAND_STATUS, opened ? DemandStatus.IN_PROGRESS : DemandStatus.UNTREATED, - Email.PROPERTY_HISTORY, Lists.newArrayList(history), + Email.PROPERTY_HISTORY, Arrays.asList(history), Email.PROPERTY_ORIGINAL_EMAIL, originalEmailDao.create(OriginalEmail.PROPERTY_CONTENT, "Demo data")); @@ -416,7 +439,7 @@ public class InitFaxToMailServiceImpl extends FaxToMailServiceSupport implements Email.PROPERTY_RECEPTION_DATE, yesterday, Email.PROPERTY_MAIL_FOLDER, folder, Email.PROPERTY_DEMAND_STATUS, opened ? DemandStatus.IN_PROGRESS : DemandStatus.UNTREATED, - Email.PROPERTY_HISTORY, Lists.newArrayList(history), + Email.PROPERTY_HISTORY, Arrays.asList(history), Email.PROPERTY_ORIGINAL_EMAIL, originalEmailDao.create(OriginalEmail.PROPERTY_CONTENT, "Demo data")); diff --git a/faxtomail-service/src/main/java/com/franciaflex/faxtomail/services/service/MailFolderServiceImpl.java b/faxtomail-service/src/main/java/com/franciaflex/faxtomail/services/service/MailFolderServiceImpl.java index 6f1f27e..6075f72 100644 --- a/faxtomail-service/src/main/java/com/franciaflex/faxtomail/services/service/MailFolderServiceImpl.java +++ b/faxtomail-service/src/main/java/com/franciaflex/faxtomail/services/service/MailFolderServiceImpl.java @@ -81,8 +81,7 @@ public class MailFolderServiceImpl extends FaxToMailServiceSupport implements Ma Map<String, Object> params = new HashMap<>(); params.put("recipient", recipient); - List<MailFilter> filters = filterTopiaDao.find(query, params, tpb); - return filters; + return filterTopiaDao.find(query, params, tpb); } @Override @@ -94,8 +93,7 @@ public class MailFolderServiceImpl extends FaxToMailServiceSupport implements Ma @Override public List<MailFolder> getRootMailFolders() { MailFolderTopiaDao dao = getPersistenceContext().getMailFolderDao(); - List<MailFolder> result = dao.forParentEquals(null).findAll(); - return result; + return dao.forParentEquals(null).findAll(); } @Override @@ -244,7 +242,7 @@ public class MailFolderServiceImpl extends FaxToMailServiceSupport implements Ma @Override public List<MailFolder> getMailFolders(Collection<String> ids) { MailFolderTopiaDao dao = getPersistenceContext().getMailFolderDao(); - return new ArrayList<MailFolder>(dao.forTopiaIdIn(ids).findAll()); + return new ArrayList<>(dao.forTopiaIdIn(ids).findAll()); } /** @@ -258,7 +256,7 @@ public class MailFolderServiceImpl extends FaxToMailServiceSupport implements Ma List<MailFolder> roots = dao.forParentEquals(null).findAll(); for (MailFolder root : roots) { - Collection<MailFolder> mailFolders = getFoldersWithWaitingState(root, new HashSet<WaitingState>(), requiredWaitingStates); + Collection<MailFolder> mailFolders = getFoldersWithWaitingState(root, new HashSet<>(), requiredWaitingStates); result.addAll(mailFolders); } @@ -308,22 +306,19 @@ public class MailFolderServiceImpl extends FaxToMailServiceSupport implements Ma @Override public Map<String, Long> getMailFoldersUsage() { EmailTopiaDao dao = getPersistenceContext().getEmailDao(); - Map<String, Long> result = dao.getMailCountByFolder(); - return result; + return dao.getMailCountByFolder(); } @Override public MailFolder getFolderForFaxToMailUser(FaxToMailUser customerResponsible) { MailFolderTopiaDao dao = getPersistenceContext().getMailFolderDao(); - MailFolder result = dao.forCustomerResponsiblesContains(customerResponsible).findAnyOrNull(); - return result; + return dao.forCustomerResponsiblesContains(customerResponsible).findAnyOrNull(); } @Override public MailFolder getMailFolder(String topiaId) { MailFolderTopiaDao dao = getPersistenceContext().getMailFolderDao(); - MailFolder result = dao.forTopiaIdEquals(topiaId).findUnique(); - return result; + return dao.forTopiaIdEquals(topiaId).findUnique(); } @Override diff --git a/faxtomail-service/src/main/java/com/franciaflex/faxtomail/services/service/ReferentielServiceImpl.java b/faxtomail-service/src/main/java/com/franciaflex/faxtomail/services/service/ReferentielServiceImpl.java index 076deaf..e31d9f1 100644 --- a/faxtomail-service/src/main/java/com/franciaflex/faxtomail/services/service/ReferentielServiceImpl.java +++ b/faxtomail-service/src/main/java/com/franciaflex/faxtomail/services/service/ReferentielServiceImpl.java @@ -112,8 +112,7 @@ public class ReferentielServiceImpl extends FaxToMailServiceSupport implements R @Override public Map<String, Long> getWaitingStatesUsage() { WaitingStateTopiaDao dao = getPersistenceContext().getWaitingStateDao(); - Map<String, Long> result = dao.getWaitingStateCountByFolder(); - return result; + return dao.getWaitingStateCountByFolder(); } @Override @@ -154,7 +153,7 @@ public class ReferentielServiceImpl extends FaxToMailServiceSupport implements R if (StringUtils.isNotBlank(client.getEmailAddress())) { List<String> currentAddresses = current.getEmailAddresses(); if (currentAddresses == null) { - currentAddresses = new ArrayList<String>(); + currentAddresses = new ArrayList<>(); } currentAddresses.add(client.getEmailAddress()); current.setEmailAddresses(currentAddresses); @@ -162,7 +161,7 @@ public class ReferentielServiceImpl extends FaxToMailServiceSupport implements R if (StringUtils.isNotBlank(client.getFaxNumber())) { List<String> faxNumbers = current.getFaxNumbers(); if (faxNumbers == null) { - faxNumbers = new ArrayList<String>(); + faxNumbers = new ArrayList<>(); } faxNumbers.add(client.getFaxNumber()); current.setFaxNumbers(faxNumbers); diff --git a/faxtomail-service/src/main/java/com/franciaflex/faxtomail/services/service/UserServiceImpl.java b/faxtomail-service/src/main/java/com/franciaflex/faxtomail/services/service/UserServiceImpl.java index dc7fb43..3082980 100644 --- a/faxtomail-service/src/main/java/com/franciaflex/faxtomail/services/service/UserServiceImpl.java +++ b/faxtomail-service/src/main/java/com/franciaflex/faxtomail/services/service/UserServiceImpl.java @@ -31,11 +31,11 @@ import com.franciaflex.faxtomail.persistence.entities.FaxToMailUserTopiaDao; import com.franciaflex.faxtomail.persistence.entities.Stamp; import com.franciaflex.faxtomail.persistence.entities.StampTopiaDao; import com.franciaflex.faxtomail.services.FaxToMailServiceSupport; -import com.google.common.base.Preconditions; import org.hibernate.Hibernate; import java.util.Collection; import java.util.List; +import java.util.Objects; /** * @author kmorin - kmorin@codelutin.com @@ -50,8 +50,7 @@ public class UserServiceImpl extends FaxToMailServiceSupport implements UserServ @Override public long getActiveUserCount() { FaxToMailUserTopiaDao faxtomailUserDao = getPersistenceContext().getFaxToMailUserDao(); - long result = faxtomailUserDao.forHiddenEquals(false).count(); - return result; + return faxtomailUserDao.forHiddenEquals(false).count(); } /** @@ -62,8 +61,7 @@ public class UserServiceImpl extends FaxToMailServiceSupport implements UserServ @Override public long getActiveGroupCount() { FaxToMailUserGroupTopiaDao faxtomailUserGroupDao = getPersistenceContext().getFaxToMailUserGroupDao(); - long result = faxtomailUserGroupDao.forHiddenEquals(false).count(); - return result; + return faxtomailUserGroupDao.forHiddenEquals(false).count(); } @Override @@ -75,9 +73,8 @@ public class UserServiceImpl extends FaxToMailServiceSupport implements UserServ @Override public FaxToMailUser getUserByLogin(String login) { FaxToMailUserTopiaDao dao = getPersistenceContext().getFaxToMailUserDao(); - FaxToMailUser user = dao.forLoginEquals(login) + return dao.forLoginEquals(login) .findUnique(); - return user; } @Override @@ -98,11 +95,10 @@ public class UserServiceImpl extends FaxToMailServiceSupport implements UserServ @Override public Collection<Stamp> getPdfEditorStamps(FaxToMailUser user) { - Preconditions.checkNotNull(user); + Objects.requireNonNull(user); StampTopiaDao stampDao = getPersistenceContext().getStampDao(); - Collection<Stamp> result = stampDao.findAllForUser(user); - return result; + return stampDao.findAllForUser(user); } } diff --git a/faxtomail-service/src/main/java/com/franciaflex/faxtomail/services/service/ValidationServiceImpl.java b/faxtomail-service/src/main/java/com/franciaflex/faxtomail/services/service/ValidationServiceImpl.java index 2055561..79ba3b6 100644 --- a/faxtomail-service/src/main/java/com/franciaflex/faxtomail/services/service/ValidationServiceImpl.java +++ b/faxtomail-service/src/main/java/com/franciaflex/faxtomail/services/service/ValidationServiceImpl.java @@ -40,8 +40,7 @@ public class ValidationServiceImpl extends FaxToMailServiceSupport implements Va @Override public NuitonValidatorResult validateEmail(Email email) { NuitonValidator<Email> validator = NuitonValidatorFactory.newValidator(Email.class); - NuitonValidatorResult result = validator.validate(email); - return result; + return validator.validate(email); } } diff --git a/faxtomail-service/src/main/java/com/franciaflex/faxtomail/services/service/imports/ClientImportModel.java b/faxtomail-service/src/main/java/com/franciaflex/faxtomail/services/service/imports/ClientImportModel.java index 695b82c..a4f65eb 100644 --- a/faxtomail-service/src/main/java/com/franciaflex/faxtomail/services/service/imports/ClientImportModel.java +++ b/faxtomail-service/src/main/java/com/franciaflex/faxtomail/services/service/imports/ClientImportModel.java @@ -29,8 +29,6 @@ import org.apache.commons.lang3.StringUtils; import org.nuiton.csv.ValueParser; import org.nuiton.csv.ext.AbstractImportModel; -import java.text.ParseException; - /** * @author Kevin Morin (Code Lutin) * @@ -40,32 +38,26 @@ public class ClientImportModel extends AbstractImportModel<ClientImportBean> { public ClientImportModel(char separator) { super(separator); - ValueParser<String> nullParser = new ValueParser<String>() { - @Override - public String parse(String s) throws ParseException { - if ("NULL".equals(s)) { - s = null; - } - return s; + ValueParser<String> nullParser = s -> { + if ("NULL".equals(s)) { + s = null; } + return s; }; // parser qui retire les non nombres des numero de fax - ValueParser<String> faxParser = new ValueParser<String>() { - @Override - public String parse(String s) throws ParseException { - if ("NULL".equals(s)) { + ValueParser<String> faxParser = s -> { + if ("NULL".equals(s)) { + s = null; + } + if (s != null) { + s = StringUtils.removePattern(s, "[^0-9]"); + if ("0".equals(s) || s.isEmpty()) { s = null; } - if (s != null) { - s = StringUtils.removePattern(s, "[^0-9]"); - if ("0".equals(s) || s.isEmpty()) { - s = null; - } - } - - return s; } + + return s; }; newIgnoredColumn("Id_Correspondance"); diff --git a/faxtomail-service/src/main/java/com/franciaflex/faxtomail/services/service/imports/EmailAccountImportModel.java b/faxtomail-service/src/main/java/com/franciaflex/faxtomail/services/service/imports/EmailAccountImportModel.java index 00736df..5f22b19 100644 --- a/faxtomail-service/src/main/java/com/franciaflex/faxtomail/services/service/imports/EmailAccountImportModel.java +++ b/faxtomail-service/src/main/java/com/franciaflex/faxtomail/services/service/imports/EmailAccountImportModel.java @@ -27,11 +27,8 @@ package com.franciaflex.faxtomail.services.service.imports; import com.franciaflex.faxtomail.persistence.entities.EmailAccount; import com.franciaflex.faxtomail.persistence.entities.EmailAccountImpl; import com.franciaflex.faxtomail.persistence.entities.EmailProtocol; -import org.nuiton.csv.ValueParser; import org.nuiton.csv.ext.AbstractImportModel; -import java.text.ParseException; - /** * @author Kevin Morin (Code Lutin) * @@ -41,25 +38,9 @@ public class EmailAccountImportModel extends AbstractImportModel<EmailAccount> { public EmailAccountImportModel(char separator) { super(separator); - newMandatoryColumn("protocol", EmailAccount.PROPERTY_PROTOCOL, new ValueParser<EmailProtocol>() { - - @Override - public EmailProtocol parse(String value) throws ParseException { - EmailProtocol protocol = EmailProtocol.valueOf(value.toUpperCase()); - return protocol; - } - - }); + newMandatoryColumn("protocol", EmailAccount.PROPERTY_PROTOCOL, value -> EmailProtocol.valueOf(value.toUpperCase())); newMandatoryColumn("host", EmailAccount.PROPERTY_HOST); - newMandatoryColumn("port", EmailAccount.PROPERTY_PORT, new ValueParser<Integer>() { - - @Override - public Integer parse(String value) throws ParseException { - Integer result = Integer.valueOf(value); - return result; - } - - }); + newMandatoryColumn("port", EmailAccount.PROPERTY_PORT, Integer::valueOf); newMandatoryColumn("user", EmailAccount.PROPERTY_LOGIN); newMandatoryColumn("password", EmailAccount.PROPERTY_PASSWORD); } diff --git a/faxtomail-service/src/main/java/com/franciaflex/faxtomail/services/service/imports/EmailFilterImportModel.java b/faxtomail-service/src/main/java/com/franciaflex/faxtomail/services/service/imports/EmailFilterImportModel.java index f4402e7..4814687 100644 --- a/faxtomail-service/src/main/java/com/franciaflex/faxtomail/services/service/imports/EmailFilterImportModel.java +++ b/faxtomail-service/src/main/java/com/franciaflex/faxtomail/services/service/imports/EmailFilterImportModel.java @@ -43,18 +43,8 @@ public class EmailFilterImportModel extends AbstractImportModel<MailFilter> { super(separator); newMandatoryColumn("recipient", MailFilter.PROPERTY_EXPRESSION); - newMandatoryColumn("folder", MailFilter.PROPERTY_MAIL_FOLDER, new ValueParser<Object>() { - @Override - public Object parse(String value) throws ParseException { - return foldersByName.get(value); - } - }); - newMandatoryColumn("position", MailFilter.PROPERTY_POSITION, new ValueParser<Object>() { - @Override - public Object parse(String value) throws ParseException { - return Integer.parseInt(value); - } - }); + newMandatoryColumn("folder", MailFilter.PROPERTY_MAIL_FOLDER, (ValueParser<Object>) foldersByName::get); + newMandatoryColumn("position", MailFilter.PROPERTY_POSITION, (ValueParser<Object>) Integer::parseInt); } @Override diff --git a/faxtomail-service/src/test/java/com/franciaflex/faxtomail/services/service/AbstractFaxToMailServiceTest.java b/faxtomail-service/src/test/java/com/franciaflex/faxtomail/services/service/AbstractFaxToMailServiceTest.java index d4b4936..2cfeb35 100644 --- a/faxtomail-service/src/test/java/com/franciaflex/faxtomail/services/service/AbstractFaxToMailServiceTest.java +++ b/faxtomail-service/src/test/java/com/franciaflex/faxtomail/services/service/AbstractFaxToMailServiceTest.java @@ -71,7 +71,7 @@ public class AbstractFaxToMailServiceTest { protected FaxToMailUser currentUser; protected Map<String, String> getDatabaseConfiguration(String dataBase) { - Map<String, String> hibernateH2Config = new HashMap<String, String>(); + Map<String, String> hibernateH2Config = new HashMap<>(); hibernateH2Config.putAll(getApplicationConfig().getTopiaProperties()); @@ -129,36 +129,33 @@ public class AbstractFaxToMailServiceTest { protected void addMissingTable(FaxToMailTopiaApplicationContext applicationContext) { FaxToMailTopiaPersistenceContext persistenceContext = applicationContext.newPersistenceContext(); TopiaSqlSupport sqlSupport = persistenceContext.getSqlSupport(); - sqlSupport.doSqlWork(new TopiaSqlWork() { - @Override - public void execute(Connection connection) throws SQLException { - - Statement stat = connection.createStatement(); - - stat.executeUpdate("create table newClient ( " + - "name longvarchar, " + - "emailAddress longvarchar, " + - "faxNumber longvarchar, " + - "caracteristic1 longvarchar, " + - "caracteristic2 longvarchar, " + - "caracteristic3 longvarchar, " + - "code longvarchar not null, " + - "company longvarchar not null, " + - "brand longvarchar, " + - "personInCharge longvarchar, " + - "unique (code, company, emailAddress, faxnumber)" + - "); "); - - stat.executeUpdate("create table ediReturn ( " + - "rangeRowTopiaId longvarchar not null," + - "commandNumber longvarchar, " + - "error longvarchar, " + - "unique (rangeRowTopiaId) " + - ")"); - - connection.commit(); + sqlSupport.doSqlWork(connection -> { + + Statement stat = connection.createStatement(); + + stat.executeUpdate("create table newClient ( " + + "name longvarchar, " + + "emailAddress longvarchar, " + + "faxNumber longvarchar, " + + "caracteristic1 longvarchar, " + + "caracteristic2 longvarchar, " + + "caracteristic3 longvarchar, " + + "code longvarchar not null, " + + "company longvarchar not null, " + + "brand longvarchar, " + + "personInCharge longvarchar, " + + "unique (code, company, emailAddress, faxnumber)" + + "); "); + + stat.executeUpdate("create table ediReturn ( " + + "rangeRowTopiaId longvarchar not null," + + "commandNumber longvarchar, " + + "error longvarchar, " + + "unique (rangeRowTopiaId) " + + ")"); + + connection.commit(); - } }); persistenceContext.close(); diff --git a/faxtomail-service/src/test/java/com/franciaflex/faxtomail/services/service/ClientServiceTest.java b/faxtomail-service/src/test/java/com/franciaflex/faxtomail/services/service/ClientServiceTest.java index bd3a864..5325ff7 100644 --- a/faxtomail-service/src/test/java/com/franciaflex/faxtomail/services/service/ClientServiceTest.java +++ b/faxtomail-service/src/test/java/com/franciaflex/faxtomail/services/service/ClientServiceTest.java @@ -30,17 +30,15 @@ import com.franciaflex.faxtomail.persistence.entities.Client; import com.franciaflex.faxtomail.persistence.entities.ClientTopiaDao; import com.franciaflex.faxtomail.persistence.entities.EmailImpl; import com.franciaflex.faxtomail.persistence.entities.NewClient; -import com.google.common.collect.Lists; import org.junit.Assert; import org.junit.Before; import org.junit.Test; import org.nuiton.topia.persistence.support.TopiaSqlSupport; -import org.nuiton.topia.persistence.support.TopiaSqlWork; import java.io.IOException; -import java.sql.Connection; import java.sql.PreparedStatement; -import java.sql.SQLException; +import java.util.Arrays; +import java.util.Collections; import java.util.List; /** @@ -83,35 +81,32 @@ public class ClientServiceTest extends AbstractFaxToMailServiceTest { // add new clients TopiaSqlSupport sqlSupport = getServiceContext().getPersistenceContext().getSqlSupport(); - sqlSupport.doSqlWork(new TopiaSqlWork() { - @Override - public void execute(Connection connection) throws SQLException { - - String query = String.format("INSERT INTO %s(%s,%s,%s,%s,%s) VALUES(?, ?, ?, ?, ?)", - NewClient.class.getSimpleName(), - NewClient.PROPERTY_CODE, - NewClient.PROPERTY_COMPANY, - NewClient.PROPERTY_BRAND, - NewClient.PROPERTY_EMAIL_ADDRESS, - NewClient.PROPERTY_NAME); - - PreparedStatement stat = connection.prepareStatement(query); - stat.setString(1, "99154"); - stat.setString(2, "FX"); - stat.setString(3, "FX"); - stat.setString(4, "gerard.menvussa@lutin.com"); - stat.setString(5, "Gerard"); - int result = stat.executeUpdate(); - Assert.assertEquals(1, result); - - stat.setString(1, "99154"); - stat.setString(2, "FX"); - stat.setString(3, "FX"); - stat.setString(4, "gerard.menvussa+test@lutin.com"); - stat.setString(5, "Gerard"); - result = stat.executeUpdate(); - Assert.assertEquals(1, result); - } + sqlSupport.doSqlWork(connection -> { + + String query = String.format("INSERT INTO %s(%s,%s,%s,%s,%s) VALUES(?, ?, ?, ?, ?)", + NewClient.class.getSimpleName(), + NewClient.PROPERTY_CODE, + NewClient.PROPERTY_COMPANY, + NewClient.PROPERTY_BRAND, + NewClient.PROPERTY_EMAIL_ADDRESS, + NewClient.PROPERTY_NAME); + + PreparedStatement stat = connection.prepareStatement(query); + stat.setString(1, "99154"); + stat.setString(2, "FX"); + stat.setString(3, "FX"); + stat.setString(4, "gerard.menvussa@lutin.com"); + stat.setString(5, "Gerard"); + int result = stat.executeUpdate(); + Assert.assertEquals(1, result); + + stat.setString(1, "99154"); + stat.setString(2, "FX"); + stat.setString(3, "FX"); + stat.setString(4, "gerard.menvussa+test@lutin.com"); + stat.setString(5, "Gerard"); + result = stat.executeUpdate(); + Assert.assertEquals(1, result); }); // precedure de mise à jour @@ -130,7 +125,7 @@ public class ClientServiceTest extends AbstractFaxToMailServiceTest { BrandsForDomain brandsForDomain = brandsForDomainTopiaDao.newInstance(); brandsForDomain.setDomainName("groupecreal.com"); - brandsForDomain.setBrands(Lists.newArrayList("CREAL")); + brandsForDomain.setBrands(Collections.singletonList("CREAL")); brandsForDomain = brandsForDomainTopiaDao.create(brandsForDomain); ClientTopiaDao clientTopiaDao = getServiceContext().getPersistenceContext().getClientDao(); @@ -172,7 +167,7 @@ public class ClientServiceTest extends AbstractFaxToMailServiceTest { Assert.assertEquals(1, foundClients.size()); Assert.assertEquals(client, foundClients.get(0)); - brandsForDomain.setBrands(Lists.newArrayList("CREAL", "FX")); + brandsForDomain.setBrands(Arrays.asList("CREAL", "FX")); brandsForDomain = brandsForDomainTopiaDao.update(brandsForDomain); brands = getServiceContext().getConfigurationService().getBrandsForEmailAddress(domain); diff --git a/faxtomail-service/src/test/java/com/franciaflex/faxtomail/services/service/EmailServiceTest.java b/faxtomail-service/src/test/java/com/franciaflex/faxtomail/services/service/EmailServiceTest.java index cb6c74b..2333fdd 100644 --- a/faxtomail-service/src/test/java/com/franciaflex/faxtomail/services/service/EmailServiceTest.java +++ b/faxtomail-service/src/test/java/com/franciaflex/faxtomail/services/service/EmailServiceTest.java @@ -36,9 +36,7 @@ import com.franciaflex.faxtomail.persistence.entities.MailFolder; import com.franciaflex.faxtomail.persistence.entities.MailFolderTopiaDao; import com.franciaflex.faxtomail.persistence.entities.Range; import com.franciaflex.faxtomail.persistence.entities.SearchFilter; -import com.google.common.collect.Iterables; import com.google.common.collect.Sets; -import com.google.common.io.Files; import org.apache.commons.io.FileUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -62,6 +60,7 @@ import java.util.Map; import java.util.Map.Entry; import java.util.Properties; import java.util.Set; +import java.util.stream.Collectors; /** * Email service tests. @@ -195,8 +194,8 @@ public class EmailServiceTest extends AbstractFaxToMailServiceTest { Assert.assertEquals(5, page2.getCount()); // + 5 archived now Assert.assertEquals(1, page2.getElements().size()); - Set<String> page1Ids = Sets.newHashSet(Iterables.transform(page1.getElements(), TopiaEntities.getTopiaIdFunction())); - Set<String> page2Ids = Sets.newHashSet(Iterables.transform(page2.getElements(), TopiaEntities.getTopiaIdFunction())); + Set<String> page1Ids = page1.getElements().stream().map(TopiaEntities.getTopiaIdFunction()::apply).collect(Collectors.toSet()); + Set<String> page2Ids = page2.getElements().stream().map(TopiaEntities.getTopiaIdFunction()::apply).collect(Collectors.toSet()); Assert.assertTrue(Sets.intersection(page1Ids, page2Ids).isEmpty()); } @@ -330,7 +329,7 @@ public class EmailServiceTest extends AbstractFaxToMailServiceTest { List<Attachment> attachments = service.extractAttachmentsFromMessage(message); for (Attachment attachment : attachments) { - Files.copy(attachment.getOriginalFile().getFile(), new File(tempDirectory, attachment.getOriginalFileName())); + FileUtils.copyFile(attachment.getOriginalFile().getFile(), new File(tempDirectory, attachment.getOriginalFileName())); } } catch (Exception e) { diff --git a/faxtomail-service/src/test/java/com/franciaflex/faxtomail/services/service/MailFolderServiceTest.java b/faxtomail-service/src/test/java/com/franciaflex/faxtomail/services/service/MailFolderServiceTest.java index 3ea8303..fa8ce44 100644 --- a/faxtomail-service/src/test/java/com/franciaflex/faxtomail/services/service/MailFolderServiceTest.java +++ b/faxtomail-service/src/test/java/com/franciaflex/faxtomail/services/service/MailFolderServiceTest.java @@ -28,7 +28,6 @@ import com.franciaflex.faxtomail.persistence.entities.EmailImpl; import com.franciaflex.faxtomail.persistence.entities.FaxToMailUser; import com.franciaflex.faxtomail.persistence.entities.MailFilter; import com.franciaflex.faxtomail.persistence.entities.MailFolder; -import com.google.common.collect.Lists; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.junit.Assert; @@ -39,6 +38,7 @@ import javax.mail.Address; import javax.mail.internet.AddressException; import javax.mail.internet.InternetAddress; import java.io.IOException; +import java.util.Arrays; import java.util.HashSet; import java.util.List; @@ -71,17 +71,17 @@ public class MailFolderServiceTest extends AbstractFaxToMailServiceTest { Address a3 = new InternetAddress("dsfdsf qd qsdsq d <fx.01test@franciaflex.com>"); EmailImpl email = new EmailImpl(); - HashSet<String> modifiedProperties = new HashSet<String>(); + HashSet<String> modifiedProperties = new HashSet<>(); - MailFilter filter = service.findMailFilter(email, modifiedProperties, Lists.newArrayList(a1, a2, a3)); + MailFilter filter = service.findMailFilter(email, modifiedProperties, Arrays.asList(a1, a2, a3)); Assert.assertNotNull(filter); Assert.assertEquals(filter.getMailFolder().getName(), "Cyril"); - filter = service.findMailFilter(email, modifiedProperties, Lists.newArrayList(a1, a3, a2)); + filter = service.findMailFilter(email, modifiedProperties, Arrays.asList(a1, a3, a2)); Assert.assertNotNull(filter); Assert.assertEquals(filter.getMailFolder().getName(), "Cyril"); - filter = service.findMailFilter(email, modifiedProperties, Lists.newArrayList(a3, a1, a2)); + filter = service.findMailFilter(email, modifiedProperties, Arrays.asList(a3, a1, a2)); Assert.assertNotNull(filter); Assert.assertEquals(filter.getMailFolder().getName(), "Cyril"); diff --git a/faxtomail-service/src/test/java/com/franciaflex/faxtomail/services/service/MiscTest.java b/faxtomail-service/src/test/java/com/franciaflex/faxtomail/services/service/MiscTest.java index 4203e8d..ffb27be 100644 --- a/faxtomail-service/src/test/java/com/franciaflex/faxtomail/services/service/MiscTest.java +++ b/faxtomail-service/src/test/java/com/franciaflex/faxtomail/services/service/MiscTest.java @@ -42,7 +42,7 @@ public class MiscTest extends AbstractFaxToMailServiceTest { @Override protected Map<String, String> getDatabaseConfiguration(String dataBase) { - Map<String, String> hibernateH2Config = new HashMap<String, String>(); + Map<String, String> hibernateH2Config = new HashMap<>(); // sqlserver config hibernateH2Config.put(Environment.DIALECT, "org.hibernate.dialect.H2Dialect"); diff --git a/faxtomail-service/src/test/java/com/franciaflex/faxtomail/services/service/migration/FlywayMigrationTest.java b/faxtomail-service/src/test/java/com/franciaflex/faxtomail/services/service/migration/FlywayMigrationTest.java index b2289a7..d16ab0a 100644 --- a/faxtomail-service/src/test/java/com/franciaflex/faxtomail/services/service/migration/FlywayMigrationTest.java +++ b/faxtomail-service/src/test/java/com/franciaflex/faxtomail/services/service/migration/FlywayMigrationTest.java @@ -52,7 +52,7 @@ public class FlywayMigrationTest extends AbstractFaxToMailServiceTest { @Override protected Map<String, String> getDatabaseConfiguration(String dataBase) { - Map<String, String> hibernateH2Config = new HashMap<String, String>(); + Map<String, String> hibernateH2Config = new HashMap<>(); // copy database to test it outside source directory File tempDirFile = SystemUtils.getJavaIoTmpDir(); diff --git a/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/FaxToMailActionFactory.java b/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/FaxToMailActionFactory.java index 12e65f4..64978d5 100644 --- a/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/FaxToMailActionFactory.java +++ b/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/FaxToMailActionFactory.java @@ -48,8 +48,7 @@ public class FaxToMailActionFactory extends ApplicationActionFactory { try { // create action - A result = ConstructorUtils.invokeConstructor(actionName, (AbstractFaxToMailUIHandler) handler); - return result; + return ConstructorUtils.invokeConstructor(actionName, (AbstractFaxToMailUIHandler) handler); } catch (Exception e) { throw new ApplicationTechnicalException(t("application.action.create.error", actionName), e); diff --git a/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/FaxToMailUIContext.java b/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/FaxToMailUIContext.java index e578793..f2a998f 100644 --- a/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/FaxToMailUIContext.java +++ b/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/FaxToMailUIContext.java @@ -45,7 +45,6 @@ import com.franciaflex.faxtomail.ui.swing.content.search.SearchUIModel; import com.franciaflex.faxtomail.ui.swing.util.UIMessageNotifier; import com.franciaflex.faxtomail.ui.swing.util.data.Handler; import com.google.common.base.Preconditions; -import com.google.common.collect.Maps; import com.google.common.collect.Sets; import jaxx.runtime.swing.editor.bean.BeanDoubleList; import jaxx.runtime.swing.editor.bean.BeanFilterableComboBox; @@ -85,16 +84,17 @@ import javax.swing.JOptionPane; import java.awt.Color; import java.awt.Component; import java.awt.Container; -import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeListener; import java.io.Closeable; import java.io.File; import java.util.ArrayList; import java.util.Collection; import java.util.HashMap; +import java.util.HashSet; import java.util.List; import java.util.Locale; import java.util.Map; +import java.util.Objects; import java.util.Set; import static org.nuiton.i18n.I18n.t; @@ -211,9 +211,9 @@ public class FaxToMailUIContext extends AbstractBean implements Closeable, UIMes protected FolderData currentFolderEmails = new FolderData(); /** Les dossiers étendus dans la liste (pour pouvoir les étendres encore au rechargement de l'UI). */ - protected List<MailFolder> listExpandedFolders = new ArrayList<MailFolder>(); + protected List<MailFolder> listExpandedFolders = new ArrayList<>(); /** Les dossiers étendus dans la sélection de dossier pour transfert (pour pouvoir les étendres encore au rechargement de l'UI). */ - protected List<MailFolder> transmitExpandedFolders = new ArrayList<MailFolder>(); + protected List<MailFolder> transmitExpandedFolders = new ArrayList<>(); protected SearchUIModel search; @@ -233,7 +233,7 @@ public class FaxToMailUIContext extends AbstractBean implements Closeable, UIMes protected EmailFilter emailFilter = new EmailFilter(); public static FaxToMailUIContext newContext(FaxToMailConfiguration config) { - Preconditions.checkNotNull(config); + Objects.requireNonNull(config); Preconditions.checkState(applicationContext == null, "Application context was already opened!"); applicationContext = new FaxToMailUIContext(config); @@ -269,7 +269,7 @@ public class FaxToMailUIContext extends AbstractBean implements Closeable, UIMes InitFaxToMailService initFaxToMailService = serviceContext.getInitFaxToMailService(); initFaxToMailService.init(); - Map<Class, State> additionalStates = Maps.newHashMap(); + Map<Class, State> additionalStates = new HashMap<>(); additionalStates.put(BeanFilterableComboBox.class, new BeanFilterableComboBoxState()); additionalStates.put(BeanDoubleList.class, new BeanDoubleListState()); File uiConfigFile = getConfig().getUIConfigFile(); @@ -302,25 +302,21 @@ public class FaxToMailUIContext extends AbstractBean implements Closeable, UIMes } }; - UIMessageNotifier logMessageNotifier = new UIMessageNotifier() { - - @Override - public void showInformationMessage(String message) { - if (StringUtils.isNotBlank(message)) { - message = message.replaceAll("\\<strong\\>", ""); - message = message.replaceAll("\\<.strong\\>", ""); - message = message.replaceAll("\\<li\\>", ""); - message = message.replaceAll("\\<.li\\>", ""); - message = message.replaceAll("\\<ul\\>", ""); - message = message.replaceAll("\\<.ul\\>", ""); - if (log.isInfoEnabled()) { - log.info(message); - } + UIMessageNotifier logMessageNotifier = message -> { + if (StringUtils.isNotBlank(message)) { + message = message.replaceAll("\\<strong\\>", ""); + message = message.replaceAll("\\<.strong\\>", ""); + message = message.replaceAll("\\<li\\>", ""); + message = message.replaceAll("\\<.li\\>", ""); + message = message.replaceAll("\\<ul\\>", ""); + message = message.replaceAll("\\<.ul\\>", ""); + if (log.isInfoEnabled()) { + log.info(message); } } }; - this.messageNotifiers = Sets.newHashSet(); + this.messageNotifiers = new HashSet<>(); addMessageNotifier(logMessageNotifier); faxToMailActionFactory = new FaxToMailActionFactory(); @@ -363,15 +359,11 @@ public class FaxToMailUIContext extends AbstractBean implements Closeable, UIMes ConverterUtil.initConverters(); // Use shutdownHook to close context on System.exit - Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() { - - @Override - public void run() { - if (log.isInfoEnabled()) { - log.info("Close context on shutdown"); - } - close(); + Runtime.getRuntime().addShutdownHook(new Thread(() -> { + if (log.isInfoEnabled()) { + log.info("Close context on shutdown"); } + close(); })); //--------------------------------------------------------------------// @@ -511,14 +503,10 @@ public class FaxToMailUIContext extends AbstractBean implements Closeable, UIMes saveContextToConfig(); // list when programId or campaingId change to save the configuration - addPropertyChangeListener(new PropertyChangeListener() { + addPropertyChangeListener(evt -> { - @Override - public void propertyChange(PropertyChangeEvent evt) { - - if (PROPERTIES_TO_SAVE.contains(evt.getPropertyName())) { - saveContextToConfig(); - } + if (PROPERTIES_TO_SAVE.contains(evt.getPropertyName())) { + saveContextToConfig(); } }); } @@ -859,7 +847,7 @@ public class FaxToMailUIContext extends AbstractBean implements Closeable, UIMes } public void setDemands(List<DemandeUIModel> demands) { - this.demands = new ArrayList<DemandeUIModel>(demands); + this.demands = new ArrayList<>(demands); } public void removeDemand(DemandeUIModel demand) { diff --git a/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/RunFaxToMail.java b/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/RunFaxToMail.java index 738d93f..f9aebe6 100644 --- a/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/RunFaxToMail.java +++ b/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/RunFaxToMail.java @@ -120,12 +120,7 @@ public class RunFaxToMail { } } finally { - SwingUtilities.invokeLater(new Runnable() { - @Override - public void run() { - splashScreen.complete(); - } - }); + SwingUtilities.invokeLater(splashScreen::complete); } } @@ -143,12 +138,7 @@ public class RunFaxToMail { final MainUI mainUI = new MainUI(context); context.addMessageNotifier(mainUI.getHandler()); - SwingUtilities.invokeLater(new Runnable() { - @Override - public void run() { - mainUI.setVisible(true); - } - }); + SwingUtilities.invokeLater(() -> mainUI.setVisible(true)); } public static void closeFaxToMail(MainUIHandler handler, Integer exitCode) { diff --git a/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/actions/PrintOnDefaultPrinterAction.java b/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/actions/PrintOnDefaultPrinterAction.java index f782259..2a65352 100644 --- a/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/actions/PrintOnDefaultPrinterAction.java +++ b/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/actions/PrintOnDefaultPrinterAction.java @@ -78,7 +78,7 @@ public class PrintOnDefaultPrinterAction extends AbstractFaxToMailAction { int printedFileNb = 0; Multimap<DemandeUIModel, AttachmentFile> nonPrintedAttachment = HashMultimap.create(); - notPrintableDemands = new ArrayList<DemandeUIModel>(); + notPrintableDemands = new ArrayList<>(); for (DemandeUIModel demandeUIModel : attachmentsToPrintByDemand.keySet()) { @@ -90,7 +90,7 @@ public class PrintOnDefaultPrinterAction extends AbstractFaxToMailAction { demandeUIModel.setTakenBy(currentUser); } - List<String> printedFiles = new ArrayList<String>(); + List<String> printedFiles = new ArrayList<>(); FaxToMailServiceContext serviceContext = getContext().newServiceContext(); if (printDemandDetails) { diff --git a/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/actions/ShowDemandeAction.java b/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/actions/ShowDemandeAction.java index ba1abf9..03fe289 100644 --- a/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/actions/ShowDemandeAction.java +++ b/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/actions/ShowDemandeAction.java @@ -224,13 +224,10 @@ public class ShowDemandeAction extends AbstractMainUIFaxToMailAction { @Override public void propertyChange(PropertyChangeEvent evt) { if (!getContext().isBusy()) { - SwingUtilities.invokeLater(new Runnable() { - @Override - public void run() { - if (frame != null) { - frame.toFront(); - frame = null; - } + SwingUtilities.invokeLater(() -> { + if (frame != null) { + frame.toFront(); + frame = null; } }); getContext().removePropertyChangeListener(FaxToMailUIContext.PROPERTY_BUSY, this); diff --git a/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/MainUIHandler.java b/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/MainUIHandler.java index b8a7545..4d0ade1 100644 --- a/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/MainUIHandler.java +++ b/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/MainUIHandler.java @@ -31,7 +31,6 @@ import com.franciaflex.faxtomail.ui.swing.util.AbstractFaxToMailDemandListHandle import com.franciaflex.faxtomail.ui.swing.util.AbstractFaxToMailUIHandler; import com.franciaflex.faxtomail.ui.swing.util.FaxToMailUI; import com.franciaflex.faxtomail.ui.swing.util.RemoveablePropertyChangeListener; -import com.google.common.base.Preconditions; import jaxx.runtime.JAXXBinding; import jaxx.runtime.SwingUtil; import jaxx.runtime.swing.session.SwingSession; @@ -43,8 +42,11 @@ import org.nuiton.i18n.I18n; import org.nuiton.jaxx.application.swing.action.ApplicationActionUI; import org.nuiton.jaxx.application.swing.util.CloseableUI; -import javax.swing.*; -import java.awt.*; +import javax.swing.Icon; +import javax.swing.JComponent; +import javax.swing.JLabel; +import javax.swing.JToolBar; +import java.awt.Cursor; import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; import java.beans.PropertyChangeEvent; @@ -52,6 +54,7 @@ import java.beans.PropertyChangeListener; import java.beans.PropertyChangeListenerProxy; import java.io.IOException; import java.util.Locale; +import java.util.Objects; import static org.nuiton.i18n.I18n.t; @@ -163,15 +166,12 @@ public class MainUIHandler extends AbstractFaxToMailUIHandler<FaxToMailUIContext // SwingUtil.getLayer(ui.getBody()).setUI(new BetaLayerUI()); - getContext().addPropertyChangeListener(FaxToMailUIContext.PROPERTY_ACTION_IN_PROGRESS, new PropertyChangeListener() { - @Override - public void propertyChange(PropertyChangeEvent evt) { - boolean inProgress = (boolean) evt.getNewValue(); - MainUI ui = getUI(); - ui.getSearchButton().setEnabled(!inProgress); - ui.getDemandListButton().setEnabled(!inProgress); + getContext().addPropertyChangeListener(FaxToMailUIContext.PROPERTY_ACTION_IN_PROGRESS, evt -> { + boolean inProgress = (boolean) evt.getNewValue(); + MainUI ui1 = getUI(); + ui1.getSearchButton().setEnabled(!inProgress); + ui1.getDemandListButton().setEnabled(!inProgress); // ui.getExitButton().setEnabled(!inProgress); - } }); changeTitle(); @@ -292,7 +292,7 @@ public class MainUIHandler extends AbstractFaxToMailUIHandler<FaxToMailUIContext } } else { FaxToMailUI<?, ?> body = (FaxToMailUI<?, ?>) currentBody; - Preconditions.checkNotNull(currentBody); + Objects.requireNonNull(currentBody); AbstractFaxToMailUIHandler<?, ?> handler = body.getHandler(); if (handler instanceof CloseableUI) { diff --git a/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/attachment/AttachmentCellEditor.java b/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/attachment/AttachmentCellEditor.java index 0401a2e..52a4fe1 100644 --- a/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/attachment/AttachmentCellEditor.java +++ b/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/attachment/AttachmentCellEditor.java @@ -33,19 +33,21 @@ import com.franciaflex.faxtomail.ui.swing.content.demande.DemandeUIModel; import com.franciaflex.faxtomail.ui.swing.util.DemandeTableModel; import com.franciaflex.faxtomail.ui.swing.util.FaxToMailUI; import com.franciaflex.faxtomail.ui.swing.util.FaxToMailUIUtil; -import com.google.common.base.Preconditions; import com.google.common.collect.Sets; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import javax.swing.*; +import javax.swing.AbstractCellEditor; +import javax.swing.JTable; import javax.swing.border.LineBorder; import javax.swing.event.CellEditorListener; import javax.swing.event.ChangeEvent; import javax.swing.table.TableCellEditor; -import java.awt.*; +import java.awt.Color; +import java.awt.Component; import java.util.Date; import java.util.EventObject; +import java.util.Objects; /** * To edit attachments from a table cell. @@ -159,7 +161,7 @@ public class AttachmentCellEditor extends AbstractCellEditor implements TableCel public Object getCellEditorValue() { AttachmentEditorUIModel model = editorButton.getBean(); - Preconditions.checkNotNull(model, "No model found in editor."); + Objects.requireNonNull(model, "No model found in editor."); Object result = model.getAttachment(); if (log.isDebugEnabled()) { diff --git a/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/attachment/AttachmentEditorUIHandler.java b/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/attachment/AttachmentEditorUIHandler.java index a8d4b0a..adc3774 100644 --- a/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/attachment/AttachmentEditorUIHandler.java +++ b/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/attachment/AttachmentEditorUIHandler.java @@ -27,9 +27,8 @@ package com.franciaflex.faxtomail.ui.swing.content.attachment; import com.franciaflex.faxtomail.persistence.entities.Attachment; import com.franciaflex.faxtomail.ui.swing.content.attachment.actions.EditAttachmentAction; import com.franciaflex.faxtomail.ui.swing.content.attachment.actions.OpenAttachmentAction; -import com.franciaflex.faxtomail.ui.swing.util.toolbar.AbstractToolbarPopupHandler; import com.franciaflex.faxtomail.ui.swing.util.FaxToMailUIUtil; -import com.google.common.collect.Iterables; +import com.franciaflex.faxtomail.ui.swing.util.toolbar.AbstractToolbarPopupHandler; import jaxx.runtime.SwingUtil; import jaxx.runtime.swing.HidorButton; import jaxx.runtime.validator.swing.SwingValidator; @@ -39,9 +38,12 @@ import org.apache.commons.logging.LogFactory; import org.jdesktop.swingx.JXTable; import org.jdesktop.swingx.decorator.HighlighterFactory; -import javax.swing.*; -import javax.swing.event.TableModelEvent; -import javax.swing.event.TableModelListener; +import javax.swing.AbstractCellEditor; +import javax.swing.Icon; +import javax.swing.JComponent; +import javax.swing.JLabel; +import javax.swing.JOptionPane; +import javax.swing.JTable; import javax.swing.table.AbstractTableModel; import javax.swing.table.DefaultTableColumnModel; import javax.swing.table.TableCellEditor; @@ -49,11 +51,9 @@ import javax.swing.table.TableCellRenderer; import javax.swing.table.TableColumn; import javax.swing.table.TableColumnModel; import javax.swing.table.TableModel; -import java.awt.*; +import java.awt.Component; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; -import java.beans.PropertyChangeEvent; -import java.beans.PropertyChangeListener; import java.util.Collection; import static org.nuiton.i18n.I18n.t; @@ -77,21 +77,13 @@ public class AttachmentEditorUIHandler extends AbstractToolbarPopupHandler<Attac initTable(ui.getAttachments(), getModel().getAttachment()); initTable(ui.getInlineAttachments(), getModel().getInlineAttachments()); - ui.getInlineAttachmentsHidor().addPropertyChangeListener(HidorButton.PROPERTY_TARGET_VISIBLE, new PropertyChangeListener() { - @Override - public void propertyChange(PropertyChangeEvent evt) { - getUI().pack(); - } - }); + ui.getInlineAttachmentsHidor().addPropertyChangeListener(HidorButton.PROPERTY_TARGET_VISIBLE, evt -> getUI().pack()); - getModel().addPropertyChangeListener(AttachmentModelAware.PROPERTY_ATTACHMENT, new PropertyChangeListener() { - @Override - public void propertyChange(PropertyChangeEvent evt) { - AbstractTableModel tableModel = (AbstractTableModel) getUI().getAttachments().getModel(); - tableModel.fireTableDataChanged(); - tableModel = (AbstractTableModel) getUI().getInlineAttachments().getModel(); - tableModel.fireTableDataChanged(); - } + getModel().addPropertyChangeListener(AttachmentModelAware.PROPERTY_ATTACHMENT, evt -> { + AbstractTableModel tableModel = (AbstractTableModel) getUI().getAttachments().getModel(); + tableModel.fireTableDataChanged(); + tableModel = (AbstractTableModel) getUI().getInlineAttachments().getModel(); + tableModel.fireTableDataChanged(); }); } @@ -111,7 +103,7 @@ public class AttachmentEditorUIHandler extends AbstractToolbarPopupHandler<Attac @Override public Object getValueAt(int rowIndex, int columnIndex) { - return Iterables.get(attachmentList, rowIndex); + return CollectionUtils.get(attachmentList, rowIndex); } @Override @@ -120,12 +112,7 @@ public class AttachmentEditorUIHandler extends AbstractToolbarPopupHandler<Attac } }; - attachmentTableModel.addTableModelListener(new TableModelListener() { - @Override - public void tableChanged(TableModelEvent e) { - getUI().pack(); - } - }); + attachmentTableModel.addTableModelListener(e -> getUI().pack()); TableColumnModel columnModel = new DefaultTableColumnModel(); TableColumn column = new TableColumn(); diff --git a/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/attachment/AttachmentEditorUIModel.java b/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/attachment/AttachmentEditorUIModel.java index 7aabb5c..750a41c 100644 --- a/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/attachment/AttachmentEditorUIModel.java +++ b/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/attachment/AttachmentEditorUIModel.java @@ -26,17 +26,15 @@ package com.franciaflex.faxtomail.ui.swing.content.attachment; import com.franciaflex.faxtomail.persistence.entities.Attachment; import com.franciaflex.faxtomail.ui.swing.util.AbstractFaxToMailBeanUIModel; -import com.google.common.base.Predicate; -import com.google.common.collect.Collections2; import org.apache.commons.lang3.ObjectUtils; import org.apache.commons.lang3.StringUtils; import org.nuiton.util.beans.Binder; import org.nuiton.util.beans.BinderFactory; import java.util.ArrayList; -import java.util.Collections; import java.util.Comparator; import java.util.List; +import java.util.stream.Collectors; /** * @author Kevin Morin (Code Lutin) @@ -76,12 +74,12 @@ public class AttachmentEditorUIModel extends AbstractFaxToMailBeanUIModel<Attach //protected File file; protected boolean editable = true; - protected final List<Attachment> attachments = new ArrayList<Attachment>(); - protected final List<Attachment> inlineAttachments = new ArrayList<Attachment>(); + protected final List<Attachment> attachments = new ArrayList<>(); + protected final List<Attachment> inlineAttachments = new ArrayList<>(); protected Attachment selectedAttachment; - protected List<AttachmentListener> openingListeners = new ArrayList<AttachmentListener>(); + protected List<AttachmentListener> openingListeners = new ArrayList<>(); protected static Binder<AttachmentEditorUIModel, AttachmentModelAware> toBeanBinder = BinderFactory.newBinder(AttachmentEditorUIModel.class, @@ -109,13 +107,13 @@ public class AttachmentEditorUIModel extends AbstractFaxToMailBeanUIModel<Attach } public void addAllAttachment(List<Attachment> attachments) { - Object oldValue = new ArrayList<Attachment>(getAttachment()); + Object oldValue = new ArrayList<>(getAttachment()); this.attachments.addAll(attachments); firePropertyChange(AttachmentModelAware.PROPERTY_ATTACHMENT, oldValue, this.attachments); } public void addAttachment(Attachment attachment) { - Object oldValue = new ArrayList<Attachment>(getAttachment()); + Object oldValue = new ArrayList<>(getAttachment()); attachments.add(attachment); firePropertyChange(AttachmentModelAware.PROPERTY_ATTACHMENT, oldValue, attachments); } @@ -134,12 +132,9 @@ public class AttachmentEditorUIModel extends AbstractFaxToMailBeanUIModel<Attach if (attachments != null) { - inlineAttachments.addAll(Collections2.filter(attachments, new Predicate<Attachment>() { - @Override - public boolean apply(Attachment input) { - return input.isInlineAttachment(); - } - })); + inlineAttachments.addAll(attachments.stream() + .filter(Attachment::isInlineAttachment) + .collect(Collectors.toList())); this.attachments.addAll(attachments); @@ -161,8 +156,8 @@ public class AttachmentEditorUIModel extends AbstractFaxToMailBeanUIModel<Attach } public void sortAttachments() { - Collections.sort(this.attachments, ATTACHMENT_COMPARATOR); - Collections.sort(this.inlineAttachments, ATTACHMENT_COMPARATOR); + this.attachments.sort(ATTACHMENT_COMPARATOR); + this.inlineAttachments.sort(ATTACHMENT_COMPARATOR); } public Attachment getSelectedAttachment() { diff --git a/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/attachment/actions/EditAttachmentAction.java b/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/attachment/actions/EditAttachmentAction.java index 01bab80..b001ea9 100644 --- a/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/attachment/actions/EditAttachmentAction.java +++ b/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/attachment/actions/EditAttachmentAction.java @@ -98,15 +98,12 @@ public class EditAttachmentAction extends AbstractFaxToMailAction<AttachmentEdit @Override public void propertyChange(PropertyChangeEvent evt) { if (!getContext().isBusy()) { - SwingUtilities.invokeLater(new Runnable() { - @Override - public void run() { - bringCurrentDemandToFront(); - - if (frame != null) { - frame.toFront(); - frame = null; - } + SwingUtilities.invokeLater(() -> { + bringCurrentDemandToFront(); + + if (frame != null) { + frame.toFront(); + frame = null; } }); getContext().removePropertyChangeListener(FaxToMailUIContext.PROPERTY_BUSY, this); diff --git a/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/demande/DemandeListTableFilter.java b/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/demande/DemandeListTableFilter.java index 4dcc368..242a9c6 100644 --- a/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/demande/DemandeListTableFilter.java +++ b/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/demande/DemandeListTableFilter.java @@ -77,95 +77,95 @@ public class DemandeListTableFilter extends AbstractTableFilter<JXTable> { switch (property) { case Email.PROPERTY_DEMAND_STATUS: - emailFilter.setDemandStatus(!filtered ? null : new HashSet<DemandStatus>((Collection)items)); + emailFilter.setDemandStatus(!filtered ? null : new HashSet<>((Collection) items)); break; case Email.PROPERTY_RECEPTION_DATE: - emailFilter.setReceptionDates(!filtered ? null : new HashSet<Date>((Collection) items)); + emailFilter.setReceptionDates(!filtered ? null : new HashSet<>((Collection) items)); break; case Email.PROPERTY_RECIPIENT: - emailFilter.setRecipients(!filtered ? null : new HashSet<String>((Collection) items)); + emailFilter.setRecipients(!filtered ? null : new HashSet<>((Collection) items)); break; case Email.PROPERTY_SENDER: - emailFilter.setSenders(!filtered ? null : new HashSet<String>((Collection) items)); + emailFilter.setSenders(!filtered ? null : new HashSet<>((Collection) items)); break; case Email.PROPERTY_OBJECT: - emailFilter.setDemandObjects(!filtered ? null : new HashSet<String>((Collection) items)); + emailFilter.setDemandObjects(!filtered ? null : new HashSet<>((Collection) items)); break; case DemandeUIModel.PROPERTY_CLIENT_CODE: - emailFilter.setClientCodes(!filtered ? null : new HashSet<String>((Collection) items)); + emailFilter.setClientCodes(!filtered ? null : new HashSet<>((Collection) items)); break; case DemandeUIModel.PROPERTY_CLIENT_NAME: - emailFilter.setClientNames(!filtered ? null : new HashSet<String>((Collection) items)); + emailFilter.setClientNames(!filtered ? null : new HashSet<>((Collection) items)); break; case DemandeUIModel.PROPERTY_CLIENT_BRAND: - emailFilter.setClientBrands(!filtered ? null : new HashSet<String>((Collection) items)); + emailFilter.setClientBrands(!filtered ? null : new HashSet<>((Collection) items)); break; case Email.PROPERTY_DEMAND_TYPE: - emailFilter.setDemandTypes(!filtered ? null : new HashSet<DemandType>((Collection) items)); + emailFilter.setDemandTypes(!filtered ? null : new HashSet<>((Collection) items)); break; case Email.PROPERTY_EDI_ERROR: - emailFilter.setEdiCodeNumbers(!filtered ? null : new HashSet<String>((Collection) items)); + emailFilter.setEdiCodeNumbers(!filtered ? null : new HashSet<>((Collection) items)); break; case Email.PROPERTY_WAITING_STATE: - emailFilter.setWaitingStates(!filtered ? null : new HashSet<WaitingState>((Collection) items)); + emailFilter.setWaitingStates(!filtered ? null : new HashSet<>((Collection) items)); break; case Email.PROPERTY_TAKEN_BY: - emailFilter.setTakenBys(!filtered ? null : new HashSet<FaxToMailUser>((Collection) items)); + emailFilter.setTakenBys(!filtered ? null : new HashSet<>((Collection) items)); break; case Email.PROPERTY_PRIORITY: - emailFilter.setPriorities(!filtered ? null : new HashSet<Priority>((Collection) items)); + emailFilter.setPriorities(!filtered ? null : new HashSet<>((Collection) items)); break; case Email.PROPERTY_PROJECT_REFERENCE: - emailFilter.setProjectReferences(!filtered ? null : new HashSet<String>((Collection) items)); + emailFilter.setProjectReferences(!filtered ? null : new HashSet<>((Collection) items)); break; case Email.PROPERTY_COMPANY_REFERENCE: - emailFilter.setLocalReferences(!filtered ? null : new HashSet<String>((Collection) items)); + emailFilter.setLocalReferences(!filtered ? null : new HashSet<>((Collection) items)); break; case DemandeUIModel.PROPERTY_REFERENCE: - emailFilter.setReferences(!filtered ? null : new HashSet<String>((Collection) items)); + emailFilter.setReferences(!filtered ? null : new HashSet<>((Collection) items)); break; case Email.PROPERTY_RANGE_ROW: - emailFilter.setRanges(!filtered ? null : new HashSet<Range>((Collection) items)); + emailFilter.setRanges(!filtered ? null : new HashSet<>((Collection) items)); break; case DemandeUIModel.PROPERTY_PF_NB: - emailFilter.setProductsQuantities(!filtered ? null : new HashSet<Long>((Collection) items)); + emailFilter.setProductsQuantities(!filtered ? null : new HashSet<>((Collection) items)); break; case DemandeUIModel.PROPERTY_SAV_NB: - emailFilter.setSavQuantities(!filtered ? null : new HashSet<Long>((Collection) items)); + emailFilter.setSavQuantities(!filtered ? null : new HashSet<>((Collection) items)); break; case DemandeUIModel.PROPERTY_QUOTATION_NB: - emailFilter.setQuotationQuantities(!filtered ? null : new HashSet<Long>((Collection) items)); + emailFilter.setQuotationQuantities(!filtered ? null : new HashSet<>((Collection) items)); break; case Email.PROPERTY_LAST_ATTACHMENT_OPENER: - emailFilter.setLastAttachmentOpeners(!filtered ? null : new HashSet<FaxToMailUser>((Collection) items)); + emailFilter.setLastAttachmentOpeners(!filtered ? null : new HashSet<>((Collection) items)); break; case Email.PROPERTY_COMMENT: - emailFilter.setComments(!filtered ? null : new HashSet<String>((Collection) items)); + emailFilter.setComments(!filtered ? null : new HashSet<>((Collection) items)); break; case Email.PROPERTY_SUBJECT: - emailFilter.setSubjects(!filtered ? null : new HashSet<String>((Collection) items)); + emailFilter.setSubjects(!filtered ? null : new HashSet<>((Collection) items)); break; } @@ -263,7 +263,7 @@ public class DemandeListTableFilter extends AbstractTableFilter<JXTable> { filteredDates.add(cal.getTime()); } } - result = new HashSet<Object>(filteredDates); + result = new HashSet<>(filteredDates); } return result; diff --git a/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/demande/DemandeListUIHandler.java b/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/demande/DemandeListUIHandler.java index 85bc56c..b5a1676 100644 --- a/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/demande/DemandeListUIHandler.java +++ b/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/demande/DemandeListUIHandler.java @@ -37,9 +37,9 @@ import com.franciaflex.faxtomail.persistence.entities.MailField; import com.franciaflex.faxtomail.persistence.entities.MailFolder; import com.franciaflex.faxtomail.persistence.entities.OriginalEmailImpl; import com.franciaflex.faxtomail.ui.swing.FaxToMailUIContext; +import com.franciaflex.faxtomail.ui.swing.actions.PrintOnDefaultPrinterAction; import com.franciaflex.faxtomail.ui.swing.content.demande.actions.ComputeQuantitiesByRangeAction; import com.franciaflex.faxtomail.ui.swing.content.demande.actions.LoadFolderEmailsAction; -import com.franciaflex.faxtomail.ui.swing.actions.PrintOnDefaultPrinterAction; import com.franciaflex.faxtomail.ui.swing.content.demande.actions.SaveDemandeFromListAction; import com.franciaflex.faxtomail.ui.swing.util.AbstractFaxToMailDemandListHandler; import com.franciaflex.faxtomail.ui.swing.util.DemandeTableModel; @@ -48,7 +48,6 @@ import com.franciaflex.faxtomail.ui.swing.util.FolderTreeNode; import com.franciaflex.faxtomail.ui.swing.util.PaginationComboModel; import com.franciaflex.faxtomail.ui.swing.util.RemoveablePropertyChangeListener; import com.google.common.collect.HashMultimap; -import com.google.common.collect.Lists; import com.google.common.collect.Multimap; import jaxx.runtime.JAXXUtil; import jaxx.runtime.swing.table.filter.TableFilter; @@ -59,7 +58,6 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.jdesktop.swingx.JXTable; import org.jdesktop.swingx.decorator.ColorHighlighter; -import org.jdesktop.swingx.decorator.ComponentAdapter; import org.jdesktop.swingx.decorator.HighlightPredicate; import org.nuiton.decorator.Decorator; import org.nuiton.jaxx.application.swing.action.ApplicationUIAction; @@ -67,19 +65,20 @@ import org.nuiton.jaxx.application.swing.util.CloseableUI; import org.nuiton.util.beans.Binder; import org.nuiton.util.beans.BinderFactory; -import javax.swing.*; -import javax.swing.event.ListSelectionEvent; -import javax.swing.event.ListSelectionListener; -import javax.swing.event.TreeSelectionEvent; -import javax.swing.event.TreeSelectionListener; +import javax.swing.JComponent; +import javax.swing.JPopupMenu; +import javax.swing.JRootPane; +import javax.swing.JTree; +import javax.swing.KeyStroke; +import javax.swing.ListSelectionModel; +import javax.swing.SwingUtilities; +import javax.swing.Timer; import javax.swing.table.TableCellEditor; import javax.swing.tree.DefaultMutableTreeNode; import javax.swing.tree.TreePath; -import java.awt.*; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; +import java.awt.Color; +import java.awt.Dimension; import java.awt.event.ItemEvent; -import java.awt.event.ItemListener; import java.awt.event.MouseEvent; import java.beans.IntrospectionException; import java.beans.PropertyChangeEvent; @@ -88,6 +87,7 @@ import java.beans.PropertyDescriptor; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.util.ArrayList; +import java.util.Arrays; import java.util.Collection; import java.util.Date; import java.util.List; @@ -209,72 +209,61 @@ public class DemandeListUIHandler extends AbstractFaxToMailDemandListHandler<Dem updateEmailFilterWithContextEmailFilter(); - dataTable.getSelectionModel().addListSelectionListener(new ListSelectionListener() { + dataTable.getSelectionModel().addListSelectionListener(e -> { + ListSelectionModel source = (ListSelectionModel) e.getSource(); - @Override - public void valueChanged(ListSelectionEvent e) { - ListSelectionModel source = (ListSelectionModel) e.getSource(); + DemandeListUIModel model12 = getModel(); + if (source.isSelectionEmpty()) { + model12.setSelectedEmails(null); - DemandeListUIModel model = getModel(); - if (source.isSelectionEmpty()) { - model.setSelectedEmails(null); - - } else { - List<DemandeUIModel> selectedRows = new ArrayList<DemandeUIModel>(); - DemandeTableModel dataTableModel = (DemandeTableModel) dataTable.getModel(); - for (int i = source.getMinSelectionIndex(); i <= source.getMaxSelectionIndex(); i++) { - if (source.isSelectedIndex(i)) { - selectedRows.add(dataTableModel.getEntry(i)); - } + } else { + List<DemandeUIModel> selectedRows = new ArrayList<>(); + DemandeTableModel dataTableModel = (DemandeTableModel) dataTable.getModel(); + for (int i = source.getMinSelectionIndex(); i <= source.getMaxSelectionIndex(); i++) { + if (source.isSelectedIndex(i)) { + selectedRows.add(dataTableModel.getEntry(i)); } - model.setSelectedEmails(selectedRows); } + model12.setSelectedEmails(selectedRows); } }); - model.addPropertyChangeListener(DemandeListUIModel.PROPERTY_EMAILS, new PropertyChangeListener() { - @Override - public void propertyChange(PropertyChangeEvent evt) { - List<DemandeUIModel> emails = (List<DemandeUIModel>) evt.getNewValue(); - DemandeTableModel dataTableModel = (DemandeTableModel) dataTable.getModel(); - dataTableModel.setRows(emails); - - int quotationNb = 0; - int pfNb = 0; - int savNb = 0; - for (DemandeUIModel email : emails) { - quotationNb += email.getQuotationNb(); - pfNb += email.getPfNb(); - savNb += email.getSavNb(); - } - - DemandeListUIModel model = (DemandeListUIModel) evt.getSource(); - model.setQuotationNb(quotationNb); - model.setPfNb(pfNb); - model.setSavNb(savNb); + model.addPropertyChangeListener(DemandeListUIModel.PROPERTY_EMAILS, evt -> { + List<DemandeUIModel> emails = (List<DemandeUIModel>) evt.getNewValue(); + DemandeTableModel dataTableModel = (DemandeTableModel) dataTable.getModel(); + dataTableModel.setRows(emails); + + int quotationNb = 0; + int pfNb = 0; + int savNb = 0; + for (DemandeUIModel email : emails) { + quotationNb += email.getQuotationNb(); + pfNb += email.getPfNb(); + savNb += email.getSavNb(); } - }); - model.addPropertyChangeListener(DemandeListUIModel.PROPERTY_SELECTED_EMAILS, new PropertyChangeListener() { + DemandeListUIModel model1 = (DemandeListUIModel) evt.getSource(); + model1.setQuotationNb(quotationNb); + model1.setPfNb(pfNb); + model1.setSavNb(savNb); + }); - @Override - public void propertyChange(PropertyChangeEvent evt) { - List<DemandeUIModel> oldDemands = (List<DemandeUIModel>) evt.getOldValue(); - if (oldDemands != null) { - for (DemandeUIModel demand : oldDemands) { - demand.removePropertyChangeListener(selectedDemandeChangeListener); - } + model.addPropertyChangeListener(DemandeListUIModel.PROPERTY_SELECTED_EMAILS, evt -> { + List<DemandeUIModel> oldDemands = (List<DemandeUIModel>) evt.getOldValue(); + if (oldDemands != null) { + for (DemandeUIModel demand : oldDemands) { + demand.removePropertyChangeListener(selectedDemandeChangeListener); } + } - List<DemandeUIModel> newDemands = (List<DemandeUIModel>) evt.getNewValue(); - if (newDemands != null) { - for (DemandeUIModel demand : newDemands) { - demand.addPropertyChangeListener(selectedDemandeChangeListener); - } + List<DemandeUIModel> newDemands = (List<DemandeUIModel>) evt.getNewValue(); + if (newDemands != null) { + for (DemandeUIModel demand : newDemands) { + demand.addPropertyChangeListener(selectedDemandeChangeListener); } - - resetTimer(); } + + resetTimer(); }); // init tree @@ -286,34 +275,28 @@ public class DemandeListUIHandler extends AbstractFaxToMailDemandListHandler<Dem getContext().addPropertyChangeListener(FaxToMailUIContext.PROPERTY_ACTION_IN_PROGRESS, actionInProgressListener); - navigationTree.addTreeSelectionListener(new TreeSelectionListener() { - @Override - public void valueChanged(TreeSelectionEvent e) { - TableCellEditor cellEditor = dataTable.getCellEditor(); - if (cellEditor != null) { - cellEditor.stopCellEditing(); - } + navigationTree.addTreeSelectionListener(e -> { + TableCellEditor cellEditor = dataTable.getCellEditor(); + if (cellEditor != null) { + cellEditor.stopCellEditing(); + } - FolderTreeNode folderNode = (FolderTreeNode) e.getPath().getLastPathComponent(); - if (folderNode.isCanSelect()) { - MailFolder folder = folderNode.getMailFolder(); + FolderTreeNode folderNode = (FolderTreeNode) e.getPath().getLastPathComponent(); + if (folderNode.isCanSelect()) { + MailFolder folder = folderNode.getMailFolder(); - getModel().setSelectedFolder(folder); - } + getModel().setSelectedFolder(folder); } }); - model.addPropertyChangeListener(DemandeListUIModel.PROPERTY_SELECTED_FOLDER, new PropertyChangeListener() { - @Override - public void propertyChange(PropertyChangeEvent evt) { - MailFolder folder = (MailFolder) evt.getNewValue(); - getContext().setCurrentMailFolder(folder); - loadFolderDemands(nodesByFolder); - - DefaultMutableTreeNode node = nodesByFolder.get(folder); - if (node != null) { - navigationTree.setSelectionPath(new TreePath(node.getPath())); - } + model.addPropertyChangeListener(DemandeListUIModel.PROPERTY_SELECTED_FOLDER, evt -> { + MailFolder folder = (MailFolder) evt.getNewValue(); + getContext().setCurrentMailFolder(folder); + loadFolderDemands(nodesByFolder); + + DefaultMutableTreeNode node = nodesByFolder.get(folder); + if (node != null) { + navigationTree.setSelectionPath(new TreePath(node.getPath())); } }); @@ -322,12 +305,7 @@ public class DemandeListUIHandler extends AbstractFaxToMailDemandListHandler<Dem int resultPerPage = getConfig().getResultPerPage(); ui.getModel().setResultPerPage(resultPerPage); ui.getResultPerPageCombo().setSelectedItem(resultPerPage); - ui.getResultPerPageCombo().addItemListener(new ItemListener() { - @Override - public void itemStateChanged(ItemEvent e) { - updateResultPerPage(e); - } - }); + ui.getResultPerPageCombo().addItemListener(this::updateResultPerPage); // add refresh shortcut JRootPane rootPane = getContext().getMainUI().getRootPane(); @@ -337,13 +315,10 @@ public class DemandeListUIHandler extends AbstractFaxToMailDemandListHandler<Dem rootPane.getActionMap().put(REFRESH_FOLDER_ACTION, refreshAction); int interval = getConfig().getRefreshListInterval() * 1000; - refreshListTimer = new Timer(interval, new ActionListener() { - @Override - public void actionPerformed(ActionEvent e) { - LoadFolderEmailsAction refreshAction = getContext().getActionFactory() - .createLogicAction(DemandeListUIHandler.this, LoadFolderEmailsAction.class); - getContext().getActionEngine().runAction(refreshAction); - } + refreshListTimer = new Timer(interval, e -> { + LoadFolderEmailsAction refreshAction1 = getContext().getActionFactory() + .createLogicAction(DemandeListUIHandler.this, LoadFolderEmailsAction.class); + getContext().getActionEngine().runAction(refreshAction1); }); loadFolderDemands(nodesByFolder); @@ -369,10 +344,10 @@ public class DemandeListUIHandler extends AbstractFaxToMailDemandListHandler<Dem List<MailField> fields = getColumns(); if (CollectionUtils.isEmpty(fields)) { - fields = Lists.newArrayList(MailField.getTableFields()); + fields = Arrays.asList(MailField.getTableFields()); } - List<String> propertiesToBind = new ArrayList<String>(); + List<String> propertiesToBind = new ArrayList<>(); for (int i = 0; i < fields.size(); i++) { String property = null; @@ -561,22 +536,19 @@ public class DemandeListUIHandler extends AbstractFaxToMailDemandListHandler<Dem @Override public void initDemandeTable(final JXTable table, boolean sortable) { - HighlightPredicate reportNotTakenPredicate = new HighlightPredicate() { - @Override - public boolean isHighlighted(Component renderer, ComponentAdapter adapter) { - int viewRow = adapter.row; - int modelRow = adapter.convertRowIndexToModel(viewRow); - DemandeUIModel row = ((DemandeTableModel) table.getModel()).getEntry(modelRow); - MailFolder folder = getModel().getSelectedFolder(); - while (folder.getOpenAttachmentReportNoTaken() == null - && folder.getParent() != null) { - folder = folder.getParent(); - } - - return Boolean.TRUE.equals(folder.getOpenAttachmentReportNoTaken()) - && row.getLastAttachmentOpener() != null - && !row.getLastAttachmentOpener().equals(row.getTakenBy()); + HighlightPredicate reportNotTakenPredicate = (renderer, adapter) -> { + int viewRow = adapter.row; + int modelRow = adapter.convertRowIndexToModel(viewRow); + DemandeUIModel row = ((DemandeTableModel) table.getModel()).getEntry(modelRow); + MailFolder folder = getModel().getSelectedFolder(); + while (folder.getOpenAttachmentReportNoTaken() == null + && folder.getParent() != null) { + folder = folder.getParent(); } + + return Boolean.TRUE.equals(folder.getOpenAttachmentReportNoTaken()) + && row.getLastAttachmentOpener() != null + && !row.getLastAttachmentOpener().equals(row.getTakenBy()); }; Color color = Color.ORANGE; table.addHighlighter(new ColorHighlighter(reportNotTakenPredicate, color, Color.WHITE, color.darker(), Color.WHITE)); @@ -720,7 +692,7 @@ public class DemandeListUIHandler extends AbstractFaxToMailDemandListHandler<Dem FaxToMailUser currentUser = getContext().getCurrentUser(); Date now = new Date(); - List<History> histories = new ArrayList<History>(); + List<History> histories = new ArrayList<>(); DemandeUIModel email = new DemandeUIModel(); History history = new HistoryImpl(); history.setFaxToMailUser(currentUser); diff --git a/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/demande/DemandeListUIModel.java b/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/demande/DemandeListUIModel.java index 5469b49..2ae6b32 100644 --- a/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/demande/DemandeListUIModel.java +++ b/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/demande/DemandeListUIModel.java @@ -158,7 +158,7 @@ public class DemandeListUIModel extends AbstractSerializableBean { public void addEmail(DemandeUIModel email) { if (emails == null) { - emails = new ArrayList<DemandeUIModel>(); + emails = new ArrayList<>(); } Object oldValue = getEmailNb(); emails.add(email); diff --git a/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/demande/DemandeUIHandler.java b/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/demande/DemandeUIHandler.java index 888cea2..d4291ec 100644 --- a/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/demande/DemandeUIHandler.java +++ b/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/demande/DemandeUIHandler.java @@ -194,7 +194,7 @@ public class DemandeUIHandler extends AbstractFaxToMailUIHandler<DemandeUIModel, initBeanFilterableComboBox(ui.getStatusComboBox(), Arrays.asList(DemandStatus.values()), model.getDemandStatus()); // utilisation des etats d'attente défini pour le dossier (si défini) - List<DemandType> demandTypes = new ArrayList<DemandType>(); + List<DemandType> demandTypes = new ArrayList<>(); Collection<DemandType> folderDemandTypes = getDemandTypeForFolder(folder); if (CollectionUtils.isEmpty(folderDemandTypes)) { demandTypes.addAll(getContext().getDemandTypeCache()); @@ -204,7 +204,7 @@ public class DemandeUIHandler extends AbstractFaxToMailUIHandler<DemandeUIModel, initBeanFilterableComboBox(ui.getDocTypeComboBox(), demandTypes, model.getDemandType()); // utilisation des etats d'attente défini pour le dossier (si défini) - List<WaitingState> waitingStates = new ArrayList<WaitingState>(); + List<WaitingState> waitingStates = new ArrayList<>(); Collection<WaitingState> folderWaitingStates = getWaitingStateForFolder(folder); if (CollectionUtils.isEmpty(folderWaitingStates)) { waitingStates.addAll(getContext().getWaitingStateCache()); @@ -220,19 +220,14 @@ public class DemandeUIHandler extends AbstractFaxToMailUIHandler<DemandeUIModel, final JXTable table = ui.getRangeTable(); // utilisation des gammes défini pour le dossier (si défini) - List<Range> ranges = new ArrayList<Range>(); + List<Range> ranges = new ArrayList<>(); Collection<Range> folderRanges = getRangeForFolder(folder); if (CollectionUtils.isEmpty(folderRanges)) { ranges.addAll(getContext().getRangeCache()); } else { ranges.addAll(folderRanges); } - Collections.sort(ranges, new Comparator<Range>() { - @Override - public int compare(Range o1, Range o2) { - return ObjectUtils.compare(o1.getLabel(), o2.getLabel()); - } - }); + ranges.sort((o1, o2) -> ObjectUtils.compare(o1.getLabel(), o2.getLabel())); TableColumnModelExt columnModel = new DefaultTableColumnModelExt(); addComboDataColumnToModel(columnModel, @@ -256,7 +251,7 @@ public class DemandeUIHandler extends AbstractFaxToMailUIHandler<DemandeUIModel, // init range model final RangeTableModel rangeTableModel = new RangeTableModel(columnModel); - List<RangeRowModel> rangeRowModels = new ArrayList<RangeRowModel>(model.getValidRangeRowModels()); + List<RangeRowModel> rangeRowModels = new ArrayList<>(model.getValidRangeRowModels()); rangeTableModel.setRows(rangeRowModels); Map<String, Integer> quantities = FaxToMailUIUtil.computeQuantities(rangeRowModels); @@ -344,16 +339,12 @@ public class DemandeUIHandler extends AbstractFaxToMailUIHandler<DemandeUIModel, }; table.addKeyListener(keyAdapter); - HighlightPredicate rowIsInvalidPredicate = new HighlightPredicate() { - @Override - public boolean isHighlighted(Component renderer, ComponentAdapter adapter) { - AbstractApplicationTableModel model = (AbstractApplicationTableModel) table.getModel(); - int viewRow = adapter.row; - int modelRow = adapter.convertRowIndexToModel(viewRow); - RangeRowModel row = (RangeRowModel) model.getEntry(modelRow); - boolean result = !row.isValid(); - return result; - } + HighlightPredicate rowIsInvalidPredicate = (renderer, adapter) -> { + AbstractApplicationTableModel model1 = (AbstractApplicationTableModel) table.getModel(); + int viewRow = adapter.row; + int modelRow = adapter.convertRowIndexToModel(viewRow); + RangeRowModel row = (RangeRowModel) model1.getEntry(modelRow); + return !row.isValid(); }; Color color = new Color(255, 51, 51); table.addHighlighter(new ColorHighlighter(rowIsInvalidPredicate, color, Color.WHITE, color.darker(), Color.WHITE)); @@ -497,15 +488,14 @@ public class DemandeUIHandler extends AbstractFaxToMailUIHandler<DemandeUIModel, @Override public boolean quitUI() { - boolean result = quitScreen2( + + return quitScreen2( true, getModel().isModify(), t("faxtomail.demande.askCancelEditBeforeLeaving.cancelSave"), t("faxtomail.demande.askSaveBeforeLeaving.save"), getContext().getActionFactory().createLogicAction(this, SaveDemandeAction.class) ); - - return result; } @Override diff --git a/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/demande/DemandeUIModel.java b/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/demande/DemandeUIModel.java index 1810e85..fb074a0 100644 --- a/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/demande/DemandeUIModel.java +++ b/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/demande/DemandeUIModel.java @@ -43,7 +43,6 @@ import com.franciaflex.faxtomail.persistence.entities.WaitingState; import com.franciaflex.faxtomail.services.FaxToMailServiceUtils; import com.franciaflex.faxtomail.ui.swing.content.attachment.AttachmentModelAware; import com.franciaflex.faxtomail.ui.swing.util.AbstractFaxToMailBeanUIModel; -import com.google.common.collect.Lists; import jaxx.runtime.JAXXUtil; import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.lang3.StringUtils; @@ -62,10 +61,9 @@ import javax.mail.Part; import javax.mail.Session; import javax.mail.internet.MimeMessage; import javax.mail.internet.MimeMultipart; -import java.beans.PropertyChangeEvent; -import java.beans.PropertyChangeListener; import java.util.ArrayList; import java.util.Collection; +import java.util.Collections; import java.util.Date; import java.util.List; import java.util.Properties; @@ -95,13 +93,13 @@ public class DemandeUIModel extends AbstractFaxToMailBeanUIModel<Email, DemandeU protected final Email editObject = new EmailImpl(); - protected final List<Attachment> attachments = new ArrayList<Attachment>(); + protected final List<Attachment> attachments = new ArrayList<>(); - protected final List<Reply> replies = new ArrayList<Reply>(); + protected final List<Reply> replies = new ArrayList<>(); - protected final List<DemandeUIModel> groupedDemandes = new ArrayList<DemandeUIModel>(); + protected final List<DemandeUIModel> groupedDemandes = new ArrayList<>(); - protected final List<RangeRowModel> validRangeRowModels = new ArrayList<RangeRowModel>(); + protected final List<RangeRowModel> validRangeRowModels = new ArrayList<>(); protected int quotationNb; @@ -148,37 +146,34 @@ public class DemandeUIModel extends AbstractFaxToMailBeanUIModel<Email, DemandeU // } // }); - addPropertyChangeListener(Email.PROPERTY_RANGE_ROW, new PropertyChangeListener() { - @Override - public void propertyChange(PropertyChangeEvent evt) { - Collection<RangeRow> rangeRows = (Collection<RangeRow>) evt.getNewValue(); - int quotationNb = 0; - int pfNb = 0; - int savNb = 0; - if (rangeRows != null) { - for (RangeRow rangeRow : rangeRows) { - if (rangeRow != null) { - Integer quotationQuantity = rangeRow.getQuotationQuantity(); - if (quotationQuantity != null) { - quotationNb += quotationQuantity; - } - - Integer productQuantity = rangeRow.getProductQuantity(); - if (productQuantity != null) { - pfNb += productQuantity; - } - - Integer savQuantity = rangeRow.getSavQuantity(); - if (savQuantity != null) { - savNb += savQuantity; - } + addPropertyChangeListener(Email.PROPERTY_RANGE_ROW, evt -> { + Collection<RangeRow> rangeRows = (Collection<RangeRow>) evt.getNewValue(); + int quotationNb = 0; + int pfNb = 0; + int savNb = 0; + if (rangeRows != null) { + for (RangeRow rangeRow : rangeRows) { + if (rangeRow != null) { + Integer quotationQuantity = rangeRow.getQuotationQuantity(); + if (quotationQuantity != null) { + quotationNb += quotationQuantity; + } + + Integer productQuantity = rangeRow.getProductQuantity(); + if (productQuantity != null) { + pfNb += productQuantity; + } + + Integer savQuantity = rangeRow.getSavQuantity(); + if (savQuantity != null) { + savNb += savQuantity; } } } - setQuotationNb(quotationNb); - setPfNb(pfNb); - setSavNb(savNb); } + setQuotationNb(quotationNb); + setPfNb(pfNb); + setSavNb(savNb); }); } @@ -247,7 +242,7 @@ public class DemandeUIModel extends AbstractFaxToMailBeanUIModel<Email, DemandeU protected void loadAttachments(Email entity) { // On ne copie pas entierrement les attachments pour ne pas force le chargement du contenu binaire du fichier en mémoire. - List<Attachment> attachmentCopy = new ArrayList<Attachment>(); + List<Attachment> attachmentCopy = new ArrayList<>(); if (entity.getAttachment() != null) { for (Attachment attachment : entity.getAttachment()) { Attachment clone = new AttachmentImpl(); @@ -265,7 +260,7 @@ public class DemandeUIModel extends AbstractFaxToMailBeanUIModel<Email, DemandeU */ protected void loadReplies(Email entity) { - List<Reply> replyCopy = new ArrayList<Reply>(); + List<Reply> replyCopy = new ArrayList<>(); if (entity.getReplies() != null) { for (Reply reply : entity.getReplies()) { Reply clone = new ReplyImpl(); @@ -576,32 +571,32 @@ public class DemandeUIModel extends AbstractFaxToMailBeanUIModel<Email, DemandeU @Override public List<Attachment> getAttachment() { - return new ArrayList<Attachment>(attachments); + return new ArrayList<>(attachments); } @Override public void addAllAttachment(List<Attachment> attachment) { - Object oldValue = new ArrayList<Attachment>(getAttachment()); + Object oldValue = new ArrayList<>(getAttachment()); attachments.addAll(attachment); firePropertyChange(Email.PROPERTY_ATTACHMENT, oldValue, getAttachment()); } @Override public void addAttachment(Attachment attachment) { - Object oldValue = new ArrayList<Attachment>(getAttachment()); + Object oldValue = new ArrayList<>(getAttachment()); attachments.add(attachment); firePropertyChange(Email.PROPERTY_ATTACHMENT, oldValue, getAttachment()); } @Override public void removeAttachment(Attachment attachment) { - Object oldValue = new ArrayList<Attachment>(getAttachment()); + Object oldValue = new ArrayList<>(getAttachment()); attachments.remove(attachment); firePropertyChange(Email.PROPERTY_ATTACHMENT, oldValue, getAttachment()); } public void setAttachment(List<Attachment> attachment) { - Object oldValue = new ArrayList<Attachment>(getAttachment()); + Object oldValue = new ArrayList<>(getAttachment()); attachments.clear(); if (attachment != null) { attachments.addAll(attachment); @@ -616,7 +611,7 @@ public class DemandeUIModel extends AbstractFaxToMailBeanUIModel<Email, DemandeU public void addRangeRow(RangeRow rangeRow) { Object oldValue = null; if (getRangeRow() != null) { - oldValue = new ArrayList<RangeRow>(getRangeRow()); + oldValue = new ArrayList<>(getRangeRow()); } String refOldValue = getReference(); editObject.addRangeRow(rangeRow); @@ -627,7 +622,7 @@ public class DemandeUIModel extends AbstractFaxToMailBeanUIModel<Email, DemandeU public void addAllRangeRow(List<RangeRow> rangeRow) { Object oldValue = null; if (getRangeRow() != null) { - oldValue = new ArrayList<RangeRow>(getRangeRow()); + oldValue = new ArrayList<>(getRangeRow()); } String refOldValue = getReference(); editObject.addAllRangeRow(rangeRow); @@ -638,7 +633,7 @@ public class DemandeUIModel extends AbstractFaxToMailBeanUIModel<Email, DemandeU public void removeRangeRow(RangeRow rangeRow) { Object oldValue = null; if (getRangeRow() != null) { - oldValue = new ArrayList<RangeRow>(getRangeRow()); + oldValue = new ArrayList<>(getRangeRow()); } // on met à jour la référence, qui est la concaténation des numéros de commande et de "notre" référence String refOldValue = getReference(); @@ -648,12 +643,12 @@ public class DemandeUIModel extends AbstractFaxToMailBeanUIModel<Email, DemandeU } public void setRangeRow(List<RangeRow> rangeRow) { - ArrayList<RangeRow> oldValue = new ArrayList<RangeRow>(); + ArrayList<RangeRow> oldValue = new ArrayList<>(); if (getRangeRow() != null) { oldValue.addAll(getRangeRow()); } if (rangeRow == null) { - rangeRow = new ArrayList<RangeRow>(); + rangeRow = new ArrayList<>(); } // on met à jour la référence, qui est la concaténation des numéros de commande et de "notre" référence String refOldValue = getReference(); @@ -735,7 +730,7 @@ public class DemandeUIModel extends AbstractFaxToMailBeanUIModel<Email, DemandeU } public void setGroupedDemandes(EmailGroup emailGroup) { - Object oldValue = new ArrayList<DemandeUIModel>(getGroupedDemandes()); + Object oldValue = new ArrayList<>(getGroupedDemandes()); groupedDemandes.clear(); if (emailGroup != null) { Collection<Email> emails = emailGroup.getEmail(); @@ -758,7 +753,7 @@ public class DemandeUIModel extends AbstractFaxToMailBeanUIModel<Email, DemandeU } public void addGroupedDemande(DemandeUIModel demand) { - Object oldValue = new ArrayList<DemandeUIModel>(getGroupedDemandes()); + Object oldValue = new ArrayList<>(getGroupedDemandes()); groupedDemandes.add(demand); firePropertyChange(PROPERTY_GROUPED_DEMANDES, oldValue, getGroupedDemandes()); @@ -773,7 +768,7 @@ public class DemandeUIModel extends AbstractFaxToMailBeanUIModel<Email, DemandeU } public void addAllReplies(List<Reply> replies) { - Object oldValue = new ArrayList<Reply>(getReplies()); + Object oldValue = new ArrayList<>(getReplies()); editObject.addAllReplies(replies); firePropertyChange(Email.PROPERTY_REPLIES, oldValue, getAttachment()); } @@ -784,7 +779,7 @@ public class DemandeUIModel extends AbstractFaxToMailBeanUIModel<Email, DemandeU } public void removeReply(Reply reply) { - Object oldValue = new ArrayList<Reply>(getReplies()); + Object oldValue = new ArrayList<>(getReplies()); editObject.removeReplies(reply); firePropertyChange(Email.PROPERTY_REPLIES, oldValue, getReplies()); } @@ -808,14 +803,14 @@ public class DemandeUIModel extends AbstractFaxToMailBeanUIModel<Email, DemandeU } public void setValidRangeRowModels(List<RangeRowModel> validRangeRowModels) { - Object oldValue = new ArrayList<RangeRowModel>(validRangeRowModels); + Object oldValue = new ArrayList<>(validRangeRowModels); this.validRangeRowModels.clear(); this.validRangeRowModels.addAll(validRangeRowModels); firePropertyChanged(PROPERTY_VALID_RANGE_ROW_MODELS, oldValue, validRangeRowModels); } public void addValidRangeRow(RangeRowModel row) { - Object oldValue = new ArrayList<RangeRowModel>(validRangeRowModels); + Object oldValue = new ArrayList<>(validRangeRowModels); if (!validRangeRowModels.contains(row)) { validRangeRowModels.add(row); } @@ -823,13 +818,13 @@ public class DemandeUIModel extends AbstractFaxToMailBeanUIModel<Email, DemandeU } public void removeValidRangeRow(RangeRowModel row) { - Object oldValue = new ArrayList<RangeRowModel>(validRangeRowModels); + Object oldValue = new ArrayList<>(validRangeRowModels); validRangeRowModels.remove(row); firePropertyChanged(PROPERTY_VALID_RANGE_ROW_MODELS, oldValue, validRangeRowModels); } public void recomputeValidRangeRows() { - ArrayList<RangeRowModel> validRangeRowModels = new ArrayList<RangeRowModel>(); + ArrayList<RangeRowModel> validRangeRowModels = new ArrayList<>(); Collection<RangeRow> rangeRows = getRangeRow(); if (rangeRows != null) { for (RangeRow rangeRow : rangeRows) { @@ -936,8 +931,8 @@ public class DemandeUIModel extends AbstractFaxToMailBeanUIModel<Email, DemandeU subject = FaxToMailServiceUtils.getDecodedSubject(message.getSubject()); } - toRecipients = new ArrayList<String>(); - ccRecipients = new ArrayList<String>(); + toRecipients = new ArrayList<>(); + ccRecipients = new ArrayList<>(); Address[] recipients = message.getRecipients(Message.RecipientType.TO); if (recipients != null) { for (Address address : recipients) { @@ -959,7 +954,7 @@ public class DemandeUIModel extends AbstractFaxToMailBeanUIModel<Email, DemandeU } else if (message.isMimeType("text/*")) { String content = FaxToMailServiceUtils.getTextFromMessage(message); if (plainContents == null) { - plainContents = new ArrayList<String>(); + plainContents = new ArrayList<>(); } plainContents.add(JAXXUtil.getStringValue(content)); } @@ -969,8 +964,8 @@ public class DemandeUIModel extends AbstractFaxToMailBeanUIModel<Email, DemandeU log.warn("error while parsing the original email content, may come from the imported archives", e); } //may comes from the imported archives - plainContents = Lists.newArrayList(getOriginalEmailContent()); - toRecipients = Lists.newArrayList(getRecipient()); + plainContents = Collections.singletonList(getOriginalEmailContent()); + toRecipients = Collections.singletonList(getRecipient()); } } @@ -997,13 +992,13 @@ public class DemandeUIModel extends AbstractFaxToMailBeanUIModel<Email, DemandeU if (bp.isMimeType("text/plain")) { if (plainContents == null) { - plainContents = new ArrayList<String>(); + plainContents = new ArrayList<>(); } plainContents.add(JAXXUtil.getStringValue(content)); } else { if (htmlContents == null) { - htmlContents = new ArrayList<String>(); + htmlContents = new ArrayList<>(); } htmlContents.add(content); diff --git a/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/demande/DemandesUIHandler.java b/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/demande/DemandesUIHandler.java index fdebab4..9f6e881 100644 --- a/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/demande/DemandesUIHandler.java +++ b/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/demande/DemandesUIHandler.java @@ -108,29 +108,26 @@ public class DemandesUIHandler extends AbstractFaxToMailUIHandler<DemandesUIMode DemandesUIModel model = getModel(); // setCustomTab(0, getModel().getDemands().get(0)); - final PropertyChangeListener demandEnabledAndValidListener = new PropertyChangeListener() { - @Override - public void propertyChange(PropertyChangeEvent evt) { + final PropertyChangeListener demandEnabledAndValidListener = evt -> { - if (evt.getPropertyName().equals(DemandeUIModel.PROPERTY_VALID) - || evt.getPropertyName().equals(DemandeUIModel.PROPERTY_EDITABLE) - || evt.getPropertyName().equals(Email.PROPERTY_ARCHIVE_DATE)) { + if (evt.getPropertyName().equals(DemandeUIModel.PROPERTY_VALID) + || evt.getPropertyName().equals(DemandeUIModel.PROPERTY_EDITABLE) + || evt.getPropertyName().equals(Email.PROPERTY_ARCHIVE_DATE)) { - DemandesUI ui = getUI(); - ui.processDataBinding(DemandesUI.BINDING_ARCHIVE_BUTTON_ENABLED); - ui.processDataBinding(DemandesUI.BINDING_GROUP_BUTTON_ENABLED); - ui.processDataBinding(DemandesUI.BINDING_REPLY_BUTTON_ENABLED); - ui.processDataBinding(DemandesUI.BINDING_SAVE_BUTTON_ENABLED); - ui.processDataBinding(DemandesUI.BINDING_TRANSMIT_BUTTON_ENABLED); + DemandesUI ui1 = getUI(); + ui1.processDataBinding(DemandesUI.BINDING_ARCHIVE_BUTTON_ENABLED); + ui1.processDataBinding(DemandesUI.BINDING_GROUP_BUTTON_ENABLED); + ui1.processDataBinding(DemandesUI.BINDING_REPLY_BUTTON_ENABLED); + ui1.processDataBinding(DemandesUI.BINDING_SAVE_BUTTON_ENABLED); + ui1.processDataBinding(DemandesUI.BINDING_TRANSMIT_BUTTON_ENABLED); - } + } - if (evt.getPropertyName().equals(DemandeUIModel.PROPERTY_VALID) - || evt.getPropertyName().equals(DemandeUIModel.PROPERTY_EDITABLE) - || evt.getPropertyName().equals(Email.PROPERTY_WAITING_STATE)) { + if (evt.getPropertyName().equals(DemandeUIModel.PROPERTY_VALID) + || evt.getPropertyName().equals(DemandeUIModel.PROPERTY_EDITABLE) + || evt.getPropertyName().equals(Email.PROPERTY_WAITING_STATE)) { - updateButtonEnability(); - } + updateButtonEnability(); } }; diff --git a/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/demande/DemandesUIModel.java b/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/demande/DemandesUIModel.java index 9f7cf6b..39a1c1a 100644 --- a/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/demande/DemandesUIModel.java +++ b/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/demande/DemandesUIModel.java @@ -48,9 +48,9 @@ public class DemandesUIModel extends AbstractBean { protected boolean printEnabled; protected boolean replyEnabled; - protected List<DemandeUIModel> demands = new ArrayList<DemandeUIModel>(); + protected List<DemandeUIModel> demands = new ArrayList<>(); - protected List<com.franciaflex.faxtomail.ui.swing.content.demande.DemandsListener> listeners = new ArrayList<com.franciaflex.faxtomail.ui.swing.content.demande.DemandsListener>(); + protected List<com.franciaflex.faxtomail.ui.swing.content.demande.DemandsListener> listeners = new ArrayList<>(); protected int currentIndex = -1; diff --git a/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/demande/QuantitiesByRangeUIHandler.java b/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/demande/QuantitiesByRangeUIHandler.java index 87d0c1b..55cac16 100644 --- a/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/demande/QuantitiesByRangeUIHandler.java +++ b/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/demande/QuantitiesByRangeUIHandler.java @@ -32,9 +32,7 @@ import org.jdesktop.swingx.table.DefaultTableColumnModelExt; import org.jdesktop.swingx.table.TableColumnModelExt; import org.nuiton.jaxx.application.swing.util.Cancelable; -import javax.swing.*; -import java.beans.PropertyChangeEvent; -import java.beans.PropertyChangeListener; +import javax.swing.JComponent; import java.util.List; /** @@ -85,12 +83,7 @@ public class QuantitiesByRangeUIHandler extends AbstractFaxToMailUIHandler<Quant table.getTableHeader().setReorderingAllowed(false); getModel().addPropertyChangeListener(QuantitiesByRangeUIModel.PROPERTY_RANGE_ROWS, - new PropertyChangeListener() { - @Override - public void propertyChange(PropertyChangeEvent evt) { - setRangeRows((List<RangeRowModel>) evt.getNewValue()); - } - }); + evt -> setRangeRows((List<RangeRowModel>) evt.getNewValue())); } @Override diff --git a/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/demande/QuantitiesByRangeUIModel.java b/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/demande/QuantitiesByRangeUIModel.java index f15a041..733e854 100644 --- a/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/demande/QuantitiesByRangeUIModel.java +++ b/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/demande/QuantitiesByRangeUIModel.java @@ -42,7 +42,7 @@ public class QuantitiesByRangeUIModel extends AbstractBean { protected MailFolder rootFolder; - protected List<RangeRowModel> rangeRows = new ArrayList<RangeRowModel>(); + protected List<RangeRowModel> rangeRows = new ArrayList<>(); public MailFolder getRootFolder() { return rootFolder; @@ -59,7 +59,7 @@ public class QuantitiesByRangeUIModel extends AbstractBean { } public void setRangeRows(Collection<RangeRowModel> rangeRows) { - this.rangeRows = new ArrayList<RangeRowModel>(rangeRows); + this.rangeRows = new ArrayList<>(rangeRows); firePropertyChange(PROPERTY_RANGE_ROWS, null, this.rangeRows); } } diff --git a/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/demande/actions/ArchiveAction.java b/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/demande/actions/ArchiveAction.java index 0fad329..d548626 100644 --- a/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/demande/actions/ArchiveAction.java +++ b/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/demande/actions/ArchiveAction.java @@ -28,13 +28,11 @@ import com.franciaflex.faxtomail.persistence.entities.DemandStatus; import com.franciaflex.faxtomail.persistence.entities.MailFolder; import com.franciaflex.faxtomail.ui.swing.content.demande.DemandeUIHandler; import com.franciaflex.faxtomail.ui.swing.content.demande.DemandeUIModel; -import com.google.common.base.Optional; -import com.google.common.base.Predicate; -import com.google.common.collect.Iterables; -import javax.swing.*; +import javax.swing.JOptionPane; import java.util.Collection; import java.util.Date; +import java.util.Optional; import static org.nuiton.i18n.I18n.t; @@ -63,8 +61,7 @@ public class ArchiveAction extends SaveDemandeAndExitAction { JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE); - boolean result = i == JOptionPane.YES_OPTION; - return result; + return i == JOptionPane.YES_OPTION; } @Override @@ -87,12 +84,9 @@ public class ArchiveAction extends SaveDemandeAndExitAction { do { Collection<MailFolder> children = folder.getChildren(); if (children != null) { - Optional<MailFolder> optArchiveChild = Iterables.tryFind(children, new Predicate<MailFolder>() { - @Override - public boolean apply(MailFolder mailFolder) { - return mailFolder.isArchiveFolder(); - } - }); + Optional<MailFolder> optArchiveChild = children.stream() + .filter(MailFolder::isArchiveFolder) + .findAny(); if (optArchiveChild.isPresent()) { archiveChild = optArchiveChild.get(); } diff --git a/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/demande/actions/ArchiveFromListAction.java b/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/demande/actions/ArchiveFromListAction.java index 0bc0695..5bfffb6 100644 --- a/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/demande/actions/ArchiveFromListAction.java +++ b/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/demande/actions/ArchiveFromListAction.java @@ -30,14 +30,12 @@ import com.franciaflex.faxtomail.persistence.entities.MailAction; import com.franciaflex.faxtomail.persistence.entities.MailFolder; import com.franciaflex.faxtomail.ui.swing.content.demande.DemandeListUIHandler; import com.franciaflex.faxtomail.ui.swing.content.demande.DemandeUIModel; -import com.google.common.base.Optional; -import com.google.common.base.Predicate; -import com.google.common.collect.Iterables; -import javax.swing.*; +import javax.swing.JOptionPane; import java.util.ArrayList; import java.util.Date; import java.util.List; +import java.util.Optional; import static org.nuiton.i18n.I18n.t; @@ -58,7 +56,7 @@ public class ArchiveFromListAction extends SaveDemandeFromListAction { public boolean prepareAction() throws Exception { boolean result = super.prepareAction(); - demandsToArchive = new ArrayList<DemandeUIModel>(); + demandsToArchive = new ArrayList<>(); List<DemandeUIModel> currentEmails = getModel().getSelectedEmails(); String notArchivableDemandTitles = ""; @@ -113,12 +111,9 @@ public class ArchiveFromListAction extends SaveDemandeFromListAction { MailFolder archiveChild = null; do { if (folder.getChildren() != null) { - Optional<MailFolder> optArchiveChild = Iterables.tryFind(folder.getChildren(), new Predicate<MailFolder>() { - @Override - public boolean apply(MailFolder mailFolder) { - return mailFolder.isArchiveFolder(); - } - }); + Optional<MailFolder> optArchiveChild = folder.getChildren().stream() + .filter(MailFolder::isArchiveFolder) + .findAny(); if (optArchiveChild.isPresent()) { archiveChild = optArchiveChild.get(); } diff --git a/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/demande/actions/LoadFolderEmailsAction.java b/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/demande/actions/LoadFolderEmailsAction.java index fdef7ad..8385f73 100644 --- a/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/demande/actions/LoadFolderEmailsAction.java +++ b/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/demande/actions/LoadFolderEmailsAction.java @@ -36,12 +36,11 @@ import com.franciaflex.faxtomail.ui.swing.content.demande.DemandeListUIHandler; import com.franciaflex.faxtomail.ui.swing.content.demande.DemandeListUIModel; import com.franciaflex.faxtomail.ui.swing.content.demande.DemandeUIModel; import com.franciaflex.faxtomail.ui.swing.util.DemandeTableModel; -import com.google.common.collect.Maps; import com.google.common.collect.Sets; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.jdesktop.swingx.JXTable; -import org.nuiton.topia.persistence.TopiaEntities; +import org.nuiton.topia.persistence.TopiaEntity; import org.nuiton.util.pagination.PaginationResult; import java.util.ArrayList; @@ -49,13 +48,15 @@ import java.util.Collection; import java.util.HashSet; import java.util.List; import java.util.Map; +import java.util.function.Function; +import java.util.stream.Collectors; import static org.nuiton.i18n.I18n.t; /** * Action de chargement des demandes d'un dossier lors de la selection d'un dossier dans l'arbre * des dossiers. - * + * * @author Kevin Morin (Code Lutin) */ public class LoadFolderEmailsAction extends AbstractFaxToMailAction<DemandeListUIModel, DemandeListUI, DemandeListUIHandler> { @@ -80,7 +81,7 @@ public class LoadFolderEmailsAction extends AbstractFaxToMailAction<DemandeListU //FIXME enlever la rustine FaxToMailUIContext.FolderData currentFolderEmails = getContext().getCurrentFolderEmails(); if (getContext().isUseFolderCache() && folder.equals(currentFolderEmails.getFolder())) { - model.setEmails(new ArrayList<DemandeUIModel>(currentFolderEmails.getDemands())); + model.setEmails(new ArrayList<>(currentFolderEmails.getDemands())); PaginationResult<Email> paginationResult = currentFolderEmails.getPaginationResult(); model.setPaginationParameter(paginationResult.getCurrentPage()); model.setPaginationResult(paginationResult); @@ -115,25 +116,26 @@ public class LoadFolderEmailsAction extends AbstractFaxToMailAction<DemandeListU FaxToMailUser currentUser = getContext().getCurrentUser(); List<MailField> columns = handler.getColumns(); - Collection<MailField> fields = new HashSet<MailField>(); + Collection<MailField> fields = new HashSet<>(); if (columns != null) { fields.addAll(columns); } fields.add(MailField.TAKEN_BY); PaginationResult<Email> paginationResult = getContext().newServiceContext().getEmailService() - .getEmailForFolder(folder, - currentUser, - getModel().getEmailFilter(), - model.getPaginationParameter()); + .getEmailForFolder(folder, + currentUser, + getModel().getEmailFilter(), + model.getPaginationParameter()); List<Email> emails = paginationResult.getElements(); if (log.isDebugEnabled()) { log.debug(emails.size() + " emails in folder " + folder.getName()); } - Map<String, WaitingState> waitingStateById = Maps.uniqueIndex(getContext().getWaitingStateCache(), TopiaEntities.getTopiaIdFunction()); + Map<String, WaitingState> waitingStateById = getContext().getWaitingStateCache().stream() + .collect(Collectors.toMap(TopiaEntity::getTopiaId, Function.identity())); - List<DemandeUIModel> demands = new ArrayList<DemandeUIModel>(); + List<DemandeUIModel> demands = new ArrayList<>(); for (Email email : emails) { DemandeUIModel demand = new DemandeUIModel(); demand.fromEntityExcluding(email, Sets.newHashSet(Email.PROPERTY_MAIL_FOLDER, Email.PROPERTY_HISTORY)); diff --git a/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/demande/actions/OpenMailFolderChooserFromListAction.java b/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/demande/actions/OpenMailFolderChooserFromListAction.java index 953735f..c2eda5c 100644 --- a/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/demande/actions/OpenMailFolderChooserFromListAction.java +++ b/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/demande/actions/OpenMailFolderChooserFromListAction.java @@ -62,7 +62,7 @@ public class OpenMailFolderChooserFromListAction extends AbstractFaxToMailAction boolean result = super.prepareAction(); List<DemandeUIModel> selectedEmails = getModel().getSelectedEmails(); - demandsToTransmit = new ArrayList<DemandeUIModel>(); + demandsToTransmit = new ArrayList<>(); String notTransmitableDemandsTitle = ""; for (DemandeUIModel demandeUIModel : selectedEmails) { @@ -105,15 +105,12 @@ public class OpenMailFolderChooserFromListAction extends AbstractFaxToMailAction @Override public void propertyChange(PropertyChangeEvent evt) { if (!getContext().isBusy()) { - SwingUtilities.invokeLater(new Runnable() { - @Override - public void run() { - - bringCurrentDemandToFront(); - if (frame != null) { - frame.toFront(); - frame = null; - } + SwingUtilities.invokeLater(() -> { + + bringCurrentDemandToFront(); + if (frame != null) { + frame.toFront(); + frame = null; } }); getContext().removePropertyChangeListener(FaxToMailUIContext.PROPERTY_BUSY, this); diff --git a/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/demande/actions/OpenReplyFormAction.java b/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/demande/actions/OpenReplyFormAction.java index 545029b..73c7255 100644 --- a/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/demande/actions/OpenReplyFormAction.java +++ b/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/demande/actions/OpenReplyFormAction.java @@ -77,7 +77,7 @@ public class OpenReplyFormAction extends AbstractFaxToMailAction<DemandeListUIMo SigningForDomain signingForDomain = null; if (!demand.isFax() && demand.getRecipient() != null) { - signingForDomain = getContext().newServiceContext().getConfigurationService().getSigningForEmailAddress(demand.getRecipient()).orNull(); + signingForDomain = getContext().newServiceContext().getConfigurationService().getSigningForEmailAddress(demand.getRecipient()); } model.setSigning(signingForDomain); @@ -103,15 +103,12 @@ public class OpenReplyFormAction extends AbstractFaxToMailAction<DemandeListUIMo @Override public void propertyChange(PropertyChangeEvent evt) { if (!getContext().isBusy()) { - SwingUtilities.invokeLater(new Runnable() { - @Override - public void run() { - - bringCurrentDemandToFront(); - if (frame != null) { - frame.toFront(); - frame = null; - } + SwingUtilities.invokeLater(() -> { + + bringCurrentDemandToFront(); + if (frame != null) { + frame.toFront(); + frame = null; } }); getContext().removePropertyChangeListener(FaxToMailUIContext.PROPERTY_BUSY, this); diff --git a/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/demande/actions/SaveAndOpenModalFrameAction.java b/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/demande/actions/SaveAndOpenModalFrameAction.java index bece8d4..2f872de 100644 --- a/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/demande/actions/SaveAndOpenModalFrameAction.java +++ b/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/demande/actions/SaveAndOpenModalFrameAction.java @@ -58,15 +58,12 @@ public abstract class SaveAndOpenModalFrameAction<FC extends ApplicationUI> exte @Override public void propertyChange(PropertyChangeEvent evt) { if (!getContext().isBusy()) { - SwingUtilities.invokeLater(new Runnable() { - @Override - public void run() { + SwingUtilities.invokeLater(() -> { - bringCurrentDemandToFront(); - if (frame != null) { - frame.toFront(); - frame = null; - } + bringCurrentDemandToFront(); + if (frame != null) { + frame.toFront(); + frame = null; } }); getContext().removePropertyChangeListener(FaxToMailUIContext.PROPERTY_BUSY, this); diff --git a/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/demande/actions/SaveAndOpenReplyFormAction.java b/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/demande/actions/SaveAndOpenReplyFormAction.java index 13d52b4..0249d99 100644 --- a/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/demande/actions/SaveAndOpenReplyFormAction.java +++ b/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/demande/actions/SaveAndOpenReplyFormAction.java @@ -66,7 +66,7 @@ public class SaveAndOpenReplyFormAction extends SaveAndOpenModalFrameAction<Repl SigningForDomain signingForDomain = null; if (!currentDemand.isFax() && currentDemand.getRecipient() != null) { - signingForDomain = getContext().newServiceContext().getConfigurationService().getSigningForEmailAddress(currentDemand.getRecipient()).orNull(); + signingForDomain = getContext().newServiceContext().getConfigurationService().getSigningForEmailAddress(currentDemand.getRecipient()); } model.setSigning(signingForDomain); diff --git a/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/demande/actions/SaveDemandeAction.java b/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/demande/actions/SaveDemandeAction.java index ae1fe1b..f124522 100644 --- a/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/demande/actions/SaveDemandeAction.java +++ b/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/demande/actions/SaveDemandeAction.java @@ -40,14 +40,15 @@ import com.franciaflex.faxtomail.ui.swing.content.demande.DemandeUIHandler; import com.franciaflex.faxtomail.ui.swing.content.demande.DemandeUIModel; import com.franciaflex.faxtomail.ui.swing.content.demande.RangeRowModel; import com.franciaflex.faxtomail.ui.swing.content.demande.RangeTableModel; -import com.google.common.collect.Maps; import org.apache.commons.lang3.StringUtils; -import org.nuiton.topia.persistence.TopiaEntities; +import org.nuiton.topia.persistence.TopiaEntity; import org.nuiton.util.beans.BeanMonitor; import java.util.ArrayList; import java.util.Collection; import java.util.Map; +import java.util.function.Function; +import java.util.stream.Collectors; import static org.nuiton.i18n.I18n.t; @@ -103,9 +104,10 @@ public class SaveDemandeAction extends AbstractFaxToMailAction<DemandeUIModel, D rangeRows = new ArrayList<>(); } - Map<String, RangeRow> rangeRowsById = Maps.uniqueIndex(rangeRows, TopiaEntities.getTopiaIdFunction()); + Map<String, RangeRow> rangeRowsById = rangeRows.stream() + .collect(Collectors.toMap(TopiaEntity::getTopiaId, Function.identity())); - model.setRangeRow(new ArrayList<RangeRow>()); + model.setRangeRow(new ArrayList<>()); for (RangeRowModel rangeRowModel : rows) { RangeRow rangeRow = rangeRowsById.get(rangeRowModel.getTopiaId()); if (rangeRow == null) { @@ -145,7 +147,7 @@ public class SaveDemandeAction extends AbstractFaxToMailAction<DemandeUIModel, D // reload range rows with ids RangeTableModel rangeTableModel = (RangeTableModel) getUI().getRangeTable().getModel(); model.recomputeValidRangeRows(); - rangeTableModel.setRows(new ArrayList<RangeRowModel>(model.getValidRangeRowModels())); + rangeTableModel.setRows(new ArrayList<>(model.getValidRangeRowModels())); getModel().setModify(false); monitor.clearModified(); diff --git a/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/demande/demandgroup/DemandGroupHighlightDialog.java b/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/demande/demandgroup/DemandGroupHighlightDialog.java index d642b9d..bd80cee 100644 --- a/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/demande/demandgroup/DemandGroupHighlightDialog.java +++ b/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/demande/demandgroup/DemandGroupHighlightDialog.java @@ -56,11 +56,7 @@ public class DemandGroupHighlightDialog extends JDialog { if (delayGroupedDemandWarningDialog > 0) { - timer = new Timer(delayGroupedDemandWarningDialog, new ActionListener() { - public void actionPerformed(ActionEvent e) { - dispose(); - } - }); + timer = new Timer(delayGroupedDemandWarningDialog, e -> dispose()); } else { timer = null; diff --git a/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/demande/demandgroup/DemandGroupUIHandler.java b/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/demande/demandgroup/DemandGroupUIHandler.java index 356f8e1..fe35ab9 100644 --- a/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/demande/demandgroup/DemandGroupUIHandler.java +++ b/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/demande/demandgroup/DemandGroupUIHandler.java @@ -24,17 +24,17 @@ package com.franciaflex.faxtomail.ui.swing.content.demande.demandgroup; * #L% */ -import com.franciaflex.faxtomail.ui.swing.content.demande.demandgroup.actions.OpenGroupedDemandAction; import com.franciaflex.faxtomail.ui.swing.content.demande.DemandeUIModel; +import com.franciaflex.faxtomail.ui.swing.content.demande.demandgroup.actions.OpenGroupedDemandAction; import com.franciaflex.faxtomail.ui.swing.util.toolbar.AbstractToolbarPopupHandler; -import com.google.common.collect.Iterables; import jaxx.runtime.validator.swing.SwingValidator; +import org.apache.commons.collections4.CollectionUtils; import org.jdesktop.swingx.JXTable; import org.jdesktop.swingx.decorator.HighlighterFactory; -import javax.swing.*; -import javax.swing.event.TableModelEvent; -import javax.swing.event.TableModelListener; +import javax.swing.AbstractCellEditor; +import javax.swing.JComponent; +import javax.swing.JTable; import javax.swing.table.AbstractTableModel; import javax.swing.table.DefaultTableColumnModel; import javax.swing.table.TableCellEditor; @@ -42,7 +42,7 @@ import javax.swing.table.TableCellRenderer; import javax.swing.table.TableColumn; import javax.swing.table.TableColumnModel; import javax.swing.table.TableModel; -import java.awt.*; +import java.awt.Component; import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeListener; @@ -92,7 +92,7 @@ public class DemandGroupUIHandler extends AbstractToolbarPopupHandler<DemandeUIM @Override public Object getValueAt(int rowIndex, int columnIndex) { - return Iterables.get(getModel().getGroupedDemandes(), rowIndex); + return CollectionUtils.get(getModel().getGroupedDemandes(), rowIndex); } @Override @@ -101,12 +101,7 @@ public class DemandGroupUIHandler extends AbstractToolbarPopupHandler<DemandeUIM } }; - demandGroupTableModel.addTableModelListener(new TableModelListener() { - @Override - public void tableChanged(TableModelEvent e) { - getUI().pack(); - } - }); + demandGroupTableModel.addTableModelListener(e -> getUI().pack()); TableColumnModel columnModel = new DefaultTableColumnModel(); TableColumn column = new TableColumn(); diff --git a/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/demande/history/HistoryListUIHandler.java b/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/demande/history/HistoryListUIHandler.java index 3d9278f..61aba18 100644 --- a/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/demande/history/HistoryListUIHandler.java +++ b/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/demande/history/HistoryListUIHandler.java @@ -27,10 +27,8 @@ package com.franciaflex.faxtomail.ui.swing.content.demande.history; import com.franciaflex.faxtomail.persistence.entities.Email; import com.franciaflex.faxtomail.persistence.entities.History; import com.franciaflex.faxtomail.ui.swing.content.demande.DemandeUIModel; -import com.franciaflex.faxtomail.ui.swing.util.toolbar.AbstractToolbarPopupHandler; import com.franciaflex.faxtomail.ui.swing.util.FaxToMailUIUtil; -import com.google.common.base.Function; -import com.google.common.collect.Ordering; +import com.franciaflex.faxtomail.ui.swing.util.toolbar.AbstractToolbarPopupHandler; import jaxx.runtime.JAXXUtil; import jaxx.runtime.SwingUtil; import jaxx.runtime.swing.model.JaxxDefaultListModel; @@ -41,8 +39,15 @@ import org.jdesktop.swingx.JXList; import org.jdesktop.swingx.decorator.HighlighterFactory; import org.nuiton.i18n.I18n; -import javax.swing.*; -import java.awt.*; +import javax.swing.AbstractAction; +import javax.swing.Action; +import javax.swing.ImageIcon; +import javax.swing.JButton; +import javax.swing.JComponent; +import javax.swing.JList; +import javax.swing.ListCellRenderer; +import java.awt.Component; +import java.awt.Toolkit; import java.awt.datatransfer.Clipboard; import java.awt.datatransfer.StringSelection; import java.awt.event.ActionEvent; @@ -50,7 +55,7 @@ import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeListener; import java.util.ArrayList; import java.util.Collection; -import java.util.Collections; +import java.util.Comparator; import java.util.List; import java.util.Set; @@ -90,43 +95,32 @@ public class HistoryListUIHandler extends AbstractToolbarPopupHandler<DemandeUIM final JXList list = ui.getHistories(); list.setCellRenderer(new HistoryListCellRenderer()); - JaxxDefaultListModel<History> listModel = new JaxxDefaultListModel<History>(); - List<History> histories = new ArrayList<History>(); + JaxxDefaultListModel<History> listModel = new JaxxDefaultListModel<>(); + List<History> histories = new ArrayList<>(); listModel.setAllElements(histories); list.setModel(listModel); list.addHighlighter(HighlighterFactory.createAlternateStriping()); - final PropertyChangeListener listener = new PropertyChangeListener() { - @Override - public void propertyChange(PropertyChangeEvent evt) { - Collection<History> newValue = (Collection<History>) evt.getNewValue(); - List<History> histories = new ArrayList<History>(); - if (newValue != null) { - histories.addAll(newValue); - } - //sort histories by modification date - Collections.sort(histories, Ordering.natural().onResultOf(new Function<History, Comparable>() { - @Override - public Comparable apply(History history) { - return history.getModificationDate(); - } - })); - ((JaxxDefaultListModel) getUI().getHistories().getModel()).setAllElements(histories); + final PropertyChangeListener listener = evt -> { + Collection<History> newValue = (Collection<History>) evt.getNewValue(); + List<History> histories1 = new ArrayList<>(); + if (newValue != null) { + histories1.addAll(newValue); } + //sort histories by modification date + histories1.sort(Comparator.comparing(History::getModificationDate)); + ((JaxxDefaultListModel) getUI().getHistories().getModel()).setAllElements(histories1); }; - getUI().addPropertyChangeListener(HistoryListUI.PROPERTY_MODEL, new PropertyChangeListener() { - @Override - public void propertyChange(PropertyChangeEvent evt) { - DemandeUIModel oldModel = (DemandeUIModel) evt.getOldValue(); - if (oldModel != null) { - oldModel.removePropertyChangeListener(Email.PROPERTY_HISTORY, listener); - } - DemandeUIModel newModel = (DemandeUIModel) evt.getNewValue(); - if (newModel != null) { - newModel.addPropertyChangeListener(Email.PROPERTY_HISTORY, listener); - listener.propertyChange(new PropertyChangeEvent(newModel, Email.PROPERTY_HISTORY, null, newModel.getHistory())); - } + getUI().addPropertyChangeListener(HistoryListUI.PROPERTY_MODEL, evt -> { + DemandeUIModel oldModel = (DemandeUIModel) evt.getOldValue(); + if (oldModel != null) { + oldModel.removePropertyChangeListener(Email.PROPERTY_HISTORY, listener); + } + DemandeUIModel newModel = (DemandeUIModel) evt.getNewValue(); + if (newModel != null) { + newModel.addPropertyChangeListener(Email.PROPERTY_HISTORY, listener); + listener.propertyChange(new PropertyChangeEvent(newModel, Email.PROPERTY_HISTORY, null, newModel.getHistory())); } }); @@ -191,7 +185,7 @@ public class HistoryListUIHandler extends AbstractToolbarPopupHandler<DemandeUIM } public String decorateFields(Set<String> fields) { - List<String> fieldLabels = new ArrayList<String>(); + List<String> fieldLabels = new ArrayList<>(); if (fields != null) { for (String field : fields) { String label; @@ -212,14 +206,11 @@ public class HistoryListUIHandler extends AbstractToolbarPopupHandler<DemandeUIM public HistoryListCellRenderer() { super(HistoryListUIHandler.this); - getModel().addPropertyChangeListener(HistoryItemModel.PROPERTY_FIELDS, new PropertyChangeListener() { - @Override - public void propertyChange(PropertyChangeEvent evt) { - if (evt.getNewValue() != null) { - add(getFields(), 1); - } else { - remove(getFields()); - } + getModel().addPropertyChangeListener(HistoryItemModel.PROPERTY_FIELDS, evt -> { + if (evt.getNewValue() != null) { + add(getFields(), 1); + } else { + remove(getFields()); } }); } diff --git a/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/demande/replies/ButtonDemandReplies.java b/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/demande/replies/ButtonDemandReplies.java index 2143127..46647f3 100644 --- a/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/demande/replies/ButtonDemandReplies.java +++ b/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/demande/replies/ButtonDemandReplies.java @@ -90,9 +90,8 @@ public class ButtonDemandReplies extends AbstractToolbarPopupButton<DemandReplie @Override protected DemandRepliesUI createNewPopup() { - DemandRepliesUI ui = new DemandRepliesUI(FaxToMailUIContext.getApplicationContext(), - JAXXWidgetUtil.getParentContainer(this, JFrame.class)); - return ui; + return new DemandRepliesUI(FaxToMailUIContext.getApplicationContext(), + JAXXWidgetUtil.getParentContainer(this, JFrame.class)); } public DemandeUIModel getBean() { diff --git a/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/demande/replies/DemandRepliesUIHandler.java b/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/demande/replies/DemandRepliesUIHandler.java index b4ec12d..212e894 100644 --- a/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/demande/replies/DemandRepliesUIHandler.java +++ b/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/demande/replies/DemandRepliesUIHandler.java @@ -40,9 +40,9 @@ import com.franciaflex.faxtomail.ui.swing.content.reply.ReplyFormUI; import com.franciaflex.faxtomail.ui.swing.content.reply.ReplyFormUIModel; import com.franciaflex.faxtomail.ui.swing.util.FaxToMailUIUtil; import com.franciaflex.faxtomail.ui.swing.util.toolbar.AbstractToolbarPopupHandler; -import com.google.common.collect.Iterables; import jaxx.runtime.JAXXUtil; import jaxx.runtime.validator.swing.SwingValidator; +import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.apache.commons.mail.util.MimeMessageUtils; @@ -59,8 +59,6 @@ import javax.mail.internet.MimeUtility; import javax.swing.AbstractCellEditor; import javax.swing.JComponent; import javax.swing.JTable; -import javax.swing.event.TableModelEvent; -import javax.swing.event.TableModelListener; import javax.swing.table.AbstractTableModel; import javax.swing.table.DefaultTableColumnModel; import javax.swing.table.TableCellEditor; @@ -70,7 +68,6 @@ import javax.swing.table.TableColumnModel; import javax.swing.table.TableModel; import java.awt.Component; import java.awt.Dimension; -import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeListener; import java.io.ByteArrayOutputStream; import java.util.regex.Pattern; @@ -91,28 +88,22 @@ public class DemandRepliesUIHandler extends AbstractToolbarPopupHandler<DemandeU initTable(ui.getReplies()); - final PropertyChangeListener listener = new PropertyChangeListener() { - @Override - public void propertyChange(PropertyChangeEvent evt) { - updateTable(); - JAXXUtil.processDataBinding(getUI(), - DemandRepliesUI.BINDING_NO_REPLY_LABEL_VISIBLE, - DemandRepliesUI.BINDING_REPLIES_VISIBLE); - } + final PropertyChangeListener listener = evt -> { + updateTable(); + JAXXUtil.processDataBinding(getUI(), + DemandRepliesUI.BINDING_NO_REPLY_LABEL_VISIBLE, + DemandRepliesUI.BINDING_REPLIES_VISIBLE); }; - getUI().addPropertyChangeListener(DemandRepliesUI.PROPERTY_MODEL, new PropertyChangeListener() { - @Override - public void propertyChange(PropertyChangeEvent evt) { - DemandeUIModel oldModel = (DemandeUIModel) evt.getOldValue(); - if (oldModel != null) { - oldModel.removePropertyChangeListener(Email.PROPERTY_REPLIES, listener); - } - DemandeUIModel newModel = (DemandeUIModel) evt.getNewValue(); - if (newModel != null) { - newModel.addPropertyChangeListener(Email.PROPERTY_REPLIES, listener); - } - updateTable(); + getUI().addPropertyChangeListener(DemandRepliesUI.PROPERTY_MODEL, evt -> { + DemandeUIModel oldModel = (DemandeUIModel) evt.getOldValue(); + if (oldModel != null) { + oldModel.removePropertyChangeListener(Email.PROPERTY_REPLIES, listener); } + DemandeUIModel newModel = (DemandeUIModel) evt.getNewValue(); + if (newModel != null) { + newModel.addPropertyChangeListener(Email.PROPERTY_REPLIES, listener); + } + updateTable(); }); } @@ -127,8 +118,7 @@ public class DemandRepliesUIHandler extends AbstractToolbarPopupHandler<DemandeU @Override public int getRowCount() { DemandeUIModel model = getModel(); - int count = model == null ? 0 : model.sizeReplies(); - return count; + return model == null ? 0 : model.sizeReplies(); } @Override @@ -139,7 +129,7 @@ public class DemandRepliesUIHandler extends AbstractToolbarPopupHandler<DemandeU @Override public Object getValueAt(int rowIndex, int columnIndex) { DemandeUIModel model = getModel(); - return model == null ? null : Iterables.get(model.getReplies(), rowIndex); + return model == null ? null : CollectionUtils.get(model.getReplies(), rowIndex); } @Override @@ -148,12 +138,7 @@ public class DemandRepliesUIHandler extends AbstractToolbarPopupHandler<DemandeU } }; - demandRepliesTableModel.addTableModelListener(new TableModelListener() { - @Override - public void tableChanged(TableModelEvent e) { - getUI().pack(); - } - }); + demandRepliesTableModel.addTableModelListener(e -> getUI().pack()); TableColumnModel columnModel = new DefaultTableColumnModel(); TableColumn column = new TableColumn(); diff --git a/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/demande/replies/RepliesCellEditor.java b/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/demande/replies/RepliesCellEditor.java index 2935405..1b4d83a 100644 --- a/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/demande/replies/RepliesCellEditor.java +++ b/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/demande/replies/RepliesCellEditor.java @@ -28,17 +28,19 @@ import com.franciaflex.faxtomail.ui.swing.FaxToMailUIContext; import com.franciaflex.faxtomail.ui.swing.content.demande.DemandeUIModel; import com.franciaflex.faxtomail.ui.swing.util.DemandeTableModel; import com.franciaflex.faxtomail.ui.swing.util.FaxToMailUI; -import com.google.common.base.Preconditions; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import javax.swing.*; +import javax.swing.AbstractCellEditor; +import javax.swing.JTable; import javax.swing.border.LineBorder; import javax.swing.event.CellEditorListener; import javax.swing.event.ChangeEvent; import javax.swing.table.TableCellEditor; -import java.awt.*; +import java.awt.Color; +import java.awt.Component; import java.util.EventObject; +import java.util.Objects; /** * To edit replies from a table cell. @@ -103,7 +105,7 @@ public class RepliesCellEditor extends AbstractCellEditor implements TableCellEd public Object getCellEditorValue() { DemandeUIModel model = editorButton.getBean(); - Preconditions.checkNotNull(model, "No model found in editor."); + Objects.requireNonNull(model, "No model found in editor."); Object result = model.getReplies(); if (log.isDebugEnabled()) { diff --git a/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/demande/replies/actions/OpenReplyAction.java b/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/demande/replies/actions/OpenReplyAction.java index db85c6d..0f55718 100644 --- a/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/demande/replies/actions/OpenReplyAction.java +++ b/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/demande/replies/actions/OpenReplyAction.java @@ -43,11 +43,11 @@ import org.apache.commons.lang3.StringUtils; import org.apache.commons.mail.util.MimeMessageUtils; import javax.mail.internet.MimeMessage; -import java.beans.PropertyChangeEvent; -import java.beans.PropertyChangeListener; import javax.swing.JFrame; import javax.swing.SwingUtilities; import java.awt.Dimension; +import java.beans.PropertyChangeEvent; +import java.beans.PropertyChangeListener; import static org.nuiton.i18n.I18n.t; @@ -120,13 +120,10 @@ public class OpenReplyAction extends AbstractFaxToMailAction<DemandeUIModel, Dem @Override public void propertyChange(PropertyChangeEvent evt) { if (!getContext().isBusy()) { - SwingUtilities.invokeLater(new Runnable() { - @Override - public void run() { - if (frame != null) { - frame.toFront(); - frame = null; - } + SwingUtilities.invokeLater(() -> { + if (frame != null) { + frame.toFront(); + frame = null; } }); getContext().removePropertyChangeListener(FaxToMailUIContext.PROPERTY_BUSY, this); diff --git a/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/pdfeditor/PDFEditorUIHandler.java b/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/pdfeditor/PDFEditorUIHandler.java index c41f0c9..d47cdd7 100644 --- a/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/pdfeditor/PDFEditorUIHandler.java +++ b/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/pdfeditor/PDFEditorUIHandler.java @@ -92,20 +92,17 @@ public class PDFEditorUIHandler extends AbstractFaxToMailUIHandler<PDFEditorUIMo final PDFEditorUIModel model = getModel(); JAXXButtonGroup actionGroup = ui.getActionGroup(); - actionGroup.addPropertyChangeListener(JAXXButtonGroup.SELECTED_VALUE_PROPERTY, new PropertyChangeListener() { - @Override - public void propertyChange(PropertyChangeEvent evt) { - Object newValue = evt.getNewValue(); - Object selectedComponent; - if (newValue instanceof String) { - String value = (String) newValue; - selectedComponent = PDFEditorUIModel.EditionComponent.valueOf(value); - - } else { - selectedComponent = newValue; - } - model.setSelectedComponent(selectedComponent); + actionGroup.addPropertyChangeListener(JAXXButtonGroup.SELECTED_VALUE_PROPERTY, evt -> { + Object newValue = evt.getNewValue(); + Object selectedComponent; + if (newValue instanceof String) { + String value = (String) newValue; + selectedComponent = EditionComponent.valueOf(value); + + } else { + selectedComponent = newValue; } + model.setSelectedComponent(selectedComponent); }); String value = (String) actionGroup.getSelectedValue(); @@ -164,93 +161,74 @@ public class PDFEditorUIHandler extends AbstractFaxToMailUIHandler<PDFEditorUIMo }); model.addPropertyChangeListener(PDFEditorUIModel.PROPERTY_CURRENT_PAGE_INDEX, - new PropertyChangeListener() { - @Override - public void propertyChange(PropertyChangeEvent evt) { - Integer pageNb = (Integer) evt.getNewValue(); - Integer prevPageNb = (Integer) evt.getOldValue(); - updatePageNumber(pageNb, prevPageNb); - } + evt -> { + Integer pageNb = (Integer) evt.getNewValue(); + Integer prevPageNb = (Integer) evt.getOldValue(); + updatePageNumber(pageNb, prevPageNb); } ); - model.addPropertyChangeListener(new PropertyChangeListener() { - @Override - public void propertyChange(PropertyChangeEvent evt) { - if (Attachment.PROPERTY_ORIGINAL_FILE.equals(evt.getPropertyName()) - || Attachment.PROPERTY_EDITED_FILE.equals(evt.getPropertyName())) { - - PDFEditorUIModel model = (PDFEditorUIModel) evt.getSource(); - AttachmentFile attachmentFile = model.getNotNullFile(); - - if (attachmentFile != null) { - File file = attachmentFile.getFile(); - if (!FaxToMailUIUtil.isFileAPDF(attachmentFile)) { - try { - file = convertFileToPdf(attachmentFile); - - } catch (IOException e) { - if (log.isErrorEnabled()) { - log.error("error while converting file to pdf", e); - } - getContext().getErrorHelper().showErrorDialog(t("faxtomail.pdfEditor.convertToPdf.error")); - - } catch (DocumentException e) { - if (log.isErrorEnabled()) { - log.error("error while converting file to pdf", e); - } - getContext().getErrorHelper().showErrorDialog(t("faxtomail.pdfEditor.convertToPdf.error")); + model.addPropertyChangeListener(evt -> { + if (Attachment.PROPERTY_ORIGINAL_FILE.equals(evt.getPropertyName()) + || Attachment.PROPERTY_EDITED_FILE.equals(evt.getPropertyName())) { + + PDFEditorUIModel model1 = (PDFEditorUIModel) evt.getSource(); + AttachmentFile attachmentFile = model1.getNotNullFile(); + + if (attachmentFile != null) { + File file = attachmentFile.getFile(); + if (!FaxToMailUIUtil.isFileAPDF(attachmentFile)) { + try { + file = convertFileToPdf(attachmentFile); + + } catch (IOException e) { + if (log.isErrorEnabled()) { + log.error("error while converting file to pdf", e); + } + getContext().getErrorHelper().showErrorDialog(t("faxtomail.pdfEditor.convertToPdf.error")); + + } catch (DocumentException e) { + if (log.isErrorEnabled()) { + log.error("error while converting file to pdf", e); } + getContext().getErrorHelper().showErrorDialog(t("faxtomail.pdfEditor.convertToPdf.error")); } + } - if (FaxToMailUIUtil.isFileAPDF(attachmentFile)) { - try { + if (FaxToMailUIUtil.isFileAPDF(attachmentFile)) { + try { // pdDocument = PDDocument.loadLegacy(file); // if (pdDocument.isEncrypted()) { // pdDocument.decrypt(""); // } - pdDocument = PDDocument.load(file); - model.setPageNumber(pdDocument.getNumberOfPages()); - model.setCurrentPageIndex(1); - - } catch (IOException e) { - if (log.isErrorEnabled()) { - log.error("error while converting file to pdf", e); - } - getContext().getErrorHelper().showErrorDialog(t("faxtomail.pdfEditor.readPdf.error")); + pdDocument = PDDocument.load(file); + model1.setPageNumber(pdDocument.getNumberOfPages()); + model1.setCurrentPageIndex(1); + + } catch (IOException e) { + if (log.isErrorEnabled()) { + log.error("error while converting file to pdf", e); } + getContext().getErrorHelper().showErrorDialog(t("faxtomail.pdfEditor.readPdf.error")); } - getUI().setCursor(Cursor.getDefaultCursor()); - model.firePropertyChanged(PDFEditorUIModel.PROPERTY_CURRENT_PAGE_INDEX, null, 1); } + getUI().setCursor(Cursor.getDefaultCursor()); + model1.firePropertyChanged(PDFEditorUIModel.PROPERTY_CURRENT_PAGE_INDEX, null, 1); } } }); - model.addPropertyChangeListener(PDFEditorUIModel.PROPERTY_ZOOM, new PropertyChangeListener() { - @Override - public void propertyChange(PropertyChangeEvent evt) { - displayPage(model.getCurrentPageIndex(), - (Float) evt.getOldValue(), - model.getRotation()); - } - }); + model.addPropertyChangeListener(PDFEditorUIModel.PROPERTY_ZOOM, evt -> displayPage(model.getCurrentPageIndex(), + (Float) evt.getOldValue(), + model.getRotation())); - model.addPropertyChangeListener(PDFEditorUIModel.PROPERTY_ROTATION, new PropertyChangeListener() { - @Override - public void propertyChange(PropertyChangeEvent evt) { - displayPage(model.getCurrentPageIndex(), - model.getZoom(), - (Integer) evt.getOldValue()); - } - }); + model.addPropertyChangeListener(PDFEditorUIModel.PROPERTY_ROTATION, evt -> displayPage(model.getCurrentPageIndex(), + model.getZoom(), + (Integer) evt.getOldValue())); - model.addPropertyChangeListener(PDFEditorUIModel.PROPERTY_STAMPS, new PropertyChangeListener() { - @Override - public void propertyChange(PropertyChangeEvent evt) { - Collection<Stamp> stamps = (Collection<Stamp>) evt.getNewValue(); - updateStamps(stamps); - } + model.addPropertyChangeListener(PDFEditorUIModel.PROPERTY_STAMPS, evt -> { + Collection<Stamp> stamps = (Collection<Stamp>) evt.getNewValue(); + updateStamps(stamps); }); } diff --git a/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/print/AttachmentToPrintChooserUIHandler.java b/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/print/AttachmentToPrintChooserUIHandler.java index aafb86c..af522ef 100644 --- a/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/print/AttachmentToPrintChooserUIHandler.java +++ b/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/print/AttachmentToPrintChooserUIHandler.java @@ -72,15 +72,12 @@ public class AttachmentToPrintChooserUIHandler extends AbstractFaxToMailUIHandle // add attached files getModel().addAttachmentToPrint(demandDetailAttachment); - checkBox.addItemListener(new ItemListener() { - @Override - public void itemStateChanged(ItemEvent e) { - log.info("state changed " + e.getStateChange()); - if (e.getStateChange() == ItemEvent.SELECTED) { - getModel().addAttachmentToPrint(demandDetailAttachment); - } else { - getModel().removeAttachmentToPrint(demandDetailAttachment); - } + checkBox.addItemListener(e -> { + log.info("state changed " + e.getStateChange()); + if (e.getStateChange() == ItemEvent.SELECTED) { + getModel().addAttachmentToPrint(demandDetailAttachment); + } else { + getModel().removeAttachmentToPrint(demandDetailAttachment); } }); @@ -112,15 +109,12 @@ public class AttachmentToPrintChooserUIHandler extends AbstractFaxToMailUIHandle if (printable) { getModel().addAttachmentToPrint(attachmentFile); - checkBox.addItemListener(new ItemListener() { - @Override - public void itemStateChanged(ItemEvent e) { - log.info("state changed " + e.getStateChange()); - if (e.getStateChange() == ItemEvent.SELECTED) { - getModel().addAttachmentToPrint(attachmentFile); - } else { - getModel().removeAttachmentToPrint(attachmentFile); - } + checkBox.addItemListener(e -> { + log.info("state changed " + e.getStateChange()); + if (e.getStateChange() == ItemEvent.SELECTED) { + getModel().addAttachmentToPrint(attachmentFile); + } else { + getModel().removeAttachmentToPrint(attachmentFile); } }); } diff --git a/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/print/AttachmentToPrintChooserUIModel.java b/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/print/AttachmentToPrintChooserUIModel.java index 6d8ac6c..131d520 100644 --- a/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/print/AttachmentToPrintChooserUIModel.java +++ b/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/print/AttachmentToPrintChooserUIModel.java @@ -41,7 +41,7 @@ public class AttachmentToPrintChooserUIModel extends AbstractBean { protected DemandeUIModel demand; - protected Collection<AttachmentFile> attachmentsToPrint = new HashSet<AttachmentFile>(); + protected Collection<AttachmentFile> attachmentsToPrint = new HashSet<>(); public DemandeUIModel getDemand() { return demand; @@ -56,20 +56,20 @@ public class AttachmentToPrintChooserUIModel extends AbstractBean { } public void setAttachmentsToPrint(Collection<AttachmentFile> attachmentsToPrint) { - Object oldValue = new HashSet<AttachmentFile>(this.attachmentsToPrint); + Object oldValue = new HashSet<>(this.attachmentsToPrint); this.attachmentsToPrint.clear(); this.attachmentsToPrint.addAll(attachmentsToPrint); firePropertyChange(PROPERTY_ATTACHEMENTS_TO_PRINT, oldValue, this.attachmentsToPrint); } public void addAttachmentToPrint(AttachmentFile attachmentFile) { - Object oldValue = new HashSet<AttachmentFile>(this.attachmentsToPrint); + Object oldValue = new HashSet<>(this.attachmentsToPrint); this.attachmentsToPrint.add(attachmentFile); firePropertyChange(PROPERTY_ATTACHEMENTS_TO_PRINT, oldValue, this.attachmentsToPrint); } public void removeAttachmentToPrint(AttachmentFile attachmentFile) { - Object oldValue = new HashSet<AttachmentFile>(this.attachmentsToPrint); + Object oldValue = new HashSet<>(this.attachmentsToPrint); this.attachmentsToPrint.remove(attachmentFile); firePropertyChange(PROPERTY_ATTACHEMENTS_TO_PRINT, oldValue, this.attachmentsToPrint); } diff --git a/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/reply/ReplyFormUIHandler.java b/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/reply/ReplyFormUIHandler.java index 55abd5c..66d13da 100644 --- a/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/reply/ReplyFormUIHandler.java +++ b/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/reply/ReplyFormUIHandler.java @@ -38,7 +38,6 @@ import com.franciaflex.faxtomail.ui.swing.content.reply.actions.SenderChangedAct import com.franciaflex.faxtomail.ui.swing.util.AbstractFaxToMailUIHandler; import com.franciaflex.faxtomail.ui.swing.util.FaxToMailUIUtil; import com.google.common.base.Strings; -import com.google.common.collect.Lists; import jaxx.runtime.SwingUtil; import jaxx.runtime.validator.swing.SwingValidator; import org.apache.commons.io.FileUtils; @@ -61,8 +60,6 @@ import java.awt.Dimension; import java.awt.Font; import java.awt.Window; import java.awt.event.ActionListener; -import java.beans.PropertyChangeEvent; -import java.beans.PropertyChangeListener; import java.io.File; import java.io.IOException; import java.lang.reflect.Method; @@ -122,135 +119,115 @@ public class ReplyFormUIHandler extends AbstractFaxToMailUIHandler<ReplyFormUIMo editor.setFont(font); ReplyFormUIModel model = getModel(); - model.addPropertyChangeListener(ReplyFormUIModel.PROPERTY_ORIGINAL_DEMAND, new PropertyChangeListener() { - @Override - public void propertyChange(PropertyChangeEvent evt) { - DemandeUIModel demand = (DemandeUIModel) evt.getNewValue(); - ReplyFormUIModel model = (ReplyFormUIModel) evt.getSource(); - - List<DemandeUIModel> models = new ArrayList<>(); - models.addAll(demand.getGroupedDemandes()); - - // on crée les pj disponibles (versions éditées et non éditées) - for (DemandeUIModel demandeUIModel : models) { - // remove newline character (cf #6960) - String prefix = StringUtils.remove(demandeUIModel.getTitle(), '\n'); - - for (Attachment attachment : demandeUIModel.getAttachment()) { - - ReplyAttachmentModel replyOriginalAttachmentModel = - new ReplyAttachmentModel(attachment, true, prefix + attachment.getOriginalFileName()); - model.addAvailableAttachment(replyOriginalAttachmentModel); - - if (!Strings.isNullOrEmpty(attachment.getEditedFileName())) { - ReplyAttachmentModel replyEditedAttachmentModel = - new ReplyAttachmentModel(attachment, false, prefix + attachment.getEditedFileName()); - model.addAvailableAttachment(replyEditedAttachmentModel); - } + model.addPropertyChangeListener(ReplyFormUIModel.PROPERTY_ORIGINAL_DEMAND, evt -> { + DemandeUIModel demand = (DemandeUIModel) evt.getNewValue(); + ReplyFormUIModel model13 = (ReplyFormUIModel) evt.getSource(); + + List<DemandeUIModel> models = new ArrayList<>(); + models.addAll(demand.getGroupedDemandes()); + + // on crée les pj disponibles (versions éditées et non éditées) + for (DemandeUIModel demandeUIModel : models) { + // remove newline character (cf #6960) + String prefix = StringUtils.remove(demandeUIModel.getTitle(), '\n'); + + for (Attachment attachment : demandeUIModel.getAttachment()) { + + ReplyAttachmentModel replyOriginalAttachmentModel = + new ReplyAttachmentModel(attachment, true, prefix + attachment.getOriginalFileName()); + model13.addAvailableAttachment(replyOriginalAttachmentModel); + + if (!Strings.isNullOrEmpty(attachment.getEditedFileName())) { + ReplyAttachmentModel replyEditedAttachmentModel = + new ReplyAttachmentModel(attachment, false, prefix + attachment.getEditedFileName()); + model13.addAvailableAttachment(replyEditedAttachmentModel); } } + } + + model13.setSubject(t("faxtomail.reply.subject", demand.getSubject())); - model.setSubject(t("faxtomail.reply.subject", demand.getSubject())); + String recipient = demand.getRecipient(); + String signing; - String recipient = demand.getRecipient(); - String signing; + // this have to be disable for read only mode (useless) + if (!model13.isReadonly()) { - // this have to be disable for read only mode (useless) - if (!model.isReadonly()) { - - // attachment combo - JComboBox<AttachmentFile> addAttachmentFile = ui.getAddAttachmentFile(); - addAttachmentFile.setModel(SwingUtil.newComboModel(model.getAvailableAttachments().toArray())); - addAttachmentFile.setSelectedItem(null); + // attachment combo + JComboBox<AttachmentFile> addAttachmentFile = ui.getAddAttachmentFile(); + addAttachmentFile.setModel(SwingUtil.newComboModel(model13.getAvailableAttachments().toArray())); + addAttachmentFile.setSelectedItem(null); - // sender combo - MailFolder folder = demand.getMailFolder(); - List<String> folderReplyAdresses = new ArrayList<>(); + // sender combo + MailFolder folder = demand.getMailFolder(); + List<String> folderReplyAdresses = new ArrayList<>(); // List<String> folderReplyDomains = new ArrayList<>(); - while (folder != null) { - folderReplyAdresses.addAll(folder.getReplyAddresses()); + while (folder != null) { + folderReplyAdresses.addAll(folder.getReplyAddresses()); // folderReplyDomains.addAll(folder.getReplyDomains()); - folder = folder.getParent(); - } + folder = folder.getParent(); + } // model.setSenderAllowedDomains(folderReplyDomains); - List<String> replyToAddresses = Lists.newArrayList(); - String selectedItem = null; - if (!demand.isFax() && recipient != null) { - replyToAddresses.add(recipient); - model.setFrom(recipient); - selectedItem = recipient; - } - if (folderReplyAdresses != null) { - replyToAddresses.addAll(folderReplyAdresses); - } - Collections.sort(replyToAddresses); - - ui.getFromComboBox().setBeanType(String.class); - initBeanFilterableComboBox(ui.getFromComboBox(), replyToAddresses, selectedItem); - - model.setSenderAllowedAddresses(replyToAddresses); + List<String> replyToAddresses = new ArrayList<>(); + String selectedItem = null; + if (!demand.isFax() && recipient != null) { + replyToAddresses.add(recipient); + model13.setFrom(recipient); + selectedItem = recipient; + } + if (folderReplyAdresses != null) { + replyToAddresses.addAll(folderReplyAdresses); + } + Collections.sort(replyToAddresses); - // contacts - initBeanFilterableComboBox(ui.getContactField(), getContext().getContactCache(), null); + ui.getFromComboBox().setBeanType(String.class); + initBeanFilterableComboBox(ui.getFromComboBox(), replyToAddresses, selectedItem); - // signatures - signing = getSigningParagraph(createSigning(recipient)); + model13.setSenderAllowedAddresses(replyToAddresses); - } else { - model.setFrom(recipient); - signing = ""; - } + // contacts + initBeanFilterableComboBox(ui.getContactField(), getContext().getContactCache(), null); - String plainContent = StringUtils.join(demand.getPlainContent(), CONTENT_SEPARATOR); - String quotedText = plainContent != null ? plainContent.replaceAll("\n", "<br/> ") : ""; + // signatures + signing = getSigningParagraph(createSigning(recipient)); - String quotedReply = FaxToMailUIUtil.getQuotedReplyContent(signing, decorate(demand.getReceptionDate()), demand.getSender(), quotedText); - model.setMessage(quotedReply); + } else { + model13.setFrom(recipient); + signing = ""; } - }); - model.addPropertyChangeListener(ReplyFormUIModel.PROPERTY_ATTACHMENT, new PropertyChangeListener() { - @Override - public void propertyChange(PropertyChangeEvent evt) { - updateAttachmentPanel((Collection<ReplyAttachmentModel>) evt.getNewValue()); - } - }); + String plainContent = StringUtils.join(demand.getPlainContent(), CONTENT_SEPARATOR); + String quotedText = plainContent != null ? plainContent.replaceAll("\n", "<br/> ") : ""; - model.addPropertyChangeListener(ReplyFormUIModel.PROPERTY_READONLY, new PropertyChangeListener() { - @Override - public void propertyChange(PropertyChangeEvent evt) { - updateAttachmentPanel(getModel().getAttachments()); - } + String quotedReply = FaxToMailUIUtil.getQuotedReplyContent(signing, decorate(demand.getReceptionDate()), demand.getSender(), quotedText); + model13.setMessage(quotedReply); }); - model.addPropertyChangeListener(ReplyFormUIModel.PROPERTY_FROM, new PropertyChangeListener() { + model.addPropertyChangeListener(ReplyFormUIModel.PROPERTY_ATTACHMENT, evt -> updateAttachmentPanel((Collection<ReplyAttachmentModel>) evt.getNewValue())); - @Override - public void propertyChange(PropertyChangeEvent evt) { - ReplyFormUIModel model = (ReplyFormUIModel) evt.getSource(); - if (!model.isReadonly()) { - getContext().getActionEngine().runAction(senderChangedAction); - ui.getMessage().setCaretPosition(0); - } + model.addPropertyChangeListener(ReplyFormUIModel.PROPERTY_READONLY, evt -> updateAttachmentPanel(getModel().getAttachments())); + + model.addPropertyChangeListener(ReplyFormUIModel.PROPERTY_FROM, evt -> { + ReplyFormUIModel model12 = (ReplyFormUIModel) evt.getSource(); + if (!model12.isReadonly()) { + getContext().getActionEngine().runAction(senderChangedAction); + ui.getMessage().setCaretPosition(0); } }); JComboBox addAttachmentFile = ui.getAddAttachmentFile(); addAttachmentFile.setEditor(new FileComboBoxEditor()); - getValidator().addPropertyChangeListener(SimpleBeanValidator.VALID_PROPERTY, new PropertyChangeListener() { - @Override - public void propertyChange(PropertyChangeEvent evt) { + getValidator().addPropertyChangeListener(SimpleBeanValidator.VALID_PROPERTY, evt -> { - ReplyFormUIModel model = getModel(); - if (log.isDebugEnabled()) { - log.debug("Model [" + model + - "] pass to valid state [" + - evt.getNewValue() + "]"); - } - model.setValid((Boolean) evt.getNewValue()); + ReplyFormUIModel model1 = getModel(); + if (log.isDebugEnabled()) { + log.debug("Model [" + model1 + + "] pass to valid state [" + + evt.getNewValue() + "]"); } + model1.setValid((Boolean) evt.getNewValue()); }); diff --git a/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/reply/ReplyFormUIModel.java b/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/reply/ReplyFormUIModel.java index d68cd0a..9617a14 100644 --- a/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/reply/ReplyFormUIModel.java +++ b/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/reply/ReplyFormUIModel.java @@ -27,7 +27,6 @@ package com.franciaflex.faxtomail.ui.swing.content.reply; import com.franciaflex.faxtomail.persistence.entities.SigningForDomain; import com.franciaflex.faxtomail.services.service.ldap.Contact; import com.franciaflex.faxtomail.ui.swing.content.demande.DemandeUIModel; -import com.google.common.base.Preconditions; import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.io.FileUtils; import org.jdesktop.beans.AbstractSerializableBean; @@ -38,6 +37,7 @@ import java.io.File; import java.util.Date; import java.util.HashSet; import java.util.List; +import java.util.Objects; import java.util.Set; /** @@ -90,8 +90,8 @@ public class ReplyFormUIModel extends AbstractSerializableBean { protected List<String> senderAllowedDomains; protected List<String> senderAllowedAddresses; - protected Set<ReplyAttachmentModel> attachments = new HashSet<ReplyAttachmentModel>(); - protected Set<ReplyAttachmentModel> availableAttachments = new HashSet<ReplyAttachmentModel>(); + protected Set<ReplyAttachmentModel> attachments = new HashSet<>(); + protected Set<ReplyAttachmentModel> availableAttachments = new HashSet<>(); protected File lastVisitedDirectory = FileUtils.getUserDirectory(); @@ -321,7 +321,7 @@ public class ReplyFormUIModel extends AbstractSerializableBean { * @return true/false */ protected boolean isEmailAllowed(String mail) { - Preconditions.checkNotNull(mail); + Objects.requireNonNull(mail); List<String> senderAllowedAddresses = getSenderAllowedAddresses(); if (senderAllowedAddresses != null) { for (String address : senderAllowedAddresses) { @@ -342,7 +342,7 @@ public class ReplyFormUIModel extends AbstractSerializableBean { */ @Deprecated protected boolean isDomainAllowed(String mail) { - Preconditions.checkNotNull(mail); + Objects.requireNonNull(mail); List<String> senderAllowedDomains = getSenderAllowedDomains(); if (CollectionUtils.isEmpty(senderAllowedDomains)) { @@ -359,8 +359,7 @@ public class ReplyFormUIModel extends AbstractSerializableBean { // Do not remove the unused parameter, it is just for the validation // to bind the totalAttachmentLength property public boolean isAttachmentSizeValid(long totalAttachmentLength) { - boolean valid = maxAttachmentLength == 0 || this.totalAttachmentLength < maxAttachmentLength; - return valid; + return maxAttachmentLength == 0 || this.totalAttachmentLength < maxAttachmentLength; } /** diff --git a/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/reply/actions/ReplyAction.java b/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/reply/actions/ReplyAction.java index 6bc96a9..9647716 100644 --- a/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/reply/actions/ReplyAction.java +++ b/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/reply/actions/ReplyAction.java @@ -34,13 +34,12 @@ import com.franciaflex.faxtomail.ui.swing.content.reply.ReplyAttachmentModel; import com.franciaflex.faxtomail.ui.swing.content.reply.ReplyFormUI; import com.franciaflex.faxtomail.ui.swing.content.reply.ReplyFormUIHandler; import com.franciaflex.faxtomail.ui.swing.content.reply.ReplyFormUIModel; -import com.google.common.base.Function; -import com.google.common.collect.Collections2; import com.google.common.collect.Sets; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import java.util.Collection; +import java.util.stream.Collectors; import static org.nuiton.i18n.I18n.t; @@ -64,12 +63,9 @@ public class ReplyAction extends AbstractFaxToMailAction<ReplyFormUIModel, Reply EmailService emailService = serviceContext.getEmailService(); DemandeUIModel originalDemand = getModel().getOriginalDemand(); - Collection<AttachmentFile> attachmentFiles = Collections2.transform(model.getAttachments(), new Function<ReplyAttachmentModel, AttachmentFile>() { - @Override - public AttachmentFile apply(ReplyAttachmentModel replyAttachmentModel) { - return replyAttachmentModel.getAttachmentFile(); - } - }); + Collection<AttachmentFile> attachmentFiles = model.getAttachments().stream() + .map(ReplyAttachmentModel::getAttachmentFile) + .collect(Collectors.toList()); Email email = emailService.reply(model.getFrom(), model.getTo(), model.getCc(), diff --git a/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/reply/actions/SenderChangedAction.java b/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/reply/actions/SenderChangedAction.java index 40ae4e7..1d1f4c3 100644 --- a/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/reply/actions/SenderChangedAction.java +++ b/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/reply/actions/SenderChangedAction.java @@ -62,7 +62,7 @@ public class SenderChangedAction extends AbstractFaxToMailAction<ReplyFormUIMode FaxToMailServiceContext serviceContext = getContext().newServiceContext(); signingForDomain = null; if (!model.getOriginalDemand().isFax() && model.getFrom() != null) { - signingForDomain = serviceContext.getConfigurationService().getSigningForEmailAddress(model.getFrom()).orNull(); + signingForDomain = serviceContext.getConfigurationService().getSigningForEmailAddress(model.getFrom()); } } diff --git a/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/search/SearchToGroupUIHandler.java b/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/search/SearchToGroupUIHandler.java index 523315e..a617b08 100644 --- a/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/search/SearchToGroupUIHandler.java +++ b/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/search/SearchToGroupUIHandler.java @@ -169,47 +169,38 @@ public class SearchToGroupUIHandler extends AbstractFaxToMailDemandListHandler<S initDemandeTable(dataTable, true); - model.addPropertyChangeListener(SearchUIModel.PROPERTY_RESULTS, new PropertyChangeListener() { - @Override - public void propertyChange(PropertyChangeEvent evt) { - List<DemandeUIModel> emails = (List<DemandeUIModel>) evt.getNewValue(); - DemandeTableModel dataTableModel = (DemandeTableModel) dataTable.getModel(); - dataTableModel.setRows(emails); - - DemandeUIModel currentEmail = getContext().getCurrentEmail(); - if (currentEmail != null) { - int row = dataTableModel.getRowIndex(currentEmail); - if (row > 0) { - dataTable.setRowSelectionInterval(row, row); - } + model.addPropertyChangeListener(SearchUIModel.PROPERTY_RESULTS, evt -> { + List<DemandeUIModel> emails = (List<DemandeUIModel>) evt.getNewValue(); + DemandeTableModel dataTableModel = (DemandeTableModel) dataTable.getModel(); + dataTableModel.setRows(emails); + + DemandeUIModel currentEmail = getContext().getCurrentEmail(); + if (currentEmail != null) { + int row = dataTableModel.getRowIndex(currentEmail); + if (row > 0) { + dataTable.setRowSelectionInterval(row, row); } } }); - dataTable.getSelectionModel().addListSelectionListener(new ListSelectionListener() { - @Override - public void valueChanged(ListSelectionEvent e) { - if (!e.getValueIsAdjusting()) { - ListSelectionModel selectionModel = (ListSelectionModel) e.getSource(); - SearchUIModel model = getModel(); - int selectedIndex = selectionModel.getLeadSelectionIndex(); - selectedIndex = dataTable.convertRowIndexToModel(selectedIndex); - DemandeTableModel dataTableModel = (DemandeTableModel) dataTable.getModel(); - DemandeUIModel selectedModel = selectedIndex < 0 ? null : dataTableModel.getEntry(selectedIndex); - model.setGroupEnabled(!selectionModel.isSelectionEmpty() && isDemandSelectable(selectedModel)); - } + dataTable.getSelectionModel().addListSelectionListener(e -> { + if (!e.getValueIsAdjusting()) { + ListSelectionModel selectionModel = (ListSelectionModel) e.getSource(); + SearchUIModel model1 = getModel(); + int selectedIndex = selectionModel.getLeadSelectionIndex(); + selectedIndex = dataTable.convertRowIndexToModel(selectedIndex); + DemandeTableModel dataTableModel = (DemandeTableModel) dataTable.getModel(); + DemandeUIModel selectedModel = selectedIndex < 0 ? null : dataTableModel.getEntry(selectedIndex); + model1.setGroupEnabled(!selectionModel.isSelectionEmpty() && isDemandSelectable(selectedModel)); } }); - HighlightPredicate rowAlreadyInGroupPredicate = new HighlightPredicate() { - @Override - public boolean isHighlighted(Component renderer, ComponentAdapter adapter) { - int viewRow = adapter.row; - int modelRow = adapter.convertRowIndexToModel(viewRow); - DemandeTableModel dataTableModel = (DemandeTableModel) dataTable.getModel(); - DemandeUIModel row = dataTableModel.getEntry(modelRow); - return !isDemandSelectable(row); - } + HighlightPredicate rowAlreadyInGroupPredicate = (renderer, adapter) -> { + int viewRow = adapter.row; + int modelRow = adapter.convertRowIndexToModel(viewRow); + DemandeTableModel dataTableModel = (DemandeTableModel) dataTable.getModel(); + DemandeUIModel row = dataTableModel.getEntry(modelRow); + return !isDemandSelectable(row); }; dataTable.addHighlighter(new ColorHighlighter(rowAlreadyInGroupPredicate, null, Color.GRAY, Color.GRAY, Color.WHITE)); @@ -218,12 +209,7 @@ public class SearchToGroupUIHandler extends AbstractFaxToMailDemandListHandler<S int resultPerPage = getConfig().getResultPerPage(); ui.getModel().setResultPerPage(resultPerPage); ui.getResultPerPageCombo().setSelectedItem(resultPerPage); - ui.getResultPerPageCombo().addItemListener(new ItemListener() { - @Override - public void itemStateChanged(ItemEvent e) { - updateResultPerPage(e); - } - }); + ui.getResultPerPageCombo().addItemListener(this::updateResultPerPage); getContext().getSwingSession().add(ui, true); } @@ -232,12 +218,7 @@ public class SearchToGroupUIHandler extends AbstractFaxToMailDemandListHandler<S @Override protected void initTextField(JTextField jTextField) { super.initTextField(jTextField); - jTextField.addActionListener(new ActionListener() { - @Override - public void actionPerformed(ActionEvent e) { - searchDemandes(); - } - }); + jTextField.addActionListener(e -> searchDemandes()); } @Override diff --git a/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/search/SearchUIHandler.java b/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/search/SearchUIHandler.java index cd72c65..8f5f068 100644 --- a/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/search/SearchUIHandler.java +++ b/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/search/SearchUIHandler.java @@ -166,20 +166,17 @@ public class SearchUIHandler extends AbstractFaxToMailDemandListHandler<SearchUI initDemandeTable(dataTable, true); - model.addPropertyChangeListener(SearchUIModel.PROPERTY_RESULTS, new PropertyChangeListener() { - @Override - public void propertyChange(PropertyChangeEvent evt) { - List<DemandeUIModel> emails = (List<DemandeUIModel>) evt.getNewValue(); - DemandeTableModel dataTableModel = (DemandeTableModel) dataTable.getModel(); - dataTableModel.setRows(emails); - - DemandeUIModel currentEmail = getContext().getCurrentEmail(); - if (currentEmail != null) { - int row = dataTableModel.getRowIndex(currentEmail); - if (row > 0) { - dataTable.setRowSelectionInterval(row, row); - dataTable.scrollRowToVisible(row); - } + model.addPropertyChangeListener(SearchUIModel.PROPERTY_RESULTS, evt -> { + List<DemandeUIModel> emails = (List<DemandeUIModel>) evt.getNewValue(); + DemandeTableModel dataTableModel = (DemandeTableModel) dataTable.getModel(); + dataTableModel.setRows(emails); + + DemandeUIModel currentEmail = getContext().getCurrentEmail(); + if (currentEmail != null) { + int row = dataTableModel.getRowIndex(currentEmail); + if (row > 0) { + dataTable.setRowSelectionInterval(row, row); + dataTable.scrollRowToVisible(row); } } }); @@ -193,23 +190,13 @@ public class SearchUIHandler extends AbstractFaxToMailDemandListHandler<SearchUI int resultPerPage = getConfig().getResultPerPage(); ui.getModel().setResultPerPage(resultPerPage); ui.getResultPerPageCombo().setSelectedItem(resultPerPage); - ui.getResultPerPageCombo().addItemListener(new ItemListener() { - @Override - public void itemStateChanged(ItemEvent e) { - updateResultPerPage(e); - } - }); + ui.getResultPerPageCombo().addItemListener(this::updateResultPerPage); } @Override protected void initTextField(JTextField jTextField) { super.initTextField(jTextField); - jTextField.addActionListener(new ActionListener() { - @Override - public void actionPerformed(ActionEvent e) { - searchDemandes(); - } - }); + jTextField.addActionListener(e -> searchDemandes()); } @Override diff --git a/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/search/actions/GroupAction.java b/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/search/actions/GroupAction.java index 35cb0d7..65bdfad 100644 --- a/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/search/actions/GroupAction.java +++ b/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/search/actions/GroupAction.java @@ -71,8 +71,7 @@ public class GroupAction extends AbstractFaxToMailAction<SearchUIModel, SearchTo JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE); - boolean result = i == JOptionPane.YES_OPTION; - return result; + return i == JOptionPane.YES_OPTION; } @Override diff --git a/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/search/actions/SearchAction.java b/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/search/actions/SearchAction.java index e486ae6..c40cb8e 100644 --- a/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/search/actions/SearchAction.java +++ b/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/search/actions/SearchAction.java @@ -25,25 +25,23 @@ package com.franciaflex.faxtomail.ui.swing.content.search.actions; */ import com.franciaflex.faxtomail.persistence.entities.Email; -import com.franciaflex.faxtomail.persistence.entities.RangeRow; import com.franciaflex.faxtomail.persistence.entities.SearchFilter; import com.franciaflex.faxtomail.persistence.entities.WaitingState; import com.franciaflex.faxtomail.services.FaxToMailServiceContext; import com.franciaflex.faxtomail.ui.swing.actions.AbstractFaxToMailAction; import com.franciaflex.faxtomail.ui.swing.content.demande.DemandeUIModel; -import com.franciaflex.faxtomail.ui.swing.content.demande.RangeRowModel; import com.franciaflex.faxtomail.ui.swing.content.search.SearchUI; import com.franciaflex.faxtomail.ui.swing.content.search.SearchUIHandler; import com.franciaflex.faxtomail.ui.swing.content.search.SearchUIModel; -import com.google.common.collect.Maps; import com.google.common.collect.Sets; -import org.nuiton.topia.persistence.TopiaEntities; +import org.nuiton.topia.persistence.TopiaEntity; import org.nuiton.util.pagination.PaginationResult; import java.util.ArrayList; -import java.util.Collection; import java.util.List; import java.util.Map; +import java.util.function.Function; +import java.util.stream.Collectors; import static org.nuiton.i18n.I18n.t; @@ -72,7 +70,8 @@ public class SearchAction extends AbstractFaxToMailAction<SearchUIModel, SearchU List<Email> emails = paginationResult.getElements(); List<DemandeUIModel> result = new ArrayList<>(); - Map<String, WaitingState> waitingStateById = Maps.uniqueIndex(getContext().getWaitingStateCache(), TopiaEntities.getTopiaIdFunction()); + Map<String, WaitingState> waitingStateById = getContext().getWaitingStateCache().stream() + .collect(Collectors.toMap(TopiaEntity::getTopiaId, Function.identity())); for (Email email : emails) { DemandeUIModel demand = new DemandeUIModel(); diff --git a/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/search/actions/SearchToGroupAction.java b/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/search/actions/SearchToGroupAction.java index 4751817..1113639 100644 --- a/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/search/actions/SearchToGroupAction.java +++ b/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/search/actions/SearchToGroupAction.java @@ -34,17 +34,19 @@ import com.franciaflex.faxtomail.ui.swing.content.demande.DemandeUIModel; import com.franciaflex.faxtomail.ui.swing.content.search.SearchToGroupUI; import com.franciaflex.faxtomail.ui.swing.content.search.SearchToGroupUIHandler; import com.franciaflex.faxtomail.ui.swing.content.search.SearchUIModel; -import com.google.common.collect.Maps; import com.google.common.collect.Sets; -import org.nuiton.topia.persistence.TopiaEntities; +import org.nuiton.topia.persistence.TopiaEntity; import org.nuiton.util.pagination.PaginationResult; -import javax.swing.*; +import javax.swing.JFrame; +import javax.swing.SwingUtilities; import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeListener; import java.util.ArrayList; import java.util.List; import java.util.Map; +import java.util.function.Function; +import java.util.stream.Collectors; import static org.nuiton.i18n.I18n.t; @@ -71,7 +73,8 @@ public class SearchToGroupAction extends AbstractFaxToMailAction<SearchUIModel, List<Email> emails = paginationResult.getElements(); List<DemandeUIModel> result = new ArrayList<>(); - Map<String, WaitingState> waitingStateById = Maps.uniqueIndex(getContext().getWaitingStateCache(), TopiaEntities.getTopiaIdFunction()); + Map<String, WaitingState> waitingStateById = getContext().getWaitingStateCache().stream() + .collect(Collectors.toMap(TopiaEntity::getTopiaId, Function.identity()));; for (Email email : emails) { DemandeUIModel demand = new DemandeUIModel(); @@ -93,13 +96,10 @@ public class SearchToGroupAction extends AbstractFaxToMailAction<SearchUIModel, @Override public void propertyChange(PropertyChangeEvent evt) { if (!getContext().isBusy()) { - SwingUtilities.invokeLater(new Runnable() { - @Override - public void run() { - final JFrame frame = getUI().getParentContainer(JFrame.class); - if (frame != null) { - frame.toFront(); - } + SwingUtilities.invokeLater(() -> { + final JFrame frame = getUI().getParentContainer(JFrame.class); + if (frame != null) { + frame.toFront(); } }); getContext().removePropertyChangeListener(FaxToMailUIContext.PROPERTY_BUSY, this); diff --git a/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/transmit/MailFolderChooserUIHandler.java b/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/transmit/MailFolderChooserUIHandler.java index 7fad488..f5ac549 100644 --- a/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/transmit/MailFolderChooserUIHandler.java +++ b/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/transmit/MailFolderChooserUIHandler.java @@ -34,11 +34,10 @@ import com.franciaflex.faxtomail.ui.swing.util.FolderTreeNode; import jaxx.runtime.validator.swing.SwingValidator; import org.nuiton.jaxx.application.swing.util.Cancelable; -import javax.swing.*; -import javax.swing.event.TreeSelectionEvent; -import javax.swing.event.TreeSelectionListener; +import javax.swing.JComponent; +import javax.swing.JTree; import javax.swing.tree.DefaultMutableTreeNode; -import java.awt.*; +import java.awt.Component; import java.util.Collection; import java.util.HashSet; import java.util.List; @@ -59,7 +58,7 @@ public class MailFolderChooserUIHandler extends AbstractFaxToMailUIHandler<MailF MailFolder currentMailFolder = model.getDemandeUIModels().get(0).getMailFolder(); // on recupere seulement les dossiers qui accepte l'ensemble des états d'attentes de l'ensemble des demandes - Set<WaitingState> allWaitingStates = new HashSet<WaitingState>(); + Set<WaitingState> allWaitingStates = new HashSet<>(); for (DemandeUIModel demande : model.getDemandeUIModels()) { if (demande.getWaitingState() != null) { allWaitingStates.add(demande.getWaitingState()); @@ -88,28 +87,24 @@ public class MailFolderChooserUIHandler extends AbstractFaxToMailUIHandler<MailF if (node.getClass().isAssignableFrom(FolderTreeNode.class)) { FolderTreeNode folderTreeNode = (FolderTreeNode) node; - MailFolder folderWithAllowMoveDemandIntoFolder = folder; // le dossier n'est pas grisé si: // - le n'est pas le dossier courrant // - l'utilsateur à les droits sur le dossier // - le dossier cible à les mêmes etatAttente/typeDemande que toutes les demandes à bouger folderTreeNode.setCanSelect(!currentMailFolder.equals(folder) && - folderWithAllowMoveDemandIntoFolder.isFolderMoveable() && - (foldersWithWaitingState == null || foldersWithWaitingState.contains(folder))); + folder.isFolderMoveable() && + (foldersWithWaitingState == null || foldersWithWaitingState.contains(folder))); } } - navigationTree.addTreeSelectionListener(new TreeSelectionListener() { - @Override - public void valueChanged(TreeSelectionEvent e) { - FolderTreeNode folderNode = (FolderTreeNode) e.getPath().getLastPathComponent(); - MailFolder folder = folderNode.getMailFolder(); - if (!folderNode.isCanSelect()) { - folder = null; - } - getModel().setMailFolder(folder); + navigationTree.addTreeSelectionListener(e -> { + FolderTreeNode folderNode = (FolderTreeNode) e.getPath().getLastPathComponent(); + MailFolder folder = folderNode.getMailFolder(); + if (!folderNode.isCanSelect()) { + folder = null; } + getModel().setMailFolder(folder); }); // fix jaxx binding, apparement, il faut lui refaire un set null diff --git a/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/transmit/actions/TransmitAction.java b/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/transmit/actions/TransmitAction.java index bff06a6..5244820 100644 --- a/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/transmit/actions/TransmitAction.java +++ b/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/transmit/actions/TransmitAction.java @@ -34,9 +34,6 @@ import com.franciaflex.faxtomail.ui.swing.content.transmit.MailFolderChooserUI; import com.franciaflex.faxtomail.ui.swing.content.transmit.MailFolderChooserUIHandler; import com.franciaflex.faxtomail.ui.swing.content.transmit.MailFolderChooserUIModel; import com.franciaflex.faxtomail.ui.swing.util.FaxToMailUI; -import com.google.common.base.Function; -import com.google.common.base.Predicate; -import com.google.common.collect.Collections2; import jaxx.runtime.JAXXContext; import jaxx.runtime.JAXXUtil; @@ -45,6 +42,7 @@ import javax.swing.JOptionPane; import java.util.ArrayList; import java.util.Collection; import java.util.List; +import java.util.stream.Collectors; import static org.nuiton.i18n.I18n.t; @@ -64,22 +62,18 @@ public class TransmitAction extends AbstractFaxToMailAction<MailFolderChooserUIM boolean result = super.prepareAction(); MailFolderChooserUIModel model = getModel(); - List<DemandeUIModel> demandeUIModels = new ArrayList<DemandeUIModel>(model.getDemandeUIModels()); + List<DemandeUIModel> demandeUIModels = new ArrayList<>(model.getDemandeUIModels()); for (final DemandeUIModel demandeUIModel : model.getDemandeUIModels()) { final MailFolder mailFolder = demandeUIModel.getMailFolder(); List<DemandeUIModel> groupedDemandes = demandeUIModel.getGroupedDemandes(); // on cherche les demandes groupées qui sont dans le même groupe, pour demander si on les déplace aussi - Collection<DemandeUIModel> sameFolderGroupedDemands = - Collections2.filter(groupedDemandes, new Predicate<DemandeUIModel>() { - @Override - public boolean apply(DemandeUIModel groupDemandeUIModel) { - return !demandeUIModel.equals(groupDemandeUIModel) - && groupDemandeUIModel.getDemandStatus().isEditableStatus() - && mailFolder.equals(groupDemandeUIModel.getMailFolder()); - } - }); + Collection<DemandeUIModel> sameFolderGroupedDemands = groupedDemandes.stream() + .filter(groupDemandeUIModel -> !demandeUIModel.equals(groupDemandeUIModel) + && groupDemandeUIModel.getDemandStatus().isEditableStatus() + && mailFolder.equals(groupDemandeUIModel.getMailFolder())) + .collect(Collectors.toList()); if (!sameFolderGroupedDemands.isEmpty()) { String groupedDemandTitles = ""; @@ -107,12 +101,7 @@ public class TransmitAction extends AbstractFaxToMailAction<MailFolderChooserUIM @Override public void doAction() throws Exception { MailFolderChooserUIModel model = getModel(); - Collection<String> emailIds = Collections2.transform(model.getDemandeUIModels(), new Function<DemandeUIModel, String>() { - @Override - public String apply(DemandeUIModel demandeUIModel) { - return demandeUIModel.getTopiaId(); - } - }); + Collection<String> emailIds = model.getDemandeUIModels().stream().map(DemandeUIModel::getTopiaId).collect(Collectors.toSet()); getContext().newServiceContext().getEmailService().transmit(emailIds, model.getMailFolder(), getContext().getCurrentUser()); } @@ -138,7 +127,7 @@ public class TransmitAction extends AbstractFaxToMailAction<MailFolderChooserUIM } else if (DemandeListUI.class.isAssignableFrom(parentUI.getClass())) { DemandeListUI demandeListUI = (DemandeListUI) parentUI; DemandeListUIModel listModel = demandeListUI.getModel(); - List<DemandeUIModel> demandList = new ArrayList<DemandeUIModel>(listModel.getEmails()); + List<DemandeUIModel> demandList = new ArrayList<>(listModel.getEmails()); demandList.removeAll(getModel().getDemandeUIModels()); listModel.setEmails(demandList); } diff --git a/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/util/AbstractFaxToMailDemandListHandler.java b/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/util/AbstractFaxToMailDemandListHandler.java index d1509d3..e9a31ee 100644 --- a/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/util/AbstractFaxToMailDemandListHandler.java +++ b/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/util/AbstractFaxToMailDemandListHandler.java @@ -40,8 +40,6 @@ import com.franciaflex.faxtomail.ui.swing.content.demande.DemandeUIModel; import com.franciaflex.faxtomail.ui.swing.content.demande.demandgroup.DemandGroupCellRenderer; import com.franciaflex.faxtomail.ui.swing.content.demande.replies.RepliesCellEditor; import com.franciaflex.faxtomail.ui.swing.content.demande.replies.RepliesCellRenderer; -import com.google.common.base.Function; -import com.google.common.collect.Lists; import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.lang3.ArrayUtils; import org.apache.commons.lang3.StringUtils; @@ -72,9 +70,11 @@ import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; import java.awt.event.MouseListener; import java.util.ArrayList; +import java.util.Arrays; import java.util.Collection; import java.util.Date; import java.util.List; +import java.util.function.Function; /** * @author Kevin Morin (Code Lutin) @@ -127,14 +127,11 @@ public abstract class AbstractFaxToMailDemandListHandler<M, UI extends FaxToMail }; table.addHighlighter(highlighter); - HighlightPredicate rowIsInvalidPredicate = new HighlightPredicate() { - @Override - public boolean isHighlighted(Component renderer, ComponentAdapter adapter) { - int viewRow = adapter.row; - int modelRow = adapter.convertRowIndexToModel(viewRow); - DemandeUIModel row = ((DemandeTableModel) table.getModel()).getEntry(modelRow); - return !row.isValid() && row.getTakenBy() != null; - } + HighlightPredicate rowIsInvalidPredicate = (renderer, adapter) -> { + int viewRow = adapter.row; + int modelRow = adapter.convertRowIndexToModel(viewRow); + DemandeUIModel row = ((DemandeTableModel) table.getModel()).getEntry(modelRow); + return !row.isValid() && row.getTakenBy() != null; }; Color color = new Color(255, 51, 51); table.addHighlighter(new ColorHighlighter(rowIsInvalidPredicate, color, Color.WHITE, color.darker(), Color.WHITE)); @@ -150,7 +147,7 @@ public abstract class AbstractFaxToMailDemandListHandler<M, UI extends FaxToMail TableColumnModelExt columnModel = new DefaultTableColumnModelExt(); if (CollectionUtils.isEmpty(columns)) { - columns = Lists.newArrayList(MailField.getTableFields()); + columns = Arrays.asList(MailField.getTableFields()); } for (MailField columnName : columns) { @@ -191,20 +188,10 @@ public abstract class AbstractFaxToMailDemandListHandler<M, UI extends FaxToMail break; case PF_NB: - tableCellRenderer = new QuantityTableCellRenderer(new Function<RangeRow, Integer>() { - @Override - public Integer apply(RangeRow input) { - return input != null ? input.getProductQuantity() : null; - } - }); + tableCellRenderer = new QuantityTableCellRenderer(input -> input != null ? input.getProductQuantity() : null); break; case SAV_NB: - tableCellRenderer = new QuantityTableCellRenderer(new Function<RangeRow, Integer>() { - @Override - public Integer apply(RangeRow input) { - return input != null ? input.getSavQuantity() : null; - } - }); + tableCellRenderer = new QuantityTableCellRenderer(input -> input != null ? input.getSavQuantity() : null); break; case DEMAND_STATUS: @@ -324,7 +311,7 @@ public abstract class AbstractFaxToMailDemandListHandler<M, UI extends FaxToMail String tooltipText = null; - List<String> ranges = new ArrayList<String>(); + List<String> ranges = new ArrayList<>(); Collection<RangeRow> rangeRows = demande.getRangeRow(); if (rangeRows != null) { for (RangeRow rangeRow : rangeRows) { diff --git a/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/util/AbstractFaxToMailUIHandler.java b/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/util/AbstractFaxToMailUIHandler.java index 8898d99..1c05556 100644 --- a/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/util/AbstractFaxToMailUIHandler.java +++ b/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/util/AbstractFaxToMailUIHandler.java @@ -32,9 +32,6 @@ import com.franciaflex.faxtomail.services.DecoratorService; import com.franciaflex.faxtomail.services.FaxToMailServiceUtils; import com.franciaflex.faxtomail.ui.swing.FaxToMailUIContext; import com.franciaflex.faxtomail.ui.swing.content.demande.DemandeUIModel; -import com.google.common.base.Preconditions; -import com.google.common.collect.Lists; -import com.google.common.collect.Sets; import jaxx.runtime.JAXXUtil; import jaxx.runtime.SwingUtil; import jaxx.runtime.swing.editor.bean.BeanFilterableComboBox; @@ -45,7 +42,7 @@ import org.jdesktop.swingx.autocomplete.ComboBoxCellEditor; import org.jdesktop.swingx.autocomplete.ObjectToStringConverter; import org.jdesktop.swingx.table.TableColumnExt; import org.nuiton.decorator.Decorator; -import org.nuiton.jaxx.application.ApplicationDataUtil; +import org.nuiton.jaxx.application.bean.JavaBeanObjectUtil; import org.nuiton.jaxx.application.swing.AbstractApplicationUIHandler; import org.nuiton.jaxx.application.swing.ApplicationUI; import org.nuiton.jaxx.application.swing.action.AbstractApplicationAction; @@ -56,13 +53,24 @@ import org.nuiton.jaxx.application.swing.util.CloseableUI; import org.nuiton.util.beans.BeanUtil; import org.nuiton.validator.bean.simple.SimpleBeanValidator; -import javax.swing.*; +import javax.swing.AbstractAction; +import javax.swing.ComboBoxModel; +import javax.swing.JComboBox; +import javax.swing.JComponent; +import javax.swing.JFrame; +import javax.swing.JOptionPane; +import javax.swing.JRootPane; +import javax.swing.KeyStroke; +import javax.swing.SwingUtilities; +import javax.swing.WindowConstants; import javax.swing.table.TableColumnModel; import javax.swing.text.JTextComponent; -import java.awt.*; +import java.awt.Component; +import java.awt.Container; +import java.awt.Dimension; +import java.awt.Frame; import java.awt.event.ActionEvent; import java.awt.event.ItemEvent; -import java.awt.event.ItemListener; import java.awt.event.KeyEvent; import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; @@ -71,7 +79,9 @@ import java.beans.PropertyChangeListener; import java.io.Serializable; import java.lang.reflect.Method; import java.util.ArrayList; +import java.util.HashSet; import java.util.List; +import java.util.Objects; import java.util.Set; import static org.nuiton.i18n.I18n.t; @@ -127,10 +137,9 @@ public abstract class AbstractFaxToMailUIHandler<M, UI extends FaxToMailUI<M, ?> public <O> Decorator<O> getDecorator(Class<O> type, String name) { DecoratorService decoratorService = getContext().newServiceContext().getDecoratorService(); - Preconditions.checkNotNull(type); + Objects.requireNonNull(type); - Decorator<O> decorator = decoratorService.getDecoratorByType(type, name); - return decorator; + return decoratorService.getDecoratorByType(type, name); } // sonar signale cette methode comme inutile, mais elle augmente la visibilité en fait @@ -148,7 +157,7 @@ public abstract class AbstractFaxToMailUIHandler<M, UI extends FaxToMailUI<M, ?> public void setText(ItemEvent e, String property) { String value = JAXXUtil.getStringValue(e.getItem()); - ApplicationDataUtil.setProperty(getModel(), property, value); + JavaBeanObjectUtil.setProperty(getModel(), property, value); } @Override @@ -165,16 +174,13 @@ public abstract class AbstractFaxToMailUIHandler<M, UI extends FaxToMailUI<M, ?> protected void listenValidatorValid(SimpleBeanValidator validator, final AbstractFaxToMailBeanUIModel model) { - validator.addPropertyChangeListener(SimpleBeanValidator.VALID_PROPERTY, new PropertyChangeListener() { - @Override - public void propertyChange(PropertyChangeEvent evt) { - if (log.isDebugEnabled()) { - log.debug("Model [" + model + - "] pass to valid state [" + - evt.getNewValue() + "]"); - } - model.setValid((Boolean) evt.getNewValue()); + validator.addPropertyChangeListener(SimpleBeanValidator.VALID_PROPERTY, evt -> { + if (log.isDebugEnabled()) { + log.debug("Model [" + model + + "] pass to valid state [" + + evt.getNewValue() + "]"); } + model.setValid((Boolean) evt.getNewValue()); }); } @@ -183,9 +189,10 @@ public abstract class AbstractFaxToMailUIHandler<M, UI extends FaxToMailUI<M, ?> } protected Set<String> getPropertiesToIgnore() { - return Sets.newHashSet( - AbstractFaxToMailBeanUIModel.PROPERTY_MODIFY, - AbstractFaxToMailBeanUIModel.PROPERTY_VALID); + Set<String> properties = new HashSet<>(); + properties.add(AbstractFaxToMailBeanUIModel.PROPERTY_MODIFY); + properties.add(AbstractFaxToMailBeanUIModel.PROPERTY_VALID); + return properties; } public JFrame openFrame(ApplicationUI dialogContent, @@ -420,14 +427,14 @@ public abstract class AbstractFaxToMailUIHandler<M, UI extends FaxToMailUI<M, ?> String property, boolean addNull) { - java.util.List<HL> universe = new ArrayList<HL>(); + java.util.List<HL> universe = new ArrayList<>(); if (addNull) { universe.add(null); } if (values != null) { universe.addAll(values); } - final ComboBoxModel<HL> comboModel = new CheckBoxComboBoxModel<HL>(universe, selection); + final ComboBoxModel<HL> comboModel = new CheckBoxComboBoxModel<>(universe, selection); comboBox.setModel(comboModel); comboBox.setRenderer(new CheckBoxListCellRenderer<HL>() { @Override @@ -436,21 +443,14 @@ public abstract class AbstractFaxToMailUIHandler<M, UI extends FaxToMailUI<M, ?> } }); final Method mutator = BeanUtil.getMutator(getModel(), property); - comboBox.addItemListener(new ItemListener() { - @Override - public void itemStateChanged(ItemEvent e) { - //reopen the combo - SwingUtilities.invokeLater(new Runnable() { - public void run() { - comboBox.showPopup(); - } - }); - - if (e.getStateChange() == ItemEvent.SELECTED) { - BeanUIUtil.invokeMethod(mutator, - getModel(), - e.getItem()); - } + comboBox.addItemListener(e -> { + //reopen the combo + SwingUtilities.invokeLater(comboBox::showPopup); + + if (e.getStateChange() == ItemEvent.SELECTED) { + BeanUIUtil.invokeMethod(mutator, + getModel(), + e.getItem()); } }); } @@ -460,13 +460,10 @@ public abstract class AbstractFaxToMailUIHandler<M, UI extends FaxToMailUI<M, ?> WaitingState waitingState = model.getWaitingState(); boolean valid = model.isValid(); - boolean enabled = - waitingState == null && (valid || !FaxToMailServiceUtils.contains(config.getInvalidFormDisabledActions(), action)) - || waitingState != null && - (valid && !FaxToMailServiceUtils.contains(waitingState.getValidFormDisabledActions(), action) - || !valid && !FaxToMailServiceUtils.contains(waitingState.getInvalidFormDisabledActions(), action)); - - return enabled; + return waitingState == null && (valid || !FaxToMailServiceUtils.contains(config.getInvalidFormDisabledActions(), action)) + || waitingState != null && + (valid && !FaxToMailServiceUtils.contains(waitingState.getValidFormDisabledActions(), action) + || !valid && !FaxToMailServiceUtils.contains(waitingState.getInvalidFormDisabledActions(), action)); } protected <R, B> TableColumnExt addComboDataColumnToModel(TableColumnModel model, @@ -477,7 +474,7 @@ public abstract class AbstractFaxToMailUIHandler<M, UI extends FaxToMailUI<M, ?> comboBox.setMaximumRowCount(20); comboBox.setRenderer(newListCellRender(decorator)); - List<B> dataToList = Lists.newArrayList(data); + List<B> dataToList = new ArrayList<>(data); // add a null value at first position if (!dataToList.isEmpty() && dataToList.get(0) != null) { diff --git a/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/util/CheckBoxComboBoxModel.java b/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/util/CheckBoxComboBoxModel.java index 0afc687..0999eee 100644 --- a/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/util/CheckBoxComboBoxModel.java +++ b/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/util/CheckBoxComboBoxModel.java @@ -25,9 +25,10 @@ package com.franciaflex.faxtomail.ui.swing.util; */ import com.franciaflex.faxtomail.persistence.entities.HasLabel; -import com.google.common.collect.Iterables; +import org.apache.commons.collections4.CollectionUtils; -import javax.swing.*; +import javax.swing.AbstractListModel; +import javax.swing.ComboBoxModel; import java.util.ArrayList; import java.util.List; @@ -41,12 +42,12 @@ public class CheckBoxComboBoxModel<HL extends HasLabel> extends AbstractListMode private List<HL> values; public CheckBoxComboBoxModel(List<HL> values, List<HL> selection) { - this.values = new ArrayList<HL>(); + this.values = new ArrayList<>(); if (values != null) { this.values.addAll(values); } - this.selection = new ArrayList<Object>(); + this.selection = new ArrayList<>(); if (selection != null) { this.selection.addAll(selection); } @@ -54,7 +55,7 @@ public class CheckBoxComboBoxModel<HL extends HasLabel> extends AbstractListMode @Override public void setSelectedItem(Object anItem) { - selection = new ArrayList<Object>(selection); + selection = new ArrayList<>(selection); if (selection.contains(anItem)) { selection.remove(anItem); @@ -76,6 +77,6 @@ public class CheckBoxComboBoxModel<HL extends HasLabel> extends AbstractListMode @Override public HL getElementAt(int index) { - return Iterables.get(values, index); + return CollectionUtils.get(values, index); } } diff --git a/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/util/CheckBoxListCellRenderer.java b/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/util/CheckBoxListCellRenderer.java index 6d8aee9..defe00b 100644 --- a/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/util/CheckBoxListCellRenderer.java +++ b/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/util/CheckBoxListCellRenderer.java @@ -25,15 +25,22 @@ package com.franciaflex.faxtomail.ui.swing.util; */ import com.franciaflex.faxtomail.persistence.entities.HasLabel; -import com.google.common.base.Function; -import com.google.common.collect.Lists; import org.apache.commons.lang3.StringUtils; -import javax.swing.*; +import javax.swing.DefaultListCellRenderer; +import javax.swing.JCheckBox; +import javax.swing.JComponent; +import javax.swing.JLabel; +import javax.swing.JList; +import javax.swing.ListCellRenderer; +import javax.swing.UIManager; import javax.swing.border.Border; import javax.swing.border.EmptyBorder; -import java.awt.*; +import java.awt.Color; +import java.awt.Component; +import java.awt.Rectangle; import java.io.Serializable; +import java.util.stream.Collectors; import static org.nuiton.i18n.I18n.t; @@ -135,14 +142,11 @@ public abstract class CheckBoxListCellRenderer<HL extends HasLabel> } else { - if (value != null && java.util.List.class.isAssignableFrom(value.getClass())) { + if (java.util.List.class.isAssignableFrom(value.getClass())) { java.util.List<HL> etats = (java.util.List<HL>) value; - java.util.List<String> e = Lists.transform(etats, new Function<HL, String>() { - @Override - public String apply(HL input) { - return input != null ? input.getLabel() : noneLabel; - } - }); + java.util.List<String> e = etats.stream() + .map(input -> input != null ? input.getLabel() : noneLabel) + .collect(Collectors.toList()); decorate = StringUtils.join(e, " ou "); label.setText(decorate); } @@ -272,8 +276,8 @@ public abstract class CheckBoxListCellRenderer<HL extends HasLabel> @Override protected void firePropertyChange(String propertyName, Object oldValue, Object newValue) { // Strings get interned... - if (propertyName == "text" - || ((propertyName == "font" || propertyName == "foreground") + if ("text".equals(propertyName) + || (("font".equals(propertyName) || "foreground".equals(propertyName)) && oldValue != newValue && getClientProperty(javax.swing.plaf.basic.BasicHTML.propertyKey) != null)) { @@ -428,8 +432,8 @@ public abstract class CheckBoxListCellRenderer<HL extends HasLabel> @Override protected void firePropertyChange(String propertyName, Object oldValue, Object newValue) { // Strings get interned... - if (propertyName == "text" - || ((propertyName == "font" || propertyName == "foreground") + if ("text".equals(propertyName) + || (("font".equals(propertyName) || "foreground".equals(propertyName)) && oldValue != newValue && getClientProperty(javax.swing.plaf.basic.BasicHTML.propertyKey) != null)) { diff --git a/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/util/DemandeTableModel.java b/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/util/DemandeTableModel.java index 77cf1fa..b2c77d7 100644 --- a/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/util/DemandeTableModel.java +++ b/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/util/DemandeTableModel.java @@ -25,13 +25,8 @@ package com.franciaflex.faxtomail.ui.swing.util; import com.franciaflex.faxtomail.persistence.entities.Email; import com.franciaflex.faxtomail.persistence.entities.MailField; import com.franciaflex.faxtomail.ui.swing.content.demande.DemandeUIModel; -import com.google.common.base.Preconditions; -import com.google.common.base.Predicate; -import com.google.common.collect.Iterables; -import com.google.common.collect.Lists; import com.google.common.collect.Sets; import jaxx.runtime.SwingUtil; -import org.apache.commons.lang3.ObjectUtils; import org.apache.commons.lang3.tuple.Pair; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -44,6 +39,7 @@ import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.Objects; import java.util.Set; import static org.nuiton.i18n.I18n.n; @@ -60,157 +56,157 @@ public class DemandeTableModel extends AbstractTableModel { public static final Map<MailField, ColumnIdentifier<Email>> COLUMN_IDENTIFIERS = new HashMap<MailField, ColumnIdentifier<Email>>() {{ put(MailField.SENDER, - ColumnIdentifier.<Email>newReadOnlyId( + ColumnIdentifier.newReadOnlyId( Email.PROPERTY_SENDER, n("faxtomail.demandeList.table.header.sender"), n("faxtomail.demandeList.table.header.sender.tip"))); put(MailField.OBJECT, - ColumnIdentifier.<Email>newReadOnlyId( + ColumnIdentifier.newReadOnlyId( Email.PROPERTY_OBJECT, n("faxtomail.demandeList.table.header.object"), n("faxtomail.demandeList.table.header.object.tip"))); put(MailField.RECEPTION_DATE, - ColumnIdentifier.<Email>newReadOnlyId( + ColumnIdentifier.newReadOnlyId( Email.PROPERTY_RECEPTION_DATE, n("faxtomail.demandeList.table.header.receptionDate"), n("faxtomail.demandeList.table.header.receptionDate.tip"))); put(MailField.RECIPIENT, - ColumnIdentifier.<Email>newReadOnlyId( + ColumnIdentifier.newReadOnlyId( Email.PROPERTY_RECIPIENT, n("faxtomail.demandeList.table.header.recipient"), n("faxtomail.demandeList.table.header.recipient.tip"))); put(MailField.CLIENT_CODE, - ColumnIdentifier.<Email>newReadOnlyId( + ColumnIdentifier.newReadOnlyId( DemandeUIModel.PROPERTY_CLIENT_CODE, n("faxtomail.demandeList.table.header.clientCode"), n("faxtomail.demandeList.table.header.clientCode.tip"))); put(MailField.CLIENT_NAME, - ColumnIdentifier.<Email>newReadOnlyId( + ColumnIdentifier.newReadOnlyId( DemandeUIModel.PROPERTY_CLIENT_NAME, n("faxtomail.demandeList.table.header.clientName"), n("faxtomail.demandeList.table.header.clientName.tip"))); put(MailField.CLIENT_BRAND, - ColumnIdentifier.<Email>newReadOnlyId( + ColumnIdentifier.newReadOnlyId( DemandeUIModel.PROPERTY_CLIENT_BRAND, n("faxtomail.demandeList.table.header.brand"), n("faxtomail.demandeList.table.header.brand.tip"))); put(MailField.DEMAND_STATUS, - ColumnIdentifier.<Email>newReadOnlyId( + ColumnIdentifier.newReadOnlyId( Email.PROPERTY_DEMAND_STATUS, n("faxtomail.demandeList.table.header.status"), n("faxtomail.demandeList.table.header.status.tip"))); put(MailField.DEMAND_TYPE, - ColumnIdentifier.<Email>newReadOnlyId( + ColumnIdentifier.newReadOnlyId( Email.PROPERTY_DEMAND_TYPE, n("faxtomail.demandeList.table.header.type"), n("faxtomail.demandeList.table.header.type.tip"))); put(MailField.EDI_RETURN, - ColumnIdentifier.<Email>newReadOnlyId( + ColumnIdentifier.newReadOnlyId( Email.PROPERTY_EDI_ERROR, n("faxtomail.demandeList.table.header.ediCodeNumber"), n("faxtomail.demandeList.table.header.ediCodeNumber.tip"))); put(MailField.WAITING_STATE, - ColumnIdentifier.<Email>newReadOnlyId( + ColumnIdentifier.newReadOnlyId( Email.PROPERTY_WAITING_STATE, n("faxtomail.demandeList.table.header.waitingState"), n("faxtomail.demandeList.table.header.waitingState.tip"))); put(MailField.TAKEN_BY, - ColumnIdentifier.<Email>newReadOnlyId( + ColumnIdentifier.newReadOnlyId( Email.PROPERTY_TAKEN_BY, n("faxtomail.demandeList.table.header.user"), n("faxtomail.demandeList.table.header.user.tip"))); put(MailField.PRIORITY, - ColumnIdentifier.<Email>newId( + ColumnIdentifier.newId( Email.PROPERTY_PRIORITY, n("faxtomail.demandeList.table.header.priority"), n("faxtomail.demandeList.table.header.priority.tip"))); put(MailField.PROJECT_REFERENCE, - ColumnIdentifier.<Email>newReadOnlyId( + ColumnIdentifier.newReadOnlyId( Email.PROPERTY_PROJECT_REFERENCE, n("faxtomail.demandeList.table.header.projectReference"), n("faxtomail.demandeList.table.header.projectReference.tip"))); put(MailField.COMPANY_REFERENCE, - ColumnIdentifier.<Email>newReadOnlyId( + ColumnIdentifier.newReadOnlyId( Email.PROPERTY_COMPANY_REFERENCE, n("faxtomail.demandeList.table.header.companyReference"), n("faxtomail.demandeList.table.header.companyReference.tip"))); put(MailField.REFERENCE, - ColumnIdentifier.<Email>newReadOnlyId( + ColumnIdentifier.newReadOnlyId( DemandeUIModel.PROPERTY_REFERENCE, n("faxtomail.demandeList.table.header.reference"), n("faxtomail.demandeList.table.header.reference.tip"))); put(MailField.RANGE_ROW, - ColumnIdentifier.<Email>newReadOnlyId( + ColumnIdentifier.newReadOnlyId( Email.PROPERTY_RANGE_ROW, n("faxtomail.demandeList.table.header.range"), n("faxtomail.demandeList.table.header.range.tip"))); put(MailField.PF_NB, - ColumnIdentifier.<Email>newReadOnlyId( + ColumnIdentifier.newReadOnlyId( DemandeUIModel.PROPERTY_PF_NB, n("faxtomail.demandeList.table.header.pfNb"), n("faxtomail.demandeList.table.header.pfNb.tip"))); put(MailField.SAV_NB, - ColumnIdentifier.<Email>newReadOnlyId( + ColumnIdentifier.newReadOnlyId( DemandeUIModel.PROPERTY_SAV_NB, n("faxtomail.demandeList.table.header.savNb"), n("faxtomail.demandeList.table.header.savNb.tip"))); put(MailField.QUOTATION_NB, - ColumnIdentifier.<Email>newReadOnlyId( + ColumnIdentifier.newReadOnlyId( DemandeUIModel.PROPERTY_QUOTATION_NB, n("faxtomail.demandeList.table.header.quotationNb"), n("faxtomail.demandeList.table.header.quotationNb.tip"))); put(MailField.REPLIES, - ColumnIdentifier.<Email>newId( + ColumnIdentifier.newId( Email.PROPERTY_REPLIES, n("faxtomail.demandeList.table.header.replies"), n("faxtomail.demandeList.table.header.replies.tip"))); put(MailField.ATTACHMENT, - ColumnIdentifier.<Email>newId( + ColumnIdentifier.newId( Email.PROPERTY_ATTACHMENT, n("faxtomail.demandeList.table.header.attachment"), n("faxtomail.demandeList.table.header.attachment.tip"))); put(MailField.GROUP, - ColumnIdentifier.<Email>newId( + ColumnIdentifier.newId( DemandeUIModel.PROPERTY_GROUPED_DEMANDES, n("faxtomail.demandeList.table.header.emailGroup"), n("faxtomail.demandeList.table.header.emailGroup.tip"))); put(MailField.LAST_ATTACHMENT_OPENING_IN_THIS_FOLDER_USER, - ColumnIdentifier.<Email>newId( + ColumnIdentifier.newId( Email.PROPERTY_LAST_ATTACHMENT_OPENER, n("faxtomail.demandeList.table.header.lastAttachmentOpeningUser"), n("faxtomail.demandeList.table.header.lastAttachmentOpeningUser.tip"))); put(MailField.COMMENT, - ColumnIdentifier.<Email>newId( + ColumnIdentifier.newId( Email.PROPERTY_COMMENT, n("faxtomail.demandeList.table.header.comment"), n("faxtomail.demandeList.table.header.comment.tip"))); put(MailField.SUBJECT, - ColumnIdentifier.<Email>newId( + ColumnIdentifier.newId( Email.PROPERTY_SUBJECT, n("faxtomail.demandeList.table.header.subject"), n("faxtomail.demandeList.table.header.subject.tip"))); @@ -219,12 +215,12 @@ public class DemandeTableModel extends AbstractTableModel { public DemandeTableModel(TableColumnModelExt columnModel, MailField... editableProperties) { - this.identifiers = Lists.newArrayListWithCapacity(columnModel.getColumnCount()); + this.identifiers = new ArrayList<>(columnModel.getColumnCount()); for (TableColumn tc : columnModel.getColumns(true)) { this.identifiers.add((ColumnIdentifier<DemandeUIModel>) tc.getIdentifier()); } - List<ColumnIdentifier> nonEditableColumns = new ArrayList<ColumnIdentifier>(COLUMN_IDENTIFIERS.values()); + List<ColumnIdentifier> nonEditableColumns = new ArrayList<>(COLUMN_IDENTIFIERS.values()); for (MailField editableProperty : editableProperties) { nonEditableColumns.remove(COLUMN_IDENTIFIERS.get(editableProperty)); } @@ -263,7 +259,7 @@ public class DemandeTableModel extends AbstractTableModel { public final void setRows(List<DemandeUIModel> data) { // can't accept a empty data list - Preconditions.checkNotNull(data, "Data list can not be null."); + Objects.requireNonNull(data, "Data list can not be null."); this.rows = null; if (log.isDebugEnabled()) { @@ -286,10 +282,10 @@ public class DemandeTableModel extends AbstractTableModel { public final void addNewRow(int rowIndex, DemandeUIModel newValue) { - Preconditions.checkNotNull(newValue, "Row can not be null."); + Objects.requireNonNull(newValue, "Row can not be null."); List<DemandeUIModel> data = getRows(); - Preconditions.checkNotNull(data, "Data list can not be null."); + Objects.requireNonNull(data, "Data list can not be null."); data.add(rowIndex, newValue); @@ -299,17 +295,17 @@ public class DemandeTableModel extends AbstractTableModel { public final void fireTableRowsInserted(DemandeUIModel newValue) { - Preconditions.checkNotNull(newValue, "Row can not be null."); + Objects.requireNonNull(newValue, "Row can not be null."); int rowIndex = getRowIndex(newValue); fireTableRowsInserted(rowIndex, rowIndex); } public final int updateRow(DemandeUIModel row) { - Preconditions.checkNotNull(row, "Row can not be null."); + Objects.requireNonNull(row, "Row can not be null."); List<DemandeUIModel> data = getRows(); - Preconditions.checkNotNull(data, "Data list can not be null."); + Objects.requireNonNull(data, "Data list can not be null."); int rowIndex = data.indexOf(row); @@ -337,8 +333,7 @@ public class DemandeTableModel extends AbstractTableModel { } public final int getRowIndex(DemandeUIModel row) { - int result = rows == null ? -1 : rows.indexOf(row); - return result; + return rows == null ? -1 : rows.indexOf(row); } // cf #5944 java.lang.ArrayIndexOutOfBoundsException: the rowIndex was 15, but should be int [0,14] @@ -352,8 +347,7 @@ public class DemandeTableModel extends AbstractTableModel { return null; } List<DemandeUIModel> data = getRows(); - DemandeUIModel result = data == null ? null : data.get(rowIndex); - return result; + return data == null ? null : data.get(rowIndex); } public final void setNoneEditableCols(ColumnIdentifier<?>... noneEditableCols) { @@ -374,8 +368,7 @@ public class DemandeTableModel extends AbstractTableModel { public final Object getValueAt(int rowIndex, int columnIndex) { DemandeUIModel entry = getEntry(rowIndex); ColumnIdentifier<DemandeUIModel> identifier = getIdentifier(columnIndex); - Object result = identifier.getValue(entry); - return result; + return identifier.getValue(entry); } @Override @@ -411,11 +404,10 @@ public class DemandeTableModel extends AbstractTableModel { DemandeUIModel entry = getEntry(rowIndex); - boolean result = (COLUMN_IDENTIFIERS.get(MailField.ATTACHMENT).equals(propertyName) || - COLUMN_IDENTIFIERS.get(MailField.REPLIES).equals(propertyName) || - entry.isEditable()) - && !noneEditableCols.contains(propertyName); - return result; + return (COLUMN_IDENTIFIERS.get(MailField.ATTACHMENT).equals(propertyName) || + COLUMN_IDENTIFIERS.get(MailField.REPLIES).equals(propertyName) || + entry.isEditable()) + && !noneEditableCols.contains(propertyName); } public final void fireTableCellUpdated(int rowIndex, @@ -451,17 +443,16 @@ public class DemandeTableModel extends AbstractTableModel { } protected ColumnIdentifier<DemandeUIModel> getIdentifier(int columnIndex) { - ColumnIdentifier<DemandeUIModel> identifier = identifiers.get(columnIndex); - return identifier; + return identifiers.get(columnIndex); } public int getColumnIndex(final String propertyName) { - return Iterables.indexOf(identifiers, new Predicate<ColumnIdentifier<DemandeUIModel>>() { - @Override - public boolean apply(ColumnIdentifier<DemandeUIModel> input) { - return ObjectUtils.equals(propertyName, input.getPropertyName()); + for (int i = 0 ; i < identifiers.size() ; i++) { + if (Objects.equals(propertyName, identifiers.get(i).getPropertyName())) { + return i; } - }); + } + return -1; } public Pair<Integer, Integer> getCell(DemandeUIModel row, final String propertyName) { @@ -469,9 +460,7 @@ public class DemandeTableModel extends AbstractTableModel { int rowIndex = getRowIndex(row); int columnIndex = getColumnIndex(propertyName); - Pair<Integer, Integer> cell = Pair.of(rowIndex, columnIndex); - - return cell; + return Pair.of(rowIndex, columnIndex); } public void moveUp(DemandeUIModel row) { diff --git a/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/util/FaxToMailUIUtil.java b/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/util/FaxToMailUIUtil.java index c2f35ca..a9b18d2 100644 --- a/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/util/FaxToMailUIUtil.java +++ b/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/util/FaxToMailUIUtil.java @@ -38,10 +38,6 @@ import com.franciaflex.faxtomail.ui.swing.FaxToMailUIContext; import com.franciaflex.faxtomail.ui.swing.content.demande.DemandeUIHandler; import com.franciaflex.faxtomail.ui.swing.content.demande.DemandeUIModel; import com.franciaflex.faxtomail.ui.swing.content.demande.RangeRowModel; -import com.google.common.base.Function; -import com.google.common.base.Preconditions; -import com.google.common.collect.Lists; -import com.google.common.collect.Ordering; import com.itextpdf.text.Document; import com.itextpdf.text.DocumentException; import com.itextpdf.text.PageSize; @@ -54,7 +50,6 @@ import com.sun.media.jai.codec.SeekableStream; import jaxx.runtime.JAXXObject; import jaxx.runtime.JAXXUtil; import org.apache.commons.collections4.CollectionUtils; -import org.apache.commons.collections4.Predicate; import org.apache.commons.io.Charsets; import org.apache.commons.io.FilenameUtils; import org.apache.commons.io.IOUtils; @@ -79,7 +74,6 @@ import javax.swing.JPanel; import javax.swing.JTextPane; import javax.swing.JTree; import javax.swing.event.HyperlinkEvent; -import javax.swing.event.HyperlinkListener; import javax.swing.tree.DefaultMutableTreeNode; import javax.swing.tree.DefaultTreeCellRenderer; import javax.swing.tree.DefaultTreeModel; @@ -89,10 +83,8 @@ import java.awt.Color; import java.awt.Component; import java.awt.Desktop; import java.awt.Font; -import java.awt.Graphics; import java.awt.image.BufferedImage; import java.awt.image.RenderedImage; -import java.awt.print.PageFormat; import java.awt.print.Printable; import java.awt.print.PrinterException; import java.awt.print.PrinterJob; @@ -109,13 +101,14 @@ import java.nio.ByteBuffer; import java.nio.channels.FileChannel; import java.nio.charset.StandardCharsets; import java.util.ArrayList; +import java.util.Arrays; import java.util.Collection; -import java.util.Collections; import java.util.Comparator; import java.util.Enumeration; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.Objects; import java.util.regex.Pattern; import static org.nuiton.i18n.I18n.t; @@ -129,8 +122,8 @@ public final class FaxToMailUIUtil extends ApplicationUIUtil { /** Logger. */ private static final Log log = LogFactory.getLog(FaxToMailUIUtil.class); - public static final List<String> EDITABLE_EXTENSIONS = Lists.newArrayList("PDF", "PNG", "JPG", "JPEG", "GIF", - "TIF", "BMP", "TXT"); + public static final List<String> EDITABLE_EXTENSIONS = Arrays.asList("PDF", "PNG", "JPG", "JPEG", "GIF", + "TIF", "BMP", "TXT"); private FaxToMailUIUtil() { // never instanciate util class @@ -152,14 +145,9 @@ public final class FaxToMailUIUtil extends ApplicationUIUtil { final boolean colorNotAffectedFolders) { DefaultMutableTreeNode root = new DefaultMutableTreeNode("root"); - Map<MailFolder, FolderTreeNode> nodesByFolder = new HashMap<MailFolder, FolderTreeNode>(); - List<MailFolder> orderedFolders = new ArrayList<MailFolder>(folders); - Collections.sort(orderedFolders, Ordering.natural().onResultOf(new Function<MailFolder, Comparable>() { - @Override - public Comparable apply(MailFolder folder) { - return folder.getName(); - } - })); + Map<MailFolder, FolderTreeNode> nodesByFolder = new HashMap<>(); + List<MailFolder> orderedFolders = new ArrayList<>(folders); + orderedFolders.sort(Comparator.comparing(MailFolder::getName)); for (MailFolder folder : orderedFolders) { nodesByFolder.putAll(FaxToMailUIUtil.createFolderTree(context, root, folder)); @@ -245,7 +233,7 @@ public final class FaxToMailUIUtil extends ApplicationUIUtil { public static List<MailFolder> getExpandedFolders(JTree tree) { TreeModel treeModel = tree.getModel(); Enumeration<TreePath> paths = tree.getExpandedDescendants(new TreePath(treeModel.getRoot())); - java.util.List<MailFolder> folders = new ArrayList<MailFolder>(); + java.util.List<MailFolder> folders = new ArrayList<>(); if (paths != null) { while (paths.hasMoreElements()) { TreePath path = paths.nextElement(); @@ -267,7 +255,7 @@ public final class FaxToMailUIUtil extends ApplicationUIUtil { protected static Map<MailFolder, FolderTreeNode> createFolderTree(FaxToMailUIContext context, DefaultMutableTreeNode parent, MailFolder folder) { - Map<MailFolder, FolderTreeNode> result = new HashMap<MailFolder, FolderTreeNode>(); + Map<MailFolder, FolderTreeNode> result = new HashMap<>(); FolderTreeNode node = new FolderTreeNode(folder); node.setCanSelect(true); @@ -276,19 +264,9 @@ public final class FaxToMailUIUtil extends ApplicationUIUtil { parent.add(node); if (folder.isChildrenNotEmpty()) { - List<MailFolder> children = new ArrayList<MailFolder>(folder.getChildren()); - CollectionUtils.filter(children, new Predicate<MailFolder>() { - @Override - public boolean evaluate(MailFolder object) { - return !object.isArchiveFolder(); - } - }); - Collections.sort(children, new Comparator<MailFolder>() { - @Override - public int compare(MailFolder o1, MailFolder o2) { - return o1.getName().compareTo(o2.getName()); - } - }); + List<MailFolder> children = new ArrayList<>(folder.getChildren()); + CollectionUtils.filter(children, object -> !object.isArchiveFolder()); + children.sort(Comparator.comparing(MailFolder::getName)); for (MailFolder child : children) { result.putAll(createFolderTree(context, node, child)); } @@ -325,7 +303,7 @@ public final class FaxToMailUIUtil extends ApplicationUIUtil { } } } - Map<String, Integer> result = new HashMap<String, Integer>(); + Map<String, Integer> result = new HashMap<>(); result.put(DemandeUIModel.PROPERTY_QUOTATION_NB, quotationNb); result.put(DemandeUIModel.PROPERTY_PF_NB, pfNb); result.put(DemandeUIModel.PROPERTY_SAV_NB, savNb); @@ -524,64 +502,62 @@ public final class FaxToMailUIUtil extends ApplicationUIUtil { final PDFRenderer renderer = new PDFRenderer(pdDocument); final int numOfPages = pdDocument.getNumberOfPages(); - printJob.setPrintable(new Printable() { - public int print(Graphics graphics, PageFormat pageFormat, int pageIndex) throws PrinterException { - try { - if (pageIndex >= numOfPages) { - return NO_SUCH_PAGE; - } - - double paperWidth = (int) pageFormat.getImageableWidth(); - double paperHeight = (int) pageFormat.getImageableHeight(); - int paperX = (int) pageFormat.getImageableX(); - int paperY = (int) pageFormat.getImageableY(); - - if (log.isDebugEnabled()) { - log.debug("page width " + paperWidth); - log.debug("page height " + paperHeight); - log.debug("page x " + paperX); - log.debug("page y " + paperY); - } - - BufferedImage image = renderer.renderImageWithDPI(pageIndex, 300); - - int imageWidth = image.getWidth(); - int imageHeight = image.getHeight(); - double widthRatio = paperWidth / imageWidth; - double heightRatio = paperHeight / imageHeight; - - if (log.isDebugEnabled()) { - log.debug("width ratio : " + widthRatio); - log.debug("height ratio : " + heightRatio); - } - - int width; - int height; - // if the image is smaller than the page - if (widthRatio >= 1 && heightRatio >= 1) { - width = imageWidth; - height = imageHeight; - - } else { - double minRatio = Math.min(widthRatio, heightRatio); - width = (int) (minRatio * imageWidth); - height = (int) (minRatio * imageHeight); - } - - if (log.isDebugEnabled()) { - log.debug("image width : " + width); - log.debug("image height : " + height); - } - graphics.drawImage(image, paperX, paperY, width, height, null); - - return PAGE_EXISTS; - - } catch (Exception e) { - if (log.isErrorEnabled()) { - log.error("error while printing", e); - } - return NO_SUCH_PAGE; + printJob.setPrintable((graphics, pageFormat, pageIndex) -> { + try { + if (pageIndex >= numOfPages) { + return Printable.NO_SUCH_PAGE; + } + + double paperWidth = (int) pageFormat.getImageableWidth(); + double paperHeight = (int) pageFormat.getImageableHeight(); + int paperX = (int) pageFormat.getImageableX(); + int paperY = (int) pageFormat.getImageableY(); + + if (log.isDebugEnabled()) { + log.debug("page width " + paperWidth); + log.debug("page height " + paperHeight); + log.debug("page x " + paperX); + log.debug("page y " + paperY); + } + + BufferedImage image = renderer.renderImageWithDPI(pageIndex, 300); + + int imageWidth = image.getWidth(); + int imageHeight = image.getHeight(); + double widthRatio = paperWidth / imageWidth; + double heightRatio = paperHeight / imageHeight; + + if (log.isDebugEnabled()) { + log.debug("width ratio : " + widthRatio); + log.debug("height ratio : " + heightRatio); } + + int width; + int height; + // if the image is smaller than the page + if (widthRatio >= 1 && heightRatio >= 1) { + width = imageWidth; + height = imageHeight; + + } else { + double minRatio = Math.min(widthRatio, heightRatio); + width = (int) (minRatio * imageWidth); + height = (int) (minRatio * imageHeight); + } + + if (log.isDebugEnabled()) { + log.debug("image width : " + width); + log.debug("image height : " + height); + } + graphics.drawImage(image, paperX, paperY, width, height, null); + + return Printable.PAGE_EXISTS; + + } catch (Exception e) { + if (log.isErrorEnabled()) { + log.error("error while printing", e); + } + return Printable.NO_SUCH_PAGE; } }); @@ -620,8 +596,7 @@ public final class FaxToMailUIUtil extends ApplicationUIUtil { } else { type = FileType.OTHER; } - File result = convertFileToPdf(new FileInputStream(file), type); - return result; + return convertFileToPdf(new FileInputStream(file), type); } protected enum FileType { @@ -730,7 +705,7 @@ public final class FaxToMailUIUtil extends ApplicationUIUtil { if (extCommand != null && StringUtils.isNotBlank(extCommand.getOpenAttachmentCommand())) { String command = extCommand.getOpenAttachmentCommand(); String[] args = StringUtil.split(command, " "); - List<String> comArgs = new ArrayList<String>(); + List<String> comArgs = new ArrayList<>(); for (String arg : args) { String localArg = arg; localArg = localArg.replace("%f", file.getAbsolutePath()); @@ -804,7 +779,7 @@ public final class FaxToMailUIUtil extends ApplicationUIUtil { JPanel textPanePanel, String content) { - Preconditions.checkNotNull(content); + Objects.requireNonNull(content); JTextPane textPane = createHtmlTextPane(); @@ -870,24 +845,20 @@ public final class FaxToMailUIUtil extends ApplicationUIUtil { Font font = new Font(Font.MONOSPACED, Font.PLAIN, 16); textPane.setFont(font); - textPane.addHyperlinkListener(new HyperlinkListener() { - @Override - public void hyperlinkUpdate(HyperlinkEvent e) { - if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) { - FaxToMailUIUtil.openLink(e.getURL()); - } + textPane.addHyperlinkListener(e -> { + if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) { + FaxToMailUIUtil.openLink(e.getURL()); } }); return textPane; } public static String getQuotedReplyContent(String signing, String receptionDate, String sender, String originalEmail) { - String quotedReply = t("faxtomail.reply.message", - signing, - receptionDate, - sender, - originalEmail); - return quotedReply; + return t("faxtomail.reply.message", + signing, + receptionDate, + sender, + originalEmail); } } diff --git a/faxtomail-ui-web/src/main/java/com/franciaflex/faxtomail/FaxToMailApplicationContext.java b/faxtomail-ui-web/src/main/java/com/franciaflex/faxtomail/FaxToMailApplicationContext.java index e7c8577..d2c51eb 100644 --- a/faxtomail-ui-web/src/main/java/com/franciaflex/faxtomail/FaxToMailApplicationContext.java +++ b/faxtomail-ui-web/src/main/java/com/franciaflex/faxtomail/FaxToMailApplicationContext.java @@ -57,9 +57,7 @@ public class FaxToMailApplicationContext { public FaxToMailTopiaPersistenceContext newPersistenceContext() { - FaxToMailTopiaPersistenceContext persistenceContext = getTopiaApplicationContext().newPersistenceContext(); - - return persistenceContext; + return getTopiaApplicationContext().newPersistenceContext(); } diff --git a/faxtomail-ui-web/src/main/java/com/franciaflex/faxtomail/web/FaxToMailActionSupport.java b/faxtomail-ui-web/src/main/java/com/franciaflex/faxtomail/web/FaxToMailActionSupport.java index 364d938..13d1890 100644 --- a/faxtomail-ui-web/src/main/java/com/franciaflex/faxtomail/web/FaxToMailActionSupport.java +++ b/faxtomail-ui-web/src/main/java/com/franciaflex/faxtomail/web/FaxToMailActionSupport.java @@ -33,7 +33,6 @@ import com.franciaflex.faxtomail.persistence.entities.MailFolderAbstract; import com.franciaflex.faxtomail.web.json.HibernateProxyTypeAdapter; import com.franciaflex.faxtomail.web.json.TopiaEntityAdapter; import com.google.common.collect.HashMultimap; -import com.google.common.collect.Maps; import com.google.common.collect.Multimap; import com.google.gson.ExclusionStrategy; import com.google.gson.FieldAttributes; @@ -46,6 +45,7 @@ import org.apache.struts2.convention.annotation.Result; import org.apache.struts2.convention.annotation.Results; import org.nuiton.topia.persistence.TopiaEntity; +import java.util.LinkedHashMap; import java.util.Map; @Results({ @@ -72,8 +72,7 @@ public class FaxToMailActionSupport extends ActionSupport { public boolean shouldSkipField(FieldAttributes f) { Class<?> declaringClass = f.getDeclaringClass(); String attributeName = f.getName(); - boolean result = GSON_EXCLUSIONS.containsEntry(declaringClass, attributeName); - return result; + return GSON_EXCLUSIONS.containsEntry(declaringClass, attributeName); } @Override @@ -158,7 +157,7 @@ public class FaxToMailActionSupport extends ActionSupport { * @return map (enum value > i18n text) */ protected <T> Map<T, String> getEnumAsMap(T... values) { - Map<T, String> valuesMap = Maps.newLinkedHashMap(); + Map<T, String> valuesMap = new LinkedHashMap<>(); for (T value : values) { String i18n = value.getClass().getName() + "." + value.toString(); String trans = getText(i18n); diff --git a/faxtomail-ui-web/src/main/java/com/franciaflex/faxtomail/web/FaxToMailInterceptor.java b/faxtomail-ui-web/src/main/java/com/franciaflex/faxtomail/web/FaxToMailInterceptor.java index cf10f9e..20398ed 100644 --- a/faxtomail-ui-web/src/main/java/com/franciaflex/faxtomail/web/FaxToMailInterceptor.java +++ b/faxtomail-ui-web/src/main/java/com/franciaflex/faxtomail/web/FaxToMailInterceptor.java @@ -32,7 +32,6 @@ import com.franciaflex.faxtomail.persistence.entities.FaxToMailUserGroup; import com.franciaflex.faxtomail.services.FaxToMailService; import com.franciaflex.faxtomail.services.FaxToMailServiceContext; import com.franciaflex.faxtomail.services.service.LdapService; -import com.google.common.base.Preconditions; import com.opensymphony.xwork2.ActionInvocation; import com.opensymphony.xwork2.ActionProxy; import com.opensymphony.xwork2.interceptor.Interceptor; @@ -45,6 +44,7 @@ import org.nuiton.util.beans.BeanUtil; import java.beans.PropertyDescriptor; import java.util.List; import java.util.Map; +import java.util.Objects; import java.util.Set; public class FaxToMailInterceptor implements Interceptor { @@ -196,8 +196,8 @@ public class FaxToMailInterceptor implements Interceptor { .getApplication() .get(FaxToMailApplicationContext.APPLICATION_CONTEXT_PARAMETER); - Preconditions.checkNotNull(applicationContext, - "application context must be initialized before calling an action"); + Objects.requireNonNull(applicationContext, + "application context must be initialized before calling an action"); return applicationContext; @@ -207,9 +207,8 @@ public class FaxToMailInterceptor implements Interceptor { FaxToMailApplicationContext extranetEncAhiApplicationContext = getFaxToMailApplicationContext(invocation); FaxToMailTopiaPersistenceContext persistenceContext = extranetEncAhiApplicationContext.newPersistenceContext(); - FaxToMailServiceContext serviceContext = extranetEncAhiApplicationContext.newServiceContext(persistenceContext); - return serviceContext; + return extranetEncAhiApplicationContext.newServiceContext(persistenceContext); } @Override diff --git a/faxtomail-ui-web/src/main/java/com/franciaflex/faxtomail/web/FaxToMailJsonResultSupport.java b/faxtomail-ui-web/src/main/java/com/franciaflex/faxtomail/web/FaxToMailJsonResultSupport.java index 67b7500..b9a3874 100644 --- a/faxtomail-ui-web/src/main/java/com/franciaflex/faxtomail/web/FaxToMailJsonResultSupport.java +++ b/faxtomail-ui-web/src/main/java/com/franciaflex/faxtomail/web/FaxToMailJsonResultSupport.java @@ -24,9 +24,9 @@ package com.franciaflex.faxtomail.web; * #L% */ -import com.google.common.base.Charsets; import com.opensymphony.xwork2.Action; import com.opensymphony.xwork2.ActionInvocation; +import org.apache.commons.io.Charsets; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.apache.struts2.dispatcher.StrutsResultSupport; diff --git a/faxtomail-ui-web/src/main/java/com/franciaflex/faxtomail/web/FaxToMailSession.java b/faxtomail-ui-web/src/main/java/com/franciaflex/faxtomail/web/FaxToMailSession.java index d69a8d9..1998866 100644 --- a/faxtomail-ui-web/src/main/java/com/franciaflex/faxtomail/web/FaxToMailSession.java +++ b/faxtomail-ui-web/src/main/java/com/franciaflex/faxtomail/web/FaxToMailSession.java @@ -25,10 +25,10 @@ package com.franciaflex.faxtomail.web; */ import com.franciaflex.faxtomail.persistence.entities.FaxToMailUser; -import com.google.common.collect.Lists; import java.io.Serializable; import java.util.Collection; +import java.util.LinkedList; public class FaxToMailSession implements Serializable { @@ -46,7 +46,7 @@ public class FaxToMailSession implements Serializable { public Collection<String> getMessages() { if (messages == null) { - messages = Lists.newLinkedList(); + messages = new LinkedList<>(); } return messages; } @@ -57,7 +57,7 @@ public class FaxToMailSession implements Serializable { public Collection<String> getErrorMessages() { if (errorMessages == null) { - errorMessages = Lists.newLinkedList(); + errorMessages = new LinkedList<>(); } return errorMessages; } diff --git a/faxtomail-ui-web/src/main/java/com/franciaflex/faxtomail/web/action/DemandDetailAction.java b/faxtomail-ui-web/src/main/java/com/franciaflex/faxtomail/web/action/DemandDetailAction.java index 2242274..fe8fa61 100644 --- a/faxtomail-ui-web/src/main/java/com/franciaflex/faxtomail/web/action/DemandDetailAction.java +++ b/faxtomail-ui-web/src/main/java/com/franciaflex/faxtomail/web/action/DemandDetailAction.java @@ -37,10 +37,6 @@ import com.franciaflex.faxtomail.services.DecoratorService; import com.franciaflex.faxtomail.services.FaxToMailServiceUtils; import com.franciaflex.faxtomail.services.service.EmailService; import com.franciaflex.faxtomail.web.FaxToMailActionSupport; -import com.google.common.base.Function; -import com.google.common.base.Preconditions; -import com.google.common.collect.Lists; -import com.google.common.collect.Ordering; import org.apache.commons.lang3.ArrayUtils; import org.apache.commons.lang3.StringUtils; import org.apache.commons.logging.Log; @@ -72,7 +68,9 @@ import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.util.ArrayList; import java.util.Collections; +import java.util.Comparator; import java.util.List; +import java.util.Objects; import static org.nuiton.i18n.I18n.t; @@ -230,7 +228,7 @@ public class DemandDetailAction extends FaxToMailActionSupport { } public List<EmailUIModel> getReplies() throws Exception { - Preconditions.checkNotNull(demand); + Objects.requireNonNull(demand); List<EmailUIModel> result = new ArrayList<>(); for (Reply reply : demand.getReplies()) { @@ -242,17 +240,17 @@ public class DemandDetailAction extends FaxToMailActionSupport { replyModel.setSubject(message.getSubject()); String toRecipient = message.getRecipients(MimeMessage.RecipientType.TO)[0].toString(); - replyModel.setToRecipients(Lists.newArrayList(toRecipient)); + replyModel.setToRecipients(Collections.singletonList(toRecipient)); replyModel.setSender(message.getFrom()[0].toString()); if (ArrayUtils.isNotEmpty(message.getRecipients(MimeMessage.RecipientType.CC))) { String ccRecipient = message.getRecipients(MimeMessage.RecipientType.CC)[0].toString(); - replyModel.setCcRecipients(Lists.newArrayList(ccRecipient)); + replyModel.setCcRecipients(Collections.singletonList(ccRecipient)); } if (ArrayUtils.isNotEmpty(message.getRecipients(MimeMessage.RecipientType.BCC))) { String bccRecipient = message.getRecipients(MimeMessage.RecipientType.BCC)[0].toString(); - replyModel.setBccRecipients(Lists.newArrayList(bccRecipient)); + replyModel.setBccRecipients(Collections.singletonList(bccRecipient)); } if (message.isMimeType("multipart/*")) { @@ -271,15 +269,10 @@ public class DemandDetailAction extends FaxToMailActionSupport { } public List<History> getHistories() { - Preconditions.checkNotNull(demand); + Objects.requireNonNull(demand); List<History> result = new ArrayList<>(demand.getHistory()); - Collections.sort(result, Ordering.natural().onResultOf(new Function<History, Comparable>() { - @Override - public Comparable apply(History history) { - return history.getModificationDate(); - } - })); + result.sort(Comparator.comparing(History::getModificationDate)); return result; } diff --git a/faxtomail-ui-web/src/main/java/com/franciaflex/faxtomail/web/action/SearchAction.java b/faxtomail-ui-web/src/main/java/com/franciaflex/faxtomail/web/action/SearchAction.java index 631a08d..25c80f7 100644 --- a/faxtomail-ui-web/src/main/java/com/franciaflex/faxtomail/web/action/SearchAction.java +++ b/faxtomail-ui-web/src/main/java/com/franciaflex/faxtomail/web/action/SearchAction.java @@ -35,9 +35,6 @@ 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; @@ -49,9 +46,11 @@ import org.apache.struts2.convention.annotation.Result; import org.nuiton.decorator.Decorator; import java.util.ArrayList; +import java.util.Arrays; import java.util.Collection; import java.util.List; import java.util.Map; +import java.util.stream.Collectors; /** * @author Kevin Morin (Code Lutin) @@ -112,7 +111,7 @@ public class SearchAction extends FaxToMailActionSupport { } else { List<MailField> mailFields = configurationService.getSearchDisplayColumns(); if (CollectionUtils.isEmpty(mailFields)) { - mailFields = Lists.newArrayList(MailField.getTableFields()); + mailFields = Arrays.asList(MailField.getTableFields()); } tableMailFields = getEnumAsMap(mailFields.toArray(new MailField[mailFields.size()])); } @@ -273,7 +272,7 @@ public class SearchAction extends FaxToMailActionSupport { String tooltipText = null; switch (field) { case PF_NB: - List<String> ranges = new ArrayList<String>(); + List<String> ranges = new ArrayList<>(); Collection<RangeRow> rangeRows = email.getRangeRow(); if (rangeRows != null) { for (RangeRow rangeRow : rangeRows) { @@ -290,7 +289,7 @@ public class SearchAction extends FaxToMailActionSupport { break; case SAV_NB: - ranges = new ArrayList<String>(); + ranges = new ArrayList<>(); rangeRows = email.getRangeRow(); if (rangeRows != null) { for (RangeRow rangeRow : rangeRows) { @@ -307,7 +306,7 @@ public class SearchAction extends FaxToMailActionSupport { break; case QUOTATION_NB: - ranges = new ArrayList<String>(); + ranges = new ArrayList<>(); rangeRows = email.getRangeRow(); if (rangeRows != null) { for (RangeRow rangeRow : rangeRows) { @@ -328,12 +327,9 @@ public class SearchAction extends FaxToMailActionSupport { 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); - } - }); + List<String> replyNames = replies.stream() + .map(decorator::toString) + .collect(Collectors.toList()); tooltipText = StringUtils.join(replyNames, "\n"); } break; @@ -343,16 +339,13 @@ public class SearchAction extends FaxToMailActionSupport { if (CollectionUtils.isNotEmpty(attachments)) { final Decorator<Attachment> decorator = decoratorService.getDecoratorByType(Attachment.class); - Collection<String> attachmentNames = Collections2.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; + Collection<String> attachmentNames = attachments.stream().map(attachment -> { + String name = decorator.toString(attachment); + if (attachment.getEditedFileName() != null) { + name += " (+ édité)"; } - }); + return name; + }).collect(Collectors.toList()); tooltipText = StringUtils.join(attachmentNames, "\n"); } break; @@ -370,17 +363,14 @@ public class SearchAction extends FaxToMailActionSupport { 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; + Collection<String> emailTitles = emails.stream().map(email1 -> { + String result = email1.getObject(); + String ref = email1.getReference(); + if (!ref.isEmpty()) { + result = ref + " - " + result; } - }); + return result; + }).collect(Collectors.toList()); tooltipText = StringUtils.join(emailTitles, "\n"); break; diff --git a/faxtomail-ui-web/src/main/java/com/franciaflex/faxtomail/web/job/AbstractFaxToMailJob.java b/faxtomail-ui-web/src/main/java/com/franciaflex/faxtomail/web/job/AbstractFaxToMailJob.java index 9ef59d6..3f76abc 100644 --- a/faxtomail-ui-web/src/main/java/com/franciaflex/faxtomail/web/job/AbstractFaxToMailJob.java +++ b/faxtomail-ui-web/src/main/java/com/franciaflex/faxtomail/web/job/AbstractFaxToMailJob.java @@ -33,7 +33,6 @@ public abstract class AbstractFaxToMailJob implements Job { public static final String APPLICATION_CONTEXT = "applicationContext"; protected FaxToMailApplicationContext getApplicationContext(JobExecutionContext jobExecutionContext) { - FaxToMailApplicationContext applicationContext = (FaxToMailApplicationContext) jobExecutionContext.getMergedJobDataMap().get(APPLICATION_CONTEXT); - return applicationContext; + return (FaxToMailApplicationContext) jobExecutionContext.getMergedJobDataMap().get(APPLICATION_CONTEXT); } } diff --git a/faxtomail-ui-web/src/main/java/com/franciaflex/faxtomail/web/job/MailFilterJob.java b/faxtomail-ui-web/src/main/java/com/franciaflex/faxtomail/web/job/MailFilterJob.java index 02d5c5e..2610b83 100644 --- a/faxtomail-ui-web/src/main/java/com/franciaflex/faxtomail/web/job/MailFilterJob.java +++ b/faxtomail-ui-web/src/main/java/com/franciaflex/faxtomail/web/job/MailFilterJob.java @@ -44,8 +44,6 @@ import com.franciaflex.faxtomail.services.service.ClientService; import com.franciaflex.faxtomail.services.service.ConfigurationService; import com.franciaflex.faxtomail.services.service.EmailService; import com.franciaflex.faxtomail.services.service.MailFolderService; -import com.google.common.base.Function; -import com.google.common.collect.Collections2; import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.lang3.StringUtils; import org.apache.commons.logging.Log; @@ -75,6 +73,7 @@ import java.util.HashSet; import java.util.List; import java.util.Properties; import java.util.Set; +import java.util.stream.Collectors; import static org.nuiton.i18n.I18n.t; @@ -251,18 +250,14 @@ public class MailFilterJob extends AbstractFaxToMailJob { if (allRecipients != null) { recipientAddresses.addAll(Arrays.asList(allRecipients)); } - Set<String> recipients = new HashSet<String>( - Collections2.transform(recipientAddresses, new Function<Address, String>() { - @Override - public String apply(Address address) { - String recipient = address.toString(); - // some recipient are like "toto tutu<toto.tutu73@gmail.com>" - // the regex is to extract email address from it - recipient = recipient.replaceAll("\\s", "").replaceFirst("^.*<(.*)>$", "$1"); - recipient = recipient.toLowerCase(); - return recipient; - } - })); + Set<String> recipients = recipientAddresses.stream().map(address -> { + String recipient = address.toString(); + // some recipient are like "toto tutu<toto.tutu73@gmail.com>" + // the regex is to extract email address from it + recipient = recipient.replaceAll("\\s", "").replaceFirst("^.*<(.*)>$", "$1"); + recipient = recipient.toLowerCase(); + return recipient; + }).collect(Collectors.toSet()); // try to find the real recipient, in case it is in the bcc Enumeration allHeaders = message.getAllHeaders(); diff --git a/faxtomail-ui-web/src/main/java/com/franciaflex/faxtomail/web/json/TopiaEntityAdapter.java b/faxtomail-ui-web/src/main/java/com/franciaflex/faxtomail/web/json/TopiaEntityAdapter.java index 9948b29..3685e8c 100644 --- a/faxtomail-ui-web/src/main/java/com/franciaflex/faxtomail/web/json/TopiaEntityAdapter.java +++ b/faxtomail-ui-web/src/main/java/com/franciaflex/faxtomail/web/json/TopiaEntityAdapter.java @@ -49,13 +49,11 @@ public class TopiaEntityAdapter implements JsonSerializer<TopiaEntity>, JsonDese @Override public TopiaEntity deserialize(JsonElement jsonElement, Type type, JsonDeserializationContext jsonDeserializationContext) throws JsonParseException { - TopiaEntity result = jsonDeserializationContext.deserialize(jsonElement, implementationClass); - return result; + return jsonDeserializationContext.deserialize(jsonElement, implementationClass); } @Override public JsonElement serialize(TopiaEntity object, Type type, JsonSerializationContext jsonSerializationContext) { - JsonElement result = jsonSerializationContext.serialize(object, object.getClass()); - return result; + return jsonSerializationContext.serialize(object, object.getClass()); } } diff --git a/pom.xml b/pom.xml index 08579fd..102596c 100644 --- a/pom.xml +++ b/pom.xml @@ -95,13 +95,13 @@ <ciViewId>FaxToMail</ciViewId> <!-- libraries version --> - <nuitonI18nVersion>3.4.1</nuitonI18nVersion> - <nuitonConfigVersion>3.0-rc-3</nuitonConfigVersion> - <nuitonCsvVersion>3.0-rc-4</nuitonCsvVersion> + <nuitonI18nVersion>3.6.2</nuitonI18nVersion> + <nuitonConfigVersion>3.1.1</nuitonConfigVersion> + <nuitonCsvVersion>3.0-rc-6</nuitonCsvVersion> <nuitonDecoratorVersion>3.0</nuitonDecoratorVersion> - <nuitonUtilsVersion>3.0-rc-11</nuitonUtilsVersion> - <nuitonValidatorVersion>3.0-rc-2</nuitonValidatorVersion> - <nuitonWebVersion>1.17</nuitonWebVersion> + <nuitonUtilsVersion>3.0-rc-16</nuitonUtilsVersion> + <nuitonValidatorVersion>3.0.1</nuitonValidatorVersion> + <nuitonWebVersion>1.18</nuitonWebVersion> <eugeneVersion>2.13</eugeneVersion> <topiaVersion>3.0-beta-13</topiaVersion> @@ -109,7 +109,7 @@ <h2Version>1.3.176</h2Version> <guavaVersion>18.0</guavaVersion> - <jaxxVersion>2.28.2</jaxxVersion> + <jaxxVersion>2.38</jaxxVersion> <!-- do not upgrade to 1.6.5-1 --> <swingXVersion>1.6.4</swingXVersion> <xworkVersion>2.3.16.3</xworkVersion> @@ -137,8 +137,8 @@ <license.licenseName>gpl_v3</license.licenseName> <!-- Java version --> - <javaVersion>1.7</javaVersion> - <signatureArtifactId>java17</signatureArtifactId> + <javaVersion>1.8</javaVersion> + <signatureArtifactId>java18</signatureArtifactId> <signatureVersion>1.0</signatureVersion> <!-- issues status to include in changelog --> -- To stop receiving notification emails like this one, please contact codelutin.com SCM administrator <admin+scm@codelutin.com>.
participants (1)
-
codelutin.com scm