Search in sources :

Example 1 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_null_rendition_arg_is_noop.

@Test
public void test_with_null_rendition_arg_is_noop() throws Exception {
    WorkItem workItem = mock(WorkItem.class);
    MetaDataMap metaData = new SimpleMetaDataMap();
    process.execute(workItem, workflowSession, metaData, workflowHelper);
    verifyZeroInteractions(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 2 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);
    verifyZeroInteractions(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 3 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_rendition_arg_getting_no_rendition_is_noop.

@Test
public void test_with_rendition_arg_getting_no_rendition_is_noop() throws Exception {
    String path = "/content/dam/some/path.ext";
    WorkItem workItem = mock(WorkItem.class);
    WorkflowData data = mock(WorkflowData.class);
    when(workItem.getWorkflowData()).thenReturn(data);
    when(data.getPayloadType()).thenReturn(WorkflowHelper.TYPE_JCR_PATH);
    when(data.getPayload()).thenReturn(path);
    Resource resource = mock(Resource.class);
    Asset asset = mock(Asset.class);
    when(resource.adaptTo(Asset.class)).thenReturn(asset);
    when(resource.getResourceType()).thenReturn(DamConstants.NT_DAM_ASSET);
    when(resourceResolver.getResource(path)).thenReturn(resource);
    MetaDataMap metaData = new SimpleMetaDataMap();
    metaData.put("PROCESS_ARGS", "renditionName:test");
    process.execute(workItem, workflowSession, metaData, workflowHelper);
    verifyZeroInteractions(harness);
}
Also used : SimpleMetaDataMap(com.day.cq.workflow.metadata.SimpleMetaDataMap) Resource(org.apache.sling.api.resource.Resource) MetaDataMap(com.day.cq.workflow.metadata.MetaDataMap) SimpleMetaDataMap(com.day.cq.workflow.metadata.SimpleMetaDataMap) Asset(com.day.cq.dam.api.Asset) WorkItem(com.day.cq.workflow.exec.WorkItem) WorkflowData(com.day.cq.workflow.exec.WorkflowData) Test(org.junit.Test)

Example 4 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 {
    ResourceResolver resourceResolver = null;
    String wfPayload = null;
    try {
        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) {
                log.error("Could not find the metadata node for Asset [ " + asset.getPath() + " ]");
                throw new WorkflowException("Could not find the metadata node for Asset [ " + asset.getPath() + " ]");
            }
            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);
    } finally {
        if (resourceResolver != null) {
            resourceResolver.close();
        }
    }
}
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 5 with MetaDataMap

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

the class SendTemplatedEmailProcessTest method test_with_payload_notJcrPath_is_noop.

@Test
public void test_with_payload_notJcrPath_is_noop() throws Exception {
    WorkflowData workflowData = mock(WorkflowData.class);
    when(workItem.getWorkflowData()).thenReturn(workflowData);
    when(workflowData.getPayloadType()).thenReturn("");
    MetaDataMap metaData = new SimpleMetaDataMap();
    process.execute(workItem, workflowSession, metaData);
    verifyZeroInteractions(harness);
}
Also used : SimpleMetaDataMap(com.day.cq.workflow.metadata.SimpleMetaDataMap) MetaDataMap(com.day.cq.workflow.metadata.MetaDataMap) SimpleMetaDataMap(com.day.cq.workflow.metadata.SimpleMetaDataMap) WorkflowData(com.day.cq.workflow.exec.WorkflowData) 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