Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gitlab #121

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
839 changes: 839 additions & 0 deletions node_modules/@polymer/paper-slider/paper-slider.js

Large diffs are not rendered by default.

299 changes: 299 additions & 0 deletions package-lock.json

Large diffs are not rendered by default.

7 changes: 5 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"@polymer/iron-list": "3.1.0",
"@polymer/iron-meta": "3.0.1",
"@polymer/iron-resizable-behavior": "3.0.1",
"@polymer/paper-slider": "3.0.1",
"@polymer/polymer": "3.5.1",
"@vaadin/accordion": "23.2.11",
"@vaadin/app-layout": "23.2.11",
Expand Down Expand Up @@ -133,6 +134,7 @@
"@polymer/iron-list": "3.1.0",
"@polymer/iron-meta": "3.0.1",
"@polymer/iron-resizable-behavior": "3.0.1",
"@polymer/paper-slider": "3.0.1",
"@polymer/polymer": "3.5.1",
"@vaadin/accordion": "23.2.11",
"@vaadin/app-layout": "23.2.11",
Expand Down Expand Up @@ -252,7 +254,7 @@
"workbox-core": "6.5.0",
"workbox-precaching": "6.5.0"
},
"hash": "b0fdb93e5b0841a4e7180e6c7c73c3bd2e583d1a36aca2f5ee4307c817248ea0"
"hash": "b3094de5d39c28514094f0555fc3e59751af2627a0ea11001400f44d8cff3594"
},
"overrides": {
"@vaadin/bundles": "$@vaadin/bundles",
Expand Down Expand Up @@ -359,6 +361,7 @@
"@vaadin/lit-renderer": "$@vaadin/lit-renderer",
"@vaadin/confirm-dialog": "$@vaadin/confirm-dialog",
"@vaadin/multi-select-combo-box": "$@vaadin/multi-select-combo-box",
"@vaadin/vaadin-confirm-dialog": "$@vaadin/vaadin-confirm-dialog"
"@vaadin/vaadin-confirm-dialog": "$@vaadin/vaadin-confirm-dialog",
"@polymer/paper-slider": "$@polymer/paper-slider"
}
}
17 changes: 17 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
<enabled>false</enabled>
</snapshots>
</repository>

</repositories>

<pluginRepositories>
Expand Down Expand Up @@ -109,6 +110,15 @@
<artifactId>spring-boot-starter-oauth2-client</artifactId>
</dependency>
<!-- End Spring -->

<!-- Vaadin -->
<dependency>
<groupId>org.vaadin.addons.componentfactory</groupId>
<artifactId>lumo-paper-slider</artifactId>
<version>1.0.1</version>
<scope>compile</scope>
</dependency>
<!-- End Vaadin -->

<!-- For RadarChart -->
<dependency>
Expand Down Expand Up @@ -145,6 +155,13 @@
<version>1.313</version>
</dependency>

<!-- GitLab API -->
<dependency>
<groupId>org.gitlab4j</groupId>
<artifactId>gitlab4j-api</artifactId>
<version>5.3.0</version>
</dependency>

