Added Denormalize

git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/portlets/user/tabular-data-gwt-service@98368 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Giancarlo Panichi 2014-07-03 13:30:54 +00:00
parent 22b62fd345
commit 8aab0d7033
10 changed files with 458 additions and 5 deletions

View File

@ -59,6 +59,8 @@ import org.gcube.portlets.user.td.gwtservice.shared.tr.column.type.ChangeColumnT
import org.gcube.portlets.user.td.gwtservice.shared.tr.column.type.ChangeColumnTypeSession;
import org.gcube.portlets.user.td.gwtservice.shared.tr.groupby.GroupByMonitor;
import org.gcube.portlets.user.td.gwtservice.shared.tr.metadata.TRMetadata;
import org.gcube.portlets.user.td.gwtservice.shared.tr.normalization.DenormalizationMonitor;
import org.gcube.portlets.user.td.gwtservice.shared.tr.normalization.DenormalizationSession;
import org.gcube.portlets.user.td.gwtservice.shared.tr.normalization.NormalizationMonitor;
import org.gcube.portlets.user.td.gwtservice.shared.tr.normalization.NormalizationSession;
import org.gcube.portlets.user.td.gwtservice.shared.tr.open.TDOpenSession;
@ -1025,4 +1027,24 @@ public interface TDGWTService extends RemoteService {
public void startNormalization(NormalizationSession normalizationSession)
throws TDGWTServiceException;
// Denormalization
/**
* Get Operation Monitor during the denormalization operation
*
* @return
* @throws TDGWTServiceException
*/
public DenormalizationMonitor getDenormalizationMonitor()
throws TDGWTServiceException;
/**
* Start Denormalization and invokes the client library
*
* @param denormalizationSession
* @throws TDGWTServiceException
*/
public void startDenormalization(
DenormalizationSession denormalizationSession)
throws TDGWTServiceException;
}

View File

@ -58,6 +58,8 @@ import org.gcube.portlets.user.td.gwtservice.shared.tr.column.type.ChangeColumnT
import org.gcube.portlets.user.td.gwtservice.shared.tr.column.type.ChangeColumnTypeSession;
import org.gcube.portlets.user.td.gwtservice.shared.tr.groupby.GroupByMonitor;
import org.gcube.portlets.user.td.gwtservice.shared.tr.metadata.TRMetadata;
import org.gcube.portlets.user.td.gwtservice.shared.tr.normalization.DenormalizationMonitor;
import org.gcube.portlets.user.td.gwtservice.shared.tr.normalization.DenormalizationSession;
import org.gcube.portlets.user.td.gwtservice.shared.tr.normalization.NormalizationMonitor;
import org.gcube.portlets.user.td.gwtservice.shared.tr.normalization.NormalizationSession;
import org.gcube.portlets.user.td.gwtservice.shared.tr.open.TDOpenSession;
@ -267,6 +269,9 @@ public interface TDGWTServiceAsync {
//Normalization
void getNormalizationMonitor(AsyncCallback<NormalizationMonitor> callback);
void startNormalization(NormalizationSession normalizationSession, AsyncCallback<Void> callback);
//Denormalization
void getDenormalizationMonitor(AsyncCallback<DenormalizationMonitor> callback);
void startDenormalization(DenormalizationSession denormalizationSession, AsyncCallback<Void> callback);
}

View File

