This is an automated email from the ASF dual-hosted git repository. solomax pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/openmeetings.git
commit 6333a7728f6c10f997821fd56faeb595b54cfa3e Author: Maxim Solodovnik <solomax...@gmail.com> AuthorDate: Sun Nov 8 13:04:57 2020 +0700 [OPENMEETINGS-2478] code is improved by using java11 Map --- .../openmeetings/core/remote/KurentoHandler.java | 9 +- .../db/bind/adapter/OauthMapAdapter.java | 2 +- .../openmeetings/db/dto/user/TestOAuthUser.java | 8 +- .../apache/openmeetings/backup/BackupImport.java | 145 +++++++++++---------- .../caldav/handler/AbstractCalendarHandler.java | 9 +- .../openmeetings/util/process/ProcessHelper.java | 4 +- .../openmeetings/web/app/LabelResourceLoader.java | 14 +- 7 files changed, 90 insertions(+), 101 deletions(-) diff --git a/openmeetings-core/src/main/java/org/apache/openmeetings/core/remote/KurentoHandler.java b/openmeetings-core/src/main/java/org/apache/openmeetings/core/remote/KurentoHandler.java index ce9b19c..a0cd23b 100644 --- a/openmeetings-core/src/main/java/org/apache/openmeetings/core/remote/KurentoHandler.java +++ b/openmeetings-core/src/main/java/org/apache/openmeetings/core/remote/KurentoHandler.java @@ -25,7 +25,6 @@ import java.security.InvalidKeyException; import java.security.NoSuchAlgorithmException; import java.util.Base64; import java.util.Collection; -import java.util.HashMap; import java.util.HashSet; import java.util.List; import java.util.Map; @@ -35,6 +34,7 @@ import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.Executors; import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.atomic.AtomicBoolean; +import java.util.stream.Collectors; import javax.annotation.PostConstruct; import javax.annotation.PreDestroy; @@ -225,11 +225,8 @@ public class KurentoHandler { } private static Map<String, String> tagsAsMap(MediaObject pipe) { - Map<String, String> map = new HashMap<>(); - for (Tag t : pipe.getTags()) { - map.put(t.getKey(), t.getValue()); - } - return map; + return pipe.getTags().stream() + .collect(Collectors.toMap(Tag::getKey, Tag::getValue)); } Transaction beginTransaction() { diff --git a/openmeetings-db/src/main/java/org/apache/openmeetings/db/bind/adapter/OauthMapAdapter.java b/openmeetings-db/src/main/java/org/apache/openmeetings/db/bind/adapter/OauthMapAdapter.java index e009901..9807541 100644 --- a/openmeetings-db/src/main/java/org/apache/openmeetings/db/bind/adapter/OauthMapAdapter.java +++ b/openmeetings-db/src/main/java/org/apache/openmeetings/db/bind/adapter/OauthMapAdapter.java @@ -111,6 +111,6 @@ public class OauthMapAdapter extends XmlAdapter<Object, Map<String, String>> { if ("mapping".equals(el.getLocalName())) { return getMap(el.getChildNodes()); } - return new HashMap<>(); + return Map.of(); } } diff --git a/openmeetings-db/src/test/java/org/apache/openmeetings/db/dto/user/TestOAuthUser.java b/openmeetings-db/src/test/java/org/apache/openmeetings/db/dto/user/TestOAuthUser.java index 5fe3d94..3a5bdb0 100644 --- a/openmeetings-db/src/test/java/org/apache/openmeetings/db/dto/user/TestOAuthUser.java +++ b/openmeetings-db/src/test/java/org/apache/openmeetings/db/dto/user/TestOAuthUser.java @@ -26,7 +26,6 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNull; import static org.junit.jupiter.api.Assertions.assertTrue; -import java.util.HashMap; import java.util.Map; import org.apache.openmeetings.db.entity.server.OAuthServer; @@ -141,10 +140,9 @@ class TestOAuthUser { @Test void map() { - Map<String, String> umap = new HashMap<>(); - umap.put("login", "abc"); - umap.put("email", "abc@local"); - OAuthUser user = new OAuthUser(umap); + OAuthUser user = new OAuthUser(Map.of( + "login", "abc" + , "email", "abc@local")); assertEquals("abc", user.getLogin(), "Login should be correct"); assertEquals("abc@local", user.getEmail(), "Email should be correct"); assertNull(user.getUserData().get(PARAM_FNAME), "First name should be empty"); diff --git a/openmeetings-install/src/main/java/org/apache/openmeetings/backup/BackupImport.java b/openmeetings-install/src/main/java/org/apache/openmeetings/backup/BackupImport.java index 66836d0..3bf6aa4 100644 --- a/openmeetings-install/src/main/java/org/apache/openmeetings/backup/BackupImport.java +++ b/openmeetings-install/src/main/java/org/apache/openmeetings/backup/BackupImport.java @@ -18,6 +18,7 @@ */ package org.apache.openmeetings.backup; +import static java.util.Map.entry; import static java.util.UUID.randomUUID; import static org.apache.openmeetings.db.bind.Constants.APPOINTMENT_LIST_NODE; import static org.apache.openmeetings.db.bind.Constants.APPOINTMENT_NODE; @@ -237,79 +238,79 @@ import org.springframework.stereotype.Component; @Component public class BackupImport { private static final Logger log = LoggerFactory.getLogger(BackupImport.class); - private static final Map<String, String> outdatedConfigKeys = new HashMap<>(); - private static final Map<String, Configuration.Type> configTypes = new HashMap<>(); + private static final Map<String, String> outdatedConfigKeys = Map.ofEntries( + entry("crypt_ClassName", CONFIG_CRYPT) + , entry("system_email_addr", CONFIG_SMTP_SYSTEM_EMAIL) + , entry("smtp_server", CONFIG_SMTP_SERVER) + , entry("smtp_port", CONFIG_SMTP_PORT) + , entry("email_username", CONFIG_SMTP_USER) + , entry("email_userpass", CONFIG_SMTP_PASS) + , entry("default_lang_id", CONFIG_DEFAULT_LANG) + , entry("allow_frontend_register", CONFIG_REGISTER_FRONTEND) + , entry("max_upload_size", CONFIG_MAX_UPLOAD_SIZE) + , entry("rss_feed1", CONFIG_DASHBOARD_RSS_FEED1) + , entry("rss_feed2", CONFIG_DASHBOARD_RSS_FEED2) + , entry("oauth2.ignore_bad_ssl", CONFIG_IGNORE_BAD_SSL) + , entry("default.quality.screensharing", CONFIG_SCREENSHARING_QUALITY) + , entry("default.fps.screensharing", CONFIG_SCREENSHARING_FPS) + , entry("ldap_default_id", CONFIG_DEFAULT_LDAP_ID) + , entry("default_group_id", CONFIG_DEFAULT_GROUP_ID) + , entry("imagemagick_path", CONFIG_PATH_IMAGEMAGIC) + , entry("sox_path", CONFIG_PATH_SOX) + , entry("ffmpeg_path", CONFIG_PATH_FFMPEG) + , entry("office.path", CONFIG_PATH_OFFICE) + , entry("red5sip.enable", CONFIG_SIP_ENABLED) + , entry("red5sip.room_prefix", CONFIG_SIP_ROOM_PREFIX) + , entry("red5sip.exten_context", CONFIG_SIP_EXTEN_CONTEXT) + , entry("sendEmailAtRegister", CONFIG_EMAIL_AT_REGISTER) + , entry("sendEmailWithVerficationCode", CONFIG_EMAIL_VERIFICATION) + , entry("swftools_zoom", CONFIG_DOCUMENT_DPI) + , entry("swftools_jpegquality", CONFIG_DOCUMENT_QUALITY) + , entry("sms.subject", CONFIG_REMINDER_MESSAGE) + , entry("exclusive.audio.keycode", CONFIG_KEYCODE_MUTE_OTHERS) + , entry("header.csp.frame.options", CONFIG_CSP_FRAME) + ); + private static final Map<String, Configuration.Type> configTypes = Map.ofEntries( + entry(CONFIG_REGISTER_FRONTEND, Configuration.Type.BOOL) + , entry(CONFIG_REGISTER_SOAP, Configuration.Type.BOOL) + , entry(CONFIG_REGISTER_OAUTH, Configuration.Type.BOOL) + , entry(CONFIG_SMTP_TLS, Configuration.Type.BOOL) + , entry(CONFIG_EMAIL_AT_REGISTER, Configuration.Type.BOOL) + , entry(CONFIG_EMAIL_VERIFICATION, Configuration.Type.BOOL) + , entry(CONFIG_SIP_ENABLED, Configuration.Type.BOOL) + , entry(CONFIG_SCREENSHARING_FPS_SHOW, Configuration.Type.BOOL) + , entry(CONFIG_SCREENSHARING_ALLOW_REMOTE, Configuration.Type.BOOL) + , entry(CONFIG_DASHBOARD_SHOW_MYROOMS, Configuration.Type.BOOL) + , entry(CONFIG_DASHBOARD_SHOW_CHAT, Configuration.Type.BOOL) + , entry(CONFIG_DASHBOARD_SHOW_RSS, Configuration.Type.BOOL) + , entry(CONFIG_REPLY_TO_ORGANIZER, Configuration.Type.BOOL) + , entry(CONFIG_IGNORE_BAD_SSL, Configuration.Type.BOOL) + , entry(CONFIG_MYROOMS_ENABLED, Configuration.Type.BOOL) + , entry(CONFIG_DEFAULT_GROUP_ID, Configuration.Type.NUMBER) + , entry(CONFIG_SMTP_PORT, Configuration.Type.NUMBER) + , entry(CONFIG_SMTP_TIMEOUT_CON, Configuration.Type.NUMBER) + , entry(CONFIG_SMTP_TIMEOUT, Configuration.Type.NUMBER) + , entry(CONFIG_DEFAULT_LANG, Configuration.Type.NUMBER) + , entry(CONFIG_DOCUMENT_DPI, Configuration.Type.NUMBER) + , entry(CONFIG_DOCUMENT_QUALITY, Configuration.Type.NUMBER) + , entry(CONFIG_SCREENSHARING_QUALITY, Configuration.Type.NUMBER) + , entry(CONFIG_SCREENSHARING_FPS, Configuration.Type.NUMBER) + , entry(CONFIG_MAX_UPLOAD_SIZE, Configuration.Type.NUMBER) + , entry(CONFIG_APPOINTMENT_REMINDER_MINUTES, Configuration.Type.NUMBER) + , entry(CONFIG_LOGIN_MIN_LENGTH, Configuration.Type.NUMBER) + , entry(CONFIG_PASS_MIN_LENGTH, Configuration.Type.NUMBER) + , entry(CONFIG_CALENDAR_ROOM_CAPACITY, Configuration.Type.NUMBER) + , entry(CONFIG_KEYCODE_ARRANGE, Configuration.Type.HOTKEY) + , entry(CONFIG_KEYCODE_MUTE_OTHERS, Configuration.Type.HOTKEY) + , entry(CONFIG_KEYCODE_MUTE, Configuration.Type.HOTKEY) + , entry(CONFIG_DEFAULT_LDAP_ID, Configuration.Type.NUMBER) + , entry(CONFIG_CAM_FPS, Configuration.Type.NUMBER) + , entry(CONFIG_MIC_RATE, Configuration.Type.NUMBER) + , entry(CONFIG_MIC_ECHO, Configuration.Type.BOOL) + , entry(CONFIG_MIC_NOISE, Configuration.Type.BOOL) + , entry(CONFIG_EXT_PROCESS_TTL, Configuration.Type.NUMBER) + ); private static final Pattern UUID_PATTERN = Pattern.compile("^[\\da-f]{8}(?:-[\\da-f]{4}){3}-[\\da-f]{12}$"); - static { - outdatedConfigKeys.put("crypt_ClassName", CONFIG_CRYPT); - outdatedConfigKeys.put("system_email_addr", CONFIG_SMTP_SYSTEM_EMAIL); - outdatedConfigKeys.put("smtp_server", CONFIG_SMTP_SERVER); - outdatedConfigKeys.put("smtp_port", CONFIG_SMTP_PORT); - outdatedConfigKeys.put("email_username", CONFIG_SMTP_USER); - outdatedConfigKeys.put("email_userpass", CONFIG_SMTP_PASS); - outdatedConfigKeys.put("default_lang_id", CONFIG_DEFAULT_LANG); - outdatedConfigKeys.put("allow_frontend_register", CONFIG_REGISTER_FRONTEND); - outdatedConfigKeys.put("max_upload_size", CONFIG_MAX_UPLOAD_SIZE); - outdatedConfigKeys.put("rss_feed1", CONFIG_DASHBOARD_RSS_FEED1); - outdatedConfigKeys.put("rss_feed2", CONFIG_DASHBOARD_RSS_FEED2); - outdatedConfigKeys.put("oauth2.ignore_bad_ssl", CONFIG_IGNORE_BAD_SSL); - outdatedConfigKeys.put("default.quality.screensharing", CONFIG_SCREENSHARING_QUALITY); - outdatedConfigKeys.put("default.fps.screensharing", CONFIG_SCREENSHARING_FPS); - outdatedConfigKeys.put("ldap_default_id", CONFIG_DEFAULT_LDAP_ID); - outdatedConfigKeys.put("default_group_id", CONFIG_DEFAULT_GROUP_ID); - outdatedConfigKeys.put("imagemagick_path", CONFIG_PATH_IMAGEMAGIC); - outdatedConfigKeys.put("sox_path", CONFIG_PATH_SOX); - outdatedConfigKeys.put("ffmpeg_path", CONFIG_PATH_FFMPEG); - outdatedConfigKeys.put("office.path", CONFIG_PATH_OFFICE); - outdatedConfigKeys.put("red5sip.enable", CONFIG_SIP_ENABLED); - outdatedConfigKeys.put("red5sip.room_prefix", CONFIG_SIP_ROOM_PREFIX); - outdatedConfigKeys.put("red5sip.exten_context", CONFIG_SIP_EXTEN_CONTEXT); - outdatedConfigKeys.put("sendEmailAtRegister", CONFIG_EMAIL_AT_REGISTER); - outdatedConfigKeys.put("sendEmailWithVerficationCode", CONFIG_EMAIL_VERIFICATION); - outdatedConfigKeys.put("swftools_zoom", CONFIG_DOCUMENT_DPI); - outdatedConfigKeys.put("swftools_jpegquality", CONFIG_DOCUMENT_QUALITY); - outdatedConfigKeys.put("sms.subject", CONFIG_REMINDER_MESSAGE); - outdatedConfigKeys.put("exclusive.audio.keycode", CONFIG_KEYCODE_MUTE_OTHERS); - outdatedConfigKeys.put("header.csp.frame.options", CONFIG_CSP_FRAME); - configTypes.put(CONFIG_REGISTER_FRONTEND, Configuration.Type.BOOL); - configTypes.put(CONFIG_REGISTER_SOAP, Configuration.Type.BOOL); - configTypes.put(CONFIG_REGISTER_OAUTH, Configuration.Type.BOOL); - configTypes.put(CONFIG_SMTP_TLS, Configuration.Type.BOOL); - configTypes.put(CONFIG_EMAIL_AT_REGISTER, Configuration.Type.BOOL); - configTypes.put(CONFIG_EMAIL_VERIFICATION, Configuration.Type.BOOL); - configTypes.put(CONFIG_SIP_ENABLED, Configuration.Type.BOOL); - configTypes.put(CONFIG_SCREENSHARING_FPS_SHOW, Configuration.Type.BOOL); - configTypes.put(CONFIG_SCREENSHARING_ALLOW_REMOTE, Configuration.Type.BOOL); - configTypes.put(CONFIG_DASHBOARD_SHOW_MYROOMS, Configuration.Type.BOOL); - configTypes.put(CONFIG_DASHBOARD_SHOW_CHAT, Configuration.Type.BOOL); - configTypes.put(CONFIG_DASHBOARD_SHOW_RSS, Configuration.Type.BOOL); - configTypes.put(CONFIG_REPLY_TO_ORGANIZER, Configuration.Type.BOOL); - configTypes.put(CONFIG_IGNORE_BAD_SSL, Configuration.Type.BOOL); - configTypes.put(CONFIG_MYROOMS_ENABLED, Configuration.Type.BOOL); - configTypes.put(CONFIG_DEFAULT_GROUP_ID, Configuration.Type.NUMBER); - configTypes.put(CONFIG_SMTP_PORT, Configuration.Type.NUMBER); - configTypes.put(CONFIG_SMTP_TIMEOUT_CON, Configuration.Type.NUMBER); - configTypes.put(CONFIG_SMTP_TIMEOUT, Configuration.Type.NUMBER); - configTypes.put(CONFIG_DEFAULT_LANG, Configuration.Type.NUMBER); - configTypes.put(CONFIG_DOCUMENT_DPI, Configuration.Type.NUMBER); - configTypes.put(CONFIG_DOCUMENT_QUALITY, Configuration.Type.NUMBER); - configTypes.put(CONFIG_SCREENSHARING_QUALITY, Configuration.Type.NUMBER); - configTypes.put(CONFIG_SCREENSHARING_FPS, Configuration.Type.NUMBER); - configTypes.put(CONFIG_MAX_UPLOAD_SIZE, Configuration.Type.NUMBER); - configTypes.put(CONFIG_APPOINTMENT_REMINDER_MINUTES, Configuration.Type.NUMBER); - configTypes.put(CONFIG_LOGIN_MIN_LENGTH, Configuration.Type.NUMBER); - configTypes.put(CONFIG_PASS_MIN_LENGTH, Configuration.Type.NUMBER); - configTypes.put(CONFIG_CALENDAR_ROOM_CAPACITY, Configuration.Type.NUMBER); - configTypes.put(CONFIG_KEYCODE_ARRANGE, Configuration.Type.HOTKEY); - configTypes.put(CONFIG_KEYCODE_MUTE_OTHERS, Configuration.Type.HOTKEY); - configTypes.put(CONFIG_KEYCODE_MUTE, Configuration.Type.HOTKEY); - configTypes.put(CONFIG_DEFAULT_LDAP_ID, Configuration.Type.NUMBER); - configTypes.put(CONFIG_CAM_FPS, Configuration.Type.NUMBER); - configTypes.put(CONFIG_MIC_RATE, Configuration.Type.NUMBER); - configTypes.put(CONFIG_MIC_ECHO, Configuration.Type.BOOL); - configTypes.put(CONFIG_MIC_NOISE, Configuration.Type.BOOL); - configTypes.put(CONFIG_EXT_PROCESS_TTL, Configuration.Type.NUMBER); - } @Autowired private AppointmentDao appointmentDao; diff --git a/openmeetings-service/src/main/java/org/apache/openmeetings/service/calendar/caldav/handler/AbstractCalendarHandler.java b/openmeetings-service/src/main/java/org/apache/openmeetings/service/calendar/caldav/handler/AbstractCalendarHandler.java index 6f64b87..65a5b6d 100644 --- a/openmeetings-service/src/main/java/org/apache/openmeetings/service/calendar/caldav/handler/AbstractCalendarHandler.java +++ b/openmeetings-service/src/main/java/org/apache/openmeetings/service/calendar/caldav/handler/AbstractCalendarHandler.java @@ -22,6 +22,8 @@ import java.io.IOException; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.function.Function; +import java.util.stream.Collectors; import org.apache.http.client.HttpClient; import org.apache.http.client.methods.HttpRequestBase; @@ -66,11 +68,8 @@ public abstract class AbstractCalendarHandler implements CalendarHandler { * @return Map of Hrefs to Appointments */ static Map<String, Appointment> listToMap(List<Appointment> appointments) { - Map<String, Appointment> map = new HashMap<>(); - for(Appointment a : appointments) { - map.put(a.getHref(), a); - } - return map; + return appointments.stream() + .collect(Collectors.toMap(Appointment::getHref, Function.identity())); } /** diff --git a/openmeetings-util/src/main/java/org/apache/openmeetings/util/process/ProcessHelper.java b/openmeetings-util/src/main/java/org/apache/openmeetings/util/process/ProcessHelper.java index b4db748..262b60d 100644 --- a/openmeetings-util/src/main/java/org/apache/openmeetings/util/process/ProcessHelper.java +++ b/openmeetings-util/src/main/java/org/apache/openmeetings/util/process/ProcessHelper.java @@ -26,7 +26,6 @@ import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; -import java.util.HashMap; import java.util.Map; import java.util.concurrent.TimeUnit; @@ -98,8 +97,7 @@ public class ProcessHelper { } public static ProcessResult executeScript(String process, String[] argv, boolean optional) { - Map<String, String> env = new HashMap<>(); - return executeScript(process, argv, env, optional); + return executeScript(process, argv, Map.of(), optional); } private static ProcessResult executeScript(String process, String[] argv, Map<? extends String, ? extends String> env, boolean optional) { diff --git a/openmeetings-web/src/main/java/org/apache/openmeetings/web/app/LabelResourceLoader.java b/openmeetings-web/src/main/java/org/apache/openmeetings/web/app/LabelResourceLoader.java index aa441d9..1b4c6af 100644 --- a/openmeetings-web/src/main/java/org/apache/openmeetings/web/app/LabelResourceLoader.java +++ b/openmeetings-web/src/main/java/org/apache/openmeetings/web/app/LabelResourceLoader.java @@ -18,7 +18,6 @@ */ package org.apache.openmeetings.web.app; -import java.util.HashMap; import java.util.Locale; import java.util.Map; @@ -32,14 +31,11 @@ import org.apache.wicket.resource.loader.IStringResourceLoader; * */ public class LabelResourceLoader implements IStringResourceLoader { - private static final Map<String, String> STRING_LABEL_MAPPING = new HashMap<>(); - - static { - STRING_LABEL_MAPPING.put("PagingNavigator.first", "goto.first"); - STRING_LABEL_MAPPING.put("PagingNavigator.previous", "goto.prev"); - STRING_LABEL_MAPPING.put("PagingNavigator.next", "goto.next"); - STRING_LABEL_MAPPING.put("PagingNavigator.last", "goto.last"); - } + private static final Map<String, String> STRING_LABEL_MAPPING = Map.of( + "PagingNavigator.first", "goto.first" + , "PagingNavigator.previous", "goto.prev" + , "PagingNavigator.next", "goto.next" + , "PagingNavigator.last", "goto.last"); @Override public String loadStringResource(Class<?> clazz, String key, Locale locale,