Skip to content

Commit

Permalink
API Consumer partially updates a Gluu attribute #41
Browse files Browse the repository at this point in the history
  • Loading branch information
syntrydy committed Sep 4, 2020
1 parent 7bd7e7c commit ff32982
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,27 +6,30 @@
import java.util.ArrayList;
import java.util.List;

import javax.enterprise.context.ApplicationScoped;
import javax.enterprise.context.RequestScoped;
import javax.inject.Inject;
import javax.validation.Valid;
import javax.validation.constraints.NotNull;
import javax.ws.rs.Consumes;
import javax.ws.rs.DELETE;
import javax.ws.rs.DefaultValue;
import javax.ws.rs.GET;
import javax.ws.rs.PATCH;
import javax.ws.rs.POST;
import javax.ws.rs.PUT;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.WebApplicationException;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;

import org.gluu.model.GluuAttribute;
import org.gluu.configapi.filters.ProtectedApi;
import org.gluu.configapi.util.ApiConstants;
import org.gluu.configapi.util.AttributeNames;
import org.gluu.configapi.util.Jackson;
import org.gluu.model.GluuAttribute;
import org.gluu.oxtrust.service.AttributeService;
import org.slf4j.Logger;

Expand All @@ -38,7 +41,7 @@
@Path(ApiConstants.BASE_API_URL + ApiConstants.ATTRIBUTES)
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@ApplicationScoped
@RequestScoped
public class AttributesResource extends BaseResource {

/**
Expand Down Expand Up @@ -117,6 +120,23 @@ public Response updateAttribute(@Valid GluuAttribute attribute) {
return Response.ok(result).build();
}

@PATCH
@Consumes(MediaType.APPLICATION_JSON_PATCH_JSON)
@ProtectedApi(scopes = { WRITE_ACCESS })
@Path(ApiConstants.INUM_PATH)
public Response patchAtribute(@PathParam(ApiConstants.INUM) @NotNull String inum, @NotNull String pathString) {
GluuAttribute existingAttribute = attributeService.getAttributeByInum(inum);
checkResourceNotNull(existingAttribute, GLUU_ATTRIBUTE);
try {
existingAttribute = Jackson.applyPatch(pathString, existingAttribute);
attributeService.updateAttribute(existingAttribute);
return Response.ok(existingAttribute).build();
} catch (Exception e) {
logger.error("", e);
throw new WebApplicationException(e.getMessage());
}
}

@DELETE
@Path(ApiConstants.INUM_PATH)
@ProtectedApi(scopes = { WRITE_ACCESS })
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,6 @@ public Response patchScope(@PathParam(ApiConstants.INUM) @NotNull String inum, @
logger.error("",e);
throw new WebApplicationException(e.getMessage());
}

}

@DELETE
Expand Down

0 comments on commit ff32982

Please sign in to comment.