Search in sources :

Example 1 with UriInfo

use of javax.ws.rs.core.UriInfo in project che by eclipse.

the class FactoryService method getFactoryByAttribute.

@GET
@Path("/find")
@Produces(APPLICATION_JSON)
@ApiOperation(value = "Get factory by attribute, " + "the attribute must match one of the Factory model fields with type 'String', " + "e.g. (factory.name, factory.creator.name)", notes = "If specify more than one value for a single query parameter then will be taken the first one")
@ApiResponses({ @ApiResponse(code = 200, message = "Response contains list requested factories"), @ApiResponse(code = 400, message = "When query does not contain at least one attribute to search for"), @ApiResponse(code = 500, message = "Internal server error") })
public List<FactoryDto> getFactoryByAttribute(@DefaultValue("0") @QueryParam("skipCount") Integer skipCount, @DefaultValue("30") @QueryParam("maxItems") Integer maxItems, @Context UriInfo uriInfo) throws BadRequestException, ServerException {
    final Set<String> skip = ImmutableSet.of("token", "skipCount", "maxItems");
    final List<Pair<String, String>> query = URLEncodedUtils.parse(uriInfo.getRequestUri()).entrySet().stream().filter(param -> !skip.contains(param.getKey()) && !param.getValue().isEmpty()).map(entry -> Pair.of(entry.getKey(), entry.getValue().iterator().next())).collect(toList());
    checkArgument(!query.isEmpty(), "Query must contain at least one attribute");
    final List<FactoryDto> factories = new ArrayList<>();
    for (Factory factory : factoryManager.getByAttribute(maxItems, skipCount, query)) {
        factories.add(injectLinks(asDto(factory), null));
    }
    return factories;
}
Also used : URLEncodedUtils(org.eclipse.che.commons.lang.URLEncodedUtils) Produces(javax.ws.rs.Produces) LoggerFactory(org.slf4j.LoggerFactory) Path(javax.ws.rs.Path) ApiParam(io.swagger.annotations.ApiParam) FactoryBuilder(org.eclipse.che.api.factory.server.builder.FactoryBuilder) FactoryDto(org.eclipse.che.api.factory.shared.dto.FactoryDto) ApiOperation(io.swagger.annotations.ApiOperation) QueryParam(javax.ws.rs.QueryParam) Service(org.eclipse.che.api.core.rest.Service) PreferenceManager(org.eclipse.che.api.user.server.PreferenceManager) Consumes(javax.ws.rs.Consumes) Map(java.util.Map) DefaultValue(javax.ws.rs.DefaultValue) APPLICATION_JSON(javax.ws.rs.core.MediaType.APPLICATION_JSON) NameGenerator(org.eclipse.che.commons.lang.NameGenerator) DELETE(javax.ws.rs.DELETE) WorkspaceManager(org.eclipse.che.api.workspace.server.WorkspaceManager) ImmutableSet(com.google.common.collect.ImmutableSet) Context(javax.ws.rs.core.Context) Predicate(java.util.function.Predicate) Set(java.util.Set) Pair(org.eclipse.che.commons.lang.Pair) AuthorDto(org.eclipse.che.api.factory.shared.dto.AuthorDto) List(java.util.List) BadRequestException(org.eclipse.che.api.core.BadRequestException) Response(javax.ws.rs.core.Response) ProjectConfig(org.eclipse.che.api.core.model.project.ProjectConfig) UriInfo(javax.ws.rs.core.UriInfo) WorkspaceImpl(org.eclipse.che.api.workspace.server.model.impl.WorkspaceImpl) TEXT_PLAIN(javax.ws.rs.core.MediaType.TEXT_PLAIN) FactoryLinksHelper.createLinks(org.eclipse.che.api.factory.server.FactoryLinksHelper.createLinks) PathParam(javax.ws.rs.PathParam) ByteArrayOutputStream(java.io.ByteArrayOutputStream) GET(javax.ws.rs.GET) Strings.isNullOrEmpty(com.google.common.base.Strings.isNullOrEmpty) ApiResponses(io.swagger.annotations.ApiResponses) ArrayList(java.util.ArrayList) Inject(javax.inject.Inject) HashSet(java.util.HashSet) EnvironmentContext(org.eclipse.che.commons.env.EnvironmentContext) ApiException(org.eclipse.che.api.core.ApiException) User(org.eclipse.che.api.core.model.user.User) ConflictException(org.eclipse.che.api.core.ConflictException) MULTIPART_FORM_DATA(javax.ws.rs.core.MediaType.MULTIPART_FORM_DATA) Api(io.swagger.annotations.Api) DtoFactory(org.eclipse.che.dto.server.DtoFactory) CONTENT_DISPOSITION(javax.ws.rs.core.HttpHeaders.CONTENT_DISPOSITION) Logger(org.slf4j.Logger) POST(javax.ws.rs.POST) Iterator(java.util.Iterator) JsonSyntaxException(com.google.gson.JsonSyntaxException) FileItem(org.apache.commons.fileupload.FileItem) IOException(java.io.IOException) NotFoundException(org.eclipse.che.api.core.NotFoundException) Factory(org.eclipse.che.api.core.model.factory.Factory) Collectors.toList(java.util.stream.Collectors.toList) Boolean.parseBoolean(java.lang.Boolean.parseBoolean) ServerException(org.eclipse.che.api.core.ServerException) ApiResponse(io.swagger.annotations.ApiResponse) ForbiddenException(org.eclipse.che.api.core.ForbiddenException) ProjectConfigImpl(org.eclipse.che.api.workspace.server.model.impl.ProjectConfigImpl) PUT(javax.ws.rs.PUT) UserManager(org.eclipse.che.api.user.server.UserManager) Collections(java.util.Collections) InputStream(java.io.InputStream) FactoryDto(org.eclipse.che.api.factory.shared.dto.FactoryDto) ArrayList(java.util.ArrayList) LoggerFactory(org.slf4j.LoggerFactory) DtoFactory(org.eclipse.che.dto.server.DtoFactory) Factory(org.eclipse.che.api.core.model.factory.Factory) Pair(org.eclipse.che.commons.lang.Pair) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Example 2 with UriInfo

