public void testIgnoreArchivedItems() throws Exception {
    RulesRepository repo = getRepo();

    PackageItem pkg = repo.createPackage("testIgnoreArchivedItems", "");
    AssetItem model = pkg.addAsset("model", "qed");
    model.updateFormat(AssetFormats.MODEL);

    model.updateBinaryContentAttachment(this.getClass().getResourceAsStream("/billasurf.jar"));
    model.checkin("");

    ServiceImplementation.updateDroolsHeader(
        "import com.billasurf.Board\n global com.billasurf.Person customer", pkg);

    AssetItem rule1 = pkg.addAsset("rule_1", "");
    rule1.updateFormat(AssetFormats.DRL);
    rule1.updateContent("rule 'rule1' \n when Board() \n then customer.setAge(42); \n end");
    rule1.checkin("");

    AssetItem rule2 = pkg.addAsset("rule2", "");
    rule2.updateFormat(AssetFormats.DRL);
    rule2.updateContent("agenda-group 'q' \n when \n Boardx() \n then \n System.err.println(42);");
    rule2.checkin("");

    repo.save();

    ContentPackageAssembler asm = new ContentPackageAssembler(pkg);
    assertTrue(asm.hasErrors());

    rule2.archiveItem(true);
    rule2.checkin("");

    assertTrue(rule2.isArchived());
    asm = new ContentPackageAssembler(pkg);
    assertFalse(asm.hasErrors());
  }
コード例 #2
0
 void handleArchivedForSavePackage(PackageConfigData data, PackageItem item) {
   for (Iterator<AssetItem> iter = item.getAssets(); iter.hasNext(); ) {
     AssetItem assetItem = iter.next();
     if (!assetItem.isArchived()) {
       assetItem.archiveItem(true);
       assetItem.checkin(data.getDescription());
     }
   }
 }
コード例 #3
0
  public String getDRL() {
    StringBuffer src = new StringBuffer();
    src.append("package " + this.pkg.getName() + "\n");
    src.append(ServiceImplementation.getDroolsHeader(this.pkg) + "\n\n");

    // now we load up the DSL files
    builder.setDSLFiles(
        BRMSPackageBuilder.getDSLMappingFiles(
            pkg,
            new BRMSPackageBuilder.DSLErrorEvent() {
              public void recordError(AssetItem asset, String message) {
                errors.add(new ContentAssemblyError(asset, message));
              }
            }));

    // do the functions and declared types.
    AssetItemIterator it =
        this.pkg.listAssetsByFormat(new String[] {AssetFormats.FUNCTION, AssetFormats.DRL_MODEL});
    while (it.hasNext()) {
      AssetItem func = (AssetItem) it.next();
      if (!func.isArchived()) {
        src.append(func.getContent() + "\n\n");
      }
    }

    // now the rules
    Iterator iter = pkg.getAssets();
    while (iter.hasNext()) {
      AssetItem asset = (AssetItem) iter.next();
      if (!asset.isArchived()) {

        ContentHandler h = ContentManager.getHandler(asset.getFormat());
        if (h instanceof IRuleAsset) {
          IRuleAsset ruleAsset = (IRuleAsset) h;
          ruleAsset.assembleDRL(builder, asset, src);
        }

        src.append("\n\n");
      }
    }

    return src.toString();
  }
コード例 #4
0
  /** This will build the package. */
  private void buildPackage() {
    AssetSelector selector = SelectorManager.getInstance().getSelector(selectorConfigName);
    if (selector == null) {
      this.errors.add(
          new ContentAssemblyError(
              this.pkg, "The selector named " + selectorConfigName + " is not available."));
      return;
    }
    Iterator it = pkg.getAssets();
    while (it.hasNext()) {

      AssetItem asset = (AssetItem) it.next();

      if (!asset.isArchived() && (selector.isAssetAllowed(asset))) {
        buildAsset(asset);
      }
    }
  }
コード例 #5
0
  protected InputStream generateZip() {
    List<AssetItem> jarAssets = new LinkedList<AssetItem>();
    AssetZipper assetZipper = null;

    Iterator<AssetItem> assetItemIterator = getAssetItemIterator("jar", "wsdl", "xmlschema");
    while (assetItemIterator.hasNext()) {
      AssetItem assetItem = assetItemIterator.next();
      if (!assetItem.isArchived() && !assetItem.getDisabled()) {
        jarAssets.add(assetItem);
      }
    }
    if (jarAssets.size() != 0) {
      assetZipper = new AssetZipper(jarAssets, null);

      return assetZipper.zipAssets();
    }

    // REVISIT: return an empty zip instead?
    return null;
  }
