summaryrefslogtreecommitdiffstats
path: root/src/main/java/org/openslx/imagemaster/localrpc/JsonUser.java
blob: 6b2769b0ad95c46914dead85147fe66e9ad28866 (plain) (blame)
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
package org.openslx.imagemaster.localrpc;

import org.apache.log4j.Logger;
import org.openslx.bwlp.thrift.iface.Role;
import org.openslx.bwlp.thrift.iface.UserInfo;
import org.openslx.imagemaster.util.Util;

public class JsonUser
{

	private static final Logger LOGGER = Logger.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;

	public UserInfo toUser()
	{
		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;
	}

}