@Override public void updateRouteElement(DocumentRouteElement routeElement, CoreSession session) throws DocumentRouteNotLockedException { if (!isLockedByCurrentUser(routeElement.getDocumentRoute(session), session)) { throw new DocumentRouteNotLockedException(); } routeElement.save(session); }
@Override public void lockDocumentRoute(DocumentRoute routeModel, CoreSession session) throws DocumentRouteAlredayLockedException { LockableDocumentRoute lockableRoute = routeModel.getDocument().getAdapter(LockableDocumentRoute.class); boolean lockedByCurrent = isLockedByCurrentUser(routeModel, session); if (lockableRoute.isLocked(session) && !lockedByCurrent) { throw new DocumentRouteAlredayLockedException(); } if (!lockedByCurrent) { lockableRoute.lockDocument(session); } }
@Override public void removeRouteElement(DocumentRouteElement routeElement, CoreSession session) throws DocumentRouteNotLockedException { DocumentRoute parentRoute = routeElement.getDocumentRoute(session); if (!isLockedByCurrentUser(parentRoute, session)) { throw new DocumentRouteNotLockedException(); } session.removeDocument(routeElement.getDocument().getRef()); session.save();// the document will be queried later on }
@Override @Deprecated public void addRouteElementToRoute(DocumentRef parentDocumentRef, int idx, DocumentRouteElement routeElement, CoreSession session) throws DocumentRouteNotLockedException { DocumentRoute route = getParentRouteModel(parentDocumentRef, session); if (!isLockedByCurrentUser(route, session)) { throw new DocumentRouteNotLockedException(); } DocumentModelList children = session.query( String.format(ORDERED_CHILDREN_QUERY, session.getDocument(parentDocumentRef).getId())); DocumentModel sourceDoc; try { sourceDoc = children.get(idx); addRouteElementToRoute(parentDocumentRef, sourceDoc.getName(), routeElement, session); } catch (IndexOutOfBoundsException e) { addRouteElementToRoute(parentDocumentRef, null, routeElement, session); } }
@Override @Deprecated public void addRouteElementToRoute(DocumentRef parentDocumentRef, String sourceName, DocumentRouteElement routeElement, CoreSession session) throws DocumentRouteNotLockedException { DocumentRoute parentRoute = getParentRouteModel(parentDocumentRef, session); if (!isLockedByCurrentUser(parentRoute, session)) { throw new DocumentRouteNotLockedException(); } PathSegmentService pss = Framework.getService(PathSegmentService.class); DocumentModel docRouteElement = routeElement.getDocument(); DocumentModel parentDocument = session.getDocument(parentDocumentRef); docRouteElement.setPathInfo(parentDocument.getPathAsString(), pss.generatePathSegment(docRouteElement)); String lifecycleState = parentDocument.getCurrentLifeCycleState() .equals(DocumentRouteElement.ElementLifeCycleState.draft.name()) ? DocumentRouteElement.ElementLifeCycleState.draft.name() : DocumentRouteElement.ElementLifeCycleState.ready.name(); docRouteElement.putContextData(LifeCycleConstants.INITIAL_LIFECYCLE_STATE_OPTION_NAME, lifecycleState); docRouteElement = session.createDocument(docRouteElement); session.orderBefore(parentDocumentRef, docRouteElement.getName(), sourceName); session.save();// the new document will be queried later on }