Minor Update

git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/portlets/user/tabular-data-gwt-service@91251 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Giancarlo Panichi 2014-02-10 10:54:37 +00:00
parent 009ab1315b
commit 1a118ecbe3
1 changed files with 155 additions and 89 deletions

View File

@ -25,6 +25,9 @@ import org.gcube.common.homelibrary.home.HomeManagerFactory;
import org.gcube.common.homelibrary.home.exceptions.InternalErrorException; import org.gcube.common.homelibrary.home.exceptions.InternalErrorException;
import org.gcube.common.homelibrary.home.workspace.Workspace; import org.gcube.common.homelibrary.home.workspace.Workspace;
import org.gcube.common.homelibrary.home.workspace.WorkspaceItem; import org.gcube.common.homelibrary.home.workspace.WorkspaceItem;
import org.gcube.common.resources.gcore.ServiceEndpoint;
import org.gcube.common.resources.gcore.ServiceEndpoint.AccessPoint;
import org.gcube.common.resources.gcore.ServiceEndpoint.Profile;
import org.gcube.data.analysis.tabulardata.commons.utils.AuthorizationProvider; import org.gcube.data.analysis.tabulardata.commons.utils.AuthorizationProvider;
import org.gcube.data.analysis.tabulardata.commons.utils.AuthorizationToken; import org.gcube.data.analysis.tabulardata.commons.utils.AuthorizationToken;
import org.gcube.data.analysis.tabulardata.commons.webservice.types.TaskStatus; import org.gcube.data.analysis.tabulardata.commons.webservice.types.TaskStatus;
@ -113,11 +116,17 @@ import org.gcube.portlets.user.td.gwtservice.shared.tr.type.Codelist;
import org.gcube.portlets.user.td.gwtservice.shared.tr.type.Dataset; import org.gcube.portlets.user.td.gwtservice.shared.tr.type.Dataset;
import org.gcube.portlets.user.td.widgetcommonevent.shared.TRId; import org.gcube.portlets.user.td.widgetcommonevent.shared.TRId;
import org.gcube.portlets.user.td.widgetcommonevent.shared.tr.column.ColumnTypeCode; import org.gcube.portlets.user.td.widgetcommonevent.shared.tr.column.ColumnTypeCode;
import org.gcube.resources.discovery.client.api.DiscoveryClient;
import org.gcube.resources.discovery.client.queries.api.SimpleQuery;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import static org.gcube.resources.discovery.icclient.ICFactory.clientFor;
import static org.gcube.resources.discovery.icclient.ICFactory.queryFor;
import com.google.gwt.user.server.rpc.RemoteServiceServlet; import com.google.gwt.user.server.rpc.RemoteServiceServlet;
import org.gcube.common.resources.gcore.utils.Group;
/** /**
* *
* @author "Giancarlo Panichi" <a * @author "Giancarlo Panichi" <a
@ -638,13 +647,11 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
return t; return t;
} }
/** /**
* *
* {@inheritDoc} * {@inheritDoc}
*/ */
public void setCodelistsPagingLoader() public void setCodelistsPagingLoader() throws TDGWTServiceException {
throws TDGWTServiceException {
try { try {
HttpSession session = this.getThreadLocalRequest().getSession(); HttpSession session = this.getThreadLocalRequest().getSession();
ASLSession aslSession = SessionUtil.getAslSession(session); ASLSession aslSession = SessionUtil.getAslSession(session);
@ -652,10 +659,11 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
AuthorizationProvider.instance.set(new AuthorizationToken( AuthorizationProvider.instance.set(new AuthorizationToken(
aslSession.getUsername())); aslSession.getUsername()));
TabularDataService service = TabularDataServiceFactory.getService(); TabularDataService service = TabularDataServiceFactory.getService();
CodelistTableType codType=new CodelistTableType(); CodelistTableType codType = new CodelistTableType();
List<TabularResource> trs = service.getTabularResourcesByType(codType.getName()); List<TabularResource> trs = service
.getTabularResourcesByType(codType.getName());
SessionUtil.setTabularResources(session, trs); SessionUtil.setTabularResources(session, trs);
ArrayList<TabResource> ltr = new ArrayList<TabResource>(); ArrayList<TabResource> ltr = new ArrayList<TabResource>();
@ -675,100 +683,100 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
e.printStackTrace(); e.printStackTrace();
logger.error("Error retrieving Codelist in setCodelistsPagingLoader(): " logger.error("Error retrieving Codelist in setCodelistsPagingLoader(): "
+ e.getLocalizedMessage()); + e.getLocalizedMessage());
throw new TDGWTServiceException( throw new TDGWTServiceException("Error retrieving Codelist: "
"Error retrieving Codelist: " + e.getLocalizedMessage());
+ e.getLocalizedMessage());
} }
} }
/** /**
* *
* {@inheritDoc} * {@inheritDoc}
*/ */
public CodelistPagingLoadResult getCodelistsPagingLoader(CodelistPagingLoadConfig plc) public CodelistPagingLoadResult getCodelistsPagingLoader(
throws TDGWTServiceException { CodelistPagingLoadConfig plc) throws TDGWTServiceException {
try { try {
HttpSession session = this.getThreadLocalRequest().getSession(); HttpSession session = this.getThreadLocalRequest().getSession();
ArrayList<TabResource> ltr = SessionUtil.getCodelistsPagingLoaded(session); ArrayList<TabResource> ltr = SessionUtil
String direction=SessionUtil.getCodelistsPagingLoadedDirection(session); .getCodelistsPagingLoaded(session);
String filter=SessionUtil.getCodelistsPagingLoadedFilter(session); String direction = SessionUtil
.getCodelistsPagingLoadedDirection(session);
if(ltr==null){ String filter = SessionUtil.getCodelistsPagingLoadedFilter(session);
if (ltr == null) {
logger.error("Error no codelist present in session"); logger.error("Error no codelist present in session");
throw new TDGWTServiceException( throw new TDGWTServiceException(
"Error no codelist present in session"); "Error no codelist present in session");
} }
if(direction==null){ if (direction == null) {
logger.error("Error no codelist direction present in session"); logger.error("Error no codelist direction present in session");
throw new TDGWTServiceException( throw new TDGWTServiceException(
"Error no codelist direction present in session"); "Error no codelist direction present in session");
} }
if(filter==null){ if (filter == null) {
logger.error("Error no codelist filter present in session"); logger.error("Error no codelist filter present in session");
throw new TDGWTServiceException( throw new TDGWTServiceException(
"Error no codelist filter present in session"); "Error no codelist filter present in session");
} }
if(plc.getOffset()<0 || plc.getOffset()>=ltr.size()){ if (plc.getOffset() < 0 || plc.getOffset() >= ltr.size()) {
logger.error("Error CodelistPagingLoadConfig no valid range request"); logger.error("Error CodelistPagingLoadConfig no valid range request");
throw new TDGWTServiceException( throw new TDGWTServiceException(
"Error CodelistPagingLoadConfig no valid range request"); "Error CodelistPagingLoadConfig no valid range request");
}
int request_end=plc.getOffset()+plc.getLimit();
if(request_end>ltr.size()){
request_end=ltr.size();
} }
ArrayList<TabResource> ltrTemp=new ArrayList<TabResource>(); int request_end = plc.getOffset() + plc.getLimit();
if (request_end > ltr.size()) {
if(filter.compareTo(plc.getFilter())!=0){ request_end = ltr.size();
} }
ArrayList<TabResource> ltrTemp = new ArrayList<TabResource>();
if(direction.compareTo(plc.getDirection())!=0){
if (filter.compareTo(plc.getFilter()) != 0) {
} }
if (direction.compareTo(plc.getDirection()) != 0) {
}
for (int i = plc.getOffset(); i < request_end; i++) { for (int i = plc.getOffset(); i < request_end; i++) {
try { try {
ltr.get(i); ltr.get(i);
ltrTemp.add(ltr.get(i)); ltrTemp.add(ltr.get(i));
} catch (IndexOutOfBoundsException e) { } catch (IndexOutOfBoundsException e) {
logger.debug("OutOfBounds in getCodelistsPagingLoader() size:" + ltr.size() + " index: " + i logger.debug("OutOfBounds in getCodelistsPagingLoader() size:"
+ " Error:" + e.getMessage() + "\n"); + ltr.size()
+ " index: "
+ i
+ " Error:"
+ e.getMessage() + "\n");
} }
} }
CodelistPagingLoadResult codelistPagingLoadResult=new CodelistPagingLoadResult(); CodelistPagingLoadResult codelistPagingLoadResult = new CodelistPagingLoadResult();
codelistPagingLoadResult.setFilter(plc.getFilter()); codelistPagingLoadResult.setFilter(plc.getFilter());
codelistPagingLoadResult.setDirection(plc.getDirection()); codelistPagingLoadResult.setDirection(plc.getDirection());
codelistPagingLoadResult.setLimit(plc.getLimit()); codelistPagingLoadResult.setLimit(plc.getLimit());
codelistPagingLoadResult.setOffset(plc.getOffset()); codelistPagingLoadResult.setOffset(plc.getOffset());
codelistPagingLoadResult.setTotalLenght(ltr.size()); codelistPagingLoadResult.setTotalLenght(ltr.size());
codelistPagingLoadResult.setLtr(ltrTemp); codelistPagingLoadResult.setLtr(ltrTemp);
logger.debug("Codelists retrieved: " + ltrTemp); logger.debug("Codelists retrieved: " + ltrTemp);
return codelistPagingLoadResult; return codelistPagingLoadResult;
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
logger.error("Error retrieving Codelist in getCodelistsPagingLoader(): " logger.error("Error retrieving Codelist in getCodelistsPagingLoader(): "
+ e.getLocalizedMessage()); + e.getLocalizedMessage());
throw new TDGWTServiceException( throw new TDGWTServiceException("Error retrieving Codelist: "
"Error retrieving Codelist: " + e.getLocalizedMessage());
+ e.getLocalizedMessage());
} }
} }
/** /**
* *
* {@inheritDoc} * {@inheritDoc}
@ -1871,10 +1879,52 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
* @return * @return
*/ */
protected Map<String, Object> sdmxExportParameter( protected Map<String, Object> sdmxExportParameter(
SDMXExportSession exportSession) { SDMXExportSession exportSession) throws TDGWTServiceException {
boolean internalRegistry = false;
String destination=null;//Es: http://pc-fortunati.isti.cnr.it:8080/FusionRegistry/ws/rest/
if (exportSession != null) {
if (exportSession.getRegistryBaseUrl() != null
&& !exportSession.getRegistryBaseUrl().isEmpty()) {
destination= exportSession.getRegistryBaseUrl();
} else {
internalRegistry = true;
}
} else {
internalRegistry = true;
}
if(internalRegistry){
SimpleQuery query = queryFor(ServiceEndpoint.class);
query.addCondition("$resource/Profile/Category/text() eq 'SDMX'").addCondition("$resource/Profile/Name/text() eq 'SDMXRegistry'");
DiscoveryClient<ServiceEndpoint> client = clientFor(ServiceEndpoint.class);
List<ServiceEndpoint> listService=client.submit(query);
if(listService.size()>0){
ServiceEndpoint serviceEnd=listService.get(0);
if(serviceEnd!=null){
Profile prof=serviceEnd.profile();
Group<AccessPoint> groupA=prof.accessPoints();
for(AccessPoint acc: groupA){
if(acc.description().compareTo("REST Interface v2.1")==0){
destination=acc.address();
break;
}
}
} else {
}
} else {
}
}
if(destination==null){
logger.debug("Destination: "+destination);
throw new TDGWTServiceException("SDMX Service not discovered");
}
Map<String, Object> parameterInstances = new HashMap<String, Object>(); Map<String, Object> parameterInstances = new HashMap<String, Object>();
parameterInstances.put(Constants.PARAMETER_REGISTRYBASEURL, parameterInstances.put(Constants.PARAMETER_REGISTRYBASEURL,
"http://pc-fortunati.isti.cnr.it:8080/FusionRegistry/ws/rest/"); destination);
parameterInstances.put(Constants.PARAMETER_AGENCY, "SDMX"); parameterInstances.put(Constants.PARAMETER_AGENCY, "SDMX");
parameterInstances.put(Constants.PARAMETER_ID, "NEW_CL_DIVISION"); parameterInstances.put(Constants.PARAMETER_ID, "NEW_CL_DIVISION");
parameterInstances.put(Constants.PARAMETER_VERSION, "2.0"); parameterInstances.put(Constants.PARAMETER_VERSION, "2.0");
@ -2234,7 +2284,7 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
} }
/** /**
* Retrieve OperationExecution for change column type * Retrieve OperationExecution for change column type
* *
* @param changeColumnTypeSession * @param changeColumnTypeSession
* @return * @return
@ -2267,7 +2317,8 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
if (changeColumnTypeSession.getColumnTypeCodeTarget().compareTo( if (changeColumnTypeSession.getColumnTypeCodeTarget().compareTo(
ColumnTypeCode.ATTRIBUTE) == 0) { ColumnTypeCode.ATTRIBUTE) == 0) {
operationDefinition = getOperationDescriptorWithId( operationDefinition = getOperationDescriptorWithId(
OperationsId.ChangeToAttributeColumn.toString(), capabilities); OperationsId.ChangeToAttributeColumn.toString(),
capabilities);
map.put(Constants.PARAMETER_DATA_TYPE, ColumnDataTypeMap map.put(Constants.PARAMETER_DATA_TYPE, ColumnDataTypeMap
.map(changeColumnTypeSession.getColumnDataType())); .map(changeColumnTypeSession.getColumnDataType()));
@ -2275,50 +2326,64 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
.getColumnData().getColumnId(), .getColumnData().getColumnId(),
operationDefinition.getOperationId(), map); operationDefinition.getOperationId(), map);
} else { } else {
if (changeColumnTypeSession.getColumnTypeCodeTarget().compareTo( if (changeColumnTypeSession.getColumnTypeCodeTarget()
ColumnTypeCode.CODE) == 0) { .compareTo(ColumnTypeCode.CODE) == 0) {
operationDefinition = getOperationDescriptorWithId( operationDefinition = getOperationDescriptorWithId(
OperationsId.ChangeToCodeColumn.toString(), capabilities); OperationsId.ChangeToCodeColumn.toString(),
capabilities);
invocation = new OperationExecution(changeColumnTypeSession invocation = new OperationExecution(changeColumnTypeSession
.getColumnData().getColumnId(), .getColumnData().getColumnId(),
operationDefinition.getOperationId(),map); operationDefinition.getOperationId(), map);
} else { } else {
if (changeColumnTypeSession.getColumnTypeCodeTarget().compareTo( if (changeColumnTypeSession.getColumnTypeCodeTarget()
ColumnTypeCode.CODENAME) == 0) { .compareTo(ColumnTypeCode.CODENAME) == 0) {
operationDefinition = getOperationDescriptorWithId( operationDefinition = getOperationDescriptorWithId(
OperationsId.ChangeToCodeName.toString(), capabilities); OperationsId.ChangeToCodeName.toString(),
invocation = new OperationExecution(changeColumnTypeSession capabilities);
.getColumnData().getColumnId(), invocation = new OperationExecution(
operationDefinition.getOperationId(),map); changeColumnTypeSession.getColumnData()
.getColumnId(),
operationDefinition.getOperationId(), map);
} else { } else {
if (changeColumnTypeSession.getColumnTypeCodeTarget().compareTo( if (changeColumnTypeSession.getColumnTypeCodeTarget()
ColumnTypeCode.CODEDESCRIPTION) == 0) { .compareTo(ColumnTypeCode.CODEDESCRIPTION) == 0) {
operationDefinition = getOperationDescriptorWithId( operationDefinition = getOperationDescriptorWithId(
OperationsId.ChangeToCodeDescription.toString(), capabilities); OperationsId.ChangeToCodeDescription
invocation = new OperationExecution(changeColumnTypeSession .toString(),
.getColumnData().getColumnId(), capabilities);
operationDefinition.getOperationId(),map); invocation = new OperationExecution(
changeColumnTypeSession.getColumnData()
.getColumnId(),
operationDefinition.getOperationId(), map);
} else { } else {
if (changeColumnTypeSession.getColumnTypeCodeTarget().compareTo( if (changeColumnTypeSession
ColumnTypeCode.ANNOTATION) == 0) { .getColumnTypeCodeTarget().compareTo(
ColumnTypeCode.ANNOTATION) == 0) {
operationDefinition = getOperationDescriptorWithId( operationDefinition = getOperationDescriptorWithId(
OperationsId.ChangeToAnnotationColumn.toString(), capabilities); OperationsId.ChangeToAnnotationColumn
invocation = new OperationExecution(changeColumnTypeSession .toString(),
.getColumnData().getColumnId(), capabilities);
operationDefinition.getOperationId(),map); invocation = new OperationExecution(
changeColumnTypeSession.getColumnData()
.getColumnId(),
operationDefinition.getOperationId(),
map);
} else { } else {
if (changeColumnTypeSession.getColumnTypeCodeTarget().compareTo( if (changeColumnTypeSession
ColumnTypeCode.DIMENSION) == 0) { .getColumnTypeCodeTarget().compareTo(
ColumnTypeCode.DIMENSION) == 0) {
} else { } else {
if (changeColumnTypeSession.getColumnTypeCodeTarget().compareTo( if (changeColumnTypeSession
ColumnTypeCode.TIMEDIMENSION) == 0) { .getColumnTypeCodeTarget()
.compareTo(
ColumnTypeCode.TIMEDIMENSION) == 0) {
} else { } else {
} }
} }
} }
} }
} }
} }
} }
@ -2346,10 +2411,11 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
OperationExecution invocation = retriveOperationExecution(service, OperationExecution invocation = retriveOperationExecution(service,
changeColumnTypeSession); changeColumnTypeSession);
if(invocation==null){ if (invocation == null) {
throw new TDGWTServiceException("Error in ChangeColumnType: Operation not supported for now!"); throw new TDGWTServiceException(
"Error in ChangeColumnType: Operation not supported for now!");
} }
TabularResourceId serviceTR = new TabularResourceId( TabularResourceId serviceTR = new TabularResourceId(
Long.valueOf(changeColumnTypeSession.getColumnData() Long.valueOf(changeColumnTypeSession.getColumnData()
.getTrId().getId())); .getTrId().getId()));