Search in sources :

Example 6 with BadRequestAlertException

use of com.arnaugarcia.uplace.web.rest.errors.BadRequestAlertException in project uplace.es by Uplace.

the class RealEstateResource method createRealEstate.

/**
 * POST  /real-estates : Create a new realEstate.
 *
 * @param realEstate the realEstate to create
 * @return the ResponseEntity with status 201 (Created) and with body the new realEstate, or with status 400 (Bad Request) if the realEstate has already an ID
 * @throws URISyntaxException if the Location URI syntax is incorrect
 */
@PostMapping("/real-estates")
@Timed
public ResponseEntity<RealEstate> createRealEstate(@Valid @RequestBody RealEstate realEstate) throws URISyntaxException {
    log.debug("REST request to save RealEstate : {}", realEstate);
    if (realEstate.getId() != null) {
        throw new BadRequestAlertException("A new realEstate cannot already have an ID", ENTITY_NAME, "idexists");
    }
    RealEstate result = realEstateService.save(realEstate);
    return ResponseEntity.created(new URI("/api/real-estates/" + result.getId())).headers(HeaderUtil.createEntityCreationAlert(ENTITY_NAME, result.getId().toString())).body(result);
}
Also used : BadRequestAlertException(com.arnaugarcia.uplace.web.rest.errors.BadRequestAlertException) RealEstate(com.arnaugarcia.uplace.domain.RealEstate) URI(java.net.URI) Timed(com.codahale.metrics.annotation.Timed)

Example 7 with BadRequestAlertException

use of com.arnaugarcia.uplace.web.rest.errors.BadRequestAlertException in project uplace.es by Uplace.

the class NotificationService method updates.

@Transactional()
public List<Notification> updates(List<Notification> notifications) {
    User user = userService.getUserWithAuthoritiesByLogin(SecurityUtils.getCurrentUserLogin().get()).get();
    // if there are a notification that does not belongs to the user and isn't admin... error
    notifications.forEach(notification -> {
        if (!notification.getUser().equals(user) && !SecurityUtils.isCurrentUserInRole(AuthoritiesConstants.ADMIN)) {
            throw new BadRequestAlertException("This notification doesn't belongs to you :)", ENTITY_NOTIFICATION, ErrorConstants.ERR_BAD_USER);
        }
    });
    return notificationRepository.save(notifications);
}
Also used : BadRequestAlertException(com.arnaugarcia.uplace.web.rest.errors.BadRequestAlertException) User(com.arnaugarcia.uplace.domain.User) Transactional(org.springframework.transaction.annotation.Transactional)

Example 8 with BadRequestAlertException

use of com.arnaugarcia.uplace.web.rest.errors.BadRequestAlertException in project uplace.es by Uplace.

the class NotificationService method markAs.

@Transactional(readOnly = true)
public List<Notification> markAs(List<Notification> notifications, Boolean status) {
    User user = userService.getUserWithAuthoritiesByLogin(SecurityUtils.getCurrentUserLogin().get()).get();
    notifications.forEach(notification -> {
        if (!notification.getUser().equals(user) && !SecurityUtils.isCurrentUserInRole(AuthoritiesConstants.ADMIN)) {
            throw new BadRequestAlertException("This notification doesn't belongs to you :)", ENTITY_NOTIFICATION, ErrorConstants.ERR_BAD_USER);
        } else {
            notification.setRead(status);
        }
    });
    return notificationRepository.save(notifications);
}
Also used : BadRequestAlertException(com.arnaugarcia.uplace.web.rest.errors.BadRequestAlertException) User(com.arnaugarcia.uplace.domain.User) Transactional(org.springframework.transaction.annotation.Transactional)

Example 9 with BadRequestAlertException

use of com.arnaugarcia.uplace.web.rest.errors.BadRequestAlertException in project uplace.es by Uplace.

the class NotificationService method findOneByType.

/**
 * Get one notification by id.
 *
 * @param id the id of the entity
 * @return the entity
 */
