Example usage for org.springframework.http HttpMethod PUT

List of usage examples for org.springframework.http HttpMethod PUT

Introduction

In this page you can find the example usage for org.springframework.http HttpMethod PUT.

Prototype

HttpMethod PUT

To view the source code for org.springframework.http HttpMethod PUT.

Click Source Link

Usage

From source file:sg.ncl.MainController.java

@RequestMapping(path = "/password_reset")
public String resetPassword(@ModelAttribute("passwordResetForm") PasswordResetForm passwordResetForm)
        throws IOException {
    if (!passwordResetForm.isPasswordOk()) {
        return FORGET_PSWD_NEW_PSWD_PAGE;
    }//from ww  w .j av a  2  s  .c o  m

    JSONObject obj = new JSONObject();
    obj.put("key", passwordResetForm.getKey());
    obj.put("new", passwordResetForm.getPassword1());

    log.info("Connecting to sio for password reset, key = {}", passwordResetForm.getKey());
    HttpHeaders headers = new HttpHeaders();
    headers.setContentType(MediaType.APPLICATION_JSON);
    HttpEntity<String> request = new HttpEntity<>(obj.toString(), headers);
    restTemplate.setErrorHandler(new MyResponseErrorHandler());
    ResponseEntity response = null;
    try {
        response = restTemplate.exchange(properties.getPasswordResetURI(), HttpMethod.PUT, request,
                String.class);
    } catch (RestClientException e) {
        log.warn("Error connecting to sio for password reset! {}", e);
        passwordResetForm.setErrMsg("Cannot connect to server! Please try again later.");
        return FORGET_PSWD_NEW_PSWD_PAGE;
    }

    if (RestUtil.isError(response.getStatusCode())) {
        EnumMap<ExceptionState, String> exceptionMessageMap = new EnumMap<>(ExceptionState.class);
        exceptionMessageMap.put(PASSWORD_RESET_REQUEST_TIMEOUT_EXCEPTION,
                "Password reset request timed out. Please request a new reset email.");
        exceptionMessageMap.put(PASSWORD_RESET_REQUEST_NOT_FOUND_EXCEPTION,
                "Invalid password reset request. Please request a new reset email.");
        exceptionMessageMap.put(ADAPTER_CONNECTION_EXCEPTION,
                "Server-side error. Please contact " + CONTACT_EMAIL);

        MyErrorResource error = objectMapper.readValue(response.getBody().toString(), MyErrorResource.class);
        ExceptionState exceptionState = ExceptionState.parseExceptionState(error.getError());

        final String errMsg = exceptionMessageMap.get(exceptionState) == null ? ERR_SERVER_OVERLOAD
                : exceptionMessageMap.get(exceptionState);
        passwordResetForm.setErrMsg(errMsg);
        log.warn("Server responded error for password reset: {}", exceptionState.toString());
        return FORGET_PSWD_NEW_PSWD_PAGE;
    }
    log.info("Password was reset, key = {}", passwordResetForm.getKey());
    return "password_reset_success";
}

From source file:sg.ncl.MainController.java

