@Override public EventClassFamilyDto findEventClassFamilyById(String id) { validateSqlId(id, "Event class family id is incorrect. Can't find event class family by id " + id); return getDto(eventClassFamilyDao.findById(id)); }
@Override public Set<String> getFqnSetForEcf(String ecfId) { if (isValidSqlId(ecfId)) { LOG.debug("Get fqn list for event class family by id [{}] ", ecfId); Set<String> storedFqns = new HashSet<>(); EventClassFamily ecf = eventClassFamilyDao.findById(ecfId); ecf.getSchemas().forEach(ecfv -> ecfv.getRecords() .forEach(ec -> storedFqns.add(ec.getFqn()))); return storedFqns; } else { throw new IncorrectParameterException("Incorrect event class family id: " + ecfId); } } }
@Override public boolean isValidEcfListInSdkProfile(List<AefMapInfoDto> aefList) { Set<EventClass> ecList = new HashSet<>(); for (AefMapInfoDto aef : aefList) { EventClassFamily ecf = eventClassFamilyDao.findById(aef.getEcfId()); Optional<EventClassFamilyVersion> optEcfv = ecf.getSchemas().stream() .filter(ecfv -> ecfv.getVersion() == aef.getVersion()) .findFirst(); if (optEcfv.isPresent()) { for (EventClass ec : optEcfv.get().getRecords()) { if (!ecList.add(ec)) { return false; } } } } return true; }
@Override public List<EventClassFamilyVersionDto> findEventClassFamilyVersionsByEcfId(String ecfId) { validateSqlId(ecfId, "Event class family id is incorrect. Can't find event class family by id " + ecfId); EventClassFamily ecf = eventClassFamilyDao.findById(ecfId); return convertDtoList(ecf.getSchemas()); }
@Override public List<EventClassDto> findEventClassesByFamilyIdVersionAndType(String ecfId, int version, EventClassType type) { List<EventClassDto> eventClasses = new ArrayList<>(); if (isValidSqlId(ecfId)) { LOG.debug("Find event classes by family id [{}] version [{}] and type [{}]", ecfId, version, type); EventClassFamily ecf = eventClassFamilyDao.findById(ecfId); Optional<EventClassFamilyVersion> ecfv = ecf.getSchemas().stream() .filter(s -> s.getVersion() == version).findFirst(); if (type == null) { ecfv.ifPresent( e -> eventClasses.addAll(convertDtoList(e.getRecords()))); } else { ecfv.ifPresent( e -> eventClasses.addAll(convertDtoList(e.getRecords().stream() .filter(ec -> ec.getType() == type) .collect(Collectors.toList())))); } } else { throw new IncorrectParameterException("Incorrect event class family id: " + ecfId); } return eventClasses; }
@Test public void removeById() { List<EventClassFamily> eventClassFamilies = generateEventClassFamily(null, 2); EventClassFamily eventClassFamily = eventClassFamilies.get(0); EventClassFamily dto = eventClassFamilyDao.findById(eventClassFamily.getStringId()); Assert.assertNotNull(dto); eventClassFamilyDao.removeById(eventClassFamily.getStringId()); dto = eventClassFamilyDao.findById(eventClassFamily.getStringId()); Assert.assertNull(dto); }
@Test public void removeByTenantId() { List<EventClassFamily> eventClassFamilies = generateEventClassFamily(null, 2); EventClassFamily eventClassFamily = eventClassFamilies.get(0); EventClassFamily dto = eventClassFamilyDao.findById(eventClassFamily.getStringId()); Assert.assertNotNull(dto); Assert.assertNotNull(dto.getTenant()); eventClassFamilyDao.removeByTenantId(dto.getTenant().getStringId()); dto = eventClassFamilyDao.findById(eventClassFamily.getStringId()); Assert.assertNull(dto); }
@Test public void findByTenantIdTest() { List<EventClassFamily> eventClassFamilies = generateEventClassFamily(null, 2); EventClassFamily dto = eventClassFamilyDao.findById(eventClassFamilies.get(0).getStringId()); Assert.assertNotNull(dto); List<EventClassFamily> eventClassFamilyList = eventClassFamilyDao.findByTenantId(dto.getTenant().getStringId()); EventClassFamily eventClassFamily = null; for (EventClassFamily found : eventClassFamilyList) { if (dto.getId().equals(found.getId())) { eventClassFamily = found; } } Assert.assertNotNull(eventClassFamily); Assert.assertEquals(dto, eventClassFamily); }
@Test public void findByTenantIdAndNameTest() { List<EventClassFamily> eventClassFamilies = generateEventClassFamily(null, 2); EventClassFamily dto = eventClassFamilyDao.findById(eventClassFamilies.get(0).getStringId()); Assert.assertNotNull(dto); EventClassFamily eventClassFamily = eventClassFamilyDao.findByTenantIdAndName(dto.getTenant().getStringId(), dto.getName()); Assert.assertNotNull(eventClassFamily); Assert.assertEquals(dto, eventClassFamily); }