@Test public void shouldDeletePortPropertiesWhenDeletingSwitch() throws SwitchNotFoundException { Switch sw = Switch.builder().switchId(TEST_SWITCH_ID).status(SwitchStatus.ACTIVE).build(); switchRepository.add(sw); PortProperties portProperties = PortProperties.builder().switchObj(sw).port(7).discoveryEnabled(false).build(); portPropertiesRepository.add(portProperties); switchOperationsService.deleteSwitch(TEST_SWITCH_ID, false); assertFalse(switchRepository.findById(TEST_SWITCH_ID).isPresent()); assertTrue(portPropertiesRepository.findAll().isEmpty()); }
public boolean deleteSwitch(SwitchId switchId, boolean force) throws SwitchNotFoundException { transactionManager.doInTransaction(() -> { Switch sw = switchRepository.findById(switchId) .orElseThrow(() -> new SwitchNotFoundException(switchId)); switchPropertiesRepository.findBySwitchId(sw.getSwitchId()) .ifPresent(sp -> switchPropertiesRepository.remove(sp)); portPropertiesRepository.getAllBySwitchId(sw.getSwitchId()) .forEach(portPropertiesRepository::remove); if (force) { switchRepository.remove(sw); } else { switchRepository.removeIfNoDependant(sw); } }); return !switchRepository.exists(switchId); }
SwitchOperationsService implements ILinkOperationsServiceCarrier { public boolean deleteSwitch(SwitchId switchId, boolean force) throws SwitchNotFoundException { transactionManager.doInTransaction(() -> { Switch sw = switchRepository.findById(switchId) .orElseThrow(() -> new SwitchNotFoundException(switchId)); switchPropertiesRepository.findBySwitchId(sw.getSwitchId()) .ifPresent(sp -> switchPropertiesRepository.remove(sp)); portPropertiesRepository.getAllBySwitchId(sw.getSwitchId()) .forEach(portPropertiesRepository::remove); if (force) { switchRepository.remove(sw); } else { switchRepository.removeIfNoDependant(sw); } }); return !switchRepository.exists(switchId); } }
SwitchOperationsService implements ILinkOperationsServiceCarrier { public boolean deleteSwitch(SwitchId switchId, boolean force) throws SwitchNotFoundException { transactionManager.doInTransaction(() -> { Switch sw = switchRepository.findById(switchId) .orElseThrow(() -> new SwitchNotFoundException(switchId)); switchPropertiesRepository.findBySwitchId(sw.getSwitchId()) .ifPresent(sp -> switchPropertiesRepository.remove(sp)); portPropertiesRepository.getAllBySwitchId(sw.getSwitchId()) .forEach(portPropertiesRepository::remove); if (force) { switchRepository.remove(sw); } else { switchRepository.removeIfNoDependant(sw); } }); return !switchRepository.exists(switchId); } SwitchOperationsService(RepositoryFactory repositoryFactory,
                                   TransactionManager transactionManager,
                                   SwitchOperationsServiceCarrier carrier); }
SwitchOperationsService implements ILinkOperationsServiceCarrier { public boolean deleteSwitch(SwitchId switchId, boolean force) throws SwitchNotFoundException { transactionManager.doInTransaction(() -> { Switch sw = switchRepository.findById(switchId) .orElseThrow(() -> new SwitchNotFoundException(switchId)); switchPropertiesRepository.findBySwitchId(sw.getSwitchId()) .ifPresent(sp -> switchPropertiesRepository.remove(sp)); portPropertiesRepository.getAllBySwitchId(sw.getSwitchId()) .forEach(portPropertiesRepository::remove); if (force) { switchRepository.remove(sw); } else { switchRepository.removeIfNoDependant(sw); } }); return !switchRepository.exists(switchId); } SwitchOperationsService(RepositoryFactory repositoryFactory,
                                   TransactionManager transactionManager,
                                   SwitchOperationsServiceCarrier carrier); GetSwitchResponse getSwitch(SwitchId switchId); List<GetSwitchResponse> getAllSwitches(); Switch updateSwitchUnderMaintenanceFlag(SwitchId switchId, boolean underMaintenance); boolean deleteSwitch(SwitchId switchId, boolean force); void checkSwitchIsDeactivated(SwitchId switchId); void checkSwitchHasNoFlows(SwitchId switchId); void checkSwitchHasNoFlowSegments(SwitchId switchId); void checkSwitchHasNoIsls(SwitchId switchId); SwitchPropertiesDto getSwitchProperties(SwitchId switchId); SwitchPropertiesDto updateSwitchProperties(SwitchId switchId, SwitchPropertiesDto switchPropertiesDto); PortProperties getPortProperties(SwitchId switchId, int port); Collection<SwitchConnectedDevice> getSwitchConnectedDevices(
            SwitchId switchId); List<IslEndpoint> getSwitchIslEndpoints(SwitchId switchId); Switch patchSwitch(SwitchId switchId, SwitchPatch data); }
SwitchOperationsService implements ILinkOperationsServiceCarrier { public boolean deleteSwitch(SwitchId switchId, boolean force) throws SwitchNotFoundException { transactionManager.doInTransaction(() -> { Switch sw = switchRepository.findById(switchId) .orElseThrow(() -> new SwitchNotFoundException(switchId)); switchPropertiesRepository.findBySwitchId(sw.getSwitchId()) .ifPresent(sp -> switchPropertiesRepository.remove(sp)); portPropertiesRepository.getAllBySwitchId(sw.getSwitchId()) .forEach(portPropertiesRepository::remove); if (force) { switchRepository.remove(sw); } else { switchRepository.removeIfNoDependant(sw); } }); return !switchRepository.exists(switchId); } SwitchOperationsService(RepositoryFactory repositoryFactory,
                                   TransactionManager transactionManager,
                                   SwitchOperationsServiceCarrier carrier); GetSwitchResponse getSwitch(SwitchId switchId); List<GetSwitchResponse> getAllSwitches(); Switch updateSwitchUnderMaintenanceFlag(SwitchId switchId, boolean underMaintenance); boolean deleteSwitch(SwitchId switchId, boolean force); void checkSwitchIsDeactivated(SwitchId switchId); void checkSwitchHasNoFlows(SwitchId switchId); void checkSwitchHasNoFlowSegments(SwitchId switchId); void checkSwitchHasNoIsls(SwitchId switchId); SwitchPropertiesDto getSwitchProperties(SwitchId switchId); SwitchPropertiesDto updateSwitchProperties(SwitchId switchId, SwitchPropertiesDto switchPropertiesDto); PortProperties getPortProperties(SwitchId switchId, int port); Collection<SwitchConnectedDevice> getSwitchConnectedDevices(
            SwitchId switchId); List<IslEndpoint> getSwitchIslEndpoints(SwitchId switchId); Switch patchSwitch(SwitchId switchId, SwitchPatch data);  }