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 3: Implement IPersistor)
(Step 4: Implement IPersistor)
Line 59: Line 59:
 
  import java.util.Map;
 
  import java.util.Map;
 
  import java.util.Set;  
 
  import java.util.Set;  
 
+
 
  import org.eclipse.core.runtime.CoreException;
 
  import org.eclipse.core.runtime.CoreException;
 
  import org.eclipse.mylyn.industrial.core.dto.IndustrialAttachment;
 
  import org.eclipse.mylyn.industrial.core.dto.IndustrialAttachment;
Line 76: Line 76:
 
   *  
 
   *  
 
   */  
 
   */  
 +
 +
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 {
 
  public class MemoryPersistor implements IPersistor {
Line 89: Line 91:
 
  public MemoryPersistor() {
 
  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 {
 
  public boolean canInitialize(TaskRepository repository) throws SQLException, CoreException {
Line 94: Line 98:
 
  }
 
  }
 
   
 
   
 +
 +
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,
 
  public Map<String, String> fetchAdditional(TaskRepository repository, String... key) throws SQLException,
 
  CoreException {
 
  CoreException {
Line 101: Line 108:
 
  return result;
 
  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,
 
  public byte[] fetchAttachmentBlob(TaskRepository repository, String attachmentId) throws SQLException,
 
  CoreException {
 
  CoreException {
Line 107: Line 115:
 
  }
 
  }
 
   
 
   
 +
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)
 
  public List<IndustrialAttachment> fetchAttachments(TaskRepository repository, String... taskId)
 
  throws SQLException, CoreException {
 
  throws SQLException, CoreException {
Line 114: Line 123:
 
   
 
   
 
  }
 
  }
+
 
 +
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,
 
  public List<IndustrialComment> fetchComments(TaskRepository repository, String... taskId) throws SQLException,
 
  CoreException {
 
  CoreException {
Line 121: Line 131:
 
  }
 
  }
 
   
 
   
 +
Fetches a task from the repository
 
  public IndustrialTask fetchTask(TaskRepository repository, String... taskId) throws SQLException, CoreException {
 
  public IndustrialTask fetchTask(TaskRepository repository, String... taskId) throws SQLException, CoreException {
 
  return tasks.get(taskId[0]);
 
  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,
 
  public List<String> findTasks(TaskRepository repository, IndustrialQueryParams criteria) throws SQLException,
 
  CoreException {
 
  CoreException {
Line 133: Line 145:
 
  }
 
  }
 
   
 
   
 +
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 {
 
  public List<String> getLegalIssueStatus(TaskRepository repository) throws SQLException, CoreException {
 
  return Arrays.asList(new String[] { "OPEN", "CLOSED" });
 
  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 {
 
  public List<String> getLegalOwners(TaskRepository repository) throws SQLException, CoreException {
 
  return Arrays.asList(new String[] { System.getProperty("user.name"), "Some othe people" });
 
  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 {
 
  public List<String> getLegalPriorities(TaskRepository repository) throws SQLException, CoreException {
 
  return Arrays.asList(new String[] { "High", "Medium", "Low" });
 
  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 {
 
  public List<String> getLegalProducts(TaskRepository repository) throws SQLException, CoreException {
 
  return Arrays.asList(new String[] { "ECLIPSE", ".NET", "NETBEANS" });
 
  return Arrays.asList(new String[] { "ECLIPSE", ".NET", "NETBEANS" });
 
  }
 
  }
 
   
 
   
 +
 +
Initialize this repository configuration.
 
  public void initialize(TaskRepository repository) throws SQLException, CoreException {
 
  public void initialize(TaskRepository repository) throws SQLException, CoreException {
 
  }
 
  }
 
   
 
   
 +
Persists an attachement
 
  public void persistAttachment(TaskRepository repository, IndustrialAttachment attachment) throws SQLException,
 
  public void persistAttachment(TaskRepository repository, IndustrialAttachment attachment) throws SQLException,
 
  CoreException {
 
  CoreException {
Line 165: Line 184:
 
  }
 
  }
 
   
 
   
 +
Persists a comment
 
  public void persistComment(TaskRepository repository, IndustrialComment comment) throws SQLException, CoreException {
 
  public void persistComment(TaskRepository repository, IndustrialComment comment) throws SQLException, CoreException {
 
   
 
   
Line 177: Line 197:
 
  }
 
  }
 
   
 
   
 +
Persists a task
 
  public String persistTask(TaskRepository repository, IndustrialTask toPersisTask) throws SQLException,
 
  public String persistTask(TaskRepository repository, IndustrialTask toPersisTask) throws SQLException,
 
  CoreException {
 
  CoreException {
Line 185: Line 206:
 
  }
 
  }
 
   
 
   
 +
Updates a task
 
  public void updateTask(TaskRepository repository, IndustrialTask task) throws SQLException, CoreException {
 
  public void updateTask(TaskRepository repository, IndustrialTask task) throws SQLException, CoreException {
 
  tasks.put(task.getTaskId(), task);
 
  tasks.put(task.getTaskId(), task);
 
  }
 
  }
 
   
 
   
 +
Validates the repository
 
  public boolean validate(TaskRepository repository) throws SQLException, CoreException {
 
  public boolean validate(TaskRepository repository) throws SQLException, CoreException {
 
  return true;
 
  return true;

Revision as of 14:06, 17 February 2009

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

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
 * 
 */ 

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;
	}

}

Back to the top