Lior Vernia has uploaded a new change for review. Change subject: restapi: Implement custom properties using elements ......................................................................
restapi: Implement custom properties using elements There exists an implementation where the key, value and validation regular expression are stored as attributes; this adds a different implementation, where they're stored as elements, which might be more flexbile in the future, e.g. if multiple values per key should be supported. Change-Id: I03173b72b4f9ab2906ca9a2989d6115efcb19264 Signed-off-by: Lior Vernia <[email protected]> --- M backend/manager/modules/restapi/interface/definition/src/main/resources/api.xsd M backend/manager/modules/restapi/types/src/main/java/org/ovirt/engine/api/restapi/utils/CustomPropertiesParser.java 2 files changed, 52 insertions(+), 0 deletions(-) git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/16/27316/1 diff --git a/backend/manager/modules/restapi/interface/definition/src/main/resources/api.xsd b/backend/manager/modules/restapi/interface/definition/src/main/resources/api.xsd index 87d5ca1..a0e04e1 100644 --- a/backend/manager/modules/restapi/interface/definition/src/main/resources/api.xsd +++ b/backend/manager/modules/restapi/interface/definition/src/main/resources/api.xsd @@ -2545,6 +2545,21 @@ </xs:sequence> </xs:complexType> + <xs:complexType name="Property"> + <xs:sequence> + <xs:element name="name" type="xs:string" minOccurs="1" maxOccurs="1"/> + <xs:element name="value" type="xs:string" minOccurs="1" maxOccurs="1"/> + </xs:sequence> + </xs:complexType> + + <xs:element name="properties" type="Properties"/> + + <xs:complexType name="Properties"> + <xs:sequence> + <xs:element name="property" type="Property" minOccurs="0" maxOccurs="unbounded"/> + </xs:sequence> + </xs:complexType> + <xs:element name="payloads" type="Payloads"/> <xs:complexType name="Payloads"> diff --git a/backend/manager/modules/restapi/types/src/main/java/org/ovirt/engine/api/restapi/utils/CustomPropertiesParser.java b/backend/manager/modules/restapi/types/src/main/java/org/ovirt/engine/api/restapi/utils/CustomPropertiesParser.java index 95de09c..705e281 100644 --- a/backend/manager/modules/restapi/types/src/main/java/org/ovirt/engine/api/restapi/utils/CustomPropertiesParser.java +++ b/backend/manager/modules/restapi/types/src/main/java/org/ovirt/engine/api/restapi/utils/CustomPropertiesParser.java @@ -1,9 +1,13 @@ package org.ovirt.engine.api.restapi.utils; import java.util.ArrayList; +import java.util.HashMap; import java.util.List; +import java.util.Map; import org.ovirt.engine.api.model.CustomProperty; +import org.ovirt.engine.api.model.Properties; +import org.ovirt.engine.api.model.Property; public class CustomPropertiesParser { @@ -61,4 +65,37 @@ } return buff.toString(); } + + /** + * Get a map containing the key:value pairs from the given Properties object. + * + * @param properties + * The key:value pairs. + * @return A newly-created map containing the key:value pairs. + */ + public static Map<String, String> toMap(Properties properties) { + Map<String, String> res = new HashMap<String, String>(); + for (Property property : properties.getProperty()) { + res.put(property.getName(), property.getValue()); + } + return res; + } + + /** + * Create a Properties object from a map containing key:value pairs. + * + * @param properties + * The map containing key:value pairs. + * @return A newly-created Properties object containing the key:value pairs. + */ + public static Properties fromMap(Map<String, String> properties) { + Properties res = new Properties(); + for (Map.Entry<String, String> entry : properties.entrySet()) { + Property property = new Property(); + property.setName(entry.getKey()); + property.setValue(entry.getValue()); + res.getProperty().add(property); + } + return res; + } } -- To view, visit http://gerrit.ovirt.org/27316 To unsubscribe, visit http://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I03173b72b4f9ab2906ca9a2989d6115efcb19264 Gerrit-PatchSet: 1 Gerrit-Project: ovirt-engine Gerrit-Branch: master Gerrit-Owner: Lior Vernia <[email protected]> _______________________________________________ Engine-patches mailing list [email protected] http://lists.ovirt.org/mailman/listinfo/engine-patches
