Juan Hernandez has uploaded a new change for review.

Change subject: resttapi: Move Event remove from collection to entity
......................................................................

resttapi: Move Event remove from collection to entity

This patch moves the method that implements the DELETE operation from
the collection interface to the entity interface. This is needed to
avoid issues with newer versions of Resteasy.

Change-Id: Ic63a9ff97b0a7dfa69b660c2b83c034cc673ecf4
Related: https://gerrit.ovirt.org/41783
Signed-off-by: Juan Hernandez <juan.hernan...@redhat.com>
---
M 
backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/resource/EventResource.java
M 
backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/resource/EventsResource.java
M 
backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendEventResource.java
M 
backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendEventsResource.java
A 
backend/manager/modules/restapi/jaxrs/src/test/java/org/ovirt/engine/api/restapi/resource/BackendEventResourceTest.java
M 
backend/manager/modules/restapi/jaxrs/src/test/java/org/ovirt/engine/api/restapi/resource/BackendEventsResourceTest.java
6 files changed, 99 insertions(+), 52 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/27/41827/1

diff --git 
a/backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/resource/EventResource.java
 
b/backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/resource/EventResource.java
index fd06f62..ac74711 100644
--- 
a/backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/resource/EventResource.java
+++ 
b/backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/resource/EventResource.java
@@ -16,13 +16,18 @@
 
 package org.ovirt.engine.api.resource;
 
+import javax.ws.rs.DELETE;
 import javax.ws.rs.GET;
 import javax.ws.rs.Produces;
+import javax.ws.rs.core.Response;
+
 import org.ovirt.engine.api.model.Event;
 
 @Produces( { ApiMediaType.APPLICATION_XML, ApiMediaType.APPLICATION_JSON, 
ApiMediaType.APPLICATION_X_YAML })
 public interface EventResource {
-
     @GET
-    public Event get();
+    Event get();
+
+    @DELETE
+    Response remove();
 }
diff --git 
a/backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/resource/EventsResource.java
 
b/backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/resource/EventsResource.java
index 087369d..25abbc6 100644
--- 
a/backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/resource/EventsResource.java
+++ 
b/backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/resource/EventsResource.java
@@ -17,7 +17,6 @@
 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;
@@ -33,23 +32,18 @@
 @Path("/events")
 @Produces( { ApiMediaType.APPLICATION_XML, ApiMediaType.APPLICATION_JSON, 
ApiMediaType.APPLICATION_X_YAML })
 public interface EventsResource {
-
     @GET
-    public Events list();
+    Events list();
 
     @POST
     @Consumes({ApiMediaType.APPLICATION_XML, ApiMediaType.APPLICATION_JSON, 
ApiMediaType.APPLICATION_X_YAML})
-    public Response add(Event event);
-
-    @DELETE
-    @Path("{id}")
-    public Response remove(@PathParam("id") String id);
+    Response add(Event event);
 
     @POST
     @Consumes({ApiMediaType.APPLICATION_XML, ApiMediaType.APPLICATION_JSON, 
ApiMediaType.APPLICATION_X_YAML})
     @Actionable
     @Path("undelete")
-    public Response undelete(Action action);
+    Response undelete(Action action);
 
     /**
      * Sub-resource locator method, returns individual EventResource on which 
the remainder of the URI is dispatched.
@@ -58,5 +52,5 @@
      * @return matching subresource if found
      */
     @Path("{id}")
-    public EventResource getEventSubResource(@PathParam("id") String id);
+    EventResource getEventSubResource(@PathParam("id") String id);
 }
diff --git 
a/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendEventResource.java
 
b/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendEventResource.java
index bee42e0..de88fe7 100644
--- 
a/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendEventResource.java
+++ 
b/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendEventResource.java
@@ -2,30 +2,42 @@
 
 import org.ovirt.engine.api.model.Event;
 import org.ovirt.engine.api.resource.EventResource;
+import org.ovirt.engine.core.common.action.RemoveAuditLogByIdParameters;
+import org.ovirt.engine.core.common.action.VdcActionType;
 import org.ovirt.engine.core.common.businessentities.AuditLog;
+import org.ovirt.engine.core.common.queries.GetAuditLogByIdParameters;
+import org.ovirt.engine.core.common.queries.VdcQueryType;
+import org.ovirt.engine.core.compat.Guid;
 
