Moti Asayag has uploaded a new change for review.

Change subject: restapi: Add support for vnic profiles
......................................................................

restapi: Add support for vnic profiles

The patch adds support for the vnic profiles entity.
The vnic profiles is added as a top collection and also
as a sub collection of the network resource.

Change-Id: I7a0d472215ec1b0c359c0e2012e142ae8a627ce9
Signed-off-by: Moti Asayag <masa...@redhat.com>
---
M 
backend/manager/modules/restapi/interface/common/jaxrs/src/main/java/org/ovirt/engine/api/common/util/LinkHelper.java
A 
backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/resource/VnicProfileResource.java
A 
backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/resource/VnicProfilesResource.java
M 
backend/manager/modules/restapi/interface/definition/src/main/resources/api.xsd
M 
backend/manager/modules/restapi/interface/definition/src/main/resources/rsdl_metadata.yaml
M 
backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/BackendApplication.java
M 
backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendApiResource.java
A 
backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendVnicProfileResource.java
A 
backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendVnicProfilesResource.java
M 
backend/manager/modules/restapi/jaxrs/src/test/java/org/ovirt/engine/api/restapi/resource/BackendApiResourceTest.java
A 
backend/manager/modules/restapi/types/src/main/java/org/ovirt/engine/api/restapi/types/VnicProfileMapper.java
A 
backend/manager/modules/restapi/types/src/test/java/org/ovirt/engine/api/restapi/types/VnicProfileMapperTest.java
12 files changed, 440 insertions(+), 0 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/87/17587/1

diff --git 
a/backend/manager/modules/restapi/interface/common/jaxrs/src/main/java/org/ovirt/engine/api/common/util/LinkHelper.java
 
b/backend/manager/modules/restapi/interface/common/jaxrs/src/main/java/org/ovirt/engine/api/common/util/LinkHelper.java
index 503b60c..28f56a3 100644
--- 
a/backend/manager/modules/restapi/interface/common/jaxrs/src/main/java/org/ovirt/engine/api/common/util/LinkHelper.java
+++ 
b/backend/manager/modules/restapi/interface/common/jaxrs/src/main/java/org/ovirt/engine/api/common/util/LinkHelper.java
@@ -71,6 +71,7 @@
 import org.ovirt.engine.api.model.VM;
 import org.ovirt.engine.api.model.VersionCaps;
 import org.ovirt.engine.api.model.VmPool;
+import org.ovirt.engine.api.model.VnicProfile;
 import org.ovirt.engine.api.model.WatchDog;
 import org.ovirt.engine.api.resource.AssignedNetworkResource;
 import org.ovirt.engine.api.resource.AssignedNetworksResource;
@@ -154,6 +155,8 @@
 import org.ovirt.engine.api.resource.VmReportedDevicesResource;
 import org.ovirt.engine.api.resource.VmResource;
 import org.ovirt.engine.api.resource.VmsResource;
+import org.ovirt.engine.api.resource.VnicProfileResource;
+import org.ovirt.engine.api.resource.VnicProfilesResource;
 import org.ovirt.engine.api.resource.WatchdogResource;
 import org.ovirt.engine.api.resource.gluster.GlusterBrickResource;
 import org.ovirt.engine.api.resource.gluster.GlusterBricksResource;
@@ -341,6 +344,9 @@
 
         map = new ParentToCollectionMap(StepResource.class, 
StepsResource.class, Job.class);
         TYPES.put(Step.class, map);
