# baseURI: http://topbraid.org/workflowsamples

@prefix dash: <http://datashapes.org/dash#> .
@prefix metadata: <http://topbraid.org/metadata#> .
@prefix owl: <http://www.w3.org/2002/07/owl#> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix edg: <http://edg.topbraid.solutions/model/> .
@prefix sh: <http://www.w3.org/ns/shacl#> .
@prefix teamwork: <http://topbraid.org/teamwork#> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .

teamwork:Approved
  a teamwork:TagStatus ;
  teamwork:editable false ;
  rdfs:label "Approved" ;
.
teamwork:GlossaryReviewWorkflowTemplate
  a teamwork:TagWorkflowTemplate ;
  teamwork:editorWorkflowParticipantProperty edg:subjectMatterExpert ;
  teamwork:initialStatus teamwork:InProgress ;
  teamwork:managerWorkflowParticipantProperty edg:businessSteward ;
  teamwork:managerWorkflowParticipantProperty edg:dataGovernor ;
  teamwork:suitableWorkflowForProjectType edg:GlossaryProjectType ;
  teamwork:transition teamwork:GlossaryReviewWorkflowTemplate-AcceptChangesToProduction ;
  teamwork:transition teamwork:GlossaryReviewWorkflowTemplate-ApproveChanges ;
  teamwork:transition teamwork:GlossaryReviewWorkflowTemplate-MarkAsReviewed ;
  teamwork:transition teamwork:GlossaryReviewWorkflowTemplate-ReStartWork ;
  teamwork:transition teamwork:GlossaryReviewWorkflowTemplate-RequestReview ;
  rdfs:comment "The workflow template is scoped to glossaries only. It uses governance roles for transitions and specifies what roles should have manager and editor access to the working copy. It includes a SME review step. Following this step, business steward may decide to make additional changes and either ask for another review or it may decide to directly change the state to \"approved\"." ;
  rdfs:label "Glossary term review workflow" ;
.
teamwork:GlossaryReviewWorkflowTemplate-AcceptChangesToProduction
  a teamwork:TagStatusTransition ;
  teamwork:fromStatus teamwork:Approved ;
  teamwork:requiredGovernanceRole edg:businessSteward ;
  teamwork:toStatus teamwork:Committed ;
  teamwork:transitionLabel "Accept changes to production" ;
  rdfs:label "Glossary review workflow template-Accept changes to production" ;
  sh:order "0"^^xsd:decimal ;
.
teamwork:GlossaryReviewWorkflowTemplate-ApproveChanges
  a teamwork:TagStatusTransition ;
  teamwork:fromStatus teamwork:Reviewed ;
  teamwork:requiredGovernanceRole edg:businessSteward ;
  teamwork:toStatus teamwork:Approved ;
  teamwork:transitionLabel "Approve changes" ;
  rdfs:label "Glossary review workflow template-Approve changes" ;
  sh:order "1"^^xsd:decimal ;
.
teamwork:GlossaryReviewWorkflowTemplate-MarkAsReviewed
  a teamwork:TagStatusTransition ;
  teamwork:fromStatus teamwork:ReviewRequested ;
  teamwork:requiredGovernanceRole edg:subjectMatterExpert ;
  teamwork:toStatus teamwork:Reviewed ;
  teamwork:transitionLabel "Mark as reviewed" ;
  rdfs:label "Glossary review workflow template-Mark as reviewed" ;
  sh:order "4"^^xsd:decimal ;
.
teamwork:GlossaryReviewWorkflowTemplate-ReStartWork
  a teamwork:TagStatusTransition ;
  teamwork:fromStatus teamwork:Reviewed ;
  teamwork:requiredGovernanceRole edg:businessSteward ;
  teamwork:toStatus teamwork:InProgress ;
  teamwork:transitionLabel "Re-start work" ;
  rdfs:label "Glossary review workflow template-Re-start work" ;
  sh:order "2"^^xsd:decimal ;
