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; }
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); } }