Search in sources :

Example 1 with ContentType

use of com.google.cloud.asset.v1.ContentType in project geotoolkit by Geomatys.

the class OwcXmlIO method readStyle.

private static MutableStyle readStyle(OfferingType offering, boolean def) throws JAXBException, FactoryException {
    final List<Object> content = offering.getOperationOrContentOrStyleSet();
    for (Object co : content) {
        if (co instanceof JAXBElement)
            co = ((JAXBElement) co).getValue();
        if (!(co instanceof StyleSetType))
            continue;
        final StyleSetType sst = (StyleSetType) co;
        if (sst.isDefault() != def)
            continue;
        final List<Object> ssc = sst.getNameOrTitleOrAbstract();
        for (Object ss : ssc) {
            if (ss instanceof JAXBElement)
                ss = ((JAXBElement) ss).getValue();
            if (!(ss instanceof ContentType))
                continue;
            final ContentType ct = (ContentType) ss;
            final List<Object> subcs = ct.getContent();
            for (Object subc : subcs) {
                if (subc instanceof JAXBElement)
                    subc = ((JAXBElement) subc).getValue();
                if (!(subc instanceof UserStyle))
                    continue;
                final StyleXmlIO io = new StyleXmlIO();
                return io.readStyle(subc, Specification.SymbologyEncoding.V_1_1_0);
            }
        }
    }
    return null;
}
Also used : UserStyle(org.geotoolkit.sld.xml.v110.UserStyle) ContentType(org.geotoolkit.owc.xml.v10.ContentType) StyleSetType(org.geotoolkit.owc.xml.v10.StyleSetType) StyleXmlIO(org.geotoolkit.sld.xml.StyleXmlIO) JAXBElement(javax.xml.bind.JAXBElement)

Example 2 with ContentType

use of com.google.cloud.asset.v1.ContentType in project geotoolkit by Geomatys.

the class OwcXmlIO method readEntry.

private static MapItem readEntry(final EntryType entry) throws JAXBException, FactoryException, DataStoreException {
    final List<Object> entryContent = entry.getAuthorOrCategoryOrContent();
    String layerName = "";
    String layerTitle = "";
    String layerAbstract = "";
    boolean visible = true;
    boolean selectable = true;
    double layerOpacity = 1.0;
    MapItem mapItem = null;
    MutableStyle baseStyle = null;
    MutableStyle selectionStyle = null;
    final List<MapItem> children = new ArrayList<>();
    for (Object o : entryContent) {
        QName name = null;
        if (o instanceof JAXBElement) {
            final JAXBElement jax = (JAXBElement) o;
            name = jax.getName();
            o = jax.getValue();
            if (GEOTK_FACTORY._Visible_QNAME.equals(name)) {
                visible = (Boolean) o;
            } else if (GEOTK_FACTORY._Selectable_QNAME.equals(name)) {
                selectable = (Boolean) o;
            } else if (GEOTK_FACTORY._Opacity_QNAME.equals(name)) {
                layerOpacity = (Double) o;
            }
        }
        if (o instanceof OfferingType) {
            final OfferingType offering = (OfferingType) o;
            for (OwcExtension ext : getExtensions()) {
                if (ext.getCode().equals(offering.getCode())) {
                    mapItem = ext.createLayer(offering);
                    break;
                }
            }
            // search for styles
            baseStyle = readStyle(offering, true);
            selectionStyle = readStyle(offering, false);
        } else if (o instanceof ContentType) {
            // decode children
            final ContentType content = (ContentType) o;
            final List<Object> contentContent = content.getContent();
            for (Object co : contentContent) {
                if (co instanceof JAXBElement) {
                    co = ((JAXBElement) o).getValue();
                }
                if (co instanceof EntryType) {
                    children.add(readEntry((EntryType) co));
                }
            }
        } else if (o instanceof IdType) {
            final IdType idType = (IdType) o;
            final String value = idType.getValue();
            layerName = value;
        } else if (o instanceof TextType) {
            final TextType tt = (TextType) o;
            if (ATOM_FACTORY._EntryTypeTitle_QNAME.equals(name)) {
                if (!tt.getContent().isEmpty()) {
                    layerTitle = (String) tt.getContent().get(0);
                }
            } else if (ATOM_FACTORY._EntryTypeSummary_QNAME.equals(name)) {
                if (!tt.getContent().isEmpty()) {
                    layerAbstract = (String) tt.getContent().get(0);
                }
            }
        }
    }
    if (mapItem == null) {
        mapItem = MapBuilder.createItem();
    } else if (mapItem instanceof MapLayer) {
        if (baseStyle != null) {
            ((MapLayer) mapItem).setStyle(baseStyle);
        }
        ((MapLayer) mapItem).setOpacity(layerOpacity);
    }
    mapItem.setIdentifier(layerName);
    mapItem.setTitle(layerTitle);
    mapItem.setAbstract(layerAbstract);
    mapItem.setVisible(visible);
    if (mapItem instanceof MapLayers) {
        ((MapLayers) mapItem).getComponents().addAll(children);
    } else if (!children.isEmpty()) {
        throw new IllegalArgumentException("MapLayer can not have children layers.");
    }
    return mapItem;
}
Also used : ContentType(org.geotoolkit.owc.xml.v10.ContentType) QName(javax.xml.namespace.QName) MapLayer(org.apache.sis.portrayal.MapLayer) ArrayList(java.util.ArrayList) JAXBElement(javax.xml.bind.JAXBElement) IdType(org.w3._2005.atom.IdType) TextType(org.w3._2005.atom.TextType) OfferingType(org.geotoolkit.owc.xml.v10.OfferingType) EntryType(org.w3._2005.atom.EntryType) MutableStyle(org.geotoolkit.style.MutableStyle) List(java.util.List) ArrayList(java.util.ArrayList) MapItem(org.apache.sis.portrayal.MapItem) MapLayers(org.apache.sis.portrayal.MapLayers)

