public static List getFiles()

in server/src/main/java/com/epam/aidial/core/server/util/ApplicationTypeSchemaUtils.java [158:194]


    public static List<ResourceDescriptor> getFiles(Config config, Application application, EncryptionService encryptionService, ResourceService resourceService) {
        try {
            String customApplicationSchema = getCustomApplicationSchemaOrThrow(config, application);
            if (customApplicationSchema == null) {
                return Collections.emptyList();
            }
            JsonSchema appSchema = SCHEMA_FACTORY.getSchema(customApplicationSchema);
            CollectorContext collectorContext = new CollectorContext();
            String customPropsJson = ProxyUtil.MAPPER.writeValueAsString(application.getApplicationProperties());
            Set<ValidationMessage> validationResult = appSchema.validate(customPropsJson, InputFormat.JSON,
                    e -> e.setCollectorContext(collectorContext));
            if (!validationResult.isEmpty()) {
                throw new ApplicationTypeSchemaValidationException("Failed to validate custom app against the schema", validationResult);
            }
            ListCollector<String> propsCollector = (ListCollector<String>) collectorContext.getCollectorMap().get("file");
            if (propsCollector == null) {
                return Collections.emptyList();
            }
            List<ResourceDescriptor> result = new ArrayList<>();
            for (String item : propsCollector.collect()) {
                try {
                    ResourceDescriptor descriptor = ResourceDescriptorFactory.fromAnyUrl(item, encryptionService);
                    if (!descriptor.isFolder() && !resourceService.hasResource(descriptor)) {
                        throw new ApplicationTypeSchemaValidationException("Resource listed as dependent to the application not found or inaccessible: " + item);
                    }
                    result.add(descriptor);
                } catch (IllegalArgumentException e) {
                    throw new ApplicationTypeSchemaValidationException("Failed to get resource descriptor for url: " + item, e);
                }
            }
            return result;
        } catch (ApplicationTypeSchemaValidationException e) {
            throw e;
        } catch (Exception e) {
            throw new ApplicationTypeSchemaProcessingException("Failed to obtain list of files attached to the custom app", e);
        }
    }