@Test public void testAddIfSameVardgivareButDifferentUnitsCopiesSchemaVersion() { final String enhetsId = "enhetsId"; final String vardgivarId = "vardgivarId"; IntegreradEnhetEntry entry = new IntegreradEnhetEntry(enhetsId, vardgivarId); IntegreradEnhet integreradEnhet = new IntegreradEnhet(); integreradEnhet.setEnhetsId("another enhetsId"); integreradEnhet.setSchemaVersion3(true); integreradEnhet.setVardgivarId(vardgivarId); when(integreradEnhetRepository.findById(eq(enhetsId))).thenReturn(Optional.of(integreradEnhet)); when(integreradEnhetRepository.save(any(IntegreradEnhet.class))).thenReturn(new IntegreradEnhet()); registry.addIfSameVardgivareButDifferentUnits(enhetsId, entry, LuseEntryPoint.MODULE_ID); ArgumentCaptor<IntegreradEnhet> enhetCaptor = ArgumentCaptor.forClass(IntegreradEnhet.class); verify(integreradEnhetRepository, times(3)).save(enhetCaptor.capture()); assertNotNull(enhetCaptor.getAllValues().get(0).getSenasteKontrollDatum()); assertTrue(enhetCaptor.getAllValues().get(1).isSchemaVersion3()); }
@Override @Transactional public void addIfSameVardgivareButDifferentUnits(String orgEnhetsHsaId, IntegreradEnhetEntry newEntry, String intygType) { if (getSchemaVersion(orgEnhetsHsaId, intygType).isPresent()) { IntegreradEnhet enhet = getIntegreradEnhetAndUpdateControlDate(orgEnhetsHsaId); IntegreradEnhetEntry orgEntry = getIntegreradEnhetEntry(enhet); if (orgEntry != null && orgEntry.compareTo(newEntry) != 0) { putIntegreradEnhet(newEntry, enhet.isSchemaVersion1(), enhet.isSchemaVersion3()); } } }
IntegreradeEnheterRegistryImpl implements IntegreradeEnheterRegistry { @Override @Transactional public void addIfSameVardgivareButDifferentUnits(String orgEnhetsHsaId, IntegreradEnhetEntry newEntry, String intygType) { if (getSchemaVersion(orgEnhetsHsaId, intygType).isPresent()) { IntegreradEnhet enhet = getIntegreradEnhetAndUpdateControlDate(orgEnhetsHsaId); IntegreradEnhetEntry orgEntry = getIntegreradEnhetEntry(enhet); if (orgEntry != null && orgEntry.compareTo(newEntry) != 0) { putIntegreradEnhet(newEntry, enhet.isSchemaVersion1(), enhet.isSchemaVersion3()); } } } }
IntegreradeEnheterRegistryImpl implements IntegreradeEnheterRegistry { @Override @Transactional public void addIfSameVardgivareButDifferentUnits(String orgEnhetsHsaId, IntegreradEnhetEntry newEntry, String intygType) { if (getSchemaVersion(orgEnhetsHsaId, intygType).isPresent()) { IntegreradEnhet enhet = getIntegreradEnhetAndUpdateControlDate(orgEnhetsHsaId); IntegreradEnhetEntry orgEntry = getIntegreradEnhetEntry(enhet); if (orgEntry != null && orgEntry.compareTo(newEntry) != 0) { putIntegreradEnhet(newEntry, enhet.isSchemaVersion1(), enhet.isSchemaVersion3()); } } }  }
IntegreradeEnheterRegistryImpl implements IntegreradeEnheterRegistry { @Override @Transactional public void addIfSameVardgivareButDifferentUnits(String orgEnhetsHsaId, IntegreradEnhetEntry newEntry, String intygType) { if (getSchemaVersion(orgEnhetsHsaId, intygType).isPresent()) { IntegreradEnhet enhet = getIntegreradEnhetAndUpdateControlDate(orgEnhetsHsaId); IntegreradEnhetEntry orgEntry = getIntegreradEnhetEntry(enhet); if (orgEntry != null && orgEntry.compareTo(newEntry) != 0) { putIntegreradEnhet(newEntry, enhet.isSchemaVersion1(), enhet.isSchemaVersion3()); } } }  @Override @Transactional void putIntegreradEnhet(IntegreradEnhetEntry entry, boolean schemaVersion1, boolean schemaVersion3); @Override @Transactional boolean isEnhetIntegrerad(String enhetsHsaId, String intygType); @Override @Transactional(readOnly = true) IntegreradEnhet getIntegreradEnhet(String enhetsId); @Override @Transactional(readOnly = true) List<IntegreradEnhet> getAllIntegreradEnhet(); @Override @Transactional void addIfSameVardgivareButDifferentUnits(String orgEnhetsHsaId, IntegreradEnhetEntry newEntry, String intygType); @Override @Transactional void deleteIntegreradEnhet(String enhetsHsaId); @Override @Transactional Optional<SchemaVersion> getSchemaVersion(String enhetsHsaId, String intygType); @Override @Transactional(readOnly = true) List<IntegreradEnhetEntryWithSchemaVersion> getIntegreradeVardenheter(); }
IntegreradeEnheterRegistryImpl implements IntegreradeEnheterRegistry { @Override @Transactional public void addIfSameVardgivareButDifferentUnits(String orgEnhetsHsaId, IntegreradEnhetEntry newEntry, String intygType) { if (getSchemaVersion(orgEnhetsHsaId, intygType).isPresent()) { IntegreradEnhet enhet = getIntegreradEnhetAndUpdateControlDate(orgEnhetsHsaId); IntegreradEnhetEntry orgEntry = getIntegreradEnhetEntry(enhet); if (orgEntry != null && orgEntry.compareTo(newEntry) != 0) { putIntegreradEnhet(newEntry, enhet.isSchemaVersion1(), enhet.isSchemaVersion3()); } } }  @Override @Transactional void putIntegreradEnhet(IntegreradEnhetEntry entry, boolean schemaVersion1, boolean schemaVersion3); @Override @Transactional boolean isEnhetIntegrerad(String enhetsHsaId, String intygType); @Override @Transactional(readOnly = true) IntegreradEnhet getIntegreradEnhet(String enhetsId); @Override @Transactional(readOnly = true) List<IntegreradEnhet> getAllIntegreradEnhet(); @Override @Transactional void addIfSameVardgivareButDifferentUnits(String orgEnhetsHsaId, IntegreradEnhetEntry newEntry, String intygType); @Override @Transactional void deleteIntegreradEnhet(String enhetsHsaId); @Override @Transactional Optional<SchemaVersion> getSchemaVersion(String enhetsHsaId, String intygType); @Override @Transactional(readOnly = true) List<IntegreradEnhetEntryWithSchemaVersion> getIntegreradeVardenheter();  }