Merge pull request #9945 from sampada07/JAVA-33

JAVA-33: Moved spring-katharsis to boot-2
This commit is contained in:
Dhawal Kapil 2020-08-31 20:29:48 +05:30 committed by GitHub
commit 792df33996
6 changed files with 23 additions and 14 deletions

View File

@ -10,9 +10,9 @@
<parent>
<groupId>com.baeldung</groupId>
<artifactId>parent-boot-1</artifactId>
<artifactId>parent-boot-2</artifactId>
<version>0.0.1-SNAPSHOT</version>
<relativePath>../parent-boot-1</relativePath>
<relativePath>../parent-boot-2</relativePath>
</parent>
<dependencies>

View File

@ -4,7 +4,7 @@ import io.katharsis.spring.boot.v3.KatharsisConfigV3;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.support.SpringBootServletInitializer;
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
import org.springframework.context.annotation.Import;
@SpringBootApplication

View File

@ -7,6 +7,9 @@ import io.katharsis.repository.ResourceRepositoryV2;
import io.katharsis.resource.list.ResourceList;
import com.baeldung.persistence.model.Role;
import java.util.Optional;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
@ -17,7 +20,8 @@ public class RoleResourceRepository implements ResourceRepositoryV2<Role, Long>
@Override
public Role findOne(Long id, QuerySpec querySpec) {
return roleRepository.findOne(id);
Optional<Role> role = roleRepository.findById(id);
return role.isPresent()? role.get() : null;
}
@Override
@ -27,7 +31,7 @@ public class RoleResourceRepository implements ResourceRepositoryV2<Role, Long>
@Override
public ResourceList<Role> findAll(Iterable<Long> ids, QuerySpec querySpec) {
return querySpec.apply(roleRepository.findAll(ids));
return querySpec.apply(roleRepository.findAllById(ids));
}
@Override
@ -37,7 +41,7 @@ public class RoleResourceRepository implements ResourceRepositoryV2<Role, Long>
@Override
public void delete(Long id) {
roleRepository.delete(id);
roleRepository.deleteById(id);
}
@Override

View File

@ -6,6 +6,8 @@ import io.katharsis.queryspec.QuerySpec;
import io.katharsis.repository.ResourceRepositoryV2;
import io.katharsis.resource.list.ResourceList;
import java.util.Optional;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
@ -17,7 +19,8 @@ public class UserResourceRepository implements ResourceRepositoryV2<User, Long>
@Override
public User findOne(Long id, QuerySpec querySpec) {
return userRepository.findOne(id);
Optional<User> user = userRepository.findById(id);
return user.isPresent()? user.get() : null;
}
@Override
@ -27,7 +30,7 @@ public class UserResourceRepository implements ResourceRepositoryV2<User, Long>
@Override
public ResourceList<User> findAll(Iterable<Long> ids, QuerySpec querySpec) {
return querySpec.apply(userRepository.findAll(ids));
return querySpec.apply(userRepository.findAllById(ids));
}
@Override
@ -37,7 +40,7 @@ public class UserResourceRepository implements ResourceRepositoryV2<User, Long>
@Override
public void delete(Long id) {
userRepository.delete(id);
userRepository.deleteById(id);
}
@Override

View File

@ -8,6 +8,7 @@ import io.katharsis.repository.RelationshipRepositoryV2;
import io.katharsis.resource.list.ResourceList;
import java.util.HashSet;
import java.util.Optional;
import java.util.Set;
import com.baeldung.persistence.model.Role;
@ -31,7 +32,7 @@ public class UserToRoleRelationshipRepository implements RelationshipRepositoryV
@Override
public void setRelations(User user, Iterable<Long> roleIds, String fieldName) {
final Set<Role> roles = new HashSet<Role>();
roles.addAll(roleRepository.findAll(roleIds));
roles.addAll(roleRepository.findAllById(roleIds));
user.setRoles(roles);
userRepository.save(user);
}
@ -39,7 +40,7 @@ public class UserToRoleRelationshipRepository implements RelationshipRepositoryV
@Override
public void addRelations(User user, Iterable<Long> roleIds, String fieldName) {
final Set<Role> roles = user.getRoles();
roles.addAll(roleRepository.findAll(roleIds));
roles.addAll(roleRepository.findAllById(roleIds));
user.setRoles(roles);
userRepository.save(user);
}
@ -47,7 +48,7 @@ public class UserToRoleRelationshipRepository implements RelationshipRepositoryV
@Override
public void removeRelations(User user, Iterable<Long> roleIds, String fieldName) {
final Set<Role> roles = user.getRoles();
roles.removeAll(roleRepository.findAll(roleIds));
roles.removeAll(roleRepository.findAllById(roleIds));
user.setRoles(roles);
userRepository.save(user);
}
@ -60,7 +61,8 @@ public class UserToRoleRelationshipRepository implements RelationshipRepositoryV
@Override
public ResourceList<Role> findManyTargets(Long sourceId, String fieldName, QuerySpec querySpec) {
final User user = userRepository.findOne(sourceId);
final Optional<User> userOptional = userRepository.findById(sourceId);
User user = userOptional.isPresent() ? userOptional.get() : new User();
return querySpec.apply(user.getRoles());
}

View File

@ -6,7 +6,7 @@ spring.jpa.hibernate.ddl-auto = create-drop
spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.H2Dialect
server.port=8082
server.context-path=/spring-katharsis
server.servlet.context-path=/spring-katharsis
katharsis.domainName=http://localhost:8082/spring-katharsis
katharsis.pathPrefix=/