James Moger
2012-04-25 e191104cd356faa2e261cc37585143878e23298d
commit | author | age
831469 1 /*
JM 2  * Copyright 2011 gitblit.com.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 package com.gitblit.models;
17
18 import java.io.Serializable;
19 import java.util.Date;
20 import java.util.Map;
21
22 import com.gitblit.Constants.FederationToken;
23
24 /**
25  * Represents a proposal from a Gitblit instance to pull its repositories.
26  */
27 public class FederationProposal implements Serializable {
28
29     private static final long serialVersionUID = 1L;
30
31     public Date received;
32
33     public String name;
34
35     public String url;
36
37     public FederationToken tokenType;
38
39     public String token;
dd9ae7 40     
JM 41     public String message;
831469 42
JM 43     public Map<String, RepositoryModel> repositories;
44
45     /**
46      * The constructor for a federation proposal.
47      * 
48      * @param url
49      *            the url of the source Gitblit instance
50      * @param tokenType
51      *            the type of token from the source Gitblit instance
52      * @param token
53      *            the federation token from the source Gitblit instance
54      * @param repositories
55      *            the map of repositories to be pulled from the source Gitblit
56      *            instance keyed by the repository clone url
57      */
58     public FederationProposal(String url, FederationToken tokenType, String token,
59             Map<String, RepositoryModel> repositories) {
60         this.received = new Date();
61         this.url = url;
62         this.tokenType = tokenType;
63         this.token = token;
dd9ae7 64         this.message = "";
831469 65         this.repositories = repositories;
JM 66         try {
67             // determine server name and set that as the proposal name
68             name = url.substring(url.indexOf("//") + 2);
69             if (name.contains("/")) {
70                 name = name.substring(0, name.indexOf('/'));
71             }
dd9ae7 72             name = name.replace(".", "").replace(";", "").replace(":", "").replace("-", "");
831469 73         } catch (Exception e) {
JM 74             name = Long.toHexString(System.currentTimeMillis());
75         }
76     }
77
78     @Override
79     public String toString() {
80         return "Federation Proposal (" + url + ")";
81     }
82 }