.
teamwork:GlossaryReviewWorkflowTemplate-RequestReview
  a teamwork:TagStatusTransition ;
  teamwork:fromStatus teamwork:InProgress ;
  teamwork:requiredGovernanceRole edg:businessSteward ;
  teamwork:toStatus teamwork:ReviewRequested ;
  teamwork:transitionLabel "Request review" ;
  rdfs:label "Glossary review workflow template-Request review" ;
  sh:order "1"^^xsd:decimal ;
.
teamwork:IncrementVersion
  a teamwork:WorkflowStatusEntryScript ;
  dash:js """const currentGraph = teamwork.currentMasterGraph();
const versionPredicate = metadata.version;

const versionTriples = graph.triples(currentGraph, versionPredicate, null);

if (versionTriples.length === 0) {
	const initialVersion = "Version 1";
	graph.transaction(graph.dataGraphURI, `Add initial version: ${initialVersion}`, () => {
		graph.add(currentGraph, versionPredicate, initialVersion);
	});
} else {
	const currentVersionLiteral = versionTriples[0].object;
	const currentVersionString = currentVersionLiteral.value || currentVersionLiteral;

	// Extract version number using regex
	const match = currentVersionString.match(/Version (\\d+)/);
	let nextVersion = 1; //fallback

	if (match) {
		nextVersion = parseInt(match[1], 10) + 1;
	}

	const nextVersionString = `Version ${nextVersion}`;

	graph.transaction(graph.dataGraphURI, `Update version to ${nextVersionString}`, () => {
		graph.remove(currentGraph, versionPredicate, currentVersionLiteral);
		graph.add(currentGraph, versionPredicate, nextVersionString);
	});
}
""" ;
  rdfs:label "Increment Version" ;
.
teamwork:IncrementVersionStatus
  a teamwork:TagStatus ;
  teamwork:faIcon "fa-thumbs-up" ;
  teamwork:statusEntryScript teamwork:IncrementVersion ;
  rdfs:label "Increment version status" ;
.
teamwork:NoReviewWorkflowTemplate
  a teamwork:TagWorkflowTemplate ;
  teamwork:initialStatus teamwork:Uncommitted ;
  teamwork:transition teamwork:NoReviewWorkflowTemplate-CommitChangesToProduction ;
  rdfs:comment "This simple workflow template used by working copies. Initially a working copy is uncommitted. From there it can be committed." ;
  rdfs:label "No review workflow" ;
.
teamwork:NoReviewWorkflowTemplate-CommitChangesToProduction
  a teamwork:TagStatusTransition ;
  teamwork:fromStatus teamwork:Uncommitted ;
  teamwork:toStatus teamwork:Committed ;
  teamwork:transitionLabel "Commit changes to production" ;
  rdfs:label "No review workflow template-Commit changes to production" ;
  sh:order "0"^^xsd:decimal ;
.
teamwork:OpenForVoting
  a teamwork:TagStatus ;
  teamwork:faIcon "fa-question" ;
  rdfs:comment "votes are being accepted." ;
  rdfs:label "Open for Voting" ;
.
teamwork:ReviewRequested
  a teamwork:TagStatus ;
  rdfs:label "Review requested" ;
.
teamwork:ReviewRequiredWorkflowTemplate
  a teamwork:TagWorkflowTemplate ;
  teamwork:initialStatus teamwork:InProgress ;
  teamwork:transition teamwork:ReviewRequiredWorkflowTemplate-AcceptChangesToProduction ;
  teamwork:transition teamwork:ReviewRequiredWorkflowTemplate-AllowFurtherChanges ;
  teamwork:transition teamwork:ReviewRequiredWorkflowTemplate-ApproveChanges ;
  teamwork:transition teamwork:ReviewRequiredWorkflowTemplate-RejectChanges ;
  teamwork:transition teamwork:ReviewRequiredWorkflowTemplate-SubmitForReview ;
  rdfs:comment "The workflow template ensures that there is always a review step. Explicit approval is needed before changes are commited. If review results in rejection of changes, work can be re-started and another review cycle can follow." ;
  rdfs:label "Basic review workflow" ;
