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));
}
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));
}
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);
}
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");
}
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);
}
}
}
Aggregations