Search in sources :

Example 16 with PathParam

use of javax.ws.rs.PathParam in project syndesis by syndesisio.

the class IntegrationHandler method putDeployment.

@PUT
@Produces(MediaType.APPLICATION_JSON)
@Path("/{id}/deployments")
public IntegrationDeployment putDeployment(@Context SecurityContext sec, @NotNull @PathParam("id") @ApiParam(required = true) String id) {
    Integration integration = getIntegration(id);
    int nextDeploymentVersion = 1;
    // Update previous deployments targetState=Undeployed and make sure nextDeploymentVersion is larger than all previous ones.
    Set<String> deploymentIds = getDataManager().fetchIdsByPropertyValue(IntegrationDeployment.class, "integrationId", id);
    if (deploymentIds != null && !deploymentIds.isEmpty()) {
        Stream<IntegrationDeployment> deployments = deploymentIds.stream().map(i -> getDataManager().fetch(IntegrationDeployment.class, i)).filter(r -> r != null);
        for (IntegrationDeployment d : deployments.toArray(IntegrationDeployment[]::new)) {
            nextDeploymentVersion = Math.max(nextDeploymentVersion, d.getVersion() + 1);
            getDataManager().update(d.withTargetState(IntegrationDeploymentState.Unpublished));
        }
    }
    IntegrationDeployment deployment = new IntegrationDeployment.Builder().id(IntegrationDeployment.compositeId(id, nextDeploymentVersion)).spec(integration).version(nextDeploymentVersion).userId(sec.getUserPrincipal().getName()).build();
    deployment = getDataManager().create(deployment);
    return deployment;
}
Also used : Produces(javax.ws.rs.Produces) Path(javax.ws.rs.Path) SecurityContext(javax.ws.rs.core.SecurityContext) ApiParam(io.swagger.annotations.ApiParam) SortOptionsFromQueryParams(io.syndesis.server.endpoint.v1.operations.SortOptionsFromQueryParams) PaginationFilter(io.syndesis.server.endpoint.util.PaginationFilter) MediaType(javax.ws.rs.core.MediaType) EncryptionComponent(io.syndesis.server.dao.manager.EncryptionComponent) Connection(io.syndesis.common.model.connection.Connection) IdPrefixFilter(io.syndesis.server.dao.manager.operators.IdPrefixFilter) IntegrationOverview(io.syndesis.common.model.integration.IntegrationOverview) Integration(io.syndesis.common.model.integration.Integration) AllValidations(io.syndesis.common.model.validation.AllValidations) Context(javax.ws.rs.core.Context) Set(java.util.Set) Validator(javax.validation.Validator) Connector(io.syndesis.common.model.connection.Connector) ListResult(io.syndesis.common.model.ListResult) Extension(io.syndesis.common.model.extension.Extension) NotNull(javax.validation.constraints.NotNull) Collectors(java.util.stream.Collectors) Updater(io.syndesis.server.endpoint.v1.operations.Updater) List(java.util.List) Stream(java.util.stream.Stream) PaginationOptionsFromQueryParams(io.syndesis.server.endpoint.v1.operations.PaginationOptionsFromQueryParams) DataManagerSupport(io.syndesis.server.endpoint.v1.util.DataManagerSupport) Optional(java.util.Optional) UriInfo(javax.ws.rs.core.UriInfo) IntegrationDeploymentState(io.syndesis.common.model.integration.IntegrationDeploymentState) ReflectiveSorter(io.syndesis.server.endpoint.util.ReflectiveSorter) ReverseFilter(io.syndesis.server.dao.manager.operators.ReverseFilter) Op(io.syndesis.common.model.filter.Op) PathParam(javax.ws.rs.PathParam) Creator(io.syndesis.server.endpoint.v1.operations.Creator) Action(io.syndesis.common.model.action.Action) GET(javax.ws.rs.GET) Step(io.syndesis.common.model.integration.Step) Kind(io.syndesis.common.model.Kind) IntegrationBulletinBoard(io.syndesis.common.model.bulletin.IntegrationBulletinBoard) Validating(io.syndesis.server.endpoint.v1.operations.Validating) ConvertGroup(javax.validation.groups.ConvertGroup) EntityNotFoundException(javax.persistence.EntityNotFoundException) FilterOptions(io.syndesis.common.model.filter.FilterOptions) DataManager(io.syndesis.server.dao.manager.DataManager) Api(io.swagger.annotations.Api) SuppressFBWarnings(io.syndesis.common.util.SuppressFBWarnings) IntegrationDeployment(io.syndesis.common.model.integration.IntegrationDeployment) Default(javax.validation.groups.Default) POST(javax.ws.rs.POST) IntegrationDeploymentOverview(io.syndesis.common.model.integration.IntegrationDeploymentOverview) Deleter(io.syndesis.server.endpoint.v1.operations.Deleter) DataShape(io.syndesis.common.model.DataShape) Getter(io.syndesis.server.endpoint.v1.operations.Getter) Lister(io.syndesis.server.endpoint.v1.operations.Lister) Component(org.springframework.stereotype.Component) Inspectors(io.syndesis.server.inspector.Inspectors) OpenShiftService(io.syndesis.server.openshift.OpenShiftService) PUT(javax.ws.rs.PUT) BaseHandler(io.syndesis.server.endpoint.v1.handler.BaseHandler) Integration(io.syndesis.common.model.integration.Integration) IntegrationDeployment(io.syndesis.common.model.integration.IntegrationDeployment) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) PUT(javax.ws.rs.PUT)