-public class BackendEventResource extends
-AbstractBackendResource<Event, AuditLog> implements EventResource {
-    private String id;
-    private BackendEventsResource parent;
+import javax.ws.rs.core.Response;
+
+public class BackendEventResource extends 
AbstractBackendActionableResource<Event, AuditLog> implements EventResource {
+    BackendEventsResource parent;
 
     public BackendEventResource(String id, BackendEventsResource parent) {
-        super(Event.class, AuditLog.class);
-        this.id = id;
+        super(id, Event.class, AuditLog.class);
         this.parent = parent;
-    }
-
-    public BackendEventResource() {
-        super(Event.class, AuditLog.class);
     }
 
     @Override
     public Event get() {
-        return parent.lookupEvent(id);
+        return performGet(VdcQueryType.GetAuditLogById, new 
GetAuditLogByIdParameters(asLong(id)));
     }
 
     @Override
     protected Event doPopulate(Event model, AuditLog entity) {
         return model;
     }
+
+    @Override
+    protected Guid asGuidOr404(String id) {
+        // The identifiers of events aren't UUIDs:
+        return null;
+    }
+
+    @Override
+    public Response remove() {
+        get();
+        return performAction(VdcActionType.RemoveAuditLogById, new 
RemoveAuditLogByIdParameters(asLong(id)));
+    }
 }
diff --git 
a/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendEventsResource.java
 
b/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendEventsResource.java
index 708f510..e368ddd 100644
--- 
a/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendEventsResource.java
+++ 
b/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendEventsResource.java
@@ -10,7 +10,6 @@
 import org.ovirt.engine.api.resource.EventResource;
 import org.ovirt.engine.api.resource.EventsResource;
 import org.ovirt.engine.core.common.action.AddExternalEventParameters;
-import org.ovirt.engine.core.common.action.RemoveAuditLogByIdParameters;
 import org.ovirt.engine.core.common.action.VdcActionParametersBase;
 import org.ovirt.engine.core.common.action.VdcActionType;
 import org.ovirt.engine.core.common.businessentities.AuditLog;
@@ -58,19 +57,6 @@
         }
     }
 
-    public Event lookupEvent(String id) {
-        try {
-            Long longId = Long.valueOf(id);
-            for (AuditLog auditLog : getBackendCollection()) {
-                if (auditLog.getAuditLogId() == longId)
-                    return addLinks(map(auditLog));
-            }
-            return notFound();
-        } catch (NumberFormatException e) {
-            return notFound();
-        }
-    }
-
     @Override
     public Response add(Event event) {
         validateParameters(event, "origin", "severity", "customId", 
"description");
@@ -78,11 +64,6 @@
         return performCreate(VdcActionType.AddExternalEvent,
                                new AddExternalEventParameters(map(event)),
                                new 
QueryIdResolver<Long>(VdcQueryType.GetAuditLogById, 
GetAuditLogByIdParameters.class));
-    }
-
-    @Override
-    protected Response performRemove(String id) {
-        return performAction(VdcActionType.RemoveAuditLogById, new 
RemoveAuditLogByIdParameters(asLong(id)));
     }
 
     @Override
diff --git 
a/backend/manager/modules/restapi/jaxrs/src/test/java/org/ovirt/engine/api/restapi/resource/BackendEventResourceTest.java
 
