Added method: getAvailableCataloguesByToken

git-svn-id: http://svn.d4science-ii.research-infrastructures.eu/gcube/trunk/portal/ws-synchronized-module-library@164806 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Francesco Mangiacrapa 2018-03-08 10:55:32 +00:00
parent a6a6d86632
commit 25f0145bf8
3 changed files with 264 additions and 82 deletions

View File

@ -0,0 +1,127 @@
/**
*
*/
package org.gcube.portal.wssynclibrary.shared.thredds;
import java.io.Serializable;
/**
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it Mar 8, 2018
*/
public class ThCatalogueBean implements Serializable, Comparable<ThCatalogueBean>{
/**
*
*/
private static final long serialVersionUID = 56447135995876633L;
private String name;
private String path;
private Boolean isDefault;
public ThCatalogueBean() {
// TODO Auto-generated constructor stub
}
/**
* @param name
* @param path
* @param isDefault
*/
public ThCatalogueBean(String name, String path, Boolean isDefault) {
super();
this.name = name;
this.path = path;
this.isDefault = isDefault;
}
/**
* @return the name
*/
public String getName() {
return name;
}
/**
* @return the path
*/
public String getPath() {
return path;
}
/**
* @return the isDefault
*/
public Boolean getIsDefault() {
return isDefault;
}
/**
* @param name the name to set
*/
public void setName(String name) {
this.name = name;
}
/**
* @param path the path to set
*/
public void setPath(String path) {
this.path = path;
}
/**
* @param isDefault the isDefault to set
*/
public void setIsDefault(Boolean isDefault) {
this.isDefault = isDefault;
}
/* (non-Javadoc)
* @see java.lang.Object#toString()
*/
@Override
public String toString() {
StringBuilder builder = new StringBuilder();
builder.append("ThCatalogueBean [name=");
builder.append(name);
builder.append(", path=");
builder.append(path);
builder.append(", isDefault=");
builder.append(isDefault);
builder.append("]");
return builder.toString();
}
/* (non-Javadoc)
* @see java.lang.Comparable#compareTo(java.lang.Object)
*/
@Override
public int compareTo(ThCatalogueBean o) {
if(o==null)
return -1;
return this.getName().compareTo(o.getName());
}
}

View File

@ -3,6 +3,7 @@ package org.gcube.portal.wssynclibrary.thredds;
import java.util.function.Function;
import org.gcube.portal.wssynclibrary.shared.thredds.Status;
import org.gcube.portal.wssynclibrary.shared.thredds.ThCatalogueBean;
import org.gcube.portal.wssynclibrary.shared.thredds.ThProcessDescriptor;
import org.gcube.portal.wssynclibrary.shared.thredds.ThProcessStatus;
import org.gcube.portal.wssynclibrary.shared.thredds.ThSyncFolderDescriptor;
@ -11,6 +12,7 @@ import org.gcube.usecases.ws.thredds.engine.impl.ProcessDescriptor;
import org.gcube.usecases.ws.thredds.engine.impl.ProcessStatus;
import org.gcube.usecases.ws.thredds.model.SyncFolderDescriptor;
import org.gcube.usecases.ws.thredds.model.SynchFolderConfiguration;
import org.gcube.usecases.ws.thredds.model.gui.CatalogBean;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -123,6 +125,20 @@ public class ThreddsConverter {
};
/** The to th catalogue bean. */
public static Function<CatalogBean, ThCatalogueBean> toThCatalogueBean = new Function<CatalogBean, ThCatalogueBean>() {
@Override
public ThCatalogueBean apply(CatalogBean t) {
if(t==null)
return null;
return new ThCatalogueBean(t.getName(), t.getPath(), t.getIsDefault());
}
};
/** The to th process status. */
public static Function<ProcessStatus, ThProcessStatus> toThProcessStatus = new Function<ProcessStatus, ThProcessStatus>() {
@ -174,4 +190,5 @@ public class ThreddsConverter {
};
}

View File

@ -1,8 +1,11 @@
package org.gcube.portal.wssynclibrary.thredds;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.gcube.common.homelibrary.home.HomeLibrary;
import org.gcube.common.homelibrary.home.workspace.Properties;
@ -12,6 +15,7 @@ import org.gcube.common.scope.api.ScopeProvider;
import org.gcube.portal.wssynclibrary.shared.ItemNotSynched;
import org.gcube.portal.wssynclibrary.shared.thredds.Status;
import org.gcube.portal.wssynclibrary.shared.thredds.Sync_Status;
import org.gcube.portal.wssynclibrary.shared.thredds.ThCatalogueBean;
import org.gcube.portal.wssynclibrary.shared.thredds.ThProcessDescriptor;
import org.gcube.portal.wssynclibrary.shared.thredds.ThProcessStatus;
import org.gcube.portal.wssynclibrary.shared.thredds.ThSyncFolderDescriptor;
@ -28,6 +32,7 @@ import org.gcube.usecases.ws.thredds.faults.WorkspaceNotSynchedException;
import org.gcube.usecases.ws.thredds.model.SyncFolderDescriptor;
import org.gcube.usecases.ws.thredds.model.SyncOperationCallBack;
import org.gcube.usecases.ws.thredds.model.SynchFolderConfiguration;
import org.gcube.usecases.ws.thredds.model.gui.CatalogBean;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -389,4 +394,37 @@ public class WorkspaceThreddsSynchronize implements WorkspaceThreddsSynchronized
mapCallBack.put(itemId, new ThSyncStatus(thDesc, thStatus));
logger.debug("Update map for "+itemId +" with new "+thStatus);
}
/**
* Gets the available catalogues by token.
*
* @param token the token
* @return
* @return the available catalogues by token
* @throws Exception the exception
*/
public List<ThCatalogueBean> getAvailableCataloguesByToken(String token) throws Exception{
if(token==null || token.isEmpty())
throw new Exception("Invalid parameter token null or empty");
logger.debug("Get Available Catalogues by token: "+token.substring(0, token.length()-5)+"XXXXX");
Set<CatalogBean> ctlgs = engine.getAvailableCatalogsByToken(token);
if(ctlgs==null || ctlgs.size()==0)
return new ArrayList<ThCatalogueBean>(1);
List<ThCatalogueBean> listCtlgs = new ArrayList<ThCatalogueBean>(ctlgs.size());
for(CatalogBean bean: ctlgs){
System.out.println(bean.getName()+" in "+bean.getPath()+" Default : "+bean.getIsDefault());
ThCatalogueBean toBean = ThreddsConverter.toThCatalogueBean.apply(bean);
if(toBean!=null)
listCtlgs.add(toBean);
}
Collections.sort(listCtlgs);
return listCtlgs;
}
}