Example 17 with PathParam

use of javax.ws.rs.PathParam in project syndesis by syndesisio.

the class JsonDBResource method get.

@Produces({ APPLICATION_JSON, APPLICATION_JAVASCRIPT })
@Path("/{path: .*}.json")
@GET
public Response get(@PathParam("path") String path, @QueryParam("print") String print, @QueryParam("shallow") Boolean shallow, @QueryParam("callback") String callback) {
    GetOptions options = new GetOptions();
    if ("pretty".equals(print)) {
        options.prettyPrint(true);
    } else if ("silent".equals(print)) {
        if (jsondb.exists(path)) {
            return Response.noContent().build();
        }
        return Response.status(Response.Status.NOT_FOUND).build();
    }
    if (shallow != null) {
        options.depth(1);
    }
    String contentType = APPLICATION_JSON;
    if (callback != null) {
        contentType = APPLICATION_JAVASCRIPT;
        options.callback(callback);
    }
    Consumer<OutputStream> stream = jsondb.getAsStreamingOutput(path, options);
    if (stream == null) {
        return Response.status(Response.Status.NOT_FOUND).build();
    }
    StreamingOutput streamingOutput = x -> stream.accept(x);
    return Response.ok(streamingOutput).header(CONTENT_TYPE, contentType).build();
}
Also used : OutputStream(java.io.OutputStream) CONTENT_TYPE(javax.ws.rs.core.HttpHeaders.CONTENT_TYPE) PathParam(javax.ws.rs.PathParam) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) Path(javax.ws.rs.Path) HashMap(java.util.HashMap) StreamingOutput(javax.ws.rs.core.StreamingOutput) JsonDB(io.syndesis.server.jsondb.JsonDB) Consumer(java.util.function.Consumer) GetOptions(io.syndesis.server.jsondb.GetOptions) QueryParam(javax.ws.rs.QueryParam) Consumes(javax.ws.rs.Consumes) Response(javax.ws.rs.core.Response) Map(java.util.Map) PUT(javax.ws.rs.PUT) APPLICATION_JSON(javax.ws.rs.core.MediaType.APPLICATION_JSON) InputStream(java.io.InputStream) DELETE(javax.ws.rs.DELETE) OutputStream(java.io.OutputStream) StreamingOutput(javax.ws.rs.core.StreamingOutput) GetOptions(io.syndesis.server.jsondb.GetOptions) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 18 with PathParam

use of javax.ws.rs.PathParam in project timbuctoo by HuygensING.

