Author: hair
Date: 2007-10-27 14:39:07-0700
New Revision: 10472
Modified:
trunk/src/conf/classes/org/tigris/scarab/util/xmlissues/xsls/jira.xsl
trunk/src/java/org/tigris/scarab/screens/admin/ (props changed)
trunk/src/java/org/tigris/scarab/screens/admin/XMLImportIssuesResults.java
trunk/src/java/org/tigris/scarab/util/word/QueryResult.java
trunk/src/java/org/tigris/scarab/util/xmlissues/Dependency.java
trunk/src/java/org/tigris/scarab/util/xmlissues/ImportIssues.java
trunk/src/java/org/tigris/scarab/util/xmlissues/ScarabIssues.java
Log:
SCB1584 - Import issues from Jira
dependencies fixed
Modified: trunk/src/conf/classes/org/tigris/scarab/util/xmlissues/xsls/jira.xsl
Url: http://scarab.tigris.org/source/browse/scarab/trunk/src/conf/classes/org/tigris/scarab/util/xmlissues/xsls/jira.xsl?view=diff&rev=10472&p1=trunk/src/conf/classes/org/tigris/scarab/util/xmlissues/xsls/jira.xsl&p2=trunk/src/conf/classes/org/tigris/scarab/util/xmlissues/xsls/jira.xsl&r1=10471&r2=10472
==============================================================================
--- trunk/src/conf/classes/org/tigris/scarab/util/xmlissues/xsls/jira.xsl (original)
+++ trunk/src/conf/classes/org/tigris/scarab/util/xmlissues/xsls/jira.xsl 2007-10-27 14:39:07-0700
@@ -3,173 +3,270 @@
Document : jira.xsl
Created on : November 30, 2005, 6:04 AM
Author : hair
- Description:
- Purpose of transformation follows.
+ Description: Transform a jira xml into scarab xml. The transformed xml can then be imported into scarab.
-->
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0">
- <xsl:output method="xml" encoding="UTF-8" indent="yes"
- doctype-system="http://scarab.tigris.org/dtd/scarab-0.21.0.dtd"/>
+ <xsl:output method="xml" encoding="UTF-8" indent="yes"/>
+<!-- doctype-system="http://scarab.tigris.org/dtd/scarab-0.21.0.dtd"/-->
<xsl:template match="rss/channel">
- <scarab-issues>
- <import-type>create-same-db</import-type>
+ <scarab-issues>
+ <import-type>create-same-db</import-type>
- <!-- ImportIssues.insertModuleNode(..) -->
+ <!-- ImportIssues.insertModuleNode(..) -->
- <issues>
+ <issues>
- <xsl:for-each select="item">
+ <xsl:for-each select="item">
- <issue>
- <id><xsl:value-of select="translate(key,'-','')"/></id> <!-- remove hyphons, not scarab style. -->
- <artifact-type>[JIRA] <xsl:value-of select="type"/></artifact-type>
- <activity-sets>
- <activity-set>
-
- <type>Create Issue</type>
- <xsl:for-each select="reporter"><!-- [XXX] Only ever be one, but we need to get to attribute @username -->
- <xsl:element name="created-by">
- <xsl:attribute name="username"><xsl:value-of select="@username"/></xsl:attribute>
- <xsl:attribute name="fullname"><xsl:value-of select="."/></xsl:attribute>
- <xsl:value-of select="@username"/>
- </xsl:element>
- </xsl:for-each>
- <created-date>
- <format>EEE, d MMM yyyy HH:mm:ss Z (z)</format>
- <timestamp><xsl:value-of select="created"/></timestamp>
- </created-date>
- <activities>
- <activity>
-
- <attribute>[JIRA] Summary</attribute>
- <new-value><xsl:value-of select="summary"/></new-value>
- <description>Issue <xsl:value-of select="key"/> had Summary set to '<xsl:value-of select="summary"/>'</description>
- <end-date>
- <format>EEE, d MMM yyyy HH:mm:ss Z (z)</format>
- <timestamp><xsl:value-of select="created"/></timestamp>
- </end-date>
- </activity>
- <activity>
-
- <attribute>[JIRA] Description</attribute>
- <!-- JIRA writes its descriptions out in xhtml format -->
- <new-value>__Original ID: <xsl:value-of select="key"/>__ \\
- <xsl:value-of select="translate(description,'<br/>','')"/>
- </new-value>
- <description>Description set to <xsl:value-of select="description" disable-output-escaping="yes"/></description>
- </activity>
- <activity>
-
- <attribute>[JIRA] Status</attribute>
- <new-option><xsl:value-of select="status"/></new-option>
- <description>Status set to <xsl:value-of select="status"/></description>
- </activity>
- <activity>
-
- <attribute>[JIRA] Environment</attribute>
- <new-value><xsl:value-of select="environment"/></new-value>
- <description>Environment set to <xsl:value-of select="environment"/></description>
- </activity>
- <activity>
-
- <attribute>[JIRA] Priority</attribute>
- <new-option><xsl:value-of select="priority"/></new-option>
- <description>Priority set to <xsl:value-of select="priority"/></description>
- </activity>
- <xsl:if test="version!=''">
- <activity>
-
- <attribute>[JIRA] Version</attribute>
- <new-option><xsl:value-of select="version[1]"/></new-option>
- <description>Version set to <xsl:value-of select="version"/></description>
- </activity>
- </xsl:if>
- <xsl:if test="component!=''">
- <activity>
-
- <attribute>[JIRA] Component</attribute>
- <new-option><xsl:value-of select="component"/></new-option>
- <description>Component set to <xsl:value-of select="component"/></description>
- </activity>
- </xsl:if>
- <activity>
-
- <attribute>[JIRA] Due</attribute>
- <new-value><xsl:value-of select="due"/></new-value>
- <description>Due set to <xsl:value-of select="due"/></description>
- </activity>
- <activity>
-
- <attribute>[JIRA] Votes</attribute>
- <new-value><xsl:value-of select="votes"/></new-value>
- <description>Votes set to <xsl:value-of select="votes"/></description>
- </activity>
- </activities>
- </activity-set>
- <activity-set>
-
- <type>Edit Issue</type>
- <created-date>
- <format>EEE, d MMM yyyy HH:mm:ss Z (z)</format>
- <timestamp><xsl:value-of select="updated"/></timestamp>
- </created-date>
- <activities>
- <activity>
-
- <attribute>[JIRA] Resolution</attribute>
- <new-option><xsl:value-of select="resolution"/></new-option>
- <new-value><xsl:value-of select="resolution"/></new-value>
- <description>Resolution set to <xsl:value-of select="resolution"/></description>
- </activity>
- <xsl:if test="assignee!='Unassigned'">
- <xsl:for-each select="assignee">
- <activity>
- <attribute>[JIRA] Assignee</attribute>
- <xsl:element name="new-user">
- <xsl:attribute name="username"><xsl:value-of select="@username"/></xsl:attribute>
- <xsl:attribute name="fullname"><xsl:value-of select="."/></xsl:attribute>
- <xsl:value-of select="@username"/>
- </xsl:element>
- <new-value><xsl:value-of select="@username"/></new-value>
- <description>Assignee set to <xsl:value-of select="@username"/> (<xsl:value-of select="."/>)</description>
- </activity>
- </xsl:for-each>
- </xsl:if>
- </activities>
- </activity-set>
-
- <xsl:for-each select="comments/comment">
- <activity-set>
- <type>Edit Issue</type>
- <created-date>
- <format>EEE, d MMM yyyy HH:mm:ss Z (z)</format>
- <timestamp><xsl:value-of select="../../updated"/></timestamp>
- </created-date>
- <attachment>
- <name>comment</name>
- <type>COMMENT</type>
- <data><xsl:value-of select="." disable-output-escaping="yes"/></data>
- <mimetype>text/plain</mimetype>
- <created-date>
- <format>EEE, d MMM yyyy HH:mm:ss Z (z)</format>
- <timestamp><xsl:value-of select="@created"/></timestamp>
- </created-date>
- <created-by><xsl:value-of select="@author"/></created-by>
- <deleted>false</deleted>
- </attachment>
- </activity-set>
- </xsl:for-each>
-
- </activity-sets>
- </issue>
-
- </xsl:for-each>
+ <issue>
+ <id><xsl:value-of select="translate(key,'-','')"/></id> <!-- remove hyphons, not scarab style. -->
+ <artifact-type>[JIRA] <xsl:value-of select="type"/></artifact-type>
+ <activity-sets>
+ <activity-set>
+
+ <type>Create Issue</type>
+ <xsl:for-each select="reporter"><!-- [XXX] Only ever be one, but we need to get to attribute @username -->
+ <xsl:element name="created-by">
+ <xsl:attribute name="username"><xsl:value-of select="@username"/></xsl:attribute>
+ <xsl:attribute name="fullname"><xsl:value-of select="."/></xsl:attribute>
+ <xsl:value-of select="@username"/>
+ </xsl:element>
+ </xsl:for-each>
+ <created-date>
+ <format>EEE, d MMM yyyy HH:mm:ss Z (z)</format>
+ <timestamp><xsl:value-of select="created"/></timestamp>
+ </created-date>
+ <activities>
+ <activity>
+ <attribute>[JIRA] Summary</attribute>
+ <new-value><xsl:value-of select="summary"/></new-value>
+ <description>Issue <xsl:value-of select="key"/> had Summary set to '<xsl:value-of select="summary"/>'</description>
+ <end-date>
+ <format>EEE, d MMM yyyy HH:mm:ss Z (z)</format>
+ <timestamp><xsl:value-of select="created"/></timestamp>
+ </end-date>
+ </activity>
+ <activity>
+ <attribute>[JIRA] Description</attribute>
+ <!-- JIRA writes its descriptions out in xhtml format -->
+ <new-value>__Original JIRA Id: <xsl:value-of select="key"/>__ \\
+<xsl:call-template name="tidy-html"><xsl:with-param name="input" select="description"/></xsl:call-template>
+ </new-value>
+ <description>Description set to <xsl:call-template name="tidy-html"><xsl:with-param name="input" select="description"/></xsl:call-template>
+ </description>
+ </activity>
+ <activity>
+ <attribute>[JIRA] Status</attribute>
+ <new-option><xsl:value-of select="status"/></new-option>
+ <description>Status set to <xsl:value-of select="status"/></description>
+ </activity>
+ <activity>
+ <attribute>[JIRA] Environment</attribute>
+ <new-value><xsl:value-of select="environment"/></new-value>
+ <description>Environment set to <xsl:value-of select="environment"/></description>
+ </activity>
+ <activity>
+ <attribute>[JIRA] Priority</attribute>
+ <new-option><xsl:value-of select="priority"/></new-option>
+ <description>Priority set to <xsl:value-of select="priority"/></description>
+ </activity>
+ <xsl:if test="version!=''">
+ <activity>
+ <attribute>[JIRA] Version</attribute>
+ <new-option><xsl:value-of select="version[1]"/></new-option>
+ <description>Version set to <xsl:value-of select="version"/></description>
+ </activity>
+ </xsl:if>
+ <xsl:for-each select="component">
+ <activity>
+ <attribute>[JIRA] Component</attribute>
+ <new-option><xsl:value-of select="."/></new-option>
+ <description>Component set to <xsl:value-of select="."/></description>
+ </activity>
+ </xsl:for-each>
+ <activity>
+ <attribute>[JIRA] Due</attribute>
+ <new-value><xsl:value-of select="due"/></new-value>
+ <description>Due set to <xsl:value-of select="due"/></description>
+ </activity>
+ <activity>
+ <attribute>[JIRA] Votes</attribute>
+ <new-value><xsl:value-of select="votes"/></new-value>
+ <description>Votes set to <xsl:value-of select="votes"/></description>
+ </activity>
+ <xsl:for-each select="customfields/customfield">
+ <activity>
+ <attribute>[JIRA] <xsl:value-of select="customfieldname"/></attribute>
+ <!-- XXX not sure this will work, it should be improved to just use [0] anyway -->
+ <xsl:for-each select="customfieldvalues/customfieldvalue">
+ <new-value><xsl:value-of select="."/></new-value>
+ <description><xsl:value-of select="customfieldname"/> set to <xsl:value-of select="."/></description>
+ </xsl:for-each>
+ </activity>
+ </xsl:for-each>
+ </activities>
+ </activity-set>
+ <activity-set>
+ <type>Edit Issue</type>
+ <created-date>
+ <format>EEE, d MMM yyyy HH:mm:ss Z (z)</format>
+ <timestamp><xsl:value-of select="updated"/></timestamp>
+ </created-date>
+ <activities>
+ <activity>
+ <attribute>[JIRA] Resolution</attribute>
+ <new-option><xsl:value-of select="resolution"/></new-option>
+ <new-value><xsl:value-of select="resolution"/></new-value>
+ <description>Resolution set to <xsl:value-of select="resolution"/></description>
+ </activity>
+ <xsl:if test="assignee!='Unassigned'">
+ <xsl:for-each select="assignee">
+ <activity>
+ <attribute>[JIRA] Assignee</attribute>
+ <xsl:element name="new-user">
+ <xsl:attribute name="username"><xsl:value-of select="@username"/></xsl:attribute>
+ <xsl:attribute name="fullname"><xsl:value-of select="."/></xsl:attribute>
+ <xsl:value-of select="@username"/>
+ </xsl:element>
+ <new-value><xsl:value-of select="@username"/></new-value>
+ <description>Assignee set to <xsl:value-of select="@username"/> (<xsl:value-of select="."/>)</description>
+ </activity>
+ </xsl:for-each>
+ </xsl:if>
+ </activities>
+ </activity-set>
+
+ <xsl:for-each select="comments/comment">
+ <activity-set>
+ <type>Edit Issue</type>
+ <created-date>
+ <format>EEE, d MMM yyyy HH:mm:ss Z (z)</format>
+ <timestamp><xsl:value-of select="../../updated"/></timestamp>
+ </created-date>
+ <attachment>
+ <name>comment</name>
+ <type>COMMENT</type>
+ <data><xsl:call-template name="tidy-html"><xsl:with-param name="input" select="."/></xsl:call-template></data>
+ <mimetype>text/plain</mimetype>
+ <created-date>
+ <format>EEE, d MMM yyyy HH:mm:ss Z (z)</format>
+ <timestamp><xsl:value-of select="@created"/></timestamp>
+ </created-date>
+ <created-by><xsl:value-of select="@author"/></created-by>
+ <deleted>false</deleted>
+ </attachment>
+ </activity-set>
+ </xsl:for-each>
+
+ <xsl:for-each select="issuelinks/issuelinktype">
+ <activity-set>
+ <!-- Note the id uses the id of this dependant bug.
+ We must use the same activity set id for both the dependant
+ and prerequisite bugs.
+ -->
+ <!--id><xsl:value-of select="@id"/></id-->
+ <type>Edit Issue</type>
+ <created-by><xsl:value-of select="../../reporter/@username"/></created-by>
+ <created-date>
+ <format>EEE, d MMM yyyy HH:mm:ss Z (z)</format>
+ <timestamp><xsl:value-of select="../../created"/></timestamp>
+ </created-date>
+ <activities>
+
+ <xsl:for-each select="outwardlinks/issuelink">
+ <activity>
+ <attribute>NullAttribute</attribute>
+ <xsl:variable name="type">
+ <xsl:if test="starts-with(../../name, 'Depends')">blocking</xsl:if>
+ <xsl:if test="starts-with(../../name, 'Duplicate')">duplicate</xsl:if>
+ </xsl:variable>
+ <new-value><xsl:value-of select="$type"/></new-value>
+ <dependency>
+ <id><xsl:value-of select="issuekey/@id"/></id>
+ <parent><xsl:value-of select="translate(../../../../key,'-','')"/></parent>
+ <child><xsl:value-of select="translate(issuekey,'-','')"/></child>
+ <type><xsl:value-of select="$type"/></type>
+ <deleted>false</deleted>
+ </dependency>
+ <description><xsl:value-of select="translate(issuekey,'-','')"/> <xsl:value-of select="../@description"/></description>
+ </activity>
+ </xsl:for-each>
+
+ <xsl:for-each select="inwardlinks/issuelink">
+ <activity>
+ <attribute>NullAttribute</attribute>
+ <xsl:variable name="type">
+ <xsl:if test="starts-with(../../name, 'Depends')">blocking</xsl:if>
+ <xsl:if test="starts-with(../../name, 'Duplicate')">duplicate</xsl:if>
+ </xsl:variable>
+ <new-value><xsl:value-of select="$type"/></new-value>
+ <dependency>
+ <id><xsl:value-of select="issuekey/@id"/></id>
+ <parent><xsl:value-of select="translate(issuekey,'-','')"/></parent>
+ <child><xsl:value-of select="translate(../../../../key,'-','')"/></child>
+ <type><xsl:value-of select="$type"/></type>
+ <deleted>false</deleted>
+ </dependency>
+ <description><xsl:value-of select="translate(issuekey,'-','')"/> <xsl:value-of select="../@description"/></description>
+ </activity>
+ </xsl:for-each>
+ </activities>
+
+ </activity-set>
+ </xsl:for-each>
+
+ </activity-sets>
+ </issue>
+
+ </xsl:for-each>
+
+ </issues>
+
+ </scarab-issues>
+
+ </xsl:template>
+
+ <!-- Utility templates -->
+
+ <xsl:template name="tidy-html">
+ <xsl:param name="input"/>
+
+ <xsl:call-template name="string-replace">
+ <xsl:with-param name="string">
+
+ <xsl:call-template name="string-replace">
+ <xsl:with-param name="string" select="$input"/>
+ <xsl:with-param name="from">&nbsp;</xsl:with-param>
+ <xsl:with-param name="to"> </xsl:with-param>
+ </xsl:call-template>
+
+ </xsl:with-param>
+ <xsl:with-param name="from"><br/></xsl:with-param>
+ <xsl:with-param name="to"> </xsl:with-param>
+ </xsl:call-template>
+
+ </xsl:template>
+
+ <xsl:template name="string-replace" >
+ <xsl:param name="string"/>
+ <xsl:param name="from"/>
+ <xsl:param name="to"/>
+ <xsl:choose>
+ <xsl:when test="contains($string,$from)">
+ <xsl:value-of select="substring-before($string,$from)"/>
+ <xsl:value-of select="$to"/>
+ <xsl:call-template name="string-replace">
+ <xsl:with-param name="string" select="substring-after($string,$from)"/>
+ <xsl:with-param name="from" select="$from"/>
+ <xsl:with-param name="to" select="$to"/>
+ </xsl:call-template>
+ </xsl:when>
+ <xsl:otherwise>
+ <xsl:value-of select="$string" disable-output-escaping="no"/>
+ </xsl:otherwise>
+ </xsl:choose>
+ </xsl:template>
- </issues>
-
- </scarab-issues>
-
- </xsl:template>
-
-</xsl:stylesheet>
\ No newline at end of file
+</xsl:stylesheet>
Modified: trunk/src/java/org/tigris/scarab/screens/admin/XMLImportIssuesResults.java
Url: http://scarab.tigris.org/source/browse/scarab/trunk/src/java/org/tigris/scarab/screens/admin/XMLImportIssuesResults.java?view=diff&rev=10472&p1=trunk/src/java/org/tigris/scarab/screens/admin/XMLImportIssuesResults.java&p2=trunk/src/java/org/tigris/scarab/screens/admin/XMLImportIssuesResults.java&r1=10471&r2=10472
==============================================================================
--- trunk/src/java/org/tigris/scarab/screens/admin/XMLImportIssuesResults.java (original)
+++ trunk/src/java/org/tigris/scarab/screens/admin/XMLImportIssuesResults.java 2007-10-27 14:39:07-0700
@@ -62,6 +62,8 @@
import org.tigris.scarab.om.ScarabUser;
import org.tigris.scarab.tools.ScarabRequestTool;
import org.tigris.scarab.om.Module;
+import org.tigris.scarab.om.ModuleManager;
+import org.tigris.scarab.om.ScarabUser;
import org.tigris.scarab.util.xmlissues.ImportIssues;
import org.tigris.scarab.tools.ScarabLocalizationTool;
@@ -111,7 +113,10 @@
{
try
{
- final ImportIssues importIssues = new ImportIssues();
+ final ScarabUser user = (ScarabUser)data.getUser();
+ final ImportIssues importIssues = new ImportIssues(
+ false,
+ user.hasPermission(ScarabSecurity.DOMAIN__ADMIN, (Module)null));
final ScarabRequestTool scarabR = getScarabRequestTool(context);
final String type = data.getParameters().getString("xmlFormat");
Modified: trunk/src/java/org/tigris/scarab/util/word/QueryResult.java
Url: http://scarab.tigris.org/source/browse/scarab/trunk/src/java/org/tigris/scarab/util/word/QueryResult.java?view=diff&rev=10472&p1=trunk/src/java/org/tigris/scarab/util/word/QueryResult.java&p2=trunk/src/java/org/tigris/scarab/util/word/QueryResult.java&r1=10471&r2=10472
==============================================================================
--- trunk/src/java/org/tigris/scarab/util/word/QueryResult.java (original)
+++ trunk/src/java/org/tigris/scarab/util/word/QueryResult.java 2007-10-27 14:39:07-0700
@@ -95,7 +95,7 @@
this.L10N = L10N;
}
- private final Issue getIssue()
+ public final Issue getIssue()
throws TorqueException
{
return IssueManager.getInstance(issueId);
Modified: trunk/src/java/org/tigris/scarab/util/xmlissues/Dependency.java
Url: http://scarab.tigris.org/source/browse/scarab/trunk/src/java/org/tigris/scarab/util/xmlissues/Dependency.java?view=diff&rev=10472&p1=trunk/src/java/org/tigris/scarab/util/xmlissues/Dependency.java&p2=trunk/src/java/org/tigris/scarab/util/xmlissues/Dependency.java&r1=10471&r2=10472
==============================================================================
--- trunk/src/java/org/tigris/scarab/util/xmlissues/Dependency.java (original)
+++ trunk/src/java/org/tigris/scarab/util/xmlissues/Dependency.java 2007-10-27 14:39:07-0700
@@ -1,7 +1,7 @@
package org.tigris.scarab.util.xmlissues;
/* ================================================================
- * Copyright (c) 2000-2002 CollabNet. All rights reserved.
+ * Copyright (c) 2000-2006 CollabNet. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
@@ -48,6 +48,7 @@
public class Dependency implements java.io.Serializable
{
+ /** @deprecated no point in using this anymore. **/
private String id = null;
private String type = null;
private String child = null;
@@ -58,11 +59,13 @@
{
}
+ /** @deprecated no point in using this anymore. **/
public void setId(String id)
{
this.id = id;
}
+ /** @deprecated no point in using this anymore. **/
public String getId()
{
return this.id;
@@ -108,21 +111,31 @@
return this.deleted;
}
- public boolean equals(Dependency dependency)
+ public boolean equals(Object obj)
{
- return (id.equals(dependency.getId()) &&
- child.equals(dependency.getChild()) &&
- parent.equals(dependency.getParent()) &&
- type.equals(dependency.getType()));
+ if( obj instanceof Dependency ){
+ final Dependency dependency = (Dependency)obj;
+ // Check the opposing matching dependency as well.
+ // It makes the presumption that immediate cyclic dependencies are not permitted.
+ return ((child.equals(dependency.getChild()) && parent.equals(dependency.getParent()))
+ || (child.equals(dependency.getParent()) && parent.equals(dependency.getChild())))
+ && type.equals(dependency.getType());
+ }else{
+ return super.equals(obj);
+ }
}
public int hashCode()
{
- return id == null ? 0 : id.hashCode();
+ int hash = 37;
+ hash += child.hashCode() + parent.hashCode(); // Allows parent-child to be swapped around & give same hashcode.
+ hash *= 17;
+ hash += type.hashCode();
+ return hash;
}
public String toString()
{
- return ("Id: " + id + " Type: " + type + " Parent: " + parent + " Child: " + child);
+ return ("Type: " + type + " Parent: " + parent + " Child: " + child);
}
}
Modified: trunk/src/java/org/tigris/scarab/util/xmlissues/ImportIssues.java
Url: http://scarab.tigris.org/source/browse/scarab/trunk/src/java/org/tigris/scarab/util/xmlissues/ImportIssues.java?view=diff&rev=10472&p1=trunk/src/java/org/tigris/scarab/util/xmlissues/ImportIssues.java&p2=trunk/src/java/org/tigris/scarab/util/xmlissues/ImportIssues.java&r1=10471&r2=10472
==============================================================================
--- trunk/src/java/org/tigris/scarab/util/xmlissues/ImportIssues.java (original)
+++ trunk/src/java/org/tigris/scarab/util/xmlissues/ImportIssues.java 2007-10-27 14:39:07-0700
@@ -88,9 +88,8 @@
import org.apache.commons.digester.Digester;
import org.apache.commons.digester.Rule;
import org.apache.commons.fileupload.FileItem;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
import org.apache.fulcrum.localization.Localization;
+import org.apache.log4j.Logger;
import org.apache.torque.TorqueException;
import org.jdom.Document;
import org.jdom.Element;
@@ -106,6 +105,7 @@
import org.tigris.scarab.util.TurbineInitialization;
import org.tigris.scarab.workflow.WorkflowFactory;
import org.xml.sax.Attributes;
+import org.xml.sax.EntityResolver;
import org.xml.sax.ErrorHandler;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
@@ -136,7 +136,7 @@
public class ImportIssues
implements ErrorHandler
{
- private static final Log LOG = LogFactory.getLog(ImportIssues.class);
+ private static final Logger LOG = Logger.getLogger(ImportIssues.class);
private final transient TransformerFactory transformerFactory
= TransformerFactory.newInstance();
// private final transient DocumentBuilderFactory documentBuilderFactory
@@ -183,6 +183,7 @@
private File configDir = null;
private boolean sendEmail = false;
private File xmlFile = null;
+ private boolean allowGlobalImports;
/**
* Current file attachment handling code contains a security hole
@@ -209,12 +210,13 @@
public ImportIssues()
{
- this(false);
+ this(false, false);
}
- public ImportIssues(final boolean allowFileAttachments)
+ public ImportIssues(final boolean allowFileAttachments, final boolean allowGlobalImports)
{
this.allowFileAttachments = allowFileAttachments;
+ this.allowGlobalImports = allowGlobalImports;
this.importErrors = new ImportErrors();
}
@@ -612,7 +614,7 @@
final String name,
final Reader is,
final BeanReader reader)
- throws ParserConfigurationException,SAXException,IOException,ScarabException
+ throws ParserConfigurationException,SAXException,IOException,ScarabException, TorqueException
{
setValidationMode(reader, false);
final ScarabIssues si = (ScarabIssues)reader.parse(is);
@@ -700,49 +702,7 @@
String systemId)
throws SAXException
{
- InputSource input = null;
- if (publicId == null && systemId != null)
- {
- // Resolve SYSTEM DOCTYPE.
- if (SYSTEM_DTD_URI.equalsIgnoreCase(systemId) ||
- INTERNAL_DTD_URI.equalsIgnoreCase(systemId))
- {
- // First look for the DTD in the classpath.
- input = resolveDTDResource();
-
- if (input == null)
- {
- // Kick resolution back to Digester.
- input = super.resolveEntity(publicId,
- systemId);
- }
- }
- }
- return input;
- }
-
- /**
- * Looks for the DTD in the classpath as resouce
- * {@link #DTD_RESOURCE}.
- *
- * @return The DTD, or <code>null</code> if not found.
- */
- private InputSource resolveDTDResource()
- {
- InputStream stream =
- getClass().getResourceAsStream(DTD_RESOURCE);
- if (stream != null)
- {
- LOG.debug("Located DTD in classpath using " +
- "resource path '" + DTD_RESOURCE + '\'');
- return new InputSource(stream);
- }
- else
- {
- LOG.debug("DTD resource '" + DTD_RESOURCE + "' not " +
- "found in classpath");
- return null;
- }
+ return ImportIssues.this.resolveEntity(this, publicId, systemId);
}
};
@@ -787,6 +747,7 @@
{
ScarabIssues si = (ScarabIssues) getDigester().peek();
si.allowFileAttachments(allowFileAttachments);
+ si.allowGlobalImports(allowGlobalImports);
si.inValidationMode(validationMode);
si.importErrors = importErrors;
}
@@ -921,7 +882,7 @@
transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
}
transformer.transform(xmlSource, result);
- System.out.println(writer.toString());
+ //System.out.println(writer.toString());
return new StringReader(writer.toString());
}
@@ -970,6 +931,15 @@
// JDom version (jdk1.3 compatible)
final SAXBuilder builder = new SAXBuilder();
+ builder.setEntityResolver(new EntityResolver()
+ {
+ public InputSource resolveEntity(String publicId,
+ String systemId)
+ throws SAXException
+ {
+ return ImportIssues.this.resolveEntity(this, publicId, systemId);
+ }
+ });
final Document doc = builder.build(result);
final Element root = doc.getRootElement();
@@ -1035,4 +1005,61 @@
return instance;
}
}
+
+
+
+ private InputSource resolveEntity(
+ final EntityResolver reader,
+ final String publicId,
+ final String systemId)
+ throws SAXException
+ {
+ InputSource input = null;
+ if (publicId == null && systemId != null)
+ {
+ // Resolve SYSTEM DOCTYPE.
+ if (SYSTEM_DTD_URI.equalsIgnoreCase(systemId) ||
+ INTERNAL_DTD_URI.equalsIgnoreCase(systemId))
+ {
+ // First look for the DTD in the classpath.
+ input = resolveDTDResource();
+
+ if (input == null)
+ {
+ try {
+ // Kick resolution back to Digester.
+ input = reader.resolveEntity(publicId, systemId);
+
+ } catch (IOException ex) {
+ LOG.error(ex);
+ }
+ }
+ }
+ }
+ return input;
+ }
+
+ /**
+ * Looks for the DTD in the classpath as resouce
+ * {@link #DTD_RESOURCE}.
+ *
+ * @return The DTD, or <code>null</code> if not found.
+ */
+ private InputSource resolveDTDResource()
+ {
+ InputStream stream =
+ getClass().getResourceAsStream(DTD_RESOURCE);
+ if (stream != null)
+ {
+ LOG.debug("Located DTD in classpath using " +
+ "resource path '" + DTD_RESOURCE + '\'');
+ return new InputSource(stream);
+ }
+ else
+ {
+ LOG.debug("DTD resource '" + DTD_RESOURCE + "' not " +
+ "found in classpath");
+ return null;
+ }
+ }
}
Modified: trunk/src/java/org/tigris/scarab/util/xmlissues/ScarabIssues.java
Url: http://scarab.tigris.org/source/browse/scarab/trunk/src/java/org/tigris/scarab/util/xmlissues/ScarabIssues.java?view=diff&rev=10472&p1=trunk/src/java/org/tigris/scarab/util/xmlissues/ScarabIssues.java&p2=trunk/src/java/org/tigris/scarab/util/xmlissues/ScarabIssues.java&r1=10471&r2=10472
==============================================================================
--- trunk/src/java/org/tigris/scarab/util/xmlissues/ScarabIssues.java (original)
+++ trunk/src/java/org/tigris/scarab/util/xmlissues/ScarabIssues.java 2007-10-27 14:39:07-0700
@@ -61,9 +61,8 @@
import java.util.Set;
import org.apache.commons.collections.map.LinkedMap;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
import org.apache.fulcrum.localization.Localization;
+import org.apache.log4j.Logger;
import org.apache.torque.TorqueException;
import org.apache.turbine.Turbine;
import org.tigris.scarab.om.Activity;
@@ -128,7 +127,7 @@
*/
public class ScarabIssues implements java.io.Serializable
{
- private static final Log LOG = LogFactory.getLog(ScarabIssues.class);
+ private static final Logger LOG = Logger.getLogger(ScarabIssues.class);
private XmlModule module = null;
@@ -164,7 +163,7 @@
* Maps dependency IDs from the XML file to IDs assigned by the
* DB.
*/
- private final List dependActivitySetId = new ArrayList();
+ private final Set/*<Dependency>*/ dependActivitySetId = new HashSet/*<Dependency>*/();
private static final int CREATE_SAME_DB = 1;
private static final int CREATE_DIFFERENT_DB = 2;
@@ -204,6 +203,8 @@
* during XML parsing.
*/
private boolean allowFileAttachments = false;
+
+ private boolean allowGlobalImport = false;
public ScarabIssues()
{
@@ -239,6 +240,10 @@
{
this.allowFileAttachments = flag;
}
+
+ public void allowGlobalImports(final boolean flag){
+ allowGlobalImport = flag;
+ }
public void inValidationMode(final boolean flag)
{
@@ -341,55 +346,57 @@
{
final XmlActivity activity = (XmlActivity)itr.next();
final Dependency dependency = activity.getDependency();
- final String child = (String)issueXMLMap.get(dependency.getChild());
- final String parent = (String)issueXMLMap.get(dependency.getParent());
- if (parent == null || child == null)
- {
- LOG.debug("Could not find issues for parent '" + parent +
- "' and child '" + child + '\'');
- }
- else
- {
- try
- {
- final Issue parentIssueOM = IssueManager.getIssueById(parent);
- if (parentIssueOM == null)
- {
- throw new IllegalArgumentException("Missing parent issue"); //EXCEPTION
- }
- }
- catch (Exception e)
- {
- final String error = Localization.format(
- ScarabConstants.DEFAULT_BUNDLE_NAME,
- getLocale(),
- "CouldNotLocateParentDepend", parent);
- importErrors.add(error);
- }
- try
- {
- final Issue childIssueOM = IssueManager.getIssueById(child);
- if (childIssueOM == null)
- {
- throw new IllegalArgumentException("Missing child issue"); //EXCEPTION
- }
- }
- catch (Exception e)
- {
- final String error = Localization.format(
- ScarabConstants.DEFAULT_BUNDLE_NAME,
- getLocale(),
- "CouldNotLocateChildDepend", child);
- importErrors.add(error);
- }
- }
+
+// // FIXME the following checks don't work because issueXMLMap hasn't been filled
+// final String child = (String)issueXMLMap.get(dependency.getChild());
+// final String parent = (String)issueXMLMap.get(dependency.getParent());
+// if (parent == null || child == null)
+// {
+// LOG.debug("Could not find issues for parent '" + parent + "'(" + dependency.getChild()
+// + ") and child '" + child + "\' (" + dependency.getParent() + ')');
+// }
+// else
+// {
+// try
+// {
+// final Issue parentIssueOM = IssueManager.getIssueById(parent);
+// if (parentIssueOM == null)
+// {
+// throw new IllegalArgumentException("Missing parent issue"); //EXCEPTION
+// }
+// }
+// catch (Exception e)
+// {
+// final String error = Localization.format(
+// ScarabConstants.DEFAULT_BUNDLE_NAME,
+// getLocale(),
+// "CouldNotLocateParentDepend", parent);
+// importErrors.add(error);
+// }
+// try
+// {
+// final Issue childIssueOM = IssueManager.getIssueById(child);
+// if (childIssueOM == null)
+// {
+// throw new IllegalArgumentException("Missing child issue"); //EXCEPTION
+// }
+// }
+// catch (Exception e)
+// {
+// final String error = Localization.format(
+// ScarabConstants.DEFAULT_BUNDLE_NAME,
+// getLocale(),
+// "CouldNotLocateChildDepend", child);
+// importErrors.add(error);
+// }
+// }
}
}
allDependencies.clear();
}
void doHandleDependencies()
- throws ScarabException
+ throws ScarabException, TorqueException
{
LOG.debug("Number of dependencies found: " + allDependencies.size());
for (Iterator itr = allDependencies.iterator(); itr.hasNext();)
@@ -404,10 +411,29 @@
final String parent = (String)issueXMLMap.get(dependency.getParent());
if (parent == null || child == null)
{
+ if(null != parent || null != child)
+ {
+ // add a comment into the issue that informs of the dependency
+ final Issue issueOM = IssueManager.getIssueById(null == parent ? child : parent);
+ final Attachment attachmentOM = new Attachment();
+ attachmentOM.setName("comment");
+ attachmentOM.setTypeId(Attachment.COMMENT__PK);
+ attachmentOM.setMimeType("text/plain");
+ // TODO i18n this
+ final String text = "Dependency \""
+ + parent + " (originally " + dependency.getParent() + ") " + dependency.getType() + ' '
+ + child + " (originally " + dependency.getParent()
+ + ") \" was not imported due to "
+ + null == parent ? dependency.getParent() : dependency.getChild() + " not being resolved";
+ attachmentOM.setData(text);
+ issueOM.addComment(attachmentOM, ScarabUserManager.getInstance("Administrator"));
+ }
+
LOG.debug("Could not find issues: parent: " + parent + " child: " + child);
+ LOG.debug("----------------------------------------------------");
continue;
}
-
+ LOG.debug("doHandleDependencies: " + dependency);
if (getImportTypeCode() == UPDATE_SAME_DB)
{
LOG.error("[TODO] update-same-db import type not yet implemented");
@@ -426,7 +452,7 @@
newDependOM.setObservedId(parentIssueOM.getIssueId());
newDependOM.setObserverId(childIssueOM.getIssueId());
newDependOM.setDependType(type);
- LOG.debug("Dep: " + dependency.getId() + " Type: " + type + " Parent: " + parent + " Child: " + child);
+ LOG.debug("Dep: " + type + " Parent: " + parent + " Child: " + child);
LOG.debug("XML Activity id: " + activity.getId());
if (activity.isAddDependency())
{
@@ -460,7 +486,7 @@
}
catch (Exception e)
{
- e.printStackTrace();
+ LOG.error("Failed to handle dependencies", e);
throw new ScarabException(new L10NKey("Failed to handle dependencies <localize me>"),e); //EXCEPTION
}
}
@@ -552,75 +578,75 @@
{
throw new IllegalArgumentException(); //EXCEPTION
}
- }
- catch (Exception e)
- {
- final String error = Localization.format(
- ScarabConstants.DEFAULT_BUNDLE_NAME,
- getLocale(),
- "CouldNotFindIssueType", issue.getArtifactType());
- importErrors.add(error);
- }
- if (!moduleOM.getRModuleIssueType(issueTypeOM).getActive())
- {
- final String error = Localization.format(
- ScarabConstants.DEFAULT_BUNDLE_NAME,
- getLocale(),
- "IssueTypeInactive", issue.getArtifactType());
- importErrors.add(error);
- }
- List moduleAttributeList = null;
- if (moduleOM != null)
- {
- moduleAttributeList = moduleOM.getAttributes(issueTypeOM);
- }
-
- final List activitySets = issue.getActivitySets();
- for (Iterator itr = activitySets.iterator(); itr.hasNext();)
- {
- final XmlActivitySet activitySet = (XmlActivitySet) itr.next();
- if (activitySet.getCreatedBy() != null)
+ if (!moduleOM.getRModuleIssueType(issueTypeOM).getActive())
+ {
+ final String error = Localization.format(
+ ScarabConstants.DEFAULT_BUNDLE_NAME,
+ getLocale(),
+ "IssueTypeInactive", issue.getArtifactType());
+ importErrors.add(error);
+ }
+ List moduleAttributeList = null;
+ if (moduleOM != null)
{
- importUsers.add(activitySet.getCreatedBy());
+ moduleAttributeList = moduleOM.getAttributes(issueTypeOM);
}
- if (activitySet.getAttachment() != null)
+
+ final List activitySets = issue.getActivitySets();
+ for (Iterator itr = activitySets.iterator(); itr.hasNext();)
{
- final String attachCreatedBy = activitySet.getAttachment().getCreatedBy();
- if (attachCreatedBy != null)
+ final XmlActivitySet activitySet = (XmlActivitySet) itr.next();
+ if (activitySet.getCreatedBy() != null)
{
- importUsers.add(attachCreatedBy);
+ importUsers.add(activitySet.getCreatedBy());
}
- }
-
- // Validate the activity set's type.
- try
- {
- final ActivitySetType ttOM =
- ActivitySetTypeManager.getInstance(activitySet.getType());
- if (ttOM == null)
+ if (activitySet.getAttachment() != null)
{
- throw new IllegalArgumentException(); //EXCEPTION
+ final String attachCreatedBy = activitySet.getAttachment().getCreatedBy();
+ if (attachCreatedBy != null)
+ {
+ importUsers.add(attachCreatedBy);
+ }
}
- }
- catch (Exception e)
- {
- final String error = Localization.format(
- ScarabConstants.DEFAULT_BUNDLE_NAME,
- getLocale(),
- "CouldNotFindActivitySetType", activitySet.getType());
- importErrors.add(error);
- }
- // Validate the activity set's date.
- validateDate(activitySet.getCreatedDate(), true);
+ // Validate the activity set's type.
+ try
+ {
+ final ActivitySetType ttOM =
+ ActivitySetTypeManager.getInstance(activitySet.getType());
+ if (ttOM == null)
+ {
+ throw new IllegalArgumentException(); //EXCEPTION
+ }
+ }
+ catch (Exception e)
+ {
+ final String error = Localization.format(
+ ScarabConstants.DEFAULT_BUNDLE_NAME,
+ getLocale(),
+ "CouldNotFindActivitySetType", activitySet.getType());
+ importErrors.add(error);
+ }
- final List activities = activitySet.getActivities();
- for (Iterator itrb = activities.iterator(); itrb.hasNext();)
- {
- validateActivity(moduleOM, issueTypeOM, moduleAttributeList,
- activitySet, (XmlActivity) itrb.next());
+ // Validate the activity set's date.
+ validateDate(activitySet.getCreatedDate(), true);
+
+ final List activities = activitySet.getActivities();
+ for (Iterator itrb = activities.iterator(); itrb.hasNext();)
+ {
+ validateActivity(moduleOM, issueTypeOM, moduleAttributeList,
+ activitySet, (XmlActivity) itrb.next());
+ }
}
}
+ catch (Exception e)
+ {
+ final String error = Localization.format(
+ ScarabConstants.DEFAULT_BUNDLE_NAME,
+ getLocale(),
+ "CouldNotFindIssueType", issue.getArtifactType());
+ importErrors.add(error);
+ }
}
/**
@@ -702,11 +728,11 @@
// processing.
if (isDependencyActivity(activity))
{
- if (!isDuplicateDependency(activitySet))
+ if (!isDuplicateDependency(activity))
{
allDependencies.add(activity);
- LOG.debug("-------------Stored Dependency # " +
- allDependencies.size() + "-------------");
+ LOG.debug("+------------Stored Dependency # " +
+ allDependencies.size() + '[' + activity.getDependency() + ']');
}
// Dependency activities don't require further
@@ -752,6 +778,10 @@
(ScarabConstants.DEFAULT_BUNDLE_NAME, getLocale(),
"CouldNotFindAttributeOption", args);
importErrors.add(error);
+
+ AttributeOptionManager.getInstance(
+ attributeOM, activity.getNewOption(),
+ moduleOM, issueTypeOM);
}
// check for module options
try
@@ -874,9 +904,8 @@
// The import data may nominate its ID
if (id != null) {
// This will cause Issue.save() to use this ID
- issueOM.setIdCount(Integer.parseInt(id));
+ issueOM.setFederatedId(id);
}
-
// create the issue in the database
issueOM.save();
@@ -1184,12 +1213,13 @@
// add any dependency activities to a list for later processing
if (isDependencyActivity(activity))
{
- if (!isDuplicateDependency(activitySet))
+ if (!isDuplicateDependency(activity))
{
final Object[] obj = {activitySetOM, activity, activityAttachmentOM};
allDependencies.add(obj);
- dependActivitySetId.add(activitySet.getId());
- LOG.debug("-------------Stored Dependency # " + allDependencies.size() + "-------------");
+ dependActivitySetId.add(activity.getDependency());
+ LOG.debug("-------------Stored Dependency # "
+ + allDependencies.size() + '[' + activity.getDependency() + ']');
continue;
}
}
@@ -1370,9 +1400,9 @@
return (activity.getDependency() != null);
}
- private boolean isDuplicateDependency(final XmlActivitySet activitySet)
+ private boolean isDuplicateDependency(final XmlActivity activity)
{
- return (dependActivitySetId.indexOf(activitySet.getId()) > -1);
+ return dependActivitySetId.contains(activity.getDependency());
}
private Activity createActivity(final XmlActivity activity,
@@ -1500,8 +1530,14 @@
}
private Module getModuleForIssue(final XmlModule module, final XmlIssue issue)
- throws TorqueException
+ throws TorqueException, ScarabException
{
+
+ if(issue.hasModuleCode() && !issue.getModuleCode().equals(module.getCode()) && !allowGlobalImport){
+ throw new ScarabException(
+ new L10NKey("Lacking permission to cross-module import. Contact your administor. <localize me>"));
+ }
+
return issue.hasModuleCode()
? ModuleManager.getInstance(module.getDomain(),
null,issue.getModuleCode())
lmpx.com only provides a reader for public news (NNTP) servers. It is not
affiliated with the servers or forums shown here and is not responsible for
the content of articles, which is written by their respective authors.