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
This commit is contained in:
parent
d5070c094d
commit
124f2e204c
|
@ -1,9 +1,31 @@
|
||||||
package org.gcube.resourcemanagement.support.client;
|
package org.gcube.resourcemanagement.support.client;
|
||||||
|
|
||||||
import com.google.gwt.core.client.EntryPoint;
|
import com.google.gwt.core.client.EntryPoint;
|
||||||
|
import com.google.gwt.event.shared.HandlerManager;
|
||||||
|
|
||||||
public class Resource_support implements EntryPoint {
|
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.
|
* This is the entry point method.
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -0,0 +1,28 @@
|
||||||
|
package org.gcube.resourcemanagement.support.client.events;
|
||||||
|
|
||||||
|
import com.google.gwt.event.shared.GwtEvent;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public class SetScopeEvent extends GwtEvent<SetScopeEventHandler> {
|
||||||
|
public static Type<SetScopeEventHandler> TYPE = new Type<SetScopeEventHandler>();
|
||||||
|
|
||||||
|
private String scope2Set;
|
||||||
|
|
||||||
|
public String getScope() {
|
||||||
|
return scope2Set;
|
||||||
|
}
|
||||||
|
public SetScopeEvent(String scope2Set) {
|
||||||
|
this.scope2Set = scope2Set;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Type<SetScopeEventHandler> getAssociatedType() {
|
||||||
|
return TYPE;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void dispatch(SetScopeEventHandler handler) {
|
||||||
|
handler.onSetScope(this);
|
||||||
|
}
|
||||||
|
}
|
|
@ -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);
|
||||||
|
}
|
|
@ -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 <a href="mailto:daniele.strollo@isti.cnr.it">Daniele Strollo</a>
|
||||||
|
***************************************************************************/
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
|
@ -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 <a href="mailto:daniele.strollo@isti.cnr.it">Daniele Strollo</a>
|
||||||
|
***************************************************************************/
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
|
@ -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 <a href="mailto:daniele.strollo@isti.cnr.it">Daniele Strollo</a>
|
||||||
|
***************************************************************************/
|
||||||
|
|
||||||
|
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 + "</" + this.rootNode + ">");
|
||||||
|
} catch (DOMParseException e) {
|
||||||
|
return "Not a valid XML document";
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
@ -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 <a href="mailto:daniele.strollo@isti.cnr.it">Daniele Strollo</a>
|
||||||
|
***************************************************************************/
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue