Unverified Commit 2a91e6aa authored by Javier Guerra's avatar Javier Guerra Committed by GitHub

Merge pull request #5 from openconnectivity/develop

Merge develop into master
parents f70dcdba 93ee21be
Package: OTGC
Version: 2.0.3
Version: 2.0.4
Section: custom
Priority: optional
Architecture: amd64
......
......@@ -11,7 +11,7 @@
# Constants
PROJECT_NAME="otgc"
VERSION="2.0.3"
VERSION="2.0.4"
program=$0
......
......@@ -6,7 +6,7 @@
<groupId>otgc</groupId>
<artifactId>otgc</artifactId>
<version>2.0.3</version>
<version>2.0.4</version>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
......
......@@ -20,6 +20,7 @@
package org.openconnectivity.otgc.data.repository;
import io.reactivex.Completable;
import io.reactivex.Maybe;
import io.reactivex.Observable;
import io.reactivex.Single;
import org.apache.log4j.Logger;
......@@ -28,6 +29,7 @@ import org.openconnectivity.otgc.domain.model.resource.virtual.p.OcPlatformInfo;
import org.openconnectivity.otgc.domain.model.resource.virtual.res.OcEndpoint;
import org.openconnectivity.otgc.domain.model.resource.virtual.res.OcRes;
import org.openconnectivity.otgc.domain.model.resource.virtual.res.OcResource;
import org.openconnectivity.otgc.utils.constant.DiscoveryScope;
import org.openconnectivity.otgc.utils.constant.OcfResourceType;
import org.openconnectivity.otgc.data.entity.DeviceEntity;
import org.openconnectivity.otgc.data.persistence.DatabaseManager;
......@@ -145,7 +147,6 @@ public class IotivityRepository {
public Observable<Device> scanUnownedDevices() {
return Completable.create(emitter -> {
LOG.debug("Discovering unowned devices");
unownedDevices.clear();
OCObtDiscoveryHandler handler = (uuid, endpoints) -> {
......@@ -162,20 +163,30 @@ public class IotivityRepository {
unownedDevices.add(new Device(DeviceType.UNOWNED, deviceId, new OcDeviceInfo(), endpoints, Device.NOTHING_PERMITS));
};
int ret = OCObt.discoverUnownedDevices(handler);
int ret;
String scope = settingRepository.get(SettingRepository.DISCOVERY_SCOPE_KEY, SettingRepository.DISCOVERY_SCOPE_DEFAULT_VALUE);
if (scope.equals(DiscoveryScope.DISCOVERY_SCOPE_SITE)) {
LOG.debug("Discovering unowned devices in Site-Local scope");
ret = OCObt.discoverUnownedDevicesSiteLocalIPv6(handler);
} else if (scope.equals(DiscoveryScope.DISCOVERY_SCOPE_REALM)) {
LOG.debug("Discovering unowned devices in Realm-Local scope");
ret = OCObt.discoverUnownedDevicesRealmLocalIPv6(handler);
} else {
LOG.debug("Discovering unowned devices in Link-Local scope");
ret = OCObt.discoverUnownedDevices(handler);
}
if (ret < 0) {
String error = "ERROR discovering un-owned Devices.";
LOG.error(error);
emitter.onError(new Exception(error));
}
}).timeout(getDiscoveryTimeout(), TimeUnit.SECONDS)
.onErrorComplete()
.andThen(Observable.fromIterable(unownedDevices));
.onErrorComplete()
.andThen(Observable.fromIterable(unownedDevices));
}
public Observable<Device> scanOwnedDevices() {
return Completable.create(emitter -> {
LOG.debug("Discovering owned devices");
ownedDevices.clear();
OCObtDiscoveryHandler handler = (uuid, endpoints) -> {
......@@ -192,15 +203,26 @@ public class IotivityRepository {
ownedDevices.add(new Device(DeviceType.OWNED_BY_SELF, deviceId, new OcDeviceInfo(), endpoints, Device.FULL_PERMITS));
};
int ret = OCObt.discoverOwnedDevices(handler);
int ret;
String scope = settingRepository.get(SettingRepository.DISCOVERY_SCOPE_KEY, SettingRepository.DISCOVERY_SCOPE_DEFAULT_VALUE);
if (scope.equals(DiscoveryScope.DISCOVERY_SCOPE_SITE)) {
LOG.debug("Discovering owned devices in Site-Local scope");
ret = OCObt.discoverOwnedDevicesSiteLocalIPv6(handler);
} else if (scope.equals(DiscoveryScope.DISCOVERY_SCOPE_REALM)) {
LOG.debug("Discovering owned devices in Realm-Local scope");
ret = OCObt.discoverOwnedDevicesRealmLocalIPv6(handler);
} else {
LOG.debug("Discovering owned devices in Link-Local scope");
ret = OCObt.discoverOwnedDevices(handler);
}
if (ret < 0) {
String error = "ERROR discovering owned Devices.";
LOG.error(error);
emitter.onError(new Exception(error));
}
}).timeout(getDiscoveryTimeout(), TimeUnit.SECONDS)
.onErrorComplete()
.andThen(Observable.fromIterable(ownedDevices));
.onErrorComplete()
.andThen(Observable.fromIterable(ownedDevices));
}
public Completable scanHosts() {
......@@ -233,8 +255,22 @@ public class IotivityRepository {
}
};
if (!OCMain.doIPMulticast(OcfResourceUri.RES_URI, null, handler)) {
emitter.onError(new Exception("Error scanning hosts"));
String scope = settingRepository.get(SettingRepository.DISCOVERY_SCOPE_KEY, SettingRepository.DISCOVERY_SCOPE_DEFAULT_VALUE);
if (scope.equals(DiscoveryScope.DISCOVERY_SCOPE_SITE)) {
LOG.debug("Discovering owned devices by other OBT in Site-Local scope");
if (!OCMain.doSiteLocalIPv6Multicast(OcfResourceUri.RES_URI, null, handler)) {
emitter.onError(new Exception("Error scanning hosts"));
}
} else if (scope.equals(DiscoveryScope.DISCOVERY_SCOPE_REALM)) {
LOG.debug("Discovering owned devices by other OBT in Realm-Local scope");
if (!OCMain.doRealmLocalIPv6Multicast(OcfResourceUri.RES_URI, null, handler)) {
emitter.onError(new Exception("Error scanning hosts"));
}
} else {
LOG.debug("Discovering owned devices by other OBT in Link-Local scope");
if (!OCMain.doIPMulticast(OcfResourceUri.RES_URI, null, handler)) {
emitter.onError(new Exception("Error scanning hosts"));
}
}
}).timeout(getDiscoveryTimeout(), TimeUnit.SECONDS)
......@@ -397,7 +433,7 @@ public class IotivityRepository {
public int getDiscoveryTimeout() {
return Integer.parseInt(settingRepository.get(SettingRepository.DISCOVERY_TIMEOUT_KEY,
SettingRepository.DISCOVERY_TIMEOUT_DEFAULT_VALUE));
SettingRepository.DISCOVERY_TIMEOUT_DEFAULT_VALUE));
}
public Single<List<OcResource>> findVerticalResources(String host) {
......
......@@ -42,6 +42,8 @@ public class SettingRepository {
public static final String DISCOVERY_TIMEOUT_DEFAULT_VALUE = "5";
public static final String FIRST_RUN_KEY = "FIRSTRUN";
public static final String FIRST_RUN_DEFAULT_VALUE = "true";
public static final String DISCOVERY_SCOPE_KEY = "discovery_scope";
public static final String DISCOVERY_SCOPE_DEFAULT_VALUE = "Link-Local";
@Inject
......
/*
* Copyright 2018 DEKRA Testing and Certification, S.A.U. All Rights Reserved.
*
* ****************************************************************
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.openconnectivity.otgc.utils.constant;
public class DiscoveryScope {
private DiscoveryScope() {}
public static final String DISCOVERY_SCOPE_LINK = "Link-Local";
public static final String DISCOVERY_SCOPE_SITE = "Site-Local";
public static final String DISCOVERY_SCOPE_REALM = "Realm-Local";
}
......@@ -19,6 +19,7 @@
package org.openconnectivity.otgc.view.setting;
import com.jfoenix.controls.JFXComboBox;
import com.jfoenix.controls.JFXTextField;
import de.saxsys.mvvmfx.FxmlView;
import de.saxsys.mvvmfx.InjectViewModel;
......@@ -37,11 +38,18 @@ public class SettingsView implements FxmlView<SettingsViewModel>, Initializable
private SettingsViewModel viewModel;
@FXML private JFXTextField jfxDiscoveryTimeout;
@FXML private JFXComboBox<String> jfxDiscoveryScope;
@Override
public void initialize(URL location, ResourceBundle resources) {
jfxDiscoveryTimeout.textProperty().bindBidirectional(viewModel.discoveryTimeoutProperty());
jfxDiscoveryTimeout.setTextFormatter(new TextFormatter<>(PositiveIntegerValidator.getFilter()));
jfxDiscoveryScope.itemsProperty().bindBidirectional(viewModel.discoveryScopeProperty());
jfxDiscoveryScope.getSelectionModel().select(viewModel.selectedDiscoveryScopeProperty().get());
jfxDiscoveryScope.getSelectionModel().selectedItemProperty().addListener(((observable, oldValue, newValue) -> {
viewModel.selectedDiscoveryScopeProperty().setValue(newValue);
}));
}
}
......@@ -21,14 +21,22 @@ package org.openconnectivity.otgc.viewmodel;
import de.saxsys.mvvmfx.ViewModel;
import io.reactivex.disposables.CompositeDisposable;
import javafx.beans.property.ListProperty;
import javafx.beans.property.SimpleListProperty;
import javafx.beans.property.SimpleStringProperty;
import javafx.beans.property.StringProperty;
import javafx.beans.value.ObservableListValue;
import javafx.beans.value.ObservableValue;
import javafx.collections.FXCollections;
import org.openconnectivity.otgc.utils.constant.DiscoveryScope;
import org.openconnectivity.otgc.utils.rx.SchedulersFacade;
import org.openconnectivity.otgc.domain.usecase.setting.GetSettingUseCase;
import org.openconnectivity.otgc.domain.usecase.setting.UpdateSettingUseCase;
import javax.inject.Inject;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
public class SettingsViewModel implements ViewModel {
......@@ -40,12 +48,24 @@ public class SettingsViewModel implements ViewModel {
private static final String DISCOVERY_TIMEOUT_KEY = "discovery_timeout";
private static final String DISCOVERY_TIMEOUT_DEFAULT = "5";
private static final String DISCOVERY_SCOPE_KEY = "discovery_scope";
private static final String DISCOVERY_SCOPE_DEFAULT = "Link-Local";
private StringProperty discoveryTimeout = new SimpleStringProperty();
public StringProperty discoveryTimeoutProperty() {
return discoveryTimeout;
}
private ListProperty<String> discoveryScope = new SimpleListProperty<>();
public ListProperty<String> discoveryScopeProperty() {
return discoveryScope;
}
private StringProperty selectedDiscoveryScope = new SimpleStringProperty();
public StringProperty selectedDiscoveryScopeProperty() {
return selectedDiscoveryScope;
}
@Inject
public SettingsViewModel(SchedulersFacade schedulersFacade,
GetSettingUseCase getSettingUseCase,
......@@ -58,6 +78,14 @@ public class SettingsViewModel implements ViewModel {
public void initialize() {
discoveryTimeout.setValue(getSettingUseCase.execute(DISCOVERY_TIMEOUT_KEY, DISCOVERY_TIMEOUT_DEFAULT));
discoveryTimeoutProperty().addListener(this::discoveryTimeoutListener);
String scopeList[] = { DiscoveryScope.DISCOVERY_SCOPE_LINK,
DiscoveryScope.DISCOVERY_SCOPE_SITE,
DiscoveryScope.DISCOVERY_SCOPE_REALM};
discoveryScopeProperty().setValue(FXCollections.observableArrayList(scopeList));
selectedDiscoveryScope.setValue(getSettingUseCase.execute(DISCOVERY_SCOPE_KEY, DISCOVERY_SCOPE_DEFAULT));
selectedDiscoveryScopeProperty().addListener(this::discoveryScopeListener);
}
public void discoveryTimeoutListener(ObservableValue<? extends String> observableValue, String oldValue, String newValue) {
......@@ -66,4 +94,11 @@ public class SettingsViewModel implements ViewModel {
.observeOn(schedulersFacade.ui())
.subscribe());
}
public void discoveryScopeListener (ObservableValue<? extends String> observableValue, String oldValue, String newValue) {
disposables.add(updateSettingUseCase.execute(DISCOVERY_SCOPE_KEY, newValue)
.subscribeOn(schedulersFacade.io())
.observeOn(schedulersFacade.ui())
.subscribe());
}
}
......@@ -27,6 +27,7 @@ import javafx.beans.binding.Bindings;
import javafx.beans.property.*;
import javafx.beans.value.ObservableBooleanValue;
import org.apache.log4j.Logger;
import org.openconnectivity.otgc.domain.usecase.accesscontrol.CreateAclUseCase;
import org.openconnectivity.otgc.utils.constant.NotificationKey;
import org.openconnectivity.otgc.domain.model.devicelist.Device;
import org.openconnectivity.otgc.domain.model.devicelist.DeviceType;
......@@ -37,6 +38,7 @@ import org.openconnectivity.otgc.domain.usecase.*;
import org.openconnectivity.otgc.utils.scopes.DeviceListToolbarDetailScope;
import javax.inject.Inject;
import java.util.Arrays;
import java.util.List;
import java.util.concurrent.TimeUnit;
......@@ -59,6 +61,7 @@ public class ToolbarViewModel implements ViewModel {
private final SchedulersFacade schedulersFacade;
private final GetOTMethodsUseCase getOTMethodsUseCase;
private final OnboardUseCase onboardUseCase;
private final CreateAclUseCase createAclUseCase;
private final GetDeviceInfoUseCase getDeviceInfoUseCase;
private final GetDeviceNameUseCase getDeviceNameUseCase;
private final SetDeviceNameUseCase setDeviceNameUseCase;
......@@ -85,6 +88,7 @@ public class ToolbarViewModel implements ViewModel {
public ToolbarViewModel(SchedulersFacade schedulersFacade,
GetOTMethodsUseCase getOTMethodsUseCase,
OnboardUseCase onboardUseCase,
CreateAclUseCase createAclUseCase,
GetDeviceInfoUseCase getDeviceInfoUseCase,
GetDeviceNameUseCase getDeviceNameUseCase,
SetDeviceNameUseCase setDeviceNameUseCase,
......@@ -96,6 +100,7 @@ public class ToolbarViewModel implements ViewModel {
this.schedulersFacade = schedulersFacade;
this.getOTMethodsUseCase = getOTMethodsUseCase;
this.onboardUseCase = onboardUseCase;
this.createAclUseCase = createAclUseCase;
this.getDeviceInfoUseCase = getDeviceInfoUseCase;
this.getDeviceNameUseCase = getDeviceNameUseCase;
this.setDeviceNameUseCase = setDeviceNameUseCase;
......@@ -164,7 +169,13 @@ public class ToolbarViewModel implements ViewModel {
.observeOn(schedulersFacade.ui())
.doOnSubscribe(__ -> otmResponse.setValue(Response.loading()))
.subscribe(
ownedDevice -> otmResponse.setValue(Response.success(ownedDevice)),
ownedDevice -> createAclUseCase.execute(ownedDevice, true, Arrays.asList("*"), 31)
.subscribeOn(schedulersFacade.io())
.observeOn(schedulersFacade.ui())
.subscribe(
() -> otmResponse.setValue(Response.success(ownedDevice)),
throwable -> otmResponse.setValue(Response.error(throwable))
),
throwable -> otmResponse.setValue(Response.error(throwable))
),
throwable -> otmResponse.setValue(Response.error(throwable))
......
......@@ -28,6 +28,7 @@
<?import com.jfoenix.controls.JFXCheckBox?>
<?import com.jfoenix.controls.JFXRadioButton?>
<?import com.jfoenix.controls.JFXComboBox?>
<VBox maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="300.0" prefWidth="400.0"
xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1"
fx:controller="org.openconnectivity.otgc.view.setting.SettingsView">
......@@ -46,13 +47,9 @@
<ColumnConstraints percentWidth="5.0" hgrow="NEVER" />
<ColumnConstraints percentWidth="35.0" hgrow="ALWAYS" />
</columnConstraints>
<!-- <rowConstraints>
<RowConstraints />
<RowConstraints />
</rowConstraints> -->
<children>
<!-- Row 0 : Discovery timeout-->
<!-- <AnchorPane GridPane.rowIndex="0" GridPane.columnIndex="0">
<AnchorPane GridPane.rowIndex="0" GridPane.columnIndex="0">
<children>
<Label text="%settings.label.discovery_timeout" alignment="CENTER"
AnchorPane.bottomAnchor="0.0" AnchorPane.topAnchor="0.0"
......@@ -65,9 +62,9 @@
AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0"
AnchorPane.topAnchor="0.0" AnchorPane.bottomAnchor="0.0" />
</children>
</AnchorPane>-->
</AnchorPane>
<!-- Row 1 : Discovery scope -->
<!-- <AnchorPane GridPane.rowIndex="1" GridPane.columnIndex="0">
<AnchorPane GridPane.rowIndex="1" GridPane.columnIndex="0">
<children>
<Label text="%settings.label.discovery_scope" alignment="CENTER"
AnchorPane.bottomAnchor="0.0" AnchorPane.topAnchor="0.0"
......@@ -76,18 +73,11 @@
</AnchorPane>
<AnchorPane GridPane.rowIndex="1" GridPane.columnIndex="2">
<children>
<JFXRadioButton fx:id="linkRadioButton" selected="true" text="%settings.iotivity.radiobutton.link"
onAction="#handleDiscoveryScopeGroup">
<toggleGroup>
<ToggleGroup fx:id="toggleDiscoveryScopeGroup"/>
</toggleGroup>
</JFXRadioButton>
<JFXRadioButton fx:id="siteRadioButton" selected="false" onAction="#handleDiscoveryScopeGroup"
text="%settings.iotivity.radiobutton.site" toggleGroup="$toggleDiscoveryScopeGroup" />
<JFXRadioButton fx:id="realmRadioButton" selected="false" onAction="#handleDiscoveryScopeGroup"
text="%settings.iotivity.radiobutton.realm" toggleGroup="$toggleDiscoveryScopeGroup" />
<JFXComboBox fx:id="jfxDiscoveryScope"
AnchorPane.bottomAnchor="0.0" AnchorPane.topAnchor="0.0"
AnchorPane.rightAnchor="0.0" AnchorPane.leftAnchor="0.0" />
</children>
</AnchorPane> -->
</AnchorPane>
</children>
</GridPane>
</children>
......
......@@ -63,6 +63,8 @@ about.para2=DEKRA Testing and Certification, S.A.U.
settings.window.title=Settings
settings.iotivity.title=IoTivity
settings.label.discovery_timeout=Discovery timeout (in seconds)
settings.label.discovery_scope=Multicast IPv6 scope
settings.title.discovery_scope=Select IPv6 scope
# Main
main.init_oic_stack.success=OIC Stack initialized
main.init_oic_stack.error=Error initializing OIC Stack
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment