This repository has been archived by the owner on Jun 29, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #17 from openconnectivity/develop
Merge develop into master
- Loading branch information
Showing
25 changed files
with
1,119 additions
and
305 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,7 +11,7 @@ | |
|
||
# Constants | ||
PROJECT_NAME="otgc" | ||
VERSION="2.7.0" | ||
VERSION="2.8.0" | ||
|
||
program=$0 | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
83 changes: 83 additions & 0 deletions
83
src/main/java/org/openconnectivity/otgc/domain/usecase/OnboardDevicesUseCase.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
package org.openconnectivity.otgc.domain.usecase; | ||
|
||
import io.reactivex.Single; | ||
import org.openconnectivity.otgc.data.repository.DoxsRepository; | ||
import org.openconnectivity.otgc.data.repository.IotivityRepository; | ||
import org.openconnectivity.otgc.data.repository.SettingRepository; | ||
import org.openconnectivity.otgc.domain.model.devicelist.Device; | ||
import org.openconnectivity.otgc.utils.constant.OcfOxmType; | ||
import org.openconnectivity.otgc.utils.rx.SchedulersFacade; | ||
|
||
import javax.inject.Inject; | ||
import java.util.List; | ||
import java.util.concurrent.TimeUnit; | ||
|
||
public class OnboardDevicesUseCase { | ||
|
||
/* Repositories */ | ||
private final IotivityRepository iotivityRepository; | ||
private final DoxsRepository doxsRepository; | ||
private final SettingRepository settingRepository; | ||
/* Scheduler */ | ||
private final SchedulersFacade schedulersFacade; | ||
|
||
@Inject | ||
public OnboardDevicesUseCase(IotivityRepository iotivityRepository, | ||
DoxsRepository doxsRepository, | ||
SettingRepository settingRepository, | ||
SchedulersFacade schedulersFacade) { | ||
this.iotivityRepository = iotivityRepository; | ||
this.doxsRepository = doxsRepository; | ||
this.settingRepository = settingRepository; | ||
|
||
this.schedulersFacade = schedulersFacade; | ||
} | ||
|
||
public Single<Device> execute(Device device, List<OcfOxmType> oxms) { | ||
int it1 = oxms.size() - 1; | ||
if (it1 < 0) { | ||
return null; | ||
} | ||
|
||
return executeOnboard(device, oxms.get(it1)) | ||
.onErrorResumeNext(error1 -> { | ||
int it2 = it1 - 1; | ||
if (it2 < 0) { | ||
return null; | ||
} | ||
return iotivityRepository.scanUnownedDevices() | ||
.filter(device1 -> device.getDeviceId().equals(device1.getDeviceId())) | ||
.firstOrError() | ||
.flatMap(device1 -> | ||
executeOnboard(device1, oxms.get(it2)) | ||
.onErrorResumeNext(error -> { | ||
int it3 = it1 - 2; | ||
if (it3 < 0) { | ||
return null; | ||
} | ||
return iotivityRepository.scanUnownedDevices() | ||
.filter(device2 -> device.getDeviceId().equals(device2.getDeviceId())) | ||
.firstOrError() | ||
.flatMap(device2 -> executeOnboard(device2, oxms.get(it3))); | ||
}) | ||
); | ||
}); | ||
} | ||
|
||
private Single<Device> executeOnboard(Device deviceToOnboard, OcfOxmType oxm) { | ||
int delay = Integer.parseInt(settingRepository.get(SettingRepository.REQUESTS_DELAY_KEY, SettingRepository.REQUESTS_DELAY_DEFAULT_VALUE)); | ||
|
||
final Single<Device> getUpdatedOcSecureResource = iotivityRepository.scanOwnedDevices() | ||
.filter(device -> deviceToOnboard.getDeviceId().equals(device.getDeviceId()) | ||
|| deviceToOnboard.equalsHosts(device)) | ||
.singleOrError(); | ||
|
||
return doxsRepository.doOwnershipTransfer(deviceToOnboard.getDeviceId(), oxm) | ||
.delay(2 * delay, TimeUnit.SECONDS, schedulersFacade.ui()) | ||
.andThen(getUpdatedOcSecureResource | ||
.onErrorResumeNext(error -> getUpdatedOcSecureResource | ||
.retry(2) | ||
.onErrorResumeNext(Single.error(error))) | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
src/main/java/org/openconnectivity/otgc/utils/handler/OCSetRandomPinHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
package org.openconnectivity.otgc.utils.handler; | ||
|
||
public interface OCSetRandomPinHandler { | ||
public String handler(); | ||
public String handler(String deviceId); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.