From b0cbe6e72b6a276d28dc879dd88ed7a8cbae6b1c Mon Sep 17 00:00:00 2001 From: Giancarlo Panichi Date: Thu, 3 Apr 2014 16:36:35 +0000 Subject: [PATCH] Added Batch Replace git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/portlets/user/tabular-data-gwt-service@94270 82a268e6-3cf1-43bd-a215-b396298e98cf --- .../gwtservice/client/rpc/TDGWTService.java | 120 +++++++------- .../client/rpc/TDGWTServiceAsync.java | 4 + .../td/gwtservice/server/SessionUtil.java | 78 ++++++++- .../gwtservice/server/TDGWTServiceImpl.java | 148 ++++++++++++++++-- .../server/trservice/ExpressionGenerator.java | 107 ++++++++++--- .../server/trservice/QueryService.java | 25 +-- .../td/gwtservice/shared/tr/DimensionRow.java | 51 ++++++ .../shared/tr/batch/Occurences.java | 24 ++- .../tr/batch/ReplaceBatchColumnMonitor.java | 21 +++ .../tr/batch/ReplaceBatchColumnSession.java | 63 ++++++++ .../shared/tr/batch/ReplaceEntry.java | 110 +++++++++++++ 11 files changed, 648 insertions(+), 103 deletions(-) create mode 100644 src/main/java/org/gcube/portlets/user/td/gwtservice/shared/tr/DimensionRow.java create mode 100644 src/main/java/org/gcube/portlets/user/td/gwtservice/shared/tr/batch/ReplaceBatchColumnMonitor.java create mode 100644 src/main/java/org/gcube/portlets/user/td/gwtservice/shared/tr/batch/ReplaceBatchColumnSession.java create mode 100644 src/main/java/org/gcube/portlets/user/td/gwtservice/shared/tr/batch/ReplaceEntry.java 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 beb341b..d6e747d 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 @@ -28,6 +28,8 @@ import org.gcube.portlets.user.td.gwtservice.shared.tr.ColumnData; 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.Occurences; +import org.gcube.portlets.user.td.gwtservice.shared.tr.batch.ReplaceBatchColumnMonitor; +import org.gcube.portlets.user.td.gwtservice.shared.tr.batch.ReplaceBatchColumnSession; import org.gcube.portlets.user.td.gwtservice.shared.tr.clone.CloneTabularResourceSession; import org.gcube.portlets.user.td.gwtservice.shared.tr.column.DeleteColumnMonitor; import org.gcube.portlets.user.td.gwtservice.shared.tr.column.DeleteColumnSession; @@ -53,7 +55,6 @@ 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 com.google.gwt.user.client.rpc.AsyncCallback; import com.google.gwt.user.client.rpc.RemoteService; import com.google.gwt.user.client.rpc.RemoteServiceRelativePath; @@ -84,7 +85,7 @@ public interface TDGWTService extends RemoteService { * @throws TDGWTServiceException */ public String hello() throws TDGWTServiceException; - + /** * Get informations on the current tabular resource * @@ -99,9 +100,9 @@ public interface TDGWTService extends RemoteService { * @param tabResource * @throws TDGWTServiceException */ - public void setTabResourceInformation(TabResource tabResource) throws TDGWTServiceException; - - + public void setTabResourceInformation(TabResource tabResource) + throws TDGWTServiceException; + /** * Get informations on tabular resource * @@ -175,7 +176,7 @@ public interface TDGWTService extends RemoteService { */ public ArrayList getTRMetadata(TRId trId) throws TDGWTServiceException; - + /** * Return true if is a valid tabular resource * @@ -185,9 +186,8 @@ public interface TDGWTService extends RemoteService { */ public Boolean isTabularResourceValid(TRId trId) throws TDGWTServiceException; - - - //Share + + // Share /** * Retrieves information sharing on the tabular resource * @@ -195,8 +195,8 @@ public interface TDGWTService extends RemoteService { * @return * @throws TDGWTServiceException */ - public ShareInfo getShareInfo(TRId trId) throws TDGWTServiceException; - + public ShareInfo getShareInfo(TRId trId) throws TDGWTServiceException; + /** * Share sabular resource * @@ -204,8 +204,8 @@ public interface TDGWTService extends RemoteService { * @return * @throws TDGWTServiceException */ - public void setShare(ShareInfo shareInfo) throws TDGWTServiceException; - + public void setShare(ShareInfo shareInfo) throws TDGWTServiceException; + // Open /** @@ -216,7 +216,7 @@ public interface TDGWTService extends RemoteService { */ public ArrayList getTabularResources() throws TDGWTServiceException; - + /** * Return all tabular resource of a user and last tables * @@ -226,17 +226,17 @@ public interface TDGWTService extends RemoteService { public ArrayList getTabularResourcesAndLastTables() throws TDGWTServiceException; - //Clone + // Clone /** * Start clone tabular resource * * @param labelColumnSession * @throws TDGWTServiceException */ - public TRId startCloneTabularResource(CloneTabularResourceSession cloneTabularResourceSession) + public TRId startCloneTabularResource( + CloneTabularResourceSession cloneTabularResourceSession) throws TDGWTServiceException; - // /** * Initialize Codelists Paging Loader @@ -281,11 +281,10 @@ public interface TDGWTService extends RemoteService { */ public ArrayList getColumns(TRId trId) throws TDGWTServiceException; - - + /** - * Retrieves the list of columns in the table provided by trId - * only CODE and CODENAME types + * Retrieves the list of columns in the table provided by trId only CODE and + * CODENAME types * * @return * @throws TDGWTServiceException @@ -293,7 +292,6 @@ public interface TDGWTService extends RemoteService { public ArrayList getColumnsForDimension(TRId trId) throws TDGWTServiceException; - /** * Retrieves information about a specific column * @@ -496,9 +494,7 @@ public interface TDGWTService extends RemoteService { ChangeTableTypeSession changeTableTypeSession) throws TDGWTServiceException; - - - //Rows Operations + // Rows Operations /** * Get Operation Monitor during the Delete Rows operation * @@ -515,11 +511,9 @@ public interface TDGWTService extends RemoteService { * @param labelColumnSession * @throws TDGWTServiceException */ - public void startDeleteRows( - DeleteRowsSession deleteRowsSession) + public void startDeleteRows(DeleteRowsSession deleteRowsSession) throws TDGWTServiceException; - /** * Get Operation Monitor during the operation on duplicates * @@ -536,11 +530,9 @@ public interface TDGWTService extends RemoteService { * @param labelColumnSession * @throws TDGWTServiceException */ - public void startDuplicates( - DuplicatesSession duplicatesSession) + public void startDuplicates(DuplicatesSession duplicatesSession) throws TDGWTServiceException; - // Column Operation /** @@ -600,20 +592,38 @@ public interface TDGWTService extends RemoteService { */ public void startLabelColumn(LabelColumnSession labelColumnSession) throws TDGWTServiceException; - - - //BatchReplace Operations + + // BatchReplace Operations /** * Retrieves the values ​​in a column grouped by number of occurrences * - * @param column + * @param column * @return */ public ArrayList getOccurencesForBatchReplace(ColumnData column) - throws TDGWTServiceException; - - - //Replace Operation + throws TDGWTServiceException; + + /** + * Get Operation Monitor during the batch replace on column + * + * + * @return + * @throws TDGWTServiceException + */ + public ReplaceBatchColumnMonitor getReplaceBatchColumnMonitor() + throws TDGWTServiceException; + + /** + * Start batch replace on column + * + * @param replaceBatchColumnSession + * @throws TDGWTServiceException + */ + public void startReplaceBatchColumn( + ReplaceBatchColumnSession replaceBatchColumnSession) + throws TDGWTServiceException; + + // Replace Operation /** * Get Operation Monitor during the replace the Column Value operation * @@ -632,42 +642,40 @@ public interface TDGWTService extends RemoteService { */ public void startReplaceColumn(ReplaceColumnSession replaceColumnSession) throws TDGWTServiceException; - - - - //Templates + + // Templates /** - * Retrieves templates of user + * Retrieves templates of user * * @return */ public ArrayList getTemplates() throws TDGWTServiceException; - + /** * Get Operation Monitor during Apply Template operation * * @param callback */ - - public TemplateApplyMonitor getTemplateApplyMonitor() throws TDGWTServiceException; - + + public TemplateApplyMonitor getTemplateApplyMonitor() + throws TDGWTServiceException; + /** * Start Apply Template * * @param applyTemplateSession - * + * */ - void startTemplateApply(TemplateApplySession templateApplySession) throws TDGWTServiceException; - - + void startTemplateApply(TemplateApplySession templateApplySession) + throws TDGWTServiceException; + /** * Start Delete Template * * @param applyTemplateSession - * + * */ - void startTemplateDelete(TemplateDeleteSession templateDeleteSession) throws TDGWTServiceException; - - + void startTemplateDelete(TemplateDeleteSession templateDeleteSession) + 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 4430358..26b5097 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 @@ -27,6 +27,8 @@ import org.gcube.portlets.user.td.gwtservice.shared.tr.ColumnData; 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.Occurences; +import org.gcube.portlets.user.td.gwtservice.shared.tr.batch.ReplaceBatchColumnMonitor; +import org.gcube.portlets.user.td.gwtservice.shared.tr.batch.ReplaceBatchColumnSession; import org.gcube.portlets.user.td.gwtservice.shared.tr.clone.CloneTabularResourceSession; import org.gcube.portlets.user.td.gwtservice.shared.tr.column.DeleteColumnMonitor; import org.gcube.portlets.user.td.gwtservice.shared.tr.column.DeleteColumnSession; @@ -188,6 +190,8 @@ public interface TDGWTServiceAsync { //BatchReplace Operation void getOccurencesForBatchReplace(ColumnData column, AsyncCallback> callback); + void getReplaceBatchColumnMonitor(AsyncCallback callback); + void startReplaceBatchColumn(ReplaceBatchColumnSession replaceBatchColumnSession,AsyncCallback callback); //Replace Operation void getReplaceColumnMonitor(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 8876d88..56c2449 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 @@ -25,6 +25,8 @@ import org.gcube.portlets.user.td.gwtservice.shared.source.SDMXRegistrySource; import org.gcube.portlets.user.td.gwtservice.shared.template.TemplateApplyMonitor; import org.gcube.portlets.user.td.gwtservice.shared.template.TemplateApplySession; import org.gcube.portlets.user.td.gwtservice.shared.tr.TabResource; +import org.gcube.portlets.user.td.gwtservice.shared.tr.batch.ReplaceBatchColumnMonitor; +import org.gcube.portlets.user.td.gwtservice.shared.tr.batch.ReplaceBatchColumnSession; import org.gcube.portlets.user.td.gwtservice.shared.tr.clone.CloneTabularResourceSession; import org.gcube.portlets.user.td.gwtservice.shared.tr.column.DeleteColumnMonitor; import org.gcube.portlets.user.td.gwtservice.shared.tr.column.DeleteColumnSession; @@ -96,7 +98,11 @@ public class SessionUtil { protected static final String REPLACE_COLUMN_SESSION = "REPLACE_COLUMN_SESSION"; protected static final String REPLACE_COLUMN_MONITOR = "REPLACE_COLUMN_MONITOR"; protected static final String REPLACE_COLUMN_TASK = "REPLACE_COLUMN_TASK"; - + + protected static final String REPLACE_BATCH_COLUMN_SESSION = "REPLACE_BATCH_COLUMN_SESSION"; + protected static final String REPLACE_BATCH_COLUMN_MONITOR = "REPLACE_BATCH_COLUMN_MONITOR"; + protected static final String REPLACE_BATCH_COLUMN_TASK = "REPLACE_BATCH_COLUMN_TASK"; + protected static final String CHANGE_THE_COLUMN_LABEL_SESSION = "CHANGE_THE_COLUMN_LABEL_SESSION"; protected static final String CHANGE_THE_COLUMN_LABEL_MONITOR = "CHANGE_THE_COLUMN_LABEL_MONITOR"; protected static final String CHANGE_THE_COLUMN_LABEL_TASK = "CHANGE_THE_COLUMN_LABEL_TASK"; @@ -803,7 +809,7 @@ public class SessionUtil { } public static void setReplaceColumnMonitor(HttpSession httpSession, - DeleteColumnMonitor replaceColumnMonitor) { + ReplaceColumnMonitor replaceColumnMonitor) { ReplaceColumnMonitor rc = (ReplaceColumnMonitor) httpSession .getAttribute(REPLACE_COLUMN_MONITOR); if (rc != null) { @@ -828,6 +834,74 @@ public class SessionUtil { httpSession.setAttribute(REPLACE_COLUMN_TASK, task); } + + // + public static ReplaceBatchColumnSession getReplaceBatchColumnSession( + HttpSession httpSession) { + ReplaceBatchColumnSession replaceBatchColumnSession = (ReplaceBatchColumnSession) httpSession + .getAttribute(REPLACE_BATCH_COLUMN_SESSION); + if (replaceBatchColumnSession != null) { + return replaceBatchColumnSession; + } else { + replaceBatchColumnSession = new ReplaceBatchColumnSession(); + httpSession.setAttribute(REPLACE_BATCH_COLUMN_SESSION, + replaceBatchColumnSession); + return replaceBatchColumnSession; + } + } + + public static void setReplaceBatchColumnSession(HttpSession httpSession, + ReplaceBatchColumnSession replaceBatchColumnSession) { + ReplaceBatchColumnSession rbc = (ReplaceBatchColumnSession) httpSession + .getAttribute(REPLACE_BATCH_COLUMN_SESSION); + if (rbc != null) { + httpSession.removeAttribute(REPLACE_BATCH_COLUMN_SESSION); + } + httpSession.setAttribute(REPLACE_BATCH_COLUMN_SESSION, replaceBatchColumnSession); + + } + + public static ReplaceBatchColumnMonitor getReplaceBatchColumnMonitor( + HttpSession httpSession) { + ReplaceBatchColumnMonitor replaceBatchColumnMonitor = (ReplaceBatchColumnMonitor) httpSession + .getAttribute(REPLACE_BATCH_COLUMN_MONITOR); + if (replaceBatchColumnMonitor != null) { + return replaceBatchColumnMonitor; + } else { + replaceBatchColumnMonitor = new ReplaceBatchColumnMonitor(); + httpSession.setAttribute(REPLACE_BATCH_COLUMN_MONITOR, + replaceBatchColumnMonitor); + return replaceBatchColumnMonitor; + } + } + + public static void setReplaceBatchColumnMonitor(HttpSession httpSession, + ReplaceBatchColumnMonitor replaceBatchColumnMonitor) { + ReplaceBatchColumnMonitor rbc = (ReplaceBatchColumnMonitor) httpSession + .getAttribute(REPLACE_BATCH_COLUMN_MONITOR); + if (rbc != null) { + httpSession.removeAttribute(REPLACE_BATCH_COLUMN_MONITOR); + } + httpSession.setAttribute(REPLACE_BATCH_COLUMN_MONITOR, replaceBatchColumnMonitor); + + } + + public static Task getReplaceBatchColumnTask(HttpSession httpSession) { + Task monitor = (Task) httpSession.getAttribute(REPLACE_BATCH_COLUMN_TASK); + if (monitor == null) { + logger.error("REPLACE_BATCH_COLUMN_TASK was not acquired"); + } + return monitor; + } + + public static void setReplaceBatchColumnTask(HttpSession httpSession, Task task) { + Task monitor = (Task) httpSession.getAttribute(REPLACE_BATCH_COLUMN_TASK); + if (monitor != null) + httpSession.removeAttribute(REPLACE_BATCH_COLUMN_TASK); + httpSession.setAttribute(REPLACE_BATCH_COLUMN_TASK, task); + } + + // public static ChangeTableTypeSession getChangeTableTypeSession( 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 c191202..4f1b8f2 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 @@ -120,6 +120,9 @@ import org.gcube.portlets.user.td.gwtservice.shared.tr.ColumnViewData; 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.Occurences; +import org.gcube.portlets.user.td.gwtservice.shared.tr.batch.ReplaceBatchColumnMonitor; +import org.gcube.portlets.user.td.gwtservice.shared.tr.batch.ReplaceBatchColumnSession; +import org.gcube.portlets.user.td.gwtservice.shared.tr.batch.ReplaceEntry; import org.gcube.portlets.user.td.gwtservice.shared.tr.clone.CloneTabularResourceSession; import org.gcube.portlets.user.td.gwtservice.shared.tr.column.DeleteColumnMonitor; import org.gcube.portlets.user.td.gwtservice.shared.tr.column.DeleteColumnSession; @@ -295,7 +298,7 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements updateTabResourceInformation(currentTR, trMetadatas); currentTR.setDate(getTRCreationDate(trId)); currentTR.setValid(isTabularResourceValid(trId)); - + logger.debug("GetTabResourceInformation() updated information:" + currentTR.toString()); return currentTR; @@ -1120,8 +1123,8 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements TabResource t = retrieveTRMetadataFromService(service, tr, i); if (t.getTrId() != null && t.isValid()) { - ltr.add(t); - + ltr.add(t); + } } catch (Throwable e) { logger.error("TabResource discarded: " + tr + " cause: " @@ -1590,8 +1593,9 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements logger.error( "Error deleting the tabular resource: " + e.getLocalizedMessage(), e); - throw new TDGWTServiceException("Error deleting the tabular resource: " - + e.getLocalizedMessage()); + throw new TDGWTServiceException( + "Error deleting the tabular resource: " + + e.getLocalizedMessage()); } } @@ -2443,15 +2447,15 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements + e.getLocalizedMessage()); } } - - + /** * * @param trId * @return * @throws TDGWTServiceException */ - public Boolean isTabularResourceValid(TRId trId) throws TDGWTServiceException { + public Boolean isTabularResourceValid(TRId trId) + throws TDGWTServiceException { try { HttpSession session = this.getThreadLocalRequest().getSession(); ASLSession aslSession = SessionUtil.getAslSession(session); @@ -2469,11 +2473,11 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements return tr.isValid(); } catch (Throwable e) { - logger.error( - "Error checking if it is a valid tabular resource: " + e.getLocalizedMessage(), - e); - throw new TDGWTServiceException("Error checking if it is a valid tabular resource: " - + e.getLocalizedMessage()); + logger.error("Error checking if it is a valid tabular resource: " + + e.getLocalizedMessage(), e); + throw new TDGWTServiceException( + "Error checking if it is a valid tabular resource: " + + e.getLocalizedMessage()); } } @@ -3326,6 +3330,74 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements return invocation; } + /** + * Retrieve OperationExecution for change column type + * + * @param replaceColumnSession + * @return + */ + protected List retrieveOperationExecution( + TabularDataService service, + ReplaceBatchColumnSession replaceBatchColumnSession) + throws TDGWTServiceException { + + ArrayList invocations = new ArrayList(); + for (ReplaceEntry re : replaceBatchColumnSession.getReplaceEntryList()) { + + OperationExecution invocation = null; + List capabilities = service.getCapabilities(); + + logger.debug(replaceBatchColumnSession.toString()); + OperationDefinition operationDefinition; + Map map = new HashMap(); + + if (replaceBatchColumnSession.isReplaceDimension()) { + logger.debug("Is a Replace of view column"); + operationDefinition = OperationDefinitionMap.map( + OperationsId.ReplaceColumnByExpression.toString(), + capabilities); + + Expression condition = ExpressionGenerator + .genReplaceValueParameterCondition(replaceBatchColumnSession,re); + Expression value = ExpressionGenerator + .genReplaceBatchValueParameterValue(replaceBatchColumnSession,re); + + map.put(Constants.PARAMETER_REPLACE_BY_EXPRESSION_COLUMN_CONDITION, + condition); + map.put(Constants.PARAMETER_REPLACE_BY_EXPRESSION_COLUMN_VALUE, + value); + + invocation = new OperationExecution(replaceBatchColumnSession + .getColumnData().getColumnViewData() + .getSourceTableDimensionColumnId(), + operationDefinition.getOperationId(), map); + + } else { + logger.debug("Is a Replace of basic column"); + + operationDefinition = OperationDefinitionMap.map( + OperationsId.ReplaceColumnByExpression.toString(), + capabilities); + + Expression condition = ExpressionGenerator + .genReplaceValueParameterCondition(replaceBatchColumnSession,re); + Expression value = ExpressionGenerator + .genReplaceBatchValueParameterValue(replaceBatchColumnSession,re); + + map.put(Constants.PARAMETER_REPLACE_BY_EXPRESSION_COLUMN_CONDITION, + condition); + map.put(Constants.PARAMETER_REPLACE_BY_EXPRESSION_COLUMN_VALUE, + value); + + invocation = new OperationExecution(replaceBatchColumnSession + .getColumnData().getColumnId(), + operationDefinition.getOperationId(), map); + } + invocations.add(invocation); + } + return invocations; + } + /** * * @param service @@ -5051,4 +5123,54 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements } + /** + * + * {@inheritDoc} + */ + @Override + public void startReplaceBatchColumn( + ReplaceBatchColumnSession replaceBatchColumnSession) + throws TDGWTServiceException { + try { + HttpSession session = this.getThreadLocalRequest().getSession(); + SessionUtil.setReplaceBatchColumnSession(session, + replaceBatchColumnSession); + ASLSession aslSession = SessionUtil.getAslSession(session); + + AuthorizationProvider.instance.set(new AuthorizationToken( + aslSession.getUsername())); + TabularDataService service = TabularDataServiceFactory.getService(); + + List invocations = retrieveOperationExecution( + service, replaceBatchColumnSession); + if (invocations == null) { + throw new TDGWTServiceException("Operation not supported"); + } + TabularResourceId serviceTRId = new TabularResourceId( + Long.valueOf(replaceBatchColumnSession.getTrId().getId())); + logger.debug("OperationInvocation: \n" + invocations.toString()); + Task trTask = service.executeBatch(invocations, serviceTRId); + logger.debug("Start Task on service: TaskId " + trTask.getId()); + SessionUtil.setReplaceBatchColumnTask(session, trTask); + return; + } catch (Throwable e) { + e.printStackTrace(); + throw new TDGWTServiceException( + "Error in operation for batch replace on column: " + + e.getLocalizedMessage()); + } + + } + + /** + * + * {@inheritDoc} + */ + @Override + public ReplaceBatchColumnMonitor getReplaceBatchColumnMonitor() + throws TDGWTServiceException { + // TODO Auto-generated method stub + return null; + } + } diff --git a/src/main/java/org/gcube/portlets/user/td/gwtservice/server/trservice/ExpressionGenerator.java b/src/main/java/org/gcube/portlets/user/td/gwtservice/server/trservice/ExpressionGenerator.java index 8715ca9..dd4a203 100644 --- a/src/main/java/org/gcube/portlets/user/td/gwtservice/server/trservice/ExpressionGenerator.java +++ b/src/main/java/org/gcube/portlets/user/td/gwtservice/server/trservice/ExpressionGenerator.java @@ -8,27 +8,29 @@ import org.gcube.data.analysis.tabulardata.model.datatype.value.TDInteger; import org.gcube.data.analysis.tabulardata.model.datatype.value.TDTypeValue; import org.gcube.data.analysis.tabulardata.model.table.TableId; import org.gcube.portlets.user.td.gwtservice.shared.exception.TDGWTServiceException; +import org.gcube.portlets.user.td.gwtservice.shared.tr.batch.ReplaceBatchColumnSession; +import org.gcube.portlets.user.td.gwtservice.shared.tr.batch.ReplaceEntry; import org.gcube.portlets.user.td.gwtservice.shared.tr.column.ReplaceColumnSession; /** * - * @author "Giancarlo Panichi" - * g.panichi@isti.cnr.it - * + * @author "Giancarlo Panichi" g.panichi@isti.cnr.it + * */ public class ExpressionGenerator { public static Expression genReplaceValueParameterCondition( - ReplaceColumnSession replaceColumnSession) throws TDGWTServiceException { + ReplaceColumnSession replaceColumnSession) + throws TDGWTServiceException { if (replaceColumnSession.isReplaceDimension()) { // Dimension TableId tableId; - if(replaceColumnSession - .getColumnData().getTrId().isViewTable()){ + if (replaceColumnSession.getColumnData().getTrId().isViewTable()) { tableId = new TableId(Long.valueOf(replaceColumnSession .getColumnData().getTrId().getReferenceTargetTableId())); } else { tableId = new TableId(Long.valueOf(replaceColumnSession - .getColumnData().getTrId().getTableId())); + .getColumnData().getTrId().getTableId())); } ColumnReference cr = new ColumnReference(tableId, new ColumnLocalId(replaceColumnSession.getColumnData() @@ -42,23 +44,23 @@ public class ExpressionGenerator { } else { // Simple TableId tableId; - if(replaceColumnSession - .getColumnData().getTrId().isViewTable()){ - tableId = new TableId(Long.valueOf(replaceColumnSession + if (replaceColumnSession.getColumnData().getTrId().isViewTable()) { + tableId = new TableId(Long.valueOf(replaceColumnSession .getColumnData().getTrId().getReferenceTargetTableId())); - + } else { tableId = new TableId(Long.valueOf(replaceColumnSession .getColumnData().getTrId().getTableId())); - + } ColumnReference cr = new ColumnReference(tableId, new ColumnLocalId(replaceColumnSession.getColumnData() .getColumnId())); - TDTypeValue td=TDTypeValueMap.map(replaceColumnSession.getColumnData() - .getDataTypeName(), replaceColumnSession.getValue()); + TDTypeValue td = TDTypeValueMap.map(replaceColumnSession + .getColumnData().getDataTypeName(), replaceColumnSession + .getValue()); Equals eq = new Equals(cr, td); return eq; @@ -66,14 +68,81 @@ public class ExpressionGenerator { } public static Expression genReplaceValueParameterValue( - ReplaceColumnSession replaceColumnSession) throws TDGWTServiceException { + ReplaceColumnSession replaceColumnSession) + throws TDGWTServiceException { if (replaceColumnSession.isReplaceDimension()) { - TDInteger value = new TDInteger(Integer.parseInt(replaceColumnSession - .getReplaceValue())); + TDInteger value = new TDInteger( + Integer.parseInt(replaceColumnSession.getReplaceValue())); return value; } else { - TDTypeValue td=TDTypeValueMap.map(replaceColumnSession.getColumnData() - .getDataTypeName(), replaceColumnSession.getReplaceValue()); + TDTypeValue td = TDTypeValueMap.map(replaceColumnSession + .getColumnData().getDataTypeName(), replaceColumnSession + .getReplaceValue()); + return td; + } + } + + public static Expression genReplaceValueParameterCondition( + ReplaceBatchColumnSession replaceBatchColumnSession, ReplaceEntry re) + throws TDGWTServiceException { + if (replaceBatchColumnSession.isReplaceDimension()) { + // Dimension + TableId tableId; + if (replaceBatchColumnSession.getColumnData().getTrId() + .isViewTable()) { + tableId = new TableId(Long.valueOf(replaceBatchColumnSession + .getColumnData().getTrId().getReferenceTargetTableId())); + } else { + tableId = new TableId(Long.valueOf(replaceBatchColumnSession + .getColumnData().getTrId().getTableId())); + } + ColumnReference cr = new ColumnReference(tableId, + new ColumnLocalId(replaceBatchColumnSession.getColumnData() + .getColumnViewData() + .getSourceTableDimensionColumnId())); + + Equals eq = new Equals(cr, new TDInteger( + Integer.parseInt(re.getRowId()))); + + return eq; + } else { + // Simple + TableId tableId; + if (replaceBatchColumnSession.getColumnData().getTrId() + .isViewTable()) { + tableId = new TableId(Long.valueOf(replaceBatchColumnSession + .getColumnData().getTrId().getReferenceTargetTableId())); + + } else { + tableId = new TableId(Long.valueOf(replaceBatchColumnSession + .getColumnData().getTrId().getTableId())); + + } + + ColumnReference cr = new ColumnReference(tableId, + new ColumnLocalId(replaceBatchColumnSession.getColumnData() + .getColumnId())); + + TDTypeValue td = TDTypeValueMap.map(replaceBatchColumnSession + .getColumnData().getDataTypeName(), + re.getValue()); + Equals eq = new Equals(cr, td); + + return eq; + } + } + + public static Expression genReplaceBatchValueParameterValue( + ReplaceBatchColumnSession replaceBatchColumnSession, ReplaceEntry re) + throws TDGWTServiceException { + if (replaceBatchColumnSession.isReplaceDimension()) { + TDInteger value = new TDInteger(Integer.parseInt(re + .getReplacementDimensionRow().getRowId())); + return value; + } else { + TDTypeValue td = TDTypeValueMap.map(replaceBatchColumnSession + .getColumnData().getDataTypeName(), + re.getReplacementValue()); return td; } } diff --git a/src/main/java/org/gcube/portlets/user/td/gwtservice/server/trservice/QueryService.java b/src/main/java/org/gcube/portlets/user/td/gwtservice/server/trservice/QueryService.java index 0337bbb..04666a1 100644 --- a/src/main/java/org/gcube/portlets/user/td/gwtservice/server/trservice/QueryService.java +++ b/src/main/java/org/gcube/portlets/user/td/gwtservice/server/trservice/QueryService.java @@ -41,20 +41,20 @@ public class QueryService { TableId tableId = new TableId(new Long(column.getTrId().getTableId())); ColumnLocalId columnId = new ColumnLocalId(column.getColumnId()); - QuerySelect querySelect; QueryGroup queryGroup; if (column.isViewColumn()) { - querySelect = new QuerySelect(Arrays.asList( - new QueryColumn(columnId), new QueryColumn(columnId, - Function.COUNT))); + ColumnLocalId sourceColumnId = new ColumnLocalId(column + .getColumnViewData().getSourceTableDimensionColumnId()); + querySelect = new QuerySelect(Arrays.asList(new QueryColumn( + columnId), new QueryColumn(sourceColumnId), + new QueryColumn(columnId, Function.COUNT))); logger.debug("Occurences querySelect:" + querySelect.toString()); - queryGroup = new QueryGroup(Arrays.asList(columnId)); + queryGroup = new QueryGroup(Arrays.asList(columnId, sourceColumnId)); logger.debug("Occurences queryGroup:" + queryGroup.toString()); } else { - querySelect = new QuerySelect(Arrays.asList( - new QueryColumn(columnId), new QueryColumn(columnId, - Function.COUNT))); + querySelect = new QuerySelect(Arrays.asList(new QueryColumn( + columnId), new QueryColumn(columnId, Function.COUNT))); logger.debug("Occurences querySelect:" + querySelect.toString()); queryGroup = new QueryGroup(Arrays.asList(columnId)); logger.debug("Occurences queryGroup:" + queryGroup.toString()); @@ -113,8 +113,13 @@ public class QueryService { for (i = 0; i < totalRows; i++) { currentRow = rows.getJSONArray(i); - occurence = new Occurences(currentRow.getString(0), - currentRow.getInt(1)); + if (column.isViewColumn()) { + occurence = new Occurences(currentRow.getString(0), + currentRow.getString(1),currentRow.getInt(2)); + } else { + occurence = new Occurences(currentRow.getString(0), + currentRow.getInt(1)); + } occurences.add(occurence); } diff --git a/src/main/java/org/gcube/portlets/user/td/gwtservice/shared/tr/DimensionRow.java b/src/main/java/org/gcube/portlets/user/td/gwtservice/shared/tr/DimensionRow.java new file mode 100644 index 0000000..d7af084 --- /dev/null +++ b/src/main/java/org/gcube/portlets/user/td/gwtservice/shared/tr/DimensionRow.java @@ -0,0 +1,51 @@ +package org.gcube.portlets.user.td.gwtservice.shared.tr; + +import java.io.Serializable; + +/** + * + * @author "Giancarlo Panichi" g.panichi@isti.cnr.it + * + */ +public class DimensionRow implements Serializable { + + private static final long serialVersionUID = -4220185160420435932L; + + + protected String rowId; + protected String value; + + public DimensionRow(){ + + } + + public DimensionRow(String rowId, String value){ + this.rowId=rowId; + this.value=value; + } + + + public String getValue() { + return value; + } + + public void setValue(String value) { + this.value = value; + } + + public String getRowId() { + return rowId; + } + + public void setRowId(String rowId) { + this.rowId = rowId; + } + + @Override + public String toString() { + return "DimensionRow [rowId=" + rowId + ", value=" + value + "]"; + } + + +} diff --git a/src/main/java/org/gcube/portlets/user/td/gwtservice/shared/tr/batch/Occurences.java b/src/main/java/org/gcube/portlets/user/td/gwtservice/shared/tr/batch/Occurences.java index 8c61845..0314992 100644 --- a/src/main/java/org/gcube/portlets/user/td/gwtservice/shared/tr/batch/Occurences.java +++ b/src/main/java/org/gcube/portlets/user/td/gwtservice/shared/tr/batch/Occurences.java @@ -14,14 +14,22 @@ public class Occurences implements Serializable { protected String value; protected int number; + protected String rowId;//For view column, contains the value of the associated dimension column public Occurences(){ } - public Occurences(String value, int numnber){ + public Occurences(String value, int number){ this.value=value; - this.number=numnber; + this.number=number; + this.rowId=null; + } + + public Occurences(String value, String rowId,int number){ + this.value=value; + this.number=number; + this.rowId=rowId; } @@ -41,11 +49,21 @@ public class Occurences implements Serializable { public void setNumber(int number) { this.number = number; } + + public String getRowId() { + return rowId; + } + + public void setRowId(String rowId) { + this.rowId = rowId; + } @Override public String toString() { - return "Occurence [value=" + value + ", number=" + number + "]"; + return "Occurences [value=" + value + ", number=" + number + ", rowId=" + + rowId + "]"; } + diff --git a/src/main/java/org/gcube/portlets/user/td/gwtservice/shared/tr/batch/ReplaceBatchColumnMonitor.java b/src/main/java/org/gcube/portlets/user/td/gwtservice/shared/tr/batch/ReplaceBatchColumnMonitor.java new file mode 100644 index 0000000..4d4a9a0 --- /dev/null +++ b/src/main/java/org/gcube/portlets/user/td/gwtservice/shared/tr/batch/ReplaceBatchColumnMonitor.java @@ -0,0 +1,21 @@ +/** + * + */ +package org.gcube.portlets.user.td.gwtservice.shared.tr.batch; + +import java.io.Serializable; + +import org.gcube.portlets.user.td.gwtservice.shared.OperationMonitor; + +/** + * + * @author "Giancarlo Panichi" + * g.panichi@isti.cnr.it + * + */ +public class ReplaceBatchColumnMonitor extends OperationMonitor implements Serializable { + + + private static final long serialVersionUID = -7694151843138161474L; + +} diff --git a/src/main/java/org/gcube/portlets/user/td/gwtservice/shared/tr/batch/ReplaceBatchColumnSession.java b/src/main/java/org/gcube/portlets/user/td/gwtservice/shared/tr/batch/ReplaceBatchColumnSession.java new file mode 100644 index 0000000..7aed74a --- /dev/null +++ b/src/main/java/org/gcube/portlets/user/td/gwtservice/shared/tr/batch/ReplaceBatchColumnSession.java @@ -0,0 +1,63 @@ +package org.gcube.portlets.user.td.gwtservice.shared.tr.batch; + +import java.io.Serializable; +import java.util.ArrayList; + +import org.gcube.portlets.user.td.gwtservice.shared.tr.ColumnData; +import org.gcube.portlets.user.td.widgetcommonevent.shared.TRId; + +/** + * + * @author "Giancarlo Panichi" g.panichi@isti.cnr.it + * + */ +public class ReplaceBatchColumnSession implements Serializable { + + private static final long serialVersionUID = -1896235499708614266L; + + protected TRId trId; + protected ColumnData columnData; + protected ArrayList replaceEntryList; + protected boolean replaceDimension; + + public TRId getTrId() { + return trId; + } + + public void setTrId(TRId trId) { + this.trId = trId; + } + + public ColumnData getColumnData() { + return columnData; + } + + public void setColumnData(ColumnData columnData) { + this.columnData = columnData; + } + + public ArrayList getReplaceEntryList() { + return replaceEntryList; + } + + public void setReplaceEntryList(ArrayList replaceEntryList) { + this.replaceEntryList = replaceEntryList; + } + + public boolean isReplaceDimension() { + return replaceDimension; + } + + public void setReplaceDimension(boolean replaceDimension) { + this.replaceDimension = replaceDimension; + } + + @Override + public String toString() { + return "ReplaceBatchColumnSession [trId=" + trId + ", columnData=" + + columnData + ", replaceEntryList=" + replaceEntryList + + ", replaceDimension=" + replaceDimension + "]"; + } + +} diff --git a/src/main/java/org/gcube/portlets/user/td/gwtservice/shared/tr/batch/ReplaceEntry.java b/src/main/java/org/gcube/portlets/user/td/gwtservice/shared/tr/batch/ReplaceEntry.java new file mode 100644 index 0000000..4ace38e --- /dev/null +++ b/src/main/java/org/gcube/portlets/user/td/gwtservice/shared/tr/batch/ReplaceEntry.java @@ -0,0 +1,110 @@ +package org.gcube.portlets.user.td.gwtservice.shared.tr.batch; + +import java.io.Serializable; + +import org.gcube.portlets.user.td.gwtservice.shared.tr.DimensionRow; + + + +public class ReplaceEntry implements Serializable { + + private static final long serialVersionUID = 1630393311734647924L; + + protected String value; + protected String rowId;//For view column, contains the value of the associated dimension column + protected Integer number; + protected String replacementValue; + protected DimensionRow replacementDimensionRow; + + public ReplaceEntry(){ + + } + + /** + * Create a ReplaceEntry for normal column type + * + * @param value + * @param number + * @param replacementValue + * @param replacementDimensionRow + */ + public ReplaceEntry(String value, Integer number, String replacementValue, DimensionRow replacementDimensionRow) { + this.value = value; + this.rowId = null; + this.number = number; + this.replacementValue = replacementValue; + this.replacementDimensionRow = replacementDimensionRow; + } + + /** + * Create a ReplaceEntry for view column type + * + * @param value + * @param number + * @param replacementValue + * @param replacementDimensionRow + */ + public ReplaceEntry(String value, String rowId, Integer number, String replacementValue, DimensionRow replacementDimensionRow) { + this.value = value; + this.rowId = rowId; + this.number = number; + this.replacementValue = replacementValue; + this.replacementDimensionRow = replacementDimensionRow; + } + + public String getValue() { + return value; + } + + public void setValue(String value) { + this.value = value; + } + + public Integer getNumber() { + return number; + } + + public void setNumber(Integer number) { + this.number = number; + } + + public String getReplacementValue() { + return replacementValue; + } + + public void setReplacementValue(String replacementValue) { + this.replacementValue = replacementValue; + } + + public DimensionRow getReplacementDimensionRow() { + return replacementDimensionRow; + } + + public void setReplacementDimensionRow(DimensionRow replacementDimensionRow) { + this.replacementDimensionRow = replacementDimensionRow; + } + + public String getRowId() { + return rowId; + } + + public void setRowId(String rowId) { + this.rowId = rowId; + } + + @Override + public String toString() { + return "ReplaceEntry [value=" + value + ", rowId=" + rowId + + ", number=" + number + ", replacementValue=" + + replacementValue + ", replacementDimensionRow=" + + replacementDimensionRow + "]"; + } + + + + + + + +} +