@Override protected GenericModel<EventClassDto> newInstance(Long id) { return new EventClass(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); } } }
private void setBackreference(List<EventClassFamilyVersion> ecfvList) { ecfvList.forEach(ecfv -> ecfv.getRecords().forEach(ec -> ec.setEcfv(ecfv))); }
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; }
EventClass currentEvent = new EventClass(items.get(position).get("name").toString(), items.get(position).get("location"), items.get(position).get("date") , items.get(position).get("type"), items.get(position).get("theme"),items.get(position).get("link")); ImageView imageView = (ImageView) rowView.findViewById(R.id.imageView_type); txtName.setText(currentEvent.getEvent_name()); txtDate.setText(android.text.format.DateFormat.format("dd MMMM yyyy",currentEvent.getDate())); if(currentEvent.getType().equals("triathlon")) { imageView.setImageResource(R.drawable.triathlon_70); if(currentEvent.getType().equals("run")) { imageView.setImageResource(R.drawable.ic_run_70); if(currentEvent.getType().equals("cycling")) { imageView.setImageResource(R.drawable.ic_cycle_70);
@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); }
@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; }
@Test public void testFindByTenantIdAndFqnAndVersion() { EventClassFamily classFamily = generateEventClassFamily(null, 1).get(0); Tenant tenant = classFamily.getTenant(); List<EventClass> events = generateEventClass(tenant, classFamily, 1); EventClass ec = events.get(0); EventClass found = eventClassDao.findByTenantIdAndFqnAndVersion(tenant.getId().toString(), ec.getFqn(), ec.getVersion()); Assert.assertEquals(ec.getFqn(), found.getFqn()); Assert.assertEquals(ec.getVersion(), found.getVersion()); } }
@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 ApplicationEventMapDto toDto() { ApplicationEventMapDto dto = createDto(); dto.setId(getStringId()); if (eventClass != null) { dto.setEventClassId(eventClass.getStringId()); } dto.setFqn(fqn); dto.setAction(action); return dto; }
@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; }
/** * 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)); } }
@Override public String toString() { return "EventClass [ecfv=" + ecfv + ", fqn=" + fqn + ", type=" + type + ", ctlSchema=" + getCtlSchema() + ", id=" + id + "]"; }
return false; } else if (!eventClass.equals(other.eventClass)) { return false;
@Test public void removeById() { List<EventClass> eventClasses = generateEventClass(null, null, 2); String id = eventClasses.get(0).getStringId(); EventClass dto = eventClassDao.findById(id); Assert.assertNotNull(dto); eventClassDao.removeById(id); dto = eventClassDao.findById(id); Assert.assertNull(dto); }
@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; }
/** * Instantiates the EventClassFamilyVersion. */ public EventClassFamilyVersion(EventClassFamilyVersionDto dto) { this.id = getLongId(dto.getId()); this.version = dto.getVersion(); this.createdUsername = dto.getCreatedUsername(); this.createdTime = dto.getCreatedTime(); if (dto.getRecords() != null) { this.records = new ArrayList<>(dto.getRecords().size()); for (EventClassDto record : dto.getRecords()) { this.records.add(new EventClass(record)); } } }
@Test public void testFindByTenantIdAndFqn() { EventClassFamily classFamily = generateEventClassFamily(null, 1).get(0); Tenant tenant = classFamily.getTenant(); List<EventClass> events = generateEventClass(tenant, classFamily, 3); EventClass ec = events.get(0); List<EventClass> found = eventClassDao.findByTenantIdAndFqn(tenant.getId().toString(), ec.getFqn()); Assert.assertEquals(ec, found.get(0)); }
return false; if (getCtlSchema() == null) { if (other.getCtlSchema() != null) { return false; } else if (!getCtlSchema().equals(other.getCtlSchema())) { return false;
/** * Instantiates the ApplicationEventMap. */ public ApplicationEventMap(ApplicationEventMapDto dto) { this.id = getLongId(dto.getId()); Long eventClassId = getLongId(dto.getEventClassId()); if (eventClassId != null) { this.eventClass = new EventClass(eventClassId); } this.fqn = dto.getFqn(); this.action = dto.getAction(); }