Changeset 4351


Ignore:
Timestamp:
01/27/14 15:31:44 (10 years ago)
Author:
olhsha
Message:

dbase admin's resource for updating users account type

File:
1 edited

Legend:

Unmodified
Added
Removed
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/rest/UserResource.java

    r4301 r4351  
    219219        }
    220220    }
     221   
     222    @PUT
     223    @Produces(MediaType.TEXT_PLAIN)
     224    @Path("{externalId}/account/{accountType}")
     225    public String updateUserAccount(@PathParam("externalId") String externalId, @PathParam("accountType") String accountType) throws IOException {
     226        String remoteUser = httpServletRequest.getRemoteUser();
     227        Number remoteUserID = dbIntegrityService.getUserInternalIDFromRemoteID(remoteUser);
     228        if (remoteUserID != null) {
     229            if (dbIntegrityService.getTypeOfUserAccount(remoteUserID).equals(admin)) {
     230                dbIntegrityService.setServiceURI(uriInfo.getBaseUri().toString());
     231                final boolean updated = dbIntegrityService.updateAccount(UUID.fromString(externalId), accountType);
     232                if (updated) {
     233                    return "The account was updated to "+dbIntegrityService.getTypeOfUserAccount(dbIntegrityService.getUserInternalIdentifier(UUID.fromString(externalId)));
     234                } else {
     235                    httpServletResponse.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "The account was not updated.");
     236                    return "The account was not updated.";
     237                }
     238            } else {
     239                httpServletResponse.sendError(HttpServletResponse.SC_UNAUTHORIZED, "The logged-in user does not have admin rights to update an account type in the database");
     240                return null;
     241            }
     242        } else {
     243            httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, "The logged-in user is not found in the database");
     244            return null;
     245        }
     246    }
    221247
    222248    @DELETE
     
    276302        return httpServletRequest.getRemoteUser().equals(dbIntegrityService.getUserRemoteID(userID));
    277303    }
     304   
     305   
    278306}
Note: See TracChangeset for help on using the changeset viewer.