@ -56,6 +56,8 @@ import org.gcube.portlets.user.td.gwtservice.shared.tr.column.type.ChangeColumnT
import org.gcube.portlets.user.td.gwtservice.shared.tr.column.type.ChangeColumnTypeSession;
import org.gcube.portlets.user.td.gwtservice.shared.tr.groupby.GroupByMonitor;
import org.gcube.portlets.user.td.gwtservice.shared.tr.groupby.GroupBySession;
import org.gcube.portlets.user.td.gwtservice.shared.tr.normalization.DenormalizationMonitor;
import org.gcube.portlets.user.td.gwtservice.shared.tr.normalization.DenormalizationSession;
import org.gcube.portlets.user.td.gwtservice.shared.tr.normalization.NormalizationMonitor;
import org.gcube.portlets.user.td.gwtservice.shared.tr.normalization.NormalizationSession;
import org.gcube.portlets.user.td.gwtservice.shared.tr.open.TDOpenSession;
@ -1995,6 +1997,75 @@ public class SessionUtil {
httpSession.removeAttribute(SessionConstants.NORMALIZATION_TASK);
httpSession.setAttribute(SessionConstants.NORMALIZATION_TASK, task);
}
//
public static DenormalizationSession getDenormalizationSession(
HttpSession httpSession) {
DenormalizationSession denormalizationSession = (DenormalizationSession) httpSession
.getAttribute(SessionConstants.DENORMALIZATION_SESSION);
if (denormalizationSession != null) {
return denormalizationSession;
} else {
denormalizationSession = new DenormalizationSession();
httpSession
.setAttribute(SessionConstants.DENORMALIZATION_SESSION, denormalizationSession);
return denormalizationSession;
}
}
public static void setDenormalizationSession(HttpSession httpSession,
DenormalizationSession denormalizationSession) {
DenormalizationSession dn = (DenormalizationSession) httpSession
.getAttribute(SessionConstants.DENORMALIZATION_SESSION);
if (dn != null) {
httpSession.removeAttribute(SessionConstants.DENORMALIZATION_SESSION);
}
httpSession.setAttribute(SessionConstants.DENORMALIZATION_SESSION, denormalizationSession);
}
public static DenormalizationMonitor getDenormalizationMonitor(
HttpSession httpSession) {
DenormalizationMonitor denormalizationMonitor = (DenormalizationMonitor) httpSession
.getAttribute(SessionConstants.DENORMALIZATION_MONITOR);
if (denormalizationMonitor != null) {
return denormalizationMonitor;
} else {
denormalizationMonitor = new DenormalizationMonitor();
httpSession
.setAttribute(SessionConstants.DENORMALIZATION_MONITOR, denormalizationMonitor);
return denormalizationMonitor;
}
}
public static void setDeNormalizationMonitor(HttpSession httpSession,
DenormalizationMonitor denormalizationMonitor) {
DenormalizationMonitor dn = (DenormalizationMonitor) httpSession
.getAttribute(SessionConstants.DENORMALIZATION_MONITOR);
if (dn != null) {
httpSession.removeAttribute(SessionConstants.DENORMALIZATION_MONITOR);
}
httpSession.setAttribute(SessionConstants.DENORMALIZATION_MONITOR, denormalizationMonitor);
}
public static Task getDenormalizationTask(HttpSession httpSession) {
Task monitor = (Task) httpSession.getAttribute(SessionConstants.DENORMALIZATION_TASK);
if (monitor == null) {
logger.error("DENORMALIZATION_TASK was not acquired");
}
return monitor;
}
public static void setDenormalizationTask(HttpSession httpSession, Task task) {
Task monitor = (Task) httpSession.getAttribute(SessionConstants.DENORMALIZATION_TASK);
if (monitor != null)
httpSession.removeAttribute(SessionConstants.DENORMALIZATION_TASK);
httpSession.setAttribute(SessionConstants.DENORMALIZATION_TASK, task);
}
}

View File

