@Test public void createsSlugForGivenLabel() { MockEntity savedEntity = put.createSlug(MockEntity.builder().label(TEST_LABEL).build()); assertEquals(savedEntity.getSlug(), TEST_SLUG); savedEntity = put.createSlug(MockEntity.builder().label(TEST_LABEL_SPECIAL_CHARACTERS).build()); assertEquals(savedEntity.getSlug(), BaseRestService.GENERIC_PREFIX); savedEntity = put.createSlug(MockEntity.builder().label(TEST_LABEL_NUMERIC).build()); assertEquals(savedEntity.getSlug(), BaseRestService.GENERIC_PREFIX + "-" + TEST_LABEL_NUMERIC); savedEntity = put.createSlug(MockEntity.builder().label(TEST_LABEL_NUMERIC_AND_SPACES).build()); assertEquals(savedEntity.getSlug(), BaseRestService.GENERIC_PREFIX + "-" + TEST_LABEL_NUMERIC); }
@NonNull protected T createSlug(@NonNull final T input) { final String baseSlug = basicSlugFromLabel(input.getLabel()); final String slug = !isSlugAlreadyUsed(baseSlug) ? baseSlug : addSuffix(baseSlug, 1); input.setSlug(slug); return input; }
BaseRestService implements RestService<T> { @NonNull protected T createSlug(@NonNull final T input) { final String baseSlug = basicSlugFromLabel(input.getLabel()); final String slug = !isSlugAlreadyUsed(baseSlug) ? baseSlug : addSuffix(baseSlug, 1); input.setSlug(slug); return input; } }
BaseRestService implements RestService<T> { @NonNull protected T createSlug(@NonNull final T input) { final String baseSlug = basicSlugFromLabel(input.getLabel()); final String slug = !isSlugAlreadyUsed(baseSlug) ? baseSlug : addSuffix(baseSlug, 1); input.setSlug(slug); return input; } protected  BaseRestService(@NonNull final BaseSlugRepository<T> repository); }
BaseRestService implements RestService<T> { @NonNull protected T createSlug(@NonNull final T input) { final String baseSlug = basicSlugFromLabel(input.getLabel()); final String slug = !isSlugAlreadyUsed(baseSlug) ? baseSlug : addSuffix(baseSlug, 1); input.setSlug(slug); return input; } protected  BaseRestService(@NonNull final BaseSlugRepository<T> repository); @NonNull T createItem(@NonNull final T input); @NonNull Collection<T> getItems(); @NonNull T getItem(@NonNull final String slug); @NonNull T getItem(@NonNull final Long id); @NonNull T updateItem(@NonNull final T input); void deleteItem(String slug); void deleteItem(Long id); }
BaseRestService implements RestService<T> { @NonNull protected T createSlug(@NonNull final T input) { final String baseSlug = basicSlugFromLabel(input.getLabel()); final String slug = !isSlugAlreadyUsed(baseSlug) ? baseSlug : addSuffix(baseSlug, 1); input.setSlug(slug); return input; } protected  BaseRestService(@NonNull final BaseSlugRepository<T> repository); @NonNull T createItem(@NonNull final T input); @NonNull Collection<T> getItems(); @NonNull T getItem(@NonNull final String slug); @NonNull T getItem(@NonNull final Long id); @NonNull T updateItem(@NonNull final T input); void deleteItem(String slug); void deleteItem(Long id); static final String GENERIC_PREFIX; }