@RequestMapping(value = "/account_settings", method = RequestMethod.POST)
public String editAccountDetails(@ModelAttribute("editUser") User2 editUser,
        final RedirectAttributes redirectAttributes, HttpSession session) throws WebServiceRuntimeException {

    String editPhrase = "editPhrase";

    if (checkEditUserFields(editUser, redirectAttributes, editPhrase)) {
        session.removeAttribute(webProperties.getSessionUserAccount());
        return "redirect:/account_settings";
    } else {//from ww w . ja  v  a 2  s  . c o  m
        // used to compare original and edited User2 objects
        User2 originalUser = (User2) session.getAttribute(webProperties.getSessionUserAccount());

        JSONObject userObject = new JSONObject();
        JSONObject userDetails = new JSONObject();
        JSONObject address = new JSONObject();

        userDetails.put(FNAME, editUser.getFirstName());
        userDetails.put(LNAME, editUser.getLastName());
        userDetails.put(EMAIL, editUser.getEmail());
        userDetails.put(PHONE, editUser.getPhone());
        userDetails.put(JOB_TITLE, editUser.getJobTitle());
        userDetails.put(ADDRESS, address);
        userDetails.put(INSTITUTION, editUser.getInstitution());
        userDetails.put(INSTITUTION_ABBREVIATION, originalUser.getInstitutionAbbreviation());
        userDetails.put(INSTITUTION_WEB, originalUser.getInstitutionWeb());

        address.put(ADDRESS1, originalUser.getAddress1());
        address.put(ADDRESS2, originalUser.getAddress2());
        address.put(COUNTRY, editUser.getCountry());
        address.put(CITY, originalUser.getCity());
        address.put(REGION, originalUser.getRegion());
        address.put(ZIP_CODE, originalUser.getPostalCode());

        userObject.put(USER_DETAILS, userDetails);

        String userId_uri = properties.getSioUsersUrl()
                + session.getAttribute(webProperties.getSessionUserId());

        HttpEntity<String> request = createHttpEntityWithBody(userObject.toString());
        restTemplate.exchange(userId_uri, HttpMethod.PUT, request, String.class);

        checkUserUpdate(editUser, redirectAttributes, originalUser);

        // credential service change password
        if (editUser.isPasswordMatch()) {
            JSONObject credObject = new JSONObject();
            credObject.put(PSWD, editUser.getPassword());

            HttpEntity<String> credRequest = createHttpEntityWithBody(credObject.toString());
            restTemplate.setErrorHandler(new MyResponseErrorHandler());
            ResponseEntity response = restTemplate.exchange(
                    properties.getUpdateCredentials(session.getAttribute("id").toString()), HttpMethod.PUT,
                    credRequest, String.class);
            String responseBody = response.getBody().toString();

            try {
                if (RestUtil.isError(response.getStatusCode())) {
                    MyErrorResource error = objectMapper.readValue(responseBody, MyErrorResource.class);
                    redirectAttributes.addFlashAttribute(editPhrase, "fail");
                } else {
                    redirectAttributes.addFlashAttribute(editPhrase, SUCCESS);
                }
            } catch (IOException e) {
                throw new WebServiceRuntimeException(e.getMessage());
            } finally {
                session.removeAttribute(webProperties.getSessionUserAccount());
            }
        }
    }
    return "redirect:/account_settings";
}

From source file:sg.ncl.MainController.java

@RequestMapping(value = "/team_profile/{teamId}", method = RequestMethod.POST)
public String editTeamProfile(@PathVariable String teamId, @ModelAttribute("team") Team2 editTeam,
        final RedirectAttributes redirectAttributes, HttpSession session) throws IOException {

    boolean errorsFound = false;

    if (editTeam.getDescription().isEmpty()) {
        errorsFound = true;//from ww w .  j  a va 2 s. c o m
        redirectAttributes.addFlashAttribute("editDesc", "fail");
    }

    if (errorsFound) {
        // safer to remove
        session.removeAttribute(ORIGINAL_TEAM);
        return REDIRECT_TEAM_PROFILE + editTeam.getId();
    }

    // can edit team description and team website for now

    JSONObject teamfields = new JSONObject();
    teamfields.put("id", teamId);
    teamfields.put("name", editTeam.getName());
    teamfields.put(DESCRIPTION, editTeam.getDescription());
    teamfields.put(WEBSITE, "http://default.com");
    teamfields.put(ORGANISATION_TYPE, editTeam.getOrganisationType());
    teamfields.put("privacy", "OPEN");
    teamfields.put(STATUS, editTeam.getStatus());
    teamfields.put(MEMBERS, editTeam.getMembersList());

    HttpEntity<String> request = createHttpEntityWithBody(teamfields.toString());
    ResponseEntity response;
    try {
        response = restTemplate.exchange(properties.getTeamById(teamId), HttpMethod.PUT, request, String.class);
    } catch (RestClientException e) {
        log.warn("Error connecting to sio team service for edit team profile: {}", e);
        redirectAttributes.addFlashAttribute(MESSAGE, ERR_SERVER_OVERLOAD);
        return REDIRECT_TEAM_PROFILE + teamId;
    }

    String responseBody = response.getBody().toString();

    if (RestUtil.isError(response.getStatusCode())) {
        MyErrorResource error = objectMapper.readValue(responseBody, MyErrorResource.class);
        ExceptionState exceptionState = ExceptionState.parseExceptionState(error.getError());
        switch (exceptionState) {
        case TEAM_NOT_FOUND_EXCEPTION:
            log.warn("Edit team profile: Team {} not found", teamId);
            return REDIRECT_INDEX_PAGE;
        case FORBIDDEN_EXCEPTION:
            log.warn("Edit team profile: Profile can only be updated by team owner.");
            redirectAttributes.addFlashAttribute(MESSAGE, "Profile can only be updated by team owner.");
            return REDIRECT_TEAM_PROFILE + teamId;
        default:
            log.warn("Edit team profile: sio or deterlab adapter connection error");
            redirectAttributes.addFlashAttribute(MESSAGE, ERR_SERVER_OVERLOAD);
            return REDIRECT_TEAM_PROFILE + teamId;
        }
    }

    Team2 originalTeam = (Team2) session.getAttribute(ORIGINAL_TEAM);

    if (!originalTeam.getDescription().equals(editTeam.getDescription())) {
        redirectAttributes.addFlashAttribute("editDesc", SUCCESS);
    }

    // safer to remove
    session.removeAttribute(ORIGINAL_TEAM);
    return REDIRECT_TEAM_PROFILE + teamId;
}

