private EndpointProfilesBodyDto createNextBodyPage(List<EndpointProfileBodyDto> profilesBodyDto, String endpointGroupId, String limit) { EndpointProfilesBodyDto endpointProfilesBodyDto = new EndpointProfilesBodyDto(); PageLinkDto pageLinkDto = new PageLinkDto(); String next; int lim = Integer.valueOf(limit); if (profilesBodyDto.size() == (lim + 1)) { pageLinkDto.setEndpointGroupId(endpointGroupId); pageLinkDto.setLimit(limit); pageLinkDto.setOffset( Base64.encodeBase64URLSafeString(profilesBodyDto.get(lim).getEndpointKeyHash())); profilesBodyDto.remove(lim); next = null; } else { next = DaoConstants.LAST_PAGE_MESSAGE; } pageLinkDto.setNext(next); endpointProfilesBodyDto.setPageLinkDto(pageLinkDto); endpointProfilesBodyDto.setEndpointProfilesBody(profilesBodyDto); return endpointProfilesBodyDto; }
@Override public EndpointProfilesPageDto findByEndpointGroupId(PageLinkDto pageLink) { LOG.debug("Find endpoint profiles by endpoint group id [{}] ", pageLink.getEndpointGroupId()); EndpointProfilesPageDto endpointProfilesPageDto = new EndpointProfilesPageDto(); int lim = Integer.valueOf(pageLink.getLimit()); int offs = Integer.valueOf(pageLink.getOffset()); List<MongoEndpointProfile> mongoEndpointProfileList = find( query(new Criteria() .orOperator(where(EP_GROUP_STATE + "." + ENDPOINT_GROUP_ID) .is(pageLink.getEndpointGroupId()), where(EP_GROUP_STATE + "." + ENDPOINT_GROUP_ID) .is(pageLink.getEndpointGroupId()))) .skip(offs) .limit(lim + 1)); if (mongoEndpointProfileList.size() == (lim + 1)) { String offset = Integer.toString(lim + offs); pageLink.setOffset(offset); mongoEndpointProfileList.remove(lim); } else { pageLink.setNext(DaoConstants.LAST_PAGE_MESSAGE); } endpointProfilesPageDto.setPageLinkDto(pageLink); endpointProfilesPageDto.setEndpointProfiles(convertDtoList(mongoEndpointProfileList)); return endpointProfilesPageDto; }
@Override @Transactional public EndpointProfilesPageDto findEndpointProfileByEndpointGroupId(PageLinkDto pageLink) { validateSqlId(pageLink.getLimit(), "Can't find endpoint group by id. Incorrect limit parameter " + pageLink.getLimit()); validateString(pageLink.getOffset(), "Can't find endpoint group by id. Incorrect offset " + "parameter " + pageLink.getOffset()); return endpointProfileDao.findByEndpointGroupId(pageLink); }
/** * Gets the endpoint profile body by endpoint group id. * * @param pageLink contains information about groupId, offset and limit */ public EndpointProfilesBodyDto getEndpointProfileBodyByEndpointGroupId(PageLinkDto pageLink) throws Exception { String endpointGroupId = pageLink.getEndpointGroupId(); String limit = pageLink.getLimit(); String offset = pageLink.getOffset(); ResponseEntity<EndpointProfilesBodyDto> entity = restTemplate.exchange(restTemplate.getUrl() + "endpointProfileBodyByGroupId?endpointGroupId=" + endpointGroupId + "&limit=" + limit + "&offset=" + offset, HttpMethod.GET, null, new ParameterizedTypeReference<EndpointProfilesBodyDto>() {}); return entity.getBody(); }
private PageLinkDto createNext(PageLinkDto pageLink, HttpServletRequest request) { if (pageLink != null && pageLink.getNext() == null) { StringBuilder nextUrl = new StringBuilder(); nextUrl.append(request.getScheme()).append("://").append(request.getServerName()); int port = request.getServerPort(); if (HTTP_PORT != port && HTTPS_PORT != port) { nextUrl.append(":").append(port); } String next = nextUrl.append(request.getRequestURI()) .append("?") .append(pageLink.getNextUrlPart()) .toString(); pageLink.setNext(next); LOG.debug("Generated next url {}", next); } return pageLink; } }
private PageLinkDto getPageLinkDto() { List<EndpointProfileDto> endpointProfileList = new ArrayList<>(); for (int i = 0; i < GENERATED_PROFILES_COUNT; i++) { endpointProfileList.add(generateEndpointProfileWithEndpointGroupId(TEST_APPID)); } String id = endpointProfileList.get(0).getGroupState().get(0).getEndpointGroupId(); return new PageLinkDto(id, TEST_LIMIT, TEST_OFFSET); }
@Override public EndpointProfilesPageDto findByEndpointGroupId(PageLinkDto pageLink) { LOG.debug("Try to find endpoint profile by endpoint group id [{}]", pageLink.getEndpointGroupId()); EndpointProfilesPageDto endpointProfilesPageDto; List<EndpointProfileDto> cassandraEndpointProfileList; ByteBuffer[] keyHashList; if (pageLink.getApplicationId() != null) { keyHashList = cassandraEpByAppIdDao.findEpByAppId( pageLink, pageLink.getApplicationId()); } else { keyHashList = cassandraEpByEndpointGroupIdDao.findEpByEndpointGroupId(pageLink); } cassandraEndpointProfileList = findEndpointProfilesList( keyHashList, pageLink.getEndpointGroupId()); endpointProfilesPageDto = createNextPage( cassandraEndpointProfileList, pageLink.getEndpointGroupId(), pageLink.getLimit()); return endpointProfilesPageDto; }
@Override public EndpointProfilesPageDto getEndpointProfileByEndpointGroupId(String endpointGroupId, String limit, String offset) throws KaaAdminServiceException { checkAuthority(KaaAuthorityDto.TENANT_DEVELOPER, KaaAuthorityDto.TENANT_USER); try { if (Integer.valueOf(limit) > MAX_LIMIT) { throw new IllegalArgumentException( "Incorrect limit parameter. You must enter value not more than " + MAX_LIMIT); } EndpointGroupDto endpointGroupDto = getEndpointGroup(endpointGroupId); PageLinkDto pageLinkDto = new PageLinkDto(endpointGroupId, limit, offset); if (isGroupAll(endpointGroupDto)) { pageLinkDto.setApplicationId(endpointGroupDto.getApplicationId()); } return controlService.getEndpointProfileByEndpointGroupId(pageLinkDto); } catch (Exception ex) { throw Utils.handleException(ex); } }
@Override public void onSuccess(EndpointProfilesPageDto result) { Set<EndpointProfileDto> hs = new HashSet<>(); hs.addAll(result.getEndpointProfiles()); hs.addAll(endpointProfilesList); endpointProfilesList.clear(); endpointProfilesList.addAll(hs); callback.onSuccess(endpointProfilesList); offset = result.getPageLinkDto().getOffset(); } });
@Test public void testFindBodyByEndpointGroupIdWithNfGroupState() throws Exception { PageLinkDto pageLink = getPageLinkDto(); EndpointProfilesBodyDto found = endpointProfileDao.findBodyByEndpointGroupId(pageLink); Assert.assertFalse(found.getEndpointProfilesBody().isEmpty()); int lim = Integer.valueOf(TEST_LIMIT); Assert.assertEquals(lim, found.getEndpointProfilesBody().size()); pageLink.setApplicationId(TEST_APPID); EndpointProfilesBodyDto foundbyAppId = endpointProfileDao.findBodyByEndpointGroupId(pageLink); Assert.assertFalse(foundbyAppId.getEndpointProfilesBody().isEmpty()); Assert.assertEquals(lim, foundbyAppId.getEndpointProfilesBody().size()); }
/** * Gets the endpoint profile by endpoint group id. * * @param pageLink contains information about groupId, offset and limit */ public EndpointProfilesPageDto getEndpointProfileByEndpointGroupId(PageLinkDto pageLink) throws Exception { String endpointGroupId = pageLink.getEndpointGroupId(); String limit = pageLink.getLimit(); String offset = pageLink.getOffset(); ParameterizedTypeReference<EndpointProfilesPageDto> typeRef = new ParameterizedTypeReference<EndpointProfilesPageDto>() {}; ResponseEntity<EndpointProfilesPageDto> entity = restTemplate.exchange(restTemplate.getUrl() + "endpointProfileByGroupId?endpointGroupId=" + endpointGroupId + "&limit=" + limit + "&offset=" + offset, HttpMethod.GET, null, typeRef); return entity.getBody(); }
@Override @Transactional public EndpointProfilesBodyDto findEndpointProfileBodyByEndpointGroupId(PageLinkDto pageLink) { validateSqlId(pageLink.getLimit(), "Can't find endpoint group by id. Incorrect limit parameter " + pageLink.getLimit()); validateString(pageLink.getOffset(), "Can't find endpoint group by id. Incorrect offset " + "parameter " + pageLink.getOffset()); return endpointProfileDao.findBodyByEndpointGroupId(pageLink); }
@Test public void findBodyByEndpointGroupIdTest() { for (int i = 0; i < GENERATED_PROFILES_COUNT; i++) { generateEndpointProfileWithGroupIdDto(TEST_ENDPOINT_GROUP_ID); } int lim = Integer.valueOf(TEST_LIMIT); PageLinkDto pageLink = new PageLinkDto(TEST_ENDPOINT_GROUP_ID, TEST_LIMIT, TEST_OFFSET); EndpointProfilesBodyDto found = endpointProfileDao.findBodyByEndpointGroupId(pageLink); Assert.assertFalse(found.getEndpointProfilesBody().isEmpty()); Assert.assertEquals(lim, found.getEndpointProfilesBody().size()); }
@Override public EndpointProfilesBodyDto findBodyByEndpointGroupId(PageLinkDto pageLink) { LOG.debug("Try to find endpoint profile body by endpoint group id [{}]", pageLink.getEndpointGroupId()); List<EndpointProfileBodyDto> profilesBodyDto; ByteBuffer[] keyHashList; if (pageLink.getApplicationId() != null) { keyHashList = cassandraEpByAppIdDao.findEpByAppId( pageLink, pageLink.getApplicationId()); } else { keyHashList = cassandraEpByEndpointGroupIdDao.findEpByEndpointGroupId(pageLink); } profilesBodyDto = findEndpointProfilesBodyList(keyHashList, pageLink.getEndpointGroupId()); if (profilesBodyDto == null) { profilesBodyDto = Collections.emptyList(); } EndpointProfilesBodyDto endpointProfilesBodyDto = createNextBodyPage( profilesBodyDto, pageLink.getEndpointGroupId(), pageLink.getLimit()); return endpointProfilesBodyDto; }
@Override public EndpointProfilesBodyDto getEndpointProfileBodyByEndpointGroupId(String endpointGroupId, String limit, String offset) throws KaaAdminServiceException { checkAuthority(KaaAuthorityDto.TENANT_DEVELOPER, KaaAuthorityDto.TENANT_USER); try { if (Integer.valueOf(limit) > MAX_LIMIT) { throw new IllegalArgumentException( "Incorrect limit parameter. You must enter value not more than " + MAX_LIMIT); } EndpointGroupDto endpointGroupDto = getEndpointGroup(endpointGroupId); PageLinkDto pageLinkDto = new PageLinkDto(endpointGroupId, limit, offset); if (isGroupAll(endpointGroupDto)) { pageLinkDto.setApplicationId(endpointGroupDto.getApplicationId()); } return controlService.getEndpointProfileBodyByEndpointGroupId(pageLinkDto); } catch (Exception ex) { throw Utils.handleException(ex); } }
@Test public void testFindByEndpointGroupId() throws Exception { PageLinkDto pageLink = getPageLinkDto(); EndpointProfilesPageDto found = endpointProfileDao.findByEndpointGroupId(pageLink); Assert.assertFalse(found.getEndpointProfiles().isEmpty()); int lim = Integer.valueOf(TEST_LIMIT); Assert.assertEquals(lim, found.getEndpointProfiles().size()); pageLink.setApplicationId(TEST_APPID); EndpointProfilesPageDto foundbyAppId = endpointProfileDao.findByEndpointGroupId(pageLink); Assert.assertFalse(foundbyAppId.getEndpointProfiles().isEmpty()); Assert.assertEquals(lim, foundbyAppId.getEndpointProfiles().size()); }
@Override public EndpointProfilesBodyDto findBodyByEndpointGroupId(PageLinkDto pageLink) { LOG.debug("Find endpoint profiles body by endpoint group id [{}] ", pageLink.getEndpointGroupId()); List<EndpointProfileBodyDto> profilesBody = new ArrayList<>(); int lim = Integer.valueOf(pageLink.getLimit()); int offs = Integer.valueOf(pageLink.getOffset()); Query query = Query.query( new Criteria() .orOperator( where(EP_GROUP_STATE + "." + ENDPOINT_GROUP_ID) .is(pageLink.getEndpointGroupId()), where(EP_GROUP_STATE + "." + ENDPOINT_GROUP_ID) .is(pageLink.getEndpointGroupId()))); query.skip(offs).limit(lim + 1); query.fields() pageLink.setOffset(offset); endpointProfileDtoList.remove(lim); } else { pageLink.setNext(DaoConstants.LAST_PAGE_MESSAGE);
String endpointGroupId = pageLink.getEndpointGroupId(); String limit = pageLink.getLimit(); ByteBuffer endpointKey = getByteBuffer(Base64.decodeBase64(pageLink.getOffset())); Statement queryStatement; if ("0".equals(pageLink.getOffset())) { queryStatement = select().from(getColumnFamilyName()) .where(eq(
private EndpointProfilesPageDto createNextPage( List<EndpointProfileDto> cassandraEndpointProfileList, String endpointGroupId, String limit ) { EndpointProfilesPageDto endpointProfilesPageDto = new EndpointProfilesPageDto(); PageLinkDto pageLinkDto = new PageLinkDto(); String next; int lim = Integer.valueOf(limit); if (cassandraEndpointProfileList.size() == (lim + 1)) { pageLinkDto.setEndpointGroupId(endpointGroupId); pageLinkDto.setLimit(limit); pageLinkDto.setOffset(Base64.encodeBase64URLSafeString( cassandraEndpointProfileList.get(lim).getEndpointKeyHash())); cassandraEndpointProfileList.remove(lim); next = null; } else { next = DaoConstants.LAST_PAGE_MESSAGE; } pageLinkDto.setNext(next); endpointProfilesPageDto.setPageLinkDto(pageLinkDto); endpointProfilesPageDto.setEndpointProfiles(cassandraEndpointProfileList); return endpointProfilesPageDto; }