@Override protected GenericModel<EventClassFamilyVersionDto> newInstance(Long id) { return new EventClassFamilyVersion(id); }
@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 EventClassFamilyVersionDto toDto() { EventClassFamilyVersionDto dto = createDto(); dto.setId(getStringId()); dto.setVersion(version); dto.setCreatedUsername(createdUsername); dto.setCreatedTime(createdTime); if (records != null) { List<EventClassDto> recordsDto = new ArrayList<>(records.size()); for (EventClass record : records) { recordsDto.add(record.toDto()); } dto.setRecords(recordsDto); } return dto; }
@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()); } } }
protected List<EventClassFamilyVersion> generateEventClassFamilyVersion(EventClassFamily eventClassFamily, int ecfvCount, int ecCount) { List<EventClassFamilyVersion> ecfvList = new ArrayList<>(ecfvCount); for (int i = 0; i < ecfvCount; i++) { EventClassFamilyVersion ecfv = new EventClassFamilyVersion(); List<EventClass> ecList = new ArrayList<>(); for (int j = 0; j < ecCount; j++) { EventClass ec = new EventClass(); ec.setTenant(eventClassFamily.getTenant()); Optional<CtlSchema> ctlMaxVersion = ctlSchemaDao.find().stream() .max((ctl1, ctl2) -> Integer.compare(ctl1.getVersion(), ctl2.getVersion())); int version = ctlMaxVersion.isPresent() ? (ctlMaxVersion.get().getVersion() + 1) : 1; ec.setCtlSchema(generateCTLSchema(DEFAULT_FQN, version, eventClassFamily.getTenant(), CTLSchemaScopeDto.TENANT)); ec.setEcfv(ecfv); ec.setFqn("Test FQN" + RANDOM.nextInt()); ec.setType(EventClassType.EVENT); ecList.add(ec); } ecfv.setRecords(ecList); ecfvList.add(ecfv); } return ecfvList; }
@Test public void findByEcfIdTest() { List<EventClass> eventClasses = generateEventClass(null, null, 2); EventClass dto = eventClassDao.findById(eventClasses.get(0).getStringId()); Assert.assertNotNull(dto); List<EventClass> eventClassesList = eventClassDao.findByEcfvId(dto.getEcfv().getStringId()); EventClass eventClass = null; for (EventClass found : eventClassesList) { if (dto.getId().equals(found.getId())) { eventClass = found; } } Assert.assertNotNull(eventClass); Assert.assertEquals(dto, eventClass); }
private void setBackreference(List<EventClassFamilyVersion> ecfvList) { ecfvList.forEach(ecfv -> ecfv.getRecords().forEach(ec -> ec.setEcfv(ecfv))); }
@Override public int hashCode() { final int prime = 31; int result = 1; result = prime * result + ((ecfv == null) ? 0 : ecfv.hashCode()); result = prime * result + ((fqn == null) ? 0 : fqn.hashCode()); result = prime * result + ((id == null) ? 0 : id.hashCode()); result = prime * result + ((getCtlSchema() == null) ? 0 : getCtlSchema().hashCode()); result = prime * result + ((tenant == null) ? 0 : tenant.hashCode()); result = prime * result + ((type == null) ? 0 : type.hashCode()); return result; }
return false; } else if (!ecfv.equals(other.ecfv)) { return false;
ecf.setEcfId(String.valueOf(eventClassFamily.getId())); ecf.setEcfName(eventClassFamily.getName()); ecf.setVersion(eventClassFamilyVersion.getVersion()); if (occupiedEcfs != null && !occupiedEcfs.contains(ecf)) { vacantEcfs.add(ecf);
@Test public void removeByEcfvId() { List<EventClass> eventClasses = generateEventClass(null, null, 2); String id = eventClasses.get(0).getStringId(); EventClass dto = eventClassDao.findById(id); Assert.assertNotNull(dto); String ecfvId = dto.getEcfv().getStringId(); Assert.assertNotNull(ecfvId); eventClassDao.removeByEcfvId(ecfvId); dto = eventClassDao.findById(id); Assert.assertNull(dto); }
@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 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; }
setEventClassProperties(eventClassFamily, eventClass); schemasDto.forEach(s -> schemas.add(new EventClassFamilyVersion(s))); setBackreference(schemas); EventClassFamily ecf = new EventClassFamily(eventClassFamily);
@Override public EventClassDto toDto() { EventClassDto dto = createDto(); dto.setId(getStringId()); if (tenant != null) { dto.setTenantId(tenant.getStringId()); } if (ecfv != null) { dto.setEcfvId(ecfv.getStringId()); } dto.setFqn(fqn); dto.setType(type); dto.setCreatedUsername(createdUsername); dto.setCreatedTime(createdTime); dto.setDescription(description); dto.setName(name); dto.setVersion(version); dto.setCtlSchemaId(getCtlSchema().getStringId()); return dto; }
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; }
/** * Create new instance of EventClass. * * @param dto data transfer object, contain data for new instance */ public EventClass(EventClassDto dto) { super(dto); this.id = getLongId(dto.getId()); Long tenantId = getLongId(dto.getTenantId()); if (tenantId != null) { this.tenant = new Tenant(tenantId); } this.fqn = dto.getFqn(); this.type = dto.getType(); Long ecfvId = getLongId(dto.getEcfvId()); if (ecfvId != null) { this.ecfv = new EventClassFamilyVersion(ecfvId); } this.version = dto.getVersion(); this.name = dto.getName(); this.description = dto.getDescription(); this.createdUsername = dto.getCreatedUsername(); this.createdTime = dto.getCreatedTime(); Long ctlId = getLongId(dto.getCtlSchemaId()); if (ctlId != null) { this.setCtlSchema(new CtlSchema(ctlId)); } }