]> git.basschouten.com Git - openhab-addons.git/blob
4bc9839a1d278bf843bb872e57a4e3daff63f01a
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2021 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             date = DATE_FORMAT_PARSER.parse(call.getDate());
41         } catch (ParseException e) {
42             // ignore parsing error
43             date = null;
44         }
45         String[] durationParts = call.getDuration().split(":");
46         duration = Integer.parseInt(durationParts[0]) * 60 + Integer.parseInt(durationParts[1]);
47         type = Integer.parseInt(call.getType());
48         if (CallListType.OUTBOUND_COUNT.typeString().equals(call.getType())) {
49             localNumber = call.getCallerNumber();
50             remoteNumber = call.getCalled();
51         } else {
52             localNumber = call.getCalledNumber();
53             remoteNumber = call.getCaller();
54         }
55     }
56 }