Added the sharing of rules

git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/portlets/user/tabular-data-expression-widget@114328 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Giancarlo Panichi 2015-04-22 12:19:33 +00:00
parent ad279aa428
commit 5f2e145e3d
4 changed files with 80 additions and 98 deletions

View File

@ -488,7 +488,7 @@ public class ColumnExpressionPanel extends FramedPanel {
columnMockUp.getColumnDataType());
RuleDescriptionData ruleDescriptionData = new RuleDescriptionData(
0, ruleNameS, ruleDescriptionS, null,
0, ruleNameS, ruleDescriptionS, null, null,
RuleScopeType.COLUMN, tdBaseColumnRule, exp);
return ruleDescriptionData;
} else {

View File

@ -1,6 +1,5 @@
package org.gcube.portlets.user.td.expressionwidget.server;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.List;
@ -30,15 +29,13 @@ import org.gcube.portlets.user.td.gwtservice.server.TDGWTServiceImpl;
import org.gcube.portlets.user.td.gwtservice.server.trservice.ColumnDataTypeMap;
import org.gcube.portlets.user.td.gwtservice.shared.exception.TDGWTServiceException;
import org.gcube.portlets.user.td.gwtservice.shared.rule.AppliedRulesResponseData;
import org.gcube.portlets.user.td.gwtservice.shared.rule.ApplyColumnRulesSession;
import org.gcube.portlets.user.td.gwtservice.shared.rule.RuleDescriptionData;
import org.gcube.portlets.user.td.gwtservice.shared.rule.RuleScopeType;
import org.gcube.portlets.user.td.gwtservice.shared.rule.ApplyColumnRulesSession;
import org.gcube.portlets.user.td.gwtservice.shared.rule.type.TDRuleColumnType;
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.ColumnData;
import org.gcube.portlets.user.td.widgetcommonevent.shared.tr.column.ColumnDataType;
import org.gcube.portlets.user.td.widgetcommonevent.shared.tr.column.ColumnMockUp;
@ -58,11 +55,12 @@ public class ExpressionServiceImpl extends TDGWTServiceImpl implements
private static final long serialVersionUID = 4632292751581364137L;
protected static Logger logger = LoggerFactory
private static Logger logger = LoggerFactory
.getLogger(ExpressionServiceImpl.class);
protected static SimpleDateFormat sdf = new SimpleDateFormat(
"yyyy-MM-dd HH:mm");
//private static SimpleDateFormat sdf = new SimpleDateFormat(
// "yyyy-MM-dd HH:mm");
/**
*
@ -238,26 +236,18 @@ public class ExpressionServiceImpl extends TDGWTServiceImpl implements
TabularDataService service = TabularDataServiceFactory.getService();
List<RuleDescription> rules = service.getRules();
logger.debug("Service Rules: "+((rules==null)?"null":rules.size()));
ArrayList<RuleDescriptionData> rulesDes = new ArrayList<RuleDescriptionData>();
C_ExpressionParser parser = new C_ExpressionParser();
for (RuleDescription ruleDescription : rules) {
Expression serviceExpression = ruleDescription.getRule();
C_Expression cexp = parser.parse(serviceExpression);
TDRuleColumnType tdRuleColumnType = RuleColumnTypeMap
.map(ruleDescription.getRuleColumnType());
RuleDescriptionData ruleData = new RuleDescriptionData(
ruleDescription.getId(), ruleDescription.getName(),
ruleDescription.getDescription(),
ruleDescription.getOwner(),
RuleScopeMap.map(ruleDescription.getScope()),
tdRuleColumnType, cexp);
RuleDescriptionData ruleData = RuleDescriptionMap
.map(ruleDescription);
logger.debug("Rule: " + ruleData);
rulesDes.add(ruleData);
}
logger.debug("Rules: "+rulesDes.size());
return rulesDes;
} catch (TDGWTServiceException e) {
@ -275,7 +265,9 @@ public class ExpressionServiceImpl extends TDGWTServiceImpl implements
}
}
/**
*
* {@inheritDoc}
@ -287,34 +279,25 @@ public class ExpressionServiceImpl extends TDGWTServiceImpl implements
HttpSession session = this.getThreadLocalRequest().getSession();
ASLSession aslSession = SessionUtil.getAslSession(session);
logger.debug("GetRules()");
logger.debug("GetRules(): "+scope);
AuthorizationProvider.instance.set(new AuthorizationToken(
aslSession.getUsername(), aslSession.getScope()));
TabularDataService service = TabularDataServiceFactory.getService();
List<RuleDescription> rules = service.getRulesByScope(RuleScopeMap
.map(scope));
logger.debug("Service Rules: "+((rules==null)?"null":rules.size()));
ArrayList<RuleDescriptionData> rulesDes = new ArrayList<RuleDescriptionData>();
C_ExpressionParser parser = new C_ExpressionParser();
for (RuleDescription ruleDescription : rules) {
Expression serviceExpression = ruleDescription.getRule();
C_Expression cexp = parser.parse(serviceExpression);
TDRuleColumnType tdRuleColumnType = RuleColumnTypeMap
.map(ruleDescription.getRuleColumnType());
RuleDescriptionData ruleData = new RuleDescriptionData(
ruleDescription.getId(), ruleDescription.getName(),
ruleDescription.getDescription(),
ruleDescription.getOwner(),
RuleScopeMap.map(ruleDescription.getScope()),
tdRuleColumnType, cexp);
logger.info("Rule: " + ruleData);
RuleDescriptionData ruleData = RuleDescriptionMap
.map(ruleDescription);
logger.debug("Rule: " + ruleData);
rulesDes.add(ruleData);
}
logger.debug("Rules: "+rulesDes.size());
return rulesDes;
} catch (TDGWTServiceException e) {
@ -375,11 +358,11 @@ public class ExpressionServiceImpl extends TDGWTServiceImpl implements
for (RuleDescription ruleDescription : rules) {
RuleDescriptionData ruleData = RuleDescriptionMap
.map(ruleDescription);
logger.debug("Rule:" + ruleData);
rulesDes.add(ruleData);
logger.info("Rule:" + ruleData);
}
logger.debug("Rules: "+rulesDes.size());
return rulesDes;
} catch (TDGWTServiceException e) {
@ -590,57 +573,6 @@ public class ExpressionServiceImpl extends TDGWTServiceImpl implements
}
/**
* Retrieve and set Tabular Resource Type
*
* @param trId
* @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()); } }
*/
}

