Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

aem.events_osgi_mapping enrich xdm Asset to add DamAsset metadata #90

Open
francoisledroff opened this issue Apr 1, 2022 · 0 comments

Comments

@francoisledroff
Copy link
Collaborator

francoisledroff commented Apr 1, 2022

The challenge would be in white-listing the metadata, as it can be too large.

it could be like this:

package package com.adobe.aio.aem.event.xdm.aem;

import com.adobe.xdm.assets.Asset;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonInclude.Include;
import com.fasterxml.jackson.annotation.JsonProperty;
import java.util.GregorianCalendar;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
import org.apache.sling.api.resource.ValueMap;

@JsonInclude(Include.NON_NULL)
@JsonIgnoreProperties(ignoreUnknown = true)
public class DamAsset extends Asset {


  Map<String, String> metadatas;

  @JsonIgnore
  public void setMetadata(ValueMap valueMap) {
    if (valueMap != null) {
      metadatas = new HashMap<>();
      for (String entry : valueMap.keySet()) {
        Object value = valueMap.get(entry);
        if (value != null && !entry.startsWith("jcr:") && !(value instanceof GregorianCalendar)
            && !(value.getClass().isArray())) {
          metadatas.put(entry, value.toString());
          //TODO better filtering with metadata whitelist configuration 
        }
      }
    }
  }

  @JsonProperty("xdmAsset:metadatas")
  public Map<String, String> getMetadata() {
    return metadatas;
  }

  @Override
  public boolean equals(Object o) {
    if (this == o) {
      return true;
    }
    if (o == null || getClass() != o.getClass()) {
      return false;
    }
    if (!super.equals(o)) {
      return false;
    }
    DamAsset damAsset = (DamAsset) o;
    return Objects.equals(metadatas, damAsset.metadatas);
  }

  @Override
  public int hashCode() {
    return Objects.hash(super.hashCode(), metadatas);
  }

  @Override
  public String toString() {
    return "DamAsset{id='" + this.id + '\'' + ", type='" + this.type + '\'' + ", assetId='"
        + this.getAssetId() + '\'' + ", assetName='" + this.getAssetName() + '\''
        + ", etag='" + this.getEtag()
        + '\'' + ", path='" + this.getPath() + '\'' + ", format='" + this.getFormat() + '\''
        + "metadatas=" + metadatas +
        '}';
  }
}

@francoisledroff francoisledroff changed the title aem.events_osgi_mapping replace xdm Asset to add DamAsset with metadata aem.events_osgi_mapping enrich xdm Asset to add DamAsset metadata Apr 7, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant