task_21363 #1
|
@ -3,6 +3,7 @@ package org.gcube.portlets.widgets.ckancontentmoderator.client;
|
||||||
import org.gcube.datacatalogue.utillibrary.shared.ItemStatus;
|
import org.gcube.datacatalogue.utillibrary.shared.ItemStatus;
|
||||||
import org.gcube.portlets.widgets.ckancontentmoderator.client.ui.MainPanel;
|
import org.gcube.portlets.widgets.ckancontentmoderator.client.ui.MainPanel;
|
||||||
import org.gcube.portlets.widgets.ckancontentmoderator.client.ui.util.ExtModal;
|
import org.gcube.portlets.widgets.ckancontentmoderator.client.ui.util.ExtModal;
|
||||||
|
import org.gcube.portlets.widgets.ckancontentmoderator.client.util.ModerationQueryStringUtil.ModerationBuilder;
|
||||||
import org.gcube.portlets.widgets.ckancontentmoderator.shared.DISPLAY_FIELD;
|
import org.gcube.portlets.widgets.ckancontentmoderator.shared.DISPLAY_FIELD;
|
||||||
|
|
||||||
import com.github.gwtbootstrap.client.ui.Modal;
|
import com.github.gwtbootstrap.client.ui.Modal;
|
||||||
|
@ -23,8 +24,13 @@ public class CkanContentModeratorWidget {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Instantiates a new ckan content moderator widget.
|
* Instantiates a new ckan content moderator widget.
|
||||||
|
*
|
||||||
|
* @param initItemStatus the init item status
|
||||||
|
* @param initOnItemName the init on item name
|
||||||
|
* @param displayFields the display fields
|
||||||
|
* @param sortByFields the sort by fields
|
||||||
*/
|
*/
|
||||||
public CkanContentModeratorWidget(ItemStatus initItemStatus, DISPLAY_FIELD[] displayFields,
|
public CkanContentModeratorWidget(ItemStatus initItemStatus, String initOnItemName, DISPLAY_FIELD[] displayFields,
|
||||||
DISPLAY_FIELD[] sortByFields) {
|
DISPLAY_FIELD[] sortByFields) {
|
||||||
mainPanel.setWidth("100%");
|
mainPanel.setWidth("100%");
|
||||||
ccux = new CheckConfigsUxController(mainPanel, initItemStatus, displayFields, sortByFields, null);
|
ccux = new CheckConfigsUxController(mainPanel, initItemStatus, displayFields, sortByFields, null);
|
||||||
|
@ -39,10 +45,25 @@ public class CkanContentModeratorWidget {
|
||||||
if (iamModerator) {
|
if (iamModerator) {
|
||||||
mainPanel.setLoggedLabelText("Logged in as Moderator");
|
mainPanel.setLoggedLabelText("Logged in as Moderator");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(initOnItemName!=null) {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Instantiates a new ckan content moderator widget.
|
||||||
|
*
|
||||||
|
* @param builder the builder
|
||||||
|
*/
|
||||||
|
public CkanContentModeratorWidget(ModerationBuilder builder) {
|
||||||
|
this(builder.getItemStatus(), builder.getItemName(), builder.getDisplayFields(), builder.getSortByFields());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Show as modal.
|
* Show as modal.
|
||||||
|
*
|
||||||
|
* @param modalTitle the modal title
|
||||||
*/
|
*/
|
||||||
public void showAsModal(String modalTitle) {
|
public void showAsModal(String modalTitle) {
|
||||||
final Modal modal = new ExtModal(true, true);
|
final Modal modal = new ExtModal(true, true);
|
||||||
|
@ -65,6 +86,11 @@ public class CkanContentModeratorWidget {
|
||||||
return mainPanel;
|
return mainPanel;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the congifs.
|
||||||
|
*
|
||||||
|
* @return the congifs
|
||||||
|
*/
|
||||||
public CkanContentModeratorCheckConfigs getCongifs() {
|
public CkanContentModeratorCheckConfigs getCongifs() {
|
||||||
return ccux.getModeratorCheckConfig();
|
return ccux.getModeratorCheckConfig();
|
||||||
}
|
}
|
||||||
|
|
|
@ -120,70 +120,6 @@ public class CkanContentModeratorWidgetController {
|
||||||
itemField.setJsonFields(Arrays.asList(display_FIELD.getJsonField() +" "+order.name().toLowerCase()));
|
itemField.setJsonFields(Arrays.asList(display_FIELD.getJsonField() +" "+order.name().toLowerCase()));
|
||||||
listSortByIF.add(itemField);
|
listSortByIF.add(itemField);
|
||||||
}
|
}
|
||||||
// ItemFieldDV itemField = new ItemFieldDV();
|
|
||||||
// itemField.setDisplayName(display_FIELD.getLabel() + " - " + SearchingFilter.ORDER.ASC);
|
|
||||||
// itemField.setJsonFields(
|
|
||||||
// Arrays.asList("extras_systemtype " + SearchingFilter.ORDER.ASC.name().toLowerCase()));
|
|
||||||
// listSortByIF.add(itemField);
|
|
||||||
//
|
|
||||||
// switch (display_FIELD) {
|
|
||||||
// case TYPE: {
|
|
||||||
// ItemFieldDV itemField = new ItemFieldDV();
|
|
||||||
// itemField.setDisplayName(display_FIELD.name() + " " + SearchingFilter.ORDER.ASC);
|
|
||||||
// itemField.setJsonFields(
|
|
||||||
// Arrays.asList("extras_systemtype " + SearchingFilter.ORDER.ASC.name().toLowerCase()));
|
|
||||||
// listSortByIF.add(itemField);
|
|
||||||
//
|
|
||||||
// ItemFieldDV itemField2 = new ItemFieldDV();
|
|
||||||
// itemField2.setDisplayName(display_FIELD.name() + " " + SearchingFilter.ORDER.DESC);
|
|
||||||
// itemField2.setJsonFields(
|
|
||||||
// Arrays.asList("extras_systemtype " + SearchingFilter.ORDER.DESC.name().toLowerCase()));
|
|
||||||
// listSortByIF.add(itemField2);
|
|
||||||
// break;
|
|
||||||
// }
|
|
||||||
// case CREATED: {
|
|
||||||
// ItemFieldDV itemField = new ItemFieldDV();
|
|
||||||
// itemField.setDisplayName(display_FIELD.name() + " " + SearchingFilter.ORDER.ASC);
|
|
||||||
// itemField.setJsonFields(
|
|
||||||
// Arrays.asList("metadata_created " + SearchingFilter.ORDER.ASC.name().toLowerCase()));
|
|
||||||
// listSortByIF.add(itemField);
|
|
||||||
//
|
|
||||||
// ItemFieldDV itemField2 = new ItemFieldDV();
|
|
||||||
// itemField2.setDisplayName(display_FIELD.name() + " " + SearchingFilter.ORDER.DESC);
|
|
||||||
// itemField2.setJsonFields(
|
|
||||||
// Arrays.asList("metadata_created " + SearchingFilter.ORDER.DESC.name().toLowerCase()));
|
|
||||||
// listSortByIF.add(itemField2);
|
|
||||||
// break;
|
|
||||||
// }
|
|
||||||
// case LAST_UPDATE: {
|
|
||||||
// ItemFieldDV itemField = new ItemFieldDV();
|
|
||||||
// itemField.setDisplayName(display_FIELD.name() + " " + SearchingFilter.ORDER.ASC);
|
|
||||||
// itemField.setJsonFields(
|
|
||||||
// Arrays.asList("metadata_modified " + SearchingFilter.ORDER.ASC.name().toLowerCase()));
|
|
||||||
// listSortByIF.add(itemField);
|
|
||||||
//
|
|
||||||
// ItemFieldDV itemField2 = new ItemFieldDV();
|
|
||||||
// itemField2.setDisplayName(display_FIELD.name() + " " + SearchingFilter.ORDER.DESC);
|
|
||||||
// itemField2.setJsonFields(
|
|
||||||
// Arrays.asList("metadata_modified " + SearchingFilter.ORDER.DESC.name().toLowerCase()));
|
|
||||||
// listSortByIF.add(itemField2);
|
|
||||||
// break;
|
|
||||||
// }
|
|
||||||
// default:
|
|
||||||
// ItemFieldDV itemField = new ItemFieldDV();
|
|
||||||
// itemField.setDisplayName(display_FIELD.name() + " " + SearchingFilter.ORDER.ASC);
|
|
||||||
// itemField.setJsonFields(
|
|
||||||
// Arrays.asList(display_FIELD.name() + " " + SearchingFilter.ORDER.ASC.name().toLowerCase()));
|
|
||||||
// listSortByIF.add(itemField);
|
|
||||||
//
|
|
||||||
// ItemFieldDV itemField2 = new ItemFieldDV();
|
|
||||||
// itemField2.setDisplayName(display_FIELD.name() + " " + SearchingFilter.ORDER.DESC);
|
|
||||||
// itemField2.setJsonFields(
|
|
||||||
// Arrays.asList(display_FIELD.name() + " " + SearchingFilter.ORDER.DESC.name().toLowerCase()));
|
|
||||||
// listSortByIF.add(itemField2);
|
|
||||||
// break;
|
|
||||||
// }
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return listSortByIF;
|
return listSortByIF;
|
||||||
|
|
|
@ -0,0 +1,209 @@
|
||||||
|
package org.gcube.portlets.widgets.ckancontentmoderator.client.util;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
|
||||||
|
import org.gcube.datacatalogue.utillibrary.shared.ItemStatus;
|
||||||
|
import org.gcube.portlets.widgets.ckancontentmoderator.client.ContentModeratorWidgetConstants;
|
||||||
|
import org.gcube.portlets.widgets.ckancontentmoderator.shared.DISPLAY_FIELD;
|
||||||
|
|
||||||
|
import com.google.gwt.core.client.GWT;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The Class ModerationQueryStringUtil.
|
||||||
|
*
|
||||||
|
* @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it
|
||||||
|
*
|
||||||
|
* May 4, 2022
|
||||||
|
*/
|
||||||
|
public class ModerationQueryStringUtil {
|
||||||
|
|
||||||
|
public static final String MODERATION_PARAMETER = "moderation";
|
||||||
|
public static final String ITEM_NAME_PARAMETER = "item_name";
|
||||||
|
public static final String STATUS_PARAMETER = "status";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The Enum MODERATION_VALUE.
|
||||||
|
*
|
||||||
|
* @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it
|
||||||
|
*
|
||||||
|
* May 4, 2022
|
||||||
|
*/
|
||||||
|
public enum MODERATION_VALUE {
|
||||||
|
show
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Instantiates a new moderation query string util.
|
||||||
|
*/
|
||||||
|
public ModerationQueryStringUtil() {
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* To moderation builder.
|
||||||
|
*
|
||||||
|
* @param decodedQueryString the decoded query string
|
||||||
|
* @return the moderation builder
|
||||||
|
*/
|
||||||
|
public ModerationBuilder toModerationBuilder(String decodedQueryString) {
|
||||||
|
ModerationBuilder mbuilder = null;
|
||||||
|
|
||||||
|
if (decodedQueryString == null || decodedQueryString.isEmpty())
|
||||||
|
return null;
|
||||||
|
|
||||||
|
String moderationValue = QueryStringUtil.getValueOfParameterInTheURL(MODERATION_PARAMETER, decodedQueryString);
|
||||||
|
|
||||||
|
MODERATION_VALUE toModerationValue = null;
|
||||||
|
// Moderation parameter in the query string has a not empty value
|
||||||
|
if (moderationValue != null) {
|
||||||
|
try {
|
||||||
|
toModerationValue = MODERATION_VALUE.valueOf(moderationValue.toLowerCase());
|
||||||
|
} catch (Exception e) {
|
||||||
|
GWT.log("Moderation value: " + moderationValue + " is not a value of " + MODERATION_VALUE.values());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (toModerationValue != null) {
|
||||||
|
|
||||||
|
mbuilder = new ModerationBuilder();
|
||||||
|
|
||||||
|
String itemNameValue = QueryStringUtil.getValueOfParameterInTheURL(ITEM_NAME_PARAMETER, decodedQueryString);
|
||||||
|
if (itemNameValue != null) {
|
||||||
|
mbuilder.setItemName(itemNameValue);
|
||||||
|
}
|
||||||
|
|
||||||
|
String statusValue = QueryStringUtil.getValueOfParameterInTheURL(STATUS_PARAMETER, decodedQueryString);
|
||||||
|
if (statusValue != null) {
|
||||||
|
try {
|
||||||
|
ItemStatus theStatus = ItemStatus.valueOf(statusValue.toUpperCase());
|
||||||
|
mbuilder.setItemStatus(theStatus);
|
||||||
|
} catch (Exception e) {
|
||||||
|
GWT.log("Error on assigning "+ItemStatus.values() +" from string "+statusValue);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return mbuilder;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The Class ModerationBuilder.
|
||||||
|
*
|
||||||
|
* @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it
|
||||||
|
*
|
||||||
|
* May 4, 2022
|
||||||
|
*/
|
||||||
|
public class ModerationBuilder {
|
||||||
|
|
||||||
|
private ItemStatus itemStatus = ItemStatus.PENDING;
|
||||||
|
private String itemName = null;
|
||||||
|
private DISPLAY_FIELD[] displayFields = DISPLAY_FIELD.values();
|
||||||
|
private DISPLAY_FIELD[] sortByFields = ContentModeratorWidgetConstants.DEFAULT_SORT_BY_FIELDS;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Instantiates a new moderation builder.
|
||||||
|
*/
|
||||||
|
ModerationBuilder() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the item name.
|
||||||
|
*
|
||||||
|
* @return the item name
|
||||||
|
*/
|
||||||
|
public String getItemName() {
|
||||||
|
return itemName;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the item name.
|
||||||
|
*
|
||||||
|
* @param itemName the new item name
|
||||||
|
*/
|
||||||
|
public void setItemName(String itemName) {
|
||||||
|
this.itemName = itemName;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the item status.
|
||||||
|
*
|
||||||
|
* @return the item status
|
||||||
|
*/
|
||||||
|
public ItemStatus getItemStatus() {
|
||||||
|
return itemStatus;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the display fields.
|
||||||
|
*
|
||||||
|
* @return the display fields
|
||||||
|
*/
|
||||||
|
public DISPLAY_FIELD[] getDisplayFields() {
|
||||||
|
return displayFields;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the sort by fields.
|
||||||
|
*
|
||||||
|
* @return the sort by fields
|
||||||
|
*/
|
||||||
|
public DISPLAY_FIELD[] getSortByFields() {
|
||||||
|
return sortByFields;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the item status.
|
||||||
|
*
|
||||||
|
* @param itemStatus the new item status
|
||||||
|
*/
|
||||||
|
public void setItemStatus(ItemStatus itemStatus) {
|
||||||
|
this.itemStatus = itemStatus;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the display fields.
|
||||||
|
*
|
||||||
|
* @param displayFields the new display fields
|
||||||
|
*/
|
||||||
|
public void setDisplayFields(DISPLAY_FIELD[] displayFields) {
|
||||||
|
this.displayFields = displayFields;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the sort by fields.
|
||||||
|
*
|
||||||
|
* @param sortByFields the new sort by fields
|
||||||
|
*/
|
||||||
|
public void setSortByFields(DISPLAY_FIELD[] sortByFields) {
|
||||||
|
this.sortByFields = sortByFields;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
StringBuilder builder = new StringBuilder();
|
||||||
|
builder.append("ModerationBuilder [itemStatus=");
|
||||||
|
builder.append(itemStatus);
|
||||||
|
builder.append(", itemName=");
|
||||||
|
builder.append(itemName);
|
||||||
|
builder.append(", displayFields=");
|
||||||
|
builder.append(Arrays.toString(displayFields));
|
||||||
|
builder.append(", sortByFields=");
|
||||||
|
builder.append(Arrays.toString(sortByFields));
|
||||||
|
builder.append("]");
|
||||||
|
return builder.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Base 64 decode.
|
||||||
|
*
|
||||||
|
* @param a the a
|
||||||
|
* @return the string
|
||||||
|
*/
|
||||||
|
protected static native String base64decode(String a) /*-{
|
||||||
|
return window.atob(a);
|
||||||
|
}-*/;
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,71 @@
|
||||||
|
package org.gcube.portlets.widgets.ckancontentmoderator.client.util;
|
||||||
|
|
||||||
|
import com.google.gwt.core.client.GWT;
|
||||||
|
import com.google.gwt.http.client.URL;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The Class QueryStringUtil.
|
||||||
|
*
|
||||||
|
* @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it
|
||||||
|
*
|
||||||
|
* May 3, 2022
|
||||||
|
*/
|
||||||
|
public class QueryStringUtil {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the value of parameter in the URL.
|
||||||
|
*
|
||||||
|
* @param paramName the param name
|
||||||
|
* @param url the url
|
||||||
|
* @return the value of parameter in the URL
|
||||||
|
*/
|
||||||
|
public static String getValueOfParameterInTheURL(String paramName, String url) {
|
||||||
|
int index = url.toLowerCase().indexOf(paramName.toLowerCase() + "="); // ADDING CHAR "=" IN TAIL TO BE SURE THAT
|
||||||
|
// IT IS A PARAMETER
|
||||||
|
String value = null;
|
||||||
|
if (index > -1) {
|
||||||
|
|
||||||
|
int start = index + paramName.length() + 1; // add +1 for char '='
|
||||||
|
String sub = url.substring(start, url.length());
|
||||||
|
int indexOfSeparator = sub.indexOf("&");
|
||||||
|
int end = indexOfSeparator != -1 ? indexOfSeparator : sub.length();
|
||||||
|
value = sub.substring(0, end);
|
||||||
|
}
|
||||||
|
|
||||||
|
GWT.log("Returning value " + value + " for the parameter: " + paramName);
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Base 64 decode.
|
||||||
|
*
|
||||||
|
* @param a the a
|
||||||
|
* @return the string
|
||||||
|
*/
|
||||||
|
private static native String base64decode(String a) /*-{
|
||||||
|
return window.atob(a);
|
||||||
|
}-*/;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Base 64 decode query string.
|
||||||
|
*
|
||||||
|
* @param base64EncodedQueryString the base 64 encoded query string
|
||||||
|
* @return the string
|
||||||
|
*/
|
||||||
|
public static String base64DecodeQueryString(String base64EncodedQueryString) {
|
||||||
|
|
||||||
|
if (base64EncodedQueryString != null && !base64EncodedQueryString.isEmpty()) {
|
||||||
|
String b64DecodedQueryStringParameter = base64decode(base64EncodedQueryString);
|
||||||
|
GWT.log("Base64 Decoded string is: " + b64DecodedQueryStringParameter);
|
||||||
|
b64DecodedQueryStringParameter = URL.decodeQueryString(b64DecodedQueryStringParameter); // equals should be
|
||||||
|
// encoded too (%3D)
|
||||||
|
GWT.log("Decoded query string is: " + b64DecodedQueryStringParameter);
|
||||||
|
|
||||||
|
return b64DecodedQueryStringParameter;
|
||||||
|
}
|
||||||
|
|
||||||
|
return base64EncodedQueryString;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue