Repository.java 2.9 KB
Newer Older
/*
 * Copyright 2020 École des Mines de Saint-Étienne.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package fr.emse.gitlab.saref.entities.git;

import java.io.File;
Maxime Lefrançois's avatar
Maxime Lefrançois committed
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import org.apache.jena.rdf.model.Resource;
import org.apache.jena.rdf.model.ResourceFactory;
Maxime Lefrançois's avatar
Maxime Lefrançois committed
import org.eclipse.jgit.lib.Ref;
import org.eclipse.jgit.revwalk.RevCommit;

import fr.emse.gitlab.saref.Constants;

/**
 *
 * @author maxime.lefrancois
 */
public class Repository {

Maxime Lefrançois's avatar
Maxime Lefrançois committed
	private final File directory;
	private final String name;
	private List<Version> versions;
	private String currentBranch;
Maxime Lefrançois's avatar
Maxime Lefrançois committed
	private transient Resource resource;

	public Repository(File directory, String name) {
		this.directory = directory;
		this.name = name;
		this.versions = new ArrayList<>();
	}
	
	public Repository(File directory) {
		this(directory, directory.getName());
Maxime Lefrançois's avatar
Maxime Lefrançois committed

	public void addBranchVersion(Ref ref, Date issued, String branchName) {
		versions.add(new BranchVersion(this, ref, issued, branchName));
	}

	public void addMasterVersion(Ref ref, Date issued) {
		versions.add(new MasterVersion(this, ref, issued));
	}
	
	public void addReleaseVersion(Ref ref, Date issued, int major, int minor, int patch) {
		versions.add(new ReleaseVersion(this, ref, issued, major, minor, patch));
	}
	
	public String getName() {
		return name;
	}

Maxime Lefrançois's avatar
Maxime Lefrançois committed
	public Resource getResource() {
		if (resource == null) {
			resource = ResourceFactory.createResource(getNamespace());
		}
		return resource;
	}
Maxime Lefrançois's avatar
Maxime Lefrançois committed
	public String getNamespace() {
		if (getName().equals("saref-core")) {
			return String.format("%score/", Constants.BASE);
		} else {
Maxime Lefrançois's avatar
Maxime Lefrançois committed
			return String.format("%s%s/", Constants.BASE, getName());
Maxime Lefrançois's avatar
Maxime Lefrançois committed

	public String getPrefix() {
		if (getName().equals("saref-core")) {
			return "saref:";
		} else {
Maxime Lefrançois's avatar
Maxime Lefrançois committed
			return String.format("s%s:", getName().substring(5));
Maxime Lefrançois's avatar
Maxime Lefrançois committed

	public File getDirectory() {
		return directory;
	}
Maxime Lefrançois's avatar
Maxime Lefrançois committed

	public List<Version> getVersions() {
		return versions;
	}

	public String getOntologyFileName() {
Maxime Lefrançois's avatar
Maxime Lefrançois committed
		if (getName().equals("saref-core")) {
			return "saref.ttl";
		} else {
Maxime Lefrançois's avatar
Maxime Lefrançois committed
			return String.format("%s.ttl", getName());
	public void setCurrentBranch(String currentBranch) {
		this.currentBranch = currentBranch;
	public String getCurrentBranch() {
		return currentBranch;
Maxime Lefrançois's avatar
Maxime Lefrançois committed
	}