From 86d7b979b9ce86368af4648d9a22e1ecf669f0d5 Mon Sep 17 00:00:00 2001 From: Giancarlo Panichi Date: Tue, 20 May 2014 10:19:27 +0000 Subject: [PATCH] Fixed Edit Row git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/portlets/user/tabular-data-gwt-service@95848 82a268e6-3cf1-43bd-a215-b396298e98cf --- .../td/gwtservice/server/SessionUtil.java | 6 +- .../gwtservice/server/TDGWTServiceImpl.java | 10 +++- .../server/trservice/ExpressionGenerator.java | 59 +++++++++++++++++-- .../gwtservice/server/trservice/ValueMap.java | 1 + .../user/td/gwtservice/shared/Constants.java | 2 + 5 files changed, 68 insertions(+), 10 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 681df08..56f1998 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 @@ -74,15 +74,15 @@ public class SessionUtil { ASLSession session; if (username == null) { logger.warn("no user found in session, using test one"); - //throw new TDGWTSessionExpiredException("Session Expired!"); + throw new TDGWTSessionExpiredException("Session Expired!"); - username = Constants.DEFAULT_USER; + /*username = Constants.DEFAULT_USER; String scope = Constants.DEFAULT_SCOPE; httpSession.setAttribute(ScopeHelper.USERNAME_ATTRIBUTE, username); session = SessionManager.getInstance().getASLSession( httpSession.getId(), username); - session.setScope(scope); + session.setScope(scope);*/ } else { session = SessionManager.getInstance().getASLSession( diff --git a/src/main/java/org/gcube/portlets/user/td/gwtservice/server/TDGWTServiceImpl.java b/src/main/java/org/gcube/portlets/user/td/gwtservice/server/TDGWTServiceImpl.java index 35ef0b8..d88366e 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 @@ -3898,13 +3898,17 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements } else { logger.debug("Is a edit row"); - + + Expression exp=ExpressionGenerator.genEditRowParamaterCondition(service, editRowSession); + operationDefinition = OperationDefinitionMap.map( OperationsId.ModifyTuplesValuesByExpression.toString(), service); - + + map.put(Constants.PARAMETER_ADD_ROW_COMPOSITE, compositeValue); - + map.put(Constants.PARAMETER_EDIT_ROW_CONDITION, exp); + invocation = new OperationExecution( operationDefinition.getOperationId(), map); } 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 b751493..f04791c 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 @@ -1,21 +1,28 @@ package org.gcube.portlets.user.td.gwtservice.server.trservice; import java.util.ArrayList; +import java.util.List; import org.gcube.data.analysis.tabulardata.expression.Expression; import org.gcube.data.analysis.tabulardata.expression.composite.comparable.Equals; import org.gcube.data.analysis.tabulardata.expression.logical.And; import org.gcube.data.analysis.tabulardata.expression.logical.Not; +import org.gcube.data.analysis.tabulardata.model.column.Column; 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.column.type.IdColumnType; 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.Table; 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.ReplaceBatchColumnSession; import org.gcube.portlets.user.td.gwtservice.shared.tr.batch.ReplaceEntry; import org.gcube.portlets.user.td.gwtservice.shared.tr.column.ReplaceColumnSession; +import org.gcube.portlets.user.td.gwtservice.shared.tr.rows.EditRowSession; +import org.gcube.portlets.user.td.widgetcommonevent.shared.TRId; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -218,11 +225,11 @@ public class ExpressionGenerator { new ColumnLocalId(columnLocalId)); listColumnReference.add(cr); } - if(listColumnReference.size()<=0){ + if (listColumnReference.size() <= 0) { return null; } else { - if(listColumnReference.size()==1){ - Not not=new Not(listColumnReference.get(0)); + if (listColumnReference.size() == 1) { + Not not = new Not(listColumnReference.get(0)); return not; } else { And and = new And(listColumnReference); @@ -231,7 +238,6 @@ public class ExpressionGenerator { } } - } catch (Throwable e) { logger.debug("Error in genReplaceBatchOccurrencesFilter: " + e.getLocalizedMessage()); @@ -243,4 +249,49 @@ public class ExpressionGenerator { } + public static Expression genEditRowParamaterCondition(TabularDataService service, + EditRowSession editRowSession) throws TDGWTServiceException { + try { + Expression exp=null; + TRId trId = editRowSession.getTrId(); + TableId tableId; + if (trId.isViewTable()) { + tableId = new TableId( + new Long(trId.getReferenceTargetTableId())); + } else { + tableId = new TableId(new Long(trId.getTableId())); + } + + Table table = service.getTable(new TableId(Long.valueOf(trId + .getTableId()))); + + List cols = table.getColumns(); + Column idCol = null; + for (Column c : cols) { + if (c.getColumnType() instanceof IdColumnType) { + idCol = c; + break; + } + } + + if (idCol != null) { + ColumnReference cr = new ColumnReference(tableId, + idCol.getLocalId()); + + exp = new Equals(cr, new TDInteger( + Integer.parseInt(editRowSession.getRowId()))); + + } else { + logger.debug("No IdColumnType retrieved for table:"+table.getId().toString()); + } + logger.debug("genEditRowParamaterCondition() condition:"+exp); + return exp; + } catch (Throwable e) { + logger.error("Error in genEditRowParamaterCondition(): "+e.getLocalizedMessage()); + e.printStackTrace(); + throw new TDGWTServiceException("Error in genEditRowParamaterCondition(): "+e.getLocalizedMessage()); + } + + } + } diff --git a/src/main/java/org/gcube/portlets/user/td/gwtservice/server/trservice/ValueMap.java b/src/main/java/org/gcube/portlets/user/td/gwtservice/server/trservice/ValueMap.java index c0540e4..fe05d02 100644 --- a/src/main/java/org/gcube/portlets/user/td/gwtservice/server/trservice/ValueMap.java +++ b/src/main/java/org/gcube/portlets/user/td/gwtservice/server/trservice/ValueMap.java @@ -40,6 +40,7 @@ public class ValueMap { protected SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); + public ArrayList> genValueMap(EditRowSession editRowSession){ ArrayList> composit=new ArrayList>(); 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 ecf5155..bce11dd 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 @@ -43,6 +43,8 @@ public class Constants { public static final String PARAMETER_ADD_ROW_COMPOSITE_TOSETVALUE="toSetValue"; public static final String PARAMETER_ADD_ROW_COMPOSITE="mapping"; + public static final String PARAMETER_EDIT_ROW_CONDITION="condition"; + public static final String NAME_PARAMETER_ID="NAME_PARAMETER_ID"; public static final String PARAMETER_KEY="key"; public static final String PARAMETER_REFERENCE_COLUMN="refColumn";