From: G S Senthil Kumar Date: Thu, 3 Mar 2016 20:24:50 +0000 (+0530) Subject: Resolved issues and concerns found during overall functionality testing. X-Git-Tag: 1.2.0+RC1~580^2^2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=5abf72f56ce6e33d8c4c9577486d71f79481f3c8;p=platform%2Fupstream%2Fiotivity.git Resolved issues and concerns found during overall functionality testing. 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 Reviewed-on: https://gerrit.iotivity.org/gerrit/5373 Tested-by: jenkins-iotivity Reviewed-by: Madan Lanka --- diff --git a/service/simulator/java/eclipse-plugin/ClientControllerPlugin/src/oic/simulator/clientcontroller/manager/ResourceManager.java b/service/simulator/java/eclipse-plugin/ClientControllerPlugin/src/oic/simulator/clientcontroller/manager/ResourceManager.java index 4f510ab6f..03d8d3588 100644 --- a/service/simulator/java/eclipse-plugin/ClientControllerPlugin/src/oic/simulator/clientcontroller/manager/ResourceManager.java +++ b/service/simulator/java/eclipse-plugin/ClientControllerPlugin/src/oic/simulator/clientcontroller/manager/ResourceManager.java @@ -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 resInterfaces = resourceN - .getResourceInterfaces(); - if (null != resInterfaces) { - ifType = resInterfaces.get(0); + if (!observeRequestSent) { + try { + String ifType = null; + Vector 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 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 existingResTypes = existingNativeResourceRef + .getResourceTypes(); + Vector newResTypes = newNativeResourceRef + .getResourceTypes(); + + if (!change) { + if (existingResTypes.size() != newResTypes.size()) { + change = true; + } else { + // Compare both lists. + Iterator itr = existingResTypes.iterator(); + while (itr.hasNext()) { + if (!newResTypes.contains(itr.next())) { + change = true; + break; + } + } + } + } + + // Compare Interface Types. + Vector existingInterfaceTypes = existingNativeResourceRef + .getResourceInterfaces(); + Vector newInterfaceTypes = newNativeResourceRef + .getResourceInterfaces(); + + if (!change) { + if (existingInterfaceTypes.size() != newInterfaceTypes.size()) { + change = true; + } else { + // Compare both lists. + Iterator 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 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 getPlatformProperties() { - if (null == currentResourceInSelection) { + RemoteResource resourceInSelection = getCurrentResourceInSelection(); + if (null == resourceInSelection) { return null; } - SimulatorRemoteResource remoteResource = currentResourceInSelection + SimulatorRemoteResource remoteResource = resourceInSelection .getRemoteResourceRef(); if (null == remoteResource) { return null; diff --git a/service/simulator/java/eclipse-plugin/ClientControllerPlugin/src/oic/simulator/clientcontroller/utils/AttributeValueBuilder.java b/service/simulator/java/eclipse-plugin/ClientControllerPlugin/src/oic/simulator/clientcontroller/utils/AttributeValueBuilder.java index b12c0a742..221f1d42a 100644 --- a/service/simulator/java/eclipse-plugin/ClientControllerPlugin/src/oic/simulator/clientcontroller/utils/AttributeValueBuilder.java +++ b/service/simulator/java/eclipse-plugin/ClientControllerPlugin/src/oic/simulator/clientcontroller/utils/AttributeValueBuilder.java @@ -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); } diff --git a/service/simulator/java/eclipse-plugin/ClientControllerPlugin/src/oic/simulator/clientcontroller/view/AttributeView.java b/service/simulator/java/eclipse-plugin/ClientControllerPlugin/src/oic/simulator/clientcontroller/view/AttributeView.java index ed5c83bf1..c36c0f8d4 100644 --- a/service/simulator/java/eclipse-plugin/ClientControllerPlugin/src/oic/simulator/clientcontroller/view/AttributeView.java +++ b/service/simulator/java/eclipse-plugin/ClientControllerPlugin/src/oic/simulator/clientcontroller/view/AttributeView.java @@ -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 diff --git a/service/simulator/java/eclipse-plugin/ClientControllerPlugin/src/oic/simulator/clientcontroller/view/dialogs/PostRequestDialog.java b/service/simulator/java/eclipse-plugin/ClientControllerPlugin/src/oic/simulator/clientcontroller/view/dialogs/PostRequestDialog.java index 47eed95f3..f8269b55d 100644 --- a/service/simulator/java/eclipse-plugin/ClientControllerPlugin/src/oic/simulator/clientcontroller/view/dialogs/PostRequestDialog.java +++ b/service/simulator/java/eclipse-plugin/ClientControllerPlugin/src/oic/simulator/clientcontroller/view/dialogs/PostRequestDialog.java @@ -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; diff --git a/service/simulator/java/eclipse-plugin/ClientControllerPlugin/src/oic/simulator/clientcontroller/view/dialogs/PutRequestDialog.java b/service/simulator/java/eclipse-plugin/ClientControllerPlugin/src/oic/simulator/clientcontroller/view/dialogs/PutRequestDialog.java index 04a1f177a..cd99ffcf0 100644 --- a/service/simulator/java/eclipse-plugin/ClientControllerPlugin/src/oic/simulator/clientcontroller/view/dialogs/PutRequestDialog.java +++ b/service/simulator/java/eclipse-plugin/ClientControllerPlugin/src/oic/simulator/clientcontroller/view/dialogs/PutRequestDialog.java @@ -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); diff --git a/service/simulator/java/eclipse-plugin/ClientControllerPlugin/src/oic/simulator/clientcontroller/view/dialogs/UpdatePrimitiveArrayAttributeDialog.java b/service/simulator/java/eclipse-plugin/ClientControllerPlugin/src/oic/simulator/clientcontroller/view/dialogs/UpdatePrimitiveArrayAttributeDialog.java index 1df6e5a01..5224b8780 100644 --- a/service/simulator/java/eclipse-plugin/ClientControllerPlugin/src/oic/simulator/clientcontroller/view/dialogs/UpdatePrimitiveArrayAttributeDialog.java +++ b/service/simulator/java/eclipse-plugin/ClientControllerPlugin/src/oic/simulator/clientcontroller/view/dialogs/UpdatePrimitiveArrayAttributeDialog.java @@ -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() { diff --git a/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/manager/ResourceManager.java b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/manager/ResourceManager.java index 4f89a62b0..1e16e091f 100644 --- a/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/manager/ResourceManager.java +++ b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/manager/ResourceManager.java @@ -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 properties) { diff --git a/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/utils/AttributeValueBuilder.java b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/utils/AttributeValueBuilder.java index 38ac2c395..421b7c1cb 100644 --- a/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/utils/AttributeValueBuilder.java +++ b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/utils/AttributeValueBuilder.java @@ -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); } diff --git a/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/utils/Constants.java b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/utils/Constants.java index f8a04bf90..5dcf7430d 100644 --- a/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/utils/Constants.java +++ b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/utils/Constants.java @@ -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"; diff --git a/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/AttributeView.java b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/AttributeView.java index abc7189e7..538ebe8a6 100644 --- a/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/AttributeView.java +++ b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/AttributeView.java @@ -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(); diff --git a/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/ResourceManagerView.java b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/ResourceManagerView.java index b8ed4b07b..9a09de3fc 100644 --- a/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/ResourceManagerView.java +++ b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/ResourceManagerView.java @@ -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() { diff --git a/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/dialogs/CreateResourceWizard.java b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/dialogs/CreateResourceWizard.java index 399cf6e9a..a29eecc3b 100644 --- a/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/dialogs/CreateResourceWizard.java +++ b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/dialogs/CreateResourceWizard.java @@ -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; } diff --git a/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/dialogs/UpdatePrimitiveArrayAttributeDialog.java b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/dialogs/UpdatePrimitiveArrayAttributeDialog.java index 2253b60b2..af2669eb4 100644 --- a/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/dialogs/UpdatePrimitiveArrayAttributeDialog.java +++ b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/dialogs/UpdatePrimitiveArrayAttributeDialog.java @@ -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() {