in progress

This commit is contained in:
Francesco Mangiacrapa 2021-06-16 18:02:54 +02:00
parent 373ee7fe56
commit 2b458df5c6
6 changed files with 223 additions and 179 deletions

View File

@ -1,11 +1,15 @@
package org.gcube.portlets.widgets.ckancontentmoderator.client; 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.events.ClickItemEvent;
import org.gcube.portlets.widgets.ckancontentmoderator.client.events.ClickItemEventHandler;
import org.gcube.portlets.widgets.ckancontentmoderator.client.ui.ContentModeratorPaginatedView; import org.gcube.portlets.widgets.ckancontentmoderator.client.ui.ContentModeratorPaginatedView;
import org.gcube.portlets.widgets.ckancontentmoderator.client.ui.ContentModeratorSystemBaseView; import org.gcube.portlets.widgets.ckancontentmoderator.client.ui.ContentModeratorSystemBaseView;
import org.gcube.portlets.widgets.ckancontentmoderator.client.ui.table.ItemsTable.DISPLAY_FIELD; import org.gcube.portlets.widgets.ckancontentmoderator.client.ui.table.ItemsTable.DISPLAY_FIELD;
import org.gcube.portlets.widgets.ckancontentmoderator.shared.CatalogueDataset;
import com.google.gwt.core.client.GWT; import com.google.gwt.core.client.GWT;
import com.google.gwt.event.shared.HandlerManager;
import com.google.gwt.user.client.Command; import com.google.gwt.user.client.Command;
import com.google.gwt.user.client.rpc.AsyncCallback; import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.Composite; import com.google.gwt.user.client.ui.Composite;
@ -26,6 +30,7 @@ public class CkanContentModeratorWidget {
private ContentModeratorSystemBaseView cmsPanel = new ContentModeratorSystemBaseView(); private ContentModeratorSystemBaseView cmsPanel = new ContentModeratorSystemBaseView();
private Boolean isContentModeratorEnabled = null; private Boolean isContentModeratorEnabled = null;
private ContentModeratorPaginatedView paginatedView; private ContentModeratorPaginatedView paginatedView;
public final static HandlerManager eventBus = new HandlerManager(null);
/** /**
* Instantiates a new ckan content moderator widget. * Instantiates a new ckan content moderator widget.
@ -38,10 +43,28 @@ public class CkanContentModeratorWidget {
// itemsTable.initTable(null, null, new ListDataProvider<CatalogueDataset>()); // itemsTable.initTable(null, null, new ListDataProvider<CatalogueDataset>());
// cmsPanel.add(itemsTable.getCellTable()); // cmsPanel.add(itemsTable.getCellTable());
paginatedView = new ContentModeratorPaginatedView(status, displayFields, sortByField); paginatedView = new ContentModeratorPaginatedView(eventBus, status, displayFields, sortByField);
//cmsPanel.addToTop(new LoadingPanel(new HTML("Loading..."))); //cmsPanel.addToTop(new LoadingPanel(new HTML("Loading...")));
cmsPanel.addToCenter(paginatedView.getCellPanel()); cmsPanel.addToCenter(paginatedView.getCellPanel());
cmsPanel.addToBottom(paginatedView.getPagerPanel()); cmsPanel.addToBottom(paginatedView.getPagerPanel());
bindEvents();
}
private void bindEvents() {
eventBus.addHandler(ClickItemEvent.TYPE, new ClickItemEventHandler() {
@Override
public <T> void onClick(ClickItemEvent<T> clickItemEvent) {
if(clickItemEvent.getItem() instanceof CatalogueDataset) {
CatalogueDataset clickedDataset = (CatalogueDataset) clickItemEvent.getItem();
//Window.open(clickedDataset.getUrl(), null, "_blank");
}
}
});
} }
// /** // /**

View File

@ -13,6 +13,7 @@ import org.gcube.portlets.widgets.ckancontentmoderator.shared.CatalogueDataset;
import org.gcube.portlets.widgets.ckancontentmoderator.shared.SearchedData; import org.gcube.portlets.widgets.ckancontentmoderator.shared.SearchedData;
import com.google.gwt.core.client.GWT; import com.google.gwt.core.client.GWT;
import com.google.gwt.event.shared.HandlerManager;
import com.google.gwt.user.cellview.client.SimplePager; import com.google.gwt.user.cellview.client.SimplePager;
import com.google.gwt.user.cellview.client.SimplePager.TextLocation; import com.google.gwt.user.cellview.client.SimplePager.TextLocation;
import com.google.gwt.user.client.rpc.AsyncCallback; import com.google.gwt.user.client.rpc.AsyncCallback;
@ -27,37 +28,46 @@ import com.google.gwt.view.client.Range;
import com.google.gwt.view.client.SelectionModel; import com.google.gwt.view.client.SelectionModel;
import com.google.gwt.view.client.SingleSelectionModel; import com.google.gwt.view.client.SingleSelectionModel;
/**
* The Class ContentModeratorPaginatedView.
*
* @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it
*
* Jun 16, 2021
*/
public class ContentModeratorPaginatedView { public class ContentModeratorPaginatedView {
private static final int ITEM_START_INDEX = ContentModeratorWidgetConstants.ITEM_START_INDEX; private static final int ITEM_START_INDEX = ContentModeratorWidgetConstants.ITEM_START_INDEX;
private static final int ITEMS_PER_PAGE = ContentModeratorWidgetConstants.ITEMS_PER_PAGE; private static final int ITEMS_PER_PAGE = ContentModeratorWidgetConstants.ITEMS_PER_PAGE;
private VerticalPanel vPanel = new VerticalPanel(); private VerticalPanel vPanel = new VerticalPanel();
private FlowPanel pagerPanel = new FlowPanel(); private FlowPanel pagerPanel = new FlowPanel();
private Boolean newLoading = false; private Boolean newLoading = false;
private ItemsTable<CatalogueDataset> itemsTable; private ItemsTable<CatalogueDataset> itemsTable;
private MyCustomDataProvider<CatalogueDataset> dataProvider = new MyCustomDataProvider<CatalogueDataset>(); private MyCustomDataProvider<CatalogueDataset> dataProvider = new MyCustomDataProvider<CatalogueDataset>();
protected Widget orginalLoadingIndicator = null; protected Widget orginalLoadingIndicator = null;
private LoadingPanel loadingPanel = new LoadingPanel(new HTML("Loading data...")); private LoadingPanel loadingPanel = new LoadingPanel(new HTML("Loading data..."));
// private int serverStartIndex = 0;
private ItemStatus itemStatus; private ItemStatus itemStatus;
private int serverStartIndex; private int serverStartIndex;
public ContentModeratorPaginatedView(ItemStatus theStatus, DISPLAY_FIELD[] displayFields, /**
* Instantiates a new content moderator paginated view.
*
* @param eventbus
*
* @param theStatus the the status
* @param displayFields the display fields
* @param sortByField the sort by field
*/
public ContentModeratorPaginatedView(HandlerManager eventbus, ItemStatus theStatus, DISPLAY_FIELD[] displayFields,
DISPLAY_FIELD sortByField) { DISPLAY_FIELD sortByField) {
this.itemStatus = theStatus; this.itemStatus = theStatus;
this.newLoading = true; this.newLoading = true;
itemsTable = new ItemsTable<CatalogueDataset>(null, displayFields, sortByField); itemsTable = new ItemsTable<CatalogueDataset>(eventbus, displayFields, sortByField);
itemsTable.initTable(null, null, dataProvider); itemsTable.initTable(null, null, dataProvider);
orginalLoadingIndicator = itemsTable.getCellTable().getLoadingIndicator(); orginalLoadingIndicator = itemsTable.getCellTable().getLoadingIndicator();
initPagination(ITEMS_PER_PAGE); initPagination(ITEMS_PER_PAGE);
loadNewPage(ITEM_START_INDEX, ITEMS_PER_PAGE,false); loadNewPage(ITEM_START_INDEX, ITEMS_PER_PAGE, false);
} }
/** /**
@ -107,6 +117,8 @@ public class ContentModeratorPaginatedView {
/** /**
* Set the panel in loading mode. * Set the panel in loading mode.
*
* @param show the show
*/ */
protected void showLoading(boolean show) { protected void showLoading(boolean show) {
loadingPanel.setVisible(show); loadingPanel.setVisible(show);
@ -121,16 +133,17 @@ public class ContentModeratorPaginatedView {
return pagerPanel; return pagerPanel;
} }
/* /**
* (non-Javadoc) * Load new page.
* *
* @see org.gcube.portlets.widgets.wsexplorer.client.view.WorkspaceExplorer# * @param startIdx the start idx
* loadFolder(org.gcube.portlets.widgets.wsexplorer.shared.Item, boolean, int, * @param limit the limit
* int, boolean) * @param resetStore the reset store
*/ */
public void loadNewPage(final int startIdx, final int limit, final boolean resetStore) { public void loadNewPage(final int startIdx, final int limit, final boolean resetStore) {
newLoading = resetStore; newLoading = resetStore;
GWT.log("loading data with parameters [startIdx: "+startIdx+", limit: " + limit + ", resetStore:" + resetStore + "]"); GWT.log("loading data with parameters [startIdx: " + startIdx + ", limit: " + limit + ", resetStore:"
+ resetStore + "]");
// showLoading(true); // showLoading(true);
int newStartIndex = startIdx; int newStartIndex = startIdx;
@ -141,13 +154,84 @@ public class ContentModeratorPaginatedView {
serverStartIndex = 0; serverStartIndex = 0;
GWT.log("Store reset performed start index is: " + newStartIndex); GWT.log("Store reset performed start index is: " + newStartIndex);
getAsycnDataProvider().updateRowCount(ITEMS_PER_PAGE, false); getAsycnDataProvider().updateRowCount(ITEMS_PER_PAGE, false);
//newLoading = false; // newLoading = false;
} }
loadItemsForStatus(itemStatus, newStartIndex, limit, serverStartIndex); loadItemsForStatus(itemStatus, newStartIndex, limit, serverStartIndex);
} }
/**
* Sets the new page result.
*
* @param result the new new page result
*/
private void setNewPageResult(SearchedData result) {
serverStartIndex = result.getServerEndIndex();
if (newLoading) {
getCellTable().setVisibleRangeAndClearData(new Range(result.getClientStartIndex(), ITEMS_PER_PAGE), false);
}
SelectionModel<? super CatalogueDataset> sm = getCellTable().getSelectionModel();
if (sm instanceof SingleSelectionModel) {
SingleSelectionModel<CatalogueDataset> ssm = (SingleSelectionModel<CatalogueDataset>) sm;
ssm.clear();
}
getAsycnDataProvider().updateRowCount((int) result.getTotalItems(), true);
getAsycnDataProvider().updateRowData(result.getClientStartIndex(), result.getData());
if (result.getData().size() == 0) {
getCellTable().setLoadingIndicator(new Label("No data"));
} else {
getCellTable().setLoadingIndicator(orginalLoadingIndicator);
}
GWT.log("Updating row data startIndex: " + result.getClientStartIndex() + " children size: "
+ result.getData().size());
GWT.log("getAsycnDataProvider().getDataDisplays().size(): " + getCellTable().getRowCount());
if (result.isServerSearchFinished()) {
GWT.log("Search finished!!!");
getAsycnDataProvider().updateRowCount(getCellTable().getRowCount(), true);
}
newLoading = false;
}
/**
* Load items for status.
*
* @param status the status
* @param offset the offset
* @param limit the limit
* @param serverIndex the server index
*/
private void loadItemsForStatus(ItemStatus status, int offset, int limit, int serverIndex) {
showLoading(true);
GWT.log("calling getDataForStatus with parameters [startIndex: " + offset + ", limit: " + limit
+ ", serverIndex:" + serverIndex + "]");
CkanContentModeratorWidget.contentModeratorService.getDataForStatus(status, offset, limit, serverIndex,
new AsyncCallback<SearchedData>() {
@Override
public void onSuccess(SearchedData result) {
showLoading(false);
setNewPageResult(result);
}
@Override
public void onFailure(Throwable caught) {
showLoading(false);
}
});
}
/** /**
* A custom {@link AsyncDataProvider}. * A custom {@link AsyncDataProvider}.
* *
@ -176,95 +260,12 @@ public class ContentModeratorPaginatedView {
GWT.log("OnLoading is true.. returning"); GWT.log("OnLoading is true.. returning");
return; return;
} }
try {
GWT.log("Range changed: " + start + " " + length + " visible count: " + display.getVisibleItemCount()); GWT.log("Range changed: " + start + " " + length + " visible count: " + display.getVisibleItemCount());
// GWT.log("Server start index: " + serverStartIndex);
// int newStart = start < serverStartIndex? serverStartIndex : start;
// GWT.log("newStart index: "+newStart);
loadNewPage(start, length, false); loadNewPage(start, length, false);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
} }
/**
* Sets the new page result.
*
* @param result the new new page result
*/
private void setNewPageResult(SearchedData result){
serverStartIndex = result.getServerEndIndex();
if(newLoading){
getCellTable().setVisibleRangeAndClearData(new Range(result.getClientStartIndex(), ITEMS_PER_PAGE), false);
}
SelectionModel<? super CatalogueDataset> sm = getCellTable().getSelectionModel();
if(sm instanceof SingleSelectionModel){
SingleSelectionModel<CatalogueDataset> ssm = (SingleSelectionModel<CatalogueDataset>) sm;
ssm.clear();
}
getAsycnDataProvider().updateRowCount((int) result.getTotalItems(), true);
getAsycnDataProvider().updateRowData(result.getClientStartIndex(), result.getData());
if(result.getData().size()==0){
getCellTable().setLoadingIndicator(new Label("No data"));
}else{
getCellTable().setLoadingIndicator(orginalLoadingIndicator);
}
//getCellTable().setVisibleRangeAndClearData(new Range(startIdx, result.getChildren()).), false);
//getAsycnDataProvider().getDataDisplays().
GWT.log("Updating row data startIndex: "+result.getClientStartIndex() + " children size: "+result.getData().size());
GWT.log("getAsycnDataProvider().getDataDisplays().size(): "+getCellTable().getRowCount());
if(result.isServerSearchFinished()){
GWT.log("Search finished!!!");
getAsycnDataProvider().updateRowCount(getCellTable().getRowCount(), true);
}
//getCellTable().setPageSize(result.getChildren().size()+1);
//getCellTable().setVisibleRange(startIdx, result.getChildren().size());
//getCellTable().redraw();
//GWT.log("cellTable size: "+getCellTable().getRowCount());
newLoading = false;
}
/**
* Load items for status.
*
* @param status the status
* @param offset
* @param limit
* @throws Exception the exception
*/
private void loadItemsForStatus(ItemStatus status, int offset, int limit, int serverIndex) {
showLoading(true);
//TODO implement new method
GWT.log("calling getDataForStatus with parameters [startIndex: "+offset+", limit: " + limit + ", serverIndex:" + serverIndex + "]");
CkanContentModeratorWidget.contentModeratorService.getDataForStatus(status, offset, limit, serverIndex,
new AsyncCallback<SearchedData>() {
@Override
public void onSuccess(SearchedData result) {
showLoading(false);
setNewPageResult(result);
}
@Override
public void onFailure(Throwable caught) {
showLoading(false);
}
});
} }
} }

