Subversion Repositories SmartDukaan

Rev

Rev 34568 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
21543 ashik.ali 1
package com.spice.profitmandi.common.util;
2
 
26066 amit.gupta 3
import com.google.gson.Gson;
22215 ashik.ali 4
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
26079 amit.gupta 5
import com.spice.profitmandi.common.web.client.RestClient;
21894 ashik.ali 6
import com.spice.profitmandi.thrift.clients.InventoryClient;
23509 amit.gupta 7
import com.spice.profitmandi.thrift.clients.WarehouseClient;
21894 ashik.ali 8
import in.shop2020.model.v1.inventory.InventoryService;
9
import in.shop2020.model.v1.inventory.StateInfo;
23509 amit.gupta 10
import in.shop2020.model.v1.inventory.Warehouse;
23884 amit.gupta 11
import in.shop2020.model.v1.order.OrderStatusGroups;
21894 ashik.ali 12
import in.shop2020.model.v1.order.RechargeOrderStatus;
13
import in.shop2020.model.v1.order.RechargePlan;
23509 amit.gupta 14
import in.shop2020.warehouse.InventoryItem;
15
import in.shop2020.warehouse.WarehouseService;
30122 amit.gupta 16
import org.apache.commons.io.FileUtils;
17
import org.apache.commons.lang3.StringEscapeUtils;
18
import org.apache.logging.log4j.LogManager;
19
import org.apache.logging.log4j.Logger;
20
import org.springframework.core.io.InputStreamSource;
21
import org.springframework.mail.javamail.JavaMailSender;
22
import org.springframework.mail.javamail.MimeMessageHelper;
21543 ashik.ali 23
 
30122 amit.gupta 24
import javax.mail.Multipart;
25
import javax.mail.internet.InternetAddress;
26
import javax.mail.internet.MimeBodyPart;
27
import javax.mail.internet.MimeMessage;
28
import javax.mail.internet.MimeMultipart;
29
import java.io.File;
30
import java.io.IOException;
31
import java.io.Serializable;
32955 amit.gupta 32
import java.time.*;
30122 amit.gupta 33
import java.util.*;
34
import java.util.concurrent.ConcurrentHashMap;
35
import java.util.function.Function;
36
import java.util.function.Predicate;
37
import java.util.regex.Matcher;
38
import java.util.regex.Pattern;
39
 
