Rev 30 | 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 java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import net.brutex.mylyn.sbmconnector.SBMConnectorPlugin;
import net.brutex.mylyn.sbmconnector.core.model.SBMStaticFields;
import net.brutex.sbm.wsclient.TTItem;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.mylyn.tasks.core.AbstractRepositoryConnector;
import org.eclipse.mylyn.tasks.core.IRepositoryQuery;
import org.eclipse.mylyn.tasks.core.ITask;
import org.eclipse.mylyn.tasks.core.TaskRepository;
import org.eclipse.mylyn.tasks.core.data.AbstractTaskDataHandler;
import org.eclipse.mylyn.tasks.core.data.TaskAttribute;
import org.eclipse.mylyn.tasks.core.data.TaskData;
import org.eclipse.mylyn.tasks.core.data.TaskDataCollector;
import org.eclipse.mylyn.tasks.core.data.TaskMapper;
import org.eclipse.mylyn.tasks.core.sync.ISynchronizationSession;
public class SBMRepositoryConnector extends AbstractRepositoryConnector {
private SBMTicketDataHandler datahandler;
private static Map<TaskRepository, SBMClient> clients = new HashMap<TaskRepository, SBMClient>();
public SBMRepositoryConnector() {
this.datahandler = new SBMTicketDataHandler(this);
}
public static synchronized SBMClient getClient(TaskRepository repository) {
SBMClient client = clients.get(repository);
if (client == null) {
client = new SBMClient(repository);
clients.put(repository, client);
}
return client;
}
@Override
public boolean canCreateNewTask(TaskRepository repository) {
return false;
}
@Override
public boolean canCreateTaskFromKey(TaskRepository repository) {
return false;
}
@Override
public boolean canSynchronizeTask(TaskRepository taskRepository, ITask task) {
return true;
}
@Override
public String getConnectorKind() {
return SBMConnectorPlugin.CONNECTOR_KIND;
}
@Override
public String getLabel() {
return SBMConnectorPlugin.LABEL;
}
@Override
public String getRepositoryUrlFromTaskUrl(String taskFullUrl) {
// TODO Auto-generated method stub
return null;
}
@Override
public TaskData getTaskData(TaskRepository taskRepository, String taskId,
IProgressMonitor monitor) throws CoreException {
monitor.beginTask("Loading SBM Ticket", IProgressMonitor.UNKNOWN);
TaskData data = null;
try {
SBMClient client = getClient(taskRepository);
TTItem item = client.getTTItem(taskId);
data = datahandler.convert(taskRepository, item, monitor);
} finally {
monitor.done();
}
return data;
}
@Override
public String getTaskIdFromTaskUrl(String taskFullUrl) {
// TODO Auto-generated method stub
return null;
}
@Override
public String getTaskUrl(String repositoryUrl, String taskId) {
// TODO Auto-generated method stub
return null;
}
@Override
public boolean hasTaskChanged(TaskRepository taskRepository, ITask task,
TaskData taskData) {
TaskAttribute attribute = taskData.getRoot().getAttribute(
SBMStaticFields.LASTMODIFIEDDATE.getValue());
if (attribute != null) {
Date dataModificationDate = taskData.getAttributeMapper()
.getDateValue(attribute);
if (dataModificationDate != null) {
Date taskModificationDate = task.getModificationDate();
if (taskModificationDate != null) {
return !taskModificationDate.equals(dataModificationDate);
}
}
}
return true;
}
@Override
public IStatus performQuery(TaskRepository repository,
IRepositoryQuery query, TaskDataCollector collector,
ISynchronizationSession session, IProgressMonitor monitor) {
try {
monitor.beginTask("Lade Daten", IProgressMonitor.UNKNOWN);
SBMClient client = new SBMClient(repository);
List<TTItem> list = client.getTTItemsByTable(query
.getAttribute("table"), query.getAttribute("sql_where"));
for (TTItem ttitem : list) {
TaskData data = datahandler
.convert(repository, ttitem, monitor);
collector.accept(data);
}
} catch (CoreException e) {
return new Status(IStatus.ERROR, SBMConnectorPlugin.PLUGIN_ID,
"Query fehlgeschlagen.", e);
} finally {
monitor.done();
}
return Status.OK_STATUS;
}
@Override
public void updateRepositoryConfiguration(TaskRepository taskRepository,
IProgressMonitor monitor) throws CoreException {
// TODO Auto-generated method stub
}
@Override
public void updateTaskFromTaskData(TaskRepository taskRepository,
ITask task, TaskData taskData) {
getTaskMapping(taskData).applyTo(task);
}
@Override
public TaskMapper getTaskMapping(TaskData taskData) {
return new TaskMapper(taskData);
}
@Override
public AbstractTaskDataHandler getTaskDataHandler() {
return datahandler;
}
@Override
public boolean canDeleteTask(TaskRepository repository, ITask task) {
return false;
}
@Override
public boolean hasRepositoryDueDate(TaskRepository taskRepository,
ITask task, TaskData taskData) {
// TODO Auto-generated method stub
return false;
}
}