the class TabularUpload method upload.

@Consumes(MediaType.MULTIPART_FORM_DATA)
@Produces(MediaType.APPLICATION_JSON)
@POST
public Response upload(@FormDataParam("file") final InputStream rdfInputStream, @FormDataParam("file") final FormDataBodyPart body, @FormDataParam("file") final FormDataContentDisposition fileInfo, @FormDataParam("fileMimeTypeOverride") final MediaType mimeTypeOverride, FormDataMultiPart formData, @HeaderParam("authorization") final String authHeader, @PathParam("userId") final String ownerId, @PathParam("dataSetId") final String dataSetId, @QueryParam("forceCreation") boolean forceCreation) throws DataStoreCreationException, FileStorageFailedException, ExecutionException, InterruptedException, LogStorageFailedException {
    final Either<Response, Response> result = authCheck.getOrCreate(authHeader, ownerId, dataSetId, forceCreation).flatMap(userAndDs -> authCheck.hasAdminAccess(userAndDs.getLeft(), userAndDs.getRight())).map(userAndDs -> {
        final MediaType mediaType = mimeTypeOverride == null ? body.getMediaType() : mimeTypeOverride;
        Optional<Loader> loader = LoaderFactory.createFor(mediaType.toString(), formData.getFields().entrySet().stream().filter(entry -> entry.getValue().size() > 0).filter(entry -> entry.getValue().get(0) != null).filter(entry -> MediaTypes.typeEqual(MediaType.TEXT_PLAIN_TYPE, entry.getValue().get(0).getMediaType())).collect(Collectors.toMap(Map.Entry::getKey, entry -> entry.getValue().get(0).getValue())));
        if (!loader.isPresent()) {
            return errorResponseHelper.error(400, "We do not support the mediatype '" + mediaType + "'. Make sure to add the correct mediatype to the file " + "parameter. In curl you'd use `-F \"file=@<filename>;type=<mediatype>\"`. In a webbrowser you probably " + "have no way of setting the correct mimetype. So you can use a special parameter to override it: " + "`formData.append(\"fileMimeTypeOverride\", \"<mimetype>\");`");
        }
        final DataSet dataSet = userAndDs.getRight();
        ImportManager importManager = dataSet.getImportManager();
        if (StringUtils.isBlank(fileInfo.getName())) {
            return Response.status(400).entity("filename cannot be empty.").build();
        }
        try {
            String fileToken = importManager.addFile(rdfInputStream, fileInfo.getFileName(), mediaType);
            Future<ImportStatus> promise = importManager.generateLog(dataSet.getMetadata().getBaseUri(), dataSet.getMetadata().getBaseUri(), new TabularRdfCreator(loader.get(), fileToken, fileInfo.getFileName()));
            return handleImportManagerResult(promise);
        } catch (FileStorageFailedException | LogStorageFailedException e) {
            LOG.error("Tabular upload failed", e);
            return Response.serverError().build();
        }
    });
    if (result.isLeft()) {
        return result.getLeft();
    } else {
        return result.get();
    }
}
Also used : PathParam(javax.ws.rs.PathParam) ImportStatus(nl.knaw.huygens.timbuctoo.v5.dataset.ImportStatus) FormDataContentDisposition(org.glassfish.jersey.media.multipart.FormDataContentDisposition) Produces(javax.ws.rs.Produces) DataSetRepository(nl.knaw.huygens.timbuctoo.v5.dataset.DataSetRepository) LoggerFactory(org.slf4j.LoggerFactory) Path(javax.ws.rs.Path) FormDataMultiPart(org.glassfish.jersey.media.multipart.FormDataMultiPart) StringUtils(org.apache.commons.lang3.StringUtils) MediaType(javax.ws.rs.core.MediaType) Future(java.util.concurrent.Future) QueryParam(javax.ws.rs.QueryParam) Consumes(javax.ws.rs.Consumes) Map(java.util.Map) FormDataBodyPart(org.glassfish.jersey.media.multipart.FormDataBodyPart) HeaderParam(javax.ws.rs.HeaderParam) Loader(nl.knaw.huygens.timbuctoo.bulkupload.loaders.Loader) LogStorageFailedException(nl.knaw.huygens.timbuctoo.v5.filestorage.exceptions.LogStorageFailedException) AuthCheck(nl.knaw.huygens.timbuctoo.v5.dropwizard.endpoints.auth.AuthCheck) Either(javaslang.control.Either) Logger(org.slf4j.Logger) POST(javax.ws.rs.POST) ImportManager(nl.knaw.huygens.timbuctoo.v5.dataset.ImportManager) DataStoreCreationException(nl.knaw.huygens.timbuctoo.v5.dataset.exceptions.DataStoreCreationException) LoaderFactory(nl.knaw.huygens.timbuctoo.bulkupload.loaders.LoaderFactory) Collectors(java.util.stream.Collectors) ErrorResponseHelper.handleImportManagerResult(nl.knaw.huygens.timbuctoo.v5.dropwizard.endpoints.ErrorResponseHelper.handleImportManagerResult) ExecutionException(java.util.concurrent.ExecutionException) MediaTypes(org.glassfish.jersey.message.internal.MediaTypes) FormDataParam(org.glassfish.jersey.media.multipart.FormDataParam) Response(javax.ws.rs.core.Response) FileStorageFailedException(nl.knaw.huygens.timbuctoo.v5.filestorage.exceptions.FileStorageFailedException) TabularRdfCreator(nl.knaw.huygens.timbuctoo.v5.bulkupload.TabularRdfCreator) Optional(java.util.Optional) DataSet(nl.knaw.huygens.timbuctoo.v5.dataset.dto.DataSet) InputStream(java.io.InputStream) ImportManager(nl.knaw.huygens.timbuctoo.v5.dataset.ImportManager) DataSet(nl.knaw.huygens.timbuctoo.v5.dataset.dto.DataSet) LogStorageFailedException(nl.knaw.huygens.timbuctoo.v5.filestorage.exceptions.LogStorageFailedException) Loader(nl.knaw.huygens.timbuctoo.bulkupload.loaders.Loader) FileStorageFailedException(nl.knaw.huygens.timbuctoo.v5.filestorage.exceptions.FileStorageFailedException) Response(javax.ws.rs.core.Response) ImportStatus(nl.knaw.huygens.timbuctoo.v5.dataset.ImportStatus) MediaType(javax.ws.rs.core.MediaType) TabularRdfCreator(nl.knaw.huygens.timbuctoo.v5.bulkupload.TabularRdfCreator) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) POST(javax.ws.rs.POST)

