Search in sources :

Example 1 with PATCH

use of io.dropwizard.jersey.PATCH in project dockstore by dockstore.

the class AbstractHostedEntryResource method editHosted.

@PATCH
@io.swagger.jaxrs.PATCH
@Path("/hostedEntry/{entryId}")
@Timed
@UnitOfWork
@Consumes(MediaType.APPLICATION_JSON)
public T editHosted(@ApiParam(hidden = true) @Parameter(hidden = true, name = "user") @Auth User user, @ApiParam(value = "Entry to modify.", required = true) @Parameter(description = "Entry to modify", name = "entryId", in = ParameterIn.PATH) @PathParam("entryId") Long entryId, @ApiParam(value = "Set of updated sourcefiles, add files by adding new files with unknown paths, delete files by including them with emptied content", required = true) @Parameter(description = "Set of updated sourcefiles, add files by adding new files with unknown paths, delete files by including them with emptied content", name = "sourceFiles", required = true) Set<SourceFile> sourceFiles) {
    T entry = getEntryDAO().findById(entryId);
    checkEntry(entry);
    checkUserCanUpdate(user, entry);
    checkHosted(entry);
    checkVersionLimit(user, entry);
    updateUnsetAbsolutePaths(sourceFiles);
    U version = getVersion(entry);
    Set<SourceFile> versionSourceFiles = handleSourceFileMerger(entryId, sourceFiles, entry, version);
    return saveVersion(user, entryId, entry, version, versionSourceFiles, Optional.empty());
}
Also used : POST(javax.ws.rs.POST) SourceFile(io.dockstore.webservice.core.SourceFile) Path(javax.ws.rs.Path) UnitOfWork(io.dropwizard.hibernate.UnitOfWork) Consumes(javax.ws.rs.Consumes) Timed(com.codahale.metrics.annotation.Timed) PATCH(io.dropwizard.jersey.PATCH)

Example 2 with PATCH

use of io.dropwizard.jersey.PATCH in project zucchini-ui by pgentile.

the class TestRunResource method update.

@PATCH
@Path("{testRunId}")
public void update(@PathParam("testRunId") final String testRunId, @Valid @NotNull final UpdateTestRunRequest request) {
    final TestRun testRun = testRunRepository.getById(testRunId);
    if (!Strings.isNullOrEmpty(request.getType())) {
        testRun.setType(request.getType());
    }
    if (!Strings.isNullOrEmpty(request.getEnvironment())) {
        testRun.setEnvironment(request.getEnvironment());
    }
    if (!Strings.isNullOrEmpty(request.getName())) {
        testRun.setName(request.getName());
    }
    testRun.setLabels(convertRequestLabels(request.getLabels()));
    testRunRepository.save(testRun);
}
Also used : TestRun(io.zucchiniui.backend.testrun.domain.TestRun) PATCH(io.dropwizard.jersey.PATCH)

Example 3 with PATCH

use of io.dropwizard.jersey.PATCH in project velcom by IPDSnelting.

the class RepoEndpoint method patch.

@PATCH
@Path("{repoid}")
@Timed(histogram = true)
public void patch(@Auth Admin admin, @PathParam("repoid") UUID repoUuid, @NotNull PatchRequest request) throws NoSuchRepoException {
    RepoId repoId = new RepoId(repoUuid);
    // Guards whether the repo exists (that's why it's so high up in the function)
    Repo repo = repoAccess.getRepo(repoId);
    repoAccess.updateRepo(repoId, request.getName().orElse(null), request.getRemoteUrl().map(RemoteUrl::new).orElse(null));
    request.getTrackedBranches().ifPresent(trackedBranches -> {
        Set<BranchName> trackedBranchNames = trackedBranches.stream().map(BranchName::fromName).collect(Collectors.toSet());
        repoAccess.setTrackedBranches(repoId, trackedBranchNames);
        try {
            listener.synchronizeCommitsForRepo(repo);
        } catch (SynchronizeCommitsException e) {
            LOGGER.warn("Failed to update repo {} successfully", repoId);
        }
    });
    request.getGithubToken().ifPresent(token -> {
        String stripped = token.strip();
        if (stripped.equals("")) {
            repoAccess.unsetGithubAuthToken(repoId);
        } else {
            repoAccess.setGithubAuthToken(repoId, stripped);
        }
    });
}
Also used : Repo(de.aaaaaaah.velcom.backend.access.repoaccess.entities.Repo) JsonRepo(de.aaaaaaah.velcom.backend.restapi.jsonobjects.JsonRepo) BranchName(de.aaaaaaah.velcom.backend.access.repoaccess.entities.BranchName) RepoId(de.aaaaaaah.velcom.backend.access.repoaccess.entities.RepoId) RemoteUrl(de.aaaaaaah.velcom.backend.access.repoaccess.entities.RemoteUrl) SynchronizeCommitsException(de.aaaaaaah.velcom.backend.listener.SynchronizeCommitsException) Path(javax.ws.rs.Path) Timed(io.micrometer.core.annotation.Timed) PATCH(io.dropwizard.jersey.PATCH)

