1 /* 2 * Copyright (C) 2011-2014 eXo Platform SAS. 3 * 4 * This file is part of eXo Acceptance Webapp. 5 * 6 * eXo Acceptance Webapp is free software; you can redistribute it and/or modify it 7 * under the terms of the GNU Lesser General Public License as 8 * published by the Free Software Foundation; either version 3 of 9 * the License, or (at your option) any later version. 10 * 11 * eXo Acceptance Webapp software is distributed in the hope that it will be useful, 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 * Lesser General Public License for more details. 15 * 16 * You should have received a copy of the GNU Lesser General Public 17 * License along with eXo Acceptance Webapp; if not, write to the Free 18 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 19 * 02110-1301 USA, or see <http://www.gnu.org/licenses/>. 20 */ 21 package org.exoplatform.acceptance.model.vcs; 22 23 import org.exoplatform.acceptance.model.StorableObject; 24 25 import com.fasterxml.jackson.annotation.JsonCreator; 26 import com.fasterxml.jackson.annotation.JsonIgnoreProperties; 27 import com.fasterxml.jackson.annotation.JsonProperty; 28 import com.google.common.base.Function; 29 import com.google.common.base.Objects; 30 import com.google.common.collect.FluentIterable; 31 import java.util.ArrayList; 32 import java.util.List; 33 import javax.validation.constraints.NotNull; 34 import javax.validation.constraints.Size; 35 import org.springframework.data.mongodb.core.mapping.Document; 36 37 /** 38 * a Version Control System Repository 39 * 40 * @author Arnaud Héritier ( aheritier@exoplatform.com ) 41 * @since 2.0.0 42 */ 43 @Document(collection = "vcsrepositories") 44 @JsonIgnoreProperties({"tags", "references", "branches"}) 45 public class VCSRepository extends StorableObject { 46 47 @NotNull 48 @Size(min = 1) 49 private final List<VCSCoordinates> remoteRepositories = new ArrayList<>(); 50 51 /** 52 * The type of VCS 53 */ 54 @NotNull 55 private Type type = Type.GIT; 56 57 /** 58 * <p>Constructor for VCSRepository.</p> 59 */ 60 public VCSRepository() { 61 } 62 63 /** 64 * <p>Constructor for VCSRepository.</p> 65 * 66 * @param name a {@link java.lang.String} object. 67 */ 68 @JsonCreator 69 public VCSRepository(@NotNull @JsonProperty("name") String name) { 70 super(name); 71 } 72 73 /** 74 * <p>Constructor for VCSRepository.</p> 75 * 76 * @param name a {@link java.lang.String} object. 77 * @param id a {@link java.lang.String} object. 78 */ 79 public VCSRepository(@NotNull String name, @NotNull String id) { 80 super(name, id); 81 } 82 83 /** 84 * <p>addRemoteRepository.</p> 85 * 86 * @param name a {@link java.lang.String} object. 87 * @param url a {@link java.lang.String} object. 88 */ 89 public void addRemoteRepository(String name, String url) { 90 addRemoteRepository(new VCSCoordinates(name, url)); 91 } 92 93 /** 94 * <p>addRemoteRepository.</p> 95 * 96 * @param coordinates a {@link org.exoplatform.acceptance.model.vcs.VCSCoordinates} object. 97 */ 98 public void addRemoteRepository(VCSCoordinates coordinates) { 99 assert coordinates.getName() != null; 100 remoteRepositories.add(coordinates); 101 } 102 103 /** 104 * <p>addRemoteRepository.</p> 105 * 106 * @param name a {@link java.lang.String} object. 107 * @param url a {@link java.lang.String} object. 108 * @param credentialId a {@link java.lang.String} object. 109 */ 110 public void addRemoteRepository(String name, String url, String credentialId) { 111 addRemoteRepository(new VCSCoordinates(name, url, credentialId)); 112 } 113 114 /** 115 * <p>getTags.</p> 116 * 117 * @return a {@link java.util.List} object. 118 */ 119 public List<VCSRef> getTags() { 120 return VCSRef.SORT_BY_NAME.sortedCopy(FluentIterable.from(getReferences()).filter(VCSRef.IS_TAG).toList()); 121 } 122 123 /** 124 * <p>getReferences.</p> 125 * 126 * @return a {@link java.util.List} object. 127 */ 128 public List<VCSRef> getReferences() { 129 return VCSRef.SORT_BY_NAME.sortedCopy( 130 FluentIterable.from(getRemoteRepositories()).transformAndConcat(new Function<VCSCoordinates, 131 Iterable<VCSRef>>() { 132 // TODO : Juzu throws a NPE in live mode when using @Nullable annotation 133 //@Nullable 134 @Override 135 //public Iterable<VCSRef> apply(@Nullable coordinates input) { 136 public Iterable<VCSRef> apply(VCSCoordinates input) { 137 return input.getReferences(); 138 } 139 }).toList() 140 ); 141 } 142 143 /** 144 * <p>getBranches.</p> 145 * 146 * @return a {@link java.util.List} object. 147 */ 148 public List<VCSRef> getBranches() { 149 return VCSRef.SORT_BY_NAME.sortedCopy(FluentIterable.from(getReferences()).filter(VCSRef.IS_BRANCH).toList()); 150 } 151 152 /** 153 * {@inheritDoc} 154 * Returns a string representation of the object. In general, the 155 * {@code toString} method returns a string that 156 * "textually represents" this object. The result should 157 * be a concise but informative representation that is easy for a 158 * person to read. 159 * It is recommended that all subclasses override this method. 160 * The {@code toString} method for class {@code Object} 161 * returns a string consisting of the name of the class of which the 162 * object is an instance, the at-sign character `{@code @}', and 163 * the unsigned hexadecimal representation of the hash code of the 164 * object. In other words, this method returns a string equal to the 165 * value of: 166 * <blockquote> 167 * <pre> 168 * getClass().getName() + '@' + Integer.toHexString(hashCode()) 169 * </pre></blockquote> 170 */ 171 @Override 172 public String toString() { 173 return Objects.toStringHelper(this) 174 .add("id", getId()) 175 .add("type", getType()) 176 .add("name", getName()) 177 .add("remotes", getRemoteRepositories()) 178 .toString(); 179 } 180 181 /** 182 * <p>Getter for the field <code>type</code>.</p> 183 * 184 * @return a {@link org.exoplatform.acceptance.model.vcs.VCSRepository.Type} object. 185 */ 186 public Type getType() { 187 return type; 188 } 189 190 /** 191 * <p>Setter for the field <code>type</code>.</p> 192 * 193 * @param type a {@link org.exoplatform.acceptance.model.vcs.VCSRepository.Type} object. 194 */ 195 public void setType(@NotNull Type type) { 196 this.type = type; 197 } 198 199 /** 200 * <p>Getter for the field <code>remoteRepositories</code>.</p> 201 * 202 * @return a {@link java.util.List} object. 203 */ 204 public List<VCSCoordinates> getRemoteRepositories() { 205 return remoteRepositories; 206 } 207 208 /** 209 * <p>Setter for the field <code>remoteRepositories</code>.</p> 210 * 211 * @param coordinatesList a {@link java.util.List} object. 212 */ 213 public void setRemoteRepositories(List<VCSCoordinates> coordinatesList) { 214 remoteRepositories.clear(); 215 for (VCSCoordinates coordinates : coordinatesList) { 216 addRemoteRepository(coordinates); 217 } 218 } 219 220 /** 221 * VCS Repository types 222 */ 223 public enum Type { 224 GIT 225 } 226 227 228 }