Skip to content

Commit

Permalink
services fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
nocs00 committed Jul 20, 2016
1 parent 6c2d4d3 commit 3872073
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 12 deletions.
Expand Up @@ -62,10 +62,6 @@ public EventClass(EventClassDto dto) {
if (tenantId != null) {
this.tenant = new Tenant(tenantId);
}
Long ecfId = getLongId(dto.getEcfId());
if (ecfId != null) {
this.ecf = new EventClassFamilyVersion(ecfId);
}
this.fqn = dto.getFqn();
this.type = dto.getType();
}
Expand Down
Expand Up @@ -72,7 +72,7 @@ public class EventClassFamily extends GenericModel<EventClassFamilyDto> {
protected long createdTime;

@OneToMany(cascade = CascadeType.ALL)
@JoinColumn(name = EVENT_CLASS_FAMILY_VERSION_EVENT_CLASS_FAMILY_ID)
@JoinColumn(name = EVENT_CLASS_FAMILY_VERSION_EVENT_CLASS_FAMILY_ID, nullable = false)
private List<EventClassFamilyVersion> schemas;

public EventClassFamily() {
Expand Down
Expand Up @@ -36,7 +36,7 @@ public class EventClassFamilyVersion extends GenericModel<EventClassFamilyVersio
private static final long serialVersionUID = -7490111487256831990L;

@OneToMany(cascade = CascadeType.ALL)
@JoinColumn(name = EVENT_CLASS_EVENT_CLASS_FAMILY_VERSION_ID)
@JoinColumn(name = EVENT_CLASS_EVENT_CLASS_FAMILY_VERSION_ID, nullable = false)
private List<EventClass> records;

@Column(name = EVENT_CLASS_FAMILY_VERSION_VERSION)
Expand Down
Expand Up @@ -26,6 +26,7 @@
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.stream.Collectors;

import org.apache.commons.lang.StringUtils;
import org.kaaproject.avro.ui.shared.NamesValidator;
Expand Down Expand Up @@ -163,9 +164,10 @@ public int compare(EventClassFamilyVersionDto o1,
EventClassFamily ecf = new EventClassFamily(eventClassFamily);
List<EventClassFamilyVersion> schemas = new ArrayList<>();
for (EventClassDto eventClass : records) {
saveEventClass(eventClassFamily, eventClass, version);
setEventClassProperties(eventClassFamily, eventClass, version);
}
schemasDto.forEach(s -> schemas.add(new EventClassFamilyVersion(s)));
setEventClassECF(schemas);
ecf.setSchemas(schemas);
eventClassFamilyDao.save(ecf);
} else {
Expand All @@ -178,11 +180,14 @@ public int compare(EventClassFamilyVersionDto o1,
}
}

private void saveEventClass(EventClassFamilyDto eventClassFamilyDto, EventClassDto eventClass, int version) {
private void setEventClassProperties(EventClassFamilyDto eventClassFamilyDto, EventClassDto eventClass, int version) {
eventClass.setTenantId(eventClassFamilyDto.getTenantId());
eventClass.setEcfId(eventClassFamilyDto.getId());
eventClass.setVersion(version);
//eventClassDao.save(new EventClass(eventClass));
}

private void setEventClassECF(List<EventClassFamilyVersion> ecfvList) {
ecfvList.forEach(ecfv -> ecfv.getRecords().forEach(ec -> ec.setEcf(ecfv)));
}

private boolean validateEventClassFamilyFqns(EventClassFamilyDto eventClassFamily, List<String> fqns) {
Expand All @@ -194,7 +199,9 @@ public List<EventClassDto> findEventClassesByFamilyIdVersionAndType(String ecfId
List<EventClassDto> eventClasses;
if (isValidSqlId(ecfId)) {
LOG.debug("Find event classes by family id [{}] version [{}] and type [{}]", ecfId, version, type);
eventClasses = convertDtoList(eventClassDao.findByEcfIdVersionAndType(ecfId, version, type));
EventClassFamily ecf = eventClassFamilyDao.findById(ecfId);
EventClassFamilyVersion ecfv = ecf.getSchemas().stream().filter(s -> s.getVersion() == version).collect(Collectors.toList()).get(0);
eventClasses = convertDtoList(eventClassDao.findByEcfIdVersionAndType(String.valueOf(ecfv.getId()), ecfv.getVersion(), type));
} else {
throw new IncorrectParameterException("Incorrect event class family id: " + ecfId);
}
Expand Down
Expand Up @@ -292,7 +292,6 @@ protected void clearDBData() {
if (url.contains("h2")) {
LOG.info("Deleting data from H2 database");
new H2DBTestRunner().truncateTables(dataSource);
new H2DBTestRunner().truncateSequences(dataSource);
} else {
LOG.info("Deleting data from PostgreSQL database");
new PostgreDBTestRunner().truncateTables(dataSource);
Expand Down
Expand Up @@ -134,8 +134,9 @@ public void testGetEventClassesByFamilyIdVersionAndType() throws Exception {
List<EventClassDto> eventClasses = client.getEventClassesByFamilyIdVersionAndType(eventClassFamily.getId(), 1, EventClassType.EVENT);
Assert.assertNotNull(eventClasses);
Assert.assertEquals(1, eventClasses.size());
eventClassFamilyVersion = client.getEventClassFamilyVersionsById(eventClassFamily.getId()).get(0);
for (EventClassDto eventClass : eventClasses) {
Assert.assertEquals(eventClassFamily.getId(), eventClass.getEcfId());
Assert.assertEquals(eventClassFamilyVersion.getId(), eventClass.getEcfId());
Assert.assertEquals(0, eventClass.getVersion());
}
}
Expand Down

0 comments on commit 3872073

Please sign in to comment.