Updated Rule

git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/portlets/user/tabular-data-expression-widget@114061 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Giancarlo Panichi 2015-04-15 11:32:02 +00:00
parent b4e626cfc4
commit 704f570300
10 changed files with 379 additions and 104 deletions

View File

@ -16,6 +16,7 @@ import org.gcube.portlets.user.td.expressionwidget.shared.exception.ConditionTyp
import org.gcube.portlets.user.td.expressionwidget.shared.model.logical.C_Not;
import org.gcube.portlets.user.td.expressionwidget.shared.rule.RuleDescriptionData;
import org.gcube.portlets.user.td.expressionwidget.shared.rule.RuleScopeType;
import org.gcube.portlets.user.td.expressionwidget.shared.rule.type.TDBaseColumnRuleType;
import org.gcube.portlets.user.td.gwtservice.client.rpc.TDGWTServiceAsync;
import org.gcube.portlets.user.td.gwtservice.shared.exception.TDGWTIsFinalException;
import org.gcube.portlets.user.td.gwtservice.shared.exception.TDGWTIsLockedException;
@ -721,13 +722,16 @@ public class ColumnExpressionPanel extends FramedPanel {
protected RuleDescriptionData retrieveRuleDescriptionData(C_Expression exp) {
ColumnMockUp columnMockUp = checkEnterData();
if (columnMockUp != null) {
if(exp!=null){
String ruleNameS = ruleName.getCurrentValue();
String ruleDescriptionS = ruleDescription.getCurrentValue();
RuleDescriptionData ruleDescriptionData = new RuleDescriptionData(
0, ruleNameS, ruleDescriptionS, RuleScopeType.COLUMN, exp);
return ruleDescriptionData;
if (exp != null) {
String ruleNameS = ruleName.getCurrentValue();
String ruleDescriptionS = ruleDescription.getCurrentValue();
TDBaseColumnRuleType tdBaseColumnRule = new TDBaseColumnRuleType(
columnMockUp.getColumnDataType());
RuleDescriptionData ruleDescriptionData = new RuleDescriptionData(
0, ruleNameS, ruleDescriptionS, RuleScopeType.COLUMN,
tdBaseColumnRule, exp);
return ruleDescriptionData;
} else {
UtilsGXT3.alert("Attention", "Enter a valid condition!");
return null;

View File

@ -48,10 +48,14 @@ public interface ExpressionService extends RemoteService {
public String startAddColumn(AddColumnSession addColumnSession)
throws TDGWTServiceException;
public ArrayList<RuleDescriptionData> getRules()
throws TDGWTServiceException;
public ArrayList<RuleDescriptionData> getRules(RuleScopeType scope)
throws TDGWTServiceException;
public String saveColumnRule(RuleDescriptionData ruleDescriptionData)
throws TDGWTServiceException;
}

View File

@ -41,4 +41,7 @@ public interface ExpressionServiceAsync {
void getRules(RuleScopeType scope,
AsyncCallback<ArrayList<RuleDescriptionData>> callback);
void saveColumnRule(RuleDescriptionData ruleDescriptionData,
AsyncCallback<String> callback);
}

View File

@ -7,36 +7,33 @@ import java.util.List;
import javax.servlet.http.HttpSession;
import org.gcube.application.framework.core.session.ASLSession;
import org.gcube.data.analysis.tabulardata.commons.rules.types.RuleColumnType;
import org.gcube.data.analysis.tabulardata.commons.utils.AuthorizationProvider;
import org.gcube.data.analysis.tabulardata.commons.utils.AuthorizationToken;
import org.gcube.data.analysis.tabulardata.commons.webservice.types.RuleDescription;
import org.gcube.data.analysis.tabulardata.expression.Expression;
import org.gcube.data.analysis.tabulardata.model.metadata.table.DatasetViewTableMetadata;
import org.gcube.data.analysis.tabulardata.model.table.Table;
import org.gcube.data.analysis.tabulardata.service.TabularDataService;
import org.gcube.data.analysis.tabulardata.service.impl.TabularDataServiceFactory;
import org.gcube.data.analysis.tabulardata.service.tabular.TabularResource;
import org.gcube.data.analysis.tabulardata.service.tabular.TabularResourceId;
import org.gcube.data.analysis.tabulardata.service.rules.RuleId;
import org.gcube.portlets.user.td.expressionwidget.client.rpc.ExpressionService;
import org.gcube.portlets.user.td.expressionwidget.server.service.RuleScopeMap;
import org.gcube.portlets.user.td.expressionwidget.server.service.rule.RuleColumnTypeMap;
import org.gcube.portlets.user.td.expressionwidget.server.service.rule.RuleScopeMap;
import org.gcube.portlets.user.td.expressionwidget.shared.exception.ExpressionParserException;
import org.gcube.portlets.user.td.expressionwidget.shared.exception.ExpressionServiceException;
import org.gcube.portlets.user.td.expressionwidget.shared.rule.RuleDescriptionData;
import org.gcube.portlets.user.td.expressionwidget.shared.rule.RuleScopeType;
import org.gcube.portlets.user.td.gwtservice.server.SessionUtil;
import org.gcube.portlets.user.td.gwtservice.server.TDGWTServiceImpl;
import org.gcube.portlets.user.td.gwtservice.server.trservice.TabularResourceTypeMap;
import org.gcube.portlets.user.td.gwtservice.shared.exception.TDGWTServiceException;
import org.gcube.portlets.user.td.gwtservice.shared.tr.column.AddColumnSession;
import org.gcube.portlets.user.td.gwtservice.shared.tr.column.FilterColumnSession;
import org.gcube.portlets.user.td.gwtservice.shared.tr.column.ReplaceColumnByExpressionSession;
import org.gcube.portlets.user.td.widgetcommonevent.shared.TRId;
import org.gcube.portlets.user.td.widgetcommonevent.shared.expression.C_Expression;
import org.gcube.portlets.user.td.widgetcommonevent.shared.tr.column.ColumnMockUp;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.google.gwt.user.server.rpc.RemoteServiceServlet;
//import com.google.gwt.user.server.rpc.RemoteServiceServlet;
/**
*
@ -44,7 +41,7 @@ import com.google.gwt.user.server.rpc.RemoteServiceServlet;
* href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
*
*/
public class ExpressionServiceImpl extends RemoteServiceServlet implements
public class ExpressionServiceImpl extends TDGWTServiceImpl implements
ExpressionService {
private static final long serialVersionUID = 4632292751581364137L;
@ -76,7 +73,7 @@ public class ExpressionServiceImpl extends RemoteServiceServlet implements
filterColumnSession);
C_ExpressionParser parser = new C_ExpressionParser();
Expression expression=null;
Expression expression = null;
try {
expression = parser.parse(filterColumnSession.getCexpression());
} catch (ExpressionParserException e) {
@ -85,10 +82,10 @@ public class ExpressionServiceImpl extends RemoteServiceServlet implements
}
logger.debug("Service Expression:" + expression);
TDGWTServiceImpl gwtService = new TDGWTServiceImpl();
// TDGWTServiceImpl gwtService = new TDGWTServiceImpl();
String taskId = gwtService.startFilterColumn(filterColumnSession,
expression, session);
String taskId = startFilterColumn(filterColumnSession, expression,
session);
return taskId;
@ -120,7 +117,7 @@ public class ExpressionServiceImpl extends RemoteServiceServlet implements
ColumnMockUp columnMockUp = addColumnSession.getColumnMockUp();
Expression expression=null;
Expression expression = null;
if (columnMockUp.hasExpression()) {
C_ExpressionParser parser = new C_ExpressionParser();
@ -135,10 +132,10 @@ public class ExpressionServiceImpl extends RemoteServiceServlet implements
}
TDGWTServiceImpl gwtService = new TDGWTServiceImpl();
// TDGWTServiceImpl gwtService = new TDGWTServiceImpl();
String taskId = gwtService.startAddColumn(addColumnSession,
expression, session);
String taskId = startAddColumn(addColumnSession, expression,
session);
return taskId;
@ -197,9 +194,9 @@ public class ExpressionServiceImpl extends RemoteServiceServlet implements
logger.debug("Service Replace Expression:" + replaceExpression);
}
TDGWTServiceImpl gwtService = new TDGWTServiceImpl();
// TDGWTServiceImpl gwtService = new TDGWTServiceImpl();
String taskId = gwtService.startReplaceColumnByExpression(
String taskId = startReplaceColumnByExpression(
replaceColumnByExpressionSession, conditionExpression,
replaceExpression, session);
return taskId;
@ -208,12 +205,10 @@ public class ExpressionServiceImpl extends RemoteServiceServlet implements
throw e;
} catch (Throwable e) {
e.printStackTrace();
throw new TDGWTServiceException(
e.getLocalizedMessage());
throw new TDGWTServiceException(e.getLocalizedMessage());
}
}
/**
*
* {@inheritDoc}
@ -265,8 +260,7 @@ public class ExpressionServiceImpl extends RemoteServiceServlet implements
}
}
/**
*
* {@inheritDoc}
@ -317,9 +311,69 @@ public class ExpressionServiceImpl extends RemoteServiceServlet implements
}
}
/**
*
* {@inheritDoc}
*/
@Override
public String saveColumnRule(
RuleDescriptionData ruleDescriptionData)
throws TDGWTServiceException {
try {
HttpSession session = this.getThreadLocalRequest().getSession();
ASLSession aslSession = SessionUtil.getAslSession(session);
logger.debug("SaveColumnRule() :" + ruleDescriptionData);
AuthorizationProvider.instance.set(new AuthorizationToken(
aslSession.getUsername(), aslSession.getScope()));
TabularDataService service = TabularDataServiceFactory.getService();
C_ExpressionParser parser = new C_ExpressionParser();
Expression conditionExpression = null;
try {
conditionExpression = parser.parse(ruleDescriptionData
.getExpression());
} catch (ExpressionParserException e) {
logger.debug(e.getLocalizedMessage());
throw new TDGWTServiceException(e.getLocalizedMessage());
}
logger.debug("Service Condition Expression:" + conditionExpression);
RuleColumnType ruleColumnType = RuleColumnTypeMap
.map(ruleDescriptionData.getTdRuleColumnType());
RuleId ruleId=service.saveColumnRule(ruleDescriptionData.getName(),
ruleDescriptionData.getDescription(), conditionExpression,
ruleColumnType);
logger.debug("RuleId: "+ruleId);
String ruleIdent=null;
if(ruleId!=null){
ruleIdent=String.valueOf(ruleId.getId());
}
return ruleIdent;
} catch (TDGWTServiceException e) {
logger.error(e.getLocalizedMessage());
throw e;
} catch (SecurityException e) {
logger.error(e.getLocalizedMessage());
e.printStackTrace();
throw e;
} catch (Throwable e) {
logger.error("Error in getRule(): " + e.getLocalizedMessage());
e.printStackTrace();
throw new TDGWTServiceException("Error retrieving the rules: "
+ e.getLocalizedMessage());
}
}
/**
* Retrieve and set Tabular Resource Type
*
@ -327,67 +381,50 @@ public class ExpressionServiceImpl extends RemoteServiceServlet implements
* @return
* @throws TDGWTServiceException
*/
protected TRId retrieveTabularResourceBasicData(TRId trId)
throws TDGWTServiceException {
try {
HttpSession session = this.getThreadLocalRequest().getSession();
ASLSession aslSession = SessionUtil.getAslSession(session);
AuthorizationProvider.instance.set(new AuthorizationToken(
aslSession.getUsername(), aslSession.getScope()));
TabularDataService service = TabularDataServiceFactory.getService();
TabularResourceId tabularResourceId = new TabularResourceId(
new Long(trId.getId()));
TabularResource tr = service.getTabularResource(tabularResourceId);
Table table = service.getLastTable(tabularResourceId);
Table viewTable = null;
if (table.contains(DatasetViewTableMetadata.class)) {
DatasetViewTableMetadata dwm = table
.getMetadata(DatasetViewTableMetadata.class);
try {
viewTable = service.getTable(dwm
.getTargetDatasetViewTableId());
} catch (Exception e) {
logger.error("view table not found");
}
}
TRId newTRId;
if (viewTable == null) {
newTRId = new TRId(
String.valueOf(tr.getId().getValue()),
TabularResourceTypeMap.map(tr.getTabularResourceType()),
tr.getTableType(), String.valueOf(table.getId()
.getValue()), table.getTableType().getName());
} else {
newTRId = new TRId(
String.valueOf(tr.getId().getValue()),
TabularResourceTypeMap.map(tr.getTabularResourceType()),
tr.getTableType(), String.valueOf(viewTable.getId()
.getValue()), viewTable.getTableType()
.getName(), String.valueOf(table.getId()
.getValue()), true);
}
logger.debug("Retrieved TRId basic info:" + newTRId.toString());
return newTRId;
} catch (TDGWTServiceException 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 on Service: "
+ e.getLocalizedMessage());
}
}
/*
* protected TRId retrieveTabularResourceBasicData(TRId trId) throws
* TDGWTServiceException { try { HttpSession session =
* this.getThreadLocalRequest().getSession(); ASLSession aslSession =
* SessionUtil.getAslSession(session);
*
* AuthorizationProvider.instance.set(new AuthorizationToken(
* aslSession.getUsername(), aslSession.getScope())); TabularDataService
* service = TabularDataServiceFactory.getService(); TabularResourceId
* tabularResourceId = new TabularResourceId( new Long(trId.getId()));
*
* TabularResource tr = service.getTabularResource(tabularResourceId); Table
* table = service.getLastTable(tabularResourceId);
*
* Table viewTable = null;
*
* if (table.contains(DatasetViewTableMetadata.class)) {
* DatasetViewTableMetadata dwm = table
* .getMetadata(DatasetViewTableMetadata.class); try { viewTable =
* service.getTable(dwm .getTargetDatasetViewTableId()); } catch (Exception
* e) { logger.error("view table not found"); } }
*
* TRId newTRId; if (viewTable == null) { newTRId = new TRId(
* String.valueOf(tr.getId().getValue()),
* TabularResourceTypeMap.map(tr.getTabularResourceType()),
* tr.getTableType(), String.valueOf(table.getId() .getValue()),
* table.getTableType().getName());
*
* } else { newTRId = new TRId( String.valueOf(tr.getId().getValue()),
* TabularResourceTypeMap.map(tr.getTabularResourceType()),
* tr.getTableType(), String.valueOf(viewTable.getId() .getValue()),
* viewTable.getTableType() .getName(), String.valueOf(table.getId()
* .getValue()), true);
*
* }
*
* logger.debug("Retrieved TRId basic info:" + newTRId.toString()); return
* newTRId;
*
* } catch (TDGWTServiceException 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 on Service: "
* + e.getLocalizedMessage()); } }
*/
}

View File

@ -0,0 +1,95 @@
package org.gcube.portlets.user.td.expressionwidget.server.service.rule;
import org.gcube.data.analysis.tabulardata.commons.rules.types.BaseColumnRuleType;
import org.gcube.data.analysis.tabulardata.commons.rules.types.DimensionColumnRuleType;
import org.gcube.data.analysis.tabulardata.commons.rules.types.RuleColumnType;
import org.gcube.data.analysis.tabulardata.commons.utils.DimensionReference;
import org.gcube.data.analysis.tabulardata.model.column.ColumnLocalId;
import org.gcube.data.analysis.tabulardata.model.table.TableId;
import org.gcube.portlets.user.td.expressionwidget.shared.rule.type.TDBaseColumnRuleType;
import org.gcube.portlets.user.td.expressionwidget.shared.rule.type.TDDimensionColumnRuleType;
import org.gcube.portlets.user.td.expressionwidget.shared.rule.type.TDRuleColumnType;
import org.gcube.portlets.user.td.gwtservice.server.trservice.ColumnDataTypeMap;
import org.gcube.portlets.user.td.widgetcommonevent.shared.tr.column.DimensionReferenceData;
/**
*
* @author giancarlo
* email: <a href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
*
*/
public class RuleColumnTypeMap {
public static RuleColumnType map(TDRuleColumnType tdRuleColumnType) {
if (tdRuleColumnType == null) {
return null;
}
if (tdRuleColumnType instanceof TDBaseColumnRuleType) {
TDBaseColumnRuleType tdBaseColumnRuleType = (TDBaseColumnRuleType) tdRuleColumnType;
BaseColumnRuleType baseColumnRuleType = new BaseColumnRuleType(
ColumnDataTypeMap.map(tdBaseColumnRuleType
.getColumnDataType()));
return baseColumnRuleType;
}
if (tdRuleColumnType instanceof TDDimensionColumnRuleType) {
TDDimensionColumnRuleType tdDimensionColumnRuleType = (TDDimensionColumnRuleType) tdRuleColumnType;
TableId tableId = new TableId(
Long.valueOf(tdDimensionColumnRuleType
.getDimensionReferenceData().getTableId()));
ColumnLocalId columnId = new ColumnLocalId(
tdDimensionColumnRuleType.getDimensionReferenceData()
.getColumnId());
DimensionReference dimensionReference = new DimensionReference(
tableId, columnId);
DimensionColumnRuleType dimensionColumnRuleType = new DimensionColumnRuleType(
dimensionReference);
return dimensionColumnRuleType;
}
return null;
}
public static TDRuleColumnType map(RuleColumnType ruleColumnType) {
if (ruleColumnType == null) {
return null;
}
if (ruleColumnType instanceof BaseColumnRuleType) {
BaseColumnRuleType baseColumnRuleType = (BaseColumnRuleType) ruleColumnType;
TDBaseColumnRuleType tdBaseColumnRuleType = new TDBaseColumnRuleType(
ColumnDataTypeMap.map(baseColumnRuleType
.getInternalType()));
return tdBaseColumnRuleType;
}
if (ruleColumnType instanceof DimensionColumnRuleType) {
DimensionColumnRuleType dimensionColumnRuleType = (DimensionColumnRuleType) ruleColumnType;
DimensionReference dimensionReference=(DimensionReference)dimensionColumnRuleType.getInternalType();
DimensionReferenceData dimensionReferenceData = new DimensionReferenceData(
String.valueOf(dimensionReference.getTableId().getValue()), dimensionReference.getColumnId().getValue());
TDDimensionColumnRuleType tdDimensionColumnRuleType = new TDDimensionColumnRuleType(
dimensionReferenceData);
return tdDimensionColumnRuleType;
}
return null;
}
}

View File

@ -1,4 +1,4 @@
package org.gcube.portlets.user.td.expressionwidget.server.service;
package org.gcube.portlets.user.td.expressionwidget.server.service.rule;
import org.gcube.data.analysis.tabulardata.commons.rules.RuleScope;
import org.gcube.portlets.user.td.expressionwidget.shared.rule.RuleScopeType;

View File

@ -2,6 +2,7 @@ package org.gcube.portlets.user.td.expressionwidget.shared.rule;
import java.io.Serializable;
import org.gcube.portlets.user.td.expressionwidget.shared.rule.type.TDRuleColumnType;
import org.gcube.portlets.user.td.widgetcommonevent.shared.expression.C_Expression;
/**
@ -17,6 +18,7 @@ public class RuleDescriptionData implements Serializable {
private String name;
private String description;
private RuleScopeType scope;
private TDRuleColumnType tdRuleColumnType;
private C_Expression expression;
public RuleDescriptionData() {
@ -24,12 +26,27 @@ public class RuleDescriptionData implements Serializable {
}
public RuleDescriptionData(long id, String name, String description,
RuleScopeType scope, C_Expression expression) {
RuleScopeType scope,
C_Expression expression) {
super();
this.id = id;
this.name = name;
this.description = description;
this.scope = scope;
this.tdRuleColumnType = null;
this.expression = expression;
}
public RuleDescriptionData(long id, String name, String description,
RuleScopeType scope, TDRuleColumnType tdRuleColumnType,
C_Expression expression) {
super();
this.id = id;
this.name = name;
this.description = description;
this.scope = scope;
this.tdRuleColumnType = tdRuleColumnType;
this.expression = expression;
}
@ -65,6 +82,14 @@ public class RuleDescriptionData implements Serializable {
this.scope = scope;
}
public TDRuleColumnType getTdRuleColumnType() {
return tdRuleColumnType;
}
public void setTdRuleColumnType(TDRuleColumnType tdRuleColumnType) {
this.tdRuleColumnType = tdRuleColumnType;
}
public C_Expression getExpression() {
return expression;
}
@ -72,21 +97,21 @@ public class RuleDescriptionData implements Serializable {
public void setExpression(C_Expression expression) {
this.expression = expression;
}
public String getReadableExpression(){
if(expression!=null){
public String getReadableExpression() {
if (expression != null) {
return expression.getReadableExpression();
} else {
return "";
}
}
@Override
public String toString() {
return "RuleDescriptionData [id=" + id + ", name=" + name
+ ", description=" + description + ", scope=" + scope
+ ", expression=" + expression + "]";
+ ", tdRuleColumnType=" + tdRuleColumnType + ", expression="
+ expression + "]";
}
}

View File

@ -0,0 +1,41 @@
package org.gcube.portlets.user.td.expressionwidget.shared.rule.type;
import org.gcube.portlets.user.td.widgetcommonevent.shared.tr.column.ColumnDataType;
/**
*
* @author giancarlo
* email: <a href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
*
*/
public class TDBaseColumnRuleType extends TDRuleColumnType {
private static final long serialVersionUID = -2967788094664606371L;
private ColumnDataType columnDataType;
public TDBaseColumnRuleType(){
super();
}
public TDBaseColumnRuleType(ColumnDataType columnDataType) {
super();
this.columnDataType = columnDataType;
}
public ColumnDataType getColumnDataType() {
return columnDataType;
}
public void setColumnDataType(ColumnDataType columnDataType) {
this.columnDataType = columnDataType;
}
@Override
public String toString() {
return "TDBaseColumnRuleType [columnDataType=" + columnDataType + "]";
}
}

View File

@ -0,0 +1,41 @@
package org.gcube.portlets.user.td.expressionwidget.shared.rule.type;
import org.gcube.portlets.user.td.widgetcommonevent.shared.tr.column.DimensionReferenceData;
/**
*
* @author giancarlo email: <a
* href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
*
*/
public class TDDimensionColumnRuleType extends TDRuleColumnType {
private static final long serialVersionUID = -2967788094664606371L;
private DimensionReferenceData dimensionReferenceData;
public TDDimensionColumnRuleType() {
super();
}
public TDDimensionColumnRuleType(
DimensionReferenceData dimensionReferenceData) {
super();
this.dimensionReferenceData = dimensionReferenceData;
}
public DimensionReferenceData getDimensionReferenceData() {
return dimensionReferenceData;
}
public void setDimensionReferenceData(
DimensionReferenceData dimensionReferenceData) {
this.dimensionReferenceData = dimensionReferenceData;
}
@Override
public String toString() {
return "TDDimensionColumnRuleType [dimensionReferenceData="
+ dimensionReferenceData + "]";
}
}

View File

@ -0,0 +1,25 @@
package org.gcube.portlets.user.td.expressionwidget.shared.rule.type;
import java.io.Serializable;
/**
*
* @author giancarlo
* email: <a href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
*
*/
public class TDRuleColumnType implements Serializable {
/**
*
*/
private static final long serialVersionUID = 8230123565752504602L;
public TDRuleColumnType(){
}
}