diff --git a/src/main/java/org/gcube/portlets/user/td/gwtservice/client/rpc/TDGWTService.java b/src/main/java/org/gcube/portlets/user/td/gwtservice/client/rpc/TDGWTService.java index e7e74b9..b5a375d 100644 --- a/src/main/java/org/gcube/portlets/user/td/gwtservice/client/rpc/TDGWTService.java +++ b/src/main/java/org/gcube/portlets/user/td/gwtservice/client/rpc/TDGWTService.java @@ -29,6 +29,7 @@ import org.gcube.portlets.user.td.gwtservice.shared.template.TemplateApplySessio import org.gcube.portlets.user.td.gwtservice.shared.template.TemplateData; import org.gcube.portlets.user.td.gwtservice.shared.template.TemplateDeleteSession; import org.gcube.portlets.user.td.gwtservice.shared.tr.ColumnData; +import org.gcube.portlets.user.td.gwtservice.shared.tr.RefColumn; import org.gcube.portlets.user.td.gwtservice.shared.tr.TabResource; import org.gcube.portlets.user.td.gwtservice.shared.tr.TableData; import org.gcube.portlets.user.td.gwtservice.shared.tr.batch.Occurrences; @@ -96,14 +97,13 @@ public interface TDGWTService extends RemoteService { // TabularResource /** - * Get current TRId + * Get current TRId * * @return * @throws TDGWTServiceException */ public TRId getCurrentTRId() throws TDGWTServiceException; - - + /** * Get informations on the current tabular resource * @@ -204,11 +204,18 @@ public interface TDGWTService extends RemoteService { */ public ArrayList getTRMetadata(TRId trId) throws TDGWTServiceException; - - - - - //Validations + + /** + * Retreive a ColumnData that is a connection to external table + * + * @param refColumn + * @return + * @throws TDGWTServiceException + */ + public ColumnData getConnection(RefColumn refColumn) + throws TDGWTServiceException; + + // Validations /** * Returns validations contained in the tasks * @@ -216,9 +223,9 @@ public interface TDGWTService extends RemoteService { * @return * @throws TDGWTServiceException */ - public ValidationsTasksMetadata getValidationsTasksMetadata(TRId trId) - throws TDGWTServiceException; - + public ValidationsTasksMetadata getValidationsTasksMetadata(TRId trId) + throws TDGWTServiceException; + /** * Return Validations Metadata of Table * @@ -226,10 +233,9 @@ public interface TDGWTService extends RemoteService { * @return * @throws TDGWTServiceException */ - public TabValidationsMetadata getTableValidationsMetadata(TRId trId) + public TabValidationsMetadata getTableValidationsMetadata(TRId trId) throws TDGWTServiceException; - - + /** * Returns ArrayList that contains all the validation columns of * columnName @@ -241,37 +247,34 @@ public interface TDGWTService extends RemoteService { */ public ArrayList getValidationColumns(TRId trId, String columnName) throws TDGWTServiceException; - - - //RollBack + + // RollBack /** * Call rollback on tabular resource * * @param rollBackSession * @throws TDGWTServiceException */ - public void rollBack(RollBackSession rollBackSession) + public void rollBack(RollBackSession rollBackSession) throws TDGWTServiceException; - + /** - * Get Operation Monitor during the rollback + * Get Operation Monitor during the rollback * * @return * @throws TDGWTServiceException */ public RollBackSessionMonitor getRollBackMonitor() throws TDGWTServiceException; - + /** * Call discard operation on tabular resource * * @param trId * @throws TDGWTServiceException */ - public RollBackSession discard(TRId trId) - throws TDGWTServiceException; - - + public RollBackSession discard(TRId trId) throws TDGWTServiceException; + // Share /** * Retrieves information sharing on the tabular resource @@ -596,11 +599,10 @@ public interface TDGWTService extends RemoteService { * @return * @throws TDGWTServiceException */ - public EditRowMonitor getEditRowMonitor() - throws TDGWTServiceException; + public EditRowMonitor getEditRowMonitor() throws TDGWTServiceException; /** - * Start edit row or add row + * Start edit row or add row * * @param labelColumnSession * @throws TDGWTServiceException @@ -608,7 +610,6 @@ public interface TDGWTService extends RemoteService { public void startEditRow(EditRowSession editRowSession) throws TDGWTServiceException; - /** * Get Operation Monitor during the Delete Rows operation * @@ -805,8 +806,8 @@ public interface TDGWTService extends RemoteService { * @throws TDGWTServiceException */ ArrayList getLocales() throws TDGWTServiceException; - - //History + + // History /** * Retrieve History * @@ -814,7 +815,7 @@ public interface TDGWTService extends RemoteService { * @throws TDGWTServiceException */ ArrayList getHistory() throws TDGWTServiceException; - + /** * Retrieve History for specific tabular resource * @@ -823,14 +824,14 @@ public interface TDGWTService extends RemoteService { * @throws TDGWTServiceException */ ArrayList getHistory(TRId trId) throws TDGWTServiceException; - + /** * * @return * @throws TDGWTServiceException */ OpHistory getLastOperationInfo() throws TDGWTServiceException; - + /** * * @param trId @@ -838,6 +839,5 @@ public interface TDGWTService extends RemoteService { * @throws TDGWTServiceException */ OpHistory getLastOperationInfo(TRId trId) throws TDGWTServiceException; - - + } diff --git a/src/main/java/org/gcube/portlets/user/td/gwtservice/client/rpc/TDGWTServiceAsync.java b/src/main/java/org/gcube/portlets/user/td/gwtservice/client/rpc/TDGWTServiceAsync.java index f8f0020..3d175b5 100644 --- a/src/main/java/org/gcube/portlets/user/td/gwtservice/client/rpc/TDGWTServiceAsync.java +++ b/src/main/java/org/gcube/portlets/user/td/gwtservice/client/rpc/TDGWTServiceAsync.java @@ -28,6 +28,7 @@ import org.gcube.portlets.user.td.gwtservice.shared.template.TemplateApplySessio import org.gcube.portlets.user.td.gwtservice.shared.template.TemplateData; import org.gcube.portlets.user.td.gwtservice.shared.template.TemplateDeleteSession; import org.gcube.portlets.user.td.gwtservice.shared.tr.ColumnData; +import org.gcube.portlets.user.td.gwtservice.shared.tr.RefColumn; import org.gcube.portlets.user.td.gwtservice.shared.tr.TabResource; import org.gcube.portlets.user.td.gwtservice.shared.tr.TableData; import org.gcube.portlets.user.td.gwtservice.shared.tr.batch.Occurrences; @@ -100,6 +101,7 @@ public interface TDGWTServiceAsync { void getColumnsForDimension(TRId trId, AsyncCallback> callback); void getColumn(TRId trId, String columnName, AsyncCallback callback); void getColumn(String columnLocalId,TRId trId, AsyncCallback callback); + void getConnection(RefColumn refColumn, AsyncCallback callback); //Validations void getValidationsTasksMetadata(TRId trId,AsyncCallback callback); diff --git a/src/main/java/org/gcube/portlets/user/td/gwtservice/server/SessionUtil.java b/src/main/java/org/gcube/portlets/user/td/gwtservice/server/SessionUtil.java index b827a5a..90f5449 100644 --- a/src/main/java/org/gcube/portlets/user/td/gwtservice/server/SessionUtil.java +++ b/src/main/java/org/gcube/portlets/user/td/gwtservice/server/SessionUtil.java @@ -16,6 +16,7 @@ import org.gcube.data.analysis.tabulardata.service.tabular.TabularResource; import org.gcube.portal.custom.scopemanager.scopehelper.ScopeHelper; import org.gcube.portlets.user.td.gwtservice.server.file.FileUploadSession; import org.gcube.portlets.user.td.gwtservice.server.trservice.TRTasksManager; +import org.gcube.portlets.user.td.gwtservice.shared.Constants; import org.gcube.portlets.user.td.gwtservice.shared.csv.CSVExportSession; import org.gcube.portlets.user.td.gwtservice.shared.csv.CSVImportSession; import org.gcube.portlets.user.td.gwtservice.shared.exception.TDGWTSessionExpiredException; @@ -73,15 +74,15 @@ public class SessionUtil { ASLSession session; if (username == null) { logger.warn("no user found in session, using test one"); - throw new TDGWTSessionExpiredException("Session Expired!"); + /*throw new TDGWTSessionExpiredException("Session Expired!");*/ - /*username = Constants.DEFAULT_USER; + username = Constants.DEFAULT_USER; String scope = Constants.DEFAULT_SCOPE; httpSession.setAttribute(ScopeHelper.USERNAME_ATTRIBUTE, username); session = SessionManager.getInstance().getASLSession( httpSession.getId(), username); - session.setScope(scope);*/ + session.setScope(scope); } else { session = SessionManager.getInstance().getASLSession( 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 d88366e..ee33802 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 @@ -64,6 +64,7 @@ import org.gcube.data.analysis.tabulardata.model.metadata.common.DescriptionsMet import org.gcube.data.analysis.tabulardata.model.metadata.common.ImmutableLocalizedText; import org.gcube.data.analysis.tabulardata.model.metadata.common.LocalizedText; import org.gcube.data.analysis.tabulardata.model.metadata.common.NamesMetadata; +import org.gcube.data.analysis.tabulardata.model.metadata.common.TableDescriptorMetadata; import org.gcube.data.analysis.tabulardata.model.metadata.common.Validation; import org.gcube.data.analysis.tabulardata.model.metadata.common.ValidationsMetadata; import org.gcube.data.analysis.tabulardata.model.metadata.table.DatasetViewTableMetadata; @@ -100,12 +101,13 @@ import org.gcube.portlets.user.td.gwtservice.server.file.FileUtil; import org.gcube.portlets.user.td.gwtservice.server.storage.FilesStorage; import org.gcube.portlets.user.td.gwtservice.server.trservice.ColumnDataTypeMap; import org.gcube.portlets.user.td.gwtservice.server.trservice.ExpressionGenerator; +import org.gcube.portlets.user.td.gwtservice.server.trservice.ExtractReferences; import org.gcube.portlets.user.td.gwtservice.server.trservice.OperationDefinitionMap; -import org.gcube.portlets.user.td.gwtservice.server.trservice.OperationsId; import org.gcube.portlets.user.td.gwtservice.server.trservice.QueryService; import org.gcube.portlets.user.td.gwtservice.server.trservice.TaskStateMap; import org.gcube.portlets.user.td.gwtservice.server.trservice.ValueMap; import org.gcube.portlets.user.td.gwtservice.shared.Constants; +import org.gcube.portlets.user.td.gwtservice.shared.OperationsId; import org.gcube.portlets.user.td.gwtservice.shared.csv.AvailableCharsetList; import org.gcube.portlets.user.td.gwtservice.shared.csv.CSVExportMonitor; import org.gcube.portlets.user.td.gwtservice.shared.csv.CSVExportSession; @@ -140,6 +142,7 @@ import org.gcube.portlets.user.td.gwtservice.shared.template.TemplateData; import org.gcube.portlets.user.td.gwtservice.shared.template.TemplateDeleteSession; import org.gcube.portlets.user.td.gwtservice.shared.tr.ColumnData; import org.gcube.portlets.user.td.gwtservice.shared.tr.ColumnViewData; +import org.gcube.portlets.user.td.gwtservice.shared.tr.RefColumn; import org.gcube.portlets.user.td.gwtservice.shared.tr.RelationshipData; import org.gcube.portlets.user.td.gwtservice.shared.tr.TabResource; import org.gcube.portlets.user.td.gwtservice.shared.tr.TableData; @@ -3871,7 +3874,7 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements * @param replaceColumnSession * @return */ - // TODO Check this operation + protected OperationExecution retrieveOperationExecution( TabularDataService service, EditRowSession editRowSession) throws TDGWTServiceException { @@ -6487,6 +6490,8 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements validations.add(validation); i++; } + //TODO Fix refColumn + InvocationS invocationS=null; if (job.getInvocation() != null) { Map mapSent=new HashMap(); @@ -6499,10 +6504,12 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements mapSent.put(key, o.toString()); } + RefColumn refColumn=ExtractReferences.extract(job.getInvocation()); + invocationS = new InvocationS(job.getInvocation() .getColumnId(), job.getInvocation() .getIdentifier(), job.getInvocation() - .getOperationId(), mapSent); + .getOperationId(), mapSent, refColumn); } JobS jobS = new JobS(String.valueOf(j), job.getProgress(), job.getHumaReadableStatus(), job.getDescription(), @@ -6678,5 +6685,44 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements } } + + + //TODO Connect + @Override + public ColumnData getConnection(RefColumn refColumn) + throws TDGWTServiceException { + try { + HttpSession session = this.getThreadLocalRequest().getSession(); + ASLSession aslSession = SessionUtil.getAslSession(session); + + logger.debug("GetConnection on " + refColumn.toString()); + AuthorizationProvider.instance.set(new AuthorizationToken( + aslSession.getUsername())); + TabularDataService service = TabularDataServiceFactory.getService(); + TableId tableId = new TableId( + new Long(refColumn.getTableId())); + + Table table=service.getTable(tableId); + TableDescriptorMetadata tableDesc=table.getMetadata(TableDescriptorMetadata.class); + if(tableDesc==null){ + logger.error("Error in getConnection(): No TableDescriptorMetadata found for table "+table); + throw new TDGWTServiceException("Error in getConnection(): No TableDescriptorMetadata found for table "+table); + } + + logger.debug("Table connect to tabular resource: "+tableDesc.getRefId()); + TRId tId=new TRId(String.valueOf(tableDesc.getRefId())); + TRId trId=retrieveTabularResourceBasicData(tId); + ColumnData columnData=getColumn(refColumn.getColumnId(), trId); + + return columnData; + } catch (TDGWTSessionExpiredException e) { + throw e; + } catch (Throwable e) { + logger.debug("Error in getConnection(): " + e.getLocalizedMessage()); + e.printStackTrace(); + throw new TDGWTServiceException("Error: " + e.getLocalizedMessage()); + + } + } } diff --git a/src/main/java/org/gcube/portlets/user/td/gwtservice/server/trservice/ExtractReferences.java b/src/main/java/org/gcube/portlets/user/td/gwtservice/server/trservice/ExtractReferences.java new file mode 100644 index 0000000..2dfa00e --- /dev/null +++ b/src/main/java/org/gcube/portlets/user/td/gwtservice/server/trservice/ExtractReferences.java @@ -0,0 +1,52 @@ +package org.gcube.portlets.user.td.gwtservice.server.trservice; + +import java.util.Map; + +import org.gcube.data.analysis.tabulardata.commons.webservice.types.operations.OperationExecution; +import org.gcube.data.analysis.tabulardata.model.column.ColumnReference; +import org.gcube.portlets.user.td.gwtservice.shared.Constants; +import org.gcube.portlets.user.td.gwtservice.shared.OperationsId; +import org.gcube.portlets.user.td.gwtservice.shared.tr.RefColumn; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * + * @author "Giancarlo Panichi" + * + */ +public class ExtractReferences { + protected static Logger logger = LoggerFactory + .getLogger(ExtractReferences.class); + + public static RefColumn extract(OperationExecution op) { + logger.debug("ExtractReferences OperationExecution: "+op); + RefColumn refColumn = null; + Long opId = op.getOperationId(); + + if (opId.compareTo(OperationsId.ChangeToDimensionColumn.toLong())==0) { + refColumn = retrieveRefColumn(op); + } + + logger.debug("ExtractReferences: " + refColumn); + return refColumn; + + } + + protected static RefColumn retrieveRefColumn(OperationExecution op) { + RefColumn refColumn = null; + Map parameters = op.getParameters(); + ColumnReference columnReference = (ColumnReference) parameters + .get(Constants.PARAMETER_REFERENCE_COLUMN); + logger.debug("Parameter " + Constants.PARAMETER_REFERENCE_COLUMN + ": " + + columnReference); + if (columnReference != null && columnReference.getColumnId() != null + && columnReference.getTableId() != null) { + refColumn = new RefColumn(String.valueOf(columnReference + .getTableId().getValue()), columnReference.getColumnId() + .getValue()); + + } + return refColumn; + } +} diff --git a/src/main/java/org/gcube/portlets/user/td/gwtservice/shared/Constants.java b/src/main/java/org/gcube/portlets/user/td/gwtservice/shared/Constants.java index bce11dd..6101b6c 100644 --- a/src/main/java/org/gcube/portlets/user/td/gwtservice/shared/Constants.java +++ b/src/main/java/org/gcube/portlets/user/td/gwtservice/shared/Constants.java @@ -48,6 +48,7 @@ public class Constants { public static final String NAME_PARAMETER_ID="NAME_PARAMETER_ID"; public static final String PARAMETER_KEY="key"; public static final String PARAMETER_REFERENCE_COLUMN="refColumn"; + public static final String PARAMETER_PERIOD_FORMAT="periodFormat"; public static final String PARAMETER_EXPRESSION="expression"; @@ -55,4 +56,8 @@ public class Constants { public static final String PARAMETER_ROW_ID="rowId"; + public static final String REQUEST_PROPERTIES_REFCOLUMN="RefColumn"; + public static final String REQUEST_PROPERTIES_COLUMNID="ColumnId"; + + } diff --git a/src/main/java/org/gcube/portlets/user/td/gwtservice/server/trservice/OperationsId.java b/src/main/java/org/gcube/portlets/user/td/gwtservice/shared/OperationsId.java similarity index 97% rename from src/main/java/org/gcube/portlets/user/td/gwtservice/server/trservice/OperationsId.java rename to src/main/java/org/gcube/portlets/user/td/gwtservice/shared/OperationsId.java index 9b08230..5b5b6d8 100644 --- a/src/main/java/org/gcube/portlets/user/td/gwtservice/server/trservice/OperationsId.java +++ b/src/main/java/org/gcube/portlets/user/td/gwtservice/shared/OperationsId.java @@ -1,4 +1,4 @@ -package org.gcube.portlets.user.td.gwtservice.server.trservice; +package org.gcube.portlets.user.td.gwtservice.shared; /** @@ -129,6 +129,11 @@ public enum OperationsId { public String toString() { return id; } + + public Long toLong(){ + return Long.valueOf(id); + } + } diff --git a/src/main/java/org/gcube/portlets/user/td/gwtservice/shared/task/InvocationS.java b/src/main/java/org/gcube/portlets/user/td/gwtservice/shared/task/InvocationS.java index 519cac7..4b8f2d9 100644 --- a/src/main/java/org/gcube/portlets/user/td/gwtservice/shared/task/InvocationS.java +++ b/src/main/java/org/gcube/portlets/user/td/gwtservice/shared/task/InvocationS.java @@ -3,6 +3,8 @@ package org.gcube.portlets.user.td.gwtservice.shared.task; import java.io.Serializable; import java.util.Map; +import org.gcube.portlets.user.td.gwtservice.shared.tr.RefColumn; + /** * * @author "Giancarlo Panichi" @@ -16,19 +18,21 @@ public class InvocationS implements Serializable { protected long operationId; protected Long identifier; protected Map parameters; - - public InvocationS(){ - + protected RefColumn refColumn; + + public InvocationS() { + } - - public InvocationS(String columnId,long operationId,Long identifier,Map parameters){ - this.columnId=columnId; - this.operationId=operationId; - this.identifier=identifier; - this.parameters=parameters; + + public InvocationS(String columnId, long operationId, Long identifier, + Map parameters, RefColumn refColumn) { + this.columnId = columnId; + this.operationId = operationId; + this.identifier = identifier; + this.parameters = parameters; + this.refColumn=refColumn; } - - + public String getColumnId() { return columnId; } @@ -60,12 +64,22 @@ public class InvocationS implements Serializable { public void setParameters(Map parameters) { this.parameters = parameters; } + + public RefColumn getRefColumn() { + return refColumn; + } + + public void setRefColumn(RefColumn refColumn) { + this.refColumn = refColumn; + } @Override public String toString() { return "InvocationS [columnId=" + columnId + ", operationId=" + operationId + ", identifier=" + identifier + ", parameters=" - + parameters + "]"; + + parameters + ", refColumn=" + refColumn + "]"; } + + } diff --git a/src/main/java/org/gcube/portlets/user/td/gwtservice/shared/tr/RefColumn.java b/src/main/java/org/gcube/portlets/user/td/gwtservice/shared/tr/RefColumn.java new file mode 100644 index 0000000..57d34d9 --- /dev/null +++ b/src/main/java/org/gcube/portlets/user/td/gwtservice/shared/tr/RefColumn.java @@ -0,0 +1,47 @@ +package org.gcube.portlets.user.td.gwtservice.shared.tr; + +import java.io.Serializable; + +/** + * + * @author "Giancarlo Panichi" + * + */ +public class RefColumn implements Serializable { + + private static final long serialVersionUID = -5400296839423693397L; + + protected String tableId; + protected String columnId; + + public RefColumn(){ + + } + + public RefColumn(String tableId, String columnId){ + this.tableId=tableId; + this.columnId=columnId; + } + + public String getTableId() { + return tableId; + } + + public void setTableId(String tableId) { + this.tableId = tableId; + } + + public String getColumnId() { + return columnId; + } + + public void setColumnId(String columnId) { + this.columnId = columnId; + } + + @Override + public String toString() { + return "RefColumn [tableId=" + tableId + ", columnId=" + columnId + "]"; + } + +}