/** * Unmoves document from the trash. * <p> * Also fires async events to untrash the children. * * @param doc the document to untrash * @since 10.1 */ default void untrashDocument(DocumentModel doc) { untrashDocuments(Collections.singletonList(doc)); }
/** * Is document purgeable/untrashable? * <p> * Documents need to be in the trash for this to be true, in addition to the standard permission checks. * * @param doc the document * @param principal the current user (to check locks) * @return {@code true} if the documents are purgeable/untrashable */ default boolean canPurgeOrUntrash(DocumentModel doc, NuxeoPrincipal principal) { return canPurgeOrUntrash(Collections.singletonList(doc), principal); }
/** * Moves document to the trash. * <p> * Do nothing if the document current state is trashed. * <p> * Proxies are removed. * <p> * Since 10.3, sublevels are trashed asynchronously using BAF. * * @param doc the document to trash * @since 10.1 */ default void trashDocument(DocumentModel doc) { trashDocuments(Collections.singletonList(doc)); }
protected void visitExpressionIsTrashed(Expression node) { TrashService trashService = Framework.getService(TrashService.class); if (trashService.hasFeature(TRASHED_STATE_IS_DEDUCED_FROM_LIFECYCLE)) { visitExpressionIsTrashedOnLifeCycle(node); } else if (trashService.hasFeature(TRASHED_STATE_IN_MIGRATION)) { visitExpressionIsTrashedOnLifeCycle(node); buf.append(" OR "); visitExpressionWhereFalseMayBeNull(node); } else if (trashService.hasFeature(TRASHED_STATE_IS_DEDICATED_PROPERTY)) { visitExpressionWhereFalseMayBeNull(node); } else { throw new UnsupportedOperationException("TrashService is in an unknown state"); } }
boolean deleteTransitions = LifeCycleConstants.DELETE_TRANSITION.equals(transition) || LifeCycleConstants.UNDELETE_TRANSITION.equals(transition); if (deleteTransitions && !trashService.hasFeature(TRASHED_STATE_IS_DEDUCED_FROM_LIFECYCLE) && !Boolean.TRUE.equals(options.get(FROM_LIFE_CYCLE_TRASH_SERVICE))) { String message = "Following the transition '" + transition + "' is deprecated. Please use TrashService."; trashService.trashDocument(docModel); } else { trashService.untrashDocument(docModel);
protected void setDeleteState(DocumentModel doc) { Framework.getService(TrashService.class).trashDocument(doc); }
@OperationMethod(collector = DocumentModelCollector.class) public DocumentModel run(DocumentModel doc) { if (trashService.canPurgeOrUntrash(doc, session.getPrincipal())) { trashService.untrashDocument(doc); return session.getDocument(doc.getRef()); } else { throw new NuxeoException("Cannot untrash these documents", SC_FORBIDDEN); } }
@Override public boolean hasFeature(Feature feature) { switch (feature) { case TRASHED_STATE_IS_DEDUCED_FROM_LIFECYCLE: case TRASHED_STATE_IN_MIGRATION: return false; case TRASHED_STATE_IS_DEDICATED_PROPERTY: return true; default: throw new UnsupportedOperationException(feature.name()); } }
@Override public boolean isTrashed(DocumentRef docRef) { return Framework.getService(TrashService.class).isTrashed(this, docRef); }
@OperationMethod() public void run() { trashService.purgeDocumentsUnder(parent); }
@Override public void write(JsonGenerator jg, DocumentModel document) throws IOException { TrashService trashService = Framework.getService(TrashService.class); try (SessionWrapper wrapper = ctx.getSession(document)) { DocumentModel above = trashService.getAboveDocument(document, wrapper.getSession().getPrincipal()); if (above != null) { writeEntityField(NAME, above, jg); } } }
if (trashService.hasFeature(Feature.TRASHED_STATE_IS_DEDUCED_FROM_LIFECYCLE)) { filter = QueryBuilders.termQuery(NXQL.ECM_LIFECYCLESTATE, LifeCycleConstants.DELETED_STATE); } else if (trashService.hasFeature(Feature.TRASHED_STATE_IN_MIGRATION)) { filter = QueryBuilders.boolQuery() .should(QueryBuilders.termQuery(NXQL.ECM_LIFECYCLESTATE, LifeCycleConstants.DELETED_STATE)) .should(QueryBuilders.termQuery(name, true)); } else if (trashService.hasFeature(Feature.TRASHED_STATE_IS_DEDICATED_PROPERTY)) { filter = QueryBuilders.termQuery(name, true);
@Override public void removeItem(DocumentRef ref) { DocumentModel doc = getSession().getDocument(ref); if (doc != null) { if (isTemporaryFile(doc)) { session.removeDocument(ref); } else { getTrashService().trashDocuments(Arrays.asList(doc)); } } else { log.warn("Can't move document " + ref.toString() + " to trash. Document did not found."); } }
@OperationMethod public DocumentModel run(DocumentModel doc) { trashService.trashDocument(doc); // return doc with updated deleted markers return session.getDocument(doc.getRef()); }
@Override public boolean hasFeature(Feature feature) { switch (feature) { case TRASHED_STATE_IS_DEDUCED_FROM_LIFECYCLE: return true; case TRASHED_STATE_IN_MIGRATION: case TRASHED_STATE_IS_DEDICATED_PROPERTY: return false; default: throw new UnsupportedOperationException(feature.name()); } }
if (trashService.hasFeature(TRASHED_STATE_IS_DEDICATED_PROPERTY) || trashService.hasFeature(TRASHED_STATE_IN_MIGRATION)) {
@OperationMethod public DocumentModelList run(DocumentModelList docs) { trashService.trashDocuments(docs); // return docs with updated deleted markers DocumentModelList result = new DocumentModelListImpl(); for (DocumentModel doc : docs) { if (session.exists(doc.getRef())) { result.add(session.getDocument(doc.getRef())); } } return result; }
@Override public boolean hasFeature(Feature feature) { switch (feature) { case TRASHED_STATE_IN_MIGRATION: return true; case TRASHED_STATE_IS_DEDUCED_FROM_LIFECYCLE: case TRASHED_STATE_IS_DEDICATED_PROPERTY: return false; default: throw new UnsupportedOperationException(feature.name()); } }
protected Document walkIsTrashed(Operator op, Operand rvalue) { if (op != Operator.EQ && op != Operator.NOTEQ) { throw new QueryParseException(NXQL.ECM_ISTRASHED + " requires = or <> operator"); } TrashService trashService = Framework.getService(TrashService.class); if (trashService.hasFeature(TRASHED_STATE_IS_DEDUCED_FROM_LIFECYCLE)) { return walkIsTrashed(new Reference(NXQL.ECM_LIFECYCLESTATE), op, rvalue, new StringLiteral(LifeCycleConstants.DELETED_STATE)); } else if (trashService.hasFeature(TRASHED_STATE_IN_MIGRATION)) { Document lifeCycleTrashed = walkIsTrashed(new Reference(NXQL.ECM_LIFECYCLESTATE), op, rvalue, new StringLiteral(LifeCycleConstants.DELETED_STATE)); Document propertyTrashed = walkIsTrashed(new Reference(NXQL.ECM_ISTRASHED), op, rvalue, new BooleanLiteral(true)); return new Document(QueryOperators.OR, new ArrayList<>(Arrays.asList(lifeCycleTrashed, propertyTrashed))); } else if (trashService.hasFeature(TRASHED_STATE_IS_DEDICATED_PROPERTY)) { return walkIsTrashed(new Reference(NXQL.ECM_ISTRASHED), op, rvalue, new BooleanLiteral(true)); } else { throw new UnsupportedOperationException("TrashService is in an unknown state"); } }
protected Boolean walkIsTrashed(Operator op, Operand rvalue) { if (op != Operator.EQ && op != Operator.NOTEQ) { throw new QueryParseException(NXQL.ECM_ISTRASHED + " requires = or <> operator"); } TrashService trashService = Framework.getService(TrashService.class); if (trashService.hasFeature(TRASHED_STATE_IS_DEDUCED_FROM_LIFECYCLE)) { return walkIsTrashed(new Reference(NXQL.ECM_LIFECYCLESTATE), op, rvalue, new StringLiteral(LifeCycleConstants.DELETED_STATE)); } else if (trashService.hasFeature(TRASHED_STATE_IN_MIGRATION)) { Boolean lifeCycleTrashed = walkIsTrashed(new Reference(NXQL.ECM_LIFECYCLESTATE), op, rvalue, new StringLiteral(LifeCycleConstants.DELETED_STATE)); Boolean propertyTrashed = walkIsTrashed(new Reference(NXQL.ECM_ISTRASHED), op, rvalue, new IntegerLiteral(1L)); return or(lifeCycleTrashed, propertyTrashed); } else if (trashService.hasFeature(TRASHED_STATE_IS_DEDICATED_PROPERTY)) { return walkIsTrashed(new Reference(NXQL.ECM_ISTRASHED), op, rvalue, new IntegerLiteral(1L)); } else { throw new UnsupportedOperationException("TrashService is in an unknown state"); } }