From 1a118ecbe377a38438617d83d07653288a1b0045 Mon Sep 17 00:00:00 2001 From: Giancarlo Panichi Date: Mon, 10 Feb 2014 10:54:37 +0000 Subject: [PATCH] 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 --- .../gwtservice/server/TDGWTServiceImpl.java | 244 +++++++++++------- 1 file changed, 155 insertions(+), 89 deletions(-) diff --git a/src/main/java/org/gcube/portlets/user/td/gwtservice/server/TDGWTServiceImpl.java b/src/main/java/org/gcube/portlets/user/td/gwtservice/server/TDGWTServiceImpl.java index e5628ae..e6b83e1 100644 --- a/src/main/java/org/gcube/portlets/user/td/gwtservice/server/TDGWTServiceImpl.java +++ b/src/main/java/org/gcube/portlets/user/td/gwtservice/server/TDGWTServiceImpl.java @@ -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.workspace.Workspace; 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.AuthorizationToken; 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.widgetcommonevent.shared.TRId; 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.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 org.gcube.common.resources.gcore.utils.Group; /** * * @author "Giancarlo Panichi" trs = service.getTabularResourcesByType(codType.getName()); + + CodelistTableType codType = new CodelistTableType(); + + List trs = service + .getTabularResourcesByType(codType.getName()); SessionUtil.setTabularResources(session, trs); ArrayList ltr = new ArrayList(); @@ -675,100 +683,100 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements e.printStackTrace(); logger.error("Error retrieving Codelist in setCodelistsPagingLoader(): " + e.getLocalizedMessage()); - throw new TDGWTServiceException( - "Error retrieving Codelist: " - + e.getLocalizedMessage()); + throw new TDGWTServiceException("Error retrieving Codelist: " + + e.getLocalizedMessage()); } } - + /** * * {@inheritDoc} */ - public CodelistPagingLoadResult getCodelistsPagingLoader(CodelistPagingLoadConfig plc) - throws TDGWTServiceException { + public CodelistPagingLoadResult getCodelistsPagingLoader( + CodelistPagingLoadConfig plc) throws TDGWTServiceException { try { HttpSession session = this.getThreadLocalRequest().getSession(); - - ArrayList ltr = SessionUtil.getCodelistsPagingLoaded(session); - String direction=SessionUtil.getCodelistsPagingLoadedDirection(session); - String filter=SessionUtil.getCodelistsPagingLoadedFilter(session); - - if(ltr==null){ + + ArrayList ltr = SessionUtil + .getCodelistsPagingLoaded(session); + String direction = SessionUtil + .getCodelistsPagingLoadedDirection(session); + String filter = SessionUtil.getCodelistsPagingLoadedFilter(session); + + if (ltr == null) { logger.error("Error no codelist present in session"); throw new TDGWTServiceException( "Error no codelist present in session"); - } - - if(direction==null){ + } + + if (direction == null) { logger.error("Error no codelist direction present in session"); throw new TDGWTServiceException( "Error no codelist direction present in session"); - } - if(filter==null){ + } + if (filter == null) { logger.error("Error no codelist filter present in session"); throw new TDGWTServiceException( "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"); throw new TDGWTServiceException( "Error CodelistPagingLoadConfig no valid range request"); - } - - - int request_end=plc.getOffset()+plc.getLimit(); - if(request_end>ltr.size()){ - request_end=ltr.size(); } - - ArrayList ltrTemp=new ArrayList(); - - if(filter.compareTo(plc.getFilter())!=0){ - + + int request_end = plc.getOffset() + plc.getLimit(); + if (request_end > ltr.size()) { + request_end = ltr.size(); } - - - if(direction.compareTo(plc.getDirection())!=0){ - + + ArrayList ltrTemp = new ArrayList(); + + if (filter.compareTo(plc.getFilter()) != 0) { + } - + + if (direction.compareTo(plc.getDirection()) != 0) { + + } + for (int i = plc.getOffset(); i < request_end; i++) { try { ltr.get(i); ltrTemp.add(ltr.get(i)); } catch (IndexOutOfBoundsException e) { - logger.debug("OutOfBounds in getCodelistsPagingLoader() size:" + ltr.size() + " index: " + i - + " Error:" + e.getMessage() + "\n"); + logger.debug("OutOfBounds in getCodelistsPagingLoader() size:" + + ltr.size() + + " index: " + + i + + " Error:" + + e.getMessage() + "\n"); } } - - CodelistPagingLoadResult codelistPagingLoadResult=new CodelistPagingLoadResult(); + + CodelistPagingLoadResult codelistPagingLoadResult = new CodelistPagingLoadResult(); codelistPagingLoadResult.setFilter(plc.getFilter()); codelistPagingLoadResult.setDirection(plc.getDirection()); codelistPagingLoadResult.setLimit(plc.getLimit()); codelistPagingLoadResult.setOffset(plc.getOffset()); codelistPagingLoadResult.setTotalLenght(ltr.size()); codelistPagingLoadResult.setLtr(ltrTemp); - + logger.debug("Codelists retrieved: " + ltrTemp); return codelistPagingLoadResult; } catch (Exception e) { e.printStackTrace(); logger.error("Error retrieving Codelist in getCodelistsPagingLoader(): " + e.getLocalizedMessage()); - throw new TDGWTServiceException( - "Error retrieving Codelist: " - + e.getLocalizedMessage()); + throw new TDGWTServiceException("Error retrieving Codelist: " + + e.getLocalizedMessage()); } } - - - + /** * * {@inheritDoc} @@ -1871,10 +1879,52 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements * @return */ protected Map 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 client = clientFor(ServiceEndpoint.class); + List listService=client.submit(query); + if(listService.size()>0){ + ServiceEndpoint serviceEnd=listService.get(0); + if(serviceEnd!=null){ + Profile prof=serviceEnd.profile(); + Group 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 parameterInstances = new HashMap(); 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_ID, "NEW_CL_DIVISION"); 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 * @return @@ -2267,7 +2317,8 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements if (changeColumnTypeSession.getColumnTypeCodeTarget().compareTo( ColumnTypeCode.ATTRIBUTE) == 0) { operationDefinition = getOperationDescriptorWithId( - OperationsId.ChangeToAttributeColumn.toString(), capabilities); + OperationsId.ChangeToAttributeColumn.toString(), + capabilities); map.put(Constants.PARAMETER_DATA_TYPE, ColumnDataTypeMap .map(changeColumnTypeSession.getColumnDataType())); @@ -2275,50 +2326,64 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements .getColumnData().getColumnId(), operationDefinition.getOperationId(), map); } else { - if (changeColumnTypeSession.getColumnTypeCodeTarget().compareTo( - ColumnTypeCode.CODE) == 0) { + if (changeColumnTypeSession.getColumnTypeCodeTarget() + .compareTo(ColumnTypeCode.CODE) == 0) { operationDefinition = getOperationDescriptorWithId( - OperationsId.ChangeToCodeColumn.toString(), capabilities); + OperationsId.ChangeToCodeColumn.toString(), + capabilities); invocation = new OperationExecution(changeColumnTypeSession .getColumnData().getColumnId(), - operationDefinition.getOperationId(),map); + operationDefinition.getOperationId(), map); } else { - if (changeColumnTypeSession.getColumnTypeCodeTarget().compareTo( - ColumnTypeCode.CODENAME) == 0) { + if (changeColumnTypeSession.getColumnTypeCodeTarget() + .compareTo(ColumnTypeCode.CODENAME) == 0) { operationDefinition = getOperationDescriptorWithId( - OperationsId.ChangeToCodeName.toString(), capabilities); - invocation = new OperationExecution(changeColumnTypeSession - .getColumnData().getColumnId(), - operationDefinition.getOperationId(),map); + OperationsId.ChangeToCodeName.toString(), + capabilities); + invocation = new OperationExecution( + changeColumnTypeSession.getColumnData() + .getColumnId(), + operationDefinition.getOperationId(), map); } else { - if (changeColumnTypeSession.getColumnTypeCodeTarget().compareTo( - ColumnTypeCode.CODEDESCRIPTION) == 0) { + if (changeColumnTypeSession.getColumnTypeCodeTarget() + .compareTo(ColumnTypeCode.CODEDESCRIPTION) == 0) { operationDefinition = getOperationDescriptorWithId( - OperationsId.ChangeToCodeDescription.toString(), capabilities); - invocation = new OperationExecution(changeColumnTypeSession - .getColumnData().getColumnId(), - operationDefinition.getOperationId(),map); + OperationsId.ChangeToCodeDescription + .toString(), + capabilities); + invocation = new OperationExecution( + changeColumnTypeSession.getColumnData() + .getColumnId(), + operationDefinition.getOperationId(), map); } else { - if (changeColumnTypeSession.getColumnTypeCodeTarget().compareTo( - ColumnTypeCode.ANNOTATION) == 0) { + if (changeColumnTypeSession + .getColumnTypeCodeTarget().compareTo( + ColumnTypeCode.ANNOTATION) == 0) { operationDefinition = getOperationDescriptorWithId( - OperationsId.ChangeToAnnotationColumn.toString(), capabilities); - invocation = new OperationExecution(changeColumnTypeSession - .getColumnData().getColumnId(), - operationDefinition.getOperationId(),map); + OperationsId.ChangeToAnnotationColumn + .toString(), + capabilities); + invocation = new OperationExecution( + changeColumnTypeSession.getColumnData() + .getColumnId(), + operationDefinition.getOperationId(), + map); } else { - if (changeColumnTypeSession.getColumnTypeCodeTarget().compareTo( - ColumnTypeCode.DIMENSION) == 0) { + if (changeColumnTypeSession + .getColumnTypeCodeTarget().compareTo( + ColumnTypeCode.DIMENSION) == 0) { } else { - if (changeColumnTypeSession.getColumnTypeCodeTarget().compareTo( - ColumnTypeCode.TIMEDIMENSION) == 0) { + if (changeColumnTypeSession + .getColumnTypeCodeTarget() + .compareTo( + ColumnTypeCode.TIMEDIMENSION) == 0) { } else { - + } } } } - + } } } @@ -2346,10 +2411,11 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements OperationExecution invocation = retriveOperationExecution(service, changeColumnTypeSession); - if(invocation==null){ - throw new TDGWTServiceException("Error in ChangeColumnType: Operation not supported for now!"); + if (invocation == null) { + throw new TDGWTServiceException( + "Error in ChangeColumnType: Operation not supported for now!"); } - + TabularResourceId serviceTR = new TabularResourceId( Long.valueOf(changeColumnTypeSession.getColumnData() .getTrId().getId()));