Skip to content

Commit

Permalink
Merge branch 'main' of github.com:dotCMS/core into issue-30871-pin-ub…
Browse files Browse the repository at this point in the history
…untu-version-used-by-github
  • Loading branch information
dcolina committed Dec 11, 2024
2 parents 699f9dd + d67b5fd commit 70af725
Show file tree
Hide file tree
Showing 30 changed files with 517 additions and 344 deletions.
1 change: 1 addition & 0 deletions .github/workflows/legacy-release_maven-release-process.yml
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,7 @@ jobs:
uses: ./.github/workflows/issue_comp_release-labeling.yml
with:
new_label: 'Release : ${{ github.event.inputs.release_version }}'
rename_label: 'Next Release'
secrets:
CI_MACHINE_TOKEN: ${{ secrets.CI_MACHINE_TOKEN }}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ describe('DotPageApiService', () => {
.subscribe();

spectator.expectOne(
'/api/v1/page/render/test-url?language_id=en&com.dotmarketing.persona.id=modes.persona.no.persona&variantName=DEFAULT&depth=0&mode=PREVIEW_MODE',
'/api/v1/page/render/test-url?language_id=en&com.dotmarketing.persona.id=modes.persona.no.persona&variantName=DEFAULT&depth=0&mode=LIVE',
HttpMethod.GET
);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ export class DotPageApiService {

const isPreview = preview === 'true';
const pageType = clientHost ? 'json' : 'render';
const mode = isPreview ? PAGE_MODE.PREVIEW : PAGE_MODE.EDIT;
const mode = isPreview ? PAGE_MODE.LIVE : PAGE_MODE.EDIT;

const pageApiUrl = createPageApiUrlWithQueryParams(url, {
language_id,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -672,6 +672,13 @@ describe('withEditor', () => {
expect(store.$editorProps().iframe.opacity).toBe('1');
});

it('should not have opacity or progressBar in preview mode', () => {
patchState(store, { pageParams: { ...emptyParams, preview: 'true' } });

expect(store.$editorProps().iframe.opacity).toBe('1');
expect(store.$editorProps().progressBar).toBe(false);
});

describe('showDialogs', () => {
it('should have the value of false when we cannot edit the page', () => {
patchState(store, { canEditPage: false });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,10 @@ export function withEditor() {
const bounds = store.bounds();
const dragItem = store.dragItem();
const isEditState = store.isEditState();
const isLoading = !isClientReady || store.status() === UVE_STATUS.LOADING;

const isPageReady = isTraditionalPage || isClientReady;
const isPreview = params?.preview === 'true';
const isPageReady = isTraditionalPage || isClientReady || isPreview;
const isLoading = !isPageReady || store.status() === UVE_STATUS.LOADING;

const { dragIsActive, isScrolling } = getEditorStates(state);

Expand All @@ -131,8 +132,6 @@ export function withEditor() {
!!contentletArea && canEditPage && isEditState && !isScrolling;

const showDropzone = canEditPage && state === EDITOR_STATE.DRAGGING;

const isPreview = params?.preview === 'true';
const showPalette = isEnterprise && canEditPage && isEditState && !isPreview;

const shouldShowSeoResults = socialMedia && ogTags;
Expand Down
11 changes: 11 additions & 0 deletions core-web/libs/sdk/client/src/lib/editor/sdk-editor.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,4 +164,15 @@ describe('DotCMSPageEditor', () => {
});
});
});

it('should isInsideEditor return false when is preview mode', () => {
Object.defineProperty(window, 'location', {
value: {
search: '?preview=true'
},
writable: true
});

expect(isInsideEditor()).toBe(false);
});
});
7 changes: 7 additions & 0 deletions core-web/libs/sdk/client/src/lib/editor/sdk-editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { DotCMSPageEditorConfig, ReorderMenuConfig } from './models/editor.model
import { INLINE_EDITING_EVENT_KEY, InlineEditEventData } from './models/inline-event.model';

import { Contentlet } from '../client/content/shared/types';
import { isPreviewMode } from '../utils';

/**
* Updates the navigation in the editor.
Expand Down Expand Up @@ -109,6 +110,12 @@ export function isInsideEditor(): boolean {
return false;
}

const preview = isPreviewMode();

if (preview) {
return false;
}

return window.parent !== window;
}

Expand Down
20 changes: 19 additions & 1 deletion core-web/libs/sdk/client/src/lib/utils/page/common-utils.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { getPageRequestParams } from './common-utils';
import { getPageRequestParams, isPreviewMode } from './common-utils';

describe('Common Utils', () => {
it('should return the correct Request Params', () => {
Expand Down Expand Up @@ -34,4 +34,22 @@ describe('Common Utils', () => {

expect(pageRequestParams).toEqual({ path: 'test' });
});

describe('Is Preview Mode', () => {
it('should return true when preview mode is enabled', () => {
jest.spyOn(window, 'location', 'get').mockReturnValueOnce({
search: '?preview=true'
} as Location);

expect(isPreviewMode()).toBe(true);
});

it('should return false when preview mode is disabled', () => {
jest.spyOn(window, 'location', 'get').mockReturnValueOnce({
search: ''
} as Location);

expect(isPreviewMode()).toBe(false);
});
});
});
12 changes: 12 additions & 0 deletions core-web/libs/sdk/client/src/lib/utils/page/common-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,15 @@ export const getPageRequestParams = ({
...finalParams
};
};

/**
* Checks if the code is running inside an editor.
*
* @return {*} {boolean}
*/
export const isPreviewMode = (): boolean => {
const queryParams = new URLSearchParams(window.location.search);
const isPreviewMode = queryParams.get('preview');

return isPreviewMode === 'true';
};
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import com.dotmarketing.exception.DotRuntimeException;
import com.dotmarketing.portlets.contentlet.model.Contentlet;
import com.dotmarketing.util.PageMode;
import com.dotmarketing.util.UtilMethods;
import com.dotmarketing.util.WebKeys;
import com.liferay.portal.model.User;
import io.vavr.control.Try;
Expand All @@ -28,8 +29,11 @@ public static Context getMockContext(Contentlet contentlet) {
return getMockContext(contentlet, APILocator.systemUser());
}

public static Context getMockContext(Contentlet contentlet, User user) {
Host host = Try.of(() -> APILocator.getHostAPI().find(contentlet.getHost(), APILocator.systemUser(), true)).getOrElse(APILocator.systemHost());
public static Context getMockContext(final Contentlet contentlet, final User user) {
final Host host = UtilMethods.isSet(contentlet.getIdentifier()) ?
Try.of(() -> APILocator.getHostAPI().find(contentlet.getHost(),
APILocator.systemUser(), true)).getOrElse(APILocator.systemHost()) :
APILocator.systemHost();
String hostName = "SYSTEM_HOST".equalsIgnoreCase(host.getIdentifier())
? Try.of(() -> APILocator.getHostAPI().findDefaultHost(APILocator.systemUser(), false).getHostname()).getOrElseThrow(DotRuntimeException::new)
: host.getHostname();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
package com.dotcms.jobs.business.api;

import com.dotcms.jobs.business.processor.JobProcessor;
import com.dotmarketing.exception.DotRuntimeException;
import com.dotmarketing.util.Logger;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import javax.enterprise.context.ApplicationScoped;
import javax.enterprise.context.Dependent;
import javax.enterprise.inject.Any;
import javax.enterprise.inject.spi.Bean;
import javax.enterprise.inject.spi.BeanManager;
import javax.inject.Inject;

/**
* Discovers all classes that implement the JobProcessor interface using CDI.
*/
@ApplicationScoped
public class JobProcessorDiscovery {

private final BeanManager beanManager;

@Inject
public JobProcessorDiscovery(BeanManager beanManager) {
this.beanManager = beanManager;
}

/**
* Default constructor required by CDI.
*/
public JobProcessorDiscovery() {
this.beanManager = null;
}

/**
* Discovers all classes that implement the JobProcessor interface using CDI. Does not create
* instances, only finds the classes.
*
* @return A list of classes that implement the JobProcessor interface.
*/
public List<Class<? extends JobProcessor>> discoverJobProcessors() {

List<Class<? extends JobProcessor>> processors = new ArrayList<>();

try {
Set<Bean<?>> beans = beanManager.getBeans(JobProcessor.class, Any.Literal.INSTANCE);

for (Bean<?> bean : beans) {
Class<?> beanClass = bean.getBeanClass();

if (JobProcessor.class.isAssignableFrom(beanClass)) {

// Validate that the bean is in the correct scope
validateScope(bean);

processors.add((Class<? extends JobProcessor>) beanClass);
Logger.debug(this, "Discovered JobProcessor: " + beanClass.getName());
}
}
} catch (Exception e) {
var errorMessage = "Error discovering JobProcessors";
Logger.error(this, errorMessage, e);
throw new DotRuntimeException(errorMessage, e);
}

if (processors.isEmpty()) {
Logger.warn(this, "No JobProcessors were discovered");
}

return processors;
}

/**
* Validates that the scope of the bean is correct for a JobProcessor.
*
* @param bean The bean to validate.
*/
private void validateScope(Bean<?> bean) {
Class<?> scope = bean.getScope();
if (scope != Dependent.class) {
throw new DotRuntimeException(
"JobProcessor " + bean.getBeanClass().getName() +
" must use @Dependent scope, found: " + scope.getName());
}
}

}
Original file line number Diff line number Diff line change
@@ -1,32 +1,44 @@
package com.dotcms.jobs.business.api;

import com.dotcms.cdi.CDIUtils;
import com.dotcms.jobs.business.error.JobProcessorInstantiationException;
import com.dotcms.jobs.business.processor.JobProcessor;
import com.dotmarketing.util.Logger;
import java.util.Optional;
import javax.enterprise.context.ApplicationScoped;

@ApplicationScoped
public class JobProcessorFactory {

public JobProcessorFactory() {
// Default constructor for CDI
}

/**
* Creates a new instance of the specified job processor class.
* First attempts to get the processor from CDI context, falls back to direct instantiation if that fails.
*
* @param processorClass The class of the job processor to create.
* @return An optional containing the new job processor instance, or an empty optional if the
* processor could not be created.
* @return A new job processor instance
* @throws JobProcessorInstantiationException if creation fails through both methods
*/
JobProcessor newInstance(
Class<? extends JobProcessor> processorClass) {
JobProcessor newInstance(Class<? extends JobProcessor> processorClass) {

Optional<? extends JobProcessor> cdiInstance = CDIUtils.getBean(processorClass);

if (cdiInstance.isPresent()) {
return cdiInstance.get();
}

// If CDI fails, try direct instantiation
return createInstance(processorClass);
}

/**
* Creates a new instance using reflection.
*/
private JobProcessor createInstance(Class<? extends JobProcessor> processorClass) {
try {
return processorClass.getDeclaredConstructor().newInstance();
} catch (Exception e) {
Logger.error(this, "Error creating job processor", e);
Logger.error(this, "Error creating job processor via reflection", e);
throw new JobProcessorInstantiationException(processorClass, e);
}
}

}
}

This file was deleted.

Loading

0 comments on commit 70af725

Please sign in to comment.