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