Example 4 with PATCH

use of io.dropwizard.jersey.PATCH in project ldproxy by interactive-instruments.

the class EndpointStyleMetadataManagerCollection method computeDefinition.

@Override
protected ApiEndpointDefinition computeDefinition(OgcApiDataV2 apiData) {
    Optional<StylesConfiguration> stylesExtension = apiData.getExtension(StylesConfiguration.class);
    ImmutableApiEndpointDefinition.Builder definitionBuilder = new ImmutableApiEndpointDefinition.Builder().apiEntrypoint("collections").sortPriority(ApiEndpointDefinition.SORT_PRIORITY_STYLE_METADATA_MANAGER_COLLECTION);
    String subSubPath = "/styles/{styleId}/metadata";
    String path = "/collections/{collectionId}" + subSubPath;
    List<OgcApiPathParameter> pathParameters = getPathParameters(extensionRegistry, apiData, path);
    Optional<OgcApiPathParameter> optCollectionIdParam = pathParameters.stream().filter(param -> param.getName().equals("collectionId")).findAny();
    if (!optCollectionIdParam.isPresent()) {
        LOGGER.error("Path parameter 'collectionId' missing for resource at path '" + path + "'. The resource will not be available.");
    } else {
        final OgcApiPathParameter collectionIdParam = optCollectionIdParam.get();
        final boolean explode = collectionIdParam.getExplodeInOpenApi(apiData);
        final List<String> collectionIds = (explode) ? collectionIdParam.getValues(apiData) : ImmutableList.of("{collectionId}");
        for (String collectionId : collectionIds) {
            HttpMethods method = HttpMethods.PUT;
            List<OgcApiQueryParameter> queryParameters = getQueryParameters(extensionRegistry, apiData, path, collectionId, method);
            List<ApiHeader> headers = getHeaders(extensionRegistry, apiData, path, collectionId, method);
            String operationSummary = "update the metadata document of a style in the feature collection '" + collectionId + "'";
            String description = "Update the style metadata for the style with the id `styleId`";
            if (stylesExtension.map(StylesConfiguration::isValidationEnabled).orElse(false)) {
                description += " or just validate the style metadata.\n" + "If the header `Prefer` is set to `handling=strict`, the style will be validated before adding " + "the style to the server. If the parameter `dry-run` is set to `true`, the server will " + "not be changed and only any validation errors will be reported";
            }
            description += ".\n" + "This operation updates the complete metadata document.\n";
            // TODO document rules, e.g.wrt links
            Optional<String> operationDescription = Optional.of(description);
            String resourcePath = "/collections/" + collectionId + subSubPath;
            ImmutableOgcApiResourceData.Builder resourceBuilder = new ImmutableOgcApiResourceData.Builder().path(resourcePath).pathParameters(pathParameters);
            ApiOperation operation = addOperation(apiData, method, queryParameters, headers, collectionId, subSubPath, operationSummary, operationDescription, TAGS);
            if (operation != null)
                resourceBuilder.putOperations(method.name(), operation);
            method = HttpMethods.PATCH;
            queryParameters = getQueryParameters(extensionRegistry, apiData, path, collectionId, method);
            headers = getHeaders(extensionRegistry, apiData, path, collectionId, method);
            operationSummary = "update parts of the style metadata document of a style in the feature collection '" + collectionId + "'";
            description = "Update selected elements of the style metadata for the style with the id `styleId`";
            if (stylesExtension.map(StylesConfiguration::isValidationEnabled).orElse(false)) {
                description += " or just validate the style metadata.\n" + "If the header `Prefer` is set to `handling=strict`, the style will be validated before adding " + "the style to the server. If the parameter `dry-run` is set to `true`, the server will " + "not be changed and only any validation errors will be reported";
            }
            description += ".\n" + "The PATCH semantics in this operation are defined by " + "RFC 7396 (JSON Merge Patch). From the specification:\n" + "\n" + "_'A JSON merge patch document describes changes to be " + "made to a target JSON document using a syntax that " + "closely mimics the document being modified. Recipients " + "of a merge patch document determine the exact set of " + "changes being requested by comparing the content of " + "the provided patch against the current content of the " + "target document. If the provided merge patch contains " + "members that do not appear within the target, those " + "members are added. If the target does contain the " + "member, the value is replaced. Null values in the " + "merge patch are given special meaning to indicate " + "the removal of existing values in the target.'_\n" + "\n" + "Some examples:\n" + "\n" + "To add or update the point of contact, the access" + "constraint and the revision date, just send\n" + "\n" + "```\n" + "{\n" + "  \"pointOfContact\": \"Jane Doe\",\n" + "  \"accessConstraints\": \"restricted\",\n" + "  \"dates\": {\n" + "    \"revision\": \"2019-05-17T11:46:12Z\"\n" + "  }\n" + "}\n" + "```\n" + "\n" + "To remove the point of contact, the access " + "constraint and the revision date, send \n" + "\n" + "```\n" + "{\n" + "  \"pointOfContact\": null,\n" + "  \"accessConstraints\": null,\n" + "  \"dates\": {\n" + "    \"revision\": null\n" + "  }\n" + "}\n" + "```\n" + "\n" + "For arrays the complete array needs to be sent. " + "To add a keyword to the example style metadata object, send\n" + "\n" + "```\n" + "{\n" + "  \"keywords\": [ \"basemap\", \"TDS\", \"TDS 6.1\", \"OGC API\", \"new keyword\" ]\n" + "}\n" + "```\n" + "\n" + "To remove the \"TDS\" keyword, send\n" + "\n" + "```\n" + "{\n" + "  \"keywords\": [ \"basemap\", \"TDS 6.1\", \"OGC API\", \"new keyword\" ]\n" + "}\n" + "```\n" + "\n" + "To remove the keywords, send\n" + "\n" + "```\n" + "{\n" + "  \"keywords\": null\n" + "}\n" + "```\n" + "\n" + "The same applies to `stylesheets` and `layers`. To update " + "these members, you have to send the complete new array value.";
            // TODO document rules, e.g.wrt links
            operationDescription = Optional.of(description);
            operation = addOperation(apiData, method, queryParameters, headers, collectionId, subSubPath, operationSummary, operationDescription, TAGS);
            if (operation != null)
                resourceBuilder.putOperations(method.name(), operation);
            definitionBuilder.putResources(resourcePath, resourceBuilder.build());
        }
    }
    return definitionBuilder.build();
}
Also used : PATCH(io.dropwizard.jersey.PATCH) PathParam(javax.ws.rs.PathParam) ApiHeader(de.ii.ogcapi.foundation.domain.ApiHeader) ExtensionConfiguration(de.ii.ogcapi.foundation.domain.ExtensionConfiguration) OgcApiPathParameter(de.ii.ogcapi.foundation.domain.OgcApiPathParameter) User(de.ii.xtraplatform.auth.domain.User) Path(javax.ws.rs.Path) LoggerFactory(org.slf4j.LoggerFactory) Auth(io.dropwizard.auth.Auth) Singleton(javax.inject.Singleton) EndpointSubCollection(de.ii.ogcapi.collections.domain.EndpointSubCollection) AutoBind(com.github.azahnen.dagger.annotations.AutoBind) Inject(javax.inject.Inject) HttpServletRequest(javax.servlet.http.HttpServletRequest) MediaType(javax.ws.rs.core.MediaType) QueryParam(javax.ws.rs.QueryParam) ImmutableList(com.google.common.collect.ImmutableList) Consumes(javax.ws.rs.Consumes) Map(java.util.Map) DefaultValue(javax.ws.rs.DefaultValue) ImmutableOgcApiResourceData(de.ii.ogcapi.collections.domain.ImmutableOgcApiResourceData) ExtensionRegistry(de.ii.ogcapi.foundation.domain.ExtensionRegistry) ApiOperation(de.ii.ogcapi.foundation.domain.ApiOperation) OgcApiQueryParameter(de.ii.ogcapi.foundation.domain.OgcApiQueryParameter) ApiMediaTypeContent(de.ii.ogcapi.foundation.domain.ApiMediaTypeContent) ApiRequestContext(de.ii.ogcapi.foundation.domain.ApiRequestContext) Context(javax.ws.rs.core.Context) Logger(org.slf4j.Logger) OgcApi(de.ii.ogcapi.foundation.domain.OgcApi) HttpMethods(de.ii.ogcapi.foundation.domain.HttpMethods) Collectors(java.util.stream.Collectors) StyleMetadataFormatExtension(de.ii.ogcapi.styles.domain.StyleMetadataFormatExtension) ImmutableApiEndpointDefinition(de.ii.ogcapi.foundation.domain.ImmutableApiEndpointDefinition) Objects(java.util.Objects) ApiEndpointDefinition(de.ii.ogcapi.foundation.domain.ApiEndpointDefinition) List(java.util.List) Response(javax.ws.rs.core.Response) OgcApiDataV2(de.ii.ogcapi.foundation.domain.OgcApiDataV2) StylesConfiguration(de.ii.ogcapi.styles.domain.StylesConfiguration) Optional(java.util.Optional) ImmutableQueryInputStyleMetadata(de.ii.ogcapi.styles.manager.domain.ImmutableQueryInputStyleMetadata) PUT(javax.ws.rs.PUT) FormatExtension(de.ii.ogcapi.foundation.domain.FormatExtension) QueriesHandlerStylesManager(de.ii.ogcapi.styles.manager.domain.QueriesHandlerStylesManager) StylesConfiguration(de.ii.ogcapi.styles.domain.StylesConfiguration) ImmutableApiEndpointDefinition(de.ii.ogcapi.foundation.domain.ImmutableApiEndpointDefinition) HttpMethods(de.ii.ogcapi.foundation.domain.HttpMethods) OgcApiPathParameter(de.ii.ogcapi.foundation.domain.OgcApiPathParameter) ApiHeader(de.ii.ogcapi.foundation.domain.ApiHeader) OgcApiQueryParameter(de.ii.ogcapi.foundation.domain.OgcApiQueryParameter) ImmutableOgcApiResourceData(de.ii.ogcapi.collections.domain.ImmutableOgcApiResourceData) ApiOperation(de.ii.ogcapi.foundation.domain.ApiOperation)