.
teamwork:ReviewRequiredWorkflowTemplate-AcceptChangesToProduction
  a teamwork:TagStatusTransition ;
  teamwork:fromStatus teamwork:Approved ;
  teamwork:toStatus teamwork:Committed ;
  teamwork:transitionLabel "Accept changes to production" ;
  rdfs:label "Review required workflow template-Accept changes to production" ;
  sh:order "0"^^xsd:decimal ;
.
teamwork:ReviewRequiredWorkflowTemplate-AllowFurtherChanges
  a teamwork:TagStatusTransition ;
  teamwork:fromStatus teamwork:Rejected ;
  teamwork:toStatus teamwork:InProgress ;
  teamwork:transitionLabel "Allow further changes" ;
  rdfs:label "Review required workflow template-Allow further changes" ;
  sh:order "2"^^xsd:decimal ;
.
teamwork:ReviewRequiredWorkflowTemplate-ApproveChanges
  a teamwork:TagStatusTransition ;
  teamwork:fromStatus teamwork:FrozenForReview ;
  teamwork:requiredGovernanceRole edg:businessSteward ;
  teamwork:toStatus teamwork:Approved ;
  teamwork:transitionLabel "Approve changes" ;
  rdfs:label "Review required workflow template-Approve changes" ;
  sh:order "1"^^xsd:decimal ;
.
teamwork:ReviewRequiredWorkflowTemplate-RejectChanges
  a teamwork:TagStatusTransition ;
  teamwork:fromStatus teamwork:FrozenForReview ;
  teamwork:requiredGovernanceRole edg:businessSteward ;
  teamwork:toStatus teamwork:Rejected ;
  teamwork:transitionLabel "Reject changes" ;
  rdfs:label "Review required workflow template-Reject changes" ;
  sh:order "4"^^xsd:decimal ;
.
teamwork:ReviewRequiredWorkflowTemplate-SubmitForReview
  a teamwork:TagStatusTransition ;
  teamwork:fromStatus teamwork:InProgress ;
  teamwork:requiredTagPermissionRole teamwork:editor ;
  teamwork:toStatus teamwork:FrozenForReview ;
  teamwork:transitionLabel "Submit for review" ;
  rdfs:label "Review required workflow template-Submit for review" ;
  sh:order "1"^^xsd:decimal ;
.
teamwork:ReviewRequiredwithEscalationWorkflowTemplate
  a teamwork:TagWorkflowTemplate ;
  teamwork:initialStatus teamwork:InProgress ;
  teamwork:transition teamwork:ReviewRequiredwithEscalationWorkflowTemplate-AcceptChangesToProduction ;
  teamwork:transition teamwork:ReviewRequiredwithEscalationWorkflowTemplate-AllowFurtherChanges ;
  teamwork:transition teamwork:ReviewRequiredwithEscalationWorkflowTemplate-Approve ;
  teamwork:transition teamwork:ReviewRequiredwithEscalationWorkflowTemplate-ApproveChanges ;
  teamwork:transition teamwork:ReviewRequiredwithEscalationWorkflowTemplate-Escalate ;
  teamwork:transition teamwork:ReviewRequiredwithEscalationWorkflowTemplate-Reject ;
  teamwork:transition teamwork:ReviewRequiredwithEscalationWorkflowTemplate-RejectChanges ;
  teamwork:transition teamwork:ReviewRequiredwithEscalationWorkflowTemplate-SubmitForReview ;
  rdfs:comment "The workflow template ensures that there is always a review step. If review is not completed in 24 hours, escalation happens to the manager of the asset collection. Explicit approval is needed before changes are commited. If review results in rejection of changes, work can be re-started and another review cycle can follow." ;
  rdfs:label "Review with escalation workflow" ;
.
teamwork:ReviewRequiredwithEscalationWorkflowTemplate-AcceptChangesToProduction
  a teamwork:TagStatusTransition ;
  teamwork:fromStatus teamwork:Approved ;
  teamwork:toStatus teamwork:Committed ;
  teamwork:transitionLabel "Accept changes to production" ;
  rdfs:label "Review required with escalation workflow template-Accept changes to production" ;
  sh:order "0"^^xsd:decimal ;