<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
Expand Down
8 changes: 8 additions & 0 deletions src/main/java/io/bssw/psip/backend/model/CategoryScore.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
public class CategoryScore {
private String path = "";
private String score = "";
private String name = "";
private List<ItemScore> surveyScores = new ArrayList<>();

public String getPath() {
Expand All @@ -50,6 +51,13 @@ public String getScore() {
public void setScore(String score) {
this.score = score;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}

public List<ItemScore> getItemScores() {
return surveyScores;
}
Expand Down
30 changes: 30 additions & 0 deletions src/main/java/io/bssw/psip/backend/model/SurveyScore.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,46 @@
*******************************************************************************/
package io.bssw.psip.backend.model;

import com.fasterxml.jackson.annotation.JsonIgnore;

import java.time.LocalDate;
import java.time.LocalTime;
import java.time.format.DateTimeFormatter;
import java.time.format.FormatStyle;
import java.util.ArrayList;
import java.util.List;

public class SurveyScore {
private String timestamp = "";
private String version = "";
@JsonIgnore
private String friendlyTimestamp = "";
private List<CategoryScore> categoryScores = new ArrayList<>();

public String getTimestamp() {
return timestamp;
}
@JsonIgnore
public String getFriendlyTimestamp() {
//TODO: see if it's possible to pass in a locale, everything is in UTC
/*NOTE: assuming that the formatting of the date and time don't change
these hard-coded numbers should work.
*/
if (friendlyTimestamp.equals("")) {
String dateStamp = timestamp.substring(0, 10);
String timeStamp = timestamp.substring(11, 19);
LocalDate date = LocalDate.parse(dateStamp);
String newDate = date.format(DateTimeFormatter.ofLocalizedDate(FormatStyle.MEDIUM));
LocalTime time = LocalTime.parse(timeStamp);
String newTime = time.format(DateTimeFormatter.ofLocalizedTime(FormatStyle.SHORT));
return newDate + " at " + newTime;
}
return friendlyTimestamp;
}
@JsonIgnore
public void setFriendlyTimestamp(String friendlyTimestamp) {
this.friendlyTimestamp = friendlyTimestamp;
}
public void setTimestamp(String timestamp) {
this.timestamp = timestamp;
}
Expand All @@ -56,4 +85,5 @@ public List<CategoryScore> getCategoryScores() {
public void setCategoryScores(List<CategoryScore> categoryScores) {
this.categoryScores = categoryScores;
}

}
Original file line number Diff line number Diff line change
@@ -1,17 +1,166 @@
package io.bssw.psip.backend.service;

import io.bssw.psip.ui.views.Home;
import org.gitlab4j.api.*;
import org.gitlab4j.api.models.Branch;
import org.gitlab4j.api.models.Project;
import org.gitlab4j.api.models.RepositoryFile;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.security.oauth2.core.OAuth2AccessToken;
import org.springframework.stereotype.Service;

import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;

//NOTE: *** all methods requiring the "projectIdOrPath" argument (usually the first argument) may not require
// the GITLAB_URL constant to be concatenated, will know after testing ***

@Service
public class GitLabRepositoryProvider extends AbstractRepositoryProvider {

private static final String GITLAB_URL = "https://code.ornl.gov/";
private static final String COMMIT_MESSAGE_CREATE = "created .psip/history.json file and added the first survey score.";
private static final String COMMIT_MESSAGE_UPDATE = "updated .psip/history.json file.";
private static final String SURVEY_FILE = ".psip/survey.yml";
public static final String HISTORY_FILE = ".psip/history.json";

private static final Logger LOGGER = LoggerFactory.getLogger(GitLabRepositoryProvider.class);
private GitLabApi gl;
private RepositoryApi glRepo;
private Branch glBranch;

@Override
public String getName() {
return "gitlab";
}
@Override
public boolean login() {
if (gl == null) {
OAuth2AccessToken token = getRepositoryManager().getAccessToken();
gl = new GitLabApi(GITLAB_URL, token.getTokenValue());
}
return true;
}
public void logout() {
gl = null;
glRepo = null;
glBranch = null;
}
@Override
public void connect(String url, String branch) throws Exception {
if (gl != null && url != null && branch != null) {
glRepo = gl.getRepositoryApi();
glBranch = glRepo.getBranch(GITLAB_URL + url, branch);
}
}
@Override
public void disconnect() {
glRepo = null;
glBranch = null;
}

@Override
public boolean isConnected() {
return glRepo != null && glBranch != null;
}

@Override
public InputStream readFile(String path) throws IOException {
if (isConnected()) {
try {
RepositoryFileApi repoFileApi = new RepositoryFileApi(gl);
RepositoryFile repoFile = repoFileApi.getFile(GITLAB_URL + Home.getRepo(), path, Home.getBranch());
return new ByteArrayInputStream(repoFile.getDecodedContentAsBytes());
} catch (GitLabApiException e) {
LOGGER.error(e.getLocalizedMessage());
return null;
}
}
throw new IOException("Could not read from " + SURVEY_FILE + " because there is no connection to the repo.");
}
@Override
public void writeFile(String path, String contents) throws IOException {
RepositoryFileApi repoFileApi = new RepositoryFileApi(gl);
if (isConnected()) {
try {
RepositoryFile repoFile = repoFileApi.getFile(GITLAB_URL + Home.getRepo(), path, Home.getBranch());
repoFile.setContent(contents);
repoFile.setFilePath(path);
repoFileApi.updateFile(GITLAB_URL + Home.getRepo(), repoFile, Home.getBranch(), COMMIT_MESSAGE_UPDATE);
return;
} catch (GitLabApiException e) {
LOGGER.error(e.getLocalizedMessage());
}
try {
RepositoryFile repoFile = new RepositoryFile();
repoFile.setContent(contents);
repoFileApi.createFile(GITLAB_URL + Home.getRepo(), repoFile, Home.getBranch(), COMMIT_MESSAGE_CREATE);
return;
} catch (GitLabApiException e) {
LOGGER.error(e.getLocalizedMessage());
}
}
throw new IOException("Could not write to " + HISTORY_FILE + " because there is no connection to the repo.");
}
@Override
public boolean canProvideRepositories() {
return false;
}
@Override
public List<String> getRepositories() {
List<String> repositories = new ArrayList<>();
if (gl != null) {
ProjectApi projectApi = gl.getProjectApi();
try {
List<Project> projectList = (List<Project>) projectApi.getProjects(gl.getDefaultPerPage());
for (Project project : projectList) {
repositories.add(project.getName());
}
} catch (GitLabApiException e) {
LOGGER.error("Error while trying to get the gitlab projects");
throw new RuntimeException(e);
}
}
return repositories;
}
@Override
public List<String> getBranches(String repository) {
//NOTE: really don't have a way to use this repository argument with this API
List<String> branches = new ArrayList<>();
if (glRepo != null) {
try {
List<Branch> branchList = glRepo.getBranches(GITLAB_URL + Home.getRepo());
for (Branch branch : branchList) {
branches.add(branch.getName());
}
} catch (GitLabApiException e) {
LOGGER.error("Error while trying to return the branches.");
// throw new RuntimeException(e);
}
}
return branches;
}
@Override
public String getDefaultBranch(String repository) {
String defaultBranch = "";
try {
List<Branch> branches = glRepo.getBranches(GITLAB_URL + Home.getRepo());
for (Branch branch: branches) {
if (branch.getDefault()) {
defaultBranch = branch.getName();
break;
}
}
return defaultBranch;
} catch (GitLabApiException e) {
throw new RuntimeException(e);
}
}



}
Loading