private List<DeviceVO> getDeviceList(List<String> deviceIds, HivePrincipal principal) { return deviceDao.getDeviceList(deviceIds, principal); } }
public Optional<ConfigurationVO> findByName(String name) { return configurationDao.getByName(name); }
@Transactional public List<PluginVO> findByStatus(PluginStatus status) { return pluginDao.findByStatus(status); }
private Optional<NetworkVO> findNetworkByIdOrName(NetworkVO network) { return ofNullable(network.getId()) .map(id -> ofNullable(networkDao.find(id))) .orElseGet(() -> networkDao.findFirstByName(network.getName())); } }
public boolean isNetworkExists(Long networkId) { return ofNullable(networkId) .map(id -> networkDao.find(id) != null) .orElse(false); }
/** * Retrieves user by id (no networks fetched in this case) * * @param id user id * @return User model without networks, or null if there is no such user */ @Transactional(propagation = Propagation.NOT_SUPPORTED) public UserVO findById(@NotNull long id) { return userDao.find(id); }
/** * Retrieves user with device types by id, if there is no device types user has * access to device types will be represented by empty set * * @param id user id * @return User model with device types, or null, if there is no such user */ @Transactional(propagation = Propagation.NOT_SUPPORTED) public UserWithDeviceTypeVO findUserWithDeviceType(@NotNull long id) { return userDao.getWithDeviceTypeById(id); }
private Optional<DeviceTypeVO> findDeviceTypeByIdOrName(DeviceTypeVO deviceType) { return ofNullable(deviceType.getId()) .map(id -> ofNullable(deviceTypeDao.find(id))) .orElseGet(() -> deviceTypeDao.findFirstByName(deviceType.getName())); } }
private UserVO updateStatisticOnSuccessfulLogin(UserVO user, long loginTimeout) { boolean update = false; if (user.getLoginAttempts() != 0) { update = true; user.setLoginAttempts(0); } if (user.getLastLogin() == null || timestampService.getTimestamp() - user.getLastLogin().getTime() > loginTimeout) { update = true; user.setLastLogin(timestampService.getDate()); } return update ? userDao.merge(user) : user; }
@Transactional public boolean delete(long id) { int result = pluginDao.deleteById(id); return result > 0; }
/** * Deletes user by id. deletion is cascade * * @param id user id * @return true in case of success, false otherwise */ @Transactional(propagation = Propagation.REQUIRED) public boolean deleteUser(long id) { int result = userDao.deleteById(id); return result > 0; }
@Transactional public PluginVO create(PluginVO pluginVO) { pluginDao.persist(pluginVO); return pluginVO; }
@Transactional public PluginVO findByTopic(String topicName) { try { return pluginDao.findByTopic(topicName); } catch (Exception e) { return null; } }
@Transactional public PluginVO update(PluginVO pluginVO) { return pluginDao.merge(pluginVO); }
@Transactional public PluginVO findByName(String pluginName) { return pluginDao.findByName(pluginName); }
public boolean isDeviceTypeExists(Long deviceTypeId) { return ofNullable(deviceTypeId) .map(id -> deviceTypeDao.find(id) != null) .orElse(false); }
/** * Retrieves user with networks by id, if there is no networks user has * access to networks will be represented by empty set * * @param id user id * @return User model with networks, or null, if there is no such user */ @Transactional(propagation = Propagation.NOT_SUPPORTED) public UserWithNetworkVO findUserWithNetworks(@NotNull long id) { return userDao.getWithNetworksById(id); }
@Transactional(propagation = Propagation.SUPPORTS) public boolean hasAccessToNetwork(UserVO user, NetworkVO network) { if (!user.isAdmin()) { long count = userDao.hasAccessToNetwork(user, network); return count > 0; } return true; }
@Transactional(propagation = Propagation.SUPPORTS) public boolean hasAccessToDevice(UserVO user, String deviceId) { if (!user.isAdmin()) { long count = userDao.hasAccessToDevice(user, deviceId); return count > 0; } return true; }
private Optional<NetworkVO> findNetworkByIdOrName(NetworkVO network) { return ofNullable(network.getId()) .map(id -> ofNullable(networkDao.find(id))) .orElseGet(() -> networkDao.findFirstByName(network.getName())); } }