Search in sources :

Example 1 with RestApiException

use of com.salesmanager.shop.store.api.exception.RestApiException in project shopizer by shopizer-ecommerce.

the class MerchantStoreApi method addLogo.

@ResponseStatus(HttpStatus.CREATED)
@PostMapping(value = { "/private/store/{code}/marketing/logo" })
@ApiOperation(httpMethod = "POST", value = "Add store logo", notes = "")
public void addLogo(@PathVariable String code, @RequestParam("file") MultipartFile uploadfile, HttpServletRequest request) {
    // user doing action must be attached to the store being modified
    String userName = getUserFromRequest(request);
    validateUserPermission(userName, code);
    if (uploadfile.isEmpty()) {
        throw new RestApiException("Upload file is empty");
    }
    InputContentFile cmsContentImage = createInputContentFile(uploadfile);
    storeFacade.addStoreLogo(code, cmsContentImage);
}
Also used : InputContentFile(com.salesmanager.core.model.content.InputContentFile) RestApiException(com.salesmanager.shop.store.api.exception.RestApiException) PostMapping(org.springframework.web.bind.annotation.PostMapping) ResponseStatus(org.springframework.web.bind.annotation.ResponseStatus) ApiOperation(io.swagger.annotations.ApiOperation)

Example 2 with RestApiException

use of com.salesmanager.shop.store.api.exception.RestApiException in project shopizer by shopizer-ecommerce.

the class MerchantStoreApi method createInputContentFile.

private InputContentFile createInputContentFile(MultipartFile image) {
    InputContentFile cmsContentImage = null;
    try {
        InputStream input = new ByteArrayInputStream(image.getBytes());
        cmsContentImage = new InputContentFile();
        cmsContentImage.setFileName(image.getOriginalFilename());
        cmsContentImage.setMimeType(image.getContentType());
        cmsContentImage.setFileContentType(FileContentType.LOGO);
        cmsContentImage.setFile(input);
    } catch (IOException ioe) {
        throw new RestApiException(ioe);
    }
    return cmsContentImage;
}
Also used : InputContentFile(com.salesmanager.core.model.content.InputContentFile) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) IOException(java.io.IOException) RestApiException(com.salesmanager.shop.store.api.exception.RestApiException)

Example 3 with RestApiException

use of com.salesmanager.shop.store.api.exception.RestApiException in project shopizer by shopizer-ecommerce.

the class SearchToolsApi method contact.

@PostMapping("/private/system/search/index")
@ApiOperation(httpMethod = "POST", value = "Indexes all products", notes = "", produces = "application/json")
@ApiImplicitParams({ @ApiImplicitParam(name = "store", dataType = "String", defaultValue = "DEFAULT"), @ApiImplicitParam(name = "lang", dataType = "String", defaultValue = "en") })
public ResponseEntity<Void> contact(@ApiIgnore MerchantStore merchantStore, @ApiIgnore Language language, HttpServletRequest request) {
    // superadmin, admin and admin_catalogue
    String authenticatedUser = userFacade.authenticatedUser();
    if (authenticatedUser == null) {
        throw new UnauthorizedException();
    }
    Principal principal = request.getUserPrincipal();
    String userName = principal.getName();
    ReadableUser user = userFacade.findByUserName(userName, null, language);
    if (user == null) {
        throw new UnauthorizedException();
    }
    userFacade.authorizedGroup(authenticatedUser, Stream.of(Constants.GROUP_SUPERADMIN, Constants.GROUP_ADMIN, Constants.GROUP_ADMIN_CATALOGUE, Constants.GROUP_ADMIN_RETAIL).collect(Collectors.toList()));
    if (!user.getMerchant().equals(merchantStore.getCode())) {
        throw new UnauthorizedException();
    }
    try {
        searchFacade.indexAllData(merchantStore);
    } catch (Exception e) {
        throw new RestApiException("Exception while indexing store data", e);
    }
    return new ResponseEntity<Void>(HttpStatus.CREATED);
}
Also used : ResponseEntity(org.springframework.http.ResponseEntity) ReadableUser(com.salesmanager.shop.model.user.ReadableUser) UnauthorizedException(com.salesmanager.shop.store.api.exception.UnauthorizedException) RestApiException(com.salesmanager.shop.store.api.exception.RestApiException) Principal(java.security.Principal) RestApiException(com.salesmanager.shop.store.api.exception.RestApiException) UnauthorizedException(com.salesmanager.shop.store.api.exception.UnauthorizedException) PostMapping(org.springframework.web.bind.annotation.PostMapping) ApiImplicitParams(io.swagger.annotations.ApiImplicitParams) ApiOperation(io.swagger.annotations.ApiOperation)

Aggregations

RestApiException (com.salesmanager.shop.store.api.exception.RestApiException)3 InputContentFile (com.salesmanager.core.model.content.InputContentFile)2 ApiOperation (io.swagger.annotations.ApiOperation)2 PostMapping (org.springframework.web.bind.annotation.PostMapping)2 ReadableUser (com.salesmanager.shop.model.user.ReadableUser)1 UnauthorizedException (com.salesmanager.shop.store.api.exception.UnauthorizedException)1 ApiImplicitParams (io.swagger.annotations.ApiImplicitParams)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 Principal (java.security.Principal)1 ResponseEntity (org.springframework.http.ResponseEntity)1 ResponseStatus (org.springframework.web.bind.annotation.ResponseStatus)1