GroupRest { @PUT @Path("{groupTitle}") @RolesAllowed("admin") @ApiOperation("Update a Mobi Group's information") @Consumes(MediaType.APPLICATION_JSON) public Response updateGroup(@PathParam("groupTitle") String groupTitle, String newGroupStr) { if (StringUtils.isEmpty(groupTitle)) { throw ErrorUtils.sendError("Group title must be provided", Response.Status.BAD_REQUEST); } Model groupModel = jsonldToModel(newGroupStr, transformer); Set<Resource> subjects = groupModel.filter(null, vf.createIRI(RDF.TYPE.stringValue()), vf.createIRI(Group.TYPE)).subjects(); if (subjects.size() < 1) { throw ErrorUtils.sendError("Group must have an ID", Response.Status.BAD_REQUEST); } Group newGroup = groupFactory.createNew(subjects.iterator().next(), groupModel); Value title = newGroup.getProperty(vf.createIRI(DCTERMS.TITLE.stringValue())).orElseThrow(() -> ErrorUtils.sendError("Group title must be present in new group", Response.Status.BAD_REQUEST)); if (!groupTitle.equals(title.stringValue())) { throw ErrorUtils.sendError("Provided group title and the group title in the data must match", Response.Status.BAD_REQUEST); } try { Group savedGroup = engineManager.retrieveGroup(rdfEngine.getEngineName(), groupTitle).orElseThrow(() -> ErrorUtils.sendError("Group " + groupTitle + " not found", Response.Status.BAD_REQUEST)); Optional<Value> savedGroupTitle = savedGroup.getProperty(vf.createIRI(DCTERMS.TITLE.stringValue())); if (!savedGroupTitle.isPresent()) { throw ErrorUtils.sendError("Group must have a title", Response.Status.INTERNAL_SERVER_ERROR); } if (!savedGroupTitle.get().equals(title)) { throw ErrorUtils.sendError("Group titles must match", Response.Status.BAD_REQUEST); } if (!savedGroup.getHasGroupRole().isEmpty()) { newGroup.setHasGroupRole(savedGroup.getHasGroupRole()); } if (!savedGroup.getMember().isEmpty()) { newGroup.setMember(savedGroup.getMember()); } engineManager.updateGroup(rdfEngine.getEngineName(), newGroup); return Response.ok().build(); } catch (IllegalArgumentException ex) { throw ErrorUtils.sendError(ex.getMessage(), Response.Status.BAD_REQUEST); } }  @GET @RolesAllowed("user") @Produces(MediaType.APPLICATION_JSON) @ApiOperation("Get all Mobi Groups") Response getGroups(); @POST @RolesAllowed("admin") @ApiOperation("Create a new Mobi Group") @Produces(MediaType.TEXT_PLAIN) @Consumes(MediaType.MULTIPART_FORM_DATA) Response createGroup(@FormDataParam("title") String title,
                         @FormDataParam("description") String description,
                         @FormDataParam("roles") List<FormDataBodyPart> roles,
                         @FormDataParam("members") List<FormDataBodyPart> members); @GET @Path("{groupTitle}") @RolesAllowed("user") @Produces(MediaType.APPLICATION_JSON) @ApiOperation("Get a single Mobi Group") Response getGroup(@PathParam("groupTitle") String groupTitle); @PUT @Path("{groupTitle}") @RolesAllowed("admin") @ApiOperation("Update a Mobi Group's information") @Consumes(MediaType.APPLICATION_JSON) Response updateGroup(@PathParam("groupTitle") String groupTitle, String newGroupStr); @DELETE @Path("{groupTitle}") @RolesAllowed("admin") @ApiOperation("Remove a Mobi Group") Response deleteGroup(@PathParam("groupTitle") String groupTitle); @GET @Path("{groupTitle}/roles") @RolesAllowed("user") @Produces(MediaType.APPLICATION_JSON) @ApiOperation("List roles of a Mobi Group") Response getGroupRoles(@PathParam("groupTitle") String groupTitle); @PUT @Path("{groupTitle}/roles") @RolesAllowed("admin") @ApiOperation("Add roles to a Mobi Group") Response addGroupRoles(@PathParam("groupTitle") String groupTitle, @QueryParam("roles") List<String> roles); @DELETE @Path("{groupTitle}/roles") @RolesAllowed("admin") @ApiOperation("Remove role from a Mobi Group") Response removeGroupRole(@PathParam("groupTitle") String groupTitle, @QueryParam("role") String role); @GET @Path("{groupTitle}/users") @RolesAllowed("user") @Produces(MediaType.APPLICATION_JSON) @ApiOperation("List users of a Mobi Group") Response getGroupUsers(@PathParam("groupTitle") String groupTitle); @PUT @Path("{groupTitle}/users") @RolesAllowed("admin") @ApiOperation("Add a Mobi User to a Group") Response addGroupUser(@PathParam("groupTitle") String groupTitle, 
                                 @QueryParam("users") List<String> usernames); @DELETE @Path("{groupTitle}/users") @RolesAllowed("admin") @ApiOperation("Remove a Mobi User from a Group") Response removeGroupUser(@PathParam("groupTitle") String groupTitle, @QueryParam("user") String username);  }
@Test public void updateGroupTest() { Response response = target().path("groups/testGroup") .request() .put(Entity.entity(groupedModelToString(group.getModel(), getRDFFormat("jsonld"), transformer), MediaType.APPLICATION_JSON_TYPE)); assertEquals(response.getStatus(), 200); verify(engineManager).retrieveGroup(ENGINE_NAME, "testGroup"); verify(engineManager).updateGroup(eq(ENGINE_NAME), any(Group.class)); }