public String getPath() { return asset.getPath(); }
@Override public @NotNull String getPath() { return this.damAsset.getPath(); }
private void createSequenceItemResource(Asset asset, ProcessArgs processArgs, ResourceResolver resourceResolver, Resource parentResource, AtomicInteger count, ValueMap properties) { try { resourceResolver.create(parentResource, String.valueOf(count.incrementAndGet()), new ImmutableMap.Builder<String, Object>() .put(JcrConstants.JCR_PRIMARYTYPE, JcrConstants.NT_UNSTRUCTURED) .put("xmpNodeType", "xmpStruct") .put(processArgs.getNameProperty(), properties.get(PN_SMART_TAG_NAME, String.class)) .put(processArgs.getConfidenceProperty(), properties.get(PN_SMART_TAG_CONFIDENCE, Double.class)) .build()); } catch (PersistenceException e) { log.error("Unable to sync Smart Tag [ {} ] to XMP Metadata structure for asset [ {} ]", properties.get("name", String.class), asset.getPath(), e); } }
/** * Update the Assets original rendition. * * @param asset the Asset to update * @param fileInputStream the new binary representation of the Asset * @param mimeType the MIME Type of the asset * @return the updated asset * @throws CsvAssetImportException */ private Asset updateAssetOriginal(Asset asset, InputStream fileInputStream, String mimeType) throws CsvAssetImportException { try { if (asset != null) { final Node originalNode = asset.getOriginal().adaptTo(Node.class); if (originalNode != null) { JcrUtils.putFile(originalNode.getParent(), "original", mimeType, fileInputStream, Calendar.getInstance()); log.info("Updated existing Asset's [ {} ] original rendition.", asset.getPath()); } else { log.warn("Could not find original rendition for Asset [ {} ] to update.", asset.getPath()); } } else { log.warn("Could not update a null asset"); } } catch (Exception e) { throw new CsvAssetImportException("Could not update Asset at [ " + asset.getPath() + " ]", e); } return asset; }
log.debug("Imported asset: {}", asset.getPath()); log.debug("Updated properties on asset: {}", asset.getPath()); } else { throw new CsvAssetImportException("Could not find an asset in the DAM to update. Skipping as a failure."); return asset.getPath(); } catch (Exception e) { throw new CsvAssetImportException("Could not import row", e);
/** * Updates AEM System properties of the Asset. * @param asset the asset to update. */ private void updateSystemProperties(final Asset asset) { Resource resource = asset.adaptTo(Resource.class); Resource jcrContentResource = resource.getChild(JcrConstants.JCR_CONTENT); if (jcrContentResource == null) { log.error("Could not find the jcr:content node for asset [ {} ]", asset.getPath()); return; } final ModifiableValueMap properties = jcrContentResource.adaptTo(ModifiableValueMap.class); properties.put("cq:name", asset.getName()); properties.put("cq:parentPath", StringUtils.removeEnd(asset.getPath(), "/" + asset.getName())); }
@Override public boolean hasFinished(Serializable serializable, WorkItem workItem, WorkflowSession workflowSession, MetaDataMap metaDataMap) { if (serializable == null) { return true; } ResourceResolver resolver = workflowSession.adaptTo(ResourceResolver.class); Asset asset = getAssetFromPayload(workItem, resolver); if (asset == null) { log.error("job started, but asset no longer exists."); return true; } if (serializable instanceof String) { TranscriptionService.Result result = transcriptionService.getResult((String) serializable); if (result.isCompleted()) { try { asset.addRendition("transcription.txt", new ByteArrayInputStream(result.getContent().getBytes("UTF-8")), "text/plain"); log.info("Transcription for {} created.", asset.getPath()); } catch (UnsupportedEncodingException e) { log.error("Unable to save new rendition", e); } return true; } else { return false; } } else { log.error("Unexpected serializable {}", serializable); return true; } }
@Override public boolean hasFinished(Serializable serializable, WorkItem workItem, WorkflowSession workflowSession, MetaDataMap metaDataMap) { if (serializable == null) { return true; } ResourceResolver resolver = workflowSession.adaptTo(ResourceResolver.class); Asset asset = getAssetFromPayload(workItem, resolver); if (asset == null) { log.error("job started, but asset no longer exists."); return true; } if (serializable instanceof String) { TranscriptionService.Result result = transcriptionService.getResult((String) serializable); if (result.isCompleted()) { try { asset.addRendition("transcription.txt", new ByteArrayInputStream(result.getContent().getBytes("UTF-8")), "text/plain"); log.info("Transcription for {} created.", asset.getPath()); } catch (Exception e) { log.error("Unable to save new rendition", e); } return true; } else { return false; } } else { log.error("Unexpected serializable {}", serializable); return true; } }
public final void execute(WorkItem workItem, WorkflowSession workflowSession, MetaDataMap metaDataMap) throws WorkflowException { log.debug("Invoked syncSmartTagsToMetadata Workflow Process step for payload [ {} ]", workItem.getWorkflowData().getPayload()); final ProcessArgs processArgs = new ProcessArgs(metaDataMap); try (ResourceResolver resourceResolver = workflowHelper.getResourceResolver(workflowSession)) { final List<String> payloads = workflowPackageManager.getPaths(resourceResolver, (String) workItem.getWorkflowData().getPayload()); final List<Asset> assets = payloads.stream() .map(payload -> DamUtil.resolveToAsset(resourceResolver.getResource(payload))) .filter(Objects::nonNull) .collect(Collectors.toList()); assets.stream().forEach(asset -> { try { syncSmartTagsToMetadata(asset, processArgs); } catch (PersistenceException e) { log.error("Unable to sync Smart Tags to XMP Metadata structure for asset [ {} ]", asset.getPath(), e); } }); } catch (RepositoryException e) { log.error("Could not find the payload", e); throw new WorkflowException("Could not find the payload"); } }
/** * Get node for storing the renditions additional metadata. * @param asset Asset * @param createIfNotExists if true the node is (tried to be) created automatically if it does not exist * @return Node or null if it does not exist or could not be created */ @SuppressWarnings("null") private Resource getRenditionsMetadataResource(Asset asset, boolean createIfNotExists) { Resource assetResource = asset.adaptTo(Resource.class); String renditionsMetadataPath = assetResource.getPath() + "/" + JCR_CONTENT + "/" + NN_RENDITIONS_METADATA; try { if (createIfNotExists) { return ResourceUtil.getOrCreateResource(assetResource.getResourceResolver(), renditionsMetadataPath, ImmutableMap.<String, Object>of(JCR_PRIMARYTYPE, NT_UNSTRUCTURED), NT_UNSTRUCTURED, false); } else { return assetResource.getChild(renditionsMetadataPath); } } catch (PersistenceException ex) { log.error("Unable to get/create renditions metadata node at " + asset.getPath(), ex); } return null; }
map.put(CF_PATH, asset.getPath()); map.put(CF_NAME, asset.getName()); map.put(CF_TITLE, title);
asset.getPath() + "/jcr:content/metadata/" + processArgs.getSequenceName());
@SuppressWarnings({"PMD.CollapsibleIfStatements", "squid:S1066"}) @Override public final void execute(WorkItem workItem, WorkflowSession wfSession, MetaDataMap metaData) throws WorkflowException { final WorkflowHelper.AssetResourceResolverPair pair = workflowHelper.getAssetFromPayload(workItem, wfSession); if (pair == null) { String wfPayload = workItem.getWorkflowData().getPayload().toString(); String message = "execute: cannot process audio, asset [{" + wfPayload + "}] in payload doesn't exist for workflow [{" + workItem.getId() + "}]."; throw new WorkflowException(message); } final String assetMimeType = pair.asset.getMimeType(); if ((assetMimeType == null || !assetMimeType.startsWith("audio/"))) { if (!pair.asset.getName().endsWith(".wav") || !pair.asset.getName().endsWith(".mp3") || !pair.asset.getName().endsWith(".ogg")) { log.info("execute: asset [{}] is not of a audio mime type, asset ignored.", pair.asset.getPath()); return; } } try { helper.process(pair.asset, pair.resourceResolver, metaData, this); } catch (AudioException e) { throw new WorkflowException("Unable to transcode audio", e); } finally { pair.resourceResolver.close(); } }
@SuppressWarnings("PMD.CollapsibleIfStatements") public final void execute(WorkItem workItem, WorkflowSession wfSession, MetaDataMap metaData) throws WorkflowException { final Asset asset = getAssetFromPayload(workItem, wfSession.getSession()); final ResourceResolver resolver = getResourceResolver(wfSession.getSession()); if (asset == null) { String wfPayload = workItem.getWorkflowData().getPayload().toString(); String message = "execute: cannot process audio, asset [{" + wfPayload + "}] in payload doesn't exist for workflow [{" + workItem.getId() + "}]."; throw new WorkflowException(message); } final String assetMimeType = asset.getMimeType(); if (assetMimeType == null || !assetMimeType.startsWith("audio/")) { if (!asset.getName().endsWith(".wav") || !asset.getName().endsWith(".mp3") || !asset.getName().endsWith(".ogg")) { log.info("execute: asset [{}] is not of a audio mime type, asset ignored.", asset.getPath()); return; } } try { helper.process(asset, resolver, metaData, this); } catch (AudioException e) { throw new WorkflowException("Unable to transcode audio", e); } }
log.debug("Payload path [ {} ] does not resolve to an asset", payload); } else { assetPaths.add(asset.getPath());
private void writeAsset(Asset asset, XMLStreamWriter stream, ResourceResolver resolver) throws XMLStreamException { stream.writeStartElement(NS, "url"); String loc = externalizer.externalLink(resolver, externalizerDomain, asset.getPath()); writeElement(stream, "loc", loc); if (includeLastModified) { long lastModified = asset.getLastModified(); if (lastModified > 0) { writeElement(stream, "lastmod", DATE_FORMAT.format(lastModified)); } } Resource contentResource = asset.adaptTo(Resource.class).getChild(JcrConstants.JCR_CONTENT); if (contentResource != null) { final ValueMap properties = contentResource.getValueMap(); writeFirstPropertyValue(stream, "changefreq", changefreqProperties, properties); writeFirstPropertyValue(stream, "priority", priorityProperties, properties); } stream.writeEndElement(); }
/** * {@inheritDoc} */ @Override public Resource getReplicationStatusResource(String path, ResourceResolver resourceResolver) { final Page page = resourceResolver.adaptTo(PageManager.class).getContainingPage(path); final Asset asset = DamUtil.resolveToAsset(resourceResolver.getResource(path)); Resource resource; String type; if (page != null) { type = "Page"; resource = page.getContentResource(); } else if (asset != null) { type = "Asset"; Resource assetResource = resourceResolver.getResource(asset.getPath()); resource = assetResource.getChild(JcrConstants.JCR_CONTENT); } else { type = "Resource"; resource = resourceResolver.getResource(path); } log.trace(type + "'s resource that tracks replication status is " + resource.getPath()); return resource; }
private void writeAsset(Asset asset, XMLStreamWriter stream, ResourceResolver resolver) throws XMLStreamException { stream.writeStartElement(NS, "url"); String loc = externalizer.externalLink(resolver, externalizerDomain, asset.getPath()); writeElement(stream, "loc", loc); if (includeLastModified) { long lastModified = asset.getLastModified(); if (lastModified > 0) { writeElement(stream, "lastmod", DATE_FORMAT.format(lastModified)); } } Resource contentResource = asset.adaptTo(Resource.class).getChild(JcrConstants.JCR_CONTENT); if (contentResource != null) { if (includeInheritValue) { HierarchyNodeInheritanceValueMap hierarchyNodeInheritanceValueMap = new HierarchyNodeInheritanceValueMap( contentResource); writeFirstPropertyValue(stream, "changefreq", changefreqProperties, hierarchyNodeInheritanceValueMap); writeFirstPropertyValue(stream, "priority", priorityProperties, hierarchyNodeInheritanceValueMap); } else { ValueMap properties = contentResource.getValueMap(); writeFirstPropertyValue(stream, "changefreq", changefreqProperties, properties); writeFirstPropertyValue(stream, "priority", priorityProperties, properties); } } stream.writeEndElement(); }