From af19d456e2247c8b2349c9f781467c7b6619e08f Mon Sep 17 00:00:00 2001 From: Giancarlo Panichi Date: Fri, 10 Oct 2014 16:50:30 +0000 Subject: [PATCH] Minor update git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/portlets/user/tabular-data-gwt-service@100622 82a268e6-3cf1-43bd-a215-b396298e98cf --- .../gwtservice/client/rpc/TDGWTService.java | 12 +++++ .../client/rpc/TDGWTServiceAsync.java | 4 +- .../gwtservice/server/SessionConstants.java | 2 + .../td/gwtservice/server/SessionUtil.java | 46 +++++++++++++--- .../gwtservice/server/TDGWTServiceImpl.java | 53 +++++++++++++++++++ .../opexecution/OpExecution4MapCreation.java | 2 +- .../td/gwtservice/shared/UIOperationsId.java | 3 +- .../shared/map/MapCreationSession.java | 48 +++++++++++------ 8 files changed, 142 insertions(+), 28 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 1964ffd..d333b27 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 @@ -18,6 +18,7 @@ import org.gcube.portlets.user.td.gwtservice.shared.history.OpHistory; import org.gcube.portlets.user.td.gwtservice.shared.history.RollBackSession; import org.gcube.portlets.user.td.gwtservice.shared.json.JSONExportSession; import org.gcube.portlets.user.td.gwtservice.shared.licenses.LicenceData; +import org.gcube.portlets.user.td.gwtservice.shared.map.MapCreationSession; import org.gcube.portlets.user.td.gwtservice.shared.monitor.BackgroundOperationMonitorSession; import org.gcube.portlets.user.td.gwtservice.shared.monitor.OperationMonitor; import org.gcube.portlets.user.td.gwtservice.shared.monitor.OperationMonitorSession; @@ -929,4 +930,15 @@ public interface TDGWTService extends RemoteService { public ArrayList getResourcesTDByType(TRId trId, ResourceTDType resourceTDType) throws TDGWTServiceException; + // GIS MAP + /** + * Start Map Creation and invokes the client library + * + * @param mapCreationSession + * @return + * @throws TDGWTServiceException + */ + public String startMapCreation(MapCreationSession mapCreationSession) + throws TDGWTServiceException; + } 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 4196995..a2b3e7d 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 @@ -17,6 +17,7 @@ import org.gcube.portlets.user.td.gwtservice.shared.history.OpHistory; import org.gcube.portlets.user.td.gwtservice.shared.history.RollBackSession; import org.gcube.portlets.user.td.gwtservice.shared.json.JSONExportSession; import org.gcube.portlets.user.td.gwtservice.shared.licenses.LicenceData; +import org.gcube.portlets.user.td.gwtservice.shared.map.MapCreationSession; import org.gcube.portlets.user.td.gwtservice.shared.monitor.BackgroundOperationMonitorSession; import org.gcube.portlets.user.td.gwtservice.shared.monitor.OperationMonitor; import org.gcube.portlets.user.td.gwtservice.shared.monitor.OperationMonitorSession; @@ -341,6 +342,7 @@ public interface TDGWTServiceAsync { //GIS MAP - + void startMapCreation(MapCreationSession mapCreationSession, + AsyncCallback callback); } diff --git a/src/main/java/org/gcube/portlets/user/td/gwtservice/server/SessionConstants.java b/src/main/java/org/gcube/portlets/user/td/gwtservice/server/SessionConstants.java index eeddaab..9d2ef06 100644 --- a/src/main/java/org/gcube/portlets/user/td/gwtservice/server/SessionConstants.java +++ b/src/main/java/org/gcube/portlets/user/td/gwtservice/server/SessionConstants.java @@ -76,6 +76,8 @@ public class SessionConstants { protected static final String DUPLICATES_ROWS_SESSION = "DUPLICATES_ROWS_SESSION"; + protected static final String MAP_CREATION_SESSION = "MAP_CREATION_SESSION"; + protected static final String TEMPLATE_APPLY_SESSION = "TEMPLATE_APPLY_SESSION"; protected static final String CODELISTS_PAGING_LOADED = "CODELISTS_PAGING_LOADED"; diff --git a/src/main/java/org/gcube/portlets/user/td/gwtservice/server/SessionUtil.java b/src/main/java/org/gcube/portlets/user/td/gwtservice/server/SessionUtil.java index a8d9a92..e945319 100644 --- a/src/main/java/org/gcube/portlets/user/td/gwtservice/server/SessionUtil.java +++ b/src/main/java/org/gcube/portlets/user/td/gwtservice/server/SessionUtil.java @@ -25,6 +25,7 @@ import org.gcube.portlets.user.td.gwtservice.shared.extract.ExtractCodelistSessi import org.gcube.portlets.user.td.gwtservice.shared.file.FileUploadMonitor; import org.gcube.portlets.user.td.gwtservice.shared.history.RollBackSession; import org.gcube.portlets.user.td.gwtservice.shared.json.JSONExportSession; +import org.gcube.portlets.user.td.gwtservice.shared.map.MapCreationSession; import org.gcube.portlets.user.td.gwtservice.shared.sdmx.SDMXExportSession; import org.gcube.portlets.user.td.gwtservice.shared.sdmx.SDMXImportSession; import org.gcube.portlets.user.td.gwtservice.shared.source.SDMXRegistrySource; @@ -81,14 +82,13 @@ public class SessionUtil { // Remove comment for Test /* - username = Constants.DEFAULT_USER; - String scope = Constants.DEFAULT_SCOPE; - - httpSession.setAttribute(ScopeHelper.USERNAME_ATTRIBUTE, username); - session = SessionManager.getInstance().getASLSession( - httpSession.getId(), username); - session.setScope(scope); - */ + * username = Constants.DEFAULT_USER; String scope = + * Constants.DEFAULT_SCOPE; + * + * httpSession.setAttribute(ScopeHelper.USERNAME_ATTRIBUTE, + * username); session = SessionManager.getInstance().getASLSession( + * httpSession.getId(), username); session.setScope(scope); + */ } else { session = SessionManager.getInstance().getASLSession( httpSession.getId(), username); @@ -1305,6 +1305,36 @@ public class SessionUtil { } + // / + + public static MapCreationSession getMapCreationSession( + HttpSession httpSession) { + MapCreationSession mapCreationSession = (MapCreationSession) httpSession + .getAttribute(SessionConstants.MAP_CREATION_SESSION); + if (mapCreationSession != null) { + return mapCreationSession; + } else { + mapCreationSession = new MapCreationSession(); + httpSession.setAttribute(SessionConstants.MAP_CREATION_SESSION, + mapCreationSession); + return mapCreationSession; + } + } + + public static void setMapCreationSession(HttpSession httpSession, + MapCreationSession mapCreationSession) { + MapCreationSession mapC = (MapCreationSession) httpSession + .getAttribute(SessionConstants.MAP_CREATION_SESSION); + if (mapC != null) { + httpSession.removeAttribute(SessionConstants.MAP_CREATION_SESSION); + } + httpSession.setAttribute(SessionConstants.MAP_CREATION_SESSION, + mapCreationSession); + + } + + // + public static TaskWrapper getStartedTask(HttpSession httpSession, String taskId) { TaskWrapper taskWrapper = null; 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 3264f99..5c170de 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 @@ -123,6 +123,7 @@ import org.gcube.portlets.user.td.gwtservice.server.opexecution.OpExecution4Filt import org.gcube.portlets.user.td.gwtservice.server.opexecution.OpExecution4GroupBy; import org.gcube.portlets.user.td.gwtservice.server.opexecution.OpExecution4JSONExport; import org.gcube.portlets.user.td.gwtservice.server.opexecution.OpExecution4LabelColumn; +import org.gcube.portlets.user.td.gwtservice.server.opexecution.OpExecution4MapCreation; import org.gcube.portlets.user.td.gwtservice.server.opexecution.OpExecution4MergeColumn; import org.gcube.portlets.user.td.gwtservice.server.opexecution.OpExecution4Normalization; import org.gcube.portlets.user.td.gwtservice.server.opexecution.OpExecution4ReplaceBatch; @@ -161,6 +162,7 @@ import org.gcube.portlets.user.td.gwtservice.shared.history.OpHistory; import org.gcube.portlets.user.td.gwtservice.shared.history.RollBackSession; import org.gcube.portlets.user.td.gwtservice.shared.json.JSONExportSession; import org.gcube.portlets.user.td.gwtservice.shared.licenses.LicenceData; +import org.gcube.portlets.user.td.gwtservice.shared.map.MapCreationSession; import org.gcube.portlets.user.td.gwtservice.shared.monitor.BackgroundOperationMonitorCreator; import org.gcube.portlets.user.td.gwtservice.shared.monitor.BackgroundOperationMonitorSession; import org.gcube.portlets.user.td.gwtservice.shared.monitor.OperationMonitor; @@ -6764,6 +6766,57 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements + e.getLocalizedMessage()); } } + + @Override + public String startMapCreation(MapCreationSession mapCreationSession) + throws TDGWTServiceException { + try { + HttpSession session = this.getThreadLocalRequest().getSession(); + SessionUtil.setMapCreationSession(session, mapCreationSession); + ASLSession aslSession = SessionUtil.getAslSession(session); + + AuthorizationProvider.instance.set(new AuthorizationToken( + aslSession.getUsername(), aslSession.getScope())); + TabularDataService service = TabularDataServiceFactory.getService(); + checkTabularResourceLocked(service, mapCreationSession.getTrId()); + + + OpExecution4MapCreation opEx = new OpExecution4MapCreation(service, + mapCreationSession); + OpExecutionDirector director = new OpExecutionDirector(); + director.setOperationExecutionBuilder(opEx); + director.constructOperationExecution(); + OperationExecution invocation = director.getOperationExecution(); + + if (invocation == null) { + throw new TDGWTServiceException( + "Error Delete Rows invocation: Operation not supported"); + } + + TabularResourceId serviceTR = new TabularResourceId( + Long.valueOf(mapCreationSession.getTrId().getId())); + logger.debug("OperationInvocation: \n" + invocation.toString()); + Task trTask = service.execute(invocation, serviceTR); + logger.debug("Start Task on service: TaskId " + trTask.getId()); + + TaskWrapper taskWrapper = new TaskWrapper(trTask, + UIOperationsId.GenerateMap, mapCreationSession.getTrId()); + SessionUtil.setStartedTask(session, taskWrapper); + + return trTask.getId().getValue(); + } catch (TDGWTServiceException 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 creating the map: " + + e.getLocalizedMessage()); + } + + } diff --git a/src/main/java/org/gcube/portlets/user/td/gwtservice/server/opexecution/OpExecution4MapCreation.java b/src/main/java/org/gcube/portlets/user/td/gwtservice/server/opexecution/OpExecution4MapCreation.java index 1712e04..0540ac7 100644 --- a/src/main/java/org/gcube/portlets/user/td/gwtservice/server/opexecution/OpExecution4MapCreation.java +++ b/src/main/java/org/gcube/portlets/user/td/gwtservice/server/opexecution/OpExecution4MapCreation.java @@ -59,7 +59,7 @@ public class OpExecution4MapCreation extends OpExecutionBuilder { map.put(Constants.PARAMETER_GENERATEMAP_METACREDITS, mapCreationSession.getMetaCredits()); map.put(Constants.PARAMETER_GENERATEMAP_METAKEYWORDS, - mapCreationSession.getMetaKewords()); + mapCreationSession.getMetaKeywords()); OperationExecution invocation = new OperationExecution( diff --git a/src/main/java/org/gcube/portlets/user/td/gwtservice/shared/UIOperationsId.java b/src/main/java/org/gcube/portlets/user/td/gwtservice/shared/UIOperationsId.java index df9c917..f31943f 100644 --- a/src/main/java/org/gcube/portlets/user/td/gwtservice/shared/UIOperationsId.java +++ b/src/main/java/org/gcube/portlets/user/td/gwtservice/shared/UIOperationsId.java @@ -95,7 +95,8 @@ public enum UIOperationsId { ResumeTask("Resume Task"), ResubmitTask("ResubmitTask"), RollBack("Roll Back"), - ApplyTemplate("Apply Template"); + ApplyTemplate("Apply Template"), + GenerateMap("Generate Map"); /** * @param text diff --git a/src/main/java/org/gcube/portlets/user/td/gwtservice/shared/map/MapCreationSession.java b/src/main/java/org/gcube/portlets/user/td/gwtservice/shared/map/MapCreationSession.java index 672fe83..6d81bec 100644 --- a/src/main/java/org/gcube/portlets/user/td/gwtservice/shared/map/MapCreationSession.java +++ b/src/main/java/org/gcube/portlets/user/td/gwtservice/shared/map/MapCreationSession.java @@ -7,6 +7,7 @@ import java.io.Serializable; import java.util.ArrayList; import org.gcube.portlets.user.td.gwtservice.shared.tr.ColumnData; +import org.gcube.portlets.user.td.widgetcommonevent.shared.TRId; /** * @@ -18,6 +19,7 @@ public class MapCreationSession implements Serializable { private static final long serialVersionUID = 2648327461965415567L; + private TRId trId; private String name; private ArrayList feature; private boolean useView; @@ -26,14 +28,15 @@ public class MapCreationSession implements Serializable { private String metaAbstract; private String metaPurpose; private String metaCredits; - private ArrayList metaKewords; + private ArrayList metaKeywords; public MapCreationSession() { super(); } - + /** * + * @param trId * @param name * @param feature * @param useView @@ -42,13 +45,15 @@ public class MapCreationSession implements Serializable { * @param metaAbstract * @param metaPurpose * @param metaCredits - * @param metaKewords + * @param metaKeywords */ - public MapCreationSession(String name, ArrayList feature, - boolean useView, ColumnData geometry, String username, - String metaAbstract, String metaPurpose, String metaCredits, - ArrayList metaKewords) { + public MapCreationSession(TRId trId, String name, + ArrayList feature, boolean useView, + ColumnData geometry, String username, String metaAbstract, + String metaPurpose, String metaCredits, + ArrayList metaKeywords) { super(); + this.trId = trId; this.name = name; this.feature = feature; this.useView = useView; @@ -57,7 +62,15 @@ public class MapCreationSession implements Serializable { this.metaAbstract = metaAbstract; this.metaPurpose = metaPurpose; this.metaCredits = metaCredits; - this.metaKewords = metaKewords; + this.metaKeywords = metaKeywords; + } + + public TRId getTrId() { + return trId; + } + + public void setTrId(TRId trId) { + this.trId = trId; } public String getName() { @@ -124,21 +137,22 @@ public class MapCreationSession implements Serializable { this.metaCredits = metaCredits; } - public ArrayList getMetaKewords() { - return metaKewords; + public ArrayList getMetaKeywords() { + return metaKeywords; } - public void setMetaKewords(ArrayList metaKewords) { - this.metaKewords = metaKewords; + public void setMetaKeywords(ArrayList metaKeywords) { + this.metaKeywords = metaKeywords; } @Override public String toString() { - return "MapCreationSession [name=" + name + ", feature=" + feature - + ", useView=" + useView + ", geometry=" + geometry - + ", username=" + username + ", metaAbstract=" + metaAbstract - + ", metaPurpose=" + metaPurpose + ", metaCredits=" - + metaCredits + ", metaKewords=" + metaKewords + "]"; + return "MapCreationSession [trId=" + trId + ", name=" + name + + ", feature=" + feature + ", useView=" + useView + + ", geometry=" + geometry + ", username=" + username + + ", metaAbstract=" + metaAbstract + ", metaPurpose=" + + metaPurpose + ", metaCredits=" + metaCredits + + ", metaKeywords=" + metaKeywords + "]"; } }