private CtlSchema generateCTLSchema(String fqn, Tenant tenant, int version, String body) { CtlSchema ctlSchema = new CtlSchema(); if (tenant == null) { tenant = generateTenant(); } ctlSchema.setMetaInfo(new CtlSchemaMetaInfo(fqn, tenant, null)); ctlSchema.setVersion(version); if (isBlank(body)) { body = UUID.randomUUID().toString(); } ctlSchema.setBody(body); return ctlSchema; }
private List<CtlSchemaMetaInfoDto> getMetaInfoFromCtlSchema(List<CtlSchema> schemas) { Map<String, CtlSchemaMetaInfoDto> metaInfoMap = new HashMap<>(); if (!schemas.isEmpty()) { for (CtlSchema schema : schemas) { String metaInfoId = schema.getMetaInfo().getStringId(); CtlSchemaMetaInfoDto metaInfoDto = metaInfoMap.get(metaInfoId); if (metaInfoDto == null) { metaInfoDto = getDto(schema.getMetaInfo()); metaInfoMap.put(metaInfoId, metaInfoDto); } List<Integer> versions = metaInfoDto.getVersions(); if (versions == null) { versions = new ArrayList<>(); metaInfoDto.setVersions(versions); } versions.add(schema.getVersion()); } } List<CtlSchemaMetaInfoDto> result = new ArrayList<>(metaInfoMap.values()); return result; }
return false; } else if (!ctlSchema.equals(other.ctlSchema)) { return false;
new CtlSchemaMetaInfo(metaInfo)); ctlSchemaMetaInfoDao.lockRequest(lockOptions).setScope(true).lock(uniqueMetaInfo); CtlSchema ctlSchema = new CtlSchema(unSavedSchema); ctlSchema.setMetaInfo(uniqueMetaInfo); ctlSchema.setCreatedTime(System.currentTimeMillis()); ctlSchemaMetaInfoDao.refresh(uniqueMetaInfo); try {
@Override public CTLSchemaDto updateCtlSchema(CTLSchemaDto ctlSchema) { validateCtlSchemaObject(ctlSchema); LOG.debug("Update ctl schema with id [{}]", ctlSchema.getId()); CtlSchema schema = ctlSchemaDao.findById(ctlSchema.getId()); if (schema != null) { synchronized (this) { if (ctlSchema.getVersion() != schema.getVersion()) { throw new DatabaseProcessingException("Can't change version of existing common type " + "version."); } CtlSchemaMetaInfo metaInfo = schema.getMetaInfo(); if (!ctlSchema.getMetaInfo().equals(metaInfo.toDto())) { throw new DatabaseProcessingException("Can't update scope of existing common type " + "version within update procedure."); } ctlSchemaMetaInfoDao.lockRequest(lockOptions).setScope(true).lock(metaInfo); schema.update(ctlSchema); return DaoUtil.getDto(ctlSchemaDao.save(schema, true)); } } else { throw new DatabaseProcessingException("Can't find common type version by id."); } }
@Override protected GenericModel<CTLSchemaDto> newInstance(Long id) { return new CtlSchema(id); }
private void setEventClassProperties(EventClassFamilyDto eventClassFamilyDto, EventClassDto eventClass) { eventClass.setTenantId(eventClassFamilyDto.getTenantId()); eventClass.setVersion(ctlSchemaDao.findById(eventClass.getCtlSchemaId()).getVersion()); }
if (ctlSchema != null) { List<CtlSchema> dependsList = ctlSchemaDao.findDependentSchemas(ctlSchema.getStringId()); if (dependsList.isEmpty()) { synchronized (this) { CtlSchemaMetaInfo metaInfo = ctlSchema.getMetaInfo(); ctlSchemaMetaInfoDao.lockRequest(lockOptions).setScope(true).lock(metaInfo); try { ctlSchemaDao.removeById(ctlSchema.getStringId()); List<CtlSchema> schemas = ctlSchemaDao.findAllByMetaInfoId(metaInfo.getStringId()); if (schemas == null || schemas.isEmpty()) {
@Override public CTLSchemaDto toDto() { CTLSchemaDto ctlSchemaDto = createDto(); ctlSchemaDto.setId(getStringId()); ctlSchemaDto.setMetaInfo(metaInfo.toDto()); ctlSchemaDto.setVersion(version); ctlSchemaDto.setCreatedTime(createdTime); ctlSchemaDto.setCreatedUsername(createdUsername); ctlSchemaDto.setBody(body); ctlSchemaDto.setDefaultRecord(defaultRecord); ctlSchemaDto.setDependencySet(DaoUtil.convertDtoSet(dependencySet)); return ctlSchemaDto; }
@Override public List<CTLSchemaDto> findCtlSchemaDependents(String schemaId) { validateSqlId(schemaId, "Incorrect schema id for ctl schema request."); LOG.debug("Find dependents schemas for schema with id [{}]", schemaId); List<CTLSchemaDto> list = Collections.emptyList(); CtlSchema schemaDto = ctlSchemaDao.findById(schemaId); if (schemaDto != null) { list = convertDtoList(ctlSchemaDao.findDependentSchemas(schemaDto.getStringId())); } return list; }
@Override public int hashCode() { final int prime = 31; int result = 1; result = prime * result + ((application == null) ? 0 : application.hashCode()); result = prime * result + (int) (createdTime ^ (createdTime >>> 32)); result = prime * result + ((createdUsername == null) ? 0 : createdUsername.hashCode()); result = prime * result + ((ctlSchema == null) ? 0 : ctlSchema.hashCode()); result = prime * result + ((description == null) ? 0 : description.hashCode()); result = prime * result + ((name == null) ? 0 : name.hashCode()); result = prime * result + version; return result; }
private byte[] serializeNotificationBody(NotificationDto nf, NotificationSchema nfSchema) throws IOException { GenericAvroConverter<GenericRecord> converter = new GenericAvroConverter<>(nfSchema.getCtlSchema().getBody()); String notificationJson = new String(nf.getBody(), Charset.forName("UTF8")); GenericRecord notificationAvro = converter.decodeJson(notificationJson); return converter.encode(notificationAvro); }
/** * Update <code>CtlSchema</code> instance, get data from dto. * * @param dto data transfer object */ public void update(CTLSchemaDto dto) { this.body = dto.getBody(); this.defaultRecord = dto.getDefaultRecord(); Set<CTLSchemaDto> dependencies = dto.getDependencySet(); if (dependencies != null && !dependencies.isEmpty()) { for (CTLSchemaDto dependency : dependencies) { dependencySet.add(new CtlSchema(dependency)); } } }
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; }
@Override public List<CTLSchemaDto> findCtlSchemaDependents(String fqn, Integer version, String tenantId, String applicationId) { if (isBlank(fqn) || version == null) { throw new IncorrectParameterException("Incorrect parameters for ctl schema request."); } LOG.debug("Find dependents schemas for schema with fqn {} version {}, tenantId {} and " + "applicationId ()", fqn, version, tenantId, applicationId); List<CTLSchemaDto> schemas = Collections.emptyList(); CtlSchema schema = ctlSchemaDao.findByFqnAndVerAndTenantIdAndApplicationId(fqn, version, tenantId, applicationId); if (schema != null) { schemas = convertDtoList(ctlSchemaDao.findDependentSchemas(schema.getStringId())); } return schemas; }
@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; }
protected CtlSchema generateCTLSchema(String fqn, int version, Tenant tenant, CTLSchemaScopeDto scope) { if (scope == null) { if (tenant == null) { scope = CTLSchemaScopeDto.SYSTEM; } else { scope = CTLSchemaScopeDto.TENANT; } } CtlSchemaMetaInfo metaInfo = new CtlSchemaMetaInfo(); metaInfo.setFqn(fqn); metaInfo.setTenant(tenant); metaInfo = ctlSchemaMetaInfoDao.save(metaInfo); CtlSchema ctlSchema = new CtlSchema(); ctlSchema.setMetaInfo(metaInfo); ctlSchema.setVersion(version); ctlSchema.setBody(UUID.randomUUID().toString()); ctlSchema.setDependencySet(new HashSet<CtlSchema>()); ctlSchema = ctlSchemaDao.save(ctlSchema); return ctlSchema; }
/** * Instantiates a new Base schema. * * @param dto data transfare object that used to create instance */ public BaseSchema(T dto) { if (dto != null) { this.id = getLongId(dto); this.version = dto.getVersion(); Long appId = getLongId(dto.getApplicationId()); this.application = appId != null ? new Application(appId) : null; Long ctlSchemaId = getLongId(dto.getCtlSchemaId()); this.ctlSchema = ctlSchemaId != null ? new CtlSchema(ctlSchemaId) : null; this.name = dto.getName(); this.description = dto.getDescription(); this.createdUsername = dto.getCreatedUsername(); this.createdTime = dto.getCreatedTime(); } }
@Override public T toDto() { T dto = createDto(); dto.setId(getStringId()); if (application != null) { dto.setApplicationId(application.getStringId()); } if (ctlSchema != null) { dto.setCtlSchemaId(ctlSchema.getStringId()); } dto.setVersion(version); dto.setName(name); dto.setDescription(description); dto.setCreatedUsername(createdUsername); dto.setCreatedTime(createdTime); return dto; }
return false; } else if (!getCtlSchema().equals(other.getCtlSchema())) { return false;