From source file:sg.ncl.MainController.java

@RequestMapping(value = "/team_quota/{teamId}", method = RequestMethod.POST)
public String editTeamQuota(@PathVariable String teamId, @ModelAttribute("teamQuota") TeamQuota editTeamQuota,
        final RedirectAttributes redirectAttributes, HttpSession session) throws IOException {

    final String NUMBER_QUOTA = "#quota";
    JSONObject teamQuotaJSONObject = new JSONObject();
    teamQuotaJSONObject.put(TEAM_ID, teamId);

    // check if budget is negative or exceeding limit
    if (!editTeamQuota.getBudget().equals("")) {
        if (Double.parseDouble(editTeamQuota.getBudget()) < 0) {
            redirectAttributes.addFlashAttribute(EDIT_BUDGET, "negativeError");
            return REDIRECT_TEAM_PROFILE + teamId + NUMBER_QUOTA;
        } else if (Double.parseDouble(editTeamQuota.getBudget()) > 99999999.99) {
            redirectAttributes.addFlashAttribute(EDIT_BUDGET, "exceedingLimit");
            return REDIRECT_TEAM_PROFILE + teamId + NUMBER_QUOTA;
        }/* w w  w  .  ja  va2s  .  c o  m*/
    }

    teamQuotaJSONObject.put(QUOTA, editTeamQuota.getBudget());
    HttpEntity<String> request = createHttpEntityWithBody(teamQuotaJSONObject.toString());
    ResponseEntity response;
    try {
        response = restTemplate.exchange(properties.getQuotaByTeamId(teamId), HttpMethod.PUT, request,
                String.class);
    } catch (RestClientException e) {
        log.warn("Error connecting to sio team service for display team quota: {}", e);
        redirectAttributes.addFlashAttribute(MESSAGE, ERR_SERVER_OVERLOAD);
        return REDIRECT_TEAM_PROFILE_TEAM_ID;
    }

    String responseBody = response.getBody().toString();
    // handling exceptions from SIO
    if (RestUtil.isError(response.getStatusCode())) {
        MyErrorResource error = objectMapper.readValue(responseBody, MyErrorResource.class);
        ExceptionState exceptionState = ExceptionState.parseExceptionState(error.getError());
        switch (exceptionState) {
        case TEAM_NOT_FOUND_EXCEPTION:
            log.warn("Get team quota: Team {} not found", teamId);
            return REDIRECT_INDEX_PAGE;
        case TEAM_QUOTA_OUT_OF_RANGE_EXCEPTION:
            log.warn("Get team quota: Budget is out of range");
            return REDIRECT_TEAM_PROFILE + teamId + NUMBER_QUOTA;
        case FORBIDDEN_EXCEPTION:
            log.warn("Get team quota: Budget can only be updated by team owner.");
            redirectAttributes.addFlashAttribute(EDIT_BUDGET, "editDeny");
            return REDIRECT_TEAM_PROFILE + teamId + NUMBER_QUOTA;
        default:
            log.warn("Get team quota : sio or deterlab adapter connection error");
            redirectAttributes.addFlashAttribute(MESSAGE, ERR_SERVER_OVERLOAD);
            return REDIRECT_TEAM_PROFILE + teamId + NUMBER_QUOTA;
        }
    } else {
        log.info("Edit team quota info : {}", responseBody);
    }

    //check if new budget is different in order to display successful message to user
    String originalBudget = (String) session.getAttribute(ORIGINAL_BUDGET);
    if (!originalBudget.equals(editTeamQuota.getBudget())) {
        redirectAttributes.addFlashAttribute(EDIT_BUDGET, SUCCESS);
    }

    // safer to remove
    session.removeAttribute(ORIGINAL_BUDGET);

    return REDIRECT_TEAM_PROFILE + teamId + NUMBER_QUOTA;
}

From source file:sg.ncl.MainController.java

