diff --git a/server/src/main/java/com/epam/aidial/core/server/controller/ApplicationTypeSchemaController.java b/server/src/main/java/com/epam/aidial/core/server/controller/ApplicationTypeSchemaController.java index e3c4d9c4..83bdbe36 100644 --- a/server/src/main/java/com/epam/aidial/core/server/controller/ApplicationTypeSchemaController.java +++ b/server/src/main/java/com/epam/aidial/core/server/controller/ApplicationTypeSchemaController.java @@ -55,7 +55,7 @@ ObjectNode getSchema() throws JsonProcessingException { try { schemaId = URI.create(schemaIdParam); } catch (IllegalArgumentException e) { - throw new HttpException(HttpStatus.BAD_REQUEST, "Schema ID is required"); + throw new HttpException(HttpStatus.BAD_REQUEST, "Bad Schema ID"); } String schema = context.getConfig().getApplicationTypeSchemas().get(schemaId.toString()); diff --git a/server/src/main/java/com/epam/aidial/core/server/service/PublicationService.java b/server/src/main/java/com/epam/aidial/core/server/service/PublicationService.java index 8d2de2e1..342a1884 100644 --- a/server/src/main/java/com/epam/aidial/core/server/service/PublicationService.java +++ b/server/src/main/java/com/epam/aidial/core/server/service/PublicationService.java @@ -378,12 +378,23 @@ private void prepareAndValidatePublicationRequest(ProxyContext context, Publicat validateRules(publication); } + /** + * Builds the target folder path for custom application files. + * + * @param resource the publication resource containing the target URL + * @return the constructed target folder path for custom application files + */ private static String buildTargetFolderForCustomAppFiles(Publication.Resource resource) { String targetUrl = resource.getTargetUrl(); - String appPath = targetUrl.substring(targetUrl.indexOf(ResourceDescriptor.PATH_SEPARATOR, - targetUrl.indexOf(ResourceDescriptor.PATH_SEPARATOR) + 1) + 1, - targetUrl.lastIndexOf(ResourceDescriptor.PATH_SEPARATOR)); - String appName = targetUrl.substring(targetUrl.lastIndexOf(ResourceDescriptor.PATH_SEPARATOR) + 1); + // Find the index of the end of a bucket segment (the second slash in the target URL) + int indexOfBucketEndSlash = targetUrl.indexOf(ResourceDescriptor.PATH_SEPARATOR, targetUrl.indexOf(ResourceDescriptor.PATH_SEPARATOR) + 1); + // Find the index of the start of a file name (the last slash in the target URL) + int indexOfFileNameStartSlash = targetUrl.lastIndexOf(ResourceDescriptor.PATH_SEPARATOR); + // Extract the application path from the target URL + String appPath = targetUrl.substring(indexOfBucketEndSlash + 1, indexOfFileNameStartSlash); + // Extract the application name from the target URL + String appName = targetUrl.substring(indexOfFileNameStartSlash + 1); + // Construct and return the target folder path return appPath + ResourceDescriptor.PATH_SEPARATOR + "." + appName + ResourceDescriptor.PATH_SEPARATOR; } diff --git a/server/src/test/java/com/epam/aidial/core/server/ResourceBaseTest.java b/server/src/test/java/com/epam/aidial/core/server/ResourceBaseTest.java index e05460fb..6e2e6ad1 100644 --- a/server/src/test/java/com/epam/aidial/core/server/ResourceBaseTest.java +++ b/server/src/test/java/com/epam/aidial/core/server/ResourceBaseTest.java @@ -117,7 +117,7 @@ void init() throws Exception { redis = RedisServer.newRedisServer() .port(16370) .bind("127.0.0.1") - .onShutdownForceStop(true) + .onShutdownForceStop(true) // redis on windows does not stop gracefully. So tests takes 6h to complete otherwise. .setting("maxmemory 16M") .setting("maxmemory-policy volatile-lfu") .build();