107 lines
3.6 KiB
Java
107 lines
3.6 KiB
Java
/**
|
|
*
|
|
*/
|
|
package org.gcube.portlets.user.sdmxexportwizardtd.server;
|
|
|
|
import java.util.ArrayList;
|
|
import java.util.List;
|
|
|
|
import org.gcube.datapublishing.sdmx.api.model.SDMXRegistryDescriptor;
|
|
import org.gcube.datapublishing.sdmx.api.model.SDMXRegistryInterfaceType;
|
|
import org.gcube.datapublishing.sdmx.api.registry.SDMXRegistryClient;
|
|
import org.gcube.datapublishing.sdmx.api.registry.SDMXRegistryClient.Detail;
|
|
import org.gcube.datapublishing.sdmx.api.registry.SDMXRegistryClient.References;
|
|
import org.gcube.datapublishing.sdmx.impl.model.GCubeSDMXRegistryDescriptor;
|
|
import org.gcube.datapublishing.sdmx.impl.model.SDMXRegistryDescriptorImpl;
|
|
import org.gcube.datapublishing.sdmx.impl.registry.FusionRegistryClient;
|
|
import org.gcube.portlets.user.sdmxexportwizardtd.shared.Agencies;
|
|
import org.gcube.portlets.user.sdmxexportwizardtd.shared.Codelist;
|
|
import org.gcube.portlets.user.sdmxexportwizardtd.shared.Dataset;
|
|
import org.sdmxsource.sdmx.api.model.beans.SdmxBeans;
|
|
import org.sdmxsource.sdmx.api.model.beans.base.AgencyBean;
|
|
import org.sdmxsource.sdmx.api.model.beans.codelist.CodelistBean;
|
|
import org.sdmxsource.sdmx.api.model.beans.datastructure.DataflowBean;
|
|
import org.slf4j.Logger;
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
/**
|
|
*
|
|
* @author "Giancarlo Panichi" <a
|
|
* href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
|
|
*
|
|
*/
|
|
public class SDMXClient {
|
|
|
|
public static enum TYPE {
|
|
INTERNAL, ANOTHER
|
|
}
|
|
|
|
protected static Logger logger = LoggerFactory.getLogger(SDMXClient.class);
|
|
|
|
protected SDMXRegistryClient client;
|
|
protected TYPE type;
|
|
protected String url;
|
|
|
|
public SDMXClient() {
|
|
type = TYPE.INTERNAL;
|
|
url = null;
|
|
SDMXRegistryDescriptor descriptor = new GCubeSDMXRegistryDescriptor();
|
|
client = new FusionRegistryClient(descriptor);
|
|
|
|
}
|
|
|
|
public SDMXClient(String url) {
|
|
type = TYPE.ANOTHER;
|
|
this.url = url;
|
|
SDMXRegistryDescriptorImpl descriptor = new SDMXRegistryDescriptorImpl();
|
|
descriptor.setUrl(SDMXRegistryInterfaceType.RESTV2_1, url);
|
|
client = new FusionRegistryClient(descriptor);
|
|
}
|
|
|
|
public List<Codelist> getAllCodelists() throws Exception {
|
|
SdmxBeans beans = client.getCodelist("all", "all", "all",
|
|
Detail.allstubs, References.none);
|
|
List<Codelist> codelists = new ArrayList<Codelist>();
|
|
for (CodelistBean codelist : beans.getCodelists())
|
|
codelists.add(new Codelist(codelist.getId(), codelist.getName(),
|
|
codelist.getAgencyId(), codelist.getVersion(), codelist
|
|
.getDescription()));
|
|
logger.debug("codelists: " + codelists);
|
|
return codelists;
|
|
}
|
|
|
|
public List<Dataset> getAllDatasets() throws Exception {
|
|
SdmxBeans beans = client.getProvisionAgreement("all", "all", "latest",
|
|
Detail.full, References.children);
|
|
List<Dataset> datasets = new ArrayList<Dataset>();
|
|
for (DataflowBean dataflowBean : beans.getDataflows()) {
|
|
datasets.add(new Dataset(dataflowBean.getId(), dataflowBean
|
|
.getName(), dataflowBean.getAgencyId(), dataflowBean
|
|
.getVersion(), dataflowBean.getDescription()));
|
|
}
|
|
logger.debug("datasets: " + datasets);
|
|
return datasets;
|
|
}
|
|
|
|
public List<Agencies> getAllAgencies() throws Exception {
|
|
List<Agencies> agenciesList = new ArrayList<Agencies>();
|
|
if (client == null) {
|
|
logger.error("getAllAgencies() Error: client is null");
|
|
} else {
|
|
SdmxBeans beans = client.getAgencyScheme("SDMX", "AGENCIES", "1.0",
|
|
Detail.full, References.none);
|
|
if (beans == null) {
|
|
logger.error("getAllAgencies() Error: SdmxBeans is null");
|
|
} else {
|
|
for (AgencyBean agency : beans.getAgencies())
|
|
agenciesList.add(new Agencies(agency.getId(), agency
|
|
.getName(), agency.getDescription()));
|
|
|
|
}
|
|
}
|
|
logger.debug("agencies: " + agenciesList);
|
|
return agenciesList;
|
|
}
|
|
|
|
}
|