@Test public void testMinimalConvert() { apiEntity = new ApiEntity(); apiEntity.setId(API_ID); apiEntity.setDescription(API_DESCRIPTION); Proxy proxy = new Proxy(); proxy.setVirtualHosts(Collections.singletonList(new VirtualHost("/foo"))); apiEntity.setProxy(proxy); doReturn(false).when(ratingService).isEnabled(); apiEntity.setCategories(new HashSet<>(Arrays.asList(API_CATEGORY, API_CATEGORY_HIDDEN))); doReturn(false).when(parameterService).findAsBoolean(Key.PORTAL_APIS_CATEGORY_ENABLED); apiEntity.setLifecycleState(ApiLifecycleState.CREATED); Api responseApi = apiMapper.convert(apiEntity); assertNotNull(responseApi); assertNull(responseApi.getPages()); assertNull(responseApi.getPlans()); assertEquals(API_DESCRIPTION, responseApi.getDescription()); assertEquals(API_ID, responseApi.getId()); assertNull(responseApi.getName()); assertNull(responseApi.getVersion()); assertTrue(responseApi.getDraft()); List<String> entrypoints = responseApi.getEntrypoints(); assertNull(entrypoints); List<String> labels = responseApi.getLabels(); assertNotNull(labels); assertEquals(0, labels.size()); assertNull(responseApi.getOwner()); List<String> categories = responseApi.getCategories(); assertNotNull(categories); assertEquals(0, categories.size()); RatingSummary ratingSummary = responseApi.getRatingSummary(); assertNull(ratingSummary); }
public Api convert(ApiEntity api) { final Api apiItem = new Api(); apiItem.setDescription(api.getDescription()); List<ApiEntrypointEntity> apiEntrypoints = api.getEntrypoints(); if (apiEntrypoints != null) { List<String> entrypoints = apiEntrypoints.stream().map(ApiEntrypointEntity::getTarget) .collect(Collectors.toList()); apiItem.setEntrypoints(entrypoints); } apiItem.setDraft(api.getLifecycleState() == ApiLifecycleState.UNPUBLISHED || api.getLifecycleState() == ApiLifecycleState.CREATED); apiItem.setRunning(api.getState() == Lifecycle.State.STARTED); apiItem.setPublic(api.getVisibility() == Visibility.PUBLIC); apiItem.setId(api.getId()); List<String> apiLabels = api.getLabels(); if (apiLabels != null) { apiItem.setLabels(new ArrayList<>(apiLabels)); } else { apiItem.setLabels(new ArrayList<>()); } apiItem.setName(api.getName()); PrimaryOwnerEntity primaryOwner = api.getPrimaryOwner(); if (primaryOwner != null) { User owner = new User(); owner.setId(primaryOwner.getId()); owner.setDisplayName(primaryOwner.getDisplayName()); owner.setEmail(primaryOwner.getEmail()); apiItem.setOwner(owner); } apiItem.setPages(null); apiItem.setPlans(null); if (ratingService.isEnabled()) { final RatingSummaryEntity ratingSummaryEntity = ratingService.findSummaryByApi(api.getId()); RatingSummary ratingSummary = new RatingSummary().average(ratingSummaryEntity.getAverageRate()) .count(BigDecimal.valueOf(ratingSummaryEntity.getNumberOfRatings())); apiItem.setRatingSummary(ratingSummary); } if (api.getUpdatedAt() != null) { apiItem.setUpdatedAt(api.getUpdatedAt().toInstant().atOffset(ZoneOffset.UTC)); } apiItem.setVersion(api.getVersion()); boolean isCategoryModeEnabled = this.parameterService.findAsBoolean(Key.PORTAL_APIS_CATEGORY_ENABLED); if (isCategoryModeEnabled && api.getCategories() != null) { apiItem.setCategories(api.getCategories().stream().filter(categoryId -> { try { categoryService.findNotHiddenById(categoryId); return true; } catch (CategoryNotFoundException v) { return false; } }).collect(Collectors.toList())); } else { apiItem.setCategories(new ArrayList<>()); } return apiItem; }
ApiMapper { public Api convert(ApiEntity api) { final Api apiItem = new Api(); apiItem.setDescription(api.getDescription()); List<ApiEntrypointEntity> apiEntrypoints = api.getEntrypoints(); if (apiEntrypoints != null) { List<String> entrypoints = apiEntrypoints.stream().map(ApiEntrypointEntity::getTarget) .collect(Collectors.toList()); apiItem.setEntrypoints(entrypoints); } apiItem.setDraft(api.getLifecycleState() == ApiLifecycleState.UNPUBLISHED || api.getLifecycleState() == ApiLifecycleState.CREATED); apiItem.setRunning(api.getState() == Lifecycle.State.STARTED); apiItem.setPublic(api.getVisibility() == Visibility.PUBLIC); apiItem.setId(api.getId()); List<String> apiLabels = api.getLabels(); if (apiLabels != null) { apiItem.setLabels(new ArrayList<>(apiLabels)); } else { apiItem.setLabels(new ArrayList<>()); } apiItem.setName(api.getName()); PrimaryOwnerEntity primaryOwner = api.getPrimaryOwner(); if (primaryOwner != null) { User owner = new User(); owner.setId(primaryOwner.getId()); owner.setDisplayName(primaryOwner.getDisplayName()); owner.setEmail(primaryOwner.getEmail()); apiItem.setOwner(owner); } apiItem.setPages(null); apiItem.setPlans(null); if (ratingService.isEnabled()) { final RatingSummaryEntity ratingSummaryEntity = ratingService.findSummaryByApi(api.getId()); RatingSummary ratingSummary = new RatingSummary().average(ratingSummaryEntity.getAverageRate()) .count(BigDecimal.valueOf(ratingSummaryEntity.getNumberOfRatings())); apiItem.setRatingSummary(ratingSummary); } if (api.getUpdatedAt() != null) { apiItem.setUpdatedAt(api.getUpdatedAt().toInstant().atOffset(ZoneOffset.UTC)); } apiItem.setVersion(api.getVersion()); boolean isCategoryModeEnabled = this.parameterService.findAsBoolean(Key.PORTAL_APIS_CATEGORY_ENABLED); if (isCategoryModeEnabled && api.getCategories() != null) { apiItem.setCategories(api.getCategories().stream().filter(categoryId -> { try { categoryService.findNotHiddenById(categoryId); return true; } catch (CategoryNotFoundException v) { return false; } }).collect(Collectors.toList())); } else { apiItem.setCategories(new ArrayList<>()); } return apiItem; } }
ApiMapper { public Api convert(ApiEntity api) { final Api apiItem = new Api(); apiItem.setDescription(api.getDescription()); List<ApiEntrypointEntity> apiEntrypoints = api.getEntrypoints(); if (apiEntrypoints != null) { List<String> entrypoints = apiEntrypoints.stream().map(ApiEntrypointEntity::getTarget) .collect(Collectors.toList()); apiItem.setEntrypoints(entrypoints); } apiItem.setDraft(api.getLifecycleState() == ApiLifecycleState.UNPUBLISHED || api.getLifecycleState() == ApiLifecycleState.CREATED); apiItem.setRunning(api.getState() == Lifecycle.State.STARTED); apiItem.setPublic(api.getVisibility() == Visibility.PUBLIC); apiItem.setId(api.getId()); List<String> apiLabels = api.getLabels(); if (apiLabels != null) { apiItem.setLabels(new ArrayList<>(apiLabels)); } else { apiItem.setLabels(new ArrayList<>()); } apiItem.setName(api.getName()); PrimaryOwnerEntity primaryOwner = api.getPrimaryOwner(); if (primaryOwner != null) { User owner = new User(); owner.setId(primaryOwner.getId()); owner.setDisplayName(primaryOwner.getDisplayName()); owner.setEmail(primaryOwner.getEmail()); apiItem.setOwner(owner); } apiItem.setPages(null); apiItem.setPlans(null); if (ratingService.isEnabled()) { final RatingSummaryEntity ratingSummaryEntity = ratingService.findSummaryByApi(api.getId()); RatingSummary ratingSummary = new RatingSummary().average(ratingSummaryEntity.getAverageRate()) .count(BigDecimal.valueOf(ratingSummaryEntity.getNumberOfRatings())); apiItem.setRatingSummary(ratingSummary); } if (api.getUpdatedAt() != null) { apiItem.setUpdatedAt(api.getUpdatedAt().toInstant().atOffset(ZoneOffset.UTC)); } apiItem.setVersion(api.getVersion()); boolean isCategoryModeEnabled = this.parameterService.findAsBoolean(Key.PORTAL_APIS_CATEGORY_ENABLED); if (isCategoryModeEnabled && api.getCategories() != null) { apiItem.setCategories(api.getCategories().stream().filter(categoryId -> { try { categoryService.findNotHiddenById(categoryId); return true; } catch (CategoryNotFoundException v) { return false; } }).collect(Collectors.toList())); } else { apiItem.setCategories(new ArrayList<>()); } return apiItem; }  }
ApiMapper { public Api convert(ApiEntity api) { final Api apiItem = new Api(); apiItem.setDescription(api.getDescription()); List<ApiEntrypointEntity> apiEntrypoints = api.getEntrypoints(); if (apiEntrypoints != null) { List<String> entrypoints = apiEntrypoints.stream().map(ApiEntrypointEntity::getTarget) .collect(Collectors.toList()); apiItem.setEntrypoints(entrypoints); } apiItem.setDraft(api.getLifecycleState() == ApiLifecycleState.UNPUBLISHED || api.getLifecycleState() == ApiLifecycleState.CREATED); apiItem.setRunning(api.getState() == Lifecycle.State.STARTED); apiItem.setPublic(api.getVisibility() == Visibility.PUBLIC); apiItem.setId(api.getId()); List<String> apiLabels = api.getLabels(); if (apiLabels != null) { apiItem.setLabels(new ArrayList<>(apiLabels)); } else { apiItem.setLabels(new ArrayList<>()); } apiItem.setName(api.getName()); PrimaryOwnerEntity primaryOwner = api.getPrimaryOwner(); if (primaryOwner != null) { User owner = new User(); owner.setId(primaryOwner.getId()); owner.setDisplayName(primaryOwner.getDisplayName()); owner.setEmail(primaryOwner.getEmail()); apiItem.setOwner(owner); } apiItem.setPages(null); apiItem.setPlans(null); if (ratingService.isEnabled()) { final RatingSummaryEntity ratingSummaryEntity = ratingService.findSummaryByApi(api.getId()); RatingSummary ratingSummary = new RatingSummary().average(ratingSummaryEntity.getAverageRate()) .count(BigDecimal.valueOf(ratingSummaryEntity.getNumberOfRatings())); apiItem.setRatingSummary(ratingSummary); } if (api.getUpdatedAt() != null) { apiItem.setUpdatedAt(api.getUpdatedAt().toInstant().atOffset(ZoneOffset.UTC)); } apiItem.setVersion(api.getVersion()); boolean isCategoryModeEnabled = this.parameterService.findAsBoolean(Key.PORTAL_APIS_CATEGORY_ENABLED); if (isCategoryModeEnabled && api.getCategories() != null) { apiItem.setCategories(api.getCategories().stream().filter(categoryId -> { try { categoryService.findNotHiddenById(categoryId); return true; } catch (CategoryNotFoundException v) { return false; } }).collect(Collectors.toList())); } else { apiItem.setCategories(new ArrayList<>()); } return apiItem; }  Api convert(ApiEntity api); ApiLinks computeApiLinks(String basePath, Date updateDate); }
ApiMapper { public Api convert(ApiEntity api) { final Api apiItem = new Api(); apiItem.setDescription(api.getDescription()); List<ApiEntrypointEntity> apiEntrypoints = api.getEntrypoints(); if (apiEntrypoints != null) { List<String> entrypoints = apiEntrypoints.stream().map(ApiEntrypointEntity::getTarget) .collect(Collectors.toList()); apiItem.setEntrypoints(entrypoints); } apiItem.setDraft(api.getLifecycleState() == ApiLifecycleState.UNPUBLISHED || api.getLifecycleState() == ApiLifecycleState.CREATED); apiItem.setRunning(api.getState() == Lifecycle.State.STARTED); apiItem.setPublic(api.getVisibility() == Visibility.PUBLIC); apiItem.setId(api.getId()); List<String> apiLabels = api.getLabels(); if (apiLabels != null) { apiItem.setLabels(new ArrayList<>(apiLabels)); } else { apiItem.setLabels(new ArrayList<>()); } apiItem.setName(api.getName()); PrimaryOwnerEntity primaryOwner = api.getPrimaryOwner(); if (primaryOwner != null) { User owner = new User(); owner.setId(primaryOwner.getId()); owner.setDisplayName(primaryOwner.getDisplayName()); owner.setEmail(primaryOwner.getEmail()); apiItem.setOwner(owner); } apiItem.setPages(null); apiItem.setPlans(null); if (ratingService.isEnabled()) { final RatingSummaryEntity ratingSummaryEntity = ratingService.findSummaryByApi(api.getId()); RatingSummary ratingSummary = new RatingSummary().average(ratingSummaryEntity.getAverageRate()) .count(BigDecimal.valueOf(ratingSummaryEntity.getNumberOfRatings())); apiItem.setRatingSummary(ratingSummary); } if (api.getUpdatedAt() != null) { apiItem.setUpdatedAt(api.getUpdatedAt().toInstant().atOffset(ZoneOffset.UTC)); } apiItem.setVersion(api.getVersion()); boolean isCategoryModeEnabled = this.parameterService.findAsBoolean(Key.PORTAL_APIS_CATEGORY_ENABLED); if (isCategoryModeEnabled && api.getCategories() != null) { apiItem.setCategories(api.getCategories().stream().filter(categoryId -> { try { categoryService.findNotHiddenById(categoryId); return true; } catch (CategoryNotFoundException v) { return false; } }).collect(Collectors.toList())); } else { apiItem.setCategories(new ArrayList<>()); } return apiItem; }  Api convert(ApiEntity api); ApiLinks computeApiLinks(String basePath, Date updateDate);  }