Search in sources :

Example 1 with EntityDto

use of org.entando.entando.aps.system.services.entity.model.EntityDto in project entando-core by entando.

the class ProfileController method addUserProfile.

@RestAccessControl(permission = Permission.MANAGE_USER_PROFILES)
@RequestMapping(value = "/userProfiles", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<SimpleRestResponse<EntityDto>> addUserProfile(@Valid @RequestBody EntityDto bodyRequest, BindingResult bindingResult) {
    logger.debug("Add new user profile -> {}", bodyRequest);
    if (bindingResult.hasErrors()) {
        throw new ValidationGenericException(bindingResult);
    }
    this.getProfileValidator().validate(bodyRequest, bindingResult);
    if (bindingResult.hasErrors()) {
        throw new ValidationGenericException(bindingResult);
    }
    EntityDto response = this.getUserProfileService().addUserProfile(bodyRequest, bindingResult);
    if (bindingResult.hasErrors()) {
        throw new ValidationGenericException(bindingResult);
    }
    return new ResponseEntity<>(new SimpleRestResponse<>(response), HttpStatus.OK);
}
Also used : EntityDto(org.entando.entando.aps.system.services.entity.model.EntityDto) ResponseEntity(org.springframework.http.ResponseEntity) ValidationGenericException(org.entando.entando.web.common.exceptions.ValidationGenericException) RestAccessControl(org.entando.entando.web.common.annotation.RestAccessControl)

Example 2 with EntityDto

use of org.entando.entando.aps.system.services.entity.model.EntityDto in project entando-core by entando.

the class ProfileController method updateUserProfile.

@RestAccessControl(permission = Permission.MANAGE_USER_PROFILES)
@RequestMapping(value = "/userProfiles/{username}", method = RequestMethod.PUT, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<SimpleRestResponse<EntityDto>> updateUserProfile(@PathVariable String username, @Valid @RequestBody EntityDto bodyRequest, BindingResult bindingResult) {
    logger.debug("Update user profile -> {}", bodyRequest);
    if (bindingResult.hasErrors()) {
        throw new ValidationGenericException(bindingResult);
    }
    this.getProfileValidator().validateBodyName(username, bodyRequest, bindingResult);
    EntityDto response = this.getUserProfileService().updateUserProfile(bodyRequest, bindingResult);
    if (bindingResult.hasErrors()) {
        throw new ValidationGenericException(bindingResult);
    }
    return new ResponseEntity<>(new SimpleRestResponse<>(response), HttpStatus.OK);
}
Also used : EntityDto(org.entando.entando.aps.system.services.entity.model.EntityDto) ResponseEntity(org.springframework.http.ResponseEntity) ValidationGenericException(org.entando.entando.web.common.exceptions.ValidationGenericException) RestAccessControl(org.entando.entando.web.common.annotation.RestAccessControl)

Example 3 with EntityDto

use of org.entando.entando.aps.system.services.entity.model.EntityDto 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)

Aggregations

EntityDto (org.entando.entando.aps.system.services.entity.model.EntityDto)3 RestAccessControl (org.entando.entando.web.common.annotation.RestAccessControl)3 ResponseEntity (org.springframework.http.ResponseEntity)3 ValidationGenericException (org.entando.entando.web.common.exceptions.ValidationGenericException)2 ResourceNotFoundException (org.entando.entando.aps.system.exception.ResourceNotFoundException)1 IUserProfile (org.entando.entando.aps.system.services.userprofile.model.IUserProfile)1