21543 ashik.ali 40
public class Utils {
31177 tejbeer 41
 
35102 amit 42
    public static final float FLOAT_EPSILON = 0.001f;
21986 kshitij.so 43
 
35102 amit 44
    public static final double DOUBLE_EPSILON = 0.001d;
31177 tejbeer 45
 
33045 amit.gupta 46
 
35102 amit 47
    public static String[] getAlphaNumericParts(String alphaNumericString) {
48
        String[] parts = alphaNumericString.split("(?<=\\D)(?=\\d)");
49
        return parts;
50
    }
33045 amit.gupta 51
 
35102 amit 52
    private static final Logger logger = LogManager.getLogger(Utils.class);
53
    public static final String EXPORT_ENTITIES_PATH = getExportPath();
54
    public static final String PRODUCT_PROPERTIES_SNIPPET = "ProductPropertiesSnippet.html";
55
    public static final String DOCUMENT_STORE = "/profitmandi/documents/";
56
    private Gson gson = new Gson();
57
    private static final Map<Integer, String> helpMap = new HashMap<>(6);
58
    private static final Map<Integer, String> dthIdAliasMap = new HashMap<>(7);
59
    private static Map<Long, List<RechargePlan>> operatorPlanMap = new HashMap<>(20);
60
    private static Map<Long, String> mobileProvidersMap;
61
    private static Map<Long, String> dthProvidersMap;
62
    private static Map<Long, String> allProviders;
63
    public static Map<RechargeOrderStatus, String> rechargeStatusMap = new HashMap<>();
64
    public static OrderStatusGroups ORDER_STATUS_GROUPS = new OrderStatusGroups();
65
    public static final String SYSTEM_PARTNER = "testpxps@gmail.com";
66
    public static final int SYSTEM_PARTNER_ID = 175120474;
67
    private static final RestClient rc = new RestClient();
68
    private static final String regex = "^[a-zA-Z0-9_!#$%&'*+/=?`{|}~^.-]+@[a-zA-Z0-9.-]+$";
69
    public static final LocalTime MAX_TIME = LocalTime.of(23, 59, 59);
70
    // Compile regular expression to get the pattern
71
    private static final Pattern pattern = Pattern.compile(regex);
24440 amit.gupta 72
 
35102 amit 73
    public static boolean validateEmail(String email) {
74
        if (email == null) {
75
            return false;
76
        }
77
        Matcher matcher = pattern.matcher(email);
78
        return matcher.matches();
79
    }
31177 tejbeer 80
 
35102 amit 81
    @SuppressWarnings("serial")
82
    public static final Map<String, String> MIME_TYPE = Collections.unmodifiableMap(new HashMap<String, String>() {
83
        {
84
            put("image/png", "png");
85
            put("image/jpeg", "jpeg");
86
            put("image/pjpeg", "jpeg");
87
            put("application/pdf", "pdf");
88
            put("application/msword", "doc");
89
            put("application/vnd.openxmlformats-officedocument.wordprocessingml.document", "docx");
90
            put("application/vnd.ms-excel", "xls");
91
            put("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", "xlsx");
92
        }
93
    });
21543 ashik.ali 94
 
35102 amit 95
    private static String getExportPath() {
96
        String exportPath = "/var/lib/tomcat7/webapps/export/html/entities/";
97
        /*
98
         * String exportPath = null;
99
         *
100
         * try { ConfigClient client = ConfigClient.getClient(); exportPath =
101
         * client.get("export_entities_path"); } catch (Exception ce) {
102
         * logger.error("Unable to read export path from the config client: ", ce);
103
         * logger.warn("Setting the default export path"); exportPath =
104
         * "/var/lib/tomcat7/webapps/export/html/entities/"; }
105
         */
106
        return exportPath;
107
    }
21986 kshitij.so 108
 
35102 amit 109
    public static LocalDateTime toLocalDateTime(long epochTimeInMillis) {
110
        return LocalDateTime.ofInstant(Instant.ofEpochMilli(epochTimeInMillis), ZoneId.systemDefault());
111
    }
32724 amit.gupta 112
 
35102 amit 113
    public static String getRechargeDisplayStatus(RechargeOrderStatus status) {
114
        if (status == null) {
115
            status = RechargeOrderStatus.INIT;
116
        }
117
        String displayStatus = (String) rechargeStatusMap.get(status);
118
        if (displayStatus == null) {
119
            return "";
120
        }
121
        return displayStatus;
122
    }
21543 ashik.ali 123
 
35102 amit 124
    public static boolean copyDocument(String documentPath) {
125
        File source = new File(documentPath);
126
        File dest = new File(DOCUMENT_STORE + source.getName());
127
        try {
128
            FileUtils.copyFile(source, dest);
129
        } catch (IOException e) {
130
            e.printStackTrace();
131
            return false;
132
        }
133
        return true;
134
    }
21543 ashik.ali 135
 
35102 amit 136
    public static Map<Long, String> getMobileProvidersMap() {
137
        return mobileProvidersMap;
138
    }
21543 ashik.ali 139
 
35102 amit 140
    public static Map<Long, String> getDthProvidersMap() {
141
        return dthProvidersMap;
142
    }
21986 kshitij.so 143
 
35102 amit 144
    public static Map<Long, String> getAllProviders() {
145
        return allProviders;
146
    }
21986 kshitij.so 147
 
35102 amit 148
    public static String getProvider(long operatorId) {
149
        return allProviders.get(operatorId);
150
    }
21543 ashik.ali 151
 
35102 amit 152
    public static void sendSms(String text, String mobileNumber) throws Exception {
153
        Map<String, String> paramsMap = new HashMap<>();
154
        paramsMap.put("username", "SmartDukaanT");
155
        paramsMap.put("password", "Smart@91");
156
        paramsMap.put("senderID", "SMTDKN");
157
        paramsMap.put("message", text);
158
        paramsMap.put("mobile", mobileNumber);
159
        paramsMap.put("messageType", "Text");
160
        // rc.getResponse(SMS_GATEWAY, paramsMap, null);
161
    }
24440 amit.gupta 162
 
35102 amit 163
    public static void sendMailWithAttachments(JavaMailSender mailSender, String emailTo, String[] cc, String subject,
164
                                               String body, List<File> attachments) throws Exception {
165
        MimeMessage message = mailSender.createMimeMessage();
166
        MimeMessageHelper helper = new MimeMessageHelper(message, true);
167
        helper.setSubject(subject);
168
        helper.setText(body);
169
        if (cc != null) {
170
            helper.setCc(cc);
171
        }
172
        helper.setTo(emailTo);
173
        // helper.setTo("amit.gupta@smartdukaan.com");
174
        InternetAddress senderAddress = new InternetAddress("noreply@smartdukaan.com", "SmartDukaan Care");
175
        helper.setFrom(senderAddress);
176
        if (attachments != null) {
177
            for (File file : attachments) {
178
                helper.addAttachment(file.getName(), file);
179
            }
180
        }
181
        mailSender.send(message);
182
    }
25764 amit.gupta 183
 
35102 amit 184
    public static class Attachment {
185
        public Attachment(String fileName, InputStreamSource inputStreamSource) {
186
            this.fileName = fileName;
187
            this.inputStreamSource = inputStreamSource;
188
        }
25764 amit.gupta 189
 
35102 amit 190
        private String fileName;
191
        private InputStreamSource inputStreamSource;
25764 amit.gupta 192
 
35102 amit 193
        public String getFileName() {
194
            return fileName;
195
        }
25764 amit.gupta 196
 
35102 amit 197
        public void setFileName(String fileName) {
198
            this.fileName = fileName;
199
        }
25764 amit.gupta 200
 
35102 amit 201
        public InputStreamSource getInputStreamSource() {
202
            return inputStreamSource;
203
        }
25764 amit.gupta 204
 
35102 amit 205
        public void setInputStreamSource(InputStreamSource inputStreamSource) {
206
            this.inputStreamSource = inputStreamSource;
207
        }
25764 amit.gupta 208
 
35102 amit 209
        @Override
210
        public String toString() {
211
            return "Attachment [fileName=" + fileName + ", inputStreamSource=" + inputStreamSource + "]";
212
        }
213
    }
25764 amit.gupta 214
 
35102 amit 215
    public static void sendMailWithAttachment(JavaMailSender mailSender, String[] emailTo, String[] cc, String subject,
216
                                              String body, String fileName, InputStreamSource inputStreamSource) throws Exception {
217
        MimeMessage message = mailSender.createMimeMessage();
218
        MimeMessageHelper helper = new MimeMessageHelper(message, true);
219
        helper.setSubject(subject);
220
        helper.setText(body);
221
        if (cc != null) {
222
            helper.setCc(cc);
223
        }
224
        helper.setTo(emailTo);
225
        helper.addAttachment(fileName, inputStreamSource);
226
        InternetAddress senderAddress = new InternetAddress("noreply@smartdukaan.com", "SmartDukaan Care");
227
        helper.setFrom(senderAddress);
228
        mailSender.send(message);
229
    }
25764 amit.gupta 230
 
35102 amit 231
    public static void sendMailWithAttachments(JavaMailSender mailSender, String[] emailTo, String[] cc, String[] bcc,
232
                                               String subject, String body, Attachment... attachments) throws Exception {
233
        sendMailWithAttachments(mailSender, emailTo, cc, bcc,
234
                subject, body, false, attachments);
235
    }
25764 amit.gupta 236
 
35102 amit 237
    public static void sendMailWithAttachments(JavaMailSender mailSender, String[] emailTo, String[] cc, String[] bcc,
238
                                               String subject, String body, boolean html, Attachment... attachments) throws Exception {
239
        MimeMessage message = mailSender.createMimeMessage();
240
        MimeMessageHelper helper = new MimeMessageHelper(message, true);
241
        helper.setSubject(subject);
242
        helper.setText(body, html);
243
        if (cc != null) {
244
            helper.setCc(cc);
245
        }
246
        if (bcc != null) {
247
            helper.setBcc(bcc);
248
        }
249
        helper.setTo(emailTo);
250
        for (Attachment attachment : attachments) {
251
            helper.addAttachment(attachment.getFileName(), attachment.getInputStreamSource());
252
        }
253
        InternetAddress senderAddress = new InternetAddress("noreply@smartdukaan.com", "SmartDukaan Care");
254
        helper.setFrom(senderAddress);
255
        mailSender.send(message);
256
    }
24440 amit.gupta 257
 
35102 amit 258
    public static void sendHtmlMailWithAttachments(JavaMailSender mailSender, String[] emailTo, String[] cc,
259
                                                   String subject, String body, Attachment... attachments) throws Exception {
260
        MimeMessage message = mailSender.createMimeMessage();
261
        MimeMessageHelper helper = new MimeMessageHelper(message, true);
262
        helper.setSubject(subject);
263
        helper.setText(body, true);
264
        // helper.setText(body, true);
265
        if (cc != null) {
266
            helper.setCc(cc);
267
        }
268
        helper.setTo(emailTo);
269
        for (Attachment attachment : attachments) {
270
            if (attachment == null)
271
                break;
272
            helper.addAttachment(attachment.getFileName(), attachment.getInputStreamSource());
273
        }
274
        InternetAddress senderAddress = new InternetAddress("noreply@smartdukaan.com", "SmartDukaan Care");
275
        helper.setFrom(senderAddress);
276
        mailSender.send(message);
277
    }
21986 kshitij.so 278
 
35102 amit 279
    public static String[] getOrderStatus(RechargeOrderStatus status) {
280
        if (status == null) {
281
            status = RechargeOrderStatus.INIT;
282
        }
283
        if (status.equals(RechargeOrderStatus.PAYMENT_FAILED) || status.equals(RechargeOrderStatus.PAYMENT_PENDING)) {
284
            return new String[]{"false", "PAYMENT FAILED", "Payment failed at the payment gateway."};
285
        } else if (status.equals(RechargeOrderStatus.PAYMENT_SUCCESSFUL)
286
                || status.equals(RechargeOrderStatus.RECHARGE_UNKNOWN)) {
287
            if (status.equals(RechargeOrderStatus.PAYMENT_SUCCESSFUL)) {
288
                return new String[]{"false", "PAYMENT SUCCESSFUL",
289
                        "Your Payment was successful but due to some internal error with the operator's system we are not sure if the recharge was successful."
290
                                + " We have put your recharge under process."
291
                                + " As soon as we get a confirmation on this transaction, we will notify you."};
292
            } else {
293
                return new String[]{"false", "RECHARGE IN PROCESS",
294
                        "Your Payment is successful.We have put your recharge under process."
295
                                + " Please wait while we check with the operator."};
296
            }
297
        } else if (status.equals(RechargeOrderStatus.RECHARGE_FAILED)
298
                || status.equals(RechargeOrderStatus.RECHARGE_FAILED_REFUNDED)) {
299
            return new String[]{"false", "RECHARGE FAILED",
300
                    "Your Payment was successful but unfortunately the recharge failed.Don't worry your payment is safe with us."
301
                            + " The entire Amount has been refunded to your wallet."};
302
        } else if (status.equals(RechargeOrderStatus.RECHARGE_SUCCESSFUL)) {
303
            return new String[]{"false", "SUCCESS", "Congratulations! Your device is successfully recharged."};
304
        } else if (status.equals(RechargeOrderStatus.PARTIALLY_REFUNDED)
305
                || status.equals(RechargeOrderStatus.REFUNDED)) {
306
            return new String[]{"false", "PAYMENT REFUNDED",
307
                    "The payment associated with this recharge order has been refunded."};
308
        } else {
309
            return new String[]{"true", "ERROR", "INVALID INPUT"};
310
        }
311
    }
25764 amit.gupta 312
 
35102 amit 313
    public static String getIconUrl(int entityId, String host, int port, String webapp) {
314
        return "";
315
    }
23509 amit.gupta 316
 
24440 amit.gupta 317
 
35102 amit 318
    private static WarehouseService.Client getWarehouseClient() throws Exception {
319
        try {
320
            WarehouseClient client = new WarehouseClient();
321
            WarehouseService.Client warehouseClient = client.getClient();
322
            return warehouseClient;
323
        } catch (Exception e) {
324
            throw e;
325
        }
326
    }
24440 amit.gupta 327
 
35102 amit 328
    public static Map<String, Warehouse> getWarehouseByImeis(List<String> imeis) throws Exception {
329
        List<InventoryItem> inventoryItems = getWarehouseClient().getInventoryItemsBySerailNumbers(imeis);
330
        Map<String, InventoryItem> imeiInventoryItemMap = new HashMap<>();
331
        for (InventoryItem inventoryItem : inventoryItems) {
332
            imeiInventoryItemMap.put(inventoryItem.getSerialNumber(), inventoryItem);
333
        }
334
        Map<Integer, Warehouse> warehouseMap = new HashMap<>();
335
        Map<String, Warehouse> serialNumberWarehouseMap = new HashMap<>();
336
        InventoryClient client = new InventoryClient();
337
        InventoryService.Client inventoryClient = client.getClient();
338
        logger.info("[imeiInventoryItemMap] {}", imeiInventoryItemMap);
339
        for (InventoryItem inventory : new HashSet<>(imeiInventoryItemMap.values())) {
340
            Warehouse phWarehouse = null;
341
            if (warehouseMap.containsKey(inventory.getPhysicalWarehouseId())) {
342
                phWarehouse = warehouseMap.get((int) inventory.getPhysicalWarehouseId());
343
            } else {
344
                phWarehouse = inventoryClient.getWarehouse(inventory.getPhysicalWarehouseId());
345
                warehouseMap.put((int) inventory.getPhysicalWarehouseId(), phWarehouse);
346
            }
347
            serialNumberWarehouseMap.put(inventory.getSerialNumber(), phWarehouse);
24440 amit.gupta 348
 
35102 amit 349
        }
350
        return serialNumberWarehouseMap;
351
    }
24440 amit.gupta 352
 
35102 amit 353
    public static Map<Integer, Warehouse> getWarehousesByIds(Set<Integer> warehouseIds) throws Exception {
354
        InventoryClient client = new InventoryClient();
355
        InventoryService.Client inventoryClient = client.getClient();
356
        Map<Integer, Warehouse> warehouseMap = new HashMap<>();
357
        for (Integer warehouseId : warehouseIds) {
358
            warehouseMap.put(warehouseId, inventoryClient.getWarehouse(warehouseId));
359
        }
360
        return warehouseMap;
361
    }
24440 amit.gupta 362
 
35102 amit 363
    public static String getStateCode(String stateName) throws Exception {
364
        return getStateInfo(stateName).getStateCode();
365
    }
24440 amit.gupta 366
 
35102 amit 367
    public static long getStateId(String stateName) throws ProfitMandiBusinessException {
368
        try {
369
            return getStateInfo(stateName).getId();
370
        } catch (Exception e) {
371
            e.printStackTrace();
372
            throw new ProfitMandiBusinessException("State Name", stateName, "Could not fetch state");
373
        }
374
    }
24440 amit.gupta 375
 
35102 amit 376
    public static StateInfo getStateByStateId(long stateId) throws Exception {
377
        InventoryClient client = new InventoryClient();
378
        InventoryService.Client inventoryClient = client.getClient();
379
        Map<Long, StateInfo> map = inventoryClient.getStateMaster();
380
        return map.get(stateId);
381
    }
24440 amit.gupta 382
 
35102 amit 383
    public static StateInfo getStateInfo(String stateName) throws Exception {
384
        try {
385
            InventoryClient client = new InventoryClient();
386
            InventoryService.Client inventoryClient = client.getClient();
387
            Map<Long, StateInfo> map = inventoryClient.getStateMaster();
388
            List<StateInfo> stateInfos = new ArrayList<>(map.values());
389
            logger.info("State Name: {}", stateName);
390
            for (StateInfo stateInfo : stateInfos) {
391
                logger.info("State Name from service: {}", stateInfo.getStateName());
392
                if (stateName.toUpperCase().equals(stateInfo.getStateName().toUpperCase())) {
393
                    return stateInfo;
394
                }
395
            }
396
            throw new Exception("Not found");
397
        } catch (Exception e) {
398
            e.printStackTrace();
399
            throw e;
400
        }
401
    }
23509 amit.gupta 402
 
35102 amit 403
    public static void main(String[] args) throws Exception {
404
        Utils.sendSms("Hello", "9990381569");
405
    }
27285 tejbeer 406
 
35102 amit 407
    public static void sendEmbeddedHtmlMail(JavaMailSender mailSender, String[] emailTo, String[] cc, String subject,
408
                                            String body, Map<? extends Serializable, File> map) throws Exception {
409
        MimeMessage message = mailSender.createMimeMessage();
410
        MimeMessageHelper helper = new MimeMessageHelper(message, true);
411
        helper.setSubject(subject);
412
        Multipart mp = new MimeMultipart();
27285 tejbeer 413
 
35102 amit 414
        MimeBodyPart messageBodyPart = new MimeBodyPart();
415
        messageBodyPart.setContent(body, "text/html");
416
        mp.addBodyPart(messageBodyPart);
25998 amit.gupta 417
 
35102 amit 418
        // helper.setText(body, true);
419
        if (cc != null) {
420
            helper.setCc(cc);
421
        }
422
        helper.setTo(emailTo);
423
        InternetAddress senderAddress = new InternetAddress("noreply@smartdukaan.com", "SmartDukaan Care");
424
        helper.setFrom(senderAddress);
425
        for (Map.Entry<? extends Serializable, File> entry : map.entrySet()) {
426
            entry.getKey();
427
            entry.getValue();
428
            MimeBodyPart imagePart = new MimeBodyPart();
429
            imagePart.setHeader("Content-ID", entry.getKey() + "");
430
            imagePart.setDisposition(MimeBodyPart.INLINE);
431
            imagePart.attachFile(entry.getValue());
432
            mp.addBodyPart(imagePart);
25764 amit.gupta 433
 
35102 amit 434
        }
435
        message.setContent(mp);
436
        mailSender.send(message);
27285 tejbeer 437
 
35102 amit 438
    }
32199 amit.gupta 439
 
35102 amit 440
    public String html(String string) {
441
        return org.apache.commons.lang.StringEscapeUtils.escapeHtml(String.valueOf(string));
442
    }
25764 amit.gupta 443
 
35102 amit 444
    public String htmlJson(Object object) {
445
        return StringEscapeUtils.escapeHtml4(gson.toJson(object));
446
    }
27285 tejbeer 447
 
35102 amit 448
    public static String getHyphenatedString(String s) {
449
        s = s.trim().replaceAll("\\s+", " ");
450
        s = s.replaceAll("\\s", "-");
451
        return s.toLowerCase();
452
    }
30122 amit.gupta 453
 
35102 amit 454
    public static void sendMailWithAttachments(JavaMailSender mailSender, String[] emailTo, String[] cc, String subject,
455
                                               String body, Attachment... attachments) throws Exception {
456
        MimeMessage message = mailSender.createMimeMessage();
457
        MimeMessageHelper helper = new MimeMessageHelper(message, true);
458
        helper.setSubject(subject);
459
        helper.setText(body, true);
460
        if (cc != null) {
461
            helper.setCc(cc);
462
        }
463
        helper.setTo(emailTo);
464
        for (Attachment attachment : attachments) {
465
            helper.addAttachment(attachment.getFileName(), attachment.getInputStreamSource());
466
        }
467
        InternetAddress senderAddress = new InternetAddress("noreply@smartdukaan.com", "SmartDukaan Care");
468
        helper.setFrom(senderAddress);
469
        mailSender.send(message);
470
    }
33354 amit.gupta 471
 
35102 amit 472
    public static int compareFloat(float f1, float f2) {
473
        if (Math.abs(f1 - f2) < DOUBLE_EPSILON) {
474
            return 0;
475
        }
26534 amit.gupta 476
 
35102 amit 477
        return Float.compare(f1, f2);
478
    }
31177 tejbeer 479
 
35102 amit 480
    public static int compareDouble(double d1, double d2) {
481
        if (Math.abs(d1 - d2) < DOUBLE_EPSILON) {
482
            return 0;
483
        }
484
        return Double.compare(d1, d2);
485
    }
30122 amit.gupta 486
 
35102 amit 487
    public static <T> Predicate<T> distinctByKey(Function<? super T, ?> keyExtractor) {
488
        Set<Object> seen = ConcurrentHashMap.newKeySet();
489
        return t -> seen.add(keyExtractor.apply(t));
490
    }
31903 amit.gupta 491
 
35102 amit 492
    public static <T> Predicate<T> smallestByKey(Function<? super T, ?> keyExtractor) {
493
        Set<Object> seen = ConcurrentHashMap.newKeySet();
494
        return t -> seen.add(keyExtractor.apply(t));
495
    }
32955 amit.gupta 496
 
35102 amit 497
    public static LocalDate convertToLocalDate(Date dateToConvert) {
498
        return Instant.ofEpochMilli(dateToConvert.getTime())
499
                .atZone(ZoneId.systemDefault())
500
                .toLocalDate();
501
    }
502
 
503
    public static LocalDateTime convertToLocalDateTime(Date dateToConvert) {
504
        return Instant.ofEpochMilli(dateToConvert.getTime())
505
                .atZone(ZoneId.systemDefault())
506
                .toLocalDateTime();
507
    }
508
 
26084 amit.gupta 509
}