Search in sources :

Example 1 with FeedModel

use of com.gitblit.models.FeedModel in project gitblit by gitblit.

the class RpcUtils method getBranchFeeds.

/**
	 * Retrieves a list of available branch feeds in the Gitblit server.
	 *
	 * @param serverUrl
	 * @param account
	 * @param password
	 * @return
	 * @throws IOException
	 */
public static List<FeedModel> getBranchFeeds(String serverUrl, String account, char[] password) throws IOException {
    List<FeedModel> feeds = new ArrayList<FeedModel>();
    Map<String, Collection<String>> allBranches = getBranches(serverUrl, account, password);
    for (Map.Entry<String, Collection<String>> entry : allBranches.entrySet()) {
        for (String branch : entry.getValue()) {
            FeedModel feed = new FeedModel();
            feed.repository = entry.getKey();
            feed.branch = branch;
            feeds.add(feed);
        }
    }
    return feeds;
}
Also used : FeedModel(com.gitblit.models.FeedModel) ArrayList(java.util.ArrayList) Collection(java.util.Collection) Map(java.util.Map)

Example 2 with FeedModel

use of com.gitblit.models.FeedModel in project gitblit by gitblit.

the class GitblitClient method getBranches.

public List<String> getBranches(String repository) {
    List<FeedModel> feeds = getAvailableFeeds(repository);
    List<String> branches = new ArrayList<String>();
    for (FeedModel feed : feeds) {
        branches.add(feed.branch);
    }
    Collections.sort(branches);
    return branches;
}
Also used : FeedModel(com.gitblit.models.FeedModel) ArrayList(java.util.ArrayList)

Example 3 with FeedModel

use of com.gitblit.models.FeedModel in project gitblit by gitblit.

the class GitblitClient method refreshSubscribedFeeds.

public List<FeedEntryModel> refreshSubscribedFeeds(int page) throws IOException {
    Set<FeedEntryModel> allEntries = new HashSet<FeedEntryModel>();
    if (reg.feeds.size() > 0) {
        for (FeedModel feed : reg.feeds) {
            feed.lastRefreshDate = feed.currentRefreshDate;
            feed.currentRefreshDate = new Date();
            List<FeedEntryModel> entries = SyndicationUtils.readFeed(url, feed.repository, feed.branch, -1, page, account, password);
            allEntries.addAll(entries);
        }
    }
    reg.cacheFeeds();
    syndicatedEntries.clear();
    syndicatedEntries.addAll(allEntries);
    Collections.sort(syndicatedEntries);
    return syndicatedEntries;
}
Also used : FeedModel(com.gitblit.models.FeedModel) FeedEntryModel(com.gitblit.models.FeedEntryModel) Date(java.util.Date) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet)

Example 4 with FeedModel

use of com.gitblit.models.FeedModel in project gitblit by gitblit.

the class GitblitManager method saveRegistration.

@Override
public boolean saveRegistration(String name, GitblitRegistration reg) {
    try {
        StoredConfig config = getConfig();
        if (!StringUtils.isEmpty(name) && !name.equals(reg.name)) {
            // delete old registration
            registrations.remove(name);
            config.unsetSection(SERVER, name);
        }
        // update registration
        config.setString(SERVER, reg.name, "url", reg.url);
        config.setString(SERVER, reg.name, "account", reg.account);
        if (reg.savePassword) {
            config.setString(SERVER, reg.name, "password", Base64.encodeBytes(new String(reg.password).getBytes("UTF-8")));
        } else {
            config.setString(SERVER, reg.name, "password", "");
        }
        if (reg.lastLogin != null) {
            config.setString(SERVER, reg.name, "lastLogin", dateFormat.format(reg.lastLogin));
        }
        // serialize the feed definitions
        List<String> definitions = new ArrayList<String>();
        for (FeedModel feed : reg.feeds) {
            definitions.add(feed.toString());
        }
        if (definitions.size() > 0) {
            config.setStringList(SERVER, reg.name, FEED, definitions);
        }
        config.save();
        return true;
    } catch (Throwable t) {
        Utils.showException(GitblitManager.this, t);
    }
    return false;
}
Also used : StoredConfig(org.eclipse.jgit.lib.StoredConfig) FeedModel(com.gitblit.models.FeedModel) ArrayList(java.util.ArrayList)

Example 5 with FeedModel

use of com.gitblit.models.FeedModel in project gitblit by gitblit.

the class GitblitManager method loadRegistrations.

private void loadRegistrations() {
    try {
        StoredConfig config = getConfig();
        Set<String> servers = config.getSubsections(SERVER);
        for (String server : servers) {
            Date lastLogin = new Date(0);
            String date = config.getString(SERVER, server, "lastLogin");
            if (!StringUtils.isEmpty(date)) {
                lastLogin = dateFormat.parse(date);
            }
            String url = config.getString(SERVER, server, "url");
            String account = config.getString(SERVER, server, "account");
            char[] password;
            String pw = config.getString(SERVER, server, "password");
            if (StringUtils.isEmpty(pw)) {
                password = new char[0];
            } else {
                password = new String(Base64.decode(pw)).toCharArray();
            }
            GitblitRegistration reg = new GitblitRegistration(server, url, account, password) {

                private static final long serialVersionUID = 1L;

                @Override
                protected void cacheFeeds() {
                    writeFeedCache(this);
                }
            };
            String[] feeds = config.getStringList(SERVER, server, FEED);
            if (feeds != null) {
                // deserialize the field definitions
                for (String definition : feeds) {
                    FeedModel feed = new FeedModel(definition);
                    reg.feeds.add(feed);
                }
            }
            reg.lastLogin = lastLogin;
            loadFeedCache(reg);
            registrations.put(reg.name, reg);
        }
    } catch (Throwable t) {
        Utils.showException(GitblitManager.this, t);
    }
}
Also used : StoredConfig(org.eclipse.jgit.lib.StoredConfig) FeedModel(com.gitblit.models.FeedModel) Date(java.util.Date)

Aggregations

FeedModel (com.gitblit.models.FeedModel)11 ArrayList (java.util.ArrayList)3 Date (java.util.Date)3 ForbiddenException (com.gitblit.GitBlitException.ForbiddenException)2 File (java.io.File)2 IOException (java.io.IOException)2 ConnectException (java.net.ConnectException)2 ConfigInvalidException (org.eclipse.jgit.errors.ConfigInvalidException)2 StoredConfig (org.eclipse.jgit.lib.StoredConfig)2 FeedEntryModel (com.gitblit.models.FeedEntryModel)1 BorderLayout (java.awt.BorderLayout)1 FlowLayout (java.awt.FlowLayout)1 Insets (java.awt.Insets)1 ActionEvent (java.awt.event.ActionEvent)1 ActionListener (java.awt.event.ActionListener)1 BufferedReader (java.io.BufferedReader)1 FileReader (java.io.FileReader)1 FileWriter (java.io.FileWriter)1 SimpleDateFormat (java.text.SimpleDateFormat)1 Collection (java.util.Collection)1