All Downloads are FREE. Search and download functionalities are using the official Maven repository.
Please wait. This can take some minutes ...
Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance.
Project price only 1 $
You can buy this project and download/modify it how often you want.
com.adobe.cq.social.commons.comments.api.AbstractCommentCollectionConfiguration Maven / Gradle / Ivy
/*************************************************************************
*
* ADOBE CONFIDENTIAL
* __________________
*
* Copyright 2013 Adobe Systems Incorporated
* All Rights Reserved.
*
* NOTICE: All information contained herein is, and remains
* the property of Adobe Systems Incorporated and its suppliers,
* if any. The intellectual and technical concepts contained
* herein are proprietary to Adobe Systems Incorporated and its
* suppliers and are protected by trade secret or copyright law.
* Dissemination of this information or reproduction of this material
* is strictly forbidden unless prior written permission is obtained
* from Adobe Systems Incorporated.
**************************************************************************/
package com.adobe.cq.social.commons.comments.api;
import java.util.AbstractMap;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map.Entry;
import javax.annotation.Nonnull;
import org.apache.commons.lang3.StringUtils;
import org.apache.sling.api.resource.Resource;
import org.apache.sling.api.resource.ResourceUtil;
import org.apache.sling.api.resource.ValueMap;
import com.adobe.cq.social.commons.CommentSystem;
import com.adobe.cq.social.scf.CollectionPagination;
import com.adobe.cq.social.scf.core.CollectionSortedOrder;
import com.fasterxml.jackson.annotation.JsonProperty;
/**
* Base implementation of the {@link CommentCollectionConfiguration}.
*/
public class AbstractCommentCollectionConfiguration implements CommentCollectionConfiguration {
private boolean allowsVoting;
private boolean isRTEEnabled;
private boolean allowsAttachment;
private final boolean allowsTranslateAllButton;
private final boolean allowsFlagging;
private final boolean allowsClose;
private final boolean allowsPin;
private final boolean allowsDeny;
private final boolean allowsEdit;
private final boolean allowsReply;
private final boolean allowsFollowing;
private final boolean allowsSubscriptions;
private final boolean allowsFeaturedContent;
private boolean allowsDelete;
private boolean allowsMove;
private boolean allowsCustomFlagReason = true;
private int pageSize = 10;
private final ValueMap configValueMap;
private final CollectionSortedOrder sortOrder;
private final String[] sortField;
private final String[] sortFieldOrder;
private final String[] sortByList;
private List> sortFields = new ArrayList>();
private String timeSelector = PV_DEFAULT_ANALYTICS_TIME_SELECTOR;
private List sortByItemsList = new ArrayList();
private final int thumbnailSize;
private boolean doNotGetRepliesOnListingPage;
/**
* Constructor.
* @param commentSystem the {@link CommentSystem} instance of the CommentCollection
*/
public AbstractCommentCollectionConfiguration(final Resource commentSystem) {
this(ResourceUtil.getValueMap(commentSystem));
}
/**
* Constructor.
* @param vm properties valuemap to use for the configuration
*/
public AbstractCommentCollectionConfiguration(@Nonnull final ValueMap vm) {
allowsVoting =
vm.get(CommentCollectionConfiguration.PN_ALLOW_VOTING,
CommentCollectionConfiguration.PV_DEFAULT_ALLOW_VOTING);
allowsEdit = true; // cs.allowsEdit();
pageSize = vm.get(PN_MAX_ITEMS_PER_PAGE, CollectionPagination.DEFAULT_PAGE_SIZE);
allowsTranslateAllButton = vm.get(PN_ALLOW_TRANSLATE_ALL, PV_DEFAULT_ALLOW_TRANSLATE_ALL);
allowsCustomFlagReason = vm.get(PN_ALLOW_CUSTOM_FLAGREASON, PV_DEFAULT_ALLOW_CUSTOM_FLAGREASON);
allowsAttachment = vm.get(PN_ALLOW_ATTACHMENT, PV_DEFAULT_ALLOW_ATTACHMENT);
isRTEEnabled = vm.get(PN_RTE_ENABLED, PV_DEFAULT_RTE_ENABLED);
allowsDeny = vm.get(PN_ALLOW_DENY, PV_DEFAULT_ALLOW_DENY);
allowsFlagging = vm.get(PN_ALLOW_FLAGGING, PV_DEFAULT_ALLOW_FLAGGING);
allowsFollowing = vm.get(PN_ALLOW_FOLLOWING, PV_DEFAULT_ALLOW_FOLLOWING);
allowsSubscriptions = vm.get(PN_ALLOW_SUBSCRIPTIONS, PV_DEFAULT_ALLOW_SUBSCRIPTIONS);
allowsReply = vm.get(PN_ALLOW_REPLIES, PV_DEFAULT_ALLOW_REPLIES);
allowsMove = vm.get(PN_ALLOW_MOVE, PV_DEFAULT_ALLOW_MOVE);
allowsClose = vm.get(PN_ALLOW_CLOSE, PV_DEFAULT_ALLOW_CLOSE);
allowsPin = vm.get(PN_ALLOW_PINNING, PV_DEFAULT_ALLOW_PIN);
allowsDelete = vm.get(PN_ALLOW_DELETE_COMMENTS, PV_DEFAULT_ALLOW_DELETE_COMMENTS);
allowsFeaturedContent = vm.get(PN_ALLOW_FEATURED_CONTENT, PV_DEFAULT_ALLOW_FEATURED_CONTENT);
thumbnailSize = vm.get(THUMBNAIL_SIZE_PROPERTY, THUMBNAIL_DEFAULT_SIZE);
doNotGetRepliesOnListingPage = vm.get(PN_DO_NOT_GET_REPLIES_ON_LISTING_PAGE, PV_DEFAULT_DO_NOT_GET_REPLIES_ON_LISTING_PAGE);
final String sortOrderValue = vm.get(PN_SORT_ORDER, "DESC");
this.sortField = vm.get(PN_SORT_FIELD, new String[]{PV_DEFAULT_SORT_FIELD});
this.sortFieldOrder = vm.get(PN_SORT_FIELD_ORDER, new String[0]);
this.sortByList =
vm.get(SORT_BY, new String[]{PV_DEFAULT_NEWEST, PV_DEFAULT_SORT_FIELD, PV_DEFAULT_LAST_UPDATED});
this.timeSelector = vm.get(ANALYTICS_TIME_SELECTOR, timeSelector);
final int sortFieldOrderLength = sortFieldOrder.length;
for (int i = 0; i < sortByList.length; i++) {
sortByItemsList.add(sortByList[i]);
}
for (int i = 0; i < sortField.length; i++) {
String orderString = PV_SORT_DESC;
if (i < sortFieldOrderLength) {
orderString = sortFieldOrder[i];
}
boolean ascendingOrder = false;
if (StringUtils.equals(orderString, PV_SORT_ASC)) {
ascendingOrder = true;
}
// The conversion of jcr_ fields to jcr: for ordering should have been done on client side
// Changing it on server to reduce touch points for the change
sortFields.add(new AbstractMap.SimpleEntry(sortField[i].replace("jcr_", "jcr:"), ascendingOrder));
}
this.sortOrder =
StringUtils.equalsIgnoreCase(PV_SORT_ASC, sortOrderValue) ? CollectionSortedOrder.DEFAULT_ORDER
: CollectionSortedOrder.REVERSED_ORDER;
this.configValueMap = vm;
}
@Override
@JsonProperty("thumbnailSize")
public int getThumbNailSize() {
return thumbnailSize;
}
@Override
@JsonProperty("isVotingAllowed")
public boolean isVotingAllowed() {
return allowsVoting;
}
@Override
@JsonProperty("isAttachmentAllowed")
public boolean isAttachmentAllowed() {
return allowsAttachment;
}
@Override
@JsonProperty("isRTEEnabled")
public boolean isRTEEnabled() {
return isRTEEnabled;
}
@Override
@JsonProperty("isCustomFlagReasonAllowed")
public boolean isCustomFlagReasonAllowed() {
return allowsCustomFlagReason;
}
@Override
@JsonProperty("isTranslateAllButtonAllowed")
public boolean isTranslateAllButtonAllowed() {
return allowsTranslateAllButton;
}
@Override
public int getPageSize() {
return this.pageSize;
}
@Override
@JsonProperty("isFlaggingAllowed")
public boolean isFlaggingAllowed() {
return allowsFlagging;
}
@Override
@JsonProperty("isCloseAllowed")
public boolean isCloseAllowed() {
return allowsClose;
}
@Override
@JsonProperty("isPinAllowed")
public boolean isPinAllowed() {
return allowsPin;
}
@Override
@JsonProperty("isDenyAllowed")
public boolean isDenyAllowed() {
return allowsDeny;
}
@Override
@JsonProperty("isEditAllowed")
public boolean isEditAllowed() {
return allowsEdit;
}
@Override
@JsonProperty("isReplyAllowed")
public boolean isReplyAllowed() {
return allowsReply;
}
@Override
@JsonProperty("isDeleteAllowed")
public boolean isDeleteAllowed() {
return allowsDelete;
}
protected void setAllowsMove(final boolean allowsMove) {
this.allowsMove = allowsMove;
}
protected void setAllowsDelete(final boolean flag) {
allowsDelete = flag;
}
protected void setAllowsAttachment(final boolean flag) {
allowsAttachment = flag;
}
protected void setAllowsVoting(final boolean flag) {
allowsVoting = flag;
}
protected void setRTEEnabled(final boolean flag) {
isRTEEnabled = flag;
}
/**
* Gets the configuration value map that this configuration object is based off of.
* @return a value map that has configuration details in it.
*/
@Nonnull
protected ValueMap getConfigValueMap() {
return this.configValueMap;
}
@Override
public boolean isFollowingAllowed() {
return allowsFollowing;
}
@Override
public boolean isSubscriptionsAllowed() {
return allowsSubscriptions;
}
@Override
public CollectionSortedOrder getSortOrder() {
return this.sortOrder;
}
@Override
public boolean isMoveAllowed() {
return allowsMove;
}
@Override
public List> getSortFields() {
return sortFields;
}
@Override
public List getSortByItemsList() {
return sortByItemsList;
}
@Override
public String getAnalyticsTimeSelector() {
return timeSelector;
}
@Override
@JsonProperty("isFeaturingContentAllowed")
public boolean isFeaturingContentAllowed() {
return allowsFeaturedContent;
}
@Override
@JsonProperty("doNotGetRepliesOnListingPage")
public boolean isDoNotGetRepliesOnListingPage() {return doNotGetRepliesOnListingPage;}
}