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

Cdi demo #29970

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft

Cdi demo #29970

Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ private static enum TransactionErrorEnum {
@Advice.OnMethodEnter(inline = false)
public static TransactionInfo enter(@Advice.Origin("#m") String methodName) throws DotDataException {

System.out.println("Method name: " + methodName);

TransactionInfo info = null;
boolean isLocalTransaction = false;
boolean isNewConnection = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@
import java.util.Optional;
import java.util.function.Function;
import java.util.stream.Collectors;
import javax.enterprise.context.ApplicationScoped;
import javax.inject.Inject;

import static com.dotmarketing.portlets.contentlet.model.Contentlet.DISABLED_WYSIWYG_KEY;
import static com.dotmarketing.portlets.contentlet.model.Contentlet.IDENTIFIER_KEY;
Expand All @@ -81,6 +83,7 @@
* which reads the contentlet from the columns located in the contentlet table.
* This is meant to deal with a json representation of contentlet stored in only one column.
*/
@ApplicationScoped
public class ContentletJsonAPIImpl implements ContentletJsonAPI {

private static final BinaryFileFilter binaryFileFilter = new BinaryFileFilter();
Expand All @@ -92,6 +95,9 @@ public class ContentletJsonAPIImpl implements ContentletJsonAPI {
final FolderAPI folderAPI;
final HostAPI hostAPI;

@Inject
ContentletJsonHelper helper;

/**
* API-Parametrized constructor
* @param identifierAPI
Expand Down Expand Up @@ -136,7 +142,7 @@ public String toJson(final com.dotmarketing.portlets.contentlet.model.Contentlet
throws JsonProcessingException, DotDataException {

final com.dotmarketing.portlets.contentlet.model.Contentlet copy = new com.dotmarketing.portlets.contentlet.model.Contentlet(contentlet);
return ContentletJsonHelper.INSTANCE.get().writeAsString(toImmutable(copy));
return helper.writeAsString(toImmutable(copy));
}

/**
Expand Down Expand Up @@ -541,7 +547,7 @@ List<String> findSelectedCategories(final CategoryField categoryField, final Con
* @throws JsonProcessingException
*/
public Contentlet immutableFromJson(final String json) throws JsonProcessingException {
return ContentletJsonHelper.INSTANCE.get().immutableFromJson(json);
return helper.immutableFromJson(json);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,14 @@
import java.util.Collections;
import java.util.List;
import java.util.Optional;
import javax.enterprise.context.ApplicationScoped;

/**
* Contentlet Json related logic falls here
* In case we need to parse stuff outside an API
* For example: We do not use APIs in our UpgradeTasks etc..
*/
@ApplicationScoped
public class ContentletJsonHelper {

/**
Expand Down Expand Up @@ -109,6 +111,7 @@ public ObjectMapper objectMapper() {
return this.objectMapper.get();
}


public enum INSTANCE {
INSTANCE;
private final ContentletJsonHelper helper = new ContentletJsonHelper();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import com.dotcms.browser.BrowserAPIImpl;
import com.dotcms.business.SystemAPI;
import com.dotcms.business.SystemAPIImpl;
import com.dotcms.cdi.CDIUtils;
import com.dotcms.cluster.business.ServerAPI;
import com.dotcms.cluster.business.ServerAPIImpl;
import com.dotcms.cms.login.LoginServiceAPI;
Expand Down Expand Up @@ -171,6 +172,7 @@

import java.io.Closeable;
import java.io.IOException;
import java.util.Optional;
import java.util.Queue;
import java.util.TimeZone;
import java.util.concurrent.ConcurrentLinkedQueue;
Expand Down Expand Up @@ -339,7 +341,8 @@ public static RoleAPI getRoleAPI() {
* @return The {@link UserAPI} class.
*/
public static UserAPI getUserAPI() {
return (UserAPI)getInstance(APIIndex.USER_API);
final Optional<UserAPI> bean = CDIUtils.getBean(UserAPI.class);
return bean.orElseGet(() -> (UserAPI) getInstance(APIIndex.USER_API));
}

private static final Lazy<MailAPI> lazyMail = Lazy.of(MailAPIImpl::new);
Expand Down Expand Up @@ -1116,7 +1119,8 @@ public static DeterministicIdentifierAPI getDeterministicIdentifierAPI(){
* @return the instance
*/
public static ContentletJsonAPI getContentletJsonAPI(){
return (ContentletJsonAPI) getInstance(APIIndex.CONTENTLET_JSON_API);
final Optional<ContentletJsonAPI> bean = CDIUtils.getBean(ContentletJsonAPI.class);
return bean.orElseGet(() -> (ContentletJsonAPI) getInstance(APIIndex.CONTENTLET_JSON_API));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import com.liferay.portal.util.PropsUtil;
import com.liferay.util.GetterUtil;
import io.vavr.control.Try;
import javax.enterprise.context.ApplicationScoped;
import org.apache.commons.lang.StringUtils;

import java.text.MessageFormat;
Expand All @@ -57,10 +58,10 @@
* @version 1.9
* @since 1.6
*/
@ApplicationScoped
public class UserAPIImpl implements UserAPI {

private final UserFactory userFactory;
private final UserFactoryLiferay userFactoryLiferay;
private final PermissionAPI permissionAPI;
private final UserProxyAPI userProxyAPI;
private final BundleAPI bundleAPI;
Expand All @@ -70,7 +71,6 @@ public class UserAPIImpl implements UserAPI {
*/
public UserAPIImpl() {
userFactory = FactoryLocator.getUserFactory();
userFactoryLiferay = FactoryLocator.getUserFactoryLiferay();
permissionAPI = APILocator.getPermissionAPI();
userProxyAPI = APILocator.getUserProxyAPI();
bundleAPI = APILocator.getBundleAPI();
Expand Down
Loading