Example 5 with PATCH

use of io.dropwizard.jersey.PATCH in project zucchini-ui by pgentile.

the class CommentResource method updateComment.

@PATCH
@Path("{commentId}")
public void updateComment(@PathParam("commentId") final String commentId, @Valid @NotNull final UpdateCommentRequest request) {
    final Comment comment = loadCommentById(commentId);
    comment.setContent(request.getContent());
    commentRepository.save(comment);
}
Also used : Comment(io.zucchiniui.backend.comment.domain.Comment) Path(javax.ws.rs.Path) PATCH(io.dropwizard.jersey.PATCH)

Aggregations

PATCH (io.dropwizard.jersey.PATCH)7 Path (javax.ws.rs.Path)6 Consumes (javax.ws.rs.Consumes)4 OgcApiDataV2 (de.ii.ogcapi.foundation.domain.OgcApiDataV2)3 QueriesHandlerStylesManager (de.ii.ogcapi.styles.manager.domain.QueriesHandlerStylesManager)3 ImmutableQueryInputStyleMetadata (de.ii.ogcapi.styles.manager.domain.ImmutableQueryInputStyleMetadata)2 Timed (com.codahale.metrics.annotation.Timed)1 AutoBind (com.github.azahnen.dagger.annotations.AutoBind)1 ImmutableList (com.google.common.collect.ImmutableList)1 BranchName (de.aaaaaaah.velcom.backend.access.repoaccess.entities.BranchName)1 RemoteUrl (de.aaaaaaah.velcom.backend.access.repoaccess.entities.RemoteUrl)1 Repo (de.aaaaaaah.velcom.backend.access.repoaccess.entities.Repo)1 RepoId (de.aaaaaaah.velcom.backend.access.repoaccess.entities.RepoId)1 SynchronizeCommitsException (de.aaaaaaah.velcom.backend.listener.SynchronizeCommitsException)1 JsonRepo (de.aaaaaaah.velcom.backend.restapi.jsonobjects.JsonRepo)1 EndpointSubCollection (de.ii.ogcapi.collections.domain.EndpointSubCollection)1 ImmutableOgcApiResourceData (de.ii.ogcapi.collections.domain.ImmutableOgcApiResourceData)1 ApiEndpointDefinition (de.ii.ogcapi.foundation.domain.ApiEndpointDefinition)1 ApiHeader (de.ii.ogcapi.foundation.domain.ApiHeader)1 ApiMediaTypeContent (de.ii.ogcapi.foundation.domain.ApiMediaTypeContent)1