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

Avatar

Avatar

wolk_arkadiusz

Avatar

wolk_arkadiusz

wolk_arkadiusz

10-10-2017

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

View Entire Topic

Avatar

Avatar

wolk_arkadiusz

Avatar

wolk_arkadiusz

wolk_arkadiusz

19-10-2017

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