Java源码示例:com.atlassian.bitbucket.util.PageRequest
示例1
private void calculateTotalRepositories() {
try {
securityService.withPermission(Permission.ADMIN, "Read all repositories").call(new Operation<Object, Throwable>() {
@Override
public Object perform() {
int repositories = 0;
PageRequest nextPage = new PageRequestImpl(0, 10000);
do {
Page<Repository> repositoryPage = repositoryService.findAll(nextPage);
repositories += repositoryPage.getSize();
nextPage = repositoryPage.getNextPageRequest();
} while (nextPage != null);
totalRepositories.set(repositories);
return null;
}
});
} catch (Throwable th) {
log.error("Cannot read all repositories", th);
}
}
示例2
private void calculateTotalPullRequests() {
try {
securityService.withPermission(Permission.ADMIN, "Read all pull requests").call(new Operation<Object, Throwable>() {
@Override
public Object perform() {
int pullRequests = 0;
PageRequest nextPage = new PageRequestImpl(0, 10000);
do {
Page<PullRequest> pullRequestPage = pullRequestService.search(new PullRequestSearchRequest.Builder().state(OPEN).build(), nextPage);
pullRequests += pullRequestPage.getSize();
nextPage = pullRequestPage.getNextPageRequest();
} while (nextPage != null);
totalPullRequests.set(pullRequests);
return null;
}
});
} catch (Throwable th) {
log.error("Cannot read all pull requests", th);
}
}
示例3
PullRequest findPRByCommitId(String commitId) {
PullRequestSearchRequest request = new PullRequestSearchRequest.Builder()
.state(PullRequestState.OPEN)
.withProperties(false)
.build();
PageRequest nextPage = new PageRequestImpl(0, SEARCH_PAGE_SIZE);
do {
Page<PullRequest> page = prService.search(request, nextPage);
PullRequest pr = searchForPR(page, commitId);
if(pr != null) {
return pr;
} else {
nextPage = page.getNextPageRequest();
}
} while(nextPage != null);
return null;
}
示例4
@Before
@SuppressWarnings("unchecked")
public void setup() throws Exception {
MockitoAnnotations.initMocks(this);
ApplicationUser userA = mockApplicationUser("userA");
ApplicationUser userB = mockApplicationUser("userB");
ApplicationUser user1 = mockApplicationUser("user1");
ApplicationUser user2 = mockApplicationUser("user2");
ApplicationUser user3 = mockApplicationUser("user3");
ApplicationUser user4 = mockApplicationUser("user4");
List<ApplicationUser> userList1 = newArrayList(user1, user2);
List<ApplicationUser> userList2 = newArrayList(user3, user4);
Page p1 = mock(Page.class);
Page p2 = mock(Page.class);
Page empty = mock(Page.class);
when(p1.getValues()).thenReturn(userList1);
when(p2.getValues()).thenReturn(userList2);
when(empty.getValues()).thenReturn(emptyList());
when(userService.findUsersByGroup(any(String.class), any(PageRequest.class))).then((Answer<Page>) invocation -> {
String group = (String) invocation.getArguments()[0];
PageRequest pageRequest = (PageRequest) invocation.getArguments()[1];
if("group1".equals(group) && pageRequest.getStart() == 0) {
return p1;
} else if("group2".equals(group) && pageRequest.getStart() == 0) {
return p2;
} else {
return empty;
}
});
when(userService.getUserBySlug("userA")).thenReturn(userA);
when(userService.getUserBySlug("userB")).thenReturn(userB);
when(userService.getUserBySlug("user1")).thenReturn(user1);
when(userService.getUserBySlug("user2")).thenReturn(user2);
when(userService.getUserBySlug("user3")).thenReturn(user3);
when(userService.getUserBySlug("user4")).thenReturn(user4);
}