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 ed7a614..563b626 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 @@ -174,6 +174,7 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements ArrayList trMetadatas = getTRMetadata(currentTR .getTrId()); updateTabResourceInformation(currentTR, trMetadatas); + currentTR.setDate(getTRCreationDate(currentTR.getTrId())); SessionUtil.setTabResource(session, currentTR); return currentTR; @@ -196,13 +197,14 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements try { @SuppressWarnings("unused") HttpSession session = this.getThreadLocalRequest().getSession(); - //ASLSession aslSession = SessionUtil.getAslSession(session); + // ASLSession aslSession = SessionUtil.getAslSession(session); TabResource currentTR = new TabResource(); currentTR.setTrId(trId); ArrayList trMetadatas = getTRMetadata(currentTR .getTrId()); updateTabResourceInformation(currentTR, trMetadatas); + currentTR.setDate(getTRCreationDate(trId)); return currentTR; } catch (Exception e) { @@ -280,7 +282,7 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements int i = 0; for (Column c : cols) { if (c.getColumnType() instanceof IdColumnType) { - + } else { ColumnData cData = new ColumnData(); cData.setId(Integer.toString(i)); @@ -321,11 +323,9 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements } catch (Exception e) { logger.error( - "Error retrieving Columns: " - + e.getLocalizedMessage(), e); - throw new TDGWTServiceException( - "Error retrieving Columns: " - + e.getLocalizedMessage()); + "Error retrieving Columns: " + e.getLocalizedMessage(), e); + throw new TDGWTServiceException("Error retrieving Columns: " + + e.getLocalizedMessage()); } } @@ -333,7 +333,8 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements * * {@inheritDoc} */ - public ArrayList getColumns(TRId trId) throws TDGWTServiceException { + public ArrayList getColumns(TRId trId) + throws TDGWTServiceException { try { HttpSession session = this.getThreadLocalRequest().getSession(); ASLSession aslSession = SessionUtil.getAslSession(session); @@ -342,8 +343,8 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements aslSession.getUsername())); TabularDataService service = TabularDataServiceFactory.getService(); - Table table = service.getTable(new TableId(Long - .valueOf(trId.getTableId()))); + Table table = service.getTable(new TableId(Long.valueOf(trId + .getTableId()))); ArrayList columns = new ArrayList(); @@ -351,7 +352,7 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements int i = 0; for (Column c : cols) { if (c.getColumnType() instanceof IdColumnType) { - + } else { ColumnData cData = new ColumnData(); cData.setId(Integer.toString(i)); @@ -392,19 +393,18 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements } catch (Exception e) { logger.error( - "Error retrieving Columns: " - + e.getLocalizedMessage(), e); - throw new TDGWTServiceException( - "Error retrieving Columns: " - + e.getLocalizedMessage()); + "Error retrieving Columns: " + e.getLocalizedMessage(), e); + throw new TDGWTServiceException("Error retrieving Columns: " + + e.getLocalizedMessage()); } } - + /** * * {@inheritDoc} */ - public ColumnData getColumn(TRId trId, String columnName) throws TDGWTServiceException { + public ColumnData getColumn(TRId trId, String columnName) + throws TDGWTServiceException { try { HttpSession session = this.getThreadLocalRequest().getSession(); ASLSession aslSession = SessionUtil.getAslSession(session); @@ -413,14 +413,14 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements aslSession.getUsername())); TabularDataService service = TabularDataServiceFactory.getService(); - Table table = service.getTable(new TableId(Long - .valueOf(trId.getTableId()))); + Table table = service.getTable(new TableId(Long.valueOf(trId + .getTableId()))); - ColumnData cData = new ColumnData(); + ColumnData cData = new ColumnData(); Column c = table.getColumnByName(columnName); if (c.getColumnType() instanceof IdColumnType) { - + } else { cData.setId(Integer.toString(0)); cData.setColumnId(c.getLocalId().getValue()); @@ -457,15 +457,13 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements return cData; } catch (Exception e) { - logger.error( - "Error retrieving Column: " - + e.getLocalizedMessage(), e); - throw new TDGWTServiceException( - "Error retrieving Column: " - + e.getLocalizedMessage()); + logger.error("Error retrieving Column: " + e.getLocalizedMessage(), + e); + throw new TDGWTServiceException("Error retrieving Column: " + + e.getLocalizedMessage()); } } - + /** * * {@inheritDoc} @@ -544,11 +542,12 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements */ protected void syncTRMetaData(TabularResource tr, TabResource tabResource) { // Date date = Calendar.getInstance().getTime(); - logger.debug("TRservice [id:"+tr.getId()+" ,creationDate:"+tr.getCreationDate()+"]"); - logger.debug("TabResource [name:"+tabResource.getName()+ - " ,description:"+tabResource.getDescription()+ - " ,agency:"+tabResource.getAgency()+ - " ,rights:"+tabResource.getRight()+"]"); + logger.debug("TRservice [id:" + tr.getId() + " ,creationDate:" + + tr.getCreationDate() + "]"); + logger.debug("TabResource [name:" + tabResource.getName() + + " ,description:" + tabResource.getDescription() + " ,agency:" + + tabResource.getAgency() + " ,rights:" + + tabResource.getRight() + "]"); tabResource.setDate(sdf.format(tr.getCreationDate().getTime())); tr.setMetadata(new NameMetadata(tabResource.getName())); tr.setMetadata(new DescriptionMetadata(tabResource.getDescription())); @@ -834,7 +833,7 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements TabularResource serviceTR = trService.createTabularResource(); syncTRMetaData(serviceTR, importSDMXTabResource); - + TRId trId = new TRId(String.valueOf(serviceTR.getId().getValue())); importSDMXTabResource.setTrId(trId); @@ -1433,6 +1432,31 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements SessionUtil.setFileUploadSession(session, fileUploadSession); } + public String getTRCreationDate(TRId trId) throws TDGWTServiceException { + try { + HttpSession session = this.getThreadLocalRequest().getSession(); + ASLSession aslSession = SessionUtil.getAslSession(session); + + logger.debug("GetTRMetadata on " + trId.toString()); + + AuthorizationProvider.instance.set(new AuthorizationToken( + aslSession.getUsername())); + TabularDataService service = TabularDataServiceFactory.getService(); + + TabularResource tr = service + .getTabularResource(new TabularResourceId(Long.valueOf(trId + .getId()))); + + return sdf.format(tr.getCreationDate().getTime()); + + } catch (Exception e) { + logger.error( + "Error in getTRCreationDate(): " + e.getLocalizedMessage(), e); + throw new TDGWTServiceException("Error in getTRCreationDate(): " + + e.getLocalizedMessage()); + } + } + /** * * {@inheritDoc} @@ -1442,9 +1466,9 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements try { HttpSession session = this.getThreadLocalRequest().getSession(); ASLSession aslSession = SessionUtil.getAslSession(session); - - logger.debug("GetTRMetadata on TRId:"+trId.toString()); - + + logger.debug("GetTRMetadata on " + trId.toString()); + AuthorizationProvider.instance.set(new AuthorizationToken( aslSession.getUsername())); TabularDataService service = TabularDataServiceFactory.getService(); @@ -1454,8 +1478,8 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements .getId()))); Collection trMetas = tr.getAllMetadata(); - - logger.debug("GetTRMetadata size: "+trMetas.size()); + + logger.debug("GetTRMetadata size: " + trMetas.size()); ArrayList listTRMetadata = new ArrayList(); for (TabularResourceMetadata trMetadata : trMetas) { @@ -1494,8 +1518,8 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements } } } - - logger.debug("GetTRMetadata retrived: "+listTRMetadata.size()); + + logger.debug("GetTRMetadata retrived: " + listTRMetadata.size()); return listTRMetadata; } catch (Exception e) { @@ -1515,8 +1539,8 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements try { HttpSession session = this.getThreadLocalRequest().getSession(); ASLSession aslSession = SessionUtil.getAslSession(session); - - logger.debug("GetTableMetadata on TRId:"+trId.toString()); + + logger.debug("GetTableMetadata on " + trId.toString()); AuthorizationProvider.instance.set(new AuthorizationToken( aslSession.getUsername())); TabularDataService service = TabularDataServiceFactory.getService(); @@ -1527,7 +1551,7 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements Collection cMeta = table.getAllMetadata(); ArrayList listTabMetadata = new ArrayList(); - logger.debug("Metadata size:"+cMeta.size()); + logger.debug("Metadata size:" + cMeta.size()); for (TableMetadata tMetadata : cMeta) { if (tMetadata instanceof DescriptionsMetadata) { TabDescriptionsMetadata trDescriptionsMetadata = new TabDescriptionsMetadata();