This repository has been archived by the owner on Nov 9, 2017. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Alex Eng
committed
Sep 29, 2014
1 parent
120eb90
commit 6f78455
Showing
3 changed files
with
71 additions
and
1 deletion.
There are no files selected for viewing
63 changes: 63 additions & 0 deletions
63
zanata-war/src/main/java/org/zanata/rest/service/UserService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package org.zanata.rest.service; | ||
|
||
import javax.ws.rs.Path; | ||
import javax.ws.rs.PathParam; | ||
import javax.ws.rs.core.GenericEntity; | ||
import javax.ws.rs.core.Response; | ||
|
||
import org.jboss.resteasy.util.GenericType; | ||
import org.jboss.seam.annotations.In; | ||
import org.jboss.seam.annotations.Name; | ||
import org.jboss.seam.security.management.JpaIdentityStore; | ||
import org.zanata.dao.AccountDAO; | ||
import org.zanata.model.HAccount; | ||
import org.zanata.model.HPerson; | ||
import org.zanata.rest.dto.Locale; | ||
import org.zanata.rest.dto.TransUnitStatus; | ||
import org.zanata.rest.dto.User; | ||
import org.zanata.rest.dto.VersionInfo; | ||
import org.zanata.service.GravatarService; | ||
import org.zanata.util.VersionUtility; | ||
|
||
import org.zanata.rest.service.UserResource; | ||
|
||
import java.lang.reflect.Type; | ||
import java.util.List; | ||
|
||
@Name("userService") | ||
@Path(UserResource.SERVICE_PATH) | ||
public class UserService implements UserResource { | ||
|
||
@In(value = JpaIdentityStore.AUTHENTICATED_USER) | ||
private HAccount authenticatedAccount; | ||
|
||
@In | ||
private GravatarService gravatarServiceImpl; | ||
|
||
@In | ||
private AccountDAO accountDAO; | ||
|
||
@Override | ||
public Response getMyInfo() { | ||
return createUser(authenticatedAccount); | ||
} | ||
|
||
@Override | ||
public Response getUserInfo(String username) { | ||
HAccount account = accountDAO.getByUsername(username); | ||
return createUser(account); | ||
} | ||
|
||
private Response createUser(HAccount account) { | ||
if (account == null) { | ||
return Response.status(Response.Status.NOT_FOUND).build(); | ||
} | ||
|
||
HPerson person = account.getPerson(); | ||
User user = | ||
new User(account.getUsername(), person.getEmail(), | ||
person.getName(), | ||
gravatarServiceImpl.getGravatarHash(person.getEmail())); | ||
return Response.ok(user).build(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters