Search in sources :

Example 1 with Result

use of org.craftercms.studio.model.rest.Result in project studio by craftercms.

the class SitesController method createSite.

@PostMapping("/create_site_from_marketplace")
public ResponseBody createSite(@Valid @RequestBody CreateSiteRequest request) throws RemoteRepositoryNotFoundException, InvalidRemoteRepositoryException, ServiceLayerException, InvalidRemoteRepositoryCredentialsException, InvalidRemoteUrlException, RemoteRepositoryNotBareException {
    marketplaceService.createSite(request);
    Result result = new Result();
    result.setResponse(ApiResponse.CREATED);
    ResponseBody response = new ResponseBody();
    response.setResult(result);
    return response;
}
Also used : Result(org.craftercms.studio.model.rest.Result) ResponseBody(org.craftercms.studio.model.rest.ResponseBody) PostMapping(org.springframework.web.bind.annotation.PostMapping)

Example 2 with Result

use of org.craftercms.studio.model.rest.Result in project studio by craftercms.

the class UsersController method resetPassword.

@PostMapping(PATH_PARAM_ID + RESET_PASSWORD)
public ResponseBody resetPassword(@PathVariable(REQUEST_PARAM_ID) String userId, @RequestBody ResetPasswordRequest resetPasswordRequest) throws UserNotFoundException, UserExternallyManagedException, ServiceLayerException {
    userService.resetPassword(resetPasswordRequest.getUsername(), resetPasswordRequest.getNewPassword());
    ResponseBody responseBody = new ResponseBody();
    Result result = new Result();
    result.setResponse(OK);
    responseBody.setResult(result);
    return responseBody;
}
Also used : ResponseBody(org.craftercms.studio.model.rest.ResponseBody) Result(org.craftercms.studio.model.rest.Result) PostMapping(org.springframework.web.bind.annotation.PostMapping)

Example 3 with Result

use of org.craftercms.studio.model.rest.Result in project studio by craftercms.

the class UsersController method validateToken.

@GetMapping(value = VALIDATE_TOKEN, produces = APPLICATION_JSON_VALUE)
public ResponseBody validateToken(HttpServletResponse response, @RequestParam(value = REQUEST_PARAM_TOKEN, required = true) String token) throws UserNotFoundException, UserExternallyManagedException, ServiceLayerException {
    int delay = studioConfiguration.getProperty(SECURITY_SET_PASSWORD_DELAY, Integer.class);
    try {
        TimeUnit.SECONDS.sleep(delay);
    } catch (InterruptedException e) {
        logger.debug("Interrupted while delaying request by " + delay + " seconds.", e);
    }
    boolean valid = userService.validateToken(token);
    ResponseBody responseBody = new ResponseBody();
    Result result = new Result();
    if (valid) {
        result.setResponse(OK);
    } else {
        result.setResponse(UNAUTHORIZED);
        response.setStatus(HttpStatus.UNAUTHORIZED.value());
    }
    responseBody.setResult(result);
    return responseBody;
}
Also used : ResponseBody(org.craftercms.studio.model.rest.ResponseBody) Result(org.craftercms.studio.model.rest.Result) GetMapping(org.springframework.web.bind.annotation.GetMapping)

Example 4 with Result

use of org.craftercms.studio.model.rest.Result in project studio by craftercms.

the class ConfigurationController method writeConfiguration.

@PostMapping("/write_configuration")
public ResponseBody writeConfiguration(@RequestBody WriteConfigurationRequest wcRequest) throws ServiceLayerException {
    InputStream is = IOUtils.toInputStream(wcRequest.getContent());
    String siteId = wcRequest.getSiteId();
    if (StringUtils.equals(siteId, studioConfiguration.getProperty(CONFIGURATION_GLOBAL_SYSTEM_SITE))) {
        configurationService.writeGlobalConfiguration(wcRequest.getPath(), is);
    } else {
        configurationService.writeConfiguration(siteId, wcRequest.getModule(), wcRequest.getPath(), wcRequest.getEnvironment(), is);
    }
    ResponseBody responseBody = new ResponseBody();
    Result result = new Result();
    result.setResponse(OK);
    responseBody.setResult(result);
    return responseBody;
}
Also used : InputStream(java.io.InputStream) ResponseBody(org.craftercms.studio.model.rest.ResponseBody) Result(org.craftercms.studio.model.rest.Result) PostMapping(org.springframework.web.bind.annotation.PostMapping)

Example 5 with Result

use of org.craftercms.studio.model.rest.Result in project studio by craftercms.

the class RepositoryManagementController method removeRemote.

@PostMapping(REMOVE_REMOTE)
public ResponseBody removeRemote(HttpServletResponse response, @RequestBody RemoveRemoteRequest removeRemoteRequest) throws CryptoException, SiteNotFoundException, RemoteNotRemovableException {
    if (!siteService.exists(removeRemoteRequest.getSiteId())) {
        throw new SiteNotFoundException(removeRemoteRequest.getSiteId());
    }
    boolean res = repositoryManagementService.removeRemote(removeRemoteRequest.getSiteId(), removeRemoteRequest.getRemoteName());
    ResponseBody responseBody = new ResponseBody();
    Result result = new Result();
    if (res) {
        result.setResponse(OK);
    } else {
        response.setStatus(HttpStatus.INTERNAL_SERVER_ERROR.value());
        result.setResponse(REMOVE_REMOTE_FAILED);
    }
    responseBody.setResult(result);
    return responseBody;
}
Also used : SiteNotFoundException(org.craftercms.studio.api.v1.exception.SiteNotFoundException) ResponseBody(org.craftercms.studio.model.rest.ResponseBody) Result(org.craftercms.studio.model.rest.Result) PostMapping(org.springframework.web.bind.annotation.PostMapping)

Aggregations

ResponseBody (org.craftercms.studio.model.rest.ResponseBody)18 Result (org.craftercms.studio.model.rest.Result)18 PostMapping (org.springframework.web.bind.annotation.PostMapping)12 SiteNotFoundException (org.craftercms.studio.api.v1.exception.SiteNotFoundException)8 DeleteMapping (org.springframework.web.bind.annotation.DeleteMapping)4 InputStream (java.io.InputStream)1 PullFromRemoteConflictException (org.craftercms.studio.api.v2.exception.PullFromRemoteConflictException)1 GetMapping (org.springframework.web.bind.annotation.GetMapping)1 ResponseStatus (org.springframework.web.bind.annotation.ResponseStatus)1