@Override public String getLifeCycleState() { return target.getLifeCycleState(); }
protected void followTransitionByOption(CoreSession session, Document doc, Map<String, Serializable> options) { String lifecycleState = doc.getLifeCycleState(); if ((APPROVED_STATE.equals(lifecycleState) || OBSOLETE_STATE.equals(lifecycleState)) && doc.getAllowedStateTransitions().contains(BACK_TO_PROJECT_TRANSITION)) { doc.followTransition(BACK_TO_PROJECT_TRANSITION); if (session != null) { // Send an event to notify that the document state has changed sendEvent(session, doc, lifecycleState, options); } } }
@Override public String getCurrentLifeCycleState(DocumentRef docRef) { Document doc = resolveReference(docRef); checkPermission(doc, READ_LIFE_CYCLE); return doc.getLifeCycleState(); }
protected List<VersioningOption> getSaveOptions(Document doc) { boolean versionable = doc.getType().getFacets().contains(FacetNames.VERSIONABLE); String lifeCycleState; try { lifeCycleState = doc.getLifeCycleState(); } catch (LifeCycleException e) { lifeCycleState = null; } String type = doc.getType().getName(); return getSaveOptions(versionable, lifeCycleState, type); }
protected VersioningOption validateOption(Document doc, VersioningOption option) { List<VersioningOption> options = getSaveOptions(doc); // some variables for exceptions String type = doc.getType().getName(); String lifeCycleState; try { lifeCycleState = doc.getLifeCycleState(); } catch (LifeCycleException e) { lifeCycleState = null; } if (option == null) { if (options.isEmpty() || options.contains(NONE)) { // Valid cases: // - we don't ask for a version and versioning is blocked by configuration // - we don't ask for a version and NONE is available as restriction return NONE; } else { // No version is asked but configuration requires that document must be versioned ie: NONE doesn't // appear in restriction contribution throw new NuxeoException("Versioning configuration restricts documents with type=" + type + "/lifeCycleState=" + lifeCycleState + " must be versioned for each updates."); } } else if (!options.contains(option)) { throw new NuxeoException("Versioning option=" + option + " is not allowed by the configuration for type=" + type + "/lifeCycleState=" + lifeCycleState); } return option; }
@Override public void followTransition(Document doc, String transitionName) throws LifeCycleException { String lifeCycleState = doc.getLifeCycleState(); LifeCycle lifeCycle = getLifeCycleFor(doc); if (lifeCycle != null && lifeCycle.getAllowedStateTransitionsFrom(lifeCycleState).contains(transitionName)) { String destinationStateName = lifeCycle.getTransitionByName(transitionName).getDestinationStateName(); doc.setCurrentLifeCycleState(destinationStateName); } else { throw new LifeCycleException( "Not allowed to follow transition <" + transitionName + "> from state <" + lifeCycleState + '>'); } }
String formerStateName = doc.getLifeCycleState(); doc.followTransition(transition); eventOptions.put(LifeCycleConstants.TRANSTION_EVENT_OPTION_TO, doc.getLifeCycleState()); eventOptions.put(LifeCycleConstants.TRANSTION_EVENT_OPTION_TRANSITION, transition); String comment = (String) options.get("comment");
refresh.lifeCycleState = doc.getLifeCycleState(); refresh.lifeCyclePolicy = doc.getLifeCyclePolicy(); refresh.isCheckedOut = doc.isCheckedOut();
protected void sendEvent(CoreSession session, Document doc, String previousLifecycleState, Map<String, Serializable> options) { String sid = session.getSessionId(); DocumentModel docModel = DocumentModelFactory.createDocumentModel(doc, sid, null); DocumentEventContext ctx = new DocumentEventContext(session, session.getPrincipal(), docModel); ctx.setProperty(TRANSTION_EVENT_OPTION_FROM, previousLifecycleState); ctx.setProperty(TRANSTION_EVENT_OPTION_TO, doc.getLifeCycleState()); ctx.setProperty(TRANSTION_EVENT_OPTION_TRANSITION, BACK_TO_PROJECT_TRANSITION); ctx.setProperty(REPOSITORY_NAME, session.getRepositoryName()); ctx.setProperty(SESSION_ID, sid); ctx.setProperty(DOC_LIFE_CYCLE, BACK_TO_PROJECT_TRANSITION); ctx.setProperty(CATEGORY, DocumentEventCategories.EVENT_LIFE_CYCLE_CATEGORY); ctx.setProperty(COMMENT, options.get(COMMENT)); Framework.getService(EventService.class).fireEvent(ctx.newEvent(TRANSITION_EVENT)); }
String lifeCycleState = doc.getLifeCycleState(); docModel.prefetchCurrentLifecycleState(lifeCycleState); String lifeCyclePolicy = doc.getLifeCyclePolicy();