Skip to content

Instantly share code, notes, and snippets.

Eresh ereshzealous

Block or report user

Report or block ereshzealous

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View AuthorController.java
package com.eresh.spring.rest;
import com.eresh.spring.persistence.entity.Author;
import com.eresh.spring.persistence.repository.AuthorRepository;
import com.eresh.spring.rest.ws.WSAuthorResponse;
import com.eresh.spring.service.AuthorService;
import reactor.core.publisher.Mono;
import org.apache.commons.lang3.RandomStringUtils;
import org.springframework.beans.factory.annotation.Autowired;
View SaveAuthor.java
public Mono<Author> saveAuthor(Author author) {
if (StringUtils.isNotBlank(author.getId())) {
return authorRepository.findByIdAndDeleteIsFalse(author.getId())
.switchIfEmpty(Mono.error(new Exception("No Author found with Id: " + author.getId())))
.doOnSuccess(author1 -> {
author1 = updateAuthor(author, author1);
authorRepository.save(author1)
.subscribe();
});
}
View findAuthors.java
public Mono<WSAuthorResponse> findAuthors(Integer offset, Integer limit) {
WSAuthorResponse result = new WSAuthorResponse();
return authorRepository.count()
.map(totalElements -> {
result.setTotalElements(totalElements);
return totalElements;
})
.flatMapMany(el -> authorRepository.retrieveAllAuthors(PageRequest.of(offset, limit)))
.collectList()
.map(data -> {
View BaseEntity.java
package com.eresh.spring.persistence.entity;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import org.springframework.data.annotation.CreatedBy;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.Id;
import org.springframework.data.annotation.LastModifiedBy;
View Author.java
package com.eresh.spring.persistence.entity;
import lombok.Data;
import org.springframework.data.mongodb.core.index.TextIndexed;
import org.springframework.data.mongodb.core.mapping.Document;
/**
* Created By Gorantla, Eresh on 12/Dec/2019
**/
View AuthorRepository.java
package com.eresh.spring.persistence.repository;
import com.eresh.spring.persistence.entity.Author;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.mongodb.repository.Query;
import org.springframework.data.mongodb.repository.ReactiveMongoRepository;
View BeanUtil.java
package com.minikube.sample.rest.controller;
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Service;
/**
* Created by Eresh Gorantla on 09/May/2019
**/
View ProptotypeBean.java
package com.minikube.sample.rest.controller;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
import java.util.concurrent.atomic.AtomicInteger;
View SingletonBean.java
package com.minikube.sample.rest.controller;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
import java.util.concurrent.atomic.AtomicInteger;
/**
View PrototypeBean-1
package com.minikube.sample.rest.controller;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
/**
* Created By Gorantla, Eresh on 13/Jan/2020
**/
You can’t perform that action at this time.