Commit 9bafe700 authored by michael.simon's avatar michael.simon
Browse files

Implemented endpoint. Simple for now.

parent a700b911
......@@ -3,18 +3,21 @@ package edu.kit.scc.webreg.service;
import java.io.IOException;
import java.util.Map;
import javax.servlet.ServletException;
import edu.kit.scc.webreg.exc.RestInterfaceException;
public interface UserUpdateService {
Map<String, String> updateUser(String eppn, String serviceShortName,
String localHostName) throws IOException, ServletException,
String localHostName) throws IOException,
RestInterfaceException;
Map<String, String> updateUser(Long regId, String localHostName)
throws IOException, ServletException, RestInterfaceException;
throws IOException, RestInterfaceException;
Map<String, String> updateUser(String eppn, String localHostName)
throws IOException, RestInterfaceException;
void updateUserAsync(String eppn, String localHostName);
}
......@@ -7,9 +7,9 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.ejb.Asynchronous;
import javax.ejb.Stateless;
import javax.inject.Inject;
import javax.servlet.ServletException;
import org.slf4j.Logger;
......@@ -59,7 +59,7 @@ public class UserUpdateServiceImpl implements UserUpdateService, Serializable {
@Override
public Map<String, String> updateUser(String eppn,
String serviceShortName, String localHostName)
throws IOException, ServletException, RestInterfaceException {
throws IOException, RestInterfaceException {
UserEntity user = findUser(eppn);
if (user == null)
......@@ -76,9 +76,50 @@ public class UserUpdateServiceImpl implements UserUpdateService, Serializable {
return update(user, service, registry, localHostName);
}
@Override
public Map<String, String> updateUser(String eppn, String localHostName)
throws IOException, RestInterfaceException {
UserEntity user = findUser(eppn);
if (user == null)
throw new NoUserFoundException("no such user");
try {
user = userUpdater.updateUserFromIdp(user);
} catch (UserUpdateException e) {
logger.warn("Could not update user {}: {}", e.getMessage(), user.getEppn());
throw new UserUpdateFailedException("user update failed: " + e.getMessage());
}
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
Map<String, String> map = new HashMap<String, String>();
map.put("eppn", user.getEppn());
map.put("email", user.getEmail());
map.put("last_update", df.format(user.getLastUpdate()));
return map;
}
@Override
@Asynchronous
public void updateUserAsync(String eppn, String localHostName) {
UserEntity user = findUser(eppn);
if (user == null) {
logger.info("Not updating user. No such user: {}", eppn);
return;
}
try {
user = userUpdater.updateUserFromIdp(user);
} catch (UserUpdateException e) {
logger.warn("Could not update user {}: {}", e.getMessage(), user.getEppn());
}
}
@Override
public Map<String, String> updateUser(Long regId, String localHostName)
throws IOException, ServletException, RestInterfaceException {
throws IOException, RestInterfaceException {
RegistryEntity registry = registryDao.findById(regId);
if (registry == null) {
......
package edu.kit.scc.webreg.rest;
import java.io.IOException;
import java.util.Map;
import javax.inject.Inject;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Context;
import edu.kit.scc.webreg.exc.RestInterfaceException;
import edu.kit.scc.webreg.service.UserUpdateService;
@Path("/user-admin")
public class UserController {
@Inject
private UserUpdateService userUpdateService;
@Path(value = "/update-async/{eppn}")
@Produces({"application/json"})
@GET
public Map<String, String> updateUserAsync(@PathParam("eppn") String eppn, @Context HttpServletRequest request)
throws IOException, RestInterfaceException, ServletException {
return userUpdateService.updateUser(eppn, request.getLocalName());
}
@Path(value = "/update/{eppn}")
@Produces({"application/json"})
@GET
public String updateUser(@PathParam("eppn") String eppn, @Context HttpServletRequest request)
throws IOException, RestInterfaceException, ServletException {
userUpdateService.updateUser(eppn, request.getLocalName());
return "";
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment