diff options
author | relves | 2008-12-12 21:42:16 +0000 |
---|---|---|
committer | relves | 2008-12-12 21:42:16 +0000 |
commit | 1faecfd359e3702fea8882570e99d2f3750f1b05 (patch) | |
tree | fa0a0a874360ca9edb60cd4294eac4f863bb3ed3 /org.eclipse.mylyn.bugzilla.core | |
parent | 89cf9802ccca470a31dc5224f697e743e1fc4cf6 (diff) | |
download | org.eclipse.mylyn.tasks-1faecfd359e3702fea8882570e99d2f3750f1b05.tar.gz org.eclipse.mylyn.tasks-1faecfd359e3702fea8882570e99d2f3750f1b05.tar.xz org.eclipse.mylyn.tasks-1faecfd359e3702fea8882570e99d2f3750f1b05.zip |
ASSIGNED - bug 186265: [patch] Add support for Bugzilla flags
https://bugs.eclipse.org/bugs/show_bug.cgi?id=186265
Diffstat (limited to 'org.eclipse.mylyn.bugzilla.core')
10 files changed, 504 insertions, 67 deletions
diff --git a/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/BugzillaAttribute.java b/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/BugzillaAttribute.java index b83e4afa9..21bd31475 100644 --- a/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/BugzillaAttribute.java +++ b/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/BugzillaAttribute.java @@ -82,6 +82,8 @@ public enum BugzillaAttribute { FILENAME("filename", "filename", TaskAttribute.TYPE_SHORT_TEXT, false, false), + FLAG("Flag:", "flag", null, false, false), + GROUP("Group", "group", TaskAttribute.TYPE_BOOLEAN, true, true), IS_OBSOLETE("Obsolete", "isobsolete", TaskAttribute.TYPE_BOOLEAN, true, false), diff --git a/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/BugzillaClient.java b/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/BugzillaClient.java index 72d916ee8..ef24bb176 100644 --- a/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/BugzillaClient.java +++ b/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/BugzillaClient.java @@ -50,7 +50,6 @@ import org.apache.commons.httpclient.methods.multipart.FilePart; import org.apache.commons.httpclient.methods.multipart.MultipartRequestEntity; import org.apache.commons.httpclient.methods.multipart.Part; import org.apache.commons.httpclient.methods.multipart.PartBase; -import org.apache.commons.httpclient.methods.multipart.PartSource; import org.apache.commons.httpclient.methods.multipart.StringPart; import org.apache.commons.httpclient.params.HttpMethodParams; import org.eclipse.core.net.proxy.IProxyData; @@ -74,6 +73,9 @@ import org.eclipse.mylyn.tasks.core.IRepositoryQuery; import org.eclipse.mylyn.tasks.core.RepositoryResponse; import org.eclipse.mylyn.tasks.core.RepositoryStatus; import org.eclipse.mylyn.tasks.core.RepositoryResponse.ResponseKind; +import org.eclipse.mylyn.tasks.core.data.AbstractTaskAttachmentSource; +import org.eclipse.mylyn.tasks.core.data.TaskAttachmentMapper; +import org.eclipse.mylyn.tasks.core.data.TaskAttachmentPartSource; import org.eclipse.mylyn.tasks.core.data.TaskAttribute; import org.eclipse.mylyn.tasks.core.data.TaskAttributeMapper; import org.eclipse.mylyn.tasks.core.data.TaskData; @@ -616,13 +618,41 @@ public class BugzillaClient { } } - public void postAttachment(String bugReportID, String comment, String description, String contentType, - boolean isPatch, PartSource source, IProgressMonitor monitor) throws HttpException, IOException, + public void postAttachment(String bugReportID, String comment, AbstractTaskAttachmentSource source, + TaskAttribute attachmentAttribute, IProgressMonitor monitor) throws HttpException, IOException, CoreException { monitor = Policy.monitorFor(monitor); + String description = source.getDescription(); + String contentType = source.getContentType(); + String filename = source.getName(); + boolean isPatch = false; + + if (attachmentAttribute != null) { + TaskAttachmentMapper mapper = TaskAttachmentMapper.createFrom(attachmentAttribute); + + if (mapper.getDescription() != null) { + description = mapper.getDescription(); + } + + if (mapper.getContentType() != null) { + contentType = mapper.getContentType(); + } + + if (mapper.getFileName() != null) { + filename = mapper.getFileName(); + } + + if (mapper.isPatch() != null) { + isPatch = mapper.isPatch(); + } + } Assert.isNotNull(bugReportID); Assert.isNotNull(source); Assert.isNotNull(contentType); + if (description == null) { + throw new CoreException(new Status(IStatus.WARNING, BugzillaCorePlugin.ID_PLUGIN, + "A description is required when submitting attachments.")); + } hostConfiguration = WebUtil.createHostConfiguration(httpClient, location, monitor); if (!authenticated && hasAuthenticationCredentials()) { @@ -651,7 +681,7 @@ public class BugzillaClient { if (comment != null) { parts.add(new StringPart(IBugzillaConstants.POST_INPUT_COMMENT, comment, characterEncoding)); } - parts.add(new FilePart(IBugzillaConstants.POST_INPUT_DATA, source)); + parts.add(new FilePart(IBugzillaConstants.POST_INPUT_DATA, new TaskAttachmentPartSource(source, filename))); if (isPatch) { parts.add(new StringPart(ATTRIBUTE_ISPATCH, VALUE_ISPATCH)); @@ -659,7 +689,55 @@ public class BugzillaClient { parts.add(new StringPart(ATTRIBUTE_CONTENTTYPEMETHOD, VALUE_CONTENTTYPEMETHOD_MANUAL)); parts.add(new StringPart(ATTRIBUTE_CONTENTTYPEENTRY, contentType)); } - + if (attachmentAttribute != null) { + Collection<TaskAttribute> attributes = attachmentAttribute.getAttributes().values(); + Iterator<TaskAttribute> itr = attributes.iterator(); + while (itr.hasNext()) { + TaskAttribute a = itr.next(); + if (a.getId().startsWith("task.common.kind.flag_type")) { + List<BugzillaFlag> flags = repositoryConfiguration.getFlags(); + TaskAttribute requestee = a.getAttribute("requestee"); + a = a.getAttribute("state"); + String value = a.getValue(); + String id = ""; + if (value.equals(" ")) { + continue; + } + String flagname = a.getMetaData().getLabel(); + BugzillaFlag theFlag = null; + for (BugzillaFlag bugzillaFlag : flags) { + if (flagname.equals(bugzillaFlag.getName())) { + theFlag = bugzillaFlag; + break; + } + } + if (theFlag != null) { + int flagTypeNumber = theFlag.getFlagId(); + id = "flag_type-" + flagTypeNumber; + value = a.getValue(); + if (value.equals("?") && requestee != null) { + parts.add(new StringPart("requestee_type-" + flagTypeNumber, + requestee.getValue() != null ? requestee.getValue() : "")); + } + } + parts.add(new StringPart(id, value != null ? value : "")); + } else if (a.getId().startsWith("task.common.kind.flag")) { + TaskAttribute flagnumber = a.getAttribute("number"); + TaskAttribute requestee = a.getAttribute("requestee"); + a = a.getAttribute("state"); + String id = "flag-" + flagnumber.getValue(); + String value = a.getValue(); + if (value.equals(" ")) { + value = "X"; + } + if (value.equals("?") && requestee != null) { + parts.add(new StringPart("requestee-" + flagnumber.getValue(), + requestee.getValue() != null ? requestee.getValue() : "")); + } + parts.add(new StringPart(id, value != null ? value : "")); + } + } + } postMethod.setRequestEntity(new MultipartRequestEntity(parts.toArray(new Part[1]), postMethod.getParams())); postMethod.setDoAuthentication(true); int status = WebUtil.execute(httpClient, hostConfiguration, postMethod, monitor); @@ -975,11 +1053,51 @@ public class BugzillaClient { fields.put(a.getId() + i++, new NameValuePair(a.getId(), string != null ? string : "")); } } else if (a.getId() != null && a.getId().compareTo("") != 0) { + String id = a.getId(); String value = a.getValue(); if (a.getId().equals(BugzillaAttribute.DELTA_TS.getKey())) { value = stripTimeZone(value); } - fields.put(a.getId(), new NameValuePair(a.getId(), value != null ? value : "")); + if (a.getId().startsWith("task.common.kind.flag_type")) { + List<BugzillaFlag> flags = repositoryConfiguration.getFlags(); + TaskAttribute requestee = a.getAttribute("requestee"); + a = a.getAttribute("state"); + value = a.getValue(); + if (value.equals(" ")) { + continue; + } + String flagname = a.getMetaData().getLabel(); + BugzillaFlag theFlag = null; + for (BugzillaFlag bugzillaFlag : flags) { + if (flagname.equals(bugzillaFlag.getName())) { + theFlag = bugzillaFlag; + break; + } + } + if (theFlag != null) { + int flagTypeNumber = theFlag.getFlagId(); + id = "flag_type-" + flagTypeNumber; + value = a.getValue(); + if (value.equals("?") && requestee != null) { + fields.put("requestee_type-" + flagTypeNumber, new NameValuePair("requestee_type-" + + flagTypeNumber, requestee.getValue() != null ? requestee.getValue() : "")); + } + } + } else if (a.getId().startsWith("task.common.kind.flag")) { + TaskAttribute flagnumber = a.getAttribute("number"); + TaskAttribute requestee = a.getAttribute("requestee"); + a = a.getAttribute("state"); + id = "flag-" + flagnumber.getValue(); + value = a.getValue(); + if (value.equals(" ")) { + value = "X"; + } + if (value.equals("?") && requestee != null) { + fields.put("requestee-" + flagnumber.getValue(), new NameValuePair("requestee-" + + flagnumber.getValue(), requestee.getValue() != null ? requestee.getValue() : "")); + } + } + fields.put(id, new NameValuePair(id, value != null ? value : "")); } } diff --git a/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/BugzillaFlag.java b/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/BugzillaFlag.java index 84cb2bbe6..a28160c0b 100644 --- a/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/BugzillaFlag.java +++ b/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/BugzillaFlag.java @@ -12,13 +12,18 @@ package org.eclipse.mylyn.internal.bugzilla.core; import java.io.Serializable; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; /** * @author Frank Becker */ public class BugzillaFlag implements Serializable { - private static final long serialVersionUID = 4920551884607344418L; +// old private static final long serialVersionUID = 4920551884607344418L; + private static final long serialVersionUID = -3149026741475639885L; private final String name; @@ -26,28 +31,39 @@ public class BugzillaFlag implements Serializable { private final String type; - private boolean requestable; + private final boolean requestable; - private boolean specifically_requestable; + private final boolean specifically_requestable; - private boolean multiplicable; + private final boolean multiplicable; + + private final int flagId; + + private final Map<String, List<String>> used = new HashMap<String, List<String>>(); public BugzillaFlag(String name, String description, String type, String requestable, - String specifically_requestable, String multiplicable) { + String specifically_requestable, String multiplicable, int flagId) { this.description = description; this.name = name; this.type = type; + this.flagId = flagId; if (multiplicable != null && !multiplicable.equals("")) { this.multiplicable = multiplicable.equals("1"); + } else { + this.multiplicable = false; } if (requestable != null && !requestable.equals("")) { this.requestable = requestable.equals("1"); + } else { + this.requestable = false; } if (specifically_requestable != null && !specifically_requestable.equals("")) { this.specifically_requestable = specifically_requestable.equals("1"); + } else { + this.specifically_requestable = false; } } @@ -74,4 +90,27 @@ public class BugzillaFlag implements Serializable { public boolean isMultiplicable() { return multiplicable; } + + public int getFlagId() { + return flagId; + } + + public void addUsed(String product, String component) { + List<String> componentList = used.get(product); + if (componentList == null) { + componentList = new ArrayList<String>(); + used.put(product, componentList); + } + if (!componentList.contains(component)) { + componentList.add(component); + } + } + + public boolean isUsedIn(String product, String component) { + List<String> componentList = used.get(product); + if (componentList != null && componentList.contains(component)) { + return true; + } + return false; + } } diff --git a/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/BugzillaFlagMapper.java b/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/BugzillaFlagMapper.java new file mode 100644 index 000000000..054ae3ec5 --- /dev/null +++ b/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/BugzillaFlagMapper.java @@ -0,0 +1,115 @@ +/******************************************************************************* + * Copyright (c) 2004, 2008 Tasktop Technologies and others. + * 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: + * Tasktop Technologies - initial API and implementation + *******************************************************************************/ + +package org.eclipse.mylyn.internal.bugzilla.core; + +import org.eclipse.core.runtime.Assert; +import org.eclipse.mylyn.tasks.core.data.TaskAttribute; +import org.eclipse.mylyn.tasks.core.data.TaskAttributeMapper; +import org.eclipse.mylyn.tasks.core.data.TaskAttributeMetaData; +import org.eclipse.mylyn.tasks.core.data.TaskData; + +/** + * @author Frank Becker + * @since 3.1 + */ +public class BugzillaFlagMapper { + + private String requestee; + + private String setter; + + private String state; + + private String flagId; + + private int number; + + public String getRequestee() { + return requestee; + } + + public void setRequestee(String requestee) { + this.requestee = requestee; + } + + public String getSetter() { + return setter; + } + + public void setSetter(String setter) { + this.setter = setter; + } + + public String getState() { + return state; + } + + public void setState(String state) { + this.state = state; + } + + public String getFlagId() { + return flagId; + } + + public void setFlagId(String flagId) { + this.flagId = flagId; + } + + public int getNumber() { + return number; + } + + public void setNumber(int number) { + this.number = number; + } + + public void applyTo(TaskAttribute taskAttribute) { + Assert.isNotNull(taskAttribute); + TaskData taskData = taskAttribute.getTaskData(); + TaskAttributeMapper mapper = taskData.getAttributeMapper(); + TaskAttributeMetaData meta = taskAttribute.getMetaData().defaults(); + meta.setType(IBugzillaConstants.EDITOR_TYPE_FLAG); + meta.setKind(TaskAttribute.KIND_DEFAULT); + meta.setReadOnly(false); + + if (getNumber() != 0) { + TaskAttribute child = taskAttribute.createMappedAttribute("number"); + child.getMetaData().defaults().setType(TaskAttribute.TYPE_INTEGER); + mapper.setIntegerValue(child, getNumber()); + } + if (getRequestee() != null) { + TaskAttribute child = taskAttribute.createMappedAttribute("requestee"); + child.getMetaData().defaults().setType(TaskAttribute.TYPE_SHORT_TEXT); + mapper.setValue(child, getRequestee()); + } + if (getSetter() != null) { + TaskAttribute child = taskAttribute.createMappedAttribute("setter"); + child.getMetaData().defaults().setType(TaskAttribute.TYPE_SHORT_TEXT); + mapper.setValue(child, getSetter()); + } + if (getState() != null) { + TaskAttribute child = taskAttribute.createMappedAttribute("state"); +// child.putOption("", ""); +// child.putOption("?", "?"); +// child.putOption("+", "+"); +// child.putOption("-", "-"); + child.getMetaData().defaults().setType(TaskAttribute.TYPE_SINGLE_SELECT); + child.getMetaData().setLabel(flagId); + child.getMetaData().setReadOnly(false); + mapper.setValue(child, getState()); + taskAttribute.getMetaData().putValue(TaskAttribute.META_ASSOCIATED_ATTRIBUTE_ID, "state"); + + } + } + +} diff --git a/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/BugzillaRepositoryConnector.java b/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/BugzillaRepositoryConnector.java index 944e952dc..8bf6bd446 100644 --- a/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/BugzillaRepositoryConnector.java +++ b/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/BugzillaRepositoryConnector.java @@ -398,6 +398,7 @@ public class BugzillaRepositoryConnector extends AbstractRepositoryConnector { enSetting.addLanguageAttribute("bad_login", "error"); enSetting.addLanguageAttribute("processed", "processed"); enSetting.addLanguageAttribute("changes_submitted", "Changes submitted"); + enSetting.addLanguageAttribute("changes_submitted", "added to Bug"); languages.add(enSetting); } diff --git a/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/BugzillaTaskAttachmentHandler.java b/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/BugzillaTaskAttachmentHandler.java index fcc9b8c96..dd471ff01 100644 --- a/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/BugzillaTaskAttachmentHandler.java +++ b/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/BugzillaTaskAttachmentHandler.java @@ -27,7 +27,6 @@ import org.eclipse.mylyn.tasks.core.TaskRepository; import org.eclipse.mylyn.tasks.core.data.AbstractTaskAttachmentHandler; import org.eclipse.mylyn.tasks.core.data.AbstractTaskAttachmentSource; import org.eclipse.mylyn.tasks.core.data.TaskAttachmentMapper; -import org.eclipse.mylyn.tasks.core.data.TaskAttachmentPartSource; import org.eclipse.mylyn.tasks.core.data.TaskAttribute; /** @@ -75,38 +74,8 @@ public class BugzillaTaskAttachmentHandler extends AbstractTaskAttachmentHandler monitor.beginTask("Sending attachment", IProgressMonitor.UNKNOWN); BugzillaClient client = connector.getClientManager().getClient(repository, new SubProgressMonitor(monitor, IProgressMonitor.UNKNOWN)); - String description = source.getDescription(); - String contentType = source.getContentType(); - String filename = source.getName(); - boolean isPatch = false; - if (attachmentAttribute != null) { - TaskAttachmentMapper mapper = TaskAttachmentMapper.createFrom(attachmentAttribute); - - if (mapper.getDescription() != null) { - description = mapper.getDescription(); - } - - if (mapper.getContentType() != null) { - contentType = mapper.getContentType(); - } - - if (mapper.getFileName() != null) { - filename = mapper.getFileName(); - } - - if (mapper.isPatch() != null) { - isPatch = mapper.isPatch(); - } - } - - if (description == null) { - throw new CoreException(new Status(IStatus.WARNING, BugzillaCorePlugin.ID_PLUGIN, - "A description is required when submitting attachments.")); - } - - client.postAttachment(task.getTaskId(), comment, description, contentType, isPatch, - new TaskAttachmentPartSource(source, filename), monitor); + client.postAttachment(task.getTaskId(), comment, source, attachmentAttribute, monitor); } catch (IOException e) { throw new CoreException(new Status(IStatus.ERROR, BugzillaCorePlugin.ID_PLUGIN, "Unable to submit attachment", e)); diff --git a/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/IBugzillaConstants.java b/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/IBugzillaConstants.java index 063a592df..d1dfff357 100644 --- a/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/IBugzillaConstants.java +++ b/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/IBugzillaConstants.java @@ -278,6 +278,8 @@ public interface IBugzillaConstants { public static final String EDITOR_TYPE_VOTES = "bugzilla.editor.votes"; + public static final String EDITOR_TYPE_FLAG = "bugzilla.editor.flag"; + public static final String ATTRIBUTE_BUGZILLA_QUERY_CUSTOM = "bugzilla.query.custom"; // Old Tags used for migration diff --git a/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/RepositoryConfiguration.java b/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/RepositoryConfiguration.java index 8463096bb..ae77183ed 100644 --- a/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/RepositoryConfiguration.java +++ b/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/RepositoryConfiguration.java @@ -16,7 +16,6 @@ import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; import java.util.HashSet; -import java.util.LinkedList; import java.util.List; import java.util.Locale; import java.util.Map; @@ -33,7 +32,8 @@ import org.eclipse.mylyn.tasks.core.data.TaskOperation; */ public class RepositoryConfiguration implements Serializable { - private static final long serialVersionUID = 575019225495659016L; +// old private static final long serialVersionUID = 575019225495659016L; + private static final long serialVersionUID = -782630475741754124L; private static final String VERSION_UNKNOWN = "unknown"; @@ -65,7 +65,7 @@ public class RepositoryConfiguration implements Serializable { private final List<String> milestones = new ArrayList<String>(); - private final List<BugzillaCustomField> customFields = new LinkedList<BugzillaCustomField>(); + private final List<BugzillaCustomField> customFields = new ArrayList<BugzillaCustomField>(); private final List<BugzillaFlag> flags = new ArrayList<BugzillaFlag>(); @@ -369,11 +369,73 @@ public class RepositoryConfiguration implements Serializable { public void configureTaskData(TaskData taskData) { if (taskData != null) { + addMissingFlags(taskData); updateAttributeOptions(taskData); addValidOperations(taskData); } } + private void addMissingFlags(TaskData taskData) { + List<String> existingFlags = new ArrayList<String>(); + for (TaskAttribute attribute : new HashSet<TaskAttribute>(taskData.getRoot().getAttributes().values())) { + if (attribute.getId().startsWith("task.common.kind.flag")) { + TaskAttribute state = attribute.getAttribute("state"); + if (state != null) { + String nameValue = state.getMetaData().getLabel(); + if (!existingFlags.contains(nameValue)) { + existingFlags.add(nameValue); + } + } + } + } + TaskAttribute productAttribute = taskData.getRoot().getMappedAttribute(BugzillaAttribute.PRODUCT.getKey()); + TaskAttribute componentAttribute = taskData.getRoot().getMappedAttribute(BugzillaAttribute.COMPONENT.getKey()); + List<BugzillaFlag> flags = getFlags(); + for (BugzillaFlag bugzillaFlag : flags) { + if (bugzillaFlag.getType().equals("attachment")) { + continue; + } + if (!bugzillaFlag.isUsedIn(productAttribute.getValue(), componentAttribute.getValue())) { + continue; + } + if (existingFlags.contains(bugzillaFlag.getName()) && !bugzillaFlag.isMultiplicable()) { + continue; + } + BugzillaFlagMapper mapper = new BugzillaFlagMapper(); + mapper.setRequestee(""); + mapper.setSetter(""); + mapper.setState(" "); + mapper.setFlagId(bugzillaFlag.getName()); + mapper.setNumber(0); + TaskAttribute attribute = taskData.getRoot().createAttribute( + "task.common.kind.flag_type" + bugzillaFlag.getFlagId()); + mapper.applyTo(attribute); + } + setFlagsRequestee(taskData); + } + + private void setFlagsRequestee(TaskData taskData) { + for (TaskAttribute attribute : new HashSet<TaskAttribute>(taskData.getRoot().getAttributes().values())) { + if (attribute.getId().startsWith("task.common.kind.flag")) { + TaskAttribute state = attribute.getAttribute("state"); + if (state != null) { + String nameValue = state.getMetaData().getLabel(); + for (BugzillaFlag bugzillaFlag : flags) { + if (nameValue.equals(bugzillaFlag.getName())) { + TaskAttribute requestee = attribute.getAttribute("requestee"); + if (requestee == null) { + requestee = attribute.createMappedAttribute("requestee"); + requestee.getMetaData().defaults().setType(TaskAttribute.TYPE_SHORT_TEXT); + requestee.setValue(""); + } + requestee.getMetaData().setReadOnly(!bugzillaFlag.isSpecifically_requestable()); + } + } + } + } + } + } + public void updateAttributeOptions(TaskData existingReport) { TaskAttribute attributeProduct = existingReport.getRoot() .getMappedAttribute(BugzillaAttribute.PRODUCT.getKey()); @@ -390,6 +452,10 @@ public class RepositoryConfiguration implements Serializable { continue; } + if (attribute.getId().startsWith("task.common.kind.flag")) { + attribute = attribute.getAttribute("state"); + } + attribute.clearOptions(); for (String option : optionValues) { attribute.putOption(option, option); @@ -409,25 +475,55 @@ public class RepositoryConfiguration implements Serializable { } } - } else { - - BugzillaAttribute element; - try { - element = BugzillaAttribute.valueOf(attribute.getId().trim().toUpperCase(Locale.ENGLISH)); - } catch (RuntimeException e) { - if (e instanceof IllegalArgumentException) { - // ignore unrecognized tags - return options; + } else if (attribute.getId().startsWith("task.common.kind.flag")) { + + TaskAttribute state = attribute.getAttribute("state"); + if (state != null) { + String nameValue = state.getMetaData().getLabel(); + options.add(""); + for (BugzillaFlag bugzillaFlag : flags) { + if (nameValue.equals(bugzillaFlag.getName())) { + if (nameValue.equals(bugzillaFlag.getName())) { + if (bugzillaFlag.isRequestable()) { + options.add("?"); + } + break; + } + } } - throw e; + options.add("+"); + options.add("-"); } + } + + else { + String kind = attribute.getMetaData().getKind(); + + if (kind != null && kind.equals("task.common.kind.flag")) { + options.add(""); + options.add("?"); + options.add("+"); + options.add("-"); + } else { + + BugzillaAttribute element; + try { + element = BugzillaAttribute.valueOf(attribute.getId().trim().toUpperCase(Locale.ENGLISH)); + } catch (RuntimeException e) { + if (e instanceof IllegalArgumentException) { + // ignore unrecognized tags + return options; + } + throw e; + } - options = getOptionValues(element, product); + options = getOptionValues(element, product); - if (element != BugzillaAttribute.RESOLUTION && element != BugzillaAttribute.OP_SYS - && element != BugzillaAttribute.BUG_SEVERITY && element != BugzillaAttribute.PRIORITY - && element != BugzillaAttribute.BUG_STATUS) { - Collections.sort(options); + if (element != BugzillaAttribute.RESOLUTION && element != BugzillaAttribute.OP_SYS + && element != BugzillaAttribute.BUG_SEVERITY && element != BugzillaAttribute.PRIORITY + && element != BugzillaAttribute.BUG_STATUS) { + Collections.sort(options); + } } } return options; @@ -564,4 +660,13 @@ public class RepositoryConfiguration implements Serializable { public List<BugzillaFlag> getFlags() { return flags; } + + public BugzillaFlag getFlagWithId(Integer id) { + for (BugzillaFlag bugzillaFlag : flags) { + if (bugzillaFlag.getFlagId() == id) { + return bugzillaFlag; + } + } + return null; + } } diff --git a/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/SaxConfigurationContentHandler.java b/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/SaxConfigurationContentHandler.java index fa4af4ff3..2a4c3326d 100644 --- a/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/SaxConfigurationContentHandler.java +++ b/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/SaxConfigurationContentHandler.java @@ -93,6 +93,8 @@ public class SaxConfigurationContentHandler extends DefaultHandler { private static final String ELEMENT_SPECIFICALLY_REQUESTABLE = "specifically_requestable"; + private static final String ELEMENT_ID = "id"; + private static final String ELEMENT_MULTIPLICABLE = "multiplicable"; private static final int EXPECTING_ROOT = 0; @@ -163,6 +165,8 @@ public class SaxConfigurationContentHandler extends DefaultHandler { private String currentMultiplicable; + private int currentId; + private String currentTypeDesc = ""; private String currentEnterBug = ""; @@ -187,6 +191,12 @@ public class SaxConfigurationContentHandler extends DefaultHandler { private final Map<String, List<String>> customOption = new HashMap<String, List<String>>(); + private final Map<String, Map<String, List<String>>> flagsInComponent = new HashMap<String, Map<String, List<String>>>(); + + private final Map<String, Integer> flagIds = new HashMap<String, Integer>(); + + private String currentComponent = ""; + private String currentCustomOptionName = ""; public RepositoryConfiguration getConfiguration() { @@ -255,6 +265,7 @@ public class SaxConfigurationContentHandler extends DefaultHandler { currentType = ""; currentTypeDesc = ""; currentEnterBug = ""; + currentId = -1; } else if (localName.equals(ELEMENT_FLAG_TYPES)) { state = state | IN_FLAG_TYPES; } else if (localName.equals(ELEMENT_FLAG_TYPE)) { @@ -338,9 +349,10 @@ public class SaxConfigurationContentHandler extends DefaultHandler { } } else if (state == (IN_COMPONENTS | IN_LI | IN_COMPONENT)) { // COMPONENT NAME + currentComponent = characters.toString(); if (about != null && !componentNames.containsValue(about)) { - if (characters.length() > 0) { - componentNames.put(about, characters.toString()); + if (currentComponent.length() > 0) { + componentNames.put(about, currentComponent); } } } else if (state == (IN_TARGET_MILESTONES | IN_LI | IN_TARGET_MILESTONE)) { @@ -392,6 +404,8 @@ public class SaxConfigurationContentHandler extends DefaultHandler { currentDescription = characters.toString(); } else if (localName.equals(ELEMENT_TYPE)) { currentType = characters.toString(); + } else if (localName.equals(ELEMENT_ID)) { + currentId = Integer.parseInt(characters.toString()); } else if (localName.equals(ELEMENT_TYPE_DESC)) { currentTypeDesc = characters.toString(); } else if (localName.equals(ELEMENT_ENTER_BUG)) { @@ -405,9 +419,14 @@ public class SaxConfigurationContentHandler extends DefaultHandler { } else if (localName.equals(ELEMENT_FLAG_TYPES)) { state = state & ~IN_FLAG_TYPES; } else if (localName.equals(ELEMENT_FLAG_TYPE)) { - BugzillaFlag newFlag = new BugzillaFlag(currentName, currentDescription, currentType, currentRequestable, - currentSpecifically_requestable, currentMultiplicable); - configuration.addFlag(newFlag); + if (currentId != -1) { + if (about != null && !flagIds.containsValue(about)) { + flagIds.put(about, currentId); + } + BugzillaFlag newFlag = new BugzillaFlag(currentName, currentDescription, currentType, + currentRequestable, currentSpecifically_requestable, currentMultiplicable, currentId); + configuration.addFlag(newFlag); + } state = state & ~IN_FLAG_TYPE; } else if (localName.startsWith(BugzillaCustomField.CUSTOM_FIELD_PREFIX)) { state = state & ~IN_CUSTOM_OPTION; @@ -457,9 +476,35 @@ public class SaxConfigurationContentHandler extends DefaultHandler { } } break; + case IN_COMPONENTS | IN_LI | IN_COMPONENT | IN_FLAG_TYPES | IN_LI_LI: + if (attributes != null) { + String compURI = attributes.getValue(ATTRIBUTE_RESOURCE); + if (compURI != null && currentComponent.length() > 0 && currentProduct.length() > 0 + && compURI.length() > 0) { + + Map<String, List<String>> flagComponentList = flagsInComponent.get(currentProduct); + if (flagComponentList == null) { + flagComponentList = new HashMap<String, List<String>>(); + flagsInComponent.put(currentProduct, flagComponentList); + } + List<String> flagsForComponent = flagComponentList.get(currentComponent); + if (flagsForComponent == null) { + flagsForComponent = new ArrayList<String>(); + flagComponentList.put(currentComponent, flagsForComponent); + } + flagsForComponent.add(compURI.replace("flags.cgi?id=", "flag.cgi?id=")); + int i = 0; + i++; + } + } + break; case IN_COMPONENTS | IN_LI | IN_COMPONENT: if (attributes != null) { about = attributes.getValue(ATTRIBUTE_RDF_ABOUT); + int idx = about.indexOf("&product="); + if (idx != -1) { + currentProduct = about.substring(idx + 9); + } } break; case IN_VERSIONS | IN_LI | IN_VERSION: @@ -478,7 +523,7 @@ public class SaxConfigurationContentHandler extends DefaultHandler { about = attributes.getValue(ATTRIBUTE_RDF_ABOUT); } break; - case IN_FLAG_TYPE | IN_LI | IN_FLAG_TYPE: + case IN_FLAG_TYPES | IN_LI | IN_FLAG_TYPE: if (attributes != null) { about = attributes.getValue(ATTRIBUTE_RDF_ABOUT); } @@ -521,6 +566,19 @@ public class SaxConfigurationContentHandler extends DefaultHandler { } } + + for (String flagProduct : flagsInComponent.keySet()) { + Map<String, List<String>> flagComponentUsage = flagsInComponent.get(flagProduct); + for (String flagusageList : flagComponentUsage.keySet()) { + List<String> flagList = flagComponentUsage.get(flagusageList); + for (String flagAbout : flagList) { + Integer flagId = flagIds.get(flagAbout); + BugzillaFlag flag = configuration.getFlagWithId(flagId); + flag.addUsed(flagProduct, flagusageList); + } + } + } + super.endDocument(); } } diff --git a/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/SaxMultiBugReportContentHandler.java b/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/SaxMultiBugReportContentHandler.java index 888b93c84..04970451e 100644 --- a/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/SaxMultiBugReportContentHandler.java +++ b/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/SaxMultiBugReportContentHandler.java @@ -163,6 +163,26 @@ public class SaxMultiBugReportContentHandler extends DefaultHandler { isPatch = "1".equals(attributes.getValue(BugzillaAttribute.IS_PATCH.getKey())); } break; + case FLAG: + if (attributes != null && attributes.getLength() > 0) { + String name = attributes.getValue(ATTRIBUTE_NAME); + if (name != null) { + BugzillaFlagMapper mapper = new BugzillaFlagMapper(); + String requestee = attributes.getValue("requestee"); + mapper.setRequestee(requestee); + String setter = attributes.getValue("setter"); + mapper.setSetter(setter); + String status = attributes.getValue("status"); + mapper.setState(status); + mapper.setFlagId(name); + String id = attributes.getValue("id"); + mapper.setNumber(Integer.valueOf(id)); + TaskAttribute attribute = repositoryTaskData.getRoot() + .createAttribute("task.common.kind.flag" + id); + mapper.applyTo(attribute); + } + } + break; } } @@ -170,6 +190,11 @@ public class SaxMultiBugReportContentHandler extends DefaultHandler { @Override public void endElement(String uri, String localName, String qName) throws SAXException { + //remove whitespaces from the end of the parsed Text + while (characters.length() > 0 && Character.isWhitespace(characters.charAt(characters.length() - 1))) { + characters.setLength(characters.length() - 1); + } + String parsedText = characters.toString(); if (localName.startsWith(BugzillaCustomField.CUSTOM_FIELD_PREFIX)) { @@ -372,6 +397,9 @@ public class SaxMultiBugReportContentHandler extends DefaultHandler { case UNKNOWN: //ignore break; + case FLAG: + //ignore + break; default: TaskAttribute defaultAttribute = repositoryTaskData.getRoot().getMappedAttribute(tag.getKey()); if (defaultAttribute == null) { |