/src/main/groovy/com/onresolve/jira/groovy/customfield/CustomFieldConfiguration.groovy
Groovy | 203 lines | 128 code | 43 blank | 32 comment | 7 complexity | a61cbc7ac35cd4836c0fd4d7ac539a43 MD5 | raw file
- package com.onresolve.jira.groovy.customfield;
-
-
- import com.atlassian.core.util.ClassLoaderUtils
- import com.atlassian.jira.util.json.JSONObject
- import groovy.util.slurpersupport.GPathResult
-
- public class CustomFieldConfiguration {
-
- // todo: what the fuck are all these things
- private Long id;
-
- /**
- * The inline groovy script
- */
- private String script;
-
- /**
- * The groovy script file - use this OR the script. Use the file by preference
- */
- private String scriptFile;
-
- private String template;
-
- /**
- * The entity to take templates from, eg float, datetime etc
- */
- private String modelTemplate;
-
- /**
- * A custom template if ever implemented, needs inline as well as file impls
- */
- private String customTemplate;
-
- /**
- * The name of the custom field associated with this configuration
- */
- private String name;
-
- /**
- * The field config scheme associated with this configuration
- */
- private String fieldConfigSchemeName;
-
- /**
- * The velocity template which corresponds with this field's model template
- */
- private String viewTemplate;
-
- private Long cfId;
-
- public String getFieldConfigSchemeName() {
- return fieldConfigSchemeName;
- }
-
- public String getViewTemplate() {
- if (modelTemplate) {
- if (viewTemplate) {
- return viewTemplate
- }
-
- if (modelTemplate == "html") {
- viewTemplate = "templates/customfield/view-scriptedfield-html.vm"
- }
- else {
- GPathResult gpath = new XmlSlurper().parse(ClassLoaderUtils.getResourceAsStream("system-customfieldtypes-plugin.xml", getClass()))
- viewTemplate = gpath."customfield-type".find {cft ->
- cft."@key".text() == modelTemplate
- }."resource".find {
- it."@name" == "view"
- }."@location".text()
- }
- return viewTemplate
- }
- return null
- }
-
- public void setFieldConfigSchemeName(String fieldConfigSchemeName) {
- this.fieldConfigSchemeName = fieldConfigSchemeName;
- }
-
- public static String NAME = "name";
- public static String FCS_NAME = "fcsName";
- public static String SCRIPT = "script";
- public static String SCRIPT_FILE = "scriptFile";
- public static String TEMPLATE = "template";
- public static String MODEL_TEMPLATE = "modelTemplate";
- public static String CUSTOM_TEMPLATE = "customTemplate";
-
- public CustomFieldConfiguration() {
-
- }
-
- public CustomFieldConfiguration(String jsonString) {
- JSONObject jsonObject = new JSONObject(jsonString)
- this.setName(jsonObject.get(NAME) as String)
- this.setScript(jsonObject.get(SCRIPT) as String)
- this.setScriptFile(jsonObject.has(SCRIPT_FILE) ? jsonObject.get(SCRIPT_FILE) as String : null)
- this.setTemplate(jsonObject.get(TEMPLATE) as String)
- this.setModelTemplate(jsonObject.get(MODEL_TEMPLATE) as String)
- this.setCustomTemplate(jsonObject.get(CUSTOM_TEMPLATE) as String)
-
- }
-
- public CustomFieldConfiguration(String name, String fieldConfigSchemeName, Long cfId) {
- this.name = name;
- this.fieldConfigSchemeName = fieldConfigSchemeName;
- this.cfId = cfId;
- }
-
- /*
- // todo: unused
- public CustomFieldConfiguration(Long id, String script, String template, String modelTemplate, String customTemplate) {
- this.id = id;
- this.script = script;
- this.template = template;
- this.modelTemplate = modelTemplate;
- this.customTemplate = customTemplate;
- }
- */
-
- @SuppressWarnings("unchecked")
- public JSONObject asJsonString() {
- return new JSONObject([(getId().toString()): asMap()]);
- }
-
- public Map asMap() {
- return [
- (SCRIPT): getScript() ?: JSONObject.NULL,
- (TEMPLATE): getTemplate() ?: JSONObject.NULL,
- (SCRIPT_FILE): getScriptFile() ?: JSONObject.NULL,
- (MODEL_TEMPLATE): getModelTemplate() ?: JSONObject.NULL,
- (CUSTOM_TEMPLATE): getCustomTemplate() ?: JSONObject.NULL,
- (NAME): getName(),
- (FCS_NAME): getFieldConfigSchemeName()
- ];
- }
-
- public Long getId() {
- return id;
- }
-
- public void setId(Long id) {
- this.id = id;
- }
-
- public String getScript() {
- return script;
- }
-
- public void setScript(String script) {
- this.script = script;
- }
-
- public String getScriptFile() {
- return scriptFile;
- }
-
- public void setScriptFile(String scriptFile) {
- this.scriptFile = scriptFile;
- }
-
- public String getTemplate() {
- return template;
- }
-
- public void setTemplate(String template) {
- this.template = template;
- }
-
- public String getModelTemplate() {
- return modelTemplate;
- }
-
- public void setModelTemplate(String modelTemplate) {
- this.modelTemplate = modelTemplate;
- }
-
- public String getCustomTemplate() {
- return customTemplate;
- }
-
- public void setCustomTemplate(String customTemplate) {
- this.customTemplate = customTemplate;
- }
-
- public String getName() {
- return name;
- }
-
- public void setName(String name) {
- this.name = name;
- }
-
- public Long getCfId() {
- return cfId
- }
-
- public void setCfId(Long cfId) {
- this.cfId = cfId
- }
-
- }