@ -14,6 +14,7 @@ import org.gcube.portlets.gcubeckan.gcubeckandatacatalog.client.event.ShowRevert
import org.gcube.portlets.gcubeckan.gcubeckandatacatalog.client.resource.CkanPortletResources ;
import org.gcube.portlets.gcubeckan.gcubeckandatacatalog.shared.BeanUserInOrgGroupRole ;
import org.gcube.portlets.gcubeckan.gcubeckandatacatalog.shared.CkanConnectorAccessPoint ;
import org.gcube.portlets.gcubeckan.gcubeckandatacatalog.shared.ManageProductResponse ;
import com.google.gwt.core.client.GWT ;
import com.google.gwt.event.logical.shared.ResizeEvent ;
@ -49,7 +50,7 @@ public class GCubeCkanDataCatalogPanel extends BaseViewTemplate {
private RootPanel rootPanel ;
private HandlerManager eventBus ;
private CkanConnectorAccessPoint ckanAccessPoint ;
private boolean isManageProductToShow = false ;
private ManageProductResponse manageProductResponse = null ;
private String viewPerVREPath = null ;
private static String latestSelectedProductIdentifier ;
public static final int IFRAME_FIX_HEIGHT = 1800 ;
@ -58,18 +59,15 @@ public class GCubeCkanDataCatalogPanel extends BaseViewTemplate {
/ * *
* Instantiates a new g cube ckan data catalog panel .
*
* @param rootPanel
* the root panel
* @param eventManager
* the event manager
* @param rootPanel the root panel
* @param eventManager the event manager
* /
public GCubeCkanDataCatalogPanel (
RootPanel rootPanel , HandlerManager eventManager ) {
public GCubeCkanDataCatalogPanel ( RootPanel rootPanel , HandlerManager eventManager ) {
this . rootPanel = rootPanel ;
this . eventBus = eventManager ;
// postMessage(obj.toString(), ckanFramePanel.getFrame());
// postMessage(obj.toString(), ckanFramePanel.getFrame());
// send message about gateway url
obj = new JSONObject ( ) ;
String landingPageVREs = Window . Location . getProtocol ( ) + "//" + Window . Location . getHostName ( ) + "/explore" ;
@ -86,7 +84,7 @@ public class GCubeCkanDataCatalogPanel extends BaseViewTemplate {
// decode parameters (they could have been encoded)
final Map < String , String > paramsMap = new HashMap < String , String > ( 2 ) ;
String queryParameters = Window . Location . getQueryString ( ) ;
if ( queryParameters ! = null & & ! queryParameters . isEmpty ( ) ) {
if ( queryParameters ! = null & & ! queryParameters . isEmpty ( ) ) {
String decoded = URL . decodeQueryString ( queryParameters ) ; // equals should be encoded too (%3D)
String [ ] params = decoded . substring ( decoded . indexOf ( "?" ) + 1 ) . split ( "&" ) ;
for ( int i = 0 ; i < params . length ; i + + ) {
@ -96,19 +94,18 @@ public class GCubeCkanDataCatalogPanel extends BaseViewTemplate {
GWT . log ( "Extracted parameters are " + paramsMap ) ;
}
String pathParameter = paramsMap . get ( GCubeCkanDataCatalog . GET_PATH_PARAMETER ) ; // Window.Location.getParameter(GCubeCkanDataCatalog.GET_PATH_PARAMETER);
String pathParameter = paramsMap . get ( GCubeCkanDataCatalog . GET_PATH_PARAMETER ) ; // Window.Location.getParameter(GCubeCkanDataCatalog.GET_PATH_PARAMETER);
String queryParameter = paramsMap . get ( GCubeCkanDataCatalog . GET_QUERY_PARAMETER ) ; // Window.Location.getParameter(GCubeCkanDataCatalog.GET_QUERY_PARAMETER);
String browserLocationURL = getBrowserLocationURL ( ) ;
GCubeCkanDataCatalog . service . getCKanConnector ( browserLocationURL ,
pathParameter , queryParameter ,
GCubeCkanDataCatalog . service . getCKanConnector ( browserLocationURL , pathParameter , queryParameter ,
new AsyncCallback < CkanConnectorAccessPoint > ( ) {
@Override
public void onSuccess ( CkanConnectorAccessPoint ckan ) {
if ( ckan . isOutsideLoginOnPortal ( ) ) {
if ( ckan . isOutsideLoginOnPortal ( ) ) {
// the portlet is outside the portal and no user is logged
// in show only home and statistics
@ -123,36 +120,37 @@ public class GCubeCkanDataCatalogPanel extends BaseViewTemplate {
ckanAccessPoint = ckan ;
instanceCkanFrame ( ckan . buildURI ( ) ) ;
GCubeCkanDataCatalogPanel . this . rootPanel . remove ( loading ) ;
String browserLocationURL = getBrowserLocationURL ( ) ;
// check if view per organisation is enabled
//and performing some actions in this case (e.g. removed the management buttons, etc.)
GCubeCkanDataCatalog . service . isViewPerVREEnabled ( browserLocationURL , new AsyncCallback < String > ( ) {
@Override
public void onSuccess ( String result ) {
GWT . log ( "isViewPerVREEnabled?: " + result ) ;
if ( result ! = null & & ! result . isEmpty ( ) ) {
// hide all management buttons
managementPanel . removeGenericManagementButtons ( ) ;
// set real relative path
ckanAccessPoint . addPathInfo ( result ) ;
// save this information
viewPerVREPath = result ;
}
}
@Override
public void onFailure ( Throwable caught ) {
// check if view per organisation is enabled
// and performing some actions in this case (e.g. removed the management
// buttons, etc.)
GCubeCkanDataCatalog . service . isViewPerVREEnabled ( browserLocationURL ,
new AsyncCallback < String > ( ) {
@Override
public void onSuccess ( String result ) {
GWT . log ( "isViewPerVREEnabled?: " + result ) ;
if ( result ! = null & & ! result . isEmpty ( ) ) {
// hide all management buttons
managementPanel . removeGenericManagementButtons ( ) ;
// set real relative path
ckanAccessPoint . addPathInfo ( result ) ;
// save this information
viewPerVREPath = result ;
}
}
// ?
@Override
public void onFailure ( Throwable caught ) {
}
} ) ;
// ?
}
} ) ;
if ( ! ckan . isOutsideLoginOnPortal ( ) ) {
if ( ! ckan . isOutsideLoginOnPortal ( ) ) {
// MANAGE CKAN MANAGEMENT PANEL ACCORDING TO MY ROLE
GCubeCkanDataCatalog . service . getMyRole ( new AsyncCallback < RolesCkanGroupOrOrg > ( ) {
@ -183,37 +181,39 @@ public class GCubeCkanDataCatalogPanel extends BaseViewTemplate {
} ) ;
// retrieve organizations
GCubeCkanDataCatalog . service . getCkanOrganizationsNamesAndUrlsForUser ( new AsyncCallback < List < BeanUserInOrgGroupRole > > ( ) {
GCubeCkanDataCatalog . service . getCkanOrganizationsNamesAndUrlsForUser (
new AsyncCallback < List < BeanUserInOrgGroupRole > > ( ) {
@Override
public void onSuccess ( List < BeanUserInOrgGroupRole > result ) {
ckanOrganizationsPanel . setOrganizations ( result ) ;
}
@Override
public void onSuccess ( List < BeanUserInOrgGroupRole > result ) {
ckanOrganizationsPanel . setOrganizations ( result ) ;
}
@Override
public void onFailure ( Throwable caught ) {
// an error message will be displayed
ckanOrganizationsPanel . setOrganizations ( null ) ;
}
} ) ;
@Override
public void onFailure ( Throwable caught ) {
// an error message will be displayed
ckanOrganizationsPanel . setOrganizations ( null ) ;
}
} ) ;
// retrieve groups
GCubeCkanDataCatalog . service . getCkanGroupsNamesAndUrlsForUser ( new AsyncCallback < List < BeanUserInOrgGroupRole > > ( ) {
GCubeCkanDataCatalog . service . getCkanGroupsNamesAndUrlsForUser (
new AsyncCallback < List < BeanUserInOrgGroupRole > > ( ) {
@Override
public void onSuccess ( List < BeanUserInOrgGroupRole > result ) {
ckanGroupsPanel . setGroups ( result ) ;
}
@Override
public void onSuccess ( List < BeanUserInOrgGroupRole > result ) {
ckanGroupsPanel . setGroups ( result ) ;
}
@Override
public void onFailure ( Throwable caught ) {
ckanGroupsPanel . setGroups ( null ) ;
}
} ) ;
@Override
public void onFailure ( Throwable caught ) {
ckanGroupsPanel . setGroups ( null ) ;
}
} ) ;
// check if the url encodes a revert operation to be performed
if ( paramsMap . containsKey ( GCubeCkanDataCatalog . REVERT_QUERY_PARAM ) & &
paramsMap . get ( GCubeCkanDataCatalog . REVERT_QUERY_PARAM ) . equals ( "true" ) ) {
if ( paramsMap . containsKey ( GCubeCkanDataCatalog . REVERT_QUERY_PARAM )
& & paramsMap . get ( GCubeCkanDataCatalog . REVERT_QUERY_PARAM ) . equals ( "true" ) ) {
eventBus . fireEvent ( new ShowRevertOperationWidgetEvent ( Window . Location . getHref ( ) ) ) ;
@ -222,21 +222,29 @@ public class GCubeCkanDataCatalogPanel extends BaseViewTemplate {
/ * *
* Just check if it is enabled . . then we need to listen for dom events coming
* /
GCubeCkanDataCatalog . service . isManageProductEnabled ( new AsyncCallback < Boolean > ( ) {
@Override
public void onSuccess ( Boolean result ) {
isManageProductToShow = result ;
managementPanel . showManageProductButton ( isManageProductToShow ) ;
}
@Override
public void onFailure ( Throwable caught ) {
isManageProductToShow = false ;
managementPanel . showManageProductButton ( isManageProductToShow ) ;
}
} ) ;
GCubeCkanDataCatalog . service
. isManageProductEnabled ( new AsyncCallback < ManageProductResponse > ( ) {
@Override
public void onSuccess ( ManageProductResponse result ) {
manageProductResponse = result ;
if ( manageProductResponse ! = null ) {
if ( manageProductResponse . isGRSFManageEnabled ( ) ) {
managementPanel . showManageCMSProductsButton (
manageProductResponse . isManageEnabled ( ) ) ;
} else if ( manageProductResponse . isManageEnabled ( ) ) {
managementPanel . showManageCMSProductsButton ( manageProductResponse . isManageEnabled ( ) ) ;
managementPanel . enableManageCMSProductsButton ( manageProductResponse . isManageEnabled ( ) ) ;
}
}
}
@Override
public void onFailure ( Throwable caught ) {
managementPanel . showManageGRSFProductButton ( false ) ;
}
} ) ;
}
@ -250,14 +258,12 @@ public class GCubeCkanDataCatalogPanel extends BaseViewTemplate {
}
} ) ;
Window . addResizeHandler ( new ResizeHandler ( ) {
@Override
public void onResize ( ResizeEvent event ) {
GWT . log ( "onWindowResized width: " + event . getWidth ( ) +
" height: " + event . getHeight ( ) ) ;
GWT . log ( "onWindowResized width: " + event . getWidth ( ) + " height: " + event . getHeight ( ) ) ;
updateSize ( ) ;
}
} ) ;
@ -270,28 +276,27 @@ public class GCubeCkanDataCatalogPanel extends BaseViewTemplate {
listenForPostMessage ( ) ;
}
/ * *
* Gets the browser location URL .
*
* @return the browser location URL
* /
public String getBrowserLocationURL ( ) {
String browserLocationURL = null ;
try {
browserLocationURL = Window . Location . getHref ( ) ;
} catch ( Exception e ) {
} catch ( Exception e ) {
// silent
}
GWT . log ( "Returning browserLocationURL: " + browserLocationURL ) ;
GWT . log ( "Returning browserLocationURL: " + browserLocationURL ) ;
return browserLocationURL ;
}
public static String getLatestSelectedProductIdentifier ( ) {
public static String getLatestSelectedProductIdentifier ( ) {
return latestSelectedProductIdentifier ;
}
@ -310,8 +315,7 @@ public class GCubeCkanDataCatalogPanel extends BaseViewTemplate {
/ * *
* Sets the top panel visible .
*
* @param bool
* the new top panel visible
* @param bool the new top panel visible
* /
public void setTopPanelVisible ( boolean bool ) {
@ -322,8 +326,7 @@ public class GCubeCkanDataCatalogPanel extends BaseViewTemplate {
/ * *
* show or hide edit / insert buttons according to the role .
*
* @param show
* the show
* @param show the show
* /
public void showEditInsertButtons ( boolean show ) {
@ -333,8 +336,7 @@ public class GCubeCkanDataCatalogPanel extends BaseViewTemplate {
/ * *
* Instance ckan frame .
*
* @param ckanUrlConnector
* the ckan url connector
* @param ckanUrlConnector the ckan url connector
* @return the frame
* /
public Frame instanceCkanFrame ( String ckanUrlConnector ) {
@ -366,16 +368,15 @@ public class GCubeCkanDataCatalogPanel extends BaseViewTemplate {
* Update window size .
* /
public void updateSize ( ) {
/ * RootPanel workspace = rootPanel ;
int topBorder = workspace . getAbsoluteTop ( ) ;
GWT . log ( "top: " + topBorder ) ;
int footer = 30 ; // 85 footer is bottombar + sponsor
int rootHeight = Window . getClientHeight ( ) - topBorder - 5 - footer ;
int height = rootHeight - getTopPanelHeight ( ) ;
if ( ckanFramePanel . getFrame ( ) ! = null ) {
int newH = managementPanel ! = null & & managementPanel . getCurrentHeight ( ) > 0 ? managementPanel . getOffsetHeight ( ) + height : height ;
ckanFramePanel . getFrame ( ) . setHeight ( 2000 + "px" ) ;
} * /
/ *
* RootPanel workspace = rootPanel ; int topBorder = workspace . getAbsoluteTop ( ) ;
* GWT . log ( "top: " + topBorder ) ; int footer = 30 ; // 85 footer is bottombar +
* sponsor int rootHeight = Window . getClientHeight ( ) - topBorder - 5 - footer ;
* int height = rootHeight - getTopPanelHeight ( ) ; if ( ckanFramePanel . getFrame ( )
* ! = null ) { int newH = managementPanel ! = null & &
* managementPanel . getCurrentHeight ( ) > 0 ? managementPanel . getOffsetHeight ( ) +
* height : height ; ckanFramePanel . getFrame ( ) . setHeight ( 2000 + "px" ) ; }
* /
RootPanel workspace = this . rootPanel ;
int topBorder = workspace . getAbsoluteTop ( ) ;
@ -383,14 +384,17 @@ public class GCubeCkanDataCatalogPanel extends BaseViewTemplate {
int rootHeight = Window . getClientHeight ( ) - topBorder - 5 - footer ;
int height = rootHeight - getTopPanelHeight ( ) ;
if ( this . ckanFramePanel . getFrame ( ) ! = null ) {
int newH = this . managementPanel ! = null & & this . managementPanel . getCurrentHeight ( ) > 0 ? this . managementPanel . getOffsetHeight ( ) + height : height ;
int newH = this . managementPanel ! = null & & this . managementPanel . getCurrentHeight ( ) > 0
? this . managementPanel . getOffsetHeight ( ) + height
: height ;
this . ckanFramePanel . getFrame ( ) . setHeight ( newH + "px" ) ;
}
// workspace.setHeight(height+"px");
// workspace.setHeight(height+"px");
}
/ * *
* Print a message
*
* @param string
* /
protected native void printString ( String string ) / * - {
@ -401,71 +405,76 @@ public class GCubeCkanDataCatalogPanel extends BaseViewTemplate {
* Listen for post message .
* /
private final native void listenForPostMessage ( ) / * - {
var that = this ;
$wnd . addEventListener ( "message" , function ( msg ) {
console . log ( "read message..." ) ;
that . @org.gcube.portlets.gcubeckan.gcubeckandatacatalog.client.view.GCubeCkanDataCatalogPanel : : onPostMessage ( Ljava / lang / String ; Ljava / lang / String ; ) ( msg . data , msg . origin ) ;
} ) ;
var that = this ;
$wnd
. addEventListener (
"message" ,
function ( msg ) {
console . log ( "read message..." ) ;
that . @org.gcube.portlets.gcubeckan.gcubeckandatacatalog.client.view.GCubeCkanDataCatalogPanel : : onPostMessage ( Ljava / lang / String ; Ljava / lang / String ; ) ( msg . data , msg . origin ) ;
} ) ;
} - * / ;
/ * *
* On post message .
*
* @param data the data
* @param data the data
* @param origin the origin
* /
private void onPostMessage ( String data , String origin ) {
printString ( "Read data: " + data + ", from origin: " + origin ) ;
printString ( "Ckan base url: " + ckanAccessPoint . getBaseUrl ( ) ) ;
printString ( "Read data: " + data + ", from origin: " + origin ) ;
printString ( "Ckan base url: " + ckanAccessPoint . getBaseUrl ( ) ) ;
// parsing data.. it is a json bean of the type
printString ( "Incoming message is " + data + " from " + origin ) ;
if ( ckanAccessPoint . getBaseUrl ( ) . indexOf ( origin ) > = 0 ) {
if ( ckanAccessPoint . getBaseUrl ( ) . indexOf ( origin ) > = 0 ) {
// The data has been sent from your site
// The data sent with postMessage is stored in event.data
String height = null ;
String productId = null ;
boolean isProductKeyMissing = false ;
try {
try {
JSONValue parsedJSON = JSONParser . parseStrict ( data ) ;
JSONObject object = parsedJSON . isObject ( ) ;
GWT . log ( "Object is " + object ) ;
if ( object ! = null ) {
//Supporting Task #12286: parsing the translate values for 'dataset', 'organization' and so on
if ( object . containsKey ( "translate" ) ) {
if ( object ! = null ) {
// Supporting Task #12286: parsing the translate values for 'dataset',
// 'organization' and so on
if ( object . containsKey ( "translate" ) ) {
JSONObject theTranslate = ( JSONObject ) object . get ( "translate" ) ;
GWT . log ( "theTranslate is " + object ) ;
for ( String key : theTranslate . keySet ( ) ) {
// GWT.log("theTranslate key " + key);
// GWT.log("theTranslate key " + key);
String value = theTranslate . get ( key ) . isString ( ) . stringValue ( ) ;
printString ( "Customizing navigation link '" + key + "' with translate: " + value ) ;
managementPanel . customizeLabelAccordingTranslate ( key , value ) ;
printString ( "Customizing navigation link '" + key + "' with translate: " + value ) ;
managementPanel . customizeLabelAccordingTranslate ( key , value ) ;
}
} else if ( object . containsKey ( "height" ) ) {
} else if ( object . containsKey ( "height" ) ) {
height = object . get ( "height" ) . isString ( ) . stringValue ( ) ;
if ( object . containsKey ( "product" ) )
if ( object . containsKey ( "product" ) )
productId = object . get ( "product" ) . isString ( ) . stringValue ( ) ;
else
isProductKeyMissing = true ;
}
}
} catch ( Exception e ) {
} catch ( Exception e ) {
GWT . log ( "Exception is " + e ) ;
}
if ( height ! = null )
if ( height ! = null )
setIFrameHeight ( height . toString ( ) ) ;
// show or hide the manage product button
if ( ! isProductKeyMissing ) {
if ( ! isProductKeyMissing ) {
latestSelectedProductIdentifier = productId . toString ( ) ;
managementPanel . enableShareItemButton ( productId ! = null & & ! productId . isEmpty ( ) ) ;
managementPanel . enablePublishOnZenodoButton ( productId ! = null & & ! productId . isEmpty ( ) ) ;
managementPanel . enableManageProductButton ( productId ! = null & & ! productId . isEmpty ( ) & & isManageProductToShow ) ;
managementPanel . enableManageGRSFProductButton (
productId ! = null & & ! productId . isEmpty ( ) & & manageProductResponse . isGRSFManageEnabled ( ) ) ;
}
} else {
// The data hasn't been sent from your site!
@ -475,30 +484,29 @@ public class GCubeCkanDataCatalogPanel extends BaseViewTemplate {
}
/ * *
* Sets the i frame height .
*
* @param height the new i frame height
* /
private void setIFrameHeight ( String height ) {
private void setIFrameHeight ( String height ) {
String parsedHeight = null ;
if ( height = = null | | height . isEmpty ( ) )
if ( height = = null | | height . isEmpty ( ) )
return ;
if ( height . contains ( "px" ) ) {
if ( height . contains ( "px" ) ) {
parsedHeight = height ;
} else {
try {
} else {
try {
int intH = Integer . parseInt ( height ) ;
parsedHeight = intH + " px" ;
} catch ( Exception e ) {
} catch ( Exception e ) {
}
}
if ( parsedHeight ! = null ) {
GWT . log ( "Setting new height for ckan iFrame: " + height ) ;
if ( parsedHeight ! = null ) {
GWT . log ( "Setting new height for ckan iFrame: " + height ) ;
this . ckanFramePanel . getFrame ( ) . setHeight ( height ) ;
}
}
@ -515,9 +523,10 @@ public class GCubeCkanDataCatalogPanel extends BaseViewTemplate {
/ * *
* Return the catalogue url ( e . g . http : //ckan-d-d4s.d4science.org:443/)
*
* @return
* /
public String getCatalogueUrl ( ) {
public String getCatalogueUrl ( ) {
printString ( "Base url for iframe is " + ckanAccessPoint . getCatalogueBaseUrl ( ) ) ;
return ckanAccessPoint . getCatalogueBaseUrl ( ) ;
@ -565,11 +574,12 @@ public class GCubeCkanDataCatalogPanel extends BaseViewTemplate {
/ * *
* Show management panel
*
* @param show
* /
public void showManagementPanel ( boolean show ) {
public void showManagementPanel ( boolean show ) {
managementPanel . showManage ProductButton( show ) ;
managementPanel . showManage GRSF ProductButton( show ) ;
}