Skip to content
This repository has been archived by the owner on Jun 29, 2021. It is now read-only.

Commit

Permalink
Merge pull request #5 from openconnectivity/develop
Browse files Browse the repository at this point in the history
Merge develop into master
  • Loading branch information
javiguerra authored Sep 2, 2019
2 parents f70dcdb + 93ee21b commit 2a91e6a
Show file tree
Hide file tree
Showing 11 changed files with 145 additions and 33 deletions.
2 changes: 1 addition & 1 deletion build/debian/control
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Package: OTGC
Version: 2.0.3
Version: 2.0.4
Section: custom
Priority: optional
Architecture: amd64
Expand Down
2 changes: 1 addition & 1 deletion build/debian/otgc_native.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

# Constants
PROJECT_NAME="otgc"
VERSION="2.0.3"
VERSION="2.0.4"

program=$0

Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -28,6 +29,7 @@
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;
Expand Down Expand Up @@ -145,7 +147,6 @@ public Completable setFactoryResetHandler(OCFactoryPresetsHandler handler) {

public Observable<Device> scanUnownedDevices() {
return Completable.create(emitter -> {
LOG.debug("Discovering unowned devices");
unownedDevices.clear();

OCObtDiscoveryHandler handler = (uuid, endpoints) -> {
Expand All @@ -162,20 +163,30 @@ public Observable<Device> scanUnownedDevices() {
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) -> {
Expand All @@ -192,15 +203,26 @@ public Observable<Device> scanOwnedDevices() {
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() {
Expand Down Expand Up @@ -233,8 +255,22 @@ public Completable scanHosts() {
}
};

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)
Expand Down Expand Up @@ -397,7 +433,7 @@ public Single<DeviceEntity> getDeviceFromDatabase(String deviceId) {

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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* 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";
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
}));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,22 @@

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 {

Expand All @@ -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,
Expand All @@ -58,6 +78,14 @@ public SettingsViewModel(SchedulersFacade schedulersFacade,
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) {
Expand All @@ -66,4 +94,11 @@ public void discoveryTimeoutListener(ObservableValue<? extends String> observab
.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());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
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;
Expand All @@ -37,6 +38,7 @@
import org.openconnectivity.otgc.utils.scopes.DeviceListToolbarDetailScope;

import javax.inject.Inject;
import java.util.Arrays;
import java.util.List;
import java.util.concurrent.TimeUnit;

Expand All @@ -59,6 +61,7 @@ public IntegerProperty positionDeviceProperty() {
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;
Expand All @@ -85,6 +88,7 @@ public void initialize() {
public ToolbarViewModel(SchedulersFacade schedulersFacade,
GetOTMethodsUseCase getOTMethodsUseCase,
OnboardUseCase onboardUseCase,
CreateAclUseCase createAclUseCase,
GetDeviceInfoUseCase getDeviceInfoUseCase,
GetDeviceNameUseCase getDeviceNameUseCase,
SetDeviceNameUseCase setDeviceNameUseCase,
Expand All @@ -96,6 +100,7 @@ public ToolbarViewModel(SchedulersFacade schedulersFacade,
this.schedulersFacade = schedulersFacade;
this.getOTMethodsUseCase = getOTMethodsUseCase;
this.onboardUseCase = onboardUseCase;
this.createAclUseCase = createAclUseCase;
this.getDeviceInfoUseCase = getDeviceInfoUseCase;
this.getDeviceNameUseCase = getDeviceNameUseCase;
this.setDeviceNameUseCase = setDeviceNameUseCase;
Expand Down Expand Up @@ -164,7 +169,13 @@ public void doOwnershipTransfer(Device deviceToOnboard) {
.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))
Expand Down
Loading

0 comments on commit 2a91e6a

Please sign in to comment.