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

Replace RequestResponseFactory by Sling Request builders #3406

Merged
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ The format is based on [Keep a Changelog](http://keepachangelog.com)
<!-- Keep this up to date! After a release, change the tag name to the latest release -->-

## Unreleased ([details][unreleased changes details])

### Added

- #3426 - Content Sync: view history of completed jobs

### Changed
Expand All @@ -25,9 +28,11 @@ The format is based on [Keep a Changelog](http://keepachangelog.com)
- #3357 - Added debugging and null checking to ReferencesModel to prevent NPE
- #3398 - CreateRedirectConfigurationServlet throws PersistenceException when ancestor node types are different than expected
- #3275 - CCVAR: Fixed Same Attribute not updating correctly.
- #3402 - EnsureOakIndexManagerImpl does not pick up changes in EnsureOakIndex configurations.

### Changed

- #3403 - Replace deprecated com.day.cq.contentsync.handler.util.RequestResponseFactory by SlingHttpServletRequestBuilder
davidjgonzalez marked this conversation as resolved.
Show resolved Hide resolved
- #3376 - Redirect Manager: refactor code to not require service user
- #3408 - Reduce usage of Apache Commons Lang 2
- #3401 - Move SyslogAppender into separate bundle for onprem only. SyslogAppender does not work in Cloud Service.
Expand All @@ -39,7 +44,6 @@ The format is based on [Keep a Changelog](http://keepachangelog.com)

- #3355 - Fixed system notifications dismissal, and upgraded to CoralUI 3.


### Added

- #3333 - Use lodash embedded by ACS AEM Commons
Expand Down
1 change: 1 addition & 0 deletions bundle/bnd.bnd
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ Import-Package: \
!io.jsonwebtoken.*,\
!org.bouncycastle.jce.*,\
!org.checkerframework.checker.nullness.qual,\
com.day.cq.wcm.api;version="[1.30,2)",\
*
# support processing of legacy Felix SCR annotations through the felix.scr.bnd plugin, look at https://github.com/apache/felix/blob/trunk/tools/org.apache.felix.scr.bnd/src/main/java/org/apache/felix/scrplugin/bnd/SCRDescriptorBndPlugin.java#L60
# paths require special handling: https://bnd.bndtools.org/chapters/820-instructions.html#file
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,14 @@
*/
package com.adobe.acs.commons.mcp.impl.processes;

import org.apache.sling.engine.SlingRequestProcessor;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Reference;

import com.adobe.acs.commons.mcp.ProcessDefinitionFactory;
import com.adobe.acs.commons.util.RequireAem;
import com.day.cq.contentsync.handler.util.RequestResponseFactory;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Service;
import org.apache.felix.scr.annotations.Reference;
import org.apache.sling.engine.SlingRequestProcessor;

@Component
@Service(ProcessDefinitionFactory.class)
@Component(service = ProcessDefinitionFactory.class)
public class RefreshFolderThumbnailsFactory extends ProcessDefinitionFactory<RefreshFolderTumbnails> {

// Disable this feature on AEM as a Cloud Service
Expand All @@ -35,18 +33,14 @@ public class RefreshFolderThumbnailsFactory extends ProcessDefinitionFactory<Ref

@Reference
private SlingRequestProcessor slingProcessor;

@Reference
RequestResponseFactory reqRspFactory;


@Override
public String getName() {
return "Refresh asset folder thumbnails";
}

@Override
protected RefreshFolderTumbnails createProcessDefinitionInstance() {
return new RefreshFolderTumbnails(reqRspFactory, slingProcessor);
return new RefreshFolderTumbnails(slingProcessor);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -17,40 +17,40 @@
*/
package com.adobe.acs.commons.mcp.impl.processes;

import com.adobe.acs.commons.fam.ActionManager;
import com.adobe.acs.commons.fam.actions.ActionBatch;
import com.adobe.acs.commons.functions.CheckedFunction;
import com.adobe.acs.commons.mcp.ProcessDefinition;
import com.adobe.acs.commons.mcp.ProcessInstance;
import com.adobe.acs.commons.mcp.form.CheckboxComponent;
import com.adobe.acs.commons.mcp.form.FormField;
import com.adobe.acs.commons.mcp.form.PathfieldComponent;
import com.adobe.acs.commons.mcp.form.RadioComponent;
import com.adobe.acs.commons.mcp.model.GenericBlobReport;
import com.adobe.acs.commons.util.visitors.TreeFilteringResourceVisitor;
import com.day.cq.commons.jcr.JcrConstants;
import com.day.cq.contentsync.handler.util.RequestResponseFactory;
import com.day.cq.dam.api.DamConstants;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.EnumMap;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.jcr.RepositoryException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.io.output.NullOutputStream;

import org.apache.sling.api.request.builder.Builders;
import org.apache.sling.api.resource.LoginException;
import org.apache.sling.api.resource.PersistenceException;
import org.apache.sling.api.resource.Resource;
import org.apache.sling.api.resource.ResourceResolver;
import org.apache.sling.engine.SlingRequestProcessor;

import com.adobe.acs.commons.fam.ActionManager;
import com.adobe.acs.commons.fam.actions.ActionBatch;
import com.adobe.acs.commons.functions.CheckedFunction;
import com.adobe.acs.commons.mcp.ProcessDefinition;
import com.adobe.acs.commons.mcp.ProcessInstance;
import com.adobe.acs.commons.mcp.form.CheckboxComponent;
import com.adobe.acs.commons.mcp.form.FormField;
import com.adobe.acs.commons.mcp.form.PathfieldComponent;
import com.adobe.acs.commons.mcp.form.RadioComponent;
import com.adobe.acs.commons.mcp.model.GenericBlobReport;
import com.adobe.acs.commons.util.visitors.TreeFilteringResourceVisitor;
import com.day.cq.commons.jcr.JcrConstants;
import com.day.cq.dam.api.DamConstants;

/**
* Replace folder thumbnails under a user-definable set of circumstances As a business user, I would like an easy way to
* scan and repair missing thumbnails, or just regenerate all thumbnails under a given tree of the DAM.
Expand Down Expand Up @@ -83,16 +83,8 @@ public boolean shouldReplace(Resource r) throws Exception {

public static final String FOLDER_THUMBNAIL = "/jcr:content/folderThumbnail";

private static Map<String, Object> THUMBNAIL_PARAMS = new HashMap<>();

static {
THUMBNAIL_PARAMS.put("width", "200");
THUMBNAIL_PARAMS.put("height", "120");
}

private static final int PLACEHOLDER_SIZE = 1024;

private RequestResponseFactory requestFactory;
private SlingRequestProcessor slingProcessor;

@FormField(name = "Starting Path",
Expand All @@ -113,8 +105,7 @@ public boolean shouldReplace(Resource r) throws Exception {

private transient List<String> foldersToReplace = Collections.synchronizedList(new ArrayList<>());

public RefreshFolderTumbnails(RequestResponseFactory reqRspFactory, SlingRequestProcessor slingProcessor) {
this.requestFactory = reqRspFactory;
public RefreshFolderTumbnails(SlingRequestProcessor slingProcessor) {
this.slingProcessor = slingProcessor;
}

Expand Down Expand Up @@ -197,12 +188,20 @@ private void rebuildThumbnails(ActionManager manager) {
}

private void rebuildThumbnail(ResourceResolver rr, String folderPath) throws ServletException, IOException {
HttpServletRequest req = requestFactory.createRequest("GET", folderPath + ".folderthumbnail.jpg", THUMBNAIL_PARAMS);
try (NullOutputStream out = new NullOutputStream()) {
HttpServletResponse res = requestFactory.createResponse(out);
slingProcessor.processRequest(req, res, rr);
res.flushBuffer();
Resource resource = rr.getResource(folderPath);
if (resource == null) {
throw new IllegalArgumentException("Resource not found at " + folderPath);
}
HttpServletRequest req = Builders.newRequestBuilder(resource)
.withRequestMethod("GET")
.withSelectors("folderthumbnail")
.withExtension("jpg")
.withParameter("width", "200")
.withParameter("height", "120")
.build();
HttpServletResponse res = Builders.newResponseBuilder().build();
slingProcessor.processRequest(req, res, rr);
res.flushBuffer();
record(folderPath, "Rebuild", "Thumbnail was rebuilt");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import com.adobe.cq.dam.cfm.VariationTemplate;
import com.adobe.cq.dam.cfm.VersionDef;
import com.adobe.cq.dam.cfm.VersionedContent;
import com.day.cq.tagging.Tag;

import java.util.Calendar;
import java.util.HashMap;
Expand Down Expand Up @@ -176,5 +177,27 @@ public void removeVariation(String name) throws ContentFragmentException {
public Calendar getLastModifiedDeep() throws ContentFragmentException {
return Calendar.getInstance();
}


@Override
public @Nullable Calendar getLastModifiedDate() {
return Calendar.getInstance();
}

@Override
public @NotNull Tag[] getTags() throws ContentFragmentException {
return new Tag[0];
}

@Override
public @NotNull Tag[] getVariationTags(@NotNull String arg0) throws ContentFragmentException {
return new Tag[0];
}

@Override
public void setTags(@NotNull Tag[] arg0) throws ContentFragmentException {
}

@Override
public void setVariationTags(@NotNull Tag[] arg0, @NotNull String arg1) throws ContentFragmentException {
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -76,4 +76,9 @@ public String getContentType() {
public void setContentType(@Nullable String contentType) {

}

@Override
public @Nullable Calendar getLastModified() {
return null;
}
}
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@
</sonar.issue.ignore.multicriteria.e1.resourceKey>

<!-- the minimum AEM 6.5 version being supported -->
<aem.classic.api.version>6.5.10.0002</aem.classic.api.version>
<aem.classic.api.version>6.5.21.0000</aem.classic.api.version>
<!-- the minimum AEMaaCS version being supported -->
<aem.sdk.api.version>2023.11.14227.20231108T162349Z-231100</aem.sdk.api.version>

Expand Down
Loading