b/backend/manager/modules/restapi/jaxrs/src/test/java/org/ovirt/engine/api/restapi/resource/BackendEventResourceTest.java
new file mode 100644
index 0000000..804aea4
--- /dev/null
+++ 
b/backend/manager/modules/restapi/jaxrs/src/test/java/org/ovirt/engine/api/restapi/resource/BackendEventResourceTest.java
@@ -0,0 +1,65 @@
+package org.ovirt.engine.api.restapi.resource;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.ovirt.engine.api.model.Event;
+import org.ovirt.engine.core.common.AuditLogSeverity;
+import org.ovirt.engine.core.common.AuditLogType;
+import org.ovirt.engine.core.common.action.RemoveAuditLogByIdParameters;
+import org.ovirt.engine.core.common.action.VdcActionType;
+import org.ovirt.engine.core.common.businessentities.AuditLog;
+import org.ovirt.engine.core.common.queries.GetAuditLogByIdParameters;
+import org.ovirt.engine.core.common.queries.VdcQueryType;
+
+import java.util.Date;
+
+import static org.easymock.EasyMock.expect;
+
+public class BackendEventResourceTest extends 
AbstractBackendSubResourceTest<Event, AuditLog, BackendEventResource> {
+    private static final long[] LOG_IDS = { 1 };
+
+    public BackendEventResourceTest() {
+        super(new BackendEventResource(String.valueOf(LOG_IDS[0]), new 
BackendEventsResource()));
+    }
+
+    @Before
+    public void initParent() {
+        initResource(resource.parent);
+    }
+
+    @Test
+    public void testRemove() throws Exception {
+        setUpGetEntityExpectations();
+        setUriInfo(
+            setUpActionExpectations(
+                VdcActionType.RemoveAuditLogById,
+                RemoveAuditLogByIdParameters.class,
+                new String[] { "AuditLogId" },
+                new Object[] { LOG_IDS[0] },
+                true,
+                true
+            )
+        );
+        verifyRemove(resource.remove());
+    }
+
+    private void setUpGetEntityExpectations() throws Exception {
+        setUpGetEntityExpectations(
+            VdcQueryType.GetAuditLogById,
+            GetAuditLogByIdParameters.class,
+            new String[] { "Id" },
+            new Object[] { LOG_IDS[0] },
+            getEntity(0)
+        );
+    }
+
+    @Override
+    protected AuditLog getEntity(int index) {
+        AuditLog mock = control.createMock(AuditLog.class);
+        expect(mock.getAuditLogId()).andReturn(LOG_IDS[index]).anyTimes();
+        
expect(mock.getLogType()).andReturn(AuditLogType.EXTERNAL_ALERT).anyTimes();
+        
expect(mock.getSeverity()).andReturn(AuditLogSeverity.ALERT).anyTimes();
+        expect(mock.getLogTime()).andReturn(new Date()).anyTimes();
+        return mock;
+    }
+}
diff --git 
a/backend/manager/modules/restapi/jaxrs/src/test/java/org/ovirt/engine/api/restapi/resource/BackendEventsResourceTest.java
 
b/backend/manager/modules/restapi/jaxrs/src/test/java/org/ovirt/engine/api/restapi/resource/BackendEventsResourceTest.java
index 5c2202d..74253f6 100644
--- 
a/backend/manager/modules/restapi/jaxrs/src/test/java/org/ovirt/engine/api/restapi/resource/BackendEventsResourceTest.java
+++ 
b/backend/manager/modules/restapi/jaxrs/src/test/java/org/ovirt/engine/api/restapi/resource/BackendEventsResourceTest.java
@@ -15,7 +15,6 @@
 import org.ovirt.engine.core.common.AuditLogSeverity;
 import org.ovirt.engine.core.common.AuditLogType;
 import org.ovirt.engine.core.common.action.AddExternalEventParameters;
-import org.ovirt.engine.core.common.action.RemoveAuditLogByIdParameters;
 import org.ovirt.engine.core.common.action.VdcActionParametersBase;
 import org.ovirt.engine.core.common.action.VdcActionType;
 import org.ovirt.engine.core.common.businessentities.AuditLog;
@@ -75,15 +74,6 @@
         assertEquals(model.getCustomId(), CUSTOMER_EVENT_IDS[index]);
     }
 
-
-    @Test
-    public void testRemove() throws Exception {
-        setUriInfo(setUpBasicUriExpectations());
-        setUpActionExpectations(VdcActionType.RemoveAuditLogById, 
RemoveAuditLogByIdParameters.class, new String[] {
-                "AuditLogId" }, new Object[] { LOG_IDS[0] }, true, true, 
false);
-        setUpQueryExpectations("");
-        verifyRemove(collection.remove(String.valueOf(LOG_IDS[0])));
-    }
 
     protected org.ovirt.engine.core.common.businessentities.AuditLog 
getEntity(int index) {
         AuditLog auditLogMock = 
control.createMock(org.ovirt.engine.core.common.businessentities.AuditLog.class);


-- 
To view, visit https://gerrit.ovirt.org/41827
To unsubscribe, visit https://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ic63a9ff97b0a7dfa69b660c2b83c034cc673ecf4
Gerrit-PatchSet: 1
Gerrit-Project: ovirt-engine
Gerrit-Branch: master
Gerrit-Owner: Juan Hernandez <juan.hernan...@redhat.com>
_______________________________________________
Engine-patches mailing list
Engine-patches@ovirt.org
http://lists.ovirt.org/mailman/listinfo/engine-patches

Reply via email to