Work item 11 - Complete JSON Objects w/ Arrays

parent 02853631
......@@ -39,6 +39,7 @@ public class SerializableResource implements Serializable {
private List<String> types;
private List<String> interfaces;
Map<String, Object> properties = new HashMap<>();
Map<String, Boolean> propertiesAccess = new HashMap<>();
private boolean observing = false;
private boolean observable = true;
......@@ -99,6 +100,9 @@ public class SerializableResource implements Serializable {
case OC_REP_BOOL:
properties.put(ocRepresentation.getName(), ocRepresentation.getValue().getBool());
break;
case OC_REP_BOOL_ARRAY:
properties.put(ocRepresentation.getName(), OCRep.ocArrayToBooleanArray(ocRepresentation.getValue().getArray()));
break;
case OC_REP_STRING:
properties.put(ocRepresentation.getName(), ocRepresentation.getValue().getString());
break;
......@@ -125,6 +129,16 @@ public class SerializableResource implements Serializable {
}
}
public Map<String, Boolean> getPropertiesAccess() {
return this.propertiesAccess;
}
public void setPropertiesAccess(List<DynamicUiProperty> properties) {
for (DynamicUiProperty property : properties) {
propertiesAccess.put(property.getName(), property.isReadOnly());
}
}
public boolean isObserving() {
return this.observing;
}
......
......@@ -27,6 +27,8 @@ import org.openconnectivity.otgc.data.repository.IotivityRepository;
import org.openconnectivity.otgc.domain.model.client.SerializableResource;
import org.openconnectivity.otgc.domain.model.devicelist.Device;
import java.util.Map;
import javax.inject.Inject;
import io.reactivex.Completable;
......@@ -43,4 +45,9 @@ public class PostRequestUseCase {
return iotivityRepository.getSecureEndpoint(device)
.flatMapCompletable(endpoint -> iotivityRepository.post(endpoint, resource.getUri(), device.getDeviceId(), rep, valueArray));
}
public Completable execute(Device device, SerializableResource resource, Map<String, Object> values) {
return iotivityRepository.getSecureEndpoint(device)
.flatMapCompletable(endpoint -> iotivityRepository.post(endpoint, resource.getUri(), device.getDeviceId(), values));
}
}
......@@ -77,7 +77,7 @@ public class UiFromSwaggerUseCase {
uiElement.setPath(pathEntry.getKey());
String definitionName = getSchemaTitle(pathEntry.getValue());
if (definitionName != null && !definitionName.isEmpty()) {
uiElement.setResourceTypes(getResourceTypes(jsonSwagger, definitionName));
uiElement.setResourceTypes(getResourceTypes(swagger, definitionName));
uiElement.setInterfaces(getInterfaces(swagger, definitionName));
uiElement.setProperties(getProperties(swagger, definitionName));
uiElement.setSupportedOperations(getSupportedOperations(pathEntry.getValue()));
......@@ -100,20 +100,11 @@ public class UiFromSwaggerUseCase {
return schemaTitle;
}
private List<String> getResourceTypes(JSONObject jsonSwagger, String definitionName) throws JSONException {
List<String> resourceTypes = new ArrayList<>();
private List<String> getResourceTypes(Swagger swagger, String definitionName) {
ArrayProperty interfaces = (ArrayProperty) swagger.getDefinitions().get(definitionName).getProperties().get("rt");
StringProperty rtItems = (StringProperty) interfaces.getItems();
JSONArray jsonRt = jsonSwagger.getJSONObject("definitions")
.getJSONObject(definitionName)
.getJSONObject("properties")
.getJSONObject("rt")
.getJSONArray("default");
for (int i = 0; i < jsonRt.length(); i++) {
resourceTypes.add(jsonRt.getString(i));
}
return resourceTypes;
return rtItems.getEnum();
}
private List<String> getInterfaces(Swagger swagger, String definitionName) {
......
......@@ -217,6 +217,7 @@ public class GenericClientActivity extends AppCompatActivity implements HasSuppo
for (DynamicUiElement uiElement : uiElements) {
SerializableResource resource = new SerializableResource();
resource.setUri(uiElement.getPath());
resource.setPropertiesAccess(uiElement.getProperties());
resource.setResourceTypes(uiElement.getResourceTypes());
resource.setResourceInterfaces(uiElement.getInterfaces());
......
......@@ -39,6 +39,8 @@ import org.openconnectivity.otgc.utils.viewmodel.ViewModelErrorType;
import org.openconnectivity.otgc.utils.rx.SchedulersFacade;
import org.openconnectivity.otgc.domain.model.devicelist.Device;
import java.util.Map;
import javax.inject.Inject;
import io.reactivex.disposables.CompositeDisposable;
......@@ -159,7 +161,23 @@ public class ResourceViewModel extends ViewModel {
.observeOn(mSchedulersFacade.ui())
.subscribe(
() -> {},//mResponse::setValue,
throwable -> mError.setValue(new ViewModelError(Error.POST, null))
throwable -> {
mError.setValue(new ViewModelError(Error.POST, null));
mResponse.setValue(resource);
}
));
}
public void postRequest(Device device, SerializableResource resource, Map<String, Object> values) {
disposables.add(mPostRequestUseCase.execute(device, resource, values)
.subscribeOn(mSchedulersFacade.io())
.observeOn(mSchedulersFacade.ui())
.subscribe(
() -> {},//mResponse::setValue,
throwable -> {
mError.setValue(new ViewModelError(Error.POST, null));
mResponse.setValue(resource);
}
));
}
......
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