@ -102,6 +102,7 @@ import org.gcube.portlets.user.td.gwtservice.server.opexecution.OpExecution4Chan
import org.gcube.portlets.user.td.gwtservice.server.opexecution.OpExecution4CodelistMapping;
import org.gcube.portlets.user.td.gwtservice.server.opexecution.OpExecution4DeleteColumn;
import org.gcube.portlets.user.td.gwtservice.server.opexecution.OpExecution4DeleteRows;
import org.gcube.portlets.user.td.gwtservice.server.opexecution.OpExecution4Denormalization;
import org.gcube.portlets.user.td.gwtservice.server.opexecution.OpExecution4Duplicates;
import org.gcube.portlets.user.td.gwtservice.server.opexecution.OpExecution4EditRow;
import org.gcube.portlets.user.td.gwtservice.server.opexecution.OpExecution4ExtractCodelist;
@ -194,6 +195,8 @@ import org.gcube.portlets.user.td.gwtservice.shared.tr.metadata.TRLocalizedText;
import org.gcube.portlets.user.td.gwtservice.shared.tr.metadata.TRMetadata;
import org.gcube.portlets.user.td.gwtservice.shared.tr.metadata.TRNameMetadata;
import org.gcube.portlets.user.td.gwtservice.shared.tr.metadata.TRRightsMetadata;
import org.gcube.portlets.user.td.gwtservice.shared.tr.normalization.DenormalizationMonitor;
import org.gcube.portlets.user.td.gwtservice.shared.tr.normalization.DenormalizationSession;
import org.gcube.portlets.user.td.gwtservice.shared.tr.normalization.NormalizationMonitor;
import org.gcube.portlets.user.td.gwtservice.shared.tr.normalization.NormalizationSession;
import org.gcube.portlets.user.td.gwtservice.shared.tr.open.TDOpenSession;
@ -8204,5 +8207,163 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
}
}
@Override
public void startDenormalization(DenormalizationSession denormalizationSession)
throws TDGWTServiceException {
try {
HttpSession session = this.getThreadLocalRequest().getSession();
SessionUtil.setDenormalizationSession(session, denormalizationSession);
ASLSession aslSession = SessionUtil.getAslSession(session);
if (denormalizationSession == null) {
logger.error("DenormalizationSession is null");
throw new TDGWTServiceException(
"Error in normalization : DenormalizationSession is null");
}
logger.debug("StartDenormalization: " + denormalizationSession);
AuthorizationProvider.instance.set(new AuthorizationToken(
aslSession.getUsername(), aslSession.getScope()));
TabularDataService service = TabularDataServiceFactory.getService();
OpExecution4Denormalization opEx = new OpExecution4Denormalization(service,
denormalizationSession);
OpExecutionDirector director = new OpExecutionDirector();
director.setOperationExecutionBuilder(opEx);
director.constructOperationExecution();
OperationExecution invocation = director.getOperationExecution();
if (invocation == null) {
throw new TDGWTServiceException(
"Error in invocation: Operation not supported");
}
Long id = Long.valueOf(denormalizationSession.getTrId().getId());
TabularResourceId serviceTR = new TabularResourceId(id);
logger.debug("OperationInvocation: \n" + invocation.toString());
Task trTask = service.execute(invocation, serviceTR);
logger.debug("Denormalization start on service: TaskId " + trTask.getId());
SessionUtil.setDenormalizationTask(session, trTask);
return;
} catch (TDGWTSessionExpiredException 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 in start denormalization: "
+ e.getLocalizedMessage());
}
}
@Override
public DenormalizationMonitor getDenormalizationMonitor()
throws TDGWTServiceException {
try {
HttpSession session = this.getThreadLocalRequest().getSession();
DenormalizationSession denormalizationSession = SessionUtil
.getDenormalizationSession(session);
Task task = SessionUtil.getNormalizationTask(session);
DenormalizationMonitor denormalizationMonitor = new DenormalizationMonitor();
if (task == null) {
logger.debug("Task null");
throw new TDGWTServiceException(
"Error in DenormalizationMonitor task null");
} else {
TaskStatus status = task.getStatus();
if (status == null) {
logger.debug("Services TaskStatus : null");
throw new TDGWTServiceException(
"Error in DenormalizationMonitor Status null");
} else {
logger.debug("Services TaskStatus: " + task.getStatus());
denormalizationMonitor
.setStatus(TaskStateMap.map(task.getStatus()));
TRId trId;
TabResource tabResource;
switch (denormalizationMonitor.getStatus()) {
case FAILED:
if (task.getResult() != null) {
logger.debug("Task exception:"
+ task.getErrorCause());
task.getErrorCause().printStackTrace();
denormalizationMonitor.setError(new Throwable(task
.getErrorCause()));
} else {
logger.debug("Task exception: Error In DenormalizationMonitor");
denormalizationMonitor.setError(new Throwable(
"Error task resume"));
}
denormalizationMonitor.setProgress(task.getProgress());
break;
case SUCCEDED:
logger.debug("Task Result:" + task.getResult());
denormalizationMonitor.setProgress(task.getProgress());
trId = new TRId();
trId.setId(denormalizationSession.getTrId().getId());
trId = retrieveTabularResourceBasicData(trId);
denormalizationMonitor.setTrId(trId);
tabResource = SessionUtil.getTabResource(session);
tabResource.setTrId(trId);
SessionUtil.setTabResource(session, tabResource);
SessionUtil.setTRId(session, trId);
break;
case IN_PROGRESS:
denormalizationMonitor.setProgress(task.getProgress());
break;
case VALIDATING_RULES:
denormalizationMonitor.setProgress(task.getProgress());
break;
case GENERATING_VIEW:
break;
case ABORTED:
break;
case STOPPED:
logger.debug("Task Result:" + task.getResult());
denormalizationMonitor.setProgress(task.getProgress());
trId = retrieveTabularResourceBasicData(denormalizationSession
.getTrId());
denormalizationMonitor.setTrId(trId);
tabResource = SessionUtil.getTabResource(session);
tabResource.setTrId(trId);
SessionUtil.setTabResource(session, tabResource);
SessionUtil.setTRId(session, trId);
break;
case INITIALIZING:
break;
default:
break;
}
}
SessionUtil.setDenormalizationTask(session, task);
}
logger.debug("DenormalizationMonitor(): " + denormalizationMonitor);
return denormalizationMonitor;
} catch (TDGWTSessionExpiredException e) {
throw e;
} catch (Throwable e) {
logger.debug("Error in DenormalizationMonitor: " + e.getLocalizedMessage());
e.printStackTrace();
throw new TDGWTServiceException("Error: " + e.getLocalizedMessage());
}
}
}