@Transactional(readOnly = true)
public Notification findOneByType(NotificationType notificationType, Long id) {
    log.debug("Request to get Notification : {}", id);
    Notification notification = null;
    switch(notificationType) {
        case NOTIFICATION:
            notification = notificationRepository.findOneByType(NotificationType.NOTIFICATION, id);
            break;
        case REQUEST:
            notification = notificationRepository.findOneByType(NotificationType.REQUEST, id);
            break;
        case ALERT:
            throw new BadRequestAlertException("Not yet implemented", ENTITY_REQUEST, ErrorConstants.NOT_IMPLEMENTED);
    }
    User user = userService.getUserWithAuthoritiesByLogin(SecurityUtils.getCurrentUserLogin().get()).get();
    if (notification == null || !notification.getType().equals(NotificationType.NOTIFICATION)) {
        throw new BadRequestAlertException("No notification was found with this ID", ENTITY_NOTIFICATION, ErrorConstants.ERR_BAD_ID);
    }
    // If the notification.user does not match and isn't admin... error
    if (!notification.getUser().equals(user) && !SecurityUtils.isCurrentUserInRole(AuthoritiesConstants.ADMIN)) {
        throw new BadRequestAlertException("This notification doesn't belongs to you :)", ENTITY_NOTIFICATION, ErrorConstants.ERR_BAD_USER);
    }
    return notification;
}
Also used : BadRequestAlertException(com.arnaugarcia.uplace.web.rest.errors.BadRequestAlertException) User(com.arnaugarcia.uplace.domain.User) Notification(com.arnaugarcia.uplace.domain.Notification) Transactional(org.springframework.transaction.annotation.Transactional)

Example 10 with BadRequestAlertException

use of com.arnaugarcia.uplace.web.rest.errors.BadRequestAlertException in project uplace.es by Uplace.

the class NotificationService method deletes.

public void deletes(List<Notification> notificationList) {
    log.debug("Request to delete a list of Notification : {}", notificationList.size());
    // TODO: Check if the notification exists and is a notification
    User user = userService.getUserWithAuthoritiesByLogin(SecurityUtils.getCurrentUserLogin().get()).get();
    // Checks if the user is the correct user
    notificationList.forEach(notification -> {
        if (!notification.getUser().equals(user) && !SecurityUtils.isCurrentUserInRole(AuthoritiesConstants.ADMIN)) {
            throw new BadRequestAlertException("This notification doesn't belongs to you :)", ENTITY_NOTIFICATION, ErrorConstants.ERR_BAD_USER);
        }
    });
    notificationRepository.delete(notificationList);
}
Also used : BadRequestAlertException(com.arnaugarcia.uplace.web.rest.errors.BadRequestAlertException) User(com.arnaugarcia.uplace.domain.User)

Aggregations

BadRequestAlertException (com.arnaugarcia.uplace.web.rest.errors.BadRequestAlertException)14 Timed (com.codahale.metrics.annotation.Timed)9 URI (java.net.URI)8 User (com.arnaugarcia.uplace.domain.User)6 Notification (com.arnaugarcia.uplace.domain.Notification)4 Transactional (org.springframework.transaction.annotation.Transactional)3 Agent (com.arnaugarcia.uplace.domain.Agent)1 Company (com.arnaugarcia.uplace.domain.Company)1 Location (com.arnaugarcia.uplace.domain.Location)1 Photo (com.arnaugarcia.uplace.domain.Photo)1 RealEstate (com.arnaugarcia.uplace.domain.RealEstate)1 LocationDTO (com.arnaugarcia.uplace.service.dto.LocationDTO)1 EmailAlreadyUsedException (com.arnaugarcia.uplace.web.rest.errors.EmailAlreadyUsedException)1 LoginAlreadyUsedException (com.arnaugarcia.uplace.web.rest.errors.LoginAlreadyUsedException)1 Secured (org.springframework.security.access.annotation.Secured)1