+
+        map = new ParentToCollectionMap(VnicProfileResource.class, 
VnicProfilesResource.class);
+        TYPES.put(VnicProfile.class, map);
     }
 
     /**
diff --git 
a/backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/resource/VnicProfileResource.java
 
b/backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/resource/VnicProfileResource.java
new file mode 100644
index 0000000..db1984d
--- /dev/null
+++ 
b/backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/resource/VnicProfileResource.java
@@ -0,0 +1,29 @@
+/*
+* Copyright (c) 2010 Red Hat, Inc.
+*
+* 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 org.ovirt.engine.api.resource;
+
+import javax.ws.rs.Path;
+import javax.ws.rs.Produces;
+
+import org.ovirt.engine.api.model.VnicProfile;
+
+@Produces({ApiMediaType.APPLICATION_XML, ApiMediaType.APPLICATION_JSON, 
ApiMediaType.APPLICATION_X_YAML})
+public interface VnicProfileResource extends UpdatableResource<VnicProfile> {
+
+    @Path("permissions")
+    public AssignedPermissionsResource getPermissionsResource();
+}
diff --git 
a/backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/resource/VnicProfilesResource.java
 
b/backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/resource/VnicProfilesResource.java
new file mode 100644
index 0000000..108bbac
--- /dev/null
+++ 
b/backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/resource/VnicProfilesResource.java
@@ -0,0 +1,36 @@
+package org.ovirt.engine.api.resource;
+
+import javax.ws.rs.Consumes;
+import javax.ws.rs.DELETE;
+import javax.ws.rs.GET;
+import javax.ws.rs.POST;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.Response;
+
+import org.jboss.resteasy.annotations.providers.jaxb.Formatted;
+import org.ovirt.engine.api.model.VnicProfile;
+import org.ovirt.engine.api.model.VnicProfiles;
+
+
+@Path("/vnicprofiles")
+@Produces({ApiMediaType.APPLICATION_XML, ApiMediaType.APPLICATION_JSON, 
ApiMediaType.APPLICATION_X_YAML})
+public interface VnicProfilesResource {
+
+    @GET
+    @Formatted
+    public VnicProfiles list();
+
+    @POST
+    @Formatted
+    @Consumes({ApiMediaType.APPLICATION_XML, ApiMediaType.APPLICATION_JSON, 
ApiMediaType.APPLICATION_X_YAML})
+    public Response add(VnicProfile vnicProfile);
+
+    @DELETE
+    @Path("{id}")
+    public Response remove(@PathParam("id") String id);
+
+    @Path("{id}")
+    public VnicProfileResource getVnicProfileSubResource(@PathParam("id") 
String id);
+}
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 4e58c59..16d18fb 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
@@ -1842,6 +1842,7 @@
           <xs:element name="mtu" type="xs:int" minOccurs="0"/>
           <xs:element ref="usages" minOccurs="0" maxOccurs="1"/>
           <xs:element name="required" type="xs:boolean" minOccurs="0"/>
+          <xs:element ref="vnic_profiles" minOccurs="0" maxOccurs="1"/>
         </xs:sequence>
       </xs:extension>
     </xs:complexContent>
@@ -1876,6 +1877,38 @@
     </xs:complexContent>
   </xs:complexType>
 
+  <!-- Vnic Profiles -->
+  <xs:element name="vnic_profile" type="VnicProfile"/>
+
+  <xs:element name="vnic_profiles" type="VnicProfiles" />
+
+  <xs:complexType name="VnicProfile">
+    <xs:complexContent>
+      <xs:extension base="BaseResource">
+        <xs:sequence>
+          <xs:element ref="network" minOccurs="1" maxOccurs="1"/>
+          <xs:element name="port_mirroring" type="xs:boolean" minOccurs="0"/>
+          <xs:element ref="custom_properties" minOccurs="0"/>
+        </xs:sequence>
+      </xs:extension>
+    </xs:complexContent>
+  </xs:complexType>
+
+  <xs:complexType name="VnicProfiles">
+    <xs:complexContent>
+      <xs:extension base="BaseResources">
+        <xs:sequence>
+          <xs:annotation>
+            <xs:appinfo>
+                <jaxb:property name="VnicProfiles"/>
+            </xs:appinfo>
+          </xs:annotation>
+          <xs:element ref="vnic_profile" minOccurs="0" maxOccurs="unbounded"/>
+        </xs:sequence>
+      </xs:extension>
+    </xs:complexContent>
+  </xs:complexType>
+
   <!-- Storage Domains -->
 
   <xs:element name="storage_domain" type="StorageDomain"/>
diff --git 
a/backend/manager/modules/restapi/interface/definition/src/main/resources/rsdl_metadata.yaml
 
b/backend/manager/modules/restapi/interface/definition/src/main/resources/rsdl_metadata.yaml
index 3a6eb35..7b07c5b 100644
--- 
a/backend/manager/modules/restapi/interface/definition/src/main/resources/rsdl_metadata.yaml
+++ 
b/backend/manager/modules/restapi/interface/definition/src/main/resources/rsdl_metadata.yaml
@@ -2306,6 +2306,92 @@
       Content-Type: {value: application/xml|json, required: true}
       Expect: {value: 201-created, required: false}
       Correlation-Id: {value: 'any string', required: false}
+- name: /api/vnicprofiles|rel=get
+  request:
+    body:
+      parameterType: null
+      signatures: []
+    urlparams: {}
+    headers: {}
+- name: /api/vnicprofiles/{vnicprofile:id}|rel=get
+  request:
+    body:
+      parameterType: null
+      signatures: []
+    urlparams: {}
+    headers: {}
+- name: /api/vnicprofiles/{vnicprofile:id}|rel=delete
+  request:
+    body:
+      parameterType: null
+      signatures: []
+    urlparams:
+      async: {context: matrix, type: 'xs:boolean', value: true|false, 
required: false}
+    headers:
+      Correlation-Id: {value: 'any string', required: false}
+- name: /api/vnicprofiles/{vnicprofile:id}|rel=update
+  request:
+    body:
+      parameterType: VnicProfile
+      signatures:
+      - mandatoryArguments: {}
+        optionalArguments: {vnicprofile.name: 'xs:string', 
vnicprofile.description: 'xs:string', vnicprofile.port_mirroring: 'xs:boolean',
+        vnicprofile.custom_properties.custom_property--COLLECTION: 
{custom_property.name: 'xs:string', custom_property.value: 'xs:string'}}
+    urlparams: {}
+    headers:
+      Content-Type: {value: application/xml|json, required: true}
+      Correlation-Id: {value: 'any string', required: false}
+- name: /api/vnicprofiles|rel=add
+  request:
+    body:
+      parameterType: VnicProfile
+      signatures:
+      - mandatoryArguments: {vnicprofile.network.id: 'xs:string', 
vnicprofile.name: 'xs:string'}
+        optionalArguments: {vnicprofile.description: 'xs:string', 
vnicprofile.port_mirroring: 'xs:boolean',
+        vnicprofile.custom_properties.custom_property--COLLECTION: 
{custom_property.name: 'xs:string', custom_property.value: 'xs:string'}}
+    urlparams: {}
+    headers:
+      Content-Type: {value: application/xml|json, required: true}
+      Expect: {value: 201-created, required: false}
+      Correlation-Id: {value: 'any string', required: false}
+- name: /api/vnicprofiles/{vnicprofile:id}/permissions|rel=get
+  request:
+    body:
+      parameterType: null
+      signatures: []
+    urlparams:
+      max: {context: matrix, type: 'xs:int', value: 'max results', required: 
false}
+    headers: {}
+- name: /api/vnicprofiles/{vnicprofile:id}/permissions/{permission:id}|rel=get
+  request:
+    body:
+      parameterType: null
+      signatures: []
+    urlparams: {}
+    headers: {}
+- name: 
/api/vnicprofiles/{vnicprofiles:id}/permissions/{permission:id}|rel=delete
+  request:
+    body:
+      parameterType: null
+      signatures: []
+    urlparams:
+      async: {context: matrix, type: 'xs:boolean', value: true|false, 
required: false}
+    headers:
+      Correlation-Id: {value: 'any string', required: false}
+- name: /api/vnicprofiles/{vnicprofile:id}/permissions|rel=add
+  request:
+    body:
+      parameterType: Permission
+      signatures:
+      - mandatoryArguments: {permission.user.id: 'xs:string', 
permission.role.id: 'xs:string'}
+        optionalArguments: {}
+      - mandatoryArguments: {permission.group.id: 'xs:string', 
permission.role.id: 'xs:string'}
+        optionalArguments: {}
+    urlparams: {}
+    headers:
+      Content-Type: {value: application/xml|json, required: true}
+      Expect: {value: 201-created, required: false}
+      Correlation-Id: {value: 'any string', required: false}
 - name: /api/roles|rel=get
   request:
     body:
diff --git 
a/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/BackendApplication.java
 
b/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/BackendApplication.java
index 37471bc..b063d9e 100644
--- 
a/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/BackendApplication.java
+++ 
b/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/BackendApplication.java
@@ -56,6 +56,7 @@
 import org.ovirt.engine.api.restapi.resource.BackendUsersResource;
 import org.ovirt.engine.api.restapi.resource.BackendVmPoolsResource;
 import org.ovirt.engine.api.restapi.resource.BackendVmsResource;
+import org.ovirt.engine.api.restapi.resource.BackendVnicProfilesResource;
 import 
org.ovirt.engine.api.restapi.resource.validation.MalformedIdExceptionMapper;
 import org.ovirt.engine.api.restapi.resource.validation.ValidatorLocator;
 import org.ovirt.engine.api.restapi.security.auth.LoginValidator;
@@ -132,6 +133,7 @@
         addResource(new BackendDomainsResource());
         addResource(new BackendJobsResource());
         addResource(new BackendStorageServerConnectionsResource());
+        addResource(new BackendVnicProfilesResource());
 
         // Authentication singletons:
         final BasicAuthorizationScheme scheme = new BasicAuthorizationScheme();
diff --git 
a/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendApiResource.java
 
b/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendApiResource.java
index 563c66a..e85d047 100644
--- 
a/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendApiResource.java
+++ 
b/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendApiResource.java
@@ -119,6 +119,7 @@
         links.add(createLink("disks", LinkFlags.SEARCHABLE));
         links.add(createLink("jobs"));
         links.add(createLink("storageconnections"));
+        links.add(createLink("vnicprofiles"));
         return links;
     }
 
diff --git 
a/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendVnicProfileResource.java
 
b/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendVnicProfileResource.java
new file mode 100644
index 0000000..5f375d8
--- /dev/null
+++ 
b/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendVnicProfileResource.java
@@ -0,0 +1,67 @@
+package org.ovirt.engine.api.restapi.resource;
+
+
+import javax.ws.rs.Consumes;
+import javax.ws.rs.GET;
+import javax.ws.rs.PUT;
+
+import org.ovirt.engine.api.model.VnicProfile;
+import org.ovirt.engine.api.resource.AssignedPermissionsResource;
+import org.ovirt.engine.api.resource.VnicProfileResource;
+import org.ovirt.engine.core.common.VdcObjectType;
+import org.ovirt.engine.core.common.action.VdcActionParametersBase;
+import org.ovirt.engine.core.common.action.VdcActionType;
+import org.ovirt.engine.core.common.action.VnicProfileParameters;
+import org.ovirt.engine.core.common.queries.GetPermissionsForObjectParameters;
+import org.ovirt.engine.core.common.queries.IdQueryParameters;
+import org.ovirt.engine.core.common.queries.VdcQueryType;
+import org.ovirt.engine.core.compat.Guid;
+
+public class BackendVnicProfileResource extends 
AbstractBackendSubResource<VnicProfile, 
org.ovirt.engine.core.common.businessentities.network.VnicProfile> implements 
VnicProfileResource {
+
+    protected BackendVnicProfileResource(String id) {
+        super(id, VnicProfile.class,
+                
org.ovirt.engine.core.common.businessentities.network.VnicProfile.class,
+                BackendVnicProfilesResource.SUB_COLLECTIONS);
+    }
+
+    @Override
+    @GET
+    public VnicProfile get() {
+        return performGet(VdcQueryType.GetVnicProfileById, new 
IdQueryParameters(guid));
+    }
+
+    @Override
+    @PUT
+    @Consumes({ "application/xml", "application/json", "application/x-yaml" })
+    public VnicProfile update(VnicProfile resource) {
+        return performUpdate(resource,
+                new QueryIdResolver<Guid>(VdcQueryType.GetVnicProfileById, 
IdQueryParameters.class),
+                VdcActionType.UpdateVnicProfile,
+                new UpdateParametersProvider());
+    }
+
+    @Override
+    protected VnicProfile doPopulate(VnicProfile model,
+            org.ovirt.engine.core.common.businessentities.network.VnicProfile 
entity) {
+        return model;
+    }
+
+    @Override
+    public AssignedPermissionsResource getPermissionsResource() {
+        return inject(new BackendAssignedPermissionsResource(guid,
+                VdcQueryType.GetPermissionsForObject,
+                new GetPermissionsForObjectParameters(guid),
+                VnicProfile.class,
+                VdcObjectType.VnicProfile));
+    }
+
+    protected class UpdateParametersProvider
+            implements ParametersProvider<VnicProfile, 
org.ovirt.engine.core.common.businessentities.network.VnicProfile> {
+        @Override
+        public VdcActionParametersBase getParameters(VnicProfile incoming,
+                
org.ovirt.engine.core.common.businessentities.network.VnicProfile entity) {
+            return new VnicProfileParameters(map(incoming, entity));
+        }
+    }
+}
diff --git 
a/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendVnicProfilesResource.java
 
b/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendVnicProfilesResource.java
new file mode 100644
index 0000000..619ac8c
--- /dev/null
+++ 
b/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendVnicProfilesResource.java
@@ -0,0 +1,83 @@
+package org.ovirt.engine.api.restapi.resource;
+
+import java.util.List;
+
+import javax.ws.rs.Consumes;
+import javax.ws.rs.GET;
+import javax.ws.rs.POST;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.core.Response;
+
+import org.ovirt.engine.api.model.VnicProfile;
+import org.ovirt.engine.api.model.VnicProfiles;
+import org.ovirt.engine.api.resource.VnicProfileResource;
+import org.ovirt.engine.api.resource.VnicProfilesResource;
+import org.ovirt.engine.core.common.action.VdcActionType;
+import org.ovirt.engine.core.common.action.VnicProfileParameters;
+import org.ovirt.engine.core.common.queries.IdQueryParameters;
+import org.ovirt.engine.core.common.queries.VdcQueryType;
+import org.ovirt.engine.core.compat.Guid;
+
+public class BackendVnicProfilesResource
+        extends AbstractBackendCollectionResource<VnicProfile, 
org.ovirt.engine.core.common.businessentities.network.VnicProfile>
+        implements VnicProfilesResource {
+
+    static final String[] SUB_COLLECTIONS = { "permissions" };
+
+    public BackendVnicProfilesResource() {
+        super(VnicProfile.class,
+                
org.ovirt.engine.core.common.businessentities.network.VnicProfile.class,
+                SUB_COLLECTIONS);
+    }
+
+    @Override
+    @GET
+    public VnicProfiles list() {
+        return 
mapCollection(getBackendCollection(VdcQueryType.GetAllVnicProfiles, new 
IdQueryParameters(Guid.Empty)));
+    }
+
+    private VnicProfiles 
mapCollection(List<org.ovirt.engine.core.common.businessentities.network.VnicProfile>
 entities) {
+        VnicProfiles collection = new VnicProfiles();
+        for (org.ovirt.engine.core.common.businessentities.network.VnicProfile 
entity : entities) {
+            collection.getVnicProfiles().add(addLinks(map(entity)));
+        }
+
+        return collection;
+    }
+
+    @Override
+    @POST
+    @Consumes({ "application/xml", "application/json", "application/x-yaml" })
+    public Response add(VnicProfile vnicProfile) {
+        validateParameters(vnicProfile, "name", "network.id");
+        org.ovirt.engine.core.common.businessentities.network.VnicProfile 
entity = map(vnicProfile);
+        return performCreate(VdcActionType.AddVnicProfile,
+                new VnicProfileParameters(entity),
+                new QueryIdResolver<Guid>(VdcQueryType.GetVnicProfileById, 
IdQueryParameters.class));
+    }
+
+    @Override
+    @Path("{id}")
+    public VnicProfileResource getVnicProfileSubResource(@PathParam("id") 
String id) {
+        return inject(new BackendVnicProfileResource(id));
+    }
+
+    @Override
+    protected Response performRemove(String id) {
+        return performAction(VdcActionType.RemoveVnicProfile, new 
VnicProfileParameters(getVnicProfile(id)));
+    }
+
+    protected 
org.ovirt.engine.core.common.businessentities.network.VnicProfile 
getVnicProfile(String id) {
+        return 
getEntity(org.ovirt.engine.core.common.businessentities.network.VnicProfile.class,
+                VdcQueryType.GetVnicProfileById,
+                new IdQueryParameters(asGuidOr404(id)),
+                "VnicProfiles");
+    }
+
+    @Override
+    protected VnicProfile doPopulate(VnicProfile model,
+            org.ovirt.engine.core.common.businessentities.network.VnicProfile 
entity) {
+        return model;
+    }
+}
diff --git 
a/backend/manager/modules/restapi/jaxrs/src/test/java/org/ovirt/engine/api/restapi/resource/BackendApiResourceTest.java
 
b/backend/manager/modules/restapi/jaxrs/src/test/java/org/ovirt/engine/api/restapi/resource/BackendApiResourceTest.java
index dfe8399..46f153d 100644
--- 
a/backend/manager/modules/restapi/jaxrs/src/test/java/org/ovirt/engine/api/restapi/resource/BackendApiResourceTest.java
+++ 
b/backend/manager/modules/restapi/jaxrs/src/test/java/org/ovirt/engine/api/restapi/resource/BackendApiResourceTest.java
@@ -118,6 +118,7 @@
         "disks/search",
         "jobs",
         "storageconnections",
+        "vnicprofiles",
     };
 
     private static final String[] relationshipsGlusterOnly = {
@@ -170,6 +171,7 @@
         BASE_PATH + "/disks?search={query}",
         BASE_PATH + "/jobs",
         BASE_PATH + "/storageconnections",
+        BASE_PATH + "/vnicprofiles"
     };
 
     private static final String[] hrefsGlusterOnly = {
diff --git 
a/backend/manager/modules/restapi/types/src/main/java/org/ovirt/engine/api/restapi/types/VnicProfileMapper.java
 
b/backend/manager/modules/restapi/types/src/main/java/org/ovirt/engine/api/restapi/types/VnicProfileMapper.java
new file mode 100644
index 0000000..3b219e2
--- /dev/null
+++ 
b/backend/manager/modules/restapi/types/src/main/java/org/ovirt/engine/api/restapi/types/VnicProfileMapper.java
@@ -0,0 +1,66 @@
+package org.ovirt.engine.api.restapi.types;
+
+import org.ovirt.engine.api.model.CustomProperties;
+import org.ovirt.engine.api.model.Network;
+import org.ovirt.engine.api.model.VnicProfile;
+import org.ovirt.engine.api.restapi.utils.CustomPropertiesParser;
+import org.ovirt.engine.api.restapi.utils.GuidUtils;
+import org.ovirt.engine.core.utils.customprop.DevicePropertiesUtils;
+
+public class VnicProfileMapper {
+    @Mapping(from = VnicProfile.class, to = 
org.ovirt.engine.core.common.businessentities.network.VnicProfile.class)
+    public static 
org.ovirt.engine.core.common.businessentities.network.VnicProfile 
map(VnicProfile model,
+            org.ovirt.engine.core.common.businessentities.network.VnicProfile 
template) {
+        org.ovirt.engine.core.common.businessentities.network.VnicProfile 
entity =
+                template != null ? template : new 
org.ovirt.engine.core.common.businessentities.network.VnicProfile();
+        if (model.isSetId()) {
+            entity.setId(GuidUtils.asGuid(model.getId()));
+        }
+        if (model.isSetName()) {
+            entity.setName(model.getName());
+        }
+        if (model.isSetDescription()) {
+            entity.setDescription(model.getDescription());
+        }
+        if (model.isSetNetwork() && model.getNetwork().isSetId()) {
+            entity.setNetworkId(GuidUtils.asGuid(model.getNetwork().getId()));
+        }
+        if (model.isSetPortMirroring()) {
+            entity.setPortMirroring(model.isPortMirroring());
+        }
+        if (model.isSetCustomProperties()) {
+            entity.setCustomProperties(DevicePropertiesUtils.getInstance()
+                    
.convertProperties(CustomPropertiesParser.parse(model.getCustomProperties().getCustomProperty())));
+        }
+
+        return entity;
+    }
+
+    @Mapping(from = 
org.ovirt.engine.core.common.businessentities.network.VnicProfile.class, to = 
VnicProfile.class)
+    public static VnicProfile 
map(org.ovirt.engine.core.common.businessentities.network.VnicProfile entity,
+            VnicProfile template) {
+        VnicProfile model = template != null ? template : new VnicProfile();
+        if (entity.getId() != null) {
+            model.setId(entity.getId().toString());
+        }
+        if (entity.getName() != null) {
+            model.setName(entity.getName());
+        }
+        if (entity.getDescription() != null) {
+            model.setDescription(entity.getDescription());
+        }
+        if (entity.getNetworkId() != null) {
+            model.setNetwork(new Network());
+            model.getNetwork().setId(entity.getNetworkId().toString());
+        }
+        model.setPortMirroring(entity.isPortMirroring());
+        if (entity.getCustomProperties() != null && 
!entity.getCustomProperties().isEmpty()) {
+            CustomProperties hooks = new CustomProperties();
+            hooks.getCustomProperty().addAll(CustomPropertiesParser.parse(
+                    
DevicePropertiesUtils.getInstance().convertProperties(entity.getCustomProperties()),
 false));
+            model.setCustomProperties(hooks);
+        }
+
+        return model;
+    }
+}
diff --git 
a/backend/manager/modules/restapi/types/src/test/java/org/ovirt/engine/api/restapi/types/VnicProfileMapperTest.java
 
b/backend/manager/modules/restapi/types/src/test/java/org/ovirt/engine/api/restapi/types/VnicProfileMapperTest.java
new file mode 100644
index 0000000..38cbd63
--- /dev/null
+++ 
b/backend/manager/modules/restapi/types/src/test/java/org/ovirt/engine/api/restapi/types/VnicProfileMapperTest.java
@@ -0,0 +1,29 @@
+package org.ovirt.engine.api.restapi.types;
+
+import org.ovirt.engine.api.model.VnicProfile;
+import org.ovirt.engine.api.restapi.utils.CustomPropertiesParser;
+
+public class VnicProfileMapperTest extends 
AbstractInvertibleMappingTest<VnicProfile,
+        org.ovirt.engine.core.common.businessentities.network.VnicProfile,
+        org.ovirt.engine.core.common.businessentities.network.VnicProfile> {
+
+    public VnicProfileMapperTest() {
+        super(VnicProfile.class,
+                
org.ovirt.engine.core.common.businessentities.network.VnicProfile.class,
+                
org.ovirt.engine.core.common.businessentities.network.VnicProfile.class);
+    }
+
+    @Override
+    protected void verify(VnicProfile model, VnicProfile transform) {
+        assertNotNull(transform);
+        assertEquals(model.getId(), transform.getId());
+        assertEquals(model.getName(), transform.getName());
+        assertEquals(model.getDescription(), transform.getDescription());
+        assertNotNull(transform.getNetwork());
+        assertEquals(model.getNetwork().getId(), 
transform.getNetwork().getId());
+        assertEquals(model.isPortMirroring(), transform.isPortMirroring());
+        assertNotNull(transform.getCustomProperties());
+        
assertEquals(CustomPropertiesParser.parse(model.getCustomProperties().getCustomProperty()),
+                
CustomPropertiesParser.parse(transform.getCustomProperties().getCustomProperty()));
+    }
+}


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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I7a0d472215ec1b0c359c0e2012e142ae8a627ce9
Gerrit-PatchSet: 1
Gerrit-Project: ovirt-engine
Gerrit-Branch: master
Gerrit-Owner: Moti Asayag <masa...@redhat.com>
_______________________________________________
Engine-patches mailing list
Engine-patches@ovirt.org
http://lists.ovirt.org/mailman/listinfo/engine-patches

Reply via email to