Skip to content

Commit 1bf840d

Browse files
Merge pull request #893 from adobe/develop
v2.5.0 release
2 parents ed219a6 + 83f3b7d commit 1bf840d

File tree

85 files changed

+3203
-28
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

85 files changed

+3203
-28
lines changed

all/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
<parent>
2323
<groupId>com.adobe.aem.commons</groupId>
2424
<artifactId>assetshare</artifactId>
25-
<version>2.4.9-SNAPSHOT</version>
25+
<version>2.5.0-SNAPSHOT</version>
2626
<relativePath>../pom.xml</relativePath>
2727
</parent>
2828

core.cloud/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
<parent>
2020
<groupId>com.adobe.aem.commons</groupId>
2121
<artifactId>assetshare</artifactId>
22-
<version>2.4.9-SNAPSHOT</version>
22+
<version>2.5.0-SNAPSHOT</version>
2323
<relativePath>../pom.xml</relativePath>
2424
</parent>
2525
<artifactId>assetshare.core.cloud</artifactId>

core/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
<parent>
2020
<groupId>com.adobe.aem.commons</groupId>
2121
<artifactId>assetshare</artifactId>
22-
<version>2.4.9-SNAPSHOT</version>
22+
<version>2.5.0-SNAPSHOT</version>
2323
<relativePath>../pom.xml</relativePath>
2424
</parent>
2525
<artifactId>assetshare.core</artifactId>
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/*
2+
* Asset Share Commons
3+
*
4+
* Copyright (C) 2023 Adobe
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*
18+
*/
19+
package com.adobe.aem.commons.assetshare.components.assetkit;
20+
21+
import com.adobe.aem.commons.assetshare.components.Component;
22+
import com.adobe.aem.commons.assetshare.content.AssetModel;
23+
import org.osgi.annotation.versioning.ConsumerType;
24+
import org.osgi.annotation.versioning.ProviderType;
25+
26+
import java.util.Collection;
27+
@ProviderType
28+
public interface AssetKit extends Component {
29+
Collection<? extends AssetModel> getAssets();
30+
boolean isReady();
31+
32+
@ConsumerType
33+
interface Filter {
34+
Collection<? extends AssetModel> filter(Collection<? extends AssetModel> assets);
35+
}
36+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*
2+
* Asset Share Commons
3+
*
4+
* Copyright (C) 2023 Adobe
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*
18+
*/
19+
package com.adobe.aem.commons.assetshare.components.assetkit.impl;
20+
21+
import com.adobe.aem.commons.assetshare.components.assetkit.AssetKit;
22+
import com.adobe.aem.commons.assetshare.content.AssetModel;
23+
import org.apache.commons.lang3.StringUtils;
24+
import org.osgi.service.component.annotations.Component;
25+
26+
import java.util.Collection;
27+
import java.util.stream.Collectors;
28+
29+
@Component(property = {
30+
"service.ranking:Integer=-10000"
31+
})
32+
public class AssetKitFilterImpl implements AssetKit.Filter {
33+
34+
@Override
35+
public Collection<? extends AssetModel> filter(final Collection<? extends AssetModel> assets) {
36+
return assets.stream().filter(asset -> !StringUtils.equals(StringUtils.lowerCase(asset.getTitle()), "banner")).collect(Collectors.toList());
37+
}
38+
}
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
/*
2+
* Asset Share Commons
3+
*
4+
* Copyright (C) 2023 Adobe
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*
18+
*/
19+
package com.adobe.aem.commons.assetshare.components.assetkit.impl;
20+
21+
import com.adobe.aem.commons.assetshare.components.assetkit.AssetKit;
22+
import com.adobe.aem.commons.assetshare.content.AssetModel;
23+
import com.adobe.aem.commons.assetshare.util.assetkit.AssetKitHelper;
24+
import com.adobe.cq.export.json.ComponentExporter;
25+
import com.adobe.cq.export.json.ExporterConstants;
26+
import org.apache.sling.api.SlingHttpServletRequest;
27+
import org.apache.sling.models.annotations.Exporter;
28+
import org.apache.sling.models.annotations.Model;
29+
import org.apache.sling.models.annotations.Optional;
30+
import org.apache.sling.models.annotations.injectorspecific.OSGiService;
31+
import org.apache.sling.models.annotations.injectorspecific.Self;
32+
import org.apache.sling.models.annotations.injectorspecific.ValueMapValue;
33+
34+
import javax.annotation.Nonnull;
35+
import java.util.Collection;
36+
37+
@Model(
38+
adaptables = {SlingHttpServletRequest.class},
39+
adapters = {AssetKit.class, ComponentExporter.class},
40+
resourceType = {com.adobe.aem.commons.assetshare.components.assetkit.impl.AssetKitImpl.RESOURCE_TYPE}
41+
)
42+
@Exporter(name = ExporterConstants.SLING_MODEL_EXPORTER_NAME, extensions = ExporterConstants.SLING_MODEL_EXTENSION)
43+
public class AssetKitImpl implements AssetKit {
44+
public static final String RESOURCE_TYPE = "asset-share-commons/components/asset-kit";
45+
46+
@Self
47+
private SlingHttpServletRequest request;
48+
49+
@ValueMapValue
50+
@Optional
51+
private Collection<String> paths;
52+
53+
@OSGiService
54+
private AssetKitHelper assetKitHelper;
55+
56+
@OSGiService
57+
@Optional
58+
private AssetKit.Filter assetsFilter;
59+
60+
Collection<? extends AssetModel> assets;
61+
62+
@Override
63+
public Collection<? extends AssetModel> getAssets() {
64+
if (assets != null) {
65+
return assets;
66+
}
67+
68+
assets = assetKitHelper.getAssets(request.getResourceResolver(), paths.toArray(new String[0]));
69+
// Return a list of AssetModels from the paths using isAssetPath, isAssetFolderPath and isAssetCollectionPath
70+
71+
if (assetsFilter != null) {
72+
assets = assetsFilter.filter(assets);
73+
}
74+
75+
return assets;
76+
}
77+
78+
@Override
79+
public boolean isReady() {
80+
return getAssets().size() > 0;
81+
}
82+
83+
@Nonnull
84+
@Override
85+
public String getExportedType() {
86+
return RESOURCE_TYPE;
87+
}
88+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/*
2+
* Asset Share Commons
3+
*
4+
* Copyright (C) 2023 Adobe
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*
18+
*/
19+
20+
@Version("1.0.0")
21+
package com.adobe.aem.commons.assetshare.components.assetkit;
22+
23+
import org.osgi.annotation.versioning.Version;
24+
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
/*
2+
* Asset Share Commons
3+
*
4+
* Copyright (C) 2017 Adobe
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*
18+
*/
19+
20+
package com.adobe.aem.commons.assetshare.content.properties.impl;
21+
22+
import com.adobe.aem.commons.assetshare.content.properties.AbstractComputedProperty;
23+
import com.adobe.aem.commons.assetshare.content.properties.ComputedProperty;
24+
import com.day.cq.dam.api.Asset;
25+
import org.apache.commons.lang3.StringUtils;
26+
import org.apache.sling.api.SlingHttpServletRequest;
27+
import org.osgi.framework.Constants;
28+
import org.osgi.service.component.annotations.Activate;
29+
import org.osgi.service.component.annotations.Component;
30+
import org.osgi.service.metatype.annotations.AttributeDefinition;
31+
import org.osgi.service.metatype.annotations.Designate;
32+
import org.osgi.service.metatype.annotations.ObjectClassDefinition;
33+
34+
import static com.adobe.aem.commons.assetshare.content.properties.ComputedProperty.DEFAULT_ASC_COMPUTED_PROPERTY_SERVICE_RANKING;
35+
36+
@Component(
37+
service = ComputedProperty.class,
38+
property = {
39+
Constants.SERVICE_RANKING + "=" + DEFAULT_ASC_COMPUTED_PROPERTY_SERVICE_RANKING
40+
}
41+
)
42+
@Designate(ocd = FileExtensionImpl.Cfg.class)
43+
public class FileExtensionImpl extends AbstractComputedProperty<String> {
44+
public static final String LABEL = "File Extension";
45+
public static final String NAME = "fileExtension";
46+
private Cfg cfg;
47+
48+
@Override
49+
public String getName() {
50+
return NAME;
51+
}
52+
53+
@Override
54+
public String getLabel() {
55+
return cfg.label();
56+
}
57+
58+
@Override
59+
public String[] getTypes() {
60+
return cfg.types();
61+
}
62+
63+
@Override
64+
public String get(Asset asset, SlingHttpServletRequest request) {
65+
return StringUtils.substringAfterLast(asset.getName(), ".");
66+
}
67+
68+
@Activate
69+
protected void activate(Cfg cfg) {
70+
this.cfg = cfg;
71+
}
72+
73+
@ObjectClassDefinition(name = "Asset Share Commons - Computed Property - File Extension")
74+
public @interface Cfg {
75+
@AttributeDefinition(
76+
name = "Label",
77+
description = "Human read-able label."
78+
)
79+
String label() default LABEL;
80+
81+
@AttributeDefinition(
82+
name = "Types",
83+
description = "Defines the type of data this exposes. This classification allows for intelligent exposure of Computed Properties in DataSources, etc."
84+
)
85+
String[] types() default {Types.METADATA};
86+
}
87+
}

core/src/main/java/com/adobe/aem/commons/assetshare/content/properties/impl/FileSizeImpl.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,11 @@ public String get(Asset asset, SlingHttpServletRequest request) {
7676
}
7777
}
7878

79-
return UIHelper.getSizeLabel(bytes, request);
79+
if (request != null) {
80+
return UIHelper.getSizeLabel(bytes, request);
81+
} else {
82+
return UIHelper.getSizeLabel(bytes);
83+
}
8084
}
8185

