]> git.basschouten.com Git - openhab-addons.git/blob
24e0cc978a5a3cc2845f58a9ab6d88b9082e278b
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2023 Contributors to the openHAB project
3  *
4  * See the NOTICE file(s) distributed with this work for additional
5  * information.
6  *
7  * This program and the accompanying materials are made available under the
8  * terms of the Eclipse Public License 2.0 which is available at
9  * http://www.eclipse.org/legal/epl-2.0
10  *
11  * SPDX-License-Identifier: EPL-2.0
12  */
13 package org.openhab.binding.tr064.internal.soap;
14
15 import java.text.ParseException;
16 import java.text.SimpleDateFormat;
17 import java.util.Date;
18
19 import org.eclipse.jdt.annotation.NonNullByDefault;
20 import org.eclipse.jdt.annotation.Nullable;
21 import org.openhab.binding.tr064.internal.dto.additions.Call;
22
23 /**
24  * The {@link CallListEntry} is used for post-processing the retrieved call
25  * lists
26  *
27  * @author Jan N. Klug - Initial contribution
28  */
29 @NonNullByDefault
30 public class CallListEntry {
31     private static final SimpleDateFormat DATE_FORMAT_PARSER = new SimpleDateFormat("dd.MM.yy HH:mm");
32     public @Nullable String localNumber;
33     public @Nullable String remoteNumber;
34     public @Nullable Date date;
35     public @Nullable Integer type;
36     public @Nullable Integer duration;
37
38     public CallListEntry(Call call) {
39         try {
40             synchronized (DATE_FORMAT_PARSER) {
41                 date = DATE_FORMAT_PARSER.parse(call.getDate());
42             }
43         } catch (ParseException e) {
44             // ignore parsing error
45             date = null;
46         }
47         String[] durationParts = call.getDuration().split(":");
48         duration = Integer.parseInt(durationParts[0]) * 60 + Integer.parseInt(durationParts[1]);
49         type = Integer.parseInt(call.getType());
50         if (CallListType.OUTBOUND_COUNT.typeString().equals(call.getType())) {
51             localNumber = call.getCallerNumber();
52             remoteNumber = call.getCalled();
53         } else {
54             localNumber = call.getCalledNumber();
55             remoteNumber = call.getCaller();
56         }
57     }
58 }