private Long getCreatorId(String topic, UserVO user) { if (topic.equals("*")) { return user.isAdmin() ? user.getId() : null; } PluginVO pluginVO = pluginService.findByTopic(topic); return Optional.ofNullable(pluginVO) .map(plugin -> plugin.getUserId()) .orElse(null); }
private PluginVO getPluginVO(String topicName, AsyncResponse asyncResponse, HivePrincipal principal, UserVO user) { PluginVO pluginVO; if (principal.getPlugin() != null) { pluginVO = principal.getPlugin(); } else { pluginVO = pluginService.findByTopic(topicName); if (pluginVO == null) { if (user.isAdmin()) { asyncResponse.resume(ResponseFactory.response(NOT_FOUND, new ErrorResponse(NOT_FOUND.getStatusCode(), PLUGIN_NOT_FOUND))); } else { asyncResponse.resume(ResponseFactory.response(FORBIDDEN, new ErrorResponse(FORBIDDEN.getStatusCode(), NO_ACCESS_TO_PLUGIN))); } } else if (!user.isAdmin() && pluginVO.getUserId() != null && !pluginVO.getUserId().equals(user.getId())) { asyncResponse.resume(ResponseFactory.response(FORBIDDEN, new ErrorResponse(FORBIDDEN.getStatusCode(), NO_ACCESS_TO_PLUGIN))); } } return pluginVO; } }
UserWithNetworkVO userWithNetworksVO = userService.findUserWithNetworks(existingPlugin.getUserId()); .map(NetworkVO::getId).collect(Collectors.toSet())); UserWithDeviceTypeVO userWithDeviceTypeVO = userService.findUserWithDeviceType(existingPlugin.getUserId()); if (!userWithDeviceTypeVO.getAllDeviceTypesAvailable()) { principal.setAllDeviceTypesAvailable(false);
public static Plugin convertToEntity(PluginVO vo) { Plugin entity = null; if (vo != null) { entity = new Plugin(); entity.setId(vo.getId()); entity.setName(vo.getName()); entity.setDescription(vo.getDescription()); entity.setTopicName(vo.getTopicName()); entity.setFilter(vo.getFilter()); entity.setStatus(vo.getStatus()); entity.setSubscriptionId(vo.getSubscriptionId()); entity.setUserId(vo.getUserId()); entity.setParameters(vo.getParameters()); } return entity; } }