/** * 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; }
public static Asset toAsset(AssetItem a, UriInfo uriInfo) { AssetMetadata metadata = new AssetMetadata(); metadata.setUuid(a.getUUID()); metadata.setCreated(a.getCreatedDate().getTime()); metadata.setDisabled(a.getDisabled()); metadata.setFormat(a.getFormat()); metadata.setNote("<![CDATA[ " + a.getCheckinComment() + " ]]>"); metadata.setCheckInComment(a.getCheckinComment()); metadata.setVersionNumber(a.getVersionNumber()); List<CategoryItem> categories = a.getCategories(); // TODO: Is this a bug since cat's are never assigned to metadata after this? String[] cats = new String[categories.size()]; int counter = 0; for (CategoryItem c : categories) { cats[counter++] = c.getName(); } Asset ret = new Asset(); ret.setTitle(a.getTitle()); ret.setBinaryContentAttachmentFileName(a.getBinaryContentAttachmentFileName()); ret.setPublished(a.getLastModified().getTime()); ret.setAuthor(a.getLastContributor()); ret.setMetadata(metadata); ret.setDescription(a.getDescription()); ret.setRefLink( uriInfo .getBaseUriBuilder() .path("/packages/{packageName}/assets/{assetName}") .build(a.getModule().getName(), a.getName())); ret.setBinaryLink( uriInfo .getBaseUriBuilder() .path("/packages/{packageName}/assets/{assetName}/binary") .build(a.getModule().getName(), a.getName())); ret.setSourceLink( uriInfo .getBaseUriBuilder() .path("/packages/{packageName}/assets/{assetName}/source") .build(a.getModule().getName(), a.getName())); return ret; }