public Pair putApplication()

in server/src/main/java/com/epam/aidial/core/server/service/ApplicationService.java [216:259]


    public Pair<ResourceItemMetadata, Application> putApplication(ResourceDescriptor resource, EtagHeader etag, Application application) {
        prepareApplication(resource, application);

        ResourceItemMetadata meta = resourceService.computeResource(resource, etag, json -> {
            Application existing = ProxyUtil.convertToObject(json, Application.class);
            Application.Function function = application.getFunction();

            if (application.getApplicationTypeSchemaId() != null && existing != null
                    && existing.getApplicationProperties() != null && application.getApplicationProperties() == null) {
                throw new HttpException(HttpStatus.BAD_REQUEST, "The application with schema can not be updated to the one without properties");
            }

            if (function != null) {
                if (existing == null || existing.getFunction() == null) {
                    if (isPublicOrReview(resource)) {
                        throw new HttpException(HttpStatus.CONFLICT, "The application function cannot be created in public/review bucket");
                    }

                    function.setId(UrlUtil.encodePathSegment(idGenerator.get()));
                    function.setAuthorBucket(resource.getBucketName());
                    function.setStatus(Application.Function.Status.UNDEPLOYED);
                    function.setTargetFolder(encodeTargetFolder(resource, function.getId()));
                } else {
                    if (isPublicOrReview(resource) && !function.getSourceFolder().equals(existing.getFunction().getSourceFolder())) {
                        throw new HttpException(HttpStatus.CONFLICT, "The application function source folder cannot be updated in public/review bucket");
                    }
                    application.setEndpoint(existing.getEndpoint());
                    application.getFeatures().setRateEndpoint(existing.getFeatures().getRateEndpoint());
                    application.getFeatures().setTokenizeEndpoint(existing.getFeatures().getTokenizeEndpoint());
                    application.getFeatures().setTruncatePromptEndpoint(existing.getFeatures().getTruncatePromptEndpoint());
                    application.getFeatures().setConfigurationEndpoint(existing.getFeatures().getConfigurationEndpoint());
                    function.setId(existing.getFunction().getId());
                    function.setAuthorBucket(existing.getFunction().getAuthorBucket());
                    function.setStatus(existing.getFunction().getStatus());
                    function.setTargetFolder(existing.getFunction().getTargetFolder());
                    function.setError(existing.getFunction().getError());
                }
            }

            return ProxyUtil.convertToString(application);
        });

        return Pair.of(meta, application);
    }