use of io.hops.hopsworks.common.api.ResourceRequest in project hopsworks by logicalclocks.
the class UsersResource method findById.
@GET
@Path("{userId}")
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation(value = "Find User by Id.", response = UserProfileDTO.class)
public Response findById(@PathParam("userId") Integer userId, @Context UriInfo uriInfo, @Context SecurityContext sc) throws UserException {
Users user = jWTHelper.getUserPrincipal(sc);
BbcGroup adminGroup = bbcGroupFacade.findByGroupName("HOPS_ADMIN");
if (!Objects.equals(user.getUid(), userId) && !user.getBbcGroupCollection().contains(adminGroup)) {
throw new UserException(RESTCodes.UserErrorCode.ACCESS_CONTROL, Level.SEVERE);
}
ResourceRequest resourceRequest = new ResourceRequest(ResourceRequest.Name.USERS);
UserProfileDTO userDTO = usersBuilder.build(uriInfo, resourceRequest, userId);
return Response.ok().entity(userDTO).build();
}
use of io.hops.hopsworks.common.api.ResourceRequest in project hopsworks by logicalclocks.
the class TestCommitBuilder method testBuildPopulatedOffsetAndLimit.
@Test
public void testBuildPopulatedOffsetAndLimit() throws Exception {
// arrange
ResourceRequest resourceRequest = new ResourceRequest(ResourceRequest.Name.COMMITS);
resourceRequest.setOffset(0);
resourceRequest.setLimit(0);
resourceRequest.setSort(new HashSet<SortBy>());
resourceRequest.setFilter(new HashSet<FilterBy>());
// act
CommitDTO commitDTO = commitBuilder.build(mockUriInfo, resourceRequest, project, featuregroup);
// assert
verify(featureGroupCommitController).getCommitDetails(featuregroup.getId(), 0, 0, resourceRequest.getSort(), resourceRequest.getFilter());
Assert.assertEquals(0, commitDTO.getCount().intValue());
}
use of io.hops.hopsworks.common.api.ResourceRequest in project hopsworks by logicalclocks.
the class UsersResource method findAll.
@GET
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation(value = "Get all users.", response = UserDTO.class)
public Response findAll(@BeanParam Pagination pagination, @BeanParam UsersBeanParam usersBeanParam, @Context UriInfo uriInfo, @Context SecurityContext sc) throws UserException {
if (!settings.isUserSearchEnabled()) {
throw new UserException(RESTCodes.UserErrorCode.USER_SEARCH_NOT_ALLOWED, Level.FINE);
}
ResourceRequest resourceRequest = new ResourceRequest(ResourceRequest.Name.USERS);
resourceRequest.setOffset(pagination.getOffset());
resourceRequest.setLimit(pagination.getLimit());
resourceRequest.setSort(usersBeanParam.getSortBySet());
resourceRequest.setFilter(usersBeanParam.getFilter());
UserDTO userDTO = usersBuilder.buildItems(uriInfo, resourceRequest);
return Response.ok().entity(userDTO).build();
}
use of io.hops.hopsworks.common.api.ResourceRequest in project hopsworks by logicalclocks.
the class GitResource method fileCheckout.
@ApiOperation(value = "Execute git checkout --filename. The final execution message will " + "contain the list of files in the status. If some of the files in the argument are present in the final " + "execution message then they failed to be checkout out", response = GitOpExecutionDTO.class)
@POST
@Path("/repository/{repositoryId}/file")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@AllowedProjectRoles({ AllowedProjectRoles.DATA_OWNER, AllowedProjectRoles.DATA_SCIENTIST })
@JWTRequired(acceptedTokens = { Audience.API }, allowedUserRoles = { "HOPS_ADMIN", "HOPS_USER" })
@ApiKeyRequired(acceptedScopes = { ApiScope.GIT }, allowedUserRoles = { "HOPS_ADMIN", "HOPS_USER" })
public Response fileCheckout(@Context UriInfo uriInfo, @PathParam("repositoryId") Integer repositoryId, @Context SecurityContext sc, GitFileCheckout files, @BeanParam ExecutionBeanParam executionBeanParam) throws GitOpException, HopsSecurityException {
Users hopsworksUser = jWTHelper.getUserPrincipal(sc);
GitOpExecution execution = gitController.fileCheckout(project, hopsworksUser, repositoryId, files.getFiles());
ResourceRequest resourceRequest = new ResourceRequest(ResourceRequest.Name.EXECUTION);
resourceRequest.setExpansions(executionBeanParam.getExpansions().getResources());
GitOpExecutionDTO dto = executionBuilder.build(uriInfo, resourceRequest, execution);
return Response.ok().entity(dto).build();
}
use of io.hops.hopsworks.common.api.ResourceRequest in project hopsworks by logicalclocks.
the class GitResource method gitRepository.
@ApiOperation(value = "Get a repository with a particular Id", response = GitRepositoryDTO.class)
@GET
@Path("/repository/{repositoryId}")
@Produces(MediaType.APPLICATION_JSON)
@AllowedProjectRoles({ AllowedProjectRoles.DATA_OWNER, AllowedProjectRoles.DATA_SCIENTIST })
@JWTRequired(acceptedTokens = { Audience.API }, allowedUserRoles = { "HOPS_ADMIN", "HOPS_USER" })
@ApiKeyRequired(acceptedScopes = { ApiScope.GIT }, allowedUserRoles = { "HOPS_ADMIN", "HOPS_USER" })
public Response gitRepository(@PathParam("repositoryId") Integer repositoryId, @Context SecurityContext sc, @Context UriInfo uriInfo, @BeanParam RepositoryBeanParam repositoryBeanParam) throws GitOpException {
ResourceRequest resourceRequest = new ResourceRequest(ResourceRequest.Name.REPOSITORY);
resourceRequest.setExpansions(repositoryBeanParam.getExpansions().getResources());
GitRepository gitRepository = commandConfigurationValidator.verifyRepository(project, repositoryId);
GitRepositoryDTO dto = gitRepositoryBuilder.build(uriInfo, resourceRequest, project, gitRepository);
return Response.ok().entity(dto).build();
}
Aggregations