Skip to main content

Notice: this Wiki will be going read only early in 2024 and edits will no longer be possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.

Jump to: navigation, search

Difference between revisions of "Mylyn/Incubator/Generic Industrial Connector/Configuring Industrial Connector using Nothing"

(Step 5: Give it a Spin)
 
(6 intermediate revisions by the same user not shown)
Line 3: Line 3:
 
==Step 1: Get the Source==
 
==Step 1: Get the Source==
 
Point your favorit SVN client towards
 
Point your favorit SVN client towards
  svn://bugs.industrial-tsi.com/mylyn_gsc/trunk
+
  http://svn.codespot.com/a/eclipselabs.org/industrial-mylyn/trunk/
and get all the projects.
+
and get all the projects. If you want to build the memory connector yourself then close the reference implementation project ''org.eclipse.mylyn.industrial.demo.memory'' to get it out of the way.
  
 
==Step 2: Create a Fragment Project==
 
==Step 2: Create a Fragment Project==
Line 12: Line 12:
 
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:
 
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:
  
 
+
[[Mylyn/Incubator/Generic SQL Connector/Configuring Industrial Connector using Nothing/connector.xml|Here is the source]]
<?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.
 
There is already a reference project called ''org.eclipse.mylyn.industrial.demo.memory'' where you can also view the comments in this file.
Line 35: Line 19:
 
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.
 
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.
  
<br>
+
Now implement the class like [[Mylyn/Incubator/Generic SQL Connector/Configuring Industrial Connector using Nothing/persistorsource|we did in this link.]] (You can also copy the source to the clipboard and paste it in the source folder of your project)
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
+
  * <code>org.eclipse.mylyn.industrial.core.persistence.IPersistor</code>
+
  *
+
  * @author Wim Jongman
+
  * @since 0.8.0
+
  *
+
  */
+
 
+
// The first part just contains some fields we are going to use as our storage medium and the default constructor.
+
+
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() {
+
}
+
 
+
// Defines if this repository can be intitialized. This means that the class defined in the org.eclipse.mylyn.sql.core.database.dbinitializer may be called to do initialization work. Whatever that may be is up to the implementor of that class.
+
+
public boolean canInitialize(TaskRepository repository) throws SQLException, CoreException {
+
return false;
+
}
+
+
 
+
// Fetches additional Mylyn attributes from the repository. Until the Mylyn attribute task.common.user.reporter.name is supported by its own method, it can be supplied by this method. We need this to supply the task reporter name.
+
 
+
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;
+
}
+
 
+
// Return the blob content of the attachment with the given key. The passed id of the attachment is read from the task so this method should not return null.
+
public byte[] fetchAttachmentBlob(TaskRepository repository, String attachmentId) throws SQLException,
+
CoreException {
+
return blobs.get(attachmentId);
+
}
+
+
// Given a repository and a task key, return all attachments belonging to the task with the given key.
+
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>();
+
+
}
+
  
// Given a repository and one or more task keys, return all comments belonging to the task with the given keys.
 
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>();
 
}
 
 
// Fetches a task from the repository
 
public IndustrialTask fetchTask(TaskRepository repository, String... taskId) throws SQLException, CoreException {
 
return tasks.get(taskId[0]);
 
}
 
 
// Search for all tasks obeying the given criteria and return their keys. This just returns all tasks, no effort was made to match each task against the ''criteria''
 
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>();
 
}
 
 
// This list of allowed statusses is also used to populate a Status task attribute and to query the repository.
 
public List<String> getLegalIssueStatus(TaskRepository repository) throws SQLException, CoreException {
 
return Arrays.asList(new String[] { "OPEN", "CLOSED" });
 
}
 
 
// This list of owners is also used to populate the Owner task attribute and to query the repository.
 
public List<String> getLegalOwners(TaskRepository repository) throws SQLException, CoreException {
 
return Arrays.asList(new String[] { System.getProperty("user.name"), "Some othe people" });
 
}
 
 
// This list of priorities is also used to populate a Priority task attribute and to query the repository.
 
public List<String> getLegalPriorities(TaskRepository repository) throws SQLException, CoreException {
 
return Arrays.asList(new String[] { "High", "Medium", "Low" });
 
}
 
 
// This list of products is also used to populate the Product task attribute and to query the repository.
 
public List<String> getLegalProducts(TaskRepository repository) throws SQLException, CoreException {
 
return Arrays.asList(new String[] { "ECLIPSE", ".NET", "NETBEANS" });
 
}
 
 
 
// Initialize this repository configuration.
 
public void initialize(TaskRepository repository) throws SQLException, CoreException {
 
}
 
 
// Persists an attachement
 
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);
 
 
}
 
 
// Persists a comment
 
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);
 
 
}
 
 
// Persists a task
 
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;
 
}
 
 
// Updates a task
 
public void updateTask(TaskRepository repository, IndustrialTask task) throws SQLException, CoreException {
 
tasks.put(task.getTaskId(), task);
 
}
 
 
// Validates the repository
 
public boolean validate(TaskRepository repository) throws SQLException, CoreException {
 
return true;
 
}
 
 
}
 
 
==Step 5: Give it a Spin ==
 
==Step 5: Give it a Spin ==
 
Ready?  
 
Ready?  
* Open the Build tab in the fragement and click on the connector.xml
+
* Open the Build tab in the fragement and make sure to include connector.xml on the binary build
 
* Create a run configuration and connect your fragment project and then "Add required projects". Run and when the workspace comes up,  
 
* Create a run configuration and connect your fragment project and then "Add required projects". Run and when the workspace comes up,  
 
* Open the Mylyn task list and the Mylyn repository views.
 
* Open the Mylyn task list and the Mylyn repository views.

Latest revision as of 16:55, 10 March 2011

This page describes how you can implement a Mylyn connector in 5 minutes using your computers memory as the persistance medium.

Step 1: Get the Source

Point your favorit SVN client towards

http://svn.codespot.com/a/eclipselabs.org/industrial-mylyn/trunk/

and get all the projects. If you want to build the memory connector yourself then close the reference implementation project org.eclipse.mylyn.industrial.demo.memory to get it out of the way.

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:

Here is the source

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 class like we did in this link. (You can also copy the source to the clipboard and paste it in the source folder of your project)

Step 5: Give it a Spin

Ready?

  • Open the Build tab in the fragement and make sure to include connector.xml on the binary build
  • Create a run configuration and connect your fragment project and then "Add required projects". Run and when the workspace comes up,
  • Open the Mylyn task list and the Mylyn repository views.
  • Create a new repository and select "Industrial" --> Next.

P1.png

  • Type "jdbc:memory://helloworld" as the repos, give it a fancy name and select the name you have placed in the connector.xml ("Memory" in our example)

P2.png

  • Press finish
  • Press Yes

P3.png

  • Enter some criteria

P4.png

  • Create tasks.

Back to the top