diff --git a/server/build.gradle b/server/build.gradle index 3b38578ee..df298595b 100644 --- a/server/build.gradle +++ b/server/build.gradle @@ -23,7 +23,7 @@ def versions = [ springdoc: '2.1.0', spdx: '2.2.8', gcloud: '2.22.3', - azure: '12.18.0', + azure: '12.23.0', guava: '30.0-jre', junit: '5.7.1', testcontainers: '1.15.2', diff --git a/server/src/main/java/org/eclipse/openvsx/LocalRegistryService.java b/server/src/main/java/org/eclipse/openvsx/LocalRegistryService.java index bcfefb34c..3ab8fd014 100644 --- a/server/src/main/java/org/eclipse/openvsx/LocalRegistryService.java +++ b/server/src/main/java/org/eclipse/openvsx/LocalRegistryService.java @@ -113,7 +113,7 @@ public ExtensionJson getExtension(String namespace, String extensionName, String @Cacheable(value = CACHE_EXTENSION_JSON, keyGenerator = GENERATOR_EXTENSION_JSON) public ExtensionJson getExtension(String namespace, String extensionName, String targetPlatform, String version) { var extVersion = findExtensionVersion(namespace, extensionName, targetPlatform, version); - var json = toExtensionVersionJson(extVersion, targetPlatform, true, false); + var json = toExtensionVersionJson(extVersion, targetPlatform, true); json.downloads = getDownloads(extVersion.getExtension(), targetPlatform, extVersion.getVersion()); return json; } @@ -611,24 +611,13 @@ public ResultJson verifyToken(String namespaceName, String tokenValue) { return ResultJson.success("Valid token"); } - @Retryable(value = { DataIntegrityViolationException.class }) - @Transactional(rollbackOn = ErrorResultException.class) public ExtensionJson publish(InputStream content, UserData user) throws ErrorResultException { - var token = new PersonalAccessToken(); - token.setDescription("One time use publish token"); - token.setValue(users.generateTokenValue()); - token.setCreatedTimestamp(TimeUtil.getCurrentUTC()); - token.setAccessedTimestamp(token.getCreatedTimestamp()); - token.setUser(user); - token.setActive(true); - entityManager.persist(token); - - var json = publish(content, token.getValue()); - token.setActive(false); + var token = users.createAccessToken(user, "One time use publish token"); + var json = publish(content, token.value); + users.deleteAccessToken(user, token.id); return json; } - @Transactional(rollbackOn = ErrorResultException.class) public ExtensionJson publish(InputStream content, String tokenValue) throws ErrorResultException { var token = users.useAccessToken(tokenValue); if (token == null || token.getUser() == null) { @@ -639,7 +628,7 @@ public ExtensionJson publish(InputStream content, String tokenValue) throws Erro eclipse.checkPublisherAgreement(token.getUser()); var extVersion = extensions.publishVersion(content, token); - var json = toExtensionVersionJson(extVersion, null, true, true); + var json = toExtensionVersionJson(extVersion, null, true); json.success = "It can take a couple minutes before the extension version is available"; var sameVersions = repositories.findVersions(extVersion.getVersion(), extVersion.getExtension()); @@ -812,14 +801,10 @@ private List getAllVersionReferences( }).collect(Collectors.toList()); } - public ExtensionJson toExtensionVersionJson(ExtensionVersion extVersion, String targetPlatform, boolean onlyActive, boolean inTransaction) { + public ExtensionJson toExtensionVersionJson(ExtensionVersion extVersion, String targetPlatform, boolean onlyActive) { var extension = extVersion.getExtension(); - var latest = inTransaction - ? versions.getLatest(extension, targetPlatform, false, onlyActive) - : versions.getLatestTrxn(extension, targetPlatform, false, onlyActive); - var latestPreRelease = inTransaction - ? versions.getLatest(extension, targetPlatform, true, onlyActive) - : versions.getLatestTrxn(extension, targetPlatform, true, onlyActive); + var latest = versions.getLatestTrxn(extension, targetPlatform, false, onlyActive); + var latestPreRelease = versions.getLatestTrxn(extension, targetPlatform, true, onlyActive); var json = extVersion.toExtensionJson(); json.preview = latest != null && latest.isPreview(); diff --git a/server/src/main/java/org/eclipse/openvsx/admin/AdminAPI.java b/server/src/main/java/org/eclipse/openvsx/admin/AdminAPI.java index f9c426066..ecd8517a3 100644 --- a/server/src/main/java/org/eclipse/openvsx/admin/AdminAPI.java +++ b/server/src/main/java/org/eclipse/openvsx/admin/AdminAPI.java @@ -199,7 +199,7 @@ public ResponseEntity getExtension(@PathVariable String namespace json.allVersions = Collections.emptyMap(); json.allTargetPlatformVersions = Collections.emptyMap(); } else { - json = local.toExtensionVersionJson(latest, null, false, false); + json = local.toExtensionVersionJson(latest, null, false); json.allTargetPlatformVersions = versions.getVersionsTrxn(extension).stream() .collect(Collectors.groupingBy(ExtensionVersion::getVersion, Collectors.mapping(ExtensionVersion::getTargetPlatform, Collectors.toList()))); } diff --git a/server/src/main/java/org/eclipse/openvsx/publish/PublishExtensionVersionHandler.java b/server/src/main/java/org/eclipse/openvsx/publish/PublishExtensionVersionHandler.java index 6ebcd6989..41c2a8dcc 100644 --- a/server/src/main/java/org/eclipse/openvsx/publish/PublishExtensionVersionHandler.java +++ b/server/src/main/java/org/eclipse/openvsx/publish/PublishExtensionVersionHandler.java @@ -63,7 +63,7 @@ public class PublishExtensionVersionHandler { @Autowired ExtensionValidator validator; - @Transactional + @Transactional(rollbackOn = ErrorResultException.class) public ExtensionVersion createExtensionVersion(ExtensionProcessor processor, PersonalAccessToken token, LocalDateTime timestamp, boolean checkDependencies) { // Extract extension metadata from its manifest var extVersion = createExtensionVersion(processor, token.getUser(), token, timestamp); diff --git a/server/src/main/java/org/eclipse/openvsx/publish/PublishExtensionVersionService.java b/server/src/main/java/org/eclipse/openvsx/publish/PublishExtensionVersionService.java index 464cf8674..dc719de02 100644 --- a/server/src/main/java/org/eclipse/openvsx/publish/PublishExtensionVersionService.java +++ b/server/src/main/java/org/eclipse/openvsx/publish/PublishExtensionVersionService.java @@ -43,6 +43,7 @@ public void deleteFileResources(ExtensionVersion extVersion) { repositories.findFiles(extVersion).forEach(entityManager::remove); } + @Retryable public void storeDownload(FileResource download, TempFile extensionFile) { if (storageUtil.shouldStoreExternally(download)) { storageUtil.uploadFile(download, extensionFile); @@ -78,8 +79,7 @@ public void mirrorResource(FileResource resource) { } @Transactional - public void persistResource(FileResource resource) { - resource.setExtension(entityManager.merge(resource.getExtension())); + public synchronized void persistResource(FileResource resource) { entityManager.persist(resource); }