Search in sources :

Example 16 with LegendSDLCServerException

use of org.finos.legend.sdlc.server.error.LegendSDLCServerException in project legend-sdlc by finos.

the class GitLabRevisionApi method getWorkspacePackageRevisionContextByWorkspaceAccessType.

private RevisionAccessContext getWorkspacePackageRevisionContextByWorkspaceAccessType(String projectId, String workspaceId, WorkspaceType workspaceType, ProjectFileAccessProvider.WorkspaceAccessType workspaceAccessType, String packagePath) {
    LegendSDLCServerException.validateNonNull(projectId, "projectId may not be null");
    LegendSDLCServerException.validateNonNull(workspaceId, "workspaceId may not be null");
    LegendSDLCServerException.validateNonNull(workspaceType, "workspaceType may not be null");
    LegendSDLCServerException.validateNonNull(workspaceAccessType, "workspaceAccessType may not be null");
    LegendSDLCServerException.validateNonNull(packagePath, "packagePath may not be null");
    if (!isValidPackagePath(packagePath)) {
        throw new LegendSDLCServerException("Invalid package path: " + packagePath, Status.BAD_REQUEST);
    }
    ProjectStructure projectStructure = getProjectStructure(projectId, workspaceId, null, workspaceType, workspaceAccessType);
    MutableList<String> directories = Iterate.collectWith(projectStructure.getEntitySourceDirectories(), ProjectStructure.EntitySourceDirectory::packagePathToFilePath, packagePath, Lists.mutable.empty());
    MutableList<String> canonicalizedAndReducedDirectories = ProjectPaths.canonicalizeAndReduceDirectories(directories);
    return new ProjectFileRevisionAccessContextWrapper(getProjectFileAccessProvider().getRevisionAccessContext(projectId, workspaceId, workspaceType, workspaceAccessType, canonicalizedAndReducedDirectories), new PackageablePathExceptionProcessor(packagePath, canonicalizedAndReducedDirectories));
}
Also used : LegendSDLCServerException(org.finos.legend.sdlc.server.error.LegendSDLCServerException) ProjectStructure(org.finos.legend.sdlc.server.project.ProjectStructure)

Example 17 with LegendSDLCServerException

use of org.finos.legend.sdlc.server.error.LegendSDLCServerException in project legend-sdlc by finos.

the class GitLabRevisionApi method getWorkspaceEntityRevisionContextByWorkspaceAccessType.

private RevisionAccessContext getWorkspaceEntityRevisionContextByWorkspaceAccessType(String projectId, String workspaceId, WorkspaceType workspaceType, ProjectFileAccessProvider.WorkspaceAccessType workspaceAccessType, String entityPath) {
    LegendSDLCServerException.validateNonNull(projectId, "projectId may not be null");
    LegendSDLCServerException.validateNonNull(workspaceId, "workspaceId may not be null");
    LegendSDLCServerException.validateNonNull(workspaceType, "workspaceType may not be null");
    LegendSDLCServerException.validateNonNull(workspaceAccessType, "workspaceAccessType may not be null");
    LegendSDLCServerException.validateNonNull(entityPath, "entityPath may not be null");
    if (!isValidEntityPath(entityPath)) {
        throw new LegendSDLCServerException("Invalid entity path: " + entityPath, Status.BAD_REQUEST);
    }
    ProjectFileAccessProvider fileAccessProvider = getProjectFileAccessProvider();
    ProjectFileAccessProvider.FileAccessContext fileAccessContext = fileAccessProvider.getFileAccessContext(projectId, workspaceId, workspaceType, workspaceAccessType, null);
    ProjectStructure projectStructure = ProjectStructure.getProjectStructure(fileAccessContext);
    String filePath = projectStructure.findEntityFile(entityPath, fileAccessContext);
    if (filePath == null) {
        throw new LegendSDLCServerException("Cannot find entity \"" + entityPath + "\" in " + workspaceType.getLabel() + " " + workspaceAccessType.getLabel() + " " + workspaceId + " in project " + projectId, Status.NOT_FOUND);
    }
    String canonicalizedFilePath = ProjectPaths.canonicalizeFile(filePath);
    return new ProjectFileRevisionAccessContextWrapper(fileAccessProvider.getRevisionAccessContext(projectId, workspaceId, workspaceType, workspaceAccessType, canonicalizedFilePath), new PackageablePathExceptionProcessor(entityPath, canonicalizedFilePath));
}
Also used : ProjectFileAccessProvider(org.finos.legend.sdlc.server.project.ProjectFileAccessProvider) LegendSDLCServerException(org.finos.legend.sdlc.server.error.LegendSDLCServerException) ProjectStructure(org.finos.legend.sdlc.server.project.ProjectStructure)

Example 18 with LegendSDLCServerException

use of org.finos.legend.sdlc.server.error.LegendSDLCServerException in project legend-sdlc by finos.

the class GitLabUserApi method getUserById.

