| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
package com.buckosoft.PicMan.business; |
| 9 | |
|
| 10 | |
|
| 11 | |
import java.awt.Dimension; |
| 12 | |
import java.io.File; |
| 13 | |
import java.util.Date; |
| 14 | |
import java.util.Iterator; |
| 15 | |
import java.util.LinkedList; |
| 16 | |
import java.util.List; |
| 17 | |
import java.util.ListIterator; |
| 18 | |
|
| 19 | |
import org.apache.commons.logging.Log; |
| 20 | |
import org.apache.commons.logging.LogFactory; |
| 21 | |
import org.springframework.scheduling.quartz.CronTriggerBean; |
| 22 | |
|
| 23 | |
import com.buckosoft.BSAccount.BSAccountMan; |
| 24 | |
import com.buckosoft.PicMan.business.common.PicManCommonImpl; |
| 25 | |
import com.buckosoft.PicMan.business.mosaic.MosaicMan; |
| 26 | |
import com.buckosoft.PicMan.db.DatabaseFacade; |
| 27 | |
import com.buckosoft.PicMan.domain.Chain; |
| 28 | |
import com.buckosoft.PicMan.domain.Filter; |
| 29 | |
import com.buckosoft.PicMan.domain.JobLogEntry; |
| 30 | |
import com.buckosoft.PicMan.domain.Pic; |
| 31 | |
import com.buckosoft.PicMan.domain.Set; |
| 32 | |
import com.buckosoft.PicMan.domain.SetSize; |
| 33 | |
import com.buckosoft.PicMan.domain.Thumbnail; |
| 34 | |
import com.buckosoft.PicMan.image.PicReader; |
| 35 | |
import com.buckosoft.PicMan.image.ThumbCache; |
| 36 | |
import com.buckosoft.PicMan.util.FilterUtil; |
| 37 | |
import com.buckosoft.PicMan.web.HtmlUtils; |
| 38 | |
import com.buckosoft.PicMan.web.PicFilterWeb; |
| 39 | |
import com.buckosoft.PicMan.web.SetSizeWebTable; |
| 40 | |
|
| 41 | |
|
| 42 | |
|
| 43 | |
|
| 44 | |
|
| 45 | |
|
| 46 | |
public class PicManImpl extends PicManCommonImpl implements PicManFacade { |
| 47 | |
|
| 48 | |
private static final boolean INJECT_ERROR = false; |
| 49 | |
|
| 50 | 0 | protected final Log logger = LogFactory.getLog(getClass()); |
| 51 | |
|
| 52 | |
|
| 53 | |
private CronTriggerBean batchManagerTrigger; |
| 54 | |
|
| 55 | 0 | private PicReader picReader = new PicReader(); |
| 56 | 0 | private PicFilterWeb picFilterWeb = new PicFilterWeb(); |
| 57 | 0 | private SetSizeWebTable setSizeWebTable = new SetSizeWebTable(); |
| 58 | 0 | private HtmlUtils htmlUtils = new HtmlUtils(); |
| 59 | 0 | private BatchManager batchManager = new BatchManager(); |
| 60 | 0 | private ThumbCache thumbCache = new ThumbCache(); |
| 61 | 0 | private ThumbCache mosaicThumbCache = null; |
| 62 | 0 | private MosaicMan mosaicMan = new MosaicMan(); |
| 63 | 0 | private PicImporterImpl picImporter = null; |
| 64 | 0 | private SyncManager_Old syncManager = new SyncManager_Old(); |
| 65 | 0 | private MetaSetChangeAuditor metaSetChangeAuditor = new MetaSetChangeAuditor(); |
| 66 | 0 | private PosterManager posterManager = null; |
| 67 | |
|
| 68 | |
private BSAccountMan bsAccountMan; |
| 69 | |
|
| 70 | 0 | private LinkedList<JobLogEntry> jobLog = new LinkedList<JobLogEntry>(); |
| 71 | |
|
| 72 | 0 | private boolean databaseDEBUG = false; |
| 73 | |
|
| 74 | 0 | public PicManImpl() { |
| 75 | 0 | this.picReader.setPicMan(this); |
| 76 | |
|
| 77 | |
|
| 78 | 0 | this.batchManager.setPicMan(this); |
| 79 | |
|
| 80 | 0 | this.mosaicMan.setPicMan(this); |
| 81 | 0 | this.thumbCache.setPicMan(this); |
| 82 | 0 | this.syncManager.setPicMan(this); |
| 83 | 0 | this.metaSetChangeAuditor.setPicMan(this); |
| 84 | |
|
| 85 | 0 | this.picReader.setThumbCache(this.thumbCache); |
| 86 | |
|
| 87 | |
if (INJECT_ERROR) { |
| 88 | |
Exception e = new Exception("Test"); |
| 89 | |
e.fillInStackTrace(); |
| 90 | |
logger.info(e); |
| 91 | |
addError(e); |
| 92 | |
logger.info("test exception...", e); |
| 93 | |
JobLogEntry jle = new JobLogEntry(); |
| 94 | |
jle.setType(JobLogEntry.DONE); |
| 95 | |
jle.setError(); |
| 96 | |
jle.setEndTime(new Date()); |
| 97 | |
this.addJobToLog(jle); |
| 98 | |
} |
| 99 | 0 | } |
| 100 | |
|
| 101 | |
public DatabaseFacade getDB() { |
| 102 | 0 | return(this.dbf); |
| 103 | |
} |
| 104 | |
|
| 105 | |
public void setBatchManagerTrigger(CronTriggerBean batchManagerTrigger) { |
| 106 | 0 | this.batchManagerTrigger = batchManagerTrigger; |
| 107 | 0 | } |
| 108 | |
|
| 109 | |
|
| 110 | |
|
| 111 | |
|
| 112 | |
public void setPicManDatabase(DatabaseFacade pmdb) { |
| 113 | 0 | super.setPicManDatabase(pmdb); |
| 114 | 0 | this.dbf = pmdb; |
| 115 | 0 | this.dbf.setPicManCommonFacade(this); |
| 116 | 0 | this.dbf.setDEBUG(this.databaseDEBUG); |
| 117 | |
|
| 118 | 0 | this.picFilterWeb.setDatabase(dbf); |
| 119 | 0 | this.setSizeWebTable.setDatabase(dbf); |
| 120 | |
|
| 121 | 0 | this.htmlUtils.setDatabase(dbf); |
| 122 | |
|
| 123 | |
|
| 124 | 0 | this.setupThumbCache(); |
| 125 | 0 | } |
| 126 | |
|
| 127 | |
|
| 128 | |
|
| 129 | |
|
| 130 | |
public void setDEBUGBatchManager(boolean debugFlag) { |
| 131 | 0 | this.batchManager.setDEBUG(debugFlag); |
| 132 | 0 | } |
| 133 | |
|
| 134 | |
|
| 135 | |
|
| 136 | |
|
| 137 | |
public void setDEBUGBatchManagerEntry(boolean debugFlag) { |
| 138 | 0 | this.batchManager.setDEBUGEntry(debugFlag); |
| 139 | 0 | } |
| 140 | |
|
| 141 | |
public void setDEBUGDatabaseImpl(boolean debugFlag) { |
| 142 | 0 | this.databaseDEBUG = debugFlag; |
| 143 | 0 | if (this.dbf != null) |
| 144 | 0 | this.dbf.setDEBUG(debugFlag); |
| 145 | 0 | } |
| 146 | |
|
| 147 | |
|
| 148 | |
|
| 149 | |
|
| 150 | |
public void setDEBUGMosaicMan(boolean debugFlag) { |
| 151 | 0 | this.mosaicMan.setDEBUG(debugFlag); |
| 152 | 0 | } |
| 153 | |
|
| 154 | |
|
| 155 | |
|
| 156 | |
|
| 157 | |
public void setDEBUGMosaicEngine(boolean debugFlag) { |
| 158 | 0 | this.mosaicMan.setDEBUGEngine(debugFlag); |
| 159 | 0 | } |
| 160 | |
|
| 161 | |
|
| 162 | |
|
| 163 | |
|
| 164 | |
|
| 165 | |
public BSAccountMan getBSAccountMan() { |
| 166 | 0 | return bsAccountMan; |
| 167 | |
} |
| 168 | |
|
| 169 | |
|
| 170 | |
|
| 171 | |
|
| 172 | |
public void setBSAccountMan(BSAccountMan bsAccountMan) { |
| 173 | 0 | this.bsAccountMan = bsAccountMan; |
| 174 | 0 | } |
| 175 | |
|
| 176 | |
|
| 177 | |
|
| 178 | |
|
| 179 | |
|
| 180 | |
public Thumbnail getThumbNail(Pic pic, int height) { |
| 181 | 0 | if (this.mosaicThumbCache != null && height <= this.mosaicThumbCache.getCachedHeight()) { |
| 182 | 0 | Thumbnail tn = this.mosaicThumbCache.getThumbNail(pic, height); |
| 183 | 0 | if (tn != null) |
| 184 | 0 | return(tn); |
| 185 | |
} |
| 186 | 0 | return(picReader.getThumbNail(pic, height, null)); |
| 187 | |
} |
| 188 | |
|
| 189 | |
|
| 190 | |
public Thumbnail getThumbNail(Pic pic, int height, String label) { |
| 191 | 0 | if (label == null) |
| 192 | 0 | return(getThumbNail(pic, height)); |
| 193 | 0 | if (this.mosaicThumbCache != null && height <= this.mosaicThumbCache.getCachedHeight()) { |
| 194 | 0 | Thumbnail tn = this.mosaicThumbCache.getThumbNail(pic, height); |
| 195 | 0 | if (tn != null) |
| 196 | 0 | return(tn); |
| 197 | |
} |
| 198 | 0 | return(picReader.getThumbNail(pic, height, label)); |
| 199 | |
} |
| 200 | |
|
| 201 | |
|
| 202 | |
public Thumbnail getMosaicThumbNail(Pic pic, int height) { |
| 203 | 0 | if (this.mosaicThumbCache != null && height <= this.mosaicThumbCache.getCachedHeight()) { |
| 204 | 0 | Thumbnail tn = this.mosaicThumbCache.getThumbNail(pic, height); |
| 205 | 0 | if (tn != null) |
| 206 | 0 | return(tn); |
| 207 | 0 | tn = picReader.getThumbNail(pic, this.mosaicThumbCache.getCachedHeight(), null); |
| 208 | 0 | this.mosaicThumbCache.addToCache(pic, tn); |
| 209 | 0 | tn = this.mosaicThumbCache.getThumbNail(pic, height); |
| 210 | 0 | return(tn); |
| 211 | |
} |
| 212 | |
|
| 213 | |
|
| 214 | 0 | return(picReader.getThumbNail(pic, height, null)); |
| 215 | |
} |
| 216 | |
|
| 217 | |
|
| 218 | |
|
| 219 | |
|
| 220 | |
|
| 221 | |
|
| 222 | |
|
| 223 | |
public ThumbCache getThumbCache() { |
| 224 | 0 | return(this.thumbCache); |
| 225 | |
} |
| 226 | |
|
| 227 | |
|
| 228 | |
|
| 229 | |
|
| 230 | |
|
| 231 | |
public void setupThumbCache() { |
| 232 | 0 | this.thumbCache.setupCache(this.dbf.getSystem().getThumbCacheDirectory(), |
| 233 | 0 | this.dbf.getSystem().getThumbHeight(), |
| 234 | 0 | this.dbf.getSystem().getThumbCacheSize()); |
| 235 | 0 | } |
| 236 | |
|
| 237 | |
|
| 238 | |
|
| 239 | |
|
| 240 | |
|
| 241 | |
|
| 242 | |
|
| 243 | |
public void setupMosaicThumbCache(int sid, int height) { |
| 244 | 0 | if (this.mosaicThumbCache != null && this.mosaicThumbCache.getCachedHeight() == height) |
| 245 | 0 | return; |
| 246 | 0 | this.mosaicThumbCache = new ThumbCache(); |
| 247 | 0 | this.mosaicThumbCache.setPicMan(this); |
| 248 | 0 | this.mosaicThumbCache.setupCache(this.dbf.getSystem().getMosaicThumbCacheDir(), height, Integer.MAX_VALUE); |
| 249 | 0 | this.mosaicThumbCache.setMosaicSet(sid); |
| 250 | 0 | this.mosaicThumbCache.deleteCache(); |
| 251 | |
|
| 252 | 0 | } |
| 253 | |
|
| 254 | |
|
| 255 | |
|
| 256 | |
|
| 257 | |
public void releaseMosaicThumbCache() { |
| 258 | 0 | if (this.mosaicThumbCache != null) |
| 259 | 0 | this.mosaicThumbCache.release(); |
| 260 | 0 | this.mosaicThumbCache = null; |
| 261 | 0 | } |
| 262 | |
|
| 263 | |
|
| 264 | |
|
| 265 | |
|
| 266 | |
public SyncManager_Old getSyncManager() { |
| 267 | 0 | return syncManager; |
| 268 | |
} |
| 269 | |
|
| 270 | |
|
| 271 | |
|
| 272 | |
|
| 273 | |
public LinkedList<JobLogEntry> getJobLog() { |
| 274 | 0 | return jobLog; |
| 275 | |
} |
| 276 | |
|
| 277 | |
|
| 278 | |
|
| 279 | |
|
| 280 | |
public int getJobLogMaxCount() { |
| 281 | 0 | return(10); |
| 282 | |
} |
| 283 | |
|
| 284 | |
|
| 285 | |
|
| 286 | |
|
| 287 | |
public void addJobToLog(JobLogEntry jle) { |
| 288 | 0 | ListIterator<JobLogEntry> liter = jobLog.listIterator(); |
| 289 | 0 | while (liter.hasNext()) { |
| 290 | 0 | JobLogEntry ojle = liter.next(); |
| 291 | |
|
| 292 | 0 | if (jle.getSerial() == ojle.getSerial()) { |
| 293 | 0 | liter.set(jle); |
| 294 | 0 | return; |
| 295 | |
} |
| 296 | 0 | } |
| 297 | 0 | jobLog.addFirst(jle); |
| 298 | 0 | } |
| 299 | |
|
| 300 | |
|
| 301 | |
|
| 302 | |
|
| 303 | |
|
| 304 | |
|
| 305 | |
|
| 306 | |
|
| 307 | |
public String getPicFilterWebEdit(String picName) { |
| 308 | 0 | return(picFilterWeb.getFilterEdit(picName)); |
| 309 | |
} |
| 310 | |
|
| 311 | |
|
| 312 | |
|
| 313 | |
|
| 314 | |
@Deprecated |
| 315 | |
public String getSetSizeWebTable(List<SetSize> setSizeList, boolean showUnused) { |
| 316 | 0 | return(this.setSizeWebTable.getSetSizeWebTable(setSizeList, showUnused)); |
| 317 | |
} |
| 318 | |
|
| 319 | |
|
| 320 | |
|
| 321 | |
|
| 322 | |
public String getContactSelectorHtml(Chain chain, String setName, String uri) { |
| 323 | 0 | return(this.htmlUtils.getContactSelectorHtml(chain, setName, uri)); |
| 324 | |
} |
| 325 | |
|
| 326 | |
|
| 327 | |
|
| 328 | |
|
| 329 | |
public String getSetSizeCheckboxesHtml(Chain chain) { |
| 330 | 0 | return(this.htmlUtils.getSetSizeCheckboxesHtml(chain)); |
| 331 | |
} |
| 332 | |
|
| 333 | |
|
| 334 | |
|
| 335 | |
|
| 336 | |
|
| 337 | |
|
| 338 | |
|
| 339 | |
|
| 340 | |
public void runBatchManager() throws Exception { |
| 341 | 0 | batchManager.run(); |
| 342 | 0 | } |
| 343 | |
|
| 344 | |
|
| 345 | |
|
| 346 | |
|
| 347 | |
public BatchManager getBatchManager() { |
| 348 | 0 | return(this.batchManager); |
| 349 | |
} |
| 350 | |
|
| 351 | |
|
| 352 | |
|
| 353 | |
|
| 354 | |
public String engineRunningShortStatus() { |
| 355 | 0 | return(batchManager.engineRunningShortStatus()); |
| 356 | |
} |
| 357 | |
|
| 358 | |
|
| 359 | |
|
| 360 | |
|
| 361 | |
public void setEngineCronExpression(String expression) { |
| 362 | |
try { |
| 363 | 0 | batchManagerTrigger.setCronExpression(expression); |
| 364 | 0 | } catch (Exception ex) { |
| 365 | 0 | Exception e1 = new Exception("setEngineCronExpression threw exception", ex); |
| 366 | 0 | e1.fillInStackTrace(); |
| 367 | 0 | logger.info(e1); |
| 368 | 0 | addError(e1); |
| 369 | 0 | } |
| 370 | 0 | } |
| 371 | |
|
| 372 | |
|
| 373 | |
|
| 374 | |
|
| 375 | |
|
| 376 | |
|
| 377 | |
|
| 378 | |
|
| 379 | |
|
| 380 | |
|
| 381 | |
|
| 382 | |
|
| 383 | |
|
| 384 | |
|
| 385 | |
|
| 386 | |
public Filter getMaskedFilter(List<Set> sets, Filter filter) { |
| 387 | 0 | Filter f = new Filter(); |
| 388 | 0 | f.setPicName(filter.getPicName()); |
| 389 | |
|
| 390 | 0 | f.setTime(filter.getDate()); |
| 391 | |
|
| 392 | 0 | List<Integer> sizes = dbf.getSizes(); |
| 393 | 0 | Iterator<Set> setIter = sets.iterator(); |
| 394 | 0 | while (setIter.hasNext()) { |
| 395 | 0 | Set set = setIter.next(); |
| 396 | 0 | Iterator<Integer> sizeIter = sizes.iterator(); |
| 397 | 0 | String s = set.getName(); |
| 398 | 0 | while (sizeIter.hasNext()) { |
| 399 | 0 | int size = sizeIter.next().intValue(); |
| 400 | 0 | int v = filter.getFilter(s, size); |
| 401 | 0 | if (v != 0) |
| 402 | 0 | f.addFilter(s, size, v); |
| 403 | 0 | } |
| 404 | 0 | } |
| 405 | 0 | return(f); |
| 406 | |
} |
| 407 | |
|
| 408 | |
|
| 409 | |
|
| 410 | |
|
| 411 | |
public Thumbnail getTestMosaicThumbNail(Pic pic, int height, int depth) { |
| 412 | 0 | return(this.mosaicMan.getMosaicManDevelopment().getMosaicThumbNail(pic, height, depth)); |
| 413 | |
} |
| 414 | |
|
| 415 | |
|
| 416 | |
|
| 417 | |
|
| 418 | |
public Dimension determinePicSize(Pic pic) { |
| 419 | 0 | return(this.picReader.determinePicSize(pic)); |
| 420 | |
} |
| 421 | |
|
| 422 | |
|
| 423 | |
|
| 424 | |
|
| 425 | |
public MosaicMan getMosaicMan() { |
| 426 | 0 | return mosaicMan; |
| 427 | |
} |
| 428 | |
|
| 429 | |
|
| 430 | |
|
| 431 | |
|
| 432 | |
public PicImporter getPicImporter() { |
| 433 | 0 | if (picImporter == null) { |
| 434 | 0 | picImporter = new PicImporterImpl(); |
| 435 | 0 | picImporter.setPicMan(this); |
| 436 | |
} |
| 437 | 0 | return(picImporter); |
| 438 | |
} |
| 439 | |
|
| 440 | |
|
| 441 | |
|
| 442 | |
|
| 443 | |
public PicReader getPicReader() { |
| 444 | 0 | return(picReader); |
| 445 | |
} |
| 446 | |
|
| 447 | |
|
| 448 | |
|
| 449 | |
|
| 450 | |
public int getFilesInDirCount(int rid, String dir) { |
| 451 | 0 | return(this.picReader.getFilesInDirCount(rid, dir)); |
| 452 | |
} |
| 453 | |
|
| 454 | |
|
| 455 | |
|
| 456 | |
|
| 457 | |
public List<String> getDirsInDir(int rid, String subDir) { |
| 458 | 0 | List<String> list = new LinkedList<String>(); |
| 459 | 0 | String dir = this.getDB().getRoot(rid).getPath(); |
| 460 | 0 | if (subDir == null) |
| 461 | 0 | subDir = "."; |
| 462 | 0 | File file = new File(dir, subDir); |
| 463 | 0 | File[] l = file.listFiles(); |
| 464 | 0 | if (l == null) |
| 465 | 0 | return(list); |
| 466 | 0 | for (int i=0; i<l.length; i++) { |
| 467 | 0 | if (l[i].isDirectory()) { |
| 468 | 0 | if (l[i].getName().startsWith(".")) |
| 469 | 0 | continue; |
| 470 | 0 | list.add(l[i].getName()); |
| 471 | |
} |
| 472 | |
} |
| 473 | 0 | return(list); |
| 474 | |
} |
| 475 | |
|
| 476 | |
|
| 477 | |
|
| 478 | |
|
| 479 | |
|
| 480 | |
@Override |
| 481 | |
public String getFilterAsString(String picName) { |
| 482 | 0 | return(FilterUtil.getFilterAsString(this, picName)); |
| 483 | |
} |
| 484 | |
|
| 485 | |
|
| 486 | |
|
| 487 | |
|
| 488 | |
public boolean isEngineOn() { |
| 489 | 0 | return(this.getDB().getSystem().isEngineOn()); |
| 490 | |
} |
| 491 | |
|
| 492 | |
|
| 493 | |
|
| 494 | |
|
| 495 | |
@Override |
| 496 | |
public PosterManager getPosterManager() { |
| 497 | 0 | if (posterManager == null) { |
| 498 | 0 | posterManager = new PosterManager(); |
| 499 | 0 | posterManager.setPicMan(this); |
| 500 | |
} |
| 501 | 0 | return(this.posterManager); |
| 502 | |
} |
| 503 | |
|
| 504 | |
} |