8286
@Activate
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package com.adobe.aem.commons.assetshare.util;
2+
3+
import com.adobe.granite.workflow.WorkflowSession;
4+
import com.adobe.granite.workflow.exec.WorkItem;
5+
import com.adobe.granite.workflow.exec.WorkflowData;
6+
import com.adobe.granite.workflow.metadata.MetaDataMap;
7+
8+
/**
9+
* Util to help working with Workflows and Workflow processes
10+
*/
11+
public class WorkflowUtil {
12+
13+
public static <T> boolean persistData(WorkItem workItem, WorkflowSession workflowSession, String key, T val) {
14+
WorkflowData data = workItem.getWorkflow().getWorkflowData();
15+
if (data.getMetaDataMap() == null) {
16+
return false;
17+
}
18+
19+
data.getMetaDataMap().put(key, val);
20+
workflowSession.updateWorkflowData(workItem.getWorkflow(), data);
21+
22+
return true;
23+
}
24+
25+
public static <T> T getPersistedData(WorkItem workItem, String key, Class<T> type) {
26+
MetaDataMap map = workItem.getWorkflow().getWorkflowData().getMetaDataMap();
27+
return map.get(key, type);
28+
}
29+
30+
public static <T> T getPersistedData(WorkItem workItem, String key, T defaultValue) {
31+
MetaDataMap map = workItem.getWorkflow().getWorkflowData().getMetaDataMap();
32+
return map.get(key, defaultValue);
33+
}
34+
}

0 commit comments

Comments
 (0)