private boolean checkScopeUpdate(CtlSchemaMetaInfoDto newSchemaMetaInfo, CtlSchemaMetaInfoDto prevSchemaMetaInfo) { if (!newSchemaMetaInfo.equals(prevSchemaMetaInfo)) { if (isBlank(newSchemaMetaInfo.getFqn())) { throw new DatabaseProcessingException("FQN can't be empty."); if (!newSchemaMetaInfo.getFqn().equals(prevSchemaMetaInfo.getFqn())) { throw new DatabaseProcessingException("Can't change FQN of the existing common type."); CTLSchemaScopeDto newScope = newSchemaMetaInfo.getScope(); CTLSchemaScopeDto prevScope = prevSchemaMetaInfo.getScope(); if (newScope != prevScope) { if (!isBlank(newSchemaMetaInfo.getTenantId()) && !newSchemaMetaInfo.getTenantId().equals(prevSchemaMetaInfo.getTenantId())) { throw new DatabaseProcessingException("Can't change tenant reference for the existing " + "common type."); if (!isBlank(newSchemaMetaInfo.getApplicationId()) && !newSchemaMetaInfo.getApplicationId().equals(prevSchemaMetaInfo.getApplicationId())) { throw new DatabaseProcessingException("Can't change application reference for the " + "existing common type.");
@Override protected CtlSchemaMetaInfoDto createDto() { return new CtlSchemaMetaInfoDto(); }
@Override public CtlSchemaMetaInfoDto toDto() { CtlSchemaMetaInfoDto ctlSchemaMetaInfoDto = createDto(); ctlSchemaMetaInfoDto.setId(getStringId()); ctlSchemaMetaInfoDto.setFqn(fqn); ctlSchemaMetaInfoDto.setApplicationId(application != null ? application.getStringId() : null); ctlSchemaMetaInfoDto.setTenantId(tenant != null ? tenant.getStringId() : null); return ctlSchemaMetaInfoDto; }
private Map<Fqn, List<Integer>> extractCtlSchemaVersionsInfo( List<CtlSchemaMetaInfoDto> ctlSchemaInfos) { Map<Fqn, List<Integer>> ctlSchemaVersions = new HashMap<>(); for (CtlSchemaMetaInfoDto ctlSchemaInfo : ctlSchemaInfos) { ctlSchemaVersions.put(new Fqn(ctlSchemaInfo.getFqn()), ctlSchemaInfo.getVersions()); } return ctlSchemaVersions; }
@Override protected Place existingEntityPlace(String id) { CtlSchemaMetaInfoDto schema = dataProvider.getRowData(id); return new CtlSchemaPlace(id, Collections.max(schema.getVersions()), schema.getScope(), null, schema.getScope() == getCurrentScope(), false); }
CTLSchemaDto dependencySchema = controlService.getCtlSchemaByFqnVersionTenantIdAndApplicationId( dependency.getMetaInfo().getFqn(), dependency.getVersion(), dependency.getMetaInfo().getTenantId(), dependency.getMetaInfo().getApplicationId()); if (dependencySchema == null) { String message = "Unable to locate dependency \"" + dependency.getMetaInfo().getFqn() + "\" (version " + dependency.getVersion() + ")"; throw new IllegalArgumentException(message); } catch (Exception cause) { LOG.error("Unable to parse CTL schema \"" + schema.getMetaInfo().getFqn() + "\" (version " + schema.getVersion() + "): ", cause); throw new IllegalArgumentException("Unable to parse CTL schema \"" + schema.getMetaInfo().getFqn() + "\" (version " + schema.getVersion() + "): " + cause.getMessage());
private List<FileData> recursiveShallowExport(List<FileData> files, CTLSchemaDto parent) throws Exception { files.add(this.shallowExport(parent)); ObjectNode object = new ObjectMapper().readValue(parent.getBody(), ObjectNode.class); ArrayNode dependencies = (ArrayNode) object.get(DEPENDENCIES); if (dependencies != null) { for (JsonNode node : dependencies) { ObjectNode dependency = (ObjectNode) node; String fqn = dependency.get(FQN).getTextValue(); Integer version = dependency.get(VERSION).getIntValue(); CTLSchemaDto child = this.findAnyCtlSchemaByFqnAndVerAndTenantIdAndApplicationId( fqn, version, parent.getMetaInfo().getTenantId(), parent.getMetaInfo().getApplicationId()); Validate.notNull(child, MessageFormat.format("The dependency [{0}] was not found!", fqn)); this.recursiveShallowExport(files, child); } } return files; } }
/** * Create new instance of CTL schema meta info. * * @param dto data transfer object that used for creating new instance, * it hold id, full qualified name, tenant id and application id * of new instance */ public CtlSchemaMetaInfo(CtlSchemaMetaInfoDto dto) { this.id = ModelUtils.getLongId(dto.getId()); this.fqn = dto.getFqn(); Long tenantId = getLongId(dto.getTenantId()); this.tenant = tenantId != null ? new Tenant(tenantId) : null; Long appId = getLongId(dto.getApplicationId()); this.application = appId != null ? new Application(appId) : null; }
CtlSchemaFormDto toCtlSchemaForm(CTLSchemaDto ctlSchema, ConverterType converterType) throws KaaAdminServiceException { try { CtlSchemaFormDto ctlSchemaForm = new CtlSchemaFormDto(ctlSchema); SchemaFormAvroConverter converter = getCtlSchemaConverterForScope( ctlSchemaForm.getMetaInfo().getTenantId(), ctlSchemaForm.getMetaInfo().getApplicationId(), converterType); RecordField form = converter.createSchemaFormFromSchema(ctlSchema.getBody()); ctlSchemaForm.setSchema(form); List<Integer> availableVersions = controlService.getAllCtlSchemaVersionsByFqnTenantIdAndApplicationId( ctlSchema.getMetaInfo().getFqn(), ctlSchema.getMetaInfo().getTenantId(), ctlSchema.getMetaInfo().getApplicationId()); availableVersions = availableVersions == null ? Collections.<Integer>emptyList() : availableVersions; Collections.sort(availableVersions); ctlSchemaForm.getMetaInfo().setVersions(availableVersions); return ctlSchemaForm; } catch (Exception cause) { throw Utils.handleException(cause); } }
if (sourceCtlSchema != null) { checkCtlSchemaEditScope( sourceCtlSchema.getMetaInfo().getTenantId(), sourceCtlSchema.getMetaInfo().getApplicationId()); ctlSchemaForm = new CtlSchemaFormDto(); ctlSchemaForm.setMetaInfo(sourceCtlSchema.getMetaInfo()); RecordField form = sourceCtlSchema.getSchema(); form.updateVersion(form.getContext().getMaxVersion( new Fqn(sourceCtlSchema.getMetaInfo().getFqn())) + 1); ctlSchemaForm.setSchema(form); } else { form.updateVersion(1); ctlSchemaForm.setSchema(form); CtlSchemaMetaInfoDto metaInfo = new CtlSchemaMetaInfoDto(null, getCurrentUser().getTenantId(), applicationId); ctlSchemaForm.setMetaInfo(metaInfo);
@Override public String getValue(CtlSchemaMetaInfoDto item) { return item.getFqn(); } },
synchronized (this) { List<CtlSchemaMetaInfo> existingFqns = ctlSchemaMetaInfoDao.findExistingFqns(metaInfo .getFqn(), metaInfo.getTenantId(), metaInfo.getApplicationId()); if (existingFqns != null && !existingFqns.isEmpty()) { throw new DatabaseProcessingException("Can't save common type due to an FQN conflict."); metaInfo.setId(null); CtlSchemaMetaInfo uniqueMetaInfo = ctlSchemaMetaInfoDao.save( new CtlSchemaMetaInfo(metaInfo));
RecordField schemaForm = ctlSchemaForm.getSchema(); ctlSchema.setMetaInfo(ctlSchemaForm.getMetaInfo()); ctlSchema.getMetaInfo().setFqn(schemaForm.getDeclaredFqn().getFqnString()); ctlSchema.getMetaInfo().setTenantId(currentUser.getTenantId()); ctlSchema.setVersion(schemaForm.getVersion()); List<FqnVersion> dependenciesList = schemaForm.getContext().getCtlDependenciesList(); controlService.getAnyCtlSchemaByFqnVersionTenantIdAndApplicationId( fqnVersion.getFqnString(), fqnVersion.getVersion(), ctlSchema.getMetaInfo().getTenantId(), ctlSchema.getMetaInfo().getApplicationId()); if (dependency != null) { dependencies.add(dependency); ctlSchema.getMetaInfo().getTenantId(), ctlSchema.getMetaInfo().getApplicationId(), converterType); Schema avroSchema = converter.createSchemaFromSchemaForm(schemaForm); String schemaBody = SchemaFormAvroConverter.createSchemaString(avroSchema, true);
@Test public void testScopeUpdate() { CtlSchemaMetaInfoDto metaInfo = appSchema3.getMetaInfo(); metaInfo.setApplicationId(null); ctlService.updateCtlSchemaMetaInfoScope(metaInfo); CTLSchemaDto found = ctlService.findCtlSchemaByFqnAndVerAndTenantIdAndApplicationId(metaInfo.getFqn(), appSchema3.getVersion(), metaInfo.getTenantId(), null); Assert.assertEquals(appSchema3, found); }
@Override public void onClick(ClickEvent event) { CtlSchemaMetaInfoDto metaInfo = entity.getMetaInfo(); KaaAdmin.getDataSource().promoteScopeToTenant(metaInfo.getApplicationId(), metaInfo.getFqn(), new BusyAsyncCallback<CtlSchemaMetaInfoDto>() { @Override public void onFailureImpl(Throwable caught) { Utils.handleException(caught, detailsView); } @Override public void onSuccessImpl(CtlSchemaMetaInfoDto result) { CtlSchemaPlace place = null; if (CtlSchemaActivity.this.place.getScope() == APPLICATION) { place = new CtlSchemaPlace(result.getId(), version, result.getScope(), CtlSchemaActivity.this.place.getApplicationId(), result.getScope() == APPLICATION, false); } else if (CtlSchemaActivity.this.place.getScope() == TENANT) { place = new CtlSchemaPlace(result.getId(), version, result.getScope(), CtlSchemaActivity.this.place.getEcfId(), CtlSchemaActivity.this.place.getEcfVersionId(), CtlSchemaActivity.this.place.getEcfVersion(), result.getScope() == TENANT, false); } goTo(place); } }); } }));
@Override public CtlSchemaMetaInfoDto updateCtlSchemaMetaInfoScope(CtlSchemaMetaInfoDto ctlSchemaMetaInfo) { validateObject(ctlSchemaMetaInfo, "Incorrect ctl schema meta info object"); LOG.debug("Update ctl schema meta info scope with id [{}]", ctlSchemaMetaInfo.getId()); CtlSchemaMetaInfo schemaMetaInfo = ctlSchemaMetaInfoDao.findById(ctlSchemaMetaInfo.getId()); if (schemaMetaInfo != null) { synchronized (this) { ctlSchemaMetaInfoDao.lockRequest(lockOptions).setScope(true).lock(schemaMetaInfo); if (checkScopeUpdate(ctlSchemaMetaInfo, schemaMetaInfo.toDto())) { List<CtlSchemaMetaInfo> others = ctlSchemaMetaInfoDao.findOthersByFqnAndTenantId( ctlSchemaMetaInfo.getFqn(), ctlSchemaMetaInfo.getTenantId(), ctlSchemaMetaInfo .getId()); if (others != null && !others.isEmpty()) { throw new DatabaseProcessingException("Can't update scope of the common type due to " + "an FQN conflict."); } schemaMetaInfo = ctlSchemaMetaInfoDao.updateScope( new CtlSchemaMetaInfo(ctlSchemaMetaInfo)); } return DaoUtil.getDto(schemaMetaInfo); } } else { throw new DatabaseProcessingException("Can't find common type by id."); } }
@Override public LogSchemaViewDto createLogSchemaFormCtlSchema(CtlSchemaFormDto ctlSchemaForm) throws KaaAdminServiceException { LOG.error("createLogSchemaFormCtlSchema [{}]", ctlSchemaForm.getSchema().getDisplayString()); checkAuthority(KaaAuthorityDto.TENANT_DEVELOPER, KaaAuthorityDto.TENANT_USER); try { checkApplicationId(ctlSchemaForm.getMetaInfo().getApplicationId()); LogSchemaDto logSchema = new LogSchemaDto(); logSchema.setApplicationId(ctlSchemaForm.getMetaInfo().getApplicationId()); logSchema.setName(ctlSchemaForm.getSchema().getDisplayNameFieldValue()); logSchema.setDescription(ctlSchemaForm.getSchema().getDescriptionFieldValue()); CtlSchemaFormDto savedCtlSchemaForm = ctlService.saveCtlSchemaForm( ctlSchemaForm, ConverterType.FORM_AVRO_CONVERTER); logSchema.setCtlSchemaId(savedCtlSchemaForm.getId()); LogSchemaDto savedLogSchema = saveLogSchema(logSchema); return getLogSchemaView(savedLogSchema.getId()); } catch (Exception ex) { throw Utils.handleException(ex); } }
protected void bindDetailsView(boolean fireChanged) { if (!create) { List<Integer> schemaVersions = entity.getMetaInfo().getVersions(); Collections.sort(schemaVersions); detailsView.setTitle(entity.getMetaInfo().getFqn()); detailsView.getScope().setText(Utils.getCtlScopeTitleString(entity.getMetaInfo().getScope())); detailsView.getCreatedUsername().setValue(entity.getCreatedUsername());
controlService.getCtlSchemaByFqnVersionTenantIdAndApplicationId( fqn, versions.get(0), tenantId, applicationId).getMetaInfo(); ctlSchemaMetaInfo.setApplicationId(null); //promote to tenant Set<CTLSchemaDto> schemaDependents = schema.getDependencySet(); dependencies.addAll(schemaDependents.stream() .filter(dep -> dep.getMetaInfo().getScope() == CTLSchemaScopeDto.APPLICATION) .collect(Collectors.toList()));
@Override public boolean equals(Object obj) { if (this == obj) { return true; } if (obj == null) { return false; } if (getClass() != obj.getClass()) { return false; } CtlSchemaReferenceDto other = (CtlSchemaReferenceDto) obj; if (metaInfo == null && other.metaInfo != null) { return false; } else { if (!metaInfo.equals(other.metaInfo)) { return false; } } if (version != other.version) { return false; } return true; }