示例#1
0
  public void retrieveAssetContent(RuleAsset asset, AssetItem item) throws SerializationException {
    RuleModel ruleModel = getBrlXmlPersistence().unmarshal(item.getContent());

    ruleModel.name = asset.getName();

    asset.setContent(ruleModel);
  }
  private PackageItem handlePackageItem(AssetItem item, RuleAsset asset)
      throws SerializationException {
    PackageItem pkgItem = item.getPackage();

    ContentHandler handler = ContentManager.getHandler(asset.metaData.format);
    handler.retrieveAssetContent(asset, pkgItem, item);

    asset.isreadonly = asset.metaData.hasSucceedingVersion;

    if (pkgItem.isSnapshot()) {
      asset.isreadonly = true;
    }
    return pkgItem;
  }
示例#3
0
  public void onSave() {
    // TODO: validate if the XML is valid

    RuleContentText rct = new RuleContentText();
    rct.content = text.getText();
    asset.content = rct;
  }
  public WorkingSetSelectorPopup(RuleModeller m, RuleAsset a) {
    this.modeller = m;
    this.asset = a;

    pop = new FormStylePopup();
    Constants constants = ((Constants) GWT.create(Constants.class));
    pop.setTitle(constants.SelectWorkingSets());
    Grid g = buildDoubleList(null);

    RepositoryServiceFactory.getAssetService()
        .listAssets(
            asset.getMetaData().getPackageUUID(),
            new String[] {AssetFormats.WORKING_SET},
            0,
            -1,
            "workingsetList",
            new GenericCallback<TableDataResult>() {

              public void onSuccess(TableDataResult result) {

                for (int i = 0; i < result.data.length; i++) {
                  if (WorkingSetManager.getInstance()
                      .isWorkingSetActive(
                          asset.getMetaData().getPackageName(), result.data[i].id)) {
                    selectedFacts.addItem(result.data[i].getDisplayName(), result.data[i].id);
                  } else {
                    availableFacts.addItem(result.data[i].getDisplayName(), result.data[i].id);
                  }
                }
              }
            });

    Button save = new Button(constants.SaveAndClose());
    save.addClickHandler(
        new ClickHandler() {
          public void onClick(ClickEvent event) {
            String[] wsUUIDs = new String[selectedFacts.getItemCount()];
            for (int i = 0; i < selectedFacts.getItemCount(); i++) {
              wsUUIDs[i] = selectedFacts.getValue(i);
            }

            WorkingSetManager.getInstance()
                .applyWorkingSets(
                    asset.getMetaData().getPackageName(),
                    wsUUIDs,
                    new Command() {
                      public void execute() {
                        LoadingPopup.close();
                        pop.hide();
                        modeller.refreshWidget();
                        modeller.verifyRule(null, true);
                      }
                    });
          }
        });

    pop.addRow(g);
    pop.addRow(save);
  }