Example 19 with PathParam

use of javax.ws.rs.PathParam in project onebusaway-application-modules by camsys.

the class RESTEndpointsDocumenter method discoverParameters.

/**
 * Get the parameters for the specified endpoint from the provided java method.
 */
@SuppressWarnings("rawtypes")
private void discoverParameters(Method method, Endpoint endpoint) {
    Annotation[][] annotations = method.getParameterAnnotations();
    Class[] parameterTypes = method.getParameterTypes();
    for (int i = 0; i < parameterTypes.length; i++) {
        Class parameter = parameterTypes[i];
        // ignore parameters used to access context
        if ((parameter == Request.class) || (parameter == javax.servlet.http.HttpServletResponse.class) || (parameter == javax.servlet.http.HttpServletRequest.class)) {
            continue;
        }
        EndpointParameter nextParameter = new EndpointParameter();
        nextParameter.javaType = parameter.getName();
        Annotation[] parameterAnnotations = annotations[i];
        for (Annotation annotation : parameterAnnotations) {
            if (annotation instanceof PathParam) {
                nextParameter.parameterType = ParameterType.PATH;
                PathParam pathparam = (PathParam) annotation;
                nextParameter.name = pathparam.value();
            } else if (annotation instanceof QueryParam) {
                nextParameter.parameterType = ParameterType.QUERY;
                QueryParam queryparam = (QueryParam) annotation;
                nextParameter.name = queryparam.value();
            } else if (annotation instanceof DefaultValue) {
                DefaultValue defaultvalue = (DefaultValue) annotation;
                nextParameter.defaultValue = defaultvalue.value();
            }
        }
        switch(nextParameter.parameterType) {
            case PATH:
                endpoint.pathParameters.add(nextParameter);
                break;
            case QUERY:
                endpoint.queryParameters.add(nextParameter);
                break;
            case PAYLOAD:
                endpoint.payloadParameters.add(nextParameter);
                break;
        }
    }
}
Also used : Request(javax.ws.rs.core.Request) Annotation(java.lang.annotation.Annotation) DefaultValue(javax.ws.rs.DefaultValue) QueryParam(javax.ws.rs.QueryParam) PathParam(javax.ws.rs.PathParam)

