diff --git a/legend-depot-artifacts-refresh/src/main/java/org/finos/legend/depot/store/artifacts/ArtifactsModule.java b/legend-depot-artifacts-refresh/src/main/java/org/finos/legend/depot/store/artifacts/ArtifactsModule.java index 7a5693eeb..e8f7d1e21 100644 --- a/legend-depot-artifacts-refresh/src/main/java/org/finos/legend/depot/store/artifacts/ArtifactsModule.java +++ b/legend-depot-artifacts-refresh/src/main/java/org/finos/legend/depot/store/artifacts/ArtifactsModule.java @@ -24,6 +24,8 @@ import org.finos.legend.depot.store.artifacts.api.ArtifactsRefreshService; import org.finos.legend.depot.store.artifacts.api.entities.EntitiesVersionArtifactsHandler; import org.finos.legend.depot.store.artifacts.api.entities.EntityArtifactsProvider; +import org.finos.legend.depot.store.artifacts.api.generation.FileArtifactGenerationsVersionArtifactsHandler; +import org.finos.legend.depot.store.artifacts.api.generation.artifact.ArtifactGenerationsVersionArtifactsHandler; import org.finos.legend.depot.store.artifacts.api.generation.file.FileGenerationsProvider; import org.finos.legend.depot.store.artifacts.api.generation.file.FileGenerationsVersionArtifactsHandler; import org.finos.legend.depot.store.artifacts.api.status.ManageRefreshStatusService; @@ -33,7 +35,9 @@ import org.finos.legend.depot.store.artifacts.services.ArtifactsRefreshServiceImpl; import org.finos.legend.depot.store.artifacts.services.entities.EntitiesHandlerImpl; import org.finos.legend.depot.store.artifacts.services.entities.EntityProvider; -import org.finos.legend.depot.store.artifacts.services.file.FileGenerationVersionsHandler; +import org.finos.legend.depot.store.artifacts.services.file.ArtifactGenerationHandler; +import org.finos.legend.depot.store.artifacts.services.file.FileArtifactGenerationVersionsHandler; +import org.finos.legend.depot.store.artifacts.services.file.FileGenerationHandler; import org.finos.legend.depot.store.artifacts.services.file.FileGenerationsProviderImpl; import org.finos.legend.depot.store.artifacts.store.mongo.ArtifactsMongo; import org.finos.legend.depot.store.artifacts.store.mongo.MongoRefreshStatus; @@ -62,9 +66,12 @@ protected void configure() bind(EntitiesVersionArtifactsHandler.class).to(EntitiesHandlerImpl.class); bind(EntityArtifactsProvider.class).to(EntityProvider.class); - bind(FileGenerationsVersionArtifactsHandler.class).to(FileGenerationVersionsHandler.class); + bind(ArtifactGenerationsVersionArtifactsHandler.class).to(ArtifactGenerationHandler.class); + bind(FileGenerationsVersionArtifactsHandler.class).to(FileGenerationHandler.class); + bind(FileArtifactGenerationsVersionArtifactsHandler.class).to(FileArtifactGenerationVersionsHandler.class); bind(FileGenerationsProvider.class).to(FileGenerationsProviderImpl.class); + bind(ArtifactsRefreshService.class).to(ArtifactsRefreshServiceImpl.class); expose(EntityArtifactsProvider.class); @@ -73,6 +80,8 @@ protected void configure() expose(ManageRefreshStatusService.class); expose(RefreshStatusService.class); expose(ArtifactsResource.class); + expose(ArtifactGenerationsVersionArtifactsHandler.class); + expose(FileGenerationsVersionArtifactsHandler.class); } @Provides @@ -87,7 +96,7 @@ boolean registerEntityRefresh(EntitiesVersionArtifactsHandler versionArtifactsHa @Provides @Named("fileGenerationRefresh") @Singleton - boolean registerFileGenerationRefresh(FileGenerationsVersionArtifactsHandler versionArtifactsHandler) + boolean registerFileGenerationRefresh(FileArtifactGenerationsVersionArtifactsHandler versionArtifactsHandler) { ArtifactResolverFactory.registerVersionUpdater(ArtifactType.FILE_GENERATIONS, versionArtifactsHandler); return true; diff --git a/legend-depot-artifacts-refresh/src/main/java/org/finos/legend/depot/store/artifacts/api/generation/FileArtifactGenerationsVersionArtifactsHandler.java b/legend-depot-artifacts-refresh/src/main/java/org/finos/legend/depot/store/artifacts/api/generation/FileArtifactGenerationsVersionArtifactsHandler.java new file mode 100644 index 000000000..08ce6f215 --- /dev/null +++ b/legend-depot-artifacts-refresh/src/main/java/org/finos/legend/depot/store/artifacts/api/generation/FileArtifactGenerationsVersionArtifactsHandler.java @@ -0,0 +1,23 @@ +// Copyright 2022 Goldman Sachs +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// + +package org.finos.legend.depot.store.artifacts.api.generation; + +import org.finos.legend.depot.store.artifacts.api.ProjectVersionArtifactsHandler; + +public interface FileArtifactGenerationsVersionArtifactsHandler extends ProjectVersionArtifactsHandler +{ + +} diff --git a/legend-depot-artifacts-refresh/src/main/java/org/finos/legend/depot/store/artifacts/api/generation/artifact/ArtifactGenerationsVersionArtifactsHandler.java b/legend-depot-artifacts-refresh/src/main/java/org/finos/legend/depot/store/artifacts/api/generation/artifact/ArtifactGenerationsVersionArtifactsHandler.java new file mode 100644 index 000000000..567afd754 --- /dev/null +++ b/legend-depot-artifacts-refresh/src/main/java/org/finos/legend/depot/store/artifacts/api/generation/artifact/ArtifactGenerationsVersionArtifactsHandler.java @@ -0,0 +1,32 @@ +// Copyright 2022 Goldman Sachs +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// + +package org.finos.legend.depot.store.artifacts.api.generation.artifact; + +import java.util.List; +import org.finos.legend.depot.domain.api.MetadataEventResponse; +import org.finos.legend.depot.domain.generation.artifact.ArtifactGeneration; +import org.finos.legend.depot.domain.project.ProjectData; + +public interface ArtifactGenerationsVersionArtifactsHandler +{ + + MetadataEventResponse refreshProjectVersionArtifacts(ProjectData project, String versionId, List fileGenerations); + + void delete(String groupId, String artifactId, String versionId); + + + +} diff --git a/legend-depot-artifacts-refresh/src/main/java/org/finos/legend/depot/store/artifacts/api/generation/file/FileGenerationsVersionArtifactsHandler.java b/legend-depot-artifacts-refresh/src/main/java/org/finos/legend/depot/store/artifacts/api/generation/file/FileGenerationsVersionArtifactsHandler.java index a102d1a15..4110f4679 100644 --- a/legend-depot-artifacts-refresh/src/main/java/org/finos/legend/depot/store/artifacts/api/generation/file/FileGenerationsVersionArtifactsHandler.java +++ b/legend-depot-artifacts-refresh/src/main/java/org/finos/legend/depot/store/artifacts/api/generation/file/FileGenerationsVersionArtifactsHandler.java @@ -1,4 +1,4 @@ -// Copyright 2021 Goldman Sachs +// Copyright 2022 Goldman Sachs // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -15,9 +15,16 @@ package org.finos.legend.depot.store.artifacts.api.generation.file; -import org.finos.legend.depot.store.artifacts.api.ProjectVersionArtifactsHandler; +import java.util.List; +import org.finos.legend.depot.domain.api.MetadataEventResponse; +import org.finos.legend.depot.domain.generation.file.FileGeneration; +import org.finos.legend.depot.domain.project.ProjectData; -public interface FileGenerationsVersionArtifactsHandler extends ProjectVersionArtifactsHandler +public interface FileGenerationsVersionArtifactsHandler { + MetadataEventResponse refreshProjectVersionArtifacts(ProjectData project, String versionId, List fileGenerations); + + void delete(String groupId, String artifactId, String versionId); + } diff --git a/legend-depot-artifacts-refresh/src/main/java/org/finos/legend/depot/store/artifacts/services/file/ArtifactGenerationHandler.java b/legend-depot-artifacts-refresh/src/main/java/org/finos/legend/depot/store/artifacts/services/file/ArtifactGenerationHandler.java new file mode 100644 index 000000000..9064bdade --- /dev/null +++ b/legend-depot-artifacts-refresh/src/main/java/org/finos/legend/depot/store/artifacts/services/file/ArtifactGenerationHandler.java @@ -0,0 +1,105 @@ +// Copyright 2022 Goldman Sachs +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// + +package org.finos.legend.depot.store.artifacts.services.file; + +import java.io.File; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Optional; +import java.util.Set; +import java.util.stream.Collectors; +import javax.inject.Inject; +import javax.inject.Singleton; +import org.finos.legend.depot.artifacts.repository.api.ArtifactRepository; +import org.finos.legend.depot.artifacts.repository.domain.ArtifactType; +import org.finos.legend.depot.domain.api.MetadataEventResponse; +import org.finos.legend.depot.domain.generation.artifact.ArtifactGeneration; +import org.finos.legend.depot.domain.generation.artifact.StoredArtifactGeneration; +import org.finos.legend.depot.domain.project.ProjectData; +import org.finos.legend.depot.services.api.generation.artifact.ManageArtifactGenerationsService; +import org.finos.legend.depot.store.artifacts.api.generation.artifact.ArtifactGenerationsVersionArtifactsHandler; +import org.finos.legend.sdlc.domain.model.entity.Entity; +import org.finos.legend.sdlc.serialization.EntityLoader; +import org.slf4j.Logger; + +@Singleton +public class ArtifactGenerationHandler implements ArtifactGenerationsVersionArtifactsHandler +{ + + public static final String VERSIONED_ENTITIES = "versioned-entities"; + public static final String PURE_PACKAGE_SEPARATOR = "::"; + public static final String PATH = "/"; + private static final Logger LOGGER = org.slf4j.LoggerFactory.getLogger(ArtifactGenerationHandler.class); + protected final ManageArtifactGenerationsService generations; + private final ArtifactRepository repository; + + @Inject + public ArtifactGenerationHandler(ArtifactRepository repository, ManageArtifactGenerationsService artifactGenerationService) + { + this.repository = repository; + this.generations = artifactGenerationService; + } + + + @Override + public MetadataEventResponse refreshProjectVersionArtifacts(ProjectData project, String versionId, List artifactGenerations) + { + MetadataEventResponse response = new MetadataEventResponse(); + + Map entities = findEntitiesByPath(project.getGroupId(), project.getArtifactId(), versionId); + Set entityPaths = entities.keySet(); + String message = String.format(" %s version %s found %s artifact generations", project.getProjectId(), versionId, artifactGenerations.size()); + LOGGER.info(message); + response.addMessage(message); + artifactGenerations.forEach(generation -> + { + String generator = null; + Optional entityKey = entityPaths.stream().filter(s -> generation.getPath().startsWith(PATH + s)).findFirst(); + if (entityKey.isPresent()) + { + generator = entities.get(entityKey.get()).getPath(); + } + StoredArtifactGeneration storedArtifactGeneration = new StoredArtifactGeneration(project.getGroupId(), project.getArtifactId(), versionId, generator, generation); + this.generations.createOrUpdate(storedArtifactGeneration); + }); + return response; + } + + private Map findEntitiesByPath(String groupId, String artifactId, String versionId) + { + Map entityMap = new HashMap<>(); + Optional entitiesFiles = repository.findFiles(ArtifactType.ENTITIES, groupId, artifactId, versionId).stream().filter(file -> isEntitiesArtifactFile(versionId, file)).findFirst(); + entitiesFiles.map(file -> EntityLoader.newEntityLoader(file).getAllEntities().collect(Collectors.toList())).orElse(Collections.emptyList()) + .forEach(entity -> entityMap.put(entity.getPath().replace(PURE_PACKAGE_SEPARATOR, PATH), entity)); + return entityMap; + } + + private boolean isEntitiesArtifactFile(String versionId, File file) + { + String entitiesFileName = "entities-" + versionId; + return file.getName().contains(entitiesFileName) && !file.getName().contains(VERSIONED_ENTITIES); + } + + @Override + public void delete(String groupId, String artifactId, String versionId) + { + this.generations.delete(groupId, artifactId, versionId); + } + + +} diff --git a/legend-depot-artifacts-refresh/src/main/java/org/finos/legend/depot/store/artifacts/services/file/FileArtifactGenerationVersionsHandler.java b/legend-depot-artifacts-refresh/src/main/java/org/finos/legend/depot/store/artifacts/services/file/FileArtifactGenerationVersionsHandler.java new file mode 100644 index 000000000..050958875 --- /dev/null +++ b/legend-depot-artifacts-refresh/src/main/java/org/finos/legend/depot/store/artifacts/services/file/FileArtifactGenerationVersionsHandler.java @@ -0,0 +1,65 @@ +// Copyright 2021 Goldman Sachs +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// + +package org.finos.legend.depot.store.artifacts.services.file; + +import java.io.File; +import java.util.List; +import java.util.stream.Collectors; +import javax.inject.Inject; +import javax.inject.Singleton; +import org.finos.legend.depot.domain.api.MetadataEventResponse; +import org.finos.legend.depot.domain.generation.artifact.ArtifactGeneration; +import org.finos.legend.depot.domain.generation.file.FileGeneration; +import org.finos.legend.depot.domain.project.ProjectData; +import org.finos.legend.depot.store.artifacts.api.generation.FileArtifactGenerationsVersionArtifactsHandler; +import org.finos.legend.depot.store.artifacts.api.generation.artifact.ArtifactGenerationsVersionArtifactsHandler; +import org.finos.legend.depot.store.artifacts.api.generation.file.FileGenerationsProvider; +import org.finos.legend.depot.store.artifacts.api.generation.file.FileGenerationsVersionArtifactsHandler; + + +public class FileArtifactGenerationVersionsHandler implements FileArtifactGenerationsVersionArtifactsHandler +{ + + private final FileGenerationsProvider fileGenerationsProvider; + private final ArtifactGenerationsVersionArtifactsHandler artifactGenerationHandler; + private final FileGenerationsVersionArtifactsHandler fileGenerationHandler; + + @Inject + public FileArtifactGenerationVersionsHandler(FileGenerationsProvider fileGenerationsProvider, ArtifactGenerationsVersionArtifactsHandler artifactGenerationHandler, FileGenerationsVersionArtifactsHandler fileGenerationHandler) + { + this.fileGenerationsProvider = fileGenerationsProvider; + this.artifactGenerationHandler = artifactGenerationHandler; + this.fileGenerationHandler = fileGenerationHandler; + } + + @Override + public MetadataEventResponse refreshProjectVersionArtifacts(ProjectData project, String versionId, List files) + { + List fileGenerations = this.fileGenerationsProvider.loadArtifacts(files); + MetadataEventResponse response = new MetadataEventResponse(); + response.combine(this.fileGenerationHandler.refreshProjectVersionArtifacts(project, versionId, fileGenerations)); + response.combine(this.artifactGenerationHandler.refreshProjectVersionArtifacts(project, versionId, + fileGenerations.stream().map(e -> new ArtifactGeneration(e.getPath(), e.getContent())).collect(Collectors.toList()))); + return response; + } + + @Override + public void delete(String groupId, String artifactId, String versionId) + { + this.fileGenerationHandler.delete(groupId, artifactId, versionId); + this.artifactGenerationHandler.delete(groupId, artifactId, versionId); + } +} diff --git a/legend-depot-artifacts-refresh/src/main/java/org/finos/legend/depot/store/artifacts/services/file/BaseFileGenerationHandler.java b/legend-depot-artifacts-refresh/src/main/java/org/finos/legend/depot/store/artifacts/services/file/FileGenerationHandler.java similarity index 79% rename from legend-depot-artifacts-refresh/src/main/java/org/finos/legend/depot/store/artifacts/services/file/BaseFileGenerationHandler.java rename to legend-depot-artifacts-refresh/src/main/java/org/finos/legend/depot/store/artifacts/services/file/FileGenerationHandler.java index e36e45ab6..3c4181288 100644 --- a/legend-depot-artifacts-refresh/src/main/java/org/finos/legend/depot/store/artifacts/services/file/BaseFileGenerationHandler.java +++ b/legend-depot-artifacts-refresh/src/main/java/org/finos/legend/depot/store/artifacts/services/file/FileGenerationHandler.java @@ -15,6 +15,15 @@ package org.finos.legend.depot.store.artifacts.services.file; +import static org.finos.legend.depot.domain.generation.file.FileGeneration.GENERATION_CONFIGURATION; + +import java.io.File; +import java.util.Collections; +import java.util.List; +import java.util.Optional; +import java.util.stream.Collectors; +import javax.inject.Inject; +import javax.inject.Singleton; import org.finos.legend.depot.artifacts.repository.api.ArtifactRepository; import org.finos.legend.depot.artifacts.repository.domain.ArtifactType; import org.finos.legend.depot.domain.api.MetadataEventResponse; @@ -22,23 +31,14 @@ import org.finos.legend.depot.domain.generation.file.StoredFileGeneration; import org.finos.legend.depot.domain.project.ProjectData; import org.finos.legend.depot.services.api.generation.file.ManageFileGenerationsService; -import org.finos.legend.depot.store.artifacts.api.generation.file.FileGenerationsProvider; +import org.finos.legend.depot.store.artifacts.api.generation.file.FileGenerationsVersionArtifactsHandler; import org.finos.legend.sdlc.domain.model.entity.Entity; import org.finos.legend.sdlc.serialization.EntityLoader; import org.slf4j.Logger; -import java.io.File; -import java.util.Collections; -import java.util.List; -import java.util.Optional; -import java.util.stream.Collectors; - -import static org.finos.legend.depot.domain.generation.file.FileGeneration.GENERATION_CONFIGURATION; - -public abstract class BaseFileGenerationHandler +@Singleton +public class FileGenerationHandler implements FileGenerationsVersionArtifactsHandler { - - public static final String TYPE = "type"; public static final String PATH = "/"; public static final String GENERATION_OUTPUT_PATH = "generationOutputPath"; @@ -46,20 +46,22 @@ public abstract class BaseFileGenerationHandler public static final String UNDERSCORE = "_"; public static final String VERSIONED_ENTITIES = "versioned-entities"; public static final String BLANK = ""; - private static final Logger LOGGER = org.slf4j.LoggerFactory.getLogger(BaseFileGenerationHandler.class); + private static final Logger LOGGER = org.slf4j.LoggerFactory.getLogger(FileGenerationHandler.class); + + // File Generations protected final ManageFileGenerationsService generations; - private final FileGenerationsProvider provider; private final ArtifactRepository repository; - - protected BaseFileGenerationHandler(ArtifactRepository repository, FileGenerationsProvider provider, ManageFileGenerationsService generations) + @Inject + public FileGenerationHandler(ArtifactRepository repository, ManageFileGenerationsService generations) { this.repository = repository; - this.provider = provider; this.generations = generations; } - public MetadataEventResponse refreshProjectVersionArtifacts(ProjectData project, String versionId, List files) + + @Override + public MetadataEventResponse refreshProjectVersionArtifacts(ProjectData project, String versionId, List gens) { MetadataEventResponse response = new MetadataEventResponse(); List fileGenerationEntities = findFileGenerationEntities(project.getGroupId(), project.getArtifactId(), versionId); @@ -68,16 +70,15 @@ public MetadataEventResponse refreshProjectVersionArtifacts(ProjectData project, response.addMessage(String.format("%s no generations found for version %s", project.getProjectId(), versionId)); return response; } - List gens = provider.loadArtifacts(files); String message = String.format(" %s version %s found %s generations", project.getProjectId(), versionId, gens.size()); LOGGER.info(message); response.addMessage(message); fileGenerationEntities.forEach(entity -> { - String generationPath = (String)entity.getContent().get(GENERATION_OUTPUT_PATH); + String generationPath = (String) entity.getContent().get(GENERATION_OUTPUT_PATH); String path = PATH + (generationPath != null ? generationPath : entity.getPath().replace(PURE_PACKAGE_SEPARATOR, UNDERSCORE)); - String type = (String)entity.getContent().get(TYPE); + String type = (String) entity.getContent().get(TYPE); gens.stream().filter(gen -> gen.getPath().startsWith(path)).forEach(gen -> { @@ -88,13 +89,20 @@ public MetadataEventResponse refreshProjectVersionArtifacts(ProjectData project, return response; } + @Override + public void delete(String groupId, String artifactId, String versionId) + { + this.generations.delete(groupId, artifactId, versionId); + } + private List findFileGenerationEntities(String groupId, String artifactId, String versionId) { List files = repository.findFiles(ArtifactType.ENTITIES, groupId, artifactId, versionId); Optional entitiesFiles = files.stream().filter(file -> isEntitiesArtifactFile(versionId, file)).findFirst(); - return entitiesFiles.map(file -> EntityLoader.newEntityLoader(file).getAllEntities() - .filter(en -> en.getClassifierPath().equalsIgnoreCase(GENERATION_CONFIGURATION)).collect(Collectors.toList())).orElse(Collections.emptyList()); + return entitiesFiles.map( + file -> EntityLoader.newEntityLoader(file).getAllEntities().filter(en -> en.getClassifierPath().equalsIgnoreCase(GENERATION_CONFIGURATION)).collect(Collectors.toList())) + .orElse(Collections.emptyList()); } private boolean isEntitiesArtifactFile(String versionId, File file) diff --git a/legend-depot-artifacts-refresh/src/main/java/org/finos/legend/depot/store/artifacts/services/file/FileGenerationVersionsHandler.java b/legend-depot-artifacts-refresh/src/main/java/org/finos/legend/depot/store/artifacts/services/file/FileGenerationVersionsHandler.java deleted file mode 100644 index 9ff87129f..000000000 --- a/legend-depot-artifacts-refresh/src/main/java/org/finos/legend/depot/store/artifacts/services/file/FileGenerationVersionsHandler.java +++ /dev/null @@ -1,41 +0,0 @@ -// Copyright 2021 Goldman Sachs -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// - -package org.finos.legend.depot.store.artifacts.services.file; - -import org.finos.legend.depot.artifacts.repository.api.ArtifactRepository; -import org.finos.legend.depot.services.api.generation.file.ManageFileGenerationsService; -import org.finos.legend.depot.store.artifacts.api.generation.file.FileGenerationsProvider; -import org.finos.legend.depot.store.artifacts.api.generation.file.FileGenerationsVersionArtifactsHandler; - -import javax.inject.Inject; - -public class FileGenerationVersionsHandler extends BaseFileGenerationHandler implements FileGenerationsVersionArtifactsHandler -{ - - - @Inject - public FileGenerationVersionsHandler(ArtifactRepository repository, FileGenerationsProvider provider, ManageFileGenerationsService generations) - { - super(repository, provider, generations); - } - - - @Override - public void delete(String groupId,String artifactId,String versionId) - { - generations.delete(groupId,artifactId, versionId); - } -} diff --git a/legend-depot-artifacts-refresh/src/test/java/org/finos/legend/depot/store/artifacts/services/TestArtifactsRefreshService.java b/legend-depot-artifacts-refresh/src/test/java/org/finos/legend/depot/store/artifacts/services/TestArtifactsRefreshService.java index 3c3c2351f..b4975038e 100644 --- a/legend-depot-artifacts-refresh/src/test/java/org/finos/legend/depot/store/artifacts/services/TestArtifactsRefreshService.java +++ b/legend-depot-artifacts-refresh/src/test/java/org/finos/legend/depot/store/artifacts/services/TestArtifactsRefreshService.java @@ -1,4 +1,4 @@ -// Copyright 2021 Goldman Sachs +// Copyright 2022 Goldman Sachs // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -26,9 +26,11 @@ import org.finos.legend.depot.domain.project.ProjectData; import org.finos.legend.depot.domain.project.ProjectVersionDependency; import org.finos.legend.depot.services.entities.EntitiesServiceImpl; +import org.finos.legend.depot.services.generation.artifact.ArtifactGenerationsServiceImpl; import org.finos.legend.depot.services.generation.file.FileGenerationsServiceImpl; import org.finos.legend.depot.services.projects.ProjectsServiceImpl; import org.finos.legend.depot.store.api.entities.UpdateEntities; +import org.finos.legend.depot.store.api.generation.artifact.UpdateArtifactGenerations; import org.finos.legend.depot.store.api.generation.file.UpdateFileGenerations; import org.finos.legend.depot.store.api.projects.UpdateProjects; import org.finos.legend.depot.store.artifacts.api.ArtifactsRefreshService; @@ -37,13 +39,16 @@ import org.finos.legend.depot.store.artifacts.api.status.ManageRefreshStatusService; import org.finos.legend.depot.store.artifacts.services.entities.EntitiesHandlerImpl; import org.finos.legend.depot.store.artifacts.services.entities.EntityProvider; -import org.finos.legend.depot.store.artifacts.services.file.FileGenerationVersionsHandler; +import org.finos.legend.depot.store.artifacts.services.file.ArtifactGenerationHandler; +import org.finos.legend.depot.store.artifacts.services.file.FileArtifactGenerationVersionsHandler; +import org.finos.legend.depot.store.artifacts.services.file.FileGenerationHandler; import org.finos.legend.depot.store.artifacts.services.file.FileGenerationsProviderImpl; import org.finos.legend.depot.store.artifacts.store.mongo.ArtifactsMongo; import org.finos.legend.depot.store.artifacts.store.mongo.MongoRefreshStatus; import org.finos.legend.depot.store.artifacts.store.mongo.api.UpdateArtifacts; import org.finos.legend.depot.store.mongo.TestStoreMongo; import org.finos.legend.depot.store.mongo.entities.EntitiesMongo; +import org.finos.legend.depot.store.mongo.generation.artifact.ArtifactGenerationsMongo; import org.finos.legend.depot.store.mongo.generation.file.FileGenerationsMongo; import org.finos.legend.depot.store.mongo.projects.ProjectsMongo; import org.finos.legend.sdlc.domain.model.entity.Entity; @@ -73,6 +78,7 @@ public class TestArtifactsRefreshService extends TestStoreMongo protected UpdateEntities entitiesStore = new EntitiesMongo(mongoProvider); protected List properties = Arrays.asList("[a-zA-Z0-9]+.version"); protected UpdateFileGenerations fileGenerationsStore = new FileGenerationsMongo(mongoProvider); + protected UpdateArtifactGenerations artifactGenerationsStore = new ArtifactGenerationsMongo(mongoProvider); protected ManageRefreshStatusService refreshStatusStore = new MongoRefreshStatus(mongoProvider); protected EntityArtifactsProvider entitiesProvider = new EntityProvider(); @@ -86,7 +92,10 @@ public class TestArtifactsRefreshService extends TestStoreMongo public void setUpData() { ArtifactResolverFactory.registerVersionUpdater(ArtifactType.ENTITIES, new EntitiesHandlerImpl(new EntitiesServiceImpl(entitiesStore, projectsStore), entitiesProvider)); - ArtifactResolverFactory.registerVersionUpdater(ArtifactType.FILE_GENERATIONS, new FileGenerationVersionsHandler(repository, fileGenerationsProvider, new FileGenerationsServiceImpl(fileGenerationsStore, entitiesStore))); + FileGenerationHandler fileGenerationHandler = new FileGenerationHandler(repository, new FileGenerationsServiceImpl(fileGenerationsStore, entitiesStore)); + ArtifactGenerationHandler artifactGenerationHandler = new ArtifactGenerationHandler(repository, new ArtifactGenerationsServiceImpl(artifactGenerationsStore)); + + ArtifactResolverFactory.registerVersionUpdater(ArtifactType.FILE_GENERATIONS, new FileArtifactGenerationVersionsHandler(fileGenerationsProvider, artifactGenerationHandler, fileGenerationHandler)); projectsStore.createOrUpdate(new ProjectData(PROJECT_B, TEST_GROUP_ID, TEST_DEPENDENCIES_ARTIFACT_ID)); projectsStore.createOrUpdate(new ProjectData(PROJECT_A, TEST_GROUP_ID, TEST_ARTIFACT_ID)); diff --git a/legend-depot-artifacts-refresh/src/test/java/org/finos/legend/depot/store/artifacts/services/generation/file/TestGenerationsProvider.java b/legend-depot-artifacts-refresh/src/test/java/org/finos/legend/depot/store/artifacts/services/generation/file/TestGenerationsProvider.java index 04c9ebebb..f14d6e200 100644 --- a/legend-depot-artifacts-refresh/src/test/java/org/finos/legend/depot/store/artifacts/services/generation/file/TestGenerationsProvider.java +++ b/legend-depot-artifacts-refresh/src/test/java/org/finos/legend/depot/store/artifacts/services/generation/file/TestGenerationsProvider.java @@ -23,15 +23,20 @@ import org.finos.legend.depot.domain.generation.file.StoredFileGeneration; import org.finos.legend.depot.domain.project.ProjectData; import org.finos.legend.depot.domain.version.VersionValidator; +import org.finos.legend.depot.services.api.generation.artifact.ManageArtifactGenerationsService; import org.finos.legend.depot.services.api.generation.file.ManageFileGenerationsService; +import org.finos.legend.depot.services.generation.artifact.ArtifactGenerationsServiceImpl; import org.finos.legend.depot.services.generation.file.FileGenerationsServiceImpl; import org.finos.legend.depot.store.api.entities.UpdateEntities; import org.finos.legend.depot.store.api.projects.UpdateProjects; import org.finos.legend.depot.store.artifacts.api.generation.file.FileGenerationsProvider; -import org.finos.legend.depot.store.artifacts.services.file.FileGenerationVersionsHandler; +import org.finos.legend.depot.store.artifacts.services.file.ArtifactGenerationHandler; +import org.finos.legend.depot.store.artifacts.services.file.FileArtifactGenerationVersionsHandler; +import org.finos.legend.depot.store.artifacts.services.file.FileGenerationHandler; import org.finos.legend.depot.store.artifacts.services.file.FileGenerationsProviderImpl; import org.finos.legend.depot.store.mongo.TestStoreMongo; import org.finos.legend.depot.store.mongo.entities.EntitiesMongo; +import org.finos.legend.depot.store.mongo.generation.artifact.ArtifactGenerationsMongo; import org.finos.legend.depot.store.mongo.generation.file.FileGenerationsMongo; import org.finos.legend.depot.store.mongo.projects.ProjectsMongo; import org.junit.Assert; @@ -53,6 +58,7 @@ public class TestGenerationsProvider extends TestStoreMongo private final UpdateProjects projects = new ProjectsMongo(mongoProvider); private final UpdateEntities entities = new EntitiesMongo(mongoProvider); private final ManageFileGenerationsService generations = new FileGenerationsServiceImpl(new FileGenerationsMongo(mongoProvider), entities); + protected ManageArtifactGenerationsService artifactGenerations = new ArtifactGenerationsServiceImpl(new ArtifactGenerationsMongo(mongoProvider)); @Before public void setup() @@ -89,7 +95,9 @@ public void canRefreshRevisions() { Assert.assertTrue(generations.getAll().isEmpty()); - FileGenerationVersionsHandler handler = new FileGenerationVersionsHandler(repository, fileGenerationsProvider, generations); + ArtifactGenerationHandler artifactGenerationHandler = new ArtifactGenerationHandler(repository, artifactGenerations); + FileGenerationHandler fileGenerationHandler = new FileGenerationHandler(repository, generations); + FileArtifactGenerationVersionsHandler handler = new FileArtifactGenerationVersionsHandler(fileGenerationsProvider, artifactGenerationHandler, fileGenerationHandler); ProjectData projectData = projects.find(TEST_GROUP_ID, TEST_ARTIFACT_ID).get(); MetadataEventResponse response = handler.refreshProjectRevisionArtifacts(projectData, getFiles(VersionValidator.MASTER_SNAPSHOT)); Assert.assertNotNull(response); @@ -105,7 +113,9 @@ public void canRefreshVersions() { Assert.assertTrue(generations.getAll().isEmpty()); - FileGenerationVersionsHandler handler = new FileGenerationVersionsHandler(repository, fileGenerationsProvider, generations); + ArtifactGenerationHandler artifactGenerationHandler = new ArtifactGenerationHandler(repository, artifactGenerations); + FileGenerationHandler fileGenerationHandler = new FileGenerationHandler(repository, generations); + FileArtifactGenerationVersionsHandler handler = new FileArtifactGenerationVersionsHandler(fileGenerationsProvider, artifactGenerationHandler, fileGenerationHandler); ProjectData projectData = projects.find(TEST_GROUP_ID, TEST_ARTIFACT_ID).get(); MetadataEventResponse response = handler.refreshProjectVersionArtifacts(projectData, "2.0.0", getFiles("2.0.0")); Assert.assertNotNull(response); @@ -121,7 +131,9 @@ public void canRefreshVersions() public void canReadFileGenerationArtifactsWithMultipleGenerations() { Assert.assertTrue(generations.getAll().isEmpty()); - FileGenerationVersionsHandler handler = new FileGenerationVersionsHandler(repository, fileGenerationsProvider, generations); + ArtifactGenerationHandler artifactGenerationHandler = new ArtifactGenerationHandler(repository, artifactGenerations); + FileGenerationHandler fileGenerationHandler = new FileGenerationHandler(repository, generations); + FileArtifactGenerationVersionsHandler handler = new FileArtifactGenerationVersionsHandler(fileGenerationsProvider, artifactGenerationHandler, fileGenerationHandler); ProjectData projectData = projects.find(TEST_GROUP_ID, TEST_ARTIFACT_ID).get(); MetadataEventResponse response = handler.refreshProjectVersionArtifacts(projectData, "2.0.0", getFiles("2.0.0")); Assert.assertNotNull(response); diff --git a/legend-depot-core-services/src/main/java/org/finos/legend/depot/services/AdminServicesModule.java b/legend-depot-core-services/src/main/java/org/finos/legend/depot/services/AdminServicesModule.java index 99a7cc44d..b17eb7dd2 100644 --- a/legend-depot-core-services/src/main/java/org/finos/legend/depot/services/AdminServicesModule.java +++ b/legend-depot-core-services/src/main/java/org/finos/legend/depot/services/AdminServicesModule.java @@ -16,19 +16,24 @@ package org.finos.legend.depot.services; import com.google.inject.PrivateModule; +import org.finos.legend.depot.services.api.generation.artifact.ArtifactGenerationsService; +import org.finos.legend.depot.services.api.generation.artifact.ManageArtifactGenerationsService; import org.finos.legend.depot.services.api.entities.ManageEntitiesService; import org.finos.legend.depot.services.api.generation.file.FileGenerationsService; import org.finos.legend.depot.services.api.generation.file.ManageFileGenerationsService; import org.finos.legend.depot.services.api.projects.ManageProjectsService; import org.finos.legend.depot.services.entities.EntitiesServiceImpl; +import org.finos.legend.depot.services.generation.artifact.ArtifactGenerationsServiceImpl; import org.finos.legend.depot.services.generation.file.FileGenerationsServiceImpl; import org.finos.legend.depot.services.projects.ProjectsServiceImpl; import org.finos.legend.depot.store.api.entities.Entities; import org.finos.legend.depot.store.api.entities.UpdateEntities; +import org.finos.legend.depot.store.api.generation.artifact.UpdateArtifactGenerations; import org.finos.legend.depot.store.api.generation.file.UpdateFileGenerations; import org.finos.legend.depot.store.api.projects.Projects; import org.finos.legend.depot.store.api.projects.UpdateProjects; import org.finos.legend.depot.store.mongo.entities.EntitiesMongo; +import org.finos.legend.depot.store.mongo.generation.artifact.ArtifactGenerationsMongo; import org.finos.legend.depot.store.mongo.generation.file.FileGenerationsMongo; import org.finos.legend.depot.store.mongo.projects.ProjectsMongo; @@ -42,19 +47,24 @@ protected void configure() bind(Entities.class).to(EntitiesMongo.class); bind(UpdateEntities.class).to(EntitiesMongo.class); bind(UpdateFileGenerations.class).to(FileGenerationsMongo.class); + bind(UpdateArtifactGenerations.class).to(ArtifactGenerationsMongo.class); bind(ManageProjectsService.class).to(ProjectsServiceImpl.class); bind(ManageEntitiesService.class).to(EntitiesServiceImpl.class); bind(FileGenerationsService.class).to(FileGenerationsServiceImpl.class); bind(ManageFileGenerationsService.class).to(FileGenerationsServiceImpl.class); + bind(ArtifactGenerationsService.class).to(ArtifactGenerationsServiceImpl.class); + bind(ManageArtifactGenerationsService.class).to(ArtifactGenerationsServiceImpl.class); expose(ManageProjectsService.class); expose(ManageEntitiesService.class); expose(ManageFileGenerationsService.class); + expose(ManageArtifactGenerationsService.class); expose(UpdateEntities.class); expose(Entities.class); expose(UpdateFileGenerations.class); + expose(UpdateArtifactGenerations.class); expose(Projects.class); expose(UpdateProjects.class); } diff --git a/legend-depot-core-services/src/main/java/org/finos/legend/depot/services/ReadOnlyServicesModule.java b/legend-depot-core-services/src/main/java/org/finos/legend/depot/services/ReadOnlyServicesModule.java index 54773f79b..f4e89269e 100644 --- a/legend-depot-core-services/src/main/java/org/finos/legend/depot/services/ReadOnlyServicesModule.java +++ b/legend-depot-core-services/src/main/java/org/finos/legend/depot/services/ReadOnlyServicesModule.java @@ -16,21 +16,26 @@ package org.finos.legend.depot.services; import com.google.inject.PrivateModule; +import org.finos.legend.depot.services.api.generation.artifact.ArtifactGenerationsService; import org.finos.legend.depot.services.api.entities.EntitiesService; import org.finos.legend.depot.services.api.generation.file.FileGenerationsService; import org.finos.legend.depot.services.api.entities.EntityClassifierService; import org.finos.legend.depot.services.api.projects.ProjectsService; import org.finos.legend.depot.services.entities.EntitiesServiceImpl; +import org.finos.legend.depot.services.generation.artifact.ArtifactGenerationsServiceImpl; import org.finos.legend.depot.services.generation.file.FileGenerationsServiceImpl; import org.finos.legend.depot.services.entities.EntityClassifierServiceImpl; import org.finos.legend.depot.services.projects.ProjectsServiceImpl; import org.finos.legend.depot.store.api.entities.Entities; import org.finos.legend.depot.store.api.entities.UpdateEntities; +import org.finos.legend.depot.store.api.generation.artifact.ArtifactGenerations; +import org.finos.legend.depot.store.api.generation.artifact.UpdateArtifactGenerations; import org.finos.legend.depot.store.api.generation.file.FileGenerations; import org.finos.legend.depot.store.api.generation.file.UpdateFileGenerations; import org.finos.legend.depot.store.api.projects.Projects; import org.finos.legend.depot.store.api.projects.UpdateProjects; import org.finos.legend.depot.store.mongo.entities.EntitiesMongo; +import org.finos.legend.depot.store.mongo.generation.artifact.ArtifactGenerationsMongo; import org.finos.legend.depot.store.mongo.generation.file.FileGenerationsMongo; import org.finos.legend.depot.store.mongo.projects.ProjectsMongo; @@ -45,15 +50,19 @@ protected void configure() bind(UpdateProjects.class).to(ProjectsMongo.class); bind(FileGenerations.class).to(FileGenerationsMongo.class); bind(UpdateFileGenerations.class).to(FileGenerationsMongo.class); + bind(ArtifactGenerations.class).to(ArtifactGenerationsMongo.class); + bind(UpdateArtifactGenerations.class).to(ArtifactGenerationsMongo.class); bind(EntitiesService.class).to(EntitiesServiceImpl.class); bind(EntityClassifierService.class).to(EntityClassifierServiceImpl.class); bind(ProjectsService.class).to(ProjectsServiceImpl.class); bind(FileGenerationsService.class).to(FileGenerationsServiceImpl.class); + bind(ArtifactGenerationsService.class).to(ArtifactGenerationsServiceImpl.class); expose(ProjectsService.class); expose(EntitiesService.class); expose(EntityClassifierService.class); expose(FileGenerationsService.class); + expose(ArtifactGenerationsService.class); } } diff --git a/legend-depot-core-services/src/main/java/org/finos/legend/depot/services/api/generation/artifact/ArtifactGenerationsService.java b/legend-depot-core-services/src/main/java/org/finos/legend/depot/services/api/generation/artifact/ArtifactGenerationsService.java new file mode 100644 index 000000000..5bcc59440 --- /dev/null +++ b/legend-depot-core-services/src/main/java/org/finos/legend/depot/services/api/generation/artifact/ArtifactGenerationsService.java @@ -0,0 +1,58 @@ +// Copyright 2022 Goldman Sachs +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// + +package org.finos.legend.depot.services.api.generation.artifact; + +import java.util.List; +import java.util.Optional; +import org.finos.legend.depot.domain.generation.artifact.ArtifactGeneration; + +import static org.finos.legend.depot.domain.version.VersionValidator.MASTER_SNAPSHOT; + + +public interface ArtifactGenerationsService +{ + List getArtifactGenerations(String groupId, String artifactId, String versionId); + + default List getLatestArtifactGenerations(String groupId, String artifactId) + { + return getArtifactGenerations(groupId, artifactId, MASTER_SNAPSHOT); + } + + Optional getArtifactGenerationByPath(String groupId, String artifactId, String versionId, String path); + + default Optional getLatestArtifactGenerationByPath(String groupId, String artifactId, String path) + { + return getArtifactGenerationByPath(groupId, artifactId, MASTER_SNAPSHOT, path); + } + + default Optional getArtifactGenerationContentByPath(String groupId, String artifactId, String versionId, String path) + { + return getArtifactGenerationByPath(groupId, artifactId, versionId, path).map(o -> o.getContent()); + } + + default Optional getLatestArtifactGenerationContentByPath(String groupId, String artifactId, String path) + { + return getArtifactGenerationByPath(groupId, artifactId, MASTER_SNAPSHOT, path).map(o -> o.getContent()); + } + + List getArtifactsGenerationsByGenerator(String groupId, String artifactId, String versionId, String entityPath); + + default List getLatestArtifactsGenerationsByGenerator(String groupId, String artifactId, String entityPath) + { + return getArtifactsGenerationsByGenerator(groupId, artifactId, MASTER_SNAPSHOT, entityPath); + } + +} diff --git a/legend-depot-core-services/src/main/java/org/finos/legend/depot/services/api/generation/artifact/ManageArtifactGenerationsService.java b/legend-depot-core-services/src/main/java/org/finos/legend/depot/services/api/generation/artifact/ManageArtifactGenerationsService.java new file mode 100644 index 000000000..6aa70ae06 --- /dev/null +++ b/legend-depot-core-services/src/main/java/org/finos/legend/depot/services/api/generation/artifact/ManageArtifactGenerationsService.java @@ -0,0 +1,39 @@ +// Copyright 2022 Goldman Sachs +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// + +package org.finos.legend.depot.services.api.generation.artifact; + +import static org.finos.legend.depot.domain.version.VersionValidator.MASTER_SNAPSHOT; + +import java.util.List; +import org.finos.legend.depot.domain.generation.artifact.StoredArtifactGeneration; + + +public interface ManageArtifactGenerationsService extends ArtifactGenerationsService +{ + + void delete(String groupId, String artifactId, String versionId); + + default void deleteLatest(String groupId, String artifactId) + { + delete(groupId, artifactId, MASTER_SNAPSHOT); + } + + void createOrUpdate(StoredArtifactGeneration artifactGeneration); + + List getAll(); + + +} diff --git a/legend-depot-core-services/src/main/java/org/finos/legend/depot/services/generation/artifact/ArtifactGenerationsServiceImpl.java b/legend-depot-core-services/src/main/java/org/finos/legend/depot/services/generation/artifact/ArtifactGenerationsServiceImpl.java new file mode 100644 index 000000000..a509f2458 --- /dev/null +++ b/legend-depot-core-services/src/main/java/org/finos/legend/depot/services/generation/artifact/ArtifactGenerationsServiceImpl.java @@ -0,0 +1,76 @@ +// Copyright 2022 Goldman Sachs +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// + +package org.finos.legend.depot.services.generation.artifact; + +import java.util.List; +import java.util.Optional; +import java.util.stream.Collectors; +import javax.inject.Inject; +import org.finos.legend.depot.domain.generation.artifact.ArtifactGeneration; +import org.finos.legend.depot.domain.generation.artifact.StoredArtifactGeneration; +import org.finos.legend.depot.services.api.generation.artifact.ArtifactGenerationsService; +import org.finos.legend.depot.services.api.generation.artifact.ManageArtifactGenerationsService; +import org.finos.legend.depot.store.api.generation.artifact.UpdateArtifactGenerations; + +public class ArtifactGenerationsServiceImpl implements ArtifactGenerationsService, ManageArtifactGenerationsService +{ + + private final UpdateArtifactGenerations artifactGenerationsUpdater; + + @Inject + public ArtifactGenerationsServiceImpl(UpdateArtifactGenerations artifactGenerations) + { + this.artifactGenerationsUpdater = artifactGenerations; + } + + @Override + public List getAll() + { + return artifactGenerationsUpdater.getAll(); + } + + @Override + public void delete(String groupId, String artifactId, String versionId) + { + artifactGenerationsUpdater.delete(groupId, artifactId, versionId); + } + + @Override + public void createOrUpdate(StoredArtifactGeneration artifactGeneration) + { + artifactGenerationsUpdater.createOrUpdate(artifactGeneration); + } + + @Override + public List getArtifactGenerations(String groupId, String artifactId, String versionId) + { + return artifactGenerationsUpdater.find(groupId, artifactId, versionId).stream().map(StoredArtifactGeneration::getArtifact).collect(Collectors.toList()); + } + + @Override + public List getArtifactsGenerationsByGenerator(String groupId, String artifactId, String versionId, String generatorPath) + { + return artifactGenerationsUpdater.findByGenerator(groupId, artifactId, versionId, generatorPath).stream().map(StoredArtifactGeneration::getArtifact).collect(Collectors.toList()); + } + + @Override + public Optional getArtifactGenerationByPath(String groupId, String artifactId, String versionId, String path) + { + return artifactGenerationsUpdater.get(groupId, artifactId, versionId, path).map(StoredArtifactGeneration::getArtifact); + } + + +} diff --git a/legend-depot-core-services/src/test/java/org/finos/legend/depot/services/generation/artifact/TestArtifactGenerationsService.java b/legend-depot-core-services/src/test/java/org/finos/legend/depot/services/generation/artifact/TestArtifactGenerationsService.java new file mode 100644 index 000000000..4f07e63ef --- /dev/null +++ b/legend-depot-core-services/src/test/java/org/finos/legend/depot/services/generation/artifact/TestArtifactGenerationsService.java @@ -0,0 +1,143 @@ +// Copyright 2022 Goldman Sachs +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// + +package org.finos.legend.depot.services.generation.artifact; + +import java.io.File; +import java.net.URL; +import java.util.List; +import java.util.Optional; +import java.util.stream.Stream; +import org.finos.legend.depot.domain.generation.artifact.ArtifactGeneration; +import org.finos.legend.depot.domain.generation.artifact.StoredArtifactGeneration; +import org.finos.legend.depot.domain.generation.file.FileGeneration; +import org.finos.legend.depot.domain.version.VersionValidator; +import org.finos.legend.depot.services.api.generation.artifact.ManageArtifactGenerationsService; +import org.finos.legend.depot.services.generation.file.TestFileGenerationsService; +import org.finos.legend.depot.store.api.entities.Entities; +import org.finos.legend.depot.store.api.generation.artifact.UpdateArtifactGenerations; +import org.finos.legend.depot.store.mongo.TestStoreMongo; +import org.finos.legend.depot.store.mongo.entities.EntitiesMongo; +import org.finos.legend.depot.store.mongo.generation.artifact.ArtifactGenerationsMongo; +import org.finos.legend.depot.store.mongo.generation.file.FileGenerationLoader; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; + +public class TestArtifactGenerationsService extends TestStoreMongo +{ + + protected Entities entities = new EntitiesMongo(mongoProvider); + + private static final URL filePath = TestFileGenerationsService.class.getClassLoader().getResource("file-generation/test-file-generation-master-SNAPSHOT.jar"); + + private UpdateArtifactGenerations generations = new ArtifactGenerationsMongo(mongoProvider); + + private ManageArtifactGenerationsService service = new ArtifactGenerationsServiceImpl(generations); + + private static String GROUP_ID = "group.test"; + private static String ARTIFACT_ID = "test"; + + @Before + public void loadData() throws Exception + { + + try (FileGenerationLoader file = FileGenerationLoader.newFileGenerationsLoader(new File(filePath.toURI()))) + { + Stream data = file.getAllFileGenerations(); + Assert.assertNotNull(data); + data.forEach(gen -> + { + ArtifactGeneration generation = new ArtifactGeneration(gen.getPath(), gen.getContent()); + generations.createOrUpdate(new StoredArtifactGeneration(GROUP_ID, ARTIFACT_ID, VersionValidator.MASTER_SNAPSHOT, "model::generator::MyGenerator", generation)); + generations.createOrUpdate(new StoredArtifactGeneration(GROUP_ID, ARTIFACT_ID, "1.0.1", null, generation)); + generations.createOrUpdate(new StoredArtifactGeneration(GROUP_ID, ARTIFACT_ID, "1.0.0", "model::generator::MyGenerator", generation)); + generations.createOrUpdate(new StoredArtifactGeneration("group.test.otherproject", "test", "1.0.0", null, generation)); + }); + + Assert.assertEquals(52, generations.getAll().size()); + } + } + + @Test + public void canDelete() + { + + service.deleteLatest(GROUP_ID, ARTIFACT_ID); + Assert.assertEquals(39, generations.getAll().size()); + service.delete("group.test.otherproject", "test", "1.0.0"); + Assert.assertEquals(26, generations.getAll().size()); + service.delete(GROUP_ID, ARTIFACT_ID, "1.1.0"); + Assert.assertEquals(26, generations.getAll().size()); + } + + @Test + + public void canGetArtifactGeneration() + { + List masterArtifactGenerations = service.getArtifactGenerations(GROUP_ID, ARTIFACT_ID, VersionValidator.MASTER_SNAPSHOT); + Assert.assertEquals(13, masterArtifactGenerations.size()); + List lastestArtifactGenerations = service.getLatestArtifactGenerations(GROUP_ID, ARTIFACT_ID); + Assert.assertEquals(13, lastestArtifactGenerations.size()); + List artifactGenerationsFirst = service.getArtifactGenerations(GROUP_ID, ARTIFACT_ID, "1.0.0"); + Assert.assertEquals(13, artifactGenerationsFirst.size()); + List artifactGenerations = service.getArtifactGenerations(GROUP_ID, ARTIFACT_ID, "1.0.1"); + Assert.assertEquals(13, artifactGenerations.size()); + } + + + @Test + public void canGetArtifactsByGenerator() + { + List masterArtifactGenerations = service.getLatestArtifactsGenerationsByGenerator(GROUP_ID, ARTIFACT_ID, "model::generator::MyGenerator"); + Assert.assertEquals(13, masterArtifactGenerations.size()); + + List artifactGenerations = service.getArtifactsGenerationsByGenerator(GROUP_ID, ARTIFACT_ID, "1.0.0", "model::generator::MyGenerator"); + Assert.assertEquals(13, artifactGenerations.size()); + + List noArtifactsGeneration = service.getArtifactsGenerationsByGenerator(GROUP_ID, ARTIFACT_ID, "1.0.0", "model::generator::MISSING"); + Assert.assertEquals(0, noArtifactsGeneration.size()); + + } + + + @Test + public void canGetArtifactsByPath() + { + String path = "/model/generator/MyGenerator/my-ext/Artifactgeneration.txt"; + String expectedContent = "My Generated Artifact for model::generator::MyGenerator."; + Optional artifactGenerationOptional = service.getArtifactGenerationByPath(GROUP_ID, ARTIFACT_ID, "1.0.1", path); + Assert.assertTrue(artifactGenerationOptional.isPresent()); + Assert.assertEquals(expectedContent, artifactGenerationOptional.get().getContent()); + + Optional latestArtifact = service.getLatestArtifactGenerationByPath(GROUP_ID, ARTIFACT_ID,path); + Assert.assertTrue(latestArtifact.isPresent()); + Assert.assertEquals(expectedContent, latestArtifact.get().getContent()); + + Optional missingGeneration = service.getArtifactGenerationByPath(GROUP_ID, ARTIFACT_ID, "10.0.1", path); + Assert.assertTrue(!missingGeneration.isPresent()); + + Optional artifactContent = service.getArtifactGenerationContentByPath(GROUP_ID, ARTIFACT_ID, "1.0.1", path); + Assert.assertTrue(artifactContent.isPresent()); + Assert.assertEquals(expectedContent, artifactContent.get()); + + Optional latestContent = service.getLatestArtifactGenerationContentByPath(GROUP_ID, ARTIFACT_ID, path); + Assert.assertTrue(latestContent.isPresent()); + Assert.assertEquals(expectedContent, latestContent.get()); + } + + + +} diff --git a/legend-depot-core-services/src/test/java/org/finos/legend/depot/services/generation/file/TestFileGenerationsService.java b/legend-depot-core-services/src/test/java/org/finos/legend/depot/services/generation/file/TestFileGenerationsService.java index 9b9f1eaff..6ec709ec6 100644 --- a/legend-depot-core-services/src/test/java/org/finos/legend/depot/services/generation/file/TestFileGenerationsService.java +++ b/legend-depot-core-services/src/test/java/org/finos/legend/depot/services/generation/file/TestFileGenerationsService.java @@ -53,13 +53,16 @@ public void loadData() throws Exception Assert.assertNotNull(data); data.forEach(gen -> { - FileGeneration generation = new FileGeneration(gen.getPath().replace("examples_avrogen/", ""), gen.getContent()); - generations.createOrUpdate(new StoredFileGeneration("group.test", "test", VersionValidator.MASTER_SNAPSHOT, "examples::avrogen", AVRO, generation)); - generations.createOrUpdate(new StoredFileGeneration("group.test", "test", "1.0.1", "examples::avrogen", AVRO, generation)); - generations.createOrUpdate(new StoredFileGeneration("group.test", "test", "1.0.0", "examples::avrogen", AVRO, generation)); - generations.createOrUpdate(new StoredFileGeneration("group.test.otherproject", "test", "1.0.0", "examples::avrogen1", AVRO, generation)); - }); + if (!gen.getPath().startsWith("/model/")) + { + FileGeneration generation = new FileGeneration(gen.getPath().replace("examples_avrogen/", ""), gen.getContent()); + generations.createOrUpdate(new StoredFileGeneration("group.test", "test", VersionValidator.MASTER_SNAPSHOT, "examples::avrogen", AVRO, generation)); + generations.createOrUpdate(new StoredFileGeneration("group.test", "test", "1.0.1", "examples::avrogen", AVRO, generation)); + generations.createOrUpdate(new StoredFileGeneration("group.test", "test", "1.0.0", "examples::avrogen", AVRO, generation)); + generations.createOrUpdate(new StoredFileGeneration("group.test.otherproject", "test", "1.0.0", "examples::avrogen1", AVRO, generation)); + } + }); Assert.assertEquals(48, generations.getAll().size()); } } diff --git a/legend-depot-core-services/src/test/resources/file-generation/test-file-generation-master-SNAPSHOT.jar b/legend-depot-core-services/src/test/resources/file-generation/test-file-generation-master-SNAPSHOT.jar index 1aa5b4e89..1a02caa02 100644 Binary files a/legend-depot-core-services/src/test/resources/file-generation/test-file-generation-master-SNAPSHOT.jar and b/legend-depot-core-services/src/test/resources/file-generation/test-file-generation-master-SNAPSHOT.jar differ diff --git a/legend-depot-core-tracing/src/main/java/org/finos/legend/depot/tracing/resources/ResourceLoggingAndTracing.java b/legend-depot-core-tracing/src/main/java/org/finos/legend/depot/tracing/resources/ResourceLoggingAndTracing.java index 1eaf2cf90..421b99dac 100644 --- a/legend-depot-core-tracing/src/main/java/org/finos/legend/depot/tracing/resources/ResourceLoggingAndTracing.java +++ b/legend-depot-core-tracing/src/main/java/org/finos/legend/depot/tracing/resources/ResourceLoggingAndTracing.java @@ -54,6 +54,14 @@ public class ResourceLoggingAndTracing public static final String GET_VERSION_FILE_GENERATION = "get version file generations"; public static final String GET_VERSION_FILE_GENERATION_BY_PATH = "get version file generations by path"; public static final String GET_VERSION_FILE_GENERATION_BY_FILEPATH = "get revision file generations by file"; + public static final String GET_LATEST_ARTIFACT_GENERATIONS = "get latest artifact generations"; + public static final String GET_ARTIFACT_GENERATIONS = "get artifact generations"; + public static final String GET_ARTIFACT_GENERATIONS_BY_GENERATOR = "get artifact generations by generator"; + public static final String GET_LATEST_ARTIFACT_GENERATIONS_BY_GENERATOR = "get latest artifact generations by generator"; + public static final String GET_ARTIFACT_GENERATION_BY_PATH = "get artifact generation by path"; + public static final String GET_LATEST_ARTIFACT_GENERATION_BY_PATH = "get latest artifact generation by path"; + public static final String GET_ARTIFACT_GENERATION_CONTENT_BY_PATH = "get artifact generation content by path"; + public static final String GET_LATEST_ARTIFACT_GENERATION_CONTENT_BY_PATH = "get latest artifact generation content by path"; public static final String GET_ALL_EVENTS_IN_QUEUE = "get all queue events"; public static final String FIND_PAST_EVENTS = "find past events"; public static final String ENQUEUE_EVENT = "enqueue event"; diff --git a/legend-depot-model/src/main/java/org/finos/legend/depot/domain/generation/artifact/ArtifactGeneration.java b/legend-depot-model/src/main/java/org/finos/legend/depot/domain/generation/artifact/ArtifactGeneration.java new file mode 100644 index 000000000..6d7751462 --- /dev/null +++ b/legend-depot-model/src/main/java/org/finos/legend/depot/domain/generation/artifact/ArtifactGeneration.java @@ -0,0 +1,62 @@ +// Copyright 2022 Goldman Sachs +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// + +package org.finos.legend.depot.domain.generation.artifact; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import org.apache.commons.lang.builder.EqualsBuilder; +import org.apache.commons.lang.builder.HashCodeBuilder; + +@JsonIgnoreProperties(ignoreUnknown = true) +public class ArtifactGeneration +{ + + @JsonProperty + private String content; + + @JsonProperty + private String path; + + @JsonCreator + public ArtifactGeneration(@JsonProperty(value = "path") String path, @JsonProperty(value = "content") String content) + { + this.content = content; + this.path = path; + } + + public String getPath() + { + return path; + } + + public String getContent() + { + return content; + } + + @Override + public boolean equals(Object obj) + { + return EqualsBuilder.reflectionEquals(this, obj); + } + + @Override + public int hashCode() + { + return HashCodeBuilder.reflectionHashCode(this); + } +} diff --git a/legend-depot-model/src/main/java/org/finos/legend/depot/domain/generation/artifact/StoredArtifactGeneration.java b/legend-depot-model/src/main/java/org/finos/legend/depot/domain/generation/artifact/StoredArtifactGeneration.java new file mode 100644 index 000000000..379732c9a --- /dev/null +++ b/legend-depot-model/src/main/java/org/finos/legend/depot/domain/generation/artifact/StoredArtifactGeneration.java @@ -0,0 +1,86 @@ +// Copyright 2022 Goldman Sachs +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// + +package org.finos.legend.depot.domain.generation.artifact; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonProperty; +import javax.validation.constraints.NotNull; +import org.apache.commons.lang.builder.EqualsBuilder; +import org.apache.commons.lang.builder.HashCodeBuilder; +import org.finos.legend.depot.domain.BaseDomain; +import org.finos.legend.depot.domain.HasIdentifier; + +public class StoredArtifactGeneration extends BaseDomain implements HasIdentifier +{ + @JsonProperty + private String id; + + @JsonProperty + @NotNull + private String versionId; + + @JsonProperty + private String generator; + + @JsonProperty + private ArtifactGeneration artifact; + + @JsonCreator + public StoredArtifactGeneration(@JsonProperty(value = "groupId") String groupId, + @JsonProperty(value = "artifactId") String artifactId, + @JsonProperty(value = "versionId") String versionId, + @JsonProperty(value = "generator") String generator, + @JsonProperty(value = "artifact") ArtifactGeneration artifact) + { + super(groupId, artifactId); + this.versionId = versionId; + this.generator = generator; + this.artifact = artifact; + } + + @Override + public String getId() + { + return id; + } + + public String getVersionId() + { + return versionId; + } + + public String getGenerator() + { + return generator; + } + + public ArtifactGeneration getArtifact() + { + return artifact; + } + + @Override + public boolean equals(Object obj) + { + return EqualsBuilder.reflectionEquals(this, obj); + } + + @Override + public int hashCode() + { + return HashCodeBuilder.reflectionHashCode(this); + } +} diff --git a/legend-depot-server/src/main/java/org/finos/legend/depot/server/guice/DepotServerResourcesModule.java b/legend-depot-server/src/main/java/org/finos/legend/depot/server/guice/DepotServerResourcesModule.java index 4bfba6d1f..b1f4e0257 100644 --- a/legend-depot-server/src/main/java/org/finos/legend/depot/server/guice/DepotServerResourcesModule.java +++ b/legend-depot-server/src/main/java/org/finos/legend/depot/server/guice/DepotServerResourcesModule.java @@ -17,6 +17,7 @@ import com.google.inject.PrivateModule; import org.finos.legend.depot.server.resources.ProjectsResource; +import org.finos.legend.depot.server.resources.artifact.ArtifactGenerationsResource; import org.finos.legend.depot.server.resources.dependencies.DependenciesResource; import org.finos.legend.depot.server.resources.entities.EntitiesResource; import org.finos.legend.depot.server.resources.file.FileGenerationsResource; @@ -32,11 +33,13 @@ protected void configure() bind(EntityClassifierResource.class); bind(DependenciesResource.class); bind(FileGenerationsResource.class); + bind(ArtifactGenerationsResource.class); expose(ProjectsResource.class); expose(EntityClassifierResource.class); expose(EntitiesResource.class); expose(DependenciesResource.class); expose(FileGenerationsResource.class); + expose(ArtifactGenerationsResource.class); } } \ No newline at end of file diff --git a/legend-depot-server/src/main/java/org/finos/legend/depot/server/resources/artifact/ArtifactGenerationsResource.java b/legend-depot-server/src/main/java/org/finos/legend/depot/server/resources/artifact/ArtifactGenerationsResource.java new file mode 100644 index 000000000..92849e5f1 --- /dev/null +++ b/legend-depot-server/src/main/java/org/finos/legend/depot/server/resources/artifact/ArtifactGenerationsResource.java @@ -0,0 +1,96 @@ +// Copyright 2022 Goldman Sachs +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// + +package org.finos.legend.depot.server.resources.artifact; + +import static org.finos.legend.depot.tracing.resources.ResourceLoggingAndTracing.GET_ARTIFACT_GENERATIONS; +import static org.finos.legend.depot.tracing.resources.ResourceLoggingAndTracing.GET_ARTIFACT_GENERATIONS_BY_GENERATOR; +import static org.finos.legend.depot.tracing.resources.ResourceLoggingAndTracing.GET_ARTIFACT_GENERATION_BY_PATH; +import static org.finos.legend.depot.tracing.resources.ResourceLoggingAndTracing.GET_ARTIFACT_GENERATION_CONTENT_BY_PATH; +import static org.finos.legend.depot.tracing.resources.ResourceLoggingAndTracing.GET_REVISION_FILE_GENERATION_ENTITIES; + +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import java.util.List; +import java.util.Optional; +import javax.inject.Inject; +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; +import javax.ws.rs.Produces; +import javax.ws.rs.core.MediaType; +import org.finos.legend.depot.domain.generation.artifact.ArtifactGeneration; +import org.finos.legend.depot.services.api.generation.artifact.ArtifactGenerationsService; +import org.finos.legend.depot.store.metrics.QueryMetricsContainer; +import org.finos.legend.depot.tracing.resources.BaseResource; + +@Path("artifactGenerations") +@Api("Artifact Generations") +public class ArtifactGenerationsResource extends BaseResource +{ + private final ArtifactGenerationsService artifactGenerationService; + + @Inject + public ArtifactGenerationsResource(ArtifactGenerationsService artifactGenerationService) + { + this.artifactGenerationService = artifactGenerationService; + } + + @GET + @Path("/{groupId}/{artifactId}/{versionId}") + @ApiOperation(GET_ARTIFACT_GENERATIONS) + @Produces(MediaType.APPLICATION_JSON) + public List getArtifactGenerations(@PathParam("groupId") String groupId, @PathParam("artifactId") String artifactId, @PathParam("versionId") String versionId) + { + QueryMetricsContainer.record(groupId, artifactId, versionId); + return handle(GET_REVISION_FILE_GENERATION_ENTITIES, () -> this.artifactGenerationService.getArtifactGenerations(groupId, artifactId, versionId)); + } + + @GET + @Path("/{groupId}/{artifactId}/{versionId}/artifact{path}") + @ApiOperation(GET_ARTIFACT_GENERATION_BY_PATH) + @Produces(MediaType.APPLICATION_JSON) + public Optional getArtifactGenerationByPath(@PathParam("groupId") String groupId, @PathParam("artifactId") String artifactId, @PathParam("versionId") String versionId, + @PathParam("path") String path) + { + QueryMetricsContainer.record(groupId, artifactId, versionId); + return handle(GET_ARTIFACT_GENERATION_BY_PATH, () -> this.artifactGenerationService.getArtifactGenerationByPath(groupId, artifactId, versionId, path)); + } + + @GET + @Path("/{groupId}/{artifactId}/{versionId}/artifact/{path}/content") + @ApiOperation(GET_ARTIFACT_GENERATION_CONTENT_BY_PATH) + @Produces(MediaType.TEXT_PLAIN) + public Optional getArtifactGenerationContentByPath(@PathParam("groupId") String groupId, @PathParam("artifactId") String artifactId, @PathParam("versionId") String versionId, + @PathParam("path") String path) + { + QueryMetricsContainer.record(groupId, artifactId, versionId); + return handle(GET_ARTIFACT_GENERATION_CONTENT_BY_PATH, () -> this.artifactGenerationService.getArtifactGenerationContentByPath(groupId, artifactId, versionId, path)); + } + + @GET + @Path("/{groupId}/{artifactId}/{versionId}/generator/{generatorPath}") + @ApiOperation(GET_ARTIFACT_GENERATIONS_BY_GENERATOR) + @Produces(MediaType.APPLICATION_JSON) + public List getArtifactGenerationsByGenerator(@PathParam("groupId") String groupId, @PathParam("artifactId") String artifactId, @PathParam("versionId") String versionId, + @PathParam("generatorPath") String generatorPath) + { + + QueryMetricsContainer.record(groupId, artifactId, versionId); + return handle(GET_ARTIFACT_GENERATIONS_BY_GENERATOR, () -> this.artifactGenerationService.getArtifactsGenerationsByGenerator(groupId, artifactId, versionId, generatorPath)); + } + + +} diff --git a/legend-depot-store-api/src/main/java/org/finos/legend/depot/store/api/generation/artifact/ArtifactGenerations.java b/legend-depot-store-api/src/main/java/org/finos/legend/depot/store/api/generation/artifact/ArtifactGenerations.java new file mode 100644 index 000000000..2185cab64 --- /dev/null +++ b/legend-depot-store-api/src/main/java/org/finos/legend/depot/store/api/generation/artifact/ArtifactGenerations.java @@ -0,0 +1,35 @@ +// Copyright 2022 Goldman Sachs +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// + +package org.finos.legend.depot.store.api.generation.artifact; + +import java.util.List; +import java.util.Optional; +import org.finos.legend.depot.domain.generation.artifact.StoredArtifactGeneration; + +public interface ArtifactGenerations +{ + + List getAll(); + + Optional get(String groupId, String artifactId, String versionId, String filePath); + + List find(String groupId, String artifactId, String versionId); + + List findByGenerator(String groupId, String artifactId, String versionId, String entityPath); + + // TODO: We may want to add find by folder path + +} diff --git a/legend-depot-store-api/src/main/java/org/finos/legend/depot/store/api/generation/artifact/UpdateArtifactGenerations.java b/legend-depot-store-api/src/main/java/org/finos/legend/depot/store/api/generation/artifact/UpdateArtifactGenerations.java new file mode 100644 index 000000000..55eac53a6 --- /dev/null +++ b/legend-depot-store-api/src/main/java/org/finos/legend/depot/store/api/generation/artifact/UpdateArtifactGenerations.java @@ -0,0 +1,28 @@ +// Copyright 2021 Goldman Sachs +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// + +package org.finos.legend.depot.store.api.generation.artifact; + +import org.finos.legend.depot.domain.generation.artifact.StoredArtifactGeneration; + +public interface UpdateArtifactGenerations extends ArtifactGenerations +{ + StoredArtifactGeneration createOrUpdate(StoredArtifactGeneration artifactGenerations); + + boolean delete(String groupId, String artifactId, String versionId); + + boolean createIndexesIfAbsent(); + +} diff --git a/legend-depot-store-mongo/pom.xml b/legend-depot-store-mongo/pom.xml index 344098cf4..f1487b8f6 100644 --- a/legend-depot-store-mongo/pom.xml +++ b/legend-depot-store-mongo/pom.xml @@ -95,6 +95,14 @@ + + org.apache.maven.plugins + maven-compiler-plugin + + 11 + 11 + + \ No newline at end of file diff --git a/legend-depot-store-mongo/src/main/java/org/finos/legend/depot/store/mongo/generation/artifact/ArtifactGenerationsMongo.java b/legend-depot-store-mongo/src/main/java/org/finos/legend/depot/store/mongo/generation/artifact/ArtifactGenerationsMongo.java new file mode 100644 index 000000000..54b7a5de6 --- /dev/null +++ b/legend-depot-store-mongo/src/main/java/org/finos/legend/depot/store/mongo/generation/artifact/ArtifactGenerationsMongo.java @@ -0,0 +1,111 @@ +// Copyright 2022 Goldman Sachs +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// + +package org.finos.legend.depot.store.mongo.generation.artifact; + +import static com.mongodb.client.model.Filters.and; +import static com.mongodb.client.model.Filters.eq; + +import com.mongodb.client.MongoCollection; +import com.mongodb.client.MongoDatabase; +import java.util.List; +import java.util.Optional; +import javax.inject.Inject; +import javax.inject.Named; +import org.bson.conversions.Bson; +import org.finos.legend.depot.domain.generation.artifact.StoredArtifactGeneration; +import org.finos.legend.depot.store.api.generation.artifact.ArtifactGenerations; +import org.finos.legend.depot.store.api.generation.artifact.UpdateArtifactGenerations; +import org.finos.legend.depot.store.mongo.BaseMongo; + +public class ArtifactGenerationsMongo extends BaseMongo implements ArtifactGenerations, UpdateArtifactGenerations +{ + + public static final String COLLECTION = "artifact-generations"; + private static final String ARTIFACT_PATH = "artifact.path"; + private static final String GENERATOR = "generator"; + + + @Inject + public ArtifactGenerationsMongo(@Named("mongoDatabase") MongoDatabase databaseProvider) + { + super(databaseProvider, StoredArtifactGeneration.class); + } + + @Override + protected MongoCollection getCollection() + { + return getMongoCollection(COLLECTION); + } + + @Override + public List getAll() + { + return getAllStoredEntities(); + } + + @Override + public boolean createIndexesIfAbsent() + { + return createIndexIfAbsent("groupId-artifactId-versionId", GROUP_ID, ARTIFACT_ID, VERSION_ID); + } + + + @Override + protected Bson getKeyFilter(StoredArtifactGeneration data) + { + return and( + getArtifactAndVersionFilter(data.getGroupId(), data.getArtifactId(), data.getVersionId()), + eq(ARTIFACT_PATH, data.getArtifact().getPath()) + ); + } + + @Override + protected void validateNewData(StoredArtifactGeneration data) + { + // no + } + + @Override + public Optional get(String groupId, String artifactId, String versionId, String filePath) + { + return findOne( + and( + getArtifactAndVersionFilter(groupId, artifactId, versionId), + eq(ARTIFACT_PATH, filePath) + ) + ); + } + + @Override + public List find(String groupId, String artifactId, String versionId) + { + return find(getArtifactAndVersionFilter(groupId, artifactId, versionId)); + } + + @Override + public List findByGenerator(String groupId, String artifactId, String versionId, String generatorPath) + { + return find(and(getArtifactAndVersionFilter(groupId, artifactId, versionId), eq(GENERATOR, generatorPath))); + } + + @Override + public boolean delete(String groupId, String artifactId, String versionId) + { + return delete(getArtifactAndVersionFilter(groupId, artifactId, versionId)); + } + + +} \ No newline at end of file diff --git a/legend-depot-store-mongo/src/test/java/org/finos/legend/depot/store/mongo/generation/artifact/TestArtifactsGenerationStore.java b/legend-depot-store-mongo/src/test/java/org/finos/legend/depot/store/mongo/generation/artifact/TestArtifactsGenerationStore.java new file mode 100644 index 000000000..0ce8bd1a9 --- /dev/null +++ b/legend-depot-store-mongo/src/test/java/org/finos/legend/depot/store/mongo/generation/artifact/TestArtifactsGenerationStore.java @@ -0,0 +1,172 @@ +// Copyright 2022 Goldman Sachs +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// + + +package org.finos.legend.depot.store.mongo.generation.artifact; + +import static org.finos.legend.depot.domain.version.VersionValidator.MASTER_SNAPSHOT; + +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.core.type.TypeReference; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.mongodb.client.MongoCollection; +import java.io.InputStream; +import java.net.URL; +import java.util.List; +import java.util.Optional; +import org.bson.Document; +import org.finos.legend.depot.domain.generation.artifact.StoredArtifactGeneration; +import org.finos.legend.depot.store.api.generation.artifact.UpdateArtifactGenerations; +import org.finos.legend.depot.store.mongo.TestStoreMongo; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; + +public class TestArtifactsGenerationStore extends TestStoreMongo +{ + + private UpdateArtifactGenerations generations = new ArtifactGenerationsMongo(mongoProvider); + private static String TEST_GROUP_ID = "examples.metadata"; + private static String TEST_ARTIFACT_ID = "test"; + private static String GENERATOR = "examples::metadata::test::MainGenerator"; + + private List readArtifactGenerations(URL fileName) + { + try + { + InputStream stream = fileName.openStream(); + String jsonInput = new java.util.Scanner(stream).useDelimiter("\\A").next(); + + List generations = new ObjectMapper().readValue(jsonInput, new TypeReference>() + { + }); + Assert.assertNotNull("testing file" + fileName.getFile(), generations); + return generations; + } catch (Exception e) + { + Assert.fail("an error has occurred loading test metadata" + e.getMessage()); + } + return null; + } + + private MongoCollection getMongoArtifactGenerations() + { + return getMongoDatabase().getCollection(ArtifactGenerationsMongo.COLLECTION); + } + + private void setUpArtifactGenerationFromFile(URL generationsData) + { + try + { + readArtifactGenerations(generationsData).forEach(project -> + { + try + { + getMongoArtifactGenerations().insertOne(Document.parse(new ObjectMapper().writeValueAsString(project))); + } catch (JsonProcessingException e) + { + Assert.fail("an error has occurred loading test project metadata" + e.getMessage()); + } + }); + Assert.assertNotNull(getMongoArtifactGenerations()); + } catch (Exception e) + { + Assert.fail("an error has occurred loading test project metadata" + e.getMessage()); + } + } + + @Before + public void loadData() + { + setUpArtifactGenerationFromFile(this.getClass().getClassLoader().getResource("data/artifact-generations.json")); + Assert.assertEquals(9, generations.getAll().size()); + } + + @Test + public void canQueryByVersion() + { + List result = generations.find(TEST_GROUP_ID, TEST_ARTIFACT_ID, "2.3.3"); + Assert.assertEquals(7, result.size()); + + List snapShotVersionResult = generations.find(TEST_GROUP_ID, TEST_ARTIFACT_ID, MASTER_SNAPSHOT); + Assert.assertEquals(2, snapShotVersionResult.size()); + + Assert.assertEquals(0, generations.find(TEST_GROUP_ID, TEST_ARTIFACT_ID, "12.3.2").size()); + } + + @Test + public void canQueryByPath() + { + String filePath = "/examples/metadata/test/dependency/Test.json"; + Optional result = generations.get(TEST_GROUP_ID, TEST_ARTIFACT_ID, "2.3.3", "/examples/metadata/test/dependency/Test.json"); + Assert.assertTrue(result.isPresent()); + StoredArtifactGeneration storedArtifactGeneration = result.get(); + Assert.assertEquals(storedArtifactGeneration.getArtifact().getPath(), filePath); + Assert.assertEquals(storedArtifactGeneration.getArtifact().getContent(), "my test content 3"); + Assert.assertEquals(storedArtifactGeneration.getGenerator(), GENERATOR); + + Optional noResult = generations.get(TEST_GROUP_ID, TEST_ARTIFACT_ID, "2.3.3", "Does/Not/Exist.json"); + Assert.assertTrue(noResult.isEmpty()); + + } + + + @Test + public void canQueryAll() + { + List artifactGenerations = generations.getAll(); + Assert.assertEquals(9, artifactGenerations.size()); + } + + + @Test + public void canFindByGenerator() + { + List artifactGenerations = generations.findByGenerator(TEST_GROUP_ID, TEST_ARTIFACT_ID, "2.3.3", GENERATOR); + Assert.assertEquals(3, artifactGenerations.size()); + artifactGenerations.forEach(a -> Assert.assertEquals(a.getGenerator(), GENERATOR)); + } + + @Test + public void canFindByProject() + { + + List artifactGenerations = generations.find(TEST_GROUP_ID, TEST_ARTIFACT_ID, "2.3.3"); + Assert.assertEquals(7, artifactGenerations.size()); + artifactGenerations.forEach(a -> + { + Assert.assertEquals(TEST_GROUP_ID, a.getGroupId()); + Assert.assertEquals(TEST_ARTIFACT_ID, a.getArtifactId()); + Assert.assertEquals("2.3.3", a.getVersionId()); + }); + + List noGenerations = generations.find(TEST_GROUP_ID, TEST_ARTIFACT_ID, "10.0.0"); + Assert.assertEquals(0, noGenerations.size()); + } + + + @Test + public void canDelete() + { + List artifactGenerations = generations.getAll(); + Assert.assertEquals(9, artifactGenerations.size()); + generations.delete(TEST_GROUP_ID, TEST_ARTIFACT_ID, "2.3.3"); + + List afterGenerations = generations.getAll(); + Assert.assertEquals(2, afterGenerations.size()); + } + + +} diff --git a/legend-depot-store-mongo/src/test/resources/data/artifact-generations.json b/legend-depot-store-mongo/src/test/resources/data/artifact-generations.json new file mode 100644 index 000000000..1edba04a7 --- /dev/null +++ b/legend-depot-store-mongo/src/test/resources/data/artifact-generations.json @@ -0,0 +1,103 @@ +[ + { + "id": "604a224b952ac3ff3cbe31981", + "groupId": "examples.metadata", + "artifactId": "test", + "versionId": "master-SNAPSHOT", + "generator": "examples::metadata::test::MainGenerator", + "artifact": { + "content": "my test content", + "path": "/examples/metadata/test/ClientBasic/my-extension/MyArtifact.txt" + } + }, + { + "id": "604a224b952ac3ff3cbe319d2", + "versionId": "master-SNAPSHOT", + "groupId": "examples.metadata", + "artifactId": "test", + "generator": null, + "artifact": { + "content": "my test content", + "path": "/examples/metadata/test/ClientBasic.json" + } + }, + { + "id": "604a224b952ac3ff3cbe31a03", + "groupId": "examples.metadata", + "artifactId": "test", + "versionId": "2.3.3", + "generator": "examples::metadata::test::MainGenerator", + "artifact": { + "content": "my test content 3", + "path": "/examples/metadata/test/dependency/Test.json" + } + }, + { + "id": "604a224c952ac3ff3cbe31ae4", + "versionId": "2.3.3", + "groupId": "examples.metadata", + "artifactId": "test", + "generator": "examples::metadata::test::MainGenerator", + "type": "protobuf", + "artifact": { + "content": "my test content 3", + "path": "/Root/MyFile.json" + } + }, + { + "id": "604a224c952ac3ff3cbe31b25", + "versionId": "2.3.3", + "groupId": "examples.metadata", + "artifactId": "test", + "generator": "examples::metadata::test::MainGenerator", + "artifact": { + "content": "my test content 4", + "path": "/examples/metadata/test/ClientBasic.proto" + } + }, + { + "id": "604a224c952ac3ff3cbe31b76", + "versionId": "2.3.3", + "groupId": "examples.metadata", + "artifactId": "test", + "generator": "examples::metadata::test::ClientBasic5", + "artifact": { + "content": "my test content 5", + "path": "/examples/metadata/test/dependency/Dependency.proto" + } + }, + { + "id": "604a224c952ac3ff3cbe31bb", + "groupId": "examples.metadata", + "artifactId": "test", + "versionId": "2.3.3", + "generator": "examples::metadata::test::ClientBasic6", + "type": "avro", + "artifact": { + "content": "my test content 6", + "path": "/examples/metadata/test/ClassWithDependency.avro" + } + }, + { + "id": "604a224c952ac3ff3cbe31be7", + "groupId": "examples.metadata", + "artifactId": "test", + "versionId": "2.3.3", + "generator": "examples::metadata::test::ClientBasic7", + "artifact": { + "content": "my test content 7", + "path": "/examples/metadata/test/ClientBasic.avro" + } + }, + { + "id": "604a224c952ac3ff3cbe31c38", + "groupId": "examples.metadata", + "artifactId": "test", + "versionId": "2.3.3", + "generator": null, + "artifact": { + "content": "my test content for nothing", + "path": "/examples/metadata/test/dependency/Dependency.avro" + } + } +] \ No newline at end of file diff --git a/legend-depot-store-server/src/main/java/org/finos/legend/depot/store/resources/projects/ManageProjectsResource.java b/legend-depot-store-server/src/main/java/org/finos/legend/depot/store/resources/projects/ManageProjectsResource.java index 644d159fb..82541aec4 100644 --- a/legend-depot-store-server/src/main/java/org/finos/legend/depot/store/resources/projects/ManageProjectsResource.java +++ b/legend-depot-store-server/src/main/java/org/finos/legend/depot/store/resources/projects/ManageProjectsResource.java @@ -22,14 +22,12 @@ import org.finos.legend.depot.domain.api.MetadataEventResponse; import org.finos.legend.depot.domain.project.ProjectData; import org.finos.legend.depot.services.api.projects.ManageProjectsService; -import org.finos.legend.depot.store.notifications.domain.RefreshAllMetadataNotification; import org.finos.legend.depot.tracing.resources.ResourceLoggingAndTracing; import javax.inject.Inject; import javax.inject.Named; import javax.inject.Provider; import javax.ws.rs.DELETE; -import javax.ws.rs.GET; import javax.ws.rs.PUT; import javax.ws.rs.Path; import javax.ws.rs.PathParam;