use of javax.ws.rs.core.UriInfo in project jersey by jersey.

the class UriRoutingContextTest method testGetQueryParametersEmptyValues.

/**
     * Migrated Jersey 1.x {@code com.sun.jersey.impl.QueryParametersHttpRequestTest}.
     */
@Test
public void testGetQueryParametersEmptyValues() throws Exception {
    final UriInfo ui = createContext("/widgets/10?one&two&three", "GET");
    MultivaluedMap<String, String> p = ui.getQueryParameters();
    assertEquals(p.getFirst("one"), "");
    assertEquals(p.getFirst("two"), "");
    assertEquals(p.getFirst("three"), "");
}
Also used : UriInfo(javax.ws.rs.core.UriInfo) Test(org.junit.Test)

Example 3 with UriInfo

use of javax.ws.rs.core.UriInfo in project jersey by jersey.

the class UriRoutingContextTest method testGetQueryParametersEncoded.

/**
     * Migrated Jersey 1.x {@code com.sun.jersey.impl.QueryParametersHttpRequestTest}.
     */
@Test
public void testGetQueryParametersEncoded() throws Exception {
    final UriInfo ui = createContext("/widgets/10?x+=+1%20&%20y+=+2", "GET");
    MultivaluedMap<String, String> p = ui.getQueryParameters(false);
    assertEquals("+1%20", p.getFirst("x "));
    assertEquals("+2", p.getFirst(" y "));
}
Also used : UriInfo(javax.ws.rs.core.UriInfo) Test(org.junit.Test)

Example 4 with UriInfo

use of javax.ws.rs.core.UriInfo in project jersey by jersey.

the class UriRoutingContextTest method testGetPathSegmentsMultipleSlash.

