Search in sources :

Example 1 with EntityDiff

use of org.finos.legend.sdlc.domain.model.comparison.EntityDiff in project legend-sdlc by finos.

the class GitLabComparisonApiTestResource method runUserWorkspaceComparisonTest.

public void runUserWorkspaceComparisonTest() {
    String projectName = "ComparisonTestProjectOne";
    String description = "A test project.";
    ProjectType projectType = ProjectType.PRODUCTION;
    String groupId = "org.finos.sdlc.test";
    String artifactId = "comptestprojone";
    List<String> tags = Lists.mutable.with("doe", "moffitt", AbstractGitLabServerApiTest.INTEGRATION_TEST_PROJECT_TAG);
    String workspaceOneId = "testworkspaceone";
    Project createdProject = gitLabProjectApi.createProject(projectName, description, projectType, groupId, artifactId, tags);
    Assert.assertNotNull(createdProject);
    Assert.assertEquals(projectName, createdProject.getName());
    Assert.assertEquals(description, createdProject.getDescription());
    Assert.assertEquals(projectType, createdProject.getProjectType());
    Assert.assertEquals(Sets.mutable.withAll(tags), Sets.mutable.withAll(createdProject.getTags()));
    String projectId = createdProject.getProjectId();
    Workspace createdWorkspaceOne = gitLabWorkspaceApi.newUserWorkspace(projectId, workspaceOneId);
    Revision fromRevision = gitLabRevisionApi.getUserWorkspaceRevisionContext(projectId, workspaceOneId).getCurrentRevision();
    Assert.assertNotNull(createdWorkspaceOne);
    Assert.assertEquals(workspaceOneId, createdWorkspaceOne.getWorkspaceId());
    Assert.assertEquals(projectId, createdWorkspaceOne.getProjectId());
    Assert.assertNotNull(createdWorkspaceOne.getUserId());
    String entityPath = "test::entity";
    String classifierPath = "meta::test::mathematicsDepartment";
    Map<String, String> entityContentMap = Maps.mutable.with("package", "test", "name", "entity", "math-113", "abstract-algebra", "math-185", "complex-analysis");
    gitLabEntityApi.getUserWorkspaceEntityModificationContext(projectId, workspaceOneId).createEntity(entityPath, classifierPath, entityContentMap, "initial entity");
    List<Entity> modifiedWorkspaceEntities = gitLabEntityApi.getUserWorkspaceEntityAccessContext(projectId, workspaceOneId).getEntities(null, null, null);
    Assert.assertNotNull(modifiedWorkspaceEntities);
    Assert.assertEquals(1, modifiedWorkspaceEntities.size());
    Entity initalEntity = modifiedWorkspaceEntities.get(0);
    Assert.assertEquals(initalEntity.getPath(), entityPath);
    Assert.assertEquals(initalEntity.getClassifierPath(), classifierPath);
    Assert.assertEquals(initalEntity.getContent(), entityContentMap);
    Revision toRevision = gitLabRevisionApi.getUserWorkspaceRevisionContext(projectId, workspaceOneId).getCurrentRevision();
    List<EntityDiff> entityDiffs = gitLabComparisonApi.getUserWorkspaceCreationComparison(projectId, workspaceOneId).getEntityDiffs();
    String fromRevisionId = gitLabComparisonApi.getUserWorkspaceCreationComparison(projectId, workspaceOneId).getFromRevisionId();
    String toRevisionId = gitLabComparisonApi.getUserWorkspaceCreationComparison(projectId, workspaceOneId).getToRevisionId();
    Assert.assertNotNull(fromRevision);
    Assert.assertNotNull(toRevision);
    Assert.assertEquals(fromRevision.getId(), fromRevisionId);
    Assert.assertEquals(toRevision.getId(), toRevisionId);
    Assert.assertNotNull(entityDiffs);
    Assert.assertEquals(1, entityDiffs.size());
    Assert.assertEquals(EntityChangeType.CREATE, entityDiffs.get(0).getEntityChangeType());
    Revision projectFromRevision = gitLabRevisionApi.getProjectRevisionContext(projectId).getCurrentRevision();
    Revision projectToRevision = gitLabRevisionApi.getUserWorkspaceRevisionContext(projectId, workspaceOneId).getCurrentRevision();
    List<EntityDiff> projectEntityDiffs = gitLabComparisonApi.getUserWorkspaceProjectComparison(projectId, workspaceOneId).getEntityDiffs();
    String projectFromRevisionId = gitLabComparisonApi.getUserWorkspaceProjectComparison(projectId, workspaceOneId).getFromRevisionId();
    String projectToRevisionId = gitLabComparisonApi.getUserWorkspaceProjectComparison(projectId, workspaceOneId).getToRevisionId();
    Assert.assertNotNull(projectFromRevision);
    Assert.assertEquals(projectFromRevision.getId(), projectFromRevisionId);
    Assert.assertEquals(projectToRevision.getId(), projectToRevisionId);
    Assert.assertNotNull(projectEntityDiffs);
    Assert.assertEquals(1, projectEntityDiffs.size());
    Assert.assertEquals(EntityChangeType.CREATE, projectEntityDiffs.get(0).getEntityChangeType());
}
Also used : Project(org.finos.legend.sdlc.domain.model.project.Project) Entity(org.finos.legend.sdlc.domain.model.entity.Entity) Revision(org.finos.legend.sdlc.domain.model.revision.Revision) ProjectType(org.finos.legend.sdlc.domain.model.project.ProjectType) EntityDiff(org.finos.legend.sdlc.domain.model.comparison.EntityDiff) Workspace(org.finos.legend.sdlc.domain.model.project.workspace.Workspace)

