This is the codeAbility Sharing Platform! Learn more about the codeAbility Sharing Platform.

Skip to content
Snippets Groups Projects
Commit db2ac00c authored by Michael Breu's avatar Michael Breu :speech_balloon:
Browse files

Fixing Connector version

parent f33ea2ff
1 merge request!55June Release
package at.ac.uibk.gitsearch.domain;
import java.text.ParseException;
import java.util.regex.MatchResult;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
* represents an exercise id.
* Also provides some utility methods to parse and unparse exercise Ids
* @author Michael Breu
*
*/
public class ExerciseId {
private String projectId; // should be numeric
private String path; // a path with slashes (root slash omitted)
public ExerciseId() {
}
public ExerciseId(String projectId, String path) {
super();
this.projectId = projectId;
this.path = path;
}
/**
* @return the projectId
*/
public String getProjectId() {
return projectId;
}
/**
* @return the path
*/
public String getPath() {
return path;
}
protected final static Pattern ExerciseIdPattern = Pattern.compile("(\\d+)(:(.*))?");
public String toString() {
if(path==null)
return projectId;
if (path.equals(""))
return projectId;
return projectId + ":" + path;
}
/**
* parses the external representation of an ExerciseId.
* @param externalRepresentation
* @return
* @throws ParseException
*/
public static ExerciseId fromString(String externalRepresentation) throws ParseException {
final Matcher ma = ExerciseIdPattern.matcher(externalRepresentation);
if(!ma.matches()) throw new ParseException("Cannot parse " + externalRepresentation, 0);
final MatchResult matchResult = ma.toMatchResult();
String projectId = matchResult.group(1);
String path = matchResult.group(3);
while (path!=null && path.startsWith("/")) {
path = path.substring(1);
}
return new ExerciseId(projectId, path);
}
}
......@@ -11,6 +11,7 @@ import java.util.regex.Pattern;
import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;
import org.codeability.sharing.plugins.api.search.util.ExerciseId;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
......@@ -32,7 +33,6 @@ import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.HandlerMapping;
import org.springframework.web.servlet.support.ServletUriComponentsBuilder;
import at.ac.uibk.gitsearch.domain.ExerciseId;
import at.ac.uibk.gitsearch.service.GitlabService;
import at.ac.uibk.gitsearch.service.StatisticsService;
import at.ac.uibk.gitsearch.service.dto.StatisticsDTO;
......
......@@ -2,6 +2,7 @@ package at.ac.uibk.gitsearch.domain;
import java.text.ParseException;
import org.codeability.sharing.plugins.api.search.util.ExerciseId;
import org.junit.Assert;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment