Search in sources :

Example 41 with ResourceNotFoundException

use of org.entando.entando.aps.system.exception.ResourceNotFoundException in project entando-core by entando.

the class DataTypeController method getDataType.

@RestAccessControl(permission = Permission.SUPERUSER)
@RequestMapping(value = "/dataTypes/{dataTypeCode}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<SimpleRestResponse<DataTypeDto>> getDataType(@PathVariable String dataTypeCode) throws JsonProcessingException {
    logger.debug("Requested data type -> {}", dataTypeCode);
    if (!this.getDataTypeValidator().existType(dataTypeCode)) {
        throw new ResourceNotFoundException(DataTypeValidator.ERRCODE_ENTITY_TYPE_DOES_NOT_EXIST, "Data Type", dataTypeCode);
    }
    DataTypeDto dto = this.getDataObjectService().getDataType(dataTypeCode);
    logger.debug("Main Response -> {}", dto);
    return new ResponseEntity<>(new SimpleRestResponse<>(dto), HttpStatus.OK);
}
Also used : ResponseEntity(org.springframework.http.ResponseEntity) ResourceNotFoundException(org.entando.entando.aps.system.exception.ResourceNotFoundException) DataTypeDto(org.entando.entando.aps.system.services.dataobject.model.DataTypeDto) RestAccessControl(org.entando.entando.web.common.annotation.RestAccessControl)

Example 42 with ResourceNotFoundException

use of org.entando.entando.aps.system.exception.ResourceNotFoundException in project entando-core by entando.

the class FileBrowserValidator method validate.

@Override
public void validate(Object target, Errors errors) {
    FileBrowserRequest request = (FileBrowserRequest) target;
    String path = request.getPath();
    if (path.endsWith("/")) {
        if (request instanceof FileBrowserFileRequest) {
            errors.rejectValue("path", ERRCODE_INVALID_PATH, new String[] { path }, "fileBrowser.filename.invalidPath");
            return;
        } else {
            path = path.substring(0, path.length() - 1);
        }
    }
    if (!path.contains("/")) {
        return;
    }
    try {
        String directory = path.substring(0, path.lastIndexOf("/"));
        if (!this.getStorageManager().exists(directory, request.isProtectedFolder())) {
            throw new ResourceNotFoundException(FileBrowserValidator.ERRCODE_RESOURCE_DOES_NOT_EXIST, "parent folder", path);
        }
        if (request instanceof FileBrowserFileRequest) {
            FileBrowserFileRequest fileRequest = (FileBrowserFileRequest) target;
            String extractedFileName = path.substring(path.lastIndexOf("/") + 1, path.length());
            if (!extractedFileName.equalsIgnoreCase(fileRequest.getFilename())) {
                errors.rejectValue("filename", ERRCODE_FILENAME_MISMATCH, new String[] { fileRequest.getFilename(), extractedFileName }, "fileBrowser.filename.body.mismatch");
                throw new ValidationConflictException((BindingResult) errors);
            }
        }
    } catch (ValidationConflictException vce) {
        throw vce;
    } catch (ResourceNotFoundException e) {
        throw e;
    } catch (Exception e) {
        logger.error("Error checking path {} , protected {} ", path, request.isProtectedFolder(), e);
        throw new RestServerError("error checking path", e);
    }
}
Also used : FileBrowserRequest(org.entando.entando.web.filebrowser.model.FileBrowserRequest) RestServerError(org.entando.entando.aps.system.exception.RestServerError) FileBrowserFileRequest(org.entando.entando.web.filebrowser.model.FileBrowserFileRequest) ResourceNotFoundException(org.entando.entando.aps.system.exception.ResourceNotFoundException) ResourceNotFoundException(org.entando.entando.aps.system.exception.ResourceNotFoundException) ValidationConflictException(org.entando.entando.web.common.exceptions.ValidationConflictException) ValidationConflictException(org.entando.entando.web.common.exceptions.ValidationConflictException)

Example 43 with ResourceNotFoundException

use of org.entando.entando.aps.system.exception.ResourceNotFoundException in project entando-core by entando.

the class GuiFragmentController method updateGuiFragment.

