Notice: This Wiki is now read only and edits are no longer possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.
Mylyn/Incubator/Generic Industrial Connector/Configuring Industrial Connector using Nothing
This page describes how you can implement a Mylyn connector in 5 minutes using your computers memory as the persistance medium.
Contents
Step 1: Get the Source
Point your favorit SVN client towards
svn://bugs.industrial-tsi.com/mylyn_gsc/trunk
and get all the projects.
Step 2: Create a Fragment Project
Create a fragment project for your connector with the org.eclipse.mylyn.industrial.core project as the host.
Step 3: Create a connector.xml
This is going to be moved to the extension point mechanism in a very near future version. For now, create a connector.xml file in the root of your project with the following contents:
<?xml version="1.0" encoding="UTF-8"?> <connector xmlns="ptth://www.industrial-tsi.com/mylyn/connector/connector_1_0.dtd"> <repository name="Memory"> <persistor name="Memory"> <class>org.eclipse.mylyn.industrial.demo.memory.MemoryPersistor</class> </persistor> <repository-properties> <property name="can-create-new-task" value="true" /> <property name="can-create-task-from-key" value="true" /> <property name="can-query-repository" value="true" /> <property name="can-synchronize-tasks" value="true" /> <property name="can-get-attachments" value="true" /> <property name="can-post-attachments" value="true" /> </repository-properties> </repository> </connector>
There is already a reference project called org.eclipse.mylyn.industrial.demo.memory where you can also view the comments in this file.
Step 4: Implement IPersistor
Make an extension to org.eclipse.mylyn.industrial.core.persistor and open the class that you have typed in there. Make sure the name of this class appears in the config.xml described in step 3.
Now implement the following class:
/******************************************************************************* * Copyright (c) 2008 Industrial TSI and Maarten Meijer. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors: * Industrial TSI - initial API and implementation *******************************************************************************/ package org.eclipse.mylyn.industrial.demo.memory; import java.sql.SQLException; import java.util.ArrayList; import java.util.Arrays; import java.util.Calendar; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Set;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.mylyn.industrial.core.dto.IndustrialAttachment;
import org.eclipse.mylyn.industrial.core.dto.IndustrialComment;
import org.eclipse.mylyn.industrial.core.dto.IndustrialQueryParams;
import org.eclipse.mylyn.industrial.core.dto.IndustrialTask;
import org.eclipse.mylyn.industrial.core.persistence.IPersistor;
import org.eclipse.mylyn.tasks.core.TaskRepository;
/**
* On-The-Fly (Memory) implementation of the interface
* org.eclipse.mylyn.industrial.core.persistence.IPersistor
*
* @author Wim Jongman
* @since 0.8.0
*
*/
public class MemoryPersistor implements IPersistor {
private HashMap<String, IndustrialTask> tasks = new HashMap<String, IndustrialTask>();
private HashMap<String, ArrayList<IndustrialComment>> comments = new HashMap<String, ArrayList<IndustrialComment>>();
private Map<String, byte[]> blobs = new HashMap<String, byte[]>();
private Map<String, List<IndustrialAttachment>> attachements = new HashMap<String, List<IndustrialAttachment>>();
public MemoryPersistor() {
}
public boolean canInitialize(TaskRepository repository) throws SQLException, CoreException {
return false;
}
public Map<String, String> fetchAdditional(TaskRepository repository, String... key) throws SQLException,
CoreException {
Map<String, String> result = new HashMap<String, String>();
result.put("task.common.user.reporter.name", System.getProperty("user.name"));
return result;
}
public byte[] fetchAttachmentBlob(TaskRepository repository, String attachmentId) throws SQLException,
CoreException {
return blobs.get(attachmentId);
}
public List<IndustrialAttachment> fetchAttachments(TaskRepository repository, String... taskId)
throws SQLException, CoreException {
List<IndustrialAttachment> as = attachements.get(taskId[0]);
return (as != null) ? as : new ArrayList<IndustrialAttachment>();
}
public List<IndustrialComment> fetchComments(TaskRepository repository, String... taskId) throws SQLException,
CoreException {
List<IndustrialComment> cs = comments.get(taskId[0]);
return (cs != null) ? cs : new ArrayList<IndustrialComment>();
}
public IndustrialTask fetchTask(TaskRepository repository, String... taskId) throws SQLException, CoreException {
return tasks.get(taskId[0]);
}
public List<String> findTasks(TaskRepository repository, IndustrialQueryParams criteria) throws SQLException,
CoreException {
Set<String> keys = tasks.keySet();
if (keys != null)
return new ArrayList<String>(keys);
return new ArrayList<String>();
}
public List<String> getLegalIssueStatus(TaskRepository repository) throws SQLException, CoreException {
return Arrays.asList(new String[] { "OPEN", "CLOSED" });
}
public List<String> getLegalOwners(TaskRepository repository) throws SQLException, CoreException {
return Arrays.asList(new String[] { System.getProperty("user.name"), "Some othe people" });
}
public List<String> getLegalPriorities(TaskRepository repository) throws SQLException, CoreException {
return Arrays.asList(new String[] { "High", "Medium", "Low" });
}
public List<String> getLegalProducts(TaskRepository repository) throws SQLException, CoreException {
return Arrays.asList(new String[] { "ECLIPSE", ".NET", "NETBEANS" });
}
public void initialize(TaskRepository repository) throws SQLException, CoreException {
}
public void persistAttachment(TaskRepository repository, IndustrialAttachment attachment) throws SQLException,
CoreException {
List<IndustrialAttachment> list = attachements.get(attachment.getTaskId());
if (list == null) {
list = new ArrayList<IndustrialAttachment>();
}
list.add(attachment);
attachment.setId("" + (list.size() + 1));
attachements.put(attachment.getTaskId(), list);
}
public void persistComment(TaskRepository repository, IndustrialComment comment) throws SQLException, CoreException {
comment.setGroupKey(Calendar.getInstance().getTime().toString());
ArrayList<IndustrialComment> list = comments.get(comment.getTaskId());
if (list == null) {
list = new ArrayList<IndustrialComment>();
}
list.add(comment);
comments.put(comment.getTaskId(), list);
}
public String persistTask(TaskRepository repository, IndustrialTask toPersisTask) throws SQLException,
CoreException {
String id = "MemomryTask" + (tasks.size() + 1);
toPersisTask.setTaskId(id);
tasks.put(id, toPersisTask);
return id;
}
public void updateTask(TaskRepository repository, IndustrialTask task) throws SQLException, CoreException {
tasks.put(task.getTaskId(), task);
}
public boolean validate(TaskRepository repository) throws SQLException, CoreException {
return true;
}
}