Search in sources :

Example 1 with RequestBody

use of org.eclipse.microprofile.openapi.annotations.parameters.RequestBody in project solr-document-store by DBCDK.

the class ResourceBean method addResource.

@POST
@Consumes({ MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_JSON })
@Path("add")
@Operation(operationId = "add-resource", summary = "Adds a resource to an item", description = "This operation sets the resource and connect" + " it to a number of manifestations item, if possible.")
@APIResponses({ @APIResponse(name = "Success", responseCode = "200", description = "Resource has been added", ref = StatusResponse.NAME) })
@RequestBody(ref = BibliographicResourceSchemaAnnotated.NAME)
public Response addResource(String jsonContent) throws JSONBException {
    try (LogWith logWith = track(UUID.randomUUID().toString())) {
        AddResourceRequest request = jsonbContext.unmarshall(jsonContent, AddResourceRequest.class);
        // Add resource
        BibliographicResourceEntity resource = request.asBibliographicResource();
        log.debug("POST resource: {}", resource);
        return storeResource(resource);
    }
}
Also used : LogWith(dk.dbc.log.LogWith) BibliographicResourceEntity(dk.dbc.search.solrdocstore.jpa.BibliographicResourceEntity) AddResourceRequest(dk.dbc.search.solrdocstore.request.AddResourceRequest) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) APIResponses(org.eclipse.microprofile.openapi.annotations.responses.APIResponses) Operation(org.eclipse.microprofile.openapi.annotations.Operation) RequestBody(org.eclipse.microprofile.openapi.annotations.parameters.RequestBody)

Example 2 with RequestBody

use of org.eclipse.microprofile.openapi.annotations.parameters.RequestBody in project policies-ui-backend by RedHatInsights.

the class PolicyCrudService method validateName.

@Operation(summary = "Validates the Policy.name and verifies if it is unique.")
@POST
@Path("/validate-name")
@RequestBody(content = { @Content(schema = @Schema(type = SchemaType.STRING)) })
@APIResponses({ @APIResponse(responseCode = "200", description = "Name validated", content = @Content(schema = @Schema(implementation = Msg.class))), @APIResponse(responseCode = "400", description = "Policy validation failed", content = @Content(schema = @Schema(implementation = Msg.class))), @APIResponse(responseCode = "403", description = "Individual permissions missing to complete action", content = @Content(schema = @Schema(implementation = Msg.class))), @APIResponse(responseCode = "409", description = "Name not unique"), @APIResponse(responseCode = "500", description = "Internal error") })
@Parameter(name = "id", description = "UUID of the policy")
public Response validateName(@NotNull JsonString policyName, @QueryParam("id") UUID id) {
    if (!user.canReadPolicies()) {
        return Response.status(Response.Status.FORBIDDEN).entity(new Msg(MISSING_PERMISSIONS_TO_VERIFY_POLICY)).build();
    }
    Policy policy = new Policy();
    policy.id = id;
    policy.name = policyName.getString();
    Set<ConstraintViolation<Policy>> result = validator.validateProperty(policy, "name");
    if (result.size() > 0) {
        String error = String.join(";", result.stream().map(ConstraintViolation::getMessage).collect(Collectors.toSet()));
        return Response.status(400).entity(new Msg(error)).build();
    }
    Response isNameValid = isNameUnique(policy);
    if (isNameValid != null) {
        return isNameValid;
    }
    return Response.status(200).entity(new Msg("Policy.name validated")).build();
}
Also used : Msg(com.redhat.cloud.policies.app.model.Msg) Policy(com.redhat.cloud.policies.app.model.Policy) APIResponse(org.eclipse.microprofile.openapi.annotations.responses.APIResponse) ConstraintViolation(javax.validation.ConstraintViolation) JsonString(javax.json.JsonString) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) APIResponses(org.eclipse.microprofile.openapi.annotations.responses.APIResponses) Parameter(org.eclipse.microprofile.openapi.annotations.parameters.Parameter) Operation(org.eclipse.microprofile.openapi.annotations.Operation) RequestBody(org.eclipse.microprofile.openapi.annotations.parameters.RequestBody)

Example 3 with RequestBody

use of org.eclipse.microprofile.openapi.annotations.parameters.RequestBody in project solr-document-store by DBCDK.

the class ResourceBean method putResource.

