@WebRemote
  @LoggedIn
  public void promoteAssetToGlobalArea(String uuid) {
    serviceSecurity.checkSecurityIsPackageDeveloperWithPackageName(RulesRepository.GLOBAL_AREA);
    AssetItem item = rulesRepository.loadAssetByUUID(uuid);
    serviceSecurity.checkSecurityIsPackageDeveloperWithPackageName(item.getModuleName());

    // Perform house-keeping for when an Asset is removed from a module
    attachmentRemoved(item);

    log.info(
        "USER:"******" CHANGING MODULE OF asset: ["
            + uuid
            + "] to [ globalArea ]");
    rulesRepository.moveRuleItemModule(
        RulesRepository.GLOBAL_AREA, uuid, "promote asset to globalArea");

    // Perform house-keeping for when an Asset is added to a module
    attachmentAdded(item);
  }
 private void archiveOrUnarchiveAsset(String uuid, boolean archive) {
   AssetItem item = rulesRepository.loadAssetByUUID(uuid);
   serviceSecurity.checkIsPackageDeveloperOrAnalyst(item);
   if (item.getModule().isArchived()) {
     throw new RulesRepositoryException(
         "The package ["
             + item.getModuleName()
             + "] that asset ["
             + item.getName()
             + "] belongs to is archived. You need to unarchive it first.");
   }
   log.info(
       "USER:"******" ARCHIVING asset: ["
           + item.getName()
           + "] UUID: ["
           + item.getUUID()
           + "] ");
   try {
     ContentHandler handler = getContentHandler(item);
     if (handler instanceof ICanHasAttachment) {
       ((ICanHasAttachment) handler).onAttachmentRemoved(item);
     }
   } catch (IOException e) {
     log.error("Unable to remove asset attachment", e);
   }
   item.archiveItem(archive);
   ModuleItem pkg = item.getModule();
   pkg.updateBinaryUpToDate(false);
   RuleBaseCache.getInstance().remove(pkg.getUUID());
   if (archive) {
     item.checkin("archived");
   } else {
     item.checkin("unarchived");
   }
   push("packageChange", pkg.getName());
 }
Beispiel #3
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;
  }