Example 2 with EntityDiff

use of org.finos.legend.sdlc.domain.model.comparison.EntityDiff in project legend-sdlc by finos.

the class GitLabComparisonApiTestResource method runGroupWorkspaceComparisonTest.

public void runGroupWorkspaceComparisonTest() {
    String projectName = "ComparisonTestProjectTwo";
    String description = "A test project.";
    ProjectType projectType = ProjectType.PRODUCTION;
    String groupId = "org.finos.sdlc.test";
    String artifactId = "comptestprojtwo";
    List<String> tags = Lists.mutable.with("doe", "moffitt", AbstractGitLabServerApiTest.INTEGRATION_TEST_PROJECT_TAG);
    String workspaceOneId = "testworkspaceone";
    Project createdProject = gitLabProjectApi.createProject(projectName, description, projectType, groupId, artifactId, tags);
    Assert.assertNotNull(createdProject);
    Assert.assertEquals(projectName, createdProject.getName());
    Assert.assertEquals(description, createdProject.getDescription());
    Assert.assertEquals(projectType, createdProject.getProjectType());
    Assert.assertEquals(Sets.mutable.withAll(tags), Sets.mutable.withAll(createdProject.getTags()));
    String projectId = createdProject.getProjectId();
    Workspace createdWorkspaceOne = gitLabWorkspaceApi.newGroupWorkspace(projectId, workspaceOneId);
    Revision fromRevision = gitLabRevisionApi.getGroupWorkspaceRevisionContext(projectId, workspaceOneId).getCurrentRevision();
    Assert.assertNotNull(createdWorkspaceOne);
    Assert.assertEquals(workspaceOneId, createdWorkspaceOne.getWorkspaceId());
    Assert.assertEquals(projectId, createdWorkspaceOne.getProjectId());
    Assert.assertNull(createdWorkspaceOne.getUserId());
    String entityPath = "test::entity";
    String classifierPath = "meta::test::mathematicsDepartment";
    Map<String, String> entityContentMap = Maps.mutable.with("package", "test", "name", "entity", "math-113", "abstract-algebra", "math-185", "complex-analysis");
    gitLabEntityApi.getGroupWorkspaceEntityModificationContext(projectId, workspaceOneId).createEntity(entityPath, classifierPath, entityContentMap, "initial entity");
    List<Entity> modifiedWorkspaceEntities = gitLabEntityApi.getGroupWorkspaceEntityAccessContext(projectId, workspaceOneId).getEntities(null, null, null);
    Assert.assertNotNull(modifiedWorkspaceEntities);
    Assert.assertEquals(1, modifiedWorkspaceEntities.size());
    Entity initalEntity = modifiedWorkspaceEntities.get(0);
    Assert.assertEquals(initalEntity.getPath(), entityPath);
    Assert.assertEquals(initalEntity.getClassifierPath(), classifierPath);
    Assert.assertEquals(initalEntity.getContent(), entityContentMap);
    Revision toRevision = gitLabRevisionApi.getGroupWorkspaceRevisionContext(projectId, workspaceOneId).getCurrentRevision();
    List<EntityDiff> entityDiffs = gitLabComparisonApi.getGroupWorkspaceCreationComparison(projectId, workspaceOneId).getEntityDiffs();
    String fromRevisionId = gitLabComparisonApi.getGroupWorkspaceCreationComparison(projectId, workspaceOneId).getFromRevisionId();
    String toRevisionId = gitLabComparisonApi.getGroupWorkspaceCreationComparison(projectId, workspaceOneId).getToRevisionId();
    Assert.assertNotNull(fromRevision);
    Assert.assertNotNull(toRevision);
    Assert.assertEquals(fromRevision.getId(), fromRevisionId);
    Assert.assertEquals(toRevision.getId(), toRevisionId);
    Assert.assertNotNull(entityDiffs);
    Assert.assertEquals(1, entityDiffs.size());
    Assert.assertEquals(EntityChangeType.CREATE, entityDiffs.get(0).getEntityChangeType());
    Revision projectFromRevision = gitLabRevisionApi.getProjectRevisionContext(projectId).getCurrentRevision();
    Revision projectToRevision = gitLabRevisionApi.getGroupWorkspaceRevisionContext(projectId, workspaceOneId).getCurrentRevision();
    List<EntityDiff> projectEntityDiffs = gitLabComparisonApi.getGroupWorkspaceProjectComparison(projectId, workspaceOneId).getEntityDiffs();
    String projectFromRevisionId = gitLabComparisonApi.getGroupWorkspaceProjectComparison(projectId, workspaceOneId).getFromRevisionId();
    String projectToRevisionId = gitLabComparisonApi.getGroupWorkspaceProjectComparison(projectId, workspaceOneId).getToRevisionId();
    Assert.assertNotNull(projectFromRevision);
    Assert.assertEquals(projectFromRevision.getId(), projectFromRevisionId);
    Assert.assertEquals(projectToRevision.getId(), projectToRevisionId);
    Assert.assertNotNull(projectEntityDiffs);
    Assert.assertEquals(1, projectEntityDiffs.size());
    Assert.assertEquals(EntityChangeType.CREATE, projectEntityDiffs.get(0).getEntityChangeType());
}
Also used : Project(org.finos.legend.sdlc.domain.model.project.Project) Entity(org.finos.legend.sdlc.domain.model.entity.Entity) Revision(org.finos.legend.sdlc.domain.model.revision.Revision) ProjectType(org.finos.legend.sdlc.domain.model.project.ProjectType) EntityDiff(org.finos.legend.sdlc.domain.model.comparison.EntityDiff) Workspace(org.finos.legend.sdlc.domain.model.project.workspace.Workspace)