@PostMapping("/update_experiment/{teamId}/{expId}")
public String updateExperimentFormSubmit(@ModelAttribute("edit_experiment") Experiment2 editExperiment,
        BindingResult bindingResult, @PathVariable String teamId, @PathVariable String expId,
        RedirectAttributes redirectAttributes) throws WebServiceRuntimeException {

    // check max duration for errors
    if (bindingResult.hasErrors() || !editExperiment.getMaxDuration().toString().matches("\\d+")) {
        redirectAttributes.addFlashAttribute(MESSAGE, MAX_DURATION_ERROR);
        return REDIRECT_UPDATE_EXPERIMENT + teamId + "/" + expId;
    }//from   w ww  .j a va 2s  .  c  o m

    // get original experiment
    HttpEntity<String> request = createHttpEntityHeaderOnly();
    ResponseEntity response = restTemplate.exchange(properties.getExperiment(expId), HttpMethod.GET, request,
            String.class);
    Experiment2 experiment = extractExperiment(response.getBody().toString());

    experiment.setNsFileContent(editExperiment.getNsFileContent());
    experiment.setMaxDuration(editExperiment.getMaxDuration());

    objectMapper.registerModule(new JavaTimeModule());
    String jsonExperiment;
    try {
        jsonExperiment = objectMapper.writeValueAsString(experiment);
    } catch (JsonProcessingException e) {
        log.debug("update experiment convert to json error: {}", experiment);
        redirectAttributes.addFlashAttribute(MESSAGE, ERR_SERVER_OVERLOAD);
        return REDIRECT_UPDATE_EXPERIMENT + teamId + "/" + expId;
    }

    // identical endpoint as delete experiment but different HTTP method
    restTemplate.setErrorHandler(new MyResponseErrorHandler());
    request = createHttpEntityWithBody(jsonExperiment);
    ResponseEntity updateExperimentResponse;
    try {
        updateExperimentResponse = restTemplate.exchange(properties.getDeleteExperiment(teamId, expId),
                HttpMethod.PUT, request, String.class);
    } catch (Exception e) {
        log.warn("Error connecting to experiment service to update experiment", e.getMessage());
        redirectAttributes.addFlashAttribute(MESSAGE, ERR_SERVER_OVERLOAD);
        return REDIRECT_EXPERIMENTS;
    }

    String updateExperimentResponseBody = updateExperimentResponse.getBody().toString();

    try {
        if (RestUtil.isError(updateExperimentResponse.getStatusCode())) {
            MyErrorResource error = objectMapper.readValue(updateExperimentResponseBody, MyErrorResource.class);
            ExceptionState exceptionState = ExceptionState.parseExceptionState(error.getError());

            switch (exceptionState) {
            case NS_FILE_PARSE_EXCEPTION:
            case EXPERIMENT_MODIFY_EXCEPTION:
                log.warn("update experiment failed for Team: {}, Exp: {}", teamId, expId);
                redirectAttributes.addFlashAttribute(MESSAGE, "Error in parsing NS File");
                redirectAttributes.addFlashAttribute("exp_output", error.getMessage());
                break;
            case OBJECT_OPTIMISTIC_LOCKING_FAILURE_EXCEPTION:
                // do nothing
                log.info("update experiment database locking failure");
                break;
            default:
                // do nothing
                break;
            }
            return REDIRECT_UPDATE_EXPERIMENT + teamId + "/" + expId;
        } else {
            // everything ok
            log.info("update experiment success for Team:{}, Exp: {}", teamId, expId);
            redirectAttributes.addFlashAttribute(EXPERIMENT_MESSAGE,
                    getExperimentMessage(experiment.getName(), experiment.getTeamName())
                            + " has been modified. You may proceed to start the experiment.");
            return REDIRECT_EXPERIMENTS;
        }
    } catch (IOException e) {
        throw new WebServiceRuntimeException(e.getMessage());
    }
}

From source file:sg.ncl.MainController.java

