@GET @Path("/") @Produces(MediaType.APPLICATION_JSON) public RESTResponse<Collection<DashboardEntity>> listAllDashboards() { return RESTResponse.async(() -> dashboardEntityService.findAll()).get(); }
@GET @Path("/{uuidOrName}") @Produces(MediaType.APPLICATION_JSON) public RESTResponse<DashboardEntity> getDashboardByUUIDOrName(@PathParam("uuidOrName") String uuidOrName) { return RESTResponse.async(() -> dashboardEntityService.getByUUIDOrName(uuidOrName, uuidOrName)).get(); }
default DashboardEntity createOrUpdate(DashboardEntity dashboardEntity, User user) throws EntityNotFoundException { Preconditions.checkNotNull(dashboardEntity, "DashboardEntity should not be null"); if (dashboardEntity.getUuid() == null) { Preconditions.checkArgument(dashboardEntity.getAuthor() == null, "author is immutable"); dashboardEntity.setAuthor(user.getName()); return create(dashboardEntity); } else { return update(dashboardEntity, user); } } }
@DELETE @Path("/{uuid}") @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) @RolesAllowed({User.Role.USER, User.Role.ADMINISTRATOR}) public RESTResponse<DashboardEntity> deleteDashboard(String uuid, @Auth User user) { return RESTResponse.async(() -> dashboardEntityService.deleteByUUID(uuid, user)).get(); } }
@POST @Path("/") @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) @RolesAllowed({User.Role.USER, User.Role.ADMINISTRATOR}) public RESTResponse<DashboardEntity> createOrUpdateDashboard(DashboardEntity dashboardEntity, @Auth User user) { return RESTResponse.async(() -> dashboardEntityService.createOrUpdate(dashboardEntity, user)).get(); }