@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 findByEcfvIdTest() { List<EventClassFamily> eventClassFamilies = generateEventClassFamily(null, 1); EventClassFamily ecf = eventClassFamilies.get(0); List<EventClassFamilyVersion> ecfvList = generateEventClassFamilyVersion(ecf, 1, 1); ecf.setSchemas(ecfvList); ecf = eventClassFamilyDao.save(ecf); EventClassFamilyVersion ecfv = ecfvList.get(0); EventClassFamily ecfByEcfv = eventClassFamilyDao.findByEcfvId(ecfv.getStringId()); Assert.assertNotNull(ecfByEcfv); Assert.assertEquals(ecf, ecfByEcfv); Assert.assertEquals(ecfByEcfv.getSchemas().size(), 1); if (ecfByEcfv.getSchemas().size() == 1) { Assert.assertEquals(ecfByEcfv.getSchemas().get(0).getRecords().size(), 1); } else { throw new AssertionError("There should be 1 ecfv in fetched ecf, but got: " + ecfByEcfv.getSchemas().size()); } } }
for (EventClassFamily eventClassFamily : eventClassFamilies) { if (eventClassFamily.getSchemas() != null) { for (EventClassFamilyVersion eventClassFamilyVersion : eventClassFamily.getSchemas()) { EcfInfoDto ecf = new EcfInfoDto(); ecf.setEcfId(String.valueOf(eventClassFamily.getId()));
protected List<EventClass> generateEventClass(Tenant tenant, EventClassFamily eventClassFamily, int count) { if (tenant == null) { tenant = generateTenant(); } if (eventClassFamily == null) { eventClassFamily = generateEventClassFamily(tenant, 1).get(0); } List<EventClassFamilyVersion> ecfvList = generateEventClassFamilyVersion(eventClassFamily, 1, count); eventClassFamily.setSchemas(ecfvList); eventClassFamily = eventClassFamilyDao.save(eventClassFamily); List<EventClass> storedECs = eventClassFamily.getSchemas().get(0).getRecords(); return storedECs; }