Fix for jira issue IOT-1087.
authorHarish Kumara Marappa <h.marappa@samsung.com>
Thu, 21 Apr 2016 16:46:39 +0000 (22:16 +0530)
committerMadan Lanka <lanka.madan@samsung.com>
Thu, 12 May 2016 06:50:41 +0000 (06:50 +0000)
Resource was creating with oic.if.def which is not defined in OIC spec.
Modified the code such that all simulated resource will be having at least
oic.if.baseline interface at any point of time as per 1.0.0 core spec.

Change-Id: I07c6e4513546d1d4be9c0584408801552c5f4ce4
Signed-off-by: Harish Kumara Marappa <h.marappa@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/7877
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: Madan Lanka <lanka.madan@samsung.com>
Reviewed-by: Uze Choi <uzchoi@samsung.com>
Tested-by: Uze Choi <uzchoi@samsung.com>
(cherry picked from commit 3cd3700407657c96d02534f6e6be6c2398b97c68)
Reviewed-on: https://gerrit.iotivity.org/gerrit/8047

service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/manager/ResourceManager.java
service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/utils/Utility.java
service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/MetaPropertiesView.java
service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/dialogs/UpdateResourceInterfaceDialog.java
service/simulator/src/server/oc_interface_details.cpp
service/simulator/src/server/simulator_single_resource_impl.cpp

index dc11654..44fc3ee 100644 (file)
@@ -590,12 +590,21 @@ public class ResourceManager {
             }
 
             // Set the resource interfaces.
-            jSimulatorSingleResource
-                    .setInterface(Utility.convertSetToVectorString(resource
-                            .getResourceInterfaces()));
+            Set<String> interfaces = resource.getResourceInterfaces();
+            if (null != interfaces && !interfaces.isEmpty()) {
+                jSimulatorSingleResource.setInterface(Utility
+                        .convertSetToVectorString(resource
+                                .getResourceInterfaces()));
+            }
 
             // Register the resource with the platform.
             jSimulatorSingleResource.start();
