Scene7FileMetadataServiceImpl.java
4.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* com.day.cq.commons.jcr.JcrUtil
* com.day.cq.dam.api.Asset
* javax.jcr.Node
* javax.jcr.Property
* org.apache.felix.scr.annotations.Component
* org.apache.felix.scr.annotations.Reference
* org.apache.felix.scr.annotations.Service
* org.apache.sling.api.resource.Resource
*/
package com.day.cq.dam.scene7.impl;
import com.day.cq.commons.jcr.JcrUtil;
import com.day.cq.dam.api.Asset;
import com.day.cq.dam.scene7.api.S7Config;
import com.day.cq.dam.scene7.api.Scene7EndpointsManager;
import com.day.cq.dam.scene7.api.Scene7FileMetadataService;
import com.day.cq.dam.scene7.api.constants.Scene7AssetType;
import com.day.cq.dam.scene7.api.model.Scene7Asset;
import java.net.URL;
import java.util.Date;
import javax.jcr.Node;
import javax.jcr.Property;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Reference;
import org.apache.felix.scr.annotations.Service;
import org.apache.sling.api.resource.Resource;
@Component
@Service
public class Scene7FileMetadataServiceImpl
implements Scene7FileMetadataService {
private static final String SYNC_FLAG = "newRendition";
@Reference
private Scene7EndpointsManager scene7EndpointsManager;
@Override
public void setAssetMetadataProperty(Asset asset, String propertyName, Object propertyValue) throws Exception {
Resource resource = (Resource)asset.adaptTo(Resource.class);
Node node = (Node)resource.adaptTo(Node.class);
if (node != null) {
Node metadata = node.getNode("jcr:content/metadata");
Node content = node.getNode("jcr:content");
JcrUtil.setProperty((Node)content, (String)"newRendition", (Object)true);
JcrUtil.setProperty((Node)metadata, (String)propertyName, (Object)propertyValue);
}
}
@Override
public void setAssetMetadataOnSync(Asset asset, Scene7Asset scene7Asset, S7Config s7Config, String status) throws Exception {
this.setAssetMetadataProperty(asset, "dam:scene7ID", scene7Asset.getAssetHandle());
String publishedServer = s7Config.getPublishServer();
if (!publishedServer.endsWith("/")) {
publishedServer = publishedServer + "/";
}
this.setAssetMetadataProperty(asset, "dam:scene7Name", scene7Asset.getName());
this.setAssetMetadataProperty(asset, "dam:scene7Type", scene7Asset.getAssetType().getValue());
this.setAssetMetadataProperty(asset, "dam:scene7File", scene7Asset.getRootFolder() + scene7Asset.getName());
this.setAssetMetadataProperty(asset, "dam:scene7CompanyID", s7Config.getCompanyHandle());
this.setAssetMetadataProperty(asset, "dam:scene7Domain", publishedServer);
this.setAssetMetadataProperty(asset, "dam:scene7APIServer", this.scene7EndpointsManager.getAPIServer(s7Config.getRegion()).toString());
this.setAssetMetadataProperty(asset, "dam:scene7CloudConfigPath", s7Config.getCloudConfigPath());
this.setAssetMetadataProperty(asset, "dam:scene7FileStatus", status);
Long s7LastModifiedTimestamp = scene7Asset.getModifiedDate().getTime();
this.setAssetMetadataProperty(asset, "dam:scene7LastModified", s7LastModifiedTimestamp);
this.setAssetMetadataProperty(asset, "dam:scene7Folder", scene7Asset.getFolder());
}
@Override
public void removeAssetMetadataProperty(Asset asset, String propertyName) throws Exception {
Resource resource = (Resource)asset.adaptTo(Resource.class);
Resource metadataResource = resource.getChild("jcr:content/metadata");
Node metadataNode = (Node)metadataResource.adaptTo(Node.class);
metadataNode.getProperty(propertyName).remove();
}
protected void bindScene7EndpointsManager(Scene7EndpointsManager scene7EndpointsManager) {
this.scene7EndpointsManager = scene7EndpointsManager;
}
protected void unbindScene7EndpointsManager(Scene7EndpointsManager scene7EndpointsManager) {
if (this.scene7EndpointsManager == scene7EndpointsManager) {
this.scene7EndpointsManager = null;
}
}
}