Subversion Repositories XServices

Rev

Rev 30 | 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 org.eclipse.mylyn.tasks.core.TaskRepository;
import org.eclipse.mylyn.tasks.core.data.TaskAttribute;
import org.eclipse.mylyn.tasks.core.data.TaskAttributeMapper;

public class SBMTicketAttributeMapper extends TaskAttributeMapper {

        public SBMTicketAttributeMapper(TaskRepository taskRepository) {
                super(taskRepository);
        }
        
        @Override
        public String mapToRepositoryKey(TaskAttribute parent, String key) {
                SBMTicketAttribute attribute = SBMTicketAttribute.getSBMAttributeByTaskName(key);
                if(attribute != null) {
                        return attribute.getSBMName();
                }
                return super.mapToRepositoryKey(parent, key); //just returns key
        }
        
        @Override
        public TaskAttribute getAssoctiatedAttribute(TaskAttribute taskAttribute) {
                return super.getAssoctiatedAttribute(taskAttribute);
        }
        
        /**
         * Map SBM field type to task field type. This mapping is a hint only because
         * SBM allows fields to have a type and subtype, but the subtype is not returned
         * by the SBM web service.
         *
         * @param sbmtype the SBM field type (unfortunately without field subtype)
         * @return the mylyn task field type
         */
        public String mapToTaskKey(SBMFieldTypes sbmtype) {
                String tasktype = TaskAttribute.TYPE_SHORT_TEXT;
                switch(sbmtype) {
                        case NUMERIC: tasktype = TaskAttribute.TYPE_LONG; break;
                        case TEXT: tasktype = TaskAttribute.TYPE_LONG_TEXT; break;
                        case DATETIME: tasktype = TaskAttribute.TYPE_DATETIME; break;
                        case SELECTION: tasktype = TaskAttribute.TYPE_SINGLE_SELECT; break;
                        case BINARY: tasktype = TaskAttribute.TYPE_BOOLEAN; break;
                        case STATE: tasktype = TaskAttribute.TYPE_SINGLE_SELECT; break;
                        case USER: tasktype = TaskAttribute.TYPE_PERSON; break;
                        case PROJECT: tasktype = TaskAttribute.TYPE_SINGLE_SELECT; break;
                        case SUMMATION: tasktype = TaskAttribute.TYPE_INTEGER; break;
                        case MULTIPLE_SELECTION: tasktype = TaskAttribute.TYPE_MULTI_SELECT; break;
                        case CONTACT: tasktype = TaskAttribute.TYPE_PERSON; break;
                        case INCIDENT: tasktype = TaskAttribute.TYPE_TASK_DEPENDENCY; break;
                        case FOLDER: tasktype = TaskAttribute.TYPE_SINGLE_SELECT; break;
                        case RELATIONAL: tasktype = TaskAttribute.TYPE_SINGLE_SELECT; break;
                        case SUBRELATIONAL: tasktype = TaskAttribute.TYPE_SHORT_TEXT; break;
                        case SYSTEM: tasktype = TaskAttribute.TYPE_SHORT_TEXT; break;
                        case MULTIPLE_RELATIONAL: tasktype = TaskAttribute.TYPE_MULTI_SELECT; break;
                        case MULTIPLE_GROUP: tasktype = TaskAttribute.TYPE_MULTI_SELECT; break;
                        case MULTIPLE_USERGROUP: tasktype = TaskAttribute.TYPE_MULTI_SELECT; break;
                }
                return tasktype;
        }
}