James Moger
2011-11-04 fa5e6f97aab0faca8e11ab8a264b0190c145b07f
src/com/gitblit/client/GitblitClient.java
@@ -25,6 +25,7 @@
import java.util.Map;
import java.util.Set;
import com.gitblit.Constants;
import com.gitblit.GitBlitException.ForbiddenException;
import com.gitblit.GitBlitException.NotAllowedException;
import com.gitblit.GitBlitException.UnauthorizedException;
@@ -38,6 +39,7 @@
import com.gitblit.models.SyndicatedEntryModel;
import com.gitblit.models.UserModel;
import com.gitblit.utils.RpcUtils;
import com.gitblit.utils.StringUtils;
import com.gitblit.utils.SyndicationUtils;
/**
@@ -50,6 +52,8 @@
public class GitblitClient implements Serializable {
   private static final long serialVersionUID = 1L;
   private static final Date NEVER = new Date(0);
   protected final GitblitRegistration reg;
@@ -94,6 +98,7 @@
   }
   public void login() throws IOException {
      refreshSettings();
      refreshAvailableFeeds();
      refreshRepositories();
@@ -108,7 +113,6 @@
         // credentials may not have administrator access
         // or server may have disabled rpc management
         refreshUsers();
         refreshSettings();
         allowManagement = true;
      } catch (UnauthorizedException e) {
      } catch (ForbiddenException e) {
@@ -130,7 +134,6 @@
      } catch (IOException e) {
         e.printStackTrace();
      }
   }
   public boolean allowManagement() {
@@ -143,6 +146,33 @@
   public boolean isOwner(RepositoryModel model) {
      return account != null && account.equalsIgnoreCase(model.owner);
   }
   public String getURL(String action, String repository, String objectId) {
      boolean mounted = settings.get(Keys.web.mountParameters).getBoolean(true);
      StringBuilder sb = new StringBuilder();
      sb.append(url);
      sb.append('/');
      sb.append(action);
      sb.append('/');
      if (mounted) {
         // mounted url/action/repository/objectId
         sb.append(StringUtils.encodeURL(repository));
         if (!StringUtils.isEmpty(objectId)) {
            sb.append('/');
            sb.append(objectId);
         }
         return sb.toString();
      } else {
         // parameterized url/action/&r=repository&h=objectId
         sb.append("?r=");
         sb.append(repository);
         if (!StringUtils.isEmpty(objectId)) {
            sb.append("&h=");
            sb.append(objectId);
         }
         return sb.toString();
      }
   }
   public ServerSettings getSettings() {
@@ -184,17 +214,31 @@
      return status;
   }
   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;
   }
   public List<FeedModel> getAvailableFeeds() {
      return availableFeeds;
   }
   public List<FeedModel> getAvailableFeeds(RepositoryModel repository) {
      return getAvailableFeeds(repository.name);
   }
   public List<FeedModel> getAvailableFeeds(String repository) {
      List<FeedModel> repositoryFeeds = new ArrayList<FeedModel>();
      if (repository == null) {
         return repositoryFeeds;
      }
      for (FeedModel feed : availableFeeds) {
         if (feed.repository.equalsIgnoreCase(repository.name)) {
         if (feed.repository.equalsIgnoreCase(repository)) {
            repositoryFeeds.add(feed);
         }
      }
@@ -213,12 +257,14 @@
      Set<SyndicatedEntryModel> allEntries = new HashSet<SyndicatedEntryModel>();
      if (reg.feeds.size() > 0) {
         for (FeedModel feed : reg.feeds) {
            feed.lastRefresh = new Date();
            feed.lastRefreshDate = feed.currentRefreshDate;
            feed.currentRefreshDate = new Date();
            List<SyndicatedEntryModel> entries = SyndicationUtils.readFeed(url,
                  feed.repository, feed.branch, feed.maxRetrieval, account, password);
                  feed.repository, feed.branch, -1, account, password);
            allEntries.addAll(entries);
         }
      }
      reg.cacheFeeds();
      syndicatedEntries.clear();
      syndicatedEntries.addAll(allEntries);
      Collections.sort(syndicatedEntries);
@@ -241,12 +287,30 @@
      }
   }
   public Date getLastFeedRefresh(String repository, String branch) {
      FeedModel feed = new FeedModel();
      feed.repository = repository;
      feed.branch = branch;
      if (reg.feeds.contains(feed)) {
         int idx = reg.feeds.indexOf(feed);
         feed = reg.feeds.get(idx);
         return feed.lastRefreshDate;
      }
      return NEVER;
   }
   public boolean isSubscribed(RepositoryModel repository) {
      return subscribedRepositories.contains(repository.name.toLowerCase());
   }
   public List<SyndicatedEntryModel> getSyndicatedEntries() {
      return syndicatedEntries;
   }
   public List<SyndicatedEntryModel> search(String repository, String branch, String fragment,
         Constants.SearchType type, int numberOfEntries) throws IOException {
      return SyndicationUtils.readSearchFeed(url, repository, branch, fragment, type,
            numberOfEntries, account, password);
   }
   public List<FederationModel> refreshFederationRegistrations() throws IOException {
@@ -290,7 +354,7 @@
   public boolean createRepository(RepositoryModel repository, List<String> permittedUsers)
         throws IOException {
      boolean success = true;
      success &= RpcUtils.createRepository(repository, url, account, password);
      success &= RpcUtils.createRepository(repository, url, account, password);
      if (permittedUsers.size() > 0) {
         // if new repository has named members, set them
         success &= RpcUtils.setRepositoryMembers(repository, permittedUsers, url, account,