Skip to content

Commit 732debf

Browse files
author
eugenp
committed
work on principal/service DTO
1 parent 78b23a5 commit 732debf

8 files changed

Lines changed: 12 additions & 15 deletions

File tree

‎src/main/java/org/rest/sec/dto/User.java‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ public User( final Principal principal ){
4444

4545
name = principal.getName();
4646
roles = principal.getRoles();
47+
id = principal.getId();
4748
}
4849

4950
// API

‎src/main/java/org/rest/sec/model/Principal.java‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ public class Principal implements IEntity{
2929
@Column( nullable = false )
3030
private String password;
3131

32-
/* Persistence */
3332
@OneToMany( fetch = FetchType.EAGER )
3433
@JoinColumn( name = "ROLE_ID" )
3534
@Column( nullable = false )

‎src/main/java/org/rest/sec/persistence/service/impl/dto/UserServiceImpl.java‎

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22

33
import java.util.List;
44

5+
import org.rest.common.web.RestPreconditions;
56
import org.rest.sec.dto.PrincipalToUserFunction;
67
import org.rest.sec.dto.User;
78
import org.rest.sec.model.Principal;
8-
import org.rest.sec.model.Role;
99
import org.rest.sec.persistence.service.IPrincipalService;
1010
import org.rest.sec.persistence.service.dto.IUserService;
1111
import org.springframework.beans.factory.annotation.Autowired;
@@ -17,7 +17,6 @@
1717
import org.springframework.transaction.annotation.Transactional;
1818

1919
import com.google.common.collect.Lists;
20-
import com.google.common.collect.Sets;
2120

2221
@Service
2322
@Transactional
@@ -43,6 +42,9 @@ public User findByName( final String name ){
4342
@Override
4443
public User findOne( final long id ){
4544
final Principal principal = principalService.findOne( id );
45+
if( principal == null ){
46+
return null;
47+
}
4648
return new User( principal );
4749
}
4850

@@ -72,7 +74,7 @@ public Page< User > findPaginated( final int page, final int size, final String
7274

7375
@Override
7476
public User create( final User entity ){
75-
final Principal newPrincipalEntity = new Principal( entity.getName(), entity.getPassword(), Sets.<Role> newHashSet() );
77+
final Principal newPrincipalEntity = new Principal( entity.getName(), entity.getPassword(), entity.getRoles() );
7678
principalService.create( newPrincipalEntity );
7779
entity.setId( newPrincipalEntity.getId() );
7880
return entity;
@@ -82,7 +84,12 @@ public User create( final User entity ){
8284

8385
@Override
8486
public void update( final User entity ){
85-
throw new UnsupportedOperationException();
87+
final Principal principalToUpdate = RestPreconditions.checkNotNull( principalService.findOne( entity.getId() ) );
88+
89+
principalToUpdate.setName( entity.getName() );
90+
principalToUpdate.setRoles( entity.getRoles() );
91+
92+
principalService.update( principalToUpdate );
8693
}
8794

8895
// delete

‎src/test/java/org/rest/sec/web/user/UserDiscoverabilityRESTIntegrationTest.java‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import static org.apache.commons.lang3.RandomStringUtils.randomAlphabetic;
44

5-
import org.junit.Ignore;
65
import org.junit.runner.RunWith;
76
import org.rest.sec.dto.User;
87
import org.rest.sec.testing.template.UserRESTTemplateImpl;
@@ -18,7 +17,6 @@
1817

1918
@RunWith( SpringJUnit4ClassRunner.class )
2019
@ContextConfiguration( classes = { ApplicationTestConfig.class, PersistenceJPAConfig.class },loader = AnnotationConfigContextLoader.class )
21-
@Ignore( "user and principal work is still in progress" )
2220
public class UserDiscoverabilityRESTIntegrationTest extends AbstractDiscoverabilityRESTIntegrationTest< User >{
2321

2422
@Autowired

‎src/test/java/org/rest/sec/web/user/UserLogicRESTIntegrationTest.java‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
import static org.junit.Assert.assertThat;
88

99
import org.hamcrest.Matchers;
10-
import org.junit.Ignore;
1110
import org.junit.Test;
1211
import org.junit.runner.RunWith;
1312
import org.rest.sec.dto.User;
@@ -27,7 +26,6 @@
2726

2827
@RunWith( SpringJUnit4ClassRunner.class )
2928
@ContextConfiguration( classes = { ApplicationTestConfig.class, PersistenceJPAConfig.class },loader = AnnotationConfigContextLoader.class )
30-
@Ignore( "user and principal work is still in progress" )
3129
public class UserLogicRESTIntegrationTest extends AbstractLogicRESTIntegrationTest< User >{
3230

3331
@Autowired

‎src/test/java/org/rest/sec/web/user/UserMimeRESTIntegrationTest.java‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package org.rest.sec.web.user;
22

3-
import org.junit.Ignore;
43
import org.junit.runner.RunWith;
54
import org.rest.sec.dto.User;
65
import org.rest.sec.testing.template.UserRESTTemplateImpl;
@@ -14,7 +13,6 @@
1413

1514
@RunWith( SpringJUnit4ClassRunner.class )
1615
@ContextConfiguration( classes = { ApplicationTestConfig.class, PersistenceJPAConfig.class },loader = AnnotationConfigContextLoader.class )
17-
@Ignore( "user and principal work is still in progress" )
1816
public class UserMimeRESTIntegrationTest extends AbstractMimeRESTIntegrationTest< User >{
1917

2018
@Autowired

‎src/test/java/org/rest/sec/web/user/UserSortRESTIntegrationTest.java‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package org.rest.sec.web.user;
22

3-
import org.junit.Ignore;
43
import org.junit.runner.RunWith;
54
import org.rest.sec.dto.User;
65
import org.rest.sec.testing.template.UserRESTTemplateImpl;
@@ -16,7 +15,6 @@
1615

1716
@RunWith( SpringJUnit4ClassRunner.class )
1817
@ContextConfiguration( classes = { ApplicationTestConfig.class, PersistenceJPAConfig.class },loader = AnnotationConfigContextLoader.class )
19-
@Ignore( "user and principal work is still in progress" )
2018
public class UserSortRESTIntegrationTest extends AbstractSortRESTIntegrationTest< User >{
2119

2220
@Autowired

‎src/test/java/org/rest/security/SecurityRESTIntegrationTest.java‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import static org.hamcrest.CoreMatchers.is;
55
import static org.hamcrest.MatcherAssert.assertThat;
66

7-
import org.junit.Ignore;
87
import org.junit.Test;
98
import org.junit.runner.RunWith;
109
import org.rest.sec.testing.template.UserRESTTemplateImpl;
@@ -19,7 +18,6 @@
1918

2019
@RunWith( SpringJUnit4ClassRunner.class )
2120
@ContextConfiguration( classes = { ApplicationTestConfig.class, PersistenceJPAConfig.class },loader = AnnotationConfigContextLoader.class )
22-
@Ignore( "user and principal work is still in progress" )
2321
public class SecurityRESTIntegrationTest{
2422

2523
@Autowired

0 commit comments

Comments
 (0)