22
33import java .util .List ;
44
5+ import org .rest .common .web .RestPreconditions ;
56import org .rest .sec .dto .PrincipalToUserFunction ;
67import org .rest .sec .dto .User ;
78import org .rest .sec .model .Principal ;
8- import org .rest .sec .model .Role ;
99import org .rest .sec .persistence .service .IPrincipalService ;
1010import org .rest .sec .persistence .service .dto .IUserService ;
1111import org .springframework .beans .factory .annotation .Autowired ;
1717import org .springframework .transaction .annotation .Transactional ;
1818
1919import 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
0 commit comments