Resolved issues and concerns found during overall functionality testing.
authorG S Senthil Kumar <senthil.gs@samsung.com>
Thu, 3 Mar 2016 20:24:50 +0000 (01:54 +0530)
committerMadan Lanka <lanka.madan@samsung.com>
Mon, 7 Mar 2016 06:36:06 +0000 (06:36 +0000)
1. Handled the array type value validation.
2. Handled the redundant resource discovery callbacks.
3. Added more information in UI to show the array properties
   when updating array type values.
4. Added more log messages.

Change-Id: I95bf65ad4bd7b9cfcfe02141832b281065bd0f99
Signed-off-by: G S Senthil Kumar <senthil.gs@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/5373
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: Madan Lanka <lanka.madan@samsung.com>
13 files changed:
service/simulator/java/eclipse-plugin/ClientControllerPlugin/src/oic/simulator/clientcontroller/manager/ResourceManager.java
service/simulator/java/eclipse-plugin/ClientControllerPlugin/src/oic/simulator/clientcontroller/utils/AttributeValueBuilder.java
service/simulator/java/eclipse-plugin/ClientControllerPlugin/src/oic/simulator/clientcontroller/view/AttributeView.java
service/simulator/java/eclipse-plugin/ClientControllerPlugin/src/oic/simulator/clientcontroller/view/dialogs/PostRequestDialog.java
service/simulator/java/eclipse-plugin/ClientControllerPlugin/src/oic/simulator/clientcontroller/view/dialogs/PutRequestDialog.java
service/simulator/java/eclipse-plugin/ClientControllerPlugin/src/oic/simulator/clientcontroller/view/dialogs/UpdatePrimitiveArrayAttributeDialog.java
service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/manager/ResourceManager.java
service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/utils/AttributeValueBuilder.java
service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/utils/Constants.java
service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/AttributeView.java
service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/ResourceManagerView.java
service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/dialogs/CreateResourceWizard.java
service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/dialogs/UpdatePrimitiveArrayAttributeDialog.java

