diff --git a/src/main/java/org/gcube/portlets/user/td/gwtservice/server/opexecution/OpExecution4EditRow.java b/src/main/java/org/gcube/portlets/user/td/gwtservice/server/opexecution/OpExecution4EditRow.java index 9c03e51..002b849 100644 --- a/src/main/java/org/gcube/portlets/user/td/gwtservice/server/opexecution/OpExecution4EditRow.java +++ b/src/main/java/org/gcube/portlets/user/td/gwtservice/server/opexecution/OpExecution4EditRow.java @@ -26,7 +26,8 @@ import org.slf4j.LoggerFactory; * */ public class OpExecution4EditRow extends OpExecutionBuilder { - protected static Logger logger = LoggerFactory + private static final String ITEM_CREATE_ROW = "NewRow"; + private static Logger logger = LoggerFactory .getLogger(OpExecution4EditRow.class); private TabularDataService service; @@ -39,44 +40,62 @@ public class OpExecution4EditRow extends OpExecutionBuilder { @Override public void buildOpEx() throws TDGWTServiceException { - OperationExecution invocation = null; - logger.debug(editRowSession.toString()); - OperationDefinition operationDefinition; - + + OperationDefinition operationDefinition; + OperationExecution invocation; + Map map = new HashMap(); + ArrayList invocations = new ArrayList(); + ValueMap valueMap = new ValueMap(); - ArrayList> compositeValue = valueMap - .genValueMap(editRowSession); - + if (editRowSession.isNewRow()) { logger.debug("Is a add row"); operationDefinition = OperationDefinitionMap.map( OperationsId.AddRow.toString(), service); + HashMap fieldsMap=editRowSession.getRowsMaps().get(ITEM_CREATE_ROW); + + ArrayList> compositeValue = valueMap + .genValueMap(editRowSession.getTrId(), editRowSession.getColumns(), fieldsMap); + map.put(Constants.PARAMETER_ADD_ROW_COMPOSITE, compositeValue); invocation = new OperationExecution( operationDefinition.getOperationId(), map); + invocations.add(invocation); } else { logger.debug("Is a edit row"); + + for (String rowId : editRowSession.getRowsId()) { + HashMap fieldsMap=editRowSession.getRowsMaps().get(rowId); + + ArrayList> compositeValue = valueMap + .genValueMap(editRowSession.getTrId(),editRowSession.getColumns(), fieldsMap); - Expression exp = ExpressionGenerator.genEditRowParamaterCondition( - service, editRowSession); + Expression exp = ExpressionGenerator.genEditRowParamaterCondition( + service, editRowSession.getTrId(), rowId); - operationDefinition = OperationDefinitionMap.map( - OperationsId.ModifyTuplesValuesByExpression.toString(), - service); + operationDefinition = OperationDefinitionMap.map( + OperationsId.ModifyTuplesValuesByExpression.toString(), + service); - map.put(Constants.PARAMETER_ADD_ROW_COMPOSITE, compositeValue); - map.put(Constants.PARAMETER_EDIT_ROW_CONDITION, exp); + map.put(Constants.PARAMETER_ADD_ROW_COMPOSITE, compositeValue); + map.put(Constants.PARAMETER_EDIT_ROW_CONDITION, exp); + + invocation = new OperationExecution( + operationDefinition.getOperationId(), map); + invocations.add(invocation); + } - invocation = new OperationExecution( - operationDefinition.getOperationId(), map); } - operationExecutionSpec.setOp(invocation); + + + operationExecutionSpec.setOps(invocations); + } 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 27a3e94..748f73f 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 @@ -23,7 +23,6 @@ import org.gcube.portlets.user.td.gwtservice.shared.tr.batch.ReplaceBatchColumnS import org.gcube.portlets.user.td.gwtservice.shared.tr.batch.ReplaceEntry; import org.gcube.portlets.user.td.gwtservice.shared.tr.column.ReplaceColumnByExpressionSession; 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; @@ -295,11 +294,10 @@ public class ExpressionGenerator { } public static Expression genEditRowParamaterCondition( - TabularDataService service, EditRowSession editRowSession) + TabularDataService service, TRId trId, String rowId) throws TDGWTServiceException { try { Expression exp = null; - TRId trId = editRowSession.getTrId(); TableId tableId; if (trId.isViewTable()) { tableId = new TableId( @@ -325,7 +323,7 @@ public class ExpressionGenerator { idCol.getLocalId()); exp = new Equals(cr, new TDInteger( - Integer.parseInt(editRowSession.getRowId()))); + Integer.parseInt(rowId))); } else { logger.debug("No IdColumnType retrieved for table:" 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 692ff86..3871790 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 @@ -20,7 +20,6 @@ import org.gcube.data.analysis.tabulardata.model.table.TableId; import org.gcube.portlets.user.td.gwtservice.shared.Constants; 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.rows.EditRowSession; import org.gcube.portlets.user.td.widgetcommonevent.shared.TRId; import org.gcube.portlets.user.td.widgetcommonevent.shared.tr.column.ColumnDataType; import org.gcube.portlets.user.td.widgetcommonevent.shared.tr.column.ColumnTypeCode; @@ -43,28 +42,28 @@ public class ValueMap { protected SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); - public ArrayList> genValueMap(EditRowSession editRowSession) + public ArrayList> genValueMap(TRId trId, ArrayList columns, HashMap fieldsMap) throws TDGWTServiceException { ArrayList> composit=new ArrayList>(); - if(editRowSession.getMaps()==null){ + if(fieldsMap==null){ return composit; } - TRId trId=editRowSession.getTrId(); + TableId tableId; if(trId.isViewTable()){ tableId=new TableId(new Long(trId.getReferenceTargetTableId())); } else { tableId=new TableId(new Long(trId.getTableId())); } - Map parametersValue=editRowSession.getMaps(); + Map parametersValue=fieldsMap; Set keys=parametersValue.keySet(); Iterator iterator=keys.iterator(); String key; while(iterator.hasNext()){ key=iterator.next(); String value=parametersValue.get(key); - for(ColumnData col:editRowSession.getColumns()){ + for(ColumnData col:columns){ if(col.getColumnId().compareTo(key)==0){ if (col.getTypeCode().compareTo( ColumnTypeCode.DIMENSION.toString()) == 0 diff --git a/src/main/java/org/gcube/portlets/user/td/gwtservice/shared/tr/rows/EditRowSession.java b/src/main/java/org/gcube/portlets/user/td/gwtservice/shared/tr/rows/EditRowSession.java index e47ee81..61529c4 100644 --- a/src/main/java/org/gcube/portlets/user/td/gwtservice/shared/tr/rows/EditRowSession.java +++ b/src/main/java/org/gcube/portlets/user/td/gwtservice/shared/tr/rows/EditRowSession.java @@ -9,37 +9,47 @@ import org.gcube.portlets.user.td.widgetcommonevent.shared.TRId; /** * - * @author giancarlo - * email: g.panichi@isti.cnr.it + * @author giancarlo email: g.panichi@isti.cnr.it * */ public class EditRowSession implements Serializable { private static final long serialVersionUID = -4503878699159491057L; - - protected TRId trId; - protected ArrayList columns; - protected HashMap maps; - protected boolean newRow; - protected String rowId; - - public EditRowSession(){ - + + private TRId trId; + + private ArrayList columns; + + private boolean newRow; + + /** + * A HashMap from rowId to HashMap from columnId to value + */ + private HashMap> rowsMaps; + + private ArrayList rowsId; + + public EditRowSession() { + } - - public EditRowSession(TRId trId, ArrayList columns,HashMap maps){ - this.trId=trId; - this.columns=columns; - this.maps=maps; - this.newRow=true; + + public EditRowSession(TRId trId, ArrayList columns, + HashMap> rowsMaps) { + this.trId = trId; + this.columns = columns; + this.rowsMaps = rowsMaps; + this.newRow = true; } - - public EditRowSession(TRId trId, ArrayList columns,HashMap maps, String rowId){ - this.trId=trId; - this.columns=columns; - this.maps=maps; - this.newRow=false; - this.rowId=rowId; + + public EditRowSession(TRId trId, ArrayList columns, + HashMap> rowsMaps, + ArrayList rowsId) { + this.trId = trId; + this.columns = columns; + this.rowsMaps = rowsMaps; + this.newRow = false; + this.rowsId = rowsId; } public TRId getTrId() { @@ -58,14 +68,6 @@ public class EditRowSession implements Serializable { this.columns = columns; } - public HashMap getMaps() { - return maps; - } - - public void setMaps(HashMap maps) { - this.maps = maps; - } - public boolean isNewRow() { return newRow; } @@ -74,22 +76,27 @@ public class EditRowSession implements Serializable { this.newRow = newRow; } - public String getRowId() { - return rowId; + public HashMap> getRowsMaps() { + return rowsMaps; } - public void setRowId(String rowId) { - this.rowId = rowId; + public void setRowsMaps(HashMap> rowsMaps) { + this.rowsMaps = rowsMaps; + } + + public ArrayList getRowsId() { + return rowsId; + } + + public void setRowsId(ArrayList rowsId) { + this.rowsId = rowsId; } @Override public String toString() { return "EditRowSession [trId=" + trId + ", columns=" + columns - + ", maps=" + maps + ", newRow=" + newRow + ", rowId=" + rowId - + "]"; + + ", newRow=" + newRow + ", rowsMaps=" + rowsMaps + ", rowsId=" + + rowsId + "]"; } - - - }