View File

@ -0,0 +1,99 @@
package org.gcube.portlets.user.td.gwtservice.server.opexecution;
import java.util.HashMap;
import java.util.Map;
import org.gcube.data.analysis.tabulardata.commons.webservice.types.operations.OperationDefinition;
import org.gcube.data.analysis.tabulardata.commons.webservice.types.operations.OperationExecution;
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.table.TableId;
import org.gcube.data.analysis.tabulardata.service.TabularDataService;
import org.gcube.portlets.user.td.gwtservice.server.trservice.OperationDefinitionMap;
import org.gcube.portlets.user.td.gwtservice.shared.Constants;
import org.gcube.portlets.user.td.gwtservice.shared.OperationsId;
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.normalization.DenormalizationSession;
import org.gcube.portlets.user.td.widgetcommonevent.shared.TRId;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* Operation Execution for Denormalization
*
* @author "Giancarlo Panichi" email: <a
* href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
*
*/
public class OpExecution4Denormalization extends OpExecutionBuilder {
protected static Logger logger = LoggerFactory
.getLogger(OpExecution4Denormalization.class);
private TabularDataService service;
private DenormalizationSession denormalizationSession;
public OpExecution4Denormalization(TabularDataService service,
DenormalizationSession denormalizationSession) {
this.service = service;
this.denormalizationSession = denormalizationSession;
}
@Override
public void buildOpEx() throws TDGWTServiceException {
OperationExecution invocation = null;
logger.debug(denormalizationSession.toString());
OperationDefinition operationDefinition;
Map<String, Object> map = new HashMap<String, Object>();
TRId trId = denormalizationSession.getTrId();
logger.debug("trID: " + trId);
if(trId==null){
logger.error("Error in DenormalizationSession: trId is null");
throw new TDGWTServiceException("No tabular resource set");
}
long tabId;
if(trId.isViewTable()){
tabId = new Long(trId.getReferenceTargetTableId());
} else {
tabId = new Long(trId.getTableId());
}
TableId tId = new TableId(tabId);
ColumnData valueCol=denormalizationSession.getValueColumn();
logger.debug("Value Column: "+valueCol);
if(valueCol==null){
logger.error("Error in DenormalizationSession: Value Column is null");
throw new TDGWTServiceException("No value column set");
}
ColumnLocalId valueId = new ColumnLocalId(valueCol.getColumnId());
ColumnReference valueColumnReference = new ColumnReference(tId, valueId);
ColumnData attributeCol=denormalizationSession.getAttributeColumn();
logger.debug("Attribute Column: "+valueCol);
if(attributeCol==null){
logger.error("Error in DenormalizationSession: Attribute Column is null");
throw new TDGWTServiceException("No attribute column set");
}
ColumnLocalId attributeId = new ColumnLocalId(attributeCol.getColumnId());
ColumnReference attributeColumnReference = new ColumnReference(tId, attributeId);
operationDefinition = OperationDefinitionMap.map(
OperationsId.Denormalize.toString(), service);
map.put(Constants.PARAMETER_DENORMALIZATION_VALUE_COLUMN, valueColumnReference);
map.put(Constants.PARAMETER_DENORMALIZATION_ATTRIBUTE_COLUMN, attributeColumnReference);
invocation = new OperationExecution(
operationDefinition.getOperationId(), map);
operationExecutionSpec.setOp(invocation);
}
}

