Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
BedrockMission!

Learn more

View all

Sign in to view all badges

SOLVED

dam:assetState property value remains "processing" after custom workflow finish

wolk_arkadiusz
Level 2
Level 2

Hi,

I have created custom workflow, which is generating additional renditions for assets after they are created/modified. Problem is that (after workflow finish) value of property dam:assetState remains "processing". Workflow is not transient. Assets are fully modifiable and I can use them normally.

I guess that probably I've forget about adding some step in workflow model, or whatever.

AEM version 6.2.0.SP1.

Please advise.

Thanks,

Arek

1 Accepted Solution
rmahendra
Correct answer by
Employee
Employee

dam:assetState is being set to processed in the DAM Update Asset Workflow Completed Step. Please check if you have that step in the dam update asset workflow.

1356788_pastedImage_0.png

View solution in original post

12 Replies
smacdonald2008
Level 10
Level 10

Are you using the AssetManager API in a custom step to create the renditions?

wolk_arkadiusz
Level 2
Level 2

Hi,

To create renditions I'm using com.day.image.Layer and its methods: resize() and crop(). After that, using InputStream from the layer I'm adding new rendition using com.day.cq.dam.api.Asset.addRenditionMethod().

smacdonald2008
Level 10
Level 10

You are using this API in a custom workflow step - correct?

wolk_arkadiusz
Level 2
Level 2

Correct.

I've created custom workflow step as implementation of com.adobe.granite.workflow.exec.WorkflowProcess. In this custom step I'm using classes I've described in the previous comment.

smacdonald2008
Level 10
Level 10

The only thing i can do is try to reduplicate your findings. I will write a custom workflow step that uses the AssetManager API to see if i get the same results. I will post back my findings.

smacdonald2008
Level 10
Level 10

I built a custom workflow step and injected that into a workflow model. In the custom workflow - i used the AssetManager API to work with an asset and place it in an AEM DAM location.

Here is the node props.

MM1.png

There is no issue when you code with the AssetManager API.

wolk_arkadiusz
Level 2
Level 2

Okay, I see. Maybe you could help me with pointing which process is responsible for changing property state from "processing" to "processed"?

smacdonald2008
Level 10
Level 10

There is not a specific workflow that places an asset in this state. The point is when you write a custom workflow step that modifies an asset - use the Asset Manager API. When it creates the asset and the workflow completes, the asset will automatically be put in this state - as shown in my illustration.

For example, if you had this custom workflow step in a workflow - the asset would be in the processed state.

@Component

@Service

 

@Properties({

    @Property(name = Constants.SERVICE_DESCRIPTION, value = "Test Email workflow process implementation."),

    @Property(name = Constants.SERVICE_VENDOR, value = "Adobe"),

    @Property(name = "process.label", value = "Test Email Workflow Process") })

public class CustomStep implements WorkflowProcess

{

      

     

/** Default log. */

protected final Logger log = LoggerFactory.getLogger(this.getClass());

     

//Inject a MessageGatewayService

//Inject a Sling ResourceResolverFactory

@Reference

private ResourceResolverFactory resolverFactory;

     

public void execute(WorkItem item, WorkflowSession wfsession,MetaDataMap args) throws WorkflowException {

         

try

{

    log.info("**** Here in execute method");    //ensure that the execute method is invoked   

         

    //Get the Assets from the file system for a test

   

    File file = new File("C:\\Users\\scottm\\Mal10.JPG");

    InputStream fis = null;

    fis = new FileInputStream(file);

   

        String name = writeToDam(fis, "Malcolm.jpg") ;

       

         log.info("**** Name of the new Assets is "+name);

}

 

    catch (Exception e)

    {

    e.printStackTrace()  ;

    }

}

//Save the uploaded file into the AEM DAM using AssetManager API

private String writeToDam(InputStream is, String fileName)

{

try

{

    //Inject a ResourceResolver

    ResourceResolver resourceResolver = resolverFactory.getAdministrativeResourceResolver(null);

    

    //Use AssetManager to place the file into the AEM DAM

    com.day.cq.dam.api.AssetManager assetMgr = resourceResolver.adaptTo(com.day.cq.dam.api.AssetManager.class);

    String newFile = "/content/dam/summit-toys/"+fileName ;

    assetMgr.createAsset(newFile, is,"image/jpeg", true);

        

    // Return the path to the file was stored

    return newFile;

}

catch(Exception e)

{

    e.printStackTrace();

}

return null;

}

}

If you are not getting this result in a custom workflow - you are doing something wrong.

wolk_arkadiusz
Level 2
Level 2

But AssetManager enables to create new Asset. In my case, I already have the asset and I'm just creating a few new renditions for the asset. Please take a look at the code below.

private static final String CONTENT_PATH = "/" + JcrConstants.JCR_CONTENT;

private static final String DAM_THUMBNAIL_FORMAT = "cq5dam.thumbnail.%s.%s.png";

public void execute(WorkItem workItem, WorkflowSession workflowSession, MetaDataMap metaDataMap)

   throws WorkflowException {

  org.apache.sling.api.resource.Resource imgResource = getResourceFromPayload(workItem, workflowSession);

   com.day.cq.dam.api.Asset asset = imgResource.adaptTo(Asset.class);

   String mimeType = asset.getMimeType();

  try (ByteArrayOutputStream outputStream = new ByteArrayOutputStream()) {

  com.day.image.Layer layer = new Layer(asset.getOriginal().getStream());

  int width = layer.getWidth();
  int height = layer.getHeight();

  int resizedWidth = width / 2;
  int resizedHeight = height / 2;

   layer.resize(resizedWidth, resizedHeight);
   layer.write(mimeType, 1, outputStream);

  try (ByteArrayInputStream inputStream = new ByteArrayInputStream(outputStream.toByteArray())) {

  String renditionName = String.format(DAM_THUMBNAIL_FORMAT, 1, 1);
   asset.addRendition(renditionName, inputStream, mimeType);
   }

  } catch (IOException e) {

   LOG.error("IOException while creating custom rendition for an image", e);
   }

}

Do you have any bits of advice for me?

Thanks

nikhilsinghal
Level 2
Level 2

Hi Scott

We are also facing the similar issue. Could you let us know what could be done about it.

Below is our code which we are using to write the custom renditions when the asset gets uploaded.

protected void writeRenditionToRepository(AssetHandler assetHandler, double originalHeight, double originalWidth,

double res, Rendition original, String renditionName, Session session, Asset asset, String mimeType,

String extension) throws IOException, RepositoryException {

     Dimension dim = new Dimension((int) Math.round(originalWidth * res), (int) Math.round(originalHeight * res));

     BufferedImage image = assetHandler.getImage(original, dim);

     log.debug("Rasterized to an image with dim {}x{}", image.getWidth(), image.getHeight());

     ByteArrayOutputStream out = new ByteArrayOutputStream();

     boolean w = ImageIO.write(image, extension, out);

     if (w) {

          ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());

          asset.setBatchMode(true);

          asset.addRendition(renditionName, in, mimeType);

          session.save();

          in.close();

     }

     out.close();

}

rmahendra
Correct answer by
Employee
Employee

dam:assetState is being set to processed in the DAM Update Asset Workflow Completed Step. Please check if you have that step in the dam update asset workflow.

1356788_pastedImage_0.png

View solution in original post

nikhilsinghal
Level 2
Level 2

Thanks.

This seemed to have resolved it.

We had the previous version of the dam update asset model checked in which might have got deployed post the upgrade of our 6.2 instance overriding the updated model & causing this bizarre behavior.