Added cloud configuration

parent 216f944c
......@@ -11,7 +11,7 @@
# Constants
PROJECT_NAME="otgc"
VERSION="2.12.0"
VERSION="2.13.0"
program=$0
......
Subproject commit f4ae603d09e81a3673e395d7382450b52e6be2cb
Subproject commit bb53715d5e4dbe30360685690bac61f2e4546f6b
......@@ -6,7 +6,7 @@
<groupId>otgc</groupId>
<artifactId>otgc</artifactId>
<version>2.12.0</version>
<version>2.13.0</version>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
......
package org.openconnectivity.otgc.data.repository;
import io.reactivex.Completable;
import io.reactivex.Single;
import org.iotivity.OCCloud;
import org.iotivity.OCCloudContext;
import org.openconnectivity.otgc.domain.model.resource.cloud.OcCloudConfiguration;
import javax.inject.Inject;
import javax.inject.Singleton;
@Singleton
public class CloudRepository {
@Inject
public CloudRepository() {
}
public Single<Integer> retrieveState() {
return Single.create(emitter -> {
OCCloudContext ctx = OCCloud.getContext(0);
short status = ctx.getStore().getStatus();
emitter.onSuccess((int)status);
});
}
public Single<OcCloudConfiguration> retrieveCloudConfiguration() {
return Single.create(emitter -> {
OCCloudContext ctx = OCCloud.getContext(0);
String apn = ctx.getStore().getAuth_provider();
String url = ctx.getStore().getCi_server();
String at = ctx.getStore().getAccess_token();
String uuid = ctx.getStore().getSid();
emitter.onSuccess(new OcCloudConfiguration(apn, url, at, uuid));
});
}
public Completable provisionCloudConfiguration(String authProvider, String cloudUrl, String accessToken, String cloudUuid) {
return Completable.create(emitter -> {
OCCloudContext ctx = OCCloud.getContext(0);
OCCloud.provisionConfResource(ctx, authProvider, cloudUrl, accessToken, cloudUuid);
emitter.onComplete();
});
}
}
package org.openconnectivity.otgc.domain.model.resource.cloud;
public class OcCloudConfiguration {
private String authProvider;
private String cloudUrl;
private String accessToken;
private String cloudUuid;
public OcCloudConfiguration() { }
public OcCloudConfiguration(String apn, String url, String at, String uuid) {
this.authProvider = apn;
this.cloudUrl = url;
this.accessToken = at;
this.cloudUuid = uuid;
}
public String getAuthProvider() {
return authProvider;
}
public void setAuthProvider(String authProvider) {
this.authProvider = authProvider;
}
public String getCloudUrl() {
return cloudUrl;
}
public void setCloudUrl(String cloudUrl) {
this.cloudUrl = cloudUrl;
}
public String getAccessToken() {
return accessToken;
}
public void setAccessToken(String accessToken) {
this.accessToken = accessToken;
}
public String getCloudUuid() {
return cloudUuid;
}
public void setCloudUuid(String cloudUuid) {
this.cloudUuid = cloudUuid;
}
}
package org.openconnectivity.otgc.domain.usecase.cloud;
import io.reactivex.Completable;
import org.openconnectivity.otgc.data.repository.CloudRepository;
import javax.inject.Inject;
public class ProvisionCloudConfUseCase {
private final CloudRepository cloudRepository;
@Inject
public ProvisionCloudConfUseCase(CloudRepository cloudRepository) {
this.cloudRepository = cloudRepository;
}
public Completable execute(String authProvider, String cloudUrl, String accessToken, String cloudUuid) {
return cloudRepository.provisionCloudConfiguration(authProvider, cloudUrl, accessToken, cloudUuid);
}
}
package org.openconnectivity.otgc.domain.usecase.cloud;
import io.reactivex.Single;
import org.openconnectivity.otgc.data.repository.CloudRepository;
import org.openconnectivity.otgc.domain.model.resource.cloud.OcCloudConfiguration;
import javax.inject.Inject;
public class RetrieveCloudConfigurationUseCase {
private final CloudRepository cloudRepository;
@Inject
public RetrieveCloudConfigurationUseCase(CloudRepository cloudRepository) {
this.cloudRepository = cloudRepository;
}
public Single<OcCloudConfiguration> execute() {
return cloudRepository.retrieveCloudConfiguration();
}
}
package org.openconnectivity.otgc.domain.usecase.cloud;
import io.reactivex.Single;
import org.openconnectivity.otgc.data.repository.CloudRepository;
import javax.inject.Inject;
public class RetrieveStatusUseCase {
private final CloudRepository cloudRepository;
@Inject
public RetrieveStatusUseCase(CloudRepository cloudRepository) {
this.cloudRepository = cloudRepository;
}
public Single<Integer> execute() {
return cloudRepository.retrieveState();
}
}
package org.openconnectivity.otgc.view.cloud;
import com.jfoenix.controls.JFXTextField;
import de.saxsys.mvvmfx.FxmlView;
import de.saxsys.mvvmfx.InjectViewModel;
import javafx.beans.value.ObservableValue;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.Label;
import javafx.stage.Stage;
import org.apache.log4j.Logger;
import org.openconnectivity.otgc.utils.util.Toast;
import org.openconnectivity.otgc.utils.viewmodel.Response;
import org.openconnectivity.otgc.utils.viewmodel.Status;
import org.openconnectivity.otgc.viewmodel.CloudViewModel;
import javax.inject.Inject;
import java.net.URL;
import java.util.ResourceBundle;
public class CloudView implements FxmlView<CloudViewModel>, Initializable {
private final Logger LOG = Logger.getLogger(CloudView.class);
@InjectViewModel
private CloudViewModel viewModel;
@Inject
private Stage primaryStage;
@FXML private Label statusValue;
@FXML private JFXTextField authProviderTextField;
@FXML private JFXTextField cloudUrlTextField;
@FXML private JFXTextField accessTokenTextField;
@FXML private JFXTextField cloudUuidTextField;
private ResourceBundle resourceBundle;
public void initialize(URL url, ResourceBundle resourceBundle) {
this.resourceBundle = resourceBundle;
this.statusValue.textProperty().bind(viewModel.getStatusProperty());
this.authProviderTextField.textProperty().bindBidirectional(viewModel.getAuthProviderProperty());
this.cloudUrlTextField.textProperty().bindBidirectional(viewModel.getCloudUrlProperty());
this.accessTokenTextField.textProperty().bindBidirectional(viewModel.getAccessTokenProperty());
this.cloudUuidTextField.textProperty().bindBidirectional(viewModel.getCloudUuidProperty());
viewModel.retrieveStatusResponseProperty().addListener(this::processRetrieveStatusResponse);
viewModel.retrieveCloudConfResponseProperty().addListener(this::processRetrieveCloudConfResponse);
viewModel.storeCloudConfigResponseProperty().addListener(this::processStoreCloudConfigResponse);
}
private void processRetrieveStatusResponse(ObservableValue<? extends Response<Integer>> observableValue, Response<Integer> oldValue, Response<Integer> newValue) {
if (newValue.status == Status.ERROR) {
Toast.show(primaryStage, resourceBundle.getString("cloud.retrieve_status.error"));
LOG.debug(newValue.message);
}
}
private void processRetrieveCloudConfResponse(ObservableValue<? extends Response<Void>> observableValue, Response<Void> oldValue, Response<Void> newValue) {
if (newValue.status == Status.ERROR) {
Toast.show(primaryStage, resourceBundle.getString("cloud.retrieve_cloud_conf.error"));
LOG.debug(newValue.message);
}
}
private void processStoreCloudConfigResponse(ObservableValue<? extends Response<Void>> observableValue, Response<Void> oldValue, Response<Void> newValue) {
if (newValue.status == Status.SUCCESS) {
Toast.show(primaryStage, resourceBundle.getString("cloud.store_cloud_conf.success"));
} else if (newValue.status == Status.ERROR){
Toast.show(primaryStage, resourceBundle.getString("cloud.store_cloud_conf.error"));
}
}
@FXML
public void handleSaveCloudConf() {
String authProvider = authProviderTextField.textProperty().getValue();
String cloudUrl = cloudUrlTextField.textProperty().getValue();
String accessToken = accessTokenTextField.textProperty().getValue();
String cloudUuid = cloudUuidTextField.textProperty().getValue();
viewModel.provisionCloudConfiguration(authProvider, cloudUrl, accessToken, cloudUuid);
}
}
......@@ -26,6 +26,7 @@ import javafx.fxml.Initializable;
import javafx.scene.Parent;
import javafx.scene.control.Label;
import javafx.stage.Stage;
import org.openconnectivity.otgc.view.cloud.CloudView;
import org.openconnectivity.otgc.viewmodel.MenuViewModel;
import org.openconnectivity.otgc.view.about.AboutView;
import org.openconnectivity.otgc.utils.util.DialogHelper;
......@@ -74,4 +75,10 @@ public class MenuView implements FxmlView<MenuViewModel>, Initializable {
Parent view = FluentViewLoader.fxmlView(AboutView.class).load().getView();
DialogHelper.showDialog(view, primaryStage, resourceBundle.getString("about.window.title"), "/styles/about.css");
}
@FXML
public void cloud() {
Parent view = FluentViewLoader.fxmlView(CloudView.class).load().getView();
DialogHelper.showDialog(view, primaryStage, resourceBundle.getString("cloud.window.title"), "/styles/cloud.css");
}
}
/*
* 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.viewmodel;
import de.saxsys.mvvmfx.ViewModel;
import io.reactivex.disposables.CompositeDisposable;
import javafx.beans.property.ObjectProperty;
import javafx.beans.property.SimpleObjectProperty;
import javafx.beans.property.SimpleStringProperty;
import javafx.beans.property.StringProperty;
import org.iotivity.OCCloudStatusMask;
import org.openconnectivity.otgc.domain.usecase.cloud.ProvisionCloudConfUseCase;
import org.openconnectivity.otgc.domain.usecase.cloud.RetrieveCloudConfigurationUseCase;
import org.openconnectivity.otgc.domain.usecase.cloud.RetrieveStatusUseCase;
import org.openconnectivity.otgc.utils.rx.SchedulersFacade;
import org.openconnectivity.otgc.utils.viewmodel.Response;
import javax.inject.Inject;
public class CloudViewModel implements ViewModel {
private final SchedulersFacade schedulersFacade;
private final CompositeDisposable disposables = new CompositeDisposable();
// Use Cases
private final RetrieveStatusUseCase retrieveStatusUseCase;
private final RetrieveCloudConfigurationUseCase retrieveCloudConfigurationUseCase;
private final ProvisionCloudConfUseCase provisionCloudConfUseCase;
// Observable responses
private final ObjectProperty<Response<Integer>> retrieveStatusResponse = new SimpleObjectProperty<>();
private final ObjectProperty<Response<Void>> retrieveCloudConfResponse = new SimpleObjectProperty<>();
private final ObjectProperty<Response<Void>> storeCloudConfigResponse = new SimpleObjectProperty<>();
// Observable properties
private final StringProperty statusProperty = new SimpleStringProperty();
public StringProperty getStatusProperty() {
return statusProperty;
}
private final StringProperty authProviderProperty = new SimpleStringProperty();
public StringProperty getAuthProviderProperty() {
return authProviderProperty;
}
private final StringProperty cloudUrlProperty = new SimpleStringProperty();
public StringProperty getCloudUrlProperty() {
return cloudUrlProperty;
}
private final StringProperty accessTokenProperty = new SimpleStringProperty();
public StringProperty getAccessTokenProperty() {
return accessTokenProperty;
}
private final StringProperty cloudUuidProperty = new SimpleStringProperty();
public StringProperty getCloudUuidProperty() {
return cloudUuidProperty;
}
@Inject
public CloudViewModel(SchedulersFacade schedulersFacade,
RetrieveStatusUseCase retrieveStatusUseCase,
RetrieveCloudConfigurationUseCase retrieveCloudConfigurationUseCase,
ProvisionCloudConfUseCase provisionCloudConfUseCase) {
this.schedulersFacade = schedulersFacade;
this.retrieveStatusUseCase = retrieveStatusUseCase;
this.retrieveCloudConfigurationUseCase = retrieveCloudConfigurationUseCase;
this.provisionCloudConfUseCase = provisionCloudConfUseCase;
retrieveStatus();
retrieveCloudConfiguration();
}
public ObjectProperty<Response<Integer>> retrieveStatusResponseProperty() {
return retrieveStatusResponse;
}
public ObjectProperty<Response<Void>> retrieveCloudConfResponseProperty() {
return retrieveCloudConfResponse;
}
public ObjectProperty<Response<Void>> storeCloudConfigResponseProperty() {
return storeCloudConfigResponse;
}
private void retrieveStatus() {
disposables.add(retrieveStatusUseCase.execute()
.subscribeOn(schedulersFacade.io())
.observeOn(schedulersFacade.ui())
.subscribe(
(status) -> {
retrieveStatusResponse.setValue(Response.success(status));
updateValueStatus(status);
},
throwable -> retrieveStatusResponse.setValue(Response.error(throwable))
));
}
private void retrieveCloudConfiguration() {
disposables.add(retrieveCloudConfigurationUseCase.execute()
.subscribeOn(schedulersFacade.io())
.observeOn(schedulersFacade.ui())
.subscribe(
(cloudConf) -> {
retrieveCloudConfResponse.setValue(Response.success(null));
authProviderProperty.setValue(cloudConf.getAuthProvider());
cloudUrlProperty.setValue(cloudConf.getCloudUrl());
accessTokenProperty.setValue(cloudConf.getAccessToken());
cloudUuidProperty.setValue(cloudConf.getCloudUuid());
},
throwable -> retrieveCloudConfResponse.setValue(Response.error(throwable))
));
}
public void updateValueStatus(int status) {
// Set value of status
switch(status) {
case OCCloudStatusMask.OC_CLOUD_INITIALIZED:
statusProperty.setValue("Initialized");
break;
case OCCloudStatusMask.OC_CLOUD_REGISTERED:
statusProperty.setValue("Registered");
break;
case OCCloudStatusMask.OC_CLOUD_LOGGED_IN:
statusProperty.setValue("Logged in");
break;
case OCCloudStatusMask.OC_CLOUD_TOKEN_EXPIRY:
statusProperty.setValue("Token expiry");
break;
case OCCloudStatusMask.OC_CLOUD_REFRESHED_TOKEN:
statusProperty.setValue("Refresh token");
break;
case OCCloudStatusMask.OC_CLOUD_LOGGED_OUT:
statusProperty.setValue("Logged out");
break;
case OCCloudStatusMask.OC_CLOUD_FAILURE:
statusProperty.setValue("Failure");
break;
case OCCloudStatusMask.OC_CLOUD_DEREGISTERED:
statusProperty.setValue("Deregistered");
break;
default:
statusProperty.setValue("Unknown");
break;
}
}
public void provisionCloudConfiguration(String authProvider, String cloudUrl, String accessToken, String cloudUuid) {
disposables.add(provisionCloudConfUseCase.execute(authProvider, cloudUrl, accessToken, cloudUuid)
.subscribeOn(schedulersFacade.io())
.observeOn(schedulersFacade.ui())
.subscribe(
() -> storeCloudConfigResponse.setValue(Response.success(null)),
throwable -> storeCloudConfigResponse.setValue(Response.error(throwable))
));
}
}
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.image.ImageView?>
<?import javafx.scene.image.Image?>
<?import javafx.geometry.Insets?>
<!--
~ 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.
~
-->
<?import com.jfoenix.controls.JFXTextField?>
<?import com.jfoenix.controls.JFXButton?>
<AnchorPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="300.0" prefWidth="400.0" xmlns="http://javafx.com/javafx/8.0.40" xmlns:fx="http://javafx.com/fxml/1" fx:controller="org.openconnectivity.otgc.view.cloud.CloudView">
<children>
<VBox AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0" alignment="CENTER">
<children>
<HBox spacing="10">
<padding><Insets top="10" right="10" bottom="10" left="10"/></padding>
<Label styleClass="labelTitle" text="%cloud.label.status" />
<Label fx:id="statusValue" id="statusValue" />
</HBox>
<VBox spacing="20">
<padding><Insets top="10" right="10" bottom="10" left="10"/></padding>
<JFXTextField fx:id="authProviderTextField" labelFloat="true" promptText="%cloud.label.auth_provider" />
<JFXTextField fx:id="cloudUrlTextField" labelFloat="true" promptText="%cloud.label.url" />
<JFXTextField fx:id="accessTokenTextField" labelFloat="true" promptText="%cloud.label.access_token" />
<JFXTextField fx:id="cloudUuidTextField" labelFloat="true" promptText="%cloud.label.uuid" />
<JFXButton onAction="#handleSaveCloudConf" text="%cloud.button.save" buttonType="RAISED" />
</VBox>
</children>
</VBox>
</children>
</AnchorPane>
......@@ -40,6 +40,11 @@
<MenuItem mnemonicParsing="false" onAction="#close" text="%menu.file.close" />
</items>
</Menu>
<Menu mnemonicParsing="false" text="%menu.cloud">
<items>
<MenuItem mnemonicParsing="false" onAction="#cloud" text="%menu.cloud.configuration" />
</items>
</Menu>
<Menu mnemonicParsing="false" text="%menu.help">
<items>
<MenuItem mnemonicParsing="false" onAction="#about" text="%menu.help.about" />
......
......@@ -30,6 +30,8 @@ menu.file=File
menu.file.close=Close
menu.file.discover=Discover
menu.file.settings=Settings
menu.cloud=Cloud
menu.cloud.configuration=Configuration
menu.help=Help
menu.help.about=About
# Toolbar
......@@ -61,6 +63,18 @@ trust_anchor.button.select_certificate=Select certificate
trust_anchor.button.select_key=Select key
trust_anchor.button.save=Save
trust_anchor.button.remove=Delete
# Cloud
cloud.window.title=Cloud Configuration
cloud.label.status=Status:
cloud.label.auth_provider=Authentication Provider
cloud.label.url=Cloud URL
cloud.label.access_token=Access Token
cloud.label.uuid=Cloud UUID
cloud.button.save=Save
cloud.retrieve_status.error=Retrieve status has failed
cloud.retrieve_cloud_conf.error=Retrieve Cloud Configuration has failed
cloud.store_cloud_conf.success=Cloud Configuration has been updated
cloud.store_cloud_conf.error=Store cloud configuration has failed
# About
about.window.title=About
about.title1=OTGC
......
.labelTitle {
-fx-font-weight: bold;
}
.labelTitle, .labelValue {
-fx-font-size: 14px;
}
#saveConfButton {
-jfx-button-type: RAISED;
}
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