From 124f2e204cc7218f43ecf17f49f3a441f3289b07 Mon Sep 17 00:00:00 2001 From: Massimiliano Assante Date: Thu, 3 Jan 2013 16:47:24 +0000 Subject: [PATCH] separated deps using eventbus, moved statushandlers from the RMP classes git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/portlets/admin/rmp-common-library@67081 82a268e6-3cf1-43bd-a215-b396298e98cf --- .../support/client/Resource_support.java | 22 +++ .../support/client/events/SetScopeEvent.java | 28 ++++ .../client/events/SetScopeEventHandler.java | 7 + .../support/client/utils/CurrentStatus.java | 126 ++++++++++++++++++ .../support/client/utils/StatusHandler.java | 37 +++++ .../client/views/validators/XMLValidator.java | 45 +++++++ .../operations/SupportedOperations.java | 88 ++++++++++++ 7 files changed, 353 insertions(+) create mode 100644 src/main/java/org/gcube/resourcemanagement/support/client/events/SetScopeEvent.java create mode 100644 src/main/java/org/gcube/resourcemanagement/support/client/events/SetScopeEventHandler.java create mode 100644 src/main/java/org/gcube/resourcemanagement/support/client/utils/CurrentStatus.java create mode 100644 src/main/java/org/gcube/resourcemanagement/support/client/utils/StatusHandler.java create mode 100644 src/main/java/org/gcube/resourcemanagement/support/client/views/validators/XMLValidator.java create mode 100644 src/main/java/org/gcube/resourcemanagement/support/shared/operations/SupportedOperations.java diff --git a/src/main/java/org/gcube/resourcemanagement/support/client/Resource_support.java b/src/main/java/org/gcube/resourcemanagement/support/client/Resource_support.java index 87b3d52..b97add8 100644 --- a/src/main/java/org/gcube/resourcemanagement/support/client/Resource_support.java +++ b/src/main/java/org/gcube/resourcemanagement/support/client/Resource_support.java @@ -1,9 +1,31 @@ package org.gcube.resourcemanagement.support.client; import com.google.gwt.core.client.EntryPoint; +import com.google.gwt.event.shared.HandlerManager; public class Resource_support implements EntryPoint { + private HandlerManager eventBus; + + public Resource_support() { + super(); + // TODO Auto-generated constructor stub + } + public Resource_support(HandlerManager eventBus){ + singleton = this; + this.eventBus = eventBus; + } + + private static Resource_support singleton; + + public static Resource_support get() { + return singleton; + } + + public HandlerManager getEventBus() { + return this.eventBus; + } + /** * This is the entry point method. */ diff --git a/src/main/java/org/gcube/resourcemanagement/support/client/events/SetScopeEvent.java b/src/main/java/org/gcube/resourcemanagement/support/client/events/SetScopeEvent.java new file mode 100644 index 0000000..174768c --- /dev/null +++ b/src/main/java/org/gcube/resourcemanagement/support/client/events/SetScopeEvent.java @@ -0,0 +1,28 @@ +package org.gcube.resourcemanagement.support.client.events; + +import com.google.gwt.event.shared.GwtEvent; + + + +public class SetScopeEvent extends GwtEvent { + public static Type TYPE = new Type(); + + private String scope2Set; + + public String getScope() { + return scope2Set; + } + public SetScopeEvent(String scope2Set) { + this.scope2Set = scope2Set; + } + + @Override + public Type getAssociatedType() { + return TYPE; + } + + @Override + protected void dispatch(SetScopeEventHandler handler) { + handler.onSetScope(this); + } +} diff --git a/src/main/java/org/gcube/resourcemanagement/support/client/events/SetScopeEventHandler.java b/src/main/java/org/gcube/resourcemanagement/support/client/events/SetScopeEventHandler.java new file mode 100644 index 0000000..6e6bfbc --- /dev/null +++ b/src/main/java/org/gcube/resourcemanagement/support/client/events/SetScopeEventHandler.java @@ -0,0 +1,7 @@ +package org.gcube.resourcemanagement.support.client.events; + +import com.google.gwt.event.shared.EventHandler; + +public interface SetScopeEventHandler extends EventHandler { + void onSetScope(SetScopeEvent event); +} diff --git a/src/main/java/org/gcube/resourcemanagement/support/client/utils/CurrentStatus.java b/src/main/java/org/gcube/resourcemanagement/support/client/utils/CurrentStatus.java new file mode 100644 index 0000000..c983e72 --- /dev/null +++ b/src/main/java/org/gcube/resourcemanagement/support/client/utils/CurrentStatus.java @@ -0,0 +1,126 @@ +/**************************************************************************** + * This software is part of the gCube Project. + * Site: http://www.gcube-system.org/ + **************************************************************************** + * The gCube/gCore software is licensed as Free Open Source software + * conveying to the EUPL (http://ec.europa.eu/idabc/eupl). + * The software and documentation is provided by its authors/distributors + * "as is" and no expressed or + * implied warranty is given for its use, quality or fitness for a + * particular case. + **************************************************************************** + * Filename: CurrentStatus.java + **************************************************************************** + * @author Daniele Strollo + ***************************************************************************/ + +package org.gcube.resourcemanagement.support.client.utils; + +import java.io.Serializable; + +import org.gcube.resourcemanagement.support.client.Resource_support; +import org.gcube.resourcemanagement.support.client.events.SetScopeEvent; +import org.gcube.resourcemanagement.support.shared.types.RunningMode; +import org.gcube.resourcemanagement.support.shared.types.UserGroup; + +import com.google.gwt.core.client.GWT; +import com.google.gwt.event.shared.HandlerManager; + +/** + * @author Daniele Strollo (ISTI-CNR) + */ +public final class CurrentStatus implements Serializable { + private static final long serialVersionUID = 6487678609485417222L; + private String currentScope = "/gcube/devsec"; + private String currentResourceType = null; + private String currentResourceSubType = ""; + private String currentUser = "anonymous"; + private UserGroup credentials = UserGroup.DEBUG; + private RunningMode runningMode = RunningMode.STANDALONE; + private boolean useCache = false; + private boolean loadGHNatStartup = true; + + public CurrentStatus() { + } + + public boolean useCache() { + return this.useCache; + } + + public void setUseCache(final boolean useCache) { + this.useCache = useCache; + } + + public void setCurrentScope(final String scope) { + if (scope != null) { + currentScope = scope.trim(); + } + Resource_support.get().getEventBus().fireEvent(new SetScopeEvent(scope)); + GWT.log("Set Scope event sent for " + scope); + //Commands.setStatusScope(scope); + } + + public String getCurrentScope() { + return currentScope; + } + + public void setCurrentResourceType(final String resType) { + if (resType != null) { + currentResourceType = resType.trim(); + } else { + currentResourceType = null; + } + } + + public String getCurrentResourceType() { + return currentResourceType; + } + + public String getCurrentResourceSubType() { + return currentResourceSubType; + } + + public void setCurrentResourceSubType(final String currentResourceSubType) { + if (currentResourceSubType != null) { + this.currentResourceSubType = currentResourceSubType.trim(); + } else { + this.currentResourceSubType = null; + } + } + + public UserGroup getCredentials() { + return credentials; + } + + public void setCredentials(final UserGroup credentials) { + this.credentials = credentials; + } + + public void setRunningMode(final RunningMode runningMode) { + this.runningMode = runningMode; + } + + public RunningMode getRunningMode() { + return runningMode; + } + + public void setCurrentUser(final String currentUser) { + if (currentUser != null) { + this.currentUser = currentUser.trim(); + } else { + this.currentUser = null; + } + } + + public String getCurrentUser() { + return currentUser; + } + + public boolean isLoadGHNatStartup() { + return loadGHNatStartup; + } + + public void setLoadGHNatStartup(boolean loadGHNatStartup) { + this.loadGHNatStartup = loadGHNatStartup; + } +} diff --git a/src/main/java/org/gcube/resourcemanagement/support/client/utils/StatusHandler.java b/src/main/java/org/gcube/resourcemanagement/support/client/utils/StatusHandler.java new file mode 100644 index 0000000..86592bc --- /dev/null +++ b/src/main/java/org/gcube/resourcemanagement/support/client/utils/StatusHandler.java @@ -0,0 +1,37 @@ +/**************************************************************************** + * This software is part of the gCube Project. + * Site: http://www.gcube-system.org/ + **************************************************************************** + * The gCube/gCore software is licensed as Free Open Source software + * conveying to the EUPL (http://ec.europa.eu/idabc/eupl). + * The software and documentation is provided by its authors/distributors + * "as is" and no expressed or + * implied warranty is given for its use, quality or fitness for a + * particular case. + **************************************************************************** + * Filename: StatusHandler.java + **************************************************************************** + * @author Daniele Strollo + ***************************************************************************/ + +package org.gcube.resourcemanagement.support.client.utils; + + + + +/** + * @author Daniele Strollo (ISTI-CNR) + * + */ +public class StatusHandler { + + private static CurrentStatus status = new CurrentStatus(); + + public static final synchronized void setStatus(final CurrentStatus status) { + StatusHandler.status = status; + } + + public static final synchronized CurrentStatus getStatus() { + return StatusHandler.status; + } +} diff --git a/src/main/java/org/gcube/resourcemanagement/support/client/views/validators/XMLValidator.java b/src/main/java/org/gcube/resourcemanagement/support/client/views/validators/XMLValidator.java new file mode 100644 index 0000000..9f6f7e2 --- /dev/null +++ b/src/main/java/org/gcube/resourcemanagement/support/client/views/validators/XMLValidator.java @@ -0,0 +1,45 @@ +/**************************************************************************** + * This software is part of the gCube Project. + * Site: http://www.gcube-system.org/ + **************************************************************************** + * The gCube/gCore software is licensed as Free Open Source software + * conveying to the EUPL (http://ec.europa.eu/idabc/eupl). + * The software and documentation is provided by its authors/distributors + * "as is" and no expressed or + * implied warranty is given for its use, quality or fitness for a + * particular case. + **************************************************************************** + * Filename: XMLValidator.java + **************************************************************************** + * @author Daniele Strollo + ***************************************************************************/ + +package org.gcube.resourcemanagement.support.client.views.validators; + +import com.extjs.gxt.ui.client.widget.form.Field; +import com.extjs.gxt.ui.client.widget.form.Validator; +import com.google.gwt.xml.client.XMLParser; +import com.google.gwt.xml.client.impl.DOMParseException; + +/** + * @author Daniele Strollo (ISTI-CNR) + * + */ +public class XMLValidator implements Validator { + private String rootNode = "body"; + + public XMLValidator(final String rootNode) { + this.rootNode = rootNode; + } + + public final String validate(final Field field, final String value) { + try { + XMLParser.parse("<" + this.rootNode + ">" + value + ""); + } catch (DOMParseException e) { + return "Not a valid XML document"; + } + return null; + } +} + + diff --git a/src/main/java/org/gcube/resourcemanagement/support/shared/operations/SupportedOperations.java b/src/main/java/org/gcube/resourcemanagement/support/shared/operations/SupportedOperations.java new file mode 100644 index 0000000..1d98126 --- /dev/null +++ b/src/main/java/org/gcube/resourcemanagement/support/shared/operations/SupportedOperations.java @@ -0,0 +1,88 @@ +/**************************************************************************** + * This software is part of the gCube Project. + * Site: http://www.gcube-system.org/ + **************************************************************************** + * The gCube/gCore software is licensed as Free Open Source software + * conveying to the EUPL (http://ec.europa.eu/idabc/eupl). + * The software and documentation is provided by its authors/distributors + * "as is" and no expressed or + * implied warranty is given for its use, quality or fitness for a + * particular case. + **************************************************************************** + * Filename: SupportedOperations.java + **************************************************************************** + * @author Daniele Strollo + ***************************************************************************/ + +package org.gcube.resourcemanagement.support.shared.operations; + +import org.gcube.resourcemanagement.support.shared.types.UserGroup; + +/** + * @author Daniele Strollo (ISTI-CNR) + * + */ +public enum SupportedOperations { + GHN_SHUTDOWN(UserGroup.ADMIN), + GHN_RESTART(UserGroup.ADMIN), + GHN_CLEAN_RESTART(UserGroup.ADMIN), + GHN_DELETE(UserGroup.ADMIN), + GHN_FORCE_DELETE(UserGroup.SUPERUSER, UserGroup.ADMIN), + + GENERIC_RESOURCE_CREATE(UserGroup.ADMIN), + GENERIC_RESOURCE_EDIT(UserGroup.ADMIN), + GENERIC_RESOURCE_DELETE(UserGroup.ADMIN), + GENERIC_RESOURCE_FORCE_DELETE(UserGroup.SUPERUSER, UserGroup.ADMIN), + + RUNTIME_RESOURCE_DELETE(UserGroup.ADMIN), + RUNTIME_RESOURCE_FORCE_DELETE(UserGroup.SUPERUSER, UserGroup.ADMIN), + + SERVICE_CREATE(UserGroup.ADMIN), + SERVICE_DEPLOY(UserGroup.ADMIN), + SERVICE_GET_REPORT(UserGroup.ADMIN, UserGroup.DEBUG), + SERVICE_GET_RESOURCE_BY_ID(UserGroup.ADMIN, UserGroup.DEBUG, UserGroup.USER), + + RUNNING_INSTANCE_UNDEPLOY(UserGroup.ADMIN), + + COLLECTION_DELETE(UserGroup.ADMIN), + COLLECTION_FORCE_DELETE(UserGroup.SUPERUSER, UserGroup.ADMIN), + + VIEW_DELETE(UserGroup.ADMIN), + VIEW_FORCE_DELETE(UserGroup.SUPERUSER, UserGroup.ADMIN), + + ADD_TO_SCOPE(UserGroup.ADMIN), + + SWEEP_GHN(UserGroup.ADMIN), + + CREATE_MENU_SHOW(UserGroup.ADMIN, UserGroup.DEBUG), + INFRASTRUCTURE_UPGRADE(UserGroup.ADMIN, UserGroup.DEBUG); + + private UserGroup[] permissions = null; + + private SupportedOperations(final UserGroup...permissions) { + this.permissions = permissions; + } + + public UserGroup[] getPermissions() { + return this.permissions; + } + + /** + * States if a group is allowed to execute an operation. + * @param permission + * @return + */ + public boolean isAllowed(final UserGroup permission) { + if (this.getPermissions() == null + || this.getPermissions().length == 0 + || permission == null) { + return false; + } + for (UserGroup g : this.getPermissions()) { + if (g.equals(permission)) { + return true; + } + } + return false; + } +}