Exemplo n.º 1
0
  @Override
  @Transactional
  public TestingLabDTO create(TestingLabDTO dto)
      throws EntityCreationException, EntityRetrievalException {

    TestingLabEntity entity = null;
    try {
      if (dto.getId() != null) {
        entity = this.getEntityById(dto.getId());
      }
    } catch (EntityRetrievalException e) {
      throw new EntityCreationException(e);
    }

    if (entity != null) {
      throw new EntityCreationException("An entity with this ID already exists.");
    } else {
      entity = new TestingLabEntity();

      if (dto.getAddress() != null) {
        entity.setAddress(addressDao.mergeAddress(dto.getAddress()));
      }

      entity.setName(dto.getName());
      entity.setWebsite(dto.getWebsite());
      entity.setAccredidationNumber(dto.getAccredidationNumber());
      entity.setTestingLabCode(dto.getTestingLabCode());

      if (dto.getDeleted() != null) {
        entity.setDeleted(dto.getDeleted());
      } else {
        entity.setDeleted(false);
      }

      if (dto.getLastModifiedUser() != null) {
        entity.setLastModifiedUser(dto.getLastModifiedUser());
      } else {
        entity.setLastModifiedUser(Util.getCurrentUser().getId());
      }

      if (dto.getLastModifiedDate() != null) {
        entity.setLastModifiedDate(dto.getLastModifiedDate());
      } else {
        entity.setLastModifiedDate(new Date());
      }

      if (dto.getCreationDate() != null) {
        entity.setCreationDate(dto.getCreationDate());
      } else {
        entity.setCreationDate(new Date());
      }

      create(entity);
      return new TestingLabDTO(entity);
    }
  }
Exemplo n.º 2
0
  @Override
  @Transactional
  public TestingLabDTO update(TestingLabDTO dto) throws EntityRetrievalException {
    TestingLabEntity entity = this.getEntityById(dto.getId());

    if (entity == null) {
      throw new EntityRetrievalException("Entity with id " + dto.getId() + " does not exist");
    }

    if (dto.getAddress() != null) {
      try {
        entity.setAddress(addressDao.mergeAddress(dto.getAddress()));
      } catch (EntityCreationException ex) {
        logger.error("Could not create new address in the database.", ex);
        entity.setAddress(null);
      }
    } else {
      entity.setAddress(null);
    }

    entity.setWebsite(dto.getWebsite());
    entity.setAccredidationNumber(dto.getAccredidationNumber());

    if (dto.getName() != null) {
      entity.setName(dto.getName());
    }

    if (dto.getTestingLabCode() != null) {
      entity.setTestingLabCode(dto.getTestingLabCode());
    }

    if (dto.getDeleted() != null) {
      entity.setDeleted(dto.getDeleted());
    }

    if (dto.getLastModifiedUser() != null) {
      entity.setLastModifiedUser(dto.getLastModifiedUser());
    } else {
      entity.setLastModifiedUser(Util.getCurrentUser().getId());
    }

    if (dto.getLastModifiedDate() != null) {
      entity.setLastModifiedDate(dto.getLastModifiedDate());
    } else {
      entity.setLastModifiedDate(new Date());
    }

    update(entity);
    return new TestingLabDTO(entity);
  }