Package gov.nasa.arc.mct.policy

Examples of gov.nasa.arc.mct.policy.ExecutionResult


*/
public class PreferredViewPolicy implements Policy {

    @Override
    public ExecutionResult execute(PolicyContext context) {
        return new ExecutionResult(context,true,"");
    }
View Full Code Here


public class ObjectPermissionPolicy implements Policy {
    private static String ANY_USER = "*";

    @Override
    public ExecutionResult execute(PolicyContext context) {
        ExecutionResult result = new ExecutionResult(context, true, "");
       
        AbstractComponent component = context.getProperty("TARGET", AbstractComponent.class);
        char action = (Character) context.getProperty("ACTION");
        switch(action) {
            case 'w': result.setStatus(isComposable(component)); break;
            case 'r': result.setStatus(isAccessible(component)); break;
            default: break;
        }
       
        if (!result.getStatus())
            result.setMessage("Permission denied on " + component.getDisplayName());
       
        return result;
    }
View Full Code Here

    public CanDeleteComponentPolicy() {
    }
   
    @Override
    public ExecutionResult execute(PolicyContext context) {
        ExecutionResult result = new ExecutionResult(context);
        result.setStatus(true);
        AbstractComponent component = context.getProperty(PolicyContext.PropertyName.TARGET_COMPONENT.getName(), AbstractComponent.class);
       
        if (component instanceof MineTaxonomyComponent) {
            result.setStatus(false);
            result.setMessage("Cannot delete My Sandbox.");
        } else if (!component.getOwner().equals(PlatformAccess.getPlatform().getCurrentUser().getUserId())) {
            result.setStatus(false);
            result.setMessage(component.getDisplayName() + " cannot be deleted because it is owned by " + component.getOwner() + ".");
        }

        return result;
    }
View Full Code Here

   
    static final String[] RESERVED_WORDS = {"drop box", "dropbox"};

    @Override
    public ExecutionResult execute(PolicyContext context) {
      ExecutionResult result = new ExecutionResult(context, true, "");
       
        String name = context.getProperty("NAME", String.class);
        String found = "";
       
        for (int i=0; i<RESERVED_WORDS.length; i++) {
       
            if (name.toLowerCase().indexOf(RESERVED_WORDS[i].toLowerCase()) > -1) {
                result.setStatus(false);
                found = RESERVED_WORDS[i];             
            }
        }
       
        if (!result.getStatus())
            result.setMessage("Name must not contain the words \"" + found + "\"");
       
        return result;
    }
View Full Code Here

    @Override
    public ExecutionResult execute(PolicyContext context) {
        @SuppressWarnings("unchecked")
        Collection<AbstractComponent> sourceComponents = context.getProperty(PolicyContext.PropertyName.SOURCE_COMPONENTS.getName(), Collection.class);
        if (sourceComponents == null) return new ExecutionResult(context, true, "");
       
        for (AbstractComponent component : sourceComponents) {
            if (MineTaxonomyComponent.class.isAssignableFrom(component.getClass())) {
                return new ExecutionResult(context, false, "cannot contain my sandbox");
            }
        }
       
        return new ExecutionResult(context, true, "");
    }
View Full Code Here

    public CanRemoveComponentPolicy() {
    }
   
    @Override
    public ExecutionResult execute(PolicyContext context) {
        ExecutionResult result = new ExecutionResult(context);
        result.setStatus(true);
        AbstractComponent component = context.getProperty(PolicyContext.PropertyName.TARGET_COMPONENT.getName(), AbstractComponent.class);
              
        if (component instanceof TelemetryUserDropBoxComponent) {
            String runtimeUser = PlatformAccess.getPlatform().getCurrentUser().getUserId();
            String usersDropBoxName = runtimeUser+ BUNDLE.getString("user_drop_box");
           
            if (component.getCreator().equals(runtimeUser) && component.getDisplayName().equals(usersDropBoxName)) {
                return result;
            } else {
                result.setStatus(false);
                result.setMessage(component.getDisplayName() + " cannot remove from a DropBox because the runtime user is not the DropBox owner.");
            }
        }
        return result;
    }
View Full Code Here

   
    private final String[] dropBoxComponentTypes = {TelemetryUserDropBoxComponent.class.getName()};