View File

@ -2,6 +2,9 @@ package org.gcube.portlets.user.td.expressionwidget.server.service.rule;
import java.util.ArrayList;
import java.util.List;
import org.gcube.data.analysis.tabulardata.commons.webservice.types.RuleDescription;
import org.gcube.data.analysis.tabulardata.expression.Expression;
import org.gcube.portlets.user.td.expressionwidget.server.C_ExpressionParser;
@ -9,6 +12,7 @@ import org.gcube.portlets.user.td.expressionwidget.shared.exception.ExpressionPa
import org.gcube.portlets.user.td.gwtservice.shared.exception.TDGWTServiceException;
import org.gcube.portlets.user.td.gwtservice.shared.rule.RuleDescriptionData;
import org.gcube.portlets.user.td.gwtservice.shared.rule.type.TDRuleColumnType;
import org.gcube.portlets.user.td.gwtservice.shared.share.Contacts;
import org.gcube.portlets.user.td.widgetcommonevent.shared.expression.C_Expression;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -21,9 +25,11 @@ import org.slf4j.LoggerFactory;
*
*/
public class RuleDescriptionMap {
private static Logger logger = LoggerFactory
private static final Logger logger = LoggerFactory
.getLogger(RuleDescriptionMap.class);
private static final String SECURITY_EXCEPTION_RIGHTS = "Security exception, you don't have the required rights!";
public static RuleDescriptionData map(RuleDescription ruleDescription)
throws TDGWTServiceException, ExpressionParserException {
@ -64,7 +70,8 @@ public class RuleDescriptionMap {
private static RuleDescriptionData createColumnRule(
RuleDescription ruleDescription) throws ExpressionParserException {
RuleDescription ruleDescription) throws ExpressionParserException,
TDGWTServiceException {
Expression serviceExpression = ruleDescription.getRule();
@ -73,14 +80,57 @@ public class RuleDescriptionMap {
C_Expression cexp = parser.parse(serviceExpression);
TDRuleColumnType tdRuleColumnType = RuleColumnTypeMap
.map(ruleDescription.getRuleColumnType());
Contacts owner = new Contacts("", ruleDescription.getOwner(), false);
ArrayList<Contacts> contacts=retrieveRuleShareInfo(ruleDescription);
RuleDescriptionData ruleData = new RuleDescriptionData(
ruleDescription.getId(), ruleDescription.getName(),
ruleDescription.getDescription(),
ruleDescription.getOwner(),
owner, contacts,
RuleScopeMap.map(ruleDescription.getScope()),
tdRuleColumnType, cexp);
return ruleData;
}
private static ArrayList<Contacts> retrieveRuleShareInfo(
RuleDescription ruleDescription)
throws TDGWTServiceException {
try {
ArrayList<Contacts> contacts = new ArrayList<Contacts>();
List<String> sharedWithUsers = ruleDescription
.getSharedWithUsers();
logger.debug("Shared with Users: " + sharedWithUsers);
if (sharedWithUsers != null) {
for (String user : sharedWithUsers) {
Contacts cont = new Contacts(user, user, false);
contacts.add(cont);
}
}
List<String> sharedWithGroups = ruleDescription
.getSharedWithGroups();
logger.debug("Shared with Groups: " + sharedWithUsers);
if (sharedWithGroups != null) {
for (String group : sharedWithGroups) {
Contacts cont = new Contacts(group, group, true);
contacts.add(cont);
}
}
return contacts;
} catch (SecurityException e) {
e.printStackTrace();
throw new TDGWTServiceException(SECURITY_EXCEPTION_RIGHTS);
} catch (Throwable e) {
e.printStackTrace();
throw new TDGWTServiceException("Error in retrieveShareInfo: "
+ e.getLocalizedMessage());
}
}
}

View File

@ -25,7 +25,7 @@ public interface RuleDescriptionDataProperties extends PropertyAccess<RuleDescr
ValueProvider<RuleDescriptionData, String> name();
ValueProvider<RuleDescriptionData, String> scopeLabel();
ValueProvider<RuleDescriptionData, String> description();
ValueProvider<RuleDescriptionData, String> owner();
ValueProvider<RuleDescriptionData, String> ownerLogin();
ValueProvider<RuleDescriptionData, String> readableExpression();