From 1ae219d7e13618577ab115fa2a94929be2bbf69f Mon Sep 17 00:00:00 2001 From: Giancarlo Panichi Date: Fri, 4 Apr 2014 14:02:44 +0000 Subject: [PATCH] Added getValidationColumns() git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/portlets/user/tabular-data-gwt-service@94356 82a268e6-3cf1-43bd-a215-b396298e98cf --- .../gwtservice/client/rpc/TDGWTService.java | 29 +++- .../client/rpc/TDGWTServiceAsync.java | 25 +--- .../gwtservice/server/TDGWTServiceImpl.java | 133 ++++++++++++++++-- .../td/gwtservice/shared/tr/ColumnData.java | 54 +++++-- 4 files changed, 192 insertions(+), 49 deletions(-) diff --git a/src/main/java/org/gcube/portlets/user/td/gwtservice/client/rpc/TDGWTService.java b/src/main/java/org/gcube/portlets/user/td/gwtservice/client/rpc/TDGWTService.java index 2702012..0e327b1 100644 --- a/src/main/java/org/gcube/portlets/user/td/gwtservice/client/rpc/TDGWTService.java +++ b/src/main/java/org/gcube/portlets/user/td/gwtservice/client/rpc/TDGWTService.java @@ -85,7 +85,9 @@ public interface TDGWTService extends RemoteService { * @throws TDGWTServiceException */ public String hello() throws TDGWTServiceException; - + + + //TabularResource /** * Get informations on the current tabular resource * @@ -111,6 +113,18 @@ public interface TDGWTService extends RemoteService { */ public TabResource getTabResourceInformation(TRId trId) throws TDGWTServiceException; + + /** + * Return true if is a valid tabular resource + * + * @param trId + * @return + * @throws TDGWTServiceException + */ + public Boolean isTabularResourceValid(TRId trId) + throws TDGWTServiceException; + + /** * Get creation date on tabular resource @@ -177,16 +191,21 @@ public interface TDGWTService extends RemoteService { public ArrayList getTRMetadata(TRId trId) throws TDGWTServiceException; + + /** - * Return true if is a valid tabular resource + * Returns ArrayList that contains all the validation columns of columnName * * @param trId + * @param columnName * @return * @throws TDGWTServiceException */ - public Boolean isTabularResourceValid(TRId trId) - throws TDGWTServiceException; - + public ArrayList getValidationColumns(TRId trId, String columnName) + throws TDGWTServiceException; + + + // Share /** * Retrieves information sharing on the tabular resource diff --git a/src/main/java/org/gcube/portlets/user/td/gwtservice/client/rpc/TDGWTServiceAsync.java b/src/main/java/org/gcube/portlets/user/td/gwtservice/client/rpc/TDGWTServiceAsync.java index 44d4ef6..5779601 100644 --- a/src/main/java/org/gcube/portlets/user/td/gwtservice/client/rpc/TDGWTServiceAsync.java +++ b/src/main/java/org/gcube/portlets/user/td/gwtservice/client/rpc/TDGWTServiceAsync.java @@ -71,41 +71,26 @@ public interface TDGWTServiceAsync { void hello(AsyncCallback callback); + //TabularResource void createTabularResource(TabResource tabResource,AsyncCallback callback); - + void removeTabularResource(TRId trId, AsyncCallback callback); + void isTabularResourceValid(TRId trId,AsyncCallback callback); void getTabResourceInformation(AsyncCallback callback); - - void getTabResourceInformation(TRId trId,AsyncCallback callback); - + void getTabResourceInformation(TRId trId,AsyncCallback callback); void setTabResourceInformation(TabResource tabResource, AsyncCallback callback); - void getTRCreationDate(TRId trId,AsyncCallback callback); - void setTabResource(TabResource tabResource, AsyncCallback callback); - void getTabularResources(AsyncCallback> callback); - void getTabularResourcesAndLastTables(AsyncCallback> callback); - void getLastTable(TRId trId, AsyncCallback callback); - void getTable(TRId trId, AsyncCallback callback); - void getTableMetadata(TRId trId, AsyncCallback> callback); - void getTRMetadata(TRId trId, AsyncCallback> callback); - void getColumns(AsyncCallback> callback); - void getColumns(TRId trId, AsyncCallback> callback); - void getColumnsForDimension(TRId trId, AsyncCallback> callback); - void getColumn(TRId trId, String columnName, AsyncCallback callback); - - void removeTabularResource(TRId trId, AsyncCallback callback); - - void isTabularResourceValid(TRId trId,AsyncCallback callback); + void getValidationColumns(TRId trId, String columnName, AsyncCallback> callback); //Share void getShareInfo(TRId trId, AsyncCallback callback); diff --git a/src/main/java/org/gcube/portlets/user/td/gwtservice/server/TDGWTServiceImpl.java b/src/main/java/org/gcube/portlets/user/td/gwtservice/server/TDGWTServiceImpl.java index fe7688a..1f8e6c6 100644 --- a/src/main/java/org/gcube/portlets/user/td/gwtservice/server/TDGWTServiceImpl.java +++ b/src/main/java/org/gcube/portlets/user/td/gwtservice/server/TDGWTServiceImpl.java @@ -52,6 +52,7 @@ import org.gcube.data.analysis.tabulardata.model.column.type.DimensionColumnType import org.gcube.data.analysis.tabulardata.model.column.type.IdColumnType; import org.gcube.data.analysis.tabulardata.model.column.type.TimeDimensionColumnType; import org.gcube.data.analysis.tabulardata.model.column.type.ValidationColumnType; +import org.gcube.data.analysis.tabulardata.model.metadata.column.ValidationReferencesMetadata; import org.gcube.data.analysis.tabulardata.model.metadata.column.ViewColumnMetadata; import org.gcube.data.analysis.tabulardata.model.metadata.common.DescriptionsMetadata; import org.gcube.data.analysis.tabulardata.model.metadata.common.ImmutableLocalizedText; @@ -601,6 +602,105 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements } } + /** + * + * {@inheritDoc} + */ + public ArrayList getValidationColumns(TRId trId, + String columnName) throws TDGWTServiceException { + try { + HttpSession session = this.getThreadLocalRequest().getSession(); + ASLSession aslSession = SessionUtil.getAslSession(session); + + AuthorizationProvider.instance.set(new AuthorizationToken( + aslSession.getUsername())); + TabularDataService service = TabularDataServiceFactory.getService(); + + logger.debug("getValidationColumns():[" + trId.toString()+" columnName: "+columnName+"]"); + + Table table = service.getTable(new TableId(Long.valueOf(trId + .getTableId()))); + + Column columnSource=table.getColumnByName(columnName); + if(columnSource==null){ + logger.error("Column not present on table"); + throw new TDGWTServiceException("Column not present on table"); + } + + logger.debug("getValidationColumns(): columnSource ColumnLocalId "+columnSource.getLocalId()); + String columnSourceId=columnSource.getLocalId().getValue(); + + ArrayList columns = new ArrayList(); + + List cols = table.getColumns(); + int i = 0; + for (Column c : cols) { + if (c.getColumnType() instanceof ValidationColumnType) { + if (c.contains(ValidationReferencesMetadata.class)) { + ValidationReferencesMetadata validationReferenceMetadata = c + .getMetadata(ValidationReferencesMetadata.class); + List valColumnList=validationReferenceMetadata.getValidationReferenceColumn(); + for(ColumnLocalId columnLocalId:valColumnList){ + if(columnLocalId.getValue().compareTo(columnSourceId)==0){ + ColumnData cData = new ColumnData(); + cData.setId(Integer.toString(i)); + cData.setColumnId(c.getLocalId().getValue()); + cData.setName(c.getName()); + cData.setTypeCode(c.getColumnType().getCode()); + cData.setTypeName(c.getColumnType().getName()); + cData.setDataTypeName(c.getDataType().getName()); + NamesMetadata labelsMetadata = null; + try { + labelsMetadata = c.getMetadata(NamesMetadata.class); + } catch (NoSuchMetadataException e) { + logger.debug("labelMetadata: NoSuchMetadataException " + + e.getLocalizedMessage()); + } + + if (labelsMetadata == null) { + cData.setLabel("nolabel"); + logger.debug("LabelsMetadata no labels"); + } else { + LocalizedText cl = null; + cl = labelsMetadata.getTextWithLocale("en"); + if (cl == null) { + cData.setLabel("nolabel"); + logger.debug("ColumnLabel no label in en"); + } else { + cData.setLabel(cl.getValue()); + logger.debug("Column Set Label: " + + cl.getValue()); + } + } + cData.setTrId(trId); + cData.setValidationColumn(true); + ArrayList validatedColumnReferences= new ArrayList(); + for(ColumnLocalId cLocalId:valColumnList){ + validatedColumnReferences.add(cLocalId.getValue()); + } + cData.setValidatedColumnReferences(validatedColumnReferences); + columns.add(cData); + i++; + break; + } + } + + + } + } + + } + logger.debug("Validation Column: "+columns.size()); + return columns; + + } catch (Throwable e) { + logger.error( + "Error retrieving Validation Columns: " + e.getLocalizedMessage(), e); + throw new TDGWTServiceException("Error retrieving Validation Columns: " + + e.getLocalizedMessage()); + } + } + /** * * {@inheritDoc} @@ -4741,8 +4841,8 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements * {@inheritDoc} */ @Override - public ArrayList getOccurrencesForBatchReplace(ColumnData column) - throws TDGWTServiceException { + public ArrayList getOccurrencesForBatchReplace( + ColumnData column) throws TDGWTServiceException { try { HttpSession session = this.getThreadLocalRequest().getSession(); ASLSession aslSession = SessionUtil.getAslSession(session); @@ -5154,7 +5254,7 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements Long.valueOf(replaceBatchColumnSession.getTrId().getId())); logger.debug("OperationInvocation: \n" + invocations.toString()); Task trTask = service.executeBatch(invocations, serviceTRId); - if(trTask==null){ + if (trTask == null) { logger.error("Error on service Task null"); throw new TDGWTServiceException("Task not started"); } @@ -5208,18 +5308,20 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements if (task.getResult() != null) { logger.debug("Task exception:" + task.getErrorCause()); - replaceBatchColumnMonitor.setError(new Throwable(task - .getErrorCause())); + replaceBatchColumnMonitor.setError(new Throwable( + task.getErrorCause())); } else { logger.debug("Task exception: Error In ReplaceBatchColumnMonitor"); replaceBatchColumnMonitor.setError(new Throwable( "Error replacing the Column value")); } - replaceBatchColumnMonitor.setProgress(task.getProgress()); + replaceBatchColumnMonitor.setProgress(task + .getProgress()); break; case SUCCEDED: logger.debug("Task Result:" + task.getResult()); - replaceBatchColumnMonitor.setProgress(task.getProgress()); + replaceBatchColumnMonitor.setProgress(task + .getProgress()); trId = new TRId(); trId.setId(replaceBatchColumnSession.getTrId().getId()); @@ -5232,16 +5334,19 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements SessionUtil.setTRId(session, trId); break; case IN_PROGRESS: - replaceBatchColumnMonitor.setProgress(task.getProgress()); + replaceBatchColumnMonitor.setProgress(task + .getProgress()); break; case VALIDATING_RULES: - replaceBatchColumnMonitor.setProgress(task.getProgress()); + replaceBatchColumnMonitor.setProgress(task + .getProgress()); break; case ABORTED: break; case STOPPED: logger.debug("Task Result:" + task.getResult()); - replaceBatchColumnMonitor.setProgress(task.getProgress()); + replaceBatchColumnMonitor.setProgress(task + .getProgress()); trId = new TRId(); trId.setId(replaceBatchColumnSession.getColumnData() .getTrId().getId()); @@ -5263,15 +5368,15 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements SessionUtil.setReplaceBatchColumnTask(session, task); } - logger.info("ReplaceBatchColumnMonitor(): " + replaceBatchColumnMonitor); + logger.info("ReplaceBatchColumnMonitor(): " + + replaceBatchColumnMonitor); return replaceBatchColumnMonitor; } catch (Throwable e) { logger.debug("Error in ReplaceBatchColumnMonitor: " + e.getLocalizedMessage()); e.printStackTrace(); - throw new TDGWTServiceException( - "Error in replace batch: " - + e.getLocalizedMessage()); + throw new TDGWTServiceException("Error in replace batch: " + + e.getLocalizedMessage()); } diff --git a/src/main/java/org/gcube/portlets/user/td/gwtservice/shared/tr/ColumnData.java b/src/main/java/org/gcube/portlets/user/td/gwtservice/shared/tr/ColumnData.java index 7e3658a..fbccab7 100644 --- a/src/main/java/org/gcube/portlets/user/td/gwtservice/shared/tr/ColumnData.java +++ b/src/main/java/org/gcube/portlets/user/td/gwtservice/shared/tr/ColumnData.java @@ -1,6 +1,7 @@ package org.gcube.portlets.user.td.gwtservice.shared.tr; import java.io.Serializable; +import java.util.ArrayList; import org.gcube.portlets.user.td.widgetcommonevent.shared.TRId; @@ -15,7 +16,7 @@ public class ColumnData implements Serializable { private static final long serialVersionUID = 7614033455605898209L; protected String id; // For insert in table only - protected String columnId; //Id of column on server + protected String columnId; // Id of column on server protected String name; protected String typeName; protected String typeCode; @@ -24,6 +25,14 @@ public class ColumnData implements Serializable { protected TRId trId; protected boolean viewColumn; protected ColumnViewData columnViewData; + + // validation columns that validate this column + protected ArrayList validationColumnReferences; + + // true if this is a validation column + protected boolean validationColumn; + // if this is a validation column then contains the columns validated + protected ArrayList validatedColumnReferences; public String getColumnId() { return columnId; @@ -32,7 +41,7 @@ public class ColumnData implements Serializable { public void setColumnId(String columnId) { this.columnId = columnId; } - + public String getName() { return name; } @@ -80,7 +89,7 @@ public class ColumnData implements Serializable { public void setDataTypeName(String dataTypeName) { this.dataTypeName = dataTypeName; } - + public String getLabel() { return label; } @@ -96,7 +105,7 @@ public class ColumnData implements Serializable { public void setColumnViewData(ColumnViewData columnViewData) { this.columnViewData = columnViewData; } - + public boolean isViewColumn() { return viewColumn; } @@ -105,18 +114,43 @@ public class ColumnData implements Serializable { this.viewColumn = viewColumn; } + public boolean isValidationColumn() { + return validationColumn; + } + + public void setValidationColumn(boolean validationColumn) { + this.validationColumn = validationColumn; + } + + public ArrayList getValidatedColumnReferences() { + return validatedColumnReferences; + } + + public void setValidatedColumnReferences( + ArrayList validatedColumnReferences) { + this.validatedColumnReferences = validatedColumnReferences; + } + + public ArrayList getValidationColumnReferences() { + return validationColumnReferences; + } + + public void setValidationColumnReferences( + ArrayList validationColumnReferences) { + this.validationColumnReferences = validationColumnReferences; + } + @Override public String toString() { return "ColumnData [id=" + id + ", columnId=" + columnId + ", name=" + name + ", typeName=" + typeName + ", typeCode=" + typeCode + ", dataTypeName=" + dataTypeName + ", label=" + label + ", trId=" + trId + ", viewColumn=" + viewColumn - + ", columnViewData=" + columnViewData + "]"; + + ", columnViewData=" + columnViewData + + ", validationColumnReferences=" + validationColumnReferences + + ", validationColumn=" + validationColumn + + ", validatedColumnReferences=" + validatedColumnReferences + + "]"; } - - - - - }