Juan Hernandez has uploaded a new change for review.

Change subject: codegen: Add method to get entity by string id
......................................................................

codegen: Add method to get entity by string id

Currently the method that allows retrieving an entity by id assumes that
the identifier is a UUID, but this isn't true for some entities. This
patch adds an additional method that allows retrieving entities by id
using a string as the parameter.

Change-Id: Idc86f12d1e336f02f6086d34e464d45a0ad9c48b
Related: https://bugzilla.redhat.com/1099818
Signed-off-by: Juan Hernandez <[email protected]>
(cherry picked from commit 8ad49637b4a55d019da64f23b1ef933023f0463f)
---
M 
ovirt-engine-sdk-java-codegen/src/main/java/org/ovirt/engine/sdk/codegen/templates/CollectionTemplate
M 
ovirt-engine-sdk-java-codegen/src/main/java/org/ovirt/engine/sdk/codegen/templates/SubCollectionTemplate
M 
ovirt-engine-sdk-java/src/main/java/org/ovirt/engine/sdk/common/CollectionDecorator.java
3 files changed, 56 insertions(+), 0 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine-sdk-java 
refs/changes/16/28016/1

diff --git 
a/ovirt-engine-sdk-java-codegen/src/main/java/org/ovirt/engine/sdk/codegen/templates/CollectionTemplate
 
b/ovirt-engine-sdk-java-codegen/src/main/java/org/ovirt/engine/sdk/codegen/templates/CollectionTemplate
index 7dc69bb..05f6fc6 100644
--- 
a/ovirt-engine-sdk-java-codegen/src/main/java/org/ovirt/engine/sdk/codegen/templates/CollectionTemplate
+++ 
b/ovirt-engine-sdk-java-codegen/src/main/java/org/ovirt/engine/sdk/codegen/templates/CollectionTemplate
@@ -74,5 +74,24 @@
         return getProxy().get(url, 
org.ovirt.engine.sdk.entities.$publicEntityName$.class, 
$decoratorEntityName$.class);
     }
 
+    /**
+     * Fetches $decoratorEntityName$ object by id.
+     *
+     * @return {@link $decoratorEntityName$ }
+     *
+     * @throws ClientProtocolException
+     *             Signals that HTTP/S protocol error has occurred.
+     * @throws ServerException
+     *             Signals that an oVirt api error has occurred.
+     * @throws IOException
+     *             Signals that an I/O exception of some sort has occurred.
+     */
+    @Override
+    public $decoratorEntityName$ getById(String id) throws 
ClientProtocolException,
+            ServerException, IOException {
+        String url = SLASH + getName() + SLASH + id;
+        return getProxy().get(url, 
org.ovirt.engine.sdk.entities.$publicEntityName$.class, 
$decoratorEntityName$.class);
+    }
+
 $methods$
 }
diff --git 
a/ovirt-engine-sdk-java-codegen/src/main/java/org/ovirt/engine/sdk/codegen/templates/SubCollectionTemplate
 
b/ovirt-engine-sdk-java-codegen/src/main/java/org/ovirt/engine/sdk/codegen/templates/SubCollectionTemplate
index f2ee8c3..ace7863 100644
--- 
a/ovirt-engine-sdk-java-codegen/src/main/java/org/ovirt/engine/sdk/codegen/templates/SubCollectionTemplate
+++ 
b/ovirt-engine-sdk-java-codegen/src/main/java/org/ovirt/engine/sdk/codegen/templates/SubCollectionTemplate
@@ -79,5 +79,25 @@
         return getProxy().get(url, 
org.ovirt.engine.sdk.entities.$publicEntityName$.class, 
$decoratorEntityName$.class);
     }
 
+    /**
+     * Fetches $decoratorEntityName$ object by id.
+     *
+     * @return
+     *     {@link $decoratorEntityName$ }
+     *
+     * @throws ClientProtocolException
+     *             Signals that HTTP/S protocol error has occurred.
+     * @throws ServerException
+     *             Signals that an oVirt api error has occurred.
+     * @throws IOException
+     *             Signals that an I/O exception of some sort has occurred.
+     */
+    @Override
+    public $decoratorEntityName$ getById(String id) throws 
ClientProtocolException,
+            ServerException, IOException {
+        String url = this.parent.getHref() + SLASH + getName() + SLASH + id;
+        return getProxy().get(url, 
org.ovirt.engine.sdk.entities.$publicEntityName$.class, 
$decoratorEntityName$.class);
+    }
+
 $methods$
 }
diff --git 
a/ovirt-engine-sdk-java/src/main/java/org/ovirt/engine/sdk/common/CollectionDecorator.java
 
b/ovirt-engine-sdk-java/src/main/java/org/ovirt/engine/sdk/common/CollectionDecorator.java
index 1f07358..3e127cd 100644
--- 
a/ovirt-engine-sdk-java/src/main/java/org/ovirt/engine/sdk/common/CollectionDecorator.java
+++ 
b/ovirt-engine-sdk-java/src/main/java/org/ovirt/engine/sdk/common/CollectionDecorator.java
@@ -94,6 +94,23 @@
     abstract public Z get(UUID id) throws ClientProtocolException, 
ServerException, IOException;
 
     /**
+     * Fetches entity from the collection by id
+     *
+     * @param id
+     *            entity id
+     *
+     * @return Z
+     *
+     * @throws ClientProtocolException
+     *             Signals that HTTP/S protocol error has occurred.
+     * @throws ServerException
+     *             Signals that an oVirt api error has occurred.
+     * @throws IOException
+     *             Signals that an I/O exception of some sort has occurred.
+     */
+    abstract public Z getById(String id) throws ClientProtocolException, 
ServerException, IOException;
+
+    /**
      * Fetches object by name.
      * 
      * @param name


-- 
To view, visit http://gerrit.ovirt.org/28016
To unsubscribe, visit http://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Idc86f12d1e336f02f6086d34e464d45a0ad9c48b
Gerrit-PatchSet: 1
Gerrit-Project: ovirt-engine-sdk-java
Gerrit-Branch: sdk_3.5
Gerrit-Owner: Juan Hernandez <[email protected]>
_______________________________________________
Engine-patches mailing list
[email protected]
http://lists.ovirt.org/mailman/listinfo/engine-patches

Reply via email to