@LoggedIn
 public long getAssetCount(AssetPageRequest request) throws SerializationException {
   if (request == null) {
     throw new IllegalArgumentException("request cannot be null");
   }
   return repositoryAssetOperations.getAssetCount(request);
 }
 /** @deprecated in favour of {@link #quickFindAsset(QueryPageRequest)} */
 @WebRemote
 @LoggedIn
 public TableDataResult quickFindAsset(
     String searchText, boolean searchArchived, int skip, int numRows)
     throws SerializationException {
   return repositoryAssetOperations.quickFindAsset(searchText, searchArchived, skip, numRows);
 }
  @WebRemote
  @LoggedIn
  public String renameAsset(String uuid, String newName) {
    AssetItem item = rulesRepository.loadAssetByUUID(uuid);
    serviceSecurity.checkIsPackageDeveloperOrAnalyst(item);

    return repositoryAssetOperations.renameAsset(uuid, newName);
  }
  @WebRemote
  @Restrict("#{identity.loggedIn}")
  public String renameAsset(String uuid, String newName) {
    AssetItem item = getRulesRepository().loadAssetByUUID(uuid);
    serviceSecurity.checkSecurityIsPackageDeveloper(item);

    return repositoryAssetOperations.renameAsset(uuid, newName);
  }
  @WebRemote
  @LoggedIn
  public TableDataResult loadItemHistory(String uuid) throws SerializationException {
    // VersionableItem assetItem = rulesRepository.loadAssetByUUID( uuid );
    VersionableItem assetItem = rulesRepository.loadItemByUUID(uuid);

    // serviceSecurity.checkSecurityAssetPackagePackageReadOnly( assetItem );
    return repositoryAssetOperations.loadItemHistory(assetItem);
  }
  /** @deprecated in favour of {@link loadArchivedAssets(PageRequest)} */
  @WebRemote
  @Restrict("#{identity.loggedIn}")
  public TableDataResult loadAssetHistory(String packageUUID, String assetName)
      throws SerializationException {
    PackageItem pi = getRulesRepository().loadPackageByUUID(packageUUID);
    AssetItem assetItem = pi.loadAsset(assetName);
    serviceSecurity.checkSecurityAssetPackagePackageReadOnly(assetItem);

    return repositoryAssetOperations.loadItemHistory(assetItem);
  }
  /** @deprecated in favour of {@link #loadArchivedAssets(PageRequest)} */
  @WebRemote
  @LoggedIn
  public TableDataResult loadAssetHistory(String packageUUID, String assetName)
      throws SerializationException {
    ModuleItem pi = rulesRepository.loadModuleByUUID(packageUUID);
    AssetItem assetItem = pi.loadAsset(assetName);
    serviceSecurity.checkSecurityPackageReadOnlyWithPackageUuid(assetItem.getModule().getUUID());

    return repositoryAssetOperations.loadItemHistory(assetItem);
  }
 /** @deprecated in favour of {@link ServiceImplementation#queryFullText(QueryPageRequest)} */
 @WebRemote
 @LoggedIn
 public TableDataResult queryFullText(String text, boolean seekArchived, int skip, int numRows)
     throws SerializationException {
   if (numRows == 0) {
     throw new DetailedSerializationException(
         "Unable to return zero results (bug)",
         "probably have the parameters around the wrong way, sigh...");
   }
   return repositoryAssetOperations.queryFullText(text, seekArchived, skip, numRows);
 }
 /** @deprecated in favour of {@link #findAssetPage(AssetPageRequest)} */
 @WebRemote
 @LoggedIn
 public TableDataResult listAssets(
     String packageUuid, String formats[], int skip, int numRows, String tableConfig)
     throws SerializationException {
   log.debug("Loading asset list for [" + packageUuid + "]");
   if (numRows == 0) {
     throw new DetailedSerializationException(
         "Unable to return zero results (bug)",
         "probably have the parameters around the wrong way, sigh...");
   }
   return repositoryAssetOperations.listAssets(packageUuid, formats, skip, numRows, tableConfig);
 }
  @WebRemote
  @LoggedIn
  public PageResponse<QueryPageRow> quickFindAsset(QueryPageRequest request)
      throws SerializationException {
    if (request == null) {
      throw new IllegalArgumentException("request cannot be null");
    }
    if (request.getPageSize() != null && request.getPageSize() < 0) {
      throw new IllegalArgumentException("pageSize cannot be less than zero.");
    }

    return repositoryAssetOperations.quickFindAsset(request);
  }
  @WebRemote
  @Restrict("#{identity.loggedIn}")
  public PageResponse<AssetPageRow> findAssetPage(AssetPageRequest request)
      throws SerializationException {
    if (request == null) {
      throw new IllegalArgumentException("request cannot be null");
    }
    if (request.getPageSize() != null && request.getPageSize() < 0) {
      throw new IllegalArgumentException("pageSize cannot be less than zero.");
    }

    return repositoryAssetOperations.findAssetPage(request);
  }
  @WebRemote
  @LoggedIn
  public PageResponse<AdminArchivedPageRow> loadArchivedAssets(PageRequest request)
      throws SerializationException {
    if (request == null) {
      throw new IllegalArgumentException("request cannot be null");
    }
    if (request.getPageSize() != null && request.getPageSize() < 0) {
      throw new IllegalArgumentException("pageSize cannot be less than zero.");
    }

    return repositoryAssetOperations.loadArchivedAssets(request);
  }
  /**
   * 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;
  }
  @WebRemote
  @LoggedIn
  public String checkinVersion(Asset asset) throws SerializationException {
    serviceSecurity.checkIsPackageDeveloperOrAnalyst(asset);

    log.info(
        "USER:"******" CHECKING IN asset: ["
            + asset.getName()
            + "] UUID: ["
            + asset.getUuid()
            + "] ");
    return repositoryAssetOperations.checkinVersion(asset);
  }
  /**
   * 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
  @LoggedIn
  public Asset loadRuleAsset(String uuid) throws SerializationException {

    long time = System.currentTimeMillis();

    AssetItem item = rulesRepository.loadAssetByUUID(uuid);
    Asset asset = new AssetPopulator().populateFrom(item);

    asset.setMetaData(repositoryAssetOperations.populateMetaData(item));

    serviceSecurity.checkIsPackageReadOnlyOrAnalystReadOnly(asset);
    ModuleItem 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;
  }
 @WebRemote
 @Restrict("#{identity.loggedIn}")
 public BuilderResult buildAsset(RuleAsset asset) throws SerializationException {
   serviceSecurity.checkSecurityIsPackageDeveloper(asset);
   return repositoryAssetOperations.buildAsset(asset);
 }
 /*
  * (non-Javadoc)
  * @see
  * org.drools.guvnor.client.rpc.RepositoryService#getAssetLockerUserName
  * (java.lang.String)
  */
 @LoggedIn
 public String getAssetLockerUserName(String uuid) {
   return repositoryAssetOperations.getAssetLockerUserName(uuid);
 }
 @LoggedIn
 public void clearAllDiscussionsForAsset(final String assetId) {
   serviceSecurity.checkSecurityIsAdmin();
   repositoryAssetOperations.clearAllDiscussionsForAsset(assetId);
 }
 @LoggedIn
 public List<DiscussionRecord> addToDiscussionForAsset(String assetId, String comment) {
   return repositoryAssetOperations.addToDiscussionForAsset(assetId, comment);
 }
 /*
  * (non-Javadoc)
  *
  * @see
  * org.drools.guvnor.client.rpc.RepositoryService#unLockAsset(java.lang.
  * String)
  */
 @Restrict("#{identity.loggedIn}")
 public void unLockAsset(String uuid) {
   repositoryAssetOperations.unLockAsset(uuid);
 }
 /*
  * (non-Javadoc)
  * @see
  * org.drools.guvnor.client.rpc.RepositoryService#unLockAsset(java.lang.
  * String)
  */
 @LoggedIn
 public void unLockAsset(String uuid) {
   repositoryAssetOperations.unLockAsset(uuid);
 }
 @Restrict("#{identity.loggedIn}")
 public List<DiscussionRecord> addToDiscussionForAsset(String assetId, String comment) {
   return repositoryAssetOperations.addToDiscussionForAsset(assetId, comment);
 }
 /*
  * (non-Javadoc)
  *
  * @see
  * org.drools.guvnor.client.rpc.RepositoryService#getAssetLockerUserName
  * (java.lang.String)
  */
 @Restrict("#{identity.loggedIn}")
 public String getAssetLockerUserName(String uuid) {
   return repositoryAssetOperations.getAssetLockerUserName(uuid);
 }
 @WebRemote
 @LoggedIn
 public BuilderResult validateAsset(Asset asset) throws SerializationException {
   serviceSecurity.checkIsPackageDeveloperOrAnalyst(asset);
   return repositoryAssetOperations.validateAsset(asset);
 }
 @Create
 public void create() {
   repositoryAssetOperations.setRulesRepository(getRulesRepository());
 }
 @WebRemote
 @LoggedIn
 public String buildAssetSource(Asset asset) throws SerializationException {
   serviceSecurity.checkIsPackageDeveloperOrAnalyst(asset);
   return repositoryAssetOperations.buildAssetSource(asset);
 }
 @WebRemote
 @LoggedIn
 public void restoreVersion(String versionUUID, String assetUUID, String comment) {
   repositoryAssetOperations.restoreVersion(versionUUID, assetUUID, comment);
 }
 @WebRemote
 @LoggedIn
 @Deprecated
 public TableDataResult loadArchivedAssets(int skip, int numRows) throws SerializationException {
   return repositoryAssetOperations.loadArchivedAssets(skip, numRows);
 }