1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
|
package org.openslx.imagemaster.localrpc;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.openslx.bwlp.thrift.iface.AuthorizationError;
import org.openslx.bwlp.thrift.iface.Role;
import org.openslx.bwlp.thrift.iface.TAuthorizationException;
import org.openslx.bwlp.thrift.iface.UserInfo;
import org.openslx.imagemaster.util.Util;
public class JsonUser
{
private static final Logger LOGGER = LogManager.getLogger( JsonUser.class );
private String userId = null;
private String organizationId = null;
private String firstName = null;
private String lastName = null;
private String mail = null;
private String role = null;
private String status;
private String error;
private String accessCode;
public UserInfo toUser()
{
if ( !"ok".equals( status ) )
return null;
Role role;
try {
role = Role.valueOf( this.role );
} catch ( Exception e ) {
LOGGER.warn( "Invalid role: " + this.role );
return null;
}
if ( Util.isEmpty( userId, "userId", LOGGER ) || Util.isEmpty( organizationId, "orgId", LOGGER )
|| Util.isEmpty( lastName, "lastName", LOGGER ) || Util.isEmpty( mail, "mail", LOGGER ) )
return null;
UserInfo ui = new UserInfo( userId, firstName, lastName, mail, organizationId );
ui.role = role;
return ui;
}
public TAuthorizationException toException()
{
if ( "ok".equals( status ) )
return null;
return new TAuthorizationException( AuthorizationError.GENERIC_ERROR, this.error );
}
public String accessCode()
{
return this.accessCode;
}
}
|