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 e0643af7a..a748f4e47 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 @@ -22,6 +22,7 @@ import org.finos.legend.depot.artifacts.repository.domain.ArtifactType; import org.finos.legend.depot.store.admin.services.schedules.SchedulesFactory; import org.finos.legend.depot.store.artifacts.api.ArtifactsRefreshService; +import org.finos.legend.depot.store.artifacts.api.ProjectVersionArtifactsHandler; 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.file.FileGenerationsProvider; @@ -33,7 +34,8 @@ 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.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; @@ -59,7 +61,7 @@ protected void configure() bind(EntitiesVersionArtifactsHandler.class).to(EntitiesHandlerImpl.class); bind(EntityArtifactsProvider.class).to(EntityProvider.class); - bind(FileGenerationsVersionArtifactsHandler.class).to(FileGenerationVersionsHandler.class); + bind(ProjectVersionArtifactsHandler.class).to(FileArtifactGenerationVersionsHandler.class); bind(FileGenerationsProvider.class).to(FileGenerationsProviderImpl.class); bind(ArtifactsRefreshService.class).to(ArtifactsRefreshServiceImpl.class); diff --git a/legend-depot-artifacts-refresh/src/main/java/org/finos/legend/depot/store/artifacts/api/generation/artifact/ArtifactGenerationProvider.java b/legend-depot-artifacts-refresh/src/main/java/org/finos/legend/depot/store/artifacts/api/generation/artifact/ArtifactGenerationProvider.java new file mode 100644 index 000000000..29faa8b37 --- /dev/null +++ b/legend-depot-artifacts-refresh/src/main/java/org/finos/legend/depot/store/artifacts/api/generation/artifact/ArtifactGenerationProvider.java @@ -0,0 +1,9 @@ +package org.finos.legend.depot.store.artifacts.api.generation.artifact; + +import org.finos.legend.depot.domain.generation.artifact.ArtifactGeneration; +import org.finos.legend.depot.store.artifacts.api.ArtifactLoader; + +public interface ArtifactGenerationProvider extends ArtifactLoader +{ + +} 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..2aeb33c8e --- /dev/null +++ b/legend-depot-artifacts-refresh/src/main/java/org/finos/legend/depot/store/artifacts/api/generation/artifact/ArtifactGenerationsVersionArtifactsHandler.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.artifact; + +import org.finos.legend.depot.store.artifacts.api.ProjectVersionArtifactsHandler; + +public interface ArtifactGenerationsVersionArtifactsHandler extends ProjectVersionArtifactsHandler +{ + +} 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..669065a2b 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 @@ -20,4 +20,6 @@ public interface FileGenerationsVersionArtifactsHandler extends ProjectVersionArtifactsHandler { + + } diff --git a/legend-depot-artifacts-refresh/src/main/java/org/finos/legend/depot/store/artifacts/services/artifact/ArtifactProviderImpl.java b/legend-depot-artifacts-refresh/src/main/java/org/finos/legend/depot/store/artifacts/services/artifact/ArtifactProviderImpl.java new file mode 100644 index 000000000..607215fc6 --- /dev/null +++ b/legend-depot-artifacts-refresh/src/main/java/org/finos/legend/depot/store/artifacts/services/artifact/ArtifactProviderImpl.java @@ -0,0 +1,44 @@ +package org.finos.legend.depot.store.artifacts.services.artifact; + +import java.io.File; +import java.util.List; +import javax.inject.Inject; +import javax.inject.Singleton; +import org.finos.legend.depot.artifacts.repository.domain.ArtifactType; +import org.finos.legend.depot.domain.generation.artifact.ArtifactGeneration; +import org.finos.legend.depot.store.artifacts.api.generation.artifact.ArtifactGenerationProvider; + + +@Singleton +public class ArtifactProviderImpl implements ArtifactGenerationProvider +{ + + public static final ArtifactType FILE_GENERATION = ArtifactType.FILE_GENERATIONS; + + + @Inject + public ArtifactProviderImpl() + { + super(); + } + + @Override + public List loadArtifacts(List files) + { + return null; + + + + } + + + + + @Override + public ArtifactType getType() + { + return FILE_GENERATION; + } + + +} 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..b426ee460 --- /dev/null +++ b/legend-depot-artifacts-refresh/src/main/java/org/finos/legend/depot/store/artifacts/services/file/ArtifactGenerationHandler.java @@ -0,0 +1,89 @@ +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 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.artifact.ManageArtifactGenerationService; +import org.finos.legend.depot.store.artifacts.api.generation.artifact.ArtifactGenerationProvider; +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; + +public class ArtifactGenerationHandler implements ArtifactGenerationsVersionArtifactsHandler +{ + + public static final String VERSIONED_ENTITIES = "versioned-entities"; + public static final String PURE_PACKAGE_SEPARATOR = "::"; + private static final Logger LOGGER = org.slf4j.LoggerFactory.getLogger(ArtifactGenerationHandler.class); + protected final ManageArtifactGenerationService generations; + private final ArtifactGenerationProvider provider; + private final ArtifactRepository repository; + + + public ArtifactGenerationHandler(ArtifactRepository repository, ArtifactGenerationProvider artifactGenerationProvider, ManageArtifactGenerationService artifactGenerationService) + { + this.repository = repository; + this.generations = artifactGenerationService; + this.provider = artifactGenerationProvider; + + } + + public MetadataEventResponse refreshProjectVersionArtifacts(ProjectData project, String versionId, List files) + { + MetadataEventResponse response = new MetadataEventResponse(); + String separator = File.separator; + List artifactGenerations = provider.loadArtifacts(files); + 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(separator + 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, File.separator), 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..ef39664aa --- /dev/null +++ b/legend-depot-artifacts-refresh/src/main/java/org/finos/legend/depot/store/artifacts/services/file/FileArtifactGenerationVersionsHandler.java @@ -0,0 +1,61 @@ +// 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.Arrays; +import java.util.List; +import javax.inject.Inject; +import org.finos.legend.depot.artifacts.repository.api.ArtifactRepository; +import org.finos.legend.depot.domain.api.MetadataEventResponse; +import org.finos.legend.depot.domain.project.ProjectData; +import org.finos.legend.depot.services.api.artifact.ManageArtifactGenerationService; +import org.finos.legend.depot.services.api.generation.file.ManageFileGenerationsService; +import org.finos.legend.depot.store.artifacts.api.ProjectVersionArtifactsHandler; +import org.finos.legend.depot.store.artifacts.api.generation.artifact.ArtifactGenerationProvider; +import org.finos.legend.depot.store.artifacts.api.generation.file.FileGenerationsProvider; + +public class FileArtifactGenerationVersionsHandler implements ProjectVersionArtifactsHandler +{ + + private final List fileArtifactHandlers; + + + @Inject + public FileArtifactGenerationVersionsHandler(ArtifactRepository repository, FileGenerationsProvider provider, ManageFileGenerationsService generations, + ArtifactGenerationProvider artifactGenerationProvider, ManageArtifactGenerationService manageArtifactGenerationService) + { + ArtifactGenerationHandler artifactGenerationHandler = new ArtifactGenerationHandler(repository, artifactGenerationProvider, manageArtifactGenerationService); + FileGenerationHandler fileGenerationHandler = new FileGenerationHandler(repository, provider, generations); + this.fileArtifactHandlers = Arrays.asList(artifactGenerationHandler, fileGenerationHandler); + } + + + @Override + public MetadataEventResponse refreshProjectVersionArtifacts(ProjectData project, String versionId, List files) + { + MetadataEventResponse response = new MetadataEventResponse(); + this.fileArtifactHandlers.forEach(h -> response.combine(h.refreshProjectVersionArtifacts(project, versionId, files))); + + return null; + } + + @Override + public void delete(String groupId, String artifactId, String versionId) + { + this.fileArtifactHandlers.forEach(h -> h.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 81% 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..b2e09cdc5 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,14 @@ 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.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; @@ -23,22 +31,14 @@ 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,13 +46,14 @@ 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) + protected FileGenerationHandler(ArtifactRepository repository, FileGenerationsProvider provider, ManageFileGenerationsService generations) { this.repository = repository; this.provider = provider; @@ -75,9 +76,9 @@ public MetadataEventResponse refreshProjectVersionArtifacts(ProjectData project, 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 1873a8d82..cc24ea418 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 @@ -37,7 +37,7 @@ 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.FileArtifactGenerationVersionsHandler; 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; @@ -86,7 +86,7 @@ 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))); + ArtifactResolverFactory.registerVersionUpdater(ArtifactType.FILE_GENERATIONS, new FileArtifactGenerationVersionsHandler(repository, fileGenerationsProvider, new FileGenerationsServiceImpl(fileGenerationsStore, entitiesStore))); 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..9dada0262 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 @@ -28,7 +28,7 @@ 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.FileArtifactGenerationVersionsHandler; 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; @@ -89,7 +89,7 @@ public void canRefreshRevisions() { Assert.assertTrue(generations.getAll().isEmpty()); - FileGenerationVersionsHandler handler = new FileGenerationVersionsHandler(repository, fileGenerationsProvider, generations); + FileArtifactGenerationVersionsHandler handler = new FileArtifactGenerationVersionsHandler(repository, fileGenerationsProvider, generations); 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 +105,7 @@ public void canRefreshVersions() { Assert.assertTrue(generations.getAll().isEmpty()); - FileGenerationVersionsHandler handler = new FileGenerationVersionsHandler(repository, fileGenerationsProvider, generations); + FileArtifactGenerationVersionsHandler handler = new FileArtifactGenerationVersionsHandler(repository, fileGenerationsProvider, generations); 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 +121,7 @@ public void canRefreshVersions() public void canReadFileGenerationArtifactsWithMultipleGenerations() { Assert.assertTrue(generations.getAll().isEmpty()); - FileGenerationVersionsHandler handler = new FileGenerationVersionsHandler(repository, fileGenerationsProvider, generations); + FileArtifactGenerationVersionsHandler handler = new FileArtifactGenerationVersionsHandler(repository, fileGenerationsProvider, generations); 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..1b7110f4b 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,11 +16,14 @@ package org.finos.legend.depot.services; import com.google.inject.PrivateModule; +import org.finos.legend.depot.services.api.artifact.ArtifactGenerationService; +import org.finos.legend.depot.services.api.artifact.ManageArtifactGenerationService; 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; @@ -47,6 +50,8 @@ protected void configure() bind(ManageEntitiesService.class).to(EntitiesServiceImpl.class); bind(FileGenerationsService.class).to(FileGenerationsServiceImpl.class); bind(ManageFileGenerationsService.class).to(FileGenerationsServiceImpl.class); + bind(ArtifactGenerationService.class).to(ArtifactGenerationsServiceImpl.class); + bind(ManageArtifactGenerationService.class).to(ArtifactGenerationsServiceImpl.class); expose(ManageProjectsService.class); expose(ManageEntitiesService.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..ae6fc0209 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 @@ -26,11 +26,14 @@ 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,6 +48,8 @@ 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); diff --git a/legend-depot-core-services/src/main/java/org/finos/legend/depot/services/api/artifact/ArtifactGenerationService.java b/legend-depot-core-services/src/main/java/org/finos/legend/depot/services/api/artifact/ArtifactGenerationService.java new file mode 100644 index 000000000..79a926daa --- /dev/null +++ b/legend-depot-core-services/src/main/java/org/finos/legend/depot/services/api/artifact/ArtifactGenerationService.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.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 ArtifactGenerationService +{ + 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/artifact/ManageArtifactGenerationService.java b/legend-depot-core-services/src/main/java/org/finos/legend/depot/services/api/artifact/ManageArtifactGenerationService.java new file mode 100644 index 000000000..755310d8f --- /dev/null +++ b/legend-depot-core-services/src/main/java/org/finos/legend/depot/services/api/artifact/ManageArtifactGenerationService.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.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 ManageArtifactGenerationService extends ArtifactGenerationService +{ + + 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..7dcf8adcc --- /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.artifact.ArtifactGenerationService; +import org.finos.legend.depot.services.api.artifact.ManageArtifactGenerationService; +import org.finos.legend.depot.store.api.generation.artifact.UpdateArtifactGenerations; + +public class ArtifactGenerationsServiceImpl implements ArtifactGenerationService, ManageArtifactGenerationService +{ + + 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-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 639567d8d..08c261268 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/resources/artifact/ArtifactGenerationResource.java b/legend-depot-server/src/main/java/org/finos/legend/depot/server/resources/artifact/ArtifactGenerationResource.java new file mode 100644 index 000000000..bd2ffd077 --- /dev/null +++ b/legend-depot-server/src/main/java/org/finos/legend/depot/server/resources/artifact/ArtifactGenerationResource.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.artifact.ArtifactGenerationService; +import org.finos.legend.depot.store.metrics.QueryMetricsContainer; +import org.finos.legend.depot.tracing.resources.BaseResource; + +@Path("artifactGenerations") +@Api("Artifact Generations") +public class ArtifactGenerationResource extends BaseResource +{ + private final ArtifactGenerationService artifactGenerationService; + + @Inject + public ArtifactGenerationResource(ArtifactGenerationService 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/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..401779978 --- /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)); + } + + +} diff --git a/legend-depot-store-mongo/src/main/java/org/finos/legend/depot/store/mongo/generation/file/FileGenerationsMongo.java b/legend-depot-store-mongo/src/main/java/org/finos/legend/depot/store/mongo/generation/file/FileGenerationsMongo.java index 573fb68ba..06e1506b4 100644 --- a/legend-depot-store-mongo/src/main/java/org/finos/legend/depot/store/mongo/generation/file/FileGenerationsMongo.java +++ b/legend-depot-store-mongo/src/main/java/org/finos/legend/depot/store/mongo/generation/file/FileGenerationsMongo.java @@ -66,8 +66,7 @@ public boolean createIndexesIfAbsent() @Override protected Bson getKeyFilter(StoredFileGeneration data) { - return and(getArtifactAndVersionFilter(data.getGroupId(), data.getArtifactId(), data.getVersionId()), - eq(FILE_PATH, data.getFile().getPath())); + return and(getArtifactAndVersionFilter(data.getGroupId(), data.getArtifactId(), data.getVersionId()), eq(FILE_PATH, data.getFile().getPath())); } @Override