Minor Update

git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/portlets/user/tabular-data-gwt-service@93298 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Giancarlo Panichi 2014-03-18 17:12:19 +00:00
parent 1be2753732
commit c61aefafac
5 changed files with 92 additions and 16 deletions

View File

@ -99,7 +99,13 @@
<classifier>sources</classifier>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>20090211</version>
</dependency>
<dependency>
<groupId>org.gcube.data.publishing</groupId>
<artifactId>sdmx-registry-client-gcube</artifactId>

View File

@ -47,7 +47,6 @@ import org.gcube.portlets.user.td.gwtservice.shared.tr.type.Codelist;
import org.gcube.portlets.user.td.gwtservice.shared.tr.type.Dataset;
import org.gcube.portlets.user.td.widgetcommonevent.shared.TRId;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.rpc.RemoteService;
import com.google.gwt.user.client.rpc.RemoteServiceRelativePath;

View File

@ -3491,6 +3491,72 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
}
public ArrayList<ColumnData> getColumnsForDimension(TRId trId,
ASLSession aslSession) throws TDGWTServiceException {
try {
AuthorizationProvider.instance.set(new AuthorizationToken(
aslSession.getUsername()));
TabularDataService service = TabularDataServiceFactory.getService();
logger.debug("getColumnsForDimension():" + trId.toString());
Table table = service.getTable(new TableId(Long.valueOf(trId
.getTableId())));
ArrayList<ColumnData> columns = new ArrayList<ColumnData>();
List<Column> cols = table.getColumns();
int i = 0;
for (Column c : cols) {
ColumnType ctype = c.getColumnType();
if (ctype instanceof CodeColumnType
|| ctype instanceof CodeNameColumnType) {
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);
columns.add(cData);
i++;
}
}
return columns;
} catch (Exception e) {
logger.error(
"Error in getColumnsForDimension() retrieving Columns: "
+ e.getLocalizedMessage(), e);
throw new TDGWTServiceException("Error retrieving Columns: "
+ e.getLocalizedMessage());
}
}
/**
*
* {@inheritDoc}
@ -3992,8 +4058,7 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
}
@Override
public ArrayList<Occurences> getOccurencesForBatchReplace(
ColumnData column)
public ArrayList<Occurences> getOccurencesForBatchReplace(ColumnData column)
throws TDGWTServiceException {
try {
HttpSession session = this.getThreadLocalRequest().getSession();
@ -4003,8 +4068,10 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
aslSession.getUsername()));
TabularDataService service = TabularDataServiceFactory.getService();
ArrayList<Occurences> occurences=QueryService.queryOccurences(service,column, Direction.ASC);
ArrayList<Occurences> occurences = QueryService.queryOccurences(
service, column, Direction.ASC);
logger.debug("Retrieved Occurences");
return occurences;
} catch (Exception e) {
logger.debug("Error in GetOccurencesForBatchReplace: "
@ -4016,7 +4083,5 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
}
}
}

View File

@ -13,12 +13,10 @@ import org.gcube.data.analysis.tabulardata.query.parameters.select.QueryColumn;
import org.gcube.data.analysis.tabulardata.query.parameters.select.QueryColumn.Function;
import org.gcube.data.analysis.tabulardata.query.parameters.select.QuerySelect;
import org.gcube.data.analysis.tabulardata.service.TabularDataService;
import org.gcube.data.analysis.tabulardata.service.exception.NoSuchTableException;
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.batch.Occurences;
import org.gcube.portlets.user.td.gwtservice.shared.tr.paging.Direction;
import org.json.JSONArray;
import org.json.JSONException;
import org.slf4j.Logger;
@ -32,16 +30,18 @@ public class QueryService {
public static ArrayList<Occurences> queryOccurences(
TabularDataService service, ColumnData column, Direction direction)
throws TDGWTServiceException {
logger.debug("QueryOccurences");
ArrayList<Occurences> occurences = new ArrayList<Occurences>();
TableId tableId = new TableId(new Long(column.getTrId().getTableId()));
ColumnLocalId columnId = new ColumnLocalId(column.getColumnId());
QuerySelect querySelect = new QuerySelect(Arrays.asList(
new QueryColumn(columnId), new QueryColumn(columnId,
Function.COUNT)));
logger.debug("Occurences querySelect:"+querySelect.toString());
QueryGroup queryGroup = new QueryGroup(Arrays.asList(columnId));
logger.debug("Occurences queryGroup:"+querySelect.toString());
QueryOrder queryOrder = null;
switch (direction) {
case ASC:
@ -55,8 +55,10 @@ public class QueryService {
break;
}
QueryPage queryPage = null;// All occurences
logger.debug("Occurences queryPage all");
String serviceJson = null;
try {
if (queryOrder == null) {
@ -67,7 +69,7 @@ public class QueryService {
serviceJson = service.queryAsJson(tableId, queryPage,
queryOrder, querySelect, queryGroup);
}
} catch (NoSuchTableException e) {
} catch (Throwable e) {
logger.debug("Error by running the query on the server:"+e.getLocalizedMessage());
e.printStackTrace();
throw new TDGWTServiceException(
@ -75,10 +77,14 @@ public class QueryService {
}
logger.debug("Created serviceJson");
logger.debug(serviceJson);
JSONArray currentRow = null;
int i = -1;
int j = -1;
int totalRows = -1;
try {
org.json.JSONObject obj = new org.json.JSONObject(serviceJson);
org.json.JSONArray rows = obj.getJSONArray("rows");

View File

@ -10,8 +10,8 @@ import java.io.Serializable;
*/
public class Occurences implements Serializable {
private static final long serialVersionUID = -5933329146218505850L;
private static final long serialVersionUID = -5521905443482827219L;
protected String value;
protected int number;