Package br.edu.utfpr.cm.JGitMinerWeb.services.miner

Source Code of br.edu.utfpr.cm.JGitMinerWeb.services.miner.RepositoryServices

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package br.edu.utfpr.cm.JGitMinerWeb.services.miner;

import br.edu.utfpr.cm.JGitMinerWeb.dao.GenericDao;
import br.edu.utfpr.cm.JGitMinerWeb.model.miner.EntityRepository;
import br.edu.utfpr.cm.JGitMinerWeb.util.OutLog;
import java.io.Serializable;
import java.util.Date;
import java.util.List;
import org.eclipse.egit.github.core.Repository;
import org.eclipse.egit.github.core.service.RepositoryService;

/**
*
* @author Douglas
*/
public class RepositoryServices implements Serializable {

    private static EntityRepository getRepositoryByIdRepository(Long idRepo, GenericDao dao) {
        List<EntityRepository> users = dao.executeNamedQueryWithParams("Repository.findByIdRepository", new String[]{"idRepository"}, new Object[]{idRepo});
        if (!users.isEmpty()) {
            return users.get(0);
        }
        return null;
    }

    public static EntityRepository createEntity(Repository gitRepository, GenericDao dao, boolean primary) {
        if (gitRepository == null) {
            return null;
        }

        EntityRepository repo = getRepositoryByIdRepository(gitRepository.getId(), dao);

        if (primary || repo == null) {
            if (repo == null) {
                repo = new EntityRepository();
            }
            repo.setParent(RepositoryServices.createEntity(gitRepository.getParent(), dao, false));
            repo.setSource(RepositoryServices.createEntity(gitRepository.getSource(), dao, false));
            repo.setMasterBranch(gitRepository.getMasterBranch());
        }

        repo.setMineredAt(new Date());
        repo.setPrimaryMiner(primary);
        repo.setFork(gitRepository.isFork());
        repo.setHasDownloads(gitRepository.isHasDownloads());
        repo.setHasIssues(gitRepository.isHasIssues());
        repo.setHasWiki(gitRepository.isHasWiki());
        repo.setIsPrivate(gitRepository.isPrivate());
        repo.setCreatedAt(gitRepository.getCreatedAt());
        repo.setPushedAt(gitRepository.getPushedAt());
        repo.setUpdatedAt(gitRepository.getUpdatedAt());
        repo.setIdRepository(gitRepository.getId());
        repo.setSizeRepository(gitRepository.getSize());
        repo.setCloneUrl(gitRepository.getCloneUrl());
        repo.setDescription(gitRepository.getDescription());
        repo.setHomepage(gitRepository.getHomepage());
        repo.setGitUrl(gitRepository.getGitUrl());
        repo.setHtmlUrl(gitRepository.getHtmlUrl());
        repo.setLanguageRepository(gitRepository.getLanguage());
        repo.setMirrorUrl(gitRepository.getMirrorUrl());
        repo.setName(gitRepository.getName());
        repo.setSshUrl(gitRepository.getSshUrl());
        repo.setSvnUrl(gitRepository.getSvnUrl());
        repo.setUrl(gitRepository.getUrl());
        repo.setOwner(UserServices.createEntity(gitRepository.getOwner(), dao, false));

        if (repo.getId() == null || repo.getId().equals(0l)) {
            dao.insert(repo);
        } else {
            dao.edit(repo);
        }

        return repo;
    }

    public static Repository getGitRepository(String ownerLogin, String repoName) throws Exception {
        return new RepositoryService(AuthServices.getGitHubClient()).getRepository(ownerLogin, repoName);
    }

    public static List<Repository> getGitForksFromRepository(Repository gitRepo, OutLog out) throws Exception {
        out.printLog("Baixando Forks...\n");
        List<Repository> forks = new RepositoryService(AuthServices.getGitHubClient()).getForks(gitRepo);
        out.printLog(forks.size() + " Forks baixados!");
        return forks;
    }
}
TOP

Related Classes of br.edu.utfpr.cm.JGitMinerWeb.services.miner.RepositoryServices

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.