Search in sources :

Example 1 with WorkflowCheckState

use of com.enonic.xp.content.WorkflowCheckState in project xp by enonic.

the class ContentServiceImplTest_versions method version_workflow_info.

@Test
public void version_workflow_info() throws Exception {
    final Map<String, WorkflowCheckState> checks = Map.of("checkName1", WorkflowCheckState.APPROVED, "checkName2", WorkflowCheckState.PENDING);
    final WorkflowInfo workflowInfo = WorkflowInfo.create().state(WorkflowState.IN_PROGRESS).checks(checks).build();
    final Content content = this.contentService.create(CreateContentParams.create().contentData(new PropertyTree()).displayName("This is my test content").parent(ContentPath.ROOT).name("myContent").type(ContentTypeName.folder()).workflowInfo(workflowInfo).build());
    final FindContentVersionsResult versions = this.contentService.getVersions(FindContentVersionsParams.create().contentId(content.getId()).build());
    final ContentVersion contentVersion = versions.getContentVersions().iterator().next();
    final WorkflowInfo retrievedWorkflowInfo = contentVersion.getWorkflowInfo();
    assertEquals(WorkflowState.IN_PROGRESS, retrievedWorkflowInfo.getState());
    assertEquals(WorkflowCheckState.APPROVED, retrievedWorkflowInfo.getChecks().get("checkName1"));
    assertEquals(WorkflowCheckState.PENDING, retrievedWorkflowInfo.getChecks().get("checkName2"));
}
Also used : Content(com.enonic.xp.content.Content) ContentVersion(com.enonic.xp.content.ContentVersion) WorkflowInfo(com.enonic.xp.content.WorkflowInfo) PropertyTree(com.enonic.xp.data.PropertyTree) FindContentVersionsResult(com.enonic.xp.content.FindContentVersionsResult) WorkflowCheckState(com.enonic.xp.content.WorkflowCheckState) Test(org.junit.jupiter.api.Test)

Example 2 with WorkflowCheckState

use of com.enonic.xp.content.WorkflowCheckState in project xp by enonic.

the class ContentDataSerializerTest method create_propertyTree_populated_with_workflowInfo.

@Test
public void create_propertyTree_populated_with_workflowInfo() {
    final String check1Name = "myCheck1";
    final WorkflowCheckState check1State = WorkflowCheckState.APPROVED;
    final String check2Name = "myCheck2";
    final WorkflowCheckState check2State = WorkflowCheckState.PENDING;
    final WorkflowInfo workflowInfo = WorkflowInfo.create().state(WorkflowState.PENDING_APPROVAL).checks(Map.of(check1Name, check1State, check2Name, check2State)).build();
    final ContentDataSerializer contentDataSerializer = createContentDataSerializer();
    final CreateContentTranslatorParams params = CreateContentTranslatorParams.create().parent(ContentPath.ROOT).name("myContentName").contentData(new PropertyTree()).displayName("myDisplayName").type(ContentTypeName.codeMedia()).creator(PrincipalKey.ofAnonymous()).childOrder(ChildOrder.defaultOrder()).workflowInfo(workflowInfo).build();
    final PropertyTree data = contentDataSerializer.toCreateNodeData(params);
    final PropertySet workflowData = data.getSet(ContentPropertyNames.WORKFLOW_INFO);
    assertEquals(workflowInfo.getState().toString(), workflowData.getString(ContentPropertyNames.WORKFLOW_INFO_STATE));
    final PropertySet workflowChecks = workflowData.getPropertySet(ContentPropertyNames.WORKFLOW_INFO_CHECKS);
    assertEquals(check1State.toString(), workflowChecks.getString(check1Name));
    assertEquals(check2State.toString(), workflowChecks.getString(check2Name));
}
Also used : CreateContentTranslatorParams(com.enonic.xp.content.CreateContentTranslatorParams) WorkflowInfo(com.enonic.xp.content.WorkflowInfo) PropertyTree(com.enonic.xp.data.PropertyTree) PropertySet(com.enonic.xp.data.PropertySet) WorkflowCheckState(com.enonic.xp.content.WorkflowCheckState) Test(org.junit.jupiter.api.Test)

Example 3 with WorkflowCheckState

use of com.enonic.xp.content.WorkflowCheckState in project xp by enonic.

the class WorkflowInfoSerializer method extract.

public WorkflowInfo extract(final PropertySet workflowInfo) {
    if (workflowInfo == null) {
        return WorkflowInfo.ready();
    }
    final ImmutableMap.Builder<String, WorkflowCheckState> mapBuilder = ImmutableMap.builder();
    PropertySet checkSet = workflowInfo.getSet(WORKFLOW_INFO_CHECKS);
    if (checkSet != null) {
        for (String checks : checkSet.getPropertyNames()) {
            mapBuilder.put(checks, WorkflowCheckState.valueOf(checkSet.getString(checks)));
        }
    }
    return WorkflowInfo.create().state(workflowInfo.getString(WORKFLOW_INFO_STATE)).checks(mapBuilder.build()).build();
}
Also used : PropertySet(com.enonic.xp.data.PropertySet) WorkflowCheckState(com.enonic.xp.content.WorkflowCheckState) ImmutableMap(com.google.common.collect.ImmutableMap)

Aggregations

WorkflowCheckState (com.enonic.xp.content.WorkflowCheckState)3 WorkflowInfo (com.enonic.xp.content.WorkflowInfo)2 PropertySet (com.enonic.xp.data.PropertySet)2 PropertyTree (com.enonic.xp.data.PropertyTree)2 Test (org.junit.jupiter.api.Test)2 Content (com.enonic.xp.content.Content)1 ContentVersion (com.enonic.xp.content.ContentVersion)1 CreateContentTranslatorParams (com.enonic.xp.content.CreateContentTranslatorParams)1 FindContentVersionsResult (com.enonic.xp.content.FindContentVersionsResult)1 ImmutableMap (com.google.common.collect.ImmutableMap)1