@Override
public User getUserById(String userId) {
    LegendSDLCServerException.validateNonNull(userId, "userId cannot be null");
    Exception exception = null;
    for (GitLabMode mode : getValidGitLabModes()) {
        User user;
        try {
            user = fromGitLabAbstractUser(getGitLabApi(mode).getUserApi().getUser(userId));
        } catch (Exception e) {
            exception = e;
            user = null;
        }
        if (user != null) {
            return user;
        }
    }
    if (exception != null) {
        throw buildException(exception, () -> "User " + getCurrentUser() + " is not allowed to get user " + userId, () -> "Unknown user: " + userId, () -> "Error getting user " + userId);
    }
    throw new LegendSDLCServerException("Unknown user: " + userId, Status.NOT_FOUND);
}
Also used : LegendSDLCServerException(org.finos.legend.sdlc.server.error.LegendSDLCServerException) User(org.finos.legend.sdlc.domain.model.user.User) LegendSDLCServerException(org.finos.legend.sdlc.server.error.LegendSDLCServerException) GitLabMode(org.finos.legend.sdlc.server.gitlab.mode.GitLabMode)

Example 19 with LegendSDLCServerException

use of org.finos.legend.sdlc.server.error.LegendSDLCServerException in project legend-sdlc by finos.

the class GitLabUserApi method getCurrentUserInfo.

@Override
public User getCurrentUserInfo() {
    List<Exception> exceptions = Lists.mutable.empty();
    for (GitLabMode mode : getValidGitLabModes()) {
        try {
            User user = fromGitLabAbstractUser(getGitLabApi(mode).getUserApi().getCurrentUser());
            if (user != null) {
                return user;
            }
        } catch (Exception e) {
            exceptions.add(e);
        }
    }
    if (exceptions.isEmpty()) {
        throw new LegendSDLCServerException("Could not get current user information");
    }
    Exception e = exceptions.get(0);
    for (Exception other : exceptions) {
        if (other != e) {
            e.addSuppressed(other);
        }
    }
    throw buildException(e, () -> "User " + getCurrentUser() + " is not allowed to get current user information", null, () -> "Error getting current user information");
}
Also used : LegendSDLCServerException(org.finos.legend.sdlc.server.error.LegendSDLCServerException) User(org.finos.legend.sdlc.domain.model.user.User) LegendSDLCServerException(org.finos.legend.sdlc.server.error.LegendSDLCServerException) GitLabMode(org.finos.legend.sdlc.server.gitlab.mode.GitLabMode)

Example 20 with LegendSDLCServerException

use of org.finos.legend.sdlc.server.error.LegendSDLCServerException in project legend-sdlc by finos.

the class GitLabVersionApi method getVersions.

