private boolean isComponentWriteableByUser(AbstractComponent component) { Platform p = PlatformAccess.getPlatform(); PolicyContext policyContext = new PolicyContext(); policyContext.setProperty(PolicyContext.PropertyName.TARGET_COMPONENT.getName(), component); policyContext.setProperty(PolicyContext.PropertyName.ACTION.getName(), 'w'); String inspectionKey = PolicyInfo.CategoryType.OBJECT_INSPECTION_POLICY_CATEGORY.getKey(); return p.getPolicyManager().execute(inspectionKey, policyContext).getStatus(); }
@BeforeMethod public void setup() { MockitoAnnotations.initMocks(this); policy = new PlotStringPolicy(); context = new PolicyContext(); viewInfo = new ViewInfo(PlotViewManifestation.class, "Plot", ViewType.OBJECT); context.setProperty(PolicyContext.PropertyName.TARGET_VIEW_INFO.getName(), viewInfo); context.setProperty(PolicyContext.PropertyName.TARGET_COMPONENT.getName(), mockProvider); }
@Override public boolean isEnabled() { List<AbstractComponent> components = new ArrayList<AbstractComponent>(selectedManifestations.size()); for (View view : selectedManifestations) { components.add(view.getManifestedComponent()); } // disable use for objects which cannot be contained PolicyContext context = new PolicyContext(); context.setProperty(PolicyContext.PropertyName.SOURCE_COMPONENTS.getName(), components); String policyCategoryKey = PolicyInfo.CategoryType.CAN_OBJECT_BE_CONTAINED_CATEGORY.getKey(); ExecutionResult result = PolicyManagerImpl.getInstance().execute(policyCategoryKey, context); return result.getStatus(); }
@Override public boolean canHandle(ActionContext context) { if (context.getSelectedManifestations().isEmpty()) return false; AbstractComponent targetComponent = context.getSelectedManifestations().iterator().next().getManifestedComponent(); PolicyContext policyContext = new PolicyContext(); policyContext.setProperty( PolicyContext.PropertyName.TARGET_COMPONENT.getName(), targetComponent); policyContext.setProperty(PolicyContext.PropertyName.ACTION.getName(), 'w'); String compositionKey = PolicyInfo.CategoryType.COMPOSITION_POLICY_CATEGORY.getKey(); return (context.getSelectedManifestations().size() == 1) && PlatformAccess.getPlatform() .getPolicyManager() .execute(compositionKey, policyContext) .getStatus(); }