示例#5
0
 public void storeAssetContent(RuleAsset asset, AssetItem repoAsset)
     throws SerializationException {
   RuleModel data = (RuleModel) asset.getContent();
   if (data.name == null) {
     data.name = repoAsset.getName();
   }
   repoAsset.updateContent(getBrlXmlPersistence().marshal(data));
 }
  @Test
  public void testStore() throws Exception {
    FactModelContentHandler ch = new FactModelContentHandler();

    RulesRepository repo = rulesRepository;

    PackageItem pkg = repo.loadDefaultPackage();
    AssetItem asset = pkg.addAsset("testDeclaredTypeStore", "");
    asset.updateFormat("model.drl");
    asset.updateContent("declare Foo\n name: String\n end");
    asset.checkin("");

    RuleAsset ass = new RuleAsset();
    ch.retrieveAssetContent(ass, asset);
    assertTrue(ass.getContent() instanceof FactModels);
    FactModels fm = (FactModels) ass.getContent();

    assertEquals(1, fm.models.size());
    FactMetaModel mm = (FactMetaModel) fm.models.get(0);
    assertEquals(1, mm.getFields().size());
    assertEquals("Foo", mm.getName());

    FieldMetaModel fmm = (FieldMetaModel) mm.getFields().get(0);
    assertEquals("name", fmm.name);

    mm.getFields().add(new FieldMetaModel("age", "int"));

    ch.storeAssetContent(ass, asset);

    assertTrue(asset.getContent().indexOf("age: int") > -1);

    asset.updateContent("rubbish here");
    asset.checkin("");

    ch.retrieveAssetContent(ass, asset);
    assertTrue(ass.getContent() instanceof RuleContentText);

    ch.storeAssetContent(ass, asset);

    assertEquals("rubbish here", asset.getContent());
  }
 public void onSave() {
   try {
     String s =
         callSave(
             ((IFrameElement) ((com.google.gwt.dom.client.Element) frame.getElement()))
                 .getContentDocument());
     String p =
         callPreprocessingData(
             ((IFrameElement) ((com.google.gwt.dom.client.Element) frame.getElement()))
                 .getContentDocument());
     if (asset.getContent() == null) {
       asset.setContent(new RuleFlowContentModel());
     }
     ((RuleFlowContentModel) asset.getContent()).setXml(null);
     ((RuleFlowContentModel) asset.getContent()).setJson(s);
     ((RuleFlowContentModel) asset.getContent()).setPreprocessingdata(p);
   } catch (Exception e) {
     GWT.log("JSNI method callSave() threw an exception:", e);
     Window.alert("JSNI method callSave() threw an exception: " + e);
   }
 }
  private AnalysisReport performAssetVerification(
      RuleAsset asset, boolean useVerifierDefaultConfig, Set<String> activeWorkingSets)
      throws SerializationException {
    long startTime = System.currentTimeMillis();

    if (Contexts.isSessionContextActive()) {
      Identity.instance()
          .checkPermission(
              new PackageNameType(asset.getMetaData().getPackageName()),
              RoleType.PACKAGE_DEVELOPER.getName());
    }

    PackageItem packageItem =
        getAssetService().getRulesRepository().loadPackage(asset.getMetaData().getPackageName());

    List<String> constraintRules = applyWorkingSets(activeWorkingSets);

    Verifier verifierToBeUsed = null;
    if (useVerifierDefaultConfig) {
      verifierToBeUsed = defaultVerifier;
    } else {
      verifierToBeUsed = getWorkingSetVerifier(constraintRules);
    }

    log.debug("constraints rules: " + constraintRules);

    try {
      VerifierRunner runner = new VerifierRunner(verifierToBeUsed);
      AnalysisReport report = runner.verify(packageItem, chooseScopesAgendaFilterFor(asset));

      verifierToBeUsed.flushKnowledgeSession();

      log.debug("Asset verification took: " + (System.currentTimeMillis() - startTime));

      return report;

    } catch (Throwable t) {
      throw new SerializationException(t.getMessage());
    }
  }
  private List<String> applyWorkingSets(Set<String> activeWorkingSets)
      throws SerializationException {
    if (activeWorkingSets == null) {
      return new LinkedList<String>();
    }

    RuleAsset[] workingSets =
        getAssetService()
            .loadRuleAssets(activeWorkingSets.toArray(new String[activeWorkingSets.size()]));
    List<String> constraintRules = new LinkedList<String>();
    if (workingSets != null) {
      for (RuleAsset workingSet : workingSets) {
        WorkingSetConfigData wsConfig = (WorkingSetConfigData) workingSet.getContent();
        if (wsConfig.constraints != null) {
          for (ConstraintConfiguration config : wsConfig.constraints) {
            constraintRules.add(ConstraintsFactory.getInstance().getVerifierRule(config));
          }
        }
      }
    }
    return constraintRules;
  }
  public DefaultRuleContentWidget(RuleAsset a, int visibleLines) {
    asset = a;
    data = (RuleContentText) asset.getContent();

    if (data.content == null) {
      data.content = "";
    }

    text = new TextArea();
    text.setWidth("100%");
    text.setVisibleLines((visibleLines == -1) ? 16 : visibleLines);
    text.setText(data.content);

    text.getElement().setAttribute("spellcheck", "false"); // NON-NLS

    text.setStyleName("default-text-Area"); // NON-NLS

    text.addChangeHandler(
        new ChangeHandler() {
          public void onChange(ChangeEvent event) {
            data.content = text.getText();
            makeDirty();
          }
        });

    text.addKeyDownHandler(
        new KeyDownHandler() {

          public void onKeyDown(KeyDownEvent event) {
            if (event.getNativeKeyCode() == KeyCodes.KEY_TAB) {
              int pos = text.getCursorPos();
              insertText("\t");
              text.setCursorPos(pos + 1);
              text.cancelKey();
              text.setFocus(true);
            }
          }
        });

    initWidget(text);
  }
