1 package com.atlassian.plugins.codegen.modules.stash.hook;
2
3 import com.atlassian.plugins.codegen.modules.BasicClassModuleProperties;
4 import com.google.common.collect.Lists;
5
6 import java.util.List;
7
8 public class RepositoryHookProperties extends BasicClassModuleProperties
9 {
10 private static final String ICON = "ICON";
11 private static final String FIELDS = "FIELDS";
12 private static final String SOY_PACKAGE = "SOY_PACKAGE";
13
14 private final String type;
15 private String icon;
16
17 public RepositoryHookProperties(String fqRequestClassName, String type)
18 {
19 super(fqRequestClassName);
20 this.type = type;
21 setConfigured(true);
22 setIcon(true);
23 }
24
25 public String getType()
26 {
27 return type;
28 }
29
30 public String getIcon()
31 {
32 return icon;
33 }
34
35 public void setIcon(boolean icon)
36 {
37 if (icon)
38 {
39 put(ICON, "icon-example.png");
40 }
41 else
42 {
43 remove(ICON);
44 }
45 }
46
47 public boolean ifConfigured()
48 {
49 return get(FIELDS) != null;
50 }
51
52 public void addField(String fieldName)
53 {
54 List<String> fields = (List<String>) get(FIELDS);
55 if (fields == null)
56 {
57 put(FIELDS, fields = Lists.newArrayList());
58 }
59 fields.add(fieldName);
60 }
61
62 public void setConfigured(boolean configured)
63 {
64 if (configured)
65 {
66 if (type.equals(RepositoryHookModuleCreator.TYPE_POST))
67 {
68 addField("url");
69 }
70 else if (type.equals(RepositoryHookModuleCreator.TYPE_MERGE_CHECK))
71 {
72 addField("reviewers");
73 }
74 }
75 else
76 {
77 remove(FIELDS);
78 }
79 }
80
81 @Override
82 public void setFullyQualifiedClassname(String fqName) {
83 super.setFullyQualifiedClassname(fqName);
84 put(SOY_PACKAGE, getClassId().getPackage() + "." + getClassId().getName().toLowerCase());
85 }
86
87 public String getSoyFile() {
88 return getProperty(MODULE_KEY) + ".soy";
89 }
90 }