private Stream<Version> getVersions(GitLabProjectId projectId, Integer minMajorVersion, Integer maxMajorVersion, Integer minMinorVersion, Integer maxMinorVersion, Integer minPatchVersion, Integer maxPatchVersion) {
    switch(getProjectTypeFromMode(projectId.getGitLabMode())) {
        case PROTOTYPE:
            {
                return Stream.empty();
            }
        case PRODUCTION:
            {
                try {
                    Stream<Version> stream = PagerTools.stream(getGitLabApi(projectId.getGitLabMode()).getTagsApi().getTags(projectId.getGitLabId(), ITEMS_PER_PAGE)).filter(GitLabVersionApi::isVersionTag).map(tag -> fromGitLabTag(projectId.toString(), tag));
                    // major version constraint
                    if ((minMajorVersion != null) && (maxMajorVersion != null)) {
                        int minMajorVersionInt = minMajorVersion;
                        int maxMajorVersionInt = maxMajorVersion;
                        if (minMajorVersionInt == maxMajorVersionInt) {
                            stream = stream.filter(v -> v.getId().getMajorVersion() == minMajorVersionInt);
                        } else {
                            stream = stream.filter(v -> {
                                int majorVersion = v.getId().getMajorVersion();
                                return (minMajorVersionInt <= majorVersion) && (majorVersion <= maxMajorVersionInt);
                            });
                        }
                    } else if (minMajorVersion != null) {
                        int minMajorVersionInt = minMajorVersion;
                        stream = stream.filter(v -> v.getId().getMajorVersion() >= minMajorVersionInt);
                    } else if (maxMajorVersion != null) {
                        int maxMajorVersionInt = maxMajorVersion;
                        stream = stream.filter(v -> v.getId().getMajorVersion() <= maxMajorVersionInt);
                    }
                    // minor version constraint
                    if ((minMinorVersion != null) && (maxMinorVersion != null)) {
                        int minMinorVersionInt = minMinorVersion;
                        int maxMinorVersionInt = maxMinorVersion;
                        if (minMinorVersionInt == maxMinorVersionInt) {
                            stream = stream.filter(v -> v.getId().getMinorVersion() == minMinorVersionInt);
                        } else {
                            stream = stream.filter(v -> {
                                int minorVersion = v.getId().getMinorVersion();
                                return (minMinorVersionInt <= minorVersion) && (minorVersion <= maxMinorVersionInt);
                            });
                        }
                    } else if (minMinorVersion != null) {
                        int minMinorVersionInt = minMinorVersion;
                        stream = stream.filter(v -> v.getId().getMinorVersion() >= minMinorVersionInt);
                    } else if (maxMinorVersion != null) {
                        int maxMinorVersionInt = maxMinorVersion;
                        stream = stream.filter(v -> v.getId().getMinorVersion() <= maxMinorVersionInt);
                    }
                    // patch version constraint
                    if ((minPatchVersion != null) && (maxPatchVersion != null)) {
                        int minPatchVersionInt = minPatchVersion;
                        int maxPatchVersionInt = maxPatchVersion;
                        if (minPatchVersionInt == maxPatchVersionInt) {
                            stream = stream.filter(v -> v.getId().getPatchVersion() == minPatchVersionInt);
                        } else {
                            stream = stream.filter(v -> {
                                int patchVersion = v.getId().getPatchVersion();
                                return (minPatchVersionInt <= patchVersion) && (patchVersion <= maxPatchVersionInt);
                            });
                        }
                    } else if (minPatchVersion != null) {
                        int minPatchVersionInt = minPatchVersion;
                        stream = stream.filter(v -> v.getId().getPatchVersion() >= minPatchVersionInt);
                    } else if (maxPatchVersion != null) {
                        int maxPatchVersionInt = maxPatchVersion;
                        stream = stream.filter(v -> v.getId().getPatchVersion() <= maxPatchVersionInt);
                    }
                    return stream;
                } catch (Exception e) {
                    throw buildException(e, () -> "User " + getCurrentUser() + " is not allowed to get versions for project " + projectId, () -> "Unknown project: " + projectId, () -> "Error getting versions for project " + projectId);
                }
            }
        default:
            {
                throw new LegendSDLCServerException("Unknown project: " + projectId, Status.BAD_REQUEST);
            }
    }
}
Also used : CommitsApi(org.gitlab4j.api.CommitsApi) NewVersionType(org.finos.legend.sdlc.server.domain.api.version.NewVersionType) GitLabUserContext(org.finos.legend.sdlc.server.gitlab.auth.GitLabUserContext) CommitRef(org.gitlab4j.api.models.CommitRef) Inject(javax.inject.Inject) GitLabApiTools(org.finos.legend.sdlc.server.gitlab.tools.GitLabApiTools) LegendSDLCServerException(org.finos.legend.sdlc.server.error.LegendSDLCServerException) Tag(org.gitlab4j.api.models.Tag) PagerTools(org.finos.legend.sdlc.server.gitlab.tools.PagerTools) BackgroundTaskProcessor(org.finos.legend.sdlc.server.tools.BackgroundTaskProcessor) VersionApi(org.finos.legend.sdlc.server.domain.api.version.VersionApi) Status(javax.ws.rs.core.Response.Status) Commit(org.gitlab4j.api.models.Commit) VersionId(org.finos.legend.sdlc.domain.model.version.VersionId) Pager(org.gitlab4j.api.Pager) Collectors(java.util.stream.Collectors) BinaryOperator(java.util.function.BinaryOperator) Version(org.finos.legend.sdlc.domain.model.version.Version) RefType(org.gitlab4j.api.models.CommitRef.RefType) GitLabProjectId(org.finos.legend.sdlc.server.gitlab.GitLabProjectId) List(java.util.List) Stream(java.util.stream.Stream) GitLabApiException(org.gitlab4j.api.GitLabApiException) Comparator(java.util.Comparator) Collections(java.util.Collections) GitLabApi(org.gitlab4j.api.GitLabApi) LegendSDLCServerException(org.finos.legend.sdlc.server.error.LegendSDLCServerException) Stream(java.util.stream.Stream) LegendSDLCServerException(org.finos.legend.sdlc.server.error.LegendSDLCServerException) GitLabApiException(org.gitlab4j.api.GitLabApiException)

Aggregations

LegendSDLCServerException (org.finos.legend.sdlc.server.error.LegendSDLCServerException)64 GitLabProjectId (org.finos.legend.sdlc.server.gitlab.GitLabProjectId)34 GitLabApiException (org.gitlab4j.api.GitLabApiException)23 ProjectFileAccessProvider (org.finos.legend.sdlc.server.project.ProjectFileAccessProvider)20 RepositoryApi (org.gitlab4j.api.RepositoryApi)17 MergeRequest (org.gitlab4j.api.models.MergeRequest)16 GitLabApi (org.gitlab4j.api.GitLabApi)14 Branch (org.gitlab4j.api.models.Branch)11 ProjectStructure (org.finos.legend.sdlc.server.project.ProjectStructure)10 ProjectConfiguration (org.finos.legend.sdlc.domain.model.project.configuration.ProjectConfiguration)7 GitLabMode (org.finos.legend.sdlc.server.gitlab.mode.GitLabMode)7 DiffRef (org.gitlab4j.api.models.DiffRef)7 Revision (org.finos.legend.sdlc.domain.model.revision.Revision)6 VersionId (org.finos.legend.sdlc.domain.model.version.VersionId)6 MergeRequestApi (org.gitlab4j.api.MergeRequestApi)6 List (java.util.List)5 CommitsApi (org.gitlab4j.api.CommitsApi)5 Commit (org.gitlab4j.api.models.Commit)5 Comparator (java.util.Comparator)4 Pattern (java.util.regex.Pattern)4