Updated EditRow to manage to more than one row
git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/portlets/user/tabular-data-gwt-service@111332 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
3fe01a703f
commit
e2fd7ce753
|
@ -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<String, Object> map = new HashMap<String, Object>();
|
||||
ArrayList<OperationExecution> invocations = new ArrayList<OperationExecution>();
|
||||
|
||||
ValueMap valueMap = new ValueMap();
|
||||
ArrayList<Map<String, Object>> compositeValue = valueMap
|
||||
.genValueMap(editRowSession);
|
||||
|
||||
|
||||
if (editRowSession.isNewRow()) {
|
||||
logger.debug("Is a add row");
|
||||
operationDefinition = OperationDefinitionMap.map(
|
||||
OperationsId.AddRow.toString(), service);
|
||||
|
||||
HashMap<String,String> fieldsMap=editRowSession.getRowsMaps().get(ITEM_CREATE_ROW);
|
||||
|
||||
ArrayList<Map<String, Object>> 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<String,String> fieldsMap=editRowSession.getRowsMaps().get(rowId);
|
||||
|
||||
ArrayList<Map<String, Object>> 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);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -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:"
|
||||
|
|
|
@ -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<Map<String,Object>> genValueMap(EditRowSession editRowSession)
|
||||
public ArrayList<Map<String,Object>> genValueMap(TRId trId, ArrayList<ColumnData> columns, HashMap<String,String> fieldsMap)
|
||||
throws TDGWTServiceException {
|
||||
ArrayList<Map<String,Object>> composit=new ArrayList<Map<String,Object>>();
|
||||
|
||||
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<String,String> parametersValue=editRowSession.getMaps();
|
||||
Map<String,String> parametersValue=fieldsMap;
|
||||
Set<String> keys=parametersValue.keySet();
|
||||
Iterator<String> 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
|
||||
|
|
|
@ -9,37 +9,47 @@ import org.gcube.portlets.user.td.widgetcommonevent.shared.TRId;
|
|||
|
||||
/**
|
||||
*
|
||||
* @author giancarlo
|
||||
* email: <a href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
|
||||
* @author giancarlo email: <a
|
||||
* href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
|
||||
*
|
||||
*/
|
||||
public class EditRowSession implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = -4503878699159491057L;
|
||||
|
||||
protected TRId trId;
|
||||
protected ArrayList<ColumnData> columns;
|
||||
protected HashMap<String, String> maps;
|
||||
protected boolean newRow;
|
||||
protected String rowId;
|
||||
|
||||
public EditRowSession(){
|
||||
|
||||
|
||||
private TRId trId;
|
||||
|
||||
private ArrayList<ColumnData> columns;
|
||||
|
||||
private boolean newRow;
|
||||
|
||||
/**
|
||||
* A HashMap from rowId to HashMap from columnId to value
|
||||
*/
|
||||
private HashMap<String, HashMap<String, String>> rowsMaps;
|
||||
|
||||
private ArrayList<String> rowsId;
|
||||
|
||||
public EditRowSession() {
|
||||
|
||||
}
|
||||
|
||||
public EditRowSession(TRId trId, ArrayList<ColumnData> columns,HashMap<String, String> maps){
|
||||
this.trId=trId;
|
||||
this.columns=columns;
|
||||
this.maps=maps;
|
||||
this.newRow=true;
|
||||
|
||||
public EditRowSession(TRId trId, ArrayList<ColumnData> columns,
|
||||
HashMap<String, HashMap<String, String>> rowsMaps) {
|
||||
this.trId = trId;
|
||||
this.columns = columns;
|
||||
this.rowsMaps = rowsMaps;
|
||||
this.newRow = true;
|
||||
}
|
||||
|
||||
public EditRowSession(TRId trId, ArrayList<ColumnData> columns,HashMap<String, String> maps, String rowId){
|
||||
this.trId=trId;
|
||||
this.columns=columns;
|
||||
this.maps=maps;
|
||||
this.newRow=false;
|
||||
this.rowId=rowId;
|
||||
|
||||
public EditRowSession(TRId trId, ArrayList<ColumnData> columns,
|
||||
HashMap<String, HashMap<String, String>> rowsMaps,
|
||||
ArrayList<String> 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<String, String> getMaps() {
|
||||
return maps;
|
||||
}
|
||||
|
||||
public void setMaps(HashMap<String, String> 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<String, HashMap<String, String>> getRowsMaps() {
|
||||
return rowsMaps;
|
||||
}
|
||||
|
||||
public void setRowId(String rowId) {
|
||||
this.rowId = rowId;
|
||||
public void setRowsMaps(HashMap<String, HashMap<String, String>> rowsMaps) {
|
||||
this.rowsMaps = rowsMaps;
|
||||
}
|
||||
|
||||
public ArrayList<String> getRowsId() {
|
||||
return rowsId;
|
||||
}
|
||||
|
||||
public void setRowsId(ArrayList<String> 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 + "]";
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue