001/* 002 * (C) Copyright 2006-2013 Nuxeo SA (http://nuxeo.com/) and others. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 * 016 * Contributors: 017 * Nuxeo - initial API and implementation 018 * 019 * $Id$ 020 */ 021 022package org.nuxeo.ecm.core.event.impl; 023 024import org.nuxeo.common.collections.ScopeType; 025import org.nuxeo.common.collections.ScopedMap; 026import org.nuxeo.common.utils.Path; 027import org.nuxeo.ecm.core.api.CoreSession; 028import org.nuxeo.ecm.core.api.DataModel; 029import org.nuxeo.ecm.core.api.DocumentModel; 030import org.nuxeo.ecm.core.api.DocumentRef; 031import org.nuxeo.ecm.core.api.IdRef; 032import org.nuxeo.ecm.core.api.Lock; 033import org.nuxeo.ecm.core.api.PathRef; 034import org.nuxeo.ecm.core.api.PropertyException; 035import org.nuxeo.ecm.core.api.VersioningOption; 036import org.nuxeo.ecm.core.api.model.DocumentPart; 037import org.nuxeo.ecm.core.api.model.Property; 038import org.nuxeo.ecm.core.api.model.PropertyVisitor; 039import org.nuxeo.ecm.core.api.model.resolver.DocumentPropertyObjectResolverImpl; 040import org.nuxeo.ecm.core.api.model.resolver.PropertyObjectResolver; 041import org.nuxeo.ecm.core.api.security.ACP; 042import org.nuxeo.ecm.core.event.Event; 043import org.nuxeo.ecm.core.event.EventBundle; 044import org.nuxeo.ecm.core.schema.DocumentType; 045 046import java.io.Serializable; 047import java.util.Collection; 048import java.util.Map; 049import java.util.Set; 050 051/** 052 * Light weight {@link DocumentModel} implementation Only holds {@link DocumentRef}, RepositoryName, name, path and 053 * context data. Used to reduce memory footprint of {@link Event} stacked in {@link EventBundle}. 054 * 055 * @author Thierry Delprat 056 */ 057public class ShallowDocumentModel implements DocumentModel { 058 059 private static final long serialVersionUID = 1L; 060 061 private final String id; 062 063 private final String repoName; 064 065 private final String name; 066 067 private final Path path; 068 069 private final String type; 070 071 private final boolean isFolder; 072 073 private final boolean isVersion; 074 075 private final boolean isProxy; 076 077 private final boolean isImmutable; 078 079 private final ScopedMap contextData; 080 081 private final Set<String> facets; 082 083 private final String lifecycleState; 084 085 public ShallowDocumentModel(DocumentModel doc) { 086 id = doc.getId(); 087 repoName = doc.getRepositoryName(); 088 name = doc.getName(); 089 path = doc.getPath(); 090 type = doc.getType(); 091 isFolder = doc.isFolder(); 092 isVersion = doc.isVersion(); 093 isProxy = doc.isProxy(); 094 isImmutable = doc.isImmutable(); 095 contextData = doc.getContextData(); 096 facets = doc.getFacets(); 097 if (doc.isLifeCycleLoaded()) { 098 lifecycleState = doc.getCurrentLifeCycleState(); 099 } else { 100 lifecycleState = null; 101 } 102 } 103 104 public ShallowDocumentModel(String id, String repoName, String name, Path path, String type, boolean isFolder, 105 boolean isVersion, boolean isProxy, boolean isImmutable, ScopedMap contextData, Set<String> facets, 106 String lifecycleState) { 107 this.id = id; 108 this.repoName = repoName; 109 this.name = name; 110 this.path = path; 111 this.type = type; 112 this.isFolder = isFolder; 113 this.isVersion = isVersion; 114 this.isProxy = isProxy; 115 this.isImmutable = isImmutable; 116 this.contextData = contextData; 117 this.facets = facets; 118 this.lifecycleState = lifecycleState; 119 } 120 121 @Override 122 public String getId() { 123 return id; 124 } 125 126 @Override 127 public DocumentRef getRef() { 128 return id == null ? null : new IdRef(id); 129 } 130 131 @Override 132 public String getRepositoryName() { 133 return repoName; 134 } 135 136 @Override 137 public String getName() { 138 return name; 139 } 140 141 @Override 142 public Long getPos() { 143 return null; 144 } 145 146 @Override 147 public Path getPath() { 148 return path; 149 } 150 151 @Override 152 public String getPathAsString() { 153 if (path != null) { 154 return path.toString(); 155 } 156 return null; 157 } 158 159 @Override 160 public DocumentRef getParentRef() { 161 if (path != null) { 162 return new PathRef(path.removeLastSegments(1).toString()); 163 } 164 return null; 165 } 166 167 @Override 168 public String getType() { 169 return type; 170 } 171 172 @Override 173 public boolean isFolder() { 174 return isFolder; 175 } 176 177 @Override 178 public boolean isVersion() { 179 return isVersion; 180 } 181 182 @Override 183 public void copyContent(DocumentModel sourceDoc) { 184 throw new UnsupportedOperationException(); 185 } 186 187 @Override 188 public void copyContextData(DocumentModel otherDocument) { 189 throw new UnsupportedOperationException(); 190 } 191 192 @Override 193 public boolean followTransition(String transition) { 194 throw new UnsupportedOperationException(); 195 } 196 197 @Override 198 public ACP getACP() { 199 throw new UnsupportedOperationException(); 200 } 201 202 @Override 203 public void accept(PropertyVisitor visitor, Object arg) { 204 throw new UnsupportedOperationException(); 205 } 206 207 @Override 208 public <T> T getAdapter(Class<T> itf) { 209 throw new UnsupportedOperationException(); 210 } 211 212 @Override 213 public <T> T getAdapter(Class<T> itf, boolean refreshCache) { 214 throw new UnsupportedOperationException(); 215 } 216 217 @Override 218 public Collection<String> getAllowedStateTransitions() { 219 throw new UnsupportedOperationException(); 220 } 221 222 @Override 223 public String getCacheKey() { 224 throw new UnsupportedOperationException(); 225 } 226 227 @Override 228 public ScopedMap getContextData() { 229 return contextData; 230 } 231 232 @Override 233 public Serializable getContextData(ScopeType scope, String key) { 234 if (contextData == null) { 235 return null; 236 } 237 return contextData.getScopedValue(scope, key); 238 } 239 240 @Override 241 public CoreSession getCoreSession() { 242 throw new UnsupportedOperationException(); 243 } 244 245 @Override 246 public void detach(boolean loadAll) { 247 } 248 249 @Override 250 public void attach(String sid) { 251 } 252 253 @Override 254 public String getCurrentLifeCycleState() { 255 return lifecycleState; 256 } 257 258 @Override 259 public DataModel getDataModel(String schema) { 260 throw new UnsupportedOperationException(); 261 } 262 263 @Override 264 public Map<String, DataModel> getDataModels() { 265 throw new UnsupportedOperationException(); 266 } 267 268 @Override 269 public Collection<DataModel> getDataModelsCollection() { 270 throw new UnsupportedOperationException(); 271 } 272 273 @Override 274 public Set<String> getFacets() { 275 return facets; 276 } 277 278 @Override 279 public Set<String> getDeclaredFacets() { 280 throw new UnsupportedOperationException(); 281 } 282 283 @Override 284 public String[] getSchemas() { 285 throw new UnsupportedOperationException(); 286 } 287 288 @Override 289 public String[] getDeclaredSchemas() { 290 throw new UnsupportedOperationException(); 291 } 292 293 @Override 294 public DocumentType getDocumentType() { 295 throw new UnsupportedOperationException(); 296 } 297 298 @Override 299 public String getLifeCyclePolicy() { 300 throw new UnsupportedOperationException(); 301 } 302 303 @Override 304 public String getLock() { 305 throw new UnsupportedOperationException(); 306 } 307 308 @Override 309 public DocumentPart getPart(String schema) { 310 throw new UnsupportedOperationException(); 311 } 312 313 @Override 314 public DocumentPart[] getParts() { 315 throw new UnsupportedOperationException(); 316 } 317 318 @Override 319 public Collection<Property> getPropertyObjects(String schema) { 320 throw new UnsupportedOperationException(); 321 } 322 323 @Override 324 public Map<String, Object> getProperties(String schemaName) { 325 throw new UnsupportedOperationException(); 326 } 327 328 @Override 329 public Property getProperty(String xpath) throws PropertyException { 330 throw new UnsupportedOperationException(); 331 } 332 333 @Override 334 public Object getProperty(String schemaName, String name) { 335 throw new UnsupportedOperationException(); 336 } 337 338 @Override 339 public Property getPropertyObject(String schema, String name) { 340 throw new UnsupportedOperationException(); 341 } 342 343 @Override 344 public Serializable getPropertyValue(String xpath) throws PropertyException { 345 throw new UnsupportedOperationException(); 346 } 347 348 @Override 349 public String getSessionId() { 350 throw new UnsupportedOperationException(); 351 } 352 353 @Override 354 public String getSourceId() { 355 throw new UnsupportedOperationException(); 356 } 357 358 @Override 359 public <T extends Serializable> T getSystemProp(String systemProperty, Class<T> type) { 360 throw new UnsupportedOperationException(); 361 } 362 363 @Override 364 public String getTitle() { 365 throw new UnsupportedOperationException(); 366 } 367 368 @Override 369 public String getVersionLabel() { 370 throw new UnsupportedOperationException(); 371 } 372 373 @Override 374 public String getCheckinComment() { 375 throw new UnsupportedOperationException(); 376 } 377 378 @Override 379 public boolean hasFacet(String facet) { 380 return facets.contains(facet); 381 } 382 383 @Override 384 public boolean hasSchema(String schema) { 385 throw new UnsupportedOperationException(); 386 } 387 388 @Override 389 public boolean addFacet(String facet) { 390 throw new UnsupportedOperationException(); 391 } 392 393 @Override 394 public boolean removeFacet(String facet) { 395 throw new UnsupportedOperationException(); 396 } 397 398 @Override 399 public boolean isDownloadable() { 400 throw new UnsupportedOperationException(); 401 } 402 403 @Override 404 public boolean isLifeCycleLoaded() { 405 return lifecycleState != null; 406 } 407 408 @Override 409 public boolean isLocked() { 410 throw new UnsupportedOperationException(); 411 } 412 413 @Override 414 public boolean isProxy() { 415 return isProxy; 416 } 417 418 @Override 419 public boolean isImmutable() { 420 return isImmutable; 421 } 422 423 @Override 424 public boolean isDirty() { 425 throw new UnsupportedOperationException(); 426 } 427 428 @Override 429 public boolean isVersionable() { 430 throw new UnsupportedOperationException(); 431 } 432 433 @Override 434 public boolean isPrefetched(String xpath) { 435 return false; 436 } 437 438 @Override 439 public boolean isPrefetched(String schemaName, String name) { 440 return false; 441 } 442 443 @Override 444 public void prefetchCurrentLifecycleState(String lifecycle) { 445 throw new UnsupportedOperationException(); 446 } 447 448 @Override 449 public void prefetchLifeCyclePolicy(String lifeCyclePolicy) { 450 throw new UnsupportedOperationException(); 451 } 452 453 @Override 454 public void putContextData(String key, Serializable value) { 455 throw new UnsupportedOperationException(); 456 } 457 458 @Override 459 public void putContextData(ScopeType scope, String key, Serializable value) { 460 throw new UnsupportedOperationException(); 461 } 462 463 @Override 464 public void refresh() { 465 throw new UnsupportedOperationException(); 466 } 467 468 @Override 469 public void refresh(int refreshFlags, String[] schemas) { 470 throw new UnsupportedOperationException(); 471 } 472 473 @Override 474 public void reset() { 475 throw new UnsupportedOperationException(); 476 } 477 478 @Override 479 public void setACP(ACP acp, boolean overwrite) { 480 throw new UnsupportedOperationException(); 481 } 482 483 @Override 484 public void setLock(String key) { 485 throw new UnsupportedOperationException(); 486 } 487 488 @Override 489 public Lock setLock() { 490 throw new UnsupportedOperationException(); 491 } 492 493 @Override 494 public Lock getLockInfo() { 495 throw new UnsupportedOperationException(); 496 } 497 498 @Override 499 public Lock removeLock() { 500 throw new UnsupportedOperationException(); 501 } 502 503 @Override 504 public void setPathInfo(String parentPath, String name) { 505 throw new UnsupportedOperationException(); 506 } 507 508 @Override 509 public void setProperties(String schemaName, Map<String, Object> data) { 510 throw new UnsupportedOperationException(); 511 } 512 513 @Override 514 public void setProperty(String schemaName, String name, Object value) { 515 throw new UnsupportedOperationException(); 516 } 517 518 @Override 519 public void setPropertyValue(String xpath, Serializable value) { 520 throw new UnsupportedOperationException(); 521 } 522 523 @Override 524 public void unlock() { 525 throw new UnsupportedOperationException(); 526 } 527 528 @Override 529 public DocumentModel clone() throws CloneNotSupportedException { 530 throw new CloneNotSupportedException(); 531 } 532 533 @Override 534 public Serializable getContextData(String key) { 535 if (contextData == null) { 536 return null; 537 } 538 return contextData.getScopedValue(key); 539 } 540 541 @Override 542 public boolean isCheckedOut() { 543 throw new UnsupportedOperationException(); 544 } 545 546 @Override 547 public void checkOut() { 548 throw new UnsupportedOperationException(); 549 } 550 551 @Override 552 public DocumentRef checkIn(VersioningOption option, String checkinComment) { 553 throw new UnsupportedOperationException(); 554 } 555 556 @Override 557 public String getVersionSeriesId() { 558 throw new UnsupportedOperationException(); 559 } 560 561 @Override 562 public boolean isLatestVersion() { 563 return false; 564 } 565 566 @Override 567 public boolean isMajorVersion() { 568 return false; 569 } 570 571 @Override 572 public boolean isLatestMajorVersion() { 573 return false; 574 } 575 576 @Override 577 public boolean isVersionSeriesCheckedOut() { 578 return true; 579 } 580 581 @Override 582 public String getChangeToken() { 583 return null; 584 } 585 586 @Override 587 public Map<String, String> getBinaryFulltext() { 588 return null; 589 } 590 591 @Override 592 public PropertyObjectResolver getObjectResolver(String xpath) { 593 return DocumentPropertyObjectResolverImpl.create(this, xpath); 594 } 595 596}