index 4f510ab6fc92ed1e95544ff34fb3684824bf57e5..03d8d3588b9904713a2d278cbe56b65a416bb93a 100644 (file)
@@ -141,23 +141,30 @@ public class ResourceManager {
                         // If resource already exist, then ignore it.
                         boolean exist = isUidExist(uid);
                         if (exist) {
+                            handleExistingResource(resourceN);
                             return;
                         }
 
                         RemoteResource resource = new RemoteResource();
                         resource.setRemoteResourceRef(resourceN);
 
+                        boolean observeRequestSent = false;
+
                         String uri = resourceN.getURI();
                         if (null != uri && uri.trim().length() > 0) {
                             // Add resource to favorite list if it was in
                             // favorites list during find/refresh operation.
-                            if (favoriteURIList.contains(uri)) {
-                                addResourcetoFavorites(resource);
-                            }
-                            // Add resource to observed resources list if it was
-                            // in observe list during find/refresh operation.
-                            if (observedResourceURIList.contains(uri)) {
-                                sendObserveRequest(resource);
+                            synchronized (favoriteURIList) {
+                                if (favoriteURIList.contains(uri)) {
+                                    addResourcetoFavorites(resource);
+                                }
+                            } // Add resource to observed resources list if it
+                              // was
+                              // in observe list during find/refresh operation.
+                            synchronized (observedResourceURIList) {
+                                if (observedResourceURIList.contains(uri)) {
+                                    observeRequestSent = sendObserveRequest(resource);
+                                }
                             }
                         } else {
                             Activator
@@ -183,25 +190,29 @@ public class ResourceManager {
                                         "Resource Found [" + resourceN.getURI()
                                                 + "].");
 
-                        // Send an initial GET request to get the resource
+                        // Send an initial GET request(If observe request has
+                        // not been sent already) to get the resource
                         // attributes on an interface supported by the resource.
-                        try {
-                            String ifType = null;
-                            Vector<String> resInterfaces = resourceN
-                                    .getResourceInterfaces();
-                            if (null != resInterfaces) {
-                                ifType = resInterfaces.get(0);
+                        if (!observeRequestSent) {
+                            try {
+                                String ifType = null;
+                                Vector<String> resInterfaces = resourceN
+                                        .getResourceInterfaces();
+                                if (null != resInterfaces) {
+                                    ifType = resInterfaces.get(0);
+                                }
+                                resourceN.get(
+                                        formQueryParameters(ifType, null),
+                                        getListener);
+                            } catch (SimulatorException e) {
+                                Activator
+                                        .getDefault()
+                                        .getLogManager()
+                                        .log(Level.ERROR.ordinal(),
+                                                new Date(),
+                                                Utility.getSimulatorErrorString(
+                                                        e, null));
                             }
-                            resourceN.get(formQueryParameters(ifType, null),
-                                    getListener);
-                        } catch (SimulatorException e) {
-                            Activator
-                                    .getDefault()
-                                    .getLogManager()
-                                    .log(Level.ERROR.ordinal(),
-                                            new Date(),
-                                            Utility.getSimulatorErrorString(e,
-                                                    null));
                         }
 
                         // Get the device information
@@ -504,6 +515,154 @@ public class ResourceManager {
         threadHandle.start();
     }
 
+    private void handleExistingResource(
+            final SimulatorRemoteResource newNativeResourceRef) {
+        if (null == newNativeResourceRef) {
+            return;
+        }
+
+        RemoteResource existingResource = getResource(newNativeResourceRef
+                .getId());
+        if (null == existingResource) {
+            return;
+        }
+
+        SimulatorRemoteResource existingNativeResourceRef = existingResource
+                .getRemoteResourceRef();
+        if (null == existingNativeResourceRef) {
+            return;
+        }
+
+        // Compare the resource properties(resource types, interface types and
+        // observable)
+        // of the received resource with the existing resource.
+        // If there is a change, then replace the existing resource properties
+        // and send
+        // a GET request to receive the latest resource representation.
+        boolean change = compareResourceProperties(existingNativeResourceRef,
+                newNativeResourceRef);
+        if (!change) {
+            return;
+        }
+
+        existingResource.setRemoteResourceRef(newNativeResourceRef);
+
+        try {
+            String ifType = null;
+            Vector<String> resInterfaces = newNativeResourceRef
+                    .getResourceInterfaces();
+            if (null != resInterfaces) {
+                ifType = resInterfaces.get(0);
+            }
+            newNativeResourceRef.get(formQueryParameters(ifType, null),
+                    getListener);
+        } catch (SimulatorException e) {
+            Activator
+                    .getDefault()
+                    .getLogManager()
+                    .log(Level.ERROR.ordinal(), new Date(),
+                            Utility.getSimulatorErrorString(e, null));
+        }
+
+        // Notify the UI listener which may be looking for this callback for
+        // further processing.
+        UiListenerHandler.getInstance().newResourceFoundNotification(
+                existingResource);
+
+        // Notify the UI listeners by re-selecting the same resource.
+        // This is just to refresh the resource properties being shown.
+        RemoteResource resourceInSelection = getCurrentResourceInSelection();
+        if (null != resourceInSelection) {
+            if (resourceInSelection.getRemoteResourceRef().getURI()
+                    .equals(newNativeResourceRef.getURI())) {
+                UiListenerHandler.getInstance()
+                        .resourceSelectionChangedUINotification(
+                                existingResource);
+            }
+        }
+    }
+
+    private boolean compareResourceProperties(
+            SimulatorRemoteResource existingNativeResourceRef,
+            SimulatorRemoteResource newNativeResourceRef) {
+        boolean change = false;
+
+        try {
+            // Compare URI.
+            if (!existingNativeResourceRef.getURI().equals(
+                    existingNativeResourceRef.getURI())) {
+                change = true;
+            }
+
+            // Compare ID.
+            if (!change
+                    && !existingNativeResourceRef.getId().equals(
+                            existingNativeResourceRef.getId())) {
+                change = true;
+            }
+
+            // Compare Host.
+            if (!change
+                    && !existingNativeResourceRef.getHost().equals(
+                            existingNativeResourceRef.getHost())) {
+                change = true;
+            }
+
+            // Compare Observable flag.
+            if (!change
+                    && existingNativeResourceRef.isObservable() != existingNativeResourceRef
+                            .isObservable()) {
+                change = true;
+            }
+
+            // Compare Resource Types.
+            Vector<String> existingResTypes = existingNativeResourceRef
+                    .getResourceTypes();
+            Vector<String> newResTypes = newNativeResourceRef
+                    .getResourceTypes();
+
+            if (!change) {
+                if (existingResTypes.size() != newResTypes.size()) {
+                    change = true;
+                } else {
+                    // Compare both lists.
+                    Iterator<String> itr = existingResTypes.iterator();
+                    while (itr.hasNext()) {
+                        if (!newResTypes.contains(itr.next())) {
+                            change = true;
+                            break;
+                        }
+                    }
+                }
+            }
+
+            // Compare Interface Types.
+            Vector<String> existingInterfaceTypes = existingNativeResourceRef
+                    .getResourceInterfaces();
+            Vector<String> newInterfaceTypes = newNativeResourceRef
+                    .getResourceInterfaces();
+
+            if (!change) {
+                if (existingInterfaceTypes.size() != newInterfaceTypes.size()) {
+                    change = true;
+                } else {
+                    // Compare both lists.
+                    Iterator<String> itr = existingInterfaceTypes.iterator();
+                    while (itr.hasNext()) {
+                        if (!newInterfaceTypes.contains(itr.next())) {
+                            change = true;
+                            break;
+                        }
+                    }
+                }
+            }
+        } catch (Exception e) {
+            change = true;
+        }
+
+        return change;
+    }
+
     private RemoteResource handleResponse(String uid,
             SimulatorResourceModel resourceModelN) {
         if (null == uid || null == resourceModelN) {
@@ -742,10 +901,15 @@ public class ResourceManager {
                         }
                         // Delete all cached details of resources
                         resourceMap.clear();
-                        favoriteResources.clear();
+
+                        synchronized (favoriteResources) {
+                            favoriteResources.clear();
+                        }
 
                         // Clearing the device and platform information
-                        hostDeviceAndPlatformMap.clear();
+                        synchronized (hostDeviceAndPlatformMap) {
+                            hostDeviceAndPlatformMap.clear();
+                        }
                     }
                     // Change the current resource in selection
                     setCurrentResourceInSelection(null);
@@ -908,11 +1072,12 @@ public class ResourceManager {
     }
 
     public List<MetaProperty> getDeviceProperties() {
-        if (null == currentResourceInSelection) {
+        RemoteResource resourceInSelection = getCurrentResourceInSelection();
+        if (null == resourceInSelection) {
             return null;
         }
 
-        SimulatorRemoteResource remoteResource = currentResourceInSelection
+        SimulatorRemoteResource remoteResource = resourceInSelection
                 .getRemoteResourceRef();
         if (null == remoteResource) {
             return null;
@@ -955,11 +1120,12 @@ public class ResourceManager {
     }
 
     public List<MetaProperty> getPlatformProperties() {
-        if (null == currentResourceInSelection) {
+        RemoteResource resourceInSelection = getCurrentResourceInSelection();
+        if (null == resourceInSelection) {
             return null;
         }
 
-        SimulatorRemoteResource remoteResource = currentResourceInSelection
+        SimulatorRemoteResource remoteResource = resourceInSelection
                 .getRemoteResourceRef();
         if (null == remoteResource) {
             return null;
index b12c0a74252130c76a288d1fe61488fb7a64880f..221f1d42abc863129b262013bde4955a29e5de43 100644 (file)
@@ -127,36 +127,67 @@ public class AttributeValueBuilder {
             return null;
 
         if (valueType == AttributeValue.ValueType.INTEGER) {
+            if (1 == valuesString.length && valuesString[0].isEmpty()) {
+                return new AttributeValue(new Integer[0]);
+            }
+
             Integer[] result = new Integer[valuesString.length];
             for (int index = 0; index < valuesString.length; index++) {
-                Integer value = (Integer) handleDepth0(valuesString[index],
-                        valueType).get();
-                if (null == value)
-                    return null;
-                result[index] = value;
+                if (null != valuesString[index]
+                        && !valuesString[index].isEmpty()) {
+                    Integer value = (Integer) handleDepth0(valuesString[index],
+                            valueType).get();
+                    if (null == value)
+                        return null;
+                    result[index] = value;
+                }
             }
             return new AttributeValue(result);
         } else if (valueType == AttributeValue.ValueType.DOUBLE) {
+            if (1 == valuesString.length && valuesString[0].isEmpty()) {
+                return new AttributeValue(new Double[0]);
+            }
+
             Double[] result = new Double[valuesString.length];
             for (int index = 0; index < valuesString.length; index++) {
-                Double value = (Double) handleDepth0(valuesString[index],
-                        valueType).get();
-                if (null == value)
-                    return null;
-                result[index] = value;
+                if (null != valuesString[index]
+                        && !valuesString[index].isEmpty()) {
+                    Double value = (Double) handleDepth0(valuesString[index],
+                            valueType).get();
+                    if (null == value)
+                        return null;
+                    result[index] = value;
+                }
             }
             return new AttributeValue(result);
         } else if (valueType == AttributeValue.ValueType.BOOLEAN) {
+            if (1 == valuesString.length && valuesString[0].isEmpty()) {
+                return new AttributeValue(new Boolean[0]);
+            }
+
             Boolean[] result = new Boolean[valuesString.length];
             for (int index = 0; index < valuesString.length; index++) {
-                Boolean value = (Boolean) handleDepth0(valuesString[index],
-                        valueType).get();
-                if (null == value)
-                    return null;
-                result[index] = value;
+                if (null != valuesString[index]
+                        && !valuesString[index].isEmpty()) {
+                    Boolean value = (Boolean) handleDepth0(valuesString[index],
+                            valueType).get();
+                    if (null == value)
+                        return null;
+                    result[index] = value;
+                }
             }
             return new AttributeValue(result);
         } else if (valueType == AttributeValue.ValueType.STRING) {
+            if (1 == valuesString.length && valuesString[0].isEmpty()) {
+                return new AttributeValue(new String[0]);
+            }
+
+            for (int index = 0; index < valuesString.length; index++) {
+                if (null != valuesString[index]
+                        && !valuesString[index].isEmpty()) {
+                    valuesString[index] = valuesString[index].trim();
+                }
+            }
             return new AttributeValue(valuesString);
         }
 
index ed5c83bf198f3bda6415b9222c406a9c599442fc..c36c0f8d4cb9a9b5f7156dc655fa83b20324308f 100644 (file)
@@ -259,7 +259,7 @@ public class AttributeView extends ViewPart {
                                         new Date(),
                                         "["
                                                 + reqType.toString()
-                                                + "] Verification Completed for \""
+                                                + "] Verification is successful for \""
                                                 + remoteResource.getURI()
                                                 + "\".");
                     }
@@ -290,7 +290,7 @@ public class AttributeView extends ViewPart {
                                         new Date(),
                                         "["
                                                 + reqType
-                                                + "] Verification Aborted for \""
+                                                + "] Verification is failed for \""
                                                 + remoteResource.getURI()
                                                 + "\".");
                     }
@@ -698,11 +698,7 @@ public class AttributeView extends ViewPart {
                                     }
                                 }
                             }
-                            if (startCount == 0 && stopCount == 0) {
-                                MessageDialog.openInformation(Display
-                                        .getDefault().getActiveShell(),
-                                        "Verification", "No New Changes.");
-                            } else {
+                            if (!(startCount == 0 && stopCount == 0)) {
                                 boolean answer = MessageDialog.openQuestion(
                                         Display.getDefault().getActiveShell(),
                                         "Verification", status
index 47eed95f37279048c8403396e64b92766e44696c..f8269b55d79ca8d59d92e94e806481874e21ac50 100644 (file)
@@ -113,10 +113,19 @@ public class PostRequestDialog extends TitleAreaDialog {
     protected Control createDialogArea(Composite parent) {
         Composite compLayout = (Composite) super.createDialogArea(parent);
 
-        Group paramsGrp = new Group(compLayout, SWT.NONE);
+        Composite rootContainer = new Composite(compLayout, SWT.NONE);
+        GridLayout layout = new GridLayout();
+        rootContainer.setLayout(layout);
         GridData gd = new GridData(SWT.FILL, SWT.FILL, true, true);
+        rootContainer.setLayoutData(gd);
+
+        Group paramsGrp = new Group(rootContainer, SWT.NONE);
+        gd = new GridData();
+        gd.horizontalAlignment = SWT.FILL;
+        gd.grabExcessHorizontalSpace = true;
+        gd.minimumHeight = 50;
         paramsGrp.setLayoutData(gd);
-        GridLayout layout = new GridLayout(2, false);
+        layout = new GridLayout(2, false);
         layout.verticalSpacing = 10;
         layout.marginTop = 10;
         paramsGrp.setLayout(layout);
@@ -187,7 +196,7 @@ public class PostRequestDialog extends TitleAreaDialog {
             }
         }
 
-        Composite container = new Composite(compLayout, SWT.NONE);
+        Composite container = new Composite(rootContainer, SWT.NONE);
         container.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
         layout = new GridLayout(1, false);
         layout.verticalSpacing = 10;
index 04a1f177aeec97b406acee0d7ad35506d79c4d1b..cd99ffcf057e9b562432560dc44f1443f80f59dc 100644 (file)
@@ -112,9 +112,19 @@ public class PutRequestDialog extends TitleAreaDialog {
     protected Control createDialogArea(Composite parent) {
         Composite compLayout = (Composite) super.createDialogArea(parent);
 
-        Group paramsGrp = new Group(compLayout, SWT.NONE);
-        paramsGrp.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
-        GridLayout layout = new GridLayout(2, false);
+        Composite rootContainer = new Composite(compLayout, SWT.NONE);
+        GridLayout layout = new GridLayout();
+        rootContainer.setLayout(layout);
+        GridData gd = new GridData(SWT.FILL, SWT.FILL, true, true);
+        rootContainer.setLayoutData(gd);
+
+        Group paramsGrp = new Group(rootContainer, SWT.NONE);
+        gd = new GridData();
+        gd.horizontalAlignment = SWT.FILL;
+        gd.grabExcessHorizontalSpace = true;
+        gd.minimumHeight = 50;
+        paramsGrp.setLayoutData(gd);
+        layout = new GridLayout(2, false);
         layout.verticalSpacing = 10;
         layout.marginTop = 10;
         paramsGrp.setLayout(layout);
@@ -123,7 +133,7 @@ public class PutRequestDialog extends TitleAreaDialog {
         ifTypeLbl.setText("Interface Type");
 
         ifTypesCmb = new Combo(paramsGrp, SWT.NULL);
-        GridData gd = new GridData();
+        gd = new GridData();
         gd.grabExcessHorizontalSpace = true;
         gd.horizontalAlignment = SWT.FILL;
         ifTypesCmb.setLayoutData(gd);
@@ -185,8 +195,9 @@ public class PutRequestDialog extends TitleAreaDialog {
             }
         }
 
-        Composite container = new Composite(compLayout, SWT.NONE);
-        container.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
+        Composite container = new Composite(rootContainer, SWT.NONE);
+        gd = new GridData(SWT.FILL, SWT.FILL, true, true);
+        container.setLayoutData(gd);
         layout = new GridLayout(1, false);
         layout.verticalSpacing = 10;
         layout.marginTop = 10;
@@ -241,7 +252,8 @@ public class PutRequestDialog extends TitleAreaDialog {
 
         // make lines and header visible
         Tree tree = attViewer.getTree();
-        tree.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
+        GridData gd = new GridData(SWT.FILL, SWT.FILL, true, true);
+        tree.setLayoutData(gd);
         tree.setHeaderVisible(true);
         tree.setLinesVisible(true);
 
index 1df6e5a0176a1ac0d2a873085f999f7e8667763d..5224b8780a701ca27b9aa60de3736f1f8332e7e0 100644 (file)
@@ -23,6 +23,7 @@ import org.eclipse.swt.layout.GridLayout;
 import org.eclipse.swt.widgets.Composite;
 import org.eclipse.swt.widgets.Control;
 import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Group;
 import org.eclipse.swt.widgets.Label;
 import org.eclipse.swt.widgets.MessageBox;
 import org.eclipse.swt.widgets.Shell;
@@ -50,6 +51,10 @@ public class UpdatePrimitiveArrayAttributeDialog extends TitleAreaDialog {
     private Text                       currentValueTxt;
     private Text                       newValueTxt;
     private Text                       allowedValuesTxt;
+    private Text                       minRangeTxt;
+    private Text                       maxRangeTxt;
+    private Text                       allowDuplicatesTxt;
+    private Text                       additionalItemsTxt;
     private SimulatorResourceAttribute attribute;
     private String                     newValue;
 
@@ -91,10 +96,104 @@ public class UpdatePrimitiveArrayAttributeDialog extends TitleAreaDialog {
         gd.horizontalAlignment = SWT.FILL;
         attNameTxt.setLayoutData(gd);
 
-        Label allowedValuesLbl = new Label(container, SWT.NONE);
+        Group subGroup = new Group(container, SWT.NONE);
+        subGroup.setText("Array Properties");
+        layout = new GridLayout(2, true);
+        subGroup.setLayout(layout);
+        gd = new GridData();
+        gd.grabExcessHorizontalSpace = true;
+        gd.horizontalAlignment = SWT.FILL;
+        gd.horizontalSpan = 2;
+        subGroup.setLayoutData(gd);
+
+        Composite minRangeContainer = new Composite(subGroup, SWT.NONE);
+        gd = new GridData();
+        gd.grabExcessHorizontalSpace = true;
+        gd.horizontalAlignment = SWT.FILL;
+        minRangeContainer.setLayoutData(gd);
+        layout = new GridLayout(2, true);
+        minRangeContainer.setLayout(layout);
+
+        Label minRangeLbl = new Label(minRangeContainer, SWT.NONE);
+        minRangeLbl.setText("Minimum Items");
+
+        minRangeTxt = new Text(minRangeContainer, SWT.BORDER | SWT.READ_ONLY);
+        gd = new GridData();
+        gd.grabExcessHorizontalSpace = true;
+        gd.horizontalAlignment = SWT.FILL;
+        minRangeTxt.setLayoutData(gd);
+        minRangeTxt.setBackground(container.getBackground());
+
+        Composite maxRangeContainer = new Composite(subGroup, SWT.NONE);
+        gd = new GridData();
+        gd.grabExcessHorizontalSpace = true;
+        gd.horizontalAlignment = SWT.FILL;
+        maxRangeContainer.setLayoutData(gd);
+        layout = new GridLayout(2, true);
+        maxRangeContainer.setLayout(layout);
+
+        Label maxRangeLbl = new Label(maxRangeContainer, SWT.NONE);
+        maxRangeLbl.setText("Maximum Items");
+
+        maxRangeTxt = new Text(maxRangeContainer, SWT.BORDER | SWT.READ_ONLY);
+        gd = new GridData();
+        gd.grabExcessHorizontalSpace = true;
+        gd.horizontalAlignment = SWT.FILL;
+        maxRangeTxt.setLayoutData(gd);
+        maxRangeTxt.setBackground(container.getBackground());
+
+        Composite uniqueContainer = new Composite(subGroup, SWT.NONE);
+        gd = new GridData();
+        gd.grabExcessHorizontalSpace = true;
+        gd.horizontalAlignment = SWT.FILL;
+        uniqueContainer.setLayoutData(gd);
+        layout = new GridLayout(2, true);
+        uniqueContainer.setLayout(layout);
+
+        Label uniqueLbl = new Label(uniqueContainer, SWT.NONE);
+        uniqueLbl.setText("Allow Duplicates");
+
+        allowDuplicatesTxt = new Text(uniqueContainer, SWT.BORDER
+                | SWT.READ_ONLY);
+        gd = new GridData();
+        gd.grabExcessHorizontalSpace = true;
+        gd.horizontalAlignment = SWT.FILL;
+        allowDuplicatesTxt.setLayoutData(gd);
+        allowDuplicatesTxt.setBackground(container.getBackground());
+
+        Composite addlItemsContainer = new Composite(subGroup, SWT.NONE);
+        gd = new GridData();
+        gd.grabExcessHorizontalSpace = true;
+        gd.horizontalAlignment = SWT.FILL;
+        addlItemsContainer.setLayoutData(gd);
+        layout = new GridLayout(2, true);
+        addlItemsContainer.setLayout(layout);
+
+        Label addlItemsLbl = new Label(addlItemsContainer, SWT.NONE);
+        addlItemsLbl.setText("Allow Extra Items");
+
+        additionalItemsTxt = new Text(addlItemsContainer, SWT.BORDER
+                | SWT.READ_ONLY);
+        gd = new GridData();
+        gd.grabExcessHorizontalSpace = true;
+        gd.horizontalAlignment = SWT.FILL;
+        additionalItemsTxt.setLayoutData(gd);
+        additionalItemsTxt.setBackground(container.getBackground());
+
+        Group elementPropGroup = new Group(container, SWT.NONE);
+        elementPropGroup.setText("Element Property");
+        layout = new GridLayout(2, false);
+        elementPropGroup.setLayout(layout);
+        gd = new GridData();
+        gd.grabExcessHorizontalSpace = true;
+        gd.horizontalAlignment = SWT.FILL;
+        gd.horizontalSpan = 2;
+        elementPropGroup.setLayoutData(gd);
+
+        Label allowedValuesLbl = new Label(elementPropGroup, SWT.NONE);
         allowedValuesLbl.setText("Allowed Values");
 
-        allowedValuesTxt = new Text(container, SWT.MULTI | SWT.READ_ONLY
+        allowedValuesTxt = new Text(elementPropGroup, SWT.MULTI | SWT.READ_ONLY
                 | SWT.BORDER | SWT.WRAP | SWT.V_SCROLL);
         allowedValuesTxt.setBackground(container.getBackground());
         gd = new GridData();
@@ -133,15 +232,17 @@ public class UpdatePrimitiveArrayAttributeDialog extends TitleAreaDialog {
         newValueTxt.setLayoutData(gd);
         newValueTxt.setFocus();
 
-        Label hintHeader = new Label(container, SWT.NULL);
-        hintHeader.setText("Note:-");
+        Group hintGroup = new Group(container, SWT.NONE);
+        hintGroup.setText("Note");
+        layout = new GridLayout();
+        hintGroup.setLayout(layout);
         gd = new GridData();
         gd.grabExcessHorizontalSpace = true;
         gd.horizontalAlignment = SWT.FILL;
         gd.horizontalSpan = 2;
-        hintHeader.setLayoutData(gd);
+        hintGroup.setLayoutData(gd);
 
-        Label hint = new Label(container, SWT.NULL);
+        Label hint = new Label(hintGroup, SWT.NULL);
         hint.setText("Array values should be comma-seperated and surrounded by square brackets.\n"
                 + "Ex: \"[value]\", \"[value1,value2]\", \"[[value1], [value2]]\"");
         gd = new GridData();
@@ -168,7 +269,7 @@ public class UpdatePrimitiveArrayAttributeDialog extends TitleAreaDialog {
         if (elementProp.isInteger()) {
             IntegerProperty intProp = elementProp.asInteger();
             if (intProp.hasRange()) {
-                values = "From " + intProp.min() + " To " + intProp.max();
+                values = intProp.min() + " - " + intProp.max();
             } else if (intProp.hasValues()) {
                 int[] arr = intProp.getValues();
                 for (int i = 0; i < arr.length; i++) {
@@ -185,7 +286,7 @@ public class UpdatePrimitiveArrayAttributeDialog extends TitleAreaDialog {
         } else if (elementProp.isDouble()) {
             DoubleProperty dblProp = elementProp.asDouble();
             if (dblProp.hasRange()) {
-                values = "From " + dblProp.min() + " To " + dblProp.max();
+                values = dblProp.min() + " - " + dblProp.max();
             } else if (dblProp.hasValues()) {
                 double[] arr = dblProp.getValues();
                 for (int i = 0; i < arr.length; i++) {
@@ -222,6 +323,14 @@ public class UpdatePrimitiveArrayAttributeDialog extends TitleAreaDialog {
         // Set the current value.
         currentValueTxt.setText(new AttributeValueStringConverter(attribute
                 .value()).toString());
+
+        minRangeTxt.setText(String.valueOf(arrProp.minItems()));
+
+        maxRangeTxt.setText(String.valueOf(arrProp.maxItems()));
+
+        allowDuplicatesTxt.setText(!arrProp.isUnique() ? "Yes" : "No");
+
+        additionalItemsTxt.setText(arrProp.isVariable() ? "Yes" : "No");
     }
 
     public String getNewValue() {
index 4f89a62b05f12cf4350dbebfdaf533330d1196be..1e16e091f6b74fee6d0fa35e5174dd31f5ba630a 100644 (file)
@@ -613,6 +613,12 @@ public class ResourceManager {
         UiListenerHandler.getInstance().resourceCreatedUINotification(
                 ResourceType.SINGLE);
 
+        Activator
+                .getDefault()
+                .getLogManager()
+                .log(Level.INFO.ordinal(), new Date(),
+                        "Resource created [" + resource.getResourceURI() + "].");
+
         return true;
     }
 
@@ -745,6 +751,12 @@ public class ResourceManager {
                             Utility.getSimulatorErrorString(e, null));
             throw e;
         }
+
+        Activator
+                .getDefault()
+                .getLogManager()
+                .log(Level.INFO.ordinal(), new Date(),
+                        "Resource created [" + resource.getResourceURI() + "].");
         return true;
     }
 
@@ -850,6 +862,12 @@ public class ResourceManager {
 
         // Delete this resource
         data.deleteResource(res);
+
+        Activator
+                .getDefault()
+                .getLogManager()
+                .log(Level.INFO.ordinal(), new Date(),
+                        "Resource deleted [" + res.getResourceURI() + "].");
     }
 
     public boolean isUriUnique(List<MetaProperty> properties) {
index 38ac2c39567bed89053874391fd55b3ec55b722c..421b7c1cb39b99a5e570131f98930d8f55b8035c 100644 (file)
@@ -127,36 +127,67 @@ public class AttributeValueBuilder {
             return null;
 
         if (valueType == AttributeValue.ValueType.INTEGER) {
+            if (1 == valuesString.length && valuesString[0].isEmpty()) {
+                return new AttributeValue(new Integer[0]);
+            }
+
             Integer[] result = new Integer[valuesString.length];
             for (int index = 0; index < valuesString.length; index++) {
-                Integer value = (Integer) handleDepth0(valuesString[index],
-                        valueType).get();
-                if (null == value)
-                    return null;
-                result[index] = value;
+                if (null != valuesString[index]
+                        && !valuesString[index].isEmpty()) {
+                    Integer value = (Integer) handleDepth0(valuesString[index],
+                            valueType).get();
+                    if (null == value)
+                        return null;
+                    result[index] = value;
+                }
             }
             return new AttributeValue(result);
         } else if (valueType == AttributeValue.ValueType.DOUBLE) {
+            if (1 == valuesString.length && valuesString[0].isEmpty()) {
+                return new AttributeValue(new Double[0]);
+            }
+
             Double[] result = new Double[valuesString.length];
             for (int index = 0; index < valuesString.length; index++) {
-                Double value = (Double) handleDepth0(valuesString[index],
-                        valueType).get();
-                if (null == value)
-                    return null;
-                result[index] = value;
+                if (null != valuesString[index]
+                        && !valuesString[index].isEmpty()) {
+                    Double value = (Double) handleDepth0(valuesString[index],
+                            valueType).get();
+                    if (null == value)
+                        return null;
+                    result[index] = value;
+                }
             }
             return new AttributeValue(result);
         } else if (valueType == AttributeValue.ValueType.BOOLEAN) {
+            if (1 == valuesString.length && valuesString[0].isEmpty()) {
+                return new AttributeValue(new Boolean[0]);
+            }
+
             Boolean[] result = new Boolean[valuesString.length];
             for (int index = 0; index < valuesString.length; index++) {
-                Boolean value = (Boolean) handleDepth0(valuesString[index],
-                        valueType).get();
-                if (null == value)
-                    return null;
-                result[index] = value;
+                if (null != valuesString[index]
+                        && !valuesString[index].isEmpty()) {
+                    Boolean value = (Boolean) handleDepth0(valuesString[index],
+                            valueType).get();
+                    if (null == value)
+                        return null;
+                    result[index] = value;
+                }
             }
             return new AttributeValue(result);
         } else if (valueType == AttributeValue.ValueType.STRING) {
+            if (1 == valuesString.length && valuesString[0].isEmpty()) {
+                return new AttributeValue(new String[0]);
+            }
+
+            for (int index = 0; index < valuesString.length; index++) {
+                if (null != valuesString[index]
+                        && !valuesString[index].isEmpty()) {
+                    valuesString[index] = valuesString[index].trim();
+                }
+            }
             return new AttributeValue(valuesString);
         }
 
index f8a04bf902373a142022ae5de74293f39c859237..5dcf7430de3039dcd199ebf64e74959362efb513 100644 (file)
@@ -169,6 +169,8 @@ public class Constants {
                                                                                           + "It should contain only lowercase alphabets, "
                                                                                           + "numbers(0-9), dot(.) and hyphen(-).";
 
+    public static final String         RESOURCE_LIMIT_EXCEEDED_MSG                = "A maximum of 200 resources can exist in the server.";
+
     public static final int            TREE_EXPANSION_LEVEL                       = 10;
 
     public static final String         BASELINE_INTERFACE                         = "oic.if.baseline";
index abc7189e79c386fe67d0fbbfc6635adb02722f45..538ebe8a6daa3594881447378c587234b7bc864d 100644 (file)
@@ -433,6 +433,37 @@ public class AttributeView extends ViewPart {
                                     "Unable to perform the operation.",
                                     "Failed to obtain the required data. Operation cannot be performed.");
                 } else {
+                    // Check whether a new item can be added to the array by
+                    // checking
+                    // the array property of the current attribute in
+                    // selection(Model Array type attribute).
+                    AttributeElement attElement = getSelectedElement();
+                    SimulatorResourceAttribute attribute = attElement
+                            .getSimulatorResourceAttribute();
+
+                    AttributeValue attValue = attribute.value();
+                    AttributeProperty attProperty = attribute.property();
+                    if (null != attProperty
+                            && attProperty instanceof ArrayProperty) {
+                        ArrayProperty prop = attProperty.asArray();
+                        if (null != prop && !prop.isVariable()) {
+                            SimulatorResourceModel[] model = (SimulatorResourceModel[]) attValue
+                                    .get();
+                            if (null != model
+                                    && model.length >= prop.maxItems()) {
+                                MessageDialog
+                                        .openError(
+                                                Display.getDefault()
+                                                        .getActiveShell(),
+                                                "Unable to perform the operation.",
+                                                "Exceeding the maximum number of array elements allowed for this attribute.\n"
+                                                        + "Maximum number of allowed array element(s): "
+                                                        + prop.maxItems());
+                                return;
+                            }
+                        }
+                    }
+
                     ModelArrayAddItemDialog dialog = new ModelArrayAddItemDialog(
                             Display.getDefault().getActiveShell(),
                             representation);
@@ -446,9 +477,6 @@ public class AttributeView extends ViewPart {
                         SimulatorResourceModel newModel = (SimulatorResourceModel) newAttribute
                                 .value().get();
 
-                        AttributeElement attElement = getSelectedElement();
-                        SimulatorResourceAttribute attribute = attElement
-                                .getSimulatorResourceAttribute();
                         SimulatorResourceModel[] modelArray = (SimulatorResourceModel[]) attribute
                                 .value().get();
                         SimulatorResourceModel[] newModelArray = new SimulatorResourceModel[modelArray.length + 1];
@@ -504,6 +532,33 @@ public class AttributeView extends ViewPart {
         addItems.addSelectionListener(new SelectionAdapter() {
             @Override
             public void widgetSelected(SelectionEvent e) {
+                // Check whether any existing item can be removed from the array
+                // by checking
+                // the array property of the current attribute in
+                // selection(Model Array type attribute).
+                SimulatorResourceAttribute parentSRA = parentElement
+                        .getSimulatorResourceAttribute();
+                AttributeValue value = parentSRA.value();
+                AttributeProperty attProperty = parentSRA.property();
+                if (null != attProperty && attProperty instanceof ArrayProperty) {
+                    ArrayProperty prop = attProperty.asArray();
+                    if (null != prop) {
+                        SimulatorResourceModel[] model = (SimulatorResourceModel[]) value
+                                .get();
+                        if (null != model && model.length <= prop.minItems()) {
+                            MessageDialog
+                                    .openError(
+                                            Display.getDefault()
+                                                    .getActiveShell(),
+                                            "Unable to perform the operation.",
+                                            "Violating the minimum number of array elements allowed for this attribute.\n"
+                                                    + "Minimum number of allowed array element(s): "
+                                                    + prop.minItems());
+                            return;
+                        }
+                    }
+                }
+
                 MessageBox dialog = new MessageBox(menu.getShell(),
                         SWT.ICON_QUESTION | SWT.OK | SWT.CANCEL);
                 dialog.setText("Confirm action");
@@ -514,9 +569,6 @@ public class AttributeView extends ViewPart {
                 }
 
                 // Removing the element from the attribute value.
-                SimulatorResourceAttribute parentSRA = parentElement
-                        .getSimulatorResourceAttribute();
-                AttributeValue value = parentSRA.value();
                 SimulatorResourceModel[] modelArray = (SimulatorResourceModel[]) value
                         .get();
 
index b8ed4b07b19d8881ed3f387cc8e5852e1592fb48..9a09de3fc97128796ab9e82be0c8737c081749a4 100644 (file)
@@ -402,11 +402,9 @@ public class ResourceManagerView extends ViewPart {
             @Override
             public void widgetSelected(SelectionEvent e) {
                 if (resourceManager.getResourceCount() >= Constants.MAX_RESOURCE_COUNT) {
-                    MessageDialog
-                            .openInformation(Display.getDefault()
-                                    .getActiveShell(),
-                                    "Resource limit exceeded",
-                                    "Exceeded the limit of resources that can exist in the server.");
+                    MessageDialog.openInformation(Display.getDefault()
+                            .getActiveShell(), "Resource limit exceeded",
+                            Constants.RESOURCE_LIMIT_EXCEEDED_MSG);
                     return;
                 }
                 PlatformUI.getWorkbench().getDisplay().syncExec(new Runnable() {
index 399cf6e9ad84d9b759f879dbab9f4c525a468743..a29eecc3bc9ffa0a569d2034fb3d46b0916ffab5 100644 (file)
@@ -191,10 +191,9 @@ public class CreateResourceWizard extends Wizard {
             // Handling multiple instance creation of simple resource with RAML
             if ((loadRamlPage.getResourceCount() + Activator.getDefault()
                     .getResourceManager().getResourceCount()) > Constants.MAX_RESOURCE_COUNT) {
-                MessageDialog
-                        .openInformation(Display.getDefault().getActiveShell(),
-                                "Resource limit exceeded",
-                                "Exceeded the limit of resources that can exist in the server.");
+                MessageDialog.openInformation(Display.getDefault()
+                        .getActiveShell(), "Resource limit exceeded",
+                        Constants.RESOURCE_LIMIT_EXCEEDED_MSG);
                 return false;
             }
 
index 2253b60b29113a41bf9ac8c2609e965ce3ad42f2..af2669eb4f481cbfc4d2dc265f2e2f2e9eb56524 100644 (file)
@@ -23,6 +23,7 @@ import org.eclipse.swt.layout.GridLayout;
 import org.eclipse.swt.widgets.Composite;
 import org.eclipse.swt.widgets.Control;
 import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Group;
 import org.eclipse.swt.widgets.Label;
 import org.eclipse.swt.widgets.MessageBox;
 import org.eclipse.swt.widgets.Shell;
@@ -50,6 +51,10 @@ public class UpdatePrimitiveArrayAttributeDialog extends TitleAreaDialog {
     private Text                       currentValueTxt;
     private Text                       newValueTxt;
     private Text                       allowedValuesTxt;
+    private Text                       minRangeTxt;
+    private Text                       maxRangeTxt;
+    private Text                       allowDuplicatesTxt;
+    private Text                       additionalItemsTxt;
     private SimulatorResourceAttribute attribute;
     private String                     newValue;
 
@@ -91,10 +96,104 @@ public class UpdatePrimitiveArrayAttributeDialog extends TitleAreaDialog {
         gd.horizontalAlignment = SWT.FILL;
         attNameTxt.setLayoutData(gd);
 
-        Label allowedValuesLbl = new Label(container, SWT.NONE);
+        Group subGroup = new Group(container, SWT.NONE);
+        subGroup.setText("Array Properties");
+        layout = new GridLayout(2, true);
+        subGroup.setLayout(layout);
+        gd = new GridData();
+        gd.grabExcessHorizontalSpace = true;
+        gd.horizontalAlignment = SWT.FILL;
+        gd.horizontalSpan = 2;
+        subGroup.setLayoutData(gd);
+
+        Composite minRangeContainer = new Composite(subGroup, SWT.NONE);
+        gd = new GridData();
+        gd.grabExcessHorizontalSpace = true;
+        gd.horizontalAlignment = SWT.FILL;
+        minRangeContainer.setLayoutData(gd);
+        layout = new GridLayout(2, true);
+        minRangeContainer.setLayout(layout);
+
+        Label minRangeLbl = new Label(minRangeContainer, SWT.NONE);
+        minRangeLbl.setText("Minimum Items");
+
+        minRangeTxt = new Text(minRangeContainer, SWT.BORDER | SWT.READ_ONLY);
+        gd = new GridData();
+        gd.grabExcessHorizontalSpace = true;
+        gd.horizontalAlignment = SWT.FILL;
+        minRangeTxt.setLayoutData(gd);
+        minRangeTxt.setBackground(container.getBackground());
+
+        Composite maxRangeContainer = new Composite(subGroup, SWT.NONE);
+        gd = new GridData();
+        gd.grabExcessHorizontalSpace = true;
+        gd.horizontalAlignment = SWT.FILL;
+        maxRangeContainer.setLayoutData(gd);
+        layout = new GridLayout(2, true);
+        maxRangeContainer.setLayout(layout);
+
+        Label maxRangeLbl = new Label(maxRangeContainer, SWT.NONE);
+        maxRangeLbl.setText("Maximum Items");
+
+        maxRangeTxt = new Text(maxRangeContainer, SWT.BORDER | SWT.READ_ONLY);
+        gd = new GridData();
+        gd.grabExcessHorizontalSpace = true;
+        gd.horizontalAlignment = SWT.FILL;
+        maxRangeTxt.setLayoutData(gd);
+        maxRangeTxt.setBackground(container.getBackground());
+
+        Composite uniqueContainer = new Composite(subGroup, SWT.NONE);
+        gd = new GridData();
+        gd.grabExcessHorizontalSpace = true;
+        gd.horizontalAlignment = SWT.FILL;
+        uniqueContainer.setLayoutData(gd);
+        layout = new GridLayout(2, true);
+        uniqueContainer.setLayout(layout);
+
+        Label uniqueLbl = new Label(uniqueContainer, SWT.NONE);
+        uniqueLbl.setText("Allow Duplicates");
+
+        allowDuplicatesTxt = new Text(uniqueContainer, SWT.BORDER
+                | SWT.READ_ONLY);
+        gd = new GridData();
+        gd.grabExcessHorizontalSpace = true;
+        gd.horizontalAlignment = SWT.FILL;
+        allowDuplicatesTxt.setLayoutData(gd);
+        allowDuplicatesTxt.setBackground(container.getBackground());
+
+        Composite addlItemsContainer = new Composite(subGroup, SWT.NONE);
+        gd = new GridData();
+        gd.grabExcessHorizontalSpace = true;
+        gd.horizontalAlignment = SWT.FILL;
+        addlItemsContainer.setLayoutData(gd);
+        layout = new GridLayout(2, true);
+        addlItemsContainer.setLayout(layout);
+
+        Label addlItemsLbl = new Label(addlItemsContainer, SWT.NONE);
+        addlItemsLbl.setText("Allow Extra Items");
+
+        additionalItemsTxt = new Text(addlItemsContainer, SWT.BORDER
+                | SWT.READ_ONLY);
+        gd = new GridData();
+        gd.grabExcessHorizontalSpace = true;
+        gd.horizontalAlignment = SWT.FILL;
+        additionalItemsTxt.setLayoutData(gd);
+        additionalItemsTxt.setBackground(container.getBackground());
+
+        Group elementPropGroup = new Group(container, SWT.NONE);
+        elementPropGroup.setText("Element Property");
+        layout = new GridLayout(2, false);
+        elementPropGroup.setLayout(layout);
+        gd = new GridData();
+        gd.grabExcessHorizontalSpace = true;
+        gd.horizontalAlignment = SWT.FILL;
+        gd.horizontalSpan = 2;
+        elementPropGroup.setLayoutData(gd);
+
+        Label allowedValuesLbl = new Label(elementPropGroup, SWT.NONE);
         allowedValuesLbl.setText("Allowed Values");
 
-        allowedValuesTxt = new Text(container, SWT.MULTI | SWT.READ_ONLY
+        allowedValuesTxt = new Text(elementPropGroup, SWT.MULTI | SWT.READ_ONLY
                 | SWT.BORDER | SWT.WRAP | SWT.V_SCROLL);
         allowedValuesTxt.setBackground(container.getBackground());
         gd = new GridData();
@@ -133,15 +232,17 @@ public class UpdatePrimitiveArrayAttributeDialog extends TitleAreaDialog {
         newValueTxt.setLayoutData(gd);
         newValueTxt.setFocus();
 
-        Label hintHeader = new Label(container, SWT.NULL);
-        hintHeader.setText("Note:-");
+        Group hintGroup = new Group(container, SWT.NONE);
+        hintGroup.setText("Note");
+        layout = new GridLayout();
+        hintGroup.setLayout(layout);
         gd = new GridData();
         gd.grabExcessHorizontalSpace = true;
         gd.horizontalAlignment = SWT.FILL;
         gd.horizontalSpan = 2;
-        hintHeader.setLayoutData(gd);
+        hintGroup.setLayoutData(gd);
 
-        Label hint = new Label(container, SWT.NULL);
+        Label hint = new Label(hintGroup, SWT.NULL);
         hint.setText("Array values should be comma-seperated and surrounded by square brackets.\n"
                 + "Ex: \"[value]\", \"[value1,value2]\", \"[[value1], [value2]]\"");
         gd = new GridData();
@@ -168,7 +269,7 @@ public class UpdatePrimitiveArrayAttributeDialog extends TitleAreaDialog {
         if (elementProp.isInteger()) {
             IntegerProperty intProp = elementProp.asInteger();
             if (intProp.hasRange()) {
-                values = "From " + intProp.min() + " To " + intProp.max();
+                values = intProp.min() + " - " + intProp.max();
             } else if (intProp.hasValues()) {
                 int[] arr = intProp.getValues();
                 for (int i = 0; i < arr.length; i++) {
@@ -185,7 +286,7 @@ public class UpdatePrimitiveArrayAttributeDialog extends TitleAreaDialog {
         } else if (elementProp.isDouble()) {
             DoubleProperty dblProp = elementProp.asDouble();
             if (dblProp.hasRange()) {
-                values = "From " + dblProp.min() + " To " + dblProp.max();
+                values = dblProp.min() + " - " + dblProp.max();
             } else if (dblProp.hasValues()) {
                 double[] arr = dblProp.getValues();
                 for (int i = 0; i < arr.length; i++) {
@@ -222,6 +323,14 @@ public class UpdatePrimitiveArrayAttributeDialog extends TitleAreaDialog {
         // Set the current value.
         currentValueTxt.setText(new AttributeValueStringConverter(attribute
                 .value()).toString());
+
+        minRangeTxt.setText(String.valueOf(arrProp.minItems()));
+
+        maxRangeTxt.setText(String.valueOf(arrProp.maxItems()));
+
+        allowDuplicatesTxt.setText(!arrProp.isUnique() ? "Yes" : "No");
+
+        additionalItemsTxt.setText(arrProp.isVariable() ? "Yes" : "No");
     }
 
     public String getNewValue() {