.
teamwork:ReviewRequiredwithEscalationWorkflowTemplate-AllowFurtherChanges
  a teamwork:TagStatusTransition ;
  teamwork:fromStatus teamwork:Rejected ;
  teamwork:requiredGovernanceRole edg:dataGovernor ;
  teamwork:toStatus teamwork:InProgress ;
  teamwork:transitionLabel "Allow further changes" ;
  rdfs:label "Review required with escalation workflow template-Allow further changes" ;
  sh:order "2"^^xsd:decimal ;
.
teamwork:ReviewRequiredwithEscalationWorkflowTemplate-Approve
  a teamwork:TagStatusTransition ;
  teamwork:fromStatus teamwork:Escalated ;
  teamwork:requiredGovernanceRole edg:dataGovernor ;
  teamwork:toStatus teamwork:Approved ;
  teamwork:transitionLabel "Approve" ;
  rdfs:label "Review required with escalation workflow template-Approve" ;
.
teamwork:ReviewRequiredwithEscalationWorkflowTemplate-ApproveChanges
  a teamwork:TagStatusTransition ;
  teamwork:fromStatus teamwork:FrozenForReview ;
  teamwork:requiredGovernanceRole edg:dataProducer ;
  teamwork:toStatus teamwork:Approved ;
  teamwork:transitionLabel "Approve changes" ;
  rdfs:label "Review required with escalation workflow template-Approve changes" ;
  sh:order "1"^^xsd:decimal ;
.
teamwork:ReviewRequiredwithEscalationWorkflowTemplate-Escalate
  a teamwork:TagStatusTransition ;
  teamwork:autoTransitionHours 24 ;
  teamwork:fromStatus teamwork:FrozenForReview ;
  teamwork:toStatus teamwork:Escalated ;
  teamwork:transitionLabel "Escalate" ;
  rdfs:label "Review required with escalation workflow template-Escalate" ;
.
teamwork:ReviewRequiredwithEscalationWorkflowTemplate-Reject
  a teamwork:TagStatusTransition ;
  teamwork:fromStatus teamwork:Escalated ;
  teamwork:requiredGovernanceRole edg:dataGovernor ;
  teamwork:toStatus teamwork:Rejected ;
  teamwork:transitionLabel "Reject" ;
  rdfs:label "Review required with escalation workflow template-Reject" ;
.
teamwork:ReviewRequiredwithEscalationWorkflowTemplate-RejectChanges
  a teamwork:TagStatusTransition ;
  teamwork:fromStatus teamwork:FrozenForReview ;
  teamwork:requiredGovernanceRole edg:dataProducer ;
  teamwork:toStatus teamwork:Rejected ;
  teamwork:transitionLabel "Reject changes" ;
  rdfs:label "Review required with escalation workflow template-Reject changes" ;
  sh:order "4"^^xsd:decimal ;
.
teamwork:ReviewRequiredwithEscalationWorkflowTemplate-SubmitForReview
  a teamwork:TagStatusTransition ;
  teamwork:fromStatus teamwork:InProgress ;
  teamwork:requiredTagPermissionRole teamwork:editor ;
  teamwork:toStatus teamwork:FrozenForReview ;
  teamwork:transitionLabel "Submit for review" ;
  rdfs:label "Review required with escalation workflow template-Submit for review" ;
  sh:order "1"^^xsd:decimal ;
.
teamwork:VersionIncrementWorkflowTemplate
  a teamwork:TagWorkflowTemplate ;
  teamwork:initialStatus teamwork:Uncommitted ;
  teamwork:transition teamwork:VersionIncrementWorkflowTemplate-CommitChangesToProduction ;
  teamwork:transition teamwork:VersionIncrementWorkflowTemplate-IncrementVersion ;
  rdfs:comment "This simple workflow template to demonstrate how to call a transition script. In this case it is to increment the version of the asset collection instance." ;
  rdfs:label "Version increment workflow" ;
.
teamwork:VersionIncrementWorkflowTemplate-CommitChangesToProduction
  a teamwork:TagStatusTransition ;
  teamwork:fromStatus teamwork:IncrementVersionStatus ;
  teamwork:requiredGovernanceRole edg:dataGovernor ;
  teamwork:toStatus teamwork:Committed ;
  teamwork:transitionLabel "Commit changes to production" ;
  rdfs:label "Version increment workflow template - Commit changes to production" ;
  sh:order "0"^^xsd:decimal ;