View File

@ -22,7 +22,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* Operation Execution for duplicates
* Operation Execution for Normalization
*
* @author "Giancarlo Panichi" email: <a
* href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>

View File

@ -86,5 +86,8 @@ public class Constants {
public static final String PARAMETER_NORMALIZATION_NORM_LABEL = "norm_label";
public static final String PARAMETER_NORMALIZATION_QUANT_LABEL = "quant_label";
public static final String PARAMETER_DENORMALIZATION_VALUE_COLUMN = "value_column";
public static final String PARAMETER_DENORMALIZATION_ATTRIBUTE_COLUMN = "attribute_column";
}

View File

@ -0,0 +1,21 @@
package org.gcube.portlets.user.td.gwtservice.shared.tr.normalization;
import java.io.Serializable;
import org.gcube.portlets.user.td.gwtservice.shared.OperationMonitor;
/**
*
* @author "Giancarlo Panichi"
* email: <a href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
*
*/
public class DenormalizationMonitor extends OperationMonitor implements
Serializable {
private static final long serialVersionUID = -1943471748865606817L;
}

View File

@ -0,0 +1,74 @@
package org.gcube.portlets.user.td.gwtservice.shared.tr.normalization;
import java.io.Serializable;
import org.gcube.portlets.user.td.gwtservice.shared.tr.ColumnData;
import org.gcube.portlets.user.td.widgetcommonevent.shared.TRId;
/**
*
* @author "Giancarlo Panichi"
* email: <a href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
*
*/
public class DenormalizationSession implements Serializable {
private static final long serialVersionUID = 4139331553059193758L;
protected TRId trId;
protected ColumnData valueColumn;
protected ColumnData attributeColumn;
public DenormalizationSession() {
}
/**
*
* @param trId
* @param valueColumn
* @param attributeColumn
*/
public DenormalizationSession(TRId trId, ColumnData valueColumn,
ColumnData attributeColumn ) {
this.trId = trId;
this.valueColumn = valueColumn;
this.attributeColumn = attributeColumn;
}
public TRId getTrId() {
return trId;
}
public void setTrId(TRId trId) {
this.trId = trId;
}
public ColumnData getValueColumn() {
return valueColumn;
}
public void setValueColumn(ColumnData valueColumn) {
this.valueColumn = valueColumn;
}
public ColumnData getAttributeColumn() {
return attributeColumn;
}
public void setAttributeColumn(ColumnData attributeColumn) {
this.attributeColumn = attributeColumn;
}
@Override
public String toString() {
return "DenormalizationSession [trId=" + trId + ", valueColumn="
+ valueColumn + ", attributeColumn=" + attributeColumn + "]";
}
}

View File

@ -17,9 +17,6 @@ public class NormalizationSession implements Serializable {
private static final long serialVersionUID = 4139331553059193758L;
public enum DuplicateOp {
VALIDATE, DELETE;
}
protected TRId trId;
protected ArrayList<ColumnData> columns;