@PUT
@Consumes({ MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_JSON })
@Path("{fieldName}/{agencyId}:{bibliographicRecordId}")
@Operation(operationId = "add/update-resource", summary = "Adds/updates/removes a resource to/from an item", description = "This operation sets/removes the resource and connected" + " manifestations item, are queued.")
@APIResponses({ @APIResponse(name = "Success", responseCode = "200", description = "Resource has been added", ref = StatusResponse.NAME) })
@RequestBody(ref = BibliographicResourceSchemaAnnotated.NAME)
public Response putResource(String jsonContent, @PathParam("fieldName") String fieldName, @PathParam("agencyId") Integer agencyId, @PathParam("bibliographicRecordId") String bibliographicRecordId, @QueryParam("trackingId") String trackingId) throws JSONBException {
    if (trackingId == null || trackingId.isEmpty())
        trackingId = UUID.randomUUID().toString();
    try (LogWith logWith = track(trackingId)) {
        ResourceRestRequest request = jsonbContext.unmarshall(jsonContent, ResourceRestRequest.class);
        BibliographicResourceEntity resource = new BibliographicResourceEntity(agencyId, bibliographicRecordId, fieldName, request.getHas());
        log.debug("PUT resource: {}", resource);
        return storeResource(resource);
    }
}
Also used : LogWith(dk.dbc.log.LogWith) ResourceRestRequest(dk.dbc.search.solrdocstore.request.ResourceRestRequest) BibliographicResourceEntity(dk.dbc.search.solrdocstore.jpa.BibliographicResourceEntity) Path(javax.ws.rs.Path) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) APIResponses(org.eclipse.microprofile.openapi.annotations.responses.APIResponses) Operation(org.eclipse.microprofile.openapi.annotations.Operation) PUT(javax.ws.rs.PUT) RequestBody(org.eclipse.microprofile.openapi.annotations.parameters.RequestBody)

Example 4 with RequestBody

use of org.eclipse.microprofile.openapi.annotations.parameters.RequestBody in project solr-document-store by DBCDK.

the class ResourceBean method deleteResource.

@DELETE
@Consumes({ MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_JSON })
@Path("{fieldName}/{agencyId}:{bibliographicRecordId}")
@Operation(operationId = "delete-resource", summary = "Removes a resource to an item", description = "This operation removed the resource and queues old connected" + " manifestations item, if any.")
@APIResponses({ @APIResponse(name = "Success", responseCode = "200", description = "Resource has been added", ref = StatusResponse.NAME) })
@RequestBody(ref = BibliographicResourceSchemaAnnotated.NAME)
public Response deleteResource(@PathParam("fieldName") String fieldName, @PathParam("agencyId") Integer agencyId, @PathParam("bibliographicRecordId") String bibliographicRecordId, @QueryParam("trackingId") String trackingId) throws JSONBException {
    if (trackingId == null || trackingId.isEmpty())
        trackingId = UUID.randomUUID().toString();
    try (LogWith logWith = track(trackingId)) {
        BibliographicResourceEntity resource = new BibliographicResourceEntity(agencyId, bibliographicRecordId, fieldName, false);
        log.debug("DELETE resource: {}", resource);
        return storeResource(resource);
    }
}
Also used : LogWith(dk.dbc.log.LogWith) BibliographicResourceEntity(dk.dbc.search.solrdocstore.jpa.BibliographicResourceEntity) Path(javax.ws.rs.Path) DELETE(javax.ws.rs.DELETE) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) APIResponses(org.eclipse.microprofile.openapi.annotations.responses.APIResponses) Operation(org.eclipse.microprofile.openapi.annotations.Operation) RequestBody(org.eclipse.microprofile.openapi.annotations.parameters.RequestBody)

Aggregations

Path (javax.ws.rs.Path)4 Operation (org.eclipse.microprofile.openapi.annotations.Operation)4 RequestBody (org.eclipse.microprofile.openapi.annotations.parameters.RequestBody)4 APIResponses (org.eclipse.microprofile.openapi.annotations.responses.APIResponses)4 LogWith (dk.dbc.log.LogWith)3 BibliographicResourceEntity (dk.dbc.search.solrdocstore.jpa.BibliographicResourceEntity)3 Consumes (javax.ws.rs.Consumes)3 Produces (javax.ws.rs.Produces)3 POST (javax.ws.rs.POST)2 Msg (com.redhat.cloud.policies.app.model.Msg)1 Policy (com.redhat.cloud.policies.app.model.Policy)1 AddResourceRequest (dk.dbc.search.solrdocstore.request.AddResourceRequest)1 ResourceRestRequest (dk.dbc.search.solrdocstore.request.ResourceRestRequest)1 JsonString (javax.json.JsonString)1 ConstraintViolation (javax.validation.ConstraintViolation)1 DELETE (javax.ws.rs.DELETE)1 PUT (javax.ws.rs.PUT)1 Parameter (org.eclipse.microprofile.openapi.annotations.parameters.Parameter)1 APIResponse (org.eclipse.microprofile.openapi.annotations.responses.APIResponse)1