Example 20 with PathParam

use of javax.ws.rs.PathParam in project ovirt-engine by oVirt.

the class V3CapabilitiesServer method get.

@GET
@Path("/{id}")
public V3VersionCaps get(@PathParam("id") String id) {
    V3Capabilities capabilities = list();
    Optional<V3VersionCaps> caps = capabilities.getVersions().stream().filter(x -> x.getId().equals(id)).findFirst();
    if (caps.isPresent()) {
        return caps.get();
    }
    throw new WebApplicationException(Response.Status.NOT_FOUND);
}
Also used : V3VersionCaps(org.ovirt.engine.api.v3.types.V3VersionCaps) DOMSource(javax.xml.transform.dom.DOMSource) PathParam(javax.ws.rs.PathParam) XPathExpressionException(javax.xml.xpath.XPathExpressionException) Produces(javax.ws.rs.Produces) XPath(javax.xml.xpath.XPath) GET(javax.ws.rs.GET) VersionSource(org.ovirt.engine.api.restapi.invocation.VersionSource) XPathConstants(javax.xml.xpath.XPathConstants) Path(javax.ws.rs.Path) CurrentManager(org.ovirt.engine.api.restapi.invocation.CurrentManager) Document(org.w3c.dom.Document) Node(org.w3c.dom.Node) JAXB(javax.xml.bind.JAXB) V3Capabilities(org.ovirt.engine.api.v3.types.V3Capabilities) V3VersionCaps(org.ovirt.engine.api.v3.types.V3VersionCaps) NodeList(org.w3c.dom.NodeList) Current(org.ovirt.engine.api.restapi.invocation.Current) XPathFactory(javax.xml.xpath.XPathFactory) Element(org.w3c.dom.Element) Response(javax.ws.rs.core.Response) DocumentBuilder(javax.xml.parsers.DocumentBuilder) Optional(java.util.Optional) WebApplicationException(javax.ws.rs.WebApplicationException) DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) InputStream(java.io.InputStream) WebApplicationException(javax.ws.rs.WebApplicationException) V3Capabilities(org.ovirt.engine.api.v3.types.V3Capabilities) XPath(javax.xml.xpath.XPath) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET)

Aggregations

PathParam (javax.ws.rs.PathParam)127 Path (javax.ws.rs.Path)105 GET (javax.ws.rs.GET)96 Produces (javax.ws.rs.Produces)96 Response (javax.ws.rs.core.Response)93 QueryParam (javax.ws.rs.QueryParam)82 List (java.util.List)72 MediaType (javax.ws.rs.core.MediaType)72 POST (javax.ws.rs.POST)71 DELETE (javax.ws.rs.DELETE)70 Consumes (javax.ws.rs.Consumes)66 Inject (javax.inject.Inject)62 Api (io.swagger.annotations.Api)60 ApiOperation (io.swagger.annotations.ApiOperation)59 Map (java.util.Map)59 ApiResponse (io.swagger.annotations.ApiResponse)58 ApiResponses (io.swagger.annotations.ApiResponses)57 Collectors (java.util.stream.Collectors)57 Logger (org.slf4j.Logger)52 LoggerFactory (org.slf4j.LoggerFactory)52