From 622243cd045d236de5845c959a24cf2f784fb824 Mon Sep 17 00:00:00 2001 From: Giancarlo Panichi Date: Tue, 8 Jul 2014 16:12:09 +0000 Subject: [PATCH] Added the management of ambiguity git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/portlets/user/tabular-data-gwt-service@98502 82a268e6-3cf1-43bd-a215-b396298e98cf --- .../td/gwtservice/server/SessionUtil.java | 7 +- .../server/trservice/QueryService.java | 289 +++++++++++++++--- .../gwtservice/client/TestServiceTable.java | 4 +- 3 files changed, 251 insertions(+), 49 deletions(-) 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 7a43fbc..169bd04 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 @@ -17,6 +17,7 @@ import org.gcube.portal.custom.scopemanager.scopehelper.ScopeHelper; import org.gcube.portlets.user.td.gwtservice.server.file.CSVFileUploadSession; import org.gcube.portlets.user.td.gwtservice.server.file.CodelistMappingFileUploadSession; 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.codelisthelper.CodelistMappingMonitor; import org.gcube.portlets.user.td.gwtservice.shared.codelisthelper.CodelistMappingSession; import org.gcube.portlets.user.td.gwtservice.shared.csv.CSVExportSession; @@ -92,8 +93,8 @@ 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; String scope = Constants.DEFAULT_SCOPE; @@ -101,7 +102,7 @@ public class SessionUtil { session = SessionManager.getInstance().getASLSession( httpSession.getId(), username); session.setScope(scope); - */ + } else { session = SessionManager.getInstance().getASLSession( httpSession.getId(), username); 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 093a910..db65db7 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 @@ -17,6 +17,7 @@ import org.gcube.data.analysis.tabulardata.query.parameters.select.QuerySelect; 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.ConditionCode; import org.gcube.portlets.user.td.gwtservice.shared.tr.batch.Occurrences; import org.gcube.portlets.user.td.gwtservice.shared.tr.batch.OccurrencesForReplaceBatchColumnSession; import org.gcube.portlets.user.td.gwtservice.shared.tr.batch.ShowOccurrencesType; @@ -48,23 +49,105 @@ 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()) { - 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, sourceColumnId)); - logger.debug("Occurences queryGroup:" + queryGroup.toString()); + QuerySelect querySelect = null; + QueryGroup queryGroup = null; + + ConditionCode conditionCode = occurrencesSession.getConditionCode(); + if (conditionCode == null) { + logger.debug("Replace Batch no validations"); + if (column.isViewColumn()) { + 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, + sourceColumnId)); + logger.debug("Occurences queryGroup:" + queryGroup.toString()); + } else { + 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()); + } } else { - 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()); + logger.debug("Replace Batch from validations"); + switch (conditionCode) { + case AllowedColumnType: + break; + case AmbigousValueOnExternalReference: + if (column.isViewColumn()) { + ColumnLocalId sourceColumnId = new ColumnLocalId(column + .getColumnViewData() + .getSourceTableDimensionColumnId()); + querySelect = new QuerySelect(Arrays.asList( + new QueryColumn(columnId), new QueryColumn( + sourceColumnId))); + logger.debug("Occurences querySelect:" + + querySelect.toString()); + } else { + querySelect = new QuerySelect( + Arrays.asList(new QueryColumn(columnId))); + logger.debug("Occurences querySelect:" + + querySelect.toString()); + } + break; + case CastValidation: + break; + case CodeNamePresence: + break; + case DuplicateTupleValidation: + break; + case DuplicateValueInColumn: + break; + case GenericTupleValidity: + break; + case GenericValidity: + break; + case MaxOneCodenameForDataLocale: + break; + case MustContainAtLeastOneDimension: + break; + case MustContainAtLeastOneMeasure: + break; + case MustHaveDataLocaleMetadataAndAtLeastOneLabel: + break; + case OnlyOneCodeColumn: + break; + case OnlyOneCodenameColumn: + break; + case ValidPeriodFormat: + break; + case MissingValueOnExternalReference: + default: + if (column.isViewColumn()) { + 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, + sourceColumnId)); + logger.debug("Occurences queryGroup:" + + queryGroup.toString()); + } else { + 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()); + } + break; + } } QueryOrder queryOrder = null; @@ -88,42 +171,100 @@ public class QueryService { if (occurrencesSession.getShowType().compareTo( ShowOccurrencesType.ONLYERRORS) == 0) { if (occurrencesSession.isHasValidationColumns()) { - Expression exp=ExpressionGenerator + Expression exp = ExpressionGenerator .genReplaceBatchOccurrencesFilter(occurrencesSession); - logger.debug("Expression: "+exp); - if(exp!=null){ - queryFilter = new QueryFilter( - exp); + logger.debug("Expression: " + exp); + if (exp != null) { + queryFilter = new QueryFilter(exp); } } else { return occurences; } } - + logger.debug("Query on " + tableId.toString() + " queryPage:" - + queryPage + " queryFilter:" + queryFilter - + " querySelect:" + querySelect + " queryGroup:" - + queryGroup+" queryOrder:"+queryOrder); - logger.debug("Query Select Columns:"+querySelect.getColumns()); - logger.debug("Query Group Columns: "+queryGroup.getColumns()); + + queryPage + ", queryFilter:" + queryFilter + ", querySelect:" + + querySelect + ", queryGroup:" + queryGroup + ", queryOrder:" + + queryOrder); + + if (querySelect != null) { + logger.debug("Query Select Columns:" + querySelect.getColumns()); + } + + if (queryGroup != null) { + logger.debug("Query Group Columns: " + queryGroup.getColumns()); + } + String serviceJson = null; try { if (queryOrder == null) { if (queryFilter == null) { - serviceJson = service.queryAsJson(tableId, queryPage, - querySelect, queryGroup); + if (queryGroup == null) { + logger.debug("1-QueryAsJson-->tableId:" + tableId + + ", queryPage:" + queryPage + ", querySelect:" + + querySelect); + serviceJson = service.queryAsJson(tableId, queryPage, + querySelect); + } else { + logger.debug("2-QueryAsJson-->tableId:" + tableId + + ", queryPage:" + queryPage + ", querySelect:" + + querySelect + ", queryGroup:" + queryGroup); + serviceJson = service.queryAsJson(tableId, queryPage, + querySelect, queryGroup); + } } else { - serviceJson = service.queryAsJson(tableId, queryPage, - queryFilter, querySelect, queryGroup); + if (queryGroup == null) { + logger.debug("3-QueryAsJson-->[tableId:" + tableId + + ", queryPage:" + queryPage + ", queryFilter:" + + queryFilter + ", querySelect:" + querySelect + + "]"); + serviceJson = service.queryAsJson(tableId, queryPage, + queryFilter, querySelect); + } else { + logger.debug("4-QueryAsJson-->[tableId:" + tableId + + ", queryPage:" + queryPage + ", queryFilter:" + + queryFilter + ", querySelect:" + querySelect + + ", queryGroup:" + queryGroup + "]"); + serviceJson = service.queryAsJson(tableId, queryPage, + queryFilter, querySelect, queryGroup); + } } } else { if (queryFilter == null) { - serviceJson = service.queryAsJson(tableId, queryPage, - queryOrder, querySelect, queryGroup); + if (queryGroup == null) { + logger.debug("5-QueryAsJson-->[tableId:" + tableId + + ", queryPage:" + queryPage + ", queryOrder:" + + queryOrder + ", querySelect:" + querySelect + + "]"); + serviceJson = service.queryAsJson(tableId, queryPage, + queryOrder, querySelect); + } else { + logger.debug("6-QueryAsJson-->[tableId:" + tableId + + ", queryPage:" + queryPage + ", queryOrder:" + + queryOrder + ", querySelect:" + querySelect + + ", queryGroup:" + queryGroup + "]"); + serviceJson = service.queryAsJson(tableId, queryPage, + queryOrder, querySelect, queryGroup); + } } else { - serviceJson = service.queryAsJson(tableId, queryPage, - queryFilter, queryOrder, querySelect, queryGroup); + if (queryGroup == null) { + logger.debug("7-QueryAsJson-->[tableId:" + tableId + + ", queryPage:" + queryPage + ", queryFilter:" + + queryFilter + ", queryOrder:" + queryOrder + + ", querySelect:" + querySelect + "]"); + serviceJson = service.queryAsJson(tableId, queryPage, + queryFilter, queryOrder, querySelect); + } else { + logger.debug("8-QueryAsJson-->[tableId:" + tableId + + ", queryPage:" + queryPage + ", queryFilter:" + + queryFilter + ", queryOrder:" + queryOrder + + ", querySelect:" + querySelect + + ", queryGroup:" + queryGroup + "]"); + serviceJson = service.queryAsJson(tableId, queryPage, + queryFilter, queryOrder, querySelect, + queryGroup); + } } } } catch (Throwable e) { @@ -150,16 +291,77 @@ public class QueryService { logger.debug("Reading rows from json"); Occurrences occurence = null; for (i = 0; i < totalRows; i++) { - currentRow = rows.getJSONArray(i); - if (column.isViewColumn()) { - occurence = new Occurrences(currentRow.getString(0), - currentRow.getString(1), currentRow.getInt(2)); + if (conditionCode == null) { + if (column.isViewColumn()) { + occurence = new Occurrences( + currentRow.getString(0), + currentRow.getString(1), + currentRow.getInt(2)); + } else { + occurence = new Occurrences( + currentRow.getString(0), + currentRow.getInt(1)); + } + break; } else { - occurence = new Occurrences(currentRow.getString(0), - currentRow.getInt(1)); + switch (conditionCode) { + case AllowedColumnType: + break; + case AmbigousValueOnExternalReference: + if (column.isViewColumn()) { + occurence = new Occurrences( + currentRow.getString(0), + currentRow.getString(1), 1); + } else { + occurence = new Occurrences( + currentRow.getString(0), 1); + } + break; + case CastValidation: + break; + case CodeNamePresence: + break; + case DuplicateTupleValidation: + break; + case DuplicateValueInColumn: + break; + case GenericTupleValidity: + break; + case GenericValidity: + break; + case MaxOneCodenameForDataLocale: + break; + + case MustContainAtLeastOneDimension: + break; + case MustContainAtLeastOneMeasure: + break; + case MustHaveDataLocaleMetadataAndAtLeastOneLabel: + break; + case OnlyOneCodeColumn: + break; + case OnlyOneCodenameColumn: + break; + case ValidPeriodFormat: + break; + case MissingValueOnExternalReference: + default: + if (column.isViewColumn()) { + occurence = new Occurrences( + currentRow.getString(0), + currentRow.getString(1), + currentRow.getInt(2)); + } else { + occurence = new Occurrences( + currentRow.getString(0), + currentRow.getInt(1)); + } + break; + + } } - //logger.debug(occurence.toString()); + // logger.debug(occurence.toString()); occurences.add(occurence); } @@ -169,6 +371,7 @@ public class QueryService { logger.error("An error occurred while parsing json document\n" + "At Row " + i + ",Column " + j + "\nRow Content: " + currentRow + "\nLenght rows " + totalRows, e); + e.printStackTrace(); throw new TDGWTServiceException( "An error occurred, while reading json of service", e); } @@ -177,6 +380,4 @@ public class QueryService { } - - } diff --git a/src/test/java/org/gcube/portlets/user/td/gwtservice/client/TestServiceTable.java b/src/test/java/org/gcube/portlets/user/td/gwtservice/client/TestServiceTable.java index 04d2c09..4803ede 100644 --- a/src/test/java/org/gcube/portlets/user/td/gwtservice/client/TestServiceTable.java +++ b/src/test/java/org/gcube/portlets/user/td/gwtservice/client/TestServiceTable.java @@ -21,8 +21,8 @@ import org.junit.Test; * */ public class TestServiceTable { - private final static long trId = 100; - private final static long searchTableId=341; + private final static long trId = 238; + private final static long searchTableId=4312; private String user=Constants.DEFAULT_USER; private String scope=Constants.DEFAULT_SCOPE;