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>
// 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
"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
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) {
}
// 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);
}
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;
}
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;
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);
}
new Date(),
"["
+ reqType.toString()
- + "] Verification Completed for \""
+ + "] Verification is successful for \""
+ remoteResource.getURI()
+ "\".");
}
new Date(),
"["
+ reqType
- + "] Verification Aborted for \""
+ + "] Verification is failed for \""
+ remoteResource.getURI()
+ "\".");
}
}
}
}
- 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
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);
}
}
- 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;
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);
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);
}
}
- 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;
// 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);
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;
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;
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();
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();
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++) {
} 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++) {
// 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() {
UiListenerHandler.getInstance().resourceCreatedUINotification(
ResourceType.SINGLE);
+ Activator
+ .getDefault()
+ .getLogManager()
+ .log(Level.INFO.ordinal(), new Date(),
+ "Resource created [" + resource.getResourceURI() + "].");
+
return true;
}
Utility.getSimulatorErrorString(e, null));
throw e;
}
+
+ Activator
+ .getDefault()
+ .getLogManager()
+ .log(Level.INFO.ordinal(), new Date(),
+ "Resource created [" + resource.getResourceURI() + "].");
return true;
}
// 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) {
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);
}
+ "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";
"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);
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];
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");
}
// Removing the element from the attribute value.
- SimulatorResourceAttribute parentSRA = parentElement
- .getSimulatorResourceAttribute();
- AttributeValue value = parentSRA.value();
SimulatorResourceModel[] modelArray = (SimulatorResourceModel[]) value
.get();
@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() {
// 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;
}
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;
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;
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();
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();
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++) {
} 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++) {
// 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() {