@RequestMapping(value = "/admin/gpus/{gpu}/passwd/{userid}", method = RequestMethod.POST)
public String adminChangeGpuUserPassword(@PathVariable("gpu") Integer gpu,
        @PathVariable("userid") String userid, @RequestParam("newpasswd") String newpasswd,
        RedirectAttributes redirectAttributes, HttpSession session) throws WebServiceRuntimeException {
    if (!validateIfAdmin(session)) {
        return NO_PERMISSION_PAGE;
    }/*from  w w w  . j a v  a 2 s .  c  o m*/

    GpuProperties.Domain domain = gpuProperties.getDomains().get(gpu);
    String url = "http://" + domain.getHost() + ":" + domain.getPort() + "/users/" + userid;

    JSONObject jsonObject = new JSONObject();
    jsonObject.put("password", newpasswd);

    HttpEntity<String> request = createHttpEntityWithBodyNoAuthHeader(jsonObject.toString());
    ResponseEntity response = restTemplate.exchange(url, HttpMethod.PUT, request, String.class);
    String responseBody = response.getBody().toString();

    jsonObject = new JSONObject(responseBody);
    String message = jsonObject.getString(userid);
    if (message.contains("Failed")) {
        redirectAttributes.addFlashAttribute("message", message + " '" + userid + "'");
    } else {
        redirectAttributes.addFlashAttribute("messageSuccess", message + " '" + userid + "'");
    }

    redirectAttributes.addFlashAttribute("gpuUsersMap", getGpuUsers(gpu));
    redirectAttributes.addFlashAttribute("selectedGpu", gpu);
    return "redirect:/admin/gpus";
}

From source file:sg.ncl.MainController.java

private Dataset updateDataset(Dataset dataset, DataResource dataResource) throws IOException {
    log.info("Data resource updating... {}", dataResource);
    HttpEntity<String> request = createHttpEntityWithBody(objectMapper.writeValueAsString(dataResource));
    ResponseEntity response = restTemplate.exchange(
            properties.getResource(dataset.getId().toString(), dataResource.getId().toString()), HttpMethod.PUT,
            request, String.class);

    Dataset updatedDataset = extractDataInfo(response.getBody().toString());
    log.info("Data resource updated... {}", dataResource.getUri());
    return updatedDataset;
}

From source file:sg.ncl.MainController.java

@PostMapping("/admin/monthly/contribute")
public String adminMonthlyValidate(@Valid @ModelAttribute("project") ProjectDetails project,
        BindingResult binding, HttpSession session, Model model) throws WebServiceRuntimeException {
    if (!validateIfAdmin(session)) {
        return NO_PERMISSION_PAGE;
    }/* w  ww  .  j  a  va2s.c  o m*/

    if (binding.hasErrors()) {
        String message = buildErrorMessage(binding);
        model.addAttribute(MESSAGE, message);
        model.addAttribute(KEY_PROJECT, project);
        return ADMIN_MONTHLY_CONTRIBUTE;
    } else {
        JSONObject jsonObject = new JSONObject();
        jsonObject.put(ORGANISATION_TYPE, project.getOrganisationType());
        jsonObject.put(ORGANISATION_NAME, project.getOrganisationName());
        jsonObject.put(KEY_PROJECT_NAME, project.getProjectName());
        jsonObject.put(KEY_OWNER, project.getOwner());
        jsonObject.put(KEY_DATE_CREATED, project.getZonedDateCreated());
        jsonObject.put("education", project.isEducation());
        jsonObject.put("serviceTool", project.isServiceTool());
        jsonObject.put("supportedBy", project.getSupportedBy());
        jsonObject.put("projectUsages", new ArrayList());
        log.debug("JsonObject: {}", jsonObject);

        restTemplate.setErrorHandler(new MyResponseErrorHandler());
        HttpEntity<String> request = createHttpEntityWithBody(jsonObject.toString());
        ResponseEntity response;
        if (project.getId() == null || project.getId() == 0) {
            response = restTemplate.exchange(properties.getMonthly(), HttpMethod.POST, request, String.class);
        } else {
            response = restTemplate.exchange(properties.getMonthly() + "/" + project.getId(), HttpMethod.PUT,
                    request, String.class);
        }
        String responseBody = response.getBody().toString();

        try {
            if (RestUtil.isError(response.getStatusCode())) {
                MyErrorResource error = objectMapper.readValue(responseBody, MyErrorResource.class);
                ExceptionState exceptionState = ExceptionState.parseExceptionState(error.getError());
                switch (exceptionState) {
                case PROJECT_DETAILS_NOT_FOUND_EXCEPTION:
                    log.warn("Project not found for updating");
                    model.addAttribute(MESSAGE, "Error(s):<ul><li>project not found for editing</li></ul>");
                    break;
                case PROJECT_NAME_ALREADY_EXISTS_EXCEPTION:
                    log.warn("Project name already exists: {}", project.getProjectName());
                    model.addAttribute(MESSAGE, "Error(s):<ul<li>project name already exist</li></ul>");
                    break;
                case FORBIDDEN_EXCEPTION:
                    log.warn("Saving of project forbidden.");
                    model.addAttribute(MESSAGE, "Error(s):<ul><li>saving project forbidden</li></ul>");
                    break;
                default:
                    log.warn("Unknown error for validating project.");
                    model.addAttribute(MESSAGE,
                            "Error(s):<ul><li>unknown error for validating project</li></ul>");
                }
                model.addAttribute(KEY_PROJECT, project);
                return ADMIN_MONTHLY_CONTRIBUTE;
            } else {
                log.info("Project details saved: {}", responseBody);
            }
        } catch (IOException e) {
            log.error("adminMonthlyValidate: {}", e.toString());
            throw new WebServiceRuntimeException(e.getMessage());
        }
    }

    return "redirect:/admin/monthly";
}

