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 dc1165431f5e3f4b6d1f89b10d34f129c21c2c69..44fc3eedc088764f4d08bfaf2357fc417578ebff 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 a6628745c281bd373f5947f18a684168f668c9eb..dcf10e4189488ac321a9f13aeb37aa1993f7a39b 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 d5fd2d67a585ffafa8797848f5db7f77be73259a..b362e2e0b9001e7545e9bab3775f8f49e737fad5 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 4fe07b558d993bbf648052f99fcd230d099dd7b2..09a40073ae19afd37a8143489097a1a87095d75c 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 b32f1f69d10c1720508e8fe7600e6f3505bce01a..96f1599fca648e8dc7ee83eea33c2d9379d5d444 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 5cc5c87f7bf5c7cd8d9a4795c63be27832b9fcc3..2539d2289b19089cd140c28229d63afd99c84638 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 << "] "