    @Override
    public ExecutionResult execute(PolicyContext context) {
        ExecutionResult trueResult = new ExecutionResult(context, true, "");

        AbstractComponent component = context.getProperty(PolicyContext.PropertyName.TARGET_COMPONENT.getName(), AbstractComponent.class);       
        if (!checkArguments(context, component))
            return trueResult; // pass it over to the next policy in the chain       

        ViewType viewType = context
                .getProperty(PolicyContext.PropertyName.VIEW_TYPE.getName(), ViewType.class);
        ViewInfo targetViewInfo = context.getProperty(PolicyContext.PropertyName.TARGET_VIEW_INFO.getName(), ViewInfo.class);
        if (viewType == ViewType.OBJECT || viewType == ViewType.CENTER) {
                if (DropboxCanvasView.class.isAssignableFrom(targetViewInfo.getViewClass()) ||
                        targetViewInfo.getViewName().equals("Info"))
                    return new ExecutionResult(context, true, "");
        }
        return new ExecutionResult(context, false, "");
    }
View Full Code Here

    @SuppressWarnings("unchecked")
    @Override
    public ExecutionResult execute(PolicyContext context) {
        char action = context.getProperty("ACTION", Character.class);
        if (action != 'w')
            return new ExecutionResult(context, true, "");

        AbstractComponent targetComponent = (AbstractComponent) context.getProperty("TARGET");
       
        // Context stores properties untyped, so we're forced to do an unchecked conversion here.
        Collection<AbstractComponent> sourceComponents = (Collection<AbstractComponent>) context.getProperty("SOURCES");
        if (sourceComponents != null) {
            for (AbstractComponent sourceComponent : sourceComponents) {
                if(isSameComponent(sourceComponent, targetComponent)) {
                   
                    return new ExecutionResult(context, false, " Cannot drop " + sourceComponent.getDisplayName() + " onto itself.");
                }
            }
        }
       
        return new ExecutionResult(context, true, "");
    }
View Full Code Here

    @Override
    public ExecutionResult execute(PolicyContext context) {
        AbstractComponent component = context.getProperty(PolicyContext.PropertyName.TARGET_COMPONENT.getName(), AbstractComponent.class);
        if (component == null)
            return new ExecutionResult(context, false, "Invalid component.");

        // "*" is the wildcard owner, so always allow this
        // Otherwise, check for a match on owner
        // Finally, check if there is Group ownership of this component
        User user = PlatformAccess.getPlatform().getCurrentUser();
        String owner = component.getOwner();
        if (!owner.equals("*") && !owner.equals(user.getUserId()) && !RoleAccess.hasRole(user, owner)) {
            Group group = component.getCapability(Group.class); // Check for group ownership
            String groupId = group != null ? group.getDiscipline() : null;
            if (groupId == null || !groupId.equals(PlatformAccess.getPlatform().getCurrentUser().getDisciplineId())) {
                return new ExecutionResult(context, false, "User does not own this component.");
            }
        }
           
       
        return new ExecutionResult(context, true, "");
    }
View Full Code Here

        ViewInfo viewInfo = context.getProperty(PolicyContext.PropertyName.TARGET_VIEW_INFO.getName(), ViewInfo.class);
        if (viewInfo.getViewType() == ViewType.OBJECT) {
            result = FeedView.class.isAssignableFrom(viewInfo.getViewClass());
        }
    }
    return new ExecutionResult(context, result, null);
  }
View Full Code Here

TOP

Related Classes of gov.nasa.arc.mct.policy.ExecutionResult

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.