Search in sources :

Example 16 with Asset

use of com.google.cloud.asset.v1.Asset in project java-asset by googleapis.

the class BatchGetAssetsHistoryExample method main.

// Export assets for a project.
// @param args path where the results will be exported to.
public static void main(String... args) throws Exception {
    // Asset names, e.g.: "//storage.googleapis.com/[BUCKET_NAME]"
    String[] assetNames = args[0].split(",");
    try (AssetServiceClient client = AssetServiceClient.create()) {
        ProjectName parent = ProjectName.of(projectId);
        ContentType contentType = ContentType.CONTENT_TYPE_UNSPECIFIED;
        TimeWindow readTimeWindow = TimeWindow.newBuilder().build();
        BatchGetAssetsHistoryRequest request = BatchGetAssetsHistoryRequest.newBuilder().setParent(parent.toString()).addAllAssetNames(Arrays.asList(assetNames)).setContentType(contentType).setReadTimeWindow(readTimeWindow).build();
        BatchGetAssetsHistoryResponse response = client.batchGetAssetsHistory(request);
        System.out.println(response);
    }
}
Also used : ContentType(com.google.cloud.asset.v1.ContentType) ProjectName(com.google.cloud.asset.v1.ProjectName) AssetServiceClient(com.google.cloud.asset.v1.AssetServiceClient) BatchGetAssetsHistoryRequest(com.google.cloud.asset.v1.BatchGetAssetsHistoryRequest) BatchGetAssetsHistoryResponse(com.google.cloud.asset.v1.BatchGetAssetsHistoryResponse) TimeWindow(com.google.cloud.asset.v1.TimeWindow)

Example 17 with Asset

use of com.google.cloud.asset.v1.Asset in project java-asset by googleapis.

the class ListAssetsExample method listAssets.

public static void listAssets() throws IOException, IllegalArgumentException {
    // The project id of the asset parent to list.
    String projectId = "YOUR_PROJECT_ID";
    // The asset types to list. E.g.,
    // ["storage.googleapis.com/Bucket", "bigquery.googleapis.com/Table"].
    // See full list of supported asset types at
    // https://cloud.google.com/asset-inventory/docs/supported-asset-types.
    String[] assetTypes = { "YOUR_ASSET_TYPES_TO_LIST" };
    // The asset content type to list. E.g., ContentType.CONTENT_TYPE_UNSPECIFIED.
    // See full list of content types at
    // https://cloud.google.com/asset-inventory/docs/reference/rpc/google.cloud.asset.v1#contenttype
    ContentType contentType = ContentType.CONTENT_TYPE_UNSPECIFIED;
    listAssets(projectId, assetTypes, contentType);
}
Also used : ContentType(com.google.cloud.asset.v1.ContentType)

Example 18 with Asset

use of com.google.cloud.asset.v1.Asset in project tapestry-5 by apache.

the class AssetObjectProvider method provide.

/**
 * Provides the asset. If the expression does not identify an asset domain, with a prefix, it is assumed to be a
 * path on the classpath, relative to the root of the classpath.
 *
 * @param objectType the type of object (which must be Object or Asset)
 * @param locator    not used
 */
public <T> T provide(Class<T> objectType, AnnotationProvider annotationProvider, ObjectLocator locator) {
    Path path = annotationProvider.getAnnotation(Path.class);
    if (path == null)
        return null;
    String expanded = symbolSource.expandSymbols(path.value());
    Asset asset = source.getAsset(null, expanded, null);
    return typeCoercer.coerce(asset, objectType);
}
Also used : Path(org.apache.tapestry5.annotations.Path) Asset(org.apache.tapestry5.Asset)

Example 19 with Asset

use of com.google.cloud.asset.v1.Asset in project tapestry-5 by apache.

the class AssetSourceImpl method getLocalizedAssetFromResource.

private Asset getLocalizedAssetFromResource(Resource unlocalized, Locale locale) {
    final Resource localized;
    if (locale == null) {
        localized = unlocalized;
    } else {
        Reference<Asset> reference = cache.get(unlocalized);
        if (reference != null) {
            Asset asset = reference.get();
            if (asset != null) {
                // Prefer resource from cache to use its cache
                unlocalized = asset.getResource();
            }
        }
        localized = unlocalized.forLocale(locale);
    }
    if (localized == null || !localized.exists()) {
        throw new AssetNotFoundException(String.format("Unable to locate asset '%s' (the file does not exist).", unlocalized), unlocalized);
    }
    return getAssetForResource(localized);
}
Also used : Resource(org.apache.tapestry5.commons.Resource) Asset(org.apache.tapestry5.Asset) AssetNotFoundException(org.apache.tapestry5.services.AssetNotFoundException)

Example 20 with Asset

use of com.google.cloud.asset.v1.Asset in project tapestry-5 by apache.

the class AssetSourceImpl method createAssetFromResource.

private Asset createAssetFromResource(Resource resource) {
    try {
        upgradeReadLockToWriteLock();
        // Check for competing thread beat us to it (not very likely!):
        Asset result = TapestryInternalUtils.getAndDeref(cache, resource);
        if (result != null) {
            return result;
        }
        Class resourceClass = resource.getClass();
        AssetFactory factory = registry.get(resourceClass);
        return factory.createAsset(resource);
    } finally {
        downgradeWriteLockToReadLock();
    }
}
Also used : Asset(org.apache.tapestry5.Asset) AssetFactory(org.apache.tapestry5.services.AssetFactory)

Aggregations

Asset (org.apache.tapestry5.Asset)19 Resource (org.apache.tapestry5.commons.Resource)8 Test (org.testng.annotations.Test)7 AssetFactory (org.apache.tapestry5.services.AssetFactory)6 AssetSource (org.apache.tapestry5.services.AssetSource)6 ClasspathResource (org.apache.tapestry5.ioc.internal.util.ClasspathResource)5 ContentType (com.google.cloud.asset.v1.ContentType)4 ThreadLocale (org.apache.tapestry5.ioc.services.ThreadLocale)4 AssetServiceClient (com.google.cloud.asset.v1.AssetServiceClient)3 ComponentResources (org.apache.tapestry5.ComponentResources)3 Path (org.apache.tapestry5.annotations.Path)3 Test (org.junit.Test)3 Asset (com.google.cloud.asset.v1.Asset)2 ListAssetsPagedResponse (com.google.cloud.asset.v1.AssetServiceClient.ListAssetsPagedResponse)2 ListAssetsRequest (com.google.cloud.asset.v1.ListAssetsRequest)2 AbstractMessage (com.google.protobuf.AbstractMessage)2 ArrayList (java.util.ArrayList)2 ResourceName (com.google.api.resourcenames.ResourceName)1 BatchGetAssetsHistoryRequest (com.google.cloud.asset.v1.BatchGetAssetsHistoryRequest)1 BatchGetAssetsHistoryResponse (com.google.cloud.asset.v1.BatchGetAssetsHistoryResponse)1