コード例 #6
0
  private void addToVerifier(AssetItemIterator assets, ResourceType resourceType) {
    while (assets.hasNext()) {
      AssetItem asset = assets.next();
      if (!asset.isArchived() && !asset.getDisabled()) {
        if (resourceType == ResourceType.DTABLE) {
          DecisionTableConfiguration dtableconfiguration =
              KnowledgeBuilderFactory.newDecisionTableConfiguration();
          dtableconfiguration.setInputType(DecisionTableInputType.XLS);

          verifier.addResourcesToVerify(
              ResourceFactory.newByteArrayResource(asset.getBinaryContentAsBytes()),
              resourceType,
              (ResourceConfiguration) dtableconfiguration);
        } else {
          verifier.addResourcesToVerify(
              ResourceFactory.newReaderResource(new StringReader(asset.getContent())),
              resourceType);
        }
      }
    }
  }
コード例 #7
0
 private boolean isAssetArchivedOrRestored(AssetItem right, AssetItem left) {
   return right.isArchived() != left.isArchived();
 }
コード例 #8
0
  /** @deprecated in favour of {@link compareSnapshots(SnapshotComparisonPageRequest)} */
  protected SnapshotDiffs compareSnapshots(
      String packageName, String firstSnapshotName, String secondSnapshotName) {
    SnapshotDiffs diffs = new SnapshotDiffs();
    List<SnapshotDiff> list = new ArrayList<SnapshotDiff>();

    PackageItem leftPackage = rulesRepository.loadPackageSnapshot(packageName, firstSnapshotName);
    PackageItem rightPackage = rulesRepository.loadPackageSnapshot(packageName, secondSnapshotName);

    // Older one has to be on the left.
    if (isRightOlderThanLeft(leftPackage, rightPackage)) {
      PackageItem temp = leftPackage;
      leftPackage = rightPackage;
      rightPackage = temp;

      diffs.leftName = secondSnapshotName;
      diffs.rightName = firstSnapshotName;
    } else {
      diffs.leftName = firstSnapshotName;
      diffs.rightName = secondSnapshotName;
    }

    Iterator<AssetItem> leftExistingIter = leftPackage.getAssets();
    while (leftExistingIter.hasNext()) {
      AssetItem left = leftExistingIter.next();
      if (isPackageItemDeleted(rightPackage, left)) {
        SnapshotDiff diff = new SnapshotDiff();

        diff.name = left.getName();
        diff.diffType = SnapshotDiff.TYPE_DELETED;
        diff.leftUuid = left.getUUID();

        list.add(diff);
      }
    }

    Iterator<AssetItem> rightExistingIter = rightPackage.getAssets();
    while (rightExistingIter.hasNext()) {
      AssetItem right = rightExistingIter.next();
      AssetItem left = null;
      if (right != null && leftPackage.containsAsset(right.getName())) {
        left = leftPackage.loadAsset(right.getName());
      }

      // Asset is deleted or added
      if (right == null || left == null) {
        SnapshotDiff diff = new SnapshotDiff();

        if (left == null) {
          diff.name = right.getName();
          diff.diffType = SnapshotDiff.TYPE_ADDED;
          diff.rightUuid = right.getUUID();
        }

        list.add(diff);
      } else if (isAssetArchivedOrRestored(right, left)) { // Has the asset
        // been archived
        // or restored
        SnapshotDiff diff = new SnapshotDiff();

        diff.name = right.getName();
        diff.leftUuid = left.getUUID();
        diff.rightUuid = right.getUUID();

        if (left.isArchived()) {
          diff.diffType = SnapshotDiff.TYPE_RESTORED;
        } else {
          diff.diffType = SnapshotDiff.TYPE_ARCHIVED;
        }

        list.add(diff);
      } else if (isAssetItemUpdated(right, left)) { // Has the asset been
        // updated
        SnapshotDiff diff = new SnapshotDiff();

        diff.name = right.getName();
        diff.leftUuid = left.getUUID();
        diff.rightUuid = right.getUUID();
        diff.diffType = SnapshotDiff.TYPE_UPDATED;

        list.add(diff);
      }
    }

    diffs.diffs = list.toArray(new SnapshotDiff[list.size()]);
    return diffs;
  }