.
teamwork:VersionIncrementWorkflowTemplate-IncrementVersion
  a teamwork:TagStatusTransition ;
  teamwork:fromStatus teamwork:Uncommitted ;
  teamwork:requiredGovernanceRole edg:dataGovernor ;
  teamwork:toStatus teamwork:IncrementVersionStatus ;
  teamwork:transitionLabel "Increment version" ;
  rdfs:label "Version increment workflow template - Increment version" ;
  sh:order "0"^^xsd:decimal ;
.
teamwork:VotingComplete
  a teamwork:TagStatus ;
  teamwork:faIcon "fas fa-hourglass-end" ;
  rdfs:comment "voting is closed." ;
  rdfs:label "Voting Complete" ;
.
teamwork:VotingWorkflowTemplate
  a teamwork:TagWorkflowTemplate ;
  teamwork:initialStatus teamwork:InProgress ;
  teamwork:managerWorkflowParticipantProperty edg:accountable ;
  teamwork:managerWorkflowParticipantProperty edg:responsible ;
  teamwork:transition teamwork:VotingWorkflowTemplate-AcceptChangesToProduction ;
  teamwork:transition teamwork:VotingWorkflowTemplate-Approve ;
  teamwork:transition teamwork:VotingWorkflowTemplate-Reject ;
  teamwork:transition teamwork:VotingWorkflowTemplate-StartVotingProcess ;
  teamwork:transition teamwork:VotingWorkflowTemplate-Vote ;
  rdfs:comment "The workflow template includes a voting step." ;
  rdfs:label "Voting workflow" ;
.
teamwork:VotingWorkflowTemplate-AcceptChangesToProduction
  a teamwork:TagStatusTransition ;
  teamwork:fromStatus teamwork:Approved ;
  teamwork:requiredGovernanceRole edg:responsible ;
  teamwork:toStatus teamwork:Committed ;
  teamwork:transitionLabel "Accept changes to production" ;
  rdfs:label "Voting workflow template-Accept changes to production" ;
  sh:order "0"^^xsd:decimal ;
.
teamwork:VotingWorkflowTemplate-Approve
  a teamwork:TagStatusTransition ;
  teamwork:fromStatus teamwork:VotingComplete ;
  teamwork:requiredGovernanceRole edg:accountable ;
  teamwork:toStatus teamwork:Approved ;
  teamwork:transitionLabel "Approve" ;
  rdfs:label "Voting workflow template-Approve" ;
  sh:order "1"^^xsd:decimal ;
.
teamwork:VotingWorkflowTemplate-Reject
  a teamwork:TagStatusTransition ;
  teamwork:fromStatus teamwork:VotingComplete ;
  teamwork:requiredGovernanceRole edg:accountable ;
  teamwork:toStatus teamwork:Rejected ;
  teamwork:transitionLabel "Reject" ;
  rdfs:label "Voting workflow template-Reject" ;
  sh:order "2"^^xsd:decimal ;
.
teamwork:VotingWorkflowTemplate-StartVotingProcess
  a teamwork:TagStatusTransition ;
  teamwork:fromStatus teamwork:InProgress ;
  teamwork:requiredGovernanceRole edg:responsible ;
  teamwork:toStatus teamwork:OpenForVoting ;
  teamwork:transitionLabel "Start voting process" ;
  rdfs:label "Voting workflow template-Start voting process" ;
  sh:order "1"^^xsd:decimal ;
.
teamwork:VotingWorkflowTemplate-Vote
  a teamwork:TagStatusTransition ;
  teamwork:fromStatus teamwork:OpenForVoting ;
  teamwork:minVoteCount 2 ;
  teamwork:toStatus teamwork:VotingComplete ;
  teamwork:transitionLabel "Vote" ;
  teamwork:voteAutoTransitions true ;
  teamwork:votingUserGovernanceRole edg:consulted ;
  rdfs:label "Voting workflow template-Vote" ;
  sh:order "4"^^xsd:decimal ;
.
