Subversion Repositories XServices

Rev

Rev 39 | Go to most recent revision | View as "text/plain" | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

/*
 *   Mylyn Connector for Serena Business Mashups
 *       Copyright 2010 Brian Rosenberger (Brutex Network)
 *
 *   Licensed under the Apache License, Version 2.0 (the "License");
 *   you may not use this file except in compliance with the License.
 *   You may obtain a copy of the License at
 *
 *       http://www.apache.org/licenses/LICENSE-2.0
 *
 *   Unless required by applicable law or agreed to in writing, software
 *   distributed under the License is distributed on an "AS IS" BASIS,
 *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *   See the License for the specific language governing permissions and
 *   limitations under the License.
 * 
 *   Serena, TeamTrack and Serena Business Mashup are 
 *       registered trademarks of SERENA Software Inc.
 */
package net.brutex.mylyn.sbmconnector.core;

import net.brutex.mylyn.sbmconnector.core.model.SBMFieldTypes;
import net.brutex.mylyn.sbmconnector.core.model.SBMStaticFields;

import org.eclipse.mylyn.tasks.core.data.TaskAttribute;


/**
 * Map the Mylyn TaskAttributes to SBMTicket Attributes and vice versa.
 * @author Brian Rosenberger
 *
 */
public enum SBMTicketAttribute {
        DESCRIPTION(
                        "DESCRIPTION", 
                        "label_description",
                        SBMFieldTypes.TEXT,
                        TaskAttribute.DESCRIPTION, 
                        TaskAttribute.TYPE_LONG_RICH_TEXT,
                        false), //hidden because has extra part
        ID(
                        SBMStaticFields.ID.getValue(),
                        "ts_id",
                        SBMFieldTypes.SYSTEM,
                        TaskAttribute.TASK_KEY, 
                        TaskAttribute.TYPE_SHORT_TEXT,
                        false),
        UUID(
                        SBMStaticFields.UUID.getValue(),
                        "ts_uuid",
                        SBMFieldTypes.SYSTEM,
                        TaskAttribute.KIND_DEFAULT, 
                        TaskAttribute.TYPE_SHORT_TEXT,
                        false),
        PROJECT(
                        SBMStaticFields.PROJECTID.getValue(),
                        "label_project",
                        SBMFieldTypes.SYSTEM,
                        TaskAttribute.PRODUCT, 
                        TaskAttribute.TYPE_SHORT_TEXT),
        STATE(
                        SBMStaticFields.STATE.getValue(),
                        "label_state",
                        SBMFieldTypes.SYSTEM,
                        TaskAttribute.STATUS, 
                        TaskAttribute.TYPE_SHORT_TEXT,
                        false), //hidden because has extra part
        SUBMITTER(
                        SBMStaticFields.SUBMITTER.getValue(),
                        "label_submitter",
                        SBMFieldTypes.USER,
                        TaskAttribute.USER_REPORTER, 
                        TaskAttribute.TYPE_PERSON,
                        false), //hidden because has extra part 
        SUBMITDATE(
                        SBMStaticFields.SUBMITDATE.getValue(),
                        "label_submitdate",
                        SBMFieldTypes.DATETIME,
                        TaskAttribute.DATE_CREATION, 
                        TaskAttribute.TYPE_DATETIME),
        LASTMODIFIER(
                        SBMStaticFields.LASTMODIFIER.getValue(),
                        "label_last modifier",
                        SBMFieldTypes.USER,
                        TaskAttribute.PERSON_NAME, 
                        TaskAttribute.TYPE_PERSON),
        LASTMODIFIEDDATE(
                        SBMStaticFields.LASTMODIFIEDDATE.getValue(),
                        "label_modifieddate",
                        SBMFieldTypes.DATETIME,
                        TaskAttribute.DATE_MODIFICATION, 
                        TaskAttribute.TYPE_DATETIME,
                        false), //hidden because has extra part
        CLOSEDATE(
                        SBMStaticFields.CLOSEDATE.getValue(),
                        "label_closedate",
                        SBMFieldTypes.DATETIME,
                        TaskAttribute.DATE_DUE, 
                        TaskAttribute.TYPE_DATETIME),
        ITEMURL(
                        SBMStaticFields.ITEMURL.getValue(),
                        "Item Link:",
                        SBMFieldTypes.SYSTEM,
                        TaskAttribute.TASK_URL, 
                        TaskAttribute.TYPE_URL,
                        false),
        TITLE(
                        "TITLE",
                        "label_title",
                        SBMFieldTypes.TEXT,
                        TaskAttribute.SUMMARY,
                        TaskAttribute.TYPE_SHORT_TEXT,
                        false), //hidden because has extra part
        ACTIVEINACTIVE(
                        SBMStaticFields.ACTIVEINACTIVE.getValue(),
                        "label_activeinactive",
                        SBMFieldTypes.BINARY,
                        null,
                        TaskAttribute.TYPE_BOOLEAN),
        ISSUETYPE(
                        "ISSUETYPE",
                        "label_itemtype",
                        SBMFieldTypes.SELECTION,
                        TaskAttribute.TASK_KIND,
                        TaskAttribute.TYPE_SHORT_TEXT); 
        
        private String sbm_name;
        private String task_name;
        private String sbm_type;
        private String sbm_label;
        private String task_type;
        private boolean visible;
        
        public static final boolean VISIBLE = true;
        public static final boolean HIDDEN = false;
        
        private SBMTicketAttribute(String sbm_name, String sbm_label, SBMFieldTypes sbm_type, String task_name, String task_type) {
                this(sbm_name,sbm_label,sbm_type,task_name,task_type, SBMTicketAttribute.VISIBLE);
        }
        
        private SBMTicketAttribute(String sbm_name, String sbm_label, SBMFieldTypes sbm_type,
                        String task_name, String task_type, boolean visible) {
                this.sbm_name = sbm_name;
                this.sbm_label = sbm_label;
                this.sbm_type = sbm_type.getValue();
                this.task_name = task_name;
                this.task_type = task_type;
                this.visible = visible;
        }
        
        public String getSBMName() {
                return this.sbm_name;
        }
        public String getSBMLabel() {
                return this.sbm_label;
        }
        public String getTaskName() {
                return this.task_name;
        }
        public String getTaskType() {
                return this.task_type;
        }
        public String getSBMType() {
                return this.sbm_type;
        }
        
        public boolean isVisible() {
                return this.visible;
        }
        
        public static SBMTicketAttribute getSBMAttributeBySBMName(String sbm_fieldname) {
                for (SBMTicketAttribute attribute : values()) {
                        if (sbm_fieldname.equals(attribute.getSBMName())) {
                                return attribute;
                        }
                }
                return null;
        }
        
        public static SBMTicketAttribute getSBMAttributeByTaskName(String task_fieldname) {
                for (SBMTicketAttribute attribute : values()) {
                        if (task_fieldname.equals(attribute.getTaskName())) {
                                return attribute;
                        }
                }
                return null;
        }
        
        public static boolean hasSBMField(String fieldname) {
                for (SBMTicketAttribute attribute : values()) {
                        if (attribute.getSBMName().equals(fieldname)) {
                                return true;
                        }
                }
                return false;
        }
}