From source file:sg.ncl.MainController.java

@PostMapping("/admin/monthly/{pid}/usage/contribute")
public String adminMonthlyUsageValidate(@Valid @ModelAttribute("usage") ProjectUsage usage,
        BindingResult binding, @PathVariable String pid, HttpSession session, Model model)
        throws WebServiceRuntimeException {
    if (!validateIfAdmin(session)) {
        return NO_PERMISSION_PAGE;
    }/*from  w w  w  . jav a2  s  .c o m*/

    if (binding.hasErrors()) {
        String message = buildErrorMessage(binding);
        model.addAttribute(MESSAGE, message);
        model.addAttribute(KEY_USAGE, usage);
        model.addAttribute("pid", pid);
        return ADMIN_MONTHLY_USAGE_CONTRIBUTE;
    } else {
        JSONObject jsonObject = new JSONObject();
        jsonObject.put(KEY_PROJECT_DETAILS_ID, pid);
        jsonObject.put("month", usage.getMonth());
        jsonObject.put(KEY_USAGE, usage.getUsage());
        log.debug("JsonObject: {}", jsonObject);

        restTemplate.setErrorHandler(new MyResponseErrorHandler());
        HttpEntity<String> request = createHttpEntityWithBody(jsonObject.toString());
        ResponseEntity response;
        if (usage.getId() == null || usage.getId() == 0) {
            response = restTemplate.exchange(properties.getMonthlyUsage(pid), HttpMethod.POST, request,
                    String.class);
        } else {
            response = restTemplate.exchange(properties.getMonthlyUsage(pid), HttpMethod.PUT, request,
                    String.class);
        }
        String responseBody = response.getBody().toString();

        try {
            if (RestUtil.isError(response.getStatusCode())) {
                MyErrorResource error = objectMapper.readValue(responseBody, MyErrorResource.class);
                ExceptionState exceptionState = ExceptionState.parseExceptionState(error.getError());
                checkProjectUsageExceptionState(usage, model, exceptionState);
                model.addAttribute(KEY_USAGE, usage);
                model.addAttribute("pid", pid);
                return ADMIN_MONTHLY_USAGE_CONTRIBUTE;
            } else {
                log.info("Project details saved: {}", responseBody);
            }
        } catch (IOException e) {
            log.error("adminMonthlyValidate: {}", e.toString());
            throw new WebServiceRuntimeException(e.getMessage());
        }
    }

    return "redirect:/admin/monthly/" + pid + "/usage";
}

From source file:sg.ncl.MainController.java

private String restrictTeam(final Team2 team, RedirectAttributes redirectAttributes) throws IOException {
    log.info("Restricting team {}", team.getId());

    HttpEntity<String> request = createHttpEntityHeaderOnly();
    ResponseEntity response = restTemplate.exchange(
            properties.getSioTeamsStatusUrl(team.getId(), TeamStatus.RESTRICTED), HttpMethod.PUT, request,
            String.class);
    String responseBody = response.getBody().toString();

    if (RestUtil.isError(response.getStatusCode())) {
        MyErrorResource error = objectMapper.readValue(responseBody, MyErrorResource.class);
        ExceptionState exceptionState = ExceptionState.parseExceptionState(error.getError());
        String logMessage = "Failed to restrict team {}: {}";
        handleException(team, redirectAttributes, error, exceptionState, logMessage);
        return REDIRECT_ADMIN;
    } else {// w ww . j  ava2  s  .co  m
        // good
        log.info("Team {} has been restricted", team.getId());
        redirectAttributes.addFlashAttribute(MESSAGE_SUCCESS,
                "Team status has been changed to " + TeamStatus.RESTRICTED.name());
        return REDIRECT_ADMIN;
    }
}