Minor Update

git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/portlets/user/tabular-data-gwt-service@94246 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Giancarlo Panichi 2014-04-03 13:32:29 +00:00
parent a17d4b01cf
commit 701c43759f
4 changed files with 154 additions and 82 deletions

View File

@ -53,6 +53,7 @@ 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;
@ -174,7 +175,18 @@ public interface TDGWTService extends RemoteService {
*/
public ArrayList<TRMetadata> getTRMetadata(TRId trId)
throws TDGWTServiceException;
/**
* Return true if is a valid tabular resource
*
* @param trId
* @return
* @throws TDGWTServiceException
*/
public Boolean isTabularResourceValid(TRId trId)
throws TDGWTServiceException;
//Share
/**
* Retrieves information sharing on the tabular resource

View File

@ -96,14 +96,14 @@ public interface TDGWTServiceAsync {
void getColumns(AsyncCallback<ArrayList<ColumnData>> callback);
void getColumns(TRId trId, AsyncCallback<ArrayList<ColumnData>> callback);
void getColumnsForDimension(TRId trId, AsyncCallback<ArrayList<ColumnData>> callback);
void getColumn(TRId trId, String columnName, AsyncCallback<ColumnData> callback);
void removeTabularResource(TRId trId, AsyncCallback<Void> callback);
void isTabularResourceValid(TRId trId,AsyncCallback<Boolean> callback);
//Share
void getShareInfo(TRId trId, AsyncCallback<ShareInfo> callback);

View File

@ -253,6 +253,7 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
.getTrId());
updateTabResourceInformation(currentTR, trMetadatas);
currentTR.setDate(getTRCreationDate(currentTR.getTrId()));
currentTR.setValid(isTabularResourceValid(currentTR.getTrId()));
SessionUtil.setTabResource(session, currentTR);
logger.debug("GetTabResourceInformation() updated information:"
+ currentTR.toString());
@ -293,6 +294,8 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
.getTrId());
updateTabResourceInformation(currentTR, trMetadatas);
currentTR.setDate(getTRCreationDate(trId));
currentTR.setValid(isTabularResourceValid(trId));
logger.debug("GetTabResourceInformation() updated information:"
+ currentTR.toString());
return currentTR;
@ -936,6 +939,7 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
+ tabResource.getAgency() + " ,rights:"
+ tabResource.getRight() + "]");
tabResource.setDate(sdf.format(tr.getCreationDate().getTime()));
tabResource.setValid(tr.isValid());
tr.setMetadata(new NameMetadata(tabResource.getName()));
tr.setMetadata(new DescriptionMetadata(tabResource.getDescription()));
// tr.setMetadata(new CreationDateMetadata(date));
@ -977,6 +981,7 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
trId.setTabularResourceType(tr.getTableType());
t.setId(String.valueOf(i));
t.setTrId(trId);
t.setValid(tr.isValid());
if (tr.contains(NameMetadata.class)) {
NameMetadata nameMeta = tr.getMetadata(NameMetadata.class);
if (nameMeta != null && nameMeta.getValue() != null) {
@ -1039,13 +1044,13 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
Table viewTable = null;
TRId trId;
TabResource t;
if (table == null) {
logger.info("Tabular resource " + tr.getId() + " has no table.");
t = new TabResource();
t.setTrId(null);
} else {
tableId = table.getId();
tableId = table.getId();
if (tableId == null) {
logger.info("Tabular Resource " + tr.getId()
+ " has last table with id null.");
@ -1062,23 +1067,26 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
logger.error("view table not found");
}
}
if (viewTable == null) {
trId = new TRId(String.valueOf(tr.getId().getValue()),
tr.getTableType(), String.valueOf(tableId.getValue()),
table.getTableType().getName());
tr.getTableType(), String.valueOf(tableId
.getValue()), table.getTableType()
.getName());
} else {
trId = new TRId(String.valueOf(tr.getId().getValue()),
tr.getTableType(), String.valueOf(viewTable.getId().getValue()),
viewTable.getTableType().getName(),String.valueOf(tableId.getValue()),true);
tr.getTableType(), String.valueOf(viewTable.getId()
.getValue()), viewTable.getTableType()
.getName(), String.valueOf(tableId
.getValue()), true);
}
t = getTabResourceInformation(trId);
}
}
t.setId(String.valueOf(i));
return t;
@ -1111,8 +1119,9 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
try {
TabResource t = retrieveTRMetadataFromService(service, tr,
i);
if (t.getTrId() != null) {
ltr.add(t);
if (t.getTrId() != null && t.isValid()) {
ltr.add(t);
}
} catch (Throwable e) {
logger.error("TabResource discarded: " + tr + " cause: "
@ -1567,13 +1576,21 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
TabularResourceId id = new TabularResourceId(Long.valueOf(trId
.getId()));
service.removeTabularResource(id);
TabularResource tr = service.getTabularResource(id);
String owner = tr.getOwner();
if (owner != null && owner.compareTo(aslSession.getUsername()) == 0) {
service.removeTabularResource(id);
} else {
throw new TDGWTServiceException(
"You are not the owner of this tabular resource (owner: "
+ owner + ")");
}
return;
} catch (Throwable e) {
logger.error(
"Error removing TabularResource: "
"Error deleting the tabular resource: "
+ e.getLocalizedMessage(), e);
throw new TDGWTServiceException("Error removing TabularResource: "
throw new TDGWTServiceException("Error deleting the tabular resource: "
+ e.getLocalizedMessage());
}
}
@ -1601,12 +1618,12 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
TabularResource serviceTR = service.createTabularResource();
Table table = service.getLastTable(serviceTR.getId());
syncTRMetaData(serviceTR, tabResource);
TRId trId = new TRId(String.valueOf(serviceTR.getId().getValue()),
serviceTR.getTableType(), String.valueOf(table.getId()
.getValue()), table.getTableType().getName());
tabResource.setTrId(trId);
tabResource.setValid(serviceTR.isValid());
return tabResource;
} catch (Throwable e) {
logger.error(
@ -1764,9 +1781,9 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
new Long(trId.getId()));
TabularResource tr = service.getTabularResource(tabularResourceId);
Table table = service.getLastTable(tabularResourceId);
Table viewTable=null;
Table viewTable = null;
if (table.contains(DatasetViewTableMetadata.class)) {
DatasetViewTableMetadata dwm = table
.getMetadata(DatasetViewTableMetadata.class);
@ -1777,21 +1794,22 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
logger.error("view table not found");
}
}
TRId newTRId;
if (viewTable == null) {
newTRId = new TRId(String.valueOf(tr.getId().getValue()),
tr.getTableType(), String.valueOf(table.getId().getValue()),
table.getTableType().getName());
tr.getTableType(), String.valueOf(table.getId()
.getValue()), table.getTableType().getName());
} else {
newTRId = new TRId(String.valueOf(tr.getId().getValue()),
tr.getTableType(), String.valueOf(viewTable.getId().getValue()),
viewTable.getTableType().getName(),
String.valueOf(table.getId().getValue()),true);
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;
@ -1840,8 +1858,8 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
case SUCCEDED:
importMonitor.setProgress(task.getProgress());
logger.debug("Task Result: " + task.getResult());
trId=retrieveTabularResourceBasicData(trId);
trId = retrieveTabularResourceBasicData(trId);
sdmxImportTabResource.setTrId(trId);
SessionUtil.setSDMXImportTabResource(session,
@ -1866,7 +1884,7 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
case STOPPED:
importMonitor.setProgress(task.getProgress());
logger.debug("Task Result: " + task.getResult());
trId=retrieveTabularResourceBasicData(trId);
trId = retrieveTabularResourceBasicData(trId);
sdmxImportTabResource.setTrId(trId);
SessionUtil.setSDMXImportTabResource(session,
@ -2078,9 +2096,9 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
}
String user = aslSession.getUsername();
logger.info("Session User:" + user);
logger.debug("StartCSVImport: "+csvImportSession.toString());
logger.debug("StartCSVImport: " + csvImportSession.toString());
FileUploadSession fileUploadSession = SessionUtil
.getFileUploadSession(session);
if (fileUploadSession == null) {
@ -2118,7 +2136,8 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
parameterInstances.put(Constants.PARAMETER_HASHEADER, hasHeader);// true
parameterInstances.put(Constants.PARAMETER_FIELDMASK,
csvImportSession.getColumnToImportMask());// Column Mask
parameterInstances.put(Constants.PARAMETER_SKIPERROR, csvImportSession.isSkipInvalidLines());
parameterInstances.put(Constants.PARAMETER_SKIPERROR,
csvImportSession.isSkipInvalidLines());
return parameterInstances;
}
@ -2234,7 +2253,7 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
importMonitor.setStatus(TaskStateMap.map(task
.getStatus()));
switch (importMonitor.getStatus()) {
case FAILED:
if (task.getResult() != null) {
@ -2251,8 +2270,8 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
case SUCCEDED:
logger.debug("Task Result: " + task.getResult());
importMonitor.setProgress(task.getProgress());
trId=retrieveTabularResourceBasicData(trId);
trId = retrieveTabularResourceBasicData(trId);
csvImportTabResource.setTrId(trId);
SessionUtil.setCSVImportTabResource(session,
csvImportTabResource);
@ -2265,8 +2284,8 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
case STOPPED:
logger.debug("Task Result: " + task.getResult());
importMonitor.setProgress(task.getProgress());
trId=retrieveTabularResourceBasicData(trId);
trId = retrieveTabularResourceBasicData(trId);
csvImportTabResource.setTrId(trId);
SessionUtil.setCSVImportTabResource(session,
csvImportTabResource);
@ -2383,7 +2402,7 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
FileUtil.exceptionDetailMessage(e));
fileUploadSession.setFileUploadState(FileUploadState.FAILED);
SessionUtil.setFileUploadSession(session, fileUploadSession);
logger.error("Error elaborating the imput stream", e);
logger.error("Error elaborating the input stream", e);
throw new TDGWTServiceException(
"Error in importCSV getFileFromWorkspace: "
+ e.getLocalizedMessage(), e);
@ -2424,6 +2443,39 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
+ e.getLocalizedMessage());
}
}
/**
*
* @param trId
* @return
* @throws TDGWTServiceException
*/
public Boolean isTabularResourceValid(TRId trId) throws TDGWTServiceException {
try {
HttpSession session = this.getThreadLocalRequest().getSession();
ASLSession aslSession = SessionUtil.getAslSession(session);
logger.debug("IsTabularResourceValid: " + trId.toString());
AuthorizationProvider.instance.set(new AuthorizationToken(
aslSession.getUsername()));
TabularDataService service = TabularDataServiceFactory.getService();
TabularResource tr = service
.getTabularResource(new TabularResourceId(Long.valueOf(trId
.getId())));
logger.debug("IsTabularResourceValid: " + tr.isValid());
return tr.isValid();
} catch (Throwable e) {
logger.error(
"Error checking if it is a valid tabular resource: " + e.getLocalizedMessage(),
e);
throw new TDGWTServiceException("Error checking if it is a valid tabular resource: "
+ e.getLocalizedMessage());
}
}
/**
*
@ -2812,7 +2864,7 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
case SUCCEDED:
logger.debug("Task Result:" + task.getResult());
exportMonitor.setProgress(task.getProgress());
table = task.getResult().getPrimaryTable();
logger.debug("Table retrived: " + table.toString());
exportMetadata = table
@ -3557,7 +3609,7 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
trId = new TRId();
trId.setId(changeColumnTypeSession.getColumnData()
.getTrId().getId());
trId=retrieveTabularResourceBasicData(trId);
trId = retrieveTabularResourceBasicData(trId);
changeColumnTypeMonitor.setTrId(trId);
tabResource = SessionUtil.getTabResource(session);
@ -3579,8 +3631,8 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
trId = new TRId();
trId.setId(changeColumnTypeSession.getColumnData()
.getTrId().getId());
trId=retrieveTabularResourceBasicData(trId);
trId = retrieveTabularResourceBasicData(trId);
changeColumnTypeMonitor.setTrId(trId);
tabResource = SessionUtil.getTabResource(session);
@ -3700,7 +3752,7 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
trId = new TRId();
trId.setId(deleteColumnSession.getColumnData()
.getTrId().getId());
trId=retrieveTabularResourceBasicData(trId);
trId = retrieveTabularResourceBasicData(trId);
deleteColumnMonitor.setTrId(trId);
tabResource = SessionUtil.getTabResource(session);
@ -3724,7 +3776,7 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
trId = new TRId();
trId.setId(deleteColumnSession.getColumnData()
.getTrId().getId());
trId=retrieveTabularResourceBasicData(trId);
trId = retrieveTabularResourceBasicData(trId);
deleteColumnMonitor.setTrId(trId);
tabResource = SessionUtil.getTabResource(session);
@ -3843,7 +3895,7 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
trId = new TRId();
trId.setId(labelColumnSession.getColumnData().getTrId()
.getId());
trId=retrieveTabularResourceBasicData(trId);
trId = retrieveTabularResourceBasicData(trId);
labelColumnMonitor.setTrId(trId);
tabResource = SessionUtil.getTabResource(session);
@ -3865,7 +3917,7 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
trId = new TRId();
trId.setId(labelColumnSession.getColumnData().getTrId()
.getId());
trId=retrieveTabularResourceBasicData(trId);
trId = retrieveTabularResourceBasicData(trId);
labelColumnMonitor.setTrId(trId);
tabResource = SessionUtil.getTabResource(session);
@ -3987,8 +4039,8 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
logger.debug("Table retrived: " + table.toString());
trId = new TRId();
trId.setId(changeTableTypeSession.getTrId().getId());
trId=retrieveTabularResourceBasicData(trId);
trId = retrieveTabularResourceBasicData(trId);
changeTableTypeMonitor.setTrId(trId);
tabResource = SessionUtil.getTabResource(session);
@ -4011,8 +4063,8 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
logger.debug("Table retrived: " + table.toString());
trId = new TRId();
trId.setId(changeTableTypeSession.getTrId().getId());
trId=retrieveTabularResourceBasicData(trId);
trId = retrieveTabularResourceBasicData(trId);
changeTableTypeMonitor.setTrId(trId);
tabResource = SessionUtil.getTabResource(session);
@ -4221,7 +4273,7 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
trId = new TRId();
trId.setId(deleteRowsSession.getTrId().getId());
trId=retrieveTabularResourceBasicData(trId);
trId = retrieveTabularResourceBasicData(trId);
deleteRowsMonitor.setTrId(trId);
tabResource = SessionUtil.getTabResource(session);
@ -4242,7 +4294,7 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
deleteRowsMonitor.setProgress(task.getProgress());
trId = new TRId();
trId.setId(deleteRowsSession.getTrId().getId());
trId=retrieveTabularResourceBasicData(trId);
trId = retrieveTabularResourceBasicData(trId);
deleteRowsMonitor.setTrId(trId);
tabResource = SessionUtil.getTabResource(session);
@ -4293,9 +4345,9 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
TabularResource cloned = service.cloneTabularResource(serviceTR);
Table table = service.getLastTable(serviceTR);
Table viewTable=null;
Table viewTable = null;
if (table.contains(DatasetViewTableMetadata.class)) {
DatasetViewTableMetadata dwm = table
.getMetadata(DatasetViewTableMetadata.class);
@ -4306,24 +4358,21 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
logger.error("view table not found");
}
}
TRId trId;
if (viewTable == null) {
trId = new TRId(
new Long(cloned.getId().getValue()).toString(),
cloned.getTableType(),
new Long(table.getId().getValue()).toString(), table
.getTableType().getName());
trId = new TRId(new Long(cloned.getId().getValue()).toString(),
cloned.getTableType(), new Long(table.getId()
.getValue()).toString(), table.getTableType()
.getName());
} else {
trId = new TRId(new Long(cloned.getId().getValue()).toString(),
cloned.getTableType(),
String.valueOf(viewTable.getId().getValue()),
viewTable.getTableType().getName(),
String.valueOf(table.getId().getValue()),true);
cloned.getTableType(), String.valueOf(viewTable.getId()
.getValue()), viewTable.getTableType()
.getName(), String.valueOf(table.getId()
.getValue()), true);
}
TabResource tabResource = new TabResource();
tabResource.setTrId(trId);
@ -4432,7 +4481,7 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
logger.debug("Table retrived: " + table.toString());
trId = new TRId();
trId.setId(duplicatesSession.getTrId().getId());
trId=retrieveTabularResourceBasicData(trId);
trId = retrieveTabularResourceBasicData(trId);
duplicatesMonitor.setTrId(trId);
tabResource = SessionUtil.getTabResource(session);
@ -4455,8 +4504,8 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
logger.debug("Table retrived: " + table.toString());
trId = new TRId();
trId.setId(duplicatesSession.getTrId().getId());
trId=retrieveTabularResourceBasicData(trId);
trId = retrieveTabularResourceBasicData(trId);
duplicatesMonitor.setTrId(trId);
tabResource = SessionUtil.getTabResource(session);
@ -4768,7 +4817,7 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
trId = new TRId();
trId.setId(templateApplySession.getTrId().getId());
trId=retrieveTabularResourceBasicData(trId);
trId = retrieveTabularResourceBasicData(trId);
templateApplyMonitor.setTrId(trId);
tabResource = SessionUtil.getTabResource(session);
@ -4791,7 +4840,7 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
trId = new TRId();
trId.setId(templateApplySession.getTrId().getId());
trId=retrieveTabularResourceBasicData(trId);
trId = retrieveTabularResourceBasicData(trId);
templateApplyMonitor.setTrId(trId);
tabResource = SessionUtil.getTabResource(session);
@ -4948,7 +4997,7 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
trId = new TRId();
trId.setId(replaceColumnSession.getTrId().getId());
trId=retrieveTabularResourceBasicData(trId);
trId = retrieveTabularResourceBasicData(trId);
replaceColumnMonitor.setTrId(trId);
tabResource = SessionUtil.getTabResource(session);
@ -4971,7 +5020,7 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
trId.setId(replaceColumnSession.getColumnData()
.getTrId().getId());
trId=retrieveTabularResourceBasicData(trId);
trId = retrieveTabularResourceBasicData(trId);
replaceColumnMonitor.setTrId(trId);
tabResource = SessionUtil.getTabResource(session);

View File

@ -23,6 +23,7 @@ public class TabResource implements Serializable {
protected String agency;
protected String date;
protected String right;
protected boolean valid;
protected TRId trId;
public TabResource(){}
@ -100,13 +101,23 @@ public class TabResource implements Serializable {
public void setDescription(String description) {
this.description = description;
}
public boolean isValid() {
return valid;
}
public void setValid(boolean valid) {
this.valid = valid;
}
@Override
public String toString() {
return "TabResource [id=" + id + ", name=" + name + ", description="
+ description + ", agency=" + agency + ", date=" + date
+ ", right=" + right + ", trId=" + trId + "]";
+ ", right=" + right + ", valid=" + valid + ", trId=" + trId
+ "]";
}
}