Changeset 3958
- Timestamp:
- Nov 5, 2010, 12:09:35 PM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/plugin/src/org/proteios/plugins/ProjectToTrash.java
r3445 r3958 53 53 import org.proteios.core.query.Restrictions; 54 54 55 import java.util.ArrayList; 55 56 import java.util.List; 56 57 … … 63 64 extends AbstractPlugin 64 65 { 66 /** 67 * Logger used. Used to log specific events. 68 */ 69 protected static final org.apache.log4j.Logger log = org.apache.log4j.LogManager 70 .getLogger("org.proteios.io"); 71 65 72 public MainType getMainType() 66 73 { … … 94 101 int jobCount = 0, hitCount = 0, featureCount = 0, ssCount = 0, fileCount = 0, dirCount = 0; 95 102 Project project = (Project) job.getValue("project"); 96 // Only needed if the project wasn't active when the job was 97 // created: 103 // Only needed if the project wasn't active when the job was created: 98 104 sc.setActiveProject(project); 99 105 DbControl dc = sc.newDbControl(); 100 dc.reattachItem(project); 106 //dc.reattachItem(project); 107 project = Project.getById(dc, project.getId()); 101 108 int project_id = sc.getActiveProjectId(); 102 109 /* Check that the feature file hasn't been imported already */ … … 110 117 for (Hit hit : hitList) 111 118 { 112 dc.reattachItem(hit);113 119 dc.deleteItem(hit); 114 120 hitCount++; … … 120 126 for (Feature feat : featureList) 121 127 { 122 dc.reattachItem(feat);123 128 dc.deleteItem(feat); 124 129 featureCount++; … … 130 135 for (Job job : jobList) 131 136 { 132 dc.reattachItem(job);133 137 job.setRemoved(true); 134 138 jobCount++; … … 140 144 for (SpectrumSearch ss : spectrumSearchList) 141 145 { 142 dc.reattachItem(ss);143 146 ss.setRemoved(true); 144 147 ssCount++; … … 147 150 fileQuery.exclude(Include.MINE, Include.OTHERS); 148 151 fileQuery.include(Include.IN_PROJECT); 149 List<File> fileList = fileQuery.list(dc); 152 List<File> fileItemResultList = fileQuery.list(dc); 153 log.debug("ProjectToTrash: fileItemResultList.size() = " + fileItemResultList.size() + " fileList = " + fileItemResultList); 154 // 155 Directory projDir = project.getProjectDirectory(); 156 List<Directory> dirList = new ArrayList<Directory>(); 157 dirList = directoryTree(dc, dirList, projDir); 158 log.debug("ProjectToTrash: dirList.size() = " + dirList.size() + " dirList = " + dirList); 159 // 160 List<File> fileList = new ArrayList<File>(); 161 fileList = filesInDirectories(dc, dirList); 162 log.debug("ProjectToTrash: fileList.size() = " + fileList.size() + " fileList = " + fileList); 150 163 for (File f : fileList) 151 164 { 152 dc.reattachItem(f);165 //dc.reattachItem(f); 153 166 f.setRemoved(true); 154 167 fileCount++; … … 157 170 dirQuery.exclude(Include.MINE, Include.OTHERS); 158 171 dirQuery.include(Include.IN_PROJECT); 159 List<Directory> dirList = dirQuery.list(dc); 160 Directory projDir = project.getProjectDirectory(); 172 List<Directory> dirItemResultList = dirQuery.list(dc); 173 log.debug("ProjectToTrash: dirItemResultList.size() = " + dirItemResultList.size()); 174 // Set no active project 175 log.debug("ProjectToTrash: active project set to null"); 176 sc.setActiveProject(null); 161 177 if (!dirList.contains(projDir)) 162 178 { 163 // Doesn't work to reattach for some reason179 log.debug("ProjectToTrash: projDir.getName() = \"" + projDir.getName() + "\" set to removed"); 164 180 projDir.setRemoved(true); 165 181 dirCount++; … … 167 183 for (Directory d : dirList) 168 184 { 169 dc.reattachItem(d);185 log.debug("ProjectToTrash: d.getName() = \"" + d.getName() + "\" set to removed"); 170 186 d.setRemoved(true); 171 187 dirCount++; 172 188 } 173 project.setClosed(true); 174 /** 175 * Don't delete, just close. 176 */ 177 // project.setRemoved(true); 189 project.setRemoved(true); 178 190 dc.commit(); 179 191 response … … 181 193 } 182 194 } 195 196 197 /** 198 * Obtains a list of all directories that have the start directory as ancestor. 199 * 200 * @param dc DbControl The DbControl to use. 201 * @param dirList List<Directory> The directory list that will be appended with found directories. 202 * @param startDir Directory The start directory for the search. 203 * @return List<Directory> The directory list updated with found directories. 204 */ 205 private List<Directory> directoryTree(DbControl dc, List<Directory> dirList, Directory startDir) 206 { 207 if (startDir != null) 208 { 209 // Find sub-directories to start directory 210 ItemQuery<Directory> dirQuery = startDir.getSubDirectories(); 211 /* 212 if (sc.getActiveProjectId() > 0) 213 { 214 dirQuery.include(Include.IN_PROJECT); 215 } 216 */ 217 List<Directory> tmpList = dirQuery.list(dc); 218 // Add sub-directories to directory list 219 for (Directory dir: tmpList) 220 { 221 // Add directory to dirList, if not already in list 222 if (!dirList.contains(dir)) 223 { 224 dirList.add(dir); 225 } 226 // Add directories in sub-directory to directory list 227 dirList = directoryTree(dc, dirList, dir); 228 } 229 } 230 return dirList; 231 } 232 233 234 /** 235 * Obtains a list of all files in a list of directories. 236 * 237 * @param dc DbControl The DbControl to use. 238 * @param dirList List<Directory> The directory list. 239 * @return List<File> The file list updated with found files. 240 */ 241 private List<File> filesInDirectories(DbControl dc, List<Directory> dirList) 242 { 243 List<File> fileList = new ArrayList<File>(); 244 for (Directory dir: dirList) 245 { 246 ItemQuery<File> fileQuery = dir.getFileQuery(); 247 List<File> tmpList = fileQuery.list(dc); 248 for (File file: tmpList) 249 { 250 // Add file to fileList, if not already in list 251 if (!fileList.contains(file)) 252 { 253 fileList.add(file); 254 } 255 } 256 } 257 return fileList; 258 } 183 259 }
Note: See TracChangeset
for help on using the changeset viewer.