View Javadoc

1   /*
2    * Copyright 2012-2013 smartics, Kronseder & Reiner GmbH
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 de.smartics.maven.bugzilla.command;
17  
18  import org.apache.maven.artifact.versioning.ArtifactVersion;
19  import org.apache.maven.artifact.versioning.DefaultArtifactVersion;
20  import org.codehaus.plexus.util.StringUtils;
21  
22  import de.smartics.maven.issue.command.AddComponentCommand;
23  import de.smartics.maven.issue.command.AddMilestoneCommand;
24  import de.smartics.maven.issue.command.AddProductCommand;
25  import de.smartics.maven.issue.command.AddVersionCommand;
26  import de.smartics.maven.issue.command.ClassificationNavigationCommand;
27  import de.smartics.maven.issue.command.CommandArgument;
28  import de.smartics.maven.issue.command.CommandFactory;
29  import de.smartics.maven.issue.command.LoginCommand;
30  import de.smartics.maven.issue.command.LogoutCommand;
31  import de.smartics.maven.issue.command.ProductNavigationCommand;
32  import de.smartics.maven.issue.command.UpdateProductCommand;
33  
34  /**
35   * A factory for command to run against a Bugzilla issue management system.
36   */
37  public final class BugzillaCommandFactory implements CommandFactory
38  {
39    // ********************************* Fields *********************************
40  
41    // --- constants ------------------------------------------------------------
42  
43    // --- members --------------------------------------------------------------
44  
45    /**
46     * The version of the issue server. Allows the implementation to make version
47     * dependent decisions.
48     */
49    private final String issueServerVersion;
50  
51    // ****************************** Initializer *******************************
52  
53    // ****************************** Constructors ******************************
54  
55    /**
56     * Default constructor.
57     *
58     * @param issueServerVersion the version of the issue server.
59     */
60    public BugzillaCommandFactory(final String issueServerVersion)
61    {
62      this.issueServerVersion = issueServerVersion;
63    }
64  
65    // ****************************** Inner Classes *****************************
66  
67    // ********************************* Methods ********************************
68  
69    // --- init -----------------------------------------------------------------
70  
71    // --- get&set --------------------------------------------------------------
72  
73    // --- business -------------------------------------------------------------
74  
75    @Override
76    public ClassificationNavigationCommand createClassificationNavigationCommand(
77        final String service,
78        final CommandArgument<ClassificationNavigationCommand> classification)
79    {
80      return new BugzillaClassificationNavigationCommand(service, classification);
81    }
82  
83    @Override
84    public ProductNavigationCommand createProductNavigationCommand(
85        final String service,
86        final CommandArgument<ProductNavigationCommand> product)
87    {
88      return new BugzillaProductNavigationCommand(service, product);
89    }
90  
91    @Override
92    public ProductNavigationCommand createProductNavigationCommand(
93        final String service,
94        final CommandArgument<ProductNavigationCommand> action,
95        final CommandArgument<ProductNavigationCommand> product)
96    {
97      return new BugzillaProductNavigationCommand(service, action, product);
98    }
99  
100   @Override
101   public AddVersionCommand createAddVersionCommand(
102       final CommandArgument<AddVersionCommand> product,
103       final CommandArgument<AddVersionCommand> version,
104       final CommandArgument<AddVersionCommand> token)
105   {
106     return new BugzillaAddVersionCommand(product, version, token);
107   }
108 
109   @Override
110   public AddMilestoneCommand createAddMilestoneCommand(
111       final CommandArgument<AddMilestoneCommand> product,
112       final CommandArgument<AddMilestoneCommand> milestone,
113       final CommandArgument<AddMilestoneCommand> sortkey,
114       final CommandArgument<AddMilestoneCommand> token)
115   {
116     return new BugzillaAddMilestoneCommand(product, milestone, sortkey, token);
117   }
118 
119   /**
120    * Creates the login command.
121    *
122    * @param login the user name.
123    * @param password the passwort to login.
124    * @return the login command instance.
125    */
126   @Override
127   public LoginCommand createLoginCommand(
128       final CommandArgument<LoginCommand> login,
129       final CommandArgument<LoginCommand> password)
130   {
131     return new BugzillaLoginCommand(login, password);
132   }
133 
134   @Override
135   public LogoutCommand createLogoutCommand()
136   {
137     return new BugzillaLogoutCommand();
138   }
139 
140   // CHECKSTYLE:OFF
141   @Override
142   public AddProductCommand createAddProductCommand(
143       // NOPMD
144       final CommandArgument<AddProductCommand> classification,
145       final CommandArgument<AddProductCommand> product,
146       final CommandArgument<AddProductCommand> description,
147       final CommandArgument<AddProductCommand> defaultMilestone,
148       final CommandArgument<AddProductCommand> version,
149       final CommandArgument<AddProductCommand> token)
150   {
151     return new BugzillaAddProductCommand(classification, product, description,
152         defaultMilestone, version, token, null, null, null);
153   }
154 
155   // CHECKSTYLE:ON
156 
157   // CHECKSTYLE:OFF
158   @Override
159   public UpdateProductCommand createUpdateProductCommand(
160       final CommandArgument<UpdateProductCommand> oldProduct,
161       final CommandArgument<UpdateProductCommand> product,
162       final CommandArgument<UpdateProductCommand> description,
163       final CommandArgument<UpdateProductCommand> defaultMilestone,
164       final CommandArgument<UpdateProductCommand> token)
165   {
166     return new BugzillaUpdateProductCommand(oldProduct, product, description,
167         defaultMilestone, token);
168   }
169 
170   // CHECKSTYLE:ON
171   @Override
172   public AddComponentCommand createAddComponentCommand(
173       final CommandArgument<AddComponentCommand> product,
174       final CommandArgument<AddComponentCommand> component,
175       final CommandArgument<AddComponentCommand> description,
176       final CommandArgument<AddComponentCommand> initialOwner,
177       final CommandArgument<AddComponentCommand> token)
178   {
179     return new BugzillaAddComponentCommand(product, component, description,
180         initialOwner, token);
181   }
182 
183   // CHECKSTYLE:OFF
184   @Override
185   public AddProductCommand createAddProductCommand(
186       final CommandArgument<AddProductCommand> classification,
187       final CommandArgument<AddProductCommand> product,
188       final CommandArgument<AddProductCommand> description,
189       final CommandArgument<AddProductCommand> defaultMilestone,
190       final CommandArgument<AddProductCommand> version,
191       final CommandArgument<AddProductCommand> token,
192       final CommandArgument<AddProductCommand> component,
193       final CommandArgument<AddProductCommand> componentDescription,
194       final CommandArgument<AddProductCommand> componentInitialOwner)
195   {
196     return new BugzillaAddProductCommand(classification, product, description,
197         defaultMilestone, version, token, component, componentDescription,
198         componentInitialOwner);
199   }
200   // CHECKSTYLE:ON
201 
202   @Override
203   public boolean requiresComponentOnProductCreation()
204   {
205     if (StringUtils.isNotBlank(issueServerVersion))
206     {
207       final ArtifactVersion version =
208           new DefaultArtifactVersion(issueServerVersion);
209       final boolean requires =
210           (version.getMajorVersion() >= 4 && version.getMinorVersion() >= 4);
211       return requires;
212     }
213     return false;
214   }
215 
216   // --- object basics --------------------------------------------------------
217 
218 }