@RestAccessControl(permission = Permission.SUPERUSER)
@RequestMapping(value = "/{fragmentCode}", method = RequestMethod.PUT, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<SimpleRestResponse<GuiFragmentDto>> updateGuiFragment(@PathVariable String fragmentCode, @Valid @RequestBody GuiFragmentRequestBody guiFragmentRequest, BindingResult bindingResult) {
    // field validations
    if (bindingResult.hasErrors()) {
        throw new ValidationGenericException(bindingResult);
    }
    int result = this.getGuiFragmentValidator().validateBody(fragmentCode, guiFragmentRequest, bindingResult);
    if (bindingResult.hasErrors()) {
        if (404 == result) {
            throw new ResourceNotFoundException(GuiFragmentValidator.ERRCODE_FRAGMENT_DOES_NOT_EXISTS, "fragment", fragmentCode);
        } else {
            throw new ValidationGenericException(bindingResult);
        }
    }
    GuiFragmentDto fragment = this.getGuiFragmentService().updateGuiFragment(guiFragmentRequest);
    return new ResponseEntity<>(new SimpleRestResponse<>(fragment), HttpStatus.OK);
}
Also used : ResponseEntity(org.springframework.http.ResponseEntity) ResourceNotFoundException(org.entando.entando.aps.system.exception.ResourceNotFoundException) ValidationGenericException(org.entando.entando.web.common.exceptions.ValidationGenericException) GuiFragmentDto(org.entando.entando.aps.system.services.guifragment.model.GuiFragmentDto) RestAccessControl(org.entando.entando.web.common.annotation.RestAccessControl) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 44 with ResourceNotFoundException

use of org.entando.entando.aps.system.exception.ResourceNotFoundException in project entando-core by entando.

the class ProfileController method getUserProfile.

@RestAccessControl(permission = Permission.MANAGE_USER_PROFILES)
@RequestMapping(value = "/userProfiles/{username}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<SimpleRestResponse<EntityDto>> getUserProfile(@PathVariable String username) throws JsonProcessingException {
    logger.debug("Requested profile -> {}", username);
    EntityDto dto;
    if (!this.getProfileValidator().existProfile(username)) {
        if (userExists(username)) {
            // if the user exists but the profile doesn't, creates an empty profile
            IUserProfile userProfile = createNewEmptyUserProfile(username);
            dto = new EntityDto(userProfile);
        } else {
            throw new ResourceNotFoundException(EntityValidator.ERRCODE_ENTITY_DOES_NOT_EXIST, "Profile", username);
        }
    } else {
        dto = this.getUserProfileService().getUserProfile(username);
    }
    logger.debug("Main Response -> {}", dto);
    return new ResponseEntity<>(new SimpleRestResponse<>(dto), HttpStatus.OK);
}
Also used : EntityDto(org.entando.entando.aps.system.services.entity.model.EntityDto) ResponseEntity(org.springframework.http.ResponseEntity) IUserProfile(org.entando.entando.aps.system.services.userprofile.model.IUserProfile) ResourceNotFoundException(org.entando.entando.aps.system.exception.ResourceNotFoundException) RestAccessControl(org.entando.entando.web.common.annotation.RestAccessControl)

Example 45 with ResourceNotFoundException

use of org.entando.entando.aps.system.exception.ResourceNotFoundException in project entando-core by entando.

the class GuiFragmentService method updateGuiFragment.

@Override
public GuiFragmentDto updateGuiFragment(GuiFragmentRequestBody guiFragmentRequest) {
    String code = guiFragmentRequest.getCode();
    try {
        GuiFragment fragment = this.getGuiFragmentManager().getGuiFragment(code);
        if (null == fragment) {
            throw new ResourceNotFoundException(GuiFragmentValidator.ERRCODE_FRAGMENT_DOES_NOT_EXISTS, "fragment", code);
        }
        fragment.setGui(guiFragmentRequest.getGuiCode());
        this.getGuiFragmentManager().updateGuiFragment(fragment);
        return this.getDtoBuilder().convert(fragment);
    } catch (ResourceNotFoundException e) {
        throw e;
    } catch (ApsSystemException e) {
        logger.error("Error updating fragment {}", code, e);
        throw new RestServerError("error in update fragment", e);
    }
}
Also used : RestServerError(org.entando.entando.aps.system.exception.RestServerError) ApsSystemException(com.agiletec.aps.system.exception.ApsSystemException) ResourceNotFoundException(org.entando.entando.aps.system.exception.ResourceNotFoundException)

Aggregations

ResourceNotFoundException (org.entando.entando.aps.system.exception.ResourceNotFoundException)53 RestServerError (org.entando.entando.aps.system.exception.RestServerError)27 ValidationGenericException (org.entando.entando.web.common.exceptions.ValidationGenericException)20 BeanPropertyBindingResult (org.springframework.validation.BeanPropertyBindingResult)16 ApsSystemException (com.agiletec.aps.system.exception.ApsSystemException)15 IPage (com.agiletec.aps.system.services.page.IPage)9 RestAccessControl (org.entando.entando.web.common.annotation.RestAccessControl)9 Category (com.agiletec.aps.system.services.category.Category)7 PagedMetadata (org.entando.entando.web.common.model.PagedMetadata)7 ResponseEntity (org.springframework.http.ResponseEntity)7 SearcherDaoPaginatedResult (com.agiletec.aps.system.common.model.dao.SearcherDaoPaginatedResult)6 List (java.util.List)6 ArrayList (java.util.ArrayList)5 ValidationConflictException (org.entando.entando.web.common.exceptions.ValidationConflictException)5 PageDto (org.entando.entando.aps.system.services.page.model.PageDto)4 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)4 CategoryUtilizer (com.agiletec.aps.system.services.category.CategoryUtilizer)3 Group (com.agiletec.aps.system.services.group.Group)3 Widget (com.agiletec.aps.system.services.page.Widget)3 Role (com.agiletec.aps.system.services.role.Role)3