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;
}
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;
}
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());
}
}
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);
}
}
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);
}
}
}
Aggregations