From affb2cfd294dc44af0bc15133ccf3cc529d4b026 Mon Sep 17 00:00:00 2001 From: Giancarlo Panichi Date: Wed, 2 Jul 2014 15:31:01 +0000 Subject: [PATCH] Updated Replace Bach with ConditionCode on Validation git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/portlets/user/tabular-data-gwt-service@98308 82a268e6-3cf1-43bd-a215-b396298e98cf --- .../gwtservice/client/rpc/TDGWTService.java | 66 ++++--- .../client/rpc/TDGWTServiceAsync.java | 6 + .../gwtservice/server/SessionConstants.java | 7 + .../td/gwtservice/server/SessionUtil.java | 74 +++++++- .../gwtservice/server/TDGWTServiceImpl.java | 178 +++++++++++++++++- .../OpExecution4CodelistMapping.java | 2 +- .../OpExecution4Normalization.java | 81 ++++++++ .../server/trservice/ExpressionGenerator.java | 80 +++++--- .../server/trservice/QueryService.java | 2 +- .../user/td/gwtservice/shared/Constants.java | 4 + .../td/gwtservice/shared/OperationsId.java | 5 + .../gwtservice/shared/task/InvocationS.java | 1 - .../gwtservice/shared/tr/ConditionCode.java | 53 ++++++ .../shared/tr/ConditionCodeMap.java | 28 +++ ...currencesForReplaceBatchColumnSession.java | 34 +++- .../normalization/NormalizationMonitor.java | 18 ++ .../normalization/NormalizationSession.java | 92 +++++++++ .../shared/tr/table/Validations.java | 59 +++++- 18 files changed, 707 insertions(+), 83 deletions(-) create mode 100644 src/main/java/org/gcube/portlets/user/td/gwtservice/server/opexecution/OpExecution4Normalization.java create mode 100644 src/main/java/org/gcube/portlets/user/td/gwtservice/shared/tr/ConditionCode.java create mode 100644 src/main/java/org/gcube/portlets/user/td/gwtservice/shared/tr/ConditionCodeMap.java create mode 100644 src/main/java/org/gcube/portlets/user/td/gwtservice/shared/tr/normalization/NormalizationMonitor.java create mode 100644 src/main/java/org/gcube/portlets/user/td/gwtservice/shared/tr/normalization/NormalizationSession.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 f584b94..0702fd3 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 @@ -59,6 +59,8 @@ import org.gcube.portlets.user.td.gwtservice.shared.tr.column.type.ChangeColumnT import org.gcube.portlets.user.td.gwtservice.shared.tr.column.type.ChangeColumnTypeSession; import org.gcube.portlets.user.td.gwtservice.shared.tr.groupby.GroupByMonitor; import org.gcube.portlets.user.td.gwtservice.shared.tr.metadata.TRMetadata; +import org.gcube.portlets.user.td.gwtservice.shared.tr.normalization.NormalizationMonitor; +import org.gcube.portlets.user.td.gwtservice.shared.tr.normalization.NormalizationSession; import org.gcube.portlets.user.td.gwtservice.shared.tr.open.TDOpenSession; import org.gcube.portlets.user.td.gwtservice.shared.tr.paging.CodelistPagingLoadConfig; import org.gcube.portlets.user.td.gwtservice.shared.tr.paging.CodelistPagingLoadResult; @@ -776,28 +778,27 @@ public interface TDGWTService extends RemoteService { */ public void startLabelColumn(LabelColumnSession labelColumnSession) throws TDGWTServiceException; - + /** * Get Operation Monitor during the Split Column operation * * * @return * @throws TDGWTServiceException - */ + */ public SplitColumnMonitor getSplitColumnMonitor() throws TDGWTServiceException; - + /** * Start split column * * @param splitColumnSession * @throws TDGWTServiceException - - public void startSplitColumn(SplitColumnSession splitColumnSession) - throws TDGWTServiceException; - */ - - + * + * public void startSplitColumn(SplitColumnSession + * splitColumnSession) throws TDGWTServiceException; + */ + /** * Get Operation Monitor during the Merge Column operation * @@ -813,32 +814,30 @@ public interface TDGWTService extends RemoteService { * * @param splitColumnSession * @throws TDGWTServiceException - - public void startMergeColumn(MergeColumnSession mergeColumnSession) - throws TDGWTServiceException; - */ - - + * + * public void startMergeColumn(MergeColumnSession + * mergeColumnSession) throws TDGWTServiceException; + */ + /** * Get Operation Monitor during the Group By operation * * * @return * @throws TDGWTServiceException - */ - public GroupByMonitor getGroupByMonitor() - throws TDGWTServiceException; - + */ + public GroupByMonitor getGroupByMonitor() throws TDGWTServiceException; + /** * Start group by * * @param groupBySession * @throws TDGWTServiceException - - public void startGroupBy(GroupBySession groupBySession) - throws TDGWTServiceException; - */ - + * + * public void startGroupBy(GroupBySession groupBySession) + * throws TDGWTServiceException; + */ + // BatchReplace Operations /** * Retrieves the values ​​in a column grouped by number of occurrences @@ -1007,4 +1006,23 @@ public interface TDGWTService extends RemoteService { CodelistMappingSession codelistMappingSession) throws TDGWTServiceException; + // Normalization + /** + * Get Operation Monitor during the Normalization operation + * + * @return + * @throws TDGWTServiceException + */ + public NormalizationMonitor getNormalizationMonitor() + throws TDGWTServiceException; + + /** + * Start Normalization and invokes the client library + * + * @param normalizationSession + * @throws TDGWTServiceException + */ + public void startNormalization(NormalizationSession normalizationSession) + 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 c56d307..801ccdf 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 @@ -58,6 +58,8 @@ import org.gcube.portlets.user.td.gwtservice.shared.tr.column.type.ChangeColumnT import org.gcube.portlets.user.td.gwtservice.shared.tr.column.type.ChangeColumnTypeSession; import org.gcube.portlets.user.td.gwtservice.shared.tr.groupby.GroupByMonitor; import org.gcube.portlets.user.td.gwtservice.shared.tr.metadata.TRMetadata; +import org.gcube.portlets.user.td.gwtservice.shared.tr.normalization.NormalizationMonitor; +import org.gcube.portlets.user.td.gwtservice.shared.tr.normalization.NormalizationSession; import org.gcube.portlets.user.td.gwtservice.shared.tr.open.TDOpenSession; import org.gcube.portlets.user.td.gwtservice.shared.tr.paging.CodelistPagingLoadConfig; import org.gcube.portlets.user.td.gwtservice.shared.tr.paging.CodelistPagingLoadResult; @@ -261,6 +263,10 @@ public interface TDGWTServiceAsync { void setCodelistMappingSession(CodelistMappingSession codelistMappingSession, AsyncCallback callback); void getFileFromWorkspace(CodelistMappingSession codelistMappingSession, AsyncCallback callback); void startCodelistMappingImport(CodelistMappingSession codelistMappingSession, AsyncCallback callback); + + //Normalization + void getNormalizationMonitor(AsyncCallback callback); + void startNormalization(NormalizationSession normalizationSession, AsyncCallback callback); } diff --git a/src/main/java/org/gcube/portlets/user/td/gwtservice/server/SessionConstants.java b/src/main/java/org/gcube/portlets/user/td/gwtservice/server/SessionConstants.java index b98a677..9d031ac 100644 --- a/src/main/java/org/gcube/portlets/user/td/gwtservice/server/SessionConstants.java +++ b/src/main/java/org/gcube/portlets/user/td/gwtservice/server/SessionConstants.java @@ -62,6 +62,13 @@ public class SessionConstants { protected static final String GROUPBY_MONITOR = "GROUPBY_MONITOR"; protected static final String GROUPBY_TASK = "GROUPBY_TASK"; + protected static final String NORMALIZATION_SESSION = "NORMALIZATION_SESSION"; + protected static final String NORMALIZATION_MONITOR = "NORMALIZATION_MONITOR"; + protected static final String NORMALIZATION_TASK = "NORMALIZATION_TASK"; + + protected static final String DENORMALIZATION_SESSION = "DENORMALIZATION_SESSION"; + protected static final String DENORMALIZATION_MONITOR = "DENORMALIZATION_MONITOR"; + protected static final String DENORMALIZATION_TASK = "DENORMALIZATION_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"; 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 d9f9045..e0f8999 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 @@ -56,6 +56,8 @@ import org.gcube.portlets.user.td.gwtservice.shared.tr.column.type.ChangeColumnT import org.gcube.portlets.user.td.gwtservice.shared.tr.column.type.ChangeColumnTypeSession; import org.gcube.portlets.user.td.gwtservice.shared.tr.groupby.GroupByMonitor; import org.gcube.portlets.user.td.gwtservice.shared.tr.groupby.GroupBySession; +import org.gcube.portlets.user.td.gwtservice.shared.tr.normalization.NormalizationMonitor; +import org.gcube.portlets.user.td.gwtservice.shared.tr.normalization.NormalizationSession; import org.gcube.portlets.user.td.gwtservice.shared.tr.open.TDOpenSession; import org.gcube.portlets.user.td.gwtservice.shared.tr.rows.DeleteRowsMonitor; import org.gcube.portlets.user.td.gwtservice.shared.tr.rows.DeleteRowsSession; @@ -329,10 +331,7 @@ public class SessionUtil { return fileUploadSession; } - - - - //TODO + public static void setCodelistMappingFileUploadSession(HttpSession httpSession, CodelistMappingFileUploadSession s) throws TDGWTSessionExpiredException { @@ -1931,6 +1930,71 @@ public class SessionUtil { httpSession.setAttribute(SessionConstants.CODELIST_MAPPING_TASK, task); } - + // + public static NormalizationSession getNormalizationSession( + HttpSession httpSession) { + NormalizationSession normalizationSession = (NormalizationSession) httpSession + .getAttribute(SessionConstants.NORMALIZATION_SESSION); + if (normalizationSession != null) { + return normalizationSession; + } else { + normalizationSession = new NormalizationSession(); + httpSession + .setAttribute(SessionConstants.NORMALIZATION_SESSION, normalizationSession); + return normalizationSession; + } + } + + public static void setNormalizationSession(HttpSession httpSession, + NormalizationSession normalizationSession) { + NormalizationSession gb = (NormalizationSession) httpSession + .getAttribute(SessionConstants.NORMALIZATION_SESSION); + if (gb != null) { + httpSession.removeAttribute(SessionConstants.NORMALIZATION_SESSION); + } + httpSession.setAttribute(SessionConstants.NORMALIZATION_SESSION, normalizationSession); + + } + + public static NormalizationMonitor getNormalizationMonitor( + HttpSession httpSession) { + NormalizationMonitor normalizationMonitor = (NormalizationMonitor) httpSession + .getAttribute(SessionConstants.NORMALIZATION_MONITOR); + if (normalizationMonitor != null) { + return normalizationMonitor; + } else { + normalizationMonitor = new NormalizationMonitor(); + httpSession + .setAttribute(SessionConstants.NORMALIZATION_MONITOR, normalizationMonitor); + return normalizationMonitor; + } + } + + public static void setNormalizationMonitor(HttpSession httpSession, + NormalizationMonitor normalizationMonitor) { + NormalizationMonitor nm = (NormalizationMonitor) httpSession + .getAttribute(SessionConstants.NORMALIZATION_MONITOR); + if (nm != null) { + httpSession.removeAttribute(SessionConstants.NORMALIZATION_MONITOR); + } + httpSession.setAttribute(SessionConstants.NORMALIZATION_MONITOR, normalizationMonitor); + + } + + public static Task getNormalizationTask(HttpSession httpSession) { + Task monitor = (Task) httpSession.getAttribute(SessionConstants.NORMALIZATION_TASK); + if (monitor == null) { + logger.error("NORMALIZATION_TASK was not acquired"); + } + return monitor; + } + + public static void setNormalizationTask(HttpSession httpSession, Task task) { + Task monitor = (Task) httpSession.getAttribute(SessionConstants.NORMALIZATION_TASK); + if (monitor != null) + httpSession.removeAttribute(SessionConstants.NORMALIZATION_TASK); + httpSession.setAttribute(SessionConstants.NORMALIZATION_TASK, task); + } + } 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 2fbb18f..7b0352f 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 @@ -108,6 +108,7 @@ import org.gcube.portlets.user.td.gwtservice.server.opexecution.OpExecution4Extr import org.gcube.portlets.user.td.gwtservice.server.opexecution.OpExecution4GroupBy; import org.gcube.portlets.user.td.gwtservice.server.opexecution.OpExecution4LabelColumn; import org.gcube.portlets.user.td.gwtservice.server.opexecution.OpExecution4MergeColumn; +import org.gcube.portlets.user.td.gwtservice.server.opexecution.OpExecution4Normalization; import org.gcube.portlets.user.td.gwtservice.server.opexecution.OpExecution4ReplaceBatch; import org.gcube.portlets.user.td.gwtservice.server.opexecution.OpExecution4ReplaceColumn; import org.gcube.portlets.user.td.gwtservice.server.opexecution.OpExecution4SplitColumn; @@ -162,6 +163,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.ConditionCodeMap; 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; @@ -192,6 +194,8 @@ import org.gcube.portlets.user.td.gwtservice.shared.tr.metadata.TRLocalizedText; import org.gcube.portlets.user.td.gwtservice.shared.tr.metadata.TRMetadata; import org.gcube.portlets.user.td.gwtservice.shared.tr.metadata.TRNameMetadata; import org.gcube.portlets.user.td.gwtservice.shared.tr.metadata.TRRightsMetadata; +import org.gcube.portlets.user.td.gwtservice.shared.tr.normalization.NormalizationMonitor; +import org.gcube.portlets.user.td.gwtservice.shared.tr.normalization.NormalizationSession; import org.gcube.portlets.user.td.gwtservice.shared.tr.open.TDOpenSession; import org.gcube.portlets.user.td.gwtservice.shared.tr.paging.CodelistPagingLoadConfig; import org.gcube.portlets.user.td.gwtservice.shared.tr.paging.CodelistPagingLoadResult; @@ -3150,7 +3154,7 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements AuthorizationProvider.instance.set(new AuthorizationToken( aslSession.getUsername(), aslSession.getScope())); TabularDataService service = TabularDataServiceFactory.getService(); - // TODO + TabularResource tr = service .getTabularResource(new TabularResourceId(Long.valueOf(trId .getId()))); @@ -3246,7 +3250,7 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements int i = 0; for (Validation v : vals) { valid = new Validations(String.valueOf(i), - v.getDescription(), v.isValid()); + v.getDescription(), v.isValid(), null, null); vList.add(valid); i++; } @@ -6557,11 +6561,14 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements for (ValidationDescriptor val : job.getValidations()) { Validations validation = new Validations( String.valueOf(i), val.getDescription(), - val.isValid()); + val.isValid(), + ConditionCodeMap.mapConditionCode(val + .getConditionCode()), + val.getValidationColumn()); validations.add(validation); i++; } - // TODO Fix refColumn + InvocationS invocationS = null; if (job.getInvocation() != null) { @@ -6818,7 +6825,7 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements } } - // TODO + @Override public void startTaskResubmit(TaskResubmitSession taskResubmitSession) throws TDGWTServiceException { @@ -6967,7 +6974,7 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements } } - // TODO + @Override public void startTaskResume(TaskResumeSession taskResumeSession) throws TDGWTServiceException { @@ -7115,7 +7122,7 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements } } - // TODO + @Override public void startExtractCodelist( ExtractCodelistSession extractCodelistSession) @@ -7272,7 +7279,7 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements } } - // TODO + //TODO public void startSplitColumn(SplitColumnSession splitColumnSession, HttpSession session) throws TDGWTServiceException { try { @@ -8042,4 +8049,159 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements } } + + + @Override + public void startNormalization(NormalizationSession normalizationSession) + throws TDGWTServiceException { + try { + HttpSession session = this.getThreadLocalRequest().getSession(); + SessionUtil.setNormalizationSession(session, normalizationSession); + ASLSession aslSession = SessionUtil.getAslSession(session); + if (normalizationSession == null) { + logger.error("NormalizationSession is null"); + throw new TDGWTServiceException( + "Error in normalization : NormalizationSession is null"); + } + + logger.debug("StartNormalization: " + normalizationSession); + AuthorizationProvider.instance.set(new AuthorizationToken( + aslSession.getUsername(), aslSession.getScope())); + TabularDataService service = TabularDataServiceFactory.getService(); + + OpExecution4Normalization opEx = new OpExecution4Normalization(service, + normalizationSession); + OpExecutionDirector director = new OpExecutionDirector(); + director.setOperationExecutionBuilder(opEx); + director.constructOperationExecution(); + OperationExecution invocation = director.getOperationExecution(); + + if (invocation == null) { + throw new TDGWTServiceException( + "Error in invocation: Operation not supported"); + } + Long id = Long.valueOf(normalizationSession.getTrId().getId()); + + TabularResourceId serviceTR = new TabularResourceId(id); + logger.debug("OperationInvocation: \n" + invocation.toString()); + Task trTask = service.execute(invocation, serviceTR); + logger.debug("Normalization start on service: TaskId " + trTask.getId()); + SessionUtil.setNormalizationTask(session, trTask); + return; + + } catch (TDGWTSessionExpiredException e) { + throw e; + } catch (SecurityException e) { + e.printStackTrace(); + throw new TDGWTServiceException( + "Security exception, you haven't rights!"); + } catch (Throwable e) { + e.printStackTrace(); + throw new TDGWTServiceException("Error in start normalization: " + + e.getLocalizedMessage()); + } + + } + + + @Override + public NormalizationMonitor getNormalizationMonitor() + throws TDGWTServiceException { + try { + HttpSession session = this.getThreadLocalRequest().getSession(); + NormalizationSession normalizationSession = SessionUtil + .getNormalizationSession(session); + + Task task = SessionUtil.getNormalizationTask(session); + NormalizationMonitor normalizationMonitor = new NormalizationMonitor(); + + if (task == null) { + logger.debug("Task null"); + throw new TDGWTServiceException( + "Error in NormalizationMonitor task null"); + } else { + TaskStatus status = task.getStatus(); + if (status == null) { + logger.debug("Services TaskStatus : null"); + throw new TDGWTServiceException( + "Error in NormalizationMonitor Status null"); + } else { + logger.debug("Services TaskStatus: " + task.getStatus()); + + normalizationMonitor + .setStatus(TaskStateMap.map(task.getStatus())); + + TRId trId; + TabResource tabResource; + switch (normalizationMonitor.getStatus()) { + case FAILED: + if (task.getResult() != null) { + logger.debug("Task exception:" + + task.getErrorCause()); + task.getErrorCause().printStackTrace(); + normalizationMonitor.setError(new Throwable(task + .getErrorCause())); + } else { + logger.debug("Task exception: Error In NormalizationMonitor"); + normalizationMonitor.setError(new Throwable( + "Error task resume")); + } + normalizationMonitor.setProgress(task.getProgress()); + break; + case SUCCEDED: + logger.debug("Task Result:" + task.getResult()); + normalizationMonitor.setProgress(task.getProgress()); + trId = new TRId(); + trId.setId(normalizationSession.getTrId().getId()); + trId = retrieveTabularResourceBasicData(trId); + normalizationMonitor.setTrId(trId); + tabResource = SessionUtil.getTabResource(session); + tabResource.setTrId(trId); + SessionUtil.setTabResource(session, tabResource); + SessionUtil.setTRId(session, trId); + break; + case IN_PROGRESS: + normalizationMonitor.setProgress(task.getProgress()); + break; + case VALIDATING_RULES: + normalizationMonitor.setProgress(task.getProgress()); + break; + case GENERATING_VIEW: + break; + case ABORTED: + break; + case STOPPED: + logger.debug("Task Result:" + task.getResult()); + normalizationMonitor.setProgress(task.getProgress()); + + trId = retrieveTabularResourceBasicData(normalizationSession + .getTrId()); + + normalizationMonitor.setTrId(trId); + tabResource = SessionUtil.getTabResource(session); + tabResource.setTrId(trId); + SessionUtil.setTabResource(session, tabResource); + SessionUtil.setTRId(session, trId); + break; + case INITIALIZING: + break; + default: + break; + } + } + SessionUtil.setNormalizationTask(session, task); + } + + logger.debug("NormalizationMonitor(): " + normalizationMonitor); + return normalizationMonitor; + } catch (TDGWTSessionExpiredException e) { + throw e; + } catch (Throwable e) { + logger.debug("Error in NormalizationMonitor: " + e.getLocalizedMessage()); + e.printStackTrace(); + throw new TDGWTServiceException("Error: " + e.getLocalizedMessage()); + + } + } + } diff --git a/src/main/java/org/gcube/portlets/user/td/gwtservice/server/opexecution/OpExecution4CodelistMapping.java b/src/main/java/org/gcube/portlets/user/td/gwtservice/server/opexecution/OpExecution4CodelistMapping.java index c6d165f..03a1aa0 100644 --- a/src/main/java/org/gcube/portlets/user/td/gwtservice/server/opexecution/OpExecution4CodelistMapping.java +++ b/src/main/java/org/gcube/portlets/user/td/gwtservice/server/opexecution/OpExecution4CodelistMapping.java @@ -58,7 +58,7 @@ public class OpExecution4CodelistMapping extends OpExecutionBuilder { ColumnLocalId columnId=new ColumnLocalId(columnData.getColumnId()); ColumnReference colRef=new ColumnReference(tableId, columnId); - map.put(Constants.PARAMETER_URL, colRef); + map.put(Constants.PARAMETER_IMPORT_CODELIST_MAPPING_OLDCODES, colRef); invocation = new OperationExecution( operationDefinition.getOperationId(), map); diff --git a/src/main/java/org/gcube/portlets/user/td/gwtservice/server/opexecution/OpExecution4Normalization.java b/src/main/java/org/gcube/portlets/user/td/gwtservice/server/opexecution/OpExecution4Normalization.java new file mode 100644 index 0000000..58ba1ad --- /dev/null +++ b/src/main/java/org/gcube/portlets/user/td/gwtservice/server/opexecution/OpExecution4Normalization.java @@ -0,0 +1,81 @@ +package org.gcube.portlets.user.td.gwtservice.server.opexecution; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Map; + +import org.gcube.data.analysis.tabulardata.commons.webservice.types.operations.OperationDefinition; +import org.gcube.data.analysis.tabulardata.commons.webservice.types.operations.OperationExecution; +import org.gcube.data.analysis.tabulardata.model.column.ColumnLocalId; +import org.gcube.data.analysis.tabulardata.model.column.ColumnReference; +import org.gcube.data.analysis.tabulardata.model.table.TableId; +import org.gcube.data.analysis.tabulardata.service.TabularDataService; +import org.gcube.portlets.user.td.gwtservice.server.trservice.OperationDefinitionMap; +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.exception.TDGWTServiceException; +import org.gcube.portlets.user.td.gwtservice.shared.tr.ColumnData; +import org.gcube.portlets.user.td.gwtservice.shared.tr.normalization.NormalizationSession; +import org.gcube.portlets.user.td.widgetcommonevent.shared.TRId; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * Operation Execution for duplicates + * + * @author "Giancarlo Panichi" email: g.panichi@isti.cnr.it + * + */ +public class OpExecution4Normalization extends OpExecutionBuilder { + protected static Logger logger = LoggerFactory + .getLogger(OpExecution4Normalization.class); + + private TabularDataService service; + private NormalizationSession normalizationSession; + + public OpExecution4Normalization(TabularDataService service, + NormalizationSession normalizationSession) { + this.service = service; + this.normalizationSession = normalizationSession; + } + + @Override + public void buildOpEx() throws TDGWTServiceException { + OperationExecution invocation = null; + + logger.debug(normalizationSession.toString()); + OperationDefinition operationDefinition; + Map map = new HashMap(); + + ArrayList cols = normalizationSession.getColumns(); + logger.debug("Column To Set: " + cols); + ArrayList columnReferences = new ArrayList(); + + for (ColumnData col : cols) { + ColumnLocalId cId = new ColumnLocalId(col.getColumnId()); + TRId trId = col.getTrId(); + logger.debug("trID: " + trId); + long tabId = new Long(trId.getTableId()); + TableId tId = new TableId(tabId); + ColumnReference columnReference = new ColumnReference(tId, cId); + columnReferences.add(columnReference); + } + + //String name=normalizationSession.getNormalizedColumnName(); + //String value=normalizationSession.getValueColumnName(); + + operationDefinition = OperationDefinitionMap.map( + OperationsId.Normalize.toString(), service); + + map.put(Constants.PARAMETER_KEY, columnReferences); + + + invocation = new OperationExecution( + operationDefinition.getOperationId(), map); + + operationExecutionSpec.setOp(invocation); + + } + +} 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 f04791c..77e2d4d 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 @@ -18,6 +18,7 @@ import org.gcube.data.analysis.tabulardata.model.table.TableId; import org.gcube.data.analysis.tabulardata.service.TabularDataService; import org.gcube.portlets.user.td.gwtservice.shared.exception.TDGWTServiceException; import org.gcube.portlets.user.td.gwtservice.shared.tr.ColumnData; +import org.gcube.portlets.user.td.gwtservice.shared.tr.batch.OccurrencesForReplaceBatchColumnSession; 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; @@ -211,31 +212,45 @@ public class ExpressionGenerator { } - public static Expression genReplaceBatchOccurrencesFilter(ColumnData column) + public static Expression genReplaceBatchOccurrencesFilter( + OccurrencesForReplaceBatchColumnSession occurrencesSession) throws TDGWTServiceException { - try { - ArrayList validationColumnReferences = column - .getValidationColumnReferences(); + + String validationColumnColumnId = occurrencesSession + .getValidationColumnColumnId(); + ColumnData column = occurrencesSession.getColumnData(); TableId tableId = new TableId(Long.valueOf(column.getTrId() .getTableId())); - ArrayList listColumnReference = new ArrayList(); - for (String columnLocalId : validationColumnReferences) { - ColumnReference cr = new ColumnReference(tableId, - new ColumnLocalId(columnLocalId)); - listColumnReference.add(cr); - } - if (listColumnReference.size() <= 0) { - return null; - } else { - if (listColumnReference.size() == 1) { - Not not = new Not(listColumnReference.get(0)); - return not; - } else { - And and = new And(listColumnReference); - Not not = new Not(and); - return not; + + if (validationColumnColumnId == null + || validationColumnColumnId.isEmpty()) { + ArrayList validationColumnReferences = column + .getValidationColumnReferences(); + ArrayList listColumnReference = new ArrayList(); + for (String columnLocalId : validationColumnReferences) { + ColumnReference cr = new ColumnReference(tableId, + new ColumnLocalId(columnLocalId)); + listColumnReference.add(cr); } + if (listColumnReference.size() <= 0) { + return null; + } else { + if (listColumnReference.size() == 1) { + Not not = new Not(listColumnReference.get(0)); + return not; + } else { + And and = new And(listColumnReference); + Not not = new Not(and); + return not; + } + } + + } else { + ColumnReference cr = new ColumnReference(tableId, + new ColumnLocalId(validationColumnColumnId)); + Not not = new Not(cr); + return not; } } catch (Throwable e) { @@ -249,10 +264,11 @@ public class ExpressionGenerator { } - public static Expression genEditRowParamaterCondition(TabularDataService service, - EditRowSession editRowSession) throws TDGWTServiceException { + public static Expression genEditRowParamaterCondition( + TabularDataService service, EditRowSession editRowSession) + throws TDGWTServiceException { try { - Expression exp=null; + Expression exp = null; TRId trId = editRowSession.getTrId(); TableId tableId; if (trId.isViewTable()) { @@ -261,7 +277,7 @@ public class ExpressionGenerator { } else { tableId = new TableId(new Long(trId.getTableId())); } - + Table table = service.getTable(new TableId(Long.valueOf(trId .getTableId()))); @@ -280,18 +296,22 @@ public class ExpressionGenerator { exp = new Equals(cr, new TDInteger( Integer.parseInt(editRowSession.getRowId()))); - + } else { - logger.debug("No IdColumnType retrieved for table:"+table.getId().toString()); + logger.debug("No IdColumnType retrieved for table:" + + table.getId().toString()); } - logger.debug("genEditRowParamaterCondition() condition:"+exp); + logger.debug("genEditRowParamaterCondition() condition:" + exp); return exp; } catch (Throwable e) { - logger.error("Error in genEditRowParamaterCondition(): "+e.getLocalizedMessage()); + logger.error("Error in genEditRowParamaterCondition(): " + + e.getLocalizedMessage()); e.printStackTrace(); - throw new TDGWTServiceException("Error in genEditRowParamaterCondition(): "+e.getLocalizedMessage()); + throw new TDGWTServiceException( + "Error in genEditRowParamaterCondition(): " + + e.getLocalizedMessage()); } - + } } 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 2f1335b..093a910 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 @@ -89,7 +89,7 @@ public class QueryService { ShowOccurrencesType.ONLYERRORS) == 0) { if (occurrencesSession.isHasValidationColumns()) { Expression exp=ExpressionGenerator - .genReplaceBatchOccurrencesFilter(column); + .genReplaceBatchOccurrencesFilter(occurrencesSession); logger.debug("Expression: "+exp); if(exp!=null){ queryFilter = new QueryFilter( 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 d72dfef..a17f551 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 @@ -3,6 +3,7 @@ */ package org.gcube.portlets.user.td.gwtservice.shared; + /** * * @author "Giancarlo Panichi" g.panichi@isti.cnr.it + * + */ +public enum ConditionCode { + GenericValidity(0), + OnlyOneCodeColumn(1), + OnlyOneCodenameColumn(2), + MaxOneCodenameForDataLocale(3), + AllowedColumnType(4), + MustHaveDataLocaleMetadataAndAtLeastOneLabel(5), + MustContainAtLeastOneDimension(6), + MustContainAtLeastOneMeasure(7), + GenericTupleValidity(100), + DuplicateTupleValidation(101), + DuplicateValueInColumn(102), + AmbigousValueOnExternalReference(103), + MissingValueOnExternalReference(104), + CodeNamePresence(105), + CastValidation(106), + ValidPeriodFormat(105); + + + /** + * @param int + */ + private ConditionCode(final int id) { + this.id = id; + } + + private final int id; + + + public int value() { + return id; + } + + @Override + public String toString(){ + return String.valueOf(id); + } + + + + +} + + diff --git a/src/main/java/org/gcube/portlets/user/td/gwtservice/shared/tr/ConditionCodeMap.java b/src/main/java/org/gcube/portlets/user/td/gwtservice/shared/tr/ConditionCodeMap.java new file mode 100644 index 0000000..1b10a3c --- /dev/null +++ b/src/main/java/org/gcube/portlets/user/td/gwtservice/shared/tr/ConditionCodeMap.java @@ -0,0 +1,28 @@ +package org.gcube.portlets.user.td.gwtservice.shared.tr; + + +/** + * + * @author "Giancarlo Panichi" + * email: g.panichi@isti.cnr.it + * + */ +public class ConditionCodeMap { + + /** + * + * @param conditionCode + * @return + */ + public static ConditionCode mapConditionCode(int conditionCode) { + ConditionCode[] conditions=ConditionCode.values(); + for(ConditionCode cond:conditions){ + if(cond.value()==conditionCode){ + return cond; + } + } + + return ConditionCode.GenericValidity; + + } +} diff --git a/src/main/java/org/gcube/portlets/user/td/gwtservice/shared/tr/batch/OccurrencesForReplaceBatchColumnSession.java b/src/main/java/org/gcube/portlets/user/td/gwtservice/shared/tr/batch/OccurrencesForReplaceBatchColumnSession.java index d2ab279..6bcf2a0 100644 --- a/src/main/java/org/gcube/portlets/user/td/gwtservice/shared/tr/batch/OccurrencesForReplaceBatchColumnSession.java +++ b/src/main/java/org/gcube/portlets/user/td/gwtservice/shared/tr/batch/OccurrencesForReplaceBatchColumnSession.java @@ -3,6 +3,7 @@ package org.gcube.portlets.user.td.gwtservice.shared.tr.batch; import java.io.Serializable; import org.gcube.portlets.user.td.gwtservice.shared.tr.ColumnData; +import org.gcube.portlets.user.td.gwtservice.shared.tr.ConditionCode; /** * @@ -13,18 +14,25 @@ import org.gcube.portlets.user.td.gwtservice.shared.tr.ColumnData; public class OccurrencesForReplaceBatchColumnSession implements Serializable { private static final long serialVersionUID = -838394991333185029L; + protected ColumnData columnData; protected ShowOccurrencesType showType; protected boolean hasValidationColumns; + protected ConditionCode conditionCode; + protected String validationColumnColumnId; + public OccurrencesForReplaceBatchColumnSession() { } public OccurrencesForReplaceBatchColumnSession(ColumnData columnData, - ShowOccurrencesType showType, boolean hasValidationColumns) { + ShowOccurrencesType showType, boolean hasValidationColumns, + ConditionCode conditionCode, String validationColumnColumnId) { this.columnData = columnData; this.showType = showType; this.hasValidationColumns = hasValidationColumns; + this.conditionCode=conditionCode; + this.validationColumnColumnId=validationColumnColumnId; } public ColumnData getColumnData() { @@ -50,16 +58,32 @@ public class OccurrencesForReplaceBatchColumnSession implements Serializable { public void setHasValidationColumns(boolean hasValidationColumns) { this.hasValidationColumns = hasValidationColumns; } + + public ConditionCode getConditionCode() { + return conditionCode; + } + + public void setConditionCode(ConditionCode conditionCode) { + this.conditionCode = conditionCode; + } + + public String getValidationColumnColumnId() { + return validationColumnColumnId; + } + + public void setValidationColumnColumnId(String validationColumnColumnId) { + this.validationColumnColumnId = validationColumnColumnId; + } @Override public String toString() { return "OccurrencesForReplaceBatchColumnSession [columnData=" + columnData + ", showType=" + showType - + ", hasValidationColumns=" + hasValidationColumns + "]"; + + ", hasValidationColumns=" + hasValidationColumns + + ", conditionCode=" + conditionCode + + ", validationColumnColumnId=" + validationColumnColumnId + + "]"; } - - - } diff --git a/src/main/java/org/gcube/portlets/user/td/gwtservice/shared/tr/normalization/NormalizationMonitor.java b/src/main/java/org/gcube/portlets/user/td/gwtservice/shared/tr/normalization/NormalizationMonitor.java new file mode 100644 index 0000000..f861af4 --- /dev/null +++ b/src/main/java/org/gcube/portlets/user/td/gwtservice/shared/tr/normalization/NormalizationMonitor.java @@ -0,0 +1,18 @@ +package org.gcube.portlets.user.td.gwtservice.shared.tr.normalization; + +import java.io.Serializable; + +import org.gcube.portlets.user.td.gwtservice.shared.OperationMonitor; + +/** + * + * @author "Giancarlo Panichi" + * email: g.panichi@isti.cnr.it + * + */ +public class NormalizationMonitor extends OperationMonitor implements + Serializable { + + private static final long serialVersionUID = -7021715301225849091L; + +} \ No newline at end of file diff --git a/src/main/java/org/gcube/portlets/user/td/gwtservice/shared/tr/normalization/NormalizationSession.java b/src/main/java/org/gcube/portlets/user/td/gwtservice/shared/tr/normalization/NormalizationSession.java new file mode 100644 index 0000000..a7cdcb1 --- /dev/null +++ b/src/main/java/org/gcube/portlets/user/td/gwtservice/shared/tr/normalization/NormalizationSession.java @@ -0,0 +1,92 @@ +package org.gcube.portlets.user.td.gwtservice.shared.tr.normalization; + +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" + * email: g.panichi@isti.cnr.it + * + */ +public class NormalizationSession implements Serializable { + + private static final long serialVersionUID = 4139331553059193758L; + + public enum DuplicateOp { + VALIDATE, DELETE; + } + + protected TRId trId; + protected ArrayList columns; + protected String normalizedColumnName; + protected String valueColumnName; + + + public NormalizationSession() { + + } + + /** + * + * @param trId + * @param columns + * @param normalizedColumnName + * @param valueColumnName + */ + public NormalizationSession(TRId trId, ArrayList columns,String normalizedColumnName, + String valueColumnName ) { + this.trId = trId; + this.columns = columns; + this.normalizedColumnName=normalizedColumnName; + this.valueColumnName=valueColumnName; + } + + public TRId getTrId() { + return trId; + } + + public void setTrId(TRId trId) { + this.trId = trId; + } + + public ArrayList getColumns() { + return columns; + } + + public void setColumns(ArrayList columns) { + this.columns = columns; + } + + public String getNormalizedColumnName() { + return normalizedColumnName; + } + + public void setNormalizedColumnName(String normalizedColumnName) { + this.normalizedColumnName = normalizedColumnName; + } + + public String getValueColumnName() { + return valueColumnName; + } + + public void setValueColumnName(String valueColumnName) { + this.valueColumnName = valueColumnName; + } + + @Override + public String toString() { + return "NormalizationSession [trId=" + trId + ", columns=" + columns + + ", normalizedColumnName=" + normalizedColumnName + + ", valueColumnName=" + valueColumnName + "]"; + } + + + + +} + diff --git a/src/main/java/org/gcube/portlets/user/td/gwtservice/shared/tr/table/Validations.java b/src/main/java/org/gcube/portlets/user/td/gwtservice/shared/tr/table/Validations.java index 647996d..9c190f0 100644 --- a/src/main/java/org/gcube/portlets/user/td/gwtservice/shared/tr/table/Validations.java +++ b/src/main/java/org/gcube/portlets/user/td/gwtservice/shared/tr/table/Validations.java @@ -2,25 +2,44 @@ package org.gcube.portlets.user.td.gwtservice.shared.tr.table; import java.io.Serializable; +import org.gcube.portlets.user.td.gwtservice.shared.tr.ConditionCode; + /** * * @author "Giancarlo Panichi" - * + * email: g.panichi@isti.cnr.it + * */ public class Validations implements Serializable { private static final long serialVersionUID = 4950002331717895999L; - String id;// Only for grid - String description; - Boolean valid; - + protected String id;// Only for grid + protected String description; + protected Boolean valid; + protected ConditionCode conditionCode; + protected String validationColumnColumnId; + + /** + * + */ public Validations() { } - - public Validations(String id, String description, Boolean valid) { + + /** + * + * @param id + * @param description + * @param valid + * @param conditionCode + * @param validationColumnColumnId + */ + public Validations(String id, String description, Boolean valid, ConditionCode conditionCode + , String validationColumnColumnId) { this.id = id; this.description = description; this.valid = valid; + this.conditionCode = conditionCode; + this.validationColumnColumnId=validationColumnColumnId; } public String getDescription() { @@ -47,10 +66,34 @@ public class Validations implements Serializable { this.id = id; } + public ConditionCode getConditionCode() { + return conditionCode; + } + + public void setConditionCode(ConditionCode conditionCode) { + this.conditionCode = conditionCode; + } + + + + public String getValidationColumnColumnId() { + return validationColumnColumnId; + } + + public void setValidationColumnColumnId(String validationColumnColumnId) { + this.validationColumnColumnId = validationColumnColumnId; + } + @Override public String toString() { return "Validations [id=" + id + ", description=" + description - + ", valid=" + valid + "]"; + + ", valid=" + valid + ", conditionCode=" + conditionCode + + ", validationColumnColumnId=" + validationColumnColumnId + + "]"; } + + + + }