Skip to content

Commit

Permalink
#30669 remove boolean param
Browse files Browse the repository at this point in the history
  • Loading branch information
valentinogiardino committed Nov 21, 2024
1 parent f6814a2 commit 9c82d66
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,17 @@
@ApplicationScoped
public class ContentImportHelper {

private static final String CMD_PREVIEW = "preview";
private static final String CMD_PUBLISH = "publish";

private JobQueueManagerAPI jobQueueManagerAPI;
private JobQueueManagerHelper jobQueueManagerHelper;

@Inject
public ContentImportHelper(JobQueueManagerAPI jobQueueManagerAPI, JobQueueManagerHelper jobQueueManagerHelper) {
public ContentImportHelper(final JobQueueManagerAPI jobQueueManagerAPI, final JobQueueManagerHelper jobQueueManagerHelper) {
this.jobQueueManagerAPI = jobQueueManagerAPI;
this.jobQueueManagerHelper = jobQueueManagerHelper;
}

public ContentImportHelper() {
//default constructor Mandatory for CDI
}

@PostConstruct
Expand All @@ -55,15 +53,15 @@ public void onDestroy() {
/**
* Creates a content import job with the provided parameters
*
* @param preview Whether this is a preview job
* @param command Whether this is a preview job
* @param queueName The name of the queue to submit the job to
* @param params The import parameters
* @param user The user initiating the import
* @param request The HTTP request
* @return The ID of the created job
*/
public String createJob(
final boolean preview,
final String command,
final String queueName,
final ContentImportParams params,
final User user,
Expand All @@ -72,7 +70,7 @@ public String createJob(
params.checkValid();
params.getForm().checkValid();

final Map<String, Object> jobParameters = createJobParameters(preview, params, user, request);
final Map<String, Object> jobParameters = createJobParameters(command, params, user, request);
processFileUpload(params, jobParameters, request);

return jobQueueManagerAPI.createJob(queueName, jobParameters);
Expand All @@ -82,15 +80,15 @@ public String createJob(
* Creates the job parameters map from the provided inputs
*/
private Map<String, Object> createJobParameters(
final boolean preview,
final String command,
final com.dotcms.rest.api.v1.contentImport.ContentImportParams params,
final User user,
final HttpServletRequest request) throws JsonProcessingException, DotDataException {
final HttpServletRequest request) throws JsonProcessingException {

final Map<String, Object> jobParameters = new HashMap<>();

// Add required parameters
jobParameters.put("cmd", preview ? CMD_PREVIEW : CMD_PUBLISH);
jobParameters.put("cmd", command);
jobParameters.put("userId", user.getUserId());
jobParameters.put("contentType", params.getForm().getContentType());
jobParameters.put("workflowActionId", params.getForm().getWorkflowActionId());
Expand All @@ -111,7 +109,7 @@ private void addOptionalParameters(
final com.dotcms.rest.api.v1.contentImport.ContentImportParams params,
final Map<String, Object> jobParameters) throws JsonProcessingException {

final com.dotcms.rest.api.v1.contentImport.ContentImportForm form = params.getForm();
final ContentImportForm form = params.getForm();

if (form.getLanguage() != null && !form.getLanguage().isEmpty()) {
jobParameters.put("language", form.getLanguage());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ public void setContentDisposition(FormDataContentDisposition contentDisposition)
this.contentDisposition = contentDisposition;
}

public void setJsonForm(String jsonForm) {
this.jsonForm = jsonForm;
}

public String getJsonForm() {
return jsonForm;
}
Expand All @@ -61,7 +65,7 @@ public void setForm(ContentImportForm form) {
*/
public ContentImportForm getForm() throws JsonProcessingException {
if (null == form && (null != jsonForm && !jsonForm.isEmpty())) {
form = new ObjectMapper().readValue(jsonForm, com.dotcms.rest.api.v1.contentImport.ContentImportForm.class);
form = new ObjectMapper().readValue(jsonForm, ContentImportForm.class);
}
return form;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.dotcms.rest.WebResource;
import com.dotmarketing.exception.DotDataException;
import com.fasterxml.jackson.core.JsonProcessingException;
import graphql.VisibleForTesting;

import javax.inject.Inject;
import javax.servlet.http.HttpServletRequest;
Expand All @@ -16,15 +17,19 @@
public class ContentImportResource {

private final WebResource webResource;
private final com.dotcms.rest.api.v1.contentImport.ContentImportHelper importHelper;
private final ContentImportHelper importHelper;
private final String IMPORT_QUEUE_NAME = "importContentlets";

//TODO move to a common place
private static final String CMD_PREVIEW = "preview";
private static final String CMD_PUBLISH = "publish";

@Inject
public ContentImportResource(final com.dotcms.rest.api.v1.contentImport.ContentImportHelper importHelper) {
public ContentImportResource(final ContentImportHelper importHelper) {
this(new WebResource(), importHelper);
}

public ContentImportResource(WebResource webResource, com.dotcms.rest.api.v1.contentImport.ContentImportHelper importHelper) {
public ContentImportResource(final WebResource webResource, final ContentImportHelper importHelper) {
this.webResource = webResource;
this.importHelper = importHelper;
}
Expand All @@ -48,7 +53,7 @@ public ContentImportResource(WebResource webResource, com.dotcms.rest.api.v1.con
@Produces(MediaType.APPLICATION_JSON)
public ResponseEntityView<String> importContent(
@Context final HttpServletRequest request,
@BeanParam final com.dotcms.rest.api.v1.contentImport.ContentImportParams params)
@BeanParam final ContentImportParams params)
throws DotDataException, JsonProcessingException {
final var initDataObject = new WebResource.InitBuilder(webResource)
.requiredBackendUser(true)
Expand All @@ -57,7 +62,7 @@ public ResponseEntityView<String> importContent(
.rejectWhenNoUser(true)
.init();

final String jobId = importHelper.createJob(false, IMPORT_QUEUE_NAME, params, initDataObject.getUser(), request);
final String jobId = importHelper.createJob(CMD_PUBLISH, IMPORT_QUEUE_NAME, params, initDataObject.getUser(), request);
return new ResponseEntityView<>(jobId);
}
}

0 comments on commit 9c82d66

Please sign in to comment.