Skip to content

Commit

Permalink
temp
Browse files Browse the repository at this point in the history
  • Loading branch information
MauricioUyaguari committed Sep 22, 2022
1 parent fc3a8a5 commit 61726a4
Show file tree
Hide file tree
Showing 24 changed files with 874 additions and 69 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
@@ -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<ArtifactGeneration>
{

}
Original file line number Diff line number Diff line change
@@ -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
{

}
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,6 @@
public interface FileGenerationsVersionArtifactsHandler extends ProjectVersionArtifactsHandler
{



}
Original file line number Diff line number Diff line change
@@ -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<ArtifactGeneration> loadArtifacts(List<File> files)
{
return null;



}




@Override
public ArtifactType getType()
{
return FILE_GENERATION;
}


}
Original file line number Diff line number Diff line change
@@ -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<File> files)
{
MetadataEventResponse response = new MetadataEventResponse();
String separator = File.separator;
List<ArtifactGeneration> artifactGenerations = provider.loadArtifacts(files);
Map<String, Entity> entities = findEntitiesByPath(project.getGroupId(), project.getArtifactId(), versionId);
Set<String> 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<String> 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<String, Entity> findEntitiesByPath(String groupId, String artifactId, String versionId)
{
Map<String, Entity> entityMap = new HashMap<>();
Optional<File> 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);
}


}
Original file line number Diff line number Diff line change
@@ -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<ProjectVersionArtifactsHandler> 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<File> 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));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -23,36 +31,29 @@
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";
public static final String PURE_PACKAGE_SEPARATOR = "::";
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;
Expand All @@ -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 ->
{
Expand All @@ -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<Entity> findFileGenerationEntities(String groupId, String artifactId, String versionId)
{
List<File> files = repository.findFiles(ArtifactType.ENTITIES, groupId, artifactId, versionId);
Optional<File> 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)
Expand Down
Loading

0 comments on commit 61726a4

Please sign in to comment.