View File

@ -24,7 +24,10 @@ public class CatalogueBeansConverter {
myDataset.setAuthor(t.getAuthor()); myDataset.setAuthor(t.getAuthor());
myDataset.setAuthorEmail(t.getAuthorEmail()); myDataset.setAuthorEmail(t.getAuthorEmail());
myDataset.setCkanDatasetURL(null);
//is it needed??
myDataset.setD4ScienceItemURL(null);
myDataset.setId(t.getId()); myDataset.setId(t.getId());
myDataset.setLicenseId(t.getLicenseId()); myDataset.setLicenseId(t.getLicenseId());
myDataset.setMaintainer(t.getMaintainer()); myDataset.setMaintainer(t.getMaintainer());
@ -34,6 +37,7 @@ public class CatalogueBeansConverter {
myDataset.setOwnerOrg(t.getOwnerOrg()); myDataset.setOwnerOrg(t.getOwnerOrg());
myDataset.setTitle(t.getTitle()); myDataset.setTitle(t.getTitle());
myDataset.setType(t.getType()); myDataset.setType(t.getType());
//here is always null
myDataset.setUrl(t.getUrl()); myDataset.setUrl(t.getUrl());
myDataset.setCreated(t.getMetadataCreated().getTime()); myDataset.setCreated(t.getMetadataCreated().getTime());
return myDataset; return myDataset;

View File

@ -7,6 +7,7 @@ import org.gcube.datacatalogue.utillibrary.server.cms.CatalogueContentModeratorS
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
/** /**
* A factory for getting CatalogueContentModeratorSystem objects. * A factory for getting CatalogueContentModeratorSystem objects.
* *
@ -26,21 +27,21 @@ public class CatalogueCMSFactory {
* *
* @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it * @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it
* *
* Jun 14, 2021 * Jun 16, 2021
*/ */
private class CacheBean { private class CacheBean {
CatalogueContentModeratorSystem cmsInstance; DataCatalogueImpl dataCatalogueImpl;
long ttl; long ttl;
/** /**
* Instantiates a new cache bean. * Instantiates a new cache bean.
* *
* @param ttl the ttl * @param ttl the ttl
* @param cmsInstance the cms instance * @param dataCatalogueImpl the data catalogue impl
*/ */
public CacheBean(long ttl, CatalogueContentModeratorSystem cmsInstance) { public CacheBean(long ttl, DataCatalogueImpl dataCatalogueImpl) {
this.ttl = ttl; this.ttl = ttl;
this.cmsInstance = cmsInstance; this.dataCatalogueImpl = dataCatalogueImpl;
} }
} }
@ -73,17 +74,29 @@ public class CatalogueCMSFactory {
*/ */
public CatalogueContentModeratorSystem getCMSPerScope(String scope) throws Exception { public CatalogueContentModeratorSystem getCMSPerScope(String scope) throws Exception {
DataCatalogueImpl dataCatalogueImpl = getCatalogueImplPerScope(scope);
return dataCatalogueImpl.getCatalogueContentModerator();
}
/**
* Gets the catalogue impl per scope.
*
* @param scope the scope
* @return the catalogue impl per scope
* @throws Exception the exception
*/
public DataCatalogueImpl getCatalogueImplPerScope(String scope) throws Exception {
if (scope == null || scope.isEmpty()) if (scope == null || scope.isEmpty())
throw new IllegalArgumentException("Invalid scope given!"); throw new IllegalArgumentException("Invalid scope given!");
if (cache.containsKey(scope) && !expired(cache.get(scope))) { if (cache.containsKey(scope) && !expired(cache.get(scope))) {
return cache.get(scope).cmsInstance; return cache.get(scope).dataCatalogueImpl;
} else { } else {
logger.info("Creating "+CatalogueCMSFactory.class.getSimpleName()+" for scope " + scope); logger.info("Creating " + CatalogueCMSFactory.class.getSimpleName() + " for scope " + scope);
DataCatalogueImpl dci = new DataCatalogueImpl(scope); DataCatalogueImpl dci = new DataCatalogueImpl(scope);
CatalogueContentModeratorSystem cmsInstance = dci.getCatalogueContentModerator(); cache.put(scope, new CacheBean(System.currentTimeMillis(), dci));
cache.put(scope, new CacheBean(System.currentTimeMillis(), cmsInstance)); return dci;
return cmsInstance;
} }
} }

View File

@ -5,6 +5,7 @@ import java.util.List;
import org.gcube.common.authorization.library.provider.SecurityTokenProvider; import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
import org.gcube.common.scope.api.ScopeProvider; import org.gcube.common.scope.api.ScopeProvider;
import org.gcube.datacatalogue.utillibrary.server.DataCatalogueImpl;
import org.gcube.datacatalogue.utillibrary.server.cms.CatalogueContentModeratorSystem; import org.gcube.datacatalogue.utillibrary.server.cms.CatalogueContentModeratorSystem;
import org.gcube.datacatalogue.utillibrary.shared.ItemStatus; import org.gcube.datacatalogue.utillibrary.shared.ItemStatus;
import org.gcube.datacatalogue.utillibrary.shared.jackan.model.CkanDataset; import org.gcube.datacatalogue.utillibrary.shared.jackan.model.CkanDataset;
@ -59,7 +60,8 @@ public class CkanContentModeratorServiceImpl extends RemoteServiceServlet implem
String token = WsUtil.getCurrentToken(scope, user.getUsername()); String token = WsUtil.getCurrentToken(scope, user.getUsername());
ScopeProvider.instance.set(scope); ScopeProvider.instance.set(scope);
SecurityTokenProvider.instance.set(token); SecurityTokenProvider.instance.set(token);
CatalogueContentModeratorSystem cmsInstance = CatalogueCMSFactory.getFactory().getCMSPerScope(scope); DataCatalogueImpl catalogueImpl = CatalogueCMSFactory.getFactory().getCatalogueImplPerScope(scope);
CatalogueContentModeratorSystem cmsInstance = catalogueImpl.getCatalogueContentModerator();
List<CkanDataset> datasets = cmsInstance.getListItemsForStatus(theStatus, limit, offset); List<CkanDataset> datasets = cmsInstance.getListItemsForStatus(theStatus, limit, offset);
if (datasets != null) { if (datasets != null) {
int size = datasets.size(); int size = datasets.size();
@ -67,6 +69,8 @@ public class CkanContentModeratorServiceImpl extends RemoteServiceServlet implem
LOG.info("datasetList for input parameters returned by CMS has size: " + size); LOG.info("datasetList for input parameters returned by CMS has size: " + size);
for (CkanDataset ckanDataset : datasets) { for (CkanDataset ckanDataset : datasets) {
CatalogueDataset ds = CatalogueBeansConverter.toCatalogueDataset.apply(ckanDataset); CatalogueDataset ds = CatalogueBeansConverter.toCatalogueDataset.apply(ckanDataset);
String datasetURL = String.format("%s/dataset/%s", catalogueImpl.getCatalogueUrl(),ds.getName());
ds.setUrl(datasetURL);
LOG.debug("converted dataset is: " + ds); LOG.debug("converted dataset is: " + ds);
datasetList.add(ds); datasetList.add(ds);
} }
@ -101,8 +105,10 @@ public class CkanContentModeratorServiceImpl extends RemoteServiceServlet implem
} }
@Override @Override
public SearchedData getDataForStatus(ItemStatus status, int offset, int limit, int serverStartIndex) throws Exception { public SearchedData getDataForStatus(ItemStatus status, int offset, int limit, int serverStartIndex)
LOG.info("called getDataForStatus [status: "+status+", offset: "+offset+", limit: "+limit+", serverIndex: "+serverStartIndex); throws Exception {
LOG.info("called getDataForStatus [status: " + status + ", offset: " + offset + ", limit: " + limit
+ ", serverIndex: " + serverStartIndex);
try { try {
String scope = WsUtil.getCurrentScope(this.getThreadLocalRequest()); String scope = WsUtil.getCurrentScope(this.getThreadLocalRequest());
@ -110,64 +116,61 @@ public class CkanContentModeratorServiceImpl extends RemoteServiceServlet implem
String token = WsUtil.getCurrentToken(scope, user.getUsername()); String token = WsUtil.getCurrentToken(scope, user.getUsername());
ScopeProvider.instance.set(scope); ScopeProvider.instance.set(scope);
SecurityTokenProvider.instance.set(token); SecurityTokenProvider.instance.set(token);
//int searchStartIndex = limit < serverStartIndex? serverStartIndex : offset; // int searchStartIndex = limit < serverStartIndex? serverStartIndex : offset;
int searchStartIndex = offset; int searchStartIndex = offset;
CatalogueContentModeratorSystem cmsInstance = CatalogueCMSFactory.getFactory().getCMSPerScope(scope); CatalogueContentModeratorSystem cmsInstance = CatalogueCMSFactory.getFactory().getCMSPerScope(scope);
SearchedData searchedData = new SearchedData(offset, limit, searchStartIndex, false); SearchedData searchedData = new SearchedData(offset, limit, searchStartIndex, false);
long totalItemsForStatus = cmsInstance.countListItemsForStatus(status); long totalItemsForStatus = cmsInstance.countListItemsForStatus(status);
LOG.info("totalItemsForStatus "+status+" are : "+totalItemsForStatus); LOG.info("totalItemsForStatus " + status + " are : " + totalItemsForStatus);
List<CatalogueDataset> listDataset = new ArrayList<CatalogueDataset>(); List<CatalogueDataset> listDataset = new ArrayList<CatalogueDataset>();
try { try {
LOG.debug("getListItemsForStatus with searchStartIndex: "+searchStartIndex+", limit: "+limit); LOG.debug("getListItemsForStatus with searchStartIndex: " + searchStartIndex + ", limit: " + limit);
listDataset = getListItemsForStatus(status, searchStartIndex, limit); listDataset = getListItemsForStatus(status, searchStartIndex, limit);
}catch (Exception e) { } catch (Exception e) {
LOG.error("Error occurred on gettin items for status: "+status,e); LOG.error("Error occurred on gettin items for status: " + status, e);
} }
int listDatasetSize = listDataset.size(); int listDatasetSize = listDataset.size();
LOG.debug("Returned "+listDatasetSize+" with above parameters"); LOG.debug("Returned " + listDatasetSize + " with above parameters");
searchedData.setData(listDataset); searchedData.setData(listDataset);
searchedData.setTotalItems(totalItemsForStatus); searchedData.setTotalItems(totalItemsForStatus);
if(listDatasetSize == limit || listDatasetSize==0){ if (listDatasetSize == limit || listDatasetSize == 0) {
LOG.debug("Page completed returning "+listDatasetSize+ " items"); LOG.debug("Page completed returning " + listDatasetSize + " items");
int newOffset = searchStartIndex+offset; int newOffset = searchStartIndex + offset;
searchedData.setServerSearchFinished(newOffset>totalItemsForStatus || listDatasetSize == 0); searchedData.setServerSearchFinished(newOffset > totalItemsForStatus || listDatasetSize == 0);
LOG.debug("is Search finished: "+searchedData.isServerSearchFinished()); LOG.debug("is Search finished: " + searchedData.isServerSearchFinished());
return searchedData; return searchedData;
} }
/*int offsetStartIndex = searchStartIndex; /*
boolean pageOffsetOut = false; * int offsetStartIndex = searchStartIndex; boolean pageOffsetOut = false;
while(listDatasetSize < offset && !searchedData.isServerSearchFinished() && !pageOffsetOut){ //&& SEARCH NOT ULTIMATED * while(listDatasetSize < offset && !searchedData.isServerSearchFinished() &&
LOG.debug("MyLg new WHILE Items count: "+totalItemsForStatus+" is less than limit.."); * !pageOffsetOut){ //&& SEARCH NOT ULTIMATED
* LOG.debug("MyLg new WHILE Items count: "
int newOffsetStartIndex = offsetStartIndex+limit+1; * +totalItemsForStatus+" is less than limit..");
LOG.debug("MyLg NewStartIndex is startIndex+limit: "+newOffsetStartIndex); *
* int newOffsetStartIndex = offsetStartIndex+limit+1;
//THERE ARE OTHER CHILDREN OVER NEW START INDEX * LOG.debug("MyLg NewStartIndex is startIndex+limit: "+newOffsetStartIndex);
if(newOffsetStartIndex < totalItemsForStatus){ *
//newLimit = limit - childrenToReturn.size(); * //THERE ARE OTHER CHILDREN OVER NEW START INDEX if(newOffsetStartIndex <
LOG.debug("MyLg getting items with index start: "+newOffsetStartIndex + ", limit: "+offset); * totalItemsForStatus){ //newLimit = limit - childrenToReturn.size();
* LOG.debug("MyLg getting items with index start: "+newOffsetStartIndex +
int diff = (int) (offset - totalItemsForStatus); //How items are remaining * ", limit: "+offset);
//int offset = 0; *
LOG.debug("MyLg new search start: "+newOffsetStartIndex + ", diff: "+diff+ ", retrieved: "+listDatasetSize); * int diff = (int) (offset - totalItemsForStatus); //How items are remaining
if(diff >= listDatasetSize){ * //int offset = 0; LOG.debug("MyLg new search start: "+newOffsetStartIndex +
}else{ * ", diff: "+diff+ ", retrieved: "+listDatasetSize); if(diff >=
pageOffsetOut = true; * listDatasetSize){ }else{ pageOffsetOut = true; } offsetStartIndex =
} * newOffsetStartIndex; LOG.debug("MyLg items count is: "+totalItemsForStatus +
offsetStartIndex = newOffsetStartIndex; * " serverEndIndex: "+offsetStartIndex);
LOG.debug("MyLg items count is: "+totalItemsForStatus + " serverEndIndex: "+offsetStartIndex); * searchedData.setServerEndIndex(offsetStartIndex); }else{ LOG.
searchedData.setServerEndIndex(offsetStartIndex); * debug("New start index (oldStartIndex+limit) is grather than total items count, search is finished"
}else{ * ); searchedData.setServerSearchFinished(true); } }
LOG.debug("New start index (oldStartIndex+limit) is grather than total items count, search is finished"); */
searchedData.setServerSearchFinished(true); LOG.debug("Returning: " + searchedData);
}
}*/
LOG.debug("Returning: "+searchedData);
return searchedData; return searchedData;
} catch (Exception e) { } catch (Exception e) {

View File

@ -6,7 +6,7 @@ import org.gcube.datacatalogue.utillibrary.shared.ItemStatus;
import com.google.gwt.user.client.rpc.IsSerializable; import com.google.gwt.user.client.rpc.IsSerializable;
// TODO: Auto-generated Javadoc
/** /**
* The Class CatalogueDataset. * The Class CatalogueDataset.
* *
@ -34,7 +34,7 @@ public class CatalogueDataset implements Serializable, IsSerializable {
private String type; private String type;
private String url; private String url;
private String version; private String version;
private String ckanDatasetURL; private String d4scienceItemURL;
private long created; private long created;
/** /**
@ -99,8 +99,12 @@ public class CatalogueDataset implements Serializable, IsSerializable {
return version; return version;
} }
public String getCkanDatasetURL() { public String getD4scienceItemURL() {
return ckanDatasetURL; return d4scienceItemURL;
}
public long getCreated() {
return created;
} }
public void setAuthor(String author) { public void setAuthor(String author) {
@ -159,16 +163,12 @@ public class CatalogueDataset implements Serializable, IsSerializable {
this.version = version; this.version = version;
} }
public void setCkanDatasetURL(String ckanDatasetURL) { public void setD4ScienceItemURL(String d4scienceItemURL) {
this.ckanDatasetURL = ckanDatasetURL; this.d4scienceItemURL = d4scienceItemURL;
} }
public void setCreated(long creationTime) { public void setCreated(long created) {
this.created = creationTime; this.created = created;
}
public long getCreated() {
return created;
} }
@Override @Override
@ -202,8 +202,8 @@ public class CatalogueDataset implements Serializable, IsSerializable {
builder.append(url); builder.append(url);
builder.append(", version="); builder.append(", version=");
builder.append(version); builder.append(version);
builder.append(", ckanDatasetURL="); builder.append(", d4scienceItemURL=");
builder.append(ckanDatasetURL); builder.append(d4scienceItemURL);
builder.append(", created="); builder.append(", created=");
builder.append(created); builder.append(created);
builder.append("]"); builder.append("]");