Search in sources :

Example 6 with MetaDataMap

use of com.day.cq.workflow.metadata.MetaDataMap in project acs-aem-commons by Adobe-Consulting-Services.

the class RenditionModifyingProcessTest method test_with_blank_rendition_arg_is_noop.

@Test
public void test_with_blank_rendition_arg_is_noop() throws Exception {
    WorkItem workItem = mock(WorkItem.class);
    MetaDataMap metaData = new SimpleMetaDataMap();
    metaData.put("PROCESS_ARGS", "");
    process.execute(workItem, workflowSession, metaData, workflowHelper);
    verifyNoInteractions(harness);
}
Also used : SimpleMetaDataMap(com.day.cq.workflow.metadata.SimpleMetaDataMap) MetaDataMap(com.day.cq.workflow.metadata.MetaDataMap) SimpleMetaDataMap(com.day.cq.workflow.metadata.SimpleMetaDataMap) WorkItem(com.day.cq.workflow.exec.WorkItem) Test(org.junit.Test)

Example 7 with MetaDataMap

use of com.day.cq.workflow.metadata.MetaDataMap in project acs-aem-commons by Adobe-Consulting-Services.

the class WorkflowHelperImplTest method testBuildArguments.

@Test
public void testBuildArguments() throws Exception {
    MetaDataMap map = mock(MetaDataMap.class);
    when(map.get(WorkflowHelper.PROCESS_ARGS, String.class)).thenReturn("foo:bar,goo:baz");
    String[] result = workflowHelper.buildArguments(map);
    assertNotNull(result);
    assertEquals(2, result.length);
    assertEquals("foo:bar", result[0]);
    assertEquals("goo:baz", result[1]);
}
Also used : MetaDataMap(com.day.cq.workflow.metadata.MetaDataMap) Test(org.junit.Test)

Example 8 with MetaDataMap

use of com.day.cq.workflow.metadata.MetaDataMap in project acs-aem-commons by Adobe-Consulting-Services.

the class DamMetadataPropertyResetProcess method execute.

@Override
public final void execute(WorkItem workItem, WorkflowSession workflowSession, MetaDataMap metaDataMap) throws WorkflowException {
    String wfPayload = null;
    try (ResourceResolver resourceResolver = this.getResourceResolver(workflowSession.getSession())) {
        wfPayload = (String) workItem.getWorkflowData().getPayload();
        final List<String> payloads = workflowPackageManager.getPaths(resourceResolver, wfPayload);
        final Map<String, String> srcDestMap = this.getProcessArgsMap(metaDataMap);
        for (final String payload : payloads) {
            final Asset asset = DamUtil.resolveToAsset(resourceResolver.getResource(payload));
            if (asset == null) {
                log.debug("Payload path [ {} ] does not resolve to an asset", payload);
                continue;
            }
            String metadataPath = String.format("%s/%s/%s", asset.getPath(), JcrConstants.JCR_CONTENT, DamConstants.METADATA_FOLDER);
            Resource metadataResource = resourceResolver.getResource(metadataPath);
            if (metadataResource == null) {
                String msg = String.format("Could not find the metadata node for Asset [ %s ]", asset.getPath());
                throw new WorkflowException(msg);
            }
            final ModifiableValueMap mvm = metadataResource.adaptTo(ModifiableValueMap.class);
            for (final Map.Entry<String, String> entry : srcDestMap.entrySet()) {
                final String srcProperty = entry.getValue();
                final String destProperty = entry.getKey();
                if (mvm.get(srcProperty) != null) {
                    // Remove dest property first in case Types differ
                    mvm.remove(destProperty);
                    // If the src value is NOT null, update the dest property
                    mvm.put(destProperty, mvm.get(srcProperty));
                } else if (mvm.containsKey(srcProperty)) {
                    // Else if the src value IS null, AND the src property exists on the node, remove the dest property
                    mvm.remove(destProperty);
                }
                // Else leave the dest property alone since there is no source defined to overwrite it with
                // Remove the source
                mvm.remove(srcProperty);
            }
        }
    } catch (LoginException e) {
        throw new WorkflowException("Could not get a ResourceResolver object from the WorkflowSession", e);
    } catch (RepositoryException e) {
        throw new WorkflowException(String.format("Could not find the payload for '%s'", wfPayload), e);
    }
}
Also used : WorkflowException(com.day.cq.workflow.WorkflowException) ResourceResolver(org.apache.sling.api.resource.ResourceResolver) Resource(org.apache.sling.api.resource.Resource) Asset(com.day.cq.dam.api.Asset) LoginException(org.apache.sling.api.resource.LoginException) RepositoryException(javax.jcr.RepositoryException) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) MetaDataMap(com.day.cq.workflow.metadata.MetaDataMap) ModifiableValueMap(org.apache.sling.api.resource.ModifiableValueMap) ModifiableValueMap(org.apache.sling.api.resource.ModifiableValueMap)

Example 9 with MetaDataMap

use of com.day.cq.workflow.metadata.MetaDataMap in project acs-aem-commons by Adobe-Consulting-Services.

the class WorkflowHelperImplTest method testBuildArgumentsFromNullArguments.

@Test
public void testBuildArgumentsFromNullArguments() throws Exception {
    MetaDataMap map = mock(MetaDataMap.class);
    when(map.get(WorkflowHelper.PROCESS_ARGS, String.class)).thenReturn(null);
    String[] result = workflowHelper.buildArguments(map);
    assertNotNull(result);
    assertEquals(0, result.length);
}
Also used : MetaDataMap(com.day.cq.workflow.metadata.MetaDataMap) Test(org.junit.Test)

Example 10 with MetaDataMap

use of com.day.cq.workflow.metadata.MetaDataMap in project acs-aem-commons by Adobe-Consulting-Services.

the class WorkflowHelperImplTest method testBuildArgumentsFromBlankArguments.

@Test
public void testBuildArgumentsFromBlankArguments() throws Exception {
    MetaDataMap map = mock(MetaDataMap.class);
    when(map.get(WorkflowHelper.PROCESS_ARGS, String.class)).thenReturn("");
    String[] result = workflowHelper.buildArguments(map);
    assertNotNull(result);
    assertEquals(0, result.length);
}
Also used : MetaDataMap(com.day.cq.workflow.metadata.MetaDataMap) Test(org.junit.Test)

Aggregations

MetaDataMap (com.day.cq.workflow.metadata.MetaDataMap)12 Test (org.junit.Test)11 SimpleMetaDataMap (com.day.cq.workflow.metadata.SimpleMetaDataMap)8 WorkflowData (com.day.cq.workflow.exec.WorkflowData)6 Resource (org.apache.sling.api.resource.Resource)5 WorkItem (com.day.cq.workflow.exec.WorkItem)4 Asset (com.day.cq.dam.api.Asset)3 HashMap (java.util.HashMap)3 Rendition (com.day.cq.dam.api.Rendition)1 RenditionPicker (com.day.cq.dam.api.RenditionPicker)1 WorkflowException (com.day.cq.workflow.WorkflowException)1 Layer (com.day.image.Layer)1 InputStream (java.io.InputStream)1 LinkedHashMap (java.util.LinkedHashMap)1 Map (java.util.Map)1 RepositoryException (javax.jcr.RepositoryException)1 LoginException (org.apache.sling.api.resource.LoginException)1 ModifiableValueMap (org.apache.sling.api.resource.ModifiableValueMap)1 ResourceResolver (org.apache.sling.api.resource.ResourceResolver)1 InvocationOnMock (org.mockito.invocation.InvocationOnMock)1