Search in sources :

Example 1 with EntityChangeType

use of org.finos.legend.sdlc.domain.model.entity.change.EntityChangeType in project legend-sdlc by finos.

the class GitLabEntityApi method collectErrorsForEntityChange.

private static void collectErrorsForEntityChange(EntityChange entityChange, Collection<? super String> errorMessages) {
    if (entityChange == null) {
        errorMessages.add("Invalid entity change: null");
        return;
    }
    EntityChangeType type = entityChange.getType();
    if (type == null) {
        errorMessages.add("Missing entity change type");
    }
    String path = entityChange.getEntityPath();
    String classifierPath = entityChange.getClassifierPath();
    Map<String, ?> content = entityChange.getContent();
    String newPath = entityChange.getNewEntityPath();
    if (path == null) {
        errorMessages.add("Missing entity path");
    } else if (!isValidEntityPath(path)) {
        errorMessages.add("Invalid entity path: " + path);
    } else if (content != null) {
        Object pkg = content.get("package");
        Object name = content.get("name");
        if (!(pkg instanceof String) || !(name instanceof String) || !path.equals(pkg + "::" + name)) {
            StringBuilder builder = new StringBuilder("Mismatch between entity path (\"").append(path).append("\") and package (");
            if (pkg instanceof String) {
                builder.append('"').append(pkg).append('"');
            } else {
                builder.append(pkg);
            }
            builder.append(") and name (");
            if (name instanceof String) {
                builder.append('"').append(name).append('"');
            } else {
                builder.append(name);
            }
            builder.append(") properties");
            errorMessages.add(builder.toString());
        }
    }
    if (type != null) {
        switch(type) {
            case CREATE:
            case MODIFY:
                {
                    if (classifierPath == null) {
                        errorMessages.add("Missing classifier path");
                    } else if (!isValidClassifierPath(classifierPath)) {
                        errorMessages.add("Invalid classifier path: " + classifierPath);
                    }
                    if (content == null) {
                        errorMessages.add("Missing content");
                    }
                    if (newPath != null) {
                        errorMessages.add("Unexpected new entity path: " + newPath);
                    }
                    break;
                }
            case RENAME:
                {
                    if (classifierPath != null) {
                        errorMessages.add("Unexpected classifier path: " + classifierPath);
                    }
                    if (content != null) {
                        errorMessages.add("Unexpected content");
                    }
                    if (newPath == null) {
                        errorMessages.add("Missing new entity path");
                    } else if (!isValidEntityPath(newPath)) {
                        errorMessages.add("Invalid new entity path: " + newPath);
                    }
                    break;
                }
            case DELETE:
                {
                    if (classifierPath != null) {
                        errorMessages.add("Unexpected classifier path: " + classifierPath);
                    }
                    if (content != null) {
                        errorMessages.add("Unexpected content");
                    }
                    if (newPath != null) {
                        errorMessages.add("Unexpected new entity path: " + newPath);
                    }
                    break;
                }
            default:
                {
                    errorMessages.add("Unexpected entity change type: " + type);
                }
        }
    }
}
Also used : EntityChangeType(org.finos.legend.sdlc.domain.model.entity.change.EntityChangeType)

Example 2 with EntityChangeType

use of org.finos.legend.sdlc.domain.model.entity.change.EntityChangeType 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

EntityChangeType (org.finos.legend.sdlc.domain.model.entity.change.EntityChangeType)2 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 Comparison (org.finos.legend.sdlc.domain.model.comparison.Comparison)1 EntityDiff (org.finos.legend.sdlc.domain.model.comparison.EntityDiff)1 ProjectStructure (org.finos.legend.sdlc.server.project.ProjectStructure)1