Alexander Wels has uploaded a new change for review. Change subject: restapi: bookmarks ......................................................................
restapi: bookmarks - Add support for bookmarks to the REST api. - The following URLs/verbs are now available: - /ovirt-engine/api/bookmarks (GET) get a list of book marks. - /ovirt-engine/api/bookmarks/{id} (GET) get book mark details. - /ovirt-engine/api/bookmarks/{id} (PUT) update book mark. - /ovirt-engine/api/bookmarks/{id} (DELETE) remove book mark. - /ovirt-engine/api/bookmarks (POST) add new book mark - The standard json and xml are available. The format is the following: <bookmark> <name>The name</name> <value>host.name=something</value> </bookmark> or { "name": "The name", "value": "host.name=something" } Change-Id: I068194732a45223dae22c18ffee5aaa0f3ec930d Bug-Url: https://bugzilla.redhat.com/show_bug.cgi?id=1075556 Signed-off-by: Alexander Wels <aw...@redhat.com> --- A backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/GetBookmarkByBookmarkIdQuery.java A backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/GetBookmarkByBookmarkNameQuery.java M backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/queries/VdcQueryType.java A backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/resource/BookmarkResource.java A backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/resource/BookmarksResource.java M backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/utils/ApiRootLinksCreator.java M backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/utils/LinkHelper.java M backend/manager/modules/restapi/interface/definition/src/main/resources/api.xsd M backend/manager/modules/restapi/interface/definition/src/main/resources/jyaml.yml 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 A backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendBookmarkResource.java A backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendBookmarksResource.java M backend/manager/modules/restapi/jaxrs/src/test/java/org/ovirt/engine/api/restapi/resource/BackendApiResourceTest.java A backend/manager/modules/restapi/jaxrs/src/test/java/org/ovirt/engine/api/restapi/resource/BackendBookmarkResourceTest.java A backend/manager/modules/restapi/jaxrs/src/test/java/org/ovirt/engine/api/restapi/resource/BackendBookmarksResourceTest.java A backend/manager/modules/restapi/types/src/main/java/org/ovirt/engine/api/restapi/types/BookmarkMapper.java A backend/manager/modules/restapi/types/src/test/java/org/ovirt/engine/api/restapi/types/BookmarkMapperTest.java 18 files changed, 707 insertions(+), 6 deletions(-) git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/69/26769/1 diff --git a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/GetBookmarkByBookmarkIdQuery.java b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/GetBookmarkByBookmarkIdQuery.java new file mode 100644 index 0000000..fd860c0 --- /dev/null +++ b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/GetBookmarkByBookmarkIdQuery.java @@ -0,0 +1,18 @@ +package org.ovirt.engine.core.bll; + +import org.ovirt.engine.core.common.queries.IdQueryParameters; +import org.ovirt.engine.core.dal.dbbroker.DbFacade; + +public class GetBookmarkByBookmarkIdQuery<P extends IdQueryParameters> extends QueriesCommandBase<P> { + + public GetBookmarkByBookmarkIdQuery(P parameters) { + super(parameters); + } + + @Override + protected void executeQueryCommand() { + getQueryReturnValue().setReturnValue( + DbFacade.getInstance().getBookmarkDao().get(getParameters().getId())); + } + +} diff --git a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/GetBookmarkByBookmarkNameQuery.java b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/GetBookmarkByBookmarkNameQuery.java new file mode 100644 index 0000000..8e2169a --- /dev/null +++ b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/GetBookmarkByBookmarkNameQuery.java @@ -0,0 +1,18 @@ +package org.ovirt.engine.core.bll; + +import org.ovirt.engine.core.common.queries.NameQueryParameters; +import org.ovirt.engine.core.dal.dbbroker.DbFacade; + +public class GetBookmarkByBookmarkNameQuery<P extends NameQueryParameters> extends QueriesCommandBase<P> { + + public GetBookmarkByBookmarkNameQuery(P parameters) { + super(parameters); + } + + @Override + protected void executeQueryCommand() { + getQueryReturnValue().setReturnValue( + DbFacade.getInstance().getBookmarkDao().getByName(getParameters().getName())); + } + +} diff --git a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/queries/VdcQueryType.java b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/queries/VdcQueryType.java index 9a657dc..b5774b4 100644 --- a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/queries/VdcQueryType.java +++ b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/queries/VdcQueryType.java @@ -167,6 +167,8 @@ // Bookmarks GetAllBookmarks, + GetBookmarkByBookmarkId, + GetBookmarkByBookmarkName, // Configuration values GetConfigurationValue(VdcQueryAuthType.User), diff --git a/backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/resource/BookmarkResource.java b/backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/resource/BookmarkResource.java new file mode 100644 index 0000000..d94f251 --- /dev/null +++ b/backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/resource/BookmarkResource.java @@ -0,0 +1,9 @@ +package org.ovirt.engine.api.resource; + +import javax.ws.rs.Produces; + +import org.ovirt.engine.api.model.Bookmark; + +@Produces({ApiMediaType.APPLICATION_XML, ApiMediaType.APPLICATION_JSON, ApiMediaType.APPLICATION_X_YAML}) +public interface BookmarkResource extends UpdatableResource<Bookmark> { +} diff --git a/backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/resource/BookmarksResource.java b/backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/resource/BookmarksResource.java new file mode 100644 index 0000000..71a8607 --- /dev/null +++ b/backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/resource/BookmarksResource.java @@ -0,0 +1,35 @@ +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.Bookmark; +import org.ovirt.engine.api.model.Bookmarks; + +@Path("/bookmarks") +@Produces({ApiMediaType.APPLICATION_XML, ApiMediaType.APPLICATION_JSON, ApiMediaType.APPLICATION_X_YAML}) +public interface BookmarksResource { + + @GET + @Formatted + Bookmarks list(); + + @POST + @Formatted + @Consumes({ApiMediaType.APPLICATION_XML, ApiMediaType.APPLICATION_JSON, ApiMediaType.APPLICATION_X_YAML}) + public Response add(Bookmark bookmark); + + @DELETE + @Path("{id}") + public Response remove(@PathParam("id") String id); + + @Path("{id}") + public BookmarkResource getBookmarkSubResource(@PathParam("id") String id); +} diff --git a/backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/utils/ApiRootLinksCreator.java b/backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/utils/ApiRootLinksCreator.java index 1b609c1..572a152 100644 --- a/backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/utils/ApiRootLinksCreator.java +++ b/backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/utils/ApiRootLinksCreator.java @@ -40,6 +40,7 @@ links.add(createLink("roles", baseUri)); links.add(createLink("storagedomains", LinkFlags.SEARCHABLE, baseUri)); links.add(createLink("tags", baseUri)); + links.add(createLink("bookmarks", baseUri)); links.add(createLink("templates", LinkFlags.SEARCHABLE, baseUri)); links.add(createLink("users", LinkFlags.SEARCHABLE, baseUri)); links.add(createLink("groups", LinkFlags.SEARCHABLE, baseUri)); diff --git a/backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/utils/LinkHelper.java b/backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/utils/LinkHelper.java index e9ff142..6d17a13 100644 --- a/backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/utils/LinkHelper.java +++ b/backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/utils/LinkHelper.java @@ -32,6 +32,7 @@ import org.ovirt.engine.api.model.AffinityGroup; import org.ovirt.engine.api.model.Application; import org.ovirt.engine.api.model.BaseResource; +import org.ovirt.engine.api.model.Bookmark; import org.ovirt.engine.api.model.CdRom; import org.ovirt.engine.api.model.Cluster; import org.ovirt.engine.api.model.DataCenter; @@ -88,6 +89,8 @@ import org.ovirt.engine.api.resource.AssignedTagsResource; import org.ovirt.engine.api.resource.AttachedStorageDomainResource; import org.ovirt.engine.api.resource.AttachedStorageDomainsResource; +import org.ovirt.engine.api.resource.BookmarkResource; +import org.ovirt.engine.api.resource.BookmarksResource; import org.ovirt.engine.api.resource.CapabilitiesResource; import org.ovirt.engine.api.resource.CapabiliyResource; import org.ovirt.engine.api.resource.ClusterResource; @@ -313,6 +316,9 @@ map.add(AssignedTagResource.class, AssignedTagsResource.class, Group.class); TYPES.put(Tag.class, map); + map = new ParentToCollectionMap(BookmarkResource.class, BookmarksResource.class); + TYPES.put(Bookmark.class, map); + map = new ParentToCollectionMap(TemplateResource.class, TemplatesResource.class); map.add(StorageDomainContentResource.class, StorageDomainContentsResource.class, StorageDomain.class); TYPES.put(Template.class, map); 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 89a4760..039a381 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 @@ -3338,6 +3338,36 @@ </xs:complexContent> </xs:complexType> + <!-- Bookmarks --> + <xs:element name="bookmark" type="Bookmark" /> + + <xs:element name="bookmarks" type="Bookmarks" /> + + <xs:complexType name="Bookmark"> + <xs:complexContent> + <xs:extension base="BaseResource"> + <xs:sequence> + <xs:element name="value" type="xs:string" minOccurs="1" maxOccurs="1"/> + </xs:sequence> + </xs:extension> + </xs:complexContent> + </xs:complexType> + + <xs:complexType name="Bookmarks"> + <xs:complexContent> + <xs:extension base="BaseResources"> + <xs:sequence> + <xs:annotation> + <xs:appinfo> + <jaxb:property name="Bookmarks"/> + </xs:appinfo> + </xs:annotation> + <xs:element ref="bookmark" minOccurs="0" maxOccurs="unbounded"/> + </xs:sequence> + </xs:extension> + </xs:complexContent> + </xs:complexType> + <!-- Tags --> <xs:element name="tag" type="Tag"/> diff --git a/backend/manager/modules/restapi/interface/definition/src/main/resources/jyaml.yml b/backend/manager/modules/restapi/interface/definition/src/main/resources/jyaml.yml index ee17287..e97869c 100644 --- a/backend/manager/modules/restapi/interface/definition/src/main/resources/jyaml.yml +++ b/backend/manager/modules/restapi/interface/definition/src/main/resources/jyaml.yml @@ -73,6 +73,7 @@ tag: org.ovirt.engine.api.model.Tag parent: org.ovirt.engine.api.model.TagParent tags: org.ovirt.engine.api.model.Tags + bookmarks: org.ovirt.engine.api.models.Bookmarks template: org.ovirt.engine.api.model.Template templates: org.ovirt.engine.api.model.Templates ticket: org.ovirt.engine.api.model.Ticket @@ -160,6 +161,8 @@ org.ovirt.engine.api.model.Storage: org.ovirt.engine.api.resteasy.yaml.CustomBeanWrapper org.ovirt.engine.api.model.SupportedVersions: org.ovirt.engine.api.resteasy.yaml.CustomBeanWrapper org.ovirt.engine.api.model.SystemVersion: org.ovirt.engine.api.resteasy.yaml.CustomBeanWrapper + org.ovirt.engine.api.model.Bookmark: org.ovirt.engine.api.resteasy.yaml.CustomBeanWrapper + org.ovirt.engine.api.model.Bookmarks: org.ovirt.engine.api.resteasy.yaml.CustomBeanWrapper org.ovirt.engine.api.model.Tag: org.ovirt.engine.api.resteasy.yaml.CustomBeanWrapper org.ovirt.engine.api.model.TagParent: org.ovirt.engine.api.resteasy.yaml.CustomBeanWrapper org.ovirt.engine.api.model.Tags: org.ovirt.engine.api.resteasy.yaml.CustomBeanWrapper 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 2bb756f..f7edabf 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 @@ -3317,6 +3317,51 @@ Content-Type: {value: application/xml|json, required: true} Expect: {value: 201-created, required: false} Correlation-Id: {value: 'any string', required: false} +- name: /bookmarks|rel=get + description: get the list of bookmarks in the system + request: + body: + parameterType: null + signatures: [] + urlparams: {} + headers: {} +- name: /bookmarks/{bookmark:id}|rel=get + description: get the details of the specified bookmark in the system + request: + body: + parameterType: null + signatures: [] + urlparams: {} + headers: {} +- name: /bookmarks/{tag:id}|rel=delete + description: delete the specified bookmark from the system + request: + body: + parameterType: null + signatures: [] + urlparams: {} + headers: {} +- name: /bookmarks/{tag:id}|rel=update + description: update the specified bookmark in the system + request: + body: + parameterType: Bookmark + signatures: + - mandatoryArguments: {bookmark.name: 'xs:string', bookmark.value: 'xs:string'} + description: update the name, value of the specified bookmark in the system + urlparams: {} + headers: + Content-Type: {value: application/xml|json, required: true} +- name: /bookmarks|rel=add + description: add a new bookmark to the system + request: + body: + parameterType: Bookmark + signatures: + - mandatoryArguments: {bookmark.name: 'xs:string', bookmark.value: 'xs:string'} + urlparams: {} + headers: + Content-Type: {value: application/xml|json, required: true} - name: /tags|rel=get description: get the list of tags in the system request: 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 5b7d9e1..859b968 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 @@ -37,6 +37,7 @@ import org.ovirt.engine.api.restapi.logging.ResponseStatusLogger; import org.ovirt.engine.api.restapi.resource.AbstractBackendResource; import org.ovirt.engine.api.restapi.resource.BackendApiResource; +import org.ovirt.engine.api.restapi.resource.BackendBookmarksResource; import org.ovirt.engine.api.restapi.resource.BackendCapabilitiesResource; import org.ovirt.engine.api.restapi.resource.BackendClustersResource; import org.ovirt.engine.api.restapi.resource.BackendDataCentersResource; @@ -77,16 +78,16 @@ private static final Logger logger = Logger.getLogger(BackendApplication.class); // The messages bundle: - private MessageBundle messageBundle; - private MappingLocator mappingLocator; - private ValidatorLocator validatorLocator; - private SessionHelper sessionHelper; + private final MessageBundle messageBundle; + private final MappingLocator mappingLocator; + private final ValidatorLocator validatorLocator; + private final SessionHelper sessionHelper; // The reference to the backend bean: private BackendLocal backend; // The set of singletons: - private Set<Object> singletons = new HashSet<Object>(); + private final Set<Object> singletons = new HashSet<Object>(); public BackendApplication() throws Exception { // Create and load the message bundle: @@ -134,6 +135,7 @@ addResource(new BackendVmPoolsResource()); addResource(new BackendDisksResource()); addResource(new BackendTagsResource()); + addResource(new BackendBookmarksResource()); addResource(new BackendRolesResource()); addResource(new BackendUsersResource()); addResource(new BackendGroupsResource()); diff --git a/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendBookmarkResource.java b/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendBookmarkResource.java new file mode 100644 index 0000000..5c6b71a --- /dev/null +++ b/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendBookmarkResource.java @@ -0,0 +1,45 @@ +package org.ovirt.engine.api.restapi.resource; + +import org.ovirt.engine.api.model.Bookmark; +import org.ovirt.engine.api.resource.BookmarkResource; +import org.ovirt.engine.core.common.action.BookmarksOperationParameters; +import org.ovirt.engine.core.common.action.VdcActionParametersBase; +import org.ovirt.engine.core.common.action.VdcActionType; +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 BackendBookmarkResource extends AbstractBackendSubResource<Bookmark, + org.ovirt.engine.core.common.businessentities.Bookmark> implements BookmarkResource { + + protected BackendBookmarkResource(String id) { + super(id, Bookmark.class, org.ovirt.engine.core.common.businessentities.Bookmark.class); + } + + @Override + public Bookmark get() { + return performGet(VdcQueryType.GetBookmarkByBookmarkId, new IdQueryParameters(guid)); + } + + @Override + public Bookmark update(Bookmark incoming) { + return performUpdate(incoming, new QueryIdResolver<Guid>(VdcQueryType.GetBookmarkByBookmarkId, + IdQueryParameters.class), VdcActionType.UpdateBookmark, new UpdateParametersProvider()); + } + + protected class UpdateParametersProvider implements ParametersProvider<Bookmark, + org.ovirt.engine.core.common.businessentities.Bookmark> { + + @Override + public VdcActionParametersBase getParameters(Bookmark incoming, + org.ovirt.engine.core.common.businessentities.Bookmark entity) { + return new BookmarksOperationParameters(map(incoming, entity)); + } + } + + @Override + protected Bookmark doPopulate(Bookmark model, org.ovirt.engine.core.common.businessentities.Bookmark entity) { + return model; + } + +} diff --git a/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendBookmarksResource.java b/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendBookmarksResource.java new file mode 100644 index 0000000..f792127 --- /dev/null +++ b/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendBookmarksResource.java @@ -0,0 +1,85 @@ +package org.ovirt.engine.api.restapi.resource; + +import java.util.List; + +import javax.ws.rs.core.Response; + +import org.ovirt.engine.api.model.Bookmark; +import org.ovirt.engine.api.model.Bookmarks; +import org.ovirt.engine.api.resource.BookmarkResource; +import org.ovirt.engine.api.resource.BookmarksResource; +import org.ovirt.engine.core.common.action.BookmarksOperationParameters; +import org.ovirt.engine.core.common.action.BookmarksParametersBase; +import org.ovirt.engine.core.common.action.VdcActionType; +import org.ovirt.engine.core.common.queries.NameQueryParameters; +import org.ovirt.engine.core.common.queries.VdcQueryParametersBase; +import org.ovirt.engine.core.common.queries.VdcQueryType; +import org.ovirt.engine.core.compat.Guid; + +public class BackendBookmarksResource extends + AbstractBackendCollectionResource<Bookmark, org.ovirt.engine.core.common.businessentities.Bookmark> implements + BookmarksResource { + + public BackendBookmarksResource() { + super(Bookmark.class, org.ovirt.engine.core.common.businessentities.Bookmark.class); + } + + @Override + public Bookmarks list() { + return mapCollection(getBackendCollection(VdcQueryType.GetAllBookmarks, new VdcQueryParametersBase())); + } + + @Override + public Response add(Bookmark bookmark) { + validateParameters(bookmark, "name"); + validateParameters(bookmark, "value"); + return performCreate(VdcActionType.AddBookmark, new BookmarksOperationParameters(map(bookmark)), + new BookmarkNameResolver(bookmark.getName())); + } + + @Override + @SingleEntityResource + public BookmarkResource getBookmarkSubResource(String id) { + return inject(new BackendBookmarkResource(id)); + } + + @Override + protected Response performRemove(String id) { + return performAction(VdcActionType.RemoveBookmark, new BookmarksParametersBase(asGuid(id))); + } + + @Override + protected Bookmark doPopulate(Bookmark model, org.ovirt.engine.core.common.businessentities.Bookmark entity) { + return model; + } + + protected Bookmarks mapCollection(List<org.ovirt.engine.core.common.businessentities.Bookmark> entities) { + Bookmarks collection = new Bookmarks(); + for (org.ovirt.engine.core.common.businessentities.Bookmark entity : entities) { + collection.getBookmarks().add(addLinks(map(entity))); + } + return collection; + } + + protected org.ovirt.engine.core.common.businessentities.Bookmark lookupBookmarkByName(final String name) { + return getEntity(org.ovirt.engine.core.common.businessentities.Bookmark.class, + VdcQueryType.GetBookmarkByBookmarkName, new NameQueryParameters(name), name); + } + + protected class BookmarkNameResolver extends EntityIdResolver<Guid> { + + private final String name; + + BookmarkNameResolver(String name) { + this.name = name; + } + + @Override + public org.ovirt.engine.core.common.businessentities.Bookmark lookupEntity(Guid id) throws + BackendFailureException { + assert (id == null); // AddTag returns nothing, lookup name instead + return lookupBookmarkByName(name); + } + } + +} 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 e6dc59a..4e4da03 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 @@ -103,6 +103,7 @@ "storagedomains", "storagedomains/search", "tags", + "bookmarks", "templates", "templates/search", "users", @@ -119,7 +120,7 @@ "jobs", "storageconnections", "vnicprofiles", - "permissions", + "permissions" }; private static final String[] relationshipsGlusterOnly = { @@ -157,6 +158,7 @@ BASE_PATH + "/storagedomains", BASE_PATH + "/storagedomains?search={query}", BASE_PATH + "/tags", + BASE_PATH + "/bookmarks", BASE_PATH + "/templates", BASE_PATH + "/templates?search={query}", BASE_PATH + "/users", diff --git a/backend/manager/modules/restapi/jaxrs/src/test/java/org/ovirt/engine/api/restapi/resource/BackendBookmarkResourceTest.java b/backend/manager/modules/restapi/jaxrs/src/test/java/org/ovirt/engine/api/restapi/resource/BackendBookmarkResourceTest.java new file mode 100644 index 0000000..17097b7 --- /dev/null +++ b/backend/manager/modules/restapi/jaxrs/src/test/java/org/ovirt/engine/api/restapi/resource/BackendBookmarkResourceTest.java @@ -0,0 +1,133 @@ +package org.ovirt.engine.api.restapi.resource; + +import static org.ovirt.engine.api.restapi.resource.BackendBookmarksResourceTest.VALUES; +import static org.ovirt.engine.api.restapi.resource.BackendBookmarksResourceTest.getModel; +import static org.ovirt.engine.api.restapi.resource.BackendBookmarksResourceTest.setUpBookmarks; + +import javax.ws.rs.WebApplicationException; + +import org.junit.Test; +import org.ovirt.engine.api.model.Bookmark; +import org.ovirt.engine.core.common.action.BookmarksOperationParameters; +import org.ovirt.engine.core.common.action.VdcActionType; +import org.ovirt.engine.core.common.queries.IdQueryParameters; +import org.ovirt.engine.core.common.queries.VdcQueryType; + +public class BackendBookmarkResourceTest extends AbstractBackendSubResourceTest<Bookmark, + org.ovirt.engine.core.common.businessentities.Bookmark, BackendBookmarkResource> { + + public BackendBookmarkResourceTest() { + super(new BackendBookmarkResource(GUIDS[0].toString())); + } + + @Test + public void testBadGuid() throws Exception { + control.replay(); + try { + new BackendBookmarkResource("foo"); + fail("expected WebApplicationException"); + } catch (WebApplicationException wae) { + verifyNotFoundException(wae); + } + } + + @Test + public void testGetNotFound() throws Exception { + setUriInfo(setUpBasicUriExpectations()); + //Get will return 404 + setUpGetEntityExpectations(0, true); + control.replay(); + try { + resource.get(); + fail("expected WebApplicationException"); + } catch (WebApplicationException wae) { + verifyNotFoundException(wae); + } + } + + @Test + public void testGet() throws Exception { + setUpGetEntityExpectations(0); + setUriInfo(setUpBasicUriExpectations()); + + control.replay(); + + verifyModel(resource.get(), 0); + } + + @Test + public void testUpdateNotFound() throws Exception { + setUriInfo(setUpBasicUriExpectations()); + //Get will return 404 + setUpGetEntityExpectations(0, true); + control.replay(); + try { + resource.update(getModel(0)); + fail("expected WebApplicationException"); + } catch (WebApplicationException wae) { + verifyNotFoundException(wae); + } + } + + @Test + public void testUpdate() throws Exception { + setUpGetEntityExpectations(0); + setUpGetEntityExpectations(0); + + setUriInfo(setUpActionExpectations(VdcActionType.UpdateBookmark, BookmarksOperationParameters.class, + new String[] { "Bookmark.bookmark_id", "Bookmark.bookmark_name", "Bookmark.bookmark_value" }, + new Object[] { GUIDS[0], NAMES[0], VALUES[0] }, true, true)); + + verifyModel(resource.update(getModel(0)), 0); + } + + @Test + public void testUpdateCantDo() throws Exception { + doTestBadUpdate(false, true, CANT_DO); + } + + @Test + public void testUpdateFailed() throws Exception { + doTestBadUpdate(true, false, FAILURE); + } + + private void doTestBadUpdate(boolean canDo, boolean success, String detail) throws Exception { + setUpGetEntityExpectations(0); + + + setUriInfo(setUpActionExpectations(VdcActionType.UpdateBookmark, BookmarksOperationParameters.class, + new String[] {}, new Object[] {}, canDo, success)); + + try { + resource.update(getModel(0)); + fail("expected WebApplicationException"); + } catch (WebApplicationException wae) { + verifyFault(wae, detail); + } + } + + @Override + protected org.ovirt.engine.core.common.businessentities.Bookmark getEntity(int index) { + return setUpBookmarks().get(index); + } + + @Override + protected void verifyModel(Bookmark model, int index) { + assertEquals(GUIDS[index].toString(), model.getId()); + assertEquals(NAMES[index], model.getName()); + assertEquals(VALUES[index], model.getValue()); + verifyLinks(model); + } + + protected void setUpGetEntityExpectations(int index) throws Exception { + setUpGetEntityExpectations(index, false); + } + + protected void setUpGetEntityExpectations(int index, boolean notFound) throws Exception { + setUpGetEntityExpectations(VdcQueryType.GetBookmarkByBookmarkId, + IdQueryParameters.class, + new String[] { "Id" }, + new Object[] { GUIDS[index] }, + notFound ? null : getEntity(index)); + } +} diff --git a/backend/manager/modules/restapi/jaxrs/src/test/java/org/ovirt/engine/api/restapi/resource/BackendBookmarksResourceTest.java b/backend/manager/modules/restapi/jaxrs/src/test/java/org/ovirt/engine/api/restapi/resource/BackendBookmarksResourceTest.java new file mode 100644 index 0000000..966ae0e --- /dev/null +++ b/backend/manager/modules/restapi/jaxrs/src/test/java/org/ovirt/engine/api/restapi/resource/BackendBookmarksResourceTest.java @@ -0,0 +1,196 @@ +package org.ovirt.engine.api.restapi.resource; + +import java.util.ArrayList; +import java.util.List; + +import javax.ws.rs.WebApplicationException; +import javax.ws.rs.core.Response; + +import org.junit.Before; +import org.junit.Test; +import org.ovirt.engine.api.model.Bookmark; +import org.ovirt.engine.core.common.action.BookmarksOperationParameters; +import org.ovirt.engine.core.common.action.BookmarksParametersBase; +import org.ovirt.engine.core.common.action.VdcActionType; +import org.ovirt.engine.core.common.queries.IdQueryParameters; +import org.ovirt.engine.core.common.queries.NameQueryParameters; +import org.ovirt.engine.core.common.queries.VdcQueryParametersBase; +import org.ovirt.engine.core.common.queries.VdcQueryType; +import org.ovirt.engine.core.compat.Guid; + +public class BackendBookmarksResourceTest extends AbstractBackendCollectionResourceTest<Bookmark, + org.ovirt.engine.core.common.businessentities.Bookmark, BackendBookmarksResource> { + + static final String[] VALUES = {"host.name='blah'", "vms.status='down'", "template.description='something'"}; + + public BackendBookmarksResourceTest() { + super(new BackendBookmarksResource(), null, ""); + } + + @Override + @Before + public void setUp() { + super.setUp(); + } + + @Test + public void testRemove() throws Exception { + setUpGetEntityExpectations(GUIDS[0], getEntity(0)); + setUriInfo(setUpActionExpectations(VdcActionType.RemoveBookmark, + BookmarksParametersBase.class, + new String[] { "BookmarkId" }, + new Object[] { GUIDS[0] }, + true, + true)); + verifyRemove(collection.remove(GUIDS[0].toString())); + } + + @Test + public void testRemoveNonExistant() throws Exception{ + setUpGetEntityExpectations(NON_EXISTANT_GUID, null); + control.replay(); + try { + collection.remove(NON_EXISTANT_GUID.toString()); + fail("expected WebApplicationException"); + } catch (WebApplicationException wae) { + assertNotNull(wae.getResponse()); + assertEquals(404, wae.getResponse().getStatus()); + } + } + + @Test + public void testRemoveCantDo() throws Exception { + doTestBadRemove(false, true, CANT_DO); + } + + @Test + public void testRemoveFailed() throws Exception { + doTestBadRemove(true, false, FAILURE); + } + + @Test + public void testAddBookmark() throws Exception { + setUriInfo(setUpBasicUriExpectations()); + setUpCreationExpectations(VdcActionType.AddBookmark, BookmarksOperationParameters.class, + new String[] { "Bookmark.bookmark_name", "Bookmark.bookmark_value" }, + new Object[] { NAMES[0], VALUES[0] }, true, true, null, VdcQueryType.GetBookmarkByBookmarkName, + NameQueryParameters.class, new String[] { "Name" }, new Object[] { NAMES[0] }, getEntity(0)); + + Response response = collection.add(getModel(0)); + assertEquals(201, response.getStatus()); + assertTrue(response.getEntity() instanceof Bookmark); + verifyModel((Bookmark)response.getEntity(), 0); + } + + @Test + public void testAddIncompleteParameters() throws Exception { + setUriInfo(setUpBasicUriExpectations()); + control.replay(); + try { + collection.add(new Bookmark()); + fail("expected WebApplicationException on incomplete parameters"); + } catch (WebApplicationException wae) { + verifyIncompleteException(wae, "Bookmark", "add", "name"); + } + } + + @Test + public void testAddBookmarkCantDo() throws Exception { + doTestBadAddBookmark(false, true, CANT_DO); + } + + @Test + public void testAddBookmarkFailure() throws Exception { + doTestBadAddBookmark(true, false, FAILURE); + } + + /************************************************************************************* + * Helpers. + *************************************************************************************/ + + private void doTestBadAddBookmark(boolean canDo, boolean success, String detail) throws Exception { + setUriInfo(setUpActionExpectations(VdcActionType.AddBookmark, BookmarksOperationParameters.class, + new String[] { "Bookmark.bookmark_name", "Bookmark.bookmark_value" }, + new Object[] { NAMES[0], VALUES[0] }, canDo, success)); + try { + collection.add(getModel(0)); + fail("expected WebApplicationException"); + } catch (WebApplicationException wae) { + verifyFault(wae, detail); + } + } + + protected void doTestBadRemove(boolean canDo, boolean success, String detail) throws Exception { + setUpGetEntityExpectations(GUIDS[0], getEntity(0)); + setUriInfo(setUpActionExpectations(VdcActionType.RemoveBookmark, BookmarksParametersBase.class, + new String[] { "BookmarkId" }, new Object[] { GUIDS[0] }, canDo, success)); + try { + collection.remove(GUIDS[0].toString()); + fail("expected WebApplicationException"); + } catch (WebApplicationException wae) { + verifyFault(wae, detail); + } + } + + private void setUpGetEntityExpectations(Guid guid, + org.ovirt.engine.core.common.businessentities.Bookmark entity) throws Exception { + setUpGetEntityExpectations(VdcQueryType.GetBookmarkByBookmarkId, + IdQueryParameters.class, new String[] { "Id" }, new Object[] { guid }, entity); + } + + @Override + protected List<Bookmark> getCollection() { + return collection.list().getBookmarks(); + } + + @Override + protected org.ovirt.engine.core.common.businessentities.Bookmark getEntity(int index) { + org.ovirt.engine.core.common.businessentities.Bookmark bookmark = + new org.ovirt.engine.core.common.businessentities.Bookmark(); + bookmark.setbookmark_id(GUIDS[index]); + bookmark.setbookmark_name(NAMES[index]); + bookmark.setbookmark_value(VALUES[index]); + return bookmark; + } + + @Override + protected void setUpQueryExpectations(String query, Object failure) throws Exception { + setUpEntityQueryExpectations(VdcQueryType.GetAllBookmarks, + VdcQueryParametersBase.class, + new String[] { }, + new Object[] { }, + setUpBookmarks(), + failure); + control.replay(); + } + + static List<org.ovirt.engine.core.common.businessentities.Bookmark> setUpBookmarks() { + List<org.ovirt.engine.core.common.businessentities.Bookmark> bookmarks = + new ArrayList<org.ovirt.engine.core.common.businessentities.Bookmark>(); + for (int i = 0; i < NAMES.length; i++) { + org.ovirt.engine.core.common.businessentities.Bookmark bookmark = + new org.ovirt.engine.core.common.businessentities.Bookmark(); + bookmark.setbookmark_id(GUIDS[i]); + bookmark.setbookmark_name(NAMES[i]); + bookmark.setbookmark_value(VALUES[i]); + bookmarks.add(bookmark); + } + return bookmarks; + } + + @Override + protected void verifyModel(Bookmark model, int index) { + assertEquals(GUIDS[index].toString(), model.getId()); + assertEquals(NAMES[index], model.getName()); + assertEquals(VALUES[index], model.getValue()); + verifyLinks(model); + } + + static Bookmark getModel(int index) { + Bookmark model = new Bookmark(); + model.setId(GUIDS[index].toString()); + model.setName(NAMES[index]); + model.setValue(VALUES[index]); + return model; + } +} diff --git a/backend/manager/modules/restapi/types/src/main/java/org/ovirt/engine/api/restapi/types/BookmarkMapper.java b/backend/manager/modules/restapi/types/src/main/java/org/ovirt/engine/api/restapi/types/BookmarkMapper.java new file mode 100644 index 0000000..f97edee --- /dev/null +++ b/backend/manager/modules/restapi/types/src/main/java/org/ovirt/engine/api/restapi/types/BookmarkMapper.java @@ -0,0 +1,44 @@ +package org.ovirt.engine.api.restapi.types; + +import org.ovirt.engine.api.model.Bookmark; +import org.ovirt.engine.api.restapi.utils.GuidUtils; + +public class BookmarkMapper { + /** + * Map the generated REST bookmark model to the business entity bookmark model. + * @param model The REST bookmark model + * @param template The business entity bookmark model template. + * @return A business entity bookmark model filled from the REST model. + */ + @Mapping(from = Bookmark.class, to = org.ovirt.engine.core.common.businessentities.Bookmark.class) + public static org.ovirt.engine.core.common.businessentities.Bookmark map(Bookmark model, + org.ovirt.engine.core.common.businessentities.Bookmark template) { + org.ovirt.engine.core.common.businessentities.Bookmark entity = + template != null ? template : new org.ovirt.engine.core.common.businessentities.Bookmark(); + if (model.isSetId()) { + entity.setbookmark_id(GuidUtils.asGuid(model.getId())); + } + if (model.isSetValue()) { + entity.setbookmark_value(model.getValue()); + } + if (model.isSetName()) { + entity.setbookmark_name(model.getName()); + } + return entity; + } + + /** + * Map a business entity bookmark model to a generated REST bookmark model. + * @param entity The business entity bookmark model. + * @param template The REST bookmark model template to use. + * @return A REST bookmark model filled from the business entity. + */ + @Mapping(from = org.ovirt.engine.core.common.businessentities.Bookmark.class, to = Bookmark.class) + public static Bookmark map(org.ovirt.engine.core.common.businessentities.Bookmark entity, Bookmark template) { + Bookmark model = template != null ? template : new Bookmark(); + model.setId(entity.getbookmark_id().toString()); + model.setName(entity.getbookmark_name()); + model.setValue(entity.getbookmark_value()); + return model; + } +} diff --git a/backend/manager/modules/restapi/types/src/test/java/org/ovirt/engine/api/restapi/types/BookmarkMapperTest.java b/backend/manager/modules/restapi/types/src/test/java/org/ovirt/engine/api/restapi/types/BookmarkMapperTest.java new file mode 100644 index 0000000..ae70159 --- /dev/null +++ b/backend/manager/modules/restapi/types/src/test/java/org/ovirt/engine/api/restapi/types/BookmarkMapperTest.java @@ -0,0 +1,27 @@ +package org.ovirt.engine.api.restapi.types; + +import org.junit.Before; +import org.ovirt.engine.api.model.Bookmark; + +public class BookmarkMapperTest extends AbstractInvertibleMappingTest<Bookmark, + org.ovirt.engine.core.common.businessentities.Bookmark, org.ovirt.engine.core.common.businessentities.Bookmark> { + + public BookmarkMapperTest() { + super(Bookmark.class, org.ovirt.engine.core.common.businessentities.Bookmark.class, + org.ovirt.engine.core.common.businessentities.Bookmark.class); + } + + @Override + @Before + public void setUp() { + super.setUp(); + } + + @Override + protected void verify(Bookmark model, Bookmark transform) { + assertNotNull(transform); + assertEquals(model.getName(), transform.getName()); + assertEquals(model.getId(), transform.getId()); + assertEquals(model.getValue(), transform.getValue()); + } +} -- To view, visit http://gerrit.ovirt.org/26769 To unsubscribe, visit http://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I068194732a45223dae22c18ffee5aaa0f3ec930d Gerrit-PatchSet: 1 Gerrit-Project: ovirt-engine Gerrit-Branch: master Gerrit-Owner: Alexander Wels <aw...@redhat.com> _______________________________________________ Engine-patches mailing list Engine-patches@ovirt.org http://lists.ovirt.org/mailman/listinfo/engine-patches