java/code/src/com/redhat/rhn/domain/channel/ChannelFactory.java | 8 java/code/src/com/redhat/rhn/manager/channel/repo/CreateRepoCommand.java | 121 ++++++++++ 2 files changed, 129 insertions(+)
New commits: commit 285b59d1710b1bfd8080c23197d759809c57b1d1 Author: Shannon Hughes shughes@redhat.com Date: Tue May 18 15:35:11 2010 -0400
support classes for adding a Repo object
diff --git a/java/code/src/com/redhat/rhn/domain/channel/ChannelFactory.java b/java/code/src/com/redhat/rhn/domain/channel/ChannelFactory.java index 5fbc56b..ed8d74d 100644 --- a/java/code/src/com/redhat/rhn/domain/channel/ChannelFactory.java +++ b/java/code/src/com/redhat/rhn/domain/channel/ChannelFactory.java @@ -457,6 +457,14 @@ public class ChannelFactory extends HibernateFactory { public static Channel createChannel() { return new Channel(); } + + /** + * Creates an empty Repo + * @return empty Repo + */ + public static ContentSource createRepo() { + return new ContentSource(); + }
/** * Utility to call {@link #refreshNewestPackageCache(Long, String)} given a channel. diff --git a/java/code/src/com/redhat/rhn/manager/channel/repo/CreateRepoCommand.java b/java/code/src/com/redhat/rhn/manager/channel/repo/CreateRepoCommand.java new file mode 100644 index 0000000..adec5e4 --- /dev/null +++ b/java/code/src/com/redhat/rhn/manager/channel/repo/CreateRepoCommand.java @@ -0,0 +1,121 @@ +/** + * Copyright (c) 2009--2010 Red Hat, Inc. + * + * This software is licensed to you under the GNU General Public License, + * version 2 (GPLv2). There is NO WARRANTY for this software, express or + * implied, including the implied warranties of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. You should have received a copy of GPLv2 + * along with this software; if not, see + * http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt. + * + * Red Hat trademarks are not licensed under GPLv2. No permission is + * granted to use or replicate Red Hat trademarks that are incorporated + * in this software or its documentation. + */ +package com.redhat.rhn.manager.channel.repo; + +import java.util.ArrayList; +import java.util.List; + +import org.apache.log4j.Logger; + +import com.redhat.rhn.common.validator.ValidatorError; +import com.redhat.rhn.domain.channel.ChannelFactory; +import com.redhat.rhn.domain.channel.ContentSource; + +/** + * CreateRepoCommand - Command to create a repo + * @version $Rev: 119601 $ + */ +public class CreateRepoCommand { + + private String label; + private String url; + private ContentSource newRepo; + private List<ValidatorError> errors; + + private static Logger log = Logger.getLogger(CreateRepoCommand.class); + + /** + * Constructor to create an org + * @param nameIn to set on the org + * @param loginIn to use for 1st user in org + * @param passwordIn to set for first user + * @param emailIn to set for first user + */ + public CreateRepoCommand(String labelIn, String urlIn) { + this.label = labelIn; + this.url = urlIn; + } + + /** + * + * @return label for repo + */ + public String getLabel() { + return label; + } + + /** + * + * @param labelIn to set for repo + */ + public void setLabel(String LabelIn) { + this.label = LabelIn; + } + + /** + * + * @return url for repo + */ + public String getUrl() { + return url; + } + + /** + * + * @param urlIn to set for repo + */ + public void setUrl(String urlIn) { + this.url = urlIn; + } + + /** + * Check for errors and store Org to db. + * @return ValidatorError[] array if there are errors + */ + public ValidatorError[] store() { + ValidatorError[] errors = validate(); + if (errors != null && errors.length > 0) { + return errors; + } + else { + // Create repo + ContentSource repo = ChannelFactory.createRepo(); + repo.setLabel(this.label); + repo.setSourceUrl(this.url); + ChannelFactory.save(repo); + this.newRepo = repo; + } + return null; + } + + /** + * Get the newly created org. + * @return Org that was stored to DB + */ + public ContentSource getNewRepo() { + return this.newRepo; + } + + /** + * Validates the repo object. + * @return an Object array of ValidatorErrors. + */ + public ValidatorError[] validate() { + errors = new ArrayList(); //clear validation errors + return (ValidatorError[]) errors.toArray(new ValidatorError[0]); + } + + +}
spacewalk-commits@lists.fedorahosted.org