From: G S Senthil Kumar Date: Wed, 18 Nov 2015 19:14:46 +0000 (+0530) Subject: Displaying and editing the complex value types for attributes. X-Git-Tag: 1.2.0+RC1~764^2~6 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=b76f9709482b03334b468ab47a295761b3fd6a78;p=platform%2Fupstream%2Fiotivity.git Displaying and editing the complex value types for attributes. 1. Tested model and array of model type attribute values. 2. Inclues bug fixing for single resource creation without RAML. Change-Id: I3f0791dde17e4e0d7f6c2165eb59443465f4163d Signed-off-by: G S Senthil Kumar Reviewed-on: https://gerrit.iotivity.org/gerrit/4267 Tested-by: jenkins-iotivity Reviewed-by: RadhaBhavani Reviewed-by: Madan Lanka --- diff --git a/service/simulator/examples/client/simulator_client.cpp b/service/simulator/examples/client/simulator_client.cpp index db7fca2..ea039cb 100644 --- a/service/simulator/examples/client/simulator_client.cpp +++ b/service/simulator/examples/client/simulator_client.cpp @@ -71,7 +71,7 @@ class ClientController int choice = -1; std::cout << "Enter your choice: "; std::cin >> choice; - if (choice < 0 || choice > 12) + if (choice < 0 || choice > 14) { std::cout << "Invaild choice !" << std::endl; continue; } @@ -89,7 +89,9 @@ class ClientController case 9: sendAllPUTRequests(); break; case 10: sendAllPOSTRequests(); break; case 11: configure(); break; - case 12: printMenu(); break; + case 12: getDeviceInfo(); break; + case 13: getPlatformInfo(); break; + case 14: printMenu(); break; case 0: cont = false; } } @@ -110,7 +112,9 @@ class ClientController std::cout << "9. Send All PUT requests" << std::endl; std::cout << "10. Send All POST requests" << std::endl; std::cout << "11. Configure (using RAML file)" << std::endl; - std::cout << "12: Help" << std::endl; + std::cout << "12. Get Device Information" << std::endl; + std::cout << "13. Get Platform Information" << std::endl; + std::cout << "14: Help" << std::endl; std::cout << "0. Exit" << std::endl; std::cout << "###################################################" << std::endl; } @@ -539,6 +543,77 @@ class ClientController } } + void getDeviceInfo() + { + SimulatorRemoteResourceSP resource = selectResource(); + if (!resource) + return; + + try + { + SimulatorManager::getInstance()->getDeviceInfo(resource->getHost(), std::bind([](DeviceInfo & deviceInfo) + { + std::cout << "###Device Information received...." << std::endl; + std::ostringstream out; + out << "Device name: " << deviceInfo.getName() << std::endl; + out << "Device ID: " << deviceInfo.getID() << std::endl; + out << "Device Spec version: " << deviceInfo.getSpecVersion() << std::endl; + out << "Device dat model version: " << deviceInfo.getDataModelVersion() << std::endl; + + std::cout << out.str() << std::endl; + }, std::placeholders::_1)); + } + catch (InvalidArgsException &e) + { + std::cout << "InvalidArgsException occured [code : " << e.code() << " Detail: " << e.what() << "]" + << std::endl; + } + catch (SimulatorException &e) + { + std::cout << "SimulatorException occured [code : " << e.code() << " Detail: " << e.what() << "]" << + std::endl; + } + } + + void getPlatformInfo() + { + SimulatorRemoteResourceSP resource = selectResource(); + if (!resource) + return; + + try + { + SimulatorManager::getInstance()->getPlatformInfo(resource->getHost(), std::bind([](PlatformInfo & platformInfo) + { + std::cout << "###Platform Information received...." << std::endl; + std::ostringstream out; + out << "Platform ID: " << platformInfo.getPlatformID() << std::endl; + out << "Platform version: " << platformInfo.getPlatformVersion() << std::endl; + out << "Manufacturer name: " << platformInfo.getManufacturerName() << std::endl; + out << "Manufacturer url: " << platformInfo.getManufacturerUrl() << std::endl; + out << "Modle number: " << platformInfo.getModelNumber() << std::endl; + out << "Date of manufacture: " << platformInfo.getDateOfManfacture() << std::endl; + out << "Operatio system version: " << platformInfo.getOSVersion() << std::endl; + out << "Hardware version: " << platformInfo.getHardwareVersion() << std::endl; + out << "Firmware version: " << platformInfo.getFirmwareVersion() << std::endl; + out << "Support url: " << platformInfo.getSupportUrl() << std::endl; + out << "System time: " << platformInfo.getSystemTime() << std::endl; + + std::cout << out.str() << std::endl; + }, std::placeholders::_1)); + } + catch (InvalidArgsException &e) + { + std::cout << "InvalidArgsException occured [code : " << e.code() + << " Detail: " << e.what() << "]" << std::endl; + } + catch (SimulatorException &e) + { + std::cout << "SimulatorException occured [code : " << e.code() + << " Detail: " << e.what() << "]" << std::endl; + } + } + private: std::recursive_mutex m_mutex; std::map m_resList; @@ -548,10 +623,8 @@ void printMainMenu() { std::cout << "############### MAIN MENU###############" << std::endl; std::cout << "1. Client Controller Test" << std::endl; - std::cout << "2. Get device information" << std::endl; - std::cout << "3. Get platform information" << std::endl; - std::cout << "4. Set Logger" << std::endl; - std::cout << "5. Help" << std::endl; + std::cout << "2. Set Logger" << std::endl; + std::cout << "3. Help" << std::endl; std::cout << "0. Exit" << std::endl; std::cout << "######################################" << std::endl; } @@ -615,74 +688,9 @@ int main(void) std::cout << "Welcome back to main menu !" << std::endl; break; - case 2: - { - try - { - SimulatorManager::getInstance()->getDeviceInfo(std::bind([](DeviceInfo & deviceInfo) - { - std::cout << "###Device Information received...." << std::endl; - std::ostringstream out; - out << "Device name: " << deviceInfo.getName() << std::endl; - out << "Device ID: " << deviceInfo.getID() << std::endl; - out << "Device Spec version: " << deviceInfo.getSpecVersion() << std::endl; - out << "Device dat model version: " << deviceInfo.getDataModelVersion() << std::endl; - - std::cout << out.str() << std::endl; - }, std::placeholders::_1)); - } - catch (InvalidArgsException &e) - { - std::cout << "InvalidArgsException occured [code : " << e.code() << " Detail: " << e.what() << "]" - << std::endl; - } - catch (SimulatorException &e) - { - std::cout << "SimulatorException occured [code : " << e.code() << " Detail: " << e.what() << "]" << - std::endl; - } - } - break; - - case 3: - { - try - { - SimulatorManager::getInstance()->getPlatformInfo(std::bind([](PlatformInfo & platformInfo) - { - std::cout << "###Platform Information received...." << std::endl; - std::ostringstream out; - out << "Platform ID: " << platformInfo.getPlatformID() << std::endl; - out << "Platform version: " << platformInfo.getPlatformVersion() << std::endl; - out << "Manufacturer name: " << platformInfo.getManufacturerName() << std::endl; - out << "Manufacturer url: " << platformInfo.getManufacturerUrl() << std::endl; - out << "Modle number: " << platformInfo.getModelNumber() << std::endl; - out << "Date of manufacture: " << platformInfo.getDateOfManfacture() << std::endl; - out << "Operatio system version: " << platformInfo.getOSVersion() << std::endl; - out << "Hardware version: " << platformInfo.getHardwareVersion() << std::endl; - out << "Firmware version: " << platformInfo.getFirmwareVersion() << std::endl; - out << "Support url: " << platformInfo.getSupportUrl() << std::endl; - out << "System time: " << platformInfo.getSystemTime() << std::endl; - - std::cout << out.str() << std::endl; - }, std::placeholders::_1)); - } - catch (InvalidArgsException &e) - { - std::cout << "InvalidArgsException occured [code : " << e.code() - << " Detail: " << e.what() << "]" << std::endl; - } - catch (SimulatorException &e) - { - std::cout << "SimulatorException occured [code : " << e.code() - << " Detail: " << e.what() << "]" << std::endl; - } - } - break; - - case 4: setLogger(); break; + case 2: setLogger(); break; - case 5: printMainMenu(); break; + case 3: printMainMenu(); break; case 0: cont = false; } diff --git a/service/simulator/inc/simulator_manager.h b/service/simulator/inc/simulator_manager.h index 5b3d76e..6ba4572 100644 --- a/service/simulator/inc/simulator_manager.h +++ b/service/simulator/inc/simulator_manager.h @@ -124,7 +124,7 @@ class SimulatorManager * * NOTE: API throws @InvalidArgsException and @SimulatorException on error. */ - void getDeviceInfo(DeviceInfoCallback callback); + void getDeviceInfo(const std::string &host, DeviceInfoCallback callback); /** * API for registering device information with stack. @@ -145,7 +145,7 @@ class SimulatorManager * * NOTE: API throws @InvalidArgsException and @SimulatorException on error. */ - void getPlatformInfo(PlatformInfoCallback callback); + void getPlatformInfo(const std::string &host, PlatformInfoCallback callback); /** * API for registering platform information with stack. 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 bcadd4a..3de0d3e 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 @@ -39,10 +39,7 @@ import oic.simulator.clientcontroller.listener.IPutUIListener; import oic.simulator.clientcontroller.listener.IResourceSelectionChangedUIListener; import oic.simulator.clientcontroller.listener.IVerificationUIListener; import oic.simulator.clientcontroller.remoteresource.MetaProperty; -import oic.simulator.clientcontroller.remoteresource.PutPostAttributeModel; import oic.simulator.clientcontroller.remoteresource.RemoteResource; -import oic.simulator.clientcontroller.remoteresource.RemoteResourceAttribute; -import oic.simulator.clientcontroller.utils.AttributeValueBuilder; import oic.simulator.clientcontroller.utils.Constants; import oic.simulator.clientcontroller.utils.Utility; @@ -215,9 +212,12 @@ public class ResourceManager { // Get the device and platform information try { - SimulatorManager.findDevices(deviceListener); - SimulatorManager - .getPlatformInformation(platformListener); + SimulatorManager.findDevices(resource + .getRemoteResourceRef().getHost(), + deviceListener); + SimulatorManager.getPlatformInformation(resource + .getRemoteResourceRef().getHost(), + platformListener); } catch (SimulatorException e) { Activator .getDefault() @@ -473,57 +473,18 @@ public class ResourceManager { return null; } - resource.setResourceModelRef(resourceModelN); - Map attributeMap = fetchResourceAttributesFromModel(resourceModelN); - if (resource.isConfigUploaded()) { - updateResourceAttributesFromResponse(resource, attributeMap); + // if(!resource.isConfigUploaded() || null == + // resource.getResourceModelRef()) + SimulatorResourceModel resourceModel = resource.getResourceModelRef(); + if (null == resourceModel) { + resource.setResourceModelRef(resourceModelN); } else { - resource.setResourceAttributesMap(attributeMap); + resourceModel.update(resourceModelN); } - // TODO: Printing the values for debugging - if (null != attributeMap) { - RemoteResourceAttribute.printAttributes(attributeMap); - } - return resource; - } - private void updateResourceAttributesFromResponse(RemoteResource res, - Map newAttributeMap) { - if (null == res || null == newAttributeMap) { - return; - } - Map oldAttributeMap = res - .getResourceAttributesMap(); - if (null == oldAttributeMap) { - return; - } - Iterator itr = oldAttributeMap.keySet().iterator(); - String attName; - RemoteResourceAttribute newAtt; - RemoteResourceAttribute oldAtt; - while (itr.hasNext()) { - attName = itr.next(); - newAtt = newAttributeMap.get(attName); - if (null == newAtt) { - // Attribute does not exist in the received model. Hence - // removing it from local model. - itr.remove(); - } else { - oldAtt = oldAttributeMap.get(attName); - if (null != oldAtt) { - oldAtt.setAttributeValue(newAtt.getAttributeValue()); - } else { - itr.remove(); - } - newAttributeMap.remove(attName); - } - } - // Adding new attributes in the received model. - itr = newAttributeMap.keySet().iterator(); - while (itr.hasNext()) { - attName = itr.next(); - oldAttributeMap.put(attName, newAttributeMap.get(attName)); - } + resource.setResourceRepresentation(resourceModelN, false); + + return resource; } public synchronized DeviceInfo getDeviceInfo() { @@ -729,7 +690,8 @@ public class ResourceManager { public void addObservedResourceURI(String resourceURI) { synchronized (observedResourceURIList) { - observedResourceURIList.add(resourceURI); + if (!observedResourceURIList.contains(resourceURI)) + observedResourceURIList.add(resourceURI); } } @@ -802,75 +764,6 @@ public class ResourceManager { return resource; } - private Map fetchResourceAttributesFromModel( - SimulatorResourceModel resourceModelN) { - Map resourceAttributeMap = null; - if (null != resourceModelN) { - Map attributeMapN; - attributeMapN = resourceModelN.getAttributes(); - if (null != attributeMapN) { - resourceAttributeMap = new HashMap(); - - Set attNameSet = attributeMapN.keySet(); - String attName; - Object attValueObj; - AttributeValue attValueN; - AttributeProperty attPropN; - TypeInfo typeInfo; - Type valuesType; - SimulatorResourceAttribute attributeN; - RemoteResourceAttribute attribute; - Iterator attNameItr = attNameSet.iterator(); - while (attNameItr.hasNext()) { - attName = attNameItr.next(); - attributeN = attributeMapN.get(attName); - if (null != attributeN) { - attribute = new RemoteResourceAttribute(); - attribute.setResourceAttributeRef(attributeN); - attribute.setAttributeName(attName); - - attValueN = attributeN.value(); - if (null != attValueN) { - attValueObj = attValueN.get(); - if (null != attValueObj) { - attribute.setAttributeValue(attValueObj); - } - - // Set the attribute type - typeInfo = attValueN.typeInfo(); - if (null != typeInfo) { - attribute.setAttValBaseType(typeInfo.mBaseType); - attribute.setAttValType(typeInfo.mType); - attribute.setDepth(typeInfo.mDepth); - } - - } - - // Set the range and allowed values - attPropN = attributeN.property(); - valuesType = attPropN.type(); - attribute.setValuesType(valuesType); - if (valuesType == Type.RANGE) { - attribute.setMinValue(attPropN.min()); - attribute.setMaxValue(attPropN.max()); - } else if (valuesType == Type.VALUESET) { - Object[] values = attPropN.valueSet(); - if (null != values && values.length > 0) { - List valueList = new ArrayList(); - for (Object obj : values) { - valueList.add(((AttributeValue) obj).get()); - } - attribute.setAllowedValues(valueList); - } - } - resourceAttributeMap.put(attName, attribute); - } - } - } - } - return resourceAttributeMap; - } - private void newResourceFoundNotification(RemoteResource resource) { synchronized (findResourceUIListeners) { if (findResourceUIListeners.size() > 0) { @@ -1401,13 +1294,135 @@ public class ResourceManager { return resourceList; } - public String getAttributeValue(RemoteResource res, String attName) { - if (null == res || null == attName) { + public List getAllValuesOfAttribute(SimulatorResourceAttribute att) { + if (null == att) { + return null; + } + + AttributeValue val = att.value(); + if (null == val) { return null; } - return res.getAttributeValue(attName); + + List values = new ArrayList(); + + TypeInfo type = val.typeInfo(); + + AttributeProperty prop = att.property(); + if (null == prop || prop.type().ordinal() == Type.UNKNOWN.ordinal()) { + values.add(Utility.getAttributeValueAsString(val)); + return values; + } + + Type valuesType = prop.type(); + + if (type.mType != ValueType.RESOURCEMODEL) { + if (type.mType == ValueType.ARRAY) { + if (type.mDepth == 1) { + AttributeProperty childProp = prop.getChildProperty(); + if (null != childProp) { + valuesType = childProp.type(); + if (valuesType.ordinal() == Type.RANGE.ordinal()) { + List list = getRangeForPrimitiveNonArrayAttributes( + childProp, type.mBaseType); + if (null != list) { + values.addAll(list); + } + } else if (valuesType.ordinal() == Type.VALUESET + .ordinal()) { + List list = getAllowedValuesForPrimitiveNonArrayAttributes( + childProp.valueSet(), type.mBaseType); + if (null != list) { + values.addAll(list); + } + } + } + } + } else { + if (valuesType.ordinal() == Type.RANGE.ordinal()) { + List list = getRangeForPrimitiveNonArrayAttributes( + prop, type.mType); + if (null != list) { + values.addAll(list); + } + } else if (valuesType.ordinal() == Type.VALUESET.ordinal()) { + List list = getAllowedValuesForPrimitiveNonArrayAttributes( + prop.valueSet(), type.mType); + if (null != list) { + values.addAll(list); + } + } + } + } + + if (values.isEmpty()) { + values.add(Utility.getAttributeValueAsString(val)); + } + + return values; + } + + public List getRangeForPrimitiveNonArrayAttributes( + AttributeProperty prop, ValueType type) { + if (null == prop) { + return null; + } + + if (type == ValueType.ARRAY || type == ValueType.RESOURCEMODEL) { + return null; + } + + List values = new ArrayList(); + switch (type) { + case INTEGER: + int min = (int) prop.min(); + int max = (int) prop.max(); + for (int iVal = min; iVal <= max; iVal++) { + values.add(String.valueOf(iVal)); + } + break; + case DOUBLE: + double minD = (double) prop.min(); + double maxD = (double) prop.max(); + for (double iVal = minD; iVal <= maxD; iVal = iVal + 1.0) { + values.add(String.valueOf(iVal)); + } + break; + default: + } + return values; + } + + public List getAllowedValuesForPrimitiveNonArrayAttributes( + AttributeValue[] attValues, ValueType type) { + if (null == attValues || attValues.length < 1) { + return null; + } + + if (type == ValueType.ARRAY || type == ValueType.RESOURCEMODEL) { + return null; + } + + Object obj; + List values = new ArrayList(); + for (AttributeValue val : attValues) { + if (null == val) { + continue; + } + obj = val.get(); + if (null == obj) { + continue; + } + values.add(String.valueOf(obj)); + } + return values; } + /* + * public String getAttributeValue(RemoteResource res, String attName) { if + * (null == res || null == attName) { return null; } return + * res.getAttributeValue(attName); } + */ public void sendGetRequest(RemoteResource resource) { if (null == resource) { return; @@ -1428,23 +1443,16 @@ public class ResourceManager { } public void sendPutRequest(RemoteResource resource, - List putPostModelList) { - if (null == resource) { + SimulatorResourceModel model) { + if (null == resource || null == model) { return; } SimulatorRemoteResource resourceN = resource.getRemoteResourceRef(); if (null == resourceN) { return; } - Map attMap = resource - .getResourceAttributesMap(); - if (null == attMap || attMap.size() < 1) { - return; - } try { - SimulatorResourceModel resourceModel = getUpdatedResourceModel( - attMap, putPostModelList); - resourceN.put(null, resourceModel, putListener); + resourceN.put(null, model, putListener); } catch (Exception e) { String addlInfo; addlInfo = "Invalid Attribute Value. Cannot send PUT request."; @@ -1457,32 +1465,16 @@ public class ResourceManager { } public void sendPostRequest(RemoteResource resource, - List putPostModelList) { - if (null == resource) { + SimulatorResourceModel model) { + if (null == resource || null == model) { return; } SimulatorRemoteResource resourceN = resource.getRemoteResourceRef(); if (null == resourceN) { return; } - Map attMap = resource - .getResourceAttributesMap(); - if (null == attMap || attMap.size() < 1) { - return; - } - // Filter out the attributes whose modification status is true. - Iterator itr = putPostModelList.iterator(); - PutPostAttributeModel model; - while (itr.hasNext()) { - model = itr.next(); - if (!model.isModified()) { - itr.remove(); - } - } try { - SimulatorResourceModel resourceModel = getUpdatedResourceModel( - attMap, putPostModelList); - resourceN.post(null, resourceModel, postListener); + resourceN.post(null, model, postListener); } catch (Exception e) { String addlInfo; addlInfo = "Invalid Attribute Value. Cannot send POST request."; @@ -1494,22 +1486,6 @@ public class ResourceManager { } } - private SimulatorResourceModel getUpdatedResourceModel( - Map attMap, - List putPostModelList) throws Exception { - SimulatorResourceModel resourceModel = new SimulatorResourceModel(); - for (PutPostAttributeModel putPostAttribute : putPostModelList) - { - String attributeName = putPostAttribute.getAttName(); - RemoteResourceAttribute resourceAttribute = attMap.get(attributeName); - AttributeValue attributeValue = AttributeValueBuilder.build( - putPostAttribute.getAttValue(), resourceAttribute.getAttValBaseType()); - resourceModel.addAttribute(attributeName, attributeValue); - } - - return resourceModel; - } - public boolean sendObserveRequest(RemoteResource resource) { if (null == resource) { return false; @@ -1640,21 +1616,19 @@ public class ResourceManager { return false; } try { - SimulatorResourceModel resourceModel; - resourceModel = resourceN.setConfigInfo(configFilePath); - if (null == resourceModel) { + SimulatorResourceModel configuredResourceModel; + configuredResourceModel = resourceN.setConfigInfo(configFilePath); + if (null == configuredResourceModel) { return false; } + // Store the resource model in the local cache - resource.setResourceModelRef(resourceModel); - - // Fetching the allowed values and range for all the attributes - Map attributeMap = fetchResourceAttributesFromModel(resourceModel); - resource.setResourceAttributesMap(attributeMap); - // TODO: Printing the values for debugging - if (null != attributeMap) { - RemoteResourceAttribute.printAttributes(attributeMap); + SimulatorResourceModel resourceModel = resource + .getResourceModelRef(); + if (null != resourceModel) { + configuredResourceModel.update(resourceModel); } + resource.setResourceModelRef(configuredResourceModel); } catch (SimulatorException e) { Activator .getDefault() diff --git a/service/simulator/java/eclipse-plugin/ClientControllerPlugin/src/oic/simulator/clientcontroller/remoteresource/AttributeElement.java b/service/simulator/java/eclipse-plugin/ClientControllerPlugin/src/oic/simulator/clientcontroller/remoteresource/AttributeElement.java new file mode 100644 index 0000000..670d2a7 --- /dev/null +++ b/service/simulator/java/eclipse-plugin/ClientControllerPlugin/src/oic/simulator/clientcontroller/remoteresource/AttributeElement.java @@ -0,0 +1,300 @@ +package oic.simulator.clientcontroller.remoteresource; + +import java.util.HashMap; +import java.util.Map; + +import oic.simulator.clientcontroller.utils.AttributeValueStringConverter; + +import org.oic.simulator.AttributeValue; +import org.oic.simulator.InvalidArgsException; +import org.oic.simulator.SimulatorResourceAttribute; +import org.oic.simulator.SimulatorResourceModel; + +public class AttributeElement { + private Object mParent = null; + private SimulatorResourceAttribute mAttribute = null; + private Map mChildAttributes = new HashMap(); + private boolean mPostState = false; + + public AttributeElement(Object parent, SimulatorResourceAttribute attribute) { + mParent = parent; + mAttribute = attribute; + AttributeValue.TypeInfo typeInfo = attribute.value().typeInfo(); + if (typeInfo.mType == AttributeValue.ValueType.RESOURCEMODEL) { + SimulatorResourceModel resModel = (SimulatorResourceModel) attribute + .value().get(); + for (Map.Entry entrySet : resModel + .getAttributes().entrySet()) + mChildAttributes.put(entrySet.getKey(), new AttributeElement( + this, entrySet.getValue())); + } else if (typeInfo.mType == AttributeValue.ValueType.ARRAY + && typeInfo.mBaseType == AttributeValue.ValueType.RESOURCEMODEL) { + if (typeInfo.mDepth == 1) { + SimulatorResourceModel[] resModelArray = (SimulatorResourceModel[]) attribute + .value().get(); + for (int i = 0; i < resModelArray.length; i++) { + SimulatorResourceAttribute indexAttribute = new SimulatorResourceAttribute( + "[" + Integer.toString(i) + "]", + new AttributeValue(resModelArray[i]), null); + mChildAttributes.put("[" + Integer.toString(i) + "]", + new AttributeElement(this, indexAttribute)); + } + } else if (typeInfo.mDepth == 2) { + SimulatorResourceModel[][] resModelArray = (SimulatorResourceModel[][]) attribute + .value().get(); + for (int i = 0; i < resModelArray.length; i++) { + SimulatorResourceAttribute indexAttribute = new SimulatorResourceAttribute( + "[" + Integer.toString(i) + "]", + new AttributeValue(resModelArray[i]), null); + mChildAttributes.put("[" + Integer.toString(i) + "]", + new AttributeElement(this, indexAttribute)); + } + } else if (typeInfo.mDepth == 3) { + SimulatorResourceModel[][][] resModelArray = (SimulatorResourceModel[][][]) attribute + .value().get(); + for (int i = 0; i < resModelArray.length; i++) { + SimulatorResourceAttribute indexAttribute = new SimulatorResourceAttribute( + "[" + Integer.toString(i) + "]", + new AttributeValue(resModelArray[i]), null); + mChildAttributes.put("[" + Integer.toString(i) + "]", + new AttributeElement(this, indexAttribute)); + } + } + } + } + + public Object getParent() { + return mParent; + } + + public boolean hasChildren() { + if (mChildAttributes != null && mChildAttributes.size() > 0) + return true; + return false; + } + + public Map getChildren() { + if (hasChildren() == true) + return mChildAttributes; + return null; + } + + public SimulatorResourceAttribute getSimulatorResourceAttribute() { + return mAttribute; + } + + public boolean isPostSupported() { + /* Auto update is disabled for ARRAY and RESOURCEMODEL type values */ + AttributeValue.TypeInfo typeInfo = mAttribute.value().typeInfo(); + return (!(typeInfo.mType == AttributeValue.ValueType.ARRAY && typeInfo.mBaseType == AttributeValue.ValueType.RESOURCEMODEL) && typeInfo.mType != AttributeValue.ValueType.RESOURCEMODEL); + } + + public void update(SimulatorResourceAttribute attribute) { + if (attribute == null) + return; + + AttributeValue.TypeInfo typeInfo = attribute.value().typeInfo(); + if (typeInfo.mType == AttributeValue.ValueType.RESOURCEMODEL) { + SimulatorResourceModel resModel = (SimulatorResourceModel) attribute + .value().get(); + for (Map.Entry entry : resModel + .getAttributes().entrySet()) { + AttributeElement attributeElement = mChildAttributes.get(entry + .getKey()); + if (attributeElement != null) { + attributeElement.update(entry.getValue()); + } else // Display new attribute in UI + { + AttributeElement newAttribute = new AttributeElement(this, + entry.getValue()); + mChildAttributes.put(entry.getKey(), newAttribute); + } + } + } else if (typeInfo.mType == AttributeValue.ValueType.ARRAY + && typeInfo.mBaseType == AttributeValue.ValueType.RESOURCEMODEL) { + if (typeInfo.mDepth == 1) { + SimulatorResourceModel[] resModelArray = (SimulatorResourceModel[]) attribute + .value().get(); + for (int i = 0; i < resModelArray.length; i++) { + SimulatorResourceAttribute indexAttribute = new SimulatorResourceAttribute( + "[" + Integer.toString(i) + "]", + new AttributeValue(resModelArray[i]), null); + AttributeElement attributeElement = mChildAttributes + .get("[" + Integer.toString(i) + "]"); + if (attributeElement != null) { + attributeElement.update(indexAttribute); + } else // Display new attribute in UI + { + AttributeElement newAttribute = new AttributeElement( + this, indexAttribute); + mChildAttributes.put("[" + Integer.toString(i) + "]", + newAttribute); + } + } + } + if (typeInfo.mDepth == 2) { + SimulatorResourceModel[][] resModelArray = (SimulatorResourceModel[][]) attribute + .value().get(); + for (int i = 0; i < resModelArray.length; i++) { + SimulatorResourceAttribute indexAttribute = new SimulatorResourceAttribute( + "[" + Integer.toString(i) + "]", + new AttributeValue(resModelArray[i]), null); + AttributeElement attributeElement = mChildAttributes + .get("[" + Integer.toString(i) + "]"); + if (attributeElement != null) { + attributeElement.update(indexAttribute); + } else // Display new attribute in UI + { + AttributeElement newAttribute = new AttributeElement( + this, indexAttribute); + mChildAttributes.put("[" + Integer.toString(i) + "]", + newAttribute); + } + } + } + if (typeInfo.mDepth == 3) { + SimulatorResourceModel[][][] resModelArray = (SimulatorResourceModel[][][]) attribute + .value().get(); + for (int i = 0; i < resModelArray.length; i++) { + SimulatorResourceAttribute indexAttribute = new SimulatorResourceAttribute( + "[" + Integer.toString(i) + "]", + new AttributeValue(resModelArray[i]), null); + AttributeElement attributeElement = mChildAttributes + .get("[" + Integer.toString(i) + "]"); + if (attributeElement != null) { + attributeElement.update(indexAttribute); + } else // Display new attribute in UI + { + AttributeElement newAttribute = new AttributeElement( + this, indexAttribute); + mChildAttributes.put("[" + Integer.toString(i) + "]", + newAttribute); + } + } + } + } else { + String currentValue = new AttributeValueStringConverter( + mAttribute.value()).toString(); + String newValue = new AttributeValueStringConverter( + attribute.value()).toString(); + if (currentValue != newValue) { + mAttribute.setValue(attribute.value()); + } + } + } + + public void updateForRAMLUpload(SimulatorResourceAttribute attribute) { + if (attribute == null) + return; + + AttributeValue.TypeInfo typeInfo = attribute.value().typeInfo(); + if (typeInfo.mType == AttributeValue.ValueType.RESOURCEMODEL) { + SimulatorResourceModel resModel = (SimulatorResourceModel) attribute + .value().get(); + for (Map.Entry entry : resModel + .getAttributes().entrySet()) { + AttributeElement attributeElement = mChildAttributes.get(entry + .getKey()); + if (attributeElement != null) { + attributeElement.update(entry.getValue()); + } else // Display new attribute in UI + { + AttributeElement newAttribute = new AttributeElement(this, + entry.getValue()); + mChildAttributes.put(entry.getKey(), newAttribute); + } + } + } else if (typeInfo.mType == AttributeValue.ValueType.ARRAY + && typeInfo.mBaseType == AttributeValue.ValueType.RESOURCEMODEL) { + if (typeInfo.mDepth == 1) { + SimulatorResourceModel[] resModelArray = (SimulatorResourceModel[]) attribute + .value().get(); + for (int i = 0; i < resModelArray.length; i++) { + SimulatorResourceAttribute indexAttribute = new SimulatorResourceAttribute( + "[" + Integer.toString(i) + "]", + new AttributeValue(resModelArray[i]), null); + AttributeElement attributeElement = mChildAttributes + .get("[" + Integer.toString(i) + "]"); + if (attributeElement != null) { + attributeElement.update(indexAttribute); + } else // Display new attribute in UI + { + AttributeElement newAttribute = new AttributeElement( + this, indexAttribute); + mChildAttributes.put("[" + Integer.toString(i) + "]", + newAttribute); + } + } + } + if (typeInfo.mDepth == 2) { + SimulatorResourceModel[][] resModelArray = (SimulatorResourceModel[][]) attribute + .value().get(); + for (int i = 0; i < resModelArray.length; i++) { + SimulatorResourceAttribute indexAttribute = new SimulatorResourceAttribute( + "[" + Integer.toString(i) + "]", + new AttributeValue(resModelArray[i]), null); + AttributeElement attributeElement = mChildAttributes + .get("[" + Integer.toString(i) + "]"); + if (attributeElement != null) { + attributeElement.update(indexAttribute); + } else // Display new attribute in UI + { + AttributeElement newAttribute = new AttributeElement( + this, indexAttribute); + mChildAttributes.put("[" + Integer.toString(i) + "]", + newAttribute); + } + } + } + if (typeInfo.mDepth == 3) { + SimulatorResourceModel[][][] resModelArray = (SimulatorResourceModel[][][]) attribute + .value().get(); + for (int i = 0; i < resModelArray.length; i++) { + SimulatorResourceAttribute indexAttribute = new SimulatorResourceAttribute( + "[" + Integer.toString(i) + "]", + new AttributeValue(resModelArray[i]), null); + AttributeElement attributeElement = mChildAttributes + .get("[" + Integer.toString(i) + "]"); + if (attributeElement != null) { + attributeElement.update(indexAttribute); + } else // Display new attribute in UI + { + AttributeElement newAttribute = new AttributeElement( + this, indexAttribute); + mChildAttributes.put("[" + Integer.toString(i) + "]", + newAttribute); + } + } + } + } else { + mAttribute.setProperty(attribute.property()); + } + } + + public boolean getPostState() { + return mPostState; + } + + public void setPostState(boolean mPostState) { + this.mPostState = mPostState; + } + + public void deepSetChildValue(SimulatorResourceAttribute attribute) + throws InvalidArgsException { + if (null == attribute || null == attribute.name()) + return; + + AttributeValue.TypeInfo myValuetypeInfo = mAttribute.value().typeInfo(); + if (myValuetypeInfo.mType == AttributeValue.ValueType.RESOURCEMODEL) { + SimulatorResourceModel resModel = (SimulatorResourceModel) mAttribute + .value().get(); + if (resModel.containsAttribute(attribute.name())) + resModel.setAttributeValue(attribute.name(), attribute.value()); + else + return; + } + + if (mParent instanceof AttributeElement) + ((AttributeElement) mParent).deepSetChildValue(mAttribute); + } +} diff --git a/service/simulator/java/eclipse-plugin/ClientControllerPlugin/src/oic/simulator/clientcontroller/remoteresource/PutPostAttributeModel.java b/service/simulator/java/eclipse-plugin/ClientControllerPlugin/src/oic/simulator/clientcontroller/remoteresource/PutPostAttributeModel.java deleted file mode 100644 index de3f384..0000000 --- a/service/simulator/java/eclipse-plugin/ClientControllerPlugin/src/oic/simulator/clientcontroller/remoteresource/PutPostAttributeModel.java +++ /dev/null @@ -1,89 +0,0 @@ -/* - * Copyright 2015 Samsung Electronics All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package oic.simulator.clientcontroller.remoteresource; - -import java.util.List; - -/** - * This is a helper class for showing the resource attributes in PUT and POST - * dialogs. - */ -public class PutPostAttributeModel { - - private String attName; - private String attValue; - private List values; - boolean modified; - - public String getAttName() { - return attName; - } - - public void setAttName(String attName) { - this.attName = attName; - } - - public String getAttValue() { - return attValue; - } - - public void setAttValue(String attValue) { - this.attValue = attValue; - } - - public List getValues() { - return values; - } - - public void setValues(List values) { - this.values = values; - } - - public void prependNewValue(String customValue) { - if (values.contains(customValue)) { - values.remove(customValue); - } - values.add(0, customValue); - } - - public boolean isModified() { - return modified; - } - - public void setModified(boolean modified) { - this.modified = modified; - } - - public static PutPostAttributeModel getModel( - RemoteResourceAttribute attribute) { - PutPostAttributeModel putPostModel = null; - if (null != attribute) { - putPostModel = new PutPostAttributeModel(); - putPostModel.setAttName(attribute.getAttributeName()); - putPostModel.setAttValue(String.valueOf(attribute - .getAttributeValue())); - putPostModel.setValues(attribute.getAllValues()); - putPostModel.setModified(false); - } - return putPostModel; - } - - @Override - public String toString() { - return attName + "," + attValue + "\n"; - } -} diff --git a/service/simulator/java/eclipse-plugin/ClientControllerPlugin/src/oic/simulator/clientcontroller/remoteresource/RemoteResource.java b/service/simulator/java/eclipse-plugin/ClientControllerPlugin/src/oic/simulator/clientcontroller/remoteresource/RemoteResource.java index 04c39d1..977e0b2 100644 --- a/service/simulator/java/eclipse-plugin/ClientControllerPlugin/src/oic/simulator/clientcontroller/remoteresource/RemoteResource.java +++ b/service/simulator/java/eclipse-plugin/ClientControllerPlugin/src/oic/simulator/clientcontroller/remoteresource/RemoteResource.java @@ -16,11 +16,6 @@ package oic.simulator.clientcontroller.remoteresource; -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; -import java.util.Map; - import oic.simulator.clientcontroller.utils.Constants; import org.oic.simulator.SimulatorResourceModel; @@ -32,24 +27,25 @@ import org.oic.simulator.client.SimulatorRemoteResource; */ public class RemoteResource { - private boolean observed; + private boolean observed; // Native object references - private SimulatorRemoteResource remoteResourceRef; - private SimulatorResourceModel resourceModelRef; - private Map resourceAttributesMap; + private SimulatorRemoteResource remoteResourceRef; + private SimulatorResourceModel resourceModelRef; + private ResourceRepresentation mResourceRepresentation; + // private Map resourceAttributesMap; - private boolean configUploaded; + private boolean configUploaded; - private boolean getAutomtnInProgress; - private boolean putAutomtnInProgress; - private boolean postAutomtnInProgress; + private boolean getAutomtnInProgress; + private boolean putAutomtnInProgress; + private boolean postAutomtnInProgress; - private int getAutomtnId; - private int putAutomtnId; - private int postAutomtnId; + private int getAutomtnId; + private int putAutomtnId; + private int postAutomtnId; - private boolean isFavorite; + private boolean isFavorite; public SimulatorResourceModel getResourceModelRef() { return resourceModelRef; @@ -59,15 +55,14 @@ public class RemoteResource { this.resourceModelRef = resourceModel; } - public Map getResourceAttributesMap() { - return resourceAttributesMap; - } - - public void setResourceAttributesMap( - Map resourceAttributesMap) { - this.resourceAttributesMap = resourceAttributesMap; - } - + /* + * public Map getResourceAttributesMap() { + * return resourceAttributesMap; } + * + * public void setResourceAttributesMap( Map resourceAttributesMap) { + * this.resourceAttributesMap = resourceAttributesMap; } + */ public int getGetAutomtnId() { return getAutomtnId; } @@ -140,35 +135,22 @@ public class RemoteResource { this.observed = observed; } - public List getPutPostModel() { - Map attMap = getResourceAttributesMap(); - if (null == attMap || attMap.size() < 1) { - return null; - } - List putPostModelList = new ArrayList(); - String attName; - RemoteResourceAttribute attribute; - PutPostAttributeModel putPostModel; - Iterator attItr = attMap.keySet().iterator(); - while (attItr.hasNext()) { - attName = attItr.next(); - attribute = attMap.get(attName); - putPostModel = PutPostAttributeModel.getModel(attribute); - if (null != putPostModel) { - putPostModelList.add(putPostModel); - } - } - return putPostModelList; - } - - public String getAttributeValue(String attName) { - RemoteResourceAttribute attribute = resourceAttributesMap.get(attName); - if (null == attribute) { - return null; - } - return String.valueOf(attribute.getAttributeValue()); - } - + /* + * public List getPutPostModel() { Map attMap = getResourceAttributesMap(); if (null == + * attMap || attMap.size() < 1) { return null; } List + * putPostModelList = new ArrayList(); String + * attName; RemoteResourceAttribute attribute; PutPostAttributeModel + * putPostModel; Iterator attItr = attMap.keySet().iterator(); while + * (attItr.hasNext()) { attName = attItr.next(); attribute = + * attMap.get(attName); putPostModel = + * PutPostAttributeModel.getModel(attribute); if (null != putPostModel) { + * putPostModelList.add(putPostModel); } } return putPostModelList; } + * + * public String getAttributeValue(String attName) { RemoteResourceAttribute + * attribute = resourceAttributesMap.get(attName); if (null == attribute) { + * return null; } return String.valueOf(attribute.getAttributeValue()); } + */ public int getAutomationtype(int autoId) { if (getAutomtnId == autoId) { return Constants.GET_AUTOMATION_INDEX; @@ -196,4 +178,16 @@ public class RemoteResource { public void setFavorite(boolean isFavorite) { this.isFavorite = isFavorite; } + + public void setResourceRepresentation(SimulatorResourceModel resModel, + boolean ramlUploaded) { + if (mResourceRepresentation == null) + mResourceRepresentation = new ResourceRepresentation(resModel); + else + mResourceRepresentation.update(resModel, ramlUploaded); + } + + public ResourceRepresentation getResourceRepresentation() { + return mResourceRepresentation; + } } diff --git a/service/simulator/java/eclipse-plugin/ClientControllerPlugin/src/oic/simulator/clientcontroller/remoteresource/RemoteResourceAttribute.java b/service/simulator/java/eclipse-plugin/ClientControllerPlugin/src/oic/simulator/clientcontroller/remoteresource/RemoteResourceAttribute.java index e014bdc..0c16341 100644 --- a/service/simulator/java/eclipse-plugin/ClientControllerPlugin/src/oic/simulator/clientcontroller/remoteresource/RemoteResourceAttribute.java +++ b/service/simulator/java/eclipse-plugin/ClientControllerPlugin/src/oic/simulator/clientcontroller/remoteresource/RemoteResourceAttribute.java @@ -22,7 +22,6 @@ import java.util.List; import java.util.Map; import org.oic.simulator.AttributeProperty.Type; -import org.oic.simulator.AttributeValue; import org.oic.simulator.AttributeValue.ValueType; import org.oic.simulator.SimulatorResourceAttribute; diff --git a/service/simulator/java/eclipse-plugin/ClientControllerPlugin/src/oic/simulator/clientcontroller/remoteresource/ResourceRepresentation.java b/service/simulator/java/eclipse-plugin/ClientControllerPlugin/src/oic/simulator/clientcontroller/remoteresource/ResourceRepresentation.java new file mode 100644 index 0000000..724edbb --- /dev/null +++ b/service/simulator/java/eclipse-plugin/ClientControllerPlugin/src/oic/simulator/clientcontroller/remoteresource/ResourceRepresentation.java @@ -0,0 +1,82 @@ +package oic.simulator.clientcontroller.remoteresource; + +import java.util.HashMap; +import java.util.Map; + +import org.oic.simulator.InvalidArgsException; +import org.oic.simulator.SimulatorResourceAttribute; +import org.oic.simulator.SimulatorResourceModel; + +public class ResourceRepresentation { + private Map mAttributes = new HashMap(); + + public ResourceRepresentation(SimulatorResourceModel resourceModel) { + if (resourceModel != null && resourceModel.size() > 0) { + for (Map.Entry entry : resourceModel + .getAttributes().entrySet()) + mAttributes.put(entry.getKey(), new AttributeElement(this, + entry.getValue())); + } + } + + public Map getAttributes() { + return mAttributes; + } + + public void update(SimulatorResourceModel resourceModel, + boolean ramlUploaded) { + for (Map.Entry entry : resourceModel + .getAttributes().entrySet()) { + AttributeElement attributeElement = mAttributes.get(entry.getKey()); + if (attributeElement != null) { + if (ramlUploaded) + attributeElement.updateForRAMLUpload(entry.getValue()); + else + attributeElement.update(entry.getValue()); + } else // Display new attribute in UI + { + AttributeElement newAttribute = new AttributeElement(this, + entry.getValue()); + mAttributes.put(entry.getKey(), newAttribute); + } + } + } + + public SimulatorResourceModel getModel() { + if (null == mAttributes || mAttributes.isEmpty()) { + return null; + } + SimulatorResourceModel model = new SimulatorResourceModel(); + for (Map.Entry entry : mAttributes.entrySet()) { + AttributeElement attributeElement = mAttributes.get(entry.getKey()); + if (attributeElement != null) { + try { + model.addAttribute(attributeElement + .getSimulatorResourceAttribute()); + } catch (InvalidArgsException e) { + e.printStackTrace(); + } + } + } + return model; + } + + public SimulatorResourceModel getSelectedModel() { + if (null == mAttributes || mAttributes.isEmpty()) { + return null; + } + SimulatorResourceModel model = new SimulatorResourceModel(); + for (Map.Entry entry : mAttributes.entrySet()) { + AttributeElement attributeElement = mAttributes.get(entry.getKey()); + if (attributeElement != null && attributeElement.getPostState()) { + try { + model.addAttribute(attributeElement + .getSimulatorResourceAttribute()); + } catch (InvalidArgsException e) { + e.printStackTrace(); + } + } + } + return model; + } +} \ No newline at end of file diff --git a/service/simulator/java/eclipse-plugin/ClientControllerPlugin/src/oic/simulator/clientcontroller/utils/AttributeValueStringConverter.java b/service/simulator/java/eclipse-plugin/ClientControllerPlugin/src/oic/simulator/clientcontroller/utils/AttributeValueStringConverter.java new file mode 100644 index 0000000..e15c5d2 --- /dev/null +++ b/service/simulator/java/eclipse-plugin/ClientControllerPlugin/src/oic/simulator/clientcontroller/utils/AttributeValueStringConverter.java @@ -0,0 +1,327 @@ +package oic.simulator.clientcontroller.utils; + +import java.util.Map; + +import org.oic.simulator.AttributeValue; +import org.oic.simulator.AttributeValueVisitor; +import org.oic.simulator.SimulatorResourceAttribute; +import org.oic.simulator.SimulatorResourceModel; + +public class AttributeValueStringConverter implements + AttributeValueVisitor.VisitingMethods { + + private AttributeValue mValue; + + public AttributeValueStringConverter(AttributeValue value) { + mValue = value; + } + + @Override + public String toString() { + AttributeValueVisitor visitor = new AttributeValueVisitor(mValue, this); + return (String) visitor.visit(); + } + + @Override + public String visitingValue(Integer value) { + return value.toString(); + } + + @Override + public String visitingValue(Double value) { + return value.toString(); + } + + @Override + public String visitingValue(Boolean value) { + return value.toString(); + } + + @Override + public String visitingValue(String value) { + return new String(value); + } + + @Override + public String visitingValue(SimulatorResourceModel value) { + StringBuilder result = new StringBuilder(); + result.append("{"); + boolean first = true; + for (Map.Entry entry : value + .getAttributes().entrySet()) { + if (!first) + result.append(", "); + first = false; + result.append("\"" + entry.getKey() + "\":"); + AttributeValue attributeValue = entry.getValue().value(); + result.append(new AttributeValueStringConverter(attributeValue) + .toString()); + } + + result.append("}"); + return result.toString(); + } + + @Override + public String visitingValue(Integer[] values) { + StringBuilder result = new StringBuilder(); + result.append("["); + boolean first = true; + for (Integer value : values) { + if (!first) + result.append(", "); + first = false; + result.append(value.toString()); + } + + result.append("]"); + return result.toString(); + } + + @Override + public String visitingValue(Double[] values) { + StringBuilder result = new StringBuilder(); + result.append("["); + boolean first = true; + for (Double value : values) { + if (!first) + result.append(", "); + first = false; + result.append(value.toString()); + } + + result.append("]"); + return result.toString(); + } + + @Override + public String visitingValue(Boolean[] values) { + StringBuilder result = new StringBuilder(); + result.append("["); + boolean first = true; + for (Boolean value : values) { + if (!first) + result.append(", "); + first = false; + result.append(value.toString()); + } + + result.append("]"); + return result.toString(); + } + + @Override + public String visitingValue(String[] values) { + StringBuilder result = new StringBuilder(); + result.append("["); + boolean first = true; + for (String value : values) { + if (!first) + result.append(", "); + first = false; + result.append(value); + } + + result.append("]"); + return result.toString(); + } + + @Override + public String visitingValue(SimulatorResourceModel[] values) { + StringBuilder result = new StringBuilder(); + result.append("["); + boolean first = true; + for (SimulatorResourceModel value : values) { + if (!first) + result.append(", "); + first = false; + AttributeValue attributeValue = new AttributeValue(value); + result.append(new AttributeValueStringConverter(attributeValue) + .toString()); + } + + result.append("]"); + return result.toString(); + } + + @Override + public String visitingValue(Integer[][] values) { + StringBuilder result = new StringBuilder(); + result.append("["); + boolean first = true; + for (Integer[] value : values) { + if (!first) + result.append(", "); + first = false; + AttributeValue attributeValue = new AttributeValue(value); + result.append(new AttributeValueStringConverter(attributeValue) + .toString()); + } + + result.append("]"); + return result.toString(); + } + + @Override + public String visitingValue(Double[][] values) { + StringBuilder result = new StringBuilder(); + result.append("["); + boolean first = true; + for (Double[] value : values) { + if (!first) + result.append(", "); + first = false; + AttributeValue attributeValue = new AttributeValue(value); + result.append(new AttributeValueStringConverter(attributeValue) + .toString()); + } + + result.append("]"); + return result.toString(); + } + + @Override + public String visitingValue(Boolean[][] values) { + StringBuilder result = new StringBuilder(); + result.append("["); + boolean first = true; + for (Boolean[] value : values) { + if (!first) + result.append(", "); + first = false; + AttributeValue attributeValue = new AttributeValue(value); + result.append(new AttributeValueStringConverter(attributeValue) + .toString()); + } + + result.append("]"); + return result.toString(); + } + + @Override + public String visitingValue(String[][] values) { + StringBuilder result = new StringBuilder(); + result.append("["); + boolean first = true; + for (String[] value : values) { + if (!first) + result.append(", "); + first = false; + AttributeValue attributeValue = new AttributeValue(value); + result.append(new AttributeValueStringConverter(attributeValue) + .toString()); + } + + result.append("]"); + return result.toString(); + } + + @Override + public String visitingValue(SimulatorResourceModel[][] values) { + StringBuilder result = new StringBuilder(); + result.append("["); + boolean first = true; + for (SimulatorResourceModel[] value : values) { + if (!first) + result.append(", "); + first = false; + AttributeValue attributeValue = new AttributeValue(value); + result.append(new AttributeValueStringConverter(attributeValue) + .toString()); + } + + result.append("]"); + return result.toString(); + } + + @Override + public String visitingValue(Integer[][][] values) { + StringBuilder result = new StringBuilder(); + result.append("["); + boolean first = true; + for (Integer[][] value : values) { + if (!first) + result.append(", "); + first = false; + AttributeValue attributeValue = new AttributeValue(value); + result.append(new AttributeValueStringConverter(attributeValue) + .toString()); + } + + result.append("]"); + return result.toString(); + } + + @Override + public String visitingValue(Double[][][] values) { + StringBuilder result = new StringBuilder(); + result.append("["); + boolean first = true; + for (Double[][] value : values) { + if (!first) + result.append(", "); + first = false; + AttributeValue attributeValue = new AttributeValue(value); + result.append(new AttributeValueStringConverter(attributeValue) + .toString()); + } + + result.append("]"); + return result.toString(); + } + + @Override + public String visitingValue(Boolean[][][] values) { + StringBuilder result = new StringBuilder(); + result.append("["); + boolean first = true; + for (Boolean[][] value : values) { + if (!first) + result.append(", "); + first = false; + AttributeValue attributeValue = new AttributeValue(value); + result.append(new AttributeValueStringConverter(attributeValue) + .toString()); + } + + result.append("]"); + return result.toString(); + } + + @Override + public String visitingValue(String[][][] values) { + StringBuilder result = new StringBuilder(); + result.append("["); + boolean first = true; + for (String[][] value : values) { + if (!first) + result.append(", "); + first = false; + AttributeValue attributeValue = new AttributeValue(value); + result.append(new AttributeValueStringConverter(attributeValue) + .toString()); + } + + result.append("]"); + return result.toString(); + } + + @Override + public String visitingValue(SimulatorResourceModel[][][] values) { + StringBuilder result = new StringBuilder(); + result.append("["); + boolean first = true; + for (SimulatorResourceModel[][] value : values) { + if (!first) + result.append(", "); + first = false; + AttributeValue attributeValue = new AttributeValue(value); + result.append(new AttributeValueStringConverter(attributeValue) + .toString()); + } + + result.append("]"); + return result.toString(); + } + +} diff --git a/service/simulator/java/eclipse-plugin/ClientControllerPlugin/src/oic/simulator/clientcontroller/utils/Utility.java b/service/simulator/java/eclipse-plugin/ClientControllerPlugin/src/oic/simulator/clientcontroller/utils/Utility.java index 254f1f8..9c13390 100644 --- a/service/simulator/java/eclipse-plugin/ClientControllerPlugin/src/oic/simulator/clientcontroller/utils/Utility.java +++ b/service/simulator/java/eclipse-plugin/ClientControllerPlugin/src/oic/simulator/clientcontroller/utils/Utility.java @@ -22,7 +22,10 @@ import java.util.Iterator; import java.util.List; import java.util.Set; +import org.oic.simulator.AttributeValue; import org.oic.simulator.SimulatorException; +import org.oic.simulator.AttributeValue.TypeInfo; +import org.oic.simulator.AttributeValue.ValueType; /** * This class has common utility methods. @@ -93,4 +96,69 @@ public class Utility { } return detail; } + + // This method only works for attributes whose values are of type int, + // double, bool, string and 1-D array of primitive types + public static String getAttributeValueAsString(AttributeValue val) { + if (null == val) { + return null; + } + Object value = val.get(); + if (null == value) { + return null; + } + TypeInfo type = val.typeInfo(); + if (type.mType == ValueType.RESOURCEMODEL + || (type.mType == ValueType.ARRAY && type.mBaseType == ValueType.RESOURCEMODEL) + || (type.mType == ValueType.ARRAY && type.mDepth > 1)) { + return null; + } + if (type.mType == ValueType.ARRAY) { + if (type.mBaseType == ValueType.INTEGER) { + Integer[] values = (Integer[]) value; + if (null == values || values.length < 1) { + return null; + } + List list = new ArrayList(); + for (Integer i : values) { + list.add(i); + } + return list.toString(); + } else if (type.mBaseType == ValueType.DOUBLE) { + Double[] values = (Double[]) value; + if (null == values || values.length < 1) { + return null; + } + List list = new ArrayList(); + for (Double i : values) { + list.add(i); + } + return list.toString(); + } else if (type.mBaseType == ValueType.BOOLEAN) { + Boolean[] values = (Boolean[]) value; + if (null == values || values.length < 1) { + return null; + } + List list = new ArrayList(); + for (Boolean i : values) { + list.add(i); + } + return list.toString(); + } else if (type.mBaseType == ValueType.STRING) { + String[] values = (String[]) value; + if (null == values || values.length < 1) { + return null; + } + List list = new ArrayList(); + for (String i : values) { + list.add(i); + } + return list.toString(); + } else { + return null; + } + } else { + return String.valueOf(value); + } + } } \ No newline at end of file diff --git a/service/simulator/java/eclipse-plugin/ClientControllerPlugin/src/oic/simulator/clientcontroller/view/AttributeEditingSupport.java b/service/simulator/java/eclipse-plugin/ClientControllerPlugin/src/oic/simulator/clientcontroller/view/AttributeEditingSupport.java new file mode 100644 index 0000000..0120f9d --- /dev/null +++ b/service/simulator/java/eclipse-plugin/ClientControllerPlugin/src/oic/simulator/clientcontroller/view/AttributeEditingSupport.java @@ -0,0 +1,414 @@ +/* + * Copyright 2015 Samsung Electronics All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package oic.simulator.clientcontroller.view; + +import java.util.List; + +import oic.simulator.clientcontroller.Activator; +import oic.simulator.clientcontroller.manager.ResourceManager; +import oic.simulator.clientcontroller.remoteresource.AttributeElement; +import oic.simulator.clientcontroller.remoteresource.RemoteResource; +import oic.simulator.clientcontroller.utils.AttributeValueBuilder; +import oic.simulator.clientcontroller.utils.Utility; +import oic.simulator.clientcontroller.view.dialogs.PostRequestDialog; + +import org.eclipse.jface.dialogs.TitleAreaDialog; +import org.eclipse.jface.viewers.CellEditor; +import org.eclipse.jface.viewers.CheckboxCellEditor; +import org.eclipse.jface.viewers.ComboBoxCellEditor; +import org.eclipse.jface.viewers.EditingSupport; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.jface.viewers.TreeViewer; +import org.eclipse.swt.SWT; +import org.eclipse.swt.custom.CCombo; +import org.eclipse.swt.events.ModifyEvent; +import org.eclipse.swt.events.ModifyListener; +import org.eclipse.swt.widgets.MessageBox; +import org.eclipse.swt.widgets.Tree; +import org.eclipse.swt.widgets.TreeItem; +import org.oic.simulator.AttributeValue; +import org.oic.simulator.AttributeValue.TypeInfo; +import org.oic.simulator.AttributeValue.ValueType; +import org.oic.simulator.InvalidArgsException; +import org.oic.simulator.SimulatorResourceAttribute; + +/** + * This class provides editing support to the resources attributes table in the + * attributes view. + */ +public class AttributeEditingSupport { + + private AttributeValueEditor attValueEditor; + private PostRequestEditor postReqEditor; + + public AttributeValueEditor createAttributeValueEditor(TreeViewer viewer, + TitleAreaDialog dialog) { + attValueEditor = new AttributeValueEditor(viewer, dialog); + return attValueEditor; + } + + public PostRequestEditor createAutomationEditor(TreeViewer viewer) { + postReqEditor = new PostRequestEditor(viewer); + return postReqEditor; + } + + class AttributeValueEditor extends EditingSupport { + + private final TreeViewer viewer; + private CCombo comboBox; + private TitleAreaDialog dialog; + + public AttributeValueEditor(TreeViewer viewer, TitleAreaDialog dialog) { + super(viewer); + this.viewer = viewer; + this.dialog = dialog; + } + + @Override + protected boolean canEdit(Object arg0) { + return true; + } + + @Override + protected CellEditor getCellEditor(final Object element) { + ResourceManager resourceManager = Activator.getDefault() + .getResourceManager(); + + RemoteResource res = resourceManager + .getCurrentResourceInSelection(); + if (null == res) { + return null; + } + + final SimulatorResourceAttribute attribute; + if (!(element instanceof AttributeElement)) { + return null; + } + + final AttributeElement attributeElement = ((AttributeElement) element); + attribute = attributeElement.getSimulatorResourceAttribute(); + if (null == attribute) { + return null; + } + + final AttributeValue val = attribute.value(); + if (null == val) { + return null; + } + + final TypeInfo type = val.typeInfo(); + if (type.mBaseType == ValueType.RESOURCEMODEL) { + return null; + } + + String values[] = null; + List valueSet = resourceManager + .getAllValuesOfAttribute(attribute); + values = convertListToStringArray(valueSet); + + ComboBoxCellEditor comboEditor; + comboEditor = new ComboBoxCellEditor(viewer.getTree(), values); + comboBox = (CCombo) comboEditor.getControl(); + comboBox.addModifyListener(new ModifyListener() { + + @Override + public void modifyText(ModifyEvent event) { + + String newValue = comboBox.getText(); + + if (null != newValue && !newValue.isEmpty()) { + attributeElement.setPostState(true); + } else { + attributeElement.setPostState(false); + } + + /* + * if (type.mType == ValueType.ARRAY) { return; } + */ + /* + * String oldValue = String.valueOf(Utility + * .getAttributeValueAsString(val)); String newValue = + * comboBox.getText(); + * + * if (null != newValue && !newValue.isEmpty()) { + * attributeElement.setPostState(true); } else { + * attributeElement.setPostState(false); } + * + * if (!oldValue.equals(newValue)) { // Get the + * AttriuteValue from the string AttributeValue value = + * AttributeValueBuilder.build( newValue, type.mBaseType); + * TypeInfo resTypeInfo = value.typeInfo(); if (null == + * value || type.mDepth != resTypeInfo.mDepth || type.mType + * != resTypeInfo.mType || type.mBaseType != + * resTypeInfo.mBaseType) { MessageBox dialog = new + * MessageBox(viewer.getTree() .getShell(), SWT.ICON_ERROR | + * SWT.OK); dialog.setText("Invalid Value"); + * dialog.setMessage("Given value is invalid"); + * dialog.open(); } else { updateAttributeValue(attribute, + * value); } } + */ + if (dialog instanceof PostRequestDialog) { + viewer.update(attributeElement, null); + // comboBox.setVisible(false); + } + } + }); + return comboEditor; + } + + @Override + protected Object getValue(Object element) { + int indexOfItem = 0; + SimulatorResourceAttribute att = null; + + if (element instanceof AttributeElement) { + att = ((AttributeElement) element) + .getSimulatorResourceAttribute(); + } + + if (att == null) { + return 0; + } + + String valueString = Utility.getAttributeValueAsString(att.value()); + List valueSet = Activator.getDefault().getResourceManager() + .getAllValuesOfAttribute(att); + if (null != valueSet) { + indexOfItem = valueSet.indexOf(valueString); + } + if (indexOfItem == -1) { + indexOfItem = 0; + } + return indexOfItem; + } + + @Override + protected void setValue(Object element, Object value) { + SimulatorResourceAttribute att = null; + if (element instanceof AttributeElement) { + att = ((AttributeElement) element) + .getSimulatorResourceAttribute(); + } + + if (att == null) { + return; + } + + AttributeValue val = att.value(); + if (null == val) { + return; + } + + TypeInfo type = val.typeInfo(); + /* + * if (type.mType == ValueType.ARRAY) { int index; try { index = + * Integer.parseInt(String.valueOf(value)); } catch + * (NumberFormatException nfe) { index = -1; } if (index == -1) { + * String oldValue = String.valueOf(Utility + * .getAttributeValueAsString(val)); String newValue = + * comboBox.getText(); if (!oldValue.equals(newValue)) { // Get the + * AttriuteValue from the string AttributeValue attValue = + * AttributeValueBuilder.build( newValue, type.mBaseType); TypeInfo + * resTypeInfo = attValue.typeInfo(); if (null == attValue || + * type.mDepth != resTypeInfo.mDepth || type.mType != + * resTypeInfo.mType || type.mBaseType != resTypeInfo.mBaseType) { + * MessageBox dialog = new MessageBox(viewer.getTree() .getShell(), + * SWT.ICON_ERROR | SWT.OK); dialog.setText("Invalid Value"); + * dialog.setMessage("Given value is invalid"); dialog.open(); } + * else { updateAttributeValue(att, attValue); } } } } + */ + + String oldValue = String.valueOf(Utility + .getAttributeValueAsString(val)); + String newValue = comboBox.getText(); + if (!oldValue.equals(newValue)) { + // Get the AttriuteValue from the string + AttributeValue attValue = AttributeValueBuilder.build(newValue, + type.mBaseType); + TypeInfo resTypeInfo = attValue.typeInfo(); + if (null == attValue || type.mDepth != resTypeInfo.mDepth + || type.mType != resTypeInfo.mType + || type.mBaseType != resTypeInfo.mBaseType) { + MessageBox dialog = new MessageBox(viewer.getTree() + .getShell(), SWT.ICON_ERROR | SWT.OK); + dialog.setText("Invalid Value"); + dialog.setMessage("Given value is invalid"); + dialog.open(); + } else { + updateAttributeValue(att, attValue); + } + } + + viewer.update(element, null); + } + + public String[] convertListToStringArray(List values) { + String[] strArr; + if (null != values && values.size() > 0) { + strArr = values.toArray(new String[1]); + } else { + strArr = new String[1]; + } + return strArr; + } + + public void updateAttributeValue(SimulatorResourceAttribute att, + AttributeValue value) { + att.setValue(value); + + IStructuredSelection selection = (IStructuredSelection) viewer + .getSelection(); + if (null == selection) { + return; + } + + Object obj = selection.getFirstElement(); + if (null == obj) { + return; + } + + Tree t = viewer.getTree(); + TreeItem item = t.getSelection()[0]; + if (null == item) { + return; + } + + TreeItem parent = item.getParentItem(); + if (null != parent) { + while (parent.getParentItem() != null) { + parent = parent.getParentItem(); + } + Object data = parent.getData(); + ((AttributeElement) data).setPostState(true); + } + + if (item.getData() instanceof AttributeElement) { + AttributeElement attributeElement = (AttributeElement) item + .getData(); + attributeElement.getSimulatorResourceAttribute() + .setValue(value); + + parent = item.getParentItem(); + if (null != parent) { + Object data = parent.getData(); + try { + ((AttributeElement) data).deepSetChildValue(att); + } catch (InvalidArgsException e) { + e.printStackTrace(); + } + } + } + } + + public AttributeValue getResultantValue(AttributeValue newValue) { + AttributeValue val = null; + IStructuredSelection selection = (IStructuredSelection) viewer + .getSelection(); + if (null == selection) { + return null; + } + + Object obj = selection.getFirstElement(); + if (null == obj) { + return null; + } + + Tree t = viewer.getTree(); + TreeItem item = t.getSelection()[0]; + if (null == item) { + return null; + } + + TreeItem parent = item.getParentItem(); + if (null == parent) { + val = newValue; + } else { + while (parent.getParentItem() != null) { + parent = parent.getParentItem(); + } + // Parent will point to the top-level attribute of type + // LocalResourceAttribute + Object data = parent.getData(); + val = ((AttributeElement) data).getSimulatorResourceAttribute() + .value(); + } + + return val; + } + } + + class PostRequestEditor extends EditingSupport { + + private final TreeViewer viewer; + + public PostRequestEditor(TreeViewer viewer) { + super(viewer); + this.viewer = viewer; + } + + @Override + protected boolean canEdit(Object arg0) { + return true; + } + + @Override + protected CellEditor getCellEditor(Object element) { + SimulatorResourceAttribute att = null; + if (element instanceof AttributeElement) { + att = ((AttributeElement) element) + .getSimulatorResourceAttribute(); + } + + if (null == att) { + return null; + } + + AttributeValue val = att.value(); + if (null == val) { + return null; + } + + TypeInfo type = val.typeInfo(); + + if (type.mType == ValueType.RESOURCEMODEL + || type.mBaseType == ValueType.RESOURCEMODEL) { + return null; + } + + return new CheckboxCellEditor(null, SWT.CHECK | SWT.READ_ONLY); + } + + @Override + protected Object getValue(Object element) { + if (element instanceof AttributeElement) { + return ((AttributeElement) element).getPostState(); + } + + return false; + } + + @Override + protected void setValue(Object element, Object value) { + if (!(element instanceof AttributeElement)) { + return; + } + boolean status = (Boolean) value; + ((AttributeElement) element).setPostState(status); + viewer.update(element, null); + } + } +} 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 e61d484..953e8f0 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 @@ -16,7 +16,6 @@ package oic.simulator.clientcontroller.view; -import java.util.List; import java.util.Map; import oic.simulator.clientcontroller.Activator; @@ -28,35 +27,39 @@ import oic.simulator.clientcontroller.listener.IPutUIListener; import oic.simulator.clientcontroller.listener.IResourceSelectionChangedUIListener; import oic.simulator.clientcontroller.listener.IVerificationUIListener; import oic.simulator.clientcontroller.manager.ResourceManager; -import oic.simulator.clientcontroller.remoteresource.PutPostAttributeModel; +import oic.simulator.clientcontroller.remoteresource.AttributeElement; import oic.simulator.clientcontroller.remoteresource.RemoteResource; -import oic.simulator.clientcontroller.remoteresource.RemoteResourceAttribute; +import oic.simulator.clientcontroller.remoteresource.ResourceRepresentation; import oic.simulator.clientcontroller.utils.Constants; +import oic.simulator.clientcontroller.utils.Utility; import oic.simulator.clientcontroller.view.dialogs.PostRequestDialog; import oic.simulator.clientcontroller.view.dialogs.PutRequestDialog; import oic.simulator.clientcontroller.view.dialogs.VerificationDialog; import org.eclipse.jface.dialogs.MessageDialog; -import org.eclipse.jface.viewers.IStructuredContentProvider; -import org.eclipse.jface.viewers.StyledCellLabelProvider; -import org.eclipse.jface.viewers.TableViewer; -import org.eclipse.jface.viewers.TableViewerColumn; +import org.eclipse.jface.viewers.ILabelProviderListener; +import org.eclipse.jface.viewers.ITableLabelProvider; +import org.eclipse.jface.viewers.ITreeContentProvider; +import org.eclipse.jface.viewers.TreeViewer; import org.eclipse.jface.viewers.Viewer; -import org.eclipse.jface.viewers.ViewerCell; import org.eclipse.jface.window.Window; import org.eclipse.swt.SWT; import org.eclipse.swt.events.SelectionAdapter; import org.eclipse.swt.events.SelectionEvent; import org.eclipse.swt.graphics.Color; +import org.eclipse.swt.graphics.Image; import org.eclipse.swt.layout.GridData; import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.widgets.Button; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Group; -import org.eclipse.swt.widgets.Table; +import org.eclipse.swt.widgets.Tree; +import org.eclipse.swt.widgets.TreeColumn; import org.eclipse.ui.PlatformUI; import org.eclipse.ui.part.ViewPart; +import org.oic.simulator.AttributeValue.ValueType; +import org.oic.simulator.SimulatorResourceAttribute; import org.oic.simulator.client.SimulatorRemoteResource.VerificationType; /** @@ -66,7 +69,7 @@ public class AttributeView extends ViewPart { public static final String VIEW_ID = "oic.simulator.clientcontroller.view.attribute"; - private TableViewer attTblViewer; + private TreeViewer attViewer; private Button getButton; private Button putButton; @@ -107,9 +110,9 @@ public class AttributeView extends ViewPart { setVisibility((resource == null) ? false : true); // Update the attribute table - if (null != attTblViewer - && !attTblViewer.getControl().isDisposed()) { - updateViewer(getData(resource)); + if (null != attViewer + && !attViewer.getControl().isDisposed()) { + updateViewer(resource); } // Update the observe status @@ -134,7 +137,7 @@ public class AttributeView extends ViewPart { if (resourceInSelection != resource) { return; } - updateViewer(getData(resource)); + updateViewer(resource); // Update the observe status updateObserve(resource); @@ -158,7 +161,7 @@ public class AttributeView extends ViewPart { if (resourceInSelection != resource) { return; } - updateViewer(getData(resource)); + updateViewer(resource); // Update the observe status updateObserve(resource); @@ -182,7 +185,7 @@ public class AttributeView extends ViewPart { if (resourceInSelection != resource) { return; } - updateViewer(getData(resource)); + updateViewer(resource); // Update the observe status updateObserve(resource); @@ -206,7 +209,7 @@ public class AttributeView extends ViewPart { if (resourceInSelection != resource) { return; } - updateViewer(getData(resource)); + updateViewer(resource); // Update the observe status updateObserve(resource); @@ -293,28 +296,20 @@ public class AttributeView extends ViewPart { } } - private Map getData(RemoteResource resource) { - if (null == resource) { - return null; + private void updateViewer(RemoteResource resource) { + if (null == attViewer) { + return; } - Map attMap = resource - .getResourceAttributesMap(); - return attMap; - } - - private void updateViewer(Map attMap) { - if (null != attTblViewer) { - Table tbl = attTblViewer.getTable(); - if (null != attMap) { - attTblViewer.setInput(attMap.entrySet().toArray()); - if (!tbl.isDisposed()) { - tbl.setLinesVisible(true); - } - } else { - if (!tbl.isDisposed()) { - tbl.removeAll(); - tbl.setLinesVisible(false); - } + Tree tree = attViewer.getTree(); + if (null != resource) { + attViewer.setInput(resource.getResourceRepresentation()); + if (!tree.isDisposed()) { + tree.setLinesVisible(true); + } + } else { + if (!tree.isDisposed()) { + tree.removeAll(); + tree.setLinesVisible(false); } } } @@ -363,9 +358,8 @@ public class AttributeView extends ViewPart { setVisibility(false); // Updating the data in the UI as per the resource in selection. - if (null != attTblViewer && !attTblViewer.getControl().isDisposed()) { - updateViewer(getData(resourceManager - .getCurrentResourceInSelection())); + if (null != attViewer && !attViewer.getControl().isDisposed()) { + updateViewer(resourceManager.getCurrentResourceInSelection()); } } @@ -421,57 +415,34 @@ public class AttributeView extends ViewPart { } private void setupAttributeTable(Group attGroup) { - attTblViewer = new TableViewer(attGroup, SWT.SINGLE | SWT.H_SCROLL - | SWT.V_SCROLL | SWT.FULL_SELECTION | SWT.BORDER); + Tree addressTree = new Tree(attGroup, SWT.SINGLE | SWT.BORDER + | SWT.H_SCROLL | SWT.V_SCROLL | SWT.FULL_SELECTION); + addressTree.setHeaderVisible(true); - createAttributeColumns(attTblViewer); + attViewer = new TreeViewer(addressTree); + + createAttributeColumns(attViewer); // make lines and header visible - Table table = attTblViewer.getTable(); - table.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); - table.setHeaderVisible(true); - table.setLinesVisible(true); + Tree tree = attViewer.getTree(); + tree.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); + tree.setHeaderVisible(true); + tree.setLinesVisible(true); - attTblViewer.setContentProvider(new AttributeContentProvider()); + attViewer.setContentProvider(new AttributeContentProvider()); + attViewer.setLabelProvider(new AttributeLabelProvider()); } - public void createAttributeColumns(TableViewer tableViewer) { + public void createAttributeColumns(TreeViewer viewer) { + Tree tree = viewer.getTree(); - TableViewerColumn attName = new TableViewerColumn(tableViewer, SWT.NONE); - attName.getColumn().setWidth(attTblColWidth[0]); - attName.getColumn().setText(attTblHeaders[0]); - attName.setLabelProvider(new StyledCellLabelProvider() { - @Override - public void update(ViewerCell cell) { - Object element = cell.getElement(); - if (element instanceof Map.Entry) { - @SuppressWarnings("unchecked") - Map.Entry entry = (Map.Entry) element; - cell.setText(entry.getKey()); - } - } - }); + TreeColumn attName = new TreeColumn(tree, SWT.NONE); + attName.setWidth(attTblColWidth[0]); + attName.setText(attTblHeaders[0]); - TableViewerColumn attValue = new TableViewerColumn(tableViewer, - SWT.NONE); - attValue.getColumn().setWidth(attTblColWidth[1]); - attValue.getColumn().setText(attTblHeaders[1]); - attValue.setLabelProvider(new StyledCellLabelProvider() { - @Override - public void update(ViewerCell cell) { - Object element = cell.getElement(); - if (element instanceof Map.Entry) { - @SuppressWarnings("unchecked") - Map.Entry entry = (Map.Entry) element; - Object value = entry.getValue().getAttributeValue(); - if (null == value) { - cell.setText(""); - } else { - cell.setText(String.valueOf(value)); - } - } - } - }); + TreeColumn attValue = new TreeColumn(tree, SWT.NONE); + attValue.setWidth(attTblColWidth[1]); + attValue.setText(attTblHeaders[1]); } private void setUIListeners() { @@ -503,10 +474,8 @@ public class AttributeView extends ViewPart { "PUT Automation is in progress. Please wait or stop the automation."); return; } - List putPostModelList; - putPostModelList = resourceInSelection - .getPutPostModel(); - if (null == putPostModelList) { + if (resourceInSelection.getResourceRepresentation() + .getAttributes().size() < 1) { MessageDialog .openInformation(Display.getDefault() .getActiveShell(), "PUT Request", @@ -514,12 +483,12 @@ public class AttributeView extends ViewPart { return; } PutRequestDialog putDialog = new PutRequestDialog( - Display.getDefault().getActiveShell(), - putPostModelList); + Display.getDefault().getActiveShell()); if (putDialog.open() == Window.OK) { // Call the native PUT method resourceManager.sendPutRequest(resourceInSelection, - putPostModelList); + putDialog.getUpdatedRepresentation() + .getModel()); } } }); @@ -539,24 +508,24 @@ public class AttributeView extends ViewPart { "POST Automation is in progress. Please wait or stop the automation."); return; } - List putPostModelList; - putPostModelList = resourceInSelection - .getPutPostModel(); - if (null == putPostModelList) { + if (resourceInSelection.getResourceRepresentation() + .getAttributes().size() < 1) { MessageDialog .openInformation(Display.getDefault() - .getActiveShell(), "PUT Request", + .getActiveShell(), "POST Request", "No attributes exist in the resource model."); return; } PostRequestDialog postDialog = new PostRequestDialog( - Display.getDefault().getActiveShell(), - putPostModelList); + Display.getDefault().getActiveShell()); if (postDialog.open() == Window.OK) { // Call the native POST method + ResourceRepresentation representation = postDialog + .getUpdatedRepresentation(); resourceManager.sendPostRequest( - resourceInSelection, putPostModelList); + resourceInSelection, + representation.getSelectedModel()); } } }); @@ -756,21 +725,103 @@ public class AttributeView extends ViewPart { observeResButton.setEnabled(visibility); } - class AttributeContentProvider implements IStructuredContentProvider { + class AttributeContentProvider implements ITreeContentProvider { @Override public void dispose() { } @Override - public void inputChanged(Viewer viewer, Object arg1, Object arg2) { + public void inputChanged(Viewer viewer, Object oldAttribute, + Object newAttribute) { + } + + @Override + public Object[] getChildren(Object attribute) { + if (attribute instanceof AttributeElement) { + return ((AttributeElement) attribute).getChildren().values() + .toArray(); + } + + return new Object[0]; + } + + @Override + public Object getParent(Object attribute) { + if (attribute instanceof AttributeElement) + return ((AttributeElement) attribute).getParent(); + return null; } @Override - public Object[] getElements(Object element) { - return (Object[]) element; + public boolean hasChildren(Object attribute) { + if (attribute instanceof AttributeElement) + return ((AttributeElement) attribute).hasChildren(); + return false; } + @Override + public Object[] getElements(Object resourceModel) { + if (resourceModel instanceof ResourceRepresentation) { + return ((ResourceRepresentation) resourceModel).getAttributes() + .values().toArray(); + } + + return new Object[0]; + } + } + + class AttributeLabelProvider implements ITableLabelProvider { + + @Override + public void addListener(ILabelProviderListener arg0) { + } + + @Override + public void dispose() { + } + + @Override + public boolean isLabelProperty(Object arg0, String arg1) { + return false; + } + + @Override + public void removeListener(ILabelProviderListener arg0) { + + } + + @Override + public Image getColumnImage(Object element, int col) { + return null; + } + + @Override + public String getColumnText(Object element, int column) { + if (element instanceof AttributeElement) { + AttributeElement attrElement = (AttributeElement) element; + switch (column) { + case 0: // Attribute name column + { + SimulatorResourceAttribute attribute = attrElement + .getSimulatorResourceAttribute(); + return attribute.name(); + } + + case 1: // Attribute value column + { + SimulatorResourceAttribute attribute = attrElement + .getSimulatorResourceAttribute(); + + if (attribute.value().typeInfo().mBaseType != ValueType.RESOURCEMODEL) + return Utility.getAttributeValueAsString(attribute + .value()); + return null; + } + } + } + return null; + } } @Override 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 2e9bc3c..2dec196 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 @@ -16,60 +16,52 @@ package oic.simulator.clientcontroller.view.dialogs; -import java.util.Iterator; -import java.util.List; - import oic.simulator.clientcontroller.Activator; -import oic.simulator.clientcontroller.manager.ResourceManager; -import oic.simulator.clientcontroller.remoteresource.PutPostAttributeModel; +import oic.simulator.clientcontroller.remoteresource.AttributeElement; +import oic.simulator.clientcontroller.remoteresource.RemoteResource; +import oic.simulator.clientcontroller.remoteresource.ResourceRepresentation; import oic.simulator.clientcontroller.utils.Constants; +import oic.simulator.clientcontroller.utils.Utility; +import oic.simulator.clientcontroller.view.AttributeEditingSupport; import org.eclipse.jface.dialogs.IDialogConstants; -import org.eclipse.jface.dialogs.MessageDialog; import org.eclipse.jface.dialogs.TitleAreaDialog; -import org.eclipse.jface.viewers.CellEditor; -import org.eclipse.jface.viewers.CheckboxCellEditor; -import org.eclipse.jface.viewers.ColumnLabelProvider; -import org.eclipse.jface.viewers.ComboBoxCellEditor; -import org.eclipse.jface.viewers.EditingSupport; -import org.eclipse.jface.viewers.IStructuredContentProvider; -import org.eclipse.jface.viewers.IStructuredSelection; -import org.eclipse.jface.viewers.StyledCellLabelProvider; -import org.eclipse.jface.viewers.TableViewer; -import org.eclipse.jface.viewers.TableViewerColumn; +import org.eclipse.jface.viewers.ILabelProviderListener; +import org.eclipse.jface.viewers.ITableLabelProvider; +import org.eclipse.jface.viewers.ITreeContentProvider; +import org.eclipse.jface.viewers.TreeViewer; +import org.eclipse.jface.viewers.TreeViewerColumn; import org.eclipse.jface.viewers.Viewer; -import org.eclipse.jface.viewers.ViewerCell; import org.eclipse.swt.SWT; -import org.eclipse.swt.custom.CCombo; -import org.eclipse.swt.events.ModifyEvent; -import org.eclipse.swt.events.ModifyListener; import org.eclipse.swt.graphics.Image; import org.eclipse.swt.layout.GridData; import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.widgets.Button; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Control; -import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Shell; -import org.eclipse.swt.widgets.Table; +import org.eclipse.swt.widgets.Tree; +import org.eclipse.swt.widgets.TreeColumn; +import org.oic.simulator.AttributeValue.ValueType; +import org.oic.simulator.SimulatorResourceAttribute; /** * This dialog is used for generating a POST request. */ public class PostRequestDialog extends TitleAreaDialog { - private TableViewer attTblViewer; + private TreeViewer attViewer; + + private AttributeEditingSupport attributeEditor; - private final String[] attTblHeaders = { "Name", "Value", - "Select" }; - private final Integer[] attTblColWidth = { 200, 200, 50 }; + private ResourceRepresentation updatedRepresentation; - private List modelList = null; + private final String[] attTblHeaders = { "Name", "Value", + "Select" }; + private final Integer[] attTblColWidth = { 200, 200, 50 }; - public PostRequestDialog(Shell parentShell, - List modelList) { + public PostRequestDialog(Shell parentShell) { super(parentShell); - this.modelList = modelList; } @Override @@ -89,270 +81,203 @@ public class PostRequestDialog extends TitleAreaDialog { layout.marginTop = 10; container.setLayout(layout); - createTableViewer(container); - - attTblViewer.setInput(modelList.toArray()); + createTreeViewer(container); - return compLayout; - } + RemoteResource resource = Activator.getDefault().getResourceManager() + .getCurrentResourceInSelection(); - private void createTableViewer(Composite parent) { - attTblViewer = new TableViewer(parent, SWT.SINGLE | SWT.H_SCROLL - | SWT.V_SCROLL | SWT.FULL_SELECTION | SWT.BORDER); + updatedRepresentation = new ResourceRepresentation( + resource.getResourceModelRef()); - createAttributeColumns(attTblViewer); + attViewer.setInput(updatedRepresentation); - // make lines and header visible - Table table = attTblViewer.getTable(); - table.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); - table.setHeaderVisible(true); - table.setLinesVisible(true); - - attTblViewer.setContentProvider(new AttributeContentProvider()); + return compLayout; } - public void createAttributeColumns(TableViewer tableViewer) { - - // attributeEditor = new AttributeEditingSupport(); + private void createTreeViewer(Composite parent) { + Tree addressTree = new Tree(parent, SWT.SINGLE | SWT.BORDER + | SWT.H_SCROLL | SWT.V_SCROLL | SWT.FULL_SELECTION); + addressTree.setHeaderVisible(true); - TableViewerColumn attName = new TableViewerColumn(tableViewer, SWT.NONE); - attName.getColumn().setWidth(attTblColWidth[0]); - attName.getColumn().setText(attTblHeaders[0]); - attName.setLabelProvider(new StyledCellLabelProvider() { - @Override - public void update(ViewerCell cell) { - Object element = cell.getElement(); - if (element instanceof PutPostAttributeModel) { - PutPostAttributeModel entry = (PutPostAttributeModel) element; - cell.setText(entry.getAttName()); - } - } - }); - - TableViewerColumn attValue = new TableViewerColumn(tableViewer, - SWT.NONE); - attValue.getColumn().setWidth(attTblColWidth[1]); - attValue.getColumn().setText(attTblHeaders[1]); - attValue.setLabelProvider(new StyledCellLabelProvider() { - @Override - public void update(ViewerCell cell) { - Object element = cell.getElement(); - if (element instanceof PutPostAttributeModel) { - PutPostAttributeModel entry = (PutPostAttributeModel) element; - cell.setText(entry.getAttValue()); - } - } - }); - - attValue.setEditingSupport(new AttributeValueEditor(attTblViewer)); - - TableViewerColumn updateColumn = new TableViewerColumn(tableViewer, - SWT.NONE); - updateColumn.getColumn().setWidth(attTblColWidth[2]); - updateColumn.getColumn().setText(attTblHeaders[2]); - updateColumn.setLabelProvider(new ColumnLabelProvider() { - @Override - public String getText(Object element) { - return ""; - } + attViewer = new TreeViewer(addressTree); - @Override - public Image getImage(Object element) { - PutPostAttributeModel model = (PutPostAttributeModel) element; - if (model.isModified()) { - return Activator.getDefault().getImageRegistry() - .get(Constants.CHECKED); - } - return Activator.getDefault().getImageRegistry() - .get(Constants.UNCHECKED); - } - }); - updateColumn.setEditingSupport(new UpdateEditor(attTblViewer)); - } + createAttributeColumns(attViewer); - @Override - protected boolean isResizable() { - return true; - } + // make lines and header visible + Tree tree = attViewer.getTree(); + tree.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); + tree.setHeaderVisible(true); + tree.setLinesVisible(true); - @Override - public boolean isHelpAvailable() { - return false; + attViewer.setContentProvider(new AttributeContentProvider()); + attViewer.setLabelProvider(new AttributeLabelProvider()); } - @Override - protected Button createButton(Composite parent, int id, String label, - boolean defaultButton) { - if (id == IDialogConstants.OK_ID) { - label = "POST"; - } - return super.createButton(parent, id, label, defaultButton); + public void createAttributeColumns(TreeViewer viewer) { + Tree tree = viewer.getTree(); + + attributeEditor = new AttributeEditingSupport(); + + TreeColumn attName = new TreeColumn(tree, SWT.NONE); + attName.setWidth(attTblColWidth[0]); + attName.setText(attTblHeaders[0]); + + TreeColumn attValue = new TreeColumn(tree, SWT.NONE); + attValue.setWidth(attTblColWidth[1]); + attValue.setText(attTblHeaders[1]); + TreeViewerColumn attValueVwrCol = new TreeViewerColumn(attViewer, + attValue); + attValueVwrCol.setEditingSupport(attributeEditor + .createAttributeValueEditor(attViewer, this)); + + TreeColumn updateColumn = new TreeColumn(tree, SWT.NONE); + updateColumn.setWidth(attTblColWidth[2]); + updateColumn.setText(attTblHeaders[2]); + TreeViewerColumn updateVwrCol = new TreeViewerColumn(attViewer, + updateColumn); + updateVwrCol.setEditingSupport(attributeEditor + .createAutomationEditor(attViewer)); } - class AttributeContentProvider implements IStructuredContentProvider { + class AttributeContentProvider implements ITreeContentProvider { @Override public void dispose() { } @Override - public void inputChanged(Viewer arg0, Object arg1, Object arg2) { + public void inputChanged(Viewer viewer, Object oldAttribute, + Object newAttribute) { } @Override - public Object[] getElements(Object element) { - return (Object[]) element; - } - - } - - class AttributeValueEditor extends EditingSupport { - private final TableViewer viewer; - private CCombo comboBox; + public Object[] getChildren(Object attribute) { + if (attribute instanceof AttributeElement) { + return ((AttributeElement) attribute).getChildren().values() + .toArray(); + } - public AttributeValueEditor(TableViewer viewer) { - super(viewer); - this.viewer = viewer; + return new Object[0]; } @Override - protected boolean canEdit(Object arg0) { - return true; - } - - @Override - protected CellEditor getCellEditor(Object element) { - PutPostAttributeModel attributeInSelection = (PutPostAttributeModel) element; - - String values[] = null; - List valueSet = attributeInSelection.getValues(); - values = convertListToStringArray(valueSet); - - ComboBoxCellEditor comboEditor = new ComboBoxCellEditor( - viewer.getTable(), values); - comboBox = (CCombo) comboEditor.getControl(); - if (null != comboBox) { - comboBox.addModifyListener(new ModifyListener() { - @Override - public void modifyText(ModifyEvent e) { - IStructuredSelection selection = (IStructuredSelection) AttributeValueEditor.this.viewer - .getSelection(); - PutPostAttributeModel att = (PutPostAttributeModel) selection - .getFirstElement(); - if (null == att) { - return; - } - String newValue = comboBox.getText(); - if (null != newValue && !newValue.isEmpty()) { - att.setModified(true); - } else { - att.setModified(false); - } - AttributeValueEditor.this.viewer.update(att, null); - } - }); - } - return comboEditor; + public Object getParent(Object attribute) { + if (attribute instanceof AttributeElement) + return ((AttributeElement) attribute).getParent(); + return null; } @Override - protected Object getValue(Object element) { - int indexOfItem = 0; - PutPostAttributeModel att = (PutPostAttributeModel) element; - String valueString = att.getAttValue(); - List valueSet = att.getValues(); - if (null != valueSet) { - indexOfItem = valueSet.indexOf(valueString); - } - if (indexOfItem == -1) { - indexOfItem = 0; - } - return indexOfItem; + public boolean hasChildren(Object attribute) { + if (attribute instanceof AttributeElement) + return ((AttributeElement) attribute).hasChildren(); + return false; } @Override - protected void setValue(Object element, Object value) { - PutPostAttributeModel att = (PutPostAttributeModel) element; - int index; - try { - index = Integer.parseInt(String.valueOf(value)); - } catch (NumberFormatException nfe) { - index = -1; + public Object[] getElements(Object resourceModel) { + if (resourceModel instanceof ResourceRepresentation) { + return ((ResourceRepresentation) resourceModel).getAttributes() + .values().toArray(); } - String newValue; - if (index == -1) { - newValue = comboBox.getText(); - att.prependNewValue(newValue); - } else { - newValue = att.getValues().get(index); - } - att.setAttValue(newValue); - viewer.update(element, null); - } - public String[] convertListToStringArray(List valueList) { - String[] strArr; - if (null != valueList && valueList.size() > 0) { - strArr = valueList.toArray(new String[1]); - } else { - strArr = new String[1]; - } - return strArr; + return new Object[0]; } } - class UpdateEditor extends EditingSupport { + class AttributeLabelProvider implements ITableLabelProvider { - private final TableViewer viewer; + @Override + public void addListener(ILabelProviderListener arg0) { + } - public UpdateEditor(TableViewer viewer) { - super(viewer); - this.viewer = viewer; + @Override + public void dispose() { } @Override - protected boolean canEdit(Object arg0) { - return true; + public boolean isLabelProperty(Object arg0, String arg1) { + return false; } @Override - protected CellEditor getCellEditor(Object element) { - return new CheckboxCellEditor(null, SWT.CHECK | SWT.READ_ONLY); + public void removeListener(ILabelProviderListener arg0) { + } @Override - protected Object getValue(Object element) { - PutPostAttributeModel model = (PutPostAttributeModel) element; - return model.isModified(); + public Image getColumnImage(Object element, int col) { + if (col == 2) { + if (element instanceof AttributeElement) { + + AttributeElement attrElement = (AttributeElement) element; + if (attrElement.isPostSupported()) { + if (attrElement.getPostState()) { + return Activator.getDefault().getImageRegistry() + .get(Constants.CHECKED); + } else { + return Activator.getDefault().getImageRegistry() + .get(Constants.UNCHECKED); + } + } + } + } + + return null; } @Override - protected void setValue(Object element, Object value) { - PutPostAttributeModel model = (PutPostAttributeModel) element; - boolean status = (Boolean) value; - model.setModified(status); - viewer.update(element, null); + public String getColumnText(Object element, int column) { + if (element instanceof AttributeElement) { + AttributeElement attrElement = (AttributeElement) element; + switch (column) { + case 0: // Attribute name column + { + SimulatorResourceAttribute attribute = attrElement + .getSimulatorResourceAttribute(); + return attribute.name(); + } + + case 1: // Attribute value column + { + SimulatorResourceAttribute attribute = attrElement + .getSimulatorResourceAttribute(); + + if (attribute.value().typeInfo().mBaseType != ValueType.RESOURCEMODEL) + return Utility.getAttributeValueAsString(attribute + .value()); + return null; + } + + case 2: { + return ""; + } + } + } + return null; } } @Override - protected void okPressed() { - String value; - PutPostAttributeModel attModel; - Iterator itr; - itr = modelList.iterator(); - while (itr.hasNext()) { - attModel = itr.next(); - if (null == attModel) { - return; - } - value = attModel.getAttValue(); - if (null == value || value.isEmpty()) { - MessageDialog.openError(Display.getDefault().getActiveShell(), - "Empty value", "Attribute value should not be empty."); - return; - } + protected boolean isResizable() { + return true; + } + + @Override + public boolean isHelpAvailable() { + return false; + } + + @Override + protected Button createButton(Composite parent, int id, String label, + boolean defaultButton) { + if (id == IDialogConstants.OK_ID) { + label = "POST"; } - close(); + return super.createButton(parent, id, label, defaultButton); + } + + public ResourceRepresentation getUpdatedRepresentation() { + return updatedRepresentation; } } 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 69dbeeb..12981f6 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 @@ -16,50 +16,50 @@ package oic.simulator.clientcontroller.view.dialogs; -import java.util.Iterator; -import java.util.List; - -import oic.simulator.clientcontroller.remoteresource.PutPostAttributeModel; +import oic.simulator.clientcontroller.Activator; +import oic.simulator.clientcontroller.remoteresource.AttributeElement; +import oic.simulator.clientcontroller.remoteresource.RemoteResource; +import oic.simulator.clientcontroller.remoteresource.ResourceRepresentation; +import oic.simulator.clientcontroller.utils.Utility; +import oic.simulator.clientcontroller.view.AttributeEditingSupport; import org.eclipse.jface.dialogs.IDialogConstants; -import org.eclipse.jface.dialogs.MessageDialog; import org.eclipse.jface.dialogs.TitleAreaDialog; -import org.eclipse.jface.viewers.CellEditor; -import org.eclipse.jface.viewers.ComboBoxCellEditor; -import org.eclipse.jface.viewers.EditingSupport; -import org.eclipse.jface.viewers.IStructuredContentProvider; -import org.eclipse.jface.viewers.StyledCellLabelProvider; -import org.eclipse.jface.viewers.TableViewer; -import org.eclipse.jface.viewers.TableViewerColumn; +import org.eclipse.jface.viewers.ILabelProviderListener; +import org.eclipse.jface.viewers.ITableLabelProvider; +import org.eclipse.jface.viewers.ITreeContentProvider; +import org.eclipse.jface.viewers.TreeViewer; +import org.eclipse.jface.viewers.TreeViewerColumn; import org.eclipse.jface.viewers.Viewer; -import org.eclipse.jface.viewers.ViewerCell; import org.eclipse.swt.SWT; -import org.eclipse.swt.custom.CCombo; +import org.eclipse.swt.graphics.Image; import org.eclipse.swt.layout.GridData; import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.widgets.Button; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Control; -import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Shell; -import org.eclipse.swt.widgets.Table; +import org.eclipse.swt.widgets.Tree; +import org.eclipse.swt.widgets.TreeColumn; +import org.oic.simulator.AttributeValue.ValueType; +import org.oic.simulator.SimulatorResourceAttribute; /** * This dialog is used for generating a PUT request. */ public class PutRequestDialog extends TitleAreaDialog { - private TableViewer attTblViewer; + private TreeViewer attViewer; + + private AttributeEditingSupport attributeEditor; - private final String[] attTblHeaders = { "Name", "Value" }; - private final Integer[] attTblColWidth = { 200, 200 }; + private ResourceRepresentation updatedRepresentation; - private List modelList = null; + private final String[] attTblHeaders = { "Name", "Value" }; + private final Integer[] attTblColWidth = { 200, 200 }; - public PutRequestDialog(Shell parentShell, - List modelList) { + public PutRequestDialog(Shell parentShell) { super(parentShell); - this.modelList = modelList; } @Override @@ -79,155 +79,155 @@ public class PutRequestDialog extends TitleAreaDialog { layout.marginTop = 10; container.setLayout(layout); - createTableViewer(container); + createTreeViewer(container); + + RemoteResource resource = Activator.getDefault().getResourceManager() + .getCurrentResourceInSelection(); - attTblViewer.setInput(modelList.toArray()); + updatedRepresentation = new ResourceRepresentation( + resource.getResourceModelRef()); + + attViewer.setInput(updatedRepresentation); return compLayout; } - private void createTableViewer(Composite parent) { - attTblViewer = new TableViewer(parent, SWT.SINGLE | SWT.H_SCROLL - | SWT.V_SCROLL | SWT.FULL_SELECTION | SWT.BORDER); + private void createTreeViewer(Composite parent) { + Tree addressTree = new Tree(parent, SWT.SINGLE | SWT.BORDER + | SWT.H_SCROLL | SWT.V_SCROLL | SWT.FULL_SELECTION); + addressTree.setHeaderVisible(true); + + attViewer = new TreeViewer(addressTree); - createAttributeColumns(attTblViewer); + createAttributeColumns(attViewer); // make lines and header visible - Table table = attTblViewer.getTable(); - table.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); - table.setHeaderVisible(true); - table.setLinesVisible(true); + Tree tree = attViewer.getTree(); + tree.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); + tree.setHeaderVisible(true); + tree.setLinesVisible(true); - attTblViewer.setContentProvider(new AttributeContentProvider()); + attViewer.setContentProvider(new AttributeContentProvider()); + attViewer.setLabelProvider(new AttributeLabelProvider()); } - public void createAttributeColumns(TableViewer tableViewer) { - - TableViewerColumn attName = new TableViewerColumn(tableViewer, SWT.NONE); - attName.getColumn().setWidth(attTblColWidth[0]); - attName.getColumn().setText(attTblHeaders[0]); - attName.setLabelProvider(new StyledCellLabelProvider() { - @Override - public void update(ViewerCell cell) { - Object element = cell.getElement(); - if (element instanceof PutPostAttributeModel) { - PutPostAttributeModel entry = (PutPostAttributeModel) element; - cell.setText(entry.getAttName()); - } - } - }); - - TableViewerColumn attValue = new TableViewerColumn(tableViewer, - SWT.NONE); - attValue.getColumn().setWidth(attTblColWidth[1]); - attValue.getColumn().setText(attTblHeaders[1]); - attValue.setLabelProvider(new StyledCellLabelProvider() { - @Override - public void update(ViewerCell cell) { - Object element = cell.getElement(); - if (element instanceof PutPostAttributeModel) { - PutPostAttributeModel entry = (PutPostAttributeModel) element; - cell.setText(entry.getAttValue()); - } - } - }); - attValue.setEditingSupport(new AttributeValueEditor(attTblViewer)); + public void createAttributeColumns(TreeViewer viewer) { + Tree tree = viewer.getTree(); + + attributeEditor = new AttributeEditingSupport(); + + TreeColumn attName = new TreeColumn(tree, SWT.NONE); + attName.setWidth(attTblColWidth[0]); + attName.setText(attTblHeaders[0]); + + TreeColumn attValue = new TreeColumn(tree, SWT.NONE); + attValue.setWidth(attTblColWidth[1]); + attValue.setText(attTblHeaders[1]); + TreeViewerColumn attValueVwrCol = new TreeViewerColumn(attViewer, + attValue); + attValueVwrCol.setEditingSupport(attributeEditor + .createAttributeValueEditor(attViewer, this)); } - class AttributeContentProvider implements IStructuredContentProvider { + class AttributeContentProvider implements ITreeContentProvider { @Override public void dispose() { } @Override - public void inputChanged(Viewer arg0, Object arg1, Object arg2) { + public void inputChanged(Viewer viewer, Object oldAttribute, + Object newAttribute) { } @Override - public Object[] getElements(Object element) { - return (Object[]) element; + public Object[] getChildren(Object attribute) { + if (attribute instanceof AttributeElement) { + return ((AttributeElement) attribute).getChildren().values() + .toArray(); + } + + return new Object[0]; } - } - class AttributeValueEditor extends EditingSupport { - private final TableViewer viewer; - private CCombo comboBox; + @Override + public Object getParent(Object attribute) { + if (attribute instanceof AttributeElement) + return ((AttributeElement) attribute).getParent(); + return null; + } - public AttributeValueEditor(TableViewer viewer) { - super(viewer); - this.viewer = viewer; + @Override + public boolean hasChildren(Object attribute) { + if (attribute instanceof AttributeElement) + return ((AttributeElement) attribute).hasChildren(); + return false; } @Override - protected boolean canEdit(Object arg0) { - return true; + public Object[] getElements(Object resourceModel) { + if (resourceModel instanceof ResourceRepresentation) { + return ((ResourceRepresentation) resourceModel).getAttributes() + .values().toArray(); + } + + return new Object[0]; } + } + + class AttributeLabelProvider implements ITableLabelProvider { @Override - protected CellEditor getCellEditor(Object element) { - PutPostAttributeModel attributeInSelection = (PutPostAttributeModel) element; + public void addListener(ILabelProviderListener arg0) { + } - String values[] = null; - List valueSet = attributeInSelection.getValues(); - values = convertListToStringArray(valueSet); + @Override + public void dispose() { + } - ComboBoxCellEditor comboEditor = new ComboBoxCellEditor( - viewer.getTable(), values); - comboBox = (CCombo) comboEditor.getControl(); - return comboEditor; + @Override + public boolean isLabelProperty(Object arg0, String arg1) { + return false; } @Override - protected Object getValue(Object element) { - int indexOfItem = 0; - PutPostAttributeModel att = (PutPostAttributeModel) element; - String valueString = att.getAttValue(); - List valueSet = att.getValues(); - if (null != valueSet) { - indexOfItem = valueSet.indexOf(valueString); - } - if (indexOfItem == -1) { - indexOfItem = 0; - } - return indexOfItem; + public void removeListener(ILabelProviderListener arg0) { + } @Override - protected void setValue(Object element, Object value) { - PutPostAttributeModel att = (PutPostAttributeModel) element; - int index; - try { - index = Integer.parseInt(String.valueOf(value)); - } catch (NumberFormatException nfe) { - index = -1; - } - if (index == -1) { - String customValue = comboBox.getText(); - att.prependNewValue(customValue); - att.setAttValue(customValue); - } else { - String attValue = att.getValues().get(index); - att.setAttValue(attValue); - } - viewer.update(element, null); + public Image getColumnImage(Object element, int col) { + return null; } - public String[] convertListToStringArray(List valueList) { - String[] strArr; - if (null != valueList && valueList.size() > 0) { - strArr = valueList.toArray(new String[1]); - } else { - strArr = new String[1]; + @Override + public String getColumnText(Object element, int column) { + if (element instanceof AttributeElement) { + AttributeElement attrElement = (AttributeElement) element; + switch (column) { + case 0: // Attribute name column + { + SimulatorResourceAttribute attribute = attrElement + .getSimulatorResourceAttribute(); + return attribute.name(); + } + + case 1: // Attribute value column + { + SimulatorResourceAttribute attribute = attrElement + .getSimulatorResourceAttribute(); + + if (attribute.value().typeInfo().mBaseType != ValueType.RESOURCEMODEL) + return Utility.getAttributeValueAsString(attribute + .value()); + return null; + } + } } - return strArr; + return null; } } - public List getUpdatedModel() { - return modelList; - } - @Override protected boolean isResizable() { return true; @@ -247,24 +247,8 @@ public class PutRequestDialog extends TitleAreaDialog { return super.createButton(parent, id, label, defaultButton); } - @Override - protected void okPressed() { - String value; - PutPostAttributeModel attModel; - Iterator itr; - itr = modelList.iterator(); - while (itr.hasNext()) { - attModel = itr.next(); - if (null == attModel) { - return; - } - value = attModel.getAttValue(); - if (null == value || value.isEmpty()) { - MessageDialog.openError(Display.getDefault().getActiveShell(), - "Empty value", "Attribute value should not be empty."); - return; - } - } - close(); + public ResourceRepresentation getUpdatedRepresentation() { + return updatedRepresentation; } + } 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 3e80941..d7a8e20 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 @@ -27,18 +27,7 @@ import java.util.Map; import java.util.Set; import java.util.Vector; -import oic.simulator.serviceprovider.Activator; -import oic.simulator.serviceprovider.model.CollectionResource; -import oic.simulator.serviceprovider.model.Device; -import oic.simulator.serviceprovider.model.LocalResourceAttribute; -import oic.simulator.serviceprovider.model.MetaProperty; -import oic.simulator.serviceprovider.model.Resource; -import oic.simulator.serviceprovider.model.ResourceType; -import oic.simulator.serviceprovider.model.SRMItem; -import oic.simulator.serviceprovider.model.SingleResource; -import oic.simulator.serviceprovider.utils.Constants; -import oic.simulator.serviceprovider.utils.Utility; - +import org.eclipse.swt.widgets.Display; import org.oic.simulator.AttributeProperty; import org.oic.simulator.AttributeProperty.Type; import org.oic.simulator.AttributeValue; @@ -59,6 +48,19 @@ import org.oic.simulator.server.SimulatorResource.ObserverListener; import org.oic.simulator.server.SimulatorResource.ResourceModelChangeListener; import org.oic.simulator.server.SimulatorSingleResource; +import oic.simulator.serviceprovider.Activator; +import oic.simulator.serviceprovider.model.AttributeElement; +import oic.simulator.serviceprovider.model.CollectionResource; +import oic.simulator.serviceprovider.model.Device; +import oic.simulator.serviceprovider.model.LocalResourceAttribute; +import oic.simulator.serviceprovider.model.MetaProperty; +import oic.simulator.serviceprovider.model.Resource; +import oic.simulator.serviceprovider.model.ResourceType; +import oic.simulator.serviceprovider.model.SRMItem; +import oic.simulator.serviceprovider.model.SingleResource; +import oic.simulator.serviceprovider.utils.Constants; +import oic.simulator.serviceprovider.utils.Utility; + /** * This class acts as an interface between the simulator java SDK and the * various UI modules. It maintains all the details of resources and provides @@ -141,27 +143,16 @@ public class ResourceManager { return; } - Resource resource = data.getResourceByURI(resourceURI); - if (null == resource) { - return; - } - - resource.setResourceModel(resourceModelN); - - // 7. Fetch the resource attributes. - Map resourceAttributeMap; - try { - resourceAttributeMap = fetchResourceAttributesFromModel(resourceModelN); - if (null != resourceAttributeMap) { - resource.setResourceAttributes(resourceAttributeMap); + Display.getDefault().asyncExec(new Runnable() { + @Override + public void run() { + Resource resource = data + .getResourceByURI(resourceURI); + if (null != resource) { + resource.setResourceRepresentation(resourceModelN); + } } - } catch (SimulatorException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - - UiListenerHandler.getInstance() - .resourceModelChangedUINotification(resource); + }); } }); } @@ -191,20 +182,24 @@ public class ResourceManager { null); } else if (resource.isAttributeAutomationInProgress()) { // Find the attribute with the given automation id - LocalResourceAttribute attribute; - attribute = getAttributeWithGivenAutomationId( + final AttributeElement attribute = getAttributeWithGivenAutomationId( resource, automationId); if (null != attribute) { - attribute.setAutomationInProgress(false); + // Display.getDefault().asyncExec(new Runnable() + // { + // @Override + // public void run() { + attribute.setAutoUpdateState(false); + // } + // }); resource.setAttributeAutomationInProgress(isAnyAttributeInAutomation(resource)); // Notify the UI listeners - UiListenerHandler - .getInstance() - .automationCompleteUINotification( - resource, - attribute - .getResourceAttributeRef() - .name()); + /* + * UiListenerHandler .getInstance() + * .automationCompleteUINotification( resource, + * attribute + * .getSimulatorResourceAttribute().name()); + */ } else { // TODO: Temporarily reset the attribute // automation status to false for making @@ -484,6 +479,8 @@ public class ResourceManager { // 6. Get the resource model java object reference. resource.setResourceModel(jSimulatorSingleResource .getResourceModel()); + + resource.setResourceRepresentation(resource.getResourceModel()); } // 7. Register the resource with the platform. @@ -541,6 +538,10 @@ public class ResourceManager { jSimulatorCollectionResource .setResourceModelChangeListener(resourceModelChangeListener); + // set resource model + resource.setResourceRepresentation(jSimulatorCollectionResource + .getResourceModel());; + // 5. Register the resource with the platform. jSimulatorCollectionResource.start(); resource.setStarted(true); @@ -673,6 +674,8 @@ public class ResourceManager { jSimulatorSingleResource.start(); singleRes.setStarted(true); + singleRes.setResourceRepresentation(jResModel); + // 7. Fetch the resource attributes. Map resourceAttributeMap; resourceAttributeMap = fetchResourceAttributesFromModel(jResModel); @@ -761,6 +764,8 @@ public class ResourceManager { jSimulatorCollectionResource.start(); collectionRes.setStarted(true); + collectionRes.setResourceRepresentation(jResModel); + // 7. Fetch the resource attributes. Map resourceAttributeMap; resourceAttributeMap = fetchResourceAttributesFromModel(jResModel); @@ -1475,107 +1480,6 @@ public class ResourceManager { return Utility.getCollectionResourceListFromSet(childs); } - /* - * public void deleteResourceByURI(String resourceURI) { if (null != - * resourceURI) { Resource resource = - * getSimulatorResourceByURI(resourceURI); if (null != resource) { // - * Unregister the resource from the platform deleteResource(resource); - * - * // Delete from the local data structure deleteLocalResourceDetails(null, - * resourceURI); - * - * // Notify the UI listener for removing this resource // from UI // - * resourceDeletedUINotification(); if (resource == - * getCurrentResourceInSelection()) { // Listeners might query the resource - * being deleted // if exists. So set the currently selection to // null. - * setCurrentResourceInSelection(null); - * - * // Notify all observers for resource selection // change event // - * resourceSelectionChangedUINotification(); } } } } - * - * private SingleResource getSimulatorResourceByURI(String resourceURI) { - * SingleResource resource = null; if (null != resourceURI) { synchronized - * (resourceMap) { resource = resourceMap.get(resourceURI); } } return - * resource; } - * - * private void deleteResource(SingleResource resource) { if (null != - * resource) { SimulatorResourceServer resourceServerN = resource - * .getResourceServer(); if (null != resourceServerN) { try { - * SimulatorManager.deleteResource(resourceServerN); } catch - * (SimulatorException e) { Activator .getDefault() .getLogManager() - * .log(Level.ERROR.ordinal(), new Date(), - * Utility.getSimulatorErrorString(e, null)); } } } } - * - * public void deleteResourceByType(final String resourceType) { - * System.out.println(resourceType + "to be deleted."); if (null != - * resourceType) { new Thread() { - * - * @Override public void run() { // Unregister the resources from the - * platform deleteResource(resourceType); - * - * // Delete from the local data structure - * deleteLocalResourceDetails(resourceType, null); - * - * // Notify the UI listener for removing this resource from UI - * resourceDeletedUINotification(); - * - * if (null != currentResourceInSelection && - * currentResourceInSelection.getResourceTypes() .contains(resourceType)) { - * // Listeners might query the resource being deleted if // exists. So set - * the currently selection to null. setCurrentResourceInSelection(null); - * - * // Notify all observers for resource selection change // event - * resourceSelectionChangedUINotification(null); } } }.start(); } } - * - * private void deleteResource(String resourceType) { if (null != - * resourceType) { try { SimulatorManager.deleteResources(resourceType); } - * catch (SimulatorException e) { Activator .getDefault() .getLogManager() - * .log(Level.ERROR.ordinal(), new Date(), - * Utility.getSimulatorErrorString(e, null)); } } } - * - * public void deleteAllResources() { new Thread() { - * - * @Override public void run() { // Unregister the resources from the - * platform deleteResource(); - * - * // Delete from the local data structure deleteLocalResourceDetails(null, - * null); - * - * // Notify the UI listener for removing this resource from UI - * resourceDeletedUINotification(); - * - * // Listeners might query the resource being deleted if exists. // So set - * the currently selection to null. setCurrentResourceInSelection(null); - * - * // Notify all observers for resource selection change event - * resourceSelectionChangedUINotification(null); } }.start(); } - * - * private void deleteResource() { try { - * SimulatorManager.deleteResources(null); } catch (SimulatorException e) { - * Activator .getDefault() .getLogManager() .log(Level.ERROR.ordinal(), new - * Date(), Utility.getSimulatorErrorString(e, null)); } } - * - * private void deleteLocalResourceDetails(String resourceType, String - * resourceURI) { synchronized (resourceMap) { if (null == resourceType && - * null == resourceURI) { resourceMap.clear(); } else if (null != - * resourceType) { Set uriSet = resourceMap.keySet(); if (null == - * uriSet) { return; } String uri; SingleResource simpleRes; - * Iterator uriItr = uriSet.iterator(); while (uriItr.hasNext()) { - * uri = uriItr.next(); simpleRes = resourceMap.get(uri); if - * (simpleRes.getResourceTypes().contains(resourceType)) { uriItr.remove(); - * } } } else { removeResourceFromMap(resourceURI); } } } - * - * - * - * public Set getResourceTypeList() { Set types = null; - * synchronized (resourceMap) { if (resourceMap.size() > 0) { types = new - * TreeSet(); Set typeSet = resourceMap.keySet(); - * Iterator typeItr = typeSet.iterator(); SingleResource resource; - * while (typeItr.hasNext()) { resource = resourceMap.get(typeItr.next()); - * Set subTypes = resource.getResourceTypes(); - * types.addAll(subTypes); } } } return types; } - */ - public void resourceSelectionChanged(final Resource selectedResource) { new Thread() { @Override @@ -1932,51 +1836,6 @@ public class ResourceManager { } } - /* - * private ModelChangeNotificationType compareAndUpdateLocalAttributes( - * Map resourceAttributeMapOld, Map resourceAttributeMapNew, - * Set valueChangeSet) { ModelChangeNotificationType - * notificationType = ModelChangeNotificationType.NONE; if (null != - * resourceAttributeMapOld && null != resourceAttributeMapNew) { Set - * oldMapKeySet = resourceAttributeMapOld.keySet(); Iterator - * attributeMapOldItr = oldMapKeySet.iterator(); String attName; - * LocalResourceAttribute attributeOld; LocalResourceAttribute attributeNew; - * Object attValueOld; Object attValueNew; String oldValueStr; String - * newValueStr; while (attributeMapOldItr.hasNext()) { attName = - * attributeMapOldItr.next(); if - * (resourceAttributeMapNew.containsKey(attName)) { attributeOld = - * resourceAttributeMapOld.get(attName); attributeNew = - * resourceAttributeMapNew.get(attName); // Copy the attribute value from - * new to old if the value // has been changed // Comparing only the - * attribute's value considering the // fact that only the value can be - * changed if (null != attributeOld && null != attributeNew) { attValueOld = - * attributeOld.getAttributeValue(); attValueNew = - * attributeNew.getAttributeValue(); - * - * oldValueStr = String.valueOf(attValueOld); newValueStr = - * String.valueOf(attValueNew); - * - * if (null != oldValueStr && null != newValueStr) { if - * (!oldValueStr.equals(newValueStr)) { - * attributeOld.setAttributeValue(attValueNew); notificationType = - * ModelChangeNotificationType.ATTRIBUTE_VALUE_CHANGED; - * valueChangeSet.add(attributeOld); } } } - * resourceAttributeMapNew.remove(attName); } else { // Attribute doesn't - * exist in the new model. Hence // removing it from the model. - * resourceAttributeMapOld.remove(attName); notificationType = - * ModelChangeNotificationType.ATTRIBUTE_REMOVED; } } // Check for new - * attributes in the new model if (resourceAttributeMapNew.size() > 0) { - * Set remainingAttSet = resourceAttributeMapNew.keySet(); - * Iterator remainingAttItr = remainingAttSet.iterator(); - * LocalResourceAttribute attribute; while (remainingAttItr.hasNext()) { - * attName = remainingAttItr.next(); if (null != attName) { attribute = - * resourceAttributeMapNew.get(attName); if (null != attribute) { - * resourceAttributeMapOld.put(attName, attribute); } } } notificationType = - * ModelChangeNotificationType.ATTRIBUTE_ADDED; } } return notificationType; - * } - */ - // TODO: This method should get the status from the native layer. public boolean isResourceStarted(Resource resource) { if (null == resource) { @@ -2170,14 +2029,15 @@ public class ResourceManager { } public int startAutomation(SingleResource resource, - LocalResourceAttribute attribute, AutoUpdateType autoType, + AttributeElement attribute, AutoUpdateType autoType, int autoUpdateInterval) { int autoId = -1; if (null != resource && null != attribute) { SimulatorSingleResource server = (SimulatorSingleResource) resource .getSimulatorResource(); if (null != server) { - String attrName = attribute.getResourceAttributeRef().name(); + String attrName = attribute.getSimulatorResourceAttribute() + .name(); try { autoId = server.startAttributeUpdation(attrName, autoType, autoUpdateInterval, automationListener); @@ -2193,21 +2053,19 @@ public class ResourceManager { return -1; } if (-1 != autoId) { - attribute.setAutomationId(autoId); - attribute.setAutomationType(autoType); - attribute.setAutomationUpdateInterval(autoUpdateInterval); - attribute.setAutomationInProgress(true); + attribute.setAutoUpdateId(autoId); + attribute.setAutoUpdateType(autoType); + attribute.setAutoUpdateInterval(autoUpdateInterval); + attribute.setAutoUpdateState(true); resource.setAttributeAutomationInProgress(true); - } else { - attribute.setAutomationInProgress(false); } } } return autoId; } - public void stopAutomation(SingleResource resource, - LocalResourceAttribute att, int autoId) { + public void stopAutomation(SingleResource resource, AttributeElement att, + int autoId) { if (null != resource) { SimulatorSingleResource server = (SimulatorSingleResource) resource .getSimulatorResource(); @@ -2226,7 +2084,7 @@ public class ResourceManager { return; } // Change the automation status - att.setAutomationInProgress(false); + att.setAutoUpdateState(false); resource.setAttributeAutomationInProgress(isAnyAttributeInAutomation(resource)); } } @@ -2317,76 +2175,60 @@ public class ResourceManager { } private boolean isAnyAttributeInAutomation(SingleResource resource) { - if (null == resource) { + if (null == resource || null == resource.getResourceRepresentation()) { return false; } - Map attMap = resource - .getResourceAttributes(); - if (null == attMap) { + + Map attributes = resource + .getResourceRepresentation().getAttributes(); + if (null == attributes || 0 == attributes.size()) return false; + + for (Map.Entry entry : attributes.entrySet()) { + if (entry.getValue().isAutoUpdateInProgress()) + return true; } - boolean status = false; - Set keySet = attMap.keySet(); - Iterator attItr = keySet.iterator(); - while (attItr.hasNext()) { - LocalResourceAttribute attribute = attMap.get(attItr.next()); - if (attribute.isAutomationInProgress()) { - status = true; - break; - } - } - return status; + + return false; } // Changes the automation state of the resource and its attributes private void changeResourceLevelAutomationStatus(SingleResource resource, boolean status) { - Map attributeMap = resource - .getResourceAttributes(); - if (null != attributeMap) { - Set attrNameSet = attributeMap.keySet(); - Iterator attrNameItr = attrNameSet.iterator(); - String attrName; - LocalResourceAttribute attribute; - while (attrNameItr.hasNext()) { - attrName = attrNameItr.next(); - attribute = attributeMap.get(attrName); - if (null != attribute) { - attribute.setAutomationInProgress(status); - } - } + if (null == resource || null == resource.getResourceRepresentation()) { + return; + } + + Map attributes = resource + .getResourceRepresentation().getAttributes(); + if (null == attributes || 0 == attributes.size()) + return; + + for (Map.Entry entry : attributes.entrySet()) { + entry.getValue().setAutoUpdateState(status); } + resource.setResourceAutomationInProgress(status); } - private LocalResourceAttribute getAttributeWithGivenAutomationId( + private AttributeElement getAttributeWithGivenAutomationId( SingleResource resource, int automationId) { - LocalResourceAttribute targetAttribute = null; - if (null != resource) { - Map attributeMap = resource - .getResourceAttributes(); - if (null != attributeMap) { - Set attNameSet = attributeMap.keySet(); - Iterator attNameItr = attNameSet.iterator(); - String attName; - LocalResourceAttribute attribute; - while (attNameItr.hasNext()) { - attName = attNameItr.next(); - if (null != attName) { - attribute = attributeMap.get(attName); - if (null != attribute) { - if (attribute.isAutomationInProgress() - && (attribute.getAutomationId() == automationId)) { - targetAttribute = attribute; - break; - } - } - } - } - } + if (null == resource || null == resource.getResourceRepresentation()) { + return null; + } + + Map attributes = resource + .getResourceRepresentation().getAttributes(); + if (null == attributes || 0 == attributes.size()) + return null; + + for (Map.Entry entry : attributes.entrySet()) { + if (automationId == entry.getValue().getAutoUpdateId()) + return entry.getValue(); } - return targetAttribute; + + return null; } public boolean isResourceAutomationStarted(SingleResource resource) { diff --git a/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/model/AttributeElement.java b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/model/AttributeElement.java new file mode 100644 index 0000000..4c493a2 --- /dev/null +++ b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/model/AttributeElement.java @@ -0,0 +1,278 @@ +package oic.simulator.serviceprovider.model; + +import java.util.HashMap; +import java.util.Map; + +import org.oic.simulator.AttributeValue; +import org.oic.simulator.InvalidArgsException; +import org.oic.simulator.SimulatorResourceAttribute; +import org.oic.simulator.SimulatorResourceModel; +import org.oic.simulator.server.SimulatorResource.AutoUpdateType; + +import oic.simulator.serviceprovider.utils.AttributeValueStringConverter; +import oic.simulator.serviceprovider.utils.Constants; + +public class AttributeElement { + private Object mParent = null; + private SimulatorResourceAttribute mAttribute = null; + private Map mChildAttributes = new HashMap(); + private DataChangeListener mListener = null; + private boolean mAutoUpdateSupport = false; + private int mAutoUpdateId = -1; + private boolean mAutoUpdateState = false; + private int mAutoUpdateInterval = Constants.DEFAULT_AUTOMATION_INTERVAL; + private AutoUpdateType mAutoUpdateType = Constants.DEFAULT_AUTOMATION_TYPE; + + public AttributeElement(Object parent, + SimulatorResourceAttribute attribute, boolean autoUpdateSupport) { + mParent = parent; + mAttribute = attribute; + mAutoUpdateSupport = autoUpdateSupport; + AttributeValue.TypeInfo typeInfo = attribute.value().typeInfo(); + if (typeInfo.mType == AttributeValue.ValueType.RESOURCEMODEL) { + mAutoUpdateSupport = false; + SimulatorResourceModel resModel = (SimulatorResourceModel) attribute + .value().get(); + for (Map.Entry entrySet : resModel + .getAttributes().entrySet()) + mChildAttributes.put(entrySet.getKey(), new AttributeElement( + this, entrySet.getValue(), false)); + } else if (typeInfo.mType == AttributeValue.ValueType.ARRAY) { + mAutoUpdateSupport = false; + if (typeInfo.mBaseType == AttributeValue.ValueType.RESOURCEMODEL) { + if (typeInfo.mDepth == 1) { + SimulatorResourceModel[] resModelArray = (SimulatorResourceModel[]) attribute + .value().get(); + for (int i = 0; i < resModelArray.length; i++) { + SimulatorResourceAttribute indexAttribute = new SimulatorResourceAttribute( + "[" + Integer.toString(i) + "]", + new AttributeValue(resModelArray[i]), null); + mChildAttributes.put("[" + Integer.toString(i) + "]", + new AttributeElement(this, indexAttribute, + false)); + } + } else if (typeInfo.mDepth == 2) { + SimulatorResourceModel[][] resModelArray = (SimulatorResourceModel[][]) attribute + .value().get(); + for (int i = 0; i < resModelArray.length; i++) { + SimulatorResourceAttribute indexAttribute = new SimulatorResourceAttribute( + "[" + Integer.toString(i) + "]", + new AttributeValue(resModelArray[i]), null); + mChildAttributes.put("[" + Integer.toString(i) + "]", + new AttributeElement(this, indexAttribute, + false)); + } + } else if (typeInfo.mDepth == 3) { + SimulatorResourceModel[][][] resModelArray = (SimulatorResourceModel[][][]) attribute + .value().get(); + for (int i = 0; i < resModelArray.length; i++) { + SimulatorResourceAttribute indexAttribute = new SimulatorResourceAttribute( + "[" + Integer.toString(i) + "]", + new AttributeValue(resModelArray[i]), null); + mChildAttributes.put("[" + Integer.toString(i) + "]", + new AttributeElement(this, indexAttribute, + false)); + } + } + } + } + } + + public Object getParent() { + return mParent; + } + + public boolean hasChildren() { + if (mChildAttributes != null && mChildAttributes.size() > 0) + return true; + return false; + } + + public Map getChildren() { + if (hasChildren() == true) + return mChildAttributes; + return null; + } + + public SimulatorResourceAttribute getSimulatorResourceAttribute() { + return mAttribute; + } + + public int getAutoUpdateId() { + return mAutoUpdateId; + } + + public void setAutoUpdateId(int id) { + mAutoUpdateId = id; + } + + public boolean isAutoUpdateInProgress() { + return mAutoUpdateState; + } + + public void setAutoUpdateState(boolean state) { + if (mAutoUpdateState != state) { + mAutoUpdateState = state; + if (mListener != null) + mListener.update(this); + } + } + + public int getAutoUpdateInterval() { + return mAutoUpdateInterval; + } + + public void setAutoUpdateInterval(int interval) { + mAutoUpdateInterval = interval; + } + + public AutoUpdateType getAutoUpdateType() { + return mAutoUpdateType; + } + + public void setAutoUpdateType(AutoUpdateType type) { + mAutoUpdateType = type; + } + + public boolean isAutoUpdateSupport() { + return mAutoUpdateSupport; + } + + public boolean isReadOnly() { + return (null == mAttribute.property()); + } + + public void setListener(DataChangeListener listener) { + mListener = listener; + for (Map.Entry entry : mChildAttributes + .entrySet()) + entry.getValue().setListener(listener); + } + + public DataChangeListener getListener() { + return mListener; + } + + public void update(SimulatorResourceAttribute attribute) { + if (attribute == null) + return; + + AttributeValue.TypeInfo typeInfo = attribute.value().typeInfo(); + if (typeInfo.mType == AttributeValue.ValueType.RESOURCEMODEL) { + SimulatorResourceModel resModel = (SimulatorResourceModel) attribute + .value().get(); + for (Map.Entry entry : resModel + .getAttributes().entrySet()) { + AttributeElement attributeElement = mChildAttributes.get(entry + .getKey()); + if (attributeElement != null) { + attributeElement.update(entry.getValue()); + } else // Display new attribute in UI + { + AttributeElement newAttribute = new AttributeElement(this, + entry.getValue(), false); + mChildAttributes.put(entry.getKey(), newAttribute); + if (mListener != null) + mListener.add(newAttribute); + } + } + } else if (typeInfo.mType == AttributeValue.ValueType.ARRAY + && typeInfo.mBaseType == AttributeValue.ValueType.RESOURCEMODEL) { + if (typeInfo.mDepth == 1) { + SimulatorResourceModel[] resModelArray = (SimulatorResourceModel[]) attribute + .value().get(); + for (int i = 0; i < resModelArray.length; i++) { + SimulatorResourceAttribute indexAttribute = new SimulatorResourceAttribute( + "[" + Integer.toString(i) + "]", + new AttributeValue(resModelArray[i]), null); + AttributeElement attributeElement = mChildAttributes + .get("[" + Integer.toString(i) + "]"); + if (attributeElement != null) { + attributeElement.update(indexAttribute); + } else // Display new attribute in UI + { + AttributeElement newAttribute = new AttributeElement( + this, indexAttribute, false); + mChildAttributes.put("[" + Integer.toString(i) + "]", + newAttribute); + if (mListener != null) + mListener.add(newAttribute); + } + } + } + if (typeInfo.mDepth == 2) { + SimulatorResourceModel[][] resModelArray = (SimulatorResourceModel[][]) attribute + .value().get(); + for (int i = 0; i < resModelArray.length; i++) { + SimulatorResourceAttribute indexAttribute = new SimulatorResourceAttribute( + "[" + Integer.toString(i) + "]", + new AttributeValue(resModelArray[i]), null); + AttributeElement attributeElement = mChildAttributes + .get("[" + Integer.toString(i) + "]"); + if (attributeElement != null) { + attributeElement.update(indexAttribute); + } else // Display new attribute in UI + { + AttributeElement newAttribute = new AttributeElement( + this, indexAttribute, false); + mChildAttributes.put("[" + Integer.toString(i) + "]", + newAttribute); + if (mListener != null) + mListener.add(newAttribute); + } + } + } + if (typeInfo.mDepth == 3) { + SimulatorResourceModel[][][] resModelArray = (SimulatorResourceModel[][][]) attribute + .value().get(); + for (int i = 0; i < resModelArray.length; i++) { + SimulatorResourceAttribute indexAttribute = new SimulatorResourceAttribute( + "[" + Integer.toString(i) + "]", + new AttributeValue(resModelArray[i]), null); + AttributeElement attributeElement = mChildAttributes + .get("[" + Integer.toString(i) + "]"); + if (attributeElement != null) { + attributeElement.update(indexAttribute); + } else // Display new attribute in UI + { + AttributeElement newAttribute = new AttributeElement( + this, indexAttribute, false); + mChildAttributes.put("[" + Integer.toString(i) + "]", + newAttribute); + if (mListener != null) + mListener.add(newAttribute); + } + } + } + } else { + String currentValue = new AttributeValueStringConverter( + mAttribute.value()).toString(); + String newValue = new AttributeValueStringConverter( + attribute.value()).toString(); + if (!currentValue.equals(newValue)) { + mAttribute = attribute; + if (mListener != null) + mListener.update(this); + } + } + } + + public void deepSetChildValue(SimulatorResourceAttribute attribute) + throws InvalidArgsException { + if (null == attribute || null == attribute.name()) + return; + + AttributeValue.TypeInfo myValuetypeInfo = mAttribute.value().typeInfo(); + if (myValuetypeInfo.mType == AttributeValue.ValueType.RESOURCEMODEL) { + SimulatorResourceModel resModel = (SimulatorResourceModel) mAttribute + .value().get(); + if (resModel.containsAttribute(attribute.name())) + resModel.setAttributeValue(attribute.name(), attribute.value()); + else + return; + } + + if (mParent instanceof AttributeElement) + ((AttributeElement) mParent).deepSetChildValue(mAttribute); + } +} diff --git a/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/model/AutomationSettingHelper.java b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/model/AutomationSettingHelper.java index 9a456b9..efb7726 100644 --- a/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/model/AutomationSettingHelper.java +++ b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/model/AutomationSettingHelper.java @@ -20,10 +20,10 @@ import java.util.ArrayList; import java.util.Iterator; import java.util.List; -import oic.simulator.serviceprovider.utils.Constants; - import org.oic.simulator.server.SimulatorResource.AutoUpdateType; +import oic.simulator.serviceprovider.utils.Constants; + /** * This is a helper class for providing the automation settings information to * UI. @@ -64,7 +64,7 @@ public class AutomationSettingHelper { } public static List getAutomationSettings( - LocalResourceAttribute attribute) { + AttributeElement attribute) { List settingList = null; boolean invalidSetting; @@ -76,7 +76,7 @@ public class AutomationSettingHelper { .equals(Constants.AUTOMATION_TYPE)) { setting.setSettingID(Constants.AUTOMATION_TYPE); if (null != attribute) { - setting.setSettingValue(attribute.getAutomationType() + setting.setSettingValue(attribute.getAutoUpdateType() .toString()); } else { setting.setSettingValue(AutoUpdateType.ONE_TIME.toString()); @@ -90,7 +90,7 @@ public class AutomationSettingHelper { setting.setSettingID(Constants.UPDATE_INTERVAL_IN_MS); if (null != attribute) { setting.setSettingValue(String.valueOf(attribute - .getAutomationUpdateInterval())); + .getAutoUpdateInterval())); } else { setting.setSettingValue(String .valueOf(Constants.DEFAULT_AUTOMATION_INTERVAL)); diff --git a/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/model/DataChangeListener.java b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/model/DataChangeListener.java new file mode 100644 index 0000000..745332b --- /dev/null +++ b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/model/DataChangeListener.java @@ -0,0 +1,9 @@ +package oic.simulator.serviceprovider.model; + +public interface DataChangeListener { + public void add(AttributeElement attribute); + + public void remove(AttributeElement attribute); + + public void update(AttributeElement attribute); +} diff --git a/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/model/Resource.java b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/model/Resource.java index 5772cc2..abf0c31 100644 --- a/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/model/Resource.java +++ b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/model/Resource.java @@ -30,6 +30,7 @@ public abstract class Resource { // Java SDK object reference SimulatorResource simulatorResource; private SimulatorResourceModel resourceModel; + private ResourceRepresentation mResourceRepresentation; private String resourceURI; private String resourceName; @@ -243,18 +244,14 @@ public abstract class Resource { this.attributes = attributes; } - // Added for debugging purpose - public void printResourceInfo() { - System.out.println("Resource URI: " + getResourceURI()); - System.out.println("Resource Name: " + getResourceName()); - System.out.println("Resource types: " + getResourceTypes()); - System.out.println("Resource Interfaces: " + getResourceInterfaces()); - System.out.println("Resource Attributes:-"); - /* - * if (null != resourceAttributesMap) { Iterator attItr = - * resourceAttributesMap.keySet().iterator(); while (attItr.hasNext()) { - * resourceAttributesMap.get(attItr.next()) .printAttributeDetails();; } - * } - */ + public void setResourceRepresentation(SimulatorResourceModel resModel) { + if (mResourceRepresentation == null) + mResourceRepresentation = new ResourceRepresentation(resModel); + else + mResourceRepresentation.update(resModel); + } + + public ResourceRepresentation getResourceRepresentation() { + return mResourceRepresentation; } } diff --git a/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/model/ResourceRepresentation.java b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/model/ResourceRepresentation.java new file mode 100644 index 0000000..799c7bd --- /dev/null +++ b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/model/ResourceRepresentation.java @@ -0,0 +1,55 @@ +package oic.simulator.serviceprovider.model; + +import java.util.HashMap; +import java.util.Map; + +import org.oic.simulator.SimulatorResourceAttribute; +import org.oic.simulator.SimulatorResourceModel; + +public class ResourceRepresentation { + private DataChangeListener mListener = null; + private Map mAttributes = new HashMap(); + + public ResourceRepresentation(SimulatorResourceModel resourceModel) { + if (resourceModel != null && resourceModel.size() > 0) { + for (Map.Entry entry : resourceModel + .getAttributes().entrySet()) + mAttributes.put(entry.getKey(), new AttributeElement(this, + entry.getValue(), true)); + } + } + + public Map getAttributes() { + return mAttributes; + } + + public void setListener(DataChangeListener listener) { + mListener = listener; + for (Map.Entry entry : mAttributes.entrySet()) + entry.getValue().setListener(listener); + } + + public DataChangeListener getListener() { + return mListener; + } + + public void update(SimulatorResourceModel resourceModel) { + if (null == resourceModel) + return; + + for (Map.Entry entry : resourceModel + .getAttributes().entrySet()) { + AttributeElement attributeElement = mAttributes.get(entry.getKey()); + if (attributeElement != null) { + attributeElement.update(entry.getValue()); + } else // Display new attribute in UI + { + AttributeElement newAttribute = new AttributeElement(this, + entry.getValue(), true); + mAttributes.put(entry.getKey(), newAttribute); + if (mListener != null) + mListener.add(newAttribute); + } + } + } +} diff --git a/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/utils/AttributeValueStringConverter.java b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/utils/AttributeValueStringConverter.java new file mode 100644 index 0000000..fab87b9 --- /dev/null +++ b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/utils/AttributeValueStringConverter.java @@ -0,0 +1,327 @@ +package oic.simulator.serviceprovider.utils; + +import java.util.Map; + +import org.oic.simulator.AttributeValue; +import org.oic.simulator.AttributeValueVisitor; +import org.oic.simulator.SimulatorResourceAttribute; +import org.oic.simulator.SimulatorResourceModel; + +public class AttributeValueStringConverter implements + AttributeValueVisitor.VisitingMethods { + + private AttributeValue mValue; + + public AttributeValueStringConverter(AttributeValue value) { + mValue = value; + } + + @Override + public String toString() { + AttributeValueVisitor visitor = new AttributeValueVisitor(mValue, this); + return (String) visitor.visit(); + } + + @Override + public String visitingValue(Integer value) { + return value.toString(); + } + + @Override + public String visitingValue(Double value) { + return value.toString(); + } + + @Override + public String visitingValue(Boolean value) { + return value.toString(); + } + + @Override + public String visitingValue(String value) { + return new String(value); + } + + @Override + public String visitingValue(SimulatorResourceModel value) { + StringBuilder result = new StringBuilder(); + result.append("{"); + boolean first = true; + for (Map.Entry entry : value + .getAttributes().entrySet()) { + if (!first) + result.append(", "); + first = false; + result.append("\"" + entry.getKey() + "\":"); + AttributeValue attributeValue = entry.getValue().value(); + result.append(new AttributeValueStringConverter(attributeValue) + .toString()); + } + + result.append("}"); + return result.toString(); + } + + @Override + public String visitingValue(Integer[] values) { + StringBuilder result = new StringBuilder(); + result.append("["); + boolean first = true; + for (Integer value : values) { + if (!first) + result.append(", "); + first = false; + result.append(value.toString()); + } + + result.append("]"); + return result.toString(); + } + + @Override + public String visitingValue(Double[] values) { + StringBuilder result = new StringBuilder(); + result.append("["); + boolean first = true; + for (Double value : values) { + if (!first) + result.append(", "); + first = false; + result.append(value.toString()); + } + + result.append("]"); + return result.toString(); + } + + @Override + public String visitingValue(Boolean[] values) { + StringBuilder result = new StringBuilder(); + result.append("["); + boolean first = true; + for (Boolean value : values) { + if (!first) + result.append(", "); + first = false; + result.append(value.toString()); + } + + result.append("]"); + return result.toString(); + } + + @Override + public String visitingValue(String[] values) { + StringBuilder result = new StringBuilder(); + result.append("["); + boolean first = true; + for (String value : values) { + if (!first) + result.append(", "); + first = false; + result.append(value); + } + + result.append("]"); + return result.toString(); + } + + @Override + public String visitingValue(SimulatorResourceModel[] values) { + StringBuilder result = new StringBuilder(); + result.append("["); + boolean first = true; + for (SimulatorResourceModel value : values) { + if (!first) + result.append(", "); + first = false; + AttributeValue attributeValue = new AttributeValue(value); + result.append(new AttributeValueStringConverter(attributeValue) + .toString()); + } + + result.append("]"); + return result.toString(); + } + + @Override + public String visitingValue(Integer[][] values) { + StringBuilder result = new StringBuilder(); + result.append("["); + boolean first = true; + for (Integer[] value : values) { + if (!first) + result.append(", "); + first = false; + AttributeValue attributeValue = new AttributeValue(value); + result.append(new AttributeValueStringConverter(attributeValue) + .toString()); + } + + result.append("]"); + return result.toString(); + } + + @Override + public String visitingValue(Double[][] values) { + StringBuilder result = new StringBuilder(); + result.append("["); + boolean first = true; + for (Double[] value : values) { + if (!first) + result.append(", "); + first = false; + AttributeValue attributeValue = new AttributeValue(value); + result.append(new AttributeValueStringConverter(attributeValue) + .toString()); + } + + result.append("]"); + return result.toString(); + } + + @Override + public String visitingValue(Boolean[][] values) { + StringBuilder result = new StringBuilder(); + result.append("["); + boolean first = true; + for (Boolean[] value : values) { + if (!first) + result.append(", "); + first = false; + AttributeValue attributeValue = new AttributeValue(value); + result.append(new AttributeValueStringConverter(attributeValue) + .toString()); + } + + result.append("]"); + return result.toString(); + } + + @Override + public String visitingValue(String[][] values) { + StringBuilder result = new StringBuilder(); + result.append("["); + boolean first = true; + for (String[] value : values) { + if (!first) + result.append(", "); + first = false; + AttributeValue attributeValue = new AttributeValue(value); + result.append(new AttributeValueStringConverter(attributeValue) + .toString()); + } + + result.append("]"); + return result.toString(); + } + + @Override + public String visitingValue(SimulatorResourceModel[][] values) { + StringBuilder result = new StringBuilder(); + result.append("["); + boolean first = true; + for (SimulatorResourceModel[] value : values) { + if (!first) + result.append(", "); + first = false; + AttributeValue attributeValue = new AttributeValue(value); + result.append(new AttributeValueStringConverter(attributeValue) + .toString()); + } + + result.append("]"); + return result.toString(); + } + + @Override + public String visitingValue(Integer[][][] values) { + StringBuilder result = new StringBuilder(); + result.append("["); + boolean first = true; + for (Integer[][] value : values) { + if (!first) + result.append(", "); + first = false; + AttributeValue attributeValue = new AttributeValue(value); + result.append(new AttributeValueStringConverter(attributeValue) + .toString()); + } + + result.append("]"); + return result.toString(); + } + + @Override + public String visitingValue(Double[][][] values) { + StringBuilder result = new StringBuilder(); + result.append("["); + boolean first = true; + for (Double[][] value : values) { + if (!first) + result.append(", "); + first = false; + AttributeValue attributeValue = new AttributeValue(value); + result.append(new AttributeValueStringConverter(attributeValue) + .toString()); + } + + result.append("]"); + return result.toString(); + } + + @Override + public String visitingValue(Boolean[][][] values) { + StringBuilder result = new StringBuilder(); + result.append("["); + boolean first = true; + for (Boolean[][] value : values) { + if (!first) + result.append(", "); + first = false; + AttributeValue attributeValue = new AttributeValue(value); + result.append(new AttributeValueStringConverter(attributeValue) + .toString()); + } + + result.append("]"); + return result.toString(); + } + + @Override + public String visitingValue(String[][][] values) { + StringBuilder result = new StringBuilder(); + result.append("["); + boolean first = true; + for (String[][] value : values) { + if (!first) + result.append(", "); + first = false; + AttributeValue attributeValue = new AttributeValue(value); + result.append(new AttributeValueStringConverter(attributeValue) + .toString()); + } + + result.append("]"); + return result.toString(); + } + + @Override + public String visitingValue(SimulatorResourceModel[][][] values) { + StringBuilder result = new StringBuilder(); + result.append("["); + boolean first = true; + for (SimulatorResourceModel[][] value : values) { + if (!first) + result.append(", "); + first = false; + AttributeValue attributeValue = new AttributeValue(value); + result.append(new AttributeValueStringConverter(attributeValue) + .toString()); + } + + result.append("]"); + return result.toString(); + } + +} diff --git a/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/utils/Utility.java b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/utils/Utility.java index 73d559c..8b3f2f5 100644 --- a/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/utils/Utility.java +++ b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/utils/Utility.java @@ -362,7 +362,7 @@ public class Utility { return null; } Set resultSet = new HashSet(); - if (type.equals(Constants.INT)) { + if (AttributeValue.ValueType.INTEGER == type) { int val; Iterator itr = values.iterator(); while (itr.hasNext()) { @@ -373,7 +373,7 @@ public class Utility { // Added for safety. Nothing to do. } } - } else if (type.equals(Constants.DOUBLE)) { + } else if (AttributeValue.ValueType.DOUBLE == type) { double val; Iterator itr = values.iterator(); while (itr.hasNext()) { @@ -384,10 +384,10 @@ public class Utility { // Added for safety. Nothing to do. } } - } else if (type.equals(Constants.BOOL)) { + } else if (AttributeValue.ValueType.BOOLEAN == type) { resultSet.add(true); resultSet.add(false); - } else { + } else if (AttributeValue.ValueType.STRING == type) { Iterator itr = values.iterator(); while (itr.hasNext()) { resultSet.add(itr.next()); diff --git a/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/AttributeEditingSupport.java b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/AttributeEditingSupport.java index 1544fb6..b9de9d2 100644 --- a/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/AttributeEditingSupport.java +++ b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/AttributeEditingSupport.java @@ -20,11 +20,11 @@ import java.util.List; import oic.simulator.serviceprovider.Activator; import oic.simulator.serviceprovider.manager.ResourceManager; +import oic.simulator.serviceprovider.model.AttributeElement; import oic.simulator.serviceprovider.model.AutomationSettingHelper; import oic.simulator.serviceprovider.model.CollectionResource; -import oic.simulator.serviceprovider.model.LocalResourceAttribute; import oic.simulator.serviceprovider.model.Resource; -import oic.simulator.serviceprovider.model.SRMItem; +import oic.simulator.serviceprovider.model.ResourceRepresentation; import oic.simulator.serviceprovider.model.SingleResource; import oic.simulator.serviceprovider.utils.AttributeValueBuilder; import oic.simulator.serviceprovider.utils.Utility; @@ -52,7 +52,6 @@ import org.oic.simulator.AttributeValue.TypeInfo; import org.oic.simulator.AttributeValue.ValueType; import org.oic.simulator.InvalidArgsException; import org.oic.simulator.SimulatorResourceAttribute; -import org.oic.simulator.SimulatorResourceModel; import org.oic.simulator.server.SimulatorResource.AutoUpdateType; /** @@ -105,53 +104,44 @@ public class AttributeEditingSupport { return null; } - final SimulatorResourceAttribute att; - if (element instanceof SimulatorResourceAttribute - || element instanceof LocalResourceAttribute) { - if (element instanceof LocalResourceAttribute) { - LocalResourceAttribute localAtt = (LocalResourceAttribute) element; - att = localAtt.getResourceAttributeRef(); - } else { - att = (SimulatorResourceAttribute) element; - } - } else { + final SimulatorResourceAttribute attribute; + if (!(element instanceof AttributeElement)) { return null; } - if (null == att) { + AttributeElement attributeElement = ((AttributeElement) element); + attribute = attributeElement.getSimulatorResourceAttribute(); + if (null == attribute) { return null; } - final AttributeValue val = att.value(); - if (null == val) { + // CellEditor is not required as the automation is in progress. + if (attributeElement.isAutoUpdateInProgress()) { return null; } - final TypeInfo type = val.typeInfo(); - if (type.mType == ValueType.RESOURCEMODEL - || (type.mType == ValueType.ARRAY && type.mBaseType == ValueType.RESOURCEMODEL)) { + final AttributeValue val = attribute.value(); + if (null == val) { return null; } - AttributeProperty prop = att.property(); - if (null == prop) { + final TypeInfo type = val.typeInfo(); + if (type.mBaseType == ValueType.RESOURCEMODEL) { return null; } - if (!resourceManager.isAttHasRangeOrAllowedValues(att)) { + AttributeProperty prop = attribute.property(); + if (null == prop) { return null; } - // CellEditor is not required as the automation is in progress. - if (element instanceof LocalResourceAttribute - && ((LocalResourceAttribute) element) - .isAutomationInProgress()) { + if (!resourceManager.isAttHasRangeOrAllowedValues(attribute)) { return null; } String values[] = null; List valueSet = resourceManager - .getAllValuesOfAttribute(att); + .getAllValuesOfAttribute(attribute); values = convertListToStringArray(valueSet); ComboBoxCellEditor comboEditor; @@ -186,7 +176,7 @@ public class AttributeEditingSupport { dialog.setMessage("Given value is invalid"); dialog.open(); } else { - updateAttributeValue(att, value); + updateAttributeValue(attribute, value); MessageBox dialog = new MessageBox(viewer.getTree() .getShell(), SWT.ICON_QUESTION | SWT.OK | SWT.CANCEL); @@ -196,7 +186,7 @@ public class AttributeEditingSupport { if (retval != SWT.OK) { value = AttributeValueBuilder.build(oldValue, type.mBaseType); - updateAttributeValue(att, value); + updateAttributeValue(attribute, value); } else { ResourceManager resourceManager; resourceManager = Activator.getDefault() @@ -205,11 +195,11 @@ public class AttributeEditingSupport { Resource resource = resourceManager .getCurrentResourceInSelection(); - AttributeValue resultValue = getResultantValue(value); + SimulatorResourceAttribute result = getResultantValue(value); resourceManager.attributeValueUpdated( - (SingleResource) resource, att.name(), - resultValue); + (SingleResource) resource, + result.name(), result.value()); } } @@ -224,17 +214,14 @@ public class AttributeEditingSupport { @Override protected Object getValue(Object element) { int indexOfItem = 0; - SimulatorResourceAttribute att; + SimulatorResourceAttribute att = null; - if (element instanceof LocalResourceAttribute) { - LocalResourceAttribute localAtt = (LocalResourceAttribute) element; - att = localAtt.getResourceAttributeRef(); - if (null == att) { - return 0; - } - } else if (element instanceof SimulatorResourceAttribute) { - att = (SimulatorResourceAttribute) element; - } else { + if (element instanceof AttributeElement) { + att = ((AttributeElement) element) + .getSimulatorResourceAttribute(); + } + + if (att == null) { return 0; } @@ -252,17 +239,14 @@ public class AttributeEditingSupport { @Override protected void setValue(Object element, Object value) { - SimulatorResourceAttribute att; + SimulatorResourceAttribute att = null; - if (element instanceof LocalResourceAttribute) { - LocalResourceAttribute localAtt = (LocalResourceAttribute) element; - att = localAtt.getResourceAttributeRef(); - if (null == att) { - return; - } - } else if (element instanceof SimulatorResourceAttribute) { - att = (SimulatorResourceAttribute) element; - } else { + if (element instanceof AttributeElement) { + att = ((AttributeElement) element) + .getSimulatorResourceAttribute(); + } + + if (att == null) { return; } @@ -316,11 +300,11 @@ public class AttributeEditingSupport { Resource resource = resourceManager .getCurrentResourceInSelection(); - AttributeValue resultValue = getResultantValue(attValue); + SimulatorResourceAttribute result = getResultantValue(attValue); resourceManager.attributeValueUpdated( - (SingleResource) resource, att.name(), - resultValue); + (SingleResource) resource, + result.name(), result.value()); } } } @@ -360,54 +344,27 @@ public class AttributeEditingSupport { if (null == item) { return; } - TreeItem parent = item.getParentItem(); - // Get the parent model - if (null == parent) { - // Top-level attribute - Resource res = Activator.getDefault().getResourceManager() - .getCurrentResourceInSelection(); - if (null == res) { - return; - } - SimulatorResourceModel model = res.getResourceModel(); - if (null == model) { - return; - } - try { - model.setAttributeValue(att.name(), value); - } catch (InvalidArgsException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - } else { - SimulatorResourceModel model; - Object data = parent.getData(); - if (null == data) { - return; - } - if (data instanceof SRMItem) { - model = ((SRMItem) data).getModel(); - } else { - SimulatorResourceAttribute parentAtt; - if (data instanceof LocalResourceAttribute) { - parentAtt = ((LocalResourceAttribute) data) - .getResourceAttributeRef(); - } else { - parentAtt = (SimulatorResourceAttribute) data; + if (item.getData() instanceof AttributeElement) { + AttributeElement attributeElement = (AttributeElement) item + .getData(); + attributeElement.getSimulatorResourceAttribute() + .setValue(value); + + TreeItem parent = item.getParentItem(); + if (null != parent) { + Object data = parent.getData(); + try { + ((AttributeElement) data).deepSetChildValue(att); + } catch (InvalidArgsException e) { + e.printStackTrace(); } - model = (SimulatorResourceModel) parentAtt.value().get(); - } - try { - model.setAttributeValue(att.name(), value); - } catch (InvalidArgsException e) { - // TODO Auto-generated catch block - e.printStackTrace(); } } } - public AttributeValue getResultantValue(AttributeValue newValue) { + public SimulatorResourceAttribute getResultantValue( + AttributeValue newValue) { AttributeValue val = null; IStructuredSelection selection = (IStructuredSelection) viewer .getSelection(); @@ -426,24 +383,24 @@ public class AttributeEditingSupport { return null; } + SimulatorResourceAttribute result = null; TreeItem parent = item.getParentItem(); if (null == parent) { Object data = item.getData(); - // SimulatorResourceAttribute att = - // ((LocalResourceAttribute)data).getResourceAttributeRef(); - val = newValue; + result = ((AttributeElement) data) + .getSimulatorResourceAttribute(); } else { while (parent.getParentItem() != null) { parent = parent.getParentItem(); } + // Parent will point to the top-level attribute of type - // LocalResourceAttribute Object data = parent.getData(); - val = ((LocalResourceAttribute) data).getResourceAttributeRef() - .value(); + result = ((AttributeElement) data) + .getSimulatorResourceAttribute(); } - return val; + return result; } } @@ -480,9 +437,9 @@ public class AttributeEditingSupport { } SimulatorResourceAttribute att = null; - if (element instanceof LocalResourceAttribute) { - LocalResourceAttribute localAtt = (LocalResourceAttribute) element; - att = localAtt.getResourceAttributeRef(); + if (element instanceof AttributeElement) { + att = ((AttributeElement) element) + .getSimulatorResourceAttribute(); } if (null == att) { @@ -501,17 +458,29 @@ public class AttributeEditingSupport { return null; } + Object parent = ((AttributeElement) element).getParent(); + if (null != parent && !(parent instanceof ResourceRepresentation)) { + return null; + } + return new CheckboxCellEditor(null, SWT.CHECK | SWT.READ_ONLY); } @Override protected Object getValue(Object element) { - LocalResourceAttribute att = (LocalResourceAttribute) element; - return att.isAutomationInProgress(); + if (element instanceof AttributeElement) { + return ((AttributeElement) element).isAutoUpdateInProgress(); + } + + return false; } @Override protected void setValue(Object element, Object value) { + if (!(element instanceof AttributeElement)) { + return; + } + ResourceManager resourceManager = Activator.getDefault() .getResourceManager(); // As automation depends on the current resource in selection, its @@ -521,7 +490,7 @@ public class AttributeEditingSupport { return; } - LocalResourceAttribute att = (LocalResourceAttribute) element; + AttributeElement att = (AttributeElement) element; boolean checked = (Boolean) value; if (checked) { // Start the automation @@ -549,17 +518,17 @@ public class AttributeEditingSupport { .getActiveShell(), "Automation Status", "Automation start failed!!"); } else { - viewer.update(element, null); + // viewer.update(element, null); } } } else { // Stop the automation resourceManager.stopAutomation((SingleResource) resource, att, - att.getAutomationId()); + att.getAutoUpdateId()); MessageDialog.openInformation(Display.getDefault() .getActiveShell(), "Automation Status", "Automation stopped."); - viewer.update(element, null); + // viewer.update(element, null); } } } 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 f81bda6..5806cec 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 @@ -17,7 +17,6 @@ package oic.simulator.serviceprovider.view; import java.util.List; -import java.util.Map; import oic.simulator.serviceprovider.Activator; import oic.simulator.serviceprovider.listener.IAutomationUIListener; @@ -25,11 +24,12 @@ import oic.simulator.serviceprovider.listener.IResourceModelChangedUIListener; import oic.simulator.serviceprovider.listener.ISelectionChangedUIListener; import oic.simulator.serviceprovider.manager.ResourceManager; import oic.simulator.serviceprovider.manager.UiListenerHandler; -import oic.simulator.serviceprovider.model.CollectionResource; +import oic.simulator.serviceprovider.model.AttributeElement; +import oic.simulator.serviceprovider.model.DataChangeListener; import oic.simulator.serviceprovider.model.Device; import oic.simulator.serviceprovider.model.LocalResourceAttribute; import oic.simulator.serviceprovider.model.Resource; -import oic.simulator.serviceprovider.model.SRMItem; +import oic.simulator.serviceprovider.model.ResourceRepresentation; import oic.simulator.serviceprovider.model.SingleResource; import oic.simulator.serviceprovider.utils.Constants; import oic.simulator.serviceprovider.utils.Utility; @@ -55,7 +55,6 @@ import org.oic.simulator.AttributeValue; import org.oic.simulator.AttributeValue.TypeInfo; import org.oic.simulator.AttributeValue.ValueType; import org.oic.simulator.SimulatorResourceAttribute; -import org.oic.simulator.SimulatorResourceModel; /** * This class manages and shows the attribute view in the perspective. @@ -90,17 +89,20 @@ public class AttributeView extends ViewPart { @Override public void run() { if (null != attViewer) { - updateViewer(getData(resource)); - Tree tree = attViewer.getTree(); - if (!tree.isDisposed()) { - if (null != resource - && (resource instanceof SingleResource && ((SingleResource) resource) - .isResourceAutomationInProgress())) { - tree.setEnabled(false); - } else { - tree.setEnabled(true); - } - } + if (null != resource + && null != resource + .getResourceRepresentation()) + attViewer.setInput(resource + .getResourceRepresentation()); + /* + * updateViewer(getData(resource)); Tree tree = + * attViewer.getTree(); if (!tree.isDisposed()) { if + * (null != resource && (resource instanceof + * SingleResource && ((SingleResource) resource) + * .isResourceAutomationInProgress())) { + * tree.setEnabled(false); } else { + * tree.setEnabled(true); } } + */ } } }); @@ -131,22 +133,17 @@ public class AttributeView extends ViewPart { if (null == resourceInSelection) { return; } - if (resource != resourceInSelection) { - // This notification is for a different resource - // whose attributes are not - // currently not being shown in UI. So ignoring this - // notification. - return; - } - // Refresh the table viewers which will display - // the updated values - if (null != attViewer) { - if (resource instanceof CollectionResource) { - updateViewer(getData(resource)); - } else { - updateViewer(getData(resource)); - } - } + /* + * if (resource != resourceInSelection) { // This + * notification is for a different resource // whose + * attributes are not // currently not being shown in + * UI. So ignoring this // notification. return; } // + * Refresh the table viewers which will display // the + * updated values if (null != attViewer) { if (resource + * instanceof CollectionResource) { + * updateViewer(getData(resource)); } else { + * updateViewer(getData(resource)); } } + */ } }); } @@ -272,10 +269,9 @@ public class AttributeView extends ViewPart { addManagerListeners(); // Check whether there is any resource selected already - List propertyList = getData(resourceManager - .getCurrentResourceInSelection()); - if (null != propertyList) { - updateViewer(propertyList); + Resource resource = resourceManager.getCurrentResourceInSelection(); + if (resource != null) { + attViewer.setInput(resource.getResourceRepresentation()); } } @@ -345,128 +341,84 @@ public class AttributeView extends ViewPart { } } - class AttributeContentProvider implements ITreeContentProvider { + class AttributeContentProvider implements ITreeContentProvider, + DataChangeListener { + + private TreeViewer mTreeViewer; @Override public void dispose() { } @Override - public void inputChanged(Viewer arg0, Object arg1, Object arg2) { + public void inputChanged(Viewer viewer, Object oldAttribute, + Object newAttribute) { + mTreeViewer = (TreeViewer) viewer; } @Override - public Object[] getChildren(Object element) { - if (element instanceof SimulatorResourceAttribute - || element instanceof LocalResourceAttribute) { - SimulatorResourceAttribute att; - if (element instanceof LocalResourceAttribute) { - LocalResourceAttribute localAtt = (LocalResourceAttribute) element; - att = localAtt.getResourceAttributeRef(); - if (null == att) { - return new Object[1]; - } - } else { - att = (SimulatorResourceAttribute) element; - } - AttributeValue val = att.value(); - if (null == val) { - return new Object[1]; - } - TypeInfo type = val.typeInfo(); - if (type.mType == ValueType.RESOURCEMODEL) { - SimulatorResourceModel model = (SimulatorResourceModel) val - .get(); - if (null == model) { - return new Object[1]; - } - return resourceManager.getAttributes(model).toArray(); - } else if (type.mType == ValueType.ARRAY - && type.mBaseType == ValueType.RESOURCEMODEL - && type.mDepth == 1) { - SimulatorResourceModel[] model = (SimulatorResourceModel[]) val - .get(); - if (null == model || model.length < 1) { - return new Object[1]; - } - return resourceManager.getIndexedAttributes(model) - .toArray(); - } - } else if (element instanceof SRMItem) { - SRMItem item = (SRMItem) element; - SimulatorResourceModel model = (SimulatorResourceModel) item - .getModel(); - if (null == model) { - return new Object[1]; - } - return resourceManager.getAttributes(model).toArray(); + public Object[] getChildren(Object attribute) { + if (attribute instanceof AttributeElement) { + return ((AttributeElement) attribute).getChildren().values() + .toArray(); } - return new Object[1]; + + return new Object[0]; } @Override - public Object[] getElements(Object element) { - Object[] elements = (Object[]) element; - return elements; + public Object getParent(Object attribute) { + if (attribute instanceof AttributeElement) + return ((AttributeElement) attribute).getParent(); + return null; } @Override - public Object getParent(Object element) { - return null; + public boolean hasChildren(Object attribute) { + if (attribute instanceof AttributeElement) + return ((AttributeElement) attribute).hasChildren(); + return false; } @Override - public boolean hasChildren(Object element) { - if (element instanceof SimulatorResourceAttribute - || element instanceof LocalResourceAttribute) { - SimulatorResourceAttribute att; - if (element instanceof LocalResourceAttribute) { - LocalResourceAttribute localAtt = (LocalResourceAttribute) element; - att = localAtt.getResourceAttributeRef(); - if (null == att) { - return false; - } - } else { - att = (SimulatorResourceAttribute) element; - } - AttributeValue val = att.value(); - if (null == val) { - return false; - } - TypeInfo type = val.typeInfo(); - if (type.mType == ValueType.RESOURCEMODEL) { - SimulatorResourceModel model = (SimulatorResourceModel) val - .get(); - if (null == model) { - return false; - } - Map attributes = model - .getAttributes(); - if (null != attributes && attributes.size() > 0) { - return true; - } - } else if (type.mType == ValueType.ARRAY - && type.mBaseType == ValueType.RESOURCEMODEL - && type.mDepth == 1) { - SimulatorResourceModel[] model = (SimulatorResourceModel[]) val - .get(); - if (null != model && model.length > 0) { - return true; - } + public Object[] getElements(Object resourceModel) { + if (resourceModel instanceof ResourceRepresentation) { + ((ResourceRepresentation) resourceModel).setListener(this); + return ((ResourceRepresentation) resourceModel).getAttributes() + .values().toArray(); + } + + return new Object[0]; + } + + @Override + public void add(final AttributeElement attribute) { + Display.getDefault().asyncExec(new Runnable() { + @Override + public void run() { + mTreeViewer.refresh(attribute.getParent()); } - } else if (element instanceof SRMItem) { - SRMItem srmItem = (SRMItem) element; - SimulatorResourceModel model = srmItem.getModel(); - if (null == model) { - return false; + }); + } + + @Override + public void remove(final AttributeElement attribute) { + Display.getDefault().asyncExec(new Runnable() { + @Override + public void run() { + mTreeViewer.refresh(attribute.getParent()); } - Map attributes = model - .getAttributes(); - if (null != attributes && attributes.size() > 0) { - return true; + }); + } + + @Override + public void update(final AttributeElement attribute) { + Display.getDefault().asyncExec(new Runnable() { + @Override + public void run() { + mTreeViewer.update(attribute, null); } - } - return false; + }); } } @@ -493,110 +445,89 @@ public class AttributeView extends ViewPart { @Override public Image getColumnImage(Object element, int col) { if (col == 2) { - if (element instanceof SimulatorResourceAttribute - || element instanceof LocalResourceAttribute) { - SimulatorResourceAttribute att; - if (element instanceof LocalResourceAttribute) { - LocalResourceAttribute localAtt = (LocalResourceAttribute) element; - att = localAtt.getResourceAttributeRef(); - } else { - att = (SimulatorResourceAttribute) element; - } - AttributeValue val = att.value(); - if (null == val) { - return null; - } - TypeInfo type = val.typeInfo(); - if (type.mType == ValueType.RESOURCEMODEL - || type.mType == ValueType.ARRAY) { - return null; - } - if (element instanceof LocalResourceAttribute) { - if (!resourceManager.isAttHasRangeOrAllowedValues(att)) { - System.out.println("No range or allowed values"); - return null; - } - if (((LocalResourceAttribute) element) - .isAutomationInProgress()) { - return Activator.getDefault().getImageRegistry() - .get(Constants.CHECKED); + if (element instanceof AttributeElement) { + // Ignore for collection resource + Resource res = resourceManager + .getCurrentResourceInSelection(); + if (res instanceof SingleResource) { + AttributeElement attrElement = (AttributeElement) element; + SimulatorResourceAttribute attribute = attrElement + .getSimulatorResourceAttribute(); + TypeInfo type = attribute.value().typeInfo(); + if (attrElement.isAutoUpdateSupport() + && !attrElement.isReadOnly()) { + if (attrElement.isAutoUpdateInProgress()) { + return Activator.getDefault() + .getImageRegistry() + .get(Constants.CHECKED); + } else { + return Activator.getDefault() + .getImageRegistry() + .get(Constants.UNCHECKED); + } } - return Activator.getDefault().getImageRegistry() - .get(Constants.UNCHECKED); } - return null; } } return null; } @Override - public String getColumnText(Object element, int col) { - if (element instanceof SimulatorResourceAttribute - || element instanceof LocalResourceAttribute) { - SimulatorResourceAttribute att; - if (element instanceof LocalResourceAttribute) { - LocalResourceAttribute localAtt = (LocalResourceAttribute) element; - att = localAtt.getResourceAttributeRef(); - } else { - att = (SimulatorResourceAttribute) element; - } - AttributeValue val = att.value(); - if (null == val) { - return ""; - } - TypeInfo type = val.typeInfo(); - switch (col) { - case 0: - return att.name(); - case 1: - if (!(type.mType == ValueType.RESOURCEMODEL || (type.mType == ValueType.ARRAY && type.mBaseType == ValueType.RESOURCEMODEL))) { - String value = Utility - .getAttributeValueAsString(val); - if (null == value) { - value = ""; - } - return value; - } else { - return ""; - } - case 2: + public String getColumnText(Object element, int column) { + if (element instanceof AttributeElement) { + AttributeElement attrElement = (AttributeElement) element; + switch (column) { + case 0: // Attribute name column + { + SimulatorResourceAttribute attribute = attrElement + .getSimulatorResourceAttribute(); + return attribute.name(); + } + + case 1: // Attribute value column + { + SimulatorResourceAttribute attribute = attrElement + .getSimulatorResourceAttribute(); + + if (attribute.value().typeInfo().mBaseType != ValueType.RESOURCEMODEL) + return Utility.getAttributeValueAsString(attribute + .value()); + return null; + } + + case 2: { + // Ignore for collection resource Resource res = resourceManager .getCurrentResourceInSelection(); - if (null != res && res instanceof CollectionResource) { - return "-"; - } - - if (type.mType == ValueType.RESOURCEMODEL - || type.mType == ValueType.ARRAY) { - return ""; - } - if (element instanceof LocalResourceAttribute) { - if (!resourceManager - .isAttHasRangeOrAllowedValues(att)) { - System.out - .println("No range or allowed values"); - return "Read Only"; - } - if (((LocalResourceAttribute) element) - .isAutomationInProgress()) { - return Constants.ENABLED; + if (res instanceof SingleResource) { + SimulatorResourceAttribute attribute = attrElement + .getSimulatorResourceAttribute(); + TypeInfo type = attribute.value().typeInfo(); + if (type.mType == AttributeValue.ValueType.ARRAY) { + if (type.mBaseType != AttributeValue.ValueType.RESOURCEMODEL) { + return "NA"; + } + } else if (type.mType != AttributeValue.ValueType.RESOURCEMODEL) { + Object parent = attrElement.getParent(); + if (null != parent + && !(parent instanceof ResourceRepresentation)) { + return "NA"; + } else if (attrElement.isReadOnly()) { + return "Read-only"; + } else if (attrElement.isAutoUpdateSupport()) { + if (attrElement.isAutoUpdateInProgress()) + return Constants.ENABLED; + else + return Constants.DISABLED; + } } - return Constants.DISABLED; } - return "NA"; - } - } else if (element instanceof SRMItem) { - SRMItem item = (SRMItem) element; - switch (col) { - case 0: - return "[" + item.getIndex() + "]"; - case 1: - return ""; - case 2: + return ""; + } } } + return null; } 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 9098bcf..20fac74 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 @@ -500,7 +500,6 @@ public class CreateResourceWizard extends Wizard { .createSingleResource(resource); if (result) { status = "Resource created."; - resource.printResourceInfo(); } else { status = "Failed to create resource."; } @@ -532,7 +531,6 @@ public class CreateResourceWizard extends Wizard { if (result) { status = "Resource created."; - loadRamlPage.getResource().printResourceInfo(); } else { status = "Failed to create resource."; } diff --git a/service/simulator/java/jni/simulator_manager_jni.cpp b/service/simulator/java/jni/simulator_manager_jni.cpp index 3391685..ab1a338 100644 --- a/service/simulator/java/jni/simulator_manager_jni.cpp +++ b/service/simulator/java/jni/simulator_manager_jni.cpp @@ -270,7 +270,7 @@ Java_org_oic_simulator_SimulatorManager_setDeviceInfo JNIEXPORT void JNICALL Java_org_oic_simulator_SimulatorManager_findDevices -(JNIEnv *env, jobject object, jobject listener) +(JNIEnv *env, jobject object, jstring hostUri, jobject listener) { VALIDATE_CALLBACK(env, listener) @@ -282,7 +282,8 @@ Java_org_oic_simulator_SimulatorManager_findDevices try { - SimulatorManager::getInstance()->getDeviceInfo(callback); + JniString jniHostUri(env, hostUri); + SimulatorManager::getInstance()->getDeviceInfo(jniHostUri.get(), callback); } catch (InvalidArgsException &e) { @@ -314,7 +315,7 @@ Java_org_oic_simulator_SimulatorManager_setPlatformInfo JNIEXPORT void JNICALL Java_org_oic_simulator_SimulatorManager_getPlatformInformation -(JNIEnv *env, jobject object, jobject listener) +(JNIEnv *env, jobject object, jstring hostUri, jobject listener) { VALIDATE_CALLBACK(env, listener) @@ -326,7 +327,8 @@ Java_org_oic_simulator_SimulatorManager_getPlatformInformation try { - SimulatorManager::getInstance()->getPlatformInfo(callback); + JniString jniHostUri(env, hostUri); + SimulatorManager::getInstance()->getPlatformInfo(jniHostUri.get(), callback); } catch (InvalidArgsException &e) { diff --git a/service/simulator/java/jni/simulator_resource_model_jni.cpp b/service/simulator/java/jni/simulator_resource_model_jni.cpp index d363d0b..63babf1 100644 --- a/service/simulator/java/jni/simulator_resource_model_jni.cpp +++ b/service/simulator/java/jni/simulator_resource_model_jni.cpp @@ -492,18 +492,58 @@ class ValueConverterCpp void getValue(jobject &jValue, SimulatorResourceModel &value) { + simulatorResourceModelToCpp(m_env, jValue, value); } void getValue(jobject &jValue, std::vector &value) { + jobjectArray array = (jobjectArray) jValue; + size_t length = m_env->GetArrayLength(array); + std::vector result(length); + for (size_t i = 0; i < length; i++) + { + jobject jElement = m_env->GetObjectArrayElement(array, i); + + SimulatorResourceModel element; + getValue(jElement, element); + result[i] = element; + } + + value = result; } void getValue(jobject &jValue, std::vector> &value) { + jobjectArray array = (jobjectArray) jValue; + size_t length = m_env->GetArrayLength(array); + std::vector> result(length); + for (size_t i = 0; i < length; i++) + { + jobject jElement = m_env->GetObjectArrayElement(array, i); + + std::vector childArray; + getValue(jElement, childArray); + value[i] = childArray; + } + + value = result; } void getValue(jobject &jValue, std::vector>> &value) { + jobjectArray array = (jobjectArray) jValue; + size_t length = m_env->GetArrayLength(array); + std::vector>> result(length); + for (size_t i = 0; i < length; i++) + { + jobject jElement = m_env->GetObjectArrayElement(array, i); + + std::vector> childArray; + getValue(jElement, childArray); + value[i] = childArray; + } + + value = result; } JNIEnv *m_env; @@ -561,7 +601,7 @@ class JniAttributeProperty jAttributeProperty = env->NewObject(gSimulatorClassRefs.attributePropertyCls, propertyCtor, property.min(), property.max()); } - else + else if (SimulatorResourceModel::AttributeProperty::Type::VALUE_SET == property.type()) { static jmethodID propertyCtor = env->GetMethodID( gSimulatorClassRefs.attributePropertyCls, "", "([Lorg/oic/simulator/AttributeValue;)V"); @@ -578,6 +618,10 @@ class JniAttributeProperty jAttributeProperty = env->NewObject(gSimulatorClassRefs.attributePropertyCls, propertyCtor, jValueSet); } + else + { + return jAttributeProperty; + } // Add child property if (jAttributeProperty && property.getChildProperty()) @@ -684,7 +728,8 @@ jobject simulatorResourceModelToJava(JNIEnv *env, SimulatorResourceModel &resMod addEntryToHashMap(env, attributesMap, jAttrName, jAttributeValue); jobject jAttributeProperty = JniAttributeProperty::toJava(env, attributeEntry.second.getProperty()); - addEntryToHashMap(env, propertiesMap, jAttrName, jAttributeProperty); + if (jAttributeProperty) + addEntryToHashMap(env, propertiesMap, jAttrName, jAttributeProperty); } static jmethodID simulatorResourceModelCtor = env->GetMethodID( diff --git a/service/simulator/java/sdk/src/org/oic/simulator/AttributeProperty.java b/service/simulator/java/sdk/src/org/oic/simulator/AttributeProperty.java index b555f0e..32bfafb 100644 --- a/service/simulator/java/sdk/src/org/oic/simulator/AttributeProperty.java +++ b/service/simulator/java/sdk/src/org/oic/simulator/AttributeProperty.java @@ -21,10 +21,10 @@ package org.oic.simulator; */ public class AttributeProperty { - private Type mType = Type.UNKNOWN; - private double mMin = -1; - private double mMax = -1; - private AttributeValue[] mValueSet = null; + private Type mType = Type.UNKNOWN; + private double mMin = -1; + private double mMax = -1; + private AttributeValue[] mValueSet = null; private AttributeProperty mChildProperty = null; /** @@ -146,8 +146,8 @@ public class AttributeProperty { * API to set child attribute propety. * * @param childProperty - * Child element property this property used if the - * Attribute value is of array type. + * Child element property this property used if the Attribute + * value is of array type. */ public void setChildProperty(AttributeProperty childProperty) { mChildProperty = childProperty; diff --git a/service/simulator/java/sdk/src/org/oic/simulator/AttributeValueValidation.java b/service/simulator/java/sdk/src/org/oic/simulator/AttributeValueValidation.java index 935588f..30ace70 100644 --- a/service/simulator/java/sdk/src/org/oic/simulator/AttributeValueValidation.java +++ b/service/simulator/java/sdk/src/org/oic/simulator/AttributeValueValidation.java @@ -1,6 +1,7 @@ package org.oic.simulator; -public class AttributeValueValidation implements AttributeValueVisitor.VisitingMethods { +public class AttributeValueValidation implements + AttributeValueVisitor.VisitingMethods { private AttributeProperty mProperty = null; public AttributeValueValidation(AttributeProperty property) { @@ -67,7 +68,8 @@ public class AttributeValueValidation implements AttributeValueVisitor.VisitingM return false; if (mProperty.getChildProperty() != null) { - AttributeValueValidation rangeValidation = new AttributeValueValidation(mProperty.getChildProperty()); + AttributeValueValidation rangeValidation = new AttributeValueValidation( + mProperty.getChildProperty()); for (Integer value : values) { if (rangeValidation.visitingValue(value) == false) return false; @@ -86,7 +88,8 @@ public class AttributeValueValidation implements AttributeValueVisitor.VisitingM return false; if (mProperty.getChildProperty() != null) { - AttributeValueValidation rangeValidation = new AttributeValueValidation(mProperty.getChildProperty()); + AttributeValueValidation rangeValidation = new AttributeValueValidation( + mProperty.getChildProperty()); for (Double value : values) { if (rangeValidation.visitingValue(value) == false) return false; @@ -105,7 +108,8 @@ public class AttributeValueValidation implements AttributeValueVisitor.VisitingM return false; if (mProperty.getChildProperty() != null) { - AttributeValueValidation rangeValidation = new AttributeValueValidation(mProperty.getChildProperty()); + AttributeValueValidation rangeValidation = new AttributeValueValidation( + mProperty.getChildProperty()); for (Boolean value : values) { if (rangeValidation.visitingValue(value) == false) return false; @@ -124,7 +128,8 @@ public class AttributeValueValidation implements AttributeValueVisitor.VisitingM return false; if (mProperty.getChildProperty() != null) { - AttributeValueValidation rangeValidation = new AttributeValueValidation(mProperty.getChildProperty()); + AttributeValueValidation rangeValidation = new AttributeValueValidation( + mProperty.getChildProperty()); for (String value : values) { if (rangeValidation.visitingValue(value) == false) return false; @@ -148,7 +153,8 @@ public class AttributeValueValidation implements AttributeValueVisitor.VisitingM return false; if (mProperty.getChildProperty() != null) { - AttributeValueValidation rangeValidation = new AttributeValueValidation(mProperty.getChildProperty()); + AttributeValueValidation rangeValidation = new AttributeValueValidation( + mProperty.getChildProperty()); for (Integer[] value : values) { if (rangeValidation.visitingValue(value) == false) return false; @@ -167,7 +173,8 @@ public class AttributeValueValidation implements AttributeValueVisitor.VisitingM return false; if (mProperty.getChildProperty() != null) { - AttributeValueValidation rangeValidation = new AttributeValueValidation(mProperty.getChildProperty()); + AttributeValueValidation rangeValidation = new AttributeValueValidation( + mProperty.getChildProperty()); for (Double[] value : values) { if (rangeValidation.visitingValue(value) == false) return false; @@ -186,7 +193,8 @@ public class AttributeValueValidation implements AttributeValueVisitor.VisitingM return false; if (mProperty.getChildProperty() != null) { - AttributeValueValidation rangeValidation = new AttributeValueValidation(mProperty.getChildProperty()); + AttributeValueValidation rangeValidation = new AttributeValueValidation( + mProperty.getChildProperty()); for (Boolean[] value : values) { if (rangeValidation.visitingValue(value) == false) return false; @@ -205,7 +213,8 @@ public class AttributeValueValidation implements AttributeValueVisitor.VisitingM return false; if (mProperty.getChildProperty() != null) { - AttributeValueValidation rangeValidation = new AttributeValueValidation(mProperty.getChildProperty()); + AttributeValueValidation rangeValidation = new AttributeValueValidation( + mProperty.getChildProperty()); for (String[] value : values) { if (rangeValidation.visitingValue(value) == false) return false; @@ -229,7 +238,8 @@ public class AttributeValueValidation implements AttributeValueVisitor.VisitingM return false; if (mProperty.getChildProperty() != null) { - AttributeValueValidation rangeValidation = new AttributeValueValidation(mProperty.getChildProperty()); + AttributeValueValidation rangeValidation = new AttributeValueValidation( + mProperty.getChildProperty()); for (Integer[][] value : values) { if (rangeValidation.visitingValue(value) == false) return false; @@ -248,7 +258,8 @@ public class AttributeValueValidation implements AttributeValueVisitor.VisitingM return false; if (mProperty.getChildProperty() != null) { - AttributeValueValidation rangeValidation = new AttributeValueValidation(mProperty.getChildProperty()); + AttributeValueValidation rangeValidation = new AttributeValueValidation( + mProperty.getChildProperty()); for (Double[][] value : values) { if (rangeValidation.visitingValue(value) == false) return false; @@ -267,7 +278,8 @@ public class AttributeValueValidation implements AttributeValueVisitor.VisitingM return false; if (mProperty.getChildProperty() != null) { - AttributeValueValidation rangeValidation = new AttributeValueValidation(mProperty.getChildProperty()); + AttributeValueValidation rangeValidation = new AttributeValueValidation( + mProperty.getChildProperty()); for (Boolean[][] value : values) { if (rangeValidation.visitingValue(value) == false) return false; @@ -286,7 +298,8 @@ public class AttributeValueValidation implements AttributeValueVisitor.VisitingM return false; if (mProperty.getChildProperty() != null) { - AttributeValueValidation rangeValidation = new AttributeValueValidation(mProperty.getChildProperty()); + AttributeValueValidation rangeValidation = new AttributeValueValidation( + mProperty.getChildProperty()); for (String[][] value : values) { if (rangeValidation.visitingValue(value) == false) return false; @@ -311,7 +324,8 @@ public class AttributeValueValidation implements AttributeValueVisitor.VisitingM } private boolean checkValueSet(T value) { - if (AttributeProperty.Type.VALUESET == mProperty.type() && null != mProperty.valueSet()) { + if (AttributeProperty.Type.VALUESET == mProperty.type() + && null != mProperty.valueSet()) { for (AttributeValue allowedValue : mProperty.valueSet()) { if (allowedValue.get().equals(value)) return true; diff --git a/service/simulator/java/sdk/src/org/oic/simulator/AttributeValueVisitor.java b/service/simulator/java/sdk/src/org/oic/simulator/AttributeValueVisitor.java index 28fc0fb..0d2cea5 100644 --- a/service/simulator/java/sdk/src/org/oic/simulator/AttributeValueVisitor.java +++ b/service/simulator/java/sdk/src/org/oic/simulator/AttributeValueVisitor.java @@ -1,7 +1,7 @@ package org.oic.simulator; public class AttributeValueVisitor { - private AttributeValue mValue; + private AttributeValue mValue; private VisitingMethods mListener; public interface VisitingMethods { @@ -65,7 +65,8 @@ public class AttributeValueVisitor { if (2 == typeInfo.mDepth) return mListener.visitingValue((Integer[][]) mValue.get()); if (3 == typeInfo.mDepth) - return mListener.visitingValue((Integer[][][]) mValue.get()); + return mListener + .visitingValue((Integer[][][]) mValue.get()); } } else if (AttributeValue.ValueType.DOUBLE == typeInfo.mBaseType) { if (AttributeValue.ValueType.DOUBLE == typeInfo.mType) @@ -87,7 +88,8 @@ public class AttributeValueVisitor { if (2 == typeInfo.mDepth) return mListener.visitingValue((Boolean[][]) mValue.get()); if (3 == typeInfo.mDepth) - return mListener.visitingValue((Boolean[][][]) mValue.get()); + return mListener + .visitingValue((Boolean[][][]) mValue.get()); } } else if (AttributeValue.ValueType.STRING == typeInfo.mBaseType) { if (AttributeValue.ValueType.STRING == typeInfo.mType) @@ -102,14 +104,21 @@ public class AttributeValueVisitor { } } else if (AttributeValue.ValueType.RESOURCEMODEL == typeInfo.mBaseType) { if (AttributeValue.ValueType.RESOURCEMODEL == typeInfo.mType) - return mListener.visitingValue((SimulatorResourceModel) mValue.get()); + return mListener.visitingValue((SimulatorResourceModel) mValue + .get()); else if (AttributeValue.ValueType.ARRAY == typeInfo.mType) { if (1 == typeInfo.mDepth) - return mListener.visitingValue((SimulatorResourceModel[]) mValue.get()); + return mListener + .visitingValue((SimulatorResourceModel[]) mValue + .get()); if (2 == typeInfo.mDepth) - return mListener.visitingValue((SimulatorResourceModel[][]) mValue.get()); + return mListener + .visitingValue((SimulatorResourceModel[][]) mValue + .get()); if (3 == typeInfo.mDepth) - return mListener.visitingValue((SimulatorResourceModel[][][]) mValue.get()); + return mListener + .visitingValue((SimulatorResourceModel[][][]) mValue + .get()); } } diff --git a/service/simulator/java/sdk/src/org/oic/simulator/SimulatorManager.java b/service/simulator/java/sdk/src/org/oic/simulator/SimulatorManager.java index 4f4fb5e..e4d3772 100644 --- a/service/simulator/java/sdk/src/org/oic/simulator/SimulatorManager.java +++ b/service/simulator/java/sdk/src/org/oic/simulator/SimulatorManager.java @@ -148,11 +148,14 @@ public class SimulatorManager { /** * API to search for devices in the network. * + * @param hostUri + * URI of the host device. * @param listener * Listener for receiving the device information. */ - public static native void findDevices(DeviceListener listener) - throws InvalidArgsException, SimulatorException; + public static native void findDevices(String hostUri, + DeviceListener listener) throws InvalidArgsException, + SimulatorException; /** * API to set the platform information. @@ -166,11 +169,14 @@ public class SimulatorManager { /** * API to find all devices' platform information in the network. * + * @param hostUri + * URI of the host device. * @param listener * Listener for receiving the platform information. */ - public static native void getPlatformInformation(PlatformListener listener) - throws InvalidArgsException, SimulatorException; + public static native void getPlatformInformation(String hostUri, + PlatformListener listener) throws InvalidArgsException, + SimulatorException; /** * API to set the listener for receiving log messages. diff --git a/service/simulator/java/sdk/src/org/oic/simulator/SimulatorResourceAttribute.java b/service/simulator/java/sdk/src/org/oic/simulator/SimulatorResourceAttribute.java index e2db0f4..e8bbb39 100644 --- a/service/simulator/java/sdk/src/org/oic/simulator/SimulatorResourceAttribute.java +++ b/service/simulator/java/sdk/src/org/oic/simulator/SimulatorResourceAttribute.java @@ -78,10 +78,9 @@ public class SimulatorResourceAttribute { } /** - * API to get propety of attribute's value. + * API to get property of attribute's value. * - * @return Attribute's value property {@AttributeProperty - * }. + * @return Attribute's value property {@AttributeProperty}. */ public AttributeProperty property() { return mProperty; @@ -89,11 +88,21 @@ public class SimulatorResourceAttribute { /** * API to set the value of attribute. - * + * * @param value * Value of the attribute. */ public void setValue(AttributeValue value) { this.mValue = value; } + + /** + * API to set the property of attribute. + * + * @param value + * Property of the attribute. + */ + public void setProperty(AttributeProperty property) { + this.mProperty = property; + } } diff --git a/service/simulator/java/sdk/src/org/oic/simulator/SimulatorResourceModel.java b/service/simulator/java/sdk/src/org/oic/simulator/SimulatorResourceModel.java index 04c2de5..c1e3b80 100644 --- a/service/simulator/java/sdk/src/org/oic/simulator/SimulatorResourceModel.java +++ b/service/simulator/java/sdk/src/org/oic/simulator/SimulatorResourceModel.java @@ -180,8 +180,7 @@ public class SimulatorResourceModel { * @param attrName * Name of the attribute. * - * @return Attribute value type information {@AttributeValue.TypeInfo - * }. + * @return Attribute value type information {@AttributeValue.TypeInfo}. */ public AttributeValue.TypeInfo getAttributeType(String attrName) { if (mValues.containsKey(attrName)) @@ -218,6 +217,32 @@ public class SimulatorResourceModel { return mValues.size(); } + /** + * API to update the attribute values from given + * {@link SimulatorResourceModel}. + */ + public void update(SimulatorResourceModel resourceModel) { + if (null == resourceModel || 0 == resourceModel.size()) + return; + + for (Map.Entry entry : resourceModel + .getAttributes().entrySet()) { + SimulatorResourceAttribute newAttribute = entry.getValue(); + SimulatorResourceAttribute attribute = getAttribute(entry.getKey()); + if (null != newAttribute && null != attribute) { + if (null != attribute.property()) { + AttributeValueValidation validation = new AttributeValueValidation( + attribute.property()); + if (!validation.validate(newAttribute.value())) { + mValues.put(entry.getKey(), newAttribute.value()); + } + } else { + mValues.put(entry.getKey(), newAttribute.value()); + } + } + } + } + // Methods used in native code private SimulatorResourceModel(Map values, Map properties) { diff --git a/service/simulator/src/server/simulator_collection_resource_impl.cpp b/service/simulator/src/server/simulator_collection_resource_impl.cpp index b519c07..b9fcb62 100755 --- a/service/simulator/src/server/simulator_collection_resource_impl.cpp +++ b/service/simulator/src/server/simulator_collection_resource_impl.cpp @@ -31,6 +31,9 @@ SimulatorCollectionResourceImpl::SimulatorCollectionResourceImpl() m_resourceHandle(NULL) { m_property = static_cast(OC_DISCOVERABLE | OC_OBSERVABLE); + + std::vector links; + m_resModel.add("links", links); } std::string SimulatorCollectionResourceImpl::getName() const @@ -234,6 +237,11 @@ void SimulatorCollectionResourceImpl::setActionType(std::map &actionType) +{ + m_actionTypes = actionType; +} + std::vector SimulatorCollectionResourceImpl::getObserversList() { return m_observersList; @@ -601,4 +609,4 @@ RAML::ActionType SimulatorCollectionResourceImpl::getActionType(std::string requ return RAML::ActionType::DELETE; return RAML::ActionType::NONE; -} \ No newline at end of file +} diff --git a/service/simulator/src/simulator_manager.cpp b/service/simulator/src/simulator_manager.cpp index 001cbb3..4b10c14 100644 --- a/service/simulator/src/simulator_manager.cpp +++ b/service/simulator/src/simulator_manager.cpp @@ -49,7 +49,7 @@ std::shared_ptr SimulatorManager::createResource( VALIDATE_INPUT(configPath.empty(), "Empty path!") std::shared_ptr resource = - SimulatorResourceFactory::getInstance()->createResource(configPath); + SimulatorResourceFactory::getInstance()->createResource(configPath); if (!resource) throw SimulatorException(SIMULATOR_ERROR, "Failed to create resource!"); return resource; @@ -62,7 +62,7 @@ std::vector> SimulatorManager::createResource VALIDATE_INPUT(!count, "Count is zero!") std::vector> resources = - SimulatorResourceFactory::getInstance()->createResource(configPath, count); + SimulatorResourceFactory::getInstance()->createResource(configPath, count); if (!resources.size()) throw SimulatorException(SIMULATOR_ERROR, "Failed to create resource!"); return resources; @@ -133,7 +133,7 @@ void SimulatorManager::findResource(const std::string &resourceType, CT_DEFAULT, findCallback); } -void SimulatorManager::getDeviceInfo(DeviceInfoCallback callback) +void SimulatorManager::getDeviceInfo(const std::string &host, DeviceInfoCallback callback) { VALIDATE_CALLBACK(callback) @@ -149,14 +149,11 @@ void SimulatorManager::getDeviceInfo(DeviceInfoCallback callback) callback(deviceInfo); }, std::placeholders::_1, callback); - std::ostringstream uri; - uri << OC_MULTICAST_PREFIX << OC_RSRVD_DEVICE_URI; - typedef OCStackResult (*GetDeviceInfo)(const std::string &, const std::string &, OCConnectivityType, OC::FindDeviceCallback); - invokeocplatform(static_cast(OC::OCPlatform::getDeviceInfo), "", - uri.str(), CT_DEFAULT, deviceCallback); + invokeocplatform(static_cast(OC::OCPlatform::getDeviceInfo), host.c_str(), + "/oic/d", CT_DEFAULT, deviceCallback); } void SimulatorManager::setDeviceInfo(const std::string &deviceName) @@ -171,7 +168,7 @@ void SimulatorManager::setDeviceInfo(const std::string &deviceName) ocDeviceInfo); } -void SimulatorManager::getPlatformInfo(PlatformInfoCallback callback) +void SimulatorManager::getPlatformInfo(const std::string &host, PlatformInfoCallback callback) { VALIDATE_CALLBACK(callback) @@ -194,14 +191,11 @@ void SimulatorManager::getPlatformInfo(PlatformInfoCallback callback) callback(platformInfo); }, std::placeholders::_1, callback); - std::ostringstream uri; - uri << OC_MULTICAST_PREFIX << OC_RSRVD_PLATFORM_URI; - typedef OCStackResult (*GetPlatformInfo)(const std::string &, const std::string &, OCConnectivityType, OC::FindPlatformCallback); - invokeocplatform(static_cast(OC::OCPlatform::getPlatformInfo), "", - uri.str(), CT_DEFAULT, platformCallback); + invokeocplatform(static_cast(OC::OCPlatform::getPlatformInfo), host.c_str(), + "/oic/p", CT_DEFAULT, platformCallback); } void SimulatorManager::setPlatformInfo(PlatformInfo &platformInfo) diff --git a/service/simulator/unittests/SimulatorTest/src/org/oic/simulator/test/AttributeValueValidationTest.java b/service/simulator/unittests/SimulatorTest/src/org/oic/simulator/test/AttributeValueValidationTest.java index 96618f4..8ba72fa 100644 --- a/service/simulator/unittests/SimulatorTest/src/org/oic/simulator/test/AttributeValueValidationTest.java +++ b/service/simulator/unittests/SimulatorTest/src/org/oic/simulator/test/AttributeValueValidationTest.java @@ -46,8 +46,7 @@ public class AttributeValueValidationTest extends TestCase { } public void testValidateInt_N03() { - AttributeValueValidation validation = new AttributeValueValidation( - null); + AttributeValueValidation validation = new AttributeValueValidation(null); assertFalse(validation.validate(new AttributeValue(6))); } @@ -164,8 +163,7 @@ public class AttributeValueValidationTest extends TestCase { } public void testValidateDouble_N03() { - AttributeValueValidation validation = new AttributeValueValidation( - null); + AttributeValueValidation validation = new AttributeValueValidation(null); assertFalse(validation.validate(new AttributeValue(6.0))); } diff --git a/service/simulator/unittests/SimulatorTest/src/org/oic/simulator/test/SimulatorManagerTest.java b/service/simulator/unittests/SimulatorTest/src/org/oic/simulator/test/SimulatorManagerTest.java index c63170a..4d195a1 100644 --- a/service/simulator/unittests/SimulatorTest/src/org/oic/simulator/test/SimulatorManagerTest.java +++ b/service/simulator/unittests/SimulatorTest/src/org/oic/simulator/test/SimulatorManagerTest.java @@ -611,7 +611,7 @@ public class SimulatorManagerTest extends TestCase { try { SimulatorManager.setDeviceInfo("Samsung"); - SimulatorManager.findDevices(listener); + SimulatorManager.findDevices(null, listener); syncResult = true; } catch (InvalidArgsException e) { e.printStackTrace(); @@ -634,7 +634,7 @@ public class SimulatorManagerTest extends TestCase { ExceptionType exType = ExceptionType.UNKNOWN; try { - SimulatorManager.findDevices(null); + SimulatorManager.findDevices(null, null); } catch (InvalidArgsException e) { exType = ExceptionType.INVALID_ARGS; } catch (SimulatorException e) { @@ -652,7 +652,7 @@ public class SimulatorManagerTest extends TestCase { infoHolder); try { - SimulatorManager.getPlatformInformation(listener); + SimulatorManager.getPlatformInformation(null, listener); syncResult = true; } catch (InvalidArgsException e) { e.printStackTrace(); @@ -675,7 +675,7 @@ public class SimulatorManagerTest extends TestCase { ExceptionType exType = ExceptionType.UNKNOWN; try { - SimulatorManager.getPlatformInformation(null); + SimulatorManager.getPlatformInformation(null, null); } catch (InvalidArgsException e) { exType = ExceptionType.INVALID_ARGS; } catch (SimulatorException e) {