+
+            // Read the interfaces from the native layer and set it to the
+            // interface list.
+            resource.setResourceInterfaces(Utility
+                    .convertVectorToSet(jSimulatorSingleResource.getInterface()));
+
             resource.setStarted(true);
         } catch (SimulatorException e) {
             Activator
index a662874..dcf10e4 100644 (file)
@@ -577,7 +577,6 @@ public class Utility {
         Map<String, String> ifTypes = null;
         if (resourceClass == SingleResource.class) {
             ifTypes = new HashMap<String, String>();
-            ifTypes.put(Constants.BASELINE_INTERFACE, "Baseline");
             ifTypes.put(Constants.READ_ONLY_INTERFACE, "Read-Only");
             ifTypes.put(Constants.READ_WRITE_INTERFACE, "Read-Write");
             ifTypes.put(Constants.ACTUATOR_INTERFACE, "Actuator");
index d5fd2d6..b362e2e 100644 (file)
@@ -223,6 +223,8 @@ public class MetaPropertiesView extends ViewPart {
                         // interface set.
                         Set<String> curIfSet = resourceInSelection
                                 .getResourceInterfaces();
+                        // Adding default interface to local set if removed.
+                        updatedIfSet.add(Constants.BASELINE_INTERFACE);
                         if (null != curIfSet && null != updatedIfSet) {
                             if (curIfSet.size() != updatedIfSet.size()) {
                                 update = true;
@@ -506,7 +508,13 @@ public class MetaPropertiesView extends ViewPart {
                             }
                             // Update the model
                             MetaProperty prop = (MetaProperty) element;
-                            prop.setPropValue(newPropValue.toString());
+                            StringBuilder value = new StringBuilder();
+                            value.append(Constants.BASELINE_INTERFACE);
+                            if (newPropValue.length() > 0) {
+                                value.append(", " + newPropValue.toString());
+                            }
+                            prop.setPropValue(value.toString());
+
                             // Update the viewer in a separate UI thread.
                             Display.getDefault().asyncExec(new Runnable() {
                                 @Override
index 4fe07b5..09a4007 100644 (file)
@@ -17,7 +17,6 @@
 package oic.simulator.serviceprovider.view.dialogs;
 
 import org.eclipse.jface.dialogs.IDialogConstants;
-import org.eclipse.jface.dialogs.MessageDialog;
 import org.eclipse.jface.dialogs.TrayDialog;
 import org.eclipse.jface.window.Window;
 import org.eclipse.swt.SWT;
@@ -36,8 +35,6 @@ import org.eclipse.swt.widgets.Shell;
 import java.util.ArrayList;
 import java.util.Map;
 
-import oic.simulator.serviceprovider.utils.Constants;
-
 /**
  * Dialog for starting and stopping the automatic verifications.
  */
@@ -197,23 +194,15 @@ public class UpdateResourceInterfaceDialog extends TrayDialog {
 
     @Override
     protected void okPressed() {
-        String[] items = ifTypesList.getItems();
-        if (null == items || items.length == 0) {
-            MessageDialog
-                    .openInformation(
-                            getShell(),
-                            "Default Interface Type Selection",
-                            "As no interface types are added, the resource will be "
-                                    + "configured with the default interface type(oic.if.baseline).");
-            ifTypesList.add("Baseline" + " ("
-                    + Constants.DEFAULT_SINGLE_RESOURCE_INTERFACE + ")");
-        }
-
         // Clearing the map to freshly add selected items.
         updatedResInterfaces.clear();
-        for (String item : ifTypesList.getItems()) {
-            String value = supportedResInterfaces.get(item);
-            updatedResInterfaces.put(item, value);
+
+        String[] items = ifTypesList.getItems();
+        if (null != items && items.length > 0) {
+            for (String item : items) {
+                String value = supportedResInterfaces.get(item);
+                updatedResInterfaces.put(item, value);
+            }
         }
         close();
     }
index b32f1f6..96f1599 100644 (file)
@@ -39,7 +39,7 @@ bool OCInterfaceDetails::isInterface(const std::string &interfaceType)
 {
     if (m_interfaces.end() != m_interfaces.find(interfaceType))
         return true;
-    return true;
+    return false;
 }
 
 bool OCInterfaceDetails::isRequestSupported(const std::string &interfaceType,
index 5cc5c87..2539d22 100755 (executable)
@@ -79,6 +79,12 @@ void SimulatorSingleResourceImpl::setInterface(const std::string &interfaceType)
 {
     VALIDATE_INPUT(interfaceType.empty(), "Interface type list is empty!")
 
+    if (false == OCInterfaceDetails::getInstance()->isInterface(interfaceType))
+    {
+        OIC_LOG(ERROR, TAG, "Request is not OIC spec defined!");
+        return;
+    }
+
     std::lock_guard<std::recursive_mutex> lock(m_objectLock);
     if (m_resourceHandle)
     {
@@ -86,7 +92,8 @@ void SimulatorSingleResourceImpl::setInterface(const std::string &interfaceType)
                                  "Resource interface can not be reset when resource is started!");
     }
 
-    m_interfaces = {interfaceType};
+    if (interfaceType != OC::DEFAULT_INTERFACE)
+        m_interfaces = {OC::DEFAULT_INTERFACE, interfaceType};
 }
 
 void SimulatorSingleResourceImpl::setInterface(const std::vector<std::string> &interfaceTypes)
@@ -100,9 +107,12 @@ void SimulatorSingleResourceImpl::setInterface(const std::vector<std::string> &i
                                  "Resource interface can not be reset when resource is started!");
     }
 
-    m_interfaces.clear();
+    m_interfaces = {OC::DEFAULT_INTERFACE};
     for (auto &interfaceType : interfaceTypes)
     {
+        if (false == OCInterfaceDetails::getInstance()->isInterface(interfaceType))
+            continue;
+
         if (m_interfaces.end() ==
             std::find(m_interfaces.begin(), m_interfaces.end(), interfaceType))
         {
@@ -115,6 +125,12 @@ void SimulatorSingleResourceImpl::addInterface(const std::string &interfaceType)
 {
     VALIDATE_INPUT(interfaceType.empty(), "Interface type is empty!")
 
+    if (false == OCInterfaceDetails::getInstance()->isInterface(interfaceType))
+    {
+        OIC_LOG(ERROR, TAG, "Request is not OIC spec defined!");
+        return;
+    }
+
     if (m_interfaces.end() != std::find(m_interfaces.begin(), m_interfaces.end(), interfaceType))
     {
         SIM_LOG(ILogger::ERROR, "[" << m_uri << "] "