コード例 #9
0
  /*    public static Entry ToPackageEntry(PackageItem p, UriInfo uriInfo) {
      UriBuilder base;
      if(p.isHistoricalVersion()) {
          base = uriInfo.getBaseUriBuilder().path("packages").path(p.getName()).path("versions").path(Long.toString(p.getVersionNumber()));
      } else {
          base = uriInfo.getBaseUriBuilder().path("packages").path(p.getName());
      }

      //NOTE: Entry extension is not supported in RESTEasy. We need to either use Abdera or get extension
      //supported in RESTEasy
      //PackageMetadata metadata = new PackageMetadata();
      //metadata.setUuid(p.getUUID());
      //metadata.setCreated(p.getCreatedDate().getTime());
      //metadata.setLastModified(p.getLastModified().getTime());
      //metadata.setLastContributor(p.getLastContributor());
      //c.setJAXBObject(metadata);

      Entry e =new Entry();
      e.setTitle(p.getTitle());
      e.setSummary(p.getDescription());
      e.setPublished(new Date(p.getLastModified().getTimeInMillis()));
      e.setBase(base.clone().build());

      e.setId(base.clone().build());

      Iterator<AssetItem> i = p.getAssets();
      while (i.hasNext()) {
          AssetItem item = i.next();
          Link link = new Link();
          link.setHref((base.clone().path("assets").path(item.getName())).build());
          link.setTitle(item.getTitle());
          link.setRel("asset");
          e.getLinks().add(link);
      }

      Content c = new Content();
      c.setType(MediaType.APPLICATION_OCTET_STREAM_TYPE);
      c.setSrc(base.clone().path("binary").build());
      e.setContent(c);

      return e;
  }*/
  public static Entry toAssetEntryAbdera(AssetItem a, UriInfo uriInfo) {
    URI baseURL;
    if (a.isHistoricalVersion()) {
      baseURL =
          uriInfo
              .getBaseUriBuilder()
              .path("packages/{packageName}/assets/{assetName}/versions/{version}")
              .build(a.getModuleName(), a.getName(), Long.toString(a.getVersionNumber()));
    } else {
      baseURL =
          uriInfo
              .getBaseUriBuilder()
              .path("packages/{packageName}/assets/{assetName}")
              .build(a.getModuleName(), a.getName());
    }

    Factory factory = Abdera.getNewFactory();

    org.apache.abdera.model.Entry e = factory.getAbdera().newEntry();
    e.setTitle(a.getTitle());
    e.setSummary(a.getDescription());
    e.setPublished(new Date(a.getLastModified().getTimeInMillis()));
    e.setBaseUri(baseURL.toString());
    e.addAuthor(a.getLastContributor());

    e.setId(baseURL.toString());

    // generate meta data
    ExtensibleElement extension = e.addExtension(METADATA);
    ExtensibleElement childExtension = extension.addExtension(ARCHIVED);
    // childExtension.setAttributeValue("type", ArtifactsRepository.METADATA_TYPE_STRING);
    childExtension.addSimpleExtension(VALUE, a.isArchived() ? "true" : "false");

    childExtension = extension.addExtension(UUID);
    childExtension.addSimpleExtension(VALUE, a.getUUID());

    childExtension = extension.addExtension(STATE);
    childExtension.addSimpleExtension(VALUE, a.getState() == null ? "" : a.getState().getName());

    childExtension = extension.addExtension(FORMAT);
    childExtension.addSimpleExtension(VALUE, a.getFormat());

    childExtension = extension.addExtension(VERSION_NUMBER);
    childExtension.addSimpleExtension(VALUE, String.valueOf(a.getVersionNumber()));

    childExtension = extension.addExtension(CHECKIN_COMMENT);
    childExtension.addSimpleExtension(VALUE, a.getCheckinComment());

    List<CategoryItem> categories = a.getCategories();
    childExtension = extension.addExtension(CATEGORIES);
    for (CategoryItem c : categories) {
      childExtension.addSimpleExtension(VALUE, c.getName());
    }

    org.apache.abdera.model.Content content = factory.newContent();
    content.setSrc(UriBuilder.fromUri(baseURL).path("binary").build().toString());
    content.setMimeType("application/octet-stream");
    content.setContentType(Type.MEDIA);
    e.setContentElement(content);

    return e;
  }