View Javadoc

1   /*
2    */
3   package com.atlassian.jira.migrate;
4   
5   import java.util.ArrayList;
6   import java.util.Collection;
7   import java.util.Collections;
8   import java.util.Iterator;
9   import java.util.List;
10  
11  import org.apache.log4j.Category;
12  import org.ofbiz.core.entity.GenericEntityException;
13  import org.ofbiz.core.entity.GenericValue;
14  
15  import com.atlassian.jira.ManagerFactory;
16  import com.atlassian.jira.issue.Issue;
17  
18  /**
19   */
20  public abstract class AbstractMigrateTask implements MigrateTask {
21  
22  	private static Category log = Category.getInstance(AbstractMigrateTask.class);
23  
24  	private List errors = new ArrayList();
25  
26  
27  	/**
28  	 * @see com.atlassian.jira.migrate.MigrateTask#migrateIssue(com.atlassian.jira.issue.Issue)
29  	 */
30  	public void migrate() throws Exception {
31  		throw new Exception("migrate not implemented");
32  	}
33  
34  	/**
35  	 * @see com.atlassian.jira.migrate.MigrateTask#migrateIssue(com.atlassian.jira.issue.Issue)
36  	 */
37  	public void migrateIssue(Issue _issue) throws Exception {
38  		throw new Exception("migrateIssue not implemented");
39  	}
40  
41  	/**
42  	 * @see com.atlassian.jira.migrate.MigrateTask#migrateProject(org.ofbiz.core.entity.GenericValue)
43  	 */
44  	public void migrateProject(GenericValue _project) throws Exception {
45  		throw new Exception("migrateProject not implemented");
46  	}
47  
48  
49  	/**
50  	 * @return True is Project assumed as CMM Project
51  	 * @throws GenericEntityException
52  	 */
53  	public Collection getProjectsToMigrate() throws Exception {
54  //		return ManagerFactory.getProjectManager().getProjects();
55  		return Collections.EMPTY_LIST;
56  	}
57  
58  	/**
59  	 * @return True if Project is identified to be migrate   
60  	 * @throws GenericEntityException
61  	 */
62  	public boolean isCandidateForMigration(final GenericValue _project) throws Exception {
63  		return true;
64  	}	
65  
66  	/**
67  	 * @return True if Project is ready to be migrate (All issue may be migrated)   
68  	 * @throws GenericEntityException
69  	 */
70  	public boolean isReadyForMigration(final GenericValue _project) throws Exception {
71  		return true;
72  	}	
73  	
74  	/**
75  	 * @return Project List candidates to Migration
76  	 * @throws GenericEntityException
77  	 */
78  	public Collection getProjectsCandidateForMigration() throws Exception {
79  		Collection projects = getProjectsToMigrate();		
80  		Collection projectsToMigrate = new ArrayList();		
81  
82  		// Verify if each Project has to migrate  
83  		for (Iterator iterator = projects.iterator(); iterator.hasNext();) {
84  			GenericValue project = (GenericValue) iterator.next();
85  			if (isCandidateForMigration(project)) {
86  				log.info("Project " + project.getString("name") + "[" + project.getLong("id") + "] is candidate for migration." );
87  				projectsToMigrate.add(project);
88  			}
89  		}		
90  		return projectsToMigrate;
91  	}
92  
93  	/**
94  	 * @return a collection of errors associated with all Projects migration
95  	 * @throws GenericEntityException
96  	 */
97  	public void migrateProjects() throws Exception {
98  		Collection projects = getProjectsCandidateForMigration();		
99  
100 		// Migrate each candidate Project  
101 		for (Iterator iterator = projects.iterator(); iterator.hasNext();) {
102 			GenericValue project = (GenericValue) iterator.next();
103 			if (isReadyForMigration(project)) {
104 				log.info("Migrating Project " + project.getString("name") + "[" + project.getLong("id") + "]" );
105 				migrateProject(project);
106 			}
107 		}
108 	}
109 	
110 	protected void addError(String error)
111 	{
112 		 errors.add(error);
113 	}
114 
115 	/**
116 	 * Useful for adding a bunch of errors (like from a command) with a prefix
117 	 */
118 	public void addErrors(String prefix, Collection errors)
119 	{
120 		 for (Iterator iterator = errors.iterator(); iterator.hasNext();)
121 		 {
122 			  String errorMessage = (String) iterator.next();
123 			  errors.add(prefix + errorMessage);
124 		 }
125 	}
126 
127 	public void addErrors(Collection errors)
128 	{
129 		 addErrors("", errors);
130 	}
131 
132 	public Collection getErrors()
133 	{
134 		 return errors;
135 	}
136 
137 }