示例#11
0
  public XmlFileWidget(final RuleAsset asset, final RuleViewer viewer) {
    super(asset, viewer);
    data = (RuleContentText) asset.getContent();

    if (data.content == null) {
      data.content = "";
    }

    text = new TextArea();
    text.setWidth("100%");
    text.setVisibleLines(16);
    text.setText(data.content);

    text.setStyleName("default-text-Area");

    text.addChangeHandler(
        new ChangeHandler() {
          public void onChange(ChangeEvent event) {
            data.content = text.getText();
          }
        });

    layout.addRow(text);
  }
 public BusinessProcessEditor(
     RuleAsset asset, RuleViewer viewer, ClientFactory clientFactory, EventBus eventBus) {
   this.asset = asset;
   modelUUID = asset.getUuid();
   initWidgets();
 }
  public WorkitemDefinitionEditor(RuleAsset a, int visibleLines) {
    asset = a;
    data = (RuleContentText) asset.getContent();
    if (data.content == null) {
      data.content = "Empty!";
    }

    Grid layout = new Grid(1, 2);

    WorkitemDefinitionElementsBrowser browser =
        new WorkitemDefinitionElementsBrowser(
            new WorkitemDefinitionElementSelectedListener() {

              public void onElementSelected(String elementName, String pasteValue) {
                insertText(pasteValue, true);
              }
            });

    layout.setWidget(0, 0, browser);
    text = new TextArea();
    text.setWidth("100%");
    text.setVisibleLines((visibleLines == -1) ? 25 : visibleLines);
    text.setText(data.content);
    text.getElement().setAttribute("spellcheck", "false"); // NON-NLS

    text.setStyleName("default-text-Area"); // NON-NLS

    text.addChangeHandler(
        new ChangeHandler() {
          public void onChange(ChangeEvent event) {
            data.content = text.getText();
            makeDirty();
          }
        });

    text.addKeyDownHandler(
        new KeyDownHandler() {

          public void onKeyDown(KeyDownEvent event) {
            if (event.getNativeKeyCode() == KeyCodes.KEY_TAB) {
              event.preventDefault();
              event.stopPropagation();
              int pos = text.getCursorPos();
              insertText("\t", false);
              text.setCursorPos(pos + 1);
              text.cancelKey();
              text.setFocus(true);
            }
          }
        });

    layout.setWidget(0, 1, text);

    layout.getColumnFormatter().setWidth(0, "10%");
    layout.getColumnFormatter().setWidth(1, "90%");
    layout
        .getCellFormatter()
        .setAlignment(0, 0, HasHorizontalAlignment.ALIGN_LEFT, HasVerticalAlignment.ALIGN_TOP);
    layout
        .getCellFormatter()
        .setAlignment(0, 1, HasHorizontalAlignment.ALIGN_LEFT, HasVerticalAlignment.ALIGN_TOP);
    layout.setWidth("95%");

    initWidget(layout);
  }
 private boolean isAssetDecisionTable(RuleAsset asset) {
   return AssetFormats.DECISION_TABLE_GUIDED.equals(asset.getMetaData().getFormat())
       || AssetFormats.DECISION_SPREADSHEET_XLS.equals(asset.getMetaData().getFormat());
 }
示例#15
0
  /**
   * This actually does the hard work of loading up an asset based on its format.
   *
   * <p>Role-based Authorization check: This method can be accessed if user has following
   * permissions: 1. The user has a ANALYST_READ role or higher (i.e., ANALYST) and this role has
   * permission to access the category which the asset belongs to. Or. 2. The user has a
   * package.readonly role or higher (i.e., package.admin, package.developer) and this role has
   * permission to access the package which the asset belongs to.
   */
  @WebRemote
  @Restrict("#{identity.loggedIn}")
  public RuleAsset loadRuleAsset(String uuid) throws SerializationException {

    long time = System.currentTimeMillis();

    AssetItem item = getRulesRepository().loadAssetByUUID(uuid);
    RuleAsset asset = new RuleAsset();

    asset.uuid = item.getUUID();
    asset.name = item.getName();
    asset.description = item.getDescription();
    asset.lastModified = item.getLastModified().getTime();
    asset.lastContributor = item.getLastContributor();
    asset.state = (item.getState() != null) ? item.getState().getName() : "";
    asset.dateCreated = item.getCreatedDate().getTime();
    asset.checkinComment = item.getCheckinComment();
    asset.versionNumber = item.getVersionNumber();

    // load standard meta data
    asset.metaData = repositoryAssetOperations.populateMetaData(item);

    // Verify if the user has permission to access the asset through package
    // based permission.
    // If failed, then verify if the user has permission to access the asset
    // through category
    // based permission
    if (Contexts.isSessionContextActive()) {

      try {
        Identity.instance()
            .checkPermission(
                new PackageNameType(asset.metaData.packageName), RoleTypes.PACKAGE_READONLY);
      } catch (RuntimeException e) {
        handleLoadRuleAssetException(asset);
      }
    }

    PackageItem pkgItem = handlePackageItem(item, asset);

    log.debug(
        "Package: "
            + pkgItem.getName()
            + ", asset: "
            + item.getName()
            + ". Load time taken for asset: "
            + (System.currentTimeMillis() - time));
    UserInbox.recordOpeningEvent(item);
    return asset;
  }
示例#16
0
 public void assembleDRL(
     BRMSPackageBuilder builder, RuleAsset asset, StringBuilder stringBuilder) {
   String drl = getSourceDRL((RuleModel) asset.getContent(), builder);
   stringBuilder.append(drl);
 }
示例#17
0
 public void compile(BRMSPackageBuilder builder, RuleAsset asset, AssemblyErrorLogger logger)
     throws DroolsParserException, IOException {
   builder.addPackageFromDrl(
       new StringReader(getSourceDRL((RuleModel) asset.getContent(), builder)));
 }