Example 3 with ContentType

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

the class CreateFeedExample method createFeed.

// Create a feed
public static void createFeed(String[] assetNames, String feedId, String topic, String projectId, ContentType contentType) throws IOException, IllegalArgumentException {
    // String[] assetNames = {"MY_ASSET_NAME"}
    // ContentType contentType = contentType
    // String FeedId = "MY_FEED_ID"
    // String topic = "projects/[PROJECT_ID]/topics/[TOPIC_NAME]"
    // String projectID = "MY_PROJECT_ID"
    Feed feed = Feed.newBuilder().addAllAssetNames(Arrays.asList(assetNames)).setContentType(contentType).setFeedOutputConfig(FeedOutputConfig.newBuilder().setPubsubDestination(PubsubDestination.newBuilder().setTopic(topic).build()).build()).build();
    CreateFeedRequest request = CreateFeedRequest.newBuilder().setParent(String.format(ProjectName.of(projectId).toString())).setFeedId(feedId).setFeed(feed).build();
    // the "close" method on the client to safely clean up any remaining background resources.
    try (AssetServiceClient client = AssetServiceClient.create()) {
        Feed response = client.createFeed(request);
        System.out.println("Feed created successfully: " + response.getName());
    } catch (IOException | IllegalArgumentException e) {
        System.out.println("Error during CreateFeed: \n" + e.toString());
    }
}
Also used : AssetServiceClient(com.google.cloud.asset.v1.AssetServiceClient) IOException(java.io.IOException) CreateFeedRequest(com.google.cloud.asset.v1.CreateFeedRequest) Feed(com.google.cloud.asset.v1.Feed)

Example 4 with ContentType

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

the class ExportAssetsExample method exportAssets.

// Export assets for a project.
// @param exportPath where the results will be exported to.
public static void exportAssets(String exportPath, ContentType contentType) throws IOException, IllegalArgumentException, InterruptedException, ExecutionException {
    try (AssetServiceClient client = AssetServiceClient.create()) {
        ProjectName parent = ProjectName.of(projectId);
        OutputConfig outputConfig = OutputConfig.newBuilder().setGcsDestination(GcsDestination.newBuilder().setUri(exportPath).build()).build();
        ExportAssetsRequest request = ExportAssetsRequest.newBuilder().setParent(parent.toString()).setOutputConfig(outputConfig).setContentType(contentType).build();
        ExportAssetsResponse response = client.exportAssetsAsync(request).get();
        System.out.println(response);
    }
}
Also used : OutputConfig(com.google.cloud.asset.v1.OutputConfig) ExportAssetsRequest(com.google.cloud.asset.v1.ExportAssetsRequest) ProjectName(com.google.cloud.asset.v1.ProjectName) AssetServiceClient(com.google.cloud.asset.v1.AssetServiceClient) ExportAssetsResponse(com.google.cloud.asset.v1.ExportAssetsResponse)

Example 5 with ContentType

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

the class ListAssetsExample method listAssets.

public static void listAssets(String projectId, String[] assetTypes, ContentType contentType) throws IOException, IllegalArgumentException {
    try (AssetServiceClient client = AssetServiceClient.create()) {
        ProjectName parent = ProjectName.of(projectId);
        // Build initial ListAssetsRequest without setting page token.
        ListAssetsRequest request = ListAssetsRequest.newBuilder().setParent(parent.toString()).addAllAssetTypes(Arrays.asList(assetTypes)).setContentType(contentType).build();
        // Repeatedly call ListAssets until page token is empty.
        ListAssetsPagedResponse response = client.listAssets(request);
        System.out.println(response);
        while (!response.getNextPageToken().isEmpty()) {
            request = request.toBuilder().setPageToken(response.getNextPageToken()).build();
            response = client.listAssets(request);
            System.out.println(response);
        }
    }
}
Also used : ListAssetsRequest(com.google.cloud.asset.v1.ListAssetsRequest) ProjectName(com.google.cloud.asset.v1.ProjectName) AssetServiceClient(com.google.cloud.asset.v1.AssetServiceClient) ListAssetsPagedResponse(com.google.cloud.asset.v1.AssetServiceClient.ListAssetsPagedResponse)

Aggregations

AssetServiceClient (com.google.cloud.asset.v1.AssetServiceClient)5 ContentType (com.google.cloud.asset.v1.ContentType)4 ProjectName (com.google.cloud.asset.v1.ProjectName)4 IOException (java.io.IOException)4 ContentType (org.geotoolkit.owc.xml.v10.ContentType)4 ArrayList (java.util.ArrayList)3 Document (org.dom4j.Document)3 DocumentException (org.dom4j.DocumentException)3 Element (org.dom4j.Element)3 SAXReader (org.dom4j.io.SAXReader)3 StyleSetType (org.geotoolkit.owc.xml.v10.StyleSetType)3 ContentType (org.ttzero.excel.entity.e7.ContentType)3 ExportAssetsRequest (com.google.cloud.asset.v1.ExportAssetsRequest)2 ExportAssetsResponse (com.google.cloud.asset.v1.ExportAssetsResponse)2 OutputConfig (com.google.cloud.asset.v1.OutputConfig)2 Path (java.nio.file.Path)2 List (java.util.List)2 JAXBElement (javax.xml.bind.JAXBElement)2 MapItem (org.apache.sis.portrayal.MapItem)2 MapLayer (org.apache.sis.portrayal.MapLayer)2