private Optional<DeviceTypeVO> findDeviceTypeByIdOrName(DeviceTypeVO deviceType) { return ofNullable(deviceType.getId()) .map(id -> ofNullable(deviceTypeDao.find(id))) .orElseGet(() -> deviceTypeDao.findFirstByName(deviceType.getName())); } }
@Transactional public DeviceTypeVO create(DeviceTypeVO newDeviceType) { hiveValidator.validate(newDeviceType); logger.debug("Creating device type {}", newDeviceType); if (newDeviceType.getId() != null) { logger.error("Can't create device type entity with id={} specified", newDeviceType.getId()); throw new IllegalParametersException(Messages.ID_NOT_ALLOWED); } List<DeviceTypeVO> existing = deviceTypeDao.findByName(newDeviceType.getName()); if (!existing.isEmpty()) { logger.error("Device type with name {} already exists", newDeviceType.getName()); throw new ActionNotAllowedException(Messages.DUPLICATE_DEVICE_TYPE); } deviceTypeDao.persist(newDeviceType); logger.info("Entity {} created successfully", newDeviceType); return newDeviceType; }
public DeviceTypeWithUsersAndDevicesVO(DeviceTypeVO vo) { setId(vo.getId()); setName(vo.getName()); setDescription(vo.getDescription()); setEntityVersion(vo.getEntityVersion()); }
@Override public DeviceTypeVO merge(DeviceTypeVO existing) { DeviceType deviceType = find(DeviceType.class, existing.getId()); deviceType.setName(existing.getName()); deviceType.setDescription(existing.getDescription()); deviceType.setEntityVersion(existing.getEntityVersion()); super.merge(deviceType); return existing; }
public static DeviceType convert(DeviceTypeVO vo) { if (vo != null) { DeviceType deviceType = new DeviceType(); deviceType.setId(vo.getId()); deviceType.setName(vo.getName()); deviceType.setDescription(vo.getDescription()); deviceType.setEntityVersion(vo.getEntityVersion()); return deviceType; } return null; } }