Example 3 with EntityDiff

use of org.finos.legend.sdlc.domain.model.comparison.EntityDiff in project legend-sdlc by finos.

the class GitLabComparisonApi method newComparison.

private static Comparison newComparison(String fromRevisionId, String toRevisionId, List<Diff> deltas, ProjectStructure fromProjectStructure, ProjectStructure toProjectStructure) {
    List<EntityDiff> entityDiffs = Lists.mutable.empty();
    AtomicBoolean isProjectConfigurationUpdated = new AtomicBoolean(false);
    deltas.forEach(diff -> {
        // File changes can be of three types:
        // 1. entity file changes - which we should handle without any problem
        // 2. project configuration changes - which we will just capture by a boolean flag to indicate if there are any changes
        // 3. other files: e.g. users can go in and modify pom.xml, add some non-entity files, etc. we DO NOT keep track of these
        String oldPath = diff.getOldPath().startsWith(FILE_PATH_DELIMITER) ? diff.getOldPath() : FILE_PATH_DELIMITER + diff.getOldPath();
        String newPath = diff.getNewPath().startsWith(FILE_PATH_DELIMITER) ? diff.getNewPath() : FILE_PATH_DELIMITER + diff.getNewPath();
        // project configuration change
        if (ProjectStructure.PROJECT_CONFIG_PATH.equals(oldPath) || ProjectStructure.PROJECT_CONFIG_PATH.equals(newPath)) {
            // technically, we know the only probable operation that can happen is MODIFICATION, CREATE is really an edge case
            isProjectConfigurationUpdated.set(true);
            return;
        }
        ProjectStructure.EntitySourceDirectory oldPathSourceDirectory = fromProjectStructure.findSourceDirectoryForEntityFilePath(oldPath);
        ProjectStructure.EntitySourceDirectory newPathSourceDirectory = toProjectStructure.findSourceDirectoryForEntityFilePath(newPath);
        // entity file change
        if ((oldPathSourceDirectory != null) || (newPathSourceDirectory != null)) {
            String oldEntityPath = (oldPathSourceDirectory == null) ? oldPath : oldPathSourceDirectory.filePathToEntityPath(oldPath);
            String newEntityPath = (newPathSourceDirectory == null) ? newPath : newPathSourceDirectory.filePathToEntityPath(newPath);
            EntityChangeType entityChangeType;
            if (diff.getDeletedFile()) {
                entityChangeType = EntityChangeType.DELETE;
            } else if (diff.getNewFile()) {
                entityChangeType = EntityChangeType.CREATE;
            } else if (diff.getRenamedFile()) {
                entityChangeType = EntityChangeType.RENAME;
            } else {
                entityChangeType = EntityChangeType.MODIFY;
            }
            entityDiffs.add(new EntityDiff() {

                @Override
                public EntityChangeType getEntityChangeType() {
                    return entityChangeType;
                }

                @Override
                public String getNewPath() {
                    return newEntityPath;
                }

                @Override
                public String getOldPath() {
                    return oldEntityPath;
                }
            });
        }
    // SKIP non-entity, non-config file
    });
    return new Comparison() {

        @Override
        public String getToRevisionId() {
            return toRevisionId;
        }

        @Override
        public String getFromRevisionId() {
            return fromRevisionId;
        }

        @Override
        public List<EntityDiff> getEntityDiffs() {
            return entityDiffs;
        }

        @Override
        public boolean isProjectConfigurationUpdated() {
            return isProjectConfigurationUpdated.get();
        }
    };
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) EntityChangeType(org.finos.legend.sdlc.domain.model.entity.change.EntityChangeType) Comparison(org.finos.legend.sdlc.domain.model.comparison.Comparison) ProjectStructure(org.finos.legend.sdlc.server.project.ProjectStructure) EntityDiff(org.finos.legend.sdlc.domain.model.comparison.EntityDiff)

Aggregations

EntityDiff (org.finos.legend.sdlc.domain.model.comparison.EntityDiff)3 Entity (org.finos.legend.sdlc.domain.model.entity.Entity)2 Project (org.finos.legend.sdlc.domain.model.project.Project)2 ProjectType (org.finos.legend.sdlc.domain.model.project.ProjectType)2 Workspace (org.finos.legend.sdlc.domain.model.project.workspace.Workspace)2 Revision (org.finos.legend.sdlc.domain.model.revision.Revision)2 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 Comparison (org.finos.legend.sdlc.domain.model.comparison.Comparison)1 EntityChangeType (org.finos.legend.sdlc.domain.model.entity.change.EntityChangeType)1 ProjectStructure (org.finos.legend.sdlc.server.project.ProjectStructure)1