/**
     * Migrated Jersey 1.x {@code com.sun.jersey.impl.PathSegmentsHttpRequestTest}.
     */
@Test
public void testGetPathSegmentsMultipleSlash() {
    final UriInfo ui = createContext("/p//p//p//", "GET");
    List<PathSegment> segments = ui.getPathSegments();
    assertEquals(7, segments.size());
    final Iterator<PathSegment> psi = segments.iterator();
    PathSegment segment;
    segment = psi.next();
    assertEquals("p", segment.getPath());
    assertEquals(0, segment.getMatrixParameters().size());
    segment = psi.next();
    assertEquals("", segment.getPath());
    assertEquals(0, segment.getMatrixParameters().size());
    segment = psi.next();
    assertEquals("p", segment.getPath());
    assertEquals(0, segment.getMatrixParameters().size());
    segment = psi.next();
    assertEquals("", segment.getPath());
    assertEquals(0, segment.getMatrixParameters().size());
    segment = psi.next();
    assertEquals("p", segment.getPath());
    assertEquals(0, segment.getMatrixParameters().size());
    segment = psi.next();
    assertEquals("", segment.getPath());
    assertEquals(0, segment.getMatrixParameters().size());
    segment = psi.next();
    assertEquals("", segment.getPath());
    assertEquals(0, segment.getMatrixParameters().size());
}
Also used : PathSegment(javax.ws.rs.core.PathSegment) UriInfo(javax.ws.rs.core.UriInfo) Test(org.junit.Test)

Example 5 with UriInfo

use of javax.ws.rs.core.UriInfo in project jersey by jersey.

the class UriRoutingContextTest method testGetPathSegmentsMultipleSlashmulitpleMatrix.

/**
     * Migrated Jersey 1.x {@code com.sun.jersey.impl.PathSegmentsHttpRequestTest}.
     */
@Test
public void testGetPathSegmentsMultipleSlashmulitpleMatrix() {
    final UriInfo ui = createContext("/;x=1;y=1/;x=2;y=2/;x=3;y=3", "GET");
    List<PathSegment> segments = ui.getPathSegments();
    assertEquals(3, segments.size());
    final Iterator<PathSegment> psi = segments.iterator();
    PathSegment segment;
    segment = psi.next();
    MultivaluedMap<String, String> m = segment.getMatrixParameters();
    assertEquals("1", m.getFirst("x"));
    assertEquals("1", m.getFirst("y"));
    segment = psi.next();
    m = segment.getMatrixParameters();
    assertEquals("2", m.getFirst("x"));
    assertEquals("2", m.getFirst("y"));
    segment = psi.next();
    m = segment.getMatrixParameters();
    assertEquals("3", m.getFirst("x"));
    assertEquals("3", m.getFirst("y"));
}
Also used : PathSegment(javax.ws.rs.core.PathSegment) UriInfo(javax.ws.rs.core.UriInfo) Test(org.junit.Test)

Aggregations

UriInfo (javax.ws.rs.core.UriInfo)336 Test (org.junit.Test)200 Response (javax.ws.rs.core.Response)70 URI (java.net.URI)50 WebApplicationException (javax.ws.rs.WebApplicationException)49 Test (org.testng.annotations.Test)25 ContainerRequestContext (javax.ws.rs.container.ContainerRequestContext)24 ArrayList (java.util.ArrayList)20 Map (java.util.Map)20 MediaType (javax.ws.rs.core.MediaType)20 AbstractBackendCollectionResourceTest (org.ovirt.engine.api.restapi.resource.AbstractBackendCollectionResourceTest)20 HttpServletRequest (javax.servlet.http.HttpServletRequest)18 Test (org.junit.jupiter.api.Test)18 InputStream (java.io.InputStream)17 PathSegment (javax.ws.rs.core.PathSegment)17 Context (javax.ws.rs.core.Context)16 HashMap (java.util.HashMap)15 GET (javax.ws.rs.GET)14 Path (javax.ws.rs.Path)14 UriBuilder (javax.ws.rs.core.UriBuilder)14